Boolean Nand
sympy.logic.boolalg.Nand(*args)
Nand is a conjunction of Not and. Nor = Not+And. It analyses each of its inputs in succession, returning True if any of them are False and False if all of them are True. If any of the inputs are False, this function returns True. If all arguments are True, returns False.
Python3
# import packages from sympy.abc import x, y from sympy.logic.boolalg import Nand # not + nand == nand nor_formula = ~(x & y) print (nor_formula) print (Nand(x, y)) # ~( True & False) == True print (Nand( True , False )) # ~(True & True) == False print (Nand( True , True )) # ~(False & False) == True print (Nand( False , False )) # ~(False & True) == True print (Nand( False , True )) |
Output:
~(x & y) ~(x & y) True False True True
What are the Logical Expressions in Sympy?
SymPy is a symbolic mathematics Python package. Its goal is to develop into a completely featured computer algebra system while keeping the code as basic as possible to make it understandable and extendable. The package is entirely written in python language. Logical expressions in sympy are expressed by using boolean functions. sympy.basic.booleanarg module of sympy contains boolean functions.
The common Python operators & (And), | (Or), and ~ (Not) can be used to create Boolean expressions. >> and can also be used to create implications. other boolean operations or gates are NAND, NOR, XOR, etc.