Lean is a proof assistant: you write mathematical statements and proofs, and the computer checks every logical step. A statement that Lean accepts is a theorem—verified to be right.

SCRP has Lean 4 installed, together with its version manager elan and build tool lake.

Check Lean Availability

Lean is set up automatically on login: the cluster’s shared copy of Lean is linked into your home directory, so no download is needed and almost no disk space is used. Because the setup runs at login, if you had a terminal open from before Lean was installed, you will need to open a new one.

To check Lean’s version, open a terminal and check:

lean --version

You should see something like Lean (version 4.35.0, ...).

What is Lean, elan, lake, and Mathlib?

Lean’s setup is a little unusual, so a quick tour of the pieces:

  • Lean - the programming language and proof assistant itself.
  • elan - a version manager for Lean. Think of it as a “phone book” that figures out which version of Lean to run and forwards your commands to the right one.
  • lake - Lean’s build tool. It handles projects with multiple files and dependencies, and turns your code into runnable programs.
  • Toolchain - a specific version of Lean, installed on your behalf. Projects can pin down which version they want.
  • Mathlib - Lean’s giant library of mathematical definitions and proofs.

The cluster provides a shared toolchain (Lean 4.35.0 and 4.33.1) in /opt/network/elan/, linked into ~/.elan in your home directory. It also has the corresponding MathLib library available, which you can set up with the lean-setup command.

lean-setup Command

If you are doing mathematics, you will want Mathlib, Lean’s giant library of mathematical definitions and proofs. Economists may further want MathEconLib, a formal foundation for economics built on top of Mathlib: game theory, mechanism design and auctions, choice and matching theory, and pricing.

A Mathlib-based project normally costs about 7.5GB of disk space and a long first build. To avoid both, the cluster keeps a shared library pool: one copy of Mathlib and MathEconLib, fully pre-built, that your project can link to instead of downloading its own. The pool’s versions are pinned (Lean 4.35.0, Mathlib v4.35.0, and MathEconLib’s current release).

To start a new project using the pool, just create a folder and run:

mkdir myproject && cd myproject
lean-setup new            # MathEconLib project (includes Mathlib)

# Write lean code in Myproject.lean before running the following command:
lake build

This scaffolds lakefile.toml, lean-toolchain, and a starter Myproject.lean (the library name is the folder name, capitalized: myproject → Myproject), then links the pool.

Options:

  • For a Mathlib-only project, use lean-setup new mathlib.
  • You can also request specific versions: lean-setup new mathlib v4.33.1
  • To see which Lean versions and pools are available: lean-setup list

If you already have a project with its own lakefile.toml, link it to the pool from inside the project folder. lean-setup will link the pre-built Mathlib of the version specified in lakefile.toml if it is available.

lean-setup matheconlib   # if your project uses MathEconLib (includes Mathlib)
lean-setup mathlib       # if your project uses Mathlib only
lake build

That’s it: no lake update, no lake exe cache get, no downloads. Your project folder stays a few MB.

A few things to pay attention to:

  • In the lakefile.toml created by lean-setup, you will see [[require]] entries referencing to the original git repositories. This is normal—the pool only replaces the downloaded copies of those libraries.
  • Don’t run lake update in a pooled project—it needs write access to the shared folders and will fail; that is by design.

Switching between pooled versions (say, 4.35.0 to 4.33.1): just change the pin and re-link. lean-setup re-points the project at the pool for the new version:

echo "leanprover/lean4:v4.33.1" > lean-toolchain   # change the pin
lean-setup mathlib                                 # link the 4.33.1 pool
lake build

If you need a version with no pool (for example, a Mathlib release newer than the pool’s), switch the project to its own copies and update normally:

lean-setup unlink     # remove the links
lake update            # fetch your own copies of the dependencies
lake exe cache get     # fetch pre-built Mathlib for your version
lake build

Note that Lean, Mathlib, and your project must all agree on the version. Pools exist for the cluster’s shared Lean 4.35.0 and 4.33.1 toolchains.

From then on the project is fully independent—it just costs its own ~7.5GB. Both kinds of projects coexist fine on the cluster.

Custom Setup

If you prefer not to use lean-setup, you can proceed as follows.

Settting Lean Version

To use the latest stable release:

elan default stable

or a specific version:

elan default leanprover/lean4:v4.35.0

Check what you have with elan show.

Note: each version you install yourself is downloaded into your home directory and takes about 3GB. To free up space, remove versions you no longer need:

elan toolchain uninstall leanprover/lean4:v4.35.0

To switch back to the cluster’s centrally-managed version, run:

elan default leanprover/lean4:v4.35.0

Create a Lean Project

Create a project folder, initialize, and build:

mkdir myproject && cd myproject
lake init
lake build

lake init creates a starter project in the current folder:

  • a lakefile.toml (describing the project)
  • a lean-toolchain file (pinning the Lean version)
  • some additional starter Lean files.

lake build compiles it and produces a runnable program, which you can run with:

./.lake/build/bin/myproject

A fresh project builds in a few seconds. The project is pinned to whatever Lean version was your default at lake init time; the cluster’s shared copy is 4.35.0.

A One-File Test without a Project

For quick experiments you can skip lake entirely. Put this in a file called hello.lean:

def main : IO Unit := IO.println "Hello from Lean on SCRP!"

Then run:

lean --run hello.lean

MathLib and MathEconLib

If you prefer not to use the pool (or need different versions), the standard Lean workflow works as usual. Add the dependency to lakefile.toml—Mathlib:

[[require]]
name = "mathlib"
scope = "leanprover-community"
rev = "v4.35.0"

or MathEconLib (add it instead of Mathlib; it pins Mathlib itself):

[[require]]
name = "matheconlib"
git = "https://github.com/matheconlib/matheconlib"
rev = "main"

Pin the toolchain to the matching version:

echo "leanprover/lean4:v4.35.0" > lean-toolchain

Note: Mathlib moves quickly and its latest release may require a newer Lean than the cluster’s shared version—in that case, install the version it asks for (elan default leanprover/lean4:vX.Y.Z) and accept the one-time download. To find a Mathlib release matching a given Lean version, check the tags: a release named v4.35.0 is built for Lean 4.35.0.

Then fetch and build:

lake update
lake exe cache get
lake build

lake exe cache get downloads ready-made files so your machine does not have to compile the whole library itself. Even so, expect the first build to use a good chunk of memory and disk (about 7GB in .lake/)—this is a good moment to move to a compute node:

srun -c 4 --mem=8G lake build

A Complete Example: Optimal Pricing under Random Value

This example puts everything together: a project, a pinned toolchain, the shared library pool, and MathEconLib. It proves a classic pricing result in three passes: first in natural language, then with MathEconLib (short), then with plain Mathlib (longer) — so you can see exactly what the economics library buys you.

The Problem in Natural Language

There is one buyer, one seller, and one good for sale.

Buyer

  • The buyer’s value \(v\) for the good is drawn from a uniform distribution on \([a, b]\). The buyer buys when price \(p \leq v\).

Seller

  • The marginal cost of the good is \(c\), while the fixed cost is \(k\).

At price \(p\), the buyer buys with probability \((b − p) / (b − a)\), and each sale nets \(p − c\). Expected profit is therefore

\[\pi(p) = (p - c) \cdot \frac{b - p}{b - a} - k\]

Optimal price is

\[p^{*} = \frac{b + c}{2}\]

The optimal price is the average of the top of the value interval and marginal cost. If \(p^{*}\) falls outside \([a, b]\), the optimal price is the nearest endpoint of the interval.

That is the claim to prove. Everything above—the model, the profit formula, the optimal price, the boundary case—is what we will now make machine-checked.

Set Up the Project

mkdir pricing && cd pricing
lean-setup new

This creates lakefile.toml (with the MathEconLib dependency and a Pricing library target), lean-toolchain, a starter Pricing.lean, and the pool links. (The library name is the folder name, capitalized: pricing → Pricing.)

Replace the contents of Pricing.lean with the code below, and build with lake build.

The Proof with MathEconLib - Example 1

MathEconLib already has a function to compute the optimal price for the pricing problem we outlined above, as well as a proof on its optimality.

In example 1, we will simply use these pre-defined components to prove the optimality of the interior solution:

  • A function uniformOptimalPrice that computes the optimal price.
  • A theorem uniformOptimalPrice_eq_peak that states if \((b+c)/2\) is in \([a,b]\), it is the optimal price.
import MathEconLib.ValueDistribution.UniformPricing

open MathEconLib ValueDistribution

-- (1) The optimal price is (b + c) / 2 if it lies inside [a, b].
example (a b c : ℝ) (hstar : (b + c) / 2 ∈ Set.Icc a b) :
    uniformOptimalPrice a b c = (b + c) / 2 :=
  uniformOptimalPrice_eq_peak a b c hstar

How to Read Lean Code

Here are the essentials for reading the code above:

  • Modules. import MathEconLib.ValueDistribution.UniformPricing imports the specific MathEconLib library for our problem. In general, you should try to import only the specific modules you need, as a blanket import MathEconLib would import over 8000 files, which takes at least several minutes to load.
  • Namespaces. open MathEconLib ValueDistribution lets you write uniformOptimalPrice instead of ValueDistribution.uniformOptimalPrice.
  • Comments. -- starts a comment to end of line.
  • Theorems. The format is
    theorem name (parameter_names : parameter_type) : CLAIM := PROOF.
    • For single-use statements, theorem name can be replaced with example.
    • := means “is proved by”. Everything between : and := is the claim; everything after is its proof.
    • To use a theorem, you call it by its name and provide it with the necessary inputs.
      • uniformOptimalPrice_eq_peak is a theorem defined in MathEconLib, and it takes four real numbers as inputs.
  • Parameters.
    • (a b c k : ℝ) introduces arbitrary real numbers as inputs to the theorem.
    • Assumptions. In Lean, assumptions are treated as parameters, and the statement its type. The format is therefore
      (name_of_assumption : assumption_statement)
      • In our case, (hstar : (b + c) / 2 ∈ Set.Icc a b) means we added an assumption named hstar—the ‘h’ stands for ‘hypothesis`—and it assumes the average of \(b\) and \(c\) lies within the closed interval \([a,b]\).
  • Functions. A functions takes parameters and compute an output. The format is:
    function name (params : param_type) : func_type : func_statement
    
    • uniformOptimalPrice is a function in MathEconLib. Its full defintion in MathEconLib is:
      def uniformOptimalPrice (a b continuationValue : ℝ) : ℝ :=
      max a (min b ((b + continuationValue) / 2))
      

      Which is the optimal price for the specific problem we outlined.

    • Lean writes function arg1 arg2 arg3 with spaces—uniformOptimalPrice a b c is \(uniformOptimalPrice(a, b, c)\).
    • For single-use function, you can define them anonymously like fun price ↦ ....
  • Proofs. In Lean, there are two proof styles, and they can be mixed freely:
    • With := by, you are in tactic mode—a program of commands (rw, ring, field_simp, nlinarith, …) that transform the goal step by step, like a whiteboard being rewritten until nothing remains.
      • A particularly note-worthly command is sorry: it tells the compiler to accept a proof as valid without actually checking anything. It is meant to be a place holder while developing larger proofs, but it can also be used to the cheat one’s way through a proof.
      • (by norm_num) inside an argument is a miniature tactic proof.
    • Without by, the proof is a single term—typically the name of an existing theorem, as in the example above: we cited an theorem defined in MathEconLib.

Note:

  • Example (1) cites the library theorem uniformOptimalPrice_eq_peak directly as its proof.
  • The hypothesis hpeak : (b + c) / 2 ∈ Set.Icc a b is the assumption that “the optimum is interior”—when it fails, the price is clamped to an endpoint, which is a different case.

The economics—the profit function, the virtual-surplus argument, the boundary care—all lives in the library. You cite it, Lean checks the citation, done. This is the pitch for MathEconLib: the statement is essentially the theorem you would write in a paper.

The Proof with MathEconLib - Example 2

What about the more general case that includes corner solutions?

  • The function uniformOptimalPrice includes corner solutions, so no change here.
  • MathEconLib has a separate theorem isMaxOn_sellerProfit_uniformInterval that states that uniformOptimalPrice is the optimal solution to the general problem.
  • We will need to state the general problem ourselves.
import MathEconLib.ValueDistribution.UniformPricing

open MathEconLib ValueDistribution

-- (2) That price maximizes expected profit among all prices in
-- [a, b] — for every a, b, c, k, boundary cases included.
example (a b c k : ℝ) (hab : a < b) :
    IsMaxOn
      (fun price ↦
        (uniformInterval a b hab).sellerProfit
          (SingleParameterProblem.postedPriceProblem a b price) c k)
      (Set.Icc a b) (uniformOptimalPrice a b c) :=
  isMaxOn_sellerProfit_uniformInterval a b hab c k

Note:

  • a < b is the only assumption, and this assumption is named hab. c and k are unrestricted.
  • IsMaxOn f s x means \(f(x) \ge f(y)\) for all \(y \in s\). In this example:
    • f is the seller’s expected profit at the given price,
    • s is \([a, b]\), and
    • x is uniformOptimalPrice from MathEconLib.

    So IsMaxOn f s x says the price given by uniformOptimalPrice is as least as good as another other price in \([a,b]\).

  • f is a single-use, anonymous function we define.
    • It takes price as an input.
    • The expected profit is calculated by a MathEconLib function ValueDistribution.sellerProfit.
      • When we write (uniformInterval a b hab).sellerProfit, what happens is Lean checks that uniformInterval is of type ValueDistribution, so ValueDistribution.sellerProfit is automatically chosen.
      • uniformInterval a b hab is then used as the first input to sellerProfit.
  • sellerProfit takes three additional inputs after the value distribution:
    • A rulebook of what the buyer would do. SingleParameterProblem.postedPriceProblem specifies that the buyer will buy one unit if the price is between a and b.
    • Marginal cost c.
    • Fixed cost k.
  • No interiority of the optimum is needed: the proof—the library’s isMaxOn_sellerProfit_uniformInterval therorem handles the boundary cases internally.

The Proof in Plain Mathlib

What if you had no economics library? Then you must build the profit function and prove optimality yourself. Mathlib supplies the mathematics (algebra, intervals, maxima); the model is on you:

import Mathlib

-- Without MathEconLib: the interior case, built by hand.
example (a b c : ℝ) (hab : a < b) :
    IsMaxOn (fun p ↦ (p - c) * (b - p) / (b - a)) (Set.Icc a b) ((b + c) / 2) := by
  intro p _
  have h_pos : 0 < b - a := sub_pos.mpr hab
  have h_sq : 0 ≤ (p - (b + c) / 2) ^ 2 := sq_nonneg _
  have h_id : ((b + c) / 2 - c) * (b - (b + c) / 2) - (p - c) * (b - p)
      = (p - (b + c) / 2) ^ 2 := by ring
  exact div_le_div_of_nonneg_right (by linarith) h_pos.le
  • example (a b c : ℝ) (hab : a < b) : ... := by: Declares an unnamed theorem (an example) with real parameters \(a, b, c\) and an assumption hab ( \(a < b\) ). The := by switches Lean from statement mode into tactic mode.
  • intro p _: Expands the definition of IsMaxOn.
    • p introduces an arbitrary point \(p\) from the domain. Note that this p and the p in fun p ↦ ... are completely unrelated. intro p _ maps its p to the \(y\) in definition of IsMaxOn f s x: \(f(x) \ge f(y)\) for all \(y \in s\). You could write intro q _ and the code will work just fine.
    • _ introduces the assumption we stated (p ∈ Icc a b) and immediately discards its name, because the interior algebra doesn’t require knowing the interval boundaries. If we have written intro p hp, then hp will be the name for the assumption p ∈ Icc a b within the context of this theorem.
  • have h_pos : 0 < b - a: Declares and proves a helper fact named h_pos stating that the denominator is strictly positive. This is necessary later because multiplying or dividing inequalities requires knowing the sign of the denominator.
    • := sub_pos.mpr hab: Uses Mathlib’s built-in theorem sub_pos to convert our provided assmption hab into \(0 < b - a\), which proves our claim that 0 < b - a.
  • have h_sq : 0 ≤ ...: Introduces a fact establishing that a squared term is always greater than or equal to zero.
    • := sq_nonneg _: Calls Lean’s standard library theorem sq_nonneg, which states that the square of any real number is non-negative. The underscore tells Lean to automatically infer what expression is being squared from the context.
  • have h_id : ... = ...: States the core algebraic relationship: the optimal profit minus the profit at price \(p\) equals the squared difference \((p - \frac{b+c}{2})^2\).
    • The equation here only contains the numerator of \(\text{Profit}(p^*) - \text{Profit}(p) \ge 0\). This is okay because we have assumed that \(b - a > 0\). We do not want the denominator because Lean’s ring tactic is designed to solve polynomials.
    • := by ring: Instantly proves this complex polynomial equality by expanding and simplifying both sides using Lean’s commutative ring solver.
  • exact ...: Finishes the proof by providing an exact term that matches the main goal ( \(\text{Profit}(p) \le \text{Profit}(p^*)\) ).
  • div_le_div_of_nonneg_right: A Mathlib lemma stating that if \(A \le B\) and \(0 \le d\) , then \(\frac{A}{d} \le \frac{B}{d}\) . It takes two arguments:
    • \(A\), \(B\) and \(d\) are automatically inferred from our claim IsMaxOn ....
    • (by linarith): Proves that the numerator inequality ( \(A \le B\) ) holds true by combining our algebraic identity (h_id) and our non-negative square fact (h_sq). linarith automatically goes through all assumptions in context, so manually specifying h_id and h_sq is not needed.
    • h_pos.le: Proves that the denominator is non-negative ( \(0 \le b - a\) ), converting our strict inequality h_pos ( \(0 < b - a\) ) into a weak inequality ( \(0 \le b - a\) ).

Note what is missing from this version compared to the MathEconLib one:

  • the profit function (p - c) * (b - p) / (b - a) is asserted by hand, not derived from any model of buyer behavior—if you wrote (b - p) / (b - a) wrong, Lean would faithfully prove the wrong theorem;
  • the boundary case (peak outside [a, b]) is not handled—this version only proves the interior case;
  • k is absent—it cancels out of the comparison, but you would have to notice that yourself;
  • each economics application would rebuild this from scratch.

MathEconLib packages exactly this kind of derivation once, correctly, with the boundary cases, so that your proof is a citation instead of a re-derivation. That is the division of labor the example is meant to show.

The first build of either version takes a few minutes while Lake verifies the pre-built library files; after that, rebuilds take seconds. When the build finishes, Lean has machine-checked the whole argument: no hand-waving, just a certificate you can re-verify any time. If you changed (b + c) / 2 to (b - c) / 2 in the Mathlib version, the build would fail—that is the proof assistant working.

Where to go next. Mathematics in Lean is the standard tutorial for proving with Mathlib. For MathEconLib specifics, browse the modules under .lake/packages/matheconlib/ in any pooled project.

Verifying Proofs with Independent Kernels

The theorem you just built is checked by Lean’s own kernel. Lean ships with extra tools for checking a proof with independent kernels, written by different people in different languages. This is useful when you want strong assurance that a proof—e.g. one received from someone else, or produced with AI assistance—really holds:

lake check              # rebuild + replay through Lean's kernel, sandboxed
lake check --paranoid   # also run the bundled external checkers:
                        # leanchecker-paranoid, lean4lean, nanoda, con-leche, con-ron

Both build and check the project inside a bubblewrap sandbox. They also verify that your theorems depend only on the three standard axioms (propext, Classical.choice, Quot.sound)—a sorry or a sneaky extra axiom will fail the check.

If the check passes, you should see:

Lean default kernel accepts the solution
Uses axioms: propext, Quot.sound, Classical.choice

Export a Flattened Proof

You can also flatten the proof into a single NDJSON file and hand that to the checkers. This is how large proofs—such as the recent Riemann Hypothesis formalization—are distributed and independently verified:

lake build                                       # build first
lake env leanexport MyLib > myproof.ndjson       # flatten
lake check --from-export myproof.ndjson          # sandboxed check of the file

Why flatten the proof? The export contains the proof and everything it depends on—your code plus the entire Mathlib it rests on—as one plain-text file with all the build machinery stripped away. That buys you:

  • A self-contained artifact. Checking it needs no project folder, no lake update, no network, no matching Mathlib version, and no compilation.
  • A byte-comparable record. The file has a SHA256 hash. A third-party can verify it checked exactly the proof you published, or confirm that their own rebuild reproduces your export byte for byte.
  • A smaller trust surface. lake check --from-export reads a text file, so nothing gets compiled or loaded from possibly-stale .olean caches on the checking machine. The only program you must trust is the checker itself.

The checkers can also be run directly on an export file. There are three independent proof checkers you can use: leanchecker-paranoid, con-leche, and con-ron. leanchecker-paranoid is a hardened version of Lean’s official C++ kernel built with strict memory-safety checks to catch memory corruption, while con-leche and con-ron are independently implemented external type-checkers that come with their own formal soundness proofs, guaranteeing they cannot accept a false proof.

leanchecker-paranoid --from-export myproof.ndjson   # Lean's kernel, hardened allocator
con-leche --jobs=8 myproof.ndjson                   # verified checker (Lean)
con-ron --jobs=8 myproof.ndjson                     # verified checker (Rust)

Judging a Solution Against a Challenge

lake comparator checks whether named theorems in a proof do in fact prove the same statements as defined in a challenge file.

First write a comparator.json in the project root:

{
  "challenge_module": "Challenge_Module_Name",
  "solution_module": "Solution_Module_Name",
  "theorem_names": ["theorem_1", "theorem_2", ...],
  "permitted_axioms": ["propext", "Quot.sound", "Classical.choice"]
}

Followed by running the comparator:

lake comparator --paranoid

Why a challenge file? When a proof arrives from someone else, “it type checks” is not enough—you also need to know what was proven. Without a challenge, the author of the solution controls both the theorem statements and their proofs, which allows the possibility of cheating through:

  • Restated claims. A famous theorem re-declared with an extra assumption, or its statement quietly edited to something trivially true. The proof compiles, but does not prove what it claims.
  • Smuggled shortcuts. An extra axiom postulating the result, or a leftover sorry, hides inside a project that otherwise looks complete.

The challenge file holds the intended statements, written by the requesting side; the comparator verifies that each named theorem in the solution proves exactly the corresponding challenge statement, uses no axiom outside the permitted three, and passes the kernel. The solution’s author cannot change what counts as success—only meet it or fail. --paranoid adds the independent external checkers to that same judgment.

The --compare mode of con-leche and con-ron performs the same statement-matching judgment standalone, on two export files, without the rest of the comparator pipeline. The toolchain-bundled binaries lack this mode; the cluster’s from-source builds are on the default PATH as con-leche-compare and con-ron-compare (versioned binaries and PROVENANCE.txt in /opt/network/lean-checkers/).

Resources Needed During Verification

The checkers come in two kinds:

  • External checkers (con-leche, con-ron, nanoda) split the work across cores with --jobs=N and finish in minutes.
  • Lean’s own kernel (leanchecker, leanchecker-paranoid, and the final stage of lake check/lake comparator) is deliberately single-threaded—no --jobs flag exists. Its checking algorithm leans on one big shared heap of memory that cannot safely be touched by several cores at once, so it processes the export in one long pass. Independent implementations (the external checkers above) were written later, in other languages, with parallelism and proofs of correctness designed in.

On a small project this difference is invisible—everything is done within minutes. On a very large export (tens of GB) it dominates: the kernel checkers need up to ~100GB of RAM, as the whole proof must sit in memory at once, and can run for days on a single core. When running on a compute node, request RAM and not cores—e.g. sbatch -p large --mem=120G—as extra cores will simply sit idle. Furthermore, as exports can be huge, you might wan to keep them in ~/archive` instead of your home directory.

