#!/usr/bin/env node 'use strict'; // job #175 (explore, formalize lane, Q-hsubpow-K-0829n): checks for the claim // sup_{b>=2, k>=1} B(b,k) = ln( ln 7 / (ln 3 * ln 2) ) = 0.938194..., attained only at (b,k) = (2,2), // where P(m) = largest prime <= m and B(b,k) = lnln P(b^(k+1)) - lnln P(b^k) - lnln P(b) // (return #10's stepped delta-coefficient; there it was MEASURED on b <= 4000, b^(k+1) <= 1e12). // Part 1: exact small cases. Part 2: the analytic bounds of the proof, evaluated on a grid, must sit below the sup. // Part 3: an independent sweep, b <= 20000 with b^(k+1) <= 1e15, P by deterministic Miller-Rabin. // Part 4: the two prime inputs, P(m) >= (7/10) m for m >= 2 and P(m) > (5/6) m for m >= 30, swept to 2e6. // A finite check: a measurement of the proof's inputs, not the proof. Deterministic; elapsed to stderr. const t0 = Date.now(); const ln = Math.log; function modpow(b, e, m) { let r = 1n; b %= m; while (e > 0n) { if (e & 1n) r = r * b % m; b = b * b % m; e >>= 1n; } return r; } function isPrime(n) { if (n < 2n) return false; for (const p of [2n, 3n, 5n, 7n, 11n, 13n, 17n, 19n, 23n, 29n, 31n, 37n]) { if (n === p) return true; if (n % p === 0n) return false; } let d = n - 1n, s = 0; while (!(d & 1n)) { d >>= 1n; s++; } for (const a of [2n, 3n, 5n, 7n, 11n, 13n, 17n, 19n, 23n, 29n, 31n, 37n]) { let x = modpow(a, d, n); if (x === 1n || x === n - 1n) continue; let ok = false; for (let r = 1; r < s; r++) { x = x * x % n; if (x === n - 1n) { ok = true; break; } } if (!ok) return false; } return true; } const Pcache = new Map(); function P(m) { // largest prime <= m, m a BigInt >= 2 const key = m.toString(); if (Pcache.has(key)) return Pcache.get(key); let q = m; while (!isPrime(q)) q--; Pcache.set(key, q); return q; } const lnB = x => { const s = x.toString(); return ln(Number(s.slice(0, 15))) + (s.length - Math.min(15, s.length)) * Math.LN10; }; const B = (b, k) => { const bb = BigInt(b); return ln(lnB(P(bb ** BigInt(k + 1)))) - ln(lnB(P(bb ** BigInt(k)))) - ln(lnB(P(bb))); }; const SUP = ln(ln(7) / (ln(3) * ln(2))); console.log('Part 1. exact small cases, B(b,k) = lnln P(b^(k+1)) - lnln P(b^k) - lnln P(b)'); for (const [b, k] of [[2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [3, 1], [3, 2], [4, 1], [4, 2], [5, 1], [10, 1]]) { const bb = BigInt(b); console.log(` (${b},${k}) P = ${P(bb ** BigInt(k + 1))}, ${P(bb ** BigInt(k))}, ${P(bb)} B = ${B(b, k).toFixed(10)}`); } console.log(` claimed sup ln(ln7/(ln3*ln2)) = ${SUP.toFixed(10)}`); console.log('Part 2. the proof\'s bounds (c = ln(10/7), L = ln b), each must stay below the sup'); const c = ln(10 / 7); const gen = (k, L) => ln((k + 1) * L / ((k * L - c) * (L - c))); let worst1 = -Infinity, worst2 = -Infinity, worst3 = -Infinity; for (let b = 5; b <= 1e6; b = b < 1000 ? b + 1 : Math.ceil(b * 1.01)) worst1 = Math.max(worst1, gen(1, ln(b))); // k = 1, b >= 5 for (let k = 2; k <= 200; k++) for (let b = 3; b <= 1e6; b = b < 1000 ? b + 1 : Math.ceil(b * 1.01)) worst2 = Math.max(worst2, gen(k, ln(b))); // k >= 2, b >= 3 for (let k = 5; k <= 2000; k++) worst3 = Math.max(worst3, ln((k + 1) * ln(2) / (k * ln(2) - ln(6 / 5))) - ln(ln(2))); // b = 2, k >= 5 console.log(` k = 1, b >= 5: max bound ${worst1.toFixed(6)} (at b = 5: ${gen(1, ln(5)).toFixed(6)})`); console.log(` k >= 2, b >= 3: max bound ${worst2.toFixed(6)} (at k = 2, b = 3: ${gen(2, ln(3)).toFixed(6)})`); console.log(` b = 2, k >= 5: max bound ${worst3.toFixed(6)} (at k = 5)`); console.log(` all below the sup: ${Math.max(worst1, worst2, worst3) < SUP}`); console.log('Part 3. independent sweep: every b <= 20000, every k with b^(k+1) <= 1e15'); let pairs = 0, best = { v: -Infinity }, second = { v: -Infinity }, above = 0; for (let b = 2; b <= 20000; b++) { for (let k = 1; Math.pow(b, k + 1) <= 1e15; k++) { const v = B(b, k); pairs++; if (v > best.v) { second = best; best = { v, b, k }; } else if (v > second.v) second = { v, b, k }; if (v > SUP + 1e-12) above++; } } console.log(` pairs ${pairs}; max B = ${best.v.toFixed(10)} at (${best.b},${best.k}); runner-up ${second.v.toFixed(10)} at (${second.b},${second.k}); pairs above the sup: ${above}`); console.log('Part 5. the same sweep with the base floor raised (MEASURED only; the proof covers b >= 2)'); for (const b0 of [3, 4, 5, 16]) { let bb = { v: -Infinity }; for (let b = b0; b <= 20000; b++) for (let k = 1; Math.pow(b, k + 1) <= 1e15; k++) { const v = B(b, k); if (v > bb.v) bb = { v, b, k }; } console.log(` sup over b >= ${b0}: ${bb.v.toFixed(10)} at (${bb.b},${bb.k})`); } console.log('Part 4. the prime inputs, swept: P(m) >= 0.7 m for 2 <= m <= 2e6, and P(m) > 5m/6 for 30 <= m <= 2e6'); const N = 2000000, comp = new Uint8Array(N + 1); for (let i = 2; i * i <= N; i++) if (!comp[i]) for (let j = i * i; j <= N; j += i) comp[j] = 1; let last = 0, fail7 = 0, fail56 = 0, minRatio = { v: Infinity, m: 0 }, minRatio30 = { v: Infinity, m: 0 }; for (let m = 2; m <= N; m++) { if (!comp[m]) last = m; const r = last / m; if (10 * last < 7 * m) fail7++; if (r < minRatio.v) minRatio = { v: r, m }; if (m >= 30) { if (6 * last <= 5 * m) fail56++; if (r < minRatio30.v) minRatio30 = { v: r, m }; } } console.log(` failures of P(m) >= 0.7m: ${fail7}; min P(m)/m = ${minRatio.v.toFixed(6)} at m = ${minRatio.m}`); console.log(` failures of P(m) > 5m/6 (m >= 30): ${fail56}; min P(m)/m = ${minRatio30.v.toFixed(6)} at m = ${minRatio30.m}`); console.error(`elapsed ${((Date.now() - t0) / 1000).toFixed(1)} s`);