Calculator Demo
O(1) compute via lookup tables. Every math operation is a single byte-array access.
f64 value → embed(π) → LUT[F] → lift(λ) → f64 result
Benchmark Results
Criterion benchmarks on native Rust. Hologram's advantage grows with operation complexity and data size.
Loading benchmark data…
Accuracy Analysis
LUT operations quantize continuous values into 256 levels. The tables below show approximation error from the calculator example.
Sin (Angle Encoding)
| Input | f64 sin | LUT sin | Error |
|---|---|---|---|
| 0.0000 | 0.000000 | 0.003922 | 0.003922 |
| 0.5000 | 0.479426 | 0.466667 | 0.012759 |
| 1.0000 | 0.841471 | 0.843137 | 0.001666 |
| 2.0000 | 0.909297 | 0.913725 | 0.004428 |
| π | 0.000000 | 0.003922 | 0.003922 |
| 5.0000 | -0.958924 | -0.952941 | 0.005983 |
Sqrt (Unsigned Encoding)
| Input | f64 sqrt | LUT sqrt | Error |
|---|---|---|---|
| 0.0000 | 0.000000 | 0.000000 | 0.000000 |
| 0.1000 | 0.316228 | 0.313725 | 0.002502 |
| 0.2500 | 0.500000 | 0.494118 | 0.005882 |
| 0.5000 | 0.707107 | 0.705882 | 0.001224 |
| 0.7500 | 0.866025 | 0.866667 | 0.000641 |
| 1.0000 | 1.000000 | 1.000000 | 0.000000 |
How It Works
Hologram pre-computes a 256-entry lookup table for each mathematical function. At runtime:
- Embed — an encoding maps a continuous f64 value to a byte (0-255)
- LUT Apply — a single array access
table[byte]gives the output byte - Lift — the inverse encoding maps the output byte back to f64
This trades precision (8-bit quantization, ~0.004 typical error) for constant-time O(1) execution regardless of operation complexity. Chains of operations (e.g., sin(cos(x))) are fused into a single 256-byte table at compile time.