// ============================================================================ // NATAL CAP 02 — FOURIER / ERDOS–TURAN CERTIFIED DISCREPANCY OF THE NATAL SET // (attack agent 2, 2026-08-14) // ============================================================================ // IDEA. The Natal@5 set N_x = { r in [0,W) : r = 11 or 17 (mod 30), // r mod p not in {0, p-2} for 7 <= p <= x }, W = x#, is a CRT product, so its // exponential sum FACTORS. Writing W = 30 * prod p, M_j = W/W_j and the CRT // twist y_j = M_j^{-1} (mod W_j): // // S(k) = sum_{r in N_x} e(kr/W) // = [ e(11 t/30) + e(17 t/30) ] * prod_{7<=p<=x} F_p(t_p), // with t = k*y_30 mod 30, t_p = k*y_p mod p, // F_p(0) = p-2 (comb frequency: p "sees" nothing) // F_p(t_p) = -(1 + e(-2 t_p/p)), |F_p| = 2|cos(2 pi t_p / p)| (t_p != 0) // and |mod-30 factor| = 2|cos(pi t / 5)| in {2, phi, phi-1} (golden ratio: // 11 and 17 differ by 6, and 30/6 = 5). // // NOTE — CORRECTION TO attack-04-fourier-budget.js: that file indexed the // local factors at k mod p, omitting the CRT twist y_p = (W/p)^{-1} mod p. // The twist permutes coefficients WITHIN a support class, so all class-level // statistics there stand, but the pointwise pairing |F(k)| * |K(k)| in its // "certified" column paired moduli with the wrong kernel values — those // numbers are close (verified below) but were not actually certificates. // Here everything is verified against a direct DFT before use. // // WHY IT MATTERS. The Scour prime q (x < q <= sqrt W) strikes natal slots // r = 0 / -2 (mod q). Dilation identity: strikes on branch 0 are exactly the // members of the dilated pattern q^{-1}N_x (same |S| profile, frequencies // permuted j -> qj) inside the INTERVAL m in [0, W/q); branch -2 is a shift // of the same. So a certified interval-discrepancy bound D gives the // deterministic cap gross(q) <= 2( N/q + D ). // // TWO CERTIFICATES, both computed exactly: // (a) SHARP-WINDOW IDENTITY (self-contained, per window length l): // |count(I) - rho*l| <= (1/W) sum_{k!=0} |S_dil(k)| |D_l(k)|, // |D_l(k)| = |sin(pi k l/W)/sin(pi k/W)|, |S_dil(k)| = |S(q^{-1}k)|. // Plus a HYBRID refinement: frequencies whose support touches <= 1 of // the primes {7..x} form deterministic periodic terms (period 30 or 30p) // whose window deviation we compute EXACTLY (they are the rigid combs // that dominated attack-04's budget); only |support| >= 2 frequencies // are paid for via the triangle inequality. // (b) ERDOS–TURAN (citable, uniform over all window lengths): for N points // x_1..x_N in [0,1) and any integer H >= 1, // D_N <= 6N/(H+1) + (4/pi) sum_{h=1}^{H} (1/h - 1/(H+1)) |S(h)|, // Kuipers & Niederreiter, Uniform Distribution of Sequences (1974), // Thm 2.5 (this explicit-constant form as used in e.g. arXiv:2606.04677; // Montgomery, Ten Lectures (1994) has a variant N/(H+1) + 3 sum |S|/h). // Cyclic (wrapping) windows are covered since dev(I^c) = dev(I). // // HONEST QUESTION. How big is the certification gap (certified / true, both // measured), which frequencies carry the budget, what is the effective base b // in |S| ~ b^n at generic k, and at what level x does the certified cap // sum_q [2N/q + 2D_q] cross N — i.e. where does this door close, in numbers? // ============================================================================ 'use strict'; const T0 = Date.now(); // ---------- utilities ------------------------------------------------------- function primesUpTo(n){const s=new Uint8Array(n+1),o=[];for(let i=2;i<=n;i++){if(!s[i]){o.push(i);for(let j=i*i;j<=n;j+=i)s[j]=1;}}return o;} function egcd(a,b){if(b===0)return[a,1,0];const[g,x,y]=egcd(b,a%b);return[g,y,x-Math.floor(a/b)*y];} function modinv(a,m){a=((a%m)+m)%m;const[g,x]=egcd(a,m);if(g!==1)throw new Error('no inverse');return((x%m)+m)%m;} const TAU = 2*Math.PI; // ---------- level construction ---------------------------------------------- function buildLevel(x){ const mids = primesUpTo(x).filter(p=>p>=7); // primes 7..x const W = 30*mids.reduce((a,b)=>a*b,1); const natal=[]; for(let r=11;ra-b); const formula = 2*mids.reduce((a,p)=>a*(p-2),1); return {x,mids,W,natal,N:natal.length,formula,rho:natal.length/W}; } // ---------- exact factored Fourier moduli (with CRT twist) ------------------- function buildFourier(L){ const {W,mids}=L; const y30 = modinv(W/30,30); const c30 = new Float64Array(30); for(let t=0;t<30;t++) c30[t]=Math.hypot(Math.cos(TAU*11*t/30)+Math.cos(TAU*17*t/30), Math.sin(TAU*11*t/30)+Math.sin(TAU*17*t/30)); const cp={},yp={}; for(const p of mids){ yp[p]=modinv(W/p,p); const a=new Float64Array(p); a[0]=p-2; for(let t=1;t position (dilation); null = identity const ind=new Uint8Array(L.W); for(const r of L.natal) ind[map?map(r):r]=1; return ind; } function prefix(ind,extra){ const W=ind.length,P=new Int32Array(W+extra+1); for(let i=0;imx)mx=c; if(cmx)mx=c; if(cbest){best=d;bl=l;} } return {dev:best,l:bl}; } // ---------- Erdos–Turan over Z/W (K–N Thm 2.5 explicit form) ------------------ function erdosTuran(L,F){ const {W,N}=L,{absS}=F; let A=0,B=0,best=1e18,bestH=0; for(let h=1;htop[top.length-1].w){top.push({h,w});top.sort((a,b)=>b.w-a.w);if(top.length>5)top.pop();} } return {best,bestH,leading:6*N/(bestH+1),top}; } // ---------- per-prime scour certificates -------------------------------------- // exact deviation of the |support|<=1 (rigid comb) terms, dilated pattern q^{-1}N function exactCombDev(L,q,l){ const {mids}=L; const iq30=modinv(q,30), A30=[(iq30*11)%30,(iq30*17)%30]; const dAll=mids.reduce((a,p)=>a*(p-2)/p,1); // U = {} : two residues mod 30, weight prod (p-2)/p const dev1=(T,f,lr)=>{ // max |window sum| of zero-mean f over period T, window lr=l%T if(lr===0)return 0; const P=new Float64Array(2*T+1);for(let i=0;i<2*T;i++)P[i+1]=P[i]+f(i%T); let m=0;for(let s=0;s(t===A30[0]||t===A30[1]); let dev=dAll*dev1(30,m=>(in30(m)?1:0)-2/30,l%30); // U = {p} : period 30p, weight prod_{p'!=p}(p'-2)/p' for(const p of mids){ const iqp=modinv(q,p), B=[0,((p-2)*iqp)%p], dp=(p-2)/p, T=30*p; const w=dAll/dp; dev+=w*dev1(T,m=>(in30(m%30)?1:0)*(((m%p)!==B[0]&&(m%p)!==B[1]?1:0)-dp),l%T); } return dev; } function scourLevel(L,F,opts){ const {W,N,rho,x,mids}=L,{absS,usupp}=F; const sqrtW=Math.sqrt(W); const qs=primesUpTo(Math.floor(sqrtW)).filter(q=>q>x); const sinT=new Float64Array(W); for(let k=1;k qj let r0=0,r2=0,t0=0,t2=0; const track=(q===qs[0]); for(let j=1;j=2){t0+=s*d0;t2+=s*d2;} if(track){ const v=s*d0/W; if(topContrib.length<4||v>topContrib[topContrib.length-1].v){ topContrib.push({j,v});topContrib.sort((a,b)=>b.v-a.v);if(topContrib.length>4)topContrib.pop(); } } } r0/=W;r2/=W;t0/=W;t2/=W; const e0=exactCombDev(L,q,l0), e2=exactCombDev(L,q,l2); const CR0=r0,CR2=r2, CH0=t0+e0, CH2=t2+e2; // true window deviation of the dilated pattern at l0 (and branch identity) const invq=modinv(q,W); const ind=indicator(L,r=>(invq*r)%W), P=prefix(ind,l0+2); const dev0=trueDevAtL(P,W,rho,l0); let b0=0; for(let m=0;mCH0+1e-6||dev0>CR0+1e-6)throw new Error(`certificate violated q=${q}: true ${dev0} vs hyb ${CH0} raw ${CR0}`); const dens=N*(l0+l2)/W, capH=dens+CH0+CH2, capR=dens+CR0+CR2; if(g>capH+1e-9)throw new Error(`gross cap violated q=${q}`); sumGross+=g;sumDens+=dens;sumCR+=CR0+CR2;sumCH+=CH0+CH2; sumTrueDev+=dev0; sumGap+=CH0/Math.max(dev0,1e-12); if(CH0top[top.length-1].s){ top.push({k,s});top.sort((a,b)=>b.s-a.s);if(top.length>4)top.pop(); } } const bArith=Math.pow(gSum/gCnt,1/n), bGeom=Math.exp(gLog/gCnt/n); return {cnt,sum,bArith,bGeom,top}; } function annot(L,k){ const divs=L.mids.filter(p=>k%p===0); return `k=${k}[div ${divs.join(',')||'-'};k%30=${k%30}]`; } // ================================ RUN ========================================== for(const x of [7,11,13,17]){ const L=buildLevel(x); console.log(`\n===== LEVEL x=${x}: W=${L.W} N=${L.N} (formula ${L.formula}) rho=${L.rho.toExponential(3)} sqrtW=${Math.sqrt(L.W).toFixed(1)} =====`); if(L.N!==L.formula)throw new Error('natal count mismatch'); const F=buildFourier(L); if(x<=11){ const v=verifyFactored(L,F); console.log(`factored S(k) vs direct DFT (all ${L.W} freqs, complex): max err ${v.maxErr.toExponential(1)};`+ ` untwisted-index modulus (attack-04 style) max pointwise error ${v.maxModDiffUntw.toFixed(3)}`); } const st=spectrumStats(L,F); console.log(`top |S|: `+st.top.map(t=>`${annot(L,t.k)}=${t.s.toFixed(1)}`).join(' ')+` (N=${L.N})`); console.log(`class avg |S| by #active primes u: `+ Array.from({length:L.mids.length+1},(_,u)=>`u=${u}:${(st.sum[u]/Math.max(st.cnt[u],1)).toFixed(2)}`).join(' ')); console.log(`generic-k effective base: b_arith=${st.bArith.toFixed(4)} (4/pi=${(4/Math.PI).toFixed(4)}) b_geom=${st.bGeom.toFixed(4)} (pred 1)`); const et=erdosTuran(L,F); console.log(`Erdos–Turan (K–N 2.5): best H=${et.bestH} bound=${et.best.toFixed(2)} (leading 6N/(H+1)=${et.leading.toFixed(2)})`); console.log(` top ET contributors: `+et.top.map(t=>`${annot(L,t.h)}:${t.w.toFixed(2)}`).join(' ')); if(x<=13){ const P=prefix(indicator(L,null),Math.floor(L.W/2)+2); const fs=fullSup(P,L.W,L.rho); console.log(`TRUE sup over ALL windows: dev=${fs.dev.toFixed(3)} at l=${fs.l} ET/true=${(et.best/fs.dev).toFixed(1)}x`); } const sc=scourLevel(L,F,{}); console.log(`scour: ${sc.qs.length} primes q in (${x}, ${Math.floor(Math.sqrt(L.W))}]`); console.log(` q l0 gross 2brMean trueDev(l0) certRaw(l0) certHyb(l0) capHyb(2br)`); sc.rows.forEach((r,i)=>{ if(i<6||i%10===0||i===sc.rows.length-1) console.log(`${String(r.q).padStart(4)} ${String(r.l0).padStart(6)} ${String(r.g).padStart(6)} ${r.dens.toFixed(1).padStart(7)} ${r.dev0.toFixed(2).padStart(10)} ${r.CR0.toFixed(2).padStart(11)} ${r.CH0.toFixed(2).padStart(11)} ${r.capH.toFixed(1).padStart(10)}`); }); console.log(`sharp-sum top contributors (q=${sc.qs[0]}, natal-frequency j): `+sc.topContrib.map(t=>`${annot(L,t.j).replace('k=','j=')}:${t.v.toFixed(2)}`).join(' ')); console.log(`TOTALS: sum gross=${sc.sumGross} sum mean=${sc.sumDens.toFixed(1)} sum certRaw=${sc.sumCR.toFixed(1)} sum certHyb=${sc.sumCH.toFixed(1)}`); console.log(`CAPS: raw=${sc.capRtot.toFixed(1)} hyb=${sc.capHtot.toFixed(1)} vs N=${L.N} -> margin(hyb)=${sc.marginH.toFixed(1)} margin(raw)=${sc.marginR.toFixed(1)}`); const oracle=sc.sumDens+2*sc.sumTrueDev; console.log(`ORACLE (if certification were PERFECT: true dev at l0, both branches): cap=${oracle.toFixed(1)} margin=${(L.N-oracle).toFixed(1)} (sum gross alone=${sc.sumGross}, N-sumGross=${L.N-sc.sumGross})`); console.log(`gap: certHyb(l0)/trueDev avg=${sc.avgGap.toFixed(2)}x worst=${sc.worstGap.toFixed(2)}x; q with certHyb margin(hyb)=-1.1 margin(raw)=-9.8 // ORACLE (if certification were PERFECT: true dev at l0, both branches): cap=7.9 margin=2.1 (sum gross alone=3, N-sumGross=7) // gap: certHyb(l0)/trueDev avg=1.74x worst=1.88x; q with certHyb margin(hyb)=-111.5 margin(raw)=-181.4 // ORACLE (if certification were PERFECT: true dev at l0, both branches): cap=117.3 margin=-27.3 (sum gross alone=73, N-sumGross=17) // gap: certHyb(l0)/trueDev avg=2.92x worst=3.94x; q with certHyb margin(hyb)=-1517.3 margin(raw)=-1807.8 // ORACLE (if certification were PERFECT: true dev at l0, both branches): cap=1433.1 margin=-443.1 (sum gross alone=1135, N-sumGross=-145) // gap: certHyb(l0)/trueDev avg=4.72x worst=6.16x; q with certHyb margin(hyb)=-20571.1 margin(raw)=-21756.8 // ORACLE (if certification were PERFECT: true dev at l0, both branches): cap=24086.9 margin=-9236.9 (sum gross alone=22132, N-sumGross=-7282) // gap: certHyb(l0)/trueDev avg=7.08x worst=9.82x; q with certHyb=2 cloud, not by few structured modes — the // largest single contributor to a sharp sum is ~1 out of ~60 at x=17 // (structured k = products of two natal primes lead, but only just). // 3. CERTIFICATION GAP (Q1). Sharp-window certificates (hybrid) vs the TRUE // deviation at the same window: avg 1.7x (x=7), 2.9x (11), 4.7x (13), // 7.1x (17) — the gap GROWS ~1.6x per level, because certified dev scales // ~N^{0.4-0.5} (L1 mass) while true dev grows only ~N^{0.2-0.26} // (2.9 -> 4.8 -> 9.6 at the first scour prime). Erdos–Turan (K–N Thm 2.5, // optimal H = 23/104/615/4432) certifies 8.2 / 18.1 / 44.5 / 107.7 vs true // sup-over-all-windows 2.24 / 4.20 / 8.17 (x<=13): 3.7x / 4.3x / 5.4x — // ET is uniform in l but ~2.5x looser than the per-l sharp identity; its // truncation term 6N/(H+1) is only ~20% of the bound, the tail sum is the // cost. The hybrid refinement (exact rigid combs, u<=1) helps most where // combs dominate: -53% at x=7, -35% at 11, -17% at 13, -8% at 17 — // diminishing exactly as the diffuse cloud takes over. // 4. THE VERDICT (Q4) — THE DOOR CLOSES THREE DIFFERENT WAYS, IN NUMBERS: // x=7: ORACLE MARGIN IS POSITIVE (+2.1): perfect per-window deviation // knowledge WOULD certify >= 2 scour survivors by pure union bound. // Our best certificate needs sum of devs <= 6.6 and delivers 7.7 — // misses by 1.1 slots (15%). The ONLY level where sharper Fourier // bookkeeping (Selberg/Beurling smoothing, exact u<=2 terms) could // flip a sign — methodologically interesting, mathematically moot // (twins below 210 are known by inspection). // x=11: certification quality is IRRELEVANT — even the oracle fails // (cap 117.3 vs N=90, margin -27.3). Twenty branch windows each // carrying true dev ~2-3 cost ~46 against available slack // N - sum(2N/q) = 19. The per-prime union bound is structurally // dead from here on, no matter how good the harmonic analysis gets. // x>=13: sum gross ALONE exceeds N (1135 vs 990; 22132 vs 14850 at 17): // strikes overlap, so even ZERO-deviation caps certify nothing. // Any viable route must CREDIT overlaps (depth >= 2 inclusion- // exclusion) — Brun/parity territory, the known wall, now with // its exact numeric location on the natal ladder. // 5. WHAT SURVIVES: PER-PRIME CAPS. The certificate is genuinely informative // per prime: at x=17 the deviation term is below the main term N/q for all // q <= 263 (49/120 scour primes), and at q=19 it proves gross(19) <= 1685 // vs true 1563 — a deterministic 8% cap on any single prime's overdraw. // Fourier certification is a fine per-prime regularity tool and a dead // aggregation tool. // 6. NEXT STEP. The oracle diagnosis says: stop polishing constants, credit // the overlaps. Strike sets of two scour primes q, q' intersect in another // natal-type CRT pattern (mod 30*prod*q*q'), so the SAME certified // machinery applies at Bonferroni depth 2-3. Measure the pairwise overlap // mass sum_{q