Download data/lean/OAI/Analysis/DiskMaximal/Envelopes.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 30.9 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Analysis/DiskMaximal/Envelopes.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Analysis/DiskMaximal/Envelopes.lean
-
curl -L -o Envelopes.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Analysis/DiskMaximal/Envelopes.lean
30.9 kB
| import OAI.Analysis.DiskMaximal.Packing | |
| namespace OAI | |
| open MeasureTheory Set | |
| open scoped ENNReal NNReal Topology ContDiff | |
| open scoped RealInnerProductSpace | |
| open MeasureTheory Set Filter | |
| open scoped Topology ENNReal | |
| open scoped Real RealInnerProductSpace | |
| open MeasureTheory Set Filter | |
| open scoped Topology RealInnerProductSpace ContDiff | |
| open MeasureTheory Set Filter | |
| open scoped Topology Interval NNReal | |
| open MeasureTheory Set Filter | |
| open scoped Topology NNReal Real | |
| open MeasureTheory Set Metric | |
| open scoped ENNReal NNReal Topology | |
| open MeasureTheory Set | |
| open scoped ENNReal NNReal | |
| open MeasureTheory Set | |
| open scoped ENNReal NNReal | |
| open MeasureTheory Set | |
| open scoped ENNReal NNReal Topology | |
| open MeasureTheory Set Metric | |
| open scoped ENNReal NNReal | |
| open MeasureTheory Set | |
| open scoped ENNReal NNReal | |
| open Finset | |
| open scoped RealInnerProductSpace | |
| open MeasureTheory Set Metric | |
| open scoped ENNReal NNReal Topology | |
| open MeasureTheory Set | |
| open scoped ENNReal NNReal RealInnerProductSpace | |
| open MeasureTheory Set | |
| open scoped ENNReal NNReal Topology | |
| open MeasureTheory Set Metric | |
| open scoped ENNReal NNReal RealInnerProductSpace | |
| open scoped RealInnerProductSpace | |
| open scoped RealInnerProductSpace | |
| open scoped ContDiff | |
| open Finset | |
| open MeasureTheory Set Metric Filter | |
| open scoped ENNReal NNReal RealInnerProductSpace ContDiff Topology | |
| open MeasureTheory MeasureTheory.Measure Set Filter | |
| open scoped ENNReal NNReal Topology RealInnerProductSpace ContDiff | |
| open MeasureTheory Set Metric Filter Finset | |
| open scoped ENNReal NNReal RealInnerProductSpace ContDiff Topology | |
| open MeasureTheory Set | |
| open scoped RealInnerProductSpace | |
| noncomputable section | |
| namespace GeometricFilter | |
| open Finset | |
| /-- Causal dyadic averaging, with both the present and the complete past. -/ | |
| def filt (c : β β β) : β β β | |
| | 0 => c 0 | |
| | i+1 => c (i+1)+filt c i/2 | |
| lemma filt_nonneg {c : β β β} (hc : β i, 0 β€ c i) (i : β) : 0 β€ filt c i := by | |
| induction i with | |
| | zero => exact hc 0 | |
| | succ i ih => exact add_nonneg (hc _) (div_nonneg ih (by norm_num)) | |
| lemma le_filt {c : β β β} (hc : β i, 0 β€ c i) (i : β) : c i β€ filt c i := by | |
| cases i with | |
| | zero => exact le_rfl | |
| | succ i => dsimp only [filt]; linarith [filt_nonneg hc i] | |
| lemma filt_le {c : β β β} {A : β} (hA : 0 β€ A) (hc : β i, c i β€ A) (i : β) : filt c i β€ 2*A := by | |
| induction i with | |
| | zero => exact (hc 0).trans (by linarith) | |
| | succ i ih => dsimp only [filt]; linarith [hc (i+1)] | |
| lemma filt_mono {c d : β β β} (h : β i, c i β€ d i) (i : β) : filt c i β€ filt d i := by | |
| induction i with | |
| | zero => exact h 0 | |
| | succ i ih => dsimp only [filt]; linarith [h (i+1)] | |
| lemma filt_mul (c : β β β) (a : β) (i : β) : filt (fun j => a*c j) i = a*filt c i := by | |
| induction i with | |
| | zero => rfl | |
| | succ i ih => simp only [filt,ih]; ring | |
| lemma filt_sum (c : β β β) (i : β) : | |
| filt c i = β j β range (i+1), (1/2:β)^(i-j)*c j := by | |
| induction i with | |
| | zero => simp [filt] | |
| | succ i ih => | |
| rw [filt,ih] | |
| conv_rhs => rw [sum_range_succ] | |
| simp only [Nat.sub_self,pow_zero,one_mul] | |
| rw [add_comm] | |
| congr 1 | |
| rw [div_eq_mul_inv,sum_mul] | |
| apply sum_congr rfl | |
| intro j hj | |
| have hj' : j β€ i := by have := mem_range.mp hj; omega | |
| rw [show i+1-j = (i-j)+1 by omega,pow_succ] | |
| ring | |
| lemma filt_tail_strong {c : β β β} (hc0 : β i, 0 β€ c i) {b m : β} (hbm : b β€ m) : | |
| (β i β Ico b (m+1), filt c i) β€ 2*β i β Ico b (m+1), c i+2*filt c b := by | |
| have hid : (β i β Ico (b+1) (m+1), filt c i) = | |
| (β i β Ico (b+1) (m+1), c i)+(β i β Ico b m, filt c i)/2 := by | |
| rw [β sum_Ico_add' (fun i => filt c i) b m 1, | |
| β sum_Ico_add' (fun i => c i) b m 1] | |
| simp only [filt,sum_add_distrib,sum_div] | |
| have hsplit := sum_eq_sum_Ico_succ_bot (f := filt c) (by omega : b < m+1) | |
| have hcsplit := sum_eq_sum_Ico_succ_bot (f := c) (by omega : b < m+1) | |
| have he : (β i β Ico b m, filt c i) β€ β i β Ico b (m+1), filt c i := by | |
| apply sum_le_sum_of_subset_of_nonneg (Ico_subset_Ico_right (by omega)) | |
| intro i _ _ | |
| exact filt_nonneg hc0 i | |
| rw [hsplit,hid] at he | |
| rw [hsplit,hid,hcsplit] | |
| linarith [hc0 b] | |
| /-- The complete pre-birth history costs a fixed amount, not the birth index. -/ | |
| theorem filt_tail {c : β β β} {A : β} (hA : 0 β€ A) (hc0 : β i, 0 β€ c i) | |
| (hcA : β i, c i β€ A) {b m : β} (hbm : b β€ m) : | |
| (β i β Ico b (m+1), filt c i) β€ 2*β i β Ico b (m+1), c i+4*A := by | |
| have h1 := filt_tail_strong hc0 hbm | |
| have h2 := filt_le hA hcA b | |
| linarith | |
| /-- Two geometric convolutions are summable on every occupied lifetime. -/ | |
| theorem double_tail {c : β β β} {A : β} (hA : 0 β€ A) (hc0 : β i, 0 β€ c i) | |
| (hcA : β i, c i β€ A) {b m : β} (hbm : b β€ m) : | |
| (β i β Ico b (m+1), filt (filt c) i) β€ 4*β i β Ico b (m+1), c i+16*A := by | |
| have h1 := filt_tail hA hc0 hcA hbm | |
| have h2 := filt_tail (by positivity : 0 β€ 2*A) (filt_nonneg hc0) (filt_le hA hcA) hbm | |
| linarith | |
| end GeometricFilter | |
| namespace GeometricFilter | |
| open Finset | |
| lemma radius_sum {r c : β β β} (j : β) (hr : β i β€ j, 0 < r i) | |
| (hstep : β i < j, r i = 2*r (i+1)) : | |
| r j*(β i β range (j+1), c i/r i) = filt c j := by | |
| induction j with | |
| | zero => simp only [Nat.zero_add,sum_range_one,filt]; field_simp [(hr 0 le_rfl).ne'] | |
| | succ j ih => | |
| have hs := ih (fun i hi => hr i (by omega)) (fun i hi => hstep i (by omega)) | |
| rw [sum_range_succ,mul_add,filt] | |
| have he : r (j+1)*(c (j+1)/r (j+1)) = c (j+1) := by field_simp [(hr (j+1) le_rfl).ne'] | |
| rw [he,add_comm] | |
| congr 1 | |
| rw [β hs,hstep j (by omega)] | |
| ring | |
| end GeometricFilter | |
| namespace ActualLabels | |
| open FiniteLabels ConeCoordinates DirectionNeighbors DyadicHats Finset GeometricFilter | |
| def spatialConstant : β := 208*comparisonConstant^2 | |
| lemma spatialConstant_pos : 0 < spatialConstant := by | |
| dsimp [spatialConstant] | |
| have := comparisonConstant_pos | |
| positivity | |
| lemma spatialConstant_ge : 2*comparisonConstant β€ spatialConstant := by | |
| dsimp [spatialConstant] | |
| nlinarith [comparisonConstant_one] | |
| lemma scaled_marginal_distance (h : β β β) (r : β β β) (q : β β β€ Γ β€) | |
| (x y : β) (j : β) (hr : β i β€ j, 0 < r i) | |
| (hstep : β i < j, r i = 2*r (i+1)) | |
| (hx : β i β€ j, boxNorm (x-point (r i) (q i)) < 199*r i) | |
| (hy : β i β€ j, boxNorm (y-point (r i) (q i)) < 199*r i) : | |
| r j*l1dist (marginal h r j x) (marginal h r j y) β€ | |
| comparisonConstant*βx-yβ*filt (energyRate h r q y) j := by | |
| have hd := mul_le_mul_of_nonneg_left (marginal_spatial_distance h r q x y j hr hx hy) (hr j le_rfl).le | |
| have he := radius_sum (c := energyRate h r q y) j hr hstep | |
| calc | |
| _ β€ r j*(comparisonConstant*βx-yβ*β i β range (j+1), energyRate h r q y i/r i) := hd | |
| _ = _ := by rw [β mul_assoc,mul_comm (r j),mul_assoc,he] | |
| /-- Actual spatial comparison at every point of the neighborhood. The gradient | |
| versions are pointwise bounded; differentiability is only needed later for IBP. -/ | |
| theorem filtered_spatial_cost (h : β β β) (r : β β β) (q : β β β€ Γ β€) | |
| (x y : β) (j : β) (hr : β i β€ j, 0 < r i) | |
| (hstep : β i < j, r i = 2*r (i+1)) | |
| (hx : β i β€ j, boxNorm (x-point (r i) (q i)) < 199*r i) | |
| (hy : β i β€ j, boxNorm (y-point (r i) (q i)) < 199*r i) | |
| (hdist : βx-yβ β€ 104*r j) : | |
| switchCost h r x j+derivativeCost h r x j β€ | |
| spatialConstant*filt (energyRate h r q y) j := by | |
| let c := energyRate h r q y | |
| have hc0 : β i, 0 β€ c i := energyRate_nonneg h r q y | |
| have hC := comparisonConstant_one | |
| have hC0 := comparisonConstant_pos.le | |
| cases j with | |
| | zero => | |
| have he : 1 β€ c 0 := by dsimp [c,energyRate,switchCost]; linarith [energy_nonneg h (r 0) (q 0)] | |
| have ht := derivativeCost_uniform h r x 0 (hr 0 le_rfl) | |
| have hbound : 1+16*(Fintype.card Label:β) β€ 2*comparisonConstant := by | |
| dsimp [comparisonConstant] | |
| nlinarith [Nat.cast_nonneg (Ξ± := β) (Fintype.card Label)] | |
| have hh := mul_le_mul_of_nonneg_left he spatialConstant_pos.le | |
| dsimp only [switchCost,filt] | |
| change _ β€ spatialConstant*c 0 | |
| nlinarith [spatialConstant_ge] | |
| | succ j => | |
| have hm := scaled_marginal_distance h r q x y j | |
| (fun i hi => hr i (by omega)) (fun i hi => hstep i (by omega)) | |
| (fun i hi => hx i (by omega)) (fun i hi => hy i (by omega)) | |
| have hd : βx-yβ β€ 52*r j := by rw [hstep j (by omega)]; linarith | |
| have hmag := mul_le_mul_of_nonneg_right hd (mul_nonneg hC0 (filt_nonneg hc0 j)) | |
| have hd' : l1dist (marginal h r j x) (marginal h r j y) β€ | |
| 52*comparisonConstant*filt c j := by | |
| have hrj := hr j (by omega) | |
| change r j*l1dist (marginal h r j x) (marginal h r j y) β€ | |
| comparisonConstant*βx-yβ*filt c j at hm | |
| nlinarith | |
| have hs := switchCost_spatial h r (q (j+1)) x y j (hr (j+1) le_rfl) | |
| (hx (j+1) le_rfl) (hy (j+1) le_rfl) | |
| have ht := derivativeCost_spatial h r (q (j+1)) x y j (hr (j+1) le_rfl) | |
| (hx (j+1) le_rfl) (hy (j+1) le_rfl) | |
| change switchCost h r x (j+1) β€ comparisonConstant*c (j+1)+_ at hs | |
| change derivativeCost h r x (j+1) β€ comparisonConstant*c (j+1)+_ at ht | |
| have hdC := mul_le_mul_of_nonneg_left hd' hC0 | |
| have hcoef : (52*comparisonConstant+52*comparisonConstant^2)*filt c j β€ | |
| (104*comparisonConstant^2)*filt c j := by | |
| apply mul_le_mul_of_nonneg_right _ (filt_nonneg hc0 j) | |
| nlinarith | |
| have hcC := mul_le_mul_of_nonneg_right spatialConstant_ge (hc0 (j+1)) | |
| change _ β€ spatialConstant*filt c (j+1) | |
| rw [filt] | |
| dsimp [spatialConstant] at hcC β’ | |
| nlinarith | |
| end ActualLabels | |
| namespace DyadicHats | |
| lemma scale_mono {r : β} (hr : 0 β€ r) {i j : β} (hij : i β€ j) : scale r i β€ scale r j := by | |
| exact mul_le_mul_of_nonneg_right (pow_le_pow_rightβ (by norm_num : (1:β) β€ 2) hij) hr | |
| lemma descending_step (r : β) {m i : β} (hi : i < m) : | |
| scale r (m-i) = 2*scale r (m-(i+1)) := by | |
| rw [show m-i = (m-(i+1))+1 by omega,scale_succ] | |
| lemma descending_compare {r : β} (hr : 0 β€ r) {m l i : β} (hi : i β€ l+1) : | |
| scale r (m-l) β€ 2*scale r (m-i) := by | |
| rw [β scale_succ] | |
| exact scale_mono hr (by omega) | |
| def neighborhood (r : β) (q : β€ Γ β€) : Set β := {x | boxNorm (x-point r q) β€ 25*r} | |
| lemma point_mem_neighborhood {r : β} (hr : 0 β€ r) (q : β€ Γ β€) : point r q β neighborhood r q := by | |
| change boxNorm (point r q-point r q) β€ _ | |
| simp only [sub_self,boxNorm] | |
| simpa using (mul_nonneg (by norm_num : (0:β) β€ 25) hr) | |
| end DyadicHats | |
| namespace ActualMarkTrees | |
| open DyadicHats IntrinsicMarks | |
| def pathVertex {N : β} (q : Grid N) (p : List (Grid N)) (i : β) : β€ Γ β€ := lastVertex q (p.take i) | |
| lemma terminal_path_locality {N : β} (v : Grid N β β) {r : β} (hr : 0 < r) | |
| {m : β} {q : Grid N} {p : List (Grid N)} (hp : activePath (tree v m 1 q) p) | |
| {i : β} (hi : i β€ m) : | |
| boxNorm (point r (lastVertex q p)-point (scale r (m-i)) (pathVertex q p i)) < scale r (m-i) := by | |
| have hlen := active_length v hp | |
| have hp' : activePath (tree v m 1 q) (p.take i++p.drop i) := by simpa only [List.take_append_drop] using hp | |
| have hl := active_prefix_locality v hr hp' (x := point r (lastVertex q p)) (by | |
| rw [List.take_append_drop,hat_at_point hr.ne'] | |
| norm_num) | |
| simpa only [List.length_take,show min i p.length = i by omega,pathVertex] using hl | |
| /-- The neighborhoods used by assembly remain within the actual 200-neighbor | |
| energy window at every earlier row, including the complete pre-birth history. -/ | |
| lemma path_neighborhood_geometry {N : β} (v : Grid N β β) {r : β} (hr : 0 < r) | |
| {m : β} {q : Grid N} {p : List (Grid N)} (hp : activePath (tree v m 1 q) p) | |
| {l : β} (hl : l β€ m) {x : β} | |
| (hx : x β neighborhood (scale r (m-l)) (pathVertex q p l)) | |
| {i : β} (hi : i β€ m) (hil : i β€ l+1) : | |
| βx-point r (lastVertex q p)β β€ 104*scale r (m-i) β§ | |
| boxNorm (x-point (scale r (m-i)) (pathVertex q p i)) < 199*scale r (m-i) β§ | |
| boxNorm (point r (lastVertex q p)-point (scale r (m-i)) (pathVertex q p i)) < 199*scale r (m-i) := by | |
| let y := point r (lastVertex q p) | |
| have hy := terminal_path_locality v hr hp hl | |
| have hyi := terminal_path_locality v hr hp hi | |
| have hxy := boxNorm_add_le (x-point (scale r (m-l)) (pathVertex q p l)) | |
| (point (scale r (m-l)) (pathVertex q p l)-y) | |
| rw [sub_add_sub_cancel,boxNorm_sub_comm (point _ _)] at hxy | |
| change boxNorm (x-point (scale r (m-l)) (pathVertex q p l)) β€ 25*scale r (m-l) at hx | |
| have hd : boxNorm (x-y) β€ 26*scale r (m-l) := by change boxNorm (y-_) < _ at hy; linarith | |
| have hrel := descending_compare hr.le (m := m) hil | |
| have hrp := scale_pos hr (m-i) | |
| have hnorm := norm_le_two_boxNorm (x-y) | |
| have hxi := boxNorm_add_le (x-y) (y-point (scale r (m-i)) (pathVertex q p i)) | |
| rw [sub_add_sub_cancel] at hxi | |
| change boxNorm (y-point (scale r (m-i)) (pathVertex q p i)) < scale r (m-i) at hyi | |
| exact β¨by dsimp only [y] at hnorm hd; linarith,by linarith,by linarithβ© | |
| end ActualMarkTrees | |
| namespace GeometricFilter | |
| open Finset | |
| lemma filt_mono_on {c d : β β β} (j : β) (h : β i β€ j, c i β€ d i) : filt c j β€ filt d j := by | |
| rw [filt_sum,filt_sum] | |
| exact sum_le_sum (fun i hi => mul_le_mul_of_nonneg_left (h i (by have := mem_range.mp hi; omega)) (by positivity)) | |
| lemma shifted_tail {c : β β β} {A : β} (hA : 0 β€ A) (hc0 : β i, 0 β€ c i) | |
| (hcA : β i, c i β€ A) {b m : β} (hbm : b β€ m) : | |
| (β i β Ico b (m+1), filt c (i+1)) β€ 2*β i β Ico b (m+1), c i+6*A := by | |
| have he := sum_Ico_sub (filt c) (by omega : b β€ m+1) | |
| rw [sum_sub_distrib] at he | |
| have h1 := filt_tail hA hc0 hcA hbm | |
| linarith [filt_le hA hcA (m+1),filt_nonneg hc0 b] | |
| end GeometricFilter | |
| namespace DyadicHats | |
| noncomputable def localSup (f : β β β) (r : β) (q : β€ Γ β€) : β := | |
| sSup (f '' neighborhood r q) | |
| lemma localSup_le {f : β β β} {r A : β} (hr : 0 β€ r) (q : β€ Γ β€) | |
| (h : β x β neighborhood r q, f x β€ A) : localSup f r q β€ A := by | |
| apply csSup_le (Set.Nonempty.image f β¨point r q,point_mem_neighborhood hr qβ©) | |
| rintro z β¨x,hx,rflβ© | |
| exact h x hx | |
| lemma le_localSup {f : β β β} {r A : β} (q : β€ Γ β€) | |
| (h : β x β neighborhood r q, f x β€ A) {x : β} (hx : x β neighborhood r q) : | |
| f x β€ localSup f r q := le_csSup β¨A,by rintro z β¨y,hy,rflβ©; exact h y hyβ© β¨x,hx,rflβ© | |
| lemma localSup_nonneg {f : β β β} {r A : β} (hr : 0 β€ r) (q : β€ Γ β€) | |
| (h0 : β x, 0 β€ f x) (h : β x β neighborhood r q, f x β€ A) : 0 β€ localSup f r q := | |
| (h0 (point r q)).trans (le_localSup q h (point_mem_neighborhood hr q)) | |
| end DyadicHats | |
| namespace ActualLabels | |
| open DyadicHats GeometricFilter FiniteLabels Finset | |
| lemma derivativeCost_nonneg (h : β β β) (r : β β β) (x : β) (i : β) (hr : 0 β€ r i) : | |
| 0 β€ derivativeCost h r x i := by | |
| cases i with | |
| | zero => exact mul_nonneg hr (sum_nonneg (fun _ _ => norm_nonneg _)) | |
| | succ i => exact FiniteLabels.expect_nonneg _ (rowDerivative_nonneg h hr x) | |
| def cellCost (h : β β β) (r : β β β) (m l : β) (q : β€ Γ β€) : β := | |
| localSup (fun x => switchCost h r x l) (r l) q+ | |
| (if l=m then 1 else localSup (fun x => switchCost h r x (l+1)) (r l) q)+ | |
| filt (fun i => localSup (fun x => derivativeCost h r x i) (r l) q) l | |
| lemma cellCost_nonneg (h : β β β) (r : β β β) (hr : β i, 0 < r i) (m l : β) (q : β€ Γ β€) : | |
| 0 β€ cellCost h r m l q := by | |
| have hs (i : β) : 0 β€ localSup (fun x => switchCost h r x i) (r l) q := | |
| localSup_nonneg (hr l).le q (fun x => switchCost_nonneg h r x i) (fun x _ => switchCost_le_one h r x i) | |
| have ht (i : β) : 0 β€ localSup (fun x => derivativeCost h r x i) (r l) q := | |
| localSup_nonneg (hr l).le q (fun x => derivativeCost_nonneg h r x i (hr i).le) | |
| (fun x _ => derivativeCost_uniform h r x i (hr i)) | |
| dsimp only [cellCost] | |
| exact add_nonneg (add_nonneg (hs _) (by split_ifs; exact zero_le_one; exact hs _)) (filt_nonneg ht l) | |
| end ActualLabels | |
| namespace ActualMarkTrees | |
| open DyadicHats IntrinsicMarks ActualLabels GeometricFilter Finset | |
| lemma path_filtered_cost {N : β} (h : β β β) (v : Grid N β β) {r : β} (hr : 0 < r) | |
| {m : β} {q : Grid N} {p : List (Grid N)} (hp : activePath (tree v m 1 q) p) | |
| {l : β} (hl : l β€ m) {x : β} (hx : x β neighborhood (scale r (m-l)) (pathVertex q p l)) | |
| {i : β} (hi : i β€ m) (hil : i β€ l+1) : | |
| switchCost h (fun j => scale r (m-j)) x i+derivativeCost h (fun j => scale r (m-j)) x i β€ | |
| spatialConstant*filt (energyRate h (fun j => scale r (m-j)) (pathVertex q p) (point r (lastVertex q p))) i := by | |
| apply filtered_spatial_cost h _ _ x _ i (fun j _ => scale_pos hr (m-j)) | |
| (fun j hj => descending_step r (by omega)) | |
| Β· intro j hj | |
| exact (path_neighborhood_geometry v hr hp hl hx (by omega : j β€ m) (by omega)).2.1 | |
| Β· intro j hj | |
| exact (path_neighborhood_geometry v hr hp hl hx (by omega : j β€ m) (by omega)).2.2 | |
| Β· exact (path_neighborhood_geometry v hr hp hl hx hi hil).1 | |
| lemma path_cellCost {N : β} (h : β β β) (v : Grid N β β) {r : β} (hr : 0 < r) | |
| {m : β} {q : Grid N} {p : List (Grid N)} (hp : activePath (tree v m 1 q) p) | |
| {l : β} (hl : l β€ m) : | |
| cellCost h (fun j => scale r (m-j)) m l (pathVertex q p l) β€ | |
| spatialConstant*(filt (energyRate h (fun j => scale r (m-j)) (pathVertex q p) (point r (lastVertex q p))) l+ | |
| filt (energyRate h (fun j => scale r (m-j)) (pathVertex q p) (point r (lastVertex q p))) (l+1)+ | |
| filt (filt (energyRate h (fun j => scale r (m-j)) (pathVertex q p) (point r (lastVertex q p)))) l)+ | |
| (if l=m then 1 else 0) := by | |
| let rs := fun j => scale r (m-j) | |
| let c := energyRate h rs (pathVertex q p) (point r (lastVertex q p)) | |
| have hs (i : β) (hi : i β€ m) (hil : i β€ l+1) : | |
| localSup (fun x => switchCost h rs x i) (rs l) (pathVertex q p l) β€ spatialConstant*filt c i := by | |
| apply localSup_le (scale_pos hr _).le | |
| intro x hx | |
| have hh := path_filtered_cost h v hr hp hl hx hi hil | |
| change switchCost h rs x i+derivativeCost h rs x i β€ spatialConstant*filt c i at hh | |
| linarith [derivativeCost_nonneg h rs x i (scale_pos hr _).le] | |
| have ht (i : β) (hi : i β€ l) : | |
| localSup (fun x => derivativeCost h rs x i) (rs l) (pathVertex q p l) β€ spatialConstant*filt c i := by | |
| apply localSup_le (scale_pos hr _).le | |
| intro x hx | |
| have hh := path_filtered_cost h v hr hp hl hx (show i β€ m by omega) (show i β€ l+1 by omega) | |
| change switchCost h rs x i+derivativeCost h rs x i β€ spatialConstant*filt c i at hh | |
| linarith [switchCost_nonneg h rs x i] | |
| have hT := filt_mono_on l ht | |
| rw [filt_mul] at hT | |
| have hnext : (if l=m then 1 else localSup (fun x => switchCost h rs x (l+1)) (rs l) (pathVertex q p l)) β€ | |
| spatialConstant*filt c (l+1)+(if l=m then 1 else 0) := by | |
| split_ifs with he | |
| Β· have hh := mul_nonneg spatialConstant_pos.le (filt_nonneg (energyRate_nonneg h rs (pathVertex q p) (point r (lastVertex q p))) (l+1)) | |
| linarith | |
| Β· simpa only [add_zero] using hs (l+1) (by omega) le_rfl | |
| have hcur := hs l hl (by omega) | |
| change cellCost h rs m l (pathVertex q p l) β€ _ | |
| dsimp only [cellCost] | |
| change _ β€ spatialConstant*(filt c l+filt c (l+1)+filt (filt c) l)+(if l=m then 1 else 0) | |
| linarith | |
| lemma path_cellCost_sum {N : β} (h : β β β) (v : Grid N β β) {r : β} (hr : 0 < r) | |
| {m : β} {q : Grid N} {p : List (Grid N)} (hp : activePath (tree v m 1 q) p) | |
| {b : β} (hb : b β€ m) : | |
| (β l β Ico b (m+1), cellCost h (fun j => scale r (m-j)) m l (pathVertex q p l)) β€ | |
| spatialConstant*(8*β i β Ico b (m+1), | |
| energyRate h (fun j => scale r (m-j)) (pathVertex q p) (point r (lastVertex q p)) i+130)+1 := by | |
| let c := energyRate h (fun j => scale r (m-j)) (pathVertex q p) (point r (lastVertex q p)) | |
| have hc0 := energyRate_nonneg h (fun j => scale r (m-j)) (pathVertex q p) (point r (lastVertex q p)) | |
| have hcA := energyRate_le_five h (fun j => scale r (m-j)) (pathVertex q p) (point r (lastVertex q p)) | |
| have h1 := filt_tail (by norm_num : (0:β) β€ 5) hc0 hcA hb | |
| have h2 := shifted_tail (by norm_num : (0:β) β€ 5) hc0 hcA hb | |
| have h3 := double_tail (by norm_num : (0:β) β€ 5) hc0 hcA hb | |
| have hs := sum_le_sum (fun l (hl : l β Finset.Ico b (m+1)) => path_cellCost h v hr hp (show l β€ m by have := Finset.mem_Ico.mp hl; omega)) | |
| change _ β€ β l β Ico b (m+1), (spatialConstant*(filt c l+filt c (l+1)+filt (filt c) l)+(if l=m then 1 else 0)) at hs | |
| simp only [sum_add_distrib,β mul_sum] at hs | |
| have he : (β l β Ico b (m+1), if l=m then (1:β) else 0) = 1 := by simp [hb] | |
| rw [he] at hs | |
| change _ β€ spatialConstant*(8*β i β Ico b (m+1), c i+130)+1 | |
| have hh : (β i β Ico b (m+1), filt c i)+(β i β Ico b (m+1), filt c (i+1))+ | |
| (β i β Ico b (m+1), filt (filt c) i) β€ 8*β i β Ico b (m+1), c i+130 := by linarith | |
| exact hs.trans (by nlinarith [mul_le_mul_of_nonneg_left hh spatialConstant_pos.le]) | |
| end ActualMarkTrees | |
| namespace ActualMarkTrees | |
| open DyadicHats IntrinsicMarks ActualLabels GeometricFilter DirectionNeighbors Finset | |
| def packingCharge {N : β} (h : β β β) (r : β) (m : β) (q : Grid N) : List (Grid N) β β := | |
| spatialCharge (fun j z => cellCost h (fun i => scale r (m-i)) m (m-j) z) m q | |
| lemma packingCharge_path {N : β} (h : β β β) (v : Grid N β β) {r : β} (hr : 0 < r) | |
| {m : β} {q : Grid N} {p : List (Grid N)} (hp : activePath (tree v m 1 q) p) | |
| {b : β} (hb : b β€ p.length) : | |
| pathCharge (packingCharge h r m q) p b β€ | |
| 8*spatialConstant*particleSwitches h r m q p b+ | |
| 8*spatialConstant*pathCharge (pathEnergy h r m q) p b+(130*spatialConstant+1) := by | |
| have hlen := active_length v hp | |
| have hs := path_cellCost_sum h v hr hp (show b β€ m by omega) | |
| have hC : pathCharge (packingCharge h r m q) p b = | |
| β i β Ico b (m+1), cellCost h (fun j => scale r (m-j)) m i (pathVertex q p i) := by | |
| rw [pathCharge_sum,hlen] | |
| apply sum_congr rfl | |
| intro i hi | |
| have hi' : i β€ m := by have := Finset.mem_Ico.mp hi; omega | |
| simp only [packingCharge,spatialCharge,List.length_take,hlen,min_eq_left hi', | |
| Nat.sub_sub_self hi',pathVertex] | |
| have hE : (β i β Ico b (m+1), energyRate h (fun j => scale r (m-j)) (pathVertex q p) | |
| (point r (lastVertex q p)) i) = | |
| particleSwitches h r m q p b+pathCharge (pathEnergy h r m q) p b := by | |
| rw [pathCharge_sum] | |
| simp only [particleSwitches,pathSwitches,hlen,energyRate,sum_add_distrib] | |
| congr 1 | |
| apply sum_congr rfl | |
| intro i hi | |
| have hi' : i β€ m := by have := Finset.mem_Ico.mp hi; omega | |
| simp only [pathEnergy,List.length_take,hlen,min_eq_left hi',pathVertex] | |
| rw [hC] | |
| rw [hE] at hs | |
| linarith | |
| lemma tree_packing_bound {N : β} (h : β β β) (v : Grid N β β) {r : β} (hr : 0 < r) | |
| (m : β) (q : Grid N) : | |
| nodeCharge (tree v m 1 q) (packingCharge h r m q) β€ | |
| 8*spatialConstant*particleEval (tree v m 1 q) (particleSwitches h r m q)+ | |
| 8*spatialConstant*nodeCharge (tree v m 1 q) (pathEnergy h r m q)+ | |
| (130*spatialConstant+1)*terminalMass (tree v m 1 q) := by | |
| have hs := particleEval_mono_active (tree v m 1 q) | |
| (F := pathCharge (packingCharge h r m q)) | |
| (fun p b hp hb => packingCharge_path h v hr hp hb) | |
| simp only [particleEval_add,particleEval_smul,particleEval_const,particle_occupancy] at hs | |
| nlinarith only [hs] | |
| def packingConstant : β := | |
| 8*spatialConstant*(2560004+2000000*(576*(4097:β)^2))+ | |
| 8*spatialConstant*(576*(4097:β)^2)+(130*spatialConstant+1) | |
| lemma packingConstant_pos : 0 < packingConstant := by | |
| dsimp [packingConstant] | |
| have := spatialConstant_pos | |
| positivity | |
| theorem spatial_packing {N : β} {r R : β} (hr : 0 < r) (hR : 0 β€ R) | |
| (hN : R/r+1 β€ (N:β)) {h : β β β} (hh : Integrable h) | |
| (hsupp : β y, h y β 0 β βyβ β€ R) (m : β) : | |
| (β j β range (m+1), β q : Grid N, scalarMass h (scale r j) q* | |
| cellCost h (fun i => scale r (m-i)) m (m-j) q) β€ | |
| packingConstant*(β« y, βh yβ) := by | |
| have hs := sum_le_sum (fun q (_ : q β (univ : Finset (Grid N))) => | |
| tree_packing_bound h (fun q => vectorMass h r q) hr m q) | |
| simp only [sum_add_distrib,β mul_sum] at hs | |
| have hleft : (β q : Grid N, nodeCharge (tree (fun q => vectorMass h r q) m 1 q) | |
| (packingCharge h r m q)) = | |
| β j β range (m+1), β q : Grid N, scalarMass h (scale r j) q* | |
| cellCost h (fun i => scale r (m-i)) m (m-j) q := by | |
| unfold packingCharge | |
| rw [sum_nodeCharge] | |
| apply sum_congr rfl | |
| intro j hj | |
| apply sum_congr rfl | |
| intro q hq | |
| rw [β vectorMass_coeff hr hR hN hh hsupp] | |
| rfl | |
| rw [hleft,sum_energyCharge hr hR hN hh hsupp,sum_terminalMass] at hs | |
| have hS := forest_switch_budget hr hR hN hh hsupp m | |
| have hE := neighbor_energy_budget hr hR hN hh hsupp (m+1) | |
| have hM := sum_scalarMass_grid_le (N := N) hh r | |
| change (β q : Grid N, βvectorMass h r qβ) β€ β« y, βh yβ at hM | |
| have hcoef : 0 β€ 8*spatialConstant := by have := spatialConstant_pos; positivity | |
| have hcoef' : 0 β€ 130*spatialConstant+1 := by have := spatialConstant_pos; positivity | |
| dsimp only [packingConstant] | |
| nlinarith only [hs,mul_le_mul_of_nonneg_left hS hcoef, | |
| mul_le_mul_of_nonneg_left hE hcoef,mul_le_mul_of_nonneg_left hM hcoef'] | |
| end ActualMarkTrees | |
| namespace CommonPrices | |
| open DyadicHats ConeCoordinates ConeScalar LocalCancellation AffineDensities DirectionNeighbors Finset DiskMoments PricePieces | |
| def rootMass {N : β} (h : β β β) (r : β) (k : β) (S : Finset (Grid N)) : β := | |
| β q β S, scalarMass h (scale r k) q | |
| lemma rootMass_nonneg {N : β} (h : β β β) (r : β) (k : β) (S : Finset (Grid N)) : | |
| 0 β€ rootMass h r k S := sum_nonneg (fun _ _ => norm_nonneg _) | |
| def sizeErrors {N : β} {r : β} (hr : 0 < r) {h : β β β} (hh : Integrable h) | |
| (k : β) (p : β) (S : Finset (Grid N)) (n : β) : Option (ErrorIndex N k) β ErrorPiece 2 | |
| | none => unitPiece (rescale p (scale r k) (rootSum h r k S n)) | |
| (integrable_rescale (rootSum_integrable hh r k S n) p (scale_pos hr k).ne') 2 | |
| | some i => smallPiece hh hr k p S n i | |
| lemma sizeErrors_price {N : β} {r R : β} (hr : 0 < r) (hR : 0 β€ R) | |
| (hN : R/r+1 β€ (N:β)) {h : β β β} (hh : Integrable h) | |
| (hsupp : β y, h y β 0 β βyβ β€ R) (k : β) (p : β) (S : Finset (Grid N)) | |
| {n : β} (hn : n β fixedPalette.labels) : | |
| errorPrice (sizeErrors hr hh k p S n) (1/100) β€ | |
| (scale r k)β»ΒΉ*(4*rootMass h r k S+2*cellPrice N r h k S) := by | |
| have hb : (sizeErrors hr hh k p S n none).mass β€ (scale r k)β»ΒΉ*4*rootMass h r k S := by | |
| change (β« X, βrescale p (scale r k) (rootSum h r k S n) Xβ) β€ _ | |
| rw [mass_rescale _ _ (scale_pos hr k)] | |
| simpa only [mul_assoc,rootMass] using mul_le_mul_of_nonneg_left | |
| (rootSum_mass hr hR hN hh hsupp k S (fixedPalette.unit n hn)) (inv_nonneg.mpr (scale_pos hr k).le) | |
| have hs := smallPiece_common_price hr hR hN hh hsupp k p S hn | |
| change (β i, (smallPiece hh hr k p S n i).size^(1/100:β)* | |
| (smallPiece hh hr k p S n i).mass) β€ _ at hs | |
| simp only [errorPrice,Fintype.sum_option,show (sizeErrors hr hh k p S n none).size = 1 from rfl, | |
| Real.one_rpow,one_mul] | |
| change (sizeErrors hr hh k p S n none).mass + (β i, (smallPiece hh hr k p S n i).size^(1/100:β)*(smallPiece hh hr k p S n i).mass) β€ _ | |
| linarith | |
| lemma sizeErrors_gradient {N : β} {r R : β} (hr : 0 < r) (hR : 0 β€ R) | |
| (hN : R/r+1 β€ (N:β)) {g : β β β} (hg : Differentiable β g) | |
| (hh : Integrable (gradient g)) (hsupp : β y, gradient g y β 0 β βyβ β€ R) | |
| (k : β) (p : β€ Γ β€) {n : β} (hn : βnβ = 1) (X : β) (hX : βXβ β€ 12) : | |
| (β i, (sizeErrors hr hh k (point (scale r k) p) (cellRoots N p) n i).density X) = | |
| gradient (fun Y => g (point (scale r k) p+scale r k β’ Y)) X := by | |
| rw [Fintype.sum_option] | |
| change rescale _ _ (rootSum _ _ _ _ _) X+ | |
| (β i : ErrorIndex N k, (smallPiece hh hr k _ _ n i).density X) = _ | |
| rw [smallPiece_sum,gradient_affine hg] | |
| simp only [rescale,β smul_add,rootSum,β sum_add_distrib] | |
| have he := sum_congr rfl (fun q (_ : q β cellRoots N p) => | |
| (vector_decomposition hr hR hN hsupp k q hn (point (scale r k) p+scale r k β’ X)).symm) | |
| rw [he,β sum_smul,cell_partition (scale_pos hr k) (scale_index_bound hr hR hN k) hsupp p X hX] | |
| /-- The endpoint-bin gradient price, with all root terms retained rather than | |
| silently using the cone estimate at one-sided maximizing radii. -/ | |
| theorem size_cell_price : β C : β, 0 < C β§ | |
| β {N : β} {r R : β} (hr : 0 < r) (hR : 0 β€ R) (hN : R/r+1 β€ (N:β)) | |
| {g : β β β}, ContDiff β 1 g β Integrable (gradient g) β | |
| (β y, gradient g y β 0 β βyβ β€ R) β β (k : β) (p : β€ Γ β€) | |
| {n : β}, n β fixedPalette.labels β β Q : Set β, volume Q β€ ENNReal.ofReal 1 β | |
| β F : β β ββ₯0β, Measurable F β§ | |
| (β«β» X in Q, F X) β€ ENNReal.ofReal (C*(scale r k)β»ΒΉ* | |
| (rootMass (gradient g) r k (cellRoots N p)+cellPrice N r (gradient g) k (cellRoots N p))) β§ | |
| β X, βXβ β€ 2 β β t, | |
| EndpointRadius (fun Y => g (point (scale r k) p+scale r k β’ Y)) X t β | |
| ENNReal.ofReal ββ« Y in Metric.ball X t, | |
| gradient (fun Z => g (point (scale r k) p+scale r k β’ Z)) Yβ β€ F X := by | |
| obtain β¨C,hC,hmajorβ© := size_majorant (by norm_num : (0:β) β€ 2) | |
| refine β¨4*C,by positivity,?_β© | |
| intro N r R hr hR hN g hg hh hsupp k p n hn Q hQ | |
| let b := sizeErrors hr hh k (point (scale r k) p) (cellRoots N p) n | |
| have hg' : ContDiff β 1 (fun Y => g (point (scale r k) p+scale r k β’ Y)) := hg.comp (by fun_prop) | |
| obtain β¨F,hFm,hFi,hFbβ© := hmajor b _ hg' Q hQ | |
| refine β¨F,hFm,?_,?_β© | |
| Β· apply hFi.trans | |
| apply ENNReal.ofReal_le_ofReal | |
| have hb := sizeErrors_price hr hR hN hh hsupp k (point (scale r k) p) (cellRoots N p) hn | |
| have hD : 0 β€ cellPrice N r (gradient g) k (cellRoots N p) := | |
| sum_nonneg (fun q _ => rootPrice_nonneg hr hR hN hh hsupp k q) | |
| change errorPrice b (1/100) β€ _ at hb | |
| have hrk := scale_pos hr k | |
| nlinarith [mul_le_mul_of_nonneg_left hb hC.le,inv_nonneg.mpr hrk.le, | |
| mul_nonneg (inv_nonneg.mpr hrk.le) hD] | |
| Β· intro X hX t ht | |
| apply hFb X _ t ht | |
| filter_upwards with Y hY | |
| apply sizeErrors_gradient hr hR hN (hg.differentiable one_ne_zero) hh hsupp k p (fixedPalette.unit n hn) | |
| have hy : βY-Xβ < 3 := by simpa only [Metric.mem_ball,dist_eq_norm] using hY | |
| have htri := norm_add_le (Y-X) X | |
| rw [sub_add_cancel] at htri | |
| linarith | |
| end CommonPrices | |
| end | |
| end OAI | |