#!/usr/bin/env python3 """Rung-pair delta-meter: calibrate before fitting. Object. With Ghat(n) = c n^b (ln n)^d (the exact law of attack-0829n-hsubpow-K.md sec 2d), f = ln Ghat, and the rung defect D(b,k) = f(b^(k+1)) - f(b) - f(b^k) the exact-law form is D(b,k) = -ln c + d*ln(1 + 1/k) - d*ln ln b . (P) Two consequences, both one line from (P): (i) the slope of D(b,k) against ln ln b is -d for EVERY rung k, with b and c eliminated; (ii) the rung difference D(b,k) - D(b,k') = d*ln( (1+1/k)/(1+1/k') ) is INDEPENDENT of b, so d is readable from a single base and three levels, with no b-regression at all. The record's delta-meter is (i) at k = 1 only (the diagonal b -> b^2); it failed its control at 16 bases (slope +0.5157 +- 0.1969 against a conjectured d = 2 + o(1)). This script reproduces that calibration and tests the generalisation. """ import math C, BETA = 0.37, 1.85 def ladder(delta, bases, rungs): """Exact-law Ghat values for the levels b^k, k = 0..rungs, for each base b.""" out = {} for b in bases: vals = {} for k in range(rungs + 1): n = b ** k if n < 2: continue vals[k] = C * n ** BETA * (math.log(n) ** delta) out[b] = vals return out def f(v): return math.log(v) def slope(xs, ys): n = len(xs) mx = sum(xs) / n my = sum(ys) / n sxx = sum((x - mx) ** 2 for x in xs) sxy = sum((x - mx) * (y - my) for x, y in zip(xs, ys)) s = sxy / sxx resid = sum((y - my - s * (x - mx)) ** 2 for x, y in zip(xs, ys)) / (n - 2) se = math.sqrt(resid / sxx) return s, se def diagonal_slope(lad, k): """Slope of D(b,k) on ln ln b -- what the record's meter does at k = 1.""" xs, ys = [], [] for b, vals in lad.items(): if k not in vals or (k + 1) not in vals: continue xs.append(math.log(math.log(b))) ys.append(f(vals[k + 1]) - f(vals[1]) - f(vals[k])) return slope(xs, ys) def rung_reader(lad, k, kp, base): """d from a SINGLE base using two rung pairs; b-free by (P).""" v = lad[base] D1 = f(v[k + 1]) - f(v[1]) - f(v[k]) D2 = f(v[kp + 1]) - f(v[1]) - f(v[kp]) factor = math.log((1 + 1 / k) / (1 + 1 / kp)) return (D1 - D2) / factor print('== 1. exact laws: the record\'s three calibrating laws, k = 1..4 ==') for delta in (0.0, 2.0, -1.0): lad = ladder(delta, range(2, 10), 4) line = ' d = %+.1f diagonal slopes:' % delta for k in (1, 2, 3): s, se = diagonal_slope(lad, k) line += ' k=%d %.4f(+-%.4f) -> dhat %+.4f' % (k, s, se, -s) print(line) print(' single-base rung reader (k=1 vs k=2):', ', '.join('%+.5f' % rung_reader(lad, 1, 2, b) for b in (2, 3, 5, 7))) print() print('== 2. the same meter on a perturbed law Ghat(1 + a/ln n), a = 0.35 ==') for delta in (2.0, -0.5): lad = {} for b in range(2, 18): vals = {} for k in range(0, 4): n = b ** k if n < 2: continue vals[k] = C * n ** BETA * (math.log(n) ** delta) * (1 + 0.35 / math.log(n)) lad[b] = vals s1, se1 = diagonal_slope(lad, 1) print(' true d = %+.1f | 16-base diagonal: %.4f(+-%.4f) -> dhat %+.4f | rung reader: %s' % (delta, s1, se1, -s1, ' '.join('%+.4f' % rung_reader(lad, 1, 2, b) for b in (2, 4, 8, 16)))) print() print('== 3. why the diagonal is the weak reader ==') for delta in (2.0,): lad = {} for b in range(2, 18): vals = {} for k in range(0, 4): n = b ** k if n < 2: continue vals[k] = C * n ** BETA * (math.log(n) ** delta) * (1 + 0.35 / math.log(n)) lad[b] = vals for k in (1, 2): m = sum(math.log(math.log(b)) for b in lad) / len(lad) print(' k = %d : mean ln ln b = %.4f, spread = %.4f (the regressor is nearly collinear)' % (k, m, max(math.log(math.log(b)) for b in lad) - min(math.log(math.log(b)) for b in lad))) print() print('Conclusion (rung of what follows): identity (P) and its two consequences are PROVEN one-liners,') print('verified here on the record\'s own three calibrating laws at k = 1, 2, 3; the single-base') print('rung reader recovers d exactly on exact laws and keeps the correct sign on a perturbed law') print('where the 16-base diagonal is biased. Whether the REAL G2 ladder obeys the exact-law') print('separation is MEASURED-or-refuted by the next experiment, not asserted here.')