-
Notifications
You must be signed in to change notification settings - Fork 5
/
typeA.cpp
445 lines (327 loc) · 9.48 KB
/
typeA.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
/*
This is typeA.cpp
Coxeter version 3.0 Copyright (C) 2002 Fokko du Cloux
See file main.cpp for full copyright notice
*/
#include "typeA.h"
/*****************************************************************************
Chapter I -- The TypeACoxGroup class
This class provides some extra features for groups of type A (i.e.,
symmetric groups.) In fact, we are especially interested in i/o in
permutation form. This is also a little test of the flexibility of
the Coxeter group hierarchy.
******************************************************************************/
namespace coxeter {
TypeACoxGroup::TypeACoxGroup(const Rank& l):FiniteCoxGroup(Type("A"),l)
/*
Constructor for the type A Coxeter groups.
*/
{
delete d_interface;
d_typeAInterface = new TypeAInterface(l);
d_interface = d_typeAInterface;
}
TypeACoxGroup::~TypeACoxGroup()
{}
bool TypeACoxGroup::parseGroupElement(ParseInterface& P) const
{
Ulong r = P.offset;
if (parseContextNumber(P)) { // the next token is a ContextNumber
if (ERRNO) // parse error
return true;
else
goto modify;
}
// if we get to this point, we have to read a CoxWord
if (hasPermutationInput()) {
typeAInterface().parsePermutation(P);
}
else {
interface().parseCoxWord(P,mintable());
}
if (ERRNO) { // no CoxWord could be parsed
if (P.offset == r) { // nothing was parsed
ERRNO = 0;
return false;
}
else // parse error
return true;
}
modify:
// if we get to this point, a group element was successfully read
while (parseModifier(P)) {
if (ERRNO)
return true;
}
// flush the current group element
prod(P.a[P.nestlevel],P.c);
P.c.reset();
if (P.offset == r) // nothing was read; c is unchanged
return false;
else
return true;
}
/****************************************************************************
Chapter II --- Derived classes
The only derived class for which something special has to be done is
the TypeAMedRankCoxGroup class, which fills in the minroot table.
*****************************************************************************/
TypeAMedRankCoxGroup::TypeAMedRankCoxGroup(const Rank& l):TypeACoxGroup(l)
{
mintable().fill(graph());
/* an error is set here in case of failure */
return;
}
TypeAMedRankCoxGroup::~TypeAMedRankCoxGroup()
{}
bool TypeASmallCoxGroup::parseDenseArray(ParseInterface& P) const
/*
Tries to parse a DenseArray from P. This is a '#' character, followed
by an integer which has to lie in the range [0,N[, where N is the size
of the group.
*/
{
const Interface& I = interface();
Token tok = 0;
Ulong p = I.getToken(P,tok);
if (p == 0)
return false;
if (!isDenseArray(tok))
return false;
// if we get to this point, we must read a valid integer
P.offset += p;
CoxNbr x = interface::readCoxNbr(P,d_order);
if (x == undef_coxnbr) { //error
P.offset -= p;
Error(DENSEARRAY_OVERFLOW,d_order);
ERRNO = PARSE_ERROR;
}
else { // x is valid
CoxWord g(0);
prodD(g,x);
CoxGroup::prod(P.c,g);
}
return true;
}
bool TypeASmallCoxGroup::parseGroupElement(ParseInterface& P) const
/*
This is the parseGroupElement function for the SmallCoxGroup type. In
this class, we have one additional representation of elements, viz. the
densearray representation. This means that an element that would be
represented by the array [x_1, ... ,x_n] is represented by the number
w = x_1+x_2*a_1+ ... +x_n*a_{n-1}, where a_j is the size of the j'th
subgroup in the filtration. This will give a bijective correspondence
between group elements and numbers in the range [0,N-1], where N is
the size of the group.
*/
{
Ulong r = P.offset;
if (parseContextNumber(P)) { // next token is a context number
if (ERRNO) // parse error
return true;
else
goto modify;
}
if (parseDenseArray(P)) { // next token is a dense array
if (ERRNO) // parse error
return true;
else
goto modify;
}
// if we get to this point, we have to read a CoxWord
if (hasPermutationInput()) {
typeAInterface().parsePermutation(P);
}
else {
interface().parseCoxWord(P,mintable());
}
if (ERRNO) { // no CoxWord could be parsed
if (P.offset == r) { // nothing was parsed
ERRNO = 0;
return false;
}
else // parse error
return true;
}
modify:
// if we get to this point, a group element was successfully read
while (parseModifier(P)) {
if (ERRNO)
return true;
}
// flush the current group element
prod(P.a[P.nestlevel],P.c);
P.c.reset();
if (P.offset == r) // nothing was read; c is unchanged
return false;
else
return true;
}
int TypeASmallCoxGroup::prodD(CoxWord& g, const DenseArray& d_x) const
/*
Does the multiplication of g by x, by recovering the normal pieces of x.
returns the length increase.
*/
{
const Transducer& T = d_transducer[0];
DenseArray x = d_x;
int l = 0;
for (Ulong j = 0; j < rank(); ++j) {
const FiltrationTerm& X = T.transducer(rank()-1-j)[0];
ParNbr c = x%X.size();
l += CoxGroup::prod(g,X.np(c));
x /= X.size();
}
return l;
}
/****************************************************************************
Chapter III --- The TypeAInterface class
Special interface for type A. It has the capacity of outputting elements
in permutation form. For simplicity, we catch permutations as Coxeter
elements in a group one rank bigger.
*****************************************************************************/
TypeAInterface::TypeAInterface(const Rank& l):Interface(Type("A"),l)
{
d_pInterface = new Interface(Type("A"),l+1);
GroupEltInterface GI(l+1,HexadecimalFromZero());
d_pInterface->setIn(GI);
d_pInterface->setOut(GI);
};
TypeAInterface::~TypeAInterface()
{
delete d_pInterface;
};
String& TypeAInterface::append(String& str, const CoxWord& g) const
/*
Special append function for type A. If hasPermutationOutput is true,
it outputs elements in permutation form.
*/
{
if (hasPermutationOutput()) { // print out as permutation
CoxWord a(0);
a.setLength(d_pInterface->rank());
coxWordToPermutation(a,g);
return d_pInterface->append(str,a);
}
else {
return interface::append(str,g,*d_out);
}
}
bool TypeAInterface::parsePermutation(ParseInterface& P) const
/*
Parses a permutation. For us, a permutation should be represented as a
Coxeter element in a group of rank one bigger.
*/
{
Ulong r = P.offset;
d_pInterface->readCoxElt(P);
if (ERRNO == NOT_COXELT) {
Error(NOT_PERMUTATION);
ERRNO = PARSE_ERROR;
return true;
}
if (P.offset > r)
permutationToCoxWord(P.c,P.c);
return true;
}
void TypeAInterface::print(FILE* file, const CoxWord& g) const
/*
Special print function for type A. If hasPermutationOutput is true,
it outputs elements in permutation form.
*/
{
if (hasPermutationOutput()) { // print out as permutation
CoxWord a(0);
a.setLength(d_pInterface->rank());
coxWordToPermutation(a,g);
d_pInterface->print(file,a);
}
else {
interface::print(file,g,*d_out);
}
return;
}
void TypeAInterface::setIn(const GroupEltInterface& i)
/*
Resets d_in to i, and clears hasPermutationInput.
*/
{
delete d_in;
d_in = new GroupEltInterface(i);
readSymbols();
setAutomaton();
setPermutationInput(false);
return;
}
void TypeAInterface::setOut(const GroupEltInterface& i)
/*
Resets d_out to i, and clears hasPermutationOutput.
*/
{
delete d_out;
d_out = new GroupEltInterface(i);
setPermutationOutput(false);
return;
}
/*****************************************************************************
Chapter IV -- Functions declared in typeA.h
This section defines the following functions declared in typeA.h :
- permutationToCoxWord(g,a) : puts in g a reduced expression of the
permutation a;
- coxWordToPermutation(a,g) : the other way around;
******************************************************************************/
void coxWordToPermutation(CoxWord& a, const CoxWord& g)
/*
Puts in a the permutation of the numbers {0,...,l} whose reduced
expression is contained in g. It should be safe to even when a = g
(i.e., we make a copy of g before overwriting a).
NOTE : it is assumed that a.length() = rank+1 is alreaady set to the
correct size.
*/
{
CoxWord h(g);
for (Ulong j = 0; j < a.length(); ++j)
a[j] = j+1;
for (Ulong j = 0; j < h.length(); ++j) {
Generator s = h[j]-1;
// interchange a[s] and a[s+1]
Generator t = a[s+1];
a[s+1] = a[s];
a[s] = t;
}
return;
}
void permutationToCoxWord(CoxWord& g, const CoxWord& a)
/*
Puts in g the standard normal form of a, which is assumed to hold
a permutation of the integers {0,...,l}. It should be safe even when
a = g (i.e., we make a copy of a before overwriting g).
The algorithm is as follows : look at the position of l in a, say
a[j] = l. Then we rotate counterclockwise the entries in a from
j to l, so that now a[l] = l, and the other a[j] are < l; and
finally put l-j into a[l]. This will be the length of the last
"slice" s_l...s_{j+1} in the normal form. Then iterate.
*/
{
CoxWord b(a);
Length c = 0;
for (Rank l = b.length()-1; l; --l) {
Rank j = 0;
for (; b[l-j] != l+1; ++j)
;
for (Rank i = l-j; i < l; ++i)
b[i] = b[i+1];
b[l] = j;
c += j;
}
g.setLength(c);
g[c] = '\0';
c = 0;
for (Ulong j = 1; j < b.length(); ++j) {
for (Ulong i = 0; i < b[j]; ++i)
g[c+i] = j-i;
c += b[j];
}
return;
}
}