|Maintainer||Sebastian Fischer (email@example.com)|
This Haskell library provides an implementation of the Davis-Putnam-Logemann-Loveland algorithm (cf. http://en.wikipedia.org/wiki/DPLL_algorithm) for the boolean satisfiability problem. It not only allows to solve boolean formulas in one go but also to add constraints and query bindings of variables incrementally.
The implementation is not sophisticated at all but uses the basic DPLL algorithm with unit propagation.
- data Boolean
- data SatSolver
- data Literal
- literalVar :: Literal -> Int
- invLiteral :: Literal -> Literal
- isPositiveLiteral :: Literal -> Bool
- type CNF = [Clause]
- type Clause = [Literal]
- booleanToCNF :: Boolean -> CNF
- newSatSolver :: SatSolver
- isSolved :: SatSolver -> Bool
- lookupVar :: Int -> SatSolver -> Maybe Bool
- assertTrue :: MonadPlus m => Boolean -> SatSolver -> m SatSolver
- assertTrue' :: MonadPlus m => CNF -> SatSolver -> m SatSolver
- branchOnVar :: MonadPlus m => Int -> SatSolver -> m SatSolver
- selectBranchVar :: SatSolver -> Int
- solve :: MonadPlus m => SatSolver -> m SatSolver
- isSolvable :: SatSolver -> Bool
Boolean formulas are represented as values of type
Variables are labeled with an
|Boolean :&&: Boolean|
and finally we provide conjunction
|Boolean :||: Boolean|
and disjunction of boolean formulas.
Literals are variables that occur either positively or negatively.
This predicate checks whether the given literal is positive.
We convert boolean formulas to conjunctive normal form by pushing negations down to variables and repeatedly applying the distributive laws.
We can lookup the binding of a variable according to the currently
stored constraints. If the variable is unbound, the result is
We can assert boolean formulas to update a
assertion may fail if the resulting constraints are unsatisfiable.
This function guesses a value for the given variable, if it is
currently unbound. As this is a non-deterministic operation, the
resulting solvers are returned in an instance of
We select a variable from the shortest clause hoping to produce a unit clause.
This function guesses values for variables such that the stored
constraints are satisfied. The result may be non-deterministic and
is, hence, returned in an instance of