Verification Example

Step 1: Create a Project with Two Modules

One module states what must be proven (the challenge, its theorems left as sorry holes); the other proves them. The two must declare the same theorem names and statements:

mkdir mycomparison && cd mycomparison
lean-setup new mathlib

Edit lakefile.toml so it has two libraries (keep the [[require]] from the scaffold), then create the two files:

[[lean_lib]]
name = "Challenge"

[[lean_lib]]
name = "Solution"
// Challenge.lean — the intended statements, as holes
import Mathlib.Tactic.Ring

theorem challenge_one : ∀ n : ℕ, n + 0 = n := by sorry
theorem challenge_two : ∀ n : ℕ, 2 * n = n + n := by sorry
// Solution.lean — the proofs
import Mathlib.Tactic.Ring

theorem challenge_one : ∀ n : ℕ, n + 0 = n := fun n => Nat.add_zero n
theorem challenge_two : ∀ n : ℕ, 2 * n = n + n := fun n => by ring
lake build Challenge Solution

Step 2: Export the Modules

lake env leanexport Challenge > challenge.ndjson
lake env leanexport Solution   > solution.ndjson

The exported files include the whole Mathlib dependency cone—about 0.8GB each here, so consider putting them in ~/archive for real projects.

Step 3: Verify

From this one example you can run every verification tool on the cluster. The first two work on the project directly; the rest consume the exports from step 2.

