#!/usr/bin/env python3 """Part 2 of the job #999 triage: two readings that are BOTH exact under (P), evaluated at the same base. Under (P) they must agree; their disagreement is a model falsifier that needs no control object and no regression over the wide b range. Reader A (the route's): delta_hat_A(b) = (D(b,1) - D(b,2)) / ln(4/3) Reader B (rung regression at one fixed base): slope of D(b,k) on ln(1 + 1/k), k = 1..k_max(b); under (P) D(b,k) = -ln c + delta ln(1+1/k) - delta ln ln b, so the slope is exactly delta at every fixed b. Also reported on the deliberately perturbed law of return #393, to calibrate how much disagreement a mere violation of (P) produces. """ import json import math A = [1, 5, 11, 29, 41, 65, 107, 149, 203, 257, 347, 527, 545, 617, 707, 869, 965, 1079, 1283, 1397, 1529, 1709] P = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79] G2 = [a + 1 for a in A] def Ghat(n): best = 2 for p in P: if p <= n: best = p return G2[P.index(best)] def reader_b(lg, b, kmax): """least-squares slope of D(b,k) on ln(1+1/k), k = 1..kmax""" xs = [math.log(1 + 1 / k) for k in range(1, kmax + 1)] ys = [lg(b ** (k + 1)) - lg(b ** k) - lg(b) for k in range(1, kmax + 1)] n = len(xs) mx, my = sum(xs) / n, sum(ys) / n sxy = sum((x - mx) * (y - my) for x, y in zip(xs, ys)) sxx = sum((x - mx) ** 2 for x in xs) slope = sxy / sxx resid = [y - (my + slope * (x - mx)) for x, y in zip(xs, ys)] return {"kmax": kmax, "ns": n, "slope": slope, "max_abs_resid": max(abs(r) for r in resid), "D_values": ys, "x_values": xs} def report(name, lg, bases, kmax_of): rows = [] for b in bases: kmax = kmax_of(b) if kmax < 2: continue d1 = lg(b ** 2) - 2 * lg(b) d2 = lg(b ** 3) - lg(b ** 2) - lg(b) a_hat = (d1 - d2) / math.log(4.0 / 3.0) rb = reader_b(lg, b, kmax) rows.append({"b": b, "kmax": kmax, "reader_A_difference": a_hat, "reader_B_regression": rb["slope"], "disagreement": a_hat - rb["slope"], "B_max_abs_resid": rb["max_abs_resid"], "B_D_values": rb["D_values"]}) return {"object": name, "rows": rows, "max_abs_disagreement": max(abs(r["disagreement"]) for r in rows)} lg_real = lambda n: math.log(Ghat(n)) def make_perturbed(delta, pert=0.35): c, beta = 0.37, 1.85 g = lambda n: c * n ** beta * (math.log(n) ** delta) * (1 + pert / math.log(n)) return lambda n: math.log(g(n)) def make_exact(delta): c, beta = 0.37, 1.85 return lambda n: math.log(c) + beta * math.log(n) + delta * math.log(math.log(n)) out = {} # served G2 ladder, trusted reach 82: k_max(b) from b^(k+1) <= 82 reach = 82 kmax82 = {b: max(k for k in range(1, 40) if b ** (k + 1) <= reach) for b in (2, 3, 4)} out["served_G2"] = report("G2 trusted to 82", lg_real, [2, 3, 4], lambda b: kmax82[b]) out["exact_law_delta_2"] = report("exact law delta=2", make_exact(2.0), [2, 3, 4], lambda b: kmax82[b]) out["exact_law_delta_minus_1"] = report("exact law delta=-1", make_exact(-1.0), [2, 3, 4], lambda b: kmax82[b]) out["perturbed_true_delta_2"] = report("perturbed delta=2", make_perturbed(2.0), [2, 3, 4], lambda b: kmax82[b]) out["perturbed_true_delta_minus_half"] = report("perturbed delta=-0.5", make_perturbed(-0.5), [2, 3, 4], lambda b: kmax82[b]) # the control reach the record cites: A048670 published to p = 311 (64 terms) reach312 = 312 kmax312 = {b: max(k for k in range(1, 40) if b ** (k + 1) <= reach312) for b in (2, 3, 4, 5, 6, 7, 8, 9)} out["control_reach_k2_bases_312"] = [b for b in range(2, 312) if b ** 3 <= reach312] out["control_reach_k3_bases_312"] = [b for b in range(2, 312) if b ** 4 <= reach312] out["kmax_at_312"] = kmax312 print(json.dumps(out, indent=1))