L'imaginaire pur se note I.
>>> from sympy import I
On peut alors définir l'exponentielle complexe :
>>> from sympy import Symbol, exp
>>> x = Symbol("x")
>>> print exp(I*x)
On peut alors développer l'exponentielle complexe en sa forme trigonométrique :
>>> exp(I*x).expand()
exp(I*x)
>>> exp(I*x).expand(complex=True)
1/exp(im(x))*cos(re(x)) + I/exp(im(x))*sin(re(x))
>>> x = Symbol("x", real=True)
>>> exp(I*x).expand(complex=True)
I*sin(x) + cos(x)
Le factoriel, et la fonction gamma de Euler (généralisation du factoriel aux réels), sont définis dans le module sympy :
>>> from sympy import *
>>> x = Symbol("x")
>>> factorial(x)
gamma(1 + x)
Si l'on précise que la variable est entière :
>>> y=Symbol('y', integer = True)
>>> factorial(y)
y!
La fonction gamma se traite comme toute autre fonction avec sympy. Par exemple, on peut en obtenir un développement limité :
>>> factorial(x).series(x, 0, 3) 1 - x*EulerGamma + (1/2)*x**2*EulerGamma**2 + (1/12)*pi**2*x**2 + O(x**3)
La fonction zeta de Riemann existe elle aussi :
>>> from sympy import *
>>> x=Symbol('x')
>>> zeta(4,x)
zeta(4, x)
On peut l'évaluer :
>>> zeta(4,1) (1/90)*pi**4
Les polynômes "classiques" sont définis dans sympy :
>>> from sympy import *
>>> x=Symbol('x')
Par exemple, pour obtenir les polynômes de Tchebychev :
>>> chebyshevt(2,x) -1 + 2*x**2
Pour ceux de Legendre, et associés :
>>> legendre(2,x) (-1/2) + (3/2)*x**2 >>> assoc_legendre(2, 1, x) -3*x*(1 - x**2)**(1/2)
Enfin, pour les polynômes de Hermite :
>>> hermite(3,x) -12*x + 8*x**3
On peut faire du calcul trigonométrique avec sympy :
>>> from sympy import *
>>> x=Symbol('x')
>>> y=Symbol('y')
>>> sin(x+y).expand(trig=True)
cos(x)*sin(y) + cos(y)*sin(x)
et mêler complexes et fonctions hyperboliques :
>>> sin(I*x) I*sinh(x) >>> asinh(I) (1/2)*pi*I
Pour le calcul de limite avec sympy, la syntaxe est limit(fonction, variable, point) :
>>> from sympy import *
>>> x=Symbol("x")
>>> limit(sin(x)/x, x, 0)
1
>>> limit(x**x, x, 0)
1
Ou, pour la limite en l'infini :
>>> limit(x, x, oo) oo >>> limit(1/x, x, oo) 0