Resolution rule: finding suitable pairs of clauses
This commit is contained in:
parent
f0ab796149
commit
3a62fd2363
1 changed files with 19 additions and 0 deletions
19
Sat.hs
19
Sat.hs
|
@ -145,6 +145,25 @@ resolve a b = do
|
||||||
x <- commonVar a b
|
x <- commonVar a b
|
||||||
return $ (a \\ [x, notLit x]) `union` (b \\ [x, notLit x])
|
return $ (a \\ [x, notLit x]) `union` (b \\ [x, notLit x])
|
||||||
|
|
||||||
|
-- Given a formula and a clause, returns a clause which can be reduced
|
||||||
|
-- with the first one by applying the resolution rule.
|
||||||
|
findMatchingClause :: CNF -> Clause -> Maybe Clause
|
||||||
|
findMatchingClause _ [] = Nothing
|
||||||
|
findMatchingClause f (x:xs) =
|
||||||
|
case find (elem $ notLit x) f of
|
||||||
|
Nothing -> findMatchingClause f xs
|
||||||
|
Just c -> Just c
|
||||||
|
|
||||||
|
-- Returns a two clauses suitable for the resolution rule, if
|
||||||
|
-- possible.
|
||||||
|
findMatchingPair :: CNF -> Maybe (Clause, Clause)
|
||||||
|
findMatchingPair [] = Nothing
|
||||||
|
findMatchingPair (c:cs) =
|
||||||
|
case findMatchingClause cs c of
|
||||||
|
Nothing -> findMatchingPair cs
|
||||||
|
Just d -> Just (c, d)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue