Status: Accepted
Owner: [email protected]
CC: asmeurer
Labels: Type-Defect Priority-Medium
New issue 2592 by [email protected]: Automatic evalf considered harmful
http://code.google.com/p/sympy/issues/detail?id=2592
A while ago i fixed issue 1321, which enabled sin(0.1) ->
0.0998334166468282 etc.
In its current form, this is a bad idea, because suppose we have some
complicated expression expr with (lots of) free symbols. Now suppose I want
to evaluate this at some point. We would want to do expr.subs(mysubs).n().
But every function therein will evaluate itself at the precision of the
input. This is insufficient if there is delicate cancellation. It's even
worse, since the core evalf() does the necessary precision tracking!
An example:
In [1]: a_, b_, p_, q_, _z = symbols('a_ b_ p_ q_ _z')
In [2]: orig = besselk(a_, _z**q_*p_)
In [3]: subs = S('{q_: 3.456965757810806, _z: 1.8293534045443263, p_:
2.6536828486006669, a_: 2.1650555615516485}')
In [5]: expand = besseli(-a_, _z**q_*p_)*gamma(a_)*gamma(-a_ + 1)/2 +
besseli(a_, _z**q_*p_)*gamma(-a_)*gamma(a_ + 1)/2
In [6]: orig.subs(subs)
Out[6]: 1.50931361722845e-10
In [7]: expand.subs(subs)
Out[7]: -5.96046447753906e-8
Without automatic evalf:
[...]
In [7]: expand.subs(subs).n()
Out[7]: 1.50931361722845e-10
Note:
In [10]: expand.args[0].subs(subs).n()
Out[10]: 488054473.942171
In [11]: expand.args[1].subs(subs).n()
Out[11]: -488054473.942171
I think there either needs to be a hint for subs to disable automatic
evalf, or automatic evalf should be disabled altogether. Actually I tend to
like automatic evalf, so maybe subs should scan for Floats, and if there
are any, prevent automatic evalf and call manual evalf in the end?
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy-issues?hl=en.