def test_Permutation_Cycle(): from sympy.combinatorics import Permutation, Cycle # general principle: economically, canonically show all moved elements # and the size of the permutation. for p, s in [ (Cycle(), '()'), (Cycle(2), '(2)'), (Cycle(2, 1), '(1 2)'), (Cycle(1, 2)(5)(6, 7)(10), '(1 2)(6 7)(10)'), (Cycle(3, 4)(1, 2)(3, 4), '(1 2)(4)'), ]: assert str(p) == s Permutation.print_cyclic = False for p, s in [ (Permutation([]), 'Permutation([])'), (Permutation([], size=1), 'Permutation([0])'), (Permutation([], size=2), 'Permutation([0, 1])'), (Permutation([], size=10), 'Permutation([], size=10)'), (Permutation([1, 0, 2]), 'Permutation([1, 0, 2])'), (Permutation([1, 0, 2, 3, 4, 5]), 'Permutation([1, 0], size=6)'), (Permutation([1, 0, 2, 3, 4, 5], size=10), 'Permutation([1, 0], size=10)'), ]: assert str(p) == s Permutation.print_cyclic = True for p, s in [ (Permutation([]), '()'), (Permutation([], size=1), '(0)'), (Permutation([], size=2), '(1)'), (Permutation([], size=10), '(9)'), (Permutation([1, 0, 2]), '(2)(0 1)'), (Permutation([1, 0, 2, 3, 4, 5]), '(5)(0 1)'), (Permutation([1, 0, 2, 3, 4, 5], size=10), '(9)(0 1)'), (Permutation([0, 1, 3, 2, 4, 5], size=10), '(9)(2 3)'), ]: assert str(p) == s
def test_Permutation_Cycle(): from sympy.combinatorics import Permutation, Cycle # general principle: economically, canonically show all moved elements # and the size of the permutation. for p, s in [ (Cycle(), "()"), (Cycle(2), "(2)"), (Cycle(2, 1), "(1 2)"), (Cycle(1, 2)(5)(6, 7)(10), "(1 2)(6 7)(10)"), (Cycle(3, 4)(1, 2)(3, 4), "(1 2)(4)"), ]: assert sstr(p) == s for p, s in [ (Permutation([]), "Permutation([])"), (Permutation([], size=1), "Permutation([0])"), (Permutation([], size=2), "Permutation([0, 1])"), (Permutation([], size=10), "Permutation([], size=10)"), (Permutation([1, 0, 2]), "Permutation([1, 0, 2])"), (Permutation([1, 0, 2, 3, 4, 5]), "Permutation([1, 0], size=6)"), (Permutation([1, 0, 2, 3, 4, 5], size=10), "Permutation([1, 0], size=10)"), ]: assert sstr(p, perm_cyclic=False) == s for p, s in [ (Permutation([]), "()"), (Permutation([], size=1), "(0)"), (Permutation([], size=2), "(1)"), (Permutation([], size=10), "(9)"), (Permutation([1, 0, 2]), "(2)(0 1)"), (Permutation([1, 0, 2, 3, 4, 5]), "(5)(0 1)"), (Permutation([1, 0, 2, 3, 4, 5], size=10), "(9)(0 1)"), (Permutation([0, 1, 3, 2, 4, 5], size=10), "(9)(2 3)"), ]: assert sstr(p) == s
def test_Cycle(): # FIXME: sT fails because Cycle is not immutable and calling srepr(Cycle(1, 2)) # adds keys to the Cycle dict (GH-17661) #import_stmt = "from sympy.combinatorics import Cycle" #sT(Cycle(1, 2), "Cycle(1, 2)", import_stmt) assert srepr(Cycle(1, 2)) == "Cycle(1, 2)"
from sympy.combinatorics import Permutation, Cycle from sympy.combinatorics.named_groups import SymmetricGroup S5 = SymmetricGroup(5) S5_elems = list(S5.generate_schreier_sims()) IDENTITY = Permutation(4) ALPHA = Permutation(Cycle(0, 1, 2, 3, 4)) BETA = Permutation(Cycle(0, 2, 4, 3, 1)) ALPHA_INV = (~ALPHA) BETA_INV = (~BETA) COMMUTATOR = ALPHA * BETA * ALPHA_INV * BETA_INV ELEMENTS = [ALPHA, ALPHA_INV, BETA, BETA_INV, COMMUTATOR] CONJUGATORS = {e: {} for e in ELEMENTS} for e1 in ELEMENTS: for e2 in ELEMENTS: for gamma in S5_elems: if gamma * e1 * (~gamma) == e2: CONJUGATORS[e1][e2] = (gamma, ~gamma) break class GroupInstruction(object): def __init__(self, index, g0, g1): self.index = index self.g0 = g0 self.g1 = g1 def __str__(self): return str(self.index).ljust(4) + str(self.g0).ljust(15) + str( self.g1).ljust(13)