Lean 4 for beginners: a first checked proof
October 16, 2026 · Oyren AI Team (AI-written)

TL;DR: Start with a two-line Lean 4 proof, then check that it compiles without
sorryand states the claim intended in the research note. Free Oyren Docs holds the prose and LaTeX; formal Lean 4 and Mathlib files run in an Oyren Codespace on a managed cloud computer.
Choose or create a workspace, then select the Lean 4 add-on in Codespace setup.
A pinned toolchain and a visible goal
A Lean project pins its compiler in lean-toolchain. The installation guide explains elan, while the editor infoview shows the goal and available hypotheses at each proof step.
lake build
lake env lean Basic.lean
lake build checks the project; lake env lean Basic.lean checks one file with the project's dependency paths. A note containing the repository revision, file path and first compiler message helps distinguish a proof error from a toolchain change.
The declaration's three parts
Lean treats propositions as types and proofs as terms of those types, as the official introduction explains. A declaration names its parameters, states a goal after the final colon and supplies a proof after := by.
The infoview puts parameters and hypotheses above ⊢ and the remaining goal below it. The diagram marks the same boundary in a declaration.
example (sample : Nat) : sample = sample := by
rfl
sample is any natural number, so the example covers every value of type Nat. The tactics chapter explains why rfl closes this equality: both sides are the same term.
Evidence already in the context
exact supplies a term whose type matches the current goal:
example (Claim : Prop) (evidence : Claim) : Claim := by
exact evidence
Claim is the proposition. The local hypothesis evidence : Claim is already a proof of it, so exact evidence closes the goal.
| Part | Role in the proof state | Example |
|---|---|---|
| PartContext | Role in the proof stateAvailable hypothesis | Exampleevidence : Claim |
| PartGoal | Role in the proof stateType after ⊢ | ExampleClaim |
| PartStep | Role in the proof stateTerm that closes the goal | Exampleexact evidence |
Changing the target to another proposition produces a type mismatch. Misspelling evidence produces an unknown identifier. The interaction chapter explains how Lean reports errors and warnings.
A proof without a placeholder
Compilation alone does not establish that a declaration is finished. sorry lets an unfinished theorem pass through with an axiom; the tactic reference documents #print axioms for inspecting a named theorem.
theorem self_eq (sample : Nat) : sample = sample := by
sorry
#print axioms self_eq
The command reports a dependency on sorryAx for this version. Replacing sorry with rfl removes it. The final check is mathematical: if a written claim says every measurement is positive but the Lean statement assumes positivity, the proof establishes only the conditional statement.
After the first file
These examples need only Lean's core library. The Mathematics in Lean basics chapter introduces Mathlib after local goals and hypotheses are familiar. A named theorem can be reused and inspected with #print axioms; an example is checked anonymously.
The kernel checks formal proof steps suggested by an AI assistant. The assistant's explanation still needs review against the goal state. In Oyren, Docs keeps the informal claim and SOLVE calculations beside the Codespace that checks the formal file.
Choose or create a workspace, then select the Lean 4 add-on in Codespace setup.
Set up Lean 4 in a Codespace