Download data/lean/OAI/Analysis/DiskMaximal/Runs.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 31.7 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Analysis/DiskMaximal/Runs.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Analysis/DiskMaximal/Runs.lean
-
curl -L -o Runs.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Analysis/DiskMaximal/Runs.lean
31.7 kB
| import OAI.Analysis.DiskMaximal.Potentials | |
| 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 RadiusEnvelope ActualLabels Finset | |
| variable (g : β β β) (r : β β β) | |
| def runEnvelope (i j : β) (x : β) : β := | |
| envelope (fun t y => signedAverage g y t) (r j) (2*r i) x | |
| lemma radius_antitone (hr : β k, 0 < r k) (hstep : β k, 2*r (k+1) = r k) : Antitone r := by | |
| apply antitone_nat_of_succ_le | |
| intro k | |
| have := hr (k+1) | |
| linarith [hstep k] | |
| lemma runEnvelope_attains (hg : ContDiff β 1 g) (hr : β k, 0 < r k) | |
| (hstep : β k, 2*r (k+1) = r k) {i j : β} (hij : i β€ j) (x : β) : | |
| β t β Icc (r j) (2*r i), runEnvelope g r i j x = signedAverage g x t β§ | |
| β s β Icc (r j) (2*r i), signedAverage g x s β€ signedAverage g x t := by | |
| apply attains _ x (signedAverage_radius_continuousOn hg x (hr j)) | |
| have := radius_antitone r hr hstep hij | |
| linarith [hr i] | |
| lemma runEnvelope_le_next (hg : ContDiff β 1 g) (hr : β k, 0 < r k) | |
| (hstep : β k, 2*r (k+1) = r k) {i j : β} (hij : i β€ j) (x : β) : | |
| runEnvelope g r i j x β€ runEnvelope g r i (j+1) x := by | |
| obtain β¨t,ht,he,_β© := runEnvelope_attains g r hg hr hstep hij x | |
| rw [he] | |
| apply le_envelope β¨(radius_antitone r hr hstep (Nat.le_succ j)).trans ht.1,ht.2β© x | |
| (signedAverage_radius_continuousOn hg x (hr (j+1))) | |
| lemma runEnvelope_extension_bound (hg : ContDiff β 1 g) (hr : β k, 0 < r k) | |
| (hstep : β k, 2*r (k+1) = r k) {i j : β} (hij : i β€ j) (x : β) {V : β} | |
| (hV : β t t', 0 < t β t β€ 4*r (j+1) β 0 < t' β t' β€ 4*r (j+1) β | |
| |signedAverage g x t-signedAverage g x t'| β€ V) : | |
| |runEnvelope g r i (j+1) x-runEnvelope g r i j x| β€ V := by | |
| have hV0 : 0 β€ V := by | |
| have hh := hr (j+1) | |
| simpa using hV (r (j+1)) (r (j+1)) hh (by linarith) hh (by linarith) | |
| have h0 := runEnvelope_le_next g r hg hr hstep hij x | |
| rw [abs_of_nonneg (sub_nonneg.mpr h0)] | |
| obtain β¨t,ht,he,_β© := runEnvelope_attains g r hg hr hstep (hij.trans (Nat.le_succ j)) x | |
| rw [he] | |
| by_cases htj : r j β€ t | |
| Β· have hh := le_envelope (u := fun t y => signedAverage g y t) β¨htj,ht.2β© x | |
| (signedAverage_radius_continuousOn hg x (hr j)) | |
| change signedAverage g x t β€ runEnvelope g r i j x at hh | |
| linarith | |
| Β· have hb : signedAverage g x (r j) β€ runEnvelope g r i j x := by | |
| change signedAverage g x (r j) β€ envelope (fun t y => signedAverage g y t) (r j) (2*r i) x | |
| apply le_envelope (u := fun t y => signedAverage g y t) (a := r j) (b := 2*r i) (r := r j) β¨le_rfl,?_β© x (signedAverage_radius_continuousOn hg x (hr j)) | |
| have := radius_antitone r hr hstep hij | |
| linarith [hr i] | |
| have hh := hV t (r j) ((hr (j+1)).trans_le ht.1) | |
| (by linarith [hstep j,hr (j+1)]) (hr j) (by linarith [hstep j,hr (j+1)]) | |
| linarith [le_abs_self (signedAverage g x t-signedAverage g x (r j))] | |
| lemma runEnvelope_new_bound (hg : ContDiff β 1 g) (hr : β k, 0 < r k) | |
| (hstep : β k, 2*r (k+1) = r k) (j : β) (x : β) {V : β} | |
| (hV : β t t', 0 < t β t β€ 4*r j β 0 < t' β t' β€ 4*r j β | |
| |signedAverage g x t-signedAverage g x t'| β€ V) : | |
| |runEnvelope g r j j x-signedAverage g x (r j)| β€ V := by | |
| obtain β¨t,ht,he,_β© := runEnvelope_attains g r hg hr hstep le_rfl x | |
| rw [he] | |
| exact hV t (r j) ((hr j).trans_le ht.1) (by linarith [hr j,ht.2]) (hr j) (by linarith [hr j]) | |
| /-- Reversed chronological histories. The active run's start is retained when | |
| its new label agrees, and is reset to the new time at a switch. -/ | |
| def activeStart : List Label β β | |
| | [] => 0 | |
| | [_] => 0 | |
| | n::old::p => if n = old then activeStart (old::p) else (old::p).length | |
| lemma activeStart_le (n : Label) (p : List Label) : activeStart (n::p) β€ p.length := by | |
| induction p generalizing n with | |
| | nil => simp [activeStart] | |
| | cons old p ih => | |
| dsimp only [activeStart] | |
| split_ifs | |
| Β· exact (ih old).trans (by simp) | |
| Β· rfl | |
| /-- The exact closed-prefix vector potential, updated without ever taking the | |
| absolute size of an old large-radius envelope. -/ | |
| def potential (x : β) : List Label β β | |
| | [] => 0 | |
| | [n] => (runEnvelope g r 0 0 x-signedAverage g x (r 0)) β’ (n:β) | |
| | n::old::p => potential x (old::p)+ | |
| (if n = old then (runEnvelope g r (activeStart (old::p)) (p.length+1) x- | |
| runEnvelope g r (activeStart (old::p)) p.length x) β’ (n:β) | |
| else (runEnvelope g r (p.length+1) (p.length+1) x- | |
| signedAverage g x (r (p.length+1))) β’ (n:β)) | |
| lemma potential_increment (hg : ContDiff β 1 g) (hr : β k, 0 < r k) | |
| (hstep : β k, 2*r (k+1) = r k) (x : β) (v : β β β) | |
| (hv : β k t t', 0 < t β t β€ 4*r k β 0 < t' β t' β€ 4*r k β | |
| |signedAverage g x t-signedAverage g x t'| β€ v k) | |
| (n : Label) (p : List Label) : βpotential g r x (n::p)-potential g r x pβ β€ v p.length := by | |
| cases p with | |
| | nil => | |
| simp only [potential,List.length_nil,sub_zero,norm_smul,Real.norm_eq_abs,label_unit,mul_one] | |
| exact runEnvelope_new_bound g r hg hr hstep 0 x (hv 0) | |
| | cons old p => | |
| simp only [potential,add_sub_cancel_left,List.length_cons] | |
| split_ifs | |
| Β· simp only [norm_smul,Real.norm_eq_abs,label_unit,mul_one] | |
| exact runEnvelope_extension_bound g r hg hr hstep (activeStart_le old p) x (hv (p.length+1)) | |
| Β· simp only [norm_smul,Real.norm_eq_abs,label_unit,mul_one] | |
| exact runEnvelope_new_bound g r hg hr hstep (p.length+1) x (hv (p.length+1)) | |
| theorem potential_continuation_bound (hg : ContDiff β 1 g) (hr : β k, 0 < r k) | |
| (hstep : β k, 2*r (k+1) = r k) (x : β) (v : β β β) | |
| (hv : β k t t', 0 < t β t β€ 4*r k β 0 < t' β t' β€ 4*r k β | |
| |signedAverage g x t-signedAverage g x t'| β€ v k) | |
| (p q : List Label) : βpotential g r x (q++p)-potential g r x pβ β€ | |
| β k β Ico p.length (p.length+q.length), v k := by | |
| induction q with | |
| | nil => simp | |
| | cons n q ih => | |
| have htri : βpotential g r x ((n::q)++p)-potential g r x pβ β€ | |
| βpotential g r x (n::(q++p))-potential g r x (q++p)β+ | |
| βpotential g r x (q++p)-potential g r x pβ := by | |
| simpa only [sub_add_sub_cancel,List.cons_append] using norm_add_le | |
| (potential g r x (n::(q++p))-potential g r x (q++p)) | |
| (potential g r x (q++p)-potential g r x p) | |
| have hi := potential_increment g r hg hr hstep x v hv n (q++p) | |
| apply htri.trans | |
| rw [List.length_cons,Nat.add_succ,sum_Ico_succ_top (by omega : p.length β€ p.length+q.length)] | |
| simpa only [List.length_append,Nat.add_comm,add_comm] using add_le_add hi ih | |
| end SignedRuns | |
| namespace SignedRuns | |
| open SignedAssembly FiniteLabels ActualLabels Finset | |
| variable (g : β β β) (r : β β β) (x : β) | |
| variable (J : β β Label β RowJet Label β) (v : β β β) | |
| /-- The actual closed-prefix potentials at the leaves, with the stochastic | |
| row jet at every observation time. -/ | |
| def jet : β β List Label β Label β JetTree Label β | |
| | 0,p,_ => .leaf (potential g r x p) | |
| | d+1,p,n => .branch (J p.length n) (potential g r x p) | |
| (β k β Ico p.length (p.length+d+1), v k) (fun a => jet d (a::p) a) | |
| lemma jet_terminalBound (d : β) (p : List Label) (old : Label) (c : β) (B : β) | |
| (h : β q : List Label, q.length = d β βpotential g r x (q++p)-cβ β€ B) : | |
| TerminalBound (jet g r x J v d p old) c B := by | |
| induction d generalizing p old with | |
| | zero => simpa only [jet,TerminalBound,List.nil_append] using h [] rfl | |
| | succ d ih => | |
| intro n | |
| apply ih | |
| intro q hq | |
| have hh := h (q++[n]) (by simp only [List.length_append,List.length_singleton,hq]) | |
| simpa only [List.append_assoc,List.singleton_append] using hh | |
| lemma jet_controlled (hg : ContDiff β 1 g) (hr : β k, 0 < r k) | |
| (hstep : β k, 2*r (k+1) = r k) | |
| (hv : β k t t', 0 < t β t β€ 4*r k β 0 < t' β t' β€ 4*r k β | |
| |DiskMoments.signedAverage g x t-DiskMoments.signedAverage g x t'| β€ v k) | |
| (d : β) (p : List Label) (old : Label) : Controlled (jet g r x J v d p old) := by | |
| induction d generalizing p old with | |
| | zero => trivial | |
| | succ d ih => | |
| constructor | |
| Β· intro n | |
| apply jet_terminalBound | |
| intro q hq | |
| have hh := potential_continuation_bound g r hg hr hstep x v hv p (q++[n]) | |
| simpa only [List.append_assoc,List.singleton_append,List.length_append,List.length_singleton,hq,Nat.add_assoc] using hh | |
| Β· intro n | |
| exact ih (n::p) n | |
| /-- Backward expected reward for an arbitrary time-dependent finite Markov law. -/ | |
| def rewardCost (reward : β β Label β β) : β β β β Label β β | |
| | _,0,_ => 0 | |
| | k,d+1,n => reward k n+expect (J k n).law (fun a => rewardCost reward (k+1) d a) | |
| lemma jet_cost (d : β) (p : List Label) (old : Label) (m : β) (hm : p.length+d = m) : | |
| cost (jet g r x J v d p old) = rewardCost J | |
| (fun k n => (β a, β(J k n).grad aβ)*(β l β Ico k m, v l)) p.length d old := by | |
| induction d generalizing p old with | |
| | zero => rfl | |
| | succ d ih => | |
| simp only [jet,cost,rewardCost] | |
| have htop : p.length+d+1 = m := by omega | |
| rw [htop] | |
| congr 1 | |
| apply sum_congr rfl | |
| intro a _ | |
| rw [ih (a::p) a (by simp only [List.length_cons]; omega)] | |
| rfl | |
| lemma expect_rewardCost (reward : β β Label β β) (ΞΌ : β β Law Label) | |
| (hΞΌ : β k, ΞΌ (k+1) = move (ΞΌ k) (fun n => (J k n).law)) (d k : β) : | |
| expect (ΞΌ k) (rewardCost J reward k d) = | |
| β i β Ico k (k+d), expect (ΞΌ i) (reward i) := by | |
| induction d generalizing k with | |
| | zero => simp [rewardCost,FiniteLabels.expect] | |
| | succ d ih => | |
| change expect (ΞΌ k) (fun n => reward k n+expect (J k n).law (fun a => rewardCost J reward (k+1) d a)) = _ | |
| rw [expect_add,β expect_move,β hΞΌ k,ih] | |
| rw [sum_Ico_eq_sum_range,sum_Ico_eq_sum_range] | |
| simp only [Nat.add_sub_cancel_left,Nat.add_assoc,Nat.add_sub_cancel_left] | |
| rw [sum_range_succ'] | |
| simp only [Nat.add_zero,Nat.add_left_comm,add_comm,Nat.add_sub_cancel_right] | |
| /-- Signed finite-history flux with the actual run potential and the exact | |
| forward stochastic marginal law. No old large-radius envelope is priced. -/ | |
| theorem run_signed_flux_bound (hg : ContDiff β 1 g) (hr : β k, 0 < r k) | |
| (hstep : β k, 2*r (k+1) = r k) | |
| (hv : β k t t', 0 < t β t β€ 4*r k β 0 < t' β t' β€ 4*r k β | |
| |DiskMoments.signedAverage g x t-DiskMoments.signedAverage g x t'| β€ v k) | |
| (m : β) (old : Label) (ΞΌ : β β Law Label) (hΞΌ0 : ΞΌ 0 = delta old) | |
| (hΞΌ : β k, ΞΌ (k+1) = move (ΞΌ k) (fun n => (J k n).law)) : | |
| |pathFlux (jet g r x J v m [] old) 1 0| β€ | |
| β k β range m, expect (ΞΌ k) (fun n => β a, β(J k n).grad aβ)* | |
| (β l β Ico k m, v l) := by | |
| have hh := signed_flux_bound _ (jet_controlled g r x J v hg hr hstep hv m [] old) | |
| rw [jet_cost g r x J v m [] old m (by simp)] at hh | |
| have he := expect_rewardCost J | |
| (fun k n => (β a, β(J k n).grad aβ)*(β l β Ico k m, v l)) ΞΌ hΞΌ m 0 | |
| rw [hΞΌ0,expect_delta] at he | |
| simp only [Nat.zero_add,Nat.Ico_zero_eq_range] at he | |
| simp only [List.length_nil] at hh | |
| rw [he] at hh | |
| simpa only [FiniteLabels.expect,β mul_assoc,β sum_mul] using hh | |
| end SignedRuns | |
| namespace SignedRuns | |
| open DiskMoments RadiusEnvelope ActualLabels ConeCoordinates | |
| structure Run where | |
| dir : Label | |
| first : β | |
| last : β | |
| /-- Completed runs, in reverse chronological order. -/ | |
| def closedRuns : List Label β List Run | |
| | [] => [] | |
| | [_] => [] | |
| | n::old::p => if n = old then closedRuns (old::p) | |
| else β¨old,activeStart (old::p),p.lengthβ©::closedRuns (old::p) | |
| def runs : List Label β List Run | |
| | [] => [] | |
| | n::p => β¨n,activeStart (n::p),p.lengthβ©::closedRuns (n::p) | |
| lemma closedRuns_bounds (n : Label) (p : List Label) : | |
| β a β closedRuns (n::p), a.first β€ a.last β§ a.last < p.length := by | |
| induction p generalizing n with | |
| | nil => simp [closedRuns] | |
| | cons old p ih => | |
| simp only [closedRuns] | |
| split_ifs with h | |
| Β· intro a ha | |
| exact β¨(ih old a ha).1,(ih old a ha).2.trans (by simp)β© | |
| Β· intro a ha | |
| rcases List.mem_cons.mp ha with ha | ha | |
| Β· subst a | |
| exact β¨activeStart_le old p,by simpβ© | |
| Β· exact β¨(ih old a ha).1,(ih old a ha).2.trans (by simp)β© | |
| lemma runs_bounds (n : Label) (p : List Label) : | |
| β a β runs (n::p), a.first β€ a.last β§ a.last β€ p.length := by | |
| intro a ha | |
| rcases List.mem_cons.mp ha with ha | ha | |
| Β· subst a | |
| exact β¨activeStart_le n p,le_rflβ© | |
| Β· exact β¨(closedRuns_bounds n p a ha).1,(closedRuns_bounds n p a ha).2.leβ© | |
| lemma runs_cover (n : Label) (p : List Label) (k : β) (hk : k β€ p.length) : | |
| β a β runs (n::p), a.first β€ k β§ k β€ a.last := by | |
| induction p generalizing n k with | |
| | nil => | |
| have hk0 : k = 0 := by simpa using hk | |
| subst k | |
| exact β¨β¨n,0,0β©,by simp [runs,activeStart],le_rfl,le_rflβ© | |
| | cons old p ih => | |
| by_cases h : n = old | |
| Β· subst n | |
| by_cases hs : activeStart (old::p) β€ k | |
| Β· refine β¨β¨old,activeStart (old::p),p.length+1β©,?_,hs,?_β© | |
| Β· simp [runs,activeStart] | |
| Β· simpa using hk | |
| Β· have hk' : k β€ p.length := (le_of_not_ge hs).trans (activeStart_le old p) | |
| obtain β¨a,ha,hak,hkaβ© := ih old k hk' | |
| have hac : a β closedRuns (old::p) := by | |
| rcases List.mem_cons.mp ha with ha | ha | |
| Β· subst a | |
| exact False.elim (hs hak) | |
| Β· exact ha | |
| exact β¨a,by simp [runs,closedRuns,hac],hak,hkaβ© | |
| Β· by_cases hk' : k β€ p.length | |
| Β· obtain β¨a,ha,hak,hkaβ© := ih old k hk' | |
| exact β¨a,by simpa only [runs,closedRuns,h,ite_false,List.mem_cons] using Or.inr ha,hak,hkaβ© | |
| Β· have he : k = p.length+1 := by simp only [List.length_cons] at hk; omega | |
| subst k | |
| exact β¨β¨n,p.length+1,p.length+1β©,by simp [runs,activeStart,h],le_rfl,le_rflβ© | |
| lemma potential_eq_runs (g : β β β) (r : β β β) (x : β) (n : Label) (p : List Label) : | |
| potential g r x (n::p) = ((runs (n::p)).map fun a => | |
| (runEnvelope g r a.first a.last x-signedAverage g x (r a.first)) β’ (a.dir:β)).sum := by | |
| induction p generalizing n with | |
| | nil => simp [potential,runs,closedRuns,activeStart] | |
| | cons old p ih => | |
| rw [potential,ih] | |
| by_cases h : n = old | |
| Β· subst n | |
| simp only [runs,closedRuns,activeStart,ite_true,List.length_cons,List.map_cons,List.sum_cons] | |
| module | |
| Β· simp only [runs,closedRuns,activeStart,h,ite_false,List.length_cons,List.map_cons,List.sum_cons] | |
| abel | |
| lemma radius_in_bin (r : β β β) | |
| (hstep : β k, 2*r (k+1) = r k) (j : β) {t : β} (ht : t β Icc (r j) (2*r 0)) : | |
| β k β€ j, t β Icc (r k) (2*r k) := by | |
| induction j with | |
| | zero => exact β¨0,le_rfl,htβ© | |
| | succ j ih => | |
| by_cases h : r j β€ t | |
| Β· obtain β¨k,hk,hktβ© := ih β¨h,ht.2β© | |
| exact β¨k,hk.trans (Nat.le_succ j),hktβ© | |
| Β· exact β¨j+1,le_rfl,ht.1,by linarith [hstep j]β© | |
| lemma runs_cover_radius (r : β β β) (hr : β k, 0 < r k) | |
| (hstep : β k, 2*r (k+1) = r k) (n : Label) (p : List Label) {t : β} | |
| (ht : t β Icc (r p.length) (2*r 0)) : | |
| β a β runs (n::p), t β Icc (r a.last) (2*r a.first) := by | |
| obtain β¨k,hk,hktβ© := radius_in_bin r hstep p.length ht | |
| obtain β¨a,ha,hi,hjβ© := runs_cover n p k hk | |
| refine β¨a,ha,?_,?_β© | |
| Β· exact (radius_antitone r hr hstep hj).trans hkt.1 | |
| Β· have hh := radius_antitone r hr hstep hi | |
| linarith [hkt.2] | |
| /-- Every history has an actually attaining winning run. No radius selection | |
| is differentiated. -/ | |
| lemma winning_run (g : β β β) (r : β β β) (hg : ContDiff β 1 g) | |
| (hr : β k, 0 < r k) (hstep : β k, 2*r (k+1) = r k) | |
| (n : Label) (p : List Label) (x : β) : | |
| β a β runs (n::p), β t β Icc (r a.last) (2*r a.first), | |
| runEnvelope g r 0 p.length x = signedAverage g x t β§ | |
| runEnvelope g r a.first a.last x = signedAverage g x t := by | |
| obtain β¨t,ht,he,hmaxβ© := runEnvelope_attains g r hg hr hstep (Nat.zero_le _) x | |
| obtain β¨a,ha,hatβ© := runs_cover_radius r hr hstep n p ht | |
| refine β¨a,ha,t,hat,he,le_antisymm ?_ ?_β© | |
| Β· obtain β¨s,hs,hsval,_β© := runEnvelope_attains g r hg hr hstep (runs_bounds n p a ha).1 x | |
| rw [hsval] | |
| apply hmax | |
| constructor | |
| Β· exact (radius_antitone r hr hstep (runs_bounds n p a ha).2).trans hs.1 | |
| Β· have hh := radius_antitone r hr hstep (Nat.zero_le a.first) | |
| linarith [hs.2] | |
| Β· exact le_envelope (u := fun t y => signedAverage g y t) hat x (signedAverage_radius_continuousOn hg x (hr a.last)) | |
| end SignedRuns | |
| namespace FiniteLabels | |
| lemma Law.ext_mass {ΞΉ : Type*} [Fintype ΞΉ] {ΞΌ Ξ½ : Law ΞΉ} (h : ΞΌ.mass = Ξ½.mass) : ΞΌ = Ξ½ := by | |
| cases ΞΌ | |
| cases Ξ½ | |
| cases h | |
| rfl | |
| end FiniteLabels | |
| namespace SignedAssembly | |
| open Finset FiniteLabels | |
| variable {ΞΉ : Type*} [Fintype ΞΉ] | |
| /-- The zero row-sum is obtained by differentiating the actual stochastic | |
| partition of unity, not postulated for the row derivatives. -/ | |
| def RowJet.ofLawAt (P : β β Law ΞΉ) (x : β) | |
| (hd : β i, DifferentiableAt β (fun y => P y i) x) : RowJet ΞΉ β where | |
| law := P x | |
| grad i := gradient (fun y => P y i) x | |
| total_grad := by | |
| have ht : (fun y => β i, P y i) = fun _ => (1:β) := funext fun y => (P y).total | |
| have hs : (β i, fderiv β (fun y => P y i) x) = 0 := by | |
| rw [β fderiv_fun_sum (fun i _ => hd i),ht] | |
| exact fderiv_const_apply (1:β) | |
| simp only [gradient,β _root_.map_sum,hs,map_zero] | |
| end SignedAssembly | |
| namespace ActualLabels | |
| open FiniteLabels SignedAssembly Finset ConeCoordinates | |
| /-- Observation time zero is the true initial spatial row. Subsequent times | |
| are the true state-dependent spatial switch rows. -/ | |
| def observation (h : β β β) (r : β β β) : β β β β Label β Law Label | |
| | 0,x,_ => initial h (r 0) x | |
| | k+1,x,n => row h (r (k+1)) x n | |
| def before (h : β β β) (r : β β β) (old : Label) (x : β) : β β Law Label | |
| | 0 => delta old | |
| | k+1 => marginal h r k x | |
| lemma before_move (h : β β β) (r : β β β) (old : Label) (x : β) (k : β) : | |
| before h r old x (k+1) = move (before h r old x k) (observation h r k x) := by | |
| cases k with | |
| | zero => | |
| apply Law.ext_mass | |
| funext j | |
| change initial h (r 0) x j = β n, delta old n*initial h (r 0) x j | |
| rw [β sum_mul,(delta old).total,one_mul] | |
| | succ k => rfl | |
| lemma observation_lipschitz (h : β β β) (r : β β β) (k : β) (hr : 0 < r k) | |
| (n j : Label) : LipschitzWith (Real.toNNReal (16/r k)) (fun x => observation h r k x n j) := by | |
| cases k with | |
| | zero => | |
| simpa only [mul_one,observation,initial,row] using spatialRow_component_lipschitz (quantize 1 (by norm_num)) | |
| (target h (r 0)) (fun _ => 1) (fun _ => zero_le_one) (fun _ => le_rfl) hr | |
| (by norm_num : (0:β) β€ 1) (fun _ => le_rfl) j | |
| | succ k => | |
| simpa only [mul_one,observation,initial,row] using spatialRow_component_lipschitz n (target h (r (k+1))) | |
| (switchChance h (r (k+1)) n) (switchChance_nonneg h (r (k+1)) n) | |
| (switchChance_le_one h (r (k+1)) n) hr (by norm_num : (0:β) β€ 1) | |
| (switchChance_le_one h (r (k+1)) n) j | |
| lemma observation_ae_diff (h : β β β) (r : β β β) (hr : β k, 0 < r k) : | |
| βα΅ x, β k n j, DifferentiableAt β (fun y => observation h r k y n j) x := by | |
| simp only [ae_all_iff] | |
| intro k n j | |
| exact (observation_lipschitz h r k (hr k) n j).ae_differentiableAt | |
| def observationJet (h : β β β) (r : β β β) (x : β) | |
| (hd : β k n j, DifferentiableAt β (fun y => observation h r k y n j) x) | |
| (k : β) (n : Label) : RowJet Label β := | |
| RowJet.ofLawAt (fun y => observation h r k y n) x (hd k n) | |
| /-- The jet's expected absolute row derivative is exactly T_k/r_k from the | |
| physical spatial packing theorem. -/ | |
| lemma observationJet_cost (h : β β β) (r : β β β) (old : Label) (x : β) | |
| (hd : β k n j, DifferentiableAt β (fun y => observation h r k y n j) x) | |
| (k : β) (hr : 0 < r k) : | |
| expect (before h r old x k) (fun n => β j, β(observationJet h r x hd k n).grad jβ) = | |
| derivativeCost h r x k/r k := by | |
| cases k with | |
| | zero => | |
| change expect (delta old) (fun _ => β j, βgradient (fun y => initial h (r 0) y j) xβ) = _ | |
| rw [FiniteLabels.expect_const,derivativeCost,mul_div_cancel_leftβ _ hr.ne'] | |
| | succ k => | |
| simp only [observationJet,RowJet.ofLawAt,observation,before,derivativeCost,rowDerivative,FiniteLabels.expect] | |
| rw [Finset.sum_div] | |
| apply sum_congr rfl | |
| intro n _ | |
| field_simp | |
| end ActualLabels | |
| namespace SignedRuns | |
| open ActualLabels FiniteLabels SignedAssembly Finset | |
| def weight (h : β β β) (r : β β β) (old : Label) (x : β) : List Label β β | |
| | [] => 1 | |
| | n::p => weight h r old x p*observation h r p.length x (p.headD old) n | |
| lemma weight_nonneg (h : β β β) (r : β β β) (old : Label) (x : β) (p : List Label) : | |
| 0 β€ weight h r old x p := by | |
| induction p with | |
| | nil => exact zero_le_one | |
| | cons n p ih => exact mul_nonneg ih ((observation h r p.length x (p.headD old)).nonneg n) | |
| lemma weight_le_one (h : β β β) (r : β β β) (old : Label) (x : β) (p : List Label) : | |
| weight h r old x p β€ 1 := by | |
| induction p with | |
| | nil => exact le_rfl | |
| | cons n p ih => | |
| apply (mul_le_mul ih (law_le_one (observation h r p.length x (p.headD old)) n) | |
| ((observation h r p.length x (p.headD old)).nonneg n) zero_le_one).trans_eq | |
| exact one_mul 1 | |
| lemma lipschitz_bounded_mul {f g : β β β} {K L : ββ₯0} (hf : LipschitzWith K f) | |
| (hg : LipschitzWith L g) (hfb : β x, βf xβ β€ 1) (hgb : β x, βg xβ β€ 1) : | |
| LipschitzWith (K+L) (fun x => f x*g x) := by | |
| rw [lipschitzWith_iff_norm_sub_le] at hf hg β’ | |
| intro x y | |
| calc | |
| βf x*g x-f y*g yβ = βf x*(g x-g y)+g y*(f x-f y)β := by congr 1; ring | |
| _ β€ βf x*(g x-g y)β+βg y*(f x-f y)β := norm_add_le _ _ | |
| _ = βf xβ*βg x-g yβ+βg yβ*βf x-f yβ := by rw [norm_mul,norm_mul] | |
| _ β€ 1*((L:β)*βx-yβ)+1*((K:β)*βx-yβ) := by | |
| gcongr | |
| Β· exact hfb x | |
| Β· exact hg x y | |
| Β· exact hgb y | |
| Β· exact hf x y | |
| _ = ((K+L:ββ₯0):β)*βx-yβ := by push_cast; ring | |
| lemma weight_lipschitz (h : β β β) (r : β β β) (hr : β k, 0 < r k) | |
| (old : Label) (p : List Label) : β K, LipschitzWith K (fun x => weight h r old x p) := by | |
| induction p with | |
| | nil => exact β¨0,LipschitzWith.const 1β© | |
| | cons n p ih => | |
| obtain β¨K,hKβ© := ih | |
| refine β¨_,lipschitz_bounded_mul hK (observation_lipschitz h r p.length (hr _) _ n) ?_ ?_β© | |
| Β· intro x | |
| rw [Real.norm_eq_abs,abs_of_nonneg (weight_nonneg h r old x p)] | |
| exact weight_le_one h r old x p | |
| Β· intro x | |
| rw [Real.norm_eq_abs,abs_of_nonneg ((observation h r p.length x (p.headD old)).nonneg n)] | |
| exact law_le_one (observation h r p.length x (p.headD old)) n | |
| lemma weight_diff (h : β β β) (r : β β β) (old : Label) (x : β) | |
| (hd : β k n j, DifferentiableAt β (fun y => observation h r k y n j) x) | |
| (p : List Label) : DifferentiableAt β (fun y => weight h r old y p) x := by | |
| induction p with | |
| | nil => exact differentiableAt_const 1 | |
| | cons n p ih => exact ih.mul (hd p.length (p.headD old) n) | |
| lemma gradient_weight_cons (h : β β β) (r : β β β) (old : Label) (x : β) | |
| (hd : β k n j, DifferentiableAt β (fun y => observation h r k y n j) x) | |
| (n : Label) (p : List Label) : | |
| gradient (fun y => weight h r old y (n::p)) x = | |
| weight h r old x p β’ (observationJet h r x hd p.length (p.headD old)).grad n+ | |
| observation h r p.length x (p.headD old) n β’ gradient (fun y => weight h r old y p) x := by | |
| simp only [weight,observationJet,RowJet.ofLawAt,gradient] | |
| rw [fderiv_fun_mul (weight_diff h r old x hd p) (hd p.length (p.headD old) n)] | |
| simp only [map_add,map_smul] | |
| /-- Unweighted finite sum over every possible terminal continuation. -/ | |
| def leafSum {E : Type*} [AddCommMonoid E] (f : List Label β E) : β β List Label β E | |
| | 0,p => f p | |
| | d+1,p => β n, leafSum f d (n::p) | |
| lemma flux_eq_weightedLeaves (g : β β β) (h : β β β) (r : β β β) (old : Label) | |
| (x : β) (hd : β k n j, DifferentiableAt β (fun y => observation h r k y n j) x) | |
| (v : β β β) (d : β) (p : List Label) : | |
| pathFlux (jet g r x (observationJet h r x hd) v d p (p.headD old)) | |
| (weight h r old x p) (gradient (fun y => weight h r old y p) x) = | |
| leafSum (fun q => inner β (gradient (fun y => weight h r old y q) x) (potential g r x q)) d p := by | |
| induction d generalizing p with | |
| | zero => rfl | |
| | succ d ih => | |
| simp only [jet,pathFlux,leafSum] | |
| apply sum_congr rfl | |
| intro n _ | |
| change pathFlux _ (weight h r old x (n::p)) | |
| (weight h r old x p β’ (observationJet h r x hd p.length (p.headD old)).grad n+ | |
| observation h r p.length x (p.headD old) n β’ gradient (fun y => weight h r old y p) x) = _ | |
| rw [β gradient_weight_cons h r old x hd n p] | |
| exact ih (n::p) | |
| /-- The signed flux bound for derivatives of the actual spatial history | |
| weights, with the true initial row and forward marginal derivatives. -/ | |
| theorem actual_signed_flux_bound (g : β β β) (h : β β β) (r : β β β) | |
| (hg : ContDiff β 1 g) (hr : β k, 0 < r k) (hstep : β k, 2*r (k+1) = r k) | |
| (old : Label) (x : β) | |
| (hd : β k n j, DifferentiableAt β (fun y => observation h r k y n j) x) | |
| (v : β β β) | |
| (hv : β k t t', 0 < t β t β€ 4*r k β 0 < t' β t' β€ 4*r k β | |
| |DiskMoments.signedAverage g x t-DiskMoments.signedAverage g x t'| β€ v k) | |
| (m : β) : | |
| |leafSum (fun q => inner β (gradient (fun y => weight h r old y q) x) (potential g r x q)) m []| β€ | |
| β k β range m, (derivativeCost h r x k/r k)*(β l β Ico k m, v l) := by | |
| have hh := run_signed_flux_bound g r x (observationJet h r x hd) v hg hr hstep hv m old | |
| (before h r old x) rfl (before_move h r old x) | |
| have he := flux_eq_weightedLeaves g h r old x hd v m [] | |
| simp only [List.headD_nil,weight] at he | |
| rw [show gradient (fun _ : β => (1:β)) x = 0 from gradient_const x 1] at he | |
| rw [he] at hh | |
| simpa only [observationJet_cost h r old x hd _ (hr _)] using hh | |
| end SignedRuns | |
| namespace SignedRuns | |
| open DiskMoments RadiusEnvelope ActualLabels ConeCoordinates | |
| lemma run_gradient_touching {g : β β β} {r : β β β} (hg : ContDiff β 1 g) | |
| (hgc : HasCompactSupport g) (hr : β k, 0 < r k) {i j : β} {x : β} | |
| (hd : DifferentiableAt β (runEnvelope g r i j) x) {t : β} | |
| (ht : t β Icc (r j) (2*r i)) (he : runEnvelope g r i j x = signedAverage g x t) : | |
| gradient (runEnvelope g r i j) x = gradient (fun y => signedAverage g y t) x := by | |
| obtain β¨K,hKβ© := hg.lipschitzWith_of_hasCompactSupport hgc one_ne_zero | |
| have hu := hasFDerivAt_signedAverage hg (fun y => norm_fderiv_le_of_lipschitz β hK) x | |
| ((hr j).trans_le ht.1) | |
| unfold gradient runEnvelope | |
| rw [RadiusEnvelope.fderiv_touching ht (fun y => signedAverage_radius_continuousOn hg y (hr j)) he hd hu.differentiableAt] | |
| lemma runs_ae_diff {g : β β β} {r : β β β} (hg : ContDiff β 1 g) | |
| (hgc : HasCompactSupport g) (hr : β k, 0 < r k) (hstep : β k, 2*r (k+1) = r k) : | |
| βα΅ x, β i j, i β€ j β DifferentiableAt β (runEnvelope g r i j) x := by | |
| simp only [ae_all_iff] | |
| intro i j hij | |
| have hab : r j β€ 2*r i := by | |
| have := radius_antitone r hr hstep hij | |
| linarith [hr i] | |
| obtain β¨L,hLβ© := run_envelope_lipschitz hg hgc (hr j) hab | |
| exact hL.ae_differentiableAt | |
| def coneContribution (n : Label) (z : β) : β := | |
| inner β (n:β) z+max 0 (-inner β (axis n 1) z)+max 0 (-inner β (axis n (-1)) z) | |
| lemma coneContribution_nonneg (n : Label) (z : β) : 0 β€ coneContribution n z := by | |
| have hc := cone_algebra (label_unit n) z | |
| change βzβ β€ 12*coneContribution n z at hc | |
| linarith [norm_nonneg z] | |
| theorem run_master {g : β β β} {r : β β β} (hg : ContDiff β 1 g) | |
| (hgc : HasCompactSupport g) (hr : β k, 0 < r k) (hstep : β k, 2*r (k+1) = r k) | |
| (n : Label) (p : List Label) (x : β) | |
| (hd : β i j, i β€ j β DifferentiableAt β (runEnvelope g r i j) x) : | |
| βgradient (runEnvelope g r 0 p.length) xβ β€ | |
| 12*((runs (n::p)).map fun a => coneContribution a.dir | |
| (gradient (runEnvelope g r a.first a.last) x)).sum := by | |
| obtain β¨a,ha,t,ht,hgval,havalβ© := winning_run g r hg hr hstep n p x | |
| have hab := runs_bounds n p a ha | |
| have htg : t β Icc (r p.length) (2*r 0) := by | |
| constructor | |
| Β· exact (radius_antitone r hr hstep hab.2).trans ht.1 | |
| Β· have hh := radius_antitone r hr hstep (Nat.zero_le a.first) | |
| linarith [ht.2] | |
| have he : gradient (runEnvelope g r 0 p.length) x = gradient (runEnvelope g r a.first a.last) x := | |
| (run_gradient_touching hg hgc hr (hd 0 p.length (Nat.zero_le _)) htg hgval).trans | |
| (run_gradient_touching hg hgc hr (hd a.first a.last hab.1) ht haval).symm | |
| rw [he] | |
| apply (cone_algebra (label_unit a.dir) _).trans | |
| apply mul_le_mul_of_nonneg_left _ (by norm_num : (0:β) β€ 12) | |
| apply List.single_le_sum | |
| Β· intro z hz | |
| obtain β¨b,_,rflβ© := List.mem_map.mp hz | |
| exact coneContribution_nonneg b.dir _ | |
| Β· exact List.mem_map.mpr β¨a,ha,rflβ© | |
| end SignedRuns | |
| namespace DiskMoments | |
| lemma signedAverage_hasCompactSupport {g : β β β} (hg : ContDiff β 1 g) | |
| (hc : HasCompactSupport g) {t : β} (ht : 0 < t) : | |
| HasCompactSupport (fun x => signedAverage g x t) := by | |
| have he : RadiusEnvelope.envelope (fun s x => signedAverage g x s) t t = | |
| fun x => signedAverage g x t := by | |
| funext x | |
| obtain β¨s,hs,he,_β© := RadiusEnvelope.attains (u := fun s x => signedAverage g x s) (a := t) (b := t) le_rfl x (signedAverage_radius_continuousOn hg x ht) | |
| have hst : s = t := le_antisymm hs.2 hs.1 | |
| simpa only [hst] using he | |
| rw [β he] | |
| exact run_envelope_hasCompactSupport hg hc ht le_rfl | |
| end DiskMoments | |
| end | |
| end OAI | |