Docs · Starting out
Starting out
Everything you need to go from an empty directory to a proved theorem, and to read what flash tells you on the way.
Install#
The quickest way is one line in a terminal. It downloads the release, checks its SHA-256, installs it, and puts flash on your PATH:
curl -fsSL https://r7n.solutions/install.sh | shIts last line tells you what to do next: open a new terminal, so the command is found, and run flash start. It gets Lean if you need it, makes or finds a project, and sets flash up; the first time takes 15 to 20 minutes on a fast connection, up to an hour on a slow one (most of it is downloading), and needs about 12 GB free: Lean 3 GB, Mathlib’s files 7 GB, and flash’s own store 1 to 2.5 GB as you work. Get started → walks through both, step by step.
To install by hand instead, download the release and its .sha256 from the Download page into one directory, and run these three commands there:
sha256sum -c lens-flash-9.0.0-linux-x86_64.tar.gz.sha256 tar -xzf lens-flash-9.0.0-linux-x86_64.tar.gz lens-flash-9.0.0-linux-x86_64/install.sh
The installer puts flash in ~/.local/share/lens-flash and links it from ~/.local/bin/flash. flash needs Linux on x86_64 (on Windows, WSL), and elan with your project’s toolchain.
To check that everything is in order:
flash doctorIt names anything that is wrong and how to fix it, and --fix applies the safe fixes. Releases are kept side by side: flash self list shows them, flash self use V switches, flash self update installs the latest, and flash self gc clears out old ones. To remove flash altogether, see Uninstalling.
A first proof#
Here is a whole project to try it on, if you would rather build one by hand than let flash start make it: a module that defines double and proves double_pos, and a file with two theorems left as sorry. Paste this into a terminal: it makes the project in a directory called leanonly, builds it once, sets flash up, and proves both theorems.
mkdir -p leanonly/LeanOnly && cd leanonly echo 'leanprover/lean4:v4.35.0' > lean-toolchain cat > lakefile.toml <<'EOF' name = "leanonly" defaultTargets = ["LeanOnly"] [[lean_lib]] name = "LeanOnly" EOF echo 'import LeanOnly.Basic' > LeanOnly.lean cat > LeanOnly/Basic.lean <<'EOF' def double (n : Nat) : Nat := n + n theorem double_pos {n : Nat} (h : 0 < n) : 0 < double n := by unfold double; omega EOF cat > Chain.lean <<'EOF' import LeanOnly theorem c_two (m : Nat) (hm : 0 < m) : 0 < double (double m) := by sorry theorem c_four (k : Nat) (hk : 0 < k) : 0 < double (double (double (double k))) := by sorry EOF lake build # once; elan provides the toolchain lean-toolchain names flash init # sets flash up in this project flash prove Chain.lean --write # proves c_two, then c_four from it, and writes both in flash check Chain.lean # sorries 0
flash proves c_two with the project’s lemma, then c_four from c_two. It checks the file with each proof in place before writing it:
flash prove Chain.lean --write── c_two (1 of 2) proved Chain.lean c_two: 2 Lean checks, … s Chain.lean:4:2: sorry replaced with a checked proof ── c_four (2 of 2) proved Chain.lean c_four: 2 Lean checks, … s Chain.lean:7:2: sorry replaced with a checked proof Chain.lean: 2 of 2 proved (c_two, c_four); … s
flash check Chain.leanok errors 0 sorries 0 … ms (remembered) exact
import LeanOnly theorem c_two (m : Nat) (hm : 0 < m) : 0 < double (double m) := by apply Nat.add_pos_left <;> (apply double_pos <;> assumption) theorem c_four (k : Nat) (hk : 0 < k) : 0 < double (double (double (double k))) := by apply c_two <;> (apply c_two <;> assumption)
And here is each claim as the kernel holds it:
flash si Chain.leanclaim c_two id bb7bcb40e60b5e9ae17379f62d45afcc48dbe6f71e4a0af373f9f25ccd4313de state proved for m : Nat assume hm : 0 < m show 0 < double (double m) rests double_pos uses Nat.add_pos_left axioms propext · Quot.sound judged computation · the proof against its statement (a type that matches only by computation) render 1 claim c_four id 8d9cc3f3e32c2818fe7a82e6c52637758d6ff5ff34faf7b016539daf240334c6 state proved for k : Nat assume hk : 0 < k show 0 < double (double (double (double k))) rests c_two axioms propext · Quot.sound judged composed render 1
Both theorems are proved, each resting on the one before it and on the standard axioms. The rest of this page explains every line you have just seen.
The loop#
Day to day, the work is a loop: write some Lean, check it, search for what is missing, and go again.
Check a file
flash check Work.leanok errors 0 sorries 3 … ms exact
Work.lean:3:8: warning: declaration uses `sorry`
Work.lean:6:8: warning: declaration uses `sorry`
Work.lean:9:8: warning: declaration uses `sorry`
- The messages are Lean’s own. The exit status is 0 when the file has no error, 1 when it has errors, and 2 when it could not be checked.
- The first file with a new set of imports starts a worker that loads them. After that, a check costs only the time Lean takes to elaborate the file.
- A source checked before is answered from memory, from any path and any program, and marked
(remembered). - A file that checks without errors teaches the project: its theorems are usable from every other file at once.
flash check DIRchecks every.leanfile under a directory, and--jsongives one object (one a line for a directory).
Search for proofs
The sorries are searched in the order of the file. Each search can use the theorems above its sorry, including the ones just proved. So a theorem that is out of reach on its own can often be reached by stating the lemmas it needs above it, each with a sorry. This works the same in a project with Mathlib as in plain Lean.
| Command | What it does |
|---|---|
flash prove FILE | every sorry in the file, in order |
flash prove FILE --write | the same, writing each proof into the file |
flash prove FILE --decl NAME | one declaration |
flash prove FILE --jobs N --heartbeats H --wall S | a bigger or smaller budget: threads (4), each run’s heartbeat cap (Lean’s 200000) and wall cap (20 s) |
flash prove --engine c THEOREM | a library theorem, searched with itself and everything after it hidden |
Look before you write
Before you prove something, it is worth asking whether it already exists.
| Command | What it does |
|---|---|
flash twins FILE | the declarations of FILE that already exist, under any name |
flash find WORDS | declarations by name |
flash type NAME | a declaration’s statement |
flash suggest FILE | the lemmas that apply at the file’s first open sorry (--decl NAME for another), with what each leaves to prove |
flash why FILE LEMMA | where a lemma you expected stopped on that goal: visibility, retrieval, matching, premises, the kernel. flash why NAME LEMMA reads the theorem’s file as it is now |
flash resolve NAME | where a declaration lives, its state, and the import that brings it |
flash twins Twins.leanmy_add_comm
≡ Nat.add_comm [theorem] Init.Data.Nat.Basic
∀ (n m : Nat), n + m = m + n
my_new
no twin
2 declarations, 1 with a twin in the map
Two declarations are twins when their statements have the same identity. Variable names and whether a binder is implicit do not count; anything that changes the meaning does.
Reading a result#
A check starts with a status line: ok or not, the number of errors, and how many declarations still use sorry. A sorry is a warning, not an error, so a file full of sorries still checks.
A search ends every goal with one of six reasons. With --json it is the reason field.
| Reason | What it means | What to do |
|---|---|---|
proved | Lean accepted a proof that rests on nothing open. | Keep it with --write. |
reduced | The goal follows from lemmas that still have a sorry, named in reduced_to. | Prove those. The goal follows when they are proved. |
exhausted | Every candidate flash built was checked, and none was accepted. | Try flash suggest FILE and flash why FILE LEMMA, then state an intermediate lemma or write the step yourself. |
no-alternatives | No lemma fitted the goal at all. | The same as for exhausted. |
budget | The checks or the time ran out. | Raise --checks or --secs. |
refused | Memory was short for a new set of imports, or a module is not built. The exit status is 2. | Try again later, or work in files whose imports are already loaded. |
Reduced is not proved
Here t_false cannot be proved (it is false when m is 0), and t_main would follow from it. flash says exactly that:
flash prove Sketch.lean── t_false (1 of 2)
not proved Sketch.lean: exhausted after 17 Lean checks, … s (C search … ms; 41 of 41 derivations tried)
── t_main (2 of 2)
reduced Sketch.lean t_main to t_false (still a sorry): 25 Lean checks, … s
Sketch.lean:8:2: proof for this sorry, given t_false (checked; --write saves it):
simp [double_pos, t_false]; done
Sketch.lean: 0 of 2 proved; reduced to the sorries above them: t_main; not proved: t_false; … s
Claims and their states
Every theorem flash sees in a check or a search becomes a claim with a state:
| State | What it means |
|---|---|
open | It has a sorry. |
reduced | A proof exists that rests on lemmas still open. |
found | A search found a proof that is not in the file yet. |
proved | Its file checks with a proof and no sorry. |
The exit status of every command, and the JSON each one prints, are in the reference: Exit statuses → JSON →