Refine Laya instinct heuristic
Browse files- laya_engine.py +24 -9
laya_engine.py
CHANGED
|
@@ -111,24 +111,39 @@ class LayaDecisionOracle:
|
|
| 111 |
@staticmethod
|
| 112 |
def _heuristic_gut_feeling(equations: List[str], legal_actions: List[Dict[str, Any]]) -> Tuple[Dict[str, Any], float, str]:
|
| 113 |
"""Mathematical instinct priority heuristic."""
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
for a in legal_actions:
|
| 116 |
if a["type"] == "zero_product_split":
|
| 117 |
-
return a, 0.
|
| 118 |
|
| 119 |
-
#
|
| 120 |
for a in legal_actions:
|
| 121 |
if a["type"] == "factor":
|
| 122 |
-
return a, 0.
|
| 123 |
|
| 124 |
-
#
|
| 125 |
for a in legal_actions:
|
| 126 |
if a["type"] == "isolate":
|
| 127 |
-
return a, 0.
|
| 128 |
|
| 129 |
-
#
|
| 130 |
for a in legal_actions:
|
| 131 |
if a["type"] == "simplify":
|
| 132 |
-
return a, 0.
|
| 133 |
|
| 134 |
-
return legal_actions[0], 0.
|
|
|
|
| 111 |
@staticmethod
|
| 112 |
def _heuristic_gut_feeling(equations: List[str], legal_actions: List[Dict[str, Any]]) -> Tuple[Dict[str, Any], float, str]:
|
| 113 |
"""Mathematical instinct priority heuristic."""
|
| 114 |
+
import re
|
| 115 |
+
|
| 116 |
+
# 1. If all equations are already in isolated form, choose finish
|
| 117 |
+
all_isolated = True
|
| 118 |
+
for eq in equations:
|
| 119 |
+
m = re.match(r'^\s*[a-zA-Z]\s*=\s*[+-]?\d+(?:\.\d+)?(?:\/\d+)?\s*$', eq)
|
| 120 |
+
if not m:
|
| 121 |
+
all_isolated = False
|
| 122 |
+
break
|
| 123 |
+
|
| 124 |
+
if all_isolated:
|
| 125 |
+
for a in legal_actions:
|
| 126 |
+
if a["type"] == "finish":
|
| 127 |
+
return a, 0.99, "⚡ Laya Instinct: All equation branches are isolated into canonical root forms; proving Q.E.D."
|
| 128 |
+
|
| 129 |
+
# 2. If factored product exists (e.g. (x-2)*(x-3)=0), zero_product_split is highest priority
|
| 130 |
for a in legal_actions:
|
| 131 |
if a["type"] == "zero_product_split":
|
| 132 |
+
return a, 0.97, "⚡ Laya Instinct: Factored product (A)(B)=0 detected; zero-product split decomposes problem into independent linear branches."
|
| 133 |
|
| 134 |
+
# 3. If any equation can be factored, factor it
|
| 135 |
for a in legal_actions:
|
| 136 |
if a["type"] == "factor":
|
| 137 |
+
return a, 0.94, "⚡ Laya Instinct: High-degree polynomial structure detected; factoring collapses nonlinear search space to linear components."
|
| 138 |
|
| 139 |
+
# 4. If any un-isolated linear equation exists, isolate it
|
| 140 |
for a in legal_actions:
|
| 141 |
if a["type"] == "isolate":
|
| 142 |
+
return a, 0.92, f"⚡ Laya Instinct: Linear term detected in {a.get('description', '')}; isolating directly yields root."
|
| 143 |
|
| 144 |
+
# 5. If needs simplification
|
| 145 |
for a in legal_actions:
|
| 146 |
if a["type"] == "simplify":
|
| 147 |
+
return a, 0.88, "⚡ Laya Instinct: Redundant algebraic terms detected; simplifying reduces complexity metric."
|
| 148 |
|
| 149 |
+
return legal_actions[0], 0.80, f"⚡ Laya Instinct: Proposing {legal_actions[0]['type']} as optimal geodesic move."
|