Skip to content

Commit fb5fb62

Browse files
committed
Merge branch 't/21204/sequences/k-regular-guess' into t/21343/k-regular-warning
* t/21204/sequences/k-regular-guess: Trac #21204: fix punctuation Trac #21319: fix punctuation Trac #21318: rmul/lmul preserve identity for multiplying by 1 Trac #21325: fixup test .subsequence being identity Trac #21318: rmul/lmul preserve identity for multiplying by 1 Trac #21325: use (new) decorator minimize_result Trac #21325: remove empty lines, fix punctuation Trac #21325: remove iteritems Trac #21318: fix rmul/lmul issues Trac #21318: use "correct" 1 Trac #21318: use tensor_product in method hadamard_product Trac #21318: use is_trivial_zero in doctest of _neg_ Trac #21318: use (new) .linear_representation in doctests Trac #21318: fix empty lines and punctuation Trac #21318: decorator minimize_result Trac #21203 review issue 10: use "raise ... from None" where approriate
2 parents f776785 + 00047ce commit fb5fb62

File tree

2 files changed

+285
-134
lines changed

2 files changed

+285
-134
lines changed

src/sage/combinat/k_regular_sequence.py

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101

102102
from .recognizable_series import RecognizableSeries
103103
from .recognizable_series import RecognizableSeriesSpace
104+
from .recognizable_series import minimize_result
104105
from sage.misc.cachefunc import cached_function, cached_method
105106

106107

@@ -111,15 +112,15 @@ def pad_right(T, length, zero=0):
111112
112113
INPUT:
113114
114-
- ``T`` -- A tuple, list or other iterable.
115+
- ``T`` -- A tuple, list or other iterable
115116
116-
- ``length`` -- a nonnegative integer.
117+
- ``length`` -- a nonnegative integer
117118
118-
- ``zero`` -- (default: ``0``) the elements to pad with.
119+
- ``zero`` -- (default: ``0``) the elements to pad with
119120
120121
OUTPUT:
121122
122-
An object of the same type as ``T``.
123+
An object of the same type as ``T``
123124
124125
EXAMPLES::
125126
@@ -147,14 +148,14 @@ def value(D, k):
147148
148149
INPUT:
149150
150-
- ``D`` -- a tuple or other iterable.
151+
- ``D`` -- a tuple or other iterable
151152
152-
- ``k`` -- the base.
153+
- ``k`` -- the base
153154
154155
OUTPUT:
155156
156157
An element in the common parent of the base `k` and of the entries
157-
of `D`.
158+
of `D`
158159
159160
EXAMPLES::
160161
@@ -172,16 +173,16 @@ def split_interlace(n, k, p):
172173
173174
INPUT:
174175
175-
- ``n`` -- an integer.
176+
- ``n`` -- an integer
176177
177-
- ``k`` -- an integer specifying the base.
178+
- ``k`` -- an integer specifying the base
178179
179180
- ``p`` -- a positive integer specifying in how many parts
180181
the input ``n`` is split. This has to be a divisor of ``k``.
181182
182183
OUTPUT:
183184
184-
A tuple of integers.
185+
A tuple of integers
185186
186187
EXAMPLES::
187188
@@ -384,7 +385,6 @@ def __iter__(self):
384385
from itertools import count
385386
return iter(self[n] for n in count())
386387

387-
388388
@cached_method
389389
def is_degenerated(self):
390390
r"""
@@ -610,27 +610,30 @@ def _minimized_right_(self):
610610
"""
611611
return self.transposed(allow_degenerated_sequence=True)._minimized_left_().transposed(allow_degenerated_sequence=True)
612612

