|
| 1 | +/- |
| 2 | +Copyright (c) 2025 David Ledvinka. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: David Ledvinka |
| 5 | +-/ |
| 6 | +module |
| 7 | + |
| 8 | +public import Mathlib.MeasureTheory.Measure.Decomposition.Lebesgue |
| 9 | + |
| 10 | +import Mathlib.MeasureTheory.Measure.Decomposition.RadonNikodym |
| 11 | +import Mathlib.Probability.Notation |
| 12 | + |
| 13 | +/-! # Conditional Lebesgue expectation |
| 14 | +
|
| 15 | +We define the conditional expectation of a `ℝ≥0∞`-valued function using the Lebesgue integral. |
| 16 | +Given a measure `P : Measure[mΩ₀] Ω` and a sub-σ-algebra `mΩ` of `mΩ₀` (meaning `hm : mΩ ≤ mΩ₀`) |
| 17 | +and a function `X : Ω → ℝ≥0∞`, if `P.trim hm` is σ-finite, then the conditional (Lebesgue) |
| 18 | +expectation `P⁻[X|mΩ]` of `X` is the `mΩ`-measurable function such that for all |
| 19 | +`mΩ`-measurable sets `s`, `∫⁻ ω in s, P⁻[X|mΩ] ω ∂P = ∫⁻ ω in s, X ω ∂P` |
| 20 | +(see `setLIntegral_condLExp`). This is unique up to `P`-ae equality (see `ae_eq_condLExp`). |
| 21 | +
|
| 22 | +## Main definitions |
| 23 | +
|
| 24 | +* `condLExp` : conditional (Lebesgue) expectation of `X` with respect to `mΩ`. |
| 25 | +* `setLIntegral_condLExp`: For any `mΩ`-measurable set `s`, |
| 26 | + `∫⁻ ω in s, P⁻[X|mΩ] ω ∂P = ∫⁻ ω in s, X ω ∂P`. |
| 27 | +* `ae_eq_condLExp` : the conditional (Lebesgue) expectation is characterized by its (Lebesgue) |
| 28 | + integral on `mΩ`-measurable sets up to `P`-ae equality. |
| 29 | +
|
| 30 | +## Notation |
| 31 | +
|
| 32 | +For a measure `P : Measure[mΩ₀] Ω`, and another `mΩ : MeasurableSpace Ω`, we define the notation |
| 33 | +* `P⁻[X|mΩ] = condLExp mΩ P X` |
| 34 | +
|
| 35 | +## Design decisions |
| 36 | +
|
| 37 | +`P⁻[X|mΩ]` is assigned the junk value `0` when either `¬ mΩ ≤ mΩ₀` (`mΩ` is not a sub-σ-algebra) |
| 38 | +or `h : mΩ ≤ mΩ₀` but `¬ SigmaFinite (P.trim hm)` (the latter always holds when `P` is a |
| 39 | +probability measure). When both these hold, in some sense the "user definition" of `P⁻[X|mΩ]` |
| 40 | +should be considered "the" measurable function which satisfies `setLIntegral_condLExp` |
| 41 | +(which is proven unique up to `P`-ae measurable equality in `ae_eq_condLExp`). The actual definition |
| 42 | +is just used to show existence. However for (potential) convenience the actual definition assigns |
| 43 | +`P⁻[X|mΩ] := X` in the case when `X` is `mΩ`-measurable (which can be invoked using |
| 44 | +`condLExp_eq_self`). |
| 45 | +
|
| 46 | +## To do |
| 47 | +
|
| 48 | +* Prove the pullout property |
| 49 | +* Prove a dominated convergence theorem. |
| 50 | +
|
| 51 | +-/ |
| 52 | + |
| 53 | +public section |
| 54 | + |
| 55 | +open MeasureTheory ProbabilityTheory Measure |
| 56 | + |
| 57 | +open scoped ENNReal |
| 58 | + |
| 59 | +namespace MeasureTheory |
| 60 | + |
| 61 | +variable {Ω : Type*} {mΩ₀ mΩ : MeasurableSpace Ω} {P : Measure[mΩ₀] Ω} {X Y : Ω → ℝ≥0∞} |
| 62 | + |
| 63 | +open Classical in |
| 64 | +/-- Conditional (Lebesgue) expectation of a function, with notation `P⁻[X|mΩ]`. |
| 65 | +
|
| 66 | +It is defined as `0` if either `¬ mΩ ≤ mΩ₀` or `hm : mΩ ≤ mΩ₀` but `¬ SigmaFinite (P.trim hm)`. |
| 67 | +
|
| 68 | +One should typically not use the definition directly. |
| 69 | +-/ |
| 70 | +noncomputable irreducible_def condLExp (mΩ : MeasurableSpace Ω) (P : Measure[mΩ₀] Ω) |
| 71 | + (X : Ω → ℝ≥0∞) : Ω → ℝ≥0∞ := |
| 72 | + if hm : mΩ ≤ mΩ₀ then |
| 73 | + if SigmaFinite (P.trim hm) then |
| 74 | + if Measurable[mΩ] X then X else |
| 75 | + ∂((P.withDensity X).trim hm)/∂(P.trim hm) |
| 76 | + else 0 |
| 77 | + else 0 |
| 78 | + |
| 79 | +@[inherit_doc MeasureTheory.condLExp] |
| 80 | +scoped macro:max P:term noWs "⁻[" X:term "|" mΩ:term "]" : term => |
| 81 | + `(MeasureTheory.condLExp $mΩ $P $X) |
| 82 | + |
| 83 | +/-- Unexpander for `μ⁻[f|m]` notation. -/ |
| 84 | +@[app_unexpander MeasureTheory.condLExp] |
| 85 | +meta def condLExpUnexpander : Lean.PrettyPrinter.Unexpander |
| 86 | + | `($_ $mΩ $P $X) => `($P⁻[$X|$mΩ]) |
| 87 | + | _ => throw () |
| 88 | + |
| 89 | +/-- info: P⁻[X|mΩ] : Ω → ℝ≥0∞ -/ |
| 90 | +#guard_msgs in |
| 91 | +#check P⁻[X|mΩ] |
| 92 | +/-- info: P⁻[X|mΩ] sorry : ℝ≥0∞ -/ |
| 93 | +#guard_msgs in |
| 94 | +#check P⁻[X|mΩ] (sorry : Ω) |
| 95 | + |
| 96 | +theorem condLExp_of_not_le (hm_not : ¬mΩ ≤ mΩ₀) : P⁻[X|mΩ] = 0 := by |
| 97 | + rw [condLExp, dif_neg hm_not] |
| 98 | + |
| 99 | +theorem condLExp_of_not_sigmaFinite (hm : mΩ ≤ mΩ₀) (hμm_not : ¬SigmaFinite (P.trim hm)) : |
| 100 | + P⁻[X|mΩ] = 0 := by simp [condLExp, dif_pos hm, hμm_not] |
| 101 | + |
| 102 | +theorem condLExp_eq_self (hm : mΩ ≤ mΩ₀) (P : Measure[mΩ₀] Ω) [hσ : SigmaFinite (P.trim hm)] |
| 103 | + (hX : Measurable[mΩ] X) : P⁻[X|mΩ] = X := by |
| 104 | + simp [condLExp, hm, hσ, hX] |
| 105 | + |
| 106 | +theorem condLExp_of_not_sub_sigma_measurable (hm : mΩ ≤ mΩ₀) (P : Measure[mΩ₀] Ω) |
| 107 | + [hσ : SigmaFinite (P.trim hm)] {X : Ω → ℝ≥0∞} (hX : ¬Measurable[mΩ] X) : |
| 108 | + P⁻[X|mΩ] = ∂((P.withDensity X).trim hm)/∂(P.trim hm) := by |
| 109 | + simp [condLExp, hm, hσ, hX] |
| 110 | + |
| 111 | +@[fun_prop] |
| 112 | +theorem measurable_condLExp (mΩ : MeasurableSpace Ω) (P : Measure[mΩ₀] Ω) (X : Ω → ℝ≥0∞) : |
| 113 | + Measurable[mΩ] P⁻[X|mΩ] := by |
| 114 | + by_cases hm : mΩ ≤ mΩ₀ |
| 115 | + · by_cases hσ : SigmaFinite (P.trim hm) |
| 116 | + · by_cases hX : Measurable[mΩ] X |
| 117 | + · simp [condLExp_eq_self hm, hX] |
| 118 | + simp [condLExp_of_not_sub_sigma_measurable hm _ hX, measurable_rnDeriv] |
| 119 | + simp [condLExp_of_not_sigmaFinite hm hσ, measurable_zero] |
| 120 | + simp [condLExp_of_not_le hm, measurable_zero] |
| 121 | + |
| 122 | +@[fun_prop] |
| 123 | +theorem measurable_condLExp' (mΩ : MeasurableSpace Ω) (P : Measure[mΩ₀] Ω) (X : Ω → ℝ≥0∞) : |
| 124 | + Measurable[mΩ₀] P⁻[X|mΩ] := by |
| 125 | + by_cases hm : mΩ ≤ mΩ₀ |
| 126 | + · exact (measurable_condLExp _ _ _).mono hm (le_refl _) |
| 127 | + · simp [condLExp_of_not_le hm, measurable_zero] |
| 128 | + |
| 129 | +variable (hm : mΩ ≤ mΩ₀) |
| 130 | + |
| 131 | +/-- The (Lebesgue) integral of the conditional (Lebesgue) expectation `P⁻[X|mΩ]` over an |
| 132 | +`mΩ`-measurable set is equal to the integral of `X` on that set. -/ |
| 133 | +theorem setLIntegral_condLExp (P : Measure[mΩ₀] Ω) [hσ : SigmaFinite (P.trim hm)] |
| 134 | + (X : Ω → ℝ≥0∞) {s : Set Ω} (hs : MeasurableSet[mΩ] s) : |
| 135 | + ∫⁻ ω in s, P⁻[X|mΩ] ω ∂P = ∫⁻ ω in s, X ω ∂P := by |
| 136 | + by_cases hX : Measurable[mΩ] X |
| 137 | + · simp [condLExp_eq_self hm _ hX] |
| 138 | + have h := AbsolutelyContinuous.trim (withDensity_absolutelyContinuous P X) hm |
| 139 | + have : SFinite ((P.withDensity X).trim hm) := sFinite_of_absolutelyContinuous h |
| 140 | + rw [condLExp_of_not_sub_sigma_measurable hm _ hX, ← lintegral_indicator (hm s hs), |
| 141 | + ← lintegral_trim hm (by measurability), lintegral_indicator hs, setLIntegral_rnDeriv' h hs, |
| 142 | + trim_measurableSet_eq hm hs, withDensity_apply _ (hm s hs)] |
| 143 | + |
| 144 | +theorem setLIntegral_condLExp_trim (P : Measure[mΩ₀] Ω) [hσ : SigmaFinite (P.trim hm)] |
| 145 | + (X : Ω → ℝ≥0∞) {s : Set Ω} (hs : MeasurableSet[mΩ] s) : |
| 146 | + ∫⁻ ω in s, P⁻[X|mΩ] ω ∂P.trim hm = ∫⁻ ω in s, X ω ∂P := by |
| 147 | + rw [setLIntegral_trim hm (measurable_condLExp _ _ _) hs, setLIntegral_condLExp _ _ _ hs] |
| 148 | + |
| 149 | +theorem lintegral_condLExp (P : Measure[mΩ₀] Ω) [hσ : SigmaFinite (P.trim hm)] (X : Ω → ℝ≥0∞) : |
| 150 | + ∫⁻ ω, P⁻[X|mΩ] ω ∂P = ∫⁻ ω, X ω ∂P := by |
| 151 | + simpa [← setLIntegral_univ] using setLIntegral_condLExp _ _ _ .univ |
| 152 | + |
| 153 | +theorem ae_eq_condLExp₀ {P : Measure[mΩ₀] Ω} [hσ : SigmaFinite (P.trim hm)] |
| 154 | + (X : Ω → ℝ≥0∞) (hY : AEMeasurable[mΩ] Y (P.trim hm)) |
| 155 | + (hXY : ∀ s, MeasurableSet[mΩ] s → ∫⁻ ω in s, Y ω ∂P = ∫⁻ ω in s, X ω ∂P) : |
| 156 | + Y =ᵐ[P] P⁻[X|mΩ] := by |
| 157 | + apply ae_eq_of_ae_eq_trim |
| 158 | + apply ae_eq_of_forall_setLIntegral_eq_of_sigmaFinite₀ hY (by fun_prop) |
| 159 | + intro s hs _ |
| 160 | + rw [setLIntegral_trim_ae hm hY hs, setLIntegral_condLExp_trim _ _ _ hs] |
| 161 | + exact hXY s hs |
| 162 | + |
| 163 | +/- The conditional (Lebesgue) expectation `P⁻[X|mΩ]` is defined uniquely as an `mΩ`-measurable |
| 164 | +function up to `P`-ae equality by its (Lebesgue) integral over all `mΩ`-measurable sets. -/ |
| 165 | +theorem ae_eq_condLExp (P : Measure[mΩ₀] Ω) [hσ : SigmaFinite (P.trim hm)] |
| 166 | + (X : Ω → ℝ≥0∞) (hY : Measurable[mΩ] Y) |
| 167 | + (hXY : ∀ s, MeasurableSet[mΩ] s → ∫⁻ ω in s, Y ω ∂P = ∫⁻ ω in s, X ω ∂P) : |
| 168 | + Y =ᵐ[P] P⁻[X|mΩ] := ae_eq_condLExp₀ _ _ hY.aemeasurable hXY |
| 169 | + |
| 170 | +theorem condLExp_const (P : Measure[mΩ₀] Ω) [hσ : SigmaFinite (P.trim hm)] (c : ℝ≥0∞) : |
| 171 | + P⁻[fun _ : Ω ↦ c|mΩ] = fun _ ↦ c := condLExp_eq_self _ _ (measurable_const) |
| 172 | + |
| 173 | +@[gcongr] |
| 174 | +theorem condLExp_congr_ae {P : Measure[mΩ₀] Ω} |
| 175 | + {X Y : Ω → ℝ≥0∞} (hXY : X =ᵐ[P] Y) : P⁻[X|mΩ] =ᵐ[P] P⁻[Y|mΩ] := by |
| 176 | + by_cases hm : mΩ ≤ mΩ₀ |
| 177 | + · by_cases hσ : SigmaFinite (P.trim hm) |
| 178 | + · refine ae_eq_condLExp _ _ _ (measurable_condLExp _ _ _) (fun s hs ↦ ?_) |
| 179 | + rw [setLIntegral_condLExp _ _ _ hs] |
| 180 | + apply setLIntegral_congr_fun_ae (hm s hs) |
| 181 | + filter_upwards [hXY] with _ h _ using h |
| 182 | + simp [condLExp_of_not_sigmaFinite hm hσ] |
| 183 | + simp [condLExp_of_not_le hm] |
| 184 | + |
| 185 | +@[gcongr] |
| 186 | +theorem condLExp_congr_ae_trim {P : Measure[mΩ₀] Ω} {X Y : Ω → ℝ≥0∞} (hXY : X =ᵐ[P] Y) : |
| 187 | + P⁻[X|mΩ] =ᵐ[P.trim hm] P⁻[Y|mΩ] := by |
| 188 | + apply ae_eq_trim_of_measurable hm (measurable_condLExp _ _ X) (measurable_condLExp _ _ Y) |
| 189 | + exact condLExp_congr_ae hXY |
| 190 | + |
| 191 | +theorem condLExp_bot' (P : Measure[mΩ₀] Ω) [NeZero P] (X : Ω → ℝ≥0∞) : |
| 192 | + P⁻[X|⊥] = fun _ => (P .univ)⁻¹ • ∫⁻ ω, X ω ∂P := by |
| 193 | + by_cases hP : IsFiniteMeasure P; swap |
| 194 | + · have hσ : ¬SigmaFinite (P.trim bot_le) := by rwa [sigmaFinite_trim_bot_iff] |
| 195 | + rw [not_isFiniteMeasure_iff] at hP |
| 196 | + rw [condLExp_of_not_sigmaFinite bot_le hσ] |
| 197 | + simpa [hP] using (by rfl) |
| 198 | + obtain ⟨c, h_eq⟩ := eq_const_of_measurable_bot (measurable_condLExp ⊥ P X) |
| 199 | + ext _ |
| 200 | + rw [← lintegral_condLExp bot_le] |
| 201 | + simp [h_eq, mul_comm, mul_assoc, ENNReal.mul_inv_cancel |
| 202 | + (NeZero.ne (P .univ)) (measure_ne_top _ _)] |
| 203 | + |
| 204 | +theorem condLExp_bot_ae_eq (P : Measure[mΩ₀] Ω) (X : Ω → ℝ≥0∞) : |
| 205 | + P⁻[X|⊥] =ᵐ[P] fun _ => (P .univ)⁻¹ • ∫⁻ ω, X ω ∂P := by |
| 206 | + rcases eq_zero_or_neZero P with rfl | hP |
| 207 | + · rw [ae_zero]; exact Filter.eventually_bot |
| 208 | + exact ae_of_all P <| congr_fun (condLExp_bot' P X) |
| 209 | + |
| 210 | +theorem condLExp_bot (P : Measure[mΩ₀] Ω) [IsProbabilityMeasure P] (X : Ω → ℝ≥0∞) : |
| 211 | + P⁻[X|⊥] = fun _ => ∫⁻ ω, X ω ∂P := |
| 212 | + (condLExp_bot' P X).trans (by simp) |
| 213 | + |
| 214 | +theorem condLExp_mono (hXY : X ≤ᵐ[P] Y) : |
| 215 | + P⁻[X|mΩ] ≤ᵐ[P] P⁻[Y|mΩ] := by |
| 216 | + by_cases hm : mΩ ≤ mΩ₀ |
| 217 | + swap; · simp_rw [condLExp_of_not_le hm]; rfl |
| 218 | + by_cases hσ : SigmaFinite (P.trim hm) |
| 219 | + swap; · simp_rw [condLExp_of_not_sigmaFinite hm hσ]; rfl |
| 220 | + apply ae_le_of_ae_le_trim |
| 221 | + apply ae_le_of_forall_setLIntegral_le_of_sigmaFinite (μ := P.trim hm) (by fun_prop) |
| 222 | + intro s hs _ |
| 223 | + repeat rw [setLIntegral_condLExp_trim hm _ _ hs] |
| 224 | + apply setLIntegral_mono_ae' (hm s hs) |
| 225 | + filter_upwards [hXY] using fun _ h _ ↦ h |
| 226 | + |
| 227 | +theorem condLExp_add_le (X Y : Ω → ℝ≥0∞) : |
| 228 | + P⁻[X|mΩ] + P⁻[Y|mΩ] ≤ᵐ[P] P⁻[X + Y|mΩ] := by |
| 229 | + by_cases hm : mΩ ≤ mΩ₀; swap |
| 230 | + · simp_rw [condLExp_of_not_le hm]; filter_upwards; simp |
| 231 | + by_cases hσ : SigmaFinite (P.trim hm); swap |
| 232 | + · simp_rw [condLExp_of_not_sigmaFinite hm hσ]; filter_upwards; simp |
| 233 | + apply ae_le_of_ae_le_trim |
| 234 | + apply ae_le_of_forall_setLIntegral_le_of_sigmaFinite (μ := P.trim hm) (by fun_prop) |
| 235 | + intro s hs _ |
| 236 | + simp only [Pi.add_apply] |
| 237 | + rw [lintegral_add_left (by fun_prop)] |
| 238 | + repeat rw [setLIntegral_condLExp_trim hm _ _ hs] |
| 239 | + grw [le_lintegral_add] |
| 240 | + simp |
| 241 | + |
| 242 | +theorem condLExp_add_left {X : Ω → ℝ≥0∞} (Y : Ω → ℝ≥0∞) (hX : AEMeasurable[mΩ₀] X P) : |
| 243 | + P⁻[X + Y|mΩ] =ᵐ[P] P⁻[X|mΩ] + P⁻[Y|mΩ] := by |
| 244 | + by_cases hm : mΩ ≤ mΩ₀ |
| 245 | + swap; · simp_rw [condLExp_of_not_le hm]; simp |
| 246 | + by_cases hσ : SigmaFinite (P.trim hm) |
| 247 | + swap; · simp_rw [condLExp_of_not_sigmaFinite hm hσ]; simp |
| 248 | + refine (ae_eq_condLExp _ _ _ (by fun_prop) ?_).symm |
| 249 | + intro s hs |
| 250 | + simp only [Pi.add_apply] |
| 251 | + rw [lintegral_add_left (by measurability)] |
| 252 | + repeat rw [setLIntegral_condLExp hm _ _ hs] |
| 253 | + rw [lintegral_add_left' (by fun_prop)] |
| 254 | + |
| 255 | +theorem condLExp_add_right (X : Ω → ℝ≥0∞) {Y : Ω → ℝ≥0∞} (hY : AEMeasurable[mΩ₀] Y P) : |
| 256 | + P⁻[X + Y|mΩ] =ᵐ[P] P⁻[X|mΩ] + P⁻[Y|mΩ] := by |
| 257 | + rw [add_comm, add_comm P⁻[X|mΩ]] |
| 258 | + exact condLExp_add_left X hY |
| 259 | + |
| 260 | +theorem condLExp_smul (X : Ω → ℝ≥0∞) (hX : AEMeasurable[mΩ₀] X P) (c : ℝ≥0∞) : |
| 261 | + P⁻[c • X|mΩ] =ᵐ[P] c • P⁻[X|mΩ] := by |
| 262 | + by_cases hm : mΩ ≤ mΩ₀ |
| 263 | + swap; · simp [condLExp_of_not_le hm] |
| 264 | + by_cases hσ : SigmaFinite (P.trim hm) |
| 265 | + swap; · simp [condLExp_of_not_sigmaFinite hm hσ] |
| 266 | + refine (ae_eq_condLExp _ _ _ (by fun_prop) ?_).symm |
| 267 | + intro s hs |
| 268 | + simp only [Pi.smul_apply, smul_eq_mul] |
| 269 | + rw [lintegral_const_mul, lintegral_const_mul'', setLIntegral_condLExp _ _ _ hs] |
| 270 | + all_goals fun_prop |
| 271 | + |
| 272 | +theorem condLExp_smul_le (X : Ω → ℝ≥0∞) {c : ℝ≥0∞} : |
| 273 | + c • P⁻[X|mΩ] ≤ᵐ[P] P⁻[c • X|mΩ] := by |
| 274 | + by_cases hm : mΩ ≤ mΩ₀; swap |
| 275 | + · simp_rw [condLExp_of_not_le hm]; filter_upwards; simp |
| 276 | + by_cases hσ : SigmaFinite (P.trim hm); swap |
| 277 | + · simp_rw [condLExp_of_not_sigmaFinite hm hσ]; filter_upwards; simp |
| 278 | + apply ae_le_of_ae_le_trim |
| 279 | + apply ae_le_of_forall_setLIntegral_le_of_sigmaFinite (μ := P.trim hm) (by fun_prop) |
| 280 | + intro s hs _ |
| 281 | + simp [setLIntegral_condLExp_trim _ _ _ hs, lintegral_const_mul _ (measurable_condLExp _ P X), |
| 282 | + lintegral_const_mul_le] |
| 283 | + |
| 284 | +theorem condLExp_smul' (X : Ω → ℝ≥0∞) {c : ℝ≥0∞} (hc : c ≠ ∞) : |
| 285 | + P⁻[c • X|mΩ] =ᵐ[P] c • P⁻[X|mΩ] := by |
| 286 | + by_cases hm : mΩ ≤ mΩ₀ |
| 287 | + swap; · simp [condLExp_of_not_le hm] |
| 288 | + by_cases hσ : SigmaFinite (P.trim hm) |
| 289 | + swap; · simp [condLExp_of_not_sigmaFinite hm hσ] |
| 290 | + refine (ae_eq_condLExp _ _ _ (by fun_prop) ?_).symm |
| 291 | + intro s hs |
| 292 | + simp only [Pi.smul_apply, smul_eq_mul] |
| 293 | + rw [lintegral_const_mul' _ _ hc, lintegral_const_mul' _ _ hc, setLIntegral_condLExp _ _ _ hs] |
| 294 | + |
| 295 | +end MeasureTheory |
0 commit comments