Browse Source

Add: Working towards easy isomorphism checks from group files

Sebastian Kreisel 4 months ago
parent
commit
8f80981e17

+ 15 - 10
src/application/group_library.c

@@ -22,14 +22,18 @@ bool app_writeGroup(char *path, Group *group, char *name)
   GroupMetaInfo meta;
   memset(meta.name, '\0', GROUP_META_NAME_LEN); // avoid garbage in meta.name
   memset(meta.minGenSet, 0xffff, GROUP_META_MINGENSET_LEN * sizeof(u16));
-  strcpy(meta.name, name);
+  if(name != 0) {
+    strcpy(meta.name, name);
+  }
   meta.order = group_order(group);
   meta.isCommutative = group_isCommutative(group);
+  printf("Determining minGenSet ...\n");
   Vecu16 *minGenSet = group_minGeneratingSet_alloc(group);
   group_truncGeneratedSet(minGenSet, 1);
   meta.minGenSetSize = minGenSet->size;
   vecu16_copyIntoArray(meta.minGenSet, minGenSet, minGenSet->size);
   vecu16_free(minGenSet);
+  printf("Writing to file ...\n");
   return group_writeToFile(group, meta, path);
 }
 
@@ -38,6 +42,7 @@ bool app_writeGroupSn(char *path, u32 n)
   char name[16];
   memset(name, 0, 16);
   sprintf(name, "S%u", n);
+  printf("Constructing group ...\n");
   Group *group = group_createSn_alloc(n);
   bool ok = app_writeGroup(path, group, name);
   group_free(group);
@@ -49,6 +54,7 @@ bool app_writeGroupCn(char *path, u32 n)
   char name[16];
   memset(name, 0, 16);
   sprintf(name, "C%u", n);
+  printf("Constructing group ...\n");
   Group *group = group_createCn_alloc(n);
   bool ok = app_writeGroup(path, group, name);
   group_free(group);
