This project was the first project for our Computationally Modelling Reasoning course at the University of South Florida.
The assignment specification is detailed in the Slide JPG files. As a brief overview, this project implements a SAT Solver using the DPLL algorithm.
The solver is implemented using Python 3.4, in the file p1.py.
We used more than 100 unit tests (as python doctests) during the development of the project.
We integrated Travis CI and GitHub Pull Requests to ensure that the master branch always passed all unit tests, and that all code was reviewed by at least one other person.
F is input string of an s-exp of a PC formula.
Must return within 60 seconds. No other output.
'S'
if the formula is satisfiable'U'
if the formula is unsatisfiable
Must find satisfiability using DPLL algorithm.
S-exp = ws freevar ws | ws list ws
ws = <empty> | <space> | <tab> | <newline> | <carriage return>
freevar = [a-z0-9]+
list = ( ws var-op ws S-exp ws S-exp-list ws )
| ( ws NOT ws S-exp ws )
| ( ws IF ws S-exp ws S-exp ws )
var-op = AND | OR
S-exp-list = S-exp | S-exp ws S-exp-list
-
Convert to Conjunctive Normal Form (CNF)
- Transform IFs into disjunctions
- Push negations into literals using DeMorgan's
- Eliminate double negations
- Distribute disjunctions into conjunctions
Example
(~p -> ~q) -> (p -> q)
~(~~p + ~q) + (~p + q)
(~~~p * ~~q) + (~p + q)
(~p * q) + (~p + q)
(~p + ~p + q) * (q + ~p + q)
-
If all clauses eliminated, return
True
-
If there is an empty clause, return
False
-
Exhaustively perform 1-literal rule.
- Find a clause with a single literal
p
- For every clause
C
containingp
in any form:- If
C
containsp
, then remove the entire clause - If
C
contains~p
, then remove~p
fromC
- If
- Find a clause with a single literal
-
Exhaustively perform affirmative negation rule.
- Find a literal
p
which only appears all positive or all negative. - Remove all clauses containing
p
.
- Find a literal
-
Perform resolution to obtain two new formulas.
-
Recurse to step 2 with each new formula, returning first
True
result.