@@ -442,6 +442,13 @@ def _repr_(self, latex=False):
442
442
....: vector([0, 1]), vector([1, 0])).transposed()
443
443
sage: repr(S) # indirect doctest
444
444
'[1] + 3*[01] + [10] + 5*[11] + 9*[001] + 3*[010] + ...'
445
+
446
+ TESTS::
447
+
448
+ sage: S = Rec((Matrix([[0]]), Matrix([[0]])),
449
+ ....: vector([1]), vector([1]))
450
+ sage: repr(S) # indirect doctest
451
+ '[] + ...'
445
452
"""
446
453
if not self :
447
454
return '0'
@@ -463,8 +470,22 @@ def summand(w, c):
463
470
return '[{w}]' .format (w = fs (w ))
464
471
return '{c}{times}[{w}]' .format (c = fr (c ), times = times , w = fs (w ))
465
472
473
+ def all_coefficients ():
474
+ number_of_nonzeros = 0
475
+ for w in self .parent ().indices ():
476
+ c = self [w ]
477
+ if c != 0 :
478
+ number_of_nonzeros = 0
479
+ yield (w , self [w ])
480
+ else :
481
+ number_of_nonzeros += 1
482
+ if number_of_nonzeros >= 100 :
483
+ return
484
+
485
+ coefficients = islice (all_coefficients (), 10 )
486
+
466
487
s = ' + ' .join (summand (w , c )
467
- for w , c in islice ( self , 10 ) )
488
+ for w , c in coefficients )
468
489
s = s .replace ('+ -' , '- ' )
469
490
return s + ' + ...'
470
491
@@ -598,6 +619,17 @@ def __iter__(self):
598
619
....: left=vector([0, 1]), right=vector([1, 0]))
599
620
sage: from itertools import islice
600
621
sage: list(islice(S, 10))
622
+ [(word: , 0),
623
+ (word: 0, 0),
624
+ (word: 1, 1),
625
+ (word: 00, 0),
626
+ (word: 01, 1),
627
+ (word: 10, 1),
628
+ (word: 11, 2),
629
+ (word: 000, 0),
630
+ (word: 001, 1),
631
+ (word: 010, 1)]
632
+ sage: list(islice((s for s in S if s[1] != 0), 10))
601
633
[(word: 1, 1),
602
634
(word: 01, 1),
603
635
(word: 10, 1),
@@ -611,7 +643,7 @@ def __iter__(self):
611
643
612
644
sage: S = Rec((Matrix([[1, 0], [0, 1]]), Matrix([[0, -1], [1, 2]])),
613
645
....: left=vector([1, 0]), right=vector([1, 0]))
614
- sage: list(islice(S , 10))
646
+ sage: list(islice((s for s in S if s[1] != 0) , 10))
615
647
[(word: , 1),
616
648
(word: 0, 1),
617
649
(word: 00, 1),
@@ -631,10 +663,7 @@ def __iter__(self):
631
663
sage: iter(S) is not it
632
664
True
633
665
"""
634
- if not self :
635
- return iter ([])
636
- return iter ((w , self [w ])
637
- for w in self .parent ().indices () if self [w ] != 0 )
666
+ return iter ((w , self [w ]) for w in self .parent ().indices ())
638
667
639
668
def is_trivial_zero (self ):
640
669
r"""
0 commit comments