Skip to content

Commit 3b548a2

Browse files
committed
Merge branch 'u/dkrenn/sequences/k-regular-guess' into u/dkrenn/k-regular-warning
* u/dkrenn/sequences/k-regular-guess: Update src/sage/combinat/k_regular_sequence.py fix left/right vector sequence issue in docstrings implement coefficient_of_n (for __getitem__) break long line in doctest
2 parents b52ecc5 + 822ce11 commit 3b548a2

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

src/sage/combinat/k_regular_sequence.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def _repr_(self):
271271
preview=10)
272272

273273
@cached_method
274-
def __getitem__(self, n, **kwds):
274+
def coefficient_of_n(self, n, **kwds):
275275
r"""
276276
Return the `n`-th entry of this sequence.
277277
@@ -289,6 +289,11 @@ def __getitem__(self, n, **kwds):
289289
sage: S[7]
290290
3
291291
292+
This is equivalent to::
293+
294+
sage: S.coefficient_of_n(7)
295+
3
296+
292297
TESTS::
293298
294299
sage: S[-1]
@@ -312,6 +317,8 @@ def __getitem__(self, n, **kwds):
312317
"""
313318
return self.coefficient_of_word(self.parent()._n_to_index_(n), **kwds)
314319

320+
__getitem__ = coefficient_of_n
321+
315322
def __iter__(self):
316323
r"""
317324
Return an iterator over the coefficients of this sequence.
@@ -796,7 +803,7 @@ def subsequence(self, a, b):
796803

797804
zero_M = self.mu[0].parent().zero()
798805
zero_R = self.right.parent().zero()
799-
# Let v(n) = self.__getitem__(n, multiply_left=False)
806+
# Let v(n) = self.coefficient_of_n(n, multiply_left=False)
800807
rule = {}
801808
# We will construct `kernel` and `rule` in such a way that for all
802809
# c in `kernel`,
@@ -832,7 +839,7 @@ def matrix_row(r, c):
832839
b.get(c, 0) * self.left
833840
for c in kernel)),
834841
vector(chain.from_iterable(
835-
(self.__getitem__(c, multiply_left=False) if c >= 0 else zero_R)
842+
(self.coefficient_of_n(c, multiply_left=False) if c >= 0 else zero_R)
836843
for c in kernel)))
837844

838845
return result
@@ -1390,20 +1397,20 @@ def guess(self, f, n_verify=100, max_exponent=10, sequence=None):
13901397
13911398
ALGORITHM:
13921399
1393-
For the purposes of this description, the left vector valued sequence
1394-
associated with a regular sequence consists of the left vector
1395-
multiplied by the corresponding matrix product, but without the right
1396-
vector of the regular sequence.
1400+
For the purposes of this description, the right vector valued sequence
1401+
associated with a regular sequence consists of the
1402+
corresponding matrix product multiplied by the right vector,
1403+
but without the left vector of the regular sequence.
13971404
1398-
The algorithm maintains a left vector valued sequence consisting
1399-
of the left vector valued sequence of the argument ``sequence``
1405+
The algorithm maintains a right vector valued sequence consisting
1406+
of the right vector valued sequence of the argument ``sequence``
14001407
(replaced by an empty tuple if ``sequence`` is ``None``) plus several
14011408
components of the shape `m \mapsto f(k^t\cdot m +r)` for suitable
14021409
``t`` and ``r``.
14031410
14041411
Implicitly, the algorithm also maintains a `d \times n_\mathrm{verify}` matrix ``A``
1405-
(where ``d`` is the dimension of the left vector valued sequence)
1406-
whose columns are the current left vector valued sequence evaluated at
1412+
(where ``d`` is the dimension of the right vector valued sequence)
1413+
whose columns are the current right vector valued sequence evaluated at
14071414
the non-negative integers less than `n_\mathrm{verify}` and ensures that this
14081415
matrix has full row rank.
14091416
@@ -1651,7 +1658,8 @@ def guess(self, f, n_verify=100, max_exponent=10, sequence=None):
16511658
16521659
::
16531660
1654-
sage: A = Seq2((Matrix([[1, 1], [1, 1]]), Matrix([[1, 1], [1, 1]])),
1661+
sage: A = Seq2(
1662+
....: (Matrix([[1, 1], [1, 1]]), Matrix([[1, 1], [1, 1]])),
16551663
....: left=(1, 1), right=(1, 1),
16561664
....: allow_degenerated_sequence=True)
16571665
sage: Seq2.guess(lambda n: n, sequence=A, n_verify=5)
@@ -1674,8 +1682,7 @@ def guess(self, f, n_verify=100, max_exponent=10, sequence=None):
16741682
seq = lambda m: vector([])
16751683
else:
16761684
mu = [M.rows() for M in sequence.mu]
1677-
seq = lambda m: (sequence._mu_of_word_(self._n_to_index_(m))
1678-
* sequence.right)
1685+
seq = lambda m: sequence.coefficient_of_n(m, multiply_left=False)
16791686
logger.info('including %s', sequence)
16801687

16811688
zero = domain(0)
@@ -1685,12 +1692,12 @@ def guess(self, f, n_verify=100, max_exponent=10, sequence=None):
16851692
# `k**t * m + r`
16861693

16871694
# The elements of `lines` will correspond to the current components
1688-
# of the left vector valued sequence described in the algorithm section
1695+
# of the right vector valued sequence described in the algorithm section
16891696
# of the docstring.
16901697

16911698
def values(m, lines):
16921699
"""
1693-
Return current (as defined by ``lines``) left vector valued
1700+
Return current (as defined by ``lines``) right vector valued
16941701
sequence for argument ``m``.
16951702
"""
16961703
return tuple(seq(m)) + tuple(f(k**t_R * m + r_R) for t_R, r_R in lines)
@@ -1705,7 +1712,7 @@ def some_inverse_U_matrix(lines):
17051712
17061713
The output is the inverse of the invertible submatrix and
17071714
the corresponding list of column indices (i.e., arguments to
1708-
the current left vector valued sequence).
1715+
the current right vector valued sequence).
17091716
"""
17101717
d = len(seq(0)) + len(lines)
17111718

0 commit comments

Comments
 (0)