Comment #1 on issue 2878 by asmeu...@gmail.com: numerical evaluation problem
http://code.google.com/p/sympy/issues/detail?id=2878

I think that's what happened. When you did S("0.6"), it created a Float with the default precision (15 digits). evalf'ing it doesn't make a difference, because once you make it as a Float, it only has that 15 digits of precision in there. The digits beyond that are just floating point junk. The S(6)/10 is different because this is exact, so it can be evalf'ed to any precision, without any loss of the original information.

Here's what I get if I set the precision to 100 from the outset:

In [27]: a.subs(x, Float("0.6", 100))
Out[27]: -3.571835597757109319424323588454190498287218733821245816297268260086351987208556861485775068313037593e-102

So the solution is to either use exact numbers up until the point where you want to get floating point numbers, or else to always put high enough precision on your floating point numbers so that the final result will be correct to the precision you desire.

P.S., here's a trick to symbolically simplify this:

In [33]: a.replace(sin, lambda x:sqrt(1 - cos(x)**2)).expand()
Out[33]: 0

Unfortunately, trigsimp() isn't smart enough to do this automatically yet.

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

Reply via email to