Search⌘ K
AI Features

Symbols and Complex Numbers

Understand how to define and use symbolic variables with SymPy, handle their properties, and work with complex numbers in symbolic computation. Explore how SymPy treats complex symbols and learn to convert SymPy complex types to Python complex numbers.

Symbolic variables

Symbolic variables, called symbols, must be defined and assigned to Python variables before they can be used. This is typically done with the Symbol function:

x = Symbol('x' )

To assign multiple symbols in a single function call, we use the symbols function:

x, y, z = symbols('x y z')

creates three symbols representing variables named x, y, and z. In this particular instance, ...

Python 3.5
from sympy import *
x = Symbol('x')
y, z = symbols('y z')
print(x + y + z)

We can explicitly set the properties positive, real, imaginary and complex for the symbol. This helps us simplify the expressions.

x = Symbol('x', real = True, positive = True)

...

Complex numbers

SymPy never ...