Simplifying/negating propcalc formula

asked 2022-01-07 19:04:32 +0200

StevenClontz gravatar image

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?

edit retag flag offensive close merge delete