mirror of
https://github.com/allaunthefox/Research-Stack.git
synced 2026-07-31 03:05:21 +00:00
- SDPVerify.lean: certificate verification engine (714 lines, compiles cleanly) - GoormaghtighCert.lean: Goormaghtigh conjecture SDP certificate - HachimojiManifoldAxiom/HachimojiSubstitution: Hachimoji DNA encoding - GeneticBraidBridge.lean: genetic algorithm braid bridge - load_dependency_graph/load_module_graph: Gremlin Cosmos DB graph loaders - test_graph_queries/rrc_math_xref: graph verification queries - Gremlin mathblob DB provisioned and accessible - Branch cleanup: deleted 11 stale remote branches Build: 3297 jobs, 0 errors (lake build Semantics.SDPVerify)
264 lines
9.9 KiB
Python
264 lines
9.9 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
rrc_manifold_assign.py — Assign RRC equations to manifold locations using
|
||
Anti-Diophantine slack regimes.
|
||
|
||
Each equation is placed on the 8D braid manifold based on:
|
||
1. Route hint from equation semantics (keyword matching)
|
||
2. Anti-Diophantine slack from match characteristics
|
||
3. Canonical Sidon label assignment
|
||
|
||
Output: shared-data/data/rrc_manifold_assignment_v1.json
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import json
|
||
import re
|
||
from collections import Counter, defaultdict
|
||
from pathlib import Path
|
||
|
||
RECEIPT_PATH = Path("archive/experimental-shim-probes/rrc_equation_classifier_receipt.json")
|
||
OUT_PATH = Path("shared-data/data/rrc_manifold_assignment_v1.json")
|
||
|
||
# Manifold route hints with keyword patterns
|
||
ROUTE_PATTERNS: list[tuple[str, list[str], str]] = [
|
||
("thermodynamic_energy", [
|
||
"energy", "entropy", "heat", "carnot", "landauer", "temperature",
|
||
"thermodynamic", "thermal", "dissipation", "efficiency", "joule",
|
||
], "Anti-Diophantine: high match density, many variant forms"),
|
||
("geometry_topology", [
|
||
"geodesic", "metric", "stereographic", "euclidean", "manifold",
|
||
"curvature", "riemann", "tensor", "topology", "holonomy",
|
||
"connection", "bundle", "chart",
|
||
], "Diophantine: tight structural constraints"),
|
||
("cognitive_load", [
|
||
"cognitive", "load", "emotional", "signal", "attention",
|
||
"salience", "novelty", "surprise", "gate",
|
||
], "Transition: moderate slack, adaptive"),
|
||
("compression_route", [
|
||
"compress", "hutter", "encoding", "codec", "entropy",
|
||
"bit", "rate", "distortion", "redundancy",
|
||
], "Anti-Diophantine: many equivalent compression schemes"),
|
||
("magnetic_signal", [
|
||
"magnetic", "magneto", "field", "wave", "plasma",
|
||
"flux", "induction", "mhd", "alfven",
|
||
], "Anti-Diophantine: dense solution space"),
|
||
("control_signal", [
|
||
"control", "gate", "overflow", "gain", "tuning",
|
||
"cascade", "feedback", "regulator", "threshold",
|
||
], "Diophantine: precise constraint satisfaction"),
|
||
("chaotic_couch", [
|
||
"chaotic", "couch", "soliton", "turbulence", "vortex",
|
||
"strange", "attractor", "lyapunov",
|
||
], "Anti-Diophantine: chaotic regime, dense trajectories"),
|
||
("number_theory", [
|
||
"prime", "modulo", "congruence", "diophantine", "integer",
|
||
"arithmetic", "logarithm", "lower_bound", "bound",
|
||
], "Diophantine: Baker-style finiteness bounds"),
|
||
]
|
||
|
||
# Canonical Sidon labels (powers of 2) for address assignment
|
||
CANONICAL_LABELS = [1, 2, 4, 8, 16, 32, 64, 128]
|
||
|
||
# Greek epigenetic state mapping (route → Greek letter)
|
||
# Phase angles per Omindirection Principle 3: 360°/8 = 45° sectors
|
||
ROUTE_GREEK_MAP: dict[str, dict] = {
|
||
"thermodynamic_energy": {
|
||
"greek": "Φ", "phase": 0, "chirality": "ambidextrous", "direction": "forward",
|
||
"label": "Stable / Fundamental"
|
||
},
|
||
"geometry_topology": {
|
||
"greek": "Λ", "phase": 45, "chirality": "left", "direction": "forward",
|
||
"label": "Ordered attractor / Lattice regime"
|
||
},
|
||
"control_signal": {
|
||
"greek": "Ρ", "phase": 90, "chirality": "ambidextrous", "direction": "forward",
|
||
"label": "Regulated / Spectral radius boundary"
|
||
},
|
||
"cognitive_load": {
|
||
"greek": "Κ", "phase": 135, "chirality": "left", "direction": "forward",
|
||
"label": "Poised / Kappa threshold"
|
||
},
|
||
"chaotic_couch": {
|
||
"greek": "Ω", "phase": 180, "chirality": "ambidextrous", "direction": "reverse",
|
||
"label": "Terminal / Chaotic fixed point"
|
||
},
|
||
"compression_route": {
|
||
"greek": "Σ", "phase": 225, "chirality": "right", "direction": "reverse",
|
||
"label": "Symmetric partner / Compression duality"
|
||
},
|
||
"magnetic_signal": {
|
||
"greek": "Π", "phase": 270, "chirality": "right", "direction": "reverse",
|
||
"label": "Potential / Field effects"
|
||
},
|
||
"number_theory": {
|
||
"greek": "Ζ", "phase": 315, "chirality": "right", "direction": "reverse",
|
||
"label": "Zero-region / Zeta-like boundary"
|
||
},
|
||
}
|
||
|
||
# Regime → Greek fallback (used when route is unclassified)
|
||
REGIME_GREEK_MAP: dict[str, str] = {
|
||
"anti_diophantine": "Φ",
|
||
"diophantine": "Λ",
|
||
"transition": "Κ",
|
||
"transition_tight": "Ρ",
|
||
}
|
||
|
||
UNCLASSIFIED_GREEK = "Ζ"
|
||
|
||
ROUTE_ORDER = ["Φ", "Λ", "Ρ", "Κ", "Ω", "Σ", "Π", "Ζ"]
|
||
|
||
|
||
def compute_antidiophantine_slack(match_count: int | None, stage: str | None) -> tuple[int, str]:
|
||
"""Compute Anti-Diophantine slack from match characteristics."""
|
||
mc = match_count or 0
|
||
if mc >= 100:
|
||
slack = 128 # Anti-Diophantine: many matches, dense
|
||
regime = "anti_diophantine"
|
||
elif mc >= 20:
|
||
slack = 64 # Transition: moderate
|
||
regime = "transition"
|
||
elif mc >= 5:
|
||
slack = 16 # Transition: tighter
|
||
regime = "transition_tight"
|
||
else:
|
||
slack = 4 # Diophantine: few matches, tight
|
||
regime = "diophantine"
|
||
# Adjust for kernel stage quality
|
||
if stage == "kernel_refine_v1":
|
||
slack = max(slack // 2, 2) # Keyword match is weaker
|
||
elif stage == "kernel_refine_v4":
|
||
slack = min(slack * 2, 256) # Dataset match is stronger
|
||
return slack, regime
|
||
|
||
|
||
def classify_route(name: str, eq_text: str) -> str:
|
||
"""Classify an equation into a manifold route by name + text keywords."""
|
||
combined = (name + " " + str(eq_text)).lower()
|
||
best_route = "unclassified"
|
||
best_score = 0
|
||
for route, keywords, _ in ROUTE_PATTERNS:
|
||
score = sum(3 for kw in keywords if kw in combined)
|
||
if score > best_score:
|
||
best_score = score
|
||
best_route = route
|
||
return best_route
|
||
|
||
|
||
def assign_canonical_label(route: str, index: int) -> int:
|
||
"""Assign a canonical Sidon label (power of 2) based on route and index."""
|
||
return CANONICAL_LABELS[hash(route + str(index)) % len(CANONICAL_LABELS)]
|
||
|
||
|
||
def route_to_greek(route: str) -> dict:
|
||
"""Map a manifold route to its Greek epigenetic state."""
|
||
g = ROUTE_GREEK_MAP.get(route)
|
||
if g is not None:
|
||
return dict(g)
|
||
return {"greek": UNCLASSIFIED_GREEK, "phase": 315, "chirality": "right",
|
||
"direction": "reverse", "label": "Unclassified / Boundary"}
|
||
|
||
|
||
def regime_fallback_greek(regime: str) -> str:
|
||
"""Fallback Greek state from regime when route is unclassified."""
|
||
return REGIME_GREEK_MAP.get(regime, UNCLASSIFIED_GREEK)
|
||
|
||
|
||
def main():
|
||
d = json.loads(RECEIPT_PATH.read_text())
|
||
eqs = d["compiled_equations"]
|
||
N = len(eqs)
|
||
|
||
manifold = {
|
||
"schema": "rrc_manifold_assignment_v1",
|
||
"description": "RRC equations assigned to 8D braid manifold locations with Anti-Diophantine slack regimes",
|
||
"strands": 8,
|
||
"canonical_labels": CANONICAL_LABELS,
|
||
"route_counts": {},
|
||
"regime_counts": Counter(),
|
||
"equations": [],
|
||
}
|
||
|
||
route_registry: dict[str, int] = Counter()
|
||
|
||
for e in eqs:
|
||
rec = e["equation_record"]
|
||
name = rec.get("name", "unknown")
|
||
eq_text = str(rec.get("equation", ""))
|
||
match_count = rec.get("arxiv_match_count")
|
||
stage = rec.get("arxiv_match_stage")
|
||
|
||
# 1. Classify route
|
||
route = rec.get("route_hint", "unclassified")
|
||
if route == "?" or route == "unclassified":
|
||
route = classify_route(name, eq_text)
|
||
if route == "unclassified" and not route:
|
||
route = "unclassified"
|
||
|
||
route_registry[route] += 1
|
||
|
||
# 2. Compute slack and regime
|
||
slack, regime = compute_antidiophantine_slack(match_count, stage)
|
||
manifold["regime_counts"][regime] += 1
|
||
|
||
# 3. Assign canonical Sidon label
|
||
label_idx = route_registry[route] - 1
|
||
sidon_label = assign_canonical_label(route, label_idx)
|
||
|
||
# 4. Compute address budget M = slack + label
|
||
M = slack + sidon_label
|
||
|
||
# 5. Compute strand position (0-7)
|
||
strand = sidon_label.bit_length() - 1
|
||
|
||
# 6. Assign Greek epigenetic state
|
||
greek_info = route_to_greek(route)
|
||
if greek_info["greek"] == UNCLASSIFIED_GREEK:
|
||
greek_info["greek"] = regime_fallback_greek(regime)
|
||
# Recalculate phase for fallback
|
||
fallback_idx = ROUTE_ORDER.index(greek_info["greek"]) if greek_info["greek"] in ROUTE_ORDER else 7
|
||
greek_info["phase"] = fallback_idx * 45
|
||
|
||
manifold["equations"].append({
|
||
"name": name,
|
||
"route": route,
|
||
"regime": regime,
|
||
"greek_state": greek_info["greek"],
|
||
"greek_phase": greek_info["phase"],
|
||
"greek_chirality": greek_info["chirality"],
|
||
"greek_direction": greek_info["direction"],
|
||
"slack": slack,
|
||
"sidon_label": sidon_label,
|
||
"address_budget": M,
|
||
"strand": strand,
|
||
"match_count": match_count,
|
||
"match_stage": stage,
|
||
})
|
||
|
||
manifold["route_counts"] = dict(route_registry)
|
||
manifold["greek_counts"] = Counter(e["greek_state"] for e in manifold["equations"])
|
||
|
||
OUT_PATH.parent.mkdir(parents=True, exist_ok=True)
|
||
OUT_PATH.write_text(json.dumps(manifold, indent=2, ensure_ascii=False))
|
||
print(f"=== Manifold Assignment ({N} equations) ===")
|
||
print(f"Routes:")
|
||
for route, count in sorted(manifold["route_counts"].items(), key=lambda x: -x[1]):
|
||
print(f" {route:30s} {count:4d}")
|
||
print(f"\nRegimes:")
|
||
for regime, count in sorted(manifold["regime_counts"].items(), key=lambda x: -x[1]):
|
||
print(f" {regime:25s} {count:4d}")
|
||
print(f"\nGreek Epigenetic States:")
|
||
for greek in ROUTE_ORDER:
|
||
count = sum(1 for e in manifold["equations"] if e["greek_state"] == greek)
|
||
label = ROUTE_GREEK_MAP.get(
|
||
next((r for r, v in ROUTE_GREEK_MAP.items() if v["greek"] == greek), ""), {}
|
||
).get("label", "")
|
||
if count > 0:
|
||
phase = next((e["greek_phase"] for e in manifold["equations"] if e["greek_state"] == greek), 0)
|
||
print(f" {greek} ({phase:3d}°): {count:4d} — {label}")
|
||
print(f"\nWritten to {OUT_PATH}")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|