group.gap 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # run this file with
  2. # gap -b -q < /dev/null group.gap | perl -pe 's/\\\n//s' | indent -kr
  3. Print("/* ----- data generated by group.gap begins ----- */\n\n");
  4. Print("struct group {\n unsigned long autosize;\n");
  5. Print(" int order, ngens;\n const char *gens;\n};\n");
  6. Print("struct groups {\n int ngroups;\n");
  7. Print(" const struct group *groups;\n};\n\n");
  8. Print("static const struct group groupdata[] = {\n");
  9. offsets := [0];
  10. offset := 0;
  11. for n in [2..26] do
  12. Print(" /* order ", n, " */\n");
  13. for G in AllSmallGroups(n) do
  14. # Construct a representation of the group G as a subgroup
  15. # of a permutation group, and find its generators in that
  16. # group.
  17. # GAP has the 'IsomorphismPermGroup' function, but I don't want
  18. # to use it because it doesn't guarantee that the permutation
  19. # representation of the group forms a Cayley table. For example,
  20. # C_4 could be represented as a subgroup of S_4 in many ways,
  21. # and not all of them work: the group generated by (12) and (34)
  22. # is clearly isomorphic to C_4 but its four elements do not form
  23. # a Cayley table. The group generated by (12)(34) and (13)(24)
  24. # is OK, though.
  25. #
  26. # Hence I construct the permutation representation _as_ the
  27. # Cayley table, and then pick generators of that. This
  28. # guarantees that when we rebuild the full group by BFS in
  29. # group.c, we will end up with the right thing.
  30. ge := Elements(G);
  31. gi := [];
  32. for g in ge do
  33. gr := [];
  34. for h in ge do
  35. k := g*h;
  36. for i in [1..n] do
  37. if k = ge[i] then
  38. Add(gr, i);
  39. fi;
  40. od;
  41. od;
  42. Add(gi, PermList(gr));
  43. od;
  44. # GAP has the 'GeneratorsOfGroup' function, but we don't want to
  45. # use it because it's bad at picking generators - it thinks the
  46. # generators of C_4 are [ (1,2)(3,4), (1,3,2,4) ] and that those
  47. # of C_6 are [ (1,2,3)(4,5,6), (1,4)(2,5)(3,6) ] !
  48. gl := ShallowCopy(Elements(gi));
  49. Sort(gl, function(v,w) return Order(v) > Order(w); end);
  50. gens := [];
  51. for x in gl do
  52. if gens = [] or not (x in gp) then
  53. Add(gens, x);
  54. gp := GroupWithGenerators(gens);
  55. fi;
  56. od;
  57. # Construct the C representation of the group generators.
  58. s := [];
  59. for x in gens do
  60. if Size(s) > 0 then
  61. Add(s, '"');
  62. Add(s, ' ');
  63. Add(s, '"');
  64. fi;
  65. sep := "\\0";
  66. for i in ListPerm(x) do
  67. chars := "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  68. Add(s, chars[i]);
  69. od;
  70. od;
  71. s := JoinStringsWithSeparator([" {", String(Size(AutomorphismGroup(G))),
  72. "L, ", String(Size(G)),
  73. ", ", String(Size(gens)),
  74. ", \"", s, "\"},\n"],"");
  75. Print(s);
  76. offset := offset + 1;
  77. od;
  78. Add(offsets, offset);
  79. od;
  80. Print("};\n\nstatic const struct groups groups[] = {\n");
  81. Print(" {0, NULL}, /* trivial case: 0 */\n");
  82. Print(" {0, NULL}, /* trivial case: 1 */\n");
  83. n := 2;
  84. for i in [1..Size(offsets)-1] do
  85. Print(" {", offsets[i+1] - offsets[i], ", groupdata+",
  86. offsets[i], "}, /* ", i+1, " */\n");
  87. od;
  88. Print("};\n\n/* ----- data generated by group.gap ends ----- */\n");
  89. quit;