module demo::lang::logic::ast::Booleans
rascal-0.40.17
Usage
import demo::lang::logic::ast::Booleans;
data Formula
data Formula
= \true()
| \false()
| \not(Formula arg)
| \and(Formula lhs, Formula rhs)
| \and(set[Formula] args)
| \or(Formula lhs, Formula rhs)
| \or(set[Formula] args)
| \if(Formula lhs, Formula rhs)
| \fi(Formula lhs, Formula rhs)
| \iff(Formula lhs, Formula rhs)
;
function or
Formula or({Formula x}) = x;
function and
Formula and({Formula x}) = x;
Formula and(Formula a, Formula b) = and({a,b});
function or
Formula or(Formula a, Formula b) = or({a,b});
function and
Formula and({*Formula a, and(set[Formula] b)}) = and(a + b);
function or
Formula or({*Formula a, or(set[Formula] b)}) = or(a + b);
function simplify
Formula simplify(or({\true(), *Formula _})) = \true();
Formula simplify(and({\false(), *Formula _})) = \false();
Formula simplify(not(not(Formula g))) = g;
Formula simplify(not(\true())) = \false();
Formula simplify(not(\false())) = \true();
Formula simplify(\if(Formula l, Formula r)) = or(not(l),r);
Formula simplify(\fi(Formula l, Formula r)) = \if(r, l);
Formula simplify(\iff(Formula l, Formula r)) = and(\if(l,r),\fi(l,r));
Formula simplify(and({Formula g,\not(g),*Formula r})) = \false();
default Formula simplify(Formula f) = f;