# audit41.py -- solveathome job #171 (explore, Q-var41). Recompute, from the inputs the file itself states, every # number sealed in research/history/staging/var41-prereg.md (sections 1-5 and its CORRECTION), independently of # research/var41-price.js. Prints AGREE / SLIP per numeric item and CHECK blocks for statements. Python 3 only. from math import log, exp, sqrt, isqrt from decimal import Decimal, getcontext getcontext().prec = 40 def is_prime(n): # deterministic Miller-Rabin for n < 3.3e24 if n < 2: return False for p in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37): if n % p == 0: return n == p d, s = n - 1, 0 while d % 2 == 0: d //= 2; s += 1 for a in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37): x = pow(a, d, n) if x in (1, n - 1): continue for _ in range(s - 1): x = x * x % n if x == n - 1: break else: return False return True def primorial(x): P = 1 for p in range(2, x + 1): if is_prime(p): P *= p return P def largest_prime_le(n): while not is_prime(n): n -= 1 return n results = [] def check(name, got, sealed, tol, note=""): ok = abs(got - sealed) <= tol results.append((name, ok)) print(f" {'AGREE' if ok else 'SLIP '} {name}: recomputed {got!r} sealed {sealed!r}{' ' + note if note else ''}") def statement(name, ok, lines): results.append((name, ok)) print(f" {'AGREE' if ok else 'SLIP '} {name}") for l in lines: print(f" {l}") ROWS = [(7, 210, 13, 6.92, 1.05, 0.1521), (11, 2310, 47, 39.27, 10.06, 0.2563), (13, 30030, 173, 304.28, 91.13, 0.2995), (17, 510510, 709, 3245.51, 1060.54, 0.3268), (19, 9699690, 3109, 41441.19, 14392.59, 0.3473), (23, 223092870, 14929, 669028.80, 243740.37, 0.3643), (29, 6469693230, 80429, 14063617.40, 5307862.63, 0.3774), (31, 200560490130, 447829, 328601798.62, 127363168.00, 0.3876), (37, 7420738134810, 2724079, 9377228928.76, 3711451136, 0.3958)] W41, E41, S41, Y41 = 304250263527210, 303627067641.7, 256725962834, 17442769 print("SECTION 1: the table and the z = 41 inputs") for x, W, y, E, V, r in ROWS: check(f"x={x} W = x#", primorial(x), W, 0) check(f"x={x} y = largest prime <= floor(sqrt(W))", largest_prime_le(isqrt(W)), y, 0) check(f"x={x} r = Var/E to 4 dp", round(V / E, 4), r, 0) check("W(41) = 41#", primorial(41), W41, 0) check("floor(sqrt(W41))", isqrt(W41), 17442771, 0) check("y(41)", largest_prime_le(isqrt(W41)), Y41, 0) print("SECTION 2: u and the literal law") check("ln W(41)", round(log(W41), 5), 33.34886, 0) check("ln y(41)", round(log(Y41), 5), 16.67443, 0) check("u(41)", round(log(W41) / log(Y41), 7), 2.0000005, 0) for (x, W, y, *_), sealed in zip(ROWS, [2.08468, 2.01161, 2.00065, 2.00235, 2.00043, 2.00010, 2.00001, 2.00000, 2.00000]): check(f"u at x={x}", round(log(W) / log(y), 5), sealed, 0) check("literal law exp(-(0.24*4+0.13*2))", round(exp(-1.22), 5), 0.29523, 0) print("SECTION 3: residuals, increments, prediction, band") res = [round(r - 0.29523, 4) for *_, r in ROWS] for (x, *_), got, sealed in zip(ROWS, res, [-0.1431, -0.0389, 0.0043, 0.0316, 0.0521, 0.0691, 0.0822, 0.0924, 0.1006]): check(f"residual x={x}", got, sealed, 0.00006) inc = [round(res[i] - res[i - 1], 4) for i in range(1, len(res))] for got, sealed in zip(inc, [0.1042, 0.0432, 0.0273, 0.0205, 0.0170, 0.0131, 0.0102, 0.0082]): check("increment", got, sealed, 0.00006) print(f" info increment ratios, last four steps: {', '.join(f'{inc[i] / inc[i - 1]:.3f}' for i in range(4, 8))} (sealed: 0.78 to 0.80)") check("next increment, 0.80 continuation", round(0.0082 * 0.80, 4), 0.0066, 0.00006) lo_a, lo_b = 0.0082 * 0.80 ** 2, 0.0082 * 0.78 ** 2 check("lower bracket, 'two-step continuation'", round(lo_a, 4), 0.0055, 0.00006, f"(0.0082 x 0.80^2 = {lo_a:.5f}; x 0.78^2 = {lo_b:.5f}; 0.0055 needs a per-step ratio of {sqrt(0.0055 / 0.0082):.3f})") check("prediction r(41)", round(0.3958 + 0.0066, 4), 0.4024, 0) check("band low as sealed", round(0.3958 + 0.0055, 4), 0.4013, 0) check("band high", round(0.3958 + 0.0082, 4), 0.4040, 0) for rr, sealed in ((0.4024, 1.2218e11), (0.4013, 1.2185e11), (0.4040, 1.2267e11)): check(f"Var(41) at r = {rr}", float(f"{rr * E41:.4e}"), sealed, 0) lnW, lnlnW = log(W41), log(log(W41)) check("lnlnW(41)", round(lnlnW, 5), 3.50702, 0) fits = [0.4435 - 1.509 / lnW, 0.6106 - 0.729 / lnlnW, 0.4454 - 1.534 / lnW, 0.6108 - 0.729 / lnlnW] for got, sealed, tag in zip(fits, [0.3983, 0.4027, 0.3994, 0.4029], ["1/lnW frozen-8", "lnlnW frozen-8", "1/lnW refit-9", "lnlnW refit-9"]): check(f"fit {tag} at z = 41", round(got, 4), sealed, 0) print("SECTION 4a: separations and the lever arm") check("separation, refit-9", round(fits[3] - fits[2], 4), 0.0035, 0) print(f" info separation, frozen-8: {fits[1] - fits[0]:.5f} (the CORRECTION records 0.00448 -> 0.0045)") inv = [1 / log(log(W)) for _, W, *_ in ROWS] for idx, sealed, tag in ((0, 0.59646, "x = 7"), (8, 0.29508, "x = 37"), (2, 0.42861, "x = 13")): check(f"1/lnlnW at {tag}", round(inv[idx], 5), sealed, 0) check("1/lnlnW at x = 41", round(1 / lnlnW, 5), 0.28514, 0) ext = inv[8] - 1 / lnlnW check("abscissa added by z = 41", round(ext, 5), 0.00994, 0.00001) check("as % of the x >= 13 lever arm", round(100 * ext / (inv[2] - inv[8]), 1), 7.4, 0) all10, fit10 = inv[0] - 1 / lnlnW, inv[2] - 1 / lnlnW statement("'going from 0.285 to 0.000 is thirty times the range that all ten points together will cover'", abs(0.28514 / all10 - 30) < 5, [f"0.28514 / (abscissa range of all ten points, x = 7..41) = {1 / lnlnW / all10:.2f}", f"0.28514 / (range of the points the fits use, x = 13..41) = {1 / lnlnW / fit10:.2f}", f"0.28514 / (abscissa added by z = 41 alone) = {1 / lnlnW / ext:.1f} <- the 'thirty times' matches this, not the sentence"]) print("SECTION 4b and CORRECTION: sigma and z(41)") check("sigma(41) at r = 0.4024", round(sqrt(0.4024 * E41)), 349542, 1) for rr, sealed in ((0.4024, -134179), (0.4013, -134363), (0.4040, -133913)): check(f"z(41) at r = {rr}", round((S41 - E41) / sqrt(rr * E41)), sealed, 1) check("z(41)/z(37) with z(37) = -22,632.9", round(134179 / 22632.9, 2), 5.93, 0) print("SECTION 4c: the precision split") check("1% in Var moves z by (units)", round(0.005 * 134180), 670, 2) check("r precision for 5:1 on 0.0035", round(0.0035 / 5, 6), 0.0007, 0) check("as a Var precision (%)", round(100 * 0.0007 / 0.402, 2), 0.17, 0.005) print("SECTION 5: adjudication coverage") held = (round(0.4024 - 0.0016, 4), round(0.4024 + 0.0016, 4)) gaps = [] if held[0] > 0.4000: gaps.append(f"[0.4000, {held[0]:.4f})") if held[1] < 0.4048: gaps.append(f"({held[1]:.4f}, 0.4048]") statement("every outcome r receives a verdict (HELD / FAILED lnW / FAILED other)", not gaps, [f"HELD: |r - 0.4024| <= 0.0016, i.e. [{held[0]:.4f}, {held[1]:.4f}]; the registered band of section 3 is [0.4013, 0.4040]", "FAILED, lnW direction: r < 0.4000. FAILED, other direction: r > 0.4048", f"outcomes with no verdict: {', '.join(gaps) if gaps else 'none'}"]) statement("the HELD interval equals the registered band", held == (0.4013, 0.4040), [f"HELD [{held[0]:.4f}, {held[1]:.4f}] against band [0.4013, 0.4040]: the lower edges differ by {0.4013 - held[0]:.4f}"]) print("SECTION 5: the certified bar (model of var41-price.js PART 2)") u = 2.0 ** -52 def bar(C, E, V): S2 = (E * E - E + V) / 2 return u * (C * 2 * S2 + 2 * E * E + 2 * E) check("bar @37 with C = 40", float(f"{bar(40, 9377228928.76, 3711451136):.3g}"), 8.2e5, 0.02e5) V41 = 0.4024 * E41 check("bar @41 with C = 36", float(f"{bar(36, E41, V41):.2g}"), 7.8e8, 0.05e8) check("dr @41 with C = 36", round(bar(36, E41, V41) / E41, 4), 0.0026, 0.00005) P7_41 = 7 * 11 * 13 * 17 * 19 * 23 * 29 * 31 * 37 * 41 P7_43 = P7_41 * 43 statement("'11 mid-primes per factor ... since 7*11*...*43 = 2.5e14 < 41# < 7*11*...*47'", P7_43 < W41, [f"7*11*...*41 = {P7_41:.4e}, 7*11*...*43 = {P7_43:.4e}, 41# = {W41:.4e}", f"so at most 10 primes >= 7 divide one integer below 41#; the charged worst case would be 3*10+3 = 33, not 3*11+3 = 36", f"dr @41 with C = 33: {bar(33, E41, V41) / E41:.5f} (INDECISIVE threshold 0.0009: verdict unchanged)"]) def sum_inv_primes(lo, hi): s = bytearray([1]) * (hi + 1); s[0] = s[1] = 0 for i in range(2, isqrt(hi) + 1): if s[i]: s[i * i::i] = bytearray(len(range(i * i, hi + 1, i))) return sum(Decimal(1) / Decimal(p) for p in range(lo, hi + 1) if s[p]) s29, s41 = sum_inv_primes(7, 80429), sum_inv_primes(7, Y41) check("mean patch count k at @29 = 3*sum_(7<=p<=80429) 1/p (census 4.958)", round(float(3 * s29), 3), 4.958, 0.02) check("charged constant k+3 at @41 = 3*sum_(7<=p<=y41) 1/p + 3", round(float(3 * s41 + 3), 1), 9.1, 0.05) check("dr @41 with C = k+3", round(bar(float(3 * s41 + 3), E41, V41) / E41, 5), 0.00075, 0.000005) bad = [n for n, ok in results if not ok] print(f"\n{len(results)} items; SLIP on {len(bad)}:") for n in bad: print(f" - {n}")