"""Declared finite analytical controls; no neural training or source benchmark reproduction.""" import json,math,itertools,hashlib from pathlib import Path ROOT=Path(__file__).resolve().parents[1] checks=[] cases=0 def check(ok,label): global cases assert ok,label cases+=1 if label not in checks: checks.append(label) def fig(fid,title,xlabel,ylabel,x,series,caption): return dict(id=fid,title=title,kind='analytical_curve',x_label=xlabel,y_label=ylabel,x={'name':xlabel,'values':x},series=[{'name':n,'values':v}for n,v in series],caption=caption) def sm(row): m=max(row);e=[math.exp(v-m)for v in row];return[v/sum(e)for v in e] xs=[0,.01,.05,.1,.25,.5,1,2,3,4] for a in xs: A=[sm([a,-a]),sm([-a,a])] det=A[0][0]*A[1][1]-A[0][1]*A[1][0] check(abs(det-math.tanh(a))<1e-12,'softmax determinant equals tanh') check(all(abs(sum(row)-1)<1e-12 for row in A),'row normalization') check(abs(sum(A[0][j]*[1,-1][j]for j in range(2))-math.tanh(a))<1e-12,'contrast transmission') check(all(abs(sum(row[j]*3 for j in range(2))-3)<1e-12 for row in A),'identical values erase distinctions') for b in [0,.2,1.5]: B=[sm([b,-b]),sm([-b,b])];V=[-2,3] actual=max(abs(sum((A[i][j]-B[i][j])*V[j]for j in range(2)))for i in range(2)) bound=max(sum(abs(A[i][j]-B[i][j])for j in range(2))for i in range(2))*max(map(abs,V)) check(actual<=bound+1e-12,'row L1 output perturbation bound') check(sm([0,0])==[.5,.5],'zero scale exact collapse') figures=[fig('contrast-rank','Rank-one scores, full-rank attention','Score scale a (dimensionless)','Determinant / contrast eigenvalue',xs,[('tanh(a)',[math.tanh(a)for a in xs])],'Author-constructed two-token scalar head. Unmasked scores have rank one for a>0; normalized determinant equals tanh(a). No model training.'), fig('saturation-tradeoff','Transmission and local score-scale sensitivity','Score scale a (dimensionless)','Dimensionless value',xs,[('Contrast transmission',[math.tanh(a)for a in xs]),('Derivative with respect to a',[1-math.tanh(a)**2 for a in xs])],'Exact symmetric two-token control. Derivative concerns this scalar parameterization, not total neural training gradients.')] out={'article_slug':'attention-rank-bottlenecks','figures':figures} (ROOT/'figures').mkdir(exist_ok=True) (ROOT/'figures/attention-rank-bottlenecks.json').write_text(json.dumps(out,indent=2)+'\n',encoding='utf-8') receipt={'status':'PASS','checks':checks,'cases':cases,'empirical_benchmark':False,'source_proofs_verified':False,'figure_sha256':hashlib.sha256((ROOT/'figures/attention-rank-bottlenecks.json').read_bytes()).hexdigest()} (ROOT/'analysis/attention-rank-bottlenecks.receipt.json').write_text(json.dumps(receipt,indent=2)+'\n',encoding='utf-8') print(json.dumps(receipt))