Lean / Reader
Lean reader

DecayRamseyPacking.lean

83 lines5 declarationsno sorryimports Mathlib.Tactic
  1. import Mathlib.Tactic
  2. namespace DecayRamseyPacking
  3. /-- Count a nonnegative weight at least once when finite intervals cover its index. -/
  4. theorem cover_mass (d : ℕ → ℝ) (hd : ∀ i, 0 ≤ d i)
  5. (target starts : Finset ℕ) (block : ℕ → Finset ℕ)
  6. (h : ∀ i ∈ target, ∃ j ∈ starts, i ∈ block j) :
  7. ∑ i ∈ target, d i ≤ ∑ j ∈ starts, ∑ i ∈ block j, d i := by
  8. classical
  9. calc
  10. ∑ i ∈ target, d i ≤ ∑ i ∈ target, ∑ j ∈ starts, (if i ∈ block j then d i else 0) := by
  11. apply Finset.sum_le_sum
  12. intro i hi
  13. obtain ⟨j, hj, hm⟩ := h i hi
  14. have hsingle := Finset.single_le_sum
  15. (f := fun j => if i ∈ block j then d i else 0)
  16. (s := starts) (fun j _ => by by_cases hh : i ∈ block j <;> simp [hh, hd]) hj
  17. simpa [hm] using hsingle
  18. _ = ∑ j ∈ starts, ∑ i ∈ target, (if i ∈ block j then d i else 0) := Finset.sum_comm
  19. _ ≤ ∑ j ∈ starts, ∑ i ∈ block j, d i := by
  20. apply Finset.sum_le_sum
  21. intro j _
  22. rw [← Finset.sum_filter]
  23. apply Finset.sum_le_sum_of_subset_of_nonneg
  24. · intro i hi
  25. exact (Finset.mem_filter.mp hi).2
  26. · intro i _ _
  27. exact hd i
  28. /-- Arbitrarily large uncovered cutoffs. An unmarked start has an empty block.
  29. The finite witness in 'excess' follows from the strict tail inequality. -/
  30. theorem unbounded_uncovered (d b : ℕ → ℝ) (hd : ∀ i, 0 ≤ d i)
  31. (block : ℕ → Finset ℕ)
  32. (left : ∀ j i, i ∈ block j → j ≤ i)
  33. (interval : ∀ j i h, i ∈ block j → j ≤ h → h ≤ i → h ∈ block j)
  34. (cost : ∀ j, ∑ i ∈ block j, d i ≤ 20 * b j)
  35. (excess : ∀ s, ∃ l, ∑ i ∈ Finset.Icc s l, d i > ∑ j ∈ Finset.Icc s l, 20 * b j) :
  36. ∀ n, ∃ m ≥ n, ∀ j, m ∉ block j := by
  37. classical
  38. intro n
  39. by_contra failed
  40. push_neg at failed
  41. let covered := fun s : ℕ => ∀ i ≥ s, ∃ j, i ∈ block j
  42. have ex : ∃ s, covered s := ⟨n, failed⟩
  43. let s := Nat.find ex
  44. have tail : covered s := Nat.find_spec ex
  45. obtain ⟨l, hl⟩ := excess s
  46. have mass := cover_mass d hd (Finset.Icc s l) (Finset.Icc s l) block (by
  47. intro i hi
  48. obtain ⟨hsi, hil⟩ := Finset.mem_Icc.mp hi
  49. obtain ⟨j, hj⟩ := tail i hsi
  50. have hji := left j i hj
  51. have hsj : s ≤ j := by
  52. by_contra! small
  53. have pred : s - 1 ∈ block j := interval j i (s - 1) hj (by omega) (by omega)
  54. have prev : covered (s - 1) := by
  55. intro x hx
  56. by_cases hsx : s ≤ x
  57. · exact tail x hsx
  58. · have hx' : x = s - 1 := by omega
  59. exact ⟨j, hx' ▸ pred⟩
  60. have minimal : s ≤ s - 1 := Nat.find_min' ex prev
  61. omega
  62. exact ⟨j, Finset.mem_Icc.mpr ⟨hsj, by omega⟩, hj⟩)
  63. have cap := Finset.sum_le_sum (s := Finset.Icc s l) (fun j _ => cost j)
  64. linarith
  65. theorem remaining_after_allocation (block used need : ℝ)
  66. (hblock : 16 * need ≤ block) (hused : used ≤ 6 * need) (hn : 0 ≤ need) :
  67. 2 * need ≤ block - used := by linarith
  68. theorem greedy_overshoot (used last need : ℝ)
  69. (hu : used < 2 * need) (hl : last < 4 * need) :
  70. used + last < 6 * need := by linarith
  71. theorem floor_capacity (x : ℝ) (hx : 2 ≤ x) : x / 2 ≤ (⌊x⌋ : ℤ) := by
  72. have h := Int.lt_floor_add_one x
  73. linarith
  74. end DecayRamseyPacking