import Mathlib namespace OAI noncomputable section open MeasureTheory Filter open scoped Topology namespace Problem367.StoppedSimpleIntegral variable {Ω ι : Type*} [mΩ : MeasurableSpace Ω] [LinearOrder ι] {P : Measure Ω} [IsFiniteMeasure P] {F : Filtration ι mΩ} {B : ι → Ω → ℝ} theorem condExp_eval_eq_min (hB : Martingale B F P) (s t : ι) : P[B t | F s] =ᵐ[P] B (min s t) := by rcases le_total s t with hst | hts · simpa only [min_eq_left hst] using hB.condExp_ae_eq hst · rw [min_eq_right hts] exact (condExp_of_stronglyMeasurable (F.le s) ((hB.stronglyMeasurable t).mono (F.mono hts)) (hB.integrable t)).eventuallyEq def intervalSum (B : ι → Ω → ℝ) (H : Ω → ℝ) (a b t : ι) (ω : Ω) : ℝ := H ω * (B (min t b) ω - B (min t a) ω) omit [IsFiniteMeasure P] in theorem intervalSum_stronglyAdapted (hB : Martingale B F P) {a b : ι} (hab : a ≤ b) {H : Ω → ℝ} (hH : StronglyMeasurable[F a] H) : StronglyAdapted F (intervalSum B H a b) := by intro t rcases le_total t a with hta | hat · have heq : intervalSum B H a b t = 0 := by funext ω simp only [intervalSum, min_eq_left hta, min_eq_left (hta.trans hab), sub_self, mul_zero, Pi.zero_apply] rw [heq] exact stronglyMeasurable_zero · exact ((hH.mono (F.mono hat)).mul (((hB.stronglyMeasurable (min t b)).mono (F.mono (min_le_left _ _))).sub ((hB.stronglyMeasurable (min t a)).mono (F.mono (min_le_left _ _))))) theorem intervalSum_eq_condExp_terminal (hB : Martingale B F P) {a b : ι} (hab : a ≤ b) {H : Ω → ℝ} (hH : StronglyMeasurable[F a] H) {K : ℝ} (hbound : ∀ᵐ ω ∂P, ‖H ω‖ ≤ K) (t : ι) : P[(fun ω => H ω * (B b ω - B a ω)) | F t] =ᵐ[P] intervalSum B H a b t := by have hDint : Integrable (fun ω => B b ω - B a ω) P := (hB.integrable b).sub (hB.integrable a) have hYint : Integrable (fun ω => H ω * (B b ω - B a ω)) P := hDint.bdd_mul (hH.mono (F.le a)).aestronglyMeasurable hbound rcases le_total t a with hta | hat · have hzero : P[(fun ω => B b ω - B a ω) | F a] =ᵐ[P] fun _ => 0 := by have hs := condExp_sub (hB.integrable b) (hB.integrable a) (F a) filter_upwards [hs, hB.condExp_ae_eq hab, hB.condExp_ae_eq (le_refl a)] with ω hs hb ha change P[(fun ω => B b ω - B a ω) | F a] ω = P[B b | F a] ω - P[B a | F a] ω at hs simpa only [hb, ha, sub_self] using hs have hyzero : P[(fun ω => H ω * (B b ω - B a ω)) | F a] =ᵐ[P] fun _ => 0 := by have hp := condExp_mul_of_stronglyMeasurable_left hH hYint hDint filter_upwards [hp, hzero] with ω hp hz change P[(fun ω => H ω * (B b ω - B a ω)) | F a] ω = H ω * P[(fun ω => B b ω - B a ω) | F a] ω at hp simpa only [hz, mul_zero] using hp have htower := condExp_condExp_of_le (μ := P) (F.mono hta) (F.le a) (f := fun ω => H ω * (B b ω - B a ω)) calc P[(fun ω => H ω * (B b ω - B a ω)) | F t] =ᵐ[P] P[P[(fun ω => H ω * (B b ω - B a ω)) | F a] | F t] := htower.symm _ =ᵐ[P] P[(fun _ : Ω => (0 : ℝ)) | F t] := condExp_congr_ae hyzero _ =ᵐ[P] intervalSum B H a b t := by change P[(0 : Ω → ℝ) | F t] =ᵐ[P] intervalSum B H a b t rw [condExp_zero] apply Filter.Eventually.of_forall intro ω simp only [intervalSum, min_eq_left hta, min_eq_left (hta.trans hab), Pi.zero_apply, sub_self, mul_zero] · have hp := condExp_mul_of_stronglyMeasurable_left (hH.mono (F.mono hat)) hYint hDint have hs := condExp_sub (hB.integrable b) (hB.integrable a) (F t) filter_upwards [hp, hs, condExp_eval_eq_min hB t b, condExp_eval_eq_min hB t a] with ω hp hs hb ha change P[(fun ω => H ω * (B b ω - B a ω)) | F t] ω = H ω * P[(fun ω => B b ω - B a ω) | F t] ω at hp change P[(fun ω => B b ω - B a ω) | F t] ω = P[B b | F t] ω - P[B a | F t] ω at hs rw [hp, hs, hb, ha] rfl theorem intervalSum_martingale (hB : Martingale B F P) {a b : ι} (hab : a ≤ b) {H : Ω → ℝ} (hH : StronglyMeasurable[F a] H) {K : ℝ} (hbound : ∀ᵐ ω ∂P, ‖H ω‖ ≤ K) : Martingale (intervalSum B H a b) F P := (martingale_condExp (fun ω => H ω * (B b ω - B a ω)) F P).congr (intervalSum_stronglyAdapted hB hab hH) (intervalSum_eq_condExp_terminal hB hab hH hbound) theorem finite_intervalSum_martingale {J : Type*} (hB : Martingale B F P) (s : Finset J) (a b : J → ι) (H : J → Ω → ℝ) (hab : ∀ i ∈ s, a i ≤ b i) (hH : ∀ i ∈ s, StronglyMeasurable[F (a i)] (H i)) (K : J → ℝ) (hbound : ∀ i ∈ s, ∀ᵐ ω ∂P, ‖H i ω‖ ≤ K i) : Martingale (fun t ω => ∑ i ∈ s, intervalSum B (H i) (a i) (b i) t ω) F P := by classical induction s using Finset.induction_on with | empty => convert martingale_zero ℝ F P using 1 ext t ω simp | @insert i s his ih => have hi := intervalSum_martingale hB (hab i (Finset.mem_insert_self i s)) (hH i (Finset.mem_insert_self i s)) (hbound i (Finset.mem_insert_self i s)) have hs := ih (fun j hj => hab j (Finset.mem_insert_of_mem hj)) (fun j hj => hH j (Finset.mem_insert_of_mem hj)) (fun j hj => hbound j (Finset.mem_insert_of_mem hj)) convert hi.add hs using 1 ext t ω simp only [Finset.sum_insert his, Pi.add_apply] theorem martingale_of_pointwise_time_L1_limit {N : Type*} {l : Filter N} [l.NeBot] {X : N → ι → Ω → ℝ} {Y : ι → Ω → ℝ} (hX : ∀ n, Martingale (X n) F P) (hY : StronglyAdapted F Y) (hYint : ∀ t, Integrable (Y t) P) (hlim : ∀ t, Tendsto (fun n => eLpNorm (X n t - Y t) 1 P) l (𝓝 0)) : Martingale Y F P := by refine ⟨hY, ?_⟩ intro s t hst apply (ae_eq_condExp_of_forall_setIntegral_eq (F.le s) (hYint t) (fun A hA _ => (hYint s).integrableOn) ?_ (hY s).aestronglyMeasurable).symm intro A hA hAfin have hs := tendsto_setIntegral_of_L1' (Y s) (Filter.Eventually.of_forall (fun n => (hX n).integrable s)) (hlim s) A have ht := tendsto_setIntegral_of_L1' (Y t) (Filter.Eventually.of_forall (fun n => (hX n).integrable t)) (hlim t) A have heq : (fun n => ∫ ω in A, X n s ω ∂P) = (fun n => ∫ ω in A, X n t ω ∂P) := funext (fun n => (hX n).setIntegral_eq hst hA) rw [heq] at hs exact tendsto_nhds_unique hs ht end Problem367.StoppedSimpleIntegral end end OAI