sympy/sympy — pull request #1679 by smichr (2012-11-29 08:04:35+00:00)
Title: 3533

A proper evaluation of an expression cannot be done by substituting
evaluated numbers into the expression as a result of precision issues.
Instead, numbers must be evaluated in groups, e.g. (sqrt(3) - sqrt(2)).n()
rather than sqrt(3).n() - sqrt(2).n(). Often this doesn't matter much,
but as the added test shows, it does matter.

evalf needs a serious overhaul to make this right, too, since if evalf
(instead of nfloat) is used on the added expression for this issue, the
same mistake occurs. This is because _matches_commutative deals with
args arg-wise (instead of in lumped args which are all numbers).

The way evalf should work, I believe, is:

1) expr.evalf()
a) expr.is_number is False
i) if subs given, then do the subs thing in evalf
ii) else call to expr._eval_evalf (with n, not prec) to find the

numbers and pass them back to evalf and replace them in the
expr; if there is not expr._eval_evalf routine use the Mixin
routine, changed to apply evalf to each of the args (rather
than returning None as now).
b) normal evalf when expr.is_number