// numcheck.js -- solveathome job #7. Two checks on section 3 of research/exact-g2-ladder.js, // written independently of that file (only its fourteen (x, G2, pos) rows are copied, as data). // // Part A uses Number only, no BigInt anywhere: the fourteen lower certificates // (pos is a twin slot mod x#, and the next slot is exactly G2 above it). // The file's header says its check FAILS if the arithmetic is done in Number. // // Part B: the mirror witness. r is a slot iff P-r-2 is (r = 0 or -2 mod p swaps with -r-2 = -2 or 0), // so the gap [pos, pos+G2] mirrors to [P-pos-G2-2, P-pos-2], another maximum. Checked in BigInt, // then again through Number, where it exceeds 2^53. 'use strict'; const ROWS = [ [2, 2, 1], [3, 6, 5], [5, 12, 17], [7, 30, 71], [11, 42, 899], [13, 66, 731], [17, 108, 701], [19, 150, 659], [23, 204, 76166567], [29, 258, 1205437109], [31, 348, 8813641451], [37, 528, 544899485411], [41, 546, 3784200788231], [43, 618, 830330079152051], ]; const PR = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43]; const slotN = (r, x) => PR.every(p => p > x || (r % p !== 0 && (r + 2) % p !== 0)); const nextGapN = (r, x) => { let d = 1; while (!slotN(r + d, x)) d++; return d; }; console.log('A. Number-only lower certificates'); console.log('x G2 pos pos+G2 safe pos is slot next slot at ok'); let allA = true; for (const [x, g, pos] of ROWS) { const safe = Number.isSafeInteger(pos + g); const at = slotN(pos, x), d = nextGapN(pos, x), ok = safe && at && d === g; allA = allA && ok; console.log(`${String(x).padEnd(4)}${String(g).padEnd(6)}${String(pos).padEnd(20)}${String(safe).padEnd(12)}` + `${String(at).padEnd(13)}${('+' + d).padEnd(14)}${ok ? 'YES' : 'NO'}`); } console.log(`all fourteen hold in Number arithmetic: ${allA}`); console.log('\nB. mirror witness P - pos - G2 - 2 at x = 41, 43'); const slotB = (r, x) => PR.every(p => p > x || (r % BigInt(p) !== 0n && (r + 2n) % BigInt(p) !== 0n)); for (const [x, g, pos] of ROWS.filter(r => r[0] >= 41)) { const P = PR.filter(p => p <= x).reduce((a, p) => a * BigInt(p), 1n); const m = P - BigInt(pos) - BigInt(g) - 2n; let d = 1n; while (!slotB(m + d, x)) d++; const mN = Number(m); // what a Number implementation would hold const exact = BigInt(mN) === m; let dN = 1; const atN = slotN(mN, x); if (atN) while (!slotN(mN + dN, x) && dN < 10000) dN++; console.log(`x=${x}: mirror ${m} > 2^53: ${m > 2n ** 53n}`); console.log(` BigInt: slot ${slotB(m, x)}, next slot at +${d} ${slotB(m, x) && d === BigInt(g) ? 'YES' : 'NO'}`); console.log(` Number: holds ${mN} (exact: ${exact}), slot ${atN}` + (atN ? `, next slot at +${dN}` : '') + ` ${atN && dN === g && exact ? 'YES' : 'NO'}`); }