csci5607/assignment-2b/make_statements.py
2023-04-25 19:52:54 -05:00

26 lines
609 B
Python

def mkslot(m, i, j):
ij = j + i * 4
return f"{m}[{ij}]"
# return m + "xyzw"[i] + str(j + 1)
def mm(leftcalled = "l", rightcalled = "r"):
stmts = []
for i in range(4):
for j in range(4):
res = mkslot("m", i, j)
terms = []
for k in range(4):
left = mkslot(leftcalled, i, k)
right = mkslot(rightcalled, k, j)
term = f"{left} * {right}"
terms.append(term)
stmt = f"{res} = {' + '.join(terms)};"
stmts.append(stmt)
return "\n".join(stmts)
print(mm())