| """ |
| Symbolic recursion operators from the Primal Logic preprint: |
| |
| Dx(t) = ∫₀ᵗ a · Q(τ) dτ where Q(t) = DT + DP + DEM + DW |
| O(f)(t) = ∫₀ᵗ b · f(τ) dτ meta-operator with intent modulation b |
| """ |
|
|
| from __future__ import annotations |
|
|
| import math |
| from dataclasses import dataclass, field |
| from typing import Callable, Dict, List, Sequence |
|
|
| import numpy as np |
|
|
| |
| MU_DEFAULT = 0.16905 |
| D_ATTRACTOR = 149.999 |
|
|
|
|
| def composite_q( |
| dt_dev: float, |
| dp_dev: float, |
| dem_dev: float, |
| dw_dev: float, |
| *, |
| weights: Sequence[float] = (1.0, 1.0, 1.0, 1.0), |
| ) -> float: |
| """Q(t) = DT + DP + DEM + DW (weighted composite input).""" |
| w_dt, w_dp, w_dem, w_dw = weights |
| return w_dt * dt_dev + w_dp * dp_dev + w_dem * dem_dev + w_dw * dw_dev |
|
|
|
|
| @dataclass |
| class SymbolicRecursionKernel: |
| """ |
| Primary kernel: Dx(t) = ∫ a · Q(t) dt with recursive phase coherence. |
| """ |
|
|
| a: float = 1.0 |
| mu: float = MU_DEFAULT |
| state: float = 0.0 |
| history: List[float] = field(default_factory=list) |
|
|
| def step(self, q_t: float, *, dt: float = 0.01) -> float: |
| """Discrete integral with exponential memory decay (3IA Atlas kernel).""" |
| decay = math.exp(-self.mu * dt) |
| self.state = decay * self.state + self.a * q_t * dt |
| self.history.append(self.state) |
| return self.state |
|
|
| def integrate_series(self, q_series: np.ndarray, *, dt: float = 0.01) -> np.ndarray: |
| self.state = 0.0 |
| self.history.clear() |
| out = np.empty_like(q_series, dtype=float) |
| for i, q in enumerate(q_series): |
| out[i] = self.step(float(q), dt=dt) |
| return out |
|
|
|
|
| @dataclass |
| class MetaOperator: |
| """ |
| O(f)(t) = ∫ b · f(t) dt — embeds symbolic recursion and intent modulation. |
| """ |
|
|
| b: float = 0.091 |
| mu: float = MU_DEFAULT |
| state: float = 0.0 |
|
|
| def apply(self, f_t: float, *, dt: float = 0.01) -> float: |
| decay = math.exp(-self.mu * dt) |
| self.state = decay * self.state + self.b * f_t * dt |
| return self.state |
|
|
| def apply_series(self, f_series: np.ndarray, *, dt: float = 0.01) -> np.ndarray: |
| self.state = 0.0 |
| out = np.empty_like(f_series, dtype=float) |
| for i, f in enumerate(f_series): |
| out[i] = self.apply(float(f), dt=dt) |
| return out |
|
|
| def collapse_to_attractor(self, signal_history: Sequence[float], *, dt: float = 0.01) -> float: |
| """SREC collapse — gateway-compatible echo integral.""" |
| total = 0.0 |
| for val in signal_history: |
| total += self.b * val * dt |
| return total if abs(total) < D_ATTRACTOR else 0.0 |
|
|
|
|
| def forcing_functions(t: np.ndarray) -> Dict[str, np.ndarray]: |
| """Worked examples from the preprint.""" |
| return { |
| "oscillatory": np.sin(t) + np.cos(t), |
| "decaying": np.exp(-t), |
| "accelerating": t**2, |
| "fractal_impulse": _fractal_impulse(t), |
| "hybrid_echo": _hybrid_echo(t), |
| } |
|
|
|
|
| def _fractal_impulse(t: np.ndarray, depth: int = 4) -> np.ndarray: |
| out = np.zeros_like(t, dtype=float) |
| for k in range(depth): |
| scale = 2**k |
| out += np.sin(scale * np.pi * t) / scale |
| return out |
|
|
|
|
| def _hybrid_echo(t: np.ndarray, delay: float = 0.5) -> np.ndarray: |
| primary = np.sin(2 * np.pi * 0.5 * t) |
| echo = np.zeros_like(t) |
| dt = t[1] - t[0] if len(t) > 1 else 0.01 |
| lag_steps = max(1, int(delay / dt)) |
| echo[lag_steps:] = 0.6 * primary[:-lag_steps] |
| return primary + echo |
|
|
|
|
| def run_worked_examples( |
| *, |
| t_end: float = 10.0, |
| n_points: int = 500, |
| a: float = 1.0, |
| b: float = 0.091, |
| ) -> Dict[str, Dict[str, object]]: |
| """Evaluate Dx and O(f) under all forcing functions.""" |
| t = np.linspace(0, t_end, n_points) |
| dt = t[1] - t[0] |
| kernel = SymbolicRecursionKernel(a=a) |
| meta = MetaOperator(b=b) |
| results: Dict[str, Dict[str, object]] = {} |
|
|
| for name, f_series in forcing_functions(t).items(): |
| dx = kernel.integrate_series(f_series, dt=dt) |
| of = meta.apply_series(f_series, dt=dt) |
| results[name] = { |
| "final_dx": float(dx[-1]), |
| "final_of": float(of[-1]), |
| "max_dx": float(np.max(np.abs(dx))), |
| "bounded": bool(np.max(np.abs(dx)) < D_ATTRACTOR * 2), |
| } |
| return results |