From 0c975dd2b467bc454a5572ea3a913a891207b4e3 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Mon, 9 Feb 2009 15:37:45 +0000 Subject: [PATCH] Added support for logical negation in the BK --- checks/Check.hs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/checks/Check.hs b/checks/Check.hs index 558e3b3..ae434bc 100644 --- a/checks/Check.hs +++ b/checks/Check.hs @@ -137,6 +137,35 @@ addBK mp mp2 g nid n = fmap ((,) $ followBK (map (keepDefined . Map.fromListWith | op == A.More = [[LessThanOrEqual (addOne rhs) lhs]] | op == A.NotEq = [[LessThanOrEqual (addOne lhs) rhs] ,[LessThanOrEqual (addOne rhs) lhs]] + g (A.Monadic _ A.MonadicNot rhs) + = negate $ g rhs + where + -- We have something with a disjunctive normal form, that we need to + -- negate: + -- not ((A and B) or (C and D)) + -- De Morgan: + -- (not (A and B)) and (not (C and D)) + -- De Morgan again: + -- (not A or not B) and (not C or not D) + -- Distribution: + -- (not A and not C) or (not A and not D) or (not B and not C) or (not + -- B and not D) + -- + -- So what we must do is do a cross-product across all the lists, + -- and negate each element. But this is futher complicated by the + -- way that Equals expands out to an ORed item. + negate orig = productN $ negateORs orig + + -- Takes a list of things ORed, gives back a list of things ANDed + negateORs = map negateANDs + + -- Takes a list of things ANDed, gives back a list of things ORed + negateANDs = concatMap negateItem + + negateItem (Equal lhs rhs) = [LessThanOrEqual (addOne lhs) rhs + ,LessThanOrEqual (addOne rhs) lhs] + negateItem (LessThanOrEqual lhs rhs) = [LessThanOrEqual (addOne rhs) lhs] + g _ = [] conBK :: [[(Var, [BackgroundKnowledge])]]