Stage 08 · Step 37 of 50

Odd squared stays odd.

Needs Mathlib12 minutesLean 4.36.0

01The idea

An odd row has pairs plus one extra item. Squaring such a row still leaves one extra after pairing.

Tacto · Your guide for this idea
Tacto pointing

Expanding the expression reveals a suitable witness.

02In maths

The square of an odd natural number is odd.

Picture it

Odd squared: pairs everywhere except one corner squareA square of side n = 2k + 1, drawn for k = 2, so it is 5 by 5. Its side splits into 2k and 1. The 2k by 2k block is covered by 2k squared teal dominoes, here 8. The two 2k by 1 strips are covered by 2k gold dominoes, here 4. Only the single corner square is left over. So n squared is 2 times (2k squared + 2k) plus 1, here 25 = 2 times 12 plus 1. The witness 2*k^2 + 2*k is given with refine, and the goal (2 * k + 1) ^ 2 = 2 * (2 * k ^ 2 + 2 * k) + 1 is checked by ring.2k12k11drawn for k = 2: side 5, area 25hk : n = 2 * k + 12k × 2k block: 2k² dominoestwo 2k × 1 strips: 2k dominoesone corner square: +1, the odd one outCount the dominoes: 2k² + 2k pairs, plus 1.For k = 2 that is 8 + 4 = 12 pairs: 25 = 2 × 12 + 1.refine ⟨2*k^2 + 2*k, ?_⟩⊢ (2 * k + 1) ^ 2 = 2 * (2 * k ^ 2 + 2 * k) + 1ring

Swipe sideways to see the whole picture.

Write the odd number as 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.

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

After line 6
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

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

    Give a witness showing that nine is odd.

  2. A little stretch

    Prove that twice k plus one is odd.

Exercises/E37.leanTry it live (opens official Lean editor)
module

import Mathlib.Algebra.Ring.Parity
import Mathlib.Tactic.Ring

example : Odd (9 : ℕ) := by
  sorry

example (k : ℕ) : Odd (2*k + 1) := by
  sorry

08A quick check

1. What form does the odd witness give?

Read the answer and explanation

n = 2k + 1. The witness accounts for pairs and one extra item.

2. What is the role of ring at the end?

Read the answer and explanation

Check the polynomial equality for the chosen witness. The existence proof already names its witness. Ring verifies its defining equation.

One more idea in your toolkit.

Take your time. Progress is yours to mark.