compiler construction - I have a language where I need to determine if my flow control statement predicates are tautologies or contradictions -
hello i'm working on domain specific language project group. want report language user if predicate in example if(predicate) or while(predicate) true or false. logic operators implemented on language and, or, negation comparison operators, <,>, >=, <=, !=, =(equal).
i naturally want examine predicates literals symbols such false, true, numbers, , strings. evaluating values symbols of expressions no problem.
are these things possible , existing information can @ achieve maybe code?
if restrict formulas boolean logic on predicate leaves (e.g., treat relational comparisons @ "ground literals"), can verify if formula tautology or not applying wang's rules of inference, here captured in algebraic specification axioms can treated left-to-right rewrite rules:
wang = { sort boolean; true, false: boolean; boolean generated true, false; not: boolean ® boolean; and, or: boolean --> boolean ® boolean associative commutative; implies, equivalent: boolean --> boolean ® boolean; axioms -- 3 simplification rules not «not1» not(true) = false; «not2» not(false) = true; «not3» not(not(x)) = x; -- definition of 'implies' «impl» implies(x,y) = or(not(x),y); -- definition of 'and' «and» and(x,y) = not(or(not(x),not(y))); -- definition of 'equivalent' «eq» equivalent(x,y) = and(implies(x,y),implies(y,x)); -- simplification rules 'or' «or01» or(true,x) = true; «or02» or(false,x) = x; «or03» or(x,not(x)) = true; «or04» or(x,or(not(x),y)) = true; «or05» or(x,x) = x; «or06» or(x,or(x,y)) = or(x,y); «or07» or(not(or(x,y)),x) = or(x,not(y)); «or08» or(not(or(x,y)),or(x,z)) = or(x,or(not(y),z)); «or09» or(not(or(x,y)),not(x)) = not(x); «or10» or(not(or(x,y)),or(not(x),z)) = or(not(x),z); «or11» or(not(or(not(x),y)),x) = x; «or12» or(not(or(not(x),y)),or(x,z)) = or(x,z); «or13» or(not(or(not(x),y)),not(or(x,y))) = not(y); «or14» or(not(or(not(x),y)),or(not(or(x,y)),z)) = or(not(y),z); endaxioms; } the beauty of these rewrite rules can apply them in order boolean equation. eventually, no rules further apply. @ point, formula either true (a tautology), false (an anti-tautology), or else (neither true or false).
(this particular rule set applied directly dms software reengineering toolkit. can implement own "rewriter" build (abstract) syntax trees boolean expression, , implementing these rules relatively simple procedures walk on tree looking place might apply, , apply them when such place found. pretty straightforward.).
Comments
Post a Comment