Lean / Reader
Lean reader

DecayCompletion.lean

80 lines2 declarationsno sorryimports DecayEdgeRefinement DecayClassification

Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports DecayEdgeRefinement, DecayClassification, which it does not have: you can read it there, but it will not check. Build the project itself to check it.

  1. import DecayEdgeRefinement
  2. import DecayClassification
  3. namespace DecayClassification
  4. /-- If finitely many integer capacities can accommodate the entire edge set,
  5. any partial coloring respecting all capacities extends without recoloring
  6. already colored edges. Colors of the partial coloring may lie outside pool. -/
  7. theorem extend_partial {α : Type*} [DecidableEq α] (E F : Finset α) (sub : F ⊆ E)
  8. (c : α → ℕ) (cap : ℕ → ℕ) (pool : Finset ℕ)
  9. (partial_ok : ∀ i, (F.filter (fun e => c e = i)).card ≤ cap i)
  10. (capacity : E.card ≤ ∑ i ∈ pool, cap i) :
  11. ∃ c' : α → ℕ, (∀ e ∈ F, c' e = c e) ∧
  12. ∀ i, (E.filter fun e => c' e = i).card ≤ cap i := by
  13. classical
  14. let left := E \ F
  15. let used i := (F.filter (fun e => c e = i)).card
  16. let free i := cap i - used i
  17. have hused : ∑ i ∈ pool, used i ≤ F.card := by
  18. dsimp [used]
  19. rw [Finset.sum_card_fiberwise_eq_card_filter]
  20. exact Finset.card_le_card (Finset.filter_subset _ _)
  21. have split : (∑ i ∈ pool, free i) + (∑ i ∈ pool, used i) = ∑ i ∈ pool, cap i := by
  22. rw [← Finset.sum_add_distrib]
  23. exact Finset.sum_congr rfl (fun i _ => Nat.sub_add_cancel (partial_ok i))
  24. have hleft : left.card ≤ ∑ i ∈ pool, free i := by
  25. dsimp [left]; rw [Finset.card_sdiff_of_subset sub]; omega
  26. obtain ⟨f,hinj,hrange⟩ := DecayEdgeRefinement.assign_one left pool free hleft
  27. let c' e := if e ∈ F then c e else (f e).1
  28. refine ⟨c',fun e he => by simp [c',he],?_⟩
  29. intro i
  30. have hnew : (left.filter (fun e => (f e).1 = i)).card ≤ free i := by
  31. calc
  32. _ ≤ (Finset.range (free i)).card := by
  33. apply Finset.card_le_card_of_injOn (fun e => (f e).2)
  34. · intro e he
  35. obtain ⟨he,eq⟩ := Finset.mem_filter.mp he
  36. exact Finset.mem_range.mpr (eq ▸ (hrange e he).2)
  37. · intro e he z hz eq
  38. obtain ⟨he,ei⟩ := Finset.mem_filter.mp he
  39. obtain ⟨hz,zi⟩ := Finset.mem_filter.mp hz
  40. exact hinj he hz (Prod.ext (ei.trans zi.symm) eq)
  41. _ = _ := Finset.card_range _
  42. have cover : E.filter (fun e => c' e = i) ⊆
  43. (F.filter (fun e => c e = i)) ∪ (left.filter (fun e => (f e).1 = i)) := by
  44. intro e he
  45. obtain ⟨he,eq⟩ := Finset.mem_filter.mp he
  46. by_cases old : e ∈ F
  47. · exact Finset.mem_union_left _ (Finset.mem_filter.mpr ⟨old,by simpa [c',old] using eq⟩)
  48. · exact Finset.mem_union_right _ (Finset.mem_filter.mpr
  49. ⟨Finset.mem_sdiff.mpr ⟨he,old⟩,by simpa [c',old] using eq⟩)
  50. have card := (Finset.card_le_card cover).trans (Finset.card_union_le ..)
  51. change _ ≤ used i + _ at card
  52. have hsum : free i + used i = cap i := Nat.sub_add_cancel (partial_ok i)
  53. omega
  54. /-- A fixed finite prefix of the original positive caps has enough integer
  55. slots for all edges once the number of edges is large enough. -/
  56. theorem eventual_capacity (a : ℕ → ℝ) (m : ℕ) (hm : 1 < ∑ i ∈ Finset.range m, a i) :
  57. ∃ B : ℕ, ∀ E ≥ B, E ≤ ∑ i ∈ Finset.range m, ⌊a i*E⌋₊ := by
  58. let total := ∑ i ∈ Finset.range m, a i
  59. have pos : 0 < total-1 := by dsimp [total]; linarith
  60. obtain ⟨B,hB⟩ := exists_nat_gt ((m:ℝ)/(total-1))
  61. refine ⟨B,?_⟩
  62. intro E hE
  63. have hBE : (B:ℝ) ≤ E := by exact_mod_cast hE
  64. have room := (div_lt_iff₀ pos).mp (hB.trans_le hBE)
  65. have floors := Finset.sum_le_sum (s := Finset.range m) (fun i (_ : i ∈ Finset.range m) =>
  66. (Nat.lt_floor_add_one (a i * (E:ℝ))).le)
  67. rw [← Finset.sum_mul, Finset.sum_add_distrib] at floors
  68. have hreal : (E:ℝ) ≤ ∑ i ∈ Finset.range m, (⌊a i*E⌋₊:ℝ) := by
  69. simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul,mul_one] at floors
  70. dsimp [total] at room
  71. nlinarith
  72. exact_mod_cast hreal
  73. #print axioms extend_partial
  74. end DecayClassification