#!/usr/bin/env python3 """Recompute all submitted A/B values using the hash-pinned published engine. The optional --preflight-only checks structure, not the numerical census. """ import argparse, functools, hashlib, importlib.util, json, math, pathlib, subprocess ap=argparse.ArgumentParser() ap.add_argument('--threads',type=int,default=4) ap.add_argument('--preflight-only',action='store_true') args=ap.parse_args() P=pathlib.Path(__file__).resolve().parent source=P/'kstar.c' assert hashlib.sha256(source.read_bytes()).hexdigest()=='4d3faa05291d3533890f6fb2ad11b8b5d22e1697ba85bcb86b713ce531ac7aba' assert hashlib.sha256((P/'keep4567.json').read_bytes()).hexdigest()=='aff5f769c45dd65eb3d518abe040c76be0f0b2fb2930d39a075559772c290fba' assert hashlib.sha256((P/'dbound2612.py').read_bytes()).hexdigest()=='f667d0b794404fdcb6468b687609239892a6becd1a2ec94a53b0dd0e79b8819b' population=json.loads((P/'keep4567.json').read_text())['rows'] a=json.loads((P/'A4568.json').read_text()) b=json.loads((P/'B4568.json').read_text()) assert len(a)==4000 and len({tuple(r['R']) for r in a})==4000 assert [{k:r[k] for k in ['R','M','Ahat','p_kept']} for r in a]==population assert all(30*math.prod(r['R'])==r['M'] and 3e8=2: expected.append({'R':r['R'],'p':prime,'A':r['A'],'M':r['M'],'Mp':r['M']*prime}) expected.sort(key=lambda r:(r['Mp'],r['R'],r['p'])) assert len(b)==len(expected), 'missing or extra B row' assert [{k:r[k] for k in ['R','p','A','M','Mp']} for r in b]==expected assert all(r['rise']==r['B']-r['A'] for r in b) if args.preflight_only: print('STRUCTURE PASS; numerical values not recomputed') raise SystemExit(0) subprocess.run(['cc','-O2','-o',str(P/'kstar-check'),str(source),'-lpthread'],check=True) def evaluate(rows): text=''.join(f"{base} {prime} {len(rs)} {' '.join(map(str,rs))}\n" for base,prime,rs in rows) lines=subprocess.run([str(P/'kstar-check'),str(args.threads)],input=text,text=True,capture_output=True,check=True).stdout.splitlines() assert len(lines)==len(rows) out=[] for line,(base,prime,rs) in zip(lines,rows): vals=list(map(int,line.split()));assert vals[:-1]==[base,prime,*rs];out.append(vals[-1]) return out assert evaluate([(30,1,r['R']) for r in a])==[r['A'] for r in a], 'A census mismatch' assert evaluate([(30,r['p'],r['R']) for r in b])==[r['B'] for r in b], 'B census mismatch' print(f"PASS: {len(a)} A values; {len(b)} B values; complete exact-D gate")