Skip to content

Instantly share code, notes, and snippets.

@larsbratholm
Created March 15, 2017 14:10
Show Gist options
  • Save larsbratholm/dcf41ca6a548de3f4f2e6727fda4b282 to your computer and use it in GitHub Desktop.
Save larsbratholm/dcf41ca6a548de3f4f2e6727fda4b282 to your computer and use it in GitHub Desktop.
from sympy import *
import itertools
def do_replacement(expr):
queue = [expr]
permutations = []
while len(queue) > 0:
next_queue = []
for item in queue:
permutations.append(str(item))
for replacement in replacements:
replaced_item = item.replace(*replacement)
if item == replaced_item:
continue
# print item, replaced_item, replacement
if str(replaced_item) not in permutations:
next_queue.append(replaced_item)
queue = next_queue[:]
for item in permutations:
print item
sn, sm, rn, rm, e = symbols('sn sm rn rm e', commutative = False)
a = Wild('a', exclude=[1])
b = Wild('b', exclude=[1])
W = Function('W')
WT = Function('WT')
Q = Function('Q')
QT = Function('QT')
U = Function('U')
UT = Function('UT')
replacements = [(QT(a)*Q(a), 1),
(Q(a)*QT(a), 1),
(WT(a)*W(a), 1),
(W(a)*WT(a), 1),
(UT(a)*U(a), 1),
(U(a)*UT(a), 1),
(Q(a)*b, W(b)*a),
(a*WT(b), b*QT(a)),
(QT(a)*a, e),
(a*Q(a),e),
(WT(a)*a, e),
(a*W(a), e),
(U(a)*a, e),
(a*UT(a), e),
(UT(a)*a,e),
(a*U(a),e),
(Q(Q(a)*b),Q(a)*Q(b)),
(W(W(a)*b),W(a)*W(b)),
(Q(a)*WT(b), WT(b)*Q(a)),
(W(a)*QT(b), QT(b)*W(a)),
(WT(a)*QT(b), QT(b)*WT(a)),
(Q(a)*W(b),W(b)*Q(a)),
(W(a)*UT(b), UT(a)*QT(b)),
(U(b)*WT(a), Q(b)*U(a)),
(W(a)*U(b), UT(a)*WT(b)),
(W(a)*U(b), Q(b)*UT(a)),
(W(a)*U(b), U(b)*QT(a)),
(UT(a)*WT(b), Q(b)*UT(a)),
(UT(a)*WT(b), U(b)*QT(a)),
(Q(b)*UT(a), U(b)*QT(a)),
(UT(b)*WT(a), W(b)*U(a)),
(UT(b)*WT(a), U(a)*QT(b)),
(UT(b)*WT(a), Q(b)*UT(b)),
(W(b)*U(a),U(a)*QT(b)),
(W(b)*U(a), Q(b)*UT(b)),
(U(a)*QT(b), Q(b)*UT(b)),
(WT(a)*UT(b), U(a)*W(b)),
(WT(a)*UT(b), QT(b)*U(a)),
(WT(a)*UT(b), UT(b)*Q(a)),
(U(a)*W(b), QT(b)*U(a)),
(U(a)*W(b), UT(b)*Q(a)),
(QT(b)*U(a), UT(b)*Q(a)),
(U(b)*W(a), WT(b)*UT(a)),
(U(b)*W(a), UT(a)*Q(b)),
(U(b)*W(a), QT(b)*U(b)),
(WT(b)*UT(a),UT(a)*Q(b)),
(WT(b)*UT(a), QT(b)*U(b)),
(UT(a)*Q(b), QT(b)*U(b)),
(WT(a)*U(b), U(b)*Q(a)),
(UT(b)*W(a), QT(a)*UT(b)),
(U(a)*UT(b), Q(a)*QT(b)),
(U(a)*U(b), Q(a)*WT(b)),
(UT(a)*UT(b), W(a)*QT(b)),
(UT(a)*U(b), W(a)*WT(b)),
(rn*rn, 1),
(rn*sn, 1),
(rm*rm, 1),
(rm*sm, 1) ]
expr = sn*W(rn)*WT(rm)*sm
do_replacement(expr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment