Hello everyone,
I am trying to use SymPy for a mathematical projet, where I need expressions to be evaluated step-by-step.
Until now, I have always used, for example, sympify("2+2", evaluate=False) and all was fine.
But now I am trying to reconstruct an expression from another object that I have created and I sometimes get in trouble with the way the `minus` is handled. Let me give an example:
Python 3.8.0a2 (v3.8.0a2:23f4589b4b, Feb 25 2019, 10:59:08)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from sympy import *
>>> from sympy.abc import *
>>>
>>> e1 = Mul(Integer(2), Integer(5), evaluate=False)
>>> e1 # all fine here
2*5
>>> print(srepr(e1)) # what I expected
Mul(Integer(2), Integer(5))
>>>
>>> e2 = Mul(Integer(-2), Integer(5), evaluate=False) # now with -2 instead of 2
>>> e2 # Hoops!
-10
>>>
>>> # yet e2 has not been evaluated to Integer(-10) but its repr() above is wrong
>>> print(srepr(e2))
Mul(Integer(-1), Integer(2), Integer(5))
>>> # I'm trying to use expressions in LaTeX documents and there our e2 is still wrong.
... latex(e2)
'- 10'
I'm quite surprised that Mul(Integer(-1), Integer(2), Integer(5)) becomes "-10" when passed through repr(). This is even more surprising:
>>> init_printing()
>>> e2
-2⋅5
How can I prevent the expression to be represented by repr()/latex() in a single integer but keep the -2*5 form?
Many thanks for your help.
Regards,
Jean Abou Samra.