Esempio n. 1
0
def test_PermutationGroup():
    assert PermutationGroup() == PermutationGroup(Permutation())

    a = Permutation(1, 2)
    b = Permutation(2, 3, 1)
    G = PermutationGroup(a, b, degree=5)
    assert G.contains(G[0])

    A = AlternatingGroup(4)
    A.schreier_sims()
    assert A.base == [0, 1]
    assert A.basic_stabilizers == [
        PermutationGroup(Permutation(0, 1, 2), Permutation(1, 2, 3)),
        PermutationGroup(Permutation(1, 2, 3))
    ]

    D = DihedralGroup(12)
    assert D.is_primitive(randomized=False) is False

    D = DihedralGroup(10)
    assert D.is_primitive() is False

    p = Permutation(0, 1, 2, 3, 4, 5)
    G1 = PermutationGroup([Permutation(0, 1, 2), Permutation(0, 1)])
    G2 = PermutationGroup([Permutation(0, 2), Permutation(0, 1, 2)])
    G3 = PermutationGroup([p, p**2])
    assert G1.order() == G2.order() == G3.order() == 6
    assert G1.is_subgroup(G2) is True
    assert G1.is_subgroup(G3) is False

    a, b = [Permutation([1, 0, 3, 2]), Permutation([1, 3, 0, 2])]
    G = PermutationGroup([a, b])
    assert G.make_perm([0, 1, 0]) == Permutation(0, 2, 3, 1)

    S = SymmetricGroup(5)
    base, strong_gens = S.schreier_sims_random()
    assert _verify_bsgs(S, base, strong_gens)

    D = DihedralGroup(4)
    assert D.strong_gens == [
        Permutation(0, 1, 2, 3),
        Permutation(0, 3)(1, 2),
        Permutation(1, 3)
    ]

    a = Permutation([1, 2, 0])
    b = Permutation([1, 0, 2])
    G = PermutationGroup([a, b])
    assert G.transitivity_degree == 3

    a = Permutation([1, 2, 0, 4, 5, 6, 3])
    G = PermutationGroup([a])
    assert G.orbit(0) == {0, 1, 2}
    assert G.orbit([0, 4], 'union') == {0, 1, 2, 3, 4, 5, 6}
    assert G.orbit([0, 4], 'sets') == {(0, 3), (0, 4), (0, 5), (0, 6), (1, 3),
                                       (1, 4), (1, 5), (1, 6), (2, 3), (2, 4),
                                       (2, 5), (2, 6)}
    assert G.orbit([0, 4], 'tuples') == {(0, 3), (0, 4), (0, 5), (0, 6),
                                         (1, 3), (1, 4), (1, 5), (1, 6),
                                         (2, 3), (2, 4), (2, 5), (2, 6)}
Esempio n. 2
0
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)]]))