Lean / Reader
Lean readerDecayModelBounds.lean
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.
import DecayPaletteGraphsimport DecayScalingnamespace DecayClassificationnamespace PaletteGraphdef denom (D i : ℕ) := (i+1)^(D*(i+1))def weight (D x : ℕ) := x^(D*x)def Fits {n r k} (G : PaletteGraph n r k) (A D : ℕ) : Prop :=∀ i, ((edges n).filter fun e => G.labels e = i).card * denom D i ≤ A*(edges n).cardtheorem weight_mono (D : ℕ) : Monotone (weight D) := byintro x y hby_cases zero : y = 0· have eq : x = y := by omegarw [eq]· exact (Nat.pow_le_pow_left h _).trans(Nat.pow_le_pow_right (by omega : 0 < y) (Nat.mul_le_mul_left D h))theorem count_zero {n r k} (G : PaletteGraph n r k) {i : ℕ} (h : r ≤ i) :((edges n).filter fun e => G.labels e = i).card = 0 := byapply Finset.card_eq_zero.mprapply Finset.eq_empty_iff_forall_notMem.mprintro e hehave eq := (Finset.mem_filter.mp he).2have lt : G.labels e < r := (G.color ..).isLtomegatheorem initial_fits {n r k} (G : PaletteGraph n r k) (D : ℕ) : G.Fits (weight D r) D := byintro iby_cases small : i < r· have price : denom D i ≤ weight D r := weight_mono D (show i+1 ≤ r by omega)exact (Nat.mul_le_mul (Finset.card_le_card (Finset.filter_subset ..)) price).trans_eq (mul_comm ..)· rw [count_zero _ (by omega),zero_mul]; omegatheorem apart_fits {n m r s k h A D} (G : PaletteGraph n r k) (H : PaletteGraph m s h)(old : G.Fits A D) (hA : 1 ≤ A) (room : weight D (r+s) ≤ n) :(G.apart H).Fits A D := byintro iby_cases early : i < r· calc_ ≤ ((((edges n).filter fun e => G.labels e = i).card*(m*m))*denom D i) :=Nat.mul_le_mul_right _ (old_count G H i early)_ = ((((edges n).filter fun e => G.labels e = i).card*denom D i)*(m*m)) := by ring_ ≤ (A*(edges n).card)*(m*m) := Nat.mul_le_mul_right _ (old i)_ ≤ _ := by rw [mul_assoc]; exact Nat.mul_le_mul_left A (copy_capacity n m)· by_cases valid : i < r+s· have price : denom D i ≤ n := (weight_mono D (show i+1 ≤ r+s by omega)).trans roomhave total := copy_capacity m nrw [Nat.mul_comm m n] at totalcalc_ ≤ (n*(edges m).card)*n := Nat.mul_le_mul (new_count G H i (by omega)) price_ = (edges m).card*(n*n) := by ring_ ≤ (edges (n*m)).card := total_ ≤ _ := by simpa using Nat.mul_le_mul_right (edges (n*m)).card hA· rw [count_zero _ (by omega),zero_mul]; omegatheorem bounded_of_fits {n r k A D} (G : PaletteGraph n r k) (fit : G.Fits A D) :Bounded (regular (A:ℝ) D) G.labels := byintro ihave h : (((edges n).filter fun e => G.labels e = i).card : ℝ) *((i+1:ℕ):ℝ)^(D*(i+1)) ≤ (A:ℝ)*(edges n).card := byexact_mod_cast (fit i : _ * ((i+1)^(D*(i+1))) ≤ _)have pos : 0 < ((i+1:ℕ):ℝ)^(D*(i+1)) := by positivityunfold regularrw [div_mul_eq_mul_div,le_div_iff₀ pos]exact h/-- Enough vertices to round capacities for every cutoff in the next palette. -/def Enough (D r n : ℕ) := weight (D+1) (2*r) ≤ ntheorem enough_appending {D r n : ℕ} (hr : 1 ≤ r) (h : Enough D r n) :weight D (r+r) ≤ n := byrw [← two_mul]exact (Nat.pow_le_pow_right (by omega : 0 < 2*r)(show D*(2*r) ≤ (D+1)*(2*r) by nlinarith)).trans htheorem size_at_cutoff {D r n j : ℕ} (hr : 1 ≤ r) (hj : j+1 ≤ 2*r) (h : Enough D r n) :denom D j < n ∧ j+1 ≤ n := byhave hb : 1 < 2*r := by omegahave a : denom D j ≤ weight D (2*r) := weight_mono D hjhave b : weight D (2*r) < weight (D+1) (2*r) :=Nat.pow_lt_pow_right hb (by nlinarith)have c : 2*r ≤ weight (D+1) (2*r) := bycalc_ = (2*r)^1 := by simp_ ≤ _ := Nat.pow_le_pow_right (by omega) (by nlinarith : 1 ≤ (D+1)*(2*r))exact ⟨(a.trans_lt b).trans_le h,hj.trans (c.trans h)⟩theorem round_at_cutoff {D A J n : ℕ} (ha : 1 ≤ A) (h : denom D J < n) :1 ≤ 2*regular (A:ℝ) D J*(edges n).card := byhave le : (((J+1:ℕ):ℝ)^(D*(J+1))) ≤ (edges n).card := byexact_mod_cast (edge_count_large h : (J+1)^(D*(J+1)) ≤ _)have A1 : (1:ℝ) ≤ A := by exact_mod_cast hahave pos : 0 < ((J+1:ℕ):ℝ)^(D*(J+1)) := by positivityunfold regularrw [← mul_div_assoc,div_mul_eq_mul_div,le_div_iff₀ pos]nlinarith [mul_le_mul_of_nonneg_right A1 (show 0 ≤ ((edges n).card : ℝ) by positivity)]end PaletteGraphend DecayClassification