Lean / Reader
Lean readerDecayClassification.lean
Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports DecayRamseyPacking, which it does not have: you can read it there, but it will not check. Build the project itself to check it.
import DecayRamseyPackingnamespace DecayClassification/-- Unordered edges are represented once, with the smaller vertex first. -/def edges (n : ℕ) : Finset (Fin n × Fin n) :=Finset.univ.filter fun e => e.1 < e.2def Bounded {n : ℕ} (a : ℕ → ℝ) (c : Fin n × Fin n → ℕ) : Prop :=∀ i, (((edges n).filter fun e => c e = i).card : ℝ) ≤ a i * (edges n).carddef MonoClique {n : ℕ} (k : ℕ) (c : Fin n × Fin n → ℕ) : Prop :=∃ s : Finset (Fin n), s.card = k ∧ ∃ i, ∀ x ∈ s, ∀ y ∈ s, x < y → c (x,y) = i/-- Color indices start at zero, so the source's color i+1 is represented by i. -/def DecayRamsey (a : ℕ → ℝ) : Prop :=∀ k ≥ 2, ∃ N, ∀ n ≥ N, ∀ c : Fin n × Fin n → ℕ, Bounded a c → MonoClique k c/-- A strict bound for the full nonnegative tail, expressed by a uniform upperbound on its finite partial sums. This includes the divergent-series case. -/def TailTest (a : ℕ → ℝ) : Prop :=∀ C : ℕ, 0 < C → ∀ N : ℕ, ∃ r : ℕ, r ≥ max 2 N ∧ ∃ u : ℝ,u * (r : ℝ)^(C*r) < 1 ∧ ∀ l, ∑ i ∈ Finset.Ico r l, a i ≤ udef Admissible (a : ℕ → ℝ) : Prop :=Antitone a ∧ (∀ i, 0 < a i) ∧ ∃ m, 1 < ∑ i ∈ Finset.range m, a i/-- The source classification stated as a proposition. -/def Classification : Prop := ∀ a, Admissible a → (DecayRamsey a ↔ TailTest a)theorem take_mass (w : ℕ → ℝ) (target atom : ℝ) (hatom : 0 ≤ atom)(s : Finset ℕ) (small : ∀ i ∈ s, w i ≤ atom) (enough : target ≤ ∑ i ∈ s, w i) :∃ t ⊆ s, target ≤ ∑ i ∈ t, w i ∧ ∑ i ∈ t, w i ≤ max target 0 + atom := byclassicalinduction s using Finset.induction_on with| empty => exact ⟨∅, Finset.Subset.rfl, enough, by simp; positivity⟩| @insert i s hi ih =>by_cases ht : target ≤ ∑ x ∈ s, w x· obtain ⟨t, hts, hlow, hhigh⟩ := ih (fun j hj => small j (Finset.mem_insert_of_mem hj)) htexact ⟨t, hts.trans (Finset.subset_insert _ _), hlow, hhigh⟩· refine ⟨insert i s, Finset.Subset.rfl, enough, ?_⟩rw [Finset.sum_insert hi]have := small i (Finset.mem_insert_self ..)linarith [le_max_left target (0:ℝ)]/-- Assign each deficient provisional color its own even-label pool. -/theorem pack_shared (d b : ℕ → ℝ) (hd : ∀ i, 0 ≤ d i) (hb : ∀ j, 0 ≤ b j)(block : ℕ → Finset ℕ) (S : Finset ℕ)(supply : ∀ j ∈ S, 16*b j ≤ ∑ i ∈ block j, d i)(small : ∀ j ∈ S, ∀ i ∈ block j, d i ≤ 4*b j)(tail : ∀ j ∈ S, ∑ h ∈ S.filter (j < ·), b h ≤ b j) :∃ A : ℕ → Finset ℕ,(∀ j ∈ S, A j ⊆ block j ∧ 2*b j ≤ ∑ i ∈ A j, d i ∧ ∑ i ∈ A j, d i ≤ 6*b j) ∧(∀ j ∈ S, ∀ h ∈ S, j ≠ h → Disjoint (A j) (A h)) := byclassicalinduction S using Finset.induction_on_min with| h0 => exact ⟨fun _ => ∅, by simp, by simp⟩| step j S lower ih =>have hj : j ∉ S := fun h => (lt_irrefl j) (lower j h)have incl : S ⊆ insert j S := Finset.subset_insert _ _obtain ⟨A, ha, hdis⟩ := ih (fun h hh => supply h (incl hh)) (fun h hh => small h (incl hh))(fun h hh => le_trans (Finset.sum_le_sum_of_subset_of_nonneg(Finset.filter_subset_filter _ incl) (fun i _ _ => hb i)) (tail h (incl hh)))let used := S.biUnion Alet available := block j \ usedhave bound : ∑ i ∈ used, d i ≤ ∑ h ∈ S, (6*b h) := byexact (DecayRamseyPacking.cover_mass d hd used S A(fun _ h => Finset.mem_biUnion.mp h)).trans(Finset.sum_le_sum (fun h hh => (ha h hh).2.2))have ht : ∑ h ∈ S, b h ≤ b j := byhave heq : (insert j S).filter (j < ·) = S := byext xsimp only [Finset.mem_filter, Finset.mem_insert]constructor· rintro ⟨h | h, hx⟩· omega· exact h· exact fun hx => ⟨Or.inr hx, lower x hx⟩simpa [heq] using tail j (Finset.mem_insert_self ..)have hcovered : ∑ i ∈ block j, d i ≤ ∑ i ∈ available, d i + ∑ i ∈ used, d i := byhave hp := Finset.sum_inter_add_sum_diff (block j) used dhave hh := Finset.sum_le_sum_of_subset_of_nonneg (Finset.inter_subset_right (s₁ := block j) (s₂ := used)) (fun i _ _ => hd i)dsimp [available]linarithrw [← Finset.mul_sum] at boundhave ha2 : 2*b j ≤ ∑ i ∈ available, d i := bylinarith [supply j (Finset.mem_insert_self ..), hb j]obtain ⟨t, hsub, hmass, hmass'⟩ := take_mass d (2*b j) (4*b j) (by linarith [hb j]) available(fun i hi => small j (Finset.mem_insert_self ..) i ((Finset.mem_sdiff.mp hi).1)) ha2let A' := Function.update A j thave h_old : ∀ h ∈ S, A' h = A h := fun h hh => Function.update_of_ne (lower h hh).ne' _ _have h_new : A' j = t := Function.update_self ..have apart : ∀ h ∈ S, Disjoint t (A h) := byintro h hhrw [Finset.disjoint_left]exact fun i hi hih => (Finset.mem_sdiff.mp (hsub hi)).2 (Finset.mem_biUnion.mpr ⟨h,hh,hih⟩)refine ⟨A', ?_, ?_⟩· intro h hhrcases Finset.mem_insert.mp hh with eq | old· subst hrw [h_new]refine ⟨fun i hi => (Finset.mem_sdiff.mp (hsub hi)).1, hmass, ?_⟩rw [max_eq_left (by linarith [hb j] : (0:ℝ) ≤ 2*b j)] at hmass'linarith· rw [h_old h old]; exact ha h old· intro x hx y hy hxyrcases Finset.mem_insert.mp hx with eqx | hxs· subst xhave hys := (Finset.mem_insert.mp hy).resolve_left hxy.symmrw [h_new, h_old _ hys]exact apart _ hys· rcases Finset.mem_insert.mp hy with eqy | hys· subst yrw [h_old _ hxs, h_new]exact (apart _ hxs).symm· rw [h_old _ hxs, h_old _ hys]exact hdis _ hxs _ hys hxyend DecayClassification