Skip to content
LeanLearn

Tactics

Version-aware: every example below compiled against the pinned toolchain (2026.11.0, Lean 4.36.0, no Mathlib) in content validation. Before and after goal states are computed live by Lean when you step through an example. Tactics that need Mathlib are marked and cannot be run here yet. (Catalogue text is in English for now.)

logic

intro

Level 2core Lean 4.36

Assume the left side of an implication (or take an arbitrary object for a ∀) and give it a name.

Formal role
→-introduction / ∀-introduction: builds a λ-abstraction `fun h => _`.
Goal must be
The goal must be an implication A → B, a ∀ statement, or a negation ¬A (which means A → False).
What it changes
Adds a new hypothesis h : A (or a variable x) to the context; the goal becomes B.
When not to use it
When you want to use an implication you already have; that is apply or function application, not intro.
Common mistakes
  • Using intro when the goal is not an implication or ∀ (Lean reports that there is nothing to introduce).
  • Forgetting that ¬P is P → False, so intro works on negations too.
Alternatives
  • intros (introduce everything, with automatic names)
  • rintro (introduce and destructure at once)
  • fun h => … in term mode
beginner
Open in Playground →
example (P : Prop) : P → P := by
  intro h
  exact h
intermediateintro accepts several names at once.
Open in Playground →
example (P Q R : Prop) : P → Q → R → Q := by
  intro hp hq hr
  exact hq
advancedFor ∀, intro introduces an arbitrary object.
Open in Playground →
example : ∀ n : Nat, n + 0 = n := by
  intro n
  rfl

Practise: P → Q → QFill in the missing step

apply

Level 2core Lean 4.36

Work backwards: use a fact whose conclusion matches the goal, and prove its assumptions instead.

Formal role
→-elimination run backwards: unifies the conclusion of h with the goal and creates goals for h's premises.
Goal must be
The conclusion of h must match the goal.
What it changes
Replaces the goal with one goal per premise of h that Lean cannot infer.
When not to use it
When you already have every argument: exact is clearer.
Common mistakes
  • Applying a hypothesis whose conclusion does not match the goal.
  • Expecting apply to use hypotheses automatically; you still have to prove the new goals.
Alternatives
  • exact h x (forward style)
  • refine h ?_
beginner
Open in Playground →
example (P Q : Prop) (hpq : P → Q) (hp : P) : Q := by
  apply hpq
  exact hp
intermediate
Open in Playground →
example (P Q R : Prop) (hpq : P → Q) (hqr : Q → R) : P → R := by
  intro hp
  apply hqr
  apply hpq
  exact hp

Practise: Chaining implications

constructor

Level 2core Lean 4.36

Prove a statement built from parts (like P ∧ Q or P ↔ Q) by proving each part.

Formal role
Applies the first matching constructor of the goal's inductive type (And.intro, Iff.intro, …).
Goal must be
The goal's type must be an inductive type, such as ∧, ↔, True or a structure.
What it changes
Creates one goal per argument of the constructor (for ∧: case left and case right).
When not to use it
For ∨ goals, choose a side explicitly with left/right.
Common mistakes
  • Using constructor on P ∨ Q: it picks the first constructor (left), which may be the wrong side. Use left or right.
Alternatives
  • exact ⟨_, _⟩ (anonymous constructor)
  • refine ⟨?_, ?_⟩
beginner
Open in Playground →
example (P Q : Prop) (hp : P) (hq : Q) : P ∧ Q := by
  constructor
  · exact hp
  · exact hq
intermediate
Open in Playground →
example (P Q : Prop) : P ∧ Q ↔ Q ∧ P := by
  constructor
  · intro h
    exact ⟨h.2, h.1⟩
  · intro h
    exact ⟨h.2, h.1⟩

Practise: Build an ANDAND is commutative

obtain

Level 2core Lean 4.36

Take a hypothesis apart into its pieces, such as the two halves of an AND.

Formal role
Pattern-matches a term (∧-elimination, ∃-elimination, …) using rcases patterns.
Goal must be
Any goal; the term being destructured must have an inductive type.
What it changes
Removes h and adds its components as new hypotheses.
When not to use it
When you only need one part once: h.1 is shorter.
Common mistakes
  • Using | (alternatives) for an AND; | is for OR, the comma inside ⟨⟩ is for AND.
Alternatives
  • rcases h with ⟨hp, hq⟩
  • h.1 and h.2
  • cases h with | intro hp hq => …
