Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sympy: how to sympify logical "NOT"

Tags:

python

sympy

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

like image 572
xuhdev Avatar asked Feb 10 '23 12:02

xuhdev


1 Answers

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)
like image 74
Brien Avatar answered May 13 '23 02:05

Brien