diff --git a/thys/Doob_Convergence/Stopping_Time.thy b/thys/Doob_Convergence/Stopping_Time.thy --- a/thys/Doob_Convergence/Stopping_Time.thy +++ b/thys/Doob_Convergence/Stopping_Time.thy @@ -1,524 +1,524 @@ (* Author: Ata Keskin, TU München *) section \Stopping Times and Hitting Times\ text \In this section we formalize stopping times and hitting times. A stopping time is a random variable that represents the time at which a certain event occurs within a stochastic process. A hitting time, also known as first passage time or first hitting time, is a specific type of stopping time that represents the first time a stochastic process reaches a particular state or crosses a certain threshold.\ theory Stopping_Time -imports Martingales_Updates +imports Martingales.Stochastic_Process begin subsection \Stopping Time\ text \The formalization of stopping times here is simply a rewrite of the document \HOL-Probability.Stopping_Time\ \<^cite>\"hoelzl2011measuretheory"\. We have adapted the document to use the locales defined in our formalization of filtered measure spaces \<^cite>\keskin2023formalization\ \<^cite>\"Martingales-AFP"\. - This way we can omit the partial formalization of filtrations in the original document. Furthermore, we can include the initial time index \<^term>\t\<^sub>0\ that we introduced as well.\ + This way, we can omit the partial formalization of filtrations in the original document. Furthermore, we can include the initial time index \<^term>\t\<^sub>0\ that we introduced as well.\ context linearly_filtered_measure begin \ \A stopping time is a measurable function from the measure space (possible events) into the time axis.\ definition stopping_time :: "('a \ 'b) \ bool" where "stopping_time T = ((T \ space M \ {t\<^sub>0..}) \ (\t\t\<^sub>0. Measurable.pred (F t) (\x. T x \ t)))" lemma stopping_time_cong: assumes "\t x. t \ t\<^sub>0 \ x \ space (F t) \ T x = S x" shows "stopping_time T = stopping_time S" proof (cases "T \ space M \ {t\<^sub>0..}") case True hence "S \ space M \ {t\<^sub>0..}" using assms space_F by force then show ?thesis unfolding stopping_time_def using assms arg_cong[where f="(\P. \t\t\<^sub>0. P t)"] measurable_cong[where M="F _" and f="\x. T x \ _" and g="\x. S x \ _"] True by metis next case False hence "S \ space M \ {t\<^sub>0..}" using assms space_F by force then show ?thesis unfolding stopping_time_def using False by blast qed lemma stopping_time_ge_zero: assumes "stopping_time T" "\ \ space M" shows "T \ \ t\<^sub>0" using assms unfolding stopping_time_def by auto lemma stopping_timeD: assumes "stopping_time T" "t \ t\<^sub>0" shows "Measurable.pred (F t) (\x. T x \ t)" using assms unfolding stopping_time_def by simp lemma stopping_timeI[intro?]: assumes "\x. x \ space M \ T x \ t\<^sub>0" "(\t. t \ t\<^sub>0 \ Measurable.pred (F t) (\x. T x \ t))" shows "stopping_time T" using assms by (auto simp: stopping_time_def) lemma stopping_time_measurable: assumes "stopping_time T" shows "T \ borel_measurable M" proof (rule borel_measurableI_le) { fix t assume "\ t \ t\<^sub>0" hence "{x \ space M. T x \ t} = {}" using assms dual_order.trans[of _ t "t\<^sub>0"] unfolding stopping_time_def by fastforce hence "{x \ space M. T x \ t} \ sets M" by (metis sets.empty_sets) } moreover { fix t assume asm: "t \ t\<^sub>0" hence "{x \ space M. T x \ t} \ sets M" using stopping_timeD[OF assms asm] sets_F_subset unfolding Measurable.pred_def space_F[OF asm] by blast } ultimately show "{x \ space M. T x \ t} \ sets M" for t by blast qed lemma stopping_time_const: assumes "t \ t\<^sub>0" shows "stopping_time (\x. t)" using assms by (auto simp: stopping_time_def) lemma stopping_time_min: assumes "stopping_time T" "stopping_time S" shows "stopping_time (\x. min (T x) (S x))" using assms by (auto simp: stopping_time_def min_le_iff_disj intro!: pred_intros_logic) lemma stopping_time_max: assumes "stopping_time T" "stopping_time S" shows "stopping_time (\x. max (T x) (S x))" using assms by (auto simp: stopping_time_def intro!: pred_intros_logic max.coboundedI1) subsection \\\\-algebra of a Stopping Time\ text \Moving on, we define the \\\-algebra associated with a stopping time \<^term>\T\. It contains all the information up to time \<^term>\T\, the same way \<^term>\F t\ contains all the information up to time \<^term>\t\.\ definition pre_sigma :: "('a \ 'b) \ 'a measure" where "pre_sigma T = sigma (space M) {A \ sets M. \t\t\<^sub>0. {\ \ A. T \ \ t} \ sets (F t)}" lemma measure_pre_sigma[simp]: "emeasure (pre_sigma T) = (\_. 0)" by (simp add: pre_sigma_def emeasure_sigma) lemma sigma_algebra_pre_sigma: assumes "stopping_time T" shows "sigma_algebra (space M) {A \ sets M. \t\t\<^sub>0. {\\A. T \ \ t} \ sets (F t)}" proof - let ?\ = "{A \ sets M. \t\t\<^sub>0. {\\A. T \ \ t} \ sets (F t)}" { fix A assume asm: "A \ ?\" { fix t assume asm': "t \ t\<^sub>0" hence "{\\A. T \ \ t} \ sets (F t)" using asm by blast then have "{\ \ space (F t). T \ \ t} - {\ \ A. T \ \ t} \ sets (F t)" using assms[THEN stopping_timeD, OF asm'] by auto also have "{\ \ space (F t). T \ \ t} - {\ \ A. T \ \ t} = {\ \ space M - A. T \ \ t}" using space_F[OF asm'] by blast finally have "{\ \ (space M) - A. T \ \ t} \ sets (F t)" . } hence "space M - A \ ?\" using asm by blast } moreover { fix A :: "nat \ 'a set" assume asm: "range A \ ?\" { fix t assume "t \ t\<^sub>0" then have "(\i. {\ \ A i. T \ \ t}) \ sets (F t)" using asm by auto also have "(\i. {\ \ A i. T \ \ t}) = {\ \ \(A ` UNIV). T \ \ t}" by auto finally have "{\ \ \(range A). T \ \ t} \ sets (F t)" . } hence "\(range A) \ ?\" using asm by blast } ultimately show ?thesis unfolding sigma_algebra_iff2 by (auto intro!: sets.sets_into_space[THEN PowI, THEN subsetI]) qed lemma space_pre_sigma[simp]: "space (pre_sigma T) = space M" unfolding pre_sigma_def by (intro space_measure_of_conv) lemma sets_pre_sigma: assumes "stopping_time T" shows "sets (pre_sigma T) = {A \ sets M. \t\t\<^sub>0. {\\A. T \ \ t} \ F t}" unfolding pre_sigma_def using sigma_algebra.sets_measure_of_eq[OF sigma_algebra_pre_sigma, OF assms] by blast lemma sets_pre_sigmaI: assumes "stopping_time T" and "\t. t \ t\<^sub>0 \ {\ \ A. T \ \ t} \ F t" shows "A \ pre_sigma T" proof (cases "\t\t\<^sub>0. \t'. t' \ t") case True then obtain t where "t \ t\<^sub>0" "{\ \ A. T \ \ t} = A" by blast hence "A \ M" using assms(2)[of t] sets_F_subset[of t] by fastforce thus ?thesis using assms(2) unfolding sets_pre_sigma[OF assms(1)] by blast next case False hence *: "{t<..} \ {}" if "t \ t\<^sub>0" for t by (metis not_le empty_iff greaterThan_iff) obtain D :: "'b set" where D: "countable D" "\X. open X \ X \ {} \ D \ X \ {}" by (metis countable_dense_setE disjoint_iff) have **: "D \ {t<..} \ {}" if "t \ t\<^sub>0" for t using * that by (intro D(2)) auto { fix \ obtain t where t: "t \ t\<^sub>0" "T \ \ t" using linorder_linear by auto moreover obtain t' where "t' \ D \ {t<..} \ {t\<^sub>0..}" using ** t by fastforce moreover have "T \ \ t'" using calculation by fastforce ultimately have "\t. \t' \ D \ {t<..} \ {t\<^sub>0..}. T \ \ t'" by blast } hence "(\t'\(\t. D \ {t<..} \ {t\<^sub>0..}). {\ \ A. T \ \ t'}) = A" by fast moreover have "(\t'\(\t. D \ {t<..} \ {t\<^sub>0..}). {\ \ A. T \ \ t'}) \ M" using D assms(2) sets_F_subset by (intro sets.countable_UN'', fastforce, fast) ultimately have "A \ M" by argo thus ?thesis using assms(2) unfolding sets_pre_sigma[OF assms(1)] by blast qed lemma pred_pre_sigmaI: assumes "stopping_time T" shows "(\t. t \ t\<^sub>0 \ Measurable.pred (F t) (\\. P \ \ T \ \ t)) \ Measurable.pred (pre_sigma T) P" unfolding pred_def space_pre_sigma using assms by (auto intro: sets_pre_sigmaI[OF assms(1)]) lemma sets_pre_sigmaD: assumes "stopping_time T" "A \ pre_sigma T" "t \ t\<^sub>0" shows "{\ \ A. T \ \ t} \ sets (F t)" using assms sets_pre_sigma by auto lemma borel_measurable_stopping_time_pre_sigma: assumes "stopping_time T" shows "T \ borel_measurable (pre_sigma T)" proof (intro borel_measurableI_le sets_pre_sigmaI[OF assms]) fix t t' assume asm: "t \ t\<^sub>0" { assume "\ t' \ t\<^sub>0" hence "{\ \ {x \ space (pre_sigma T). T x \ t'}. T \ \ t} = {}" using assms dual_order.trans[of _ t' "t\<^sub>0"] unfolding stopping_time_def by fastforce hence "{\ \ {x \ space (pre_sigma T). T x \ t'}. T \ \ t} \ sets (F t)" by (metis sets.empty_sets) } moreover { assume asm': "t' \ t\<^sub>0" have "{\ \ space (F (min t' t)). T \ \ min t' t} \ sets (F (min t' t))" using assms asm asm' unfolding pred_def[symmetric] by (intro stopping_timeD) auto also have "\ \ sets (F t)" using assms asm asm' by (intro sets_F_mono) auto finally have "{\ \ {x \ space (pre_sigma T). T x \ t'}. T \ \ t} \ sets (F t)" using asm asm' by simp } ultimately show "{\ \ {x \ space (pre_sigma T). T x \ t'}. T \ \ t} \ sets (F t)" by blast qed lemma mono_pre_sigma: assumes "stopping_time T" "stopping_time S" and "\x. x \ space M \ T x \ S x" shows "pre_sigma T \ pre_sigma S" proof fix A assume "A \ pre_sigma T" hence asm: "A \ sets M" "t \ t\<^sub>0 \ {\ \ A. T \ \ t} \ sets (F t)" for t using assms sets_pre_sigma by blast+ { fix t assume asm': "t \ t\<^sub>0" then have "A \ space M" using sets.sets_into_space asm by blast have "{\\A. T \ \ t} \ {\\space (F t). S \ \ t} \ sets (F t)" using asm asm' stopping_timeD[OF assms(2)] by (auto simp: pred_def) also have "{\\A. T \ \ t} \ {\\space (F t). S \ \ t} = {\\A. S \ \ t}" using sets.sets_into_space[OF asm(1)] assms(3) order_trans asm' by fastforce finally have "{\\A. S \ \ t} \ sets (F t)" by simp } thus "A \ pre_sigma S" by (intro sets_pre_sigmaI assms asm) blast qed lemma stopping_time_measurable_le: assumes "stopping_time T" "s \ t\<^sub>0" "t \ s" shows "Measurable.pred (F t) (\\. T \ \ s)" using assms stopping_timeD[of T] sets_F_mono[of _ t] by (auto simp: pred_def) lemma stopping_time_measurable_less: assumes "stopping_time T" "s \ t\<^sub>0" "t \ s" shows "Measurable.pred (F t) (\\. T \ < s)" proof - have "Measurable.pred (F t) (\\. T \ < t)" if asm: "stopping_time T" "t \ t\<^sub>0" for T t proof - obtain D :: "'b set" where D: "countable D" "\X. open X \ X \ {} \ D \ X \ {}" by (metis countable_dense_setE disjoint_iff) show ?thesis proof cases assume *: "\t'\{t\<^sub>0.. {}" hence **: "D \ {t'<..< t} \ {}" if "t' \ {t\<^sub>0.. < t \ (\r\D \ {t\<^sub>0.. \ r)" if "\ \ space (F t)" for \ using **[of "T \"] that less_imp_le stopping_time_ge_zero asm by fastforce show "Measurable.pred (F t) (\w. \r\D \ {t\<^sub>0.. r)" using stopping_time_measurable_le asm D by (intro measurable_pred_countable) auto qed next assume "\ (\t'\{t\<^sub>0.. {})" then obtain t' where t': "t' \ {t\<^sub>0.. < t \ T \ \ t'" for \ using t' by (metis atLeastLessThan_iff emptyE greaterThanLessThan_iff linorder_not_less order.strict_trans1) show "Measurable.pred (F t) (\w. T w \ t')" using t' by (intro stopping_time_measurable_le[OF asm(1)]) auto qed qed qed thus ?thesis using assms sets_F_mono[of _ t] by (auto simp add: pred_def) qed lemma stopping_time_measurable_ge: assumes "stopping_time T" "s \ t\<^sub>0" "t \ s" shows "Measurable.pred (F t) (\\. T \ \ s)" by (auto simp: not_less[symmetric] intro: stopping_time_measurable_less[OF assms] Measurable.pred_intros_logic) lemma stopping_time_measurable_gr: assumes "stopping_time T" "s \ t\<^sub>0" "t \ s" shows "Measurable.pred (F t) (\x. s < T x)" by (auto simp add: not_le[symmetric] intro: stopping_time_measurable_le[OF assms] Measurable.pred_intros_logic) lemma stopping_time_measurable_eq: assumes "stopping_time T" "s \ t\<^sub>0" "t \ s" shows "Measurable.pred (F t) (\\. T \ = s)" unfolding eq_iff using stopping_time_measurable_le[OF assms] stopping_time_measurable_ge[OF assms] by (intro pred_intros_logic) lemma stopping_time_less_stopping_time: assumes "stopping_time T" "stopping_time S" shows "Measurable.pred (pre_sigma T) (\\. T \ < S \)" proof (rule pred_pre_sigmaI) fix t assume asm: "t \ t\<^sub>0" obtain D :: "'b set" where D: "countable D" and semidense_D: "\x y. x < y \ (\b\D. x \ b \ b < y)" using countable_separating_set_linorder2 by auto show "Measurable.pred (F t) (\\. T \ < S \ \ T \ \ t)" proof (rule measurable_cong[THEN iffD2]) let ?f = "\\. if T \ = t then \ S \ \ t else \s\D \ {t\<^sub>0..t}. T \ \ s \ \ (S \ \ s)" { fix \ assume "\ \ space (F t)" "T \ \ t" "T \ \ t" "T \ < S \" hence "t\<^sub>0 \ T \" "T \ < min t (S \)" using asm stopping_time_ge_zero[OF assms(1)] by auto then obtain r where "r \ D" "t\<^sub>0 \ r" "T \ \ r" "r < min t (S \)" using semidense_D order_trans by blast hence "\s\D \ {t\<^sub>0..t}. T \ \ s \ s < S \" by auto } thus "(T \ < S \ \ T \ \ t) = ?f \" if "\ \ space (F t)" for \ using that by force show "Measurable.pred (F t) ?f" using assms asm D by (intro pred_intros_logic measurable_If measurable_pred_countable countable_Collect stopping_time_measurable_le predE stopping_time_measurable_eq) auto qed qed (intro assms) end lemma (in enat_filtered_measure) stopping_time_SUP_enat: fixes T :: "nat \ ('a \ enat)" shows "(\i. stopping_time (T i)) \ stopping_time (SUP i. T i)" unfolding stopping_time_def SUP_apply SUP_le_iff by (auto intro!: pred_intros_countable) lemma (in enat_filtered_measure) stopping_time_Inf_enat: assumes "\i. Measurable.pred (F i) (P i)" shows "stopping_time (\\. Inf {i. P i \})" proof - { fix t :: enat assume asm: "t \ \" moreover { fix i \ assume "Inf {i. P i \} \ t" moreover have "a < eSuc b \ (a \ b \ a \ \)" for a b by (cases a) auto ultimately have "(\i\t. P i \)" using asm unfolding Inf_le_iff by (cases t) (auto elim!: allE[of _ "eSuc t"]) } ultimately have *: "\\. Inf {i. P i \} \ t \ (\i\{..t}. P i \)" by (auto intro!: Inf_lower2) have "Measurable.pred (F t) (\\. Inf {i. P i \} \ t)" unfolding * using sets_F_mono assms by (intro pred_intros_countable_bounded) (auto simp: pred_def) } moreover have "Measurable.pred (F t) (\\. Inf {i. P i \} \ t)" if "t = \" for t using that by simp ultimately show ?thesis by (blast intro: stopping_timeI[OF i0_lb]) qed lemma (in nat_filtered_measure) stopping_time_Inf_nat: assumes "\i. Measurable.pred (F i) (P i)" "\i \. \ \ space M \ \n. P n \" shows "stopping_time (\\. Inf {i. P i \})" proof (rule stopping_time_cong[THEN iffD2]) show "stopping_time (\x. LEAST n. P n x)" proof fix t have "((LEAST n. P n \) \ t) = (\i\t. P i \)" if "\ \ space M" for \ by (rule LeastI2_wellorder_ex[OF assms(2)[OF that]]) auto moreover have "Measurable.pred (F t) (\w. \i\{..t}. P i w)" using sets_F_mono[of _ t] assms by (intro pred_intros_countable_bounded) (auto simp: pred_def) ultimately show "Measurable.pred (F t) (\\. (LEAST n. P n \) \ t)" by (subst measurable_cong[of "F t"]) auto qed (simp) qed (simp add: Inf_nat_def) definition stopped_value :: "('b \ 'a \ 'c) \ ('a \ 'b) \ ('a \ 'c)" where "stopped_value X \ \ = X (\ \) \" subsection \Hitting Time\ text \Given a stochastic process \X\ and a borel set \A\, \hitting_time X A s t\ is the first time \X\ is in \A\ after time \s\ and before time \t\. If \X\ does not hit \A\ after time \s\ and before \t\ then the hitting time is simply \t\. The definition presented here coincides with the definition of hitting times in mathlib \<^cite>\"ying2022formalization"\.\ context linearly_filtered_measure begin definition hitting_time :: "('b \ 'a \ 'c) \ 'c set \ 'b \ 'b \ ('a \ 'b)" where "hitting_time X A s t = (\\. if \i\{s..t} \ {t\<^sub>0..}. X i \ \ A then Inf ({s..t} \ {t\<^sub>0..} \ {i. X i \ \ A}) else max t\<^sub>0 t)" lemma hitting_time_def': "hitting_time X A s t = (\\. Inf (insert (max t\<^sub>0 t) ({s..t} \ {t\<^sub>0..} \ {i. X i \ \ A})))" proof cases assume asm: "t\<^sub>0 \ s \ s \ t" hence "{s..t} \ {t\<^sub>0..} = {s..t}" by simp { fix \ assume *: "{s..t} \ {t\<^sub>0..} \ {i. X i \ \ A} \ {}" then obtain i where "i \ {s..t} \ {t\<^sub>0..} \ {i. X i \ \ A}" by blast hence "Inf ({s..t} \ {t\<^sub>0..} \ {i. X i \ \ A}) \ t" by (intro cInf_lower[of i, THEN order_trans]) auto hence "Inf (insert (max t\<^sub>0 t) ({s..t} \ {t\<^sub>0..} \ {i. X i \ \ A})) = Inf ({s..t} \ {t\<^sub>0..} \ {i. X i \ \ A})" using asm * inf_absorb2 by (subst cInf_insert_If) force+ also have "... = hitting_time X A s t \" using * unfolding hitting_time_def by auto finally have "hitting_time X A s t \ = Inf (insert (max t\<^sub>0 t) ({s..t} \ {t\<^sub>0..} \ {i. X i \ \ A}))" by argo } moreover { fix \ assume "{s..t} \ {t\<^sub>0..} \ {i. X i \ \ A} = {}" hence "hitting_time X A s t \ = Inf (insert (max t\<^sub>0 t) ({s..t} \ {t\<^sub>0..} \ {i. X i \ \ A}))" unfolding hitting_time_def by auto } ultimately show ?thesis by fast next assume "\ (t\<^sub>0 \ s \ s \ t)" moreover { assume asm: "s < t\<^sub>0" "t \ t\<^sub>0" hence "{s..t} \ {t\<^sub>0..} = {t\<^sub>0..t}" by simp { fix \ assume *: "{s..t} \ {t\<^sub>0..} \ {i. X i \ \ A} \ {}" then obtain i where "i \ {s..t} \ {t\<^sub>0..} \ {i. X i \ \ A}" by blast hence "Inf ({s..t} \ {t\<^sub>0..} \ {i. X i \ \ A}) \ t" by (intro cInf_lower[of i, THEN order_trans]) auto hence "Inf (insert (max t\<^sub>0 t) ({s..t} \ {t\<^sub>0..} \ {i. X i \ \ A})) = Inf ({s..t} \ {t\<^sub>0..} \ {i. X i \ \ A})" using asm * inf_absorb2 by (subst cInf_insert_If) force+ also have "... = hitting_time X A s t \" using * unfolding hitting_time_def by auto finally have "hitting_time X A s t \ = Inf (insert (max t\<^sub>0 t) ({s..t} \ {t\<^sub>0..} \ {i. X i \ \ A}))" by argo } moreover { fix \ assume "{s..t} \ {t\<^sub>0..} \ {i. X i \ \ A} = {}" hence "hitting_time X A s t \ = Inf (insert (max t\<^sub>0 t) ({s..t} \ {t\<^sub>0..} \ {i. X i \ \ A}))" unfolding hitting_time_def by auto } ultimately have ?thesis by fast } moreover have ?thesis if "s < t\<^sub>0" "t < t\<^sub>0" using that unfolding hitting_time_def by auto moreover have ?thesis if "s > t" using that unfolding hitting_time_def by auto ultimately show ?thesis by fastforce qed \ \The following lemma provides a sufficient condition for an injective function to preserve a hitting time.\ lemma hitting_time_inj_on: assumes "inj_on f S" "\\ t. t \ t\<^sub>0 \ X t \ \ S" "A \ S" shows "hitting_time X A = hitting_time (\t \. f (X t \)) (f ` A)" proof - have "X t \ \ A \ f (X t \) \ f ` A" if "t \ t\<^sub>0" for t \ using assms that inj_on_image_mem_iff by meson hence "{t\<^sub>0..} \ {i. X i \ \ A} = {t\<^sub>0..} \ {i. f (X i \) \ f ` A}" for \ by blast thus ?thesis unfolding hitting_time_def' Int_assoc by presburger qed lemma hitting_time_translate: fixes c :: "_ :: ab_group_add" shows "hitting_time X A = hitting_time (\n \. X n \ + c) (((+) c) ` A)" by (subst hitting_time_inj_on[OF inj_on_add, of _ UNIV]) (simp add: add.commute)+ lemma hitting_time_le: assumes "t \ t\<^sub>0" shows "hitting_time X A s t \ \ t" unfolding hitting_time_def' using assms by (intro cInf_lower[of "max t\<^sub>0 t", THEN order_trans]) auto lemma hitting_time_ge: assumes "t \ t\<^sub>0" "s \ t" shows "s \ hitting_time X A s t \" unfolding hitting_time_def' using assms by (intro le_cInf_iff[THEN iffD2]) auto lemma hitting_time_mono: assumes "t \ t\<^sub>0" "s \ s'" "t \ t'" shows "hitting_time X A s t \ \ hitting_time X A s' t' \" unfolding hitting_time_def' using assms by (fastforce intro!: cInf_mono) end context nat_filtered_measure begin \ \Hitting times are stopping times for adapted processes.\ lemma stopping_time_hitting_time: assumes "adapted_process M F 0 X" "A \ borel" shows "stopping_time (hitting_time X A s t)" proof - interpret adapted_process M F 0 X by (rule assms) have "insert t ({s..t} \ {i. X i \ \ A}) = {i. i = t \ i \ ({s..t} \ {i. X i \ \ A})}" for \ by blast hence "hitting_time X A s t = (\\. Inf {i. i = t \ i \ ({s..t} \ {i. X i \ \ A})})" unfolding hitting_time_def' by simp thus ?thesis using assms by (auto intro: stopping_time_Inf_nat) qed lemma stopping_time_hitting_time': assumes "adapted_process M F 0 X" "A \ borel" "stopping_time s" "\\. s \ \ t" shows "stopping_time (\\. hitting_time X A (s \) t \)" proof - interpret adapted_process M F 0 X by (rule assms) { fix n have "s \ \ hitting_time X A (s \) t \" if "s \ > n" for \ using hitting_time_ge[OF _ assms(4)] by simp hence "(\i\{n<..}. {\. s \ = i} \ {\. hitting_time X A i t \ \ n}) = {}" by fastforce hence *: "(\\. hitting_time X A (s \) t \ \ n) = (\\. \i\n. s \ = i \ hitting_time X A i t \ \ n)" by force have "Measurable.pred (F n) (\\. s \ = i \ hitting_time X A i t \ \ n)" if "i \ n" for i proof - have "Measurable.pred (F i) (\\. s \ = i)" using stopping_time_measurable_eq assms by blast hence "Measurable.pred (F n) (\\. s \ = i)" by (meson less_eq_nat.simps measurable_from_subalg subalgebra_F that) moreover have "Measurable.pred (F n) (\\. hitting_time X A i t \ \ n)" using stopping_timeD[OF stopping_time_hitting_time, OF assms(1,2)] by blast ultimately show ?thesis by auto qed hence "Measurable.pred (F n) (\\. \i\n. s \ = i \ hitting_time X A i t \ \ n)" by (intro pred_intros_countable) auto hence "Measurable.pred (F n) (\\. hitting_time X A (s \) t \ \ n)" using * by argo } thus ?thesis by (intro stopping_timeI) auto qed \ \If \<^term>\X\ hits \<^term>\A\ at time \<^term>\j \ {s..t}\, then the stopped value of \<^term>\X\ at the hitting time of \<^term>\A\ in the interval \<^term>\{s..t}\ is an element of \<^term>\A\.\ lemma stopped_value_hitting_time_mem: assumes "j \ {s..t}" "X j \ \ A" shows "stopped_value X (hitting_time X A s t) \ \ A" proof - have "\i\{s..t} \ {0..}. X i \ \ A" using assms by blast moreover have "Inf ({s..t} \ {i. X i \ \ A}) \ {s..t} \ {i. X i \ \ A}" using assms by (blast intro!: Inf_nat_def1) ultimately show ?thesis unfolding hitting_time_def stopped_value_def by simp qed lemma hitting_time_le_iff: assumes "i < t" shows "hitting_time X A s t \ \ i \ (\j \ {s..i}. X j \ \ A)" (is "?lhs = ?rhs") proof assume ?lhs moreover have "hitting_time X A s t \ \ insert t ({s..t} \ {i. X i \ \ A})" by (metis hitting_time_def' Int_atLeastAtMostR2 inf_sup_aci(1) insertI1 max_0L wellorder_InfI) ultimately have "hitting_time X A s t \ \ {s..i} \ {i. X i \ \ A}" using assms by force thus ?rhs by blast next assume ?rhs then obtain j where j: "j \ {s..i}" "X j \ \ A" by blast hence "hitting_time X A s t \ \ j" unfolding hitting_time_def' using assms by (auto intro: cInf_lower) thus ?lhs using j by simp qed lemma hitting_time_less_iff: assumes "i \ t" shows "hitting_time X A s t \ < i \ (\j \ {s.. \ A)" (is "?lhs = ?rhs") proof assume ?lhs moreover have "hitting_time X A s t \ \ insert t ({s..t} \ {i. X i \ \ A})" by (metis hitting_time_def' Int_atLeastAtMostR2 inf_sup_aci(1) insertI1 max_0L wellorder_InfI) ultimately have "hitting_time X A s t \ \ {s.. {i. X i \ \ A}" using assms by force thus ?rhs by blast next assume ?rhs then obtain j where j: "j \ {s.. \ A" by blast hence "hitting_time X A s t \ \ j" unfolding hitting_time_def' using assms by (auto intro: cInf_lower) thus ?lhs using j by simp qed \ \If \<^term>\X\ already hits \<^term>\A\ in the interval \<^term>\{s..t}\, then \<^term>\hitting_time X A s t = hitting_time X A s t'\ for \<^term>\t' \ t\.\ lemma hitting_time_eq_hitting_time: assumes "t \ t'" "j \ {s..t}" "X j \ \ A" shows "hitting_time X A s t \ = hitting_time X A s t' \" (is "?lhs = ?rhs") proof - have "hitting_time X A s t \ \ {s..t'}" using hitting_time_le[THEN order_trans, of t t' X A s] hitting_time_ge[of t s X A] assms by auto moreover have "stopped_value X (hitting_time X A s t) \ \ A" by (blast intro: stopped_value_hitting_time_mem assms) ultimately have "hitting_time X A s t' \ \ hitting_time X A s t \" by (fastforce simp add: hitting_time_def'[where t=t'] stopped_value_def intro!: cInf_lower) thus ?thesis by (blast intro: le_antisym hitting_time_mono[OF _ order_refl assms(1)]) qed end end \ No newline at end of file diff --git a/thys/Doob_Convergence/Upcrossing.thy b/thys/Doob_Convergence/Upcrossing.thy --- a/thys/Doob_Convergence/Upcrossing.thy +++ b/thys/Doob_Convergence/Upcrossing.thy @@ -1,639 +1,639 @@ (* Author: Ata Keskin, TU München *) section \Doob's Upcrossing Inequality and Martingale Convergence Theorems\ text \In this section we formalize upcrossings and downcrossings. Following this, we prove Doob's upcrossing inequality and first martingale convergence theorem.\ theory Upcrossing - imports Stopping_Time + imports Martingales.Martingale Stopping_Time begin (* TODO: This can be added to the library under HOL-Analysis.Borel_Space *) lemma real_embedding_borel_measurable: "real \ borel_measurable borel" by (auto intro: borel_measurable_continuous_onI) (* TODO: Add this to the library under HOL-Analysis.Extended_Real_Limits *) lemma limsup_lower_bound: fixes u:: "nat \ ereal" assumes "limsup u > l" shows "\N>k. u N > l" proof - have "limsup u = - liminf (\n. - u n)" using liminf_ereal_cminus[of 0 u] by simp hence "liminf (\n. - u n) < - l" using assms ereal_less_uminus_reorder by presburger hence "\N>k. - u N < - l" using liminf_upper_bound by blast thus ?thesis using ereal_less_uminus_reorder by simp qed lemma ereal_abs_max_min: "\c\ = max 0 c - min 0 c" for c :: ereal by (cases "c \ 0") auto subsection \Upcrossings and Downcrossings\ text \Given a stochastic process \<^term>\X\, real values \<^term>\a\ and \<^term>\b\, and some point in time \<^term>\N\, we would like to define a notion of "upcrossings" of \<^term>\X\ across the band \<^term>\{a..b}\ which counts the number of times any realization of \<^term>\X\ crosses from below \<^term>\a\ to above \<^term>\b\ before time \<^term>\N\. To make this heuristic rigorous, we inductively define the following hitting times.\ context nat_filtered_measure begin context fixes X :: "nat \ 'a \ real" and a b :: real and N :: nat begin primrec upcrossing :: "nat \ 'a \ nat" where "upcrossing 0 = (\\. 0)" | "upcrossing (Suc n) = (\\. hitting_time X {b..} (hitting_time X {..a} (upcrossing n \) N \) N \)" definition downcrossing :: "nat \ 'a \ nat" where "downcrossing n = (\\. hitting_time X {..a} (upcrossing n \) N \)" lemma upcrossing_simps: "upcrossing 0 = (\\. 0)" "upcrossing (Suc n) = (\\. hitting_time X {b..} (downcrossing n \) N \)" by (auto simp add: downcrossing_def) lemma downcrossing_simps: "downcrossing 0 = hitting_time X {..a} 0 N" "downcrossing n = (\\. hitting_time X {..a} (upcrossing n \) N \)" by (auto simp add: downcrossing_def) declare upcrossing.simps[simp del] lemma upcrossing_le: "upcrossing n \ \ N" by (cases n) (auto simp add: upcrossing_simps hitting_time_le) lemma downcrossing_le: "downcrossing n \ \ N" by (cases n) (auto simp add: downcrossing_simps hitting_time_le) lemma upcrossing_le_downcrossing: "upcrossing n \ \ downcrossing n \" unfolding downcrossing_simps by (auto intro: hitting_time_ge upcrossing_le) lemma downcrossing_le_upcrossing_Suc: "downcrossing n \ \ upcrossing (Suc n) \" unfolding upcrossing_simps by (auto intro: hitting_time_ge downcrossing_le) lemma upcrossing_mono: assumes "n \ m" shows "upcrossing n \ \ upcrossing m \" using order_trans[OF upcrossing_le_downcrossing downcrossing_le_upcrossing_Suc] assms by (rule lift_Suc_mono_le) lemma downcrossing_mono: assumes "n \ m" shows "downcrossing n \ \ downcrossing m \" using order_trans[OF downcrossing_le_upcrossing_Suc upcrossing_le_downcrossing] assms by (rule lift_Suc_mono_le) \ \The following lemmas help us make statements about when an upcrossing (resp. downcrossing) occurs, and the value that the process takes at that instant.\ lemma stopped_value_upcrossing: assumes "upcrossing (Suc n) \ \ N" shows "stopped_value X (upcrossing (Suc n)) \ \ b" proof - have *: "upcrossing (Suc n) \ < N" using le_neq_implies_less upcrossing_le assms by presburger have "\j \ {downcrossing n \..upcrossing (Suc n) \}. X j \ \ {b..}" using hitting_time_le_iff[THEN iffD1, OF *] upcrossing_simps by fastforce then obtain j where j: "j \ {downcrossing n \..N}" "X j \ \ {b..}" using * by (meson atLeastatMost_subset_iff le_refl subsetD upcrossing_le) thus ?thesis using stopped_value_hitting_time_mem[of j _ _ X] unfolding upcrossing_simps stopped_value_def by blast qed lemma stopped_value_downcrossing: assumes "downcrossing n \ \ N" shows "stopped_value X (downcrossing n) \ \ a" proof - have *: "downcrossing n \ < N" using le_neq_implies_less downcrossing_le assms by presburger have "\j \ {upcrossing n \..downcrossing n \}. X j \ \ {..a}" using hitting_time_le_iff[THEN iffD1, OF *] downcrossing_simps by fastforce then obtain j where j: "j \ {upcrossing n \..N}" "X j \ \ {..a}" using * by (meson atLeastatMost_subset_iff le_refl subsetD downcrossing_le) thus ?thesis using stopped_value_hitting_time_mem[of j _ _ X] unfolding downcrossing_simps stopped_value_def by blast qed lemma upcrossing_less_downcrossing: assumes "a < b" "downcrossing (Suc n) \ \ N" shows "upcrossing (Suc n) \ < downcrossing (Suc n) \" proof - have "upcrossing (Suc n) \ \ N" using assms by (metis le_antisym downcrossing_le upcrossing_le_downcrossing) hence "stopped_value X (downcrossing (Suc n)) \ < stopped_value X (upcrossing (Suc n)) \" using assms stopped_value_downcrossing stopped_value_upcrossing by force hence "downcrossing (Suc n) \ \ upcrossing (Suc n) \" unfolding stopped_value_def by force thus ?thesis using upcrossing_le_downcrossing by (simp add: le_neq_implies_less) qed lemma downcrossing_less_upcrossing: assumes "a < b" "upcrossing (Suc n) \ \ N" shows "downcrossing n \ < upcrossing (Suc n) \" proof - have "downcrossing n \ \ N" using assms by (metis le_antisym upcrossing_le downcrossing_le_upcrossing_Suc) hence "stopped_value X (downcrossing n) \ < stopped_value X (upcrossing (Suc n)) \" using assms stopped_value_downcrossing stopped_value_upcrossing by force hence "downcrossing n \ \ upcrossing (Suc n) \" unfolding stopped_value_def by force thus ?thesis using downcrossing_le_upcrossing_Suc by (simp add: le_neq_implies_less) qed lemma upcrossing_less_Suc: assumes "a < b" "upcrossing n \ \ N" shows "upcrossing n \ < upcrossing (Suc n) \" by (metis assms upcrossing_le_downcrossing downcrossing_less_upcrossing order_le_less_trans le_neq_implies_less upcrossing_le) (* The following lemma is a more elegant version of the same lemma on mathlib. *) lemma upcrossing_eq_bound: assumes "a < b" "n \ N" shows "upcrossing n \ = N" proof - have *: "upcrossing N \ = N" proof - { assume *: "upcrossing N \ \ N" hence asm: "upcrossing n \ < N" if "n \ N" for n using upcrossing_mono upcrossing_le that by (metis le_antisym le_neq_implies_less) { fix i j assume "i \ N" "i < j" hence "upcrossing i \ \ upcrossing j \" by (metis Suc_leI asm assms(1) leD upcrossing_less_Suc upcrossing_mono) } moreover { fix j assume "j \ N" hence "upcrossing j \ \ upcrossing N \" using upcrossing_mono by blast hence "upcrossing (Suc N) \ \ upcrossing j \" using upcrossing_less_Suc[OF assms(1) *] by simp } ultimately have "inj_on (\n. upcrossing n \) {..Suc N}" unfolding inj_on_def by (metis atMost_iff le_SucE linorder_less_linear) hence "card ((\n. upcrossing n \) ` {..Suc N}) = Suc (Suc N)" by (simp add: inj_on_iff_eq_card[THEN iffD1]) moreover have "(\n. upcrossing n \) ` {..Suc N} \ {..N}" using upcrossing_le by blast moreover have "card ((\n. upcrossing n \) ` {..Suc N}) \ Suc N" using card_mono[OF _ calculation(2)] by simp ultimately have False by linarith } thus ?thesis by blast qed thus ?thesis using upcrossing_mono[OF assms(2), of \] upcrossing_le[of n \] by simp qed lemma downcrossing_eq_bound: assumes "a < b" "n \ N" shows "downcrossing n \ = N" using upcrossing_le_downcrossing[of n \] downcrossing_le[of n \] upcrossing_eq_bound[OF assms] by simp lemma stopping_time_crossings: assumes "adapted_process M F 0 X" shows "stopping_time (upcrossing n)" "stopping_time (downcrossing n)" proof - have "stopping_time (upcrossing n) \ stopping_time (downcrossing n)" proof (induction n) case 0 then show ?case unfolding upcrossing_simps downcrossing_simps using stopping_time_const stopping_time_hitting_time[OF assms] by simp next case (Suc n) have "stopping_time (upcrossing (Suc n))" unfolding upcrossing_simps using assms Suc downcrossing_le by (intro stopping_time_hitting_time') auto moreover have "stopping_time (downcrossing (Suc n))" unfolding downcrossing_simps using assms calculation upcrossing_le by (intro stopping_time_hitting_time') auto ultimately show ?case by blast qed thus "stopping_time (upcrossing n)" "stopping_time (downcrossing n)" by blast+ qed lemmas stopping_time_upcrossing = stopping_time_crossings(1) lemmas stopping_time_downcrossing = stopping_time_crossings(2) \ \We define \upcrossings_before\ as the number of upcrossings which take place strictly before time \<^term>\N\.\ definition upcrossings_before :: "'a \ nat" where "upcrossings_before = (\\. Sup {n. upcrossing n \ < N})" lemma upcrossings_before_bdd_above: assumes "a < b" shows "bdd_above {n. upcrossing n \ < N}" proof - have "{n. upcrossing n \ < N} \ {.. < N" proof - have *: "{n. upcrossing n \ < N} \ {.. < N" unfolding upcrossing_simps by (rule assms) moreover have "Sup {.. < n" shows "upcrossing n \ = N" "downcrossing n \ = N" proof - have "\ upcrossing n \ < N" using assms upcrossings_before_bdd_above[of \] upcrossings_before_def bdd_above_nat finite_Sup_less_iff by fastforce thus "upcrossing n \ = N" using upcrossing_le[of n \] by simp thus "downcrossing n \ = N" using upcrossing_le_downcrossing[of n \] downcrossing_le[of n \] by simp qed lemma upcrossings_before_le: assumes "a < b" shows "upcrossings_before \ \ N" using upcrossings_before_less assms less_le_not_le upcrossings_before_def by (cases N) auto lemma upcrossings_before_mem: assumes "a < b" "0 < N" shows "upcrossings_before \ \ {n. upcrossing n \ < N} \ {.. < N" using assms unfolding upcrossing_simps by simp hence "{n. upcrossing n \ < N} \ {}" by blast moreover have "finite {n. upcrossing n \ < N}" using upcrossings_before_bdd_above[OF assms(1)] by (simp add: bdd_above_nat) ultimately show ?thesis using Max_in upcrossings_before_less[OF assms(1,2)] Sup_nat_def upcrossings_before_def by auto qed lemma upcrossing_less_of_le_upcrossings_before: assumes "a < b" "0 < N" "n \ upcrossings_before \" shows "upcrossing n \ < N" using upcrossings_before_mem[OF assms(1,2), of \] upcrossing_mono[OF assms(3), of \] by simp lemma upcrossings_before_sum_def: assumes "a < b" shows "upcrossings_before \ = (\k\{1..N}. indicator {n. upcrossing n \ < N} k)" proof (cases N) case 0 then show ?thesis unfolding upcrossings_before_def by simp next case (Suc N') have "upcrossing 0 \ < N" using assms Suc unfolding upcrossing_simps by simp hence "{n. upcrossing n \ < N} \ {}" by blast hence *: "\ upcrossing n \ < N" if "n \ {upcrossings_before \ <..N}" for n using finite_Sup_less_iff[THEN iffD1, OF bdd_above_nat[THEN iffD1, OF upcrossings_before_bdd_above], of \ n] by (metis that assms greaterThanAtMost_iff less_not_refl mem_Collect_eq upcrossings_before_def) have **: "upcrossing n \ < N" if "n \ {1..upcrossings_before \}" for n using assms that Suc by (intro upcrossing_less_of_le_upcrossings_before) auto have "upcrossings_before \ < N" using upcrossings_before_less Suc assms by simp hence "{1..N} - {1..upcrossings_before \} = {upcrossings_before \<..N}" "{1..N} \ {1..upcrossings_before \} = {1..upcrossings_before \}" by force+ hence "(\k\{1..N}. indicator {n. upcrossing n \ < N} k) = (\k\{1..upcrossings_before \}. indicator {n. upcrossing n \ < N} k) + (\k\{upcrossings_before \ <..N}. indicator {n. upcrossing n \ < N} k)" using sum.Int_Diff[OF finite_atLeastAtMost, of _ 1 N "{1..upcrossings_before \}"] by metis also have "... = upcrossings_before \" using * ** by simp finally show ?thesis by argo qed lemma upcrossings_before_measurable: assumes "adapted_process M F 0 X" "a < b" shows "upcrossings_before \ borel_measurable M" unfolding upcrossings_before_sum_def[OF assms(2)] using stopping_time_measurable[OF stopping_time_crossings(1), OF assms(1)] by simp lemma upcrossings_before_measurable': assumes "adapted_process M F 0 X" "a < b" shows "(\\. real (upcrossings_before \)) \ borel_measurable M" using real_embedding_borel_measurable upcrossings_before_measurable[OF assms] by simp end lemma crossing_eq_crossing: assumes "N \ N'" and "downcrossing X a b N n \ < N" shows "upcrossing X a b N n \ = upcrossing X a b N' n \" "downcrossing X a b N n \ = downcrossing X a b N' n \" proof - have "upcrossing X a b N n \ = upcrossing X a b N' n \ \ downcrossing X a b N n \ = downcrossing X a b N' n \" using assms(2) proof (induction n) case 0 show ?case by (metis (no_types, lifting) upcrossing_simps(1) assms atLeast_0 bot_nat_0.extremum hitting_time_def hitting_time_eq_hitting_time inf_top.right_neutral leD downcrossing_mono downcrossing_simps(1) max_nat.left_neutral) next case (Suc n) hence upper_less: "upcrossing X a b N (Suc n) \ < N" using upcrossing_le_downcrossing Suc order.strict_trans1 by blast hence lower_less: "downcrossing X a b N n \ < N" using downcrossing_le_upcrossing_Suc order.strict_trans1 by blast obtain j where "j \ {downcrossing X a b N n \.. \ {b..}" using hitting_time_less_iff[THEN iffD1, OF order_refl] upper_less by (force simp add: upcrossing_simps) hence upper_eq: "upcrossing X a b N (Suc n) \ = upcrossing X a b N' (Suc n) \" using Suc(1)[OF lower_less] assms(1) by (auto simp add: upcrossing_simps intro!: hitting_time_eq_hitting_time) obtain j where j: "j \ {upcrossing X a b N (Suc n) \.. \ {..a}" using Suc(2) hitting_time_less_iff[THEN iffD1, OF order_refl] by (force simp add: downcrossing_simps) thus ?case unfolding downcrossing_simps upper_eq by (force intro: hitting_time_eq_hitting_time assms) qed thus "upcrossing X a b N n \ = upcrossing X a b N' n \" "downcrossing X a b N n \ = downcrossing X a b N' n \" by auto qed lemma crossing_eq_crossing': assumes "N \ N'" and "upcrossing X a b N (Suc n) \ < N" shows "upcrossing X a b N (Suc n) \ = upcrossing X a b N' (Suc n) \" "downcrossing X a b N n \ = downcrossing X a b N' n \" proof - show lower_eq: "downcrossing X a b N n \ = downcrossing X a b N' n \" using downcrossing_le_upcrossing_Suc[THEN order.strict_trans1] crossing_eq_crossing assms by fast have "\j\{downcrossing X a b N n \.. \ {b..}" using assms(2) by (intro hitting_time_less_iff[OF order_refl, THEN iffD1]) (simp add: upcrossing_simps lower_eq) then obtain j where "j\{downcrossing X a b N n \..N}" "X j \ \ {b..}" by fastforce thus "upcrossing X a b N (Suc n) \ = upcrossing X a b N' (Suc n) \" unfolding upcrossing_simps stopped_value_def using hitting_time_eq_hitting_time[OF assms(1)] lower_eq by metis qed lemma upcrossing_eq_upcrossing: assumes "N \ N'" and "upcrossing X a b N n \ < N" shows "upcrossing X a b N n \ = upcrossing X a b N' n \" using crossing_eq_crossing'[OF assms(1)] assms(2) upcrossing_simps by (cases n) (presburger, fast) lemma upcrossings_before_zero: "upcrossings_before X a b 0 \ = 0" unfolding upcrossings_before_def by simp lemma upcrossings_before_less_exists_upcrossing: assumes "a < b" and upcrossing: "N \ L" "X L \ < a" "L \ U" "b < X U \" shows "upcrossings_before X a b N \ < upcrossings_before X a b (Suc U) \" proof - have "upcrossing X a b (Suc U) (upcrossings_before X a b N \) \ \ L" using assms upcrossing_le[THEN order_trans, OF upcrossing(1)] by (cases "0 < N", subst upcrossing_eq_upcrossing[of N "Suc U", symmetric, OF _ upcrossing_less_of_le_upcrossings_before]) (auto simp add: upcrossings_before_zero upcrossing_simps) hence "downcrossing X a b (Suc U) (upcrossings_before X a b N \) \ \ U" unfolding downcrossing_simps using upcrossing by (force intro: hitting_time_le_iff[THEN iffD2]) hence "upcrossing X a b (Suc U) (Suc (upcrossings_before X a b N \)) \ < Suc U" unfolding upcrossing_simps using upcrossing by (force intro: hitting_time_less_iff[THEN iffD2]) thus ?thesis using cSup_upper[OF _ upcrossings_before_bdd_above[OF assms(1)]] upcrossings_before_def by fastforce qed lemma crossings_translate: "upcrossing X a b N = upcrossing (\n \. (X n \ + c)) (a + c) (b + c) N" "downcrossing X a b N = downcrossing (\n \. (X n \ + c)) (a + c) (b + c) N" proof - have upper: "upcrossing X a b N n = upcrossing (\n \. (X n \ + c)) (a + c) (b + c) N n" for n proof (induction n) case 0 then show ?case by (simp only: upcrossing.simps) next case (Suc n) have "((+) c ` {..a}) = {..a + c}" by simp moreover have "((+) c ` {b..}) = {b + c..}" by simp ultimately show ?case unfolding upcrossing.simps using hitting_time_translate[of X "{b..}" c] hitting_time_translate[of X "{..a}" c] Suc by presburger qed thus "upcrossing X a b N = upcrossing (\n \. (X n \ + c)) (a + c) (b + c) N" by blast have "((+) c ` {..a}) = {..a + c}" by simp thus "downcrossing X a b N = downcrossing (\n \. (X n \ + c)) (a + c) (b + c) N" using upper downcrossing_simps hitting_time_translate[of X "{..a}" c] by presburger qed lemma upcrossings_before_translate: "upcrossings_before X a b N = upcrossings_before (\n \. (X n \ + c)) (a + c) (b + c) N" using upcrossings_before_def crossings_translate by simp lemma crossings_pos_eq: assumes "a < b" shows "upcrossing X a b N = upcrossing (\n \. max 0 (X n \ - a)) 0 (b - a) N" "downcrossing X a b N = downcrossing (\n \. max 0 (X n \ - a)) 0 (b - a) N" proof - have *: "max 0 (x - a) \ {..0} \ x - a \ {..0}" "max 0 (x - a) \ {b - a..} \ x - a \ {b - a..}" for x using assms by auto have "upcrossing X a b N = upcrossing (\n \. X n \ - a) 0 (b - a) N" using crossings_translate[of X a b N "- a"] by simp thus upper: "upcrossing X a b N = upcrossing (\n \. max 0 (X n \ - a)) 0 (b - a) N" unfolding upcrossing_def hitting_time_def' using * by presburger thus "downcrossing X a b N = downcrossing (\n \. max 0 (X n \ - a)) 0 (b - a) N" unfolding downcrossing_simps hitting_time_def' using upper * by simp qed lemma upcrossings_before_mono: assumes "a < b" "N \ N'" shows "upcrossings_before X a b N \ \ upcrossings_before X a b N' \" proof (cases N) case 0 then show ?thesis unfolding upcrossings_before_def by simp next case (Suc N') hence "upcrossing X a b N 0 \ < N" unfolding upcrossing_simps by simp thus ?thesis unfolding upcrossings_before_def using upcrossings_before_bdd_above upcrossing_eq_upcrossing assms by (intro cSup_subset_mono) auto qed lemma upcrossings_before_pos_eq: assumes "a < b" shows "upcrossings_before X a b N = upcrossings_before (\n \. max 0 (X n \ - a)) 0 (b - a) N" using upcrossings_before_def crossings_pos_eq[OF assms] by simp \ \We define \upcrossings\ to be the total number of upcrossings a stochastic process completes as \N \ \\.\ definition upcrossings :: "(nat \ 'a \ real) \ real \ real \ 'a \ ennreal" where "upcrossings X a b = (\\. (SUP N. ennreal (upcrossings_before X a b N \)))" lemma upcrossings_measurable: assumes "adapted_process M F 0 X" "a < b" shows "upcrossings X a b \ borel_measurable M" unfolding upcrossings_def using upcrossings_before_measurable'[OF assms] by (auto intro!: borel_measurable_SUP) end lemma (in nat_finite_filtered_measure) integrable_upcrossings_before: assumes "adapted_process M F 0 X" "a < b" shows "integrable M (\\. real (upcrossings_before X a b N \))" proof - have "(\\<^sup>+ x. ennreal (norm (real (upcrossings_before X a b N x))) \M) \ (\\<^sup>+ x. ennreal N \M)" using upcrossings_before_le[OF assms(2)] by (intro nn_integral_mono) simp also have "... = ennreal N * emeasure M (space M)" by simp also have "... < \" by (metis emeasure_real ennreal_less_top ennreal_mult_less_top infinity_ennreal_def) finally show ?thesis by (intro integrableI_bounded upcrossings_before_measurable' assms) qed subsection \Doob's Upcrossing Inequality\ text \Doob's upcrossing inequality provides a bound on the expected number of upcrossings a submartingale completes before some point in time. The proof follows the proof presented in the paper \A Formalization of Doob's Martingale Convergence Theorems in mathlib\ \<^cite>\ying2022formalization\ \<^cite>\Degenne_Ying_2022\.\ context nat_finite_filtered_measure begin theorem upcrossing_inequality: fixes a b :: real and N :: nat assumes "submartingale M F 0 X" shows "(b - a) * (\\. real (upcrossings_before X a b N \) \M) \ (\\. max 0 (X N \ - a) \M)" proof - interpret submartingale_linorder M F 0 X unfolding submartingale_linorder_def by (intro assms) show ?thesis proof (cases "a < b") case True \ \We show the statement first for \<^term>\X 0\ non-negative and \<^term>\X N\ greater than or equal to \<^term>\a\.\ have *: "(b - a) * (\\. real (upcrossings_before X a b N \) \M) \ (\\. X N \ \M)" if asm: "submartingale M F 0 X" "a < b" "\\. X 0 \ \ 0" "\\. X N \ \ a" for a b X proof - interpret subm: submartingale M F 0 X by (intro asm) define C :: "nat \ 'a \ real" where "C = (\n \. \k < N. indicator {downcrossing X a b N k \..} n)" have C_values: "C n \ \ {0, 1}" for n \ proof (cases "\j < N. n \ {downcrossing X a b N j \..}") case True then obtain j where j: "j \ {.. {downcrossing X a b N j \..}" by blast { fix k l :: nat assume k_less_l: "k < l" hence Suc_k_le_l: "Suc k \ l" by simp have "{downcrossing X a b N k \..} \ {downcrossing X a b N l \..} = {downcrossing X a b N l \..}" using k_less_l upcrossing_mono downcrossing_mono by simp moreover have "upcrossing X a b N (Suc k) \ \ downcrossing X a b N l \" using upcrossing_le_downcrossing downcrossing_mono[OF Suc_k_le_l] order_trans by blast ultimately have "{downcrossing X a b N k \..} \ {downcrossing X a b N l \..} = {}" by simp } hence "disjoint_family_on (\k. {downcrossing X a b N k \..}) {.. = 1" unfolding C_def using sum_indicator_disjoint_family[where ?f="\_. 1"] j by fastforce thus ?thesis by blast next case False hence "C n \ = 0" unfolding C_def by simp thus ?thesis by simp qed hence C_interval: "C n \ \ {0..1}" for n \ by (metis atLeastAtMost_iff empty_iff insert_iff order.refl zero_less_one_class.zero_le_one) \ \We consider the discrete stochastic integral of \<^term>\C\ and \<^term>\\n \. 1 - C n \\.\ define C' where "C' = (\n \. \k < n. C k \ *\<^sub>R (X (Suc k) \ - X k \))" define one_minus_C' where "one_minus_C' = (\n \. \k < n. (1 - C k \) *\<^sub>R (X (Suc k) \ - X k \))" \ \We use the fact that the crossing times are stopping times to show that C is predictable.\ have adapted_C: "adapted_process M F 0 C" proof fix i have "(\\. indicat_real {downcrossing X a b N k \..} i) \ borel_measurable (F i)" for k unfolding indicator_def using stopping_time_upcrossing[OF subm.adapted_process_axioms, THEN stopping_time_measurable_gr] stopping_time_downcrossing[OF subm.adapted_process_axioms, THEN stopping_time_measurable_le] by force thus "C i \ borel_measurable (F i)" unfolding C_def by simp qed hence "adapted_process M F 0 (\n \. 1 - C n \)" by (intro adapted_process.diff_adapted adapted_process_const) hence submartingale_one_minus_C': "submartingale M F 0 one_minus_C'" unfolding one_minus_C'_def using C_interval by (intro submartingale_partial_sum_scaleR[of _ _ 1] submartingale_linorder.intro asm) auto have "C n \ borel_measurable M" for n using adapted_C adapted_process.adapted measurable_from_subalg subalg by blast have integrable_C': "integrable M (C' n)" for n unfolding C'_def using C_interval by (intro submartingale_partial_sum_scaleR[THEN submartingale.integrable] submartingale_linorder.intro adapted_C asm) auto \ \We show the following inequality, by using the fact that \<^term>\one_minus_C'\ is a submartingale.\ have "integral\<^sup>L M (C' n) \ integral\<^sup>L M (X n)" for n proof - interpret subm': submartingale_linorder M F 0 one_minus_C' unfolding submartingale_linorder_def by (rule submartingale_one_minus_C') have "0 \ integral\<^sup>L M (one_minus_C' n)" using subm'.set_integral_le[OF sets.top, where i=0 and j=n] space_F subm'.integrable by (fastforce simp add: set_integral_space one_minus_C'_def) moreover have "one_minus_C' n \ = (\k < n. X (Suc k) \ - X k \) - C' n \" for \ unfolding one_minus_C'_def C'_def by (simp only: scaleR_diff_left sum_subtractf scale_one) ultimately have "0 \ (LINT \|M. (\k < n. X (Suc k) \ - X k \)) - integral\<^sup>L M (C' n)" using subm.integrable integrable_C' by (subst Bochner_Integration.integral_diff[symmetric]) (auto simp add: one_minus_C'_def) moreover have "(LINT \|M. (\k - X k \)) \ (LINT \|M. X n \)" using asm sum_lessThan_telescope[of "\i. X i _" n] subm.integrable by (intro integral_mono) auto ultimately show ?thesis by linarith qed moreover have "(b - a) * (\\. real (upcrossings_before X a b N \) \M) \ integral\<^sup>L M (C' N)" proof (cases N) case 0 then show ?thesis using C'_def upcrossings_before_zero by simp next case (Suc N') { fix \ have dc_not_N: "downcrossing X a b N k \ \ N" if "k < upcrossings_before X a b N \" for k by (metis Suc Suc_leI asm(2) downcrossing_le_upcrossing_Suc leD that upcrossing_less_of_le_upcrossings_before zero_less_Suc) have uc_not_N:"upcrossing X a b N (Suc k) \ \ N" if "k < upcrossings_before X a b N \" for k by (metis Suc Suc_leI asm(2) order_less_irrefl that upcrossing_less_of_le_upcrossings_before zero_less_Suc) have subset_lessThan_N: "{downcrossing X a b N i \..} \ {.. \First we rewrite the sum as follows: \ have "C' N \ = (\ki..} k * (X (Suc k) \ - X k \))" unfolding C'_def C_def by (simp add: sum_distrib_right) also have "... = (\ik..} k * (X (Suc k) \ - X k \))" using sum.swap by fast also have "... = (\ik\{.. {downcrossing X a b N i \..}. X (Suc k) \ - X k \)" by (subst Indicator_Function.sum_indicator_mult) simp+ also have "... = (\ik\{downcrossing X a b N i \..}. X (Suc k) \ - X k \)" using subset_lessThan_N[THEN Int_absorb1] by simp also have "... = (\i) \ - X (downcrossing X a b N i \) \)" by (subst sum_Suc_diff'[OF downcrossing_le_upcrossing_Suc]) blast finally have *: "C' N \ = (\i) \ - X (downcrossing X a b N i \) \)" . \ \For \<^term>\k \ N\, we consider three cases: \ \ \1. If \<^term>\k < upcrossings_before X a b N \\, then \X (upcrossing X a b N (Suc k) \) \ - X (downcrossing X a b N k \) \ \ b - a\\ \ \2. If \<^term>\k > upcrossings_before X a b N \\, then \X (upcrossing X a b N (Suc k) \) \ = X (downcrossing X a b N k \) \\\ \ \3. If \<^term>\k = upcrossings_before X a b N \\, then \X (upcrossing X a b N (Suc k) \) \ - X (downcrossing X a b N k \) \ \ 0\\ have summand_zero_if: "X (upcrossing X a b N (Suc k) \) \ - X (downcrossing X a b N k \) \ = 0" if "k > upcrossings_before X a b N \" for k using that upcrossings_before_less_implies_crossing_eq_bound[OF asm(2)] by simp have summand_nonneg_if: "X (upcrossing X a b N (Suc (upcrossings_before X a b N \)) \) \ - X (downcrossing X a b N (upcrossings_before X a b N \) \) \ \ 0" using upcrossings_before_less_implies_crossing_eq_bound(1)[OF asm(2) lessI] stopped_value_downcrossing[of X a b N _ \, THEN order_trans, OF _ asm(4)[of \]] by (cases "downcrossing X a b N (upcrossings_before X a b N \) \ \ N") (simp add: stopped_value_def)+ have interval: "{upcrossings_before X a b N \..} = {upcrossings_before X a b N \<..) = (\_. b - a)" by simp also have "... \ (\k. stopped_value X (upcrossing X a b N (Suc k)) \ - stopped_value X (downcrossing X a b N k) \)" using stopped_value_downcrossing[OF dc_not_N] stopped_value_upcrossing[OF uc_not_N] by (force intro!: sum_mono) also have "... = (\k. X (upcrossing X a b N (Suc k) \) \ - X (downcrossing X a b N k \) \)" unfolding stopped_value_def by blast also have "... \ (\k. X (upcrossing X a b N (Suc k) \) \ - X (downcrossing X a b N k \) \) + (\k\{upcrossings_before X a b N \}. X (upcrossing X a b N (Suc k) \) \ - X (downcrossing X a b N k \) \) + (\k\{upcrossings_before X a b N \<..) \ - X (downcrossing X a b N k \) \)" using summand_zero_if summand_nonneg_if by auto also have "... = (\k) \ - X (downcrossing X a b N k \) \)" using upcrossings_before_le[OF asm(2)] by (subst sum.subset_diff[where A="{..) \ C' N \" using * by presburger } thus ?thesis using integrable_upcrossings_before subm.adapted_process_axioms asm integrable_C' by (subst integral_mult_right_zero[symmetric], intro integral_mono) auto qed ultimately show ?thesis using order_trans by blast qed have "(b - a) * (\\. real (upcrossings_before X a b N \) \M) = (b - a) * (\\. real (upcrossings_before (\n \. max 0 (X n \ - a)) 0 (b - a) N \) \M)" using upcrossings_before_pos_eq[OF True] by simp also have "... \ (\\. max 0 (X N \ - a) \M)" using *[OF submartingale_linorder.max_0[OF submartingale_linorder.intro, OF submartingale.diff, OF assms supermartingale_const], of 0 "b - a" a] True by simp finally show ?thesis . next case False have "0 \ (\\. max 0 (X N \ - a) \M)" by simp moreover have "0 \ (\\. real (upcrossings_before X a b N \) \M)" by simp moreover have "b - a \ 0" using False by simp ultimately show ?thesis using mult_nonpos_nonneg order_trans by meson qed qed theorem upcrossing_inequality_Sup: fixes a b :: real assumes "submartingale M F 0 X" shows "(b - a) * (\\<^sup>+\. upcrossings X a b \ \M) \ (SUP N. (\\<^sup>+\. max 0 (X N \ - a) \M))" proof - interpret submartingale M F 0 X by (intro assms) show ?thesis proof (cases "a < b") case True have "(\\<^sup>+\. upcrossings X a b \ \M) = (SUP N. (\\<^sup>+\. real (upcrossings_before X a b N \) \M))" unfolding upcrossings_def using upcrossings_before_mono True upcrossings_before_measurable'[OF adapted_process_axioms] by (auto intro: nn_integral_monotone_convergence_SUP simp add: mono_def le_funI) hence "(b - a) * (\\<^sup>+\. upcrossings X a b \ \M) = (SUP N. (b - a) * (\\<^sup>+\. real (upcrossings_before X a b N \) \M))" by (simp add: SUP_mult_left_ennreal) moreover { fix N have "(\\<^sup>+\. real (upcrossings_before X a b N \) \M) = (\\. real (upcrossings_before X a b N \) \M)" by (force intro!: nn_integral_eq_integral integrable_upcrossings_before True adapted_process_axioms) moreover have "(\\<^sup>+\. max 0 (X N \ - a) \M) = (\\. max 0 (X N \ - a) \M)" using Bochner_Integration.integrable_diff[OF integrable integrable_const] by (force intro!: nn_integral_eq_integral) ultimately have "(b - a) * (\\<^sup>+\. real (upcrossings_before X a b N \) \M) \ (\\<^sup>+\. max 0 (X N \ - a) \M)" using upcrossing_inequality[OF assms, of b a N] True ennreal_mult'[symmetric] by simp } ultimately show ?thesis by (force intro!: Sup_mono) qed (simp add: ennreal_neg) qed end end \ No newline at end of file