beginner
Open in Playground →
example (P Q : Prop) (h : P ∧ Q) : Q := by
  obtain ⟨hp, hq⟩ := h
  exact hq
intermediate
Open in Playground →
example (P : Nat → Prop) (h : ∃ n, P n ∧ n > 0) : ∃ n, P n := by
  obtain ⟨n, hn, _⟩ := h
  exact ⟨n, hn⟩

Practise: Use an ANDAND is commutative

rcases

Level 3core Lean 4.36

Split a hypothesis into cases (OR) or pieces (AND, ∃), with one pattern.

Formal role
Recursive case analysis with patterns: ⟨a, b⟩ for products, a | b for sums.
Goal must be
Any goal; the hypothesis must have an inductive type.
What it changes
For a | b patterns, creates one goal per alternative, each with its own hypothesis.
When not to use it
When the hypothesis is not an inductive type you want to split.
Common mistakes
  • Forgetting that each alternative creates its own goal that must be finished.
Alternatives
  • cases h with | inl hp => … | inr hq => …
  • Or.elim h f g
beginner
Open in Playground →
example (P Q : Prop) (h : P ∨ Q) : Q ∨ P := by
  rcases h with hp | hq
  · exact Or.inr hp
  · exact Or.inl hq
intermediate
Open in Playground →
example (P Q R : Prop) (h : (P ∧ Q) ∨ R) : P ∨ R := by
  rcases h with ⟨hp, _⟩ | hr
  · left
    exact hp
  · right
    exact hr

Practise: OR is commutativeProof by cases

left / right

Level 2core Lean 4.36

Prove an OR by choosing which side you will prove.

Formal role
Applies the first (Or.inl) or second (Or.inr) constructor of a two-constructor type.
Goal must be
The goal must be an inductive type with exactly two constructors, such as P ∨ Q.
What it changes
The goal P ∨ Q becomes P (left) or Q (right).
When not to use it
When you do not yet know which side holds: first split on a hypothesis with rcases or by_cases.
Common mistakes
  • Choosing the side you cannot prove; there is no going back except by undoing the step.
Alternatives
  • exact Or.inl h
  • exact Or.inr h
beginner
Open in Playground →
example (P Q : Prop) (hq : Q) : P ∨ Q := by
  right
  exact hq

Practise: Prove an OR

by_cases

Level 3core Lean 4.36

Split the proof into two cases: either P holds or it does not.

Formal role
Case analysis on a decidable (or, classically, any) proposition, giving h : P and h : ¬P.
Goal must be
Any goal.
What it changes
Two goals, one with h : P and one with h : ¬P.
When not to use it
When the case split is already given by a hypothesis P ∨ Q: use rcases.
Common mistakes
  • Forgetting to name the hypothesis (by_cases h : P).
Alternatives
  • rcases Classical.em P with h | h
  • if-then-else in term mode
intermediate
Open in Playground →
example (n : Nat) : n = 0 ∨ n > 0 := by
  by_cases h : n = 0
  · left
    exact h
  · right
    omega

by_contra

Level 3needs Mathlib.Tactic.ByContra

Prove something by assuming it is false and deriving a contradiction.

Formal role
Classical reductio: turns the goal P into False with hypothesis ¬P.
Goal must be
Any proposition goal.
What it changes
Adds h : ¬P and changes the goal to False.
When not to use it
When a direct, constructive proof exists.
Common mistakes
  • Using contradiction-style proofs where a direct proof would be clearer.
Alternatives
  • Classical.byContradiction (core term)
  • exfalso then derive False

Not in core Lean 4.36. Available with Mathlib, which this environment does not include yet (Phase 5).

exists

Level 3core Lean 4.36

Prove a 'there exists' statement by naming the witness.

Formal role
∃-introduction: supplies the witness, leaving the property of that witness as the goal.
Goal must be
The goal must be ∃ x, P x (or another single-constructor type taking a value).
What it changes
The goal ∃ x, P x becomes P w for the witness w; trivial goals are closed automatically.
When not to use it
When you do not know the witness yet: first work out which value makes the property true.
Common mistakes
  • Choosing a witness that only works in some cases; for ∀ x, ∃ y, the witness may depend on x.
Alternatives
  • exact ⟨w, proof⟩ (anonymous constructor)
  • refine ⟨w, ?_⟩
beginner
Open in Playground →
example : ∃ n : Nat, n + 2 = 5 := by
  exists 3
