// Job 700: specialize the archived histogram operator to isolated deletions. // This is an existing-operator corollary, not a new sieve route. The large // base wheel adapts my return306 code; the small full-period checker is separate. 'use strict'; const fs = require('node:fs'); const assert = require('node:assert/strict'); function primesTo(n) { const out=[]; for(let p=2;p<=n;p++) if(out.every(d=>p%d!==0)) out.push(p); return out; } const primes=primesTo(521); function add(h,d,n=1) { h[d]=(h[d]||0)+n; } function stats(word,W) { const H={},J={}; for(let i=0;ia+b,0),W); return {W,D:word.length,G:Math.max(...word),M:Math.max(...Object.keys(J).map(Number)),H,J}; } function gaps(slots,W) { return slots.map((v,i)=>(i+1n%p!==0&&(n+2)%p!==0); } // Integer-by-integer definitions, with neither the wheel nor a gap-transfer rule. function directSlots(W,ps) { const slots=[]; for(let n=0;na+(+d>=t?n:0),0); } function edgeCount(H,q) { return Object.entries(H).reduce((n,[d,c])=>n+(+d%q===0?2*c:(+d%q===2||+d%q===q-2?c:0)),0); } function sorted(h) { return Object.entries(h).filter(([,n])=>n).map(([d,n])=>[+d,n]).sort((a,b)=>a[0]-b[0]); } const fixtures=[]; let histogramChecks=0,thresholdChecks=0,negativeControls=0; for(const [x,qs] of [[5,[7,11,13,17]],[7,[11,13,17]],[11,[13,17,19,23]],[13,[17,31,37]]]) { const ps=primes.filter(p=>p<=x),W=ps.reduce((a,b)=>a*b,1); const old=directSlots(W,ps),base=stats(gaps(old,W),W); for(const q of qs) { assert(!ps.includes(q)); const fresh=directSlots(q*W,[...ps,q]),actual=stats(gaps(fresh,q*W),q*W); assert.equal(fresh.length,old.length*(q-2)); // Count all cyclic adjacent-kill edges independently, including the seam. let edges=0; for(let k=0;kr.x===5&&r.q===7); assert.equal(control.max_sum_two,24);assert.equal(control.new_max,30); assert.equal(control.histogram_formula_matches,false);assert(negativeControls>0); function wheelBase(x) { const ps=primes.filter(p=>p<=x),W=ps.reduce((a,b)=>a*b,1),classes=[11,17,29]; const mask=new Uint8Array(W/10);mask.fill(1); for(const p of ps.filter(p=>p>=7)) for(let c=0;c<3;c++) for(const r of [0,p-2]) { let k=0;while((30*k+classes[c])%p!==r) k++; for(let j=3*k+c;j=3); const seam=first+W-prev;add(H,seam);add(J,lastGap+seam);add(J,seam+firstGap); assert.equal(Object.values(H).reduce((a,b)=>a+b,0),D); assert.equal(Object.values(J).reduce((a,b)=>a+b,0),D); assert.equal(Object.entries(H).reduce((a,[g,n])=>a+g*n,0),W); assert.equal(Object.entries(J).reduce((a,[g,n])=>a+g*n,0),2*W); assert.equal(D,ps.filter(p=>p>=3).reduce((a,p)=>a*(p-2),1)); return {x,W,D,G:Math.max(...Object.keys(H).map(Number)),M:Math.max(...Object.keys(J).map(Number)),H,J}; } // Cross-check the streaming pair histogram, especially its two seam terms. for(const x of [5,7,11,13]) { const wheel=wheelBase(x),ps=primes.filter(p=>p<=x); const direct=stats(gaps(directSlots(wheel.W,ps),wheel.W),wheel.W); assert.deepEqual(sorted(wheel.H),sorted(direct.H)); assert.deepEqual(sorted(wheel.J),sorted(direct.J)); } const large=wheelBase(29); assert.equal(large.D,214708725);assert.equal(large.G,258); const exceptions=primes.filter(q=>q>29&&edgeCount(large.H,q)>0); assert.equal(Math.max(...exceptions),113); const onset=127; assert(onset>Math.max(...exceptions)); // No missing factors: supported g,g-2,g+2 are <=260, all primes through521 // were checked. Every larger q also has nonzero differences below q. const derived=[127,131,137].map(q=>{ const h=predict(large,q); assert.equal(edgeCount(large.H,q),0); assert.equal(Object.values(h).reduce((a,b)=>a+b,0),large.D*(q-2)); assert.equal(Object.entries(h).reduce((a,[d,n])=>a+d*n,0),large.W*q); return {q,method:'formula_only_not_full_period_enumeration',D:large.D*(q-2),W:large.W*q, G:large.M,maximum_gap_count:2*large.J[large.M],H:sorted(h)}; }); fs.writeFileSync(process.argv[2]||'isolated-fold-700.json',JSON.stringify({schema:'sah-isolated-fold-v1', ownership:'Special case of research/a3-09-histogram-operator.md; no novel operator or route.', histogramChecks,thresholdChecks,negativeControls,fixtures, T29:{x:29,W:large.W,D:large.D,G:large.G,max_sum_two:large.M,H:sorted(large.H),J:sorted(large.J), exceptional_primes_above_29:exceptions,prime_onset:onset},derived},null,2)+'\n');