Exemplo n.º 1
0
 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())
Exemplo n.º 2
0
 def test_identity(self):
     a = Permutation([2, 3, 1, 4])
     c = Permutation([])
     self.assertEqual(a ** -1 * a, Permutation.read_cycle_form([], 4))
     self.assertEqual(a * a ** -1, Permutation.read_cycle_form([], 4))
     self.assertEqual((a * a ** -1)._func, (1, 2, 3, 4))
     self.assertEqual(c._func, ())
Exemplo n.º 3
0
 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))
Exemplo n.º 4
0
 def test_schreier_graph_construction(self):
     s1 = Permutation.read_cycle_form([[2,3]], 4)
     s2 = Permutation.read_cycle_form([[1,2,4]], 4)
     gens = [s1,s2]
     identity = Permutation([1,2,3,4])
     s_g = _schreier_graph(2, gens, identity)
     self.assertEqual(s_g, [s2,identity,s1,s2])
Exemplo n.º 5
0
 def test_klien4(self):
     a = Permutation.read_cycle_form([[1,2],[3,4]],4)
     b = Permutation.read_cycle_form([[1,3],[2,4]],4)
     G = PermGroup([a,b])
     oG = OrbitGraph(G,(1,2))
     self.assertTrue(tuple(sorted(oG.edges)) == ((1,2),(2,1),(3,4),(4,3)))
     self.assertTrue(oG.ad_list == [[2],[1],[4],[3]])
Exemplo n.º 6
0
 def test_cycle_form_reading(self):
     a = Permutation([2, 3, 1, 4])
     b = Permutation.read_cycle_form([], 4)
     e = Permutation([1, 2, 3, 4])
     self.assertEqual(b, e)
     self.assertEqual(a, Permutation.read_cycle_form([[1, 2, 3]], 4))
     self.assertEqual(a, Permutation.read_cycle_form([[2, 3, 1]], 4))
     self.assertEqual(a, Permutation.read_cycle_form([[3, 1, 2]], 4))
Exemplo n.º 7
0
 def test_coset_reps(self):
     s1 = Permutation.read_cycle_form([[2,3]], 4)
     s2 = Permutation.read_cycle_form([[1,2,4]], 4)
     gens = [s1,s2]
     identity = Permutation([1,2,3,4])
     s_g = _schreier_graph(2, gens, identity)
     cosets = _coset_reps(s_g, identity)
     self.assertEqual(cosets, [Permutation.read_cycle_form([[1,4,2]], 4),identity,s1,s2])
Exemplo n.º 8
0
 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))   
Exemplo n.º 9
0
 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)
Exemplo n.º 10
0
 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])
Exemplo n.º 11
0
 def test_schreier_generators(self):
     s1 = Permutation.read_cycle_form([[2,3]], 4)
     s2 = Permutation.read_cycle_form([[1,2,4]], 4)
     gens = [s1,s2]
     identity = Permutation([1,2,3,4])
     s_g = _schreier_graph(2, gens, identity)
     cosets = _coset_reps(s_g, identity)
     s_gen = _schreier_generators(2, cosets, gens, identity)
     gen_1 = Permutation.read_cycle_form([[3,4]], 4)
     gen_2 = Permutation.read_cycle_form([[1,3,4]], 4)
     gen_3 = Permutation.read_cycle_form([[1,3]], 4)
     self.assertEqual(s_gen, [gen_1, gen_2, gen_3])
Exemplo n.º 12
0
 def test_coset(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])
     coset = sorted((H*g1)._list_elements())
     for c in coset:
         self.assertEqual(sorted((H*c)._list_elements()), coset)
     self.assertEqual(len(H), len(coset))
     coset = sorted((g1*H)._list_elements())   
     for c in coset:
         self.assertEqual(sorted((c*H)._list_elements()), coset)
     self.assertEqual(len(H), len(coset))
Exemplo n.º 13
0
 def test_initialisation(self):
     s1 = Permutation.read_cycle_form([[2,3,5,7],[9, 10]], 10)
     s2 = Permutation.read_cycle_form([[1,2,4,8],[9, 10]], 10)
     G = PermGroup([s1, s2])
     base_gen_pairs = list(zip(['_']+G.base, G.chain_generators))
     prev = base_gen_pairs[0][1]
     base_eles = []
     for base_ele, gens in base_gen_pairs[1:-1]:
         base_eles.append(base_ele)
         for g in gens:
             for b in base_eles:
                 self.assertEqual(b, b**g)
         temp = PermGroup(gens)
         self.assertTrue(len([g for g in prev if g not in temp])>0)
         prev = gens   
Exemplo n.º 14
0
 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)
Exemplo n.º 15
0
 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])
Exemplo n.º 16
0
 def test_pow(self):
     perm = Permutation.read_cycle_form([[1,2],[5,3]], 5)
     a = Partition([[1,2,3], [4,5]])
     b = a ** perm
     c = Partition([[1,5,2], [4,3]])
     d = b ** perm
     self.assertEqual(a,d)
     self.assertEqual(b,c)              
     self.assertNotEqual(a,c)                     
     self.assertNotEqual(b,d)        
Exemplo n.º 17
0
 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)
Exemplo n.º 18
0
 def test_identity_modifiers(self):
     cf = lambda x:Permutation.read_cycle_form(x,5)
     fam = RefinementUnion([IdentityFamily()])
     prop = CosetPropertyUnion([IdentityProperty()])
     log = LeonLoggerUnion([LeonCounter()])
     union = ModifierUnion([fam,prop,log])
     a = PartitionStack([0,0,0,0,0],[-1,-1,-1,-1,-1])             
     b = PartitionStack([0,1,1,1,0],[-1,0,0,0,-1])
     funcs = union.extension_functions(a)
     self.assertEqual(funcs,None)
     index = union.exclude_backtrack_index(a,b, None, None)
     self.assertEqual(index,None)
     check = union.property_check(None)
     self.assertTrue(check)
     pos_leaf = union.leaf_fail_backtrack_index(a,b,None)
     neg_leaf = union.leaf_pass_backtrack_index(a,b,None)
     self.assertEqual(pos_leaf, None)
     self.assertEqual(neg_leaf, None)
Exemplo n.º 19
0
    def test_non_trivial_modifiers(self):
        cf = lambda x: Permutation.read_cycle_form(x,13)
        a = cf([[2,3],[4,6],[5,8],[9,11]])
        b = cf([[1,2,4,7,9,3,5,6,8,10,11,12,13]])
        G = PermGroup([a,b])
        part_stab = Partition([[3,2],[6,4],[5,1,7,8,9,10,11,12,13]])
        
        fam = RefinementUnion([PartitionStabaliserFamily(part_stab), SubgroupFamily(G)])
        
        prop = CosetPropertyUnion([PartitionStabaliserProperty(part_stab), SubgroupProperty(G)])
        
        log = LeonLoggerUnion([LeonCounter()])
        
        cons = ModifierUnion([PartitionStackConstraint()])
        
        union = ModifierUnion([fam,prop,log,cons])
        
        left = PartitionStack([0]*13,[-1]*13)         
        right = PartitionStack.deep_copy(left)
        
        funcs = union.extension_functions(left)
        self.assertFalse(funcs is None)
        funcs[0](left)
        funcs[1](right)
        
        index = union.exclude_backtrack_index(left,right, None, 1)
        self.assertEqual(index,None)

        index = union.exclude_backtrack_index(left,right, None, 2)
        self.assertEqual(index,1)
        
        self.assertTrue(union.property_check(a))
        self.assertFalse(union.property_check(b))
        
        pos_leaf = union.leaf_fail_backtrack_index(a,b,None)
        neg_leaf = union.leaf_pass_backtrack_index(a,b,None)
        self.assertEqual(pos_leaf, None)
        self.assertEqual(neg_leaf, None)
Exemplo n.º 20
0
def get_gens(big_rectangle, small_rectangle):
    (W, H) = big_rectangle
    (w, h) = small_rectangle
    (w, h) = (w-1, h-1)
    grid = [list(range(s, s + W)) for s in range(1, H*W+1, W)]
    gens = []
    for row in range(H-h):
        for col in range(W-w):
            gen = []
            #top row
            for index in range(col, col + w):
                gen.append(grid[row][index])
            #right col
            for index in range(row, row + h):
                gen.append(grid[index][col + w])
            #bottom row
            for index in range(col + w, col, -1):
                gen.append(grid[row+h][index])
            #left col
            for index in range(row + h, row, -1):
                gen.append(grid[index][col])
            gens.append(gen)
    return [Permutation.read_cycle_form([gen],W*H) for gen in gens]
def vis_cyclic6():
    b = Permutation.read_cycle_form([[1, 2, 3, 4, 5, 6]], 6)
    G = PermGroup([b])
    oG = OrbitGraph(G, (2, 5))
    draw_orbit_graph(oG)
Exemplo n.º 22
0
 def test_composition(self):
     a = Permutation([2, 3, 1, 4])
     b = Permutation([2, 1, 4, 3])
     self.assertEqual(a * b, Permutation.read_cycle_form([[2, 4, 3]], 4))
     self.assertEqual(b * a, Permutation.read_cycle_form([[1, 3, 4]], 4))
Exemplo n.º 23
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)))
Exemplo n.º 24
0
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))


Exemplo n.º 25
0
 def test_cyclic6(self):
     b = Permutation.read_cycle_form([[1,2,3,4,5,6]],6)
     G = PermGroup([b])
     oG = OrbitGraph(G,(1,2))
     self.assertTrue(tuple(sorted(oG.edges)) == ((1,2),(2,3),(3,4),(4,5),(5,6),(6,1)))
     self.assertTrue(oG.ad_list == [[2],[3],[4],[5],[6],[1]])
Exemplo n.º 26
0
 def test_coset_constructions(self):    
     s1 = Permutation.read_cycle_form([[2,3,5,7]], 8)
     s2 = Permutation.read_cycle_form([[1,2,4,8]], 8)
     self.coset_construction_from_schreier_tree_test([s1, s2])   
Exemplo n.º 27
0
 def test_permutation_commuter_property(self):
     prop = CosetProperty([PermutationCommuterProperty(Permutation([2,1,3,4]))])
     pos = Permutation.read_cycle_form([[3,4]],4)
     neg = Permutation.read_cycle_form([[2,3]],4)
     self.assertTrue(prop.check(pos))
     self.assertFalse(prop.check(neg))
Exemplo n.º 28
0
 def test_partition_stabaliser_property(self):
     prop = CosetProperty([PartitionStabaliserProperty(Partition([[1,2],[3,4],[5]]))])
     pos = Permutation.read_cycle_form([[1,2]],5)
     neg = Permutation.read_cycle_form([[1,2],[4,5]],5)
     self.assertTrue(prop.check(pos))
     self.assertFalse(prop.check(neg))
Exemplo n.º 29
0
 def test_coset_property_init(self):
     prop = CosetProperty([IdentityProperty()])
     self.assertTrue(prop.check(Permutation.read_cycle_form([[1,2,3,4]], 5)))
Exemplo n.º 30
0
 def test_empty_initialisation(self):
     s1 = Permutation.read_cycle_form([], 3)
     G = PermGroup([s1])
     self.assertEqual(len(G), 1)
     G = PermGroup([])
     self.assertEqual(len(G), 1)