evaluate=False by default?

235 views
Skip to first unread message

Gabor Takacs

unread,
Oct 2, 2011, 5:14:46 PM10/2/11
to sympy
Hi,

I experienced that sympy applies automatic evaluation at expression
creation by default
(the evaluate parameter is True in the constructors).

Therefore, e.g.
- I**3 evaluates to -I
- Pow(I, 3, evaluate=False) evaluates to I**3, but
Pow(I, 3, evaluate=False) * 1 evaluates to -I

Is it possible to change the default behaviour to "no automatic
evaluation at expression creation"?
(so that I**3 evaluates to I**3)

Gabor

gsagrawal

unread,
Oct 3, 2011, 12:44:52 AM10/3/11
to sy...@googlegroups.com
yes , i am facing the same problems.
specially when you try to convert a string format user input into a valid sympy expression using simpify(expr) which internally calls Add and Mul with default parameter (evaluate=true). is there any way to control this ?


--
You received this message because you are subscribed to the Google Groups "sympy" group.
To post to this group, send email to sy...@googlegroups.com.
To unsubscribe from this group, send email to sympy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sympy?hl=en.


Aaron Meurer

unread,
Oct 3, 2011, 11:43:04 AM10/3/11
to sy...@googlegroups.com
Currently there is not, but I don't think it would be very difficult
to add the behavior in as a global parameter at least. If you want to
just make it an option to sympify (like sympify('1 + 1',
evaluate=False)), I don't know how difficult that would be, since the
parser would have to be modified, but it should be doable. But we
definitely would accept a patch that does so. Please open an issue for
it in any case.

As for multiplying by something causing an unevaluated expression to
evaluate, I consider this to be a bug. It no longer does it in master
with 1 (because the constructor ignores the identity), but it will
still do it with any other number.

Aaron Meurer

gsagrawal

unread,
Oct 4, 2011, 1:53:23 AM10/4/11
to sy...@googlegroups.com
i was using one global variable to achieve this.
i have modified core->operation-> AssocOp with the version 0.6.5
and sympify('1 + 1',evaluate=False)) was working exactly fine returning "1+1"
but recently i have shifted to version 0.7.1
Issue is now when i call sympify("2*x+3*x) , this is not even going in to AssocOp class __new_ method.
and somehow it returns 5*x
could you please tell which class does sympify uses to evaluate Add.
i am kind of stucked here.

gsagrawal

unread,
Oct 4, 2011, 4:07:41 AM10/4/11
to sy...@googlegroups.com
Found the issue,
Actually my below issue was because of catching. i was trying to parse same expression twice ,1st with evaluate=True and 2nd time with evaluate =False. so because of catching it is returning the previous result only
but again my problem remain as caching is there. so any way to fix this ?

Aaron Meurer

unread,
Oct 4, 2011, 12:24:16 PM10/4/11
to sy...@googlegroups.com
You can turn caching off. See the "How do I turn off caching" section
of https://github.com/sympy/sympy/wiki/faq. You need to set the
SYMPY_USE_CACHE environment variable to "no".

This will slow parts of SymPy down by quite a bit, so if the
performance is too slow when you do this, you might find the specific
part that is being cached and either modify it to include evaluate in
the cache or remove the caching there. The caching is handled by the
@cacheit decorator.

Aaron Meurer

Reply all
Reply to author
Forward
0 new messages