1LoadPackage("ferret", false); 2LoadPackage("atlas", false); 3 4ReadPackage("ferret", "tst/random_obj.g"); 5 6if not(IsBound(FERRET_EXTRA_TESTS)) then 7 FERRET_EXTRA_TESTS := false; 8fi; 9 10if not(IsBound(FERRET_TEST_COUNT)) then 11 FERRET_TEST_COUNT := 50; 12fi; 13 14compare_full_groups := function(g, record) 15 local perms; 16 perms := record.generators; 17 if(Size(perms) <> Size(Group(perms))) then 18 Print("CFG: Size(p) = ", Size(perms), ", Size(Group(p)) = ", Size(Group(perms)),"\n"); 19 Print("CFG: p:", perms,"\n"); 20 return fail; 21 fi; 22 if(Size(Set(perms)) <> Size(perms)) then 23 Print("CFG: Repeated members of p!","\n"); 24 Print(perms,"\n"); 25 return fail; 26 fi; 27 if(Set(perms) <> Set(Group(perms))) then 28 Print("CFG: p not whole group!","\n"); 29 Print(Set(perms),"\n"); 30 Print(Set(Group(perms)),"\n"); 31 return fail; 32 fi; 33 if(Group(perms) <> g) then 34 Print("CFG: Wrong group!","\n"); 35 Print(g,"\n"); 36 Print(Group(perms),"\n"); 37 return fail; 38 fi; 39 return true; 40end;; 41 42 43compare_gen_groups := function(g, record) 44 local perms; 45 perms := record.generators; 46 if(Group(perms, ()) <> g) then 47 Print("CGG: Wrong group!","\n"); 48 Print("CGG: Expected: ",g,"\n"); 49 Print("CGG: Found: ",Group(perms,()),"\n"); 50 return false; 51 fi; 52 if((Length(perms) > LargestMovedPoint(g)) and (Length(perms) > 1)) then 53 Print("CGG: Too many generators! (LMP=)",LargestMovedPoint(g),"\n"); 54 Print(perms,"\n"); 55 return false; 56 fi; 57 return true; 58end;; 59 60 61 62proporderings := ["always", "alwaysbase", "never", "root", "firstnontrivial"]; 63 64# Checks all the ways of building up a single group -- can be extremely slow! 65CheckGroup := function(g) 66 local h, heuristics, only_gen, orbits, blocks, orbitals, output, record, f, orborders; 67 # Clean off GAP name from group 68 g := Group(GeneratorsOfGroup(g), ()); 69 if FERRET_EXTRA_TESTS then 70 orborders := proporderings; 71 heuristics := ["largest", "first", "smallest2", "randomsmallest", "random", "random"]; 72 else 73 orborders := ["always"]; 74 heuristics := ["smallest", "smallest2", "randomsmallest", "random"]; 75 fi; 76 77 for h in heuristics do 78 for orbits in orborders do 79 for blocks in proporderings do 80 for orbitals in proporderings do 81 record := rec(orbits := orbits, blocks := blocks, orbitals := orbitals); 82 output := 83 Solve([ConInGroup(g, record)], 84 rec( only_find_generators := true, 85 rbaseCellHeuristic := h, 86 recreturn := true) ); 87 if not(compare_gen_groups(g, output)) then 88 Print("Check Group", [g,record,h]); 89 fi; 90 91 output := 92 Solve([ConInGroup(g, record)], 93 rec( only_find_generators := false, 94 rbaseCellHeuristic := h, 95 recreturn := true) ); 96 if not(compare_full_groups(g, output)) then 97 Print("Check full group",[g,record,h]); 98 fi; 99 od; 100 od; 101 od; 102 od; 103 return true; 104end;; 105 106CheckStab := function(g, s, act, extra...) 107 local permsStandard, permsExtra, stab, comp1, comp2, stabmap, optrec; 108 109 if Size(extra) = 0 then 110 stabmap := ConStabilize(s, act); 111 elif Size(extra) = 1 then 112 stabmap := ConStabilize(s, act, extra[1]); 113 else 114 ErrorNoReturn("Only 1, or no, extra arguments"); 115 fi; 116 117 permsStandard := Solve([ConInGroup(g), stabmap], rec(recreturn := true)); 118 119 optrec := rec(blocks := Random(proporderings), orbitals := Random(proporderings)); 120 permsExtra := Solve([ConInGroup(g, optrec), stabmap], rec(recreturn := true)); 121 122 stab := Stabilizer(g, s, act); 123 124 comp1 := compare_gen_groups(stab, permsStandard); 125 126 if not(comp1) then 127 Print("Fast check stab " , g , ",",s," with action ",act," and ", extra, " failed\n"); 128 fi; 129 130 131 comp2 := compare_gen_groups(stab, permsExtra); 132 133 if not(comp2) then 134 Print("Fast check stab " , g , ",",s," with action ",act," and ", extra, " : ", optrec, " failed\n"); 135 fi; 136 return (comp1 and comp2); 137end;; 138 139# Each of these functions should take a single integer, and return a pair, containing a constraint 140# and a the group that constraint generates 141ConstraintBuilders := 142[ 143 function(x) 144 local g; 145 g := RandomGroupUpToSize(GlobalMersenneTwister, x); 146 return [ConInGroup(g), g]; 147 end, 148 function(x) 149 local s; 150 s := RandomObj(GlobalMersenneTwister, x, OnSets); 151 return [ConStabilize(s), Stabilizer(SymmetricGroup(x), s)]; 152 end 153]; 154 155CheckSmallRandomPrimitives := function() 156 return ForAll([5..10], x -> CheckStab(RandomGroupOfSize(GlobalMersenneTwister, x), [1,2,4],OnSets)) 157 and 158 ForAll([3..6], x -> CheckStab(RandomGroupOfSize(GlobalMersenneTwister, x), [[1,2],[3,4]],OnSetsSets)); 159 160end;; 161 162CheckRandomPrimitives := function() 163 return ForAll([10..20], x -> CheckStab(RandomGroupOfSize(GlobalMersenneTwister, x), [2,4,6,8,9],OnSets)) 164 and 165 ForAll([7..10], x -> CheckStab(RandomGroupOfSize(GlobalMersenneTwister, x), [[1,6],[2,4],[3,5]],OnSetsSets)); 166 167end;; 168