3a. lake check --paranoid — re-verify the Lean code through every bundled kernel (build, export, and check all inside a sandbox):

lake check --paranoid

Passing output ends with Lean default kernel accepts the solution plus a line from each external checker. This checks the proofs, not the challenge/solution correspondence—that is what the comparator (3c) adds.

3b. leanchecker-paranoid — Run an export through Lean’s hardened kernel:

leanchecker-paranoid --from-export solution.ndjson

Output: Lean default kernel accepts the solution, exit 0. Note that it also accepts the wrong solution export—the kernel checks proofs, not statements, so restated-claim cheating is invisible to it. That gap is what the tools in 3c and 3d close.

3c. lake comparator --paranoid — check if the solution’s theorems actually prove the challenge’s statements.

First write comparator.json in the project root:

{
  "challenge_module": "Challenge",
  "solution_module": "Solution",
  "theorem_names": ["challenge_one", "challenge_two"],
  "permitted_axioms": ["propext", "Quot.sound", "Classical.choice"]
}

then:

lake comparator --paranoid

Each named theorem is matched between the modules, checked for axioms outside the permitted three, and replayed through every kernel (leanchecker-paranoid, lean4lean, nanoda, con-leche, con-ron, and Lean’s default kernel). A passing run ends with:

Lean default kernel accepts the solution
Your solution is okay!

