interplane.Get Omega
Read in your language

yang

This project has not described itself yet.

Brought by drakestapleton

branch main Branches Tags History

yang / proofs / DyadicPolarFlux.lean

526 lines · 29315 bytes Raw Blame History
1import DyadicPartition
2import OneLinkTransport
3import Mathlib.Analysis.SpecialFunctions.Trigonometric.Bounds
4
5open MeasureTheory Set Real
6open YangMills.DyadicPartition YangMills.DyadicExp YangMills.DyadicTrig
7open YangMills.OneLinkTransport
8
9namespace YangMills.DyadicPolarFlux
10noncomputable section
11
12private theorem norm_pos (r : ℝ) : 0 < ∫ t in 0..π, weight r t := by
13 apply intervalIntegral.integral_pos pi_pos
14 · unfold weight; fun_prop
15 · intro t _; unfold weight; positivity
16 · refine ⟨π/2, ⟨by positivity, by linarith [pi_pos]⟩, ?_⟩
17 simp [weight]
18
19theorem mean_range (r : ℝ) : |meanCos r| ≤ 1 := by
20 have w : Continuous (weight r) := by unfold weight; fun_prop
21 have a : Continuous (fun t => weight r t * cos t) := w.mul continuous_cos
22 have pos (t : ℝ) : 0 ≤ weight r t := by unfold weight; positivity
23 have hi := intervalIntegral.integral_mono_on (μ := volume) pi_pos.le (a.intervalIntegrable _ _)
24 (w.intervalIntegrable _ _) (fun t _ => mul_le_of_le_one_right (pos t) (cos_le_one t))
25 have lo := intervalIntegral.integral_mono_on (μ := volume) pi_pos.le (w.neg.intervalIntegrable _ _)
26 (a.intervalIntegrable _ _) (fun t _ => show -weight r t ≤ weight r t*cos t by
27 linarith [mul_le_mul_of_nonneg_left (neg_one_le_cos t) (pos t)])
28 simp only [Pi.neg_apply, intervalIntegral.integral_neg] at lo
29 rw [abs_le, meanCos, le_div_iff₀ (norm_pos r), div_le_iff₀ (norm_pos r)]
30 constructor <;> linarith
31
32private theorem end_zero (r : ℝ) : polarFlux r π = 0 := by
33 have hw : Continuous (weight r) := by unfold weight; fun_prop
34 simp only [polarFlux, mul_sub]
35 have ha : Continuous (fun x => weight r x * cos x) := hw.mul continuous_cos
36 have hb : Continuous (fun x => weight r x * meanCos r) := hw.mul continuous_const
37 rw [intervalIntegral.integral_sub (ha.intervalIntegrable _ _) (hb.intervalIntegrable _ _),
38 intervalIntegral.integral_mul_const]
39 unfold meanCos
40 field_simp [(norm_pos r).ne']
41 simp
42
43private theorem cap_exp {v : ℝ} (hv : v ≤ 1/2) : exp v ≤ 2 := by
44 have h : exp v ^ 2 ≤ exp 1 := by rw [← exp_nat_mul]; apply exp_le_exp.mpr; norm_num; linarith
45 nlinarith [exp_one_lt_d9, exp_pos v]
46
47private theorem density_toward_pole {r u t : ℝ} (hr : |r| ≤ 2)
48 (hu : u ∈ Icc 0 t) (ht : t ≤ π/2048) : weight r u ≤ 2*weight r t := by
49 have ht0 := hu.1.trans hu.2
50 have h2 : t ≤ π/2 := by linarith [pi_pos]
51 have su := sin_nonneg_of_nonneg_of_le_pi hu.1 (by linarith [hu.2, pi_pos] : u ≤ π)
52 have sm := sin_le_sin_of_le_of_le_pi_div_two (by linarith [hu.1,pi_pos]) h2 hu.2
53 have sq := pow_le_pow_left₀ su sm 2
54 have hdist := abs_cos_sub_cos_le u t
55 rw [abs_of_nonpos (sub_nonpos.mpr hu.2)] at hdist
56 have absBound := mul_le_mul hr hdist (abs_nonneg _) (by norm_num : (0:ℝ)≤2)
57 rw [← abs_mul] at absBound
58 have ex := cap_exp (show r*(cos u-cos t) ≤ 1/2 by
59 linarith [(le_abs_self _).trans absBound, hu.1, Real.pi_lt_four])
60 have e : exp (r*cos u) ≤ 2*exp (r*cos t) := by
61 rw [show r*cos u = r*(cos u-cos t)+r*cos t by ring, exp_add]
62 exact mul_le_mul_of_nonneg_right ex (exp_pos _).le
63 unfold weight
64 calc _ ≤ sin t^2*(2*exp (r*cos t)) := mul_le_mul sq e (exp_pos _).le (sq_nonneg _)
65 _ = _ := by ring
66
67/-- The inward flux divided by the density is uniformly bounded on a pole cell,
68including its zero-density endpoint in the real-division convention. -/
69private theorem near_zero {r m t : ℝ} (hr : |r| ≤ 2) (hm : |m| ≤ 1)
70 (ht : t ∈ Icc 0 (π/2048)) :
71 (∫ u in 0..t, weight r u*(cos u-m))^2 / weight r t ≤
72 16*(π/2048)^2 * weight r t := by
73 let f := fun u => weight r u*(cos u-m)
74 have c : Continuous f := by unfold f weight; fun_prop
75 have w : 0 ≤ weight r t := by unfold weight; positivity
76 have cap (u : ℝ) (h : u ∈ Icc 0 t) : |f u| ≤ 4*weight r t := by
77 have wu : 0 ≤ weight r u := by unfold weight; positivity
78 have delta : |cos u-m| ≤ 2 := (abs_sub _ _).trans (by linarith [abs_cos_le_one u])
79 simp only [f, abs_mul, abs_of_nonneg wu]
80 nlinarith [mul_le_mul (density_toward_pole hr h ht.2) delta (abs_nonneg _) (mul_nonneg (by norm_num) w)]
81 have absint := intervalIntegral.abs_integral_le_integral_abs (μ := volume) (f := f) ht.1
82 have mono := intervalIntegral.integral_mono_on (μ := volume) ht.1 (c.abs.intervalIntegrable _ _)
83 (intervalIntegrable_const (c := 4*weight r t)) cap
84 simp only [intervalIntegral.integral_const, sub_zero, smul_eq_mul] at mono
85 have b := absint.trans (mono.trans (mul_le_mul_of_nonneg_right ht.2 (by positivity)))
86 have square := pow_le_pow_left₀ (abs_nonneg _) b 2
87 rw [sq_abs] at square
88 rcases w.eq_or_lt with zero | positive
89 · simp [← zero]
90 · apply (div_le_iff₀ positive).2
91 convert square using 1; ring
92
93/-- Centering cancels the complete flux, so the last cell can be integrated from π inward. -/
94private theorem reflected_flux (r t : ℝ) :
95 polarFlux r (π-t) = ∫ u in 0..t, weight (-r) u*(cos u - (-meanCos r)) := by
96 let f := fun u => weight r u*(cos u-meanCos r)
97 have c : Continuous f := by unfold f weight; fun_prop
98 have add := intervalIntegral.integral_add_adjacent_intervals (μ := volume) (c.intervalIntegrable 0 (π-t))
99 (c.intervalIntegrable (π-t) π)
100 have zero : (∫ u in 0..π, f u) = 0 := end_zero r
101 rw [zero] at add
102 have sub := intervalIntegral.integral_comp_sub_left (f := f) (a := 0) (b := t) π
103 rw [sub_zero] at sub
104 have form : (fun u => f (π-u)) = fun u => -(weight (-r) u*(cos u-(-meanCos r))) := by
105 funext u; simp [f,weight,Real.cos_pi_sub,Real.sin_pi_sub]; ring
106 rw [form, intervalIntegral.integral_neg] at sub
107 change (∫ u in 0..(π-t), f u) = _
108 linarith
109
110theorem two_pole_cells {r t : ℝ} (hr : |r| ≤ 2) (ht : t ∈ Icc 0 (π/2048)) :
111 polarFlux r t ^ 2 / weight r t ≤ 16*(π/2048)^2 * weight r t ∧
112 polarFlux r (π-t) ^ 2 / weight r (π-t) ≤ 16*(π/2048)^2 * weight r (π-t) := by
113 refine ⟨near_zero hr (mean_range r) ht, ?_⟩
114 rw [reflected_flux, show weight r (π-t) = weight (-r) t by simp [weight,Real.cos_pi_sub,Real.sin_pi_sub]]
115 apply near_zero (by simpa using hr) (by simpa using mean_range r) ht
116
117def poleCost (i : ℕ) (rl rh : ℤ) := ceilDiv (16 * weightHi (angleCell i) rl rh) 4194304
118
119/-- The actual rounded end-cell branch of the inward energy replay bounds F²/p. -/
120theorem end_cell_cost {i : ℕ} (edge : i = 0 ∨ i = 2047) {r t : ℝ} {rl rh : ℤ}
121 (ht : t ∈ Icc (angle 11 i) (angle 11 (i+1))) (hr : 0 ≤ r)
122 (hl : (rl:ℝ)/q ≤ r) (hh : r ≤ (rh:ℝ)/q)
123 (h0 : 0 ≤ rl) (h1 : rl ≤ rh) (h2 : rh ≤ 2*q) :
124 polarFlux r t ^ 2 / weight r t ≤ π^2 * ((poleCost i rl rh : ℝ)/q) := by
125 have hi : i < 2048 := by rcases edge with e|e <;> omega
126 have hR : |r| ≤ 2 := by
127 rw [abs_of_nonneg hr]
128 have v : (rh:ℝ) ≤ 2*q := by exact_mod_cast h2
129 norm_num [q] at hh v ⊢; linarith
130 have pol : polarFlux r t^2/weight r t ≤ 16*(π/2048)^2*weight r t := by
131 rcases edge with e|e
132 · subst i
133 exact (two_pole_cells hR (by norm_num [angle, Set.mem_Icc] at ht ⊢; exact ht)).1
134 · subst i
135 have z : π-t ∈ Icc 0 (π/2048) := by
136 obtain ⟨a,b⟩ := ht
137 norm_num [angle] at a b; constructor <;> linarith
138 simpa using (two_pole_cells hR z).2
139 have w : weight r t ≤ (weightHi (angleCell i) rl rh:ℝ)/q :=
140 (weight_sound hi ht hr hl hh (exponent_range i h0 h1 h2).1 (exponent_range i h0 h1 h2).2).2
141 have u := Int.ediv_mul_le (-(16*weightHi (angleCell i) rl rh)) (show (4194304:ℤ) ≠ 0 by decide)
142 have v : (16:ℝ)*weightHi (angleCell i) rl rh ≤ (poleCost i rl rh:ℝ)*4194304 := by
143 unfold poleCost ceilDiv
144 exact_mod_cast (show 16*weightHi (angleCell i) rl rh ≤ -((-(16*weightHi (angleCell i) rl rh))/4194304)*4194304 by omega)
145 have f : 16*((π:ℝ)/2048)^2*((weightHi (angleCell i) rl rh:ℝ)/q) ≤ π^2*((poleCost i rl rh:ℝ)/q) := by
146 have t' := mul_le_mul_of_nonneg_left v (sq_nonneg π)
147 norm_num [q] at *; linarith
148 exact pol.trans ((mul_le_mul_of_nonneg_left w (by positivity)).trans f)
149
150def ratioLo (x zl zh : ℤ) := min (x*q/zl) (x*q/zh)
151def ratioHi (x zl zh : ℤ) := max (ceilDiv (x*q) zl) (ceilDiv (x*q) zh)
152
153private theorem ratio_bounds (x zl zh : ℤ) {v : ℝ} (lz : 0 < zl) (lh : (zl:ℝ) ≤ v) (hh : v ≤ (zh:ℝ)) :
154 (ratioLo x zl zh:ℝ)/q ≤ (x:ℝ)/v ∧ (x:ℝ)/v ≤ (ratioHi x zl zh:ℝ)/q := by
155 have vl : 0 < (zl:ℝ) := by exact_mod_cast lz
156 have vp := vl.trans_le lh
157 have vh := vp.trans_le hh
158 have hz : 0 < zh := by exact_mod_cast vh
159 have qpos : (0:ℝ) < q := by norm_num [q]
160 have bottom (k : ℤ) (hk : 0 < k) : ((x*q/k : ℤ):ℝ)/q ≤ (x:ℝ)/k := by
161 apply (div_le_div_iff₀ qpos (by exact_mod_cast hk)).2
162 exact_mod_cast Int.ediv_mul_le (x*q) hk.ne'
163 have top (k : ℤ) (hk : 0 < k) : (x:ℝ)/k ≤ (ceilDiv (x*q) k:ℝ)/q := by
164 apply (div_le_div_iff₀ (by exact_mod_cast hk) qpos).2
165 exact_mod_cast (ceil_mul_bound (x*q) hk)
166 have lo1 : (ratioLo x zl zh:ℝ)/q ≤ (x:ℝ)/zl :=
167 (div_le_div_of_nonneg_right (by exact_mod_cast min_le_left _ _) qpos.le).trans (bottom _ lz)
168 have lo2 : (ratioLo x zl zh:ℝ)/q ≤ (x:ℝ)/zh :=
169 (div_le_div_of_nonneg_right (by exact_mod_cast min_le_right _ _) qpos.le).trans (bottom _ hz)
170 have hi1 : (x:ℝ)/zl ≤ (ratioHi x zl zh:ℝ)/q :=
171 (top _ lz).trans (div_le_div_of_nonneg_right (by exact_mod_cast le_max_left _ _) qpos.le)
172 have hi2 : (x:ℝ)/zh ≤ (ratioHi x zl zh:ℝ)/q :=
173 (top _ hz).trans (div_le_div_of_nonneg_right (by exact_mod_cast le_max_right _ _) qpos.le)
174 by_cases hx : 0 ≤ (x:ℝ)
175 · exact ⟨lo2.trans (div_le_div_of_nonneg_left hx vp hh), (div_le_div_of_nonneg_left hx vl lh).trans hi1⟩
176 · refine ⟨lo1.trans ((div_le_div_iff₀ vl vp).2 (mul_le_mul_of_nonpos_left lh (le_of_not_ge hx))),
177 ((div_le_div_iff₀ vp vh).2 (mul_le_mul_of_nonpos_left hh (le_of_not_ge hx))).trans hi2⟩
178
179def meanLo (rl rh : ℤ) := ratioLo (averageLo momentLo rl rh) (averageLo weightLo rl rh) (averageHi weightHi rl rh)
180def meanHi (rl rh : ℤ) := ratioHi (averageHi momentHi rl rh) (averageLo weightLo rl rh) (averageHi weightHi rl rh)
181
182/-- Both signs of the rounded numerator are retained when normalizing the polar flux. -/
183theorem centered_mean_sound {r : ℝ} {rl rh : ℤ} (hr : 0 ≤ r)
184 (hl : (rl:ℝ)/q ≤ r) (hh : r ≤ (rh:ℝ)/q) (h0 : 0 ≤ rl) (h1 : rl ≤ rh) (h2 : rh ≤ 2*q) :
185 (meanLo rl rh : ℝ)/q ≤ meanCos r ∧ meanCos r ≤ (meanHi rl rh : ℝ)/q := by
186 obtain ⟨z,m⟩ := partition_and_moment hr hl hh h0 h1 h2
187 obtain ⟨zl,zh⟩ := average_bounds z
188 obtain ⟨ml,mh⟩ := average_bounds m
189 let c := π/(q:ℝ)
190 have cp : 0 < c := by dsimp [c,q]; positivity
191 let Z := (∫ t in 0..π, polarWeight r t)/c
192 let M := (∫ t in 0..π, cos t*polarWeight r t)/c
193 have a : (averageLo weightLo rl rh:ℝ) ≤ Z := (le_div_iff₀ cp).2 (by simpa [c,mul_comm] using zl)
194 have b : Z ≤ (averageHi weightHi rl rh:ℝ) := (div_le_iff₀ cp).2 (by simpa [c,mul_comm] using zh)
195 have v := normalizer_lower_pos h0 h1 h2
196 have zp : 0 < Z := lt_of_lt_of_le (by exact_mod_cast v) a
197 have e : (averageLo momentLo rl rh:ℝ) ≤ M := (le_div_iff₀ cp).2 (by simpa [c,mul_comm] using ml)
198 have f : M ≤ (averageHi momentHi rl rh:ℝ) := (div_le_iff₀ cp).2 (by simpa [c,mul_comm] using mh)
199 have ident : meanCos r = M/Z := by
200 unfold meanCos M Z; simp only [polarWeight,weight]; simp_rw [mul_comm (cos _)]
201 field_simp [cp.ne']
202 rw [ident]
203 exact ⟨(ratio_bounds _ _ _ v a b).1.trans (div_le_div_of_nonneg_right e zp.le),
204 (div_le_div_of_nonneg_right f zp.le).trans (ratio_bounds _ _ _ v a b).2⟩
205
206/-- Both halves are integrated in the inward coordinate s, beginning at a pole. -/
207def physical (back : Bool) (s : ℝ) := if back then π-s else s
208def index (back : Bool) (j : ℕ) := if back then 2047-j else j
209def source (back : Bool) (r s : ℝ) :=
210 let t := physical back s
211 (if back then meanCos r - cos t else cos t - meanCos r) * weight r t
212
213private theorem inward (back : Bool) (r s : ℝ) :
214 (∫ u in 0..s, source back r u) = polarFlux r (physical back s) := by
215 cases back with
216 | false => simp only [source,physical,Bool.false_eq_true,if_false,polarFlux]; apply intervalIntegral.integral_congr; intro t _; ring
217 | true =>
218 simp only [physical,if_true,reflected_flux]
219 apply intervalIntegral.integral_congr
220 intro t _; simp [source,physical,weight,cos_pi_sub,sin_pi_sub]; ring
221
222private theorem grid_physical (back : Bool) {j : ℕ} (hj : j < 1024) {t : ℝ}
223 (ht : t ∈ Icc (angle 11 j) (angle 11 (j+1))) :
224 physical back t ∈ Icc (angle 11 (index back j)) (angle 11 (index back j+1)) := by
225 cases back with
226 | false => exact ht
227 | true =>
228 obtain ⟨l,h⟩ := ht
229 simp only [physical,index,if_true]
230 have hsub : j ≤ 2047 := by omega
231 simp [angle, Nat.cast_sub hsub] at *
232 constructor <;> linarith
233
234def lowerSlope (back : Bool) (c : Cell) (ml mh wl wh : ℤ) :=
235 loMul (if back then ml-c.cosHi else c.cosLo-mh) wl wh
236def upperSlope (back : Bool) (c : Cell) (ml mh wl wh : ℤ) :=
237 hiMul (if back then mh-c.cosLo else c.cosHi-ml) wl wh
238
239def increment (lower back : Bool) (j : ℕ) (rl rh : ℤ) :=
240 let c := angleCell (index back j)
241 (if lower then lowerSlope else upperSlope) back c (meanLo rl rh) (meanHi rl rh) (weightLo c rl rh) (weightHi c rl rh)
242
243theorem slope_sound (back : Bool) {j : ℕ} (hj : j < 1024) {r t : ℝ} {rl rh : ℤ}
244 (ht : t ∈ Icc (angle 11 j) (angle 11 (j+1))) (hr : 0 ≤ r)
245 (hl : (rl:ℝ)/q ≤ r) (hh : r ≤ (rh:ℝ)/q) (h0 : 0 ≤ rl) (h1 : rl ≤ rh) (h2 : rh ≤ 2*q) :
246 (increment true back j rl rh:ℝ)/q ≤ source back r t ∧ source back r t ≤ (increment false back j rl rh:ℝ)/q := by
247 let i := index back j
248 have hi : i < 2048 := by cases back <;> simp [i,index] <;> omega
249 have ht' := grid_physical back hj ht
250 obtain ⟨cl,ch,_,_⟩ := grid_enclosure hi ht'
251 obtain ⟨ml,mh⟩ := centered_mean_sound hr hl hh h0 h1 h2
252 obtain ⟨wl,wh⟩ := weight_sound hi ht' hr hl hh (exponent_range i h0 h1 h2).1 (exponent_range i h0 h1 h2).2
253 let c := angleCell i
254 let l := if back then meanLo rl rh-c.cosHi else c.cosLo-meanHi rl rh
255 let h := if back then meanHi rl rh-c.cosLo else c.cosHi-meanLo rl rh
256 let delta := if back then meanCos r-cos (physical back t) else cos (physical back t)-meanCos r
257 have low : (l:ℝ)/q ≤ delta := by
258 change (c.cosLo:ℝ)/q ≤ _ at cl; change _ ≤ (c.cosHi:ℝ)/q at ch
259 cases back <;> simp only [l,delta,Bool.false_eq_true,if_true,if_false,Int.cast_sub, sub_div] at * <;> linarith
260 have high : delta ≤ (h:ℝ)/q := by
261 change (c.cosLo:ℝ)/q ≤ _ at cl; change _ ≤ (c.cosHi:ℝ)/q at ch
262 cases back <;> simp only [h,delta,Bool.false_eq_true,if_true,if_false,Int.cast_sub, sub_div] at * <;> linarith
263 have pos : 0 ≤ polarWeight r (physical back t) := by unfold polarWeight; positivity
264 exact ⟨(mul_bounds l _ _ wl wh).1.trans (mul_le_mul_of_nonneg_right low pos),
265 (mul_le_mul_of_nonneg_right high pos).trans (mul_bounds h _ _ wl wh).2⟩
266
267def runningSlope (lower back : Bool) (j : ℕ) (rl rh : ℤ) := ∑ k ∈ Finset.range j, increment lower back k rl rh
268
269private theorem width (j : ℕ) : angle 11 (j+1) - angle 11 j = π/2048 := by
270 simp only [angle,Nat.cast_add,Nat.cast_one]; ring
271
272private theorem bin (f : ℝ → ℝ) (c : Continuous f) {a b : ℝ} (ab : a ≤ b) {l h : ℝ}
273 (bounds : ∀ t ∈ Icc a b, l ≤ f t ∧ f t ≤ h) :
274 (b-a)*l ≤ (∫ t in a..b, f t) ∧ (∫ t in a..b, f t) ≤ (b-a)*h := by
275 have lo := intervalIntegral.integral_mono_on (μ := volume) ab (intervalIntegrable_const (c:=l))
276 (c.intervalIntegrable _ _) (fun t ht => (bounds t ht).1)
277 have hi := intervalIntegral.integral_mono_on (μ := volume) ab (c.intervalIntegrable _ _)
278 (intervalIntegrable_const (c:=h)) (fun t ht => (bounds t ht).2)
279 simpa using And.intro lo hi
280
281private theorem src_cont (back : Bool) (r : ℝ) : Continuous (source back r) := by
282 cases back <;> unfold source physical weight <;> simp only [Bool.false_eq_true,if_true,if_false] <;> fun_prop
283
284theorem flux_at_edge (back : Bool) {r : ℝ} {rl rh : ℤ} (hr : 0 ≤ r)
285 (hl : (rl:ℝ)/q ≤ r) (hh : r ≤ (rh:ℝ)/q) (h0 : 0 ≤ rl) (h1 : rl ≤ rh) (h2 : rh ≤ 2*q)
286 (j : ℕ) (hj : j ≤ 1024) :
287 (π/2048)*((runningSlope true back j rl rh:ℝ)/q) ≤ (∫ t in 0..angle 11 j, source back r t) ∧
288 (∫ t in 0..angle 11 j, source back r t) ≤ (π/2048)*((runningSlope false back j rl rh:ℝ)/q) := by
289 induction j with
290 | zero => simp [runningSlope,angle]
291 | succ j ih =>
292 have prev := ih (by omega)
293 have ab : angle 11 j ≤ angle 11 (j+1) := by linarith [width j,pi_pos]
294 have inc := bin _ (src_cont back r) ab (fun t ht => slope_sound back (by omega : j<1024) ht hr hl hh h0 h1 h2)
295 rw [width] at inc
296 rw [← intervalIntegral.integral_add_adjacent_intervals ((src_cont back r).intervalIntegrable 0 (angle 11 j))
297 ((src_cont back r).intervalIntegrable (angle 11 j) (angle 11 (j+1)))]
298 have ps (lower : Bool) : runningSlope lower back (j+1) rl rh = runningSlope lower back j rl rh + increment lower back j rl rh :=
299 Finset.sum_range_succ _ _
300 rw [ps,ps]; push_cast
301 simp only [add_div,mul_add]
302 exact ⟨add_le_add prev.1 inc.1, add_le_add prev.2 inc.2⟩
303
304private theorem partial_bin (f : ℝ → ℝ) (c : Continuous f) {a b t l h : ℝ} (ht : t ∈ Icc a b)
305 (box : ∀ u ∈ Icc a b, l ≤ f u ∧ f u ≤ h) :
306 (b-a)*min 0 l ≤ (∫ u in a..t, f u) ∧ (∫ u in a..t, f u) ≤ (b-a)*max 0 h := by
307 have v := bin f c ht.1 (fun u hu => box u ⟨hu.1,hu.2.trans ht.2⟩)
308 have w : 0 ≤ t-a := sub_nonneg.mpr ht.1
309 have span : t-a ≤ b-a := by linarith [ht.2]
310 constructor
311 · calc (b-a)*min 0 l ≤ (t-a)*min 0 l := mul_le_mul_of_nonpos_right span (min_le_left _ _)
312 _ ≤ (t-a)*l := mul_le_mul_of_nonneg_left (min_le_right _ _) w
313 _ ≤ _ := v.1
314 · calc _ ≤ (t-a)*h := v.2
315 _ ≤ (t-a)*max 0 h := mul_le_mul_of_nonneg_left (le_max_right _ _) w
316 _ ≤ (b-a)*max 0 h := mul_le_mul_of_nonneg_right span (le_max_left _ _)
317
318def fluxCap (fl fh dl dh : ℤ) : ℤ := ceilDiv (max (-(fl+min 0 dl)) (fh+max 0 dh)) 2048
319
320set_option maxRecDepth 4000 in
321theorem partial_flux_cap (back : Bool) {j : ℕ} (hj : j < 1024) {r t : ℝ} {rl rh : ℤ}
322 (ht : t ∈ Icc (angle 11 j) (angle 11 (j+1))) (hr : 0 ≤ r)
323 (hl : (rl:ℝ)/q ≤ r) (hh : r ≤ (rh:ℝ)/q) (h0 : 0 ≤ rl) (h1 : rl ≤ rh) (h2 : rh ≤ 2*q) :
324 let cap := fluxCap (runningSlope true back j rl rh) (runningSlope false back j rl rh)
325 (increment true back j rl rh) (increment false back j rl rh)
326 |polarFlux r (physical back t)| ≤ π*((cap:ℝ)/q) := by
327 let fl := runningSlope true back j rl rh
328 let fh := runningSlope false back j rl rh
329 let dl := increment true back j rl rh
330 let dh := increment false back j rl rh
331 have start := flux_at_edge back hr hl hh h0 h1 h2 j hj.le
332 have sub := partial_bin _ (src_cont back r) ht
333 (fun u hu => slope_sound back hj hu hr hl hh h0 h1 h2)
334 have div_min : min 0 ((dl:ℝ)/q) = (min 0 dl:ℤ)/(q:ℝ) := by
335 push_cast; simpa only [zero_div] using min_div_div_right (by norm_num [q] : (0:ℝ) ≤ q) 0 (dl:ℝ)
336 have div_max : max 0 ((dh:ℝ)/q) = (max 0 dh:ℤ)/(q:ℝ) := by
337 push_cast; simpa only [zero_div] using max_div_div_right (by norm_num [q] : (0:ℝ) ≤ q) 0 (dh:ℝ)
338 change _ * min 0 ((dl:ℝ)/q) ≤ _ ∧ _ ≤ _ * max 0 ((dh:ℝ)/q) at sub
339 rw [width,div_min,div_max] at sub
340 let f := source back r
341 have sum := intervalIntegral.integral_add_adjacent_intervals (μ:=volume) ((src_cont back r).intervalIntegrable 0 (angle 11 j))
342 ((src_cont back r).intervalIntegrable (angle 11 j) t)
343 have lower := add_le_add start.1 sub.1
344 have upper := add_le_add start.2 sub.2
345 rw [sum] at lower upper
346 change π/2048*((fl:ℝ)/q)+_ ≤ _ at lower
347 change _ ≤ π/2048*((fh:ℝ)/q)+_ at upper
348 have ce := ceil_mul_bound (max (-(fl+min 0 dl)) (fh+max 0 dh)) (show (0:ℤ)<2048 by decide)
349 change _ ≤ (fluxCap fl fh dl dh : ℝ)*2048 at ce
350 push_cast at ce
351 have a := (le_max_left _ _).trans ce
352 have b := (le_max_right _ _).trans ce
353 let sc := π/(2048*(q:ℝ))
354 have pos : 0 ≤ sc := by dsimp [sc,q]; positivity
355 have a' := mul_le_mul_of_nonneg_left a pos
356 have b' := mul_le_mul_of_nonneg_left b pos
357 change |polarFlux _ _| ≤ π*((fluxCap fl fh dl dh:ℝ)/q)
358 rw [← inward, abs_le]
359 push_cast at lower upper
360 dsimp [sc] at a' b'; norm_num only [q, Int.cast_ofNat] at lower upper a' b' ⊢
361 constructor <;> linarith
362
363def cellCost (j : ℕ) (wh wl f : ℤ) := if j=0 then ceilDiv (16*wh) 4194304 else ceilDiv (f*f) wl
364
365private theorem cap_density {F p : ℝ} {a wl : ℤ} (absF : |F| ≤ π*((a:ℝ)/q))
366 (low : (wl:ℝ)/q ≤ p) (positive : 0 < wl) :
367 F^2/p ≤ π^2*((ceilDiv (a*a) wl:ℝ)/q) := by
368 have qp : (0:ℝ)<q := by norm_num [q]
369 have w : 0 < (wl:ℝ) := by exact_mod_cast positive
370 have pp := (div_pos w qp).trans_le low
371 have up := ceil_mul_bound (a*a) positive
372 push_cast at up
373 have pos : (0:ℝ) ≤ ceilDiv (a*a) wl := by
374 by_contra! h
375 nlinarith [mul_neg_of_neg_of_pos h w, sq_nonneg (a:ℝ)]
376 have hmul := mul_le_mul_of_nonneg_left low (div_nonneg pos qp.le)
377 have sq := pow_le_pow_left₀ (abs_nonneg F) absF 2
378 rw [sq_abs] at sq
379 apply (div_le_iff₀ pp).2
380 calc F^2 ≤ π^2*((a:ℝ)*a/(q:ℝ)^2) := by norm_num [q] at sq ⊢; linarith
381 _ ≤ π^2*((ceilDiv (a*a) wl:ℝ)*wl/(q:ℝ)^2) :=
382 mul_le_mul_of_nonneg_left (div_le_div_of_nonneg_right up (sq_nonneg _)) (sq_nonneg _)
383 _ ≤ _ := by
384 have z := mul_le_mul_of_nonneg_left hmul (sq_nonneg π)
385 norm_num [q] at z ⊢; linarith
386
387def energyCell (back : Bool) (j : ℕ) (rl rh : ℤ) :=
388 let c := angleCell (index back j)
389 let f := fluxCap (runningSlope true back j rl rh) (runningSlope false back j rl rh)
390 (increment true back j rl rh) (increment false back j rl rh)
391 cellCost j (weightHi c rl rh) (weightLo c rl rh) f
392
393def integrand (r t : ℝ) := polarFlux r t ^ 2 / weight r t
394
395theorem energy_cell_sound (back : Bool) {j : ℕ} (hj : j < 1024) {r t : ℝ} {rl rh : ℤ}
396 (ht : t ∈ Icc (angle 11 j) (angle 11 (j+1))) (hr : 0 ≤ r)
397 (hl : (rl:ℝ)/q ≤ r) (hh : r ≤ (rh:ℝ)/q) (h0 : 0 ≤ rl) (h1 : rl ≤ rh) (h2 : rh ≤ 2*q)
398 (den : j ≠ 0 → 0 < weightLo (angleCell (index back j)) rl rh) :
399 integrand r (physical back t) ≤ π^2*((energyCell back j rl rh:ℝ)/q) := by
400 have ht' := grid_physical back hj ht
401 by_cases zero : j=0
402 · subst j
403 have edge : index back 0 = 0 ∨ index back 0 = 2047 := by cases back <;> simp [index]
404 exact end_cell_cost edge ht' hr hl hh h0 h1 h2
405 · have hi : index back j < 2048 := by cases back <;> simp [index] <;> omega
406 have w := (weight_sound hi ht' hr hl hh (exponent_range _ h0 h1 h2).1 (exponent_range _ h0 h1 h2).2).1
407 have f := partial_flux_cap back hj ht hr hl hh h0 h1 h2
408 simp only [energyCell,cellCost,if_neg zero]
409 exact cap_density f w (den zero)
410
411def gridCost (i : ℕ) (rl rh : ℤ) :=
412 if i < 1024 then energyCell false i rl rh else energyCell true (2047-i) rl rh
413
414private theorem grid_cost_sound {i : ℕ} (hi : i < 2048) {r t : ℝ} {rl rh : ℤ}
415 (ht : t ∈ Icc (angle 11 i) (angle 11 (i+1))) (hr : 0 ≤ r)
416 (hl : (rl:ℝ)/q ≤ r) (hh : r ≤ (rh:ℝ)/q) (h0 : 0 ≤ rl) (h1 : rl ≤ rh) (h2 : rh ≤ 2*q)
417 (den : ∀ i < 2048, i ≠ 0 → i ≠ 2047 → 0 < weightLo (angleCell i) rl rh) :
418 integrand r t ≤ π^2*((gridCost i rl rh:ℝ)/q) := by
419 by_cases first : i<1024
420 · simpa [gridCost,first,physical] using energy_cell_sound false first ht hr hl hh h0 h1 h2
421 (fun h => den i hi h (by omega))
422 · let j := 2047-i
423 have eq : index true j = i := by simp [index,j]; omega
424 have rev : π-t ∈ Icc (angle 11 j) (angle 11 (j+1)) := by
425 obtain ⟨a,b⟩ := ht; have h : i ≤ 2047 := by omega
426 simp [angle,j,Nat.cast_sub h] at *; constructor <;> linarith
427 have jj : j<1024 := by dsimp [j]; omega
428 have nonzero (hn : j ≠ 0) : i ≠ 2047 := by dsimp [j] at hn; omega
429 have d (hn : j ≠ 0) : 0 < weightLo (angleCell (index true j)) rl rh := by
430 rw [eq]; exact den i hi (by omega) (nonzero hn)
431 simpa [gridCost,first,physical,j] using energy_cell_sound true jj rev hr hl hh h0 h1 h2 d
432
433private theorem energy_continuous {r : ℝ} (hr : 0 ≤ r) :
434 ContinuousOn (integrand r) (Icc 0 π) := by
435 have w : Continuous (weight r) := by unfold weight; fun_prop
436 have h := ((polarSpeed_continuousOn hr).pow 2).mul w.continuousOn
437 apply h.congr
438 intro t _
439 dsimp [integrand]
440 by_cases hz : weight r t = 0
441 · simp [hz]
442 · field_simp
443
444def energyAverage (rl rh : ℤ) := ceilDiv (∑ i ∈ Finset.range 2048, gridCost i rl rh) 2048
445def ratioCap (rl rh : ℤ) := ceilDiv (energyAverage rl rh * q) (averageLo weightLo rl rh)
446def parallelCap (rl rh : ℤ) := ceilDiv (ratioCap rl rh * 986961) 100000
447
448/-- The inward integer flux sums and both pole branches bound the normalized continuous
449polar energy, with the same outward-rounded π² factor used by the Omega evaluator. -/
450theorem normalized_parallel {r : ℝ} {rl rh : ℤ} (hr : 0 ≤ r)
451 (hl : (rl:ℝ)/q ≤ r) (hh : r ≤ (rh:ℝ)/q) (h0 : 0 ≤ rl) (h1 : rl ≤ rh) (h2 : rh ≤ 2*q) :
452 parallelEnergy r ≤ (parallelCap rl rh:ℝ)/q := by
453 have den := fun i hi left right => @interior_weight_pos i hi left right rl rh h0 h1 h2
454 let f := fun t => integrand r t / π^2
455 let N := ∫ t in 0..π, f t
456 let Z := ∫ t in 0..π, weight r t
457 let H := energyAverage rl rh
458 let L := averageLo weightLo rl rh
459 let R := ratioCap rl rh
460 have cont : ContinuousOn f (Icc 0 π) := (energy_continuous hr).div_const _
461 have order (i : ℕ) (_ : i < 2048) : angle 11 i ≤ angle 11 (i+1) := by linarith [width i,pi_pos]
462 have ends : angle 11 0 = 0 ∧ angle 11 2048 = π := by norm_num [angle]
463 have sub (i : ℕ) (hi : i < 2048) : Icc (angle 11 i) (angle 11 (i+1)) ⊆ Icc 0 π := by
464 apply Icc_subset_Icc
465 · unfold angle; positivity
466 · have b : (i:ℝ)+1 ≤ 2048 := by exact_mod_cast (show i+1 ≤ 2048 by omega)
467 simp [angle]; nlinarith [mul_le_mul_of_nonneg_right b pi_pos.le]
468 have hg (i : ℕ) (hi : i < 2048) := (cont.mono (sub i hi)).intervalIntegrable_of_Icc (μ := volume) (order i hi)
469 have point (t : ℝ) : 0 ≤ f t := by dsimp [f,integrand,weight]; positivity
470 have bd (i : ℕ) (hi : i < 2048) (t : ℝ) (ht : t ∈ Icc (angle 11 i) (angle 11 (i+1))) :
471 0 ≤ f t ∧ f t ≤ (gridCost i rl rh:ℝ)/q := by
472 refine ⟨point t,(div_le_iff₀ (sq_pos_of_pos pi_pos)).2 ?_⟩
473 simpa only [mul_comm (π^2)] using grid_cost_sound hi ht hr hl hh h0 h1 h2 den
474 have upper := (integral_enclosure order hg bd).2
475 simp only [width,ends.1,ends.2] at upper
476 have c := ceil_mul_bound (∑ i ∈ Finset.range 2048, gridCost i rl rh) (show (0:ℤ)<2048 by decide)
477 change _ ≤ (H:ℝ)*2048 at c
478 push_cast at c
479 have rel : N ≤ (π/(q:ℝ))*H := by
480 have k : 0 ≤ π/(2048*(q:ℝ)) := by dsimp [q]; positivity
481 have eq : (∑ i ∈ Finset.range 2048, π/2048*((gridCost i rl rh:ℝ)/q)) =
482 π/(2048*q)*∑ i ∈ Finset.range 2048,(gridCost i rl rh:ℝ) := by
483 rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intros; ring
484 rw [eq] at upper
485 have rescale (x : ℝ) : π/(2048*q)*(x*2048) = (π/(q:ℝ))*x := by norm_num [q]; ring
486 rw [← rescale]; exact upper.trans (mul_le_mul_of_nonneg_left c k)
487 have z := (average_bounds (partition_and_moment hr hl hh h0 h1 h2).1).1
488 change (π/(q:ℝ))*L ≤ Z at z
489 have lp := normalizer_lower_pos h0 h1 h2
490 have lp' : 0 < (L:ℝ) := by exact_mod_cast lp
491 have qp : (0:ℝ)<q := by norm_num [q]
492 have cp := div_pos pi_pos qp
493 have zp := (mul_pos cp lp').trans_le z
494 have np : 0 ≤ N := intervalIntegral.integral_nonneg pi_pos.le (fun t _ => point t)
495 have hp := nonneg_of_mul_nonneg_right (np.trans rel) cp
496 have frac : N/Z ≤ (H:ℝ)/L := by
497 apply (div_le_div_iff₀ zp lp').2
498 calc N*(L:ℝ) ≤ (π/(q:ℝ)*H)*L := mul_le_mul_of_nonneg_right rel lp'.le
499 _ = H*(π/(q:ℝ)*L) := by ring
500 _ ≤ H*Z := mul_le_mul_of_nonneg_left z hp
501 have u := ceil_mul_bound (H*q) lp
502 change _ ≤ (R:ℝ)*L at u; push_cast at u
503 have ur : (H:ℝ)/L ≤ (R:ℝ)/q := (div_le_div_iff₀ lp' qp).2 u
504 have rp := (div_nonneg hp lp'.le).trans ur
505 have pi2 : π^2 ≤ 986961/100000 := by
506 have d := pow_le_pow_left₀ pi_pos.le pi_lt_d6.le 2
507 norm_num at d ⊢; linarith
508 have e := ceil_mul_bound (R*986961) (show (0:ℤ)<100000 by decide)
509 change _ ≤ (parallelCap rl rh:ℝ)*100000 at e; push_cast at e
510 have scaled : parallelEnergy r = π^2 * (N/Z) := by
511 dsimp [N,Z,f,parallelEnergy,integrand]
512 rw [intervalIntegral.integral_div]
513 field_simp [pi_ne_zero]
514 rw [scaled]
515 calc π^2*(N/Z) ≤ π^2*((R:ℝ)/q) := mul_le_mul_of_nonneg_left (frac.trans ur) (sq_nonneg _)
516 _ ≤ (986961/100000)*((R:ℝ)/q) := mul_le_mul_of_nonneg_right pi2 rp
517 _ ≤ _ := by norm_num [q] at e ⊢; linarith
518
519#print axioms normalized_parallel
520#print axioms partial_flux_cap
521#print axioms flux_at_edge
522#print axioms centered_mean_sound
523#print axioms end_cell_cost
524#print axioms two_pole_cells
525end
526end YangMills.DyadicPolarFlux