Skip to content

Commit 9c772e5

Browse files
committed
better handling of n_max
1 parent 250a98c commit 9c772e5

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/sage/combinat/k_regular_sequence.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ def _n_to_index_(self, n):
981981
except OverflowError:
982982
raise ValueError('value {} of index is negative'.format(n)) from None
983983

984-
def guess(self, f, n_max=100, max_exponent=10, sequence=None):
984+
def guess(self, f, n_verify=100, max_exponent=10, sequence=None):
985985
r"""
986986
Guess a `k`-regular sequence whose first terms coincide with `(f(n))_{n\geq0}`.
987987
@@ -990,9 +990,9 @@ def guess(self, f, n_max=100, max_exponent=10, sequence=None):
990990
- ``f`` -- a function (callable) which determines the sequence.
991991
It takes nonnegative integers as an input
992992
993-
- ``n_max`` -- (default: ``100``) a positive integer. The resulting
994-
`k`-regular sequence coincides with `f` on the first ``n_max``
995-
terms
993+
- ``n_verify`` -- (default: ``100``) a positive integer. The resulting
994+
`k`-regular sequence coincides with `f` on the first ``n_verify``
995+
terms.
996996
997997
- ``max_exponent`` -- (default: ``10``) a positive integer specifying
998998
the maximum exponent of `k` which is tried when guessing the sequence,
@@ -1019,10 +1019,10 @@ def guess(self, f, n_max=100, max_exponent=10, sequence=None):
10191019
components of the shape `m \mapsto f(k^t\cdot m +r)` for suitable
10201020
``t`` and ``r``.
10211021
1022-
Implicitly, the algorithm also maintains a `d \times n_\max` matrix ``A``
1022+
Implicitly, the algorithm also maintains a `d \times n_\mathrm{verify}` matrix ``A``
10231023
(where ``d`` is the dimension of the left vector valued sequence)
10241024
whose columns are the current left vector valued sequence evaluated at
1025-
the non-negative integers less than `n_\max` and ensures that this
1025+
the non-negative integers less than `n_\mathrm{verify}` and ensures that this
10261026
matrix has full row rank.
10271027
10281028
EXAMPLES:
@@ -1207,7 +1207,7 @@ def guess(self, f, n_max=100, max_exponent=10, sequence=None):
12071207
sage: R = kRegularSequenceSpace(2, QQ)
12081208
sage: one = R.one_hadamard()
12091209
sage: S = R.guess(lambda n: sum(n.bits()), sequence=one) + one
1210-
sage: T = R.guess(lambda n: n*n, sequence=S, n_max=4); T
1210+
sage: T = R.guess(lambda n: n*n, sequence=S, n_verify=4); T
12111211
2-regular sequence 0, 1, 4, 9, 16, 25, 36, 163/3, 64, 89, ...
12121212
sage: T.linear_representation()
12131213
((0, 0, 1),
@@ -1289,9 +1289,9 @@ def some_inverse_U_matrix(lines):
12891289
"""
12901290
d = len(seq(0)) + len(lines)
12911291

1292-
for m_indices in cantor_product(xsrange(n_max+1), repeat=d, min_slope=1):
1292+
for m_indices in cantor_product(xsrange(n_verify), repeat=d, min_slope=1):
12931293
# Iterate over all increasing lists of length d consisting
1294-
# of non-negative integers less than `n_max`.
1294+
# of non-negative integers less than `n_verify`.
12951295

12961296
U = Matrix(domain, d, d, [values(m, lines) for m in m_indices]).transpose()
12971297
try:
@@ -1319,10 +1319,18 @@ def verify_linear_combination(t_L, r_L, linear_combination, lines):
13191319
``r_L``, i.e., `m \mapsto f(k**t_L * m + r_L)`, is the linear
13201320
combination ``linear_combination`` of the current vector valued
13211321
sequence.
1322+
1323+
Note that we only evaluate the subsequence of ``f`` where arguments
1324+
of ``f`` are at most ``n_verify``. This might lead to detection of
1325+
linear dependence which would not be true for higher values, but this
1326+
coincides with the documentation of ``n_verify``.
1327+
However, this is not a guarantee that the given function will never
1328+
be evaluated beyond ``n_verify``, determining an invertible submatrix
1329+
in ``some_inverse_U_matrix`` might require us to do so.
13221330
"""
13231331
return all(f(k**t_L * m + r_L) ==
13241332
linear_combination * vector(values(m, lines))
1325-
for m in xsrange(0, (n_max - r_L) // k**t_L + 1))
1333+
for m in xsrange(0, (n_verify - r_L) // k**t_L + 1))
13261334

13271335
class NoLinearCombination(RuntimeError):
13281336
pass

0 commit comments

Comments
 (0)