On 03.05.2011 12:37, mario wrote:

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.


Hi.

This sounds amazing. A couple of questions:

1) Would it be possible to incorporate the new expansion method into the sympy.core.expr methods series/nseries? I.e. instead of calling a new function taylor, we would simply call series and get a quick response if possible.

2) Does this work with special functions? For example say we want to find a series expansion for exp(x)/loggamma(1/x). The asymptotic series expansion for loggamma returns this:

In [1]: loggamma(1/x).nseries(x,n=3,logx=y)
Out[1]:
y   log(2⋅π)   x    1   y
─ + ──────── + ── - ─ - ─ + O(x**3)
2      2       12   x   x

After that can the fast polys code take over?

3) Do you keep track of orders?
In the example you showed I did not see any O(...) terms.



The example mentioned above [exp(x)/loggamma(1/x)] is typical for the kind of expansion we do in limits, in this case we need two terms. This takes about 0.5 seconds currently. If your code can do it any faster please let me know and I would be happy to provide any assistance you may need in incorporating your code with the main series expansions (i.e. my question 1).

Regards,
Tom

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.

Reply via email to