If the solution restates a theorem (say 2 * n = n + n + 1) and sorrys it, the comparator refuses:

error: Challenge and solution theorem statement do not match: 'challenge_two'

and exits 1.

3d. con-leche --compare and con-ron --compare — the standalone statement-matching judgment, on the two exports only. Provide the challenge first, followed by the solution:

con-leche-compare --jobs=8 \
    --compare challenge.ndjson solution.ndjson
con-ron-compare --jobs=8 \
    --compare challenge.ndjson solution.ndjson

Each checker reads the solution first, then the challenge, and justifies each challenge hole against the solution. A passing run ends with, and exits 0:

con-leche: accepted 185644 declarations, 2 axioms justified by the solution (…)
con-leche: theorem challenge_one justified by the solution
con-leche: theorem challenge_two justified by the solution

On the restated-and-sorried challenge_two, both refuse and and exit with error 2:

use of the sorryAx axiom in value of challenge_two

Exit Codes

  • The standalone checkers use 0 accepted, 2 rejected;
  • lake check/lake comparator use 0 accepted, 1 rejected, 2 could not start (missing bwrap, manifest, or config).
  • Anything else is an operational error, not a verdict.

Which tool for which job?

  • For checking your own proof, lake check --paranoid (3a).
  • For judging someone else’s work against intended statements, use the comparator (3c) if you have the project, or the --compare checkers (3d) if you only have exports.

