Skip to content

Commit 5ce5276

Browse files
committed
Merge branch 't/21319/sequences/rec-hash' into t/21204/sequences/k-regular-guess
* t/21319/sequences/rec-hash: 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 c0519f0 + 93c6687 commit 5ce5276

File tree

2 files changed

+274
-123
lines changed

2 files changed

+274
-123
lines changed

src/sage/combinat/k_regular_sequence.py

Lines changed: 37 additions & 33 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_function, 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
@@ -351,28 +352,30 @@ def __iter__(self):
351352
from itertools import count
352353
return iter(self[n] for n in count())
353354

354-
355-
def subsequence(self, a, b, minimize=True):
355+
@minimize_result
356+
def subsequence(self, a, b):
356357
r"""
357358
Return the subsequence with indices `an+b` of this
358359
`k`-regular sequence.
359360
360361
INPUT:
361362
362-
- ``a`` -- a nonnegative integer.
363+
- ``a`` -- a nonnegative integer
363364
364-
- ``b`` -- an integer.
365+
- ``b`` -- an integer
365366
366367
Alternatively, this is allowed to be a dictionary
367368
`b_j \mapsto c_j`. If so, the result will be the sum
368369
of all `c_j(an+b_j)`.
369370
370-
- ``minimize`` -- (default: ``True``) a boolean. If set, then
371-
:meth:`minimized` is called after the operation.
371+
- ``minimize`` -- (default: ``None``) a boolean or ``None``.
372+
If ``True``, then :meth:`minimized` is called after the operation,
373+
if ``False``, then not. If this argument is ``None``, then
374+
the default specified by the parent's ``minimize_results`` is used.
372375
373376
OUTPUT:
374377
375-
A :class:`kRegularSequence`.
378+
A :class:`kRegularSequence`
376379
377380
.. NOTE::
378381
@@ -424,7 +427,10 @@ def subsequence(self, a, b, minimize=True):
424427
425428
sage: C.subsequence(0, 4)
426429
2-regular sequence 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, ...
427-
sage: C.subsequence(1, 0) is C
430+
431+
::
432+
433+
sage: C.subsequence(1, 0, minimize=False) is C
428434
True
429435
430436
The following test that the range for `c` in the code
@@ -536,11 +542,7 @@ def mu_line(r, i, c):
536542
if c >= 0 else dim*(zero,)
537543
for c in kernel), tuple())))
538544

539-
if minimize:
540-
return result.minimized()
541-
else:
542-
return result
543-
545+
return result
544546

545547
def backward_differences(self, **kwds):
546548
r"""
@@ -549,12 +551,14 @@ def backward_differences(self, **kwds):
549551
550552
INPUT:
551553
552-
- ``minimize`` -- (default: ``True``) a boolean. If set, then
553-
:meth:`minimized` is called after the operation.
554+
- ``minimize`` -- (default: ``None``) a boolean or ``None``.
555+
If ``True``, then :meth:`minimized` is called after the operation,
556+
if ``False``, then not. If this argument is ``None``, then
557+
the default specified by the parent's ``minimize_results`` is used.
554558
555559
OUTPUT:
556560
557-
A :class:`kRegularSequence`.
561+
A :class:`kRegularSequence`
558562
559563
.. NOTE::
560564
@@ -581,20 +585,21 @@ def backward_differences(self, **kwds):
581585
"""
582586
return self.subsequence(1, {0: 1, -1: -1}, **kwds)
583587

584-
585588
def forward_differences(self, **kwds):
586589
r"""
587590
Return the sequence of forward differences of this
588591
`k`-regular sequence.
589592
590593
INPUT:
591594
592-
- ``minimize`` -- (default: ``True``) a boolean. If set, then
593-
:meth:`minimized` is called after the operation.
595+
- ``minimize`` -- (default: ``None``) a boolean or ``None``.
596+
If ``True``, then :meth:`minimized` is called after the operation,
597+
if ``False``, then not. If this argument is ``None``, then
598+
the default specified by the parent's ``minimize_results`` is used.
594599
595600
OUTPUT:
596601
597-
A :class:`kRegularSequence`.
602+
A :class:`kRegularSequence`
598603
599604
EXAMPLES::
600605
@@ -617,8 +622,8 @@ def forward_differences(self, **kwds):
617622
"""
618623
return self.subsequence(1, {1: 1, 0: -1}, **kwds)
619624

620-
621-
def partial_sums(self, include_n=False, minimize=True):
625+
@minimize_result
626+
def partial_sums(self, include_n=False):
622627
r"""
623628
Return the sequence of partial sums of this
624629
`k`-regular sequence. That is, the `n`th entry of the result
@@ -630,12 +635,14 @@ def partial_sums(self, include_n=False, minimize=True):
630635
the `n`th entry of the result is the sum of the entries up
631636
to index `n` (included).
632637
633-
- ``minimize`` -- (default: ``True``) a boolean. If set, then
634-
:meth:`minimized` is called after the operation.
638+
- ``minimize`` -- (default: ``None``) a boolean or ``None``.
639+
If ``True``, then :meth:`minimized` is called after the operation,
640+
if ``False``, then not. If this argument is ``None``, then
641+
the default specified by the parent's ``minimize_results`` is used.
635642
636643
OUTPUT:
637644
638-
A :class:`kRegularSequence`.
645+
A :class:`kRegularSequence`
639646
640647
EXAMPLES::
641648
@@ -699,10 +706,7 @@ def partial_sums(self, include_n=False, minimize=True):
699706
(dim*(0,) if include_n else tuple(-self.left))),
700707
vector(2*tuple(self.right)))
701708

702-
if minimize:
703-
return result.minimized()
704-
else:
705-
return result
709+
return result
706710

707711

708712
def _pickle_kRegularSequenceSpace(k, coefficients, category):

0 commit comments

Comments
 (0)