Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/yang/blob/main/proofs/DyadicPartition.lean # yang This project has not described itself yet. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `yang / proofs / DyadicPartition.lean` 432 lines · 22421 bytes Raw Blame History 1 import DyadicTrig 2 import DyadicExp 3 import Mathlib.MeasureTheory.Integral.IntervalIntegral.Basic 4 import Mathlib.Tactic 5 6 open MeasureTheory Set YangMills.DyadicTrig YangMills.DyadicExp 7 8 namespace YangMills.DyadicPartition 9 10 structure Cell where 11 cosLo : Int 12 cosHi : Int 13 sinLo : Int 14 sinHi : Int 15 deriving Inhabited 16 17 def angleCell (i : ℕ) : Cell := 18 let sq := sinSqBounds i 19 ⟨(cosBounds 11 (i+1)).1 / 4, ceilDiv (cosBounds 11 i).2 4, 20 sq.1 / `4194304`, ceilDiv sq.2 `4194304`⟩ 21 22 def loMul (x lo hi : Int) := min (x*lo) (x*hi) / q 23 def hiMul (x lo hi : Int) := ceilDiv (max (x*lo) (x*hi)) q 24 25 def weightLo (c : Cell) (rl rh : ℤ) := c.sinLo * expLo (loMul c.cosLo rl rh) / q 26 def weightHi (c : Cell) (rl rh : ℤ) := ceilDiv (c.sinHi * expHi (hiMul c.cosHi rl rh)) q 27 28 theorem floor_mul_bound (x : ℤ) {d : ℤ} (hd : 0 < d) : 29 ((x / d : ℤ) : ℝ) * d ≤ x := by exact_mod_cast Int.ediv_mul_le x hd.ne' 30 31 theorem ceil_mul_bound (x : ℤ) {d : ℤ} (hd : 0 < d) : 32 (x:ℝ) ≤ (ceilDiv x d : ℝ) * d := by 33 have h := floor_mul_bound (-x) hd 34 simp [ceilDiv] at * 35 linarith 36 37 theorem grid_enclosure {i : ℕ} (hi : i < 2048) {t : ℝ} 38 (ht : t ∈ Icc (angle 11 i) (angle 11 (i+1))) : 39 (angleCell i).cosLo / (q:ℝ) ≤ Real.cos t ∧ Real.cos t ≤ (angleCell i).cosHi / (q:ℝ) ∧ 40 (angleCell i).sinLo / (q:ℝ) ≤ Real.sin t ^ 2 ∧ Real.sin t ^ 2 ≤ (angleCell i).sinHi / (q:ℝ) := by 41 obtain ⟨a,b,c,d⟩ := grid_cell_sound hi ht 42 have e := floor_mul_bound (cosBounds 11 (i+1)).1 (show (0:ℤ)<4 by decide) 43 have f := ceil_mul_bound (cosBounds 11 i).2 (show (0:ℤ)<4 by decide) 44 have g := floor_mul_bound (sinSqBounds i).1 (show (0:ℤ)<`4194304` by decide) 45 have h := ceil_mul_bound (sinSqBounds i).2 (show (0:ℤ)<`4194304` by decide) 46 dsimp [angleCell, q, scale] at * 47 norm_num only [Int.cast_ofNat] at * 48 exact ⟨by linarith, by linarith, by linarith, by linarith⟩ 49 50 noncomputable def polarWeight (r t : ℝ) := Real.sin t ^ 2 * Real.exp (r * Real.cos t) 51 52 theorem mul_bounds (x rl rh : ℤ) {r : ℝ} 53 (hl : (rl : ℝ)/q ≤ r) (hh : r ≤ (rh : ℝ)/q) : 54 (loMul x rl rh : ℝ)/q ≤ (x:ℝ)/q * r ∧ 55 (x:ℝ)/q * r ≤ (hiMul x rl rh : ℝ)/q := by 56 have a := floor_mul_bound (min (x*rl) (x*rh)) (show 0 < q by decide) 57 have b := ceil_mul_bound (max (x*rl) (x*rh)) (show 0 < q by decide) 58 change (loMul x rl rh : ℝ)*q ≤ _ at a 59 change _ ≤ (hiMul x rl rh : ℝ)*q at b 60 push_cast at a b 61 have hq : (0:ℝ) < q := by norm_num [q] 62 rcases le_total 0 (x:ℝ) with hx | hx 63 · have l := mul_le_mul_of_nonneg_left hl hx 64 have h := mul_le_mul_of_nonneg_left hh hx 65 have a' := a.trans (min_le_left _ _) 66 have b' := (le_max_right _ _).trans b 67 norm_num [q] at l h a' b' ⊢; constructor <;> linarith 68 · have l := mul_le_mul_of_nonpos_left hl hx 69 have h := mul_le_mul_of_nonpos_left hh hx 70 have a' := a.trans (min_le_right _ _) 71 have b' := (le_max_left _ _).trans b 72 norm_num [q] at l h a' b' ⊢; constructor <;> linarith 73 74 /-- The actual integer weight bounds enclose the continuous density throughout one angular cell. -/ 75 theorem weight_sound {i : ℕ} (hi : i < 2048) {r t : ℝ} {rl rh : ℤ} 76 (ht : t ∈ Icc (angle 11 i) (angle 11 (i+1))) (hr : 0 ≤ r) 77 (hl : (rl:ℝ)/q ≤ r) (hh : r ≤ (rh:ℝ)/q) 78 (el : -(2*q) ≤ loMul (angleCell i).cosLo rl rh) 79 (eh : hiMul (angleCell i).cosHi rl rh ≤ 2*q) : 80 (weightLo (angleCell i) rl rh : ℝ) / q ≤ polarWeight r t ∧ 81 polarWeight r t ≤ (weightHi (angleCell i) rl rh : ℝ) / q := by 82 let c := angleCell i 83 obtain ⟨cl,ch,sl,sh⟩ := grid_enclosure hi ht 84 have xl := (mul_bounds c.cosLo rl rh hl hh).1.trans (mul_le_mul_of_nonneg_right cl hr) 85 have xh := (mul_le_mul_of_nonneg_right ch hr).trans (mul_bounds c.cosHi rl rh hl hh).2 86 have al := (expLo_sound el).trans (Real.exp_le_exp.mpr xl) 87 have ah := (Real.exp_le_exp.mpr xh).trans (expHi_sound eh) 88 have ep : (0:ℝ) ≤ (expLo (loMul c.cosLo rl rh) : ℝ) / q := 89 div_nonneg (by exact_mod_cast (expLo_pos el).le) (by norm_num [q]) 90 have sl' := mul_le_mul sl al ep (sq_nonneg (Real.sin t)) 91 have sh' := mul_le_mul sh ah (Real.exp_pos _).le ((sq_nonneg (Real.sin t)).trans sh) 92 have dl := floor_mul_bound (c.sinLo * expLo (loMul c.cosLo rl rh)) (show 0 < q by decide) 93 have uh := ceil_mul_bound (c.sinHi * expHi (hiMul c.cosHi rl rh)) (show 0 < q by decide) 94 change (weightLo c rl rh : ℝ)*q ≤ _ at dl 95 change _ ≤ (weightHi c rl rh : ℝ)*q at uh 96 push_cast at dl uh 97 change (c.sinLo:ℝ)/q * _ ≤ _ at sl' 98 change _ ≤ (c.sinHi:ℝ)/q * _ at sh' 99 change (weightLo c rl rh : ℝ)/q ≤ polarWeight r t ∧ polarWeight r t ≤ (weightHi c rl rh : ℝ)/q 100 unfold polarWeight 101 rw [mul_comm r] 102 norm_num [q] at dl uh sl' sh' ⊢ 103 constructor <;> linarith 104 105 /-- Integer upper cost used by the transverse trial field in the replay. -/ 106 def transverseCap (c : Cell) (rl rh : ℤ) : ℤ := 107 let xl := loMul c.cosLo rl rh 108 let xh := hiMul c.cosHi rl rh 109 let d := max (-((2*q-hiMul xh c.sinLo c.sinHi)/6)) (ceilDiv (2*q-loMul xl c.sinLo c.sinHi) 6) 110 let a := max (-c.cosLo) c.cosHi 111 ceilDiv (ceilDiv (a*a) q) 27 + ceilDiv (2*ceilDiv (d*d) q) 3 112 113 noncomputable def transverseTrial (r t : ℝ) := 114 Real.cos t ^ 2/27 + (2/3:ℝ)*(1/3-r*Real.cos t*(Real.sin t)^2/6)^2 115 116 private theorem weighted_trial_nonneg (r t : ℝ) : 0 ≤ polarWeight r t * transverseTrial r t := by 117 unfold polarWeight transverseTrial 118 positivity 119 120 private theorem rounded_square (z : ℤ) (x : ℝ) (h : |x| ≤ z/(q:ℝ)) : 121 x^2 ≤ (ceilDiv (z*z) q:ℝ)/q := by 122 have nonneg := (abs_nonneg x).trans h 123 have sq := pow_le_pow_left₀ (abs_nonneg x) h 2 124 rw [sq_abs] at sq 125 have u := ceil_mul_bound (z*z) (show 0 < q by decide) 126 push_cast at u; norm_num [q] at u sq ⊢; linarith 127 128 theorem transverse_cost_sound {i : ℕ} (hi : i < 2048) {r t : ℝ} {rl rh : ℤ} 129 (ht : t ∈ Icc (angle 11 i) (angle 11 (i+1))) (hr : 0 ≤ r) 130 (hl : (rl:ℝ)/q ≤ r) (hh : r ≤ (rh:ℝ)/q) : 131 transverseTrial r t ≤ (transverseCap (angleCell i) rl rh : ℝ)/q := by 132 let c := angleCell i 133 obtain ⟨cl,ch,sl,sh⟩ := grid_enclosure hi ht 134 let xl := loMul c.cosLo rl rh 135 let xh := hiMul c.cosHi rl rh 136 have b1 := (mul_bounds c.cosLo rl rh hl hh).1.trans (mul_le_mul_of_nonneg_right cl hr) 137 have b2 := (mul_le_mul_of_nonneg_right ch hr).trans (mul_bounds c.cosHi rl rh hl hh).2 138 have p1 := (mul_bounds xl c.sinLo c.sinHi sl sh).1.trans (mul_le_mul_of_nonneg_right b1 (sq_nonneg (Real.sin t))) 139 have p2 := (mul_le_mul_of_nonneg_right b2 (sq_nonneg (Real.sin t))).trans (mul_bounds xh c.sinLo c.sinHi sl sh).2 140 let a := max (-c.cosLo) c.cosHi 141 have ah : |Real.cos t| ≤ a/(q:ℝ) := by 142 dsimp [a]; push_cast; rw [abs_le]; constructor 143 · have h := le_max_left (-(c.cosLo:ℝ)) c.cosHi 144 change (c.cosLo:ℝ)/q ≤ _ at cl 145 norm_num [q] at cl ⊢; linarith 146 · have h := le_max_right (-(c.cosLo:ℝ)) c.cosHi 147 change _ ≤ (c.cosHi:ℝ)/q at ch 148 norm_num [q] at ch ⊢; linarith 149 let v := (1/3:ℝ)-r*Real.cos t*Real.sin t^2/6 150 let dl := (2*q-hiMul xh c.sinLo c.sinHi)/6 151 let dh := ceilDiv (2*q-loMul xl c.sinLo c.sinHi) 6 152 let d := max (-dl) dh 153 have low := floor_mul_bound (2*q-hiMul xh c.sinLo c.sinHi) (show (0:ℤ)<6 by decide) 154 have high := ceil_mul_bound (2*q-loMul xl c.sinLo c.sinHi) (show (0:ℤ)<6 by decide) 155 change (dl:ℝ)*6 ≤ _ at low 156 change _ ≤ (dh:ℝ)*6 at high 157 push_cast at low high 158 have dv : |v| ≤ d/(q:ℝ) := by 159 have m1 := le_max_left (-dl) dh 160 have m2 := le_max_right (-dl) dh 161 change -dl ≤ d at m1 162 change dh ≤ d at m2 163 have m1' : -(dl:ℝ) ≤ d := by exact_mod_cast m1 164 have m2' : (dh:ℝ) ≤ d := by exact_mod_cast m2 165 rw [abs_le]; dsimp [v]; norm_num [q] at low high p1 p2 ⊢ 166 constructor <;> linarith 167 have s1 := rounded_square a _ ah 168 have s2 := rounded_square d _ dv 169 have t1 := ceil_mul_bound (ceilDiv (a*a) q) (show (0:ℤ)<27 by decide) 170 have t2 := ceil_mul_bound (2*ceilDiv (d*d) q) (show (0:ℤ)<3 by decide) 171 push_cast at t1 t2 172 change Real.cos t^2/27 + (2/3:ℝ)*v^2 ≤ 173 ((ceilDiv (ceilDiv (a*a) q) 27 + ceilDiv (2*ceilDiv (d*d) q) 3 : ℤ) : ℝ)/q 174 push_cast 175 norm_num only [q, Int.cast_ofNat] at s1 s2 t1 t2 ⊢ 176 linarith 177 178 /-- A signed integrand enclosed on every cell can be integrated using the endpoint sums. -/ 179 theorem integral_enclosure {n : ℕ} {edges lo hi : ℕ → ℝ} {f : ℝ → ℝ} 180 (order : ∀ i < n, edges i ≤ edges (i+1)) 181 (integrable : ∀ i < n, IntervalIntegrable f volume (edges i) (edges (i+1))) 182 (boxes : ∀ i < n, ∀ t ∈ Icc (edges i) (edges (i+1)), lo i ≤ f t ∧ f t ≤ hi i) : 183 (∑ i ∈ Finset.range n, (edges (i+1)-edges i)*lo i) ≤ ∫ t in edges 0..edges n, f t ∧ 184 (∫ t in edges 0..edges n, f t) ≤ ∑ i ∈ Finset.range n, (edges (i+1)-edges i)*hi i := by 185 rw [← intervalIntegral.sum_integral_adjacent_intervals integrable] 186 constructor 187 · apply Finset.sum_le_sum 188 intro i hi 189 have h := intervalIntegral.integral_mono_on (order i (Finset.mem_range.mp hi)) 190 (intervalIntegrable_const (c := lo i)) (integrable i (Finset.mem_range.mp hi)) 191 (fun t ht => (boxes i (Finset.mem_range.mp hi) t ht).1) 192 simpa using h 193 · apply Finset.sum_le_sum 194 intro i hi 195 have h := intervalIntegral.integral_mono_on (order i (Finset.mem_range.mp hi)) 196 (integrable i (Finset.mem_range.mp hi)) (intervalIntegrable_const (c := _)) 197 (fun t ht => (boxes i (Finset.mem_range.mp hi) t ht).2) 198 simpa using h 199 200 /-- Increments of two increasing functions need opposite endpoints when subtracted. -/ 201 theorem signed_cell {f g : ℝ → ℝ} {a b t : ℝ} 202 (hf : MonotoneOn f (Icc a b)) (hg : MonotoneOn g (Icc a b)) (ht : t ∈ Icc a b) : 203 f a - g b ≤ f t - g t ∧ f t - g t ≤ f b - g a := by 204 have hab := ht.1.trans ht.2 205 have ha := left_mem_Icc.mpr hab 206 have hb := right_mem_Icc.mpr hab 207 exact ⟨sub_le_sub (hf ha ht ht.1) (hg ht hb ht.2), sub_le_sub (hf ht hb ht.2) (hg ha ht ht.1)⟩ 208 209 def momentLo (c : Cell) (rl rh : ℤ) := loMul c.cosLo (weightLo c rl rh) (weightHi c rl rh) 210 def momentHi (c : Cell) (rl rh : ℤ) := hiMul c.cosHi (weightLo c rl rh) (weightHi c rl rh) 211 212 theorem moment_sound {i : ℕ} (hi : i < 2048) {r t : ℝ} {rl rh : ℤ} 213 (ht : t ∈ Icc (angle 11 i) (angle 11 (i+1))) (hr : 0 ≤ r) 214 (hl : (rl:ℝ)/q ≤ r) (hh : r ≤ (rh:ℝ)/q) 215 (el : -(2*q) ≤ loMul (angleCell i).cosLo rl rh) 216 (eh : hiMul (angleCell i).cosHi rl rh ≤ 2*q) : 217 (momentLo (angleCell i) rl rh:ℝ)/q ≤ Real.cos t * polarWeight r t ∧ 218 Real.cos t * polarWeight r t ≤ (momentHi (angleCell i) rl rh:ℝ)/q := by 219 obtain ⟨wl,wh⟩ := weight_sound hi ht hr hl hh el eh 220 obtain ⟨cl,ch,_,_⟩ := grid_enclosure hi ht 221 have hw : 0 ≤ polarWeight r t := by unfold polarWeight; positivity 222 exact ⟨(mul_bounds _ _ _ wl wh).1.trans (mul_le_mul_of_nonneg_right cl hw), 223 (mul_le_mul_of_nonneg_right ch hw).trans (mul_bounds _ _ _ wl wh).2⟩ 224 225 private theorem cos_range (n i : ℕ) : 226 -scale ≤ (cosBounds n i).1 ∧ (cosBounds n i).2 ≤ scale := by 227 cases n with 228 | zero => simp only [cosBounds]; split <;> norm_num [scale] 229 | succ n => 230 simp only [cosBounds] 231 split <;> try norm_num [scale] 232 split <;> try norm_num [scale] 233 split <;> try norm_num [scale] 234 split <;> simp [half, reflect, scale] 235 236 private theorem angle_range (i : ℕ) : -q ≤ (angleCell i).cosLo ∧ (angleCell i).cosHi ≤ q := by 237 have a := (cos_range 11 (i+1)).1 238 have b := (cos_range 11 i).2 239 dsimp [angleCell, ceilDiv, scale, q] at * 240 omega 241 242 theorem exponent_range (i : ℕ) {rl rh : ℤ} (h0 : 0 ≤ rl) (h1 : rl ≤ rh) (h2 : rh ≤ 2*q) : 243 -(2*q) ≤ loMul (angleCell i).cosLo rl rh ∧ hiMul (angleCell i).cosHi rl rh ≤ 2*q := by 244 obtain ⟨hl,hh⟩ := angle_range i 245 have aux (y : ℤ) (hy : 0 ≤ y) (h : y ≤ 2*q) : 246 -(2*q)*q ≤ (angleCell i).cosLo*y ∧ (angleCell i).cosHi*y ≤ (2*q)*q := by 247 have a := mul_le_mul_of_nonneg_right hl hy 248 have b := mul_le_mul_of_nonneg_right hh hy 249 dsimp [q] at *; constructor <;> linarith 250 have a := aux rl h0 (h1.trans h2) 251 have b := aux rh (h0.trans h1) h2 252 constructor 253 · exact (Int.le_ediv_iff_mul_le (show 0 < q by decide)).2 (le_min a.1 b.1) 254 · have hm := max_le a.2 b.2 255 unfold hiMul ceilDiv 256 apply neg_le_of_neg_le 257 apply (Int.le_ediv_iff_mul_le (show 0 < q by decide)).2 258 linarith 259 260 /-- The density and its signed cosine moment are the two integral inputs to the polar flux. -/ 261 theorem partition_and_moment {r : ℝ} {rl rh : ℤ} (hr : 0 ≤ r) 262 (hl : (rl:ℝ)/q ≤ r) (hh : r ≤ (rh:ℝ)/q) 263 (h0 : 0 ≤ rl) (h1 : rl ≤ rh) (h2 : rh ≤ 2*q) : 264 let bounded := fun (f : ℝ → ℝ) (l h : Cell → ℤ → ℤ → ℤ) => 265 (∑ i ∈ Finset.range 2048, (Real.pi/2048) * (l (angleCell i) rl rh / (q:ℝ))) ≤ (∫ t in 0..Real.pi, f t) ∧ 266 (∫ t in 0..Real.pi, f t) ≤ ∑ i ∈ Finset.range 2048, (Real.pi/2048) * (h (angleCell i) rl rh / (q:ℝ)) 267 bounded (polarWeight r) weightLo weightHi ∧ 268 bounded (fun t => Real.cos t * polarWeight r t) momentLo momentHi := by 269 have step (i : ℕ) : angle 11 (i+1) - angle 11 i = Real.pi/2048 := by 270 simp only [angle, Nat.cast_add, Nat.cast_one]; ring 271 have order (i : ℕ) (_ : i < 2048) : angle 11 i ≤ angle 11 (i+1) := by 272 linarith [step i, Real.pi_pos] 273 have ends : angle 11 0 = 0 ∧ angle 11 2048 = Real.pi := by norm_num [angle] 274 have con : Continuous (polarWeight r) := by unfold polarWeight; fun_prop 275 have first := integral_enclosure order (fun i _ => con.intervalIntegrable _ _) 276 (fun i hi t ht => weight_sound hi ht hr hl hh (exponent_range i h0 h1 h2).1 (exponent_range i h0 h1 h2).2) 277 have second := integral_enclosure order (fun i _ => (Real.continuous_cos.mul con).intervalIntegrable _ _) 278 (fun i hi t ht => moment_sound hi ht hr hl hh (exponent_range i h0 h1 h2).1 (exponent_range i h0 h1 h2).2) 279 simpa only [step, ends.1, ends.2, Pi.mul_apply] using And.intro first second 280 281 def weightedCap (c : Cell) (rl rh : ℤ) := 282 ceilDiv (transverseCap c rl rh * weightHi c rl rh) q 283 284 def averageLo (l : Cell → ℤ → ℤ → ℤ) (rl rh : ℤ) : ℤ := 285 (∑ i ∈ Finset.range 2048, l (angleCell i) rl rh) / 2048 286 287 def averageHi (h : Cell → ℤ → ℤ → ℤ) (rl rh : ℤ) : ℤ := 288 ceilDiv (∑ i ∈ Finset.range 2048, h (angleCell i) rl rh) 2048 289 290 theorem average_bounds {f : ℝ → ℝ} {l h : Cell → ℤ → ℤ → ℤ} {rl rh : ℤ} 291 (bounds : (∑ i ∈ Finset.range 2048, (Real.pi/2048)*(l (angleCell i) rl rh/(q:ℝ))) ≤ (∫ t in 0..Real.pi, f t) ∧ 292 (∫ t in 0..Real.pi, f t) ≤ ∑ i ∈ Finset.range 2048, (Real.pi/2048)*(h (angleCell i) rl rh/(q:ℝ))) : 293 (Real.pi/(q:ℝ)) * averageLo l rl rh ≤ (∫ t in 0..Real.pi, f t) ∧ 294 (∫ t in 0..Real.pi, f t) ≤ (Real.pi/(q:ℝ)) * averageHi h rl rh := by 295 have dl := floor_mul_bound (∑ i ∈ Finset.range 2048, l (angleCell i) rl rh) (show (0:ℤ)<2048 by decide) 296 have uh := ceil_mul_bound (∑ i ∈ Finset.range 2048, h (angleCell i) rl rh) (show (0:ℤ)<2048 by decide) 297 change (averageLo l rl rh : ℝ)*2048 ≤ _ at dl 298 change _ ≤ (averageHi h rl rh : ℝ)*2048 at uh 299 push_cast at dl uh 300 have sum_scale (a : ℕ → ℤ) : 301 (∑ i ∈ Finset.range 2048, (Real.pi/2048)*((a i:ℝ)/q)) = 302 (Real.pi/(2048*q)) * ∑ i ∈ Finset.range 2048, (a i:ℝ) := by 303 rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intros; ring 304 have factor : 0 ≤ Real.pi/(2048*q) := by norm_num [q]; positivity 305 have rescale (x : ℝ) : (Real.pi/(2048*q))*(x*2048) = (Real.pi/(q:ℝ))*x := by norm_num [q]; ring 306 rw [sum_scale, sum_scale] at bounds 307 constructor 308 · rw [← rescale]; exact (mul_le_mul_of_nonneg_left dl factor).trans bounds.1 309 · rw [← rescale]; exact bounds.2.trans (mul_le_mul_of_nonneg_left uh factor) 310 311 private theorem sine_lower_nonneg (i : ℕ) : 0 ≤ (angleCell i).sinLo := by 312 unfold angleCell sinSqBounds 313 dsimp 314 exact Int.ediv_nonneg (Int.ediv_nonneg (sq_nonneg _) (by decide)) (by decide) 315 316 set_option maxRecDepth 15000 in 317 set_option maxHeartbeats `2000000` in 318 private theorem interior_sines : 319 (List.range 2046).all (fun j => decide (8 ≤ (angleCell (j+1)).sinLo)) = true := by 320 decide +kernel 321 322 /-- Positive integer lower density on every non-pole cell across the full field range. -/ 323 theorem interior_weight_pos {i : ℕ} (hi : i < 2048) (left : i ≠ 0) (right : i ≠ 2047) 324 {rl rh : ℤ} (h0 : 0 ≤ rl) (h1 : rl ≤ rh) (h2 : rh ≤ 2*q) : 325 0 < weightLo (angleCell i) rl rh := by 326 have hj : i-1 ∈ List.range 2046 := List.mem_range.mpr (by omega) 327 have sine := of_decide_eq_true (List.all_eq_true.mp interior_sines (i-1) hj) 328 rw [show i-1+1=i by omega] at sine 329 have exponential := expLo_floor (exponent_range i h0 h1 h2).1 330 have prod := mul_le_mul sine exponential (show 0 ≤ q/8 by decide) (by omega) 331 have base : (8:ℤ)*(q/8) = q := by decide 332 rw [base] at prod 333 unfold weightLo 334 norm_num [q] at prod ⊢ 335 omega 336 337 set_option maxRecDepth 12000 in 338 /-- The middle cell alone makes the integer lower normalizer positive. -/ 339 theorem normalizer_lower_pos {rl rh : ℤ} (h0 : 0 ≤ rl) (h1 : rl ≤ rh) (h2 : rh ≤ 2*q) : 340 0 < averageLo weightLo rl rh := by 341 have nonneg (i : ℕ) : 0 ≤ weightLo (angleCell i) rl rh := 342 Int.ediv_nonneg (mul_nonneg (sine_lower_nonneg i) (expLo_pos (exponent_range i h0 h1 h2).1).le) (by decide) 343 have central : (angleCell 1023).cosLo = 0 := by decide 344 have fixed (n : ℕ) : squareDown n q = q := by 345 induction n with 346 | zero => rfl 347 | succ n ih => rw [squareDown, ih]; decide 348 have zero : expLo 0 = q := by simpa [expLo] using fixed 12 349 have enough : 2048 ≤ (angleCell 1023).sinLo * expLo 0 / q := by 350 rw [zero]; norm_num [q] 351 decide +kernel 352 have wl : 2048 ≤ weightLo (angleCell 1023) rl rh := by 353 simpa [weightLo, loMul, central] using enough 354 have sum := Finset.single_le_sum (f := fun i => weightLo (angleCell i) rl rh) 355 (fun i _ => nonneg i) (Finset.mem_range.mpr (show 1023 < 2048 by decide)) 356 have lower := wl.trans sum 357 unfold averageLo 358 omega 359 360 /-- The exact integer used for the normalized transverse replay row bounds the 361 continuous normalized trial energy. The middle angular cell supplies a positive denominator. -/ 362 theorem normalized_transverse {r : ℝ} {rl rh : ℤ} (hr : 0 ≤ r) 363 (hl : (rl:ℝ)/q ≤ r) (hh : r ≤ (rh:ℝ)/q) (h0 : 0 ≤ rl) (h1 : rl ≤ rh) (h2 : rh ≤ 2*q) : 364 (∫ t in 0..Real.pi, polarWeight r t * transverseTrial r t) / 365 (∫ t in 0..Real.pi, polarWeight r t) ≤ 366 (ceilDiv (averageHi weightedCap rl rh * q) (averageLo weightLo rl rh) : ℝ)/q := by 367 have hz := normalizer_lower_pos h0 h1 h2 368 have step (i : ℕ) : angle 11 (i+1) - angle 11 i = Real.pi/2048 := by 369 simp only [angle, Nat.cast_add, Nat.cast_one]; ring 370 have order (i : ℕ) (_ : i < 2048) : angle 11 i ≤ angle 11 (i+1) := by 371 linarith [step i, Real.pi_pos] 372 have con : Continuous (fun t => polarWeight r t * transverseTrial r t) := by 373 unfold polarWeight transverseTrial; fun_prop 374 have boxes (i : ℕ) (hi : i < 2048) (t : ℝ) (ht : t ∈ Icc (angle 11 i) (angle 11 (i+1))) : 375 0 ≤ polarWeight r t * transverseTrial r t ∧ 376 polarWeight r t * transverseTrial r t ≤ (weightedCap (angleCell i) rl rh:ℝ)/q := by 377 have w := (weight_sound hi ht hr hl hh (exponent_range i h0 h1 h2).1 (exponent_range i h0 h1 h2).2).2 378 have v := transverse_cost_sound hi ht hr hl hh 379 have v0 : 0 ≤ transverseTrial r t := by unfold transverseTrial; positivity 380 have w0 : 0 ≤ polarWeight r t := by unfold polarWeight; positivity 381 have m := mul_le_mul v w w0 (v0.trans v) 382 have u := ceil_mul_bound (transverseCap (angleCell i) rl rh * weightHi (angleCell i) rl rh) (show 0 < q by decide) 383 change _ ≤ (weightedCap (angleCell i) rl rh:ℝ)*q at u 384 push_cast at u 385 refine ⟨mul_nonneg w0 v0, ?_⟩ 386 rw [mul_comm] 387 norm_num [q] at u m ⊢; linarith 388 have ends : angle 11 0 = 0 ∧ angle 11 2048 = Real.pi := by norm_num [angle] 389 have cap := (integral_enclosure order (fun i _ => con.intervalIntegrable _ _) boxes).2 390 simp only [step, ends.1, ends.2] at cap 391 have lower := (partition_and_moment hr hl hh h0 h1 h2).1.1 392 let N := ∫ t in 0..Real.pi, polarWeight r t * transverseTrial r t 393 let Z := ∫ t in 0..Real.pi, polarWeight r t 394 let L := averageLo weightLo rl rh 395 let H := averageHi weightedCap rl rh 396 have l := floor_mul_bound (∑ i ∈ Finset.range 2048, weightLo (angleCell i) rl rh) (show (0:ℤ)<2048 by decide) 397 have u := ceil_mul_bound (∑ i ∈ Finset.range 2048, weightedCap (angleCell i) rl rh) (show (0:ℤ)<2048 by decide) 398 change (L:ℝ)*2048 ≤ _ at l 399 change _ ≤ (H:ℝ)*2048 at u 400 push_cast at l u 401 have scale_sum (f : ℕ → ℤ) : 402 (∑ i ∈ Finset.range 2048, (Real.pi/2048)*((f i:ℝ)/q)) = 403 (Real.pi/(2048*q)) * ∑ i ∈ Finset.range 2048, (f i:ℝ) := by 404 rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intros; ring 405 rw [scale_sum] at cap lower 406 have factor : 0 ≤ Real.pi/(2048*q) := by norm_num [q]; positivity 407 have l' := (mul_le_mul_of_nonneg_left l factor).trans lower 408 have u' := cap.trans (mul_le_mul_of_nonneg_left u factor) 409 have p : 0 < Real.pi/(q:ℝ) := by norm_num [q]; positivity 410 have Lpos : (0:ℝ) < L := by exact_mod_cast hz 411 have rescale (x : ℝ) : (Real.pi/(2048*q))*(x*2048) = (Real.pi/(q:ℝ))*x := by norm_num [q]; ring 412 have zl : (Real.pi/(q:ℝ))*L ≤ Z := by rw [← rescale]; exact l' 413 have nu : N ≤ (Real.pi/(q:ℝ))*H := by rw [← rescale]; exact u' 414 have npos : 0 ≤ N := intervalIntegral.integral_nonneg Real.pi_pos.le (fun t _ => weighted_trial_nonneg r t) 415 have nh : 0 ≤ (H:ℝ) := nonneg_of_mul_nonneg_right (npos.trans nu) p 416 have rat : N/Z ≤ (H:ℝ)/L := by 417 apply (div_le_div_iff₀ ((mul_pos p Lpos).trans_le zl) Lpos).2 418 calc N*(L:ℝ) ≤ ((Real.pi/(q:ℝ))*H)*L := mul_le_mul_of_nonneg_right nu Lpos.le 419 _ = H*((Real.pi/(q:ℝ))*L) := by ring 420 _ ≤ H*Z := mul_le_mul_of_nonneg_left zl nh 421 have final := ceil_mul_bound (H*q) hz 422 push_cast at final 423 apply rat.trans 424 apply (div_le_div_iff₀ Lpos (show (0:ℝ)