-
Notifications
You must be signed in to change notification settings - Fork 5
/
uneqkl.cpp
1756 lines (1340 loc) · 43 KB
/
uneqkl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
This is uneqkl.cpp
Coxeter version 3.0 Copyright (C) 2002 Fokko du Cloux
See file main.cpp for full copyright notice
*/
#include "uneqkl.h"
#include "interactive.h"
namespace uneqkl {
using namespace interactive;
}
namespace {
using namespace uneqkl;
void muSubtraction(KLPol& p, const MuPol& mp, const KLPol& q,
const Ulong& d, const long& m);
void positivePart(KLPol& p, const KLPol& q, const Ulong& d, const long& m);
const MuPol* writeMu(BinaryTree<MuPol>& t, const KLPol& p);
};
namespace uneqkl {
struct KLContext::KLHelper {
/* data */
KLContext* d_kl;
/* constructors and destructors */
void* operator new(size_t size) {return arena().alloc(size);}
void operator delete(void* ptr)
{return arena().free(ptr,sizeof(KLHelper));}
KLHelper(KLContext* kl):d_kl(kl) {};
~KLHelper() {};
/* member functions */
void allocExtrRow(const CoxNbr& y) {klsupport().allocExtrRow(y);}
void allocKLRow(const CoxNbr& y);
void allocMuRow(const Generator& s, const CoxNbr& y);
void allocMuRow(MuRow& row, const Generator& s, const CoxNbr& y);
bool checkKLRow(const CoxNbr& y);
bool checkMuRow(const Generator& s, const CoxNbr& y);
void ensureKLRow(const CoxNbr& y);
const ExtrRow& extrList(const CoxNbr& y) {return klsupport().extrList(y);}
void fillKLRow(const CoxNbr& y, const Generator& s = undef_generator);
void fillMuRow(const Generator& s, const CoxNbr& y);
const KLPol* fillKLPol(const CoxNbr& x, const CoxNbr& y,
const Generator& s = undef_generator);
const MuPol* fillMu(const Generator& s, const CoxNbr& x, const CoxNbr& y);
const KLPol& find(const KLPol& p) {return d_kl->d_klTree.find(p)[0];}
Ulong genL(const Generator& s) {return d_kl->genL(s);}
void initWorkspace(const CoxNbr& y, List<KLPol>& pol, const Generator& s);
CoxNbr inverse(const CoxNbr& y) {return klsupport().inverse(y);}
void inverseMin(CoxNbr& y, Generator& s);
bool isExtrAllocated(const CoxNbr& y)
{return klsupport().isExtrAllocated(y);}
bool isKLAllocated(const CoxNbr& y) {return d_kl->isKLAllocated(y);}
KLRow& klList(const CoxNbr& y) {return d_kl->d_klList[y][0];}
const KLPol& klPol(const CoxNbr& x, const CoxNbr& y)
{return d_kl->klPol(x,y);}
KLSupport& klsupport() {return d_kl->d_klsupport[0];}
BinaryTree<KLPol>& klTree() {return d_kl->d_klTree;}
Generator last(const CoxNbr& x) {return klsupport().last(x);}
Ulong length(const CoxNbr& x) {return d_kl->length(x);}
const MuPol& mu(const Generator& s, const CoxNbr& x, const CoxNbr& y)
{return d_kl->mu(s,x,y);}
void muCorrection(List<KLPol>& pol, const Generator& s, const CoxNbr& y);
void muCorrection(const CoxNbr& x, const Generator& s, const CoxNbr& y,
List<KLPol>& pol, const Ulong& a);
MuRow& muList(const Generator& s, const CoxNbr& y)
{return d_kl->d_muTable[s][0][y][0];}
MuTable& muTable(const Generator& s) {return d_kl->d_muTable[s][0];}
BinaryTree<MuPol>& muTree() {return d_kl->d_muTree;}
void prepareRowComputation(const CoxNbr& y, const Generator& s);
Rank rank() {return d_kl->rank();}
const SchubertContext& schubert() {return klsupport().schubert();}
void secondTerm(const CoxNbr& y, List<KLPol>& pol, const Generator& s);
Ulong size() {return d_kl->size();}
KLStatus& status() {return *d_kl->d_status;}
void writeMuRow(const MuRow& row, const Generator& s, const CoxNbr& y);
void writeKLRow(const CoxNbr& y, List<KLPol>& pol);
};
};
/*
This module contains code for the computation of kl polynomials with
unequal parameters.
Even though the general setup is similar to that for the ordinary kl
polynomials, there are several important technical differences :
- the polynomials are now Laurent polynomials in the indeterminate q;
morevoer they need not have positive coefficients.
- the mu-coefficients are no longer integers, but Laurent polynomials
themselves; there is one family of mu-coefficients for each conjugacy
class of generators (equivalently, for each connected component of the
Coxeter graph, after suppression of the links with an even or infinite
label.)
The reference for this construction are Lusztig's course notes.
The basic datum is for each generator s an element v_s in Z[q^{1/2},q^{-1/2}]
, a positive integral power of v = q^{1/2}, constant under conjugacy in W.
Then the Hecke algebra is defined by generators t_s, s in S, and relations :
(t_s-v_s)(t_s+v_s^{-1}) = 0, plus the braid relations (these t_s are related
to the "ordinary" T_s by t_s = v_s^{-1}T_s). This implies that t_s.t_w is
t_{sw} when sw > w, and t_{sw} - a_s.t_w otherwise, where a_s = v_s^{-1}-v_s.
Also we have t_s^{-1} = t_s + a_s for each s in S.
Then there is an A-antilinear ring involution on H defined as usual by
t_x^{-1} = t_{x^{-1}}^{-1}. This defines a formal R-function on the group W,
hence a Kazhdan-Lusztig basis c_x, x in W. As usual, c_x is the unique
self-adjoint element in H such that c_x = t_x mod H_{<0}, where H_{<0} is
the direct sum of the v^{-1}Z[v^{-1}]t_x. It turns out that c_y is of
the form :
c_y = t_y + sum_{x<y}p(x,y)t_x
where p(x,y) is in v^{-1}Z[v^{-1}] for all x < y. It is easy to see that
c_e = 1, c_s = t_s + v_s^{-1} for all s in S. From this, one can try to
construct the c_y inductively as in the equal parameter case, as follows.
Let y > e in W, and let s in S such that sy < y. Then the element c_sc_{sy}
is known; it is equal to :
(t_s + v_s^{-1})(t_{ys} + sum_{x<ys}p(x,ys)t_x)
which is t_y + sum_{z<sy,sz<z}v^s.p(z,ys).t_z mod H_{<0}. The positive part
of v_s.p(z,sy) is a polynomial in v of degree at most deg(v_s)-1 (whereas
in the classical case, this degree is at most zero).
We try to correct this by subtracting an expression of the form
sum_{z<sy,sz<z}mu^s(z,sy)c_z
This will be selfadjoint if the mu^s(z,sy) are. The problem is that there
will be an interaction between the various mu-corrections. To correct just
the z-coefficent, we could symmetrize the positive part of v_s.p(z,sy);
but then multiplying c_z with that would create new problems at levels
below z. So the best thing here is to write what we get at the level of
the polynomials. For x < y we have :
p(x,y) = p(sx,sy) if sx < x, x not comparable to sy
= p(sx,sy)+v_s.p(x,sy)-sum_{x<=z<sy,sz<z}mu^s(z,sy)p(x,z) if sx<x<=sy
= v_s^{-1}.p(x,sy) if sx > x, sx not comparable to sy
= v_s^{-1}.p(x,sy)+p(sx,sy)-sum_{x<=z<sy,sz<z}mu^s(z,sy)p(x,z)
if x < sx <= sy
so we need in any case the condition (from the second line) :
v_s.p(x,sy) = sum_{x<=z<sy,sz<z}mu^s(z,sy)p(x,z) mod A_{<0} if sx < x <= sy.
If we define the mu^s(x,y) by induction on the l(y)-l(x), we see that this
translates into : mu^s(x,sy) known mod A_{<0}, and hence mu^s(x,sy) known.
It turns out that these mu^s(x,ys) then also verify the last formula. As
a corollary, it turns out that the computation of the k-l polynomials, even
in this case, reduces to the situation of extremal pairs.
However, the main difference is that the mu-coefficents bear no obvious
relation to the k-l polynomials. They have to be computed through an
independent (although related) recursion, and for them it is not so
clear that there is much extremality reduction.
We need mu^s(x,y) for x < y, sx < x, sy > y. It is not clear to me to what
extent the mu^s depend only on the conjugacy class of s. For one thing,
the domain is not the same; but on the intersection of domains ? Anyway,
for now I'll make one table for each s.
*/
/*
This part of the program is of a more exploratory nature than the rest.
*/
/*****************************************************************************
Chapter I -- The KLContext class
Just like the ordinary k-l polynomials, the KLContext class holds the
polynomial tables and the mu-lists, and provides the functions to
access and output them. Since we restrict ourselves to positive length
functions, the polynomials can be reduced to extremal pairs; hence
the polynomial tables are synchronized with the extrList tables in
the klsupport part (which is shared among all k-l tables.)
The following functions are provided :
- constructors and destructors :
- KLContext(KLSupport* kls);
- ~KLContext();
- accessors not already inlined :
- manipulators :
- applyInverse(const CoxNbr& x) : auxiliary to permute;
- fillKL() : fills the full k-l table;
- fillMu() : fills the full mu-tables;
- fillMu(s) : fills the full mu-table for generator s;
- klPol(cont CoxNbr& x, const CoxNbr& y) : returns P_{x,y};
- row(Permutation& a, const CoxNbr& y) : fills the row for y and returns
an appropriate sort of it in a;
- permute(const Permutation&) : applies a permutation to the context;
- revertSize(const Ulong&) : reverts the size to a previous value;
- setSize(const Ulong&) : sets the size to a larger value;
*****************************************************************************/
namespace uneqkl {
KLContext::KLContext(KLSupport* kls, const CoxGraph& G, const Interface& I)
:d_klsupport(kls),d_klList(0),d_muTable(0),d_L(0),d_length(0)
/*
This constructor gets the lengths interactively from the user. This makes
it possible that an error is set during the construction. Fortunately we can
check this before any memory is gotten from the heap, so that automatic
destruction of the components on exit will be satisfactory in that case.
*/
{
d_L.setSize(2*rank());
getLength(d_L,G,I);
if (ERRNO) { /* error code is ABORT */
goto end;
}
d_status = new KLStatus;
d_help = new KLHelper(this);
d_klList.setSize(kls->size());
d_klList[0] = new KLRow(1);
d_klList[0]->setSize(1);
(*d_klList[0])[0] = d_klTree.find(one());
d_status->klrows++;
d_status->klnodes++;
d_status->klcomputed++;
d_muTable.setSize(rank());
for (Generator s = 0; s < d_muTable.size(); ++s) {
d_muTable[s] = new MuTable(kls->size());
MuTable& t = *d_muTable[s];
t.setSizeValue(kls->size());
t[0] = new MuRow(0);
}
d_length.setSize(kls->size());
for (CoxNbr x = 1; x < d_length.size(); ++x) {
Generator s = last(x);
CoxNbr xs = schubert().shift(x,s);
d_length[x] = d_length[xs] + d_L[s];
}
end:
;
}
KLContext::~KLContext()
{
for (Ulong j = 0; j < d_klList.size(); ++j) {
delete d_klList[j];
}
for (Generator s = 0; s < d_muTable.size(); ++s) {
MuTable& t = *d_muTable[s];
for (Ulong j = 0; j < t.size(); ++j) {
delete t[j];
}
delete d_muTable[s];
}
}
/******** accessors **********************************************************/
/******** manipulators *******************************************************/
void KLContext::applyInverse(const CoxNbr& x)
/*
Exchanges rows for x and x_inverse in klList. It is assumed that the row
for x_inverse is allocated.
*/
{
CoxNbr xi = inverse(x);
d_klList[x] = d_klList[xi];
d_klList[xi] = 0;
return;
}
void KLContext::fillKL()
/*
Fills the full k-l table for the current context.
*/
{
for (CoxNbr y = 0; y < size(); ++y) {
if (inverse(y) < y)
continue;
if (!d_help->checkKLRow(y))
d_help->fillKLRow(y);
}
return;
}
void KLContext::fillMu()
/*
Fills the full mu tables for the current context.
*/
{
for (Generator s = 0; s < rank(); ++s)
fillMu(s);
return;
}
void KLContext::fillMu(const Generator& s)
/*
Fills the full mu table for generator s for the current context.
*/
{
for (CoxNbr y = 0; y < size(); ++y) {
if (schubert().isDescent(y,s))
continue;
if (!d_help->checkMuRow(s,y))
d_help->fillMuRow(s,y);
}
return;
}
const KLPol& KLContext::klPol(const CoxNbr& d_x, const CoxNbr& d_y)
/*
This function returns the Kazhdan-Lusztig polynomial P_{x,y}. It is
assumed that the condition x <= y has already been checked, and that
x and y are valid context numbers.
*/
{
const SchubertContext& p = schubert();
CoxNbr x = d_x;
CoxNbr y = d_y;
/* put x in extremal position w.r.t. y */
x = p.maximize(x,p.descent(y));
/* go to inverses if necessary */
if (inverse(y) < y) {
y = inverse(y);
x = inverse(x);
}
/* check if extrList[y] is allocated */
if (!isKLAllocated(y)) {
d_help->allocKLRow(y);
if (ERRNO)
return errorPol();
}
/* find x in extrList[y] */
Ulong m = find(extrList(y),x);
const KLPol* pol = (*d_klList[y])[m];
if (pol == 0) { /* we have to compute the polynomial */
pol = d_help->fillKLPol(x,y);
if (ERRNO)
return errorPol();
}
return *pol;
}
const MuPol& KLContext::mu(const Generator& s, const CoxNbr& x,
const CoxNbr& y)
/*
This function returns mu^s_{x,y}, filling it in if necessary. It is
assumed that the conditions x < y, ys > y, xs < x have already been
checked.
*/
{
if (!isMuAllocated(s,y))
d_help->allocMuRow(s,y);
const MuRow& mu_row = muList(s,y);
/* find x in row */
MuData mx(x,0);
Ulong m = find(mu_row,mx);
if (m == not_found)
return zero();
const MuPol* mp = mu_row[m].pol;
if (mp == 0) { /* mu-polynomial must be computed */
mp = d_help->fillMu(s,x,y);
if (ERRNO)
return errorMuPol();
}
return *mp;
}
void KLContext::permute(const Permutation& a)
/*
Applies the permutation a to the context. See the permute function of
KLSupport for a detailed explanation.
*/
{
/* permute values */
for (Generator s = 0; s < d_muTable.size(); ++s) {
MuTable& t = *d_muTable[s];
for (CoxNbr y = 0; y < size(); ++y) {
if (!isMuAllocated(s,y))
continue;
MuRow& row = *t[y];
for (Ulong j = 0; j < row.size(); ++j)
row[j].x = a[row[j].x];
row.sort();
}
}
/* permute ranges */
BitMap b(a.size());
for (CoxNbr x = 0; x < size(); ++x) {
if (b.getBit(x))
continue;
if (a[x] == x) {
b.setBit(x);
continue;
}
List<MuRow*> mu_buf(0);
mu_buf.setSize(d_muTable.size());
for (CoxNbr y = a[x]; y != x; y = a[y]) {
/* back up values for y */
KLRow* kl_buf = d_klList[y];
for (Generator s = 0; s < d_muTable.size(); ++s) {
MuTable& t = *d_muTable[s];
mu_buf[s] = t[y];
}
Length length_buf = d_length[y];
/* put values for x in y */
d_klList[y] = d_klList[x];
for (Generator s = 0; s < d_muTable.size(); ++s) {
MuTable& t = *d_muTable[s];
t[y] = t[x];
}
d_length[y] = d_length[x];
/* store backup values in x */
d_klList[x] = kl_buf;
for (Generator s = 0; s < d_muTable.size(); ++s) {
MuTable& t = *d_muTable[s];
t[x] = mu_buf[s];
}
d_length[x] = length_buf;
/* set bit*/
b.setBit(y);
}
b.setBit(x);
}
return;
}
void KLContext::revertSize(const Ulong& n)
/*
Reverts the sizes of the lists to size n. This is meant to be used
only immediately after a failing context extension, to preserve the
consistency of the various list sizes. In particular, it will fail
miserably if a premutation has taken place in-between.
*/
{
d_klList.setSize(n);
for (Generator s = 0; s < d_muTable.size(); ++s) {
MuTable& t = *d_muTable[s];
t.setSize(n);
}
d_length.setSize(n);
return;
}
void KLContext::row(HeckeElt& h, const CoxNbr& y)
/*
This function makes sure that the row corresponding to y in the k-l table
is entirely filled, and returns in h the corresponding data, sorted in
the order of increasing context numbers.
*/
{
if (!d_help->checkKLRow(y)) {
d_klsupport->allocRowComputation(y);
if (ERRNO)
goto error_exit;
d_help->fillKLRow(y);
if (ERRNO)
goto error_exit;
}
{
if (y <= inverse(y)) {
const ExtrRow& e = extrList(y);
h.setSize(e.size());
const KLRow& klr = klList(y);
for (Ulong j = 0; j < e.size(); ++j) {
h[j].setData(e[j],klr[j]);
}
}
else { /* go over to inverses */
CoxNbr yi = inverse(y);
const ExtrRow& e = extrList(yi);
h.setSize(e.size());
const KLRow& klr = klList(yi);
for (Ulong j = 0; j < e.size(); ++j) {
h[j].setData(inverse(e[j]),klr[j]);
}
h.sort(); /* make sure list is ordered */
}
}
return;
error_exit:
Error(ERRNO);
ERRNO = ERROR_WARNING;
return;
}
void KLContext::setSize(const Ulong& n)
/*
This function adjusts the size of the context to a context of size n.
*/
{
CoxNbr prev_size = size();
CATCH_MEMORY_OVERFLOW = true;
d_klList.setSize(n);
if (ERRNO)
goto revert;
for (Generator s = 0; s < d_muTable.size(); ++s) {
MuTable& t = *d_muTable[s];
t.setSize(n);
if (ERRNO)
goto revert;
}
d_length.setSize(n);
if (ERRNO)
goto revert;
CATCH_MEMORY_OVERFLOW = false;
/* fill in new Lengths */
for (CoxNbr x = prev_size; x < n; ++x) {
Generator s = last(x);
CoxNbr xs = schubert().shift(x,s);
d_length[x] = d_length[xs] + genL(s);
}
return;
revert:
CATCH_MEMORY_OVERFLOW = false;
revertSize(prev_size);
return;
}
};
/*****************************************************************************
Chapter II -- The KLHelper class.
The purpose of the KLHelper class is to hide from the public eye a number
of helper functions, used in the construction and maintenance of the
k-l context. This unclutters kl.h quite a bit.
The following functions are defined :
- allocKLRow(y) : allocates one row in the k-l table;
- allocMuRow(row,s,y) : allocates row to a full mu-row for y and s;
- allocMuRow(s,y) : allocates the row for y in muTable(s);
- checkKLRow(y) : checks if the row for y (or inverse(y)) if appropriate)
in the k-l table has been filled;
- fillKLRow(y) : fills the row for y or inverse(y);
- fillKLPol(x,y) : fills in P_{x,y};
- initWorkspace(y,pol,s) : auxiliary to fillKLRow;
- inverseMin(y,s) : reflects y and s if inverse(y) < y;
- muCorrection(pol,s,y) : auxiliary to fillKLRow;
- prepareRowComputation(y,s) : auxiliary to fillKLRow;
- secondTerm(y,pol,s) : ausiliary to fillKLRow;
- writeKLRow(y,pol) : auxiliary to fillKLRow;
*****************************************************************************/
namespace uneqkl {
void KLContext::KLHelper::allocKLRow(const CoxNbr& y)
/*
Allocates one previously unallocated row in the k-l table. It is assumed
that y <= inverse(y). Allocates the corresponding extremal row if necessary.
Forwards a memory error in case of failure if CATCH_MEMORY_ERROR is set.
*/
{
if (!isExtrAllocated(y))
allocExtrRow(y);
Ulong n = extrList(y).size();
d_kl->d_klList[y] = new KLRow(n);
if (ERRNO)
return;
klList(y).setSizeValue(n);
status().klnodes += n;
status().klrows++;
return;
}
void KLContext::KLHelper::allocMuRow(const Generator& s, const CoxNbr& y)
/*
Allocates one previously unallocated row in muTable(s).
For unequal parameters, we don't try to be particularly smart. The row
for y contains one entry for each x < y s.t. xs < x (it is already
implicit that ys > y, or the row would not even be allocated.)
*/
{
MuTable& t = muTable(s);
t[y] = new MuRow(0);
allocMuRow(muList(s,y),s,y);
d_kl->d_status->munodes += muList(s,y).size();
d_kl->d_status->murows++;
return;
}
void KLContext::KLHelper::allocMuRow(MuRow& row, const Generator& s,
const CoxNbr& y)
/*
Allocates row to the full mu-row for y and s.
For unequal parameters, we don't try to be particularly smart. The row
for y contains one entry for each x < y s.t. xs < x (it is already
implicit that ys > y, or the row would not even be allocated.)
*/
{
BitMap b(0);
schubert().extractClosure(b,y);
b &= schubert().downset(s);
row.setSize(0);
BitMap::Iterator b_end = b.end();
for (BitMap::Iterator k = b.begin(); k != b_end; ++k) {
MuData md(*k,0);
row.append(md);
}
return;
}
bool KLContext::KLHelper::checkKLRow(const CoxNbr& d_y)
/*
Checks if the row corresponding to y in the k-l table has been completely
filled. Checks for inverse if y_inverse < y.
*/
{
CoxNbr y = d_y;
if (inverse(y) < y)
y = inverse(y);
if (!isKLAllocated(y))
return false;
const KLRow& kl_row = klList(y);
for (Ulong j = 0; j < kl_row.size(); ++j) {
if (kl_row[j] == 0)
return false;
}
return true;
}
bool KLContext::KLHelper::checkMuRow(const Generator& s, const CoxNbr& y)
/*
Checks if the row corresponding to y in muTable[s] has been completely
filled. Checks for inverse(y) if it is smaller than y.
*/
{
const MuTable& t = muTable(s);
if (t[y] == 0)
return false;
const MuRow& mr = *t[y];
for (Ulong j = 0; j < mr.size(); ++j) {
if (mr[j].pol == 0)
return false;
}
return true;
}
void KLContext::KLHelper::ensureKLRow(const CoxNbr& y)
/*
Makes sure that the k-l row for y is available.
*/
{
if (!checkKLRow(y)) {
klsupport().allocRowComputation(y);
if (ERRNO)
goto abort;
fillKLRow(y);
if (ERRNO)
goto abort;
}
return;
abort:
Error(ERRNO);
ERRNO = ERROR_WARNING;
return;
}
const KLPol* KLContext::KLHelper::fillKLPol(const CoxNbr& x, const CoxNbr& y,
const Generator& d_s)
/*
This function fills in a single polynomial in the k-l table (as opposed to
fillKLRow, which fills a whole row.) It isn't particularly optimized for
speed; it is not a good idea to fill large parts of the table by repeated
calls to fillKLPol.
It is assumed that x <= y in the Bruhat order, y <= inverse(y), x
extremal w.r.t. y, and that the row for y in the k-l table is allocated.
*/
{
static List<KLPol> pol(0); /* workspace stack */
const SchubertContext& p = schubert();
Generator s = d_s;
/* If d_s is undef_coxnbr, we compute the polynomial using descent by last
term in normal form */
if (s == undef_generator)
s = last(y);
CoxNbr ys = p.shift(y,s);
CoxNbr xs = p.shift(x,s);
/* check if x is comparable to ys */
if (!p.inOrder(x,ys)) { /* return the answer immediately */
status().klcomputed++;
Ulong m = list::find(extrList(y),x);
klList(y)[m] = &klPol(xs,ys);
return klList(y)[m];
}
/* get workspace */
CATCH_MEMORY_OVERFLOW = true;
Ulong a = pol.size();
pol.setSize(a+1);
/* initialize the workspace to P_{xs,ys} */
const KLPol& p_xsys = klPol(xs,ys);
if (ERRNO)
goto abort;
pol[a] = p_xsys;
/* add q.P_{x,ys} */
{
const KLPol& p_xys = klPol(x,ys);
if (ERRNO)
goto abort;
pol[a].add(p_xys,genL(s));
if (ERRNO)
goto abort;
}
/* subtract correction terms */
muCorrection(x,s,y,pol,a);
if (ERRNO)
goto abort;
/* find address of polynomial */
{
const KLPol& p_xy = find(pol[a]);
if (ERRNO)
goto abort;
Ulong m = list::find(extrList(y),x);
klList(y)[m] = &p_xy;
/* return workspace and exit */
CATCH_MEMORY_OVERFLOW = false;
pol.setSize(a);
status().klcomputed++;
return &p_xy;
}
abort: /* an error occurred */
CATCH_MEMORY_OVERFLOW = false;
if (ERRNO != MEMORY_WARNING)
ERRNO = KL_FAIL;
pol.setSize(a);
return 0;
}
void KLContext::KLHelper::fillKLRow(const CoxNbr& d_y, const Generator& d_s)
/*
This function fills one row in the k-l table entirely. This can be done
rather more efficiently than computing each polynomial individually :
in particular, most of the closure computations can be "factored" for the
whole row at a time.
It is assumed that checkKLRow(y) returns false. The row which is actually
filled is the one for the smaller of (y,inverse(y)).
*/
{
static List<KLPol> pol(0);
CoxNbr y = d_y;
if (inverse(y) < y) /* fill in the row for inverse(y) */
y = inverse(y);
if (!isKLAllocated(y))
allocKLRow(y);
/* make sure the necessary terms are available */
Generator s = d_s;
if (s == undef_generator)
s = last(y);
prepareRowComputation(y,s);
if (ERRNO)
goto abort;
/* prepare workspace; pol holds the row of polynomials;
initialize workspace with P_{xs,ys} */
initWorkspace(y,pol,s);
/* add q.P_{x,ys} when appropriate */
secondTerm(y,pol,s);
if (ERRNO)
goto abort;
/* subtract correcting terms */
muCorrection(pol,s,y);
if (ERRNO)
goto abort;
/* copy results to row */
writeKLRow(y,pol);
if (ERRNO)
goto abort;
return;
abort:
Error(ERRNO);
ERRNO = ERROR_WARNING;
return;
}
const MuPol* KLContext::KLHelper::fillMu(const Generator& s, const CoxNbr& x,
const CoxNbr& y)
/*
Fills in the mu-polynomial for s,x,y. It is assumed that x < y, sy > y,
sx < x. Recall that the mu-polynomial is the unique symmetric Laurent
polynomial whose positive part is the same as that of :
q^{L(s)/2}p(x,y) - \sum_{x<z<y,zs<s}mu(s,z,y)p(x,z)
Hence it can be computed inductively if we assume that p(x,y) is already
known, and also the mu(s,z,y) for z in ]x,y[ (this is the case in the way
the k-l computation is set up; when we need mu(s,x,y), the corresponding
p(x,y) is known.) Here the p's are the actual Laurent polynomials,
in Z[q^{-1/2}]; so some shifting is required when we read them from our
P's.
Returns 0 in case of error.
*/
{
static List<KLPol> pos_mu(0); // workspace stack
MuRow& mu_row = muList(s,y);
/* initialize a with the value u^(L(x)-L(y)+L(s))P_{x,y}(u^2) */
const KLPol& pol = klPol(x,y);
if (ERRNO) {
Error(MU_FAIL,x,y);
ERRNO = ERROR_WARNING;
return 0;
}
Ulong a = pos_mu.size();
pos_mu.setSize(a+1);
positivePart(pos_mu[a],pol,2,length(x)-length(y)+genL(s));
MuData mx(x,0);
Ulong m = list::find(mu_row,mx); // search cannot fail
/* subtract correcting terms */
const SchubertContext& p = schubert();
for (Ulong j = m+1; j < mu_row.size(); ++j) {
CoxNbr z = mu_row[j].x;
if (!p.inOrder(x,z))
continue;
const KLPol& pol = klPol(x,z);
if (ERRNO) {
Error(MU_FAIL,x,y);
ERRNO = ERROR_WARNING;
return 0;
}
const MuPol& mq = d_kl->mu(s,z,y);
if (!mq.isZero())
muSubtraction(pos_mu[a],mq,pol,2,length(x)-length(z));
if (ERRNO) {
Error(MU_FAIL,x,y);
ERRNO = ERROR_WARNING;
return 0;
}