Strilight (v0.2.0)
High-Performance Algebraic Loop Lifting & Exact Rational Recurrence Engine for Python and C
Overview: Why Iterate When You Can Solve?
Traditional compilers, runtimes, and JIT engines (such as GCC, Clang, PyPy, or Numba) treat loops as repetitive control-flow sequences, executing instructions step-by-step: $$\text{Runtime Cost} = \mathcal{O}(N)$$
When $N = 10^6$ or $10^9$, sequential execution incurs billions of CPU cycles. Strilight fundamentally re-engineers loop execution through Symbolic Algebraic Lifting:
- It statically inspects the loop body and formulates its mathematical state transition matrix: $$\vec{\mathbf{X}}(N) = \mathbf{A}^N \cdot \vec{\mathbf{X}}0 + \sum{k=0}^{N-1} \mathbf{A}^{N-1-k} \vec{\mathbf{B}}$$
- It solves the recurrence system in closed form, reducing execution time from $\mathcal{O}(N)$ to $\mathcal{O}(1)$ (for scalar/periodic/telescoping series) or $\mathcal{O}(\log N)$ (via fast binary matrix exponentiation).
Architectural Foundations
1. Exact Rational Arithmetic over $\mathbb{Q}$ (Zero Precision Loss)
Floating-point arithmetic introduces cumulative truncation errors ($1/3 \times 3 \approx 0.9999999999999999$). Strilight performs affine induction and stride analysis over the field of rational numbers $\mathbb{Q}$:
- Multipliers and offsets are modeled as canonical fractions ($\frac{p}{q}$).
- Emits double-precision kernels in C and exact
Fractionrepresentations in Python, guaranteeing 100% bit-exact mathematical parity.
2. Multi-Variable Coupled Recurrence Systems ($\mathcal{O}(\log N)$)
Variables that mutually depend on each other (e.g., physical simulations where position depends on velocity and velocity depends on acceleration) are automatically extracted into a Variable Coupling Matrix ($\mathbf{A}$). Strilight performs binary exponentiation on $\mathbf{A}$, executing millions of iterations in under 2 nanoseconds.
3. Transparent @accelerate Decorator (How It Works)
Decorating any standard Python function with @accelerate executes an automated pipeline at function definition time (zero per-call runtime analysis overhead):
- AST Extraction: Inspects the function AST, identifies
forloop constructs, and extracts induction variables. - Closed-Form Synthesis: Translates the loop into equivalent closed-form recurrence models or binary matrix exponentiation kernels.
- In-Place Splicing: Replaces the loop AST nodes in-place, compiles the callable into memory, and injects runtime globals (
Fraction,math) without polluting module namespaces. - Contract Reflection: Attaches
_loop_summaryand_invariant_contractto the compiled function object, enabling downstream compilers and verification tools to inspect the underlying transition matrix $\mathbf{A}$. - Graceful Fallback: If non-linear indexing or unsupported dynamic calls are encountered, Strilight emits a diagnostic warning and cleanly falls back to native execution without crashing.
from strilight import accelerate
@accelerate
def compute_simulation(steps: int) -> int:
acc = 0
for i in range(steps):
acc += (i * 3) + 7
return acc
# Executes in O(1) time (~0.001 ms even if steps = 100,000,000)
result = compute_simulation(100_000_000)
4. Contract-Guided C Source Directives (#pragma strilight)
Unlike Python's dynamic reflection, C code transformations in Strilight strictly follow an explicit Developer-Contract Model via OpenMP-style pragma directives. The engine never mutates C source code implicitly; transformations occur solely when directed by explicit developer contract clauses (contract, target, include, model):
#pragma strilight accelerate: Explicitly authorizes Strilight to lift the annotated Cforloop into an equivalent closed-form mathematical expression.#pragma strilight fuse: Explicit developer directive instructing Strilight to fuse designated adjacent loops sharing identical iteration domains into a unified $\mathcal{O}(\log N)$ binary matrix recurrence kernel.
// Example of contract-guided multi-loop fusion via developer directive
int simulate_motion(int n) {
int pos = 0, vel = 10;
#pragma strilight fuse
for (int i = 0; i < n; i++) {
pos += vel;
}
for (int i = 0; i < n; i++) {
vel += 2;
}
return pos;
}
5. Cross-File Symbol & Constant Resolution (CrossFileResolver)
Numerical simulations frequently define parameters in separate header files or configuration modules. Strilight's CrossFileResolver:
- Statically traces local module imports and C
#include/#definedirectives. - Evaluates literal constant expressions (e.g.
SOLAR_MASS = 4 * PI * PI) across files via AST evaluation without executing arbitrary runtime code or using unsafeeval.
6. Array Slice Induction & Cyclic Table Lookups
- Cyclic Array Lookup: Lifts cyclic table lookups (
table[i % P]) into precomputed prefix-sum closed formulas in $\mathcal{O}(1)$. - In-Place Array Slice Mutation: Classifies constant fills and arithmetic progressions, synthesizing optimal hardware
memsetcalls or vector slice assignments (arr[:N] = ...).
Benchmark Results
Evaluated across high-iteration numerical loops, comparing native execution against Strilight acceleration:
| Benchmark Scenario | Iterations ($N$) | Native Baseline | Strilight Accelerated | Measured Speedup | Precision Fidelity |
|---|---|---|---|---|---|
| Coupled 4x4 Linear System (Python) | $1,000,000$ | $75.2\text{ ms}$ | $0.0002\text{ ms}$ | $376,000\times$ | 100% Bit-Exact |
| Coupled 4x4 Linear System (GCC -O2) | $1,000,000$ | $1.1\text{ ms}$ | $0.00002\text{ ms}$ | $55,000\times$ | 100% Bit-Exact |
| Cyclic Array Lookup Summation | $1,000,000$ | $74.8\text{ ms}$ | $0.0044\text{ ms}$ | $17,000\times$ | 100% Bit-Exact |
| Planetary N-Body Celestial Mechanics | $100,000$ | $7.17\text{ ms}$ | $0.051\text{ ms}$ | $140\times$ | Analytical Orbit Parity |
Architecture & Execution Pipeline
flowchart TD
SRC["Source Code (Python / C)"] --> LIFTER["SourceLifter: AST & Pragma Parser"]
LIFTER --> RESOLV["CrossFileResolver: Static Import Resolution"]
RESOLV --> VSA["Algebraic Induction Engine: models.py"]
VSA --> MATRIX["VariableCouplingMatrix: System Transition Matrix A"]
VSA --> QFIELD["Exact Rational Domain over Q: AffineExpr"]
REDUCE --> CODEGEN["CodeGenerator: C / Python Synthesis"]
VSA --> REDUCE["Schur Reduction & Block-Diagonal Decomposition"]
CODEGEN --> OUT["O(1) / O(log N) Executable Kernel"]
Key Applications & Real-World Use Cases
Strilight addresses computational bottlenecks across scientific, engineering, and financial domains:
1. Scientific & Astrophysical Simulations
- Domain: N-Body celestial mechanics, orbital state propagation, and multi-particle kinematic cascades.
- Advantage: Bypasses iterative $\mathcal{O}(N)$ numerical time-stepping. Evaluates the state vector at arbitrary future epoch $T$ directly in $\mathcal{O}(1)$ or $\mathcal{O}(\log N)$, eliminating cumulative numerical drift via exact rational arithmetic over $\mathbb{Q}$.
2. Quantitative Finance & Actuarial Analysis
- Domain: Compound interest accrual streams, annuities, fixed-income modeling, and multi-period asset depreciation.
- Advantage: Replaces multi-thousand-step simulation loops with exact closed-form evaluations in microseconds. Guarantees 100% bit-exact rational precision, eliminating floating-point rounding discrepancies prohibited under financial regulations.
3. Real-Time Graphics & Game Engine Physics
- Domain: Particle emitters, projectile trajectories, and continuous camera animations.
- Advantage: Offloads heavy sequential loops from the CPU during real-time 60/120 FPS frame cycles, collapsing iterative accumulator passes into single-cycle algebraic evaluations executing in sub-nanoseconds.
4. Embedded Systems & Hard Real-Time Computing (IoT / Edge)
- Domain: Resource-constrained microcontrollers (ARM Cortex-M, RISC-V, ESP32) operating under strict power and clock limitations.
- Advantage: Collapsing billion-iteration cycles into an instantaneous $\mathcal{O}(1)$ arithmetic statement delivers substantial energy savings and guarantees bounded, deterministic execution deadlines.
5. Compilers, Static Analysis & Formal Verification
- Domain: Invariant inference, symbolic execution, and automated theorem proving (SMT/Z3).
- Advantage: Synthesizes formal mathematical induction contracts (
LoopInvariantContract) without memory-intensive loop unrolling.
Installation
From PyPI / Wheel Distribution:
pip install strilight
From Source (Development Mode):
git clone https://github.com/asama7706r-ui/strilight.git
cd strilight
pip install -e .
Verification & Examples
Execute the standalone verification test suite and practical examples:
# Python recurrence acceleration:
python examples/01_python_recurrence_acceleration.py
# Jovian planetary N-body celestial simulation benchmark:
python examples/02_nbody_simulation_benchmark.py
# C Developer Contract & pragma acceleration suite:
python examples/c/run_c_acceleration.py
Licensing & Dual-License Model
Strilight is released under a Dual-Licensing Model:
- Open Source (GNU GPLv3): Free for academic research, open-source projects, and personal experimentation.
- Commercial License: For integration into proprietary commercial products or enterprise pipelines without GPL copyleft obligations.
Contact: asama7706r@gmail.com
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file strilight-0.2.0.tar.gz.
File metadata
- Download URL: strilight-0.2.0.tar.gz
- Upload date:
- Size: 83.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a823ff792af4f7523592eae12a5cf42e62d9de01987bee498cb43e1726563965
|
|
| MD5 |
9ab6f2d98d03c3eab5c9e1dc1c8404dc
|
|
| BLAKE2b-256 |
7ceab0a6d78a5de7a68b13e8fae351238542d1eb3ad25b3700d01e1eb7a70283
|
Provenance
The following attestation bundles were made for strilight-0.2.0.tar.gz:
Publisher:
release.yml on asama7706r-ui/strilight
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
strilight-0.2.0.tar.gz -
Subject digest:
a823ff792af4f7523592eae12a5cf42e62d9de01987bee498cb43e1726563965 - Sigstore transparency entry: 2736353313
- Sigstore integration time:
-
Permalink:
asama7706r-ui/strilight@569a7d99cb2d18b7d54c306dedb955175c5eabee -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/asama7706r-ui
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@569a7d99cb2d18b7d54c306dedb955175c5eabee -
Trigger Event:
push
-
Statement type:
File details
Details for the file strilight-0.2.0-py3-none-any.whl.
File metadata
- Download URL: strilight-0.2.0-py3-none-any.whl
- Upload date:
- Size: 86.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c038061df868c97bb311f70affb6a0d3ab3423b3de2818d2eac0888be90bbff
|
|
| MD5 |
9eec379875510f086be97d1f36875e78
|
|
| BLAKE2b-256 |
4bb0929df88d60f7bc3b69d565809b3985aa78d44db30021b1d2edd1273df349
|
Provenance
The following attestation bundles were made for strilight-0.2.0-py3-none-any.whl:
Publisher:
release.yml on asama7706r-ui/strilight
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
strilight-0.2.0-py3-none-any.whl -
Subject digest:
8c038061df868c97bb311f70affb6a0d3ab3423b3de2818d2eac0888be90bbff - Sigstore transparency entry: 2736353534
- Sigstore integration time:
-
Permalink:
asama7706r-ui/strilight@569a7d99cb2d18b7d54c306dedb955175c5eabee -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/asama7706r-ui
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@569a7d99cb2d18b7d54c306dedb955175c5eabee -
Trigger Event:
push
-
Statement type: