Your proof-writing toolkit
A tactic for the next step.
Read the goal first. Then choose a tool. These before-and-after states come from the course’s actual Lean files.
Which tool fits this goal?
Look at the goal after ⊢, or at a fact you have. Its shape usually tells you the next move. This is a starting guide, not a rule: often several tactics work.
Finish or rewrite
Look at the goal’s main symbol
Use what you have
Let Lean do the arithmetic
h : a + 3 ≤ b ⊢ a < bWhole-number arithmetic with +, − and constantsomegaStep 25(a + b)^2 = …Algebra: expand both sides and compareringStep 26x ≤ y, y ≤ 7 ⊢ x ≤ 7Inequalities that follow by adding up ones you havelinarithStep 28⊢ 3/4 + 1/4 = 1Calculations with specific numbers, even fractionsnorm_numStep 27
Every tactic, with real before-and-after goals
rfl
For our equality goals, close a goal by definitional equality.
⊢ 2 + 2 = 4
no goals
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
example : 2 + 2 = 4 := by
rfl
decide
Run a decision procedure and turn its successful result into a proof.
⊢ 2 + 2 ≠ 5
no goals
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
example : 2 + 2 ≠ 5 := by
decide
exact
Supply a term whose type is the current goal.
P : Prop h : P ⊢ P
no goals
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
example (P : Prop) (h : P) : P := by
exact h
rw
Rewrite with named equalities or supported equivalences.
a b : Nat h : a = b ⊢ a + 1 = b + 1
no goals
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
example (a b : Nat) (h : a = b) : a + 1 = b + 1 := by
rw [h]
intro
Introduce a function input, implication premise, or universally quantified variable.
P : Prop ⊢ P → P
P : Prop h : P ⊢ P
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
example (P : Prop) : P → P := by
intro h
exact h
constructor
Apply a constructor for the goal’s type, leaving goals for its required arguments.
P Q : Prop hP : P hQ : Q ⊢ P ∧ Q
case left P Q : Prop hP : P hQ : Q ⊢ P case right P Q : Prop hP : P hQ : Q ⊢ Q
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
example (P Q : Prop) (hP : P) (hQ : Q) : P ∧ Q := by
constructor
· exact hP
· exact hQ
cases
Split a value into all its constructor cases.
P Q : Prop h : P ∨ Q ⊢ Q ∨ P
P Q : Prop h : P ∨ Q ⊢ Q ∨ P
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
example (P Q : Prop) (h : P ∨ Q) : Q ∨ P := by
cases h with
| inl hP =>
right
exact hP
| inr hQ =>
left
exact hQ
left
Choose the left constructor of an or goal.
P Q : Prop hP : P ⊢ P ∨ Q
P Q : Prop hP : P ⊢ P
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
example (P Q : Prop) (hP : P) : P ∨ Q := by
left
exact hP
example (P Q : Prop) (hQ : Q) : P ∨ Q := by
right
exact hQ
right
Choose the right constructor of an or goal.
P Q : Prop hQ : Q ⊢ P ∨ Q
P Q : Prop hQ : Q ⊢ Q
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
example (P Q : Prop) (hP : P) : P ∨ Q := by
left
exact hP
example (P Q : Prop) (hQ : Q) : P ∨ Q := by
right
exact hQ
apply
Use a theorem with a matching conclusion, leaving its missing premises as goals.
P : Prop h : ¬¬P ⊢ P
P : Prop h : ¬¬P ⊢ ¬P → False
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
example (P : Prop) (h : ¬ ¬ P) : P := by
apply Classical.byContradiction
intro hn
exact h hn
specialize
Apply a local hypothesis to arguments and replace it with the result.
P : Nat → Prop h : ∀ (n : Nat), P n ⊢ P 3
P : Nat → Prop h : P 3 ⊢ P 3
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
example : ∀ n : Nat, n = n := by
intro n
rfl
example (P : Nat → Prop) (h : ∀ n, P n) : P 3 := by
specialize h 3
exact h
exists
Supply an existence witness, then try to finish by reflexivity.
⊢ ∃ n, n + 1 = 4
no goals
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
example : ∃ n : Nat, n + 1 = 4 := by
exists 3
induction
Follow constructors, obtaining hypotheses for smaller recursive inputs.
n : Nat ⊢ 0 + n = n
n : Nat ⊢ 0 + n = n
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
theorem trail_zero_add (n : Nat) : 0 + n = n := by
induction n with
| zero => rfl
| succ n ih =>
change Nat.succ (0 + n) = Nat.succ n
rw [ih]
change
Replace a goal with a definitionally equal expression.
case succ n : Nat ih : 0 + n = n ⊢ 0 + (n + 1) = n + 1
case succ n : Nat ih : 0 + n = n ⊢ (0 + n).succ = n.succ
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
theorem trail_zero_add (n : Nat) : 0 + n = n := by
induction n with
| zero => rfl
| succ n ih =>
change Nat.succ (0 + n) = Nat.succ n
rw [ih]
simp
Simplify using rewrite rules and the configured simplifier lemmas.
α : Type u_1 xs ys : List α ⊢ (xs ++ ys).length = xs.length + ys.length
no goals
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
theorem trail_length_append (xs ys : List α) :
(xs ++ ys).length = xs.length + ys.length := by
induction xs with
| nil => simp
| cons x xs ih =>
simp [ih, Nat.add_assoc, Nat.add_comm]
omega
Prove supported arithmetic claims over Nat and Int.
a b : Nat h : a + 3 ≤ b ⊢ a < b
no goals
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
example (a b : Nat) (h : a + 3 ≤ b) : a < b := by
omega
ring
Normalize polynomial expressions to prove supported identities.
a b : ℝ ⊢ (a + b) ^ 2 = a ^ 2 + 2 * a * b + b ^ 2
no goals
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
module
import Mathlib.Tactic.Ring
import Mathlib.Basic.Real.Basic
example (a b : ℝ) : (a + b)^2 = a^2 + 2*a*b + b^2 := by
ring
norm_num
Prove supported concrete numerical facts.
⊢ 3 / 4 + 1 / 4 = 1
no goals
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
module
import Mathlib.Tactic.NormNum
example : (3 : ℚ) / 4 + 1 / 4 = 1 := by
norm_num
linarith
Derive a linear arithmetic consequence of the available facts.
x y : ℚ h₁ : x ≤ y h₂ : y ≤ 7 ⊢ x ≤ 7
no goals
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
module
import Mathlib.Tactic.Linarith
example (x y : ℚ) (h₁ : x ≤ y) (h₂ : y ≤ 7) : x ≤ 7 := by
linarith
calc
Write a chain of relations, with a justification for every link.
a b c : ℝ h₁ : a = b h₂ : b = c ⊢ a + 1 = c + 1
a b c : ℝ h₁ : a = b h₂ : b = c ⊢ a + 1 = c + 1
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
module
import Mathlib.Basic.Real.Basic
example (a b c : ℝ) (h₁ : a = b) (h₂ : b = c) : a + 1 = c + 1 := by
calc
a + 1 = b + 1 := by rw [h₁]
_ = c + 1 := by rw [h₂]
have
Introduce a local proved fact inside a tactic proof.
a b : ℝ ⊢ 2 * a * b ≤ a ^ 2 + b ^ 2
a b : ℝ h : 0 ≤ (a - b) ^ 2 ⊢ 2 * a * b ≤ a ^ 2 + b ^ 2
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
module
import Mathlib.Basic.Real.Basic
import Mathlib.Tactic.Linarith
example (a b : ℝ) : 2*a*b ≤ a^2 + b^2 := by
have h := sq_nonneg (a - b)
nlinarith
nlinarith
Use arithmetic reasoning with nonlinear preprocessing.
a b : ℝ h : 0 ≤ (a - b) ^ 2 ⊢ 2 * a * b ≤ a ^ 2 + b ^ 2
no goals
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
module
import Mathlib.Basic.Real.Basic
import Mathlib.Tactic.Linarith
example (a b : ℝ) : 2*a*b ≤ a^2 + b^2 := by
have h := sq_nonneg (a - b)
nlinarith
unfold
Replace a named definition by its defining expression.
a b : Nat h : bump a = bump b ⊢ a = b
a b : Nat h : a + 1 = b + 1 ⊢ a = b
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
def bump (n : Nat) : Nat := n + 1
theorem bump_injective (a b : Nat) (h : bump a = bump b) : a = b := by
unfold bump at h
omega
obtain
Unpack a fact into named components, such as a witness and its property.
a b : ℕ ha : Even a hb : Even b ⊢ Even (a + b)
a b : ℕ hb : Even b r : ℕ hr : a = r + r ⊢ Even (a + b)
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
module
import Mathlib.Algebra.Ring.Parity
example (a b : ℕ) (ha : Even a) (hb : Even b) : Even (a + b) := by
obtain ⟨r, hr⟩ := ha
obtain ⟨s, hs⟩ := hb
refine ⟨r + s, ?_⟩
omega
refine
Supply a term with holes that become new goals.
a b r : ℕ hr : a = r + r s : ℕ hs : b = s + s ⊢ Even (a + b)
a b r : ℕ hr : a = r + r s : ℕ hs : b = s + s ⊢ a + b = r + s + (r + s)
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
module
import Mathlib.Algebra.Ring.Parity
example (a b : ℕ) (ha : Even a) (hb : Even b) : Even (a + b) := by
obtain ⟨r, hr⟩ := ha
obtain ⟨s, hs⟩ := hb
refine ⟨r + s, ?_⟩
omega
rcases
Split and name components using a case pattern.
no goals
case inl n : ℕ h : n % 2 = 0 ⊢ 2 ∣ n * (n + 1) case inr n : ℕ h : n % 2 = 1 ⊢ 2 ∣ n * (n + 1)
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
module
import Mathlib.Data.Nat.Basic
example (n : ℕ) : 2 ∣ n * (n + 1) := by
have h : n % 2 = 0 ∨ n % 2 = 1 := by omega
rcases h with h | h
· have hn : 2 ∣ n := Nat.dvd_of_mod_eq_zero h
exact Nat.dvd_mul_right_of_dvd hn (n + 1)
· have hn : 2 ∣ n + 1 := Nat.dvd_of_mod_eq_zero (by omega)
exact Nat.dvd_mul_left_of_dvd hn n
<;>
Run the right-hand tactic on every goal produced by the left-hand tactic.
s : Switch ⊢ flipSwitch (flipSwitch s) = s
no goals
A tactic may open subgoals. Some constructs, including calc and have, also organize a proof.
Read the checked source
inductive Light where
| red | green
deriving DecidableEq
example : Light.red ≠ Light.green := by
decide
inductive Switch where
| off | on
def flipSwitch : Switch → Switch
| .off => .on
| .on => .off
example (s : Switch) : flipSwitch (flipSwitch s) = s := by
cases s <;> rfl