Simplifying/negating propcalc formula
I have some code to generate randomized boolean formulas involving AND, OR, and IMPLIES for use in student assessments:
props = [propcalc.formula(l) for l in "PQRS"]
ops = ["&","|","->"]
for _ in range(3):
shuffle(props)
shuffle(ops)
p = props.pop()
q = props.pop()
props.append(p.add_statement(q,ops.pop()))
statement = props[0]
show(statement)
It's okay, but it has some superfluous parentheses I'd like to simplify. I also would like to compute the denial of these formulas. Is there an easy recipe for this I'm overlooking?
add a comment