The following code would work to sympify logical expressions:
sympify('a&b') # And(a, b)
sympify('a|b') # Or(a, b)
But how do I get a result of Not(a)
?
It turns out the symbol you are looking for is ~
. See the following:
>>> from sympy import sympify
>>> sympify('a&b')
And(a, b)
>>> sympify('a|b')
Or(a, b)
>>> sympify('~a')
Not(a)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With