Python sympy.LessThan() 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.LessThan() Method:

We can create a mathematical expression using the less-than(<) operator with the help of the sympy.LessThan() method.

Syntax:

  sympy.LessThan(variable_1, variable_2)

Return Value:

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

sympy.LessThan() 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 less-than(<) operator by using the LessThan() function and store it in a variable.
  • Here it creates the x <= y mathematical expression.
  • Print the result mathematical expression with the less-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 less-than(<) operator by using the
# LessThan() function and store it in a variable.
# Here it creates x <= y expression.
rslt_expsn = LessThan(x, y)

# Print the result mathematical expression with the less-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 less-than(<) operator by using the LessThan() function and store it in a variable.
  • Here it creates the y<= 15 mathematical expression.
  • Print the result mathematical expression with the less-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 less-than(<) operator by using the
# LessThan() function and store it in a variable.
# Here it creates y <= 15 expression.
rslt_expsn = LessThan(y, 15)

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

Output:

y <= 15