101
101
102
102
from .recognizable_series import RecognizableSeries
103
103
from .recognizable_series import RecognizableSeriesSpace
104
+ from .recognizable_series import minimize_result
104
105
from sage .misc .cachefunc import cached_function , cached_method
105
106
106
107
@@ -111,15 +112,15 @@ def pad_right(T, length, zero=0):
111
112
112
113
INPUT:
113
114
114
- - ``T`` -- A tuple, list or other iterable.
115
+ - ``T`` -- A tuple, list or other iterable
115
116
116
- - ``length`` -- a nonnegative integer.
117
+ - ``length`` -- a nonnegative integer
117
118
118
- - ``zero`` -- (default: ``0``) the elements to pad with.
119
+ - ``zero`` -- (default: ``0``) the elements to pad with
119
120
120
121
OUTPUT:
121
122
122
- An object of the same type as ``T``.
123
+ An object of the same type as ``T``
123
124
124
125
EXAMPLES::
125
126
@@ -147,14 +148,14 @@ def value(D, k):
147
148
148
149
INPUT:
149
150
150
- - ``D`` -- a tuple or other iterable.
151
+ - ``D`` -- a tuple or other iterable
151
152
152
- - ``k`` -- the base.
153
+ - ``k`` -- the base
153
154
154
155
OUTPUT:
155
156
156
157
An element in the common parent of the base `k` and of the entries
157
- of `D`.
158
+ of `D`
158
159
159
160
EXAMPLES::
160
161
@@ -172,16 +173,16 @@ def split_interlace(n, k, p):
172
173
173
174
INPUT:
174
175
175
- - ``n`` -- an integer.
176
+ - ``n`` -- an integer
176
177
177
- - ``k`` -- an integer specifying the base.
178
+ - ``k`` -- an integer specifying the base
178
179
179
180
- ``p`` -- a positive integer specifying in how many parts
180
181
the input ``n`` is split. This has to be a divisor of ``k``.
181
182
182
183
OUTPUT:
183
184
184
- A tuple of integers.
185
+ A tuple of integers
185
186
186
187
EXAMPLES::
187
188
@@ -384,7 +385,6 @@ def __iter__(self):
384
385
from itertools import count
385
386
return iter (self [n ] for n in count ())
386
387
387
-
388
388
@cached_method
389
389
def is_degenerated (self ):
390
390
r"""
@@ -610,27 +610,30 @@ def _minimized_right_(self):
610
610
"""
611
611
return self .transposed (allow_degenerated_sequence = True )._minimized_left_ ().transposed (allow_degenerated_sequence = True )
612
612
613
- def subsequence (self , a , b , minimize = True ):
613
+ @minimize_result
614
+ def subsequence (self , a , b ):
614
615
r"""
615
616
Return the subsequence with indices `an+b` of this
616
617
`k`-regular sequence.
617
618
618
619
INPUT:
619
620
620
- - ``a`` -- a nonnegative integer.
621
+ - ``a`` -- a nonnegative integer
621
622
622
- - ``b`` -- an integer.
623
+ - ``b`` -- an integer
623
624
624
625
Alternatively, this is allowed to be a dictionary
625
626
`b_j \mapsto c_j`. If so, the result will be the sum
626
627
of all `c_j(an+b_j)`.
627
628
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.
630
633
631
634
OUTPUT:
632
635
633
- A :class:`kRegularSequence`.
636
+ A :class:`kRegularSequence`
634
637
635
638
.. NOTE::
636
639
@@ -682,7 +685,10 @@ def subsequence(self, a, b, minimize=True):
682
685
683
686
sage: C.subsequence(0, 4)
684
687
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
686
692
True
687
693
688
694
The following test that the range for `c` in the code
@@ -815,11 +821,7 @@ def mu_line(r, i, c):
815
821
if c >= 0 else dim * (zero ,)
816
822
for c in kernel ), tuple ())))
817
823
818
- if minimize :
819
- return result .minimized ()
820
- else :
821
- return result
822
-
824
+ return result
823
825
824
826
def backward_differences (self , ** kwds ):
825
827
r"""
@@ -828,12 +830,14 @@ def backward_differences(self, **kwds):
828
830
829
831
INPUT:
830
832
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.
833
837
834
838
OUTPUT:
835
839
836
- A :class:`kRegularSequence`.
840
+ A :class:`kRegularSequence`
837
841
838
842
.. NOTE::
839
843
@@ -860,20 +864,21 @@ def backward_differences(self, **kwds):
860
864
"""
861
865
return self .subsequence (1 , {0 : 1 , - 1 : - 1 }, ** kwds )
862
866
863
-
864
867
def forward_differences (self , ** kwds ):
865
868
r"""
866
869
Return the sequence of forward differences of this
867
870
`k`-regular sequence.
868
871
869
872
INPUT:
870
873
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.
873
878
874
879
OUTPUT:
875
880
876
- A :class:`kRegularSequence`.
881
+ A :class:`kRegularSequence`
877
882
878
883
EXAMPLES::
879
884
@@ -896,8 +901,8 @@ def forward_differences(self, **kwds):
896
901
"""
897
902
return self .subsequence (1 , {1 : 1 , 0 : - 1 }, ** kwds )
898
903
899
-
900
- def partial_sums (self , include_n = False , minimize = True ):
904
+ @ minimize_result
905
+ def partial_sums (self , include_n = False ):
901
906
r"""
902
907
Return the sequence of partial sums of this
903
908
`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):
909
914
the `n`th entry of the result is the sum of the entries up
910
915
to index `n` (included).
911
916
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.
914
921
915
922
OUTPUT:
916
923
917
- A :class:`kRegularSequence`.
924
+ A :class:`kRegularSequence`
918
925
919
926
EXAMPLES::
920
927
@@ -1025,10 +1032,7 @@ def partial_sums(self, include_n=False, minimize=True):
1025
1032
(dim * (0 ,) if include_n else tuple (- self .left ))),
1026
1033
vector (2 * tuple (self .right )))
1027
1034
1028
- if minimize :
1029
- return result .minimized ()
1030
- else :
1031
- return result
1035
+ return result
1032
1036
1033
1037
1034
1038
def _pickle_kRegularSequenceSpace (k , coefficients , category ):
@@ -1277,21 +1281,21 @@ def guess(self, f, n_max=100, max_dimension=10, sequence=None):
1277
1281
INPUT:
1278
1282
1279
1283
- ``f`` -- a function (callable) which determines the sequence.
1280
- It takes nonnegative integers as an input.
1284
+ It takes nonnegative integers as an input
1281
1285
1282
1286
- ``n_max`` -- (default: ``100``) a positive integer. The resulting
1283
1287
`k`-regular sequence coincides with `f` on the first ``n_max``
1284
- terms.
1288
+ terms
1285
1289
1286
1290
- ``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
1288
1292
1289
1293
- ``sequence`` -- (default: ``None``) a `k`-regular sequence used
1290
- for bootstrapping this guessing.
1294
+ for bootstrapping this guessing
1291
1295
1292
1296
OUTPUT:
1293
1297
1294
- A :class:`kRegularSequence`.
1298
+ A :class:`kRegularSequence`
1295
1299
1296
1300
EXAMPLES:
1297
1301
0 commit comments