@@ -3136,7 +3136,6 @@ def derivative(self, *args):
3136
3136
coeff_stream = self ._coeff_stream
3137
3137
if isinstance (coeff_stream , Stream_zero ):
3138
3138
return self
3139
- BR = P .base_ring ()
3140
3139
if (isinstance (coeff_stream , Stream_exact )
3141
3140
and not coeff_stream ._constant ):
3142
3141
if coeff_stream ._approximate_order >= 0 and coeff_stream ._degree <= order :
@@ -3567,6 +3566,85 @@ def coefficient(n):
3567
3566
3568
3567
compose = __call__
3569
3568
3569
+ def derivative (self , * args ):
3570
+ """
3571
+ Return the derivative of the Taylor series.
3572
+
3573
+ INPUT:
3574
+
3575
+ EXAMPLES::
3576
+
3577
+ sage: T.<z> = LazyTaylorSeriesRing(ZZ)
3578
+ sage: z.derivative()
3579
+ 1
3580
+ sage: (1+z+z^2).derivative(3)
3581
+ 0
3582
+ sage: (1/(1-z)).derivative()
3583
+ 1 + 2*z + 3*z^2 + 4*z^3 + 5*z^4 + 6*z^5 + 7*z^6 + O(z^7)
3584
+
3585
+ sage: R.<q> = QQ[]
3586
+ sage: L.<x, y> = LazyTaylorSeriesRing(R)
3587
+ sage: f = 1/(1-q*x+y); f
3588
+ 1 + (q*x-y) + (q^2*x^2+(-2*q)*x*y+y^2) + (q^3*x^3+(-3*q^2)*x^2*y+3*q*x*y^2-y^3) + (q^4*x^4+(-4*q^3)*x^3*y+6*q^2*x^2*y^2+(-4*q)*x*y^3+y^4) + (q^5*x^5+(-5*q^4)*x^4*y+10*q^3*x^3*y^2+(-10*q^2)*x^2*y^3+5*q*x*y^4-y^5) + (q^6*x^6+(-6*q^5)*x^5*y+15*q^4*x^4*y^2+(-20*q^3)*x^3*y^3+15*q^2*x^2*y^4+(-6*q)*x*y^5+y^6) + O(x,y)^7
3589
+ sage: f.derivative(q)
3590
+ x + (2*q*x^2+(-2)*x*y) + (3*q^2*x^3+(-6*q)*x^2*y+3*x*y^2) + (4*q^3*x^4+(-12*q^2)*x^3*y+12*q*x^2*y^2+(-4)*x*y^3) + (5*q^4*x^5+(-20*q^3)*x^4*y+30*q^2*x^3*y^2+(-20*q)*x^2*y^3+5*x*y^4) + (6*q^5*x^6+(-30*q^4)*x^5*y+60*q^3*x^4*y^2+(-60*q^2)*x^3*y^3+30*q*x^2*y^4+(-6)*x*y^5) + O(x,y)^7
3591
+
3592
+ """
3593
+ P = self .parent ()
3594
+ R = P ._laurent_poly_ring
3595
+ V = R .gens ()
3596
+ order = 0
3597
+ vars = []
3598
+ gen_vars = []
3599
+ for x in derivative_parse (args ):
3600
+ if x is None :
3601
+ order += 1
3602
+ elif x in V :
3603
+ gen_vars .append (x )
3604
+ else :
3605
+ vars .append (x )
3606
+
3607
+ if P ._arity > 1 and order :
3608
+ raise ValueError ("for multivariate series you have to specify the variable with respect to which the derivative should be taken" )
3609
+ else :
3610
+ order += len (gen_vars )
3611
+
3612
+ coeff_stream = self ._coeff_stream
3613
+ if isinstance (coeff_stream , Stream_zero ):
3614
+ return self
3615
+
3616
+ if P ._arity > 1 :
3617
+ coeff_stream = Stream_shift (Stream_map_coefficients (coeff_stream ,
3618
+ lambda c : c .derivative (gen_vars + vars ),
3619
+ P ._laurent_poly_ring ),
3620
+ - len (gen_vars ))
3621
+ return P .element_class (P , coeff_stream )
3622
+
3623
+ if (isinstance (coeff_stream , Stream_exact )
3624
+ and not coeff_stream ._constant ):
3625
+ if coeff_stream ._degree <= order :
3626
+ return P .zero ()
3627
+ if vars :
3628
+ coeffs = [prod (i - k for k in range (order )) * c .derivative (vars )
3629
+ for i , c in enumerate (coeff_stream ._initial_coefficients ,
3630
+ coeff_stream ._approximate_order )]
3631
+ else :
3632
+ coeffs = [prod (i - k for k in range (order )) * c
3633
+ for i , c in enumerate (coeff_stream ._initial_coefficients ,
3634
+ coeff_stream ._approximate_order )]
3635
+ coeff_stream = Stream_exact (coeffs ,
3636
+ self ._coeff_stream ._is_sparse ,
3637
+ order = coeff_stream ._approximate_order - order ,
3638
+ constant = coeff_stream ._constant )
3639
+ return P .element_class (P , coeff_stream )
3640
+
3641
+ coeff_stream = Stream_derivative (self ._coeff_stream , order )
3642
+ if vars :
3643
+ coeff_stream = Stream_map_coefficients (coeff_stream ,
3644
+ lambda c : c .derivative (vars ),
3645
+ R )
3646
+ return P .element_class (P , coeff_stream )
3647
+
3570
3648
def _format_series (self , formatter , format_strings = False ):
3571
3649
"""
3572
3650
Return nonzero ``self`` formatted by ``formatter``.
0 commit comments