sympy

Peter Otten __peter__ at web.de
Thu Mar 31 13:51:55 EDT 2016


Chris Angelico wrote:

> On Fri, Apr 1, 2016 at 1:55 AM, Peter Otten <__peter__ at web.de> wrote:
>> Hm, the two functions fmsympy() and fm() do not return the same value:
>>
>> $ python -i sympy_diff.py
>> 10000  evaluations with sympy   : dt1 = 0.7178411483764648
>> 10000  evaluations without sympy: dt2 = 0.10177111625671387
>>>>> fm(42)
>> cos(42)
>>>>> fmsympy(42)
>> -0.399985314988351
>>
> 
> Maybe not, but that's simply because one of them is completely
> evaluated. The cosine of 42 radians is indeed -0.4ish.
> 
>>>> math.cos(42)
> -0.39998531498835127

My guess was that the OP fell into the trap that he himself carefully set up 
with the star import, and accidentally used sympy.cos() where he wanted to 
invoke math.cos().

The fix would actually increase the speed difference -- but first make it 
right, then, maybe, fast.

Adding another storey to the tower of guesses, Robert Kern has probably 
already provided the answer ;)




More information about the Python-list mailing list