Solution.lean
| 1 | module |
| 2 | |
| 3 | public import E424.Main |
| 4 | |
| 5 | public section |
| 6 | |
| 7 | /-! |
| 8 | # Proof of `Challenge.lean` |
| 9 | -/ |
| 10 | |
| 11 | namespace Hofstadter |
| 12 | |
| 13 | /-- `Generated n` says that `n` lies in the smallest set of natural numbers that contains 2 and 3 and contains `a * b - 1` whenever it |
| 14 | contains `a` and `b` and `a ≠ b`. (Members are at least 2, so `a * b - 1` is ordinary subtraction.) -/ |
| 15 | inductive Generated : ℕ → Prop |
| 16 | | two : Generated 2 |
| 17 | | three : Generated 3 |
| 18 | | step {a b : ℕ} : Generated a → Generated b → a ≠ b → Generated (a * b - 1) |
| 19 | |
| 20 | theorem generated_iff (n : ℕ) : E424.Inp.Gen n ↔ Generated n := by |
| 21 | constructor <;> intro h |
| 22 | · induction h with |
| 23 | | two => exact .two |
| 24 | | three => exact .three |
| 25 | | mul_sub_one _ _ hab iha ihb => exact .step iha ihb hab |
| 26 | · induction h with |
| 27 | | two => exact .two |
| 28 | | three => exact .three |
| 29 | | step _ _ hab iha ihb => exact .mul_sub_one iha ihb hab |
| 30 | |
| 31 | /-- The proportion of generated numbers among the natural numbers below `n` tends to `2 / 3` as `n` tends to infinity. -/ |
| 32 | theorem density_eq_two_thirds : |
| 33 | Filter.Tendsto (fun n : ℕ => (Set.ncard {m : ℕ | m < n ∧ Generated m} : ℝ) / n) Filter.atTop |
| 34 | (nhds (2 / 3)) := by |
| 35 | simpa only [generated_iff] using E424.hasDensity_two_thirds |
| 36 | |
| 37 | end Hofstadter |
| 38 |