A Python package for working with Conjunctive Normal Form (CNFs) and Boolean Satisfiability
Project description
A Python package for working with Conjunctive Normal Form (CNFs) and Boolean Satisfiability (SAT)
This Python package is brought to you by Vaibhav Karve and Anil N. Hirani, Department of Mathematics, University of Illinois at Urbana-Champaign.
normal-form
recognizes variables, literals, clauses, and CNFs. The package implements an interface to easily construct CNFs and SAT-check them via third-part libraries MINISAT and PySAT.
This package is written in Python v3.10, and is publicly available under the GNU-GPL-v3.0 license. It is set to be released on the Python Packaging Index as an open-source scientific package written in the literate programming style. We specifically chose to write this package as a literate program, despite the verbosity of this style, with the goal to create reproducible computational research.
Installation and usage
To get started on using this package,
-
Istall Python 3.10 or higher.
-
python3.10 -m pip install normal-form
-
Use it in a python script (or interactive REPL) as –
from normal_form import cnf from normal_form import sat # This is the CNF (a ∨ b ∨ ¬c) ∧ (¬b ∨ c ∨ ¬d) ∧ (¬a ∨ d). x1: cnf.Cnf = cnf.cnf([[1, 2, -3], [-2, 3, -4], [-1, 4]]) sat_x1: bool = sat.cnf_bruteforce_satcheck(x1) print(sat_x1) # prints: True because x1 is satisfiable.
Overview of modules
The package consists of the following modules.
| Modules that act on Cnfs | |
| cnf.py
| Constructors and functions for sentences in conjunctive normal form |
| cnf_simplify.py
| Functions for simplifying Cnfs, for example (a∨b∨c) ∧ (a∨b∨¬ c) ⇝ (a ∨ b) |
| prop.py
| Functions for propositional calculus – conjunction, disjunction and negation |
| Modules concerning SAT | |
| sat.py
| Functions for sat-checking Cnfs |
| sxpr.py
| Functions for working with s-expressions |
| Test suite | |
| tests/*
| Unit- and property-based tests for each module |
Algorithms
Currently, normal-form
implements the following algorithms –
-
For formulae in conjunctive normal forms (CNFs), it implements variables, literals, clauses, Boolean formulae, and truth-assignments. It includes an API for reading, parsing and defining new instances.
-
For satisfiability of CNFs, it contains a bruteforce algorithm, an implementation that uses the open-source sat-solver PySAT, and an implementation using the MiniSAT solver.
Principles
normal-form
has been written in the functional-programming style with the following principles in mind –
-
Avoid classes as much as possible. Prefer defining functions instead.
-
Write small functions and then compose/map/filter them to create more complex functions.
-
Use lazy evaluation strategy whenever possible (using the itertools library).
-
Add type hints wherever possible (checked using the mypy static type-checker).
-
Add unit-tests for each function (checked using the pytest framework). Further, add property-based testing wherever possible (using the hypothesis framework).
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file normal-form-0.1.7.tar.gz
.
File metadata
- Download URL: normal-form-0.1.7.tar.gz
- Upload date:
- Size: 32.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.1 CPython/3.10.4 Linux/5.18.10-76051810-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cce064c7f4de794abb9d5d126405d966aa6ec29599b61790acbefa7e8150e4cb |
|
MD5 | b8bf6bfbc5cd526d246fa7ccbc009e55 |
|
BLAKE2b-256 | 68a2aa917b7f870227171f9de5037f47da7e4362e97527f7e430889ecc7ad254 |
File details
Details for the file normal_form-0.1.7-py3-none-any.whl
.
File metadata
- Download URL: normal_form-0.1.7-py3-none-any.whl
- Upload date:
- Size: 33.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.1 CPython/3.10.4 Linux/5.18.10-76051810-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74268d71c3bec795c9cf1a124bd5def4d7e0231900f796e54a0549fa65357bad |
|
MD5 | 2fc5cce0794bd8436aa5058de74032a7 |
|
BLAKE2b-256 | caa87ee6b40774ad7d15034bb4a1be2f388c7c50d91ed97304436de66912d50e |