Theory Example_Coin_Toss
theory Example_Coin_Toss
imports Martingale "HOL-Probability.Stream_Space" "HOL-Probability.Probability_Mass_Function"
begin
section ‹Example: Coin Toss›
text ‹Consider a coin-tossing game, where the coin lands on heads with probability ‹p ∈ [0, 1]›. Assume that the gambler wins a fixed amount ‹c > 0› on a heads outcome
and loses the same amount ‹c› on a tails outcome. Let ‹(X⇩n)⇩n⇩∈⇩ℕ› be a stochastic process, where ‹X⇩n› denotes the gambler's fortune after the ‹n›-th coin toss.
Then, we have the following three cases.›
text ‹1. If ‹p = 1/2›, it means the coin is fair and has an equal chance of landing heads or tails.
In this case, the gambler, on average, neither wins nor loses money over time. The expected value of the gambler's fortune stays the same over time.
Therefore, ‹(X⇩n)⇩n⇩∈⇩ℕ› is a martingale.›
text ‹2. If ‹p ≥ 1/2› , it means the coin is biased in favor of heads. In this case, the gambler is more likely to win money on each bet.
Over time, the gambler's fortune tends to increase on average.
Therefore, ‹(X⇩n)⇩n⇩∈⇩ℕ› is a submartingale.›
text ‹3. If ‹p ≤ 1/2› , it means the coin is biased in favor of tails. In this scenario, the gambler is more likely to lose money on each bet.
Over time, the gambler's fortune decreases on average.
Therefore, ‹(X⇩n)⇩n⇩∈⇩ℕ› is a supermartingale.›
text ‹To formalize this example, we first consider a probability space consisting of infinite sequences of coin tosses.›
definition bernoulli_stream :: "real ⇒ (bool stream) measure" where
"bernoulli_stream p = stream_space (measure_pmf (bernoulli_pmf p))"
lemma space_bernoulli_stream[simp]: "space (bernoulli_stream p) = UNIV" by (simp add: bernoulli_stream_def space_stream_space)
text ‹We define the fortune of the player at time \<^term>‹n› to be the number of heads minus number of tails.›
definition fortune :: "nat ⇒ bool stream ⇒ real" where
"fortune n = (λs. ∑b ← stake (Suc n) s. if b then 1 else -1)"
definition toss :: "nat ⇒ bool stream ⇒ real" where
"toss n = (λs. if snth s n then 1 else -1)"
lemma toss_indicator_def: "toss n = indicator {s. s !! n} - indicator {s. ¬ s !! n}"
unfolding toss_def indicator_def by force
lemma range_toss: "range (toss n) = {-1, 1}"
proof -
have "sconst True !! n" by simp
moreover have "¬sconst False !! n" by simp
ultimately have "∃x. x !! n" "∃x. ¬x !! n" by blast+
thus ?thesis unfolding toss_def image_def by auto
qed
lemma vimage_toss: "toss n -` A = (if 1 ∈ A then {s. s !! n} else {}) ∪ (if -1 ∈ A then {s. ¬s !! n} else {})"
unfolding vimage_def toss_def by auto
lemma fortune_Suc: "fortune (Suc n) s = fortune n s + toss (Suc n) s"
by (induction n arbitrary: s) (simp add: fortune_def toss_def)+
lemma fortune_toss_sum: "fortune n s = (∑i ∈ {..n}. toss i s)"
by (induction n arbitrary: s) (simp add: fortune_def toss_def, simp add: fortune_Suc)
lemma fortune_bound: "norm (fortune n s) ≤ Suc n" by (induction n) (force simp add: fortune_toss_sum toss_def)+
text ‹Our definition of \<^term>‹bernoulli_stream› constitutes a probability space.›