# fill40.py -- solveathome job #40: once run-2e9.out exists, write parse40.out and fill the report and recipe # placeholders from the run outputs. Stops without filling if strict (b) and buffered (c) disagree anywhere. import hashlib, math, re, subprocess, sys from parse40 import parse def sha(path): return hashlib.sha256(open(path, "rb").read()).hexdigest() out = subprocess.run([sys.executable, "parse40.py", "run-1e9.out", "run-2e9.out", "--embedded", "docs/research_localized-04-maxsum.js"], capture_output=True, text=True, check=True).stdout open("parse40.out", "w", encoding="utf-8").write(out) assert "0 differences" in out, "1e9 run differs from the embedded block" Y, blocks = parse(open("run-2e9.out", encoding="utf-8").read()) assert Y == 2e9 and len(blocks) == 5, (Y, len(blocks)) for b in blocks: if not (b["ab"] == "1.0000" and b["ac"] == "1.0000" and all(v[0] == v[1] == v[2] for v in b["rows"].values())): sys.exit(f"STRICT/BUFFERED DISAGREEMENT at x={b['x']}: report this first, rung refuted for sec 8") err = open("run-2e9.err", encoding="utf-8").read() wall = float(re.search(r"([0-9.]+) real", err).group(1)) mem = int(re.search(r"(\d+)\s+maximum resident set size", err).group(1)) / 1e6 rows, msrows, verdict = [], [], [] for b in blocks: D, M, x = b["D"], b["M"], b["x"] R1 = M * D / Y; lnD = math.log(D); q = R1 / lnD inx, inr = 89 <= x <= 16001, 0.736 <= q <= 1.170 where = ("inside" if inr else ("below" if q < 0.736 else "above")) + ("" if inx else "; x below the recorded x-range") rows.append(f"| {x} | {b['slots_ytop']} | {D} | {M} | {R1:.4f} | {lnD:.4f} | {q:.4f} | {where} |") msrows.append(f"| {x} | " + " | ".join(str(b["rows"][m][0]) for m in range(1, 13)) + " |") verdict.append((x, q, inx, inr)) table = ("| x | twin slots in [0, YTOP) | D(Y) | M = maxsum_1 | R(1) | lnD | R(1)/lnD | in [0.736, 1.170]? |\n" "|---|---|---|---|---|---|---|---|\n" + "\n".join(rows)) mstable = "| x | m = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |\n|---|" + "---|" * 12 + "\n" + "\n".join(msrows) inrange = [v for v in verdict if v[2]] lines = [f"- **At Y = 2e9, the {len(inrange)} checkpoints with x in the recorded x-range** give R(1)/lnD = " + ", ".join(f"{q:.4f} (x = {x})" for x, q, _, _ in inrange) + ". " + ("All of them lie inside [0.736, 1.170]." if all(v[3] for v in inrange) else "Outside [0.736, 1.170]: " + ", ".join(f"x = {x} ({q:.4f})" for x, q, _, r in inrange if not r) + ".")] for x, q, inx, inr in verdict: if not inx: lines.append(f"- **x = {x} lies below the recorded x-range,** so the range does not apply to it. Its R(1)/lnD = {q:.4f}, " + ("which happens to fall inside the interval." if inr else "outside the interval,") + (" the same position as x = 61 at Y = 1e9 (0.6332)." if not inr else "")) lines.append("- **Y = 2e9 lies above the Y values the range was recorded at** (1e7, 1e8, 1e9). So this is the first measurement at this Y, not a re-check of a recorded one.") R = { "{{CP_2E9}}": ", ".join(str(b["x"]) for b in blocks), "{{TABLE_2E9}}": table, "{{MAXSUM_2E9}}": mstable, "{{RANGE_VERDICT}}": "\n".join(lines), "{{WALL_2E9}}": f"{wall:.1f} s", "{{MEM_2E9}}": f"{mem:.0f} MB", "{{SHA_2E9_NORM}}": sha("run-2e9.normalized.out"), "{{SHA_PARSE}}": sha("parse40.py"), "{{SHA_PARSE_OUT}}": sha("parse40.out"), } for fn in ("report.md", "recipe.md"): t = open(fn, encoding="utf-8").read() for k, v in R.items(): t = t.replace(k, v) assert "{{" not in t, (fn, t[t.index("{{"): t.index("{{") + 30]) open(fn, "w", encoding="utf-8").write(t) print("filled report.md and recipe.md") print(table); print(mstable); print("\n".join(lines)) print("wall", wall, "mem MB", round(mem), "sha norm", R["{{SHA_2E9_NORM}}"], "parse40.out", R["{{SHA_PARSE_OUT}}"])