Skip to content

Instantly share code, notes, and snippets.

@mihaild
Created June 9, 2020 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mihaild/d07b7cd339c95a43067cb4c0b1a7698a to your computer and use it in GitHub Desktop.
Save mihaild/d07b7cd339c95a43067cb4c0b1a7698a to your computer and use it in GitHub Desktop.
from functools import lru_cache
def mul_by_a(x):
return ((x[0] + 1) % 8, x[1], x[2], )
def mul_by_b(x):
return (x[0] * 3 % 8, (x[1] + 1) % 4, x[2], )
def pow_ab(n):
res = (0, 0, 0)
n %= 3
for i in range(n):
res = mul_by_a(mul_by_b(res))
return res
def mul_by_c(x):
return ((x[0] * 7) % 8, (x[1] * 3) % 4, (x[2] + 1) % 2, )
@lru_cache(None)
def mul(x, y):
for i in range(x[2]):
y = mul_by_c(y)
for i in range(x[1]):
y = mul_by_b(y)
for i in range(x[0]):
y = mul_by_a(y)
return y
def check_assoc(elements):
elements = sorted(elements)
for x in elements:
for y in elements:
for z in elements:
u = mul(x, mul(y, z))
v = mul(mul(x, y), z)
assert u == v, (x, y, z, u, v)
def check_unity(elements):
u = (0, 0, 0)
for x in elements:
assert mul(x, u) == x, x
assert mul(u, x) == x, x
def order(x):
result = 1
tmp = x
while tmp != (0, 0, 0):
tmp = mul(tmp, x)
result += 1
return result
def is_gen(s):
to_check = [(0, 0, 0)]
checked = set(to_check)
while to_check:
x = to_check.pop()
for e in s:
p = mul(e, x)
if p not in checked:
to_check.append(p)
checked.add(p)
return len(checked) == 64
def commute(x, y):
return mul(x, y) == mul(y, x)
elements = [(i, j, k) for i in range(8) for j in range(4) for k in range(2)]
assert len(elements) == 64
check_assoc(elements)
check_unity(elements)
for e1 in elements:
for e2 in elements:
if is_gen([e1, e2]):
print(e1, e2)
exit()
for e1 in elements:
for e2 in elements:
if commute(e1, e2):
for e3 in elements:
if is_gen([e1, e2, e3]):
print(e1, e2, e3)
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment