Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prevent Sympy from simplifying expression python after a substitution

Tags:

python

sympy

I'm using Sympy to substiture a set of expressions for another using the Subs function, and I would like for the program not to rearrage or simplify the equations. i.e if i were substituting x+y for a in

a+b+c+a to return x+y+b+c+x+y

Does anyone know of a way to perform this?

Many thanks

like image 646
user124123 Avatar asked Jun 04 '13 15:06

user124123


People also ask

How do you substitute values in SymPy?

The subs() function in SymPy replaces all occurrences of first parameter with second. This function is useful if we want to evaluate a certain expression. For example, we want to calculate values of following expression by substituting a with 5.

How do you substitute a value in a function Python?

With the help of sympy. subs() method, we can substitute all instances of a variable or expression in a mathematical expression with some other variable or expression or value. Parameters: variable – It is the variable or expression which will be substituted.

How do you evaluate a SymPy expression?

To evaluate a numerical expression into a floating point number, use evalf . SymPy can evaluate floating point expressions to arbitrary precision. By default, 15 digits of precision are used, but you can pass any number as the argument to evalf .

How do you write a fraction in SymPy?

SymPy has Rational for working with rational numbers. A rational number is any number that can be expressed as the quotient or fraction p/q of two integers, a numerator p and a non-zero denominator q. The example works with rational numbers. The expression is in the symbolic form; we evaluate it with evalf method.


1 Answers

The only way to do it is to do Add(x, y, b, c, x, y, evaluate=False), which unfortunately isn't very easy to work with.

like image 118
asmeurer Avatar answered Sep 20 '22 03:09

asmeurer