| 1 | module |
| 2 | |
| 3 | public import E424.Input.Leaves |
| 4 | |
| 5 | @[expose] public section |
| 6 | |
| 7 | /-! |
| 8 | # Input, part 8: many maps of one slope |
| 9 | -/ |
| 10 | |
| 11 | set_option linter.style.header false |
| 12 | open Finset |
| 13 | |
| 14 | namespace E424.Inp |
| 15 | |
| 16 | /-- `ν` is within `B` of `m (24, 27, 12, 2)`. -/ |
| 17 | def Near (B m : ℕ) (ν : Ex) : Prop := |
| 18 | (ν.e2 ≤ 24 * m + B ∧ 24 * m ≤ ν.e2 + B) ∧ (ν.e3 ≤ 27 * m + B ∧ 27 * m ≤ ν.e3 + B) ∧ |
| 19 | (ν.e5 ≤ 12 * m + B ∧ 12 * m ≤ ν.e5 + B) ∧ (ν.e7 ≤ 2 * m + B ∧ 2 * m ≤ ν.e7 + B) |
| 20 | |
| 21 | /-- Small imbalance and the right clock force `ν` to be near the target. -/ |
| 22 | theorem near_of_g {R m : ℕ} {ν : Ex} (hm : 65 * m ≤ ν.om) (hm' : ν.om ≤ 65 * m + 1) |
| 23 | (hg : ∀ κ, g κ ν ≤ R) : Near (R + 1) m ν := by |
| 24 | have a0 : h1 ν ≤ R := hg 0 |
| 25 | have a1 : -h1 ν ≤ R := hg 1 |
| 26 | have a2 : h2 ν ≤ R := hg 2 |
| 27 | have a3 : -h2 ν ≤ R := hg 3 |
| 28 | have a4 : h3 ν ≤ R := hg 4 |
| 29 | have a5 : -h3 ν ≤ R := hg 5 |
| 30 | simp only [h1, h2, h3] at a0 a1 a2 a3 a4 a5 |
| 31 | simp only [Ex.om] at hm hm' |
| 32 | unfold Near |
| 33 | refine ⟨⟨?_, ?_⟩, ⟨?_, ?_⟩, ⟨?_, ?_⟩, ⟨?_, ?_⟩⟩ <;> omega |
| 34 | |
| 35 | /-- The box of `Near`. -/ |
| 36 | def box (B m : ℕ) : Finset Ex := |
| 37 | ((range (2 * B + 1) ×ˢ range (2 * B + 1)) ×ˢ (range (2 * B + 1) ×ˢ range (2 * B + 1))).image |
| 38 | fun t => ⟨24 * m + B - t.1.1, 27 * m + B - t.1.2, 12 * m + B - t.2.1, 2 * m + B - t.2.2⟩ |
| 39 | |
| 40 | theorem mem_box {B m : ℕ} {ν : Ex} (h : Near B m ν) : ν ∈ box B m := by |
| 41 | unfold Near at h |
| 42 | refine mem_image.2 ⟨((24 * m + B - ν.e2, 27 * m + B - ν.e3), (12 * m + B - ν.e5, 2 * m + B - ν.e7)), |
| 43 | ?_, ?_⟩ |
| 44 | · simp only [mem_product, mem_range]; omega |
| 45 | · ext <;> simp only <;> omega |
| 46 | |
| 47 | theorem card_box (B m : ℕ) : (box B m).card ≤ (2 * B + 1) ^ 4 := by |
| 48 | refine card_image_le.trans (le_of_eq ?_) |
| 49 | simp only [card_product, card_range] |
| 50 | ring |
| 51 | |
| 52 | /-- The total expected potential is bounded, uniformly in the clock. -/ |
| 53 | theorem vbound : ∃ W : ℝ, 0 < W ∧ ∀ L : ℕ, |
| 54 | ∑ l ∈ leaves L L ⟨0, 0, 0, 0⟩ 3, 1 / (l.1.slope : ℝ) * V l.1 l.2 ≤ W := by |
| 55 | refine ⟨V ⟨0, 0, 0, 0⟩ 3 + c0 * (1 - lam)⁻¹ + 1, ?_, fun L => ?_⟩ |
| 56 | · have := V_nonneg ⟨0, 0, 0, 0⟩ 3 |
| 57 | have := c0_nonneg |
| 58 | have : 0 < (1 - lam)⁻¹ := inv_pos.2 (by linarith [lam_lt]) |
| 59 | positivity |
| 60 | · have h := vmass L L ⟨0, 0, 0, 0⟩ 3 (by norm_num [Alive]) (by simp [Ex.om]) |
| 61 | simp only [Ex.om, Ex.slope, pow_zero, mul_one, Nat.cast_one, add_zero, Nat.sub_zero] at h |
| 62 | refine h.trans ?_ |
| 63 | have h1 : lam ^ L ≤ 1 := pow_le_one₀ lam_pos.le lam_lt.le |
| 64 | have h2 : ∑ i ∈ range L, lam ^ i ≤ (1 - lam)⁻¹ := by |
| 65 | rw [← tsum_geometric_of_lt_one lam_pos.le lam_lt] |
| 66 | exact (summable_geometric_of_lt_one lam_pos.le lam_lt).sum_le_tsum _ |
| 67 | fun i _ => pow_nonneg lam_pos.le i |
| 68 | have h3 := mul_le_mul_of_nonneg_right h1 (V_nonneg ⟨0, 0, 0, 0⟩ 3) |
| 69 | have h4 := mul_le_mul_of_nonneg_left h2 c0_nonneg |
| 70 | linarith |
| 71 | |
| 72 | /-- **Many maps of one slope.** -/ |
| 73 | theorem exists_dense : ∃ B : ℕ, 1 ≤ B ∧ ∃ κ > (0 : ℝ), ∀ m : ℕ, ∃ ν : Ex, Near B m ν ∧ |
| 74 | ∃ S : Finset ℕ, κ * ν.slope ≤ S.card ∧ ∀ c ∈ S, IsMap ν.slope c := by |
| 75 | classical |
| 76 | obtain ⟨W, hW, hvb⟩ := vbound |
| 77 | -- `z ^ t ≤ 2 W` forces `t ≤ R` |
| 78 | obtain ⟨R, hR⟩ := pow_unbounded_of_one_lt (2 * W) one_lt_z |
| 79 | refine ⟨R + 1, by omega, 1 / (72 * (2 * (R + 1 : ℕ) + 1 : ℕ) ^ 4), by positivity, fun m => ?_⟩ |
| 80 | set T := leaves (65 * m) (65 * m) ⟨0, 0, 0, 0⟩ 3 with hT |
| 81 | have hval : ∀ l ∈ T, Alive (l.2 % 36) ∧ IsMap l.1.slope (l.2 / 36) := fun l hl => |
| 82 | leaves_valid _ _ _ _ (by norm_num [Alive]) (by simpa [Ex.slope] using IsMap.one) hl |
| 83 | have hom : ∀ l ∈ T, 65 * m ≤ l.1.om ∧ l.1.om ≤ 65 * m + 1 := fun l hl => |
| 84 | leaves_om _ _ _ _ (by simp [Ex.om]) (by simp [Ex.om]) hl |
| 85 | have hmass : ∑ l ∈ T, 1 / (l.1.slope : ℝ) = 1 := by |
| 86 | have h := mass (65 * m) (65 * m) ⟨0, 0, 0, 0⟩ 3 |
| 87 | simpa only [Ex.slope, pow_zero, mul_one, Nat.cast_one] using h |
| 88 | have hsp : ∀ ν : Ex, (0 : ℝ) < ν.slope := fun ν => by exact_mod_cast slope_pos ν |
| 89 | -- Markov: the leaves with `V ≤ 2 W` carry half of the mass |
| 90 | set T' := T.filter fun l => V l.1 l.2 ≤ 2 * W with hT' |
| 91 | have hhalf : 1 / 2 ≤ ∑ l ∈ T', 1 / (l.1.slope : ℝ) := by |
| 92 | have h1 := sum_filter_add_sum_filter_not T (fun l => V l.1 l.2 ≤ 2 * W) |
| 93 | fun l => 1 / (l.1.slope : ℝ) |
| 94 | have h2 : ∑ l ∈ T.filter (fun l => ¬ V l.1 l.2 ≤ 2 * W), 1 / (l.1.slope : ℝ) ≤ 1 / 2 := by |
| 95 | have h3 : 2 * W * ∑ l ∈ T.filter (fun l => ¬ V l.1 l.2 ≤ 2 * W), 1 / (l.1.slope : ℝ) ≤ W := by |
| 96 | refine le_trans ?_ (hvb (65 * m)) |
| 97 | rw [mul_sum] |
| 98 | refine (sum_le_sum fun l hl => ?_).trans (sum_le_sum_of_subset_of_nonneg |
| 99 | (filter_subset _ _) fun l _ _ => |
| 100 | mul_nonneg (one_div_nonneg.2 (hsp l.1).le) (V_nonneg _ _)) |
| 101 | rw [mul_comm] |
| 102 | exact mul_le_mul_of_nonneg_left (not_le.1 (mem_filter.1 hl).2).le |
| 103 | (one_div_nonneg.2 (hsp l.1).le) |
| 104 | rw [← not_lt] |
| 105 | intro h |
| 106 | nlinarith |
| 107 | linarith |
| 108 | have hnear : ∀ l ∈ T', Near (R + 1) m l.1 := by |
| 109 | intro l hl |
| 110 | obtain ⟨hl, hlV⟩ := mem_filter.1 hl |
| 111 | refine near_of_g (hom l hl).1 (hom l hl).2 fun κ => ?_ |
| 112 | have h := ((le_V (hval l hl).1 κ).trans hlV).trans_lt hR |
| 113 | rw [← zpow_natCast] at h |
| 114 | exact ((zpow_lt_zpow_iff_right₀ one_lt_z).1 h).le |
| 115 | -- pigeonhole over the box |
| 116 | have hmaps : ∀ l ∈ T', l.1 ∈ box (R + 1) m := fun l hl => mem_box (hnear l hl) |
| 117 | have hcard : ((box (R + 1) m).card : ℝ) ≤ ((2 * (R + 1) + 1 : ℕ) : ℝ) ^ 4 := by |
| 118 | exact_mod_cast card_box (R + 1) m |
| 119 | set P : ℝ := ((2 * (R + 1) + 1 : ℕ) : ℝ) ^ 4 with hP |
| 120 | have hP0 : 0 < P := by positivity |
| 121 | obtain ⟨ν, hν, hpig⟩ : ∃ ν ∈ box (R + 1) m, |
| 122 | 1 / (2 * P) ≤ ∑ l ∈ T' with l.1 = ν, 1 / (l.1.slope : ℝ) := by |
| 123 | by_contra hcon |
| 124 | push Not at hcon |
| 125 | rw [← sum_fiberwise_of_maps_to hmaps] at hhalf |
| 126 | have hne : (box (R + 1) m).Nonempty := by |
| 127 | by_contra hne |
| 128 | rw [not_nonempty_iff_eq_empty] at hne |
| 129 | rw [hne, sum_empty] at hhalf |
| 130 | linarith |
| 131 | have h1 := sum_lt_sum_of_nonempty hne hcon |
| 132 | rw [sum_const, nsmul_eq_mul] at h1 |
| 133 | have h2 : ((box (R + 1) m).card : ℝ) * (1 / (2 * P)) ≤ P * (1 / (2 * P)) := by gcongr |
| 134 | have h3 : P * (1 / (2 * P)) = 1 / 2 := by field_simp |
| 135 | linarith |
| 136 | have hfib : ∑ l ∈ T' with l.1 = ν, 1 / (l.1.slope : ℝ) = |
| 137 | ((T'.filter fun l => l.1 = ν).card : ℝ) * (1 / ν.slope) := by |
| 138 | rw [← nsmul_eq_mul, ← sum_const] |
| 139 | exact sum_congr rfl fun l hl => by rw [(mem_filter.1 hl).2] |
| 140 | set T₂ := T'.filter fun l => l.1 = ν with hT₂ |
| 141 | have hbig : 1 / (2 * P) * ν.slope ≤ T₂.card := by |
| 142 | rw [hfib, mul_one_div, le_div_iff₀ (hsp ν)] at hpig |
| 143 | exact hpig |
| 144 | have hne : T₂.Nonempty := by |
| 145 | rw [← card_pos] |
| 146 | have : (0 : ℝ) < T₂.card := lt_of_lt_of_le (mul_pos (by positivity) (hsp ν)) hbig |
| 147 | exact_mod_cast this |
| 148 | have hmem : ∀ l ∈ T₂, l ∈ T ∧ l ∈ T' ∧ l.1 = ν := fun l hl => |
| 149 | ⟨(mem_filter.1 (mem_filter.1 hl).1).1, (mem_filter.1 hl).1, (mem_filter.1 hl).2⟩ |
| 150 | refine ⟨ν, ?_, T₂.image fun l => l.2 / 36, ?_, ?_⟩ |
| 151 | · obtain ⟨l, hl⟩ := hne |
| 152 | rw [← (hmem l hl).2.2] |
| 153 | exact hnear l (hmem l hl).2.1 |
| 154 | · -- at most 36 leaves share an offset |
| 155 | have h36 : T₂.card ≤ 36 * (T₂.image fun l => l.2 / 36).card := by |
| 156 | refine card_le_mul_card_image _ _ fun c _ => ?_ |
| 157 | refine (card_le_card_of_injOn (fun l => l.2 % 36) (t := range 36) |
| 158 | (fun l _ => by simp [Nat.mod_lt]) ?_).trans (card_range 36).le |
| 159 | intro l hl l' hl' h |
| 160 | rw [mem_coe, mem_filter] at hl hl' |
| 161 | refine Prod.ext ((hmem l hl.1).2.2.trans (hmem l' hl'.1).2.2.symm) ?_ |
| 162 | have h1 := hl.2 |
| 163 | have h2 := hl'.2 |
| 164 | simp only at h h1 h2 |
| 165 | omega |
| 166 | have h36' : (T₂.card : ℝ) ≤ 36 * (T₂.image fun l => l.2 / 36).card := by exact_mod_cast h36 |
| 167 | have e : 1 / (72 * P) * ν.slope = 1 / (2 * P) * ν.slope / 36 := by field_simp; ring |
| 168 | rw [e, div_le_iff₀ (by norm_num)] |
| 169 | linarith |
| 170 | · intro c hc |
| 171 | obtain ⟨l, hl, rfl⟩ := mem_image.1 hc |
| 172 | have := (hval l (hmem l hl).1).2 |
| 173 | rwa [(hmem l hl).2.2] at this |
| 174 | |
| 175 | end E424.Inp |
| 176 | |