Lean / Reader
Lean readerDecayPalettes.lean
Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports DecayClassification, DecayEdgeRefinement, which it does not have: you can read it there, but it will not check. Build the project itself to check it.
import DecayClassificationimport DecayEdgeRefinementnamespace DecayClassification/-- At an uncovered cutoff construct all disjoint actual palettes at once.Zero-based color 2j is private, and color 2i+1 supplies the shared pool. -/theorem palettes (a b : ℕ → ℝ) (ha : Antitone a) (ha0 : ∀ i, 0 ≤ a i) (hb : ∀ i, 0 ≤ b i)(J : ℕ)(tail : ∀ j ≤ J, ∑ h ∈ Finset.Ioc j J, b h ≤ b j)(blocks : ∀ j ≤ J, a (2*j+1) < 4*b j → ∃ B ⊆ Finset.Icc j J,16*b j ≤ ∑ i ∈ B, a (2*i+1) ∧ ∀ i ∈ B, a (2*i+1) ≤ 4*b j) :∃ A : ℕ → Finset ℕ, (∀ j h, j ≠ h → Disjoint (A j) (A h)) ∧(∀ j i, i ∈ A j → i ≤ 2*J+1) ∧ (∀ j ≤ J, 2*b j ≤ ∑ i ∈ A j, a i) := byclassicallet S := (Finset.range (J+1)).filter fun j => a (2*j+1) < 4*b jhave properties {j} (hj : j ∈ S) : j ≤ J ∧ a (2*j+1) < 4*b j := bysimpa [S,Nat.lt_succ_iff] using hjlet block j := if hj : j ∈ S then (blocks j (properties hj).1 (properties hj).2).choose else ∅have block_prop {j} (hj : j ∈ S) : block j ⊆ Finset.Icc j J ∧16*b j ≤ ∑ i ∈ block j, a (2*i+1) ∧ ∀ i ∈ block j, a (2*i+1) ≤ 4*b j := bysimpa [block,hj] using (blocks j (properties hj).1 (properties hj).2).choose_spechave bd : ∀ j ∈ S, ∑ h ∈ S.filter (j < ·), b h ≤ b j := byintro j hjapply le_trans _ (tail j (properties hj).1)apply Finset.sum_le_sum_of_subset_of_nonneg· intro h hhobtain ⟨hs,gt⟩ := Finset.mem_filter.mp hhexact Finset.mem_Ioc.mpr ⟨gt,(properties hs).1⟩· exact fun i _ _ => hb iobtain ⟨P,hP,hdis⟩ := pack_shared (fun i => a (2*i+1)) b (fun i => ha0 _) hb block S(fun _ hj => (block_prop hj).2.1) (fun _ hj => (block_prop hj).2.2) bdlet A j := if j ≤ J then if j ∈ S then (P j).image (fun i => 2*i+1) else {2*j} else ∅have decode (j i : ℕ) (hi : i ∈ A j) : j ≤ J ∧((j ∈ S ∧ ∃ x ∈ P j, 2*x+1=i) ∨ (j ∉ S ∧ 2*j=i)) := byby_cases hj : j ≤ J <;> by_cases hs : j ∈ S <;> simp_all [A,Finset.mem_image,eq_comm]refine ⟨A, ?_, ?_, ?_⟩· intro j h nerw [Finset.disjoint_left]intro i hij hihrcases (decode j i hij).2 with ⟨js,x,hx,ex⟩ | ⟨_,ex⟩ <;>rcases (decode h i hih).2 with ⟨hs,y,hy,ey⟩ | ⟨_,ey⟩· have eq : x=y := by omegaexact Finset.disjoint_left.mp (hdis _ js _ hs ne) hx (eq ▸ hy)all_goals omega· intro j i hiobtain ⟨hj,h⟩ := decode j i hircases h with ⟨js,x,hx,ex⟩ | ⟨_,ex⟩· have le := (Finset.mem_Icc.mp ((block_prop js).1 ((hP j js).1 hx))).2omega· omega· intro j hjby_cases hs : j ∈ S· simp only [A,hj,hs,if_true]rw [Finset.sum_image (fun x _ y _ h => by omega)]exact (hP j hs).2.1· have big : 4*b j ≤ a (2*j+1) := byby_contra! smallexact hs (Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by omega),small⟩)simp only [A,hj,hs,if_true,if_false,Finset.sum_singleton]linarith [ha (show 2*j ≤ 2*j+1 by omega), hb j]/-- Rounded palettes refine any bounded finite edge coloring while preservingthe implication from equality of new labels to equality of old labels. -/theorem integer_refinement {α : Type*} [DecidableEq α] (E : Finset α) (c : α → ℕ)(a b : ℕ → ℝ) (ha : Antitone a) (ha0 : ∀ i, 0 ≤ a i) (J : ℕ)(active : ∀ e ∈ E, c e ≤ J)(budget : ∀ j ≤ J, ((E.filter fun e => c e = j).card : ℝ) ≤ b j * E.card)(roundable : 2 ≤ a (2*J+1)*E.card)(A : ℕ → Finset ℕ) (dis : ∀ j h, j ≠ h → Disjoint (A j) (A h))(limited : ∀ j i, i ∈ A j → i ≤ 2*J+1)(mass : ∀ j ≤ J, 2*b j ≤ ∑ i ∈ A j, a i) :∃ c' : α → ℕ, (∀ i, ((E.filter fun e => c' e = i).card : ℝ) ≤ a i*E.card) ∧∀ x ∈ E, ∀ y ∈ E, c' x = c' y → c x = c y := byclassicallet cap i := ⌊a i * E.card⌋₊have caplow (j i : ℕ) (hi : i ∈ A j) : a i*E.card / 2 ≤ (cap i : ℝ) := byhave enough : 2 ≤ a i*E.card := roundable.trans (mul_le_mul_of_nonneg_right(ha (limited j i hi)) (by positivity))have hf := Nat.lt_floor_add_one (a i * E.card)dsimp [cap]linarithhave available : ∀ j, (E.filter (fun e => c e = j)).card ≤ ∑ i ∈ A j, cap i := byintro jby_cases hj : j ≤ J· have hsum := Finset.sum_le_sum (fun i (hi : i ∈ A j) => caplow j i hi)rw [← Finset.sum_div, ← Finset.sum_mul] at hsumhave total := mul_le_mul_of_nonneg_right (mass j hj) (show (0:ℝ) ≤ E.card by positivity)have hreal : ((E.filter fun e => c e = j).card : ℝ) ≤ ∑ i ∈ A j, (cap i : ℝ) := bylinarith [budget j hj]exact_mod_cast hreal· have empty : (E.filter (fun e => c e = j)) = ∅ := byapply Finset.eq_empty_iff_forall_notMem.mprintro e heobtain ⟨he,eq⟩ := Finset.mem_filter.mp heexact hj (eq ▸ active e he)simp [empty]obtain ⟨c',_,hcap,hparent⟩ := DecayEdgeRefinement.recolor E c A cap dis availablerefine ⟨c', ?_, hparent⟩intro iexact le_trans (by exact_mod_cast hcap i) (Nat.floor_le (mul_nonneg (ha0 i) (by positivity)))end DecayClassification