"""Verify the third exceptional degree and the degree-20 determinants.""" from collections import defaultdict, Counter from pathlib import Path import argparse import os import subprocess from tempfile import TemporaryDirectory import turn_components as sector def normalize(w): names={} return bytes(names.setdefault(c,len(names)) for c in w) def putfirst(w,i): return normalize(w[i:]+w[:i]) def signature(w): k=len(w) return tuple(i for i in range(k) if w[i]==w[i-1]) def gaps(turns,k): return tuple((b-a)%k for a,b in zip(turns,turns[1:]+turns[:1])) def getgroups(path): groups=defaultdict(set) for line in path.read_bytes().splitlines(): # The C++ generator already starts at a turn with minimal gap list. w=bytes(v-33 for v in line) turns=signature(w);g=gaps(turns,len(w));groups[g].add(w) for j,h in enumerate(turns[1:],1): if g[j:]+g[:j]==g:groups[g].add(putfirst(w,h)) return groups def strips(w): # Four traversals, with the same four letters and alternating orientations. k=len(w) pos=defaultdict(list) for i,c in enumerate(w):pos[c].append(i) for b,indices in pos.items(): if len(indices)!=4:continue i=indices[0] for direction in (1,-1): idx=lambda t: w[(i+t*direction)%k] seq=bytes(idx(t) for t in (-1,0,1,2)) if len(set(seq))!=4 or any(len(pos[e])!=4 for e in seq):continue groups=[];prevdir=0 for j in indices: dirs=[d for d in (1,-1) if all(w[(j+d*t)%k]==z for t,z in zip((-1,0,1,2),seq))] if len(dirs)!=1 or prevdir==dirs[0]:break d=dirs[0];prevdir=d groups.append(tuple((j+d*t)%k for t in (-1,0,1,2))) if len(groups)==4 and len({i for group in groups for i in group})==16: yield tuple(groups) def hasstrip(w,windows): first=bytes(w[j] for j in windows[0]) return len(set(first))==4 and all(w.count(c)==4 for c in first) and all( bytes(w[j] for j in window)==first for window in windows[1:]) def compress(w,remove): return normalize(w[i] for i in range(len(w)) if i not in remove) def all_transferred(ws,previous): w=min(ws) for windows in strips(w): if not all(hasstrip(v,windows) for v in ws):continue remove=sorted(q[1] for q in windows) shortened={compress(v,remove) for v in ws} # Pick a common rotation into the shorter canonical turn sector. v=next(iter(shortened));ts=signature(v);g=gaps(ts,len(v)) rot,key=min(((ts[j],g[j:]+g[:j]) for j in range(len(g))),key=lambda z:z[1]) images={putfirst(v,rot) for v in shortened} if len(images)==len(ws) and images==previous.get(key):return key return None def run(last): with TemporaryDirectory() as temp: folder=Path(temp) executable=folder/'band_orbits' source=Path(__file__).with_name('band_orbits.cpp') subprocess.run([os.environ.get('CXX','c++'),'-O3','-std=c++17', str(source),'-o',str(executable)],check=True) def generate(r,t): path=folder/'orbits.txt' with path.open('w') as stream: subprocess.run([str(executable),str(r),str(t)],stdout=stream,check=True) return path previous={} previous_exponents={} count_direct=count_transfer=0 for r in range(3,last+1): curr=getgroups(generate(r,2)) success=direct=0 current_exponents={} total=Counter() for g,ws in curr.items(): key=all_transferred(ws,previous) if previous else None if key is not None: success+=1 local=previous_exponents[key] else: w=min(ws) mask=tuple(int(w[i]==w[(i+1)%len(w)]) for i in range(len(w))) local=sector.evaluate(sorted(map(tuple,ws)),mask) direct+=1 current_exponents[g]=local stabilizer=sum(g[i:]+g[:i]==g for i in range(len(g))) copies=sum(g)//stabilizer total.update({i:copies*n for i,n in local.items()}) target={1:2*(r+1)*(32*r*r-18*r-21), 2:-2*(r+1)*(32*r*r-34*r-17), 3:-2*(r+1)*(16*r-7), 4:-6*(r+1)} assert {i:n for i,n in total.items() if n}==target print(r,'turn sectors verified by contraction',success,'directly',direct,flush=True) count_direct+=direct count_transfer+=success previous=curr previous_exponents=current_exponents if r==48: assert (count_direct,count_transfer)==(683,289578) if last>=66: print("Third-band exponents verified for r=3 through 66.",flush=True) for r,t in ((3,4),(4,2)): sectors=sector.run(generate(r,t)) expected=({1:194450,2:-125840,3:-55640,4:-11690,5:-1230,6:-50} if r==3 else {1:4190,2:-3590,3:-570,4:-30}) assert sectors==expected if __name__=='__main__': parser=argparse.ArgumentParser(description=__doc__) parser.add_argument('--last-r',default=66,type=int,choices=range(3,67),metavar='3..66') run(parser.parse_args().last_r)