>[!warning]
>This content has not been peer reviewed.
# RST Python engine
Single implementation of the RST core maths for all calculation scripts. Scripts in **expanded theory** and **expanded theory applied** plug into this package; they do not redefine the engine.
## Location
The engine lives in the **`rst_engine/`** folder at the **workspace root** (the folder that contains `expanded theory`, `expanded theory applied`, and `rst_engine`).
## Contents
| Item | Role |
|:---|:---|
| `rst_engine/__init__.py` | Package entry; re-exports the public API. |
| `rst_engine/core.py` | Fidelity μ(η,n), Resource Triangle W, source helpers, solve_omega. |
| `rst_engine/README.md` | This file — engine system and how to plug in. |
## API
- **`mu_rst(eta, n=1.25)`** — Fidelity: μ = η / (1 + η^n)^(1/n).
- **`triangle_W(Omega, N, n=1.25)`** — Total budget: W = (Ω^n + N^n)^(1/n).
- **`source_from_triangle(Omega, N, n)`** — I = Ω²/W.
- **`source_from_rst(Omega, N, n)`** — I = Ω·μ(Ω/N).
- **`solve_omega(I, N, n)`** — Solve for Ω given I and N (scalar).
Default `n = 1.25` (SPARC / core theory). Applications can pass a different `n` (e.g. 4/3).
## How scripts plug in
1. **Resolve the workspace root** from the script’s location (e.g. two levels up from the script directory).
2. **Add the root to `sys.path`** so that `rst_engine` is importable.
3. **Import** the needed symbols:
`from rst_engine import mu_rst, triangle_W, source_from_triangle, source_from_rst, solve_omega`
Example (script lives in `expanded theory applied/SomeApp/script.py`):
```python
import os
import sys
_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
_ROOT = os.path.abspath(os.path.join(_SCRIPT_DIR, "..", ".."))
sys.path.insert(0, _ROOT)
from rst_engine import mu_rst, triangle_W
```
## Scripts that use the engine
- `expanded theory/python calculations/verify_super_relational_mapping.py`
- `expanded theory applied/Navier-Stokes Smoothness/rst_navier_stokes_regulator.py`
- `expanded theory applied/BSD Conjecture/rst_bsd_solver.py`
Run from the workspace root, e.g.:
`python "expanded theory/python calculations/verify_super_relational_mapping.py"`
## Relation to the theory
The engine encodes the **Resource Triangle** and **Main Equation** from the core theory. See **expanded theory** for the mathematical derivation (Fidelity Derivation, Resource Triangle, RST Core Reduction).
## Formula alignment (theory ↔ code)
| Theory (Fidelity Derivation, Resource Triangle, RST Core Reduction) | Engine / scripts |
|:---|:---|
| $\mu(\eta,n) = \eta/(1+\eta^n)^{1/n}$, $\eta = \Omega/N$ | `mu_rst(eta, n)` in `core.py` |
| $W^n = \Omega^n + N^n$, $W = (\Omega^n + N^n)^{1/n}$ | `triangle_W(Omega, N, n)` |
| $I = \Omega^2/W$ (projection) | `source_from_triangle(Omega, N, n)` |
| $I = \Omega \cdot \mu(\Omega/N)$ (field equation) | `source_from_rst(Omega, N, n)` |
| Solve for $\Omega$ given $I$, $N$ | `solve_omega(I, N, n)` |
| Main Equation (gravity): $g_N = g^2/(g^n + a_0^n)^{1/n}$ | `rst_equilibrium_proof.py`: same identity with $I=g_N$, $\Omega=g$, $N=a_0$ |
| Rendered output = ideal × μ(ideal/N) (regulator) | Navier–Stokes: `v_rendered = v_ideal * mu_rst(v_ideal/N, n)` |
| Fidelity from noise ∝ μ(1/L) (zeros → rank) | BSD: `bsd_fidelity_from_noise(L) = mu_rst(1/L, n)` |
All scripts that use the engine have been run from the workspace root and complete successfully. The verification script (`verify_super_relational_mapping.py`) confirms identity closure, budget identity $\mu^n+\nu^n=1$, and roundtrip $I \to \Omega \to I$ to numerical precision.