intermediate
Open in Playground →
example : ∀ n : Nat, ∃ m, n < m := by
  intro n
  exists n + 1
  omega

Practise: Every number has a bigger one

specialize

Level 3core Lean 4.36

Apply a 'for all' hypothesis to a particular value, replacing it with that instance.

Formal role
∀-elimination on a hypothesis: h : ∀ x, P x becomes h : P a.
Goal must be
Any goal; the hypothesis must be a ∀ statement or an implication.
What it changes
Replaces the hypothesis by its instance at the given arguments.
When not to use it
When you need the ∀ statement more than once: keep it and apply it as a function.
Common mistakes
  • specialize replaces h; if you still need the general statement, use have h3 := h 3 instead.
Alternatives
  • exact h 3 (application)
  • have h3 := h 3
beginner
Open in Playground →
example (P : Nat → Prop) (h : ∀ x, P x) : P 3 := by
  specialize h 3
  exact h

Practise: Passing a property along

basics

exact

Level 2core Lean 4.36

Close the goal by giving something that is exactly a proof of it.

Formal role
Supplies a term whose type is (definitionally) equal to the goal.
Goal must be
Any goal, as long as you have a term of exactly that type.
What it changes
Closes the current goal. Fails with a type mismatch if the term proves something else.
When not to use it
When the term needs further arguments you have not built yet: use apply or refine.
Common mistakes
  • Giving a hypothesis with a similar but different type (for example P instead of Q).
  • Using exact when the goal still has an implication that needs intro first.
Alternatives
  • assumption (finds the matching hypothesis automatically)
  • apply (when the term only proves the goal after more arguments)
beginner
Open in Playground →
example (P Q : Prop) (hp : P) (hq : Q) : Q := by
  exact hq
intermediate
Open in Playground →
example (P Q : Prop) (hp : P) (hq : Q) : P ∧ Q := by
  exact ⟨hp, hq⟩
advancedAny term works, including function applications.
Open in Playground →
example (P Q R : Prop) (f : P → Q) (g : Q → R) (hp : P) : R := by
  exact g (f hp)

Practise: P → Q → QFill in the missing step

equality

rfl

Level 2core Lean 4.36

Prove that two things are equal when they are literally the same, or compute to the same thing.

Formal role
Closes goals a = b (and other reflexive relations) when a and b are definitionally equal.
Goal must be
The goal must be a reflexive relation such as a = b, a ↔ a, or a ≤ a for types where rfl is registered.
What it changes
Closes the goal or fails.
When not to use it
When the two sides are equal only because of a theorem (like commutativity).
Common mistakes
  • Expecting rfl to prove equations that need reasoning, such as a + b = b + a for variables.
Alternatives
  • decide (for decidable closed statements)
  • simp
  • omega (for arithmetic)
beginner
Open in Playground →
example : 2 + 2 = 4 := by
  rfl
intermediate
Open in Playground →
def double (n : Nat) : Nat := n + n

example : double 3 = 6 := by
  rfl

Practise: double 21 = 42

rw

Level 3core Lean 4.36

Replace one side of an equation by the other, inside the goal.

Formal role
Rewrites with an equation h : a = b using Eq.mpr; tries rfl afterwards.
Goal must be
The left side of the equation (or the right side, with ←) must appear in the goal.
What it changes
Every occurrence of a in the goal becomes b. Closes the goal if it becomes a = a.
When not to use it
Under binders (inside fun or ∀) rw often cannot rewrite; use simp only [h].
Common mistakes
  • The pattern does not appear in the goal exactly (rw does not look through definitions).
  • Rewriting in the wrong direction; use ← h.
Alternatives
  • simp [h]
  • calc chains
  • subst h (when h : x = e with a variable x)
beginner
Open in Playground →
example (a b : Nat) (h : a = b) : a + 1 = b + 1 := by
  rw [h]
intermediate
Open in Playground →
example (a b c : Nat) (h1 : a = b) (h2 : b = c) : a = c := by
  rw [h1, h2]
advanced← rewrites from right to left; library lemmas can be used too.
Open in Playground →
example (a b : Nat) (h : b = a) : a + 0 = b := by
  rw [Nat.add_zero, ← h]

calc

Level 3core Lean 4.36

Write a chain of equalities (or inequalities), each step with its own justification.

Formal role
Composes a sequence of relation proofs by transitivity (Trans instances).
Goal must be
The goal is a relation a R b; each step's relation must compose (=, ≤, <, …).
What it changes
Closes the goal when the chain starts at a, ends at b and every step is proved.
When not to use it
For one-step goals: a single rw or exact is clearer.
Common mistakes
  • The first line must start with the left side of the goal and the last must end with the right side.
