Stage 07 · Step 35 of 50

Different inputs stay different.

Core Lean12 minutesLean 4.36.0

01The idea

A numbered ticket machine should never give the same new ticket to two different old tickets. An injective function has that property.

Goalie · Your guide for this idea
Goalie pointing

Equal outputs force equal inputs.

02In maths

The function sending n to n + 1 is injective on natural numbers.

Picture it

Injective: arrows never land on the same outputLeft panel, bump sends n to n + 1: inputs 0, 1, 2, 3, 4 each have an arrow to a different output 1, 2, 3, 4, 5. No two arrows land in the same place, so bump is injective. Right panel, for contrast, a constant function sends every input 0 to 4 to the output 0. All five arrows collide at 0, so it is not injective. Bottom: the proof. The hypothesis h : bump a = bump b becomes h : a + 1 = b + 1 after unfold bump at h, and omega then finishes the goal a = b, leaving no goals.bump n = n + 1INPUTOUTPUT0112233445every arrow has its own landing spotfor contrast: a constant functionINPUTOUTPUT012340arrows collide: not injectiveh : bump a = bump bunfold bump at hh : a + 1 = b + 1omegano goalssame output forces the same input: take 1 from both sides

Swipe sideways to see the whole picture.

A function is injective when no two different inputs share an output: picture the arrows, and none of them collide. bump passes that test, while a constant function fails it badly. In Lean, unfold bump at h shows what h really says, a + 1 = b + 1, and omega takes 1 from both sides to get a = b.

03In Lean

This code comes directly from the file checked by Lean.

E35.leanTry it live (opens official Lean editor)
def bump (n : Nat) : Nat := n + 1

theorem bump_injective (a b : Nat) (h : bump a = bump b) : a = b := by
  unfold bump at h
  omega

A function is injective when equal outputs imply equal inputs. The theorem states that property explicitly for bump.

The tactic unfold replaces a defined name with its defining expression. Here it unfolds the function in a hypothesis.

After that step, the remaining claim is a linear arithmetic consequence.

04Step by step

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

After line 3
a b : Nat
h : bump a = bump b
⊢ a = b
After line 3: theorem bump_injective (a b : Nat) (h : bump a = bump b) : a = b := by
a b : Nat
h : bump a = bump b
⊢ a = b
After line 4: unfold bump at h
a b : Nat
h : a + 1 = b + 1
⊢ a = b
After line 5: omega
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

    Cancel the same addition of two from both sides.

  2. A little stretch

    Cancel multiplication by two over the natural numbers.

Exercises/E35.leanTry it live (opens official Lean editor)
example (a b : Nat) (h : a + 2 = b + 2) : a = b := by
  sorry

example (a b : Nat) (h : 2*a = 2*b) : a = b := by
  sorry

08A quick check

1. What does injective mean?

Read the answer and explanation

Equal outputs imply equal inputs. The definition prevents two different inputs from sharing an output.

2. Is every function injective?

Read the answer and explanation

No. For example, a constant function on Nat maps different inputs to the same output.

One more idea in your toolkit.

Take your time. Progress is yours to mark.