Research-Stack/4-Infrastructure/hardware/standard_model_12_to_4_reduction.py
Devin AI 0c9efac330 chore(consolidation): integrate E8Sidon stack (PRs #79 #80 #81 #89) into one PR
Squash the four overlapping feature branches into a single change set against
main, eliminating cross-PR merge conflicts and the duplicated CI-fix scripts.

What this brings in (merge order #79 -> #80 -> #81 -> #89):
- #79 refactor(infra): shared utilities (4-Infrastructure/lib/*: q16, hashing,
  jsonl, fraction_utils) + the scripts/math-first/* validators that the
  math-check CI requires.
- #80 feat(lean): Semantics.E8Sidon (1025 lines) -- Eisenstein coefficient
  identity E4^2 = E8 and the Sidon framework. E4_sq_eq_E8_coeff is fully proved
  (all Fourier-coefficient extraction machine-checked); the single residual gap
  is pinned to E4_sq_eq_E8_qExpansion (Mathlib lacks the valence formula /
  dim M8 = 1). 4 sorries + 1 axiom (e8_additive_completeness), all TODO(lean-port).
- #81 refactor(lean): Float-free FixedPoint core (integer-only sqrt/log2/expNeg).
  E8Sidon.lean kept at #80's final 1025-line version (the #81 intermediate
  438-line copy was overridden by merge order).
- #89 feat(lean): Semantics.RRC.PolyFactorIdentity -- short-sleeve polynomial
  detection at the zerocopy limb boundary; now imports Semantics.E8Sidon for
  sigma3/sigma7/convolutionLHS (single source of truth) instead of inlining them.

Conflict resolution:
- flake.nix -> canonical rs-surface removal (Garnix shutdown).
- scripts/math-first/* -> byte-identical across branches, clean.
- .cursorrules / AGENTS.md -> unified; baselines + sorry inventory refreshed.

Verification:
- lake build (default aggregator): 3573 jobs, 0 errors.
- lake build Semantics.RRC.PolyFactorIdentity (E8Sidon + FixedPoint + PolyFactor):
  3655 jobs, 0 errors. Witnesses verified (sigma7 4 = 16513, convolutionLHS 6 = 2350).
- Python tests: 68/68 pass.

Note: the "Workers Builds: researchstack" check is a preexisting external
Cloudflare build unrelated to this change (no branch touches 4-Infrastructure/cloudflare/).

Build: 3573 jobs (default), 3655 jobs (narrow), 0 errors
Co-Authored-By: Allaun Silverfox <bigdataiscoming+9i37y6j2@protonmail.com>
2026-06-16 02:01:31 +00:00

347 lines
13 KiB
Python

#!/usr/bin/env python3
"""Reduce the extracted Standard Model Lagrangian term axes from 12 to 4.
The input is the symbolic term-family centroid from
standard_model_lagrangian_exact_average.py. This is a compression/control-plane
projection, not a physical reduction of the Standard Model.
The four target primitives are the local OTOM primitives:
* field - value/density surface
* shear - gradient, coupling, torsion, transformation
* packet - localized event/witness/claim-like object
* spectral - eigenmode, covariance, resonance, residual spectrum
Because a 12 -> 4 projection is lossy, this runner also emits the exact 12D
residual lane required to rehydrate the symbolic centroid byte-for-byte at the
rational-coordinate level.
"""
from __future__ import annotations
import argparse
import json
from datetime import datetime, timezone
from fractions import Fraction
from pathlib import Path
from typing import Any
import sys
REPO = Path(__file__).resolve().parents[2]
sys.path.insert(0, str(REPO / "4-Infrastructure"))
from lib.hashing import sha256_bytes
from lib.fraction_utils import fraction_json, fraction_str, parse_fraction_json, vector_json
from lib.jsonl import load_json, stable_json
AVERAGE_RECEIPT = (
REPO
/ "4-Infrastructure"
/ "hardware"
/ "standard_model_lagrangian_exact_average_receipt.json"
)
SIGNED_AXIS_RECEIPT = (
REPO
/ "4-Infrastructure"
/ "hardware"
/ "standard_model_signed_axis_graph_receipt.json"
)
OUT = (
REPO
/ "4-Infrastructure"
/ "hardware"
/ "standard_model_12_to_4_reduction_receipt.json"
)
PRIMITIVES = ("field", "shear", "packet", "spectral")
# Row-stochastic projection matrix from unreduced term-family axes to the four
# local primitives. Rows intentionally sum to exactly 1.
PROJECTION: dict[str, dict[str, Fraction]] = {
"su3_gluon_field": {
"field": Fraction(1, 2),
"spectral": Fraction(1, 2),
},
"nonabelian_self_interaction": {
"shear": Fraction(1, 3),
"spectral": Fraction(2, 3),
},
"electroweak_charged_w": {
"field": Fraction(1, 3),
"shear": Fraction(1, 3),
"spectral": Fraction(1, 3),
},
"electroweak_neutral_za": {
"field": Fraction(1, 2),
"spectral": Fraction(1, 2),
},
"higgs_goldstone_scalar": {
"field": Fraction(1, 2),
"shear": Fraction(1, 2),
},
"scalar_potential": {
"field": Fraction(1, 2),
"spectral": Fraction(1, 2),
},
"fermion_quark_sector": {
"field": Fraction(1, 3),
"packet": Fraction(2, 3),
},
"fermion_lepton_sector": {
"field": Fraction(1, 3),
"packet": Fraction(2, 3),
},
"yukawa_mass_coupling": {
"shear": Fraction(1, 4),
"packet": Fraction(1, 2),
"spectral": Fraction(1, 4),
},
"charged_current_ckm": {
"shear": Fraction(1, 4),
"packet": Fraction(1, 2),
"spectral": Fraction(1, 4),
},
"ghost_gaugefix_sector": {
"shear": Fraction(1, 2),
"packet": Fraction(1, 2),
},
"derivative_kinetic_flow": {
"shear": Fraction(2, 3),
"spectral": Fraction(1, 3),
},
}
def centroid_from_average(receipt: dict[str, Any]) -> dict[str, Fraction]:
centroid: dict[str, Fraction] = {}
for item in receipt["rational_average"]["centroid_components"]:
centroid[item["node"]] = parse_fraction_json(item["centroid_component"])
return centroid
def projection_json() -> dict[str, dict[str, dict[str, Any]]]:
return {
node: {
primitive: fraction_json(weight)
for primitive, weight in weights.items()
}
for node, weights in PROJECTION.items()
}
def validate_projection(nodes: list[str]) -> list[str]:
errors: list[str] = []
missing = sorted(set(nodes) - set(PROJECTION))
extra = sorted(set(PROJECTION) - set(nodes))
if missing:
errors.append(f"missing projection rows: {missing}")
if extra:
errors.append(f"extra projection rows: {extra}")
for node in nodes:
row = PROJECTION.get(node, {})
row_sum = sum(row.values(), Fraction(0))
unknown = sorted(set(row) - set(PRIMITIVES))
if row_sum != 1:
errors.append(f"{node} projection row sums to {fraction_str(row_sum)}, not 1")
if unknown:
errors.append(f"{node} projection row has unknown primitives: {unknown}")
return errors
def project_12_to_4(centroid: dict[str, Fraction]) -> dict[str, Fraction]:
reduced = {primitive: Fraction(0) for primitive in PRIMITIVES}
for node, mass in centroid.items():
for primitive, weight in PROJECTION[node].items():
reduced[primitive] += mass * weight
return reduced
def lift_4_to_12(reduced: dict[str, Fraction]) -> dict[str, Fraction]:
"""A deterministic canonical lift from 4D to 12D.
This lift distributes each primitive's mass back over all term axes that
participated in that primitive, proportional to the same projection row
weight. It is deliberately not claimed to be the original graph. The
residual lane below is what makes exact rehydration possible.
"""
support_weight_sum = {primitive: Fraction(0) for primitive in PRIMITIVES}
for row in PROJECTION.values():
for primitive, weight in row.items():
support_weight_sum[primitive] += weight
lifted = {node: Fraction(0) for node in PROJECTION}
for node, row in PROJECTION.items():
for primitive, weight in row.items():
lifted[node] += reduced[primitive] * weight / support_weight_sum[primitive]
return lifted
def signed_l1(vector: dict[str, Fraction]) -> Fraction:
return sum((abs(value) for value in vector.values()), Fraction(0))
def ranked_abs_vector(vector: dict[str, Fraction], limit: int = 8) -> list[dict[str, Any]]:
ranked = sorted(vector.items(), key=lambda item: abs(item[1]), reverse=True)
return [
{
"axis": key,
"value": fraction_json(value),
"absolute": fraction_json(abs(value)),
}
for key, value in ranked[:limit]
]
def build_receipt() -> dict[str, Any]:
average = load_json(AVERAGE_RECEIPT)
signed_axis = load_json(SIGNED_AXIS_RECEIPT) if SIGNED_AXIS_RECEIPT.exists() else {}
nodes = average["source"]["nodes"]
projection_errors = validate_projection(nodes)
if projection_errors:
raise ValueError("; ".join(projection_errors))
centroid = centroid_from_average(average)
reduced = project_12_to_4(centroid)
reduced_mirror = {primitive: -value for primitive, value in reduced.items()}
reduced_closure = {
primitive: reduced[primitive] + reduced_mirror[primitive]
for primitive in PRIMITIVES
}
lifted = lift_4_to_12(reduced)
residual = {
node: centroid[node] - lifted[node]
for node in nodes
}
rehydrated = {
node: lifted[node] + residual[node]
for node in nodes
}
rehydration_delta = {
node: rehydrated[node] - centroid[node]
for node in nodes
}
residual_mirror = {node: -value for node, value in residual.items()}
residual_closure = {
node: residual[node] + residual_mirror[node]
for node in nodes
}
reduced_total = sum(reduced.values(), Fraction(0))
lifted_total = sum(lifted.values(), Fraction(0))
centroid_total = sum(centroid.values(), Fraction(0))
receipt = {
"schema": "standard_model_12_to_4_reduction_receipt_v1",
"generated_utc": datetime.now(timezone.utc).isoformat(),
"surface_id": "standard_model_12_to_4_reduction",
"source": {
"average_receipt": str(AVERAGE_RECEIPT.relative_to(REPO)),
"average_stable_hash_sha256": average.get("stable_average_hash_sha256"),
"signed_axis_receipt": str(SIGNED_AXIS_RECEIPT.relative_to(REPO)),
"signed_axis_stable_hash_sha256": signed_axis.get("stable_graph_hash_sha256"),
"nodes": nodes,
},
"primitive_basis": {
"field": "density/value surface coordinate",
"shear": "gradient, coupling, torsion, and transformation coordinate",
"packet": "localized event, witness, claim, or receipt coordinate",
"spectral": "eigenmode, covariance, resonance, and residual-spectrum coordinate",
},
"projection_matrix_12_to_4": projection_json(),
"projection_law": {
"row_stochastic": True,
"row_sum": "1",
"meaning": (
"Every unreduced term-family axis contributes all of its centroid "
"mass into the four-primitives control basis."
),
},
"visible_centroid_12d": vector_json(centroid),
"visible_reduced_4d": vector_json(reduced),
"reduced_4d_total": fraction_json(reduced_total),
"mirror_reduced_4d": vector_json(reduced_mirror),
"mirror_closure_4d": {
"closed": all(value == 0 for value in reduced_closure.values()),
"l1_error": fraction_json(signed_l1(reduced_closure)),
"components": vector_json(reduced_closure),
},
"canonical_lift_4d_to_12d": {
"lift_rule": (
"Distribute each primitive mass back over supporting term axes "
"proportional to the projection row weight."
),
"lifted_centroid_12d": vector_json(lifted),
"lifted_total": fraction_json(lifted_total),
},
"residual_lane_12d": {
"meaning": (
"Exact rational sidecar required to reconstruct the original "
"12-axis centroid after the lossy 12-to-4 projection."
),
"residual": vector_json(residual),
"residual_l1": fraction_json(signed_l1(residual)),
"top_residual_axes": ranked_abs_vector(residual),
"mirror_residual": vector_json(residual_mirror),
"mirror_residual_closure": {
"closed": all(value == 0 for value in residual_closure.values()),
"l1_error": fraction_json(signed_l1(residual_closure)),
},
},
"exact_rehydration": {
"closed": all(value == 0 for value in rehydration_delta.values()),
"l1_error": fraction_json(signed_l1(rehydration_delta)),
"centroid_total": fraction_json(centroid_total),
"rehydrated_total": fraction_json(sum(rehydrated.values(), Fraction(0))),
},
"claim_boundary": (
"This is a symbolic compression projection over the extracted "
"term-family graph. It is not a physical Standard Model reduction, "
"renormalization result, hidden-particle claim, or new equation of "
"motion."
),
"lawful": True,
}
stable_preimage = stable_json({
"schema": receipt["schema"],
"surface_id": receipt["surface_id"],
"source": receipt["source"],
"primitive_basis": receipt["primitive_basis"],
"projection_matrix_12_to_4": receipt["projection_matrix_12_to_4"],
"projection_law": receipt["projection_law"],
"visible_centroid_12d": receipt["visible_centroid_12d"],
"visible_reduced_4d": receipt["visible_reduced_4d"],
"mirror_closure_4d": receipt["mirror_closure_4d"],
"canonical_lift_4d_to_12d": receipt["canonical_lift_4d_to_12d"],
"residual_lane_12d": receipt["residual_lane_12d"],
"exact_rehydration": receipt["exact_rehydration"],
"claim_boundary": receipt["claim_boundary"],
"lawful": receipt["lawful"],
}).encode("utf-8")
receipt["stable_reduction_hash_sha256"] = sha256_bytes(stable_preimage)
receipt["receipt_hash_preimage_sha256"] = sha256_bytes(stable_json(receipt).encode("utf-8"))
return receipt
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--out", type=Path, default=OUT)
args = parser.parse_args()
receipt = build_receipt()
args.out.parent.mkdir(parents=True, exist_ok=True)
args.out.write_text(json.dumps(receipt, indent=2, sort_keys=True), encoding="utf-8")
print(json.dumps({
"lawful": receipt["lawful"],
"stable_reduction_hash_sha256": receipt["stable_reduction_hash_sha256"],
"receipt_hash_preimage_sha256": receipt["receipt_hash_preimage_sha256"],
"visible_reduced_4d": receipt["visible_reduced_4d"],
"mirror_closure_4d": receipt["mirror_closure_4d"]["closed"],
"residual_l1": receipt["residual_lane_12d"]["residual_l1"],
"exact_rehydration": receipt["exact_rehydration"]["closed"],
}, indent=2, sort_keys=True))
return 0
if __name__ == "__main__":
raise SystemExit(main())