This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
shifted_primed_tableau.py
2317 lines (1920 loc) · 75.1 KB
/
shifted_primed_tableau.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
# -*- coding: utf-8 -*-
"""
Shifted primed tableaux
AUTHORS:
- Kirill Paramonov (2017-08-18): initial implementation
"""
# ****************************************************************************
# Copyright (C) 2017 Kirill Paramonov <kbparamonov at ucdavis.edu>,
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# https://www.gnu.org/licenses/
# ****************************************************************************
from __future__ import print_function, absolute_import, division
from six import add_metaclass
from sage.combinat.partition import Partition, Partitions, _Partitions, OrderedPartitions
from sage.combinat.partitions import ZS1_iterator
from sage.combinat.tableau import Tableaux
from sage.combinat.skew_partition import SkewPartition
from sage.combinat.integer_vector import IntegerVectors
from sage.rings.integer import Integer
from sage.rings.rational_field import QQ
from sage.misc.inherit_comparison import InheritComparisonClasscallMetaclass
from sage.misc.lazy_attribute import lazy_attribute
from sage.structure.list_clone import ClonableArray
from sage.structure.parent import Parent
from sage.structure.unique_representation import UniqueRepresentation
from sage.structure.sage_object import SageObject
from sage.categories.regular_crystals import RegularCrystals
from sage.categories.classical_crystals import ClassicalCrystals
from sage.categories.sets_cat import Sets
from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets
from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
from sage.combinat.root_system.cartan_type import CartanType
@add_metaclass(InheritComparisonClasscallMetaclass)
class ShiftedPrimedTableau(ClonableArray):
r"""
A shifted primed tableau.
A primed tableau is a tableau of shifted shape in the alphabet
`X' = \{1' < 1 < 2' < 2 < \cdots < n' < n\}` such that
1. the entries are weakly increasing along rows and columns;
2. a row cannot have two repeated primed elements, and a column
cannot have two repeated non-primed elements;
3. there are only non-primed elements on the main diagonal.
Skew shape of the shifted primed tableaux is specified either
with an optional argument ``skew`` or with ``None`` entries.
EXAMPLES::
sage: T = ShiftedPrimedTableaux([4,2])
sage: T([[1,"2'","3'",3],[2,"3'"]])[1]
(2, 3')
sage: t = ShiftedPrimedTableau([[1,"2p",2.5,3],[2,2.5]])
sage: t[1]
(2, 3')
sage: ShiftedPrimedTableau([["2p",2,3],["2p","3p"],[2]], skew=[2,1])
[(None, None, 2', 2, 3), (None, 2', 3'), (2,)]
sage: ShiftedPrimedTableau([[None,None,"2p"],[None,"2p"]])
[(None, None, 2'), (None, 2')]
TESTS::
sage: t = ShiftedPrimedTableau([[1,2,2.5,3],[2,2.5]])
Traceback (most recent call last):
...
ValueError: [[1, 2, 2.50000000000000, 3], [2, 2.50000000000000]]
is not an element of Shifted Primed Tableaux
"""
@staticmethod
def __classcall_private__(cls, T, skew=None):
r"""
Ensure that a shifted tableau is only ever constructed as an
``element_class`` call of an appropriate parent.
EXAMPLES::
sage: data = [[1,"2'","2",3],[2,"3'"]]
sage: t = ShiftedPrimedTableau(data)
sage: T = ShiftedPrimedTableaux(shape=[4,2],weight=(1,3,2))
sage: t == T(data)
True
sage: S = ShiftedPrimedTableaux(shape=[4,2])
sage: t == S(data)
True
sage: t = ShiftedPrimedTableau([["2p",2,3],["2p"]],skew=[2,1])
sage: t.parent()
Shifted Primed Tableaux skewed by [2, 1]
sage: s = ShiftedPrimedTableau([[None, None,"2p",2,3],[None,"2p"]])
sage: s.parent()
Shifted Primed Tableaux skewed by [2, 1]
TESTS::
sage: ShiftedPrimedTableau([])
[]
sage: ShiftedPrimedTableau([tuple([])])
[]
"""
if isinstance(T, ShiftedPrimedTableau) and T._skew == skew:
return T
skew_ = Partition([row.count(None) for row in T])
if skew_:
if skew and Partition(skew) != skew_:
raise ValueError("skew shape does not agree with None entries")
skew = skew_
return ShiftedPrimedTableaux(skew=skew)(T)
def __init__(self, parent, T, skew=None, check=True, preprocessed=False):
r"""
Initialize a shifted tableau.
TESTS::
sage: s = ShiftedPrimedTableau([[1,"2'","3'",3], [2,"3'"]])
sage: t = ShiftedPrimedTableaux([4,2])([[1,"2p","3p",3], [2,"3p"]])
sage: s == t
True
sage: t.parent()
Shifted Primed Tableaux of shape [4, 2]
sage: s.parent()
Shifted Primed Tableaux
sage: r = ShiftedPrimedTableaux([4, 2])(s); r.parent()
Shifted Primed Tableaux of shape [4, 2]
sage: s is t # identical shifted tableaux are distinct objects
False
A shifted primed tableau is deeply immutable as the rows are
stored as tuples::
sage: t = ShiftedPrimedTableau([[1,"2p","3p",3],[2,"3p"]])
sage: t[0][1] = 3
Traceback (most recent call last):
...
TypeError: 'tuple' object does not support item assignment
"""
if not preprocessed:
T = self._preprocess(T, skew=skew)
self._skew = skew
ClonableArray.__init__(self, parent, T, check=check)
@staticmethod
def _preprocess(T, skew=None):
"""
Preprocessing list ``T`` to initialize the tableau.
The output is a list of rows as tuples, with explicit
``None``'s to indicate the skew shape, and entries being
``PrimedEntry``s.
Trailing empty rows are removed.
TESTS::
sage: ShiftedPrimedTableau._preprocess([["2'", "3p", 3.5]],
....: skew=[1])
[(None, 2', 3', 4')]
sage: ShiftedPrimedTableau._preprocess([[None]], skew=[1])
[(None,)]
sage: ShiftedPrimedTableau._preprocess([], skew=[2,1])
[(None, None), (None,)]
sage: ShiftedPrimedTableau._preprocess([], skew=[])
[]
"""
if isinstance(T, ShiftedPrimedTableau):
return T
# Preprocessing list t for primes and other symbols
T = [[PrimedEntry(entry) for entry in row if entry is not None]
for row in T]
while len(T) > 0 and len(T[-1]) == 0:
T = T[:-1]
row_min = min(len(skew), len(T)) if skew else 0
T_ = [(None,)*skew[i] + tuple(T[i]) for i in range(row_min)]
if row_min < len(T):
T_ += [tuple(T[i]) for i in range(row_min, len(T))]
elif skew:
T_ += [(None,)*skew[i] for i in range(row_min, len(skew))]
return T_
def check(self):
"""
Check that ``self`` is a valid primed tableau.
EXAMPLES::
sage: T = ShiftedPrimedTableaux([4,2])
sage: t = T([[1,'2p',2,2],[2,'3p']])
sage: t.check()
sage: s = ShiftedPrimedTableau([["2p",2,3],["2p"],[2]],skew=[2,1])
sage: s.check()
sage: t = T([['1p','2p',2,2],[2,'3p']])
Traceback (most recent call last):
...
ValueError: [['1p', '2p', 2, 2], [2, '3p']] is not an element of
Shifted Primed Tableaux of shape [4, 2]
"""
if not self.parent()._contains_tableau(self):
raise ValueError("{} is not an element of Shifted Primed Tableaux".format(self))
def __eq__(self, other):
"""
Check whether ``self`` is equal to ``other``.
INPUT:
- ``other`` -- the element that ``self`` is compared to
OUTPUT: Boolean
EXAMPLES::
sage: t = ShiftedPrimedTableau([[1,"2p"]])
sage: t == ShiftedPrimedTableaux([2])([[1,3/2]])
True
sage: s = ShiftedPrimedTableau([["2p",3]], skew=[1])
sage: s == [[None, "2p", 3]]
True
"""
if isinstance(other, ShiftedPrimedTableau):
return self._skew == other._skew and list(self) == list(other)
try:
Tab = ShiftedPrimedTableau(other)
except (ValueError, TypeError):
return False
return self._skew == Tab._skew and list(self) == list(Tab)
def __ne__(self, other):
"""
Check whether ``self`` is not equal to ``other``.
INPUT:
- ``other`` -- the element that ``self`` is compared to
OUTPUT: Boolean
EXAMPLES::
sage: t = ShiftedPrimedTableau([[1,"2p"]])
sage: t != ShiftedPrimedTableaux([2])([[1,1]])
True
sage: s = ShiftedPrimedTableau([["2p",3]], skew=[1])
sage: s != [[None, "2p", 3]]
False
"""
return not (self == other)
def __hash__(self):
"""
Return the hash of ``self``.
EXAMPLES::
sage: t = ShiftedPrimedTableau([[1,"2p"]])
sage: hash(t) == hash(ShiftedPrimedTableaux([2])([[1,3/2]]))
True
"""
return hash((self._skew, tuple(self)))
def _repr_(self):
"""
Return a string representation of ``self``.
EXAMPLES::
sage: t = ShiftedPrimedTableau([[1,'2p',2,2],[2,'3p']])
sage: t
[(1, 2', 2, 2), (2, 3')]
sage: ShiftedPrimedTableau([["2p",2,3],["2p"]],skew=[2,1])
[(None, None, 2', 2, 3), (None, 2')]
"""
return self.parent().options._dispatch(self, '_repr_', 'display')
def _repr_list(self):
"""
Return a string representation of ``self`` as a list of tuples.
EXAMPLES::
sage: ShiftedPrimedTableau([['2p',3],[2,2]], skew=[2])._repr_list()
"[(None, None, 2', 3), (2, 2)]"
"""
return repr([row for row in self])
def _repr_tab(self):
"""
Return a nested list of strings representing the elements.
EXAMPLES::
sage: t = ShiftedPrimedTableau([[1,'2p',2,2],[2,'3p']])
sage: t._repr_tab()
[[' 1 ', " 2'", ' 2 ', ' 2 '], [' 2 ', " 3'"]]
sage: s = ShiftedPrimedTableau([["2p",2,3],["2p"]],skew=[2,1])
sage: s._repr_tab()
[[' . ', ' . ', " 2'", ' 2 ', ' 3 '], [' . ', " 2'"]]
"""
max_len = len(str(self.max_entry())) + 2
repr_tab = []
for row in self:
repr_row = []
for entry in row:
if entry is None:
repr_row.append('. '.rjust(max_len))
elif entry.is_primed():
repr_row.append(repr(entry).rjust(max_len))
elif entry.is_unprimed():
repr_row.append(repr(entry).rjust(max_len-1)+" ")
repr_tab.append(repr_row)
return repr_tab
def _repr_diagram(self):
"""
Return a string representation of ``self`` as an array.
EXAMPLES::
sage: t = ShiftedPrimedTableau([[1,'2p',2,2],[2,'3p']])
sage: print(t._repr_diagram())
1 2' 2 2
2 3'
sage: t = ShiftedPrimedTableau([[10,'11p',11,11],[11,'12']])
sage: print(t._repr_diagram())
10 11' 11 11
11 12
sage: s = ShiftedPrimedTableau([["2p",2,3],["2p"]],skew=[2,1])
sage: print(s._repr_diagram())
. . 2' 2 3
. 2'
"""
max_len = len(str(self.max_entry()))+2
return "\n".join([" "*max_len*i + "".join(val)
for i, val in enumerate(self._repr_tab())])
_repr_compact = _repr_diagram
def _ascii_art_(self):
"""
Return ASCII representation of ``self``.
EXAMPLES::
sage: ascii_art(ShiftedPrimedTableau([[1,'2p',2,2],[2,'3p']]))
+---+---+---+---+
| 1 | 2'| 2 | 2 |
+---+---+---+---+
| 2 | 3'|
+---+---+
sage: s = ShiftedPrimedTableau([["2p",2,3],["2p"]],skew=[2,1])
sage: ascii_art(s)
+---+---+---+---+---+
| . | . | 2'| 2 | 3 |
+---+---+---+---+---+
| . | 2'|
+---+---+
TESTS::
sage: ascii_art(ShiftedPrimedTableau([]))
++
++
sage: ascii_art(ShiftedPrimedTableau([], skew=[1]))
+---+
| . |
+---+
"""
from sage.typeset.ascii_art import AsciiArt
return AsciiArt(self._ascii_art_table(unicode=False).splitlines())
def _unicode_art_(self):
"""
Return a Unicode representation of ``self``.
EXAMPLES::
sage: unicode_art(ShiftedPrimedTableau([[1,'2p',2,2],[2,'3p']]))
┌───┬───┬───┬───┐
│ 1 │ 2'│ 2 │ 2 │
└───┼───┼───┼───┘
│ 2 │ 3'│
└───┴───┘
sage: s = ShiftedPrimedTableau([["2p",2,3],["2p"]],skew=[2,1])
sage: unicode_art(s)
┌───┬───┬───┬───┬───┐
│ . │ . │ 2'│ 2 │ 3 │
└───┼───┼───┼───┴───┘
│ . │ 2'│
└───┴───┘
TESTS::
sage: unicode_art(ShiftedPrimedTableau([]))
┌┐
└┘
sage: unicode_art(ShiftedPrimedTableau([], skew=[1]))
┌───┐
│ . │
└───┘
"""
from sage.typeset.unicode_art import UnicodeArt
return UnicodeArt(self._ascii_art_table(unicode=True).splitlines())
def _ascii_art_table(self, unicode=False):
"""
TESTS::
sage: t = ShiftedPrimedTableau([[1,'2p',2],[2,'3p']])
sage: print(t._ascii_art_table(unicode=True))
┌───┬───┬───┐
│ 1 │ 2'│ 2 │
└───┼───┼───┤
│ 2 │ 3'│
└───┴───┘
sage: print(t._ascii_art_table())
+---+---+---+
| 1 | 2'| 2 |
+---+---+---+
| 2 | 3'|
+---+---+
sage: s = ShiftedPrimedTableau([[1,'2p',2, 23],[2,'30p']])
sage: print(s._ascii_art_table(unicode=True))
┌────┬────┬────┬────┐
│ 1 │ 2'│ 2 │ 23 │
└────┼────┼────┼────┘
│ 2 │ 30'│
└────┴────┘
sage: print(s._ascii_art_table(unicode=False))
+----+----+----+----+
| 1 | 2'| 2 | 23 |
+----+----+----+----+
| 2 | 30'|
+----+----+
sage: s = ShiftedPrimedTableau([["2p",2,10],["2p"]],skew=[2,1])
sage: print(s._ascii_art_table(unicode=True))
┌────┬────┬────┬────┬────┐
│ . │ . │ 2'│ 2 │ 10 │
└────┼────┼────┼────┴────┘
│ . │ 2'│
└────┴────┘
"""
if unicode:
import unicodedata
v = unicodedata.lookup('BOX DRAWINGS LIGHT VERTICAL')
h = unicodedata.lookup('BOX DRAWINGS LIGHT HORIZONTAL')
dl = unicodedata.lookup('BOX DRAWINGS LIGHT DOWN AND LEFT')
dr = unicodedata.lookup('BOX DRAWINGS LIGHT DOWN AND RIGHT')
ul = unicodedata.lookup('BOX DRAWINGS LIGHT UP AND LEFT')
ur = unicodedata.lookup('BOX DRAWINGS LIGHT UP AND RIGHT')
vl = unicodedata.lookup('BOX DRAWINGS LIGHT VERTICAL AND LEFT')
uh = unicodedata.lookup('BOX DRAWINGS LIGHT UP AND HORIZONTAL')
dh = unicodedata.lookup('BOX DRAWINGS LIGHT DOWN AND HORIZONTAL')
vh = unicodedata.lookup(
'BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL')
else:
v = '|'
h = '-'
dl = dr = ul = ur = vl = uh = dh = vh = '+'
if not self.shape():
return dr + dl + '\n' + ur + ul
# Get the widths of the columns
str_tab = self._repr_tab()
width = len(str_tab[0][0])
str_list = [dr + (h*width + dh)*(len(str_tab[0])-1) + h*width + dl]
for nrow, row in enumerate(str_tab):
l1 = " " * (width+1) * nrow
l2 = " " * (width+1) * nrow
n = len(str_tab[nrow+1]) if nrow+1 < len(str_tab) else -1
for i, e in enumerate(row):
if i == 0:
l1 += ur + h*width
elif i <= n+1:
l1 += vh + h*width
else:
l1 += uh + h*width
if unicode:
l2 += u"{}{:^{width}}".format(v, e, width=width)
else:
l2 += "{}{:^{width}}".format(v, e, width=width)
if i <= n:
l1 += vl
else:
l1 += ul
l2 += v
str_list.append(l2)
str_list.append(l1)
return "\n".join(str_list)
def pp(self):
"""
Pretty print ``self``.
EXAMPLES::
sage: t = ShiftedPrimedTableau([[1,'2p',2,2],[2,'3p']])
sage: t.pp()
1 2' 2 2
2 3'
sage: t = ShiftedPrimedTableau([[10,'11p',11,11],[11,'12']])
sage: t.pp()
10 11' 11 11
11 12
sage: s = ShiftedPrimedTableau([['2p',2,3],['2p']],skew=[2,1])
sage: s.pp()
. . 2' 2 3
. 2'
TESTS::
sage: ShiftedPrimedTableau([],skew=[1]).pp()
.
sage: ShiftedPrimedTableau([]).pp()
<BLANKLINE>
"""
print(self._repr_diagram())
def _latex_(self):
r"""
Return LaTex code for ``self``.
EXAMPLES::
sage: T = ShiftedPrimedTableaux([4,2])
sage: latex(T([[1,"2p",2,"3p"],[2,3]]))
{\def\lr#1{\multicolumn{1}{|@{\hspace{.6ex}}c@{\hspace{.6ex}}|}{\raisebox{-.3ex}{$#1$}}}
\raisebox{-.6ex}{$\begin{array}[b]{*{4}c}\cline{1-4}
\lr{ 1 }&\lr{ 2'}&\lr{ 2 }&\lr{ 3'}\\\cline{1-4}
&\lr{ 2 }&\lr{ 3 }\\\cline{2-3}
\end{array}$}
}
"""
from sage.combinat.output import tex_from_array
L = [[None]*i + row for i, row in enumerate(self._repr_tab())]
return tex_from_array(L)
def max_entry(self):
r"""
Return the minimum unprimed letter `x > y` for all `y` in ``self``.
EXAMPLES::
sage: Tab = ShiftedPrimedTableau([(1,1,'2p','3p'),(2,2)])
sage: Tab.max_entry()
3
TESTS::
sage: Tab = ShiftedPrimedTableau([], skew=[2,1])
sage: Tab.max_entry()
0
sage: Tab = ShiftedPrimedTableau([["1p"]], skew=[2,1])
sage: Tab.max_entry()
1
"""
flat = [entry.unprimed() for row in self
for entry in row if entry is not None]
if len(flat) == 0:
return 0
return max(flat)
def shape(self):
r"""
Return the shape of the underlying partition of ``self``.
EXAMPLES::
sage: t = ShiftedPrimedTableau([[1,'2p',2,2],[2,'3p']])
sage: t.shape()
[4, 2]
sage: s = ShiftedPrimedTableau([["2p",2,3],["2p"]],skew=[2,1])
sage: s.shape()
[5, 2] / [2, 1]
"""
if self._skew is None:
return Partition([len(row) for row in self])
return SkewPartition(([len(row) for row in self], self._skew))
def restrict(self, n):
"""
Return the restriction of the shifted tableau to all
the numbers less than or equal to ``n``.
.. NOTE::
If only the outer shape of the restriction, rather than
the whole restriction, is needed, then the faster method
:meth:`restriction_outer_shape` is preferred. Similarly if
only the skew shape is needed, use :meth:`restriction_shape`.
EXAMPLES::
sage: t = ShiftedPrimedTableau([[1,'2p',2,2],[2,'3p']])
sage: t.restrict(2).pp()
1 2' 2 2
2
sage: t.restrict("2p").pp()
1 2'
sage: s = ShiftedPrimedTableau([["2p",2,3],["2p"]], skew=[2,1])
sage: s.restrict(2).pp()
. . 2' 2
. 2'
sage: s.restrict(1.5).pp()
. . 2'
. 2'
"""
t = self[:]
n = PrimedEntry(n)
return ShiftedPrimedTableau([z for z in [[y for y in x if y is not None and y <= n]
for x in t] if z], skew=self._skew)
def restriction_outer_shape(self, n):
"""
Return the outer shape of the restriction of the shifted
tableau ``self`` to `n`.
If `T` is a (skew) shifted tableau and `n` is a half-integer,
then the restriction of `T` to `n` is defined as the (skew)
shifted tableau obtained by removing all cells filled with
entries greater than `n` from `T`.
This method computes merely the outer shape of the restriction.
For the restriction itself, use :meth:`restrict`.
EXAMPLES::
sage: s = ShiftedPrimedTableau([["2p",2,3],["2p"]], skew=[2,1]); s.pp()
. . 2' 2 3
. 2'
sage: s.restriction_outer_shape(2)
[4, 2]
sage: s.restriction_outer_shape("2p")
[3, 2]
"""
n = PrimedEntry(n)
if self._skew is None:
res = [len([y for y in row if y <= n]) for row in self]
else:
res = [len([y for y in row if y is None or y <= n])
for i, row in enumerate(self)]
return Partition(res)
def restriction_shape(self, n):
"""
Return the skew shape of the restriction of the skew tableau
``self`` to ``n``.
If `T` is a shifted tableau and `n` is a half-integer, then
the restriction of `T` to `n` is defined as the
(skew) shifted tableau obtained by removing all cells
filled with entries greater than `n` from `T`.
This method computes merely the skew shape of the restriction.
For the restriction itself, use :meth:`restrict`.
EXAMPLES::
sage: s = ShiftedPrimedTableau([["2p",2,3],["2p"]], skew=[2,1]); s.pp()
. . 2' 2 3
. 2'
sage: s.restriction_shape(2)
[4, 2] / [2, 1]
"""
if self._skew is None:
return Partition(self.restriction_outer_shape(n))
else:
return SkewPartition([self.restriction_outer_shape(n), self._skew])
def to_chain(self):
"""
Return the chain of partitions corresponding to the (skew)
shifted tableau ``self``, interlaced by one of the colours
``1`` is the added cell is on the diagonal, ``2`` if an
ordinary entry is added and ``3`` if a primed entry is added.
EXAMPLES::
sage: s = ShiftedPrimedTableau([(1, 2, 3.5, 5, 6.5), (3, 5.5)]); s.pp()
1 2 4' 5 7'
3 6'
sage: s.to_chain()
[[], 1, [1], 2, [2], 1, [2, 1], 3, [3, 1], 2, [4, 1], 3, [4, 2], 3, [5, 2]]
sage: s = ShiftedPrimedTableau([(1, 3.5), (2.5,), (6,)], skew=[2,1]); s.pp()
. . 1 4'
. 3'
6
sage: s.to_chain()
[[2, 1], 2, [3, 1], 0, [3, 1], 3, [3, 2], 3, [4, 2], 0, [4, 2], 1, [4, 2, 1]]
TESTS::
sage: s = ShiftedPrimedTableau([["2p",2,3],["2p"]], skew=[2,1]); s.pp()
. . 2' 2 3
. 2'
sage: s.to_chain()
Traceback (most recent call last):
...
AssertionError: can compute a chain of partitions only for skew shifted tableaux without repeated entries.
"""
assert all(e in [0, 1] for e in self.weight()), "can compute a chain of partitions only for skew shifted tableaux without repeated entries."
entries = sorted(e for row in self for e in row if e is not None)
if self._skew is None:
mu = Partition([])
m = 0
else:
mu = self._skew
m = len(self._skew)
chain = [mu]
f = 0
for e in entries:
n = e.integer()
chain.extend([0, mu]*int(n-f-1))
mu = self.restriction_outer_shape(e)
if n == e:
if any(e == row[0] for i, row in enumerate(self) if i >= m or self._skew[i] == 0):
chain.append(1)
else:
chain.append(2)
else:
chain.append(3)
chain.append(mu)
f = n
return chain
def weight(self):
r"""
Return the weight of ``self``.
The weight of a shifted primed tableau is defined to be the vector
with `i`-th component equal to the number of entries `i` and `i'`
in the tableau.
EXAMPLES::
sage: t = ShiftedPrimedTableau([['2p',2,2],[2,'3p']], skew=[1])
sage: t.weight()
(0, 4, 1)
"""
flat = [entry.integer() for row in self
for entry in row if entry is not None]
if not flat:
return ()
weight = tuple([flat.count(i+1) for i in range(max(flat))])
return weight
class CrystalElementShiftedPrimedTableau(ShiftedPrimedTableau):
"""
Class for elements of ``crystals.ShiftedPrimedTableau``.
"""
def _to_matrix(self):
"""
Return a 2-dimensional array representation of a shifted tableau.
EXAMPLES::
sage: SPT = ShiftedPrimedTableaux([4,2,1])
sage: t = SPT([[1,'2p',2,2],[2,'3p'],[3]])
sage: mat = t._to_matrix()
sage: mat
[[1, 2', 2, 2], [None, 2, 3', None], [None, None, 3, None]]
"""
m = len(self[0])
return [[None]*i + list(row) + [None]*(m-i-len(row))
for i, row in enumerate(self)]
def _reading_word_with_positions(self):
"""
Iterate over the reading word of ``self`` together with positions
of the corresponding letters in ``self``.
The reading word of a shifted primed tableau is constructed
as follows:
1. List all primed entries in the tableau, column by
column, in decreasing order within each column, moving
from the rightmost column to the left, and with all
the primes removed (i.e. all entries are increased by
half a unit).
2. Then list all unprimed entries, row by row, in
increasing order within each row, moving from the
bottommost row to the top.
EXAMPLES::
sage: SPT = ShiftedPrimedTableaux([4,2])
sage: t = SPT([[1,'2p',2,2],[2,'3p']])
sage: list(t._reading_word_with_positions())
[((1, 2), 3), ((0, 1), 2), ((1, 1), 2), ((0, 0), 1),
((0, 2), 2), ((0, 3), 2)]
"""
mat = self._to_matrix()
ndim, mdim = len(mat), len(mat[0])
for j in reversed(range(mdim)):
for i in range(ndim):
x = mat[i][j]
if x is not None and x.is_primed():
yield ((i, j), x.integer())
for i in reversed(range(ndim)):
for j in range(mdim):
x = mat[i][j]
if x is not None and x.is_unprimed():
yield ((i, j), x.integer())
def reading_word(self):
"""
Return the reading word of ``self``.
The reading word of a shifted primed tableau is constructed
as follows:
1. List all primed entries in the tableau, column by
column, in decreasing order within each column, moving
from the rightmost column to the left, and with all
the primes removed (i.e. all entries are increased by
half a unit).
2. Then list all unprimed entries, row by row, in
increasing order within each row, moving from the
bottommost row to the top.
EXAMPLES::
sage: SPT = ShiftedPrimedTableaux([4,2])
sage: t = SPT([[1,'2p',2,2],[2,'3p']])
sage: t.reading_word()
[3, 2, 2, 1, 2, 2]
"""
if self._skew is not None:
raise NotImplementedError('skew tableau must be empty')
return [tup[1] for tup in self._reading_word_with_positions()]
def f(self, ind):
r"""
Compute the action of the crystal operator `f_i` on a shifted primed
tableau using cases from the paper [HPS2017]_.
INPUT:
- ``ind`` -- element in the index set of the crystal
OUTPUT:
Primed tableau or ``None``.
EXAMPLES::
sage: SPT = ShiftedPrimedTableaux([5,4,2])
sage: t = SPT([[1,1,1,1,'3p'],[2,2,2,'3p'],[3,3]])
sage: t.pp()
1 1 1 1 3'
2 2 2 3'
3 3
sage: s = t.f(2)
sage: s is None
True
sage: t = SPT([[1,1,1,'2p','3p'],[2,2,3,3],[3,4]])
sage: t.pp()
1 1 1 2' 3'
2 2 3 3
3 4
sage: s = t.f(2)
sage: s.pp()
1 1 1 2' 3'
2 3' 3 3
3 4
sage: SPT = ShiftedPrimedTableaux([2,1])
sage: t = SPT([[1,1],[2]])
sage: t.f(0).pp()
1 2'
2
sage: t.f(1).pp()
1 2'
2
sage: t.f(2).pp()
1 1
3
sage: r = SPT([[1,'2p'],[2]])
sage: r.f(0) is None
True
sage: r.f(1) is None
True
sage: r.f(2).pp()
1 2'
3
sage: r = SPT([[1,1],[3]])
sage: r.f(0).pp()
1 2'
3
sage: r.f(1).pp()
1 2
3
sage: r.f(2) is None
True
sage: r = SPT([[1,2],[3]])
sage: r.f(0).pp()
2 2
3
sage: r.f(1).pp()
2 2
3
sage: r.f(2) is None
True
sage: t = SPT([[1,1],[2]])
sage: t.f(0).f(2).f(2).f(0) == t.f(2).f(1).f(0).f(2)
True
sage: t.f(0).f(2).f(2).f(0).pp()
2 3'
3
sage: all(t.f(0).f(2).f(2).f(0).f(i) is None for i in {0, 1, 2})
True
sage: SPT = ShiftedPrimedTableaux([4])
sage: t = SPT([[1,1,1,1]])
sage: t.f(0).pp()
1 1 1 2'
sage: t.f(1).pp()
1 1 1 2
sage: t.f(0).f(0) is None
True
sage: t.f(1).f(0).pp()
1 1 2' 2
sage: t.f(1).f(1).pp()
1 1 2 2
sage: t.f(1).f(1).f(0).pp()
1 2' 2 2
sage: t.f(1).f(1).f(1).pp()
1 2 2 2
sage: t.f(1).f(1).f(1).f(0).pp()
2 2 2 2
sage: t.f(1).f(1).f(1).f(1).pp()
2 2 2 2
sage: t.f(1).f(1).f(1).f(1).f(0) is None
True
"""
T = self._to_matrix()
# special logic for queer lowering operator f_0
if ind == 0:
read_word = [num for num in self._reading_word_with_positions() if num[1] in {1, 2}]
# f_0 acts as zero if tableau contains 2'
if any(elt == 2 and T[pos[0]][pos[1]].is_primed() for pos, elt in read_word):
return None
ones = sorted([pos for pos, elt in read_word if elt == 1], key=lambda x: x[1])
# f_0 acts as zero if tableau cotnains no entries equal to 1
if len(ones) == 0:
return None
# otherwise, f_0 changes last 1 in first row to 2'
else:
r, c = ones[-1]
assert r == 0
T[r][c] = PrimedEntry('2p') if r != c else PrimedEntry(2)
T = [tuple(elmt for elmt in row if elmt is not None) for row in T]
return type(self)(self.parent(), T, check=False, preprocessed=True)
read_word = [num for num in self._reading_word_with_positions()
if num[1] == ind or num[1] == ind+1]
element_to_change = None
count = 0