@@ -213,6 +213,25 @@ def split_interlace(n, k, p):
213
213
for d in n .digits (k , padto = 1 ))))
214
214
215
215
216
+ class DegeneratedSequenceError (RuntimeError ):
217
+ r"""
218
+ Exception raised if a degenerated sequence
219
+ (see :meth:`~kRegularSequence.is_degenerated`) is detected.
220
+
221
+ EXAMPLES::
222
+
223
+ sage: Seq2 = kRegularSequenceSpace(2, ZZ)
224
+ sage: Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]))
225
+ Traceback (most recent call last):
226
+ ...
227
+ DegeneratedSequenceError: degenerated sequence: mu[0]*right != right.
228
+ Using such a sequence might lead to wrong results.
229
+ You can use 'allow_degenerated_sequence=True' followed
230
+ by a call of method .regenerated() for correcting this.
231
+ """
232
+ pass
233
+
234
+
216
235
class kRegularSequence (RecognizableSeries ):
217
236
218
237
def __init__ (self , parent , mu , left = None , right = None ):
@@ -253,8 +272,11 @@ def __init__(self, parent, mu, left=None, right=None):
253
272
are switched.
254
273
(This is done by calling :meth:`~sage.combinat.recognizable_series.RecognizableSeries.transposed`.)
255
274
256
- - ``heal`` -- (default: ``False``) a boolean. If set, then
257
- :meth:`healed` is called at the end of creating the element.
275
+ - ``allow_degenerated_sequence`` -- (default: ``False``) a boolean. If set, then
276
+ there will be no check if the input is a degenerated sequence
277
+ (see :meth:`is_degenerated`).
278
+ Otherwise the input is checked and a :class:`DegeneratedSequenceError`
279
+ is raised if such a sequence is detected.
258
280
259
281
EXAMPLES::
260
282
@@ -368,36 +390,41 @@ def __iter__(self):
368
390
369
391
370
392
@cached_method
371
- def is_healthy (self ):
393
+ def is_degenerated (self ):
372
394
r"""
373
395
Return whether this `k`-regular sequence satisfies
374
396
`\mu[0] \mathit{right} = \mathit{right}`.
375
397
376
398
EXAMPLES::
377
399
378
400
sage: Seq2 = kRegularSequenceSpace(2, ZZ)
379
- sage: S = Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]))
380
- WARNING:...:Unhealthy sequence: mu[0]*right != right.
381
- Results might be wrong. Use heal=True or
382
- method .healed() for correcting this.
401
+ sage: Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1])) # indirect doctest
402
+ Traceback (most recent call last):
403
+ ...
404
+ DegeneratedSequenceError: degenerated sequence: mu[0]*right != right.
405
+ Using such a sequence might lead to wrong results.
406
+ You can use 'allow_degenerated_sequence=True' followed
407
+ by a call of method .regenerated() for correcting this.
408
+ sage: S = Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]),
409
+ ....: allow_degenerated_sequence=True)
383
410
sage: S
384
411
2-regular sequence 1, 3, 6, 9, 12, 18, 18, 27, 24, 36, ...
385
- sage: S.is_healthy ()
386
- False
412
+ sage: S.is_degenerated ()
413
+ True
387
414
388
415
::
389
416
390
417
sage: C = Seq2((Matrix([[2, 0], [2, 1]]), Matrix([[0, 1], [-2, 3]])),
391
418
....: vector([1, 0]), vector([0, 1]))
392
- sage: C.is_healthy ()
393
- True
419
+ sage: C.is_degenerated ()
420
+ False
394
421
"""
395
422
from sage .rings .integer_ring import ZZ
396
- return (self .mu [ZZ (0 )] * self .right ) = = self .right
423
+ return (self .mu [ZZ (0 )] * self .right ) ! = self .right
397
424
398
425
399
426
@cached_method
400
- def healed (self , minimize = True ):
427
+ def regenerated (self , minimize = True ):
401
428
r"""
402
429
Return a `k`-regular sequence that satisfies
403
430
`\mu[0] \mathit{right} = \mathit{right}`.
@@ -416,56 +443,52 @@ def healed(self, minimize=True):
416
443
sage: Seq2 = kRegularSequenceSpace(2, ZZ)
417
444
418
445
The following linear representation of `S` is chosen bad (is
419
- unhealty , see :meth:`is_healthy `), as `\mu(0)` applied on
446
+ degenerated , see :meth:`is_degenerated `), as `\mu(0)` applied on
420
447
`\mathit{right}` does not equal `\mathit{right}`::
421
448
422
- sage: S = Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]))
423
- WARNING:...:Unhealthy sequence: mu[0]*right != right.
424
- Results might be wrong. Use heal=True or
425
- method .healed() for correcting this.
449
+ sage: S = Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]),
450
+ ....: allow_degenerated_sequence=True)
426
451
sage: S
427
452
2-regular sequence 1, 3, 6, 9, 12, 18, 18, 27, 24, 36, ...
428
- sage: S.is_healthy ()
429
- False
453
+ sage: S.is_degenerated ()
454
+ True
430
455
431
- However, we can heal the sequence `S`::
456
+ However, we can regenerate the sequence `S`::
432
457
433
- sage: H = S.healed ()
458
+ sage: H = S.regenerated ()
434
459
sage: H
435
460
2-regular sequence 1, 3, 6, 9, 12, 18, 18, 27, 24, 36, ...
436
461
sage: H.mu[0], H.mu[1], H.left, H.right
437
462
(
438
463
[ 0 1] [3 0]
439
464
[-2 3], [6 0], (1, 0), (1, 1)
440
465
)
441
- sage: H.is_healthy ()
442
- True
466
+ sage: H.is_degenerated ()
467
+ False
443
468
444
469
TESTS::
445
470
446
- sage: S = Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]))
447
- WARNING:...:Unhealthy sequence: mu[0]*right != right.
448
- Results might be wrong. Use heal=True or
449
- method .healed() for correcting this.
450
- sage: H = S.healed(minimize=False)
471
+ sage: S = Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]),
472
+ ....: allow_degenerated_sequence=True)
473
+ sage: H = S.regenerated(minimize=False)
451
474
sage: H.mu[0], H.mu[1], H.left, H.right
452
475
(
453
476
[1 0] [0 0]
454
477
[0 2], [3 3], (1, 1), (1, 0)
455
478
)
456
- sage: H.is_healthy ()
457
- True
479
+ sage: H.is_degenerated ()
480
+ False
458
481
459
482
::
460
483
461
484
sage: C = Seq2((Matrix([[2, 0], [2, 1]]), Matrix([[0, 1], [-2, 3]])),
462
485
....: vector([1, 0]), vector([0, 1]))
463
- sage: C.is_healthy ()
464
- True
465
- sage: C.healed () is C
486
+ sage: C.is_degenerated ()
487
+ False
488
+ sage: C.regenerated () is C
466
489
True
467
490
"""
468
- if self .is_healthy ():
491
+ if not self .is_degenerated ():
469
492
return self
470
493
471
494
from sage .matrix .special import zero_matrix , identity_matrix
@@ -617,13 +640,11 @@ def subsequence(self, a, b, minimize=True):
617
640
ValueError: a=-1 is not nonnegative.
618
641
619
642
The following linear representation of `S` is chosen bad (is
620
- unhealty , see :meth:`is_healthy `), as `\mu(0)` applied on
643
+ degenerated , see :meth:`is_degenerated `), as `\mu(0)` applied on
621
644
`\mathit{right}` does not equal `\mathit{right}`::
622
645
623
- sage: S = Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]))
624
- WARNING:...:Unhealthy sequence: mu[0]*right != right.
625
- Results might be wrong. Use heal=True or
626
- method .healed() for correcting this.
646
+ sage: S = Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]),
647
+ ....: allow_degenerated_sequence=True)
627
648
sage: S
628
649
2-regular sequence 1, 3, 6, 9, 12, 18, 18, 27, 24, 36, ...
629
650
@@ -636,7 +657,7 @@ def subsequence(self, a, b, minimize=True):
636
657
We get the correct result by
637
658
::
638
659
639
- sage: S.healed ().subsequence(1, -4)
660
+ sage: S.regenerated ().subsequence(1, -4)
640
661
2-regular sequence 0, 0, 0, 0, 1, 3, 6, 9, 12, 18, ...
641
662
"""
642
663
from sage .rings .integer_ring import ZZ
@@ -826,13 +847,11 @@ def partial_sums(self, include_n=False, minimize=True):
826
847
2-regular sequence 0, 1, 3, 6, 10, 15, 21, 28, 36, 45, ...
827
848
828
849
The following linear representation of `S` is chosen bad (is
829
- unhealty , see :meth:`is_healthy `), as `\mu(0)` applied on
850
+ degenerated , see :meth:`is_degenerated `), as `\mu(0)` applied on
830
851
`\mathit{right}` does not equal `\mathit{right}`::
831
852
832
- sage: S = Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]))
833
- WARNING:...:Unhealthy sequence: mu[0]*right != right.
834
- Results might be wrong. Use heal=True or
835
- method .healed() for correcting this.
853
+ sage: S = Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]),
854
+ ....: allow_degenerated_sequence=True)
836
855
sage: S
837
856
2-regular sequence 1, 3, 6, 9, 12, 18, 18, 27, 24, 36, ...
838
857
@@ -865,11 +884,11 @@ def partial_sums(self, include_n=False, minimize=True):
865
884
sage: G.minimized().dimension() == G.dimension()
866
885
True
867
886
868
- Or we heal the sequence `S` first::
887
+ Or we regenerate the sequence `S` first::
869
888
870
- sage: S.healed ().partial_sums(include_n=True, minimize=False)
889
+ sage: S.regenerated ().partial_sums(include_n=True, minimize=False)
871
890
2-regular sequence 1, 4, 10, 19, 31, 49, 67, 94, 118, 154, ...
872
- sage: S.healed ().partial_sums(minimize=False)
891
+ sage: S.regenerated ().partial_sums(minimize=False)
873
892
2-regular sequence 0, 1, 4, 10, 19, 31, 49, 67, 94, 118, ...
874
893
875
894
TESTS::
@@ -1131,7 +1150,10 @@ def some_elements(self):
1131
1150
...
1132
1151
2-regular sequence 2210, 170, 0, 0, 0, 0, 0, 0, 0, 0, ...)
1133
1152
"""
1134
- return super (kRegularSequenceSpace , self ).some_elements (heal = True )
1153
+ return iter (element .regenerated ()
1154
+ for element
1155
+ in super (kRegularSequenceSpace , self ).some_elements (
1156
+ allow_degenerated_sequence = True ))
1135
1157
1136
1158
1137
1159
def _element_constructor_ (self , * args , ** kwds ):
@@ -1144,25 +1166,27 @@ def _element_constructor_(self, *args, **kwds):
1144
1166
1145
1167
sage: Seq2 = kRegularSequenceSpace(2, ZZ)
1146
1168
sage: Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]))
1147
- WARNING:...:Unhealthy sequence: mu[0]*right != right.
1148
- Results might be wrong. Use heal=True or
1149
- method .healed() for correcting this.
1169
+ Traceback (most recent call last):
1170
+ ...
1171
+ DegeneratedSequenceError: degenerated sequence: mu[0]*right != right.
1172
+ Using such a sequence might lead to wrong results.
1173
+ You can use 'allow_degenerated_sequence=True' followed
1174
+ by a call of method .regenerated() for correcting this.
1175
+ sage: Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]),
1176
+ ....: allow_degenerated_sequence=True)
1150
1177
2-regular sequence 1, 3, 6, 9, 12, 18, 18, 27, 24, 36, ...
1151
1178
sage: Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]),
1152
- ....: heal =True)
1179
+ ....: allow_degenerated_sequence =True).regenerated( )
1153
1180
2-regular sequence 1, 3, 6, 9, 12, 18, 18, 27, 24, 36, ...
1154
1181
"""
1155
- heal = kwds .pop ('heal ' , False )
1182
+ allow_degenerated_sequence = kwds .pop ('allow_degenerated_sequence ' , False )
1156
1183
element = super (kRegularSequenceSpace , self )._element_constructor_ (* args , ** kwds )
1157
- if heal :
1158
- element = element .healed ()
1159
- elif not element .is_healthy ():
1160
- import logging
1161
- logger = logging .getLogger (__name__ )
1162
- logger .warning ('Unhealthy sequence: mu[0]*right != right. '
1163
- 'Results might be wrong. '
1164
- 'Use heal=True or method .healed() '
1165
- 'for correcting this.' )
1184
+ if not allow_degenerated_sequence and element .is_degenerated ():
1185
+ raise DegeneratedSequenceError ("degenerated sequence: mu[0]*right != right. "
1186
+ "Using such a sequence might lead to wrong results. "
1187
+ "You can use 'allow_degenerated_sequence=True' followed by "
1188
+ "a call of method .regenerated() "
1189
+ "for correcting this." )
1166
1190
return element
1167
1191
1168
1192
@@ -1271,17 +1295,15 @@ def guess(self, f, n_max=100, max_dimension=10, sequence=None):
1271
1295
)
1272
1296
1273
1297
The following linear representation of `S` is chosen bad (is
1274
- unhealty , see :meth:`is_healthy `), as `\mu(0)` applied on
1298
+ degenerated , see :meth:`is_degenerated `), as `\mu(0)` applied on
1275
1299
`\mathit{right}` does not equal `\mathit{right}`::
1276
1300
1277
- sage: S = Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]))
1278
- WARNING:...:Unhealthy sequence: mu[0]*right != right.
1279
- Results might be wrong. Use heal=True or
1280
- method .healed() for correcting this.
1301
+ sage: S = Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]),
1302
+ ....: allow_degenerated_sequence=True)
1281
1303
sage: S
1282
1304
2-regular sequence 1, 3, 6, 9, 12, 18, 18, 27, 24, 36, ...
1283
- sage: S.is_healthy ()
1284
- False
1305
+ sage: S.is_degenerated ()
1306
+ True
1285
1307
1286
1308
However, we can :meth:`~kRegularSequenceSpace.guess` a `2`-regular sequence of dimension `2`::
1287
1309
@@ -1294,7 +1316,7 @@ def guess(self, f, n_max=100, max_dimension=10, sequence=None):
1294
1316
[-2 3], [6 0], (1, 0), (1, 1)
1295
1317
)
1296
1318
1297
- sage: G == S.healed ()
1319
+ sage: G == S.regenerated ()
1298
1320
True
1299
1321
1300
1322
TESTS::
0 commit comments