"""Positive-exposure realizations and two lower-pair diagnostics; not an optimizer.""" from decimal import Decimal as D, localcontext from pathlib import Path import json from local_boundary import construct, power def kl(x,y): return D(0) if x==y else x*(x/y).ln()+(1-x)*((1-x)/(1-y)).ln() def run(): with localcontext() as ctx: ctx.prec=80 r,e,b=D('.1'),D('.1'),D('1e-5') checks={};rows=[];pairs=[] for p in map(D,['.01','.001','1e-5','1e-7']): beta=1-p;h=(b*p).sqrt();u=e+D('.01') nodes=[r-h,r+h];M=sum(power(x,1+4*u) for x in nodes)/2 s=power(r,1+4*e) ys=[r/2+(1-2*p)*s/2,(1-2*p)*r/2+s/2] zs=[(y-beta*M)/(r-M) for y in ys] dominating=max(zs)+max(beta-z for z in zs) assert all(D(0)9 # Both lower-bound mechanisms, including the deterministic h=0 edge. n=D(10)**24; c=D('1e-5');L=-r.ln() for p in map(D,['1e-4','1e-6','1e-8']): beta=1-p;s=power(r,1+4*e);ys=[r/2+(1-2*p)*s/2,(1-2*p)*r/2+s/2] delta=c*min(1/n.sqrt(),p) reg=-(1-(ys[0]+delta-ys[1])/(p*r)).ln()/(4*L)-e assert reg>0 and n*kl(ys[0]+delta,ys[0])b*p:continue sigma=c*min(h,1/n.sqrt().sqrt(),p) gap=D(0);div=D(0) if sigma: _,vv=construct(beta,r,sigma,e);ww=[v[:] for v in vv] for v in ww:v[2],v[3]=beta*r*r,beta*r**3 div=n*sum(kl(x,y) for v,w in zip(vv,ww) for x,y in zip(v,w)) gap=-(1-(vv[0][4]-vv[1][4])/(p*r)).ln()/(4*L)-e assert gap>0 and divD('1e-6') pairs.append({'p':str(p),'h':str(h),'regular_gap':str(reg),'heterogeneous_gap_lower':str(gap),'heterogeneous_KL':str(div),'capped_rate':str(rate)}) checks['regular_pair_radius_and_KL']=True checks['heterogeneous_pair_radius_and_KL']=True checks['maximum_of_pairs_matches_capped_two_scale_rate']=True checks['zero_heterogeneity_edge_retains_regular_lower_pair']=any(x['h']=='0' for x in pairs) result={'identity':'Decimal finite realization diagnostics; no uniform proof, global solver or empirical coverage claim','checks':checks,'all_passed':all(checks.values()),'realizations':rows,'lower_pairs':pairs} Path(__file__).with_name('two_scale_output.json').write_text(json.dumps(result,indent=2)+'\n') print(json.dumps({'checks':checks,'all_passed':result['all_passed'],'realizations':len(rows),'pairs':len(pairs)},indent=2)) if __name__=='__main__':run()