Research-Stack/4-Infrastructure/hardware/standard_model_underverse_manifold_shape.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

235 lines
9.7 KiB
Python

#!/usr/bin/env python3
"""Manifold coordinate shape from visible/underverse Standard Model graph probes.
This builds a compact coordinate chart from:
- exact rational visible centroid
- exact underverse signed mirror
- targeted Q(phi) centroid displacement
- eigenvector sector axes
- complement residual mass
- antihydrogen gravity residual envelope as an external measured coordinate
It is a symbolic/compression manifold, not a physical spacetime manifold.
"""
from __future__ import annotations
import argparse
import json
import math
from datetime import datetime, timezone
from fractions import Fraction
from pathlib import Path
from typing import Any
from standard_model_lagrangian_eigen_probe import NODES
from standard_model_lagrangian_exact_average import QPhi, fraction_str
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
from lib.jsonl import stable_json
AVERAGE = REPO / "4-Infrastructure" / "hardware" / "standard_model_lagrangian_exact_average_receipt.json"
CLOSURE = REPO / "4-Infrastructure" / "hardware" / "standard_model_lagrangian_underverse_closure_receipt.json"
EIGEN = REPO / "4-Infrastructure" / "hardware" / "standard_model_lagrangian_eigen_probe_receipt.json"
OUT = REPO / "4-Infrastructure" / "hardware" / "standard_model_underverse_manifold_shape_receipt.json"
PHI = (1.0 + math.sqrt(5.0)) / 2.0
def file_hash(path: Path) -> str:
return sha256_bytes(path.read_bytes())
def frac_from_json(obj: dict[str, Any]) -> Fraction:
return Fraction(int(obj["numerator"]), int(obj["denominator"]))
def qphi_from_json(obj: dict[str, Any]) -> QPhi:
return QPhi(Fraction(obj["a"]), Fraction(obj["b"]))
def load_receipts() -> tuple[dict[str, Any], dict[str, Any], dict[str, Any]]:
return (
json.loads(AVERAGE.read_text(encoding="utf-8")),
json.loads(CLOSURE.read_text(encoding="utf-8")),
json.loads(EIGEN.read_text(encoding="utf-8")),
)
def visible_centroid(avg: dict[str, Any]) -> dict[str, Fraction]:
return {
item["node"]: frac_from_json(item["centroid_component"])
for item in avg["rational_average"]["centroid_components"]
}
def qphi_centroid(avg: dict[str, Any]) -> dict[str, QPhi]:
return {
item["node"]: qphi_from_json(item["centroid_component_qphi"])
for item in avg["qphi_targeted_average"]["centroid_components_qphi"]
}
def qphi_rational_delta(qphi: dict[str, QPhi], rational: dict[str, Fraction]) -> dict[str, QPhi]:
return {
node: qphi[node] - QPhi(rational[node], Fraction(0))
for node in NODES
}
def vector_norm(values: list[float]) -> float:
return math.sqrt(sum(value * value for value in values))
def build_shape() -> dict[str, Any]:
avg, closure, eigen = load_receipts()
rational = visible_centroid(avg)
mirror = {node: -value for node, value in rational.items()}
closure_sum = {node: rational[node] + mirror[node] for node in NODES}
qphi = qphi_centroid(avg)
delta = qphi_rational_delta(qphi, rational)
delta_values = [value.approx() for value in delta.values()]
rational_values = [float(rational[node]) for node in NODES]
mirror_values = [float(mirror[node]) for node in NODES]
no_phi = next(mode for mode in eigen["modes"] if mode["phi_mode"] == "none")
sector_phi = next(mode for mode in eigen["modes"] if mode["phi_mode"] == "sector_scale")
omni_phi = next(mode for mode in eigen["modes"] if mode["phi_mode"] == "omni")
top6_residual = frac_from_json(avg["rational_average"]["compressed_top_k"]["residual_mass"])
# ALPHA-g 2023 central residual as external measurement coordinate:
# a_hbar = (0.75 +/- sqrt(0.13^2 + 0.16^2)) g.
antihydrogen_residual = -0.25
antihydrogen_sigma = math.sqrt(0.13 * 0.13 + 0.16 * 0.16)
antihydrogen_z = antihydrogen_residual / antihydrogen_sigma
coordinates = {
"visible_norm_l2": vector_norm(rational_values),
"underverse_mirror_norm_l2": vector_norm(mirror_values),
"signed_closure_norm_l1": sum(abs(float(value)) for value in closure_sum.values()),
"signed_closure_exact_zero": all(value == 0 for value in closure_sum.values()),
"qphi_delta_norm_l2": vector_norm(delta_values),
"top6_residual_mass": fraction_json(top6_residual),
"eigen_gap_no_phi": no_phi["spectral_gap_proxy"],
"eigen_gap_sector_phi": sector_phi["spectral_gap_proxy"],
"eigen_gap_omni_phi": omni_phi["spectral_gap_proxy"],
"sector_phi_gap_lift": sector_phi["spectral_gap_proxy"] - no_phi["spectral_gap_proxy"],
"omni_phi_gap_lift": omni_phi["spectral_gap_proxy"] - no_phi["spectral_gap_proxy"],
"antihydrogen_gravity_residual_g": antihydrogen_residual,
"antihydrogen_gravity_sigma_g": antihydrogen_sigma,
"antihydrogen_gravity_z_score": antihydrogen_z,
}
dominant_axes = [
{
"axis": "visible_centroid",
"node": max(rational, key=lambda node: rational[node]),
"value": fraction_json(max(rational.values())),
},
{
"axis": "underverse_mirror",
"node": min(mirror, key=lambda node: mirror[node]),
"value": fraction_json(min(mirror.values())),
},
{
"axis": "qphi_delta",
"node": max(delta, key=lambda node: delta[node].approx()),
"value_qphi": delta[max(delta, key=lambda node: delta[node].approx())].as_json(),
},
{
"axis": "eigen_no_phi",
"node": no_phi["dominant_components"][0]["node"],
"value": no_phi["dominant_components"][0]["component"],
},
{
"axis": "eigen_sector_phi",
"node": sector_phi["dominant_components"][0]["node"],
"value": sector_phi["dominant_components"][0]["component"],
},
]
return {
"schema": "standard_model_underverse_manifold_shape_v1",
"coordinate_system": {
"description": "Symbolic compression manifold chart from visible graph, underverse mirror, phi displacement, residual mass, eigen axes, and antihydrogen residual envelope.",
"nodes": NODES,
"basis": [
"visible rational centroid",
"signed underverse mirror",
"targeted Q(phi) displacement",
"top-k residual mass",
"term-family eigen axes",
"external antihydrogen gravity residual coordinate",
],
},
"coordinates": coordinates,
"dominant_axes": dominant_axes,
"closure_inputs": {
"average_receipt": str(AVERAGE.relative_to(REPO)),
"average_hash": file_hash(AVERAGE),
"closure_receipt": str(CLOSURE.relative_to(REPO)),
"closure_hash": file_hash(CLOSURE),
"eigen_receipt": str(EIGEN.relative_to(REPO)),
"eigen_hash": file_hash(EIGEN),
"closure_exact": {
"complement_edge_closed": closure["complement_closure"]["edge_closure"]["closed_exactly"],
"annihilation_edge_closed": closure["annihilation_closure"]["edge_closure"]["closed_exactly"],
"annihilation_centroid_closed": closure["annihilation_closure"]["centroid_closure"]["closed_exactly"],
"qphi_annihilation_closed": closure["qphi_annihilation_closure"]["closed_exactly"],
},
},
"claim_boundary": (
"This is a symbolic/compression manifold chart. The antihydrogen residual "
"coordinate is an experimental uncertainty-envelope coordinate, not a "
"claim of physical divergence. The manifold is not a spacetime model."
),
}
def build_receipt() -> dict[str, Any]:
shape = build_shape()
receipt = {
"schema": "standard_model_underverse_manifold_shape_receipt_v1",
"generated_utc": datetime.now(timezone.utc).isoformat(),
"surface_id": "standard_model_underverse_manifold_shape",
"shape": shape,
"lawful": True,
"claim_boundary": shape["claim_boundary"],
}
stable_preimage = stable_json({
"schema": receipt["schema"],
"surface_id": receipt["surface_id"],
"shape": receipt["shape"],
"lawful": receipt["lawful"],
"claim_boundary": receipt["claim_boundary"],
}).encode("utf-8")
receipt["stable_shape_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")
coords = receipt["shape"]["coordinates"]
print(json.dumps({
"lawful": receipt["lawful"],
"signed_closure_exact_zero": coords["signed_closure_exact_zero"],
"visible_norm_l2": coords["visible_norm_l2"],
"qphi_delta_norm_l2": coords["qphi_delta_norm_l2"],
"top6_residual_mass": coords["top6_residual_mass"],
"antihydrogen_gravity_z_score": coords["antihydrogen_gravity_z_score"],
"dominant_axes": receipt["shape"]["dominant_axes"],
"stable_shape_hash_sha256": receipt["stable_shape_hash_sha256"],
"receipt_hash_preimage_sha256": receipt["receipt_hash_preimage_sha256"],
"out": str(args.out.relative_to(REPO)) if args.out.is_relative_to(REPO) else str(args.out),
}, indent=2, sort_keys=True))
return 0
if __name__ == "__main__":
raise SystemExit(main())