On 13.04.2012 11:36, krastanov.ste...@gmail.com wrote:
I was looking at evalf.py. and I don't understand how it come to be so
complicated. I thought that all the evaluation is automatically done
by mpmath, but there is much pre- and post-processing that I do not
understand. Can someone explain the general idea to me?


The truth is that evalf.py is a bit of a mystery few people understand. Whenever there is a change to it, we try to get the original author to review it ^^.

As I understand it, mpmath implements evaluation of *functions*. So say you want to compute cos(1.2354654...bla); then mpmath is your friend. As long as you have the argument to high enough precision, it will evaluate cos to any precision you desire.

But now suppose you have an expression like sin(x**2 - sqrt(37))/(1 + cos(x)), and you want to evaluate at x=1.2345bla. Mpmath cannot do that for you! You have to compute x**2 - sqrt(37), stick it into sin, then compute the denominator in a similar way, then divide. And you want to make sure that, in the end, the floating point number you return is correct to the number of figures the user requested.

So what I understand this file basically does is this: given an expression, it traverses the expression tree. At each node, say a Mul object, it figures out to what precision it needs to know the arguments in order to compute itself to the desired precision. Then it descends to the leaves with the new precision and repeats. This is complicated by the facts that (1) sometimes there can be cancellation, so the amount of precision you thought you needed might not be enough, and you have to start over, plus (2) to a lesser extent, that evaluations can come from a number of places, at least (a) mpmath, (b) custom functions in evalf.py and (c) _eval_evalf methods.

This is pretty much all I know. Chris may be able to chip in a bit more knowledge. And of course Fredrik Johansson :-).

Best,
Tom

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

Reply via email to