// ============================================================================ // NATAL-CAP-20 — THIRD ORDER: THE ZONE-SHARE EXPANSION, DERIVED ON PAPER // (2026-08-14; executes natal-cap-17 Part B reading #13's "cheaper // alternative — derive the third-order coefficient and check today's // 0.0026 residual against it on paper". Definition of the ratio kept // EXACTLY as in 01-zone-twin-share.js / natal-cap-17 Part B.) // // natal-cap-17 found EMPIRICALLY that the zone twin-share ratio follows // R(p) ≈ lim·(1 + 1/ln p + 1.5/ln²p), lim = e^{2γ}/4 = 0.793055, // with residual 0.0026 at p = 100003. Here the expansion is DERIVED by hand // to third order, the coefficients come out exact, and the third-order term // is tested against the six measured levels plus one new out-of-sample // measurement at p = 200003 (window ≈ 4.0e10, segmented sieve copied from // natal-cap-17's Part B — that file untouched). // // ============================================================================ // DERIVATION (by hand, every step shown; no CAS was available or needed) // ---------------------------------------------------------------------------- // THE OBJECT (definition from 01-zone-twin-share.js, unchanged): // // R(p) = cand / expect // cand = #{ r : 3 ≤ r, r+2 < W, r and r+2 both unhit after sieving // [1,W) by ALL primes q ≤ p, each q marking itself too } // expect = W·dens, dens = (1/2)·∏_{2 1 in // [1, W) has no factor ≤ p_n ≥ √W-ish, hence is prime; so // cand = #{ twin prime pairs (r, r+2), p < r, r+2 < W } EXACTLY. // cand is an exact integer count — the MEASUREMENT is unconditional. // Only the derived asymptotics below lean on a conjecture (Step 1). // // STEP 1 — NUMERATOR: Hardy–Littlewood (THE conditional input). // HL Conjecture B (Partitio Numerorum III, 1923): // π₂(x) = 2C₂·∫_2^x dt/ln²t + E₂(x), E₂(x) = O(x^{1/2+ε}) conjectured, // C₂ = ∏_{q>2} (1 − 1/(q−1)²) = 0.66016 18158 46869 57… // Hence cand = 2C₂·∫_p^W dt/ln²t + E₂-errors + O(1) edge terms. // Unconditionally only Brun's upper bound O(x/ln²x) is known, so every // COEFFICIENT below is HL-conditional. (Twins with a member ≤ p that the // window forgoes: π₂(p) ~ 2C₂p/ln²p, a relative O(1/p) — below all orders.) // // STEP 2 — DENOMINATOR: Mertens — and the surprise: it contributes NO // 1/ln-series terms at all. Factor each twin factor: // (1 − 1/q)²·(1 − 1/(q−1)²) = ((q−1)²/q²)·(((q−1)² − 1)/(q−1)²) // = (q² − 2q)/q² = 1 − 2/q. ✓ // Therefore // ∏_{2p}(1−1/(q−1)²) = 1 − O(1/(p·ln p)) — also below every order. So // dens = (1/2)·4·(e^{−2γ}/ln²p)·C₂·(1 + below-all-orders) // = 2C₂·e^{−2γ}/ln²p, expect = 2C₂·e^{−2γ}·W/ln²p. // (The task brief anticipated "the e^{−2γ}/ln²p form has its own 1/ln // expansion" — it does NOT. All of a₁, a₂, a₃ come from the integral; // that is why they land rational, with γ and C₂ cancelling from every // order. At finite p the product still fluctuates around its asymptote — // CHECK 2 measures that deviation δ_M directly; it is part of the honest // residual budget, just not a series term.) // // STEP 3 — THE INTEGRAL: exact identity first. From // d/dt [ t/ln^k t ] = 1/ln^k t − k/ln^{k+1} t // integration by parts iterates, factorials accumulating, giving for // every K ≥ 2 the EXACT identity (verified to machine precision, CHECK 1): // ∫_a^b dt/ln²t = Σ_{k=2..K} (k−1)!·[ t/ln^k t ]_a^b // + K!·∫_a^b dt/ln^{K+1} t. // (K=2: ∫dt/ln² = [t/ln²] + 2∫dt/ln³; then ∫dt/ln³ = [t/ln³] + 3∫dt/ln⁴; …) // // STEP 4 — UPPER LIMIT b = p²: the factor-of-2 zone. ln b = 2ℓ, ℓ := ln p, // so every power of ln b costs a power of 2: // (k−1)!·b/ln^k b = (k−1)!·p²/(2ℓ)^k. // Divide each term by the head term p²/(2ℓ)² = p²/(4ℓ²): // k=2: 1 // k=3: 2!/(2ℓ)³ ÷ 1/(2ℓ)² = 2/(2ℓ) = 1/ℓ // k=4: 3!/(2ℓ)⁴ ÷ 1/(2ℓ)² = 6/(4ℓ²) = 3/(2ℓ²) // k=5: 4!/(2ℓ)⁵ ÷ 1/(2ℓ)² = 24/(8ℓ³) = 3/ℓ³ // k=6: 5!/(2ℓ)⁶ ÷ 1/(2ℓ)² = 120/(16ℓ⁴) = 15/(2ℓ⁴) // k=7: 6!/(2ℓ)⁷ ÷ 1/(2ℓ)² = 720/(32ℓ⁵) = 45/(2ℓ⁵) // general j = k−2: a_j = (j+1)!/2^j at 1/ℓ^j. // So Σ_{k≥2}(k−1)!·b/ln^k b // = (p²/4ℓ²)·(1 + 1/ℓ + 3/(2ℓ²) + 3/ℓ³ + 15/(2ℓ⁴) + 45/(2ℓ⁵) + …). // LOWER LIMIT a = p (ln a = ℓ, no factor of 2): // Σ (k−1)!·a/ln^k a = (p/ℓ²)·(1 + 2/ℓ + 6/ℓ² + …), // which is 4/p·(…) RELATIVE to the head — smaller than every power of // 1/ℓ, though numerically −e^{2γ}/p·(1+2/ℓ+…) ≈ −1.4e−3 at p = 2999 and // −4e−5 at p = 1e5 once carried into R (kept in the numeric columns, // dropped from the printed law). // (W = p_next² vs p²: W cancels in [W/ln²W]/(W·dens); the only trace is // ln p_next = ℓ + O(gap/p), a relative wiggle ~2(g/p)/ℓ ≈ 3e−5 at 1e5.) // // STEP 5 — COMBINE. R = 2C₂·I/(W·dens) = e^{2γ}·(ℓ²/p²)·I·(1 + negligible): // // R(p) = (e^{2γ}/4)·( 1 + 1/ℓ + 3/(2ℓ²) + 3/ℓ³ + 15/(2ℓ⁴) + 45/(2ℓ⁵) + … ) // − (e^{2γ}/p)·( 1 + 2/ℓ + 6/ℓ² + … ) [+ HL error] // // a₁ = 1 — natal-cap-17's empirical fit said 1: EXACT match. // a₂ = 3/2 — empirical fit said 1.5: EXACT match. // a₃ = 3 — NEW, tested below. a₄ = 15/2, a₅ = 45/2. // a_j = (j+1)!/2^j — all RATIONAL; γ and C₂ cancel from every order. // Closed form: R(p) ~ (e^{2γ}/4)·Σ_{j≥0} (j+1)!/L^j with L = ln(p²) — // the standard π₂ asymptotic series, re-based at the zone's frontier. // (Asymptotic, divergent; terms shrink while j ≲ L ≈ 23 at p=1e5, so a // 3-term truncation is far inside the safe range.) // // WHAT THE CODE CHECKS // CHECK 0 C₂ constant against a finite product over primes ≤ 1e7. // CHECK 1 the Step-3 identity + Step-4 algebra numerically at p = 1e4 // and p = 1e6 (the brief's demanded symbolic-vs-numeric test; // this is where a factor-of-2 slip would explode). // CHECK 2 the "empty series" claim: dens_exact vs 2C₂e^{−2γ}/ℓ² (δ_M). // TABLE six measured levels (cand values from natal-cap-17's OUTPUT, // ratios re-derived from scratch and asserted against it) vs // the derived orders 1/2/3/5 and the full numeric-HL prediction. // BUDGET at p = 1e5: decompose the 3rd-order residual into series // tail + Mertens δ_M + lower limit + leftover (≈ HL error). // NEW out-of-sample p = 200003: prediction printed BEFORE the // sieve runs (window 4.0e10, ~2 min), then measured. // // Runtime ~3 min. Moratorium respected: nothing committed, nothing posted. // ============================================================================ 'use strict'; 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} const PR=primesUpTo(300000); const GAMMA=0.5772156649015329; const C2=0.6601618158468696; // Hardy–Littlewood twin constant const E2G=Math.exp(2*GAMMA), LIM=E2G/4; const fact=n=>{let f=1;for(let i=2;i<=n;i++)f*=i;return f}; const A=[1,1.5,3,7.5,22.5]; // a₁..a₅ = (j+1)!/2^j const ser=(l,k)=>LIM*(1+A.slice(0,k).reduce((s,a,j)=>s+a/l**(j+1),0)); const lowLim=(p,l)=>E2G/p*(1+2/l+6/(l*l)); // lower-limit term (subtract) let FAIL=0; const check=(name,ok,detail)=>{console.log(` ${ok?'✓':'✗'} ${name}${detail?' '+detail:''}`);if(!ok)FAIL=1}; const T00=Date.now(); // numeric ∫_a^b dt/ln^k t via u = ln t (composite Simpson; smooth integrand) function Ik(a,b,k,n=2000000){ const ua=Math.log(a),ub=Math.log(b),h=(ub-ua)/n; let s=Math.exp(ua)/ua**k+Math.exp(ub)/ub**k; for(let i=1;ipn)break;if(q>2)d*=(q-2)/q}return d} // --------------------------------------------------------------------------- console.log('CHECK 0 — the constant C₂'); { const P7=primesUpTo(10000000); let c=1;for(const q of P7)if(q>2)c*=1-1/((q-1)*(q-1)); // finite product omits factors <1 beyond 1e7 ⇒ exceeds C₂ by ≈ 6e−9 relative check('C₂ = 0.6601618158468696 matches ∏ over q ≤ 1e7 within tail size', Math.abs(c-C2)<2e-8, `finite=${c.toFixed(12)} diff=${(c-C2).toExponential(2)} (tail ≈ +4e-9 expected)`); } // --------------------------------------------------------------------------- console.log('\nCHECK 1 — integral identity + the 2ℓ substitution (symbolic vs numeric)'); for(const p of [1e4,1e6]){ const a=p,b=p*p,l=Math.log(p); const I=Ik(a,b,2); console.log(` p=${p}: I = ∫_p^{p²} dt/ln²t = ${I.toExponential(8)}`); for(const K of [2,3,4,5]){ let S=0;for(let k=2;k<=K;k++)S+=fact(k-1)*(b/Math.log(b)**k-a/Math.log(a)**k); const rem=fact(K)*Ik(a,b,K+1); const idOK=Math.abs(S+rem-I)/I<1e-9; console.log(` K=${K}: partial-sum relerr=${((S-I)/I).toExponential(2)} (next term/I=${(fact(K)*b/Math.log(b)**(K+1)/I).toExponential(2)}) exact identity Σ+K!·∫dt/ln^{K+1}t ${idOK?'✓':'✗ BROKEN'}`); if(!idOK)FAIL=1; } const upper5=[2,3,4,5].reduce((s,k)=>s+fact(k-1)*b/(2*l)**k,0); const ellform=b/(4*l*l)*(1+1/l+1.5/(l*l)+3/l**3); check(`ℓ-form (p²/4ℓ²)(1+1/ℓ+3/2ℓ²+3/ℓ³) == Σ(k−1)!p²/(2ℓ)^k, k=2..5 (p=${p})`, Math.abs(upper5-ellform)/upper5<1e-12); const Rnum=E2G*l*l/b*I; // e^{2γ}ℓ²/p²·I const Rser=ser(l,5)-lowLim(p,l); console.log(` R_num = e^{2γ}ℓ²/p²·I = ${Rnum.toFixed(7)} R_ser(5 terms − lower lim) = ${Rser.toFixed(7)} diff = ${(Rnum-Rser).toExponential(2)} (a₆-term ≈ ${(LIM*fact(7)/2**6/l**6).toExponential(1)})`); if(Math.abs(Rnum-Rser)>3*LIM*fact(7)/2**6/l**6){console.log(' ✗ diff exceeds next-order size');FAIL=1} } // --------------------------------------------------------------------------- console.log('\nCHECK 2 — Mertens has an EMPTY 1/ln series: δ_M = asy/dens_exact − 1 at finite p'); console.log(' p_n | dens_exact | 2C₂e^{−2γ}/ℓ² | δ_M(×1e4) | δ_M·ℓ (dies ⇒ no 1/ℓ term hiding)'); const LEVELS=[2999,5003,9973,20011,50021,100003,200003]; for(const pn of LEVELS){ const l=Math.log(pn),d=densExact(pn),asy=2*C2*Math.exp(-2*GAMMA)/(l*l),dm=asy/d-1; console.log(` ${String(pn).padStart(6)} | ${d.toExponential(6)} | ${asy.toExponential(6)} | ${(dm*1e4).toFixed(2).padStart(6)} | ${(dm*l).toFixed(5)}`); } // --------------------------------------------------------------------------- console.log('\nTABLE — measured levels vs derived orders (cand from natal-cap-17 OUTPUT, ratios re-derived)'); const MEAS=[ // {pn,pNext,cand} — cand = exact twin count in [3, pNext²), natal-cap-17 Part B (2026-08-14) {pn:2999, pNext:3001, cand:53804}, {pn:5003, pNext:5009, cand:130803}, {pn:9973, pNext:10007, cand:440666}, {pn:20011, pNext:20021, cand:1510202}, {pn:50021, pNext:50023, cand:7816740}, {pn:100003,pNext:100019,cand:27420901}, ]; const REF4=[0.9243,0.9119,0.8991,0.8889,0.8793,0.8735]; // cap-17 printed ratios (4 dp) console.log(' p_n | R_meas | ser1 resid | ser2 resid | ser3 resid | ser5 resid | HL-full resid'); const ROWS=[]; MEAS.forEach((m,i)=>{ const W=m.pNext*m.pNext,l=Math.log(m.pn),d=densExact(m.pn),R=m.cand/(d*W); if(Math.abs(R-REF4[i])>6e-5){console.log(` ✗ ratio mismatch vs natal-cap-17 at p=${m.pn}: ${R}`);process.exit(1)} const s1=ser(l,1),s2=ser(l,2),s3=ser(l,3),s5=ser(l,5); const hl=2*C2*Ik(m.pn,W,2)/(W*d); ROWS.push({pn:m.pn,l,R,s2,s3,s5,hl,d}); console.log(` ${String(m.pn).padStart(6)} | ${R.toFixed(5)} | ${s1.toFixed(4)} ${(R-s1).toFixed(4).padStart(7)} | ${s2.toFixed(4)} ${(R-s2).toFixed(4).padStart(7)} | ${s3.toFixed(4)} ${(R-s3).toFixed(4).padStart(7)} | ${s5.toFixed(4)} ${(R-s5).toFixed(4).padStart(7)} | ${hl.toFixed(5)} ${(R-hl).toFixed(4).padStart(7)}`); }); console.log(' (✓ all six re-derived ratios match natal-cap-17\'s printed 4-dp values)'); console.log('\n order-scaling probe: resid₂·ℓ³ → a₃·lim = 2.379 and resid₃·ℓ⁴ → a₄·lim = 5.948 if orders are right'); for(const r of ROWS)console.log(` p=${String(r.pn).padStart(6)}: resid₂·ℓ³ = ${((r.R-r.s2)*r.l**3).toFixed(2)} resid₃·ℓ⁴ = ${((r.R-r.s3)*r.l**4).toFixed(2)}`); // --------------------------------------------------------------------------- console.log('\nBUDGET at p = 100003 — where does the old 0.0026 residual go?'); { const r=ROWS[5],l=r.l; const tail=r.s5-r.s3; // a₄,a₅ series tail const dm=(2*C2*Math.exp(-2*GAMMA)/(l*l))/r.d-1; // Mertens deviation // the MEASURED expect uses dens_exact; the series replaced it by asy = // dens_exact·(1+δ_M) > dens_exact, deflating the prediction by 1/(1+δ_M); // so the measurement runs HIGH vs the series by ≈ +R·δ_M. const mert=r.s3*dm; const ll=-lowLim(100003,l); const leftover=(r.R-r.s3)-tail-mert-ll; console.log(` resid₃ = R_meas − ser3 = ${(r.R-r.s3).toFixed(5)}`); console.log(` series tail (a₄+a₅ terms) = ${tail.toFixed(5)}`); console.log(` Mertens finite-p (+R·δ_M) = ${mert.toFixed(5)} (δ_M = ${(dm*1e4).toFixed(2)}e-4)`); console.log(` lower-limit term (−e^{2γ}/p·…) = ${ll.toFixed(5)}`); console.log(` leftover (≈ HL error + a₆⁺ + edges) = ${leftover.toFixed(5)}`); console.log(` [cross-check: R_meas − HL-full = ${(r.R-r.hl).toFixed(5)} — the no-expansion residual]`); } // --------------------------------------------------------------------------- console.log('\nOUT-OF-SAMPLE — p ≈ 2e5: predictions locked BEFORE the sieve runs'); function nextPrime(n){let m=n+1;for(;;m++){let ok=m>1;for(const p of PR){if(p*p>m)break;if(m%p===0){ok=false;break}}if(ok)return m}} const PN=nextPrime(200000),PNX=nextPrime(PN),WN=PNX*PNX,LN=Math.log(PN),DN=densExact(PN); const PRED={ser2:ser(LN,2),ser3:ser(LN,3),ser5:ser(LN,5),hl:2*C2*Ik(PN,WN,2)/(WN*DN)}; console.log(` p_n = ${PN}, p_next = ${PNX}, window = ${WN} (${(WN/1e10).toFixed(3)}e10), ℓ = ${LN.toFixed(5)}`); console.log(` PREDICTIONS: ser2 = ${PRED.ser2.toFixed(5)} ser3 = ${PRED.ser3.toFixed(5)} ser5 = ${PRED.ser5.toFixed(5)} HL-full = ${PRED.hl.toFixed(5)}`); console.log(` (a₃ moves the prediction by +${(PRED.ser3-PRED.ser2).toFixed(5)}; a₄+a₅ by a further +${(PRED.ser5-PRED.ser3).toFixed(5)})`); // segmented odd-only sieve — pattern copied from natal-cap-17 levelB (that // file untouched); re-verified below against two of its exact counts. function measureLevel(pn,pNext){ const t0=Date.now(); const windowD=pNext*pNext; // ≤ 4.1e10 < 2^53 ✓ const sp=PR.filter(p=>p>2&&p<=pn); const S=1<<22,seg=new Uint8Array(S); let cand=0,prevUnhit=false; for(let lo=1;lo