Skip to content

Commit cff550e

Browse files
committed
Merge branch 't/21325/sequences/k-regular-subseq' into t/21319/sequences/rec-hash
* t/21325/sequences/k-regular-subseq: 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 15b0405 + 030162a commit cff550e

File tree

2 files changed

+269
-119
lines changed

2 files changed

+269
-119
lines changed

src/sage/combinat/k_regular_sequence.py

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696

9797
from .recognizable_series import RecognizableSeries
9898
from .recognizable_series import RecognizableSeriesSpace
99+
from .recognizable_series import minimize_result
99100
from sage.misc.cachefunc import cached_method
100101

101102

@@ -106,15 +107,15 @@ def pad_right(T, length, zero=0):
106107
107108
INPUT:
108109
109-
- ``T`` -- A tuple, list or other iterable.
110+
- ``T`` -- A tuple, list or other iterable
110111
111-
- ``length`` -- a nonnegative integer.
112+
- ``length`` -- a nonnegative integer
112113
113-
- ``zero`` -- (default: ``0``) the elements to pad with.
114+
- ``zero`` -- (default: ``0``) the elements to pad with
114115
115116
OUTPUT:
116117
117-
An object of the same type as ``T``.
118+
An object of the same type as ``T``
118119
119120
EXAMPLES::
120121
@@ -276,28 +277,30 @@ def __iter__(self):
276277
from itertools import count
277278
return iter(self[n] for n in count())
278279

279-
280-
def subsequence(self, a, b, minimize=True):
280+
@minimize_result
281+
def subsequence(self, a, b):
281282
r"""
282283
Return the subsequence with indices `an+b` of this
283284
`k`-regular sequence.
284285
285286
INPUT:
286287
287-
- ``a`` -- a nonnegative integer.
288+
- ``a`` -- a nonnegative integer
288289
289-
- ``b`` -- an integer.
290+
- ``b`` -- an integer
290291
291292
Alternatively, this is allowed to be a dictionary
292293
`b_j \mapsto c_j`. If so, the result will be the sum
293294
of all `c_j(an+b_j)`.
294295
295-
- ``minimize`` -- (default: ``True``) a boolean. If set, then
296-
:meth:`minimized` is called after the operation.
296+
- ``minimize`` -- (default: ``None``) a boolean or ``None``.
297+
If ``True``, then :meth:`minimized` is called after the operation,
298+
if ``False``, then not. If this argument is ``None``, then
299+
the default specified by the parent's ``minimize_results`` is used.
297300
298301
OUTPUT:
299302
300-
A :class:`kRegularSequence`.
303+
A :class:`kRegularSequence`
301304
302305
.. NOTE::
303306
@@ -349,7 +352,10 @@ def subsequence(self, a, b, minimize=True):
349352
350353
sage: C.subsequence(0, 4)
351354
2-regular sequence 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, ...
352-
sage: C.subsequence(1, 0) is C
355+
356+
::
357+
358+
sage: C.subsequence(1, 0, minimize=False) is C
353359
True
354360
355361
The following test that the range for `c` in the code
@@ -461,11 +467,7 @@ def mu_line(r, i, c):
461467
if c >= 0 else dim*(zero,)
462468
for c in kernel), tuple())))
463469

464-
if minimize:
465-
return result.minimized()
466-
else:
467-
return result
468-
470+
return result
469471

470472
def backward_differences(self, **kwds):
471473
r"""
@@ -474,12 +476,14 @@ def backward_differences(self, **kwds):
474476
475477
INPUT:
476478
477-
- ``minimize`` -- (default: ``True``) a boolean. If set, then
478-
:meth:`minimized` is called after the operation.
479+
- ``minimize`` -- (default: ``None``) a boolean or ``None``.
480+
If ``True``, then :meth:`minimized` is called after the operation,
481+
if ``False``, then not. If this argument is ``None``, then
482+
the default specified by the parent's ``minimize_results`` is used.
479483
480484
OUTPUT:
481485
482-
A :class:`kRegularSequence`.
486+
A :class:`kRegularSequence`
483487
484488
.. NOTE::
485489
@@ -506,20 +510,21 @@ def backward_differences(self, **kwds):
506510
"""
507511
return self.subsequence(1, {0: 1, -1: -1}, **kwds)
508512

509-
510513
def forward_differences(self, **kwds):
511514
r"""
512515
Return the sequence of forward differences of this
513516
`k`-regular sequence.
514517
515518
INPUT:
516519
517-
- ``minimize`` -- (default: ``True``) a boolean. If set, then
518-
:meth:`minimized` is called after the operation.
520+
- ``minimize`` -- (default: ``None``) a boolean or ``None``.
521+
If ``True``, then :meth:`minimized` is called after the operation,
522+
if ``False``, then not. If this argument is ``None``, then
523+
the default specified by the parent's ``minimize_results`` is used.
519524
520525
OUTPUT:
521526
522-
A :class:`kRegularSequence`.
527+
A :class:`kRegularSequence`
523528
524529
EXAMPLES::
525530
@@ -542,8 +547,8 @@ def forward_differences(self, **kwds):
542547
"""
543548
return self.subsequence(1, {1: 1, 0: -1}, **kwds)
544549

545-
546-
def partial_sums(self, include_n=False, minimize=True):
550+
@minimize_result
551+
def partial_sums(self, include_n=False):
547552
r"""
548553
Return the sequence of partial sums of this
549554
`k`-regular sequence. That is, the `n`th entry of the result
@@ -555,12 +560,14 @@ def partial_sums(self, include_n=False, minimize=True):
555560
the `n`th entry of the result is the sum of the entries up
556561
to index `n` (included).
557562
558-
- ``minimize`` -- (default: ``True``) a boolean. If set, then
559-
:meth:`minimized` is called after the operation.
563+
- ``minimize`` -- (default: ``None``) a boolean or ``None``.
564+
If ``True``, then :meth:`minimized` is called after the operation,
565+
if ``False``, then not. If this argument is ``None``, then
566+
the default specified by the parent's ``minimize_results`` is used.
560567
561568
OUTPUT:
562569
563-
A :class:`kRegularSequence`.
570+
A :class:`kRegularSequence`
564571
565572
EXAMPLES::
566573
@@ -624,10 +631,7 @@ def partial_sums(self, include_n=False, minimize=True):
624631
(dim*(0,) if include_n else tuple(-self.left))),
625632
vector(2*tuple(self.right)))
626633

627-
if minimize:
628-
return result.minimized()
629-
else:
630-
return result
634+
return result
631635

632636

633637
def _pickle_kRegularSequenceSpace(k, coefficients, category):
@@ -808,4 +812,4 @@ def _n_to_index_(self, n):
808812
try:
809813
return W(n.digits(self.k))
810814
except OverflowError:
811-
raise ValueError('value {} of index is negative'.format(n))
815+
raise ValueError('value {} of index is negative'.format(n)) from None

0 commit comments

Comments
 (0)