Boolean Or

sympy.logic.boolalg.Or

If any of the arguments is true, True is returned or else false is returned. 

  • true |true = true
  • true|false = true
  • false | true = true
  • false|false = false

Python3




# import packages
from sympy.abc import x, y
from sympy.logic.boolalg import Or
 
res = x | y
print(res)
 
# 1&y == 1 or True
print(Or(x, y).subs(x, 1))
 
# 0|y ==y
print(Or(x, y).subs(x, 0))
 
# True | False == True
print(Or(True, False))
 
# True | True == True
print(Or(True, True))
 
# False | False == False
print(Or(False, False))
 
# False | True == True
print(Or(False, True))


Output:

x | y
True
y
True
True
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.

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:

...