xuhdev
xuhdev

Reputation: 9370

sympy: how to sympify logical "NOT"

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)?

Upvotes: 4

Views: 83

Answers (1)

Blair
Blair

Reputation: 6693

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)

Upvotes: 8

Related Questions