#!/usr/bin/env python3 """C276 exact source-to-operator audit; standard library, no parameter scan.""" import argparse import hashlib import json from fractions import Fraction as Q from pathlib import Path ROOT = Path(__file__).resolve().parent.parent checks = [] def load(name): return json.loads((ROOT/name).read_text()) def sha(data): return hashlib.sha256(data).hexdigest() def check(name, condition): if not condition: raise AssertionError(name) checks.append(name) # Affine expressions have coefficients (constant,f,h). def af(c=0, f=0, h=0): return tuple(Q(x) for x in (c, f, h)) def add(a, b): return tuple(x+y for x, y in zip(a, b)) def neg(a): return tuple(-x for x in a) def sub(a, b): return add(a, neg(b)) def scale(k, a): return tuple(Q(k)*x for x in a) def fmt(a, names=("f", "h")): out = str(a[0]) if a[0] else "" for value, name in zip(a[1:], names): if value: term = name if abs(value) == 1 else str(abs(value))+"*"+name out += ("+" if value > 0 and out else "-" if value < 0 else "")+term return out or "0" def rec(a): return {"coefficients": [str(x) for x in a], "expression": fmt(a)} def aligned(a): return (a[0]+598*a[2], a[1]+a[2]) def evaluate(a, f, h): return a[0]+a[1]*f+a[2]*h def rref(rows, n=4): a = [[Q(v) for v in row] for row in rows] pivots = [] for col in range(n): start = len(pivots) found = next((r for r in range(start, len(a)) if a[r][col]), None) if found is None: continue a[start], a[found] = a[found], a[start] divisor = a[start][col] a[start] = [x/divisor for x in a[start]] for r in range(len(a)): if r != start: k = a[r][col] a[r] = [x-k*y for x, y in zip(a[r], a[start])] pivots.append(col) return a, pivots def dot(a, b): return sum(Q(x)*Q(y) for x, y in zip(a, b)) def main(out): manifest = load("SOURCE_MANIFEST.json") for name, meta in manifest.items(): data = (ROOT/"sources"/name).read_bytes() check("source digest and bytes: "+name, sha(data) == meta["sha256"] and len(data) == meta["bytes"]) cert = load("sources/C275_CERTIFICATE.json") check("C275 predecessor digest", manifest["C275_CERTIFICATE.json"]["sha256"] == "9f07d37f74b9bfb9e21984b5efa17fe53f22d545af152e208b21c629af3f7c47") for field, name in [ ("report_sha256", "C275_REPORT.md"), ("checkpoint_sha256", "C275_CHECKPOINT.md"), ("results_sha256", "C275_RESULTS.json"), ("supplemental_note_sha256", "C275_SUPPLEMENT.md"), ]: check("C275 certificate binding: "+name, cert[field] == manifest[name]["sha256"]) for prefix, items in [ ("C269", [("C269_RECTANGLE.json", "evidence/CLOSING_RECTANGLE.json"), ("C269_GRAPH_INCIDENCE.json", "evidence/GRAPH_INCIDENCE.json"), ("C269_PATHS.json", "evidence/SOURCE_PATHS.json")]), ("C270", [("C270_MAPS.json", "evidence/INDUCED_MAPS.json"), ("C270_TRANSPORT.json", "evidence/TRANSPORT_CERTIFICATE.json")]), ]: prior = {r["path"]: r for r in load("sources/"+prefix+"_ARTIFACT_MANIFEST.json")["files"]} for name, old_path in items: check("prior artifact binding: "+name, prior[old_path]["sha256"] == manifest[name]["sha256"]) rectangle = load("sources/C269_RECTANGLE.json") source_centers = rectangle["source_centers"] S, L = source_centers["Shem_close"], source_centers["Flood_close"] R, N = source_centers["SP_G3_Flood_start"], source_centers["SP_G3_primary_Noah_birth"] I = rectangle["internal598plus2"]["cumulative"] P = rectangle["internal598plus2"]["regular"] T = rectangle["translation"] check("six source nodes and17K fixed", (S, I, L, R, P, N, T) == (-5883, -5285, -5283, 3110, 3708, 3710, 8993)) check("T acts on all three retained centers", [q+T for q in (S, I, L)] == [R, P, N]) check("source598+2=600 on both sides", (I-S, L-I, L-S) == (P-R, N-P, N-R) == (598, 2, 600)) graph = load("sources/C127_GRAPH.json")["graph"] nodes = {r["id"]: r for r in graph["nodes"]} edges = {r["id"]: r for r in graph["duration_edges"]} check("standing graph size", (len(nodes), len(edges)) == (208, 382)) for edge_id, a, b, width in [ ("N04_598cum", S, I, 598), ("N04_17", I, P, 8993), ("N04_17opposite", S, R, 8993), ]: edge = edges[edge_id] check("selected stored duration: "+edge_id, edge["kind"] == "duration" and edge["width"] == width and nodes[edge["from"]]["signed_center"] == a and nodes[edge["to"]]["signed_center"] == b and b-a == width) check("interior source indices and regular identities", I-(-5290) == 5 and S-(-5890) == L-(-5290) == 7 and nodes["N04_s"]["gear"] == 2 and nodes["N04_s"]["companion"] == 0 and nodes["N04_r"]["gear"] == 3 and nodes["N04_r"]["close"] == 0) check("closing source not a stored C127 node", not any(r["signed_center"] == L for r in graph["nodes"])) closing_route = load("sources/C269_PATHS.json")["inherited_C254_closing_route"] check("retained closing route connects L to N", closing_route["centers"][0] == L and closing_route["centers"][-1] == N and sum(closing_route["widths"]) == T and closing_route["SP_Noah_source"]["rail"] == "primary" and closing_route["SP_Noah_source"]["gear"] == 3) F = lambda q: af(q, 1, 0) H = lambda q: af(q, 0, 1) G = lambda q: af(-q, 0, -1) RN = lambda y: af(y-T, 1, 0) RF = lambda y: af(T-y, 0, -1) phase_rows = [] for name, q, y, role in [ ("S", S, R, "Shem / regular G3 Flood start"), ("I", I, P, "Flood interior / regular G2 primary Noah"), ("L", L, N, "Flood closing / regular G3 primary Noah"), ]: c_map, r_map = (G, RF) if name == "S" else (F, RN) local = [] for epsilon in (-Q(1, 4), Q(1, 4)): check(f"{name} phase{epsilon}: T and both routes commute", q+epsilon+T == y+epsilon and c_map(q+epsilon) == r_map(y+epsilon)) local.append(c_map(q+epsilon)) phase_rows.append({ "source_id": name, "roles": role, "source_offset": str(epsilon), "cumulative_component": str(q+epsilon), "reflected_regular_component": str(y+epsilon), "local_image_via_either_route": rec(c_map(q+epsilon)), "map_reverses_order": name == "S", }) check(name+" preserves physical halfyear magnitude", sub(local[1], local[0]) == af(-Q(1, 2) if name == "S" else Q(1, 2))) for epsilon in (-Q(1, 4), Q(0), Q(1, 4)): check("cross-index image-alignment residual, phase"+str(epsilon), sub(H(S+epsilon), F(I+epsilon)) == af(-598, -1, 1)) check("global-pair and local-pair residuals agree, phase"+str(epsilon), add(F(I+epsilon), G(S+epsilon)) == sub(add(F(L+epsilon), G(S+epsilon)), af(2)) == af(598, 1, -1)) # x=(f,h,alpha,beta), RN(y)=y+alpha, RF(y)=-y+beta. # Both Flood records and both components give the same first row. transport_rows = [[-1, 0, 1, 0, -T], [0, 1, 0, 1, T]] X = [-1, 1, 0, 0, 598] reduced0, pivots0 = rref(transport_rows) reducedX, pivotsX = rref(transport_rows+[X]) check("source transport rank two with two free parameters", len(pivots0) == 2) check("alignment adds exactly one independent constraint", len(pivotsX) == 3) null0 = [[1, 0, 1, 0], [0, 1, 0, -1]] for k, v in enumerate(null0): check("source transport null direction"+str(k), all(dot(row[:4], v) == 0 for row in transport_rows)) check("increment varies while source transport is preserved", [dot([-1, 1, 0, 0], v) for v in null0] == [-1, 1]) nullX = [1, 1, 1, -1] check("aligned common-translation freedom survives", all(dot(row[:4], nullX) == 0 for row in transport_rows+[X])) check("aligned freedom leaves increment fixed", dot([-1, 1, 0, 0], nullX) == 0) delta = af(0, -1, 1) alignment_residual = sub(H(S), F(I)) midpoint598 = scale(Q(1, 2), add(F(I), G(S))) midpoint600 = scale(Q(1, 2), add(F(L), G(S))) check("alignment is precisely delta-598", alignment_residual == sub(delta, af(598))) check("two image midpoints differ by one for every f,h", sub(midpoint600, midpoint598) == af(1)) check("global598 pair condition and fixedJ1 condition are equivalent", add(F(I), G(S)) == sub(add(F(L), G(S)), af(2)) == neg(alignment_residual)) check("aligned three-point form with p=f-5285", aligned(F(I)) == aligned(H(S)) == (Q(-5285), Q(1)) and aligned(G(S)) == (Q(5285), Q(-1)) and aligned(F(L)) == (Q(-5283), Q(1))) check("aligned600-pair midpoint is fixed at1", aligned(midpoint600) == (Q(1), Q(0))) check("alignment leaves its common image unfixed", aligned(F(I))[1] != 0) check("general regular600-pair sum is600-delta", add(RN(N), RF(R)) == sub(af(600), delta)) # Recover the inherited baseline for comparison only, not as a solution fit. old = load("sources/C270_MAPS.json") f0 = Q(old["cumulative_Flood_map"][1]) h0 = -Q(old["cumulative_reflected_Shem_map"][1]) alpha0 = Q(old["regular_reflected_Noah_map"][1]) beta0 = Q(old["regular_reflected_Flood_map"][1]) reference = [f0, h0, alpha0, beta0] check("reference baseline is original C270 maps", reference == [5290, 5888, -3703, 3105]) check("reference satisfies source transport and alignment", all(dot(row[:4], reference) == row[4] for row in transport_rows+[X])) check("reference local image centers and increment", [evaluate(v, f0, h0) for v in [F(I), H(S), G(S), F(L)]] == [5, 5, -5, 7] and h0-f0 == 598) transport = load("sources/C270_TRANSPORT.json") check("reference intermediate binding agrees with prior transport", transport["intermediate"]["cumulative"] == str(I) and transport["intermediate"]["regular_reflected"] == str(P) and transport["intermediate"]["local"] == 5) # The MT join is a diagnostic only: (m-5289)=5889-(m+delta). check("MT join unreduced constant and old598 reduction", 5289+5889 == 11178 and 11178-598 == 10580 and 11178-2*5290 == 598) source_register = { "source_correspondence": T, "K_units": 17, "cumulative": [{"id": "S", "center": S, "role": "LXX OFF Shem closing", "index": 7}, {"id": "I", "center": I, "role": "LXX OFF Flood interior", "index": 5}, {"id": "L", "center": L, "role": "LXX OFF Flood closing", "index": 7}], "reflected_regular": [{"id": "R", "center": R, "role": "SP G3 Flood start"}, {"id": "P", "center": P, "role": "SP G2 primary Noah birth"}, {"id": "N", "center": N, "role": "SP G3 primary Noah birth"}], "parallel_widths": [598, 2, 600], "selected_stored_edges": [edges[k] for k in ["N04_598cum", "N04_17", "N04_17opposite"]], "closing_route": closing_route, "new_source_identity_or_graph_edge": False, } constraints = { "variable_order": ["f", "h", "alpha", "beta"], "transport_equations": ["alpha=f-8993", "beta=8993-h"], "source_only": {"augmented_rows": transport_rows, "rank": len(pivots0), "degrees_of_freedom": 4-len(pivots0), "rref": [[str(v) for v in r] for r in reduced0], "null_basis": null0, "delta_determined": False}, "with_explicit_alignment_X": { "condition": "H(S)=F(I)", "additional_augmented_row": X, "rank": len(pivotsX), "degrees_of_freedom": 4-len(pivotsX), "rref": [[str(v) for v in r] for r in reducedX], "null_basis": [nullX], "delta": 598, "f_remains_free": True}, "reference_only": {"original_C270_vector": [str(v) for v in reference], "not_imposed_in_source_only_solve": True}, "MT_join_not_imposed": "2m+delta=11178; the old2m=10580 already substitutes delta598", "parameter_policy": "formalQ; integer translations for inherited annual-center phase labels", } identities = { "affine_coefficient_order": ["constant", "f", "h"], "delta": rec(delta), "X_residual": rec(alignment_residual), "cross_index598_image_midpoint": rec(midpoint598), "matched_index600_image_midpoint": rec(midpoint600), "midpoint_difference": "1", "equivalent_conditions": [ "H(S)=F(I)", "G(S)=M(F(I))", "h-f=598", "G(S)=2-F(L)", "RN(P)+RF(R)=0", "RN(N)+RF(R)=2"], "aligned_three_point_form": {"p": "f-5285", "F(I)=H(S)": "p", "G(S)": "-p", "F(L)": "p+2"}, "aligned_global_pair": ["p", "-p"], "aligned_local_J1_pair": ["p+2", "-p"], "selected_local_radius": "|p+1|", "baseline_p": "5, retained reference only", "general_matched_source600_identity": "RF(y-600)=600-delta-RN(y)", "no_new_adopted_global_axis": True, } assumptions = { "source_facts": ["source coordinates and roles", "I-S=P-R=598", "L-I=N-P=2", "L-S=N-R=600", "T=q+8993"], "coordinate_conventions": ["M=-x about January AD1", "components center+/-1/4"], "unknown_maps": ["F=q+f", "H=q+h", "G=M(H)", "RN=y+alpha", "RF=-y+beta"], "transport_requirements": ["RN(T(q))=F(q) on Flood branch", "RF(T(q))=G(q) on Shem branch"], "additional_alignment_X": "Make the chosen cross-index source endpoints coincide after their different forward translations", "source_duration_does_not_itself_assert_X": True, "C270_fixed_intercepts_are_not_independent_inputs": "They were induced from the existing5290/5888 maps; freezing them would import the conclusion", "C274_reduced_MT_equation_must_not_be_used_as_raw_input": True, "C271_fixedJ1_match_counts_not_extended_to_free_delta": True, "coincident_images_do_not_identify_source_events": True, "no_inference_of_all_profile_increment_necessity_from_one_rectangle": True, "strongest_unresolved_item": "Why the tagged cross-index alignment X should be required beyond its coherent role in the declared construction", "next_proposed_step": "C277: extend the same alignment across the existing six C271 bindings, checking source-index boundaries and counterpart availability without adding source events", "next_step_executed": False, } results = { "step": "C276", "status": "passed", "check_count": len(checks), "checks": checks, "frozen_inputs": len(manifest), "source_nodes": 6, "physical_source_pairs": 6, "case_ranks": [len(pivots0), len(pivotsX)], "case_freedoms": [2, 1], "delta_fixed_by_source_transport_alone": False, "delta_uniquely598_given_X": True, "absolute_landing_fixed_by_X": False, "free_parameter_chosen": False, "new_source_event_or_parameter_scan": False, "historical_campaigns_rerun": 0, "canonical_or_graph_edits": False, "new_independent_review": False, "next_step_executed": False, } outputs = {"SOURCE_REGISTER.json": source_register, "TRANSPORT_CONSTRAINTS.json": constraints, "ALIGNMENT_IDENTITIES.json": identities, "PHASE_LEDGER.json": phase_rows, "ASSUMPTION_LEDGER.json": assumptions, "RESULTS.json": results} out.mkdir(parents=True, exist_ok=True) for name, data in outputs.items(): (out/name).write_text(json.dumps(data, ensure_ascii=False, indent=2)+"\n") print(json.dumps({"status": "passed", "checks": len(checks), "generated_outputs": len(outputs), "case_ranks": [len(pivots0), len(pivotsX)]})) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--out", type=Path, required=True) main(parser.parse_args().out)