"""Job #193: read validate.out + ext.out, tabulate every doubling step and refit K*'s growth. Custody gate: the fit of ln(K*+1) on ln P(2s) over the corpus's 16 steps must reproduce attack-kstar-01.md ยง2, slope 0.8184 +/- 0.0908 (one point per distinct step), before any refit with the new steps is printed. Also prints Lemma 1's floor N(s) = pi(2s) - pi(s) (attack-0829n-doubling-bridge.md) at every s a step serves. """ import math, re, sys W = "/Users/chrisbenjaminsen/Projects/solveathome/work/job193/" G2 = {2: 2, 3: 6, 5: 12, 7: 30, 11: 42, 13: 66, 17: 108, 19: 150, 23: 204, 29: 258, 31: 348, 37: 528, 41: 546, 43: 618, 47: 708, 53: 870, 59: 966} # A144311 a(n) + 1 CEIL = 2 ** 4.26645028414864191641 # 2^beta2 = 19.2455 def isprime(n): return n > 1 and all(n % d for d in range(2, math.isqrt(n) + 1)) def P(n): return max(p for p in range(2, n + 1) if isprime(p)) def pi(n): return sum(1 for p in range(2, n + 1) if isprime(p)) import os steps = [] outs = ["validate.out", "ext.out"] + (["ext29.out"] if os.path.exists(W + "ext29.out") else []) for l in "".join(open(W + f).read() for f in outs).splitlines(): m = re.match(r"(\d+)#->(\d+)#.*K\* = (\d+)", l) if m: steps.append(tuple(map(int, m.groups()))) serves = {} for s in range(2, 64): serves.setdefault((P(s), P(2 * s)), []).append(s) def ols(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)) b = sxy / sxx; a = my - b * mx rss = sum((y - a - b * x) ** 2 for x, y in zip(xs, ys)) return b, math.sqrt(rss / (n - 2) / sxx) print("step s K* K*+1 C2 exact floor N(s)=pi(2s)-pi(s) K*+1 > 2^beta2") for Pb, Pp, K in steps: ss = serves.get((Pb, Pp), []) floors = ",".join(str(pi(2 * s) - pi(s)) for s in ss) print(f"{Pb}#->{Pp}#".ljust(11), (",".join(map(str, ss)) or "-").ljust(8), str(K).rjust(3), str(K + 1).rjust(5), f"{G2[Pp] / G2[Pb]:9.4f}", floors.rjust(22), " yes" if K + 1 > CEIL else "") corpus = steps[:16] b, se = ols([math.log(Pp) for _, Pp, _ in corpus], [math.log(K + 1) for _, _, K in corpus]) print(f"\ncustody: ln(K*+1) on ln P(2s), corpus 16 steps: slope {b:.4f} +/- {se:.4f} (attack-kstar-01.md: 0.8184 +/- 0.0908)") if not (abs(b - 0.8184) < 5e-4 and abs(se - 0.0908) < 5e-4): sys.exit("custody gate FAILED: fit convention differs from the corpus; no refit printed") b, se = ols([math.log(Pp) for _, Pp, _ in steps], [math.log(K + 1) for _, _, K in steps]) print(f"refit, all {len(steps)} steps: slope {b:.4f} +/- {se:.4f}")