forked from gap-system/gap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcostab.c
2430 lines (2162 loc) · 84.3 KB
/
costab.c
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
/****************************************************************************
**
*W costab.c GAP source Frank Celler
*W & Volkmar Felsch
*W & Martin Schönert
*W & Alexander Hulpke
**
**
*Y Copyright (C) 1996, Lehrstuhl D für Mathematik, RWTH Aachen, Germany
*Y (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland
*Y Copyright (C) 2002 The GAP Group
**
** This file contains the functions of for coset tables.
*/
#include "costab.h"
#include "bool.h"
#include "error.h"
#include "integer.h"
#include "io.h"
#include "lists.h"
#include "modules.h"
#include "plist.h"
/****************************************************************************
**
*V declaration of static variables
*/
static Obj objRel; /* handle of a relator */
static Obj objNums; /* handle of parallel numbers list */
static Obj objTable; /* handle of the coset table */
static Obj objTable2; /* handle of coset factor table */
static Obj objNext; /* */
static Obj objPrev; /* */
static Obj objFactor; /* */
static Obj objTree; /* handle of subgroup gens tree */
static Obj objTree1; /* first tree component */
static Obj objTree2; /* second tree component */
static Obj objExponent; /* handle of subgroup order */
static Obj objWordValue; /* handle of word value */
static Int treeType; /* tree type */
static Int treeWordLength; /* maximal tree word length */
static Int firstDef; /* */
static Int lastDef; /* */
static Int firstFree; /* */
static Int lastFree; /* */
static Int minGaps; /* switch for marking mingaps */
static Int nrdel; /* */
static Int dedfst; /* position of first deduction */
static Int dedlst; /* position of last deduction */
static Int dedgen [40960]; /* deduction list keeping gens */
static Int dedcos [40960]; /* deduction list keeping cosets */
static Int dedSize = 40960; /* size of deduction list buffers */
static Int dedprint; /* print flag for warning */
static Int wordList [1024]; /* coset rep word buffer */
static Int wordSize = 1023; /* maximal no. of coset rep words */
/* clean out global Obj-type variables to avoid hogging memory*/
static void CleanOut( void )
{
objRel = (Obj) 0;
objNums = (Obj) 0;
objTable = (Obj) 0;
objTable2 = (Obj) 0;
objNext = (Obj) 0;
objPrev = (Obj) 0;
objFactor = (Obj) 0;
objTree = (Obj) 0;
objTree1 = (Obj) 0;
objTree2 = (Obj) 0;
objExponent = (Obj) 0;
objWordValue = (Obj) 0;
}
/****************************************************************************
**
*F FuncApplyRel( <self>, <app>, <rel> ) apply a relator to a coset in a TC
**
** 'FuncApplyRel' implements the internal function 'ApplyRel'.
**
** 'ApplyRel( <app>, <rel> )'
**
** 'ApplyRel' applies the relator <rel> to the application list <app>.
**
** ... more about ApplyRel ...
*/
Obj FuncApplyRel (
Obj self,
Obj app, /* handle of the application list */
Obj rel ) /* handle of the relator */
{
Int lp; /* left pointer into relator */
Int lc; /* left coset to apply to */
Int rp; /* right pointer into relator */
Int rc; /* right coset to apply to */
Int tc; /* temporary coset */
/* check the application list */
/*T 1996/12/03 fceller this should be replaced by 'PlistConv' */
RequirePlainList(0, app);
if ( LEN_PLIST(app) != 4 ) {
ErrorQuit( "<app> must be a list of length 4 not %d",
(Int) LEN_PLIST(app), 0L );
return 0;
}
/* get the four entries */
lp = INT_INTOBJ( ELM_PLIST( app, 1 ) );
lc = INT_INTOBJ( ELM_PLIST( app, 2 ) );
rp = INT_INTOBJ( ELM_PLIST( app, 3 ) );
rc = INT_INTOBJ( ELM_PLIST( app, 4 ) );
/* get and check the relator (well, only a little bit) */
/*T 1996/12/03 fceller this should be replaced by 'PlistConv' */
RequirePlainList(0, rel);
/* fix right pointer if requested */
if ( rp == -1 )
rp = lp + INT_INTOBJ( ELM_PLIST( rel, 1 ) );
/* scan as long as possible from the right to the left */
while ( lp < rp
&& 0 < (tc = INT_INTOBJ(ELM_PLIST(ELM_PLIST(rel,rp),rc))) )
{
rc = tc; rp = rp - 2;
}
/* scan as long as possible from the left to the right */
while ( lp < rp
&& 0 < (tc = INT_INTOBJ(ELM_PLIST(ELM_PLIST(rel,lp),lc))) )
{
lc = tc; lp = lp + 2;
}
/* copy the information back into the application list */
SET_ELM_PLIST( app, 1, INTOBJ_INT( lp ) );
SET_ELM_PLIST( app, 2, INTOBJ_INT( lc ) );
SET_ELM_PLIST( app, 3, INTOBJ_INT( rp ) );
SET_ELM_PLIST( app, 4, INTOBJ_INT( rc ) );
/* return 'true' if a coincidence or deduction was found */
if ( lp == rp+1
&& INT_INTOBJ(ELM_PLIST(ELM_PLIST(rel,lp),lc)) != rc )
{
return True;
}
else
return False;
}
/****************************************************************************
**
*F CompressDeductionList() . . . . removes unused items from deduction list
**
** 'CompressDeductionList' tries to find and delete deduction list entries
** which are not used any more.
**
** 'dedgen', 'dedcos', 'dedfst', 'dedlst', 'dedSize' and 'objTable' are
** assumed to be known as static variables.
*/
static void CompressDeductionList ( void )
{
Obj * ptTable; /* pointer to the coset table */
Int i;
Int j;
/* check if the situation is as assumed */
if ( dedlst != dedSize ) {
ErrorQuit( "invalid call of CompressDeductionList", 0L, 0L );
return;
}
/* run through the lists and compress them */
ptTable = BASE_PTR_PLIST(objTable) - 1;
j = 0;
for ( i = dedfst; i < dedlst; i++ ) {
if ( INT_INTOBJ(ELM_PLIST(ptTable[dedgen[i]],dedcos[i])) > 0
&& j < i )
{
dedgen[j] = dedgen[i];
dedcos[j] = dedcos[i];
j++;
}
}
/* update the pointers */
dedfst = 0;
dedlst = j;
/* check if we have at least one free position */
if ( dedlst == dedSize ) {
if ( dedprint == 0 ) {
Pr( "#I WARNING: deductions being discarded\n", 0L, 0L );
dedprint = 1;
}
dedlst--;
}
}
/****************************************************************************
**
*F HandleCoinc( <cos1>, <cos2> ) . . . . . . . . handle coincidences in a TC
**
** 'HandleCoinc' is a subroutine of 'FuncMakeConsequences' and handles the
** coincidence cos2 = cos1.
*/
static void HandleCoinc (
Int cos1,
Int cos2 )
{
Obj * ptTable; /* pointer to the coset table */
Obj * ptNext;
Obj * ptPrev;
Int c1;
Int c2;
Int c3;
Int i;
Int firstCoinc;
Int lastCoinc;
Obj * gen;
Obj * inv;
/* is this test necessary? */
if ( cos1 == cos2 ) return;
/* get some pointers */
ptTable = BASE_PTR_PLIST(objTable) - 1;
ptNext = BASE_PTR_PLIST(objNext) - 1;
ptPrev = BASE_PTR_PLIST(objPrev) - 1;
/* take the smaller one as new representative */
if ( cos2 < cos1 ) { c3 = cos1; cos1 = cos2; cos2 = c3; }
/* if we are removing an important coset update it */
if ( cos2 == lastDef )
lastDef = INT_INTOBJ( ptPrev[lastDef ] );
if ( cos2 == firstDef )
firstDef = INT_INTOBJ( ptPrev[firstDef] );
/* remove <cos2> from the coset list */
ptNext[INT_INTOBJ(ptPrev[cos2])] = ptNext[cos2];
if ( ptNext[cos2] != INTOBJ_INT( 0 ) )
ptPrev[INT_INTOBJ(ptNext[cos2])] = ptPrev[cos2];
/* put the first coincidence into the list of coincidences */
firstCoinc = cos2;
lastCoinc = cos2;
ptNext[lastCoinc] = INTOBJ_INT( 0 );
/* <cos1> is the representative of <cos2> and its own representative */
ptPrev[cos2] = INTOBJ_INT( cos1 );
/* while there are coincidences to handle */
while ( firstCoinc != 0 ) {
/* replace <firstCoinc> by its representative in the table */
cos1 = INT_INTOBJ( ptPrev[firstCoinc] ); cos2 = firstCoinc;
for ( i = 1; i <= LEN_PLIST(objTable); i++ ) {
gen = BASE_PTR_PLIST(ptTable[i]) - 1;
/* inv = ADDR_OBJ(ptTable[ ((i-1)^1)+1 ] ); */
inv = BASE_PTR_PLIST(ptTable[i + 2 * (i % 2) - 1]) - 1;
/* replace <cos2> by <cos1> in the column of <gen>^-1 */
c2 = INT_INTOBJ( gen[cos2] );
if ( c2 > 0 ) {
c1 = INT_INTOBJ( gen[cos1] );
/* if the other entry is empty copy it */
if ( c1 <= 0 ) {
gen[cos1] = INTOBJ_INT( c2 );
gen[cos2] = INTOBJ_INT( 0 );
inv[c2] = INTOBJ_INT( cos1 );
if ( dedlst == dedSize )
CompressDeductionList( );
dedgen[dedlst] = i;
dedcos[dedlst] = cos1;
dedlst++;
}
/* otherwise check for a coincidence */
else {
inv[c2] = INTOBJ_INT( 0 );
gen[cos2] = INTOBJ_INT( 0 );
if ( gen[cos1] <= INTOBJ_INT( 0 ) ) {
gen[cos1] = INTOBJ_INT( cos1 );
if ( dedlst == dedSize )
CompressDeductionList( );
dedgen[dedlst] = i;
dedcos[dedlst] = cos1;
dedlst++;
}
/* find the representative of <c1> */
while ( c1 != 1
&& INT_INTOBJ(ptNext[INT_INTOBJ(ptPrev[c1])]) != c1 )
{
c1 = INT_INTOBJ(ptPrev[c1]);
}
/* find the representative of <c2> */
while ( c2 != 1
&& INT_INTOBJ(ptNext[INT_INTOBJ(ptPrev[c2])]) != c2 )
{
c2 = INT_INTOBJ(ptPrev[c2]);
}
/* if the representatives differ we got a coincindence */
if ( c1 != c2 ) {
/* take the smaller one as new representative */
if ( c2 < c1 ) { c3 = c1; c1 = c2; c2 = c3; }
/* if we are removing an important coset update it */
if ( c2 == lastDef )
lastDef = INT_INTOBJ(ptPrev[lastDef ]);
if ( c2 == firstDef )
firstDef = INT_INTOBJ(ptPrev[firstDef]);
/* remove <c2> from the coset list */
ptNext[INT_INTOBJ(ptPrev[c2])] = ptNext[c2];
if ( ptNext[c2] != INTOBJ_INT( 0 ) )
ptPrev[INT_INTOBJ(ptNext[c2])] = ptPrev[c2];
/* append <c2> to the coincidence list */
ptNext[lastCoinc] = INTOBJ_INT( c2 );
lastCoinc = c2;
ptNext[lastCoinc] = INTOBJ_INT( 0 );
/* <c1> is the rep of <c2> and its own rep. */
ptPrev[c2] = INTOBJ_INT( c1 );
}
}
}
/* save minimal gap flags */
else if ( minGaps != 0 && c2 == -1 ) {
if ( gen[cos1] <= INTOBJ_INT( 0 ) ) {
gen[cos1] = INTOBJ_INT( -1 );
}
gen[cos2] = INTOBJ_INT( 0 );
}
}
/* move the replaced coset to the free list */
if ( firstFree == 0 ) {
firstFree = firstCoinc;
lastFree = firstCoinc;
}
else {
ptNext[lastFree] = INTOBJ_INT( firstCoinc );
lastFree = firstCoinc;
}
firstCoinc = INT_INTOBJ( ptNext[firstCoinc] );
ptNext[lastFree] = INTOBJ_INT( 0 );
nrdel++;
}
}
/****************************************************************************
**
*F FuncMakeConsequences( <self>, <list> ) find consqs of a coset definition
*/
Obj FuncMakeConsequences (
Obj self,
Obj list )
{
Obj hdSubs; /* */
Obj objRels; /* */
Obj * ptRel; /* pointer to the relator bag */
Obj * ptNums; /* pointer to this list */
Int lp; /* left pointer into relator */
Int lc; /* left coset to apply to */
Int rp; /* right pointer into relator */
Int rc; /* right coset to apply to */
Int tc; /* temporary coset */
Int i; /* loop variable */
Obj hdTmp; /* temporary variable */
/*T 1996/12/03 fceller this should be replaced by 'PlistConv' */
RequirePlainList(0, list);
objTable = ELM_PLIST( list, 1 );
objNext = ELM_PLIST( list, 2 );
objPrev = ELM_PLIST( list, 3 );
firstFree = INT_INTOBJ( ELM_PLIST( list, 6 ) );
lastFree = INT_INTOBJ( ELM_PLIST( list, 7 ) );
firstDef = INT_INTOBJ( ELM_PLIST( list, 8 ) );
lastDef = INT_INTOBJ( ELM_PLIST( list, 9 ) );
minGaps = INT_INTOBJ( ELM_PLIST( list, 12 ) );
nrdel = 0;
/* initialize the deduction queue */
dedprint = 0;
dedfst = 0;
dedlst = 1;
dedgen[ 0 ] = INT_INTOBJ( ELM_PLIST( list, 10 ) );
dedcos[ 0 ] = INT_INTOBJ( ELM_PLIST( list, 11 ) );
/* while the deduction queue is not empty */
while ( dedfst < dedlst ) {
/* skip the deduction, if it got irrelevant by a coincidence */
hdTmp = ELM_PLIST( objTable, dedgen[dedfst] );
hdTmp = ELM_PLIST( hdTmp, dedcos[dedfst] );
if ( INT_INTOBJ(hdTmp) <= 0 ) {
dedfst++;
continue;
}
/* while there are still subgroup generators apply them */
hdSubs = ELM_PLIST( list, 5 );
for ( i = LEN_LIST( hdSubs ); 1 <= i; i-- ) {
if ( ELM_PLIST( hdSubs, i ) != 0 ) {
objNums = ELM_PLIST( ELM_PLIST( hdSubs, i ), 1 );
ptNums = BASE_PTR_PLIST(objNums) - 1;
objRel = ELM_PLIST( ELM_PLIST( hdSubs, i ), 2 );
ptRel = BASE_PTR_PLIST(objRel) - 1;
lp = 2;
lc = 1;
rp = LEN_LIST( objRel ) - 1;
rc = 1;
/* scan as long as possible from the right to the left */
while ( lp<rp && 0 < (tc=INT_INTOBJ(ELM_PLIST(ptRel[rp],rc))) ) {
rc = tc; rp = rp - 2;
}
/* scan as long as possible from the left to the right */
while ( lp<rp && 0 < (tc=INT_INTOBJ(ELM_PLIST(ptRel[lp],lc))) ) {
lc = tc; lp = lp + 2;
}
/* if a coincidence or deduction has been found, handle it */
if ( lp == rp + 1 ) {
if ( INT_INTOBJ(ELM_PLIST(ptRel[lp],lc)) != rc ) {
if ( INT_INTOBJ( ELM_PLIST(ptRel[lp],lc) ) > 0 ) {
HandleCoinc( INT_INTOBJ( ELM_PLIST(ptRel[lp],lc) ), rc );
}
else if ( INT_INTOBJ( ELM_PLIST(ptRel[rp],rc) ) > 0 ) {
HandleCoinc( INT_INTOBJ( ELM_PLIST(ptRel[rp],rc) ), lc );
}
else {
SET_ELM_PLIST( ptRel[lp], lc, INTOBJ_INT( rc ) );
SET_ELM_PLIST( ptRel[rp], rc, INTOBJ_INT( lc ) );
if ( dedlst == dedSize )
CompressDeductionList();
dedgen[ dedlst ] = INT_INTOBJ( ptNums[lp] );
dedcos[ dedlst ] = lc;
dedlst++;
}
}
/* remove the completed subgroup generator */
SET_ELM_PLIST( hdSubs, i, 0 );
if ( i == LEN_PLIST(hdSubs) ) {
while ( 0 < i && ELM_PLIST(hdSubs,i) == 0 )
--i;
SET_LEN_PLIST( hdSubs, i );
i++;
}
}
/* if a minimal gap has been found, set a flag */
else if ( minGaps != 0 && lp == rp - 1 ) {
SET_ELM_PLIST( ptRel[lp], lc, INTOBJ_INT( -1 ) );
SET_ELM_PLIST( ptRel[rp], rc, INTOBJ_INT( -1 ) );
}
}
}
/* apply all relators that start with this generator */
objRels = ELM_PLIST( ELM_PLIST( list, 4 ), dedgen[dedfst] );
for ( i = 1; i <= LEN_LIST( objRels ); i++ ) {
objNums = ELM_PLIST( ELM_PLIST(objRels,i), 1 );
ptNums = BASE_PTR_PLIST(objNums) - 1;
objRel = ELM_PLIST( ELM_PLIST(objRels,i), 2 );
ptRel = BASE_PTR_PLIST(objRel) - 1;
lp = INT_INTOBJ( ELM_PLIST( ELM_PLIST(objRels,i), 3 ) );
lc = dedcos[ dedfst ];
rp = lp + INT_INTOBJ( ptRel[1] );
rc = lc;
/* scan as long as possible from the right to the left */
while ( lp<rp && 0 < (tc=INT_INTOBJ(ELM_PLIST(ptRel[rp],rc))) ) {
rc = tc; rp = rp - 2;
}
/* scan as long as possible from the left to the right */
while ( lp<rp && 0 < (tc=INT_INTOBJ(ELM_PLIST(ptRel[lp],lc))) ) {
lc = tc; lp = lp + 2;
}
/* if a coincidence or deduction has been found, handle it */
if ( lp == rp+1 && INT_INTOBJ(ELM_PLIST(ptRel[lp],lc)) != rc ) {
if ( INT_INTOBJ( ELM_PLIST(ptRel[lp],lc) ) > 0 ) {
HandleCoinc( INT_INTOBJ( ELM_PLIST(ptRel[lp],lc) ), rc );
}
else if ( INT_INTOBJ( ELM_PLIST(ptRel[rp],rc) ) > 0 ) {
HandleCoinc( INT_INTOBJ( ELM_PLIST(ptRel[rp],rc) ), lc );
}
else {
SET_ELM_PLIST( ptRel[lp], lc, INTOBJ_INT( rc ) );
SET_ELM_PLIST( ptRel[rp], rc, INTOBJ_INT( lc ) );
if ( dedlst == dedSize )
CompressDeductionList();
dedgen[ dedlst ] = INT_INTOBJ( ptNums[lp] );
dedcos[ dedlst ] = lc;
dedlst++;
}
}
/* if a minimal gap has been found, set a flag */
else if ( minGaps != 0 && lp == rp - 1 ) {
SET_ELM_PLIST( ptRel[lp], lc, INTOBJ_INT( -1 ) );
SET_ELM_PLIST( ptRel[rp], rc, INTOBJ_INT( -1 ) );
}
}
dedfst++;
}
SET_ELM_PLIST( list, 6, INTOBJ_INT( firstFree ) );
SET_ELM_PLIST( list, 7, INTOBJ_INT( lastFree ) );
SET_ELM_PLIST( list, 8, INTOBJ_INT( firstDef ) );
SET_ELM_PLIST( list, 9, INTOBJ_INT( lastDef ) );
/* clean out */
CleanOut();
return INTOBJ_INT( nrdel );
}
/****************************************************************************
**
*F FuncMakeConsequencesPres( <self>, <list> ) . . . . . . find consequences
**
** This is a special version of `FuncMakeConsequences' for the subgroup
** presentation routines.
*/
Obj FuncMakeConsequencesPres (
Obj self,
Obj list )
{
Obj objDefs1; /* handle of defs list part 1 */
Obj objDefs2; /* handle of defs list part 2 */
Obj objRels; /* */
Obj * ptRel; /* pointer to the relator bag */
Obj * ptNums; /* pointer to this list */
Int ndefs; /* number of defs done so far */
Int undefined; /* maximal of undefined entreis */
Int apply; /* num of next def to be applied */
Int ndefsMax; /* maximal number of definitons */
Int coset; /* coset involved in current def */
Int gen; /* gen involved in current def */
Int lp; /* left pointer into relator */
Int lc; /* left coset to apply to */
Int rp; /* right pointer into relator */
Int rc; /* right coset to apply to */
Int tc; /* temporary coset */
Int i; /* loop variable */
/*T 1996/12/03 fceller this should be replaced by 'PlistConv' */
RequirePlainList(0, list);
objTable = ELM_PLIST( list, 1 );
objDefs1 = ELM_PLIST( list, 2 );
objDefs2 = ELM_PLIST( list, 3 );
undefined = INT_INTOBJ( ELM_PLIST( list, 4 ) );
ndefs = INT_INTOBJ( ELM_PLIST( list, 5 ) );
/* check the definitions lists */
if ( ! ( IS_PLIST(objDefs1) && IS_PLIST(objDefs2) &&
LEN_PLIST(objDefs1) == LEN_PLIST(objDefs2) ) ) {
ErrorQuit( "inconsistent definitions lists", 0L, 0L );
return 0;
}
ndefsMax = LEN_PLIST(objDefs1);
apply = 1;
/* while the deduction queue is not worked off */
while ( apply <= ndefs ) {
/* apply all relators that start with this generator */
coset = INT_INTOBJ( ELM_PLIST( objDefs1, apply ) );
gen = INT_INTOBJ( ELM_PLIST( objDefs2, apply ) );
objRels = ELM_PLIST( ELM_PLIST( list, 6 ), gen );
for ( i = 1; i <= LEN_LIST( objRels ); i++ ) {
objNums = ELM_PLIST( ELM_PLIST(objRels,i), 1 );
ptNums = BASE_PTR_PLIST(objNums) - 1;
objRel = ELM_PLIST( ELM_PLIST(objRels,i), 2 );
ptRel = BASE_PTR_PLIST(objRel) - 1;
lp = INT_INTOBJ( ELM_PLIST( ELM_PLIST(objRels,i), 3 ) );
lc = coset;
rp = lp + INT_INTOBJ( ptRel[1] );
rc = lc;
/* scan as long as possible from the right to the left */
while ( lp<rp && 0 < (tc=INT_INTOBJ(ELM_PLIST(ptRel[rp],rc))) ) {
rc = tc; rp = rp - 2;
}
/* scan as long as possible from the left to the right */
while ( lp<rp && 0 < (tc=INT_INTOBJ(ELM_PLIST(ptRel[lp],lc))) ) {
lc = tc; lp = lp + 2;
}
/* if a deduction has been found, handle it */
if ( lp == rp+1 && INT_INTOBJ(ELM_PLIST(ptRel[rp],rc)) <= 0 ) {
SET_ELM_PLIST( ptRel[lp], lc, INTOBJ_INT( rc ) );
undefined--;
if ( INT_INTOBJ(ELM_PLIST(ptRel[rp],rc)) <= 0 ) {
SET_ELM_PLIST( ptRel[rp], rc, INTOBJ_INT( lc ) );
undefined--;
}
ndefs++;
if ( ndefs > ndefsMax ) {
ErrorQuit( "inconsistent definitions lists", 0L, 0L );
return 0;
}
SET_ELM_PLIST( objDefs1, ndefs, INTOBJ_INT( lc ) );
SET_ELM_PLIST( objDefs2, ndefs, ptNums[lp] );
if ( undefined == 0 ) {
return INTOBJ_INT( 0 );
}
}
}
apply++;
}
/* clean out */
CleanOut();
return INTOBJ_INT( undefined );
}
/****************************************************************************
**
*F FuncStandardizeTableC(<self>,<table>,<stan>) . . . . . . standardize CT
**
** This is the kernel routine for standardizing a coset table. It is called
** by the GAP routine 'StandardizeTable'. The user should not call the
** kernel routine but only the GAP routine.
**
** If <stan> = 1 the table is standardized using the (old) semilenlex
** standard.
** If not <stan> = 1 the table is standardized using the (new) lenlex
** standard (this is the default).
*/
Obj FuncStandardizeTableC (
Obj self,
Obj table,
Obj stan )
{
Obj * ptTable; /* pointer to table */
UInt nrgen; /* number of rows of the table / 2 */
Obj * g; /* one generator list from table */
Obj * h; /* generator list */
Obj * i; /* and inverse */
UInt acos; /* actual coset */
UInt lcos; /* last seen coset */
UInt mcos; /* */
UInt c1, c2; /* coset temporaries */
Obj tmp; /* temporary for swap */
UInt j, k, nloop; /* loop variables */
RequirePlainList(0, table);
/* get the arguments */
objTable = table;
ptTable = BASE_PTR_PLIST(objTable) - 1;
nrgen = LEN_PLIST(objTable) / 2;
for ( j = 1; j <= nrgen*2; j++ ) {
if ( ! IS_PLIST(ptTable[j]) ) {
ErrorQuit(
"<table>[%d] must be a plain list (not a %s)",
(Int)j,
(Int)TNAM_OBJ(ptTable[j]) );
return 0;
}
}
if ( IS_INTOBJ(stan) && INT_INTOBJ(stan) == 1 ) {
/* use semilenlex standard */
nloop = nrgen;
}
else {
/* use lenlex standard */
nloop = nrgen*2;
}
/* run over all cosets */
acos = 1;
lcos = 1;
while ( acos <= lcos ) {
/* scan through all columns of acos */
for ( j = 1; j <= nloop; j++ ) {
k = ( nloop == nrgen ) ? 2*j - 1 : j;
g = BASE_PTR_PLIST(ptTable[k]) - 1;
/* if we haven't seen this coset yet */
if ( lcos+1 < INT_INTOBJ( g[acos] ) ) {
/* swap rows lcos and g[acos] */
lcos = lcos + 1;
mcos = INT_INTOBJ( g[acos] );
for ( k = 1; k <= nrgen; k++ ) {
h = BASE_PTR_PLIST(ptTable[2 * k - 1]) - 1;
i = BASE_PTR_PLIST(ptTable[2 * k]) - 1;
c1 = INT_INTOBJ( h[lcos] );
c2 = INT_INTOBJ( h[mcos] );
if ( c1 != 0 ) i[c1] = INTOBJ_INT( mcos );
if ( c2 != 0 ) i[c2] = INTOBJ_INT( lcos );
tmp = h[lcos];
h[lcos] = h[mcos];
h[mcos] = tmp;
if ( i != h ) {
c1 = INT_INTOBJ( i[lcos] );
c2 = INT_INTOBJ( i[mcos] );
if ( c1 != 0 ) h[c1] = INTOBJ_INT( mcos );
if ( c2 != 0 ) h[c2] = INTOBJ_INT( lcos );
tmp = i[lcos];
i[lcos] = i[mcos];
i[mcos] = tmp;
}
}
}
/* if this is already the next only bump lcos */
else if ( lcos < INT_INTOBJ( g[acos] ) ) {
lcos = lcos + 1;
}
}
acos = acos + 1;
}
/* shrink the table */
for ( j = 1; j <= nrgen; j++ ) {
SET_LEN_PLIST( ptTable[2*j-1], lcos );
SET_LEN_PLIST( ptTable[2*j ], lcos );
}
/* clean out */
CleanOut();
/* return void */
return 0;
}
/****************************************************************************
**
*F InitializeCosetFactorWord() . . . . . . . initialize a coset factor word
**
** 'InitializeCosetFactorWord' initializes a word in which a new coset
** factor is to be built up.
**
** 'wordList', 'treeType', 'objTree2', and 'treeWordLength' are assumed to
** be known as static variables.
*/
static void InitializeCosetFactorWord ( void )
{
Obj * ptWord; /* pointer to the word */
Int i; /* integer variable */
/* handle the one generator MTC case */
if ( treeType == 1 ) {
objWordValue = INTOBJ_INT(0);
}
/* handle the abelianized case */
else if ( treeType == 0 ) {
ptWord = BASE_PTR_PLIST(objTree2) - 1;
for ( i = 1; i <= treeWordLength; i++ ) {
ptWord[i] = INTOBJ_INT(0);
}
}
/* handle the general case */
else {
wordList[0] = 0;
}
}
/****************************************************************************
**
*F TreeEntryC() . . . . . . . . . . . . returns a tree entry for a rep word
**
** 'TreeEntryC' determines a tree entry which represents the word given in
** 'wordList', if it finds any, or it defines a new proper tree entry, and
** then returns it.
**
** Warning: It is assumed, but not checked, that the given word is freely
** reduced and that it does not contain zeros, and that the tree type is
** either 0 or 2.
**
** 'wordList' is assumed to be known as static variable.
**
*/
static Int TreeEntryC ( void )
{
Obj * ptTree1; /* ptr to first tree component */
Obj * ptTree2; /* ptr to second tree component */
Obj * ptWord; /* ptr to given word */
Obj * ptFac; /* ptr to old word */
Obj * ptNew; /* ptr to new word */
Obj objNew; /* handle of new word */
Int treesize; /* tree size */
Int numgens; /* tree length */
Int leng; /* word length */
Int sign; /* sign flag */
Int i, k; /* integer variables */
Int gen; /* generator value */
Int u, u1, u2; /* generator values */
Int v, v1, v2; /* generator values */
Int t1, t2; /* generator values */
Int uabs, vabs; /* generator values */
/* Get the tree components */
ptTree1 = BASE_PTR_PLIST(objTree1) - 1;
ptTree2 = BASE_PTR_PLIST(objTree2) - 1;
treesize = LEN_PLIST(objTree1);
numgens = INT_INTOBJ( ELM_PLIST( objTree, 3 ) );
/* handle the abelianized case */
if ( treeType == 0 )
{
ptWord = BASE_PTR_PLIST(objTree2) - 1;
for ( leng = treeWordLength; leng >= 1; leng-- ) {
if ( ptWord[leng] != INTOBJ_INT(0) ) {
break;
}
}
if ( leng == 0 ) {
return 0;
}
for ( k = 1; k <= leng; k++ ) {
if ( ptWord[k] != INTOBJ_INT(0) ) {
break;
}
}
sign = 1;
if ( INT_INTOBJ( ptWord[k] ) < 0 ) {
/* invert the word */
sign = - 1;
for ( i = k; i <= leng; i++ ) {
ptWord[i] = INTOBJ_INT( - INT_INTOBJ( ptWord[i] ) );
}
}
for ( k = 1; k <= numgens; k++ ) {
ptFac = BASE_PTR_PLIST(ptTree1[k]) - 1;
if ( LEN_PLIST(ptTree1[k]) == leng ) {
for ( i = 1; i <= leng; i++ ) {
if ( ptFac[i] != ptWord[i] ) {
break;
}
}
if ( i > leng ) {
return sign * k;
}
}
}
/* extend the tree */
numgens++;
if ( treesize < numgens ) {
treesize = 2 * treesize;
GROW_PLIST( objTree1, treesize );
CHANGED_BAG(objTree);
}
objNew = NEW_PLIST( T_PLIST, leng );
SET_LEN_PLIST( objNew, leng );
SET_ELM_PLIST( objTree, 3, INTOBJ_INT(numgens) );
SET_LEN_PLIST( objTree1, treesize );
SET_ELM_PLIST( objTree1, numgens, objNew );
CHANGED_BAG(objTree1);
/* copy the word to the new bag */
ptWord = BASE_PTR_PLIST(objTree2) - 1;
ptNew = BASE_PTR_PLIST(objNew) - 1;
while ( leng > 0 ) {
ptNew[leng] = ptWord[leng];
leng--;
}
return sign * numgens;
}
/* handle the general case */
/* Get the length of the word */
leng = wordList[0];
gen = ( leng == 0 ) ? 0 : wordList[1];
u2 = 0; /* just to shut up gcc */
for ( i = 2; i <= leng; i++ ) {
u = gen;
v = wordList[i];
while ( i ) {
/* First handle the trivial cases */
if ( u == 0 || v == 0 || ( u + v ) == 0 ) {
gen = u + v;
break;
}
/* Cancel out factors, if possible */
u1 = INT_INTOBJ( ptTree1[ (u > 0) ? u : -u ] );
if ( u1 != 0 ) {
if ( u > 0 ) {
u2 = INT_INTOBJ( ptTree2[u] );
}
else {
u2 = - u1;
u1 = - INT_INTOBJ( ptTree2[-u] );
}
if ( u2 == -v ) {
gen = u1;
break;
}
}
v1 = INT_INTOBJ( ptTree1[ (v > 0) ? v : -v ] );
if ( v1 != 0 ) {
if ( v > 0 ) {
v2 = INT_INTOBJ( ptTree2[v] );
}
else {
v2 = - v1;
v1 = - INT_INTOBJ( ptTree2[-v] );
}
if ( v1 == -u ) {
gen = v2;
break;
}
if ( u1 != 0 && v1 == - u2 ) {
u = u1;
v = v2;
continue;
}
}
/* Check if there is already a tree entry [u,v] or [-v,-u] */
if ( u < -v ) {
t1 = u;
t2 = v;
}
else {
t1 = -v;
t2 = -u;
}
uabs = ( u > 0 ) ? u : -u;
vabs = ( v > 0 ) ? v : -v;
k = ( uabs > vabs ) ? uabs : vabs;
for ( k++; k <= numgens; k++ ) {
if ( INT_INTOBJ(ptTree1[k]) == t1 &&
INT_INTOBJ(ptTree2[k]) == t2 )
{
break;
}
}
/* Extend the tree, if necessary */
if ( k > numgens ) {
numgens++;
if ( treesize < numgens ) {
treesize = 2 * treesize;
GROW_PLIST( objTree1, treesize );
GROW_PLIST( objTree2, treesize );
ptTree1 = BASE_PTR_PLIST(objTree1) - 1;
ptTree2 = BASE_PTR_PLIST(objTree2) - 1;
SET_LEN_PLIST( objTree1, treesize );
SET_LEN_PLIST( objTree2, treesize );