Questions tagged [sympy]

SymPy is an open source Python library for symbolic mathematics.

SymPy is a Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) while keeping the code as simple as possible in order to be comprehensible and easily extensible. SymPy is written entirely in Python and does not require any external libraries.

Some examples of usage can be found here.

SymPy includes features ranging from basic symbolic arithmetic to calculus, algebra, discrete mathematics, quantum physics. It is capable of formatting the result of the computations as LaTeX code.

Some Core capabilities:

  • Basic arithmetic: *, /, +, -, **
  • Simplification
  • Expansion
  • Functions: trigonometric, hyperbolic, exponential, roots, logarithms, absolute value, spherical harmonics, factorials and gamma functions, zeta functions, polynomials, hypergeometric, special functions, ...
  • Substitution
  • Arbitrary precision integers, rational and floats
  • Non-commutative symbols
  • Pattern matching
  • Polynomials
  • Basic arithmetic: division, gcd, ...
  • Factorization
  • Square-free factorization
  • Calculus
  • Limits
  • Differentiation
  • Pretty-printing: ASCII/Unicode pretty-printing, LaTeX
  • Code generation: C, Fortran, Python
5602 questions
9
votes
3 answers

Derivative of summations

I am using sympy from time to time, but am not very good at it. At the moment I am stuck with defining a list of indexed variables, i.e. n1 to nmax and performing a summation on it. Then I want to be able to take the derivative: So far I tried the…
Johannes
  • 161
  • 1
  • 6
9
votes
1 answer

How to extract numerator and denominator from polynomial without evaluating?

I have the following expression A=Symbol('A') x=Symbol('x') B=Symbol('B') C=Symbol('C') D=Symbol('D') expression=((A**x-B-C)/(D-1))*(D-1) n,d=fraction(expression) I am getting following result: n=A**x-B-C d=1 My expected result…
Tom
  • 904
  • 1
  • 7
  • 21
9
votes
1 answer

Generate Fortran subroutine with SymPy codegen for a system of equations

Building on a former example that I've found here, I try to find out how to generate a Fortran code that correspond to a specific form that I need to stick to. The required FORTRAN code will look like this (it is based on the FitzHugh–Nagumo…
Ohm
  • 2,312
  • 4
  • 36
  • 75
9
votes
1 answer

Error solving Matrix equation with numpy

I'm writing my own Newton-Raphson algorithm in Python using sympy and numpy. The code is below but you can ignore this and skip on to the error: CODE def newtonRhapson(fncList, varz, x0): jacob = [] for fnc in fncList: vec = [] …
Greg Peckory
  • 7,700
  • 21
  • 67
  • 114
9
votes
2 answers

Sympy classes Zero, One and NegativeOne, why they exist?

Today I found this >>> type(1) >>> type(0) >>> type(-1) >>> type(2) I looked the documentation from…
Mr. E
  • 2,070
  • 11
  • 23
9
votes
2 answers

How to simplify an expression for a complex constant using sympy?

I have done some calculations in sympy, and the result is in the end a set of constants. One of them is inserted directly into the snippet below: from sympy import * expr = (18**(Rational(1, 3))/(6*(3 + sqrt(3)*I)**(Rational(1, 3))) +…
josteinb
  • 1,892
  • 2
  • 18
  • 32
9
votes
1 answer

Is sympy pretty printing broken in new jupyter notebook?

I have previously used pretty printing of math in the ipython notebook. After upgrading to jupyter (also upgrades many other ipython-related packages), pretty printing no longer works like before. I use this code in the top of my notebooks to set it…
josteinb
  • 1,892
  • 2
  • 18
  • 32
9
votes
2 answers

python (sympy) implicit function: get values instead of plot?

I am new to sympy but I already get a nice output when I plot the implicit function (actually the formula for Cassini's ovals) using sympy: from sympy import plot_implicit, symbols, Eq, solve x, y = symbols('x y') k=2.7 a=3 eq = Eq((x**2 +…
xaratustra
  • 647
  • 1
  • 14
  • 28
9
votes
2 answers

How to serialize sympy lambdified function?

The title says it all. Is there any way to serialize a function generated by sympy.lambdify?: import sympy as sym import pickle import dill a, b = sym.symbols("a, b") expr = sym.sin(a) + sym.cos(b) lambdified_expr = sym.lambdify((a, b), expr,…
akai
  • 2,498
  • 4
  • 24
  • 46
9
votes
1 answer

Error: function() takes at least n arguments (n given)

I'm trying to use SymPy to take residues, in this case the cotangent function. I've got an integrate() function: import sympy as sy import numpy as np def integrate(f, z, gamma, t, lower, upper, exact=True): ''' Integrate f(z) along the…
Marissa Graham
  • 143
  • 2
  • 5
9
votes
2 answers

Save/load sympy lambdifed expressions

Imagine the following three step process: I use sympy to build a large and somewhat complicated expression (this process costs a lot of time). That expression is then converted into a lambda function using sympy.lambdify (also slow). Said…
PeterE
  • 5,715
  • 5
  • 29
  • 51
9
votes
1 answer

How to get either side of equation in SymPy?

Suppose I have the code below. I want to get either the right side of the equation (C1 +x...). How do I do that? My problem is I have some boundary conditions for derivatives of f(x) at specific points, so I want to calculate those and find out the…
eri0o
  • 2,285
  • 4
  • 27
  • 43
9
votes
1 answer

Separating real and imaginary parts using Sympy

I am trying to segregate real and imaginary parts of the output for the following program. import sympy as sp a = sp.symbols('a', imaginary=True) b=sp.symbols('b',real=True) V=sp.symbols('V',imaginary=True) a=4*sp.I b=5 V=a+b print V Kindly help.…
Chikorita Rai
  • 851
  • 5
  • 13
  • 17
9
votes
2 answers

sympy: trigonometric sum-product identities

I have an expression: sin(x)+sin(y) There is a well-known trig identity to express this as the product of sin and cos. Is there a way to get sympy to apply this identity? simplify and trigsimp do nothing.
GeorgeSalt
  • 197
  • 1
  • 11
9
votes
1 answer

Is it possible to implement Newton's Dot Notation (or Lagrange's Prime Notation) in sympy?

Leibniz's notation can just be a bit cluttering, especially in physics problems where time is the only variable that functions are being differentiated with respect to. Additionally, is it possible to not display the (t) for a function like x(t)…
pixatlazaki
  • 572
  • 8
  • 19