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
/
diagram_algebras.py
3210 lines (2683 loc) · 109 KB
/
diagram_algebras.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
r"""
Diagram and Partition Algebras
AUTHORS:
- Mike Hansen (2007): Initial version
- Stephen Doty, Aaron Lauve, George H. Seelinger (2012): Implementation of
partition, Brauer, Temperley--Lieb, and ideal partition algebras
- Stephen Doty, Aaron Lauve, George H. Seelinger (2015): Implementation of
``*Diagram`` classes and other methods to improve diagram algebras.
"""
#*****************************************************************************
# Copyright (C) 2007 Mike Hansen <mhansen@gmail.com>,
# 2012 Stephen Doty <doty@math.luc.edu>,
# Aaron Lauve <lauve@math.luc.edu>,
# George H. Seelinger <ghseeli@gmail.com>
#
# Distributed under the terms of the GNU General Public License (GPL)
# http://www.gnu.org/licenses/
#****************************************************************************
# python3
from __future__ import division
from six.moves import range
from sage.categories.algebras import Algebras
from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
from sage.arith.power import generic_power
from sage.combinat.free_module import CombinatorialFreeModule
from sage.structure.parent import Parent
from sage.structure.unique_representation import UniqueRepresentation
from sage.combinat.combinat import bell_number, catalan_number
from sage.structure.global_options import GlobalOptions
from sage.combinat.set_partition import SetPartitions, AbstractSetPartition
from sage.combinat.partition import Partitions
from sage.combinat.symmetric_group_algebra import SymmetricGroupAlgebra_n
from sage.combinat.permutation import Permutations
from sage.sets.set import Set
from sage.graphs.graph import Graph
from sage.misc.cachefunc import cached_method
from sage.misc.lazy_attribute import lazy_attribute
from sage.misc.flatten import flatten
from sage.rings.all import ZZ
def partition_diagrams(k):
r"""
Return a generator of all partition diagrams of order ``k``.
A partition diagram of order `k \in \ZZ` to is a set partition of
`\{1, \ldots, k, -1, \ldots, -k\}`. If we have `k - 1/2 \in ZZ`, then
a partition diagram of order `k \in 1/2 \ZZ` is a set partition of
`\{1, \ldots, k+1/2, -1, \ldots, -(k+1/2)\}` with `k+1/2` and `-(k+1/2)`
in the same block. See [HR2005]_.
INPUT:
- ``k`` -- the order of the partition diagrams
EXAMPLES::
sage: import sage.combinat.diagram_algebras as da
sage: [SetPartition(p) for p in da.partition_diagrams(2)]
[{{-2, -1, 1, 2}}, {{-2, -1, 2}, {1}}, {{-2, -1, 1}, {2}},
{{-2}, {-1, 1, 2}}, {{-2, 1, 2}, {-1}}, {{-2, 1}, {-1, 2}},
{{-2, 2}, {-1, 1}}, {{-2, -1}, {1, 2}}, {{-2, -1}, {1}, {2}},
{{-2}, {-1, 2}, {1}}, {{-2, 2}, {-1}, {1}}, {{-2}, {-1, 1}, {2}},
{{-2, 1}, {-1}, {2}}, {{-2}, {-1}, {1, 2}}, {{-2}, {-1}, {1}, {2}}]
sage: [SetPartition(p) for p in da.partition_diagrams(3/2)]
[{{-2, -1, 1, 2}}, {{-2, -1, 2}, {1}}, {{-2, 2}, {-1, 1}},
{{-2, 1, 2}, {-1}}, {{-2, 2}, {-1}, {1}}]
"""
if k in ZZ:
S = SetPartitions(list(range(1, k+1)) + [-j for j in range(1, k+1)] )
for p in Partitions(2*k):
for i in S._iterator_part(p):
yield i
elif k + ZZ(1)/ZZ(2) in ZZ: # Else k in 1/2 ZZ
k = ZZ(k + ZZ(1) / ZZ(2))
S = SetPartitions(list(range(1, k+1)) + [-j for j in range(1, k)] )
for p in Partitions(2*k-1):
for sp in S._iterator_part(p):
sp = list(sp)
for i in range(len(sp)):
if k in sp[i]:
sp[i] += Set([-k])
break
yield sp
def brauer_diagrams(k):
r"""
Return a generator of all Brauer diagrams of order ``k``.
A Brauer diagram of order `k` is a partition diagram of order `k`
with block size 2.
INPUT:
- ``k`` -- the order of the Brauer diagrams
EXAMPLES::
sage: import sage.combinat.diagram_algebras as da
sage: [SetPartition(p) for p in da.brauer_diagrams(2)]
[{{-2, 1}, {-1, 2}}, {{-2, 2}, {-1, 1}}, {{-2, -1}, {1, 2}}]
sage: [SetPartition(p) for p in da.brauer_diagrams(5/2)]
[{{-3, 3}, {-2, 1}, {-1, 2}}, {{-3, 3}, {-2, 2}, {-1, 1}}, {{-3, 3}, {-2, -1}, {1, 2}}]
"""
if k in ZZ:
S = SetPartitions(list(range(1,k+1)) + [-j for j in range(1,k+1)],
[2 for j in range(1,k+1)] )
for i in S._iterator_part(S.parts):
yield list(i)
elif k + ZZ(1) / ZZ(2) in ZZ: # Else k in 1/2 ZZ
k = ZZ(k + ZZ(1) / ZZ(2))
S = SetPartitions(list(range(1, k)) + [-j for j in range(1, k)],
[2 for j in range(1, k)] )
for i in S._iterator_part(S.parts):
yield list(i) + [[k, -k]]
def temperley_lieb_diagrams(k):
r"""
Return a generator of all Temperley--Lieb diagrams of order ``k``.
A Temperley--Lieb diagram of order `k` is a partition diagram of order `k`
with block size 2 and is planar.
INPUT:
- ``k`` -- the order of the Temperley--Lieb diagrams
EXAMPLES::
sage: import sage.combinat.diagram_algebras as da
sage: [SetPartition(p) for p in da.temperley_lieb_diagrams(2)]
[{{-2, 2}, {-1, 1}}, {{-2, -1}, {1, 2}}]
sage: [SetPartition(p) for p in da.temperley_lieb_diagrams(5/2)]
[{{-3, 3}, {-2, 2}, {-1, 1}}, {{-3, 3}, {-2, -1}, {1, 2}}]
"""
B = brauer_diagrams(k)
for i in B:
if is_planar(i):
yield i
def planar_diagrams(k):
r"""
Return a generator of all planar diagrams of order ``k``.
A planar diagram of order `k` is a partition diagram of order `k`
that has no crossings.
EXAMPLES::
sage: import sage.combinat.diagram_algebras as da
sage: [SetPartition(p) for p in da.planar_diagrams(2)]
[{{-2, -1, 1, 2}}, {{-2, -1, 2}, {1}}, {{-2, -1, 1}, {2}},
{{-2}, {-1, 1, 2}}, {{-2, 1, 2}, {-1}}, {{-2, 2}, {-1, 1}},
{{-2, -1}, {1, 2}}, {{-2, -1}, {1}, {2}}, {{-2}, {-1, 2}, {1}},
{{-2, 2}, {-1}, {1}}, {{-2}, {-1, 1}, {2}}, {{-2, 1}, {-1}, {2}},
{{-2}, {-1}, {1, 2}}, {{-2}, {-1}, {1}, {2}}]
sage: [SetPartition(p) for p in da.planar_diagrams(3/2)]
[{{-2, -1, 1, 2}}, {{-2, -1, 2}, {1}}, {{-2, 2}, {-1, 1}},
{{-2, 1, 2}, {-1}}, {{-2, 2}, {-1}, {1}}]
"""
A = partition_diagrams(k)
for i in A:
if is_planar(i):
yield i
def ideal_diagrams(k):
r"""
Return a generator of all "ideal" diagrams of order ``k``.
An ideal diagram of order `k` is a partition diagram of order `k` with
propagating number less than `k`.
EXAMPLES::
sage: import sage.combinat.diagram_algebras as da
sage: [SetPartition(p) for p in da.ideal_diagrams(2)]
[{{-2, -1, 1, 2}}, {{-2, -1, 2}, {1}}, {{-2, -1, 1}, {2}}, {{-2}, {-1, 1, 2}},
{{-2, 1, 2}, {-1}}, {{-2, -1}, {1, 2}}, {{-2, -1}, {1}, {2}},
{{-2}, {-1, 2}, {1}}, {{-2, 2}, {-1}, {1}}, {{-2}, {-1, 1}, {2}}, {{-2, 1},
{-1}, {2}}, {{-2}, {-1}, {1, 2}}, {{-2}, {-1}, {1}, {2}}]
sage: [SetPartition(p) for p in da.ideal_diagrams(3/2)]
[{{-2, -1, 1, 2}}, {{-2, -1, 2}, {1}}, {{-2, 1, 2}, {-1}}, {{-2, 2}, {-1}, {1}}]
"""
A = partition_diagrams(k)
for i in A:
if propagating_number(i) < k:
yield i
class AbstractPartitionDiagram(AbstractSetPartition):
r"""
Abstract base class for partition diagrams.
This class represents a single partition diagram, that is used as a
basis key for a diagram algebra element. A partition diagram should
be a partition of the set `\{1, \ldots, k, -1, \ldots, -k\}`. Each
such set partition is regarded as a graph on nodes
`\{1, \ldots, k, -1, \ldots, -k\}` arranged in two rows, with nodes
`1, \ldots, k` in the top row from left to right and with nodes
`-1, \ldots, -k` in the bottom row from left to right, and an edge
connecting two nodes if and only if the nodes lie in the same
subset of the set partition.
EXAMPLES::
sage: import sage.combinat.diagram_algebras as da
sage: pd = da.AbstractPartitionDiagrams(da.partition_diagrams, 2)
sage: pd1 = da.AbstractPartitionDiagram(pd, [[1,2],[-1,-2]])
sage: pd2 = da.AbstractPartitionDiagram(pd, [[1,2],[-1,-2]])
sage: pd1
{{-2, -1}, {1, 2}}
sage: pd1 == pd2
True
sage: pd1 == [[1,2],[-1,-2]]
True
sage: pd1 == ((-2,-1),(2,1))
True
sage: pd1 == SetPartition([[1,2],[-1,-2]])
True
sage: pd3 = da.AbstractPartitionDiagram(pd, [[1,-2],[-1,2]])
sage: pd1 == pd3
False
sage: pd4 = da.AbstractPartitionDiagram(pd, [[1,2],[3,4]])
Traceback (most recent call last):
...
ValueError: {{1, 2}, {3, 4}} does not represent two rows of vertices
"""
def __init__(self, parent, d):
r"""
Initialize ``self``.
EXAMPLES::
sage: import sage.combinat.diagram_algebras as da
sage: pd = da.AbstractPartitionDiagrams(da.partition_diagrams, 2)
sage: pd1 = da.AbstractPartitionDiagram(pd, ((-2,-1),(1,2)) )
"""
self._base_diagram = tuple(sorted(tuple(sorted(i)) for i in d))
self._order = parent.order
super(AbstractPartitionDiagram, self).__init__(parent, self._base_diagram)
def check(self):
r"""
Check the validity of the input for the diagram.
TESTS::
sage: import sage.combinat.diagram_algebras as da
sage: pd = da.AbstractPartitionDiagrams(da.partition_diagrams, 2)
sage: pd1 = da.AbstractPartitionDiagram(pd, [[1,2],[-1,-2]]) # indirect doctest
sage: pd2 = da.AbstractPartitionDiagram(pd, [[1,2],[3,4]]) # indirect doctest
Traceback (most recent call last):
...
ValueError: {{1, 2}, {3, 4}} does not represent two rows of vertices
"""
if self._base_diagram:
tst = sorted(flatten(self._base_diagram))
if len(tst) % 2 or tst != list(range(-len(tst)//2,0)) + list(range(1,len(tst)//2+1)):
raise ValueError("%s does not represent two rows of vertices"%(self))
def __eq__(self, other):
r"""
TESTS::
sage: import sage.combinat.diagram_algebras as da
sage: pd = da.AbstractPartitionDiagrams(da.partition_diagrams, 2)
sage: pd1 = da.AbstractPartitionDiagram(pd, [[1,2],[-1,-2]])
sage: pd2 = da.AbstractPartitionDiagram(pd, [[1,2],[-1,-2]])
sage: pd1 == pd2
True
sage: pd1 == [[1,2],[-1,-2]]
True
sage: pd1 == ((-2,-1),(2,1))
True
sage: pd1 == SetPartition([[1,2],[-1,-2]])
True
sage: pd3 = da.AbstractPartitionDiagram(pd, [[1,-2],[-1,2]])
sage: pd1 == pd3
False
"""
try:
return self._base_diagram == other._base_diagram
except AttributeError:
pass
try:
other2 = self.parent(other)
return self._base_diagram == other2._base_diagram
except (TypeError, ValueError, AttributeError):
return False
def __ne__(self, other):
"""
Check not equals.
TESTS::
sage: import sage.combinat.diagram_algebras as da
sage: pd = da.AbstractPartitionDiagrams(da.partition_diagrams, 2)
sage: pd1 = da.AbstractPartitionDiagram(pd, [[1,2],[-1,-2]])
sage: pd2 = da.AbstractPartitionDiagram(pd, [[1,-2],[-1,2]])
sage: pd1 != pd2
True
sage: pd1 != ((-2,-1),(2,1))
False
"""
return not self == other
def base_diagram(self):
r"""
Return the underlying implementation of the diagram.
OUPUT:
- tuple of tuples of integers
EXAMPLES::
sage: import sage.combinat.diagram_algebras as da
sage: pd = da.AbstractPartitionDiagrams(da.partition_diagrams, 2)
sage: pd([[1,2],[-1,-2]]).base_diagram() == ((-2,-1),(1,2))
True
"""
return self._base_diagram # note, this works because self._base_diagram is immutable
diagram = base_diagram
def compose(self, other):
r"""
Compose ``self`` with ``other``.
The composition of two diagrams `X` and `Y` is given by placing
`X` on top of `Y` and removing all loops.
OUTPUT:
A tuple where the first entry is the composite diagram and the
second entry is how many loop were removed.
.. NOTE::
This is not really meant to be called directly, but it works
to call it this way if desired.
EXAMPLES::
sage: import sage.combinat.diagram_algebras as da
sage: pd = da.AbstractPartitionDiagrams(da.partition_diagrams, 2)
sage: pd([[1,2],[-1,-2]]).compose(pd([[1,2],[-1,-2]]))
({{-2, -1}, {1, 2}}, 1)
"""
(composite_diagram, loops_removed) = set_partition_composition(self._base_diagram, other._base_diagram)
return (self.__class__(self.parent(), composite_diagram), loops_removed)
def propagating_number(self):
r"""
Return the propagating number of the diagram.
The propagating number is the number of blocks with both a
positive and negative number.
EXAMPLES::
sage: import sage.combinat.diagram_algebras as da
sage: pd = da.AbstractPartitionDiagrams(da.partition_diagrams, 2)
sage: d1 = pd([[1,-2],[2,-1]])
sage: d1.propagating_number()
2
sage: d2 = pd([[1,2],[-2,-1]])
sage: d2.propagating_number()
0
"""
return ZZ(sum(1 for part in self._base_diagram if min(part) < 0 and max(part) > 0))
def count_blocks_of_size(self, n):
r"""
Count the number of blocks of a given size.
INPUT:
- ``n`` -- a positive integer
EXAMPLES::
sage: from sage.combinat.diagram_algebras import PartitionDiagram
sage: pd = PartitionDiagram([[1,-3,-5],[2,4],[3,-1,-2],[5],[-4]])
sage: pd.count_blocks_of_size(1)
2
sage: pd.count_blocks_of_size(2)
1
sage: pd.count_blocks_of_size(3)
2
"""
return sum(ZZ(len(block)==n) for block in self)
def order(self):
r"""
Return the maximum entry in the diagram element.
A diagram element will be a partition of the set
`\{-1, -2, \ldots, -k, 1, 2, \ldots, k\}`. The order of
the diagram element is the value `k`.
EXAMPLES::
sage: from sage.combinat.diagram_algebras import PartitionDiagram
sage: PartitionDiagram([[1,-1],[2,-2,-3],[3]]).order()
3
sage: PartitionDiagram([[1,-1]]).order()
1
sage: PartitionDiagram([[1,-3,-5],[2,4],[3,-1,-2],[5],[-4]]).order()
5
"""
return self._order
#@staticmethood
#def from_permutation(perm):
# return self
def is_planar(self):
r"""
Test if the diagram ``self`` is planar.
A diagram element is planar if the graph of the nodes is planar.
EXAMPLES::
sage: from sage.combinat.diagram_algebras import BrauerDiagram
sage: BrauerDiagram([[1,-2],[2,-1]]).is_planar()
False
sage: BrauerDiagram([[1,-1],[2,-2]]).is_planar()
True
"""
return is_planar(self)
class IdealDiagram(AbstractPartitionDiagram):
r"""
The element class for a ideal diagram.
A partition diagram for an integer `k` is a partition of the set
`\{1, \ldots, k, -1, \ldots, -k\}` and the propagating number is
strictly smaller than the order.
EXAMPLES::
sage: from sage.combinat.diagram_algebras import IdealDiagrams
sage: IdealDiagrams(2)
Ideal diagrams of order 2
sage: IdealDiagrams(2).list()
[{{-2, -1, 1, 2}},
{{-2, -1, 2}, {1}},
{{-2, -1, 1}, {2}},
{{-2}, {-1, 1, 2}},
{{-2, 1, 2}, {-1}},
{{-2, -1}, {1, 2}},
{{-2, -1}, {1}, {2}},
{{-2}, {-1, 2}, {1}},
{{-2, 2}, {-1}, {1}},
{{-2}, {-1, 1}, {2}},
{{-2, 1}, {-1}, {2}},
{{-2}, {-1}, {1, 2}},
{{-2}, {-1}, {1}, {2}}]
"""
@staticmethod
def __classcall_private__(cls, diag):
"""
Normalize input to initialize diagram.
The order of the diagram element is the maximum value found in
the list of lists.
EXAMPLES::
sage: from sage.combinat.diagram_algebras import IdealDiagram
sage: IdealDiagram([[1],[-1]])
{{-1}, {1}}
sage: IdealDiagram([[1], [-1]]).parent()
Ideal diagrams of order 1
"""
order = max([v for p in diag for v in p])
acls = IdealDiagrams(order)
d = (tuple(sorted(p)) for p in diag)
return acls(d)
def check(self):
r"""
Check the validity of the input for ``self``.
TESTS::
sage: from sage.combinat.diagram_algebras import IdealDiagram
sage: pd1 = IdealDiagram([[1,2],[-1,-2]]) # indirect doctest
sage: pd2 = IdealDiagram([[1,-2],[2,-1]]) # indirect doctest
Traceback (most recent call last):
...
ValueError: the diagram must have a propagating number smaller than the order
sage: pd3 = IdealDiagram([[1,2,-1,-3]]) # indirect doctest
Traceback (most recent call last):
...
ValueError: {{-3, -1, 1, 2}} does not represent two rows of vertices
sage: pd4 = IdealDiagram([[1,-2,-1],[2]]) # indirect doctest
"""
super(IdealDiagram, self).check()
if self.propagating_number()>=self.order():
raise ValueError("the diagram must have a propagating number smaller than the order")
class PlanarDiagram(AbstractPartitionDiagram):
r"""
The element class for a planar diagram.
A partition diagram for an integer `k` is a partition of the set
`\{1, \ldots, k, -1, \ldots, -k\}`, the diagram is non-crossing
EXAMPLES::
sage: from sage.combinat.diagram_algebras import PlanarDiagrams
sage: PlanarDiagrams(2)
Planar diagrams of order 2
sage: PlanarDiagrams(2).list()
[{{-2, -1, 1, 2}},
{{-2, -1, 2}, {1}},
{{-2, -1, 1}, {2}},
{{-2}, {-1, 1, 2}},
{{-2, 1, 2}, {-1}},
{{-2, 2}, {-1, 1}},
{{-2, -1}, {1, 2}},
{{-2, -1}, {1}, {2}},
{{-2}, {-1, 2}, {1}},
{{-2, 2}, {-1}, {1}},
{{-2}, {-1, 1}, {2}},
{{-2, 1}, {-1}, {2}},
{{-2}, {-1}, {1, 2}},
{{-2}, {-1}, {1}, {2}}]
"""
@staticmethod
def __classcall_private__(cls, diag):
"""
Normalize input to initialize diagram.
The order of the diagram element is the maximum value found in
the list of lists.
EXAMPLES::
sage: from sage.combinat.diagram_algebras import PlanarDiagram
sage: PlanarDiagram([[1,-1]])
{{-1, 1}}
sage: PlanarDiagram([[1, -1]]).parent()
Planar diagrams of order 1
"""
order = max([v for p in diag for v in p])
acls = PlanarDiagrams(order)
d = (tuple(sorted(p)) for p in diag)
return acls(d)
def check(self):
r"""
Check the validity of the input for ``self``.
TESTS::
sage: from sage.combinat.diagram_algebras import PlanarDiagram
sage: pd1 = PlanarDiagram([[1,2],[-1,-2]]) # indirect doctest
sage: pd2 = PlanarDiagram([[1,-2],[2,-1]]) # indirect doctest
Traceback (most recent call last):
...
ValueError: the diagram {{-2, 1}, {-1, 2}} must be planar
sage: pd3 = PlanarDiagram([[1,2,-1,-3]]) # indirect doctest
Traceback (most recent call last):
...
ValueError: {{-3, -1, 1, 2}} does not represent two rows of vertices
sage: pd4 = PlanarDiagram([[1,-2,-1],[2]]) # indirect doctest
"""
super(PlanarDiagram, self).check()
if not self.is_planar():
raise ValueError("the diagram %s must be planar"%(self))
class TemperleyLiebDiagram(AbstractPartitionDiagram):
r"""
The element class for a Temperley-Lieb diagram.
A partition diagram for an integer `k` is a partition of the set
`\{1, \ldots, k, -1, \ldots, -k\}`, the blocks are all of size
2 and the diagram is planar.
EXAMPLES::
sage: from sage.combinat.diagram_algebras import TemperleyLiebDiagrams
sage: TemperleyLiebDiagrams(2)
Temperley Lieb diagrams of order 2
sage: TemperleyLiebDiagrams(2).list()
[{{-2, 2}, {-1, 1}}, {{-2, -1}, {1, 2}}]
"""
@staticmethod
def __classcall_private__(cls, diag):
"""
Normalize input to initialize diagram.
The order of the diagram element is the maximum value found in
the list of lists.
EXAMPLES::
sage: from sage.combinat.diagram_algebras import TemperleyLiebDiagram
sage: TemperleyLiebDiagram([[1,-1]])
{{-1, 1}}
sage: TemperleyLiebDiagram([[1, -1]]).parent()
Temperley Lieb diagrams of order 1
"""
order = max([v for p in diag for v in p])
acls = TemperleyLiebDiagrams(order)
d = (tuple(sorted(p)) for p in diag)
return acls(d)
def check(self):
r"""
Check the validity of the input for ``self``.
TESTS::
sage: from sage.combinat.diagram_algebras import TemperleyLiebDiagram
sage: pd1 = TemperleyLiebDiagram([[1,2],[-1,-2]]) # indirect doctest
sage: pd2 = TemperleyLiebDiagram([[1,-2],[2,-1]]) # indirect doctest
Traceback (most recent call last):
...
ValueError: the diagram {{-2, 1}, {-1, 2}} must be planar
sage: pd3 = TemperleyLiebDiagram([[1,2,-1,-3]]) # indirect doctest
Traceback (most recent call last):
...
ValueError: {{-3, -1, 1, 2}} does not represent two rows of vertices
sage: pd4 = TemperleyLiebDiagram([[1,-2,-1],[2]]) # indirect doctest
Traceback (most recent call last):
...
ValueError: all blocks of {{-2, -1, 1}, {2}} must be of size 2
"""
super(TemperleyLiebDiagram, self).check()
if any(len(block) != 2 for block in self):
raise ValueError("all blocks of %s must be of size 2"%(self))
if not self.is_planar():
raise ValueError("the diagram %s must be planar"%(self))
class PartitionDiagram(AbstractPartitionDiagram):
r"""
The element class for a partition diagram.
A partition diagram for an integer `k` is a partition of the set
`\{1, \ldots, k, -1, \ldots, -k\}`
EXAMPLES::
sage: from sage.combinat.diagram_algebras import PartitionDiagram, PartitionDiagrams
sage: PartitionDiagrams(1)
Partition diagrams of order 1
sage: PartitionDiagrams(1).list()
[{{-1, 1}}, {{-1}, {1}}]
sage: PartitionDiagram([[1,-1]])
{{-1, 1}}
sage: PartitionDiagram(((1,-2),(2,-1))).parent()
Partition diagrams of order 2
"""
@staticmethod
def __classcall_private__(cls, diag):
"""
Normalize input to initialize diagram.
The order of the diagram element is the maximum value found in
the list of lists.
EXAMPLES::
sage: from sage.combinat.diagram_algebras import PartitionDiagram
sage: PartitionDiagram([[1],[-1]])
{{-1}, {1}}
sage: PartitionDiagram([[1],[-1]]).parent()
Partition diagrams of order 1
"""
order = max([v for p in diag for v in p])
acls = PartitionDiagrams(order)
d = (tuple(sorted(p)) for p in diag)
return acls(d)
class BrauerDiagram(AbstractPartitionDiagram):
r"""
A Brauer diagram.
A Brauer diagram for an integer `k` is a partition of the set
`\{1, \ldots, k, -1, \ldots, -k\}` with block size 2.
EXAMPLES::
sage: import sage.combinat.diagram_algebras as da
sage: bd = da.BrauerDiagrams(2)
sage: bd1 = bd([[1,2],[-1,-2]])
sage: bd2 = bd([[1,2,-1,-2]])
Traceback (most recent call last):
...
ValueError: all blocks of {{-2, -1, 1, 2}} must be of size 2
"""
@staticmethod
def __classcall_private__(cls, arg1, arg2=None):
"""
Normalize input to initialize diagram.
The input format should either be either that ``arg1`` is a
parent class and ``arg2`` is a diagram element (represented as a
list of lists of integers) or that ``arg1`` is a
list of lists. In the case that ``arg1`` is just the list of lists
we choose the order of the diagram element to be the maximum value
in those lists and the parent will be ``BrauerDiagrams(order)``.
EXAMPLES::
sage: from sage.combinat.diagram_algebras import BrauerDiagram, BrauerDiagrams
sage: BrauerDiagram([[1,-1]])
{{-1, 1}}
sage: BrauerDiagram([[1,-1]]).parent()
Brauer diagrams of order 1
sage: BrauerDiagram(BrauerDiagrams(1), [[1,-1]])
{{-1, 1}}
sage: BrauerDiagram(BrauerDiagrams(2), [[1,-1]]).parent()
Brauer diagrams of order 2
"""
if arg2 is None:
order = max([v for p in arg1 for v in p])
acls = BrauerDiagrams(order)
arg2 = arg1
else:
acls = arg1
d = (tuple(sorted(p)) for p in arg2)
return acls(d)
def __init__(self, parent, d):
r"""
Initialize ``self``.
sage: import sage.combinat.diagram_algebras as da
sage: bd = da.BrauerDiagrams(2)
sage: bd1 = da.BrauerDiagram(bd, ((-2,-1),(1,2)) )
"""
super(BrauerDiagram, self).__init__(parent,d)
def check(self):
r"""
Check the validity of the input for ``self``.
TESTS::
sage: import sage.combinat.diagram_algebras as da
sage: bd = da.BrauerDiagrams(2)
sage: bd1 = bd([[1,2],[-1,-2]]) # indirect doctest
sage: bd2 = bd([[1,2,-1,-2]]) # indirect doctest
Traceback (most recent call last):
...
ValueError: all blocks of {{-2, -1, 1, 2}} must be of size 2
"""
super(BrauerDiagram, self).check()
if any(len(i) != 2 for i in self):
raise ValueError("all blocks of %s must be of size 2"%(self))
def _repr_(self):
r"""
Return a string representation of a Brauer diagram.
TESTS::
sage: import sage.combinat.diagram_algebras as da
sage: bd = da.BrauerDiagrams(2)
sage: bd1 = bd([[1,2],[-1,-2]]); bd1
{{-2, -1}, {1, 2}}
"""
return self.parent().options._dispatch(self, '_repr_', 'display')
# add options to class
class options(GlobalOptions):
r"""
Set and display the global options for Brauer diagram (algebras). If no
parameters are set, then the function returns a copy of the options
dictionary.
The ``options`` to diagram algebras can be accessed as the method
:obj:`BrauerAlgebra.options` of :class:`BrauerAlgebra` and
related classes.
@OPTIONS@
EXAMPLES::
sage: R.<q> = QQ[]
sage: BA = BrauerAlgebra(2, q)
sage: E = BA([[1,2],[-1,-2]])
sage: E
B{{-2, -1}, {1, 2}}
sage: BrauerAlgebra.options.display="compact" # known bug (Trac #24323)
sage: E # known bug (Trac #24323)
B[12/12;]
sage: BrauerAlgebra.options._reset() # known bug (Trac #24323)
"""
NAME = 'Brauer diagram'
module = 'sage.combinat.diagram_algebras'
option_class='BrauerDiagram'
display = dict(default="normal",
description='Specifies how the Brauer diagrams should be printed',
values=dict(normal="Using the normal representation",
compact="Using the compact representation"),
case_sensitive=False)
def _repr_normal(self):
"""
Return a string representation of ``self``.
EXAMPLES::
sage: import sage.combinat.diagram_algebras as da
sage: bd = da.BrauerDiagrams(2)
sage: bd([[1,2],[-1,-2]])._repr_normal()
'{{-2, -1}, {1, 2}}'
"""
return super(BrauerDiagram, self)._repr_()
def _repr_compact(self):
"""
Return a compact string representation of ``self``.
EXAMPLES::
sage: import sage.combinat.diagram_algebras as da
sage: bd = da.BrauerDiagrams(2)
sage: bd([[1,2],[-1,-2]])._repr_compact()
'[12/12;]'
sage: bd([[1,-2],[2,-1]])._repr_compact()
'[/;21]'
"""
(top, bot, thru) = self.involution_permutation_triple()
bot.reverse()
s1 = ".".join("".join(str(b) for b in block) for block in top)
s2 = ".".join("".join(str(abs(k)) for k in sorted(block,reverse=True))
for block in bot)
s3 = "".join(str(x) for x in thru)
return "[{}/{};{}]".format(s1,s2,s3)
def involution_permutation_triple(self, curt=True):
r"""
Return the involution permutation triple of ``self``.
From Graham-Lehrer (see :class:`BrauerDiagrams`), a Brauer diagram
is a triple `(D_1, D_2, \pi)`, where:
- `D_1` is a partition of the top nodes;
- `D_2` is a partition of the bottom nodes;
- `\pi` is the induced permutation on the free nodes.
INPUT:
- ``curt`` -- (default: ``True``) if ``True``, then return bijection
on free nodes as a one-line notation (standardized to look like a
permutation), else, return the honest mapping, a list of pairs
`(i, -j)` describing the bijection on free nodes
EXAMPLES::
sage: import sage.combinat.diagram_algebras as da
sage: bd = da.BrauerDiagrams(3)
sage: elm = bd([[1,2],[-2,-3],[3,-1]])
sage: elm.involution_permutation_triple()
([(1, 2)], [(-3, -2)], [1])
sage: elm.involution_permutation_triple(curt=False)
([(1, 2)], [(-3, -2)], [[3, -1]])
"""
diagram = self.diagram()
top = []
bottom = []
for v in diagram:
if min(v)>0:
top+=[v]
if max(v)<0:
bottom+=[v]
if curt:
perm = self.perm()
else:
perm = self.bijection_on_free_nodes()
return (top,bottom,perm)
def bijection_on_free_nodes(self, two_line=False):
r"""
Return the induced bijection - as a list of `(x,f(x))` values -
from the free nodes on the top at the Brauer diagram to the free
nodes at the bottom of ``self``.
OUTPUT:
If ``two_line`` is ``True``, then the output is the induced
bijection as a two-row list ``(inputs, outputs)``.
EXAMPLES::
sage: import sage.combinat.diagram_algebras as da
sage: bd = da.BrauerDiagrams(3)
sage: elm = bd([[1,2],[-2,-3],[3,-1]])
sage: elm.bijection_on_free_nodes()
[[3, -1]]
sage: elm2 = bd([[1,-2],[2,-3],[3,-1]])
sage: elm2.bijection_on_free_nodes(two_line=True)
[[1, 2, 3], [-2, -3, -1]]
"""
terms = sorted(sorted(list(v), reverse=True) for v in self.diagram()
if max(v) > 0 and min(v) < 0)
if two_line:
terms = [[t[i] for t in terms] for i in range(2)]
return terms
def perm(self):
r"""
Return the induced bijection on the free nodes of ``self`` in
one-line notation, re-indexed and treated as a permutation.
.. SEEALSO::
:meth:`bijection_on_free_nodes`
EXAMPLES::
sage: import sage.combinat.diagram_algebras as da
sage: bd = da.BrauerDiagrams(3)
sage: elm = bd([[1,2],[-2,-3],[3,-1]])
sage: elm.perm()
[1]
"""
long_form = self.bijection_on_free_nodes()
if not long_form:
return long_form
short_form = [abs(v[1]) for v in long_form]
# given any list [i1,i2,...,ir] with distinct positive integer entries,
# return naturally associated permutation of [r].
# probably already defined somewhere in Permutations/Compositions/list/etc.
std = list(range(1, len(short_form) + 1))
j = 0
for i in range(max(short_form)+1):
if i in short_form:
j += 1
std[short_form.index(i)] = j
return std
def is_elementary_symmetric(self):
r"""
Check if is elementary symmetric.
Let `(D_1, D_2, \pi)` be the Graham-Lehrer representation
of the Brauer diagram `d`. We say `d` is *elementary symmetric*
if `D_1 = D_2` and `\pi` is the identity.
.. TODO:: Come up with a better name?
EXAMPLES::
sage: import sage.combinat.diagram_algebras as da
sage: bd = da.BrauerDiagrams(3)
sage: elm = bd([[1,2],[-1,-2],[3,-3]])
sage: elm.is_elementary_symmetric()
True
sage: elm2 = bd([[1,2],[-1,-3],[3,-2]])
sage: elm2.is_elementary_symmetric()
False
"""
(D1,D2,pi) = self.involution_permutation_triple()
D1 = sorted(sorted(abs(y) for y in x) for x in D1)
D2 = sorted(sorted(abs(y) for y in x) for x in D2)
return D1 == D2 and pi == list(range(1,len(pi)+1))
class AbstractPartitionDiagrams(Parent, UniqueRepresentation):
r"""
This is a class for subclasses of partition diagrams.
Thee primary use of this class is to serve as basis keys for
diagram algebras, but diagrams also have properties in their
own right. Furthermore, this class is meant to be extended to
create more efficient contains methods.
INPUT:
- ``name`` -- the name of the type of partition diagram
- ``order`` -- integer or integer `+ 1/2`; the order of the diagrams
EXAMPLES::
sage: import sage.combinat.diagram_algebras as da
sage: pd = da.PartitionDiagrams(2)
sage: pd
Partition diagrams of order 2
sage: [i for i in pd]
[{{-2, -1, 1, 2}},
{{-2, -1, 2}, {1}},
{{-2, -1, 1}, {2}},
{{-2}, {-1, 1, 2}},
{{-2, 1, 2}, {-1}},
{{-2, 1}, {-1, 2}},
{{-2, 2}, {-1, 1}},