1

I would like to use a function like sympify in order to convert the string "c+1+1" into a Sympy expression. However, I don't want it to simplify.

Right now, I do

from sympy import sympify
print(sympify("c+1+1")) # >> c + 2

The docs mentioned something about a kernS function that might simplify less, but it too does some simplification during the conversion:

from sympy.core.sympify import kernS
print(kernS("c+1+1")) # >> c + 2

What I would like to see back is c+1+1.

How do I turn a string into a Sympy expression without any simplifications?

Pro Q
  • 4,391
  • 4
  • 43
  • 92

1 Answers1

3

Looks like I didn't read far enough in the docs.

The simplification can be stopped by setting the evaluate parameter to False, like so:

from sympy import sympify
print(sympify("c+1+1", evaluate=False)) # >> c + 1 + 1
Pro Q
  • 4,391
  • 4
  • 43
  • 92