-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSYT3lines.py
1005 lines (885 loc) · 32.3 KB
/
SYT3lines.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
This module implement 3 line rectangular Young tableau and the set of all
of them.
EXAMPLES:
>>> SYT3lines([[5, 9, 11, 12], [2, 6, 7, 10], [1, 3, 4, 8]])
---------------------
| 5 | 9 | 11 | 12 |
---------------------
| 2 | 6 | 7 | 10 |
---------------------
| 1 | 3 | 4 | 8 |
---------------------
"""
#*****************************************************************************
# Copyright (C) 2021 Nicolas Borie <nicolas dot borie at univ-eiffel . fr>
#
# Distributed under the terms of Creative Commons Attribution-ShareAlike 3.0
# Creative Commons CC-by-SA 3.0
#
# This code is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# The full text of the CC-By-SA 3.0 is available at:
#
# https://creativecommons.org/licenses/by-sa/3.0/
# https://creativecommons.org/licenses/by-sa/3.0/fr/
#*****************************************************************************
from math import log, factorial
from copy import deepcopy
from random import randint
def is_SYT3line(values, verbose=False):
"""
Returns `True` is values is the content of a
three lines standard Young tableau.
EXAMPLES:
>>> is_SYT3line([[3], [2], [1]], True)
True
>>> is_SYT3line([[], [], []])
True
>>> is_SYT3line([[], []], True)
Content does not contain 3 lines.
False
>>> is_SYT3line([[7, 8, 9], [4, 5, 6], [1, 2, 3]], True)
True
>>> is_SYT3line([[7, 8, 9], [4, 6, 5], [1, 2, 3]], True)
The 3 lines are not increasing.
False
>>> is_SYT3line([[7, 8], [4, 5, 6], [1, 2, 3]], True)
The 3 lines does not have same lenght.
False
>>> is_SYT3line([], True)
Content seems to be empty.
False
>>> is_SYT3line([[]], True)
Content does not contain 3 lines.
False
>>> is_SYT3line([[], [], [1]], True)
The 3 lines does not have same lenght.
False
>>> is_SYT3line([[5, 6], [3, 4], [2, 1]], True)
The 3 lines are not increasing.
False
>>> is_SYT3line([[5, 4], [3, 6], [1, 2]], True)
The 3 lines are not increasing.
False
"""
if not values:
if verbose:
print('Content seems to be empty.')
return False
n = len(values[0])
if len(values) != 3:
if verbose:
print('Content does not contain 3 lines.')
return False
for j in range(1, 3):
if len(values[j]) != n:
if verbose:
print('The 3 lines does not have same lenght.')
return False
for j in range(3):
for i in range(1, n):
if values[j][i] < values[j][i-1]:
if verbose:
print('The 3 lines are not increasing.')
return False
for i in range(n):
for j in range(1, 3):
if values[j-1][i] < values[j][i]:
if verbose:
print('The colonms are not increasing.')
return False
if sorted(sum([list(vals) for vals in values], [])) != list(range(1, 3*n + 1)):
if verbose:
print('The content is not standard (values in 1 to 3n).')
return False
return True
def right_rotation_prod(t, p1, p2):
"""
Proceed a right rotation over edge linking product `p1` and `p2`
inside `t`. Coproduct `p1` must be on the left input of coproduct
`p2`.
EXAMPLES:
>>> rrp = right_rotation_prod
>>> rrp([[4, 7, 9], [2, 5, 8], [1, 3, 6]], 4, 7)
[[6, 7, 9], [2, 4, 8], [1, 3, 5]]
>>> rrp(rrp([[4, 7, 9], [2, 5, 8], [1, 3, 6]], 4, 7), 7, 9)
[[6, 8, 9], [2, 4, 7], [1, 3, 5]]
>>> rrp(rrp(rrp([[4, 7, 9], [2, 5, 8], [1, 3, 6]], 4, 7), 7, 9), 6, 8)
[[7, 8, 9], [2, 4, 6], [1, 3, 5]]
>>> rrp([[4, 7, 9], [2, 5, 8], [1, 3, 6]], 7, 9)
[[4, 8, 9], [2, 5, 7], [1, 3, 6]]
>>> rrp(rrp([[4, 7, 9], [2, 5, 8], [1, 3, 6]], 7, 9), 4, 8)
[[7, 8, 9], [2, 4, 6], [1, 3, 5]]
"""
n = len(t[0])
for i in range(n-1):
if t[0][i+1] <= p2 and t[0][i+1] > p1:
t[0][i] = t[0][i+1]-1
for j in range(1, 3):
for i in range(n):
if t[j][i] < p2 and t[j][i] > p1:
t[j][i] = t[j][i] - 1
return t
def left_rotation_prod(t, p1, p2):
"""
"""
raise NotImplementedError("Please code me!")
def left_rotation_coprod(t, i1, i2):
"""
Proceed a left rotation over edge linking coproduct `i1` and `i2`
inside `t`. Coproduct `i2` must be on the right ouput of coproduct
`i1`.
EXAMPLES:
>>> lrc = left_rotation_coprod
>>> lrc([[4, 7, 9], [2, 5, 8], [1, 3, 6]], 1, 3)
[[4, 7, 9], [3, 5, 8], [1, 2, 6]]
>>> lrc(lrc([[4, 7, 9], [2, 5, 8], [1, 3, 6]], 1, 3), 1, 6)
[[5, 7, 9], [4, 6, 8], [1, 2, 3]]
>>> lrc([[4, 7, 9], [2, 5, 8], [1, 3, 6]], 3, 6)
[[5, 7, 9], [2, 6, 8], [1, 3, 4]]
>>> lrc(lrc([[4, 7, 9], [2, 5, 8], [1, 3, 6]], 3, 6), 1, 3)
[[5, 7, 9], [3, 6, 8], [1, 2, 4]]
>>> lrc(lrc(lrc([[4, 7, 9], [2, 5, 8], [1, 3, 6]], 3, 6), 1, 3), 2, 4)
[[5, 7, 9], [4, 6, 8], [1, 2, 3]]
"""
n = len(t[0])
for i in range(n-1, -1, -1):
if t[2][i] <= i2 and t[2][i] > i1:
t[2][i] = t[2][i-1]+1
for j in range(2):
for i in range(n):
if t[j][i] < i2 and t[j][i] > i1:
t[j][i] = t[j][i] + 1
return t
def right_rotation_coprod(t, o1, o2):
"""
"""
raise NotImplementedError("Please code me!")
def jump_over_rotation(t, k):
"""
Rotation comming from the triangulations point of view making a
jump of a coproduct over product. Before the left output of the
coproduct is connected to the right input of the product and after
the input of the coproduct is connected the single output of the
product over it.
EXAMPLES:
>>> jump_over_rotation([[4, 7, 9], [2, 5, 8], [1, 3, 6]], 3)
[[3, 7, 9], [2, 5, 8], [1, 4, 6]]
>>> jump_over_rotation([[4, 7, 9], [2, 5, 8], [1, 3, 6]], 6)
[[4, 6, 9], [2, 5, 8], [1, 3, 7]]
>>> jump_over_rotation([[4, 6], [2, 5], [1, 3]], 3)
[[3, 6], [2, 5], [1, 4]]
"""
n = len(t[0])
for j in range(3):
for i in range(n):
if t[j][i] == k:
t[j][i] = k+1
elif t[j][i] == k+1:
t[j][i] = k
return t
def land_over_rotation(t, i, j, k):
"""
Rotation comming from the triangulations point of view making a
land of a coproduct comming over a product. Before the input of
the coproduct is connected the single output of the product over
it. After the right output of the coproduct is connected to the
left input of the product
i : label of the wire connected the two operators
i-1 : last right input of product
i+1 : fisrt left output of coproduct
j : left input of product
k : right output of coproduct
EXAMPLES:
>>> lor = land_over_rotation
>>> lor([[3, 6],[2, 5],[1, 4]], 4, 2, 6)
[[5, 6], [3, 4], [1, 2]]
>>> lor([[3, 6, 9],[2, 5, 8],[1, 4, 7]], 4, 2, 6)
[[5, 6, 9], [3, 4, 8], [1, 2, 7]]
>>> lor([[3, 6, 9],[2, 5, 8],[1, 4, 7]], 7, 5, 9)
[[3, 8, 9], [2, 6, 7], [1, 4, 5]]
"""
n = len(t[0])
for m in range(3):
for p in range(n):
if t[m][p] >= j and t[m][p] < i:
t[m][p] += k-i
elif t[m][p] >= i and t[m][p] < k:
t[m][p] += j-i
t[0].sort()
t[1].sort()
t[2].sort()
return t
class SYT3lines():
"""
A class modeling 3 lines rectangular standard Young tableau
EXAMPLES:
>>> SYT3lines([[7, 8, 9], [4, 5, 6], [1, 2, 3]])
-------------
| 7 | 8 | 9 |
-------------
| 4 | 5 | 6 |
-------------
| 1 | 2 | 3 |
-------------
"""
def __init__(self, values, check=True, verbose=False):
"""
TESTS:
>>> T = SYT3lines([[4, 6], [2, 5], [1, 3]])
>>> T = SYT3lines([[], [], []])
"""
if check:
if not is_SYT3line(values, verbose=verbose):
raise ValueError(str(values) +
" is not the content of a 3 lines rectangular standard Young tableau")
self._content = tuple([tuple(line) for line in values])
self._size = len(values[0])
def __repr__(self):
"""
TESTS:
>>> SYT3lines([[4, 6], [2, 5], [1, 3]])
---------
| 4 | 6 |
---------
| 2 | 5 |
---------
| 1 | 3 |
---------
"""
g = int(log(3*self._size, 10)+1)
ans = "-"*((g+3)*self._size+1)
for line in self._content:
ans += "\n| " + " | ".join(['%*d'%(g, val) for val in line]) + " |\n"
ans += "-"*((g+3)*self._size+1)
return ans
def __eq__(self, other):
"""
TESTS:
>>> T = SYT3lines([[3], [2], [1]])
>>> S = SYT3lines([[2], [3], [1]], check=False)
>>> T == S
False
>>> T == T
True
"""
if other.__class__ is self.__class__:
return self._content == other._content
else:
return self._content == other
def __hash__(self):
"""
TESTS:
>>> SYT3lines([[4, 7, 9], [2, 5, 8], [1, 3, 6]]).__hash__() > 0
True
"""
return hash(self._content)
def schutzenberger(self):
"""
Return the image of `self` by the schutzenberger involution.
EXAMPLES:
>>> T = SYT3lines([[6, 8, 9], [2, 5, 7], [1, 3, 4]])
>>> S = T.schutzenberger(); S
-------------
| 6 | 7 | 9 |
-------------
| 3 | 5 | 8 |
-------------
| 1 | 2 | 4 |
-------------
>>> S.schutzenberger() == T
True
"""
n = self._size
complement = 3 * n + 1
vals = []
for i in range(3):
line = []
for j in range(n):
line.append(complement - self._content[2-i][n-1-j])
vals.append(line)
return SYT3lines(vals, False, False)
def products_inputs(self):
"""
Returns the list of product inputs. Each product will be described
by a couple of integer `(left, right)` where `left` is the label of
wire linking the left entry of the product and `right` is the label
of the wire linking the right entry of the product.
EXAMPLES:
>>> T = SYT3lines([[4, 7, 10, 12], [2, 5, 8, 11], [1, 3, 6, 9]])
>>> T.products_inputs()
[(2, 4), (5, 7), (8, 10), (11, 12)]
>>> T = SYT3lines([[6, 8, 9], [2, 5, 7], [1, 3, 4]])
>>> T.products_inputs()
[(5, 6), (7, 8), (2, 9)]
>>> T = SYT3lines([[9, 10, 11, 12], [2, 4, 6, 8], [1, 3, 5, 7]])
>>> T.products_inputs()
[(8, 9), (6, 10), (4, 11), (2, 12)]
"""
n = self._size
done = []
prods = []
for i in range(n):
right = self._content[0][i]
j = n-1
while j >= 0:
if self._content[1][j] < right and self._content[1][j] not in done:
left = self._content[1][j]
done.append(left)
break
j = j-1
prods.append( (left, right) )
return prods
def coproducts_outputs(self):
"""
Returns the list of coproduct outputs. Each coproduct will be described
by a couple of integer `(left, right)` where `left` is the label of
wire linking the left output of the coproduct and `right` is the label
of the wire linking the right output of the coproduct.
EXAMPLES:
>>> T = SYT3lines([[9, 10, 11, 12], [2, 4, 6, 8], [1, 3, 5, 7]])
>>> T.coproducts_outputs()
[(2, 3), (4, 5), (6, 7), (8, 9)]
>>> T = SYT3lines([[3, 6], [2, 5], [1, 4]])
>>> T.coproducts_outputs()
[(2, 3), (5, 6)]
"""
n = self._size
done = []
coprods = []
for i in range(n):
right = self._content[1][i]
j = n-1
while j >= 0:
if self._content[2][j] < right and self._content[2][j] not in done:
left = self._content[2][j]
done.append(left)
break
j = j-1
coprods.append( (left+1, right+1) )
return coprods
def faces(self):
"""
Returns the list of faces appearing in the program. The faces are
described by the ordered list of labels of the edges delimiting them.
EXAMPLES::
>>> T = SYT3lines([[8, 9, 11, 14, 15], [2, 7, 10, 12, 13], [1, 3, 4, 5, 6]])
>>> T.faces()
[[1, 2, 10, 12], [1, 3, 14, 15], [2, 3, 4, 5, 6, 7, 9], [7, 8], [6, 8, 9, 10, 11], [5, 11, 12, 13, 15], [4, 13, 14]]
"""
ans =[]
prods = self.products_inputs()
coprods = self.coproducts_outputs()
# Inner function to build left border
def next_left(index):
for (l, r) in coprods:
if index == l-1:
return r
for (l, r) in prods:
if index == r:
return r+1
return None
# Inner function to build right border
def next_right(index):
for (l, r) in coprods:
if index == l-1:
return l
for (l, r) in prods:
if index == l:
return r+1
return None
# First left face
face = []
current_edge = 1
while current_edge != self._size*3 + 1:
face.append(current_edge)
current_edge = next_right(current_edge)
ans.append(face.copy())
# second right face
face = []
current_edge = 1
while current_edge != self._size*3 + 1:
face.append(current_edge)
current_edge = next_left(current_edge)
ans.append(face.copy())
# Other general faces
for (l, r) in coprods:
face = []
current_edge = l
while current_edge != None:
face.append(current_edge)
current_edge = next_left(current_edge)
current_edge = r
while current_edge != None:
face.append(current_edge)
current_edge = next_right(current_edge)
ans.append(face.copy())
return ans
def edge_type(self, i):
"""
Return the type of edge labelled by `i` inside the prograph
associated with `self`.
EXAMPLES:
>>> T = SYT3lines([[3, 6], [2, 5], [1, 4]])
>>> for i in range(1, 7):
... T.edge_type(i)
...
(0, 2)
(2, 1)
(1, 0)
(0, 2)
(2, 1)
(1, 0)
"""
if i == 1: # This is the type of unflipable edge 1
return (0, 2)
if i in self._content[0]:
go_to = 0 # right input of product
elif i in self._content[1]:
go_to = 1 # left input of product
else:
go_to = 2 # input of coproduct
if i-1 in self._content[0]:
come_from = 0 # output of product
elif i-1 in self._content[1]:
come_from = 1 # right output of coproduct
else:
come_from = 2 # left output of coproduct
return (come_from, go_to)
def is_edge_flipable(self, i):
"""
Return `True` if the wire labelled by `i` is flipable or not.
Inside Product-Coproduct Prograph, edge `1` is never flipable
since highest product is connected to lowest coproduct by the
only edge crossing infinity. For other edges, the only ones
not flipable are edge connecting left(resp. right) output of
coproduct to left(resp. right) entry of product.
>>> T = SYT3lines([[4, 6], [2, 5], [1, 3]])
>>> for i in range(1,7):
... T.is_edge_flipable(i)
...
False
False
True
True
True
False
"""
if i == 1:
return False
(c, g) = self.edge_type(i)
return (c, g) not in [(2, 1), (1, 0)]
def is_edge_reducible(self, i):
"""
Return `True` if the wire labelled by `i` is flipable
down. Return `False` otherwise.
Here two choices were possible due to symmetries
EST-WEST. Reduced edge connect either:
- output of product to right input of product (The choice)
- left output of coproduct to input of coproduct (forced by schützenberger involution)
- right output of coproduct to left input of product (forced by spherical geometry)
EXAMPLES:
>>> T = SYT3lines([[7, 8, 9], [4, 5, 6], [1, 2, 3]])
>>> [T.is_edge_reducible(i) for i in range(1, 10)]
[False, False, False, False, False, False, False, False, False]
>>> T = SYT3lines([[4, 7, 9], [2, 5, 8], [1, 3, 6]])
>>> [T.is_edge_reducible(i) for i in range(1, 10)]
[False, False, True, True, True, True, True, True, False]
"""
if i == 1:
return False
(c, g) = self.edge_type(i)
return (c, g) in [(0, 1), (1, 2), (2, 0), (0, 2)]
def reducible_edges(self):
"""
Returns the list of reducibles edges inside `self`.
EXAMPLES:
>>> T = SYT3lines([[4, 7, 9], [2, 5, 8], [1, 3, 6]])
>>> T.reducible_edges()
[3, 4, 5, 6, 7, 8]
>>> T = SYT3lines([[7, 8, 9], [4, 5, 6], [1, 2, 3]])
>>> T.reducible_edges()
[]
>>> T = SYT3lines([[3, 6, 9], [2, 5, 8], [1, 4, 7]])
>>> T.reducible_edges()
[4, 7]
"""
n = len(self._content[0])
return [i for i in range(1, 3*n+1) if self.is_edge_reducible(i)]
def flip_down_edge(self, i):
"""
Modify `self` by flipping down edge labelled by `i`.
EXAMPLES:
"""
if not self.is_edge_reducible(i):
raise ValueError('Edge %s can not be flipped down'%(str(i)))
(c, g) = self.edge_type(i)
if (c, g) == (1, 2): # left rotation for coproduct
for o1, o2 in self.coproducts_outputs():
if o2 == i:
s = o1 - 1
return SYT3lines(left_rotation_coprod([list(line) for line in self._content], s, i), False, False)
elif (c, g) == (0, 1): # right rotation for product
for i1, i2 in self.products_inputs():
if i == i1:
s = i2
return SYT3lines(right_rotation_prod([list(line) for line in self._content], i-1, s), False, False)
elif (c, g) == (2, 0): # left output of coproduct inside right input of product
return SYT3lines(jump_over_rotation([list(line) for line in self._content], i-1), False, False)
else:
if (c, g) != (0, 2):
raise ValueError("This should never happen! ")
for o1, o2 in self.coproducts_outputs():
if o1 == i+1:
k = o2
for i1, i2 in self.products_inputs():
if i-1 == i2:
j = i1
return SYT3lines(land_over_rotation([list(line) for line in self._content], i, j, k), False, False)
def lower_elements(self):
"""
EXAMPLES:
"""
return [self.flip_down_edge(i) for i in self.reducible_edges()]
def to_bialgebra_layers(self):
"""
Returns a list of list of operators whose complete assembly
rebuilt `self`. Algebraicly, `self` can be view as the
composition of some layers where each layers is a tensor
product of some products, coproducts and severals times the
identity function. This method return the minimal list of
layers whose assembly rebuilt `self`.
EXAMPLES:
>>> SYT3lines([[4, 6], [2, 5], [1, 3]]).to_bialgebra_layers()
[['C'], ['Id', 'C'], ['P', 'Id'], ['P']]
>>> SYT3lines([[5, 6], [2, 4], [1, 3]]).to_bialgebra_layers()
[['C'], ['Id', 'C'], ['Id', 'P'], ['P']]
>>> SYT3lines([[4, 6], [3, 5], [1, 2]]).to_bialgebra_layers()
[['C'], ['C', 'Id'], ['P', 'Id'], ['P']]
>>> SYT3lines([[3, 6], [2, 5], [1, 4]]).to_bialgebra_layers()
[['C'], ['P'], ['C'], ['P']]
>>> SYT3lines([[5, 6], [3, 4], [1, 2]]).to_bialgebra_layers()
[['C'], ['C', 'Id'], ['Id', 'P'], ['P']]
"""
layers = []
all_products = self.products_inputs()
all_coprods = self.coproducts_outputs()
done_coprods = []
layer_labels = [1] # the fisrt coproduct !
while all_products or (len(done_coprods) < len(self._content[0])):
new_layer = []
new_labels = []
i = 0
while (i < len(layer_labels)):
if layer_labels[i] in self._content[2]:
new_layer.append("C")
done_coprods.append(layer_labels[i])
for l, r in all_coprods:
if l == layer_labels[i]+1:
new_labels.append(l)
new_labels.append(r)
i += 1
elif (i+1 < len(layer_labels)) and (layer_labels[i], layer_labels[i+1]) in all_products:
new_layer.append("P")
all_products.remove((layer_labels[i], layer_labels[i+1]))
new_labels.append(layer_labels[i+1]+1)
i += 2
else:
new_layer.append("Id")
new_labels.append(layer_labels[i])
i += 1
layer_labels = new_labels
layers.append(new_layer)
return layers
class RectSYT3lines():
"""
A class modeling the set of all rectangular 3 lines standard Young
tableau of a given number of colunms.
EXAMPLES:
>>> S = RectSYT3lines(3)
>>> S.cardinality()
42
"""
def __init__(self, n):
"""
TESTS:
>>> S = RectSYT3lines(4)
"""
self._size = n
self._list = None
def __repr__(self):
"""
TESTS:
>>> RectSYT3lines(5)
Rectangular Standard Young Tableaux of size (3, 5)
"""
return "Rectangular Standard Young Tableaux of size (3, %d)"%(self._size)
def cardinality(self):
"""
Returns the cardinality of `self`
EXAMPLES:
>>> [RectSYT3lines(i).cardinality() for i in range(10)]
[1, 1, 5, 42, 462, 6006, 87516, 1385670, 23371634, 414315330]
"""
n = self._size
return (2*factorial(3*n)) // (factorial(n)*factorial(n+1)*factorial(n+2))
def __set_list(self):
"""
Sets the list of all elements of `self`.
EXAMPLES:
>>> for t in RectSYT3lines(2):
... print(t)
...
---------
| 3 | 6 |
---------
| 2 | 5 |
---------
| 1 | 4 |
---------
---------
| 4 | 6 |
---------
| 2 | 5 |
---------
| 1 | 3 |
---------
---------
| 5 | 6 |
---------
| 2 | 4 |
---------
| 1 | 3 |
---------
---------
| 4 | 6 |
---------
| 3 | 5 |
---------
| 1 | 2 |
---------
---------
| 5 | 6 |
---------
| 3 | 4 |
---------
| 1 | 2 |
---------
"""
if self._list is not None:
return
n = self._size
content = [[0]*n for i in range(3)]
val = 1
last = 3*n
tableaux = [content]
for val in range(1, last+1):
new_tableaux = []
for t in tableaux:
for i in range(n):
for j in range(3):
if t[j][i] == 0:
if i == 0 or t[j][i-1] != 0:
if j==2 or t[j+1][i] != 0:
t[j][i] = val
new_tableaux.append(deepcopy(t))
t[j][i] = 0
tableaux = new_tableaux
self._list = [SYT3lines(x, check=False) for x in tableaux]
def __list__(self):
"""
TESTS:
>>> R = RectSYT3lines(1)
>>> list(R)
[-----
| 3 |
-----
| 2 |
-----
| 1 |
-----]
"""
self.__set_list()
return self._list
def __iter__(self):
"""
TESTS:
>>> sum([1 for t in RectSYT3lines(3)])
42
"""
self.__set_list()
for t in self._list:
yield t
def __contains__(self, elt):
"""
TESTS:
>>> R = RectSYT3lines(3)
>>> [[7, 8, 9], [4, 5, 6], [1, 2, 3]] in R
True
>>> [[7, 8, 6], [4, 5, 9], [1, 2, 3]] in R
False
>>> T = SYT3lines([[7, 8, 9], [4, 5, 6], [1, 2, 3]])
>>> T in R
True
>>> T = SYT3lines([[7, 8, 6], [4, 5, 9], [1, 2, 3]], check=False)
>>> T in R
False
"""
if isinstance(elt, (list, tuple)):
if elt:
if elt[0]:
if len(elt[0]) == self._size:
return is_SYT3line(elt, verbose=False)
return False
elif isinstance(elt, (SYT3lines,)):
L = elt._content
if L:
if L[0]:
if len(L[0]) == self._size:
return is_SYT3line(L, verbose=False)
return False
def random_element(self):
"""
Return a random element of `self`.
EXAMPLES:
>>> R = RectSYT3lines(10)
>>> R.random_element() in R
True
"""
n = self._size
t = [[0]*n for i in range(3)]
last = 3*n
for val in range(1, last+1):
found = False
while not found:
j = randint(0,2)
i = 0
while t[j][i] != 0 and i < n-1:
i += 1
if t[j][i] == 0:
if i == 0 or t[j][i-1] != 0:
if j==2 or t[j+1][i] != 0:
found = True
t[j][i] = val
return SYT3lines(t, check=False)
def max_element(self):
"""
Return the maximal element of `self`.
EXAMPLES:
>>> RectSYT3lines(2).max_element()
---------
| 4 | 6 |
---------
| 2 | 5 |
---------
| 1 | 3 |
---------
>>> RectSYT3lines(12).max_element()
-------------------------------------------------------------
| 4 | 7 | 10 | 13 | 16 | 19 | 22 | 25 | 28 | 31 | 34 | 36 |
-------------------------------------------------------------
| 2 | 5 | 8 | 11 | 14 | 17 | 20 | 23 | 26 | 29 | 32 | 35 |
-------------------------------------------------------------
| 1 | 3 | 6 | 9 | 12 | 15 | 18 | 21 | 24 | 27 | 30 | 33 |
-------------------------------------------------------------
"""
n = self._size
val = [[], [2], [1, 3]]
pos = 0
for i in range(4, 3*n):
val[pos].append(i)
pos = (pos + 1) % 3
val[0].append(3*n)
return SYT3lines(val, check=False)
def min_element(self):
"""
Return the minimal element of `self`.
EXAMPLES:
>>> RectSYT3lines(2).min_element()
---------
| 5 | 6 |
---------
| 3 | 4 |
---------
| 1 | 2 |
---------
>>> RectSYT3lines(12).min_element()
-------------------------------------------------------------
| 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 |
-------------------------------------------------------------
| 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
-------------------------------------------------------------
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
-------------------------------------------------------------
"""
n = self._size
val = [list(range(2*n+1, 3*n+1)), list(range(n+1, 2*n+1)), list(range(1, n+1))]
return SYT3lines(val, check=False)
def intervals(self):
"""
Compute the list of all intervals classified by top element.
EXAMPLES:
>>> I = RectSYT3lines(1).intervals()
>>> [len(I[top]) for top in I]
[1]
>>> I = RectSYT3lines(2).intervals()
>>> [len(I[top]) for top in I]
[5, 2, 2, 2, 1]
>>> I = RectSYT3lines(3).intervals()
>>> [len(I[top]) for top in I]
[42, 17, 14, 27, 27, 14, 17, 13, 9, 18, 12, 5, 5, 4, 12, 18, 13, 5, 5, 9, 4, 4, 4, 9, 2, 2, 6, 6, 5, 6, 3, 2, 2, 3, 3, 6, 5, 3, 2, 1, 4, 2]
>>> # I = RectSYT3lines(4).intervals()
>>> # [len(I[top]) for top in I]
# [462, 203, 145, 347, 299, 118, 299, 347, 145, 203, 174, 144, 203, 245, 286, 76, 154, 57, 41, 101, 154, 51, 77, 39, 94, 28, 50, 103, 94, 186, 222, 144, 221, 136, 136, 221, 186, 101, 51, 41, 57, 174, 76, 245, 203, 103, 50, 28, 28, 94, 28, 66, 21, 67, 47, 140, 10, 14, 10, 66, 14, 14, 42, 42, 35, 128, 33, 39, 10, 10, 10, 31, 18, 70, 70, 18, 31, 80, 48, 160, 166, 60, 67, 21, 38, 119, 103, 53, 38, 48, 21, 39, 67, 110, 157, 147, 119, 131, 128, 131, 147, 157, 110, 80, 106, 36, 73, 88, 36, 42, 42, 14, 14, 10, 10, 14, 35, 24, 49, 10, 10, 34, 60, 166, 160, 80, 21, 24, 73, 106, 80, 108, 33, 24, 10, 10, 33, 33, 108, 88, 67, 53, 103, 14, 10, 25, 82, 8, 8, 140, 253, 47, 18, 8, 8, 25, 82, 49, 34, 24, 18, 26, 17, 14, 12, 4, 6, 5, 4, 6, 43, 18, 83, 16, 6, 4, 127, 119, 119, 127, 6, 5, 4, 12, 14, 17, 26, 4, 4, 14, 18, 20, 12, 6, 7, 9, 38, 58, 82, 22, 30, 54, 12, 22, 50, 57, 94, 68, 43, 16, 65, 68, 94, 57, 50, 22, 12, 35, 34, 9, 26, 18, 57, 40, 6, 4, 5, 6, 26, 40, 57, 9, 12, 6, 88, 39, 12, 12, 12, 10, 5, 7, 10, 12, 12, 22, 5, 24, 59, 22, 30, 22, 38, 82, 58, 55, 26, 6, 18, 80, 10, 12, 51, 9, 9, 12, 12, 28, 27, 43, 6, 4, 34, 35, 14, 14, 12, 10, 51, 65, 45, 20, 14, 7, 10, 6, 56, 77, 5, 39, 77, 56, 27, 24, 6, 58, 38, 14, 7, 9, 43, 14, 38, 28, 31, 88, 31, 80, 12, 55, 26, 6, 8, 9, 40, 12, 20, 20, 27, 21, 6, 8, 21, 7, 72, 4, 6, 72, 27, 7, 4, 16, 13, 13, 5, 8, 8, 8, 25, 21, 21, 21, 43, 4, 3, 43, 4, 4, 11, 15, 25, 25, 54, 5, 10, 8, 29, 12, 41, 41, 3, 2, 30, 4, 11, 17, 20, 37, 6, 6, 4, 4, 3, 3, 2, 8, 12, 12, 4, 12, 40, 21, 20, 8, 54, 3, 2, 12, 8, 11, 30, 7, 4, 10, 3, 9, 46, 17, 7, 4, 19, 7, 7, 16, 21, 11, 4, 15, 14, 37, 29, 46, 21, 2, 7, 8, 19, 2, 7, 6, 14, 12, 7, 11, 2, 12, 10, 34, 15, 15, 34, 18, 18, 5, 2, 6, 4, 4, 3, 3, 11, 7, 10, 5, 15, 5, 5, 15, 2, 1, 8, 6, 4, 6, 5, 9, 29, 2, 6, 8, 13, 8]
"""
max_elt = self.max_element()
intervals = {max_elt : set([max_elt])}
from copy import deepcopy
new = True
while new:
new = False
new_intervals = deepcopy(intervals)
for top in intervals:
for e in intervals[top]:
for child in e.lower_elements():
if child not in new_intervals:
new_intervals[child] = set([child])
new = True
if child not in new_intervals[top]:
new_intervals[top].add(child)
new = True
intervals = new_intervals
return intervals
#***********************************************************************
# EXPERIMENTATIONS
#***********************************************************************
def global_height():
"""
EXPERIENCE : look at the height of the prograph (number of layers)
according the size of the prograph.
There are a lot of result of the average height of a random binary
tree. So what is the height of a random PC prograph ? What is the
good experience to proceeed ?
TESTS:
>>> 1+1
2
"""
# This current experience try to compute an average rate of
# height/size for large random prograph. It seems to converge to
# zero but very very slowly. Even for random prograph of size
# 1000...
size = 1
rates = []
while True:
size += randint(0,1)
if len(rates) > size // 4:
rates.pop(0)
print("SIZE : "+str(size))