#!/usr/bin/env python3 """C328 four-context census from independently selected frozen source records. python C328_Independent_Audit.py --sources DIR --out DIR Requires C286_DATA.json, C322_DATA.json, PREVIOUS_DATA.json (C327). No new endpoint/context/phase, E execution, anchor fit, or C329 computation. """ import argparse import hashlib import itertools import json from collections import Counter from fractions import Fraction as F from pathlib import Path def sign(x): return 'positive' if x > 0 else 'negative' if x < 0 else 'zero' 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() raw = {name: (args.sources / name).read_bytes() for name in ['C286_DATA.json', 'C322_DATA.json', 'PREVIOUS_DATA.json']} register = json.loads(raw['C286_DATA.json'])['target_register'] held = json.loads(raw['C322_DATA.json']) previous = json.loads(raw['PREVIOUS_DATA.json']) roles = ['Noah birth', 'Shem birth', 'Flood start', 'Noah death', 'Shem death'] phases = [F(-1, 4), F(1, 4)] checks, contexts, annual_all, phase_all = [], [], [], [] 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) check('predecessor is C327', previous['step'], 'C327') check('three primary held biographies', len(held['biographies']), 3) for row in held['biographies']: check(f'G{row["gear"]}/roles', row['roles'], roles) for role in roles: check(f'G{row["gear"]}/{role}/SP source membership', row['SP_records'][role] in register, True) for cainan, terah in itertools.product([0, 1], repeat=2): context = f'{cainan}{terah}' annual, phase_rows, bios, deltas = [], [], [], [] for row in held['biographies']: gear, index = row['gear'], row['i'] sp, mt = row['SP_records'], {} label = f'{context}/G{gear}' for role in roles: matches = [r for r in register if r['tradition'] == 'MT' and r['gear'] == gear and r['role'] == role and r['Cainan'] == cainan and r['Terah60'] == terah and r['full430'] == 1] check(label + '/' + role + '/unique MT source', len(matches), 1) mt[role] = matches[0] check(label + '/' + role + '/no imported companion', mt[role].get('rail'), None) deltas.append(F(sp[role]['center'] - mt[role]['center'])) widths = [mt[roles[k]]['center'] - mt[roles[k + 1]]['center'] for k in range(4)] check(label + '/whole MT biography internal widths', widths, [500, 100, 350, 150]) if context == '11': check(label + '/actual held C322 MT records', mt, row['MT_records']) bios.append({'gear': gear, 'source_i': index, 'SP_records': sp, 'MT_records': mt}) sp_exact = {(role, F(comp['phase'])): F(comp['SP'][position]) for comp in row['components'] for position, role in enumerate(roles)} check(label + '/SP inherited physical offsets', all(sp_exact[role, p] == F(sp[role]['center']) + p for role in roles for p in phases), True) if context == '11': check(label + '/MT11 inherited physical offsets', all(F(comp['MT'][position]) == F(mt[role]['center']) + F(comp['phase']) for comp in row['components'] for position, role in enumerate(roles)), True) for a_role, c_role in itertools.product(roles, repeat=2): a, b, z = F(sp[a_role]['center']), F(mt[a_role]['center']), F(sp[c_role]['center']) delta, d, residual = a - b, a - z, b - z annual.append({'context': context, 'Cainan': cainan, 'Terah60': terah, 'full430': 1, 'gear': gear, 'source_i': index, 'anchor_role': a_role, 'terminal_role': c_role, 'A_SP': a, 'B_MT': b, 'C_SP': z, 'delta': delta, 'source_duration': d, 'residual': residual, 'sign': sign(residual), 'records': {'A': sp[a_role], 'B': mt[a_role], 'C': sp[c_role]}, 'partition_identity': residual == d - delta}) for pa, pb, pc in itertools.product(phases, repeat=3): av, bv, cv = sp_exact[a_role, pa], b + pb, sp_exact[c_role, pc] spans = [av - bv, bv - cv, av - cv] errors = [spans[0] - delta, spans[1] - residual, spans[2] - d] exact = all(e == 0 for e in errors) phase_rows.append({'context': context, 'gear': gear, 'source_i': index, 'anchor_role': a_role, 'terminal_role': c_role, 'phases': [pa, pb, pc], 'coordinates': [av, bv, cv], 'durations_context_residual_source': spans, 'annual_delta': delta, 'annual_d': d, 'annual_r': residual, 'residuals_context_residual_source': errors, 'exact': exact, 'positive_residual': spans[1] > 0, 'partition_identity': spans[1] == spans[2] - spans[0], 'phase_equality_criterion': exact == (pa == pb == pc), 'sign_stable': sign(spans[1]) == sign(residual)}) check(context + '/uniform15-source-role displacement', len(set(deltas)), 1) delta = deltas[0] check(context + '/expected source displacement', delta, { '00': F(650), '01': F(590), '10': F(520), '11': F(460)}[context]) check(context + '/source arithmetic', all(r['partition_identity'] for r in annual), True) check(context + '/component arithmetic', all(r['partition_identity'] for r in phase_rows), True) check(context + '/phase criterion', all(r['phase_equality_criterion'] for r in phase_rows), True) check(context + '/component sign stability', all(r['sign_stable'] for r in phase_rows), True) counts = { 'annual_candidates': len(annual), 'annual_positive': sum(r['sign'] == 'positive' for r in annual), 'annual_negative': sum(r['sign'] == 'negative' for r in annual), 'annual_zero': sum(r['sign'] == 'zero' for r in annual), 'phase_candidates': len(phase_rows), 'exact_phase_partitions': sum(r['exact'] for r in phase_rows), 'exact_positive_phase_partitions': sum(r['exact'] and r['positive_residual'] for r in phase_rows), 'phase_positive': sum(r['positive_residual'] for r in phase_rows), } expected_pos = {'00': 6, '01': 12, '10': 12, '11': 18}[context] check(context + '/75 annual rows', counts['annual_candidates'], 75) check(context + '/positive count', counts['annual_positive'], expected_pos) check(context + '/negative count', counts['annual_negative'], 75 - expected_pos) check(context + '/nozero', counts['annual_zero'], 0) check(context + '/600 phase rows', counts['phase_candidates'], 600) check(context + '/150exact', counts['exact_phase_partitions'], 150) check(context + '/exactpositive', counts['exact_positive_phase_partitions'], 2 * expected_pos) check(context + '/allphasepositive', counts['phase_positive'], 8 * expected_pos) noah950 = [r for r in annual if r['anchor_role'] == 'Noah birth' and r['terminal_role'] == 'Noah death'] check(context + '/three950 source instances', len(noah950), 3) check(context + '/Noah source lifespan950', {str(r['source_duration']) for r in noah950} == {'950'}, True) contexts.append({'context': context, 'Cainan': cainan, 'Terah60': terah, 'full430': 1, 'delta': delta, 'source_biographies': bios, 'counts': counts, 'positive_residual_multiplicities': dict(Counter(str(r['residual']) for r in annual if r['sign'] == 'positive')), 'Noah950_rows': noah950, 'distribution': [{'d': d, 'r': r, 'instances': n} for (d, r), n in sorted(Counter((r['source_duration'], r['residual']) for r in annual).items())]}) annual_all.extend(annual) phase_all.extend(phase_rows) old_rows = {(r['gear'], r['anchor_role'], r['terminal_role']): r for r in previous['rows']} slice11 = [r for r in annual_all if r['context'] == '11'] checks11 = [] for row in slice11: old = old_rows[row['gear'], row['anchor_role'], row['terminal_role']] checks11.append(all(row[k] == old[k] for k in ['A_SP', 'B_MT', 'C_SP', 'source_duration', 'residual', 'sign', 'records'])) check('all75 C327 annual rows reproduced', len(checks11) == 75 and all(checks11), True) old_phases = {(r['gear'], r['anchor_role'], r['terminal_role'], tuple(r['phases'])): r for r in previous['phase_trials']} phase11 = [r for r in phase_all if r['context'] == '11'] checks_phase11 = [] for row in phase11: old = old_phases[row['gear'], row['anchor_role'], row['terminal_role'], tuple(str(x) for x in row['phases'])] checks_phase11.append(encode(row['coordinates']) == old['coordinates'] and encode(row['durations_context_residual_source']) == old['durations'] and row['exact'] == old['exact'] and row['positive_residual'] == old['positive_residual']) check('all600 C327 phase rows reproduced', len(checks_phase11) == 600 and all(checks_phase11), True) check('300 annual candidates', len(annual_all), 300) check('2400 phase candidates', len(phase_all), 2400) check('named950 residuals', [r['Noah950_rows'][0]['residual'] for r in contexts], [F(300), F(360), F(430), F(490)]) check('all490 instances confined to11 Noah950 family', all(r['context'] == '11' and r['anchor_role'] == 'Noah birth' and r['terminal_role'] == 'Noah death' for r in annual_all if r['residual'] == 490), True) check('exactlythree490 instances', sum(r['residual'] == 490 for r in annual_all), 3) result = {'step': 'C328', 'source_sha256': {k: hashlib.sha256(v).hexdigest() for k, v in raw.items()}, 'contexts': contexts, 'annual_rows': annual_all, 'phase_rows': phase_all, 'counts': {'annual_candidates': len(annual_all), 'phase_candidates': len(phase_all), 'annual_positive': sum(r['sign'] == 'positive' for r in annual_all), 'annual_negative': sum(r['sign'] == 'negative' for r in annual_all), 'annual_zero': sum(r['sign'] == 'zero' for r in annual_all), 'exact_phase_partitions': sum(r['exact'] for r in phase_all), 'exact_positive_phase_partitions': sum(r['exact'] and r['positive_residual'] for r in phase_all)}, 'C327_slice_reproduced': all(checks11) and all(checks_phase11), 'checks': checks, 'check_count': len(checks), 'all_checks_passed': all(r['pass'] for r in checks), 'claim_status': 'Finite admitted-context sensitivity; uniqueness of a chosen residual is conditional on that criterion, not a source selector.', 'phase_scope': 'The inherited +/-1/4 output offsets are used unchanged for the selected existing context endpoints.', 'prohibitions_observed': ['No E execution', 'No new endpoint/context/phase', 'No fitted anchor', 'No C329 calculation']} args.out.mkdir(parents=True, exist_ok=True) path = args.out / 'C328_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'], 'C327_slice_reproduced': result['C327_slice_reproduced'], 'all_checks_passed': result['all_checks_passed']}, sort_keys=True)) if __name__ == '__main__': main()