Numerical Evaluation

This lesson discusses numeric types and evaluation in SymPy.

Numeric types

While SymPy primarily focuses on symbols, it is impossible to have a completely symbolic system without the ability to numerically evaluate expressions. Many operations will directly use numerical evaluation, such as plotting a function or solving an equation numerically.

SymPy has 3 numeric types: rational, real, and integers. Since rational is the new one, let’s discuss it here:

Rational

The rational class represents a rational number as a pair of two integers: the numerator and the denominator.

Rational(1, 4) 

represents 14\frac{1}{4}

Rational(5, 3) 

represents 53\frac{5}{3}

All the arithmetic operations can be performed on these rational numbers. Let’s see an implementation of this below:

Get hands-on with 1200+ tech skills courses.