Sympy: how to sympify a boolean "NOT"

The following code will work for sympify boolean expressions:

sympify('a&b') # And(a, b)
sympify('a|b') # Or(a, b)

But how do I get the result Not(a)?

+4
source share
1 answer

It turns out that the character 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)
+8
source

Source: https://habr.com/ru/post/1599388/


All Articles