Skip to content

Commit 69313ee

Browse files
committed
Implement algorithm parameter for .series()
1 parent 871ba9d commit 69313ee

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/sage/symbolic/expression.pyx

+22-1
Original file line numberDiff line numberDiff line change
@@ -4757,7 +4757,7 @@ cdef class Expression(Expression_abc):
47574757
return matrix([[g.derivative(x) for x in self.arguments()]
47584758
for g in self.gradient()])
47594759

4760-
def series(self, symbol, order=None):
4760+
def series(self, symbol, order=None, algorithm=None):
47614761
r"""
47624762
Return the power series expansion of ``self`` in terms of the
47634763
given variable to the given order.
@@ -4771,6 +4771,8 @@ cdef class Expression(Expression_abc):
47714771
- ``order`` -- integer; if nothing given, it is set
47724772
to the global default (``20``), which can be changed
47734773
using :func:`set_series_precision`
4774+
- ``algorithm`` -- string (default: ``None``);
4775+
if specified, ``'ginac'`` or ``'maxima'``
47744776
47754777
OUTPUT: a power series
47764778
@@ -4869,7 +4871,22 @@ cdef class Expression(Expression_abc):
48694871
48704872
sage: ((1 - x)^-x).series(x, 8)
48714873
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)
48724881
"""
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")
48734890
cdef Expression symbol0 = self.coerce_in(symbol)
48744891
cdef GEx x
48754892
cdef SymbolicSeries nex
@@ -4981,6 +4998,10 @@ cdef class Expression(Expression_abc):
49814998
49824999
- ``(x, a)``, ``(y, b)``, ``n`` -- variables with points, degree of polynomial
49835000
5001+
.. SEEALSO::
5002+
5003+
:meth:`series`
5004+
49845005
EXAMPLES::
49855006
49865007
sage: var('a, x, z')

0 commit comments

Comments
 (0)