Download data/lean/OAI/Analysis/DiskMaximal/RunCancellation.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 30.5 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Analysis/DiskMaximal/RunCancellation.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Analysis/DiskMaximal/RunCancellation.lean
-
curl -L -o RunCancellation.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Analysis/DiskMaximal/RunCancellation.lean
30.5 kB
| import OAI.Analysis.DiskMaximal.Runs | |
| 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 SignedRuns | |
| open DiskMoments ActualLabels | |
| def Regular (f : β β β) : Prop := HasCompactSupport f β§ β L : ββ₯0, LipschitzWith L f | |
| lemma regular_zero : Regular (fun _ : β => (0:β)) := | |
| β¨HasCompactSupport.zero,0,LipschitzWith.const 0β© | |
| lemma regular_add {f g : β β β} (hf : Regular f) (hg : Regular g) : | |
| Regular (fun x => f x+g x) := by | |
| obtain β¨hfC,L,hfLβ© := hf | |
| obtain β¨hgC,K,hgLβ© := hg | |
| exact β¨hfC.add hgC,L+K,hfL.add hgLβ© | |
| lemma regular_scalar {f : β β β} (hc : HasCompactSupport f) {L : ββ₯0} | |
| (hf : LipschitzWith L f) (n : Label) : Regular (fun x => f x β’ (n:β)) := by | |
| refine β¨hc.smul_right,L,?_β© | |
| rw [lipschitzWith_iff_norm_sub_le] at hf β’ | |
| intro x y | |
| simpa only [β sub_smul,norm_smul,label_unit,mul_one] using hf x y | |
| lemma regular_listSum {Ξ± : Type*} (l : List Ξ±) (f : Ξ± β β β β) | |
| (hf : β a β l, Regular (f a)) : Regular (fun x => (l.map fun a => f a x).sum) := by | |
| induction l with | |
| | nil => exact regular_zero | |
| | cons a l ih => | |
| exact regular_add (hf a (by simp)) (ih (fun b hb => hf b (by simp [hb]))) | |
| lemma runTerm_regular {g : β β β} {r : β β β} (hg : ContDiff β 1 g) | |
| (hgc : HasCompactSupport g) (hr : β k, 0 < r k) (hstep : β k, 2*r (k+1) = r k) | |
| (a : Run) (ha : a.first β€ a.last) : | |
| Regular (fun x => (runEnvelope g r a.first a.last x-signedAverage g x (r a.first)) β’ (a.dir:β)) := by | |
| have hab : r a.last β€ 2*r a.first := by | |
| have := radius_antitone r hr hstep ha | |
| linarith [hr a.first] | |
| obtain β¨L,hLβ© := run_envelope_lipschitz hg hgc (hr a.last) hab | |
| obtain β¨K,hKβ© := hg.lipschitzWith_of_hasCompactSupport hgc one_ne_zero | |
| apply regular_scalar | |
| ((run_envelope_hasCompactSupport hg hgc (hr a.last) hab).sub (signedAverage_hasCompactSupport hg hgc (hr a.first))) | |
| (hL.sub (signedAverage_lipschitz hK (hr a.first))) | |
| /-- Every exact history potential is compactly supported and Lipschitz, as | |
| needed for signed weighted integration by parts. -/ | |
| theorem potential_regular {g : β β β} {r : β β β} (hg : ContDiff β 1 g) | |
| (hgc : HasCompactSupport g) (hr : β k, 0 < r k) (hstep : β k, 2*r (k+1) = r k) | |
| (p : List Label) : Regular (fun x => potential g r x p) := by | |
| cases p with | |
| | nil => exact regular_zero | |
| | cons n p => | |
| simp_rw [potential_eq_runs] | |
| exact regular_listSum (runs (n::p)) _ (fun a ha => | |
| runTerm_regular hg hgc hr hstep a (runs_bounds n p a ha).1) | |
| end SignedRuns | |
| namespace SignedRuns | |
| open Complex | |
| def divergence (V : β β β) (x : β) : β := | |
| fderiv β (fun y => (V y).re) x 1+fderiv β (fun y => (V y).im) x I | |
| lemma inner_coordinates (z w : β) : | |
| inner β z w = inner β z (1:β)*w.re+inner β z I*w.im := by | |
| conv_lhs => rw [β Complex.re_add_im w] | |
| rw [inner_add_right] | |
| have hre : (w.re:β) = w.re β’ (1:β) := by simp | |
| have him : (w.im:β)*I = w.im β’ I := by rw [Complex.real_smul] | |
| rw [hre,him,real_inner_smul_right,real_inner_smul_right] | |
| ring | |
| lemma gradient_aestronglyMeasurable (f : β β β) : AEStronglyMeasurable (gradient f) := | |
| ((InnerProductSpace.toDual β β).symm.continuous.measurable.comp | |
| (measurable_fderiv β f)).aestronglyMeasurable | |
| lemma gradient_norm_le {f : β β β} {L : ββ₯0} (hf : LipschitzWith L f) (x : β) : | |
| βgradient f xβ β€ (L:β) := by | |
| simpa only [gradient,(InnerProductSpace.toDual β β).symm.norm_map] using | |
| (norm_fderiv_le_of_lipschitz β hf : βfderiv β f xβ β€ (L:β)) | |
| lemma integrable_fderiv_apply {f : β β β} {L : ββ₯0} (hf : LipschitzWith L f) | |
| (hc : HasCompactSupport f) (v : β) : Integrable (fun x => fderiv β f x v) := by | |
| have hi := (innerSL β v).integrable_comp (_root_.OAI.LipschitzWith.integrable_gradient (ΞΌ := volume) hf hc) | |
| apply hi.congr | |
| filter_upwards with x | |
| change inner β v (gradient f x) = _ | |
| rw [real_inner_comm,gradient,InnerProductSpace.toDual_symm_apply] | |
| lemma integrable_gradient_mul {f g : β β β} {L : ββ₯0} (hf : LipschitzWith L f) | |
| (hg : Integrable g) (v : β) : Integrable (fun x => inner β (gradient f x) v*g x) := by | |
| apply hg.bdd_mul ((gradient_aestronglyMeasurable f).inner aestronglyMeasurable_const) | |
| filter_upwards with x | |
| exact (norm_inner_le_norm _ _).trans (mul_le_mul_of_nonneg_right (gradient_norm_le hf x) (norm_nonneg v)) | |
| lemma regular_integrable (V : β β β) (hV : Regular V) : Integrable V := by | |
| obtain β¨hc,L,hLβ© := hV | |
| exact hL.continuous.integrable_of_hasCompactSupport hc | |
| lemma weighted_divergence_integrable {w : β β β} {K : ββ₯0} (hw : LipschitzWith K w) | |
| (hb : β x, βw xβ β€ 1) {V : β β β} (hV : Regular V) : | |
| Integrable (fun x => w x*divergence V x) := by | |
| obtain β¨hc,L,hLβ© := hV | |
| have hr := integrable_fderiv_apply (Complex.reCLM.lipschitzWith.comp hL) | |
| (hc.comp_left (map_zero Complex.reCLM)) (1:β) | |
| have hi := integrable_fderiv_apply (Complex.imCLM.lipschitzWith.comp hL) | |
| (hc.comp_left (map_zero Complex.imCLM)) I | |
| exact (hr.add hi).bdd_mul hw.continuous.aestronglyMeasurable (ae_of_all _ hb) | |
| lemma potential_flux_integrable {w : β β β} {K : ββ₯0} (hw : LipschitzWith K w) | |
| {V : β β β} (hV : Regular V) : | |
| Integrable (fun x => inner β (gradient w x) (V x)) := by | |
| have hi := regular_integrable V hV | |
| apply (hi.norm.const_mul (K:β)).mono' | |
| ((gradient_aestronglyMeasurable w).inner hi.aestronglyMeasurable) | |
| filter_upwards with x | |
| exact (norm_inner_le_norm _ _).trans (mul_le_mul_of_nonneg_right (gradient_norm_le hw x) (norm_nonneg _)) | |
| /-- Weighted vector integration by parts for the actual class of compact | |
| Lipschitz path potentials and bounded Lipschitz spatial history weights. -/ | |
| theorem vector_weighted_ibp {w : β β β} {K : ββ₯0} (hw : LipschitzWith K w) | |
| (hb : β x, βw xβ β€ 1) {V : β β β} (hV : Regular V) : | |
| (β« x, w x*divergence V x) = -β« x, inner β (gradient w x) (V x) := by | |
| obtain β¨hc,L,hLβ© := hV | |
| have hrL := Complex.reCLM.lipschitzWith.comp hL | |
| have hiL := Complex.imCLM.lipschitzWith.comp hL | |
| have hrC := hc.comp_left (map_zero Complex.reCLM) | |
| have hiC := hc.comp_left (map_zero Complex.imCLM) | |
| have hr := (integrable_fderiv_apply hrL hrC (1:β)).bdd_mul | |
| hw.continuous.aestronglyMeasurable (ae_of_all _ hb) | |
| have hi := (integrable_fderiv_apply hiL hiC I).bdd_mul | |
| hw.continuous.aestronglyMeasurable (ae_of_all _ hb) | |
| have hrr := integrable_gradient_mul hw (hrL.continuous.integrable_of_hasCompactSupport hrC) (1:β) | |
| have hir := integrable_gradient_mul hw (hiL.continuous.integrable_of_hasCompactSupport hiC) I | |
| change (β« x, w x*(fderiv β (Complex.reCLM β V) x 1+fderiv β (Complex.imCLM β V) x I)) = _ | |
| simp only [mul_add] | |
| rw [integral_add hr hi,_root_.OAI.LipschitzWith.integral_mul_fderiv_eq_neg (ΞΌ := volume) hw hrL hrC (1:β), | |
| _root_.OAI.LipschitzWith.integral_mul_fderiv_eq_neg (ΞΌ := volume) hw hiL hiC I,β neg_add,β integral_add hrr hir] | |
| congr 1 | |
| apply integral_congr_ae | |
| filter_upwards with x | |
| exact (inner_coordinates _ _).symm | |
| end SignedRuns | |
| namespace SignedRuns | |
| open ActualLabels FiniteLabels SignedAssembly Finset DiskMoments | |
| lemma leafSum_add (f g : List Label β β) (d : β) (p : List Label) : | |
| leafSum (fun q => f q+g q) d p = leafSum f d p+leafSum g d p := by | |
| induction d generalizing p with | |
| | zero => rfl | |
| | succ d ih => simp only [leafSum,ih,sum_add_distrib] | |
| lemma leafSum_mul_const (f : List Label β β) (c : β) (d : β) (p : List Label) : | |
| leafSum (fun q => f q*c) d p = leafSum f d p*c := by | |
| induction d generalizing p with | |
| | zero => rfl | |
| | succ d ih => simp only [leafSum,ih,sum_mul] | |
| lemma leafSum_const_mul (f : List Label β β) (c : β) (d : β) (p : List Label) : | |
| leafSum (fun q => c*f q) d p = c*leafSum f d p := by | |
| simpa only [mul_comm] using leafSum_mul_const f c d p | |
| lemma leafSum_neg (f : List Label β β) (d : β) (p : List Label) : | |
| leafSum (fun q => -(f q)) d p = -leafSum f d p := by | |
| simpa only [neg_one_mul] using leafSum_const_mul f (-1) d p | |
| lemma leafSum_mono (f g : List Label β β) (d : β) (p : List Label) | |
| (hle : β q, q.length = p.length+d β f q β€ g q) : leafSum f d p β€ leafSum g d p := by | |
| induction d generalizing p with | |
| | zero => exact hle p (by simp) | |
| | succ d ih => | |
| apply sum_le_sum | |
| intro n _ | |
| apply ih | |
| intro q hq | |
| apply hle q | |
| simp only [List.length_cons] at hq | |
| omega | |
| lemma leafSum_congr (f g : List Label β β) (d : β) (p : List Label) | |
| (he : β q, q.length = p.length+d β f q = g q) : leafSum f d p = leafSum g d p := | |
| le_antisymm (leafSum_mono f g d p (fun q hq => (he q hq).le)) | |
| (leafSum_mono g f d p (fun q hq => (he q hq).ge)) | |
| lemma leafSum_weight (h : β β β) (r : β β β) (old : Label) (x : β) (d : β) (p : List Label) : | |
| leafSum (weight h r old x) d p = weight h r old x p := by | |
| induction d generalizing p with | |
| | zero => rfl | |
| | succ d ih => | |
| simp only [leafSum,ih,weight,β mul_sum,(observation h r p.length x (p.headD old)).total,mul_one] | |
| lemma leafSum_integrable (f : List Label β β β β) (hf : β q, Integrable (f q)) | |
| (d : β) (p : List Label) : Integrable (fun x => leafSum (fun q => f q x) d p) := by | |
| induction d generalizing p with | |
| | zero => exact hf p | |
| | succ d ih => exact integrable_finsetSum _ (fun n _ => ih (n::p)) | |
| lemma integral_leafSum (f : List Label β β β β) (hf : β q, Integrable (f q)) | |
| (d : β) (p : List Label) : | |
| (β« x, leafSum (fun q => f q x) d p) = leafSum (fun q => β« x, f q x) d p := by | |
| induction d generalizing p with | |
| | zero => rfl | |
| | succ d ih => | |
| simp only [leafSum] | |
| rw [integral_finsetSum _ (fun n _ => leafSum_integrable f hf d (n::p))] | |
| exact sum_congr rfl (fun n _ => ih (n::p)) | |
| theorem history_weighted_ibp (g : β β β) (h : β β β) (r : β β β) | |
| (hg : ContDiff β 1 g) (hc : HasCompactSupport g) (hr : β k, 0 < r k) | |
| (hstep : β k, 2*r (k+1) = r k) (old : Label) (m : β) : | |
| (β« x, leafSum (fun q => weight h r old x q*divergence (fun y => potential g r y q) x) m []) = | |
| -β« x, leafSum (fun q => inner β (gradient (fun y => weight h r old y q) x) (potential g r x q)) m [] := by | |
| have hreg (q : List Label) := potential_regular hg hc hr hstep q | |
| have hint (q : List Label) : Integrable (fun x => weight h r old x q*divergence (fun y => potential g r y q) x) := by | |
| obtain β¨K,hKβ© := weight_lipschitz h r hr old q | |
| apply weighted_divergence_integrable hK _ (hreg q) | |
| intro x | |
| rw [Real.norm_eq_abs,abs_of_nonneg (weight_nonneg h r old x q)] | |
| exact weight_le_one h r old x q | |
| have hflux (q : List Label) : Integrable (fun x => inner β (gradient (fun y => weight h r old y q) x) (potential g r x q)) := by | |
| obtain β¨K,hKβ© := weight_lipschitz h r hr old q | |
| exact potential_flux_integrable hK (hreg q) | |
| rw [integral_leafSum _ hint,integral_leafSum _ hflux,β leafSum_neg] | |
| apply leafSum_congr | |
| intro q _ | |
| obtain β¨K,hKβ© := weight_lipschitz h r hr old q | |
| apply vector_weighted_ibp hK _ (hreg q) | |
| intro x | |
| rw [Real.norm_eq_abs,abs_of_nonneg (weight_nonneg h r old x q)] | |
| exact weight_le_one h r old x q | |
| /-- Averaging preserves the complete signed run-master inequality; finite | |
| history weights sum to one at every observation point. -/ | |
| theorem expected_run_master (g : β β β) (h : β β β) (r : β β β) | |
| (hg : ContDiff β 1 g) (hc : HasCompactSupport g) (hr : β k, 0 < r k) | |
| (hstep : β k, 2*r (k+1) = r k) (old : Label) (m : β) (x : β) | |
| (hd : β i j, i β€ j β DifferentiableAt β (runEnvelope g r i j) x) : | |
| βgradient (runEnvelope g r 0 m) xβ β€ | |
| 12*leafSum (fun q => weight h r old x q*((runs q).map fun a => coneContribution a.dir | |
| (gradient (runEnvelope g r a.first a.last) x)).sum) (m+1) [] := by | |
| have hh := leafSum_mono | |
| (fun q => weight h r old x q*βgradient (runEnvelope g r 0 m) xβ) | |
| (fun q => weight h r old x q*(12*((runs q).map fun a => coneContribution a.dir | |
| (gradient (runEnvelope g r a.first a.last) x)).sum)) (m+1) [] (by | |
| intro q hq | |
| cases q with | |
| | nil => simp at hq | |
| | cons n p => | |
| have hp : p.length = m := by simpa using hq | |
| apply mul_le_mul_of_nonneg_left _ (weight_nonneg h r old x (n::p)) | |
| simpa only [hp] using run_master hg hc hr hstep n p x hd) | |
| rw [leafSum_mul_const,leafSum_weight,weight,one_mul] at hh | |
| have he : (fun q => weight h r old x q*(12*((runs q).map fun a => coneContribution a.dir | |
| (gradient (runEnvelope g r a.first a.last) x)).sum)) = | |
| (fun q => 12*(weight h r old x q*((runs q).map fun a => coneContribution a.dir | |
| (gradient (runEnvelope g r a.first a.last) x)).sum)) := by funext q; ring | |
| rw [he,leafSum_const_mul] at hh | |
| exact hh | |
| end SignedRuns | |
| namespace SignedRuns | |
| open DiskMoments ActualLabels Complex | |
| lemma divergence_add {U V : β β β} {x : β} | |
| (hU : DifferentiableAt β U x) (hV : DifferentiableAt β V x) : | |
| divergence (fun y => U y+V y) x = divergence U x+divergence V x := by | |
| have hUr : DifferentiableAt β (fun y => (U y).re) x := Complex.reCLM.differentiableAt.comp x hU | |
| have hVr : DifferentiableAt β (fun y => (V y).re) x := Complex.reCLM.differentiableAt.comp x hV | |
| have hUi : DifferentiableAt β (fun y => (U y).im) x := Complex.imCLM.differentiableAt.comp x hU | |
| have hVi : DifferentiableAt β (fun y => (V y).im) x := Complex.imCLM.differentiableAt.comp x hV | |
| simp only [divergence,Complex.add_re,Complex.add_im] | |
| rw [fderiv_fun_add hUr hVr,fderiv_fun_add hUi hVi] | |
| simp only [_root_.add_apply] | |
| ring | |
| lemma divergence_scalar {f : β β β} {x : β} (hf : DifferentiableAt β f x) (n : β) : | |
| divergence (fun y => f y β’ n) x = inner β n (gradient f x) := by | |
| simp only [divergence,Complex.real_smul,Complex.mul_re,Complex.mul_im, | |
| Complex.ofReal_re,Complex.ofReal_im,zero_mul,sub_zero,add_zero] | |
| rw [fderiv_mul_const hf n.re,fderiv_mul_const hf n.im] | |
| simp only [_root_.smul_apply,smul_eq_mul] | |
| rw [real_inner_comm,inner_coordinates] | |
| simp only [gradient,InnerProductSpace.toDual_symm_apply] | |
| ring | |
| lemma listSum_diff {Ξ± : Type*} (l : List Ξ±) (V : Ξ± β β β β) {x : β} | |
| (hd : β a β l, DifferentiableAt β (V a) x) : | |
| DifferentiableAt β (fun y => (l.map fun a => V a y).sum) x := by | |
| induction l with | |
| | nil => exact differentiableAt_const 0 | |
| | cons a l ih => | |
| exact (hd a (by simp)).add (ih (fun a ha => hd a (by simp [ha]))) | |
| lemma divergence_listSum {Ξ± : Type*} (l : List Ξ±) (V : Ξ± β β β β) {x : β} | |
| (hd : β a β l, DifferentiableAt β (V a) x) : | |
| divergence (fun y => (l.map fun a => V a y).sum) x = (l.map fun a => divergence (V a) x).sum := by | |
| induction l with | |
| | nil => simp [divergence] | |
| | cons a l ih => | |
| have hs := listSum_diff l V (fun b hb => hd b (by simp [hb])) | |
| simp only [List.map_cons,List.sum_cons] | |
| rw [divergence_add (hd a (by simp)) hs,ih (fun b hb => hd b (by simp [hb]))] | |
| lemma average_diff {g : β β β} (hg : ContDiff β 1 g) (hc : HasCompactSupport g) | |
| (x : β) {t : β} (ht : 0 < t) : DifferentiableAt β (fun y => signedAverage g y t) x := by | |
| obtain β¨K,hKβ© := hg.lipschitzWith_of_hasCompactSupport hc one_ne_zero | |
| exact (hasFDerivAt_signedAverage hg (fun y => norm_fderiv_le_of_lipschitz β hK) x ht).differentiableAt | |
| /-- The divergence of the exact path potential is the complete signed sum | |
| of run gradients, with precisely the starting-baseline gradients removed. -/ | |
| lemma potential_divergence {g : β β β} {r : β β β} (hg : ContDiff β 1 g) | |
| (hgc : HasCompactSupport g) (hr : β k, 0 < r k) (p : List Label) (x : β) | |
| (hd : β i j, i β€ j β DifferentiableAt β (runEnvelope g r i j) x) : | |
| divergence (fun y => potential g r y p) x = | |
| ((runs p).map fun a => inner β (a.dir:β) | |
| (gradient (runEnvelope g r a.first a.last) x-gradient (fun y => signedAverage g y (r a.first)) x)).sum := by | |
| cases p with | |
| | nil => simp [potential,runs,divergence] | |
| | cons n p => | |
| simp_rw [potential_eq_runs] | |
| have hd' (a : Run) (ha : a β runs (n::p)) : | |
| DifferentiableAt β (fun y => runEnvelope g r a.first a.last y-signedAverage g y (r a.first)) x := | |
| (hd a.first a.last (runs_bounds n p a ha).1).sub (average_diff hg hgc x (hr a.first)) | |
| rw [divergence_listSum _ _ (fun a ha => (hd' a ha).smul_const (a.dir:β))] | |
| apply congrArg List.sum | |
| apply List.map_congr_left | |
| intro a ha | |
| rw [divergence_scalar (hd' a ha)] | |
| congr 1 | |
| simp only [gradient] | |
| rw [fderiv_fun_sub (hd a.first a.last (runs_bounds n p a ha).1) (average_diff hg hgc x (hr a.first)),map_sub] | |
| end SignedRuns | |
| namespace SignedRuns | |
| open DiskMoments ActualLabels Finset ConeCoordinates | |
| lemma radius_in_run_bin (r : β β β) (hstep : β k, 2*r (k+1) = r k) | |
| {i j : β} (hij : i β€ j) {t : β} (ht : t β Icc (r j) (2*r i)) : | |
| β k β Set.Icc i j, t β Icc (r k) (2*r k) := by | |
| obtain β¨l,hl,htlβ© := radius_in_bin (fun k => r (i+k)) | |
| (fun k => by simpa [Nat.add_assoc] using hstep (i+k)) (j-i) | |
| (by simpa only [Nat.add_sub_of_le hij,Nat.add_zero] using ht) | |
| exact β¨i+l,β¨by omega,by omegaβ©,htlβ© | |
| lemma attaining_endpoint {g : β β β} {r : β β β} | |
| (hr : β k, 0 < r k) (hstep : β k, 2*r (k+1) = r k) | |
| {i j k : β} (hik : i β€ k) (hkj : k β€ j) {x : β} {t : β} | |
| (ht : t β Icc (r k) (2*r k)) | |
| (hmax : β s β Icc (r j) (2*r i), signedAverage g x s β€ signedAverage g x t) : | |
| PhysicalEndpointRadius g (r k) x t := by | |
| refine β¨ht,Or.inr (Or.inr ?_)β© | |
| intro s hs | |
| apply hmax | |
| constructor | |
| Β· exact (radius_antitone r hr hstep hkj).trans hs.1 | |
| Β· have := radius_antitone r hr hstep hik | |
| linarith [hs.2] | |
| lemma attaining_interior {g : β β β} {r : β β β} | |
| (hr : β k, 0 < r k) (hstep : β k, 2*r (k+1) = r k) | |
| {i j k : β} (hik : i < k) (hkj : k < j) {x : β} {t : β} | |
| (ht : t β Icc (r k) (2*r k)) | |
| (hmax : β s β Icc (r j) (2*r i), signedAverage g x s β€ signedAverage g x t) : | |
| PhysicalNeighborhoodRadius g (r k) x t := by | |
| refine β¨ht,?_β© | |
| intro s _ hs | |
| apply hmax | |
| have hs' := abs_le.mp hs | |
| have hlow := radius_antitone r hr hstep (show k+1 β€ j by omega) | |
| have hhigh := radius_antitone r hr hstep (show i+1 β€ k by omega) | |
| constructor <;> linarith [hstep k,hstep i,hr k,ht.1,ht.2] | |
| def unfavorable (n : Label) (z : β) : β := | |
| max 0 (-inner β (axis n 1) z)+max 0 (-inner β (axis n (-1)) z) | |
| lemma unfavorable_nonneg (n : Label) (z : β) : 0 β€ unfavorable n z := | |
| add_nonneg (le_max_left _ _) (le_max_left _ _) | |
| lemma unfavorable_le_norm (n : Label) (z : β) : unfavorable n z β€ 2*βzβ := by | |
| have h (s : β) (hs : s^2 = 1) : max 0 (-inner β (axis n s) z) β€ βzβ := by | |
| apply max_le (norm_nonneg _) | |
| have hh := abs_real_inner_le_norm (axis (n:β) s) z | |
| rw [axis_norm (label_unit n) hs,one_mul] at hh | |
| exact (neg_le_abs _).trans hh | |
| have hp := h 1 (by norm_num) | |
| have hm := h (-1) (by norm_num) | |
| unfold unfavorable | |
| linarith | |
| /-- The exact unfavorable run term is charged either to one interior bin or | |
| one of its two end bins; padding by nonnegative costs permits summing runs. -/ | |
| lemma run_unfavorable_bound {g : β β β} {r : β β β} | |
| (hg : ContDiff β 1 g) (hc : HasCompactSupport g) | |
| (hr : β k, 0 < r k) (hstep : β k, 2*r (k+1) = r k) | |
| (H : β β Label β β) (J : β β β) (hH : β k n, 0 β€ H k n) (hJ : β k, 0 β€ J k) | |
| (x : β) (n : Label) {i j : β} (hij : i β€ j) | |
| (hd : DifferentiableAt β (runEnvelope g r i j) x) | |
| (hinterior : β k t, PhysicalNeighborhoodRadius g (r k) x t β | |
| unfavorable n (gradient (fun y => signedAverage g y t) x) β€ H k n) | |
| (hend : β k t, PhysicalEndpointRadius g (r k) x t β | |
| βgradient (fun y => signedAverage g y t) xβ β€ J k) : | |
| unfavorable n (gradient (runEnvelope g r i j) x) β€ | |
| (β k β Icc i j, H k n)+2*(J i+J j) := by | |
| obtain β¨t,ht,he,hmβ© := runEnvelope_attains g r hg hr hstep hij x | |
| rw [run_gradient_touching hg hc hr hd ht he] | |
| obtain β¨k,hk,hktβ© := radius_in_run_bin r hstep hij ht | |
| have hs : 0 β€ β k β Icc i j, H k n := sum_nonneg (fun _ _ => hH _ _) | |
| by_cases hki : k = i | |
| Β· subst k | |
| have hb := (unfavorable_le_norm n _).trans (mul_le_mul_of_nonneg_left | |
| (hend i t (attaining_endpoint hr hstep le_rfl hij hkt hm)) (by norm_num : (0:β) β€ 2)) | |
| linarith [hJ j] | |
| by_cases hkj : k = j | |
| Β· subst k | |
| have hb := (unfavorable_le_norm n _).trans (mul_le_mul_of_nonneg_left | |
| (hend j t (attaining_endpoint hr hstep hij le_rfl hkt hm)) (by norm_num : (0:β) β€ 2)) | |
| linarith [hJ i] | |
| have hik := hk.1 | |
| have hkj' := hk.2 | |
| have hb := hinterior k t (attaining_interior hr hstep (by omega) (by omega) hkt hm) | |
| have hsum : H k n β€ β l β Icc i j, H l n := single_le_sum (fun l _ => hH l n) (Finset.mem_Icc.mpr hk) | |
| linarith [hJ i,hJ j] | |
| end SignedRuns | |
| namespace SignedRuns | |
| open ActualLabels FiniteLabels Finset | |
| lemma leafSum_succ_last {E : Type*} [AddCommMonoid E] (f : List Label β E) | |
| (m : β) (p : List Label) : | |
| leafSum f (m+1) p = leafSum (fun q => β n, f (n::q)) m p := by | |
| induction m generalizing p with | |
| | zero => rfl | |
| | succ m ih => | |
| change (β n, leafSum f (m+1) (n::p)) = | |
| β n, leafSum (fun q => β j, f (j::q)) m (n::p) | |
| simp_rw [ih] | |
| lemma leafSum_sum {E : Type*} [AddCommMonoid E] {ΞΉ : Type*} | |
| (s : Finset ΞΉ) (f : ΞΉ β List Label β E) (m : β) (p : List Label) : | |
| leafSum (fun q => β i β s, f i q) m p = β i β s, leafSum (f i) m p := by | |
| induction m generalizing p with | |
| | zero => rfl | |
| | succ m ih => simp only [leafSum,ih]; exact sum_comm | |
| /-- The exact head law obtained from the genuine finite-history products. -/ | |
| lemma leafSum_headLaw (h : β β β) (r : β β β) (old : Label) (x : β) | |
| (m : β) (F : Label β β) : | |
| leafSum (fun q => weight h r old x q*F (q.headD old)) m [] = | |
| expect (before h r old x m) F := by | |
| induction m generalizing F with | |
| | zero => simp only [leafSum,weight,List.headD_nil,one_mul,before,expect_delta] | |
| | succ m ih => | |
| rw [leafSum_succ_last,before_move,expect_move] | |
| have he (q : List Label) : | |
| (β n, weight h r old x (n::q)*F ((n::q).headD old)) = | |
| weight h r old x q*expect (observation h r q.length x (q.headD old)) F := by | |
| simp only [weight,List.headD_cons,FiniteLabels.expect,mul_assoc,mul_sum] | |
| simp_rw [he] | |
| have hc := leafSum_congr | |
| (fun q => weight h r old x q*expect (observation h r q.length x (q.headD old)) F) | |
| (fun q => weight h r old x q*expect (observation h r m x (q.headD old)) F) m [] | |
| (by | |
| intro q hq | |
| have hqm : q.length = m := by simpa using hq | |
| rw [hqm]) | |
| rw [hc] | |
| exact ih (fun n => FiniteLabels.expect (observation h r m x n) F) | |
| /-- Additive reward along a reversed history, with its true previous state. -/ | |
| def pathReward (old : Label) (A : β β Label β Label β β) : List Label β β | |
| | [] => 0 | |
| | n::p => pathReward old A p+A p.length (p.headD old) n | |
| lemma leafSum_pathReward (h : β β β) (r : β β β) (old : Label) (x : β) | |
| (A : β β Label β Label β β) (m : β) : | |
| leafSum (fun q => weight h r old x q*pathReward old A q) m [] = | |
| β k β range m, expect (before h r old x k) | |
| (fun n => expect (observation h r k x n) (A k n)) := by | |
| induction m with | |
| | zero => simp [leafSum,pathReward] | |
| | succ m ih => | |
| rw [leafSum_succ_last,sum_range_succ] | |
| have he (q : List Label) : | |
| (β n, weight h r old x (n::q)*pathReward old A (n::q)) = | |
| weight h r old x q*pathReward old A q+ | |
| weight h r old x q*expect (observation h r q.length x (q.headD old)) (A q.length (q.headD old)) := by | |
| simp only [weight,pathReward,mul_add,sum_add_distrib,β sum_mul,β mul_sum,FiniteLabels.expect,mul_assoc] | |
| rw [(observation h r q.length x (q.headD old)).total,one_mul] | |
| simp_rw [he] | |
| rw [leafSum_add,ih] | |
| congr 1 | |
| have hc := leafSum_congr | |
| (fun q => weight h r old x q*expect (observation h r q.length x (q.headD old)) (A q.length (q.headD old))) | |
| (fun q => weight h r old x q*expect (observation h r m x (q.headD old)) (A m (q.headD old))) m [] | |
| (by | |
| intro q hq | |
| have hqm : q.length = m := by simpa using hq | |
| rw [hqm]) | |
| rw [hc] | |
| exact leafSum_headLaw h r old x m (fun n => FiniteLabels.expect (observation h r m x n) (A m n)) | |
| lemma pathReward_add (old : Label) (A B : β β Label β Label β β) (q : List Label) : | |
| pathReward old (fun k n j => A k n j+B k n j) q = | |
| pathReward old A q+pathReward old B q := by | |
| induction q with | |
| | nil => simp [pathReward] | |
| | cons n p ih => simp only [pathReward,ih]; ring | |
| lemma pathReward_nonneg (old : Label) (A : β β Label β Label β β) | |
| (hA : β k n j, 0 β€ A k n j) (q : List Label) : 0 β€ pathReward old A q := by | |
| induction q with | |
| | nil => exact le_rfl | |
| | cons n p ih => exact add_nonneg ih (hA _ _ _) | |
| end SignedRuns | |
| namespace SignedRuns | |
| open ActualLabels FiniteLabels Finset | |
| lemma run_span_sum (H : β β Label β β) (old : Label) (p : List Label) : | |
| ((runs p).map fun a => β k β Icc a.first a.last, H k a.dir).sum = | |
| pathReward old (fun k _ n => H k n) p := by | |
| cases p with | |
| | nil => rfl | |
| | cons n p => | |
| induction p generalizing n with | |
| | nil => simp [runs,closedRuns,activeStart,pathReward] | |
| | cons n' p ih => | |
| by_cases hn : n = n' | |
| Β· subst n | |
| have hsum : (β k β Icc (activeStart (n'::p)) (p.length+1), H k n') = | |
| (β k β Icc (activeStart (n'::p)) p.length, H k n')+H (p.length+1) n' := by | |
| exact sum_Icc_succ_top ((activeStart_le n' p).trans (Nat.le_succ _)) _ | |
| have hh := ih n' | |
| simp only [runs,List.map_cons,List.sum_cons] at hh | |
| simp only [runs,closedRuns,activeStart,ite_true,List.length_cons,List.map_cons,List.sum_cons,pathReward] | |
| rw [hsum] | |
| simp only [pathReward] at hh | |
| linarith | |
| Β· have hh := ih n' | |
| simp only [runs,List.map_cons,List.sum_cons] at hh | |
| simp only [runs,closedRuns,activeStart,hn,ite_false,List.length_cons,List.map_cons,List.sum_cons,pathReward, | |
| Finset.Icc_self,sum_singleton] | |
| simp only [pathReward] at hh | |
| linarith | |
| def startReward (J : β β β) : β β Label β Label β β | |
| | 0,_,_ => J 0 | |
| | k+1,n,j => if j = n then 0 else J (k+1) | |
| def boundaryReward (J : β β β) : β β Label β Label β β | |
| | 0,_,_ => J 0 | |
| | k+1,n,j => if j = n then 0 else J k+J (k+1) | |
| lemma run_start_sum (J : β β β) (old : Label) (p : List Label) : | |
| ((runs p).map fun a => J a.first).sum = pathReward old (startReward J) p := by | |
| cases p with | |
| | nil => rfl | |
| | cons n p => | |
| induction p generalizing n with | |
| | nil => simp [runs,activeStart,closedRuns,pathReward,startReward] | |
| | cons n' p ih => | |
| have hh := ih n' | |
| simp only [runs,List.map_cons,List.sum_cons] at hh | |
| simp only [pathReward,startReward] at hh | |
| by_cases hn : n = n' | |
| Β· subst n | |
| simpa only [runs,closedRuns,activeStart,ite_true,List.length_cons,List.map_cons,List.sum_cons, | |
| pathReward,startReward,List.headD_cons,add_zero] using hh | |
| Β· simp only [runs,closedRuns,activeStart,hn,ite_false,List.length_cons,List.map_cons,List.sum_cons, | |
| pathReward,startReward,List.headD_cons] | |
| linarith | |
| lemma run_boundary_sum (J : β β β) (old n : Label) (p : List Label) : | |
| ((runs (n::p)).map fun a => J a.first+J a.last).sum = | |
| pathReward old (boundaryReward J) (n::p)+J p.length := by | |
| induction p generalizing n with | |
| | nil => simp [runs,activeStart,closedRuns,pathReward,boundaryReward] | |
| | cons n' p ih => | |
| have hh := ih n' | |
| simp only [runs,List.map_cons,List.sum_cons,pathReward,boundaryReward] at hh | |
| by_cases hn : n = n' | |
| Β· subst n | |
| simp only [runs,closedRuns,activeStart,ite_true,List.length_cons,List.map_cons,List.sum_cons, | |
| pathReward,boundaryReward,List.headD_cons] | |
| linarith | |
| Β· simp only [runs,closedRuns,activeStart,hn,ite_false,List.length_cons,List.map_cons,List.sum_cons, | |
| pathReward,boundaryReward,List.headD_cons] | |
| linarith | |
| lemma startReward_nonneg (J : β β β) (hJ : β k, 0 β€ J k) (k : β) (n j : Label) : | |
| 0 β€ startReward J k n j := by | |
| cases k with | |
| | zero => exact hJ 0 | |
| | succ k => simp only [startReward]; split_ifs <;> first | exact le_rfl | exact hJ _ | |
| lemma boundaryReward_nonneg (J : β β β) (hJ : β k, 0 β€ J k) (k : β) (n j : Label) : | |
| 0 β€ boundaryReward J k n j := by | |
| cases k with | |
| | zero => exact hJ 0 | |
| | succ k => simp only [boundaryReward]; split_ifs <;> first | exact le_rfl | exact add_nonneg (hJ _) (hJ _) | |
| end SignedRuns | |
| end | |
| end OAI | |