iota-0.1.0.0
Safe HaskellSafe-Inferred
LanguageGHC2021

Algorithm.TwoSat

Synopsis

Documentation

twoSat Source #

Arguments

:: Int

the number of variables

-> Int

upper bound on the number of clauses

-> (forall s. CNFBuilder s () -> ST s ())

CNF(Conjunctive Normal Form)

-> Maybe (Vector Bool) 

2-SAT

(a0 \/ a1) /\ not a0
>>> twoSat 2 2 (\b -> addClauseCNF b (0, True) (1, True) >> addClauseCNF b (0, False) (0, False))
Just [False,True]
a0 /\ not a1 /\ (not a0 \/ a1)
>>> print $ twoSat 2 3 (\b -> addClauseCNF b (0, True) (0, True) >> addClauseCNF b (1, False) (1, False) >> addClauseCNF b (0, False) (1, True))
Nothing
a0 \/ not a0
>>> twoSat 1 1 (\b -> addClauseCNF b (0, True) (0, False))
Just [True]

addClauseCNF :: PrimMonad m => CNFBuilder (PrimState m) () -> (Int, Bool) -> (Int, Bool) -> m () Source #