"""Check the eleven cleanup rows with symbolic affine h-run lengths.""" from tag15 import RULES # Each triple represents c + a*x + b*t. x is the lift of the current # section and t the lift of the terminal controller. Every middle run # can use its own x, since a middle run plus its counter preserves lane. FIRST = [(1980,2048),(990,1024),(494,512),(247,256),(124,128),(62,64), (31,32),(16,16),(8,8),(3,4),(1,2)] MIDDLE = [(1024,2048),(512,1024),(256,512),(128,256),(64,128),(32,64), (16,32),(8,16),(4,8),(2,4),(1,2)] LAST = [(2046,2048,0),(1023,1024,0),(512,512,0),(2281,256,2048), (1140,128,1024),(570,64,512),(285,32,256),(142,16,128), (71,8,64),(36,4,32),(18,2,16)] def half(row, lane, extra=0): c, a, b = row assert a % 2 == b % 2 == 0 return ((c+1-lane)//2 + extra, a//2, b//2) def check(): rules = RULES B, U, Z = "lmlr", rules["l"], rules["m"] W, E = "pp" + "rp"*7, "pprppr" C = [B*2,(U*2)*2,E*2,B*4,Z*4,W*2,B*2,Z*2,W,B,Z,""] def projection(word,lane): return "".join(rules[c] for c in word[lane::2]) for j, counter in enumerate(C[:-1]): f, m, s = (*FIRST[j],0), (*MIDDLE[j],0), LAST[j] lane_c = f[0] % 2 lane_m = (lane_c + len(counter)) % 2 assert (m[0]+len(counter)) % 2 == 0 assert projection(counter,lane_c) == C[j+1] assert projection(counter,(lane_m+m[0])%2) == C[j+1] # The controller tails on rows 0, 1, 2 have even total width. odd = (lane_m+s[0]) % 2 f_next, m_next = half(f,0,-odd), half(m,lane_m) s_next = half(s,lane_m) if j==2: assert (lane_m+s[0])%2==0 assert projection("hrrd",0)==projection("hg",0)=="h" s_next=(s_next[0]+2025,s_next[1],s_next[2]+2048) if j<10: assert f_next==(*FIRST[j+1],0) and m_next==(*MIDDLE[j+1],0) assert s_next==LAST[j+1] else: assert C[j+1]=="" and f_next==m_next==(1,1,0) assert s_next==(9,1,8) print("All eleven affine cleanup transitions agree for every nonnegative lift.") if __name__ == "__main__": check()