Skip to content

Commit 3a39323

Browse files
dkrenncheuberg
andauthored
Apply suggestions from code review
Co-authored-by: cheuberg <[email protected]>
1 parent dbf2bdc commit 3a39323

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

src/sage/combinat/k_regular_sequence.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ def pad_right(T, length, zero=0):
125125
(1, 2, 3, 0, 0, 0, 0, 0, 0, 0)
126126
sage: pad_right((1, 2, 3), 2)
127127
(1, 2, 3)
128+
sage: from sage.combinat.k_regular_sequence import pad_right
129+
sage: pad_right([(1, 2), (3, 4)], 4, (0, 0))
130+
[(1, 2), (3, 4), (0, 0), (0, 0)]
128131
129132
TESTS::
130133
@@ -993,7 +996,8 @@ def guess(self, f, n_max=100, max_exponent=10, sequence=None):
993996
terms
994997
995998
- ``max_exponent`` -- (default: ``10``) a positive integer specifying
996-
the maximum exponent of `k` which is tried when guessing the sequence
999+
the maximum exponent of `k` which is tried when guessing the sequence,
1000+
i.e., relations between `f(k^t n+r)` are used for `0\le t\le \operatorname{max_exponent}` and `0\le r < k^j`
9971001
9981002
- ``sequence`` -- (default: ``None``) a `k`-regular sequence used
9991003
for bootstrapping the guessing by adding information of the
@@ -1006,20 +1010,20 @@ def guess(self, f, n_max=100, max_exponent=10, sequence=None):
10061010
ALGORITHM:
10071011
10081012
For the purposes of this description, the left vector valued sequence
1009-
associated with a regular sequence is consists of the left vector
1013+
associated with a regular sequence consists of the left vector
10101014
multiplied by the corresponding matrix product, but without the right
10111015
vector of the regular sequence.
10121016
10131017
The algorithm maintains a left vector valued sequence consisting
10141018
of the left vector valued sequence of the argument ``sequence``
1015-
(replaced by an empty tuple if ``sequence`` is `None`) plus several
1019+
(replaced by an empty tuple if ``sequence`` is ``None``) plus several
10161020
components of the shape `m \mapsto f(k^t\cdot m +r)` for suitable
10171021
``t`` and ``r``.
10181022
1019-
Implicitly, the algorithm also maintains a `d \times n_max` matrix ``A``
1023+
Implicitly, the algorithm also maintains a `d \times n_\max` matrix ``A``
10201024
(where ``d`` is the dimension of the left vector valued sequence)
10211025
whose columns are the current left vector valued sequence evaluated at
1022-
the non-negative integers less than `n_max` and ensures that this
1026+
the non-negative integers less than `n_\max` and ensures that this
10231027
matrix has full row rank.
10241028
10251029
EXAMPLES:
@@ -1052,6 +1056,8 @@ def guess(self, f, n_max=100, max_exponent=10, sequence=None):
10521056
1: [ 0 1]
10531057
[-1 2]},
10541058
(0, 1))
1059+
1060+
The ``INFO`` messages mean that the right vector valued sequence is the sequence `(s(n), s(2n+1))^\top`.
10551061
10561062
We guess again, but this time, we use a constant sequence
10571063
for bootstrapping the guessing process::
@@ -1219,11 +1225,10 @@ def guess(self, f, n_max=100, max_exponent=10, sequence=None):
12191225
zero = domain(0)
12201226
one = domain(1)
12211227

1222-
# A `line` will be a triple `(t, r, s)` corresponding to an entry
1223-
# `k**t * m + r` belonging to `M_s`
1224-
# TODO: what is `M_s`?
1228+
# A `line` will be a pair `(t, r)` corresponding to an entry
1229+
# `k**t * m + r`
12251230

1226-
# The elements of `lines` will be correspond to the current components
1231+
# The elements of `lines` will correspond to the current components
12271232
# of the left vector valued sequence described in the algorithm section
12281233
# of the docstring.
12291234

@@ -1234,10 +1239,12 @@ def values(m, lines):
12341239
"""
12351240
return tuple(seq(m)) + tuple(f(k**t_R * m + r_R) for t_R, r_R in lines)
12361241

1237-
@cached_function(key=lambda lines: len(lines)) # we assume that existing lines are not changed (we allow appending of new lines)
1242+
@cached_function(key=lambda lines: len(lines))
1243+
# we assume that existing lines are not changed
1244+
# (we allow appending of new lines)
12381245
def some_inverse_U_matrix(lines):
12391246
r"""
1240-
Find an invertible `d \times d` times submatrix of the matrix
1247+
Find an invertible `d \times d` submatrix of the matrix
12411248
``A`` described in the algorithm section of the docstring.
12421249
12431250
The output is the inverse of the invertible submatrix and
@@ -1256,7 +1263,7 @@ def some_inverse_U_matrix(lines):
12561263
except ZeroDivisionError:
12571264
pass
12581265
else:
1259-
raise RuntimeError('no inverse submatrix found')
1266+
raise RuntimeError('no invertible submatrix found')
12601267

12611268
def linear_combination_candidate(t_L, r_L, lines):
12621269
r"""
@@ -1310,7 +1317,8 @@ def include(line):
13101317
if left is None:
13111318
line_L = (0, 0) # entries (t, r) --> k**t * m + r
13121319
include(line_L)
1313-
left = vector((len(seq(0)) + len(lines)-1)*(zero,) + (one,))
1320+
assert len(lines) == 1
1321+
left = vector(len(seq(0))*(zero,) + (one,))
13141322

13151323
while to_branch:
13161324
line_R = to_branch.pop(0)

0 commit comments

Comments
 (0)