Examples
Random ExampleArithmetic
Algebra
Polynomial and Rational Functions
- Polynomial division div(x**2 - 4 + x, x-2)
- Greatest common divisor gcd(2*x**2 + 6*x, 12*x)
- …and least common multiple lcm(2*x**2 + 6*x, 12*x)
- Factorization factor(x**4/2 + 5*x**3/12 - x**2/3)
- Multivariate factorization factor(x**2 + 4*x*y + 4*y**2)
- Symbolic roots solve(x**2 + 4*x*y + 4*y**2)
- solve(x**2 + 4*x*y + 4*y**2, y)
- Complex roots solve(x**2 + 4*x + 181, x)
- Irrational roots solve(x**3 + 4*x + 181, x)
- Systems of equations solve_poly_system([y**2 - x**3 + 1, y*x], x, y)
Trigonometry
Calculus
Limits
Derivatives
- Derive the product rule diff(f(x)*g(x)*h(x))
- …as well as the quotient rule diff(f(x)/g(x))
- Get steps for derivatives diff((sin(x) * x^2) / (1 + tan(cot(x))))
- Multiple ways to derive functions diff(cot(xy), y)
- Implicit derivatives, too diff(y(x)^2 - 5sin(x), x)
Integrals
- integrate(tan(x))
- Multiple variables integrate(2*x + y, y)
- Limits of integration integrate(2*x + y, (x, 1, 3))
- integrate(2*x + y, (x, 1, 3), (y, 2, 4))
- Improper integrals integrate(tan(x), (x, 0, pi/2))
- Exact answers integrate(1/(x**2 + 1), (x, 0, oo))
- Get steps for integrals integrate(exp(x) / (1 + exp(2x)))
- integrate(1 /((x+1)(x+3)(x+5)))
- integrate((2x+3)**7)
Series
Number Theory
- 1006!
- factorint(12321)
- Calculate the 42nd prime prime(42)
- Calculate \( \varphi(x) \), the Euler totient function totient(42)
- isprime(12321)
- First prime greater than 42 nextprime(42)
Diophantine Equations
Discrete Mathematics
Boolean Logic
Recurrences
- Solve a recurrence relation rsolve(y(n+2)-y(n+1)-y(n), y(n))
- Specify initial conditions rsolve(y(n+2)-y(n+1)-y(n), y(n), {y(0): 0, y(1): 1})
Summation
Plotting
- plot(sin(x) + cos(2x))
- Multiple plots plot([x, x^2, x^3, x^4])
- Polar plots plot(r=1-sin(theta))
- Parametric plots plot(x=cos(t), y=sin(t))
- Multiple plot types plot(y=x,y1=x^2,r=cos(theta),r1=sin(theta))
Miscellaneous
- Documentation for functions factorial2
- sympify
- bernoulli
… and more: see the documentation to learn about the full range of SymPy's capabilities.