"""Job #1894 (pursue route 31 rev 13). QUESTION (#1002's next step): which single line of #664's field -- support threshold, class key, or grouping -- moves #666's recorded drift share 0.3228814139 toward #664's published 0.6776, once the contract is executed on the pinned producer? #666's own script (sha 43e44ef7...) is NOT in the store (ask #11), so its contract is executed as #1002's manifest transcribes it, and #664's as its served detrend.py / lstar.py implement it. FIELD: the pinned producer fibre-sign-lag.reused.py (sha a74825d8..., imported read-only): build(x), mu_array, coeff_from, c_field; ns = (x/2, x]; c(n) = C_L(n) C_R(n-2); U = V = floor(x^(6/25)), Y = Z = floor(x^(1/20)). CONTRACT AXES (each a literal of one of the two returns): support: 'exact' {c != 0} (#666) | 'tol' {|c| > 1e-9} (#664 via lstar.SUPPORT_TOL, #654) key: 'full' (s_U(n), s_U(n-2)), full smooth part (#666; lstar.build keymode='full') | 'trunc' #654's prime-power tuple response: f = c - s_g * mean{|c| : g} with s_g the class sign (both returns; lstar.renormalise); two-signed classes keep the sign of the first member (#654's class map) -- reported grouping: 'g666' slope energy sum_g SS_lin(f|g) / sum_g SS(f|g) over classes with >= 3 members only (both sums) 'g664' detrend(): every class with >= 2 members and sxx > 0 is fitted (size 2 exactly), num = sum fit^2, den = sum y^2 over ALL classes (unfitted classes contribute 0 to num, their y^2 to den) refined: class x stratum of the cofactor m = n/s_U(n): {m = 1, m prime, m semiprime with both primes > U, m carrying a prime power p^e (e >= 2) with p > U, other}; between-strata share = sum_c sum_s n_s (mean_s|c| - mean_c|c|)^2 / sum_c sum (|c| - mean_c|c|)^2 (#666's third number), evaluated on the g666 support of groups. TARGETS (pre-registered): T1 (exact, full, g666) -> 0.3228814139 with support 2208, 124 classes, 4 two-signed; T2 (tol, full, g664) -> 0.6776387465508169 with support 2191, 153 classes, 71 classes >= 3 (#664 detrend.json); T3 (exact, full, refined g666) -> 0.6715401186 and between-strata 0.5448788470. Then the 2x2x2 table and the single-change readings from T1. CONTROLS: producer sha; support 2208 raw and 2191 after tol (both published); one-signedness per key. RUN: python contract1894.py --x 16384 [--x 65536]""" import argparse, hashlib, importlib.util, json, math, sys, time import numpy as np ap = argparse.ArgumentParser(); ap.add_argument('--x', type=int, action='append'); ap.add_argument('--out', default='contract1894.json'); a = ap.parse_args() XS = a.x or [16384]; log = sys.stderr; t0 = time.time(); led = [] def check(tag, ok, detail): led.append(f"{'PASS' if ok else 'FAIL'} {tag} :: {detail}"); print(led[-1], file=log, flush=True) PROD = 'fibre-sign-lag.reused.py'; PSHA = 'a74825d84e5421eb330d6b54f93029a0aebdc2fd5120fce02ab5d6d857545b56' check('producer_sha', hashlib.sha256(open(PROD, 'rb').read()).hexdigest() == PSHA, PSHA[:16]) spec = importlib.util.spec_from_file_location('fssl', PROD); fssl = importlib.util.module_from_spec(spec); spec.loader.exec_module(fssl) def smooth_part(m, B, facts): s = 1 for p, e in facts[m]: if p <= B: s *= p ** e return s def trunc_key(m, B, facts): key = [] for p, e in facts[m]: pk = 1 for _ in range(e): pk *= p if pk <= B: key.append((p, pk)) else: break return tuple(key) def is_prime(m, primes): if m < 2: return False for p in primes: if p * p > m: return True if m % p == 0: return m == p return True def stratum(m, U, primes, facts_m): if m == 1: return 'one' if is_prime(m, primes): return 'prime' big = [(p, e) for p, e in facts_m if p > U] if len(big) == 2 and all(e == 1 for _, e in big) and math.prod(p for p, _ in big) == m: return 'semiprime' if any(e >= 2 for _, e in big): return 'primepower' return 'other' def share_g666(groups, f, ns): num = den = 0.0; used = 0 for idx in groups: if len(idx) < 3: continue y = f[idx]; xv = ns[idx].astype(float); xc = xv - xv.mean(); sxx = float((xc * xc).sum()) tot = float(((y - y.mean()) ** 2).sum()) if tot == 0 or sxx == 0: continue b = float((xc * y).sum() / sxx); fit = y.mean() + b * xc num += float(((fit - fit.mean()) ** 2).sum()); den += tot; used += 1 return (num / den if den else None), used def share_g664(groups, f, ns): num = den = 0.0; fitted = 0 for idx in groups: y = f[idx]; xv = ns[idx].astype(float); xc = xv - xv.mean(); sxx = float((xc * xc).sum()) if len(idx) >= 2 and sxx > 0: b = float((xc * y).sum() / sxx); fit = y.mean() + b * xc; num += float((fit * fit).sum()); fitted += 1 den += float((y * y).sum()) return (num / den if den else None), fitted out = {'instrument': 'contract1894.py', 'job': 1894, 'producer_sha': PSHA, 'scales': {}} for x in XS: t1 = time.time(); b = fssl.build(x); mu = fssl.mu_array(b['hi']).astype(float) c_raw = fssl.c_field(b, fssl.coeff_from(b, 'L', mu), fssl.coeff_from(b, 'R', mu)); ns = b['ns']; U, Y = b['U'], b['Y']; facts = b['facts']; primes = b['primes'] rec = {'x': x, 'U': U, 'Y': Y, 'J': int(len(ns)), 'support_exact': int(np.count_nonzero(c_raw)), 'support_tol': int(np.count_nonzero(np.abs(c_raw) > 1e-9)), 'variants': {}} check(f'x={x}_support_published', (x != 16384) or (rec['support_exact'] == 2208 and rec['support_tol'] == 2191), f"exact {rec['support_exact']} tol {rec['support_tol']} (published 2208 / 2191 at 2^14)") for supp in ('exact', 'tol'): c = np.where(np.abs(c_raw) <= 1e-9, 0.0, c_raw) if supp == 'tol' else c_raw.copy() sup = np.flatnonzero(c != 0) for key in ('full', 'trunc', 'truncUU', 'fullUU'): kf = {'full': (lambda n: (smooth_part(n, U, facts), smooth_part(n - 2, Y, facts))), 'trunc': (lambda n: (trunc_key(n, U, facts), trunc_key(n - 2, Y, facts))), 'truncUU': (lambda n: (trunc_key(n, U, facts), trunc_key(n - 2, U, facts))), # #654's prime-power key with the U cutoff on BOTH members (found by keyprobe1894.py) 'fullUU': (lambda n: (smooth_part(n, U, facts), smooth_part(n - 2, U, facts)))}[key] members = {}; sgn = {}; two = 0 for i in sup: k = kf(int(ns[i])); members.setdefault(k, []).append(int(i)) groups = [] for k, idx in members.items(): idx = np.array(idx); s = float(np.sign(c[idx[0]])); sgn[k] = s if any(np.sign(c[idx]) != s): two += 1 groups.append(idx) f = np.zeros_like(c) for k, idx in zip(members.keys(), groups): f[idx] = c[idx] - sgn[k] * np.abs(c[idx]).mean() s666, used666 = share_g666(groups, f, ns); s664, fit664 = share_g664(groups, f, ns) # refined grouping (class x stratum) and between-strata share, #666 style rgroups = []; bnum = bden = 0.0 for k, idx in zip(members.keys(), groups): if key in ('full', 'fullUU'): m_of = [int(ns[i]) // k[0] for i in idx] else: m_of = [int(ns[i]) // smooth_part(int(ns[i]), U, facts) for i in idx] strata = {} for i, m in zip(idx, m_of): strata.setdefault(stratum(m, U, primes, fssl.factor(m, primes)), []).append(int(i)) for sidx in strata.values(): rgroups.append(np.array(sidx)) if len(idx) >= 3: ac = np.abs(c[idx]); mc = ac.mean(); bden += float(((ac - mc) ** 2).sum()) for sidx in strata.values(): bnum += len(sidx) * (float(np.abs(c[sidx]).mean()) - mc) ** 2 r666, rused = share_g666(rgroups, f, ns); r664, _ = share_g664(rgroups, f, ns) rec['variants'][f'{supp}|{key}'] = {'classes': len(members), 'two_signed': two, 'g666': s666, 'g666_groups_used': used666, 'g664': s664, 'g664_fitted': fit664, 'refined_g666': r666, 'refined_groups_used': rused, 'refined_g664': r664, 'between_strata': (bnum / bden if bden else None)} print(f"x={x} {supp}|{key}: classes {len(members)} two-signed {two} g666 {s666} g664 {s664} refined {r666} between {rec['variants'][f'{supp}|{key}']['between_strata']}", file=log, flush=True) rec['secs'] = round(time.time() - t1, 1); out['scales'][str(x)] = rec if x == 16384: v = rec['variants'] check('T1_666_manifest_transcription', abs((v['exact|full']['g666'] or 0) - 0.3228814139) < 1e-6, f"exact|full g666 = {v['exact|full']['g666']} classes {v['exact|full']['classes']} two-signed {v['exact|full']['two_signed']} (target 0.3228814139, 124, 4)") check('T1b_666_reproduced_by_truncUU_key', abs((v['exact|truncUU']['g666'] or 0) - 0.3228814139) < 1e-9 and v['exact|truncUU']['classes'] == 124 and v['exact|truncUU']['two_signed'] == 4, f"exact|truncUU g666 = {v['exact|truncUU']['g666']} classes {v['exact|truncUU']['classes']} two-signed {v['exact|truncUU']['two_signed']}") check('T2_664_contract', abs((v['tol|full']['g664'] or 0) - 0.6776387465508169) < 1e-6, f"tol|full g664 = {v['tol|full']['g664']} classes {v['tol|full']['classes']} fitted {v['tol|full']['g664_fitted']} (target 0.6776387466, 153 classes)") check('T3_666_refined_truncUU', abs((v['exact|truncUU']['refined_g666'] or 0) - 0.6715401186) < 1e-6, f"truncUU refined {v['exact|truncUU']['refined_g666']} between {v['exact|truncUU']['between_strata']} (targets 0.6715401186, 0.5448788470); manifest-key refined {v['exact|full']['refined_g666']} between {v['exact|full']['between_strata']}") # single-change readings from T1 base = v['exact|full']['g666'] rec['single_changes_from_666'] = {'base_666 (exact|truncUU|g666)': v['exact|truncUU']['g666'], 'support->tol': v['tol|truncUU']['g666'], 'key->full(U,Y)': v['exact|full']['g666'], 'grouping->g664': v['exact|truncUU']['g664'], 'key->fullUU': v['exact|fullUU']['g666'], 'all(#664: tol|full|g664)': v['tol|full']['g664']} rec['single_changes_from_T1'] = rec['single_changes_from_666'] print('SINGLE_CHANGES', json.dumps(rec['single_changes_from_T1']), file=log) out['ledger'] = led; out['secs'] = round(time.time() - t0, 1) print('\n'.join(led)); print('VERDICT ' + json.dumps({'all_pass': all(l.startswith('PASS') for l in led), 'scales': {x: out['scales'][x].get('single_changes_from_T1') for x in out['scales']}, 'secs': out['secs']})) json.dump(out, open(a.out, 'w'), indent=1)