From 9e87f47572a3ad00b802b1f17c4ccfbec86006b4 Mon Sep 17 00:00:00 2001 From: Remy Degenne Date: Sun, 15 Nov 2026 16:22:25 +0100 Subject: [PATCH 1/8] feat: the Wald inequality at the bipolar rate and the lower bound on expected stopping times MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For i.i.d. observations, an e-process E for the i.i.d. null of S₁ and a stopping time τ with values in ℕ satisfy E_Q[log E_τ] ≤ E_Q[τ + 1] * bipolarRate Q₁ S₁ in EReal, with no integrability assumption on τ. Its case of the e-process ε + (1 - ε) α⁻¹ 𝟙{τ ≤ n} gives the lower bound log (1/α) / bipolarRate Q₁ S₁ ≤ E_Q[τ + 1] for every sequential test τ of level α. EValues roadmap, Layer 6, item 3 (expected stopping times), first bullet. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0196ftMVbgjSJzPQEwdek3kM --- .../EValues/BipolarRate/StoppingTime.lean | 1304 +++++++++++++++++ 1 file changed, 1304 insertions(+) create mode 100644 LMLExplore/EValues/BipolarRate/StoppingTime.lean diff --git a/LMLExplore/EValues/BipolarRate/StoppingTime.lean b/LMLExplore/EValues/BipolarRate/StoppingTime.lean new file mode 100644 index 00000000..6292ee6d --- /dev/null +++ b/LMLExplore/EValues/BipolarRate/StoppingTime.lean @@ -0,0 +1,1304 @@ +/- +Copyright (c) 2026 LMLExplore contributors. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: LMLExplore contributors +-/ +module + +public import LMLExplore.EValues.BipolarRate.Basic +public import LMLExplore.EValues.EProcess +public import Mathlib.Probability.ProductMeasure +import LMLExplore.EValues.BipolarRate.EProcess +import LMLExplore.Probability.Process.Stopping +import LMLExplore.Probability.Process.StoppedValue +import Mathlib.Probability.Independence.Integration +import Statlib.ForMathlib.MeasureTheory.Integral.EReal.Bochner +import TauCeti.Probability.Process.PathLaw.Shift + +/-! +# Expected stopping times are governed by the bipolar rate + +Let `S₁` be a set of probability measures on `𝓧` (the null) and `Q₁` a probability measure on `𝓧` +(the alternative). The observations are the coordinates of `ℕ → 𝓧`, with the i.i.d. laws +`Measure.infinitePi fun _ ↦ P`, `P ∈ S₁`, and the filtration `Filtration.piLE`, so that `τ + 1` +observations have been made at a time `τ`. Write `d = bipolarRate Q₁ S₁` and `Q` for the i.i.d. law +of `Q₁`. + +The **Wald inequality** at the bipolar rate: for every e-process `E` for the i.i.d. null and every +stopping time `τ` with values in `ℕ`, `𝔼_Q[log E_τ] ≤ 𝔼_Q[τ + 1] * d`, in `EReal`, with +Statlib's extended integral on the left. Nothing is assumed of `S₁` beyond its members being +probability measures, and nothing of `Q₁`. The expectation of `τ` may be infinite, with +`∞ * 0 = 0`: if `d = 0`, the e-process has a nonpositive expected logarithm at every stopping +time. + +Its case `E n = α⁻¹ * 𝟙{τ ≤ n}` (mixed with a constant, so that its logarithm is finite) is the +**lower bound on expected stopping times**: a sequential test of level `α`, that is, a stopping +time `τ` with values in `WithTop ℕ` such that `P^ℕ (τ < ∞) ≤ α` for every `P ∈ S₁`, makes at least +`log (1/α) / d` observations in expectation under `Q`. If `d = 0`, every test of a level `α < 1` +has an infinite expected number of observations. Since `d` is at most the smallest relative +entropy `KL_inf(Q₁, S₁)` from `Q₁` to the null (`ProbabilityTheory.bipolarRate_le_iInf_klDiv`), +this contains the lower bound with `KL_inf(Q₁, S₁)` in place of `d`, the form of the bounds of +[ARR26]; the bipolar rate can be smaller [RR26, Proposition 5.4]. + +## Main statements + +* `ProbabilityTheory.IsEProcess.eintegral_log_stoppedValue_le_mul_bipolarRate`: the Wald + inequality `𝔼_Q[log E_τ] ≤ 𝔼_Q[τ + 1] * d`. +* `ProbabilityTheory.toENNReal_log_inv_div_bipolarRate_le_lintegral`: a sequential test of level + `α` has `log (1/α) / d ≤ 𝔼_Q[τ + 1]`. + +## Implementation notes + +The proof restarts the round, the e-process stopped at `τ`, on the fresh observations each time +it ends, and bets on the number of completed rounds with a geometric mixture. Within the first +`N` observations, the mixture over the rounds completed so far of the products of their payoffs +is an `N`-sample e-variable: under the i.i.d. law of a member of the null, the first `t` +observations are independent of the later ones. Its expected logarithm under `Q` is at most +`maxLogGrowth Q₁ S₁ N ≤ N * d`. A Wald argument shows that the rounds that start within the first +`N` observations use at least `N + 1` observations, hence that `(N + 1) / 𝔼_Q[τ + 1]` of them +start in expectation; letting `N → ∞` bounds the expected truncated logarithm of the payoff of a +round by `𝔼_Q[τ + 1] * d`. The payoff is first mixed with a constant `ε`, so that its logarithm +is bounded below, and the stopping time is first bounded by `k`; the truncation, `ε` and `k` are +removed at the end. The proof uses neither the law of large numbers nor the strong Markov +property: only the independence of the first `t` observations from the later ones, summed over +the values `t` of the restart times. + +## References + +* [ARR26] S. Agrawal, A. Ram and A. Ramdas, *On stopping times of power-one sequential tests: + tight lower and upper bounds*, arXiv:2504.19952v2. +* [RR26] A. Ram and A. Ramdas, *The optimal betting wealth growth rate*, arXiv:2604.25280v1. +-/ + +public section + +open MeasureTheory Filter +open TauCeti.Probability (shift shift_iterate_apply shift_iterate_eq_reindex + measurable_shift_iterate) +open scoped ENNReal Topology + +namespace ProbabilityTheory + +variable {𝓧 : Type*} {m𝓧 : MeasurableSpace 𝓧} {S₁ : Set (Measure 𝓧)} + +/-! ### The observations after the first ones -/ + +/-- The shift by `t` observations preserves the i.i.d. law. -/ +private lemma measurePreserving_shift_iterate (P : Measure 𝓧) [IsProbabilityMeasure P] (t : ℕ) : + MeasurePreserving ((shift 𝓧)^[t]) (Measure.infinitePi fun _ : ℕ ↦ P) + (Measure.infinitePi fun _ : ℕ ↦ P) := by + refine ⟨measurable_shift_iterate t, ?_⟩ + rw [shift_iterate_eq_reindex] + exact Measure.map_infinitePi_infinitePi_of_inj (add_left_injective t) + +/-- Under an i.i.d. law, the first `t` observations are independent of the observations after +them. -/ +private lemma indepFun_initSeg_shift_iterate (P : Measure 𝓧) [IsProbabilityMeasure P] (t : ℕ) : + IndepFun (initSeg t) ((shift 𝓧)^[t]) (Measure.infinitePi fun _ : ℕ ↦ P) := by + have h := (iIndepFun_infinitePi (P := fun _ : ℕ ↦ P) (X := fun _ x ↦ x) + (fun _ ↦ measurable_id)).indepFun_set (Set.Iio t) (Set.Ici t) + (Set.disjoint_left.2 fun i (hi : i < t) (hi' : t ≤ i) ↦ (not_lt.2 hi') hi) + (fun i ↦ measurable_pi_apply i) + rw [shift_iterate_eq_reindex, initSeg_def] + exact h.comp (φ := fun (y : Set.Iio t → 𝓧) (i : Fin t) ↦ y ⟨i, i.2⟩) + (ψ := fun (y : Set.Ici t → 𝓧) (i : ℕ) ↦ y ⟨i + t, Nat.le_add_left t i⟩) + (by fun_prop) (by fun_prop) + +/-- Under an i.i.d. law, a function of the first `t` observations is independent of a function of +the observations after them. -/ +private lemma lintegral_mul_comp_shift_iterate (P : Measure 𝓧) [IsProbabilityMeasure P] + {f g : (ℕ → 𝓧) → ℝ≥0∞} {t : ℕ} (hf : Measurable f) (hft : DependsOn f (Set.Iio t)) + (hg : Measurable g) : + ∫⁻ ω, f ω * g ((shift 𝓧)^[t] ω) ∂Measure.infinitePi (fun _ : ℕ ↦ P) = + (∫⁻ ω, f ω ∂Measure.infinitePi (fun _ : ℕ ↦ P)) * + ∫⁻ ω, g ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) := by + have := nonempty_of_isProbabilityMeasure P + obtain ⟨F, hF, rfl⟩ := exists_measurable_eq_comp_initSeg hf hft + rw [← (measurePreserving_shift_iterate P t).lintegral_comp hg] + exact lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun (hF.comp (measurable_initSeg t)) + (hg.comp (measurable_shift_iterate t)) ((indepFun_initSeg_shift_iterate P t).comp hF hg) + +/-- Under an i.i.d. law, a real function of the first `t` observations is independent of a real +function of the observations after them. -/ +private lemma integral_mul_comp_shift_iterate (P : Measure 𝓧) [IsProbabilityMeasure P] + {f g : (ℕ → 𝓧) → ℝ} {t : ℕ} (hf : Measurable f) (hft : DependsOn f (Set.Iio t)) + (hg : Measurable g) : + ∫ ω, f ω * g ((shift 𝓧)^[t] ω) ∂Measure.infinitePi (fun _ : ℕ ↦ P) = + (∫ ω, f ω ∂Measure.infinitePi (fun _ : ℕ ↦ P)) * + ∫ ω, g ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) := by + have := nonempty_of_isProbabilityMeasure P + obtain ⟨F, hF, rfl⟩ := exists_measurable_eq_comp_initSeg hf hft + have hmap : ∫ ω, g ((shift 𝓧)^[t] ω) ∂Measure.infinitePi (fun _ : ℕ ↦ P) = + ∫ ω, g ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) := by + rw [← integral_map (measurable_shift_iterate t).aemeasurable + (by rw [(measurePreserving_shift_iterate P t).map_eq]; exact hg.aestronglyMeasurable), + (measurePreserving_shift_iterate P t).map_eq] + rw [← hmap] + exact ((indepFun_initSeg_shift_iterate P t).comp hF hg).integral_fun_mul_eq_mul_integral + (hF.comp (measurable_initSeg t)).aestronglyMeasurable + (hg.comp (measurable_shift_iterate t)).aestronglyMeasurable + +/-! ### Stopping times of the observations -/ + +section StoppingTime + +variable {τ : (ℕ → 𝓧) → ℕ} + +/-- A stopping time of the observations with values in `ℕ` is measurable. -/ +private lemma measurable_of_isStoppingTime_nat + (hτ : IsStoppingTime (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) fun ω ↦ (τ ω : WithTop ℕ)) : + Measurable τ := by + convert (measurable_of_countable (WithTop.untopD 0)).comp hτ.measurable' using 1 + exact funext fun ω ↦ (WithTop.untopD_coe 0 (τ ω)).symm + +/-- A stopping time of the observations with values in `ℕ` is determined by the observations up +to it. -/ +private lemma eq_of_isStoppingTime_of_forall_le + (hτ : IsStoppingTime (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) fun ω ↦ (τ ω : WithTop ℕ)) + {ω ω' : ℕ → 𝓧} (h : ∀ i ≤ τ ω, ω i = ω' i) : τ ω' = τ ω := by + have hm : MeasurableSet[Filtration.piLE (τ ω)] {ω' | τ ω' = τ ω} := by + simpa using hτ.measurableSet_eq (τ ω) + have hd : DependsOn ({ω' | τ ω' = τ ω}.indicator fun _ ↦ (1 : ℕ)) (Set.Iic (τ ω)) := + (measurable_const.indicator hm).dependsOn_of_piLE + have h1 := hd fun i hi ↦ h i hi + by_contra hne + simp [Set.indicator, hne] at h1 + +/-- The minimum of a stopping time with values in `ℕ` and a constant is a stopping time. -/ +private lemma isStoppingTime_min_nat + (hτ : IsStoppingTime (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) fun ω ↦ (τ ω : WithTop ℕ)) + (k : ℕ) : + IsStoppingTime (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) + fun ω ↦ ((min (τ ω) k : ℕ) : WithTop ℕ) := by + have h : (fun ω ↦ ((min (τ ω) k : ℕ) : WithTop ℕ)) = fun ω ↦ min (τ ω : WithTop ℕ) k := + funext fun ω ↦ WithTop.coe_min _ _ + rw [h] + exact hτ.min_natCast k + +end StoppingTime + +/-! ### Restarting a round on the fresh observations + +A round is a pair of a duration `σ : (ℕ → 𝓧) → ℕ`, the number of observations that it uses, and a +payoff `V : (ℕ → 𝓧) → ℝ≥0∞`, both determined by the observations of the round. Restarting the +round on the fresh observations at its end gives the restart times `restartTime σ j` and the +products `restartPayoff σ V j` of the payoffs of the first `j` rounds. -/ + +/-- `f` is determined by the first `σ` observations: if `σ ω ≤ u` and `ω'` agrees with `ω` on the +first `u` observations, then `f ω' = f ω`. For `f = σ`, this says that `σ` is a stopping time +counted in observations. -/ +private def DependsOnBefore {β : Type*} (σ : (ℕ → 𝓧) → ℕ) (f : (ℕ → 𝓧) → β) : Prop := + ∀ ⦃u : ℕ⦄ ⦃ω ω' : ℕ → 𝓧⦄, (∀ i < u, ω i = ω' i) → σ ω ≤ u → f ω' = f ω + +section Restart + +variable (σ : (ℕ → 𝓧) → ℕ) (V : (ℕ → 𝓧) → ℝ≥0∞) + +/-- The number of observations used by the first `j` rounds, when a round that uses `σ ω` +observations is restarted on the fresh observations at its end. -/ +private def restartTime : ℕ → (ℕ → 𝓧) → ℕ + | 0 => fun _ ↦ 0 + | j + 1 => fun ω ↦ restartTime j ω + σ ((shift 𝓧)^[restartTime j ω] ω) + +/-- The product of the payoffs `V` of the first `j` restarted rounds. -/ +private noncomputable def restartPayoff : ℕ → (ℕ → 𝓧) → ℝ≥0∞ + | 0 => fun _ ↦ 1 + | j + 1 => fun ω ↦ restartPayoff j ω * V ((shift 𝓧)^[restartTime σ j ω] ω) + +/-- The round after the first `j` ones is played on the observations after them. -/ +private lemma restartTime_succ (j : ℕ) (ω : ℕ → 𝓧) : + restartTime σ (j + 1) ω = restartTime σ j ω + σ ((shift 𝓧)^[restartTime σ j ω] ω) := + rfl + +/-- The payoff of `j + 1` rounds is that of the first `j` times that of the next one. -/ +private lemma restartPayoff_succ (j : ℕ) (ω : ℕ → 𝓧) : + restartPayoff σ V (j + 1) ω = + restartPayoff σ V j ω * V ((shift 𝓧)^[restartTime σ j ω] ω) := + rfl + +/-- The restart times are nondecreasing in the number of rounds. -/ +private lemma monotone_restartTime (ω : ℕ → 𝓧) : Monotone fun j ↦ restartTime σ j ω := + monotone_nat_of_le_succ fun _ ↦ Nat.le_add_right _ _ + +/-- If every round uses at least one observation, `j` rounds use at least `j` observations. -/ +private lemma le_restartTime (hσ1 : ∀ ω, 1 ≤ σ ω) (j : ℕ) (ω : ℕ → 𝓧) : + j ≤ restartTime σ j ω := by + induction j with + | zero => exact le_rfl + | succ j ih => exact Nat.add_le_add ih (hσ1 _) + +/-- The first `j` rounds use the sum of their durations. -/ +private lemma restartTime_eq_sum (j : ℕ) (ω : ℕ → 𝓧) : + restartTime σ j ω = ∑ i ∈ Finset.range j, σ ((shift 𝓧)^[restartTime σ i ω] ω) := by + induction j with + | zero => rfl + | succ j ih => rw [Finset.sum_range_succ, ← ih, restartTime_succ] + +/-- The payoff of the first `j` rounds is the product of their payoffs. -/ +private lemma restartPayoff_eq_prod (j : ℕ) (ω : ℕ → 𝓧) : + restartPayoff σ V j ω = ∏ i ∈ Finset.range j, V ((shift 𝓧)^[restartTime σ i ω] ω) := by + induction j with + | zero => rfl + | succ j ih => rw [Finset.prod_range_succ, ← ih, restartPayoff_succ] + +variable {σ V} + +/-- A measurable function of the observations after a measurable random number of them is +measurable. -/ +private lemma measurable_comp_shift_iterate {β : Type*} [MeasurableSpace β] + {h : (ℕ → 𝓧) → β} (hh : Measurable h) {T : (ℕ → 𝓧) → ℕ} (hT : Measurable T) : + Measurable fun ω ↦ h ((shift 𝓧)^[T ω] ω) := + measurable_apply_of_countable (u := fun t ω ↦ h ((shift 𝓧)^[t] ω)) + (fun t ↦ hh.comp (measurable_shift_iterate t)) hT + +/-- The restart times are measurable. -/ +private lemma measurable_restartTime (hσm : Measurable σ) (j : ℕ) : + Measurable (restartTime σ j) := by + induction j with + | zero => exact measurable_const + | succ j ih => exact ih.add (measurable_comp_shift_iterate hσm ih) + +/-- The products of the payoffs of the restarted rounds are measurable. -/ +private lemma measurable_restartPayoff (hσm : Measurable σ) (hVm : Measurable V) (j : ℕ) : + Measurable (restartPayoff σ V j) := by + induction j with + | zero => exact measurable_const + | succ j ih => exact ih.mul (measurable_comp_shift_iterate hVm (measurable_restartTime hσm j)) + +/-- The first `j` rounds are determined by the observations that they use. -/ +private lemma restartTime_eq_of_eqOn (hσ : DependsOnBefore σ σ) (j : ℕ) {t : ℕ} + {ω ω' : ℕ → 𝓧} (h : ∀ i < t, ω i = ω' i) (hj : restartTime σ j ω ≤ t) : + restartTime σ j ω' = restartTime σ j ω := by + induction j with + | zero => rfl + | succ j ih => + rw [restartTime_succ] at hj + have h1 := ih (by omega) + have hshift : ∀ i < t - restartTime σ j ω, + (shift 𝓧)^[restartTime σ j ω] ω i = (shift 𝓧)^[restartTime σ j ω] ω' i := fun i hi ↦ by + simp only [shift_iterate_apply] + exact h _ (by omega) + rw [restartTime_succ, restartTime_succ, h1, hσ hshift (by omega)] + +/-- The payoffs of the first `j` rounds are determined by the observations that they use. -/ +private lemma restartPayoff_eq_of_eqOn (hσ : DependsOnBefore σ σ) (hV : DependsOnBefore σ V) + (j : ℕ) {t : ℕ} {ω ω' : ℕ → 𝓧} (h : ∀ i < t, ω i = ω' i) (hj : restartTime σ j ω ≤ t) : + restartPayoff σ V j ω' = restartPayoff σ V j ω := by + induction j with + | zero => rfl + | succ j ih => + rw [restartTime_succ] at hj + have h1 := restartTime_eq_of_eqOn hσ j h (by omega) + have h2 := ih (by omega) + have hshift : ∀ i < t - restartTime σ j ω, + (shift 𝓧)^[restartTime σ j ω] ω i = (shift 𝓧)^[restartTime σ j ω] ω' i := fun i hi ↦ by + simp only [shift_iterate_apply] + exact h _ (by omega) + rw [restartPayoff_succ, restartPayoff_succ, h1, h2, hV hshift (by omega)] + +/-- Whether the first `j` rounds use exactly `t` observations is determined by the first `t` +observations. -/ +private lemma restartTime_eq_iff_of_eqOn (hσ : DependsOnBefore σ σ) (j t : ℕ) {ω ω' : ℕ → 𝓧} + (h : ∀ i < t, ω i = ω' i) : restartTime σ j ω' = t ↔ restartTime σ j ω = t := + ⟨fun h' ↦ (restartTime_eq_of_eqOn hσ j (fun i hi ↦ (h i hi).symm) h'.le).trans h', + fun h' ↦ (restartTime_eq_of_eqOn hσ j h h'.le).trans h'⟩ + +/-- Whether the first `j` rounds use at most `N` observations is determined by the first `N` +observations. -/ +private lemma restartTime_le_iff_of_eqOn (hσ : DependsOnBefore σ σ) (j N : ℕ) {ω ω' : ℕ → 𝓧} + (h : ∀ i < N, ω i = ω' i) : restartTime σ j ω' ≤ N ↔ restartTime σ j ω ≤ N := + ⟨fun h' ↦ (restartTime_eq_of_eqOn hσ j (fun i hi ↦ (h i hi).symm) h') ▸ h', + fun h' ↦ (restartTime_eq_of_eqOn hσ j h h').symm ▸ h'⟩ + +/-- On the event that the first `j` rounds use `t` observations, their payoff is a function of +the first `t` observations. -/ +private lemma dependsOn_indicator_restartTime_eq (hσ : DependsOnBefore σ σ) + (hV : DependsOnBefore σ V) (j t : ℕ) : + DependsOn ({ω | restartTime σ j ω = t}.indicator (restartPayoff σ V j)) (Set.Iio t) := by + intro ω ω' h + have h' : ∀ i < t, ω i = ω' i := fun i hi ↦ h i hi + by_cases hω : restartTime σ j ω = t + · have hω' := (restartTime_eq_iff_of_eqOn hσ j t h').2 hω + simp only [Set.indicator, Set.mem_ofPred_eq, hω, hω', ite_true] + exact (restartPayoff_eq_of_eqOn hσ hV j h' hω.le).symm + · have hω' : ¬ restartTime σ j ω' = t := mt (restartTime_eq_iff_of_eqOn hσ j t h').1 hω + simp [Set.indicator, hω, hω'] + +/-- The indicator of the event that the first `i` rounds use `t` observations is a function of +the first `t` observations. -/ +private lemma dependsOn_indicator_one_restartTime_eq (hσ : DependsOnBefore σ σ) (i t : ℕ) : + DependsOn ({ω | restartTime σ i ω = t}.indicator (1 : (ℕ → 𝓧) → ℝ)) (Set.Iio t) := by + intro ω ω' h + have h' := restartTime_eq_iff_of_eqOn hσ i t (ω := ω) (ω' := ω') fun i hi ↦ h i hi + by_cases hω : restartTime σ i ω = t + · simp [Set.indicator, hω, h'.2 hω] + · simp [Set.indicator, hω, mt h'.1 hω] + +/-- On the event that the first `j` rounds use at most `N` observations, their payoff is a +function of the first `N` observations. -/ +private lemma dependsOn_indicator_restartTime_le (hσ : DependsOnBefore σ σ) + (hV : DependsOnBefore σ V) (j N : ℕ) : + DependsOn ({ω | restartTime σ j ω ≤ N}.indicator (restartPayoff σ V j)) (Set.Iio N) := by + intro ω ω' h + have h' : ∀ i < N, ω i = ω' i := fun i hi ↦ h i hi + by_cases hω : restartTime σ j ω ≤ N + · have hω' := (restartTime_le_iff_of_eqOn hσ j N h').2 hω + simp only [Set.indicator, Set.mem_ofPred_eq, hω, hω', ite_true] + exact (restartPayoff_eq_of_eqOn hσ hV j h' hω).symm + · have hω' : ¬ restartTime σ j ω' ≤ N := mt (restartTime_le_iff_of_eqOn hσ j N h').1 hω + simp [Set.indicator, hω, hω'] + +/-- Summing the indicators of the events `{T = t}`, `t ≤ N`, gives the indicator of `{T ≤ N}`. -/ +private lemma sum_indicator_eq_indicator_le {Ω M : Type*} [AddCommMonoid M] (T : Ω → ℕ) + (f : Ω → M) (N : ℕ) (ω : Ω) : + ∑ t ∈ Finset.range (N + 1), {ω | T ω = t}.indicator f ω = {ω | T ω ≤ N}.indicator f ω := by + by_cases h : T ω ≤ N + · rw [Finset.sum_eq_single (T ω), Set.indicator_of_mem (s := {ω | T ω ≤ N}) h, + Set.indicator_of_mem (s := {x | T x = T ω}) rfl] + · exact fun t _ ht ↦ Set.indicator_of_notMem (Ne.symm ht) _ + · exact fun hT ↦ absurd (Finset.mem_range.2 (Nat.lt_succ_of_le h)) hT + · rw [Set.indicator_of_notMem h] + refine Finset.sum_eq_zero fun t ht ↦ Set.indicator_of_notMem ?_ _ + rw [Finset.mem_range] at ht + exact fun h' ↦ h (by rw [Set.mem_ofPred_eq] at h'; omega) + +/-- The event that the first `j` rounds use at most `N` observations is measurable. -/ +private lemma measurableSet_restartTime_le (hσm : Measurable σ) (j N : ℕ) : + MeasurableSet {ω | restartTime σ j ω ≤ N} := + measurable_restartTime hσm j measurableSet_Iic + +/-- The event that the first `j` rounds use exactly `t` observations is measurable. -/ +private lemma measurableSet_restartTime_eq (hσm : Measurable σ) (j t : ℕ) : + MeasurableSet {ω | restartTime σ j ω = t} := + measurable_restartTime hσm j (measurableSet_singleton t) + +/-- The payoff of `j + 1` rounds within `N` observations, decomposed along the number `t` of +observations used by the first `j` rounds. -/ +private lemma indicator_restartTime_succ_le (j N : ℕ) (ω : ℕ → 𝓧) : + {ω | restartTime σ (j + 1) ω ≤ N}.indicator (restartPayoff σ V (j + 1)) ω = + ∑ t ∈ Finset.range (N + 1), + {ω | restartTime σ j ω = t}.indicator (restartPayoff σ V j) ω * + {ω | σ ω ≤ N - t}.indicator V ((shift 𝓧)^[t] ω) := by + have hterm (t : ℕ) : {ω | restartTime σ j ω = t}.indicator (restartPayoff σ V j) ω * + {ω | σ ω ≤ N - t}.indicator V ((shift 𝓧)^[t] ω) = + {ω | restartTime σ j ω = t}.indicator (fun ω' ↦ restartPayoff σ V j ω' * + {x | σ x ≤ N - restartTime σ j ω'}.indicator V + ((shift 𝓧)^[restartTime σ j ω'] ω')) ω := by + by_cases h : restartTime σ j ω = t + · rw [Set.indicator_of_mem (s := {x | restartTime σ j x = t}) h, + Set.indicator_of_mem (s := {x | restartTime σ j x = t}) h, h] + · rw [Set.indicator_of_notMem (s := {x | restartTime σ j x = t}) h, + Set.indicator_of_notMem (s := {x | restartTime σ j x = t}) h, zero_mul] + rw [Finset.sum_congr rfl fun t _ ↦ hterm t, sum_indicator_eq_indicator_le] + simp only [Set.indicator, Set.mem_ofPred_eq, restartTime_succ, restartPayoff_succ] + by_cases h1 : restartTime σ j ω ≤ N + · by_cases h2 : σ ((shift 𝓧)^[restartTime σ j ω] ω) ≤ N - restartTime σ j ω + · have h3 : restartTime σ j ω + σ ((shift 𝓧)^[restartTime σ j ω] ω) ≤ N := by omega + simp only [h1, h2, h3, ↓reduceIte] + · have h3 : ¬ restartTime σ j ω + σ ((shift 𝓧)^[restartTime σ j ω] ω) ≤ N := by omega + simp only [h1, h2, h3, ↓reduceIte, mul_zero] + · have h3 : ¬ restartTime σ j ω + σ ((shift 𝓧)^[restartTime σ j ω] ω) ≤ N := by omega + simp only [h1, h3, ↓reduceIte] + +/-- If the payoff of a round has expectation at most `1` on each event `{σ ≤ n}` under an i.i.d. +law, so has the product of the payoffs of `j` restarted rounds on each event that they use at most +`N` observations. -/ +private lemma lintegral_indicator_restartPayoff_le_one (hσ : DependsOnBefore σ σ) + (hV : DependsOnBefore σ V) (hσm : Measurable σ) (hVm : Measurable V) + (P : Measure 𝓧) [IsProbabilityMeasure P] + (h_null : ∀ n : ℕ, + ∫⁻ ω, {ω | σ ω ≤ n}.indicator V ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) ≤ 1) + (j N : ℕ) : + ∫⁻ ω, {ω | restartTime σ j ω ≤ N}.indicator (restartPayoff σ V j) ω + ∂Measure.infinitePi (fun _ : ℕ ↦ P) ≤ 1 := by + set μ := Measure.infinitePi (fun _ : ℕ ↦ P) + induction j generalizing N with + | zero => + calc ∫⁻ ω, {ω | restartTime σ 0 ω ≤ N}.indicator (restartPayoff σ V 0) ω ∂μ + _ ≤ ∫⁻ _, 1 ∂μ := lintegral_mono fun ω ↦ Set.indicator_le (fun _ _ ↦ le_rfl) ω + _ = 1 := by simp + | succ j ih => + have hf (t : ℕ) : + Measurable ({ω | restartTime σ j ω = t}.indicator (restartPayoff σ V j)) := + (measurable_restartPayoff hσm hVm j).indicator + (measurableSet_restartTime_eq hσm j t) + have hg (t : ℕ) : Measurable ({ω | σ ω ≤ N - t}.indicator V) := + hVm.indicator (hσm measurableSet_Iic) + calc ∫⁻ ω, {ω | restartTime σ (j + 1) ω ≤ N}.indicator (restartPayoff σ V (j + 1)) ω ∂μ + _ = ∑ t ∈ Finset.range (N + 1), + ∫⁻ ω, {ω | restartTime σ j ω = t}.indicator (restartPayoff σ V j) ω * + {ω | σ ω ≤ N - t}.indicator V ((shift 𝓧)^[t] ω) ∂μ := by + simp_rw [indicator_restartTime_succ_le] + exact lintegral_finsetSum _ fun t _ ↦ + (hf t).mul ((hg t).comp (measurable_shift_iterate t)) + _ = ∑ t ∈ Finset.range (N + 1), + (∫⁻ ω, {ω | restartTime σ j ω = t}.indicator (restartPayoff σ V j) ω ∂μ) * + ∫⁻ ω, {ω | σ ω ≤ N - t}.indicator V ω ∂μ := + Finset.sum_congr rfl fun t _ ↦ lintegral_mul_comp_shift_iterate P (hf t) + (dependsOn_indicator_restartTime_eq hσ hV j t) (hg t) + _ ≤ ∑ t ∈ Finset.range (N + 1), + ∫⁻ ω, {ω | restartTime σ j ω = t}.indicator (restartPayoff σ V j) ω ∂μ := + Finset.sum_le_sum fun t _ ↦ mul_le_of_le_one_right' (h_null _) + _ = ∫⁻ ω, {ω | restartTime σ j ω ≤ N}.indicator (restartPayoff σ V j) ω ∂μ := by + rw [← lintegral_finsetSum _ fun t _ ↦ hf t] + exact lintegral_congr fun ω ↦ sum_indicator_eq_indicator_le _ _ N ω + _ ≤ 1 := ih N + +variable (σ V) in +/-- The geometric mixture, with weights `(1 - r) r ^ j`, of the products of the payoffs of the +first `j` rounds on the event that they use at most `N` observations. -/ +private noncomputable def restartMixture (r : ℝ) (N : ℕ) (ω : ℕ → 𝓧) : ℝ≥0∞ := + ∑ j ∈ Finset.range (N + 1), ENNReal.ofReal ((1 - r) * r ^ j) * + {ω | restartTime σ j ω ≤ N}.indicator (restartPayoff σ V j) ω + +/-- The mixture of restarted rounds is measurable. -/ +private lemma measurable_restartMixture (hσm : Measurable σ) (hVm : Measurable V) (r : ℝ) + (N : ℕ) : Measurable (restartMixture σ V r N) := + Finset.measurable_fun_sum _ fun j _ ↦ measurable_const.mul + ((measurable_restartPayoff hσm hVm j).indicator + (measurableSet_restartTime_le hσm j N)) + +/-- The mixture of the rounds completed within the first `N` observations is a function of the +first `N` observations. -/ +private lemma dependsOn_restartMixture (hσ : DependsOnBefore σ σ) (hV : DependsOnBefore σ V) + (r : ℝ) (N : ℕ) : DependsOn (restartMixture σ V r N) (Set.Iio N) := fun ω ω' h ↦ + Finset.sum_congr rfl fun j _ ↦ by rw [dependsOn_indicator_restartTime_le hσ hV j N h] + +/-- The mixture of restarted rounds has expectation at most `1` under an i.i.d. law for which the +payoff of a round has expectation at most `1` on each event `{σ ≤ n}`. -/ +private lemma lintegral_restartMixture_le_one (hσ : DependsOnBefore σ σ) + (hV : DependsOnBefore σ V) (hσm : Measurable σ) (hVm : Measurable V) (P : Measure 𝓧) + [IsProbabilityMeasure P] + (h_null : ∀ n : ℕ, + ∫⁻ ω, {ω | σ ω ≤ n}.indicator V ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) ≤ 1) + {r : ℝ} (hr0 : 0 ≤ r) (hr1 : r ≤ 1) (N : ℕ) : + ∫⁻ ω, restartMixture σ V r N ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) ≤ 1 := by + have hm (j : ℕ) : + Measurable ({ω | restartTime σ j ω ≤ N}.indicator (restartPayoff σ V j)) := + (measurable_restartPayoff hσm hVm j).indicator + (measurableSet_restartTime_le hσm j N) + simp only [restartMixture] + rw [lintegral_finsetSum _ fun j _ ↦ (hm j).const_mul _] + calc ∑ j ∈ Finset.range (N + 1), ∫⁻ ω, ENNReal.ofReal ((1 - r) * r ^ j) * + {ω | restartTime σ j ω ≤ N}.indicator (restartPayoff σ V j) ω + ∂Measure.infinitePi (fun _ : ℕ ↦ P) + _ = ∑ j ∈ Finset.range (N + 1), ENNReal.ofReal ((1 - r) * r ^ j) * + ∫⁻ ω, {ω | restartTime σ j ω ≤ N}.indicator (restartPayoff σ V j) ω + ∂Measure.infinitePi (fun _ : ℕ ↦ P) := + Finset.sum_congr rfl fun j _ ↦ lintegral_const_mul _ (hm j) + _ ≤ ∑ j ∈ Finset.range (N + 1), ENNReal.ofReal ((1 - r) * r ^ j) := + Finset.sum_le_sum fun j _ ↦ mul_le_of_le_one_right' + (lintegral_indicator_restartPayoff_le_one hσ hV hσm hVm P h_null j N) + _ = ENNReal.ofReal (1 - r ^ (N + 1)) := by + rw [← ENNReal.ofReal_sum_of_nonneg fun j _ ↦ mul_nonneg (by linarith) (pow_nonneg hr0 j), + ← Finset.mul_sum, mul_neg_geom_sum] + _ ≤ 1 := ENNReal.ofReal_le_one.2 (by have := pow_nonneg hr0 (N + 1); linarith) + +variable (σ) in +/-- The number of rounds completed within the first `N` observations. -/ +private def numRounds (N : ℕ) (ω : ℕ → 𝓧) : ℕ := + Nat.findGreatest (fun j ↦ restartTime σ j ω ≤ N) N + +/-- At most `N` rounds are completed within `N` observations. -/ +private lemma numRounds_le (N : ℕ) (ω : ℕ → 𝓧) : numRounds σ N ω ≤ N := Nat.findGreatest_le N + +/-- The completed rounds use at most `N` observations. -/ +private lemma restartTime_numRounds_le (N : ℕ) (ω : ℕ → 𝓧) : + restartTime σ (numRounds σ N ω) ω ≤ N := + Nat.findGreatest_spec (P := fun j ↦ restartTime σ j ω ≤ N) (Nat.zero_le N) (Nat.zero_le N) + +/-- For `i ≤ N`, the first `i` rounds use at most `N` observations if and only if they are among +the completed rounds. -/ +private lemma restartTime_le_iff_le_numRounds {N i : ℕ} (hi : i ≤ N) (ω : ℕ → 𝓧) : + restartTime σ i ω ≤ N ↔ i ≤ numRounds σ N ω := + ⟨fun h ↦ Nat.le_findGreatest hi h, + fun h ↦ (monotone_restartTime σ ω h).trans (restartTime_numRounds_le N ω)⟩ + +/-- If every round uses at least one observation, the round after the completed ones ends after +the first `N` observations. -/ +private lemma lt_restartTime_numRounds_succ (hσ1 : ∀ ω, 1 ≤ σ ω) (N : ℕ) (ω : ℕ → 𝓧) : + N < restartTime σ (numRounds σ N ω + 1) ω := by + by_cases hJ : numRounds σ N ω + 1 ≤ N + · exact not_le.1 (Nat.findGreatest_is_greatest (P := fun j ↦ restartTime σ j ω ≤ N) + (Nat.lt_succ_self _) hJ) + · have hJN : numRounds σ N ω = N := le_antisymm (numRounds_le N ω) (by omega) + rw [hJN] + exact Nat.lt_of_lt_of_le (Nat.lt_succ_self N) (le_restartTime σ hσ1 (N + 1) ω) + +/-- **Wald's argument, pointwise.** The durations of the rounds that start within the first `N` +observations add up to more than `N`. -/ +private lemma add_one_le_sum_indicator (hσ1 : ∀ ω, 1 ≤ σ ω) (N : ℕ) (ω : ℕ → 𝓧) : + (N + 1 : ℝ) ≤ ∑ i ∈ Finset.range (N + 1), {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ)) ω := by + set J := numRounds σ N ω + have hJN : J ≤ N := numRounds_le N ω + have hJ : N + 1 ≤ restartTime σ (J + 1) ω := lt_restartTime_numRounds_succ hσ1 N ω + calc (N + 1 : ℝ) ≤ (restartTime σ (J + 1) ω : ℝ) := by exact_mod_cast hJ + _ = ∑ i ∈ Finset.range (J + 1), (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ) := by + rw [restartTime_eq_sum, Nat.cast_sum] + _ = ∑ i ∈ Finset.range (J + 1), {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ)) ω := by + refine Finset.sum_congr rfl fun i hi ↦ ?_ + rw [Set.indicator_of_mem] + exact (restartTime_le_iff_le_numRounds ((Nat.lt_succ_iff.1 (Finset.mem_range.1 hi)).trans + hJN) ω).2 (Nat.lt_succ_iff.1 (Finset.mem_range.1 hi)) + _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg + (Finset.range_subset_range.2 (Nat.succ_le_succ hJN)) + fun i _ _ ↦ Set.indicator_nonneg (fun _ _ ↦ Nat.cast_nonneg _) _ + +/-- **Wald's argument, in expectation.** Under an i.i.d. law, the observations after the first +`i` rounds are independent of the event that these rounds use at most `N` observations. -/ +private lemma integral_indicator_comp_shift_restartTime (hσ : DependsOnBefore σ σ) + (hσm : Measurable σ) (P : Measure 𝓧) [IsProbabilityMeasure P] {g : (ℕ → 𝓧) → ℝ} + (hg : Measurable g) {C : ℝ} (hgC : ∀ ω, |g ω| ≤ C) (i N : ℕ) : + ∫ ω, {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ g ((shift 𝓧)^[restartTime σ i ω] ω)) ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) = + (Measure.infinitePi (fun _ : ℕ ↦ P)).real {ω | restartTime σ i ω ≤ N} * + ∫ ω, g ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) := by + set μ := Measure.infinitePi (fun _ : ℕ ↦ P) + have hf (t : ℕ) : Measurable ({ω | restartTime σ i ω = t}.indicator (1 : (ℕ → 𝓧) → ℝ)) := + measurable_one.indicator (measurableSet_restartTime_eq hσm i t) + have hfi (t : ℕ) : Integrable ({ω | restartTime σ i ω = t}.indicator (1 : (ℕ → 𝓧) → ℝ)) μ := + (integrable_const (1 : ℝ)).indicator (measurableSet_restartTime_eq hσm i t) + have hfg (t : ℕ) : Integrable (fun ω ↦ + {ω | restartTime σ i ω = t}.indicator (1 : (ℕ → 𝓧) → ℝ) ω * g ((shift 𝓧)^[t] ω)) μ := by + refine Integrable.of_bound + ((hf t).mul (hg.comp (measurable_shift_iterate t))).aestronglyMeasurable C + (ae_of_all _ fun ω ↦ ?_) + rw [Real.norm_eq_abs, abs_mul] + calc |{ω | restartTime σ i ω = t}.indicator (1 : (ℕ → 𝓧) → ℝ) ω| * |g ((shift 𝓧)^[t] ω)| + _ ≤ 1 * C := by + refine mul_le_mul ?_ (hgC _) (abs_nonneg _) zero_le_one + by_cases h : restartTime σ i ω = t <;> simp [Set.indicator, h] + _ = C := one_mul C + have hsum (ω : ℕ → 𝓧) : {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ g ((shift 𝓧)^[restartTime σ i ω] ω)) ω = + ∑ t ∈ Finset.range (N + 1), + {ω | restartTime σ i ω = t}.indicator (1 : (ℕ → 𝓧) → ℝ) ω * g ((shift 𝓧)^[t] ω) := by + rw [← sum_indicator_eq_indicator_le] + refine Finset.sum_congr rfl fun t _ ↦ ?_ + by_cases h : restartTime σ i ω = t + · rw [Set.indicator_of_mem h, Set.indicator_of_mem h, Pi.one_apply, one_mul, h] + · rw [Set.indicator_of_notMem h, Set.indicator_of_notMem h, zero_mul] + simp_rw [hsum] + rw [integral_finsetSum _ fun t _ ↦ hfg t] + calc ∑ t ∈ Finset.range (N + 1), ∫ ω, + {ω | restartTime σ i ω = t}.indicator (1 : (ℕ → 𝓧) → ℝ) ω * g ((shift 𝓧)^[t] ω) ∂μ + _ = ∑ t ∈ Finset.range (N + 1), + (∫ ω, {ω | restartTime σ i ω = t}.indicator (1 : (ℕ → 𝓧) → ℝ) ω ∂μ) * ∫ ω, g ω ∂μ := + Finset.sum_congr rfl fun t _ ↦ integral_mul_comp_shift_iterate P (hf t) + (dependsOn_indicator_one_restartTime_eq hσ i t) hg + _ = μ.real {ω | restartTime σ i ω ≤ N} * ∫ ω, g ω ∂μ := by + rw [← Finset.sum_mul, ← integral_finsetSum _ fun t _ ↦ hfi t] + simp_rw [sum_indicator_eq_indicator_le] + rw [integral_indicator_one (measurableSet_restartTime_le hσm i N)] + +end Restart + +/-! ### The truncated logarithm -/ + +/-- The logarithm truncated above at `c`, as a real number. -/ +private noncomputable def truncLog (c : ℝ) (x : ℝ≥0∞) : ℝ := (min (ENNReal.log x) c).toReal + +/-- The truncated logarithm is measurable. -/ +private lemma measurable_truncLog (c : ℝ) : Measurable (truncLog c) := + measurable_ereal_toReal.comp (ENNReal.measurable_log.min measurable_const) + +/-- The truncated logarithm of a positive finite number. -/ +private lemma truncLog_of_ne {c : ℝ} {x : ℝ≥0∞} (h0 : x ≠ 0) (htop : x ≠ ∞) : + truncLog c x = min (Real.log x.toReal) c := by + rw [truncLog, ENNReal.log_pos_real h0 htop, ← EReal.coe_strictMono.monotone.map_min, + EReal.toReal_coe] + +/-- The truncated logarithm of `∞` is the truncation level. -/ +private lemma truncLog_top (c : ℝ) : truncLog c ∞ = c := by simp [truncLog] + +/-- The truncated logarithm is at most the truncation level. -/ +private lemma truncLog_le {c : ℝ} {x : ℝ≥0∞} (h0 : x ≠ 0) : truncLog c x ≤ c := by + by_cases htop : x = ∞ + · rw [htop, truncLog_top] + · rw [truncLog_of_ne h0 htop] + exact min_le_right _ _ + +/-- The truncated logarithm of `x ≥ δ` is at least `log δ`, if `log δ ≤ c`. -/ +private lemma log_le_truncLog {c δ : ℝ} (hδ : 0 < δ) {x : ℝ≥0∞} (hx : ENNReal.ofReal δ ≤ x) + (hc : Real.log δ ≤ c) : Real.log δ ≤ truncLog c x := by + have h0 : x ≠ 0 := (lt_of_lt_of_le (ENNReal.ofReal_pos.2 hδ) hx).ne' + by_cases htop : x = ∞ + · rw [htop, truncLog_top] + exact hc + · rw [truncLog_of_ne h0 htop] + exact le_min (Real.log_le_log hδ ((ENNReal.ofReal_le_iff_le_toReal htop).1 hx)) hc + +/-- The truncated logarithm of `x ≥ δ` is bounded in absolute value, if `log δ ≤ c`. -/ +private lemma abs_truncLog_le {c δ : ℝ} (hδ : 0 < δ) {x : ℝ≥0∞} (hx : ENNReal.ofReal δ ≤ x) + (hc : Real.log δ ≤ c) : |truncLog c x| ≤ max |Real.log δ| |c| := + abs_le_max_abs_abs (log_le_truncLog hδ hx hc) + (truncLog_le (lt_of_lt_of_le (ENNReal.ofReal_pos.2 hδ) hx).ne') + +/-- The exponential of the truncated logarithm of `x` is at most `x`. -/ +private lemma ofReal_exp_truncLog_le {c : ℝ} {x : ℝ≥0∞} (h0 : x ≠ 0) : + ENNReal.ofReal (Real.exp (truncLog c x)) ≤ x := by + by_cases htop : x = ∞ + · rw [htop] + exact le_top + · rw [truncLog_of_ne h0 htop] + calc ENNReal.ofReal (Real.exp (min (Real.log x.toReal) c)) + _ ≤ ENNReal.ofReal (Real.exp (Real.log x.toReal)) := + ENNReal.ofReal_le_ofReal (Real.exp_le_exp.2 (min_le_left _ _)) + _ = x := by + rw [Real.exp_log (ENNReal.toReal_pos h0 htop), ENNReal.ofReal_toReal htop] + +/-- Mixing a payoff with a constant: `min (log x) c ≤ truncLog c ((1 - ε) x + ε) - log (1 - ε)`. -/ +private lemma min_log_le_truncLog_sub {ε : ℝ} (hε0 : 0 < ε) (hε1 : ε < 1) (c : ℝ) (x : ℝ≥0∞) : + min (ENNReal.log x) c ≤ + ((truncLog c (ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε) - Real.log (1 - ε) : ℝ) : + EReal) := by + have hlog : Real.log (1 - ε) ≤ 0 := Real.log_nonpos (by linarith) (by linarith) + by_cases h0 : x = 0 + · simp [h0] + by_cases htop : x = ∞ + · have : ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε = ∞ := by + rw [htop, ENNReal.mul_top (ENNReal.ofReal_pos.2 (by linarith)).ne', top_add] + rw [this, truncLog_top] + exact (min_le_right _ _).trans (EReal.coe_le_coe_iff.2 (by linarith)) + have hε' : ENNReal.ofReal ε ≠ 0 := (ENNReal.ofReal_pos.2 hε0).ne' + have hV0 : ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε ≠ 0 := by simp [hε'] + have hVtop : ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε ≠ ∞ := + ENNReal.add_ne_top.2 ⟨ENNReal.mul_ne_top ENNReal.ofReal_ne_top htop, ENNReal.ofReal_ne_top⟩ + have hVreal : (ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε).toReal = + (1 - ε) * x.toReal + ε := by + rw [ENNReal.toReal_add (ENNReal.mul_ne_top ENNReal.ofReal_ne_top htop) ENNReal.ofReal_ne_top, + ENNReal.toReal_mul, ENNReal.toReal_ofReal (by linarith), ENNReal.toReal_ofReal hε0.le] + rw [truncLog_of_ne hV0 hVtop, hVreal, ENNReal.log_pos_real h0 htop, + ← EReal.coe_strictMono.monotone.map_min, EReal.coe_le_coe_iff] + have hx : 0 < x.toReal := ENNReal.toReal_pos h0 htop + have hL : Real.log (1 - ε) + Real.log x.toReal ≤ Real.log ((1 - ε) * x.toReal + ε) := by + rw [← Real.log_mul (by linarith) hx.ne'] + exact Real.log_le_log (mul_pos (by linarith) hx) (by linarith) + rw [← min_sub_sub_right] + exact le_min ((min_le_left _ _).trans (by linarith)) ((min_le_right _ _).trans (by linarith)) + +/-! ### The Wald inequality for a round -/ + +section Wald + +variable {σ : (ℕ → 𝓧) → ℕ} {V : (ℕ → 𝓧) → ℝ≥0∞} + +/-- The logarithm of the mixture of restarted rounds is at least the logarithm of the weight of +the completed rounds plus their truncated log-payoffs, hence at least the sum of the truncated +log-payoffs of the rounds that start within the first `N` observations, up to `c` for the last +one and to the logarithm of the weights. -/ +private lemma log_restartMixture_ge {δ : ℝ} (hδ : 0 < δ) (hVδ : ∀ ω, ENNReal.ofReal δ ≤ V ω) + (c : ℝ) {r : ℝ} (hr0 : 0 < r) (hr1 : r < 1) (N : ℕ) (ω : ℕ → 𝓧) : + ((Real.log (1 - r) + N * Real.log r - c + ∑ i ∈ Finset.range (N + 1), + {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω : ℝ) : EReal) ≤ + ENNReal.log (restartMixture σ V r N ω) := by + set J := numRounds σ N ω + set Y : ℕ → ℝ := fun i ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω)) + have hV0 (ω : ℕ → 𝓧) : V ω ≠ 0 := (lt_of_lt_of_le (ENNReal.ofReal_pos.2 hδ) (hVδ ω)).ne' + have hJN : J ≤ N := numRounds_le N ω + have hr' : 0 < 1 - r := by linarith + -- the mixture is at least its term of index `J` + have h1 : ENNReal.ofReal ((1 - r) * r ^ J * Real.exp (∑ i ∈ Finset.range J, Y i)) ≤ + restartMixture σ V r N ω := by + calc ENNReal.ofReal ((1 - r) * r ^ J * Real.exp (∑ i ∈ Finset.range J, Y i)) + _ = ENNReal.ofReal ((1 - r) * r ^ J) * + ∏ i ∈ Finset.range J, ENNReal.ofReal (Real.exp (Y i)) := by + rw [ENNReal.ofReal_mul (mul_nonneg hr'.le (pow_nonneg hr0.le J)), Real.exp_sum, + ENNReal.ofReal_prod_of_nonneg fun i _ ↦ (Real.exp_pos _).le] + _ ≤ ENNReal.ofReal ((1 - r) * r ^ J) * restartPayoff σ V J ω := by + rw [restartPayoff_eq_prod] + gcongr with i hi + exact ofReal_exp_truncLog_le (hV0 _) + _ = ENNReal.ofReal ((1 - r) * r ^ J) * + {ω | restartTime σ J ω ≤ N}.indicator (restartPayoff σ V J) ω := by + rw [Set.indicator_of_mem (restartTime_numRounds_le N ω)] + _ ≤ restartMixture σ V r N ω := + Finset.single_le_sum (f := fun j ↦ ENNReal.ofReal ((1 - r) * r ^ j) * + {ω | restartTime σ j ω ≤ N}.indicator (restartPayoff σ V j) ω) + (fun _ _ ↦ bot_le) (Finset.mem_range.2 (Nat.lt_succ_of_le hJN)) + -- the logarithm of this term + have hpos : 0 < (1 - r) * r ^ J * Real.exp (∑ i ∈ Finset.range J, Y i) := by + have := pow_pos hr0 J + have := Real.exp_pos (∑ i ∈ Finset.range J, Y i) + positivity + have h2 : Real.log ((1 - r) * r ^ J * Real.exp (∑ i ∈ Finset.range J, Y i)) = + Real.log (1 - r) + J * Real.log r + ∑ i ∈ Finset.range J, Y i := by + rw [Real.log_mul (mul_pos hr' (pow_pos hr0 J)).ne' (Real.exp_pos _).ne', + Real.log_mul hr'.ne' (pow_pos hr0 J).ne', Real.log_pow, Real.log_exp] + -- the sum over the rounds that start within the first `N` observations + have h3 : ∑ i ∈ Finset.range (N + 1), {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω = + ∑ i ∈ Finset.range (J + 1), Y i := by + symm + refine Finset.sum_subset (Finset.range_subset_range.2 (Nat.succ_le_succ hJN)) + (fun i hi hiJ ↦ ?_) |>.symm.trans (Finset.sum_congr rfl fun i hi ↦ ?_) |>.symm + · rw [Set.indicator_of_notMem] + rw [Set.mem_ofPred_eq, restartTime_le_iff_le_numRounds + (Nat.lt_succ_iff.1 (Finset.mem_range.1 hi))] + exact fun h ↦ hiJ (Finset.mem_range.2 (Nat.lt_succ_of_le h)) + · rw [Set.indicator_of_mem] + exact (restartTime_le_iff_le_numRounds + ((Nat.lt_succ_iff.1 (Finset.mem_range.1 hi)).trans hJN) ω).2 + (Nat.lt_succ_iff.1 (Finset.mem_range.1 hi)) + have h4 : Y J ≤ c := truncLog_le (hV0 _) + have h5 : (N : ℝ) * Real.log r ≤ J * Real.log r := + mul_le_mul_of_nonpos_right (by exact_mod_cast hJN) (Real.log_nonpos hr0.le hr1.le) + calc ((Real.log (1 - r) + N * Real.log r - c + ∑ i ∈ Finset.range (N + 1), + {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω : ℝ) : EReal) + _ ≤ ((Real.log ((1 - r) * r ^ J * Real.exp (∑ i ∈ Finset.range J, Y i)) : ℝ) : EReal) := by + rw [h2, h3, Finset.sum_range_succ] + exact EReal.coe_le_coe_iff.2 (by linarith) + _ = ENNReal.log (ENNReal.ofReal ((1 - r) * r ^ J * Real.exp (∑ i ∈ Finset.range J, Y i))) := + (ENNReal.log_ofReal_of_pos hpos).symm + _ ≤ ENNReal.log (restartMixture σ V r N ω) := ENNReal.log_le_log h1 + +/-- The limit argument of the Wald inequality: if for every `r ∈ (0, 1)` and `N ≥ 1` some +`s ≥ (N + 1) / m` satisfies `log (1 - r) + N log r - c + A s ≤ N d`, then `A ≤ d m`. -/ +private lemma le_mul_of_forall_restart {A c d m : ℝ} (hm : 0 < m) (hd : 0 ≤ d) + (h : ∀ r : ℝ, 0 < r → r < 1 → ∀ N : ℕ, 1 ≤ N → ∃ s : ℝ, + (N + 1 : ℝ) ≤ m * s ∧ Real.log (1 - r) + N * Real.log r - c + A * s ≤ N * d) : + A ≤ d * m := by + by_contra hlt + rw [not_le] at hlt + have hA : 0 < A := lt_of_le_of_lt (mul_nonneg hd hm.le) hlt + set ε := A / m - d with hε + have hε0 : 0 < ε := by + rw [hε, sub_pos, lt_div_iff₀ hm] + linarith + set r := Real.exp (-(ε / 2)) with hr + have hr0 : 0 < r := Real.exp_pos _ + have hr1 : r < 1 := Real.exp_lt_one_iff.2 (by linarith) + have hlogr : Real.log r = -(ε / 2) := Real.log_exp _ + obtain ⟨N, hN⟩ := exists_nat_gt ((c - Real.log (1 - r)) * 2 / ε) + obtain ⟨s, hs1, hs2⟩ := h r hr0 hr1 (N + 1) (by omega) + have hAs : A * (((N + 1 : ℕ) : ℝ) + 1) / m ≤ A * s := by + rw [mul_div_assoc] + exact mul_le_mul_of_nonneg_left ((div_le_iff₀ hm).2 (by linarith [mul_comm m s])) hA.le + have key : A * (((N + 1 : ℕ) : ℝ) + 1) / m = (((N + 1 : ℕ) : ℝ) + 1) * (d + ε) := by + rw [hε] + field_simp + ring + rw [key] at hAs + rw [hlogr] at hs2 + have hN' : (c - Real.log (1 - r)) * 2 < N * ε := (div_lt_iff₀ hε0).1 hN + push_cast at hs2 hAs + nlinarith + +/-- **The Wald inequality for a round.** Let `σ ≥ 1` be the bounded duration and `V ≥ δ > 0` the +payoff of a round, both determined by the observations of the round. If the payoff has +expectation at most `1` on each event `{σ ≤ n}` under the i.i.d. laws of the members of `S₁`, +then under the i.i.d. law of `Q₁` the expected logarithm of the payoff, truncated above at `c`, is +at most the bipolar rate times the expected duration. -/ +private lemma integral_truncLog_le_bipolarRate_mul (Q₁ : Measure 𝓧) [IsProbabilityMeasure Q₁] + (hS₁ : ∀ P ∈ S₁, IsProbabilityMeasure P) (hσ : DependsOnBefore σ σ) + (hV : DependsOnBefore σ V) (hσm : Measurable σ) (hVm : Measurable V) (hσ1 : ∀ ω, 1 ≤ σ ω) + {K : ℕ} (hσK : ∀ ω, σ ω ≤ K) + (h_null : ∀ P ∈ S₁, ∀ n : ℕ, + ∫⁻ ω, {ω | σ ω ≤ n}.indicator V ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) ≤ 1) + {δ : ℝ} (hδ : 0 < δ) (hVδ : ∀ ω, ENNReal.ofReal δ ≤ V ω) {c : ℝ} (hc : Real.log δ ≤ c) + (hd : bipolarRate Q₁ S₁ ≠ ⊤) : + ∫ ω, truncLog c (V ω) ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁) ≤ + (bipolarRate Q₁ S₁).toReal * ∫ ω, (σ ω : ℝ) ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁) := by + set μ := Measure.infinitePi (fun _ : ℕ ↦ Q₁) + set m := ∫ ω, (σ ω : ℝ) ∂μ + set A := ∫ ω, truncLog c (V ω) ∂μ + have hd0 := bipolarRate_nonneg Q₁ S₁ + have hσm' : Measurable fun ω ↦ (σ ω : ℝ) := measurable_from_top.comp hσm + have hσC (ω : ℕ → 𝓧) : |(σ ω : ℝ)| ≤ K := by + rw [abs_of_nonneg (Nat.cast_nonneg _)] + exact_mod_cast hσK ω + have hm1 : 1 ≤ m := by + calc (1 : ℝ) = ∫ _, (1 : ℝ) ∂μ := by simp + _ ≤ m := integral_mono (integrable_const _) + (Integrable.of_bound hσm'.aestronglyMeasurable K (ae_of_all _ fun ω ↦ hσC ω)) + fun ω ↦ by exact_mod_cast hσ1 ω + -- the truncated log-payoffs are bounded + set C := max |Real.log δ| |c| + have hYm : Measurable fun ω ↦ truncLog c (V ω) := (measurable_truncLog c).comp hVm + have hT (i : ℕ) : Measurable (restartTime σ i) := measurable_restartTime hσm i + refine le_mul_of_forall_restart (c := c) (by linarith) (EReal.toReal_nonneg hd0) + fun r hr0 hr1 N hN ↦ ?_ + have hfm (i : ℕ) : Measurable fun ω ↦ {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω := + (measurable_comp_shift_iterate hYm (hT i)).indicator (hT i measurableSet_Iic) + have hfC (i : ℕ) (ω : ℕ → 𝓧) : |{ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω| ≤ C := by + by_cases h : restartTime σ i ω ≤ N + · rw [Set.indicator_of_mem h] + exact abs_truncLog_le hδ (hVδ _) hc + · rw [Set.indicator_of_notMem h, abs_zero] + exact (abs_nonneg _).trans (le_max_left _ _) + have hfi (i : ℕ) : Integrable (fun ω ↦ {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω) μ := + Integrable.of_bound (hfm i).aestronglyMeasurable C + (ae_of_all _ fun ω ↦ (Real.norm_eq_abs _).trans_le (hfC i ω)) + refine ⟨∑ i ∈ Finset.range (N + 1), μ.real {ω | restartTime σ i ω ≤ N}, ?_, ?_⟩ + · -- Wald's argument + have hgm (i : ℕ) : Measurable fun ω ↦ {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ)) ω := + (measurable_comp_shift_iterate hσm' (hT i)).indicator (hT i measurableSet_Iic) + have hgi (i : ℕ) : Integrable (fun ω ↦ {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ)) ω) μ := by + refine Integrable.of_bound (hgm i).aestronglyMeasurable K (ae_of_all _ fun ω ↦ ?_) + rw [Real.norm_eq_abs] + by_cases h : restartTime σ i ω ≤ N + · rw [Set.indicator_of_mem h] + exact hσC _ + · rw [Set.indicator_of_notMem h, abs_zero] + exact Nat.cast_nonneg _ + calc (N + 1 : ℝ) = ∫ _, (N + 1 : ℝ) ∂μ := by simp + _ ≤ ∫ ω, ∑ i ∈ Finset.range (N + 1), {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ)) ω ∂μ := + integral_mono (integrable_const _) (integrable_finsetSum _ fun i _ ↦ hgi i) + fun ω ↦ add_one_le_sum_indicator hσ1 N ω + _ = ∑ i ∈ Finset.range (N + 1), μ.real {ω | restartTime σ i ω ≤ N} * m := by + rw [integral_finsetSum _ fun i _ ↦ hgi i] + exact Finset.sum_congr rfl fun i _ ↦ + integral_indicator_comp_shift_restartTime hσ hσm Q₁ hσm' hσC i N + _ = m * ∑ i ∈ Finset.range (N + 1), μ.real {ω | restartTime σ i ω ≤ N} := by + rw [Finset.mul_sum] + exact Finset.sum_congr rfl fun i _ ↦ mul_comm _ _ + · -- the logarithmic bound + set B := Real.log (1 - r) + N * Real.log r - c + have hsum : Integrable (fun ω ↦ ∑ i ∈ Finset.range (N + 1), + {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω) μ := + integrable_finsetSum _ fun i _ ↦ hfi i + have hint : Integrable (fun ω ↦ B + ∑ i ∈ Finset.range (N + 1), + {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω) μ := + (integrable_const B).add hsum + have hval : ∫ ω, B + ∑ i ∈ Finset.range (N + 1), {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω ∂μ = + B + A * ∑ i ∈ Finset.range (N + 1), μ.real {ω | restartTime σ i ω ≤ N} := by + rw [integral_add (integrable_const B) hsum, integral_finsetSum _ fun i _ ↦ hfi i, + Finset.mul_sum] + simp only [integral_const, probReal_univ, one_smul] + congr 1 + exact Finset.sum_congr rfl fun i _ ↦ (integral_indicator_comp_shift_restartTime hσ hσm Q₁ + hYm (fun ω ↦ abs_truncLog_le hδ (hVδ ω) hc) i N).trans (mul_comm _ _) + have hle : ((B + A * ∑ i ∈ Finset.range (N + 1), μ.real {ω | restartTime σ i ω ≤ N} : ℝ) : + EReal) ≤ (N : EReal) * bipolarRate Q₁ S₁ := by + rw [← hval, ← eintegral_eq_integral hint] + calc ∫ᵉ ω, ((B + ∑ i ∈ Finset.range (N + 1), {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω : ℝ) : EReal) ∂μ + _ ≤ ∫ᵉ ω, ENNReal.log (restartMixture σ V r N ω) ∂μ := + eintegral_mono fun ω ↦ log_restartMixture_ge hδ hVδ c hr0 hr1 N ω + _ ≤ maxLogGrowth Q₁ S₁ N := + eintegral_log_le_maxLogGrowth_of_dependsOn Q₁ hS₁ (measurable_restartMixture hσm hVm r N) + (dependsOn_restartMixture hσ hV r N) fun P hP ↦ by + have := hS₁ P hP + exact lintegral_restartMixture_le_one hσ hV hσm hVm P (h_null P hP) hr0.le hr1.le N + _ ≤ N * bipolarRate Q₁ S₁ := maxLogGrowth_le_mul_bipolarRate Q₁ S₁ (by omega) + rw [← EReal.coe_toReal hd (ne_bot_of_le_ne_bot EReal.zero_ne_bot hd0), ← EReal.coe_natCast, + ← EReal.coe_mul, EReal.coe_le_coe_iff] at hle + exact hle + +end Wald + +/-! ### Extended integrals -/ + +/-- **Monotone convergence for truncations.** If the extended integrals of the truncations +`min f k`, `k ∈ ℕ`, are at most `D`, so is the extended integral of `f`. -/ +private lemma eintegral_le_of_forall_min_le {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + {f : Ω → EReal} (hf : Measurable f) {D : EReal} + (h : ∀ k : ℕ, ∫ᵉ x, min (f x) k ∂μ ≤ D) : ∫ᵉ x, f x ∂μ ≤ D := by + have hmono : Monotone EReal.toENNReal := fun _ _ h ↦ EReal.toENNReal_le_toENNReal h + have hpos (k : ℕ) (x : Ω) : (min (f x) k).toENNReal = min (f x).toENNReal k := by + rw [hmono.map_min, show ((k : EReal)) = ((k : ℝ≥0∞) : EReal) by simp, EReal.toENNReal_coe] + have hneg (k : ℕ) (x : Ω) : (-min (f x) k).toENNReal = (-f x).toENNReal := by + by_cases hk : f x ≤ k + · rw [min_eq_left hk] + · rw [not_le] at hk + have hk0 : (0 : EReal) ≤ k := by exact_mod_cast Nat.zero_le k + rw [min_eq_right hk.le, EReal.toENNReal_of_nonpos (by simp), + EReal.toENNReal_of_nonpos (by simpa using hk0.trans hk.le)] + have h' (k : ℕ) : ((∫⁻ x, min (f x).toENNReal k ∂μ : ℝ≥0∞) : EReal) - + ((∫⁻ x, (-f x).toENNReal ∂μ : ℝ≥0∞) : EReal) ≤ D := by + have := h k + simp only [eintegral, hpos, hneg] at this + exact this + have hm (k : ℕ) : Measurable fun x ↦ min (f x).toENNReal (k : ℝ≥0∞) := + (measurable_ereal_toENNReal.comp hf).min measurable_const + have hmono' : Monotone fun (k : ℕ) x ↦ min (f x).toENNReal (k : ℝ≥0∞) := + fun k k' hkk' x ↦ min_le_min_left _ (by exact_mod_cast hkk') + have hsup : ∫⁻ x, (f x).toENNReal ∂μ = ⨆ k : ℕ, ∫⁻ x, min (f x).toENNReal k ∂μ := by + rw [← lintegral_iSup hm hmono'] + refine lintegral_congr fun x ↦ le_antisymm ?_ (iSup_le fun k ↦ min_le_left _ _) + by_cases hx : (f x).toENNReal = ∞ + · simp [hx, ENNReal.iSup_natCast] + · obtain ⟨k, hk⟩ := ENNReal.exists_nat_gt hx + exact le_iSup_of_le k (min_eq_left hk.le).ge + rw [eintegral, hsup] + set b := ∫⁻ x, (-f x).toENNReal ∂μ + by_cases hb : b = ∞ + · rw [hb, EReal.coe_ennreal_top, EReal.sub_top] + exact bot_le + have hb' : (b : EReal) ≠ ⊤ := by simpa using hb + have hb'' : (b : EReal) ≠ ⊥ := by simp + rw [EReal.sub_le_iff_le_add (.inl hb'') (.inl hb')] + have hk (k : ℕ) : ((∫⁻ x, min (f x).toENNReal k ∂μ : ℝ≥0∞) : EReal) ≤ D + b := + (EReal.sub_le_iff_le_add (.inl hb'') (.inl hb')).1 (h' k) + have hD : 0 ≤ D + b := (EReal.coe_ennreal_nonneg _).trans (hk 0) + rw [← EReal.coe_toENNReal hD] at hk ⊢ + exact EReal.coe_ennreal_le_coe_ennreal_iff.2 + (iSup_le fun k ↦ EReal.coe_ennreal_le_coe_ennreal_iff.1 (hk k)) + +/-- A bound `x ≤ D + η` for every `η > 0` gives `x ≤ D`. -/ +private lemma le_coe_of_forall_pos_le_coe_add {x : EReal} {D : ℝ} + (h : ∀ η : ℝ, 0 < η → x ≤ ↑(D + η)) : x ≤ D := by + refine le_of_forall_gt_imp_ge_of_dense fun a ha ↦ ?_ + obtain ⟨r, hDr, hra⟩ := EReal.lt_iff_exists_real_btwn.1 ha + calc x ≤ ↑(D + (r - D)) := h _ (by exact_mod_cast sub_pos.2 (EReal.coe_lt_coe_iff.1 hDr)) + _ = r := by rw [add_sub_cancel] + _ ≤ a := hra.le + +/-! ### The Wald inequality for e-processes -/ + +section EProcess + +variable {E : ℕ → (ℕ → 𝓧) → ℝ≥0∞} {τ : (ℕ → 𝓧) → ℕ} + +/-- The Wald inequality for the payoff `(1 - ε) E_τ + ε`, truncated above at `c`: apply the Wald +inequality for a round to the e-process stopped at `min τ k`, and let `k` tend to infinity. The +bound `D` is that of the Wald inequality for the stopping times `min τ k`. -/ +private lemma integral_truncLog_stoppedValue_le (Q₁ : Measure 𝓧) [IsProbabilityMeasure Q₁] + (hS₁ : ∀ P ∈ S₁, IsProbabilityMeasure P) + (hE : IsEProcess E (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) + ((fun P ↦ Measure.infinitePi fun _ : ℕ ↦ P) '' S₁)) + (hτ : IsStoppingTime (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) fun ω ↦ (τ ω : WithTop ℕ)) + {ε : ℝ} (hε0 : 0 < ε) (hε1 : ε < 1) {c : ℝ} (hc : Real.log ε ≤ c) + (hd : bipolarRate Q₁ S₁ ≠ ⊤) {D : ℝ} + (hD : ∀ k : ℕ, (bipolarRate Q₁ S₁).toReal * + ∫ ω, ((min (τ ω) k + 1 : ℕ) : ℝ) ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁) ≤ D) : + ∫ ω, truncLog c (ENNReal.ofReal (1 - ε) * E (τ ω) ω + ENNReal.ofReal ε) + ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁) ≤ D := by + set μ := Measure.infinitePi (fun _ : ℕ ↦ Q₁) + set V : ℕ → (ℕ → 𝓧) → ℝ≥0∞ := fun k ω ↦ + ENNReal.ofReal (1 - ε) * E (min (τ ω) k) ω + ENNReal.ofReal ε + have hτk (k : ℕ) := isStoppingTime_min_nat hτ k + have hVm (k : ℕ) : Measurable (V k) := + (measurable_const.mul (hE.measurable_stoppedValue (hτk k))).add measurable_const + have hVε (k : ℕ) (ω : ℕ → 𝓧) : ENNReal.ofReal ε ≤ V k ω := le_add_self + -- the Wald inequality for the round stopped at `min τ k` + have hk (k : ℕ) : ∫ ω, truncLog c (V k ω) ∂μ ≤ D := by + refine (integral_truncLog_le_bipolarRate_mul (σ := fun ω ↦ min (τ ω) k + 1) Q₁ hS₁ ?_ ?_ + ((measurable_of_isStoppingTime_nat (hτk k)).add_const 1) (hVm k) (fun _ ↦ le_add_self) + (K := k + 1) (fun ω ↦ by simp) ?_ hε0 (hVε k) hc hd).trans ?_ + · intro u ω ω' h hle + simp only at hle ⊢ + rw [eq_of_isStoppingTime_of_forall_le (hτk k) fun i hi ↦ h i (by omega)] + · intro u ω ω' h hle + simp only at hle + have h' : ∀ i ≤ min (τ ω) k, ω i = ω' i := fun i hi ↦ h i (by omega) + simp only [V, eq_of_isStoppingTime_of_forall_le (hτk k) h', + ((hE.adapted (min (τ ω) k)).dependsOn_of_piLE fun i hi ↦ h' i hi).symm] + · intro P hP n + have := hS₁ P hP + have hPS : Measure.infinitePi (fun _ : ℕ ↦ P) ∈ + (fun P ↦ Measure.infinitePi fun _ : ℕ ↦ P) '' S₁ := ⟨P, hP, rfl⟩ + calc ∫⁻ ω, {ω | min (τ ω) k + 1 ≤ n}.indicator (V k) ω ∂Measure.infinitePi (fun _ ↦ P) + _ ≤ ∫⁻ ω, ENNReal.ofReal (1 - ε) * E (min (min (τ ω) k) (n - 1)) ω + ENNReal.ofReal ε + ∂Measure.infinitePi (fun _ ↦ P) := by + refine lintegral_mono fun ω ↦ ?_ + by_cases hω : min (τ ω) k + 1 ≤ n + · rw [Set.indicator_of_mem hω, min_eq_left (by omega : min (τ ω) k ≤ n - 1)] + · rw [Set.indicator_of_notMem hω] + exact bot_le + _ = ENNReal.ofReal (1 - ε) * ∫⁻ ω, E (min (min (τ ω) k) (n - 1)) ω + ∂Measure.infinitePi (fun _ ↦ P) + ENNReal.ofReal ε := by + rw [lintegral_add_right _ measurable_const, lintegral_const_mul _ + (hE.measurable_stoppedValue (isStoppingTime_min_nat (hτk k) (n - 1))), lintegral_const, + measure_univ, mul_one] + _ ≤ ENNReal.ofReal (1 - ε) * 1 + ENNReal.ofReal ε := by + gcongr + exact hE.lintegral_le_one (isStoppingTime_min_nat (hτk k) (n - 1)) hPS + _ = 1 := by + rw [mul_one, ← ENNReal.ofReal_add (by linarith) hε0.le, sub_add_cancel, + ENNReal.ofReal_one] + · exact hD k + -- let `k` tend to infinity + refine le_of_tendsto' (tendsto_integral_of_dominated_convergence (fun _ ↦ max |Real.log ε| |c|) + (fun k ↦ ((measurable_truncLog c).comp (hVm k)).aestronglyMeasurable) (integrable_const _) + (fun k ↦ ae_of_all _ fun ω ↦ (Real.norm_eq_abs _).trans_le + (abs_truncLog_le hε0 (hVε k ω) hc)) (ae_of_all _ fun ω ↦ ?_)) hk + exact tendsto_atTop_of_eventually_const (i₀ := τ ω) fun k hk ↦ by simp [V, min_eq_left hk] + +/-- The Wald inequality when the bipolar rate is finite and either it is `0` or the expected +number of observations is finite: the expected logarithm of `E_τ` is at most the real number +`d * 𝔼[τ + 1]`. -/ +private lemma eintegral_log_stoppedValue_le_toReal_mul (Q₁ : Measure 𝓧) [IsProbabilityMeasure Q₁] + (hS₁ : ∀ P ∈ S₁, IsProbabilityMeasure P) + (hE : IsEProcess E (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) + ((fun P ↦ Measure.infinitePi fun _ : ℕ ↦ P) '' S₁)) + (hτ : IsStoppingTime (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) fun ω ↦ (τ ω : WithTop ℕ)) + (hd : bipolarRate Q₁ S₁ ≠ ⊤) + (hdm : bipolarRate Q₁ S₁ = 0 ∨ + ∫⁻ ω, (τ ω : ℝ≥0∞) + 1 ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁) ≠ ∞) : + ∫ᵉ ω, ENNReal.log (E (τ ω) ω) ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁) ≤ + (((bipolarRate Q₁ S₁).toReal * + (∫⁻ ω, (τ ω : ℝ≥0∞) + 1 ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁)).toReal : ℝ) : EReal) := by + set μ := Measure.infinitePi (fun _ : ℕ ↦ Q₁) + set m := ∫⁻ ω, (τ ω : ℝ≥0∞) + 1 ∂μ + set D := (bipolarRate Q₁ S₁).toReal * m.toReal + have hτm := measurable_of_isStoppingTime_nat hτ + have hEτm : Measurable fun ω ↦ E (τ ω) ω := hE.measurable_stoppedValue hτ + have hD (k : ℕ) : (bipolarRate Q₁ S₁).toReal * ∫ ω, ((min (τ ω) k + 1 : ℕ) : ℝ) ∂μ ≤ D := by + rcases hdm with hd0 | hm + · simp [D, hd0] + refine mul_le_mul_of_nonneg_left ?_ (EReal.toReal_nonneg (bipolarRate_nonneg Q₁ S₁)) + rw [integral_eq_lintegral_of_nonneg_ae (ae_of_all _ fun _ ↦ Nat.cast_nonneg _) + ((measurable_from_top.comp ((hτm.min measurable_const).add_const 1)).aestronglyMeasurable)] + refine ENNReal.toReal_mono hm (lintegral_mono fun ω ↦ ?_) + rw [ENNReal.ofReal_natCast] + push_cast + gcongr + exact_mod_cast min_le_left _ _ + have step (ε : ℝ) (hε0 : 0 < ε) (hε1 : ε < 1) (k : ℕ) : + ∫ᵉ ω, min (ENNReal.log (E (τ ω) ω)) k ∂μ ≤ ((D - Real.log (1 - ε) : ℝ) : EReal) := by + set W : (ℕ → 𝓧) → ℝ≥0∞ := fun ω ↦ ENNReal.ofReal (1 - ε) * E (τ ω) ω + ENNReal.ofReal ε + have hc : Real.log ε ≤ k := (Real.log_neg hε0 hε1).le.trans (Nat.cast_nonneg k) + have hYi : Integrable (fun ω ↦ truncLog k (W ω)) μ := + Integrable.of_bound ((measurable_truncLog _).comp + ((measurable_const.mul hEτm).add measurable_const)).aestronglyMeasurable + (max |Real.log ε| |(k : ℝ)|) (ae_of_all _ fun ω ↦ (Real.norm_eq_abs _).trans_le + (abs_truncLog_le hε0 le_add_self hc)) + calc ∫ᵉ ω, min (ENNReal.log (E (τ ω) ω)) k ∂μ + _ ≤ ∫ᵉ ω, ((truncLog k (W ω) - Real.log (1 - ε) : ℝ) : EReal) ∂μ := + eintegral_mono fun ω ↦ by simpa using min_log_le_truncLog_sub hε0 hε1 k (E (τ ω) ω) + _ = ((∫ ω, truncLog k (W ω) ∂μ - Real.log (1 - ε) : ℝ) : EReal) := by + have hYi' : Integrable (fun ω ↦ truncLog k (W ω) - Real.log (1 - ε)) μ := + hYi.sub (integrable_const _) + rw [eintegral_eq_integral hYi', + integral_sub hYi (integrable_const _), integral_const, probReal_univ, one_smul] + _ ≤ ((D - Real.log (1 - ε) : ℝ) : EReal) := EReal.coe_le_coe_iff.2 (by + linarith [integral_truncLog_stoppedValue_le Q₁ hS₁ hE hτ hε0 hε1 hc hd hD]) + refine eintegral_le_of_forall_min_le (ENNReal.measurable_log.comp hEτm) fun k ↦ ?_ + refine le_coe_of_forall_pos_le_coe_add fun η hη ↦ ?_ + have hexp : Real.exp (-η) < 1 := Real.exp_lt_one_iff.2 (by linarith) + have h := step (1 - Real.exp (-η)) (by linarith) (by linarith [Real.exp_pos (-η)]) k + rwa [sub_sub_cancel, Real.log_exp, sub_neg_eq_add] at h + +end EProcess + +/-- **The Wald inequality at the bipolar rate.** For an e-process `E` for the i.i.d. laws of the +members of `S₁` and a stopping time `τ` with values in `ℕ`, the expected logarithm of `E` at `τ` +under the i.i.d. law of `Q₁` is at most the expected number `τ + 1` of observations times the +bipolar rate. The expected number of observations may be infinite, with `∞ * 0 = 0`: if the +bipolar rate is `0`, the expected logarithm is nonpositive at every stopping time. The expected +logarithm is Statlib's extended integral, which is `⊥` when the positive and negative parts of +the logarithm have infinite integrals. `Q₁` need not be a probability measure: otherwise its +i.i.d. law is `0` and both sides are `0`. -/ +theorem IsEProcess.eintegral_log_stoppedValue_le_mul_bipolarRate (Q₁ : Measure 𝓧) + (hS₁ : ∀ P ∈ S₁, IsProbabilityMeasure P) {E : ℕ → (ℕ → 𝓧) → ℝ≥0∞} + (hE : IsEProcess E (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) + ((fun P ↦ Measure.infinitePi fun _ : ℕ ↦ P) '' S₁)) + {τ : (ℕ → 𝓧) → ℕ} + (hτ : IsStoppingTime (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) fun ω ↦ (τ ω : WithTop ℕ)) : + ∫ᵉ ω, ENNReal.log (E (τ ω) ω) ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁) ≤ + ((∫⁻ ω, (τ ω : ℝ≥0∞) + 1 ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁) : ℝ≥0∞) : EReal) * + bipolarRate Q₁ S₁ := by + by_cases hQ : IsProbabilityMeasure Q₁ + swap + · simp [Measure.infinitePi, hQ] + set m := ∫⁻ ω, (τ ω : ℝ≥0∞) + 1 ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁) + have hm0 : (0 : EReal) < m := by + have : (1 : ℝ≥0∞) ≤ m := + calc (1 : ℝ≥0∞) = ∫⁻ _, 1 ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁) := by simp + _ ≤ m := lintegral_mono fun ω ↦ le_add_self + exact EReal.coe_ennreal_pos.2 (zero_lt_one.trans_le this) + by_cases hdtop : bipolarRate Q₁ S₁ = ⊤ + · rw [hdtop, EReal.mul_top_of_pos hm0] + exact le_top + rcases (bipolarRate_nonneg Q₁ S₁).eq_or_lt with hd | hd + · rw [← hd, mul_zero] + simpa [← hd] using eintegral_log_stoppedValue_le_toReal_mul Q₁ hS₁ hE hτ hdtop (.inl hd.symm) + by_cases hm : m = ∞ + · rw [hm, EReal.coe_ennreal_top, EReal.top_mul_of_pos hd] + exact le_top + refine (eintegral_log_stoppedValue_le_toReal_mul Q₁ hS₁ hE hτ hdtop (.inr hm)).trans_eq ?_ + rw [EReal.coe_mul, EReal.coe_toReal hdtop (ne_bot_of_gt hd), EReal.coe_ennreal_toReal hm, + mul_comm] + +/-! ### Expected stopping times of sequential tests -/ + +section Test + +variable {τ : (ℕ → 𝓧) → WithTop ℕ} + +/-- The lower bound for a level `a > 0` and a finite expected number of observations, up to a term +`- log (1 - ε)`: the Wald inequality for the e-process `ε + (1 - ε) a⁻¹ 𝟙{τ ≤ n}` at the +stopping times `min τ k`, as `k → ∞`. -/ +private lemma neg_log_le_toReal_mul_sub (Q₁ : Measure 𝓧) [IsProbabilityMeasure Q₁] + (hS₁ : ∀ P ∈ S₁, IsProbabilityMeasure P) + (hτ : IsStoppingTime (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) τ) {a : ℝ} (ha0 : 0 < a) + (h_level : ∀ P ∈ S₁, Measure.infinitePi (fun _ : ℕ ↦ P) {ω | τ ω ≠ ⊤} ≤ ENNReal.ofReal a) + (hd : bipolarRate Q₁ S₁ ≠ ⊤) + (hm : ∫⁻ ω, ENat.toENNReal (τ ω) + 1 ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁) ≠ ∞) + {ε : ℝ} (hε0 : 0 < ε) (hε1 : ε < 1) : + -Real.log a ≤ (bipolarRate Q₁ S₁).toReal * + (∫⁻ ω, ENat.toENNReal (τ ω) + 1 ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁)).toReal - + Real.log (1 - ε) := by + set μ := Measure.infinitePi (fun _ : ℕ ↦ Q₁) + set m := ∫⁻ ω, ENat.toENNReal (τ ω) + 1 ∂μ + set D := (bipolarRate Q₁ S₁).toReal * m.toReal + have hd0 := bipolarRate_nonneg Q₁ S₁ + have hτm := hτ.measurable_enat + have hτle (k : ℕ) : MeasurableSet {ω | τ ω ≤ k} := + Filtration.le _ k _ (hτ.measurableSet_le_natCast k) + have hτtop : MeasurableSet {ω | τ ω ≠ ⊤} := (hτm (measurableSet_singleton ⊤)).compl + -- `τ` is almost surely finite under the i.i.d. law of `Q₁` + have hae : ∀ᵐ ω ∂μ, τ ω ≠ ⊤ := by + filter_upwards [ae_lt_top (f := fun ω ↦ ENat.toENNReal (τ ω) + 1) + ((measurable_from_top.comp hτm).add_const 1) hm] with ω hω + exact ENat.toENNReal_ne_top.1 (ne_top_of_lt (lt_of_le_of_lt le_self_add hω)) + -- the stopping times `min τ k`, with values in `ℕ` + set τk : ℕ → (ℕ → 𝓧) → ℕ := fun k ω ↦ ENat.toNat (min (τ ω) k) + have hτk_coe (k : ℕ) (ω : ℕ → 𝓧) : ((τk k ω : ℕ) : WithTop ℕ) = min (τ ω) k := + ENat.natCast_toNat (ne_top_of_le_ne_top (WithTop.natCast_ne_top k) (min_le_right _ _)) + have hτk (k : ℕ) : IsStoppingTime (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) + fun ω ↦ (τk k ω : WithTop ℕ) := by + rw [show (fun ω ↦ (τk k ω : WithTop ℕ)) = fun ω ↦ min (τ ω) k from funext (hτk_coe k)] + exact hτ.min_natCast k + have hmk (k : ℕ) : ∫⁻ ω, (τk k ω : ℝ≥0∞) + 1 ∂μ ≤ m := lintegral_mono fun ω ↦ by + gcongr + have h : ((τk k ω : ℕ) : ℕ∞) ≤ τ ω := (hτk_coe k ω).trans_le (min_le_left _ _) + exact_mod_cast ENat.toENNReal_le.2 h + -- the e-process `ε + (1 - ε) a⁻¹ 𝟙{τ ≤ n}` + have hb0 : 0 < (1 - ε) / a := div_pos (by linarith) ha0 + set b := ENNReal.ofReal ((1 - ε) / a) + set L := Real.log (ε + (1 - ε) / a) + set E : ℕ → (ℕ → 𝓧) → ℝ≥0∞ := fun n ω ↦ + ENNReal.ofReal ε + {ω | τ ω ≤ n}.indicator (fun _ ↦ b) ω + have hE : IsEProcess E (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) + ((fun P ↦ Measure.infinitePi fun _ : ℕ ↦ P) '' S₁) := by + refine IsEProcess.of_lintegral_le_one ?_ (fun n ↦ + (measurable_const.indicator (hτ.measurableSet_le_natCast n)).const_add _) + fun σ _ _ hP ↦ ?_ + · rintro _ ⟨P, hP, rfl⟩ + have := hS₁ P hP + infer_instance + obtain ⟨P, hP, rfl⟩ := hP + have := hS₁ P hP + calc ∫⁻ ω, E (σ ω) ω ∂Measure.infinitePi (fun _ ↦ P) + _ ≤ ∫⁻ ω, ENNReal.ofReal ε + {ω | τ ω ≠ ⊤}.indicator (fun _ ↦ b) ω + ∂Measure.infinitePi (fun _ ↦ P) := + lintegral_mono fun ω ↦ add_le_add le_rfl (Set.indicator_le_indicator_of_subset + (s := {x | τ x ≤ σ ω}) (t := {x | τ x ≠ ⊤}) + (fun x hx ↦ ne_top_of_le_ne_top (WithTop.natCast_ne_top _) hx) (fun _ ↦ bot_le) ω) + _ = ENNReal.ofReal ε + b * Measure.infinitePi (fun _ ↦ P) {ω | τ ω ≠ ⊤} := by + rw [lintegral_add_left measurable_const, lintegral_const, measure_univ, mul_one, + lintegral_indicator_const hτtop] + _ ≤ ENNReal.ofReal ε + b * ENNReal.ofReal a := by + gcongr + exact h_level P hP + _ = 1 := by + rw [← ENNReal.ofReal_mul hb0.le, div_mul_cancel₀ _ ha0.ne', + ← ENNReal.ofReal_add hε0.le (by linarith), add_sub_cancel, ENNReal.ofReal_one] + -- its logarithm at `min τ k` + set g : ℕ → (ℕ → 𝓧) → ℝ := fun k ω ↦ if τ ω ≤ k then L else Real.log ε + have hgm (k : ℕ) : Measurable (g k) := Measurable.ite (hτle k) measurable_const measurable_const + have hgC (k : ℕ) (ω : ℕ → 𝓧) : ‖g k ω‖ ≤ max |L| |Real.log ε| := by + rw [Real.norm_eq_abs] + by_cases h : τ ω ≤ k + · simp only [g, h, ↓reduceIte, le_max_left] + · simp only [g, h, ↓reduceIte, le_max_right] + have hlog (k : ℕ) (ω : ℕ → 𝓧) : ENNReal.log (E (τk k ω) ω) = (g k ω : EReal) := by + have hmem : ω ∈ {x | τ x ≤ (τk k ω : WithTop ℕ)} ↔ τ ω ≤ k := by + rw [Set.mem_ofPred_eq, hτk_coe] + exact ⟨fun h ↦ h.trans (min_le_right _ _), fun h ↦ le_min le_rfl h⟩ + by_cases hω : τ ω ≤ k + · simp only [E, g, Set.indicator_of_mem (hmem.2 hω), hω, ↓reduceIte] + rw [← ENNReal.ofReal_add hε0.le hb0.le, ENNReal.log_ofReal_of_pos (by linarith)] + · simp only [E, g, Set.indicator_of_notMem (mt hmem.1 hω), hω, ↓reduceIte, add_zero] + rw [ENNReal.log_ofReal_of_pos hε0] + have hk (k : ℕ) : ∫ ω, g k ω ∂μ ≤ D := by + have hg : Integrable (g k) μ := + Integrable.of_bound (hgm k).aestronglyMeasurable _ (ae_of_all _ (hgC k)) + have h := hE.eintegral_log_stoppedValue_le_mul_bipolarRate Q₁ hS₁ (hτk k) + have hmk' : ∫⁻ ω, (τk k ω : ℝ≥0∞) + 1 ∂μ ≠ ∞ := ne_top_of_le_ne_top hm (hmk k) + rw [eintegral_congr (hlog k), eintegral_eq_integral hg, ← EReal.coe_ennreal_toReal hmk', + ← EReal.coe_toReal hd (ne_bot_of_le_ne_bot EReal.zero_ne_bot hd0), ← EReal.coe_mul, + EReal.coe_le_coe_iff] at h + calc ∫ ω, g k ω ∂μ ≤ _ := h + _ ≤ m.toReal * (bipolarRate Q₁ S₁).toReal := + mul_le_mul_of_nonneg_right (ENNReal.toReal_mono hm (hmk k)) (EReal.toReal_nonneg hd0) + _ = D := mul_comm _ _ + -- let `k` tend to infinity + have hL : L ≤ D := by + have h := le_of_tendsto' (tendsto_integral_of_dominated_convergence (f := fun _ ↦ L) _ + (fun k ↦ (hgm k).aestronglyMeasurable) (integrable_const _) (fun k ↦ ae_of_all _ (hgC k)) + (hae.mono fun ω hω ↦ ?_)) hk + · simpa using h + obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.1 hω + refine tendsto_atTop_of_eventually_const (i₀ := n) fun k hk ↦ ?_ + have : τ ω ≤ k := by + rw [← hn] + exact WithTop.coe_le_coe.2 hk + simp only [g, this, ↓reduceIte] + have h1 : Real.log (1 - ε) - Real.log a ≤ L := by + rw [← Real.log_div (by linarith) ha0.ne'] + exact Real.log_le_log hb0 (by linarith) + linarith + +/-- **The lower bound on expected stopping times.** A sequential test of level `α` for the i.i.d. +laws of the members of `S₁`, that is, a stopping time `τ` with `P^ℕ (τ < ∞) ≤ α` for every +`P ∈ S₁`, makes at least `log (1/α) / d` observations in expectation under the i.i.d. law of +`Q₁`, where `d` is the bipolar rate of `Q₁` against `S₁`: `log (1/α) / d ≤ 𝔼[τ + 1]`. The left +side is in `ℝ≥0∞`, with `log (1/α)` replaced by `0` for `α ≥ 1`: if `d = 0` and `α < 1`, the +expected number of observations is infinite, if `d = ∞` the bound is `0`, and if `α = 0` and +`d < ∞` the expected number of observations is infinite. Since the bipolar rate is at most the +smallest relative entropy from `Q₁` to `S₁` (`bipolarRate_le_iInf_klDiv`), this contains the +lower bound `log (1/α) / KL_inf(Q₁, S₁)` [ARR26]. -/ +theorem toENNReal_log_inv_div_bipolarRate_le_lintegral (Q₁ : Measure 𝓧) + [IsProbabilityMeasure Q₁] (hS₁ : ∀ P ∈ S₁, IsProbabilityMeasure P) + (hτ : IsStoppingTime (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) τ) {α : ℝ≥0∞} + (h_level : ∀ P ∈ S₁, Measure.infinitePi (fun _ : ℕ ↦ P) {ω | τ ω ≠ ⊤} ≤ α) : + (ENNReal.log α⁻¹).toENNReal / (bipolarRate Q₁ S₁).toENNReal ≤ + ∫⁻ ω, ENat.toENNReal (τ ω) + 1 ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁) := by + set m := ∫⁻ ω, ENat.toENNReal (τ ω) + 1 ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁) + by_cases hm : m = ∞ + · rw [hm] + exact le_top + by_cases hd : bipolarRate Q₁ S₁ = ⊤ + · simp [hd] + by_cases hα1 : 1 ≤ α + · rw [EReal.toENNReal_of_nonpos (ENNReal.log_le_zero_iff.2 (ENNReal.inv_le_one.2 hα1)), + ENNReal.zero_div] + exact bot_le + have hD0 : 0 ≤ (bipolarRate Q₁ S₁).toReal * m.toReal := + mul_nonneg (EReal.toReal_nonneg (bipolarRate_nonneg Q₁ S₁)) ENNReal.toReal_nonneg + -- the bound up to `- log (1 - ε)`, for every `ε ∈ (0, 1)`, gives the bound + have key {a : ℝ} (ha0 : 0 < a) + (h_level' : ∀ P ∈ S₁, Measure.infinitePi (fun _ : ℕ ↦ P) {ω | τ ω ≠ ⊤} ≤ + ENNReal.ofReal a) : + -Real.log a ≤ (bipolarRate Q₁ S₁).toReal * m.toReal := by + refine le_of_forall_pos_le_add fun η hη ↦ ?_ + have hexp : Real.exp (-η) < 1 := Real.exp_lt_one_iff.2 (by linarith) + have h := neg_log_le_toReal_mul_sub Q₁ hS₁ hτ ha0 h_level' hd hm + (ε := 1 - Real.exp (-η)) (by linarith) (by linarith [Real.exp_pos (-η)]) + rwa [sub_sub_cancel, Real.log_exp, sub_neg_eq_add] at h + rcases eq_or_ne α 0 with rfl | hα0 + · -- a test of level `0` with a finite expected number of observations would have level + -- `exp (- (d 𝔼[τ + 1] + 1))` + have h := key (Real.exp_pos (-((bipolarRate Q₁ S₁).toReal * m.toReal + 1))) + fun P hP ↦ (h_level P hP).trans bot_le + rw [Real.log_exp, neg_neg] at h + linarith + have hαtop : α ≠ ⊤ := ne_top_of_lt (not_le.1 hα1) + have h := key (ENNReal.toReal_pos hα0 hαtop) + fun P hP ↦ (h_level P hP).trans_eq (ENNReal.ofReal_toReal hαtop).symm + rw [ENNReal.log_inv, ENNReal.log_pos_real hα0 hαtop, ← EReal.coe_neg, + EReal.toENNReal_of_ne_top (EReal.coe_ne_top _), EReal.toReal_coe] + refine ENNReal.div_le_of_le_mul ?_ + rw [EReal.toENNReal_of_ne_top hd, ← ENNReal.ofReal_toReal hm, + ← ENNReal.ofReal_mul ENNReal.toReal_nonneg] + exact ENNReal.ofReal_le_ofReal (by linarith [mul_comm m.toReal (bipolarRate Q₁ S₁).toReal]) + +end Test + +end ProbabilityTheory From 96cbf0f40e9303b26236e3ed2151c35140538636 Mon Sep 17 00:00:00 2001 From: Remy Degenne Date: Sun, 15 Nov 2026 17:23:06 +0100 Subject: [PATCH 2/8] refactor: expose the general helpers of the Wald inequality and split its file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move the facts on the shift under `Measure.infinitePi` to `Probability/ProductMeasure.lean`, the `ℕ`-valued stopping-time lemmas to `Probability/Process/Stopping.lean` and monotone convergence for truncations under `∫ᵉ` to the new `MeasureTheory/Integral/EReal.lean`, all public. Use Mathlib's `EReal.le_of_forall_lt_iff_le` and `Finset.sum_ite_eq` instead of re-deriving them. Factor the repeated proof steps into lemmas and split the long proofs. Cite [EVR26, Note 01] and the paper project the proofs are adapted from. Move the restarted rounds and the Wald inequality for a round to `EValues/BipolarRate/Round.lean`, keeping each new file under 1000 lines. Co-Authored-By: Claude Code --- LMLExplore/EValues/BipolarRate/Basic.lean | 6 + LMLExplore/EValues/BipolarRate/Round.lean | 834 +++++++++++++ .../EValues/BipolarRate/StoppingTime.lean | 1112 ++--------------- LMLExplore/MeasureTheory/Integral/EReal.lean | 77 ++ LMLExplore/Probability/Process/Stopping.lean | 42 + LMLExplore/Probability/ProductMeasure.lean | 85 +- 6 files changed, 1176 insertions(+), 980 deletions(-) create mode 100644 LMLExplore/EValues/BipolarRate/Round.lean create mode 100644 LMLExplore/MeasureTheory/Integral/EReal.lean diff --git a/LMLExplore/EValues/BipolarRate/Basic.lean b/LMLExplore/EValues/BipolarRate/Basic.lean index d0719966..95d45eb4 100644 --- a/LMLExplore/EValues/BipolarRate/Basic.lean +++ b/LMLExplore/EValues/BipolarRate/Basic.lean @@ -229,6 +229,12 @@ theorem bipolarRate_le_iInf_klDiv (Q₁ : Measure 𝓧) [IsProbabilityMeasure Q rw [← EReal.toENNReal_coe (x := klDiv Q₁ P)] exact EReal.toENNReal_le_toENNReal (bipolarRate_le_klDiv Q₁ hP) +/-- A finite bipolar rate is the real number `(bipolarRate Q₁ S₁).toReal`, since it is +nonnegative. -/ +lemma coe_toReal_bipolarRate (hd : bipolarRate Q₁ S₁ ≠ ⊤) : + ((bipolarRate Q₁ S₁).toReal : EReal) = bipolarRate Q₁ S₁ := + EReal.coe_toReal hd (ne_bot_of_le_ne_bot EReal.zero_ne_bot (bipolarRate_nonneg Q₁ S₁)) + /-- A real lower bound on the growth of `n + 1` observations, divided by `n + 1`, that converges to `L` gives the lower bound `L` on the bipolar rate. -/ lemma le_bipolarRate_of_tendsto {r : ℕ → ℝ} {L : ℝ} diff --git a/LMLExplore/EValues/BipolarRate/Round.lean b/LMLExplore/EValues/BipolarRate/Round.lean new file mode 100644 index 00000000..df03c1f4 --- /dev/null +++ b/LMLExplore/EValues/BipolarRate/Round.lean @@ -0,0 +1,834 @@ +/- +Copyright (c) 2026 LMLExplore contributors. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: LMLExplore contributors +-/ +module + +public import LMLExplore.EValues.BipolarRate.Basic +public import Mathlib.Probability.ProductMeasure +public import TauCeti.Probability.Process.PathLaw.Shift +import LMLExplore.EValues.BipolarRate.EProcess +import LMLExplore.Probability.ProductMeasure +import Statlib.ForMathlib.MeasureTheory.Integral.EReal.Bochner + +/-! +# The Wald inequality at the bipolar rate for a round + +Let `S₁` be a set of probability measures on `𝓧` (the null) and `Q₁` a probability measure on `𝓧` +(the alternative), and write `d = bipolarRate Q₁ S₁`. The observations are the coordinates of +`ℕ → 𝓧`, with the i.i.d. laws `Measure.infinitePi fun _ ↦ P`. A round is a duration +`σ : (ℕ → 𝓧) → ℕ`, the number of observations that it uses, and a payoff `V : (ℕ → 𝓧) → ℝ≥0∞`, +both determined by the observations of the round (`ProbabilityTheory.DependsOnBefore`). If +`1 ≤ σ ≤ K`, `V ≥ δ > 0` and the payoff has expectation at most `1` on each event `{σ ≤ n}` under +the i.i.d. law of every member of the null, then under the i.i.d. law of `Q₁` the expected +logarithm of the payoff, truncated above at `c` (`ProbabilityTheory.truncLog`), is at most +`d * 𝔼[σ]` [EVR26, Note 01]. This is the step of the proof of the Wald inequality +`ProbabilityTheory.IsEProcess.eintegral_log_stoppedValue_le_mul_bipolarRate` that uses the +bipolar rate. + +## Main definitions + +* `ProbabilityTheory.DependsOnBefore σ f`: `f` is determined by the first `σ` observations + (`ProbabilityTheory.dependsOnBefore_iff`). +* `ProbabilityTheory.truncLog c x`: the logarithm of `x : ℝ≥0∞` truncated above at `c`, as a real + number. + +## Main statements + +* `ProbabilityTheory.integral_truncLog_le_bipolarRate_mul`: the Wald inequality for a round, + `𝔼_Q[truncLog c V] ≤ d * 𝔼_Q[σ]`. +* `ProbabilityTheory.min_log_le_truncLog_sub`: mixing a payoff `x` with a constant `ε` costs at + most `- log (1 - ε)` in truncated logarithm. + +## Implementation notes + +The proof restarts the round on the fresh observations each time it ends (Tau Ceti's +`TauCeti.Probability.shift`, iterated), and bets on the number of completed rounds with a +geometric mixture. Within the first `N` observations, the mixture over the rounds completed so far +of the products of their payoffs is an `N`-sample e-variable: by induction on the number of +rounds, splitting along the value `t` of the restart time, using that under an i.i.d. law the +first `t` observations are independent of the later ones. Its expected logarithm under `Q` is at +most `maxLogGrowth Q₁ S₁ N ≤ N * d`. A Wald argument shows that the rounds that start within the +first `N` observations use at least `N + 1` observations, hence that `(N + 1) / 𝔼_Q[σ]` of them +start in expectation; letting `N → ∞` bounds the expected truncated logarithm of the payoff by +`d * 𝔼_Q[σ]`. The proof uses neither the law of large numbers nor the strong Markov property. +The restart construction and its lemmas are private. + +The proofs are adapted from `EValuesResearch/Results/BipolarRate.lean` and +`EValuesResearch/Results/BipolarRateAux.lean` (commit `dd4072f`) in the paper project +`RemyDegenne/evalues_research`, which formalizes [EVR26, Note 01]. They are specialized here to +bounded rounds. + +## References + +* [EVR26] the research notes of the paper project `RemyDegenne/evalues_research`: Note 01, + `results/01-bipolar-rate.md`. +-/ + +public section + +open MeasureTheory Filter +open TauCeti.Probability (shift shift_iterate_apply measurable_shift_iterate) +open scoped ENNReal + +namespace ProbabilityTheory + +variable {𝓧 : Type*} {m𝓧 : MeasurableSpace 𝓧} {S₁ : Set (Measure 𝓧)} + +/-! ### Restarting a round on the fresh observations + +A round is a pair of a duration `σ : (ℕ → 𝓧) → ℕ`, the number of observations that it uses, and a +payoff `V : (ℕ → 𝓧) → ℝ≥0∞`, both determined by the observations of the round. Restarting the +round on the fresh observations at its end gives the restart times `restartTime σ j` and the +products `restartPayoff σ V j` of the payoffs of the first `j` rounds. -/ + +/-- `f` is determined by the first `σ` observations: if `σ ω ≤ u` and `ω'` agrees with `ω` on the +first `u` observations, then `f ω' = f ω`. For `f = σ`, this says that `σ` is a stopping time +counted in observations. -/ +def DependsOnBefore {β : Type*} (σ : (ℕ → 𝓧) → ℕ) (f : (ℕ → 𝓧) → β) : Prop := + ∀ ⦃u : ℕ⦄ ⦃ω ω' : ℕ → 𝓧⦄, (∀ i < u, ω i = ω' i) → σ ω ≤ u → f ω' = f ω + +/-- The defining property of `DependsOnBefore`. -/ +lemma dependsOnBefore_iff {β : Type*} {σ : (ℕ → 𝓧) → ℕ} {f : (ℕ → 𝓧) → β} : + DependsOnBefore σ f ↔ + ∀ ⦃u : ℕ⦄ ⦃ω ω' : ℕ → 𝓧⦄, (∀ i < u, ω i = ω' i) → σ ω ≤ u → f ω' = f ω := + Iff.rfl + +section Restart + +variable (σ : (ℕ → 𝓧) → ℕ) (V : (ℕ → 𝓧) → ℝ≥0∞) + +/-- The number of observations used by the first `j` rounds, when a round that uses `σ ω` +observations is restarted on the fresh observations at its end. -/ +private def restartTime : ℕ → (ℕ → 𝓧) → ℕ + | 0 => fun _ ↦ 0 + | j + 1 => fun ω ↦ restartTime j ω + σ ((shift 𝓧)^[restartTime j ω] ω) + +/-- The product of the payoffs `V` of the first `j` restarted rounds. -/ +private noncomputable def restartPayoff : ℕ → (ℕ → 𝓧) → ℝ≥0∞ + | 0 => fun _ ↦ 1 + | j + 1 => fun ω ↦ restartPayoff j ω * V ((shift 𝓧)^[restartTime σ j ω] ω) + +/-- The round after the first `j` ones is played on the observations after them. -/ +private lemma restartTime_succ (j : ℕ) (ω : ℕ → 𝓧) : + restartTime σ (j + 1) ω = restartTime σ j ω + σ ((shift 𝓧)^[restartTime σ j ω] ω) := + rfl + +/-- The payoff of `j + 1` rounds is that of the first `j` times that of the next one. -/ +private lemma restartPayoff_succ (j : ℕ) (ω : ℕ → 𝓧) : + restartPayoff σ V (j + 1) ω = + restartPayoff σ V j ω * V ((shift 𝓧)^[restartTime σ j ω] ω) := + rfl + +/-- The restart times are nondecreasing in the number of rounds. -/ +private lemma monotone_restartTime (ω : ℕ → 𝓧) : Monotone fun j ↦ restartTime σ j ω := + monotone_nat_of_le_succ fun _ ↦ Nat.le_add_right _ _ + +/-- If every round uses at least one observation, `j` rounds use at least `j` observations. -/ +private lemma le_restartTime (hσ1 : ∀ ω, 1 ≤ σ ω) (j : ℕ) (ω : ℕ → 𝓧) : + j ≤ restartTime σ j ω := by + induction j with + | zero => exact le_rfl + | succ j ih => exact Nat.add_le_add ih (hσ1 _) + +/-- The first `j` rounds use the sum of their durations. -/ +private lemma restartTime_eq_sum (j : ℕ) (ω : ℕ → 𝓧) : + restartTime σ j ω = ∑ i ∈ Finset.range j, σ ((shift 𝓧)^[restartTime σ i ω] ω) := by + induction j with + | zero => rfl + | succ j ih => rw [Finset.sum_range_succ, ← ih, restartTime_succ] + +/-- The payoff of the first `j` rounds is the product of their payoffs. -/ +private lemma restartPayoff_eq_prod (j : ℕ) (ω : ℕ → 𝓧) : + restartPayoff σ V j ω = ∏ i ∈ Finset.range j, V ((shift 𝓧)^[restartTime σ i ω] ω) := by + induction j with + | zero => rfl + | succ j ih => rw [Finset.prod_range_succ, ← ih, restartPayoff_succ] + +variable {σ V} + +/-- The restart times are measurable. -/ +private lemma measurable_restartTime (hσm : Measurable σ) (j : ℕ) : + Measurable (restartTime σ j) := by + induction j with + | zero => exact measurable_const + | succ j ih => exact ih.add (measurable_comp_shift_iterate hσm ih) + +/-- The products of the payoffs of the restarted rounds are measurable. -/ +private lemma measurable_restartPayoff (hσm : Measurable σ) (hVm : Measurable V) (j : ℕ) : + Measurable (restartPayoff σ V j) := by + induction j with + | zero => exact measurable_const + | succ j ih => exact ih.mul (measurable_comp_shift_iterate hVm (measurable_restartTime hσm j)) + +/-- If two sequences of observations agree on the first `t`, their shifts by `s` agree on the +first `t - s`. -/ +private lemma shift_iterate_eqOn {t : ℕ} {ω ω' : ℕ → 𝓧} (h : ∀ i < t, ω i = ω' i) (s : ℕ) : + ∀ i < t - s, (shift 𝓧)^[s] ω i = (shift 𝓧)^[s] ω' i := fun i hi ↦ by + simp only [shift_iterate_apply] + exact h _ (by omega) + +/-- The first `j` rounds are determined by the observations that they use. -/ +private lemma restartTime_eq_of_eqOn (hσ : DependsOnBefore σ σ) (j : ℕ) {t : ℕ} + {ω ω' : ℕ → 𝓧} (h : ∀ i < t, ω i = ω' i) (hj : restartTime σ j ω ≤ t) : + restartTime σ j ω' = restartTime σ j ω := by + induction j with + | zero => rfl + | succ j ih => + rw [restartTime_succ] at hj + have h1 := ih (by omega) + rw [restartTime_succ, restartTime_succ, h1, hσ (shift_iterate_eqOn h (restartTime σ j ω)) + (by omega)] + +/-- The payoffs of the first `j` rounds are determined by the observations that they use. -/ +private lemma restartPayoff_eq_of_eqOn (hσ : DependsOnBefore σ σ) (hV : DependsOnBefore σ V) + (j : ℕ) {t : ℕ} {ω ω' : ℕ → 𝓧} (h : ∀ i < t, ω i = ω' i) (hj : restartTime σ j ω ≤ t) : + restartPayoff σ V j ω' = restartPayoff σ V j ω := by + induction j with + | zero => rfl + | succ j ih => + rw [restartTime_succ] at hj + have h1 := restartTime_eq_of_eqOn hσ j h (by omega) + have h2 := ih (by omega) + rw [restartPayoff_succ, restartPayoff_succ, h1, h2, + hV (shift_iterate_eqOn h (restartTime σ j ω)) (by omega)] + +/-- Whether the first `j` rounds use exactly `t` observations is determined by the first `t` +observations. -/ +private lemma restartTime_eq_iff_of_eqOn (hσ : DependsOnBefore σ σ) (j t : ℕ) {ω ω' : ℕ → 𝓧} + (h : ∀ i < t, ω i = ω' i) : restartTime σ j ω' = t ↔ restartTime σ j ω = t := + ⟨fun h' ↦ (restartTime_eq_of_eqOn hσ j (fun i hi ↦ (h i hi).symm) h'.le).trans h', + fun h' ↦ (restartTime_eq_of_eqOn hσ j h h'.le).trans h'⟩ + +/-- Whether the first `j` rounds use at most `N` observations is determined by the first `N` +observations. -/ +private lemma restartTime_le_iff_of_eqOn (hσ : DependsOnBefore σ σ) (j N : ℕ) {ω ω' : ℕ → 𝓧} + (h : ∀ i < N, ω i = ω' i) : restartTime σ j ω' ≤ N ↔ restartTime σ j ω ≤ N := + ⟨fun h' ↦ (restartTime_eq_of_eqOn hσ j (fun i hi ↦ (h i hi).symm) h') ▸ h', + fun h' ↦ (restartTime_eq_of_eqOn hσ j h h').symm ▸ h'⟩ + +/-- The indicator of an event determined by the first `t` observations, applied to a function +determined by them on that event, is a function of the first `t` observations. -/ +private lemma dependsOn_indicator_of_eqOn {β : Type*} [Zero β] {A : Set (ℕ → 𝓧)} + {f : (ℕ → 𝓧) → β} {t : ℕ} + (hA : ∀ ⦃ω ω' : ℕ → 𝓧⦄, (∀ i < t, ω i = ω' i) → (ω' ∈ A ↔ ω ∈ A)) + (hf : ∀ ⦃ω ω' : ℕ → 𝓧⦄, (∀ i < t, ω i = ω' i) → ω ∈ A → f ω' = f ω) : + DependsOn (A.indicator f) (Set.Iio t) := by + intro ω ω' h + have h' : ∀ i < t, ω i = ω' i := fun i hi ↦ h i hi + by_cases hω : ω ∈ A + · rw [Set.indicator_of_mem hω, Set.indicator_of_mem ((hA h').2 hω), hf h' hω] + · rw [Set.indicator_of_notMem hω, Set.indicator_of_notMem (mt (hA h').1 hω)] + +/-- On the event that the first `j` rounds use `t` observations, their payoff is a function of +the first `t` observations. -/ +private lemma dependsOn_indicator_restartTime_eq (hσ : DependsOnBefore σ σ) + (hV : DependsOnBefore σ V) (j t : ℕ) : + DependsOn ({ω | restartTime σ j ω = t}.indicator (restartPayoff σ V j)) (Set.Iio t) := + dependsOn_indicator_of_eqOn (fun _ _ h ↦ restartTime_eq_iff_of_eqOn hσ j t h) + fun _ _ h hω ↦ restartPayoff_eq_of_eqOn hσ hV j h (le_of_eq hω) + +/-- The indicator of the event that the first `i` rounds use `t` observations is a function of +the first `t` observations. -/ +private lemma dependsOn_indicator_one_restartTime_eq (hσ : DependsOnBefore σ σ) (i t : ℕ) : + DependsOn ({ω | restartTime σ i ω = t}.indicator (1 : (ℕ → 𝓧) → ℝ)) (Set.Iio t) := + dependsOn_indicator_of_eqOn (fun _ _ h ↦ restartTime_eq_iff_of_eqOn hσ i t h) + fun _ _ _ _ ↦ rfl + +/-- On the event that the first `j` rounds use at most `N` observations, their payoff is a +function of the first `N` observations. -/ +private lemma dependsOn_indicator_restartTime_le (hσ : DependsOnBefore σ σ) + (hV : DependsOnBefore σ V) (j N : ℕ) : + DependsOn ({ω | restartTime σ j ω ≤ N}.indicator (restartPayoff σ V j)) (Set.Iio N) := + dependsOn_indicator_of_eqOn (fun _ _ h ↦ restartTime_le_iff_of_eqOn hσ j N h) + fun _ _ h hω ↦ restartPayoff_eq_of_eqOn hσ hV j h hω + +/-- Summing the indicators of the events `{T = t}`, `t ≤ N`, gives the indicator of `{T ≤ N}`. -/ +private lemma sum_indicator_eq_indicator_le {Ω M : Type*} [AddCommMonoid M] (T : Ω → ℕ) + (f : Ω → M) (N : ℕ) (ω : Ω) : + ∑ t ∈ Finset.range (N + 1), {ω | T ω = t}.indicator f ω = {ω | T ω ≤ N}.indicator f ω := by + simp only [Set.indicator_apply, Set.mem_ofPred_eq, Finset.sum_ite_eq, Finset.mem_range, + Nat.lt_succ_iff] + +/-- On the event `{T = t}`, a function `G t` of the time `t` is the function `G (T ·)` of the +random time: `𝟙{T = t} f * G t = 𝟙{T = t} (f * G T)`. -/ +private lemma indicator_eq_mul_apply {Ω M : Type*} [MulZeroClass M] (T : Ω → ℕ) (t : ℕ) + (f : Ω → M) (G : ℕ → Ω → M) (ω : Ω) : + {ω | T ω = t}.indicator f ω * G t ω = + {ω | T ω = t}.indicator (fun ω' ↦ f ω' * G (T ω') ω') ω := by + by_cases h : T ω = t + · rw [Set.indicator_of_mem (s := {x | T x = t}) h, Set.indicator_of_mem (s := {x | T x = t}) h, + h] + · rw [Set.indicator_of_notMem (s := {x | T x = t}) h, + Set.indicator_of_notMem (s := {x | T x = t}) h, zero_mul] + +/-- The event that the first `j` rounds use at most `N` observations is measurable. -/ +private lemma measurableSet_restartTime_le (hσm : Measurable σ) (j N : ℕ) : + MeasurableSet {ω | restartTime σ j ω ≤ N} := + measurable_restartTime hσm j measurableSet_Iic + +/-- The event that the first `j` rounds use exactly `t` observations is measurable. -/ +private lemma measurableSet_restartTime_eq (hσm : Measurable σ) (j t : ℕ) : + MeasurableSet {ω | restartTime σ j ω = t} := + measurable_restartTime hσm j (measurableSet_singleton t) + +/-- The payoff of `j + 1` rounds within `N` observations, decomposed along the number `t` of +observations used by the first `j` rounds. -/ +private lemma indicator_restartTime_succ_le (j N : ℕ) (ω : ℕ → 𝓧) : + {ω | restartTime σ (j + 1) ω ≤ N}.indicator (restartPayoff σ V (j + 1)) ω = + ∑ t ∈ Finset.range (N + 1), + {ω | restartTime σ j ω = t}.indicator (restartPayoff σ V j) ω * + {ω | σ ω ≤ N - t}.indicator V ((shift 𝓧)^[t] ω) := by + have hterm (t : ℕ) : {ω | restartTime σ j ω = t}.indicator (restartPayoff σ V j) ω * + {ω | σ ω ≤ N - t}.indicator V ((shift 𝓧)^[t] ω) = + {ω | restartTime σ j ω = t}.indicator (fun ω' ↦ restartPayoff σ V j ω' * + {x | σ x ≤ N - restartTime σ j ω'}.indicator V + ((shift 𝓧)^[restartTime σ j ω'] ω')) ω := + indicator_eq_mul_apply (restartTime σ j) t (restartPayoff σ V j) + (fun s ω ↦ {x | σ x ≤ N - s}.indicator V ((shift 𝓧)^[s] ω)) ω + rw [Finset.sum_congr rfl fun t _ ↦ hterm t, sum_indicator_eq_indicator_le] + simp only [Set.indicator, Set.mem_ofPred_eq, restartTime_succ, restartPayoff_succ] + by_cases h1 : restartTime σ j ω ≤ N + · by_cases h2 : σ ((shift 𝓧)^[restartTime σ j ω] ω) ≤ N - restartTime σ j ω + · have h3 : restartTime σ j ω + σ ((shift 𝓧)^[restartTime σ j ω] ω) ≤ N := by omega + simp only [h1, h2, h3, ↓reduceIte] + · have h3 : ¬ restartTime σ j ω + σ ((shift 𝓧)^[restartTime σ j ω] ω) ≤ N := by omega + simp only [h1, h2, h3, ↓reduceIte, mul_zero] + · have h3 : ¬ restartTime σ j ω + σ ((shift 𝓧)^[restartTime σ j ω] ω) ≤ N := by omega + simp only [h1, h3, ↓reduceIte] + +/-- If the payoff of a round has expectation at most `1` on each event `{σ ≤ n}` under an i.i.d. +law, so has the product of the payoffs of `j` restarted rounds on each event that they use at most +`N` observations. -/ +private lemma lintegral_indicator_restartPayoff_le_one (hσ : DependsOnBefore σ σ) + (hV : DependsOnBefore σ V) (hσm : Measurable σ) (hVm : Measurable V) + (P : Measure 𝓧) [IsProbabilityMeasure P] + (h_null : ∀ n : ℕ, + ∫⁻ ω, {ω | σ ω ≤ n}.indicator V ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) ≤ 1) + (j N : ℕ) : + ∫⁻ ω, {ω | restartTime σ j ω ≤ N}.indicator (restartPayoff σ V j) ω + ∂Measure.infinitePi (fun _ : ℕ ↦ P) ≤ 1 := by + set μ := Measure.infinitePi (fun _ : ℕ ↦ P) + induction j generalizing N with + | zero => + calc ∫⁻ ω, {ω | restartTime σ 0 ω ≤ N}.indicator (restartPayoff σ V 0) ω ∂μ + _ ≤ ∫⁻ _, 1 ∂μ := lintegral_mono fun ω ↦ Set.indicator_le (fun _ _ ↦ le_rfl) ω + _ = 1 := by simp + | succ j ih => + have hf (t : ℕ) : + Measurable ({ω | restartTime σ j ω = t}.indicator (restartPayoff σ V j)) := + (measurable_restartPayoff hσm hVm j).indicator + (measurableSet_restartTime_eq hσm j t) + have hg (t : ℕ) : Measurable ({ω | σ ω ≤ N - t}.indicator V) := + hVm.indicator (hσm measurableSet_Iic) + calc ∫⁻ ω, {ω | restartTime σ (j + 1) ω ≤ N}.indicator (restartPayoff σ V (j + 1)) ω ∂μ + _ = ∑ t ∈ Finset.range (N + 1), + ∫⁻ ω, {ω | restartTime σ j ω = t}.indicator (restartPayoff σ V j) ω * + {ω | σ ω ≤ N - t}.indicator V ((shift 𝓧)^[t] ω) ∂μ := by + simp_rw [indicator_restartTime_succ_le] + exact lintegral_finsetSum _ fun t _ ↦ + (hf t).mul ((hg t).comp (measurable_shift_iterate t)) + _ = ∑ t ∈ Finset.range (N + 1), + (∫⁻ ω, {ω | restartTime σ j ω = t}.indicator (restartPayoff σ V j) ω ∂μ) * + ∫⁻ ω, {ω | σ ω ≤ N - t}.indicator V ω ∂μ := + Finset.sum_congr rfl fun t _ ↦ lintegral_mul_comp_shift_iterate P (hf t) + (dependsOn_indicator_restartTime_eq hσ hV j t) (hg t) + _ ≤ ∑ t ∈ Finset.range (N + 1), + ∫⁻ ω, {ω | restartTime σ j ω = t}.indicator (restartPayoff σ V j) ω ∂μ := + Finset.sum_le_sum fun t _ ↦ mul_le_of_le_one_right' (h_null _) + _ = ∫⁻ ω, {ω | restartTime σ j ω ≤ N}.indicator (restartPayoff σ V j) ω ∂μ := by + rw [← lintegral_finsetSum _ fun t _ ↦ hf t] + exact lintegral_congr fun ω ↦ sum_indicator_eq_indicator_le _ _ N ω + _ ≤ 1 := ih N + +variable (σ V) in +/-- The geometric mixture, with weights `(1 - r) r ^ j`, of the products of the payoffs of the +first `j` rounds on the event that they use at most `N` observations. -/ +private noncomputable def restartMixture (r : ℝ) (N : ℕ) (ω : ℕ → 𝓧) : ℝ≥0∞ := + ∑ j ∈ Finset.range (N + 1), ENNReal.ofReal ((1 - r) * r ^ j) * + {ω | restartTime σ j ω ≤ N}.indicator (restartPayoff σ V j) ω + +/-- The mixture of restarted rounds is measurable. -/ +private lemma measurable_restartMixture (hσm : Measurable σ) (hVm : Measurable V) (r : ℝ) + (N : ℕ) : Measurable (restartMixture σ V r N) := + Finset.measurable_fun_sum _ fun j _ ↦ measurable_const.mul + ((measurable_restartPayoff hσm hVm j).indicator + (measurableSet_restartTime_le hσm j N)) + +/-- The mixture of the rounds completed within the first `N` observations is a function of the +first `N` observations. -/ +private lemma dependsOn_restartMixture (hσ : DependsOnBefore σ σ) (hV : DependsOnBefore σ V) + (r : ℝ) (N : ℕ) : DependsOn (restartMixture σ V r N) (Set.Iio N) := fun ω ω' h ↦ + Finset.sum_congr rfl fun j _ ↦ by rw [dependsOn_indicator_restartTime_le hσ hV j N h] + +/-- The mixture of restarted rounds has expectation at most `1` under an i.i.d. law for which the +payoff of a round has expectation at most `1` on each event `{σ ≤ n}`. -/ +private lemma lintegral_restartMixture_le_one (hσ : DependsOnBefore σ σ) + (hV : DependsOnBefore σ V) (hσm : Measurable σ) (hVm : Measurable V) (P : Measure 𝓧) + [IsProbabilityMeasure P] + (h_null : ∀ n : ℕ, + ∫⁻ ω, {ω | σ ω ≤ n}.indicator V ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) ≤ 1) + {r : ℝ} (hr0 : 0 ≤ r) (hr1 : r ≤ 1) (N : ℕ) : + ∫⁻ ω, restartMixture σ V r N ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) ≤ 1 := by + have hm (j : ℕ) : + Measurable ({ω | restartTime σ j ω ≤ N}.indicator (restartPayoff σ V j)) := + (measurable_restartPayoff hσm hVm j).indicator + (measurableSet_restartTime_le hσm j N) + simp only [restartMixture] + rw [lintegral_finsetSum _ fun j _ ↦ (hm j).const_mul _] + calc ∑ j ∈ Finset.range (N + 1), ∫⁻ ω, ENNReal.ofReal ((1 - r) * r ^ j) * + {ω | restartTime σ j ω ≤ N}.indicator (restartPayoff σ V j) ω + ∂Measure.infinitePi (fun _ : ℕ ↦ P) + _ = ∑ j ∈ Finset.range (N + 1), ENNReal.ofReal ((1 - r) * r ^ j) * + ∫⁻ ω, {ω | restartTime σ j ω ≤ N}.indicator (restartPayoff σ V j) ω + ∂Measure.infinitePi (fun _ : ℕ ↦ P) := + Finset.sum_congr rfl fun j _ ↦ lintegral_const_mul _ (hm j) + _ ≤ ∑ j ∈ Finset.range (N + 1), ENNReal.ofReal ((1 - r) * r ^ j) := + Finset.sum_le_sum fun j _ ↦ mul_le_of_le_one_right' + (lintegral_indicator_restartPayoff_le_one hσ hV hσm hVm P h_null j N) + _ = ENNReal.ofReal (1 - r ^ (N + 1)) := by + rw [← ENNReal.ofReal_sum_of_nonneg fun j _ ↦ mul_nonneg (by linarith) (pow_nonneg hr0 j), + ← Finset.mul_sum, mul_neg_geom_sum] + _ ≤ 1 := ENNReal.ofReal_le_one.2 (by have := pow_nonneg hr0 (N + 1); linarith) + +variable (σ) in +/-- The number of rounds completed within the first `N` observations. -/ +private def numRounds (N : ℕ) (ω : ℕ → 𝓧) : ℕ := + Nat.findGreatest (fun j ↦ restartTime σ j ω ≤ N) N + +/-- At most `N` rounds are completed within `N` observations. -/ +private lemma numRounds_le (N : ℕ) (ω : ℕ → 𝓧) : numRounds σ N ω ≤ N := Nat.findGreatest_le N + +/-- The completed rounds use at most `N` observations. -/ +private lemma restartTime_numRounds_le (N : ℕ) (ω : ℕ → 𝓧) : + restartTime σ (numRounds σ N ω) ω ≤ N := + Nat.findGreatest_spec (P := fun j ↦ restartTime σ j ω ≤ N) (Nat.zero_le N) (Nat.zero_le N) + +/-- For `i ≤ N`, the first `i` rounds use at most `N` observations if and only if they are among +the completed rounds. -/ +private lemma restartTime_le_iff_le_numRounds {N i : ℕ} (hi : i ≤ N) (ω : ℕ → 𝓧) : + restartTime σ i ω ≤ N ↔ i ≤ numRounds σ N ω := + ⟨fun h ↦ Nat.le_findGreatest hi h, + fun h ↦ (monotone_restartTime σ ω h).trans (restartTime_numRounds_le N ω)⟩ + +/-- If every round uses at least one observation, the round after the completed ones ends after +the first `N` observations. -/ +private lemma lt_restartTime_numRounds_succ (hσ1 : ∀ ω, 1 ≤ σ ω) (N : ℕ) (ω : ℕ → 𝓧) : + N < restartTime σ (numRounds σ N ω + 1) ω := by + by_cases hJ : numRounds σ N ω + 1 ≤ N + · exact not_le.1 (Nat.findGreatest_is_greatest (P := fun j ↦ restartTime σ j ω ≤ N) + (Nat.lt_succ_self _) hJ) + · have hJN : numRounds σ N ω = N := le_antisymm (numRounds_le N ω) (by omega) + rw [hJN] + exact Nat.lt_of_lt_of_le (Nat.lt_succ_self N) (le_restartTime σ hσ1 (N + 1) ω) + +/-- **Wald's argument, pointwise.** The durations of the rounds that start within the first `N` +observations add up to more than `N`. -/ +private lemma add_one_le_sum_indicator (hσ1 : ∀ ω, 1 ≤ σ ω) (N : ℕ) (ω : ℕ → 𝓧) : + (N + 1 : ℝ) ≤ ∑ i ∈ Finset.range (N + 1), {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ)) ω := by + set J := numRounds σ N ω + have hJN : J ≤ N := numRounds_le N ω + have hJ : N + 1 ≤ restartTime σ (J + 1) ω := lt_restartTime_numRounds_succ hσ1 N ω + calc (N + 1 : ℝ) ≤ (restartTime σ (J + 1) ω : ℝ) := by exact_mod_cast hJ + _ = ∑ i ∈ Finset.range (J + 1), (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ) := by + rw [restartTime_eq_sum, Nat.cast_sum] + _ = ∑ i ∈ Finset.range (J + 1), {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ)) ω := by + refine Finset.sum_congr rfl fun i hi ↦ ?_ + rw [Set.indicator_of_mem] + exact (restartTime_le_iff_le_numRounds ((Nat.lt_succ_iff.1 (Finset.mem_range.1 hi)).trans + hJN) ω).2 (Nat.lt_succ_iff.1 (Finset.mem_range.1 hi)) + _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg + (Finset.range_subset_range.2 (Nat.succ_le_succ hJN)) + fun i _ _ ↦ Set.indicator_nonneg (fun _ _ ↦ Nat.cast_nonneg _) _ + +/-- **Wald's argument, in expectation.** Under an i.i.d. law, the observations after the first +`i` rounds are independent of the event that these rounds use at most `N` observations. -/ +private lemma integral_indicator_comp_shift_restartTime (hσ : DependsOnBefore σ σ) + (hσm : Measurable σ) (P : Measure 𝓧) [IsProbabilityMeasure P] {g : (ℕ → 𝓧) → ℝ} + (hg : Measurable g) {C : ℝ} (hgC : ∀ ω, |g ω| ≤ C) (i N : ℕ) : + ∫ ω, {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ g ((shift 𝓧)^[restartTime σ i ω] ω)) ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) = + (Measure.infinitePi (fun _ : ℕ ↦ P)).real {ω | restartTime σ i ω ≤ N} * + ∫ ω, g ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) := by + set μ := Measure.infinitePi (fun _ : ℕ ↦ P) + have hf (t : ℕ) : Measurable ({ω | restartTime σ i ω = t}.indicator (1 : (ℕ → 𝓧) → ℝ)) := + measurable_one.indicator (measurableSet_restartTime_eq hσm i t) + have hfi (t : ℕ) : Integrable ({ω | restartTime σ i ω = t}.indicator (1 : (ℕ → 𝓧) → ℝ)) μ := + (integrable_const (1 : ℝ)).indicator (measurableSet_restartTime_eq hσm i t) + have hfg (t : ℕ) : Integrable (fun ω ↦ + {ω | restartTime σ i ω = t}.indicator (1 : (ℕ → 𝓧) → ℝ) ω * g ((shift 𝓧)^[t] ω)) μ := by + refine Integrable.of_bound + ((hf t).mul (hg.comp (measurable_shift_iterate t))).aestronglyMeasurable C + (ae_of_all _ fun ω ↦ ?_) + rw [Real.norm_eq_abs, abs_mul] + calc |{ω | restartTime σ i ω = t}.indicator (1 : (ℕ → 𝓧) → ℝ) ω| * |g ((shift 𝓧)^[t] ω)| + _ ≤ 1 * C := by + refine mul_le_mul ?_ (hgC _) (abs_nonneg _) zero_le_one + by_cases h : restartTime σ i ω = t <;> simp [Set.indicator, h] + _ = C := one_mul C + have hsum (ω : ℕ → 𝓧) : {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ g ((shift 𝓧)^[restartTime σ i ω] ω)) ω = + ∑ t ∈ Finset.range (N + 1), + {ω | restartTime σ i ω = t}.indicator (1 : (ℕ → 𝓧) → ℝ) ω * g ((shift 𝓧)^[t] ω) := by + rw [← sum_indicator_eq_indicator_le] + refine Finset.sum_congr rfl fun t _ ↦ ?_ + rw [indicator_eq_mul_apply (restartTime σ i) t 1 (fun s ω ↦ g ((shift 𝓧)^[s] ω))] + simp only [Pi.one_apply, one_mul] + simp_rw [hsum] + rw [integral_finsetSum _ fun t _ ↦ hfg t] + calc ∑ t ∈ Finset.range (N + 1), ∫ ω, + {ω | restartTime σ i ω = t}.indicator (1 : (ℕ → 𝓧) → ℝ) ω * g ((shift 𝓧)^[t] ω) ∂μ + _ = ∑ t ∈ Finset.range (N + 1), + (∫ ω, {ω | restartTime σ i ω = t}.indicator (1 : (ℕ → 𝓧) → ℝ) ω ∂μ) * ∫ ω, g ω ∂μ := + Finset.sum_congr rfl fun t _ ↦ integral_mul_comp_shift_iterate P (hf t) + (dependsOn_indicator_one_restartTime_eq hσ i t) hg + _ = μ.real {ω | restartTime σ i ω ≤ N} * ∫ ω, g ω ∂μ := by + rw [← Finset.sum_mul, ← integral_finsetSum _ fun t _ ↦ hfi t] + simp_rw [sum_indicator_eq_indicator_le] + rw [integral_indicator_one (measurableSet_restartTime_le hσm i N)] + +end Restart + +/-! ### The truncated logarithm -/ + +/-- The logarithm truncated above at `c`, as a real number. -/ +noncomputable def truncLog (c : ℝ) (x : ℝ≥0∞) : ℝ := (min (ENNReal.log x) c).toReal + +/-- The truncated logarithm is measurable. -/ +lemma measurable_truncLog (c : ℝ) : Measurable (truncLog c) := + measurable_ereal_toReal.comp (ENNReal.measurable_log.min measurable_const) + +/-- The truncated logarithm of a positive finite number. -/ +lemma truncLog_of_ne {c : ℝ} {x : ℝ≥0∞} (h0 : x ≠ 0) (htop : x ≠ ∞) : + truncLog c x = min (Real.log x.toReal) c := by + rw [truncLog, ENNReal.log_pos_real h0 htop, ← EReal.coe_strictMono.monotone.map_min, + EReal.toReal_coe] + +/-- The truncated logarithm of `∞` is the truncation level. -/ +lemma truncLog_top (c : ℝ) : truncLog c ∞ = c := by simp [truncLog] + +/-- The truncated logarithm is at most the truncation level. -/ +lemma truncLog_le {c : ℝ} {x : ℝ≥0∞} (h0 : x ≠ 0) : truncLog c x ≤ c := by + by_cases htop : x = ∞ + · rw [htop, truncLog_top] + · rw [truncLog_of_ne h0 htop] + exact min_le_right _ _ + +/-- The truncated logarithm of `x ≥ δ` is at least `log δ`, if `log δ ≤ c`. -/ +lemma log_le_truncLog {c δ : ℝ} (hδ : 0 < δ) {x : ℝ≥0∞} (hx : ENNReal.ofReal δ ≤ x) + (hc : Real.log δ ≤ c) : Real.log δ ≤ truncLog c x := by + have h0 : x ≠ 0 := (lt_of_lt_of_le (ENNReal.ofReal_pos.2 hδ) hx).ne' + by_cases htop : x = ∞ + · rw [htop, truncLog_top] + exact hc + · rw [truncLog_of_ne h0 htop] + exact le_min (Real.log_le_log hδ ((ENNReal.ofReal_le_iff_le_toReal htop).1 hx)) hc + +/-- The truncated logarithm of `x ≥ δ` is bounded in absolute value, if `log δ ≤ c`. -/ +lemma abs_truncLog_le {c δ : ℝ} (hδ : 0 < δ) {x : ℝ≥0∞} (hx : ENNReal.ofReal δ ≤ x) + (hc : Real.log δ ≤ c) : |truncLog c x| ≤ max |Real.log δ| |c| := + abs_le_max_abs_abs (log_le_truncLog hδ hx hc) + (truncLog_le (lt_of_lt_of_le (ENNReal.ofReal_pos.2 hδ) hx).ne') + +/-- The exponential of the truncated logarithm of `x` is at most `x`. -/ +lemma ofReal_exp_truncLog_le {c : ℝ} {x : ℝ≥0∞} (h0 : x ≠ 0) : + ENNReal.ofReal (Real.exp (truncLog c x)) ≤ x := by + by_cases htop : x = ∞ + · rw [htop] + exact le_top + · rw [truncLog_of_ne h0 htop] + calc ENNReal.ofReal (Real.exp (min (Real.log x.toReal) c)) + _ ≤ ENNReal.ofReal (Real.exp (Real.log x.toReal)) := + ENNReal.ofReal_le_ofReal (Real.exp_le_exp.2 (min_le_left _ _)) + _ = x := by + rw [Real.exp_log (ENNReal.toReal_pos h0 htop), ENNReal.ofReal_toReal htop] + +/-- Mixing a payoff with a constant: `min (log x) c ≤ truncLog c ((1 - ε) x + ε) - log (1 - ε)`. -/ +lemma min_log_le_truncLog_sub {ε : ℝ} (hε0 : 0 < ε) (hε1 : ε < 1) (c : ℝ) (x : ℝ≥0∞) : + min (ENNReal.log x) c ≤ + ((truncLog c (ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε) - Real.log (1 - ε) : ℝ) : + EReal) := by + have hlog : Real.log (1 - ε) ≤ 0 := Real.log_nonpos (by linarith) (by linarith) + by_cases h0 : x = 0 + · simp [h0] + by_cases htop : x = ∞ + · have : ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε = ∞ := by + rw [htop, ENNReal.mul_top (ENNReal.ofReal_pos.2 (by linarith)).ne', top_add] + rw [this, truncLog_top] + exact (min_le_right _ _).trans (EReal.coe_le_coe_iff.2 (by linarith)) + have hε' : ENNReal.ofReal ε ≠ 0 := (ENNReal.ofReal_pos.2 hε0).ne' + have hV0 : ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε ≠ 0 := by simp [hε'] + have hVtop : ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε ≠ ∞ := + ENNReal.add_ne_top.2 ⟨ENNReal.mul_ne_top ENNReal.ofReal_ne_top htop, ENNReal.ofReal_ne_top⟩ + have hVreal : (ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε).toReal = + (1 - ε) * x.toReal + ε := by + rw [ENNReal.toReal_add (ENNReal.mul_ne_top ENNReal.ofReal_ne_top htop) ENNReal.ofReal_ne_top, + ENNReal.toReal_mul, ENNReal.toReal_ofReal (by linarith), ENNReal.toReal_ofReal hε0.le] + rw [truncLog_of_ne hV0 hVtop, hVreal, ENNReal.log_pos_real h0 htop, + ← EReal.coe_strictMono.monotone.map_min, EReal.coe_le_coe_iff] + have hx : 0 < x.toReal := ENNReal.toReal_pos h0 htop + have hL : Real.log (1 - ε) + Real.log x.toReal ≤ Real.log ((1 - ε) * x.toReal + ε) := by + rw [← Real.log_mul (by linarith) hx.ne'] + exact Real.log_le_log (mul_pos (by linarith) hx) (by linarith) + rw [← min_sub_sub_right] + exact le_min ((min_le_left _ _).trans (by linarith)) ((min_le_right _ _).trans (by linarith)) + +/-! ### The Wald inequality for a round -/ + +section Wald + +variable {σ : (ℕ → 𝓧) → ℕ} {V : (ℕ → 𝓧) → ℝ≥0∞} + +/-- The logarithm of the mixture of restarted rounds is at least the logarithm of the weight of +the completed rounds plus their truncated log-payoffs, hence at least the sum of the truncated +log-payoffs of the rounds that start within the first `N` observations, up to `c` for the last +one and to the logarithm of the weights. -/ +private lemma log_restartMixture_ge {δ : ℝ} (hδ : 0 < δ) (hVδ : ∀ ω, ENNReal.ofReal δ ≤ V ω) + (c : ℝ) {r : ℝ} (hr0 : 0 < r) (hr1 : r < 1) (N : ℕ) (ω : ℕ → 𝓧) : + ((Real.log (1 - r) + N * Real.log r - c + ∑ i ∈ Finset.range (N + 1), + {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω : ℝ) : EReal) ≤ + ENNReal.log (restartMixture σ V r N ω) := by + set J := numRounds σ N ω + set Y : ℕ → ℝ := fun i ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω)) + have hV0 (ω : ℕ → 𝓧) : V ω ≠ 0 := (lt_of_lt_of_le (ENNReal.ofReal_pos.2 hδ) (hVδ ω)).ne' + have hJN : J ≤ N := numRounds_le N ω + have hr' : 0 < 1 - r := by linarith + -- the mixture is at least its term of index `J` + have h1 : ENNReal.ofReal ((1 - r) * r ^ J * Real.exp (∑ i ∈ Finset.range J, Y i)) ≤ + restartMixture σ V r N ω := by + calc ENNReal.ofReal ((1 - r) * r ^ J * Real.exp (∑ i ∈ Finset.range J, Y i)) + _ = ENNReal.ofReal ((1 - r) * r ^ J) * + ∏ i ∈ Finset.range J, ENNReal.ofReal (Real.exp (Y i)) := by + rw [ENNReal.ofReal_mul (mul_nonneg hr'.le (pow_nonneg hr0.le J)), Real.exp_sum, + ENNReal.ofReal_prod_of_nonneg fun i _ ↦ (Real.exp_pos _).le] + _ ≤ ENNReal.ofReal ((1 - r) * r ^ J) * restartPayoff σ V J ω := by + rw [restartPayoff_eq_prod] + gcongr with i hi + exact ofReal_exp_truncLog_le (hV0 _) + _ = ENNReal.ofReal ((1 - r) * r ^ J) * + {ω | restartTime σ J ω ≤ N}.indicator (restartPayoff σ V J) ω := by + rw [Set.indicator_of_mem (restartTime_numRounds_le N ω)] + _ ≤ restartMixture σ V r N ω := + Finset.single_le_sum (f := fun j ↦ ENNReal.ofReal ((1 - r) * r ^ j) * + {ω | restartTime σ j ω ≤ N}.indicator (restartPayoff σ V j) ω) + (fun _ _ ↦ bot_le) (Finset.mem_range.2 (Nat.lt_succ_of_le hJN)) + -- the logarithm of this term + have hpos : 0 < (1 - r) * r ^ J * Real.exp (∑ i ∈ Finset.range J, Y i) := by + have := pow_pos hr0 J + have := Real.exp_pos (∑ i ∈ Finset.range J, Y i) + positivity + have h2 : Real.log ((1 - r) * r ^ J * Real.exp (∑ i ∈ Finset.range J, Y i)) = + Real.log (1 - r) + J * Real.log r + ∑ i ∈ Finset.range J, Y i := by + rw [Real.log_mul (mul_pos hr' (pow_pos hr0 J)).ne' (Real.exp_pos _).ne', + Real.log_mul hr'.ne' (pow_pos hr0 J).ne', Real.log_pow, Real.log_exp] + -- the sum over the rounds that start within the first `N` observations + have h3 : ∑ i ∈ Finset.range (N + 1), {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω = + ∑ i ∈ Finset.range (J + 1), Y i := by + symm + refine Finset.sum_subset (Finset.range_subset_range.2 (Nat.succ_le_succ hJN)) + (fun i hi hiJ ↦ ?_) |>.symm.trans (Finset.sum_congr rfl fun i hi ↦ ?_) |>.symm + · rw [Set.indicator_of_notMem] + rw [Set.mem_ofPred_eq, restartTime_le_iff_le_numRounds + (Nat.lt_succ_iff.1 (Finset.mem_range.1 hi))] + exact fun h ↦ hiJ (Finset.mem_range.2 (Nat.lt_succ_of_le h)) + · rw [Set.indicator_of_mem] + exact (restartTime_le_iff_le_numRounds + ((Nat.lt_succ_iff.1 (Finset.mem_range.1 hi)).trans hJN) ω).2 + (Nat.lt_succ_iff.1 (Finset.mem_range.1 hi)) + have h4 : Y J ≤ c := truncLog_le (hV0 _) + have h5 : (N : ℝ) * Real.log r ≤ J * Real.log r := + mul_le_mul_of_nonpos_right (by exact_mod_cast hJN) (Real.log_nonpos hr0.le hr1.le) + calc ((Real.log (1 - r) + N * Real.log r - c + ∑ i ∈ Finset.range (N + 1), + {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω : ℝ) : EReal) + _ ≤ ((Real.log ((1 - r) * r ^ J * Real.exp (∑ i ∈ Finset.range J, Y i)) : ℝ) : EReal) := by + rw [h2, h3, Finset.sum_range_succ] + exact EReal.coe_le_coe_iff.2 (by linarith) + _ = ENNReal.log (ENNReal.ofReal ((1 - r) * r ^ J * Real.exp (∑ i ∈ Finset.range J, Y i))) := + (ENNReal.log_ofReal_of_pos hpos).symm + _ ≤ ENNReal.log (restartMixture σ V r N ω) := ENNReal.log_le_log h1 + +/-- The limit argument of the Wald inequality: if for every `r ∈ (0, 1)` and `N ≥ 1` some +`s ≥ (N + 1) / m` satisfies `log (1 - r) + N log r - c + A s ≤ N d`, then `A ≤ d m`. -/ +private lemma le_mul_of_forall_restart {A c d m : ℝ} (hm : 0 < m) (hd : 0 ≤ d) + (h : ∀ r : ℝ, 0 < r → r < 1 → ∀ N : ℕ, 1 ≤ N → ∃ s : ℝ, + (N + 1 : ℝ) ≤ m * s ∧ Real.log (1 - r) + N * Real.log r - c + A * s ≤ N * d) : + A ≤ d * m := by + by_contra hlt + rw [not_le] at hlt + have hA : 0 < A := lt_of_le_of_lt (mul_nonneg hd hm.le) hlt + set ε := A / m - d with hε + have hε0 : 0 < ε := by + rw [hε, sub_pos, lt_div_iff₀ hm] + linarith + set r := Real.exp (-(ε / 2)) with hr + have hr0 : 0 < r := Real.exp_pos _ + have hr1 : r < 1 := Real.exp_lt_one_iff.2 (by linarith) + have hlogr : Real.log r = -(ε / 2) := Real.log_exp _ + obtain ⟨N, hN⟩ := exists_nat_gt ((c - Real.log (1 - r)) * 2 / ε) + obtain ⟨s, hs1, hs2⟩ := h r hr0 hr1 (N + 1) (by omega) + have hAs : A * (((N + 1 : ℕ) : ℝ) + 1) / m ≤ A * s := by + rw [mul_div_assoc] + exact mul_le_mul_of_nonneg_left ((div_le_iff₀ hm).2 (by linarith [mul_comm m s])) hA.le + have key : A * (((N + 1 : ℕ) : ℝ) + 1) / m = (((N + 1 : ℕ) : ℝ) + 1) * (d + ε) := by + rw [hε] + field_simp + ring + rw [key] at hAs + rw [hlogr] at hs2 + have hN' : (c - Real.log (1 - r)) * 2 < N * ε := (div_lt_iff₀ hε0).1 hN + push_cast at hs2 hAs + nlinarith + +/-- **Wald's argument.** Under an i.i.d. law, the rounds that start within the first `N` +observations number at least `(N + 1) / 𝔼[σ]` in expectation. -/ +private lemma add_one_le_integral_mul_sum_measureReal (hσ : DependsOnBefore σ σ) + (hσm : Measurable σ) (hσ1 : ∀ ω, 1 ≤ σ ω) {K : ℕ} (hσK : ∀ ω, σ ω ≤ K) (P : Measure 𝓧) + [IsProbabilityMeasure P] (N : ℕ) : + (N + 1 : ℝ) ≤ (∫ ω, (σ ω : ℝ) ∂Measure.infinitePi (fun _ : ℕ ↦ P)) * + ∑ i ∈ Finset.range (N + 1), + (Measure.infinitePi (fun _ : ℕ ↦ P)).real {ω | restartTime σ i ω ≤ N} := by + set μ := Measure.infinitePi (fun _ : ℕ ↦ P) + set m := ∫ ω, (σ ω : ℝ) ∂μ + have hσm' : Measurable fun ω ↦ (σ ω : ℝ) := measurable_from_top.comp hσm + have hσC (ω : ℕ → 𝓧) : |(σ ω : ℝ)| ≤ K := by + rw [abs_of_nonneg (Nat.cast_nonneg _)] + exact_mod_cast hσK ω + have hT (i : ℕ) : Measurable (restartTime σ i) := measurable_restartTime hσm i + have hgm (i : ℕ) : Measurable fun ω ↦ {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ)) ω := + (measurable_comp_shift_iterate hσm' (hT i)).indicator (hT i measurableSet_Iic) + have hgi (i : ℕ) : Integrable (fun ω ↦ {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ)) ω) μ := by + refine Integrable.of_bound (hgm i).aestronglyMeasurable K (ae_of_all _ fun ω ↦ ?_) + rw [Real.norm_eq_abs] + by_cases h : restartTime σ i ω ≤ N + · rw [Set.indicator_of_mem h] + exact hσC _ + · rw [Set.indicator_of_notMem h, abs_zero] + exact Nat.cast_nonneg _ + calc (N + 1 : ℝ) = ∫ _, (N + 1 : ℝ) ∂μ := by simp + _ ≤ ∫ ω, ∑ i ∈ Finset.range (N + 1), {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ)) ω ∂μ := + integral_mono (integrable_const _) (integrable_finsetSum _ fun i _ ↦ hgi i) + fun ω ↦ add_one_le_sum_indicator hσ1 N ω + _ = ∑ i ∈ Finset.range (N + 1), μ.real {ω | restartTime σ i ω ≤ N} * m := by + rw [integral_finsetSum _ fun i _ ↦ hgi i] + exact Finset.sum_congr rfl fun i _ ↦ + integral_indicator_comp_shift_restartTime hσ hσm P hσm' hσC i N + _ = m * ∑ i ∈ Finset.range (N + 1), μ.real {ω | restartTime σ i ω ≤ N} := by + rw [Finset.mul_sum] + exact Finset.sum_congr rfl fun i _ ↦ mul_comm _ _ + +/-- The logarithmic bound of the Wald inequality for a round: the expected logarithm of the +mixture of the rounds completed within the first `N` observations is at most `N d`, and at least +the logarithm of the weights plus the expected truncated log-payoffs of the rounds that start +within the first `N` observations. -/ +private lemma add_integral_truncLog_mul_sum_measureReal_le (Q₁ : Measure 𝓧) + [IsProbabilityMeasure Q₁] (hS₁ : ∀ P ∈ S₁, IsProbabilityMeasure P) + (hσ : DependsOnBefore σ σ) (hV : DependsOnBefore σ V) (hσm : Measurable σ) + (hVm : Measurable V) + (h_null : ∀ P ∈ S₁, ∀ n : ℕ, + ∫⁻ ω, {ω | σ ω ≤ n}.indicator V ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) ≤ 1) + {δ : ℝ} (hδ : 0 < δ) (hVδ : ∀ ω, ENNReal.ofReal δ ≤ V ω) {c : ℝ} (hc : Real.log δ ≤ c) + (hd : bipolarRate Q₁ S₁ ≠ ⊤) {r : ℝ} (hr0 : 0 < r) (hr1 : r < 1) {N : ℕ} (hN : 1 ≤ N) : + Real.log (1 - r) + N * Real.log r - c + + (∫ ω, truncLog c (V ω) ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁)) * + ∑ i ∈ Finset.range (N + 1), + (Measure.infinitePi (fun _ : ℕ ↦ Q₁)).real {ω | restartTime σ i ω ≤ N} ≤ + N * (bipolarRate Q₁ S₁).toReal := by + set μ := Measure.infinitePi (fun _ : ℕ ↦ Q₁) + set A := ∫ ω, truncLog c (V ω) ∂μ + -- the truncated log-payoffs are bounded + set C := max |Real.log δ| |c| + have hYm : Measurable fun ω ↦ truncLog c (V ω) := (measurable_truncLog c).comp hVm + have hT (i : ℕ) : Measurable (restartTime σ i) := measurable_restartTime hσm i + have hfm (i : ℕ) : Measurable fun ω ↦ {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω := + (measurable_comp_shift_iterate hYm (hT i)).indicator (hT i measurableSet_Iic) + have hfC (i : ℕ) (ω : ℕ → 𝓧) : |{ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω| ≤ C := by + by_cases h : restartTime σ i ω ≤ N + · rw [Set.indicator_of_mem h] + exact abs_truncLog_le hδ (hVδ _) hc + · rw [Set.indicator_of_notMem h, abs_zero] + exact (abs_nonneg _).trans (le_max_left _ _) + have hfi (i : ℕ) : Integrable (fun ω ↦ {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω) μ := + Integrable.of_bound (hfm i).aestronglyMeasurable C + (ae_of_all _ fun ω ↦ (Real.norm_eq_abs _).trans_le (hfC i ω)) + set B := Real.log (1 - r) + N * Real.log r - c + have hsum : Integrable (fun ω ↦ ∑ i ∈ Finset.range (N + 1), + {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω) μ := + integrable_finsetSum _ fun i _ ↦ hfi i + have hint : Integrable (fun ω ↦ B + ∑ i ∈ Finset.range (N + 1), + {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω) μ := + (integrable_const B).add hsum + have hval : ∫ ω, B + ∑ i ∈ Finset.range (N + 1), {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω ∂μ = + B + A * ∑ i ∈ Finset.range (N + 1), μ.real {ω | restartTime σ i ω ≤ N} := by + rw [integral_add (integrable_const B) hsum, integral_finsetSum _ fun i _ ↦ hfi i, + Finset.mul_sum] + simp only [integral_const, probReal_univ, one_smul] + congr 1 + exact Finset.sum_congr rfl fun i _ ↦ (integral_indicator_comp_shift_restartTime hσ hσm Q₁ + hYm (fun ω ↦ abs_truncLog_le hδ (hVδ ω) hc) i N).trans (mul_comm _ _) + have hle : ((B + A * ∑ i ∈ Finset.range (N + 1), μ.real {ω | restartTime σ i ω ≤ N} : ℝ) : + EReal) ≤ (N : EReal) * bipolarRate Q₁ S₁ := by + rw [← hval, ← eintegral_eq_integral hint] + calc ∫ᵉ ω, ((B + ∑ i ∈ Finset.range (N + 1), {ω | restartTime σ i ω ≤ N}.indicator + (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω : ℝ) : EReal) ∂μ + _ ≤ ∫ᵉ ω, ENNReal.log (restartMixture σ V r N ω) ∂μ := + eintegral_mono fun ω ↦ log_restartMixture_ge hδ hVδ c hr0 hr1 N ω + _ ≤ maxLogGrowth Q₁ S₁ N := + eintegral_log_le_maxLogGrowth_of_dependsOn Q₁ hS₁ (measurable_restartMixture hσm hVm r N) + (dependsOn_restartMixture hσ hV r N) fun P hP ↦ by + have := hS₁ P hP + exact lintegral_restartMixture_le_one hσ hV hσm hVm P (h_null P hP) hr0.le hr1.le N + _ ≤ N * bipolarRate Q₁ S₁ := maxLogGrowth_le_mul_bipolarRate Q₁ S₁ (by omega) + rw [← coe_toReal_bipolarRate hd, ← EReal.coe_natCast, ← EReal.coe_mul, + EReal.coe_le_coe_iff] at hle + exact hle + +/-- **The Wald inequality for a round.** Let `σ ≥ 1` be the bounded duration and `V ≥ δ > 0` the +payoff of a round, both determined by the observations of the round. If the payoff has +expectation at most `1` on each event `{σ ≤ n}` under the i.i.d. laws of the members of `S₁`, +then under the i.i.d. law of `Q₁` the expected logarithm of the payoff, truncated above at `c`, is +at most the bipolar rate times the expected duration. -/ +lemma integral_truncLog_le_bipolarRate_mul (Q₁ : Measure 𝓧) [IsProbabilityMeasure Q₁] + (hS₁ : ∀ P ∈ S₁, IsProbabilityMeasure P) (hσ : DependsOnBefore σ σ) + (hV : DependsOnBefore σ V) (hσm : Measurable σ) (hVm : Measurable V) (hσ1 : ∀ ω, 1 ≤ σ ω) + {K : ℕ} (hσK : ∀ ω, σ ω ≤ K) + (h_null : ∀ P ∈ S₁, ∀ n : ℕ, + ∫⁻ ω, {ω | σ ω ≤ n}.indicator V ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) ≤ 1) + {δ : ℝ} (hδ : 0 < δ) (hVδ : ∀ ω, ENNReal.ofReal δ ≤ V ω) {c : ℝ} (hc : Real.log δ ≤ c) + (hd : bipolarRate Q₁ S₁ ≠ ⊤) : + ∫ ω, truncLog c (V ω) ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁) ≤ + (bipolarRate Q₁ S₁).toReal * ∫ ω, (σ ω : ℝ) ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁) := by + set μ := Measure.infinitePi (fun _ : ℕ ↦ Q₁) + set m := ∫ ω, (σ ω : ℝ) ∂μ + have hd0 := bipolarRate_nonneg Q₁ S₁ + have hσm' : Measurable fun ω ↦ (σ ω : ℝ) := measurable_from_top.comp hσm + have hσC (ω : ℕ → 𝓧) : |(σ ω : ℝ)| ≤ K := by + rw [abs_of_nonneg (Nat.cast_nonneg _)] + exact_mod_cast hσK ω + have hm1 : 1 ≤ m := by + calc (1 : ℝ) = ∫ _, (1 : ℝ) ∂μ := by simp + _ ≤ m := integral_mono (integrable_const _) + (Integrable.of_bound hσm'.aestronglyMeasurable K (ae_of_all _ fun ω ↦ hσC ω)) + fun ω ↦ by exact_mod_cast hσ1 ω + refine le_mul_of_forall_restart (c := c) (by linarith) (EReal.toReal_nonneg hd0) + fun r hr0 hr1 N hN ↦ ⟨_, add_one_le_integral_mul_sum_measureReal hσ hσm hσ1 hσK Q₁ N, + add_integral_truncLog_mul_sum_measureReal_le Q₁ hS₁ hσ hV hσm hVm h_null hδ hVδ hc hd hr0 + hr1 hN⟩ + +end Wald + +end ProbabilityTheory diff --git a/LMLExplore/EValues/BipolarRate/StoppingTime.lean b/LMLExplore/EValues/BipolarRate/StoppingTime.lean index 6292ee6d..6dcd4bd6 100644 --- a/LMLExplore/EValues/BipolarRate/StoppingTime.lean +++ b/LMLExplore/EValues/BipolarRate/StoppingTime.lean @@ -8,12 +8,11 @@ module public import LMLExplore.EValues.BipolarRate.Basic public import LMLExplore.EValues.EProcess public import Mathlib.Probability.ProductMeasure -import LMLExplore.EValues.BipolarRate.EProcess +import LMLExplore.EValues.BipolarRate.Round +import LMLExplore.MeasureTheory.Integral.EReal import LMLExplore.Probability.Process.Stopping import LMLExplore.Probability.Process.StoppedValue -import Mathlib.Probability.Independence.Integration import Statlib.ForMathlib.MeasureTheory.Integral.EReal.Bochner -import TauCeti.Probability.Process.PathLaw.Shift /-! # Expected stopping times are governed by the bipolar rate @@ -24,21 +23,22 @@ Let `S₁` be a set of probability measures on `𝓧` (the null) and `Q₁` a pr observations have been made at a time `τ`. Write `d = bipolarRate Q₁ S₁` and `Q` for the i.i.d. law of `Q₁`. -The **Wald inequality** at the bipolar rate: for every e-process `E` for the i.i.d. null and every -stopping time `τ` with values in `ℕ`, `𝔼_Q[log E_τ] ≤ 𝔼_Q[τ + 1] * d`, in `EReal`, with -Statlib's extended integral on the left. Nothing is assumed of `S₁` beyond its members being -probability measures, and nothing of `Q₁`. The expectation of `τ` may be infinite, with -`∞ * 0 = 0`: if `d = 0`, the e-process has a nonpositive expected logarithm at every stopping +The **Wald inequality** at the bipolar rate [EVR26, Note 01]: for every e-process `E` for the +i.i.d. null and every stopping time `τ` with values in `ℕ`, `𝔼_Q[log E_τ] ≤ 𝔼_Q[τ + 1] * d`, in +`EReal`, with Statlib's extended integral on the left. Nothing is assumed of `S₁` beyond its +members being probability measures, and nothing of `Q₁`. The expectation of `τ` may be infinite, +with `∞ * 0 = 0`: if `d = 0`, the e-process has a nonpositive expected logarithm at every stopping time. Its case `E n = α⁻¹ * 𝟙{τ ≤ n}` (mixed with a constant, so that its logarithm is finite) is the -**lower bound on expected stopping times**: a sequential test of level `α`, that is, a stopping -time `τ` with values in `WithTop ℕ` such that `P^ℕ (τ < ∞) ≤ α` for every `P ∈ S₁`, makes at least -`log (1/α) / d` observations in expectation under `Q`. If `d = 0`, every test of a level `α < 1` -has an infinite expected number of observations. Since `d` is at most the smallest relative -entropy `KL_inf(Q₁, S₁)` from `Q₁` to the null (`ProbabilityTheory.bipolarRate_le_iInf_klDiv`), -this contains the lower bound with `KL_inf(Q₁, S₁)` in place of `d`, the form of the bounds of -[ARR26]; the bipolar rate can be smaller [RR26, Proposition 5.4]. +**lower bound on expected stopping times** [EVR26, Note 01]: a sequential test of level `α`, that +is, a stopping time `τ` with values in `WithTop ℕ` such that `P^ℕ (τ < ∞) ≤ α` for every +`P ∈ S₁`, makes at least `log (1/α) / d` observations in expectation under `Q`. If `d = 0`, +every test of a level `α < 1` has an infinite expected number of observations. Since `d` is at +most the smallest relative entropy `KL_inf(Q₁, S₁)` from `Q₁` to the null +(`ProbabilityTheory.bipolarRate_le_iInf_klDiv`), this contains the lower bound with +`KL_inf(Q₁, S₁)` in place of `d`, the form of the bounds of [ARR26]; the bipolar rate can be +smaller [RR26, Proposition 5.4]. ## Main statements @@ -49,913 +49,50 @@ this contains the lower bound with `KL_inf(Q₁, S₁)` in place of `d`, the for ## Implementation notes -The proof restarts the round, the e-process stopped at `τ`, on the fresh observations each time -it ends, and bets on the number of completed rounds with a geometric mixture. Within the first -`N` observations, the mixture over the rounds completed so far of the products of their payoffs -is an `N`-sample e-variable: under the i.i.d. law of a member of the null, the first `t` -observations are independent of the later ones. Its expected logarithm under `Q` is at most -`maxLogGrowth Q₁ S₁ N ≤ N * d`. A Wald argument shows that the rounds that start within the first -`N` observations use at least `N + 1` observations, hence that `(N + 1) / 𝔼_Q[τ + 1]` of them -start in expectation; letting `N → ∞` bounds the expected truncated logarithm of the payoff of a -round by `𝔼_Q[τ + 1] * d`. The payoff is first mixed with a constant `ε`, so that its logarithm -is bounded below, and the stopping time is first bounded by `k`; the truncation, `ε` and `k` are -removed at the end. The proof uses neither the law of large numbers nor the strong Markov -property: only the independence of the first `t` observations from the later ones, summed over -the values `t` of the restart times. +The round of the Wald inequality for a round +(`ProbabilityTheory.integral_truncLog_le_bipolarRate_mul`, in +`LMLExplore.EValues.BipolarRate.Round`) is the e-process stopped at `min τ k`, mixed with a +constant `ε` so that its logarithm is bounded below: `(1 - ε) E_{min τ k} + ε`. The bound for it +holds for the logarithm truncated above at a level `c`; then `k → ∞` (dominated convergence), the +truncation level `c → ∞` (monotone convergence for the extended integral, +`MeasureTheory.eintegral_le_of_forall_min_le`) and `ε → 0`. The lower bound on expected stopping +times applies the Wald inequality to the e-process `ε + (1 - ε) α⁻¹ 𝟙{τ ≤ n}` at the stopping times +`min τ k`. + +The proofs are adapted from `EValuesResearch/Results/BipolarRate.lean` and +`EValuesResearch/Results/BipolarRateAux.lean` (commit `dd4072f`) in the paper project +`RemyDegenne/evalues_research`, which formalizes [EVR26, Note 01]. They are specialized here to +stopping times with values in `ℕ`. ## References * [ARR26] S. Agrawal, A. Ram and A. Ramdas, *On stopping times of power-one sequential tests: tight lower and upper bounds*, arXiv:2504.19952v2. * [RR26] A. Ram and A. Ramdas, *The optimal betting wealth growth rate*, arXiv:2604.25280v1. +* [EVR26] the research notes of the paper project `RemyDegenne/evalues_research`: Note 01, + `results/01-bipolar-rate.md`. -/ public section open MeasureTheory Filter -open TauCeti.Probability (shift shift_iterate_apply shift_iterate_eq_reindex - measurable_shift_iterate) open scoped ENNReal Topology namespace ProbabilityTheory variable {𝓧 : Type*} {m𝓧 : MeasurableSpace 𝓧} {S₁ : Set (Measure 𝓧)} -/-! ### The observations after the first ones -/ +/-! ### Removing the mixing constant -/ -/-- The shift by `t` observations preserves the i.i.d. law. -/ -private lemma measurePreserving_shift_iterate (P : Measure 𝓧) [IsProbabilityMeasure P] (t : ℕ) : - MeasurePreserving ((shift 𝓧)^[t]) (Measure.infinitePi fun _ : ℕ ↦ P) - (Measure.infinitePi fun _ : ℕ ↦ P) := by - refine ⟨measurable_shift_iterate t, ?_⟩ - rw [shift_iterate_eq_reindex] - exact Measure.map_infinitePi_infinitePi_of_inj (add_left_injective t) - -/-- Under an i.i.d. law, the first `t` observations are independent of the observations after -them. -/ -private lemma indepFun_initSeg_shift_iterate (P : Measure 𝓧) [IsProbabilityMeasure P] (t : ℕ) : - IndepFun (initSeg t) ((shift 𝓧)^[t]) (Measure.infinitePi fun _ : ℕ ↦ P) := by - have h := (iIndepFun_infinitePi (P := fun _ : ℕ ↦ P) (X := fun _ x ↦ x) - (fun _ ↦ measurable_id)).indepFun_set (Set.Iio t) (Set.Ici t) - (Set.disjoint_left.2 fun i (hi : i < t) (hi' : t ≤ i) ↦ (not_lt.2 hi') hi) - (fun i ↦ measurable_pi_apply i) - rw [shift_iterate_eq_reindex, initSeg_def] - exact h.comp (φ := fun (y : Set.Iio t → 𝓧) (i : Fin t) ↦ y ⟨i, i.2⟩) - (ψ := fun (y : Set.Ici t → 𝓧) (i : ℕ) ↦ y ⟨i + t, Nat.le_add_left t i⟩) - (by fun_prop) (by fun_prop) - -/-- Under an i.i.d. law, a function of the first `t` observations is independent of a function of -the observations after them. -/ -private lemma lintegral_mul_comp_shift_iterate (P : Measure 𝓧) [IsProbabilityMeasure P] - {f g : (ℕ → 𝓧) → ℝ≥0∞} {t : ℕ} (hf : Measurable f) (hft : DependsOn f (Set.Iio t)) - (hg : Measurable g) : - ∫⁻ ω, f ω * g ((shift 𝓧)^[t] ω) ∂Measure.infinitePi (fun _ : ℕ ↦ P) = - (∫⁻ ω, f ω ∂Measure.infinitePi (fun _ : ℕ ↦ P)) * - ∫⁻ ω, g ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) := by - have := nonempty_of_isProbabilityMeasure P - obtain ⟨F, hF, rfl⟩ := exists_measurable_eq_comp_initSeg hf hft - rw [← (measurePreserving_shift_iterate P t).lintegral_comp hg] - exact lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun (hF.comp (measurable_initSeg t)) - (hg.comp (measurable_shift_iterate t)) ((indepFun_initSeg_shift_iterate P t).comp hF hg) - -/-- Under an i.i.d. law, a real function of the first `t` observations is independent of a real -function of the observations after them. -/ -private lemma integral_mul_comp_shift_iterate (P : Measure 𝓧) [IsProbabilityMeasure P] - {f g : (ℕ → 𝓧) → ℝ} {t : ℕ} (hf : Measurable f) (hft : DependsOn f (Set.Iio t)) - (hg : Measurable g) : - ∫ ω, f ω * g ((shift 𝓧)^[t] ω) ∂Measure.infinitePi (fun _ : ℕ ↦ P) = - (∫ ω, f ω ∂Measure.infinitePi (fun _ : ℕ ↦ P)) * - ∫ ω, g ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) := by - have := nonempty_of_isProbabilityMeasure P - obtain ⟨F, hF, rfl⟩ := exists_measurable_eq_comp_initSeg hf hft - have hmap : ∫ ω, g ((shift 𝓧)^[t] ω) ∂Measure.infinitePi (fun _ : ℕ ↦ P) = - ∫ ω, g ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) := by - rw [← integral_map (measurable_shift_iterate t).aemeasurable - (by rw [(measurePreserving_shift_iterate P t).map_eq]; exact hg.aestronglyMeasurable), - (measurePreserving_shift_iterate P t).map_eq] - rw [← hmap] - exact ((indepFun_initSeg_shift_iterate P t).comp hF hg).integral_fun_mul_eq_mul_integral - (hF.comp (measurable_initSeg t)).aestronglyMeasurable - (hg.comp (measurable_shift_iterate t)).aestronglyMeasurable - -/-! ### Stopping times of the observations -/ - -section StoppingTime - -variable {τ : (ℕ → 𝓧) → ℕ} - -/-- A stopping time of the observations with values in `ℕ` is measurable. -/ -private lemma measurable_of_isStoppingTime_nat - (hτ : IsStoppingTime (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) fun ω ↦ (τ ω : WithTop ℕ)) : - Measurable τ := by - convert (measurable_of_countable (WithTop.untopD 0)).comp hτ.measurable' using 1 - exact funext fun ω ↦ (WithTop.untopD_coe 0 (τ ω)).symm - -/-- A stopping time of the observations with values in `ℕ` is determined by the observations up -to it. -/ -private lemma eq_of_isStoppingTime_of_forall_le - (hτ : IsStoppingTime (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) fun ω ↦ (τ ω : WithTop ℕ)) - {ω ω' : ℕ → 𝓧} (h : ∀ i ≤ τ ω, ω i = ω' i) : τ ω' = τ ω := by - have hm : MeasurableSet[Filtration.piLE (τ ω)] {ω' | τ ω' = τ ω} := by - simpa using hτ.measurableSet_eq (τ ω) - have hd : DependsOn ({ω' | τ ω' = τ ω}.indicator fun _ ↦ (1 : ℕ)) (Set.Iic (τ ω)) := - (measurable_const.indicator hm).dependsOn_of_piLE - have h1 := hd fun i hi ↦ h i hi - by_contra hne - simp [Set.indicator, hne] at h1 - -/-- The minimum of a stopping time with values in `ℕ` and a constant is a stopping time. -/ -private lemma isStoppingTime_min_nat - (hτ : IsStoppingTime (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) fun ω ↦ (τ ω : WithTop ℕ)) - (k : ℕ) : - IsStoppingTime (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) - fun ω ↦ ((min (τ ω) k : ℕ) : WithTop ℕ) := by - have h : (fun ω ↦ ((min (τ ω) k : ℕ) : WithTop ℕ)) = fun ω ↦ min (τ ω : WithTop ℕ) k := - funext fun ω ↦ WithTop.coe_min _ _ - rw [h] - exact hτ.min_natCast k - -end StoppingTime - -/-! ### Restarting a round on the fresh observations - -A round is a pair of a duration `σ : (ℕ → 𝓧) → ℕ`, the number of observations that it uses, and a -payoff `V : (ℕ → 𝓧) → ℝ≥0∞`, both determined by the observations of the round. Restarting the -round on the fresh observations at its end gives the restart times `restartTime σ j` and the -products `restartPayoff σ V j` of the payoffs of the first `j` rounds. -/ - -/-- `f` is determined by the first `σ` observations: if `σ ω ≤ u` and `ω'` agrees with `ω` on the -first `u` observations, then `f ω' = f ω`. For `f = σ`, this says that `σ` is a stopping time -counted in observations. -/ -private def DependsOnBefore {β : Type*} (σ : (ℕ → 𝓧) → ℕ) (f : (ℕ → 𝓧) → β) : Prop := - ∀ ⦃u : ℕ⦄ ⦃ω ω' : ℕ → 𝓧⦄, (∀ i < u, ω i = ω' i) → σ ω ≤ u → f ω' = f ω - -section Restart - -variable (σ : (ℕ → 𝓧) → ℕ) (V : (ℕ → 𝓧) → ℝ≥0∞) - -/-- The number of observations used by the first `j` rounds, when a round that uses `σ ω` -observations is restarted on the fresh observations at its end. -/ -private def restartTime : ℕ → (ℕ → 𝓧) → ℕ - | 0 => fun _ ↦ 0 - | j + 1 => fun ω ↦ restartTime j ω + σ ((shift 𝓧)^[restartTime j ω] ω) - -/-- The product of the payoffs `V` of the first `j` restarted rounds. -/ -private noncomputable def restartPayoff : ℕ → (ℕ → 𝓧) → ℝ≥0∞ - | 0 => fun _ ↦ 1 - | j + 1 => fun ω ↦ restartPayoff j ω * V ((shift 𝓧)^[restartTime σ j ω] ω) - -/-- The round after the first `j` ones is played on the observations after them. -/ -private lemma restartTime_succ (j : ℕ) (ω : ℕ → 𝓧) : - restartTime σ (j + 1) ω = restartTime σ j ω + σ ((shift 𝓧)^[restartTime σ j ω] ω) := - rfl - -/-- The payoff of `j + 1` rounds is that of the first `j` times that of the next one. -/ -private lemma restartPayoff_succ (j : ℕ) (ω : ℕ → 𝓧) : - restartPayoff σ V (j + 1) ω = - restartPayoff σ V j ω * V ((shift 𝓧)^[restartTime σ j ω] ω) := - rfl - -/-- The restart times are nondecreasing in the number of rounds. -/ -private lemma monotone_restartTime (ω : ℕ → 𝓧) : Monotone fun j ↦ restartTime σ j ω := - monotone_nat_of_le_succ fun _ ↦ Nat.le_add_right _ _ - -/-- If every round uses at least one observation, `j` rounds use at least `j` observations. -/ -private lemma le_restartTime (hσ1 : ∀ ω, 1 ≤ σ ω) (j : ℕ) (ω : ℕ → 𝓧) : - j ≤ restartTime σ j ω := by - induction j with - | zero => exact le_rfl - | succ j ih => exact Nat.add_le_add ih (hσ1 _) - -/-- The first `j` rounds use the sum of their durations. -/ -private lemma restartTime_eq_sum (j : ℕ) (ω : ℕ → 𝓧) : - restartTime σ j ω = ∑ i ∈ Finset.range j, σ ((shift 𝓧)^[restartTime σ i ω] ω) := by - induction j with - | zero => rfl - | succ j ih => rw [Finset.sum_range_succ, ← ih, restartTime_succ] - -/-- The payoff of the first `j` rounds is the product of their payoffs. -/ -private lemma restartPayoff_eq_prod (j : ℕ) (ω : ℕ → 𝓧) : - restartPayoff σ V j ω = ∏ i ∈ Finset.range j, V ((shift 𝓧)^[restartTime σ i ω] ω) := by - induction j with - | zero => rfl - | succ j ih => rw [Finset.prod_range_succ, ← ih, restartPayoff_succ] - -variable {σ V} - -/-- A measurable function of the observations after a measurable random number of them is -measurable. -/ -private lemma measurable_comp_shift_iterate {β : Type*} [MeasurableSpace β] - {h : (ℕ → 𝓧) → β} (hh : Measurable h) {T : (ℕ → 𝓧) → ℕ} (hT : Measurable T) : - Measurable fun ω ↦ h ((shift 𝓧)^[T ω] ω) := - measurable_apply_of_countable (u := fun t ω ↦ h ((shift 𝓧)^[t] ω)) - (fun t ↦ hh.comp (measurable_shift_iterate t)) hT - -/-- The restart times are measurable. -/ -private lemma measurable_restartTime (hσm : Measurable σ) (j : ℕ) : - Measurable (restartTime σ j) := by - induction j with - | zero => exact measurable_const - | succ j ih => exact ih.add (measurable_comp_shift_iterate hσm ih) - -/-- The products of the payoffs of the restarted rounds are measurable. -/ -private lemma measurable_restartPayoff (hσm : Measurable σ) (hVm : Measurable V) (j : ℕ) : - Measurable (restartPayoff σ V j) := by - induction j with - | zero => exact measurable_const - | succ j ih => exact ih.mul (measurable_comp_shift_iterate hVm (measurable_restartTime hσm j)) - -/-- The first `j` rounds are determined by the observations that they use. -/ -private lemma restartTime_eq_of_eqOn (hσ : DependsOnBefore σ σ) (j : ℕ) {t : ℕ} - {ω ω' : ℕ → 𝓧} (h : ∀ i < t, ω i = ω' i) (hj : restartTime σ j ω ≤ t) : - restartTime σ j ω' = restartTime σ j ω := by - induction j with - | zero => rfl - | succ j ih => - rw [restartTime_succ] at hj - have h1 := ih (by omega) - have hshift : ∀ i < t - restartTime σ j ω, - (shift 𝓧)^[restartTime σ j ω] ω i = (shift 𝓧)^[restartTime σ j ω] ω' i := fun i hi ↦ by - simp only [shift_iterate_apply] - exact h _ (by omega) - rw [restartTime_succ, restartTime_succ, h1, hσ hshift (by omega)] - -/-- The payoffs of the first `j` rounds are determined by the observations that they use. -/ -private lemma restartPayoff_eq_of_eqOn (hσ : DependsOnBefore σ σ) (hV : DependsOnBefore σ V) - (j : ℕ) {t : ℕ} {ω ω' : ℕ → 𝓧} (h : ∀ i < t, ω i = ω' i) (hj : restartTime σ j ω ≤ t) : - restartPayoff σ V j ω' = restartPayoff σ V j ω := by - induction j with - | zero => rfl - | succ j ih => - rw [restartTime_succ] at hj - have h1 := restartTime_eq_of_eqOn hσ j h (by omega) - have h2 := ih (by omega) - have hshift : ∀ i < t - restartTime σ j ω, - (shift 𝓧)^[restartTime σ j ω] ω i = (shift 𝓧)^[restartTime σ j ω] ω' i := fun i hi ↦ by - simp only [shift_iterate_apply] - exact h _ (by omega) - rw [restartPayoff_succ, restartPayoff_succ, h1, h2, hV hshift (by omega)] - -/-- Whether the first `j` rounds use exactly `t` observations is determined by the first `t` -observations. -/ -private lemma restartTime_eq_iff_of_eqOn (hσ : DependsOnBefore σ σ) (j t : ℕ) {ω ω' : ℕ → 𝓧} - (h : ∀ i < t, ω i = ω' i) : restartTime σ j ω' = t ↔ restartTime σ j ω = t := - ⟨fun h' ↦ (restartTime_eq_of_eqOn hσ j (fun i hi ↦ (h i hi).symm) h'.le).trans h', - fun h' ↦ (restartTime_eq_of_eqOn hσ j h h'.le).trans h'⟩ - -/-- Whether the first `j` rounds use at most `N` observations is determined by the first `N` -observations. -/ -private lemma restartTime_le_iff_of_eqOn (hσ : DependsOnBefore σ σ) (j N : ℕ) {ω ω' : ℕ → 𝓧} - (h : ∀ i < N, ω i = ω' i) : restartTime σ j ω' ≤ N ↔ restartTime σ j ω ≤ N := - ⟨fun h' ↦ (restartTime_eq_of_eqOn hσ j (fun i hi ↦ (h i hi).symm) h') ▸ h', - fun h' ↦ (restartTime_eq_of_eqOn hσ j h h').symm ▸ h'⟩ - -/-- On the event that the first `j` rounds use `t` observations, their payoff is a function of -the first `t` observations. -/ -private lemma dependsOn_indicator_restartTime_eq (hσ : DependsOnBefore σ σ) - (hV : DependsOnBefore σ V) (j t : ℕ) : - DependsOn ({ω | restartTime σ j ω = t}.indicator (restartPayoff σ V j)) (Set.Iio t) := by - intro ω ω' h - have h' : ∀ i < t, ω i = ω' i := fun i hi ↦ h i hi - by_cases hω : restartTime σ j ω = t - · have hω' := (restartTime_eq_iff_of_eqOn hσ j t h').2 hω - simp only [Set.indicator, Set.mem_ofPred_eq, hω, hω', ite_true] - exact (restartPayoff_eq_of_eqOn hσ hV j h' hω.le).symm - · have hω' : ¬ restartTime σ j ω' = t := mt (restartTime_eq_iff_of_eqOn hσ j t h').1 hω - simp [Set.indicator, hω, hω'] - -/-- The indicator of the event that the first `i` rounds use `t` observations is a function of -the first `t` observations. -/ -private lemma dependsOn_indicator_one_restartTime_eq (hσ : DependsOnBefore σ σ) (i t : ℕ) : - DependsOn ({ω | restartTime σ i ω = t}.indicator (1 : (ℕ → 𝓧) → ℝ)) (Set.Iio t) := by - intro ω ω' h - have h' := restartTime_eq_iff_of_eqOn hσ i t (ω := ω) (ω' := ω') fun i hi ↦ h i hi - by_cases hω : restartTime σ i ω = t - · simp [Set.indicator, hω, h'.2 hω] - · simp [Set.indicator, hω, mt h'.1 hω] - -/-- On the event that the first `j` rounds use at most `N` observations, their payoff is a -function of the first `N` observations. -/ -private lemma dependsOn_indicator_restartTime_le (hσ : DependsOnBefore σ σ) - (hV : DependsOnBefore σ V) (j N : ℕ) : - DependsOn ({ω | restartTime σ j ω ≤ N}.indicator (restartPayoff σ V j)) (Set.Iio N) := by - intro ω ω' h - have h' : ∀ i < N, ω i = ω' i := fun i hi ↦ h i hi - by_cases hω : restartTime σ j ω ≤ N - · have hω' := (restartTime_le_iff_of_eqOn hσ j N h').2 hω - simp only [Set.indicator, Set.mem_ofPred_eq, hω, hω', ite_true] - exact (restartPayoff_eq_of_eqOn hσ hV j h' hω).symm - · have hω' : ¬ restartTime σ j ω' ≤ N := mt (restartTime_le_iff_of_eqOn hσ j N h').1 hω - simp [Set.indicator, hω, hω'] - -/-- Summing the indicators of the events `{T = t}`, `t ≤ N`, gives the indicator of `{T ≤ N}`. -/ -private lemma sum_indicator_eq_indicator_le {Ω M : Type*} [AddCommMonoid M] (T : Ω → ℕ) - (f : Ω → M) (N : ℕ) (ω : Ω) : - ∑ t ∈ Finset.range (N + 1), {ω | T ω = t}.indicator f ω = {ω | T ω ≤ N}.indicator f ω := by - by_cases h : T ω ≤ N - · rw [Finset.sum_eq_single (T ω), Set.indicator_of_mem (s := {ω | T ω ≤ N}) h, - Set.indicator_of_mem (s := {x | T x = T ω}) rfl] - · exact fun t _ ht ↦ Set.indicator_of_notMem (Ne.symm ht) _ - · exact fun hT ↦ absurd (Finset.mem_range.2 (Nat.lt_succ_of_le h)) hT - · rw [Set.indicator_of_notMem h] - refine Finset.sum_eq_zero fun t ht ↦ Set.indicator_of_notMem ?_ _ - rw [Finset.mem_range] at ht - exact fun h' ↦ h (by rw [Set.mem_ofPred_eq] at h'; omega) - -/-- The event that the first `j` rounds use at most `N` observations is measurable. -/ -private lemma measurableSet_restartTime_le (hσm : Measurable σ) (j N : ℕ) : - MeasurableSet {ω | restartTime σ j ω ≤ N} := - measurable_restartTime hσm j measurableSet_Iic - -/-- The event that the first `j` rounds use exactly `t` observations is measurable. -/ -private lemma measurableSet_restartTime_eq (hσm : Measurable σ) (j t : ℕ) : - MeasurableSet {ω | restartTime σ j ω = t} := - measurable_restartTime hσm j (measurableSet_singleton t) - -/-- The payoff of `j + 1` rounds within `N` observations, decomposed along the number `t` of -observations used by the first `j` rounds. -/ -private lemma indicator_restartTime_succ_le (j N : ℕ) (ω : ℕ → 𝓧) : - {ω | restartTime σ (j + 1) ω ≤ N}.indicator (restartPayoff σ V (j + 1)) ω = - ∑ t ∈ Finset.range (N + 1), - {ω | restartTime σ j ω = t}.indicator (restartPayoff σ V j) ω * - {ω | σ ω ≤ N - t}.indicator V ((shift 𝓧)^[t] ω) := by - have hterm (t : ℕ) : {ω | restartTime σ j ω = t}.indicator (restartPayoff σ V j) ω * - {ω | σ ω ≤ N - t}.indicator V ((shift 𝓧)^[t] ω) = - {ω | restartTime σ j ω = t}.indicator (fun ω' ↦ restartPayoff σ V j ω' * - {x | σ x ≤ N - restartTime σ j ω'}.indicator V - ((shift 𝓧)^[restartTime σ j ω'] ω')) ω := by - by_cases h : restartTime σ j ω = t - · rw [Set.indicator_of_mem (s := {x | restartTime σ j x = t}) h, - Set.indicator_of_mem (s := {x | restartTime σ j x = t}) h, h] - · rw [Set.indicator_of_notMem (s := {x | restartTime σ j x = t}) h, - Set.indicator_of_notMem (s := {x | restartTime σ j x = t}) h, zero_mul] - rw [Finset.sum_congr rfl fun t _ ↦ hterm t, sum_indicator_eq_indicator_le] - simp only [Set.indicator, Set.mem_ofPred_eq, restartTime_succ, restartPayoff_succ] - by_cases h1 : restartTime σ j ω ≤ N - · by_cases h2 : σ ((shift 𝓧)^[restartTime σ j ω] ω) ≤ N - restartTime σ j ω - · have h3 : restartTime σ j ω + σ ((shift 𝓧)^[restartTime σ j ω] ω) ≤ N := by omega - simp only [h1, h2, h3, ↓reduceIte] - · have h3 : ¬ restartTime σ j ω + σ ((shift 𝓧)^[restartTime σ j ω] ω) ≤ N := by omega - simp only [h1, h2, h3, ↓reduceIte, mul_zero] - · have h3 : ¬ restartTime σ j ω + σ ((shift 𝓧)^[restartTime σ j ω] ω) ≤ N := by omega - simp only [h1, h3, ↓reduceIte] - -/-- If the payoff of a round has expectation at most `1` on each event `{σ ≤ n}` under an i.i.d. -law, so has the product of the payoffs of `j` restarted rounds on each event that they use at most -`N` observations. -/ -private lemma lintegral_indicator_restartPayoff_le_one (hσ : DependsOnBefore σ σ) - (hV : DependsOnBefore σ V) (hσm : Measurable σ) (hVm : Measurable V) - (P : Measure 𝓧) [IsProbabilityMeasure P] - (h_null : ∀ n : ℕ, - ∫⁻ ω, {ω | σ ω ≤ n}.indicator V ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) ≤ 1) - (j N : ℕ) : - ∫⁻ ω, {ω | restartTime σ j ω ≤ N}.indicator (restartPayoff σ V j) ω - ∂Measure.infinitePi (fun _ : ℕ ↦ P) ≤ 1 := by - set μ := Measure.infinitePi (fun _ : ℕ ↦ P) - induction j generalizing N with - | zero => - calc ∫⁻ ω, {ω | restartTime σ 0 ω ≤ N}.indicator (restartPayoff σ V 0) ω ∂μ - _ ≤ ∫⁻ _, 1 ∂μ := lintegral_mono fun ω ↦ Set.indicator_le (fun _ _ ↦ le_rfl) ω - _ = 1 := by simp - | succ j ih => - have hf (t : ℕ) : - Measurable ({ω | restartTime σ j ω = t}.indicator (restartPayoff σ V j)) := - (measurable_restartPayoff hσm hVm j).indicator - (measurableSet_restartTime_eq hσm j t) - have hg (t : ℕ) : Measurable ({ω | σ ω ≤ N - t}.indicator V) := - hVm.indicator (hσm measurableSet_Iic) - calc ∫⁻ ω, {ω | restartTime σ (j + 1) ω ≤ N}.indicator (restartPayoff σ V (j + 1)) ω ∂μ - _ = ∑ t ∈ Finset.range (N + 1), - ∫⁻ ω, {ω | restartTime σ j ω = t}.indicator (restartPayoff σ V j) ω * - {ω | σ ω ≤ N - t}.indicator V ((shift 𝓧)^[t] ω) ∂μ := by - simp_rw [indicator_restartTime_succ_le] - exact lintegral_finsetSum _ fun t _ ↦ - (hf t).mul ((hg t).comp (measurable_shift_iterate t)) - _ = ∑ t ∈ Finset.range (N + 1), - (∫⁻ ω, {ω | restartTime σ j ω = t}.indicator (restartPayoff σ V j) ω ∂μ) * - ∫⁻ ω, {ω | σ ω ≤ N - t}.indicator V ω ∂μ := - Finset.sum_congr rfl fun t _ ↦ lintegral_mul_comp_shift_iterate P (hf t) - (dependsOn_indicator_restartTime_eq hσ hV j t) (hg t) - _ ≤ ∑ t ∈ Finset.range (N + 1), - ∫⁻ ω, {ω | restartTime σ j ω = t}.indicator (restartPayoff σ V j) ω ∂μ := - Finset.sum_le_sum fun t _ ↦ mul_le_of_le_one_right' (h_null _) - _ = ∫⁻ ω, {ω | restartTime σ j ω ≤ N}.indicator (restartPayoff σ V j) ω ∂μ := by - rw [← lintegral_finsetSum _ fun t _ ↦ hf t] - exact lintegral_congr fun ω ↦ sum_indicator_eq_indicator_le _ _ N ω - _ ≤ 1 := ih N - -variable (σ V) in -/-- The geometric mixture, with weights `(1 - r) r ^ j`, of the products of the payoffs of the -first `j` rounds on the event that they use at most `N` observations. -/ -private noncomputable def restartMixture (r : ℝ) (N : ℕ) (ω : ℕ → 𝓧) : ℝ≥0∞ := - ∑ j ∈ Finset.range (N + 1), ENNReal.ofReal ((1 - r) * r ^ j) * - {ω | restartTime σ j ω ≤ N}.indicator (restartPayoff σ V j) ω - -/-- The mixture of restarted rounds is measurable. -/ -private lemma measurable_restartMixture (hσm : Measurable σ) (hVm : Measurable V) (r : ℝ) - (N : ℕ) : Measurable (restartMixture σ V r N) := - Finset.measurable_fun_sum _ fun j _ ↦ measurable_const.mul - ((measurable_restartPayoff hσm hVm j).indicator - (measurableSet_restartTime_le hσm j N)) - -/-- The mixture of the rounds completed within the first `N` observations is a function of the -first `N` observations. -/ -private lemma dependsOn_restartMixture (hσ : DependsOnBefore σ σ) (hV : DependsOnBefore σ V) - (r : ℝ) (N : ℕ) : DependsOn (restartMixture σ V r N) (Set.Iio N) := fun ω ω' h ↦ - Finset.sum_congr rfl fun j _ ↦ by rw [dependsOn_indicator_restartTime_le hσ hV j N h] - -/-- The mixture of restarted rounds has expectation at most `1` under an i.i.d. law for which the -payoff of a round has expectation at most `1` on each event `{σ ≤ n}`. -/ -private lemma lintegral_restartMixture_le_one (hσ : DependsOnBefore σ σ) - (hV : DependsOnBefore σ V) (hσm : Measurable σ) (hVm : Measurable V) (P : Measure 𝓧) - [IsProbabilityMeasure P] - (h_null : ∀ n : ℕ, - ∫⁻ ω, {ω | σ ω ≤ n}.indicator V ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) ≤ 1) - {r : ℝ} (hr0 : 0 ≤ r) (hr1 : r ≤ 1) (N : ℕ) : - ∫⁻ ω, restartMixture σ V r N ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) ≤ 1 := by - have hm (j : ℕ) : - Measurable ({ω | restartTime σ j ω ≤ N}.indicator (restartPayoff σ V j)) := - (measurable_restartPayoff hσm hVm j).indicator - (measurableSet_restartTime_le hσm j N) - simp only [restartMixture] - rw [lintegral_finsetSum _ fun j _ ↦ (hm j).const_mul _] - calc ∑ j ∈ Finset.range (N + 1), ∫⁻ ω, ENNReal.ofReal ((1 - r) * r ^ j) * - {ω | restartTime σ j ω ≤ N}.indicator (restartPayoff σ V j) ω - ∂Measure.infinitePi (fun _ : ℕ ↦ P) - _ = ∑ j ∈ Finset.range (N + 1), ENNReal.ofReal ((1 - r) * r ^ j) * - ∫⁻ ω, {ω | restartTime σ j ω ≤ N}.indicator (restartPayoff σ V j) ω - ∂Measure.infinitePi (fun _ : ℕ ↦ P) := - Finset.sum_congr rfl fun j _ ↦ lintegral_const_mul _ (hm j) - _ ≤ ∑ j ∈ Finset.range (N + 1), ENNReal.ofReal ((1 - r) * r ^ j) := - Finset.sum_le_sum fun j _ ↦ mul_le_of_le_one_right' - (lintegral_indicator_restartPayoff_le_one hσ hV hσm hVm P h_null j N) - _ = ENNReal.ofReal (1 - r ^ (N + 1)) := by - rw [← ENNReal.ofReal_sum_of_nonneg fun j _ ↦ mul_nonneg (by linarith) (pow_nonneg hr0 j), - ← Finset.mul_sum, mul_neg_geom_sum] - _ ≤ 1 := ENNReal.ofReal_le_one.2 (by have := pow_nonneg hr0 (N + 1); linarith) - -variable (σ) in -/-- The number of rounds completed within the first `N` observations. -/ -private def numRounds (N : ℕ) (ω : ℕ → 𝓧) : ℕ := - Nat.findGreatest (fun j ↦ restartTime σ j ω ≤ N) N - -/-- At most `N` rounds are completed within `N` observations. -/ -private lemma numRounds_le (N : ℕ) (ω : ℕ → 𝓧) : numRounds σ N ω ≤ N := Nat.findGreatest_le N - -/-- The completed rounds use at most `N` observations. -/ -private lemma restartTime_numRounds_le (N : ℕ) (ω : ℕ → 𝓧) : - restartTime σ (numRounds σ N ω) ω ≤ N := - Nat.findGreatest_spec (P := fun j ↦ restartTime σ j ω ≤ N) (Nat.zero_le N) (Nat.zero_le N) - -/-- For `i ≤ N`, the first `i` rounds use at most `N` observations if and only if they are among -the completed rounds. -/ -private lemma restartTime_le_iff_le_numRounds {N i : ℕ} (hi : i ≤ N) (ω : ℕ → 𝓧) : - restartTime σ i ω ≤ N ↔ i ≤ numRounds σ N ω := - ⟨fun h ↦ Nat.le_findGreatest hi h, - fun h ↦ (monotone_restartTime σ ω h).trans (restartTime_numRounds_le N ω)⟩ - -/-- If every round uses at least one observation, the round after the completed ones ends after -the first `N` observations. -/ -private lemma lt_restartTime_numRounds_succ (hσ1 : ∀ ω, 1 ≤ σ ω) (N : ℕ) (ω : ℕ → 𝓧) : - N < restartTime σ (numRounds σ N ω + 1) ω := by - by_cases hJ : numRounds σ N ω + 1 ≤ N - · exact not_le.1 (Nat.findGreatest_is_greatest (P := fun j ↦ restartTime σ j ω ≤ N) - (Nat.lt_succ_self _) hJ) - · have hJN : numRounds σ N ω = N := le_antisymm (numRounds_le N ω) (by omega) - rw [hJN] - exact Nat.lt_of_lt_of_le (Nat.lt_succ_self N) (le_restartTime σ hσ1 (N + 1) ω) - -/-- **Wald's argument, pointwise.** The durations of the rounds that start within the first `N` -observations add up to more than `N`. -/ -private lemma add_one_le_sum_indicator (hσ1 : ∀ ω, 1 ≤ σ ω) (N : ℕ) (ω : ℕ → 𝓧) : - (N + 1 : ℝ) ≤ ∑ i ∈ Finset.range (N + 1), {ω | restartTime σ i ω ≤ N}.indicator - (fun ω ↦ (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ)) ω := by - set J := numRounds σ N ω - have hJN : J ≤ N := numRounds_le N ω - have hJ : N + 1 ≤ restartTime σ (J + 1) ω := lt_restartTime_numRounds_succ hσ1 N ω - calc (N + 1 : ℝ) ≤ (restartTime σ (J + 1) ω : ℝ) := by exact_mod_cast hJ - _ = ∑ i ∈ Finset.range (J + 1), (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ) := by - rw [restartTime_eq_sum, Nat.cast_sum] - _ = ∑ i ∈ Finset.range (J + 1), {ω | restartTime σ i ω ≤ N}.indicator - (fun ω ↦ (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ)) ω := by - refine Finset.sum_congr rfl fun i hi ↦ ?_ - rw [Set.indicator_of_mem] - exact (restartTime_le_iff_le_numRounds ((Nat.lt_succ_iff.1 (Finset.mem_range.1 hi)).trans - hJN) ω).2 (Nat.lt_succ_iff.1 (Finset.mem_range.1 hi)) - _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg - (Finset.range_subset_range.2 (Nat.succ_le_succ hJN)) - fun i _ _ ↦ Set.indicator_nonneg (fun _ _ ↦ Nat.cast_nonneg _) _ - -/-- **Wald's argument, in expectation.** Under an i.i.d. law, the observations after the first -`i` rounds are independent of the event that these rounds use at most `N` observations. -/ -private lemma integral_indicator_comp_shift_restartTime (hσ : DependsOnBefore σ σ) - (hσm : Measurable σ) (P : Measure 𝓧) [IsProbabilityMeasure P] {g : (ℕ → 𝓧) → ℝ} - (hg : Measurable g) {C : ℝ} (hgC : ∀ ω, |g ω| ≤ C) (i N : ℕ) : - ∫ ω, {ω | restartTime σ i ω ≤ N}.indicator - (fun ω ↦ g ((shift 𝓧)^[restartTime σ i ω] ω)) ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) = - (Measure.infinitePi (fun _ : ℕ ↦ P)).real {ω | restartTime σ i ω ≤ N} * - ∫ ω, g ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) := by - set μ := Measure.infinitePi (fun _ : ℕ ↦ P) - have hf (t : ℕ) : Measurable ({ω | restartTime σ i ω = t}.indicator (1 : (ℕ → 𝓧) → ℝ)) := - measurable_one.indicator (measurableSet_restartTime_eq hσm i t) - have hfi (t : ℕ) : Integrable ({ω | restartTime σ i ω = t}.indicator (1 : (ℕ → 𝓧) → ℝ)) μ := - (integrable_const (1 : ℝ)).indicator (measurableSet_restartTime_eq hσm i t) - have hfg (t : ℕ) : Integrable (fun ω ↦ - {ω | restartTime σ i ω = t}.indicator (1 : (ℕ → 𝓧) → ℝ) ω * g ((shift 𝓧)^[t] ω)) μ := by - refine Integrable.of_bound - ((hf t).mul (hg.comp (measurable_shift_iterate t))).aestronglyMeasurable C - (ae_of_all _ fun ω ↦ ?_) - rw [Real.norm_eq_abs, abs_mul] - calc |{ω | restartTime σ i ω = t}.indicator (1 : (ℕ → 𝓧) → ℝ) ω| * |g ((shift 𝓧)^[t] ω)| - _ ≤ 1 * C := by - refine mul_le_mul ?_ (hgC _) (abs_nonneg _) zero_le_one - by_cases h : restartTime σ i ω = t <;> simp [Set.indicator, h] - _ = C := one_mul C - have hsum (ω : ℕ → 𝓧) : {ω | restartTime σ i ω ≤ N}.indicator - (fun ω ↦ g ((shift 𝓧)^[restartTime σ i ω] ω)) ω = - ∑ t ∈ Finset.range (N + 1), - {ω | restartTime σ i ω = t}.indicator (1 : (ℕ → 𝓧) → ℝ) ω * g ((shift 𝓧)^[t] ω) := by - rw [← sum_indicator_eq_indicator_le] - refine Finset.sum_congr rfl fun t _ ↦ ?_ - by_cases h : restartTime σ i ω = t - · rw [Set.indicator_of_mem h, Set.indicator_of_mem h, Pi.one_apply, one_mul, h] - · rw [Set.indicator_of_notMem h, Set.indicator_of_notMem h, zero_mul] - simp_rw [hsum] - rw [integral_finsetSum _ fun t _ ↦ hfg t] - calc ∑ t ∈ Finset.range (N + 1), ∫ ω, - {ω | restartTime σ i ω = t}.indicator (1 : (ℕ → 𝓧) → ℝ) ω * g ((shift 𝓧)^[t] ω) ∂μ - _ = ∑ t ∈ Finset.range (N + 1), - (∫ ω, {ω | restartTime σ i ω = t}.indicator (1 : (ℕ → 𝓧) → ℝ) ω ∂μ) * ∫ ω, g ω ∂μ := - Finset.sum_congr rfl fun t _ ↦ integral_mul_comp_shift_iterate P (hf t) - (dependsOn_indicator_one_restartTime_eq hσ i t) hg - _ = μ.real {ω | restartTime σ i ω ≤ N} * ∫ ω, g ω ∂μ := by - rw [← Finset.sum_mul, ← integral_finsetSum _ fun t _ ↦ hfi t] - simp_rw [sum_indicator_eq_indicator_le] - rw [integral_indicator_one (measurableSet_restartTime_le hσm i N)] - -end Restart - -/-! ### The truncated logarithm -/ - -/-- The logarithm truncated above at `c`, as a real number. -/ -private noncomputable def truncLog (c : ℝ) (x : ℝ≥0∞) : ℝ := (min (ENNReal.log x) c).toReal - -/-- The truncated logarithm is measurable. -/ -private lemma measurable_truncLog (c : ℝ) : Measurable (truncLog c) := - measurable_ereal_toReal.comp (ENNReal.measurable_log.min measurable_const) - -/-- The truncated logarithm of a positive finite number. -/ -private lemma truncLog_of_ne {c : ℝ} {x : ℝ≥0∞} (h0 : x ≠ 0) (htop : x ≠ ∞) : - truncLog c x = min (Real.log x.toReal) c := by - rw [truncLog, ENNReal.log_pos_real h0 htop, ← EReal.coe_strictMono.monotone.map_min, - EReal.toReal_coe] - -/-- The truncated logarithm of `∞` is the truncation level. -/ -private lemma truncLog_top (c : ℝ) : truncLog c ∞ = c := by simp [truncLog] - -/-- The truncated logarithm is at most the truncation level. -/ -private lemma truncLog_le {c : ℝ} {x : ℝ≥0∞} (h0 : x ≠ 0) : truncLog c x ≤ c := by - by_cases htop : x = ∞ - · rw [htop, truncLog_top] - · rw [truncLog_of_ne h0 htop] - exact min_le_right _ _ - -/-- The truncated logarithm of `x ≥ δ` is at least `log δ`, if `log δ ≤ c`. -/ -private lemma log_le_truncLog {c δ : ℝ} (hδ : 0 < δ) {x : ℝ≥0∞} (hx : ENNReal.ofReal δ ≤ x) - (hc : Real.log δ ≤ c) : Real.log δ ≤ truncLog c x := by - have h0 : x ≠ 0 := (lt_of_lt_of_le (ENNReal.ofReal_pos.2 hδ) hx).ne' - by_cases htop : x = ∞ - · rw [htop, truncLog_top] - exact hc - · rw [truncLog_of_ne h0 htop] - exact le_min (Real.log_le_log hδ ((ENNReal.ofReal_le_iff_le_toReal htop).1 hx)) hc - -/-- The truncated logarithm of `x ≥ δ` is bounded in absolute value, if `log δ ≤ c`. -/ -private lemma abs_truncLog_le {c δ : ℝ} (hδ : 0 < δ) {x : ℝ≥0∞} (hx : ENNReal.ofReal δ ≤ x) - (hc : Real.log δ ≤ c) : |truncLog c x| ≤ max |Real.log δ| |c| := - abs_le_max_abs_abs (log_le_truncLog hδ hx hc) - (truncLog_le (lt_of_lt_of_le (ENNReal.ofReal_pos.2 hδ) hx).ne') - -/-- The exponential of the truncated logarithm of `x` is at most `x`. -/ -private lemma ofReal_exp_truncLog_le {c : ℝ} {x : ℝ≥0∞} (h0 : x ≠ 0) : - ENNReal.ofReal (Real.exp (truncLog c x)) ≤ x := by - by_cases htop : x = ∞ - · rw [htop] - exact le_top - · rw [truncLog_of_ne h0 htop] - calc ENNReal.ofReal (Real.exp (min (Real.log x.toReal) c)) - _ ≤ ENNReal.ofReal (Real.exp (Real.log x.toReal)) := - ENNReal.ofReal_le_ofReal (Real.exp_le_exp.2 (min_le_left _ _)) - _ = x := by - rw [Real.exp_log (ENNReal.toReal_pos h0 htop), ENNReal.ofReal_toReal htop] - -/-- Mixing a payoff with a constant: `min (log x) c ≤ truncLog c ((1 - ε) x + ε) - log (1 - ε)`. -/ -private lemma min_log_le_truncLog_sub {ε : ℝ} (hε0 : 0 < ε) (hε1 : ε < 1) (c : ℝ) (x : ℝ≥0∞) : - min (ENNReal.log x) c ≤ - ((truncLog c (ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε) - Real.log (1 - ε) : ℝ) : - EReal) := by - have hlog : Real.log (1 - ε) ≤ 0 := Real.log_nonpos (by linarith) (by linarith) - by_cases h0 : x = 0 - · simp [h0] - by_cases htop : x = ∞ - · have : ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε = ∞ := by - rw [htop, ENNReal.mul_top (ENNReal.ofReal_pos.2 (by linarith)).ne', top_add] - rw [this, truncLog_top] - exact (min_le_right _ _).trans (EReal.coe_le_coe_iff.2 (by linarith)) - have hε' : ENNReal.ofReal ε ≠ 0 := (ENNReal.ofReal_pos.2 hε0).ne' - have hV0 : ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε ≠ 0 := by simp [hε'] - have hVtop : ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε ≠ ∞ := - ENNReal.add_ne_top.2 ⟨ENNReal.mul_ne_top ENNReal.ofReal_ne_top htop, ENNReal.ofReal_ne_top⟩ - have hVreal : (ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε).toReal = - (1 - ε) * x.toReal + ε := by - rw [ENNReal.toReal_add (ENNReal.mul_ne_top ENNReal.ofReal_ne_top htop) ENNReal.ofReal_ne_top, - ENNReal.toReal_mul, ENNReal.toReal_ofReal (by linarith), ENNReal.toReal_ofReal hε0.le] - rw [truncLog_of_ne hV0 hVtop, hVreal, ENNReal.log_pos_real h0 htop, - ← EReal.coe_strictMono.monotone.map_min, EReal.coe_le_coe_iff] - have hx : 0 < x.toReal := ENNReal.toReal_pos h0 htop - have hL : Real.log (1 - ε) + Real.log x.toReal ≤ Real.log ((1 - ε) * x.toReal + ε) := by - rw [← Real.log_mul (by linarith) hx.ne'] - exact Real.log_le_log (mul_pos (by linarith) hx) (by linarith) - rw [← min_sub_sub_right] - exact le_min ((min_le_left _ _).trans (by linarith)) ((min_le_right _ _).trans (by linarith)) - -/-! ### The Wald inequality for a round -/ - -section Wald - -variable {σ : (ℕ → 𝓧) → ℕ} {V : (ℕ → 𝓧) → ℝ≥0∞} - -/-- The logarithm of the mixture of restarted rounds is at least the logarithm of the weight of -the completed rounds plus their truncated log-payoffs, hence at least the sum of the truncated -log-payoffs of the rounds that start within the first `N` observations, up to `c` for the last -one and to the logarithm of the weights. -/ -private lemma log_restartMixture_ge {δ : ℝ} (hδ : 0 < δ) (hVδ : ∀ ω, ENNReal.ofReal δ ≤ V ω) - (c : ℝ) {r : ℝ} (hr0 : 0 < r) (hr1 : r < 1) (N : ℕ) (ω : ℕ → 𝓧) : - ((Real.log (1 - r) + N * Real.log r - c + ∑ i ∈ Finset.range (N + 1), - {ω | restartTime σ i ω ≤ N}.indicator - (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω : ℝ) : EReal) ≤ - ENNReal.log (restartMixture σ V r N ω) := by - set J := numRounds σ N ω - set Y : ℕ → ℝ := fun i ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω)) - have hV0 (ω : ℕ → 𝓧) : V ω ≠ 0 := (lt_of_lt_of_le (ENNReal.ofReal_pos.2 hδ) (hVδ ω)).ne' - have hJN : J ≤ N := numRounds_le N ω - have hr' : 0 < 1 - r := by linarith - -- the mixture is at least its term of index `J` - have h1 : ENNReal.ofReal ((1 - r) * r ^ J * Real.exp (∑ i ∈ Finset.range J, Y i)) ≤ - restartMixture σ V r N ω := by - calc ENNReal.ofReal ((1 - r) * r ^ J * Real.exp (∑ i ∈ Finset.range J, Y i)) - _ = ENNReal.ofReal ((1 - r) * r ^ J) * - ∏ i ∈ Finset.range J, ENNReal.ofReal (Real.exp (Y i)) := by - rw [ENNReal.ofReal_mul (mul_nonneg hr'.le (pow_nonneg hr0.le J)), Real.exp_sum, - ENNReal.ofReal_prod_of_nonneg fun i _ ↦ (Real.exp_pos _).le] - _ ≤ ENNReal.ofReal ((1 - r) * r ^ J) * restartPayoff σ V J ω := by - rw [restartPayoff_eq_prod] - gcongr with i hi - exact ofReal_exp_truncLog_le (hV0 _) - _ = ENNReal.ofReal ((1 - r) * r ^ J) * - {ω | restartTime σ J ω ≤ N}.indicator (restartPayoff σ V J) ω := by - rw [Set.indicator_of_mem (restartTime_numRounds_le N ω)] - _ ≤ restartMixture σ V r N ω := - Finset.single_le_sum (f := fun j ↦ ENNReal.ofReal ((1 - r) * r ^ j) * - {ω | restartTime σ j ω ≤ N}.indicator (restartPayoff σ V j) ω) - (fun _ _ ↦ bot_le) (Finset.mem_range.2 (Nat.lt_succ_of_le hJN)) - -- the logarithm of this term - have hpos : 0 < (1 - r) * r ^ J * Real.exp (∑ i ∈ Finset.range J, Y i) := by - have := pow_pos hr0 J - have := Real.exp_pos (∑ i ∈ Finset.range J, Y i) - positivity - have h2 : Real.log ((1 - r) * r ^ J * Real.exp (∑ i ∈ Finset.range J, Y i)) = - Real.log (1 - r) + J * Real.log r + ∑ i ∈ Finset.range J, Y i := by - rw [Real.log_mul (mul_pos hr' (pow_pos hr0 J)).ne' (Real.exp_pos _).ne', - Real.log_mul hr'.ne' (pow_pos hr0 J).ne', Real.log_pow, Real.log_exp] - -- the sum over the rounds that start within the first `N` observations - have h3 : ∑ i ∈ Finset.range (N + 1), {ω | restartTime σ i ω ≤ N}.indicator - (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω = - ∑ i ∈ Finset.range (J + 1), Y i := by - symm - refine Finset.sum_subset (Finset.range_subset_range.2 (Nat.succ_le_succ hJN)) - (fun i hi hiJ ↦ ?_) |>.symm.trans (Finset.sum_congr rfl fun i hi ↦ ?_) |>.symm - · rw [Set.indicator_of_notMem] - rw [Set.mem_ofPred_eq, restartTime_le_iff_le_numRounds - (Nat.lt_succ_iff.1 (Finset.mem_range.1 hi))] - exact fun h ↦ hiJ (Finset.mem_range.2 (Nat.lt_succ_of_le h)) - · rw [Set.indicator_of_mem] - exact (restartTime_le_iff_le_numRounds - ((Nat.lt_succ_iff.1 (Finset.mem_range.1 hi)).trans hJN) ω).2 - (Nat.lt_succ_iff.1 (Finset.mem_range.1 hi)) - have h4 : Y J ≤ c := truncLog_le (hV0 _) - have h5 : (N : ℝ) * Real.log r ≤ J * Real.log r := - mul_le_mul_of_nonpos_right (by exact_mod_cast hJN) (Real.log_nonpos hr0.le hr1.le) - calc ((Real.log (1 - r) + N * Real.log r - c + ∑ i ∈ Finset.range (N + 1), - {ω | restartTime σ i ω ≤ N}.indicator - (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω : ℝ) : EReal) - _ ≤ ((Real.log ((1 - r) * r ^ J * Real.exp (∑ i ∈ Finset.range J, Y i)) : ℝ) : EReal) := by - rw [h2, h3, Finset.sum_range_succ] - exact EReal.coe_le_coe_iff.2 (by linarith) - _ = ENNReal.log (ENNReal.ofReal ((1 - r) * r ^ J * Real.exp (∑ i ∈ Finset.range J, Y i))) := - (ENNReal.log_ofReal_of_pos hpos).symm - _ ≤ ENNReal.log (restartMixture σ V r N ω) := ENNReal.log_le_log h1 - -/-- The limit argument of the Wald inequality: if for every `r ∈ (0, 1)` and `N ≥ 1` some -`s ≥ (N + 1) / m` satisfies `log (1 - r) + N log r - c + A s ≤ N d`, then `A ≤ d m`. -/ -private lemma le_mul_of_forall_restart {A c d m : ℝ} (hm : 0 < m) (hd : 0 ≤ d) - (h : ∀ r : ℝ, 0 < r → r < 1 → ∀ N : ℕ, 1 ≤ N → ∃ s : ℝ, - (N + 1 : ℝ) ≤ m * s ∧ Real.log (1 - r) + N * Real.log r - c + A * s ≤ N * d) : - A ≤ d * m := by - by_contra hlt - rw [not_le] at hlt - have hA : 0 < A := lt_of_le_of_lt (mul_nonneg hd hm.le) hlt - set ε := A / m - d with hε - have hε0 : 0 < ε := by - rw [hε, sub_pos, lt_div_iff₀ hm] - linarith - set r := Real.exp (-(ε / 2)) with hr - have hr0 : 0 < r := Real.exp_pos _ - have hr1 : r < 1 := Real.exp_lt_one_iff.2 (by linarith) - have hlogr : Real.log r = -(ε / 2) := Real.log_exp _ - obtain ⟨N, hN⟩ := exists_nat_gt ((c - Real.log (1 - r)) * 2 / ε) - obtain ⟨s, hs1, hs2⟩ := h r hr0 hr1 (N + 1) (by omega) - have hAs : A * (((N + 1 : ℕ) : ℝ) + 1) / m ≤ A * s := by - rw [mul_div_assoc] - exact mul_le_mul_of_nonneg_left ((div_le_iff₀ hm).2 (by linarith [mul_comm m s])) hA.le - have key : A * (((N + 1 : ℕ) : ℝ) + 1) / m = (((N + 1 : ℕ) : ℝ) + 1) * (d + ε) := by - rw [hε] - field_simp - ring - rw [key] at hAs - rw [hlogr] at hs2 - have hN' : (c - Real.log (1 - r)) * 2 < N * ε := (div_lt_iff₀ hε0).1 hN - push_cast at hs2 hAs - nlinarith - -/-- **The Wald inequality for a round.** Let `σ ≥ 1` be the bounded duration and `V ≥ δ > 0` the -payoff of a round, both determined by the observations of the round. If the payoff has -expectation at most `1` on each event `{σ ≤ n}` under the i.i.d. laws of the members of `S₁`, -then under the i.i.d. law of `Q₁` the expected logarithm of the payoff, truncated above at `c`, is -at most the bipolar rate times the expected duration. -/ -private lemma integral_truncLog_le_bipolarRate_mul (Q₁ : Measure 𝓧) [IsProbabilityMeasure Q₁] - (hS₁ : ∀ P ∈ S₁, IsProbabilityMeasure P) (hσ : DependsOnBefore σ σ) - (hV : DependsOnBefore σ V) (hσm : Measurable σ) (hVm : Measurable V) (hσ1 : ∀ ω, 1 ≤ σ ω) - {K : ℕ} (hσK : ∀ ω, σ ω ≤ K) - (h_null : ∀ P ∈ S₁, ∀ n : ℕ, - ∫⁻ ω, {ω | σ ω ≤ n}.indicator V ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) ≤ 1) - {δ : ℝ} (hδ : 0 < δ) (hVδ : ∀ ω, ENNReal.ofReal δ ≤ V ω) {c : ℝ} (hc : Real.log δ ≤ c) - (hd : bipolarRate Q₁ S₁ ≠ ⊤) : - ∫ ω, truncLog c (V ω) ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁) ≤ - (bipolarRate Q₁ S₁).toReal * ∫ ω, (σ ω : ℝ) ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁) := by - set μ := Measure.infinitePi (fun _ : ℕ ↦ Q₁) - set m := ∫ ω, (σ ω : ℝ) ∂μ - set A := ∫ ω, truncLog c (V ω) ∂μ - have hd0 := bipolarRate_nonneg Q₁ S₁ - have hσm' : Measurable fun ω ↦ (σ ω : ℝ) := measurable_from_top.comp hσm - have hσC (ω : ℕ → 𝓧) : |(σ ω : ℝ)| ≤ K := by - rw [abs_of_nonneg (Nat.cast_nonneg _)] - exact_mod_cast hσK ω - have hm1 : 1 ≤ m := by - calc (1 : ℝ) = ∫ _, (1 : ℝ) ∂μ := by simp - _ ≤ m := integral_mono (integrable_const _) - (Integrable.of_bound hσm'.aestronglyMeasurable K (ae_of_all _ fun ω ↦ hσC ω)) - fun ω ↦ by exact_mod_cast hσ1 ω - -- the truncated log-payoffs are bounded - set C := max |Real.log δ| |c| - have hYm : Measurable fun ω ↦ truncLog c (V ω) := (measurable_truncLog c).comp hVm - have hT (i : ℕ) : Measurable (restartTime σ i) := measurable_restartTime hσm i - refine le_mul_of_forall_restart (c := c) (by linarith) (EReal.toReal_nonneg hd0) - fun r hr0 hr1 N hN ↦ ?_ - have hfm (i : ℕ) : Measurable fun ω ↦ {ω | restartTime σ i ω ≤ N}.indicator - (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω := - (measurable_comp_shift_iterate hYm (hT i)).indicator (hT i measurableSet_Iic) - have hfC (i : ℕ) (ω : ℕ → 𝓧) : |{ω | restartTime σ i ω ≤ N}.indicator - (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω| ≤ C := by - by_cases h : restartTime σ i ω ≤ N - · rw [Set.indicator_of_mem h] - exact abs_truncLog_le hδ (hVδ _) hc - · rw [Set.indicator_of_notMem h, abs_zero] - exact (abs_nonneg _).trans (le_max_left _ _) - have hfi (i : ℕ) : Integrable (fun ω ↦ {ω | restartTime σ i ω ≤ N}.indicator - (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω) μ := - Integrable.of_bound (hfm i).aestronglyMeasurable C - (ae_of_all _ fun ω ↦ (Real.norm_eq_abs _).trans_le (hfC i ω)) - refine ⟨∑ i ∈ Finset.range (N + 1), μ.real {ω | restartTime σ i ω ≤ N}, ?_, ?_⟩ - · -- Wald's argument - have hgm (i : ℕ) : Measurable fun ω ↦ {ω | restartTime σ i ω ≤ N}.indicator - (fun ω ↦ (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ)) ω := - (measurable_comp_shift_iterate hσm' (hT i)).indicator (hT i measurableSet_Iic) - have hgi (i : ℕ) : Integrable (fun ω ↦ {ω | restartTime σ i ω ≤ N}.indicator - (fun ω ↦ (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ)) ω) μ := by - refine Integrable.of_bound (hgm i).aestronglyMeasurable K (ae_of_all _ fun ω ↦ ?_) - rw [Real.norm_eq_abs] - by_cases h : restartTime σ i ω ≤ N - · rw [Set.indicator_of_mem h] - exact hσC _ - · rw [Set.indicator_of_notMem h, abs_zero] - exact Nat.cast_nonneg _ - calc (N + 1 : ℝ) = ∫ _, (N + 1 : ℝ) ∂μ := by simp - _ ≤ ∫ ω, ∑ i ∈ Finset.range (N + 1), {ω | restartTime σ i ω ≤ N}.indicator - (fun ω ↦ (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ)) ω ∂μ := - integral_mono (integrable_const _) (integrable_finsetSum _ fun i _ ↦ hgi i) - fun ω ↦ add_one_le_sum_indicator hσ1 N ω - _ = ∑ i ∈ Finset.range (N + 1), μ.real {ω | restartTime σ i ω ≤ N} * m := by - rw [integral_finsetSum _ fun i _ ↦ hgi i] - exact Finset.sum_congr rfl fun i _ ↦ - integral_indicator_comp_shift_restartTime hσ hσm Q₁ hσm' hσC i N - _ = m * ∑ i ∈ Finset.range (N + 1), μ.real {ω | restartTime σ i ω ≤ N} := by - rw [Finset.mul_sum] - exact Finset.sum_congr rfl fun i _ ↦ mul_comm _ _ - · -- the logarithmic bound - set B := Real.log (1 - r) + N * Real.log r - c - have hsum : Integrable (fun ω ↦ ∑ i ∈ Finset.range (N + 1), - {ω | restartTime σ i ω ≤ N}.indicator - (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω) μ := - integrable_finsetSum _ fun i _ ↦ hfi i - have hint : Integrable (fun ω ↦ B + ∑ i ∈ Finset.range (N + 1), - {ω | restartTime σ i ω ≤ N}.indicator - (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω) μ := - (integrable_const B).add hsum - have hval : ∫ ω, B + ∑ i ∈ Finset.range (N + 1), {ω | restartTime σ i ω ≤ N}.indicator - (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω ∂μ = - B + A * ∑ i ∈ Finset.range (N + 1), μ.real {ω | restartTime σ i ω ≤ N} := by - rw [integral_add (integrable_const B) hsum, integral_finsetSum _ fun i _ ↦ hfi i, - Finset.mul_sum] - simp only [integral_const, probReal_univ, one_smul] - congr 1 - exact Finset.sum_congr rfl fun i _ ↦ (integral_indicator_comp_shift_restartTime hσ hσm Q₁ - hYm (fun ω ↦ abs_truncLog_le hδ (hVδ ω) hc) i N).trans (mul_comm _ _) - have hle : ((B + A * ∑ i ∈ Finset.range (N + 1), μ.real {ω | restartTime σ i ω ≤ N} : ℝ) : - EReal) ≤ (N : EReal) * bipolarRate Q₁ S₁ := by - rw [← hval, ← eintegral_eq_integral hint] - calc ∫ᵉ ω, ((B + ∑ i ∈ Finset.range (N + 1), {ω | restartTime σ i ω ≤ N}.indicator - (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω : ℝ) : EReal) ∂μ - _ ≤ ∫ᵉ ω, ENNReal.log (restartMixture σ V r N ω) ∂μ := - eintegral_mono fun ω ↦ log_restartMixture_ge hδ hVδ c hr0 hr1 N ω - _ ≤ maxLogGrowth Q₁ S₁ N := - eintegral_log_le_maxLogGrowth_of_dependsOn Q₁ hS₁ (measurable_restartMixture hσm hVm r N) - (dependsOn_restartMixture hσ hV r N) fun P hP ↦ by - have := hS₁ P hP - exact lintegral_restartMixture_le_one hσ hV hσm hVm P (h_null P hP) hr0.le hr1.le N - _ ≤ N * bipolarRate Q₁ S₁ := maxLogGrowth_le_mul_bipolarRate Q₁ S₁ (by omega) - rw [← EReal.coe_toReal hd (ne_bot_of_le_ne_bot EReal.zero_ne_bot hd0), ← EReal.coe_natCast, - ← EReal.coe_mul, EReal.coe_le_coe_iff] at hle - exact hle - -end Wald - -/-! ### Extended integrals -/ - -/-- **Monotone convergence for truncations.** If the extended integrals of the truncations -`min f k`, `k ∈ ℕ`, are at most `D`, so is the extended integral of `f`. -/ -private lemma eintegral_le_of_forall_min_le {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} - {f : Ω → EReal} (hf : Measurable f) {D : EReal} - (h : ∀ k : ℕ, ∫ᵉ x, min (f x) k ∂μ ≤ D) : ∫ᵉ x, f x ∂μ ≤ D := by - have hmono : Monotone EReal.toENNReal := fun _ _ h ↦ EReal.toENNReal_le_toENNReal h - have hpos (k : ℕ) (x : Ω) : (min (f x) k).toENNReal = min (f x).toENNReal k := by - rw [hmono.map_min, show ((k : EReal)) = ((k : ℝ≥0∞) : EReal) by simp, EReal.toENNReal_coe] - have hneg (k : ℕ) (x : Ω) : (-min (f x) k).toENNReal = (-f x).toENNReal := by - by_cases hk : f x ≤ k - · rw [min_eq_left hk] - · rw [not_le] at hk - have hk0 : (0 : EReal) ≤ k := by exact_mod_cast Nat.zero_le k - rw [min_eq_right hk.le, EReal.toENNReal_of_nonpos (by simp), - EReal.toENNReal_of_nonpos (by simpa using hk0.trans hk.le)] - have h' (k : ℕ) : ((∫⁻ x, min (f x).toENNReal k ∂μ : ℝ≥0∞) : EReal) - - ((∫⁻ x, (-f x).toENNReal ∂μ : ℝ≥0∞) : EReal) ≤ D := by - have := h k - simp only [eintegral, hpos, hneg] at this - exact this - have hm (k : ℕ) : Measurable fun x ↦ min (f x).toENNReal (k : ℝ≥0∞) := - (measurable_ereal_toENNReal.comp hf).min measurable_const - have hmono' : Monotone fun (k : ℕ) x ↦ min (f x).toENNReal (k : ℝ≥0∞) := - fun k k' hkk' x ↦ min_le_min_left _ (by exact_mod_cast hkk') - have hsup : ∫⁻ x, (f x).toENNReal ∂μ = ⨆ k : ℕ, ∫⁻ x, min (f x).toENNReal k ∂μ := by - rw [← lintegral_iSup hm hmono'] - refine lintegral_congr fun x ↦ le_antisymm ?_ (iSup_le fun k ↦ min_le_left _ _) - by_cases hx : (f x).toENNReal = ∞ - · simp [hx, ENNReal.iSup_natCast] - · obtain ⟨k, hk⟩ := ENNReal.exists_nat_gt hx - exact le_iSup_of_le k (min_eq_left hk.le).ge - rw [eintegral, hsup] - set b := ∫⁻ x, (-f x).toENNReal ∂μ - by_cases hb : b = ∞ - · rw [hb, EReal.coe_ennreal_top, EReal.sub_top] - exact bot_le - have hb' : (b : EReal) ≠ ⊤ := by simpa using hb - have hb'' : (b : EReal) ≠ ⊥ := by simp - rw [EReal.sub_le_iff_le_add (.inl hb'') (.inl hb')] - have hk (k : ℕ) : ((∫⁻ x, min (f x).toENNReal k ∂μ : ℝ≥0∞) : EReal) ≤ D + b := - (EReal.sub_le_iff_le_add (.inl hb'') (.inl hb')).1 (h' k) - have hD : 0 ≤ D + b := (EReal.coe_ennreal_nonneg _).trans (hk 0) - rw [← EReal.coe_toENNReal hD] at hk ⊢ - exact EReal.coe_ennreal_le_coe_ennreal_iff.2 - (iSup_le fun k ↦ EReal.coe_ennreal_le_coe_ennreal_iff.1 (hk k)) - -/-- A bound `x ≤ D + η` for every `η > 0` gives `x ≤ D`. -/ -private lemma le_coe_of_forall_pos_le_coe_add {x : EReal} {D : ℝ} - (h : ∀ η : ℝ, 0 < η → x ≤ ↑(D + η)) : x ≤ D := by - refine le_of_forall_gt_imp_ge_of_dense fun a ha ↦ ?_ - obtain ⟨r, hDr, hra⟩ := EReal.lt_iff_exists_real_btwn.1 ha - calc x ≤ ↑(D + (r - D)) := h _ (by exact_mod_cast sub_pos.2 (EReal.coe_lt_coe_iff.1 hDr)) - _ = r := by rw [add_sub_cancel] - _ ≤ a := hra.le +/-- The mixing constant `ε` of `(1 - ε) x + ε` costs `- log (1 - ε)`, which tends to `0` with `ε`: +a bound `x ≤ D - log (1 - ε)` for every `ε ∈ (0, 1)` gives `x ≤ D`. -/ +private lemma le_of_forall_le_sub_log_one_sub {x : EReal} {D : ℝ} + (h : ∀ ε : ℝ, 0 < ε → ε < 1 → x ≤ ((D - Real.log (1 - ε) : ℝ) : EReal)) : x ≤ D := by + refine EReal.le_of_forall_lt_iff_le.1 fun z hz ↦ ?_ + have hη : 0 < z - D := sub_pos.2 (EReal.coe_lt_coe_iff.1 hz) + have hexp : Real.exp (-(z - D)) < 1 := Real.exp_lt_one_iff.2 (by linarith) + have h' := h (1 - Real.exp (-(z - D))) (by linarith) (by linarith [Real.exp_pos (-(z - D))]) + rwa [sub_sub_cancel, Real.log_exp, sub_neg_eq_add, add_sub_cancel] at h' /-! ### The Wald inequality for e-processes -/ @@ -963,6 +100,40 @@ section EProcess variable {E : ℕ → (ℕ → 𝓧) → ℝ≥0∞} {τ : (ℕ → 𝓧) → ℕ} +/-- The stopped e-process mixed with a constant, `(1 - ε) E_τ + ε`, has expectation at most `1` +on each event `{τ + 1 ≤ n}` under the i.i.d. law of a member of the null. -/ +private lemma lintegral_indicator_mix_stoppedValue_le_one (hS₁ : ∀ P ∈ S₁, IsProbabilityMeasure P) + (hE : IsEProcess E (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) + ((fun P ↦ Measure.infinitePi fun _ : ℕ ↦ P) '' S₁)) + (hτ : IsStoppingTime (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) fun ω ↦ (τ ω : WithTop ℕ)) + {ε : ℝ} (hε0 : 0 < ε) (hε1 : ε < 1) {P : Measure 𝓧} (hP : P ∈ S₁) (n : ℕ) : + ∫⁻ ω, {ω | τ ω + 1 ≤ n}.indicator + (fun ω ↦ ENNReal.ofReal (1 - ε) * E (τ ω) ω + ENNReal.ofReal ε) ω + ∂Measure.infinitePi (fun _ : ℕ ↦ P) ≤ 1 := by + have := hS₁ P hP + have hPS : Measure.infinitePi (fun _ : ℕ ↦ P) ∈ + (fun P ↦ Measure.infinitePi fun _ : ℕ ↦ P) '' S₁ := ⟨P, hP, rfl⟩ + calc ∫⁻ ω, {ω | τ ω + 1 ≤ n}.indicator + (fun ω ↦ ENNReal.ofReal (1 - ε) * E (τ ω) ω + ENNReal.ofReal ε) ω + ∂Measure.infinitePi (fun _ ↦ P) + _ ≤ ∫⁻ ω, ENNReal.ofReal (1 - ε) * E (min (τ ω) (n - 1)) ω + ENNReal.ofReal ε + ∂Measure.infinitePi (fun _ ↦ P) := by + refine lintegral_mono fun ω ↦ ?_ + by_cases hω : τ ω + 1 ≤ n + · rw [Set.indicator_of_mem hω, min_eq_left (by omega : τ ω ≤ n - 1)] + · rw [Set.indicator_of_notMem hω] + exact bot_le + _ = ENNReal.ofReal (1 - ε) * ∫⁻ ω, E (min (τ ω) (n - 1)) ω + ∂Measure.infinitePi (fun _ ↦ P) + ENNReal.ofReal ε := by + rw [lintegral_add_right _ measurable_const, lintegral_const_mul _ + (hE.measurable_stoppedValue (hτ.natCast_min (n - 1))), lintegral_const, + measure_univ, mul_one] + _ ≤ ENNReal.ofReal (1 - ε) * 1 + ENNReal.ofReal ε := by + gcongr + exact hE.lintegral_le_one (hτ.natCast_min (n - 1)) hPS + _ = 1 := by + rw [mul_one, ← ENNReal.ofReal_add (by linarith) hε0.le, sub_add_cancel, ENNReal.ofReal_one] + /-- The Wald inequality for the payoff `(1 - ε) E_τ + ε`, truncated above at `c`: apply the Wald inequality for a round to the e-process stopped at `min τ k`, and let `k` tend to infinity. The bound `D` is that of the Wald inequality for the stopping times `min τ k`. -/ @@ -980,46 +151,22 @@ private lemma integral_truncLog_stoppedValue_le (Q₁ : Measure 𝓧) [IsProbabi set μ := Measure.infinitePi (fun _ : ℕ ↦ Q₁) set V : ℕ → (ℕ → 𝓧) → ℝ≥0∞ := fun k ω ↦ ENNReal.ofReal (1 - ε) * E (min (τ ω) k) ω + ENNReal.ofReal ε - have hτk (k : ℕ) := isStoppingTime_min_nat hτ k + have hτk (k : ℕ) := hτ.natCast_min k have hVm (k : ℕ) : Measurable (V k) := (measurable_const.mul (hE.measurable_stoppedValue (hτk k))).add measurable_const have hVε (k : ℕ) (ω : ℕ → 𝓧) : ENNReal.ofReal ε ≤ V k ω := le_add_self -- the Wald inequality for the round stopped at `min τ k` have hk (k : ℕ) : ∫ ω, truncLog c (V k ω) ∂μ ≤ D := by refine (integral_truncLog_le_bipolarRate_mul (σ := fun ω ↦ min (τ ω) k + 1) Q₁ hS₁ ?_ ?_ - ((measurable_of_isStoppingTime_nat (hτk k)).add_const 1) (hVm k) (fun _ ↦ le_add_self) + (((hτk k).measurable_nat).add_const 1) (hVm k) (fun _ ↦ le_add_self) (K := k + 1) (fun ω ↦ by simp) ?_ hε0 (hVε k) hc hd).trans ?_ - · intro u ω ω' h hle - simp only at hle ⊢ - rw [eq_of_isStoppingTime_of_forall_le (hτk k) fun i hi ↦ h i (by omega)] - · intro u ω ω' h hle - simp only at hle + · refine dependsOnBefore_iff.2 fun u ω ω' h hle ↦ ?_ + rw [(hτk k).eq_of_forall_le fun i hi ↦ h i (by omega)] + · refine dependsOnBefore_iff.2 fun u ω ω' h hle ↦ ?_ have h' : ∀ i ≤ min (τ ω) k, ω i = ω' i := fun i hi ↦ h i (by omega) - simp only [V, eq_of_isStoppingTime_of_forall_le (hτk k) h', + simp only [V, (hτk k).eq_of_forall_le h', ((hE.adapted (min (τ ω) k)).dependsOn_of_piLE fun i hi ↦ h' i hi).symm] - · intro P hP n - have := hS₁ P hP - have hPS : Measure.infinitePi (fun _ : ℕ ↦ P) ∈ - (fun P ↦ Measure.infinitePi fun _ : ℕ ↦ P) '' S₁ := ⟨P, hP, rfl⟩ - calc ∫⁻ ω, {ω | min (τ ω) k + 1 ≤ n}.indicator (V k) ω ∂Measure.infinitePi (fun _ ↦ P) - _ ≤ ∫⁻ ω, ENNReal.ofReal (1 - ε) * E (min (min (τ ω) k) (n - 1)) ω + ENNReal.ofReal ε - ∂Measure.infinitePi (fun _ ↦ P) := by - refine lintegral_mono fun ω ↦ ?_ - by_cases hω : min (τ ω) k + 1 ≤ n - · rw [Set.indicator_of_mem hω, min_eq_left (by omega : min (τ ω) k ≤ n - 1)] - · rw [Set.indicator_of_notMem hω] - exact bot_le - _ = ENNReal.ofReal (1 - ε) * ∫⁻ ω, E (min (min (τ ω) k) (n - 1)) ω - ∂Measure.infinitePi (fun _ ↦ P) + ENNReal.ofReal ε := by - rw [lintegral_add_right _ measurable_const, lintegral_const_mul _ - (hE.measurable_stoppedValue (isStoppingTime_min_nat (hτk k) (n - 1))), lintegral_const, - measure_univ, mul_one] - _ ≤ ENNReal.ofReal (1 - ε) * 1 + ENNReal.ofReal ε := by - gcongr - exact hE.lintegral_le_one (isStoppingTime_min_nat (hτk k) (n - 1)) hPS - _ = 1 := by - rw [mul_one, ← ENNReal.ofReal_add (by linarith) hε0.le, sub_add_cancel, - ENNReal.ofReal_one] + · exact fun P hP n ↦ lintegral_indicator_mix_stoppedValue_le_one hS₁ hE (hτk k) hε0 hε1 hP n · exact hD k -- let `k` tend to infinity refine le_of_tendsto' (tendsto_integral_of_dominated_convergence (fun _ ↦ max |Real.log ε| |c|) @@ -1045,7 +192,7 @@ private lemma eintegral_log_stoppedValue_le_toReal_mul (Q₁ : Measure 𝓧) [Is set μ := Measure.infinitePi (fun _ : ℕ ↦ Q₁) set m := ∫⁻ ω, (τ ω : ℝ≥0∞) + 1 ∂μ set D := (bipolarRate Q₁ S₁).toReal * m.toReal - have hτm := measurable_of_isStoppingTime_nat hτ + have hτm := hτ.measurable_nat have hEτm : Measurable fun ω ↦ E (τ ω) ω := hE.measurable_stoppedValue hτ have hD (k : ℕ) : (bipolarRate Q₁ S₁).toReal * ∫ ω, ((min (τ ω) k + 1 : ℕ) : ℝ) ∂μ ≤ D := by rcases hdm with hd0 | hm @@ -1077,11 +224,8 @@ private lemma eintegral_log_stoppedValue_le_toReal_mul (Q₁ : Measure 𝓧) [Is integral_sub hYi (integrable_const _), integral_const, probReal_univ, one_smul] _ ≤ ((D - Real.log (1 - ε) : ℝ) : EReal) := EReal.coe_le_coe_iff.2 (by linarith [integral_truncLog_stoppedValue_le Q₁ hS₁ hE hτ hε0 hε1 hc hd hD]) - refine eintegral_le_of_forall_min_le (ENNReal.measurable_log.comp hEτm) fun k ↦ ?_ - refine le_coe_of_forall_pos_le_coe_add fun η hη ↦ ?_ - have hexp : Real.exp (-η) < 1 := Real.exp_lt_one_iff.2 (by linarith) - have h := step (1 - Real.exp (-η)) (by linarith) (by linarith [Real.exp_pos (-η)]) k - rwa [sub_sub_cancel, Real.log_exp, sub_neg_eq_add] at h + exact eintegral_le_of_forall_min_le (ENNReal.measurable_log.comp hEτm) fun k ↦ + le_of_forall_le_sub_log_one_sub fun ε hε0 hε1 ↦ step ε hε0 hε1 k end EProcess @@ -1092,7 +236,7 @@ bipolar rate. The expected number of observations may be infinite, with `∞ * 0 bipolar rate is `0`, the expected logarithm is nonpositive at every stopping time. The expected logarithm is Statlib's extended integral, which is `⊥` when the positive and negative parts of the logarithm have infinite integrals. `Q₁` need not be a probability measure: otherwise its -i.i.d. law is `0` and both sides are `0`. -/ +i.i.d. law is `0` and both sides are `0`. [EVR26, Note 01] -/ theorem IsEProcess.eintegral_log_stoppedValue_le_mul_bipolarRate (Q₁ : Measure 𝓧) (hS₁ : ∀ P ∈ S₁, IsProbabilityMeasure P) {E : ℕ → (ℕ → 𝓧) → ℝ≥0∞} (hE : IsEProcess E (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) @@ -1121,7 +265,7 @@ theorem IsEProcess.eintegral_log_stoppedValue_le_mul_bipolarRate (Q₁ : Measure · rw [hm, EReal.coe_ennreal_top, EReal.top_mul_of_pos hd] exact le_top refine (eintegral_log_stoppedValue_le_toReal_mul Q₁ hS₁ hE hτ hdtop (.inr hm)).trans_eq ?_ - rw [EReal.coe_mul, EReal.coe_toReal hdtop (ne_bot_of_gt hd), EReal.coe_ennreal_toReal hm, + rw [EReal.coe_mul, coe_toReal_bipolarRate hdtop, EReal.coe_ennreal_toReal hm, mul_comm] /-! ### Expected stopping times of sequential tests -/ @@ -1130,6 +274,44 @@ section Test variable {τ : (ℕ → 𝓧) → WithTop ℕ} +/-- A sequential test `τ` of level `a > 0` gives the e-process `ε + (1 - ε) a⁻¹ 𝟙{τ ≤ n}` for the +i.i.d. null, for every `ε ∈ (0, 1)`. -/ +private lemma isEProcess_add_indicator_le (hS₁ : ∀ P ∈ S₁, IsProbabilityMeasure P) + (hτ : IsStoppingTime (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) τ) {a ε : ℝ} (ha0 : 0 < a) + (hε0 : 0 < ε) (hε1 : ε < 1) + (h_level : ∀ P ∈ S₁, Measure.infinitePi (fun _ : ℕ ↦ P) {ω | τ ω ≠ ⊤} ≤ ENNReal.ofReal a) : + IsEProcess (fun n ω ↦ ENNReal.ofReal ε + {ω | τ ω ≤ n}.indicator + (fun _ ↦ ENNReal.ofReal ((1 - ε) / a)) ω) (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) + ((fun P ↦ Measure.infinitePi fun _ : ℕ ↦ P) '' S₁) := by + have hb0 : 0 < (1 - ε) / a := div_pos (by linarith) ha0 + set b := ENNReal.ofReal ((1 - ε) / a) + have hτtop : MeasurableSet {ω | τ ω ≠ ⊤} := + (hτ.measurable_enat (measurableSet_singleton ⊤)).compl + refine IsEProcess.of_lintegral_le_one ?_ (fun n ↦ + (measurable_const.indicator (hτ.measurableSet_le_natCast n)).const_add _) + fun σ _ _ hP ↦ ?_ + · rintro _ ⟨P, hP, rfl⟩ + have := hS₁ P hP + infer_instance + obtain ⟨P, hP, rfl⟩ := hP + have := hS₁ P hP + calc ∫⁻ ω, ENNReal.ofReal ε + {x | τ x ≤ σ ω}.indicator (fun _ ↦ b) ω + ∂Measure.infinitePi (fun _ ↦ P) + _ ≤ ∫⁻ ω, ENNReal.ofReal ε + {ω | τ ω ≠ ⊤}.indicator (fun _ ↦ b) ω + ∂Measure.infinitePi (fun _ ↦ P) := + lintegral_mono fun ω ↦ add_le_add le_rfl (Set.indicator_le_indicator_of_subset + (s := {x | τ x ≤ σ ω}) (t := {x | τ x ≠ ⊤}) + (fun x hx ↦ ne_top_of_le_ne_top (WithTop.natCast_ne_top _) hx) (fun _ ↦ bot_le) ω) + _ = ENNReal.ofReal ε + b * Measure.infinitePi (fun _ ↦ P) {ω | τ ω ≠ ⊤} := by + rw [lintegral_add_left measurable_const, lintegral_const, measure_univ, mul_one, + lintegral_indicator_const hτtop] + _ ≤ ENNReal.ofReal ε + b * ENNReal.ofReal a := by + gcongr + exact h_level P hP + _ = 1 := by + rw [← ENNReal.ofReal_mul hb0.le, div_mul_cancel₀ _ ha0.ne', + ← ENNReal.ofReal_add hε0.le (by linarith), add_sub_cancel, ENNReal.ofReal_one] + /-- The lower bound for a level `a > 0` and a finite expected number of observations, up to a term `- log (1 - ε)`: the Wald inequality for the e-process `ε + (1 - ε) a⁻¹ 𝟙{τ ≤ n}` at the stopping times `min τ k`, as `k → ∞`. -/ @@ -1150,7 +332,6 @@ private lemma neg_log_le_toReal_mul_sub (Q₁ : Measure 𝓧) [IsProbabilityMeas have hτm := hτ.measurable_enat have hτle (k : ℕ) : MeasurableSet {ω | τ ω ≤ k} := Filtration.le _ k _ (hτ.measurableSet_le_natCast k) - have hτtop : MeasurableSet {ω | τ ω ≠ ⊤} := (hτm (measurableSet_singleton ⊤)).compl -- `τ` is almost surely finite under the i.i.d. law of `Q₁` have hae : ∀ᵐ ω ∂μ, τ ω ≠ ⊤ := by filter_upwards [ae_lt_top (f := fun ω ↦ ENat.toENNReal (τ ω) + 1) @@ -1175,30 +356,8 @@ private lemma neg_log_le_toReal_mul_sub (Q₁ : Measure 𝓧) [IsProbabilityMeas set E : ℕ → (ℕ → 𝓧) → ℝ≥0∞ := fun n ω ↦ ENNReal.ofReal ε + {ω | τ ω ≤ n}.indicator (fun _ ↦ b) ω have hE : IsEProcess E (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) - ((fun P ↦ Measure.infinitePi fun _ : ℕ ↦ P) '' S₁) := by - refine IsEProcess.of_lintegral_le_one ?_ (fun n ↦ - (measurable_const.indicator (hτ.measurableSet_le_natCast n)).const_add _) - fun σ _ _ hP ↦ ?_ - · rintro _ ⟨P, hP, rfl⟩ - have := hS₁ P hP - infer_instance - obtain ⟨P, hP, rfl⟩ := hP - have := hS₁ P hP - calc ∫⁻ ω, E (σ ω) ω ∂Measure.infinitePi (fun _ ↦ P) - _ ≤ ∫⁻ ω, ENNReal.ofReal ε + {ω | τ ω ≠ ⊤}.indicator (fun _ ↦ b) ω - ∂Measure.infinitePi (fun _ ↦ P) := - lintegral_mono fun ω ↦ add_le_add le_rfl (Set.indicator_le_indicator_of_subset - (s := {x | τ x ≤ σ ω}) (t := {x | τ x ≠ ⊤}) - (fun x hx ↦ ne_top_of_le_ne_top (WithTop.natCast_ne_top _) hx) (fun _ ↦ bot_le) ω) - _ = ENNReal.ofReal ε + b * Measure.infinitePi (fun _ ↦ P) {ω | τ ω ≠ ⊤} := by - rw [lintegral_add_left measurable_const, lintegral_const, measure_univ, mul_one, - lintegral_indicator_const hτtop] - _ ≤ ENNReal.ofReal ε + b * ENNReal.ofReal a := by - gcongr - exact h_level P hP - _ = 1 := by - rw [← ENNReal.ofReal_mul hb0.le, div_mul_cancel₀ _ ha0.ne', - ← ENNReal.ofReal_add hε0.le (by linarith), add_sub_cancel, ENNReal.ofReal_one] + ((fun P ↦ Measure.infinitePi fun _ : ℕ ↦ P) '' S₁) := + isEProcess_add_indicator_le hS₁ hτ ha0 hε0 hε1 h_level -- its logarithm at `min τ k` set g : ℕ → (ℕ → 𝓧) → ℝ := fun k ω ↦ if τ ω ≤ k then L else Real.log ε have hgm (k : ℕ) : Measurable (g k) := Measurable.ite (hτle k) measurable_const measurable_const @@ -1222,8 +381,7 @@ private lemma neg_log_le_toReal_mul_sub (Q₁ : Measure 𝓧) [IsProbabilityMeas have h := hE.eintegral_log_stoppedValue_le_mul_bipolarRate Q₁ hS₁ (hτk k) have hmk' : ∫⁻ ω, (τk k ω : ℝ≥0∞) + 1 ∂μ ≠ ∞ := ne_top_of_le_ne_top hm (hmk k) rw [eintegral_congr (hlog k), eintegral_eq_integral hg, ← EReal.coe_ennreal_toReal hmk', - ← EReal.coe_toReal hd (ne_bot_of_le_ne_bot EReal.zero_ne_bot hd0), ← EReal.coe_mul, - EReal.coe_le_coe_iff] at h + ← coe_toReal_bipolarRate hd, ← EReal.coe_mul, EReal.coe_le_coe_iff] at h calc ∫ ω, g k ω ∂μ ≤ _ := h _ ≤ m.toReal * (bipolarRate Q₁ S₁).toReal := mul_le_mul_of_nonneg_right (ENNReal.toReal_mono hm (hmk k)) (EReal.toReal_nonneg hd0) @@ -1248,7 +406,8 @@ private lemma neg_log_le_toReal_mul_sub (Q₁ : Measure 𝓧) [IsProbabilityMeas /-- **The lower bound on expected stopping times.** A sequential test of level `α` for the i.i.d. laws of the members of `S₁`, that is, a stopping time `τ` with `P^ℕ (τ < ∞) ≤ α` for every `P ∈ S₁`, makes at least `log (1/α) / d` observations in expectation under the i.i.d. law of -`Q₁`, where `d` is the bipolar rate of `Q₁` against `S₁`: `log (1/α) / d ≤ 𝔼[τ + 1]`. The left +`Q₁`, where `d` is the bipolar rate of `Q₁` against `S₁`: `log (1/α) / d ≤ 𝔼[τ + 1]` +[EVR26, Note 01]. The left side is in `ℝ≥0∞`, with `log (1/α)` replaced by `0` for `α ≥ 1`: if `d = 0` and `α < 1`, the expected number of observations is infinite, if `d = ∞` the bound is `0`, and if `α = 0` and `d < ∞` the expected number of observations is infinite. Since the bipolar rate is at most the @@ -1270,18 +429,13 @@ theorem toENNReal_log_inv_div_bipolarRate_le_lintegral (Q₁ : Measure 𝓧) · rw [EReal.toENNReal_of_nonpos (ENNReal.log_le_zero_iff.2 (ENNReal.inv_le_one.2 hα1)), ENNReal.zero_div] exact bot_le - have hD0 : 0 ≤ (bipolarRate Q₁ S₁).toReal * m.toReal := - mul_nonneg (EReal.toReal_nonneg (bipolarRate_nonneg Q₁ S₁)) ENNReal.toReal_nonneg -- the bound up to `- log (1 - ε)`, for every `ε ∈ (0, 1)`, gives the bound have key {a : ℝ} (ha0 : 0 < a) (h_level' : ∀ P ∈ S₁, Measure.infinitePi (fun _ : ℕ ↦ P) {ω | τ ω ≠ ⊤} ≤ ENNReal.ofReal a) : - -Real.log a ≤ (bipolarRate Q₁ S₁).toReal * m.toReal := by - refine le_of_forall_pos_le_add fun η hη ↦ ?_ - have hexp : Real.exp (-η) < 1 := Real.exp_lt_one_iff.2 (by linarith) - have h := neg_log_le_toReal_mul_sub Q₁ hS₁ hτ ha0 h_level' hd hm - (ε := 1 - Real.exp (-η)) (by linarith) (by linarith [Real.exp_pos (-η)]) - rwa [sub_sub_cancel, Real.log_exp, sub_neg_eq_add] at h + -Real.log a ≤ (bipolarRate Q₁ S₁).toReal * m.toReal := + EReal.coe_le_coe_iff.1 <| le_of_forall_le_sub_log_one_sub fun ε hε0 hε1 ↦ + EReal.coe_le_coe_iff.2 (neg_log_le_toReal_mul_sub Q₁ hS₁ hτ ha0 h_level' hd hm hε0 hε1) rcases eq_or_ne α 0 with rfl | hα0 · -- a test of level `0` with a finite expected number of observations would have level -- `exp (- (d 𝔼[τ + 1] + 1))` diff --git a/LMLExplore/MeasureTheory/Integral/EReal.lean b/LMLExplore/MeasureTheory/Integral/EReal.lean new file mode 100644 index 00000000..56773fb2 --- /dev/null +++ b/LMLExplore/MeasureTheory/Integral/EReal.lean @@ -0,0 +1,77 @@ +/- +Copyright (c) 2026 LMLExplore contributors. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: LMLExplore contributors +-/ +module + +public import Statlib.ForMathlib.MeasureTheory.Integral.EReal.EIntegral + +/-! +# Monotone convergence for the truncations of an extended integral + +Statlib's extended integral `∫ᵉ x, f x ∂μ` of a function `f` with values in `EReal` is the +difference of the lower Lebesgue integrals of its positive and negative parts. Truncating `f` +above at `k` leaves its negative part unchanged, and the positive parts of the truncations +`min f k` increase to that of `f`, so a bound on the extended integrals of the truncations is a +bound on the extended integral of `f`. + +## Main statements + +* `MeasureTheory.eintegral_le_of_forall_min_le`: if the extended integrals of the truncations + `min f k`, `k ∈ ℕ`, are at most `D`, so is the extended integral of `f`. +-/ + +public section + +open scoped ENNReal + +namespace MeasureTheory + +/-- **Monotone convergence for truncations.** If the extended integrals of the truncations +`min f k`, `k ∈ ℕ`, are at most `D`, so is the extended integral of `f`. -/ +theorem eintegral_le_of_forall_min_le {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + {f : Ω → EReal} (hf : Measurable f) {D : EReal} + (h : ∀ k : ℕ, ∫ᵉ x, min (f x) k ∂μ ≤ D) : ∫ᵉ x, f x ∂μ ≤ D := by + have hmono : Monotone EReal.toENNReal := fun _ _ h ↦ EReal.toENNReal_le_toENNReal h + have hpos (k : ℕ) (x : Ω) : (min (f x) k).toENNReal = min (f x).toENNReal k := by + rw [hmono.map_min, show ((k : EReal)) = ((k : ℝ≥0∞) : EReal) by simp, EReal.toENNReal_coe] + have hneg (k : ℕ) (x : Ω) : (-min (f x) k).toENNReal = (-f x).toENNReal := by + by_cases hk : f x ≤ k + · rw [min_eq_left hk] + · rw [not_le] at hk + have hk0 : (0 : EReal) ≤ k := by exact_mod_cast Nat.zero_le k + rw [min_eq_right hk.le, EReal.toENNReal_of_nonpos (by simp), + EReal.toENNReal_of_nonpos (by simpa using hk0.trans hk.le)] + have h' (k : ℕ) : ((∫⁻ x, min (f x).toENNReal k ∂μ : ℝ≥0∞) : EReal) - + ((∫⁻ x, (-f x).toENNReal ∂μ : ℝ≥0∞) : EReal) ≤ D := by + have := h k + simp only [eintegral, hpos, hneg] at this + exact this + have hm (k : ℕ) : Measurable fun x ↦ min (f x).toENNReal (k : ℝ≥0∞) := + (measurable_ereal_toENNReal.comp hf).min measurable_const + have hmono' : Monotone fun (k : ℕ) x ↦ min (f x).toENNReal (k : ℝ≥0∞) := + fun k k' hkk' x ↦ min_le_min_left _ (by exact_mod_cast hkk') + have hsup : ∫⁻ x, (f x).toENNReal ∂μ = ⨆ k : ℕ, ∫⁻ x, min (f x).toENNReal k ∂μ := by + rw [← lintegral_iSup hm hmono'] + refine lintegral_congr fun x ↦ le_antisymm ?_ (iSup_le fun k ↦ min_le_left _ _) + by_cases hx : (f x).toENNReal = ∞ + · simp [hx, ENNReal.iSup_natCast] + · obtain ⟨k, hk⟩ := ENNReal.exists_nat_gt hx + exact le_iSup_of_le k (min_eq_left hk.le).ge + rw [eintegral, hsup] + set b := ∫⁻ x, (-f x).toENNReal ∂μ + by_cases hb : b = ∞ + · rw [hb, EReal.coe_ennreal_top, EReal.sub_top] + exact bot_le + have hb' : (b : EReal) ≠ ⊤ := by simpa using hb + have hb'' : (b : EReal) ≠ ⊥ := by simp + rw [EReal.sub_le_iff_le_add (.inl hb'') (.inl hb')] + have hk (k : ℕ) : ((∫⁻ x, min (f x).toENNReal k ∂μ : ℝ≥0∞) : EReal) ≤ D + b := + (EReal.sub_le_iff_le_add (.inl hb'') (.inl hb')).1 (h' k) + have hD : 0 ≤ D + b := (EReal.coe_ennreal_nonneg _).trans (hk 0) + rw [← EReal.coe_toENNReal hD] at hk ⊢ + exact EReal.coe_ennreal_le_coe_ennreal_iff.2 + (iSup_le fun k ↦ EReal.coe_ennreal_le_coe_ennreal_iff.1 (hk k)) + +end MeasureTheory diff --git a/LMLExplore/Probability/Process/Stopping.lean b/LMLExplore/Probability/Process/Stopping.lean index 21d153c7..83690e9f 100644 --- a/LMLExplore/Probability/Process/Stopping.lean +++ b/LMLExplore/Probability/Process/Stopping.lean @@ -7,6 +7,7 @@ module public import Mathlib.MeasureTheory.MeasurableSpace.Instances public import Mathlib.Probability.Process.Stopping +import Mathlib.MeasureTheory.Function.FactorsThrough /-! # Stopping times valued in `WithTop ℕ` and stopped adapted processes @@ -30,6 +31,11 @@ processes. `MeasureTheory.IsStoppingTime.measurableSet_natCast_lt`, `MeasureTheory.isStoppingTime_natCast`, `MeasureTheory.IsStoppingTime.min_natCast`: Mathlib's stopping-time API for `WithTop ℕ`-valued times, stated at the cast `(n : WithTop ℕ)` rather than the coercion `WithTop.some n`. +* `MeasureTheory.IsStoppingTime.measurable_nat`, `MeasureTheory.IsStoppingTime.natCast_min`: a + stopping time with values in `ℕ` is measurable, and so is its minimum with a constant a stopping + time. +* `MeasureTheory.IsStoppingTime.eq_of_forall_le`: a stopping time of the coordinate filtration + `Filtration.piLE` with values in `ℕ` is determined by the coordinates up to it. * `MeasureTheory.Adapted.stoppedProcess_of_discrete`: a stopped adapted process is adapted. -/ @@ -105,4 +111,40 @@ theorem IsStoppingTime.min_natCast (hτ : IsStoppingTime ℱ τ) (n : ℕ) : end NatCast +/-! ### Stopping times with values in `ℕ` -/ + +section Nat + +variable {ℱ : Filtration ℕ mΩ} {τ : Ω → ℕ} + +/-- A stopping time with values in `ℕ` is measurable. -/ +theorem IsStoppingTime.measurable_nat (hτ : IsStoppingTime ℱ fun ω ↦ (τ ω : WithTop ℕ)) : + Measurable τ := by + convert (measurable_of_countable (WithTop.untopD 0)).comp hτ.measurable' using 1 + exact funext fun ω ↦ (WithTop.untopD_coe 0 (τ ω)).symm + +/-- The minimum of a stopping time with values in `ℕ` and a constant is a stopping time. -/ +theorem IsStoppingTime.natCast_min (hτ : IsStoppingTime ℱ fun ω ↦ (τ ω : WithTop ℕ)) (n : ℕ) : + IsStoppingTime ℱ fun ω ↦ ((min (τ ω) n : ℕ) : WithTop ℕ) := by + have h : (fun ω ↦ ((min (τ ω) n : ℕ) : WithTop ℕ)) = fun ω ↦ min (τ ω : WithTop ℕ) n := + funext fun ω ↦ WithTop.coe_min _ _ + rw [h] + exact hτ.min_natCast n + +/-- A stopping time with values in `ℕ` of the coordinate filtration `Filtration.piLE` is +determined by the coordinates up to it: if `ω'` agrees with `ω` up to `τ ω`, then +`τ ω' = τ ω`. -/ +theorem IsStoppingTime.eq_of_forall_le {X : ℕ → Type*} [∀ i, MeasurableSpace (X i)] + {τ : (∀ i, X i) → ℕ} (hτ : IsStoppingTime Filtration.piLE fun ω ↦ (τ ω : WithTop ℕ)) + {ω ω' : ∀ i, X i} (h : ∀ i ≤ τ ω, ω i = ω' i) : τ ω' = τ ω := by + have hm : MeasurableSet[Filtration.piLE (τ ω)] {ω' | τ ω' = τ ω} := by + simpa using hτ.measurableSet_eq (τ ω) + have hd : DependsOn ({ω' | τ ω' = τ ω}.indicator fun _ ↦ (1 : ℕ)) (Set.Iic (τ ω)) := + (measurable_const.indicator hm).dependsOn_of_piLE + have h1 := hd fun i hi ↦ h i hi + by_contra hne + simp [Set.indicator, hne] at h1 + +end Nat + end MeasureTheory diff --git a/LMLExplore/Probability/ProductMeasure.lean b/LMLExplore/Probability/ProductMeasure.lean index c218f9e8..664b6333 100644 --- a/LMLExplore/Probability/ProductMeasure.lean +++ b/LMLExplore/Probability/ProductMeasure.lean @@ -7,13 +7,18 @@ module public import LMLExplore.MeasureTheory.MeasurableSpace.Constructions public import Mathlib.Probability.Independence.InfinitePi +public import TauCeti.Probability.Process.PathLaw.Shift +import LMLExplore.Probability.Process.StoppedValue +import Mathlib.Probability.Independence.Integration /-! # Infinite products of probability measures: the first terms and the next terms Under the infinite product `Measure.infinitePi` of copies of a probability measure `μ`, the first `n` coordinates have the product law `Measure.pi`, and they are independent of the next `m` -coordinates. +coordinates. The shift `(shift 𝓧)^[t]` by `t` coordinates (Tau Ceti's +`TauCeti.Probability.shift`) preserves the i.i.d. law, and the first `t` coordinates are +independent of the shifted sequence. ## Main statements @@ -21,6 +26,14 @@ coordinates. have the product law. * `MeasureTheory.Measure.infinitePi_fin_mem_and_forall_add_mem`: for an i.i.d. sequence, the first `n` terms and the next `m` terms are independent. +* `MeasureTheory.measurable_comp_shift_iterate`: a measurable function of the terms after a + measurable random number of them is measurable. +* `MeasureTheory.measurePreserving_shift_iterate`: the shift by `t` terms preserves the i.i.d. law. +* `MeasureTheory.indepFun_initSeg_shift_iterate`: the first `t` terms are independent of the + terms after them. +* `MeasureTheory.lintegral_mul_comp_shift_iterate`, `MeasureTheory.integral_mul_comp_shift_iterate`: + the expectation of the product of a function of the first `t` terms and a function of the terms + after them is the product of the expectations. -/ public section @@ -37,6 +50,76 @@ lemma measurePreserving_initSeg (P : Measure 𝓧) [IsProbabilityMeasure P] (n : rw [initSeg_def, ← Measure.infinitePi_eq_pi] exact Measure.map_infinitePi_infinitePi_of_inj Fin.val_injective +section Shift + +open ProbabilityTheory +open scoped ENNReal +open TauCeti.Probability (shift shift_iterate_eq_reindex measurable_shift_iterate) + +/-- A measurable function of the terms after a measurable random number `T` of them is +measurable. -/ +lemma measurable_comp_shift_iterate {β : Type*} [MeasurableSpace β] {h : (ℕ → 𝓧) → β} + (hh : Measurable h) {T : (ℕ → 𝓧) → ℕ} (hT : Measurable T) : + Measurable fun ω ↦ h ((shift 𝓧)^[T ω] ω) := + measurable_apply_of_countable (u := fun t ω ↦ h ((shift 𝓧)^[t] ω)) + (fun t ↦ hh.comp (measurable_shift_iterate t)) hT + +/-- The shift by `t` terms preserves the i.i.d. law. -/ +lemma measurePreserving_shift_iterate (P : Measure 𝓧) [IsProbabilityMeasure P] (t : ℕ) : + MeasurePreserving ((shift 𝓧)^[t]) (Measure.infinitePi fun _ : ℕ ↦ P) + (Measure.infinitePi fun _ : ℕ ↦ P) := by + refine ⟨measurable_shift_iterate t, ?_⟩ + rw [shift_iterate_eq_reindex] + exact Measure.map_infinitePi_infinitePi_of_inj (add_left_injective t) + +/-- Under an i.i.d. law, the first `t` terms are independent of the terms after them. -/ +lemma indepFun_initSeg_shift_iterate (P : Measure 𝓧) [IsProbabilityMeasure P] (t : ℕ) : + IndepFun (initSeg t) ((shift 𝓧)^[t]) (Measure.infinitePi fun _ : ℕ ↦ P) := by + have h := (iIndepFun_infinitePi (P := fun _ : ℕ ↦ P) (X := fun _ x ↦ x) + (fun _ ↦ measurable_id)).indepFun_set (Set.Iio t) (Set.Ici t) + (Set.disjoint_left.2 fun i (hi : i < t) (hi' : t ≤ i) ↦ (not_lt.2 hi') hi) + (fun i ↦ measurable_pi_apply i) + rw [shift_iterate_eq_reindex, initSeg_def] + exact h.comp (φ := fun (y : Set.Iio t → 𝓧) (i : Fin t) ↦ y ⟨i, i.2⟩) + (ψ := fun (y : Set.Ici t → 𝓧) (i : ℕ) ↦ y ⟨i + t, Nat.le_add_left t i⟩) + (by fun_prop) (by fun_prop) + +/-- Under an i.i.d. law, the expectation of the product of a function of the first `t` terms and +a function of the terms after them is the product of their expectations. -/ +lemma lintegral_mul_comp_shift_iterate (P : Measure 𝓧) [IsProbabilityMeasure P] + {f g : (ℕ → 𝓧) → ℝ≥0∞} {t : ℕ} (hf : Measurable f) (hft : DependsOn f (Set.Iio t)) + (hg : Measurable g) : + ∫⁻ ω, f ω * g ((shift 𝓧)^[t] ω) ∂Measure.infinitePi (fun _ : ℕ ↦ P) = + (∫⁻ ω, f ω ∂Measure.infinitePi (fun _ : ℕ ↦ P)) * + ∫⁻ ω, g ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) := by + have := nonempty_of_isProbabilityMeasure P + obtain ⟨F, hF, rfl⟩ := exists_measurable_eq_comp_initSeg hf hft + rw [← (measurePreserving_shift_iterate P t).lintegral_comp hg] + exact lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun (hF.comp (measurable_initSeg t)) + (hg.comp (measurable_shift_iterate t)) ((indepFun_initSeg_shift_iterate P t).comp hF hg) + +/-- Under an i.i.d. law, the expectation of the product of a real function of the first `t` terms +and a real function of the terms after them is the product of their expectations. -/ +lemma integral_mul_comp_shift_iterate (P : Measure 𝓧) [IsProbabilityMeasure P] + {f g : (ℕ → 𝓧) → ℝ} {t : ℕ} (hf : Measurable f) (hft : DependsOn f (Set.Iio t)) + (hg : Measurable g) : + ∫ ω, f ω * g ((shift 𝓧)^[t] ω) ∂Measure.infinitePi (fun _ : ℕ ↦ P) = + (∫ ω, f ω ∂Measure.infinitePi (fun _ : ℕ ↦ P)) * + ∫ ω, g ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) := by + have := nonempty_of_isProbabilityMeasure P + obtain ⟨F, hF, rfl⟩ := exists_measurable_eq_comp_initSeg hf hft + have hmap : ∫ ω, g ((shift 𝓧)^[t] ω) ∂Measure.infinitePi (fun _ : ℕ ↦ P) = + ∫ ω, g ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) := by + rw [← integral_map (measurable_shift_iterate t).aemeasurable + (by rw [(measurePreserving_shift_iterate P t).map_eq]; exact hg.aestronglyMeasurable), + (measurePreserving_shift_iterate P t).map_eq] + rw [← hmap] + exact ((indepFun_initSeg_shift_iterate P t).comp hF hg).integral_fun_mul_eq_mul_integral + (hF.comp (measurable_initSeg t)).aestronglyMeasurable + (hg.comp (measurable_shift_iterate t)).aestronglyMeasurable + +end Shift + end MeasureTheory namespace MeasureTheory.Measure From a861ea3115fde9eac514df527d146c30d8f9ad4b Mon Sep 17 00:00:00 2001 From: Remy Degenne Date: Sun, 15 Nov 2026 17:51:14 +0100 Subject: [PATCH 3/8] refactor: address review on the Wald inequality at the bipolar rate - Delete the thin wrapper measurable_comp_shift_iterate and use measurable_apply_of_countable at its uses. - Use IsStoppingTime.measurable_nat in Adapted.measurable_apply_stoppingTime. - Add Measure.infinitePi_of_not_isProbabilityMeasure instead of unfolding Measure.infinitePi. - Add integrable_truncLog_comp and a private integrable_natCast_of_le to remove the repeated bounded-integrability arguments. - Add truncLog_def and the simp lemmas truncLog_zero and truncLog_top. - Drop an unused import and make the shift import private in Round.lean. Co-Authored-By: Claude Code --- LMLExplore/EValues/BipolarRate/Round.lean | 75 ++++++++++--------- .../EValues/BipolarRate/StoppingTime.lean | 10 +-- .../Probability/Process/StoppedValue.lean | 4 +- LMLExplore/Probability/ProductMeasure.lean | 20 +++-- 4 files changed, 56 insertions(+), 53 deletions(-) diff --git a/LMLExplore/EValues/BipolarRate/Round.lean b/LMLExplore/EValues/BipolarRate/Round.lean index df03c1f4..826cb6b4 100644 --- a/LMLExplore/EValues/BipolarRate/Round.lean +++ b/LMLExplore/EValues/BipolarRate/Round.lean @@ -7,10 +7,11 @@ module public import LMLExplore.EValues.BipolarRate.Basic public import Mathlib.Probability.ProductMeasure -public import TauCeti.Probability.Process.PathLaw.Shift import LMLExplore.EValues.BipolarRate.EProcess import LMLExplore.Probability.ProductMeasure +import LMLExplore.Probability.Process.StoppedValue import Statlib.ForMathlib.MeasureTheory.Integral.EReal.Bochner +import TauCeti.Probability.Process.PathLaw.Shift /-! # The Wald inequality at the bipolar rate for a round @@ -153,14 +154,16 @@ private lemma measurable_restartTime (hσm : Measurable σ) (j : ℕ) : Measurable (restartTime σ j) := by induction j with | zero => exact measurable_const - | succ j ih => exact ih.add (measurable_comp_shift_iterate hσm ih) + | succ j ih => + exact ih.add (measurable_apply_of_countable (fun t ↦ hσm.comp (measurable_shift_iterate t)) ih) /-- The products of the payoffs of the restarted rounds are measurable. -/ private lemma measurable_restartPayoff (hσm : Measurable σ) (hVm : Measurable V) (j : ℕ) : Measurable (restartPayoff σ V j) := by induction j with | zero => exact measurable_const - | succ j ih => exact ih.mul (measurable_comp_shift_iterate hVm (measurable_restartTime hσm j)) + | succ j ih => exact ih.mul (measurable_apply_of_countable + (fun t ↦ hVm.comp (measurable_shift_iterate t)) (measurable_restartTime hσm j)) /-- If two sequences of observations agree on the first `t`, their shifts by `s` agree on the first `t - s`. -/ @@ -497,6 +500,10 @@ end Restart /-- The logarithm truncated above at `c`, as a real number. -/ noncomputable def truncLog (c : ℝ) (x : ℝ≥0∞) : ℝ := (min (ENNReal.log x) c).toReal +/-- The definition of the truncated logarithm, `truncLog c x = (min (log x) c).toReal`. -/ +lemma truncLog_def (c : ℝ) (x : ℝ≥0∞) : truncLog c x = (min (ENNReal.log x) c).toReal := by + rw [truncLog] + /-- The truncated logarithm is measurable. -/ lemma measurable_truncLog (c : ℝ) : Measurable (truncLog c) := measurable_ereal_toReal.comp (ENNReal.measurable_log.min measurable_const) @@ -508,8 +515,13 @@ lemma truncLog_of_ne {c : ℝ} {x : ℝ≥0∞} (h0 : x ≠ 0) (htop : x ≠ ∞ EReal.toReal_coe] /-- The truncated logarithm of `∞` is the truncation level. -/ +@[simp] lemma truncLog_top (c : ℝ) : truncLog c ∞ = c := by simp [truncLog] +/-- The truncated logarithm of `0` is `0`, the real part of `⊥ = log 0`. -/ +@[simp] +lemma truncLog_zero (c : ℝ) : truncLog c 0 = 0 := by simp [truncLog] + /-- The truncated logarithm is at most the truncation level. -/ lemma truncLog_le {c : ℝ} {x : ℝ≥0∞} (h0 : x ≠ 0) : truncLog c x ≤ c := by by_cases htop : x = ∞ @@ -533,6 +545,16 @@ lemma abs_truncLog_le {c δ : ℝ} (hδ : 0 < δ) {x : ℝ≥0∞} (hx : ENNReal abs_le_max_abs_abs (log_le_truncLog hδ hx hc) (truncLog_le (lt_of_lt_of_le (ENNReal.ofReal_pos.2 hδ) hx).ne') +/-- The truncated logarithm of a measurable function bounded below by `δ > 0` is integrable +under a finite measure. -/ +lemma integrable_truncLog_comp {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + [IsFiniteMeasure μ] {c δ : ℝ} (hδ : 0 < δ) {V : Ω → ℝ≥0∞} (hVm : Measurable V) + (hVδ : ∀ ω, ENNReal.ofReal δ ≤ V ω) (hc : Real.log δ ≤ c) : + Integrable (fun ω ↦ truncLog c (V ω)) μ := + Integrable.of_bound ((measurable_truncLog c).comp hVm).aestronglyMeasurable + (max |Real.log δ| |c|) (ae_of_all _ fun ω ↦ (Real.norm_eq_abs _).trans_le + (abs_truncLog_le hδ (hVδ ω) hc)) + /-- The exponential of the truncated logarithm of `x` is at most `x`. -/ lemma ofReal_exp_truncLog_le {c : ℝ} {x : ℝ≥0∞} (h0 : x ≠ 0) : ENNReal.ofReal (Real.exp (truncLog c x)) ≤ x := by @@ -582,6 +604,13 @@ section Wald variable {σ : (ℕ → 𝓧) → ℕ} {V : (ℕ → 𝓧) → ℝ≥0∞} +/-- A measurable bounded duration is integrable, as a real function, under a finite measure. -/ +private lemma integrable_natCast_of_le {μ : Measure (ℕ → 𝓧)} [IsFiniteMeasure μ] + {τ : (ℕ → 𝓧) → ℕ} (hτm : Measurable τ) {K : ℕ} (hτK : ∀ ω, τ ω ≤ K) : + Integrable (fun ω ↦ (τ ω : ℝ)) μ := + Integrable.of_bound (measurable_from_top.comp hτm).aestronglyMeasurable K + (ae_of_all _ fun ω ↦ by simpa using hτK ω) + /-- The logarithm of the mixture of restarted rounds is at least the logarithm of the weight of the completed rounds plus their truncated log-payoffs, hence at least the sum of the truncated log-payoffs of the rounds that start within the first `N` observations, up to `c` for the last @@ -700,18 +729,11 @@ private lemma add_one_le_integral_mul_sum_measureReal (hσ : DependsOnBefore σ rw [abs_of_nonneg (Nat.cast_nonneg _)] exact_mod_cast hσK ω have hT (i : ℕ) : Measurable (restartTime σ i) := measurable_restartTime hσm i - have hgm (i : ℕ) : Measurable fun ω ↦ {ω | restartTime σ i ω ≤ N}.indicator - (fun ω ↦ (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ)) ω := - (measurable_comp_shift_iterate hσm' (hT i)).indicator (hT i measurableSet_Iic) have hgi (i : ℕ) : Integrable (fun ω ↦ {ω | restartTime σ i ω ≤ N}.indicator - (fun ω ↦ (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ)) ω) μ := by - refine Integrable.of_bound (hgm i).aestronglyMeasurable K (ae_of_all _ fun ω ↦ ?_) - rw [Real.norm_eq_abs] - by_cases h : restartTime σ i ω ≤ N - · rw [Set.indicator_of_mem h] - exact hσC _ - · rw [Set.indicator_of_notMem h, abs_zero] - exact Nat.cast_nonneg _ + (fun ω ↦ (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ)) ω) μ := + (integrable_natCast_of_le (measurable_apply_of_countable + (fun t ↦ hσm.comp (measurable_shift_iterate t)) (hT i)) fun _ ↦ hσK _).indicator + (hT i measurableSet_Iic) calc (N + 1 : ℝ) = ∫ _, (N + 1 : ℝ) ∂μ := by simp _ ≤ ∫ ω, ∑ i ∈ Finset.range (N + 1), {ω | restartTime σ i ω ≤ N}.indicator (fun ω ↦ (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ)) ω ∂μ := @@ -744,24 +766,14 @@ private lemma add_integral_truncLog_mul_sum_measureReal_le (Q₁ : Measure 𝓧) N * (bipolarRate Q₁ S₁).toReal := by set μ := Measure.infinitePi (fun _ : ℕ ↦ Q₁) set A := ∫ ω, truncLog c (V ω) ∂μ - -- the truncated log-payoffs are bounded - set C := max |Real.log δ| |c| have hYm : Measurable fun ω ↦ truncLog c (V ω) := (measurable_truncLog c).comp hVm have hT (i : ℕ) : Measurable (restartTime σ i) := measurable_restartTime hσm i - have hfm (i : ℕ) : Measurable fun ω ↦ {ω | restartTime σ i ω ≤ N}.indicator - (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω := - (measurable_comp_shift_iterate hYm (hT i)).indicator (hT i measurableSet_Iic) - have hfC (i : ℕ) (ω : ℕ → 𝓧) : |{ω | restartTime σ i ω ≤ N}.indicator - (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω| ≤ C := by - by_cases h : restartTime σ i ω ≤ N - · rw [Set.indicator_of_mem h] - exact abs_truncLog_le hδ (hVδ _) hc - · rw [Set.indicator_of_notMem h, abs_zero] - exact (abs_nonneg _).trans (le_max_left _ _) + -- the truncated log-payoffs are bounded, hence integrable have hfi (i : ℕ) : Integrable (fun ω ↦ {ω | restartTime σ i ω ≤ N}.indicator (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω) μ := - Integrable.of_bound (hfm i).aestronglyMeasurable C - (ae_of_all _ fun ω ↦ (Real.norm_eq_abs _).trans_le (hfC i ω)) + (integrable_truncLog_comp hδ (measurable_apply_of_countable + (fun t ↦ hVm.comp (measurable_shift_iterate t)) (hT i)) (fun _ ↦ hVδ _) hc).indicator + (hT i measurableSet_Iic) set B := Real.log (1 - r) + N * Real.log r - c have hsum : Integrable (fun ω ↦ ∑ i ∈ Finset.range (N + 1), {ω | restartTime σ i ω ≤ N}.indicator @@ -815,14 +827,9 @@ lemma integral_truncLog_le_bipolarRate_mul (Q₁ : Measure 𝓧) [IsProbabilityM set μ := Measure.infinitePi (fun _ : ℕ ↦ Q₁) set m := ∫ ω, (σ ω : ℝ) ∂μ have hd0 := bipolarRate_nonneg Q₁ S₁ - have hσm' : Measurable fun ω ↦ (σ ω : ℝ) := measurable_from_top.comp hσm - have hσC (ω : ℕ → 𝓧) : |(σ ω : ℝ)| ≤ K := by - rw [abs_of_nonneg (Nat.cast_nonneg _)] - exact_mod_cast hσK ω have hm1 : 1 ≤ m := by calc (1 : ℝ) = ∫ _, (1 : ℝ) ∂μ := by simp - _ ≤ m := integral_mono (integrable_const _) - (Integrable.of_bound hσm'.aestronglyMeasurable K (ae_of_all _ fun ω ↦ hσC ω)) + _ ≤ m := integral_mono (integrable_const _) (integrable_natCast_of_le hσm hσK) fun ω ↦ by exact_mod_cast hσ1 ω refine le_mul_of_forall_restart (c := c) (by linarith) (EReal.toReal_nonneg hd0) fun r hr0 hr1 N hN ↦ ⟨_, add_one_le_integral_mul_sum_measureReal hσ hσm hσ1 hσK Q₁ N, diff --git a/LMLExplore/EValues/BipolarRate/StoppingTime.lean b/LMLExplore/EValues/BipolarRate/StoppingTime.lean index 6dcd4bd6..d933a19b 100644 --- a/LMLExplore/EValues/BipolarRate/StoppingTime.lean +++ b/LMLExplore/EValues/BipolarRate/StoppingTime.lean @@ -10,8 +10,8 @@ public import LMLExplore.EValues.EProcess public import Mathlib.Probability.ProductMeasure import LMLExplore.EValues.BipolarRate.Round import LMLExplore.MeasureTheory.Integral.EReal +import LMLExplore.Probability.ProductMeasure import LMLExplore.Probability.Process.Stopping -import LMLExplore.Probability.Process.StoppedValue import Statlib.ForMathlib.MeasureTheory.Integral.EReal.Bochner /-! @@ -210,10 +210,8 @@ private lemma eintegral_log_stoppedValue_le_toReal_mul (Q₁ : Measure 𝓧) [Is set W : (ℕ → 𝓧) → ℝ≥0∞ := fun ω ↦ ENNReal.ofReal (1 - ε) * E (τ ω) ω + ENNReal.ofReal ε have hc : Real.log ε ≤ k := (Real.log_neg hε0 hε1).le.trans (Nat.cast_nonneg k) have hYi : Integrable (fun ω ↦ truncLog k (W ω)) μ := - Integrable.of_bound ((measurable_truncLog _).comp - ((measurable_const.mul hEτm).add measurable_const)).aestronglyMeasurable - (max |Real.log ε| |(k : ℝ)|) (ae_of_all _ fun ω ↦ (Real.norm_eq_abs _).trans_le - (abs_truncLog_le hε0 le_add_self hc)) + integrable_truncLog_comp hε0 ((measurable_const.mul hEτm).add measurable_const) + (fun _ ↦ le_add_self) hc calc ∫ᵉ ω, min (ENNReal.log (E (τ ω) ω)) k ∂μ _ ≤ ∫ᵉ ω, ((truncLog k (W ω) - Real.log (1 - ε) : ℝ) : EReal) ∂μ := eintegral_mono fun ω ↦ by simpa using min_log_le_truncLog_sub hε0 hε1 k (E (τ ω) ω) @@ -248,7 +246,7 @@ theorem IsEProcess.eintegral_log_stoppedValue_le_mul_bipolarRate (Q₁ : Measure bipolarRate Q₁ S₁ := by by_cases hQ : IsProbabilityMeasure Q₁ swap - · simp [Measure.infinitePi, hQ] + · simp [Measure.infinitePi_of_not_isProbabilityMeasure (μ := fun _ : ℕ ↦ Q₁) fun h ↦ hQ (h 0)] set m := ∫⁻ ω, (τ ω : ℝ≥0∞) + 1 ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁) have hm0 : (0 : EReal) < m := by have : (1 : ℝ≥0∞) ≤ m := diff --git a/LMLExplore/Probability/Process/StoppedValue.lean b/LMLExplore/Probability/Process/StoppedValue.lean index a6ecf1c4..85896b25 100644 --- a/LMLExplore/Probability/Process/StoppedValue.lean +++ b/LMLExplore/Probability/Process/StoppedValue.lean @@ -8,6 +8,7 @@ module public import Mathlib.MeasureTheory.Constructions.BorelSpace.Order public import Mathlib.MeasureTheory.Integral.Lebesgue.Add public import Mathlib.Probability.Process.Stopping +import LMLExplore.Probability.Process.Stopping /-! # The value of a process at a possibly infinite time @@ -223,7 +224,6 @@ theorem Adapted.measurable_apply_stoppingTime [MeasurableSpace β] {mΩ : MeasurableSpace Ω} {ℱ : Filtration ℕ mΩ} {u : ℕ → Ω → β} {σ : Ω → ℕ} (hu : Adapted ℱ u) (hσ : IsStoppingTime ℱ (fun ω ↦ (σ ω : WithTop ℕ))) : Measurable fun ω ↦ u (σ ω) ω := - measurable_apply_of_countable (fun _ ↦ hu.measurable) - ((measurable_of_countable (WithTop.untopD 0)).comp hσ.measurable') + measurable_apply_of_countable (fun _ ↦ hu.measurable) hσ.measurable_nat end MeasureTheory diff --git a/LMLExplore/Probability/ProductMeasure.lean b/LMLExplore/Probability/ProductMeasure.lean index 9542f96b..f6dfa2c5 100644 --- a/LMLExplore/Probability/ProductMeasure.lean +++ b/LMLExplore/Probability/ProductMeasure.lean @@ -11,7 +11,6 @@ public import Mathlib.Probability.Process.Filtration public import TauCeti.Probability.Process.PathLaw.Shift import LMLExplore.MeasureTheory.Constructions.Pi import LMLExplore.MeasureTheory.Measure.Typeclasses.Probability -import LMLExplore.Probability.Process.StoppedValue import Mathlib.MeasureTheory.Function.FactorsThrough import Mathlib.Probability.Independence.Integration @@ -33,12 +32,12 @@ the polarization step of [EVR26, Note 03, Theorem 1], adapted from ## Main statements +* `MeasureTheory.Measure.infinitePi_of_not_isProbabilityMeasure`: the infinite product of a family + of measures that are not all probability measures is `0`. * `MeasureTheory.measurePreserving_initSeg`: the first `n` terms `initSeg n` of an i.i.d. sequence have the product law. * `MeasureTheory.Measure.infinitePi_fin_mem_and_forall_add_mem`: for an i.i.d. sequence, the first `n` terms and the next `m` terms are independent. -* `MeasureTheory.measurable_comp_shift_iterate`: a measurable function of the terms after a - measurable random number of them is measurable. * `MeasureTheory.measurePreserving_shift_iterate`: the shift by `t` terms preserves the i.i.d. law. * `MeasureTheory.indepFun_initSeg_shift_iterate`: the first `t` terms are independent of the terms after them. @@ -63,6 +62,13 @@ namespace MeasureTheory variable {𝓧 : Type*} {m𝓧 : MeasurableSpace 𝓧} +/-- The infinite product `Measure.infinitePi μ` is `0` unless every `μ i` is a probability +measure. -/ +lemma Measure.infinitePi_of_not_isProbabilityMeasure {ι : Type*} {X : ι → Type*} + [∀ i, MeasurableSpace (X i)] {μ : (i : ι) → Measure (X i)} + (h : ¬ ∀ i, IsProbabilityMeasure (μ i)) : Measure.infinitePi μ = 0 := + dite_eq_right h + /-- The first `n` terms of an i.i.d. sequence have the product law. -/ lemma measurePreserving_initSeg (P : Measure 𝓧) [IsProbabilityMeasure P] (n : ℕ) : MeasurePreserving (initSeg n) (Measure.infinitePi fun _ : ℕ ↦ P) @@ -77,14 +83,6 @@ open ProbabilityTheory open scoped ENNReal open TauCeti.Probability (shift shift_iterate_eq_reindex measurable_shift_iterate) -/-- A measurable function of the terms after a measurable random number `T` of them is -measurable. -/ -lemma measurable_comp_shift_iterate {β : Type*} [MeasurableSpace β] {h : (ℕ → 𝓧) → β} - (hh : Measurable h) {T : (ℕ → 𝓧) → ℕ} (hT : Measurable T) : - Measurable fun ω ↦ h ((shift 𝓧)^[T ω] ω) := - measurable_apply_of_countable (u := fun t ω ↦ h ((shift 𝓧)^[t] ω)) - (fun t ↦ hh.comp (measurable_shift_iterate t)) hT - /-- The shift by `t` terms preserves the i.i.d. law. -/ lemma measurePreserving_shift_iterate (P : Measure 𝓧) [IsProbabilityMeasure P] (t : ℕ) : MeasurePreserving ((shift 𝓧)^[t]) (Measure.infinitePi fun _ : ℕ ↦ P) From 54afa212ddabec24fd1bc5fffa425fc6728ba2cb Mon Sep 17 00:00:00 2001 From: Remy Degenne Date: Sun, 15 Nov 2026 19:47:24 +0100 Subject: [PATCH 4/8] refactor: export dependsOn_indicator_of_eqOn and shift_iterate_eqOn Move the two general helpers out of the private part of Round.lean: dependsOn_indicator_of_eqOn, generalised to any Pi type and coordinate set, goes to the new LMLExplore/Logic/Function/DependsOn.lean, and MeasureTheory.shift_iterate_eqOn goes to LMLExplore/Probability/ProductMeasure.lean next to the other shift lemmas. Co-Authored-By: Claude Code --- LMLExplore/EValues/BipolarRate/Round.lean | 21 +------------- LMLExplore/Logic/Function/DependsOn.lean | 33 ++++++++++++++++++++++ LMLExplore/Probability/ProductMeasure.lean | 13 ++++++++- 3 files changed, 46 insertions(+), 21 deletions(-) create mode 100644 LMLExplore/Logic/Function/DependsOn.lean diff --git a/LMLExplore/EValues/BipolarRate/Round.lean b/LMLExplore/EValues/BipolarRate/Round.lean index 826cb6b4..e8a13385 100644 --- a/LMLExplore/EValues/BipolarRate/Round.lean +++ b/LMLExplore/EValues/BipolarRate/Round.lean @@ -8,6 +8,7 @@ module public import LMLExplore.EValues.BipolarRate.Basic public import Mathlib.Probability.ProductMeasure import LMLExplore.EValues.BipolarRate.EProcess +import LMLExplore.Logic.Function.DependsOn import LMLExplore.Probability.ProductMeasure import LMLExplore.Probability.Process.StoppedValue import Statlib.ForMathlib.MeasureTheory.Integral.EReal.Bochner @@ -165,13 +166,6 @@ private lemma measurable_restartPayoff (hσm : Measurable σ) (hVm : Measurable | succ j ih => exact ih.mul (measurable_apply_of_countable (fun t ↦ hVm.comp (measurable_shift_iterate t)) (measurable_restartTime hσm j)) -/-- If two sequences of observations agree on the first `t`, their shifts by `s` agree on the -first `t - s`. -/ -private lemma shift_iterate_eqOn {t : ℕ} {ω ω' : ℕ → 𝓧} (h : ∀ i < t, ω i = ω' i) (s : ℕ) : - ∀ i < t - s, (shift 𝓧)^[s] ω i = (shift 𝓧)^[s] ω' i := fun i hi ↦ by - simp only [shift_iterate_apply] - exact h _ (by omega) - /-- The first `j` rounds are determined by the observations that they use. -/ private lemma restartTime_eq_of_eqOn (hσ : DependsOnBefore σ σ) (j : ℕ) {t : ℕ} {ω ω' : ℕ → 𝓧} (h : ∀ i < t, ω i = ω' i) (hj : restartTime σ j ω ≤ t) : @@ -211,19 +205,6 @@ private lemma restartTime_le_iff_of_eqOn (hσ : DependsOnBefore σ σ) (j N : ⟨fun h' ↦ (restartTime_eq_of_eqOn hσ j (fun i hi ↦ (h i hi).symm) h') ▸ h', fun h' ↦ (restartTime_eq_of_eqOn hσ j h h').symm ▸ h'⟩ -/-- The indicator of an event determined by the first `t` observations, applied to a function -determined by them on that event, is a function of the first `t` observations. -/ -private lemma dependsOn_indicator_of_eqOn {β : Type*} [Zero β] {A : Set (ℕ → 𝓧)} - {f : (ℕ → 𝓧) → β} {t : ℕ} - (hA : ∀ ⦃ω ω' : ℕ → 𝓧⦄, (∀ i < t, ω i = ω' i) → (ω' ∈ A ↔ ω ∈ A)) - (hf : ∀ ⦃ω ω' : ℕ → 𝓧⦄, (∀ i < t, ω i = ω' i) → ω ∈ A → f ω' = f ω) : - DependsOn (A.indicator f) (Set.Iio t) := by - intro ω ω' h - have h' : ∀ i < t, ω i = ω' i := fun i hi ↦ h i hi - by_cases hω : ω ∈ A - · rw [Set.indicator_of_mem hω, Set.indicator_of_mem ((hA h').2 hω), hf h' hω] - · rw [Set.indicator_of_notMem hω, Set.indicator_of_notMem (mt (hA h').1 hω)] - /-- On the event that the first `j` rounds use `t` observations, their payoff is a function of the first `t` observations. -/ private lemma dependsOn_indicator_restartTime_eq (hσ : DependsOnBefore σ σ) diff --git a/LMLExplore/Logic/Function/DependsOn.lean b/LMLExplore/Logic/Function/DependsOn.lean new file mode 100644 index 00000000..abb68782 --- /dev/null +++ b/LMLExplore/Logic/Function/DependsOn.lean @@ -0,0 +1,33 @@ +/- +Copyright (c) 2026 LMLExplore contributors. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: LMLExplore contributors +-/ +module + +public import Mathlib.Algebra.Group.Indicator +public import Mathlib.Logic.Function.DependsOn + +/-! +# Indicators of functions that depend on a set of coordinates + +## Main statements + +* `dependsOn_indicator_of_eqOn`: if membership in `A` and, on `A`, the function `f` are + determined by the coordinates in `s`, then so is the indicator `A.indicator f`. +-/ + +public section + +variable {ι : Type*} {α : ι → Type*} {β : Type*} + +/-- If membership in `A` is determined by the coordinates in `s`, and so is `f` on `A`, then the +indicator `A.indicator f` only depends on the coordinates in `s`. -/ +lemma dependsOn_indicator_of_eqOn [Zero β] {A : Set (Π i, α i)} {f : (Π i, α i) → β} + {s : Set ι} (hA : ∀ ⦃x y : Π i, α i⦄, (∀ i ∈ s, x i = y i) → (y ∈ A ↔ x ∈ A)) + (hf : ∀ ⦃x y : Π i, α i⦄, (∀ i ∈ s, x i = y i) → x ∈ A → f y = f x) : + DependsOn (A.indicator f) s := by + intro x y h + by_cases hx : x ∈ A + · rw [Set.indicator_of_mem hx, Set.indicator_of_mem ((hA h).2 hx), hf h hx] + · rw [Set.indicator_of_notMem hx, Set.indicator_of_notMem (mt (hA h).1 hx)] diff --git a/LMLExplore/Probability/ProductMeasure.lean b/LMLExplore/Probability/ProductMeasure.lean index af0adb30..61cde0a9 100644 --- a/LMLExplore/Probability/ProductMeasure.lean +++ b/LMLExplore/Probability/ProductMeasure.lean @@ -13,6 +13,7 @@ import LMLExplore.MeasureTheory.Constructions.Pi import LMLExplore.MeasureTheory.Measure.Typeclasses.Probability import Mathlib.MeasureTheory.Function.FactorsThrough import Mathlib.Probability.Independence.Integration +import TauCeti.Probability.Process.PathLaw.Shift /-! # Infinite products of probability measures: coordinatewise properties, first and next terms @@ -41,6 +42,8 @@ the polarization step of [EVR26, Note 03, Theorem 1], adapted from first `n` terms and the next `m` terms are independent. * `MeasureTheory.measurePreserving_shift`, `MeasureTheory.measurePreserving_shift_iterate`: the shift and its iterates preserve the i.i.d. law. +* `MeasureTheory.shift_iterate_eqOn`: two sequences that agree on the first `t` terms have shifts + by `s` that agree on the first `t - s` terms. * `MeasureTheory.indepFun_initSeg_shift_iterate`: the first `t` terms are independent of the terms after them. * `MeasureTheory.lintegral_mul_comp_shift_iterate`, `MeasureTheory.integral_mul_comp_shift_iterate`: @@ -77,7 +80,15 @@ lemma measurePreserving_initSeg (P : Measure 𝓧) [IsProbabilityMeasure P] (n : exact Measure.map_infinitePi_infinitePi_of_inj Fin.val_injective open ProbabilityTheory -open TauCeti.Probability (shift shift_iterate_eq_reindex measurable_shift_iterate) +open TauCeti.Probability (shift shift_iterate_apply shift_iterate_eq_reindex + measurable_shift_iterate) + +/-- If two sequences agree on the first `t` terms, their shifts by `s` agree on the first `t - s` +terms. -/ +lemma shift_iterate_eqOn {t : ℕ} {ω ω' : ℕ → 𝓧} (h : ∀ i < t, ω i = ω' i) (s : ℕ) : + ∀ i < t - s, (shift 𝓧)^[s] ω i = (shift 𝓧)^[s] ω' i := fun i hi ↦ by + simp only [shift_iterate_apply] + exact h _ (by omega) /-- The shift preserves the i.i.d. law. -/ lemma measurePreserving_shift (P : Measure 𝓧) [IsProbabilityMeasure P] : From 4eada51b33d8e3864bd877c98a3b751ecfc28cdf Mon Sep 17 00:00:00 2001 From: Remy Degenne Date: Sun, 15 Nov 2026 20:27:19 +0100 Subject: [PATCH 5/8] refactor: move truncLog to a generic file and factor two helpers - Move `truncLog` and its lemmas from `EValues/BipolarRate/Round.lean` to the new `LMLExplore/Analysis/SpecialFunctions/Log/TruncLog.lean`, as `ENNReal.truncLog` and `ENNReal.*`. - Add `IsStoppingTime.toNat_min` and `ENat.natCast_toNat_min` to `Probability/Process/Stopping.lean` and use them in `StoppingTime.lean`. - Factor the sum reindexing over completed rounds into the private `sum_range_indicator_restartTime_le`, used in two places. Co-Authored-By: Claude Code --- .../SpecialFunctions/Log/TruncLog.lean | 144 ++++++++++++++++ LMLExplore/EValues/BipolarRate/Round.lean | 163 +++--------------- .../EValues/BipolarRate/StoppingTime.lean | 17 +- LMLExplore/Probability/Process/Stopping.lean | 16 ++ 4 files changed, 197 insertions(+), 143 deletions(-) create mode 100644 LMLExplore/Analysis/SpecialFunctions/Log/TruncLog.lean diff --git a/LMLExplore/Analysis/SpecialFunctions/Log/TruncLog.lean b/LMLExplore/Analysis/SpecialFunctions/Log/TruncLog.lean new file mode 100644 index 00000000..c44ca32a --- /dev/null +++ b/LMLExplore/Analysis/SpecialFunctions/Log/TruncLog.lean @@ -0,0 +1,144 @@ +/- +Copyright (c) 2026 LMLExplore contributors. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: LMLExplore contributors +-/ +module + +public import Mathlib.Analysis.SpecialFunctions.Log.ENNRealLogExp +public import Mathlib.MeasureTheory.Constructions.BorelSpace.Real +public import Mathlib.MeasureTheory.Integral.IntegrableOn + +/-! +# The truncated logarithm of an extended nonnegative real + +`ENNReal.truncLog c x` is the logarithm `ENNReal.log x` of `x : ℝ≥0∞` truncated above at `c : ℝ`, +as a real number: `(min (log x) c).toReal`. It is `c` at `∞` and `0` at `0` (the real part of +`log 0 = ⊥`), and `min (Real.log x.toReal) c` otherwise. Unlike `ENNReal.log`, it is a real +function, bounded on `{x | δ ≤ x}` for `δ > 0`, hence integrable under a finite measure when +composed with a measurable function bounded below by `δ`. + +## Main definitions + +* `ENNReal.truncLog c x`: the logarithm of `x : ℝ≥0∞` truncated above at `c`, as a real number. + +## Main statements + +* `ENNReal.truncLog_of_ne`: `truncLog c x = min (Real.log x.toReal) c` for `x ≠ 0, ∞`. +* `ENNReal.abs_truncLog_le`, `ENNReal.integrable_truncLog_comp`: on `{x | δ ≤ x}`, the truncated + logarithm is bounded, hence integrable under a finite measure. +* `ENNReal.ofReal_exp_truncLog_le`: `exp (truncLog c x) ≤ x`. +* `ENNReal.min_log_le_truncLog_sub`: mixing `x` with a constant `ε` costs at most `- log (1 - ε)` + in truncated logarithm. +-/ + +public section + +open MeasureTheory + +open scoped ENNReal + +namespace ENNReal + +/-- The logarithm truncated above at `c`, as a real number. -/ +noncomputable def truncLog (c : ℝ) (x : ℝ≥0∞) : ℝ := (min (ENNReal.log x) c).toReal + +/-- The definition of the truncated logarithm, `truncLog c x = (min (log x) c).toReal`. -/ +lemma truncLog_def (c : ℝ) (x : ℝ≥0∞) : truncLog c x = (min (ENNReal.log x) c).toReal := by + rw [truncLog] + +/-- The truncated logarithm is measurable. -/ +lemma measurable_truncLog (c : ℝ) : Measurable (truncLog c) := + measurable_ereal_toReal.comp (ENNReal.measurable_log.min measurable_const) + +/-- The truncated logarithm of a positive finite number. -/ +lemma truncLog_of_ne {c : ℝ} {x : ℝ≥0∞} (h0 : x ≠ 0) (htop : x ≠ ∞) : + truncLog c x = min (Real.log x.toReal) c := by + rw [truncLog, ENNReal.log_pos_real h0 htop, ← EReal.coe_strictMono.monotone.map_min, + EReal.toReal_coe] + +/-- The truncated logarithm of `∞` is the truncation level. -/ +@[simp] +lemma truncLog_top (c : ℝ) : truncLog c ∞ = c := by simp [truncLog] + +/-- The truncated logarithm of `0` is `0`, the real part of `⊥ = log 0`. -/ +@[simp] +lemma truncLog_zero (c : ℝ) : truncLog c 0 = 0 := by simp [truncLog] + +/-- The truncated logarithm is at most the truncation level. -/ +lemma truncLog_le {c : ℝ} {x : ℝ≥0∞} (h0 : x ≠ 0) : truncLog c x ≤ c := by + by_cases htop : x = ∞ + · rw [htop, truncLog_top] + · rw [truncLog_of_ne h0 htop] + exact min_le_right _ _ + +/-- The truncated logarithm of `x ≥ δ` is at least `log δ`, if `log δ ≤ c`. -/ +lemma log_le_truncLog {c δ : ℝ} (hδ : 0 < δ) {x : ℝ≥0∞} (hx : ENNReal.ofReal δ ≤ x) + (hc : Real.log δ ≤ c) : Real.log δ ≤ truncLog c x := by + have h0 : x ≠ 0 := (lt_of_lt_of_le (ENNReal.ofReal_pos.2 hδ) hx).ne' + by_cases htop : x = ∞ + · rw [htop, truncLog_top] + exact hc + · rw [truncLog_of_ne h0 htop] + exact le_min (Real.log_le_log hδ ((ENNReal.ofReal_le_iff_le_toReal htop).1 hx)) hc + +/-- The truncated logarithm of `x ≥ δ` is bounded in absolute value, if `log δ ≤ c`. -/ +lemma abs_truncLog_le {c δ : ℝ} (hδ : 0 < δ) {x : ℝ≥0∞} (hx : ENNReal.ofReal δ ≤ x) + (hc : Real.log δ ≤ c) : |truncLog c x| ≤ max |Real.log δ| |c| := + abs_le_max_abs_abs (log_le_truncLog hδ hx hc) + (truncLog_le (lt_of_lt_of_le (ENNReal.ofReal_pos.2 hδ) hx).ne') + +/-- The truncated logarithm of a measurable function bounded below by `δ > 0` is integrable +under a finite measure. -/ +lemma integrable_truncLog_comp {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + [IsFiniteMeasure μ] {c δ : ℝ} (hδ : 0 < δ) {V : Ω → ℝ≥0∞} (hVm : Measurable V) + (hVδ : ∀ ω, ENNReal.ofReal δ ≤ V ω) (hc : Real.log δ ≤ c) : + Integrable (fun ω ↦ truncLog c (V ω)) μ := + Integrable.of_bound ((measurable_truncLog c).comp hVm).aestronglyMeasurable + (max |Real.log δ| |c|) (ae_of_all _ fun ω ↦ (Real.norm_eq_abs _).trans_le + (abs_truncLog_le hδ (hVδ ω) hc)) + +/-- The exponential of the truncated logarithm of `x` is at most `x`. -/ +lemma ofReal_exp_truncLog_le {c : ℝ} {x : ℝ≥0∞} (h0 : x ≠ 0) : + ENNReal.ofReal (Real.exp (truncLog c x)) ≤ x := by + by_cases htop : x = ∞ + · rw [htop] + exact le_top + · rw [truncLog_of_ne h0 htop] + calc ENNReal.ofReal (Real.exp (min (Real.log x.toReal) c)) + _ ≤ ENNReal.ofReal (Real.exp (Real.log x.toReal)) := + ENNReal.ofReal_le_ofReal (Real.exp_le_exp.2 (min_le_left _ _)) + _ = x := by + rw [Real.exp_log (ENNReal.toReal_pos h0 htop), ENNReal.ofReal_toReal htop] + +/-- Mixing with a constant: `min (log x) c ≤ truncLog c ((1 - ε) x + ε) - log (1 - ε)`. -/ +lemma min_log_le_truncLog_sub {ε : ℝ} (hε0 : 0 < ε) (hε1 : ε < 1) (c : ℝ) (x : ℝ≥0∞) : + min (ENNReal.log x) c ≤ + ((truncLog c (ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε) - Real.log (1 - ε) : ℝ) : + EReal) := by + have hlog : Real.log (1 - ε) ≤ 0 := Real.log_nonpos (by linarith) (by linarith) + by_cases h0 : x = 0 + · simp [h0] + by_cases htop : x = ∞ + · have : ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε = ∞ := by + rw [htop, ENNReal.mul_top (ENNReal.ofReal_pos.2 (by linarith)).ne', top_add] + rw [this, truncLog_top] + exact (min_le_right _ _).trans (EReal.coe_le_coe_iff.2 (by linarith)) + have hε' : ENNReal.ofReal ε ≠ 0 := (ENNReal.ofReal_pos.2 hε0).ne' + have hV0 : ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε ≠ 0 := by simp [hε'] + have hVtop : ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε ≠ ∞ := + ENNReal.add_ne_top.2 ⟨ENNReal.mul_ne_top ENNReal.ofReal_ne_top htop, ENNReal.ofReal_ne_top⟩ + have hVreal : (ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε).toReal = + (1 - ε) * x.toReal + ε := by + rw [ENNReal.toReal_add (ENNReal.mul_ne_top ENNReal.ofReal_ne_top htop) ENNReal.ofReal_ne_top, + ENNReal.toReal_mul, ENNReal.toReal_ofReal (by linarith), ENNReal.toReal_ofReal hε0.le] + rw [truncLog_of_ne hV0 hVtop, hVreal, ENNReal.log_pos_real h0 htop, + ← EReal.coe_strictMono.monotone.map_min, EReal.coe_le_coe_iff] + have hx : 0 < x.toReal := ENNReal.toReal_pos h0 htop + have hL : Real.log (1 - ε) + Real.log x.toReal ≤ Real.log ((1 - ε) * x.toReal + ε) := by + rw [← Real.log_mul (by linarith) hx.ne'] + exact Real.log_le_log (_root_.mul_pos (by linarith) hx) (by linarith) + rw [← min_sub_sub_right] + exact le_min ((min_le_left _ _).trans (by linarith)) ((min_le_right _ _).trans (by linarith)) + +end ENNReal diff --git a/LMLExplore/EValues/BipolarRate/Round.lean b/LMLExplore/EValues/BipolarRate/Round.lean index e8a13385..7a2e5b0b 100644 --- a/LMLExplore/EValues/BipolarRate/Round.lean +++ b/LMLExplore/EValues/BipolarRate/Round.lean @@ -5,6 +5,7 @@ Authors: LMLExplore contributors -/ module +public import LMLExplore.Analysis.SpecialFunctions.Log.TruncLog public import LMLExplore.EValues.BipolarRate.Basic public import Mathlib.Probability.ProductMeasure import LMLExplore.EValues.BipolarRate.EProcess @@ -24,7 +25,7 @@ Let `S₁` be a set of probability measures on `𝓧` (the null) and `Q₁` a pr both determined by the observations of the round (`ProbabilityTheory.DependsOnBefore`). If `1 ≤ σ ≤ K`, `V ≥ δ > 0` and the payoff has expectation at most `1` on each event `{σ ≤ n}` under the i.i.d. law of every member of the null, then under the i.i.d. law of `Q₁` the expected -logarithm of the payoff, truncated above at `c` (`ProbabilityTheory.truncLog`), is at most +logarithm of the payoff, truncated above at `c` (`ENNReal.truncLog`), is at most `d * 𝔼[σ]` [EVR26, Note 01]. This is the step of the proof of the Wald inequality `ProbabilityTheory.IsEProcess.eintegral_log_stoppedValue_le_mul_bipolarRate` that uses the bipolar rate. @@ -33,15 +34,11 @@ bipolar rate. * `ProbabilityTheory.DependsOnBefore σ f`: `f` is determined by the first `σ` observations (`ProbabilityTheory.dependsOnBefore_iff`). -* `ProbabilityTheory.truncLog c x`: the logarithm of `x : ℝ≥0∞` truncated above at `c`, as a real - number. ## Main statements * `ProbabilityTheory.integral_truncLog_le_bipolarRate_mul`: the Wald inequality for a round, `𝔼_Q[truncLog c V] ≤ d * 𝔼_Q[σ]`. -* `ProbabilityTheory.min_log_le_truncLog_sub`: mixing a payoff `x` with a constant `ε` costs at - most `- log (1 - ε)` in truncated logarithm. ## Implementation notes @@ -72,6 +69,7 @@ public section open MeasureTheory Filter open TauCeti.Probability (shift shift_iterate_apply measurable_shift_iterate) +open ENNReal (truncLog) open scoped ENNReal namespace ProbabilityTheory @@ -396,6 +394,21 @@ private lemma restartTime_le_iff_le_numRounds {N i : ℕ} (hi : i ≤ N) (ω : ⟨fun h ↦ Nat.le_findGreatest hi h, fun h ↦ (monotone_restartTime σ ω h).trans (restartTime_numRounds_le N ω)⟩ +/-- Among the first `N + 1` rounds, those that end within the first `N` observations are the +completed ones. -/ +private lemma sum_range_indicator_restartTime_le (g : ℕ → (ℕ → 𝓧) → ℝ) (N : ℕ) (ω : ℕ → 𝓧) : + ∑ i ∈ Finset.range (N + 1), {ω | restartTime σ i ω ≤ N}.indicator (g i) ω = + ∑ i ∈ Finset.range (numRounds σ N ω + 1), g i ω := by + have hJN : numRounds σ N ω ≤ N := numRounds_le N ω + rw [← Finset.sum_subset (Finset.range_subset_range.2 (Nat.succ_le_succ hJN)) + (f := fun i ↦ {ω | restartTime σ i ω ≤ N}.indicator (g i) ω)] + · refine Finset.sum_congr rfl fun i hi ↦ Set.indicator_of_mem ?_ _ + have hi' := Nat.lt_succ_iff.1 (Finset.mem_range.1 hi) + exact (restartTime_le_iff_le_numRounds (hi'.trans hJN) ω).2 hi' + · intro i hi hiJ + refine Set.indicator_of_notMem (fun h ↦ hiJ (Finset.mem_range.2 (Nat.lt_succ_of_le ?_))) _ + exact (restartTime_le_iff_le_numRounds (Nat.lt_succ_iff.1 (Finset.mem_range.1 hi)) ω).1 h + /-- If every round uses at least one observation, the round after the completed ones ends after the first `N` observations. -/ private lemma lt_restartTime_numRounds_succ (hσ1 : ∀ ω, 1 ≤ σ ω) (N : ℕ) (ω : ℕ → 𝓧) : @@ -413,20 +426,12 @@ private lemma add_one_le_sum_indicator (hσ1 : ∀ ω, 1 ≤ σ ω) (N : ℕ) ( (N + 1 : ℝ) ≤ ∑ i ∈ Finset.range (N + 1), {ω | restartTime σ i ω ≤ N}.indicator (fun ω ↦ (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ)) ω := by set J := numRounds σ N ω - have hJN : J ≤ N := numRounds_le N ω have hJ : N + 1 ≤ restartTime σ (J + 1) ω := lt_restartTime_numRounds_succ hσ1 N ω calc (N + 1 : ℝ) ≤ (restartTime σ (J + 1) ω : ℝ) := by exact_mod_cast hJ _ = ∑ i ∈ Finset.range (J + 1), (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ) := by rw [restartTime_eq_sum, Nat.cast_sum] - _ = ∑ i ∈ Finset.range (J + 1), {ω | restartTime σ i ω ≤ N}.indicator - (fun ω ↦ (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ)) ω := by - refine Finset.sum_congr rfl fun i hi ↦ ?_ - rw [Set.indicator_of_mem] - exact (restartTime_le_iff_le_numRounds ((Nat.lt_succ_iff.1 (Finset.mem_range.1 hi)).trans - hJN) ω).2 (Nat.lt_succ_iff.1 (Finset.mem_range.1 hi)) - _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg - (Finset.range_subset_range.2 (Nat.succ_le_succ hJN)) - fun i _ _ ↦ Set.indicator_nonneg (fun _ _ ↦ Nat.cast_nonneg _) _ + _ = _ := (sum_range_indicator_restartTime_le + (fun i ω ↦ (σ ((shift 𝓧)^[restartTime σ i ω] ω) : ℝ)) N ω).symm /-- **Wald's argument, in expectation.** Under an i.i.d. law, the observations after the first `i` rounds are independent of the event that these rounds use at most `N` observations. -/ @@ -476,109 +481,6 @@ private lemma integral_indicator_comp_shift_restartTime (hσ : DependsOnBefore end Restart -/-! ### The truncated logarithm -/ - -/-- The logarithm truncated above at `c`, as a real number. -/ -noncomputable def truncLog (c : ℝ) (x : ℝ≥0∞) : ℝ := (min (ENNReal.log x) c).toReal - -/-- The definition of the truncated logarithm, `truncLog c x = (min (log x) c).toReal`. -/ -lemma truncLog_def (c : ℝ) (x : ℝ≥0∞) : truncLog c x = (min (ENNReal.log x) c).toReal := by - rw [truncLog] - -/-- The truncated logarithm is measurable. -/ -lemma measurable_truncLog (c : ℝ) : Measurable (truncLog c) := - measurable_ereal_toReal.comp (ENNReal.measurable_log.min measurable_const) - -/-- The truncated logarithm of a positive finite number. -/ -lemma truncLog_of_ne {c : ℝ} {x : ℝ≥0∞} (h0 : x ≠ 0) (htop : x ≠ ∞) : - truncLog c x = min (Real.log x.toReal) c := by - rw [truncLog, ENNReal.log_pos_real h0 htop, ← EReal.coe_strictMono.monotone.map_min, - EReal.toReal_coe] - -/-- The truncated logarithm of `∞` is the truncation level. -/ -@[simp] -lemma truncLog_top (c : ℝ) : truncLog c ∞ = c := by simp [truncLog] - -/-- The truncated logarithm of `0` is `0`, the real part of `⊥ = log 0`. -/ -@[simp] -lemma truncLog_zero (c : ℝ) : truncLog c 0 = 0 := by simp [truncLog] - -/-- The truncated logarithm is at most the truncation level. -/ -lemma truncLog_le {c : ℝ} {x : ℝ≥0∞} (h0 : x ≠ 0) : truncLog c x ≤ c := by - by_cases htop : x = ∞ - · rw [htop, truncLog_top] - · rw [truncLog_of_ne h0 htop] - exact min_le_right _ _ - -/-- The truncated logarithm of `x ≥ δ` is at least `log δ`, if `log δ ≤ c`. -/ -lemma log_le_truncLog {c δ : ℝ} (hδ : 0 < δ) {x : ℝ≥0∞} (hx : ENNReal.ofReal δ ≤ x) - (hc : Real.log δ ≤ c) : Real.log δ ≤ truncLog c x := by - have h0 : x ≠ 0 := (lt_of_lt_of_le (ENNReal.ofReal_pos.2 hδ) hx).ne' - by_cases htop : x = ∞ - · rw [htop, truncLog_top] - exact hc - · rw [truncLog_of_ne h0 htop] - exact le_min (Real.log_le_log hδ ((ENNReal.ofReal_le_iff_le_toReal htop).1 hx)) hc - -/-- The truncated logarithm of `x ≥ δ` is bounded in absolute value, if `log δ ≤ c`. -/ -lemma abs_truncLog_le {c δ : ℝ} (hδ : 0 < δ) {x : ℝ≥0∞} (hx : ENNReal.ofReal δ ≤ x) - (hc : Real.log δ ≤ c) : |truncLog c x| ≤ max |Real.log δ| |c| := - abs_le_max_abs_abs (log_le_truncLog hδ hx hc) - (truncLog_le (lt_of_lt_of_le (ENNReal.ofReal_pos.2 hδ) hx).ne') - -/-- The truncated logarithm of a measurable function bounded below by `δ > 0` is integrable -under a finite measure. -/ -lemma integrable_truncLog_comp {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} - [IsFiniteMeasure μ] {c δ : ℝ} (hδ : 0 < δ) {V : Ω → ℝ≥0∞} (hVm : Measurable V) - (hVδ : ∀ ω, ENNReal.ofReal δ ≤ V ω) (hc : Real.log δ ≤ c) : - Integrable (fun ω ↦ truncLog c (V ω)) μ := - Integrable.of_bound ((measurable_truncLog c).comp hVm).aestronglyMeasurable - (max |Real.log δ| |c|) (ae_of_all _ fun ω ↦ (Real.norm_eq_abs _).trans_le - (abs_truncLog_le hδ (hVδ ω) hc)) - -/-- The exponential of the truncated logarithm of `x` is at most `x`. -/ -lemma ofReal_exp_truncLog_le {c : ℝ} {x : ℝ≥0∞} (h0 : x ≠ 0) : - ENNReal.ofReal (Real.exp (truncLog c x)) ≤ x := by - by_cases htop : x = ∞ - · rw [htop] - exact le_top - · rw [truncLog_of_ne h0 htop] - calc ENNReal.ofReal (Real.exp (min (Real.log x.toReal) c)) - _ ≤ ENNReal.ofReal (Real.exp (Real.log x.toReal)) := - ENNReal.ofReal_le_ofReal (Real.exp_le_exp.2 (min_le_left _ _)) - _ = x := by - rw [Real.exp_log (ENNReal.toReal_pos h0 htop), ENNReal.ofReal_toReal htop] - -/-- Mixing a payoff with a constant: `min (log x) c ≤ truncLog c ((1 - ε) x + ε) - log (1 - ε)`. -/ -lemma min_log_le_truncLog_sub {ε : ℝ} (hε0 : 0 < ε) (hε1 : ε < 1) (c : ℝ) (x : ℝ≥0∞) : - min (ENNReal.log x) c ≤ - ((truncLog c (ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε) - Real.log (1 - ε) : ℝ) : - EReal) := by - have hlog : Real.log (1 - ε) ≤ 0 := Real.log_nonpos (by linarith) (by linarith) - by_cases h0 : x = 0 - · simp [h0] - by_cases htop : x = ∞ - · have : ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε = ∞ := by - rw [htop, ENNReal.mul_top (ENNReal.ofReal_pos.2 (by linarith)).ne', top_add] - rw [this, truncLog_top] - exact (min_le_right _ _).trans (EReal.coe_le_coe_iff.2 (by linarith)) - have hε' : ENNReal.ofReal ε ≠ 0 := (ENNReal.ofReal_pos.2 hε0).ne' - have hV0 : ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε ≠ 0 := by simp [hε'] - have hVtop : ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε ≠ ∞ := - ENNReal.add_ne_top.2 ⟨ENNReal.mul_ne_top ENNReal.ofReal_ne_top htop, ENNReal.ofReal_ne_top⟩ - have hVreal : (ENNReal.ofReal (1 - ε) * x + ENNReal.ofReal ε).toReal = - (1 - ε) * x.toReal + ε := by - rw [ENNReal.toReal_add (ENNReal.mul_ne_top ENNReal.ofReal_ne_top htop) ENNReal.ofReal_ne_top, - ENNReal.toReal_mul, ENNReal.toReal_ofReal (by linarith), ENNReal.toReal_ofReal hε0.le] - rw [truncLog_of_ne hV0 hVtop, hVreal, ENNReal.log_pos_real h0 htop, - ← EReal.coe_strictMono.monotone.map_min, EReal.coe_le_coe_iff] - have hx : 0 < x.toReal := ENNReal.toReal_pos h0 htop - have hL : Real.log (1 - ε) + Real.log x.toReal ≤ Real.log ((1 - ε) * x.toReal + ε) := by - rw [← Real.log_mul (by linarith) hx.ne'] - exact Real.log_le_log (mul_pos (by linarith) hx) (by linarith) - rw [← min_sub_sub_right] - exact le_min ((min_le_left _ _).trans (by linarith)) ((min_le_right _ _).trans (by linarith)) - /-! ### The Wald inequality for a round -/ section Wald @@ -618,7 +520,7 @@ private lemma log_restartMixture_ge {δ : ℝ} (hδ : 0 < δ) (hVδ : ∀ ω, EN _ ≤ ENNReal.ofReal ((1 - r) * r ^ J) * restartPayoff σ V J ω := by rw [restartPayoff_eq_prod] gcongr with i hi - exact ofReal_exp_truncLog_le (hV0 _) + exact ENNReal.ofReal_exp_truncLog_le (hV0 _) _ = ENNReal.ofReal ((1 - r) * r ^ J) * {ω | restartTime σ J ω ≤ N}.indicator (restartPayoff σ V J) ω := by rw [Set.indicator_of_mem (restartTime_numRounds_le N ω)] @@ -638,19 +540,10 @@ private lemma log_restartMixture_ge {δ : ℝ} (hδ : 0 < δ) (hVδ : ∀ ω, EN -- the sum over the rounds that start within the first `N` observations have h3 : ∑ i ∈ Finset.range (N + 1), {ω | restartTime σ i ω ≤ N}.indicator (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω = - ∑ i ∈ Finset.range (J + 1), Y i := by - symm - refine Finset.sum_subset (Finset.range_subset_range.2 (Nat.succ_le_succ hJN)) - (fun i hi hiJ ↦ ?_) |>.symm.trans (Finset.sum_congr rfl fun i hi ↦ ?_) |>.symm - · rw [Set.indicator_of_notMem] - rw [Set.mem_ofPred_eq, restartTime_le_iff_le_numRounds - (Nat.lt_succ_iff.1 (Finset.mem_range.1 hi))] - exact fun h ↦ hiJ (Finset.mem_range.2 (Nat.lt_succ_of_le h)) - · rw [Set.indicator_of_mem] - exact (restartTime_le_iff_le_numRounds - ((Nat.lt_succ_iff.1 (Finset.mem_range.1 hi)).trans hJN) ω).2 - (Nat.lt_succ_iff.1 (Finset.mem_range.1 hi)) - have h4 : Y J ≤ c := truncLog_le (hV0 _) + ∑ i ∈ Finset.range (J + 1), Y i := + sum_range_indicator_restartTime_le + (fun i ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) N ω + have h4 : Y J ≤ c := ENNReal.truncLog_le (hV0 _) have h5 : (N : ℝ) * Real.log r ≤ J * Real.log r := mul_le_mul_of_nonpos_right (by exact_mod_cast hJN) (Real.log_nonpos hr0.le hr1.le) calc ((Real.log (1 - r) + N * Real.log r - c + ∑ i ∈ Finset.range (N + 1), @@ -747,12 +640,12 @@ private lemma add_integral_truncLog_mul_sum_measureReal_le (Q₁ : Measure 𝓧) N * (bipolarRate Q₁ S₁).toReal := by set μ := Measure.infinitePi (fun _ : ℕ ↦ Q₁) set A := ∫ ω, truncLog c (V ω) ∂μ - have hYm : Measurable fun ω ↦ truncLog c (V ω) := (measurable_truncLog c).comp hVm + have hYm : Measurable fun ω ↦ truncLog c (V ω) := (ENNReal.measurable_truncLog c).comp hVm have hT (i : ℕ) : Measurable (restartTime σ i) := measurable_restartTime hσm i -- the truncated log-payoffs are bounded, hence integrable have hfi (i : ℕ) : Integrable (fun ω ↦ {ω | restartTime σ i ω ≤ N}.indicator (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω) μ := - (integrable_truncLog_comp hδ (measurable_apply_of_countable + (ENNReal.integrable_truncLog_comp hδ (measurable_apply_of_countable (fun t ↦ hVm.comp (measurable_shift_iterate t)) (hT i)) (fun _ ↦ hVδ _) hc).indicator (hT i measurableSet_Iic) set B := Real.log (1 - r) + N * Real.log r - c @@ -772,7 +665,7 @@ private lemma add_integral_truncLog_mul_sum_measureReal_le (Q₁ : Measure 𝓧) simp only [integral_const, probReal_univ, one_smul] congr 1 exact Finset.sum_congr rfl fun i _ ↦ (integral_indicator_comp_shift_restartTime hσ hσm Q₁ - hYm (fun ω ↦ abs_truncLog_le hδ (hVδ ω) hc) i N).trans (mul_comm _ _) + hYm (fun ω ↦ ENNReal.abs_truncLog_le hδ (hVδ ω) hc) i N).trans (mul_comm _ _) have hle : ((B + A * ∑ i ∈ Finset.range (N + 1), μ.real {ω | restartTime σ i ω ≤ N} : ℝ) : EReal) ≤ (N : EReal) * bipolarRate Q₁ S₁ := by rw [← hval, ← eintegral_eq_integral hint] diff --git a/LMLExplore/EValues/BipolarRate/StoppingTime.lean b/LMLExplore/EValues/BipolarRate/StoppingTime.lean index b198ccf9..c11327ba 100644 --- a/LMLExplore/EValues/BipolarRate/StoppingTime.lean +++ b/LMLExplore/EValues/BipolarRate/StoppingTime.lean @@ -76,6 +76,7 @@ stopping times with values in `ℕ`. public section open MeasureTheory Filter +open ENNReal (truncLog) open scoped ENNReal Topology namespace ProbabilityTheory @@ -170,9 +171,10 @@ private lemma integral_truncLog_stoppedValue_le (Q₁ : Measure 𝓧) [IsProbabi · exact hD k -- let `k` tend to infinity refine le_of_tendsto' (tendsto_integral_of_dominated_convergence (fun _ ↦ max |Real.log ε| |c|) - (fun k ↦ ((measurable_truncLog c).comp (hVm k)).aestronglyMeasurable) (integrable_const _) + (fun k ↦ ((ENNReal.measurable_truncLog c).comp (hVm k)).aestronglyMeasurable) + (integrable_const _) (fun k ↦ ae_of_all _ fun ω ↦ (Real.norm_eq_abs _).trans_le - (abs_truncLog_le hε0 (hVε k ω) hc)) (ae_of_all _ fun ω ↦ ?_)) hk + (ENNReal.abs_truncLog_le hε0 (hVε k ω) hc)) (ae_of_all _ fun ω ↦ ?_)) hk exact tendsto_atTop_of_eventually_const (i₀ := τ ω) fun k hk ↦ by simp [V, min_eq_left hk] /-- The Wald inequality when the bipolar rate is finite and either it is `0` or the expected @@ -210,11 +212,11 @@ private lemma eintegral_log_stoppedValue_le_toReal_mul (Q₁ : Measure 𝓧) [Is set W : (ℕ → 𝓧) → ℝ≥0∞ := fun ω ↦ ENNReal.ofReal (1 - ε) * E (τ ω) ω + ENNReal.ofReal ε have hc : Real.log ε ≤ k := (Real.log_neg hε0 hε1).le.trans (Nat.cast_nonneg k) have hYi : Integrable (fun ω ↦ truncLog k (W ω)) μ := - integrable_truncLog_comp hε0 ((measurable_const.mul hEτm).add measurable_const) + ENNReal.integrable_truncLog_comp hε0 ((measurable_const.mul hEτm).add measurable_const) (fun _ ↦ le_add_self) hc calc ∫ᵉ ω, min (ENNReal.log (E (τ ω) ω)) k ∂μ _ ≤ ∫ᵉ ω, ((truncLog k (W ω) - Real.log (1 - ε) : ℝ) : EReal) ∂μ := - eintegral_mono fun ω ↦ by simpa using min_log_le_truncLog_sub hε0 hε1 k (E (τ ω) ω) + eintegral_mono fun ω ↦ by simpa using ENNReal.min_log_le_truncLog_sub hε0 hε1 k (E (τ ω) ω) _ = ((∫ ω, truncLog k (W ω) ∂μ - Real.log (1 - ε) : ℝ) : EReal) := by have hYi' : Integrable (fun ω ↦ truncLog k (W ω) - Real.log (1 - ε)) μ := hYi.sub (integrable_const _) @@ -338,11 +340,10 @@ private lemma neg_log_le_toReal_mul_sub (Q₁ : Measure 𝓧) [IsProbabilityMeas -- the stopping times `min τ k`, with values in `ℕ` set τk : ℕ → (ℕ → 𝓧) → ℕ := fun k ω ↦ ENat.toNat (min (τ ω) k) have hτk_coe (k : ℕ) (ω : ℕ → 𝓧) : ((τk k ω : ℕ) : WithTop ℕ) = min (τ ω) k := - ENat.natCast_toNat (ne_top_of_le_ne_top (WithTop.natCast_ne_top k) (min_le_right _ _)) + ENat.natCast_toNat_min (τ ω) k have hτk (k : ℕ) : IsStoppingTime (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) - fun ω ↦ (τk k ω : WithTop ℕ) := by - rw [show (fun ω ↦ (τk k ω : WithTop ℕ)) = fun ω ↦ min (τ ω) k from funext (hτk_coe k)] - exact hτ.min_natCast k + fun ω ↦ (τk k ω : WithTop ℕ) := + hτ.toNat_min k have hmk (k : ℕ) : ∫⁻ ω, (τk k ω : ℝ≥0∞) + 1 ∂μ ≤ m := lintegral_mono fun ω ↦ by gcongr have h : ((τk k ω : ℕ) : ℕ∞) ≤ τ ω := (hτk_coe k ω).trans_le (min_le_left _ _) diff --git a/LMLExplore/Probability/Process/Stopping.lean b/LMLExplore/Probability/Process/Stopping.lean index 83690e9f..02f32424 100644 --- a/LMLExplore/Probability/Process/Stopping.lean +++ b/LMLExplore/Probability/Process/Stopping.lean @@ -31,6 +31,8 @@ processes. `MeasureTheory.IsStoppingTime.measurableSet_natCast_lt`, `MeasureTheory.isStoppingTime_natCast`, `MeasureTheory.IsStoppingTime.min_natCast`: Mathlib's stopping-time API for `WithTop ℕ`-valued times, stated at the cast `(n : WithTop ℕ)` rather than the coercion `WithTop.some n`. +* `MeasureTheory.IsStoppingTime.toNat_min`, `ENat.natCast_toNat_min`: the minimum of a stopping + time with values in `WithTop ℕ` and a constant is a stopping time with values in `ℕ`. * `MeasureTheory.IsStoppingTime.measurable_nat`, `MeasureTheory.IsStoppingTime.natCast_min`: a stopping time with values in `ℕ` is measurable, and so is its minimum with a constant a stopping time. @@ -109,6 +111,20 @@ theorem IsStoppingTime.min_natCast (hτ : IsStoppingTime ℱ τ) (n : ℕ) : rw [Nat.cast_withTop] exact hτ.min_const n +/-- The minimum of `t : WithTop ℕ` and the cast `(n : WithTop ℕ)` is finite, so its value as a +natural number casts back to it. -/ +theorem _root_.ENat.natCast_toNat_min (t : WithTop ℕ) (n : ℕ) : + ((ENat.toNat (min t n) : ℕ) : WithTop ℕ) = min t n := + ENat.natCast_toNat (ne_top_of_le_ne_top (WithTop.natCast_ne_top n) (min_le_right _ _)) + +/-- The minimum of a stopping time with values in `WithTop ℕ` and the cast `(n : WithTop ℕ)`, as a +natural number, is a stopping time with values in `ℕ`; it casts back to `min (τ ω) n` +(`ENat.natCast_toNat_min`). -/ +theorem IsStoppingTime.toNat_min (hτ : IsStoppingTime ℱ τ) (n : ℕ) : + IsStoppingTime ℱ fun ω ↦ ((ENat.toNat (min (τ ω) n) : ℕ) : WithTop ℕ) := by + simp_rw [ENat.natCast_toNat_min] + exact hτ.min_natCast n + end NatCast /-! ### Stopping times with values in `ℕ` -/ From 324e88ee6876ff172f9805a0eb1991d9e76a7dbb Mon Sep 17 00:00:00 2001 From: Remy Degenne Date: Sun, 15 Nov 2026 21:16:12 +0100 Subject: [PATCH 6/8] refactor: drop the truncation-level assumption from the truncLog bounds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit abs_truncLog_le, integrable_truncLog_comp and the Wald inequality for a round integral_truncLog_le_bipolarRate_mul no longer assume log δ ≤ c, via the new lower bound ENNReal.min_log_le_truncLog. Co-Authored-By: Claude Code --- .../SpecialFunctions/Log/TruncLog.lean | 31 ++++++++++++------- LMLExplore/EValues/BipolarRate/Round.lean | 10 +++--- .../EValues/BipolarRate/StoppingTime.lean | 11 +++---- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/LMLExplore/Analysis/SpecialFunctions/Log/TruncLog.lean b/LMLExplore/Analysis/SpecialFunctions/Log/TruncLog.lean index c44ca32a..2c023892 100644 --- a/LMLExplore/Analysis/SpecialFunctions/Log/TruncLog.lean +++ b/LMLExplore/Analysis/SpecialFunctions/Log/TruncLog.lean @@ -72,31 +72,38 @@ lemma truncLog_le {c : ℝ} {x : ℝ≥0∞} (h0 : x ≠ 0) : truncLog c x ≤ c · rw [truncLog_of_ne h0 htop] exact min_le_right _ _ -/-- The truncated logarithm of `x ≥ δ` is at least `log δ`, if `log δ ≤ c`. -/ -lemma log_le_truncLog {c δ : ℝ} (hδ : 0 < δ) {x : ℝ≥0∞} (hx : ENNReal.ofReal δ ≤ x) - (hc : Real.log δ ≤ c) : Real.log δ ≤ truncLog c x := by +/-- The truncated logarithm of `x ≥ δ` is at least `min (log δ) c`. -/ +lemma min_log_le_truncLog {c δ : ℝ} (hδ : 0 < δ) {x : ℝ≥0∞} (hx : ENNReal.ofReal δ ≤ x) : + min (Real.log δ) c ≤ truncLog c x := by have h0 : x ≠ 0 := (lt_of_lt_of_le (ENNReal.ofReal_pos.2 hδ) hx).ne' by_cases htop : x = ∞ · rw [htop, truncLog_top] - exact hc + exact min_le_right _ _ · rw [truncLog_of_ne h0 htop] - exact le_min (Real.log_le_log hδ ((ENNReal.ofReal_le_iff_le_toReal htop).1 hx)) hc + exact min_le_min_right c (Real.log_le_log hδ ((ENNReal.ofReal_le_iff_le_toReal htop).1 hx)) + +/-- The truncated logarithm of `x ≥ δ` is at least `log δ`, if `log δ ≤ c`. -/ +lemma log_le_truncLog {c δ : ℝ} (hδ : 0 < δ) {x : ℝ≥0∞} (hx : ENNReal.ofReal δ ≤ x) + (hc : Real.log δ ≤ c) : Real.log δ ≤ truncLog c x := + (min_eq_left hc).symm.le.trans (min_log_le_truncLog hδ hx) -/-- The truncated logarithm of `x ≥ δ` is bounded in absolute value, if `log δ ≤ c`. -/ -lemma abs_truncLog_le {c δ : ℝ} (hδ : 0 < δ) {x : ℝ≥0∞} (hx : ENNReal.ofReal δ ≤ x) - (hc : Real.log δ ≤ c) : |truncLog c x| ≤ max |Real.log δ| |c| := - abs_le_max_abs_abs (log_le_truncLog hδ hx hc) - (truncLog_le (lt_of_lt_of_le (ENNReal.ofReal_pos.2 hδ) hx).ne') +/-- The truncated logarithm of `x ≥ δ` is bounded in absolute value. -/ +lemma abs_truncLog_le {c δ : ℝ} (hδ : 0 < δ) {x : ℝ≥0∞} (hx : ENNReal.ofReal δ ≤ x) : + |truncLog c x| ≤ max |Real.log δ| |c| := + abs_le.2 ⟨(le_min ((neg_le_neg (le_max_left _ _)).trans (neg_abs_le _)) + ((neg_le_neg (le_max_right _ _)).trans (neg_abs_le _))).trans (min_log_le_truncLog hδ hx), + (truncLog_le (lt_of_lt_of_le (ENNReal.ofReal_pos.2 hδ) hx).ne').trans + ((le_abs_self c).trans (le_max_right _ _))⟩ /-- The truncated logarithm of a measurable function bounded below by `δ > 0` is integrable under a finite measure. -/ lemma integrable_truncLog_comp {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsFiniteMeasure μ] {c δ : ℝ} (hδ : 0 < δ) {V : Ω → ℝ≥0∞} (hVm : Measurable V) - (hVδ : ∀ ω, ENNReal.ofReal δ ≤ V ω) (hc : Real.log δ ≤ c) : + (hVδ : ∀ ω, ENNReal.ofReal δ ≤ V ω) : Integrable (fun ω ↦ truncLog c (V ω)) μ := Integrable.of_bound ((measurable_truncLog c).comp hVm).aestronglyMeasurable (max |Real.log δ| |c|) (ae_of_all _ fun ω ↦ (Real.norm_eq_abs _).trans_le - (abs_truncLog_le hδ (hVδ ω) hc)) + (abs_truncLog_le hδ (hVδ ω))) /-- The exponential of the truncated logarithm of `x` is at most `x`. -/ lemma ofReal_exp_truncLog_le {c : ℝ} {x : ℝ≥0∞} (h0 : x ≠ 0) : diff --git a/LMLExplore/EValues/BipolarRate/Round.lean b/LMLExplore/EValues/BipolarRate/Round.lean index 7a2e5b0b..c1d5b6f6 100644 --- a/LMLExplore/EValues/BipolarRate/Round.lean +++ b/LMLExplore/EValues/BipolarRate/Round.lean @@ -631,7 +631,7 @@ private lemma add_integral_truncLog_mul_sum_measureReal_le (Q₁ : Measure 𝓧) (hVm : Measurable V) (h_null : ∀ P ∈ S₁, ∀ n : ℕ, ∫⁻ ω, {ω | σ ω ≤ n}.indicator V ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) ≤ 1) - {δ : ℝ} (hδ : 0 < δ) (hVδ : ∀ ω, ENNReal.ofReal δ ≤ V ω) {c : ℝ} (hc : Real.log δ ≤ c) + {δ : ℝ} (hδ : 0 < δ) (hVδ : ∀ ω, ENNReal.ofReal δ ≤ V ω) {c : ℝ} (hd : bipolarRate Q₁ S₁ ≠ ⊤) {r : ℝ} (hr0 : 0 < r) (hr1 : r < 1) {N : ℕ} (hN : 1 ≤ N) : Real.log (1 - r) + N * Real.log r - c + (∫ ω, truncLog c (V ω) ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁)) * @@ -646,7 +646,7 @@ private lemma add_integral_truncLog_mul_sum_measureReal_le (Q₁ : Measure 𝓧) have hfi (i : ℕ) : Integrable (fun ω ↦ {ω | restartTime σ i ω ≤ N}.indicator (fun ω ↦ truncLog c (V ((shift 𝓧)^[restartTime σ i ω] ω))) ω) μ := (ENNReal.integrable_truncLog_comp hδ (measurable_apply_of_countable - (fun t ↦ hVm.comp (measurable_shift_iterate t)) (hT i)) (fun _ ↦ hVδ _) hc).indicator + (fun t ↦ hVm.comp (measurable_shift_iterate t)) (hT i)) (fun _ ↦ hVδ _)).indicator (hT i measurableSet_Iic) set B := Real.log (1 - r) + N * Real.log r - c have hsum : Integrable (fun ω ↦ ∑ i ∈ Finset.range (N + 1), @@ -665,7 +665,7 @@ private lemma add_integral_truncLog_mul_sum_measureReal_le (Q₁ : Measure 𝓧) simp only [integral_const, probReal_univ, one_smul] congr 1 exact Finset.sum_congr rfl fun i _ ↦ (integral_indicator_comp_shift_restartTime hσ hσm Q₁ - hYm (fun ω ↦ ENNReal.abs_truncLog_le hδ (hVδ ω) hc) i N).trans (mul_comm _ _) + hYm (fun ω ↦ ENNReal.abs_truncLog_le hδ (hVδ ω)) i N).trans (mul_comm _ _) have hle : ((B + A * ∑ i ∈ Finset.range (N + 1), μ.real {ω | restartTime σ i ω ≤ N} : ℝ) : EReal) ≤ (N : EReal) * bipolarRate Q₁ S₁ := by rw [← hval, ← eintegral_eq_integral hint] @@ -694,7 +694,7 @@ lemma integral_truncLog_le_bipolarRate_mul (Q₁ : Measure 𝓧) [IsProbabilityM {K : ℕ} (hσK : ∀ ω, σ ω ≤ K) (h_null : ∀ P ∈ S₁, ∀ n : ℕ, ∫⁻ ω, {ω | σ ω ≤ n}.indicator V ω ∂Measure.infinitePi (fun _ : ℕ ↦ P) ≤ 1) - {δ : ℝ} (hδ : 0 < δ) (hVδ : ∀ ω, ENNReal.ofReal δ ≤ V ω) {c : ℝ} (hc : Real.log δ ≤ c) + {δ : ℝ} (hδ : 0 < δ) (hVδ : ∀ ω, ENNReal.ofReal δ ≤ V ω) {c : ℝ} (hd : bipolarRate Q₁ S₁ ≠ ⊤) : ∫ ω, truncLog c (V ω) ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁) ≤ (bipolarRate Q₁ S₁).toReal * ∫ ω, (σ ω : ℝ) ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁) := by @@ -707,7 +707,7 @@ lemma integral_truncLog_le_bipolarRate_mul (Q₁ : Measure 𝓧) [IsProbabilityM fun ω ↦ by exact_mod_cast hσ1 ω refine le_mul_of_forall_restart (c := c) (by linarith) (EReal.toReal_nonneg hd0) fun r hr0 hr1 N hN ↦ ⟨_, add_one_le_integral_mul_sum_measureReal hσ hσm hσ1 hσK Q₁ N, - add_integral_truncLog_mul_sum_measureReal_le Q₁ hS₁ hσ hV hσm hVm h_null hδ hVδ hc hd hr0 + add_integral_truncLog_mul_sum_measureReal_le Q₁ hS₁ hσ hV hσm hVm h_null hδ hVδ hd hr0 hr1 hN⟩ end Wald diff --git a/LMLExplore/EValues/BipolarRate/StoppingTime.lean b/LMLExplore/EValues/BipolarRate/StoppingTime.lean index c11327ba..9c62fe2c 100644 --- a/LMLExplore/EValues/BipolarRate/StoppingTime.lean +++ b/LMLExplore/EValues/BipolarRate/StoppingTime.lean @@ -143,7 +143,7 @@ private lemma integral_truncLog_stoppedValue_le (Q₁ : Measure 𝓧) [IsProbabi (hE : IsEProcess E (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) ((fun P ↦ Measure.infinitePi fun _ : ℕ ↦ P) '' S₁)) (hτ : IsStoppingTime (Filtration.piLE (X := fun _ : ℕ ↦ 𝓧)) fun ω ↦ (τ ω : WithTop ℕ)) - {ε : ℝ} (hε0 : 0 < ε) (hε1 : ε < 1) {c : ℝ} (hc : Real.log ε ≤ c) + {ε : ℝ} (hε0 : 0 < ε) (hε1 : ε < 1) {c : ℝ} (hd : bipolarRate Q₁ S₁ ≠ ⊤) {D : ℝ} (hD : ∀ k : ℕ, (bipolarRate Q₁ S₁).toReal * ∫ ω, ((min (τ ω) k + 1 : ℕ) : ℝ) ∂Measure.infinitePi (fun _ : ℕ ↦ Q₁) ≤ D) : @@ -160,7 +160,7 @@ private lemma integral_truncLog_stoppedValue_le (Q₁ : Measure 𝓧) [IsProbabi have hk (k : ℕ) : ∫ ω, truncLog c (V k ω) ∂μ ≤ D := by refine (integral_truncLog_le_bipolarRate_mul (σ := fun ω ↦ min (τ ω) k + 1) Q₁ hS₁ ?_ ?_ (((hτk k).measurable_nat).add_const 1) (hVm k) (fun _ ↦ le_add_self) - (K := k + 1) (fun ω ↦ by simp) ?_ hε0 (hVε k) hc hd).trans ?_ + (K := k + 1) (fun ω ↦ by simp) ?_ hε0 (hVε k) hd).trans ?_ · refine dependsOnBefore_iff.2 fun u ω ω' h hle ↦ ?_ rw [(hτk k).eq_of_forall_le fun i hi ↦ h i (by omega)] · refine dependsOnBefore_iff.2 fun u ω ω' h hle ↦ ?_ @@ -174,7 +174,7 @@ private lemma integral_truncLog_stoppedValue_le (Q₁ : Measure 𝓧) [IsProbabi (fun k ↦ ((ENNReal.measurable_truncLog c).comp (hVm k)).aestronglyMeasurable) (integrable_const _) (fun k ↦ ae_of_all _ fun ω ↦ (Real.norm_eq_abs _).trans_le - (ENNReal.abs_truncLog_le hε0 (hVε k ω) hc)) (ae_of_all _ fun ω ↦ ?_)) hk + (ENNReal.abs_truncLog_le hε0 (hVε k ω))) (ae_of_all _ fun ω ↦ ?_)) hk exact tendsto_atTop_of_eventually_const (i₀ := τ ω) fun k hk ↦ by simp [V, min_eq_left hk] /-- The Wald inequality when the bipolar rate is finite and either it is `0` or the expected @@ -210,10 +210,9 @@ private lemma eintegral_log_stoppedValue_le_toReal_mul (Q₁ : Measure 𝓧) [Is have step (ε : ℝ) (hε0 : 0 < ε) (hε1 : ε < 1) (k : ℕ) : ∫ᵉ ω, min (ENNReal.log (E (τ ω) ω)) k ∂μ ≤ ((D - Real.log (1 - ε) : ℝ) : EReal) := by set W : (ℕ → 𝓧) → ℝ≥0∞ := fun ω ↦ ENNReal.ofReal (1 - ε) * E (τ ω) ω + ENNReal.ofReal ε - have hc : Real.log ε ≤ k := (Real.log_neg hε0 hε1).le.trans (Nat.cast_nonneg k) have hYi : Integrable (fun ω ↦ truncLog k (W ω)) μ := ENNReal.integrable_truncLog_comp hε0 ((measurable_const.mul hEτm).add measurable_const) - (fun _ ↦ le_add_self) hc + (fun _ ↦ le_add_self) calc ∫ᵉ ω, min (ENNReal.log (E (τ ω) ω)) k ∂μ _ ≤ ∫ᵉ ω, ((truncLog k (W ω) - Real.log (1 - ε) : ℝ) : EReal) ∂μ := eintegral_mono fun ω ↦ by simpa using ENNReal.min_log_le_truncLog_sub hε0 hε1 k (E (τ ω) ω) @@ -223,7 +222,7 @@ private lemma eintegral_log_stoppedValue_le_toReal_mul (Q₁ : Measure 𝓧) [Is rw [eintegral_eq_integral hYi', integral_sub hYi (integrable_const _), integral_const, probReal_univ, one_smul] _ ≤ ((D - Real.log (1 - ε) : ℝ) : EReal) := EReal.coe_le_coe_iff.2 (by - linarith [integral_truncLog_stoppedValue_le Q₁ hS₁ hE hτ hε0 hε1 hc hd hD]) + linarith [integral_truncLog_stoppedValue_le Q₁ hS₁ hE hτ hε0 hε1 (c := k) hd hD]) exact eintegral_le_of_forall_min_le (ENNReal.measurable_log.comp hEτm) fun k ↦ le_of_forall_le_sub_log_one_sub fun ε hε0 hε1 ↦ step ε hε0 hε1 k From daa6239247a1213cb520cfbb9a0294221c06c224 Mon Sep 17 00:00:00 2001 From: Remy Degenne Date: Sun, 15 Nov 2026 21:43:25 +0100 Subject: [PATCH 7/8] refactor: move ENat.natCast_toNat_min to an ENat file Co-Authored-By: Claude Code --- LMLExplore/Data/ENat/Basic.lean | 29 ++++++++++++++++++++ LMLExplore/Probability/Process/Stopping.lean | 11 ++------ 2 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 LMLExplore/Data/ENat/Basic.lean diff --git a/LMLExplore/Data/ENat/Basic.lean b/LMLExplore/Data/ENat/Basic.lean new file mode 100644 index 00000000..14b3532c --- /dev/null +++ b/LMLExplore/Data/ENat/Basic.lean @@ -0,0 +1,29 @@ +/- +Copyright (c) 2026 LMLExplore contributors. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: LMLExplore contributors +-/ +module + +public import Mathlib.Data.ENat.Basic + +/-! +# The minimum of an extended natural number and a natural number + +## Main statements + +* `ENat.natCast_toNat_min`: the minimum of `t : WithTop ℕ` and the cast `(n : WithTop ℕ)` is + finite, so its value as a natural number casts back to it. +-/ + +public section + +namespace ENat + +/-- The minimum of `t : WithTop ℕ` and the cast `(n : WithTop ℕ)` is finite, so its value as a +natural number casts back to it. -/ +theorem natCast_toNat_min (t : WithTop ℕ) (n : ℕ) : + ((ENat.toNat (min t n) : ℕ) : WithTop ℕ) = min t n := + ENat.natCast_toNat (ne_top_of_le_ne_top (ENat.natCast_ne_top n) (min_le_right _ _)) + +end ENat diff --git a/LMLExplore/Probability/Process/Stopping.lean b/LMLExplore/Probability/Process/Stopping.lean index 02f32424..9226d038 100644 --- a/LMLExplore/Probability/Process/Stopping.lean +++ b/LMLExplore/Probability/Process/Stopping.lean @@ -7,6 +7,7 @@ module public import Mathlib.MeasureTheory.MeasurableSpace.Instances public import Mathlib.Probability.Process.Stopping +public import LMLExplore.Data.ENat.Basic import Mathlib.MeasureTheory.Function.FactorsThrough /-! @@ -31,8 +32,8 @@ processes. `MeasureTheory.IsStoppingTime.measurableSet_natCast_lt`, `MeasureTheory.isStoppingTime_natCast`, `MeasureTheory.IsStoppingTime.min_natCast`: Mathlib's stopping-time API for `WithTop ℕ`-valued times, stated at the cast `(n : WithTop ℕ)` rather than the coercion `WithTop.some n`. -* `MeasureTheory.IsStoppingTime.toNat_min`, `ENat.natCast_toNat_min`: the minimum of a stopping - time with values in `WithTop ℕ` and a constant is a stopping time with values in `ℕ`. +* `MeasureTheory.IsStoppingTime.toNat_min`: the minimum of a stopping time with values in + `WithTop ℕ` and a constant is a stopping time with values in `ℕ`. * `MeasureTheory.IsStoppingTime.measurable_nat`, `MeasureTheory.IsStoppingTime.natCast_min`: a stopping time with values in `ℕ` is measurable, and so is its minimum with a constant a stopping time. @@ -111,12 +112,6 @@ theorem IsStoppingTime.min_natCast (hτ : IsStoppingTime ℱ τ) (n : ℕ) : rw [Nat.cast_withTop] exact hτ.min_const n -/-- The minimum of `t : WithTop ℕ` and the cast `(n : WithTop ℕ)` is finite, so its value as a -natural number casts back to it. -/ -theorem _root_.ENat.natCast_toNat_min (t : WithTop ℕ) (n : ℕ) : - ((ENat.toNat (min t n) : ℕ) : WithTop ℕ) = min t n := - ENat.natCast_toNat (ne_top_of_le_ne_top (WithTop.natCast_ne_top n) (min_le_right _ _)) - /-- The minimum of a stopping time with values in `WithTop ℕ` and the cast `(n : WithTop ℕ)`, as a natural number, is a stopping time with values in `ℕ`; it casts back to `min (τ ω) n` (`ENat.natCast_toNat_min`). -/ From f5956bc7c9483f8f6f31e5e03edb2668c88fd9e2 Mon Sep 17 00:00:00 2001 From: Remy Degenne Date: Sun, 15 Nov 2026 23:35:31 +0100 Subject: [PATCH 8/8] refactor: share the mixing-with-a-constant bound for extended integrals Make eintegral_min_log_le_integral_truncLog_sub public in LMLExplore/MeasureTheory/Integral/EReal.lean, delete its private copy in Universal.lean, and use it in the Wald inequality of StoppingTime.lean instead of the inline re-derivation. Co-Authored-By: Claude Code --- .../EValues/BipolarRate/StoppingTime.lean | 13 ++------ LMLExplore/EValues/BipolarRate/Universal.lean | 28 ----------------- LMLExplore/MeasureTheory/Integral/EReal.lean | 31 +++++++++++++++++++ 3 files changed, 34 insertions(+), 38 deletions(-) diff --git a/LMLExplore/EValues/BipolarRate/StoppingTime.lean b/LMLExplore/EValues/BipolarRate/StoppingTime.lean index 3ac5e9d2..e0d01139 100644 --- a/LMLExplore/EValues/BipolarRate/StoppingTime.lean +++ b/LMLExplore/EValues/BipolarRate/StoppingTime.lean @@ -213,16 +213,9 @@ private lemma eintegral_log_stoppedValue_le_toReal_mul (Q₁ : Measure 𝓧) [Is have hYi : Integrable (fun ω ↦ truncLog k (W ω)) μ := ENNReal.integrable_truncLog_comp hε0 ((measurable_const.mul hEτm).add measurable_const) (fun _ ↦ le_add_self) - calc ∫ᵉ ω, min (ENNReal.log (E (τ ω) ω)) k ∂μ - _ ≤ ∫ᵉ ω, ((truncLog k (W ω) - Real.log (1 - ε) : ℝ) : EReal) ∂μ := - eintegral_mono fun ω ↦ by simpa using ENNReal.min_log_le_truncLog_sub hε0 hε1 k (E (τ ω) ω) - _ = ((∫ ω, truncLog k (W ω) ∂μ - Real.log (1 - ε) : ℝ) : EReal) := by - have hYi' : Integrable (fun ω ↦ truncLog k (W ω) - Real.log (1 - ε)) μ := - hYi.sub (integrable_const _) - rw [eintegral_eq_integral hYi', - integral_sub hYi (integrable_const _), integral_const, probReal_univ, one_smul] - _ ≤ ((D - Real.log (1 - ε) : ℝ) : EReal) := EReal.coe_le_coe_iff.2 (by - linarith [integral_truncLog_stoppedValue_le Q₁ hS₁ hE hτ hε0 hε1 (c := k) hd hD]) + exact (eintegral_min_log_le_integral_truncLog_sub hε0 hε1 k hYi).trans + (EReal.coe_le_coe_iff.2 (by + linarith [integral_truncLog_stoppedValue_le Q₁ hS₁ hE hτ hε0 hε1 (c := k) hd hD])) exact eintegral_le_of_forall_min_le (ENNReal.measurable_log.comp hEτm) fun k ↦ le_of_forall_le_sub_log_one_sub fun ε hε0 hε1 ↦ step ε hε0 hε1 k diff --git a/LMLExplore/EValues/BipolarRate/Universal.lean b/LMLExplore/EValues/BipolarRate/Universal.lean index 08b76810..3f2e6082 100644 --- a/LMLExplore/EValues/BipolarRate/Universal.lean +++ b/LMLExplore/EValues/BipolarRate/Universal.lean @@ -93,34 +93,6 @@ open MeasureTheory Filter open TauCeti.Probability (shift measurable_shift_iterate) open scoped ENNReal Topology -/-! ### Mixing with a constant, in expectation -/ - -namespace MeasureTheory - -/-- Mixing with a constant, in expectation: the extended integral of the truncation at `k` of -`log E` is at most the integral of the truncated logarithm of `(1 - ε) E + ε`, minus -`log (1 - ε)`. -/ -private lemma eintegral_min_log_le_integral_truncLog_sub {Ω : Type*} [MeasurableSpace Ω] - {μ : Measure Ω} [IsProbabilityMeasure μ] {E : Ω → ℝ≥0∞} {ε : ℝ} (hε0 : 0 < ε) (hε1 : ε < 1) - (k : ℕ) (hint : Integrable - (fun x ↦ ENNReal.truncLog k (ENNReal.ofReal (1 - ε) * E x + ENNReal.ofReal ε)) μ) : - ∫ᵉ x, min (ENNReal.log (E x)) k ∂μ ≤ - ((∫ x, ENNReal.truncLog k (ENNReal.ofReal (1 - ε) * E x + ENNReal.ofReal ε) ∂μ - - Real.log (1 - ε) : ℝ) : EReal) := by - calc ∫ᵉ x, min (ENNReal.log (E x)) k ∂μ - _ ≤ ∫ᵉ x, ((ENNReal.truncLog k (ENNReal.ofReal (1 - ε) * E x + ENNReal.ofReal ε) - - Real.log (1 - ε) : ℝ) : EReal) ∂μ := eintegral_mono fun x ↦ by - have := ENNReal.min_log_le_truncLog_sub hε0 hε1 (k : ℝ) (E x) - rwa [EReal.coe_natCast] at this - _ = ((∫ x, (ENNReal.truncLog k (ENNReal.ofReal (1 - ε) * E x + ENNReal.ofReal ε) - - Real.log (1 - ε)) ∂μ : ℝ) : EReal) := - eintegral_eq_integral (hint.sub (integrable_const _)) - _ = _ := by - rw [integral_sub hint (integrable_const _), integral_const] - simp - -end MeasureTheory - namespace ProbabilityTheory variable {𝓧 : Type*} {m𝓧 : MeasurableSpace 𝓧} {S₁ : Set (Measure 𝓧)} diff --git a/LMLExplore/MeasureTheory/Integral/EReal.lean b/LMLExplore/MeasureTheory/Integral/EReal.lean index 56773fb2..7a39d7a0 100644 --- a/LMLExplore/MeasureTheory/Integral/EReal.lean +++ b/LMLExplore/MeasureTheory/Integral/EReal.lean @@ -5,7 +5,10 @@ Authors: LMLExplore contributors -/ module +public import LMLExplore.Analysis.SpecialFunctions.Log.TruncLog +public import Mathlib.MeasureTheory.Integral.Bochner.Basic public import Statlib.ForMathlib.MeasureTheory.Integral.EReal.EIntegral +import Statlib.ForMathlib.MeasureTheory.Integral.EReal.Bochner /-! # Monotone convergence for the truncations of an extended integral @@ -16,10 +19,16 @@ above at `k` leaves its negative part unchanged, and the positive parts of the t `min f k` increase to that of `f`, so a bound on the extended integrals of the truncations is a bound on the extended integral of `f`. +For `f = log E` with `E` nonnegative, the truncations are bounded by real integrals: mixing `E` +with a constant `ε ∈ (0, 1)` bounds its logarithm below, at a cost of at most `- log (1 - ε)`. + ## Main statements * `MeasureTheory.eintegral_le_of_forall_min_le`: if the extended integrals of the truncations `min f k`, `k ∈ ℕ`, are at most `D`, so is the extended integral of `f`. +* `MeasureTheory.eintegral_min_log_le_integral_truncLog_sub`: under a probability measure, the + extended integral of `min (log E) k` is at most the integral of the truncated logarithm + `ENNReal.truncLog k ((1 - ε) E + ε)`, minus `log (1 - ε)`. -/ public section @@ -74,4 +83,26 @@ theorem eintegral_le_of_forall_min_le {Ω : Type*} [MeasurableSpace Ω] {μ : Me exact EReal.coe_ennreal_le_coe_ennreal_iff.2 (iSup_le fun k ↦ EReal.coe_ennreal_le_coe_ennreal_iff.1 (hk k)) +/-- Mixing with a constant, in expectation: the extended integral of the truncation at `k` of +`log E` is at most the integral of the truncated logarithm of `(1 - ε) E + ε`, minus +`log (1 - ε)`. -/ +theorem eintegral_min_log_le_integral_truncLog_sub {Ω : Type*} [MeasurableSpace Ω] + {μ : Measure Ω} [IsProbabilityMeasure μ] {E : Ω → ℝ≥0∞} {ε : ℝ} (hε0 : 0 < ε) (hε1 : ε < 1) + (k : ℕ) (hint : Integrable + (fun x ↦ ENNReal.truncLog k (ENNReal.ofReal (1 - ε) * E x + ENNReal.ofReal ε)) μ) : + ∫ᵉ x, min (ENNReal.log (E x)) k ∂μ ≤ + ((∫ x, ENNReal.truncLog k (ENNReal.ofReal (1 - ε) * E x + ENNReal.ofReal ε) ∂μ - + Real.log (1 - ε) : ℝ) : EReal) := by + calc ∫ᵉ x, min (ENNReal.log (E x)) k ∂μ + _ ≤ ∫ᵉ x, ((ENNReal.truncLog k (ENNReal.ofReal (1 - ε) * E x + ENNReal.ofReal ε) - + Real.log (1 - ε) : ℝ) : EReal) ∂μ := eintegral_mono fun x ↦ by + have := ENNReal.min_log_le_truncLog_sub hε0 hε1 (k : ℝ) (E x) + rwa [EReal.coe_natCast] at this + _ = ((∫ x, (ENNReal.truncLog k (ENNReal.ofReal (1 - ε) * E x + ENNReal.ofReal ε) - + Real.log (1 - ε)) ∂μ : ℝ) : EReal) := + eintegral_eq_integral (hint.sub (integrable_const _)) + _ = _ := by + rw [integral_sub hint (integrable_const _), integral_const] + simp + end MeasureTheory