Boolean ITE

sympy.logic.boolalg.ITE(*args)

ITE refers to the If then else clause. If A is true, ITE(x, y, z) evaluates and returns the result of y; otherwise, ITE(x, y, z) evaluates and returns the result of z. All of the arguments must be Booleans.

Python3




from sympy.abc import x, y, z
from sympy.logic.boolalg import ITE, Nor, Nand, Xor, Or, And
 
# ITE == if then else
print(ITE(x, y, z))
 
# x is true so y is returned
print(ITE(True, Or(True, False), And(True, True)))
 
# x is false so z is returned
print(ITE(Nor(True, False), Xor(True, False), Nand(True, True)))


Output:

ITE(x, y, z)
True
False


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.

Similar Reads

Boolean True:

sympy.logic.boolalg.BooleanTrue...

Boolean False:

...

Boolean And:

sympy.logic.boolalg.BooleanFalse...

Boolean Or:

...

Boolean Not:

...

Boolean Nor:

sympy.logic.boolalg.And...

Boolean Nand:

...

Boolean Xor:

sympy.logic.boolalg.Or...

Boolean Xnor:

...

Boolean Equivalent

sympy.logic.boolalg.Not(arg)...

Boolean ITE:

...