Stage 07 · Step 35 of 50
Different inputs stay different.
01The idea
A numbered ticket machine should never give the same new ticket to two different old tickets. An injective function has that property.
Equal outputs force equal inputs.
02In maths
The function sending n to n + 1 is injective on natural numbers.
Picture it
Swipe sideways to see the whole picture.
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.
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.
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
no goals
A goal is what remains to prove. The symbol ⊢ points to it. Meet the turnstile.
06A common slip
Lean is telling us something useful here.
def slipConstant (_n : Nat) : Nat := 0
example (a b : Nat) (_h : slipConstant a = slipConstant b) : a = b := by
rfl
Tactic `rfl` failed: The left-hand side a is not definitionally equal to the right-hand side b a b : Nat _h : slipConstant a = slipConstant b ⊢ a = b
Equal outputs of a constant function do not force equal inputs.
The fix: Check the injectivity claim. The worked function adds one instead of discarding its input.
07Your turn
sorry is a placeholder for unfinished work. Replace it as you solve each task. A finished proof has no placeholders.
- Warm-up
Cancel the same addition of two from both sides.
Show a hint
The hypothesis relates the two inputs linearly.
One more hint
omega can cancel the matching constant contribution.
- A little stretch
Cancel multiplication by two over the natural numbers.
Show a hint
The multiplier is the fixed positive number two.
One more hint
omega handles the resulting linear equality.
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
Compare with the checked solutions
There are often several valid proofs. These solutions were compiled with the same pinned Lean version.
example (a b : Nat) (h : a + 2 = b + 2) : a = b := by
omega
example (a b : Nat) (h : 2*a = 2*b) : a = b := by
omega
no goals
08A quick check
09New words & tools
Take your time. Progress is yours to mark.