Lean / Reader
Lean reader

DecayModelBounds.lean

103 lines12 declarationsno sorryimports DecayPaletteGraphs DecayScaling

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

  1. import DecayPaletteGraphs
  2. import DecayScaling
  3. namespace DecayClassification
  4. namespace PaletteGraph
  5. def denom (D i : ℕ) := (i+1)^(D*(i+1))
  6. def weight (D x : ℕ) := x^(D*x)
  7. def Fits {n r k} (G : PaletteGraph n r k) (A D : ℕ) : Prop :=
  8. ∀ i, ((edges n).filter fun e => G.labels e = i).card * denom D i ≤ A*(edges n).card
  9. theorem weight_mono (D : ℕ) : Monotone (weight D) := by
  10. intro x y h
  11. by_cases zero : y = 0
  12. · have eq : x = y := by omega
  13. rw [eq]
  14. · exact (Nat.pow_le_pow_left h _).trans
  15. (Nat.pow_le_pow_right (by omega : 0 < y) (Nat.mul_le_mul_left D h))
  16. theorem count_zero {n r k} (G : PaletteGraph n r k) {i : ℕ} (h : r ≤ i) :
  17. ((edges n).filter fun e => G.labels e = i).card = 0 := by
  18. apply Finset.card_eq_zero.mpr
  19. apply Finset.eq_empty_iff_forall_notMem.mpr
  20. intro e he
  21. have eq := (Finset.mem_filter.mp he).2
  22. have lt : G.labels e < r := (G.color ..).isLt
  23. omega
  24. theorem initial_fits {n r k} (G : PaletteGraph n r k) (D : ℕ) : G.Fits (weight D r) D := by
  25. intro i
  26. by_cases small : i < r
  27. · have price : denom D i ≤ weight D r := weight_mono D (show i+1 ≤ r by omega)
  28. exact (Nat.mul_le_mul (Finset.card_le_card (Finset.filter_subset ..)) price).trans_eq (mul_comm ..)
  29. · rw [count_zero _ (by omega),zero_mul]; omega
  30. theorem apart_fits {n m r s k h A D} (G : PaletteGraph n r k) (H : PaletteGraph m s h)
  31. (old : G.Fits A D) (hA : 1 ≤ A) (room : weight D (r+s) ≤ n) :
  32. (G.apart H).Fits A D := by
  33. intro i
  34. by_cases early : i < r
  35. · calc
  36. _ ≤ ((((edges n).filter fun e => G.labels e = i).card*(m*m))*denom D i) :=
  37. Nat.mul_le_mul_right _ (old_count G H i early)
  38. _ = ((((edges n).filter fun e => G.labels e = i).card*denom D i)*(m*m)) := by ring
  39. _ ≤ (A*(edges n).card)*(m*m) := Nat.mul_le_mul_right _ (old i)
  40. _ ≤ _ := by rw [mul_assoc]; exact Nat.mul_le_mul_left A (copy_capacity n m)
  41. · by_cases valid : i < r+s
  42. · have price : denom D i ≤ n := (weight_mono D (show i+1 ≤ r+s by omega)).trans room
  43. have total := copy_capacity m n
  44. rw [Nat.mul_comm m n] at total
  45. calc
  46. _ ≤ (n*(edges m).card)*n := Nat.mul_le_mul (new_count G H i (by omega)) price
  47. _ = (edges m).card*(n*n) := by ring
  48. _ ≤ (edges (n*m)).card := total
  49. _ ≤ _ := by simpa using Nat.mul_le_mul_right (edges (n*m)).card hA
  50. · rw [count_zero _ (by omega),zero_mul]; omega
  51. theorem bounded_of_fits {n r k A D} (G : PaletteGraph n r k) (fit : G.Fits A D) :
  52. Bounded (regular (A:ℝ) D) G.labels := by
  53. intro i
  54. have h : (((edges n).filter fun e => G.labels e = i).card : ℝ) *
  55. ((i+1:ℕ):ℝ)^(D*(i+1)) ≤ (A:ℝ)*(edges n).card := by
  56. exact_mod_cast (fit i : _ * ((i+1)^(D*(i+1))) ≤ _)
  57. have pos : 0 < ((i+1:ℕ):ℝ)^(D*(i+1)) := by positivity
  58. unfold regular
  59. rw [div_mul_eq_mul_div,le_div_iff₀ pos]
  60. exact h
  61. /-- Enough vertices to round capacities for every cutoff in the next palette. -/
  62. def Enough (D r n : ℕ) := weight (D+1) (2*r) ≤ n
  63. theorem enough_appending {D r n : ℕ} (hr : 1 ≤ r) (h : Enough D r n) :
  64. weight D (r+r) ≤ n := by
  65. rw [← two_mul]
  66. exact (Nat.pow_le_pow_right (by omega : 0 < 2*r)
  67. (show D*(2*r) ≤ (D+1)*(2*r) by nlinarith)).trans h
  68. theorem size_at_cutoff {D r n j : ℕ} (hr : 1 ≤ r) (hj : j+1 ≤ 2*r) (h : Enough D r n) :
  69. denom D j < n ∧ j+1 ≤ n := by
  70. have hb : 1 < 2*r := by omega
  71. have a : denom D j ≤ weight D (2*r) := weight_mono D hj
  72. have b : weight D (2*r) < weight (D+1) (2*r) :=
  73. Nat.pow_lt_pow_right hb (by nlinarith)
  74. have c : 2*r ≤ weight (D+1) (2*r) := by
  75. calc
  76. _ = (2*r)^1 := by simp
  77. _ ≤ _ := Nat.pow_le_pow_right (by omega) (by nlinarith : 1 ≤ (D+1)*(2*r))
  78. exact ⟨(a.trans_lt b).trans_le h,hj.trans (c.trans h)⟩
  79. theorem round_at_cutoff {D A J n : ℕ} (ha : 1 ≤ A) (h : denom D J < n) :
  80. 1 ≤ 2*regular (A:ℝ) D J*(edges n).card := by
  81. have le : (((J+1:ℕ):ℝ)^(D*(J+1))) ≤ (edges n).card := by
  82. exact_mod_cast (edge_count_large h : (J+1)^(D*(J+1)) ≤ _)
  83. have A1 : (1:ℝ) ≤ A := by exact_mod_cast ha
  84. have pos : 0 < ((J+1:ℕ):ℝ)^(D*(J+1)) := by positivity
  85. unfold regular
  86. rw [← mul_div_assoc,div_mul_eq_mul_div,le_div_iff₀ pos]
  87. nlinarith [mul_le_mul_of_nonneg_right A1 (show 0 ≤ ((edges n).card : ℝ) by positivity)]
  88. end PaletteGraph
  89. end DecayClassification