如何将字符串转换为 Python 中的逻辑表达式

How to convert string to logical expression in Python

我需要将逻辑表达式转换为不使用括号。 基本上我需要析取范式。

字符串输入:"(a | b) & c"

输出:a & c | b & c

您可以使用 pyeda 来解析您的表达式,甚至进行转换。

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

输出

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