# make_patch15.py -- job #15: proposed patch (exact integer y and an spf[1] guard in the validator's SEC 1; # one clarifying clause in the note), then run the patched validator and compare with the served stdout. import hashlib, os, shutil, subprocess V, NOTE = "research/fold-arithmetic-bridge-validation.js", "research/fold-arithmetic-bridge.md" shutil.rmtree("a", ignore_errors=True); shutil.rmtree("b", ignore_errors=True) for f in (V, NOTE): for side in ("a", "b"): os.makedirs(os.path.dirname(os.path.join(side, f)), exist_ok=True); shutil.copyfile(f, os.path.join(side, f)) def rep(path, old, new): p = os.path.join("b", path); s = open(p, encoding="utf-8").read() assert s.count(old) == 1, (path, old[:70], s.count(old)); open(p, "w", encoding="utf-8").write(s.replace(old, new)) rep(V, "const US1 = [4.5, 6];", "const US1 = [[9, 2], [6, 1]]; // u = p/q, so that y = floor(X^(1/u)) can be computed exactly") rep(V, "for (const X of XS) for (const u of US1) {\n const y = Math.floor(Math.pow(X, 1 / u));", "for (const X of XS) for (const [up, uq] of US1) {\n const u = up / uq;\n" " // exact floor of X^(1/u), the largest y with y^p <= X^q: Math.pow alone gives 15 at X = 2^18, u = 4.5, where X^(1/u) = 16\n" " let y = Math.floor(Math.pow(X, 1 / u));\n" " while (BigInt(y + 1) ** BigInt(up) <= BigInt(X) ** BigInt(uq)) y++;\n" " while (BigInt(y) ** BigInt(up) > BigInt(X) ** BigInt(uq)) y--;") rep(V, " if (spf[n] <= y || spf[n + 2] <= y) continue;", " if ((n > 1 && spf[n] <= y) || spf[n + 2] <= y) continue; // spf[1] = 0, but 1 has no prime factor") rep(NOTE, "The denominator-free identity, valid also at S=0, is", "The denominator-free identity, valid also at S=0 (where both sides vanish for every T, so it says nothing about T there), is") with open("job15.patch", "w", encoding="utf-8") as out: for f in (V, NOTE): out.write(subprocess.run(["diff", "-u", "--label", "a/" + f, "--label", "b/" + f, os.path.join("a", f), os.path.join("b", f)], capture_output=True, text=True).stdout) print("job15.patch sha256", hashlib.sha256(open("job15.patch", "rb").read()).hexdigest()) p = subprocess.run(["node", "b/" + V], capture_output=True, text=True) open("patched-stdout.txt", "w").write(p.stdout) served = open("validator-stdout.txt").read().splitlines(); new = p.stdout.splitlines() timing = lambda l: l.startswith("SEC1 done in") print(f"patched validator: exit {p.returncode}; lines {len(new)} (served {len(served)})") for i, (a, b) in enumerate(zip(served, new)): if a != b and not timing(a): print(f" line {i+1}: {a}\n -> {b}") same = all(a == b or timing(a) for a, b in zip(served, new)) and len(served) == len(new) print(f" all other lines identical (timing line excluded): {sum(1 for a, b in zip(served, new) if a != b and not timing(a))} lines differ")