Reputation: 6662
I would like to pretty print an expression to double check that it's what I want, without any manipulations or simplifications. Here's a simple example:
from sympy import *
import abc
init_session()
sigma_1, sigma_0, mu_1, mu_0,x = symbols("sigma_1 sigma_0 mu_1 mu_0 x")
diff = log(1/(sqrt(2*pi*sigma_1**2)) * exp(-(x-mu_1)**2/(2*sigma_1**2))) - log(1/(sqrt(2*pi*sigma_0**2)) * exp(-(x-mu_0)**2/(2*sigma_0**2)))
diff
This has manipulated the expression a bit, but I'd like to see it pretty printed just in the order I entered it, so I can check it easily against the formulas I've got written down.
Is there a way to do that?
Upvotes: 1
Views: 116
Reputation: 91580
You can avoid some simplifications by using
sympify("log(1/(sqrt(2*pi*sigma_1**2)) * exp(-(x-mu_1)**2/(2*sigma_1**2))) - log(1/(sqrt(2*pi*sigma_0**2)) * exp(-(x-mu_0)**2/(2*sigma_0**2)))", evaluate=False)
However, some simplifications can't be avoided. For example, there's no way to keep terms in the same order, and some expressions, like 1/x
and x**-1
are internally represented in the same way. With that being said, there are definitely places where sympify(evaluate=False)
could be improved.
Upvotes: 1