"""Nonzero-error compatibility for deterministic anchors and stable count tests. Decimal numerical implementation of the proved formulas. The rational example certificate is separate. No global optimizer for the full ten-mean set is used. """ from decimal import Decimal as D, localcontext from functools import wraps from paired_core import radius, GUARD from affine_certificate import probe_certificate def powd(x,y): return (y*x.ln()).exp() def numerical_decision(fn): @wraps(fn) def wrapped(*args,**kwargs): result=fn(*args,**kwargs) result['arithmetic']='80-digit Decimal approximation; not interval-certified' result['decision_scope']='Treat a near-boundary boolean as inconclusive until separately certified.' return result return wrapped @numerical_decision def deterministic_boundary(beta,r,t,band): with localcontext() as ctx: ctx.prec=80 lo,hi=band if not (0<=lo<=hi<=1 and all(0b for a,b in zip(lower,upper)): return dict(compatible=False,kappa=k,common_lower=lower,common_upper=upper) p=c[1]/c[0] chord=lambda z:((high[0]-z)*powd(low[0],p)+(z-low[0])*powd(high[0],p))/(high[0]-low[0]) if p>1: compatible=powd(lower[0],p)<=upper[1]+GUARD and chord(upper[0])+GUARD>=lower[1] elif p<1: compatible=chord(lower[0])<=upper[1]+GUARD and powd(upper[0],p)+GUARD>=lower[1] else: compatible=max(lower)<=min(upper)+GUARD return dict(compatible=compatible,kappa=k,common_lower=lower,common_upper=upper,power=p) @numerical_decision def minimum_radius(beta,r,t): with localcontext() as ctx: ctx.prec=80 low,high=min(t),max(t);q=r*r;c=-2*r.ln() if not (01-q:return dict(compatible=False,radius=None) z=min(low,1-width) a,b=-(z+width).ln()/c,-z.ln()/c return dict(compatible=True,radius=(b-a)/2,band=[a,b],center=(a+b)/2,exponential_width=width) def stable_population(beta,baseline,strong,intermediate,r,eps): V=[a-2*r*b+r*r*c for a,b,c in zip(strong,baseline,beta)] if min(V)<0:raise ValueError('negative quadratic deviation') private=min(beta[0],beta[1],1-beta[0],1-beta[1]) width=1-powd(r,4*min(eps,D('.5'))) bound=r*(abs(beta[0]-beta[1])+private*width)+3*sum((b*v).sqrt() for b,v in zip(beta,V)) return dict(deviations=V,difference=abs(intermediate[0]-intermediate[1]),bound=bound, margin=abs(intermediate[0]-intermediate[1])-bound) def stable_count_certificate(data,r=D('.5')): probe_certificate(data) # Shared schema validation, not a premise of this leg. if D(data['contract']['step'])!=D('.5') or not 0bound, arithmetic='80-digit Decimal with guards; numerical, not formal interval arithmetic')