"""Declared finite models for representation articles 6–10. No neural training or network I/O.""" from pathlib import Path import itertools import json import math import numpy as np TOPICS=json.loads((Path(__file__).resolve().parents[1]/"topics.json").read_text(encoding="utf-8")) def run(): panels=[];results=[];points=[] count=0 def ck(value, message): nonlocal count count+=1 assert bool(value),message def near(a,b,atol=1e-10): return bool(np.allclose(a,b,rtol=1e-9,atol=atol)) def panel(n,k,title,xlabel,ylabel,series,caption,xscale="linear",yscale="linear"): slug=TOPICS[n-1][0] panels.append(dict(article=n,number=k,slug=slug,title=title,xlabel=xlabel,ylabel=ylabel, series=[dict(label=label,x=[float(v) for v in x],y=[float(v) for v in y]) for label,x,y in series], caption=caption,xscale=xscale,yscale=yscale,kind="constructed_analytic_example", image=f"figures/{slug}-{k}.png",vector=f"figures/{slug}-{k}.svg",data=f"figures/{slug}-{k}.csv",alt=caption)) def finish(n,name,start,witness,scope): results.append(dict(article=n,slug=TOPICS[n-1][0],check=name,assertions=count-start,witness=witness,scope=scope,status="PASS")) # 6. Exact enumeration of a fair binary label with independent view corruption. start=count qs=np.linspace(0,.5,51);agrees=[];accs=[] for q in qs: joint=np.zeros((2,2,2)) for y,e1,e2 in itertools.product([0,1],repeat=3): p1=q if e1 else 1-q;p2=q if e2 else 1-q joint[y,y^e1,y^e2]+=.5*p1*p2 ck(near(joint.sum(),1),"binary channel mass") agree=sum(joint[y,v,v] for y in [0,1] for v in [0,1]) single=joint.sum(axis=2) bayes=sum(single[:,v].max() for v in [0,1]) ck(near(agree,1-2*q*(1-q)),"two-view agreement") ck(near(bayes,1-q),"single-view Bayes accuracy") agrees.append(agree);accs.append(bayes) ck(near(accs[-1],.5),"full corruption erases label") ck(near(agrees[-1],.5),"full corruption removes pair label agreement") # Nuisance bit S is independent of Y and copied to both views. ys=np.array(list(itertools.product([0,1],repeat=2))) ck(near(sum(ys[:,0]==ys[:,1])/4,.5),"nuisance predicts label only at chance") view1=ys[:,1].copy();view2=ys[:,1].copy() ck(near(np.mean(view1==view2),1) and len(set(view1))==2,"nonconstant shared nuisance perfectly aligned") def loss(pos,neg,tau): z=np.array([pos]+list(neg),dtype=float)/tau m=float(z.max()) return float(m+np.log(np.exp(z-m).sum())-z[0]) taus=np.linspace(.1,2,96) for K in [3,15,63]: for tau in [.1,.2,.5,1,2]: val=loss(1,[0]*K,tau) ck(near(val,math.log1p(K*math.exp(-1/tau))),"candidate-loss special case") ck(near(val,loss(8,[7]*K,tau)),"uniform logit shift") p=1/(1+K*math.exp(-1/tau)) derivative=(loss(1+1e-6,[0]*K,tau)-loss(1-1e-6,[0]*K,tau))/2e-6 ck(near(derivative,(p-1)/tau,atol=2e-8),"positive-logit derivative") panel(6,1,"Pair agreement and label accuracy differ","Independent flip probability q","Probability", [("Positive-pair label-bit agreement",qs,agrees),("Optimal single-view label accuracy",qs,accs)], "Constructed fair binary channel. Each view flips Y independently with probability q. Pair agreement is 1-2q(1-q); single-view Bayes accuracy is 1-q. Neither curve is a trained model result.") panel(6,2,"Temperature changes a fixed candidate loss","Temperature tau","Loss (natural-log units)", [(f"{K} negatives",taus,np.log1p(K*np.exp(-1/taus))) for K in [3,15,63]], "Constructed candidate set with positive similarity 1 and every negative similarity 0. Curves evaluate log(1+K exp(-1/tau)) for K=3,15,63; similarities are held fixed.") points.extend([[6,1,0,.25,.625],[6,2,0,1,math.log(1+3/math.e)]]) finish(6,"Binary view information, nuisance counterexample and contrastive invariants",start, dict(q=.25,pair_agreement=.625,bayes_accuracy=.75,q_half_label_accuracy=.5,nuisance_alignment=1,negative_counts=[3,15,63]), "Finite binary channel enumeration and fixed candidate-loss checks; no contrastive encoder is trained.") # 7. Gaussian second moments and an exhaustive independent-mask construction. start=count rhos=np.linspace(0,1,101) for rho in rhos: cov=np.array([[1,rho],[rho,1]]) ck(np.linalg.eigvalsh(cov).min()>-1e-12,"Gaussian covariance is positive semidefinite") for a in [-1,0,.25,1,2]: vec=np.array([1,-a]) risk=float(vec@cov@vec) ck(near(risk,1-rho*rho+(a-rho)**2),"conditional-risk excess decomposition") ck(risk>=1-rho*rho-1e-12,"conditional mean minimizes linear risk") for copies in range(1,9): for m in [0,.25,.5,.75,1]: total=0.;error=0. for masked in itertools.product([False,True],repeat=copies): k=sum(masked) probability=(m**k)*((1-m)**(copies-k)) total+=probability if all(masked):error+=.5*probability ck(near(total,1),"mask probability mass") ck(near(error,.5*m**copies),"exhaustive mask Bayes error") ms=np.linspace(0,1,101) panel(7,1,"Predictability lowers reconstruction error","Gaussian correlation rho","Expected squared reconstruction error", [("Optimal conditional mean",rhos,1-rhos*rhos),("Constant-zero prediction",rhos,np.ones_like(rhos))], "Declared zero-mean unit-variance joint Gaussian pair (X,V). The optimal predictor is rho V and its MSE is 1-rho^2. An independent semantic bit remains unpredictable at every rho.") panel(7,2,"Redundancy changes evidence survival","Independent mask probability m","Optimal label error", [(f"{r} repeated label location"+("s" if r!=1 else ""),ms,.5*ms**r) for r in [1,4,16]], "A fair label bit is repeated r times; every copy is independently masked with probability m. No other label evidence exists. Bayes error is 0.5 m^r; these are analytic curves, not MAE or BEiT measurements.") points.extend([[7,1,0,.6,.64],[7,2,1,.5,1/32]]) finish(7,"Gaussian conditional risk and exhaustive label-mask enumeration",start, dict(gaussian_rho=.6,optimal_mse=.64,copies=4,mask_probability=.5,label_error=1/32,enumerated_copy_counts=list(range(1,9))), "Second-moment algebra and exhaustive masks for up to eight repeated bits; no image reconstruction model is trained.") # 8. Interface collisions, attention permutation equivariance and pair counts. start=count X=np.array([[1.,0.],[0.,1.],[1.,1.]]) P=np.eye(3)[[2,0,1]] def att(x): z=x@x.T/math.sqrt(x.shape[1]);z-=z.max(axis=1,keepdims=True) a=np.exp(z);a/=a.sum(axis=1,keepdims=True) return a@x for perm in itertools.permutations(range(3)): Pi=np.eye(3)[list(perm)] ck(near(att(Pi@X),Pi@att(X)),"content attention permutation equivariance") E=np.array([[0.,0.],[1.,-.5],[-.5,1.]]) defect=float(np.linalg.norm(att(P@X+E)-P@att(X+E))) ck(defect>1e-3,"fixed absolute positions break token permutation equivariance") ck(near(att(P@(X+E)),P@att(X+E)),"joint content-position permutation restores identity") projection=np.array([[1.,0.,0.,0.],[0.,1.,0.,0.]]) x=np.array([1.,2.,3.,4.]);collision=x+np.array([0.,0.,1.,-1.]) ck(not near(x,collision),"patch inputs differ") ck(near(projection@x,projection@collision),"patch projection collision") ck(np.linalg.matrix_rank(projection)==2,"projection rank") ps=np.array([4,8,16,32],dtype=float) ns=(224/ps)**2 ck(near(ns,[3136,784,196,49]),"integer token counts") ck(near(ns**2,[9834496,614656,38416,2401]),"global candidate counts") ck(near(ns*49,[153664,38416,9604,2401]),"7 by 7 window candidate counts") widths=np.arange(8,65,dtype=float) for d in widths: r=min(48,int(d)) ck(48-r==max(0,48-int(d)),"rank-nullity lower-bound example") panel(8,1,"Patch size changes attention pair counts","Patch side P (pixels)","Query-key pairs per layer", [("Global attention",ps,ns**2),("7 by 7 token windows",ps,ns*49)], "Analytic counts for a 224 by 224 image, divisible patch grids, no class token or padding. Global attention counts N^2 pairs; 7 by 7 token windows count 49N. Projection, feed-forward and hardware costs are excluded.",xscale="log",yscale="log") panel(8,2,"A narrow linear interface must lose directions","Embedding width d","Minimum nullspace dimension", [("48-dimensional patch",widths,np.maximum(0,48-widths))], "Rank-nullity for a hypothetical 4 by 4 RGB patch with D=48 input coordinates. A maximal-rank linear embedding has nullspace dimension max(0,48-d). This does not assert that published ViT embeddings use these dimensions.") points.extend([[8,1,0,16,38416],[8,2,0,32,16]]) finish(8,"Patch collision, all three-token permutations and analytic attention counts",start, dict(patch_input=x.tolist(),collision_input=collision.tolist(),shared_embedding=(projection@x).tolist(),fixed_position_defect=defect,global_pairs_at_P16=38416), "Finite token-attention algebra and specified operation counts; no image benchmark or accelerator profiling.") # 9. Group projection, continuous commutator, symmetry mismatch and chirality. start=count R=np.array([[0.,-1.],[1.,0.]]) group=[np.linalg.matrix_power(R,k) for k in range(4)] W=np.diag([2.,1.]) Wbar=sum(g.T@W@g for g in group)/4 ck(near(Wbar,1.5*np.eye(2)),"group-average projection") for M in [W,np.array([[1.,2.],[3.,4.]]),np.array([[-2.,1.],[0.,7.]])]: projected=sum(g.T@M@g for g in group)/4 for g in group:ck(near(projected@g,g@projected),"all C4 commutators") angles=np.linspace(0,180,181);defects=[] for degrees in angles: t=math.radians(degrees);q=np.array([[math.cos(t),-math.sin(t)],[math.sin(t),math.cos(t)]]) defect=float(np.linalg.norm(W@q-q@W)) ck(near(defect,math.sqrt(2)*abs(math.sin(t))),"continuous commutator formula") defects.append(defect) ts=np.arange(64)*2*math.pi/64 circle=np.vstack([np.cos(ts),np.sin(ts)]) lambdas=np.linspace(0,1,101);target_errors=[];contract_errors=[] for lam in lambdas: mixed=(1-lam)*W+lam*Wbar target=float(np.mean(np.sum(((mixed-W)@circle)**2,axis=0))) contract=float(np.mean(np.sum(((mixed@R-R@mixed)@circle)**2,axis=0))) ck(near(target,.25*lam*lam),"symmetry-mismatch target risk") ck(near(contract,(1-lam)**2),"quarter-turn equivariance risk") target_errors.append(target);contract_errors.append(contract) tetra=np.array([[0.,0.,0.],[1.,0.,0.],[0.,1.,0.],[0.,0.,1.]]) reflected=tetra@np.diag([-1.,1.,1.]) distances=lambda p:np.sum((p[:,None,:]-p[None,:,:])**2,axis=-1) ck(near(distances(tetra),distances(reflected)),"mirror distances") signed=lambda p:float(np.linalg.det((p[1:]-p[0]).T)) ck(near(signed(tetra),1) and near(signed(reflected),-1),"handedness reverses") panel(9,1,"An anisotropic map breaks rotation equivariance","Rotation angle (degrees)","Commutator Frobenius norm", [("W = diag(2,1)",angles,defects),("Group projection W = 1.5 I",angles,np.zeros_like(angles))], "Exact two-dimensional linear example. The norm of W R(theta)-R(theta) W equals sqrt(2)|sin(theta)| for W=diag(2,1); the isotropic group projection has zero defect.") panel(9,2,"Enforcing a wrong symmetry trades away target fit","Mixing toward group projection, lambda","Mean squared vector error", [("Quarter-turn equivariance defect",lambdas,contract_errors),("Error on anisotropic target",lambdas,target_errors)], "Declared target W=diag(2,1), unit-circle inputs and W_lambda=(1-lambda)W+lambda(1.5I). Mean squared target error is lambda^2/4; quarter-turn equivariance error is (1-lambda)^2. This is a deliberate target-symmetry mismatch.") points.extend([[9,1,0,90,math.sqrt(2)],[9,2,0,.5,.25]]) finish(9,"C4 group projection, symmetry mismatch and reflection-sensitive target",start, dict(group_projected_matrix=Wbar.tolist(),lambda_half_target_error=.0625,lambda_half_equivariance_error=.25,oriented_triple_product=1,reflected_triple_product=-1), "Finite-group identities, analytic planar maps and a labeled tetrahedron; no continuous-image or trained EGNN certification.") # 10. Two-node contraction, reinjection fixed point and mean-tree collisions. start=count depths=np.arange(21);series=[] for alpha in [.1,.25,.45]: p=np.array([[1-alpha,alpha],[alpha,1-alpha]]) h=np.array([1.,0.]);observed=[] for k in depths: ck(near(h.sum(),1),"mean preserved") contrast=h[0]-h[1] ck(near(contrast,(1-2*alpha)**int(k)),"spectral contrast decay") observed.append((1-2*alpha)**int(k)) h=p@h series.append((f"Mixing alpha = {alpha}",depths,observed)) beta=.2;lam=.8;c=1. for _ in range(200):c=(1-beta)*lam*c+beta ck(near(c,5/9),"reinjection stationary contrast") def root_mean(x,b=2): x=np.asarray(x,dtype=float) while len(x)>1:x=x.reshape(-1,b).mean(axis=1) return float(x[0]) groups={} for bits in itertools.product([0,1],repeat=8): y=root_mean(bits) ck(near(y,sum(bits)/8),"enumerated tree mean") groups.setdefault(y,[]).append(bits) a=(1,0,0,0,0,0,0,0);b=(0,1,0,0,0,0,0,0) ck(root_mean(a)==root_mean(b) and a[0]!=b[0],"specific-leaf target collision") tree_depths=np.arange(1,13) for branching in [2,4]: for depth in range(1,6): count_leaves=branching**depth x=np.zeros(count_leaves);x[0]=1 ck(near(root_mean(x,branching),1/count_leaves),"individual leaf sensitivity") panel(10,1,"Repeated mixing removes two-node contrast","Propagation depth k","Contrast relative to initial value", series, "Declared linear two-node stochastic mixing P_alpha. Initial contrast is one; contrast after k steps is (1-2 alpha)^k. Analytic positive values are plotted even where subtracting floating-point node values would lose tiny differences.",yscale="log") panel(10,2,"Averaging attenuates each distant leaf","Tree depth d","Root derivative per leaf", [(f"Branching factor {b}",tree_depths,np.power(float(b),-tree_depths)) for b in [2,4]], "A regular depth-d tree averages b children at each internal node. The root derivative with respect to one leaf is b^(-d). Curves concern a scalar mean aggregator, not all graph networks.",yscale="log") points.extend([[10,1,0,1,.8],[10,2,0,3,.125]]) finish(10,"Two-node spectral decay, feature reinjection and exhaustive mean-tree collisions",start, dict(reinjection_beta=.2,contrast_eigenvalue=.8,stationary_gain=5/9,leaf_assignments=256,distinct_root_values=len(groups),collision_a=list(a),collision_b=list(b),shared_root_value=.125), "Linear two-node recurrence and all 256 binary assignments to eight leaves; no universal nonlinear-GNN theorem or training benchmark.") return dict(panels=panels,results=results,points=points) if __name__=="__main__": r=run() print(json.dumps(dict(panels=len(r["panels"]),results=len(r["results"]),points=len(r["points"]),assertions=sum(v["assertions"] for v in r["results"])),indent=2))