Skip to content

Instantly share code, notes, and snippets.

@robinhouston
Last active August 26, 2020 22:14
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 robinhouston/86e7b093139e630e71b8bbc5a208b2b0 to your computer and use it in GitHub Desktop.
Save robinhouston/86e7b093139e630e71b8bbc5a208b2b0 to your computer and use it in GitHub Desktop.
import math
TABLE = {
(0, +1): (+1, True), # ()
(1, +1): (-1, False), # (0 1 2)
(2, +1): (-1, True), # (0 2 1)
(0, -1): (+1, False), # (0 1)
(1, -1): (-1, True), # (1 2)
(2, -1): (+1, True) # (0 2)
}
def compose(tr1, tr2):
(t1, r1), (t2, r2) = tr1, tr2
return (t1 + r1*t2, r1*r2)
def subst(x, y):
z = {}
for ((t0, r0), n0) in x.items():
# Let tr1 be the dequoted version of (t0, r0)
t1 = (-t0) // 3
r1, should_substitute = TABLE[t0 % 3, r0]
tr1 = (t1, r1)
# and substitute where appropriate
if should_substitute:
for (tr2, n2) in y.items():
tr3 = compose(tr1, tr2)
z[tr3] = z.get(tr3, 0) + n0 * n2
else:
z[tr1] = z.get(tr1, 0) + n0
return z
x = { (-1, +1): 1, (0, +1): 1, (+1, +1): 1 }
print(sum(x.values()))
for i in range(10):
x = subst(x, x)
print(sum(x.values()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment