Skip to content

Commit 1c56e7f

Browse files
committed
implement coefficient_of_n (for __getitem__)
1 parent a2d8b25 commit 1c56e7f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/sage/combinat/k_regular_sequence.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def _repr_(self):
238238
preview=10)
239239

240240
@cached_method
241-
def __getitem__(self, n, **kwds):
241+
def coefficient_of_n(self, n, **kwds):
242242
r"""
243243
Return the `n`-th entry of this sequence.
244244
@@ -256,6 +256,11 @@ def __getitem__(self, n, **kwds):
256256
sage: S[7]
257257
3
258258
259+
This is equivalent to::
260+
261+
sage: S.coefficient_of_n(7)
262+
3
263+
259264
TESTS::
260265
261266
sage: S[-1]
@@ -279,6 +284,8 @@ def __getitem__(self, n, **kwds):
279284
"""
280285
return self.coefficient_of_word(self.parent()._n_to_index_(n), **kwds)
281286

287+
__getitem__ = coefficient_of_n
288+
282289
def __iter__(self):
283290
r"""
284291
Return an iterator over the coefficients of this sequence.
@@ -521,7 +528,7 @@ def subsequence(self, a, b):
521528

522529
zero_M = self.mu[0].parent().zero()
523530
zero_R = self.right.parent().zero()
524-
# Let v(n) = self.__getitem__(n, multiply_left=False)
531+
# Let v(n) = self.coefficient_of_n(n, multiply_left=False)
525532
rule = {}
526533
# We will construct `kernel` and `rule` in such a way that for all
527534
# c in `kernel`,
@@ -557,7 +564,7 @@ def matrix_row(r, c):
557564
b.get(c, 0) * self.left
558565
for c in kernel)),
559566
vector(chain.from_iterable(
560-
(self.__getitem__(c, multiply_left=False) if c >= 0 else zero_R)
567+
(self.coefficient_of_n(c, multiply_left=False) if c >= 0 else zero_R)
561568
for c in kernel)))
562569

563570
return result
@@ -1265,8 +1272,7 @@ def guess(self, f, n_verify=100, max_exponent=10, sequence=None):
12651272
seq = lambda m: vector([])
12661273
else:
12671274
mu = [M.rows() for M in sequence.mu]
1268-
seq = lambda m: (sequence._mu_of_word_(self._n_to_index_(m))
1269-
* sequence.right)
1275+
seq = lambda m: sequence.coefficient_of_n(m, multiply_left=False)
12701276
logger.info('including %s', sequence)
12711277

12721278
zero = domain(0)

0 commit comments

Comments
 (0)