| 1 | module |
| 2 | |
| 3 | public import E424.Input.Drift |
| 4 | |
| 5 | @[expose] public section |
| 6 | |
| 7 | /-! |
| 8 | # Input, part 7: the stopped tree |
| 9 | -/ |
| 10 | |
| 11 | set_option linter.style.header false |
| 12 | open Finset |
| 13 | |
| 14 | namespace E424.Inp |
| 15 | |
| 16 | /-- A leaf lies in the interval of its root. -/ |
| 17 | theorem leaves_interval (L n : ℕ) (ν : Ex) (N : ℕ) {l : Ex × ℕ} (hl : l ∈ leaves L n ν N) : |
| 18 | N * l.1.slope ≤ l.2 * ν.slope ∧ l.2 * ν.slope < (N + 1) * l.1.slope := by |
| 19 | induction n generalizing ν N with |
| 20 | | zero => |
| 21 | rw [leaves, mem_singleton] at hl |
| 22 | subst hl |
| 23 | exact ⟨le_rfl, Nat.mul_lt_mul_of_pos_right (Nat.lt_succ_self _) (slope_pos _)⟩ |
| 24 | | succ n ih => |
| 25 | rw [leaves] at hl |
| 26 | split_ifs at hl with hL |
| 27 | · rw [mem_singleton] at hl |
| 28 | subst hl |
| 29 | exact ⟨le_rfl, Nat.mul_lt_mul_of_pos_right (Nat.lt_succ_self _) (slope_pos _)⟩ |
| 30 | · obtain ⟨r, hr, hl⟩ := mem_biUnion.1 hl |
| 31 | rw [mem_range] at hr |
| 32 | have h := ih _ _ hl |
| 33 | rw [slope_mul _ (act_letter _ _)] at h |
| 34 | set a := act ν (N % 36) |
| 35 | have hp := slope_pos l.1 |
| 36 | have ha : 0 < a := by have := (act_letter ν (N % 36)).two_le; omega |
| 37 | have hr' : r + 1 ≤ a := hr |
| 38 | constructor |
| 39 | · refine Nat.le_of_mul_le_mul_left ?_ ha |
| 40 | calc a * (N * l.1.slope) ≤ (a * N + r) * l.1.slope := by nlinarith |
| 41 | _ ≤ l.2 * (a * ν.slope) := h.1 |
| 42 | _ = a * (l.2 * ν.slope) := by ring |
| 43 | · refine Nat.lt_of_mul_lt_mul_left (a := a) ?_ |
| 44 | calc a * (l.2 * ν.slope) = l.2 * (a * ν.slope) := by ring |
| 45 | _ < (a * N + r + 1) * l.1.slope := h.2 |
| 46 | _ ≤ a * ((N + 1) * l.1.slope) := by nlinarith |
| 47 | |
| 48 | /-- Subtrees of different children are disjoint. -/ |
| 49 | theorem leaves_disj (L n : ℕ) (ν : Ex) (N a : ℕ) {r s : ℕ} (hrs : r ≠ s) : |
| 50 | Disjoint (leaves L n ν (a * N + r)) (leaves L n ν (a * N + s)) := by |
| 51 | rw [Finset.disjoint_left] |
| 52 | intro l hr hs |
| 53 | have h1 := leaves_interval L n _ _ hr |
| 54 | have h2 := leaves_interval L n _ _ hs |
| 55 | have h3 := Nat.lt_of_mul_lt_mul_right (h1.1.trans_lt h2.2) |
| 56 | have h4 := Nat.lt_of_mul_lt_mul_right (h2.1.trans_lt h1.2) |
| 57 | omega |
| 58 | |
| 59 | /-- Sums over a subdivided node. -/ |
| 60 | theorem sum_leaves_succ (L n : ℕ) {ν : Ex} (N : ℕ) (hL : ¬ L ≤ ν.om) (Φ : Ex × ℕ → ℝ) : |
| 61 | ∑ l ∈ leaves L (n + 1) ν N, Φ l = ∑ r ∈ range (act ν (N % 36)), |
| 62 | ∑ l ∈ leaves L n (ν.mul (act ν (N % 36))) (act ν (N % 36) * N + r), Φ l := by |
| 63 | rw [leaves, if_neg hL, sum_biUnion] |
| 64 | intro r _ s _ hrs |
| 65 | exact leaves_disj _ _ _ _ _ hrs |
| 66 | |
| 67 | /-- Total mass is conserved. -/ |
| 68 | theorem mass (L n : ℕ) (ν : Ex) (N : ℕ) : |
| 69 | ∑ l ∈ leaves L n ν N, (ν.slope : ℝ) / l.1.slope = 1 := by |
| 70 | have h0 : (ν.slope : ℝ) ≠ 0 := by exact_mod_cast (slope_pos ν).ne' |
| 71 | induction n generalizing ν N with |
| 72 | | zero => rw [leaves, sum_singleton, div_self h0] |
| 73 | | succ n ih => |
| 74 | by_cases hL : L ≤ ν.om |
| 75 | · rw [leaves, if_pos hL, sum_singleton, div_self h0] |
| 76 | rw [sum_leaves_succ L n N hL] |
| 77 | have hl := act_letter ν (N % 36) |
| 78 | set a := act ν (N % 36) |
| 79 | have ha : (a : ℝ) ≠ 0 := by have := hl.two_le; exact_mod_cast (by omega : a ≠ 0) |
| 80 | have hs : ((ν.mul a).slope : ℝ) = a * ν.slope := by exact_mod_cast slope_mul ν hl |
| 81 | have hr : ∀ r ∈ range a, ∑ l ∈ leaves L n (ν.mul a) (a * N + r), |
| 82 | (ν.slope : ℝ) / l.1.slope = 1 / a := by |
| 83 | intro r _ |
| 84 | rw [← ih (ν.mul a) (a * N + r) (by rw [hs]; positivity), sum_div] |
| 85 | refine sum_congr rfl fun l _ => ?_ |
| 86 | rw [hs] |
| 87 | field_simp |
| 88 | rw [sum_congr rfl hr, sum_const, card_range, nsmul_eq_mul] |
| 89 | field_simp |
| 90 | |
| 91 | /-- Expected potential at the leaves. -/ |
| 92 | theorem vmass (L n : ℕ) (ν : Ex) (N : ℕ) (hN : Alive (N % 36)) (hn : L ≤ ν.om + n) : |
| 93 | ∑ l ∈ leaves L n ν N, (ν.slope : ℝ) / l.1.slope * V l.1 l.2 ≤ |
| 94 | lam ^ (L - ν.om) * V ν N + c0 * ∑ i ∈ range (L - ν.om), lam ^ i := by |
| 95 | have h0 : (ν.slope : ℝ) ≠ 0 := by exact_mod_cast (slope_pos ν).ne' |
| 96 | have hstop : L ≤ ν.om → ∑ l ∈ ({(ν, N)} : Finset (Ex × ℕ)), (ν.slope : ℝ) / l.1.slope * V l.1 l.2 ≤ |
| 97 | lam ^ (L - ν.om) * V ν N + c0 * ∑ i ∈ range (L - ν.om), lam ^ i := by |
| 98 | intro h |
| 99 | rw [sum_singleton, div_self h0, Nat.sub_eq_zero_of_le h] |
| 100 | simp |
| 101 | induction n generalizing ν N with |
| 102 | | zero => rw [leaves]; exact hstop (by simpa using hn) |
| 103 | | succ n ih => |
| 104 | by_cases hL : L ≤ ν.om |
| 105 | · rw [leaves, if_pos hL]; exact hstop hL |
| 106 | rw [sum_leaves_succ L n N hL] |
| 107 | have hl := act_letter ν (N % 36) |
| 108 | have hom := om_mul ν hl |
| 109 | have hd := drift (ν := ν) hN |
| 110 | have hch := fun r (hr : r < act ν (N % 36)) => child_alive hN hr |
| 111 | set a := act ν (N % 36) |
| 112 | have ha : (0 : ℝ) < a := by have := hl.two_le; exact_mod_cast (by omega : 0 < a) |
| 113 | have hs : ((ν.mul a).slope : ℝ) = a * ν.slope := by exact_mod_cast slope_mul ν hl |
| 114 | have hell : 1 ≤ ell a := by unfold ell; split_ifs <;> omega |
| 115 | have hl0 := lam_pos |
| 116 | have hl1 := lam_lt |
| 117 | have hc := c0_nonneg |
| 118 | set m := L - (ν.mul a).om with hm |
| 119 | have hr : ∀ r ∈ range a, ∑ l ∈ leaves L n (ν.mul a) (a * N + r), |
| 120 | (ν.slope : ℝ) / l.1.slope * V l.1 l.2 ≤ |
| 121 | 1 / a * (lam ^ m * V (ν.mul a) (a * N + r) + c0 * ∑ i ∈ range m, lam ^ i) := by |
| 122 | intro r hr |
| 123 | have hs0 : ((ν.mul a).slope : ℝ) ≠ 0 := by rw [hs]; positivity |
| 124 | have hi := ih (ν.mul a) (a * N + r) (hch r (mem_range.1 hr)) (by omega) hs0 (by |
| 125 | intro h |
| 126 | rw [sum_singleton, div_self hs0, Nat.sub_eq_zero_of_le h] |
| 127 | simp) |
| 128 | refine le_trans (le_of_eq ?_) (mul_le_mul_of_nonneg_left hi (by positivity)) |
| 129 | rw [mul_sum] |
| 130 | refine sum_congr rfl fun l _ => ?_ |
| 131 | rw [hs] |
| 132 | field_simp |
| 133 | refine (sum_le_sum hr).trans ?_ |
| 134 | rw [← mul_sum, sum_add_distrib, ← mul_sum, sum_const, card_range, nsmul_eq_mul] |
| 135 | -- it remains to use the drift inequality |
| 136 | have h1 : 1 / (a : ℝ) * (lam ^ m * ∑ r ∈ range a, V (ν.mul a) (a * N + r) + |
| 137 | a * (c0 * ∑ i ∈ range m, lam ^ i)) ≤ |
| 138 | lam ^ m * (lam ^ ell a * V ν N + c0) + c0 * ∑ i ∈ range m, lam ^ i := by |
| 139 | rw [div_mul_eq_mul_div, one_mul, div_le_iff₀ ha] |
| 140 | have := mul_le_mul_of_nonneg_left hd (pow_pos lam_pos m).le |
| 141 | nlinarith |
| 142 | refine h1.trans ?_ |
| 143 | have hV := V_nonneg ν N |
| 144 | have hmle : m + 1 ≤ L - ν.om := by omega |
| 145 | have h2 : lam ^ m * lam ^ ell a * V ν N ≤ lam ^ (L - ν.om) * V ν N := by |
| 146 | refine mul_le_mul_of_nonneg_right ?_ hV |
| 147 | rw [← pow_add] |
| 148 | exact pow_le_pow_of_le_one hl0.le hl1.le (by omega) |
| 149 | have h3 : lam ^ m + ∑ i ∈ range m, lam ^ i ≤ ∑ i ∈ range (L - ν.om), lam ^ i := by |
| 150 | rw [add_comm, ← sum_range_succ] |
| 151 | exact sum_le_sum_of_subset_of_nonneg (range_mono hmle) fun i _ _ => by positivity |
| 152 | have h4 := mul_le_mul_of_nonneg_left h3 hc |
| 153 | nlinarith |
| 154 | |
| 155 | /-- Leaves are valid nodes. -/ |
| 156 | theorem leaves_valid (L n : ℕ) (ν : Ex) (N : ℕ) (hN : Alive (N % 36)) |
| 157 | (hm : IsMap ν.slope (N / 36)) {l : Ex × ℕ} (hl : l ∈ leaves L n ν N) : |
| 158 | Alive (l.2 % 36) ∧ IsMap l.1.slope (l.2 / 36) := by |
| 159 | induction n generalizing ν N with |
| 160 | | zero => |
| 161 | rw [leaves, mem_singleton] at hl |
| 162 | subst hl |
| 163 | exact ⟨hN, hm⟩ |
| 164 | | succ n ih => |
| 165 | rw [leaves] at hl |
| 166 | split_ifs at hl with hL |
| 167 | · rw [mem_singleton] at hl |
| 168 | subst hl |
| 169 | exact ⟨hN, hm⟩ |
| 170 | · obtain ⟨r, hr, hl⟩ := mem_biUnion.1 hl |
| 171 | rw [mem_range] at hr |
| 172 | exact ih _ _ (child_alive hN hr) (child_isMap hN hr hm) hl |
| 173 | |
| 174 | /-- Leaves stop at the right time. -/ |
| 175 | theorem leaves_om (L n : ℕ) (ν : Ex) (N : ℕ) (hn : L ≤ ν.om + n) (hL : ν.om ≤ L + 1) |
| 176 | {l : Ex × ℕ} (hl : l ∈ leaves L n ν N) : L ≤ l.1.om ∧ l.1.om ≤ L + 1 := by |
| 177 | induction n generalizing ν N with |
| 178 | | zero => |
| 179 | rw [leaves, mem_singleton] at hl |
| 180 | subst hl |
| 181 | exact ⟨by simpa using hn, hL⟩ |
| 182 | | succ n ih => |
| 183 | rw [leaves] at hl |
| 184 | split_ifs at hl with hL' |
| 185 | · rw [mem_singleton] at hl |
| 186 | subst hl |
| 187 | exact ⟨hL', hL⟩ |
| 188 | · obtain ⟨r, hr, hl⟩ := mem_biUnion.1 hl |
| 189 | have h := om_mul ν (act_letter ν (N % 36)) |
| 190 | have hell : 1 ≤ ell (act ν (N % 36)) ∧ ell (act ν (N % 36)) ≤ 2 := by |
| 191 | unfold ell; split_ifs <;> omega |
| 192 | exact ih _ _ (by omega) (by omega) hl |
| 193 | |
| 194 | end E424.Inp |
| 195 | |