import json,math def kl(q,p): if q==0:return -math.log1p(-p) if q==1:return -math.log(p) return q*math.log(q/p)+(1-q)*math.log((1-q)/(1-p)) def upper(q,c): if q==1:return 1. lo=q;hi=1. for _ in range(100): mid=(lo+hi)/2 if mid==1:hi=mid;continue if kl(q,mid)<=c:lo=mid else:hi=mid return (lo+hi)/2 assert abs(math.log(1/.25)-math.log(4))<1e-14 for q in [0.,.01,.1,.5,.9]: for c in [.01,.05,.1,.5]: p=upper(q,c);assert p>=q and abs(kl(q,p)-c)<1e-10 for c in [.01,.1,.5]:assert abs(upper(0,c)-(1-math.exp(-c)))<1e-12 # Explicit invalid shortcut: the sample-selected prior equals the point posterior. posterior=[0.,0.,1.,0.] adaptive_prior=list(posterior) point_kl=sum(q*math.log(q/p)for q,p in zip(posterior,adaptive_prior)if q>0) assert point_kl==0. def fixed_prior_eligible(prior_dependencies): return not prior_dependencies.get("uses_certification_sample",False) dependencies={"uses_certification_sample":True,"chosen_after_posterior":True} assert not fixed_prior_eligible(dependencies) assert fixed_prior_eligible({"uses_certification_sample":False}) # This audits the declared dependency premise; it is not a theorem prover. ns=[20,50,100,500,1000];ms=[1,2,4,16,64,256];delta=.05 bound=lambda n,k,m=1:1-math.exp(-(k+math.log(2*math.sqrt(n)/delta)+math.log(m))/n) assert bound(50,math.log(4))>bound(100,math.log(4)) figures=[{"id":"sample-prior","kind":"analytical_curve","caption":"Author-constructed fixed-prior certificate arithmetic: zero empirical stochastic loss, delta=.05, KL log4 or log100. No actual trained network is certified.","x":{"name":"Certification sample size n","values":ns},"series":[{"name":"KL=log4 upper risk","values":[bound(n,math.log(4))for n in ns]},{"name":"KL=log100 upper risk","values":[bound(n,math.log(100))for n in ns]}]},{"id":"selection-cost","kind":"analytical_curve","caption":"Author-constructed n=100, zero empirical stochastic loss, delta=.05, base KL log4. Simultaneous confidence over M independently prespecified priors adds log M; plotted series are upper risks, not adaptive-prior certificates.","x":{"name":"Prespecified prior count M","values":ms},"series":[{"name":"Valid family-selection upper risk","values":[bound(100,math.log(4),m)for m in ms]},{"name":"One prespecified prior upper risk","values":[bound(100,math.log(4))for m in ms]}]}] print(json.dumps({"status":"PASS","checks":["Discrete point-mass KL","Bernoulli-kl bisection residual","Zero-loss exact inversion","Adaptive-prior negative control ineligible","Split-sample denominator sensitivity"],"eligibility_check_is_theorem_proof":False,"empirical_benchmark":False,"source_proofs_verified":False,"figures":figures}))