#!/usr/bin/env python3 """C331 admitted SP Noah-death partitions inside the four held C2872K edges. python C331_Independent_Audit.py --sources DIR --out DIR Reads C287_DATA.json, C286_DATA.json and the frozen File18/C281/prior-art controls. No MT companion, LXX death path, new endpoint, or C332 calculation is generated. """ import argparse import hashlib import itertools import json from fractions import Fraction as F from pathlib import Path def encode(x): if isinstance(x, F): return str(x) if isinstance(x, dict): return {str(k): encode(v) for k, v in x.items()} if isinstance(x, (list, tuple)): return [encode(v) for v in x] return x def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--sources', type=Path, required=True) parser.add_argument('--out', type=Path, required=True) args = parser.parse_args() names = ['C287_DATA.json', 'C286_DATA.json', 'C281_REPORT.md', 'PRIOR_ART_LOCATOR.md', 'File_18.md'] raw = {name: (args.sources / name).read_bytes() for name in names} held = json.loads(raw['C287_DATA.json']) register = json.loads(raw['C286_DATA.json'])['target_register'] c281_coverage = {} for line in raw['C281_REPORT.md'].decode().splitlines(): if line.startswith('|'): cells = [s.strip() for s in line.strip('|').split('|')] if len(cells) == 3 and cells[0].isdigit() and cells[1].isdigit(): c281_coverage[int(cells[0])] = {'required': int(cells[1]), 'admitted': not cells[2].startswith('Absent'), 'status': cells[2]} checks, rows, phases_out = [], [], [] def check(name, actual, expected): passed = actual == expected checks.append({'name': name, 'actual': encode(actual), 'expected': encode(expected), 'pass': passed}) if not passed: raise AssertionError(name) complete = [row for row in held['rows'] if row['complete']] check('four C287 complete indices', [r['i'] for r in complete], [2, 3, 4, 5]) all_mt_noah = [r for r in register if r['tradition'] == 'MT' and r['role'] == 'Noah birth' and r['Cainan'] == 1 and r['Terah60'] == 1 and r['full430'] == 1] check('global held MT Noah centers', sorted(r['center'] for r in all_mt_noah), [3246, 3248, 3250]) check('global held MT Noah rails', all(r.get('rail') is None for r in all_mt_noah), True) quarter_phases = [F(-1, 4), F(1, 4)] for old in complete: index = old['i'] label = f'i{index}' ns = [r for r in old['Noah_records'] if r['tradition'] == 'SP'] check(label + '/one held SP Noah', len(ns), 1) n_record = ns[0] check(label + '/SP Noah source membership', n_record in register, True) gear, rail = n_record['gear'], n_record['rail'] ds = [r for r in register if r['tradition'] == 'SP' and r['role'] == 'Noah death' and r['gear'] == gear and r.get('rail') == rail and r['Cainan'] == 0 and r['Terah60'] == 0 and r['full430'] == 1] ms = [r for r in all_mt_noah if r['gear'] == gear] flood_role = 'Flood start' if rail == 'primary' else 'Flood close' rs = [r for r in register if r['tradition'] == 'MT' and r['role'] == flood_role and r['gear'] == gear + 1 and r['Cainan'] == 1 and r['Terah60'] == 1 and r['full430'] == 1 and r['center'] == old['R']] check(label + '/one same-rail SP death', len(ds), 1) check(label + '/one actual same-Gear MT birth', len(ms), 1) check(label + '/one actual next-Gear MT Flood boundary', len(rs), 1) records = {'N': n_record, 'M': ms[0], 'D': ds[0], 'R': rs[0]} n, m, d, r = [F(records[k]['center']) for k in 'NMDR'] legs = [n - m, m - d, d - r] expected = [460, 490, 108] if rail == 'primary' else [459, 491, 108] check(label + '/ordered source chain', n > m > d > r, True) check(label + '/actual source legs', legs, [F(x) for x in expected]) check(label + '/SP Noah950', n - d, F(950)) check(label + '/C287 endpoint2K', n - r, F(2 * 529)) check(label + '/death remainder108', d - r, F(108)) check(label + '/Noah950 plus108', (n - d) + (d - r), F(1058)) check(label + '/actual MT Noah to R', m - r, F(598 if rail == 'primary' else 599)) required = n - 460 required_hits = [x for x in all_mt_noah if x['center'] == required] check(label + '/required460 source availability', bool(required_hits), rail == 'primary') check(label + '/C281 required coordinate', F(c281_coverage[index]['required']), required) check(label + '/C281 membership agreement', c281_coverage[index]['admitted'], bool(required_hits)) required_components = [] for pn in quarter_phases: target = n + pn - 460 hits = [{'record': rec, 'physical_phase': pm, 'coordinate': F(rec['center']) + pm} for rec in all_mt_noah for pm in quarter_phases if F(rec['center']) + pm == target] check(label + '/required460 component availability/' + str(pn), len(hits), 1 if rail == 'primary' else 0) required_components.append({'N_phase': pn, 'required_MT_coordinate': target, 'actual_MT_matches': hits}) row_phases = [] for ps in itertools.product(quarter_phases, repeat=4): nv, mv, dv, rv = [value + phase for value, phase in zip([n, m, d, r], ps)] actual_legs = [nv - mv, mv - dv, dv - rv] residuals = [actual - target for actual, target in zip(actual_legs, legs)] exact = all(x == 0 for x in residuals) row_phases.append({'i': index, 'SP_gear': gear, 'SP_rail': rail, 'phases_NMDR': ps, 'coordinates_NMDR': [nv, mv, dv, rv], 'annual_legs': legs, 'actual_legs': actual_legs, 'residuals': residuals, 'all_annual_legs_exact': exact, 'same_phase_criterion': exact == (len(set(ps)) == 1), 'Noah_lifespan': nv - dv, 'total2K': nv - rv, 'has460_490_108_legs': actual_legs == [F(460), F(490), F(108)]}) check(label + '/16 independent phase quartets', len(row_phases), 16) check(label + '/two exact phase quartets', sum(p['all_annual_legs_exact'] for p in row_phases), 2) check(label + '/allphase connected equality criterion', all(p['same_phase_criterion'] for p in row_phases), True) check(label + '/no phase repair into primary leg pattern', sum(p['has460_490_108_legs'] for p in row_phases), 2 if rail == 'primary' else 0) aliases = [record for record in old['Noah_records'] if record['tradition'] != 'SP'] check(label + '/coincident aliases retained only as Noah labels', all(a['role'] == 'Noah birth' and a['center'] == n for a in aliases), True) rows.append({'i': index, 'SP_gear': gear, 'SP_rail': rail, 'records': records, 'coordinates_NMDR': [n, m, d, r], 'legs': legs, 'Noah_lifespan': n - d, 'total2K': n - r, 'M_to_R': m - r, 'required_MT_for460': required, 'required_MT_matches': required_hits, 'required_MT_component_checks': required_components, 'C281_coverage': c281_coverage[index], 'coincident_Noah_labels_not_death_paths': aliases}) phases_out.extend(row_phases) check('four admitted SP death paths', len(rows), 4) check('two primary and two companion', [sum(r['SP_rail'] == rail for r in rows) for rail in ['primary', 'companion']], [2, 2]) check('64 phase trials', len(phases_out), 64) check('eight complete exact phase paths', sum(r['all_annual_legs_exact'] for r in phases_out), 8) check('two source-admitted460 MT birth joins', sum(bool(r['required_MT_matches']) for r in rows), 2) check('two retained LXX Noah aliases', sum(len(r['coincident_Noah_labels_not_death_paths']) for r in rows), 2) result = {'step': 'C331', 'source_sha256': {name: hashlib.sha256(value).hexdigest() for name, value in raw.items()}, 'global_held_MT_Noah_records': all_mt_noah, 'rows': rows, 'phase_quartets': phases_out, 'checks': checks, 'check_count': len(checks), 'all_checks_passed': all(r['pass'] for r in checks), 'counts': {'SP_paths': 4, 'phase_trials': 64, 'exact_phase_paths': 8, 'actual460_490_primary_paths': 2, 'actual459_491_companion_paths': 2, 'retained_LXX_Noah_aliases': 2, 'new_LXX_death_paths': 0}, 'prior_art_status': 'The four 2K endpoint relations and adjacent-Gear start/close selector are prior art. The death108 dissection is a bounded presentation refinement; no archive-wide novelty is claimed.', 'source_limit': 'Required companion MT coordinates have no admitted MT Noah record in the globally held context. Actual same-Gear MT births are retained instead.', 'prohibitions_observed': ['No MT companion invented', 'No new LXX death path', 'No new endpoint/context/phase', 'No C332 calculation']} args.out.mkdir(parents=True, exist_ok=True) path = args.out / 'C331_Independent_Audit_Results.json' path.write_text(json.dumps(encode(result), indent=2, sort_keys=True) + '\n') print(json.dumps({'result': str(path), 'checks': len(checks), 'counts': result['counts'], 'all_checks_passed': result['all_checks_passed']}, sort_keys=True)) if __name__ == '__main__': main()