Hi,

On 9 July 2013 15:05, Freddie Witherden <[email protected]> wrote:

> Hi all,
>
> Consider the following snippet:
>
> import sympy as sy
> from sympy.abc import x
> from sympy.mpmath import mp
>
> N = 4
> mp.dps = 30
>
> # Way 1
> Pn1 = sy.legendre_poly(N, x)
> dPn1 = Pn1.diff()
>
> print dPn1.evalf(mp.dps, subs={x: mp.sqrt(2)})
>
> # Way 2
> Pn2 = sy.Poly(sy.legendre_poly(N, x))
> dPn2 = Pn2.diff()
>
> print dPn2.evalf(mp.dps, subs={x: mp.sqrt(2)})
>
>
> which gives:
>
> 38.8908729652601138420464399158
> 38.8908729654156128699457970986
>
> with the second value (from dPn2.evalf(...)) being incorrect.  It
> appears as if the mp.sqrt(2) in the second case is being cast to a float
> somewhere when evaluating an sy.Poly.  Can someone explain what is going
> on?
>

What version of SymPy do you use? I can't exactly reproduce your results,
thought Poly.evalf() is wrong. Here are results for the master branch (as
of e06036a2daae4c2f6fc36e443a7516c6d7247df5):

In [1]: from sympy.integrals.rationaltools import ratint
KeyboardInterrupt

In [1]: import sympy.mpmath as mp

In [2]: dPn1 = legendre_poly(4, x).diff()

In [3]: dPn2 = Poly(legendre_poly(4, x)).diff()

In [4]: dPn1.evalf(30, {x: mp.sqrt(2)})
Out[4]: 38.8908729652601232676574205324

In [5]: dPn2.evalf(30, {x: mp.sqrt(2)})
Out[5]: 38.8908729654156128699457970986

In [6]: dPn1.subs(x, sqrt(2)).evalf(30)
Out[6]: 38.8908729652601138420464399158

In [7]: dPn2.subs(x, sqrt(2)).evalf(30)
Out[7]: 38.8908729652601138420464399158

In this https://github.com/sympy/sympy/pull/2126 pull request dPn2.evalf()
was "fixed" and now gives (almost) the same result as dPn2.evalf():

In [1]: import sympy.mpmath as mp

In [2]: dPn1 = legendre_poly(4, x).diff()

In [3]: dPn2 = Poly(legendre_poly(4, x)).diff()

In [4]: dPn1.evalf(30, {x: mp.sqrt(2)})
Out[4]: 38.8908729652601232676574205324

In [5]: dPn2.evalf(30, {x: mp.sqrt(2)})
Out[5]: 38.8908729652601232676574205926

In [6]: dPn1.subs(x, sqrt(2)).evalf(30)
Out[6]: 38.8908729652601138420464399158

In [7]: dPn2.subs(x, sqrt(2)).evalf(30)
Out[7]: 38.8908729652601138420464399158


> Polemically yours, Freddie.
>
>
Mateusz

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to