def test_equality(): p_1 = Permutation(0, 1, 3) p_2 = Permutation(0, 2, 3) p_3 = Permutation(0, 1, 2) p_4 = Permutation(0, 1, 3) g_1 = PermutationGroup(p_1, p_2) g_2 = PermutationGroup(p_3, p_4) g_3 = PermutationGroup(p_2, p_1) assert g_1 == g_2 assert g_1.generators != g_2.generators assert g_1 == g_3
def test_is_normal(): gens_s5 = [Permutation(p) for p in [[1, 2, 3, 4, 0], [2, 1, 4, 0, 3]]] G1 = PermutationGroup(gens_s5) assert G1.order() == 120 gens_a5 = [Permutation(p) for p in [[1, 0, 3, 2, 4], [2, 1, 4, 3, 0]]] G2 = PermutationGroup(gens_a5) assert G2.order() == 60 assert G2.is_normal(G1) gens3 = [Permutation(p) for p in [[2, 1, 3, 0, 4], [1, 2, 0, 3, 4]]] G3 = PermutationGroup(gens3) assert not G3.is_normal(G1) assert G3.order() == 12 G4 = G1.normal_closure(G3.generators) assert G4.order() == 60 gens5 = [Permutation(p) for p in [[1, 2, 3, 0, 4], [1, 2, 0, 3, 4]]] G5 = PermutationGroup(gens5) assert G5.order() == 24 G6 = G1.normal_closure(G5.generators) assert G6.order() == 120 assert G1.is_subgroup(G6) assert not G1.is_subgroup(G4) assert G2.is_subgroup(G4) s4 = PermutationGroup(Permutation(0, 1, 2, 3), Permutation(3)(0, 1)) s6 = PermutationGroup(Permutation(0, 1, 2, 3, 5), Permutation(5)(0, 1)) assert s6.is_normal(s4, strict=False) assert not s4.is_normal(s6, strict=False)
def test_make_perm(): assert cube.pgroup.make_perm(5, seed=list(range(5))) == \ Permutation([4, 7, 6, 5, 0, 3, 2, 1]) assert cube.pgroup.make_perm(7, seed=list(range(7))) == \ Permutation([6, 7, 3, 2, 5, 4, 0, 1]) pytest.raises(ValueError, lambda: cube.pgroup.make_perm({}, [0])) random.seed(0) assert cube.pgroup.make_perm(5) == Permutation([2, 1, 5, 6, 3, 0, 4, 7]) random.seed(0) assert cube.pgroup.make_perm(5, seed=1) == Permutation( [0, 3, 7, 4, 1, 2, 6, 5])
def test_derived_subgroup(): a = Permutation([1, 0, 2, 4, 3]) b = Permutation([0, 1, 3, 2, 4]) G = PermutationGroup([a, b]) C = G.derived_subgroup() assert C.order() == 3 assert C.is_normal(G) assert C.is_subgroup(G, 0) assert not G.is_subgroup(C, 0) gens_cube = [[1, 3, 5, 7, 0, 2, 4, 6], [1, 3, 0, 2, 5, 7, 4, 6]] gens = [Permutation(p) for p in gens_cube] G = PermutationGroup(gens) C = G.derived_subgroup() assert C.order() == 12
def test_no_metric_symmetry(): # no metric symmetry # A^d1_d0 * A^d0_d1; ord = [d0,-d0,d1,-d1]; g= [2,1,0,3,4,5] # T_c = A^d0_d1 * A^d1_d0; can = [0,3,2,1,4,5] g = Permutation([2, 1, 0, 3, 4, 5]) can = canonicalize(g, list(range(4)), None, [[], [Permutation(list(range(4)))], 2, 0]) assert can == [0, 3, 2, 1, 4, 5] # A^d1_d2 * A^d0_d3 * A^d2_d1 * A^d3_d0 # ord = [d0,-d0,d1,-d1,d2,-d2,d3,-d3] # 0 1 2 3 4 5 6 7 # g = [2,5,0,7,4,3,6,1,8,9] # T_c = A^d0_d1 * A^d1_d0 * A^d2_d3 * A^d3_d2 # can = [0,3,2,1,4,7,6,5,8,9] g = Permutation([2, 5, 0, 7, 4, 3, 6, 1, 8, 9]) # can = canonicalize(g, list(range(8)), 0, [[], [list(range(4))], 4, 0]) # assert can == [0, 2, 3, 1, 4, 6, 7, 5, 8, 9] can = canonicalize(g, list(range(8)), None, [[], [Permutation(list(range(4)))], 4, 0]) assert can == [0, 3, 2, 1, 4, 7, 6, 5, 8, 9] # A^d0_d2 * A^d1_d3 * A^d3_d0 * A^d2_d1 # g = [0,5,2,7,6,1,4,3,8,9] # T_c = A^d0_d1 * A^d1_d2 * A^d2_d3 * A^d3_d0 # can = [0,3,2,5,4,7,6,1,8,9] g = Permutation([0, 5, 2, 7, 6, 1, 4, 3, 8, 9]) can = canonicalize(g, list(range(8)), None, [[], [Permutation(list(range(4)))], 4, 0]) assert can == [0, 3, 2, 5, 4, 7, 6, 1, 8, 9] g = Permutation([12, 7, 10, 3, 14, 13, 4, 11, 6, 1, 2, 9, 0, 15, 8, 5, 16, 17]) can = canonicalize(g, list(range(16)), None, [[], [Permutation(list(range(4)))], 8, 0]) assert can == [0, 3, 2, 5, 4, 7, 6, 1, 8, 11, 10, 13, 12, 15, 14, 9, 16, 17]
def test_bell_perm(): assert [len(set(generate_bell(i))) for i in range(1, 7)] == [ factorial(i) for i in range(1, 7)] assert list(generate_bell(3)) == [ (0, 1, 2), (0, 2, 1), (2, 0, 1), (2, 1, 0), (1, 2, 0), (1, 0, 2)] # generate_bell and trotterjohnson are advertised to return the same # permutations; this is not technically necessary so this test could # be removed for n in range(1, 5): p = Permutation(range(n)) b = generate_bell(n) for bi in b: assert bi == tuple(p.array_form) p = p.next_trotterjohnson() pytest.raises(ValueError, lambda: list(generate_bell(0))) # XXX is this consistent with other permutation algorithms?
def test_verify_centralizer(): # verified by GAP S = SymmetricGroup(3) A = AlternatingGroup(3) triv = PermutationGroup([Permutation([0, 1, 2])]) assert _verify_centralizer(S, S, centr=triv) assert _verify_centralizer(S, A, centr=A)
def test_strip(): D = DihedralGroup(5) D.schreier_sims() member = Permutation([4, 0, 1, 2, 3]) not_member1 = Permutation([0, 1, 4, 3, 2]) not_member2 = Permutation([3, 1, 4, 2, 0]) identity = Permutation([0, 1, 2, 3, 4]) res1 = _strip(member, D.base, D.basic_orbits, D.basic_transversals) res2 = _strip(not_member1, D.base, D.basic_orbits, D.basic_transversals) res3 = _strip(not_member2, D.base, D.basic_orbits, D.basic_transversals) assert res1[0] == identity assert res1[1] == len(D.base) + 1 assert res2[0] == not_member1 assert res2[1] == len(D.base) + 1 assert res3[0] != identity assert res3[1] == 2
def test_normal_closure(): # the normal closure of the trivial group is trivial S = SymmetricGroup(3) identity = Permutation([0, 1, 2]) closure = S.normal_closure(identity) assert closure.is_trivial # the normal closure of the entire group is the entire group A = AlternatingGroup(4) assert A.normal_closure(A).is_subgroup(A) # brute-force verifications for subgroups for i in (3, 4, 5): S = SymmetricGroup(i) A = AlternatingGroup(i) D = DihedralGroup(i) C = CyclicGroup(i) for gp in (A, D, C): assert _verify_normal_closure(S, gp) # brute-force verifications for all elements of a group for i in range(10): S = SymmetricGroup(5) elements = list(S.generate_dimino()) for element in elements: assert _verify_normal_closure(S, element) # small groups small = [] for i in (1, 2, 3): small.append(SymmetricGroup(i)) small.append(AlternatingGroup(i)) small.append(DihedralGroup(i)) small.append(CyclicGroup(i)) for gp in small: for gp2 in small: if gp2.is_subgroup(gp, 0) and gp2.degree == gp.degree: assert _verify_normal_closure(gp, gp2)
def test_bell_perm(): assert [len(set(generate_bell(i))) for i in range(1, 7)] == [factorial(i) for i in range(1, 7)] assert list(generate_bell(3)) == [(0, 1, 2), (0, 2, 1), (2, 0, 1), (2, 1, 0), (1, 2, 0), (1, 0, 2)] # generate_bell and trotterjohnson are advertised to return the same # permutations; this is not technically necessary so this test could # be removed for n in range(1, 5): p = Permutation(range(n)) b = generate_bell(n) for bi in b: assert bi == tuple(p.array_form) p = p.next_trotterjohnson() pytest.raises(ValueError, lambda: list(generate_bell( 0))) # XXX is this consistent with other permutation algorithms?
def test_handle_precomputed_bsgs(): A = AlternatingGroup(5) A.schreier_sims() base = A.base strong_gens = A.strong_gens result = _handle_precomputed_bsgs(base, strong_gens) strong_gens_distr = _distribute_gens_by_base(base, strong_gens) assert strong_gens_distr == result[2] transversals = result[0] orbits = result[1] base_len = len(base) for i in range(base_len): for el in orbits[i]: assert transversals[i][el](base[i]) == el for j in range(i): assert transversals[i][el](base[j]) == base[j] order = 1 for i in range(base_len): order *= len(orbits[i]) assert A.order() == order _, transversals = _orbits_transversals_from_bsgs(base, strong_gens_distr) assert transversals == _handle_precomputed_bsgs(base, strong_gens, transversals)[0] assert transversals == _handle_precomputed_bsgs( base, strong_gens, transversals, basic_orbits=transversals, strong_gens_distr=strong_gens_distr)[0] D = DihedralGroup(3) D.schreier_sims() assert (_handle_precomputed_bsgs(D.base, D.strong_gens, basic_orbits=D.basic_orbits) == ([{ 0: Permutation(2), 1: Permutation(0, 1, 2), 2: Permutation(0, 2) }, { 1: Permutation(2), 2: Permutation(1, 2) }], [[0, 1, 2], [1, 2]], [[ Permutation(0, 1, 2), Permutation(0, 2), Permutation(1, 2) ], [Permutation(1, 2)]]))
def test_strong_gens_from_distr(): strong_gens_distr = [[ Permutation([0, 2, 1]), Permutation([1, 2, 0]), Permutation([1, 0, 2]) ], [Permutation([0, 2, 1])]] assert _strong_gens_from_distr(strong_gens_distr) == \ [Permutation([0, 2, 1]), Permutation([1, 2, 0]), Permutation([1, 0, 2])] assert _strong_gens_from_distr([[Permutation(0, 1)]]) == [Permutation(0, 1)]
def test_has(): a = Permutation([1, 0]) G = PermutationGroup([a]) assert G.is_abelian a = Permutation([2, 0, 1]) b = Permutation([2, 1, 0]) G = PermutationGroup([a, b]) assert not G.is_abelian G = PermutationGroup([a]) assert G.has(a) assert not G.has(b) a = Permutation([2, 0, 1, 3, 4, 5]) b = Permutation([0, 2, 1, 3, 4]) assert PermutationGroup(a, b).degree == \ PermutationGroup(a, b).degree == 6
def test_eq(): a = [[1, 2, 0, 3, 4, 5], [1, 0, 2, 3, 4, 5], [2, 1, 0, 3, 4, 5], [ 1, 2, 0, 3, 4, 5]] a = [Permutation(p) for p in a + [[1, 2, 3, 4, 5, 0]]] g = Permutation([1, 2, 3, 4, 5, 0]) G1, G2, G3 = [PermutationGroup(x) for x in [a[:2], a[2:4], [g, g**2]]] assert G1.order() == G2.order() == G3.order() == 6 assert G1.is_subgroup(G2) assert not G1.is_subgroup(G3) G4 = PermutationGroup([Permutation([0, 1])]) assert not G1.is_subgroup(G4) assert G4.is_subgroup(G1, 0) assert PermutationGroup(g, g).is_subgroup(PermutationGroup(g)) assert SymmetricGroup(3).is_subgroup(SymmetricGroup(4), 0) assert SymmetricGroup(3).is_subgroup(SymmetricGroup(3)*CyclicGroup(5), 0) assert not CyclicGroup(5).is_subgroup(SymmetricGroup(3)*CyclicGroup(5), 0) assert CyclicGroup(3).is_subgroup(SymmetricGroup(3)*CyclicGroup(5), 0)
def test_centralizer(): # the centralizer of the trivial group is the entire group S = SymmetricGroup(2) assert S.centralizer(Permutation(list(range(2)))).is_subgroup(S) A = AlternatingGroup(5) assert A.centralizer(Permutation(list(range(5)))).is_subgroup(A) # a centralizer in the trivial group is the trivial group itself triv = PermutationGroup([Permutation([0, 1, 2, 3])]) D = DihedralGroup(4) assert triv.centralizer(D).is_subgroup(triv) # brute-force verifications for centralizers of groups for i in (4, 5, 6): S = SymmetricGroup(i) A = AlternatingGroup(i) C = CyclicGroup(i) D = DihedralGroup(i) for gp in (S, A, C, D): for gp2 in (S, A, C, D): if not gp2.is_subgroup(gp): assert _verify_centralizer(gp, gp2) # verify the centralizer for all elements of several groups S = SymmetricGroup(5) elements = list(S.generate_dimino()) for element in elements: assert _verify_centralizer(S, element) A = AlternatingGroup(5) elements = list(A.generate_dimino()) for element in elements: assert _verify_centralizer(A, element) D = DihedralGroup(7) elements = list(D.generate_dimino()) for element in elements: assert _verify_centralizer(D, element) # verify centralizers of small groups within small groups small = [] for i in (1, 2, 3): small.append(SymmetricGroup(i)) small.append(AlternatingGroup(i)) small.append(DihedralGroup(i)) small.append(CyclicGroup(i)) for gp in small: for gp2 in small: if gp.degree == gp2.degree: assert _verify_centralizer(gp, gp2)
def test_tensorsymmetry(): sym = tensorsymmetry([1]*2) sym1 = TensorSymmetry(get_symmetric_group_sgs(2)) assert sym == sym1 sym = tensorsymmetry([2]) sym1 = TensorSymmetry(get_symmetric_group_sgs(2, 1)) assert sym == sym1 sym2 = tensorsymmetry() assert sym2.base == Tuple() and sym2.generators == Tuple(Permutation(1)) pytest.raises(NotImplementedError, lambda: tensorsymmetry([2, 1]))
def cyclic_form(self): """Return the indices of the corners in cyclic notation. The indices are given relative to the original position of corners. See Also ======== corners, array_form """ return Perm._af_new(self.array_form).cyclic_form
def test_pointwise_stabilizer(): S = SymmetricGroup(2) stab = S.pointwise_stabilizer([0]) assert stab.generators == [Permutation(1)] S = SymmetricGroup(5) points = [] stab = S for point in (2, 0, 3, 4, 1): stab = stab.stabilizer(point) points.append(point) assert S.pointwise_stabilizer(points).is_subgroup(stab)
def test_distribute_gens_by_base(): base = [0, 1, 2] gens = [ Permutation([0, 1, 2, 3]), Permutation([0, 1, 3, 2]), Permutation([0, 2, 3, 1]), Permutation([3, 2, 1, 0]) ] assert _distribute_gens_by_base(base, gens) == [ gens, [ Permutation([0, 1, 2, 3]), Permutation([0, 1, 3, 2]), Permutation([0, 2, 3, 1]) ], [Permutation([0, 1, 2, 3]), Permutation([0, 1, 3, 2])] ]
def test_generate(): a = Permutation([1, 0]) g = list(PermutationGroup([a]).generate()) assert g == [Permutation([0, 1]), Permutation([1, 0])] assert len(list(PermutationGroup(Permutation((0, 1))).generate())) == 1 g = PermutationGroup([a]).generate(method='dimino') assert list(g) == [Permutation([0, 1]), Permutation([1, 0])] a = Permutation([2, 0, 1]) b = Permutation([2, 1, 0]) G = PermutationGroup([a, b]) g = G.generate() v1 = [p.array_form for p in list(g)] v1.sort() assert v1 == [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]] v2 = list(G.generate(method='dimino', af=True)) assert v1 == sorted(v2) a = Permutation([2, 0, 1, 3, 4, 5]) b = Permutation([2, 1, 3, 4, 5, 0]) g = PermutationGroup([a, b]).generate(af=True) assert len(list(g)) == 360
def test_Cycle(): assert str(Cycle()) == 'Cycle()' assert Cycle(Cycle(1, 2)) == Cycle(1, 2) assert Cycle(1, 2).copy() == Cycle(1, 2) assert list(Cycle(1, 3, 2)) == [0, 3, 1, 2] assert Cycle(1, 2)(2, 3) == Cycle(1, 3, 2) assert Cycle(1, 2)(2, 3)(4, 5) == Cycle(1, 3, 2)(4, 5) assert Permutation(Cycle(1, 2)(2, 1, 0, 3)).cyclic_form, Cycle(0, 2, 1) pytest.raises(ValueError, lambda: Cycle().list()) assert Cycle(1, 2).list() == [0, 2, 1] assert Cycle(1, 2).list(4) == [0, 2, 1, 3] assert Cycle().size == 0 assert Cycle(3).list(2) == [0, 1] assert Cycle(3).list(6) == [0, 1, 2, 3, 4, 5] assert Permutation(Cycle(1, 2), size=4) == Permutation([0, 2, 1, 3]) assert str(Cycle(1, 2)(4, 5)) == 'Cycle(1, 2)(4, 5)' assert str(Cycle(1, 2)) == 'Cycle(1, 2)' assert Cycle(Permutation(list(range(3)))) == Cycle() assert Cycle(1, 2).list() == [0, 2, 1] assert Cycle(1, 2).list(4) == [0, 2, 1, 3] pytest.raises(ValueError, lambda: Cycle((1, 2))) pytest.raises(ValueError, lambda: Cycle(1, 2, 1)) pytest.raises(TypeError, lambda: Cycle(1, 2)*{}) pytest.raises(ValueError, lambda: Cycle(4)[a]) pytest.raises(ValueError, lambda: Cycle(2, -4, 3)) # check round-trip p = Permutation([[1, 2], [4, 3]], size=5) assert Permutation(Cycle(p)) == p
def test_random_pr(): D = DihedralGroup(6) r = 11 n = 3 _random_prec_n = {} _random_prec_n[0] = {'s': 7, 't': 3, 'x': 2, 'e': -1} _random_prec_n[1] = {'s': 5, 't': 5, 'x': 1, 'e': -1} _random_prec_n[2] = {'s': 3, 't': 4, 'x': 2, 'e': 1} D._random_pr_init(r, n, _random_prec_n=_random_prec_n) assert D._random_gens[11] == [0, 1, 2, 3, 4, 5] _random_prec = {'s': 2, 't': 9, 'x': 1, 'e': -1} assert D.random_pr(_random_prec=_random_prec) == \ Permutation([0, 5, 4, 3, 2, 1])
def test_coset_rank(): gens_cube = [[1, 3, 5, 7, 0, 2, 4, 6], [1, 3, 0, 2, 5, 7, 4, 6]] gens = [Permutation(p) for p in gens_cube] G = PermutationGroup(gens) i = 0 for h in G.generate(af=True): rk = G.coset_rank(h) assert rk == i h1 = G.coset_unrank(rk, af=True) assert h == h1 i += 1 assert G.coset_unrank(48) is None assert G.coset_unrank(G.coset_rank(gens[0])) == gens[0]
def _string_to_perm(s): rv = [Perm(range(20))] p = None for si in s: if si not in '01': count = int(si) - 1 else: count = 1 if si == '0': p = _f0 elif si == '1': p = _f1 rv.extend([p]*count) return Perm.rmul(*rv)
def test_lower_central_series(): # the lower central series of the trivial group consists of the trivial # group triv = PermutationGroup([Permutation([0, 1, 2])]) assert triv.lower_central_series()[0].is_subgroup(triv) # the lower central series of a simple group consists of the group itself for i in (5, 6, 7): A = AlternatingGroup(i) assert A.lower_central_series()[0].is_subgroup(A) # GAP-verified example S = SymmetricGroup(6) series = S.lower_central_series() assert len(series) == 2 assert series[1].is_subgroup(AlternatingGroup(6))
def test_derived_series(): # the derived series of the trivial group consists only of the trivial group triv = PermutationGroup([Permutation([0, 1, 2])]) assert triv.derived_series()[0].is_subgroup(triv) # the derived series for a simple group consists only of the group itself for i in (5, 6, 7): A = AlternatingGroup(i) assert A.derived_series()[0].is_subgroup(A) # the derived series for S_4 is S_4 > A_4 > K_4 > triv S = SymmetricGroup(4) series = S.derived_series() assert series[1].is_subgroup(AlternatingGroup(4)) assert series[2].is_subgroup(DihedralGroup(2)) assert series[3].is_trivial
def test_canonicalize_no_dummies(): base1, gens1 = get_symmetric_group_sgs(1) base2, gens2 = get_symmetric_group_sgs(2) base2a, gens2a = get_symmetric_group_sgs(2, 1) # A commuting # A^c A^b A^a; ord = [a,b,c]; g = [2,1,0,3,4] # T_c = A^a A^b A^c; can = list(range(5)) g = Permutation([2, 1, 0, 3, 4]) can = canonicalize(g, [], 0, (base1, gens1, 3, 0)) assert can == list(range(5)) # A anticommuting # A^c A^b A^a; ord = [a,b,c]; g = [2,1,0,3,4] # T_c = -A^a A^b A^c; can = [0,1,2,4,3] g = Permutation([2, 1, 0, 3, 4]) can = canonicalize(g, [], 0, (base1, gens1, 3, 1)) assert can == [0, 1, 2, 4, 3] # A commuting and symmetric # A^{b,d}*A^{c,a}; ord = [a,b,c,d]; g = [1,3,2,0,4,5] # T_c = A^{a c}*A^{b d}; can = [0,2,1,3,4,5] g = Permutation([1, 3, 2, 0, 4, 5]) can = canonicalize(g, [], 0, (base2, gens2, 2, 0)) assert can == [0, 2, 1, 3, 4, 5] # A anticommuting and symmetric # A^{b,d}*A^{c,a}; ord = [a,b,c,d]; g = [1,3,2,0,4,5] # T_c = -A^{a c}*A^{b d}; can = [0,2,1,3,5,4] g = Permutation([1, 3, 2, 0, 4, 5]) can = canonicalize(g, [], 0, (base2, gens2, 2, 1)) assert can == [0, 2, 1, 3, 5, 4] # A^{c,a}*A^{b,d} ; g = [2,0,1,3,4,5] # T_c = A^{a c}*A^{b d}; can = [0,2,1,3,4,5] g = Permutation([2, 0, 1, 3, 4, 5]) can = canonicalize(g, [], 0, (base2, gens2, 2, 1)) assert can == [0, 2, 1, 3, 4, 5]
def test_riemann_invariants(): baser, gensr = riemann_bsgs # R^{d0 d1}_{d1 d0}; ord = [d0,-d0,d1,-d1]; g = [0,2,3,1,4,5] # T_c = -R^{d0 d1}_{d0 d1}; can = [0,2,1,3,5,4] g = Permutation([0, 2, 3, 1, 4, 5]) can = canonicalize(g, list(range(2, 4)), 0, (baser, gensr, 1, 0)) assert can == [0, 2, 1, 3, 5, 4] # use a non minimal BSGS can = canonicalize(g, list(range(2, 4)), 0, ([2, 0], [Permutation([1, 0, 2, 3, 5, 4]), Permutation([2, 3, 0, 1, 4, 5])], 1, 0)) assert can == [0, 2, 1, 3, 5, 4] """ The following tests in test_riemann_invariants and in test_riemann_invariants1 have been checked using xperm.c from XPerm in in [1] and with an older version contained in [2] [1] xperm.c part of xPerm written by J. M. Martin-Garcia http://www.xact.es/index.html [2] test_xperm.cc in cadabra by Kasper Peeters, http://cadabra.phi-sci.com/ """ # R_d11^d1_d0^d5 * R^{d6 d4 d0}_d5 * R_{d7 d2 d8 d9} * # R_{d10 d3 d6 d4} * R^{d2 d7 d11}_d1 * R^{d8 d9 d3 d10} # ord: contravariant d_k ->2*k, covariant d_k -> 2*k+1 # T_c = R^{d0 d1 d2 d3} * R_{d0 d1}^{d4 d5} * R_{d2 d3}^{d6 d7} * # R_{d4 d5}^{d8 d9} * R_{d6 d7}^{d10 d11} * R_{d8 d9 d10 d11} g = Permutation([23, 2, 1, 10, 12, 8, 0, 11, 15, 5, 17, 19, 21, 7, 13, 9, 4, 14, 22, 3, 16, 18, 6, 20, 24, 25]) can = canonicalize(g, list(range(24)), 0, (baser, gensr, 6, 0)) assert can == [0, 2, 4, 6, 1, 3, 8, 10, 5, 7, 12, 14, 9, 11, 16, 18, 13, 15, 20, 22, 17, 19, 21, 23, 24, 25] # use a non minimal BSGS can = canonicalize(g, list(range(24)), 0, ([2, 0], [Permutation([1, 0, 2, 3, 5, 4]), Permutation([2, 3, 0, 1, 4, 5])], 6, 0)) assert can == [0, 2, 4, 6, 1, 3, 8, 10, 5, 7, 12, 14, 9, 11, 16, 18, 13, 15, 20, 22, 17, 19, 21, 23, 24, 25] g = Permutation([0, 2, 5, 7, 4, 6, 9, 11, 8, 10, 13, 15, 12, 14, 17, 19, 16, 18, 21, 23, 20, 22, 25, 27, 24, 26, 29, 31, 28, 30, 33, 35, 32, 34, 37, 39, 36, 38, 1, 3, 40, 41]) can = canonicalize(g, list(range(40)), 0, (baser, gensr, 10, 0)) assert can == [0, 2, 4, 6, 1, 3, 8, 10, 5, 7, 12, 14, 9, 11, 16, 18, 13, 15, 20, 22, 17, 19, 24, 26, 21, 23, 28, 30, 25, 27, 32, 34, 29, 31, 36, 38, 33, 35, 37, 39, 40, 41]
def test_mul(): a, b = [0, 2, 1, 3], [0, 1, 3, 2] assert _af_rmul(a, b) == [0, 2, 3, 1] assert _af_rmuln(a, b, list(range(4))) == [0, 2, 3, 1] assert rmul(Permutation(a), Permutation(b)).array_form == [0, 2, 3, 1] a = Permutation([0, 2, 1, 3]) b = (0, 1, 3, 2) c = (3, 1, 2, 0) assert Permutation.rmul(a, b, c) == Permutation([1, 2, 3, 0]) assert Permutation.rmul(a, c) == Permutation([3, 2, 1, 0]) pytest.raises(TypeError, lambda: Permutation.rmul(b, c)) n = 6 m = 8 a = [Permutation.unrank_nonlex(n, i).array_form for i in range(m)] h = list(range(n)) for i in range(m): h = _af_rmul(h, a[i]) h2 = _af_rmuln(*a[:i + 1]) assert h == h2
def _naive_list_centralizer(self, other, af=False): from diofant.combinatorics.perm_groups import PermutationGroup """ Return a list of elements for the centralizer of a subgroup/set/element. This is a brute force implementation that goes over all elements of the group and checks for membership in the centralizer. It is used to test ``.centralizer()`` from ``diofant.combinatorics.perm_groups``. Examples ======== >>> from diofant.combinatorics.testutil import _naive_list_centralizer >>> from diofant.combinatorics.named_groups import DihedralGroup >>> D = DihedralGroup(4) >>> _naive_list_centralizer(D, D) [Permutation([0, 1, 2, 3]), Permutation([2, 3, 0, 1])] See Also ======== diofant.combinatorics.perm_groups.centralizer """ from diofant.combinatorics.permutations import _af_commutes_with if hasattr(other, 'generators'): elements = list(self.generate_dimino(af=True)) gens = [x._array_form for x in other.generators] def commutes_with_gens(x): return all(_af_commutes_with(x, gen) for gen in gens) centralizer_list = [] if not af: for element in elements: if commutes_with_gens(element): centralizer_list.append(Permutation._af_new(element)) else: for element in elements: if commutes_with_gens(element): centralizer_list.append(element) return centralizer_list elif hasattr(other, 'getitem'): return _naive_list_centralizer(self, PermutationGroup(other), af) elif hasattr(other, 'array_form'): return _naive_list_centralizer(self, PermutationGroup([other]), af)
def check(h, size, rpt, target): assert len(h.faces) + len(h.vertices) - len(h.edges) == 2 assert h.size == size got = set() for p in h.pgroup: # make sure it restores original P = h.copy() hit = P.corners for _ in range(rpt): P.rotate(p) if P.corners == hit: break else: print('error in permutation', p.array_form) for _ in range(rpt): P.rotate(p) got.add(tuple(P.corners)) c = P.corners f = [[c[i] for i in f] for f in P.faces] assert h.faces == Polyhedron(c, f).faces assert len(got) == target assert PermutationGroup([Permutation(g) for g in got]).is_group