"""Independent exact review. Run from any directory; writes only review evidence.
Uses determinant minors for rank and exhaustive finite residues for affine
domains; imports none of the production/preparation algebra helpers.
"""
from pathlib import Path
from fractions import Fraction as F
from itertools import combinations, product
from math import gcd
from functools import reduce
import hashlib
import json
BASE = Path(__file__).resolve().parents[3]
CYCLE = BASE / "c932_c1131"
HERE = Path(__file__).resolve().parent
E, P, J = F(25, 23), F(70, 69), F(300, 299)
KEYS = dict(E=E, P=P, J=J)
UNITS = dict(E=336, P=360, J=364)
checks = []
def clean(value):
if isinstance(value, F):
return value.numerator if value.denominator == 1 else str(value)
if isinstance(value, dict):
return {str(k): clean(v) for k, v in value.items()}
if isinstance(value, (list, tuple)):
return [clean(x) for x in value]
return value
def check(name, actual, expected=True):
a, b = clean(actual), clean(expected)
checks.append(dict(name=name, passed=a == b, actual=a, expected=b))
def read_model(name):
return json.loads((CYCLE / "model" / (name + ".json")).read_text())
def det(a):
if not a:
return F(1)
if len(a) == 1:
return F(a[0][0])
return sum(((-1) ** j * F(a[0][j]) * det([
row[:j] + row[j + 1:] for row in a[1:]
]) for j in range(len(a))), F(0))
def rank(a):
for n in range(min(len(a), len(a[0])), 0, -1):
for rows in combinations(range(len(a)), n):
for cols in combinations(range(len(a[0])), n):
if det([[a[r][c] for c in cols] for r in rows]):
return n
return 0
def cramer(a, b):
denominator = det(a)
return [det([[b[r] if c == j else a[r][c]
for c in range(len(a))] for r in range(len(a))]) / denominator
for j in range(len(a))]
def staged(k1, k2, a, b, x):
y = a + k1 * (x - a)
return y, b + k2 * (y - b)
def exhaustive_domain(k1, k2, a, b):
"""Enumerate one guaranteed period directly, without modular inversion.
q1*q2 is a period because moving x by it changes the first output
by p1*q2 and the second by p1*p2. Only first-stage integer candidates
need evaluation. Cyclic spacings determine the least positive period.
"""
q1, q2 = k1.denominator, k2.denominator
period_bound = q1 * q2
valid = []
for x in range(a % q1, period_bound, q1):
y, z = staged(k1, k2, a, b, x)
assert y.denominator == 1
if z.denominator == 1:
valid.append(x)
if not valid:
return {"nonempty": False}, []
spacings = [valid[i + 1] - valid[i] for i in range(len(valid) - 1)]
spacings.append(valid[0] + period_bound - valid[-1])
assert len(set(spacings)) == 1
period = spacings[0]
return dict(nonempty=True, residue=valid[0] % period, period=period), valid
journal = json.loads((CYCLE / "journal.json").read_text())
records = {r["step"]: r for r in journal if 984 <= r["step"] <= 1007}
check("24 completed records", sorted(records), list(range(984, 1008)))
packet = json.loads((HERE / "sourcepacket.json").read_text())
for name, info in packet["sources"].items():
check("source hash " + name,
hashlib.sha256(Path(info["path"]).read_bytes()).hexdigest(), info["sha256"])
for n, excerpt in enumerate(packet["excerpts"], 1):
source = Path(packet["sources"][excerpt["source"]]["path"])
lo, hi = excerpt["lines"]
check("literal source excerpt " + str(n),
"\n".join(source.read_text().splitlines()[lo - 1:hi]), excerpt["text"])
artifact_bindings = []
def bind_artifacts(value):
if isinstance(value, dict):
if {"path", "sha256", "bytes"} <= value.keys():
data = (CYCLE / value["path"]).read_bytes()
check("artifact binding " + value["path"],
[hashlib.sha256(data).hexdigest(), len(data)],
[value["sha256"], value["bytes"]])
artifact_bindings.append(value)
for v in value.values():
bind_artifacts(v)
elif isinstance(value, list):
for v in value:
bind_artifacts(v)
for r in records.values():
bind_artifacts(r["results"])
inputs = read_model("key_constraint_inputs")
check("C984 calendars", inputs["calendar_measures"], [336, 360, 364])
check("C984 source fractions", inputs["allocation_fractions"], ["1/6", "1/26"])
check("C984 pivot packet", inputs["pivots"], [14006, 4836])
check("C984 covenant parts", inputs["Covenant_parts"], [299, 161])
for label, a, b, expected in [
("C985", [[336, -360], [1, -6]], [0, -5], [E, P]),
("C986", [[336, -364], [1, -26]], [0, -25], [E, J]),
]:
r = records[int(label[1:])]["results"]
check(label + " determinant", det(a), r["determinant"])
check(label + " Cramer solution", cramer(a, b), expected)
check(label + " stored solution", r["solution"], expected)
basis = read_model("key_calibration_basis")
A, rhs = basis["matrix"], basis["rhs"]
dep = basis["dependence"]
check("C987 rank by all minors", rank(A), 3)
check("C987 augmented rank by all minors", rank([r + [b] for r, b in zip(A, rhs)]), 3)
check("C987 exact left dependency including constants",
[sum(dep[r] * (A[r] + [rhs[r]])[c] for r in range(4)) for c in range(4)], [0] * 4)
check("C987 dependency primitive", reduce(gcd, dep), 1)
check("C987 every three-row constraint set independent",
[rank([A[i] for i in rows]) for rows in combinations(range(4), 3)], [3] * 4)
check("C987 first three-row solution", cramer(A[:3], rhs[:3]), [E, P, J])
check("C988 calibration-only rank", rank(A[:2]), 2)
K = F(8400, 23)
check("C988 common volume", [E * 336, P * 360, J * 364], [K] * 3)
check("C988 free family satisfies homogeneous calibration",
[sum(F(v) / d for v, d in zip(row, (336, 360, 364))) for row in A[:2]], [0, 0])
check("C989 implied allocation", (J - 1) / (E - 1), F(1, 26))
control = cramer([[336, -364], [1, -25]], [0, -24])
check("C990 perturbed E", control[0], F(312, 287))
check("C990 perturbation difference", control[0] - E, F(1, 6601))
allocs = [(P - 1) / (E - 1), (J - 1) / (P - 1), (J - 1) / (E - 1)]
check("C991 selection triangle", allocs, [F(1, 6), F(3, 13), F(1, 26)])
check("C991 selection fractions compose", allocs[0] * allocs[1], allocs[2])
check("C992 nested action", 1 + allocs[1] * ((1 + allocs[0] * (E - 1)) - 1), J)
check("C992 sequential action", P * J, F(7000, 6877))
check("C992 operations distinct", P * J != J)
# For a partition incidence C, each column has exactly one 1.
# Column i of C D - Dbar C is (k_i-k_block(i)) e_block(i).
coarsening_proof = {
"assumption": "C is the incidence map summing a declared partition into disjoint blocks",
"column_i": "(k_i-k_block(i)) times the block's coordinate vector",
"necessity": "A zero operator has every column zero; each fine factor equals its block factor",
"sufficiency": "The stated equalities make every column zero",
"limitation": "Agreement on one supplied weighted vector need not make every column zero",
}
source_parts = [F(805, 2), F(161, 2)]
partial = [source_parts[0], E * source_parts[1]]
uniform = [P * x for x in source_parts]
defect = [a - b for a, b in zip(partial, uniform)]
check("C994 partial image", partial, [F(805, 2), F(175, 2)])
check("C994 uniform image", uniform, [F(1225, 3), F(245, 3)])
check("C994 internal defect", defect, [F(-35, 6), F(35, 6)])
check("C994 same total", [sum(partial), sum(uniform), sum(defect)], [490, 490, 0])
check("C993 agreement does not commute universally", [1 - P, E - P] != [0, 0])
check("C994 general selected-last coefficient", (E - 1) * F(1, 6) * F(5, 6) * 483, F(35, 6))
B = [[1, 1], [P, 1], [E, 1]]
check("C995 measurement rank", rank(B), 2)
check("C995 native-P minor", det(B[:2]), F(-1, 69))
check("C995 dependent measurement", [sum(w * row[c] for w, row in zip([5, -6, 1], B)) for c in range(2)], [0, 0])
retained = []
for row, pair in zip(read_model("retained_part_complete_field"), [(690, 0), (690, 30), (690, 60), (9660, 2940)]):
totals = [u * pair[0] + v * pair[1] for u, v in B]
recovered = cramer(B[:2], totals[:2])
check("C996 complete totals " + str(pair), row["totals"], totals)
check("C996 inverse " + str(pair), recovered, pair)
check("C996 dependent residual " + str(pair), sum(w * t for w, t in zip([5, -6, 1], totals)), 0)
retained.append(dict(source_parts=pair, totals=totals, recovered=recovered))
domain_results = []
for stored in read_model("fixed_pivot_key_domains"):
n1, n2 = stored["pair"].split("→")
k1, k2 = KEYS[n1], KEYS[n2]
actual, witnesses = exhaustive_domain(k1, k2, 14006, 4836)
expected = {k: v for k, v in stored.items() if k not in ("pair", "gcd")}
check("C999 exhaustive domain " + stored["pair"], actual, expected)
g = gcd(k1.numerator, k2.denominator)
check("C998 existence criterion " + stored["pair"], actual["nonempty"], (4836 - 14006) % g == 0)
check("C999 gcd " + stored["pair"], g, stored["gcd"])
if actual["nonempty"]:
check("C998 period theorem " + stored["pair"], actual["period"], k1.denominator * k2.denominator // g)
substitutions = []
for n in [-2, 0, 3]:
x = actual["residue"] + n * actual["period"]
y, z = staged(k1, k2, 14006, 4836, x)
substitutions.append(dict(x=x, y=y, z=z))
check("C1000 exact stages " + stored["pair"] + " n=" + str(n), [y.denominator, z.denominator], [1, 1])
shifted, _ = exhaustive_domain(k1, k2, 14006 + 215, 4836 + 215)
check("C1002 translated coset " + stored["pair"], shifted,
dict(nonempty=True, residue=(actual["residue"] + 215) % actual["period"], period=actual["period"]))
x = actual["residue"] + 2 * actual["period"]
yz = staged(k1, k2, 14006, 4836, x)
yz2 = staged(k1, k2, 14006 + 215, 4836 + 215, x + 215)
check("C1002 both stage shifts " + stored["pair"], [v - u for u, v in zip(yz, yz2)], [215, 215])
else:
substitutions = []
domain_results.append(dict(pair=stored["pair"], **actual, exact_residues_in_q1q2_period=witnesses, substitutions=substitutions))
check("C1000 pivot difference obstruction", (4836 - 14006) % 3, 1)
for name, points, a, b, residue, placement in [
("C480", [2148, 3206], 3620, 2756, 32, True),
("fixed12026", [4114, 3056], 12026, 12026, 388, False),
]:
dom, _ = exhaustive_domain(E, E, a, b)
check("C1001 inherited domain " + name, dom, dict(nonempty=True, residue=residue, period=529))
check("C1001 width condition " + name, (points[1] - points[0]) % 529, 0)
check("C1001 placement condition " + name, (points[0] - residue) % 529 == 0, placement)
normal = read_model("key_full_field_normal_form")
heads = [14926, 14896, 14466, 14436, 14006]
gaps = [x - 14006 for x in heads]
mesh = reduce(gcd, gaps)
indices = [d // mesh for d in gaps]
images = [14006 + E * d for d in gaps]
check("C1003 source mesh and labels", [mesh, indices], [10, [92, 89, 46, 43, 0]])
check("C1003 exact full image", normal["images"], images)
check("C1003 image mesh", mesh * E, F(250, 23))
check("C1003 integral subset", [i for i, x in zip(indices, images) if x.denominator == 1], [92, 46, 0])
mixed_results = []
mixed_stored = read_model("mixed_calendar_complete_field")
check("C1004 complete ordered assignment field", [r["assignment"] for r in mixed_stored], list(product(KEYS, repeat=2)))
for row in mixed_stored:
names = row["assignment"]
outputs = [part * KEYS[n] for part, n in zip([299, 161], names)]
units = [UNITS[n] for n in names]
volumes = [value * unit for value, unit in zip(outputs, units)]
label = "".join(names)
check("C1004 outputs " + label, row["outputs"], outputs)
check("C1004 matching units " + label, row["units"], units)
check("C1004 component volumes " + label, volumes, [109200, 58800])
check("C1004 stored total and scalar sum " + label, [row["total_volume"], row["naked_sum"]], [sum(volumes), sum(outputs)])
mixed_results.append(dict(assignment=names, outputs=outputs, units=units, volumes=volumes, total=sum(volumes)))
matched, swapped = 300 * 364 + 175 * 336, 300 * 336 + 175 * 364
check("C1005 unit-label control", [300 + 175, matched, swapped, swapped - matched], [475, 168000, 164500, -3500])
remeasured = [F(matched, d) for d in UNITS.values()]
check("C1006 common-unit counts", remeasured, [500, F(1400, 3), F(6000, 13)])
check("C1006 uniform scalar images", remeasured, [460 * k for k in KEYS.values()])
qualifications = {
"backward_basis_not_independent_history": "not new evidence" in records[984]["finding"],
"source_cut_not_generated_by_fraction": "no source-appointed" in records[991]["finding"],
"numeric_inverse_does_not_restore_tags": "permission to use the route" in records[997]["results"]["not_recovered"],
"nine_affine_pairs_diagnostic": "not nine newly authorized" in records[999]["inputs"]["status"],
"congruence_representatives_not_dates": "not event dates" in records[999]["finding"],
"rational_mesh_not_new_calendar": "not a new historical calendar" in normal["status"],
"mixed_assignment_conditional": "conditional" in records[1004]["inputs"]["status"],
"nine_identities_not_independent_evidence": "not nine independent" in records[1004]["finding"],
"mixed_475_not_literal_elapsed_time": "does not reinterpret" in records[1006]["results"]["qualification"],
}
for name, present in qualifications.items():
check("scope qualifier " + name, present)
supp = packet["sources"]["SupplementA"]
supp_text = Path(supp["path"]).read_text()
section = supp_text.split("### 10.3 Cumulative calendar-body matrix", 1)[1].split("### 10.4", 1)[0]
check("source authority Supplement A section 10.3", all(x in section for x in ["9660+2940 = 12600", "12740", "13440", "4346−1406 = 2940"]))
observations = [
{
"severity": "nonblocking source-pointer clarification",
"records": [995, 996],
"finding": "The retained 9660|2940 family with totals 12600,12740,13440 is directly sourced in Supplement A §10.3. Latest File52c should not be cited as its controlling source.",
"controlling_path": supp["path"],
"controlling_sha256": supp["sha256"],
"lines": [2130, 2185],
"action": "Carry the source attribution forward explicitly; leave completed journal records and arithmetic intact.",
},
{
"severity": "wording precision",
"records": [1004, 1005, 1006],
"finding": "File60 supplies the 299|161 partition and the component branches 299→300 and161→175. The assembled475 comparison is inherited C533; cite that comparison rather than implying File60 directly appoints a literal mixed-calendar475 timeline.",
"action": "Retain the conditional unit interpretation already present in C1004–C1006 and name inherited C533 when discussing the mixed path.",
},
]
result = dict(
status="PASS_WITH_SOURCE_POINTER_CLARIFICATION" if all(c["passed"] for c in checks) else "FAIL",
review_scope="C984–C1007 exact calculations, full declared fields and source/diagnostic qualifications",
method="Independent standard-library Fraction calculations; recursive determinant/minor ranks; exhaustive finite residue classes; no root/preparation algebra imports",
script=str(Path(__file__).resolve()),
script_sha256=hashlib.sha256(Path(__file__).read_bytes()).hexdigest(),
check_count=len(checks),
pass_count=sum(c["passed"] for c in checks),
record_bindings=[dict(step=n, sha256=records[n]["sha256"]) for n in sorted(records)],
artifact_bindings=artifact_bindings,
source_bindings=packet["sources"],
coarsening_proof=coarsening_proof,
rank_basis=dict(matrix=A, rhs=rhs, rank=rank(A), left_dependency=dep, solution=[E, P, J]),
retained_measurements=retained,
exhaustive_affine_domains=domain_results,
mixed_unit_field=mixed_results,
observations=observations,
checks=checks,
)
out = CYCLE / "evidence" / "INDEPENDENT_C984_C1007.json"
out.write_text(json.dumps(clean(result), indent=2, ensure_ascii=False) + "\n")
print(json.dumps(dict(status=result["status"], checks=result["check_count"], passes=result["pass_count"], output=str(out))))
for c in checks:
if not c["passed"]:
print(json.dumps(c, ensure_ascii=False))
raise SystemExit(0 if result["status"].startswith("PASS") else 1)
Evidence
review C984 C1007.py
Linked sources and evidence
Edition and provenance
review_C984_C1007.py
SHA-256 57d7f3c906f3ed4c29655c853277a3912bd98b417b0356fbb84060200add3840
C480–C1634/Research_Cycles/C0932_C1131/prep/key_constraints/review_C984_C1007.py