As an example, the verification files for the Lean proof of Riemann Hypothesis by MIT Senior Research Scientist Andrew Sutherland ran all of them.

Cheat Sheet

Command What it does
lean --version Check Lean works and which version you have
lean-setup list Show available Lean versions and pre-built library pools
elan show What versions are installed and which is default
elan default leanprover/lean4:vX.Y.Z Set your default version (downloads if you don’t have it)
elan toolchain uninstall <name> Free up disk space
lake init Start a new project in the current folder
lake build Compile the project you are in
./.lake/build/bin/<projectname> Run the compiled program
lean --run hello.lean Run a single file, no project needed
lean-setup matheconlib Link a project to the shared MathEconLib pool
lean-setup mathlib Link a project to the shared Mathlib pool
lean-setup new [mathlib] Scaffold a new pooled project in an empty folder
lean-setup unlink Remove pool links; lake update then makes your own copies
echo "leanprover/lean4:vX.Y.Z" > lean-toolchain && lean-setup Switch a pooled project to another pooled Lean version
lake check [--paranoid] Re-verify a project through Lean’s kernel (and the external checkers), sandboxed
lake check --from-export FILE.ndjson Check a proof from an export file, no build needed
leanchecker-paranoid --from-export FILE.ndjson Lean’s kernel with hardened allocator, on an export
con-leche --jobs=N FILE.ndjson / con-ron --jobs=N FILE.ndjson Verified external checkers, on an export
con-leche-compare --compare challenge.ndjson solution.ndjson / con-ron-compare … Judge a solution export against a challenge export (0 = accepted, 2 = rejected)
lake comparator --paranoid Judge a solution against a challenge with all kernels
srun -c 4 --mem=8G lake build Build on a compute node