Hi,
I have introduced in github https://github.com/pernici/sympy
the function taylor
which computes the taylor expansion doing computations
with lpoly on QQ if possible; if it fails it computes it on
the Sympy symbolic ring (SR; by this I mean the ring of the
expressions
in Sympy which do not contain the series variable); if also this
fails,
it calls Sympy series. Since computations on QQ are much faster
than on SR, and those on SR are faster than using series,
the overhead of trying the computation in faster way is small.
>>> from sympy import *
>>> from sympy.polys.ltaylor import taylor
>>> from time import time as tm
>>> x,y=symbols('x,y')
This is done on QQ so it is fast:
>>> p = 1/cos(x)
>>> t0=tm();p1=taylor(p,x,0,100);'%.3f'%(tm()-t0)
'0.067'
>>> t0=tm();p2=series(p,x,0,100);'%.3f'%(tm()-t0)
'57.282'
This is done on SR, so it is slower than on QQ:
>>> p = 1/cos(x*sqrt(2))
>>> t0=tm();p1=taylor(p,x,0,30);'%.3f'%(tm()-t0)
'0.084'
>>> t0=tm();p2=series(p,x,0,30);'%.3f'%(tm()-t0)
'1.523'
This is done calling series, so it is a bit slower than calling
directly series:
>>> p = exp(x*log(x))
>>> t0=tm();p1=taylor(p,x,0,20);'%.3f'%(tm()-t0)
'0.148'
restart to avoid caching
...
>>> p = exp(x*log(x))
>>> t0=tm();p2=series(p,x,0,20);'%.3f'%(tm()-t0)
'0.148'
Series with parameter y:
on QQ:
>>> p = 1/sqrt(1 + y*sin(x)**2)
>>> t0=tm();p1=taylor(p,x,0,11);'%.3f'%(tm()-t0)
'0.016'
1 - 17*x**10*y**2/1260 - y*x**2/2 - x**6*y**2/4 + 3*x**4*y**2/8 +
3*x**8*y**2/40 - 7*x**10*y**3/48 - 5*x**6*y**3/16 + 5*x**8*y**3/16 -
35*x**10*y**4/96 + y*x**4/6 + 35*x**8*y**4/128 - 63*x**10*y**5/256 -
y*x**6/45 + y*x**8/630 - y*x**10/14175
>>> t0=tm();p2=series(p,x,0,11);'%.3f'%(tm()-t0)
...
AssertionError
(p1 agrees with Sage taylor(p,x,0,10))
>>> p = sqrt(x + 1/sqrt(1 + y*x + 2*y*x**2))
>>> t0=tm();p1=taylor(p,x,0,5);'%.3f'%(tm()-t0)
'0.008'
>>> t0=tm();p2=series(p,x,0,5);'%.3f'%(tm()-t0)
'11.698'
on SR:
>>> p = sqrt(x + 1/sqrt(2 + y*x + 2*y*x**2))
>>> t0=tm();p1=taylor(p,x,0,5);'%.3f'%(tm()-t0)
'0.074'
>>> t0=tm();p2=series(p,x,0,5);'%.3f'%(tm()-t0)
'17.633'
There are still a few things to do: expansion around x != 0
(to do them I have yet to translate substitutions from rmpoly to
lpoly);
a few more functions (e.g. acos,asin), but otherwise it seems fine to
me;
apart from expansions around x != 0 it should always give a correct
result.
I would appreciate bugs reports.
Done that I will make a pull request (is this the correct procedure?)
Mario
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.