// Version-3 check for finding #110886 (A(N) display in section 3.4). Exact BigInt rationals; shares no code with chk.mjs. // For x = p/q: greedy orbit n_0 < n_1 < ... (take 1/(n+2) at step n iff it fits the residual), then for EVERY N in [0, Nmax] // compare A(N) = #{k : n_k <= N} with (old) log2 log(N+2) - log2 log(1/x) + 1 and (new) max(0, same). // Exact form of the new bound for A >= 1: A <= log2 log(N+2) - log2 log(q/p) + 1 <=> q^(2^(A-1)) <= (N+2) p^(2^(A-1)). // Old display < 0 <=> (N+2)^2 p < q (i.e. N+2 < x^(-1/2)). const gcd = (a, b) => { while (b) [a, b] = [b, a % b]; return a; }; function orbit(p, q, maxTerms = 60) { let a = BigInt(p), b = BigInt(q), n = 0n; const out = []; while (a > 0n && out.length < maxTerms) { let m = (b + a - 1n) / a - 2n; if (m < n) m = n; // smallest n' >= n with 1/(n'+2) <= a/b out.push(m); const d = m + 2n; a = a * d - b; b = b * d; const g = gcd(a, b); a /= g; b /= g; n = m + 1n; } return { terms: out, finite: a === 0n }; } let rng = 0x2545F491; const rnd = k => { rng = (rng * 1103515245 + 12345) & 0x7fffffff; return (rng >>> 8) % k; }; const xs = [[1, 100], [1, 3], [2, 3], [99, 100], [1, 1000], [3, 7], [1, 2], [5, 6]]; for (let i = 0; i < 2000; i++) { const q = 2 + rnd(5000), p = 1 + rnd(q - 1); if (gcd(p, q) === 1) xs.push([p, q]); } const NMAX = 20000; let cases = 0, newFail = 0, oldFail = 0, oldFailNotPredicted = 0, predictedNotFail = 0, exactVsFloat = 0, atNj = 0, nonterm = 0; for (const [p, q] of xs) { const { terms, finite } = orbit(p, q); if (!finite) nonterm++; const P = BigInt(p), Q = BigInt(q), L1x = Math.log(q / p); const test = (N, A) => { cases++; const rhs = Math.log2(Math.log(N + 2)) - Math.log2(L1x) + 1; const exactOk = A === 0 || Q ** (1n << BigInt(A - 1)) <= BigInt(N + 2) * P ** (1n << BigInt(A - 1)); const floatOk = A <= Math.max(0, rhs) + 1e-9; if (exactOk !== floatOk) exactVsFloat++; if (!exactOk) newFail++; const oldBad = A > rhs + 1e-9, predicted = BigInt(N + 2) ** 2n * P < Q; if (oldBad) { oldFail++; if (!(A === 0 && predicted)) oldFailNotPredicted++; } else if (predicted) predictedNotFail++; }; let k = 0; for (let N = 0; N <= NMAX; N++) { while (k < terms.length && terms[k] <= BigInt(N)) k++; test(N, k); } terms.forEach((t, j) => { if (t > BigInt(NMAX) && t < 2n ** 52n) { atNj++; test(Number(t), j + 1); } }); } const ex = orbit(1, 100).terms[0], rhs0 = Math.log2(Math.log(2)) - Math.log2(Math.log(100)) + 1; console.log(`x=1/100: n_0=${ex}, N=0: A(0)=0, old display RHS=${rhs0.toFixed(4)}`); console.log(`targets ${xs.length} (all orbits finite: ${nonterm === 0}); (x,N) cases ${cases} (every N<=${NMAX}, plus ${atNj} cases N=n_j>${NMAX})`); console.log(`max(0,...) bound: ${newFail} failures; exact-vs-float disagreements ${exactVsFloat}`); console.log(`old display: ${oldFail} failures, all with A(N)=0 and N+2 0 && oldFailNotPredicted === 0 && predictedNotFail === 0 && nonterm === 0; console.log(pass ? 'PASS' : 'FAIL'); process.exit(pass ? 0 : 1);