#!/usr/bin/env node // ============================================================================ // JOB #628 — extension of row 53's §3.4 verification beyond its stated range. // // Row 53 is Q-zonegap-reduction (note research/history/staging/zonegap-02-reduction.md), // the proof-target note for TODO item Z. Its §3.4 states the zone's per-prime // fresh-kill identity // freshZone(q) = Phi*(floor((p'^2-1)/q), q) - Phi*(floor(p/q), q), // Phi*(t,q) = #{2 <= m <= t : P^-(m) >= q}, // with the prime-regime simplification // freshZone(q) = pi(floor((p'^2-1)/q)) - pi(q-1) whenever q^3 > p'^2 - 1, // VERIFIED in the served producer at p = 7, 11, 13 only, and its §5 says the // general-p statement "deserves five lines in a future pass, not a claim here". // Its SEC D3 measures the youngest active prime q = p at 2..4 fresh kills // "at every level to 97". // // This script tests, independently of the producer (no import, own sieve): // PART 1 (p <= 500, every prime q <= p) // (a) the identity: brute force vs the Phi* formula; // (b) the stated regime boundary: is it SUFFICIENT and is it NECESSARY? // PART 2 (p <= 100000) // (c) the youngest-prime count: is "2..4 to 97" a range effect? // Nothing here is a proof; every claim below is a finite count with its range. // // stdout is the artifact; progress and timing go to stderr. // ============================================================================ const PMAX = 500; // PART 1 level bound const P2 = 100000; // PART 2 level bound const t0 = Date.now(); function sieve(n) { const comp = new Uint8Array(n + 1), pr = []; for (let i = 2; i <= n; i++) { if (!comp[i]) { pr.push(i); for (let j = i * i; j <= n; j += i) comp[j] = 1; } } return pr; } const PR1 = sieve(3000); const nextP = (p) => { let q = p + 1; while (!PR1.includes(q)) q++; return q; }; const PRP = PR1.filter((q) => q <= PMAX); const N = nextP(PMAX) * nextP(PMAX); // largest zone top in PART 1 process.stderr.write(`PART1 lpf sieve to N=${N}\n`); // pi[] up to N: the prime-regime count needs pi(T) with T = floor((N-1)/q), not pi(1000) const piBig = new Int32Array(N + 1); { const comp = new Uint8Array(N + 1); let c = 0; for (let i = 2; i <= N; i++) { if (!comp[i]) { c++; for (let j = i * i; j <= N; j += i) comp[j] = 1; } piBig[i] = c; } for (let i = 0; i <= N; i++) if (i < 2) piBig[i] = 0; } const PI = (t) => (t < 0 ? 0 : piBig[Math.min(t, N)]); // lpf[m] = least prime factor of m (linear sieve) const lpf = new Uint32Array(N + 1); { const pr = []; for (let i = 2; i <= N; i++) { if (!lpf[i]) { lpf[i] = i; pr.push(i); } for (const q of pr) { const v = i * q; if (v > N || q > lpf[i]) break; lpf[v] = q; } } } // prefix_q[t] = Phi*(t, q), for t <= floor((N-1)/q); total memory ~ N * sum(1/q). const pref = new Map(); for (const q of PRP) { const T = Math.floor((N - 1) / q); const a = new Uint32Array(T + 1); for (let m = 1; m <= T; m++) a[m] = a[m - 1] + (m >= 2 && lpf[m] >= q ? 1 : 0); pref.set(q, a); } const phi = (t, q) => { const a = pref.get(q); return (t <= 0 || t > a.length - 1) ? 0 : a[t]; }; // ---- PART 1 ----------------------------------------------------------------- let pairs = 0, identFail = 0, regimeHolds = 0, regimeAgree = 0, regimeNecess = 0, regimeWrong = 0, levels1 = 0; const detail = []; for (const p of PRP) { if (p < 3) continue; levels1++; const pp = nextP(p), top = pp * pp; const cnt = new Map(); for (let n = p + 1; n < top; n++) { const q = lpf[n]; if (q < n && q <= p) cnt.set(q, (cnt.get(q) || 0) + 1); } for (const q of PRP) { if (q > p) break; pairs++; const brute = cnt.get(q) || 0; const formula = phi(Math.floor((top - 1) / q), q) - phi(Math.floor(p / q), q); const piForm = PI(Math.floor((top - 1) / q)) - PI(q - 1); const holds = q * q * q > top - 1; if (brute !== formula) { identFail++; detail.push(`IDENTITY FAIL p=${p} q=${q}: brute=${brute} formula=${formula}`); } if (holds) { regimeHolds++; if (piForm === formula) regimeAgree++; else { regimeWrong++; detail.push(`REGIME FAIL p=${p} q=${q}: holds but piForm=${piForm} != formula=${formula}`); } } else if (piForm === formula) { regimeNecess++; detail.push(`BOUNDARY LOOSE p=${p} q=${q}: q^3 <= p'^2-1 but piForm agrees (${piForm})`); } } } process.stderr.write(`PART1 done in ${((Date.now() - t0) / 1000).toFixed(1)}s\n`); // ---- PART 2 ----------------------------------------------------------------- const LIM2 = Math.ceil(P2 * 1.2); const PR2 = sieve(LIM2); const isP2 = new Uint8Array(LIM2 + 1); for (const q of PR2) isP2[q] = 1; const nextP2 = (p) => { let q = p + 1; while (!isP2[q]) q++; return q; }; const pi2 = new Int32Array(LIM2 + 1); { let k = 0; for (let i = 0; i < pi2.length; i++) { while (k < PR2.length && PR2[k] === i) k++; pi2[i] = k; } } const pList = PR2.filter((p) => p <= P2 && p >= 3); const dist = new Map(); let firstOver4 = null, over4 = 0, ymin = 99, ymax = -1; const to97 = []; for (const p of pList) { const pp = nextP2(p), T = Math.floor((pp * pp - 1) / p); const c = pi2[T] - pi2[p - 1]; dist.set(c, (dist.get(c) || 0) + 1); if (c > 4 && !firstOver4) firstOver4 = { p, pp, T, c }; if (c > 4) over4++; ymin = Math.min(ymin, c); ymax = Math.max(ymax, c); if (p <= 97) to97.push(c); } // ---- OUTPUT ----------------------------------------------------------------- console.log('JOB #628 — row 53 (Q-zonegap-reduction) §3.4 verification, extended'); console.log(''); console.log(`PART 1 identity and regime boundary, every prime p in [3,${PMAX}], every prime q <= p`); console.log(` levels ${levels1}; (p,q) pairs ${pairs}`); console.log(` (a) freshZone(q) identity failures (brute != Phi*): ${identFail}`); console.log(` (b) stated boundary q^3 > p'^2-1 holds at ${regimeHolds} pairs; pi-form agrees at ${regimeHolds - regimeWrong} of them`); console.log(` stated boundary FAILS at ${pairs - regimeHolds} pairs; pi-form agrees anyway (condition loose): ${regimeNecess}`); console.log(` => boundary sufficient on this range: ${regimeWrong === 0}; exactly tight (no loose pair): ${regimeNecess === 0}`); console.log(''); console.log(`PART 2 youngest active prime q = p, fresh kills in its whole zone, p in [3,${P2}]`); console.log(` levels ${pList.length}; count range ${ymin}..${ymax}; levels with count > 4: ${over4}`); console.log(` count distribution: ${[...dist.entries()].sort((a, b) => a[0] - b[0]).map(([k, v]) => `${k}:${v}`).join(' ')}`); console.log(` p <= 97: ${to97.join(',')} (the note's "2..4 at every level to 97")`); console.log(` first level with count > 4: ${firstOver4 ? `p=${firstOver4.p} (p'=${firstOver4.pp}, T=${firstOver4.T}, count ${firstOver4.c})` : 'none'}`); console.log(''); if (detail.length) { console.log('DETAIL'); for (const d of detail.slice(0, 30)) console.log(' ' + d); } else console.log('DETAIL none'); console.log(''); console.log(identFail === 0 && regimeWrong === 0 ? 'PART 1 ASSERTIONS PASS' : 'PART 1 FAILURES PRESENT'); process.stderr.write(`total ${((Date.now() - t0) / 1000).toFixed(1)}s\n`); if (identFail || regimeWrong) process.exitCode = 1;