613-
def subsequence(self, a, b, minimize=True):
613+
@minimize_result
614+
def subsequence(self, a, b):
614615
r"""
615616
Return the subsequence with indices `an+b` of this
616617
`k`-regular sequence.
617618
618619
INPUT:
619620
620-
- ``a`` -- a nonnegative integer.
621+
- ``a`` -- a nonnegative integer
621622
622-
- ``b`` -- an integer.
623+
- ``b`` -- an integer
623624
624625
Alternatively, this is allowed to be a dictionary
625626
`b_j \mapsto c_j`. If so, the result will be the sum
626627
of all `c_j(an+b_j)`.
627628
628-
- ``minimize`` -- (default: ``True``) a boolean. If set, then
629-
:meth:`minimized` is called after the operation.
629+
- ``minimize`` -- (default: ``None``) a boolean or ``None``.
630+
If ``True``, then :meth:`minimized` is called after the operation,
631+
if ``False``, then not. If this argument is ``None``, then
632+
the default specified by the parent's ``minimize_results`` is used.
630633
631634
OUTPUT:
632635
633-
A :class:`kRegularSequence`.
636+
A :class:`kRegularSequence`
634637
635638
.. NOTE::
636639
@@ -682,7 +685,10 @@ def subsequence(self, a, b, minimize=True):
682685
683686
sage: C.subsequence(0, 4)
684687
2-regular sequence 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, ...
685-
sage: C.subsequence(1, 0) is C
688+
689+
::
690+
691+
sage: C.subsequence(1, 0, minimize=False) is C
686692
True
687693
688694
The following test that the range for `c` in the code
@@ -815,11 +821,7 @@ def mu_line(r, i, c):
815821
if c >= 0 else dim*(zero,)
816822
for c in kernel), tuple())))
817823

818-
if minimize:
819-
return result.minimized()
820-
else:
821-
return result
822-
824+
return result
823825

824826
def backward_differences(self, **kwds):
825827
r"""
@@ -828,12 +830,14 @@ def backward_differences(self, **kwds):
828830
829831
INPUT:
830832
831-
- ``minimize`` -- (default: ``True``) a boolean. If set, then
832-
:meth:`minimized` is called after the operation.
833+
- ``minimize`` -- (default: ``None``) a boolean or ``None``.
834+
If ``True``, then :meth:`minimized` is called after the operation,
835+
if ``False``, then not. If this argument is ``None``, then
836+
the default specified by the parent's ``minimize_results`` is used.
833837
834838
OUTPUT:
835839
836-
A :class:`kRegularSequence`.
840+
A :class:`kRegularSequence`
837841
838842
.. NOTE::
839843
@@ -860,20 +864,21 @@ def backward_differences(self, **kwds):
860864
"""
861865
return self.subsequence(1, {0: 1, -1: -1}, **kwds)
862866

863-
864867
def forward_differences(self, **kwds):
865868
r"""
866869
Return the sequence of forward differences of this
867870
`k`-regular sequence.
868871
869872
INPUT:
870873
871-
- ``minimize`` -- (default: ``True``) a boolean. If set, then
872-
:meth:`minimized` is called after the operation.
874+
- ``minimize`` -- (default: ``None``) a boolean or ``None``.
875+
If ``True``, then :meth:`minimized` is called after the operation,
876+
if ``False``, then not. If this argument is ``None``, then
877+
the default specified by the parent's ``minimize_results`` is used.
873878
874879
OUTPUT:
875880
876-
A :class:`kRegularSequence`.
881+
A :class:`kRegularSequence`
877882
878883
EXAMPLES::
879884
@@ -896,8 +901,8 @@ def forward_differences(self, **kwds):
896901
"""
897902
return self.subsequence(1, {1: 1, 0: -1}, **kwds)
898903

899-
900-
def partial_sums(self, include_n=False, minimize=True):
904+
@minimize_result
905+
def partial_sums(self, include_n=False):
901906
r"""
902907
Return the sequence of partial sums of this
903908
`k`-regular sequence. That is, the `n`th entry of the result
@@ -909,12 +914,14 @@ def partial_sums(self, include_n=False, minimize=True):
909914
the `n`th entry of the result is the sum of the entries up
910915
to index `n` (included).
911916
912-
- ``minimize`` -- (default: ``True``) a boolean. If set, then
913-
:meth:`minimized` is called after the operation.
917+
- ``minimize`` -- (default: ``None``) a boolean or ``None``.
918+
If ``True``, then :meth:`minimized` is called after the operation,
919+
if ``False``, then not. If this argument is ``None``, then
920+
the default specified by the parent's ``minimize_results`` is used.
914921
915922
OUTPUT:
916923
917-
A :class:`kRegularSequence`.
924+
A :class:`kRegularSequence`
918925
919926
EXAMPLES::
920927
@@ -1025,10 +1032,7 @@ def partial_sums(self, include_n=False, minimize=True):
10251032
(dim*(0,) if include_n else tuple(-self.left))),
10261033
vector(2*tuple(self.right)))
10271034

1028-
if minimize:
1029-
return result.minimized()
1030-
else:
1031-
return result
1035+
return result
10321036

10331037

10341038
def _pickle_kRegularSequenceSpace(k, coefficients, category):
@@ -1277,21 +1281,21 @@ def guess(self, f, n_max=100, max_dimension=10, sequence=None):
12771281
INPUT:
12781282
12791283
- ``f`` -- a function (callable) which determines the sequence.
1280-
It takes nonnegative integers as an input.
1284+
It takes nonnegative integers as an input
12811285
12821286
- ``n_max`` -- (default: ``100``) a positive integer. The resulting
12831287
`k`-regular sequence coincides with `f` on the first ``n_max``
1284-
terms.
1288+
terms
12851289
12861290
- ``max_dimension`` -- (default: ``10``) a positive integer specifying
1287-
the maxium dimension which is tried when guessing the sequence.
1291+
the maxium dimension which is tried when guessing the sequence
12881292
12891293
- ``sequence`` -- (default: ``None``) a `k`-regular sequence used
1290-
for bootstrapping this guessing.
1294+
for bootstrapping this guessing
12911295
12921296
OUTPUT:
12931297
1294-
A :class:`kRegularSequence`.
1298+
A :class:`kRegularSequence`
12951299
12961300
EXAMPLES:
12971301

0 commit comments

Comments
 (0)