-
Notifications
You must be signed in to change notification settings - Fork 5
/
kl.cpp
3285 lines (2556 loc) · 79.5 KB
/
kl.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 kl.cpp
Coxeter version 3.0 Copyright (C) 2002 Fokko du Cloux
See file main.cpp for full copyright notice
*/
#include "kl.h"
#include "error.h"
#include "iterator.h"
namespace kl {
using namespace error;
using namespace iterator;
}
/****************************************************************************
This file contains the code for the computation of the (ordinary) Kazhdan-
Lusztig polynomials for W.
The kl context maintains two main lists : klList and muList. Each of these
has one pointer (to a KLRow and a MuRow, respectively) for each element in
the current schubert context; the enlargement and permutation functions
for the schubert context make sure that the various active k-l contexts
are enlarged/permuted accordingly.
The row y in klList, when allocated, contains one entry for each extremal
x <= y; the list of those x can be gotten from the klsupport structure,
which maintains these extremal lists. The lists of extremal pairs are shared
among all k-l contexts. Each entry in klList(y) is simply a pointer to
a (constant) polynomial, the k-l polynomial for (x,y). The main complication
is that I've (rightly or wrongly) decided to not allocate klList(y) if
inverse(y) < y; in that case, the polynomial is read from the list for
inverse(y). This saves space, but makes lookup more complicated. More
importantly though, the fact of systematically going over to inverse(y) when
it is smaller, seems to make the algorithm quite a bit faster and leaner
(in the sense that fewer rows need to be computed); this, more than the
memory saving, is my main reason for keeping this complication in.
The situation for mu-rows is a little bit more delicate. First of all, we
do not here go over to inverses; we fill all the rows that are needed
(using the mu-value for the inverses if it is available.) Further, we only
look at pairs where the length difference is at least three; it is known
that we can then reduce to extremal pairs, the other mu-values being zero.
But in fact, even among extremal pairs, most values are zero as well. So
we do not necessarily allocate one entry for each pair; what is guaranteed
is that all entries correspond to extremal pairs, and all non-zero mu-values
have an entry. Ideally, we would wish to allocate only the non-zero mu's;
however, this would require computing a full row as soon as one coefficient
is needed, so we have refrained from that. Anyway, to find out the value
for mu(x,y), we extremalize x, check that the length difference is odd >= 3,
look x up in muList(y), and return the corresponding mu-value if found, 0
otherwise.
The idea is to compute everything upon request : we compute exactly what
is needed in the recursive computation of what is required.
The requests that we mainly focus on are the following :
- compute a single k-l polynomial (mu-coefficient);
- compute all P_{x,y}'s (mu(x,y)'s) for a given y;
- compute the full file of k-l polynomials (mu coefficients);
It turns out that the dominant factor in the computation is the Bruhat order
comparison. That is why computing a whole row can be done much more
efficently than computing each entry in the row separately : using our
closure function from the schubert context, we can basically factor out
most of the Bruhat things for a whole row. In any case, the row computation
can be done without a single call to the slow inOrder function!
****************************************************************************/
namespace kl {
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 CoxNbr& y);
void allocMuRow(MuRow& row, const CoxNbr& y);
void allocMuTable();
void allocRowComputation(const CoxNbr& y);
bool checkKLRow(const CoxNbr& y);
bool checkMuRow(const CoxNbr& y);
void coatomCorrection(const CoxNbr& y, List<KLPol>& pol);
void coatomCorrection(const CoxNbr& x, const CoxNbr& y, const Generator& s,
List<KLPol>& pol, const Ulong& a);
KLCoeff computeMu(const CoxNbr& x, const CoxNbr& y);
const ExtrRow& extrList(const CoxNbr& y) {return klsupport().extrList(y);}
void fillMuRow(MuRow& row, const CoxNbr& y);
const KLPol* fillKLPol(const CoxNbr& x, const CoxNbr& y,
const Generator& s = undef_generator);
void fillKLRow(const CoxNbr& y);
void initWorkspace(const CoxNbr& y, List<KLPol>& pol);
CoxNbr inverse(const CoxNbr& y) {return klsupport().inverse(y);}
void inverseMuRow(const CoxNbr& y);
bool isExtrAllocated(const CoxNbr& y)
{return klsupport().isExtrAllocated(y);}
bool isKLAllocated(const CoxNbr& y) {return d_kl->isKLAllocated(y);}
bool isMuAllocated(const CoxNbr& y) {return d_kl->isMuAllocated(y);}
KLRow& klList(const CoxNbr& y) {return *d_kl->d_klList[y];}
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);}
void makeMuRow(const CoxNbr& y);
KLCoeff mu(const CoxNbr& x, const CoxNbr& y) {return d_kl->mu(x,y);}
void muCorrection(const CoxNbr& y, List<KLPol>& pol);
void muCorrection(const CoxNbr& x, const CoxNbr& y, const Generator& s,
List<KLPol>& pol, const Ulong& a);
MuRow& muList(const CoxNbr& y) {return *d_kl->d_muList[y];}
void prepareRow(const CoxNbr& y, const Generator& s);
Rank rank() {return d_kl->rank();}
void readMuRow(const CoxNbr& y);
KLCoeff recursiveMu(const CoxNbr& x, const CoxNbr& y, const Generator& s);
const SchubertContext& schubert() {return klsupport().schubert();}
void secondTerm(const CoxNbr& y, List<KLPol>& pol);
Ulong size() {return d_kl->size();}
KLStatus& status() {return *d_kl->d_status;}
void writeKLRow(const CoxNbr& y, List<KLPol>& pol);
void writeMuRow(const MuRow& row, const CoxNbr& y);
};
};
namespace {
using namespace kl;
struct PolPtrF {
typedef const KLPol* valueType;
const KLPol* operator()(const KLPol* pol) {return pol;}
};
void allocExtrRow(KLContext& kl, ExtrRow& row, const CoxNbr& y);
void appendStar(String& str, const KLContext& kl, const CoxNbr& x,
const KLPol& pol, const Length& l);
MuData* find(MuRow& row, const CoxNbr& x);
void printStar(FILE* file, const KLContext& kl, const CoxNbr& x,
const KLPol& pol, const Length& l);
KLPol& safeAdd(KLPol& p, const KLPol& q, const Degree& n);
KLPol& safeSubtract(KLPol& p, const KLPol& q, const KLCoeff& mu,
const Length& h);
void showSimpleMu(FILE* file, KLContext& kl, const CoxNbr& x,
const CoxNbr& y, const KLCoeff& r, const Interface& I);
void showRecursiveMu(FILE* file, KLContext& kl, const CoxNbr& x,
const CoxNbr& y, const KLCoeff& r, const Interface& I);
KLPol& zeroPol();
};
/****************************************************************************
Chapter I --- The KLContext class
This section defines the functions for the KLContext class. The following
functions are defined :
constructors and destructors :
- KLContext(KLSupport* kls);
- ~KLContext();
accessors :
manipulators :
- applyInverse(y) : exchanges rows in klList for y and y_inverse;
- fillKL() : fills the full k-l table;
- fillMu() : fills the full mu-table;
- klPol(x,y) : for x <= y, returns the Kazhdan-Lusztig polynomial;
- klPol(x,y,s) : same as above, using s as descent;
- lcell() : returns the left cell partition;
- lrcell() : returns the two-sided cell partition;
- mu(x,y) : for x <= y, returns the mu-coefficient;
- rcell() : returns the right cell partition;
- row(h,y,I) : returns the row of the CoxNbr y in h;
- row(e_row,kl_row,y) : returns the row of the CoxNbr y;
- revertSize(n) : reverts the size to size n;
- setSize(n) : extends the context to size n;
input/output :
- printStatus(file) : prints the status;
****************************************************************************/
namespace kl {
KLContext::KLContext(KLSupport* kls)
:d_klsupport(kls), d_klList(kls->size()), d_muList(kls->size())
{
d_status = new KLStatus;
d_help = new KLHelper(this);
d_klList.setSizeValue(kls->size());
d_klList[0] = new KLRow(1);
d_klList[0]->setSizeValue(1);
d_klList[0][0][0] = d_klTree.find(one());
d_status->klnodes++;
d_status->klrows++;
d_status->klcomputed++;
d_muList.setSizeValue(kls->size());
d_muList[0] = new MuRow(0);
}
KLContext::~KLContext()
/*
Recall that a KLContext is assumed to own its SchubertContext. The only
destructions that are not done automatically are those of the Schubert
context, the status pointer, and the extrList pointers.
*/
{
for (Ulong j = 0; j < size(); ++j) {
delete d_klList[j];
delete d_muList[j];
}
delete d_status;
return;
}
/******** 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;
}
void KLContext::fillKL()
/*
This function fills all the rows in klList, in a straightforward way.
*/
{
if (isFullKL())
return;
for (CoxNbr y = 0; y < size(); ++y) {
if (inverse(y) < y)
continue;
if (!isKLAllocated(y))
d_help->allocKLRow(y);
d_help->fillKLRow(y);
d_help->readMuRow(y);
}
setFullKL();
return;
}
void KLContext::fillMu()
/*
This function fills all the rows in the mu-list, in a straightforward way.
Sets the error ERROR_WARNING in case of error.
NOTE : error handling should be improved!
*/
{
if (isFullMu())
return;
static MuRow mu_row(0);
d_help->allocMuTable();
if (ERRNO)
goto abort;
for (CoxNbr y = 0; y < size(); ++y) {
if (inverse(y) < y)
d_help->inverseMuRow(inverse(y));
d_help->fillMuRow(*d_muList[y],y);
if (ERRNO)
goto abort;
}
setFullMu();
return;
abort:
Error(ERRNO);
ERRNO = ERROR_WARNING;
return;
}
const KLPol& KLContext::klPol(const CoxNbr& d_x, const CoxNbr& d_y,
const Generator& s)
/*
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.
*/
{
CoxNbr x = d_x;
CoxNbr y = d_y;
const SchubertContext& p = schubert();
/* put x in extremal position w.r.t. y */
x = p.maximize(x,p.descent(y));
/* check for trivial cases */
if (p.length(y) - p.length(x) < 3) { /* result is 1 */
return one();
}
/* 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 zeroPol();
}
/* find x in extrList[y] */
Ulong m = find(extrList(y),x);
const KLPol*& pol = d_help->klList(y)[m];
if (pol == 0) { /* we have to compute the polynomial */
pol = d_help->fillKLPol(x,y,s);
if (ERRNO)
return zeroPol();
}
return *pol;
}
KLCoeff KLContext::mu(const CoxNbr& x, const CoxNbr& y)
/*
This function returns the mu-coefficient mu(x,y). It is assumed that
the condition x <= y has already been checked, and that x and y are
valid context numbers.
The return value is zero if the length difference is even.
If an error occurs, it forwards the error value and returns the
value undef_klcoeff for mu.
*/
{
const SchubertContext& p = schubert();
Length d = p.length(y) - p.length(x);
if (d%2 == 0)
return 0;
if (d == 1) /* x is a coatom of y */
return 1;
/* check if x is in extremal position w.r.t. y */
if (x != p.maximize(x,p.descent(y)))
return 0;
/* allocate *d_muList[y] if necessary */
if (!isMuAllocated(y)) {
d_help->allocMuRow(y);
if (ERRNO)
return undef_klcoeff;
}
/* find x in *d_muList[y] */
MuRow& m = *d_muList[y];
MuData* md = find(m,x);
if (md == 0)
return 0;
if (md->mu == undef_klcoeff) { /* we need to compute the coefficient */
md->mu = d_help->computeMu(x,y);
if (ERRNO)
return undef_klcoeff;
}
return md->mu;
}
void KLContext::permute(const Permutation& a)
/*
This function permutes the context according to the permutation a. The
following objects have to be permuted :
- klList, muList : each row is a table with values in the context; the
list itself has range in the context; don't forget to sort the permuted
rows!
- inverse : range and values in the context, with some annoyance caused
by undef_coxnbr values;
- last : range in the context;
Applying a permutation to something goes as follows. The permutation
a is the table of the function which assigns to each x in the context its
number in the new enumeration. Applying this to the context means the
following :
(a) for tables with _values_ in the context, we need to replace t[j] with
a[t[j]];
(b) for tables with _range_ in the context, we need to put t[x] at a[x];
this amounts to replacing t[x] by t[a_inv[x]] for all x;
(c) for tables with both range and values in the context, we need to do
both : replace t[x] with a[t[a_inv[x]]]; in practice this is done
by first replacing the values as in (a), then permuting as in (b).
The replacements in (a) are straightforward. The permutations in (b) are
more delicate, and would seem to require additional memory for each list to
be transformed. In fact, things can be done in place. The thing is to use
the cycle decomposition of the permutation : put t[x] at position a[x],
t[a[x]] at position a^2[x], ... t[a^{k-1}[x]] at position x, if a^k[x] = x.
This requires only the use of the bitmap of a to mark off the entries that
have been handled, and skip to the next entry.
*/
{
/* permute values */
for (CoxNbr y = 0; y < size(); ++y) {
if (!isMuAllocated(y))
continue;
MuRow& row = *d_muList[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;
}
for (CoxNbr y = a[x]; y != x; y = a[y]) {
/* back up values for y */
KLRow* kl_buf = d_klList[y];
MuRow* mu_buf = d_muList[y];
/* put values for x in y */
d_klList[y] = d_klList[x];
d_muList[y] = d_muList[x];
/* store backup values in x */
d_klList[x] = kl_buf;
d_muList[x] = mu_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);
d_muList.setSize(n);
return;
}
void KLContext::row(HeckeElt& h, const CoxNbr& y)
/*
This function returns in h the data for the full row of y in the k-l table,
sorted in the context number order.
*/
{
if (!d_help->checkKLRow(y)) {
d_help->allocRowComputation(y);
d_help->fillKLRow(y);
}
if (ERRNO) {
Error(ERRNO);
ERRNO = ERROR_WARNING;
return;
}
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;
}
void KLContext::setSize(const Ulong& n)
/*
This function extends the context so that it can accomodate n elements.
The idea is to have the same size as the basic schubert context.
*/
{
CoxNbr prev_size = size();
CATCH_MEMORY_OVERFLOW = true;
d_klList.setSize(n);
if (ERRNO)
goto revert;
d_muList.setSize(n);
if (ERRNO)
goto revert;
CATCH_MEMORY_OVERFLOW = false;
clearFullKL();
clearFullMu();
return;
revert:
CATCH_MEMORY_OVERFLOW = false;
revertSize(prev_size);
return;
}
/******** input/output ******************************************************/
void KLContext::printStatus(FILE* file) const
/*
This function prints the status of the context. This is a data structure
that monitors precisely the computations that have been effected, and
the memory that has been allocated.
*/
{
fprintf(file,"klrows = %lu\n",d_status->klrows);
fprintf(file,"klnodes = %lu\n",d_status->klnodes);
fprintf(file,"klcomputed = %lu\n",d_status->klcomputed);
fprintf(file,"murows = %lu\n",d_status->murows);
fprintf(file,"munodes = %lu\n",d_status->munodes);
fprintf(file,"mucomputed = %lu\n",d_status->mucomputed);
fprintf(file,"muzero = %lu\n",d_status->muzero);
return;
}
/******** to be taken out! **************************************************/
void KLContext::compareMu()
/*
This function compares the mu-values gotten directly from the k-l polynomials
to those from fillMu.
*/
{
static MuRow mu_row(0);
fillMu();
printStatus(stdout);
for (CoxNbr y = 0; y < size(); ++y) {
if (inverse(y) < y)
continue;
if (!isKLAllocated(y))
d_help->allocKLRow(y);
d_help->fillKLRow(y);
const MuRow& mu_row = muList(y);
const ExtrRow& e = extrList(y);
const KLRow& kl_row = klList(y);
Ulong i = 0;
for (Ulong j = 0; j < mu_row.size(); ++j) {
CoxNbr x = mu_row[j].x;
while(e[i] < x)
++i;
const KLPol& pol = *kl_row[i];
Length d = mu_row[j].height;
if (pol.deg() == d) {
if (mu_row[j].mu != pol[d])
printf("error! x = %lu, y = %lu\n",static_cast<Ulong>(x),
static_cast<Ulong>(y));
}
else {
if(mu_row[j].mu != 0)
printf("error! x = %lu, y = %lu\n",static_cast<Ulong>(x),
static_cast<Ulong>(y));
}
}
}
}
};
/****************************************************************************
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 :
- allocExtrRow(const CoxNbr& y) : allocates a row in the extremal list;
- allocKLRow(const CoxNbr& y) : allocates a row in the k-l list;
- allocMuRow(const CoxNbr& y) : allocates a row in the mu list;
- allocMuRow(MuRow& row, const CoxNbr& y) : same, for an external mu-row;
- allocMuTable() : allocates the full mu-table;
- allocRowComputation(const CoxNbr& y) : initial allocation for a
row-computation
- checkKLRow(const CoxNbr& y) : checks if a k-l row is fully computed;
- coatomCorrection(const CoxNbr& y, List<KLPol>& pol) : subtracts the
terms ofr coatoms in the mu-correction, for a full row;
- coatomCorrection(const CoxNbr& x, const CoxNbr& y, const Generator& s,
List<KLPol>& pol, const Ulong& a) : same, for a single polynomial
- computeMu(const CoxNbr& x, const CoxNbr& y) : computes a mu-coefficient;
- fillMuRow(MuRow& row, const CoxNbr& y) : fills a row in the mu-table;
- fillKLPol(const CoxNbr& x, const CoxNbr& y, const Generator& s =
undef_generator) : fills in one polynomial, using s as descent;
- fillKLRow(const CoxNbr& y) : fills in one row in the k-l table;
CoxNbr inverse(const CoxNbr& y) : returns the inverse of y;
- initWorkspace(const CoxNbr& y, List<KLPol>& pol) : another preliminary
to the computation of a row;
- inverseMuRow(const CoxNbr& y) : constructs the mu-row for y from that
of the inverse of y;
- makeMuRow(const CoxNbr& y);
- muCorrection(const CoxNbr& y, List<KLPol>& pol) : subtracts the non-coatom
mu-part in the computation of a row;
- muCorrection(const CoxNbr& x, const CoxNbr& y, const Generator& s,
List<KLPol>& pol, const Ulong& a) : subtracts the non-coatom mu-part,
for the computation of a single polynomial;
- muList(const CoxNbr& y) : returns the row for y in muList;
- prepareRow(const CoxNbr& y, const Generator& s) : a preliminary to the
computation of a row;
- readMuRow(const CoxNbr& y) : fills in the mu-row from the k-l row;
- recursiveMu(const CoxNbr& x, const CoxNbr& y, const Generator& s) :
computes mu(x,y) using the general recursive formula;
- secondTerm(const CoxNbr& y, List<KLPol>& pol) : takes care of the
second term P_{x,ys} in the computation of a full row;
- writeKLRow(const CoxNbr& y, List<KLPol>& pol) : transfers the
polynomials from pol to klList;
- writeMuRow(const MuRow& row, const CoxNbr& y) transfers the
mu-coefficients from row to muList;
****************************************************************************/
namespace kl {
void KLContext::KLHelper::allocKLRow(const CoxNbr& y)
/*
This function allocates one row of the kl_list. The row contains one
entry for each x <= y which is extremal w.r.t. the descent set of y.
The algorithm is as follows : we extract the interval [e,y] as a
bitmap, extremalize it by intersecting with the downsets for the
various generators, and read it into the row.
Forwards the error MEMORY_WARNING if there is a memory overflow
and CATCH_MEMORY_OVERFLOW is turned on.
*/
{
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 CoxNbr& y)
/*
This function allocates one row in the muList. There is one entry for
each x < y which is extremal w.r.t. y, and has odd length-difference > 1
with y. As with allocKLRow, this function is not designed for maximal
efficiency; row allocations for big computations should be handled
differently.
*/
{
typedef FilteredIterator<CoxNbr,ExtrRow::ConstIterator,MuFilter> EI;
typedef FilteredIterator<Ulong,BitMap::Iterator,MuFilter> BI;
const SchubertContext& p = schubert();
ExtrRow e(0);
MuFilter f(p,y);
if (isExtrAllocated(y)) {
EI first(extrList(y).begin(),extrList(y).end(),f);
EI last(extrList(y).end(),extrList(y).end(),f);
new(&e) ExtrRow(first,last);
}
else {
BitMap b(size());
p.extractClosure(b,y);
if (ERRNO)
return;
maximize(p,b,p.descent(y));
BI first(b.begin(),b.end(),f);
BI last(b.end(),b.end(),f);
new(&e) ExtrRow(first,last);
}
Length ly = p.length(y);
d_kl->d_muList[y] = new MuRow(e.size());
if (ERRNO)
goto abort;
muList(y).setSizeValue(e.size());
for (Ulong j = 0; j < e.size(); ++j) {
CoxNbr x = e[j];
Length lx = p.length(x);
new(muList(y).ptr()+j) MuData(x,undef_klcoeff,(ly-lx-1)/2);
}
status().munodes += e.size();
status().murows++;
return;
abort:
Error(ERRNO);
ERRNO = ERROR_WARNING;
return;
}
void KLContext::KLHelper::allocMuRow(MuRow& row, const CoxNbr& y)
/*
Like allocMuRow(const CoxNbr& y), but does the allocation in row.
NOTE : this function does not worry about memory overflow. This should
probably be revised.
*/
{
const SchubertContext& p = schubert();
ExtrRow e(0);
if (isExtrAllocated(y)) { /* extremal row is already available */
e = extrList(y);
}
else { /* make it from scratch */
BitMap b(size());
p.extractClosure(b,y);
maximize(p,b,p.descent(y));
readBitMap(e,b);
}
/* extract elements with odd length difference > 1 */
Ulong mu_count = 0;
Length ly = p.length(y);
for (Ulong j = 0; j < e.size(); ++j) {
CoxNbr x = e[j];
Length lx = p.length(x);
if ((ly-lx)%2 == 0)
continue;
if (ly-lx == 1)
continue;
e[mu_count] = x;
mu_count++;
}
row.setSize(mu_count);
for (Ulong j = 0; j < mu_count; ++j) {
CoxNbr x = e[j];
Length lx = p.length(x);
new(row.ptr()+j) MuData(x,undef_klcoeff,(ly-lx-1)/2);
}
return;
}
void KLContext::KLHelper::allocMuTable()
/*
This function does the allocation of the full muList, using the closure
iterator. It is not as satisfactory as it should be, because the rows
are not obtained in order, and therefore we can not fill them right
away to eliminate zero entries. So I am currently not too happy with
the situation. Even if we recover the memory later on, it will be
highly fragmented.
So currently this is just an exercise in formal elegance.
*/
{
typedef FilteredIterator<Ulong,BitMap::Iterator,MuFilter> I;
const SchubertContext& p = schubert();
for (ClosureIterator cl(p); cl; ++cl) {
CoxNbr y = cl.current();
if (inverse(y) < y)
continue;
if (isMuAllocated(y))
continue;
/* find extremal list */
BitMap b = cl().bitMap();
if (ERRNO) {
printf("error! y = %lu\n",static_cast<Ulong>(y));
goto abort;
}
maximize(p,b,p.descent(y));
MuFilter f(p,y);
I first(b.begin(),b.end(),f);
I last(b.end(),b.end(),f);
ExtrRow e(first,last);
if (ERRNO) {
goto abort;
}
/* transfer to muList */
Length ly = p.length(y);
d_kl->d_muList[y] = new MuRow(e.size());
muList(y).setSizeValue(e.size());
for (Ulong j = 0; j < e.size(); ++j) {
CoxNbr x = e[j];
Length lx = p.length(x);
MuData mu_data(x,undef_klcoeff,(ly-lx-1)/2);
muList(y).append(mu_data);
if (ERRNO) {
goto abort;
}
}
status().murows++;
status().munodes += e.size();
}
return;
abort:
Error(ERRNO);
ERRNO = ERROR_WARNING;
return;
}
void KLContext::KLHelper::allocRowComputation(const CoxNbr& y)
/*
This function does the primary memory allocation for the computation
of a schubert row. This means that for each initial subword of the
normal form of y, we check if the corresponding row in klList (or the
inverse row, if appropriate) is allocated, and if not, do the allocation.
First, we determine the sequence of left and right shifts that takes
y to the identity element, as follows : if inverse(y) >= y, we shift
on the right by last(y); else, we shift on the left by last(inverse(y)),
and get the inverse of the element which will be used for the recursion
for inverse(y). So when we reconstruct the interval using this sequence
of shifts, we know that when we apply a left shift we are actually
constructing the inverse of the interval we want.
We can do this in one pass, as we extract the interval [e,y].
Deals with the possible memory error, and returns ERROR_WARNING in case
of error.
*/
{
klsupport().allocRowComputation(y);
List<Generator> g(0);
klsupport().standardPath(g,y);
CoxNbr y1 = 0;
for (Ulong j = 0; j < g.size(); ++j) {
Generator s = g[j];
y1 = schubert().shift(y1,s);
CoxNbr y2 = klsupport().inverseMin(y1);
const ExtrRow& e = extrList(y2);
if (!isKLAllocated(y2)) {
d_kl->d_klList[y2] = new KLRow(e.size());
if (ERRNO)
goto abort;
klList(y2).setSizeValue(extrList(y2).size());
status().klnodes += extrList(y2).size();
status().klrows++;
}
}
return;
abort:
Error(ERRNO);
ERRNO = ERROR_WARNING;
return;
}
bool KLContext::KLHelper::checkKLRow(const CoxNbr& d_y)
/*
This function checks if the row for y (or for inverse(y) if appropriate)
in klList has been filled.
*/
{
CoxNbr y = d_y;
if (inverse(y) < y)
y = inverse(y);
if (!isKLAllocated(y)) /* row is not allocated */
return false;
KLRow& kl_row = klList(y);
for (Ulong j = 0; j < kl_row.size(); ++j) {
if (kl_row[j] == 0)