Skip to content

Commit e7eabc4

Browse files
author
Release Manager
committed
gh-39480: Added enhancement for power series that allows access to the coefficients of specific terms Fixes #39314. Adds an enhancement to power series that when given a tuple of values corresponding to the powers of the term gives you the coefficient for said term. Functionality is similar to how coefficients are retrieved for multivariable polynomials. Also added a test for the enhancement. ### 📝 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 URL: #39480 Reported by: Noel-Roemmele Reviewer(s): Martin Rubey, Noel-Roemmele, Travis Scrimshaw
2 parents d76572e + d6e3515 commit e7eabc4

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

src/sage/rings/multi_power_series_ring_element.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,11 @@ def _im_gens_(self, codomain, im_gens, base_map=None):
673673

674674
def __getitem__(self, n):
675675
"""
676-
Return summand of total degree ``n``.
676+
Return the coefficient of the monomial ``x1^e1 * x2^e2 * ... * xk^ek``
677+
if ``n = (e_1, e2, ..., ek)`` is a tuple whose length is the number of
678+
variables ``x1,x2,...,xk`` in the power series ring.
679+
680+
Return the sum of the monomials of degree ``n`` if ``n`` is an integer.
677681
678682
TESTS::
679683
@@ -690,9 +694,30 @@ def __getitem__(self, n):
690694
...
691695
IndexError: Cannot return terms of total degree greater than or
692696
equal to precision of self.
693-
"""
697+
698+
Ensure that the enhancement detailed in :issue:`39314` works as intended::
699+
700+
sage: R.<x,y> = QQ[[]]
701+
sage: ((x+y)^3)[2,1]
702+
3
703+
sage: f = 1/(1 + x + y)
704+
sage: f[2,5]
705+
-21
706+
sage: f[0,30]
707+
Traceback (most recent call last):
708+
...
709+
IndexError: Cannot return the coefficients of terms of total degree
710+
greater than or equal to precision of self.
711+
"""
712+
if type(n) is tuple:
713+
if sum(n) >= self.prec():
714+
raise IndexError("Cannot return the coefficients of terms of " +
715+
"total degree greater than or equal to " +
716+
"precision of self.")
717+
return self._bg_value[sum(n)][n]
694718
if n >= self.prec():
695-
raise IndexError("Cannot return terms of total degree greater than or equal to precision of self.")
719+
raise IndexError("Cannot return terms of total degree greater " +
720+
"than or equal to precision of self.")
696721
return self.parent(self._bg_value[n])
697722

698723
def __invert__(self):

0 commit comments

Comments
 (0)