def test_len(self): s1 = Permutation.read_cycle_form([[1,2,3,4]], 4) s2 = Permutation.read_cycle_form([[1,2]], 4) G = PermGroup([s1, s2]) self.assertEqual(len(G), len(G._list_elements())) self.assertEqual(len(G), 24) self.assertTrue(Permutation.read_cycle_form([[3,4]], 4) in G._list_elements())
def test_change_base(self): cf = Permutation.read_cycle_form a = cf([[2,3],[4,6],[5,8],[9,11]], 13) b = cf([[1,2,4,7,9,3,5,6,8,10,11,12,13]], 13) G = PermGroup([a,b]) G.change_base([1,3]) self.assertEqual(G.base[:2], [1,3])
def test_order(self): cf = lambda x : Permutation.read_cycle_form(x,6) g1 = cf([[1,4,5,2,3]]) g2 = cf([[1,2],[3,4]]) g3 = cf([[1,2],[6,5]]) G = PermGroup([g1,g2,g3]) self.assertEqual(G.order(), 360)
def test_coset_enumeration(self): g1 = Permutation.read_cycle_form([[1,2,3,4]], 4) g2 = Permutation.read_cycle_form([[1,2]], 4) h1 = Permutation.read_cycle_form([[1,2,3]], 4) h2 = Permutation.read_cycle_form([[1,2]], 4) G = PermGroup([g1, g2]) H = PermGroup([h1, h2]) cosets = G._left_cosets(H) total = 0 elements = [] for coset in cosets: temp_eles = coset._list_elements() elements += temp_eles self.assertEqual(len(temp_eles),len(H)) total += len(temp_eles) self.assertEqual(len(G), total) self.assertEqual(sorted(G._list_elements()), sorted(elements)) cosets = G._right_cosets(H) total = 0 elements = [] for coset in cosets: temp_eles = coset._list_elements() elements += temp_eles self.assertEqual(len(temp_eles),len(H)) total += len(temp_eles) self.assertEqual(len(G), total) self.assertEqual(sorted(G._list_elements()), sorted(elements))
def test_change_base_redundancy(self): cf = lambda x: Permutation.read_cycle_form(x,6) a = cf([[1,2,3,4],[5,6]]) b = cf([[1,2]]) G = PermGroup([a,b]) G.change_base([5,6,1,2,3,4]) self.assertEqual(G.base[:4],[5,6,1,2])
def test_partition_backtrack_subgroup_two_prop_subgroup_stab(self): cf = Permutation.read_cycle_form a = cf([[3,2,6]], 7) b = cf([[3,2],[6,7]], 7) G = PermGroup([a,b]) fam_subgroup = SubgroupFamily(G) prop_subgroup = SubgroupProperty(G) stab = Partition([[1,3,5,7],[2,4,6]]) fam_part_stab = PartitionStabaliserFamily(stab) prop_part_stab = PartitionStabaliserProperty(stab) size = 7 fam = RefinementUnion([fam_part_stab, fam_subgroup]) prop = CosetPropertyUnion([prop_part_stab, prop_subgroup]) con = PartitionStackConstraint() mods = ModifierUnion([fam, prop, con]) ls = LeonSearch(mods, size) gens = ls.subgroup() found = [] s7 = PermGroup([cf([[1,2]],7),cf([[1,2,3,4,5,6,7]],7)]) for ele in s7._list_elements(): if prop.property_check(ele): found.append(ele) self.assertEqual(len(PermGroup(gens)), len(found))
def test_partition_backtrack_subgroup_two_prop_subgroup_stab(self): cf = Permutation.read_cycle_form a = cf([[3,2,6]], 7) b = cf([[3,2],[6,7]], 7) G = PermGroup([a,b]) fam_subgroup = SubgroupFamily(G) prop_subgroup = SubgroupProperty(G) stab = Partition([[1,3,5,7],[2,4,6]]) fam_part_stab = PartitionStabaliserFamily(stab) prop_part_stab = PartitionStabaliserProperty(stab) size = 7 fam = Refinement([fam_part_stab, fam_subgroup]) prop = CosetProperty([prop_part_stab, prop_subgroup]) pbw = PBW(prop, fam, size) gens = pbw.find_partition_backtrack_subgroup() found = [] s7 = PermGroup([cf([[1,2]],7),cf([[1,2,3,4,5,6,7]],7)]) for ele in s7._list_elements(): if prop.check(ele): found.append(ele) self.assertEqual(len(PermGroup(gens)), len(found))
def test_rand_element(self): cf = Permutation.read_cycle_form a = cf([[1, 2], [6,7]],7) b = cf([[1,2,3,4], [6,7]], 7) G=PermGroup([a,b]) for _ in range(100): g = G._rand_element() self.assertTrue(g in G)
def _respected_partition(comm): comm_group = Group([comm]) orbs = comm_group.orbits() len_orb = dict() for orb in orbs: if len(orb) in len_orb: len_orb[len(orb)].extend(orb) else: len_orb[len(orb)] = orb return Partition(len_orb.values())
def test_fixed_base_group(self): g1 = Permutation.read_cycle_form([[1,2,3,4,5,6]], 6) g2 = Permutation.read_cycle_form([[1,2]], 6) h1 = Permutation.read_cycle_form([[3,4,5,6]], 6) h2 = Permutation.read_cycle_form([[3,4]], 6) G = PermGroup.fixed_base_group([g1, g2], [5,4]) H = PermGroup.fixed_base_group([h1, h2], [1,2,3,4,5,6]) N = PermGroup.fixed_base_group([g1,h1], []) self.assertEqual(G.base[:2], [5,4]) self.assertEqual(H.base[:4], [1,2,3,4]) self.contains_membership_test(G, H)
def naive_min_gen(original_group, ordering): eles = original_group._list_elements(key = ordering_to_perm_key(ordering)) cur_gens = [eles[1]] cur_G = Group.fixed_base_group(cur_gens, ordering) for ele in eles: if ele not in cur_G: cur_gens.append(ele) cur_G = Group.fixed_base_group(cur_gens, ordering) if cur_G.order() == G.order(): break return cur_gens
def test_contains(self): cf = lambda x:Permutation.read_cycle_form(x, 6) g1 = cf([[1,2,3,4,5,6]]) g2 = cf([[1,2]]) h1 = cf([[3,4,5,6]]) h2 = cf([[3,4]]) a1 = cf([[3,1],[6,4]]) a2 = cf([[1,6,4]]) G = PermGroup([g1, g2]) H = PermGroup([h1, h2]) self.contains_membership_test(G, H) S6 = PermGroup.fixed_base_group([g1,g2], [5,2,1,3,4,6]) A4 = PermGroup.fixed_base_group([a1,a2], [3,1,2,5,6,4]) self.contains_membership_test(S6, A4)
def test_pre_post_element(self): cf = Permutation.read_cycle_form a = cf([[2,3],[4,6],[5,8],[9,11]], 13) b = cf([[1,2,4,7,9,3,5,6,8,10,11,12,13]], 13) G = PermGroup.fixed_base_group([a,b], [1,3]) pre = [1,3] post = [9,3] self.pre_post_works(pre, post, G)
def test_base_image_member(self): h1 = Permutation.read_cycle_form([[3,4,5,6,7]], 7) h2 = Permutation.read_cycle_form([[3,4]], 7) H = PermGroup.fixed_base_group([h1, h2], [3,4,5,6]) self.assertEqual(H.base, [3,4,5,6]) image1 = [1,2,3,4] image2 = [5,3,4,6] self.assertTrue(H.base_image_member(image1) is None) self.assertEqual(H.base_image_member(image2), Permutation.read_cycle_form([[3,5,4]],7))
def double_coset_1(self, base, image, gens, key = None): #base change (for now just recompute base but should do the proper algorithm) if len(image) == 0 or len(gens) == 0: return True G = PermGroup.fixed_base_group(gens, image[:-1]) orb = G.orbit(image[-1], stab_level = len(base) - 1, key = key) #print("Orbit of {} is {} in {}".format(image[-1], orb, G._list_elements())) if image[-1] == orb[0]: return True return False
def test_partition_backtrack_subgroup_one_prop_stab(self): cf = Permutation.read_cycle_form stab = Partition([[1,3,5],[2,4,6]]) fam_part_stab = PartitionStabaliserFamily(stab) prop_part_stab = PartitionStabaliserProperty(stab) size = 6 fam = Refinement([fam_part_stab]) prop = CosetProperty([prop_part_stab]) pbw = PBW(prop, fam, size) gens = pbw.find_partition_backtrack_subgroup() found = [] s6 = PermGroup([cf([[1,2]],6),cf([[1,2,3,4,5,6]],6)]) for ele in s6._list_elements(): if prop.check(ele): found.append(ele) self.assertEqual(len(PermGroup(gens)), len(found))
def test_partition_backtrack_subgroup_one_prop_subgroup(self): cf = Permutation.read_cycle_form a = cf([[1,2,3]], 5) b = cf([[1,2],[3,4]], 5) G = PermGroup([a,b]) fam_subgroup = SubgroupFamily(G) prop_subgroup = SubgroupProperty(G) fam = Refinement([fam_subgroup]) prop = CosetProperty([prop_subgroup]) pbw = PBW(prop, fam, 5) gens = pbw.find_partition_backtrack_subgroup() found = [] s5 = PermGroup([cf([[1,2]],5),cf([[1,2,3,4,5]],5)]) for ele in s5._list_elements(): if prop.check(ele): found.append(ele) self.assertEqual(len(PermGroup(gens)), len(found))
def test_orbit(self): g1 = Permutation.read_cycle_form([[1,2,3,4]], 4) g2 = Permutation.read_cycle_form([[1,2]], 4) base = [3,4,1] reverse_priority = [3,4,1,2] G = PermGroup.fixed_base_group([g1, g2], base) self.assertEqual(G.orbit(1), [1,2,3,4]) self.assertEqual(G.orbit(1, stab_level = 0), [1,2,3,4]) self.assertEqual(G.orbit(1, stab_level = 1), [1,2,4]) self.assertEqual(G.orbit(1, stab_level = 2), [1,2]) self.assertEqual(G.orbit(1, stab_level = 3), [1]) self.assertEqual(G.orbit(1, key = lambda x : reverse_priority[x - 1]), [3,4,1,2])
def test_partition_backtrack_subgroup_leon_paper(self): cf = Permutation.read_cycle_form a = cf([[2,3],[4,6],[5,8],[9,11]], 13) b = cf([[1,2,4,7,9,3,5,6,8,10,11,12,13]], 13) G = PermGroup([a,b]) fam_subgroup = SubgroupFamily(G) prop_subgroup = SubgroupProperty(G) stab = Partition([[1,3,5,7,9,11],[2,4,6,8,10,12,13]]) fam_part_stab = PartitionStabaliserFamily(stab) prop_part_stab = PartitionStabaliserProperty(stab) size = 13 fam = Refinement([fam_subgroup, fam_part_stab]) prop = CosetProperty([prop_subgroup, prop_part_stab]) pbw = PBW(prop, fam, size) gens = pbw.find_partition_backtrack_subgroup() cand_G = PermGroup(gens) leon_gens = [] leon_gens.append(cf([[2,12],[4,10],[5,7],[6,8]],13)) leon_gens.append(cf([[2,8],[3,5],[4,6],[10,12]],13)) leon_gens.append(cf([[1,9],[2,4],[6,8],[10,12]],13)) leon_G = PermGroup(leon_gens) third_source = [] for ele in G._list_elements(): if prop.check(ele): third_source.append(ele) self.assertEqual(cand_G.order(), leon_G.order()) for perm in leon_gens: self.assertTrue(perm in G) self.assertTrue(perm in cand_G)
def test_partition_backtrack_subgroup_one_prop_stab(self): cf = Permutation.read_cycle_form stab = Partition([[1,3,5],[2,4,6]]) fam_part_stab = PartitionStabaliserFamily(stab) prop_part_stab = PartitionStabaliserProperty(stab) size = 6 fam = RefinementUnion([fam_part_stab]) prop = CosetPropertyUnion([prop_part_stab]) con = PartitionStackConstraint() mods = ModifierUnion([fam, prop, con]) ls = LeonSearch(mods, size) gens = ls.subgroup() found = [] s6 = PermGroup([cf([[1,2]],6),cf([[1,2,3,4,5,6]],6)]) for ele in s6._list_elements(): if prop.property_check(ele): found.append(ele) self.assertEqual(sorted(PermGroup(gens)._list_elements()), sorted(found))
def test_pre_post_element_A4(self): cf = Permutation.read_cycle_form a = cf([[1,2],[3,4]], 5) b = cf([[1,2,3]], 5) G = PermGroup.fixed_base_group([a,b], [5,4,3,2,1]) pre = [5,4] post = [4,3] ele = G.prefix_postfix_image_member(pre,post) self.assertTrue(ele is None) pre = [5,4,3] post = [5,2,1] self.pre_post_works(pre, post, G) ele = G.prefix_postfix_image_member(pre,post) self.assertEqual(cf([[1,3],[2,4]],5),ele)
def test_partition_backtrack_subgroup_one_prop_subgroup(self): cf = Permutation.read_cycle_form a = cf([[1,2,3]], 5) b = cf([[1,2],[3,4]], 5) G = PermGroup([a,b]) fam_subgroup = SubgroupFamily(G) prop_subgroup = SubgroupProperty(G) fam = RefinementUnion([fam_subgroup]) prop = CosetPropertyUnion([prop_subgroup]) con = PartitionStackConstraint() mods = ModifierUnion([fam, prop, con]) ls = LeonSearch(mods, 5) gens = ls.subgroup() found = [] s5 = PermGroup([cf([[1,2]],5),cf([[1,2,3,4,5]],5)]) for ele in s5._list_elements(): if prop.property_check(ele): found.append(ele) self.assertEqual(sorted(PermGroup(gens)._list_elements()), sorted(found))
def schreier_sims0(): from permutation import Permutation from refinement import SubgroupFamily, PartitionStabaliserFamily, Refinement from partition import Partition from group import PermGroup from leon_search import PartitionBacktrackWorkhorse as PBW from coset_property import CosetProperty, SubgroupProperty, PartitionStabaliserProperty cf = Permutation.read_cycle_form a = cf([[1, 2]], 4) b = cf([[1, 2, 3, 4]], 4) G = PermGroup.fixed_base_group([a, b], [1, 2, 3, 4]) base = G.base graphs = G.schreier_graphs gens = G.chain_generators print("Base is: {}".format(base)) for i in range(len(graphs)): print("Generators and schreier graph for G[{}]:".format(i + 1)) print(gens[i]) print(graphs[i])
from group import PermGroup from permutation import Permutation _base_size = 6 cf = lambda x : Permutation.read_cycle_form(x, _base_size) a= cf([[1,2,3,4]]) b= cf([[1,2]]) c= cf([[1,2,3]]) s4 = PermGroup([a,b]) s3 = PermGroup([b,c]) for coset in s4._right_cosets(s3): print(coset._list_elements()) for coset in s4._left_cosets(s3): print(coset._list_elements()) cf = Permutation.read_cycle_form a = cf([[1, 2, 3,4,5]],5) b = cf([[1,2,3]], 5) G=PermGroup([a,b]) print(len(G))
def test_orbits(self): cf = Permutation.read_cycle_form a = cf([[1, 2], [6,7]],7) b = cf([[1,2,3,4], [6,7]], 7) G=PermGroup.fixed_base_group([a,b], [1,2,3]) self.assertEqual(sorted(G.orbits()), [[1,2,3,4],[5],[6,7]])
from ordering import ordering_to_key, ordering_to_perm_key #Set up group generators cf = Permutation.read_cycle_form a = cf([[2,3],[4,6],[5,8],[9,11]], 13) b = cf([[1,2,4,7,9,3,5,6,8,10,11,12,13]], 13) #Define ordering of base elements fix = [1,3,5,9,7,11,2,12,4,6,8,10,13] #Define corresponding key functions on numbers and perms based on base element ordering key_single = ordering_to_key(fix) key_perm = ordering_to_perm_key(fix) #Construct group G = Group.fixed_base_group([a,b],fix) #Find all elements in order #Print the base and stab orbits of G. print(G.base) level_orbits = [] for level in range(len(G.base)): to_check = sorted(G.orbit(G.base[level],level), key = key_single) level_orbits.append(to_check) print(to_check) #Set up the modulo values for a naive traversal. mods = [len(orbit) for orbit in level_orbits] def inc(count, resets):#incrementor function for the naive traversal sig = len(count) - 1 while (count[sig] + 1) % resets[sig] == 0:
if __name__ == '__main__': from _example_path_tools import add_path_examples add_path_examples() from permutation import Permutation from group import PermGroup from schreier_sims import _coset_rep_inverse as rep cf = lambda x: Permutation.read_cycle_form(x,5) a = cf([[2,3,4]]) b = cf([[1,2,3,4,5]]) A5 = PermGroup.fixed_base_group([a,b],[1,2,3]) print(A5.base) print(A5.strong_generators) for sg in A5.schreier_graphs: for image in range(1, 6): print("{}: {}".format(image, rep(image, sg, A5.identity)))
from _example_path_tools import add_path_examples add_path_examples() from partition import Partition from permutation import Permutation from group import PermGroup as Group from coset_property import permutation_commuter cf =Permutation.read_cycle_form a = cf([[1, 2]],4) check = permutation_commuter(a) b = cf([[1,2,3,4]], 4) c = cf([[3, 4]], 4) d = cf([[2, 3]], 4) e = cf([[3, 4]], 4) G = Group([a,b]) G1 = Group([c,d]) G2 = Group([e]) identity = cf([],4) sub = Group([identity]) for g in G._list_elements(): d = sub * g * sub p_flag = check(g) d_flag = d.mid_minimal() if g != identity and p_flag and d_flag: sub = Group([t for t in sub.generators + [g] if t != identity]) print("{}\nprop: {}\nmin: {} sub: {}\nd: {}\n".format(g, p_flag, d_flag, sub.generators, d._list_elements())) Dcosets = [(G2*g*G1, g) for g in G._list_elements()] for d, g in sorted(Dcosets,key = lambda x: x[0]._list_elements()): eles = d._list_elements() #print("{} ({}) {}:\n{}\n".format(g,len(eles),d.mid_minimal(),eles))