@@ -112,8 +118,9 @@ Vecptr *app_listGroupFiles_alloc(char *path, u16 order, i32 isCommutative)
 // --------------------------------------------------------------------------
 
 Group *app_searchForGroup_alloc(Group *parent,
-                                u16 order, i32 isCommutative,
-                                u32 genSizeLower, u32 genSizeUpper,
+                                u16 order,
+                                u32 genSizeLower,
+                                u32 genSizeUpper,
                                 u32 iter)
 {
   u16 n = group_order(parent);
@@ -121,7 +128,7 @@ Group *app_searchForGroup_alloc(Group *parent,
   Vecu16 *res = vecu16_alloc(n);
   Vecu16 *util = vecu16_alloc(n);
   Vecu16 *orderVec = group_getOrderVector_alloc(parent);
-  rand_setSeed(41);
+  Group *subgroup = 0;
   for(i32 i = 0; i < iter; i++) {
     u32 numGen = rand_getU32InRange(genSizeLower, genSizeUpper);
     vecu16_fill(set, 0xffff);
@@ -140,8 +147,6 @@ Group *app_searchForGroup_alloc(Group *parent,
       }
       *vecu16_at(set, j) = randEle;
     }
-    //printf("Generating with set ...\n");
-    //vecu16_print(set);
     bool ok = group_generateFromConstr_noalloc(parent, set, res, util,
                                                orderVec, order);
     if(ok) {
@@ -149,15 +154,15 @@ Group *app_searchForGroup_alloc(Group *parent,
       u32 m = 0;
       vecu16_indexOf(res, 0xffff, &m, 0);
       if(m == order) {
-        printf("%05u :: %u :: Found subgrp of order %u.\n", i + 1, numGen, m);
+        vecu16_resize(res, m);
+        subgroup = group_expandSubgroupFromSet_alloc(parent, res);
+        break;
       }
-    } else {
-
     }
   }
   vecu16_free(orderVec);
   vecu16_free(util);
   vecu16_free(res);
   vecu16_free(set);
-  return 0;
+  return subgroup;
 }

+ 8 - 2
src/application/group_library.h

@@ -36,9 +36,15 @@ Vecptr *app_listGroupFiles_alloc(char *path, u16 order, i32 isCommutative);
 // --------------------------------------------------------------------------
 
 Group *app_searchForGroup_alloc(Group *parent,
-                                u16 order, i32 isCommutative,
-                                u32 genSizeLower, u32 genSizeUpper,
+                                u16 order,
+                                u32 genSizeLower,
+                                u32 genSizeUpper,
                                 u32 iter);
 
+Vecptr *app_searchForGroups_alloc(Group *parent,
+                                  u16 order,
+                                  u32 genSizeLower,
+                                  u32 genSizeUpper,
+                                  u32 iter);
 
 #endif

+ 20 - 7
src/group/group_gen.c

@@ -369,22 +369,35 @@ Vecu16 *group_minGeneratingSet_alloc(Group *group)
 // Generating a subgroup from elements
 // --------------------------------------------------------------------------
 
-Group *group_generateSubgroup_alloc(Group *group, Vecu16 *set)
+Group *group_expandSubgroupFromSet_alloc(Group *group, Vecu16 *res)
 {
-  Vecu16 *res = group_generateFrom_alloc(group, set);
-  group_truncGeneratedSet(res, 1);
   u32 m = res->size;
   Group *subgroup = group_alloc(m, 0);
   vecu16_copyInto(res, subgroup->set, 0);
-  u16 a, b;
+  u16 a, b, ab;
+  bool isCommu = group_isCommutative(group);
   for(i32 i = 0; i < m; i++) {
     a = *vecu16_at(res, i);
-    for(i32 j = 0; j < m; j++) {
+    for(i32 j = i; j < m; j++) {
       b = *vecu16_at(res, j);
-      *vecu16_at(subgroup->gtab, get2DIndex(m, i, j)) = group_op(group, a, b);
-      *vecu16_at(subgroup->gtab, get2DIndex(m, j, i)) = group_op(group, b, a);
+      ab = group_op(group, a, b);
+      *vecu16_at(subgroup->gtab, get2DIndex(m, i, j)) = ab;
+      if(isCommu) {
+        *vecu16_at(subgroup->gtab, get2DIndex(m, j, i)) = ab;
+      } else {
+        *vecu16_at(subgroup->gtab, get2DIndex(m, j, i)) = group_op(group, b, a);
+      }
     }
   }
+  return subgroup;
+}
+
+
+Group *group_generateSubgroup_alloc(Group *group, Vecu16 *set)
+{
+  Vecu16 *res = group_generateFrom_alloc(group, set);
+  group_truncGeneratedSet(res, 1);
+  Group *subgroup = group_expandSubgroupFromSet_alloc(group, res);
   vecu16_free(res);
   return subgroup;
 }

+ 9 - 0
src/group/group_gen.h

@@ -158,6 +158,15 @@ Vecu16 *group_minGeneratingSet_alloc(Group *group);
 // Generating a subgroup from elements
 // --------------------------------------------------------------------------
 
+/*
+ * Returns a newly allocated subgroup with subgroup->set = res. res must be
+ * closed under group_op, or an invalid group is returned
+ */
+Group *group_expandSubgroupFromSet_alloc(Group *group, Vecu16 *res);
+
+/*
+ * Generated and return a newly allocated subgroup with generating set set
+ */
 Group *group_generateSubgroup_alloc(Group *group, Vecu16 *set);
 
 

+ 2 - 2
src/group/group_hom.c

@@ -192,8 +192,8 @@ bool group_checkForIsomorphismFromGen(GroupHom *hom,
       group_completeMapFromGen(hom, genSet, isoUtils->genDecompVec);
       bool isInj = mapu16_isInjective(hom->map);
       bool hasHomProp = group_hasHomProp(hom);
-      printf("%i %i -> %i %i\n", *vecu16_at(binom, 0), *vecu16_at(binom, 1),
-             isInj, hasHomProp);
+      printf("%i %i %i -> %i %i\n", *vecu16_at(binom, 0), *vecu16_at(binom, 1),
+             *vecu16_at(binom, 2), isInj, hasHomProp);
     }
     mpermOk = perm_shiftDefault(isoUtils->mperm);
   }

+ 1 - 1
src/group/group_hom.h

@@ -78,7 +78,7 @@ struct HomIsoUtils {
   Vecu16 *mperm;                  // Perm for mapping genSets onto each other
   Vecu16 *genFromOrders;          // Store the ele orders for genFrom
   Vecptr *genDecompVec;           // Full decomp into elements from genSetFrom
-  Vecu16 *genOrderConstr;            // For group_minGeneratingSetConstr
+  Vecu16 *genOrderConstr;         // For group_minGeneratingSetConstr
   GenConstrUtils *genConstrUtils; // For group_minGeneratingSetConstr
 };
 typedef struct HomIsoUtils HomIsoUtils;

+ 54 - 3
src/main.c

@@ -7,6 +7,7 @@
 #include <elfc_veci32.h>
 #include <elfc_mapu16.h>
 #include <elfc_hash.h>
+#include <elfc_random.h>
 
 #include "group/group.h"
 #include "group/group_common.h"
@@ -16,6 +17,7 @@
 
 #include "application/group_library.h"
 
+i32 main_11();
 i32 main_10();
 i32 main_9();
 i32 main_8();
@@ -29,7 +31,53 @@ i32 main_1();
 
 i32 main()
 {
-  return main_10();
+  return main_11();
+}
+
+i32 main_11()
+{
+  //Group *g1 = group_readGroupFromFile_alloc("./grplib/00016n_46544f7fed32b725.txt");
+  //Group *g2 = group_readGroupFromFile_alloc("./grplib/00016n_ad667b22219eb725.txt");
+  //Group *g1 = group_readGroupFromFile_alloc("./grplib/00048n_37e12bcbfe003125.txt");
+  //Group *g2 = group_readGroupFromFile_alloc("./grplib/00048n_7b17045886823125.txt");
+  Group *g1 = group_readGroupFromFile_alloc("./grplib/00120n_21e80f54a2599d75.txt");
+  Group *g2 = group_readGroupFromFile_alloc("./grplib/00120n_b916c3ae173f1d75.txt");
+  if(g1 == 0 || g2 == 0) {
+    return 1;
+  }
+  u16 n = group_order(g1);
+  Mapu16 *om1 = group_orderDist_alloc(g1);
+  Mapu16 *om2 = group_orderDist_alloc(g2);
+  vecu16_print(om1->domain);
+  vecu16_print(om1->codomain);
+  vecu16_print(om2->domain);
+  vecu16_print(om2->codomain);
+  mapu16_free(om1);
+  mapu16_free(om2);
+  Vecu16 *genFrom = group_minGeneratingSet_alloc(g1);
+  group_truncGeneratedSet(genFrom, 1);
+  Mapu16 *h = mapu16_alloc(n, 1);
+  vecu16_copyInto(g1->set, h->domain, 0);
+  GroupHom *hom = group_allocHom_ref(g1, g2, h);
+  Vecu16 *binom = vecu16_alloc(n);
+  binom_init(binom, 0, genFrom->size, 0);
+  HomIsoUtils *isoUtils = group_allocSetupIsoUtils(hom, genFrom);
+  vecu16_print(genFrom);
+  vecu16_print(isoUtils->genFromOrders);
+  bool ok = 1;
+  while(ok) {
+    ok = group_checkForIsomorphismFromGen(hom, genFrom, binom, isoUtils);
+  }
+
+  group_freeIsoUtils(isoUtils);
+  group_freeHom_ref(hom);
+  mapu16_free(h);
+  vecu16_free(binom);
+  vecu16_free(genFrom);
+
+  group_free(g2);
+  group_free(g1);
+  return 0;
 }
 
 i32 main_10()
@@ -39,8 +87,11 @@ i32 main_10()
   if(group == 0) {
     return 0;
   }
-  // 7! = 2 * 2 * 2 * 2 * 3 * 3 * 5 * 7
-  app_searchForGroup_alloc(group, 2 * 2 * 2 * 2, 0, 2, 3, 90000);
+  rand_setSeed(444);
+  Group *g = app_searchForGroup_alloc(group, 120, 2, 3, 90000);
+  printf("Found valid subgroup: %u\n", group_isValid(g));
+  printf("Writing subgroup to file: %u\n", app_writeGroup("./grplib", g, 0));
+  group_free(g);
   group_free(group);
   return 0;
 }