# Independent oracle: enumerate entire p-fold slot list and anchored kills, # rather than updating only the two active free phases. import subprocess,math,re,json,collections from pathlib import Path P=Path(__file__).parent primes=[2,3,5,7,11,13,17,19,23,29] def runs(bits): if all(bits):raise AssertionError('all-killed unsupported fixture') start=bits.index(False);hist=collections.Counter();n=0 for b in bits[start+1:]+bits[:start+1]: if b:n+=1 elif n:hist[n]+=1;n=0 assert n==0 return hist checks=[] for x in [7,11,13]: W=math.prod(p for p in primes if p<=x) slots=[n for n in range(W) if math.gcd(n,W)==math.gcd(n+2,W)==1] qs=[7,11,13,17,19,31,37,41,113,127] text=subprocess.check_output([str(P/'stream_check'),str(x),','.join(map(str,qs))],text=True) for line in text.splitlines(): if not line.startswith('p '):continue p=int(line.split()[1]);got={int(a):int(b) for a,b in re.findall(r'(\d+):(\d+)',line)} if W%p: want=runs([(n+k*W)%p in (0,p-2) for k in range(p) for n in slots]) else: want=collections.Counter() for a in range(p):want.update(runs([(n-a)%p in (0,2) for n in slots])) assert got==dict(want),(x,p,got,want) checks.append({'x':x,'p':p,'D':len(slots),'spectrum':got}) (P/'small-check.json').write_text(json.dumps({'method':'direct full folded list / all phases at p dividing W','cases':checks,'all_match':True},indent=2)+'\n');print('30 independent full-fold spectra PASS')