Python sympy.GreaterThan() Method

Python SymPy Module:

SymPy is a Python symbolic mathematics library. It aims to be a full-featured computer algebra system (CAS) while keeping the code as basic(simple) as possible in order to be understandable and easily expandable. SymPy is entirely written in Python. SymPy is simple to use because it only depends on mpmath, a pure Python library for arbitrary floating-point arithmetic.

Rational and Integer are the numerical types defined by SymPy. A rational number is represented by the Rational class as a pair of two Integers, numerator and denominator, therefore Rational(1, 2) is 1/2, Rational(3, 2) is 3/2, and so on. Integer numbers are represented by the Integer class.

SymPy uses mpmath in the background, allowing it to execute arbitrary-precision arithmetic computations. Some special constants, such as exp, pi, and oo (Infinity), are thus considered as symbols and can be evaluated with arbitrary precision.

Installation:

pip install sympy

Python sympy.GreaterThan() Method:

We can create a mathematical expression using the greater than operator with the help of the sympy.GreaterThan() method.

Syntax:

  sympy.GreaterThan(variable_1, variable_2)

Return Value:

A mathematical expression is returned by the GreaterThan() function.

sympy.GreaterThan() Method in Python

Example1

Approach:

  • Import all the functions from sympy module using the import keyword
  • Pass the symbols to be used as arguments to the symbols() function and store them in corresponding variables.
  • Create a mathematical expression with the greater than operator by using the GreaterThan() function and store it in a variable.
  • Here it creates the x >= y mathematical expression.
  • Print the result mathematical expression with the greater-than operator.
  • The Exit of the Program.

Below is the implementation:

# Import all the functions from sympy module using the import keyword
from sympy import *

# Pass the symbols to be used as arguments to the symbols() function
# and store them in corresponding variables.
x, y = symbols('x y')

# Create a mathematical expression with the greater than operator by using the
# GreaterThan() function and store it in a variable.
# Here it creates x >= y expression.
rslt_expsn = GreaterThan(x, y)

# Print the result mathematical expression with the greater-than operator.
print(rslt_expsn)

Output:

x >= y

Example2

Approach:

  • Import all the functions from sympy module using the import keyword
  • Pass the symbols to be used as arguments to the symbols() function and store them in corresponding variables.
  • Create a mathematical expression with the greater than operator by using the GreaterThan() function and store it in a variable.
  • Here it creates the y>= 20 mathematical expression.
  • Print the result mathematical expression with the greater-than operator.
  • The Exit of the Program.

Below is the implementation:

# Import all the functions from sympy module using the import keyword
from sympy import *

# Pass the symbols to be used as arguments to the symbols() function
# and store them in corresponding variables.
x, y = symbols('x y')

# Create a mathematical expression with the greater than operator by using the
# GreaterThan() function and store it in a variable.
# Here it creates y >= 20 expression.
rslt_expsn = GreaterThan(y, 20)

# Print the result mathematical expression with the greater than operator.
print(rslt_expsn)

Output:

y >= 20