Lean / Reader
Lean reader

DecayPalettes.lean

104 lines2 declarationsno sorryimports DecayClassification DecayEdgeRefinement

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.

  1. import DecayClassification
  2. import DecayEdgeRefinement
  3. namespace DecayClassification
  4. /-- At an uncovered cutoff construct all disjoint actual palettes at once.
  5. Zero-based color 2j is private, and color 2i+1 supplies the shared pool. -/
  6. theorem palettes (a b : ℕ → ℝ) (ha : Antitone a) (ha0 : ∀ i, 0 ≤ a i) (hb : ∀ i, 0 ≤ b i)
  7. (J : ℕ)
  8. (tail : ∀ j ≤ J, ∑ h ∈ Finset.Ioc j J, b h ≤ b j)
  9. (blocks : ∀ j ≤ J, a (2*j+1) < 4*b j → ∃ B ⊆ Finset.Icc j J,
  10. 16*b j ≤ ∑ i ∈ B, a (2*i+1) ∧ ∀ i ∈ B, a (2*i+1) ≤ 4*b j) :
  11. ∃ A : ℕ → Finset ℕ, (∀ j h, j ≠ h → Disjoint (A j) (A h)) ∧
  12. (∀ j i, i ∈ A j → i ≤ 2*J+1) ∧ (∀ j ≤ J, 2*b j ≤ ∑ i ∈ A j, a i) := by
  13. classical
  14. let S := (Finset.range (J+1)).filter fun j => a (2*j+1) < 4*b j
  15. have properties {j} (hj : j ∈ S) : j ≤ J ∧ a (2*j+1) < 4*b j := by
  16. simpa [S,Nat.lt_succ_iff] using hj
  17. let block j := if hj : j ∈ S then (blocks j (properties hj).1 (properties hj).2).choose else ∅
  18. have block_prop {j} (hj : j ∈ S) : block j ⊆ Finset.Icc j J ∧
  19. 16*b j ≤ ∑ i ∈ block j, a (2*i+1) ∧ ∀ i ∈ block j, a (2*i+1) ≤ 4*b j := by
  20. simpa [block,hj] using (blocks j (properties hj).1 (properties hj).2).choose_spec
  21. have bd : ∀ j ∈ S, ∑ h ∈ S.filter (j < ·), b h ≤ b j := by
  22. intro j hj
  23. apply le_trans _ (tail j (properties hj).1)
  24. apply Finset.sum_le_sum_of_subset_of_nonneg
  25. · intro h hh
  26. obtain ⟨hs,gt⟩ := Finset.mem_filter.mp hh
  27. exact Finset.mem_Ioc.mpr ⟨gt,(properties hs).1⟩
  28. · exact fun i _ _ => hb i
  29. obtain ⟨P,hP,hdis⟩ := pack_shared (fun i => a (2*i+1)) b (fun i => ha0 _) hb block S
  30. (fun _ hj => (block_prop hj).2.1) (fun _ hj => (block_prop hj).2.2) bd
  31. let A j := if j ≤ J then if j ∈ S then (P j).image (fun i => 2*i+1) else {2*j} else ∅
  32. have decode (j i : ℕ) (hi : i ∈ A j) : j ≤ J ∧
  33. ((j ∈ S ∧ ∃ x ∈ P j, 2*x+1=i) ∨ (j ∉ S ∧ 2*j=i)) := by
  34. by_cases hj : j ≤ J <;> by_cases hs : j ∈ S <;> simp_all [A,Finset.mem_image,eq_comm]
  35. refine ⟨A, ?_, ?_, ?_⟩
  36. · intro j h ne
  37. rw [Finset.disjoint_left]
  38. intro i hij hih
  39. rcases (decode j i hij).2 with ⟨js,x,hx,ex⟩ | ⟨_,ex⟩ <;>
  40. rcases (decode h i hih).2 with ⟨hs,y,hy,ey⟩ | ⟨_,ey⟩
  41. · have eq : x=y := by omega
  42. exact Finset.disjoint_left.mp (hdis _ js _ hs ne) hx (eq ▸ hy)
  43. all_goals omega
  44. · intro j i hi
  45. obtain ⟨hj,h⟩ := decode j i hi
  46. rcases h with ⟨js,x,hx,ex⟩ | ⟨_,ex⟩
  47. · have le := (Finset.mem_Icc.mp ((block_prop js).1 ((hP j js).1 hx))).2
  48. omega
  49. · omega
  50. · intro j hj
  51. by_cases hs : j ∈ S
  52. · simp only [A,hj,hs,if_true]
  53. rw [Finset.sum_image (fun x _ y _ h => by omega)]
  54. exact (hP j hs).2.1
  55. · have big : 4*b j ≤ a (2*j+1) := by
  56. by_contra! small
  57. exact hs (Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by omega),small⟩)
  58. simp only [A,hj,hs,if_true,if_false,Finset.sum_singleton]
  59. linarith [ha (show 2*j ≤ 2*j+1 by omega), hb j]
  60. /-- Rounded palettes refine any bounded finite edge coloring while preserving
  61. the implication from equality of new labels to equality of old labels. -/
  62. theorem integer_refinement {α : Type*} [DecidableEq α] (E : Finset α) (c : α → ℕ)
  63. (a b : ℕ → ℝ) (ha : Antitone a) (ha0 : ∀ i, 0 ≤ a i) (J : ℕ)
  64. (active : ∀ e ∈ E, c e ≤ J)
  65. (budget : ∀ j ≤ J, ((E.filter fun e => c e = j).card : ℝ) ≤ b j * E.card)
  66. (roundable : 2 ≤ a (2*J+1)*E.card)
  67. (A : ℕ → Finset ℕ) (dis : ∀ j h, j ≠ h → Disjoint (A j) (A h))
  68. (limited : ∀ j i, i ∈ A j → i ≤ 2*J+1)
  69. (mass : ∀ j ≤ J, 2*b j ≤ ∑ i ∈ A j, a i) :
  70. ∃ c' : α → ℕ, (∀ i, ((E.filter fun e => c' e = i).card : ℝ) ≤ a i*E.card) ∧
  71. ∀ x ∈ E, ∀ y ∈ E, c' x = c' y → c x = c y := by
  72. classical
  73. let cap i := ⌊a i * E.card⌋₊
  74. have caplow (j i : ℕ) (hi : i ∈ A j) : a i*E.card / 2 ≤ (cap i : ℝ) := by
  75. have enough : 2 ≤ a i*E.card := roundable.trans (mul_le_mul_of_nonneg_right
  76. (ha (limited j i hi)) (by positivity))
  77. have hf := Nat.lt_floor_add_one (a i * E.card)
  78. dsimp [cap]
  79. linarith
  80. have available : ∀ j, (E.filter (fun e => c e = j)).card ≤ ∑ i ∈ A j, cap i := by
  81. intro j
  82. by_cases hj : j ≤ J
  83. · have hsum := Finset.sum_le_sum (fun i (hi : i ∈ A j) => caplow j i hi)
  84. rw [← Finset.sum_div, ← Finset.sum_mul] at hsum
  85. have total := mul_le_mul_of_nonneg_right (mass j hj) (show (0:ℝ) ≤ E.card by positivity)
  86. have hreal : ((E.filter fun e => c e = j).card : ℝ) ≤ ∑ i ∈ A j, (cap i : ℝ) := by
  87. linarith [budget j hj]
  88. exact_mod_cast hreal
  89. · have empty : (E.filter (fun e => c e = j)) = ∅ := by
  90. apply Finset.eq_empty_iff_forall_notMem.mpr
  91. intro e he
  92. obtain ⟨he,eq⟩ := Finset.mem_filter.mp he
  93. exact hj (eq ▸ active e he)
  94. simp [empty]
  95. obtain ⟨c',_,hcap,hparent⟩ := DecayEdgeRefinement.recolor E c A cap dis available
  96. refine ⟨c', ?_, hparent⟩
  97. intro i
  98. exact le_trans (by exact_mod_cast hcap i) (Nat.floor_le (mul_nonneg (ha0 i) (by positivity)))
  99. end DecayClassification