#!/usr/bin/env python3 """C333 synthesis-only audit of sealed C324-C332 scientific claims and bindings. python C333_Independent_Audit.py --sources DIR --out DIR Requires C323_CERTIFICATE.json plus C324..C332 DATA, CERTIFICATE, RESULTS and NEXT_STEP JSON files. No source search, expanded domain, new research or C334. """ import argparse import hashlib import json from collections import Counter 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 rank(matrix): a = [[F(x) for x in row] for row in matrix] r = 0 for c in range(len(a[0])): p = next((k for k in range(r, len(a)) if a[k][c]), None) if p is None: continue a[r], a[p] = a[p], a[r] divisor = a[r][c] a[r] = [x / divisor for x in a[r]] for k in range(len(a)): if k != r and a[k][c]: factor = a[k][c] a[k] = [x - factor * y for x, y in zip(a[k], a[r])] r += 1 if r == len(a): break return r 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 = ['C323_CERTIFICATE.json'] + [f'C{n}_{kind}.json' for n in range(324, 333) for kind in ['DATA', 'CERTIFICATE', 'RESULTS', 'NEXT_STEP']] raw = {name: (args.sources / name).read_bytes() for name in names} inputs = {name: json.loads(value) for name, value in raw.items()} digest = {name: hashlib.sha256(value).hexdigest() for name, value in raw.items()} d = {n: inputs[f'C{n}_DATA.json'] for n in range(324, 333)} checks, authenticated = [], [] def check(name, actual, expected, scope='scientific_claim'): passed = actual == expected checks.append({'name': name, 'actual': encode(actual), 'expected': encode(expected), 'pass': passed, 'scope': scope}) if not passed: raise AssertionError(name) for n in range(324, 333): step = f'C{n}' cert, result, decision = [inputs[f'{step}_{kind}.json'] for kind in ['CERTIFICATE', 'RESULTS', 'NEXT_STEP']] check(step + '/completed certificate', [cert['step'], cert['status']], [step, 'completed'], 'authentication') check(step + '/passed result', [result['step'], result['status']], [step, 'passed'], 'authentication') check(step + '/data binding', digest[f'{step}_DATA.json'], cert['data_sha256'], 'authentication') check(step + '/results binding', digest[f'{step}_RESULTS.json'], cert['results_sha256'], 'authentication') check(step + '/decision binding', digest[f'{step}_NEXT_STEP.json'], cert['next_step_decision_sha256'], 'authentication') check(step + '/predecessor certificate binding', digest[f'C{n-1}_CERTIFICATE.json'], cert['previous_certificate_sha256'], 'authentication') check(step + '/historical next decision', [decision['completed_step'], decision['next_proposed_step'], decision['executed']], [step, f'C{n+1}', False], 'authentication') check(step + '/authorization remainder in snapshot', decision['authorization_remaining'], 333 - n, 'authentication') check(step + '/no canonical or graph edits', [cert['canonical_or_graph_edits'], result['canonical_or_graph_edits']], [False, False], 'authentication') check(step + '/main check inventory bound', [cert['assertions_passed'], len(result['checks'])], [result['assertions_passed']] * 2, 'authentication') authenticated.append({'step': step, 'certificate_sha256': digest[f'{step}_CERTIFICATE.json'], 'main_assertions': result['assertions_passed'], 'source_checks': result['source_checks_passed']}) check('C324 preserves four positive source findings', len(d[324]['positive_findings']), 4) check('C324 retains nine audited passage records', len(d[324]['passages']), 9) check('C324 preserves local rule and no fitted anchor', [d[324]['local_source_completion_reclassified'], d[324]['new_dilation_anchor_adopted']], [False, False]) check('C324 frozen File09 local positive excerpt', any(p['file'] == 'File_09.md' and '460 × 25/23 = 500' in p['excerpt'] and '540' in p['excerpt'] for p in d[324]['passages']), True) check('C324 exact biography expansion distinction', all([F(x) for x in r['expanded_spans']] == [F(v) * F(25, 23) for v in r['source_spans']] and not r['same_whole_biography_map'] for r in d[324]['biography_operation_test']), True) check('C324 arithmetic obstruction retained', F(500) * F(25, 23) - 500, F(1000, 23)) check('C325 finite source triple counts', [len(d[325]['comparison_domain']), len(d[325]['hits']), len(d[325]['phase_hits'])], [75, 6, 12]) check('C325 two typed role families', sorted(set((r['anchor_role'], r['terminal_role']) for r in d[325]['hits'])), [('Flood start', 'Shem death'), ('Noah birth', 'Shem birth')]) check('C325 actual source legs', all([r['A_SP'] - r['B_MT'], r['B_MT'] - r['C_SP'], r['A_SP'] - r['C_SP']] == [460, 40, 500] for r in d[325]['hits']), True) check('C325 no inferred prescription', d[325]['source_prescription_established'], False) check('C326 six full source fields', len(d[326]['rows']), 6) check('C326 regular shape', all(r['ordered_gaps'] == [460, 40, 460] and r['equal_intervals'] == [500, 500] and r['overlap'] == 40 and r['outer'] == 960 for r in d[326]['rows']), True) comparison = d[326]['File09_comparison'] check('C326 File09 distinct full field', [comparison['gaps'], comparison['overlap'], comparison['outer']], [[40, 460, 40], 460, 540]) check('C326 no whole-field identification', [d[326]['uniform_labelled_affine_equivalence'], d[326]['target_dependency_prescribed'], d[326]['new_coordinates_adopted']], [False] * 3) check('C327 complete positive and negative ledger', [len(d[327]['rows']), len(d[327]['positive_rows']), d[327]['counts']['negative_residuals'], d[327]['counts']['zero_residuals']], [75, 18, 57, 0]) check('C327 all held residual identities', all(r['residual'] == r['source_duration'] - 460 for r in d[327]['rows']), True) check('C327 positive multiplicities', dict(Counter(str(r['residual']) for r in d[327]['positive_rows'])), {'40': 6, '140': 6, '490': 3, '640': 3}) check('C327 exact phase inventory', [len(d[327]['phase_trials']), sum(r['exact'] for r in d[327]['phase_trials'])], [600, 150]) contexts = d[328]['context_summaries'] check('C328 four displacements', [r['delta'] for r in contexts], [650, 590, 520, 460]) check('C328 Noah950 context remainders', [r['Noah_lifespan_residual'] for r in contexts], [300, 360, 430, 490]) check('C328 source and complete-domain counts', [len(d[328]['endpoint_pairs']), len(d[328]['rows']), len(d[328]['phase_trials'])], [60, 300, 2400]) check('C328 existing regular context formula', all(r['delta'] == 650 - 130 * r['Cainan'] - 60 * r['Terah60'] for r in contexts), True) check('C328 all held residuals', all(r['residual'] == r['source_duration'] - r['delta'] for r in d[328]['rows']), True) check('C328 no adopted context or selector', [d[328]['new_contexts_adopted'], d[328]['source_selector_established']], [False, False]) check('C329 two source modes', len(d[329]['modes']), 2) check('C329 mode shapes', [r['durations']['SP']['Noah_to_Shem'] for r in d[329]['modes']], [500, 502]) check('C329 coherent and explicitly mixed binding', [r['coherent_single_gear'] for r in d[329]['modes']], [True, False]) check('C329 role Gear labels preserved', [[r['records']['SP']['Noah birth']['gear'], r['records']['SP']['Shem birth']['gear']] for r in d[329]['modes']], [[2, 2], [2, 1]]) check('C329 stable Noah490', d[329]['invariant_residuals']['Noah_life'], 490) for mode, expected in zip(d[329]['modes'], [(40, 640, 960), (42, 642, 962)]): mode_rows = [r for r in d[329]['rows'] if r['binding'] == mode['binding']] lookup = {(r['anchor_role'], r['terminal_role']): r['residual'] for r in mode_rows} check('C329 sensitivity/' + mode['binding'], [lookup['Noah birth', 'Shem birth'], lookup['Noah birth', 'Shem death'], mode['four_point_fields'][0]['outer']], list(expected)) check('C329 preserved600 residuals/' + mode['binding'], [lookup['Noah birth', 'Flood start'], lookup['Shem birth', 'Shem death']], [140, 140]) check('C329 recorded finite counts', [len(d[329]['rows']), len(d[329]['phase_trials']), d[329]['counts']['exact_partitions']], [50, 400, 100]) matrix = [[F(v) for v in row] for row in d[330]['incidence_matrix']] cross = [] for a, b in d[330]['residual_edge_pairs']: v = [F(0)] * 10 v[a], v[b] = F(1), F(-1) cross.append(v) check('C330 recorded incidence rank', rank(matrix), 9) check('C330 recorded cycle rank', rank(d[330]['cycle_coefficients']), 4) check('C330 all25 existing residuals add rank0', rank(matrix + cross) - rank(matrix), 0) check('C330 common translation null direction', all(sum(row) == 0 for row in matrix), True) check('C330 two mode consistency', all(r['rank'] == 9 and r['augmented_rank'] == 9 and r['nullity'] == 1 and r['cycle_rank'] == 4 for r in d[330]['modes']), True) check('C330 inherited600 field transport', all([a - b for a, b in zip(r['birth_field'], r['Flood_death_field'])] == [600] * 4 for r in d[330]['modes']), True) check('C330 recorded2048 phases and4 successes', [sum(len(r['phase_trials']) for r in d[330]['modes']), sum(p['all13_edges_exact'] for r in d[330]['modes'] for p in r['phase_trials'])], [2048, 4]) check('C331 complete four-index domain retained', sorted(r['i'] for r in d[331]['rows']), [2, 3, 4, 5]) check('C331 allfour950/108/2K', all([r['Noah_life'], r['death_to_MT_Flood'], r['total_2K']] == [950, 108, 1058] for r in d[331]['rows']), True) check('C331 primary/companion source partitions', all(r['adjacent_legs'] == ([460, 490, 108] if r['rail'] == 'primary' else [459, 491, 108]) for r in d[331]['rows']), True) check('C331 actual source death and MT birth roles', all(r['records']['D']['tradition'] == 'SP' and r['records']['D']['rail'] == r['rail'] and r['records']['M']['tradition'] == 'MT' and r['records']['M'].get('rail') is None for r in d[331]['rows']), True) check('C331 missing companion MT remains absent', all(bool(r['N_minus460_MT_Noah_matches']) == (r['rail'] == 'primary') for r in d[331]['rows']), True) check('C331 only retained LXX Noah aliases', sum(len(r['coincident_LXX_Noah_labels']) for r in d[331]['rows']), 2) check('C331 phase inventory', [len(d[331]['phase_trials']), d[331]['counts']['exact_components']], [64, 8]) check('C332 retained control scope', [len(d[332]['rows']), sorted(set(r['i'] for r in d[332]['rows']))], [20, [3, 4, 5, 6, 7]]) check('C33214source-admitted controls', sum(r['joint_admitted'] for r in d[332]['rows']), 14) check('C332 death108 is b2 only', all(r['has950_108'] == (r['b'] == 2) and r['death_to_R'] == 110 - r['b'] for r in d[332]['rows']), True) check('C332490 means primary rail in held menu', all(r['has490'] == (r['rail'] == 'primary') for r in d[332]['rows']), True) survivors = sorted((r['a'], r['b'], r['i']) for r in d[332]['both_survivors']) strong = sorted((r['a'], r['b'], r['i']) for r in d[332]['both_plus_two17K_survivors']) check('C332 newcriteria retain02 and22', survivors, [(0, 2, 3), (0, 2, 5), (2, 2, 3), (2, 2, 5)]) check('C332 stronger two17K conjunction conditional22', strong, [(2, 2, 3), (2, 2, 5)]) check('C332 allK companion remains despite failing490', [(r['a'], r['b'], r['i']) for r in d[332]['rows'] if r['joint_admitted'] and r['allK'] and not r['has490']], [(2, 2, 4)]) check('C332 no source selector or new endpoint', [d[332]['source_selector_established'], d[332]['new_endpoints_adopted']], [False, False]) claims = [ {'steps': ['C324'], 'claim': 'Positive local E completion rules retained; the particular three-way regular biography prescription remains unestablished in the bounded audit.', 'type': 'source-qualified positive finding and bounded negative finding'}, {'steps': ['C325', 'C326'], 'claim': 'Six admitted460+40=500 triples do not identify the full460|40|460 field with the File09 40|460|40 field.', 'type': 'finite endpoint arithmetic and exact metric distinction'}, {'steps': ['C327', 'C328'], 'claim': 'The complete positive residual ledger is40/140/490/640 in the selected context; Noah950 remainders are300/360/430/490 across the four admitted MT contexts.', 'type': 'dependent source-qualified residuals and context sensitivity'}, {'steps': ['C329'], 'claim': 'Noah490 and both140 relations survive the named500/502 binding change;40 becomes42 and640 becomes642.', 'type': 'bounded named-modal comparison'}, {'steps': ['C330'], 'claim': 'Rank9, four cycles, common translation freedom and25 rank-zero residual additions; paired fields share600 transport without merging source ancestry.', 'type': 'exact algebraic dependence, not witness independence'}, {'steps': ['C331'], 'claim': 'All four held SP2K paths admit950+108; actual MT intermediates give primary460+490+108 or companion459+491+108.', 'type': 'source-admitted partition of an existing2K relation'}, {'steps': ['C332'], 'claim': 'New criteria alone leave02/22 at i3/5; adding existing two17K leaves22 at i3/5 conditionally. The allK companion i4 remains valid without490.', 'type': 'finite conditional intersection and source-valid counterexample'} ] scopes = Counter(r['scope'] for r in checks) result = {'step': 'C333', 'status': 'passed', 'scope': 'Synthesis audit only; no domain expansion or new numbered research.', 'source_sha256': digest, 'authenticated_predecessors': authenticated, 'scientific_claim_ledger': claims, 'positive_source_findings_retained': d[324]['positive_findings'], 'bounded_source_verdict_retained': d[324]['bounded_source_verdict'], 'checks': checks, 'check_count': len(checks), 'checks_by_scope': dict(scopes), 'all_checks_passed': all(r['pass'] for r in checks), 'archive_audit_scope': 'ZIP integrity, upload receipts and package replays are handled by the separate archive audit, not asserted by this scientific review.', 'standing_controls': ['K=529; E=25/23; P=70/69', 'Global paired Mirror January AD1; local junction January AD2; no civil year zero', 'Regular Gears Noah/Shem/Flood only; SP person companions remain local; Flood close is a separate event boundary', 'Preserve source identity, modal binding, generated coordinates and cumulative ancestry distinctions'], 'canonical_or_graph_edits': False, 'new_independent_witness_claim': False, 'C334_executed': False} args.out.mkdir(parents=True, exist_ok=True) path = args.out / 'C333_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), 'checks_by_scope': dict(scopes), 'all_checks_passed': result['all_checks_passed'], 'C334_executed': False}, sort_keys=True)) if __name__ == '__main__': main()