forked from fricas/fricas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpresent.spad
1837 lines (1691 loc) · 74.3 KB
/
gpresent.spad
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
)if false
\documentclass{article}
\usepackage{axiom}
\usepackage{url}
\begin{document}
\title{Group Presentations}
\author{Martin J Baker}
\maketitle
\begin{abstract}
This file implements group structures related to algebraic topology,
specifically its homotopy and homology.
There are two such structures in this file:
\begin{itemize}
\item GroupPresentation - Defines a group by its generators and
relations. Used to hold fundamental group (homotopy).
\item Homology - Intended to hold homology which is calculated using
integer Smith normal form. This is an abelian group.
\end{itemize}
I have put a fuller explanation of this code here:
\url{http://www.euclideanspace.com/prog/scratchpad/mycode/discrete/finiteGroup/presentation/}
\end{abstract}
\section{Introduction}
Group represented by its generators and relations.
Here we use it to hold homotopy group such as fundamental group.
for more documentation see:
\url{http://www.euclideanspace.com/prog/scratchpad/mycode/topology/}
Representation holds the group as a set of generators and a set of
relations
Each generator is a NNI
Each relation is a list of indexes to generators. Negative values
indicate the inverse of the generator. So if '1' represents the
generator 'A' then '-1' represents its inverse 'A^-1'.
Note that the use of negative indices to represent the inverse does
not imply an abelian group. This is just a convenient way to code
the representation and, in general, the group is not necessarily
abelian.
The notation uses the following conventions.
\begin{itemize}
\item If index is positive it represents a generator shown as an
alphabetic digit followed by number if required.
\item If index is zero it represents identity shown as 'e'.
\item If index is negative it represents an inverse generator.
The notation uses '-' to indicate an inverse generator (I know this is
an abuse of notation, because the group is not necessarily Abelian).
\end{itemize}
This convention is not ambiguous and I don't like the alternatives,
'-1' exponent uses too much space and upper case alpha for inverses
may not be clear to people who don't read documentation.
\section{Homotopy Group}
The homotopy group is finitely presented by generators and relations.
This representation of a group is not, in general, algorithmically
computable into other representations of a group.
We can therefore compute 'a' (not 'the') homotopy group for a given
simplicial complex. We may also be able to apply some simplifications
to this group. However, in the general case, we cannot determine if
this is the simplest representation or determine if two such groups
are isomophic (their corresponding simplicial complexes are
homeomorphic).
Despite these fundamental limits on what is theoretically possible
I still believe it is worthwhile to have the capability to generate
'a' homotopy group for a given structure.
\section{Conversion between Finitely Presented and Permutation Groups}
In FriCAS the main group functionality is in PermutationGroup so it
is useful to be able to convert to and from it. For conversions to
PermutationGroup we use a well known algorithm called the
Todd-Coxeter algorithm.
If you wish to see how the algorithm works (or does not work) try
calling the function, with trace set to 'true', like this:
\begin{verbatim}
(7) -> d3 := dihedralGroup(3)$GroupPresentation
(7) <a b | a*a*a, b*b, a*b*a*b>
Type: GroupPresentation
(8) -> toPermutationIfCan(d3,true)
addPoint: cannot deduce more so adding a point
adding:1 at row:1
+2 2 2+ +0 0+ +2 0 2 0+
relatorTables=[| |,| |,| |]
+0 0 0+ +0 0+ +0 0 0 0+
addPoint: cannot deduce more so adding a point
adding:2 at row:1
+2 2 2+ +3 3+ +2 3 2 3+
| | | | | |
relatorTables=[|0 0 0|,|0 0|,|0 0 0 0|]
| | | | | |
+0 0 0+ +0 0+ +0 0 0 0+
inferFromRelations found a gap of 1 so deduction made
gap is in relator table:[2,2]
distance from start:1 from end:0
row at start:1
row to change:3 new value:1
generator index=2 invm=false
forwardSequence:[1,3] backwardSequence:[1,0]
inferFromRelations genIn=2 gb=1
+2 2 2+ +3 3+ +2 3 2 3+
| | | | | |
relatorTables=[|0 0 0|,|0 0|,|0 0 0 0|]
| | | | | |
+0 0 0+ +1 1+ +0 1 0 1+
addPoint: cannot deduce more so adding a point
adding:1 at row:2
+2 2 2+ +3 3+ +2 3 2 3+
| | | | | |
|4 4 4| |0 0| |4 0 4 0|
relatorTables=[| |,| |,| |]
|0 0 0| |1 1| |0 1 0 1|
| | | | | |
+0 0 0+ +0 0+ +0 0 0 0+
inferFromRelations found a gap of 1 so deduction made
gap is in relator table:[1,1,1]
distance from start:2 from end:0
row at start:1
row to change:4 new value:1
generator index=1 invm=false
forwardSequence:[1,2,4] backwardSequence:[1,0,0]
inferFromRelations genIn=1 gb=2
+2 2 2+ +3 3+ +2 3 2 3+
| | | | | |
|4 4 4| |0 0| |4 0 4 0|
relatorTables=[| |,| |,| |]
|0 0 0| |1 1| |0 1 0 1|
| | | | | |
+1 1 1+ +0 0+ +1 0 1 0+
addPoint: cannot deduce more so adding a point
adding:2 at row:2
+2 2 2+ +3 3+ +2 3 2 3+
| | | | | |
|4 4 4| |5 5| |4 5 4 5|
| | | | | |
relatorTables=[|0 0 0|,|1 1|,|0 1 0 1|]
| | | | | |
|1 1 1| |0 0| |1 0 1 0|
| | | | | |
+0 0 0+ +0 0+ +0 0 0 0+
inferFromRelations found a gap of 1 so deduction made
gap is in relator table:[2,2]
distance from start:1 from end:0
row at start:2
row to change:5 new value:2
generator index=2 invm=false
forwardSequence:[2,5] backwardSequence:[2,0]
inferFromRelations genIn=2 gb=1
+2 2 2+ +3 3+ +2 3 2 3+
| | | | | |
|4 4 4| |5 5| |4 5 4 5|
| | | | | |
relatorTables=[|0 0 0|,|1 1|,|0 1 0 1|]
| | | | | |
|1 1 1| |0 0| |1 0 1 0|
| | | | | |
+0 0 0+ +2 2+ +0 2 0 2+
inferFromRelations found a gap of 1 so deduction made
gap is in relator table:[1,2,1,2]
distance from start:2 from end:1
row at start:1
row to change:5 new value:3
generator index=1 invm=false
forwardSequence:[1,2,5,0] backwardSequence:[1,3,0,0]
inferFromRelations genIn=1 gb=2
+2 2 2+ +3 3+ +2 3 2 3+
| | | | | |
|4 4 4| |5 5| |4 5 4 5|
| | | | | |
relatorTables=[|0 0 0|,|1 1|,|0 1 0 1|]
| | | | | |
|1 1 1| |0 0| |1 0 1 0|
| | | | | |
+3 3 3+ +2 2+ +3 2 3 2+
addPoint: cannot deduce more so adding a point
adding:1 at row:3
+2 2 2+ +3 3+ +2 3 2 3+
| | | | | |
|4 4 4| |5 5| |4 5 4 5|
| | | | | |
|6 6 6| |1 1| |6 1 6 1|
relatorTables=[| |,| |,| |]
|1 1 1| |0 0| |1 0 1 0|
| | | | | |
|3 3 3| |2 2| |3 2 3 2|
| | | | | |
+0 0 0+ +0 0+ +0 0 0 0+
inferFromRelations found a gap of 1 so deduction made
gap is in relator table:[1,1,1]
distance from start:1 from end:1
row at start:3
row to change:6 new value:5
generator index=1 invm=false
forwardSequence:[3,6,0] backwardSequence:[3,5,0]
inferFromRelations genIn=1 gb=1
+2 2 2+ +3 3+ +2 3 2 3+
| | | | | |
|4 4 4| |5 5| |4 5 4 5|
| | | | | |
|6 6 6| |1 1| |6 1 6 1|
relatorTables=[| |,| |,| |]
|1 1 1| |0 0| |1 0 1 0|
| | | | | |
|3 3 3| |2 2| |3 2 3 2|
| | | | | |
+5 5 5+ +0 0+ +5 0 5 0+
inferFromRelations found a gap of 1 so deduction made
gap is in relator table:[1,2,1,2]
distance from start:1 from end:2
row at start:2
row to change:4 new value:6
generator index=2 invm=false
forwardSequence:[2,4,0,0] backwardSequence:[2,5,6,0]
inferFromRelations genIn=2 gb=1
+2 2 2+ +3 3+ +2 3 2 3+
| | | | | |
|4 4 4| |5 5| |4 5 4 5|
| | | | | |
|6 6 6| |1 1| |6 1 6 1|
relatorTables=[| |,| |,| |]
|1 1 1| |6 6| |1 6 1 6|
| | | | | |
|3 3 3| |2 2| |3 2 3 2|
| | | | | |
+5 5 5+ +0 0+ +5 0 5 0+
inferFromRelations found a gap of 1 so deduction made
gap is in relator table:[2,2]
distance from start:1 from end:0
row at start:4
row to change:6 new value:4
generator index=2 invm=false
forwardSequence:[4,6] backwardSequence:[4,0]
inferFromRelations genIn=2 gb=1
+2 2 2+ +3 3+ +2 3 2 3+
| | | | | |
|4 4 4| |5 5| |4 5 4 5|
| | | | | |
|6 6 6| |1 1| |6 1 6 1|
relatorTables=[| |,| |,| |]
|1 1 1| |6 6| |1 6 1 6|
| | | | | |
|3 3 3| |2 2| |3 2 3 2|
| | | | | |
+5 5 5+ +4 4+ +5 4 5 4+
(8) <(1 2 4)(3 6 5),(1 3)(2 5)(4 6)>
Type: Union(PermutationGroup(Integer),...)
\end{verbatim}
This will display the relatorTables at each stage and the deductions
being made from the tables.
The conversions in both directions can be improved by implementing
better simplifications but since there is no canonical form the
simplifications can never be perfect. The Todd-Coxeter does not yet
detect and remove 'coincidences', that is, duplicated points. So
this in the next improvement that needs to be made.
\section{Direct Product of Groups}
If G = < Sg | Rg > and H = < Sh | Rh >
Then G*H = < Sg,Sh | Rg,Rh,Rp >
where:
G*H is the direct product of G and H.
Rp is a set of relations specifying that each element of Sg
anti-commutes with each element of Sh.
See:
\url{https://en.wikipedia.org/wiki/Direct_product_of_groups}
This assumes that Sg and Sh are disjoint. In order to assure this the
generators will be renumbered before doing the product.
\section{Quotients}
We can generate a quotient by removing a generator (more precisely
adding relation equating this generator to neutral element) or
more generaly by adding a relation.
A quotient is an example of a surjective mapping
(epimorphism) on the group. It is easy to work with functions
between finitely presented groups, all we have to do is map
the generators and check that the relations still equal 1.
\section{Simplify Finitely Presented Groups}
There may not be a simplest form but it is possible to do some
simplifications.
In order to try to simplify a finitely generated presentation
to produce simpler but isomorphic groups we can apply certain
transformations or automorphisms (isomorphisms of the group
back to itself).
For example:
\begin{itemize}
\item Remove all zero terms in relations.
\item If a relation consists of a single generator then remove
that generator.
\item If a relation consists of a pair of generators then make
the second generator the inverse of the first.
\item If a generator is adjacent to its inverse then cancel
them out.
\item Remove duplicate relations.
\item Substitute one relation in another.
\end{itemize}
These automorphisms were studied and categorised by Tietze
and Nielsen.
\subsection{Tietze Transformations}
\begin{table}[]
\label{Tietze transformations are of 4 kinds}
\begin{tabular}{lll}
\ Kind \ Examples \\
T1 \ Add a relation \ < A | A^3 > -> < A | A^3 , A^6 > \\
T2 \ Remove a relation \ for example we can reverse the above
< A | A^3 , A^6> -> < A | A^3> \\
T3 \ Add a generator \ < A | A^3 > -> <A , B | A^3, B = A^2 > \\
T4 \ Remove a generator \ for example we can reverse the above
<A , B | A^3, B = A^2 > -> < A | A^3 > \\
\end{tabular}
\end{table}
We are interested in simplifying so we are mostly interested
in T2 and T4.
\subsection{T2}
T2 allows us to remove a relation but not generators. This
happens when a relation is redundant, that is it contains no
additional information than is already contained in the
other relations.
This happens, for example, where:
One relation is a multiple of another - In this case we can
remove the highest multiple but not the lowest.
One relation is the inverse of another - In this case we can
remove any one, but not both.
We can also simplify relations, for example, where an element
and its inverse are next to each other they can be
canceled out and removed.
\subsection{T4}
T4 allows us to remove a generator and corresponding relations.
\subsection{Nielsen Transformations}
The following transformations on a finitely generated free group
produce isomorphic groups.
\begin{itemize}
\item Switch A and B
\item Cyclically permute A, B, ... to B, ..., A.
\item Replace A with A^(-1)
\item Replace A with A*B
\item Substitute one relation in another
\end{itemize}
Most of these rules are self explanatory except substitute which
does the following:
If a generator is contained in exactly 2 relations then we may be
able to substitute one relation in another and remove that generator.
If, in at least one of these relations, the generator is contained
only once then we can move it to one side of the equation and
substitute it in the other relation.
This is done by a local function TTSubstitute.
Here is an example of its use from SimplicialComplex without
substitution:
\begin{verbatim}
(1) -> tS := torusSurface()$SimplicialComplexFactory
(1)
(1,2,3)
(2,3,5)
(2,4,5)
(2,4,7)
(1,2,6)
(2,6,7)
(3,4,6)
(3,5,6)
(3,4,7)
(1,3,7)
(1,4,5)
(1,4,6)
(5,6,7)
(1,5,7)
Type: FiniteSimplicialComplex(VertexSetAbstract)
(2) -> fundamentalGroup(tS)
(2) <o t w | o*w*t, o*t*w>
Type: GroupPresentation
\end{verbatim}
This needs to be further simplified,
<o t w | -o = w*t, -o = t*w>
Substituting for -o we have:
w*t = t*w
That is, two edges that commute.
Moving everything to one side of the equation we have:
t * w * -t * -w
\begin{verbatim}
(2) -> fundamentalGroup(tS)
(2) <s v | -s*v*s*-v>
Type: GroupPresentation
\end{verbatim}
This is the same as above with v=w and s= -t.
\section{Testing and Validating this Code}
Some functions are very difficult to test, for example in
the SimplicialComplex code here:
\url{http://www.euclideanspace.com/prog/scratchpad/mycode/topology/simplex/}
and here:
\url{http://www.euclideanspace.com/prog/scratchpad/mycode/topology/delta/}
there are functions such as fundamentalGroup which output a
GroupPresentation. The reason for the difficulty is that they
do not have a canonical form, that is, there may
be more than one correct result and none of them are better
than the others and there is no general algorithm for testing
if they are equal.
So some change to the code may change the result but the result
may be just as correct as the other result. So testing that
fundamentalGroup generates a given output for a given input
is not a useful test for correctness.
I think that all we can do in this situation is to test
fundamentalGroup with very simple inputs such as a
topological sphere. This should always produce an empty
presentation.
)endif
)abbrev domain GROUPP GroupPresentation
++ Author: Martin Baker
++ Description:
++ Group represented by its generators and relations.
++ Here we use it to hold homotopy group such as fundamental group.
++ for more documentation see:
++ http://www.euclideanspace.com/prog/scratchpad/mycode/discrete/finiteGroup/presentation/
++ Date Created: Jan 2016
++ Basic Operations:
++ Related packages:
++ Related categories:
++ Related Domains: PermutationGroup
++ Also See:
++ AMS Classifications:
++ Keywords:
++ Examples:
++ References:
GroupPresentation() : Exports == Impl where
NNI ==> NonNegativeInteger
PI ==> PositiveInteger
x<<y ==> hconcat(x::OutputForm, y::OutputForm)
GENMAP ==> List(Record(OldGen : NNI, NewGen : NNI))
Exports ==> SetCategory() with
groupPresentation : (v : List(NNI), rels1 : List(List(Integer))) -> %
++ construct from generators and relations
groupPresentation : (v : List(NNI)) -> %
++ construct free group with generators but no relations
groupPresentation : () -> %
++ construct trivial group with no generators or relations
simplify : (s : %) -> %
++ simplify(s) tries to simplify s.
++ There may not be a simplest form but it is possible to
++ do some simplifications as follows:
++ 1. Remove all zero terms in relations.
++ 2. If a relation consists of a single generator then remove
++ that generator.
++ 3. If a relation consists of a pair of generators then make the
++ second generator the inverse of the first.
++ 4. If a generator is adjacent to its inverse then cancel them out.
++ 5. Remove duplicate relations.
++ 6. Substitute one relation in another.
simplify : (s : %, trace : Boolean) -> %
++ simplify with option to trace
refactor : (a : %) -> %
++ actual value of generators is not important, it is only important that
++ they correspond to the appropriate entries in the relations.
++ Therefore we can refactor the generators without changing the
++ group represented.
quotient : (a : %, remgen : List(NNI)) -> %
++ take quotient by removing generators specified by remgen
quotient : (a : %, addrel : List(List(Integer))) -> %
++ take quotient by adding relations specified by addrel
directProduct : (a : %, b : %) -> %
++ directProduct of two groups
cyclicGroup : (n : PI) -> %
++ cyclicGroup(n) constructs the cyclic group of order n acting
++ on the integers 1, ..., n.
dihedralGroup : (n : PI) -> %
++ dihedralGroup(n) constructs the dihedral group of order 2n
++ acting on integers 1, ..., N.
symmetricGroup : (n : PI) -> %
++ symmetricGroup(n) constructs the symmetric group of order n-1.
++ Note: generates all possible relations may not be minimal.
toPermutationIfCan : (a : %) -> Union(PermutationGroup Integer, "failed")
++ convert to permutation group return "failed" for infinite groups.
++ For more information about the algorithm see:
++ \url{http://www.euclideanspace.com/prog/scratchpad/mycode/discrete/finiteGroup/pres2perm/}
toPermutationIfCan : (a : %, trace : Boolean)
-> Union(PermutationGroup Integer, "failed")
++ convert to permutation group return "failed" for infinite groups.
++ For more information about the algorithm see:
++ \url{http://www.euclideanspace.com/prog/scratchpad/mycode/discrete/finiteGroup/pres2perm/}
toPermutationIfCan : (a : %, sg : List(List(Integer)), trace : Boolean)
-> Union(PermutationGroup Integer, "failed")
++ toPermutationIfCan(a, sg, trace) returns permutation
++ representation of a on cosets of subgroup generate by sg
++ or "failed" if computation exceed resource limit.
++ trace activates debugging printouts.
Impl ==> add
-- Representation holds the group as a set of generators and a set of
-- relations.
-- Each generator is a NNI
-- Each relation is a list of indexes to generators.
-- if index is positive it represents a generator output as an
-- alphabetic digit followed by number if required.
-- if index is zero it represents identity output as 'e'.
-- if index is negative it represents an inverse generator.
Rep := Record(gens : PrimitiveArray(NNI), rels : List(List(Integer)))
-- construct from generators and relations
groupPresentation(gens1 : List(NNI), rels1 : List(List(Integer))) : % ==
-- print(" groupPresentation construct (" << gens1 << ", "
-- << rels1<< ")")
g := construct(gens1)$PrimitiveArray(NNI)
--print("groupPresentation constuct : " << rels1)
-- remove empty relations since this simplifies equality function
[g, [r for r in rels1 | not(empty?(r))]]
-- construct free group with generators but no relations
groupPresentation(gens1 : List(NNI)) : % ==
-- print(" groupPresentation construct (" << gens1 << ", "
-- << rels1<< ")")
g := construct(gens1)$PrimitiveArray(NNI)
rels2 := []$List(List(Integer))
[g, rels2]
-- construct trivial group with no generators or relations
groupPresentation() : % ==
gens1 := []$List(NNI)
rels1 := []$List(List(Integer))
groupPresentation(gens1, rels1)
-- Local function used by refactor to map a given generator in a relation.
mapGen(a : Integer, ms : GENMAP) : Integer ==
for m in ms repeat
if abs(a) = m.OldGen then return m.NewGen
if abs(a) = -m.OldGen then return -m.NewGen
error concat(["cant map ", string(a), " in refactor"])
a
-- Actual value of generators is not important, it is only important that
-- they correspond to the appropriate entries in the relations.
-- Therefore we can refactor the generators (to be ascending integers
-- starting as 1) without changing the group represented.
refactor(a : %) : % ==
-- first generate a map from existing generators to new generators
gms : GENMAP := empty()$GENMAP
for g in entries(a.gens) for gn in 1..(#(a.gens)) repeat
gm : Record(OldGen : NNI, NewGen : NNI) := [g, gn]
gms := concat(gms, gm)
-- now use this map to change elements of relations
rels1 := []$List(List(Integer))
for rel in a.rels repeat
newRel : List(Integer) := empty()$List(Integer)
for ele in rel repeat
newEle : Integer := mapGen(ele, gms)
newRel := concat(newRel, newEle)
rels1 := concat(rels1, newRel)
gens1 : List(NNI) := [gn for gn in 1..(#(a.gens))]
groupPresentation(gens1, rels1)
-- Isomorphism is the most useful level of 'equality' for
-- groups but unfortunately this is not computable in
-- the general case for presentations.
-- Although exact equality is less useful it is still useful to
-- compare very simple presentations in the validation code which
-- is useful to give some level of confidence that the
-- correct presentation was generated.
-- TODO result can be dependent on initial generator order, for
-- example <a, b | a*a, b*b*b> = <b, a | a*a, b*b*b> would be false
-- should really check all permutations of generators and return
-- true if any of them gives equality.
_=(a : %, b : %) : Boolean ==
ar : % := refactor(a)
br : % := refactor(b)
ags : List(NNI) := entries(ar.gens)
bgs : List(NNI) := entries(br.gens)
if set(ags)$Set(NNI) ~= set(bgs)$Set(NNI) then return false
ars : List(List(Integer)) := entries(ar.rels)
brs : List(List(Integer)) := entries(br.rels)
set(ars)$Set(List(Integer)) = set(brs)$Set(List(Integer))
-- Display generators as alphabetic digits
-- Local function used by coerce to OutputForm and other functions.
-- if i2 is positive it represents a generator shown as an
-- alphabetic digit followed by number if required.
-- if i2 is zero it represents identity shown as 'e'.
-- if i2 is negative it represents an inverse generator.
-- The notation uses '-' to indicate an inverse generator (I know
-- this is an abuse of notation, because the group is not
-- necessarily Abelian). I don't like the alternatives,
-- '-1' exponent uses too much space and upper case for inverses
-- may not be clear to people who don't read documentation.
outputGen(i2 : Integer) : OutputForm ==
(suffix, i) := divide(abs(i2), 25)
letters : String := "eabcdfghijklmnopqrstuvwxyz"
n : OutputForm := (letters(i + 1))::OutputForm
-- print(" groupPresentation outputGen(" << i2 <<
-- ") gives " << n)
if suffix > 0 then n := hconcat(n, outputForm(suffix + 1))
if i2 < 0 then return hconcat(message"-", n)
n
-- display a relation using alphabetic digits
outputRel(r : List(Integer)) : OutputForm ==
eleout : OutputForm := message("")
seperator : OutputForm := message(" ")
for ele in r repeat
newterm : OutputForm := outputGen(ele)
eleout := hconcat([eleout, seperator, newterm])$OutputForm
seperator := message("*")
eleout
-- display a list of relations using alphabetic digits
outputRelList(i2 : List(List(Integer))) : OutputForm ==
rels1 : List(OutputForm) := []$List(OutputForm)
for r in i2 repeat
rels1 := concat(rels1,outputRel(r))
if #rels1 > 0 then return commaSeparate(rels1)
message(" ")
-- display a list of generators using alphabetic digits
outputGenList(ps : List(NNI)) : OutputForm ==
gens1 : List(OutputForm) := []$List(OutputForm)
for p in ps repeat
gens1 := concat(gens1, outputGen(p::Integer))
if #gens1 > 0 then return blankSeparate(gens1)
message(" ")
-- local function to return indexes to each relation containing a given
-- generator.
indexesOfRelUsingGen(s : %, gen : NNI) : List(NNI) ==
res : List(NNI) := []
r : List(List(Integer)) := s.rels
for rel in r for reln in 1..(#r) repeat
if member?(gen::Integer,rel) then res := concat(res,reln)
if gen > 0 and member?(-(gen::Integer),rel)
then res := concat(res,reln)
res
-- local function to remove generator 'val' from generators
removeGen(gens1 : PrimitiveArray(NNI), val : NNI) : PrimitiveArray(NNI) ==
remove(val, gens1)
-- local function to remove generator 'val' from relations
removeGen2(rels1 : List(List(Integer)), val : NNI) : List(List(Integer)) ==
[remove(-val, remove(val::Integer, rel)) for rel in rels1]
-- local function to replace generator 'val1' with 'val2'
-- in relations
replaceGen(rels1 : List(List(Integer)), val1 : NNI, val2 : Integer
) : List(List(Integer)) ==
--print(" groupPresentation replaceGen=" << rels1 << _
-- " val1=" << val1 << " val2=" << val2)
rels2 := []$List(List(Integer))
for rel in rels1 repeat
rel2 := []$List(Integer)
for ele in rel repeat
e : Integer := abs(ele)
if e = val1 then e := val2
if ele < 0 then e := -e
rel2 := concat(rel2, e)
rels2 := concat(rels2, rel2)
rels2
-- Tietze Transformation to remove a generator that is equal to
-- the identity element. That is there is a relation containing only one
-- generator.
-- This procedure searches for a single element relation, if found, it
-- removes the corresponding generator and also removes it from
-- any relations containing it.
-- This procedure only removes one generator, if there are several
-- such relations then this procedure needs to be called several times.
-- This is a local function used by simplify.
TTRemoveGeneratorIfIdentity(s : %, trace : Boolean) : % ==
gens1 : PrimitiveArray(NNI) := s.gens
rels1 : List(List(Integer)) := s.rels
toBeRemoved : NNI := 0
for rel in rels1 repeat
if #rel = 1 and toBeRemoved = 0 then
toBeRemoved := qcoerce(abs(first(rel)))
if toBeRemoved = 0 then return s
if trace then
print hconcat([message("simplify: generator '"), _
outputGen(toBeRemoved), _
message("' is identity so remove it")])
gens1 := removeGen(gens1, toBeRemoved)
rels1 := removeGen2(rels1, toBeRemoved)
if trace then print outputRelList(rels1)
[gens1, rels1]
-- Tietze Transformation to rename a generator.
-- If a relation consists of a pair of generators then make the
-- second generator the inverse of the first.
-- This procedure searches for a two element relation, if found, it
-- replaces the second element with the inverse of the first.
-- This procedure only replaces one generator, if there are several
-- such relations then this procedure needs to be called several times.
-- This is a local function used by simplify.
TTRenameGenerator(s : %, trace : Boolean) : % ==
gens1 : PrimitiveArray(NNI) := s.gens
rels1 : List(List(Integer)) := s.rels
replaceFrom : NNI := 0
replaceTo : Integer := 0
for rel in rels1 repeat
if #rel = 2 and replaceFrom = 0 then
replaceTo := second(rel)
replaceFrom := qcoerce(abs(first(rel)))
if first(rel) > 0 then replaceTo := -replaceTo
-- don't replace an element with itself or its inverse
if replaceFrom = abs(replaceTo) then replaceFrom := 0
if replaceFrom=0 then return s
if trace then
print hconcat([message("simplify: generator '"), _
outputGen(replaceFrom), _
message("' is replaced by '"), _
outputGen(replaceTo), _
message("'")])
gens1 := removeGen(gens1, replaceFrom)
rels1 := replaceGen(rels1, replaceFrom, replaceTo)
if trace then print outputRelList(rels1)
[gens1, rels1]
-- This is a local function used by simplify.
TTRemoveEmpty(s : %, trace : Boolean) : % ==
gens1 : PrimitiveArray(NNI) := s.gens
rels1 : List(List(Integer)) := s.rels
rels2 : List(List(Integer)) := empty()$List(List(Integer))
for rel in rels1 repeat
--print(" groupPresentation simplify rel=" << rel)
if not empty?(rel) then
rels2 := concat(rels2, rel)
[gens1, rels2]
-- This is a local function used by simplify.
TTRemoveZero(s : %, trace : Boolean) : % ==
gens1 : PrimitiveArray(NNI) := s.gens
rels1 : List(List(Integer)) := s.rels
gens1 := removeGen(gens1, 0)
rels1 := removeGen2(rels1, 0)
[gens1, rels1]
-- This is a local function used by simplify.
TTRemoveEleTimesInverse(s : %, trace : Boolean) : % ==
gens1 : PrimitiveArray(NNI) := s.gens
rels1 : List(List(Integer)) := s.rels
--print("TTRemoveEleTimesInverse relations in =" << rels1)
rels2 : List(List(Integer)) := empty()$List(List(Integer))
changed : Boolean := false
for rel in rels1 repeat
--print("TTRemoveEleTimesInverse rel=" << rel)
rel2 : List(Integer) := empty()$List(Integer)
lastele : Integer := 0
for ele in rel repeat
if abs(ele) = abs(lastele) and sign(ele) ~= sign(lastele) then
if trace then print hconcat([_
message("simplify: generator '"), _
outputGen(ele), _
message("' is adjacent to its inverse")])
changed := true
lastele := 0
else
if lastele ~= 0 then rel2 := concat(rel2, lastele)
lastele := ele
if lastele ~= 0 then rel2 := concat(rel2, lastele)
if not empty?(rel2) then rels2 := concat(rels2, rel2)
if trace and changed then print outputRelList(rels2)
[gens1, rels2]
-- local function to invert relation. Used by TTSubstitute,
-- TTMinimiseInverses and relationEquivalent.
-- We invert each element and then reverse the order.
-- A bit like De Morgan's laws
invertRelation(relationIn : List(Integer)) : List(Integer) ==
relationOut := []$List(Integer)
for ele in relationIn repeat
relationOut := concat(-ele, relationOut)
relationOut
-- local function to cycle relation. Used by relationEquivalent.
-- The effect of a relation is not changed by cycling
cycleRelation(relationIn : List(Integer)) : List(Integer) ==
relationOut : List(Integer) := concat(relationIn.rest,relationIn.first)
--print(message "cycleRelation " << relationIn << message " to " << relationOut)
relationOut
-- Local function to test equivalence of two relations.
-- Used by TTRemoveDuplicateRelation.
-- Relations are considered equivalent if they are identical or
-- if they are the same after being cycled or if they are the
-- same after being inverted.
relationEquivalent(relA : List(Integer),relB : List(Integer)) : Boolean ==
-- first filter out cases where relations are different lengths
if #relA ~= #relB then return false
-- test for equality
if relA = relB then return true
-- test for equality with inverted.
if relA = invertRelation(relB) then return true
-- test for equality with cycle
relBCycle : List(Integer) := copy relB
for n in 1..(#relA) repeat
relBCycle := cycleRelation(relBCycle)
if relA = relBCycle then return true
if relA = invertRelation(relBCycle) then return true
false
-- This is a local function used by simplify.
-- It looks for and removes any duplicated relations.
-- Relations are considered duplicates if they are identical or
-- if they are the same after being cycled or if they are the
-- same after being inverted.
TTRemoveDuplicateRelation(s : %, trace : Boolean) : % ==
gens1 : PrimitiveArray(NNI) := s.gens
rels1 : List(List(Integer)) := s.rels
rels2 := []$List(List(Integer))
--print(message "TTRemoveDuplicateRelation =" << rels1)
for rela in rels1 for nrela in 1..(#rels1) repeat
-- include relation
include : Boolean := true
for relb in rels1 for nrelb in 1..(#rels1) repeat
if nrela > nrelb then
if relationEquivalent(rela,relb) then
include : Boolean := false
if trace then
m ==> "TTRemoveDuplicateRelation duplicate found "
print(message m << rela << message "=" << relb)
if include then
rels2 := concat(rels2, rela)
[gens1, rels2]
-- This is a local function used by simplify.
-- If a relation contains more inverted elements that non-inverted
-- elements then it is easier to read if we invert all the terms.
TTMinimiseInverses(s : %, trace : Boolean) : % ==
gens1 : PrimitiveArray(NNI) := s.gens
rels1 : List(List(Integer)) := s.rels
rels2 := []$List(List(Integer))
for rel in rels1 repeat
numInverts : NNI := 0
numNonInverts : NNI := 0
for ele in rel repeat
if ele < 0 then
numInverts := numInverts + 1
else
numNonInverts := numNonInverts + 1
if numInverts > numNonInverts then
rels2 := concat(rels2, invertRelation(rel))
else
rels2 := concat(rels2, rel)
[gens1, rels2]
-- This is a local function used by TTSubstitute.
-- Counts the number of times a generator (or its inverse) occurs
-- in a relation.
generatorOccurrences(rel : List(Integer),gen : NNI) : NNI ==
res : NNI := 0
for g in rel repeat
if g = gen then res := res + 1
if gen > 0 and g = -gen then res := res + 1
res
-- local function to remove relations containing given generator
removeRelations(rels1 : List(List(Integer)), val : NNI
) : List(List(Integer)) ==
res : List(List(Integer)) := []$List(List(Integer))
for rel in rels1 repeat
if (not member?(val,rel)) and (not member?(-val,rel))then
res := concat(res,rel)
res
-- This is a local function used by simplify.
-- If a generator is contained in exactly 2 relations then we may be
-- able to substitute one relation in another and remove that generator.
-- If, in at least one of these relations, the generator is contained
-- only once then we can move it to one side of the equation and
-- substitute it in the other relation.
TTSubstitute(s : %, trace : Boolean) : % ==
gs : List(NNI) := entries(s.gens)
rs : List(List(Integer)) := s.rels
r1 : List(Integer) := []
r2 : List(Integer) := []
n1 : NNI := 0
n2 : NNI := 0
genToBeRemoved : NNI := 0
for g in gs repeat
indexes : List(NNI) := indexesOfRelUsingGen(s, g)
if #indexes = 2 and genToBeRemoved=0 then
-- we have a candidate for substitution but, to be
-- sure generator must occur once in a relation
genToBeRemoved := g
r1 := rs.(indexes.1)
r2 := rs.(indexes.2)
n1 := generatorOccurrences(r1,g)
n2 := generatorOccurrences(r2,g)
if n1 ~= 1::NNI then
-- swap first and second relations
r3 : List(Integer) := r1 ; n3 : NNI := n1
r1 := r2 ; n1 := n2
r2 := r3 ; n2 := n3
if n1 ~= 1::NNI then
genToBeRemoved := 0
if n1 ~= 1::NNI then return s
-- If we have got to this point then we know a substitution
-- is possible.
if trace then
print(message("simplify: TTSubstitute (") << s << message(")"))
print(message("genToBeRemoved=") << outputGen(genToBeRemoved) << _
message(" r1=") << outputRel(r1) <<
message(" r2=") << outputRel(r2))
print(message("n1=") << n1 << message(" n2=") << n2)
restr : List(Integer) := r1
prer : List(Integer) := []
found : Boolean := false
genInverted : Boolean := false
while (not empty?(restr)) and (not found)repeat
x : Integer := first(restr)
restr := rest(restr)
if x=genToBeRemoved or x= -genToBeRemoved
then
found := true
if x<0 then genInverted := true
else prer := concat(prer,x)
postr : List(Integer) := []
while not empty?(restr) repeat
x : Integer := first(restr)
restr := rest(restr)
postr := concat(postr,x)
replacement := concat(invertRelation(prer),invertRelation(postr))
-- now substitute replacement for genToBeRemoved in r2
if trace then
print(message("we will substitute ") << outputRel(replacement) <<
message(" for ") << outputGen(genToBeRemoved) <<
message(" in ") << outputRel(r2))
newRel : List(Integer) := []
for x in r2 repeat
if abs(x)=abs(genToBeRemoved)
then
if genInverted
then newRel := concat(newRel,invertRelation(replacement))
else newRel := concat(newRel,replacement)
else newRel := concat(newRel,x)
if trace then print(message("newRel=") << outputRel(newRel))
gens1 : PrimitiveArray(NNI) := s.gens
rels1 : List(List(Integer)) := s.rels
gens1 := removeGen(gens1, genToBeRemoved)
rels1 := removeRelations(rels1, genToBeRemoved)
rels1 := concat(rels1,newRel)
if trace then print(message("gens=") << outputGenList(entries(gens1))
<< message(" rels=") << outputRelList(rels1))
[gens1, rels1]
-- true if 'a' is simpler than 'b'.
-- There may not be an absolute measure of whether one presentation
-- is simpler than another but this procedure is used only in specific
-- circumstances, that is where we have attempted to simplify the
-- presentation and we want to test if it is actually simpler.
-- We do this by testing if the number of generators or relations has
-- reduced or if the complexity of the relations has reduced.
-- This is a local function used by simplify.
isSimpler?(a : %, b : %) : Boolean ==
gensa : PrimitiveArray(NNI) := a.gens
relsa : List(List(Integer)) := a.rels
gensb : PrimitiveArray(NNI) := b.gens
relsb : List(List(Integer)) := b.rels
if #gensa < #gensb then return true
if #relsa < #relsb then return true