Resolution rule: finding suitable pairs of clauses

This commit is contained in:
Dimitri Lozeve 2016-08-03 19:30:43 +01:00
parent f0ab796149
commit 3a62fd2363
No known key found for this signature in database
GPG key ID: 12B390E6BD7CF219

19
Sat.hs
View file

@ -145,6 +145,25 @@ resolve a b = do
x <- commonVar a b
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)
----------------------------------------------------------------------