| 1 | module |
| 2 | |
| 3 | public import E424.Input.Gen |
| 4 | public import E424.Input.Cert |
| 5 | |
| 6 | @[expose] public section |
| 7 | |
| 8 | /-! |
| 9 | # Input, part 5: one step of the process (elementary identities) |
| 10 | -/ |
| 11 | |
| 12 | set_option linter.style.header false |
| 13 | open Finset |
| 14 | |
| 15 | namespace E424.Inp |
| 16 | |
| 17 | theorem act_letter (ν : Ex) (j : ℕ) : Letter (act ν j) := by |
| 18 | unfold act Letter; split_ifs <;> omega |
| 19 | |
| 20 | theorem slope_pos (ν : Ex) : 0 < ν.slope := by unfold Ex.slope; positivity |
| 21 | |
| 22 | theorem slope_mul (ν : Ex) {a : ℕ} (ha : Letter a) : (ν.mul a).slope = a * ν.slope := by |
| 23 | rcases ha with rfl | rfl | rfl | rfl | rfl <;> simp [Ex.mul, Ex.slope, pow_succ] <;> ring |
| 24 | |
| 25 | theorem om_mul (ν : Ex) {a : ℕ} (ha : Letter a) : (ν.mul a).om = ν.om + ell a := by |
| 26 | rcases ha with rfl | rfl | rfl | rfl | rfl <;> simp [Ex.mul, Ex.om, ell] <;> omega |
| 27 | |
| 28 | /-- `ed` is `10 +` the increment of `g`. -/ |
| 29 | theorem g_mul (κ : Fin 6) (ν : Ex) {a : ℕ} (ha : Letter a) : |
| 30 | g κ (ν.mul a) + 10 = g κ ν + ed κ a := by |
| 31 | rcases ha with rfl | rfl | rfl | rfl | rfl <;> fin_cases κ <;> |
| 32 | simp [Ex.mul, g, h1, h2, h3, ed] <;> omega |
| 33 | |
| 34 | theorem ed_le (κ : Fin 6) {a : ℕ} (ha : Letter a) : ed κ a ≤ 20 := by |
| 35 | rcases ha with rfl | rfl | rfl | rfl | rfl <;> revert κ <;> decide |
| 36 | |
| 37 | /-- The image of an alive cell consists of alive cells. -/ |
| 38 | theorem act_range (ν : Ex) {j : ℕ} (hj : Alive j) : |
| 39 | 39 ≤ act ν j * j ∧ act ν j * j + act ν j ≤ 72 := by |
| 40 | obtain ⟨h3, h36⟩ := hj |
| 41 | unfold act |
| 42 | interval_cases j <;> simp <;> split_ifs <;> omega |
| 43 | |
| 44 | theorem child_mod {ν : Ex} {N r : ℕ} (hN : Alive (N % 36)) (hr : r < act ν (N % 36)) : |
| 45 | (act ν (N % 36) * N + r) % 36 = act ν (N % 36) * (N % 36) - 36 + r ∧ |
| 46 | (act ν (N % 36) * N + r) / 36 = act ν (N % 36) * (N / 36) + 1 := by |
| 47 | have h := act_range ν hN |
| 48 | set a := act ν (N % 36) |
| 49 | have hdiv : a * N = a * (N % 36) + 36 * (a * (N / 36)) := by |
| 50 | conv_lhs => rw [← Nat.mod_add_div N 36] |
| 51 | ring |
| 52 | constructor <;> omega |
| 53 | |
| 54 | theorem child_alive {ν : Ex} {N r : ℕ} (hN : Alive (N % 36)) (hr : r < act ν (N % 36)) : |
| 55 | Alive ((act ν (N % 36) * N + r) % 36) := by |
| 56 | have h := act_range ν hN |
| 57 | rw [(child_mod hN hr).1] |
| 58 | unfold Alive |
| 59 | omega |
| 60 | |
| 61 | /-- Children of a valid node are valid maps. -/ |
| 62 | theorem child_isMap {ν : Ex} {N r : ℕ} (hN : Alive (N % 36)) (hr : r < act ν (N % 36)) |
| 63 | (hm : IsMap ν.slope (N / 36)) : |
| 64 | IsMap (ν.mul (act ν (N % 36))).slope ((act ν (N % 36) * N + r) / 36) := by |
| 65 | rw [slope_mul _ (act_letter _ _), (child_mod hN hr).2] |
| 66 | exact hm.step (act_letter _ _) |
| 67 | |
| 68 | end E424.Inp |
| 69 | |