Phase Separation, Futamura Projections, and Reverse-JIT Lowering
From interpreting prose on every request to partially evaluating business intent into a fast residual program with confidence-guarded bailouts.
When developers first wire language models into operational pipelines, they almost always construct a universal runtime interpreter:
Agent(playbook_prose + tools + history, live_event) ---> action + output
That design wastes energy twice. First, the model re-parses the exact same static business rules on every single incoming document or support event. Second, because conversational models emit open-ended token streams, every conditional branch carries latent token latency, parsing friction, and tail failure risk.
The First Futamura Projection for AI Systems
In 1971, Yoshihiko Futamura proved that partially evaluating a general interpreter I with respect to a fixed source program s yields a specialized residual program P_s:
mix(Interpreter, Program_s) ---> ResidualProgram_s(input)
Applied to AI software, this turns into a concrete engineering recipe:
- Your general reasoning model + alignment specs + playbooks act as the slow, flexible interpreter
I. - Your specific business workflow (vendor rules, catalog categories, invoice heuristics) acts as the slowly changing source program
s. - Phase 1 compilation runs
mix(I, s)only whensor the external world shifts — checked bysha256content hashing so untouched documents cost zero tokens. - Phase 0 execution runs the compact Computational Residue
P_s(input)at millisecond speed without dragging an open-ended agent loop into every transaction.
Combined with Matthew Flatt’s macro phase separation (“You Want It When?”), the answer to when intelligence should run becomes obvious: compile-time reasoning interprets ambiguous human intent; runtime execution evaluates narrow, verified primitives.
Smart Software and the Fourth Semantic Logic Gate
What does that Computational Residue look like inside production code?
Instead of forcing one large text-generating model to drive control flow, Smart Software keeps deterministic code in charge of state, permissions, math, locks, and side effects — and invokes focused System One decision models only at exact semantic branches.
As Diogo Almeida framed the primitive, a calibrated typed judgment API acts like a fourth semantic logic gate sitting alongside AND, OR, and NOT. Instead of returning chat prose, you pass structured state and a closed question schema (binary, choice, or ordinal), and receive calibrated probabilities over names your application already owns.
Reverse-JIT Lowering and Deoptimization Bailouts
Even better: the code emitted by Phase 1 does not need uniform intelligence across every stage. Just as a modern dynamic runtime lowers hot functions from interpreted execution down to specialized machine code — and bails out (deoptimizes) whenever a type assumption fails — Freshware treats intelligence as a 4-rung lowering axis:
| Rung | Mechanism | Unit Latency / Cost | Best Fit | Bailout Condition |
|---|---|---|---|---|
| Rung 0 · Pure Code | Deterministic functions, SQL, regex, state machines | ~1 ms · $0 | Arithmetic, locking, dedupe, stable lookups | Unseen enum or invariant check failure |
| Rung 1 · Decision Model | System One typed classifier (binary / choice / ordinal) | ~350 ms · $0.00005 | Semantic routing, entity matching, DuckDB SQL filters | Probability enters abstain band (0.35 < p < 0.65) |
| Rung 2 · Extraction | Multimodal / structured perception model | ~1,800 ms · $0.002 | Messy scanned PDFs, visual tables, layout maps | Line-sum arithmetic mismatch or missing field |
| Rung 3 · Frontier Agent | Open-ended reasoning model + tools | ~25,000 ms · $0.04 | Novel anomalies, Phase 1 compilation, /wayfinder | Escalate to Phase 2 human decision thread |
Experiment with the simulator below. Assign each pipeline stage across Rungs 0–3, adjust world drift and your confidence abstain band, and observe how lowering cuts compute cost and latency by more than 95% while deoptimization bailouts contain tail errors.
How Smart Should Each Step Be at Runtime?
Inspect Reverse-JIT Latency, Cost & Error Equations
For each stage i assigned rung r_i in {0,1,2,3} with base unit latency L(r), unit cost C(r), base error E(r), drift sensitivity k(r), world drift d in [0,1], and abstain band width a in [0,0.5]:
- Stage Bailout Probability
b_i:0.45 * don Rung 0 guards;a * (0.35 + 0.8 * d)on Rung 1 classifiers;0.15 * a + 0.12 * don Rung 2 extractors. - Effective Latency:
L_eff(i) = L(r_i) + b_i * (L(min(3, r_i + 1)) - L(r_i)). - Mitigated Tail Error:
E_i = (E(r_i) + 0.22 * d * k(r_i)) * (1 - min(0.78, 1.3 * a))on Rungs 0–2. - Pipeline Rollup: Latencies and costs sum linearly; end-to-end bailout is
1 - prod(1 - b_i)and pipeline error is1 - prod(1 - E_i).
Go Deeper: Futamura Projections & Hygienic Macro Talks
Phase separation and partial evaluation from Yoshihiko Futamura and Matthew Flatt: compiling ambiguous human intent once into a fast residual runtime.
Dr. Futamura's Projection Machine!
Compilers, Staging, and Futamura Projections
Partial Evaluation of Computation Process — An Approach to a Compiler-Compiler ↗
Provides the mathematical identity mix(I, spec) -> P_spec(input) driving Freshware's Computational Residue.
Composable and Compilable Macros: You Want It When? ↗
Answers the central question for AI harnesses: put heavy open-ended reasoning at macro-expansion time, not inside runtime event loops.