A Rust swiss army knife for reading and manipulating .olean files, usable from the CLI or inside Rust kernels, without running Lean.
It is designed for massive developments (multimillion-line proof libraries), where you want to selectively export individual theorems and their dependencies without the whole environment blowing up in memory.
- Emits lean4export NDJSON, much faster
- BLean, a compact binary export format
- Cone export of chosen constants
- Statement cones, a theorem's proof-free trusted base
- Per-module exports pinned by hash, with
join - Modular checking with module-system-restricted imports
- Closure keys and accepted store for incremental checking
inspectandcomparefor oleans and exportsunused,axiomsanddigestfor auditing a theorem's conedeps, a lazily read reference graph for huge proofs
The object layout is tied to the Lean release. This version reads olean format v2 as written by Lean 4.26 through 4.36, and refuses files from any other release.
cargo install olean-exportAdd --features mimalloc to build with the mimalloc allocator.
Releases also ship prebuilt binaries for Linux (x86_64, arm64, static musl) and macOS (arm64, x86_64), built with mimalloc. cargo binstall olean-export fetches the one for your platform.
examples/Hello.lean is compiled to an olean with plain lean:
def double (n : Nat) : Nat := n + n
theorem double_two : double 2 = 4 := rfllean -o Hello.olean Hello.leanExport one theorem with everything it depends on, then check it with a kernel such as nano-lean. Inside a Lake project, lake env sets LEAN_PATH for you, so you can run:
$ lake env olean-export Hello -c double_two -o hello.ndjson
654 modules, 65,373 constants decoded in 1.41s
36.82 KiB of NDJSON (138 names, 16 levels, 490 exprs) in 1.41s total, 11.99 MiB/s
$ nl-fast hello.ndjson
import 1.23ms arena 0 MiB, 39 decls 490 exprs 138 names 16 levels
experimental checks 967.17µs: 39 attempted, 0 failures, 0 fallbacks
bridged quot 0 ind 7 ctor 8 rec 7Blean is a new binary format that is more efficient to mmap and read than NDJSON.
Add -f blean for the same stream in a compact binary form, see docs/BLEAN.md.
lake env olean-export Hello -c double_two -f blean -o hello.bleanA cone is a set of constants plus everything they mention. Without -c the export is the cone of every constant in the loaded modules, like lean4export.
-c NAME(repeatable) exports the full cone ofNAME, proofs included. Only theorem values inside the cone are decoded, the rest stay in their oleans.statement -c NAMEfollows only the statement: types, definition bodies and whole inductive families, no proofs. Theorems it reaches are taken as stated. It prints raw terms with source lines for review (-m Ncuts long terms), or with-f ndjson|bleanexports the cone with theorems as axioms for a checker.statement --trust MODULESleaves out what those modules, or modules under them, define, so you can review the trusted base of a Tau Ceti theorem without reading all of Tau Ceti.
lake env olean-export Mathlib -c Fin.insertNth_apply_succAbove -f blean -o thm.blean
lake env olean-export statement FLT -c THEOREM --trust Init,Std,Lean,Mathlibunused -c NAME lists what the full cone of NAME leaves unused, outside --trust modules: whole files, then each declaration with its source range. A tag lists the attributes that mention it, like instance or simp, which may use it only while elaborating.
axioms prints the axioms each declaration rests on, as #print axioms collects them, for the cone of -c NAME or all loaded modules outside --trust. --uses AXIOMS keeps declarations resting on one of them, --only AXIOMS those resting on anything else, and --why shows a chain down to the axiom.
digest -c NAME prints two closure keys: one for the statement cone, one for the full cone. They ignore ids, record order, paths and the exporter, so they make a stable receipt for a build.
deps writes one NDJSON line per declaration with the constants its terms name, for the cone of -c NAME or all modules outside --trust. --modules writes one line per module instead, counting references into each module.
unused, axioms and deps are lazy. They map the oleans without reading them in, catalog only names and kinds, and read only the terms the question reaches. Terms are never decoded, so memory stays small on proofs far larger than RAM.
lake env olean-export unused RH -c riemannHypothesis --trust Init,Std,Lean,Mathlib
lake env olean-export axioms RH -c riemannHypothesis --uses Classical.choice --why
lake env olean-export axioms Mathlib --trust Init,Std,Lean --only propext,Quot.sound
lake env olean-export digest RH -c riemannHypothesis
lake env olean-export deps RH -c riemannHypothesis --modules--per-module DIR writes one export per module, pinned to its imports by hash, and join merges them back into one. keys prints a closure key per declaration, and accepted lists a store of keys checkers have already accepted.
lake env olean-export Mathlib --per-module out/
olean-export join out/*.ndjson -o mathlib.ndjson--interfaces gives modular checking with module-system-restricted imports. Each module is written against what Lean showed it, with its exports in out/public/, and join -m gives one module over its imports' interfaces.
lake env olean-export Std --per-module out/ --interfaces
olean-export join -m Std.Data.HashMap.Lemmas out/ -o view.ndjsoninspect summarizes an olean's imports, constants and bytes per section. -c lists every constant.
$ olean-export inspect tests/cases/build/Top.olean
Lean 4.35.0-rc3 (470d5ce1400764999581fd26d5d72b00d990b0f4), gmp
39.64 KiB tests/cases/build/Top.olean
imports (1)
Base
constants (24): 8 def, 6 ctor, 4 inductive, 4 recursor, 2 theorem
bytes share items section
32.43 KiB 81.8% 24 constants
1.66 KiB 4.2% 7 Lean.declRangeExt
1.09 KiB 2.8% 24 _private.Lean.Util.CollectAxioms.0.Lean.exportedAxiomsExt
...compare diffs two exports, NDJSON or blean, ignoring record order, ids and binders.
$ lean4export Top > want.ndjson
$ olean-export Top -f blean -o got.blean
$ olean-export compare want.ndjson got.blean
33 / 33 declarations: 0 only in the first, 0 only in the second, 0 differ, 0 duplicate--statements separates statement changes from proof-only changes. It matches renamed declarations by statement, and -c NAME checks whether a theorem's statement cone was kept exactly. To check a toolchain bump, export the cone from each build and compare them. The exit status is nonzero if a statement changed.
$ olean-export -L tests/cases/build/edit Top -o new.ndjson
$ olean-export compare want.ndjson new.ndjson --statements -c N.add_zero -c two
statement: two (value)
proof: N.add_zero
removed: letty
added: three
33 / 33 declarations: 30 same, 1 proof only, 1 statement, 0 renamed, 1 removed, 1 added
N.add_zero: statement kept exactly
two: statement changed, through two
error: statements differModules decode in parallel on every core, and -j N sets the thread count. The output is identical for any -j. --rss shows peak resident memory.
Wall time:
| Target | lean4export | olean-export | Speedup |
|---|---|---|---|
Small model on Lean |
18.3s | 1.0s | 18x |
| All of Mathlib | 1526s | 18s | 85x |
One Mathlib theorem (-c) |
16.5s | 5.3s | 3x |
Peak memory:
| Target | lean4export | olean-export |
|---|---|---|
Small model on Lean |
1.3 GB | 0.5 GB |
| All of Mathlib | 9.4 GB | 4.3 GB |
One Mathlib theorem (-c) |
5.6 GB | 2.0 GB |
Mathlib is on Lean 4.35.0 (712,205 declarations, identical under compare), and the theorem is Fin.insertNth_apply_succAbove.
MIT Licensed. Copyright 2026 Stephen Diehl. See LICENSE for details.