Riemann hypothesis: the Lean proof, cleaned up together
The 2026 Lean proof of the Riemann hypothesis and GRH, machine-checked by others, not refereed, no word from Clay; cleaned up together: more readable, faster to build, the theorems unchanged

| 1 | module |
| 2 | |
| 3 | public import Lib.Speed |
| 4 | |
| 5 | /-! |
| 6 | # Monotone paths through two square grids, and their turns |
| 7 | |
| 8 | The combinatorics of the paths along which forms are moved through the two grids of unitary groups, |
| 9 | the grid of the `Y^i_j` and the grid of the `Ỹ^i_j`. Here only the indices occur. |
| 10 | |
| 11 | A path goes from `(m, 0)` to `(0, m)` by steps up (`j` grows) or left (`i` falls) and meets the |
| 12 | diagonal once, at some `(l, l)`. Its first half lies in the grid of the `Ỹ` and its second half in |
| 13 | that of the `Y`. Both halves are recorded in one shape, as paths from `(0, m)` to `(l, l)` by steps |
| 14 | down or right. The half in the grid of the `Y` is read backwards, the way conjugate forms move. The |
| 15 | half in the grid of the `Ỹ` is read forwards, the way forms move, with the two indices exchanged: a |
| 16 | step left is recorded as a step down, and a step up as a step right. |
| 17 | |
| 18 | ## Main definitions and results |
| 19 | |
| 20 | * `New.GridPath`: a monotone path in one grid. `New.TwoGridPath`: a path through both grids, given |
| 21 | by two halves that meet on the diagonal. |
| 22 | * `New.TwoGridPath.Turn`: a turn replaces a node `(i, j)` by `(i + 1, j + 1)`. |
| 23 | * `New.TwoGridPath.exists_turn`: every path but the last can be turned. |
| 24 | * `New.TwoGridPath.turn_induction`: induction backwards along turns, one at each `(i, j)` with |
| 25 | `i, j < m`, from the last path to the first. |
| 26 | -/ |
| 27 | |
| 28 | @[expose] public section |
| 29 | |
| 30 | noncomputable section |
| 31 | |
| 32 | namespace New |
| 33 | |
| 34 | open Finset |
| 35 | |
| 36 | /-- A monotone path in a grid from the node `(a₀, b₀)` to the node `(a, b)`: each step lowers the |
| 37 | second index or raises the first. -/ |
| 38 | inductive GridPath (a₀ b₀ : ℕ) : ℕ → ℕ → Type |
| 39 | /-- The path without steps. -/ |
| 40 | | nil : GridPath a₀ b₀ a₀ b₀ |
| 41 | /-- A path followed by the step from `(a, b + 1)` to `(a, b)`. -/ |
| 42 | | down {a b : ℕ} (p : GridPath a₀ b₀ a (b + 1)) : GridPath a₀ b₀ a b |
| 43 | /-- A path followed by the step from `(a, b)` to `(a + 1, b)`. -/ |
| 44 | | right {a b : ℕ} (p : GridPath a₀ b₀ a b) : GridPath a₀ b₀ (a + 1) b |
| 45 | |
| 46 | namespace GridPath |
| 47 | |
| 48 | variable {a₀ b₀ a b a' b' m : ℕ} |
| 49 | |
| 50 | /-- One path followed by another. -/ |
| 51 | def append (p : GridPath a₀ b₀ a b) : ∀ {a' b' : ℕ}, GridPath a b a' b' → GridPath a₀ b₀ a' b' |
| 52 | | _, _, nil => p |
| 53 | | _, _, down q => (p.append q).down |
| 54 | | _, _, right q => (p.append q).right |
| 55 | |
| 56 | /-- The path down the first column, from `(0, m)` to `(0, b)`. -/ |
| 57 | def column (hb : b ≤ m) : GridPath 0 m 0 b := |
| 58 | Nat.decreasingInduction (motive := fun b _ ↦ GridPath 0 m 0 b) (fun _ _ p ↦ p.down) nil hb |
| 59 | |
| 60 | /-- The path along the row `m`, from `(0, m)` to `(a, m)`. -/ |
| 61 | def row (m : ℕ) : ∀ a : ℕ, GridPath 0 m a m |
| 62 | | 0 => nil |
| 63 | | a + 1 => (row m a).right |
| 64 | |
| 65 | /-- The unit squares between the first column and the steps down of a path, each named by its |
| 66 | corner with the least indices: the step from `(a, b + 1)` to `(a, b)` contributes the `(i, b)` with |
| 67 | `i < a`. -/ |
| 68 | def squares : ∀ {a b : ℕ}, GridPath a₀ b₀ a b → Finset (ℕ × ℕ) |
| 69 | | _, _, nil => ∅ |
| 70 | | a, b, down p => p.squares ∪ range a ×ˢ {b} |
| 71 | | _, _, right p => p.squares |
| 72 | |
| 73 | lemma column_self : column (le_refl m) = nil := by |
| 74 | rw [column, Nat.decreasingInduction_self] |
| 75 | |
| 76 | /-- The path down the first column from `(0, m)` to `(0, b)`, for `b < m`, is the one to |
| 77 | `(0, b + 1)` followed by a step down. -/ |
| 78 | lemma column_of_lt (hb : b < m) : column hb.le = (column hb).down := by |
| 79 | rw [column, column, Nat.decreasingInduction_succ_left (smn := hb)] |
| 80 | |
| 81 | /-- Along a path from `(a₀, b₀)` to `(a, b)` the first index does not fall and the second does |
| 82 | not grow. -/ |
| 83 | lemma le_and_le (p : GridPath a₀ b₀ a b) : a₀ ≤ a ∧ b ≤ b₀ := by |
| 84 | induction p <;> omega |
| 85 | |
| 86 | /-- The only path from `(0, m)` to `(a, m)` is `row m a`, the one that stays in the row `m`. -/ |
| 87 | lemma eq_row (p : GridPath 0 m a m) : p = row m a := by |
| 88 | have h_no_down {k : ℕ} (q : GridPath 0 m k (m + 1)) : False := by grind [q.le_and_le] |
| 89 | induction a with |
| 90 | | zero => |
| 91 | cases p with |
| 92 | | nil => rfl |
| 93 | | down q => exact (h_no_down q).elim |
| 94 | | succ a ih => |
| 95 | cases p with |
| 96 | | down q => exact (h_no_down q).elim |
| 97 | | right q => rw [row, ih q] |
| 98 | |
| 99 | /-- The squares to the left of the steps down of `p` followed by `q` are those of `p` and those |
| 100 | of `q`. -/ |
| 101 | lemma squares_append (p : GridPath a₀ b₀ a b) (q : GridPath a b a' b') : |
| 102 | (p.append q).squares = p.squares ∪ q.squares := by |
| 103 | induction q <;> simp [append, squares, *] |
| 104 | |
| 105 | /-- A square `s` to the left of a step down of a path from `(a₀, b₀)` to `(a, b)` lies to the left |
| 106 | of the column `a` and between the rows `b` and `b₀`. -/ |
| 107 | lemma bounds_of_mem_squares {p : GridPath a₀ b₀ a b} {s : ℕ × ℕ} (hs : s ∈ p.squares) : |
| 108 | s.1 < a ∧ b ≤ s.2 ∧ s.2 < b₀ := by |
| 109 | induction p with |
| 110 | | nil => simp [squares] at hs |
| 111 | | down p ih => grind [squares, p.le_and_le] |
| 112 | | right p ih => grind [squares] |
| 113 | |
| 114 | /-- The path along a row has no step down, hence no squares. -/ |
| 115 | lemma squares_row (m a : ℕ) : (row m a).squares = ∅ := by |
| 116 | induction a <;> simp [row, squares, *] |
| 117 | |
| 118 | /-- Let a path follow `q` to `(i, j + 1)`, step down to `(i, j)`, step right to `(i + 1, j)` and |
| 119 | follow `r`. Then the unit square with lower left corner `(i, j)` is not among the `squares` of the |
| 120 | path, the unit squares to the left of its steps down. -/ |
| 121 | lemma notMem_squares_down_right_append {i j : ℕ} (q : GridPath a₀ b₀ i (j + 1)) |
| 122 | (r : GridPath (i + 1) j a b) : (i, j) ∉ (q.down.right.append r).squares := by |
| 123 | have hq : (i, j) ∉ q.squares := fun h ↦ lt_irrefl i (bounds_of_mem_squares h).1 |
| 124 | have hr : (i, j) ∉ r.squares := fun h ↦ lt_irrefl j (bounds_of_mem_squares h).2.2 |
| 125 | simp [squares_append, squares, hq, hr] |
| 126 | |
| 127 | /-- Let a path follow `q` to `(i, j + 1)`, go to `(i + 1, j)` in two steps and follow `r`. If it |
| 128 | passes through `(i + 1, j + 1)` instead of `(i, j)`, then its set of `squares`, the unit squares to |
| 129 | the left of its steps down, gains the square with lower left corner `(i, j)`. -/ |
| 130 | lemma squares_right_down_append {i j : ℕ} (q : GridPath a₀ b₀ i (j + 1)) |
| 131 | (r : GridPath (i + 1) j a b) : |
| 132 | (q.right.down.append r).squares = insert (i, j) (q.down.right.append r).squares := by |
| 133 | simp [squares_append, squares, product_singleton, range_add_one] |
| 134 | |
| 135 | /-- A path from `(a₀, b₀)` to `(a, b)` has a corner `(i, j)`, where it comes down and leaves to the |
| 136 | right, or ends with a step down, or has no step down (`b = b₀`). -/ |
| 137 | lemma exists_corner_or_eq_down_or_eq (p : GridPath a₀ b₀ a b) : |
| 138 | (∃ (i j : ℕ) (q : GridPath a₀ b₀ i (j + 1)) (r : GridPath (i + 1) j a b), |
| 139 | p = q.down.right.append r) ∨ |
| 140 | (∃ q : GridPath a₀ b₀ a (b + 1), p = q.down) ∨ |
| 141 | b = b₀ := by |
| 142 | induction p with |
| 143 | | nil => exact .inr (.inr rfl) |
| 144 | | down p _ => exact .inr (.inl ⟨p, rfl⟩) |
| 145 | | @right a b p ih => |
| 146 | obtain ⟨i, j, q, r, rfl⟩ | ⟨q, rfl⟩ | hb := ih |
| 147 | · exact .inl ⟨i, j, q, r.right, rfl⟩ |
| 148 | · exact .inl ⟨a, b, q, nil, rfl⟩ |
| 149 | · exact .inr (.inr hb) |
| 150 | |
| 151 | end GridPath |
| 152 | |
| 153 | /-- A path from `(m, 0)` to `(0, m)` by steps up or left, through the two grids. It meets the |
| 154 | diagonal at `(l, l)` with `l = diagonalIndex`. Both halves are recorded as paths from `(0, m)` to |
| 155 | `(l, l)`: `half false` is the part after the diagonal read backwards, in the grid of the `Y`, where |
| 156 | `(a, b)` is `Y^a_b`, and `half true` is the part before the diagonal with the two indices |
| 157 | exchanged, in the grid of the `Ỹ`, where `(a, b)` is `Ỹ^b_a`. -/ |
| 158 | structure TwoGridPath (m : ℕ) where |
| 159 | /-- The index `l` of the node `(l, l)` at which the path meets the diagonal. -/ |
| 160 | diagonalIndex : ℕ |
| 161 | /-- The halves in the two grids, each recorded as a path from `(0, m)` to the diagonal node. -/ |
| 162 | half : Bool → GridPath 0 m diagonalIndex diagonalIndex |
| 163 | |
| 164 | namespace TwoGridPath |
| 165 | |
| 166 | variable {m : ℕ} {Γ Γ' : TwoGridPath m} {s : ℕ × ℕ} |
| 167 | |
| 168 | /-- The first path, through `(0, 0)`: it goes left from `Ỹ^m_0` to `Ỹ^0_0` and up from `Y^0_0` to |
| 169 | `Y^0_m`, so both halves are recorded as going down the first column. -/ |
| 170 | def first (m : ℕ) : TwoGridPath m := ⟨0, fun _ : Bool ↦ .column m.zero_le⟩ |
| 171 | |
| 172 | /-- The last path, through `(m, m)`: it goes up from `Ỹ^m_0` to `Ỹ^m_m` and left from `Y^m_m` to |
| 173 | `Y^0_m`, so both halves are recorded as going along the row `m`. -/ |
| 174 | def last (m : ℕ) : TwoGridPath m := ⟨m, fun _ : Bool ↦ .row m m⟩ |
| 175 | |
| 176 | /-- `Turn Γ (i, j) Γ'`: the path `Γ` reaches `(i, j)` from the right and leaves it upwards, and `Γ'` |
| 177 | arises from `Γ` by replacing the node `(i, j)` by `(i + 1, j + 1)`. -/ |
| 178 | inductive Turn : TwoGridPath m → ℕ × ℕ → TwoGridPath m → Prop |
| 179 | /-- A turn off the diagonal, at a corner `(a, b)` where one half comes down and leaves to the |
| 180 | right. For `half true` the node has the indices `(b, a)`. -/ |
| 181 | | inner (Γ : TwoGridPath m) (z : Bool) {a b : ℕ} (q : GridPath 0 m a (b + 1)) |
| 182 | (r : GridPath (a + 1) b Γ.diagonalIndex Γ.diagonalIndex) |
| 183 | (hΓ : Γ.half z = q.down.right.append r) : |
| 184 | Turn Γ (bif z then (b, a) else (a, b)) |
| 185 | ⟨Γ.diagonalIndex, Function.update Γ.half z (q.right.down.append r)⟩ |
| 186 | /-- A turn on the diagonal: both halves end with a step down. -/ |
| 187 | | diagonal {j : ℕ} (q : Bool → GridPath 0 m j (j + 1)) : |
| 188 | Turn ⟨j, fun z : Bool ↦ (q z).down⟩ (j, j) ⟨j + 1, fun z : Bool ↦ (q z).right⟩ |
| 189 | |
| 190 | /-- The unit squares between the first path and `Γ`, each named by its corner with the least |
| 191 | indices: the `(i, j)` with `i, j < Γ.diagonalIndex`, the squares of `Γ.half false`, and the mirror |
| 192 | images in the diagonal of the squares of `Γ.half true`. -/ |
| 193 | def squares (Γ : TwoGridPath m) : Finset (ℕ × ℕ) := |
| 194 | range Γ.diagonalIndex ×ˢ range Γ.diagonalIndex ∪ (Γ.half false).squares ∪ |
| 195 | (Γ.half true).squares.image Prod.swap |
| 196 | |
| 197 | /-- The unit square with least corner `s` lies between the first path, through `(0, 0)`, and the |
| 198 | path `Γ` if and only if both indices of `s` are less than `Γ.diagonalIndex`, or `s` lies to the left |
| 199 | of a step down of `Γ.half false`, or its mirror image `s.swap` lies to the left of a step down of |
| 200 | `Γ.half true`. -/ |
| 201 | lemma mem_squares : s ∈ Γ.squares ↔ |
| 202 | (s.1 < Γ.diagonalIndex ∧ s.2 < Γ.diagonalIndex) ∨ |
| 203 | s ∈ (Γ.half false).squares ∨ |
| 204 | s.swap ∈ (Γ.half true).squares := by |
| 205 | grind [squares] |
| 206 | |
| 207 | /-- A path from `(m, 0)` to `(0, m)` meets the diagonal at a node with indices at most `m`. -/ |
| 208 | lemma diagonalIndex_le (Γ : TwoGridPath m) : Γ.diagonalIndex ≤ m := (Γ.half false).le_and_le.2 |
| 209 | |
| 210 | /-- Let `Γ` be a path from `(m, 0)` to `(0, m)` by steps up or left. The set `Γ.squares` of unit |
| 211 | squares between `Γ` and the path `first m` through `(0, 0)`, each named by its corner `(i, j)` with |
| 212 | the least indices, has only members with `i, j < m`. -/ |
| 213 | lemma squares_subset (Γ : TwoGridPath m) : Γ.squares ⊆ range m ×ˢ range m := by |
| 214 | rintro ⟨i, j⟩ hs |
| 215 | suffices i < m ∧ j < m by simpa |
| 216 | have hl : Γ.diagonalIndex ≤ m := Γ.diagonalIndex_le |
| 217 | obtain ⟨hi : i < Γ.diagonalIndex, hj : j < Γ.diagonalIndex⟩ | h_false | h_true := |
| 218 | mem_squares.mp hs |
| 219 | · omega |
| 220 | · obtain ⟨hi : i < Γ.diagonalIndex, -, hj : j < m⟩ := GridPath.bounds_of_mem_squares h_false |
| 221 | omega |
| 222 | · obtain ⟨hj : j < Γ.diagonalIndex, -, hi : i < m⟩ := GridPath.bounds_of_mem_squares h_true |
| 223 | omega |
| 224 | |
| 225 | /-- No unit square lies between the first path, through `(0, 0)`, and itself. -/ |
| 226 | lemma squares_first : (first m).squares = ∅ := by |
| 227 | grind [squares, first, → GridPath.bounds_of_mem_squares] |
| 228 | |
| 229 | /-- For the last path `last m`, the one through `(m, m)`, the set `(last m).squares` is exactly the |
| 230 | `(i, j)` with `i, j < m`, that is `range m ×ˢ range m`. -/ |
| 231 | lemma squares_last : (last m).squares = range m ×ˢ range m := by |
| 232 | simp [squares, last, GridPath.squares_row] |
| 233 | |
| 234 | /-- Let `Γ` and `Γ'` be paths in `TwoGridPath m` with `Γ.Turn s Γ'`. Then `s ∉ Γ.squares`, and |
| 235 | `Γ'.squares` is `Γ.squares` with `s` inserted. -/ |
| 236 | lemma Turn.squares_eq (h_turn : Γ.Turn s Γ') : |
| 237 | s ∉ Γ.squares ∧ Γ'.squares = insert s Γ.squares := by |
| 238 | cases h_turn with |
| 239 | | @inner _ z a b q r hΓ => |
| 240 | obtain ⟨-, hb : Γ.diagonalIndex ≤ b⟩ := r.le_and_le |
| 241 | have h_notMem : (a, b) ∉ (Γ.half z).squares := by |
| 242 | simpa [hΓ] using GridPath.notMem_squares_down_right_append q r |
| 243 | have h_notMem_swap (z' : Bool) : (b, a) ∉ (Γ.half z').squares := |
| 244 | fun h ↦ hb.not_gt (GridPath.bounds_of_mem_squares h).1 |
| 245 | have h_insert : (q.right.down.append r).squares = insert (a, b) (Γ.half z).squares := by |
| 246 | simp [hΓ, GridPath.squares_right_down_append] |
| 247 | constructor |
| 248 | · cases z <;> simp [mem_squares, hb.not_gt, h_notMem, h_notMem_swap] |
| 249 | · cases z <;> simp [squares, h_insert] |
| 250 | | @diagonal j q => |
| 251 | have h_notMem (z : Bool) : (j, j) ∉ (q z).down.squares := |
| 252 | fun h_mem ↦ lt_irrefl j (GridPath.bounds_of_mem_squares h_mem).1 |
| 253 | have h_block : range (j + 1) ×ˢ range (j + 1) = insert (j, j) |
| 254 | (range j ×ˢ range j ∪ range j ×ˢ {j} ∪ (range j ×ˢ {j}).image Prod.swap) := by |
| 255 | simp only [image_swap_product, range_add_one, ← singleton_union, union_product, product_union, |
| 256 | singleton_product_singleton] |
| 257 | ac_rfl |
| 258 | refine ⟨by simp [mem_squares, h_notMem], ?_⟩ |
| 259 | simp only [squares, GridPath.squares, h_block, image_union, insert_union] |
| 260 | ac_rfl |
| 261 | |
| 262 | /-- If a path from `(m, 0)` to `(0, m)` has a turn at the node `s = (i, j)`, then `i, j < m`. -/ |
| 263 | lemma Turn.mem_product (h_turn : Γ.Turn s Γ') : s ∈ range m ×ˢ range m := by |
| 264 | obtain ⟨-, h_eq⟩ := h_turn.squares_eq |
| 265 | exact Γ'.squares_subset (by simp [h_eq]) |
| 266 | |
| 267 | /-- For `i < j`, a turn at `(i,j)` replaces a down-right corner in `Γ.half false`. |
| 268 | In the reflected half the same corner is recorded at `(j,i)`. -/ |
| 269 | lemma Turn.exists_corner {i j : ℕ} {z : Bool} |
| 270 | (h_turn : Γ.Turn (bif z then (j, i) else (i, j)) Γ') (hij : i < j) : |
| 271 | ∃ (q : GridPath 0 m i (j + 1)) (r : GridPath (i + 1) j Γ.diagonalIndex Γ.diagonalIndex), |
| 272 | Γ.half z = q.down.right.append r ∧ |
| 273 | Γ' = ⟨Γ.diagonalIndex, Function.update Γ.half z (q.right.down.append r)⟩ := by |
| 274 | generalize hs : (bif z then (j, i) else (i, j)) = s at h_turn |
| 275 | cases h_turn with |
| 276 | | @inner _ w a b q r hΓ => |
| 277 | have hab : a + 1 ≤ Γ.diagonalIndex ∧ Γ.diagonalIndex ≤ b := r.le_and_le |
| 278 | cases z <;> cases w <;> cases hs <;> first | exact ⟨q, r, hΓ, rfl⟩ | omega |
| 279 | | diagonal q => cases z <;> grind |
| 280 | |
| 281 | /-- A turn at `(j, j)` takes place on the diagonal: both halves reach `(j, j + 1)`, and their last |
| 282 | step, down to `(j, j)`, is replaced by the step right to `(j + 1, j + 1)`. -/ |
| 283 | lemma Turn.exists_eq_down_and_eq_right {j : ℕ} (h_turn : Γ.Turn (j, j) Γ') : |
| 284 | ∃ q : Bool → GridPath 0 m j (j + 1), |
| 285 | Γ = ⟨j, fun z : Bool ↦ (q z).down⟩ ∧ |
| 286 | Γ' = ⟨j + 1, fun z : Bool ↦ (q z).right⟩ := by |
| 287 | generalize hs : (j, j) = s at h_turn |
| 288 | cases h_turn with |
| 289 | | @inner _ z a b q r hΓ => |
| 290 | have hab : a + 1 ≤ Γ.diagonalIndex ∧ Γ.diagonalIndex ≤ b := r.le_and_le |
| 291 | grind |
| 292 | | diagonal q => |
| 293 | cases hs |
| 294 | exact ⟨q, rfl, rfl⟩ |
| 295 | |
| 296 | /-- Every path `Γ` from `(m, 0)` to `(0, m)` by steps up or left, other than `last m`, has a |
| 297 | turn. -/ |
| 298 | lemma exists_turn (hΓ : Γ ≠ last m) : ∃ (s : ℕ × ℕ) (Γ' : TwoGridPath m), Γ.Turn s Γ' := by |
| 299 | by_cases h_corner : ∃ (z : Bool) (a b : ℕ) (q : GridPath 0 m a (b + 1)) |
| 300 | (r : GridPath (a + 1) b Γ.diagonalIndex Γ.diagonalIndex), Γ.half z = q.down.right.append r |
| 301 | · obtain ⟨z, a, b, q, r, h_eq⟩ := h_corner |
| 302 | exact ⟨_, _, .inner Γ z q r h_eq⟩ |
| 303 | obtain ⟨l, half⟩ := Γ |
| 304 | obtain rfl | hl := eq_or_ne l m |
| 305 | · obtain rfl : half = fun _ : Bool ↦ .row l l := funext fun z ↦ (half z).eq_row |
| 306 | exact absurd rfl hΓ |
| 307 | -- Without corners, and below the last row, both halves end with a step down. |
| 308 | have h_down (z : Bool) : ∃ q : GridPath 0 m l (l + 1), half z = q.down := by |
| 309 | obtain h_has_corner | h_ends_down | h_last_row := (half z).exists_corner_or_eq_down_or_eq |
| 310 | · exact absurd ⟨z, h_has_corner⟩ h_corner |
| 311 | · exact h_ends_down |
| 312 | · exact absurd h_last_row hl |
| 313 | choose q hq using h_down |
| 314 | obtain rfl : half = fun z ↦ (q z).down := funext hq |
| 315 | exact ⟨(l, l), ⟨l + 1, fun z ↦ (q z).right⟩, .diagonal q⟩ |
| 316 | |
| 317 | /-- Let a property of a path and a finite set of index pairs hold for the last path, through |
| 318 | `(m, m)`, and the empty set. Suppose that for each turn at `s` from `Γ` to `Γ'` and each set `T` |
| 319 | without `s`, it passes from `Γ'` and `T` to `Γ` and `insert s T`. Then it holds for the first path, |
| 320 | through `(0, 0)`, and the set of all `(i, j)` with `i, j < m`. -/ |
| 321 | lemma turn_induction {motive : TwoGridPath m → Finset (ℕ × ℕ) → Prop} (h_last : motive (last m) ∅) |
| 322 | (h_turn : ∀ (Γ : TwoGridPath m) (s : ℕ × ℕ) (Γ' : TwoGridPath m) (T : Finset (ℕ × ℕ)), |
| 323 | Γ.Turn s Γ' → s ∉ T → motive Γ' T → motive Γ (insert s T)) : |
| 324 | motive (first m) (range m ×ˢ range m) := by |
| 325 | -- Induction on the number of squares between `Γ` and the last path. |
| 326 | suffices h_above_path : ∀ (k : ℕ) (Γ : TwoGridPath m), |
| 327 | #(range m ×ˢ range m \ Γ.squares) = k → motive Γ (range m ×ˢ range m \ Γ.squares) by |
| 328 | simpa [squares_first] using h_above_path _ (first m) rfl |
| 329 | intro k |
| 330 | induction k using Nat.strong_induction_on with |
| 331 | | _ k ih => |
| 332 | intro Γ hk |
| 333 | obtain rfl | h_ne := eq_or_ne Γ (last m) |
| 334 | · simpa [squares_last] using h_last |
| 335 | obtain ⟨s, Γ', hΓΓ' : Γ.Turn s Γ'⟩ := exists_turn h_ne |
| 336 | obtain ⟨hs : s ∉ Γ.squares, h_eq : Γ'.squares = insert s Γ.squares⟩ := hΓΓ'.squares_eq |
| 337 | have h_new : s ∉ range m ×ˢ range m \ Γ'.squares := by simp [h_eq] |
| 338 | have h_above : range m ×ˢ range m \ Γ.squares = |
| 339 | insert s (range m ×ˢ range m \ Γ'.squares) := by |
| 340 | rw [h_eq, sdiff_insert, insert_erase (mem_sdiff.mpr ⟨hΓΓ'.mem_product, hs⟩)] |
| 341 | rw [h_above] at hk ⊢ |
| 342 | exact h_turn Γ s Γ' _ hΓΓ' h_new (ih _ (by simp [← hk, h_new]) Γ' rfl) |
| 343 | |
| 344 | end TwoGridPath |
| 345 | |
| 346 | end New |
| 347 | |
| 348 | end |