#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Job #1892 — route 31 rev 12's frozen next_step: a SOURCE-ONLY definition manifest. Frozen question: "Can the route freeze a literal, source-backed drift-statistic contract distinguishing intercept, fitted slope, and remaining energy before any further field measurement?" Frozen method: recover return 666's job1461-strat.py, compare its literal numerator/denominator with 664's detrend() and 672's shares(), publish a definition manifest, use the exact n=c=(1,2,3) example and the centered-projection identity as discriminators. NO coefficient-field run, no random draw, no threshold sweep, no tuning toward old numbers. This script therefore builds no field: it reads sources, evaluates one recovered PURE function on a synthetic 3-point example, and does exact rational arithmetic on synthetic vectors. Nothing here writes an absolute machine path (the pinned tool refuses such an artifact). Writes job1892-manifest.json beside itself. """ import hashlib import importlib.util import json import os import re import sys from fractions import Fraction as F HERE = os.path.dirname(os.path.abspath(__file__)) # Department root: passed by the caller (a realpath built by the shell), else 5 levels up. DEP = (os.path.abspath(sys.argv[1]) if len(sys.argv) > 1 else os.path.normpath(os.path.join(HERE, "..", "..", "..", "..", ".."))) RECOVERED = os.path.join(DEP, ".solveathome", "runs", "run_20260916_134556_IX8n9g", "work", "job1461-strat.py") RECOVERED_JSON = os.path.join(DEP, ".solveathome", "runs", "run_20260916_134556_IX8n9g", "work", "job1461-strat.json") RECOVERED_SHA = "43e44ef7a665543d1a6f0a4f1a51b32490ac4681b48def0ab91757b60d5c621c" PUBLISHED_664 = {2 ** 14: 0.6776, 2 ** 16: 0.8019, 2 ** 18: 0.8331} ROUTE_NUMBERS_666 = (0.3229, 0.6715, 0.5449) # the three the route quotes as unexplained checks = [] def check(name, ok, detail): checks.append({"check": name, "pass": bool(ok), "detail": detail}) print("%-6s %s\n %s" % ("PASS" if ok else "FAIL", name, detail)) # ---------------------------------------------------------------- C1 source recovery + pin src = open(RECOVERED, "r", encoding="utf-8").read() sha = hashlib.sha256(src.encode("utf-8")).hexdigest() check("C1 recovered #666 source held locally and sha-pinned", sha == RECOVERED_SHA and os.path.getsize(RECOVERED) > 0, "locator .solveathome/runs/run_20260916_134556_IX8n9g/work/job1461-strat.py (that run is " "return #666, job 1461); sha256=%s; %d bytes, %d lines; #666's own output artifact " "job1461-strat.json sits beside it" % (sha, len(src), src.count("\n") + 1)) # ---------------------------------------------------------------- C2 literal extraction m = re.search(r"def ss_lin\(.*?\n(?:.*?\n)*? return .*?\n", src) ss_lin_lit = m.group(0).rstrip("\n") if m else "" stated = re.search(r"drift share\(C\) = .*?\n(?:\s+.*\n)*?\s+R_L\(group map.*?\n", src) stated_lit = stated.group(0).strip() if stated else "" body_ok = ("np.linalg.lstsq" in ss_lin_lit and "fit - fit.mean()" in ss_lin_lit and "vals - vals.mean()" in ss_lin_lit and "if n < 3" in ss_lin_lit) check("C2 the recovered source states and implements the same convention", body_ok and "SS_lin(f|_g) / sum_{g in C} SS(f|_g)" in stated_lit and "the linear fit is of f on n, least squares" in stated_lit, "stated: %r | implemented numerator: lstsq([nsv, 1], vals) -> sum((fit - fit.mean())**2); " "denominator: sum((vals - vals.mean())**2); groups with <3 members skipped" % (stated_lit.replace("\n", " ")[:300],)) # ---------------------------------------------------------------- exact identity machinery def exact(ns, fs): """Exact unweighted two-parameter least-squares decomposition, Fractions only.""" ns = [F(a) for a in ns] fs = [F(a) for a in fs] n = len(ns) if n < 3: return None mn, mf = sum(ns) / n, sum(fs) / n ss_tot = sum((f - mf) ** 2 for f in fs) # response energy (centered) ss_int = sum(mf ** 2 for _ in fs) # = n * mean(f)^2 = (sum f)^2 / n snf = sum((a - mn) * (f - mf) for a, f in zip(ns, fs)) snn = sum((a - mn) ** 2 for a in ns) ss_slope = (snf ** 2) / snn ss_resid = ss_tot - ss_int - ss_slope return dict(n=n, ss_tot=ss_tot, ss_int=ss_int, ss_slope=ss_slope, ss_resid=ss_resid, share_int=(ss_int / ss_tot if ss_tot else None), share_slope=(ss_slope / ss_tot if ss_tot else None), share_resid=(ss_resid / ss_tot if ss_tot else None)) # C3 the centered-projection identity, exactly, on synthetic vectors (one is the frozen example) vectors = [(1, 2, 3), [1, 2, 3], [1, 2, 4, 8, 16], [0, 1, 2], [-5, 0, 7, 9]] resps = [[-1, 0, 1], [1, 1, 1], [-3, 1, 4, -1, 2], [-1, 0, 1], [2, -2, 3, -3]] ids, rows = [], [] for ns, fs in zip(vectors, resps): r = exact(ns, fs) ids.append(r["ss_tot"] == r["ss_int"] + r["ss_slope"] + r["ss_resid"]) rows.append({"positions": list(ns), "response": list(fs), "SS_total": str(r["ss_tot"]), "SS_intercept": str(r["ss_int"]), "SS_slope": str(r["ss_slope"]), "SS_residual": str(r["ss_resid"]), "share_intercept": str(r["share_int"]), "share_slope": str(r["share_slope"]), "share_residual": str(r["share_resid"])}) check("C3 centered-projection identity SS_total = SS_intercept + SS_slope + SS_residual, exact", all(ids), "%d synthetic vectors, Fractions only, exact equality in every one; SS_intercept = " "(sum f)^2/n and SS_slope = (sum (n-nbar) f)^2 / sum (n-nbar)^2 are the two " "orthogonal parts, so a share built on one is not the share built on the other" % len(ids)) # C4 the frozen discriminator example n = c = (1,2,3), d = (-1,0,1) ex = exact((1, 2, 3), (-1, 0, 1)) check("C4 discriminator n=c=(1,2,3), response (-1,0,1): intercept share 0, slope share 1, exactly", ex["ss_int"] == 0 and ex["ss_slope"] == 2 and ex["ss_tot"] == 2 and ex["ss_resid"] == 0 and ex["share_slope"] == 1 and ex["share_int"] == 0, "SS_intercept=%s (=(sum f)^2/n = 0^2/3), SS_slope=%s (=(sum (n-2)f)^2/sum (n-2)^2 = 2^2/2), " "SS_total=%s, SS_residual=%s -> share_intercept=%s, share_slope=%s" % (ex["ss_int"], ex["ss_slope"], ex["ss_tot"], ex["ss_resid"], ex["share_int"], ex["share_slope"])) # C5 execute the RECOVERED pure function on the same example (no field built) spec = importlib.util.spec_from_file_location("recovered_1461", RECOVERED) mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(mod) import numpy as np expl, tot = mod.ss_lin(np.array([-1.0, 0.0, 1.0]), np.array([1.0, 2.0, 3.0])) short_expl, short_tot = mod.ss_lin(np.array([-1.0, 0.0]), np.array([1.0, 2.0])) check("C5 the recovered ss_lin returns the SLOPE energy, not the intercept energy", abs(expl - 2.0) < 1e-12 and abs(tot - 2.0) < 1e-12 and short_expl is None, "recovered ss_lin((-1,0,1), (1,2,3)) = (%r, %r): explained = 2.0 = SS_slope (NOT 0), " "total = 2.0; a 2-point group returns (None, tot) so short classes leave BOTH sums" % (expl, tot)) # C6 the intercept-style numerator (the shape #672's shares() uses) is identically 0 sf = F(-1) + F(0) + F(1) int_style = (sf ** 2) / 3 mean_style = 3 * (sf / 3) ** 2 check("C6 the intercept numerator (sum f)^2/n and n*mean(f)^2 vanish on this group", int_style == 0 and mean_style == 0, "(sum f)^2/n = %s and n*mean(f)^2 = %s, while SS_slope = 2 > 0: the two conventions are " "different quantities on the same group, which is the whole gap" % (int_style, mean_style)) # ---------------------------------------------------------------- C7 attribution of the three numbers art = json.load(open(RECOVERED_JSON, encoding="utf-8")) s14 = art["scales"][0] got = (round(s14["drift"]["class"]["drift_share"], 4), round(s14["drift"]["class_x_stratum"]["drift_share"], 4), round(s14["between_strata_share"], 4)) gate = s14["gate_vs_published"] allgates = all(s["gate_vs_published"]["drift_share_ok"] is False for s in art["scales"]) check("C7 the three route numbers ARE #666's own script output at x=2^14 (no re-derivation)", got == ROUTE_NUMBERS_666 and s14["x"] == 16384 and s14["classes"] == 124 and s14["two_signed_classes"] == 4 and s14["support"] == 2208 and allgates, "recovered artifact: class drift_share %.10f -> %.4f, class_x_stratum %.10f -> %.4f, " "between_strata_share %.10f -> %.4f; support 2208, 124 classes, 4 two-signed, runtime %.2fs; " "and #666's OWN gate against #664's published 0.6776/0.8019/0.8331 reads " "drift_share_ok=%s at all three scales (R_largest_ok=%s)" % (s14["drift"]["class"]["drift_share"], got[0], s14["drift"]["class_x_stratum"]["drift_share"], got[1], s14["between_strata_share"], got[2], art["runtime_s"], gate["drift_share_ok"], gate["R_largest_ok"])) # C8 the manifest: exactly which literals each of the three quantities is manifest = { "support_and_field": "#666: {n in (x/2, x] : c(n) != 0} with c evaluated in float64 and compared to 0 exactly " "(no threshold) -> 2208 at 2^14, 9572 at 2^16, 44158 at 2^18. #654's instrument applies " "|c| > 1e-9 -> 2191 at 2^14; that single threshold, not the class key, is what separated " "#666's 4/12/53 two-signed counts from #654's 0.", "class_key": "(s_U(n), s_U(n-2)) where s_U is the FULL U-smooth part (largest divisor all of whose prime " "powers are <= U), U = floor(x^(6/25)) = 10/14/19; #666 never uses #654's asymmetric " "(k(n,U), k(n-2,Y)) key. Co-factor m = n/s_U(n) is used only for the refined grouping.", "support_cutoffs": "Y = Z = floor(x^(1/20)) = 1 at all three scales (right factor C_{1,1}(n-2) = " "Lambda(m) - log m <= 0); U = 10/14/19. The route's central uncertainty already fixes " "this: at these scales the right factor is degenerate, so the field is a field of the " "truncated left coefficient.", "response": "f(n) = sgn(c(n)) * (|c(n)| - mean{|c(n')| : class of n}) -- i.e. c - s_g*mean{|c|:g} " "exactly where the class is one-signed, which is 120/124 classes at 2^14 (#666 counts 4 " "two-signed) and all of them under #654's thresholded support.", "positions_and_intercept": "regressor = float(n), the actual integer positions, NOT the rank or the class index; " "the fit carries an explicit intercept column (np.vstack([nsv, ones]).T).", "weights": "none: every member of a group counts once (unweighted OLS).", "numerator": "SS_lin(f|g) = sum((fit - mean(fit))^2) over the least-squares line of f on n in group g " "= the FITTED SLOPE energy = (sum (n - nbar_g) f)^2 / sum (n - nbar_g)^2. It is not " "(sum f)^2/n.", "denominator": "SS(f|g) = sum((f - mean(f))^2) = sum f^2, since mean(f) = 0 identically in a one-signed " "class. The drift share is a ratio of SUMS over groups, not a mean of per-group shares.", "short_classes_and_zero_denominators": "groups with fewer than 3 members are dropped from BOTH the numerator and the denominator " "(116 of 124 groups at 2^14); a group with SS(f|g) = 0 is dropped; if the pooled " "denominator is 0 the share is reported as null rather than 0.", "refined_grouping": "(class x stratum of the co-factor m) with 5 strata: m=1 | m prime | m semiprime above U | " "m carrying a prime power above U | other composite.", "between_strata_share": "sum_g n_{g,s} (mean{|c| : class x stratum} - mean{|c| : class})^2 / sum_g SS(f|g) " "-- a BETWEEN-strata energy divided by a WITHIN-group response energy; it is a third " "quantity, and its denominator is the same one the class share uses.", "attributions": { "#666 job1461-strat.py": "slope energy / response energy (recovered, sha 43e44ef7...)", "#664 detrend(d,nsv,members)": "centers the actual nsv, fits intercept plus slope, reports " "fitted energy / response energy -- the SAME convention as " "#666; its published 0.6776/0.8019/0.8331 is therefore a " "different FIELD or grouping, not a different numerator", "#672 shares(vals,groups)": "= (sum f)^2/n or n*mean(f)^2: the INTERCEPT energy. Zero " "identically on a one-signed class, so its ~8e-31 was a " "reconstruction of the intercept share, not of #666's share", }, "remaining_unattributed": "#664's exact field (support threshold and class key) is still not read line-by-line; what " "is now resolved is that its convention is slope-type like #666's, so the 0.3229 vs 0.6776 " "gap cannot be a mean-vs-slope artefact. #666's own artifact records that gate as FAILED.", } check("C8 manifest covers every field the frozen step names", all(k in manifest for k in ("support_and_field", "class_key", "support_cutoffs", "response", "positions_and_intercept", "weights", "numerator", "denominator", "short_classes_and_zero_denominators", "refined_grouping", "between_strata_share", "attributions", "remaining_unattributed")), "13 sections, each tied to a literal extracted from the recovered source or to a value read " "from its own JSON artifact; %d characters" % len(json.dumps(manifest))) # C9 the frozen clause's prohibition: no field was built check("C9 no coefficient-field run, draw, sweep or tuning (frozen clause respected)", not os.path.exists(os.path.join(HERE, "field-ran")) and "def build" not in src.split( "def load_producer")[0], "this script imports only ss_lin (a pure function of two arrays); load_producer/analyse were " "never called; no numpy sieve, no Möbius array, no R_L grid; the only executed quantities are " "the 3-point example and exact Fractions") out = {"job": 1892, "route_id": 31, "tool_version": "sah/13", "recovered_source": {"locator": ".solveathome/runs/run_20260916_134556_IX8n9g/work/" "job1461-strat.py", "sha256": sha, "sha_matches_666": sha == RECOVERED_SHA, "artifact": ".solveathome/runs/run_20260916_134556_IX8n9g/work/" "job1461-strat.json"}, "literals": {"stated_drift_share": stated_lit, "implemented_numerator": ss_lin_lit}, "identity_rows": rows, "manifest": manifest, "attribution": {"x": s14["x"], "class_drift_share": s14["drift"]["class"]["drift_share"], "refined_drift_share": s14["drift"]["class_x_stratum"]["drift_share"], "between_strata_share": s14["between_strata_share"], "published_664": PUBLISHED_664, "gate_vs_published": gate}, "checks": checks, "passed": sum(c["pass"] for c in checks), "total": len(checks)} with open(os.path.join(HERE, "job1892-manifest.json"), "w", encoding="utf-8", newline="\n") as fh: fh.write(json.dumps(out, indent=1, sort_keys=True) + "\n") print("\n%d/%d passed" % (out["passed"], out["total"])) sys.exit(0 if out["passed"] == out["total"] else 1)