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
/
tensor_product_element.pyx
1654 lines (1417 loc) · 51 KB
/
tensor_product_element.pyx
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 -*-
"""
Tensor Products of Crystal Elements
AUTHORS:
- Anne Schilling, Nicolas Thiery (2007): Initial version
- Ben Salisbury, Travis Scrimshaw (2013): Refactored tensor products to handle
non-regular crystals and created new subclass to take advantage of
the regularity
- Travis Scrimshaw (2017): Cythonized element classes
- Franco Saliola (2017): Tensor products for crystal of super algebras
- Anne Schilling (2018): Tensor products for crystals of queer super algebras
"""
#*****************************************************************************
# Copyright (C) 2007 Anne Schilling <anne at math.ucdavis.edu>
# Nicolas Thiery <nthiery at users.sf.net>
# 2017 Franco Saliola <saliola@gmail.com>
# 2017 Travis Scrimshaw <tcscrims at gmail.com>
#
# Distributed under the terms of the GNU General Public License (GPL)
#
# 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. See the GNU
# General Public License for more details.
#
# The full text of the GPL is available at:
#
# https://www.gnu.org/licenses/
#****************************************************************************
from cpython.object cimport Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, Py_GE
from sage.structure.parent cimport Parent
from sage.misc.cachefunc import cached_method, cached_in_parent_method
from sage.functions.other import ceil
from sage.combinat.tableau import Tableau
from sage.rings.all import ZZ
##############################################################################
# Support classes
##############################################################################
cdef class ImmutableListWithParent(ClonableArray):
r"""
A class for lists having a parent
Specification: any subclass ``C`` should implement ``__init__`` which
accepts the following form ``C(parent, list=list)``
"""
def __init__(self, Parent parent, list):
"""
Initialize ``self``.
TESTS::
sage: b = crystals.Tableaux(['A',2], shape=[2,1]).module_generators[0]
sage: TestSuite(b).run()
"""
ClonableArray.__init__(self, parent, list, check=False)
cpdef long _hash_(self) except? -1:
"""
Return the hash of ``self``.
TESTS::
sage: b = crystals.Tableaux(['A',2], shape=[2,1]).module_generators[0]
sage: b._hash_() == hash(b)
True
"""
return hash(tuple(self._list))
def __setstate__(self, state):
"""
For unpickling old pickles.
EXAMPLES::
sage: T = crystals.Tableaux(['A',2], shape=[2,1])
sage: b = T.module_generators[0]
sage: b.__setstate__([T, {'_list': list(b)}])
"""
self._parent = state[0]
self._list = state[1]['_list']
self._is_immutable = True
self._hash = 0
cpdef _set_index(self, k, value):
r"""
Return a sibling of ``self`` obtained by setting the
`k^{th}` entry of self to value.
EXAMPLES::
sage: b = crystals.Tableaux(['A',2], shape=[3]).module_generators[0]
sage: list(b._set_index(0, 2))
[2, 1, 1]
sage: list(b._set_index(1, 4))
[1, 4, 1]
"""
cdef list l = list(self._list) # Make a (shallow) copy
l[k] = value
return type(self)(self._parent, list=l)
##############################################################################
# Primary classes
##############################################################################
cdef class TensorProductOfCrystalsElement(ImmutableListWithParent):
r"""
A class for elements of tensor products of crystals.
"""
def _repr_(self):
"""
Return a string representation of ``self``.
EXAMPLES::
sage: C = crystals.Letters(['A',3])
sage: T = crystals.TensorProduct(C,C)
sage: T(C(1),C(2))
[1, 2]
"""
if self._parent.options.convention == "Kashiwara":
return repr(list(reversed(self._list)))
return repr(self._list)
def _latex_(self):
r"""
Return latex code for ``self``.
EXAMPLES::
sage: C = crystals.Letters(["A",2])
sage: D = crystals.Tableaux(["A",2], shape=[2])
sage: E = crystals.TensorProduct(C,D)
sage: latex(E.module_generators[0])
1 \otimes {\def\lr#1{\multicolumn{1}{|@{\hspace{.6ex}}c@{\hspace{.6ex}}|}{\raisebox{-.3ex}{$#1$}}}
\raisebox{-.6ex}{$\begin{array}[b]{*{2}c}\cline{1-2}
\lr{1}&\lr{1}\\\cline{1-2}
\end{array}$}
}
"""
from sage.misc.latex import latex
if self._parent.options.convention == "Kashiwara":
return ' \otimes '.join(latex(c) for c in reversed(self))
return ' \otimes '.join(latex(c) for c in self)
def _ascii_art_(self):
"""
Return an ASCII art representation of ``self``.
EXAMPLES::
sage: KT = crystals.TensorProductOfKirillovReshetikhinTableaux(['D',4,1],[[3,3],[2,1],[1,2]])
sage: ascii_art(KT.module_generators[0])
1 1 1
2 2 2 # 1 # 1 1
3 3 3 2
-4 -4 -4
"""
if self._parent.options.convention == "Kashiwara":
lst = list(reversed(self))
else:
lst = self
from sage.typeset.ascii_art import ascii_art, AsciiArt
s = ascii_art(lst[0])
s._baseline = s._h // 2
ret = s
for tableau in lst[1:]:
s = ascii_art(tableau)
s._baseline = s._h // 2
ret += AsciiArt([" # "]) + s
return ret
def _unicode_art_(self):
"""
Return a unicode art representation of ``self``.
EXAMPLES::
sage: KT = crystals.TensorProductOfKirillovReshetikhinTableaux(['D',4,1],[[3,3],[2,1],[1,2]])
sage: unicode_art(KT.module_generators[0])
┌───┬───┬───┐
│ 1 │ 1 │ 1 │
├───┼───┼───┤ ┌───┐
│ 2 │ 2 │ 2 │ │ 1 │ ┌───┬───┐
├───┼───┼───┤ ⊗ ├───┤ ⊗ │ 1 │ 1 │
│ 3 │ 3 │ 3 │ │ 2 │ └───┴───┘
├───┼───┼───┤ └───┘
│ 4̄ │ 4̄ │ 4̄ │
└───┴───┴───┘
"""
if self._parent.options.convention == "Kashiwara":
lst = list(reversed(self))
else:
lst = self
from sage.typeset.unicode_art import unicode_art, UnicodeArt
s = unicode_art(lst[0])
s._baseline = s._h // 2
ret = s
for tableau in lst[1:]:
s = unicode_art(tableau)
s._baseline = s._h // 2
ret += UnicodeArt([u" ⊗ "]) + s
return ret
def _repr_diagram(self):
r"""
Return a string representation of ``self`` as a diagram.
EXAMPLES::
sage: C = crystals.Tableaux(['A',3], shape=[3,1])
sage: D = crystals.Tableaux(['A',3], shape=[1])
sage: E = crystals.Tableaux(['A',3], shape=[2,2,2])
sage: T = crystals.TensorProduct(C,D,E)
sage: print(T.module_generators[0]._repr_diagram())
1 1 1 (X) 1 (X) 1 1
2 2 2
3 3
"""
pplist = []
max_widths = []
num_cols = len(self._list)
for c in self:
try:
pplist.append(c._repr_diagram().split('\n'))
except AttributeError:
pplist.append(c._repr_().split('\n'))
max_widths.append(max(map(len, pplist[-1])))
num_rows = max(map(len, pplist))
ret = ""
for i in range(num_rows):
if i > 0:
ret += '\n'
for j in range(num_cols):
if j > 0:
if i == 0:
ret += ' (X) '
else:
ret += ' '
if i < len(pplist[j]):
ret += pplist[j][i]
ret += ' '*(max_widths[j] - len(pplist[j][i]))
else:
ret += ' '*max_widths[j]
return ret
def pp(self):
"""
Pretty print ``self``.
EXAMPLES::
sage: C = crystals.Tableaux(['A',3], shape=[3,1])
sage: D = crystals.Tableaux(['A',3], shape=[1])
sage: E = crystals.Tableaux(['A',3], shape=[2,2,2])
sage: T = crystals.TensorProduct(C,D,E)
sage: T.module_generators[0].pp()
1 1 1 (X) 1 (X) 1 1
2 2 2
3 3
"""
print(self._repr_diagram())
def weight(self):
r"""
Return the weight of ``self``.
EXAMPLES::
sage: B = crystals.infinity.Tableaux("A3")
sage: T = crystals.TensorProduct(B,B)
sage: b1 = B.highest_weight_vector().f_string([2,1,3])
sage: b2 = B.highest_weight_vector().f(1)
sage: t = T(b2, b1)
sage: t
[[[1, 1, 1, 2], [2, 2], [3]], [[1, 1, 1, 1, 2], [2, 2, 4], [3]]]
sage: t.weight()
(-2, 1, 0, 1)
::
sage: C = crystals.Letters(['A',3])
sage: T = crystals.TensorProduct(C,C)
sage: T(C(1),C(2)).weight()
(1, 1, 0, 0)
sage: T = crystals.Tableaux(['D',4],shape=[])
sage: T.list()[0].weight()
(0, 0, 0, 0)
"""
WLR = self._parent.weight_lattice_realization()
return WLR(sum(elt.weight() for elt in self))
def epsilon(self, i):
r"""
Return `\varepsilon_i` of ``self``.
INPUT:
- ``i`` -- an element of the index set
EXAMPLES::
sage: B = crystals.infinity.Tableaux("G2")
sage: T = crystals.TensorProduct(B,B)
sage: b1 = B.highest_weight_vector().f(2)
sage: b2 = B.highest_weight_vector().f_string([2,2,1])
sage: t = T(b2, b1)
sage: [t.epsilon(i) for i in B.index_set()]
[0, 3]
"""
return max(self._sig(i, k) for k in range(1, len(self._list)+1))
def phi(self, i):
r"""
Return `\varphi_i` of ``self``.
INPUT:
- ``i`` -- an element of the index set
EXAMPLES::
sage: La = RootSystem(['A',2,1]).weight_lattice(extended=True).fundamental_weights()
sage: B = crystals.GeneralizedYoungWalls(2,La[0]+La[1])
sage: T = crystals.TensorProduct(B,B)
sage: b1 = B.highest_weight_vector().f_string([1,0])
sage: b2 = B.highest_weight_vector().f_string([0,1])
sage: t = T(b2, b1)
sage: [t.phi(i) for i in B.index_set()]
[1, 1, 4]
TESTS:
Check that :trac:`15462` is fixed::
sage: B = crystals.Tableaux(['A',2], shape=[2,1])
sage: La = RootSystem(['A',2]).ambient_space().fundamental_weights()
sage: T = crystals.TensorProduct(crystals.elementary.T(['A',2], La[1]+La[2]), B)
sage: t = T.an_element()
sage: t.phi(1)
2
sage: t.phi(2)
2
"""
P = self._list[-1].parent().weight_lattice_realization()
h = P.simple_coroots()
omega = P(self.weight()).scalar(h[i])
return max(omega + self._sig(i, k) for k in range(1, len(self._list)+1))
@cached_in_parent_method
def _sig(self, i, k):
r"""
Return `a_i(k)` of ``self``.
The value `a_i(k)` of a crystal `b = b_N \otimes \cdots \otimes b_1`
is defined as:
.. MATH::
a_i(k) = \varepsilon_i(b_k) - \sum_{j=1}^{k-1} \langle h_i,
\mathrm{wt}(b_j) \rangle
where `\mathrm{wt}` is the :meth:`weight` of `b_j`.
INPUT:
- ``i`` -- an element of the index set
- ``k`` -- the (1-based) index of the tensor factor of ``self``
EXAMPLES::
sage: B = crystals.infinity.GeneralizedYoungWalls(3)
sage: T = crystals.TensorProduct(B,B)
sage: b1 = B.highest_weight_vector().f_string([0,3,1])
sage: b2 = B.highest_weight_vector().f_string([3,2,1,0,2,3])
sage: t = T(b1, b2)
sage: [[t._sig(i,k) for k in range(1,len(t)+1)] for i in B.index_set()]
[[0, -1], [0, 0], [0, 1], [1, 2]]
TESTS:
Check that :trac:`18469` is fixed::
sage: E1 = crystals.elementary.B(['A',2], 1)
sage: E2 = crystals.elementary.B(['A',2], 2)
sage: T = crystals.TensorProduct(E1, E2)
sage: x = T(E1.module_generators[0], E2.module_generators[0]); x
[0, 0]
sage: [[x._sig(i,k) for k in range(1,3)] for i in T.index_set()]
[[-inf, 0], [0, -inf]]
sage: x.f(1)
[-1, 0]
sage: x.e(1)
[1, 0]
"""
if k == 1:
return self._list[-1].epsilon(i)
ep = self._list[-k].epsilon(i)
if ep == float("-inf"):
return ep
P = self._list[-1].parent().weight_lattice_realization()
h = P.simple_coroots()
wt = P.sum(P(self._list[-j].weight()) for j in range(1, k))
return ep - wt.scalar(h[i])
def e(self, i):
r"""
Return the action of `e_i` on ``self``.
INPUT:
- ``i`` -- an element of the index set
EXAMPLES::
sage: B = crystals.infinity.Tableaux("D4")
sage: T = crystals.TensorProduct(B,B)
sage: b1 = B.highest_weight_vector().f_string([1,4,3])
sage: b2 = B.highest_weight_vector().f_string([2,2,3,1,4])
sage: t = T(b2, b1)
sage: t.e(1)
[[[1, 1, 1, 1, 1], [2, 2, 3, -3], [3]], [[1, 1, 1, 1, 2], [2, 2, 2], [3, -3]]]
sage: t.e(2)
sage: t.e(3)
[[[1, 1, 1, 1, 1, 2], [2, 2, 3, -4], [3]], [[1, 1, 1, 1, 2], [2, 2, 2], [3, -3]]]
sage: t.e(4)
[[[1, 1, 1, 1, 1, 2], [2, 2, 3, 4], [3]], [[1, 1, 1, 1, 2], [2, 2, 2], [3, -3]]]
"""
N = len(self._list) + 1
for k in range(1, N):
if all(self._sig(i,k) > self._sig(i,j) for j in range(1, k)) and \
all(self._sig(i,k) >= self._sig(i,j) for j in range(k+1, N)):
crystal = self._list[-k].e(i)
if crystal is None:
return None
return self._set_index(-k, crystal)
return None
def f(self, i):
r"""
Return the action of `f_i` on ``self``.
INPUT:
- ``i`` -- an element of the index set
EXAMPLES::
sage: La = RootSystem(['A',3,1]).weight_lattice(extended=True).fundamental_weights()
sage: B = crystals.GeneralizedYoungWalls(3,La[0])
sage: T = crystals.TensorProduct(B,B,B)
sage: b1 = B.highest_weight_vector().f_string([0,3])
sage: b2 = B.highest_weight_vector().f_string([0])
sage: b3 = B.highest_weight_vector()
sage: t = T(b3, b2, b1)
sage: t.f(0)
[[[0]], [[0]], [[0, 3]]]
sage: t.f(1)
[[], [[0]], [[0, 3], [1]]]
sage: t.f(2)
[[], [[0]], [[0, 3, 2]]]
sage: t.f(3)
[[], [[0, 3]], [[0, 3]]]
"""
N = len(self._list) + 1
for k in range(1, N):
if all(self._sig(i,k) >= self._sig(i,j) for j in range(1, k)) and \
all(self._sig(i,k) > self._sig(i,j) for j in range(k+1, N)):
crystal = self._list[-k].f(i)
if crystal is None:
return None
return self._set_index(-k, crystal)
return None
cdef class TensorProductOfRegularCrystalsElement(TensorProductOfCrystalsElement):
"""
Element class for a tensor product of regular crystals.
TESTS::
sage: C = crystals.Letters(['A',2])
sage: T = crystals.TensorProduct(C, C)
sage: elt = T(C(1), C(2))
sage: from sage.combinat.crystals.tensor_product import TensorProductOfRegularCrystalsElement
sage: isinstance(elt, TensorProductOfRegularCrystalsElement)
True
"""
def e(self, i):
"""
Return the action of `e_i` on ``self``.
EXAMPLES::
sage: C = crystals.Letters(['A',5])
sage: T = crystals.TensorProduct(C,C)
sage: T(C(1),C(2)).e(1) == T(C(1),C(1))
True
sage: T(C(2),C(1)).e(1) is None
True
sage: T(C(2),C(2)).e(1) == T(C(1),C(2))
True
"""
if i not in self.index_set():
raise ValueError("i must be in the index set")
k = self.position_of_first_unmatched_plus(i)
if k is None:
return None
return self._set_index(k, self._list[k].e(i))
def f(self, i):
"""
Return the action of `f_i` on ``self``.
EXAMPLES::
sage: C = crystals.Letters(['A',5])
sage: T = crystals.TensorProduct(C,C)
sage: T(C(1),C(1)).f(1)
[1, 2]
sage: T(C(1),C(2)).f(1)
[2, 2]
sage: T(C(2),C(1)).f(1) is None
True
"""
if i not in self.index_set():
raise ValueError("i must be in the index set")
k = self.position_of_last_unmatched_minus(i)
if k is None:
return None
return self._set_index(k, self._list[k].f(i))
def phi(self, i):
r"""
Return `\varphi_i` of ``self``.
EXAMPLES::
sage: C = crystals.Letters(['A',5])
sage: T = crystals.TensorProduct(C,C)
sage: T(C(1),C(1)).phi(1)
2
sage: T(C(1),C(2)).phi(1)
1
sage: T(C(2),C(1)).phi(1)
0
"""
height = 0
for elt in reversed(self._list):
plus = elt.epsilon(i)
minus = elt.phi(i)
if height - plus < 0:
height = minus
else:
height = height - plus + minus
return height
def epsilon(self, i):
r"""
Return `\varepsilon_i` of ``self``.
EXAMPLES::
sage: C = crystals.Letters(['A',5])
sage: T = crystals.TensorProduct(C,C)
sage: T(C(1),C(1)).epsilon(1)
0
sage: T(C(1),C(2)).epsilon(1)
1
sage: T(C(2),C(1)).epsilon(1)
0
"""
height = 0
for elt in self:
minus = elt.phi(i)
plus = elt.epsilon(i)
if height - minus < 0:
height = plus
else:
height = height - minus + plus
return height
cpdef position_of_last_unmatched_minus(self, i):
"""
Return the position of the last unmatched `-` or ``None`` if
there is no unmatched `-`.
EXAMPLES::
sage: C = crystals.Letters(['A',5])
sage: T = crystals.TensorProduct(C,C)
sage: T(C(2),C(1)).position_of_last_unmatched_minus(1)
sage: T(C(1),C(2)).position_of_last_unmatched_minus(1)
0
"""
unmatched_minus = None
height = 0
cdef int j
for j,elt in enumerate(self):
plus = elt.epsilon(i)
minus = elt.phi(i)
if height - minus < 0:
unmatched_minus = j
height = plus
else:
height = height - minus + plus
return unmatched_minus
cpdef position_of_first_unmatched_plus(self, i):
"""
Return the position of the first unmatched `+` or ``None`` if
there is no unmatched `+`.
EXAMPLES::
sage: C = crystals.Letters(['A',5])
sage: T = crystals.TensorProduct(C,C)
sage: T(C(2),C(1)).position_of_first_unmatched_plus(1)
sage: T(C(1),C(2)).position_of_first_unmatched_plus(1)
1
"""
unmatched_plus = None
height = 0
cdef int N = len(self._list) - 1
cdef int j
for j, elt in enumerate(reversed(self._list)):
plus = elt.epsilon(i)
minus = elt.phi(i)
if height - plus < 0:
unmatched_plus = N - j
height = minus
else:
height = height - plus + minus
return unmatched_plus
# Legacy function
def positions_of_unmatched_minus(self, i, dual=False, reverse=False):
"""
EXAMPLES::
sage: C = crystals.Letters(['A',5])
sage: T = crystals.TensorProduct(C,C)
sage: T(C(2),C(1)).positions_of_unmatched_minus(1)
[]
sage: T(C(1),C(2)).positions_of_unmatched_minus(1)
[0]
"""
cdef list unmatched_plus = []
cdef int j
height = 0
if reverse:
self = type(self)(self._parent, list(reversed(self._list)))
if not dual:
for j,elt in enumerate(self):
minus = elt.phi(i)
plus = elt.epsilon(i)
if height-minus < 0:
unmatched_plus.append(j)
height = plus
else:
height = height - minus + plus
else:
for j,elt in enumerate(self):
plus = elt.epsilon(i)
minus = elt.phi(i)
if height-plus < 0:
unmatched_plus.append(j)
height = minus
else:
height = height - plus + minus
return unmatched_plus
# Legacy function
def positions_of_unmatched_plus(self, i):
"""
EXAMPLES::
sage: C = crystals.Letters(['A',5])
sage: T = crystals.TensorProduct(C,C)
sage: T(C(2),C(1)).positions_of_unmatched_plus(1)
[]
sage: T(C(1),C(2)).positions_of_unmatched_plus(1)
[1]
"""
cdef list L = self.positions_of_unmatched_minus(i, dual=True, reverse=True)
L.reverse()
cdef int N = len(self._list) - 1
return [N - val for val in L]
cdef class CrystalOfTableauxElement(TensorProductOfRegularCrystalsElement):
"""
Element in a crystal of tableaux.
"""
def __init__(self, parent, *args, **options):
"""
There are several ways to input tableaux, by rows, by columns,
by columns, as the list of column elements, or as a sequence
of numbers in column reading.
EXAMPLES::
sage: T = crystals.Tableaux(['A',3], shape = [2,2])
sage: t = T(rows=[[1,2],[3,4]])
sage: t
[[1, 2], [3, 4]]
sage: TestSuite(t).run()
sage: t = T(columns=[[3,1],[4,2]])
sage: t
[[1, 2], [3, 4]]
sage: TestSuite(t).run()
sage: t = T(list=[3,1,4,2])
sage: t
[[1, 2], [3, 4]]
sage: t = T(3,1,4,2)
sage: t
[[1, 2], [3, 4]]
Currently inputting the empty tableau as an empty sequence is
broken due to a bug in the generic __call__ method (see :trac:`8648`).
EXAMPLES::
sage: T = crystals.Tableaux(['A',3], shape=[])
sage: t = T()
sage: list(t)
[0]
TESTS:
Integer types that are not a Sage ``Integer`` (such as a Python ``int``
and typically arise from compiled code) were not converted into a
letter. This caused certain functions to fail. This is fixed in
:trac:`13204`::
sage: T = crystals.Tableaux(['A',3], shape = [2,2])
sage: t = T(list=[int(3),1,4,2])
sage: type(t[0])
<... 'sage.combinat.crystals.letters.Crystal_of_letters_type_A_element'>
sage: t = T(list=[3,int(1),4,2])
sage: type(t[1])
<... 'sage.combinat.crystals.letters.Crystal_of_letters_type_A_element'>
sage: C = crystals.KirillovReshetikhin(['A',int(3),1], 1,1)
sage: C[0].e(0)
[[4]]
"""
if len(args) == 1:
if isinstance(args[0], Tableau):
options['rows'] = args[0]
if 'list' in options:
the_list = options['list']
elif 'rows' in options:
rows = options['rows']
# the_list=Tableau(rows).to_word_by_column()
rows = Tableau(rows).conjugate()
the_list = []
for col in rows:
the_list += reversed(col)
elif 'columns' in options:
columns = options['columns']
the_list = []
for col in columns:
the_list += col
else:
the_list = [i for i in args]
TensorProductOfRegularCrystalsElement.__init__(self, parent, [parent.letters(_) for _ in the_list])
def _repr_(self):
"""
EXAMPLES::
sage: T = crystals.Tableaux(['A',3], shape = [2,2])
sage: t = T(rows=[[1,2],[3,4]])
sage: t._repr_()
'[[1, 2], [3, 4]]'
"""
return repr(self.to_tableau())
def _repr_diagram(self):
"""
Return a string representation of ``self`` as a diagram.
EXAMPLES::
sage: C = crystals.Tableaux(['A', 4], shape=[4,2,1])
sage: elt = C(rows=[[1,1,1,2], [2,3], [4]])
sage: print(elt._repr_diagram())
1 1 1 2
2 3
4
"""
return self.to_tableau()._repr_diagram()
def pp(self):
"""
EXAMPLES::
sage: T = crystals.Tableaux(['A',3], shape = [2,2])
sage: t = T(rows=[[1,2],[3,4]])
sage: t.pp()
1 2
3 4
"""
return self.to_tableau().pp()
def _ascii_art_(self):
"""
Return an ascii art version of ``self``.
EXAMPLES:
We check that :trac:`16486` is fixed::
sage: T = crystals.Tableaux(['B',6], shape=[1]*5)
sage: ascii_art(T.module_generators[0])
1
2
3
4
5
sage: T = crystals.Tableaux(['D',4], shape=[2,1])
sage: t = T.module_generators[0].f_string([1,2,3,4,2,2,3,4])
sage: ascii_art(t)
1 -2
-3
"""
return self.to_tableau()._ascii_art_()
def _unicode_art_(self):
"""
Return a unicode art version of ``self``.
EXAMPLES::
sage: T = crystals.Tableaux(['B',4], shape=[1]*3)
sage: unicode_art(T.module_generators[0])
┌───┐
│ 1 │
├───┤
│ 2 │
├───┤
│ 3 │
└───┘
sage: T = crystals.Tableaux(['D',4], shape=[2,1])
sage: t = T.module_generators[0].f_string([1,2,3,4,2,2,3,4])
sage: unicode_art(t)
┌───┬───┐
│ 1 │ 2̄ │
├───┼───┘
│ 3̄ │
└───┘
"""
if not self._list:
return Tableau([])._unicode_art_()
cdef list lst = self._list
cdef list tab = [ [lst[0]] ]
cdef int i
for i in range(1,len(self)):
if lst[i-1] < lst[i] or (lst[i-1].value != 0 and lst[i-1] == lst[i]):
tab.append([lst[i]])
else:
tab[len(tab)-1].append(lst[i])
for x in tab:
x.reverse()
return Tableau(tab).conjugate()._unicode_art_()
def _latex_(self):
r"""
EXAMPLES::
sage: T = crystals.Tableaux(['A',3], shape = [4,2])
sage: t = T(rows=[[1,1,2,3],[2,3]])
sage: latex(t) # indirect doctest
{\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{1}&\lr{2}&\lr{3}\\\cline{1-4}
\lr{2}&\lr{3}\\\cline{1-2}
\end{array}$}
}
"""
from sage.combinat.output import tex_from_array
# Modified version of to_tableau() to have the entries be letters
# rather than their values
if not self._list:
return "{\\emptyset}"
tab = [ [self[0]] ]
for i in range(1,len(self)):
if self[i-1] < self[i] or (self[i-1].value != 0 and self[i-1] == self[i]):
tab.append([self[i]])
else:
l = len(tab)-1
tab[l].append(self[i])
for x in tab:
x.reverse()
T = Tableau(tab).conjugate()
return tex_from_array([[letter._latex_() for letter in row] for row in T])
@cached_method
def to_tableau(self):
"""
Return the :class:`Tableau` object corresponding to ``self``.
EXAMPLES::
sage: T = crystals.Tableaux(['A',3], shape = [2,2])
sage: t = T(rows=[[1,2],[3,4]]).to_tableau(); t
[[1, 2], [3, 4]]
sage: type(t)
<class 'sage.combinat.tableau.Tableaux_all_with_category.element_class'>
sage: type(t[0][0])
<... 'int'>
sage: T = crystals.Tableaux(['D',3], shape = [1,1])
sage: t=T(rows=[[-3],[3]]).to_tableau(); t
[[-3], [3]]
sage: t=T(rows=[[3],[-3]]).to_tableau(); t
[[3], [-3]]
sage: T = crystals.Tableaux(['B',2], shape = [1,1])
sage: t = T(rows=[[0],[0]]).to_tableau(); t
[[0], [0]]
"""
if not self._list:
return Tableau([])
cdef list lst = self._list
cdef list tab = [ [lst[0].value] ]
cdef int i
for i in range(1,len(self)):
if lst[i-1] < lst[i] or (lst[i-1].value != 0 and lst[i-1] == lst[i]):
tab.append([lst[i].value])
else:
tab[len(tab)-1].append(lst[i].value)
for x in tab:
x.reverse()
return Tableau(tab).conjugate()
def shape(self):
r"""
Return the shape of the tableau corresponding to ``self``.
OUTPUT: an instance of :class:`Partition`
.. SEEALSO::
:meth:`to_tableau`
EXAMPLES::
sage: C = crystals.Tableaux(["A", 2], shape=[2,1])
sage: x = C.an_element()
sage: x.to_tableau().shape()
[2, 1]
sage: x.shape()
[2, 1]
"""
return self.to_tableau().shape()
def promotion(self):
"""
Return the result of applying promotion on ``self``.
Promotion for type A crystals of tableaux of rectangular shape.
This method only makes sense in type A with rectangular shapes.
EXAMPLES::
sage: C = crystals.Tableaux(["A",3], shape = [3,3,3])
sage: t = C(Tableau([[1,1,1],[2,2,3],[3,4,4]]))
sage: t
[[1, 1, 1], [2, 2, 3], [3, 4, 4]]
sage: t.promotion()
[[1, 1, 2], [2, 2, 3], [3, 4, 4]]
sage: t.promotion().parent()
The crystal of tableaux of type ['A', 3] and shape(s) [[3, 3, 3]]
"""
crystal = self._parent
cartan_type = crystal.cartan_type()
assert cartan_type.type() == 'A'
return crystal(self.to_tableau().promotion(cartan_type.rank()))
def promotion_inverse(self):
"""
Return the result of applying inverse promotion on ``self``.
Inverse promotion for type A crystals of tableaux of rectangular shape.
This method only makes sense in type A with rectangular shapes.
EXAMPLES::
sage: C = crystals.Tableaux(["A",3], shape = [3,3,3])
sage: t = C(Tableau([[1,1,1],[2,2,3],[3,4,4]]))
sage: t