# grid.py -- job #15 driver: builds the (X, u, interval, y-rounding) task grid, runs ./parity, and # summarises where the parity identity holds under each convention. Deterministic output (parity.log). import json, subprocess, hashlib, collections from fractions import Fraction as F def yfloor(X, u): # floor of X^(1/u) exactly, u = p/q rational: largest y with y^p <= X^q p, q = u.numerator, u.denominator; T = X ** q lo, hi = 0, 1 while hi ** p <= T: hi *= 2 while hi - lo > 1: m = (lo + hi) // 2 if m ** p <= T: lo = m else: hi = m return lo def yceil(X, u): f = yfloor(X, u); return f if f ** u.numerator == X ** u.denominator else f + 1 def isprime(m): return m >= 2 and all(m % d for d in range(2, int(m ** 0.5) + 1)) U = [F(1, 2), F(9, 10), F(19, 20), F(1), F(3, 2), F(2), F(5, 2), F(3), F(4), F(9, 2), F(5), F(6), F(8), F(10), F(12), F(16), F(20), F(24)] SMALL = list(range(1, 129)) # every integer X up to 128: n = 1, tiny S, closed ends POW = [2 ** k for k in range(0, 23)] # the note's dyadic X, up to 2^22 XS = sorted(set(SMALL + POW)) IV = {"(]": lambda X: (X + 1, 2 * X), "[]": lambda X: (X, 2 * X), "()": lambda X: (X + 1, 2 * X - 1), "[)": lambda X: (X, 2 * X - 1)} pairs = [] for X in XS: us = list(U) + ([F(X.bit_length() - 1)] if X in POW and X >= 2 and F(X.bit_length() - 1) not in U else []) for u in us: pairs.append((X, u)) # the validator's own rounding: Math.floor(Math.pow(X, 1/u)) with u as a double js = subprocess.run(["node", "-e", "const a=JSON.parse(require('fs').readFileSync(0,'utf8'));console.log(JSON.stringify(a.map(([X,u])=>Math.floor(Math.pow(X,1/u)))))"], input=json.dumps([[X, float(u)] for X, u in pairs] + [[2 ** k, u] for k in (16, 18, 20, 22, 24) for u in (4.5, 6)]), capture_output=True, text=True, check=True) jsy = json.loads(js.stdout) jsval = jsy[len(pairs):]; jsy = jsy[:len(pairs)] tasks, meta = [], {} for (X, u), yj in zip(pairs, jsy): ys = {"floor": yfloor(X, u), "ceil": yceil(X, u), "jsfloat": yj} ivs = IV if X <= 2 ** 16 else {"(]": IV["(]"]} for iv, f in ivs.items(): lo, hi = f(X) if hi < lo or lo < 1: continue for yr, y in ys.items(): tid = f"{X}|{u}|{iv}|{yr}"; tasks.append(f"{tid} {lo} {hi} {y}"); meta[tid] = (X, u, iv, yr, y, lo, hi) NMAX = 2 * max(XS) + 4 res = subprocess.run(["./parity", str(NMAX)], input="\n".join(tasks) + "\n", capture_output=True, text=True, check=True).stdout open("results.txt", "w").write(res) R = {} for line in res.splitlines(): f = line.split(); assert f[1] != "ERR", line R[f[0]] = dict(zip("S A B C Po Po2 N3 Tin Tall Tboth n1 okIn okAll okBoth four".split(), map(int, f[1:]))) out = [] P = out.append P(f"tasks {len(R)}; X values {len(XS)} (1..128 and 2^0..2^22); u values {len(U)} plus u = log2 X; results.txt sha256 {hashlib.sha256(res.encode()).hexdigest()}") P("== 1. the identity with the note's T (n in S_X, n and n+2 prime), every convention ==") for iv in IV: for yr in ("floor", "ceil", "jsfloat"): ks = [k for k in R if meta[k][2] == iv and meta[k][3] == yr] if not ks: continue P(f" {iv:2} y={yr:7}: tasks {len(ks):5}, identity fails {sum(1 for k in ks if not R[k]['okIn'])}, both-odd identity fails {sum(1 for k in ks if not R[k]['four'])}, S=0 tasks {sum(1 for k in ks if R[k]['S']==0)}") def first(ks, n=4): return "; ".join(f"X={meta[k][0]} u={meta[k][1]} {meta[k][2]} y={meta[k][4]} S={R[k]['S']} Tin={R[k]['Tin']} Tall={R[k]['Tall']} Tboth={R[k]['Tboth']}" for k in ks[:n]) key = lambda k: (meta[k][0], meta[k][1], meta[k][2], meta[k][3]) P("== 2. other readings of T ==") bad_all = sorted([k for k in R if not R[k]["okAll"]], key=key) P(f" T = all twin openers in the interval (S ignored): fails at {len(bad_all)} tasks; all with y > X: {all(meta[k][4] > meta[k][0] for k in bad_all)}; " f"with u >= 1: {sum(1 for k in bad_all if meta[k][1] >= 1)}; e.g. {first(bad_all)}") ge1 = [k for k in bad_all if meta[k][1] >= 1] P(f" the u >= 1 failures: all have n = lo <= y (lower end closed, or y rounded up to X): {all(meta[k][5] <= meta[k][4] for k in ge1)}; " f"by (interval, rounding): {sorted(collections.Counter((meta[k][2], meta[k][3]) for k in ge1).items())}") bad_both = sorted([k for k in R if not R[k]["okBoth"]], key=key) P(f" T = pairs with both members inside the interval: fails at {len(bad_both)} tasks; e.g. {first(bad_both)}") mix = [] for k in R: X, u, iv, yr, *_ = meta[k] if iv != "[]": continue k2 = f"{X}|{u}|(]|{yr}" if k2 not in R: continue s, t = R[k], R[k2] rhs = 4 * s["Po"] * s["Po2"] + (s["C"] * s["S"] - s["A"] * s["B"]) - 4 * s["N3"] * s["S"] if 4 * t["Tin"] * s["S"] != rhs: mix.append(k) mix.sort(key=key) P(f" S etc. on [X,2X] but T on (X,2X]: fails at {len(mix)} tasks, all at lesser twin primes X: {all(isprime(meta[k][0]) and isprime(meta[k][0]+2) and meta[k][0] > meta[k][4] for k in mix)}; e.g. {first(mix)}") P("== 3. S = 0: the identity holds for every value of T ==") z = sorted([k for k in R if R[k]["S"] == 0], key=key) P(f" S=0 tasks {len(z)}; of these with a twin opener in the interval (Tall > 0): {sum(1 for k in z if R[k]['Tall'] > 0)}; e.g. {first([k for k in z if R[k]['Tall'] > 0])}") P(f" S=0 with a twin opener, on the note's (X,2X] with X >= y: {sum(1 for k in z if R[k]['Tall'] > 0 and meta[k][2] == '(]' and meta[k][0] >= meta[k][4])}") P("== 4. n = 1 inside S_X (closed lower end at X = 1, y < 3) ==") n1 = sorted([k for k in R if R[k]["n1"]], key=key) P(f" tasks with n = 1 in S: {len(n1)}; identity holds at all: {all(R[k]['okIn'] for k in n1)}; the served validator's spf[1]=0 test would drop n = 1; e.g. {first(n1, 2)}") P("== 5. the four-sign identity 4T = S-A-B+C (N_odd3 = 0) and its threshold y >= (2X+2)^(1/3) ==") fl = [k for k in R if meta[k][2] == "(]" and meta[k][3] == "floor"] viol = [k for k in fl if meta[k][4] ** 3 >= 2 * meta[k][0] + 2 and R[k]["N3"] > 0] below = sorted([k for k in fl if meta[k][4] ** 3 < 2 * meta[k][0] + 2 and R[k]["N3"] > 0], key=key) P(f" (X,2X], exact floor y: tasks with y^3 >= 2X+2 and N_odd3 > 0: {len(viol)}; tasks with y^3 < 2X+2 and N_odd3 > 0: {len(below)}") k64 = "64|3|(]|floor"; P(f" X=64, u=3: y={meta[k64][4]}, N_odd3={R[k64]['N3']}, Tin={R[k64]['Tin']}, S-A-B+C={R[k64]['S']-R[k64]['A']-R[k64]['B']+R[k64]['C']} vs 4T={4*R[k64]['Tin']}") P("== 6. rounding of y: the validator's Math.floor(Math.pow(X, 1/u)) against the exact floor ==") diff = sorted([k for k in R if meta[k][3] == "jsfloat" and meta[k][4] != meta[k.replace("jsfloat", "floor")][4]], key=key) seen = sorted({(meta[k][0], meta[k][1]) for k in diff}) chg = [(X, u) for X, u in seen if R[f"{X}|{u}|(]|jsfloat"]["S"] != R[f"{X}|{u}|(]|floor"]["S"]] if seen else [] P(f" (X,u) pairs where the float floor differs from the exact floor: {len(seen)}; where that changes S on (X,2X]: {len(chg)}") P(f" e.g. {[(X, str(u), meta[f'{X}|{u}|(]|jsfloat'][4], meta[f'{X}|{u}|(]|floor'][4]) for X, u in seen[:10]]}") P(f" S changes at: {[(X, str(u), R[f'{X}|{u}|(]|jsfloat']['S'], R[f'{X}|{u}|(]|floor']['S']) for X, u in chg[:10]]}") P(f" the validator's own ten (X, u): float y {jsval}; exact {[yfloor(2 ** k, F(u).limit_denominator(2)) for k in (16, 18, 20, 22, 24) for u in (4.5, 6)]}") lg = [(X, u) for X, u in pairs if X in POW and X >= 2 and u == F(X.bit_length() - 1)] P(f" dyadic X with X^(1/u) = 2 exactly (u = log2 X, X = 2..2^22, {len(lg)} pairs): float floor != 2 at {[(X, str(u)) for X, u in lg if meta[f'{X}|{u}|(]|jsfloat'][4] != 2]}") P("== 7. 'T = #{twin openers in I} for X > y' ==") sec = sorted([k for k in R if meta[k][2] == "(]" and meta[k][3] == "floor" and R[k]["Tin"] != R[k]["Tall"]], key=key) P(f" (X,2X], exact y: Tin != Tall at {len(sec)} tasks; smallest y - X among them: {min((meta[k][4] - meta[k][0]) for k in sec) if sec else None}; at X >= y: {sum(1 for k in sec if meta[k][0] >= meta[k][4])}") open("parity.log", "w").write("\n".join(out) + "\n") print("\n".join(out))