intro
∴Level 2✓core Lean 4.36Assume 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
example (P : Prop) : P → P := by
intro h
exact h
intermediateintro accepts several names at once. example (P Q R : Prop) : P → Q → R → Q := by
intro hp hq hr
exact hq
advancedFor ∀, intro introduces an arbitrary object. example : ∀ n : Nat, n + 0 = n := by
intro n
rfl
Practise: P → Q → QFill in the missing step
apply
∴Level 2✓core Lean 4.36Work 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 ?_
example (P Q : Prop) (hpq : P → Q) (hp : P) : Q := by
apply hpq
exact hp
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 2✓core Lean 4.36Prove 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 ⟨?_, ?_⟩
example (P Q : Prop) (hp : P) (hq : Q) : P ∧ Q := by
constructor
· exact hp
· exact hq
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 2✓core Lean 4.36Take 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 => …
example (P Q : Prop) (h : P ∧ Q) : Q := by
obtain ⟨hp, hq⟩ := h
exact hq
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 3✓core Lean 4.36Split 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
example (P Q : Prop) (h : P ∨ Q) : Q ∨ P := by
rcases h with hp | hq
· exact Or.inr hp
· exact Or.inl hq
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 2✓core Lean 4.36Prove 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
example (P Q : Prop) (hq : Q) : P ∨ Q := by
right
exact hq
Practise: Prove an OR
by_cases
∴Level 3✓core Lean 4.36Split 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
example (n : Nat) : n = 0 ∨ n > 0 := by
by_cases h : n = 0
· left
exact h
· right
omega
by_contra
∴Level 3?needs Mathlib.Tactic.ByContraProve 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 3✓core Lean 4.36Prove 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, ?_⟩
example : ∃ n : Nat, n + 2 = 5 := by
exists 3
example : ∀ n : Nat, ∃ m, n < m := by
intro n
exists n + 1
omega
Practise: Every number has a bigger one
specialize
∴Level 3✓core Lean 4.36Apply 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
example (P : Nat → Prop) (h : ∀ x, P x) : P 3 := by
specialize h 3
exact h
Practise: Passing a property along