"""Exact scalar certificate and conditional domination for the audited rational rule.""" from fractions import Fraction as F from itertools import product from pathlib import Path import argparse import json HERE=Path(__file__).resolve().parent Q=F(1117,2000) G=F(59,100) D=F(13,200) T=F(33,100) PATH=F(387,1000) MAJ=F(4085,10000) MINOR=F(4735,10000) def require(ok,label): if not ok: raise ValueError(label) def bound_rows(q): p=1-q def f(u,v): return (p+q*u)/(p+q*(u+v)) a,b=1/(1+q),1/q av=1/(1+G*q) soft=q/(q*q+D*(1-q*q)) tilt=1/(1-2*D) generic=min(a,f(T,b)) retained=min(av,f(T,G*b)) comparisons=[ ("one-success softened failure ratio at least one",soft,F(1)), ("softened failure <= ordinary failure",b,soft), ("uniform leaf lower",a,T), ("uniform expanded branch lower",f(T*T,b),T), ("ordinary root message",F(1),PATH), ("generic opposite-type transition",f(T*T,1),PATH), ("generic same-type paired failure",f(retained*PATH,soft),PATH), ("generic same-type paired success",f(generic*PATH,tilt),PATH), ("generic same-type without sibling",f(generic*G*PATH,1),PATH), ("terminal same-type paired failure",f(av*PATH,soft),MAJ), ("terminal same-type paired success",f(a*PATH,tilt),MAJ), ("terminal same-type without sibling",f(a*G*PATH,1),MAJ), ("terminal opposite-type",f(T*T,1),MINOR), ("root child message",F(1),MAJ), ] for label,lhs,rhs in comparisons: require(lhs>=rhs,label) return {"a":a,"B":b,"a_gamma":av,"soft_failure":soft,"pair_success_tilt":tilt, "generic_minor_branch":generic,"thinned_minor_branch":retained, "comparisons":[(name,str(x),str(y)) for name,x,y in comparisons]} def vector(q,maj,minor,state): p=1-q success=p if state==1 else 1-q*q # oriented as a P parent: 1=01,2=10,3=11 masses=[success**m.bit_count()*(1-success)**(maj-m.bit_count()) for m in range(1<>maj else 1-rare) if minor else 1)) return result def upsets(dim): masks=[0,1] for j in range(dim): width=1<>m&1),up) for up in upsets(n)] margin,event=min(values) return {"majority":maj,"minority":minor,"effective_input":z,"events":len(values), "min_margin":margin,"upset_mask":event} def build(): q=Q bounds=bound_rows(q) checks=[] for maj,minor in product(range(3),range(2)): if maj+minor==0: continue # Same-type or root-born: full slots allowed. # Opposite-type child: geometric obstruction leaves <=1 majority. lower=min(MAJ,G*MINOR) if maj<=1 else MAJ for z in (lower,F(1)): checks.append(check_law(q,maj,minor,z)) require(all(row["min_margin"]>0 for row in checks),"nonpositive event") root=1-q*q-q require(root>0,"root independent coupling") return dict(q=q,p=1-q,retain=G,drop_each=D,branch_lower=T,path_lower=PATH, majority_final=MAJ,minority_final=MINOR,scalar=bounds, root_child_parameter_margin=root,checks=checks) if __name__=='__main__': parser=argparse.ArgumentParser() parser.add_argument("--write",action="store_true") parser.add_argument("--refined",action="store_true",help="use the final 10^-5 trial-grid endpoint") args=parser.parse_args() if args.refined: Q,G,D=F(".55855"),F(".5836"),F(".0674") PATH,MAJ,MINOR=F(".3888"),F(".41009"),F(".4734") file=HERE/("refined-certificate.json" if args.refined else "certificate.json") result=json.loads(json.dumps(build(),default=str)) if args.write: file.write_text(json.dumps(result,indent=2)+"\n",encoding="utf-8") else: require(json.loads(file.read_bytes())==result,"certificate mismatch") print("PASS",result["q"],min(float(F(row["min_margin"])) for row in result["checks"]))