#!/usr/bin/env python3 """Per-window (leg-range) decomposition at the top scales (job #2040). The signed telescoped aggregate Tx = sum_i increments_i is a sum over the chain's U-windows, and the window (Ua, Ub] is supported on divisor legs d in (Ua, Ub] -- so the chain is a leg-size ruler. This script records, at the pre-registered top scales, which windows carry the signed aggregate and which carry the absolute mass, i.e. whether the signed smallness of route 89 is a short-leg object (mass in the small-d windows), a cancellation across windows, or neither. Env: VW_LIST="24:32,25:32", VW_OUT=v-windows-top.json Set VW_CHAIN to a comma list (e.g. "1,2,3,4,6,8,12,16,24,32") to use a finer leg ruler than the dyadic chain at the same ceiling, which splits the (2,4] window into legs 3 and 4. """ import json import math import os import sys HERE = os.path.dirname(os.path.abspath(__file__)) RUN = os.path.join(HERE, "..") sys.path.insert(0, os.path.join(RUN, "job2050")) from window_increments import family # noqa: E402 ALLOWANCE = 0.08 LIST = os.environ.get("VW_LIST", "24:32") OUT = os.environ.get("VW_OUT", "v-windows-top.json") FINE = os.environ.get("VW_CHAIN") def chain_for(V): if FINE: c = [int(v) for v in FINE.split(",")] assert c[-1] == V and c == sorted(set(c)), c return c c, u = [], 1 while u <= V: c.append(u) u *= 2 if c[-1] != V: c.append(V) return c def main(): out = {"allowance": ALLOWANCE, "rows": []} for spec in LIST.split(","): j, V = (int(v) for v in spec.split(":")) x = 2 ** j ch = chain_for(V) r = family(x, ch, V) inc = r["increments_over_x"] absm = r["window_abs_mass_over_x"] Tx = sum(inc) Vx = sum(abs(v) for v in inc) windows = [] for i in range(len(ch) - 1): windows.append({ "Ua": ch[i], "Ub": ch[i + 1], "inc_over_x": inc[i], "inc_over_allowance": inc[i] / ALLOWANCE, "abs_mass_over_x": absm[i], "inc_share_of_abs_mass": (abs(inc[i]) / absm[i] if absm[i] else None), }) row = {"j": j, "V": V, "chain": ch, "surviving_pairs": r["surviving_pairs"], "Tx_over_x": Tx, "Vx_over_x": Vx, "Tx_over_allowance": Tx / ALLOWANCE, "Vx_over_allowance": Vx / ALLOWANCE, "G": r["G_sum_abs_inc_over_max_member"], "sign_changes": r["sign_changes"], "window_abs_mass_share": r["window_abs_mass_share"], "max_window_inc_over_allowance": r["max_window_inc_over_allowance"], "invariant_matches_free_side": r["invariant_matches_free_side"], "mu_identity_violations": r["mu_identity_violations"], "windows": windows} out["rows"].append(row) print(json.dumps({k: row[k] for k in ("j", "V", "Tx_over_x", "Tx_over_allowance", "Vx_over_allowance", "G", "sign_changes", "surviving_pairs")}), flush=True) for w in windows: print(json.dumps(w), flush=True) with open(os.path.join(HERE, OUT), "w") as fh: json.dump(out, fh, indent=1) if __name__ == "__main__": main()