Boolean Xor
sympy.logic.boolalg.Xor(*args)
Xor represents Logical XOR or Exclusive Or function. If an odd number of the arguments are True and the others are False, this function returns True. If an even number of the arguments are True and the others are False, the result is False.
Python3
# import packages from sympy.abc import x, y from sympy.logic.boolalg import Xor xor_formula = x ^ y print (xor_formula) print (Xor(x, y)) # True ^ False == True print (Xor( True , False )) # True ^ True == False print (Xor( True , True )) # False ^ False == False print (Xor( False , False )) # False ^ True == True print (Xor( False , True )) |
Output:
x ^ y x ^ y True False False 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.