#!/usr/bin/env python3 """C329 two explicitly named Noah/Flood-Shem bindings, fixed source contexts. python C329_Independent_Audit.py --sources DIR --out DIR Input: C322_DATA.json. Uses G2 Noah/Flood/Noah-death and G2 or G1 Shem records. No new endpoint, E execution, coherent-Gear relabeling, or C330 calculation. """ 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 geom(points): a, b, c, d = points return {'descending': a > b > c > d, 'gaps': [a - b, b - c, c - d], 'intervals': [a - c, b - d], 'overlap': b - c, 'outer': a - d} 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 = (args.sources / 'C322_DATA.json').read_bytes() source = json.loads(raw) by_gear = {row['gear']: row for row in source['biographies']} roles = ['Noah birth', 'Shem birth', 'Flood start', 'Noah death', 'Shem death'] shem_roles = {'Shem birth', 'Shem death'} phases = [F(-1, 4), F(1, 4)] checks, modes, all_annual, all_phase, all_quads = [], [], [], [], [] 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) for mode, shem_gear, family_width in [('Noah_bound_500_100', 2, 500), ('Arphaxad_bound_502_98', 1, 502)]: selected, components, origins = {}, {}, {} for role in roles: gear = shem_gear if role in shem_roles else 2 row = by_gear[gear] origins[role] = {'source_Gear': gear, 'source_C322_index': row['i']} for tradition in ['SP', 'MT']: selected[tradition, role] = row[tradition + '_records'][role] for comp in row['components']: p = F(comp['phase']) components[tradition, role, p] = F(comp[tradition][row['roles'].index(role)]) check(mode + '/' + tradition + '/' + role + '/phase/' + str(p), components[tradition, role, p] - selected[tradition, role]['center'], p) check(mode + '/' + role + '/same-role460', selected['SP', role]['center'] - selected['MT', role]['center'], 460) check(mode + '/' + role + '/source Gears retained', [selected[t, role]['gear'] for t in ['SP', 'MT']], [gear, gear]) sp = [F(selected['SP', role]['center']) for role in roles] mt = [F(selected['MT', role]['center']) for role in roles] expected_chain = [500, 100, 350, 150] if shem_gear == 2 else [502, 98, 350, 152] for tradition, chain in [('SP', sp), ('MT', mt)]: check(mode + '/' + tradition + '/adjacent spans', [chain[k] - chain[k + 1] for k in range(4)], [F(v) for v in expected_chain]) check(mode + '/' + tradition + '/Noah950', chain[0] - chain[3], F(950)) check(mode + '/' + tradition + '/Shem600', chain[1] - chain[4], F(600)) check(mode + '/' + tradition + '/NoahFlood600', chain[0] - chain[2], F(600)) annual, trials, quads = [], [], [] for a_role, c_role in itertools.product(roles, repeat=2): a = F(selected['SP', a_role]['center']) b = F(selected['MT', a_role]['center']) c = F(selected['SP', c_role]['center']) d, r = a - c, b - c annual.append({'mode': mode, 'anchor_role': a_role, 'terminal_role': c_role, 'coordinates_ABC': [a, b, c], 'source_duration': d, 'delta': a - b, 'residual': r, 'sign': sign(r), 'partition_identity': r == d - 460, 'records': {'A': selected['SP', a_role], 'B': selected['MT', a_role], 'C': selected['SP', c_role]}}) for phase_tuple in itertools.product(phases, repeat=3): pa, pb, pc = phase_tuple av, bv, cv = components['SP', a_role, pa], components['MT', a_role, pb], components['SP', c_role, pc] spans = [av - bv, bv - cv, av - cv] errors = [spans[0] - 460, spans[1] - r, spans[2] - d] exact = all(e == 0 for e in errors) trials.append({'mode': mode, 'anchor_role': a_role, 'terminal_role': c_role, 'physical_phases': phase_tuple, 'coordinates': [av, bv, cv], 'durations_context_residual_source': spans, 'annual_d': d, 'annual_r': r, 'residuals': errors, 'exact': exact, 'positive': spans[1] > 0, 'partition_identity': spans[1] == spans[2] - spans[0], 'phase_equality_criterion': exact == (pa == pb == pc), 'sign_stable': sign(spans[1]) == sign(r)}) for a_role, c_role in [('Noah birth', 'Shem birth'), ('Flood start', 'Shem death')]: corner_refs = [('SP', a_role), ('MT', a_role), ('SP', c_role), ('MT', c_role)] corners = [F(selected[t, role]['center']) for t, role in corner_refs] geometry = geom(corners) check(mode + '/' + a_role + '/full geometry', geometry, {'descending': True, 'gaps': [F(460), F(family_width - 460), F(460)], 'intervals': [F(family_width)] * 2, 'overlap': F(family_width - 460), 'outer': F(family_width + 460)}) exact_quads = [] for phase in phases: values = [components[t, role, phase] for t, role in corner_refs] check(mode + '/' + a_role + '/like-phase quadruple/' + str(phase), geom(values), geometry) exact_quads.append({'phase': phase, 'coordinates': values}) quads.append({'mode': mode, 'anchor_role': a_role, 'terminal_role': c_role, 'records': {key: selected[t, role] for key, (t, role) in zip('ABCD', corner_refs)}, 'centers': corners, 'geometry': geometry, 'like_phase_components': exact_quads}) counts = {'annual': 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_trials': len(trials), 'exact_phase_partitions': sum(r['exact'] for r in trials), 'exact_positive_phase_partitions': sum(r['exact'] and r['positive'] for r in trials)} check(mode + '/complete counts', counts, {'annual': 25, 'annual_positive': 6, 'annual_negative': 19, 'annual_zero': 0, 'phase_trials': 200, 'exact_phase_partitions': 50, 'exact_positive_phase_partitions': 12}) check(mode + '/all annual identities', all(r['partition_identity'] for r in annual), True) check(mode + '/all component identities', all(r['partition_identity'] for r in trials), True) check(mode + '/all phase criteria', all(r['phase_equality_criterion'] for r in trials), True) check(mode + '/all signs stable', all(r['sign_stable'] for r in trials), True) modes.append({'mode': mode, 'Noah_Flood_Gear': 2, 'Shem_Gear': shem_gear, 'coherent_single_Gear_biography': shem_gear == 2, 'role_origins': origins, 'SP_centers': sp, 'MT_centers': mt, 'counts': counts, 'positive_residual_multiplicities': dict(Counter(str(r['residual']) for r in annual if r['sign'] == 'positive')), 'source_records': {t: {role: selected[t, role] for role in roles} for t in ['SP', 'MT']}}) all_annual.extend(annual) all_phase.extend(trials) all_quads.extend(quads) base = {(r['anchor_role'], r['terminal_role']): r for r in all_annual if r['mode'] == 'Noah_bound_500_100'} changed = [r for r in all_annual if r['mode'] == 'Arphaxad_bound_502_98'] sensitivity = [] for row in changed: key = row['anchor_role'], row['terminal_role'] before = base[key] actual = row['residual'] - before['residual'] predicted = -2 * int(key[0] in shem_roles) + 2 * int(key[1] in shem_roles) sensitivity.append({'anchor_role': key[0], 'terminal_role': key[1], 'base_d': before['source_duration'], 'alternate_d': row['source_duration'], 'base_r': before['residual'], 'alternate_r': row['residual'], 'residual_change': actual, 'role_shift_formula': actual == predicted, 'sign_preserved': row['sign'] == before['sign']}) check('all25 sensitivity relations', all(r['role_shift_formula'] for r in sensitivity), True) check('all25 signs preserved across bindings', all(r['sign_preserved'] for r in sensitivity), True) check('sensitivity multiplicities', dict(Counter(str(r['residual_change']) for r in sensitivity)), {'0': 13, '2': 6, '-2': 6}) alternate_phases = [r for r in all_phase if r['mode'] == 'Arphaxad_bound_502_98'] check('no alternate phase restores500 source span', all(r['durations_context_residual_source'][2] != 500 for r in alternate_phases), True) check('no alternate phase restores40 residual', all(r['durations_context_residual_source'][1] != 40 for r in alternate_phases), True) check('all50 annual candidates', len(all_annual), 50) check('all400 phase candidates', len(all_phase), 400) check('four completed existing endpoint configurations', len(all_quads), 4) result = {'step': 'C329', 'source_sha256': hashlib.sha256(raw).hexdigest(), 'modes': modes, 'annual_rows': all_annual, 'phase_rows': all_phase, 'quadruples': all_quads, 'sensitivity': sensitivity, 'counts': {'annual_rows': len(all_annual), 'phase_rows': len(all_phase), 'exact_phase_partitions': sum(r['exact'] for r in all_phase), 'exact_positive_phase_partitions': sum(r['exact'] and r['positive'] for r in all_phase)}, 'checks': checks, 'check_count': len(checks), 'all_checks_passed': all(r['pass'] for r in checks), 'scope': 'Only the two named G2 Noah/Flood bindings with G2 or G1 Shem, SP OFF/T0 and MT ON/T60, full430.', 'claim_status': 'Source-admitted binding comparison; the mixed binding is not a coherent single-Gear biography.', 'prohibitions_observed': ['No new endpoint/context/phase', 'No E execution', 'No fitted anchor', 'No C330 calculation']} args.out.mkdir(parents=True, exist_ok=True) path = args.out / 'C329_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()