96
96
97
97
from .recognizable_series import RecognizableSeries
98
98
from .recognizable_series import RecognizableSeriesSpace
99
+ from .recognizable_series import minimize_result
99
100
from sage .misc .cachefunc import cached_method
100
101
101
102
@@ -106,15 +107,15 @@ def pad_right(T, length, zero=0):
106
107
107
108
INPUT:
108
109
109
- - ``T`` -- A tuple, list or other iterable.
110
+ - ``T`` -- A tuple, list or other iterable
110
111
111
- - ``length`` -- a nonnegative integer.
112
+ - ``length`` -- a nonnegative integer
112
113
113
- - ``zero`` -- (default: ``0``) the elements to pad with.
114
+ - ``zero`` -- (default: ``0``) the elements to pad with
114
115
115
116
OUTPUT:
116
117
117
- An object of the same type as ``T``.
118
+ An object of the same type as ``T``
118
119
119
120
EXAMPLES::
120
121
@@ -276,28 +277,30 @@ def __iter__(self):
276
277
from itertools import count
277
278
return iter (self [n ] for n in count ())
278
279
279
-
280
- def subsequence (self , a , b , minimize = True ):
280
+ @ minimize_result
281
+ def subsequence (self , a , b ):
281
282
r"""
282
283
Return the subsequence with indices `an+b` of this
283
284
`k`-regular sequence.
284
285
285
286
INPUT:
286
287
287
- - ``a`` -- a nonnegative integer.
288
+ - ``a`` -- a nonnegative integer
288
289
289
- - ``b`` -- an integer.
290
+ - ``b`` -- an integer
290
291
291
292
Alternatively, this is allowed to be a dictionary
292
293
`b_j \mapsto c_j`. If so, the result will be the sum
293
294
of all `c_j(an+b_j)`.
294
295
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.
297
300
298
301
OUTPUT:
299
302
300
- A :class:`kRegularSequence`.
303
+ A :class:`kRegularSequence`
301
304
302
305
.. NOTE::
303
306
@@ -349,7 +352,10 @@ def subsequence(self, a, b, minimize=True):
349
352
350
353
sage: C.subsequence(0, 4)
351
354
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
353
359
True
354
360
355
361
The following test that the range for `c` in the code
@@ -461,11 +467,7 @@ def mu_line(r, i, c):
461
467
if c >= 0 else dim * (zero ,)
462
468
for c in kernel ), tuple ())))
463
469
464
- if minimize :
465
- return result .minimized ()
466
- else :
467
- return result
468
-
470
+ return result
469
471
470
472
def backward_differences (self , ** kwds ):
471
473
r"""
@@ -474,12 +476,14 @@ def backward_differences(self, **kwds):
474
476
475
477
INPUT:
476
478
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.
479
483
480
484
OUTPUT:
481
485
482
- A :class:`kRegularSequence`.
486
+ A :class:`kRegularSequence`
483
487
484
488
.. NOTE::
485
489
@@ -506,20 +510,21 @@ def backward_differences(self, **kwds):
506
510
"""
507
511
return self .subsequence (1 , {0 : 1 , - 1 : - 1 }, ** kwds )
508
512
509
-
510
513
def forward_differences (self , ** kwds ):
511
514
r"""
512
515
Return the sequence of forward differences of this
513
516
`k`-regular sequence.
514
517
515
518
INPUT:
516
519
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.
519
524
520
525
OUTPUT:
521
526
522
- A :class:`kRegularSequence`.
527
+ A :class:`kRegularSequence`
523
528
524
529
EXAMPLES::
525
530
@@ -542,8 +547,8 @@ def forward_differences(self, **kwds):
542
547
"""
543
548
return self .subsequence (1 , {1 : 1 , 0 : - 1 }, ** kwds )
544
549
545
-
546
- def partial_sums (self , include_n = False , minimize = True ):
550
+ @ minimize_result
551
+ def partial_sums (self , include_n = False ):
547
552
r"""
548
553
Return the sequence of partial sums of this
549
554
`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):
555
560
the `n`th entry of the result is the sum of the entries up
556
561
to index `n` (included).
557
562
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.
560
567
561
568
OUTPUT:
562
569
563
- A :class:`kRegularSequence`.
570
+ A :class:`kRegularSequence`
564
571
565
572
EXAMPLES::
566
573
@@ -624,10 +631,7 @@ def partial_sums(self, include_n=False, minimize=True):
624
631
(dim * (0 ,) if include_n else tuple (- self .left ))),
625
632
vector (2 * tuple (self .right )))
626
633
627
- if minimize :
628
- return result .minimized ()
629
- else :
630
- return result
634
+ return result
631
635
632
636
633
637
def _pickle_kRegularSequenceSpace (k , coefficients , category ):
@@ -808,4 +812,4 @@ def _n_to_index_(self, n):
808
812
try :
809
813
return W (n .digits (self .k ))
810
814
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