#!/usr/bin/env python3 """C325 exhaustive census of the fixed primary biography role/phase menu. python C325_Independent_Audit.py --sources DIR --out DIR Requires C322_DATA.json, C314_DATA.json and C271_REGISTER.json. No new endpoints, E execution, anchor fitting, or C326 work. Uses actual frozen component coordinates. """ import argparse import hashlib import itertools import json from collections import Counter from fractions import Fraction as F from pathlib import Path 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() hashes, inputs = {}, {} for name in ['C322_DATA.json', 'C314_DATA.json', 'C271_REGISTER.json']: raw = (args.sources / name).read_bytes() hashes[name] = hashlib.sha256(raw).hexdigest() inputs[name] = json.loads(raw) checks = [] def check(label, actual, expected): ok = actual == expected checks.append({'label': label, 'pass': ok, 'actual': str(actual), 'expected': str(expected)}) if not ok: raise AssertionError(label) phases = [F(-1, 4), F(1, 4)] roles = ['Noah birth', 'Shem birth', 'Flood start', 'Noah death', 'Shem death'] expected_pairs = [('Noah birth', 'Shem birth'), ('Flood start', 'Shem death')] annual, component, successes = [], [], [] source_biographies = [] for biography in inputs['C322_DATA.json']['biographies']: gear, idx = biography['gear'], biography['i'] label = f'G{gear}/i{idx}' check(label + ' roles', biography['roles'], roles) sp, mt = biography['SP_records'], biography['MT_records'] for role in roles: check(label + '/' + role + '/same gear', (sp[role]['gear'], mt[role]['gear']), (gear, gear)) check(label + '/' + role + '/SP context', (sp[role]['tradition'], sp[role]['Cainan'], sp[role]['Terah60'], sp[role]['full430']), ('SP', 0, 0, 1)) check(label + '/' + role + '/MT context', (mt[role]['tradition'], mt[role]['Cainan'], mt[role]['Terah60'], mt[role]['full430']), ('MT', 1, 1, 1)) source_biographies.append({'i': idx, 'gear': gear, 'SP_records': sp, 'MT_records': mt}) exact = {} for comp in biography['components']: phase = F(comp['phase']) check(label + '/valid phase/' + str(phase), phase in phases, True) for tradition in ['SP', 'MT']: for position, role in enumerate(roles): value = F(comp[tradition][position]) exact[tradition, role, phase] = value center = biography[tradition + '_records'][role]['center'] check(label + '/' + tradition + '/' + role + '/offset/' + str(phase), value - center, phase) old_rows = [r for r in inputs['C314_DATA.json']['rows'] if r['gear'] == gear and r['i'] == idx and r['rail'] == 'primary'] check(label + '/unique primary C314 row', len(old_rows), 1) old = old_rows[0] check(label + '/reversed index', old['j'], 10 - idx) for role in ['Noah birth', 'Shem birth', 'Shem death']: check(label + '/C314 record/' + role, old['source_records'][role], sp[role]) for a_role, c_role in itertools.product(roles, roles): a, b, c = (F(sp[a_role]['center']), F(mt[a_role]['center']), F(sp[c_role]['center'])) widths = [a - b, b - c, a - c] residuals = [widths[0] - 460, widths[1] - 40, widths[2] - 500] is_match = residuals == [0, 0, 0] entry = {'i': idx, 'gear': gear, 'A_role': a_role, 'B_role': a_role, 'C_role': c_role, 'A_SP_center': int(a), 'B_MT_center': int(b), 'C_SP_center': int(c), 'widths_460_40_500': [str(w) for w in widths], 'residuals': [str(r) for r in residuals], 'all_exact': is_match} annual.append(entry) check(label + '/' + a_role + '/' + c_role + '/dependent third width', widths[0] + widths[1], widths[2]) if is_match: successes.append(entry) for pa, pb, pc in itertools.product(phases, repeat=3): av, bv, cv = exact['SP', a_role, pa], exact['MT', a_role, pb], exact['SP', c_role, pc] ws = [av - bv, bv - cv, av - cv] rs = [ws[0] - 460, ws[1] - 40, ws[2] - 500] match = rs == [0, 0, 0] phase_entry = {'i': idx, 'gear': gear, 'A_role': a_role, 'B_role': a_role, 'C_role': c_role, 'physical_phases': [str(p) for p in [pa, pb, pc]], 'coordinates': [str(x) for x in [av, bv, cv]], 'widths_460_40_500': [str(w) for w in ws], 'residuals': [str(r) for r in rs], 'all_exact': match} if match: check(label + '/successful phase equality/' + a_role + '/' + str(pa), pa == pb == pc, True) anchor_matches = [r for r in inputs['C271_REGISTER.json'] if r['source_event']['tradition'] == 'SP' and r['source_event']['gear'] == gear and r['source_event']['role'] == a_role and r['source_event']['BC_Nisan'] == a] check(label + '/unique C271 A anchor/' + a_role + '/' + str(pa), len(anchor_matches), 1) anchor = anchor_matches[0] anchor_components = [r for r in anchor['phases'] if F(r['reflected_coordinate']) == av] check(label + '/unique C271 A component/' + a_role + '/' + str(pa), len(anchor_components), 1) anchor_component = anchor_components[0] ancestor = anchor['cumulative_source'] expected_role = 'Flood' if a_role == 'Noah birth' else 'Shem' check(label + '/C271 A ancestry role/' + a_role + '/' + str(pa), ancestor['source_role'], expected_role) check(label + '/C271 A ancestry index/' + a_role + '/' + str(pa), ancestor['source_index'], idx) check(label + '/C271 A ancestry phase/' + a_role + '/' + str(pa), F(anchor_component['cumulative_coordinate']) + ancestor['source_BC_base'], pa) check(label + '/C271 A comparison width/' + a_role + '/' + str(pa), av - F(anchor_component['cumulative_coordinate']), 8993) phase_entry['A_ancestry'] = { 'source': 'C271', 'record_id': anchor['id'], 'profile': ancestor['profile'], 'cumulative_role': ancestor['source_role'], 'cumulative_index_i': idx, 'cumulative_phase': str(pa), 'cumulative_coordinate': anchor_component['cumulative_coordinate'], 'comparison_width': 8993, 'comparison_status': anchor['comparison_status'], } key = {'Shem birth': 'Shem_birth', 'Shem death': 'Shem_death'}[c_role] old_components = [r for r in old['components'] if F(r[key]) == cv] check(label + '/unique C314 Shem component/' + c_role + '/' + str(pc), len(old_components), 1) old_component = old_components[0] check(label + '/opposite Shem ancestry/' + c_role + '/' + str(pc), F(old_component['Shem_ancestry_phase']), -pc) check(label + '/paired Noah ancestry/' + c_role + '/' + str(pc), F(old_component['Noah_ancestry_phase']), pc) phase_entry['C_Shem_ancestry'] = { 'source': 'C314', 'cumulative_index_j': old['j'], 'cumulative_phase': old_component['Shem_ancestry_phase'], 'registered_paired_Noah_index_i': idx, 'registered_paired_Noah_ancestry_phase': old_component['Noah_ancestry_phase'], 'physical_C_phase': str(pc), 'note': 'A ancestry is separately bound to its own exact C271 Noah or Flood record.' } check(label + '/A and C distinct ancestry phase/' + c_role + '/' + str(pc), F(old_component['Shem_ancestry_phase']) != pa, True) component.append(phase_entry) check('annual menu size', len(annual), 75) check('component menu size', len(component), 600) check('annual successes', len(successes), 6) exact_successes = [r for r in component if r['all_exact']] check('component successes', len(exact_successes), 12) check('annual successes exactly prescribed two role-pair families', sorted(set((r['A_role'], r['C_role']) for r in successes)), sorted(expected_pairs)) for gear in [1, 2, 3]: check(f'G{gear}/annual successes', sum(r['gear'] == gear for r in successes), 2) check(f'G{gear}/phase successes', sum(r['gear'] == gear for r in exact_successes), 4) counts = { 'annual_candidates': len(annual), 'annual_successes': len(successes), 'annual_failures': len(annual) - len(successes), 'exact_component_candidates': len(component), 'exact_component_successes': len(exact_successes), 'exact_component_failures': len(component) - len(exact_successes), 'annual_leg_passes': [sum(F(r['residuals'][k]) == 0 for r in annual) for k in range(3)], 'component_leg_passes': [sum(F(r['residuals'][k]) == 0 for r in component) for k in range(3)], } check('annual separate leg pass counts', counts['annual_leg_passes'], [75, 6, 6]) check('component separate leg pass counts', counts['component_leg_passes'], [300, 24, 24]) phase_patterns = Counter(tuple(r['physical_phases']) for r in exact_successes) result = { 'step': 'C325', 'source_sha256': hashes, 'scope': '3 primary same-Gear biographies; 5 SP anchor roles; 5 SP target roles; 8 independent held phase combinations.', 'source_biographies': source_biographies, 'counts': counts, 'successful_phase_patterns': [{'pattern': list(k), 'count': v} for k, v in sorted(phase_patterns.items())], 'annual_successes': successes, 'exact_component_successes': exact_successes, 'annual_candidates': annual, 'exact_component_candidates': component, 'checks': checks, 'check_count': len(checks), 'all_checks_passed': all(c['pass'] for c in checks), 'claim_status': 'Finite coordinate census. The 40 leg follows from the 460 and 500 legs; no source prescription of E is inferred.', 'prohibitions_observed': ['No E endpoint generation', 'No fitted anchor', 'No new endpoint or phase', 'No MT/LXX SP companions', 'No cumulative Gear', 'No C326 calculation'], } args.out.mkdir(parents=True, exist_ok=True) target = args.out / 'C325_Independent_Audit_Results.json' target.write_text(json.dumps(result, indent=2, sort_keys=True) + '\n') print(json.dumps({'result': str(target), 'counts': counts, 'checks': len(checks), 'all_checks_passed': result['all_checks_passed']}, sort_keys=True)) if __name__ == '__main__': main()