How to convert string to logical expression in Python

Viewed 1693

I need to convert a logical expression to not use parenthesis. Basically I need the disjunctive normal form.

String input: "(a | b) & c"

Output: a & c | b & c

1 Answers

You can use pyeda to parse your expression and even convert it.

print(expr.expr("(a | b) & c").to_dnf())

Output

Or(And(a, c), And(b, c))
Related