----------------------------------------------------------------------------- -- Copyright 2014, Open Universiteit Nederland. This file is distributed -- under the terms of the GNU General Public License. For more information, -- see the file "LICENSE.txt", which is included in the distribution. ----------------------------------------------------------------------------- -- | -- Maintainer : bastiaan.heeren@ou.nl -- Stability : provisional -- Portability : portable (depends on ghc) -- -- Rewrite rules in the logic domain (including all the rules from the -- DWA course) -- ----------------------------------------------------------------------------- -- $Id: Rules.hs 6548 2014-05-16 10:34:18Z bastiaan $ module Domain.Logic.Rules ( ruleAbsorpAnd, ruleAbsorpOr, ruleAndOverOr, ruleOrOverAnd , ruleComplAnd, ruleComplOr, ruleDeMorganAnd, ruleDeMorganOr , ruleDefEquiv, ruleDefImpl , ruleFalseZeroAnd, ruleFalseZeroOr, ruleIdempAnd, ruleIdempOr , ruleNotFalse, ruleNotNot, ruleNotTrue , ruleTrueZeroAnd, ruleTrueZeroOr , ruleCommOr, ruleCommAnd, ruleAssocOr, ruleAssocAnd ) where import Domain.Logic.Formula import Domain.Logic.Generator() import Domain.Logic.Utils import Ideas.Common.Library hiding (ruleList) rule :: RuleBuilder f a => String -> f -> Rule a rule = rewriteRule . (propositionalId #) ruleFor :: RuleBuilder f a => Id -> String -> f -> Rule a ruleFor group s = siblingOf group . rule s ruleList :: RuleBuilder f a => String -> [f] -> Rule a ruleList = rewriteRules . (propositionalId #) ruleListFor :: RuleBuilder f a => Id -> String -> [f] -> Rule a ruleListFor group s = siblingOf group . ruleList s ----------------------------------------------------------------------------- -- Commutativity ruleCommOr :: Rule SLogic ruleCommOr = ruleFor groupCommutativity "CommOr" $ \x y -> x :||: y :~> y :||: x ruleCommAnd :: Rule SLogic ruleCommAnd = ruleFor groupCommutativity "CommAnd" $ \x y -> x :&&: y :~> y :&&: x ----------------------------------------------------------------------------- -- Associativity (implicit) ruleAssocOr :: Rule SLogic ruleAssocOr = minor $ ruleFor groupAssociativity "AssocOr" $ \x y z -> (x :||: y) :||: z :~> x :||: (y :||: z) ruleAssocAnd :: Rule SLogic ruleAssocAnd = minor $ ruleFor groupAssociativity "AssocAnd" $ \x y z -> (x :&&: y) :&&: z :~> x :&&: (y :&&: z) ----------------------------------------------------------------------------- -- Distributivity ruleAndOverOr :: Rule SLogic ruleAndOverOr = ruleListFor groupDistribution "AndOverOr" [ \x y z -> x :&&: (y :||: z) :~> (x :&&: y) :||: (x :&&: z) , \x y z -> (x :||: y) :&&: z :~> (x :&&: z) :||: (y :&&: z) ] ruleOrOverAnd :: Rule SLogic ruleOrOverAnd = ruleListFor groupDistribution "OrOverAnd" [ \x y z -> x :||: (y :&&: z) :~> (x :||: y) :&&: (x :||: z) , \x y z -> (x :&&: y) :||: z :~> (x :||: z) :&&: (y :||: z) ] ----------------------------------------------------------------------------- -- Idempotency ruleIdempOr, ruleIdempAnd :: Rule SLogic ruleIdempOr = ruleFor groupIdempotency "IdempOr" $ \x -> x :||: x :~> x ruleIdempAnd = ruleFor groupIdempotency "IdempAnd" $ \x -> x :&&: x :~> x ----------------------------------------------------------------------------- -- Absorption ruleAbsorpOr, ruleAbsorpAnd :: Rule SLogic ruleAbsorpOr = ruleListFor groupAbsorption "AbsorpOr" [ \x y -> x :||: (x :&&: y) :~> x , \x y -> x :||: (y :&&: x) :~> x , \x y -> (x :&&: y) :||: x :~> x , \x y -> (y :&&: x) :||: x :~> x ] ruleAbsorpAnd = ruleListFor groupAbsorption "AbsorpAnd" [ \x y -> x :&&: (x :||: y) :~> x , \x y -> x :&&: (y :||: x) :~> x , \x y -> (x :||: y) :&&: x :~> x , \x y -> (y :||: x) :&&: x :~> x ] ----------------------------------------------------------------------------- -- True-properties ruleTrueZeroOr, ruleTrueZeroAnd, ruleComplOr, ruleNotTrue :: Rule SLogic ruleTrueZeroOr = ruleList "TrueZeroOr" [ \x -> T :||: x :~> T , \x -> x :||: T :~> T ] ruleTrueZeroAnd = ruleList "TrueZeroAnd" [ \x -> T :&&: x :~> x , \x -> x :&&: T :~> x ] ruleComplOr = ruleList "ComplOr" [ \x -> x :||: Not x :~> T , \x -> Not x :||: x :~> T ] ruleNotTrue = rule "NotTrue" $ Not T :~> F ----------------------------------------------------------------------------- -- False-properties ruleFalseZeroOr, ruleFalseZeroAnd, ruleComplAnd, ruleNotFalse :: Rule SLogic ruleFalseZeroOr = ruleList "FalseZeroOr" [ \x -> F :||: x :~> x , \x -> x :||: F :~> x ] ruleFalseZeroAnd = ruleList "FalseZeroAnd" [ \x -> F :&&: x :~> F , \x -> x :&&: F :~> F ] ruleComplAnd = ruleList "ComplAnd" [ \x -> x :&&: Not x :~> F , \x -> Not x :&&: x :~> F ] ruleNotFalse = rule "NotFalse" $ Not F :~> T ----------------------------------------------------------------------------- -- Double negation ruleNotNot :: Rule SLogic ruleNotNot = rule "NotNot" $ \x -> Not (Not x) :~> x ----------------------------------------------------------------------------- -- De Morgan ruleDeMorganOr :: Rule SLogic ruleDeMorganOr = ruleFor groupDeMorgan "DeMorganOr" $ \x y -> Not (x :||: y) :~> Not x :&&: Not y ruleDeMorganAnd :: Rule SLogic ruleDeMorganAnd = ruleFor groupDeMorgan "DeMorganAnd" $ \x y -> Not (x :&&: y) :~> Not x :||: Not y ----------------------------------------------------------------------------- -- Implication elimination ruleDefImpl :: Rule SLogic ruleDefImpl = rule "DefImpl" $ \x y -> x :->: y :~> Not x :||: y ----------------------------------------------------------------------------- -- Equivalence elimination ruleDefEquiv :: Rule SLogic ruleDefEquiv = rule "DefEquiv" $ \x y -> x :<->: y :~> (x :&&: y) :||: (Not x :&&: Not y) ----------------------------------------------------------------------------- -- Additional rules, not in the DWA course {- ruleFalseInEquiv :: Rule SLogic ruleFalseInEquiv = ruleList "FalseInEquiv" [ \x -> F :<->: x :~> Not x , \x -> x :<->: F :~> Not x ] ruleTrueInEquiv :: Rule SLogic ruleTrueInEquiv = ruleList "TrueInEquiv" [ \x -> T :<->: x :~> x , \x -> x :<->: T :~> x ] ruleFalseInImpl :: Rule SLogic ruleFalseInImpl = ruleList "FalseInImpl" [ \x -> F :->: x :~> T , \x -> x :->: F :~> Not x ] ruleTrueInImpl :: Rule SLogic ruleTrueInImpl = ruleList "TrueInImpl" [ \x -> T :->: x :~> x , \x -> x :->: T :~> T ] ruleCommEquiv :: Rule SLogic ruleCommEquiv = rule "CommEquiv" $ \x y -> x :<->: y :~> y :<->: x ruleDefEquivImpls :: Rule SLogic ruleDefEquivImpls = rule "DefEquivImpls" $ \x y -> x :<->: y :~> (x :->: y) :&&: (y :->: x) ruleEquivSame :: Rule SLogic ruleEquivSame = rule "EquivSame" $ \x -> x :<->: x :~> T ruleImplSame :: Rule SLogic ruleImplSame = rule "ImplSame" $ \x -> x :->: (x::SLogic) :~> T -}