Alternatives
  • rw with several equations
  • Eq.trans
  • omega for linear arithmetic
intermediate
Open in Playground →
example (a b c d : Nat) (h1 : a = b) (h2 : b = c + 1) (h3 : c + 1 = d) : a = d :=
  calc a = b := h1
    _ = c + 1 := h2
    _ = d := h3
advancedSteps may mix = and ≤; each step can use any tactic.
Open in Playground →
example (a b : Nat) (h : a ≤ b) : a + 1 ≤ b + 2 :=
  calc a + 1 ≤ b + 1 := by omega
    _ ≤ b + 2 := by omega

Practise: Rewriting with lemmas

unfold

Level 3core Lean 4.36

Replace a defined name in the goal by its definition.

Formal role
Delta/equation-lemma unfolding of the named definitions.
Goal must be
The goal mentions the definition.
What it changes
The definition's body (or its matching equation) appears in the goal.
When not to use it
When a lemma about the definition already says what you need: use the lemma.
Common mistakes
  • Unfolding too much makes goals unreadable; unfold only what the next step needs.
Alternatives
  • simp only [f]
  • rw [f] (one equation at a time)
  • show with the unfolded goal
beginner
Open in Playground →
def double (n : Nat) : Nat := n + n

example (n : Nat) : double n = 2 * n := by
  unfold double
  omega

Practise: The specification of max

automation

simp

Level 3core Lean 4.36

Simplify the goal using a large set of known rewriting rules.

Formal role
Rewrites with @[simp] lemmas (plus any you pass) to a normal form; closes the goal if it becomes True.
Goal must be
Any goal; works best on equations and propositions with obvious simplifications.
What it changes
The goal becomes simpler, or is closed. Fails if nothing changes.
When not to use it
When you need precise control over which rewrite happens.
Common mistakes
  • Relying on simp in a way that makes the proof fragile when the library changes; consider simp only [...] for stable proofs.
Alternatives
  • simp only [lemmas]
  • rw
  • omega for arithmetic
beginner
Open in Playground →
example (n : Nat) : n + 0 = n := by
  simp
intermediate
Open in Playground →
example (xs : List Nat) : (xs ++ []).length = xs.length := by
  simp
advancedPass extra facts in brackets.
Open in Playground →
example (f : Nat → Nat) (h : ∀ x, f x = x) : f (f 2) = 2 := by
  simp [h]

Practise: Arithmetic with omega

decide

Level 3core Lean 4.36

Let Lean compute whether a statement with no variables is true.

Formal role
Evaluates a Decidable instance in the kernel; succeeds when it reduces to isTrue.
Goal must be
A closed proposition with a Decidable instance that the kernel can evaluate quickly.
What it changes
Closes the goal or fails.
When not to use it
For statements about all numbers; use induction or omega.
Common mistakes
  • Using decide on goals with free variables: there is nothing to compute.
  • Very large computations hit resource limits.
Alternatives
  • rfl
  • norm_num (Mathlib)
  • native_decide (trusts the compiler: not allowed in exercises)
beginner
Open in Playground →
example : 10 < 20 := by
  decide
intermediate
Open in Playground →
example : (List.range 5).sum = 10 := by
  decide

Practise: double 21 = 42

grind

Level 4core Lean 4.36

A powerful automated prover that combines equality reasoning, case splits and arithmetic.

Formal role
SMT-style proof search (congruence closure, E-matching, linear arithmetic) in core Lean.
Goal must be
Any goal; succeeds on many routine goals.
What it changes
Closes the goal or fails with diagnostic information.
When not to use it
In beginner exercises whose point is the individual steps.
Common mistakes
  • Using grind while learning hides the reasoning you are trying to practise.
Alternatives
  • omega
  • simp
  • a manual proof
intermediate
Open in Playground →
example (a b : Nat) : a + b = b + a := by
  grind

exact?

Level 3core Lean 4.36

Search the library for a lemma that closes the goal, and suggest the exact call.

Formal role
Library search: tries lemmas whose conclusion unifies with the goal, using local hypotheses.
Goal must be
Any goal; works best when a single library lemma fits.
What it changes
Prints a suggestion such as 'Try this: exact Nat.lt_succ_of_le h' (the proof still uses exact?).
When not to use it
In final proofs: paste the suggested line instead.
Common mistakes
  • Leaving exact? in a finished proof: it is slow and may find a different lemma after updates.
