Stage 08 · Step 37 of 50
Odd squared stays odd.
01The idea
An odd row has pairs plus one extra item. Squaring such a row still leaves one extra after pairing.
Expanding the expression reveals a suitable witness.
02In maths
The square of an odd natural number is odd.
Picture it
Swipe sideways to see the whole picture.
n = 2k + 1 and draw n² as a square. The big block and the two strips split perfectly into pairs, so only the corner square is left over: that is the “+1” that makes n² odd. The number of pairs, 2*k^2 + 2*k, is the witness, and ring checks the algebra after rw [hk].03In Lean
This code comes directly from the file checked by Lean.
module
import Mathlib.Algebra.Ring.Parity
import Mathlib.Tactic.Ring
example (n : ℕ) (h : Odd n) : Odd (n^2) := by
obtain ⟨k, hk⟩ := h
refine ⟨2*k^2 + 2*k, ?_⟩
rw [hk]
ring
A natural number is odd when it has the form twice a natural number plus one.
Unpack the original witness, square its expression, and look for twice another natural number plus one.
The witness in the source may look longer than the statement. The final polynomial identity checks that it has exactly the required property.
04Step by step
Choose a line to see Lean’s recorded goal state after that line.
n : ℕ h : Odd n ⊢ Odd (n ^ 2)
After line 6: example (n : ℕ) (h : Odd n) : Odd (n^2) := by
n : ℕ h : Odd n ⊢ Odd (n ^ 2)
After line 7: obtain ⟨k, hk⟩ := h
n k : ℕ hk : n = 2 * k + 1 ⊢ Odd (n ^ 2)
After line 8: refine ⟨2*k^2 + 2*k, ?_⟩
n k : ℕ hk : n = 2 * k + 1 ⊢ n ^ 2 = 2 * (2 * k ^ 2 + 2 * k) + 1
After line 9: rw [hk]
n k : ℕ hk : n = 2 * k + 1 ⊢ (2 * k + 1) ^ 2 = 2 * (2 * k ^ 2 + 2 * k) + 1
After line 10: ring
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.
module
import Mathlib.Algebra.Ring.Parity
example : Odd (4 : ℕ) := by
exact ⟨2, rfl⟩
Application type mismatch: The argument rfl has type ?m.11 = ?m.11 but is expected to have type 4 = 2 * 2 + 1 in the application Exists.intro 2 rfl
The witness gives twice two plus one, which is five rather than four.
The fix: An odd witness must satisfy the exact oddness equation.
07Your turn
sorry is a placeholder for unfinished work. Replace it as you solve each task. A finished proof has no placeholders.
- Warm-up
Give a witness showing that nine is odd.
Show a hint
Write nine as twice a natural number plus one.
One more hint
Choose four as the witness.
- A little stretch
Prove that twice k plus one is odd.
Show a hint
The statement already displays the required form.
One more hint
Use k itself as the witness.
module
import Mathlib.Algebra.Ring.Parity
import Mathlib.Tactic.Ring
example : Odd (9 : ℕ) := by
sorry
example (k : ℕ) : Odd (2*k + 1) := by
sorry
Compare with the checked solutions
There are often several valid proofs. These solutions were compiled with the same pinned Lean version.
module
import Mathlib.Algebra.Ring.Parity
import Mathlib.Tactic.Ring
example : Odd (9 : ℕ) := by
exact ⟨4, rfl⟩
example (k : ℕ) : Odd (2*k + 1) := by
exact ⟨k, rfl⟩
no goals
08A quick check
09New words & tools
Take your time. Progress is yours to mark.