"""Where is the similarity function S actually evaluated, and does it earn the gains? Valeri, 2026-09-21: "check again in which places and which similarity functions are used, because that is what gave the gain". Static reading of simroot/pure.py: S is EVALUATED only in the step length (1 - S(z))*(far - x), in the 'simpair' decision S(|phi-xi|) < S(z), and in two refuted modes (log space, progress gate). The readings behind the records - the slope-sign gate, the triple chosen by shape, the far end by dissimilarity, the 'defect' decision - compare quantities directly and never call S. The ablation, read off the existing Linux sweeps (no new run): for each reading and for each of the nine functions S used in the step, the gain of the reading is total(reading on) - total(reading off) with the same S, scale and safeguard. If the gain is the same whatever S is, S does not produce it; if it changes with S, S takes part. python -u audit_similarity_places.py """ from __future__ import annotations import json SIMS = ("ratio", "sqrt", "cbrt", "rational", "ratio_soft", "exp_abs", "rat_sq", "exp_sq", "cosine") NAME = {"ratio": "tent 1-|z|", "sqrt": "1-sqrt|z|", "cbrt": "1-|z|^1/3", "rational": "1/(1+|z|)", "ratio_soft": "(1+|z|)^-2", "exp_abs": "e^-|z|", "rat_sq": "1/(1+z^2)", "exp_sq": "e^-z^2", "cosine": "1/sqrt(1+z^2)"} def load(path): with open(path, encoding="utf8") as fh: return json.load(fh) def key(r): s = r["spec"] pad = list(s) + [None] * (9 - len(s)) return (pad[1], pad[2], pad[3], pad[5] or "none", pad[6] or "recent", pad[7] or "distance") def index(*paths): out = {} for p in paths: for r in load(p): if r["spec"][0] == "pure": out.setdefault(key(r), r) return out def both(r): return r["APS"]["total"] + r["CHA"]["total"] def main(): cells = index("sweep_full.json", "sweep_slope.json", "sweep_points.json", "sweep_direction.json", "sweep_decision.json") # reading, its 'on' cell, its 'off' cell (same S, scale, guard), guard as in the record readings = ( ("slope-sign gate", ("slope", "recent", "distance"), ("none", "recent", "distance"), "project"), ("triple by shape", ("slope", "shape", "distance"), ("slope", "recent", "distance"), "safe"), ("far end by dissimilarity", ("slope", "recent", "dissimilar"), ("slope", "recent", "distance"), "project"), ("decision 'defect'", ("defect", "recent", "distance"), ("none", "recent", "distance"), "project"), ("decision 'simpair' (uses S)", ("simpair", "recent", "distance"), ("none", "recent", "distance"), "project"), ) print("Gain of each reading (APS | CHA), by the similarity S used in the STEP." " Negative = cheaper.\n") header = f"{'S in the step':<16}" + "".join(f"{r[0]:>30}" for r in readings) print(header) spread = {} for sim in SIMS: row = f"{NAME[sim]:<16}" for name, on, off, gu in readings: a = cells.get((sim, "derived3", gu) + on) b = cells.get((sim, "derived3", gu) + off) if a is None or b is None: row += f"{'—':>30}" continue da = a["APS"]["total"] - b["APS"]["total"] dc = a["CHA"]["total"] - b["CHA"]["total"] spread.setdefault(name, []).append((sim, da, dc)) row += f"{da:>+14d} |{dc:>+7d} " print(row) print("\nDoes the gain depend on S? Range of the gain over the nine functions:") for name, rows in spread.items(): das = [r[1] for r in rows] dcs = [r[2] for r in rows] print(f" {name:<30} APS {min(das):+6d} .. {max(das):+6d} " f"CHA {min(dcs):+6d} .. {max(dcs):+6d} (over {len(rows)} functions)") return spread if __name__ == "__main__": main()