Skip to content

Commit 8e4b772

Browse files
author
Release Manager
committed
gh-39889: Implement algorithm parameter for .series() See #6119 Instead of deprecating it, this just add algorithm=maxima. Which is less intrusive. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #39889 Reported by: user202729 Reviewer(s): Travis Scrimshaw, user202729
2 parents 9d620dd + 632af5d commit 8e4b772

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/sage/symbolic/expression.pyx

Lines changed: 22 additions & 1 deletion
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='ginac'):
47614761
r"""
47624762
Return the power series expansion of ``self`` in terms of the
47634763
given variable to the given order.
@@ -4771,6 +4771,10 @@ 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: ``'ginac'``); one of the following:
4775+
4776+
* ``'ginac'``
4777+
* ``'maxima'``
47744778
47754779
OUTPUT: a power series
47764780
@@ -4869,7 +4873,20 @@ cdef class Expression(Expression_abc):
48694873
48704874
sage: ((1 - x)^-x).series(x, 8)
48714875
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)
4876+
4877+
Try different algorithms::
4878+
4879+
sage: ((1 - x)^-x).series(x, 8, algorithm="maxima")
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)
4881+
sage: ((1 - x)^-x).series(x, 8, algorithm="ginac")
4882+
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)
48724883
"""
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("invalid algorithm")
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)