Alternatives
  • apply?
  • simp?
  • rw? (suggest rewrites)
intermediateThis is the line exact? suggests here. Replace exact? with its suggestion to make the proof fast and stable.
Open in Playground →
example (a b : Nat) (h : a ≤ b) : a < b + 1 := by
  exact Nat.lt_succ_of_le h

arithmetic

omega

Level 3core Lean 4.36

Automatically prove facts about +, −, constants and comparisons of whole numbers.

Formal role
A decision procedure for linear arithmetic over Int and Nat (Presburger arithmetic fragments).
Goal must be
Goal and relevant hypotheses must be linear (no multiplication of two variables) over Nat/Int.
What it changes
Closes the goal or fails, reporting a possible counterexample.
When not to use it
For non-linear goals or goals about structures other than Nat/Int.
Common mistakes
  • Expecting omega to handle x * y with two variables (non-linear).
Alternatives
  • decide for small closed goals
  • simp
  • linarith (Mathlib, ordered fields)
beginner
Open in Playground →
example (a b : Nat) (h : a < b) : a + 1 ≤ b := by
  omega
intermediateMultiplication by a constant is linear.
Open in Playground →
example (n : Nat) : n * 2 = n + n := by
  omega

Practise: Arithmetic with omega

induction

induction

Level 3core Lean 4.36

Prove something for every natural number (or list, or tree) by proving a base case and a step.

Formal role
Applies the recursor of an inductive type, creating one goal per constructor with induction hypotheses.
Goal must be
The goal mentions a variable of an inductive type (Nat, List, …).
What it changes
Creates goals for each constructor, e.g. zero and succ with an induction hypothesis.
When not to use it
When a direct computation or library lemma already proves the goal.
Common mistakes
  • Introducing too many variables before induction, which makes the induction hypothesis too weak.
Alternatives
  • fun_induction (follows a function's recursion)
  • Nat.rec in term mode
  • omega for linear facts
intermediate
Open in Playground →
example (n : Nat) : 0 + n = n := by
  induction n with
  | zero => rfl
  | succ k ih => rw [Nat.add_succ, ih]
advanced
Open in Playground →
def sumTo : Nat → Nat
  | 0 => 0
  | n + 1 => sumTo n + (n + 1)

example (n : Nat) : 2 * sumTo n = n * (n + 1) := by
  induction n with
  | zero => rfl
  | succ k ih =>
    simp only [sumTo]
    rw [Nat.mul_add, ih]
    simp only [Nat.mul_add, Nat.add_mul, Nat.mul_one, Nat.one_mul]
    omega

structure

split

Level 3core Lean 4.36

Split a goal containing if-then-else (or match) into one goal per branch.

Formal role
Case analysis on the condition of an ite/dite or the discriminant of a match in the goal.
Goal must be
The goal contains an if-then-else or a match.
What it changes
One goal per branch, each with the branch condition as a hypothesis.
When not to use it
When simp can decide the condition directly from the hypotheses.
Common mistakes
  • split acts on the goal; for an if inside a hypothesis use split at h, or by_cases on the condition.
Alternatives
  • by_cases h : c, then simp [h]
  • cases on the match discriminant
intermediate
Open in Playground →
example (a b : Nat) : (if a ≤ b then b else a) ≥ a := by
  split <;> omega

Practise: The specification of maxInsertion adds one element

have

Level 2core Lean 4.36

State and prove an intermediate fact, then use it in the rest of the proof.

Formal role
Introduces a local hypothesis (a let-bound proof term) of the stated type.
Goal must be
Any goal.
What it changes
Adds h : T to the context after T is proved (inline with := or as a new goal).
When not to use it
When the fact is used once and the proof is short: pass the term directly.
Common mistakes
  • Forgetting to give the fact a name, then being unable to refer to it (it is called this).
Alternatives
  • obtain for destructuring
  • calc for chains
  • a separate lemma for reusable facts
beginner
Open in Playground →
example (n : Nat) (h : n > 5) : n > 2 := by
  have h2 : 5 > 2 := by decide
  omega
intermediateBreaking a proof into named steps makes it easier to read and to repair.
Open in Playground →
example (P Q R : Prop) (hpq : P → Q) (hqr : Q → R) (hp : P) : R := by
  have hq : Q := hpq hp
  exact hqr hq

Practise: Use what you have