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:

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

LeanReading
example / theoremState a proposition
:= byThe proof follows, written with tactics
rflReflexivity: after both sides are reduced, they are the same thing
rw [eq]Rewrite: use an equality to change the goal
sorryLeave this step blank for now; Lean issues a yellow warning
induction n withInduct on n
zero / succThe two shapes of a natural number: zero, and a successor (n + 1)
ihOnly 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:

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:

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:

  1. The base case (zero): first prove P(0)
  2. The inductive step (succ): assume P(n) already holds (the inductive hypothesis ih), then prove P(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:

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 write induction n, rfl fails in the zero case, and the goal gets stuck at something like 1 + m = (0 + m).succ, because 0 + m does not compute away
  • Do not write rw [Nat.succ_add]. Nat.succ_add is precisely this left-successor theorem in the library, so using it is just quoting the finished result, and the later rw [ih] then fails with No goals to be solved
  • A name to remember: add_succ has the successor on the right of +; succ_add has 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 then rw [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.