"""Job #42: compare out-spms34.txt with the embedded OUTPUT block of research/shifted-prime-mobius-sums.js. Checks, j = 10..34: - pi(2^j) + 2 against OEIS A007053 (the script counts primes p >= 5); - pi(2^j), U_mu+, U_mu-, U_lam+, U_lam- as exact integers against the embedded CUMULATIVE rows; - Sq/pi to five decimals against the embedded rows; - the DYADIC Mdy(j) column against the embedded rows (printed for the F3 cross-check). Prints the run's F1-F4 lines verbatim and every row that differs. stdout is deterministic. """ import re, sys W = "/Users/chrisbenjaminsen/Projects/solveathome/work/job42/" A007053 = [0,1,2,4,6,11,18,31,54,97,172,309,564,1028,1900,3512,6542,12251,23000,43390,82025,155611,295947,564163,1077871, 2063689,3957809,7603553,14630843,28192750,54400028,105097565,203280221,393615806,762939111] # n = 0..34 def sections(text, prefix): """Parse 'CUMULATIVE', 'AGAINST', 'DYADIC' tables into {name: {j: [cells]}}; prefix is '// ' for the embed.""" out, cur = {}, None for raw in text.splitlines(): if prefix and not raw.startswith(prefix.rstrip()): continue l = raw[len(prefix):] if prefix and raw.startswith(prefix) else (raw[2:] if prefix and raw.startswith("//") else raw) l = l.strip() for name in ("CUMULATIVE", "AGAINST", "DYADIC"): if l.startswith(name): cur = name; out[cur] = {}; break else: m = re.match(r"^(\d+) \| (.*)$", l) if cur and m: out[cur][int(m.group(1))] = [c.strip() for c in m.group(2).split("|")] elif not l: cur = None return out run_text = open(W + "out-spms34.txt", encoding="utf-8").read() emb_text = open(W + "research/shifted-prime-mobius-sums.js", encoding="utf-8").read() emb_text = emb_text[emb_text.index("// OUTPUT"):] run, emb = sections(run_text, ""), sections(emb_text, "// ") diffs = 0 print("CUMULATIVE j = 10..34: pi(2^j), U_mu+, U_mu-, U_lam+, U_lam-, Sq/pi [run | embedded | A007053 check]") for j in range(10, 35): r, e = run["CUMULATIVE"].get(j), emb["CUMULATIVE"].get(j) ints_r, ints_e = r[:5], e[:5] sq_r, sq_e = f"{float(r[5]):.5f}", f"{float(e[5]):.5f}" a_ok = int(r[0]) + 2 == A007053[j] same = ints_r == ints_e and sq_r == sq_e diffs += (not same) + (not a_ok) print(f" {j} | {' | '.join(ints_r)} | {sq_r} | embed {'SAME' if same else 'DIFFERS: ' + ' | '.join(ints_e) + ' | ' + sq_e} | " f"pi+2 = {int(r[0]) + 2} {'= A007053' if a_ok else '!= A007053 ' + str(A007053[j])}") print("\nDYADIC Mdy(j), j = 10..34 [run | embedded]") for j in range(10, 35): r, e = run["DYADIC"].get(j), emb["DYADIC"].get(j) same = r[0] == e[0] diffs += not same print(f" {j} | {r[0]} | {'SAME' if same else 'DIFFERS: ' + e[0]}") print("\nF1 control bracketing (|U|/sqrt(pi) over control rms) at j = 30..34, from the run") for j in range(30, 35): c = run["AGAINST"][j] print(f" {j} | ratios mu+ {c[2]} mu- {c[5]} lam+ {c[8]} lam- {c[11]} | ctrl rms lam+ {c[7]} lam- {c[10]}") print("\nRun's verdict and control lines, verbatim:") for l in run_text.splitlines(): if re.match(r"^(SLOPE|SIGN PERSISTENCE|FALSIFIER|CONTROLS|runtime|config)", l): print(" " + l) print(f"\n{'NO DIFFERENCES' if diffs == 0 else str(diffs) + ' DIFFERENCES'} in the compared cells (j = 10..34)") sys.exit(1 if diffs else 0)