Created
April 6, 2013 03:46
-
-
Save forestbelton/5324672 to your computer and use it in GitHub Desktop.
Symmetric group arithmetic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Computes ab in the symmetric group S_n, where a and b are given in cyclic | |
# notation. | |
def compose(a, b, n): | |
i = 1 | |
out = [] | |
while not i in out: | |
out.append(i) | |
i = apply(a, apply(b, i)) | |
if out == [1]: | |
return [] | |
return out | |
# Computes a(x) for a in S_n and 1 <= x <= n. | |
def apply(a, x): | |
if x in a: | |
return a[(a.index(x) + 1) % len(a)] | |
else: | |
return x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment