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
2
votes
1 answer

Overriding the division operator when lambdifying symbolic expressions in sympy

I'm using Sympy to evaluate symbolic expressions provided by users, but the division operator isn't behaving like any other mathematical operator. When evaluating an expression on objects with overridden operators, I get the expected result for…
Kyle Heuton
  • 9,318
  • 4
  • 40
  • 52
2
votes
1 answer

Differentiation, .diff() doesn't give expected output

I writing a bit of code, but the problem is found here: [IN>] from sympy import* [IN>] t= Symbol('t') x1 = Function('x1')(t) x2 = Function('x2')(t) y1 = Function('y1')(t) y2 = Function('y2')(t) I define my expression: [IN>]…
iiqof
  • 157
  • 10
2
votes
0 answers

Replacing trigonometric functions in Sympy

I am trying to use Sympy to simplify some trigonometry. I realize that Sympy has a mature set of tools for dealing with this, so it seems like I must be missing something. However, I have spent a lot of time searching and can't seem to find exactly…
2
votes
0 answers

Speeding up Evaluation of Sympy Symbolic Expressions

A Python program I am currently working on (Gaussian process classification) is bottlenecking on evaluation of Sympy symbolic matrices, and I can't figure out what I can, if anything, do to speed it up. Other parts of the program I've already…
mediantis
  • 145
  • 3
  • 14
2
votes
0 answers

Make Sympy's solveset function return expression

Question I wanted to find a way to get sympy's solveset function to return an expression that I can do further algebraic manipulation on. Failing this I want to convert the solveset output to a sympy expression or use an alternate function for a…
Stuart
  • 1,322
  • 1
  • 13
  • 31
2
votes
1 answer

How to find unique non-degenerate equations in a system of linear equations

I am using sympy to produce symbolic polynomial equations. I have roughly 30 variables and roughly 20 constant variables. The highest power that my equations reach is a squared term. I need to take 2^13 of these equations and figure out how many…
Paul Terwilliger
  • 1,596
  • 1
  • 20
  • 45
2
votes
0 answers

A uniq number assocciated with every symbolic variable in sympy

I am generating some symbolic sympy variables: from sympy import symarray A=symarray('A' ,(7,2)) B=symarray('B' ,(4,8)) C=symarray('C' ,(3,4)) So I totally have 7*2 + 4*8 + 3*4 = 58 symbolic variables. I want each one of these variables includes a…
Admia
  • 1,025
  • 3
  • 12
  • 24
2
votes
1 answer

sympy lambdify: how to make more functions (NCDF, NPDF, etc) available

How do I make sympy’s lambdify accept more function names, like a Normal function, for example? To make something like this work: lambdify(('x',), 'NPDF(x, 0, 1)') I don’t mind using the Normal function from the sympy statistics module, as long as…
taylor swift
  • 2,039
  • 1
  • 15
  • 29
2
votes
1 answer

lambdify: Allow limited flexibility in variable names in user defined functions

I know how to use sympy.utilities.lambdify to parse user-defined functions into lambdas like this: f = lambdify(('x',), 'x**2 - 4*x') and I know that I can make it accept a function of t instead using f = lambdify(('t',), 't**2 - 4*t') But how do…
taylor swift
  • 2,039
  • 1
  • 15
  • 29
2
votes
1 answer

SymPy: parse string as function on manifold

I'm trying to define an equation on a manifold using SymPy, and SymPy's diffgeom package. Since this equation is input by a user, it's sent into the program as a string and is therefore defined prior to the manifold definition in the code. To…
2
votes
2 answers

optimize function that includes large matrix operations

I might do a poor job of explaining this, so I'll use an example somewhat similar to my problem, but here goes: I need to compute a complex operation (repeatedly) that is a function of only a few scalars, say, x1, x2 and x3. Then a matrix whose…
bill_e
  • 930
  • 2
  • 12
  • 24
2
votes
1 answer

SymPy lambdify with dot()

Take an undefined function that happens to be named dot, and make it part of lambdify: import numpy import sympy class dot(sympy.Function): pass x = sympy.Symbol('x') a = sympy.Matrix([1, 0, 0]) f = sympy.lambdify(x, dot(a.T, x)) x =…
Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249
2
votes
1 answer

Why can the solve() function in matlab solve this equation while the nsolve() function in sympy requires a guess?

I have a mode, a maximum and minimum value of X (Xmin and Xmax), and a percentage confidence (percentage). I want to use the following functions in order to find the μ and σ of a theoretical log normal distribution: The cumulative distribution…
cachemoi
  • 343
  • 2
  • 13
2
votes
1 answer

Trigonometric identities with Python and Sympy, tan(A/2) = (sin A )/(1 + cos A)

I'm not sure how to get Sympy to perform / simplify these types of identities? It does things like sin(a + b), but doesn't seem to do others (like the one in the title)
baxx
  • 3,956
  • 6
  • 37
  • 75
2
votes
2 answers

How do you specify the assumptions/types on the elements of a Function or IndexedBase?

If I have a simple variable, I can specify the assumptions or type as follows: import sympy as sy k = sy.Symbol('k', integer=True) assert k.is_integer assert k.is_real What if I want to do the the same for an IndexedBase or a Function: f =…
Eric
  • 95,302
  • 53
  • 242
  • 374
1 2 3
99
100