Lean / Reader
Lean readerLazyLucasRuns.lean
Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports LazyLucasCore, which it does not have: you can read it there, but it will not check. Build the project itself to check it.
import LazyLucasCorenamespace LazyLucasprivate theorem cap_id (k : ℕ) : cap k + 1 = lucas (k+1) := byinduction k with| zero => decide| succ k ih =>change cap k + lucas k + 1 = lucas k + lucas (k+1)omegaprivate theorem lucas_pos (k : ℕ) : 0 < lucas k := byinduction k using Nat.strong_induction_on with| h k ih =>rcases k with _|k· decidercases k with _|k· decidechange 0 < lucas k + lucas (k+1)have := ih k (by omega)omegaprivate theorem lucas_next (k : ℕ) (hk : 1≤k) : lucas k < lucas (k+1) := byobtain ⟨j,rfl⟩ : ∃ j,k=j+1 := ⟨k-1,by omega⟩change lucas (j+1) < lucas j + lucas (j+1)have := lucas_pos jomegaprivate theorem lucas_three (k : ℕ) (hk : 2≤k) : 3 ≤ lucas k := byinduction k,hk using Nat.le_induction with| base => decide| succ k hk ih => exact ih.trans (lucas_next k (by omega)).leprivate theorem cap_ge (k : ℕ) : k ≤ cap k := byinduction k with| zero => decide| succ k ih =>change k+1 ≤ cap k+lucas khave := lucas_pos komegasectionvariable (s : ℕ → ℕ)variable (rep : ∀ {k n : ℕ}, 2 ≤ k → n ≤ cap k → s n = bounded k n)include rep inprivate theorem upper_shift {k n : ℕ} (hk : 2≤k) (lo : cap k<n) (hi : n≤cap (k+1)) :s n = 1+s (n-lucas k) := byrw [rep (k:=k+1) (by omega) hi,bounded_step hk, if_neg (by omega),rep hk]change n ≤ cap k + lucas k at hiomegainclude rep inprivate theorem last_pair (k : ℕ) (hk : 3 ≤ k) :s (cap k-2) = s (cap k-1) := byinduction k,hk using Nat.le_induction with| base =>rw [rep (k:=3) (by decide) (by decide),rep (k:=3) (by decide) (by decide)]decide| succ k hk ih =>have l := lucas_three k (by omega)have c := cap_ge khave e : cap (k+1) = cap k+lucas k := rflrw [upper_shift s rep (k:=k) (by omega) (by omega) (by omega),upper_shift s rep (k:=k) (n:=cap (k+1)-1) (by omega) (by omega) (by omega)]simp only [e,show cap k+lucas k-2-lucas k=cap k-2 by omega,show cap k+lucas k-1-lucas k=cap k-1 by omega,ih]include rep inprivate theorem first_pair (k : ℕ) (hk : 2≤k) :s (cap k+1) = s (cap k+2) := byinduction k using Nat.strong_induction_on with| h k ih =>by_cases hb : k≤3· interval_cases k <;> rw [rep (k:=5) (by decide) (by decide),rep (k:=5) (by decide) (by decide)] <;> decide· obtain ⟨j,rfl⟩ : ∃ j,k=j+2 := ⟨k-2,by omega⟩have l := lucas_three (j+2) (by omega)have e : cap (j+2+1)=cap (j+2)+lucas (j+2) := rflhave p : cap (j+2)+1=lucas (j+2)+lucas (j+1) := (cap_id _).trans (Nat.add_comm _ _)have q := cap_id jrw [upper_shift s rep (k:=j+2) (by omega) (by omega) (by omega),upper_shift s rep (k:=j+2) (n:=cap (j+2)+2) (by omega) (by omega) (by omega)]rw [show cap (j+2)+1-lucas (j+2)=cap j+1 by omega,show cap (j+2)+2-lucas (j+2)=cap j+2 by omega,ih j (by omega) (by omega)]private def HasAdjacentPair (s : ℕ → ℕ) (n : ℕ) : Prop :=s n = s (n+1) ∨ s (n+1) = s (n+2) ∨ s (n+2) = s (n+3)include rep inprivate theorem adjacent_prefix (k : ℕ) (hk : 3≤k) :∀ n, n+3 ≤ cap k → HasAdjacentPair s n := byinduction k,hk using Nat.le_induction with| base =>intro n hnhave h3 : n≤3 := by change n+3≤6 at hn; omegainterval_cases n <;> unfold HasAdjacentPair <;>simp only [rep (k:=3) (by decide) (by decide : 0≤cap 3),rep (k:=3) (by decide) (by decide : 1≤cap 3),rep (k:=3) (by decide) (by decide : 2≤cap 3),rep (k:=3) (by decide) (by decide : 3≤cap 3),rep (k:=3) (by decide) (by decide : 4≤cap 3),rep (k:=3) (by decide) (by decide : 5≤cap 3),rep (k:=3) (by decide) (by decide : 6≤cap 3),Nat.reduceAdd] <;> decide| succ k hk ih =>intro n hnby_cases low : n+3 ≤ cap k· exact ih n lowby_cases high : cap k < n· have e : cap (k+1) = cap k + lucas k := rflhave ek := cap_id khave lk := lucas_next k (by omega)have h1 : lucas k ≤ n := by omegahave prev := ih (n-lucas k) (by omega)unfold HasAdjacentPair at prev ⊢have shift (i : ℕ) (hi : i≤3) : s (n+i) = 1+s ((n-lucas k)+i) := byrw [upper_shift s rep (k:=k) (by omega) (by omega) (by omega)]congr 2omegahave h0 := shift 0 (by decide)simp only [Nat.add_zero] at h0rw [h0,shift 1 (by decide),shift 2 (by decide),shift 3 (by decide)]simpa only [Nat.add_left_cancel_iff] using prev· unfold HasAdjacentPairhave he := last_pair s rep k hkhave hs := first_pair s rep k (by omega)have c := cap_ge krcases (show n=cap k-2 ∨ n+1=cap k ∨ n=cap k by omega) with h|h|h· left; convert he using 1 <;> congr 1 <;> omega· right; right; convert hs using 1 <;> congr 1 <;> omega· right; left; simpa [h] using hsinclude rep intheorem adjacent_pair (n : ℕ) : HasAdjacentPair s n :=adjacent_prefix s rep (n+3) (by omega) n (cap_ge _)include rep inprivate theorem digit_lower_prefix (k : ℕ) (hk : 2≤k) :∀ n, n≤cap k → (0<n → 0<s n) ∧ (3≤n → 2≤s n) := byinduction k,hk using Nat.le_induction with| base =>intro n hnrw [rep (k:=2) (by decide) hn,bounded_two]change n≤3 at hninterval_cases n <;> decide| succ k hk ih =>intro n hnby_cases low : n≤cap k· exact ih n low· rw [upper_shift s rep (k:=k) hk (by omega) hn]have e : cap (k+1)=cap k+lucas k := rflhave lex := lucas_next k (by omega)have cid := cap_id khave h1 := (ih (n-lucas k) (by omega)).1 (by omega)omegaprivate theorem adjacent_not_divisible {x d : ℕ} (hd : 2≤d) (h : d∣x) (h' : d∣x+1) : False := byhave h1 : d∣1 := (Nat.dvd_add_right h).mp h'exact (by have := Nat.le_of_dvd (by decide : 0<1) h1; omega)include rep intheorem no_four_for_digit_count (n : ℕ) (hn : 1≤n) :¬(s n∣n ∧ s (n+1)∣n+1 ∧ s (n+2)∣n+2 ∧ s (n+3)∣n+3) := byrintro ⟨h₀,h₁,h₂,h₃⟩by_cases h : n≤2· have bad : ¬ s 3 ∣ 3 := by rw [rep (k:=2) (by decide) (by decide)]; decideinterval_cases n <;> contradiction· have lower (t : ℕ) (ht : n≤t) : 2≤s t :=(digit_lower_prefix s rep (t+2) (by omega) t (by have := cap_ge (t+2); omega)).2 (by omega)rcases adjacent_pair s rep n with h|h|h· exact adjacent_not_divisible (lower n le_rfl) h₀ (h ▸ h₁)· exact adjacent_not_divisible (lower _ (by omega)) h₁ (h ▸ h₂)· exact adjacent_not_divisible (lower _ (by omega)) h₂ (h ▸ h₃)endend LazyLucas