| 1 | module |
| 2 | |
| 3 | public import Mathlib |
| 4 | |
| 5 | @[expose] public section |
| 6 | |
| 7 | /-! |
| 8 | # Input, part 1: the generated set, and affine maps that preserve it |
| 9 | |
| 10 | `Gen n` says that `n` is in the smallest set that contains 2, 3 and `a * b - 1` for distinct members `a`, `b`. |
| 11 | `IsMap Q c` says that `x ↦ Q x - c` maps `{x ∈ A | 14 < x}` into itself. |
| 12 | -/ |
| 13 | |
| 14 | set_option linter.style.header false |
| 15 | |
| 16 | namespace E424.Inp |
| 17 | |
| 18 | /-- Inductive form of membership in the generated set. -/ |
| 19 | inductive Gen : ℕ → Prop |
| 20 | | two : Gen 2 |
| 21 | | three : Gen 3 |
| 22 | | mul_sub_one {a b : ℕ} : Gen a → Gen b → a ≠ b → Gen (a * b - 1) |
| 23 | |
| 24 | /-- The generated set. -/ |
| 25 | def genSet : Set ℕ := {n | Gen n} |
| 26 | |
| 27 | theorem mem_iff (n : ℕ) : n ∈ genSet ↔ Gen n := Iff.rfl |
| 28 | |
| 29 | theorem Gen.five : Gen 5 := .mul_sub_one .two .three (by norm_num) |
| 30 | theorem Gen.nine : Gen 9 := .mul_sub_one .two .five (by norm_num) |
| 31 | theorem Gen.fourteen : Gen 14 := .mul_sub_one .three .five (by norm_num) |
| 32 | theorem Gen.seventeen : Gen 17 := .mul_sub_one .two .nine (by norm_num) |
| 33 | |
| 34 | /-- The five multipliers. -/ |
| 35 | def Letter (a : ℕ) : Prop := a = 2 ∨ a = 3 ∨ a = 5 ∨ a = 9 ∨ a = 14 |
| 36 | |
| 37 | theorem Letter.gen {a : ℕ} (h : Letter a) : Gen a := by |
| 38 | rcases h with rfl | rfl | rfl | rfl | rfl |
| 39 | exacts [.two, .three, .five, .nine, .fourteen] |
| 40 | |
| 41 | theorem Letter.two_le {a : ℕ} (h : Letter a) : 2 ≤ a := by unfold Letter at h; omega |
| 42 | theorem Letter.le {a : ℕ} (h : Letter a) : a ≤ 14 := by unfold Letter at h; omega |
| 43 | |
| 44 | /-- `x ↦ Q x - c` preserves the elements above 14. -/ |
| 45 | def IsMap (Q c : ℕ) : Prop := c < Q ∧ ∀ x, Gen x → 14 < x → Gen (Q * x - c) ∧ 14 < Q * x - c |
| 46 | |
| 47 | theorem IsMap.one : IsMap 1 0 := ⟨by norm_num, fun x hx h => by simpa using ⟨hx, h⟩⟩ |
| 48 | |
| 49 | /-- Compose with `y ↦ a y - 1`. -/ |
| 50 | theorem IsMap.step {Q c a : ℕ} (h : IsMap Q c) (ha : Letter a) : IsMap (a * Q) (a * c + 1) := by |
| 51 | have h2 := ha.two_le |
| 52 | obtain ⟨hc, hx⟩ := h |
| 53 | have hle : a * (c + 1) ≤ a * Q := Nat.mul_le_mul_left _ hc |
| 54 | refine ⟨by nlinarith, fun x hxG h14 => ?_⟩ |
| 55 | obtain ⟨hg, hb⟩ := hx x hxG h14 |
| 56 | have heq : a * Q * x - (a * c + 1) = a * (Q * x - c) - 1 := by |
| 57 | rw [Nat.mul_sub, mul_assoc, Nat.sub_sub] |
| 58 | rw [heq] |
| 59 | have : 2 * (Q * x - c) ≤ a * (Q * x - c) := Nat.mul_le_mul_right _ h2 |
| 60 | exact ⟨.mul_sub_one ha.gen hg (by have := ha.le; omega), by omega⟩ |
| 61 | |
| 62 | end E424.Inp |
| 63 | |