>[!warning]
>This content has not been peer reviewed.
# Substrate Hardware — Code Documentation
## Script
`rst_hardware.py` — derives physical constants ($\alpha$, $m_p/m_e$, $\alpha_G$) from $L^n$ ball geometry.
## Dependencies
- `numpy`, `matplotlib`, `scipy` (Gamma function, Brent root-finding)
## Core functions
### `volume_ln_ball(d, n)`
Volume of the $d$-dimensional $L^n$ unit ball:
$V_d(n) = \frac{(2\,\Gamma(1+1/n))^d}{\Gamma(1+d/n)}$
Works for any real $d > 0$ via the analytic continuation of the Gamma function.
### `lacunarity_d(d, n)`
Lacunarity (enclosing hypercube to ball volume ratio): $\mathcal{L}_d(n) = 2^d / V_d(n)$.
### `perimeter_ln_2d(n)`
Euclidean arclength of the 2D $L^n$ unit ball boundary. Uses the polar parameterisation $r(\theta) = (|\cos\theta|^n + |\sin\theta|^n)^{-1/n}$ and numerically integrates $P = \int_0^{2\pi} \sqrt{r^2 + (dr/d\theta)^2}\,d\theta$.
### `surface_area_ln_3d(n)`
Euclidean surface area of the 3D $L^n$ unit ball boundary. Parameterises the boundary in spherical coordinates and computes the cross-product magnitude $|\partial\mathbf{r}/\partial\phi \times \partial\mathbf{r}/\partial\theta|$ via finite differences.
### `find_d_star(n_target, n_ref, alpha_target)`
Root-finding (Brent's method) for the embedding dimension $d^*$ where $V_d(n_\text{target})/V_d(n_\text{ref}) = \alpha_\text{target}$.
## Modes
### `--alpha`
1. Continuous sweep: $V_d(1.25)/V_d(2)$ for $d \in [0.5, 25]$. Finds $d^*$ via root-finding.
2. Integer scan at $d = 3, \ldots, 12$: volume ratio, lacunarity ratio, and cross-dimensional combinations (SA/V, P/V mixed ratios).
3. Reports the closest integer match to $\alpha^{-1} = 137.036$.
4. Outputs: `hardware_alpha_sweep.png`, `hardware_alpha_integer_scan.png`.
### `--mass`
1. Computes geometric primitives at $n = 1.25$: $V_3$, $\text{SA}_3$, $P_2$ (both L^{1.25} and L^2).
2. Tests candidate topology factors: $\text{SA}_3/P_2$, $d^* \times \text{SA}_3/P_2$, cross-ratios.
3. Derives $m_p/m_e = \alpha^{-1} \times (\text{Topology Factor})$ and ranks by match quality.
4. Output: `hardware_mass_ratio.png`.
### `--gravity`
1. Computes $\alpha_G$ (measured) and the hierarchy ratio $\alpha/\alpha_G$.
2. Finds the power $k$ where $\alpha^k = \alpha_G$ (logarithmic ratio).
3. Computes $V_{d^*}(n)/V_{d^*}(2)$ for all Dimensional Ladder sectors.
4. Output: `hardware_gravity_hierarchy.png`.
### `--discovery`
Runs all three modes sequentially and produces a master summary table plus combined figure (`hardware_discovery.png`).
## Usage
```bash
python "expanded theory applied/further applications/Substrate Hardware/rst_hardware.py" --discovery
```
Individual modes:
```bash
python rst_hardware.py --alpha
python rst_hardware.py --mass
python rst_hardware.py --gravity
```
## Output files
| File | Content |
|:---|:---|
| `hardware_alpha_sweep.png` | Volume ratio vs embedding dimension (continuous) |
| `hardware_alpha_integer_scan.png` | Volume ratio at integer dimensions (bar chart) |
| `hardware_mass_ratio.png` | Topology factor candidates for $m_p/m_e$ |
| `hardware_gravity_hierarchy.png` | Coupling hierarchy ($\alpha^k$) and ladder ratios |
| `hardware_discovery.png` | Combined three-panel discovery summary |