@@ -4757,7 +4757,7 @@ cdef class Expression(Expression_abc):
4757
4757
return matrix([[g.derivative(x) for x in self .arguments()]
4758
4758
for g in self .gradient()])
4759
4759
4760
- def series (self , symbol , order = None ):
4760
+ def series (self , symbol , order = None , algorithm = None ):
4761
4761
r """
4762
4762
Return the power series expansion of ``self`` in terms of the
4763
4763
given variable to the given order.
@@ -4771,6 +4771,8 @@ cdef class Expression(Expression_abc):
4771
4771
- ``order`` -- integer; if nothing given, it is set
4772
4772
to the global default ( ``20``) , which can be changed
4773
4773
using :func:`set_series_precision`
4774
+ - ``algorithm`` -- string ( default: ``None``) ;
4775
+ if specified, ``'ginac'`` or ``'maxima'``
4774
4776
4775
4777
OUTPUT: a power series
4776
4778
@@ -4869,7 +4871,22 @@ cdef class Expression(Expression_abc):
4869
4871
4870
4872
sage: (( 1 - x) ^ -x) . series( x, 8)
4871
4873
1 + 1* x^ 2 + 1/2* x^ 3 + 5/6* x^ 4 + 3/4* x^ 5 + 33/40* x^ 6 + 5/6* x^ 7 + Order( x^ 8)
4874
+
4875
+ Try different algorithms::
4876
+
4877
+ sage: (( 1 - x) ^ -x) . series( x, 8, algorithm="maxima")
4878
+ 1 + 1* x^ 2 + 1/2* x^ 3 + 5/6* x^ 4 + 3/4* x^ 5 + 33/40* x^ 6 + 5/6* x^ 7 + Order( x^ 8)
4879
+ sage: (( 1 - x) ^ -x) . series( x, 8, algorithm="ginac")
4880
+ 1 + 1* x^ 2 + 1/2* x^ 3 + 5/6* x^ 4 + 3/4* x^ 5 + 33/40* x^ 6 + 5/6* x^ 7 + Order( x^ 8)
4872
4881
"""
4882
+ if algorithm is None :
4883
+ algorithm = " ginac" # might be changed in the future
4884
+ if algorithm == " maxima" :
4885
+ # call series() again to convert the result (a rational function in the symbol)
4886
+ # to a SymbolicSeries with the correct order
4887
+ return self .taylor(symbol, 0 , order- 1 ).series(symbol, order, algorithm = " ginac" )
4888
+ if algorithm != " ginac" :
4889
+ raise ValueError (" algorithm must be 'maxima' or 'ginac' if specified" )
4873
4890
cdef Expression symbol0 = self .coerce_in(symbol)
4874
4891
cdef GEx x
4875
4892
cdef SymbolicSeries nex
@@ -4981,6 +4998,10 @@ cdef class Expression(Expression_abc):
4981
4998
4982
4999
- ``( x, a) ``, ``( y, b) ``, ``n`` -- variables with points, degree of polynomial
4983
5000
5001
+ .. SEEALSO::
5002
+
5003
+ :meth:`series`
5004
+
4984
5005
EXAMPLES::
4985
5006
4986
5007
sage: var( 'a, x, z')
0 commit comments