unevaluated / lazy series()

49 views
Skip to first unread message

Pablo Puente

unread,
Oct 21, 2013, 3:21:40 PM10/21/13
to sy...@googlegroups.com
Hi,

I understand that series() supports unevaluated Taylor series setting n=None.

I am writing a Wester test case X3 that probably needs unevaluated Taylor series; series(sin(x))/series(cos(x))==series(tan(x)) . In Mathematica syntax:
In[10]:= (* Note: sin(x) = x - x^3/6 + x^5/120 - x^7/5040 + O(x^9)
         cos(x) = 1 - x^2/2 + x^4/24 - x^6/720 + O(x^8)
         tan(x) = x + x^3/3 + 2/15 x^5 + 17/315 x^7 + O(x^9) *)
0. Second
 
In[11]:= tsin = Series[Sin[x], {x, 0, 7}]
0. Second
 
              3    5      7
             x    x      x         8
Out[11]= x - -- + --- - ---- + O[x]
             6    120   5040
 
In[12]:= tcos = Series[Cos[x], {x, 0, 7}]
0. Second
 
              2    4    6
             x    x    x         8
Out[12]= 1 - -- + -- - --- + O[x]
             2    24   720
In[13]:= (* Note that additional terms will be computed as needed *)
0. Second
 
In[14]:= tsin/tcos
0.01 Second
 
              3      5       7
             x    2 x    17 x        8
Out[14]= x + -- + ---- + ----- + O[x]
             3     15     315
 
In[15]:= Series[Tan[x], {x, 0, 7}]
0.01 Second
 
              3      5       7
             x    2 x    17 x        8
Out[15]= x + -- + ---- + ----- + O[x]
             3     15     315

if I try with Sympy  series(sin(x), n=None)/series(cos(x), n=None)) I get TypeError: unsupported operand type(s) for /: 'generator' and 'generator'.

Is i use  series(sin(x))/series(cos(x)) it returns (x - x**3/6 + x**5/120 + O(x**6))/(1 - x**2/2 + x**4/24 + O(x**6))

Is the unevaluated Talyor series support incomplete or is there any other way SymPy can implement this test case?

Thanks,
Pablo Puente

Aaron Meurer

unread,
Oct 21, 2013, 5:55:30 PM10/21/13
to sy...@googlegroups.com
My guess is that the paper is looking for the full series, as a
summation. If that's the case, then it isn't implemented.

If it really is looking for an expansion up to some number of terms,
just take (sin(x).series()/cos(x).series()).series() ==
tan(x).series(). Note that unlike Mathematica, SymPy does not
automatically re-compute the series evaluation when you combine series
expansions with other expressions---you need to call series() again.

Aaron Meurer
> --
> 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 sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> For more options, visit https://groups.google.com/groups/opt_out.

Pablo Puente

unread,
Oct 22, 2013, 12:57:39 AM10/22/13
to sy...@googlegroups.com
(sin(x).series()/cos(x).series()).series() == tan(x).series() 

worked fine. The tests are combining series expansions.

Thanks Aaron,
Pablo


You received this message because you are subscribed to a topic in the Google Groups "sympy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sympy/zAfvm-qmaAg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sympy+un...@googlegroups.com.

Sergey Kirpichev

unread,
Oct 22, 2013, 10:17:59 AM10/22/13
to sy...@googlegroups.com

On Monday, October 21, 2013 11:21:40 PM UTC+4, Pablo Puente wrote:
Is the unevaluated Talyor series support incomplete

In general, yes (through, it's easy to workaround as Aaron suggested above).

Actually, SymPy lacks several abstractions to implement things correctly.  We have
very good Gruntz's limit algorithm, but very naive and limited series support for this one.

The series method should return a specific object (not just Add instance), that supports some
appropriate interface (iterator at least).   And the usual arithmetic operations of course.

Some specific cases covers by the formal power/Laurent series with nice algebraic structure (ring). 

PS: Something is in our wiki:
Reply all
Reply to author
Forward
0 new messages