Stage 04 · Step 19 of 50

For every input.

Core Lean8 minutesLean 4.36.0

01The idea

A rule for every locker applies to locker three too. A universally quantified claim must cover every input.

Goalie · Your guide for this idea
Goalie pointing

You can also specialize such a claim to one input.

02In maths

Every natural number equals itself. A property holding for every natural number holds at three.

Picture it

“For all”: answer any challenge, or use the rule at one inputTop row, proving a for-all statement: the goal is for all n : Nat, n = n. The tactic intro n hands you an arbitrary natural number n, one you know nothing special about, and the goal becomes n = n. The tactic rfl closes it, leaving no goals. Bottom row, using a for-all statement: h : for all n : Nat, P n is drawn as a machine that accepts any natural number. The tactic specialize h 3 feeds it the number 3, and h becomes h : P 3, a fact about 3. exact h then finishes the goal P 3, shown by a green tick.START⊢ ∀ (n : Nat), n = nintro nAN ARBITRARY nn : Nat⊢ n = nrflDONEno goalsUSING A ∀3any Nat fitsspecialize h 3h : ∀ (n : Nat), P na rule for every nh : P 3a fact about 3exact h

Swipe sideways to see the whole picture.

A “for all” claim is a challenge: whatever number someone picks, you must win. intro n hands you a mystery number n that you know nothing about, so your proof works for every choice. Once you have a “for all” rule, you can use it at any number you like: specialize h 3 turns h into a fact about 3.

03In Lean

This code comes directly from the file checked by Lean.

E19.leanTry it live (opens official Lean editor)
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

The symbol ∀ means “for all.” Type it with \forall. It is the universal quantifier.

Introducing its variable gives you an arbitrary input. You cannot assume special properties that were not stated.

The tactic specialize applies an available universal hypothesis to a chosen argument, replacing that hypothesis with the specialized result.

04Step by step

Choose a line to see Lean’s recorded goal state after that line.

After line 1
⊢ ∀ (n : Nat), n = n
After line 1: example : ∀ n : Nat, n = n := by
⊢ ∀ (n : Nat), n = n
After line 2: intro n
n : Nat
⊢ n = n
After line 3: rfl
no goals
After line 5: example (P : Nat → Prop) (h : ∀ n, P n) : P 3 := by
P : Nat → Prop
h : ∀ (n : Nat), P n
⊢ P 3
After line 6: specialize h 3
P : Nat → Prop
h : P 3
⊢ P 3
After line 7: exact h
no goals

05Lean says

Captured from Lean 4.36.0
no goals

A goal is what remains to prove. The symbol ⊢ points to it. Meet the turnstile.

07Your turn

sorry is a placeholder for unfinished work. Replace it as you solve each task. A finished proof has no placeholders.

  1. Warm-up

    Prove that every natural number plus zero equals itself.

  2. A little stretch

    Use one universal hypothesis to prove the property at two and at five.

Exercises/E19.leanTry it live (opens official Lean editor)
example : ∀ n : Nat, n + 0 = n := by
  sorry

example (P : Nat → Prop) (h : ∀ n, P n) : P 2 ∧ P 5 := by
  sorry

08A quick check

1. What does ∀ mean?

Read the answer and explanation

For all. The statement covers every input of the named type. Type it with \forall.

2. Can you prove a universal claim by checking only three?

Read the answer and explanation

No. You must reason about an arbitrary input or use a theorem covering all inputs.

One more idea in your toolkit.

Take your time. Progress is yours to mark.