Tutorials/Day 1/28 November 2026
Tactics, definitional equality, and induction
Today Lean is treated as a language: first a small vocabulary, then complete sentences. Why can n + 0 be proved with rfl, while 0 + n needs induction?
1How a Lean sentence is built
example (what you are given) : what you must show := by
tactics
How to read this:
exampleandtheoremboth state a proposition;examplehas no name, and is useful for practice(n : Nat)is given input, read as “letnbe a natural number”; it is not part of the proof- After the colon comes the claim to be proved
:=means “the proof is as follows”byenters tactic mode: instead of writing a complete proof object, you prove the claim with a sequence of instructions- Those instructions are called tactics. After each step, the goal in Infoview changes. The proof is genuinely finished only when Infoview shows
No goalsand there is no yellow warning
Nat is a noun type (a number); Prop is a sentence type (a proposition, which may be true or false). (h : n = 0) is a hypothesis, a proposition; (n : Nat) only introduces a number.
2Today’s vocabulary
| Lean | Reading |
|---|---|
example / theorem | State a proposition |
:= by | The proof follows, written with tactics |
rfl | Reflexivity: after both sides are reduced, they are the same thing |
rw [eq] | Rewrite: use an equality to change the goal |
sorry | Leave this step blank for now; Lean issues a yellow warning |
induction n with | Induct on n |
zero / succ | The two shapes of a natural number: zero, and a successor (n + 1) |
ih | Only a name for the inductive hypothesis, not a keyword; you may choose another name |
⊢ | The turnstile. In Infoview, read it as “from the facts above, prove the claim that follows” |
You do not usually type ⊢ yourself; Infoview displays it. To enter it, type \vdash or \|-, then press space.
succ is not a keyword either. It is the successor constructor of Nat, meaning “the next number after n”, that is, n + 1. You can also write Nat.succ.
3Look at Infoview before writing the next step
Infoview is Lean talking to you:
- Above
⊢are the known facts (hypotheses) - After
⊢is the current goal, what still has to be proved
Place the cursor after by to see the real goal. If the cursor sits on sorry, Infoview may show No goals, because sorry pretends the goal is already done. In that case the declaration carries the yellow warning declaration uses sorry, and the proof is still empty.
4rfl and definitional equality
example : 1 + 1 = 2 := by rfl
example (n : Nat) : n + 0 = n := by
rfl
rfl succeeds because Lean computes (unfolds) both sides and obtains the same thing: 1 + 1 computes to 2, and n + 0 computes to n. This kind of equality is called definitional equality.
5Why 0 + n cannot use rfl: pattern matching
In mathematics, 0 + n and n + 0 are both equal to n; there is no difference. The difference appears in how addition is defined in Lean.
Pattern matching first looks at the shape of a value, then treats each constructor separately. A natural number has only two shapes: it is either 0, or the successor of some number, n + 1.
Lean’s addition on natural numbers pattern-matches on the right-hand argument:
n + 0 = n
n + (m + 1) = (n + m) + 1
Therefore:
n + 0matches the first clause exactly, so the definition itself gives the result, andrflcloses the goal (definitional equality)- In
0 + n, the right-hand side is the variablen, which has not yet revealed whether it is zero or a successor. The definition cannot unfold further, so induction is needed. This is a theorem to be proved, not a definition
In short: n + 0 is written into the definition; 0 + n is a theorem that has to be proved.
6Induction
Induction proves a statement “for every n” by following the two shapes of a natural number:
- The base case (zero): first prove
P(0) - The inductive step (succ): assume
P(n)already holds (the inductive hypothesisih), then proveP(n + 1)
Pattern matching only asks whether the value is zero or a successor. Induction gives you, in addition, the inductive hypothesis, so that in the successor case you can reuse what has already been established for the previous number.
example (n : Nat) : 0 + n = n := by
induction n with
| zero => rfl
| succ n ih =>
rw [Nat.add_succ]
rw [ih]
Line by line:
example (n : Nat) : 0 + n = n := by: letnbe a natural number; prove0 + n = nwith tactics. The goal isn : Nattogether with⊢ 0 + n = ninduction n with: split into two subgoals according to the two shapes ofn;withmeans you will name the cases yourself| zero => rfl: the base case, wherenis0. The goal becomes0 + 0 = 0, whichrflcloses| succ n ih =>: the successor case. Herenbecomes “the previous number”, andih : 0 + n = nis the inductive hypothesis. The goal is0 + n.succ = n.succ, that is,0 + (n + 1) = n + 1rw [Nat.add_succ]: the lemmaa + b.succ = (a + b).succrewrites the goal to(0 + n).succ = n.succrw [ih]: the inductive hypothesis replaces0 + nbyn, givingn.succ = n.succ. The two sides agree, and the proof is finished
7Successor on the left: succ_add
The right-hand version Nat.add_succ, namely a + b.succ = (a + b).succ, comes from the definition of addition and has already been used. The left-hand version n.succ + m = (n + m).succ is not given for free. It requires induction on the right-hand argument m (because addition matches on the right).
example (n m : Nat) : n.succ + m = (n + m).succ := by
induction m with
| zero => rfl
| succ m ih =>
rw [Nat.add_succ]
rw [Nat.add_succ]
rw [ih]
Pitfalls
- Do not induct on
n. If you writeinduction n,rflfails in thezerocase, and the goal gets stuck at something like1 + m = (0 + m).succ, because0 + mdoes not compute away - Do not write
rw [Nat.succ_add].Nat.succ_addis precisely this left-successor theorem in the library, so using it is just quoting the finished result, and the laterrw [ih]then fails withNo goals to be solved - A name to remember:
add_succhas the successor on the right of+;succ_addhas the successor on the left - In the successor case you usually need
rw [Nat.add_succ]twice: once to open the addition on the left, once on the right, and only thenrw [ih]
8Today’s practice
Paste the block below into the Lean web editor, place the cursor on each line, and watch how the goal after ⊢ changes in Infoview. It is better to start from sorry yourself, and only then compare.
-- Day 1 practice: tactics, definitional equality, and induction
-- Paste into https://live.lean-lang.org/ or open this file with the Lean 4 extension.
-- Place the cursor on each line and watch how the goal after ⊢ changes in Infoview.
-- 1. rfl: both sides become the same after computation
example : 1 + 1 = 2 := by rfl
-- 2. n + 0 is definitional (addition matches on the 0 at the right)
example (n : Nat) : n + 0 = n := by
rfl
-- 3. 0 + n needs induction: addition does not match on the left
example (n : Nat) : 0 + n = n := by
induction n with
| zero => rfl
| succ n ih =>
rw [Nat.add_succ]
rw [ih]
-- 4. Successor on the left: induct on the right-hand argument m
-- Use Nat.add_succ (successor on the right), not Nat.succ_add
-- (that is the library name of this very statement)
example (n m : Nat) : n.succ + m = (n + m).succ := by
induction m with
| zero => rfl
| succ m ih =>
rw [Nat.add_succ]
rw [Nat.add_succ]
rw [ih]
9Next
The next sentence is commutativity of addition: n + m = m + n. It can put today’s two results, 0 + n and n.succ + m, to use.