import Mathlib.Tacticnamespace LazyLucasdef lucas : ℕ → ℕ| 0 => 2| 1 => 1| n+2 => lucas n + lucas (n+1)def cap : ℕ → ℕ| 0 => 0| n+1 => cap n + lucas n/-- The number of chosen digits in a prefix of width k. At width two theweights are 2 and 1, in that order from the low-order bit upward. -/def bounded : ℕ → ℕ → ℕ| 0, _ => 0| 1, n => if n=2 then 1 else 0| 2, n => if n=0 then 0 else if n=3 then 2 else 1| k+3, n => if n ≤ cap (k+2) then bounded (k+2) n else 1+bounded (k+2) (n-lucas (k+2))theorem bounded_two (n : ℕ) : bounded 2 n = if n=0 then 0 else if n=3 then 2 else 1 := rfltheorem bounded_step {k n : ℕ} (hk : 2 ≤ k) : bounded (k+1) n =if n ≤ cap k then bounded k n else 1+bounded k (n-lucas k) := byobtain ⟨u,rfl⟩ := Nat.exists_eq_add_of_le hkrw [Nat.add_comm 2 u]; rflend LazyLucas