How it works
How Lens Flash works
flash is a single C program. It keeps an index of every declaration Lean can see, keeps Lean running so checks are quick, runs Lean’s own tactics at every sorry and then the C search on what’s left, and lets Lean decide whether each one stands.
An index of every declaration#
When you set a project up, flash reads the compiled .olean files of Lean, your dependencies and your project with its own reader, written in C. From them it builds an index of every declaration: its statement, the shape of its conclusion, its rewrite rules, what it depends on, and its identity.
A declaration’s identity is the SHA-256 of its canonical form. Binder names are dropped, universe parameters are counted by position, and every constant it uses is replaced by that constant’s own identity. So two statements that mean the same thing share an identity whatever their variables are called, and anything that changes the meaning changes it.
That is how flash twins finds a theorem you are about to prove a second time, and how the solution interface names each claim. The reader is tested against Lean itself on every supported version, one declaration at a time. What it is measured on →
Lean, kept running#
Each project has a broker: one process on a Unix socket, with a pool of Lean workers behind it. A worker loads a file’s imports once and keeps them, so the next check of a file with the same imports costs only the time Lean takes to elaborate the file itself.
- A request goes to an idle worker, preferring one that already holds the same imports.
- The pool grows one worker at a time while requests wait and memory allows. When memory is short, a new set of imports is refused rather than started.
- A request is bounded: past
resources.request_memoryit is ended and refused, and while memory is belowresources.memory_floorthe request that grew most is ended. An ended request changes no claim. - A worker that has been idle for
resources.idleretires. - Every deterministic answer is remembered against the exact builds it was made from. Send the same request again, from any program and any path, and it is answered from memory.
How prove works#
flash prove sends a file to the resident that checks it, which turns every sorry into a goal in the environment Lean held just before it, with the hypotheses, options and namespaces in force there. A fixed portfolio of Lean’s own tactic texts runs on each goal, several at once on the worker’s threads, each under its own heartbeat cap and wall cap; the first run that closes a goal stops the others. A tactic the file’s imports do not have is passed over. Then the C search runs on each declaration still open.
Nothing is reported on a tactic’s word: the file with every closure written in place is elaborated again, and a declaration counts only when that check has no error, its value no sorry, and its axioms within the standard three. The verdicts are proved, reduced (it closes through theorems above that still have a sorry), refuted (plausible found a counterexample, or decide evaluated the goal to false) and open (with extract_goal’s statement of what is left). --engine native runs the tactics alone; --engine c runs the C search alone; flash search is prove’s alias in 9.0.x.
How the C search works#
The C search (flash prove --engine c) works in two stages: a search in C over the index, then Lean’s check of what it built.
- Retrieval. flash looks up the lemmas whose conclusion has the right shape for the goal, along with the theorems above the goal in its file and the proved theorems of your modules.
- Unification in C. Each lemma is unified with the goal by a reimplementation of Lean’s unifier: definitions unfold the way Lean unfolds them, instances are checked, and data a lemma leaves open is filled from the hypotheses.
- Chaining. Up to
search.depthlemma steps are chained, and what is left at each leaf goes to a fixed set of Lean tactics. The budget is counted in steps, so the same candidates come out on every machine. - Lean’s check. The finished candidates go to Lean, up to
search.checksof them. A proof is accepted only if Lean elaborates it with no error and nosorry, using only the standard axioms, and without using the goal itself. - Placement. The accepted proof is rewritten to fit its sorry, with the file’s own hypothesis names, and the whole file is checked with it in place before you see it.
When nothing proves a goal but theorems above it still have a sorry, the search runs again with those theorems given. A proof found that way is checked with each of them turned into an axiom, so Lean names exactly the open theorems it rests on. The goal is reported as reduced to them, never as proved.
Checks teach the project#
There is no build step while you work. When a module of your project checks without errors (sorries are allowed), the same check writes it, as lean -o would, into flash’s own copy of the project’s build. Every other file can import it, and every search can use its theorems, straight away. Lake’s build directory is never touched; at the end, lake build builds the project as ordinary Lean.
The statement is the unit
Because every declaration’s identity covers its statement, flash knows exactly what an edit changed.
- An edit to a proof changes nothing downstream.
- An edit to a statement makes stale exactly the modules that cite it. A module that imports it but cites only declarations that did not change keeps its build.
- A stale module is built again on demand, before the next check or search that needs it, imports first.
- The one exception is a module’s first build by flash: what Lake built before is not known, so everything that imports it is treated as stale once.
Once the project has been quiet for 20 seconds, the new modules are merged into the index, where their theorems become candidates like any library’s.
Claims, and how they resolve#
Every theorem flash sees has a claim, in one of four states: open, reduced, found or proved. Claims live in an append-only log, and a claim’s state depends only on which records exist, never on the order they were written. Programs working at the same time therefore always agree.
When a theorem becomes proved, flash checks again the files that import it and still hold open or reduced claims, and searches again every claim that was waiting only on lemmas that are now proved. Nobody has to ask. Leases from flash frontier --take only decide who works on what; they never change a state.
Two judges#
Lean decides
Every proof flash reports has been accepted by Lean: elaborated with no error and no sorry, using only the standard axioms (propext, Classical.choice, Quot.sound), and without using the goal itself. Lean’s kernel checks every declaration it adds. Nothing else counts as proved.
r7n reads the argument
r7n is a second kernel, built into flash. For each theorem it judges the argument as a composition: the proof term, with every constant it uses taken as given and typed by that constant’s own statement. Its verdict is composed, computation (with where), or none (with why).
It runs by itself. Once a module of your project checks clean, a background job judges its proofs and keeps each verdict against the source it judged, and flash frontier counts the verdicts beside the claims:
flash frontierproj: 9 proved · 0 found · 0 reduced · 0 open r7n: 9 composed · 0 computation · 0 none
Setting interface.judge to off turns it off. Lean stays the authority: no verdict ever changes a claim’s state. What each verdict means →
Memory#
Most of the memory in use is Lean’s. A worker holds the environment of the imports it loaded, which is what lean itself holds for a file with those imports; Lean’s compiled modules are mapped from disk and shared by every worker that loads them. The pool only grows while memory allows.
flash’s own share is small. The index is mapped from disk and read only where a command needs it, and remembered answers live on disk under a size cap. Setting a project up with Mathlib loads all of Mathlib in Lean once, to index it.
A worker that has run flash prove holds Lean’s library index, about 2.2 to 2.5 GB of its own, so the default worker memory is 3 GB: a worker holding more than resources.worker_memory after an answer is retired, which gives the memory back. resources.request_memory is automatic — half of what the machine holds beyond Mathlib’s mapped image and a reserve, 11 GB on a 32 GB machine — and a request past it is ended and refused with the budget and its peak. resources.memory_floor is automatic too — a sixteenth of the machine’s memory, from 768 MB to 4 GB. An ended request changes no claim.
What it is measured on#
Every result here is a count of proofs or checks. Speed depends on your machine, so it is not listed; flash metrics measures it on yours. Every proof counted was checked by Lean, and the searches ran on flash alone. The Mathlib numbers come from Lean 4.35.0-rc3 and Mathlib 5e0c4e52.
12 of 12
Regression goals
Each needs a lemma stated through a definition the goal does not mention, in at most 6 Lean checks. A release that proves fewer than 12 is not released.
tools/regress.sh --only apply
165 of 300
Mathlib theorems, proved again
The same 300, each proved again by flash prove without itself and anything that uses it, then the C search held out on what the tactics leave. The tactics alone prove 97, the C search alone 131. A release that proves fewer than 165 is not released.
tools/regress.sh --full --only prove-mathlib300
300 of 300 shown
Solution interface: the round trip
The same 300, each claim’s text elaborated again to the theorem’s own identity. By rung, 1 to 6: 238, 29, 24, 6, 2 and 1; 11 with a repair.
tests/si/roundtrip.sh
300 of 300
The fixed point
Lean to .si to Lean, twice over: identities kept, the Lean checks, and the second and third outputs are equal byte for byte.
tests/si/fixedpoint.sh
43 · 133 · 124
r7n’s verdicts
On the 300 library proofs: composed, computation, none.
flash si --names tests/regress/mathlib-300.txt
592 of 592 refused
The mutation test
Each composed claim of the Mathlib 300 is broken (arguments swapped, a theorem retyped, a binder made opaque), and every mutant must be refused: 43 composed claims, 592 mutants, 592 refused. Separately, on the test fixture tests/si/judge.lean: 4 composed claims, 60 mutants, 60 refused.
build/si-mutants (the fixture: make test-si)
The tests that need only Lean
Each runs in a scratch store, on a project with no dependencies.
| Test | What it checks | Result |
|---|---|---|
make test-pin-lean | setting up without Mathlib; a check; proving 3 of 3 sorries; twins; a theorem proved through the one above it; a reduced theorem never reported proved | 6 of 6 |
make test-pin-store | modules built on demand and used at once; edits to proofs and to statements; claim states; takes that never collide | 5 of 5, 7 of 7 |
make test-pin-store (reopen.sh) | nothing stays “proved” on a lemma that is not; a renamed theorem is no claim; one broken module does not stop a search | 6 of 6 |
make test-pin-compose | a theorem reduced to lemmas in two modules, proved by two processes at once and resolved with no request; leases; order independence | 4 of 4 |
make test-pin-config | settings: every default, precedence, background prove, TOML as people write it, and what is not read | 11 of 11 |
make test-pin-start | flash start without the network (start.sh): with no Lean and no terminal it changes nothing; a folder that is not a project, and a place it cannot write, are refused; a project made, built, set up and checked, and its example’s sorry proved; run again, it finishes. orphan.sh: a project’s background flash process shuts down by itself once its store is deleted | 10 of 10, 2 of 2 |
make test-pin-accept | what a fresh agent met on its first project | 3 of 3 |
make test-si | hidden coercions and the like made visible; notes kept by identity; the judged lines; the fixed point; --project; what cannot be carried to Lean, named | all passing |
Reading compiled Lean
For each supported Lean version, every declaration in Lean’s own library is read by flash’s C reader and compared with what Lean itself reports, byte for byte. They are identical on all six:
- 4.33.0 · 206,647
- 4.33.1 · 206,647
- 4.34.0 · 207,969
- 4.34.1 · 208,024
- 4.35.0-rc3 · 207,900
- 4.35.0 · 207,958
On your own machine, flash metrics times checks and searches, and restates five Mathlib lemmas under new names for flash twins to find (5 of 5).