The python sympy.core.numbers Rational package library is used to represent rational numbers with arbitrary precision. It allows performing arithmetic operations on these numbers, as well as simplifying expressions involving them. Rational numbers are represented as a pair of integers, numerator and denominator.
Code Examples:
Here are a few code examples that use the Rational package library in python:
1. Creating a Rational Number:
from sympy import Rational
a = Rational(2, 3)
print(a)
Output: 2/3
2. Arithmetic operations:
from sympy import Rational
a = Rational(2, 3) b = Rational(3, 4)
c = a + b
print(c)
Output: 17/12
3. Simplifying an expression with Rational numbers:
from sympy import Rational, simplify
a = Rational(4, 8) b = Rational(2, 4)
c = a + b
print(c)
d = simplify(c)
print(d)
Output: 5/4
Description of Examples:
1. In the first example, we create a rational number 2/3 using the Rational function from the sympy package.
2. In the second example, we perform an arithmetic operation of addition on two rational numbers 2/3 and 3/4, and get the result 17/12.
3. In the third example, we create two rational numbers 4/8 and 2/4, add them up to get 1, which is then simplified using the simplify function to get 5/4.
Package Library:
The package library used in the above examples is the sympy package, specifically the sympy.core.numbers Rational package.
Python Rational - 32 examples found. These are the top rated real world Python examples of sympy.core.numbers.Rational extracted from open source projects. You can rate examples to help us improve the quality of examples.