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
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.
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.
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 .
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With