-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKLRAlgebra.py
1804 lines (1450 loc) · 58.2 KB
/
KLRAlgebra.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
import sage
from sage.rings.ring import Algebra
from sage.structure.unique_representation import UniqueRepresentation
from sage.structure.parent import Parent
#from sage.structure.element import AlgebraElement
from sage.combinat.free_module import CombinatorialFreeModule
from sage.misc.bindable_class import BindableClass
from sage.combinat.integer_vector import IntegerVectors_k
from sage.categories.realizations import Category_realization_of_parent
from sage.categories.graded_algebras import GradedAlgebras
from sage.misc.cachefunc import cached_method
#I am putting a superfluous comment here
class BasisElement(CombinatorialFreeModule.Element):
r"""
Generic basis element. Only things we do here are define some printing methods.
"""
def __init__(self, *args, **kwds):
r"""
Initialize self.
"""
CombinatorialFreeModule.Element.__init__(self, *args, **kwds)
P = self.parent().realization_of()
self._n = P.positive_root().height()
self.rename(self._get_print_name())
def _get_print_name(self):
r"""
Return a string which represents self.
This cannot be implemented at this level of generality.
"""
raise NotImplementedError('This should be implemented by subclasses')
def tikz(self, x_sep=0.5, y_sep=0.3):
r"""
Return tikz code to which draws a picture of this element.
INPUT:
- `x_sep` -- float; the distance between strands
- `y_sep` -- float; the vertical distance between crossings
OUTPUT: The tikz code which generates a picture of this element
NOTE:
Requires the following in your preamble:
`\usepackage{tikz}`
`\usetikzlibrary{positioning}`
Asks subclass for tikzmonomials (basis elements), receives them and lines them up with '+' in between them
"""
the_string = ""
mcs = self.monomial_coefficients()
first_term=True
min_height = Infinity
for monomial in mcs:
my_mon = self.parent().monomial(monomial)
rw = my_mon._get_reduced_word()
iv = my_mon.get_integer_vector()
l = len(rw)
max_dots = max(iv)
dot_space = ceil((max_dots+2)/3.0)*y_sep
this_height = (y_sep*(l+2)+dot_space)/2
if this_height < min_height:
min_height = this_height
the_terms = []
for monomial in mcs:
the_terms += ["\n"+self.parent().monomial(monomial)._tikz_monomial(x_sep=x_sep, y_sep=y_sep, coeff=mcs[monomial], first_term=first_term, coeff_height=min_height)]
first_term=False
for term in the_terms:
the_string += term
return the_string[1:]
class XTElement(BasisElement):
'''
An element of the basis of a KLR algebra which has dots at the top of diagrams
and crossings at the bottom
'''
#Correct order
def _get_print_name(self):
'''
'''
mcs = self.monomial_coefficients()
if len(mcs) != 0:
new_name = ""
for item in mcs.keys():
X = ""
for i in range(1, self._n+1):
if item[0][i-1] == 1:
X += "x_{%s}"%i
elif item[0][i-1] != 0:
X += "x_{%s}^{%s}"%(i, item[0][i-1])
if item[1].is_one():
T = ""
else:
T = "t_{%s}"%item[1]
E = "e_{%s}"%item[2]
coeff = mcs[item]
if coeff == 1:
new_name += "%s%s%s + "%(X,T,E)
else:
new_name += "%s*%s%s%s + "%(coeff,X,T,E)
new_name = new_name[:-3]
return new_name
return "0"
#TODO: Fix coefficient height
def _tikz_monomial(self, x_sep=0.5, y_sep=0.3, coeff=1, first_term=True, coeff_height=None):
rw = self._get_reduced_word()[::-1]
iv = self.get_integer_vector()
perm = self.get_permutation()
n = self._n
l = len(rw)
max_dots = max(iv)
if max_dots == 0:
dot_space = 0
else:
dot_space = ceil((max_dots+2)/3.0)*y_sep
if coeff_height == None:
coeff_height = (y_sep*(l+2)+dot_space)/2
front_matter = "\\begin{tikzpicture}\n\t\\foreach \\x in {1, ..., %s}\n\t\t\\node (\\x_-1) at (%s*\\x, %s){};\n\t\\foreach \\x in {1, ..., %s}\n\t\t\\foreach \\y in {0, ..., %s}\n\t\t\t\\node (\\x_\\y) at (%s*\\x, %s*\\y){};\n"%(n, x_sep, y_sep*(l+2)+dot_space, n, l+2, x_sep, y_sep)
if coeff == 1:
coeff = ""
else:
coeff = "\\,\\,\\left(%s\\right)\\,\\,"%latex(coeff)
if first_term:
end_matter = "\t\\node[on grid, below=%s of 1_-1] (temp) {};\n\t\\node[left=0 of temp]{$%s$};\n\\end{tikzpicture}"%(coeff_height, coeff)
else:
end_matter = "\t\\node[on grid, below=%s of 1_-1] (temp) {};\n\t\\node[left=0 of temp]{$+%s$};\n\\end{tikzpicture}"%(coeff_height, coeff)
simple_roots = self.parent().realization_of().root_system().root_lattice().simple_roots()
color_list = rainbow(len(set(perm)))
colors = {list(set(perm))[i]:color_list[i] for i in range(len(list(set(perm))))}
color_string = ""
for i in colors:
color_string += "\t\\definecolor{color%s}{HTML}{%s}\n"%(i, colors[i][1:].upper())
strands = {i:"\t\\draw [color=color%s] (%s_0.center)--(%s_1.center)"%(perm[i-1], i, i) for i in range(1,n+1)}
for i in range(l):
strands[rw[i]], strands[rw[i]+1] = (strands[rw[i]+1]+"--(%s_%s.center)"%(rw[i], i+2), strands[rw[i]]+"--(%s_%s.center)"%(rw[i]+1, i+2))
for j in range(1, n+1):
if j != rw[i] and j != rw[i]+1:
strands[j] += "--(%s_%s.center)"%(j, i+2)
for j in range(1, n+1):
strands[j] += "--(%s_%s.center)--(%s_-1.center);\n"%(j, l+2, j)
dots = {i:"\t\\foreach \\y in {1, ..., %s}\n\t\t\\node[on grid, circle, fill, inner sep=1pt, below=%s/%s*\\y of %s_-1]{};\n"%(iv[i-1], dot_space, iv[i-1]+1, i) for i in range(1, n+1)}
the_string = front_matter+color_string
for i in strands:
the_string += strands[i]
for i in dots:
if iv[i-1] != 0:
the_string += dots[i]
the_string += end_matter
return the_string
class TXElement(BasisElement):
'''
An element of the basis of a KLR algebra which has crossings at the top of
diagrams and dots at the bottom
'''
#Correct Order
def _get_print_name(self):
mcs = self.monomial_coefficients()
if len(mcs) != 0:
new_name = ""
for item in mcs.keys():
X = ""
for i in range(1, self._n+1):
if item[0][i-1] == 1:
X += "x_{%s}"%i
elif item[0][i-1] != 0:
X += "x_{%s}^{%s}"%(i, item[0][i-1])
if item[1].is_one():
T = ""
else:
T = "t_{%s}"%item[1]
E = "e_{%s}"%item[2]
coeff = mcs[item]
if coeff == 1:
new_name += "%s%s%s + "%(T,X,E)
else:
new_name += "%s*%s%s%s + "%(coeff,T,X,E)
new_name = new_name[:-3]
return new_name
else:
return "0"
#Correct Order
def _tikz_monomial(self, x_sep=0.5, y_sep=0.3, coeff=1, first_term=True, coeff_height=None):
rw = self._get_reduced_word()[::-1]
iv = self.get_integer_vector()
perm = self.get_permutation()
n = self._n
l = len(rw)
max_dots = max(iv)
if max_dots == 0:
dot_space = 0
else:
dot_space = ceil((max_dots+2)/3.0)*y_sep
if coeff_height == None:
coeff_height = (y_sep*(l+2)+dot_space)/2
front_matter = "\\begin{tikzpicture}\n\t\\foreach \\x in {1, ..., %s}\n\t\t\\node (\\x_-1) at (%s*\\x, %s){};\n\t\\foreach \\x in {1, ..., %s}\n\t\t\\foreach \\y in {0, ..., %s}\n\t\t\t\\node (\\x_\\y) at (%s*\\x, %s*\\y){};\n"%(n, x_sep, -dot_space, n, l+2, x_sep, y_sep)
if coeff == 1:
coeff = ""
else:
coeff = "\\,\\,\\left(%s\\right)\\,\\,"%latex(coeff)
if first_term:
end_matter = "\t\\node[on grid, above=%s of 1_-1] (temp) {};\n\t\\node[left=0 of temp]{$%s$};\n\\end{tikzpicture}"%(coeff_height, coeff)
else:
end_matter = "\t\\node[on grid, above=%s of 1_-1] (temp) {};\n\t\\node[left=0 of temp]{$+%s$};\n\\end{tikzpicture}"%(coeff_height, coeff)
simple_roots = self.parent().realization_of().root_system().root_lattice().simple_roots()
color_list = rainbow(len(set(perm)))
colors = {list(set(perm))[i]:color_list[i] for i in range(len(list(set(perm))))}
color_string = ""
for i in colors:
color_string += "\t\\definecolor{color%s}{HTML}{%s}\n"%(i, colors[i][1:].upper())
strands = {i:"\t\\draw [color=color%s] (%s_-1.center)--(%s_0.center)--(%s_1.center)"%(perm[i-1], i, i, i) for i in range(1,n+1)}
for i in range(l):
strands[rw[i]], strands[rw[i]+1] = (strands[rw[i]+1]+"--(%s_%s.center)"%(rw[i], i+2), strands[rw[i]]+"--(%s_%s.center)"%(rw[i]+1, i+2))
for j in range(1, n+1):
if j != rw[i] and j != rw[i]+1:
strands[j] += "--(%s_%s.center)"%(j, i+2)
for j in range(1, n+1):
strands[j] += "--(%s_%s.center);\n"%(j, l+2)
dots = {i:"\t\\foreach \\y in {1, ..., %s}\n\t\t\\node[on grid, circle, fill, inner sep=1pt, above=%s/%s*\\y of %s_-1]{};\n"%(iv[i-1], dot_space, iv[i-1]+1, i) for i in range(1, n+1)}
the_string = front_matter+color_string
for i in strands:
the_string += strands[i]
for i in dots:
if iv[i-1] != 0:
the_string += dots[i]
the_string += end_matter
return the_string
class KLRAlgebra(UniqueRepresentation, Parent):
def __init__(self, base_ring, positive_root, signs=None, *args, **kwargs):
'''
base_ring is the ring over which to define this KLR algebra
positive_root is an element of the positive root lattice of some root
system. It knows which root system it came from.
signs is a function which takes as input two integers i and j, and
outputs either plus 1 or minus 1. Real people almost never need to
specify a non-default function.
there's a mysterious _custom_signs instance variable
'''
category = GradedAlgebras(base_ring)
self._base = base_ring
Parent.__init__(self, category=category.WithRealizations())
self._R = base_ring
self._root_system = positive_root.parent().root_system
# Get the cartan matrix. If we are not of finite type, this won't work so I have
# to make a lazy family. The only supported infinite type is ["A", ZZ] right now.
# To add support for other infinite types, one needs only to define the proper
# function giving the appropriate entry in the infinite-dimensional cartan matrix
# for that infinite-type. Should also implement "symmetric_form" below......
try:
self._cartan_matrix = self._root_system.cartan_matrix()
except AttributeError as e:
if self._root_system.cartan_type() == CartanType(["A", ZZ]):
self._cartan_matrix = Family(ZZ, lambda i: Family(ZZ, lambda j: 2*kronecker_delta(i, j) - kronecker_delta(i-1, j) - kronecker_delta(i, j-1)))
else:
raise e
self._positive_root = positive_root
# I forget where I need to use the _custom_signs instance variable
if signs == None:
self._custom_signs = False
self._signs = lambda i, j: sign(j-i) #sign is a built-in sage function
else:
self._custom_signs = True
self._signs = signs
XT = KLRAlgebra.XT(self)
TX = KLRAlgebra.TX(self)
my_category = self.GradedBases()
TX_to_XT = TX.module_morphism(XT._TX_to_XT_on_basis, category=my_category, codomain=XT)
XT_to_TX = XT.module_morphism(TX._XT_to_TX_on_basis, category=my_category, codomain=TX)
TX_to_XT.register_as_coercion()
XT_to_TX.register_as_coercion()
# PLAYING AROUND WITH PRINTING STUFF.........
# defaults = ('dot_symbol':'x', 'crossing_symbol':'t', 'strand_symbol':'e')
# for arg in kwargs:
# if arg not in defaults:
# raise ValueError('%s is not a valid print option'%arg)
# self._print_options = {key:kwargs.get(key, defaults[key]) for key in defaults}
#
# for realization in self.realizations():
def _repr_(self):
r"""
Return the string representation of self.
"""
name = "KLR Algebra over %s for %s with positive root %s"%(repr(self._R), repr(self._root_system), repr(self._positive_root))
if self._custom_signs:
name += " with custom sign conventions"
return name
def change_ring(self, ring=None):
r"""
Return the KLR algebra identical to this one, over the specified ring
"""
if ring == None:
ring = self.base_ring()
if self._custom_signs:
signs = self._signs
else:
signs = None
return KLRAlgebra(ring, self._positive_root, signs=signs)
def characteristic(self):
r"""
Return the characteristic of this KLR Algebra.
"""
return self.base_ring().characteristic()
def is_finite(self):
r"""
Return whether or not this KLR algebra is finite. It isn't unless its base ring is finite and its associated positive root is zero.
"""
return self.base_ring().is_finite() and self._positive_root == 0
def root_system(self):
r"""
Return the root system associated to this KLR Algebra.
"""
return self._root_system
def cartan_matrix(self):
r"""
Return the cartan matrix of the root system associated to this KLR Algebra.
"""
return self._cartan_matrix
def positive_root(self):
r"""
Return the positive root associated to this KLR Algebra (as an element of the root lattice of the root system associated to this KLR Algebra).
"""
return self._positive_root
def signs(self, pair=None):
r"""
Return the sign associated to pair.
INPUT:
- "pair", a pair of integers (i, j) whose corresponding entry in the cartan matrix associated to this KLR Algebra is negative.
OUTPUT:
- If pair != None, return the sign (1 or -1) associated to the pair (i, j). This should always return sign((i, j)) == -sign((j, i)).
- If pair == None, return the function which yields the signs associated to pairs of integers.
"""
if pair == None:
return self._signs
return self._signs(pair[0], pair[1])
def a_realization(self):
return self.XT()
def algebra_generators(self):
return self.a_realization().algebra_generators()
monoid_generators = algebra_generators
class GradedBases(Category_realization_of_parent):
def super_categories(self):
A = self.base()
category = GradedAlgebrasWithBasis(A.base_ring())
return [A.Realizations(), category.Realizations()]
class ElementMethods:
def _get_reduced_word(self):
my_parent = self.parent()
if not self.is_monomial():
raise ValueError("%s is not a monomial"%self)
return my_parent.reduced_word(self.get_Sn_element())
def is_monomial(self):
if len(self.monomial_coefficients()) == 1:
return True
return False
# determines the idempotent e
def get_permutation(self):
if not self.is_monomial():
raise ValueError("%s is not a monomial"%self)
return self.leading_support()[2]
# determines the t
def get_Sn_element(self):
if not self.is_monomial():
raise ValueError("%s is not a monomial"%self)
return self.leading_support()[1]
# determines the X
def get_integer_vector(self):
if not self.is_monomial():
raise ValueError("%s is not a monomial"%self)
return self.leading_support()[0]
def get_first_nonzero_index(self):
v = self.get_integer_vector()
for i in range(len(v)):
if v[i] != 0:
return i
return -1
def is_x(self):
for i in range(1, self._n+1):
if self == self.parent().x(i):
return i
return False
def is_t(self):
for i in range(1, self._n):
if self == self.parent().t(i):
return i
return False
def is_e(self):
for p in self.parent()._P:
if self == self.parent().e(p):
return p
return False
def tikz(self, x_sep=0.5, y_sep=0.3):
the_string = ""
mcs = self.monomial_coefficients()
min_height = Infinity
for monomial in mcs:
my_mon = self.parent().monomial(monomial)
rw = self.parent().reduced_word(monomial[1])
iv = monomial[0]
l = len(rw)
max_dots = max(iv)
dot_space = ceil((max_dots+2)/3.0)*y_sep
this_height = (y_sep*(l+2)+dot_space)/2
if this_height < min_height:
min_height = this_height
the_terms = []
first_term=True
for monomial in mcs:
the_terms += ["\n"+self.parent().monomial(monomial)._tikz_monomial(x_sep=x_sep, y_sep=y_sep, coeff=mcs[monomial], first_term=first_term, coeff_height=min_height)]
first_term=False
for term in the_terms:
the_string += term
return the_string[1:]
def plot(self, coefficient_padding=1, **kwargs):
cp = coefficient_padding
par = self.parent()
mcs = self.monomial_coefficients()
width = par._n
heights = {mc:par.plot_on_basis(mc, height_only=True) for mc in mcs}
pieces = []
h_shift = 0
first_term = True
for mc in mcs:
if first_term:
if mcs[mc] == par.base_ring().one():
h_shift += 0
else:
coeff = text("$\\left(%s\\right)$"%latex(mcs[mc]), (h_shift, 0), color='black', **kwargs)
pieces += [coeff]
h_shift += cp
else:
if mcs[mc] == par.base_ring().one():
coeff = text("$+$", (h_shift, 0), color='black', **kwargs)
else:
coeff = text("$+\\left(%s\\right)$"%latex(mcs[mc]), (h_shift, 0), color='black', **kwargs)
pieces += [coeff]
h_shift += cp
first_term = False
pieces += [par.plot_on_basis(mc, h_shift=h_shift, v_shift=-heights[mc]/2.0, **kwargs)]
h_shift += width + cp - 1
G = sum(pieces)
G.axes(False)
G.set_aspect_ratio(1)
return G
class ParentMethods:
def _name(self):
if self._custom_words:
if self._A._custom_signs:
return str(self._A) + " and custom reduced words"
else:
return str(self._A) + " with custom reduced words"
else:
return str(self._A)
def _repr_(self):
return "%s in %s basis"%(self._name(), self._realization_name())
def reduced_word(self, g=None):
r"""
Return the distinguished reduced word for g.
INPUT:
- "g", an element of the symmetric group associated to this KLR Algebra.
OUTPUT:
- If g != None, return the distinguished reduced word of g.
- If g == None, return the function which yields the distinguished reduced words.
"""
if g == None:
return self._reduced_words
if g not in self._Sn:
raise ValueError("%s not an element of %s"%(g, self._Sn))
return self._reduced_words(self._Sn(g))
def x(self, i=None):
r"""
Return the monomial associated to i.
INPUT:
- "i", either an integer between 1 and n, or a length n integer vector.
OUTPUT:
- If i is an integer between 1 and n, returns the KLR algebra generator x_i.
- If i is a length n integer vector, returns associated product of algebra generators.
- If i == None, return a dictionary whose keys are integers 1 through n and values the associated polynomial generators of this KLR algebra.
"""
if i == None:
return {j:self.x(j) for j in range(1, self._n+1)}
if i not in range(1, self._n+1) and i not in self._IVn:
raise ValueError("%s not an integer between 1 and %s, nor an element of %s"%(i, self._n, self._IVn))
#B = self.basis()
if i in self._IVn:
v = self._IVn(i)
else:
v = self._IVn((0,)*(i-1)+(1,)+(0,)*(self._n-i))
g = self._Sn(())
return self.sum([self.monomial(self._CP((v, g, p))) for p in self._P])
def t(self, g=None):
r"""
Return the crossing associated to g.
INPUT:
- "g", either an integer between 1 and n-1, or an element of the symmetric group S_n.
OUTPUT:
- If g is an integer between 1 and n-1, returns a crossing of the gth and (g+1)th strands.
- If g is an element of S_n, returns a braid corresponding to the distinguished reduced word of g.
- If g == None, returns a dictionary whose keys are the integers between 1 and n-1, and values are the associated crossings.
"""
if g == None:
return {j:self.t(j) for j in range(1, self._n)}
if g in range(1, self._n):
g = self._Sn((g, g+1))
elif g in self._Sn:
g = self._Sn(g)
else:
raise ValueError("%s not an integer between 1 and %s, nor an element of %s"%(g, self._n-1, self._Sn))
#B = self.basis()
v = self._IVn((0,)*self._n)
return self.sum([self.monomial(self._CP((v, g, p))) for p in self._P])
def e(self, p=None):
r"""
Return the idempotent corresponding to p
INPUT:
- "p", a permutation of length n whose entries correspond to the coefficients of the positive root associated to this KLR algebra.
OUTPUT:
- If p != None, returns the idempotent corresponding to p.
- If p == None, returns a dictionary whose keys are permutations as above, and values are the corresponding idempotents.
"""
if p == None:
return {tuple(j):self.e(j) for j in self._P}
p = self._P(p)
if p not in self._P:
raise ValueError("%s not in %s"%(p, self._P))
#B = self.basis()
v = self._IVn((0,)*self._n)
g = self._Sn(())
p = self._P(p)
return self.monomial(self._CP((v, g, p)))
def longest_crossing(self):
return self.t(self.symmetric_group().long_element())
# Do I have the best way of inputting parameters? It seems clunky
# and unintuitive... Should I handle errors?
def divided_power_idempotent(self, *args):
the_is, the_ms = [arg[0] for arg in args], [arg[1] for arg in args]
my_groups = []
v = []
start = 1
for m in the_ms:
end = start + m
my_groups += [SymmetricGroup(range(start, end))]
v += range(end-start)
start = end
g = self._Sn.prod([self._Sn(G.long_element()) for G in my_groups])
p = self._P(sum([(the_is[i],)*the_ms[i] for i in range(len(the_is))], ()))
v = self._IVn(tuple(v))
return self.monomial(self._CP((v, g, p)))
def one(self):
r"""
Returns the identity element of this KLR algebra. This is the sum of all idempotents corresponding to length n permutations whose entries correspond to the coefficients of the positive root associated with this KLR algebra.
"""
g = self._Sn.one()
v = self._IVn((0,)*self._n)
return self.sum([self.monomial(self._CP((v, g, p))) for p in self._P])
def algebra_generators(self):
r"""
Returns the algebra generators. See x(), t(), e().
"""
return [self.x(i) for i in range(1, self._n+1)]+[self.t(i) for i in range(1, self._n)]+[self.e(p) for p in self._P]
def cartan_matrix(self):
return self.realization_of().cartan_matrix()
def signs(self, pair=None):
return self.realization_of().signs(pair=pair)
def symmetric_group(self):
r"""
Return the symmetric group associated to this KLR Algebra. This is the symmetric group S_n where n is the height of the positive root associated to this KLR Algebra.
"""
return self._Sn
def symmetric_form(self, left, right):
try:
return left.symmetric_form(right)
except AttributeError as e:
if self._root_system.cartan_type() == CartanType(["A", ZZ]):
mcl = left.monomial_coefficients()
mcr = right.monomial_coefficients()
return sum([mcl[i]*mcr[j]*self.cartan_matrix()[i-1][j-1] for i in mcl for j in mcr])
else:
raise e
def degree_on_basis(self, elt):
r"""
Returns the degree of the KLR algebra element associated to this basis element
"""
rw = self.reduced_word(elt[1])
iv = elt[0]
perm = elt[2]
alpha = self._A.root_system().root_lattice().basis()
sum = 0
for k in rw[::-1]:
sum -= self.symmetric_form(alpha[perm[k-1]],alpha[perm[k]])
perm = self._P(self._Sn((k, k+1))(tuple(perm)))
for k in range(1, len(iv)+1):
sum += iv[k-1]*(self.symmetric_form(alpha[perm[k-1]],alpha[perm[k-1]]))
return sum
def _g_ify(self, word):
r"""
Returns the element of S_n corresponding to word
"""
return self._Sn.prod([self._Sn((i, i+1)) for i in word])
def _add_integer_vectors(self, first, second):
r"""
Returns the point-wise sum of the two integer vectors
"""
return self._IVn((first[i]+second[i] for i in range(len(first))))
def _get_first_nonzero_index(self, v):
r"""
Returns the first index at which the integer vector "v" is non-zero, -1 if never.
"""
for i in range(len(v)):
if v[i] != 0:
return i
return -1
def _get_last_nonzero_index(self, v):
r"""
Returns the last index at which the integer vector "v" is non-zero, -1 if never.
"""
for i in range(len(v))[::-1]:
if v[i] != 0:
return i
return -1
@cached_method
def _get_move(self, word, target):
if word == target:
return ("n", 0)
assert len(word) == len(target)
# Check to see how far we match the target
i = 0
try:
while word[i] == target[i]:
i += 1
# Error is thrown if nothing matches. We don't care.
except IndexError:
pass
# If anything matches, just check the leftovers.
if i > 0:
my_move = list(self._get_move(word[i:], target[i:]))
my_move[1] += i
return tuple(my_move)
# Now the beginning doesn't match. Find where the target first crossing
# crosses in word.
temp = (target[0],) + word
j = 0
while self._g_ify(temp[:j]).length() == j:
j += 1
j -= 2
# j is now the index at which the distinguished strands cross in word.
return self._float_move(word[:j+1])
'''
give a move which floats the bottom crossing to the top
'''
@cached_method
def _float_move(self, word):
# if the two bottom crossings are far apart, just move them past
# each other for free. Do this until you can't anymore or until the crossing
# is all the way at the top.
j = len(word)-1
if j > 0 and abs(word[j] - word[j-1]) > 1:
return ('s', j-1)
# Now we can assume that the crossing of interest is as far up as possible.
# If it's at the top, then we are done with this part, just go back to
# reduce_full
# if j == 0:
# return word
# Now we can assume it got stuck on some adjacent transposition.
#print word, j
i = self._find_crossing(word)
if i == j-2:
return ('b', j-2)
my_move = list(self._sink_move(word[i:]))
my_move[1] += i
return tuple(my_move)
'''
give a move which floats the top crossing to the bottom
'''
@cached_method
def _sink_move(self, word):
my_move = list(self._float_move(word[::-1]))
if my_move[0] == "s":
my_move[1] = len(word) - 2 - my_move[1]
elif my_move[0] == "b":
my_move[1] = len(word) - 3 - my_move[1]
return tuple(my_move)
# ALMOST READY TO REWRITE THIS ACCORDING TO Reduce.py SO THE
# COMPUTATIONS WILL ACTUALLY TERMINATE!
@cached_method
def _shuffle(self, word, p):
r"""
Returns an element of this KLR algebra which is equal to the product of the generators corresponding to the reduced word "word" and the idempotent determined by p
INPUT:
- "word", a list representing a reduced word for some S_n element
- "p", a permutation corresponding to some idempotent e_p
- "Graph", the reduced word graph containing the reduced word "word"
OUTPUT:
- An element of this KLR algebra (written in the distinguished basis) which is equal to t_{s_1}t_{s_2} ... t_{s_k}e_p where word = [s_1, ..., s_k]
"""
g = self._g_ify(word)
good_word = tuple(self.reduced_word(g))
if word == good_word:
v = self._IVn((0,)*self._n)
return self.monomial(self._CP((v, g, p)))
my_move = self._get_move(word, good_word)
word = list(word)
while my_move[0] == 's':
i = my_move[1]
word[i], word[i+1] = word[i+1], word[i]
my_move = self._get_move(tuple(word), good_word)
word = tuple(word)
if my_move[0] == 'n':
v = self._IVn((0,)*self._n)
return self.monomial(self._CP((v, g, p)))
# Now there IS a next word, and the current word and next word differ by a braid relation.
# Find the index at which this braid relation occurs. i is the index along SP at which
# current_word lies.
j = my_move[1]
next_word = word[:j] + (word[j+1], word[j], word[j+1]) + word[j+3:]
# Now j is the first index at which current_word and next_word differ
# end --> j+3, word --> current_word
#OLLLLLLDDDDD
# new_p_m = self._P(self._g_ify(current_word[j+3:])(tuple(p)))
# if current_word[j+1] == current_word[j+2] + 1:
# k = current_word[j+2]
# new = self._shuffle(current_word[:j]+(current_word[j+1], current_word[j+2], current_word[j+1])+current_word[j+3:], p)
# c_ij = self.cartan_matrix()[new_p_m[k-1]-1][new_p_m[k]-1]
# if c_ij < 0 and new_p_m[k-1] == new_p_m[k+1]:
# new_g_m = self._Sn(())
# new_p_r = p
# new_p_l = new_p_m
# for r in range(-c_ij):
# new_v_m = self._IVn((0,)*(k-1) + (r,) + (0,) + (-1-c_ij-r,) + (0,)*(self._n-k-2))
# new -= self.signs(pair=(new_p_m[k-1]-1, new_p_m[k]-1)) * (self._reduce(current_word[:j], new_p_l) * self.monomial(self._CP((new_v_m, new_g_m, new_p_m))) * self._reduce(current_word[j+3:], new_p_r))
# return new
#
# if current_word[j+1] == current_word[j+2] - 1:
# k = current_word[j+1]
# new = self._shuffle(current_word[:j]+(current_word[j+1], current_word[j+2], current_word[j+1])+current_word[j+3:], p)
# c_ij = self.cartan_matrix()[new_p_m[k-1]-1][new_p_m[k]-1]
# if c_ij < 0 and new_p_m[k-1] == new_p_m[k+1]:
# new_g_m = self._Sn(())
# new_p_r = p
# new_p_l = new_p_m
# for r in range(-c_ij):
# new_v_m = self._IVn((0,)*(k-1) + (r,) + (0,) + (-1-c_ij-r,) + (0,)*(self._n-k-2))
# new += self.signs(pair=(new_p_m[k-1]-1, new_p_m[k]-1)) * (self._reduce(current_word[:j], new_p_l) * self.monomial(self._CP((new_v_m, new_g_m, new_p_m))) * self._reduce(current_word[j+3:], new_p_r))
# return new
# NEWWWWWWWWWW
new_p_m = self._P(self._g_ify(word[j+3:])(tuple(p)))
if word[j+1] == word[j+2] + 1:
k = word[j+2]
new = self._shuffle(word[:j]+(word[j+1], word[j+2], word[j+1])+word[j+3:], p)
c_ij = self.cartan_matrix()[new_p_m[k-1]-1][new_p_m[k]-1]
if c_ij < 0 and new_p_m[k-1] == new_p_m[k+1]:
new_g_m = self._Sn(())
new_p_r = p
new_p_l = new_p_m
for r in range(-c_ij):
new_v_m = self._IVn((0,)*(k-1) + (r,) + (0,) + (-1-c_ij-r,) + (0,)*(self._n-k-2))
new -= self.signs(pair=(new_p_m[k-1]-1, new_p_m[k]-1)) * (self._reduce(word[:j], new_p_l) * self.monomial(self._CP((new_v_m, new_g_m, new_p_m))) * self._reduce(word[j+3:], new_p_r))
return new
if word[j+1] == word[j+2] - 1:
k = word[j+1]
new = self._shuffle(word[:j]+(word[j+1], word[j+2], word[j+1])+word[j+3:], p)
c_ij = self.cartan_matrix()[new_p_m[k-1]-1][new_p_m[k]-1]
if c_ij < 0 and new_p_m[k-1] == new_p_m[k+1]:
new_g_m = self._Sn(())
new_p_r = p
new_p_l = new_p_m
for r in range(-c_ij):
new_v_m = self._IVn((0,)*(k-1) + (r,) + (0,) + (-1-c_ij-r,) + (0,)*(self._n-k-2))
new += self.signs(pair=(new_p_m[k-1]-1, new_p_m[k]-1)) * (self._reduce(word[:j], new_p_l) * self.monomial(self._CP((new_v_m, new_g_m, new_p_m))) * self._reduce(word[j+3:], new_p_r))
return new
@cached_method
def _reduce(self, word, p):
r"""
Returns an element of this KLR algebra which is equal to the product of the generators corresponding to "word" and the idempotent determined by "p"
INPUT:
- "word", any list containing positive integer entries between 1 and n
- "p", a permutation corresponding to some idempotent e_p
OUTPUT:
- An element of this KLR algebra (written in the distinguished basis) which is equal to t_{s_1}t_{s_2} ... t_{s_k}e_p where word = [s_1, ..., s_k]
"""
# Base case: if my word is already reduced.
# NOTE: THIS IS GOING TO GIVE A WRONG ANSWER! BECAUSE I HAVE NOT CHECKED TO SEE
# IF I HAVE THE DISTINGUISED REDUCED WORD! I'M GOING TO PUT SOME EXTRA STUFF IN!
g = self._g_ify(word)
if g.length() == len(word):
#v = self._IVn((0,)*self._n)
#return self.monomial(self._CP((v, g, p)))
#Uncomment this, and comment above for magic to happen.
return self._shuffle(word, p)
# I am looking for a minimal unreduced subword. Start at the beginning.
i = 0
# Increase the index until the subword starting at the beginning is unreduced.
while self._g_ify(word[:i+1]).length() == i+1:
i += 1
# Now go backwards...
j = i
# Decrease this second index until the subword starting at j ending at i is unreduced.
while self._g_ify(word[j:i+1]).length() == i+1-j:
j -= 1
# Another semi-base case: If my minimal unreduced subword has length 2 (and so it is a
# double-crossing), apply the appropriate relation to reduce it.
if i - j == 1:
k = word[i]
middle_p = self._P(self._g_ify(word[i+1:])(tuple(p)))
if middle_p[k-1] == middle_p[k]:
return self.zero()
if self.cartan_matrix()[middle_p[k-1]-1][middle_p[k]-1] < 0:
first_v = self._IVn((0,)*(k-1)+(-self.cartan_matrix()[middle_p[k-1]-1][middle_p[k]-1],)+(0,)*(self._n - k))
first_g = self._Sn(())
first_p = middle_p
second_v = self._IVn((0,)*k+(-self.cartan_matrix()[middle_p[k]-1][middle_p[k-1]-1],)+(0,)*(self._n - k - 1))
second_g = self._Sn(())
second_p = middle_p
first = self.monomial(self._CP((first_v, first_g, first_p)))
second = self.monomial(self._CP((second_v, second_g, second_p)))
middle = self.signs(pair=(middle_p[k-1]-1, middle_p[k]-1))*(first - second)
new_p_l = self._P(self._g_ify(word[j:])(tuple(p)))
new_p_r = p
return self._reduce(word[:j], new_p_l) * (middle * self._reduce(word[i+1:], new_p_r))
return self._reduce(word[:j]+word[i+1:], p)
# Another semi-base case: If my minimal unreduced word can be reduced by swapping
# distant transpositions, do such a swap.
if abs(word[i] - word[i-1]) > 1:
return self._reduce(word[:i-1]+(word[i], word[i-1])+word[i+1:], p)
# Now I have guaranteed that my minimal unreduced word ends in two adjacent
# transpositions, and a consequence of minimality is that the two strands which appear
# in the last two transpositions but don't cross there, DO cross somewhere else in the
# minimal unreduced word, before position 0. Straighten this piece.