Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,13 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
-
PRACTICALITY SYSTEM 12.
|
| 4 |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 5 |
-
NEW IN 12.
|
| 6 |
-
Β·
|
| 7 |
-
Β·
|
| 8 |
-
Β·
|
| 9 |
-
|
| 10 |
-
|
| 11 |
"""
|
| 12 |
|
| 13 |
import time, random, math, threading, asyncio, warnings, itertools
|
|
@@ -29,7 +29,7 @@ import uvicorn
|
|
| 29 |
warnings.filterwarnings("ignore")
|
| 30 |
USE_GPU = torch.cuda.is_available()
|
| 31 |
DEVICE = torch.device("cuda" if USE_GPU else "cpu")
|
| 32 |
-
print(f"[SYSTEM 12.
|
| 33 |
|
| 34 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 35 |
# SECTION 1: CONSTANTS
|
|
@@ -517,7 +517,6 @@ VERIFY_LAYER=VerifyLayer()
|
|
| 517 |
|
| 518 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 519 |
# SECTION 7: HYPERCUBE SET-BASED THEORIST
|
| 520 |
-
# The fundamental engine. No names. No soft weights. Pure Logic.
|
| 521 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 522 |
class Axiom:
|
| 523 |
DISCRETE="DISCRETE"; CONTINUOUS="CONTINUOUS"; METRIC="METRIC"; NETWORK="NETWORK"
|
|
@@ -532,6 +531,15 @@ ALL_AXIOMS = [
|
|
| 532 |
Axiom.TRANSITIVE, Axiom.ATOMIC, Axiom.COMPOSITE
|
| 533 |
]
|
| 534 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 535 |
AXIOM_CONTRADICTIONS=[
|
| 536 |
{Axiom.DISCRETE,Axiom.CONTINUOUS},
|
| 537 |
{Axiom.INJECTIVE,Axiom.SURJECTIVE},
|
|
@@ -541,7 +549,6 @@ AXIOM_CONTRADICTIONS=[
|
|
| 541 |
]
|
| 542 |
|
| 543 |
def build_hypercube() -> List[Set[str]]:
|
| 544 |
-
"""Generates all non-contradictory combinations of axioms up to length 6."""
|
| 545 |
valid = []
|
| 546 |
for r in range(1, 7):
|
| 547 |
for combo in itertools.combinations(ALL_AXIOMS, r):
|
|
@@ -550,44 +557,32 @@ def build_hypercube() -> List[Set[str]]:
|
|
| 550 |
valid.append(cset)
|
| 551 |
return valid
|
| 552 |
|
| 553 |
-
# Boots instantly. Generates exactly 4,708 valid universal rays.
|
| 554 |
AXIOM_HYPERCUBE = build_hypercube()
|
| 555 |
-
print(f"[SYSTEM 12.
|
| 556 |
|
| 557 |
@dataclass
|
| 558 |
class DomainStrategy:
|
| 559 |
name: str
|
| 560 |
-
hyp_weights: Dict[str,float]
|
| 561 |
-
polish: str
|
| 562 |
explore_early: bool
|
| 563 |
|
| 564 |
def compile_strategy(axioms: Set[str]) -> DomainStrategy:
|
| 565 |
-
""
|
| 566 |
-
name = "|".join(a[:3] for a in sorted(axioms)) if axioms else "BASE"
|
| 567 |
weights = {"branch": 0.0, "chain": 0.0, "coherence": 0.0, "residual_chain": 0.0, "manifold": 0.0}
|
| 568 |
polish = "both"
|
| 569 |
explore_early = False
|
| 570 |
|
| 571 |
if Axiom.CONTINUOUS in axioms:
|
| 572 |
-
weights["manifold"] = 1.5
|
| 573 |
-
weights["branch"] = 1.0
|
| 574 |
-
weights["residual_chain"] = 1.0
|
| 575 |
-
polish = "adam"
|
| 576 |
if Axiom.DISCRETE in axioms:
|
| 577 |
-
weights["chain"] = 2.0
|
| 578 |
-
weights["branch"] = 1.5
|
| 579 |
-
weights["coherence"] = 1.0
|
| 580 |
-
polish = "gradient"
|
| 581 |
-
explore_early = True
|
| 582 |
-
|
| 583 |
if Axiom.QUADRATIC in axioms or Axiom.METRIC in axioms:
|
| 584 |
-
weights["manifold"] += 1.0
|
| 585 |
-
weights["branch"] += 0.5
|
| 586 |
if Axiom.ORDERED in axioms or Axiom.NETWORK in axioms:
|
| 587 |
weights["chain"] += 1.0
|
| 588 |
if Axiom.MUTABLE in axioms or Axiom.BILINEAR in axioms:
|
| 589 |
-
weights["branch"] += 1.0
|
| 590 |
-
weights["residual_chain"] += 1.0
|
| 591 |
|
| 592 |
if sum(weights.values()) < 0.1:
|
| 593 |
weights = {"branch": 1.0, "chain": 1.0, "coherence": 1.0, "residual_chain": 1.0, "manifold": 1.0}
|
|
@@ -682,9 +677,7 @@ class ResidualOracle:
|
|
| 682 |
re=[e for e,c in sorted(de,key=lambda x:-x[1])[:5]]
|
| 683 |
return L9Certificate(round(ce,6),rv,re)
|
| 684 |
|
| 685 |
-
TOPOLOGY_ORACLE=TopologyOracle()
|
| 686 |
-
COHERENCE_ORACLE=CoherenceOracle()
|
| 687 |
-
RESIDUAL_ORACLE=ResidualOracle()
|
| 688 |
|
| 689 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 690 |
# SECTION 10: CORE SOLVERS
|
|
@@ -820,13 +813,13 @@ def solve_by_hypothesis(problem:Problem, budget:int=TOTAL_BUDGET, strategy:Optio
|
|
| 820 |
l9=RESIDUAL_ORACLE.evaluate(model.best_binding,problem,l7.hub_vars)
|
| 821 |
return {"binding":model.best_binding,"ce":model.best_ce,"solved":True,"l7":l7,"l9":l9,"time":round(time.time()-t0,3)}
|
| 822 |
|
| 823 |
-
|
| 824 |
for round_idx in range(HYPOTHESIS_MAX_ROUNDS):
|
| 825 |
if model.best_ce<SOLVE_THRESHOLD: break
|
| 826 |
l7=TOPOLOGY_ORACLE.evaluate(problem,active_scopes)
|
| 827 |
l8=COHERENCE_ORACLE.evaluate(model.scope_witnesses)
|
| 828 |
l9=RESIDUAL_ORACLE.evaluate(model.best_binding,problem,l7.hub_vars)
|
| 829 |
-
hypotheses=
|
| 830 |
improved=False
|
| 831 |
for hyp in hypotheses[:MAX_HYPS_PER_ROUND]:
|
| 832 |
if model.best_ce<SOLVE_THRESHOLD: break
|
|
@@ -858,26 +851,29 @@ def solve_by_hypothesis(problem:Problem, budget:int=TOTAL_BUDGET, strategy:Optio
|
|
| 858 |
"l7":final_l7,"l9":final_l9,"time":round(time.time()-t0,3)}
|
| 859 |
|
| 860 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 861 |
-
# SECTION 11: HYPOTHESIS
|
| 862 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 863 |
-
class
|
| 864 |
def __init__(self, strategy:Optional[DomainStrategy]=None):
|
| 865 |
self.strategy=strategy
|
| 866 |
|
| 867 |
def generate(self,problem,model,l7,l8,l9,round_idx):
|
| 868 |
hyps=[]
|
| 869 |
-
# Strict pruning: If strategy assigns 0 weight, do NOT generate.
|
| 870 |
w_br = self.strategy.hyp_weights.get("branch",1.0) if self.strategy else 1.0
|
| 871 |
w_ch = self.strategy.hyp_weights.get("chain",1.0) if self.strategy else 1.0
|
| 872 |
w_co = self.strategy.hyp_weights.get("coherence",1.0) if self.strategy else 1.0
|
| 873 |
w_rc = self.strategy.hyp_weights.get("residual_chain",1.0) if self.strategy else 1.0
|
| 874 |
w_mf = self.strategy.hyp_weights.get("manifold",1.0) if self.strategy else 1.0
|
|
|
|
|
|
|
|
|
|
| 875 |
|
| 876 |
if w_br > 0.01: hyps.extend(self._branch_hypotheses(problem,model,l9))
|
| 877 |
if w_ch > 0.01: hyps.extend(self._chain_hypotheses(problem,model,l7))
|
| 878 |
if w_co > 0.01: hyps.extend(self._coherence_hypotheses(problem,model,l8))
|
| 879 |
if w_rc > 0.01: hyps.extend(self._residual_chain_hypotheses(problem,model,l9))
|
| 880 |
if w_mf > 0.01 and round_idx>=3: hyps.extend(self._manifold_tangent_hypotheses(problem,model,l9))
|
|
|
|
| 881 |
|
| 882 |
if self.strategy:
|
| 883 |
for hyp in hyps:
|
|
@@ -887,6 +883,44 @@ class HypothesisOracle:
|
|
| 887 |
hyps=[h for h in hyps if h.hid not in model.failure_patterns]
|
| 888 |
return sorted(hyps,key=lambda h:-h.confidence)
|
| 889 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 890 |
def _branch_hypotheses(self,problem,model,l9):
|
| 891 |
hyps=[]; ref=model.best_binding
|
| 892 |
for expr_str in l9.dominant_exprs[:4]:
|
|
@@ -1017,7 +1051,6 @@ def _test_hypothesis(problem,hyp):
|
|
| 1017 |
|
| 1018 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1019 |
# SECTION 12: AXIOMATIC RAY TRACER (THE THEORIST)
|
| 1020 |
-
# Fires strict conceptual sets at the base problem. VerifyLayer arbitrates.
|
| 1021 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1022 |
@dataclass
|
| 1023 |
class RayTraceRound:
|
|
@@ -1034,10 +1067,7 @@ class AxiomRayTracer:
|
|
| 1034 |
best_ray = None
|
| 1035 |
history = []
|
| 1036 |
|
| 1037 |
-
# Phase 1: The Wavefront (Sample diverse universal rays)
|
| 1038 |
rays_to_test = random.sample(AXIOM_HYPERCUBE, self.WAVEFRONT_SIZE)
|
| 1039 |
-
|
| 1040 |
-
# Always test the explicitly defined axioms as a baseline ray
|
| 1041 |
if axl_def.axioms and axl_def.axioms not in rays_to_test:
|
| 1042 |
rays_to_test[0] = axl_def.axioms
|
| 1043 |
|
|
@@ -1048,13 +1078,10 @@ class AxiomRayTracer:
|
|
| 1048 |
print(f"\n[Ray {round_idx+1}/{self.WAVEFRONT_SIZE}] Firing: {strategy.name}")
|
| 1049 |
|
| 1050 |
t_start = time.time()
|
| 1051 |
-
# Strict solver search using base problem + axiom strategy limits
|
| 1052 |
result = solve_by_hypothesis(base_problem, budget=TOTAL_BUDGET, strategy=strategy)
|
| 1053 |
elapsed = round((time.time()-t_start)*1000, 1)
|
| 1054 |
|
| 1055 |
binding = result["binding"]
|
| 1056 |
-
|
| 1057 |
-
# The VerifyLayer is the absolute arbiter.
|
| 1058 |
verify = VERIFY_LAYER.run(binding, base_problem, axl_def.anchors)
|
| 1059 |
base_ce = verify.gate1_ce
|
| 1060 |
|
|
@@ -1254,7 +1281,7 @@ async def lifespan(app):
|
|
| 1254 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1255 |
# SECTION 15: FASTAPI + DASHBOARD
|
| 1256 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1257 |
-
app=FastAPI(title="Practicality 12.
|
| 1258 |
|
| 1259 |
def _render_collapse(record:Dict) -> str:
|
| 1260 |
b=record["binding"]; traces=record["traces"]
|
|
@@ -1328,7 +1355,6 @@ async def dashboard():
|
|
| 1328 |
runs=len(RUN_LOG); solved=sum(1 for r in RUN_LOG if r.get("solved",False))
|
| 1329 |
avg_ce=round(sum(r["ce"] for r in RUN_LOG)/max(1,runs),5) if RUN_LOG else 0
|
| 1330 |
|
| 1331 |
-
# Calculate efficacy by individual Axiom (very insightful)
|
| 1332 |
axiom_stats = defaultdict(lambda: {"tried": 0, "survived": 0, "total_ce": 0.0})
|
| 1333 |
for r in log:
|
| 1334 |
for t in r.get("traces", []):
|
|
@@ -1354,7 +1380,7 @@ async def dashboard():
|
|
| 1354 |
collapses="".join(_render_collapse(r) for r in log) if log else \
|
| 1355 |
"<div style='color:#222;padding:20px'>Warming upβ¦</div>"
|
| 1356 |
|
| 1357 |
-
return f"""<!DOCTYPE html><html><head><title>Practicality 12.
|
| 1358 |
<meta http-equiv="refresh" content="4">
|
| 1359 |
<style>
|
| 1360 |
body{{background:#090909;color:#e0e0e0;font-family:monospace;padding:20px;max-width:1400px}}
|
|
@@ -1365,9 +1391,9 @@ async def dashboard():
|
|
| 1365 |
th{{color:#2a2a2a;font-size:0.72em}}
|
| 1366 |
.badge{{display:inline-block;padding:3px 10px;border-radius:3px;background:#0e0e0e;margin:2px;font-size:0.78em;border:1px solid #1a1a1a}}
|
| 1367 |
</style></head><body>
|
| 1368 |
-
<h1>β Practicality 12.
|
| 1369 |
<div style='color:#333;font-size:0.75em;margin-bottom:12px'>
|
| 1370 |
-
Boolean Hypercube β Wavefront Rays β
|
| 1371 |
</div>
|
| 1372 |
<div style='margin-bottom:16px'>
|
| 1373 |
<span class='badge' style='color:#aaa'>Runs: {runs}</span>
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
+
PRACTICALITY SYSTEM 12.1 β AXIOMATIC ENZYMES
|
| 4 |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 5 |
+
NEW IN 12.1:
|
| 6 |
+
Β· Nomenclature: HypothesisOracle -> HypothesisGenerator (Permutations, not judges).
|
| 7 |
+
Β· Axiom Efficacy: Explicit shortcodes (CNT vs CSV) for perfect UI tracking.
|
| 8 |
+
Β· Stacked Chains (Enzymes): Combines Branching and Topological Chains into
|
| 9 |
+
composite hypotheses. A single algebraic guess cascades through interval
|
| 10 |
+
arithmetic to fold the problem before numerical solving begins.
|
| 11 |
"""
|
| 12 |
|
| 13 |
import time, random, math, threading, asyncio, warnings, itertools
|
|
|
|
| 29 |
warnings.filterwarnings("ignore")
|
| 30 |
USE_GPU = torch.cuda.is_available()
|
| 31 |
DEVICE = torch.device("cuda" if USE_GPU else "cpu")
|
| 32 |
+
print(f"[SYSTEM 12.1] Compute: {'GPU' if USE_GPU else 'CPU'}")
|
| 33 |
|
| 34 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 35 |
# SECTION 1: CONSTANTS
|
|
|
|
| 517 |
|
| 518 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 519 |
# SECTION 7: HYPERCUBE SET-BASED THEORIST
|
|
|
|
| 520 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 521 |
class Axiom:
|
| 522 |
DISCRETE="DISCRETE"; CONTINUOUS="CONTINUOUS"; METRIC="METRIC"; NETWORK="NETWORK"
|
|
|
|
| 531 |
Axiom.TRANSITIVE, Axiom.ATOMIC, Axiom.COMPOSITE
|
| 532 |
]
|
| 533 |
|
| 534 |
+
# Explicit short-codes to prevent UI collision (e.g. CNT vs CSV)
|
| 535 |
+
AXIOM_ABBR = {
|
| 536 |
+
Axiom.DISCRETE: "DIS", Axiom.CONTINUOUS: "CNT", Axiom.METRIC: "MET",
|
| 537 |
+
Axiom.NETWORK: "NET", Axiom.INJECTIVE: "INJ", Axiom.SURJECTIVE: "SUR",
|
| 538 |
+
Axiom.CONSERVED: "CSV", Axiom.MUTABLE: "MUT", Axiom.QUADRATIC: "QUA",
|
| 539 |
+
Axiom.BILINEAR: "BIL", Axiom.ORDERED: "ORD", Axiom.SYMMETRIC: "SYM",
|
| 540 |
+
Axiom.TRANSITIVE: "TRA", Axiom.ATOMIC: "ATO", Axiom.COMPOSITE: "CMP"
|
| 541 |
+
}
|
| 542 |
+
|
| 543 |
AXIOM_CONTRADICTIONS=[
|
| 544 |
{Axiom.DISCRETE,Axiom.CONTINUOUS},
|
| 545 |
{Axiom.INJECTIVE,Axiom.SURJECTIVE},
|
|
|
|
| 549 |
]
|
| 550 |
|
| 551 |
def build_hypercube() -> List[Set[str]]:
|
|
|
|
| 552 |
valid = []
|
| 553 |
for r in range(1, 7):
|
| 554 |
for combo in itertools.combinations(ALL_AXIOMS, r):
|
|
|
|
| 557 |
valid.append(cset)
|
| 558 |
return valid
|
| 559 |
|
|
|
|
| 560 |
AXIOM_HYPERCUBE = build_hypercube()
|
| 561 |
+
print(f"[SYSTEM 12.1] Axiomatic Hypercube Booted: {len(AXIOM_HYPERCUBE)} valid rays.")
|
| 562 |
|
| 563 |
@dataclass
|
| 564 |
class DomainStrategy:
|
| 565 |
name: str
|
| 566 |
+
hyp_weights: Dict[str,float]
|
| 567 |
+
polish: str
|
| 568 |
explore_early: bool
|
| 569 |
|
| 570 |
def compile_strategy(axioms: Set[str]) -> DomainStrategy:
|
| 571 |
+
name = "|".join(AXIOM_ABBR[a] for a in sorted(axioms)) if axioms else "BASE"
|
|
|
|
| 572 |
weights = {"branch": 0.0, "chain": 0.0, "coherence": 0.0, "residual_chain": 0.0, "manifold": 0.0}
|
| 573 |
polish = "both"
|
| 574 |
explore_early = False
|
| 575 |
|
| 576 |
if Axiom.CONTINUOUS in axioms:
|
| 577 |
+
weights["manifold"] = 1.5; weights["branch"] = 1.0; weights["residual_chain"] = 1.0; polish = "adam"
|
|
|
|
|
|
|
|
|
|
| 578 |
if Axiom.DISCRETE in axioms:
|
| 579 |
+
weights["chain"] = 2.0; weights["branch"] = 1.5; weights["coherence"] = 1.0; polish = "gradient"; explore_early = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 580 |
if Axiom.QUADRATIC in axioms or Axiom.METRIC in axioms:
|
| 581 |
+
weights["manifold"] += 1.0; weights["branch"] += 0.5
|
|
|
|
| 582 |
if Axiom.ORDERED in axioms or Axiom.NETWORK in axioms:
|
| 583 |
weights["chain"] += 1.0
|
| 584 |
if Axiom.MUTABLE in axioms or Axiom.BILINEAR in axioms:
|
| 585 |
+
weights["branch"] += 1.0; weights["residual_chain"] += 1.0
|
|
|
|
| 586 |
|
| 587 |
if sum(weights.values()) < 0.1:
|
| 588 |
weights = {"branch": 1.0, "chain": 1.0, "coherence": 1.0, "residual_chain": 1.0, "manifold": 1.0}
|
|
|
|
| 677 |
re=[e for e,c in sorted(de,key=lambda x:-x[1])[:5]]
|
| 678 |
return L9Certificate(round(ce,6),rv,re)
|
| 679 |
|
| 680 |
+
TOPOLOGY_ORACLE=TopologyOracle(); COHERENCE_ORACLE=CoherenceOracle(); RESIDUAL_ORACLE=ResidualOracle()
|
|
|
|
|
|
|
| 681 |
|
| 682 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 683 |
# SECTION 10: CORE SOLVERS
|
|
|
|
| 813 |
l9=RESIDUAL_ORACLE.evaluate(model.best_binding,problem,l7.hub_vars)
|
| 814 |
return {"binding":model.best_binding,"ce":model.best_ce,"solved":True,"l7":l7,"l9":l9,"time":round(time.time()-t0,3)}
|
| 815 |
|
| 816 |
+
generator=HypothesisGenerator(strategy=strategy); consec=0
|
| 817 |
for round_idx in range(HYPOTHESIS_MAX_ROUNDS):
|
| 818 |
if model.best_ce<SOLVE_THRESHOLD: break
|
| 819 |
l7=TOPOLOGY_ORACLE.evaluate(problem,active_scopes)
|
| 820 |
l8=COHERENCE_ORACLE.evaluate(model.scope_witnesses)
|
| 821 |
l9=RESIDUAL_ORACLE.evaluate(model.best_binding,problem,l7.hub_vars)
|
| 822 |
+
hypotheses=generator.generate(problem,model,l7,l8,l9,round_idx)
|
| 823 |
improved=False
|
| 824 |
for hyp in hypotheses[:MAX_HYPS_PER_ROUND]:
|
| 825 |
if model.best_ce<SOLVE_THRESHOLD: break
|
|
|
|
| 851 |
"l7":final_l7,"l9":final_l9,"time":round(time.time()-t0,3)}
|
| 852 |
|
| 853 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 854 |
+
# SECTION 11: HYPOTHESIS GENERATOR (Enzymes / Permutation Factory)
|
| 855 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 856 |
+
class HypothesisGenerator:
|
| 857 |
def __init__(self, strategy:Optional[DomainStrategy]=None):
|
| 858 |
self.strategy=strategy
|
| 859 |
|
| 860 |
def generate(self,problem,model,l7,l8,l9,round_idx):
|
| 861 |
hyps=[]
|
|
|
|
| 862 |
w_br = self.strategy.hyp_weights.get("branch",1.0) if self.strategy else 1.0
|
| 863 |
w_ch = self.strategy.hyp_weights.get("chain",1.0) if self.strategy else 1.0
|
| 864 |
w_co = self.strategy.hyp_weights.get("coherence",1.0) if self.strategy else 1.0
|
| 865 |
w_rc = self.strategy.hyp_weights.get("residual_chain",1.0) if self.strategy else 1.0
|
| 866 |
w_mf = self.strategy.hyp_weights.get("manifold",1.0) if self.strategy else 1.0
|
| 867 |
+
|
| 868 |
+
# Stacking (Enzyme): Branch + Chain composite
|
| 869 |
+
w_cmp = min(w_br, w_ch)
|
| 870 |
|
| 871 |
if w_br > 0.01: hyps.extend(self._branch_hypotheses(problem,model,l9))
|
| 872 |
if w_ch > 0.01: hyps.extend(self._chain_hypotheses(problem,model,l7))
|
| 873 |
if w_co > 0.01: hyps.extend(self._coherence_hypotheses(problem,model,l8))
|
| 874 |
if w_rc > 0.01: hyps.extend(self._residual_chain_hypotheses(problem,model,l9))
|
| 875 |
if w_mf > 0.01 and round_idx>=3: hyps.extend(self._manifold_tangent_hypotheses(problem,model,l9))
|
| 876 |
+
if w_cmp > 0.01: hyps.extend(self._composite_hypotheses(problem,model,l7,l9))
|
| 877 |
|
| 878 |
if self.strategy:
|
| 879 |
for hyp in hyps:
|
|
|
|
| 883 |
hyps=[h for h in hyps if h.hid not in model.failure_patterns]
|
| 884 |
return sorted(hyps,key=lambda h:-h.confidence)
|
| 885 |
|
| 886 |
+
def _composite_hypotheses(self,problem,model,l7,l9):
|
| 887 |
+
"""Enzyme: Pins a branch value and instantly cascades a chain reaction through interval arithmetic."""
|
| 888 |
+
hyps=[]
|
| 889 |
+
if not l7.solve_order or not l9.dominant_exprs: return hyps
|
| 890 |
+
ref=model.best_binding
|
| 891 |
+
tb=_global_hc4_tighten(problem)
|
| 892 |
+
for expr_str in l9.dominant_exprs[:3]:
|
| 893 |
+
mc=next((mc for mc in problem.compiled_constraints if mc.expr_str==expr_str),None)
|
| 894 |
+
if not mc or not mc.projections: continue
|
| 895 |
+
for v,proj_list in mc.projections.items():
|
| 896 |
+
lo,hi=problem.bounds.get(v,(-1e18,1e18))
|
| 897 |
+
for pi,proj in enumerate(proj_list):
|
| 898 |
+
try:
|
| 899 |
+
val=float(proj["func"](*[ref.get(s,0.0) for s in proj["syms"]]))
|
| 900 |
+
if not math.isfinite(val) or abs(val)>1e6 or not(lo<=val<=hi): continue
|
| 901 |
+
|
| 902 |
+
# 1. Pin the branch
|
| 903 |
+
start_box={u: IV(*tb.get(u, problem.bounds.get(u, (-10,10)))) for u in problem.variables}
|
| 904 |
+
start_box[v]=IV(val-1e-6, val+1e-6)
|
| 905 |
+
|
| 906 |
+
# 2. Trigger the cascade
|
| 907 |
+
cont=_hc4(start_box, problem.compiled_constraints)
|
| 908 |
+
if cont:
|
| 909 |
+
b=dict(ref)
|
| 910 |
+
for u,iv in cont.items(): b[u]=iv.mid()
|
| 911 |
+
# Anything contracted to near-zero width is solidly pinned by the cascade
|
| 912 |
+
pinned={u:b[u] for u in problem.variables if cont[u].width() < 1e-2}
|
| 913 |
+
hyps.append(Hypothesis(
|
| 914 |
+
hid=f"cmp_{hash(expr_str)%9999}_{v}_{pi}",
|
| 915 |
+
binding=b, h_type="composite",
|
| 916 |
+
claim=f"Enz(Br({v})βChain)",
|
| 917 |
+
derivation=[expr_str, "hc4_chain"],
|
| 918 |
+
pinned_vars=pinned,
|
| 919 |
+
free_vars=[u for u in problem.variables if u not in pinned],
|
| 920 |
+
confidence=0.90 if pi==0 else 0.80))
|
| 921 |
+
except: pass
|
| 922 |
+
return hyps
|
| 923 |
+
|
| 924 |
def _branch_hypotheses(self,problem,model,l9):
|
| 925 |
hyps=[]; ref=model.best_binding
|
| 926 |
for expr_str in l9.dominant_exprs[:4]:
|
|
|
|
| 1051 |
|
| 1052 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1053 |
# SECTION 12: AXIOMATIC RAY TRACER (THE THEORIST)
|
|
|
|
| 1054 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1055 |
@dataclass
|
| 1056 |
class RayTraceRound:
|
|
|
|
| 1067 |
best_ray = None
|
| 1068 |
history = []
|
| 1069 |
|
|
|
|
| 1070 |
rays_to_test = random.sample(AXIOM_HYPERCUBE, self.WAVEFRONT_SIZE)
|
|
|
|
|
|
|
| 1071 |
if axl_def.axioms and axl_def.axioms not in rays_to_test:
|
| 1072 |
rays_to_test[0] = axl_def.axioms
|
| 1073 |
|
|
|
|
| 1078 |
print(f"\n[Ray {round_idx+1}/{self.WAVEFRONT_SIZE}] Firing: {strategy.name}")
|
| 1079 |
|
| 1080 |
t_start = time.time()
|
|
|
|
| 1081 |
result = solve_by_hypothesis(base_problem, budget=TOTAL_BUDGET, strategy=strategy)
|
| 1082 |
elapsed = round((time.time()-t_start)*1000, 1)
|
| 1083 |
|
| 1084 |
binding = result["binding"]
|
|
|
|
|
|
|
| 1085 |
verify = VERIFY_LAYER.run(binding, base_problem, axl_def.anchors)
|
| 1086 |
base_ce = verify.gate1_ce
|
| 1087 |
|
|
|
|
| 1281 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1282 |
# SECTION 15: FASTAPI + DASHBOARD
|
| 1283 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1284 |
+
app=FastAPI(title="Practicality 12.1",lifespan=lifespan)
|
| 1285 |
|
| 1286 |
def _render_collapse(record:Dict) -> str:
|
| 1287 |
b=record["binding"]; traces=record["traces"]
|
|
|
|
| 1355 |
runs=len(RUN_LOG); solved=sum(1 for r in RUN_LOG if r.get("solved",False))
|
| 1356 |
avg_ce=round(sum(r["ce"] for r in RUN_LOG)/max(1,runs),5) if RUN_LOG else 0
|
| 1357 |
|
|
|
|
| 1358 |
axiom_stats = defaultdict(lambda: {"tried": 0, "survived": 0, "total_ce": 0.0})
|
| 1359 |
for r in log:
|
| 1360 |
for t in r.get("traces", []):
|
|
|
|
| 1380 |
collapses="".join(_render_collapse(r) for r in log) if log else \
|
| 1381 |
"<div style='color:#222;padding:20px'>Warming upβ¦</div>"
|
| 1382 |
|
| 1383 |
+
return f"""<!DOCTYPE html><html><head><title>Practicality 12.1</title>
|
| 1384 |
<meta http-equiv="refresh" content="4">
|
| 1385 |
<style>
|
| 1386 |
body{{background:#090909;color:#e0e0e0;font-family:monospace;padding:20px;max-width:1400px}}
|
|
|
|
| 1391 |
th{{color:#2a2a2a;font-size:0.72em}}
|
| 1392 |
.badge{{display:inline-block;padding:3px 10px;border-radius:3px;background:#0e0e0e;margin:2px;font-size:0.78em;border:1px solid #1a1a1a}}
|
| 1393 |
</style></head><body>
|
| 1394 |
+
<h1>β Practicality 12.1 β Axiomatic Enzymes (Permutation Spaces)</h1>
|
| 1395 |
<div style='color:#333;font-size:0.75em;margin-bottom:12px'>
|
| 1396 |
+
Boolean Hypercube β Wavefront Rays β Generator (Enzyme Stacked Chains) β Verify Layer
|
| 1397 |
</div>
|
| 1398 |
<div style='margin-bottom:16px'>
|
| 1399 |
<span class='badge' style='color:#aaa'>Runs: {runs}</span>
|