"""FL numerical count certificate and two-atom finite mixture compatibility. Count CLI: python3 this_file.py counts.json Counts use the PB two-group eight-outcome schema, without null_bound. Mean-log interval coverage requires fixed design and iid complete repeats within each preparation, for conditional or mixed marginal laws. The standalone conditional_zero_rank_exclusion additionally requires the same fixed or repeatably conditioned environment and common calibration across both preparations. The outer affine module uses only the intervals for its mixed-law allowance test. This module does not observe unknown environmental labels. 80-digit Decimal with 1e-60 allowance, not formal interval arithmetic. """ import argparse from decimal import Decimal, localcontext import json from pathlib import Path from paired_core import number, radius, serializable, KEYS, GUARD, MAX_N def log_certificate(data): if not isinstance(data, dict) or set(data) != {'alpha','groups'}: raise ValueError('use exactly alpha and groups; this conditional null has zero determinant') alpha=number(data['alpha'],'alpha',Decimal('1e-30'),Decimal(1)) if alpha==1:raise ValueError('alpha must be less than 1') groups=data['groups'] if not isinstance(groups,list) or len(groups)!=2:raise ValueError('two H1,H2 groups required') with localcontext() as ctx: ctx.prec=80 t=(Decimal(20)/alpha).ln()+GUARD output=[] for j,g in enumerate(groups,1): if not isinstance(g,dict) or set(g)!={'outcomes'}:raise ValueError('expected outcomes only') counts=g['outcomes'] if not isinstance(counts,dict) or set(counts)-set(KEYS):raise ValueError('invalid outcome keys') if any(type(v) is not int or v<0 for v in counts.values()):raise ValueError('nonnegative integer counts required') n=sum(counts.values()) if not 1<=n<=MAX_N:raise ValueError('unsupported replicate count') s=t/n vhat=Decimal(sum(v for k,v in counts.items() if k[0]=='0'))/n br=radius(vhat,s) vlo,vhi=max(Decimal(0),vhat-br),min(Decimal(1),vhat+br) resp={} for i in (2,3): plus=sum(v for k,v in counts.items() if int(k[i-1])-int(k[0])==1) minus=sum(v for k,v in counts.items() if int(k[i-1])-int(k[0])==-1) pp,pm=Decimal(plus)/n,Decimal(minus)/n dhat=pp-pm r=radius(pp,s)+radius(pm,s) dlo,dhi=dhat-r,dhat+r safe=vlo>0 and vlo-dhi>0 if safe: corners=[(1-d/v).ln() for v in (vlo,vhi) for d in (dlo,dhi)] lo,hi=min(corners)-GUARD,max(corners)+GUARD ell=(1-dhat/vhat).ln() eta=max(abs(ell-lo),abs(hi-ell))+GUARD else: lo,hi,ell,eta=Decimal('-Infinity'),Decimal('Infinity'),None,None resp[i]={'positive_count':plus,'negative_count':minus,'response':dhat, 'safe':safe,'log_estimate':ell,'log_lower':lo,'log_upper':hi,'radius':eta} output.append({'n':n,'baseline_void':vhat,'baseline_radius':br,'responses':resp}) if not all(r['safe'] for g in output for r in g['responses'].values()): return {'groups':output,'lower':Decimal('-Infinity'),'upper':Decimal('Infinity'), 'conditional_zero_rank_exclusion':False,'determinant':None,'determinant_radius':None, 'scope':'single fixed or repeatably conditioned environment; unsafe log rectangles do not certify'} a,b=output[0]['responses'],output[1]['responses'] ah,bh={i:a[i]['log_estimate'] for i in (2,3)},{i:b[i]['log_estimate'] for i in (2,3)} ar,br={i:a[i]['radius'] for i in (2,3)},{i:b[i]['radius'] for i in (2,3)} det=bh[3]*ah[2]-ah[3]*bh[2] rd=abs(bh[3])*ar[2]+abs(ah[2])*br[3]+abs(ah[3])*br[2]+abs(bh[2])*ar[3]+br[3]*ar[2]+ar[3]*br[2]+GUARD return {'groups':output,'determinant':det,'determinant_radius':rd,'lower':det-rd,'upper':det+rd, 'conditional_zero_rank_exclusion':det-rd>0, 'scope':'single fixed or repeatably conditioned environment; not an unobserved mixture null test'} def fit_finite_mixture(triples): """Construct a common three-point monotone calibration and two-atom N per label. triples is a nonempty list of [q1,q2,q3] using exact decimal strings. Fits the representation contract only; no stationary spacetime grain law. R is restricted here to <=100000 for this numerical implementation. Inputs must preserve 00 for x in v): raise ValueError("probability voids exceed 80-digit resolvable input range") u,w=v[1]/v[0],v[2]/v[0] if not 0100000:raise ValueError('required calibration exceeds numerical implementation range') out=[] for v,u,w in probabilities: goal=(1-w)/(1-u) left,right=Decimal(0),u for _ in range(280): x=(left+right)/2 val=(1-x**R)/(1-x) if val