![]() |
VOOZH | about |
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.
sympy.logic.boolalg.BooleanTrue
Boolean True in SymPy is a singleton that can be accessed with S.true, or by directly importing True or by importing simplify from the sympy package.
Output:
True True True
sympy.logic.boolalg.BooleanFalse
Boolean False in SymPy is a singleton that can be accessed with S.false, or by directly importing false or by importing simplify from the sympy package.
Output:
False False False
negation of true is false, and negation of false is true.
Output:
False True
sympy.logic.boolalg.And
It analyzes each of its arguments in sequence, it returns true if all of the arguments are true. if at least one argument is false, false is returned.
Output:
x & y y False False True False False
sympy.logic.boolalg.Or
If any of the arguments is true, True is returned or else false is returned.
Output:
x | y True y True True False True
sympy.logic.boolalg.Not(arg)
Not represents negation. If the statement is False, this method returns True. If the assertion is true, it returns False.
Output:
~x False True
sympy.logic.boolalg.Nor(*args)
Nor is a conjunction of Not and Or. Nor = Not+Or. It examines each argument in turn, returning False if any of them are True and True if all of them are False. If any argument is True, returns False. If all arguments are False, this function returns True.
Output:
~(x | y) ~(x | y) False False True False
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.
Output:
~(x & y) ~(x & y) True False True True
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.
Output:
x ^ y x ^ y True False False True
sympy.logic.boolalg.Xnor(*args)
Exclusive-NOR gate or XNOR gate is formed by combining the Exclusive-OR gate (XOR gate) and the NOT gate.
Returns False if an odd number of the arguments are True and the rest are False. Returns True if an even number of the arguments are True and the rest are False.
Output:
~(x ^ y) ~(x ^ y) False True False True
sympy.logic.boolalg.Implies(*args)
Implies refer to Logical implications. x implies y is equivalent to !x v y. Accepts x and y as Boolean inputs. If x is True and y is False, returns False. Otherwise, True is returned.
Output:
Implies(x, y) False True True True Implies(y, x) Implies(x, y)
sympy.logic.boolalg.Equivalent(*args)
Refers to an Equivalence relation. If x and y are both True or False, Equivalent(x, y) is True. If all of the arguments are logically equivalent, True is returned. Otherwise, False is returned.
Output:
Equivalent(x, y, z) False True True False True
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.
Output:
ITE(x, y, z) True False