Simple recursive and iterative SAT solver written in Python.
Switch branches/tags
Nothing to show
Clone or download
Failed to load latest commit information.
src Switch to Python3 stringio Jul 6, 2018
.gitignore Initial commit Apr 14, 2014
LICENSE Initial commit Apr 14, 2014
README.rst Fix example in README.rst Oct 15, 2017


simple-sat: Simple Python SAT Solver

This project is a simple recursive and iterative implementation of a backtracking, watchlist-based, SAT solver. Code is based mostly on Knuth's SAT0W program which can be found here. The iterative code follows Knuth's version much closer, but is a bit more complicated. The recursive version is rather straight-forward. Intended primarily to as a learning tool.

Accompanying article can be found at


usage: [-h] [-v] [-a] [-b] [--output_filter OUTPUT_FILTER] [-r]
              [-i INPUT]

Solve SAT instance by reading from stdin using an iterative or recursive
watchlist-based backtracking algorithm. Iterative algorithm is used by
default, unless the -r flag is given. Empty lines and lines starting with a #
will be ignored.

optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose         verbose output.
  -a, --all             output all possible solutions.
  -b, --brief           brief output for assignemnts: outputs variables
                        assigned 1.
  --output_filter OUTPUT_FILTER
                        only output variables with namesstring with given
  -r, --recursive       use the recursive backtracking algorithm.
  -i INPUT, --input INPUT
                        read from given file instead of stdin.

Example Usage

$ python -v --input tests/simple/
Current watchlist:
1: 1 2 3, 1 ~2
~3: ~1 ~3
Current assignment: ~1 ~2 ~3
Clause ~1 ~3 contradicted.
Found satisfying assignment.
~1 ~2 3