From 5870d7cc4b3b96c1a0557421b647d8aaf7f2a1d2 Mon Sep 17 00:00:00 2001 From: Lionel Blatter Date: Wed, 29 Jul 2026 23:18:38 +0200 Subject: [PATCH 01/18] Counting distribution --- _CoqProject | 1 + theories/numfun.v | 14 + theories/probability_theory/counting_distr.v | 2100 ++++++++++++++++++ 3 files changed, 2115 insertions(+) create mode 100644 theories/probability_theory/counting_distr.v diff --git a/_CoqProject b/_CoqProject index 0dcbd12ffa..8e1c0e06e3 100644 --- a/_CoqProject +++ b/_CoqProject @@ -152,6 +152,7 @@ theories/probability_theory/poisson_distribution.v theories/probability_theory/beta_distribution.v theories/probability_theory/probability.v theories/probability_theory/independence.v +theories/probability_theory/counting_distr.v theories/convex.v theories/charge.v diff --git a/theories/numfun.v b/theories/numfun.v index 448bb9c0c6..24d5332603 100644 --- a/theories/numfun.v +++ b/theories/numfun.v @@ -768,6 +768,20 @@ rewrite funeqE => x /=; rewrite !fctE/=; have [fx0|/ltW fx0] := leP (f x) 0. by move: fx0; rewrite -{1}oppr0 lerNl => /max_idPr ->; rewrite addr0. Qed. +Lemma le_funrpos f x: `|f^\+ x| <= `|f x|. +Proof. +rewrite ger0_norm ?funrpos_ge0//. +have := funrposDneg f => /(congr1 (fun g => g x)); rewrite /= => <-. +by rewrite lerDl funrneg_ge0. +Qed. + +Lemma le_funrneg f x: `|f^\- x| <= `|f x|. +Proof. +rewrite ger0_norm ?funrneg_ge0//. +have := funrposDneg f => /(congr1 (fun g => g x)); rewrite /= => <-. +by rewrite lerDr funrpos_ge0. +Qed. + Lemma funrposBneg f : f^\+ - f^\- = f. Proof. apply/funext => x. diff --git a/theories/probability_theory/counting_distr.v b/theories/probability_theory/counting_distr.v new file mode 100644 index 0000000000..6b4acec285 --- /dev/null +++ b/theories/probability_theory/counting_distr.v @@ -0,0 +1,2100 @@ +From HB Require Import structures. +From mathcomp Require Import boot order algebra. +From mathcomp.classical Require Import boolp classical_sets mathcomp_extra. +From mathcomp Require Import xfinmap constructive_ereal reals discrete. +From mathcomp Require Import realseq realsum. +From mathcomp Require Import esum sequences normedtype ereal cardinality fsbigop. + +(* Should be removed *) +From mathcomp Require Import numfun. + +Set Implicit Arguments. +Unset Strict Implicit. +Unset Printing Implicit Defensive. +Unset SsrOldRewriteGoalsOrder. (* remove this line when requiring MathComp >= 2.6 *) + +Import Order.TTheory GRing.Theory Num.Theory. + +Local Open Scope ring_scope. + +(* -------------------------------------------------------------------- *) +Local Notation simpm := Monoid.simpm. + +(* -------------------------------------------------------------------- *) +Reserved Notation "\dlet_ ( i <- d ) E" + (at level 36, E at level 36, i, d at level 50, + format "'[' \dlet_ ( i <- d ) '/ ' E ']'"). + +Reserved Notation "\dlim_ ( n ) E" + (at level 36, E at level 36, n at level 50, + format "'[' \dlim_ ( n ) '/ ' E ']'"). + +Reserved Notation "\P_[ mu ] E" (at level 2, format "\P_[ mu ] E"). +Reserved Notation "\P_[ mu , A ] E" (at level 2, format "\P_[ mu , A ] E"). +Reserved Notation "\E?_[ mu ] f" (at level 2, format "\E?_[ mu ] f"). +Reserved Notation "\E_[ mu ] f" (at level 2, format "\E_[ mu ] f"). +Reserved Notation "\E_[ mu , A ] f" (at level 2, format "\E_[ mu , A ] f"). +Reserved Notation "\Ee_[ mu ] f" (at level 2, format "\Ee_[ mu ] f"). + +Local Notation "\`| f |" := (fun x => `|f x|) (at level 2). + +(* -------------------------------------------------------------------- *) + +HB.mixin Record isDistribution (R : realType) (T : choiceType) (mu : T -> R) := + { + mu_positive : forall x, 0 <= mu x ; + mu_summable : summable [set: T] (EFin \o mu); + mu_sum_le_one : (esum [set: T] (EFin \o mu) <= 1)%E; + }. + +HB.structure Definition Distribution (R : realType) (T : choiceType) := + {f of @isDistribution R T f}. + +Notation "{ 'distr' T / R }" := (@Distribution.type R T) + (at level 0, T at level 2, format "{ 'distr' T / R }") + : type_scope. + +(* -------------------------------------------------------------------- *) +Section DistrCoreTh. +Context {R : realType} (T : choiceType) (mu : {distr T / R}). + +Lemma ge0_mu : forall x, 0 <= mu x. +Proof. exact: mu_positive. Qed. + +Lemma le1_mu : (esum [set: T] (EFin \o mu) <= 1)%E. +Proof. exact: mu_sum_le_one. Qed. + +Lemma summable_mu : summable [set: T] (EFin \o mu). +Proof. exact: mu_summable. Qed. +End DistrCoreTh. + +#[global] Hint Extern 0 (is_true (0 <= _)) => solve [apply: ge0_mu] : core. +#[global] Hint Resolve le1_mu summable_mu : core. + +(* -------------------------------------------------------------------- *) +Section Clamp. +Context {R : realType}. + +Definition clamp (x : R) := + Num.max (Num.min x 1) 0. + +Lemma ge0_clamp x : 0 <= clamp x. +Proof. by rewrite le_max lexx orbT. Qed. + +Lemma le1_clamp x : clamp x <= 1. +Proof. by rewrite ge_max ge_min lexx ler01 orbT. Qed. + +Definition cp01_clamp := (ge0_clamp, le1_clamp). + +Lemma clamp_in01 x : 0 <= x <= 1 -> clamp x = x. +Proof. by case/andP=> ge0_x le1_x; rewrite /clamp min_l ?max_l. Qed. + +Lemma clamp_id x : clamp (clamp x) = clamp x. +Proof. by rewrite clamp_in01 // !cp01_clamp. Qed. + +Lemma clamp0 : clamp 0 = 0. +Proof. by rewrite clamp_in01 // lexx ler01. Qed. + +Lemma clamp1 : clamp 1 = 1. +Proof. by rewrite clamp_in01 // lexx ler01. Qed. +End Clamp. + +(* -------------------------------------------------------------------- *) +Section StdDefs. +Context {R : realType} (T : choiceType). + +Implicit Types (mu : {distr T / R}) (A B E : pred T) (f : T -> R). + +Definition dinsupp mu := fun x => mu x != 0 :> R. + +Lemma in_dinsupp x (mu : {distr T / R}) : + (x \in dinsupp mu) = (mu x != 0). +Proof. by []. Qed. + +Lemma dinsuppP mu x : reflect (mu x <> 0) (x \in dinsupp mu). +Proof. by apply: (iffP idP) => /eqP. Qed. + +Lemma dinsuppPn mu x : reflect (mu x = 0) (x \notin dinsupp mu). +Proof. by rewrite -topredE /dinsupp /= negbK; apply/eqP. Qed. + +Definition pr mu E := fine (esum [set: T] (EFin \o (fun x => (E x)%:R * mu x))). +Definition prc mu E A := pr mu [predI E & A] / pr mu A. +Definition esp mu f := fine (esum [set: T] (EFin \o (fun x => f x * mu x))). +Definition espc mu f A := fine (esum [set: T] (EFin \o (fun x => f x * prc mu (pred1 x) A))). + +Definition has_esp mu f := summable [set: T] (EFin \o (fun x => f x * mu x)). +End StdDefs. + +Notation "\P_[ mu ] E" := (pr mu E). +Notation "\P_[ mu , A ] E" := (prc mu E A). +Notation "\E_[ mu ] f" := (esp mu f). +Notation "\E_[ mu , A ] f" := (espc mu f A). +Notation "\E?_[ mu ] f" := (has_esp mu f). +Notation dweight mu := (\P_[mu] predT). + +(* -------------------------------------------------------------------- *) +Section DistrTheory. +Context {R : realType} {T : choiceType} (mu : T -> R). + +Definition isdistr := + (forall x, 0 <= mu x) /\ (forall J, uniq J -> \sum_(j <- J) mu j <= 1). + +Hypothesis isd : isdistr. + +Local Lemma isd1 : forall x, 0 <= mu x. +Proof. by case: isd. Qed. + +Local Lemma isd2 : summable [set: T] (EFin \o mu). +Proof. +case isd => ? h2. +rewrite /summable (@le_lt_trans _ _ 1%:E) ?ltey//. +rewrite ge0_esum // ge_ereal_sup//= => _ [X [finX _]] <-. +rewrite fsumEFin // lee_fin fsbig_finite //=. +rewrite (eq_bigr (fun x => mu x)). ++ by move => ??; rewrite ger0_norm. +by apply: h2. +Qed. + +Local Lemma isd3 : (esum [set: T] (EFin \o mu) <= 1)%E. +Proof. +case isd => ? h2. +rewrite ge0_esum. ++ by move => ? _;rewrite lee_fin. +rewrite ge_ereal_sup//= => _ [X [finX _]] <-. +rewrite fsumEFin // lee_fin fsbig_finite //=. +by apply: h2. +Qed. + +Definition mkdistrd := @isDistribution.Build R T mu isd1 isd2 isd3. + +Definition ispredistr {T : choiceType} (mu : T -> R) := + [/\ forall x, 0 <= mu x & summable [set: T] (EFin \o mu)]. + +End DistrTheory. + +Lemma isdistr_finP {R : realType} {I : finType} (mu : I -> R) : + (isdistr mu) <-> (forall x, 0 <= mu x) /\ (\sum_j mu j <= 1). +Proof. split=> -[ ge0_mu le1]; split=> //. ++ by apply/le1; rewrite /index_enum -enumT enum_uniq. ++ move=> J uqJ; rewrite big_uniq 1?(le_trans _ le1) //=. + by rewrite [X in _<=X](bigID (mem J)) /= lerDl sumr_ge0. +Qed. + +Lemma le1_mu1 + {R : realType} {T : choiceType} (mu : {distr T / R}) x : mu x <= 1. +Proof. +case mu => //= {}mu [[?]]. +rewrite summableE => ??. +rewrite -lee_fin. +apply/(@le_trans _ _ ((esum [set: T] (EFin \o mu))))=> //. +rewrite esum_ge1 //. +by move => ? _;rewrite lee_fin. +Qed. + +(* -------------------------------------------------------------------- *) +Section DistrD. +Context {R : realType} {T : choiceType}. + +Definition dnull := fun x : T => (0 : R). + +Lemma isd_mnull : isdistr dnull. +Proof. by split=> // J _; rewrite big1 ?ler01. Qed. + +HB.instance Definition _ := @mkdistrd R T dnull isd_mnull. + +Lemma dnullE x : dnull x = 0. +Proof. by []. Qed. + +End DistrD. + +(* -------------------------------------------------------------------- *) +Lemma lef_dnull {R : realType} {T : choiceType} (mu : {distr T / R}) : + dnull <=1 mu. +Proof. by move=> x; rewrite dnullE ge0_mu. Qed. + +(* -------------------------------------------------------------------- *) +Section Restr. +Context (R : realType) (T : choiceType) (p : pred T). + +Definition drestr (mu : {distr T / R}) := + fun x => if p x then mu x else 0. + +Lemma isd_drestr (mu : {distr T / R}) : isdistr (drestr mu). +Proof. +split=> [x|J]; first by rewrite /drestr; case: ifP. +move=> eqJ; apply/(@le_trans _ _ (\sum_(j <- J) `|mu j|)). ++ apply/ler_sum=> i _; rewrite /drestr; case: ifPn=> _. + by apply/ler_norm. by apply/normr_ge0. ++ rewrite -lee_fin. + apply/(le_trans _ (le1_mu mu)). + case mu => //= {}mu [[?]]; rewrite summableE => ? _. + rewrite (@eq_esum _ _ _ _ (fun y : T => `|(EFin \o mu) y|%E)) //=. + + by move => ??; rewrite ger0_norm. + exact: sum_esum_ge. +Qed. + +HB.instance Definition _ (mu : {distr T / R}) := + @mkdistrd R T (drestr mu) (isd_drestr mu). + +Lemma drestrE (mu : {distr T / R}) x : + drestr mu x = if p x then mu x else 0. +Proof. by []. Qed. +End Restr. + +(* -------------------------------------------------------------------- *) +Section RestrTheory. +Context {R : realType} {T : choiceType}. + +Lemma drestrD (mu : {distr T / R}) (p : pred T) x : + mu x = drestr p mu x + drestr (predC p) mu x. +Proof. by rewrite !drestrE !inE; case: ifPn; rewrite /= (addr0, add0r). Qed. + +Lemma dinsupp_restr (mu : {distr T / R}) (p : pred T) x : + (x \in dinsupp (drestr p mu)) = (x \in dinsupp mu) && p x. +Proof. +apply/dinsuppP/idP. +- by rewrite /= drestrE; case: ifP=> // _ /dinsuppP ->. +- by case/andP; rewrite /= drestrE => /dinsuppP ? ->. +Qed. +End RestrTheory. + +(* -------------------------------------------------------------------- *) +Section DRat. +Context {R : realType} (T : choiceType). + +Local Notation distr := {distr T / R}. + +Implicit Types (s : seq T). + +Definition drat (s : seq T) : T -> R := + fun x : T => (count (pred1 x) s)%:R / (size s)%:R. + +Lemma ge0_drat s : forall x, 0 <= drat s x. +Proof. by move=> x; rewrite mulr_ge0 ?invr_ge0 // ler0n. Qed. + +Local Lemma has_sup_drat s J : uniq J -> \sum_(i <- J) drat s i <= 1. +Proof. +move=> uqJ; rewrite -mulr_suml /= -natr_sum; case: (size s =P 0%N). + by move=> ->; rewrite invr0 mulr0 ler01. +move=> /eqP nz_s; rewrite ler_pdivrMr ?ltr0n ?lt0n // mul1r. +rewrite ler_nat (bigID (mem s)) /= [X in (_+X)%N]big1 ?addn0. + by move=> i /count_memPn. +have ->: (size s = \sum_(i <- undup s) count_mem i s)%N. + rewrite -sum1_size -big_undup_iterop_count; apply: eq_bigr => i _. + by rewrite Monoid.iteropE iter_addn addn0 mul1n. +rewrite [X in (_<=X)%N](bigID (mem J)) /= -ltnS -addSn. +rewrite ltn_addr //= ltnS -big_filter -[X in (_<=X)%N]big_filter. +rewrite leq_eqVlt; apply/orP; left; apply/eqP/perm_big. +apply/uniq_perm; rewrite ?filter_uniq ?undup_uniq //. +by move=> x; rewrite !mem_filter mem_undup andbC. +Qed. + +Local Lemma drat_sup s : (0 < size s)%N -> + \sum_(i <- undup s) drat s i = 1. +Proof. +move=> gt0_s; rewrite -mulr_suml -natr_sum. +apply/(mulIf (x := (size s)%:R)); first by rewrite pnatr_eq0 -lt0n. +rewrite mul1r divfK ?pnatr_eq0 -?lt0n//; congr (_%:R). +rewrite -sum1_size -[in RHS]big_undup_iterop_count/=; apply: eq_bigr => i _. +by rewrite Monoid.iteropE iter_addn addn0 mul1n. +Qed. + +Local Lemma summable_drat s: summable [set :T] (EFin \o (drat s)). +Proof. +rewrite /summable (@le_lt_trans _ _ 1%:E) ?ltey//. +rewrite ge0_esum // ge_ereal_sup//= => _ [X [finX _]] <-. +rewrite fsumEFin // lee_fin fsbig_finite //=. +rewrite (eq_bigr (drat s)). ++ move => ??; rewrite ger0_norm ?ge0_drat //. +by apply/has_sup_drat. +Qed. + +Lemma isd_drat s : isdistr (drat s). +Proof. by split; [apply/ge0_drat | apply/has_sup_drat]. Qed. + +HB.instance Definition _ (s : seq T) := + @mkdistrd R T (drat s) (isd_drat s). + +Lemma drat1E s x : + drat s x = (count_mem x s)%:R / (size s)%:R. +Proof. by []. Qed. + +Definition dunit x := @locked {distr T / R} (drat [:: x] ). +Definition duni s := @locked {distr T / R} (drat (undup s)). + +Lemma dunit1E x y : (dunit x) y = (x == y)%:R. +Proof. by unlock dunit; rewrite /= drat1E /= !(simpm, invr1). Qed. + +Lemma dunit_id x : (dunit x) x = 1. +Proof. by unlock dunit; rewrite /= drat1E /= !(simpm, invr1) eq_refl. Qed. + +Lemma dunit_diff x y: x <> y -> (dunit x) y = 0. +Proof. + unlock dunit; rewrite /= drat1E /= !(simpm, invr1). + by case_eq (x == y) => //= /eqP. +Qed. + +Lemma duni1E s x : (duni s) x = (x \in s)%:R / (size (undup s))%:R. +Proof. by unlock duni; rewrite /= drat1E count_uniq_mem ?(mem_undup, undup_uniq). Qed. + +Lemma in_dunit t t' : + t' \in dinsupp (dunit t) -> t' = t :> T. +Proof. by rewrite in_dinsupp /= dunit1E pnatr_eq0 eqb0 negbK => /eqP. Qed. +End DRat. + +(* -------------------------------------------------------------------- *) +Section Flip. +Context {R : realType}. + +Definition dflip (xt : R) := + fun b => if b then clamp xt else 1 - clamp xt. + +Lemma isd_dflip xt : isdistr (dflip xt). +Proof. apply/isdistr_finP; split=> [b|]. ++ by case: b; rewrite ?subr_ge0 cp01_clamp. ++ by rewrite /index_enum !unlock /= addr0 addrC subrK. +Qed. + +HB.instance Definition _ (xt : R) := + @mkdistrd R _ (dflip xt) (isd_dflip xt). + +Lemma dflip1E xt : dflip xt =1 (fun b => if b then clamp xt else 1 - clamp xt). +Proof. by []. Qed. +End Flip. + +(* -------------------------------------------------------------------- *) +Section Bind. +Context {R : realType} {T U : choiceType} + (f : T -> {distr U / R}) (mu : {distr T /R}). + +Definition dlet := fun y : U => fine (esum [set:T] (fun x => EFin (mu x * f x y))). + +Lemma dlet_pos x : 0 <= fine (\esum_(x0 in [set: T]) (mu x0 * f x0 x)%:E). +Proof. +rewrite /fine. +case h : (\esum_(i in [set: T]) _) => //=. +rewrite -lee_fin -{}h esum_ge0 // => ??. +by rewrite EFinM mule_ge0 //= lee_tofin. +Qed. + +Lemma isd_dlet : isdistr dlet. +Proof. +split=> [x|J uqJ]. ++ exact: dlet_pos. ++ rewrite /dlet -lee_fin. + have hpos : (forall x i, 0 <= (mu x * f x i)%:E )%E. + + by move => ?? ;rewrite EFinM mule_ge0 //= lee_tofin. + apply /le_trans. + + apply sum_esum_ge => // x. + exact: dlet_pos. + apply/(le_trans _ (le1_mu mu)). + apply/(le_trans (le_esum_fine _ _ hpos)). + rewrite exchange_esum // le_esum // => i ?. + under eq_esum do rewrite EFinM. + rewrite esumZ // ?lee_tofin // => [? |]; rewrite ?lee_tofin //=. + rewrite muleC gee_pMl // ?lee_tofin //;last first. exact : (le1_mu (f i)). + rewrite (eq_esum _ _ (fun x => `|(EFin \o f i) x|%E)) //. + + by move => ??; rewrite gee0_abs //= lee_tofin. + by have := (summable_mu (f i)); rewrite summableE. +Qed. + +HB.instance Definition _ := @mkdistrd R U dlet isd_dlet. + +Lemma dletE y : dlet y = fine (esum [set:T] (fun x => EFin (mu x * f x y))). +Proof. by []. Qed. +End Bind. + +Notation "\dlet_ ( i <- d ) E" := (dlet (fun i => E) d). + +Definition dlift {R : realType} {T : choiceType} (f : T -> {distr T / R}) := + fun d => \dlet_(x <- d) f x. + +Definition diter {R : realType} {T : choiceType} n (f : T -> {distr T / R}) := + fun a => (iter n (dlift f) (dunit a)). + +(* -------------------------------------------------------------------- *) +Lemma esum_abse {R : realType} {T : choiceType} + (f : T -> R) : + (forall i, 0%R <= f i) -> + (\esum_(x in [set: T]) (f x)%:E = \esum_(x in [set: T]) `|(f x)%:E|)%E. +Proof. by move => ?; apply eq_esum => ?? ; rewrite gee0_abs // lee_tofin. Qed. + +Lemma summable_mu_wgtd {R : realType} {T : choiceType} + (f : T -> R) (mu : {distr T / R}) : + (forall x, 0 <= f x <= 1) -> summable [set: T] (fun x => EFin (mu x * f x)). +Proof. +rewrite /summable => h. +under eq_esum do rewrite EFinM. +apply: esummableMr => //. ++ exists 1%E => // => i. + case /andP: (h i) => ?? ; rewrite lee_tofin // ger0_norm //. +exact : (summable_mu mu). +Qed. + +(* -------------------------------------------------------------------- *) +Section BindTheory. +Variables (R : realType) (T U : choiceType). + +Implicit Types (f g : T -> {distr U / R}) (mu nu : {distr T / R}). + +Lemma dlet_null f : dlet f dnull =1 dnull. +Proof. +move=> x; rewrite dletE esum1; last first. ++ by rewrite dnullE. +by move => ? ?; rewrite /= dnullE /= EFinM mul0e. +Qed. + +Lemma dlet_unit f v : \dlet_(y <- dunit v) f y =1 f v. +Proof. +move=> y; rewrite dletE. +rewrite (esumID ([set v]%classic)). ++ by move => ??; rewrite lee_tofin // mulr_ge0. +rewrite setI1 //= in_setT esum_set1. +rewrite esum1 //=. ++ move => i [? h]; rewrite dunit_diff // ?mul0r //=. + by apply nesym. +by rewrite dunit_id addr0 mul1r. +Qed. + +Lemma dlet_dunit_id mu : \dlet_(t <- mu) (dunit t) =1 mu. +Proof. +move=> v; rewrite dletE. +rewrite (esumID ([set v]%classic)). ++ by move => ??; rewrite lee_tofin // mulr_ge0. +rewrite setI1 //= in_setT esum_set1. +rewrite esum1 //=. ++ move => i [? h]; rewrite dunit_diff // ?mulr0 //=. +by rewrite dunit_id mulr1 addr0. +Qed. + +Lemma eq_in_dlet f g mu nu : {in dinsupp mu, f =2 g} -> mu =1 nu -> + dlet f mu =1 dlet g nu. +Proof. +move=> eq_f eq_mu; unlock dlet=> y /=. +rewrite /dlet. +have -> //= : (\esum_(x in [set: T]) (mu x * f x y)%:E = + \esum_(x in [set: T]) (nu x * g x y)%:E). +apply /eq_esum. +move => x ?. +rewrite -eq_mu !EFinM. +case /boolP: (x \in dinsupp mu) => [/eq_f ->//|]. +by move/dinsuppPn => ->; rewrite !mul0e. +Qed. + +Lemma summable_dlet (f : T -> {distr U / R}) (mu : {distr T / R}) y : + summable [set: T] (fun x : T => EFin (mu x * (f x) y)). +Proof. by apply/summable_mu_wgtd=> x; rewrite ge0_mu le1_mu1. Qed. + +Lemma fin_esum (f : T -> {distr U / R}) (mu : {distr T / R}) y: + \esum_(x' in [set: T]) (mu x' * f x' y)%:E \is a fin_num. +Proof. +rewrite esum_abse. ++ by move => ?; rewrite mulr_ge0. +by have := (summable_dlet f mu y); rewrite summableE. +Qed. + +Lemma le_in_dlet f g mu : {in dinsupp mu, f <=2 g} -> + dlet f mu <=1 dlet g mu. +Proof. +move=> le_f; unlock dlet=> y /=; rewrite /dlet fine_le // ?fin_esum //. +apply: le_esum => x ?. +case /boolP: (x \in dinsupp mu) => [/le_f ?|]. +rewrite !EFinM lee_pmul //= lee_tofin //=. +by move/dinsuppPn => ->; rewrite !EFinM !mul0e. +Qed. + +Lemma le_mu_dlet f mu nu : mu <=1 nu -> dlet f mu <=1 dlet f nu. +Proof. +move => le_mu y; unlock dlet; rewrite /dlet fine_le //= ?fin_esum //. +apply: le_esum => x ?. +by rewrite !EFinM lee_pmul //= lee_tofin. +Qed. + +Lemma le_dlet f g mu nu : + mu <=1 nu + -> {in dinsupp mu, forall x, f x <=1 g x} + -> \dlet_(x <- mu) f x <=1 \dlet_(x <- nu) g x. +Proof. +move=> le_mu le_fg x. +by apply/(le_trans (le_in_dlet le_fg _))/le_mu_dlet. +Qed. + +Lemma dletC (mu : {distr T / R}) (nu : {distr U / R}) y : + (\dlet_(_ <- mu) nu) y = (dweight mu) * (nu y). +Proof. +rewrite dletE /pr //=. +under eq_esum do rewrite mulrC EFinM. +rewrite esumZ ?lee_tofin //= => [?| ]; rewrite ?lee_tofin //. +rewrite fineM => //=;last first. ++ rewrite mulrC. symmetry. + by under eq_esum do rewrite mul1r. +by rewrite esum_abse //; have := (summable_mu mu); rewrite summableE. +Qed. + + +Lemma dinsupp_dlet f mu y : + y \in dinsupp (\dlet_(x <- mu) f x) -> + exists2 x, x \in dinsupp mu & f x y != 0. +Proof. +rewrite in_dinsupp /= dletE => nz_dlet. +have /esum_neq0[x _] : \esum_(x in [set: T]) (mu x * f x y)%:E != 0. ++ by apply: contra nz_dlet => /eqP ->; rewrite fine0. +rewrite eqe mulf_eq0 negb_or => /andP[nz_mu nz_f]. +by exists x; rewrite ?in_dinsupp. +Qed. + +Lemma fine_esum0 (f : T -> {distr U / R}) (mu : {distr T / R}) x y: + fine (\esum_(x in [set: T]) (mu x * f x y)%:E) = 0 -> + ((mu x * f x y)%:E = 0). +Proof. +move => h0. +apply /(@esum_eq0P _ _ [set: T] (fun i => (mu i * f i y)%:E)) => //. ++ by move=> i _; rewrite lee_fin mulr_ge0. ++ by rewrite -(fineK (fin_esum f mu y)) h0. +Qed. + +Lemma dlet_dinsupp f mu x y : + x \in dinsupp mu -> f x y != 0 -> y \in dinsupp (dlet f mu). +Proof. +move => /dinsuppP mux nz_fxy. +apply /dinsuppP; rewrite /= dletE => /(fine_esum0 x). +move=> /eqP; rewrite eqe mulf_eq0 (negbTE nz_fxy) orbF => /eqP. +exact: mux. +Qed. + +Lemma dlet_eq0 (f : T -> U) mu y : + {in dinsupp mu, forall x, f x != y} -> (\dlet_(x <- mu) dunit (f x)) y = 0. +Proof. +move=> h; rewrite dletE. +have -> : \esum_(x in [set: T]) (mu x * dunit (f x) y)%:E = 0. ++ apply: esum1 => x _. + case/boolP: (x \in dinsupp mu) => [xin|/dinsuppPn ->]. + - by have := h _ xin; rewrite dunit1E => /negbTE ->; rewrite mulr0. + - by rewrite mul0r. +by []. +Qed. + +Lemma eq0_dlet (mu : {distr T / R}) (F : T -> {distr U / R}) y : + (\dlet_(x <- mu) F x) y = 0 -> forall x, x \in dinsupp mu -> F x y = 0. +Proof. +unlock dlet; rewrite /= /dlet => /fine_esum0 => h x. +move => /dinsuppP /eqP mu_x. move: (h x). +by move=> /eqP ; rewrite eqe mulf_eq0 (negbTE mu_x) /= => /eqP. +Qed. + +End BindTheory. + +(* -------------------------------------------------------------------- *) +Section DLetDLet. + Context {R:realType} {T U V : choiceType} + (f1 : T -> {distr U / R}) (f2 : U -> {distr V / R}). + +Lemma dlet_dlet (mu : {distr T / R}) : + \dlet_(x <- \dlet_(y <- mu) f1 y) f2 x + =1 \dlet_(y <- mu) (\dlet_(x <- f1 y) f2 x). +Proof. +move=> z; unlock dlet => /=; rewrite /dlet /=. +pose S y x := mu x * f1 x y * f2 y z. +rewrite (eq_esum _ _ (fun y => \esum_(x in [set: T]) (S y x)%:E)%E). ++ move => y ?; subst S; rewrite EFinM fineK ?fin_esum //. + + rewrite muleC -esumZ // ?lee_tofin // => [? |]. + + by rewrite EFinM lee_tofin // mulr_ge0. + + by apply eq_esum => ??; rewrite -EFinM mulrC. +rewrite (eq_esum _ _ (fun x => \esum_(y in [set: U]) (S y x)%:E)%E). ++ move => x ?; subst S; rewrite EFinM fineK ?fin_esum //. + + rewrite -esumZ // ?lee_tofin // => [? |]. + + by rewrite EFinM lee_tofin // mulr_ge0. + + by apply eq_esum => ??; rewrite -EFinM mulrA. +by rewrite exchange_esum // => ??; rewrite /S EFinM lee_tofin // !mulr_ge0. +Qed. +End DLetDLet. + +(* -------------------------------------------------------------------- *) +Section DLetAlg. +Context {R : realType} {T U : choiceType} (mu mu1 mu2 : {distr T / R}). + +Lemma dlet_additive (f : T -> {distr U / R}) z : + (forall x, mu x = mu1 x + mu2 x) -> (\dlet_(x <- mu) f x) z = + (\dlet_(x <- mu1) f x) z + (\dlet_(x <- mu2) f x) z. +Proof. +move=> muD; rewrite !dletE. +under eq_esum do rewrite muD mulrDl EFinD. +rewrite esumD. +1-2: by move => ??; rewrite /S EFinM lee_tofin // !mulr_ge0. +by rewrite fineD //= fin_esum . +Qed. +End DLetAlg. + +(* -------------------------------------------------------------------- *) + +HB.mixin Record isNDistribution + (R : realType) (T : choiceType) (nmu : nat -> {distr T / R}) := + { nmu_decrease : forall x, nondecreasing_seq (fun n => (nmu n x)%:E); }. + +HB.structure Definition NDistribution (R : realType) (T : choiceType) := + {f of @isNDistribution R T f }. + +Notation "{ 'ndistr' T / R }" := (@NDistribution.type R T) + (at level 0, T at level 2, format "{ 'ndistr' T / R }") + : type_scope. + + +(* -------------------------------------------------------------------- *) +Lemma sup_range_lim {R : realType} (u : (\bar R)^nat) : + nondecreasing_seq u -> ereal_sup (range u) = limn u. +Proof. +by move=> ndu; apply/esym/cvg_lim => //; exact: ereal_nondecreasing_cvgn. +Qed. + +(* -------------------------------------------------------------------- *) +Section dlim. +Context {R : realType} (T : choiceType). + +Lemma nd_f (f : {ndistr T / R}) : forall x, nondecreasing_seq (fun n => (f n x)%:E). +Proof. exact: nmu_decrease. Qed. + +Lemma id1 (f : {ndistr T / R}): forall x, cvgn (fun n => (f n x)%:E). +Proof. +case f => {}f [[nd_f] ?]. +by move=> x; apply: ereal_nondecreasing_is_cvgn; exact: nd_f. +Qed. + +(* Definition dlim (f : {ndistr T / R}) : T -> R := *) +(* fun x => fine (ereal_sup (range (fun n : nat => (f n x)%:E))). *) + +Import numFieldNormedType.Exports. + +Definition dlim (f : {ndistr T / R}) : T -> R := + fun x => fine (limn (fun n : nat => (f n x)%:E)). + +Lemma le1_lim (f : {ndistr T / R}) : + forall x, (limn (fun n => (f n x)%:E) <= 1%:E)%E. +Proof. + move=> x; apply: lime_le; [ exact: id1| apply: nearW]. + move=> n; rewrite lee_fin. + exact: le1_mu1. +Qed. + +Lemma fin_lim (f : {ndistr T / R}) : + forall x, limn (fun n => (f n x)%:E) \is a fin_num. +Proof. + move=> x; rewrite ge0_fin_numE //. + + by apply: lime_ge; [exact: id1 | apply: nearW => n; rewrite lee_fin]. + apply: le_lt_trans;[ apply le1_lim | apply ltry]. +Qed. + +Lemma sumlim (f : {ndistr T / R}): + forall L, uniq L -> + (\sum_(j <- L) limn (fun n => (f n j)%:E) = + limn (fun n => \sum_(j <- L) (f n j)%:E))%E. +Proof. +elim => [|a L IH] uqL. +- rewrite big_nil. + apply/esym/cvg_lim => //. + by apply: cvg_near_cst; apply: nearW => n; rewrite big_nil. +- case/andP: uqL => _ uqL. + rewrite big_cons IH //. + under [in RHS]eq_fun => n do rewrite big_cons. + apply/esym/cvg_lim => //. + apply: cvgeD. + + apply: fin_num_adde_defr; exact: fin_lim. + + exact: id1. + + apply: ereal_nondecreasing_is_cvgn => n m nm. + by apply: lee_sum => j _; exact : nd_f. +Qed. + +Lemma dlim_EFin (f : {ndistr T / R}): + forall x, (dlim f x)%:E = limn (fun n => (f n x)%:E). +Proof. +move=> x; rewrite /dlim fineK //. +exact: fin_lim. +Qed. + +Lemma isd_dlim (f : {ndistr T / R}): isdistr (dlim f). +Proof. +split=> [x|J uqJ]; rewrite /dlim. ++ case h: (limn _) => //=. + rewrite -lee_fin -{}h. + apply: lime_ge; first exact: id1. + apply: nearW => n. + by rewrite lee_fin. ++ rewrite -lee_fin -sumEFin. + under eq_bigr => j _ do rewrite -/(dlim f j) dlim_EFin //. + rewrite sumlim //. + apply: lime_le. + + apply: ereal_nondecreasing_is_cvgn => n m nm. + by apply: lee_sum => j _ ; exact: nd_f. + + apply: nearW => n; rewrite sumEFin. + apply: (@le_trans _ _ (esum [set: T] (EFin \o f n))); last exact: le1_mu. + exact: sum_esum_ge. +Qed. + +HB.instance Definition _ (f : {ndistr T / R}) := @mkdistrd R T (dlim f) (isd_dlim f). + +Lemma dlimE (f : {ndistr T / R}) x : + (dlim f) x = fine (limn (fun n => EFin(f n x))). +Proof. by []. Qed. + +End dlim. + +Lemma mono_nondecressing {R : realType} (T : choiceType) (f : nat -> T -> R) + (hmono : forall n m, (n <= m)%N -> forall x, f n x <= f m x) : + forall x, nondecreasing_seq (fun n => (f n x)%:E). +Proof. by move=> x n m nm; rewrite lee_fin; exact: hmono. Qed. + +Notation "\dlim_ ( n ) E" := (dlim (fun n => E)). +(* -------------------------------------------------------------------- *) + +Section DLimC. +Variables (R : realType) (T U : choiceType). + +Implicit Types (mu : {distr T / R}). + +Definition nmuc mu := fun (_:nat) => mu. + +Lemma isnd_ndc mu : forall x, nondecreasing_seq (fun n => (nmuc mu n x)%:E). +Proof. +by apply: mono_nondecressing. +Qed. + +HB.instance Definition _ mu:= @isNDistribution.Build R T (nmuc mu) (isnd_ndc mu). + +Lemma dlimC mu : forall x, (dlim (nmuc mu)) x = mu x. +Proof. +move=> x; rewrite dlimE /= /nmuc. +have -> : limn (fun n : nat => (mu x)%:E) = (mu x)%:E. + by apply/cvg_lim => //; exact: cvg_cst. +by []. +Qed. + +End DLimC. + +Section DLimBump. +Variables (R : realType) (T U : choiceType). + +Definition bump (nmu :{ndistr T / R}) := fun n => nmu (n.+1). + +Lemma isnd_bump nmu : forall x, nondecreasing_seq (fun n => (bump nmu n x)%:E). +Proof. +apply: mono_nondecressing. +rewrite /bump => n m h x. +by apply: nmu_decrease. +Qed. + +HB.instance Definition _ nmu := + @isNDistribution.Build R T (bump nmu) (isnd_bump nmu). + +Lemma dlim_bump (nmu: {ndistr T / R}) : dlim (bump nmu) =1 dlim nmu. +Proof. +move=> x; rewrite /dlim /=. +congr (fine _). +apply/cvg_lim => //. +rewrite (cvg_shiftS (fun k => (nmu k x)%:E)). +exact: id1. +Qed. + +End DLimBump. + +Section DLimLift. + +Variables (R : realType) (T U : choiceType). + +Definition lift (nmu : {ndistr T / R}) p := fun n => nmu (n + p). + +Lemma isnd_lift nmu p : forall x, nondecreasing_seq (fun n => (lift nmu p n x)%:E). +Proof. +apply: mono_nondecressing. +rewrite /lift => n m h x. +apply: nmu_decrease. +by rewrite leq_add2r. +Qed. + +HB.instance Definition _ nmu p := + @isNDistribution.Build R T (lift nmu p ) (isnd_lift nmu p). + +Lemma dlim_lift (nmu : {ndistr T / R}) p : + dlim (lift nmu p) =1 dlim nmu. +Proof. +move=> x; rewrite /dlim /=. +congr (fine _). +apply/cvg_lim => //. +rewrite (cvg_shiftn p (fun k => (nmu k x)%:E)). +exact: id1. +Qed. + +End DLimLift. + +Section DLimTheory. +Variables (R : realType) (T U : choiceType). + +Implicit Types (f g : {ndistr T / R}) (h : T -> {distr U / R}). +Implicit Types (mu : {distr T / R}). + +Lemma ge0_dlim f : forall x, 0 <= dlim f x. +Proof. exact: mu_positive. Qed. + +Lemma le1_dlim f : forall x, dlim f x <= 1. +Proof. +move => x; rewrite /= dlimE -lee_fin dlim_EFin. +exact: le1_lim. +Qed. + +Lemma le_dlim f g : + (forall n, f n <=1 g n) -> dlim f <=1 dlim g. +Proof. +move=> le x; rewrite -lee_fin !dlim_EFin. +apply: lee_lim; [exact: id1 | exact: id1 |]. +by apply: nearW => n; rewrite lee_fin; apply: le. +Qed. + +Lemma eq_dlim f g : (forall n, f n =1 g n) -> dlim f =1 dlim g. +Proof. +move=> eq_fg x. +apply/eqP; rewrite eq_le; apply/andP; split. +1-2 : by apply le_dlim; move => ??; rewrite eq_fg. +Qed. + +Lemma leub_dlim f mu : (forall n, f n <=1 mu) -> dlim f <=1 mu. +Proof. + move => le x; rewrite -(dlimC mu x). + by apply : le_dlim => n y. +Qed. + +Lemma dlim_ub f k : f k <=1 dlim f. +Proof. +move=> x; rewrite -lee_fin dlim_EFin. +apply: lime_ge; first exact: id1. +near=> n; apply: (nd_f f x). +by near: n; apply: nbhs_infty_ge. +Unshelve. all: by end_near. +Qed. + +End DLimTheory. + +Section DletDLim. +Variables (R : realType) (T U : choiceType). + +Implicit Types (f : {ndistr T / R}) (h : T -> {distr U / R}). + +Definition ndlet f h: (nat -> {distr U / R}) := fun n => dlet h (f n). + +Lemma isnd_dlet h f : forall x, nondecreasing_seq (fun n => (ndlet f h n x)%:E). +Proof. +apply: mono_nondecressing => n m hnm x. +apply: le_mu_dlet => y. +by apply nd_f. +Qed. + +HB.instance Definition _ h f := + @isNDistribution.Build R U (ndlet f h) (isnd_dlet h f). + +Lemma dlet_EFin h (mu : {distr T / R}) y : + (dlet h mu y)%:E = esum [set:T] (fun x => (mu x * h x y)%:E). +Proof. by rewrite dletE fineK// ?fin_esum. Qed. + +Lemma sup_mul (nf : {ndistr T / R}) (c : R) x : 0 <= c -> + ((dlim nf x) * c)%:E = ereal_sup (range (fun n => (nf n x * c)%:E)). +Proof. +move=> c0. +rewrite EFinM dlim_EFin -(sup_range_lim (nd_f nf x)) muleC. +rewrite (@ge0_ereal_supZl_range R T (fun t n => (nf n t)%:E)) //=. ++ by move=> t n; rewrite lee_fin; exact: ge0_mu. +have -> : + [set (c%:E * (nf i x)%:E)%E | i in [set: nat]]%classic = + [set (nf i x * c)%:E | i in [set: nat]]%classic. + apply/seteqP; split. + - by move=> ? [x0 ?]; rewrite -EFinM mulrC=> <- //=; exists x0. + - by move=> ? [x0 ?]; rewrite mulrC EFinM => <- //=; exists x0. +reflexivity. +Qed. + +Lemma dlet_lim f h : dlet h (dlim f) =1 dlim (ndlet f h). +Proof. +move=> y; apply: EFin_inj. +rewrite dlet_EFin dlim_EFin. +under eq_esum => x _ do rewrite sup_mul//. +rewrite -(sup_range_lim (nd_f (ndlet f h) y)). +rewrite (@exchange_esum_ereal_sup R T (fun x n => (f n x * h x y)%:E)) /=. ++ by move=> t n; rewrite lee_fin; apply: mulr_ge0; exact: ge0_mu. ++ move=> n m nm t; rewrite lee_fin; apply: ler_wpM2r; first exact: ge0_mu. + by rewrite -lee_fin; apply: nd_f. +have -> : +[set \esum_(x in [set: T]) (f i x * h x y)%:E | i in [set: nat]]%classic = +[set ((\dlet_(i <- f i) h i) y)%:E | i in [set: nat]]%classic. + apply/seteqP; split. + - by move=> ? [x0 ?]; rewrite -dlet_EFin => <- //=; exists x0. + - by move=> ? [x0 ?]; rewrite /ndlet dlet_EFin => <- //=; exists x0. +reflexivity. +Qed. + +End DletDLim. + +Section DLimDlet. +Context (R : realType) (T U : choiceType) (f : nat -> T -> {distr U / R}). +Context (hmono: forall x n m, (n <= m)%N -> f n x <=1 f m x). + +Definition reduce y : (nat -> {distr U / R}) := fun n => f n y. + +Lemma isnd_reduce y : + forall x, nondecreasing_seq (fun n => (reduce y n x)%:E). +Proof. +apply: mono_nondecressing => n m hnm x. +exact: hmono. +Qed. + +HB.instance Definition _ y := + @isNDistribution.Build R U (reduce y) (isnd_reduce y ). + +Definition mu_dlet mu: (nat -> {distr U / R}) := fun n => dlet (f n) mu. + +Lemma isnd_mu_dlet (mu : {distr T / R}) : + forall x, nondecreasing_seq (fun n => (mu_dlet mu n x)%:E). +Proof. +apply: mono_nondecressing => n m hnm x. +apply: le_in_dlet => z _. +exact: hmono. +Qed. + +HB.instance Definition _ mu := + @isNDistribution.Build R U (mu_dlet mu) (isnd_mu_dlet mu). + +Lemma dlim_let (mu : {distr T / R}) : + dlim (mu_dlet mu) =1 dlet (fun x => dlim (reduce x )) mu. +Proof. +move=> z; apply: EFin_inj. +rewrite dlim_EFin dlet_EFin. +under eq_esum => t _ do rewrite mulrC sup_mul//. +rewrite -(sup_range_lim (nd_f (mu_dlet mu) z)). +rewrite (@exchange_esum_ereal_sup R T (fun t n => (reduce t n z * mu t)%:E)) /=. ++ by move=> t n; rewrite /reduce lee_fin; apply: mulr_ge0; exact: ge0_mu. ++ move=> n m nm t; rewrite /reduce lee_fin; apply: ler_wpM2r; first exact: ge0_mu. + exact: hmono. +have ->: + [set ((\dlet_(i0 <- mu) f i i0) z)%:E | i in [set: nat]]%classic = + [set \esum_(x in [set: T]) (reduce x i z * mu x)%:E | i in [set: nat]]%classic. + apply/seteqP; split. + - move=> ? [x0 ?]; rewrite dlet_EFin=> <-//=; exists x0 => //=. + by under eq_esum do rewrite /reduce mulrC. + - move=> ? [x0 ?]; under eq_esum do rewrite /reduce mulrC. + by move => <- //=; exists x0 => //=; rewrite -dlet_EFin. +reflexivity. +Qed. + +End DLimDlet. + +Section DLimDLim. +Context (R : realType) (T : choiceType) (f : nat -> nat -> {distr T / R}). +Context (hmono1: (forall k n1 n2, (n1 <= n2)%N -> f n1 k <=1 f n2 k)). +Context (hmono2: (forall k n1 n2, (n1 <= n2)%N -> f k n1 <=1 f k n2)). + +Definition apply2 : (nat -> {distr T / R}) := (fun n => f n n). + +Lemma isnd_apply2: + forall x, nondecreasing_seq (fun n => (apply2 n x)%:E). +Proof. +apply: mono_nondecressing => n m hnm x. +rewrite /apply2. +apply /le_trans. ++ apply hmono1. exact: hnm. +by apply: hmono2. +Qed. + +HB.instance Definition _ := + @isNDistribution.Build R T apply2 isnd_apply2. + +Definition apply (k:nat) : (nat -> {distr T / R}) := f k. + +Lemma isnd_apply k: + forall x, nondecreasing_seq (fun n => (apply k n x)%:E). +Proof. +apply: mono_nondecressing => n m hnm x. +by apply: hmono2. +Qed. + +HB.instance Definition _ k := + @isNDistribution.Build R T (apply k) (isnd_apply k). + +Definition dlim_apply : (nat -> {distr T / R}) := (fun n => dlim (apply n)). + +Lemma isnd_dlim_apply: + forall x, nondecreasing_seq (fun n => (dlim_apply n x)%:E). +Proof. +apply: mono_nondecressing => n m hnm x. +apply le_dlim => ??. +by apply: hmono1. +Qed. + +HB.instance Definition _ := + @isNDistribution.Build R T dlim_apply isnd_dlim_apply. + +Lemma leub_dlim_dlim1 : + dlim dlim_apply <=1 dlim apply2. +Proof. +apply: leub_dlim => n. +apply: leub_dlim => m x. +apply: (@le_trans _ _ (apply2 (maxn n m) x)); last exact: dlim_ub. +apply: (@le_trans _ _ (f (maxn n m) m x)). +- apply: hmono1; exact: leq_maxl. +- apply: hmono2; exact: leq_maxr. +Qed. + +Lemma dlim_dlim_ub1 : + dlim apply2 <=1 dlim dlim_apply. +Proof. +apply: leub_dlim => n x. +apply: (@le_trans _ _ (dlim (apply n) x)). +- exact: (dlim_ub (apply n) n). +- exact: (dlim_ub dlim_apply n). +Qed. + +Definition applyk (k:nat) : (nat -> {distr T / R}) := (fun n => f n k). + +Lemma isnd_applyk k: + forall x, nondecreasing_seq (fun n => (applyk k n x)%:E). +Proof. +apply: mono_nondecressing => n m hnm x. +by apply: hmono1. +Qed. + +HB.instance Definition _ k := + @isNDistribution.Build R T (applyk k) (isnd_applyk k). + +Definition dlim_applyk : (nat -> {distr T / R}) := (fun n => dlim (applyk n)). + +Lemma isnd_dlim_applyk: + forall x, nondecreasing_seq (fun n => (dlim_applyk n x)%:E). +Proof. +apply: mono_nondecressing => n m hnm x. +apply le_dlim => ??. +by apply: hmono2. +Qed. + +HB.instance Definition _ := + @isNDistribution.Build R T dlim_applyk isnd_dlim_applyk. + +Lemma leub_dlim_dlim2 : + dlim dlim_applyk <=1 dlim apply2. +Proof. +apply: leub_dlim => n. +apply: leub_dlim => m x. +apply: (@le_trans _ _ (apply2 (maxn n m) x)); last exact: dlim_ub. +apply: (@le_trans _ _ (f (maxn n m) n x)). +- apply: hmono1; exact: leq_maxr. +- apply: hmono2; exact: leq_maxl. +Qed. + +Lemma dlim_dlim_ub2 : + dlim apply2 <=1 dlim dlim_applyk. +Proof. +apply: leub_dlim => n x. +apply: (@le_trans _ _ (dlim (applyk n) x)). +- exact: (dlim_ub (applyk n) n). +- exact: (dlim_ub dlim_applyk n). +Qed. + +Lemma dlim_dlim_com : + dlim dlim_apply =1 dlim dlim_applyk. +Proof. +move=> x; apply/eqP; rewrite eq_le; apply/andP; split. +- exact: (le_trans (leub_dlim_dlim1 x) (dlim_dlim_ub2 x)). +- exact: (le_trans (leub_dlim_dlim2 x) (dlim_dlim_ub1 x)). +Qed. + +End DLimDLim. + +Section dlet_dlim_diag. +Context (R : realType) (T U: choiceType). +Context (d : {ndistr T / R}) (h : nat -> T -> {distr U / R}). +Context (hmono: (forall k n1 n2, (n1 <= n2)%N -> h n1 k <=1 h n2 k)). + +Definition nmu_dlet (nmu : {ndistr T / R}): (nat -> {distr U / R}) := + fun n => dlet (h n) (nmu n). + +Lemma isnd_nmu_dlet (nmu : {ndistr T / R}) : + forall x, nondecreasing_seq (fun n => (nmu_dlet nmu n x)%:E). +Proof. +apply: mono_nondecressing => n m hnm x. +rewrite /= /nmu_dlet. +apply: le_dlet. ++ move => ?. + by apply: nmu_decrease. +move => ???; exact: hmono. +Qed. + +HB.instance Definition _ nmu := + @isNDistribution.Build R U (nmu_dlet nmu) (isnd_nmu_dlet nmu). + +Let hreduce := (reduce h). + +HB.instance Definition _ y := + @isNDistribution.Build R U (hreduce y) (isnd_reduce hmono y). + +Lemma key : forall n, dlet (fun x => dlim (hreduce x)) (d n) <=1 dlim (nmu_dlet d). +Proof. +move=> n u; rewrite -dlim_let. +apply: leub_dlim => m w; rewrite /mu_dlet. +apply: (@le_trans _ _ (nmu_dlet d (maxn m n) w)); last exact: dlim_ub. +rewrite /nmu_dlet; apply: le_dlet. ++ move=> x; rewrite -lee_fin; apply: (nd_f d x). + exact: leq_maxr. +by move=> ? _; apply: hmono; exact: leq_maxl. +Qed. + +Lemma dlet_dlim_diag : + dlet (fun x => dlim (hreduce x)) (dlim d) =1 dlim (nmu_dlet d). +Proof. +move=> z; apply/eqP; rewrite eq_le; apply/andP; split. +- rewrite dlet_lim; apply: leub_dlim => n. + rewrite /ndlet; exact: key. +- apply: leub_dlim => n; rewrite /nmu_dlet; apply: le_dlet. + + exact: dlim_ub. + by move=> x _; exact: (dlim_ub (hreduce x) n). +Qed. + +End dlet_dlim_diag. + +(* -------------------------------------------------------------------- *) +Section Marginals. +Variable (R : realType) (T U : choiceType) (h : T -> U) (mu : {distr T / R}). + +Definition dmargin := \dlet_(x <- mu) (dunit (h x)). + +Lemma dmarginE : dmargin = \dlet_(y <- mu) (dunit (h y)). +Proof. by []. Qed. +End Marginals. + +(* -------------------------------------------------------------------- *) +Section MarginalsTh. +Variable (R: realType) (T U V : choiceType). + +Lemma dmargin_psumE (mu : {distr T / R}) (f : T -> U) y : + (dmargin f mu) y = fine (esum [set:T] (fun x => ((f x == y)%:R * mu x)%:E)). +Proof. +rewrite dmarginE dletE. +congr fine. +apply/eq_esum => x _. +by rewrite mulrC dunit1E. +Qed. + +Lemma dlet_dmargin (mu : {distr T / R}) (f : T -> U) (g : U -> {distr V / R}): + \dlet_(u <- dmargin f mu) g u =1 \dlet_(t <- mu) (g (f t)). +Proof. +move=> x; rewrite dlet_dlet; apply: eq_in_dlet=> //. +by move=> y _ z /=; rewrite dlet_unit. +Qed. + +Lemma dmargin_dlet (mu : {distr T / R}) (f : U -> V) (g : T -> {distr U / R}): + dmargin f (\dlet_(t <- mu) g t) =1 \dlet_(t <- mu) (dmargin f (g t)). +Proof. by apply/dlet_dlet. Qed. + +Lemma dmargin_dunit (t : T) (f : T -> U): + dmargin f (dunit t) =1 dunit (f t) :> {distr U / R}. +Proof. by apply/dlet_unit. Qed. +End MarginalsTh. + +Notation dfst mu := (dmargin fst mu). +Notation dsnd mu := (dmargin snd mu). + +(* -------------------------------------------------------------------- *) +Section DSwap. +Context {R : realType} {A B : choiceType} (mu : {distr (A * B)%type / R}). + +Definition dswap : {distr (B * A)%type / R} := + dmargin (fun xy => (xy.2, xy.1)) mu. +End DSwap. + +(* -------------------------------------------------------------------- *) +Section DSwapCoreTheory. +Context {R : realType} {A B : choiceType} (mu : {distr (A * B)%type / R}). + +Lemma dswapE xy : dswap mu xy = mu (xy.2, xy.1). +Proof. +rewrite /= dletE (esumID ([set (xy.2, xy.1)]%classic)). ++ by move=> ??; rewrite lee_tofin // mulr_ge0. +rewrite setI1 //= in_setT esum_set1. +rewrite esum1 //=. ++ move=> ab [_ h] /=. + rewrite dunit_diff ?mulr0 // => heq; apply: h. + by rewrite -heq /= -surjective_pairing. +by case: xy => x y /=; rewrite dunit_id mulr1 addr0. +Qed. + +End DSwapCoreTheory. + +(* -------------------------------------------------------------------- *) +Section DSwapTheory. +Context {R : realType} {A B : choiceType} (mu : {distr (A * B)%type / R}). + +Lemma dswapK : dswap (dswap mu) =1 mu. +Proof. by case=> x y; rewrite !dswapE. Qed. + +Lemma dinsupp_swap xy : (xy.2, xy.1) \in dinsupp mu -> + xy \in dinsupp (dswap mu). +Proof. +by move=> h; apply/dinsuppP; rewrite dswapE; apply/dinsuppPn. +Qed. + +Lemma dfst_dswap : dfst (dswap mu) =1 dsnd mu. +Proof. +move=> z; rewrite /dmargin dlet_dlet => /= . +apply/eq_in_dlet => // -[x y]. +by move=> _ t /=; rewrite dlet_unit /=. +Qed. + +Lemma dsnd_dswap : dsnd (dswap mu) =1 dfst mu. +Proof. +move=> z; rewrite /dmargin dlet_dlet; apply/eq_in_dlet => // -[x y]. +by move=> _ t /=; rewrite dlet_unit /=. +Qed. +End DSwapTheory. + +(* -------------------------------------------------------------------- *) +Section DFst. +Context {R : realType} {T U : choiceType}. + +Lemma dfstE (mu : {distr (T * U)%type / R}) x : + dfst mu x = fine (esum [set:U] (fun y => (mu (x, y))%:E)). +Proof. +rewrite dmarginE dletE; congr fine. +rewrite (esumID [set z : T * U | z.1 = x]). ++ by move=> z _; rewrite lee_tofin // mulr_ge0. +rewrite [X in _ + X]esum1. ++ by move=> z [_ /= zx]; rewrite dunit_diff // ?mulr0 //=. +rewrite adde0. +rewrite (reindex_esum [set: U] _ (fun y => (x, y))). + split. + - by move=> y _; split. + - by move=> y1 y2 _ _ /(congr1 snd). + - move=> z [_ /= zx]; exists z.2 => //=. + by case: z zx => z1 z2 /= ->. +by apply: eq_esum => y _ /=; rewrite dunit_id mulr1. +Qed. + +Lemma summable_fst (mu : {distr (T * U)%type / R}) x : + summable [set:U] (fun y => (mu (x, y))%:E). +Proof. +rewrite /summable; apply: le_lt_trans (summable_mu mu). +rewrite -(reindex_esum [set:U] [set z : T * U | z.1 = x] + (fun y => (x, y)) (fun z => (`|(mu z)%:E|)%E)). ++ split. + - by move=> y _. + - by move=> y1 y2 _ _ /(congr1 snd). + - move=> z /= zx; exists z.2 => //=. + by case: z zx => z1 z2 /= ->. +by apply: subset_esum. +Qed. +End DFst. + +(* -------------------------------------------------------------------- *) +Section DSnd. +Context {R : realType} {T U : choiceType}. + +Lemma dsndE (mu : {distr (T * U)%type / R}) y : + dsnd mu y = fine (esum [set:T] (fun x => (mu (x, y))%:E)). +Proof. + by rewrite -dfst_dswap dfstE; congr fine; apply/eq_esum=> x; rewrite dswapE. +Qed. + +Lemma summable_snd (mu : {distr (T * U)%type / R}) y : + summable [set:T] (fun x => (mu (x, y))%:E). +Proof. +have := summable_fst (dswap mu) y; apply/eq_esummable. +by move=> x /=; rewrite dswapE. +Qed. +End DSnd. + +(* -------------------------------------------------------------------- *) +Section PrCoreTheory. +Context {R : realType} {T : choiceType}. + +Implicit Types (mu : {distr T / R}) (A B E : pred T). + +Lemma summable_pr E mu : summable [set:T] (fun x => ((E x)%:R * mu x)%:E). +Proof. +apply/(le_esummable (g := EFin \o mu)) => [x|]; last by apply/summable_mu. +rewrite !lee_tofin => //=. ++ by rewrite mulr_ge0. +by rewrite ler_piMl //= lern1 leq_b1. +Qed. + +Lemma pr_pred0 mu : \P_[mu] pred0 = 0. +Proof. by rewrite /pr esum1 // => x /=; rewrite mul0r. Qed. + +Lemma pr_pred1 mu x : mu x = \P_[mu] (pred1 x). +Proof. +rewrite /pr. +rewrite (eq_esum _ _ (fun y => if x == y then (mu y)%:E else 0)); last first. ++ by rewrite esum_if_eq_op_set1. +move=> y _ /=; rewrite [y == x]eq_sym. +by case: ifP => xy; rewrite ?xy /= ?mul1r ?mul0r. +Qed. + +(* -------------------------------------------------------------------- *) +Lemma pr_exp mu (E : pred T) : \P_[mu] E = \E_[mu] (fun m => (E m)%:R). +Proof. by []. Qed. + +Lemma pr_predT mu : \P_[mu] predT = fine (esum [set: T] (EFin \o mu)). +Proof. +rewrite /pr /esp; congr fine. +by apply/eq_esum=> x; rewrite mul1r. +Qed. + +Lemma pr_dunit E x : \P_[dunit x] E = (E x)%:R :> R. +Proof. +rewrite /pr. +rewrite (eq_esum _ _ (fun y => if x == y then ((E y)%:R)%:E else 0)). ++ move=> y _ /=; rewrite dunit1E. + by case: ifP => xy; rewrite ?xy /= ?mulr1 ?mulr0. +by rewrite esum_if_eq_op_set1. +Qed. + +Lemma exp_dunit (f : T -> R) (x : T) : \E_[dunit x] f = f x. +Proof. +rewrite /esp. +rewrite (eq_esum _ _ (fun y : T => if x == y then (f y)%:E else 0)%E). ++ move => x0 /=; rewrite dunit1E. + by case (x == x0) => //=; rewrite ?mulr1 ?mulr0. +by rewrite esum_if_eq_op_set1. +Qed. + +Lemma fineMK (a b : \bar R): + (0 <= b)%E -> a \is a fin_num -> + fine (a * b) = fine a * fine b. +Proof. +move => hp. +move /(elimT (EFin_fin_numP a)) => [r] ->. +case h: b => //=; last first. by move : hp; rewrite h. +have [hc|hc|->] := comparable_ltgtP (comparableT r 0). ++ rewrite lt0_muley => //=. + by rewrite mulr0. ++ rewrite gt0_muley => //=. + by rewrite mulr0. +by rewrite mul0e //= mulr0. +Qed. + +Lemma expZ mu f c : + (forall x, 0 <= f x) -> \E_[mu] (fun x => c * (f x)) = c * (\E_[mu] f). +Proof. +move => h1; rewrite /esp. +under eq_esum => x do rewrite /= -mulrA EFinM. +have hpos : forall x : T, (0%R <= (f x * mu x)%:E)%E. ++ by move=> x; rewrite lee_fin; apply: mulr_ge0; [exact: h1 | exact: ge0_mu]. +rewrite esumZ //=. +have hsum : (0 <= \esum_(i in [set: T]) (f i * mu i)%:E)%E. ++ by apply esum_ge0 => ??. +by rewrite fineMK. +Qed. + +Lemma exp_cst mu r : \E_[mu] (fun _ => r) = \P_[mu] predT * r. +Proof. +have := (expZ mu (f:= fun _ => 1%R) r). +rewrite mulr1 => -> //=. +by rewrite mulrC; congr (_ * _). +Qed. + +Lemma exp0 mu : \E_[mu] (fun _ => 0) = 0. +Proof. by rewrite exp_cst mulr0. Qed. + +Lemma has_expC mu c : \E?_[mu] (fun _ => c). +Proof. +rewrite /has_esp. +have : summable [set: T] (fun x : T => (c%:E * (mu x)%:E)%E). + by apply: esummableZl => //; exact: summable_mu. +apply/eq_esummable => x /=. +by rewrite EFinM. +Qed. + +Lemma has_exp0 mu : \E?_[mu] (fun _ => 0). +Proof. by apply/(has_expC mu 0). Qed. + +Lemma has_exp1 mu : \E?_[mu] (fun _ => 1). +Proof. by apply/(has_expC mu 1). Qed. + +Lemma has_expZ mu c F : \E?_[mu] F -> \E?_[mu] (c \*o F). +Proof. +move=> heF; rewrite /has_esp. +have := esummableZl (f := EFin \o (fun x => F x * mu x)) (c := c%:E) erefl heF. +apply/eq_esummable => x /=. +by rewrite -EFinM mulrA. +Qed. + +Lemma ge0_pr A mu : 0 <= \P_[mu] A. +Proof. +rewrite /pr. +case h: (esum _ _) => //=. +rewrite -lee_fin -h. +apply/esum_ge0 . +by move => ? _ ; rewrite lee_fin mulr_ge0. +Qed. + +Lemma ge0_prc A B mu : 0 <= \P_[mu, B] A. +Proof. by rewrite /prc mulr_ge0 ?invr_ge0 // ge0_pr. Qed. + +Lemma eq_in_pr A B mu : + {in dinsupp mu, A =i B} -> \P_[mu] A = \P_[mu] B. +Proof. +move=> eq_AB; rewrite /pr; congr fine. +apply/eq_esum => x _ /=. +case/boolP: (x \in dinsupp mu). ++ by move/eq_AB; rewrite -!topredE => /= ->. ++ by move/dinsuppPn => ->; rewrite !mulr0. +Qed. + +Lemma eq_pr A B mu : A =i B -> \P_[mu] A = \P_[mu] B. +Proof. by move=> eq_AB; apply/eq_in_pr=> x _; apply/eq_AB. Qed. + +Lemma eq_exp mu (f1 f2 : T -> R): + {in dinsupp mu, f1 =1 f2} -> \E_[mu] f1 = \E_[mu] f2. +Proof. +move=> eq_f; rewrite /esp; congr fine. +apply/eq_esum => x /=. +case/boolP: (x \in dinsupp mu). ++ by move/eq_f => ->. ++ by move/dinsuppPn => ->; rewrite !mulr0. +Qed. + +Lemma pr_pred0_eq (mu : {distr T / R}) (E : pred T) : + E =1 pred0 -> \P_[mu] E = 0. +Proof. by move=> eq; rewrite -(pr_pred0 mu); apply/eq_pr. Qed. +End PrCoreTheory. + +(* -------------------------------------------------------------------- *) +Section Esp. +Context {R : realType} {T : choiceType}. + +Implicit Types (mu : {distr T / R}) (f : T -> \bar R). + +Definition espe mu f := esum [set:T] (fun x => mule (f x) ((mu x)%:E)). + +Notation "\Ee_[ mu ] f" := (espe mu f). +End Esp. + +Section EspeCoreTheory. +Context {R : realType} {T : choiceType}. + +Implicit Types (mu : {distr T / R}) (A B E : pred T). + +Lemma eexp_eq (f g: T -> \bar R) mu: + (f =1 g)%E -> + espe mu f = espe mu g. +Proof. +move => h; rewrite /espe. +apply eq_esum => ??. +by congr (_ * _)%E. +Qed. + +Lemma eexp_dunit (f : T -> \bar R) (x : T) : + espe (dunit x) f = f x. +Proof. +rewrite /espe. +rewrite (eq_esum _ _ (fun y : T => if x == y then f y else 0%R)%E). ++ move => x0. rewrite dunit1E. + by case (x == x0) => //=; rewrite ?mule1 ?mule0. +by rewrite esum_if_eq_op_set1. +Qed. + +Lemma eexp_cst mu r : (espe mu (fun _ => r) = (\P_[mu] predT)%:E * r)%E. +Proof. +rewrite pr_predT /espe //. +rewrite esumZ. +- move => ?; rewrite lee_fin //. +rewrite muleC; congr ( _ * _)%E. +rewrite fineK //= esum_abse => //=. +by have := (summable_mu mu); rewrite summableE. +Qed. + +Lemma eexp0 mu : espe mu (fun _ => 0) = 0. +Proof. by rewrite eexp_cst mule0. Qed. + +Lemma eexp_dlet {U: choiceType} mu (nu : T -> {distr U / R}) F : +(forall x, 0%:E <= F x)%E -> +espe (dlet nu mu) F = espe mu (fun x => espe (nu x) F). +Proof. +move => HF. +have pos : (forall (i : T) (j : U), (0%R <= F j * ((mu i)%:E * (nu i j)%:E))%E). +- move => i j; rewrite mule_ge0 //. + by rewrite mule_ge0 // lee_tofin. +rewrite /espe {1}(eq_esum _ _ + (fun x : U => (F x * esum [set:T] (fun y : T => (mu y * nu y x)%:E)))%E). +- move => x ?; rewrite /= dletE. + congr ( _ * _)%E. + rewrite fineK //= esum_abse => //=. + - by move => i; rewrite mulr_ge0. + - have : summable [set: T] (fun x0 : T => ((mu x0 * nu x0 x)%:E))%E. + + apply/(le_esummable (g := EFin \o mu)) => //=. + by move => x0; rewrite !lee_fin //= mulr_ge0 //= ler_piMr //= le1_mu1. + by rewrite summableE. +symmetry. +rewrite {1}(eq_esum _ _ + (fun x : T => (esum [set:U] (fun x0 : U => F x0 * ((mu x)%:E * (nu x x0)%:E))%E))). +- move => x ?; rewrite muleC. + rewrite -esumZ. + - move => x1; rewrite mule_ge0 //=. + - exact: (ge0_mu (nu x) x1). + rewrite {1}(eq_esum _ _ + (fun x0 : U => F x0 * ((mu x)%:E * (nu x x0)%:E))%E) // ?esum_sum' //. + - by move => ??; rewrite muleCA. +rewrite exchange_esum //. +rewrite {1}(eq_esum _ _ + (fun x => (F x * (\esum_(y in [set: T]) (mu y * nu y x)%:E))%E)) //. +- move => ??. rewrite esumZ //. + by move => ?; rewrite mule_ge0 // lee_tofin. +Qed. + +Lemma eexpZ mu F c : + (forall x, 0%:E <= F x)%E -> + espe mu (fun x => mule c (F x)) = mule c (espe mu F). +Proof. +move => h. +rewrite -esumZ. ++ by move => x; rewrite mule_ge0 // lee_tofin. +by apply/eq_esum => x ?; rewrite muleA. +Qed. + +Lemma eexpB mu (A B : T -> \bar R) : + (forall x, A x \is a fin_num) -> + summable [set: T] (fun x => (A x * (mu x)%:E)%E) -> + summable [set: T] (fun x => (B x * (mu x)%:E)%E) -> + espe mu (A \- B)%E = (espe mu A - espe mu B)%E. +Proof. +move=> fA sA sB; rewrite /espe. +rewrite (esum.eq_esum _ _ (fun x => (A x * (mu x)%:E - B x * (mu x)%:E)%E)). + by move => x ? /=; rewrite muleBl//; apply: fin_num_adde_defr; exact: fA. +exact: (esummable_esumB sA sB). +Qed. + +Lemma espE mu (g : T -> R) : + esp mu g = fine (espe mu (EFin \o g)). +Proof. +by rewrite /esp /espe; congr (fine _); apply: esum.eq_esum => x ? /=; rewrite EFinM. +Qed. + +Lemma espeEFin mu (g : T -> R) : + espe mu (EFin \o g) = esum [set: T] (EFin \o (fun x => g x * mu x)). +Proof. by rewrite /espe; apply: esum.eq_esum => x ? /=; rewrite EFinM. Qed. + +Lemma eexp_dlet_esp {U: choiceType} mu (nu : T -> {distr U / R}) (g : U -> R) : + (forall y, 0 <= g y) -> (forall eta, \E?_[eta] g) -> + espe (dlet nu mu) (EFin \o g) = espe mu (EFin \o (fun x => esp (nu x) g)). +Proof. +move=> ? sg. +rewrite (eexp_dlet mu nu ). ++ by move=> x; rewrite /= lee_fin. +apply eq_esum => ?? //=. +congr (_ * _)%E. +rewrite /esp fineK//. +exact: (esummable_esum_fin_num (sg (nu _))). +Qed. + +End EspeCoreTheory. + +(* -------------------------------------------------------------------- *) +Section PrTheory. +Context {R : realType} {T U : choiceType} {I : eqType}. + +Implicit Types (mu : {distr T / R}) (A B E : pred T). + +Lemma prE (nu : {distr T / R}) (E : pred T) : + (\P_[nu] E)%:E = \esum_(t in [set: T]) ((E t)%:R * nu t)%:E. +Proof. +rewrite /pr fineK// esum_abse//. ++ by move => ?; rewrite mulr_ge0. +by have := summable_pr E nu; rewrite summableE. +Qed. + +Lemma EFin_esumZ {J : choiceType} {c : R} {a : J -> R} : + 0 <= c -> (forall i, 0 <= a i) -> + \esum_(i in [set: J]) (c * a i)%:E = (c%:E * \esum_(i in [set: J]) (a i)%:E)%E. +Proof. +move=> c0 a0; rewrite -esumZ. +- by move=> i ?; rewrite lee_fin; exact: a0. +- by apply: eq_esum => i _; rewrite EFinM. +Qed. + +Lemma pr_dlet E f (mu : {distr U / R}) : + \P_[dlet f mu] E = \E_[mu] (fun x => \P_[f x] E). +Proof. +rewrite /pr /esp. +congr (fine _). +rewrite {1}(eq_esum _ _ (fun t => \esum_(x in [set: U]) ((E t)%:R * (mu x * f x t))%:E)%E). ++ by move => t _; rewrite EFinM dlet_EFin EFin_esumZ // => ?; rewrite mulr_ge0. +rewrite {1} exchange_esum//. ++ move=> t x;rewrite lee_fin. + by apply: mulr_ge0; [exact: ler0n|apply: mulr_ge0; exact: ge0_mu]. +apply: eq_esum => x _ //=. +rewrite EFinM prE muleC -EFin_esumZ //. ++ by move => ?; rewrite mulr_ge0. +by apply: eq_esum => t _; rewrite mulrCA. +Qed. + +Lemma pr_dmargin E f (mu : {distr U / R}) : + \P_[dmargin f mu] E = \P_[mu] [pred x | f x \in E]. +Proof. +by rewrite /dmargin pr_dlet pr_exp; apply/eq_exp=> x _; rewrite pr_dunit. +Qed. + +Lemma eq0_pr A mu : + (forall x, x \in dinsupp mu -> x \notin A) -> \P_[mu] A = 0. +Proof. +move=> h; rewrite /pr esum1 //= => x ?. +have -> // : (A x)%:R * mu x = 0. +apply /eqP; rewrite mulf_eq0 orbC; case/boolP: (mu x == 0) => //=. +by move/h; rewrite -topredE /= => /negbTE->. +Qed. + +Lemma eq0_prc A B mu : + (forall x, x \in dinsupp mu -> x \in B -> x \notin A) + -> \P_[mu, B] A = 0. +Proof. +move=> h; rewrite /prc eq0_pr ?mul0r // => x /h {h} /orb_idl. +by rewrite negb_and /= => <-; rewrite orbAC orbN. +Qed. + +Lemma subset_pr A B mu : {subset B <= A} -> \P_[mu] B <= \P_[mu] A. +Proof. +move=> le_BA; rewrite -lee_fin !prE. +apply: le_esum => x _; rewrite lee_fin. +rewrite ler_wpM2r // ?ge0_mu. +rewrite ler_nat; have := le_BA x; rewrite -!topredE /=. +by case: (B x) => // ->. +Qed. + +Lemma le1_pr A mu : \P_[mu] A <= 1. +Proof. +apply: (@le_trans _ _ \P_[mu] predT); first by apply/subset_pr. +rewrite pr_predT -fine1; apply: fine_le; [| by [] | exact: le1_mu]. +rewrite ge0_fin_numE; last first. ++ apply: le_lt_trans; [exact: le1_mu| by rewrite ltey]. +by apply: esum_ge0 => x _; rewrite lee_fin ge0_mu. +Qed. + +Lemma le_exp mu f1 f2: \E?_[mu] f1 -> \E?_[mu] f2 -> + f1 <=1 f2 -> \E_[mu] f1 <= \E_[mu] f2. +Proof. +move=> sm1 sm2 le_f; rewrite /esp; apply: fine_le. +- exact: (esummable_esum_fin_num sm1). +- exact: (esummable_esum_fin_num sm2). +- apply: le_esum. + move=> x /=; have hf := le_f x. + by rewrite lee_fin ler_wpM2r // ?ge0_mu. +Qed. + +Lemma le_in_pr E1 E2 mu : + (forall x, x \in dinsupp mu -> x \in E1 -> x \in E2) -> + \P_[mu] E1 <= \P_[mu] E2. +Proof. +move=> le; rewrite -lee_fin !prE. +apply: le_esum => x _; rewrite lee_fin. +case/boolP: (x \in dinsupp mu) => [xin|/dinsuppPn ->]; last by rewrite !mulr0. +have hE : (E1 x)%:R <= (E2 x)%:R :> R. + rewrite ler_nat; have := le x xin; rewrite -!topredE /=. + by case: (E1 x) => // ->. +by rewrite ler_wpM2r // ?ge0_mu. +Qed. + +Lemma le_mu_pr A mu nu : + (forall x, x \in dinsupp nu -> x \in A -> nu x <= mu x) + -> \P_[nu] A <= \P_[mu] A. +Proof. +move=> h; rewrite -lee_fin !prE. +apply: le_esum => x _; rewrite lee_fin. +case/boolP: (x \in dinsupp nu) => [/h {}h|]; last first. + by move/dinsuppPn=> ->; rewrite mulr0; apply: mulr_ge0; [exact: ler0n|exact: ge0_mu]. +by case/boolP: (A x) => [/h|]; rewrite ?(mul0r, mul1r). +Qed. + +Lemma le1_prc A B mu : \P_[mu, B] A <= 1. +Proof. +move: (ge0_pr B mu); rewrite /prc le_eqVlt. +case/orP=> [/eqP<-|]; first by rewrite invr0 mulr0 ler01. +move/ler_pdivrMr=> ->; rewrite mul1r. +by apply: le_in_pr => x _ /andP[]. +Qed. + +Lemma prc_sum A mu : 0 < \P_[mu] A -> + fine(esum [set: T] (fun x => (\P_[mu, A] (pred1 x))%:E)) = 1. +Proof. +move=> gt0. +have a0 : forall i, 0 <= (A i)%:R * mu i. + by move=> i; apply: mulr_ge0; [exact: ler0n|exact: ge0_mu]. +have hpr1 : forall x, \P_[mu] [predI pred1 x & A] = (A x)%:R * mu x. + move=> x; rewrite /pr. + rewrite (eq_esum _ _ ( fun y => if x == y then ((A y)%:R * mu y)%:E else 0)). + move=> y _ /=; rewrite !inE [y == x]eq_sym. + by case: ifP => xy; rewrite ?xy /= ?mul1r ?mul0r. + by rewrite esum_if_eq_op_set1. +rewrite (eq_esum _ _ (fun x => ((\P_[mu] A)^-1 * ((A x)%:R * mu x))%:E)). + by move=> x _; rewrite /prc hpr1; congr (_ %:E); rewrite mulrC. +rewrite (EFin_esumZ _ a0); last first. rewrite -prE -EFinM mulVf //. ++ by rewrite gt_eqF. + by rewrite invr_ge0; exact: ge0_pr. +Qed. + +Lemma pr_eq0 mu E : \P_[mu] E = 0 -> forall x, x \in E -> mu x = 0. +Proof. +move=> hE x xE. +have hle : \P_[mu] (pred1 x) <= \P_[mu] E. + by apply: subset_pr => y; rewrite !inE => /eqP ->. +move: hle; rewrite hE -pr_pred1 => h. +by apply/eqP; rewrite eq_le h /=; exact: ge0_mu. +Qed. + +Lemma prID A B mu : + \P_[mu] A = \P_[mu] [predI A & B] + \P_[mu] [predI A & predC B]. +Proof. +have ge0 : forall (P : pred T) i, (0 <= ((P i)%:R * mu i)%:E)%E. + by move=> P i; rewrite lee_fin mulr_ge0 ?ler0n ?ge0_mu. +apply: EFin_inj; rewrite EFinD !prE. +rewrite -(esumD (fun i _ => ge0 _ i) (fun i _ => ge0 _ i)). +apply: eq_esum => x _; rewrite -EFinD; congr (_ %:E). +rewrite !inE -!topredE /= -mulrDl; congr (_ * _). +rewrite -natrD; congr (_ %:R). +by case: (A x); case: (B x). +Qed. + +Lemma pr_or_indep (A B : pred T) (mu : {distr T / R}) : + (forall x, x \in A -> x \notin B) -> + \P_[mu] [predU A & B] = \P_[mu] A + \P_[mu] B. +Proof. +move=> dsj. +have ge0 : forall (P : pred T) i, (0 <= ((P i)%:R * mu i)%:E)%E. + by move=> P i; rewrite lee_fin mulr_ge0 ?ler0n ?ge0_mu. +apply: EFin_inj; rewrite EFinD !prE. +rewrite -(esumD (fun i _ => ge0 _ i) (fun i _ => ge0 _ i)). +apply: eq_esum => x _; rewrite -EFinD; congr (_ %:E). +rewrite !inE -!topredE /= -mulrDl; congr (_ * _). +rewrite -natrD; congr (_ %:R). +case/boolP: (A x) => Ax; case/boolP: (B x) => Bx //=. +by move/dsj: Ax; rewrite -topredE /= Bx. +Qed. + +Lemma pr_mem_map f mu (r : seq U) : uniq r -> + \P_[mu] [pred x | f x \in r] + = \sum_(y <- r) \P_[mu] [pred x | f x == y]. +Proof. +elim: r => [_|y r ih]; first by rewrite big_nil pr_pred0_eq //. +case/andP=> yNr /ih {ih}h; rewrite big_cons -h -pr_or_indep. + by move=> x; rewrite !inE => /eqP->. by apply/eq_pr. +Qed. + +Lemma pr_mem mu (r : seq T) : uniq r -> + \P_[mu] [pred x | x \in r] = \sum_(x <- r) mu x. +Proof. +elim: r => [_|y r ih]; first by rewrite big_nil pr_pred0_eq //. +case/andP=> yNr /ih {ih}h; rewrite big_cons /= pr_pred1. +by rewrite -h -pr_or_indep // => x /eqP ->. +Qed. + +Lemma pr_bigor_indep mu (P : I -> pred T) (r : seq I) : + uniq r + -> (forall p1 p2 x, p1 != p2 -> p1 \in r -> p2 \in r -> x \in P p1 -> x \notin P p2) + -> \P_[mu] [pred x | has [pred p | x \in P p] r] + = \sum_(p <- r) \P_[mu] (P p). +Proof. +move=> uq_r dj; pose S x := \big[orb/false]_(p <- r) (x \in P p). +rewrite (eq_pr (B := S)) => [x|]; first by rewrite !inE -big_has. +rewrite {}/S; elim: r uq_r dj => [_|p r ih /andP[pNr /ih {ih}h]] dj. + by rewrite big_nil pr_pred0_eq // => x; rewrite big_nil. +rewrite big_cons -h => [p1 p2 x ne_p p1r p2r|]. + by apply/dj=> //; rewrite in_cons (p1r, p2r) orbT. +rewrite -pr_or_indep => [x xNPp|]. + rewrite -topredE /= big_has; apply/hasPn => y y_in_r. + apply/(dj p); rewrite ?in_cons ?(eqxx, y_in_r, orbT) //. + by apply/contra: pNr=> /eqP->. +by apply/eq_pr=> x; rewrite -!topredE /= big_cons. +Qed. + +Lemma pr_or A B mu : \P_[mu] [predU A & B] = + \P_[mu] A + \P_[mu] B - \P_[mu] [predI A & B]. +Proof. +apply/eqP; rewrite eq_sym subr_eq [in X in _==X]addrC; apply/eqP. +rewrite (prID _ B) -addrA -pr_or_indep => [x|]. + by rewrite !inE => /andP[]. +congr (_ + _); apply/eq_pr => x; rewrite !inE -!topredE /=. +by apply/orb_id2r => /negbTE ->; rewrite andbT. +Qed. + +Lemma pr_and A B mu : \P_[mu] [predI A & B] = + \P_[mu] A + \P_[mu] B - \P_[mu] [predU A & B]. +Proof. by rewrite pr_or subKr. Qed. + +Lemma ler_pr_or A B mu : + \P_[mu] [predU A & B] <= \P_[mu] A + \P_[mu] B. +Proof. by rewrite pr_or lerBlDr lerDl ge0_pr. Qed. + +Lemma ler_pr_and A B mu : + \P_[mu] [predI A & B] <= \P_[mu] A + \P_[mu] B. +Proof. by rewrite pr_and lerBlDr lerDl ge0_pr. Qed. + +Lemma pr_predC E mu: \P_[mu](predC E) = \P_[mu] predT - \P_[mu] E. +Proof. +apply/esym/eqP; rewrite subr_eq -pr_or_indep //. +by apply/eqP/eq_pr=> x; rewrite !inE orNb. +Qed. + +Lemma pr_split B A mu : \P_[mu] A = + \P_[mu] B * \P_[mu, B] A + + \P_[mu] (predC B) * \P_[mu, predC B] A. +Proof. +suff h A' B': \P_[mu] [predI A' & B'] = \P_[mu] B' * \P_[mu, B'] A'. + by rewrite (prID _ B); congr (_ + _); apply/h. +rewrite /prc mulrCA; have [] := eqVneq (\P_[mu] B') 0; last first. + by move=> nzPB'; rewrite divff // mulr1. +move=> zPB'; rewrite zPB' invr0 !mulr0; apply/eq0_pr. +move=> x mux; move/pr_eq0: zPB' => /(_ x) h; rewrite !inE. +by apply/negP=> /andP[_ /h] /dinsuppP. +Qed. + +Lemma prc_pred1 (mu : {distr T / R}) x A : + prc mu (pred1 x) A = (A x)%:R * mu x / \P_[mu] A. +Proof. +rewrite /prc; congr (_ / _); rewrite /pr. +rewrite (eq_esum _ _ (fun y => if x == y then ((A y)%:R * mu y)%:E else 0)). + move=> y _ /=; rewrite !inE [y == x]eq_sym. + by case: ifP => xy; rewrite ?xy /= ?mul1r ?mul0r. +by rewrite esum_if_eq_op_set1. +Qed. + +Lemma summable_pr_f f mu (P : pred T): + \E?_[mu] f -> + summable [set: T] (EFin \o (fun x => (P x)%:R * (f x * mu x))). +Proof. +move=> sm; rewrite /summable //= . +rewrite (eq_esum _ _ + (fun x => `|((P x)%:R)%:E * (f x * mu x)%:E|)%E). +by move => i _ //; rewrite -abseM. +apply: esummableMl; last exact: sm. +exists 1%:E=> [x|]; last by []. +by rewrite gee0_abs ?lee_fin ?ler0n// lern1 leq_b1. +Qed. + +Lemma sum_fin_num_mu_f f mu (P : pred T): + \E?_[mu] f -> + esum [set:T] (EFin \o (fun x => (P x)%:R * (f x * mu x))) \is a fin_num. +Proof. + move=> ?; apply: esummable_esum_fin_num; exact: summable_pr_f. +Qed. + +Lemma pr_esp_sum mu f (P : pred T): + \E?_[mu] f -> + \P_[mu] P * \E_[mu, P] f = + fine (esum [set: T] (EFin \o (fun x => (P x)%:R * (f x * mu x)))). +Proof. +move => sm. + have [c0|cn0] := eqVneq (\P_[mu] P) 0. +rewrite c0 mul0r. + suff -> : esum [set:T] (EFin \o (fun x => (P x)%:R * (f x * mu x))) = 0 by rewrite fine0. + rewrite (esum.eq_esum _ _ (fun=> 0%E)) ?esum0// => x. + suff h0 : (P x)%:R * mu x = 0 :> R by rewrite /= mulrCA h0 mulr0. + case Hpx: (P x); last by rewrite mul0r. + by rewrite (pr_eq0 c0 Hpx) mulr0. +rewrite /espc. +rewrite (esum.eq_esum _ _ (fun x => ((\P_[mu] P)^-1 %:E * + (EFin \o (fun x => ((P x)%:R * (f x * mu x))%R)) x)%E)). + move=> x ?; rewrite /= prc_pred1 -EFinM; congr (_ %:E). + by rewrite mulrA mulrC; congr (_ * _); exact: mulrCA. +rewrite (esummable_esumZ _ (summable_pr_f P sm)); + first by rewrite abse_fin_num. +by rewrite fineM ?abse_fin_num ?sum_fin_num_mu_f// mulVKf. +Qed. + +Lemma exp_split A f mu : \E?_[mu] f -> \E_[mu] f = + \P_[mu] A * \E_[mu, A] f + + \P_[mu] (predC A) * \E_[mu, predC A] f. +Proof. +move=> sm. +rewrite (pr_esp_sum A) // (pr_esp_sum (predC A)) // /esp -fineD ?sum_fin_num_mu_f//. +congr fine; rewrite -(esummable_esumD (summable_pr_f A sm) (summable_pr_f (predC A) sm)). +apply: esum.eq_esum => x ? /=; rewrite -EFinD; congr (_ %:E). +rewrite -mulrDl -[LHS]mul1r; congr (_ * _). +by rewrite -natrD; case: (A x). +Qed. + +Lemma bounded_has_exp mu F : + (exists M, forall x, `|F x| <= M) -> \E?_[mu] F. +Proof. +case=> M leM; rewrite /has_esp /summable. +rewrite (eq_esum _ _ (fun x=> `|(F x)%:E * (mu x)%:E|)%E). + move=> x _; rewrite -EFinM //=. +apply: esummableMl; last exact: summable_mu. +exists M%:E => [x ?|]; last by []. +by rewrite /= lee_fin; exact: leM x. +Qed. + +Lemma summable_has_exp mu F : summable [set: T] (EFin \o F) -> \E?_[mu] F. +Proof. +move=> smF; rewrite /has_esp /summable. +rewrite (eq_esum _ _ (fun x=> `|(F x)%:E * (mu x)%:E|)%E). + move=> x _; rewrite -EFinM //=. +apply: esummableMr; last exact: smF. +exists 1%:E => [x ?|]; last by []. +by rewrite /= lee_fin (ger0_norm (ge0_mu _ _)); exact: le1_mu1. +Qed. + +Lemma exp_le_bd mu F (M : R) : + 0 <= M -> (forall x, `|F x| <= M) -> \E_[mu] F <= M. +Proof. +move=> ge0M bd; apply/(@le_trans _ _ (\E_[mu] (fun _ => M))). ++ apply/le_exp. + + by apply/bounded_has_exp; exists M. + + by apply/has_expC. + + by move=> x; apply/(le_trans _ (bd x))/ler_norm. +by rewrite exp_cst ler_piMl // le1_pr. +Qed. + +Lemma ge0_esp {V : choiceType} (eta : {distr V / R}) (g : V -> R) : + (forall y, 0 <= g y) -> 0 <= \E_[eta] g. +Proof. +move=> g0; rewrite /esp; apply: fine_ge0; apply: esum_ge0 => x ?. +by rewrite lee_fin mulr_ge0//; exact: g0. +Qed. + +Lemma exp_dlet_ge0 (mu : {distr T / R}) (nu : T -> {distr U / R}) (g : U -> R) : + (forall y, 0 <= g y) -> (forall eta, \E?_[eta] g) -> + \E_[dlet nu mu] g = \E_[mu] (fun x => \E_[nu x] g). +Proof. by move=> g0 sg; rewrite espE (eexp_dlet_esp mu nu g0 sg) -espE. Qed. + +Lemma has_esp_le {V:choiceType} (mu : {distr V / R}) (k h : V -> R) : + (forall x, `|k x| <= `|h x|) -> \E?_[mu] h -> \E?_[mu] k. +Proof. +move=> kh; rewrite /has_esp => fh. +rewrite summableE ge0_fin_numE. ++ apply: esum_ge0 => i _; exact: abse_ge0. +apply: (le_lt_trans _ fh). +apply: le_esum. +by move => ??; rewrite lee_fin !normrM ler_wpM2r. +Qed. + +Lemma hcomp (mu : {distr T / R}) (nu : T -> {distr U / R}) (g : U -> R) : + (forall y, 0 <= g y) -> (forall eta, \E?_[eta] g) -> \E?_[mu] (fun x => \E_[nu x] g). +Proof. +move=> g0 sg. +have hge0 : forall x, 0 <= esp (nu x) g * mu x. + by move=> x; apply: mulr_ge0; [exact: ge0_esp | exact: ge0_mu]. +rewrite /has_esp summableE. +rewrite (esum.eq_esum _ _ (EFin \o (fun x => esp (nu x) g * mu x))). ++ move=> x _ /=; rewrite ger0_norm //. +rewrite -espeEFin -(eexp_dlet_esp mu nu g0 sg) espeEFin. +exact: (esummable_esum_fin_num (sg (dlet nu mu))). +Qed. + +Lemma expB {V: choiceType} (f g : V -> R) (eta : {distr V / R}) : + \E?_[eta] f -> \E?_[eta] g -> \E_[eta] (f \- g) = \E_[eta] f - \E_[eta] g. +Proof. +move=> sf sg. +rewrite !espE -fineB //. ++ by rewrite espeEFin; exact: (esummable_esum_fin_num sf). ++ by rewrite espeEFin; exact: (esummable_esum_fin_num sg). +congr (fine _). +rewrite {1}(eexp_eq (g:=fun x => ((f x)%:E - (g x)%:E))%E). ++ move => ?. rewrite -EFinB //. +exact : eexpB. +Qed. + +Lemma exp_dlet mu (nu : T -> {distr U / R}) F : + (forall eta, \E?_[eta] F) -> + \E_[dlet nu mu] F = \E_[mu] (fun x => \E_[nu x] F). +Proof. +move=> sF. +have spF : forall eta, \E?_[eta] F^\+. ++ by move=> eta //=; apply: (has_esp_le (le_funrpos F) (sF eta)). +have snF : forall eta, \E?_[eta] F^\-. ++ by move=> eta; apply: (has_esp_le (le_funrneg F) (sF eta)). +transitivity (\E_[mu] (fun x => \E_[nu x] F^\+) + - \E_[mu] (fun x => \E_[nu x] F^\-)). +rewrite -(exp_dlet_ge0 mu nu _ spF) // -(exp_dlet_ge0 mu nu _ snF) //. +rewrite -(expB (spF _) (snF _)); congr (\E_[dlet nu mu] _); symmetry; exact :funrposBneg. +rewrite -(expB (hcomp mu nu _ spF) (hcomp mu nu _ snF)) //. +apply: eq_exp => x _ /=. +rewrite -(expB (spF _) (snF _)). +congr (\E_[nu x] _); exact : funrposBneg. +Qed. + +End PrTheory. + +(* -------------------------------------------------------------------- *) +Section mono_esum. +Context + {R : realType} + {T : choiceType} + {f : {ndistr T/ R}}. + +Lemma mono_esum_Efn (E: T -> \bar R): + (forall m, 0 <= E m)%E -> + forall m n, (m <= n)%N -> + (esum [set:T] (fun x => E x * (f m x)%:E) <= + esum [set:T] (fun x => E x * (f n x)%:E))%E. +Proof. +move=> hE m n le_mn. +apply /esum.le_esum. +move => ??; rewrite lee_pmul => //=. +- rewrite lee_tofin //. +- rewrite lee_tofin //; exact: nmu_decrease. +Qed. + +Lemma distr_lub_sup a : + ((dlim f) a)%:E = ereal_sup (range (fun n => (f n a)%:E)). +Proof. by rewrite dlim_EFin (sup_range_lim (nd_f f a)). Qed. + +Lemma esum_dlim_r [E : T -> \bar R] [r : \bar R]: + (forall m, 0 <= E m)%E -> + (forall (n : nat), esum [set:T] (fun x : T => E x * (f n x)%:E) <= r)%E -> + (esum [set:T] (fun x : T => E x * ((dlim f ) x)%:E) <= r)%E. +Proof. +move => hE h. +rewrite (@esum.eq_esum _ _ _ _ (fun x => ereal_sup (range (fun n => E x * (f n x)%:E)%E))). +- move => ??; rewrite distr_lub_sup. + rewrite (@ge0_ereal_supZl_range R T (fun a b => (f b a)%:E)) //. + move => ??; rewrite lee_tofin //. +rewrite exchange_esum_ereal_sup //. +- by move => ??; rewrite mule_ge0 // lee_tofin. +- by move => ????; rewrite lee_pmul // ?lee_tofin // ; exact: nmu_decrease. +rewrite ge_ereal_sup//= => x [n s] <-. +exact: h. +Qed. + +Lemma esum_dlim_r_r [E : T -> R] [r : \bar R]: + (forall m, 0 <= E m) -> + (forall (n : nat), esum [set:T] (fun x : T => (E x * f n x)%:E) <= r)%E -> + (esum [set:T] (fun x : T => (E x * (dlim f ) x)%:E) <= r)%E. +Proof. +move=> hE h. +rewrite (eq_esum _ _ (fun x : T => ((E x)%:E * ((dlim f) x)%:E)%E)). ++ by move => ? _; rewrite EFinM. +apply: (esum_dlim_r (E := fun x => (E x)%:E)). +- by move=> m; exact: (lee_tofin (hE m)). +- move=> n; under eq_esum => x _ do rewrite -EFinM. + exact: h n. +Qed. + +Lemma esum_dlim (E : pred T) : + esum [set:T] (fun x : T => ((E x)%:R * (dlim f) x)%:E) = + limn (fun n => esum [set:T] (fun x : T => ((E x)%:R * f n x)%:E)). +Proof. +have hmono : forall n m, (n <= m)%N -> forall x, + (((E x)%:R * f n x)%:E <= ((E x)%:R * f m x)%:E)%E. + move=> n m nm x; rewrite lee_fin; apply: ler_wpM2l; first exact: ler0n. + by rewrite -lee_fin; exact: (nd_f f x nm). +transitivity (ereal_sup (range + (fun n => esum [set:T] (fun x : T => ((E x)%:R * f n x)%:E)))); last first. + by apply: sup_range_lim => n m nm; apply: le_esum => x _; exact: (hmono n m nm x). +rewrite -(@exchange_esum_ereal_sup R T (fun x n => ((E x)%:R * f n x)%:E)) //. ++ by move=> x n; rewrite lee_fin; apply: mulr_ge0; [exact: ler0n | exact: ge0_mu]. ++ move => x n m nm. exact: (hmono n m nm x). +apply: eq_esum => x _. +rewrite EFinM distr_lub_sup (@ge0_ereal_supZl_range R T (fun a b => (f b a)%:E)) //. ++ by move=> t n; rewrite lee_fin; exact: ge0_mu. +Qed. + +End mono_esum. + +(* -------------------------------------------------------------------- *) +Lemma distr_eqP {R : realType} {T : choiceType} (f1 f2 : {distr T / R}): + f1 =1 f2 <-> f1 = f2. +Proof. +split=> [|->] //. +case: f1 => f1 [[]ge0_1 s1 le1_1]. +case: f2 => f2 [[]ge0_2 s2 le1_2]. +move => /funext /= h. +subst;f_equal; f_equal; f_equal => //=. +Qed. From 44a0f6892a64676c8a2089954f43079a47ec22b5 Mon Sep 17 00:00:00 2001 From: Lionel Blatter Date: Fri, 21 Aug 2026 13:39:57 +0200 Subject: [PATCH 02/18] Some cleanup --- theories/probability_theory/counting_distr.v | 76 +++++++++++--------- 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/theories/probability_theory/counting_distr.v b/theories/probability_theory/counting_distr.v index 6b4acec285..69114a695d 100644 --- a/theories/probability_theory/counting_distr.v +++ b/theories/probability_theory/counting_distr.v @@ -2,7 +2,6 @@ From HB Require Import structures. From mathcomp Require Import boot order algebra. From mathcomp.classical Require Import boolp classical_sets mathcomp_extra. From mathcomp Require Import xfinmap constructive_ereal reals discrete. -From mathcomp Require Import realseq realsum. From mathcomp Require Import esum sequences normedtype ereal cardinality fsbigop. (* Should be removed *) @@ -17,6 +16,13 @@ Import Order.TTheory GRing.Theory Num.Theory. Local Open Scope ring_scope. +(* -------------------------------------------------------------------- *) +Notation "f '<=1' g" := (forall x, f x <= g x) + (at level 70, no associativity). + +Notation "f '<=2' g" := (forall x y, f x y <= g x y) + (at level 70, no associativity). + (* -------------------------------------------------------------------- *) Local Notation simpm := Monoid.simpm. @@ -43,7 +49,7 @@ Local Notation "\`| f |" := (fun x => `|f x|) (at level 2). HB.mixin Record isDistribution (R : realType) (T : choiceType) (mu : T -> R) := { mu_positive : forall x, 0 <= mu x ; - mu_summable : summable [set: T] (EFin \o mu); + mu_summable : esummable [set: T] (EFin \o mu); mu_sum_le_one : (esum [set: T] (EFin \o mu) <= 1)%E; }. @@ -64,7 +70,7 @@ Proof. exact: mu_positive. Qed. Lemma le1_mu : (esum [set: T] (EFin \o mu) <= 1)%E. Proof. exact: mu_sum_le_one. Qed. -Lemma summable_mu : summable [set: T] (EFin \o mu). +Lemma summable_mu : esummable [set: T] (EFin \o mu). Proof. exact: mu_summable. Qed. End DistrCoreTh. @@ -122,7 +128,7 @@ Definition prc mu E A := pr mu [predI E & A] / pr mu A. Definition esp mu f := fine (esum [set: T] (EFin \o (fun x => f x * mu x))). Definition espc mu f A := fine (esum [set: T] (EFin \o (fun x => f x * prc mu (pred1 x) A))). -Definition has_esp mu f := summable [set: T] (EFin \o (fun x => f x * mu x)). +Definition has_esp mu f := esummable [set: T] (EFin \o (fun x => f x * mu x)). End StdDefs. Notation "\P_[ mu ] E" := (pr mu E). @@ -144,10 +150,10 @@ Hypothesis isd : isdistr. Local Lemma isd1 : forall x, 0 <= mu x. Proof. by case: isd. Qed. -Local Lemma isd2 : summable [set: T] (EFin \o mu). +Local Lemma isd2 : esummable [set: T] (EFin \o mu). Proof. case isd => ? h2. -rewrite /summable (@le_lt_trans _ _ 1%:E) ?ltey//. +rewrite /esummable (@le_lt_trans _ _ 1%:E) ?ltey//. rewrite ge0_esum // ge_ereal_sup//= => _ [X [finX _]] <-. rewrite fsumEFin // lee_fin fsbig_finite //=. rewrite (eq_bigr (fun x => mu x)). @@ -168,7 +174,7 @@ Qed. Definition mkdistrd := @isDistribution.Build R T mu isd1 isd2 isd3. Definition ispredistr {T : choiceType} (mu : T -> R) := - [/\ forall x, 0 <= mu x & summable [set: T] (EFin \o mu)]. + [/\ forall x, 0 <= mu x & esummable [set: T] (EFin \o mu)]. End DistrTheory. @@ -184,7 +190,7 @@ Lemma le1_mu1 {R : realType} {T : choiceType} (mu : {distr T / R}) x : mu x <= 1. Proof. case mu => //= {}mu [[?]]. -rewrite summableE => ??. +rewrite esummableE => ??. rewrite -lee_fin. apply/(@le_trans _ _ ((esum [set: T] (EFin \o mu))))=> //. rewrite esum_ge1 //. @@ -227,7 +233,7 @@ move=> eqJ; apply/(@le_trans _ _ (\sum_(j <- J) `|mu j|)). by apply/ler_norm. by apply/normr_ge0. + rewrite -lee_fin. apply/(le_trans _ (le1_mu mu)). - case mu => //= {}mu [[?]]; rewrite summableE => ? _. + case mu => //= {}mu [[?]]; rewrite esummableE => ? _. rewrite (@eq_esum _ _ _ _ (fun y : T => `|(EFin \o mu) y|%E)) //=. + by move => ??; rewrite ger0_norm. exact: sum_esum_ge. @@ -299,9 +305,9 @@ rewrite -sum1_size -[in RHS]big_undup_iterop_count/=; apply: eq_bigr => i _. by rewrite Monoid.iteropE iter_addn addn0 mul1n. Qed. -Local Lemma summable_drat s: summable [set :T] (EFin \o (drat s)). +Local Lemma summable_drat s: esummable [set :T] (EFin \o (drat s)). Proof. -rewrite /summable (@le_lt_trans _ _ 1%:E) ?ltey//. +rewrite /esummable (@le_lt_trans _ _ 1%:E) ?ltey//. rewrite ge0_esum // ge_ereal_sup//= => _ [X [finX _]] <-. rewrite fsumEFin // lee_fin fsbig_finite //=. rewrite (eq_bigr (drat s)). @@ -395,7 +401,7 @@ split=> [x|J uqJ]. rewrite muleC gee_pMl // ?lee_tofin //;last first. exact : (le1_mu (f i)). rewrite (eq_esum _ _ (fun x => `|(EFin \o f i) x|%E)) //. + by move => ??; rewrite gee0_abs //= lee_tofin. - by have := (summable_mu (f i)); rewrite summableE. + by have := (summable_mu (f i)); rewrite esummableE. Qed. HB.instance Definition _ := @mkdistrd R U dlet isd_dlet. @@ -421,9 +427,9 @@ Proof. by move => ?; apply eq_esum => ?? ; rewrite gee0_abs // lee_tofin. Qed. Lemma summable_mu_wgtd {R : realType} {T : choiceType} (f : T -> R) (mu : {distr T / R}) : - (forall x, 0 <= f x <= 1) -> summable [set: T] (fun x => EFin (mu x * f x)). + (forall x, 0 <= f x <= 1) -> esummable [set: T] (fun x => EFin (mu x * f x)). Proof. -rewrite /summable => h. +rewrite /esummable => h. under eq_esum do rewrite EFinM. apply: esummableMr => //. + exists 1%E => // => i. @@ -482,7 +488,7 @@ by move/dinsuppPn => ->; rewrite !mul0e. Qed. Lemma summable_dlet (f : T -> {distr U / R}) (mu : {distr T / R}) y : - summable [set: T] (fun x : T => EFin (mu x * (f x) y)). + esummable [set: T] (fun x : T => EFin (mu x * (f x) y)). Proof. by apply/summable_mu_wgtd=> x; rewrite ge0_mu le1_mu1. Qed. Lemma fin_esum (f : T -> {distr U / R}) (mu : {distr T / R}) y: @@ -490,7 +496,7 @@ Lemma fin_esum (f : T -> {distr U / R}) (mu : {distr T / R}) y: Proof. rewrite esum_abse. + by move => ?; rewrite mulr_ge0. -by have := (summable_dlet f mu y); rewrite summableE. +by have := (summable_dlet f mu y); rewrite esummableE. Qed. Lemma le_in_dlet f g mu : {in dinsupp mu, f <=2 g} -> @@ -528,7 +534,7 @@ rewrite esumZ ?lee_tofin //= => [?| ]; rewrite ?lee_tofin //. rewrite fineM => //=;last first. + rewrite mulrC. symmetry. by under eq_esum do rewrite mul1r. -by rewrite esum_abse //; have := (summable_mu mu); rewrite summableE. +by rewrite esum_abse //; have := (summable_mu mu); rewrite esummableE. Qed. @@ -1271,9 +1277,9 @@ by apply: eq_esum => y _ /=; rewrite dunit_id mulr1. Qed. Lemma summable_fst (mu : {distr (T * U)%type / R}) x : - summable [set:U] (fun y => (mu (x, y))%:E). + esummable [set:U] (fun y => (mu (x, y))%:E). Proof. -rewrite /summable; apply: le_lt_trans (summable_mu mu). +rewrite /esummable; apply: le_lt_trans (summable_mu mu). rewrite -(reindex_esum [set:U] [set z : T * U | z.1 = x] (fun y => (x, y)) (fun z => (`|(mu z)%:E|)%E)). + split. @@ -1296,7 +1302,7 @@ Proof. Qed. Lemma summable_snd (mu : {distr (T * U)%type / R}) y : - summable [set:T] (fun x => (mu (x, y))%:E). + esummable [set:T] (fun x => (mu (x, y))%:E). Proof. have := summable_fst (dswap mu) y; apply/eq_esummable. by move=> x /=; rewrite dswapE. @@ -1309,7 +1315,7 @@ Context {R : realType} {T : choiceType}. Implicit Types (mu : {distr T / R}) (A B E : pred T). -Lemma summable_pr E mu : summable [set:T] (fun x => ((E x)%:R * mu x)%:E). +Lemma summable_pr E mu : esummable [set:T] (fun x => ((E x)%:R * mu x)%:E). Proof. apply/(le_esummable (g := EFin \o mu)) => [x|]; last by apply/summable_mu. rewrite !lee_tofin => //=. @@ -1398,7 +1404,7 @@ Proof. by rewrite exp_cst mulr0. Qed. Lemma has_expC mu c : \E?_[mu] (fun _ => c). Proof. rewrite /has_esp. -have : summable [set: T] (fun x : T => (c%:E * (mu x)%:E)%E). +have : esummable [set: T] (fun x : T => (c%:E * (mu x)%:E)%E). by apply: esummableZl => //; exact: summable_mu. apply/eq_esummable => x /=. by rewrite EFinM. @@ -1500,7 +1506,7 @@ rewrite esumZ. - move => ?; rewrite lee_fin //. rewrite muleC; congr ( _ * _)%E. rewrite fineK //= esum_abse => //=. -by have := (summable_mu mu); rewrite summableE. +by have := (summable_mu mu); rewrite esummableE. Qed. Lemma eexp0 mu : espe mu (fun _ => 0) = 0. @@ -1520,10 +1526,10 @@ rewrite /espe {1}(eq_esum _ _ congr ( _ * _)%E. rewrite fineK //= esum_abse => //=. - by move => i; rewrite mulr_ge0. - - have : summable [set: T] (fun x0 : T => ((mu x0 * nu x0 x)%:E))%E. + - have : esummable [set: T] (fun x0 : T => ((mu x0 * nu x0 x)%:E))%E. + apply/(le_esummable (g := EFin \o mu)) => //=. by move => x0; rewrite !lee_fin //= mulr_ge0 //= ler_piMr //= le1_mu1. - by rewrite summableE. + by rewrite esummableE. symmetry. rewrite {1}(eq_esum _ _ (fun x : T => (esum [set:U] (fun x0 : U => F x0 * ((mu x)%:E * (nu x x0)%:E))%E))). @@ -1553,8 +1559,8 @@ Qed. Lemma eexpB mu (A B : T -> \bar R) : (forall x, A x \is a fin_num) -> - summable [set: T] (fun x => (A x * (mu x)%:E)%E) -> - summable [set: T] (fun x => (B x * (mu x)%:E)%E) -> + esummable [set: T] (fun x => (A x * (mu x)%:E)%E) -> + esummable [set: T] (fun x => (B x * (mu x)%:E)%E) -> espe mu (A \- B)%E = (espe mu A - espe mu B)%E. Proof. move=> fA sA sB; rewrite /espe. @@ -1599,7 +1605,7 @@ Lemma prE (nu : {distr T / R}) (E : pred T) : Proof. rewrite /pr fineK// esum_abse//. + by move => ?; rewrite mulr_ge0. -by have := summable_pr E nu; rewrite summableE. +by have := summable_pr E nu; rewrite esummableE. Qed. Lemma EFin_esumZ {J : choiceType} {c : R} {a : J -> R} : @@ -1857,9 +1863,9 @@ Qed. Lemma summable_pr_f f mu (P : pred T): \E?_[mu] f -> - summable [set: T] (EFin \o (fun x => (P x)%:R * (f x * mu x))). + esummable [set: T] (EFin \o (fun x => (P x)%:R * (f x * mu x))). Proof. -move=> sm; rewrite /summable //= . +move=> sm; rewrite /esummable //= . rewrite (eq_esum _ _ (fun x => `|((P x)%:R)%:E * (f x * mu x)%:E|)%E). by move => i _ //; rewrite -abseM. @@ -1913,7 +1919,7 @@ Qed. Lemma bounded_has_exp mu F : (exists M, forall x, `|F x| <= M) -> \E?_[mu] F. Proof. -case=> M leM; rewrite /has_esp /summable. +case=> M leM; rewrite /has_esp /esummable. rewrite (eq_esum _ _ (fun x=> `|(F x)%:E * (mu x)%:E|)%E). move=> x _; rewrite -EFinM //=. apply: esummableMl; last exact: summable_mu. @@ -1921,9 +1927,9 @@ exists M%:E => [x ?|]; last by []. by rewrite /= lee_fin; exact: leM x. Qed. -Lemma summable_has_exp mu F : summable [set: T] (EFin \o F) -> \E?_[mu] F. +Lemma summable_has_exp mu F : esummable [set: T] (EFin \o F) -> \E?_[mu] F. Proof. -move=> smF; rewrite /has_esp /summable. +move=> smF; rewrite /has_esp /esummable. rewrite (eq_esum _ _ (fun x=> `|(F x)%:E * (mu x)%:E|)%E). move=> x _; rewrite -EFinM //=. apply: esummableMr; last exact: smF. @@ -1958,7 +1964,7 @@ Lemma has_esp_le {V:choiceType} (mu : {distr V / R}) (k h : V -> R) : (forall x, `|k x| <= `|h x|) -> \E?_[mu] h -> \E?_[mu] k. Proof. move=> kh; rewrite /has_esp => fh. -rewrite summableE ge0_fin_numE. +rewrite esummableE ge0_fin_numE. + apply: esum_ge0 => i _; exact: abse_ge0. apply: (le_lt_trans _ fh). apply: le_esum. @@ -1971,7 +1977,7 @@ Proof. move=> g0 sg. have hge0 : forall x, 0 <= esp (nu x) g * mu x. by move=> x; apply: mulr_ge0; [exact: ge0_esp | exact: ge0_mu]. -rewrite /has_esp summableE. +rewrite /has_esp esummableE. rewrite (esum.eq_esum _ _ (EFin \o (fun x => esp (nu x) g * mu x))). + move=> x _ /=; rewrite ger0_norm //. rewrite -espeEFin -(eexp_dlet_esp mu nu g0 sg) espeEFin. From 0f5c2b8bdae6b35ed9dda580b844c002144d05c4 Mon Sep 17 00:00:00 2001 From: Lionel Blatter Date: Mon, 24 Aug 2026 10:26:19 +0200 Subject: [PATCH 03/18] Some refactoring for dlim --- theories/probability_theory/counting_distr.v | 679 ++++++++----------- 1 file changed, 294 insertions(+), 385 deletions(-) diff --git a/theories/probability_theory/counting_distr.v b/theories/probability_theory/counting_distr.v index 69114a695d..9c431cc515 100644 --- a/theories/probability_theory/counting_distr.v +++ b/theories/probability_theory/counting_distr.v @@ -1,8 +1,9 @@ From HB Require Import structures. From mathcomp Require Import boot order algebra. -From mathcomp.classical Require Import boolp classical_sets mathcomp_extra. +From mathcomp.classical Require Import boolp classical_sets mathcomp_compat. From mathcomp Require Import xfinmap constructive_ereal reals discrete. -From mathcomp Require Import esum sequences normedtype ereal cardinality fsbigop. +From mathcomp Require Import esum ereal. +From mathcomp Require Import cardinality fsbigop topology normedtype sequences. (* Should be removed *) From mathcomp Require Import numfun. @@ -58,7 +59,7 @@ HB.structure Definition Distribution (R : realType) (T : choiceType) := Notation "{ 'distr' T / R }" := (@Distribution.type R T) (at level 0, T at level 2, format "{ 'distr' T / R }") - : type_scope. + : type_scope. (* -------------------------------------------------------------------- *) Section DistrCoreTh. @@ -154,7 +155,9 @@ Local Lemma isd2 : esummable [set: T] (EFin \o mu). Proof. case isd => ? h2. rewrite /esummable (@le_lt_trans _ _ 1%:E) ?ltey//. -rewrite ge0_esum // ge_ereal_sup//= => _ [X [finX _]] <-. +rewrite ge0_esum //. ++ by move => ? _;rewrite lee_fin. +rewrite ge_ereal_sup//= => _ [X [finX _]] <-. rewrite fsumEFin // lee_fin fsbig_finite //=. rewrite (eq_bigr (fun x => mu x)). + by move => ??; rewrite ger0_norm. @@ -180,7 +183,8 @@ End DistrTheory. Lemma isdistr_finP {R : realType} {I : finType} (mu : I -> R) : (isdistr mu) <-> (forall x, 0 <= mu x) /\ (\sum_j mu j <= 1). -Proof. split=> -[ ge0_mu le1]; split=> //. +Proof. +split=> -[ ge0_mu le1]; split=> //. + by apply/le1; rewrite /index_enum -enumT enum_uniq. + move=> J uqJ; rewrite big_uniq 1?(le_trans _ le1) //=. by rewrite [X in _<=X](bigID (mem J)) /= lerDl sumr_ge0. @@ -201,15 +205,17 @@ Qed. Section DistrD. Context {R : realType} {T : choiceType}. -Definition dnull := fun x : T => (0 : R). +Definition dnull_fun := fun x : T => (0 : R). -Lemma isd_mnull : isdistr dnull. +Lemma isd_mnull : isdistr dnull_fun. Proof. by split=> // J _; rewrite big1 ?ler01. Qed. -HB.instance Definition _ := @mkdistrd R T dnull isd_mnull. +HB.instance Definition _ := @mkdistrd R T dnull_fun isd_mnull. + +Definition dnull := @locked {distr T / R} dnull_fun. Lemma dnullE x : dnull x = 0. -Proof. by []. Qed. +Proof. by unlock dnull. Qed. End DistrD. @@ -222,14 +228,14 @@ Proof. by move=> x; rewrite dnullE ge0_mu. Qed. Section Restr. Context (R : realType) (T : choiceType) (p : pred T). -Definition drestr (mu : {distr T / R}) := +Definition drestr_fun (mu : {distr T / R}) := fun x => if p x then mu x else 0. -Lemma isd_drestr (mu : {distr T / R}) : isdistr (drestr mu). +Lemma isd_drestr (mu : {distr T / R}) : isdistr (drestr_fun mu). Proof. -split=> [x|J]; first by rewrite /drestr; case: ifP. +split=> [x|J]; first by rewrite /drestr_fun; case: ifP. move=> eqJ; apply/(@le_trans _ _ (\sum_(j <- J) `|mu j|)). -+ apply/ler_sum=> i _; rewrite /drestr; case: ifPn=> _. ++ apply/ler_sum=> i _; rewrite /drestr_fun; case: ifPn=> _. by apply/ler_norm. by apply/normr_ge0. + rewrite -lee_fin. apply/(le_trans _ (le1_mu mu)). @@ -240,11 +246,13 @@ move=> eqJ; apply/(@le_trans _ _ (\sum_(j <- J) `|mu j|)). Qed. HB.instance Definition _ (mu : {distr T / R}) := - @mkdistrd R T (drestr mu) (isd_drestr mu). + @mkdistrd R T (drestr_fun mu) (isd_drestr mu). + +Definition drestr (mu : {distr T / R}) := @locked {distr T / R} (drestr_fun mu). Lemma drestrE (mu : {distr T / R}) x : drestr mu x = if p x then mu x else 0. -Proof. by []. Qed. +Proof. by unlock drestr. Qed. End Restr. (* -------------------------------------------------------------------- *) @@ -272,13 +280,13 @@ Local Notation distr := {distr T / R}. Implicit Types (s : seq T). -Definition drat (s : seq T) : T -> R := +Definition drat_fun (s : seq T) : T -> R := fun x : T => (count (pred1 x) s)%:R / (size s)%:R. -Lemma ge0_drat s : forall x, 0 <= drat s x. +Lemma ge0_drat s : forall x, 0 <= drat_fun s x. Proof. by move=> x; rewrite mulr_ge0 ?invr_ge0 // ler0n. Qed. -Local Lemma has_sup_drat s J : uniq J -> \sum_(i <- J) drat s i <= 1. +Local Lemma has_sup_drat s J : uniq J -> \sum_(i <- J) drat_fun s i <= 1. Proof. move=> uqJ; rewrite -mulr_suml /= -natr_sum; case: (size s =P 0%N). by move=> ->; rewrite invr0 mulr0 ler01. @@ -296,7 +304,7 @@ by move=> x; rewrite !mem_filter mem_undup andbC. Qed. Local Lemma drat_sup s : (0 < size s)%N -> - \sum_(i <- undup s) drat s i = 1. + \sum_(i <- undup s) drat_fun s i = 1. Proof. move=> gt0_s; rewrite -mulr_suml -natr_sum. apply/(mulIf (x := (size s)%:R)); first by rewrite pnatr_eq0 -lt0n. @@ -305,43 +313,47 @@ rewrite -sum1_size -[in RHS]big_undup_iterop_count/=; apply: eq_bigr => i _. by rewrite Monoid.iteropE iter_addn addn0 mul1n. Qed. -Local Lemma summable_drat s: esummable [set :T] (EFin \o (drat s)). +Local Lemma summable_drat s: esummable [set :T] (EFin \o (drat_fun s)). Proof. rewrite /esummable (@le_lt_trans _ _ 1%:E) ?ltey//. -rewrite ge0_esum // ge_ereal_sup//= => _ [X [finX _]] <-. +rewrite ge0_esum. ++ by move => ? _;rewrite lee_fin. +rewrite ge_ereal_sup//= => _ [X [finX _]] <-. rewrite fsumEFin // lee_fin fsbig_finite //=. -rewrite (eq_bigr (drat s)). +rewrite (eq_bigr (drat_fun s)). + move => ??; rewrite ger0_norm ?ge0_drat //. by apply/has_sup_drat. Qed. -Lemma isd_drat s : isdistr (drat s). +Lemma isd_drat s : isdistr (drat_fun s). Proof. by split; [apply/ge0_drat | apply/has_sup_drat]. Qed. HB.instance Definition _ (s : seq T) := - @mkdistrd R T (drat s) (isd_drat s). + @mkdistrd R T (drat_fun s) (isd_drat s). + +Definition drat (s : seq T) := @locked {distr T / R} (drat_fun s). Lemma drat1E s x : drat s x = (count_mem x s)%:R / (size s)%:R. -Proof. by []. Qed. +Proof. by unlock drat. Qed. -Definition dunit x := @locked {distr T / R} (drat [:: x] ). -Definition duni s := @locked {distr T / R} (drat (undup s)). +Definition dunit x := drat [:: x]. +Definition duni s := drat (undup s). Lemma dunit1E x y : (dunit x) y = (x == y)%:R. -Proof. by unlock dunit; rewrite /= drat1E /= !(simpm, invr1). Qed. +Proof. by rewrite /dunit drat1E /= !(simpm, invr1). Qed. Lemma dunit_id x : (dunit x) x = 1. -Proof. by unlock dunit; rewrite /= drat1E /= !(simpm, invr1) eq_refl. Qed. +Proof. by rewrite /dunit drat1E /= !(simpm, invr1) eq_refl. Qed. Lemma dunit_diff x y: x <> y -> (dunit x) y = 0. Proof. - unlock dunit; rewrite /= drat1E /= !(simpm, invr1). + rewrite /dunit drat1E /= !(simpm, invr1). by case_eq (x == y) => //= /eqP. Qed. Lemma duni1E s x : (duni s) x = (x \in s)%:R / (size (undup s))%:R. -Proof. by unlock duni; rewrite /= drat1E count_uniq_mem ?(mem_undup, undup_uniq). Qed. +Proof. by rewrite /duni drat1E count_uniq_mem ?(mem_undup, undup_uniq). Qed. Lemma in_dunit t t' : t' \in dinsupp (dunit t) -> t' = t :> T. @@ -352,20 +364,22 @@ End DRat. Section Flip. Context {R : realType}. -Definition dflip (xt : R) := +Definition dflip_fun (xt : R) := fun b => if b then clamp xt else 1 - clamp xt. -Lemma isd_dflip xt : isdistr (dflip xt). +Lemma isd_dflip xt : isdistr (dflip_fun xt). Proof. apply/isdistr_finP; split=> [b|]. + by case: b; rewrite ?subr_ge0 cp01_clamp. + by rewrite /index_enum !unlock /= addr0 addrC subrK. Qed. HB.instance Definition _ (xt : R) := - @mkdistrd R _ (dflip xt) (isd_dflip xt). + @mkdistrd R _ (dflip_fun xt) (isd_dflip xt). + +Definition dflip (xt : R) := @locked {distr bool / R} (dflip_fun xt). Lemma dflip1E xt : dflip xt =1 (fun b => if b then clamp xt else 1 - clamp xt). -Proof. by []. Qed. +Proof. by unlock dflip. Qed. End Flip. (* -------------------------------------------------------------------- *) @@ -373,7 +387,7 @@ Section Bind. Context {R : realType} {T U : choiceType} (f : T -> {distr U / R}) (mu : {distr T /R}). -Definition dlet := fun y : U => fine (esum [set:T] (fun x => EFin (mu x * f x y))). +Definition dlet_fun := fun y : U => fine (esum [set:T] (fun x => EFin (mu x * f x y))). Lemma dlet_pos x : 0 <= fine (\esum_(x0 in [set: T]) (mu x0 * f x0 x)%:E). Proof. @@ -383,11 +397,11 @@ rewrite -lee_fin -{}h esum_ge0 // => ??. by rewrite EFinM mule_ge0 //= lee_tofin. Qed. -Lemma isd_dlet : isdistr dlet. +Lemma isd_dlet : isdistr dlet_fun. Proof. split=> [x|J uqJ]. + exact: dlet_pos. -+ rewrite /dlet -lee_fin. ++ rewrite /dlet_fun -lee_fin. have hpos : (forall x i, 0 <= (mu x * f x i)%:E )%E. + by move => ?? ;rewrite EFinM mule_ge0 //= lee_tofin. apply /le_trans. @@ -404,10 +418,12 @@ split=> [x|J uqJ]. by have := (summable_mu (f i)); rewrite esummableE. Qed. -HB.instance Definition _ := @mkdistrd R U dlet isd_dlet. +HB.instance Definition _ := @mkdistrd R U dlet_fun isd_dlet. + +Definition dlet := @locked {distr U / R} dlet_fun. Lemma dletE y : dlet y = fine (esum [set:T] (fun x => EFin (mu x * f x y))). -Proof. by []. Qed. +Proof. by unlock dlet. Qed. End Bind. Notation "\dlet_ ( i <- d ) E" := (dlet (fun i => E) d). @@ -476,8 +492,7 @@ Qed. Lemma eq_in_dlet f g mu nu : {in dinsupp mu, f =2 g} -> mu =1 nu -> dlet f mu =1 dlet g nu. Proof. -move=> eq_f eq_mu; unlock dlet=> y /=. -rewrite /dlet. +move=> eq_f eq_mu y; rewrite !dletE. have -> //= : (\esum_(x in [set: T]) (mu x * f x y)%:E = \esum_(x in [set: T]) (nu x * g x y)%:E). apply /eq_esum. @@ -499,10 +514,14 @@ rewrite esum_abse. by have := (summable_dlet f mu y); rewrite esummableE. Qed. +Lemma dlet_EFin (f : T -> {distr U / R}) (mu : {distr T / R}) y : + (dlet f mu y)%:E = esum [set:T] (fun x => (mu x * f x y)%:E). +Proof. by rewrite dletE fineK// ?fin_esum. Qed. + Lemma le_in_dlet f g mu : {in dinsupp mu, f <=2 g} -> dlet f mu <=1 dlet g mu. Proof. -move=> le_f; unlock dlet=> y /=; rewrite /dlet fine_le // ?fin_esum //. +move=> le_f y; rewrite !dletE fine_le // ?fin_esum //. apply: le_esum => x ?. case /boolP: (x \in dinsupp mu) => [/le_f ?|]. rewrite !EFinM lee_pmul //= lee_tofin //=. @@ -511,7 +530,7 @@ Qed. Lemma le_mu_dlet f mu nu : mu <=1 nu -> dlet f mu <=1 dlet f nu. Proof. -move => le_mu y; unlock dlet; rewrite /dlet fine_le //= ?fin_esum //. +move => le_mu y; rewrite !dletE fine_le //= ?fin_esum //. apply: le_esum => x ?. by rewrite !EFinM lee_pmul //= lee_tofin. Qed. @@ -537,7 +556,6 @@ rewrite fineM => //=;last first. by rewrite esum_abse //; have := (summable_mu mu); rewrite esummableE. Qed. - Lemma dinsupp_dlet f mu y : y \in dinsupp (\dlet_(x <- mu) f x) -> exists2 x, x \in dinsupp mu & f x y != 0. @@ -583,7 +601,7 @@ Qed. Lemma eq0_dlet (mu : {distr T / R}) (F : T -> {distr U / R}) y : (\dlet_(x <- mu) F x) y = 0 -> forall x, x \in dinsupp mu -> F x y = 0. Proof. -unlock dlet; rewrite /= /dlet => /fine_esum0 => h x. +rewrite dletE => /fine_esum0 => h x. move => /dinsuppP /eqP mu_x. move: (h x). by move=> /eqP ; rewrite eqe mulf_eq0 (negbTE mu_x) /= => /eqP. Qed. @@ -599,15 +617,15 @@ Lemma dlet_dlet (mu : {distr T / R}) : \dlet_(x <- \dlet_(y <- mu) f1 y) f2 x =1 \dlet_(y <- mu) (\dlet_(x <- f1 y) f2 x). Proof. -move=> z; unlock dlet => /=; rewrite /dlet /=. +move=> z; rewrite !dletE. pose S y x := mu x * f1 x y * f2 y z. rewrite (eq_esum _ _ (fun y => \esum_(x in [set: T]) (S y x)%:E)%E). -+ move => y ?; subst S; rewrite EFinM fineK ?fin_esum //. ++ move => y ?; subst S; rewrite EFinM dlet_EFin //. + rewrite muleC -esumZ // ?lee_tofin // => [? |]. + by rewrite EFinM lee_tofin // mulr_ge0. + by apply eq_esum => ??; rewrite -EFinM mulrC. rewrite (eq_esum _ _ (fun x => \esum_(y in [set: U]) (S y x)%:E)%E). -+ move => x ?; subst S; rewrite EFinM fineK ?fin_esum //. ++ move => x ?; subst S; rewrite EFinM dlet_EFin //. + rewrite -esumZ // ?lee_tofin // => [? |]. + by rewrite EFinM lee_tofin // mulr_ge0. + by apply eq_esum => ??; rewrite -EFinM mulrA. @@ -632,20 +650,11 @@ Qed. End DLetAlg. (* -------------------------------------------------------------------- *) +Lemma mono_nondecressing {R : realType} (T : choiceType) (f : nat -> T -> R) + (hmono : forall n m, (n <= m)%N -> forall x, f n x <= f m x) : + forall x, nondecreasing_seq (fun n => (f n x)%:E). +Proof. by move=> x n m nm; rewrite lee_fin; exact: hmono. Qed. -HB.mixin Record isNDistribution - (R : realType) (T : choiceType) (nmu : nat -> {distr T / R}) := - { nmu_decrease : forall x, nondecreasing_seq (fun n => (nmu n x)%:E); }. - -HB.structure Definition NDistribution (R : realType) (T : choiceType) := - {f of @isNDistribution R T f }. - -Notation "{ 'ndistr' T / R }" := (@NDistribution.type R T) - (at level 0, T at level 2, format "{ 'ndistr' T / R }") - : type_scope. - - -(* -------------------------------------------------------------------- *) Lemma sup_range_lim {R : realType} (u : (\bar R)^nat) : nondecreasing_seq u -> ereal_sup (range u) = limn u. Proof. @@ -653,204 +662,187 @@ by move=> ndu; apply/esym/cvg_lim => //; exact: ereal_nondecreasing_cvgn. Qed. (* -------------------------------------------------------------------- *) -Section dlim. -Context {R : realType} (T : choiceType). +(* Generic facts about [einfs] / [limn_einf] missing from sequences.v, *) +(* used below to make [dlim] total on sequences of subdistributions. *) +Lemma einfs_le {R : realType} (u : (\bar R)^nat) n m : + (n <= m)%N -> (einfs u n <= u m)%E. +Proof. by move=> nm; apply: ereal_inf_lbound; exists m; [exact: nm | by []]. Qed. -Lemma nd_f (f : {ndistr T / R}) : forall x, nondecreasing_seq (fun n => (f n x)%:E). -Proof. exact: nmu_decrease. Qed. +Lemma einfs_lift {R : realType} (u : (\bar R)^nat) p n : + einfs (fun k => u (k + p)%N) n = einfs u (n + p)%N. +Proof. +congr (ereal_inf _); apply/seteqP; split => _ /= [k /= nk] <-. +- by exists (k + p)%N => //=; rewrite leq_add2r. +- have pk : (p <= k)%N by apply: leq_trans nk; exact: leq_addl. + exists (k - p)%N => /=; last by rewrite subnK. + by rewrite -(leq_add2r p) subnK. +Qed. -Lemma id1 (f : {ndistr T / R}): forall x, cvgn (fun n => (f n x)%:E). +Lemma limn_einf_lift {R : realType} (u : (\bar R)^nat) p : + limn_einf (fun n => u (n + p)%N) = limn_einf u. Proof. -case f => {}f [[nd_f] ?]. -by move=> x; apply: ereal_nondecreasing_is_cvgn; exact: nd_f. +rewrite !limn_einf_lim. +have -> : einfs (fun k => u (k + p)%N) = (fun n => einfs u (n + p)%N). + by apply/funext => n; exact: einfs_lift. +by apply/cvg_lim => //; rewrite (cvg_shiftn p (einfs u)); exact: is_cvg_einfs. Qed. -(* Definition dlim (f : {ndistr T / R}) : T -> R := *) -(* fun x => fine (ereal_sup (range (fun n : nat => (f n x)%:E))). *) +Lemma limn_einf_bump {R : realType} (u : (\bar R)^nat) : + limn_einf (fun n => u n.+1) = limn_einf u. +Proof. +rewrite -(limn_einf_lift u 1); congr limn_einf. +by apply/funext => n; rewrite addn1. +Qed. + +Lemma limn_einf_cst {R : realType} (c : \bar R) : limn_einf (fun=> c) = c. +Proof. by rewrite is_cvg_limn_einfE ?lim_cst//; exact: is_cvg_cst. Qed. + +(* -------------------------------------------------------------------- *) +Section dlim. +Context {R : realType} (T : choiceType). + +Implicit Types (f g : nat -> {distr T / R}). Import numFieldNormedType.Exports. -Definition dlim (f : {ndistr T / R}) : T -> R := - fun x => fine (limn (fun n : nat => (f n x)%:E)). +Definition dlim_fun f : T -> R := + fun x => fine (limn_einf (fun n : nat => (f n x)%:E)). -Lemma le1_lim (f : {ndistr T / R}) : - forall x, (limn (fun n => (f n x)%:E) <= 1%:E)%E. +Lemma ge0_liminf f x : (0 <= limn_einf (fun n => (f n x)%:E))%E. Proof. - move=> x; apply: lime_le; [ exact: id1| apply: nearW]. - move=> n; rewrite lee_fin. - exact: le1_mu1. +rewrite limn_einf_lim; apply: lime_ge; first exact: is_cvg_einfs. +apply: nearW => n; apply: le_ereal_inf_tmp => _ [m _] <-. +by rewrite lee_fin. Qed. -Lemma fin_lim (f : {ndistr T / R}) : - forall x, limn (fun n => (f n x)%:E) \is a fin_num. +Lemma le1_liminf f x : (limn_einf (fun n => (f n x)%:E) <= 1%:E)%E. Proof. - move=> x; rewrite ge0_fin_numE //. - + by apply: lime_ge; [exact: id1 | apply: nearW => n; rewrite lee_fin]. - apply: le_lt_trans;[ apply le1_lim | apply ltry]. +rewrite limn_einf_lim; apply: lime_le; first exact: is_cvg_einfs. +apply: nearW => n; apply: (@le_trans _ _ ((f n x)%:E)); first exact: einfs_le. +by rewrite lee_fin le1_mu1. Qed. -Lemma sumlim (f : {ndistr T / R}): - forall L, uniq L -> - (\sum_(j <- L) limn (fun n => (f n j)%:E) = - limn (fun n => \sum_(j <- L) (f n j)%:E))%E. +Lemma fin_liminf f x : limn_einf (fun n => (f n x)%:E) \is a fin_num. Proof. -elim => [|a L IH] uqL. -- rewrite big_nil. - apply/esym/cvg_lim => //. +have h0 : (0 <= limn_einf (fun n => (f n x)%:E))%E by exact: ge0_liminf. +rewrite ge0_fin_numE//. +by apply: le_lt_trans; [apply: le1_liminf | apply: ltry]. +Qed. + +Lemma dlim_fun_EFin f x : (dlim_fun f x)%:E = limn_einf (fun n => (f n x)%:E). +Proof. by rewrite /dlim_fun fineK// fin_liminf. Qed. + +Lemma sumlim {u : T -> (\bar R)^nat} : + (forall j, nondecreasing_seq (u j)) -> (forall j, limn (u j) \is a fin_num) -> + forall L, (\sum_(j <- L) limn (u j) = limn (fun n => \sum_(j <- L) u j n))%E. +Proof. +move=> ndu fu; elim => [|a L IH]. +- rewrite big_nil; apply/esym/cvg_lim => //. by apply: cvg_near_cst; apply: nearW => n; rewrite big_nil. -- case/andP: uqL => _ uqL. - rewrite big_cons IH //. +- rewrite big_cons IH. under [in RHS]eq_fun => n do rewrite big_cons. apply/esym/cvg_lim => //. apply: cvgeD. - + apply: fin_num_adde_defr; exact: fin_lim. - + exact: id1. + + by apply: fin_num_adde_defr; exact: fu. + + by apply: ereal_nondecreasing_is_cvgn; exact: ndu. + apply: ereal_nondecreasing_is_cvgn => n m nm. - by apply: lee_sum => j _; exact : nd_f. + by apply: lee_sum => j _; exact: ndu. Qed. -Lemma dlim_EFin (f : {ndistr T / R}): - forall x, (dlim f x)%:E = limn (fun n => (f n x)%:E). +Lemma isd_dlim f : isdistr (dlim_fun f). Proof. -move=> x; rewrite /dlim fineK //. -exact: fin_lim. +split=> [x|J uqJ]. + by rewrite /dlim_fun; apply: fine_ge0; exact: ge0_liminf. +have ndE : forall j : T, nondecreasing_seq (einfs (fun n => (f n j)%:E)). + by move=> j; exact: nondecreasing_einfs. +have finE : forall j : T, limn (einfs (fun n => (f n j)%:E)) \is a fin_num. + by move=> j; rewrite -limn_einf_lim fin_liminf. +rewrite -lee_fin -sumEFin. +under eq_bigr => j _ do rewrite dlim_fun_EFin limn_einf_lim. +rewrite (sumlim ndE finE); apply: lime_le. + apply: ereal_nondecreasing_is_cvgn => n m nm. + by apply: lee_sum => j _; exact: ndE. +apply: nearW => n; apply: (@le_trans _ _ (\sum_(j <- J) (f n j)%:E)). + by apply: lee_sum => j _; exact: einfs_le. +rewrite sumEFin. +apply: (@le_trans _ _ (esum [set: T] (EFin \o f n))); last exact: le1_mu. +exact: sum_esum_ge. Qed. -Lemma isd_dlim (f : {ndistr T / R}): isdistr (dlim f). -Proof. -split=> [x|J uqJ]; rewrite /dlim. -+ case h: (limn _) => //=. - rewrite -lee_fin -{}h. - apply: lime_ge; first exact: id1. - apply: nearW => n. - by rewrite lee_fin. -+ rewrite -lee_fin -sumEFin. - under eq_bigr => j _ do rewrite -/(dlim f j) dlim_EFin //. - rewrite sumlim //. - apply: lime_le. - + apply: ereal_nondecreasing_is_cvgn => n m nm. - by apply: lee_sum => j _ ; exact: nd_f. - + apply: nearW => n; rewrite sumEFin. - apply: (@le_trans _ _ (esum [set: T] (EFin \o f n))); last exact: le1_mu. - exact: sum_esum_ge. -Qed. +HB.instance Definition _ f := @mkdistrd R T (dlim_fun f) (isd_dlim f). -HB.instance Definition _ (f : {ndistr T / R}) := @mkdistrd R T (dlim f) (isd_dlim f). +Definition dlim f := @locked {distr T / R} (dlim_fun f). -Lemma dlimE (f : {ndistr T / R}) x : - (dlim f) x = fine (limn (fun n => EFin(f n x))). -Proof. by []. Qed. +Lemma dlimE f x : dlim f x = fine (limn_einf (fun n => (f n x)%:E)). +Proof. by unlock dlim. Qed. -End dlim. +Lemma dlim_EFin f x : (dlim f x)%:E = limn_einf (fun n => (f n x)%:E). +Proof. by unlock dlim; exact: dlim_fun_EFin. Qed. -Lemma mono_nondecressing {R : realType} (T : choiceType) (f : nat -> T -> R) - (hmono : forall n m, (n <= m)%N -> forall x, f n x <= f m x) : - forall x, nondecreasing_seq (fun n => (f n x)%:E). -Proof. by move=> x n m nm; rewrite lee_fin; exact: hmono. Qed. - -Notation "\dlim_ ( n ) E" := (dlim (fun n => E)). -(* -------------------------------------------------------------------- *) - -Section DLimC. -Variables (R : realType) (T U : choiceType). - -Implicit Types (mu : {distr T / R}). +Definition homo (f : nat -> {distr T / R}) := + forall n m, (n <= m)%N -> f n <=1 f m. -Definition nmuc mu := fun (_:nat) => mu. +Definition nd (f : nat -> {distr T / R}) := + forall x, nondecreasing_seq (fun n => (f n x)%:E). -Lemma isnd_ndc mu : forall x, nondecreasing_seq (fun n => (nmuc mu n x)%:E). -Proof. -by apply: mono_nondecressing. -Qed. +Lemma dhomo_dnd f : homo f -> nd f. +Proof. by move=> hf; apply: mono_nondecressing => n m nm x; exact: hf. Qed. -HB.instance Definition _ mu:= @isNDistribution.Build R T (nmuc mu) (isnd_ndc mu). +Lemma cvg_dlim f : nd f -> forall x, cvgn (fun n => (f n x)%:E). +Proof. by move=> ndf x; apply: ereal_nondecreasing_is_cvgn; exact: ndf. Qed. -Lemma dlimC mu : forall x, (dlim (nmuc mu)) x = mu x. +Lemma dlim_limE f : nd f -> + forall x, dlim f x = fine (limn (fun n => (f n x)%:E)). Proof. -move=> x; rewrite dlimE /= /nmuc. -have -> : limn (fun n : nat => (mu x)%:E) = (mu x)%:E. - by apply/cvg_lim => //; exact: cvg_cst. -by []. +by move=> ndf x; rewrite dlimE is_cvg_limn_einfE//; exact: cvg_dlim. Qed. -End DLimC. - -Section DLimBump. -Variables (R : realType) (T U : choiceType). - -Definition bump (nmu :{ndistr T / R}) := fun n => nmu (n.+1). - -Lemma isnd_bump nmu : forall x, nondecreasing_seq (fun n => (bump nmu n x)%:E). +Lemma dlim_limEFin f : nd f -> + forall x, (dlim f x)%:E = limn (fun n => (f n x)%:E). Proof. -apply: mono_nondecressing. -rewrite /bump => n m h x. -by apply: nmu_decrease. +by move=> ndf x; rewrite dlim_EFin is_cvg_limn_einfE//; exact: cvg_dlim. Qed. -HB.instance Definition _ nmu := - @isNDistribution.Build R T (bump nmu) (isnd_bump nmu). - -Lemma dlim_bump (nmu: {ndistr T / R}) : dlim (bump nmu) =1 dlim nmu. -Proof. -move=> x; rewrite /dlim /=. -congr (fine _). -apply/cvg_lim => //. -rewrite (cvg_shiftS (fun k => (nmu k x)%:E)). -exact: id1. -Qed. +Lemma dlim_sup f : nd f -> + forall x, (dlim f x)%:E = ereal_sup (range (fun n => (f n x)%:E)). +Proof. by move=> ndf x; rewrite (dlim_limEFin ndf) -(sup_range_lim (ndf x)). Qed. -End DLimBump. +End dlim. -Section DLimLift. +Notation "\dlim_ ( n ) E" := (dlim (fun n => E)). +(* -------------------------------------------------------------------- *) +Section DLimTheory. Variables (R : realType) (T U : choiceType). -Definition lift (nmu : {ndistr T / R}) p := fun n => nmu (n + p). +Implicit Types (f g : nat -> {distr T / R}) (h : T -> {distr U / R}). +Implicit Types (mu : {distr T / R}). -Lemma isnd_lift nmu p : forall x, nondecreasing_seq (fun n => (lift nmu p n x)%:E). +Lemma dlimC mu : \dlim_(n) mu =1 mu. Proof. -apply: mono_nondecressing. -rewrite /lift => n m h x. -apply: nmu_decrease. -by rewrite leq_add2r. +by move=> x; rewrite dlimE limn_einf_cst. Qed. -HB.instance Definition _ nmu p := - @isNDistribution.Build R T (lift nmu p ) (isnd_lift nmu p). - -Lemma dlim_lift (nmu : {ndistr T / R}) p : - dlim (lift nmu p) =1 dlim nmu. -Proof. -move=> x; rewrite /dlim /=. -congr (fine _). -apply/cvg_lim => //. -rewrite (cvg_shiftn p (fun k => (nmu k x)%:E)). -exact: id1. -Qed. - -End DLimLift. - -Section DLimTheory. -Variables (R : realType) (T U : choiceType). +Lemma dlim_bump f : \dlim_(n) f n.+1 =1 dlim f. +Proof. by move=> x; rewrite !dlimE (limn_einf_bump (fun n => (f n x)%:E)). Qed. -Implicit Types (f g : {ndistr T / R}) (h : T -> {distr U / R}). -Implicit Types (mu : {distr T / R}). +Lemma dlim_lift f p : \dlim_(n) f (n + p)%N =1 dlim f. +Proof. by move=> x; rewrite !dlimE (limn_einf_lift (fun n => (f n x)%:E) p). Qed. Lemma ge0_dlim f : forall x, 0 <= dlim f x. Proof. exact: mu_positive. Qed. Lemma le1_dlim f : forall x, dlim f x <= 1. -Proof. -move => x; rewrite /= dlimE -lee_fin dlim_EFin. -exact: le1_lim. -Qed. +Proof. by move=> x; rewrite -lee_fin dlim_EFin; exact: le1_liminf. Qed. Lemma le_dlim f g : (forall n, f n <=1 g n) -> dlim f <=1 dlim g. Proof. -move=> le x; rewrite -lee_fin !dlim_EFin. -apply: lee_lim; [exact: id1 | exact: id1 |]. -by apply: nearW => n; rewrite lee_fin; apply: le. +move=> le x; rewrite -lee_fin !dlim_EFin !limn_einf_lim. +apply: lee_lim; [exact: is_cvg_einfs | exact: is_cvg_einfs |]. +apply: nearW => n; apply: le_ereal_inf_tmp => _ [m /= nm] <-. +apply: (@le_trans _ _ ((f m x)%:E)); first exact: einfs_le. +by rewrite lee_fin; exact: le. Qed. Lemma eq_dlim f g : (forall n, f n =1 g n) -> dlim f =1 dlim g. @@ -866,11 +858,11 @@ Proof. by apply : le_dlim => n y. Qed. -Lemma dlim_ub f k : f k <=1 dlim f. +Lemma dlim_ub f k : homo f -> f k <=1 dlim f. Proof. -move=> x; rewrite -lee_fin dlim_EFin. -apply: lime_ge; first exact: id1. -near=> n; apply: (nd_f f x). +move=> hf x; rewrite -lee_fin (dlim_limEFin (dhomo_dnd hf)). +apply: lime_ge; first exact: (cvg_dlim (dhomo_dnd hf)). +near=> n; apply: (dhomo_dnd hf x). by near: n; apply: nbhs_infty_ge. Unshelve. all: by end_near. Qed. @@ -880,56 +872,42 @@ End DLimTheory. Section DletDLim. Variables (R : realType) (T U : choiceType). -Implicit Types (f : {ndistr T / R}) (h : T -> {distr U / R}). - -Definition ndlet f h: (nat -> {distr U / R}) := fun n => dlet h (f n). - -Lemma isnd_dlet h f : forall x, nondecreasing_seq (fun n => (ndlet f h n x)%:E). -Proof. -apply: mono_nondecressing => n m hnm x. -apply: le_mu_dlet => y. -by apply nd_f. -Qed. - -HB.instance Definition _ h f := - @isNDistribution.Build R U (ndlet f h) (isnd_dlet h f). - -Lemma dlet_EFin h (mu : {distr T / R}) y : - (dlet h mu y)%:E = esum [set:T] (fun x => (mu x * h x y)%:E). -Proof. by rewrite dletE fineK// ?fin_esum. Qed. +Implicit Types (f : nat -> {distr T / R}) (h : T -> {distr U / R}). -Lemma sup_mul (nf : {ndistr T / R}) (c : R) x : 0 <= c -> - ((dlim nf x) * c)%:E = ereal_sup (range (fun n => (nf n x * c)%:E)). +Lemma sup_mul f (hf : nd f) (c : R) x : 0 <= c -> + ((dlim f x) * c)%:E = ereal_sup (range (fun n => (f n x * c)%:E)). Proof. move=> c0. -rewrite EFinM dlim_EFin -(sup_range_lim (nd_f nf x)) muleC. -rewrite (@ge0_ereal_supZl_range R T (fun t n => (nf n t)%:E)) //=. +rewrite EFinM (dlim_sup hf) muleC. +rewrite (@ge0_ereal_supZl_range R T (fun t n => (f n t)%:E)) //=. + by move=> t n; rewrite lee_fin; exact: ge0_mu. have -> : - [set (c%:E * (nf i x)%:E)%E | i in [set: nat]]%classic = - [set (nf i x * c)%:E | i in [set: nat]]%classic. + [set (c%:E * (f i x)%:E)%E | i in [set: nat]]%classic = + [set (f i x * c)%:E | i in [set: nat]]%classic. apply/seteqP; split. - by move=> ? [x0 ?]; rewrite -EFinM mulrC=> <- //=; exists x0. - by move=> ? [x0 ?]; rewrite mulrC EFinM => <- //=; exists x0. reflexivity. Qed. -Lemma dlet_lim f h : dlet h (dlim f) =1 dlim (ndlet f h). +Lemma dlet_lim f h : nd f -> dlet h (dlim f) =1 \dlim_(n) (dlet h (f n)). Proof. -move=> y; apply: EFin_inj. -rewrite dlet_EFin dlim_EFin. -under eq_esum => x _ do rewrite sup_mul//. -rewrite -(sup_range_lim (nd_f (ndlet f h) y)). +move=> ndf y; apply: EFin_inj. +have nd : nd (fun n => dlet h (f n)). ++ apply: mono_nondecressing => n m hnm x. + apply: le_mu_dlet => ?; rewrite -lee_fin; exact: ndf. +rewrite dlet_EFin (dlim_sup nd). +under eq_esum => x _ do rewrite (sup_mul ndf)//. rewrite (@exchange_esum_ereal_sup R T (fun x n => (f n x * h x y)%:E)) /=. + by move=> t n; rewrite lee_fin; apply: mulr_ge0; exact: ge0_mu. + move=> n m nm t; rewrite lee_fin; apply: ler_wpM2r; first exact: ge0_mu. - by rewrite -lee_fin; apply: nd_f. + by rewrite -lee_fin; exact: ndf. have -> : [set \esum_(x in [set: T]) (f i x * h x y)%:E | i in [set: nat]]%classic = [set ((\dlet_(i <- f i) h i) y)%:E | i in [set: nat]]%classic. apply/seteqP; split. - by move=> ? [x0 ?]; rewrite -dlet_EFin => <- //=; exists x0. - - by move=> ? [x0 ?]; rewrite /ndlet dlet_EFin => <- //=; exists x0. + - by move=> ? [x0 ?]; rewrite dlet_EFin => <- //=; exists x0. reflexivity. Qed. @@ -939,49 +917,30 @@ Section DLimDlet. Context (R : realType) (T U : choiceType) (f : nat -> T -> {distr U / R}). Context (hmono: forall x n m, (n <= m)%N -> f n x <=1 f m x). -Definition reduce y : (nat -> {distr U / R}) := fun n => f n y. - -Lemma isnd_reduce y : - forall x, nondecreasing_seq (fun n => (reduce y n x)%:E). -Proof. -apply: mono_nondecressing => n m hnm x. -exact: hmono. -Qed. - -HB.instance Definition _ y := - @isNDistribution.Build R U (reduce y) (isnd_reduce y ). - -Definition mu_dlet mu: (nat -> {distr U / R}) := fun n => dlet (f n) mu. - -Lemma isnd_mu_dlet (mu : {distr T / R}) : - forall x, nondecreasing_seq (fun n => (mu_dlet mu n x)%:E). -Proof. -apply: mono_nondecressing => n m hnm x. -apply: le_in_dlet => z _. -exact: hmono. -Qed. - -HB.instance Definition _ mu := - @isNDistribution.Build R U (mu_dlet mu) (isnd_mu_dlet mu). - Lemma dlim_let (mu : {distr T / R}) : - dlim (mu_dlet mu) =1 dlet (fun x => dlim (reduce x )) mu. + \dlim_(n) \dlet_(x <- mu) (f n x) =1 \dlet_(x <- mu) \dlim_(n) (f n x). Proof. +have nd1 y : nd (fun n => f n y). ++ apply: mono_nondecressing => n m hnm x. + exact: hmono. +have nd2 : nd (fun n => dlet (f n) mu). ++ apply: mono_nondecressing => n m hnm x. + apply: le_in_dlet => z _. + exact: hmono. move=> z; apply: EFin_inj. -rewrite dlim_EFin dlet_EFin. -under eq_esum => t _ do rewrite mulrC sup_mul//. -rewrite -(sup_range_lim (nd_f (mu_dlet mu) z)). -rewrite (@exchange_esum_ereal_sup R T (fun t n => (reduce t n z * mu t)%:E)) /=. -+ by move=> t n; rewrite /reduce lee_fin; apply: mulr_ge0; exact: ge0_mu. -+ move=> n m nm t; rewrite /reduce lee_fin; apply: ler_wpM2r; first exact: ge0_mu. +rewrite (dlim_sup nd2 ) dlet_EFin. +under eq_esum => t _ do rewrite mulrC (sup_mul (nd1 t))//. +rewrite (@exchange_esum_ereal_sup R T (fun t n => (f n t z * mu t)%:E)) /=. ++ by move=> t n; rewrite lee_fin; apply: mulr_ge0; exact: ge0_mu. ++ move=> n m nm t; rewrite lee_fin; apply: ler_wpM2r; first exact: ge0_mu. exact: hmono. have ->: [set ((\dlet_(i0 <- mu) f i i0) z)%:E | i in [set: nat]]%classic = - [set \esum_(x in [set: T]) (reduce x i z * mu x)%:E | i in [set: nat]]%classic. + [set \esum_(x in [set: T]) (f i x z * mu x)%:E | i in [set: nat]]%classic. apply/seteqP; split. - move=> ? [x0 ?]; rewrite dlet_EFin=> <-//=; exists x0 => //=. - by under eq_esum do rewrite /reduce mulrC. - - move=> ? [x0 ?]; under eq_esum do rewrite /reduce mulrC. + by under eq_esum do rewrite mulrC. + - move=> ? [x0 ?]; under eq_esum do rewrite mulrC. by move => <- //=; exists x0 => //=; rewrite -dlet_EFin. reflexivity. Qed. @@ -993,113 +952,67 @@ Context (R : realType) (T : choiceType) (f : nat -> nat -> {distr T / R}). Context (hmono1: (forall k n1 n2, (n1 <= n2)%N -> f n1 k <=1 f n2 k)). Context (hmono2: (forall k n1 n2, (n1 <= n2)%N -> f k n1 <=1 f k n2)). -Definition apply2 : (nat -> {distr T / R}) := (fun n => f n n). - -Lemma isnd_apply2: - forall x, nondecreasing_seq (fun n => (apply2 n x)%:E). +Lemma dhomo_apply2 : homo (fun n => f n n). Proof. -apply: mono_nondecressing => n m hnm x. -rewrite /apply2. +move=> n m hnm x. apply /le_trans. + apply hmono1. exact: hnm. by apply: hmono2. Qed. -HB.instance Definition _ := - @isNDistribution.Build R T apply2 isnd_apply2. - -Definition apply (k:nat) : (nat -> {distr T / R}) := f k. - -Lemma isnd_apply k: - forall x, nondecreasing_seq (fun n => (apply k n x)%:E). -Proof. -apply: mono_nondecressing => n m hnm x. -by apply: hmono2. -Qed. - -HB.instance Definition _ k := - @isNDistribution.Build R T (apply k) (isnd_apply k). - -Definition dlim_apply : (nat -> {distr T / R}) := (fun n => dlim (apply n)). - -Lemma isnd_dlim_apply: - forall x, nondecreasing_seq (fun n => (dlim_apply n x)%:E). -Proof. -apply: mono_nondecressing => n m hnm x. -apply le_dlim => ??. -by apply: hmono1. -Qed. - -HB.instance Definition _ := - @isNDistribution.Build R T dlim_apply isnd_dlim_apply. - Lemma leub_dlim_dlim1 : - dlim dlim_apply <=1 dlim apply2. + \dlim_(n) dlim (f n) <=1 \dlim_(n) (f n n). Proof. apply: leub_dlim => n. apply: leub_dlim => m x. -apply: (@le_trans _ _ (apply2 (maxn n m) x)); last exact: dlim_ub. -apply: (@le_trans _ _ (f (maxn n m) m x)). -- apply: hmono1; exact: leq_maxl. -- apply: hmono2; exact: leq_maxr. +apply: (@le_trans _ _ (f (maxn n m) (maxn n m) x)). + apply: (@le_trans _ _ (f (maxn n m) m x)). + - apply: hmono1; exact: leq_maxl. + - apply: hmono2; exact: leq_maxr. +apply: dlim_ub. +exact : dhomo_apply2. Qed. Lemma dlim_dlim_ub1 : - dlim apply2 <=1 dlim dlim_apply. + \dlim_(n) (f n n) <=1 \dlim_(n) dlim (f n). Proof. apply: leub_dlim => n x. -apply: (@le_trans _ _ (dlim (apply n) x)). -- exact: (dlim_ub (apply n) n). -- exact: (dlim_ub dlim_apply n). +apply: (@le_trans _ _ (dlim (f n) x)). +- apply: dlim_ub. + by move=> *; apply: hmono2. +- apply: dlim_ub. + move => *. + apply le_dlim => ??. + by apply: hmono1. Qed. -Definition applyk (k:nat) : (nat -> {distr T / R}) := (fun n => f n k). - -Lemma isnd_applyk k: - forall x, nondecreasing_seq (fun n => (applyk k n x)%:E). -Proof. -apply: mono_nondecressing => n m hnm x. -by apply: hmono1. -Qed. - -HB.instance Definition _ k := - @isNDistribution.Build R T (applyk k) (isnd_applyk k). - -Definition dlim_applyk : (nat -> {distr T / R}) := (fun n => dlim (applyk n)). - -Lemma isnd_dlim_applyk: - forall x, nondecreasing_seq (fun n => (dlim_applyk n x)%:E). -Proof. -apply: mono_nondecressing => n m hnm x. -apply le_dlim => ??. -by apply: hmono2. -Qed. - -HB.instance Definition _ := - @isNDistribution.Build R T dlim_applyk isnd_dlim_applyk. - Lemma leub_dlim_dlim2 : - dlim dlim_applyk <=1 dlim apply2. + \dlim_(m) (\dlim_(n) (f n m)) <=1 \dlim_(n) (f n n). Proof. apply: leub_dlim => n. apply: leub_dlim => m x. -apply: (@le_trans _ _ (apply2 (maxn n m) x)); last exact: dlim_ub. -apply: (@le_trans _ _ (f (maxn n m) n x)). -- apply: hmono1; exact: leq_maxr. -- apply: hmono2; exact: leq_maxl. +apply: (@le_trans _ _ (f (maxn n m) (maxn n m) x)). + apply: (@le_trans _ _ (f (maxn n m) n x)). + - apply: hmono1; exact: leq_maxr. + - apply: hmono2; exact: leq_maxl. +apply: dlim_ub. +exact : dhomo_apply2. Qed. Lemma dlim_dlim_ub2 : - dlim apply2 <=1 dlim dlim_applyk. +\dlim_(n) (f n n) <=1 \dlim_(m) (\dlim_(n) (f n m)). Proof. apply: leub_dlim => n x. -apply: (@le_trans _ _ (dlim (applyk n) x)). -- exact: (dlim_ub (applyk n) n). -- exact: (dlim_ub dlim_applyk n). +apply: (@le_trans _ _ (dlim (fun k => f k n) x)). +- apply: dlim_ub. + by move=> *; apply: hmono1. +- apply: dlim_ub. + move=> * ;apply le_dlim => ??. + by apply: hmono2. Qed. Lemma dlim_dlim_com : - dlim dlim_apply =1 dlim dlim_applyk. +\dlim_(n) (dlim (f n)) =1 \dlim_(m) (\dlim_(n) (f n m)). Proof. move=> x; apply/eqP; rewrite eq_le; apply/andP; split. - exact: (le_trans (leub_dlim_dlim1 x) (dlim_dlim_ub2 x)). @@ -1110,51 +1023,43 @@ End DLimDLim. Section dlet_dlim_diag. Context (R : realType) (T U: choiceType). -Context (d : {ndistr T / R}) (h : nat -> T -> {distr U / R}). +Context (d : nat -> {distr T / R}) (h : nat -> T -> {distr U / R}). +Context (hd : homo d). Context (hmono: (forall k n1 n2, (n1 <= n2)%N -> h n1 k <=1 h n2 k)). -Definition nmu_dlet (nmu : {ndistr T / R}): (nat -> {distr U / R}) := - fun n => dlet (h n) (nmu n). - -Lemma isnd_nmu_dlet (nmu : {ndistr T / R}) : - forall x, nondecreasing_seq (fun n => (nmu_dlet nmu n x)%:E). +Lemma dhomo_nmu_dlet (nmu : nat -> {distr T / R}) : + homo nmu -> homo (fun n => dlet (h n) (nmu n)). Proof. -apply: mono_nondecressing => n m hnm x. -rewrite /= /nmu_dlet. +move=> hnmu n m hnm x. apply: le_dlet. -+ move => ?. - by apply: nmu_decrease. ++ by move => ?; apply: hnmu. move => ???; exact: hmono. Qed. -HB.instance Definition _ nmu := - @isNDistribution.Build R U (nmu_dlet nmu) (isnd_nmu_dlet nmu). - -Let hreduce := (reduce h). - -HB.instance Definition _ y := - @isNDistribution.Build R U (hreduce y) (isnd_reduce hmono y). - -Lemma key : forall n, dlet (fun x => dlim (hreduce x)) (d n) <=1 dlim (nmu_dlet d). +Lemma dlet_dlim_diag_n : + forall n, \dlet_(x <- d n) (\dlim_(n) (h n x)) <=1 \dlim_(n) (dlet (h n) (d n)). Proof. -move=> n u; rewrite -dlim_let. -apply: leub_dlim => m w; rewrite /mu_dlet. -apply: (@le_trans _ _ (nmu_dlet d (maxn m n) w)); last exact: dlim_ub. -rewrite /nmu_dlet; apply: le_dlet. -+ move=> x; rewrite -lee_fin; apply: (nd_f d x). - exact: leq_maxr. +move=> n u; rewrite -(dlim_let hmono). +apply: leub_dlim => m w. +apply: (@le_trans _ _ ((\dlet_(i <- d (maxn m n)) h (maxn m n) i) w)); + last exact: (@dlim_ub _ _ (fun n => dlet (h n) (d n)) (maxn m n) (dhomo_nmu_dlet hd)). +apply: le_dlet. ++ move=> x; apply: hd; exact: leq_maxr. by move=> ? _; apply: hmono; exact: leq_maxl. Qed. Lemma dlet_dlim_diag : - dlet (fun x => dlim (hreduce x)) (dlim d) =1 dlim (nmu_dlet d). + \dlet_(x <- dlim d) (\dlim_(n) (h n x)) =1 \dlim_(n) (dlet (h n) (d n)). Proof. +have hnd := dhomo_dnd hd. move=> z; apply/eqP; rewrite eq_le; apply/andP; split. -- rewrite dlet_lim; apply: leub_dlim => n. - rewrite /ndlet; exact: key. -- apply: leub_dlim => n; rewrite /nmu_dlet; apply: le_dlet. - + exact: dlim_ub. - by move=> x _; exact: (dlim_ub (hreduce x) n). +- rewrite dlet_lim//; apply: leub_dlim => n. + exact: dlet_dlim_diag_n. +- apply: leub_dlim => n; apply: le_dlet. + + exact: (@dlim_ub _ _ d n hd). +move=> x _. +apply: dlim_ub. +by move=> *; exact: hmono. Qed. End dlet_dlim_diag. @@ -1287,7 +1192,8 @@ rewrite -(reindex_esum [set:U] [set z : T * U | z.1 = x] - by move=> y1 y2 _ _ /(congr1 snd). - move=> z /= zx; exists z.2 => //=. by case: z zx => z1 z2 /= ->. -by apply: subset_esum. +apply: subset_esum => //=. +by move=> z _; rewrite lee_tofin // mulr_ge0. Qed. End DFst. @@ -2023,7 +1929,9 @@ Section mono_esum. Context {R : realType} {T : choiceType} - {f : {ndistr T/ R}}. + {f : nat -> {distr T / R}}. + +Hypothesis ndf : nd f. Lemma mono_esum_Efn (E: T -> \bar R): (forall m, 0 <= E m)%E -> @@ -2035,12 +1943,12 @@ move=> hE m n le_mn. apply /esum.le_esum. move => ??; rewrite lee_pmul => //=. - rewrite lee_tofin //. -- rewrite lee_tofin //; exact: nmu_decrease. +- rewrite lee_tofin //; exact: ndf. Qed. Lemma distr_lub_sup a : ((dlim f) a)%:E = ereal_sup (range (fun n => (f n a)%:E)). -Proof. by rewrite dlim_EFin (sup_range_lim (nd_f f a)). Qed. +Proof. exact: (dlim_sup ndf a). Qed. Lemma esum_dlim_r [E : T -> \bar R] [r : \bar R]: (forall m, 0 <= E m)%E -> @@ -2054,7 +1962,7 @@ rewrite (@esum.eq_esum _ _ _ _ (fun x => ereal_sup (range (fun n => E x * (f n move => ??; rewrite lee_tofin //. rewrite exchange_esum_ereal_sup //. - by move => ??; rewrite mule_ge0 // lee_tofin. -- by move => ????; rewrite lee_pmul // ?lee_tofin // ; exact: nmu_decrease. +- by move => ????; rewrite lee_pmul // ?lee_tofin // ; exact: ndf. rewrite ge_ereal_sup//= => x [n s] <-. exact: h. Qed. @@ -2080,7 +1988,7 @@ Proof. have hmono : forall n m, (n <= m)%N -> forall x, (((E x)%:R * f n x)%:E <= ((E x)%:R * f m x)%:E)%E. move=> n m nm x; rewrite lee_fin; apply: ler_wpM2l; first exact: ler0n. - by rewrite -lee_fin; exact: (nd_f f x nm). + by rewrite -lee_fin; exact: (ndf x nm). transitivity (ereal_sup (range (fun n => esum [set:T] (fun x : T => ((E x)%:R * f n x)%:E)))); last first. by apply: sup_range_lim => n m nm; apply: le_esum => x _; exact: (hmono n m nm x). @@ -2090,6 +1998,7 @@ rewrite -(@exchange_esum_ereal_sup R T (fun x n => ((E x)%:R * f n x)%:E)) //. apply: eq_esum => x _. rewrite EFinM distr_lub_sup (@ge0_ereal_supZl_range R T (fun a b => (f b a)%:E)) //. + by move=> t n; rewrite lee_fin; exact: ge0_mu. ++ by rewrite lee_tofin. Qed. End mono_esum. From ba42c154e87e22722512b3f9d978bef036c511fb Mon Sep 17 00:00:00 2001 From: Lionel Blatter Date: Wed, 23 Sep 2026 15:18:06 +0200 Subject: [PATCH 04/18] Some refactoring --- theories/probability_theory/counting_distr.v | 149 ++++++------------- 1 file changed, 49 insertions(+), 100 deletions(-) diff --git a/theories/probability_theory/counting_distr.v b/theories/probability_theory/counting_distr.v index 9c431cc515..c7d739dd34 100644 --- a/theories/probability_theory/counting_distr.v +++ b/theories/probability_theory/counting_distr.v @@ -4,10 +4,18 @@ From mathcomp.classical Require Import boolp classical_sets mathcomp_compat. From mathcomp Require Import xfinmap constructive_ereal reals discrete. From mathcomp Require Import esum ereal. From mathcomp Require Import cardinality fsbigop topology normedtype sequences. +From mathcomp Require Import unstable. (* Should be removed *) From mathcomp Require Import numfun. +(**md**************************************************************************) +(* # SubDistribution *) +(* *) +(* ``` *) +(* ``` *) +(******************************************************************************) + Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. @@ -47,17 +55,17 @@ Local Notation "\`| f |" := (fun x => `|f x|) (at level 2). (* -------------------------------------------------------------------- *) -HB.mixin Record isDistribution (R : realType) (T : choiceType) (mu : T -> R) := +HB.mixin Record isSubDistribution (R : realType) (T : choiceType) (mu : T -> R) := { mu_positive : forall x, 0 <= mu x ; mu_summable : esummable [set: T] (EFin \o mu); mu_sum_le_one : (esum [set: T] (EFin \o mu) <= 1)%E; }. -HB.structure Definition Distribution (R : realType) (T : choiceType) := - {f of @isDistribution R T f}. +HB.structure Definition SubDistribution (R : realType) (T : choiceType) := + {f of @isSubDistribution R T f}. -Notation "{ 'distr' T / R }" := (@Distribution.type R T) +Notation "{ 'distr' T / R }" := (@SubDistribution.type R T) (at level 0, T at level 2, format "{ 'distr' T / R }") : type_scope. @@ -78,34 +86,6 @@ End DistrCoreTh. #[global] Hint Extern 0 (is_true (0 <= _)) => solve [apply: ge0_mu] : core. #[global] Hint Resolve le1_mu summable_mu : core. -(* -------------------------------------------------------------------- *) -Section Clamp. -Context {R : realType}. - -Definition clamp (x : R) := - Num.max (Num.min x 1) 0. - -Lemma ge0_clamp x : 0 <= clamp x. -Proof. by rewrite le_max lexx orbT. Qed. - -Lemma le1_clamp x : clamp x <= 1. -Proof. by rewrite ge_max ge_min lexx ler01 orbT. Qed. - -Definition cp01_clamp := (ge0_clamp, le1_clamp). - -Lemma clamp_in01 x : 0 <= x <= 1 -> clamp x = x. -Proof. by case/andP=> ge0_x le1_x; rewrite /clamp min_l ?max_l. Qed. - -Lemma clamp_id x : clamp (clamp x) = clamp x. -Proof. by rewrite clamp_in01 // !cp01_clamp. Qed. - -Lemma clamp0 : clamp 0 = 0. -Proof. by rewrite clamp_in01 // lexx ler01. Qed. - -Lemma clamp1 : clamp 1 = 1. -Proof. by rewrite clamp_in01 // lexx ler01. Qed. -End Clamp. - (* -------------------------------------------------------------------- *) Section StdDefs. Context {R : realType} (T : choiceType). @@ -140,13 +120,14 @@ Notation "\E?_[ mu ] f" := (has_esp mu f). Notation dweight mu := (\P_[mu] predT). (* -------------------------------------------------------------------- *) -Section DistrTheory. -Context {R : realType} {T : choiceType} (mu : T -> R). - -Definition isdistr := - (forall x, 0 <= mu x) /\ (forall J, uniq J -> \sum_(j <- J) mu j <= 1). +HB.factory Record isSubDistr {R : realType} {T : choiceType} (mu : T -> R) := { + distr_pos: (forall x, 0 <= mu x); + distr_lee_one: (forall J, uniq J -> \sum_(j <- J) mu j <= 1) + }. -Hypothesis isd : isdistr. +HB.builders + Context {R : realType} {T : choiceType} (mu : T -> R) + (isd : @isSubDistr R T mu). Local Lemma isd1 : forall x, 0 <= mu x. Proof. by case: isd. Qed. @@ -174,15 +155,15 @@ rewrite fsumEFin // lee_fin fsbig_finite //=. by apply: h2. Qed. -Definition mkdistrd := @isDistribution.Build R T mu isd1 isd2 isd3. +HB.instance Definition _ := @isSubDistribution.Build R T mu isd1 isd2 isd3. -Definition ispredistr {T : choiceType} (mu : T -> R) := - [/\ forall x, 0 <= mu x & esummable [set: T] (EFin \o mu)]. +HB.end. -End DistrTheory. +Definition sub_distr {R : realType} {T : choiceType} (mu : T -> R) := + (forall x, 0 <= mu x) /\ (forall J, uniq J -> \sum_(j <- J) mu j <= 1). Lemma isdistr_finP {R : realType} {I : finType} (mu : I -> R) : - (isdistr mu) <-> (forall x, 0 <= mu x) /\ (\sum_j mu j <= 1). + (sub_distr mu) <-> (forall x, 0 <= mu x) /\ (\sum_j mu j <= 1). Proof. split=> -[ ge0_mu le1]; split=> //. + by apply/le1; rewrite /index_enum -enumT enum_uniq. @@ -207,10 +188,11 @@ Context {R : realType} {T : choiceType}. Definition dnull_fun := fun x : T => (0 : R). -Lemma isd_mnull : isdistr dnull_fun. +Lemma isd_mnull : sub_distr dnull_fun. Proof. by split=> // J _; rewrite big1 ?ler01. Qed. -HB.instance Definition _ := @mkdistrd R T dnull_fun isd_mnull. +HB.instance Definition _ := + @isSubDistr.Build R T dnull_fun (proj1 isd_mnull) (proj2 isd_mnull). Definition dnull := @locked {distr T / R} dnull_fun. @@ -231,7 +213,7 @@ Context (R : realType) (T : choiceType) (p : pred T). Definition drestr_fun (mu : {distr T / R}) := fun x => if p x then mu x else 0. -Lemma isd_drestr (mu : {distr T / R}) : isdistr (drestr_fun mu). +Lemma isd_drestr (mu : {distr T / R}) : sub_distr (drestr_fun mu). Proof. split=> [x|J]; first by rewrite /drestr_fun; case: ifP. move=> eqJ; apply/(@le_trans _ _ (\sum_(j <- J) `|mu j|)). @@ -246,7 +228,7 @@ move=> eqJ; apply/(@le_trans _ _ (\sum_(j <- J) `|mu j|)). Qed. HB.instance Definition _ (mu : {distr T / R}) := - @mkdistrd R T (drestr_fun mu) (isd_drestr mu). + @isSubDistr.Build R T (drestr_fun mu) (proj1 (isd_drestr mu)) (proj2 (isd_drestr mu)). Definition drestr (mu : {distr T / R}) := @locked {distr T / R} (drestr_fun mu). @@ -286,7 +268,7 @@ Definition drat_fun (s : seq T) : T -> R := Lemma ge0_drat s : forall x, 0 <= drat_fun s x. Proof. by move=> x; rewrite mulr_ge0 ?invr_ge0 // ler0n. Qed. -Local Lemma has_sup_drat s J : uniq J -> \sum_(i <- J) drat_fun s i <= 1. +Lemma has_sup_drat s J : uniq J -> \sum_(i <- J) drat_fun s i <= 1. Proof. move=> uqJ; rewrite -mulr_suml /= -natr_sum; case: (size s =P 0%N). by move=> ->; rewrite invr0 mulr0 ler01. @@ -303,7 +285,7 @@ apply/uniq_perm; rewrite ?filter_uniq ?undup_uniq //. by move=> x; rewrite !mem_filter mem_undup andbC. Qed. -Local Lemma drat_sup s : (0 < size s)%N -> +Lemma drat_sup s : (0 < size s)%N -> \sum_(i <- undup s) drat_fun s i = 1. Proof. move=> gt0_s; rewrite -mulr_suml -natr_sum. @@ -313,7 +295,7 @@ rewrite -sum1_size -[in RHS]big_undup_iterop_count/=; apply: eq_bigr => i _. by rewrite Monoid.iteropE iter_addn addn0 mul1n. Qed. -Local Lemma summable_drat s: esummable [set :T] (EFin \o (drat_fun s)). +Lemma summable_drat s: esummable [set :T] (EFin \o (drat_fun s)). Proof. rewrite /esummable (@le_lt_trans _ _ 1%:E) ?ltey//. rewrite ge0_esum. @@ -325,11 +307,11 @@ rewrite (eq_bigr (drat_fun s)). by apply/has_sup_drat. Qed. -Lemma isd_drat s : isdistr (drat_fun s). +Lemma isd_drat s : sub_distr (drat_fun s). Proof. by split; [apply/ge0_drat | apply/has_sup_drat]. Qed. HB.instance Definition _ (s : seq T) := - @mkdistrd R T (drat_fun s) (isd_drat s). + @isSubDistr.Build R T (drat_fun s) (proj1 (isd_drat s)) (proj2 (isd_drat s)). Definition drat (s : seq T) := @locked {distr T / R} (drat_fun s). @@ -364,17 +346,19 @@ End DRat. Section Flip. Context {R : realType}. +Local Notation clamp := (@clamp R 0 1). + Definition dflip_fun (xt : R) := fun b => if b then clamp xt else 1 - clamp xt. -Lemma isd_dflip xt : isdistr (dflip_fun xt). +Lemma isd_dflip xt : sub_distr (dflip_fun xt). Proof. apply/isdistr_finP; split=> [b|]. -+ by case: b; rewrite ?subr_ge0 cp01_clamp. ++ by case: b; rewrite ?subr_ge0 clamp_gele. + by rewrite /index_enum !unlock /= addr0 addrC subrK. Qed. HB.instance Definition _ (xt : R) := - @mkdistrd R _ (dflip_fun xt) (isd_dflip xt). + @isSubDistr.Build R _ (dflip_fun xt) (proj1 (isd_dflip xt)) (proj2 (isd_dflip xt)). Definition dflip (xt : R) := @locked {distr bool / R} (dflip_fun xt). @@ -397,7 +381,7 @@ rewrite -lee_fin -{}h esum_ge0 // => ??. by rewrite EFinM mule_ge0 //= lee_tofin. Qed. -Lemma isd_dlet : isdistr dlet_fun. +Lemma isd_dlet : sub_distr dlet_fun. Proof. split=> [x|J uqJ]. + exact: dlet_pos. @@ -418,7 +402,7 @@ split=> [x|J uqJ]. by have := (summable_mu (f i)); rewrite esummableE. Qed. -HB.instance Definition _ := @mkdistrd R U dlet_fun isd_dlet. +HB.instance Definition _ := @isSubDistr.Build R U dlet_fun (proj1 isd_dlet) (proj2 isd_dlet). Definition dlet := @locked {distr U / R} dlet_fun. @@ -661,42 +645,6 @@ Proof. by move=> ndu; apply/esym/cvg_lim => //; exact: ereal_nondecreasing_cvgn. Qed. -(* -------------------------------------------------------------------- *) -(* Generic facts about [einfs] / [limn_einf] missing from sequences.v, *) -(* used below to make [dlim] total on sequences of subdistributions. *) -Lemma einfs_le {R : realType} (u : (\bar R)^nat) n m : - (n <= m)%N -> (einfs u n <= u m)%E. -Proof. by move=> nm; apply: ereal_inf_lbound; exists m; [exact: nm | by []]. Qed. - -Lemma einfs_lift {R : realType} (u : (\bar R)^nat) p n : - einfs (fun k => u (k + p)%N) n = einfs u (n + p)%N. -Proof. -congr (ereal_inf _); apply/seteqP; split => _ /= [k /= nk] <-. -- by exists (k + p)%N => //=; rewrite leq_add2r. -- have pk : (p <= k)%N by apply: leq_trans nk; exact: leq_addl. - exists (k - p)%N => /=; last by rewrite subnK. - by rewrite -(leq_add2r p) subnK. -Qed. - -Lemma limn_einf_lift {R : realType} (u : (\bar R)^nat) p : - limn_einf (fun n => u (n + p)%N) = limn_einf u. -Proof. -rewrite !limn_einf_lim. -have -> : einfs (fun k => u (k + p)%N) = (fun n => einfs u (n + p)%N). - by apply/funext => n; exact: einfs_lift. -by apply/cvg_lim => //; rewrite (cvg_shiftn p (einfs u)); exact: is_cvg_einfs. -Qed. - -Lemma limn_einf_bump {R : realType} (u : (\bar R)^nat) : - limn_einf (fun n => u n.+1) = limn_einf u. -Proof. -rewrite -(limn_einf_lift u 1); congr limn_einf. -by apply/funext => n; rewrite addn1. -Qed. - -Lemma limn_einf_cst {R : realType} (c : \bar R) : limn_einf (fun=> c) = c. -Proof. by rewrite is_cvg_limn_einfE ?lim_cst//; exact: is_cvg_cst. Qed. - (* -------------------------------------------------------------------- *) Section dlim. Context {R : realType} (T : choiceType). @@ -718,7 +666,7 @@ Qed. Lemma le1_liminf f x : (limn_einf (fun n => (f n x)%:E) <= 1%:E)%E. Proof. rewrite limn_einf_lim; apply: lime_le; first exact: is_cvg_einfs. -apply: nearW => n; apply: (@le_trans _ _ ((f n x)%:E)); first exact: einfs_le. +apply: nearW => n; apply: (@le_trans _ _ ((f n x)%:E)); first exact: ge_einfs. by rewrite lee_fin le1_mu1. Qed. @@ -749,7 +697,7 @@ move=> ndu fu; elim => [|a L IH]. by apply: lee_sum => j _; exact: ndu. Qed. -Lemma isd_dlim f : isdistr (dlim_fun f). +Lemma isd_dlim f : sub_distr (dlim_fun f). Proof. split=> [x|J uqJ]. by rewrite /dlim_fun; apply: fine_ge0; exact: ge0_liminf. @@ -763,13 +711,14 @@ rewrite (sumlim ndE finE); apply: lime_le. apply: ereal_nondecreasing_is_cvgn => n m nm. by apply: lee_sum => j _; exact: ndE. apply: nearW => n; apply: (@le_trans _ _ (\sum_(j <- J) (f n j)%:E)). - by apply: lee_sum => j _; exact: einfs_le. + by apply: lee_sum => j _; exact: ge_einfs. rewrite sumEFin. apply: (@le_trans _ _ (esum [set: T] (EFin \o f n))); last exact: le1_mu. exact: sum_esum_ge. Qed. -HB.instance Definition _ f := @mkdistrd R T (dlim_fun f) (isd_dlim f). +HB.instance Definition _ f := @isSubDistr.Build R T (dlim_fun f) + (proj1 (isd_dlim f)) (proj2 (isd_dlim f)). Definition dlim f := @locked {distr T / R} (dlim_fun f). @@ -824,10 +773,10 @@ by move=> x; rewrite dlimE limn_einf_cst. Qed. Lemma dlim_bump f : \dlim_(n) f n.+1 =1 dlim f. -Proof. by move=> x; rewrite !dlimE (limn_einf_bump (fun n => (f n x)%:E)). Qed. +Proof. by move=> x; rewrite !dlimE (limn_einf_shiftS (fun n => (f n x)%:E)). Qed. Lemma dlim_lift f p : \dlim_(n) f (n + p)%N =1 dlim f. -Proof. by move=> x; rewrite !dlimE (limn_einf_lift (fun n => (f n x)%:E) p). Qed. +Proof. by move=> x; rewrite !dlimE (limn_einf_shift_new (fun n => (f n x)%:E) p). Qed. Lemma ge0_dlim f : forall x, 0 <= dlim f x. Proof. exact: mu_positive. Qed. @@ -841,7 +790,7 @@ Proof. move=> le x; rewrite -lee_fin !dlim_EFin !limn_einf_lim. apply: lee_lim; [exact: is_cvg_einfs | exact: is_cvg_einfs |]. apply: nearW => n; apply: le_ereal_inf_tmp => _ [m /= nm] <-. -apply: (@le_trans _ _ ((f m x)%:E)); first exact: einfs_le. +apply: (@le_trans _ _ ((f m x)%:E)); first exact: ge_einfs. by rewrite lee_fin; exact: le. Qed. From ecbbf2d4bf0d505da70ed7c42b71400d94636d07 Mon Sep 17 00:00:00 2001 From: Lionel Blatter Date: Thu, 1 Oct 2026 14:03:41 +0200 Subject: [PATCH 05/18] Add some documentations --- theories/probability_theory/counting_distr.v | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/theories/probability_theory/counting_distr.v b/theories/probability_theory/counting_distr.v index c7d739dd34..b26f2db490 100644 --- a/theories/probability_theory/counting_distr.v +++ b/theories/probability_theory/counting_distr.v @@ -10,9 +10,17 @@ From mathcomp Require Import unstable. From mathcomp Require Import numfun. (**md**************************************************************************) -(* # SubDistribution *) +(* # SubDistribution *) (* *) (* ``` *) +(* SubDistribution T R == subdistribution for choicetype T with values *) +(* in R *) +(* isSubDistr == interface for functions that satisfy the *) +(* property of SubDistribution. *) +(* dnull == the zero distribution (null distribution) *) +(* dunit == degenerate distribution *) +(* dlet == monadic bind for distribution *) +(* dlim == limite for index distribution *) (* ``` *) (******************************************************************************) From b9dceb6e4f042aec566e5ba7620ba565d549f761 Mon Sep 17 00:00:00 2001 From: Lionel Blatter Date: Mon, 5 Oct 2026 17:27:24 +0200 Subject: [PATCH 06/18] Some refactoring --- theories/probability_theory/counting_distr.v | 244 +++++++++---------- 1 file changed, 115 insertions(+), 129 deletions(-) diff --git a/theories/probability_theory/counting_distr.v b/theories/probability_theory/counting_distr.v index b26f2db490..70433c20cf 100644 --- a/theories/probability_theory/counting_distr.v +++ b/theories/probability_theory/counting_distr.v @@ -65,44 +65,30 @@ Local Notation "\`| f |" := (fun x => `|f x|) (at level 2). HB.mixin Record isSubDistribution (R : realType) (T : choiceType) (mu : T -> R) := { - mu_positive : forall x, 0 <= mu x ; + mu_ge0 : forall x, 0 <= mu x ; mu_summable : esummable [set: T] (EFin \o mu); - mu_sum_le_one : (esum [set: T] (EFin \o mu) <= 1)%E; + mu_sum_le1 : (esum [set: T] (EFin \o mu) <= 1)%E; }. HB.structure Definition SubDistribution (R : realType) (T : choiceType) := {f of @isSubDistribution R T f}. -Notation "{ 'distr' T / R }" := (@SubDistribution.type R T) - (at level 0, T at level 2, format "{ 'distr' T / R }") +Notation "R .-distr T" := (@SubDistribution.type R T) + (at level 0, T at level 2, format "R .-distr T ") : type_scope. -(* -------------------------------------------------------------------- *) -Section DistrCoreTh. -Context {R : realType} (T : choiceType) (mu : {distr T / R}). - -Lemma ge0_mu : forall x, 0 <= mu x. -Proof. exact: mu_positive. Qed. - -Lemma le1_mu : (esum [set: T] (EFin \o mu) <= 1)%E. -Proof. exact: mu_sum_le_one. Qed. - -Lemma summable_mu : esummable [set: T] (EFin \o mu). -Proof. exact: mu_summable. Qed. -End DistrCoreTh. - -#[global] Hint Extern 0 (is_true (0 <= _)) => solve [apply: ge0_mu] : core. -#[global] Hint Resolve le1_mu summable_mu : core. +#[global] Hint Extern 0 (is_true (0 <= _)) => solve [apply: mu_ge0] : core. +#[global] Hint Resolve mu_sum_le1 mu_summable : core. (* -------------------------------------------------------------------- *) Section StdDefs. Context {R : realType} (T : choiceType). -Implicit Types (mu : {distr T / R}) (A B E : pred T) (f : T -> R). +Implicit Types (mu : R.-distr T) (A B E : pred T) (f : T -> R). Definition dinsupp mu := fun x => mu x != 0 :> R. -Lemma in_dinsupp x (mu : {distr T / R}) : +Lemma in_dinsupp x (mu : R.-distr T) : (x \in dinsupp mu) = (mu x != 0). Proof. by []. Qed. @@ -180,7 +166,7 @@ split=> -[ ge0_mu le1]; split=> //. Qed. Lemma le1_mu1 - {R : realType} {T : choiceType} (mu : {distr T / R}) x : mu x <= 1. + {R : realType} {T : choiceType} (mu : R.-distr T) x : mu x <= 1. Proof. case mu => //= {}mu [[?]]. rewrite esummableE => ??. @@ -202,7 +188,7 @@ Proof. by split=> // J _; rewrite big1 ?ler01. Qed. HB.instance Definition _ := @isSubDistr.Build R T dnull_fun (proj1 isd_mnull) (proj2 isd_mnull). -Definition dnull := @locked {distr T / R} dnull_fun. +Definition dnull := @locked R.-distr T dnull_fun. Lemma dnullE x : dnull x = 0. Proof. by unlock dnull. Qed. @@ -210,37 +196,37 @@ Proof. by unlock dnull. Qed. End DistrD. (* -------------------------------------------------------------------- *) -Lemma lef_dnull {R : realType} {T : choiceType} (mu : {distr T / R}) : +Lemma lef_dnull {R : realType} {T : choiceType} (mu : R.-distr T) : dnull <=1 mu. -Proof. by move=> x; rewrite dnullE ge0_mu. Qed. +Proof. by move=> x; rewrite dnullE mu_ge0. Qed. (* -------------------------------------------------------------------- *) Section Restr. Context (R : realType) (T : choiceType) (p : pred T). -Definition drestr_fun (mu : {distr T / R}) := +Definition drestr_fun (mu : R.-distr T) := fun x => if p x then mu x else 0. -Lemma isd_drestr (mu : {distr T / R}) : sub_distr (drestr_fun mu). +Lemma isd_drestr (mu : R.-distr T) : sub_distr (drestr_fun mu). Proof. split=> [x|J]; first by rewrite /drestr_fun; case: ifP. move=> eqJ; apply/(@le_trans _ _ (\sum_(j <- J) `|mu j|)). + apply/ler_sum=> i _; rewrite /drestr_fun; case: ifPn=> _. by apply/ler_norm. by apply/normr_ge0. + rewrite -lee_fin. - apply/(le_trans _ (le1_mu mu)). + apply/(le_trans _ (@mu_sum_le1 _ _ mu)). case mu => //= {}mu [[?]]; rewrite esummableE => ? _. rewrite (@eq_esum _ _ _ _ (fun y : T => `|(EFin \o mu) y|%E)) //=. + by move => ??; rewrite ger0_norm. exact: sum_esum_ge. Qed. -HB.instance Definition _ (mu : {distr T / R}) := +HB.instance Definition _ (mu : R.-distr T) := @isSubDistr.Build R T (drestr_fun mu) (proj1 (isd_drestr mu)) (proj2 (isd_drestr mu)). -Definition drestr (mu : {distr T / R}) := @locked {distr T / R} (drestr_fun mu). +Definition drestr (mu : R.-distr T) := @locked R.-distr T (drestr_fun mu). -Lemma drestrE (mu : {distr T / R}) x : +Lemma drestrE (mu : R.-distr T) x : drestr mu x = if p x then mu x else 0. Proof. by unlock drestr. Qed. End Restr. @@ -249,11 +235,11 @@ End Restr. Section RestrTheory. Context {R : realType} {T : choiceType}. -Lemma drestrD (mu : {distr T / R}) (p : pred T) x : +Lemma drestrD (mu : R.-distr T) (p : pred T) x : mu x = drestr p mu x + drestr (predC p) mu x. Proof. by rewrite !drestrE !inE; case: ifPn; rewrite /= (addr0, add0r). Qed. -Lemma dinsupp_restr (mu : {distr T / R}) (p : pred T) x : +Lemma dinsupp_restr (mu : R.-distr T) (p : pred T) x : (x \in dinsupp (drestr p mu)) = (x \in dinsupp mu) && p x. Proof. apply/dinsuppP/idP. @@ -266,7 +252,7 @@ End RestrTheory. Section DRat. Context {R : realType} (T : choiceType). -Local Notation distr := {distr T / R}. +Local Notation distr := R.-distr T. Implicit Types (s : seq T). @@ -321,7 +307,7 @@ Proof. by split; [apply/ge0_drat | apply/has_sup_drat]. Qed. HB.instance Definition _ (s : seq T) := @isSubDistr.Build R T (drat_fun s) (proj1 (isd_drat s)) (proj2 (isd_drat s)). -Definition drat (s : seq T) := @locked {distr T / R} (drat_fun s). +Definition drat (s : seq T) := @locked R.-distr T (drat_fun s). Lemma drat1E s x : drat s x = (count_mem x s)%:R / (size s)%:R. @@ -368,7 +354,7 @@ Qed. HB.instance Definition _ (xt : R) := @isSubDistr.Build R _ (dflip_fun xt) (proj1 (isd_dflip xt)) (proj2 (isd_dflip xt)). -Definition dflip (xt : R) := @locked {distr bool / R} (dflip_fun xt). +Definition dflip (xt : R) := @locked R.-distr bool (dflip_fun xt). Lemma dflip1E xt : dflip xt =1 (fun b => if b then clamp xt else 1 - clamp xt). Proof. by unlock dflip. Qed. @@ -377,7 +363,7 @@ End Flip. (* -------------------------------------------------------------------- *) Section Bind. Context {R : realType} {T U : choiceType} - (f : T -> {distr U / R}) (mu : {distr T /R}). + (f : T -> R.-distr U) (mu : R.-distr T). Definition dlet_fun := fun y : U => fine (esum [set:T] (fun x => EFin (mu x * f x y))). @@ -399,20 +385,20 @@ split=> [x|J uqJ]. apply /le_trans. + apply sum_esum_ge => // x. exact: dlet_pos. - apply/(le_trans _ (le1_mu mu)). + apply/(le_trans _ (@mu_sum_le1 _ _ mu)). apply/(le_trans (le_esum_fine _ _ hpos)). rewrite exchange_esum // le_esum // => i ?. under eq_esum do rewrite EFinM. rewrite esumZ // ?lee_tofin // => [? |]; rewrite ?lee_tofin //=. - rewrite muleC gee_pMl // ?lee_tofin //;last first. exact : (le1_mu (f i)). + rewrite muleC gee_pMl // ?lee_tofin //;last first. exact : (@mu_sum_le1 _ _ (f i)). rewrite (eq_esum _ _ (fun x => `|(EFin \o f i) x|%E)) //. + by move => ??; rewrite gee0_abs //= lee_tofin. - by have := (summable_mu (f i)); rewrite esummableE. + by have := (@mu_summable _ _ (f i)); rewrite esummableE. Qed. HB.instance Definition _ := @isSubDistr.Build R U dlet_fun (proj1 isd_dlet) (proj2 isd_dlet). -Definition dlet := @locked {distr U / R} dlet_fun. +Definition dlet := @locked R.-distr U dlet_fun. Lemma dletE y : dlet y = fine (esum [set:T] (fun x => EFin (mu x * f x y))). Proof. by unlock dlet. Qed. @@ -420,10 +406,10 @@ End Bind. Notation "\dlet_ ( i <- d ) E" := (dlet (fun i => E) d). -Definition dlift {R : realType} {T : choiceType} (f : T -> {distr T / R}) := +Definition dlift {R : realType} {T : choiceType} (f : T -> R.-distr T) := fun d => \dlet_(x <- d) f x. -Definition diter {R : realType} {T : choiceType} n (f : T -> {distr T / R}) := +Definition diter {R : realType} {T : choiceType} n (f : T -> R.-distr T) := fun a => (iter n (dlift f) (dunit a)). (* -------------------------------------------------------------------- *) @@ -434,7 +420,7 @@ Lemma esum_abse {R : realType} {T : choiceType} Proof. by move => ?; apply eq_esum => ?? ; rewrite gee0_abs // lee_tofin. Qed. Lemma summable_mu_wgtd {R : realType} {T : choiceType} - (f : T -> R) (mu : {distr T / R}) : + (f : T -> R) (mu : R.-distr T) : (forall x, 0 <= f x <= 1) -> esummable [set: T] (fun x => EFin (mu x * f x)). Proof. rewrite /esummable => h. @@ -442,14 +428,14 @@ under eq_esum do rewrite EFinM. apply: esummableMr => //. + exists 1%E => // => i. case /andP: (h i) => ?? ; rewrite lee_tofin // ger0_norm //. -exact : (summable_mu mu). +exact : (@mu_summable _ _ mu). Qed. (* -------------------------------------------------------------------- *) Section BindTheory. Variables (R : realType) (T U : choiceType). -Implicit Types (f g : T -> {distr U / R}) (mu nu : {distr T / R}). +Implicit Types (f g : T -> R.-distr U) (mu nu : R.-distr T). Lemma dlet_null f : dlet f dnull =1 dnull. Proof. @@ -494,11 +480,11 @@ case /boolP: (x \in dinsupp mu) => [/eq_f ->//|]. by move/dinsuppPn => ->; rewrite !mul0e. Qed. -Lemma summable_dlet (f : T -> {distr U / R}) (mu : {distr T / R}) y : +Lemma summable_dlet (f : T -> R.-distr U) (mu : R.-distr T) y : esummable [set: T] (fun x : T => EFin (mu x * (f x) y)). -Proof. by apply/summable_mu_wgtd=> x; rewrite ge0_mu le1_mu1. Qed. +Proof. by apply/summable_mu_wgtd=> x; rewrite mu_ge0 le1_mu1. Qed. -Lemma fin_esum (f : T -> {distr U / R}) (mu : {distr T / R}) y: +Lemma fin_esum (f : T -> R.-distr U) (mu : R.-distr T) y: \esum_(x' in [set: T]) (mu x' * f x' y)%:E \is a fin_num. Proof. rewrite esum_abse. @@ -506,7 +492,7 @@ rewrite esum_abse. by have := (summable_dlet f mu y); rewrite esummableE. Qed. -Lemma dlet_EFin (f : T -> {distr U / R}) (mu : {distr T / R}) y : +Lemma dlet_EFin (f : T -> R.-distr U) (mu : R.-distr T) y : (dlet f mu y)%:E = esum [set:T] (fun x => (mu x * f x y)%:E). Proof. by rewrite dletE fineK// ?fin_esum. Qed. @@ -536,7 +522,7 @@ move=> le_mu le_fg x. by apply/(le_trans (le_in_dlet le_fg _))/le_mu_dlet. Qed. -Lemma dletC (mu : {distr T / R}) (nu : {distr U / R}) y : +Lemma dletC (mu : R.-distr T) (nu : R.-distr U) y : (\dlet_(_ <- mu) nu) y = (dweight mu) * (nu y). Proof. rewrite dletE /pr //=. @@ -545,7 +531,7 @@ rewrite esumZ ?lee_tofin //= => [?| ]; rewrite ?lee_tofin //. rewrite fineM => //=;last first. + rewrite mulrC. symmetry. by under eq_esum do rewrite mul1r. -by rewrite esum_abse //; have := (summable_mu mu); rewrite esummableE. +by rewrite esum_abse //; have := (@mu_summable _ _ mu); rewrite esummableE. Qed. Lemma dinsupp_dlet f mu y : @@ -559,7 +545,7 @@ rewrite eqe mulf_eq0 negb_or => /andP[nz_mu nz_f]. by exists x; rewrite ?in_dinsupp. Qed. -Lemma fine_esum0 (f : T -> {distr U / R}) (mu : {distr T / R}) x y: +Lemma fine_esum0 (f : T -> R.-distr U) (mu : R.-distr T) x y: fine (\esum_(x in [set: T]) (mu x * f x y)%:E) = 0 -> ((mu x * f x y)%:E = 0). Proof. @@ -590,7 +576,7 @@ have -> : \esum_(x in [set: T]) (mu x * dunit (f x) y)%:E = 0. by []. Qed. -Lemma eq0_dlet (mu : {distr T / R}) (F : T -> {distr U / R}) y : +Lemma eq0_dlet (mu : R.-distr T) (F : T -> R.-distr U ) y : (\dlet_(x <- mu) F x) y = 0 -> forall x, x \in dinsupp mu -> F x y = 0. Proof. rewrite dletE => /fine_esum0 => h x. @@ -603,9 +589,9 @@ End BindTheory. (* -------------------------------------------------------------------- *) Section DLetDLet. Context {R:realType} {T U V : choiceType} - (f1 : T -> {distr U / R}) (f2 : U -> {distr V / R}). + (f1 : T -> R.-distr U) (f2 : U -> R.-distr V). -Lemma dlet_dlet (mu : {distr T / R}) : +Lemma dlet_dlet (mu : R.-distr T) : \dlet_(x <- \dlet_(y <- mu) f1 y) f2 x =1 \dlet_(y <- mu) (\dlet_(x <- f1 y) f2 x). Proof. @@ -627,9 +613,9 @@ End DLetDLet. (* -------------------------------------------------------------------- *) Section DLetAlg. -Context {R : realType} {T U : choiceType} (mu mu1 mu2 : {distr T / R}). +Context {R : realType} {T U : choiceType} (mu mu1 mu2 : R.-distr T). -Lemma dlet_additive (f : T -> {distr U / R}) z : +Lemma dlet_additive (f : T -> R.-distr U) z : (forall x, mu x = mu1 x + mu2 x) -> (\dlet_(x <- mu) f x) z = (\dlet_(x <- mu1) f x) z + (\dlet_(x <- mu2) f x) z. Proof. @@ -657,7 +643,7 @@ Qed. Section dlim. Context {R : realType} (T : choiceType). -Implicit Types (f g : nat -> {distr T / R}). +Implicit Types (f g : nat -> R.-distr T). Import numFieldNormedType.Exports. @@ -721,14 +707,14 @@ rewrite (sumlim ndE finE); apply: lime_le. apply: nearW => n; apply: (@le_trans _ _ (\sum_(j <- J) (f n j)%:E)). by apply: lee_sum => j _; exact: ge_einfs. rewrite sumEFin. -apply: (@le_trans _ _ (esum [set: T] (EFin \o f n))); last exact: le1_mu. +apply: (@le_trans _ _ (esum [set: T] (EFin \o f n))); last exact: mu_sum_le1. exact: sum_esum_ge. Qed. HB.instance Definition _ f := @isSubDistr.Build R T (dlim_fun f) (proj1 (isd_dlim f)) (proj2 (isd_dlim f)). -Definition dlim f := @locked {distr T / R} (dlim_fun f). +Definition dlim f := @locked R.-distr T (dlim_fun f). Lemma dlimE f x : dlim f x = fine (limn_einf (fun n => (f n x)%:E)). Proof. by unlock dlim. Qed. @@ -736,10 +722,10 @@ Proof. by unlock dlim. Qed. Lemma dlim_EFin f x : (dlim f x)%:E = limn_einf (fun n => (f n x)%:E). Proof. by unlock dlim; exact: dlim_fun_EFin. Qed. -Definition homo (f : nat -> {distr T / R}) := +Definition homo (f : nat -> R.-distr T) := forall n m, (n <= m)%N -> f n <=1 f m. -Definition nd (f : nat -> {distr T / R}) := +Definition nd (f : nat -> R.-distr T) := forall x, nondecreasing_seq (fun n => (f n x)%:E). Lemma dhomo_dnd f : homo f -> nd f. @@ -772,8 +758,8 @@ Notation "\dlim_ ( n ) E" := (dlim (fun n => E)). Section DLimTheory. Variables (R : realType) (T U : choiceType). -Implicit Types (f g : nat -> {distr T / R}) (h : T -> {distr U / R}). -Implicit Types (mu : {distr T / R}). +Implicit Types (f g : nat -> R.-distr T) (h : T -> R.-distr U). +Implicit Types (mu : R.-distr T). Lemma dlimC mu : \dlim_(n) mu =1 mu. Proof. @@ -787,7 +773,7 @@ Lemma dlim_lift f p : \dlim_(n) f (n + p)%N =1 dlim f. Proof. by move=> x; rewrite !dlimE (limn_einf_shift_new (fun n => (f n x)%:E) p). Qed. Lemma ge0_dlim f : forall x, 0 <= dlim f x. -Proof. exact: mu_positive. Qed. +Proof. exact: mu_ge0. Qed. Lemma le1_dlim f : forall x, dlim f x <= 1. Proof. by move=> x; rewrite -lee_fin dlim_EFin; exact: le1_liminf. Qed. @@ -829,7 +815,7 @@ End DLimTheory. Section DletDLim. Variables (R : realType) (T U : choiceType). -Implicit Types (f : nat -> {distr T / R}) (h : T -> {distr U / R}). +Implicit Types (f : nat -> R.-distr T) (h : T -> R.-distr R). Lemma sup_mul f (hf : nd f) (c : R) x : 0 <= c -> ((dlim f x) * c)%:E = ereal_sup (range (fun n => (f n x * c)%:E)). @@ -837,7 +823,7 @@ Proof. move=> c0. rewrite EFinM (dlim_sup hf) muleC. rewrite (@ge0_ereal_supZl_range R T (fun t n => (f n t)%:E)) //=. -+ by move=> t n; rewrite lee_fin; exact: ge0_mu. ++ by move=> t n; rewrite lee_fin; exact: mu_ge0. have -> : [set (c%:E * (f i x)%:E)%E | i in [set: nat]]%classic = [set (f i x * c)%:E | i in [set: nat]]%classic. @@ -856,8 +842,8 @@ have nd : nd (fun n => dlet h (f n)). rewrite dlet_EFin (dlim_sup nd). under eq_esum => x _ do rewrite (sup_mul ndf)//. rewrite (@exchange_esum_ereal_sup R T (fun x n => (f n x * h x y)%:E)) /=. -+ by move=> t n; rewrite lee_fin; apply: mulr_ge0; exact: ge0_mu. -+ move=> n m nm t; rewrite lee_fin; apply: ler_wpM2r; first exact: ge0_mu. ++ by move=> t n; rewrite lee_fin; apply: mulr_ge0; exact: mu_ge0. ++ move=> n m nm t; rewrite lee_fin; apply: ler_wpM2r; first exact: mu_ge0. by rewrite -lee_fin; exact: ndf. have -> : [set \esum_(x in [set: T]) (f i x * h x y)%:E | i in [set: nat]]%classic = @@ -871,10 +857,10 @@ Qed. End DletDLim. Section DLimDlet. -Context (R : realType) (T U : choiceType) (f : nat -> T -> {distr U / R}). +Context (R : realType) (T U : choiceType) (f : nat -> T -> R.-distr U). Context (hmono: forall x n m, (n <= m)%N -> f n x <=1 f m x). -Lemma dlim_let (mu : {distr T / R}) : +Lemma dlim_let (mu : R.-distr T) : \dlim_(n) \dlet_(x <- mu) (f n x) =1 \dlet_(x <- mu) \dlim_(n) (f n x). Proof. have nd1 y : nd (fun n => f n y). @@ -888,8 +874,8 @@ move=> z; apply: EFin_inj. rewrite (dlim_sup nd2 ) dlet_EFin. under eq_esum => t _ do rewrite mulrC (sup_mul (nd1 t))//. rewrite (@exchange_esum_ereal_sup R T (fun t n => (f n t z * mu t)%:E)) /=. -+ by move=> t n; rewrite lee_fin; apply: mulr_ge0; exact: ge0_mu. -+ move=> n m nm t; rewrite lee_fin; apply: ler_wpM2r; first exact: ge0_mu. ++ by move=> t n; rewrite lee_fin; apply: mulr_ge0; exact: mu_ge0. ++ move=> n m nm t; rewrite lee_fin; apply: ler_wpM2r; first exact: mu_ge0. exact: hmono. have ->: [set ((\dlet_(i0 <- mu) f i i0) z)%:E | i in [set: nat]]%classic = @@ -905,7 +891,7 @@ Qed. End DLimDlet. Section DLimDLim. -Context (R : realType) (T : choiceType) (f : nat -> nat -> {distr T / R}). +Context (R : realType) (T : choiceType) (f : nat -> nat -> R.-distr T). Context (hmono1: (forall k n1 n2, (n1 <= n2)%N -> f n1 k <=1 f n2 k)). Context (hmono2: (forall k n1 n2, (n1 <= n2)%N -> f k n1 <=1 f k n2)). @@ -980,11 +966,11 @@ End DLimDLim. Section dlet_dlim_diag. Context (R : realType) (T U: choiceType). -Context (d : nat -> {distr T / R}) (h : nat -> T -> {distr U / R}). +Context (d : nat -> R.-distr T) (h : nat -> T -> R.-distr R). Context (hd : homo d). Context (hmono: (forall k n1 n2, (n1 <= n2)%N -> h n1 k <=1 h n2 k)). -Lemma dhomo_nmu_dlet (nmu : nat -> {distr T / R}) : +Lemma dhomo_nmu_dlet (nmu : nat -> R.-distr T) : homo nmu -> homo (fun n => dlet (h n) (nmu n)). Proof. move=> hnmu n m hnm x. @@ -1023,7 +1009,7 @@ End dlet_dlim_diag. (* -------------------------------------------------------------------- *) Section Marginals. -Variable (R : realType) (T U : choiceType) (h : T -> U) (mu : {distr T / R}). +Variable (R : realType) (T U : choiceType) (h : T -> U) (mu : R.-distr T). Definition dmargin := \dlet_(x <- mu) (dunit (h x)). @@ -1035,7 +1021,7 @@ End Marginals. Section MarginalsTh. Variable (R: realType) (T U V : choiceType). -Lemma dmargin_psumE (mu : {distr T / R}) (f : T -> U) y : +Lemma dmargin_psumE (mu : R.-distr T) (f : T -> U) y : (dmargin f mu) y = fine (esum [set:T] (fun x => ((f x == y)%:R * mu x)%:E)). Proof. rewrite dmarginE dletE. @@ -1044,19 +1030,19 @@ apply/eq_esum => x _. by rewrite mulrC dunit1E. Qed. -Lemma dlet_dmargin (mu : {distr T / R}) (f : T -> U) (g : U -> {distr V / R}): +Lemma dlet_dmargin (mu : R.-distr T) (f : T -> U) (g : U -> R.-distr V): \dlet_(u <- dmargin f mu) g u =1 \dlet_(t <- mu) (g (f t)). Proof. move=> x; rewrite dlet_dlet; apply: eq_in_dlet=> //. by move=> y _ z /=; rewrite dlet_unit. Qed. -Lemma dmargin_dlet (mu : {distr T / R}) (f : U -> V) (g : T -> {distr U / R}): +Lemma dmargin_dlet (mu : R.-distr T) (f : U -> V) (g : T -> R.-distr U): dmargin f (\dlet_(t <- mu) g t) =1 \dlet_(t <- mu) (dmargin f (g t)). Proof. by apply/dlet_dlet. Qed. Lemma dmargin_dunit (t : T) (f : T -> U): - dmargin f (dunit t) =1 dunit (f t) :> {distr U / R}. + dmargin f (dunit t) =1 dunit (f t) :> R.-distr U. Proof. by apply/dlet_unit. Qed. End MarginalsTh. @@ -1065,15 +1051,15 @@ Notation dsnd mu := (dmargin snd mu). (* -------------------------------------------------------------------- *) Section DSwap. -Context {R : realType} {A B : choiceType} (mu : {distr (A * B)%type / R}). +Context {R : realType} {A B : choiceType} (mu : R.-distr (A * B)%type). -Definition dswap : {distr (B * A)%type / R} := +Definition dswap : R.-distr (B * A)%type := dmargin (fun xy => (xy.2, xy.1)) mu. End DSwap. (* -------------------------------------------------------------------- *) Section DSwapCoreTheory. -Context {R : realType} {A B : choiceType} (mu : {distr (A * B)%type / R}). +Context {R : realType} {A B : choiceType} (mu : R.-distr (A * B)%type). Lemma dswapE xy : dswap mu xy = mu (xy.2, xy.1). Proof. @@ -1091,7 +1077,7 @@ End DSwapCoreTheory. (* -------------------------------------------------------------------- *) Section DSwapTheory. -Context {R : realType} {A B : choiceType} (mu : {distr (A * B)%type / R}). +Context {R : realType} {A B : choiceType} (mu : R.-distr (A * B)%type). Lemma dswapK : dswap (dswap mu) =1 mu. Proof. by case=> x y; rewrite !dswapE. Qed. @@ -1120,7 +1106,7 @@ End DSwapTheory. Section DFst. Context {R : realType} {T U : choiceType}. -Lemma dfstE (mu : {distr (T * U)%type / R}) x : +Lemma dfstE (mu : R.-distr (T * U)%type) x : dfst mu x = fine (esum [set:U] (fun y => (mu (x, y))%:E)). Proof. rewrite dmarginE dletE; congr fine. @@ -1138,10 +1124,10 @@ rewrite (reindex_esum [set: U] _ (fun y => (x, y))). by apply: eq_esum => y _ /=; rewrite dunit_id mulr1. Qed. -Lemma summable_fst (mu : {distr (T * U)%type / R}) x : +Lemma summable_fst (mu : R.-distr (T * U)%type) x : esummable [set:U] (fun y => (mu (x, y))%:E). Proof. -rewrite /esummable; apply: le_lt_trans (summable_mu mu). +rewrite /esummable; apply: le_lt_trans (@mu_summable _ _ mu). rewrite -(reindex_esum [set:U] [set z : T * U | z.1 = x] (fun y => (x, y)) (fun z => (`|(mu z)%:E|)%E)). + split. @@ -1158,13 +1144,13 @@ End DFst. Section DSnd. Context {R : realType} {T U : choiceType}. -Lemma dsndE (mu : {distr (T * U)%type / R}) y : +Lemma dsndE (mu : R.-distr (T * U)%type) y : dsnd mu y = fine (esum [set:T] (fun x => (mu (x, y))%:E)). Proof. by rewrite -dfst_dswap dfstE; congr fine; apply/eq_esum=> x; rewrite dswapE. Qed. -Lemma summable_snd (mu : {distr (T * U)%type / R}) y : +Lemma summable_snd (mu : R.-distr (T * U)%type) y : esummable [set:T] (fun x => (mu (x, y))%:E). Proof. have := summable_fst (dswap mu) y; apply/eq_esummable. @@ -1176,11 +1162,11 @@ End DSnd. Section PrCoreTheory. Context {R : realType} {T : choiceType}. -Implicit Types (mu : {distr T / R}) (A B E : pred T). +Implicit Types (mu : R.-distr T) (A B E : pred T). Lemma summable_pr E mu : esummable [set:T] (fun x => ((E x)%:R * mu x)%:E). Proof. -apply/(le_esummable (g := EFin \o mu)) => [x|]; last by apply/summable_mu. +apply/(le_esummable (g := EFin \o mu)) => [x|]; last by apply/mu_summable. rewrite !lee_tofin => //=. + by rewrite mulr_ge0. by rewrite ler_piMl //= lern1 leq_b1. @@ -1247,7 +1233,7 @@ Proof. move => h1; rewrite /esp. under eq_esum => x do rewrite /= -mulrA EFinM. have hpos : forall x : T, (0%R <= (f x * mu x)%:E)%E. -+ by move=> x; rewrite lee_fin; apply: mulr_ge0; [exact: h1 | exact: ge0_mu]. ++ by move=> x; rewrite lee_fin; apply: mulr_ge0; [exact: h1 | exact: mu_ge0]. rewrite esumZ //=. have hsum : (0 <= \esum_(i in [set: T]) (f i * mu i)%:E)%E. + by apply esum_ge0 => ??. @@ -1268,7 +1254,7 @@ Lemma has_expC mu c : \E?_[mu] (fun _ => c). Proof. rewrite /has_esp. have : esummable [set: T] (fun x : T => (c%:E * (mu x)%:E)%E). - by apply: esummableZl => //; exact: summable_mu. + by apply: esummableZl => //; exact: mu_summable. apply/eq_esummable => x /=. by rewrite EFinM. Qed. @@ -1322,7 +1308,7 @@ case/boolP: (x \in dinsupp mu). + by move/dinsuppPn => ->; rewrite !mulr0. Qed. -Lemma pr_pred0_eq (mu : {distr T / R}) (E : pred T) : +Lemma pr_pred0_eq (mu : R.-distr T) (E : pred T) : E =1 pred0 -> \P_[mu] E = 0. Proof. by move=> eq; rewrite -(pr_pred0 mu); apply/eq_pr. Qed. End PrCoreTheory. @@ -1331,7 +1317,7 @@ End PrCoreTheory. Section Esp. Context {R : realType} {T : choiceType}. -Implicit Types (mu : {distr T / R}) (f : T -> \bar R). +Implicit Types (mu : R.-distr T) (f : T -> \bar R). Definition espe mu f := esum [set:T] (fun x => mule (f x) ((mu x)%:E)). @@ -1341,7 +1327,7 @@ End Esp. Section EspeCoreTheory. Context {R : realType} {T : choiceType}. -Implicit Types (mu : {distr T / R}) (A B E : pred T). +Implicit Types (mu : R.-distr T) (A B E : pred T). Lemma eexp_eq (f g: T -> \bar R) mu: (f =1 g)%E -> @@ -1369,13 +1355,13 @@ rewrite esumZ. - move => ?; rewrite lee_fin //. rewrite muleC; congr ( _ * _)%E. rewrite fineK //= esum_abse => //=. -by have := (summable_mu mu); rewrite esummableE. +by have := (@mu_summable _ _ mu); rewrite esummableE. Qed. Lemma eexp0 mu : espe mu (fun _ => 0) = 0. Proof. by rewrite eexp_cst mule0. Qed. -Lemma eexp_dlet {U: choiceType} mu (nu : T -> {distr U / R}) F : +Lemma eexp_dlet {U: choiceType} mu (nu : T -> R.-distr U) F : (forall x, 0%:E <= F x)%E -> espe (dlet nu mu) F = espe mu (fun x => espe (nu x) F). Proof. @@ -1399,7 +1385,7 @@ rewrite {1}(eq_esum _ _ - move => x ?; rewrite muleC. rewrite -esumZ. - move => x1; rewrite mule_ge0 //=. - - exact: (ge0_mu (nu x) x1). + - exact: (@mu_ge0 _ _ (nu x) x1). rewrite {1}(eq_esum _ _ (fun x0 : U => F x0 * ((mu x)%:E * (nu x x0)%:E))%E) // ?esum_sum' //. - by move => ??; rewrite muleCA. @@ -1442,7 +1428,7 @@ Lemma espeEFin mu (g : T -> R) : espe mu (EFin \o g) = esum [set: T] (EFin \o (fun x => g x * mu x)). Proof. by rewrite /espe; apply: esum.eq_esum => x ? /=; rewrite EFinM. Qed. -Lemma eexp_dlet_esp {U: choiceType} mu (nu : T -> {distr U / R}) (g : U -> R) : +Lemma eexp_dlet_esp {U: choiceType} mu (nu : T -> R.-distr U) (g : U -> R) : (forall y, 0 <= g y) -> (forall eta, \E?_[eta] g) -> espe (dlet nu mu) (EFin \o g) = espe mu (EFin \o (fun x => esp (nu x) g)). Proof. @@ -1461,9 +1447,9 @@ End EspeCoreTheory. Section PrTheory. Context {R : realType} {T U : choiceType} {I : eqType}. -Implicit Types (mu : {distr T / R}) (A B E : pred T). +Implicit Types (mu : R.-distr T) (A B E : pred T). -Lemma prE (nu : {distr T / R}) (E : pred T) : +Lemma prE (nu : R.-distr T) (E : pred T) : (\P_[nu] E)%:E = \esum_(t in [set: T]) ((E t)%:R * nu t)%:E. Proof. rewrite /pr fineK// esum_abse//. @@ -1480,7 +1466,7 @@ move=> c0 a0; rewrite -esumZ. - by apply: eq_esum => i _; rewrite EFinM. Qed. -Lemma pr_dlet E f (mu : {distr U / R}) : +Lemma pr_dlet E f (mu : R.-distr U) : \P_[dlet f mu] E = \E_[mu] (fun x => \P_[f x] E). Proof. rewrite /pr /esp. @@ -1489,14 +1475,14 @@ rewrite {1}(eq_esum _ _ (fun t => \esum_(x in [set: U]) ((E t)%:R * (mu x * f x + by move => t _; rewrite EFinM dlet_EFin EFin_esumZ // => ?; rewrite mulr_ge0. rewrite {1} exchange_esum//. + move=> t x;rewrite lee_fin. - by apply: mulr_ge0; [exact: ler0n|apply: mulr_ge0; exact: ge0_mu]. + by apply: mulr_ge0; [exact: ler0n|apply: mulr_ge0; exact: mu_ge0]. apply: eq_esum => x _ //=. rewrite EFinM prE muleC -EFin_esumZ //. + by move => ?; rewrite mulr_ge0. by apply: eq_esum => t _; rewrite mulrCA. Qed. -Lemma pr_dmargin E f (mu : {distr U / R}) : +Lemma pr_dmargin E f (mu : R.-distr U) : \P_[dmargin f mu] E = \P_[mu] [pred x | f x \in E]. Proof. by rewrite /dmargin pr_dlet pr_exp; apply/eq_exp=> x _; rewrite pr_dunit. @@ -1531,10 +1517,10 @@ Qed. Lemma le1_pr A mu : \P_[mu] A <= 1. Proof. apply: (@le_trans _ _ \P_[mu] predT); first by apply/subset_pr. -rewrite pr_predT -fine1; apply: fine_le; [| by [] | exact: le1_mu]. +rewrite pr_predT -fine1; apply: fine_le; [| by [] | exact: mu_sum_le1]. rewrite ge0_fin_numE; last first. -+ apply: le_lt_trans; [exact: le1_mu| by rewrite ltey]. -by apply: esum_ge0 => x _; rewrite lee_fin ge0_mu. ++ apply: le_lt_trans; [exact: mu_sum_le1| by rewrite ltey]. +by apply: esum_ge0 => x _; rewrite lee_fin mu_ge0. Qed. Lemma le_exp mu f1 f2: \E?_[mu] f1 -> \E?_[mu] f2 -> @@ -1568,7 +1554,7 @@ Proof. move=> h; rewrite -lee_fin !prE. apply: le_esum => x _; rewrite lee_fin. case/boolP: (x \in dinsupp nu) => [/h {}h|]; last first. - by move/dinsuppPn=> ->; rewrite mulr0; apply: mulr_ge0; [exact: ler0n|exact: ge0_mu]. + by move/dinsuppPn=> ->; rewrite mulr0; apply: mulr_ge0; [exact: ler0n|exact: mu_ge0]. by case/boolP: (A x) => [/h|]; rewrite ?(mul0r, mul1r). Qed. @@ -1585,7 +1571,7 @@ Lemma prc_sum A mu : 0 < \P_[mu] A -> Proof. move=> gt0. have a0 : forall i, 0 <= (A i)%:R * mu i. - by move=> i; apply: mulr_ge0; [exact: ler0n|exact: ge0_mu]. + by move=> i; apply: mulr_ge0; [exact: ler0n|exact: mu_ge0]. have hpr1 : forall x, \P_[mu] [predI pred1 x & A] = (A x)%:R * mu x. move=> x; rewrite /pr. rewrite (eq_esum _ _ ( fun y => if x == y then ((A y)%:R * mu y)%:E else 0)). @@ -1605,7 +1591,7 @@ move=> hE x xE. have hle : \P_[mu] (pred1 x) <= \P_[mu] E. by apply: subset_pr => y; rewrite !inE => /eqP ->. move: hle; rewrite hE -pr_pred1 => h. -by apply/eqP; rewrite eq_le h /=; exact: ge0_mu. +by apply/eqP; rewrite eq_le h /=; exact: mu_ge0. Qed. Lemma prID A B mu : @@ -1621,7 +1607,7 @@ rewrite -natrD; congr (_ %:R). by case: (A x); case: (B x). Qed. -Lemma pr_or_indep (A B : pred T) (mu : {distr T / R}) : +Lemma pr_or_indep (A B : pred T) (mu : R.-distr T) : (forall x, x \in A -> x \notin B) -> \P_[mu] [predU A & B] = \P_[mu] A + \P_[mu] B. Proof. @@ -1714,7 +1700,7 @@ move=> x mux; move/pr_eq0: zPB' => /(_ x) h; rewrite !inE. by apply/negP=> /andP[_ /h] /dinsuppP. Qed. -Lemma prc_pred1 (mu : {distr T / R}) x A : +Lemma prc_pred1 (mu : R.-distr T) x A : prc mu (pred1 x) A = (A x)%:R * mu x / \P_[mu] A. Proof. rewrite /prc; congr (_ / _); rewrite /pr. @@ -1785,7 +1771,7 @@ Proof. case=> M leM; rewrite /has_esp /esummable. rewrite (eq_esum _ _ (fun x=> `|(F x)%:E * (mu x)%:E|)%E). move=> x _; rewrite -EFinM //=. -apply: esummableMl; last exact: summable_mu. +apply: esummableMl; last exact: mu_summable. exists M%:E => [x ?|]; last by []. by rewrite /= lee_fin; exact: leM x. Qed. @@ -1797,7 +1783,7 @@ rewrite (eq_esum _ _ (fun x=> `|(F x)%:E * (mu x)%:E|)%E). move=> x _; rewrite -EFinM //=. apply: esummableMr; last exact: smF. exists 1%:E => [x ?|]; last by []. -by rewrite /= lee_fin (ger0_norm (ge0_mu _ _)); exact: le1_mu1. +by rewrite /= lee_fin (ger0_norm (@mu_ge0 _ _ mu x)); exact: le1_mu1. Qed. Lemma exp_le_bd mu F (M : R) : @@ -1811,19 +1797,19 @@ move=> ge0M bd; apply/(@le_trans _ _ (\E_[mu] (fun _ => M))). by rewrite exp_cst ler_piMl // le1_pr. Qed. -Lemma ge0_esp {V : choiceType} (eta : {distr V / R}) (g : V -> R) : +Lemma ge0_esp {V : choiceType} (eta : R.-distr V) (g : V -> R) : (forall y, 0 <= g y) -> 0 <= \E_[eta] g. Proof. move=> g0; rewrite /esp; apply: fine_ge0; apply: esum_ge0 => x ?. by rewrite lee_fin mulr_ge0//; exact: g0. Qed. -Lemma exp_dlet_ge0 (mu : {distr T / R}) (nu : T -> {distr U / R}) (g : U -> R) : +Lemma exp_dlet_ge0 (mu : R.-distr T) (nu : T -> R.-distr U) (g : U -> R) : (forall y, 0 <= g y) -> (forall eta, \E?_[eta] g) -> \E_[dlet nu mu] g = \E_[mu] (fun x => \E_[nu x] g). Proof. by move=> g0 sg; rewrite espE (eexp_dlet_esp mu nu g0 sg) -espE. Qed. -Lemma has_esp_le {V:choiceType} (mu : {distr V / R}) (k h : V -> R) : +Lemma has_esp_le {V:choiceType} (mu : R.-distr V) (k h : V -> R) : (forall x, `|k x| <= `|h x|) -> \E?_[mu] h -> \E?_[mu] k. Proof. move=> kh; rewrite /has_esp => fh. @@ -1834,12 +1820,12 @@ apply: le_esum. by move => ??; rewrite lee_fin !normrM ler_wpM2r. Qed. -Lemma hcomp (mu : {distr T / R}) (nu : T -> {distr U / R}) (g : U -> R) : +Lemma hcomp (mu : R.-distr T) (nu : T -> R.-distr U) (g : U -> R) : (forall y, 0 <= g y) -> (forall eta, \E?_[eta] g) -> \E?_[mu] (fun x => \E_[nu x] g). Proof. move=> g0 sg. have hge0 : forall x, 0 <= esp (nu x) g * mu x. - by move=> x; apply: mulr_ge0; [exact: ge0_esp | exact: ge0_mu]. + by move=> x; apply: mulr_ge0; [exact: ge0_esp | exact: mu_ge0]. rewrite /has_esp esummableE. rewrite (esum.eq_esum _ _ (EFin \o (fun x => esp (nu x) g * mu x))). + move=> x _ /=; rewrite ger0_norm //. @@ -1847,7 +1833,7 @@ rewrite -espeEFin -(eexp_dlet_esp mu nu g0 sg) espeEFin. exact: (esummable_esum_fin_num (sg (dlet nu mu))). Qed. -Lemma expB {V: choiceType} (f g : V -> R) (eta : {distr V / R}) : +Lemma expB {V: choiceType} (f g : V -> R) (eta : R.-distr V) : \E?_[eta] f -> \E?_[eta] g -> \E_[eta] (f \- g) = \E_[eta] f - \E_[eta] g. Proof. move=> sf sg. @@ -1860,7 +1846,7 @@ rewrite {1}(eexp_eq (g:=fun x => ((f x)%:E - (g x)%:E))%E). exact : eexpB. Qed. -Lemma exp_dlet mu (nu : T -> {distr U / R}) F : +Lemma exp_dlet mu (nu : T -> R.-distr U ) F : (forall eta, \E?_[eta] F) -> \E_[dlet nu mu] F = \E_[mu] (fun x => \E_[nu x] F). Proof. @@ -1886,7 +1872,7 @@ Section mono_esum. Context {R : realType} {T : choiceType} - {f : nat -> {distr T / R}}. + {f : nat -> R.-distr T}. Hypothesis ndf : nd f. @@ -1950,18 +1936,18 @@ transitivity (ereal_sup (range (fun n => esum [set:T] (fun x : T => ((E x)%:R * f n x)%:E)))); last first. by apply: sup_range_lim => n m nm; apply: le_esum => x _; exact: (hmono n m nm x). rewrite -(@exchange_esum_ereal_sup R T (fun x n => ((E x)%:R * f n x)%:E)) //. -+ by move=> x n; rewrite lee_fin; apply: mulr_ge0; [exact: ler0n | exact: ge0_mu]. ++ by move=> x n; rewrite lee_fin; apply: mulr_ge0; [exact: ler0n | exact: mu_ge0]. + move => x n m nm. exact: (hmono n m nm x). apply: eq_esum => x _. rewrite EFinM distr_lub_sup (@ge0_ereal_supZl_range R T (fun a b => (f b a)%:E)) //. -+ by move=> t n; rewrite lee_fin; exact: ge0_mu. ++ by move=> t n; rewrite lee_fin; exact: mu_ge0. + by rewrite lee_tofin. Qed. End mono_esum. (* -------------------------------------------------------------------- *) -Lemma distr_eqP {R : realType} {T : choiceType} (f1 f2 : {distr T / R}): +Lemma distr_eqP {R : realType} {T : choiceType} (f1 f2 : R.-distr T): f1 =1 f2 <-> f1 = f2. Proof. split=> [|->] //. From 0cc91758e0c4c47c48f0250dd8015ae0e7a7cb87 Mon Sep 17 00:00:00 2001 From: Lionel Blatter Date: Fri, 16 Oct 2026 23:11:44 +0200 Subject: [PATCH 07/18] Renaming --- theories/probability_theory/counting_distr.v | 190 +++++++++---------- 1 file changed, 95 insertions(+), 95 deletions(-) diff --git a/theories/probability_theory/counting_distr.v b/theories/probability_theory/counting_distr.v index 70433c20cf..bb3d779de4 100644 --- a/theories/probability_theory/counting_distr.v +++ b/theories/probability_theory/counting_distr.v @@ -10,13 +10,13 @@ From mathcomp Require Import unstable. From mathcomp Require Import numfun. (**md**************************************************************************) -(* # SubDistribution *) +(* # Subprobability mass function *) (* *) (* ``` *) -(* SubDistribution T R == subdistribution for choicetype T with values *) -(* in R *) -(* isSubDistr == interface for functions that satisfy the *) -(* property of SubDistribution. *) +(* Subpmf T R == subprobability mass function for choicetype T with *) +(* values in R *) +(* isSubpmf == interface for functions that satisfy the *) +(* property of Subprobability mass function. *) (* dnull == the zero distribution (null distribution) *) (* dunit == degenerate distribution *) (* dlet == monadic bind for distribution *) @@ -63,18 +63,18 @@ Local Notation "\`| f |" := (fun x => `|f x|) (at level 2). (* -------------------------------------------------------------------- *) -HB.mixin Record isSubDistribution (R : realType) (T : choiceType) (mu : T -> R) := +HB.mixin Record issubpmf (R : realType) (T : choiceType) (mu : T -> R) := { mu_ge0 : forall x, 0 <= mu x ; mu_summable : esummable [set: T] (EFin \o mu); mu_sum_le1 : (esum [set: T] (EFin \o mu) <= 1)%E; }. -HB.structure Definition SubDistribution (R : realType) (T : choiceType) := - {f of @isSubDistribution R T f}. +HB.structure Definition subpmf (R : realType) (T : choiceType) := + {f of @issubpmf R T f}. -Notation "R .-distr T" := (@SubDistribution.type R T) - (at level 0, T at level 2, format "R .-distr T ") +Notation "R .-pmf T" := (@subpmf.type R T) + (at level 0, T at level 2, format "R .-pmf T ") : type_scope. #[global] Hint Extern 0 (is_true (0 <= _)) => solve [apply: mu_ge0] : core. @@ -84,11 +84,11 @@ Notation "R .-distr T" := (@SubDistribution.type R T) Section StdDefs. Context {R : realType} (T : choiceType). -Implicit Types (mu : R.-distr T) (A B E : pred T) (f : T -> R). +Implicit Types (mu : R.-pmf T) (A B E : pred T) (f : T -> R). Definition dinsupp mu := fun x => mu x != 0 :> R. -Lemma in_dinsupp x (mu : R.-distr T) : +Lemma in_dinsupp x (mu : R.-pmf T) : (x \in dinsupp mu) = (mu x != 0). Proof. by []. Qed. @@ -114,14 +114,14 @@ Notation "\E?_[ mu ] f" := (has_esp mu f). Notation dweight mu := (\P_[mu] predT). (* -------------------------------------------------------------------- *) -HB.factory Record isSubDistr {R : realType} {T : choiceType} (mu : T -> R) := { +HB.factory Record isSubpmf {R : realType} {T : choiceType} (mu : T -> R) := { distr_pos: (forall x, 0 <= mu x); distr_lee_one: (forall J, uniq J -> \sum_(j <- J) mu j <= 1) }. HB.builders Context {R : realType} {T : choiceType} (mu : T -> R) - (isd : @isSubDistr R T mu). + (isd : @isSubpmf R T mu). Local Lemma isd1 : forall x, 0 <= mu x. Proof. by case: isd. Qed. @@ -149,7 +149,7 @@ rewrite fsumEFin // lee_fin fsbig_finite //=. by apply: h2. Qed. -HB.instance Definition _ := @isSubDistribution.Build R T mu isd1 isd2 isd3. +HB.instance Definition _ := @issubpmf.Build R T mu isd1 isd2 isd3. HB.end. @@ -166,7 +166,7 @@ split=> -[ ge0_mu le1]; split=> //. Qed. Lemma le1_mu1 - {R : realType} {T : choiceType} (mu : R.-distr T) x : mu x <= 1. + {R : realType} {T : choiceType} (mu : R.-pmf T) x : mu x <= 1. Proof. case mu => //= {}mu [[?]]. rewrite esummableE => ??. @@ -186,9 +186,9 @@ Lemma isd_mnull : sub_distr dnull_fun. Proof. by split=> // J _; rewrite big1 ?ler01. Qed. HB.instance Definition _ := - @isSubDistr.Build R T dnull_fun (proj1 isd_mnull) (proj2 isd_mnull). + @isSubpmf.Build R T dnull_fun (proj1 isd_mnull) (proj2 isd_mnull). -Definition dnull := @locked R.-distr T dnull_fun. +Definition dnull := @locked R.-pmf T dnull_fun. Lemma dnullE x : dnull x = 0. Proof. by unlock dnull. Qed. @@ -196,7 +196,7 @@ Proof. by unlock dnull. Qed. End DistrD. (* -------------------------------------------------------------------- *) -Lemma lef_dnull {R : realType} {T : choiceType} (mu : R.-distr T) : +Lemma lef_dnull {R : realType} {T : choiceType} (mu : R.-pmf T) : dnull <=1 mu. Proof. by move=> x; rewrite dnullE mu_ge0. Qed. @@ -204,10 +204,10 @@ Proof. by move=> x; rewrite dnullE mu_ge0. Qed. Section Restr. Context (R : realType) (T : choiceType) (p : pred T). -Definition drestr_fun (mu : R.-distr T) := +Definition drestr_fun (mu : R.-pmf T) := fun x => if p x then mu x else 0. -Lemma isd_drestr (mu : R.-distr T) : sub_distr (drestr_fun mu). +Lemma isd_drestr (mu : R.-pmf T) : sub_distr (drestr_fun mu). Proof. split=> [x|J]; first by rewrite /drestr_fun; case: ifP. move=> eqJ; apply/(@le_trans _ _ (\sum_(j <- J) `|mu j|)). @@ -221,12 +221,12 @@ move=> eqJ; apply/(@le_trans _ _ (\sum_(j <- J) `|mu j|)). exact: sum_esum_ge. Qed. -HB.instance Definition _ (mu : R.-distr T) := - @isSubDistr.Build R T (drestr_fun mu) (proj1 (isd_drestr mu)) (proj2 (isd_drestr mu)). +HB.instance Definition _ (mu : R.-pmf T) := + @isSubpmf.Build R T (drestr_fun mu) (proj1 (isd_drestr mu)) (proj2 (isd_drestr mu)). -Definition drestr (mu : R.-distr T) := @locked R.-distr T (drestr_fun mu). +Definition drestr (mu : R.-pmf T) := @locked R.-pmf T (drestr_fun mu). -Lemma drestrE (mu : R.-distr T) x : +Lemma drestrE (mu : R.-pmf T) x : drestr mu x = if p x then mu x else 0. Proof. by unlock drestr. Qed. End Restr. @@ -235,11 +235,11 @@ End Restr. Section RestrTheory. Context {R : realType} {T : choiceType}. -Lemma drestrD (mu : R.-distr T) (p : pred T) x : +Lemma drestrD (mu : R.-pmf T) (p : pred T) x : mu x = drestr p mu x + drestr (predC p) mu x. Proof. by rewrite !drestrE !inE; case: ifPn; rewrite /= (addr0, add0r). Qed. -Lemma dinsupp_restr (mu : R.-distr T) (p : pred T) x : +Lemma dinsupp_restr (mu : R.-pmf T) (p : pred T) x : (x \in dinsupp (drestr p mu)) = (x \in dinsupp mu) && p x. Proof. apply/dinsuppP/idP. @@ -252,7 +252,7 @@ End RestrTheory. Section DRat. Context {R : realType} (T : choiceType). -Local Notation distr := R.-distr T. +Local Notation distr := R.-pmf T. Implicit Types (s : seq T). @@ -305,9 +305,9 @@ Lemma isd_drat s : sub_distr (drat_fun s). Proof. by split; [apply/ge0_drat | apply/has_sup_drat]. Qed. HB.instance Definition _ (s : seq T) := - @isSubDistr.Build R T (drat_fun s) (proj1 (isd_drat s)) (proj2 (isd_drat s)). + @isSubpmf.Build R T (drat_fun s) (proj1 (isd_drat s)) (proj2 (isd_drat s)). -Definition drat (s : seq T) := @locked R.-distr T (drat_fun s). +Definition drat (s : seq T) := @locked R.-pmf T (drat_fun s). Lemma drat1E s x : drat s x = (count_mem x s)%:R / (size s)%:R. @@ -352,9 +352,9 @@ Proof. apply/isdistr_finP; split=> [b|]. Qed. HB.instance Definition _ (xt : R) := - @isSubDistr.Build R _ (dflip_fun xt) (proj1 (isd_dflip xt)) (proj2 (isd_dflip xt)). + @isSubpmf.Build R _ (dflip_fun xt) (proj1 (isd_dflip xt)) (proj2 (isd_dflip xt)). -Definition dflip (xt : R) := @locked R.-distr bool (dflip_fun xt). +Definition dflip (xt : R) := @locked R.-pmf bool (dflip_fun xt). Lemma dflip1E xt : dflip xt =1 (fun b => if b then clamp xt else 1 - clamp xt). Proof. by unlock dflip. Qed. @@ -363,7 +363,7 @@ End Flip. (* -------------------------------------------------------------------- *) Section Bind. Context {R : realType} {T U : choiceType} - (f : T -> R.-distr U) (mu : R.-distr T). + (f : T -> R.-pmf U) (mu : R.-pmf T). Definition dlet_fun := fun y : U => fine (esum [set:T] (fun x => EFin (mu x * f x y))). @@ -396,9 +396,9 @@ split=> [x|J uqJ]. by have := (@mu_summable _ _ (f i)); rewrite esummableE. Qed. -HB.instance Definition _ := @isSubDistr.Build R U dlet_fun (proj1 isd_dlet) (proj2 isd_dlet). +HB.instance Definition _ := @isSubpmf.Build R U dlet_fun (proj1 isd_dlet) (proj2 isd_dlet). -Definition dlet := @locked R.-distr U dlet_fun. +Definition dlet := @locked R.-pmf U dlet_fun. Lemma dletE y : dlet y = fine (esum [set:T] (fun x => EFin (mu x * f x y))). Proof. by unlock dlet. Qed. @@ -406,10 +406,10 @@ End Bind. Notation "\dlet_ ( i <- d ) E" := (dlet (fun i => E) d). -Definition dlift {R : realType} {T : choiceType} (f : T -> R.-distr T) := +Definition dlift {R : realType} {T : choiceType} (f : T -> R.-pmf T) := fun d => \dlet_(x <- d) f x. -Definition diter {R : realType} {T : choiceType} n (f : T -> R.-distr T) := +Definition diter {R : realType} {T : choiceType} n (f : T -> R.-pmf T) := fun a => (iter n (dlift f) (dunit a)). (* -------------------------------------------------------------------- *) @@ -420,7 +420,7 @@ Lemma esum_abse {R : realType} {T : choiceType} Proof. by move => ?; apply eq_esum => ?? ; rewrite gee0_abs // lee_tofin. Qed. Lemma summable_mu_wgtd {R : realType} {T : choiceType} - (f : T -> R) (mu : R.-distr T) : + (f : T -> R) (mu : R.-pmf T) : (forall x, 0 <= f x <= 1) -> esummable [set: T] (fun x => EFin (mu x * f x)). Proof. rewrite /esummable => h. @@ -435,7 +435,7 @@ Qed. Section BindTheory. Variables (R : realType) (T U : choiceType). -Implicit Types (f g : T -> R.-distr U) (mu nu : R.-distr T). +Implicit Types (f g : T -> R.-pmf U) (mu nu : R.-pmf T). Lemma dlet_null f : dlet f dnull =1 dnull. Proof. @@ -480,11 +480,11 @@ case /boolP: (x \in dinsupp mu) => [/eq_f ->//|]. by move/dinsuppPn => ->; rewrite !mul0e. Qed. -Lemma summable_dlet (f : T -> R.-distr U) (mu : R.-distr T) y : +Lemma summable_dlet (f : T -> R.-pmf U) (mu : R.-pmf T) y : esummable [set: T] (fun x : T => EFin (mu x * (f x) y)). Proof. by apply/summable_mu_wgtd=> x; rewrite mu_ge0 le1_mu1. Qed. -Lemma fin_esum (f : T -> R.-distr U) (mu : R.-distr T) y: +Lemma fin_esum (f : T -> R.-pmf U) (mu : R.-pmf T) y: \esum_(x' in [set: T]) (mu x' * f x' y)%:E \is a fin_num. Proof. rewrite esum_abse. @@ -492,7 +492,7 @@ rewrite esum_abse. by have := (summable_dlet f mu y); rewrite esummableE. Qed. -Lemma dlet_EFin (f : T -> R.-distr U) (mu : R.-distr T) y : +Lemma dlet_EFin (f : T -> R.-pmf U) (mu : R.-pmf T) y : (dlet f mu y)%:E = esum [set:T] (fun x => (mu x * f x y)%:E). Proof. by rewrite dletE fineK// ?fin_esum. Qed. @@ -522,7 +522,7 @@ move=> le_mu le_fg x. by apply/(le_trans (le_in_dlet le_fg _))/le_mu_dlet. Qed. -Lemma dletC (mu : R.-distr T) (nu : R.-distr U) y : +Lemma dletC (mu : R.-pmf T) (nu : R.-pmf U) y : (\dlet_(_ <- mu) nu) y = (dweight mu) * (nu y). Proof. rewrite dletE /pr //=. @@ -545,7 +545,7 @@ rewrite eqe mulf_eq0 negb_or => /andP[nz_mu nz_f]. by exists x; rewrite ?in_dinsupp. Qed. -Lemma fine_esum0 (f : T -> R.-distr U) (mu : R.-distr T) x y: +Lemma fine_esum0 (f : T -> R.-pmf U) (mu : R.-pmf T) x y: fine (\esum_(x in [set: T]) (mu x * f x y)%:E) = 0 -> ((mu x * f x y)%:E = 0). Proof. @@ -576,7 +576,7 @@ have -> : \esum_(x in [set: T]) (mu x * dunit (f x) y)%:E = 0. by []. Qed. -Lemma eq0_dlet (mu : R.-distr T) (F : T -> R.-distr U ) y : +Lemma eq0_dlet (mu : R.-pmf T) (F : T -> R.-pmf U ) y : (\dlet_(x <- mu) F x) y = 0 -> forall x, x \in dinsupp mu -> F x y = 0. Proof. rewrite dletE => /fine_esum0 => h x. @@ -589,9 +589,9 @@ End BindTheory. (* -------------------------------------------------------------------- *) Section DLetDLet. Context {R:realType} {T U V : choiceType} - (f1 : T -> R.-distr U) (f2 : U -> R.-distr V). + (f1 : T -> R.-pmf U) (f2 : U -> R.-pmf V). -Lemma dlet_dlet (mu : R.-distr T) : +Lemma dlet_dlet (mu : R.-pmf T) : \dlet_(x <- \dlet_(y <- mu) f1 y) f2 x =1 \dlet_(y <- mu) (\dlet_(x <- f1 y) f2 x). Proof. @@ -613,9 +613,9 @@ End DLetDLet. (* -------------------------------------------------------------------- *) Section DLetAlg. -Context {R : realType} {T U : choiceType} (mu mu1 mu2 : R.-distr T). +Context {R : realType} {T U : choiceType} (mu mu1 mu2 : R.-pmf T). -Lemma dlet_additive (f : T -> R.-distr U) z : +Lemma dlet_additive (f : T -> R.-pmf U) z : (forall x, mu x = mu1 x + mu2 x) -> (\dlet_(x <- mu) f x) z = (\dlet_(x <- mu1) f x) z + (\dlet_(x <- mu2) f x) z. Proof. @@ -643,7 +643,7 @@ Qed. Section dlim. Context {R : realType} (T : choiceType). -Implicit Types (f g : nat -> R.-distr T). +Implicit Types (f g : nat -> R.-pmf T). Import numFieldNormedType.Exports. @@ -711,10 +711,10 @@ apply: (@le_trans _ _ (esum [set: T] (EFin \o f n))); last exact: mu_sum_le1. exact: sum_esum_ge. Qed. -HB.instance Definition _ f := @isSubDistr.Build R T (dlim_fun f) +HB.instance Definition _ f := @isSubpmf.Build R T (dlim_fun f) (proj1 (isd_dlim f)) (proj2 (isd_dlim f)). -Definition dlim f := @locked R.-distr T (dlim_fun f). +Definition dlim f := @locked R.-pmf T (dlim_fun f). Lemma dlimE f x : dlim f x = fine (limn_einf (fun n => (f n x)%:E)). Proof. by unlock dlim. Qed. @@ -722,10 +722,10 @@ Proof. by unlock dlim. Qed. Lemma dlim_EFin f x : (dlim f x)%:E = limn_einf (fun n => (f n x)%:E). Proof. by unlock dlim; exact: dlim_fun_EFin. Qed. -Definition homo (f : nat -> R.-distr T) := +Definition homo (f : nat -> R.-pmf T) := forall n m, (n <= m)%N -> f n <=1 f m. -Definition nd (f : nat -> R.-distr T) := +Definition nd (f : nat -> R.-pmf T) := forall x, nondecreasing_seq (fun n => (f n x)%:E). Lemma dhomo_dnd f : homo f -> nd f. @@ -758,8 +758,8 @@ Notation "\dlim_ ( n ) E" := (dlim (fun n => E)). Section DLimTheory. Variables (R : realType) (T U : choiceType). -Implicit Types (f g : nat -> R.-distr T) (h : T -> R.-distr U). -Implicit Types (mu : R.-distr T). +Implicit Types (f g : nat -> R.-pmf T) (h : T -> R.-pmf U). +Implicit Types (mu : R.-pmf T). Lemma dlimC mu : \dlim_(n) mu =1 mu. Proof. @@ -815,7 +815,7 @@ End DLimTheory. Section DletDLim. Variables (R : realType) (T U : choiceType). -Implicit Types (f : nat -> R.-distr T) (h : T -> R.-distr R). +Implicit Types (f : nat -> R.-pmf T) (h : T -> R.-pmf R). Lemma sup_mul f (hf : nd f) (c : R) x : 0 <= c -> ((dlim f x) * c)%:E = ereal_sup (range (fun n => (f n x * c)%:E)). @@ -857,10 +857,10 @@ Qed. End DletDLim. Section DLimDlet. -Context (R : realType) (T U : choiceType) (f : nat -> T -> R.-distr U). +Context (R : realType) (T U : choiceType) (f : nat -> T -> R.-pmf U). Context (hmono: forall x n m, (n <= m)%N -> f n x <=1 f m x). -Lemma dlim_let (mu : R.-distr T) : +Lemma dlim_let (mu : R.-pmf T) : \dlim_(n) \dlet_(x <- mu) (f n x) =1 \dlet_(x <- mu) \dlim_(n) (f n x). Proof. have nd1 y : nd (fun n => f n y). @@ -891,7 +891,7 @@ Qed. End DLimDlet. Section DLimDLim. -Context (R : realType) (T : choiceType) (f : nat -> nat -> R.-distr T). +Context (R : realType) (T : choiceType) (f : nat -> nat -> R.-pmf T). Context (hmono1: (forall k n1 n2, (n1 <= n2)%N -> f n1 k <=1 f n2 k)). Context (hmono2: (forall k n1 n2, (n1 <= n2)%N -> f k n1 <=1 f k n2)). @@ -966,11 +966,11 @@ End DLimDLim. Section dlet_dlim_diag. Context (R : realType) (T U: choiceType). -Context (d : nat -> R.-distr T) (h : nat -> T -> R.-distr R). +Context (d : nat -> R.-pmf T) (h : nat -> T -> R.-pmf R). Context (hd : homo d). Context (hmono: (forall k n1 n2, (n1 <= n2)%N -> h n1 k <=1 h n2 k)). -Lemma dhomo_nmu_dlet (nmu : nat -> R.-distr T) : +Lemma dhomo_nmu_dlet (nmu : nat -> R.-pmf T) : homo nmu -> homo (fun n => dlet (h n) (nmu n)). Proof. move=> hnmu n m hnm x. @@ -1009,7 +1009,7 @@ End dlet_dlim_diag. (* -------------------------------------------------------------------- *) Section Marginals. -Variable (R : realType) (T U : choiceType) (h : T -> U) (mu : R.-distr T). +Variable (R : realType) (T U : choiceType) (h : T -> U) (mu : R.-pmf T). Definition dmargin := \dlet_(x <- mu) (dunit (h x)). @@ -1021,7 +1021,7 @@ End Marginals. Section MarginalsTh. Variable (R: realType) (T U V : choiceType). -Lemma dmargin_psumE (mu : R.-distr T) (f : T -> U) y : +Lemma dmargin_psumE (mu : R.-pmf T) (f : T -> U) y : (dmargin f mu) y = fine (esum [set:T] (fun x => ((f x == y)%:R * mu x)%:E)). Proof. rewrite dmarginE dletE. @@ -1030,19 +1030,19 @@ apply/eq_esum => x _. by rewrite mulrC dunit1E. Qed. -Lemma dlet_dmargin (mu : R.-distr T) (f : T -> U) (g : U -> R.-distr V): +Lemma dlet_dmargin (mu : R.-pmf T) (f : T -> U) (g : U -> R.-pmf V): \dlet_(u <- dmargin f mu) g u =1 \dlet_(t <- mu) (g (f t)). Proof. move=> x; rewrite dlet_dlet; apply: eq_in_dlet=> //. by move=> y _ z /=; rewrite dlet_unit. Qed. -Lemma dmargin_dlet (mu : R.-distr T) (f : U -> V) (g : T -> R.-distr U): +Lemma dmargin_dlet (mu : R.-pmf T) (f : U -> V) (g : T -> R.-pmf U): dmargin f (\dlet_(t <- mu) g t) =1 \dlet_(t <- mu) (dmargin f (g t)). Proof. by apply/dlet_dlet. Qed. Lemma dmargin_dunit (t : T) (f : T -> U): - dmargin f (dunit t) =1 dunit (f t) :> R.-distr U. + dmargin f (dunit t) =1 dunit (f t) :> R.-pmf U. Proof. by apply/dlet_unit. Qed. End MarginalsTh. @@ -1051,15 +1051,15 @@ Notation dsnd mu := (dmargin snd mu). (* -------------------------------------------------------------------- *) Section DSwap. -Context {R : realType} {A B : choiceType} (mu : R.-distr (A * B)%type). +Context {R : realType} {A B : choiceType} (mu : R.-pmf (A * B)%type). -Definition dswap : R.-distr (B * A)%type := +Definition dswap : R.-pmf (B * A)%type := dmargin (fun xy => (xy.2, xy.1)) mu. End DSwap. (* -------------------------------------------------------------------- *) Section DSwapCoreTheory. -Context {R : realType} {A B : choiceType} (mu : R.-distr (A * B)%type). +Context {R : realType} {A B : choiceType} (mu : R.-pmf (A * B)%type). Lemma dswapE xy : dswap mu xy = mu (xy.2, xy.1). Proof. @@ -1077,7 +1077,7 @@ End DSwapCoreTheory. (* -------------------------------------------------------------------- *) Section DSwapTheory. -Context {R : realType} {A B : choiceType} (mu : R.-distr (A * B)%type). +Context {R : realType} {A B : choiceType} (mu : R.-pmf (A * B)%type). Lemma dswapK : dswap (dswap mu) =1 mu. Proof. by case=> x y; rewrite !dswapE. Qed. @@ -1106,7 +1106,7 @@ End DSwapTheory. Section DFst. Context {R : realType} {T U : choiceType}. -Lemma dfstE (mu : R.-distr (T * U)%type) x : +Lemma dfstE (mu : R.-pmf (T * U)%type) x : dfst mu x = fine (esum [set:U] (fun y => (mu (x, y))%:E)). Proof. rewrite dmarginE dletE; congr fine. @@ -1124,7 +1124,7 @@ rewrite (reindex_esum [set: U] _ (fun y => (x, y))). by apply: eq_esum => y _ /=; rewrite dunit_id mulr1. Qed. -Lemma summable_fst (mu : R.-distr (T * U)%type) x : +Lemma summable_fst (mu : R.-pmf (T * U)%type) x : esummable [set:U] (fun y => (mu (x, y))%:E). Proof. rewrite /esummable; apply: le_lt_trans (@mu_summable _ _ mu). @@ -1144,13 +1144,13 @@ End DFst. Section DSnd. Context {R : realType} {T U : choiceType}. -Lemma dsndE (mu : R.-distr (T * U)%type) y : +Lemma dsndE (mu : R.-pmf (T * U)%type) y : dsnd mu y = fine (esum [set:T] (fun x => (mu (x, y))%:E)). Proof. by rewrite -dfst_dswap dfstE; congr fine; apply/eq_esum=> x; rewrite dswapE. Qed. -Lemma summable_snd (mu : R.-distr (T * U)%type) y : +Lemma summable_snd (mu : R.-pmf (T * U)%type) y : esummable [set:T] (fun x => (mu (x, y))%:E). Proof. have := summable_fst (dswap mu) y; apply/eq_esummable. @@ -1162,7 +1162,7 @@ End DSnd. Section PrCoreTheory. Context {R : realType} {T : choiceType}. -Implicit Types (mu : R.-distr T) (A B E : pred T). +Implicit Types (mu : R.-pmf T) (A B E : pred T). Lemma summable_pr E mu : esummable [set:T] (fun x => ((E x)%:R * mu x)%:E). Proof. @@ -1308,7 +1308,7 @@ case/boolP: (x \in dinsupp mu). + by move/dinsuppPn => ->; rewrite !mulr0. Qed. -Lemma pr_pred0_eq (mu : R.-distr T) (E : pred T) : +Lemma pr_pred0_eq (mu : R.-pmf T) (E : pred T) : E =1 pred0 -> \P_[mu] E = 0. Proof. by move=> eq; rewrite -(pr_pred0 mu); apply/eq_pr. Qed. End PrCoreTheory. @@ -1317,7 +1317,7 @@ End PrCoreTheory. Section Esp. Context {R : realType} {T : choiceType}. -Implicit Types (mu : R.-distr T) (f : T -> \bar R). +Implicit Types (mu : R.-pmf T) (f : T -> \bar R). Definition espe mu f := esum [set:T] (fun x => mule (f x) ((mu x)%:E)). @@ -1327,7 +1327,7 @@ End Esp. Section EspeCoreTheory. Context {R : realType} {T : choiceType}. -Implicit Types (mu : R.-distr T) (A B E : pred T). +Implicit Types (mu : R.-pmf T) (A B E : pred T). Lemma eexp_eq (f g: T -> \bar R) mu: (f =1 g)%E -> @@ -1361,7 +1361,7 @@ Qed. Lemma eexp0 mu : espe mu (fun _ => 0) = 0. Proof. by rewrite eexp_cst mule0. Qed. -Lemma eexp_dlet {U: choiceType} mu (nu : T -> R.-distr U) F : +Lemma eexp_dlet {U: choiceType} mu (nu : T -> R.-pmf U) F : (forall x, 0%:E <= F x)%E -> espe (dlet nu mu) F = espe mu (fun x => espe (nu x) F). Proof. @@ -1428,7 +1428,7 @@ Lemma espeEFin mu (g : T -> R) : espe mu (EFin \o g) = esum [set: T] (EFin \o (fun x => g x * mu x)). Proof. by rewrite /espe; apply: esum.eq_esum => x ? /=; rewrite EFinM. Qed. -Lemma eexp_dlet_esp {U: choiceType} mu (nu : T -> R.-distr U) (g : U -> R) : +Lemma eexp_dlet_esp {U: choiceType} mu (nu : T -> R.-pmf U) (g : U -> R) : (forall y, 0 <= g y) -> (forall eta, \E?_[eta] g) -> espe (dlet nu mu) (EFin \o g) = espe mu (EFin \o (fun x => esp (nu x) g)). Proof. @@ -1447,9 +1447,9 @@ End EspeCoreTheory. Section PrTheory. Context {R : realType} {T U : choiceType} {I : eqType}. -Implicit Types (mu : R.-distr T) (A B E : pred T). +Implicit Types (mu : R.-pmf T) (A B E : pred T). -Lemma prE (nu : R.-distr T) (E : pred T) : +Lemma prE (nu : R.-pmf T) (E : pred T) : (\P_[nu] E)%:E = \esum_(t in [set: T]) ((E t)%:R * nu t)%:E. Proof. rewrite /pr fineK// esum_abse//. @@ -1466,7 +1466,7 @@ move=> c0 a0; rewrite -esumZ. - by apply: eq_esum => i _; rewrite EFinM. Qed. -Lemma pr_dlet E f (mu : R.-distr U) : +Lemma pr_dlet E f (mu : R.-pmf U) : \P_[dlet f mu] E = \E_[mu] (fun x => \P_[f x] E). Proof. rewrite /pr /esp. @@ -1482,7 +1482,7 @@ rewrite EFinM prE muleC -EFin_esumZ //. by apply: eq_esum => t _; rewrite mulrCA. Qed. -Lemma pr_dmargin E f (mu : R.-distr U) : +Lemma pr_dmargin E f (mu : R.-pmf U) : \P_[dmargin f mu] E = \P_[mu] [pred x | f x \in E]. Proof. by rewrite /dmargin pr_dlet pr_exp; apply/eq_exp=> x _; rewrite pr_dunit. @@ -1607,7 +1607,7 @@ rewrite -natrD; congr (_ %:R). by case: (A x); case: (B x). Qed. -Lemma pr_or_indep (A B : pred T) (mu : R.-distr T) : +Lemma pr_or_indep (A B : pred T) (mu : R.-pmf T) : (forall x, x \in A -> x \notin B) -> \P_[mu] [predU A & B] = \P_[mu] A + \P_[mu] B. Proof. @@ -1700,7 +1700,7 @@ move=> x mux; move/pr_eq0: zPB' => /(_ x) h; rewrite !inE. by apply/negP=> /andP[_ /h] /dinsuppP. Qed. -Lemma prc_pred1 (mu : R.-distr T) x A : +Lemma prc_pred1 (mu : R.-pmf T) x A : prc mu (pred1 x) A = (A x)%:R * mu x / \P_[mu] A. Proof. rewrite /prc; congr (_ / _); rewrite /pr. @@ -1797,19 +1797,19 @@ move=> ge0M bd; apply/(@le_trans _ _ (\E_[mu] (fun _ => M))). by rewrite exp_cst ler_piMl // le1_pr. Qed. -Lemma ge0_esp {V : choiceType} (eta : R.-distr V) (g : V -> R) : +Lemma ge0_esp {V : choiceType} (eta : R.-pmf V) (g : V -> R) : (forall y, 0 <= g y) -> 0 <= \E_[eta] g. Proof. move=> g0; rewrite /esp; apply: fine_ge0; apply: esum_ge0 => x ?. by rewrite lee_fin mulr_ge0//; exact: g0. Qed. -Lemma exp_dlet_ge0 (mu : R.-distr T) (nu : T -> R.-distr U) (g : U -> R) : +Lemma exp_dlet_ge0 (mu : R.-pmf T) (nu : T -> R.-pmf U) (g : U -> R) : (forall y, 0 <= g y) -> (forall eta, \E?_[eta] g) -> \E_[dlet nu mu] g = \E_[mu] (fun x => \E_[nu x] g). Proof. by move=> g0 sg; rewrite espE (eexp_dlet_esp mu nu g0 sg) -espE. Qed. -Lemma has_esp_le {V:choiceType} (mu : R.-distr V) (k h : V -> R) : +Lemma has_esp_le {V:choiceType} (mu : R.-pmf V) (k h : V -> R) : (forall x, `|k x| <= `|h x|) -> \E?_[mu] h -> \E?_[mu] k. Proof. move=> kh; rewrite /has_esp => fh. @@ -1820,7 +1820,7 @@ apply: le_esum. by move => ??; rewrite lee_fin !normrM ler_wpM2r. Qed. -Lemma hcomp (mu : R.-distr T) (nu : T -> R.-distr U) (g : U -> R) : +Lemma hcomp (mu : R.-pmf T) (nu : T -> R.-pmf U) (g : U -> R) : (forall y, 0 <= g y) -> (forall eta, \E?_[eta] g) -> \E?_[mu] (fun x => \E_[nu x] g). Proof. move=> g0 sg. @@ -1833,7 +1833,7 @@ rewrite -espeEFin -(eexp_dlet_esp mu nu g0 sg) espeEFin. exact: (esummable_esum_fin_num (sg (dlet nu mu))). Qed. -Lemma expB {V: choiceType} (f g : V -> R) (eta : R.-distr V) : +Lemma expB {V: choiceType} (f g : V -> R) (eta : R.-pmf V) : \E?_[eta] f -> \E?_[eta] g -> \E_[eta] (f \- g) = \E_[eta] f - \E_[eta] g. Proof. move=> sf sg. @@ -1846,7 +1846,7 @@ rewrite {1}(eexp_eq (g:=fun x => ((f x)%:E - (g x)%:E))%E). exact : eexpB. Qed. -Lemma exp_dlet mu (nu : T -> R.-distr U ) F : +Lemma exp_dlet mu (nu : T -> R.-pmf U ) F : (forall eta, \E?_[eta] F) -> \E_[dlet nu mu] F = \E_[mu] (fun x => \E_[nu x] F). Proof. @@ -1872,7 +1872,7 @@ Section mono_esum. Context {R : realType} {T : choiceType} - {f : nat -> R.-distr T}. + {f : nat -> R.-pmf T}. Hypothesis ndf : nd f. @@ -1947,7 +1947,7 @@ Qed. End mono_esum. (* -------------------------------------------------------------------- *) -Lemma distr_eqP {R : realType} {T : choiceType} (f1 f2 : R.-distr T): +Lemma distr_eqP {R : realType} {T : choiceType} (f1 f2 : R.-pmf T): f1 =1 f2 <-> f1 = f2. Proof. split=> [|->] //. From ac8f41b0c60be8195068626ec832e587bae56726 Mon Sep 17 00:00:00 2001 From: Reynald Affeldt Date: Wed, 21 Oct 2026 23:56:28 +0900 Subject: [PATCH 08/18] fix CI error (not compilting with 9.2) `esp` -> `expectation` (was `esp` from French's "esperance"?) `\E_[...] ...` was not used systematically `mu_ge0` -> `subpmf_ge0` (since `mu` is the name of a bound variable) has_esp -> has_expectatione --- theories/probability_theory/counting_distr.v | 331 +++++++++---------- 1 file changed, 152 insertions(+), 179 deletions(-) diff --git a/theories/probability_theory/counting_distr.v b/theories/probability_theory/counting_distr.v index bb3d779de4..146c09da95 100644 --- a/theories/probability_theory/counting_distr.v +++ b/theories/probability_theory/counting_distr.v @@ -1,7 +1,7 @@ From HB Require Import structures. From mathcomp Require Import boot order algebra. -From mathcomp.classical Require Import boolp classical_sets mathcomp_compat. -From mathcomp Require Import xfinmap constructive_ereal reals discrete. +From mathcomp Require Import boolp classical_sets functions. +From mathcomp Require Import constructive_ereal reals discrete. From mathcomp Require Import esum ereal. From mathcomp Require Import cardinality fsbigop topology normedtype sequences. From mathcomp Require Import unstable. @@ -12,11 +12,14 @@ From mathcomp Require Import numfun. (**md**************************************************************************) (* # Subprobability mass function *) (* *) +(* `SubPmf T R` *) +(* : subprobability mass function for choicetype `T` with values in `R` *) +(* *) +(* `isSubpmf` *) +(* : interface for functions that satisfy the property of subprobability mass *) +(* : function *) +(* *) (* ``` *) -(* Subpmf T R == subprobability mass function for choicetype T with *) -(* values in R *) -(* isSubpmf == interface for functions that satisfy the *) -(* property of Subprobability mass function. *) (* dnull == the zero distribution (null distribution) *) (* dunit == degenerate distribution *) (* dlet == monadic bind for distribution *) @@ -61,35 +64,36 @@ Reserved Notation "\Ee_[ mu ] f" (at level 2, format "\Ee_[ mu ] f"). Local Notation "\`| f |" := (fun x => `|f x|) (at level 2). -(* -------------------------------------------------------------------- *) +HB.mixin Record isSubPmf {R : realType} {T : choiceType} (mu : T -> R) := { + subpmf_ge0 : forall x, 0 <= mu x ; + subpmf_summable : esummable [set: T] (EFin \o mu); + subpmf_sum_le1 : (esum [set: T] (EFin \o mu) <= 1)%E }. -HB.mixin Record issubpmf (R : realType) (T : choiceType) (mu : T -> R) := - { - mu_ge0 : forall x, 0 <= mu x ; - mu_summable : esummable [set: T] (EFin \o mu); - mu_sum_le1 : (esum [set: T] (EFin \o mu) <= 1)%E; - }. +HB.structure Definition SubPmf {R : realType} {T : choiceType} := + {f of @isSubPmf R T f}. -HB.structure Definition subpmf (R : realType) (T : choiceType) := - {f of @issubpmf R T f}. +Arguments subpmf_ge0 {R T} _. +Arguments subpmf_sum_le1 {R T} _. -Notation "R .-pmf T" := (@subpmf.type R T) - (at level 0, T at level 2, format "R .-pmf T ") - : type_scope. +Notation "R .-pmf T" := (@SubPmf.type R T) + (at level 1, T at level 2, format "R .-pmf T ") : type_scope. -#[global] Hint Extern 0 (is_true (0 <= _)) => solve [apply: mu_ge0] : core. -#[global] Hint Resolve mu_sum_le1 mu_summable : core. +#[global] Hint Extern 0 (is_true (0 <= _)) => solve [apply: subpmf_ge0] : core. +#[global] Hint Resolve subpmf_summable : core. + +Lemma subpmf_le1 {R : realType} {T : choiceType} (mu : R.-pmf T) x : mu x <= 1. +Proof. +rewrite -lee_fin; apply: le_trans; last exact: subpmf_sum_le1 mu. +by rewrite esum_ge1// => ? _; rewrite lee_fin. +Qed. -(* -------------------------------------------------------------------- *) Section StdDefs. Context {R : realType} (T : choiceType). - Implicit Types (mu : R.-pmf T) (A B E : pred T) (f : T -> R). Definition dinsupp mu := fun x => mu x != 0 :> R. -Lemma in_dinsupp x (mu : R.-pmf T) : - (x \in dinsupp mu) = (mu x != 0). +Lemma in_dinsupp x (mu : R.-pmf T) : (x \in dinsupp mu) = (mu x != 0). Proof. by []. Qed. Lemma dinsuppP mu x : reflect (mu x <> 0) (x \in dinsupp mu). @@ -98,58 +102,50 @@ Proof. by apply: (iffP idP) => /eqP. Qed. Lemma dinsuppPn mu x : reflect (mu x = 0) (x \notin dinsupp mu). Proof. by rewrite -topredE /dinsupp /= negbK; apply/eqP. Qed. -Definition pr mu E := fine (esum [set: T] (EFin \o (fun x => (E x)%:R * mu x))). -Definition prc mu E A := pr mu [predI E & A] / pr mu A. -Definition esp mu f := fine (esum [set: T] (EFin \o (fun x => f x * mu x))). -Definition espc mu f A := fine (esum [set: T] (EFin \o (fun x => f x * prc mu (pred1 x) A))). +Definition pr mu E := fine (\esum_(x in [set: T]) ((E x)%:R * mu x)%:E). +Definition prc mu E A := pr mu [predI E & A] / pr mu A. +Definition expectation_pmf mu f := fine (\esum_(x in [set: T]) (f x * mu x)%:E). +Definition espc mu f A := fine (\esum_(x in [set: T]) (f x * prc mu (pred1 x) A)%:E). -Definition has_esp mu f := esummable [set: T] (EFin \o (fun x => f x * mu x)). +Definition has_expectation_pmf mu f := esummable [set: T] (EFin \o (f \* mu)). End StdDefs. Notation "\P_[ mu ] E" := (pr mu E). Notation "\P_[ mu , A ] E" := (prc mu E A). -Notation "\E_[ mu ] f" := (esp mu f). +Notation "\E_[ mu ] f" := (expectation_pmf mu f). Notation "\E_[ mu , A ] f" := (espc mu f A). -Notation "\E?_[ mu ] f" := (has_esp mu f). +Notation "\E?_[ mu ] f" := (has_expectation_pmf mu f). Notation dweight mu := (\P_[mu] predT). -(* -------------------------------------------------------------------- *) -HB.factory Record isSubpmf {R : realType} {T : choiceType} (mu : T -> R) := { - distr_pos: (forall x, 0 <= mu x); - distr_lee_one: (forall J, uniq J -> \sum_(j <- J) mu j <= 1) - }. +HB.factory Record uniq_isSubPmf {R : realType} {T : choiceType} (mu : T -> R) := { + subpmf_ge0 : forall x, 0 <= mu x ; + uniq_subpmf_le1 : forall J, uniq J -> \sum_(j <- J) mu j <= 1 }. -HB.builders - Context {R : realType} {T : choiceType} (mu : T -> R) - (isd : @isSubpmf R T mu). +HB.builders Context {R : realType} {T : choiceType} (mu : T -> R) + of @uniq_isSubPmf R T mu. -Local Lemma isd1 : forall x, 0 <= mu x. -Proof. by case: isd. Qed. +Local Lemma pmf_ge0 x : 0 <= mu x. +Proof. exact: subpmf_ge0. Qed. -Local Lemma isd2 : esummable [set: T] (EFin \o mu). +Local Lemma pmf_summable : esummable [set: T] (EFin \o mu). Proof. -case isd => ? h2. -rewrite /esummable (@le_lt_trans _ _ 1%:E) ?ltey//. -rewrite ge0_esum //. -+ by move => ? _;rewrite lee_fin. +rewrite /esummable (@le_lt_trans _ _ 1%:E) ?ltey// ge0_esum//. + by move => ? _; rewrite lee_fin. rewrite ge_ereal_sup//= => _ [X [finX _]] <-. -rewrite fsumEFin // lee_fin fsbig_finite //=. -rewrite (eq_bigr (fun x => mu x)). -+ by move => ??; rewrite ger0_norm. -by apply: h2. +rewrite fsumEFin// lee_fin fsbig_finite//=. +rewrite (eq_bigr mu) ?uniq_subpmf_le1//. +by move => ? _; rewrite ger0_norm// subpmf_ge0. Qed. -Local Lemma isd3 : (esum [set: T] (EFin \o mu) <= 1)%E. +Local Lemma pmf_le1 : (esum [set: T] (EFin \o mu) <= 1)%E. Proof. -case isd => ? h2. rewrite ge0_esum. -+ by move => ? _;rewrite lee_fin. + by move => ? _; rewrite lee_fin subpmf_ge0. rewrite ge_ereal_sup//= => _ [X [finX _]] <-. -rewrite fsumEFin // lee_fin fsbig_finite //=. -by apply: h2. +by rewrite fsumEFin// lee_fin fsbig_finite//= uniq_subpmf_le1. Qed. -HB.instance Definition _ := @issubpmf.Build R T mu isd1 isd2 isd3. +HB.instance Definition _ := @isSubPmf.Build R T mu pmf_ge0 pmf_summable pmf_le1. HB.end. @@ -165,16 +161,6 @@ split=> -[ ge0_mu le1]; split=> //. by rewrite [X in _<=X](bigID (mem J)) /= lerDl sumr_ge0. Qed. -Lemma le1_mu1 - {R : realType} {T : choiceType} (mu : R.-pmf T) x : mu x <= 1. -Proof. -case mu => //= {}mu [[?]]. -rewrite esummableE => ??. -rewrite -lee_fin. -apply/(@le_trans _ _ ((esum [set: T] (EFin \o mu))))=> //. -rewrite esum_ge1 //. -by move => ? _;rewrite lee_fin. -Qed. (* -------------------------------------------------------------------- *) Section DistrD. @@ -186,7 +172,7 @@ Lemma isd_mnull : sub_distr dnull_fun. Proof. by split=> // J _; rewrite big1 ?ler01. Qed. HB.instance Definition _ := - @isSubpmf.Build R T dnull_fun (proj1 isd_mnull) (proj2 isd_mnull). + @uniq_isSubPmf.Build R T dnull_fun (proj1 isd_mnull) (proj2 isd_mnull). Definition dnull := @locked R.-pmf T dnull_fun. @@ -198,7 +184,7 @@ End DistrD. (* -------------------------------------------------------------------- *) Lemma lef_dnull {R : realType} {T : choiceType} (mu : R.-pmf T) : dnull <=1 mu. -Proof. by move=> x; rewrite dnullE mu_ge0. Qed. +Proof. by move=> x; rewrite dnullE. Qed. (* -------------------------------------------------------------------- *) Section Restr. @@ -214,7 +200,7 @@ move=> eqJ; apply/(@le_trans _ _ (\sum_(j <- J) `|mu j|)). + apply/ler_sum=> i _; rewrite /drestr_fun; case: ifPn=> _. by apply/ler_norm. by apply/normr_ge0. + rewrite -lee_fin. - apply/(le_trans _ (@mu_sum_le1 _ _ mu)). + apply/(le_trans _ (subpmf_sum_le1 mu)). case mu => //= {}mu [[?]]; rewrite esummableE => ? _. rewrite (@eq_esum _ _ _ _ (fun y : T => `|(EFin \o mu) y|%E)) //=. + by move => ??; rewrite ger0_norm. @@ -222,7 +208,7 @@ move=> eqJ; apply/(@le_trans _ _ (\sum_(j <- J) `|mu j|)). Qed. HB.instance Definition _ (mu : R.-pmf T) := - @isSubpmf.Build R T (drestr_fun mu) (proj1 (isd_drestr mu)) (proj2 (isd_drestr mu)). + @uniq_isSubPmf.Build R T (drestr_fun mu) (proj1 (isd_drestr mu)) (proj2 (isd_drestr mu)). Definition drestr (mu : R.-pmf T) := @locked R.-pmf T (drestr_fun mu). @@ -305,7 +291,7 @@ Lemma isd_drat s : sub_distr (drat_fun s). Proof. by split; [apply/ge0_drat | apply/has_sup_drat]. Qed. HB.instance Definition _ (s : seq T) := - @isSubpmf.Build R T (drat_fun s) (proj1 (isd_drat s)) (proj2 (isd_drat s)). + @uniq_isSubPmf.Build R T (drat_fun s) (proj1 (isd_drat s)) (proj2 (isd_drat s)). Definition drat (s : seq T) := @locked R.-pmf T (drat_fun s). @@ -352,7 +338,7 @@ Proof. apply/isdistr_finP; split=> [b|]. Qed. HB.instance Definition _ (xt : R) := - @isSubpmf.Build R _ (dflip_fun xt) (proj1 (isd_dflip xt)) (proj2 (isd_dflip xt)). + @uniq_isSubPmf.Build R _ (dflip_fun xt) (proj1 (isd_dflip xt)) (proj2 (isd_dflip xt)). Definition dflip (xt : R) := @locked R.-pmf bool (dflip_fun xt). @@ -385,18 +371,18 @@ split=> [x|J uqJ]. apply /le_trans. + apply sum_esum_ge => // x. exact: dlet_pos. - apply/(le_trans _ (@mu_sum_le1 _ _ mu)). + apply/(le_trans _ (subpmf_sum_le1 mu)). apply/(le_trans (le_esum_fine _ _ hpos)). rewrite exchange_esum // le_esum // => i ?. under eq_esum do rewrite EFinM. rewrite esumZ // ?lee_tofin // => [? |]; rewrite ?lee_tofin //=. - rewrite muleC gee_pMl // ?lee_tofin //;last first. exact : (@mu_sum_le1 _ _ (f i)). + rewrite muleC gee_pMl // ?lee_tofin //;last exact: subpmf_sum_le1. rewrite (eq_esum _ _ (fun x => `|(EFin \o f i) x|%E)) //. + by move => ??; rewrite gee0_abs //= lee_tofin. - by have := (@mu_summable _ _ (f i)); rewrite esummableE. + by rewrite -esummableE. Qed. -HB.instance Definition _ := @isSubpmf.Build R U dlet_fun (proj1 isd_dlet) (proj2 isd_dlet). +HB.instance Definition _ := @uniq_isSubPmf.Build R U dlet_fun (proj1 isd_dlet) (proj2 isd_dlet). Definition dlet := @locked R.-pmf U dlet_fun. @@ -428,7 +414,7 @@ under eq_esum do rewrite EFinM. apply: esummableMr => //. + exists 1%E => // => i. case /andP: (h i) => ?? ; rewrite lee_tofin // ger0_norm //. -exact : (@mu_summable _ _ mu). +exact: subpmf_summable. Qed. (* -------------------------------------------------------------------- *) @@ -482,7 +468,7 @@ Qed. Lemma summable_dlet (f : T -> R.-pmf U) (mu : R.-pmf T) y : esummable [set: T] (fun x : T => EFin (mu x * (f x) y)). -Proof. by apply/summable_mu_wgtd=> x; rewrite mu_ge0 le1_mu1. Qed. +Proof. by apply/summable_mu_wgtd=> x; rewrite subpmf_ge0 subpmf_le1. Qed. Lemma fin_esum (f : T -> R.-pmf U) (mu : R.-pmf T) y: \esum_(x' in [set: T]) (mu x' * f x' y)%:E \is a fin_num. @@ -531,7 +517,7 @@ rewrite esumZ ?lee_tofin //= => [?| ]; rewrite ?lee_tofin //. rewrite fineM => //=;last first. + rewrite mulrC. symmetry. by under eq_esum do rewrite mul1r. -by rewrite esum_abse //; have := (@mu_summable _ _ mu); rewrite esummableE. +by rewrite esum_abse// -esummableE subpmf_summable. Qed. Lemma dinsupp_dlet f mu y : @@ -660,8 +646,8 @@ Qed. Lemma le1_liminf f x : (limn_einf (fun n => (f n x)%:E) <= 1%:E)%E. Proof. rewrite limn_einf_lim; apply: lime_le; first exact: is_cvg_einfs. -apply: nearW => n; apply: (@le_trans _ _ ((f n x)%:E)); first exact: ge_einfs. -by rewrite lee_fin le1_mu1. +apply: nearW => n; apply: (@le_trans _ _ (f n x)%:E); first exact: ge_einfs. +by rewrite lee_fin subpmf_le1. Qed. Lemma fin_liminf f x : limn_einf (fun n => (f n x)%:E) \is a fin_num. @@ -707,12 +693,12 @@ rewrite (sumlim ndE finE); apply: lime_le. apply: nearW => n; apply: (@le_trans _ _ (\sum_(j <- J) (f n j)%:E)). by apply: lee_sum => j _; exact: ge_einfs. rewrite sumEFin. -apply: (@le_trans _ _ (esum [set: T] (EFin \o f n))); last exact: mu_sum_le1. +apply: le_trans (subpmf_sum_le1 (f n)). exact: sum_esum_ge. Qed. -HB.instance Definition _ f := @isSubpmf.Build R T (dlim_fun f) - (proj1 (isd_dlim f)) (proj2 (isd_dlim f)). +HB.instance Definition _ f := + @uniq_isSubPmf.Build R T (dlim_fun f) (proj1 (isd_dlim f)) (proj2 (isd_dlim f)). Definition dlim f := @locked R.-pmf T (dlim_fun f). @@ -772,8 +758,8 @@ Proof. by move=> x; rewrite !dlimE (limn_einf_shiftS (fun n => (f n x)%:E)). Qed Lemma dlim_lift f p : \dlim_(n) f (n + p)%N =1 dlim f. Proof. by move=> x; rewrite !dlimE (limn_einf_shift_new (fun n => (f n x)%:E) p). Qed. -Lemma ge0_dlim f : forall x, 0 <= dlim f x. -Proof. exact: mu_ge0. Qed. +Lemma ge0_dlim f x : 0 <= dlim f x. +Proof. by []. Qed. Lemma le1_dlim f : forall x, dlim f x <= 1. Proof. by move=> x; rewrite -lee_fin dlim_EFin; exact: le1_liminf. Qed. @@ -823,7 +809,7 @@ Proof. move=> c0. rewrite EFinM (dlim_sup hf) muleC. rewrite (@ge0_ereal_supZl_range R T (fun t n => (f n t)%:E)) //=. -+ by move=> t n; rewrite lee_fin; exact: mu_ge0. + by move=> t n; rewrite lee_fin. have -> : [set (c%:E * (f i x)%:E)%E | i in [set: nat]]%classic = [set (f i x * c)%:E | i in [set: nat]]%classic. @@ -842,8 +828,8 @@ have nd : nd (fun n => dlet h (f n)). rewrite dlet_EFin (dlim_sup nd). under eq_esum => x _ do rewrite (sup_mul ndf)//. rewrite (@exchange_esum_ereal_sup R T (fun x n => (f n x * h x y)%:E)) /=. -+ by move=> t n; rewrite lee_fin; apply: mulr_ge0; exact: mu_ge0. -+ move=> n m nm t; rewrite lee_fin; apply: ler_wpM2r; first exact: mu_ge0. ++ by move=> t n; rewrite lee_fin; exact: mulr_ge0. ++ move=> n m nm t; rewrite lee_fin ler_wpM2r//. by rewrite -lee_fin; exact: ndf. have -> : [set \esum_(x in [set: T]) (f i x * h x y)%:E | i in [set: nat]]%classic = @@ -874,8 +860,8 @@ move=> z; apply: EFin_inj. rewrite (dlim_sup nd2 ) dlet_EFin. under eq_esum => t _ do rewrite mulrC (sup_mul (nd1 t))//. rewrite (@exchange_esum_ereal_sup R T (fun t n => (f n t z * mu t)%:E)) /=. -+ by move=> t n; rewrite lee_fin; apply: mulr_ge0; exact: mu_ge0. -+ move=> n m nm t; rewrite lee_fin; apply: ler_wpM2r; first exact: mu_ge0. ++ by move=> t n; rewrite lee_fin; exact: mulr_ge0. ++ move=> n m nm t; rewrite lee_fin ler_wpM2r//. exact: hmono. have ->: [set ((\dlet_(i0 <- mu) f i i0) z)%:E | i in [set: nat]]%classic = @@ -1127,7 +1113,7 @@ Qed. Lemma summable_fst (mu : R.-pmf (T * U)%type) x : esummable [set:U] (fun y => (mu (x, y))%:E). Proof. -rewrite /esummable; apply: le_lt_trans (@mu_summable _ _ mu). +rewrite /esummable; apply: le_lt_trans (@subpmf_summable _ _ mu). rewrite -(reindex_esum [set:U] [set z : T * U | z.1 = x] (fun y => (x, y)) (fun z => (`|(mu z)%:E|)%E)). + split. @@ -1166,9 +1152,9 @@ Implicit Types (mu : R.-pmf T) (A B E : pred T). Lemma summable_pr E mu : esummable [set:T] (fun x => ((E x)%:R * mu x)%:E). Proof. -apply/(le_esummable (g := EFin \o mu)) => [x|]; last by apply/mu_summable. -rewrite !lee_tofin => //=. -+ by rewrite mulr_ge0. +apply/(le_esummable (g := EFin \o mu)) => [x _|//]. +rewrite !lee_tofin//=. + by rewrite mulr_ge0. by rewrite ler_piMl //= lern1 leq_b1. Qed. @@ -1190,7 +1176,7 @@ Proof. by []. Qed. Lemma pr_predT mu : \P_[mu] predT = fine (esum [set: T] (EFin \o mu)). Proof. -rewrite /pr /esp; congr fine. +rewrite /pr /expectation_pmf; congr fine. by apply/eq_esum=> x; rewrite mul1r. Qed. @@ -1205,7 +1191,7 @@ Qed. Lemma exp_dunit (f : T -> R) (x : T) : \E_[dunit x] f = f x. Proof. -rewrite /esp. +rewrite /expectation_pmf. rewrite (eq_esum _ _ (fun y : T => if x == y then (f y)%:E else 0)%E). + move => x0 /=; rewrite dunit1E. by case (x == x0) => //=; rewrite ?mulr1 ?mulr0. @@ -1227,13 +1213,12 @@ have [hc|hc|->] := comparable_ltgtP (comparableT r 0). by rewrite mul0e //= mulr0. Qed. -Lemma expZ mu f c : - (forall x, 0 <= f x) -> \E_[mu] (fun x => c * (f x)) = c * (\E_[mu] f). +Lemma expZ mu f c : (forall x, 0 <= f x) -> \E_[mu] (fun x => c * (f x)) = c * (\E_[mu] f). Proof. -move => h1; rewrite /esp. +move => h1; rewrite /expectation_pmf. under eq_esum => x do rewrite /= -mulrA EFinM. have hpos : forall x : T, (0%R <= (f x * mu x)%:E)%E. -+ by move=> x; rewrite lee_fin; apply: mulr_ge0; [exact: h1 | exact: mu_ge0]. ++ by move=> x; rewrite lee_fin; apply: mulr_ge0; [exact: h1|]. rewrite esumZ //=. have hsum : (0 <= \esum_(i in [set: T]) (f i * mu i)%:E)%E. + by apply esum_ge0 => ??. @@ -1250,24 +1235,20 @@ Qed. Lemma exp0 mu : \E_[mu] (fun _ => 0) = 0. Proof. by rewrite exp_cst mulr0. Qed. -Lemma has_expC mu c : \E?_[mu] (fun _ => c). +Lemma has_expectation_cst mu c : \E?_[mu] (cst c). Proof. -rewrite /has_esp. -have : esummable [set: T] (fun x : T => (c%:E * (mu x)%:E)%E). - by apply: esummableZl => //; exact: mu_summable. -apply/eq_esummable => x /=. -by rewrite EFinM. +have : esummable setT (fun x => c%:E * (mu x)%:E)%E. + by apply: esummableZl => //; exact: subpmf_summable. +by apply/eq_esummable => x /= _; rewrite EFinM. Qed. -Lemma has_exp0 mu : \E?_[mu] (fun _ => 0). -Proof. by apply/(has_expC mu 0). Qed. +Lemma has_exp0 mu : \E?_[mu] (cst 0). Proof. exact: has_expectation_cst. Qed. -Lemma has_exp1 mu : \E?_[mu] (fun _ => 1). -Proof. by apply/(has_expC mu 1). Qed. +Lemma has_exp1 mu : \E?_[mu] (cst 1). Proof. exact: has_expectation_cst. Qed. Lemma has_expZ mu c F : \E?_[mu] F -> \E?_[mu] (c \*o F). Proof. -move=> heF; rewrite /has_esp. +move=> heF; rewrite /has_expectation_pmf. have := esummableZl (f := EFin \o (fun x => F x * mu x)) (c := c%:E) erefl heF. apply/eq_esummable => x /=. by rewrite -EFinM mulrA. @@ -1301,7 +1282,7 @@ Proof. by move=> eq_AB; apply/eq_in_pr=> x _; apply/eq_AB. Qed. Lemma eq_exp mu (f1 f2 : T -> R): {in dinsupp mu, f1 =1 f2} -> \E_[mu] f1 = \E_[mu] f2. Proof. -move=> eq_f; rewrite /esp; congr fine. +move=> eq_f; rewrite /expectation_pmf; congr fine. apply/eq_esum => x /=. case/boolP: (x \in dinsupp mu). + by move/eq_f => ->. @@ -1316,60 +1297,52 @@ End PrCoreTheory. (* -------------------------------------------------------------------- *) Section Esp. Context {R : realType} {T : choiceType}. - Implicit Types (mu : R.-pmf T) (f : T -> \bar R). -Definition espe mu f := esum [set:T] (fun x => mule (f x) ((mu x)%:E)). +Definition eexpectation_pmf mu f := \esum_(x in [set:T]) (f x * (mu x)%:E)%E. -Notation "\Ee_[ mu ] f" := (espe mu f). End Esp. +Notation "\Ee_[ mu ] f" := (eexpectation_pmf mu f). + Section EspeCoreTheory. Context {R : realType} {T : choiceType}. - Implicit Types (mu : R.-pmf T) (A B E : pred T). -Lemma eexp_eq (f g: T -> \bar R) mu: - (f =1 g)%E -> - espe mu f = espe mu g. -Proof. -move => h; rewrite /espe. -apply eq_esum => ??. -by congr (_ * _)%E. -Qed. +Lemma eexp_eq (f g: T -> \bar R) mu : f =1 g -> \Ee_[mu] f = \Ee_[mu] g. +Proof. by move=> fg; apply: eq_esum => ? _; rewrite fg. Qed. -Lemma eexp_dunit (f : T -> \bar R) (x : T) : - espe (dunit x) f = f x. +Lemma eexp_dunit (f : T -> \bar R) (x : T) : \Ee_[dunit x] f = f x. Proof. -rewrite /espe. +rewrite /eexpectation_pmf. rewrite (eq_esum _ _ (fun y : T => if x == y then f y else 0%R)%E). + move => x0. rewrite dunit1E. by case (x == x0) => //=; rewrite ?mule1 ?mule0. by rewrite esum_if_eq_op_set1. Qed. -Lemma eexp_cst mu r : (espe mu (fun _ => r) = (\P_[mu] predT)%:E * r)%E. +Lemma eexp_cst mu r : (\Ee_[mu] (cst r) = (\P_[mu] predT)%:E * r)%E. Proof. -rewrite pr_predT /espe //. +rewrite pr_predT /eexpectation_pmf //. rewrite esumZ. - move => ?; rewrite lee_fin //. rewrite muleC; congr ( _ * _)%E. rewrite fineK //= esum_abse => //=. -by have := (@mu_summable _ _ mu); rewrite esummableE. +by have := @subpmf_summable _ _ mu; rewrite esummableE. Qed. -Lemma eexp0 mu : espe mu (fun _ => 0) = 0. +Lemma eexp0 mu : \Ee_[mu] (cst 0) = 0. Proof. by rewrite eexp_cst mule0. Qed. Lemma eexp_dlet {U: choiceType} mu (nu : T -> R.-pmf U) F : (forall x, 0%:E <= F x)%E -> -espe (dlet nu mu) F = espe mu (fun x => espe (nu x) F). + \Ee_[dlet nu mu] F = \Ee_[mu] (fun x => \Ee_[nu x] F). Proof. move => HF. have pos : (forall (i : T) (j : U), (0%R <= F j * ((mu i)%:E * (nu i j)%:E))%E). - move => i j; rewrite mule_ge0 //. by rewrite mule_ge0 // lee_tofin. -rewrite /espe {1}(eq_esum _ _ +rewrite /eexpectation_pmf {1}(eq_esum _ _ (fun x : U => (F x * esum [set:T] (fun y : T => (mu y * nu y x)%:E)))%E). - move => x ?; rewrite /= dletE. congr ( _ * _)%E. @@ -1377,15 +1350,14 @@ rewrite /espe {1}(eq_esum _ _ - by move => i; rewrite mulr_ge0. - have : esummable [set: T] (fun x0 : T => ((mu x0 * nu x0 x)%:E))%E. + apply/(le_esummable (g := EFin \o mu)) => //=. - by move => x0; rewrite !lee_fin //= mulr_ge0 //= ler_piMr //= le1_mu1. + by move => x0; rewrite !lee_fin //= mulr_ge0 //= ler_piMr //= subpmf_le1. by rewrite esummableE. symmetry. rewrite {1}(eq_esum _ _ (fun x : T => (esum [set:U] (fun x0 : U => F x0 * ((mu x)%:E * (nu x x0)%:E))%E))). - move => x ?; rewrite muleC. rewrite -esumZ. - - move => x1; rewrite mule_ge0 //=. - - exact: (@mu_ge0 _ _ (nu x) x1). + - by move => x1; rewrite mule_ge0// lee_fin. rewrite {1}(eq_esum _ _ (fun x0 : U => F x0 * ((mu x)%:E * (nu x x0)%:E))%E) // ?esum_sum' //. - by move => ??; rewrite muleCA. @@ -1396,9 +1368,11 @@ rewrite {1}(eq_esum _ _ by move => ?; rewrite mule_ge0 // lee_tofin. Qed. +Local Open Scope ereal_scope. + Lemma eexpZ mu F c : (forall x, 0%:E <= F x)%E -> - espe mu (fun x => mule c (F x)) = mule c (espe mu F). + \Ee_[mu] (fun x => c * F x) = c * \Ee_[mu] F. Proof. move => h. rewrite -esumZ. @@ -1410,34 +1384,34 @@ Lemma eexpB mu (A B : T -> \bar R) : (forall x, A x \is a fin_num) -> esummable [set: T] (fun x => (A x * (mu x)%:E)%E) -> esummable [set: T] (fun x => (B x * (mu x)%:E)%E) -> - espe mu (A \- B)%E = (espe mu A - espe mu B)%E. + \Ee_[mu] (A \- B)%E = (\Ee_[mu] A - \Ee_[mu] B)%E. Proof. -move=> fA sA sB; rewrite /espe. +move=> fA sA sB; rewrite /eexpectation_pmf. rewrite (esum.eq_esum _ _ (fun x => (A x * (mu x)%:E - B x * (mu x)%:E)%E)). by move => x ? /=; rewrite muleBl//; apply: fin_num_adde_defr; exact: fA. exact: (esummable_esumB sA sB). Qed. -Lemma espE mu (g : T -> R) : - esp mu g = fine (espe mu (EFin \o g)). +Lemma espE mu (g : T -> R) : + \E_[mu] g = fine (\Ee_[mu] (EFin \o g)). Proof. -by rewrite /esp /espe; congr (fine _); apply: esum.eq_esum => x ? /=; rewrite EFinM. +by rewrite /expectation_pmf /eexpectation_pmf; congr (fine _); apply: esum.eq_esum => x ? /=; rewrite EFinM. Qed. Lemma espeEFin mu (g : T -> R) : - espe mu (EFin \o g) = esum [set: T] (EFin \o (fun x => g x * mu x)). -Proof. by rewrite /espe; apply: esum.eq_esum => x ? /=; rewrite EFinM. Qed. + \Ee_[mu] (EFin \o g) = esum [set: T] (EFin \o (fun x => g x * mu x))%R. +Proof. by rewrite /eexpectation_pmf; apply: esum.eq_esum => x ? /=; rewrite EFinM. Qed. Lemma eexp_dlet_esp {U: choiceType} mu (nu : T -> R.-pmf U) (g : U -> R) : - (forall y, 0 <= g y) -> (forall eta, \E?_[eta] g) -> - espe (dlet nu mu) (EFin \o g) = espe mu (EFin \o (fun x => esp (nu x) g)). + (forall y, 0 <= g y)%R -> (forall eta, \E?_[eta] g) -> + \Ee_[dlet nu mu] (EFin \o g) = \Ee_[mu] (EFin \o (fun x => \E_[nu x] g)). Proof. move=> ? sg. rewrite (eexp_dlet mu nu ). + by move=> x; rewrite /= lee_fin. apply eq_esum => ?? //=. congr (_ * _)%E. -rewrite /esp fineK//. +rewrite /expectation_pmf fineK//. exact: (esummable_esum_fin_num (sg (nu _))). Qed. @@ -1469,13 +1443,13 @@ Qed. Lemma pr_dlet E f (mu : R.-pmf U) : \P_[dlet f mu] E = \E_[mu] (fun x => \P_[f x] E). Proof. -rewrite /pr /esp. +rewrite /pr /expectation_pmf. congr (fine _). rewrite {1}(eq_esum _ _ (fun t => \esum_(x in [set: U]) ((E t)%:R * (mu x * f x t))%:E)%E). + by move => t _; rewrite EFinM dlet_EFin EFin_esumZ // => ?; rewrite mulr_ge0. rewrite {1} exchange_esum//. + move=> t x;rewrite lee_fin. - by apply: mulr_ge0; [exact: ler0n|apply: mulr_ge0; exact: mu_ge0]. + by apply: mulr_ge0; [exact: ler0n|exact: mulr_ge0]. apply: eq_esum => x _ //=. rewrite EFinM prE muleC -EFin_esumZ //. + by move => ?; rewrite mulr_ge0. @@ -1517,16 +1491,16 @@ Qed. Lemma le1_pr A mu : \P_[mu] A <= 1. Proof. apply: (@le_trans _ _ \P_[mu] predT); first by apply/subset_pr. -rewrite pr_predT -fine1; apply: fine_le; [| by [] | exact: mu_sum_le1]. +rewrite pr_predT -fine1; apply: fine_le; [|by []|exact: subpmf_sum_le1]. rewrite ge0_fin_numE; last first. -+ apply: le_lt_trans; [exact: mu_sum_le1| by rewrite ltey]. -by apply: esum_ge0 => x _; rewrite lee_fin mu_ge0. + by apply: le_lt_trans; [exact: subpmf_sum_le1|rewrite ltey]. +by apply: esum_ge0 => x _; rewrite lee_fin. Qed. Lemma le_exp mu f1 f2: \E?_[mu] f1 -> \E?_[mu] f2 -> f1 <=1 f2 -> \E_[mu] f1 <= \E_[mu] f2. Proof. -move=> sm1 sm2 le_f; rewrite /esp; apply: fine_le. +move=> sm1 sm2 le_f; rewrite /expectation_pmf; apply: fine_le. - exact: (esummable_esum_fin_num sm1). - exact: (esummable_esum_fin_num sm2). - apply: le_esum. @@ -1554,7 +1528,7 @@ Proof. move=> h; rewrite -lee_fin !prE. apply: le_esum => x _; rewrite lee_fin. case/boolP: (x \in dinsupp nu) => [/h {}h|]; last first. - by move/dinsuppPn=> ->; rewrite mulr0; apply: mulr_ge0; [exact: ler0n|exact: mu_ge0]. + by move/dinsuppPn=> ->; rewrite mulr0; apply: mulr_ge0; [exact: ler0n|]. by case/boolP: (A x) => [/h|]; rewrite ?(mul0r, mul1r). Qed. @@ -1571,7 +1545,7 @@ Lemma prc_sum A mu : 0 < \P_[mu] A -> Proof. move=> gt0. have a0 : forall i, 0 <= (A i)%:R * mu i. - by move=> i; apply: mulr_ge0; [exact: ler0n|exact: mu_ge0]. + by move=> i; apply: mulr_ge0; [exact: ler0n|]. have hpr1 : forall x, \P_[mu] [predI pred1 x & A] = (A x)%:R * mu x. move=> x; rewrite /pr. rewrite (eq_esum _ _ ( fun y => if x == y then ((A y)%:R * mu y)%:E else 0)). @@ -1591,7 +1565,7 @@ move=> hE x xE. have hle : \P_[mu] (pred1 x) <= \P_[mu] E. by apply: subset_pr => y; rewrite !inE => /eqP ->. move: hle; rewrite hE -pr_pred1 => h. -by apply/eqP; rewrite eq_le h /=; exact: mu_ge0. +by apply/eqP; rewrite eq_le h /=. Qed. Lemma prID A B mu : @@ -1715,8 +1689,7 @@ Lemma summable_pr_f f mu (P : pred T): esummable [set: T] (EFin \o (fun x => (P x)%:R * (f x * mu x))). Proof. move=> sm; rewrite /esummable //= . -rewrite (eq_esum _ _ - (fun x => `|((P x)%:R)%:E * (f x * mu x)%:E|)%E). +rewrite (eq_esum _ _ (fun x => `|((P x)%:R)%:E * (f x * mu x)%:E|)%E). by move => i _ //; rewrite -abseM. apply: esummableMl; last exact: sm. exists 1%:E=> [x|]; last by []. @@ -1758,7 +1731,7 @@ Lemma exp_split A f mu : \E?_[mu] f -> \E_[mu] f = + \P_[mu] (predC A) * \E_[mu, predC A] f. Proof. move=> sm. -rewrite (pr_esp_sum A) // (pr_esp_sum (predC A)) // /esp -fineD ?sum_fin_num_mu_f//. +rewrite (pr_esp_sum A) // (pr_esp_sum (predC A)) // /expectation_pmf -fineD ?sum_fin_num_mu_f//. congr fine; rewrite -(esummable_esumD (summable_pr_f A sm) (summable_pr_f (predC A) sm)). apply: esum.eq_esum => x ? /=; rewrite -EFinD; congr (_ %:E). rewrite -mulrDl -[LHS]mul1r; congr (_ * _). @@ -1768,22 +1741,22 @@ Qed. Lemma bounded_has_exp mu F : (exists M, forall x, `|F x| <= M) -> \E?_[mu] F. Proof. -case=> M leM; rewrite /has_esp /esummable. +case=> M leM; rewrite /has_expectation_pmf /esummable. rewrite (eq_esum _ _ (fun x=> `|(F x)%:E * (mu x)%:E|)%E). move=> x _; rewrite -EFinM //=. -apply: esummableMl; last exact: mu_summable. +apply: esummableMl; last exact: subpmf_summable. exists M%:E => [x ?|]; last by []. by rewrite /= lee_fin; exact: leM x. Qed. Lemma summable_has_exp mu F : esummable [set: T] (EFin \o F) -> \E?_[mu] F. Proof. -move=> smF; rewrite /has_esp /esummable. +move=> smF; rewrite /has_expectation_pmf /esummable. rewrite (eq_esum _ _ (fun x=> `|(F x)%:E * (mu x)%:E|)%E). move=> x _; rewrite -EFinM //=. apply: esummableMr; last exact: smF. exists 1%:E => [x ?|]; last by []. -by rewrite /= lee_fin (ger0_norm (@mu_ge0 _ _ mu x)); exact: le1_mu1. +by rewrite /= lee_fin ger0_norm// subpmf_le1. Qed. Lemma exp_le_bd mu F (M : R) : @@ -1792,15 +1765,15 @@ Proof. move=> ge0M bd; apply/(@le_trans _ _ (\E_[mu] (fun _ => M))). + apply/le_exp. + by apply/bounded_has_exp; exists M. - + by apply/has_expC. + + exact/has_expectation_cst. + by move=> x; apply/(le_trans _ (bd x))/ler_norm. by rewrite exp_cst ler_piMl // le1_pr. Qed. -Lemma ge0_esp {V : choiceType} (eta : R.-pmf V) (g : V -> R) : +Lemma ge0_expectation {V : choiceType} (eta : R.-pmf V) (g : V -> R) : (forall y, 0 <= g y) -> 0 <= \E_[eta] g. Proof. -move=> g0; rewrite /esp; apply: fine_ge0; apply: esum_ge0 => x ?. +move=> g0; rewrite /expectation_pmf; apply: fine_ge0; apply: esum_ge0 => x ?. by rewrite lee_fin mulr_ge0//; exact: g0. Qed. @@ -1809,10 +1782,10 @@ Lemma exp_dlet_ge0 (mu : R.-pmf T) (nu : T -> R.-pmf U) (g : U -> R) : \E_[dlet nu mu] g = \E_[mu] (fun x => \E_[nu x] g). Proof. by move=> g0 sg; rewrite espE (eexp_dlet_esp mu nu g0 sg) -espE. Qed. -Lemma has_esp_le {V:choiceType} (mu : R.-pmf V) (k h : V -> R) : +Lemma has_expectation_le {V:choiceType} (mu : R.-pmf V) (k h : V -> R) : (forall x, `|k x| <= `|h x|) -> \E?_[mu] h -> \E?_[mu] k. Proof. -move=> kh; rewrite /has_esp => fh. +move=> kh; rewrite /has_expectation_pmf => fh. rewrite esummableE ge0_fin_numE. + apply: esum_ge0 => i _; exact: abse_ge0. apply: (le_lt_trans _ fh). @@ -1824,10 +1797,10 @@ Lemma hcomp (mu : R.-pmf T) (nu : T -> R.-pmf U) (g : U -> R) : (forall y, 0 <= g y) -> (forall eta, \E?_[eta] g) -> \E?_[mu] (fun x => \E_[nu x] g). Proof. move=> g0 sg. -have hge0 : forall x, 0 <= esp (nu x) g * mu x. - by move=> x; apply: mulr_ge0; [exact: ge0_esp | exact: mu_ge0]. -rewrite /has_esp esummableE. -rewrite (esum.eq_esum _ _ (EFin \o (fun x => esp (nu x) g * mu x))). +have hge0 : forall x, 0 <= \E_[nu x] g * mu x. + by move=> x; apply: mulr_ge0; [exact: ge0_expectation |]. +rewrite /has_expectation_pmf esummableE. +rewrite (esum.eq_esum _ _ (EFin \o (fun x => \E_[nu x] g * mu x))). + move=> x _ /=; rewrite ger0_norm //. rewrite -espeEFin -(eexp_dlet_esp mu nu g0 sg) espeEFin. exact: (esummable_esum_fin_num (sg (dlet nu mu))). @@ -1841,7 +1814,7 @@ rewrite !espE -fineB //. + by rewrite espeEFin; exact: (esummable_esum_fin_num sf). + by rewrite espeEFin; exact: (esummable_esum_fin_num sg). congr (fine _). -rewrite {1}(eexp_eq (g:=fun x => ((f x)%:E - (g x)%:E))%E). +rewrite {1}(@eexp_eq _ _ _ (fun x => (f x)%:E - (g x)%:E)%E). + move => ?. rewrite -EFinB //. exact : eexpB. Qed. @@ -1852,13 +1825,13 @@ Lemma exp_dlet mu (nu : T -> R.-pmf U ) F : Proof. move=> sF. have spF : forall eta, \E?_[eta] F^\+. -+ by move=> eta //=; apply: (has_esp_le (le_funrpos F) (sF eta)). ++ by move=> eta //=; apply: (has_expectation_le (le_funrpos F) (sF eta)). have snF : forall eta, \E?_[eta] F^\-. -+ by move=> eta; apply: (has_esp_le (le_funrneg F) (sF eta)). ++ by move=> eta; apply: (has_expectation_le (le_funrneg F) (sF eta)). transitivity (\E_[mu] (fun x => \E_[nu x] F^\+) - \E_[mu] (fun x => \E_[nu x] F^\-)). rewrite -(exp_dlet_ge0 mu nu _ spF) // -(exp_dlet_ge0 mu nu _ snF) //. -rewrite -(expB (spF _) (snF _)); congr (\E_[dlet nu mu] _); symmetry; exact :funrposBneg. +rewrite -(expB (spF _) (snF _)); congr (\E_[dlet nu mu] _); exact/esym/funrposBneg. rewrite -(expB (hcomp mu nu _ spF) (hcomp mu nu _ snF)) //. apply: eq_exp => x _ /=. rewrite -(expB (spF _) (snF _)). @@ -1936,11 +1909,11 @@ transitivity (ereal_sup (range (fun n => esum [set:T] (fun x : T => ((E x)%:R * f n x)%:E)))); last first. by apply: sup_range_lim => n m nm; apply: le_esum => x _; exact: (hmono n m nm x). rewrite -(@exchange_esum_ereal_sup R T (fun x n => ((E x)%:R * f n x)%:E)) //. -+ by move=> x n; rewrite lee_fin; apply: mulr_ge0; [exact: ler0n | exact: mu_ge0]. ++ by move=> x n; rewrite lee_fin; apply: mulr_ge0; [exact: ler0n |]. + move => x n m nm. exact: (hmono n m nm x). apply: eq_esum => x _. rewrite EFinM distr_lub_sup (@ge0_ereal_supZl_range R T (fun a b => (f b a)%:E)) //. -+ by move=> t n; rewrite lee_fin; exact: mu_ge0. ++ by move=> t n; rewrite lee_fin. + by rewrite lee_tofin. Qed. From d3ba11e16dea367812b60ae8d73c0e8f746df273 Mon Sep 17 00:00:00 2001 From: Lionel Blatter Date: Wed, 29 Jul 2026 22:26:12 +0200 Subject: [PATCH 09/18] Proof that Subprobability mass function have a subprobability measure. Connection between subprobability mass function, expectation, pmf and distribution. --- _CoqProject | 2 + classical/classical_sets.v | 3 + theories/esum_counting.v | 289 +++++++++++++++++++++++++++++++++++++ 3 files changed, 294 insertions(+) create mode 100644 theories/esum_counting.v diff --git a/_CoqProject b/_CoqProject index 8e1c0e06e3..d370bcaeb6 100644 --- a/_CoqProject +++ b/_CoqProject @@ -165,5 +165,7 @@ theories/all_analysis.v theories/showcase/summability.v theories/showcase/pnt.v +theories/esum_counting.v + analysis_stdlib/Rstruct_topology.v analysis_stdlib/showcase/uniform_bigO.v diff --git a/classical/classical_sets.v b/classical/classical_sets.v index 8dac69ec78..d844f919e8 100644 --- a/classical/classical_sets.v +++ b/classical/classical_sets.v @@ -2229,6 +2229,9 @@ End bigop_lemmas. Arguments bigcup_setD1 {T I} x. Arguments bigcap_setD1 {T I} x. +Lemma bigcup_id {T: Type} (P: set T) : \bigcup_(i in P) [set i] = P. +Proof. by rewrite bigcup_imset1 // image_id. Qed. + Lemma setD_bigcup {T} (I : eqType) (F : I -> set T) (P : set I) (j : I) : P j -> F j `\` \bigcup_(i in [set k | P k /\ k != j]) (F j `\` F i) = \bigcap_(i in P) F i. diff --git a/theories/esum_counting.v b/theories/esum_counting.v new file mode 100644 index 0000000000..36a0e7bce5 --- /dev/null +++ b/theories/esum_counting.v @@ -0,0 +1,289 @@ +From HB Require Import structures. +From mathcomp Require Import boot order algebra. +From mathcomp.classical Require Import boolp classical_sets mathcomp_extra functions. +From mathcomp Require Import xfinmap constructive_ereal reals discrete. +From mathcomp Require Import realseq realsum. +From mathcomp Require Import topology esum sequences normedtype ereal. +From mathcomp Require Import cardinality fsbigop. +From mathcomp Require Import numfun measurable_realfun. +From mathcomp Require Import measure lebesgue_measure lebesgue_integral. +From mathcomp Require Import counting_distr. +From mathcomp Require Import random_variable. + +Set Implicit Arguments. +Unset Strict Implicit. +Unset Printing Implicit Defensive. + +Import Order.TTheory GRing.Theory Num.Theory. + +Local Open Scope ring_scope. +Local Notation simpm := Monoid.simpm. +Local Open Scope classical_set_scope. +Local Open Scope ereal_scope. + +Import HBNNSimple. +Import MeasurableR. + +(* -------------------------------------------------------------------- *) +Definition discrete_measurable_space (T : choiceType) : Type := T. + +HB.instance Definition _ (T : choiceType) := + Choice.on (discrete_measurable_space T). + +HB.instance Definition _ (T : choiceType) := @isMeasurable.Build + default_measure_display + (discrete_measurable_space T) discrete_measurable discrete_measurable0 + discrete_measurableC discrete_measurableU. + +Lemma esum_setT_discrete {R : realType} (T : choiceType) (f : T -> \bar R) : + (\esum_(x in [set: discrete_measurable_space T]) f x + = \esum_(x in [set: T]) f x)%E. +Proof. +by apply: (@reindex_esum R T (discrete_measurable_space T) + [set: T] [set: discrete_measurable_space T] id f); split. +Qed. + +(* -------------------------------------------------------------------- *) +Section SubProbability_measure_subpmf. +Context (R : realType) (T : choiceType) (mu : R.-pmf T). + +Definition measure_of_pmf (S : set (discrete_measurable_space T)) := + \esum_(x in S) (EFin \o mu) x. + +Let P0 : measure_of_pmf set0 = 0%E. +Proof. by rewrite /measure_of_pmf esum_set0. Qed. + +Let P_ge0 (S : set (discrete_measurable_space T)) : (0 <= measure_of_pmf S)%E. +Proof. by apply: esum_ge0 => x _; rewrite lee_fin. Qed. + +Let P_sigma_additive : semi_sigma_additive measure_of_pmf. +Proof. +move=> F _ tF _. +have -> : measure_of_pmf (\bigcup_n F n) = (\sum_(i n; exact: P_ge0. + apply: esum_bigcup => //=. + + by apply: (sub_trivIset (@subsetT _ _) tF). + + by move=> x; rewrite lee_fin. +apply: cvg_toP => //. +apply: is_cvg_nneseries => n _ _; rewrite /measure_of_pmf. +by apply: esum_ge0 => x _; rewrite lee_fin. +Qed. + +HB.instance Definition _ := isMeasure.Build _ _ _ measure_of_pmf + P0 P_ge0 P_sigma_additive. + +Let P_setT : (measure_of_pmf [set: discrete_measurable_space T] <= 1)%E. +Proof. by rewrite /measure_of_pmf esum_setT_discrete; exact: subpmf_sum_le1. Qed. + +HB.instance Definition _ := + @Measure_isSubProbability.Build _ _ R measure_of_pmf P_setT. + +End SubProbability_measure_subpmf. + +(* -------------------------------------------------------------------- *) +Section maxe. +Context (R : realType) (T : choiceType) (mu : R.-pmf T). + +Lemma maxe_pmfM (a : \bar R) x : + (maxe (a * (mu x)%:E) 0 = maxe a 0 * (mu x)%:E)%E. +Proof. +rewrite [in LHS]muleC [in RHS]muleC maxe_pMr => //=. +- by rewrite lee_fin. +- by rewrite mule0. +Qed. + +Lemma maxeN_pmfM (a : \bar R) x : + (maxe (- (a * (mu x)%:E)) 0 = maxe (- a) 0 * (mu x)%:E)%E. +Proof. by rewrite -mulNe maxe_pmfM. Qed. + +End maxe. + +(* -------------------------------------------------------------------- *) +Section Expectation. +Context (R : realType) (T : choiceType) (mu : R.-pmf T). + +Lemma integral_espe (f : T -> \bar R) : (forall x, 0 <= f x)%E -> + \int[measure_of_pmf mu]_x f x = \Ee_[mu] f. +Proof. +move=> f0; rewrite /eexpectation_pmf -esum_setT_discrete -integral_counting_esum => //=. +rewrite - (@integral_measure_of_density _ (discrete_measurable_space T) R + (@counting (discrete_measurable_space T) R) mu) //=. +move => H; apply: eq_measure_integral => A mA _ /=. +by rewrite /measure_of_density /measure_of_pmf integral_counting_esum. +Qed. + +Lemma espeE (f : T -> R) : ('E_(measure_of_pmf mu)[f] = \Ee_[mu] (EFin \o f)). +Proof. +rewrite expectation_def integralE /eexpectation_pmf esumE; congr (_ - _). +- transitivity (\Ee_[mu] ((EFin \o f)^\+)). + by rewrite integral_espe// => x; exact: funepos_ge0. + by rewrite /eexpectation_pmf; apply: eq_esum => x _; rewrite !funeposE maxe_pmfM. +- transitivity (\Ee_[mu] ((EFin \o f)^\-)). + by rewrite integral_espe// => x; exact: funeneg_ge0. + by rewrite /eexpectation_pmf; apply: eq_esum => x _; rewrite !funenegE maxeN_pmfM. +Qed. + +End Expectation. + +(* -------------------------------------------------------------------- *) +Section pmf_subpmf. +Context d (T : measurableType d) (R : realType) (Pr : probability T R). +Variable X : {RV Pr >-> R}. + +Lemma pmf_fin_bigcup (J : seq R) : uniq J -> + \sum_(j <- J) (pmf X j)%:E + = Pr (\bigcup_(j in [set` J]) X @^-1` [set j]). +Proof. +move=> uJ. +rewrite (@measure_fin_bigcup _ _ _ Pr _ [set` J] (fun j : R => X @^-1` [set j])). +- exact: finite_seq. +- exact: trivIset_preimage1. +- by move=> j _; exact: measurable_funPTI. +- rewrite fsbig_seq//; apply: eq_fsbigr => j _. + by rewrite /pmf fineK// fin_num_measure. +Qed. + +Lemma pmf_uniq_le1 (J : seq R) : uniq J -> (\sum_(j <- J) pmf X j <= 1)%R. +Proof. +move=> uJ; rewrite -lee_fin -sumEFin pmf_fin_bigcup//. +apply: probability_le1; apply: fin_bigcup_measurable. +- exact: finite_seq. +- by move=> j _; exact: measurable_funPTI. +Qed. + +HB.instance Definition _ := + @uniq_isSubPmf.Build R R (pmf X) (@pmf_ge0 _ _ _ Pr X) pmf_uniq_le1. + +End pmf_subpmf. + +(* -------------------------------------------------------------------- *) +Section pr_pmf. +Context d (T : pmeasurableType d) (R : realType) (Pr : probability T R). +Variable X : {dRV Pr >-> R}. + +Local Notation pmfX := (@pmf _ _ _ Pr X). + +Lemma pmf_out (r : R) : ~ range X r -> pmfX r = 0%R. +Proof. by move=> nr; rewrite /pmf preimage10// measure0. Qed. + +Lemma esum_pmf_range : + esum [set: R] (EFin \o pmfX) = \esum_(r in range X) (pmfX r)%:E. +Proof. +rewrite (esumID (range X) [set: R] (EFin \o pmfX)). +- by move=> i _; rewrite lee_fin pmf_ge0. +- rewrite setTI [X in _ + X]esum1 ?adde0//= => r [_ /= nr]. + by rewrite pmf_out. +Qed. + +Lemma esum_pmf_dRV : esum [set: R] (EFin \o pmfX) = 1. +Proof. +rewrite esum_pmf_range. +rewrite (reindex_esum (dRV_dom X) (range X) (dRV_enum X) + (fun r => (pmfX r)%:E))//. +transitivity (\esum_(k in dRV_dom X) enum_prob X k). + apply: eq_esum => k kd. + by rewrite /enum_prob patchE mem_set// /pmf fineK// fin_num_measure. +rewrite -[X in \esum_(k in X) _]set_mem_set -nneseries_esum. +- by move=> n _; rewrite /enum_prob patchE; case: ifP. +- rewrite eseries_mkcond -[RHS](@sum_enum_prob _ _ _ _ _ Pr X measurable_set1). + apply: eq_eseriesr => k _. + case: ifPn => // kd. + by rewrite /enum_prob patchE (negbTE kd). +Qed. + +Lemma esum_pmf_set_dRV (A : set R) : measurable A -> + \esum_(r in A) (pmfX r)%:E = distribution Pr X A. +Proof. +move=> mA. +pose g (r : R) := if r \in A then (pmfX r)%:E else 0. +have g0 r : ~ range X r -> g r = 0. + by move=> nr; rewrite /g pmf_out//; case: ifP. +transitivity (\esum_(r in [set: R]) g r); first exact: esum_mkcond. +transitivity (\esum_(r in range X) g r). + rewrite (esumID (range X) [set: R] g). + - move=> i _; rewrite /g; case: ifPn => // _. + by rewrite lee_fin pmf_ge0. + - rewrite setTI [X in _ + X]esum1 ?adde0//= => r [_ /= nr]. + exact: g0. +rewrite (reindex_esum (dRV_dom X) (range X) (dRV_enum X) g)//. +rewrite -[X in \esum_(k in X) _]set_mem_set -nneseries_esum. +- move=> n _; rewrite /g; case: ifPn => // _. + by rewrite lee_fin pmf_ge0. +- rewrite eseries_mkcond. + rewrite [RHS](@distribution_dRV _ _ _ _ _ Pr X measurable_set1 A mA). + apply: eq_eseriesr => k _. + rewrite /g /enum_prob patchE diracE; case: ifPn => kd; last by rewrite mul0e. + rewrite /pmf fineK ?fin_num_measure//. + by case: ifPn => _; rewrite ?mule1 ?mule0. +Qed. + +Lemma esum_pmf_pred (A : set R) : + esum [set: R] (EFin \o (fun r : R => ((r \in A)%:R * pmfX r)%R)) + = \esum_(r in A) (pmfX r)%:E. +Proof. +rewrite [RHS]esum_mkcond; apply: eq_esum => r _. +by case: (r \in A) => /=; rewrite ?mul1r ?mul0r. +Qed. + +Lemma pr_pmf_dRV (A : set R) : measurable A -> + (\P_[pmfX] (fun r => r \in A))%:E = distribution Pr X A. +Proof. +by move=> mA; rewrite /pr esum_pmf_pred esum_pmf_set_dRV// fineK ?fin_num_measure. +Qed. + +End pr_pmf. + +(* -------------------------------------------------------------------- *) +Section espe_pmf. +Context d (T : pmeasurableType d) (R : realType) (Pr : probability T R). +Variable X : {dRV Pr >-> R}. + +Local Notation pmfX := (@pmf _ _ _ Pr X). + +Lemma distribution_integral_counting (A : set R) : measurable A -> + distribution Pr X A = \int[@counting R R]_(r in A) (pmfX r)%:E. +Proof. +move=> mA; rewrite integral_counting_esum => //=. +- by apply/measurable_EFinP; exact: pmf_measurable. +- by rewrite esum_pmf_set_dRV. +Qed. + +Lemma ge0_espe_pmf (f : R -> \bar R) : + measurable_fun [set: R] f -> (forall r, 0 <= f r) -> + \Ee_[pmfX] f = \int[Pr]_w f (X w). +Proof. +move=> mf f0. +have mfh : measurable_fun [set: R] (fun r => f r * (pmfX r)%:E). + by apply: emeasurable_funM => //; apply/measurable_EFinP; exact: pmf_measurable. +have fh0 r : 0 <= f r * (pmfX r)%:E. + by apply: mule_ge0; [exact: f0|rewrite lee_fin pmf_ge0]. +have step1 : \Ee_[pmfX] f = \int[@counting R R]_r (f r * (pmfX r)%:E). + by rewrite /eexpectation_pmf -integral_counting_esum//; exact: measurable_set1. +have step2 : \int[distribution Pr X]_r f r + = \int[@counting R R]_r (f r * (pmfX r)%:E). +rewrite -(@integral_measure_of_density _ R R (@counting R R) pmfX) //=. ++ move => H. apply: eq_measure_integral => A mA _ /=. + exact: distribution_integral_counting. ++ exact: pmf_measurable. +have step3 : \int[distribution Pr X]_r f r = \int[Pr]_w f (X w). + by rewrite /distribution ge0_integral_pushforward. +by rewrite step1 -step2 step3. +Qed. + +Lemma espe_pmf_dRV : \Ee_[pmfX] EFin = 'E_Pr[X]. +Proof. +have mE : measurable_fun [set: R] (EFin : R -> \bar R) by apply/measurable_EFinP. +rewrite /eexpectation_pmf esumE expectation_def integralE; congr (_ - _). +- transitivity (\Ee_[pmfX] (EFin^\+)). + by rewrite /eexpectation_pmf; apply: eq_esum => r _; rewrite !funeposE maxe_pmfM. + rewrite ge0_espe_pmf => //=. + + exact: measurable_funepos. + + by apply: eq_integral => w _; rewrite !funeposE. +- transitivity (\Ee_[pmfX] (EFin^\-)). + by rewrite /eexpectation_pmf; apply: eq_esum => r _; rewrite !funenegE maxeN_pmfM. + rewrite ge0_espe_pmf => //=. + + exact: measurable_funeneg. + + by apply: eq_integral => w _; rewrite !funenegE. +Qed. + +End espe_pmf. From 11e1c90c799b5f34cd891d4825b1042a0566c7b1 Mon Sep 17 00:00:00 2001 From: Reynald Affeldt Date: Thu, 22 Oct 2026 05:36:10 +0900 Subject: [PATCH 10/18] simplify esum_counting.v --- theories/esum_counting.v | 203 +++++++++++++-------------------------- 1 file changed, 68 insertions(+), 135 deletions(-) diff --git a/theories/esum_counting.v b/theories/esum_counting.v index 36a0e7bce5..46db6d3e10 100644 --- a/theories/esum_counting.v +++ b/theories/esum_counting.v @@ -1,14 +1,9 @@ From HB Require Import structures. From mathcomp Require Import boot order algebra. -From mathcomp.classical Require Import boolp classical_sets mathcomp_extra functions. -From mathcomp Require Import xfinmap constructive_ereal reals discrete. -From mathcomp Require Import realseq realsum. -From mathcomp Require Import topology esum sequences normedtype ereal. -From mathcomp Require Import cardinality fsbigop. -From mathcomp Require Import numfun measurable_realfun. -From mathcomp Require Import measure lebesgue_measure lebesgue_integral. -From mathcomp Require Import counting_distr. -From mathcomp Require Import random_variable. +From mathcomp Require Import boolp classical_sets functions cardinality fsbigop. +From mathcomp Require Import reals topology esum sequences normedtype ereal. +From mathcomp Require Import numfun measure measurable_realfun lebesgue_measure. +From mathcomp Require Import lebesgue_integral counting_distr random_variable. Set Implicit Arguments. Unset Strict Implicit. @@ -17,14 +12,9 @@ Unset Printing Implicit Defensive. Import Order.TTheory GRing.Theory Num.Theory. Local Open Scope ring_scope. -Local Notation simpm := Monoid.simpm. Local Open Scope classical_set_scope. Local Open Scope ereal_scope. -Import HBNNSimple. -Import MeasurableR. - -(* -------------------------------------------------------------------- *) Definition discrete_measurable_space (T : choiceType) : Type := T. HB.instance Definition _ (T : choiceType) := @@ -35,17 +25,16 @@ HB.instance Definition _ (T : choiceType) := @isMeasurable.Build (discrete_measurable_space T) discrete_measurable discrete_measurable0 discrete_measurableC discrete_measurableU. -Lemma esum_setT_discrete {R : realType} (T : choiceType) (f : T -> \bar R) : - (\esum_(x in [set: discrete_measurable_space T]) f x - = \esum_(x in [set: T]) f x)%E. +Lemma esum_setT_discrete {R : realType} {T : choiceType} (f : T -> \bar R) : + \esum_(x in [set: discrete_measurable_space T]) f x = + \esum_(x in [set: T]) f x. Proof. by apply: (@reindex_esum R T (discrete_measurable_space T) [set: T] [set: discrete_measurable_space T] id f); split. Qed. -(* -------------------------------------------------------------------- *) Section SubProbability_measure_subpmf. -Context (R : realType) (T : choiceType) (mu : R.-pmf T). +Context {R : realType} {T : choiceType} (mu : R.-pmf T). Definition measure_of_pmf (S : set (discrete_measurable_space T)) := \esum_(x in S) (EFin \o mu) x. @@ -59,11 +48,11 @@ Proof. by apply: esum_ge0 => x _; rewrite lee_fin. Qed. Let P_sigma_additive : semi_sigma_additive measure_of_pmf. Proof. move=> F _ tF _. -have -> : measure_of_pmf (\bigcup_n F n) = (\sum_(i X](_ : _ = \sum_(i n; exact: P_ge0. apply: esum_bigcup => //=. - + by apply: (sub_trivIset (@subsetT _ _) tF). - + by move=> x; rewrite lee_fin. + exact: (sub_trivIset (@subsetT _ _) tF). + by move=> x; rewrite lee_fin. apply: cvg_toP => //. apply: is_cvg_nneseries => n _ _; rewrite /measure_of_pmf. by apply: esum_ge0 => x _; rewrite lee_fin. @@ -80,210 +69,154 @@ HB.instance Definition _ := End SubProbability_measure_subpmf. -(* -------------------------------------------------------------------- *) -Section maxe. -Context (R : realType) (T : choiceType) (mu : R.-pmf T). - -Lemma maxe_pmfM (a : \bar R) x : - (maxe (a * (mu x)%:E) 0 = maxe a 0 * (mu x)%:E)%E. -Proof. -rewrite [in LHS]muleC [in RHS]muleC maxe_pMr => //=. -- by rewrite lee_fin. -- by rewrite mule0. -Qed. - -Lemma maxeN_pmfM (a : \bar R) x : - (maxe (- (a * (mu x)%:E)) 0 = maxe (- a) 0 * (mu x)%:E)%E. -Proof. by rewrite -mulNe maxe_pmfM. Qed. - -End maxe. - -(* -------------------------------------------------------------------- *) Section Expectation. -Context (R : realType) (T : choiceType) (mu : R.-pmf T). +Context {R : realType} {T : choiceType} (mu : R.-pmf T). Lemma integral_espe (f : T -> \bar R) : (forall x, 0 <= f x)%E -> \int[measure_of_pmf mu]_x f x = \Ee_[mu] f. Proof. -move=> f0; rewrite /eexpectation_pmf -esum_setT_discrete -integral_counting_esum => //=. -rewrite - (@integral_measure_of_density _ (discrete_measurable_space T) R - (@counting (discrete_measurable_space T) R) mu) //=. +move=> f0; rewrite /eexpectation_pmf -esum_setT_discrete -integral_counting_esum//=. +rewrite -(@integral_measure_of_density _ (discrete_measurable_space T) R + (@counting (discrete_measurable_space T) R) mu)//=. move => H; apply: eq_measure_integral => A mA _ /=. by rewrite /measure_of_density /measure_of_pmf integral_counting_esum. Qed. -Lemma espeE (f : T -> R) : ('E_(measure_of_pmf mu)[f] = \Ee_[mu] (EFin \o f)). +Lemma eexpectationE (f : T -> R) : + 'E_(measure_of_pmf mu)[f] = \Ee_[mu] (EFin \o f). Proof. rewrite expectation_def integralE /eexpectation_pmf esumE; congr (_ - _). - transitivity (\Ee_[mu] ((EFin \o f)^\+)). by rewrite integral_espe// => x; exact: funepos_ge0. - by rewrite /eexpectation_pmf; apply: eq_esum => x _; rewrite !funeposE maxe_pmfM. + rewrite /eexpectation_pmf; apply: eq_esum => x _; rewrite !funeposE. + by rewrite maxe_pMl ?mul0e// lee_fin. - transitivity (\Ee_[mu] ((EFin \o f)^\-)). by rewrite integral_espe// => x; exact: funeneg_ge0. - by rewrite /eexpectation_pmf; apply: eq_esum => x _; rewrite !funenegE maxeN_pmfM. + rewrite /eexpectation_pmf; apply: eq_esum => x _; rewrite !funenegE. + by rewrite maxe_pMl ?mul0e ?mulNe// lee_fin. Qed. End Expectation. -(* -------------------------------------------------------------------- *) Section pmf_subpmf. -Context d (T : measurableType d) (R : realType) (Pr : probability T R). -Variable X : {RV Pr >-> R}. +Import MeasurableR. +Context {d} {T : measurableType d} {R : realType} (P : probability T R) + (X : {RV P >-> R}). Lemma pmf_fin_bigcup (J : seq R) : uniq J -> - \sum_(j <- J) (pmf X j)%:E - = Pr (\bigcup_(j in [set` J]) X @^-1` [set j]). + \sum_(j <- J) (pmf X j)%:E = P (\bigcup_(j in [set` J]) X @^-1` [set j]). Proof. move=> uJ. -rewrite (@measure_fin_bigcup _ _ _ Pr _ [set` J] (fun j : R => X @^-1` [set j])). +rewrite (@measure_fin_bigcup _ _ _ P _ [set` J] (fun j : R => X @^-1` [set j]))//. - exact: finite_seq. - exact: trivIset_preimage1. -- by move=> j _; exact: measurable_funPTI. - rewrite fsbig_seq//; apply: eq_fsbigr => j _. by rewrite /pmf fineK// fin_num_measure. Qed. -Lemma pmf_uniq_le1 (J : seq R) : uniq J -> (\sum_(j <- J) pmf X j <= 1)%R. +Let pmf_uniq_le1 (J : seq R) : uniq J -> (\sum_(j <- J) pmf X j <= 1)%R. Proof. move=> uJ; rewrite -lee_fin -sumEFin pmf_fin_bigcup//. -apply: probability_le1; apply: fin_bigcup_measurable. -- exact: finite_seq. -- by move=> j _; exact: measurable_funPTI. +by rewrite probability_le1//; exact: fin_bigcup_measurable. Qed. HB.instance Definition _ := - @uniq_isSubPmf.Build R R (pmf X) (@pmf_ge0 _ _ _ Pr X) pmf_uniq_le1. + @uniq_isSubPmf.Build R R (pmf X) (@pmf_ge0 _ _ _ P X) pmf_uniq_le1. End pmf_subpmf. -(* -------------------------------------------------------------------- *) Section pr_pmf. -Context d (T : pmeasurableType d) (R : realType) (Pr : probability T R). -Variable X : {dRV Pr >-> R}. - -Local Notation pmfX := (@pmf _ _ _ Pr X). +Import MeasurableR. +Context {d} {T : pmeasurableType d} {R : realType} (P : probability T R) + (X : {dRV P >-> R}). -Lemma pmf_out (r : R) : ~ range X r -> pmfX r = 0%R. -Proof. by move=> nr; rewrite /pmf preimage10// measure0. Qed. +Local Notation pmfX := (@pmf _ _ _ P X). Lemma esum_pmf_range : esum [set: R] (EFin \o pmfX) = \esum_(r in range X) (pmfX r)%:E. Proof. rewrite (esumID (range X) [set: R] (EFin \o pmfX)). -- by move=> i _; rewrite lee_fin pmf_ge0. -- rewrite setTI [X in _ + X]esum1 ?adde0//= => r [_ /= nr]. - by rewrite pmf_out. +- by move=> i _; rewrite lee_fin. +rewrite setTI [X in _ + X]esum1 ?adde0//= => r [_ /= nr]. +by rewrite not_range_pmf0. Qed. Lemma esum_pmf_dRV : esum [set: R] (EFin \o pmfX) = 1. Proof. rewrite esum_pmf_range. -rewrite (reindex_esum (dRV_dom X) (range X) (dRV_enum X) - (fun r => (pmfX r)%:E))//. +rewrite (reindex_esum (dRV_dom X) (range X) (dRV_enum X))//. transitivity (\esum_(k in dRV_dom X) enum_prob X k). - apply: eq_esum => k kd. + apply: eq_esum => k kd/=. by rewrite /enum_prob patchE mem_set// /pmf fineK// fin_num_measure. rewrite -[X in \esum_(k in X) _]set_mem_set -nneseries_esum. - by move=> n _; rewrite /enum_prob patchE; case: ifP. -- rewrite eseries_mkcond -[RHS](@sum_enum_prob _ _ _ _ _ Pr X measurable_set1). - apply: eq_eseriesr => k _. - case: ifPn => // kd. +- rewrite eseries_mkcond -[RHS](sum_enum_prob X measurable_set1). + apply: eq_eseriesr => k _; case: ifPn => // kd. by rewrite /enum_prob patchE (negbTE kd). Qed. -Lemma esum_pmf_set_dRV (A : set R) : measurable A -> - \esum_(r in A) (pmfX r)%:E = distribution Pr X A. -Proof. -move=> mA. -pose g (r : R) := if r \in A then (pmfX r)%:E else 0. -have g0 r : ~ range X r -> g r = 0. - by move=> nr; rewrite /g pmf_out//; case: ifP. -transitivity (\esum_(r in [set: R]) g r); first exact: esum_mkcond. -transitivity (\esum_(r in range X) g r). - rewrite (esumID (range X) [set: R] g). - - move=> i _; rewrite /g; case: ifPn => // _. - by rewrite lee_fin pmf_ge0. - - rewrite setTI [X in _ + X]esum1 ?adde0//= => r [_ /= nr]. - exact: g0. -rewrite (reindex_esum (dRV_dom X) (range X) (dRV_enum X) g)//. -rewrite -[X in \esum_(k in X) _]set_mem_set -nneseries_esum. -- move=> n _; rewrite /g; case: ifPn => // _. - by rewrite lee_fin pmf_ge0. -- rewrite eseries_mkcond. - rewrite [RHS](@distribution_dRV _ _ _ _ _ Pr X measurable_set1 A mA). - apply: eq_eseriesr => k _. - rewrite /g /enum_prob patchE diracE; case: ifPn => kd; last by rewrite mul0e. - rewrite /pmf fineK ?fin_num_measure//. - by case: ifPn => _; rewrite ?mule1 ?mule0. -Qed. - Lemma esum_pmf_pred (A : set R) : - esum [set: R] (EFin \o (fun r : R => ((r \in A)%:R * pmfX r)%R)) - = \esum_(r in A) (pmfX r)%:E. + esum [set: R] (EFin \o (fun r => (r \in A)%:R * pmfX r))%R = + \esum_(r in A) (pmfX r)%:E. Proof. rewrite [RHS]esum_mkcond; apply: eq_esum => r _. by case: (r \in A) => /=; rewrite ?mul1r ?mul0r. Qed. Lemma pr_pmf_dRV (A : set R) : measurable A -> - (\P_[pmfX] (fun r => r \in A))%:E = distribution Pr X A. + (\P_[pmfX] (mem A))%:E = distribution P X A. Proof. -by move=> mA; rewrite /pr esum_pmf_pred esum_pmf_set_dRV// fineK ?fin_num_measure. +move=> mA; rewrite /pr esum_pmf_pred dRV_esum_pmf_distribution// fineK//. +by rewrite fin_num_measure. Qed. End pr_pmf. -(* -------------------------------------------------------------------- *) Section espe_pmf. -Context d (T : pmeasurableType d) (R : realType) (Pr : probability T R). -Variable X : {dRV Pr >-> R}. +Import MeasurableR. +Context {d} {T : pmeasurableType d} {R : realType} (P : probability T R) + (X : {dRV P >-> R}). -Local Notation pmfX := (@pmf _ _ _ Pr X). +Local Notation pmfX := (@pmf _ _ _ P X). Lemma distribution_integral_counting (A : set R) : measurable A -> - distribution Pr X A = \int[@counting R R]_(r in A) (pmfX r)%:E. + distribution P X A = \int[@counting R R]_(r in A) (pmfX r)%:E. Proof. -move=> mA; rewrite integral_counting_esum => //=. -- by apply/measurable_EFinP; exact: pmf_measurable. -- by rewrite esum_pmf_set_dRV. +move=> mA. +rewrite -dRV_esum_pmf_distribution// integral_counting_esum//=. +by apply/measurable_EFinP; exact: pmf_measurable. Qed. Lemma ge0_espe_pmf (f : R -> \bar R) : measurable_fun [set: R] f -> (forall r, 0 <= f r) -> - \Ee_[pmfX] f = \int[Pr]_w f (X w). + \Ee_[pmfX] f = \int[P]_w f (X w). Proof. move=> mf f0. have mfh : measurable_fun [set: R] (fun r => f r * (pmfX r)%:E). by apply: emeasurable_funM => //; apply/measurable_EFinP; exact: pmf_measurable. have fh0 r : 0 <= f r * (pmfX r)%:E. by apply: mule_ge0; [exact: f0|rewrite lee_fin pmf_ge0]. -have step1 : \Ee_[pmfX] f = \int[@counting R R]_r (f r * (pmfX r)%:E). +have -> : \Ee_[pmfX] f = \int[@counting R R]_r (f r * (pmfX r)%:E). by rewrite /eexpectation_pmf -integral_counting_esum//; exact: measurable_set1. -have step2 : \int[distribution Pr X]_r f r - = \int[@counting R R]_r (f r * (pmfX r)%:E). -rewrite -(@integral_measure_of_density _ R R (@counting R R) pmfX) //=. -+ move => H. apply: eq_measure_integral => A mA _ /=. +have <- : \int[distribution P X]_r f r = + \int[@counting R R]_r (f r * (pmfX r)%:E). + rewrite -(integral_measure_of_density _ (pmf_measurable X))//=. + apply: eq_measure_integral => A mA _ /=. exact: distribution_integral_counting. -+ exact: pmf_measurable. -have step3 : \int[distribution Pr X]_r f r = \int[Pr]_w f (X w). - by rewrite /distribution ge0_integral_pushforward. -by rewrite step1 -step2 step3. +by rewrite /distribution ge0_integral_pushforward. Qed. -Lemma espe_pmf_dRV : \Ee_[pmfX] EFin = 'E_Pr[X]. +Lemma espe_pmf_dRV : \Ee_[pmfX] EFin = 'E_P[X]. Proof. -have mE : measurable_fun [set: R] (EFin : R -> \bar R) by apply/measurable_EFinP. rewrite /eexpectation_pmf esumE expectation_def integralE; congr (_ - _). -- transitivity (\Ee_[pmfX] (EFin^\+)). - by rewrite /eexpectation_pmf; apply: eq_esum => r _; rewrite !funeposE maxe_pmfM. - rewrite ge0_espe_pmf => //=. - + exact: measurable_funepos. - + by apply: eq_integral => w _; rewrite !funeposE. +- transitivity (\Ee_[pmfX] EFin^\+). + by apply: eq_esum => r _; rewrite !funeposE maxe_pMl ?lee_fin// mul0e. + rewrite ge0_espe_pmf => //=; first exact: measurable_funepos. + by apply: eq_integral => w _; rewrite !funeposE. - transitivity (\Ee_[pmfX] (EFin^\-)). - by rewrite /eexpectation_pmf; apply: eq_esum => r _; rewrite !funenegE maxeN_pmfM. - rewrite ge0_espe_pmf => //=. - + exact: measurable_funeneg. - + by apply: eq_integral => w _; rewrite !funenegE. + by apply: eq_esum => r _; rewrite !funenegE maxe_pMl ?lee_fin// mul0e mulNe. + rewrite ge0_espe_pmf//=; first exact: measurable_funeneg. + by apply: eq_integral => w _; rewrite !funenegE. Qed. End espe_pmf. From 5bae25d03aa77e6df83e4a7400483fab411eb4b8 Mon Sep 17 00:00:00 2001 From: Reynald Affeldt Date: Sat, 31 Oct 2026 08:32:44 +0900 Subject: [PATCH 11/18] generalize expectation to handle \bar R rm the notation \Ee_[ mu ] f gen finite_norm to \bar R --- _CoqProject | 2 - reals/constructive_ereal.v | 2 +- theories/esum_counting.v | 222 ----------- theories/hoelder.v | 13 +- theories/probability_theory/counting_distr.v | 350 +++++++++++++++--- theories/probability_theory/independence.v | 49 +-- theories/probability_theory/random_variable.v | 120 +++--- 7 files changed, 393 insertions(+), 365 deletions(-) delete mode 100644 theories/esum_counting.v diff --git a/_CoqProject b/_CoqProject index d370bcaeb6..8e1c0e06e3 100644 --- a/_CoqProject +++ b/_CoqProject @@ -165,7 +165,5 @@ theories/all_analysis.v theories/showcase/summability.v theories/showcase/pnt.v -theories/esum_counting.v - analysis_stdlib/Rstruct_topology.v analysis_stdlib/showcase/uniform_bigO.v diff --git a/reals/constructive_ereal.v b/reals/constructive_ereal.v index 48e20c267e..f19497b94d 100644 --- a/reals/constructive_ereal.v +++ b/reals/constructive_ereal.v @@ -529,7 +529,7 @@ HB.instance Definition _ := Order.hasTop.Build ereal_display (\bar R) leey. End ERealOrder_realDomainType. Section ERealZmodule. -Context {R : zmodType}. +Context {R : baseZmodType}. Implicit Types x y z : \bar R. Definition oppe x := diff --git a/theories/esum_counting.v b/theories/esum_counting.v deleted file mode 100644 index 46db6d3e10..0000000000 --- a/theories/esum_counting.v +++ /dev/null @@ -1,222 +0,0 @@ -From HB Require Import structures. -From mathcomp Require Import boot order algebra. -From mathcomp Require Import boolp classical_sets functions cardinality fsbigop. -From mathcomp Require Import reals topology esum sequences normedtype ereal. -From mathcomp Require Import numfun measure measurable_realfun lebesgue_measure. -From mathcomp Require Import lebesgue_integral counting_distr random_variable. - -Set Implicit Arguments. -Unset Strict Implicit. -Unset Printing Implicit Defensive. - -Import Order.TTheory GRing.Theory Num.Theory. - -Local Open Scope ring_scope. -Local Open Scope classical_set_scope. -Local Open Scope ereal_scope. - -Definition discrete_measurable_space (T : choiceType) : Type := T. - -HB.instance Definition _ (T : choiceType) := - Choice.on (discrete_measurable_space T). - -HB.instance Definition _ (T : choiceType) := @isMeasurable.Build - default_measure_display - (discrete_measurable_space T) discrete_measurable discrete_measurable0 - discrete_measurableC discrete_measurableU. - -Lemma esum_setT_discrete {R : realType} {T : choiceType} (f : T -> \bar R) : - \esum_(x in [set: discrete_measurable_space T]) f x = - \esum_(x in [set: T]) f x. -Proof. -by apply: (@reindex_esum R T (discrete_measurable_space T) - [set: T] [set: discrete_measurable_space T] id f); split. -Qed. - -Section SubProbability_measure_subpmf. -Context {R : realType} {T : choiceType} (mu : R.-pmf T). - -Definition measure_of_pmf (S : set (discrete_measurable_space T)) := - \esum_(x in S) (EFin \o mu) x. - -Let P0 : measure_of_pmf set0 = 0%E. -Proof. by rewrite /measure_of_pmf esum_set0. Qed. - -Let P_ge0 (S : set (discrete_measurable_space T)) : (0 <= measure_of_pmf S)%E. -Proof. by apply: esum_ge0 => x _; rewrite lee_fin. Qed. - -Let P_sigma_additive : semi_sigma_additive measure_of_pmf. -Proof. -move=> F _ tF _. -rewrite [X in _ --> X](_ : _ = \sum_(i n; exact: P_ge0. - apply: esum_bigcup => //=. - exact: (sub_trivIset (@subsetT _ _) tF). - by move=> x; rewrite lee_fin. -apply: cvg_toP => //. -apply: is_cvg_nneseries => n _ _; rewrite /measure_of_pmf. -by apply: esum_ge0 => x _; rewrite lee_fin. -Qed. - -HB.instance Definition _ := isMeasure.Build _ _ _ measure_of_pmf - P0 P_ge0 P_sigma_additive. - -Let P_setT : (measure_of_pmf [set: discrete_measurable_space T] <= 1)%E. -Proof. by rewrite /measure_of_pmf esum_setT_discrete; exact: subpmf_sum_le1. Qed. - -HB.instance Definition _ := - @Measure_isSubProbability.Build _ _ R measure_of_pmf P_setT. - -End SubProbability_measure_subpmf. - -Section Expectation. -Context {R : realType} {T : choiceType} (mu : R.-pmf T). - -Lemma integral_espe (f : T -> \bar R) : (forall x, 0 <= f x)%E -> - \int[measure_of_pmf mu]_x f x = \Ee_[mu] f. -Proof. -move=> f0; rewrite /eexpectation_pmf -esum_setT_discrete -integral_counting_esum//=. -rewrite -(@integral_measure_of_density _ (discrete_measurable_space T) R - (@counting (discrete_measurable_space T) R) mu)//=. -move => H; apply: eq_measure_integral => A mA _ /=. -by rewrite /measure_of_density /measure_of_pmf integral_counting_esum. -Qed. - -Lemma eexpectationE (f : T -> R) : - 'E_(measure_of_pmf mu)[f] = \Ee_[mu] (EFin \o f). -Proof. -rewrite expectation_def integralE /eexpectation_pmf esumE; congr (_ - _). -- transitivity (\Ee_[mu] ((EFin \o f)^\+)). - by rewrite integral_espe// => x; exact: funepos_ge0. - rewrite /eexpectation_pmf; apply: eq_esum => x _; rewrite !funeposE. - by rewrite maxe_pMl ?mul0e// lee_fin. -- transitivity (\Ee_[mu] ((EFin \o f)^\-)). - by rewrite integral_espe// => x; exact: funeneg_ge0. - rewrite /eexpectation_pmf; apply: eq_esum => x _; rewrite !funenegE. - by rewrite maxe_pMl ?mul0e ?mulNe// lee_fin. -Qed. - -End Expectation. - -Section pmf_subpmf. -Import MeasurableR. -Context {d} {T : measurableType d} {R : realType} (P : probability T R) - (X : {RV P >-> R}). - -Lemma pmf_fin_bigcup (J : seq R) : uniq J -> - \sum_(j <- J) (pmf X j)%:E = P (\bigcup_(j in [set` J]) X @^-1` [set j]). -Proof. -move=> uJ. -rewrite (@measure_fin_bigcup _ _ _ P _ [set` J] (fun j : R => X @^-1` [set j]))//. -- exact: finite_seq. -- exact: trivIset_preimage1. -- rewrite fsbig_seq//; apply: eq_fsbigr => j _. - by rewrite /pmf fineK// fin_num_measure. -Qed. - -Let pmf_uniq_le1 (J : seq R) : uniq J -> (\sum_(j <- J) pmf X j <= 1)%R. -Proof. -move=> uJ; rewrite -lee_fin -sumEFin pmf_fin_bigcup//. -by rewrite probability_le1//; exact: fin_bigcup_measurable. -Qed. - -HB.instance Definition _ := - @uniq_isSubPmf.Build R R (pmf X) (@pmf_ge0 _ _ _ P X) pmf_uniq_le1. - -End pmf_subpmf. - -Section pr_pmf. -Import MeasurableR. -Context {d} {T : pmeasurableType d} {R : realType} (P : probability T R) - (X : {dRV P >-> R}). - -Local Notation pmfX := (@pmf _ _ _ P X). - -Lemma esum_pmf_range : - esum [set: R] (EFin \o pmfX) = \esum_(r in range X) (pmfX r)%:E. -Proof. -rewrite (esumID (range X) [set: R] (EFin \o pmfX)). -- by move=> i _; rewrite lee_fin. -rewrite setTI [X in _ + X]esum1 ?adde0//= => r [_ /= nr]. -by rewrite not_range_pmf0. -Qed. - -Lemma esum_pmf_dRV : esum [set: R] (EFin \o pmfX) = 1. -Proof. -rewrite esum_pmf_range. -rewrite (reindex_esum (dRV_dom X) (range X) (dRV_enum X))//. -transitivity (\esum_(k in dRV_dom X) enum_prob X k). - apply: eq_esum => k kd/=. - by rewrite /enum_prob patchE mem_set// /pmf fineK// fin_num_measure. -rewrite -[X in \esum_(k in X) _]set_mem_set -nneseries_esum. -- by move=> n _; rewrite /enum_prob patchE; case: ifP. -- rewrite eseries_mkcond -[RHS](sum_enum_prob X measurable_set1). - apply: eq_eseriesr => k _; case: ifPn => // kd. - by rewrite /enum_prob patchE (negbTE kd). -Qed. - -Lemma esum_pmf_pred (A : set R) : - esum [set: R] (EFin \o (fun r => (r \in A)%:R * pmfX r))%R = - \esum_(r in A) (pmfX r)%:E. -Proof. -rewrite [RHS]esum_mkcond; apply: eq_esum => r _. -by case: (r \in A) => /=; rewrite ?mul1r ?mul0r. -Qed. - -Lemma pr_pmf_dRV (A : set R) : measurable A -> - (\P_[pmfX] (mem A))%:E = distribution P X A. -Proof. -move=> mA; rewrite /pr esum_pmf_pred dRV_esum_pmf_distribution// fineK//. -by rewrite fin_num_measure. -Qed. - -End pr_pmf. - -Section espe_pmf. -Import MeasurableR. -Context {d} {T : pmeasurableType d} {R : realType} (P : probability T R) - (X : {dRV P >-> R}). - -Local Notation pmfX := (@pmf _ _ _ P X). - -Lemma distribution_integral_counting (A : set R) : measurable A -> - distribution P X A = \int[@counting R R]_(r in A) (pmfX r)%:E. -Proof. -move=> mA. -rewrite -dRV_esum_pmf_distribution// integral_counting_esum//=. -by apply/measurable_EFinP; exact: pmf_measurable. -Qed. - -Lemma ge0_espe_pmf (f : R -> \bar R) : - measurable_fun [set: R] f -> (forall r, 0 <= f r) -> - \Ee_[pmfX] f = \int[P]_w f (X w). -Proof. -move=> mf f0. -have mfh : measurable_fun [set: R] (fun r => f r * (pmfX r)%:E). - by apply: emeasurable_funM => //; apply/measurable_EFinP; exact: pmf_measurable. -have fh0 r : 0 <= f r * (pmfX r)%:E. - by apply: mule_ge0; [exact: f0|rewrite lee_fin pmf_ge0]. -have -> : \Ee_[pmfX] f = \int[@counting R R]_r (f r * (pmfX r)%:E). - by rewrite /eexpectation_pmf -integral_counting_esum//; exact: measurable_set1. -have <- : \int[distribution P X]_r f r = - \int[@counting R R]_r (f r * (pmfX r)%:E). - rewrite -(integral_measure_of_density _ (pmf_measurable X))//=. - apply: eq_measure_integral => A mA _ /=. - exact: distribution_integral_counting. -by rewrite /distribution ge0_integral_pushforward. -Qed. - -Lemma espe_pmf_dRV : \Ee_[pmfX] EFin = 'E_P[X]. -Proof. -rewrite /eexpectation_pmf esumE expectation_def integralE; congr (_ - _). -- transitivity (\Ee_[pmfX] EFin^\+). - by apply: eq_esum => r _; rewrite !funeposE maxe_pMl ?lee_fin// mul0e. - rewrite ge0_espe_pmf => //=; first exact: measurable_funepos. - by apply: eq_integral => w _; rewrite !funeposE. -- transitivity (\Ee_[pmfX] (EFin^\-)). - by apply: eq_esum => r _; rewrite !funenegE maxe_pMl ?lee_fin// mul0e mulNe. - rewrite ge0_espe_pmf//=; first exact: measurable_funeneg. - by apply: eq_integral => w _; rewrite !funenegE. -Qed. - -End espe_pmf. diff --git a/theories/hoelder.v b/theories/hoelder.v index 44fce50f98..1fb4d8e197 100644 --- a/theories/hoelder.v +++ b/theories/hoelder.v @@ -24,7 +24,8 @@ From mathcomp Require Import numfun exp real_measure lebesgue_integral. (* Lp-spaces and properties of Lp-norms: *) (* *) (* ``` *) -(* finite_norm mu p f := the L-norm of real-valued function f is finite *) +(* finite_norm mu p f := the L-norm of extended real-valued function f is *) +(* finite *) (* The parameter p is an extended real. *) (* LfunType mu p1 == type of measurable functions f with a finite *) (* L-norm *) @@ -785,15 +786,15 @@ Qed. End minkowski. Definition finite_norm d (T : measurableType d) (R : realType) - (mu : {measure set T -> \bar R}) (p : \bar R) (f : T -> R) := - ('N[ mu ]_p [ EFin \o f ] < +oo)%E. + (mu : {measure set T -> \bar R}) (p : \bar R) (f : T -> \bar R) := + ('N[ mu ]_p [ f ] < +oo)%E. Import MeasurableR. HB.mixin Record isLfunction d (T : measurableType d) (R : realType) (mu : {measure set T -> \bar R}) (p : \bar R) (p1 : (1 <= p)%E) (f : T -> R) & @MeasurableFun d _ T R f := { - Lfunction_finite : finite_norm mu p f + Lfunction_finite : finite_norm mu p (EFin \o f) }. #[short(type=LfunType)] @@ -865,7 +866,7 @@ Import numFieldNormedType.Exports HBNNSimple. HB.mixin Record isFinLebesgue d (T : measurableType d) (R : realType) (mu : {measure set T -> \bar R}) (p : \bar R) (p1 : (1 <= p)%E) (f : {mfun_ mu, T >-> R}) := { - Lebesgue_finite : finite_norm mu p f + Lebesgue_finite : finite_norm mu p (EFin \o f) }. #[short(type=LspaceType)] @@ -896,7 +897,7 @@ Section Lfun_pred. Context {d} {T : measurableType d} {R : realType} (mu : {measure set T -> \bar R}) (p : \bar R). -Definition finLfun : {pred _ -> _} := mem [set f | finite_norm mu p f]. +Definition finLfun : {pred _ -> _} := mem [set f : T -> R | finite_norm mu p (EFin \o f)]. Definition Lfun : {pred _ -> _} := [predI @mfun _ _ T R & finLfun]. Definition Lfun_key : pred_key Lfun. Proof. exact. Qed. Canonical Lfun_keyed := KeyedPred Lfun_key. diff --git a/theories/probability_theory/counting_distr.v b/theories/probability_theory/counting_distr.v index 146c09da95..c58c366f5c 100644 --- a/theories/probability_theory/counting_distr.v +++ b/theories/probability_theory/counting_distr.v @@ -1,9 +1,10 @@ From HB Require Import structures. From mathcomp Require Import boot order algebra. -From mathcomp Require Import boolp classical_sets functions. +From mathcomp Require Import boolp classical_sets functions filter. From mathcomp Require Import constructive_ereal reals discrete. From mathcomp Require Import esum ereal. From mathcomp Require Import cardinality fsbigop topology normedtype sequences. +From mathcomp Require Import measure lebesgue_measure measurable_realfun lebesgue_integral random_variable. From mathcomp Require Import unstable. (* Should be removed *) @@ -23,18 +24,36 @@ From mathcomp Require Import numfun. (* dnull == the zero distribution (null distribution) *) (* dunit == degenerate distribution *) (* dlet == monadic bind for distribution *) -(* dlim == limite for index distribution *) +(* dlim == limit for index distribution *) (* ``` *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. -Unset SsrOldRewriteGoalsOrder. (* remove this line when requiring MathComp >= 2.6 *) Import Order.TTheory GRing.Theory Num.Theory. Local Open Scope ring_scope. +Local Open Scope classical_set_scope. + +Definition discrete_measurable_space (T : choiceType) : Type := T. + +HB.instance Definition _ (T : choiceType) := + Choice.on (discrete_measurable_space T). + +HB.instance Definition _ (T : choiceType) := @isMeasurable.Build + default_measure_display + (discrete_measurable_space T) discrete_measurable discrete_measurable0 + discrete_measurableC discrete_measurableU. + +Lemma esum_setT_discrete {R : realType} {T : choiceType} (f : T -> \bar R) : + \esum_(x in [set: discrete_measurable_space T]) f x = + \esum_(x in [set: T]) f x. +Proof. +by apply: (@reindex_esum R T (discrete_measurable_space T) + [set: T] [set: discrete_measurable_space T] id f); split. +Qed. (* -------------------------------------------------------------------- *) Notation "f '<=1' g" := (forall x, f x <= g x) @@ -60,7 +79,6 @@ Reserved Notation "\P_[ mu , A ] E" (at level 2, format "\P_[ mu , A ] E"). Reserved Notation "\E?_[ mu ] f" (at level 2, format "\E?_[ mu ] f"). Reserved Notation "\E_[ mu ] f" (at level 2, format "\E_[ mu ] f"). Reserved Notation "\E_[ mu , A ] f" (at level 2, format "\E_[ mu , A ] f"). -Reserved Notation "\Ee_[ mu ] f" (at level 2, format "\Ee_[ mu ] f"). Local Notation "\`| f |" := (fun x => `|f x|) (at level 2). @@ -75,50 +93,51 @@ HB.structure Definition SubPmf {R : realType} {T : choiceType} := Arguments subpmf_ge0 {R T} _. Arguments subpmf_sum_le1 {R T} _. -Notation "R .-pmf T" := (@SubPmf.type R T) - (at level 1, T at level 2, format "R .-pmf T ") : type_scope. - #[global] Hint Extern 0 (is_true (0 <= _)) => solve [apply: subpmf_ge0] : core. #[global] Hint Resolve subpmf_summable : core. -Lemma subpmf_le1 {R : realType} {T : choiceType} (mu : R.-pmf T) x : mu x <= 1. -Proof. -rewrite -lee_fin; apply: le_trans; last exact: subpmf_sum_le1 mu. -by rewrite esum_ge1// => ? _; rewrite lee_fin. -Qed. -Section StdDefs. -Context {R : realType} (T : choiceType). -Implicit Types (mu : R.-pmf T) (A B E : pred T) (f : T -> R). +Notation "R .-pmf T" := (@SubPmf.type R T) + (at level 1, T at level 2, format "R .-pmf T ") : type_scope. -Definition dinsupp mu := fun x => mu x != 0 :> R. +Section SubProbability_measure_subpmf. +Context {R : realType} {T : choiceType} (mu : R.-pmf T). -Lemma in_dinsupp x (mu : R.-pmf T) : (x \in dinsupp mu) = (mu x != 0). -Proof. by []. Qed. +Definition measure_of_pmf (S : set (discrete_measurable_space T)) := + \esum_(x in S) (EFin \o mu) x. -Lemma dinsuppP mu x : reflect (mu x <> 0) (x \in dinsupp mu). -Proof. by apply: (iffP idP) => /eqP. Qed. +Let P0 : measure_of_pmf set0 = 0%E. +Proof. by rewrite /measure_of_pmf esum_set0. Qed. -Lemma dinsuppPn mu x : reflect (mu x = 0) (x \notin dinsupp mu). -Proof. by rewrite -topredE /dinsupp /= negbK; apply/eqP. Qed. +Let P_ge0 (S : set (discrete_measurable_space T)) : (0 <= measure_of_pmf S)%E. +Proof. by apply: esum_ge0 => x _; rewrite lee_fin. Qed. -Definition pr mu E := fine (\esum_(x in [set: T]) ((E x)%:R * mu x)%:E). -Definition prc mu E A := pr mu [predI E & A] / pr mu A. -Definition expectation_pmf mu f := fine (\esum_(x in [set: T]) (f x * mu x)%:E). -Definition espc mu f A := fine (\esum_(x in [set: T]) (f x * prc mu (pred1 x) A)%:E). +Let P_sigma_additive : semi_sigma_additive measure_of_pmf. +Proof. +move=> F _ tF _. +rewrite [X in _ --> X](_ : _ = \sum_(i n; exact: P_ge0. + apply: esum_bigcup => //=. + exact: (sub_trivIset (@subsetT _ _) tF). + by move=> x; rewrite lee_fin. +apply: cvg_toP => //. +apply: is_cvg_nneseries => n _ _; rewrite /measure_of_pmf. +by apply: esum_ge0 => x _; rewrite lee_fin. +Qed. -Definition has_expectation_pmf mu f := esummable [set: T] (EFin \o (f \* mu)). -End StdDefs. +HB.instance Definition _ := isMeasure.Build _ _ _ measure_of_pmf + P0 P_ge0 P_sigma_additive. -Notation "\P_[ mu ] E" := (pr mu E). -Notation "\P_[ mu , A ] E" := (prc mu E A). -Notation "\E_[ mu ] f" := (expectation_pmf mu f). -Notation "\E_[ mu , A ] f" := (espc mu f A). -Notation "\E?_[ mu ] f" := (has_expectation_pmf mu f). -Notation dweight mu := (\P_[mu] predT). +Let P_setT : (measure_of_pmf [set: discrete_measurable_space T] <= 1)%E. +Proof. by rewrite /measure_of_pmf esum_setT_discrete; exact: subpmf_sum_le1. Qed. + +HB.instance Definition _ := + @Measure_isSubProbability.Build _ _ R measure_of_pmf P_setT. + +End SubProbability_measure_subpmf. HB.factory Record uniq_isSubPmf {R : realType} {T : choiceType} (mu : T -> R) := { - subpmf_ge0 : forall x, 0 <= mu x ; + subpmf_ge0 : forall x : T, 0 <= mu x ; uniq_subpmf_le1 : forall J, uniq J -> \sum_(j <- J) mu j <= 1 }. HB.builders Context {R : realType} {T : choiceType} (mu : T -> R) @@ -149,6 +168,72 @@ HB.instance Definition _ := @isSubPmf.Build R T mu pmf_ge0 pmf_summable pmf_le1. HB.end. +Section pmf_subpmf. +Import MeasurableR. +Context {d} {T : measurableType d} {R : realType} (P : probability T R) + (X : {RV P >-> R}). + +Lemma pmf_fin_bigcup (J : seq R) : uniq J -> + \sum_(j <- J) (pmf X j)%:E = P (\bigcup_(j in [set` J]) X @^-1` [set j]). +Proof. +move=> uJ. +rewrite (@measure_fin_bigcup _ _ _ P _ [set` J] (fun j : R => X @^-1` [set j]))//. +- exact: finite_seq. +- exact: trivIset_preimage1. +- rewrite fsbig_seq//; apply: eq_fsbigr => j _. + by rewrite /pmf fineK// fin_num_measure. +Qed. + +Let pmf_uniq_le1 (J : seq R) : uniq J -> (\sum_(j <- J) pmf X j <= 1)%R. +Proof. +move=> uJ; rewrite -lee_fin -sumEFin pmf_fin_bigcup//. +by rewrite probability_le1//; exact: fin_bigcup_measurable. +Qed. + +HB.instance Definition _ := + @uniq_isSubPmf.Build R R (pmf X) (@pmf_ge0 _ _ _ P X) pmf_uniq_le1. + +Check (pmf X : R.-pmf R). + +End pmf_subpmf. + +Lemma subpmf_le1 {R : realType} {T : choiceType} (mu : R.-pmf T) x : mu x <= 1. +Proof. +rewrite -lee_fin; apply: le_trans; last exact: subpmf_sum_le1 mu. +by rewrite esum_ge1// => ? _; rewrite lee_fin. +Qed. + +Section StdDefs. +Context {R : realType} (T : choiceType). +Implicit Types (mu : R.-pmf T) (A B E : pred T) (f : T -> R). + +Definition dinsupp mu := fun x => mu x != 0 :> R. + +Lemma in_dinsupp x (mu : R.-pmf T) : (x \in dinsupp mu) = (mu x != 0). +Proof. by []. Qed. + +Lemma dinsuppP mu x : reflect (mu x <> 0) (x \in dinsupp mu). +Proof. by apply: (iffP idP) => /eqP. Qed. + +Lemma dinsuppPn mu x : reflect (mu x = 0) (x \notin dinsupp mu). +Proof. by rewrite -topredE /dinsupp /= negbK; apply/eqP. Qed. + +Definition pr mu E := fine (\esum_(x in [set: T]) ((E x)%:R * mu x)%:E). +Definition prc mu E A := pr mu [predI E & A] / pr mu A. +Definition expectation_pmf mu f := fine (\esum_(x in [set: T]) (f x * mu x)%:E). +Definition espc mu f A := fine (\esum_(x in [set: T]) (f x * prc mu (pred1 x) A)%:E). + +Definition has_expectation_pmf mu f := esummable [set: T] (EFin \o (f \* mu)). +End StdDefs. + +Notation "\P_[ mu ] E" := (pr mu E). +Notation "\P_[ mu , A ] E" := (prc mu E A). +Notation "\E_[ mu ] f" := (expectation_pmf mu f). +Notation "\E_[ mu , A ] f" := (espc mu f A). +Notation "\E?_[ mu ] f" := (has_expectation_pmf mu f). +Notation dweight mu := (\P_[mu] predT). + + Definition sub_distr {R : realType} {T : choiceType} (mu : T -> R) := (forall x, 0 <= mu x) /\ (forall J, uniq J -> \sum_(j <- J) mu j <= 1). @@ -217,6 +302,53 @@ Lemma drestrE (mu : R.-pmf T) x : Proof. by unlock drestr. Qed. End Restr. +Section pr_pmf. +Import MeasurableR. +Context {d} {T : pmeasurableType d} {R : realType} (P : probability T R) + (X : {dRV P >-> R}). + +Local Notation pmfX := (@pmf _ _ _ P X). + +Lemma esum_pmf_range : + esum [set: R] (EFin \o pmfX) = \esum_(r in range X) (pmfX r)%:E. +Proof. +rewrite (esumID (range X) [set: R] (EFin \o pmfX)). +- by move=> i _; rewrite lee_fin. +rewrite setTI [X in _ + X]esum1 ?adde0//= => r [_ /= nr]. +by rewrite not_range_pmf0. +Qed. + +Lemma esum_pmf_dRV : esum [set: R] (EFin \o pmfX) = 1%E. +Proof. +rewrite esum_pmf_range. +rewrite (reindex_esum (dRV_dom X) (range X) (dRV_enum X))//. +transitivity (\esum_(k in dRV_dom X) enum_prob X k). + apply: eq_esum => k kd/=. + by rewrite /enum_prob patchE mem_set// /pmf fineK// fin_num_measure. +rewrite -[X in \esum_(k in X) _]set_mem_set -nneseries_esum. +- by move=> n _; rewrite /enum_prob patchE; case: ifP. +- rewrite eseries_mkcond -[RHS](sum_enum_prob X measurable_set1). + apply: eq_eseriesr => k _; case: ifPn => // kd. + by rewrite /enum_prob patchE (negbTE kd). +Qed. + +Lemma esum_pmf_pred (A : set R) : + esum [set: R] (EFin \o (fun r => (r \in A)%:R * pmfX r))%R = + \esum_(r in A) (pmfX r)%:E. +Proof. +rewrite [RHS]esum_mkcond; apply: eq_esum => r _. +by case: (r \in A) => /=; rewrite ?mul1r ?mul0r. +Qed. + +Lemma pr_pmf_dRV (A : set R) : measurable A -> + (\P_[pmfX] (mem A))%:E = distribution P X A. +Proof. +move=> mA; rewrite /pr esum_pmf_pred dRV_esum_pmf_distribution// fineK//. +by rewrite fin_num_measure. +Qed. + +End pr_pmf. + (* -------------------------------------------------------------------- *) Section RestrTheory. Context {R : realType} {T : choiceType}. @@ -1171,8 +1303,8 @@ by case: ifP => xy; rewrite ?xy /= ?mul1r ?mul0r. Qed. (* -------------------------------------------------------------------- *) -Lemma pr_exp mu (E : pred T) : \P_[mu] E = \E_[mu] (fun m => (E m)%:R). -Proof. by []. Qed. +Lemma pr_exp mu (Q : pred T) : \P_[mu] Q = \E_[mu] (fun m => (Q m)%:R). +Proof. by []. Qed. Lemma pr_predT mu : \P_[mu] predT = fine (esum [set: T] (EFin \o mu)). Proof. @@ -1303,17 +1435,52 @@ Definition eexpectation_pmf mu f := \esum_(x in [set:T]) (f x * (mu x)%:E)%E. End Esp. -Notation "\Ee_[ mu ] f" := (eexpectation_pmf mu f). +Section Expectation. +Context {R : realType} {T : choiceType} (mu : R.-pmf T). + +Local Open Scope ereal_scope. + +Lemma integral_measure_of_pmf (f : T -> \bar R) : (forall x, 0 <= f x)%E -> + \int[measure_of_pmf mu]_x f x = \esum_(x in [set: T]) (f x * (mu x)%:E)%E. +Proof. +move=> f0; rewrite -esum_setT_discrete -integral_counting_esum//=. +rewrite -(@integral_measure_of_density _ (discrete_measurable_space T) R + (@counting (discrete_measurable_space T) R) mu)//=. +move => H; apply: eq_measure_integral => A mA _ /=. +by rewrite /measure_of_density /measure_of_pmf integral_counting_esum. +Qed. + +Lemma eexpectationE (f : T -> \bar R) : + 'E_(measure_of_pmf mu)[f] = \esum_(x in [set:T]) ((f x) * (mu x)%:E)%E. +Proof. +rewrite expectation_def integralE esumE; congr (_ - _). +- rewrite integral_measure_of_pmf//. + apply: eq_esum => x _. + by rewrite !funeposE maxe_pMl ?mul0e// lee_fin. +- rewrite integral_measure_of_pmf//. + apply: eq_esum => x _. + by rewrite !funenegE maxe_pMl ?mul0e ?mulNe// lee_fin. +Qed. + +End Expectation. Section EspeCoreTheory. Context {R : realType} {T : choiceType}. Implicit Types (mu : R.-pmf T) (A B E : pred T). -Lemma eexp_eq (f g: T -> \bar R) mu : f =1 g -> \Ee_[mu] f = \Ee_[mu] g. -Proof. by move=> fg; apply: eq_esum => ? _; rewrite fg. Qed. +Local Open Scope ereal_scope. + +Lemma eexp_eq (f g: T -> \bar R) mu : f =1 g -> + 'E_(measure_of_pmf mu) [f] = 'E_(measure_of_pmf mu) [g]. +Proof. +move=> fg. +rewrite unlock. +by apply: eq_integral => //. +Qed. -Lemma eexp_dunit (f : T -> \bar R) (x : T) : \Ee_[dunit x] f = f x. +Lemma eexp_dunit (f : T -> \bar R) (x : T) : 'E_(measure_of_pmf (dunit x)) [f] = f x. Proof. +rewrite eexpectationE. rewrite /eexpectation_pmf. rewrite (eq_esum _ _ (fun y : T => if x == y then f y else 0%R)%E). + move => x0. rewrite dunit1E. @@ -1321,9 +1488,11 @@ rewrite (eq_esum _ _ (fun y : T => if x == y then f y else 0%R)%E). by rewrite esum_if_eq_op_set1. Qed. -Lemma eexp_cst mu r : (\Ee_[mu] (cst r) = (\P_[mu] predT)%:E * r)%E. +Lemma eexp_cst mu r : ('E_(measure_of_pmf mu) [(cst r)] = (\P_[mu] predT)%:E * r)%E. Proof. -rewrite pr_predT /eexpectation_pmf //. +rewrite pr_predT. +rewrite eexpectationE. +rewrite /eexpectation_pmf //. rewrite esumZ. - move => ?; rewrite lee_fin //. rewrite muleC; congr ( _ * _)%E. @@ -1331,14 +1500,16 @@ rewrite fineK //= esum_abse => //=. by have := @subpmf_summable _ _ mu; rewrite esummableE. Qed. -Lemma eexp0 mu : \Ee_[mu] (cst 0) = 0. +Lemma eexp0 mu : 'E_(measure_of_pmf mu) [(cst 0)] = 0. Proof. by rewrite eexp_cst mule0. Qed. Lemma eexp_dlet {U: choiceType} mu (nu : T -> R.-pmf U) F : (forall x, 0%:E <= F x)%E -> - \Ee_[dlet nu mu] F = \Ee_[mu] (fun x => \Ee_[nu x] F). + 'E_(measure_of_pmf (dlet nu mu)) [F] = 'E_(measure_of_pmf mu) [fun x => 'E_(measure_of_pmf (nu x)) [F] ]. Proof. move => HF. +rewrite 2!eexpectationE. +under [in RHS]eq_esum do (rewrite eexpectationE). have pos : (forall (i : T) (j : U), (0%R <= F j * ((mu i)%:E * (nu i j)%:E))%E). - move => i j; rewrite mule_ge0 //. by rewrite mule_ge0 // lee_tofin. @@ -1362,9 +1533,8 @@ rewrite {1}(eq_esum _ _ (fun x0 : U => F x0 * ((mu x)%:E * (nu x x0)%:E))%E) // ?esum_sum' //. - by move => ??; rewrite muleCA. rewrite exchange_esum //. -rewrite {1}(eq_esum _ _ - (fun x => (F x * (\esum_(y in [set: T]) (mu y * nu y x)%:E))%E)) //. -- move => ??. rewrite esumZ //. +apply: eq_esum => u _. +rewrite esumZ //. by move => ?; rewrite mule_ge0 // lee_tofin. Qed. @@ -1372,9 +1542,10 @@ Local Open Scope ereal_scope. Lemma eexpZ mu F c : (forall x, 0%:E <= F x)%E -> - \Ee_[mu] (fun x => c * F x) = c * \Ee_[mu] F. + 'E_(measure_of_pmf mu)[fun x => c * F x] = c * 'E_(measure_of_pmf mu) [F]. Proof. move => h. +rewrite !eexpectationE. rewrite -esumZ. + by move => x; rewrite mule_ge0 // lee_tofin. by apply/eq_esum => x ?; rewrite muleA. @@ -1384,32 +1555,40 @@ Lemma eexpB mu (A B : T -> \bar R) : (forall x, A x \is a fin_num) -> esummable [set: T] (fun x => (A x * (mu x)%:E)%E) -> esummable [set: T] (fun x => (B x * (mu x)%:E)%E) -> - \Ee_[mu] (A \- B)%E = (\Ee_[mu] A - \Ee_[mu] B)%E. + 'E_(measure_of_pmf mu) [(A \- B)%E] = ('E_(measure_of_pmf mu)[A] - 'E_(measure_of_pmf mu) [B])%E. Proof. -move=> fA sA sB; rewrite /eexpectation_pmf. +move=> fA sA sB. +rewrite !eexpectationE. rewrite (esum.eq_esum _ _ (fun x => (A x * (mu x)%:E - B x * (mu x)%:E)%E)). by move => x ? /=; rewrite muleBl//; apply: fin_num_adde_defr; exact: fA. exact: (esummable_esumB sA sB). Qed. Lemma espE mu (g : T -> R) : - \E_[mu] g = fine (\Ee_[mu] (EFin \o g)). + \E_[mu] g = fine ('E_(measure_of_pmf mu) [EFin \o g]). Proof. +rewrite eexpectationE. by rewrite /expectation_pmf /eexpectation_pmf; congr (fine _); apply: esum.eq_esum => x ? /=; rewrite EFinM. Qed. Lemma espeEFin mu (g : T -> R) : - \Ee_[mu] (EFin \o g) = esum [set: T] (EFin \o (fun x => g x * mu x))%R. -Proof. by rewrite /eexpectation_pmf; apply: esum.eq_esum => x ? /=; rewrite EFinM. Qed. + 'E_(measure_of_pmf mu) [EFin \o g] = esum [set: T] (EFin \o (fun x => g x * mu x))%R. +Proof. +rewrite eexpectationE. + by rewrite /eexpectation_pmf; apply: esum.eq_esum => x ? /=; rewrite EFinM. Qed. Lemma eexp_dlet_esp {U: choiceType} mu (nu : T -> R.-pmf U) (g : U -> R) : (forall y, 0 <= g y)%R -> (forall eta, \E?_[eta] g) -> - \Ee_[dlet nu mu] (EFin \o g) = \Ee_[mu] (EFin \o (fun x => \E_[nu x] g)). + 'E_(measure_of_pmf (dlet nu mu)) [EFin \o g] = + 'E_(measure_of_pmf mu) [EFin \o (fun x => \E_[nu x] g)]. Proof. move=> ? sg. rewrite (eexp_dlet mu nu ). + by move=> x; rewrite /= lee_fin. -apply eq_esum => ?? //=. +rewrite /=. +rewrite !eexpectationE. +apply: eq_esum => ?? //=. +rewrite eexpectationE. congr (_ * _)%E. rewrite /expectation_pmf fineK//. exact: (esummable_esum_fin_num (sg (nu _))). @@ -1417,6 +1596,64 @@ Qed. End EspeCoreTheory. +Section espe_pmf. +Import MeasurableR. +Context {d} {T : pmeasurableType d} {R : realType} (P : probability T R) + (X : {dRV P >-> R}). + +Local Notation pmfX := (@pmf d T R P X). + +Local Open Scope ereal_scope. + +Lemma distribution_integral_counting (A : set R) : measurable A -> + distribution P X A = \int[@counting R R]_(r in A) (pmfX r)%:E. +Proof. +move=> mA. +rewrite -dRV_esum_pmf_distribution// integral_counting_esum//=. +by apply/measurable_EFinP; exact: pmf_measurable. +Qed. + +Lemma ge0_espe_pmf (f : R -> \bar R) : + measurable_fun [set: R] f -> (forall r, 0 <= f r) -> + 'E_(measure_of_pmf pmfX) [f] = \int[P]_w f (X w). +Proof. +move=> mf f0. +(*rewrite unlock/=. +rewrite -ge0_integral_distribution//.*) +rewrite eexpectationE. +have mfh : measurable_fun [set: R] (fun r => f r * (pmfX r)%:E). + by apply: emeasurable_funM => //; apply/measurable_EFinP; exact: pmf_measurable. +have fh0 r : 0 <= f r * (pmfX r)%:E. + by apply: mule_ge0; [exact: f0|rewrite lee_fin pmf_ge0]. +rewrite [LHS](_ : _ = \int[@counting R R]_r (f r * (pmfX r)%:E)). + by rewrite /eexpectation_pmf -integral_counting_esum//; exact: measurable_set1. +have <- : \int[distribution P X]_r f r = + \int[@counting R R]_r (f r * (pmfX r)%:E). + rewrite -(integral_measure_of_density _ (pmf_measurable X))//=. + apply: eq_measure_integral => A mA _ /=. + exact: distribution_integral_counting. +by rewrite /distribution ge0_integral_pushforward. +Qed. + +Lemma espe_pmf_dRV : 'E_(measure_of_pmf pmfX) [EFin] = 'E_P[EFin \o X]. +Proof. +rewrite eexpectationE. +rewrite /eexpectation_pmf esumE expectation_def integralE; congr (_ - _). +- transitivity ('E_(measure_of_pmf pmfX) [(@EFin R)^\+%E]). + rewrite eexpectationE. + by apply: eq_esum => r _; rewrite !funeposE maxe_pMl ?lee_fin// mul0e. + rewrite ge0_espe_pmf => //=; first exact: measurable_funepos. + by apply: eq_integral => w _; rewrite !funeposE. +- transitivity ('E_(measure_of_pmf pmfX) [(@EFin R)^\-%E]). + rewrite eexpectationE. + by apply: eq_esum => r _; rewrite !funenegE maxe_pMl ?lee_fin// mul0e mulNe. + rewrite ge0_espe_pmf//=; first exact: measurable_funeneg. + by apply: eq_integral => w _; rewrite !funenegE. +Qed. + +End espe_pmf. + + (* -------------------------------------------------------------------- *) Section PrTheory. Context {R : realType} {T U : choiceType} {I : eqType}. @@ -1814,6 +2051,7 @@ rewrite !espE -fineB //. + by rewrite espeEFin; exact: (esummable_esum_fin_num sf). + by rewrite espeEFin; exact: (esummable_esum_fin_num sg). congr (fine _). +transitivity ('E_(measure_of_pmf eta)[((EFin \o f) \- (EFin \o g))%E])%E => //. rewrite {1}(@eexp_eq _ _ _ (fun x => (f x)%:E - (g x)%:E)%E). + move => ?. rewrite -EFinB //. exact : eexpB. diff --git a/theories/probability_theory/independence.v b/theories/probability_theory/independence.v index 96b881e56c..74bc20f8a7 100644 --- a/theories/probability_theory/independence.v +++ b/theories/probability_theory/independence.v @@ -564,7 +564,7 @@ Lemma independent_Lfun1_expectation_product_measure_lty (X Y : {RV P >-> R}) : independent_RVs2 P X Y -> (X : _ -> _) \in Lfun P 1 -> (Y : _ -> _) \in Lfun P 1 -> 'E_((P \x P) : probability (T * T)%type R) - [(fun x => `|X x.1 * Y x.2|)%R] < +oo. + [(fun x => `|X x.1 * Y x.2|%:E)] < +oo. Proof. move=> indeXY iX iY. rewrite unlock [ltLHS](_ : _ = @@ -610,19 +610,20 @@ Import MeasurableR. (forall y y', y \in range f -> y' \in range g -> P (f @^-1` [set y] `&` g @^-1` [set y']) = P (f @^-1` [set y]) * P (g @^-1` [set y'])) -> - 'E_P [f \* g] = 'E_P [f] * 'E_P [g]. + 'E_P [EFin \o (f \* g)%R] = 'E_P [EFin \o f] * 'E_P [EFin \o g]. Proof. move=> fg; transitivity - ('E_P [(fun x => (\sum_(y \in range f) y * \1_(f @^-1` [set y]) x)%R) - \* (fun x => (\sum_(y \in range g) y * \1_(g @^-1` [set y]) x)%R)]). + ('E_P [EFin \o ((fun x => (\sum_(y \in range f) y * \1_(f @^-1` [set y]) x)%R) + \* (fun x => (\sum_(y \in range g) y * \1_(g @^-1` [set y]) x)%R))%R]). by congr ('E_P [_]); apply/funext => t/=; rewrite (fimfunE f) (fimfunE g). -transitivity ('E_P [(fun x => (\sum_(y \in range f) \sum_(y' \in range g) y * y' - * \1_(f @^-1` [set y] `&` g @^-1` [set y']) x)%R)]). +transitivity ('E_P [EFin \o ((fun x => (\sum_(y \in range f) \sum_(y' \in range g) y * y' + * \1_(f @^-1` [set y] `&` g @^-1` [set y']) x)%R))]). congr ('E_P [_]); apply/funext => t/=. - rewrite mulr_fsuml; apply: eq_fsbigr => y yf; rewrite mulr_fsumr. + rewrite mulr_fsuml; congr EFin. + apply: eq_fsbigr => y yf; rewrite mulr_fsumr. by apply: eq_fsbigr => y' y'g; rewrite indicI mulrCA !mulrA (mulrC y'). rewrite unlock. -under eq_integral do rewrite -fsumEFin//. +under eq_integral do rewrite /= -fsumEFin//. transitivity (\sum_(y \in range f) (\sum_(y' \in range g) ((y * y')%:E * \int[P]_w (\1_(f @^-1` [set y] `&` g @^-1` [set y']) w)%:E))). rewrite ge0_integral_fsum//=. @@ -646,9 +647,9 @@ transitivity (\sum_(y \in range f) (\sum_(y' \in range g) ((y * y')%:E * ((\int[P]_w (\1_(f @^-1` [set y]) w)%:E) * \int[P]_w (\1_(g @^-1` [set y']) w)%:E)))). apply: eq_fsbigr => y fy; apply: eq_fsbigr => y' gy'; congr *%E. - transitivity ('E_P[\1_(f @^-1` [set y] `&` g @^-1` [set y'])]). + transitivity ('E_P[EFin \o \1_(f @^-1` [set y] `&` g @^-1` [set y'])]). by rewrite unlock. - transitivity ('E_P[\1_(f @^-1` [set y])] * 'E_P[\1_(g @^-1` [set y'])]); + transitivity ('E_P[EFin \o \1_(f @^-1` [set y])] * 'E_P[EFin \o \1_(g @^-1` [set y'])]); last by rewrite unlock. rewrite expectation_indic//; first exact: measurableI. by rewrite !expectation_indic//; exact: fg. @@ -683,16 +684,16 @@ Qed. Lemma ge0_independent_expectationM (X Y : {RV P >-> R}) : independent_RVs2 P X Y -> - 'E_P[X] *? 'E_P[Y] -> + 'E_P[EFin \o X] *? 'E_P[EFin \o Y] -> (forall t, 0 <= X t)%R -> (forall t, 0 <= Y t)%R -> - 'E_P [X * Y] = 'E_P [X] * 'E_P [Y]. + 'E_P [EFin \o (X * Y)%R] = 'E_P [EFin \o X] * 'E_P [EFin \o Y]. Proof. move=> indeXY defXY X0 Y0. have mX : measurable_fun setT (EFin \o X) by exact/measurable_EFinP. have mY : measurable_fun setT (EFin \o Y) by exact/measurable_EFinP. pose X_ := nnsfun_approx measurableT mX. pose Y_ := nnsfun_approx measurableT mY. -have EXY : 'E_P[X_ n \* Y_ n] @[n --> \oo] --> 'E_P [X * Y]. +have EXY : 'E_P[EFin \o (X_ n \* Y_ n)%R] @[n --> \oo] --> 'E_P [EFin \o (X * Y)%R]. rewrite unlock; have -> : \int[P]_w ((X * Y) w)%:E = \int[P]_x limn (fun n => (EFin \o (X_ n \* Y_ n)%R) x). apply: eq_integral => t _; apply/esym/cvg_lim => //=. @@ -704,7 +705,7 @@ have EXY : 'E_P[X_ n \* Y_ n] @[n --> \oo] --> 'E_P [X * Y]. - by move=> n t _; rewrite lee_fin. - move=> t _ m n mn. by rewrite lee_fin/= ler_pM//; exact/lefP/nd_nnsfun_approx. -have EX : 'E_P[X_ n] @[n --> \oo] --> 'E_P [X]. +have EX : 'E_P[EFin \o X_ n] @[n --> \oo] --> 'E_P [EFin \o X]. rewrite unlock. have -> : \int[P]_w (X w)%:E = \int[P]_x limn (fun n => (EFin \o X_ n) x). by apply: eq_integral => t _; apply/esym/cvg_lim => //=; @@ -713,7 +714,7 @@ have EX : 'E_P[X_ n] @[n --> \oo] --> 'E_P [X]. - by move=> n; exact/measurable_EFinP. - by move=> n t _; rewrite lee_fin. - by move=> t _ m n mn; rewrite lee_fin/=; exact/lefP/nd_nnsfun_approx. -have EY : 'E_P[Y_ n] @[n --> \oo] --> 'E_P [Y]. +have EY : 'E_P[EFin \o Y_ n] @[n --> \oo] --> 'E_P [EFin \o Y]. rewrite unlock. have -> : \int[P]_w (Y w)%:E = \int[P]_x limn (fun n => (EFin \o Y_ n) x). by apply: eq_integral => t _; apply/esym/cvg_lim => //=; @@ -722,9 +723,9 @@ have EY : 'E_P[Y_ n] @[n --> \oo] --> 'E_P [Y]. - by move=> n; exact/measurable_EFinP. - by move=> n t _; rewrite lee_fin. - by move=> t _ m n mn; rewrite lee_fin/=; exact/lefP/nd_nnsfun_approx. -have {EX EY}EXY' : 'E_P[X_ n] * 'E_P[Y_ n] @[n --> \oo] --> 'E_P[X] * 'E_P[Y]. +have {EX EY}EXY' : 'E_P[EFin \o X_ n] * 'E_P[EFin \o Y_ n] @[n --> \oo] --> 'E_P[EFin \o X] * 'E_P[EFin \o Y]. apply: cvgeM => //. -suff : forall n, 'E_P[X_ n \* Y_ n] = 'E_P[X_ n] * 'E_P[Y_ n]. +suff : forall n, 'E_P[EFin \o (X_ n \* Y_ n)%R] = 'E_P[EFin \o X_ n] * 'E_P[EFin \o Y_ n]. by move=> suf; apply: (cvg_unique _ EXY) => //=; under eq_fun do rewrite suf. move=> n; apply: expectationM_nnsfun => x y xX_ yY_. suff : P (\big[setI/setT]_(j <- [fset false; true]%fset) @@ -784,10 +785,10 @@ Import MeasurableR. Lemma independent_Lfun1_expectationM_lty (X Y : {RV P >-> R}) : independent_RVs2 P X Y -> (X : _ -> _) \in Lfun P 1 -> (Y : _ -> _) \in Lfun P 1 -> - `|'E_P [X * Y]| < +oo. + `|'E_P [EFin \o (X * Y)%R]| < +oo. Proof. move=> indeXY iX iY. -apply: (@le_lt_trans _ _ 'E_P[(@normr _ _ \o X) * (@normr _ _ \o Y)]). +apply: (@le_lt_trans _ _ 'E_P[EFin \o ((@normr _ _ \o X) * (@normr _ _ \o Y))%R]). rewrite unlock/= (le_trans (le_abse_integral _ _ _))//. apply/measurable_EFinP/measurable_funM. by move/Lfun1_integrable : iX => /measurable_int/measurable_EFinP. @@ -828,10 +829,10 @@ Qed. Lemma independent_expectationM (X Y : {RV P >-> R}) : independent_RVs2 P X Y -> (X : _ -> _) \in Lfun P 1 -> (Y : _ -> _) \in Lfun P 1 -> - 'E_P [X * Y] = 'E_P [X] * 'E_P [Y]. + 'E_P [EFin \o (X * Y)%R] = 'E_P [EFin \o X] * 'E_P [EFin \o Y]. Proof. move=> XY iX iY. -transitivity ('E_P[(X^\+ - X^\-) * (Y^\+ - Y^\-)]). +transitivity ('E_P[EFin \o ((X^\+ - X^\-) * (Y^\+ - Y^\-))%R]). by congr ('E_P[_]); apply/funext => /= t; rewrite !funrposBneg. have ? : X^\-%R \in Lfun P 1. apply/Lfun1_integrable; rewrite -funerneg; apply/integrable_funeneg => //. @@ -856,8 +857,8 @@ have ? : (X^\+ \* Y^\-)%R \in Lfun P 1. by apply: independent_Lfun1M => //=; exact: independent_RVs2_funrposneg. have ? : (X^\- \* Y^\-)%R \in Lfun P 1. by apply: independent_Lfun1M => //=; exact: independent_RVs2_funrnegneg. -transitivity ('E_P[X^\+ * Y^\+] - 'E_P[X^\- * Y^\+] - - 'E_P[X^\+ * Y^\-] + 'E_P[X^\- * Y^\-]). +transitivity ('E_P[EFin \o (X^\+ * Y^\+)%R] - 'E_P[EFin \o (X^\- * Y^\+)%R] + - 'E_P[EFin \o (X^\+ * Y^\-)%R] + 'E_P[EFin \o (X^\- * Y^\-)%R]). rewrite mulrDr !mulrDl -!expectationB//=; first by rewrite rpredB. rewrite -expectationD//=; first by rewrite !rpredB. congr ('E_P[_]); apply/funext => t/=. @@ -874,7 +875,7 @@ rewrite [in LHS]ge0_independent_expectationM//=. rewrite [in LHS]ge0_independent_expectationM//=. exact: independent_RVs2_funrnegneg. by rewrite mule_def_fin// expectation_fin_num. -transitivity ('E_P[X^\+ - X^\-] * 'E_P[Y^\+ - Y^\-]); last first. +transitivity ('E_P[EFin \o (X^\+ - X^\-)%R] * 'E_P[EFin \o (Y^\+ - Y^\-)%R]); last first. by rewrite !funrposBneg. rewrite -addeA -addeACA -muleBr. by rewrite expectation_fin_num. diff --git a/theories/probability_theory/random_variable.v b/theories/probability_theory/random_variable.v index efebbbfa82..83de0efa5c 100644 --- a/theories/probability_theory/random_variable.v +++ b/theories/probability_theory/random_variable.v @@ -526,7 +526,7 @@ Qed. End complementary_cumulative_distribution_function. HB.lock Definition expectation {d} {T : measurableType d} {R : realType} - (P : subprobability T R) (X : T -> R) := (\int[P]_w (X w)%:E)%E. + (P : subprobability T R) (X : T -> \bar R) := (\int[P]_w X w)%E. Canonical expectation_unlockable := Unlockable expectation.unlock. Arguments expectation {d T R} P _%_R. Notation "''E_' P [ X ]" := (@expectation _ _ _ P X) : ereal_scope. @@ -536,59 +536,57 @@ Local Open Scope ereal_scope. Context d (T : measurableType d) (R : realType) (P : subprobability T R). Import MeasurableR. -Lemma expectation_def (X : T -> R) : 'E_P[X] = (\int[P]_w (X w)%:E)%E. +Lemma expectation_def (X : T -> \bar R) : 'E_P[X] = (\int[P]_w X w)%E. Proof. by rewrite unlock. Qed. Lemma expectation_fin_num (X : T -> R) : X \in Lfun P 1 -> - 'E_P[X] \is a fin_num. + 'E_P[EFin \o X] \is a fin_num. Proof. by move=> ?; rewrite unlock integrable_fin_num//; exact/Lfun1_integrable. Qed. -Lemma expectation_indic (A : set T) (mA : measurable A) : 'E_P[\1_A] = P A. +Lemma expectation_indic (A : set T) (mA : measurable A) : 'E_P[EFin \o \1_A] = P A. Proof. by rewrite unlock integral_indic// setIT. Qed. Lemma integrable_expectation (X : T -> R) : - X \in Lfun P 1 -> `| 'E_P[X] | < +oo. + X \in Lfun P 1 -> `| 'E_P[EFin \o X] | < +oo. Proof. move/Lfun1_integrable => /integrableP[? Xoo]; rewrite (le_lt_trans _ Xoo)//. by rewrite expectation_def (le_trans (le_abse_integral _ _ _)). Qed. Lemma expectationZl (X : T -> R) (k : R) : X \in Lfun P 1 -> - 'E_P[k \o* X] = k%:E * 'E_P[X]. + 'E_P[EFin \o k \o* X] = k%:E * 'E_P[EFin \o X]. Proof. by move=> ?; rewrite unlock muleC -integralZr//; exact/Lfun1_integrable. Qed. -Lemma expectation_ge0 (X : T -> R) : (forall x, 0 <= X x)%R -> +Lemma expectation_ge0 (X : T -> \bar R) : (forall x, 0 <= X x)%E -> 0 <= 'E_P[X]. -Proof. -by move=> ?; rewrite unlock integral_ge0// => x _; rewrite lee_fin. -Qed. +Proof. by move=> ?; rewrite unlock integral_ge0. Qed. -Lemma expectation_le (X Y : T -> R) : +Lemma expectation_le (X Y : T -> \bar R) : measurable_fun [set: T] X -> measurable_fun [set: T] Y -> - (forall x, 0 <= X x)%R -> (forall x, 0 <= Y x)%R -> - {ae P, (forall x, X x <= Y x)%R} -> 'E_P[X] <= 'E_P[Y]. + (forall x, 0 <= X x)%E -> (forall x, 0 <= Y x)%E -> + {ae P, (forall x, X x <= Y x)%E} -> 'E_P[X] <= 'E_P[Y]. Proof. move=> mX mY X0 Y0 XY; rewrite unlock ae_ge0_le_integral => //. -- by move=> t _; apply: X0. +(*- by move=> t _; apply: X0. - exact/measurable_EFinP. - by move=> t _; apply: Y0. -- exact/measurable_EFinP. +- exact/measurable_EFinP.*) - move: XY => [N [mN PN XYN]]; exists N; split => // t /= h. - by apply: XYN => /=; apply: contra_not h; rewrite lee_fin. + by apply: XYN => /=; apply: contra_not h. Qed. Lemma expectationD (X Y : T -> R) : X \in Lfun P 1 -> Y \in Lfun P 1 -> - 'E_P[X \+ Y] = 'E_P[X] + 'E_P[Y]. + 'E_P[EFin \o (X \+ Y)%R] = 'E_P[EFin \o X] + 'E_P[EFin \o Y]. Proof. by move=> ? ?; rewrite unlock integralD_EFin//; exact/Lfun1_integrable. Qed. Lemma expectationB (X Y : T -> R) : X \in Lfun P 1 -> Y \in Lfun P 1 -> - 'E_P[X \- Y] = 'E_P[X] - 'E_P[Y]. + 'E_P[EFin \o (X \- Y)%R] = 'E_P[EFin \o X] - 'E_P[EFin \o Y]. Proof. by move=> ? ?; rewrite unlock integralB_EFin//; exact/Lfun1_integrable. Qed. @@ -600,14 +598,15 @@ Local Open Scope ereal_scope. Context {d} {T : measurableType d} {R : realType} (P : probability T R). Import MeasurableR. -Lemma expectation_cst r : 'E_P[cst r] = r%:E. +Lemma expectation_cst r : 'E_P[cst r] = r. Proof. by rewrite unlock/= integral_cst//= probability_setT mule1. Qed. Lemma expectation_sum (X : seq (T -> R)) : (forall Xi, Xi \in X -> Xi \in Lfun P 1) -> - 'E_P[\sum_(Xi <- X) Xi] = \sum_(Xi <- X) 'E_P[Xi]. + 'E_P[EFin \o (\sum_(Xi <- X) Xi)%R] = \sum_(Xi <- X) 'E_P[EFin \o Xi]. Proof. -elim: X => [|X0 X IHX] intX; first by rewrite !big_nil expectation_cst. +elim: X => [|X0 X IHX] intX. + by rewrite !big_nil/= (_ : _ \o _ = cst 0)// expectation_cst. rewrite !big_cons expectationD. - by rewrite intX// mem_head. - by rewrite big_seq rpred_sum// => Y YX/=; rewrite intX// inE YX orbT. @@ -624,7 +623,7 @@ Import MeasurableR. Let mu : {measure set _ -> \bar R} := @lebesgue_measure R. Lemma ge0_expectation_ccdf (X : {RV P >-> R}) : (forall x, 0 <= X x)%R -> - 'E_P[X] = \int[mu]_(r in `[0%R, +oo[) ccdf X r. + 'E_P[EFin \o X] = \int[mu]_(r in `[0%R, +oo[) ccdf X r. Proof. pose GR := measurableTypeR R. pose distrX := distribution P X. @@ -686,7 +685,7 @@ by move=> /(_ measurableT [set true]); rewrite setTI; exact. Qed. Let ge0_expectation_preimage (X : {RV P >-> R}) : (forall x, 0 <= X x)%R -> - 'E_P[X] = \int[mu]_(r in `[0%R, +oo[) P (X @^-1` `[r, +oo[). + 'E_P[EFin \o X] = \int[mu]_(r in `[0%R, +oo[) P (X @^-1` `[r, +oo[). Proof. have mPeqr : measurable_fun setT (fun r => P (X @^-1` [set r])). apply: (eq_measurable_fun (EFin \o pmf X)) => [r/= _|]. @@ -714,7 +713,7 @@ apply: eq_integral =>/= r _; rewrite -measureU//. Qed. Lemma le0_expectation_cdf (X : {RV P >-> R}) : (forall x, X x <= 0)%R -> - 'E_P[X] = - \int[mu]_(r in `]-oo, 0%R[) cdf X r. + 'E_P[EFin \o X] = - \int[mu]_(r in `]-oo, 0%R[) cdf X r. Proof. pose Y : {RV P >-> R} := (- X)%R. pose fPleY r := fine (P (Y @^-1` `[r, +oo[)). @@ -725,7 +724,7 @@ have mfPleY : measurable_fun setT fPleY. by apply: preimage_subset; apply: subset_itvr; rewrite bnd_simp. move=> X_le0. have Y_ge0 x : (0 <= Y x)%R by rewrite oppr_ge0/=. -transitivity (- 'E_P[Y]). +transitivity (- 'E_P[EFin \o Y]). rewrite !expectation_def /Y -integral_ge0N/= => [x _|]. by rewrite lee_fin/= oppr_ge0. by apply: eq_integral => x _; rewrite opprK. @@ -758,7 +757,7 @@ by rewrite !in_itv/= lerNl le_max lerN2 (leNgt _ 0%R) oppr_gt0 r0 orbF. Qed. Lemma expectation_cdf_ccdf (X : {RV P >-> R}) : Lfun P 1 X -> - 'E_P[X] = \int[mu]_(r in `[0%R, +oo[) ccdf X r + 'E_P[EFin \o X] = \int[mu]_(r in `[0%R, +oo[) ccdf X r - \int[mu]_(r in `]-oo, 0%R[) cdf X r. Proof. move=> L1X. @@ -779,7 +778,7 @@ End tail_expectation_formula. HB.lock Definition covariance {d} {T : measurableType d} {R : realType} (P : probability T R) (X Y : T -> R) := - 'E_P[(X \- cst (fine 'E_P[X])) * (Y \- cst (fine 'E_P[Y]))]%E. + 'E_P[EFin \o ((X \- cst (fine 'E_P[EFin \o X])) * (Y \- cst (fine 'E_P[EFin \o Y])))%R]%E. Canonical covariance_unlockable := Unlockable covariance.unlock. Arguments covariance {d T R} P _%_R _%_R. @@ -793,16 +792,17 @@ Context d (T : measurableType d) (R : realType) (P : probability T R). Lemma covarianceE (X Y : T -> R) : X \in Lfun P 1 -> Y \in Lfun P 1 -> (X * Y)%R \in Lfun P 1 -> - covariance P X Y = 'E_P[X * Y] - 'E_P[X] * 'E_P[Y]. + covariance P X Y = 'E_P[EFin \o (X * Y)%R] - 'E_P[EFin \o X] * 'E_P[EFin \o Y]. Proof. move=> l1X l1Y l1XY. -rewrite unlock [X in 'E_P[X]](_ : _ = (X \* Y \- fine 'E_P[X] \o* Y - \- fine 'E_P[Y] \o* X \+ fine ('E_P[X] * 'E_P[Y]) \o* cst 1)%R). +rewrite unlock [X in 'E_P[X]](_ : _ = EFin \o (X \* Y \- fine 'E_P[EFin \o X] \o* Y + \- fine 'E_P[EFin \o Y] \o* X \+ fine ('E_P[EFin \o X] * 'E_P[EFin \o Y]) \o* cst 1)%R). apply/funeqP => x /=; rewrite mulrDr !mulrDl/= mul1r. rewrite fineM ?expectation_fin_num// mulrNN addrA. by rewrite mulrN mulNr [Z in (X x * Y x - Z)%R]mulrC. rewrite expectationD/= ?rpredB//= ?Lfun_scale ?Lfun_cst//. rewrite 2?expectationB//= ?rpredB ?Lfun_scale// 3?expectationZl//= ?Lfun_cst//. +rewrite [EFin \o cst 1%R](_ : _ = cst 1%E)//. rewrite expectation_cst mule1 fineM ?expectation_fin_num// EFinM. rewrite !fineK ?expectation_fin_num//. by rewrite muleC subeK ?fin_numM ?expectation_fin_num. @@ -823,7 +823,9 @@ Qed. Lemma covariance_cst_l c (X : T -> R) : covariance P (cst c) X = 0. Proof. -rewrite unlock expectation_cst/=. +rewrite unlock. +rewrite [EFin \o cst c](_ : _ = cst c%:E)//. +rewrite expectation_cst/=. rewrite [X in 'E_P[X]](_ : _ = cst 0%R) ?expectation_cst//. by apply/funeqP => x; rewrite !fctE/= subrr mul0r. Qed. @@ -933,7 +935,7 @@ Definition variance (X : T -> R) := covariance P X X. Local Notation "''V_' P [ X ]" := (variance X). Lemma varianceE (X : T -> R) : X \in Lfun P 2%:E -> - 'V_P[X] = 'E_P[X ^+ 2] - ('E_P[X]) ^+ 2. + 'V_P[X] = 'E_P[EFin \o (X ^+ 2)%R] - ('E_P[EFin \o X]) ^+ 2. Proof. move=> X2; rewrite /variance. by rewrite covarianceE ?Lfun2_mul_Lfun1// Lfun_subset12 ?fin_num_measure. @@ -953,7 +955,9 @@ Qed. Lemma variance_cst r : 'V_P[cst r] = 0%E. Proof. -rewrite /variance unlock expectation_cst/=. +rewrite /variance unlock. +rewrite (_ : _ \o cst r = cst r%:E)//. +rewrite expectation_cst/=. rewrite [X in 'E_P[X]](_ : _ = cst 0%R) ?expectation_cst//. by apply/funext => x; rewrite !fctE/= subrr mulr0. Qed. @@ -1065,7 +1069,7 @@ End variance. Notation "'V_ P [ X ]" := (variance P X). Definition mmt_gen_fun d (T : measurableType d) (R : realType) - (P : probability T R) (X : T -> R) (t : R) := ('E_P[expR \o t \o* X])%E. + (P : probability T R) (X : T -> R) (t : R) := ('E_P[EFin \o (expR \o t \o* X)])%E. Notation "'M_ P X" := (@mmt_gen_fun _ _ _ P X). Section markov_chebyshev_cantelli. @@ -1077,7 +1081,7 @@ Lemma markov (X : {RV P >-> R}) (f : R -> R) (eps : R) : (0 < eps)%R -> measurable_fun [set: R] f -> (forall r, 0 <= r -> 0 <= f r)%R -> {in Num.nneg &, {homo f : x y / x <= y}}%R -> (f eps)%:E * P [set x | eps%:E <= `| (X x)%:E | ] <= - 'E_P[f \o (fun x => `| x |%R) \o X]. + 'E_P[EFin \o (f \o (fun x => `| x |%R) \o X)]. Proof. move=> e0 mf f0 f_nd; rewrite -(setTI [set _ | _]). apply: (le_trans (@le_integral_comp_abse _ _ _ P _ measurableT (EFin \o X) @@ -1105,58 +1109,66 @@ by rewrite ger0_norm ?expR_ge0// lee_fin ler_expR mulrC ler_pM2r. Qed. Lemma chebyshev (X : {RV P >-> R}) (eps : R) : (0 < eps)%R -> - P [set x | (eps <= `| X x - fine ('E_P[X])|)%R ] <= (eps ^- 2)%:E * 'V_P[X]. + P [set x | (eps <= `| X x - fine ('E_P[EFin \o X])|)%R ] <= (eps ^- 2)%:E * 'V_P[X]. Proof. move => heps; have [->|hv] := eqVneq 'V_P[X] +oo. by rewrite mulr_infty gtr0_sg ?mul1e// ?leey// invr_gt0// exprn_gt0. have h (Y : {RV P >-> R}) : - P [set x | (eps <= `|Y x|)%R] <= (eps ^- 2)%:E * 'E_P[Y ^+ 2]. + P [set x | (eps <= `|Y x|)%R] <= (eps ^- 2)%:E * 'E_P[EFin \o (Y ^+ 2)%R]. rewrite -lee_pdivrMl; first by rewrite invr_gt0// exprn_gt0. rewrite exprnN expfV exprz_inv opprK -exprnP. - apply: (@le_trans _ _ ('E_P[(@GRing.exp R ^~ 2%N \o normr) \o Y])). + apply: (@le_trans _ _ ('E_P[EFin \o (@GRing.exp R ^~ 2%N \o normr) \o Y])). apply: (@markov Y (@GRing.exp R ^~ 2%N)) => //. - by move=> r _; exact: sqr_ge0. - by move=> x y; rewrite !nnegrE => x0 y0; rewrite ler_sqr. apply: expectation_le. - - by apply: measurableT_comp => //; exact: measurableT_comp. - - by []. + - apply: measurableT_comp => //. + apply: measurableT_comp => //. + by apply: measurableT_comp => //. + - by apply: measurableT_comp => //. - by move=> x /=; exact: sqr_ge0. - by move=> x /=; exact: sqr_ge0. - by apply/aeW => t /=; rewrite real_normK// num_real. -have := h (X \- cst (fine ('E_P[X])))%R. +have := h (X \- cst (fine ('E_P[EFin \o X])))%R. by move=> /le_trans; apply; rewrite /variance [in leRHS]unlock. Qed. Lemma cantelli (X : {RV P >-> R}) (lambda : R) : (X : T -> R) \in Lfun P 2%:E -> (0 < lambda)%R -> - P [set x | lambda%:E <= (X x)%:E - 'E_P[X]] + P [set x | lambda%:E <= (X x)%:E - 'E_P[EFin \o X]] <= (fine 'V_P[X] / (fine 'V_P[X] + lambda^2))%:E. Proof. move=> /[dup] X2. move=> /(Lfun_subset12 (fin_num_measure P _ measurableT)) X1 lambda_gt0. -have finEK : (fine 'E_P[X])%:E = 'E_P[X] by rewrite fineK ?expectation_fin_num. +have finEK : (fine 'E_P[EFin \o X])%:E = 'E_P[EFin \o X] by rewrite fineK ?expectation_fin_num. have finVK : (fine 'V_P[X])%:E = 'V_P[X] by rewrite fineK ?variance_fin_num. -pose Y := (X \- cst (fine 'E_P[X]))%R. +pose Y := (X \- cst (fine 'E_P[EFin \o X]))%R. have Y2 : (Y : T -> R) \in Lfun P 2%:E. by rewrite /Y rpredB ?lee1n//= => _; rewrite Lfun_cst. -have EY : 'E_P[Y] = 0. - rewrite expectationB ?Lfun_cst//= expectation_cst. - by rewrite finEK subee// expectation_fin_num. +have EY : 'E_P[EFin \o Y] = 0. + rewrite expectationB ?Lfun_cst//=. + rewrite (_ : _ \o cst _ = cst 'E_P[EFin \o X])//. + apply/funext => x/=. + by rewrite finEK //. + rewrite expectation_cst. + by rewrite subee// expectation_fin_num. have VY : 'V_P[Y] = 'V_P[X] by rewrite varianceB_cst_r. have le (u : R) : (0 <= u)%R -> - P [set x | lambda%:E <= (X x)%:E - 'E_P[X]] + P [set x | lambda%:E <= (X x)%:E - 'E_P[EFin \o X]] <= ((fine 'V_P[X] + u^2) / (lambda + u)^2)%:E. move=> uge0; rewrite EFinM. - have -> : (fine 'V_P[X] + u^2)%:E = 'E_P[(Y \+ cst u)^+2]%R. - rewrite -VY -[RHS](@subeK _ _ (('E_P[(Y \+ cst u)%R])^+2)). + have -> : (fine 'V_P[X] + u^2)%:E = 'E_P[EFin \o (Y \+ cst u)^+2]%R. + rewrite -VY -[RHS](@subeK _ _ (('E_P[EFin \o (Y \+ cst u)%R])^+2)). rewrite fin_numX// expectation_fin_num//= rpredD ?Lfun_cst//. by rewrite rpredB// Lfun_cst. rewrite -varianceE/=. by rewrite rpredD ?lee1n//= => _; rewrite Lfun_cst. rewrite -expe2 expectationD/= ?Lfun_cst//; first by rewrite rpredB ?Lfun_cst. - rewrite EY// add0e expectation_cst -EFinM. + rewrite EY// add0e. + rewrite (_ : _ \o _ = cst u%:E)//. + rewrite expectation_cst -EFinM. by rewrite (varianceD_cst_r _ Y2) EFinD fineK ?variance_fin_num. - have le : [set x | lambda%:E <= (X x)%:E - 'E_P[X]] + have le : [set x | lambda%:E <= (X x)%:E - 'E_P[EFin \o X]] `<=` [set x | ((lambda + u)^2)%:E <= ((Y x + u)^+2)%:E]. move=> x /= le; rewrite lee_fin; apply: lerXn2r. - exact: addr_ge0 (ltW lambda_gt0) _. @@ -1335,7 +1347,7 @@ Import MeasurableR. Lemma dRV_expectation (X : {dRV P >-> R}) : P.-integrable [set: T] (EFin \o X) -> - 'E_P[X] = \sum_(n ix; rewrite unlock. rewrite -[in LHS](_ : \bigcup_k (if k \in dRV_dom X then @@ -1381,7 +1393,7 @@ Qed. Lemma expectation_pmf (X : {dRV P >-> R}) : P.-integrable [set: T] (EFin \o X) -> - 'E_P[X] = \sum_(n iX; rewrite dRV_expectation// [in RHS]eseries_mkcond. From c065fd343123cf7140df85dd978a0a04a04795b8 Mon Sep 17 00:00:00 2001 From: Reynald Affeldt Date: Sun, 1 Nov 2026 05:32:08 +0900 Subject: [PATCH 12/18] linting - rm has_expectation - rename exp -> pmf_expectation --- theories/probability_theory/counting_distr.v | 741 +++++++++---------- 1 file changed, 351 insertions(+), 390 deletions(-) diff --git a/theories/probability_theory/counting_distr.v b/theories/probability_theory/counting_distr.v index c58c366f5c..f515d04e00 100644 --- a/theories/probability_theory/counting_distr.v +++ b/theories/probability_theory/counting_distr.v @@ -4,7 +4,7 @@ From mathcomp Require Import boolp classical_sets functions filter. From mathcomp Require Import constructive_ereal reals discrete. From mathcomp Require Import esum ereal. From mathcomp Require Import cardinality fsbigop topology normedtype sequences. -From mathcomp Require Import measure lebesgue_measure measurable_realfun lebesgue_integral random_variable. +From mathcomp Require Import measure lebesgue_measure measurable_realfun lebesgue_integral hoelder random_variable. From mathcomp Require Import unstable. (* Should be removed *) @@ -28,6 +28,18 @@ From mathcomp Require Import numfun. (* ``` *) (******************************************************************************) +Reserved Notation "R .-pmf T" (at level 1, T at level 2, format "R .-pmf T "). +Reserved Notation "\P_[ mu ] E" (at level 2, format "\P_[ mu ] E"). +Reserved Notation "\P_[ mu , A ] E" (at level 2, format "\P_[ mu , A ] E"). +Reserved Notation "\E_[ mu ] f" (at level 2, format "\E_[ mu ] f"). +Reserved Notation "\E_[ mu , A ] f" (at level 2, format "\E_[ mu , A ] f"). +Reserved Notation "\dlet_ ( i <- d ) E" + (at level 36, E at level 36, i, d at level 50, + format "'[' \dlet_ ( i <- d ) '/ ' E ']'"). +Reserved Notation "\dlim_ ( n ) E" + (at level 36, E at level 36, n at level 50, + format "'[' \dlim_ ( n ) '/ ' E ']'"). + Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. @@ -37,6 +49,12 @@ Import Order.TTheory GRing.Theory Num.Theory. Local Open Scope ring_scope. Local Open Scope classical_set_scope. +Notation "f '<=1' g" := (forall x, f x <= g x) + (at level 70, no associativity). +Notation "f '<=2' g" := (forall x y, f x y <= g x y) + (at level 70, no associativity). +Local Notation "\`| f |" := (fun x => `|f x|) (at level 2). + Definition discrete_measurable_space (T : choiceType) : Type := T. HB.instance Definition _ (T : choiceType) := @@ -55,33 +73,6 @@ by apply: (@reindex_esum R T (discrete_measurable_space T) [set: T] [set: discrete_measurable_space T] id f); split. Qed. -(* -------------------------------------------------------------------- *) -Notation "f '<=1' g" := (forall x, f x <= g x) - (at level 70, no associativity). - -Notation "f '<=2' g" := (forall x y, f x y <= g x y) - (at level 70, no associativity). - -(* -------------------------------------------------------------------- *) -Local Notation simpm := Monoid.simpm. - -(* -------------------------------------------------------------------- *) -Reserved Notation "\dlet_ ( i <- d ) E" - (at level 36, E at level 36, i, d at level 50, - format "'[' \dlet_ ( i <- d ) '/ ' E ']'"). - -Reserved Notation "\dlim_ ( n ) E" - (at level 36, E at level 36, n at level 50, - format "'[' \dlim_ ( n ) '/ ' E ']'"). - -Reserved Notation "\P_[ mu ] E" (at level 2, format "\P_[ mu ] E"). -Reserved Notation "\P_[ mu , A ] E" (at level 2, format "\P_[ mu , A ] E"). -Reserved Notation "\E?_[ mu ] f" (at level 2, format "\E?_[ mu ] f"). -Reserved Notation "\E_[ mu ] f" (at level 2, format "\E_[ mu ] f"). -Reserved Notation "\E_[ mu , A ] f" (at level 2, format "\E_[ mu , A ] f"). - -Local Notation "\`| f |" := (fun x => `|f x|) (at level 2). - HB.mixin Record isSubPmf {R : realType} {T : choiceType} (mu : T -> R) := { subpmf_ge0 : forall x, 0 <= mu x ; subpmf_summable : esummable [set: T] (EFin \o mu); @@ -96,9 +87,7 @@ Arguments subpmf_sum_le1 {R T} _. #[global] Hint Extern 0 (is_true (0 <= _)) => solve [apply: subpmf_ge0] : core. #[global] Hint Resolve subpmf_summable : core. - -Notation "R .-pmf T" := (@SubPmf.type R T) - (at level 1, T at level 2, format "R .-pmf T ") : type_scope. +Notation "R .-pmf T" := (@SubPmf.type R T) : type_scope. Section SubProbability_measure_subpmf. Context {R : realType} {T : choiceType} (mu : R.-pmf T). @@ -136,6 +125,62 @@ HB.instance Definition _ := End SubProbability_measure_subpmf. +Section expectation_measure_of_pmf. +Context {R : realType} {T : choiceType}. +Implicit Types (mu : R.-pmf T). + +Local Open Scope ereal_scope. + +Lemma integral_measure_of_pmf mu (f : T -> \bar R) : (forall x, 0 <= f x) -> + \int[measure_of_pmf mu]_x f x = \esum_(x in [set: T]) (f x * (mu x)%:E). +Proof. +move=> f0; rewrite -esum_setT_discrete -integral_counting_esum//=. +rewrite -(@integral_measure_of_density _ (discrete_measurable_space T) R + (@counting (discrete_measurable_space T) R) mu)//=. +move => H; apply: eq_measure_integral => A mA _ /=. +by rewrite /measure_of_density /measure_of_pmf integral_counting_esum. +Qed. + +Lemma integrable_esummable_new mu (A : T -> \bar R) : + esummable [set: T] (fun x : T => A x * (mu x)%:E)%E <-> + (measure_of_pmf mu).-integrable [set: discrete_measurable_space T] A. +Proof. +rewrite esummableE. +under eq_esum do rewrite abseM abse_EFin (@ger0_norm _ (mu _))//. +rewrite ge0_fin_numE//. + by rewrite esum_ge0// => x _; rewrite mule_ge0 ?lee_fin ?abse_ge0. +split=> [Amu|/integrableP[_]]. + apply/integrableP; split => //. + by rewrite integral_measure_of_pmf// => x; rewrite abse_ge0. +by rewrite integral_measure_of_pmf// => x; rewrite abse_ge0. +Qed. + +Lemma expectation_pmf mu (f : T -> \bar R) : + 'E_(measure_of_pmf mu)[f] = \esum_(x in [set:T]) (f x * (mu x)%:E). +Proof. +rewrite expectation_def integralE esumE; congr (_ - _). +- rewrite integral_measure_of_pmf//. + apply: eq_esum => x _. + by rewrite !funeposE maxe_pMl ?mul0e// lee_fin. +- rewrite integral_measure_of_pmf//. + apply: eq_esum => x _. + by rewrite !funenegE maxe_pMl ?mul0e ?mulNe// lee_fin. +Qed. + +Lemma expectation_pmfEFin mu (g : T -> R) : + 'E_(measure_of_pmf mu) [EFin \o g] = esum [set: T] (EFin \o (fun x => g x * mu x))%R. +Proof. by rewrite expectation_pmf. Qed. + +Lemma expectation_pmf0 mu : 'E_(measure_of_pmf mu) [cst 0] = 0. +Proof. by rewrite unlock integral0. Qed. + +(* NB: not used *) +Lemma expection_pmfZ mu F c : (forall x, 0%:E <= F x)%E -> + 'E_(measure_of_pmf mu)[fun x => c * F x] = c * 'E_(measure_of_pmf mu) [F]. +Proof. by move=> /= F0; rewrite unlock ge0_integralZl. Qed. + +End expectation_measure_of_pmf. + HB.factory Record uniq_isSubPmf {R : realType} {T : choiceType} (mu : T -> R) := { subpmf_ge0 : forall x : T, 0 <= mu x ; uniq_subpmf_le1 : forall J, uniq J -> \sum_(j <- J) mu j <= 1 }. @@ -193,8 +238,6 @@ Qed. HB.instance Definition _ := @uniq_isSubPmf.Build R R (pmf X) (@pmf_ge0 _ _ _ P X) pmf_uniq_le1. -Check (pmf X : R.-pmf R). - End pmf_subpmf. Lemma subpmf_le1 {R : realType} {T : choiceType} (mu : R.-pmf T) x : mu x <= 1. @@ -220,19 +263,27 @@ Proof. by rewrite -topredE /dinsupp /= negbK; apply/eqP. Qed. Definition pr mu E := fine (\esum_(x in [set: T]) ((E x)%:R * mu x)%:E). Definition prc mu E A := pr mu [predI E & A] / pr mu A. -Definition expectation_pmf mu f := fine (\esum_(x in [set: T]) (f x * mu x)%:E). +Definition pmf_expectation mu f := fine (\esum_(x in [set: T]) (f x * mu x)%:E). Definition espc mu f A := fine (\esum_(x in [set: T]) (f x * prc mu (pred1 x) A)%:E). -Definition has_expectation_pmf mu f := esummable [set: T] (EFin \o (f \* mu)). +Definition pmf_esummable mu f := esummable [set: T] (EFin \o (f \* mu)). + End StdDefs. Notation "\P_[ mu ] E" := (pr mu E). Notation "\P_[ mu , A ] E" := (prc mu E A). -Notation "\E_[ mu ] f" := (expectation_pmf mu f). +Notation "\E_[ mu ] f" := (pmf_expectation mu f). Notation "\E_[ mu , A ] f" := (espc mu f A). -Notation "\E?_[ mu ] f" := (has_expectation_pmf mu f). Notation dweight mu := (\P_[mu] predT). +(* NB: not used *) +(*Section Esp. +Context {R : realType} {T : choiceType}. +Implicit Types (mu : R.-pmf T) (f : T -> \bar R). + +Definition epmf_expectation mu f := \esum_(x in [set:T]) (f x * (mu x)%:E)%E. + +End Esp.*) Definition sub_distr {R : realType} {T : choiceType} (mu : T -> R) := (forall x, 0 <= mu x) /\ (forall J, uniq J -> \sum_(j <- J) mu j <= 1). @@ -246,7 +297,6 @@ split=> -[ ge0_mu le1]; split=> //. by rewrite [X in _<=X](bigID (mem J)) /= lerDl sumr_ge0. Qed. - (* -------------------------------------------------------------------- *) Section DistrD. Context {R : realType} {T : choiceType}. @@ -377,7 +427,7 @@ Implicit Types (s : seq T). Definition drat_fun (s : seq T) : T -> R := fun x : T => (count (pred1 x) s)%:R / (size s)%:R. -Lemma ge0_drat s : forall x, 0 <= drat_fun s x. +Lemma drat_ge0 s : forall x, 0 <= drat_fun s x. Proof. by move=> x; rewrite mulr_ge0 ?invr_ge0 // ler0n. Qed. Lemma has_sup_drat s J : uniq J -> \sum_(i <- J) drat_fun s i <= 1. @@ -415,12 +465,12 @@ rewrite ge0_esum. rewrite ge_ereal_sup//= => _ [X [finX _]] <-. rewrite fsumEFin // lee_fin fsbig_finite //=. rewrite (eq_bigr (drat_fun s)). -+ move => ??; rewrite ger0_norm ?ge0_drat //. ++ move => ??; rewrite ger0_norm ?drat_ge0 //. by apply/has_sup_drat. Qed. Lemma isd_drat s : sub_distr (drat_fun s). -Proof. by split; [apply/ge0_drat | apply/has_sup_drat]. Qed. +Proof. by split; [exact/drat_ge0|exact/has_sup_drat]. Qed. HB.instance Definition _ (s : seq T) := @uniq_isSubPmf.Build R T (drat_fun s) (proj1 (isd_drat s)) (proj2 (isd_drat s)). @@ -435,22 +485,18 @@ Definition dunit x := drat [:: x]. Definition duni s := drat (undup s). Lemma dunit1E x y : (dunit x) y = (x == y)%:R. -Proof. by rewrite /dunit drat1E /= !(simpm, invr1). Qed. +Proof. by rewrite /dunit drat1E /= addn0 divr1. Qed. Lemma dunit_id x : (dunit x) x = 1. -Proof. by rewrite /dunit drat1E /= !(simpm, invr1) eq_refl. Qed. +Proof. by rewrite /dunit drat1E /= addn0 divr1 eqxx. Qed. Lemma dunit_diff x y: x <> y -> (dunit x) y = 0. -Proof. - rewrite /dunit drat1E /= !(simpm, invr1). - by case_eq (x == y) => //= /eqP. -Qed. +Proof. by rewrite /dunit drat1E /= addn0 divr1 => /eqP /negPf ->. Qed. Lemma duni1E s x : (duni s) x = (x \in s)%:R / (size (undup s))%:R. Proof. by rewrite /duni drat1E count_uniq_mem ?(mem_undup, undup_uniq). Qed. -Lemma in_dunit t t' : - t' \in dinsupp (dunit t) -> t' = t :> T. +Lemma in_dunit t t' : t' \in dinsupp (dunit t) -> t' = t :> T. Proof. by rewrite in_dinsupp /= dunit1E pnatr_eq0 eqb0 negbK => /eqP. Qed. End DRat. @@ -464,7 +510,8 @@ Definition dflip_fun (xt : R) := fun b => if b then clamp xt else 1 - clamp xt. Lemma isd_dflip xt : sub_distr (dflip_fun xt). -Proof. apply/isdistr_finP; split=> [b|]. +Proof. +apply/isdistr_finP; split=> [b|]. + by case: b; rewrite ?subr_ge0 clamp_gele. + by rewrite /index_enum !unlock /= addr0 addrC subrK. Qed. @@ -480,8 +527,7 @@ End Flip. (* -------------------------------------------------------------------- *) Section Bind. -Context {R : realType} {T U : choiceType} - (f : T -> R.-pmf U) (mu : R.-pmf T). +Context {R : realType} {T U : choiceType} (f : T -> R.-pmf U) (mu : R.-pmf T). Definition dlet_fun := fun y : U => fine (esum [set:T] (fun x => EFin (mu x * f x y))). @@ -530,11 +576,10 @@ Definition dlift {R : realType} {T : choiceType} (f : T -> R.-pmf T) := Definition diter {R : realType} {T : choiceType} n (f : T -> R.-pmf T) := fun a => (iter n (dlift f) (dunit a)). -(* -------------------------------------------------------------------- *) -Lemma esum_abse {R : realType} {T : choiceType} - (f : T -> R) : - (forall i, 0%R <= f i) -> - (\esum_(x in [set: T]) (f x)%:E = \esum_(x in [set: T]) `|(f x)%:E|)%E. +(* TODO: move (generic lemma) *) +Lemma esum_abse {R : realType} {T : choiceType} (f : T -> R) : + (forall i, 0 <= f i)%R -> + (\esum_(x in [set: T]) (f x)%:E = \esum_(x in [set: T]) `|(f x)%:E|)%E. Proof. by move => ?; apply eq_esum => ?? ; rewrite gee0_abs // lee_tofin. Qed. Lemma summable_mu_wgtd {R : realType} {T : choiceType} @@ -599,7 +644,7 @@ by move/dinsuppPn => ->; rewrite !mul0e. Qed. Lemma summable_dlet (f : T -> R.-pmf U) (mu : R.-pmf T) y : - esummable [set: T] (fun x : T => EFin (mu x * (f x) y)). + esummable [set: T] (fun x : T => (mu x * (f x) y)%:E). Proof. by apply/summable_mu_wgtd=> x; rewrite subpmf_ge0 subpmf_le1. Qed. Lemma fin_esum (f : T -> R.-pmf U) (mu : R.-pmf T) y: @@ -706,8 +751,8 @@ End BindTheory. (* -------------------------------------------------------------------- *) Section DLetDLet. - Context {R:realType} {T U V : choiceType} - (f1 : T -> R.-pmf U) (f2 : U -> R.-pmf V). +Context {R : realType} {T U V : choiceType} + (f1 : T -> R.-pmf U) (f2 : U -> R.-pmf V). Lemma dlet_dlet (mu : R.-pmf T) : \dlet_(x <- \dlet_(y <- mu) f1 y) f2 x @@ -768,14 +813,14 @@ Import numFieldNormedType.Exports. Definition dlim_fun f : T -> R := fun x => fine (limn_einf (fun n : nat => (f n x)%:E)). -Lemma ge0_liminf f x : (0 <= limn_einf (fun n => (f n x)%:E))%E. +Lemma liminf_ge0 f x : (0 <= limn_einf (fun n => (f n x)%:E))%E. Proof. rewrite limn_einf_lim; apply: lime_ge; first exact: is_cvg_einfs. apply: nearW => n; apply: le_ereal_inf_tmp => _ [m _] <-. by rewrite lee_fin. Qed. -Lemma le1_liminf f x : (limn_einf (fun n => (f n x)%:E) <= 1%:E)%E. +Lemma liminf_le1 f x : (limn_einf (fun n => (f n x)%:E) <= 1%:E)%E. Proof. rewrite limn_einf_lim; apply: lime_le; first exact: is_cvg_einfs. apply: nearW => n; apply: (@le_trans _ _ (f n x)%:E); first exact: ge_einfs. @@ -784,9 +829,9 @@ Qed. Lemma fin_liminf f x : limn_einf (fun n => (f n x)%:E) \is a fin_num. Proof. -have h0 : (0 <= limn_einf (fun n => (f n x)%:E))%E by exact: ge0_liminf. +have h0 : (0 <= limn_einf (fun n => (f n x)%:E))%E by exact: liminf_ge0. rewrite ge0_fin_numE//. -by apply: le_lt_trans; [apply: le1_liminf | apply: ltry]. +by apply: le_lt_trans; [exact: liminf_le1 |exact: ltry]. Qed. Lemma dlim_fun_EFin f x : (dlim_fun f x)%:E = limn_einf (fun n => (f n x)%:E). @@ -812,11 +857,11 @@ Qed. Lemma isd_dlim f : sub_distr (dlim_fun f). Proof. split=> [x|J uqJ]. - by rewrite /dlim_fun; apply: fine_ge0; exact: ge0_liminf. -have ndE : forall j : T, nondecreasing_seq (einfs (fun n => (f n j)%:E)). - by move=> j; exact: nondecreasing_einfs. -have finE : forall j : T, limn (einfs (fun n => (f n j)%:E)) \is a fin_num. - by move=> j; rewrite -limn_einf_lim fin_liminf. + by rewrite /dlim_fun; apply: fine_ge0; exact: liminf_ge0. +have ndE (j : T) : nondecreasing_seq (einfs (fun n => (f n j)%:E)). + exact: nondecreasing_einfs. +have finE (j : T) : limn (einfs (fun n => (f n j)%:E)) \is a fin_num. + by rewrite -limn_einf_lim fin_liminf. rewrite -lee_fin -sumEFin. under eq_bigr => j _ do rewrite dlim_fun_EFin limn_einf_lim. rewrite (sumlim ndE finE); apply: lime_le. @@ -890,11 +935,11 @@ Proof. by move=> x; rewrite !dlimE (limn_einf_shiftS (fun n => (f n x)%:E)). Qed Lemma dlim_lift f p : \dlim_(n) f (n + p)%N =1 dlim f. Proof. by move=> x; rewrite !dlimE (limn_einf_shift_new (fun n => (f n x)%:E) p). Qed. -Lemma ge0_dlim f x : 0 <= dlim f x. +Lemma dlim_ge0 f x : 0 <= dlim f x. Proof. by []. Qed. -Lemma le1_dlim f : forall x, dlim f x <= 1. -Proof. by move=> x; rewrite -lee_fin dlim_EFin; exact: le1_liminf. Qed. +Lemma dlim_le1 f : forall x, dlim f x <= 1. +Proof. by move=> x; rewrite -lee_fin dlim_EFin; exact: liminf_le1. Qed. Lemma le_dlim f g : (forall n, f n <=1 g n) -> dlim f <=1 dlim g. @@ -915,8 +960,8 @@ Qed. Lemma leub_dlim f mu : (forall n, f n <=1 mu) -> dlim f <=1 mu. Proof. - move => le x; rewrite -(dlimC mu x). - by apply : le_dlim => n y. +move => le x; rewrite -(dlimC mu x). +by apply : le_dlim => n y. Qed. Lemma dlim_ub f k : homo f -> f k <=1 dlim f. @@ -931,9 +976,9 @@ Qed. End DLimTheory. Section DletDLim. -Variables (R : realType) (T U : choiceType). +Context {R : realType} {T U : choiceType}. -Implicit Types (f : nat -> R.-pmf T) (h : T -> R.-pmf R). +Implicit Types (f : (R.-pmf T)^nat) (h : T -> R.-pmf R). Lemma sup_mul f (hf : nd f) (c : R) x : 0 <= c -> ((dlim f x) * c)%:E = ereal_sup (range (fun n => (f n x * c)%:E)). @@ -1083,8 +1128,8 @@ Qed. End DLimDLim. Section dlet_dlim_diag. -Context (R : realType) (T U: choiceType). -Context (d : nat -> R.-pmf T) (h : nat -> T -> R.-pmf R). +Context {R : realType} {T U : choiceType}. +Context (d : (R.-pmf T)^nat) (h : nat -> T -> R.-pmf R). Context (hd : homo d). Context (hmono: (forall k n1 n2, (n1 <= n2)%N -> h n1 k <=1 h n2 k)). @@ -1137,7 +1182,7 @@ End Marginals. (* -------------------------------------------------------------------- *) Section MarginalsTh. -Variable (R: realType) (T U V : choiceType). +Context {R : realType} {T U V : choiceType}. Lemma dmargin_psumE (mu : R.-pmf T) (f : T -> U) y : (dmargin f mu) y = fine (esum [set:T] (fun x => ((f x == y)%:R * mu x)%:E)). @@ -1276,61 +1321,50 @@ by move=> x /=; rewrite dswapE. Qed. End DSnd. -(* -------------------------------------------------------------------- *) -Section PrCoreTheory. +Section pmf_esummable_lemmas. Context {R : realType} {T : choiceType}. +Implicit Types (mu : R.-pmf T). -Implicit Types (mu : R.-pmf T) (A B E : pred T). - -Lemma summable_pr E mu : esummable [set:T] (fun x => ((E x)%:R * mu x)%:E). +Lemma pmf_esummable_cst mu c : pmf_esummable mu (cst c). Proof. -apply/(le_esummable (g := EFin \o mu)) => [x _|//]. -rewrite !lee_tofin//=. - by rewrite mulr_ge0. -by rewrite ler_piMl //= lern1 leq_b1. +have : esummable setT (fun x => c%:E * (mu x)%:E)%E. + by apply: esummableZl => //; exact: subpmf_summable. +by apply/eq_esummable => x /= _; rewrite EFinM. Qed. -Lemma pr_pred0 mu : \P_[mu] pred0 = 0. -Proof. by rewrite /pr esum1 // => x /=; rewrite mul0r. Qed. - -Lemma pr_pred1 mu x : mu x = \P_[mu] (pred1 x). +Lemma pmf_esummableZ mu c F : pmf_esummable mu F -> pmf_esummable mu (c \*o F). Proof. -rewrite /pr. -rewrite (eq_esum _ _ (fun y => if x == y then (mu y)%:E else 0)); last first. -+ by rewrite esum_if_eq_op_set1. -move=> y _ /=; rewrite [y == x]eq_sym. -by case: ifP => xy; rewrite ?xy /= ?mul1r ?mul0r. +move=> heF; rewrite /pmf_esummable. +have := esummableZl (f := EFin \o (fun x => F x * mu x)) (c := c%:E) erefl heF. +apply/eq_esummable => x /=. +by rewrite -EFinM mulrA. Qed. -(* -------------------------------------------------------------------- *) -Lemma pr_exp mu (Q : pred T) : \P_[mu] Q = \E_[mu] (fun m => (Q m)%:R). -Proof. by []. Qed. - -Lemma pr_predT mu : \P_[mu] predT = fine (esum [set: T] (EFin \o mu)). +Lemma bounded_pmf_esummable mu F : + (exists M, forall x, `|F x| <= M) -> pmf_esummable mu F. Proof. -rewrite /pr /expectation_pmf; congr fine. -by apply/eq_esum=> x; rewrite mul1r. +case=> M leM; rewrite /pmf_esummable /esummable. +rewrite (eq_esum _ _ (fun x=> `|(F x)%:E * (mu x)%:E|)%E). + move=> x _; rewrite -EFinM //=. +apply: esummableMl; last exact: subpmf_summable. +exists M%:E => [x ?|]; last by []. +by rewrite /= lee_fin; exact: leM x. Qed. -Lemma pr_dunit E x : \P_[dunit x] E = (E x)%:R :> R. +Lemma esummable_pmf mu F : esummable [set: T] (EFin \o F) -> pmf_esummable mu F. Proof. -rewrite /pr. -rewrite (eq_esum _ _ (fun y => if x == y then ((E y)%:R)%:E else 0)). -+ move=> y _ /=; rewrite dunit1E. - by case: ifP => xy; rewrite ?xy /= ?mulr1 ?mulr0. -by rewrite esum_if_eq_op_set1. +move=> smF; rewrite /pmf_esummable /esummable. +rewrite (eq_esum _ _ (fun x=> `|(F x)%:E * (mu x)%:E|)%E). + by move=> x _; rewrite -EFinM. +apply: esummableMr; last exact: smF. +exists 1%:E => [x ?|]; last by []. +by rewrite /= lee_fin ger0_norm// subpmf_le1. Qed. -Lemma exp_dunit (f : T -> R) (x : T) : \E_[dunit x] f = f x. -Proof. -rewrite /expectation_pmf. -rewrite (eq_esum _ _ (fun y : T => if x == y then (f y)%:E else 0)%E). -+ move => x0 /=; rewrite dunit1E. - by case (x == x0) => //=; rewrite ?mulr1 ?mulr0. -by rewrite esum_if_eq_op_set1. -Qed. +End pmf_esummable_lemmas. -Lemma fineMK (a b : \bar R): +(* TODO: move (generic lemma) *) +Lemma fineMK {R : realDomainType} (a b : \bar R): (0 <= b)%E -> a \is a fin_num -> fine (a * b) = fine a * fine b. Proof. @@ -1345,9 +1379,14 @@ have [hc|hc|->] := comparable_ltgtP (comparableT r 0). by rewrite mul0e //= mulr0. Qed. -Lemma expZ mu f c : (forall x, 0 <= f x) -> \E_[mu] (fun x => c * (f x)) = c * (\E_[mu] f). +Section pmf_expectation_lemmas. +Context {R : realType} {T : choiceType}. +Implicit Types (mu : R.-pmf T). + +Lemma pmf_expectationZ mu f c : (forall x, 0 <= f x) -> + \E_[mu] (fun x => c * (f x)) = c * (\E_[mu] f). Proof. -move => h1; rewrite /expectation_pmf. +move => h1; rewrite /pmf_expectation. under eq_esum => x do rewrite /= -mulrA EFinM. have hpos : forall x : T, (0%R <= (f x * mu x)%:E)%E. + by move=> x; rewrite lee_fin; apply: mulr_ge0; [exact: h1|]. @@ -1357,36 +1396,116 @@ have hsum : (0 <= \esum_(i in [set: T]) (f i * mu i)%:E)%E. by rewrite fineMK. Qed. -Lemma exp_cst mu r : \E_[mu] (fun _ => r) = \P_[mu] predT * r. +Lemma pmf_expectation_cst mu r : \E_[mu] (fun=> r) = \P_[mu] predT * r. Proof. -have := (expZ mu (f:= fun _ => 1%R) r). +have := pmf_expectationZ mu (f := fun=> 1%R) r. rewrite mulr1 => -> //=. -by rewrite mulrC; congr (_ * _). +by rewrite mulrC; congr (_ * _). Qed. -Lemma exp0 mu : \E_[mu] (fun _ => 0) = 0. -Proof. by rewrite exp_cst mulr0. Qed. +Lemma pmf_expectation0 mu : \E_[mu] (fun=> 0) = 0. +Proof. by rewrite pmf_expectation_cst mulr0. Qed. -Lemma has_expectation_cst mu c : \E?_[mu] (cst c). +Lemma eq_pmf_expectation mu (f1 f2 : T -> R): + {in dinsupp mu, f1 =1 f2} -> \E_[mu] f1 = \E_[mu] f2. Proof. -have : esummable setT (fun x => c%:E * (mu x)%:E)%E. - by apply: esummableZl => //; exact: subpmf_summable. -by apply/eq_esummable => x /= _; rewrite EFinM. +move=> eq_f; rewrite /pmf_expectation; congr fine. +apply/eq_esum => x /=. +case/boolP: (x \in dinsupp mu). ++ by move/eq_f => ->. ++ by move/dinsuppPn => ->; rewrite !mulr0. Qed. -Lemma has_exp0 mu : \E?_[mu] (cst 0). Proof. exact: has_expectation_cst. Qed. +Lemma pmf_expectationE mu (g : T -> R) : + \E_[mu] g = fine ('E_(measure_of_pmf mu) [EFin \o g]). +Proof. by rewrite expectation_pmf. Qed. -Lemma has_exp1 mu : \E?_[mu] (cst 1). Proof. exact: has_expectation_cst. Qed. +Lemma pmf_expectationB mu (f g : T -> R) : + pmf_esummable mu f -> pmf_esummable mu g -> + \E_[mu] (f \- g) = \E_[mu] f - \E_[mu] g. +Proof. +move=> sf sg. +rewrite !pmf_expectationE. +rewrite expectationB//; [exact/Lfun1_integrable/integrable_esummable_new..|]. +by rewrite fineB// expectation_pmfEFin esummable_esum_fin_num. +Qed. -Lemma has_expZ mu c F : \E?_[mu] F -> \E?_[mu] (c \*o F). +Lemma pmf_expectation_ge0 mu (g : T -> R) : + (forall y, 0 <= g y) -> 0 <= \E_[mu] g. Proof. -move=> heF; rewrite /has_expectation_pmf. -have := esummableZl (f := EFin \o (fun x => F x * mu x)) (c := c%:E) erefl heF. -apply/eq_esummable => x /=. -by rewrite -EFinM mulrA. +move=> g0. +rewrite /pmf_expectation fine_ge0// esum_ge0// => x _. +by rewrite lee_fin mulr_ge0. Qed. -Lemma ge0_pr A mu : 0 <= \P_[mu] A. +End pmf_expectation_lemmas. + +Section PrCoreTheory. +Context {R : realType} {T : choiceType}. + +Implicit Types (mu : R.-pmf T) (A B E : pred T). + +Lemma summable_pr E mu : esummable [set:T] (fun x => ((E x)%:R * mu x)%:E). +Proof. +apply/(le_esummable (g := EFin \o mu)) => [x _|//]. +rewrite !lee_tofin//=. + by rewrite mulr_ge0. +by rewrite ler_piMl //= lern1 leq_b1. +Qed. + +Lemma pr_pred0 mu : \P_[mu] pred0 = 0. +Proof. by rewrite /pr esum1 // => x /=; rewrite mul0r. Qed. + +Lemma pr_pred1 mu x : mu x = \P_[mu] (pred1 x). +Proof. +rewrite /pr. +rewrite (eq_esum _ _ (fun y => if x == y then (mu y)%:E else 0)); last first. ++ by rewrite esum_if_eq_op_set1. +move=> y _ /=; rewrite [y == x]eq_sym. +by case: ifP => xy; rewrite ?xy /= ?mul1r ?mul0r. +Qed. + +Lemma pr_exp mu (Q : pred T) : \P_[mu] Q = \E_[mu] (fun m => (Q m)%:R). +Proof. by []. Qed. + +Lemma pr_predT mu : \P_[mu] predT = fine (esum [set: T] (EFin \o mu)). +Proof. +rewrite /pr /pmf_expectation; congr fine. +by apply/eq_esum=> x; rewrite mul1r. +Qed. + +Lemma expectation_pmf_cst mu r : ('E_(measure_of_pmf mu) [cst r] = (\P_[mu] predT)%:E * r)%E. +Proof. +rewrite expectation_pmf. +rewrite esumZ. + by move=> ?; rewrite lee_fin. +rewrite muleC; congr (_ * _)%E. +rewrite pr_predT. +rewrite fineK//=. +rewrite esum_abse//=. +have := @subpmf_summable _ _ mu. +by rewrite esummableE. +Qed. + +Lemma pr_dunit E x : \P_[dunit x] E = (E x)%:R :> R. +Proof. +rewrite /pr. +rewrite (eq_esum _ _ (fun y => if x == y then ((E y)%:R)%:E else 0)). ++ move=> y _ /=; rewrite dunit1E. + by case: ifP => xy; rewrite ?xy /= ?mulr1 ?mulr0. +by rewrite esum_if_eq_op_set1. +Qed. + +Lemma exp_dunit (f : T -> R) (x : T) : \E_[dunit x] f = f x. +Proof. +rewrite /pmf_expectation. +rewrite (eq_esum _ _ (fun y : T => if x == y then (f y)%:E else 0)%E). ++ move => x0 /=; rewrite dunit1E. + by case (x == x0) => //=; rewrite ?mulr1 ?mulr0. +by rewrite esum_if_eq_op_set1. +Qed. + +Lemma pr_ge0 A mu : 0 <= \P_[mu] A. Proof. rewrite /pr. case h: (esum _ _) => //=. @@ -1395,11 +1514,10 @@ apply/esum_ge0 . by move => ? _ ; rewrite lee_fin mulr_ge0. Qed. -Lemma ge0_prc A B mu : 0 <= \P_[mu, B] A. -Proof. by rewrite /prc mulr_ge0 ?invr_ge0 // ge0_pr. Qed. +Lemma prc_ge0 A B mu : 0 <= \P_[mu, B] A. +Proof. by rewrite /prc mulr_ge0 ?invr_ge0 // pr_ge0. Qed. -Lemma eq_in_pr A B mu : - {in dinsupp mu, A =i B} -> \P_[mu] A = \P_[mu] B. +Lemma eq_in_pr A B mu : {in dinsupp mu, A =i B} -> \P_[mu] A = \P_[mu] B. Proof. move=> eq_AB; rewrite /pr; congr fine. apply/eq_esum => x _ /=. @@ -1411,58 +1529,11 @@ Qed. Lemma eq_pr A B mu : A =i B -> \P_[mu] A = \P_[mu] B. Proof. by move=> eq_AB; apply/eq_in_pr=> x _; apply/eq_AB. Qed. -Lemma eq_exp mu (f1 f2 : T -> R): - {in dinsupp mu, f1 =1 f2} -> \E_[mu] f1 = \E_[mu] f2. -Proof. -move=> eq_f; rewrite /expectation_pmf; congr fine. -apply/eq_esum => x /=. -case/boolP: (x \in dinsupp mu). -+ by move/eq_f => ->. -+ by move/dinsuppPn => ->; rewrite !mulr0. -Qed. - Lemma pr_pred0_eq (mu : R.-pmf T) (E : pred T) : E =1 pred0 -> \P_[mu] E = 0. Proof. by move=> eq; rewrite -(pr_pred0 mu); apply/eq_pr. Qed. -End PrCoreTheory. - -(* -------------------------------------------------------------------- *) -Section Esp. -Context {R : realType} {T : choiceType}. -Implicit Types (mu : R.-pmf T) (f : T -> \bar R). - -Definition eexpectation_pmf mu f := \esum_(x in [set:T]) (f x * (mu x)%:E)%E. -End Esp. - -Section Expectation. -Context {R : realType} {T : choiceType} (mu : R.-pmf T). - -Local Open Scope ereal_scope. - -Lemma integral_measure_of_pmf (f : T -> \bar R) : (forall x, 0 <= f x)%E -> - \int[measure_of_pmf mu]_x f x = \esum_(x in [set: T]) (f x * (mu x)%:E)%E. -Proof. -move=> f0; rewrite -esum_setT_discrete -integral_counting_esum//=. -rewrite -(@integral_measure_of_density _ (discrete_measurable_space T) R - (@counting (discrete_measurable_space T) R) mu)//=. -move => H; apply: eq_measure_integral => A mA _ /=. -by rewrite /measure_of_density /measure_of_pmf integral_counting_esum. -Qed. - -Lemma eexpectationE (f : T -> \bar R) : - 'E_(measure_of_pmf mu)[f] = \esum_(x in [set:T]) ((f x) * (mu x)%:E)%E. -Proof. -rewrite expectation_def integralE esumE; congr (_ - _). -- rewrite integral_measure_of_pmf//. - apply: eq_esum => x _. - by rewrite !funeposE maxe_pMl ?mul0e// lee_fin. -- rewrite integral_measure_of_pmf//. - apply: eq_esum => x _. - by rewrite !funenegE maxe_pMl ?mul0e ?mulNe// lee_fin. -Qed. - -End Expectation. +End PrCoreTheory. Section EspeCoreTheory. Context {R : realType} {T : choiceType}. @@ -1470,127 +1541,62 @@ Implicit Types (mu : R.-pmf T) (A B E : pred T). Local Open Scope ereal_scope. -Lemma eexp_eq (f g: T -> \bar R) mu : f =1 g -> - 'E_(measure_of_pmf mu) [f] = 'E_(measure_of_pmf mu) [g]. -Proof. -move=> fg. -rewrite unlock. -by apply: eq_integral => //. -Qed. - Lemma eexp_dunit (f : T -> \bar R) (x : T) : 'E_(measure_of_pmf (dunit x)) [f] = f x. Proof. -rewrite eexpectationE. -rewrite /eexpectation_pmf. +rewrite expectation_pmf. +(*rewrite /epmf_expectation.*) rewrite (eq_esum _ _ (fun y : T => if x == y then f y else 0%R)%E). + move => x0. rewrite dunit1E. by case (x == x0) => //=; rewrite ?mule1 ?mule0. by rewrite esum_if_eq_op_set1. Qed. -Lemma eexp_cst mu r : ('E_(measure_of_pmf mu) [(cst r)] = (\P_[mu] predT)%:E * r)%E. -Proof. -rewrite pr_predT. -rewrite eexpectationE. -rewrite /eexpectation_pmf //. -rewrite esumZ. -- move => ?; rewrite lee_fin //. -rewrite muleC; congr ( _ * _)%E. -rewrite fineK //= esum_abse => //=. -by have := @subpmf_summable _ _ mu; rewrite esummableE. -Qed. - -Lemma eexp0 mu : 'E_(measure_of_pmf mu) [(cst 0)] = 0. -Proof. by rewrite eexp_cst mule0. Qed. - Lemma eexp_dlet {U: choiceType} mu (nu : T -> R.-pmf U) F : -(forall x, 0%:E <= F x)%E -> - 'E_(measure_of_pmf (dlet nu mu)) [F] = 'E_(measure_of_pmf mu) [fun x => 'E_(measure_of_pmf (nu x)) [F] ]. + (forall x, 0 <= F x)%E -> + 'E_(measure_of_pmf (dlet nu mu)) [F] = + 'E_(measure_of_pmf mu) [fun x => 'E_(measure_of_pmf (nu x)) [F]]. Proof. move => HF. -rewrite 2!eexpectationE. -under [in RHS]eq_esum do (rewrite eexpectationE). -have pos : (forall (i : T) (j : U), (0%R <= F j * ((mu i)%:E * (nu i j)%:E))%E). -- move => i j; rewrite mule_ge0 //. - by rewrite mule_ge0 // lee_tofin. -rewrite /eexpectation_pmf {1}(eq_esum _ _ - (fun x : U => (F x * esum [set:T] (fun y : T => (mu y * nu y x)%:E)))%E). -- move => x ?; rewrite /= dletE. +rewrite 2!expectation_pmf. +under [in RHS]eq_esum do rewrite expectation_pmf. +have pos (i : T) (j : U) : (0 <= F j * ((mu i)%:E * (nu i j)%:E))%E. + by rewrite !mule_ge0// lee_fin. +rewrite {1}(eq_esum _ _ (fun x : U => (F x * esum [set:T] (fun y : T => (mu y * nu y x)%:E)))). + move => x ?; rewrite /= dletE. congr ( _ * _)%E. - rewrite fineK //= esum_abse => //=. - - by move => i; rewrite mulr_ge0. - - have : esummable [set: T] (fun x0 : T => ((mu x0 * nu x0 x)%:E))%E. - + apply/(le_esummable (g := EFin \o mu)) => //=. - by move => x0; rewrite !lee_fin //= mulr_ge0 //= ler_piMr //= subpmf_le1. - by rewrite esummableE. + rewrite fineK//= esum_abse//=. + by move => i; rewrite mulr_ge0. + have : esummable [set: T] (fun x0 : T => (mu x0 * nu x0 x)%:E)%E. + apply/(le_esummable (g := EFin \o mu)) => //=. + by move => x0; rewrite !lee_fin //= mulr_ge0 //= ler_piMr //= subpmf_le1. + by rewrite esummableE. symmetry. -rewrite {1}(eq_esum _ _ - (fun x : T => (esum [set:U] (fun x0 : U => F x0 * ((mu x)%:E * (nu x x0)%:E))%E))). -- move => x ?; rewrite muleC. - rewrite -esumZ. - - by move => x1; rewrite mule_ge0// lee_fin. - rewrite {1}(eq_esum _ _ - (fun x0 : U => F x0 * ((mu x)%:E * (nu x x0)%:E))%E) // ?esum_sum' //. - - by move => ??; rewrite muleCA. -rewrite exchange_esum //. +rewrite {1}(eq_esum _ _ (fun x => esum [set:U] (fun x0 : U => F x0 * ((mu x)%:E * (nu x x0)%:E))%E)). + move => x _; rewrite muleC -esumZ. + by move => x1; rewrite mule_ge0// lee_fin. + rewrite {1}(eq_esum _ _ (fun x0 : U => F x0 * ((mu x)%:E * (nu x x0)%:E))%E)//. + by move=> ? ?; rewrite muleCA. +rewrite exchange_esum//. apply: eq_esum => u _. -rewrite esumZ //. - by move => ?; rewrite mule_ge0 // lee_tofin. +rewrite esumZ//. +by move => ?; rewrite mule_ge0// lee_fin. Qed. Local Open Scope ereal_scope. -Lemma eexpZ mu F c : - (forall x, 0%:E <= F x)%E -> - 'E_(measure_of_pmf mu)[fun x => c * F x] = c * 'E_(measure_of_pmf mu) [F]. -Proof. -move => h. -rewrite !eexpectationE. -rewrite -esumZ. -+ by move => x; rewrite mule_ge0 // lee_tofin. -by apply/eq_esum => x ?; rewrite muleA. -Qed. - -Lemma eexpB mu (A B : T -> \bar R) : - (forall x, A x \is a fin_num) -> - esummable [set: T] (fun x => (A x * (mu x)%:E)%E) -> - esummable [set: T] (fun x => (B x * (mu x)%:E)%E) -> - 'E_(measure_of_pmf mu) [(A \- B)%E] = ('E_(measure_of_pmf mu)[A] - 'E_(measure_of_pmf mu) [B])%E. -Proof. -move=> fA sA sB. -rewrite !eexpectationE. -rewrite (esum.eq_esum _ _ (fun x => (A x * (mu x)%:E - B x * (mu x)%:E)%E)). - by move => x ? /=; rewrite muleBl//; apply: fin_num_adde_defr; exact: fA. -exact: (esummable_esumB sA sB). -Qed. - -Lemma espE mu (g : T -> R) : - \E_[mu] g = fine ('E_(measure_of_pmf mu) [EFin \o g]). -Proof. -rewrite eexpectationE. -by rewrite /expectation_pmf /eexpectation_pmf; congr (fine _); apply: esum.eq_esum => x ? /=; rewrite EFinM. -Qed. - -Lemma espeEFin mu (g : T -> R) : - 'E_(measure_of_pmf mu) [EFin \o g] = esum [set: T] (EFin \o (fun x => g x * mu x))%R. -Proof. -rewrite eexpectationE. - by rewrite /eexpectation_pmf; apply: esum.eq_esum => x ? /=; rewrite EFinM. Qed. - Lemma eexp_dlet_esp {U: choiceType} mu (nu : T -> R.-pmf U) (g : U -> R) : - (forall y, 0 <= g y)%R -> (forall eta, \E?_[eta] g) -> + (forall y, 0 <= g y)%R -> (forall eta, pmf_esummable eta g) -> 'E_(measure_of_pmf (dlet nu mu)) [EFin \o g] = 'E_(measure_of_pmf mu) [EFin \o (fun x => \E_[nu x] g)]. Proof. -move=> ? sg. -rewrite (eexp_dlet mu nu ). -+ by move=> x; rewrite /= lee_fin. -rewrite /=. -rewrite !eexpectationE. -apply: eq_esum => ?? //=. -rewrite eexpectationE. +move=> g0 sg. +rewrite (eexp_dlet mu nu)/=. + by move=> x; rewrite /= lee_fin. +rewrite !expectation_pmf. +apply: eq_esum => t _ //=. +rewrite expectation_pmf. congr (_ * _)%E. -rewrite /expectation_pmf fineK//. +rewrite /pmf_expectation fineK//. exact: (esummable_esum_fin_num (sg (nu _))). Qed. @@ -1613,20 +1619,20 @@ rewrite -dRV_esum_pmf_distribution// integral_counting_esum//=. by apply/measurable_EFinP; exact: pmf_measurable. Qed. -Lemma ge0_espe_pmf (f : R -> \bar R) : - measurable_fun [set: R] f -> (forall r, 0 <= f r) -> - 'E_(measure_of_pmf pmfX) [f] = \int[P]_w f (X w). +Lemma ge0_expectation_pmf (f : R -> \bar R) : + measurable_fun [set: R] f -> (forall r, 0 <= f r) -> + 'E_(measure_of_pmf pmfX) [f] = \int[P]_w f (X w). Proof. move=> mf f0. (*rewrite unlock/=. rewrite -ge0_integral_distribution//.*) -rewrite eexpectationE. +rewrite expectation_pmf. have mfh : measurable_fun [set: R] (fun r => f r * (pmfX r)%:E). by apply: emeasurable_funM => //; apply/measurable_EFinP; exact: pmf_measurable. have fh0 r : 0 <= f r * (pmfX r)%:E. by apply: mule_ge0; [exact: f0|rewrite lee_fin pmf_ge0]. rewrite [LHS](_ : _ = \int[@counting R R]_r (f r * (pmfX r)%:E)). - by rewrite /eexpectation_pmf -integral_counting_esum//; exact: measurable_set1. + by rewrite (*/epmf_expectation*) -integral_counting_esum//; exact: measurable_set1. have <- : \int[distribution P X]_r f r = \int[@counting R R]_r (f r * (pmfX r)%:E). rewrite -(integral_measure_of_density _ (pmf_measurable X))//=. @@ -1635,25 +1641,24 @@ have <- : \int[distribution P X]_r f r = by rewrite /distribution ge0_integral_pushforward. Qed. -Lemma espe_pmf_dRV : 'E_(measure_of_pmf pmfX) [EFin] = 'E_P[EFin \o X]. +Lemma expectation_pmf_dRV : 'E_(measure_of_pmf pmfX) [EFin] = 'E_P[EFin \o X]. Proof. -rewrite eexpectationE. -rewrite /eexpectation_pmf esumE expectation_def integralE; congr (_ - _). +rewrite expectation_pmf. +rewrite (*/epmf_expectation*) esumE expectation_def integralE; congr (_ - _). - transitivity ('E_(measure_of_pmf pmfX) [(@EFin R)^\+%E]). - rewrite eexpectationE. + rewrite expectation_pmf. by apply: eq_esum => r _; rewrite !funeposE maxe_pMl ?lee_fin// mul0e. - rewrite ge0_espe_pmf => //=; first exact: measurable_funepos. + rewrite ge0_expectation_pmf => //=; first exact: measurable_funepos. by apply: eq_integral => w _; rewrite !funeposE. - transitivity ('E_(measure_of_pmf pmfX) [(@EFin R)^\-%E]). - rewrite eexpectationE. + rewrite expectation_pmf. by apply: eq_esum => r _; rewrite !funenegE maxe_pMl ?lee_fin// mul0e mulNe. - rewrite ge0_espe_pmf//=; first exact: measurable_funeneg. + rewrite ge0_expectation_pmf//=; first exact: measurable_funeneg. by apply: eq_integral => w _; rewrite !funenegE. Qed. End espe_pmf. - (* -------------------------------------------------------------------- *) Section PrTheory. Context {R : realType} {T U : choiceType} {I : eqType}. @@ -1680,7 +1685,7 @@ Qed. Lemma pr_dlet E f (mu : R.-pmf U) : \P_[dlet f mu] E = \E_[mu] (fun x => \P_[f x] E). Proof. -rewrite /pr /expectation_pmf. +rewrite /pr /pmf_expectation. congr (fine _). rewrite {1}(eq_esum _ _ (fun t => \esum_(x in [set: U]) ((E t)%:R * (mu x * f x t))%:E)%E). + by move => t _; rewrite EFinM dlet_EFin EFin_esumZ // => ?; rewrite mulr_ge0. @@ -1696,7 +1701,7 @@ Qed. Lemma pr_dmargin E f (mu : R.-pmf U) : \P_[dmargin f mu] E = \P_[mu] [pred x | f x \in E]. Proof. -by rewrite /dmargin pr_dlet pr_exp; apply/eq_exp=> x _; rewrite pr_dunit. +by rewrite /dmargin pr_dlet pr_exp; apply/eq_pmf_expectation=> x _; rewrite pr_dunit. Qed. Lemma eq0_pr A mu : @@ -1734,10 +1739,10 @@ rewrite ge0_fin_numE; last first. by apply: esum_ge0 => x _; rewrite lee_fin. Qed. -Lemma le_exp mu f1 f2: \E?_[mu] f1 -> \E?_[mu] f2 -> +Lemma le_exp mu f1 f2 : pmf_esummable mu f1 -> pmf_esummable mu f2 -> f1 <=1 f2 -> \E_[mu] f1 <= \E_[mu] f2. Proof. -move=> sm1 sm2 le_f; rewrite /expectation_pmf; apply: fine_le. +move=> sm1 sm2 le_f; rewrite /pmf_expectation; apply: fine_le. - exact: (esummable_esum_fin_num sm1). - exact: (esummable_esum_fin_num sm2). - apply: le_esum. @@ -1769,9 +1774,9 @@ case/boolP: (x \in dinsupp nu) => [/h {}h|]; last first. by case/boolP: (A x) => [/h|]; rewrite ?(mul0r, mul1r). Qed. -Lemma le1_prc A B mu : \P_[mu, B] A <= 1. +Lemma prc_le1 A B mu : \P_[mu, B] A <= 1. Proof. -move: (ge0_pr B mu); rewrite /prc le_eqVlt. +move: (pr_ge0 B mu); rewrite /prc le_eqVlt. case/orP=> [/eqP<-|]; first by rewrite invr0 mulr0 ler01. move/ler_pdivrMr=> ->; rewrite mul1r. by apply: le_in_pr => x _ /andP[]. @@ -1793,7 +1798,7 @@ rewrite (eq_esum _ _ (fun x => ((\P_[mu] A)^-1 * ((A x)%:R * mu x))%:E)). by move=> x _; rewrite /prc hpr1; congr (_ %:E); rewrite mulrC. rewrite (EFin_esumZ _ a0); last first. rewrite -prE -EFinM mulVf //. + by rewrite gt_eqF. - by rewrite invr_ge0; exact: ge0_pr. +by rewrite invr_ge0// pr_ge0. Qed. Lemma pr_eq0 mu E : \P_[mu] E = 0 -> forall x, x \in E -> mu x = 0. @@ -1884,13 +1889,11 @@ Lemma pr_and A B mu : \P_[mu] [predI A & B] = \P_[mu] A + \P_[mu] B - \P_[mu] [predU A & B]. Proof. by rewrite pr_or subKr. Qed. -Lemma ler_pr_or A B mu : - \P_[mu] [predU A & B] <= \P_[mu] A + \P_[mu] B. -Proof. by rewrite pr_or lerBlDr lerDl ge0_pr. Qed. +Lemma ler_pr_or A B mu : \P_[mu] [predU A & B] <= \P_[mu] A + \P_[mu] B. +Proof. by rewrite pr_or lerBlDr lerDl pr_ge0. Qed. -Lemma ler_pr_and A B mu : - \P_[mu] [predI A & B] <= \P_[mu] A + \P_[mu] B. -Proof. by rewrite pr_and lerBlDr lerDl ge0_pr. Qed. +Lemma ler_pr_and A B mu : \P_[mu] [predI A & B] <= \P_[mu] A + \P_[mu] B. +Proof. by rewrite pr_and lerBlDr lerDl pr_ge0. Qed. Lemma pr_predC E mu: \P_[mu](predC E) = \P_[mu] predT - \P_[mu] E. Proof. @@ -1922,7 +1925,7 @@ by rewrite esum_if_eq_op_set1. Qed. Lemma summable_pr_f f mu (P : pred T): - \E?_[mu] f -> + pmf_esummable mu f -> esummable [set: T] (EFin \o (fun x => (P x)%:R * (f x * mu x))). Proof. move=> sm; rewrite /esummable //= . @@ -1934,14 +1937,14 @@ by rewrite gee0_abs ?lee_fin ?ler0n// lern1 leq_b1. Qed. Lemma sum_fin_num_mu_f f mu (P : pred T): - \E?_[mu] f -> + pmf_esummable mu f -> esum [set:T] (EFin \o (fun x => (P x)%:R * (f x * mu x))) \is a fin_num. Proof. move=> ?; apply: esummable_esum_fin_num; exact: summable_pr_f. Qed. Lemma pr_esp_sum mu f (P : pred T): - \E?_[mu] f -> + pmf_esummable mu f -> \P_[mu] P * \E_[mu, P] f = fine (esum [set: T] (EFin \o (fun x => (P x)%:R * (f x * mu x)))). Proof. @@ -1963,66 +1966,43 @@ rewrite (esummable_esumZ _ (summable_pr_f P sm)); by rewrite fineM ?abse_fin_num ?sum_fin_num_mu_f// mulVKf. Qed. -Lemma exp_split A f mu : \E?_[mu] f -> \E_[mu] f = +Lemma exp_split A f mu : pmf_esummable mu f -> \E_[mu] f = \P_[mu] A * \E_[mu, A] f + \P_[mu] (predC A) * \E_[mu, predC A] f. Proof. move=> sm. -rewrite (pr_esp_sum A) // (pr_esp_sum (predC A)) // /expectation_pmf -fineD ?sum_fin_num_mu_f//. +rewrite (pr_esp_sum A) // (pr_esp_sum (predC A)) // /pmf_expectation -fineD ?sum_fin_num_mu_f//. congr fine; rewrite -(esummable_esumD (summable_pr_f A sm) (summable_pr_f (predC A) sm)). apply: esum.eq_esum => x ? /=; rewrite -EFinD; congr (_ %:E). rewrite -mulrDl -[LHS]mul1r; congr (_ * _). by rewrite -natrD; case: (A x). Qed. -Lemma bounded_has_exp mu F : - (exists M, forall x, `|F x| <= M) -> \E?_[mu] F. -Proof. -case=> M leM; rewrite /has_expectation_pmf /esummable. -rewrite (eq_esum _ _ (fun x=> `|(F x)%:E * (mu x)%:E|)%E). - move=> x _; rewrite -EFinM //=. -apply: esummableMl; last exact: subpmf_summable. -exists M%:E => [x ?|]; last by []. -by rewrite /= lee_fin; exact: leM x. -Qed. - -Lemma summable_has_exp mu F : esummable [set: T] (EFin \o F) -> \E?_[mu] F. -Proof. -move=> smF; rewrite /has_expectation_pmf /esummable. -rewrite (eq_esum _ _ (fun x=> `|(F x)%:E * (mu x)%:E|)%E). - move=> x _; rewrite -EFinM //=. -apply: esummableMr; last exact: smF. -exists 1%:E => [x ?|]; last by []. -by rewrite /= lee_fin ger0_norm// subpmf_le1. -Qed. - Lemma exp_le_bd mu F (M : R) : 0 <= M -> (forall x, `|F x| <= M) -> \E_[mu] F <= M. Proof. move=> ge0M bd; apply/(@le_trans _ _ (\E_[mu] (fun _ => M))). + apply/le_exp. - + by apply/bounded_has_exp; exists M. - + exact/has_expectation_cst. + + by apply/bounded_pmf_esummable; exists M. + + exact/pmf_esummable_cst. + by move=> x; apply/(le_trans _ (bd x))/ler_norm. -by rewrite exp_cst ler_piMl // le1_pr. -Qed. - -Lemma ge0_expectation {V : choiceType} (eta : R.-pmf V) (g : V -> R) : - (forall y, 0 <= g y) -> 0 <= \E_[eta] g. -Proof. -move=> g0; rewrite /expectation_pmf; apply: fine_ge0; apply: esum_ge0 => x ?. -by rewrite lee_fin mulr_ge0//; exact: g0. +by rewrite pmf_expectation_cst ler_piMl // le1_pr. Qed. Lemma exp_dlet_ge0 (mu : R.-pmf T) (nu : T -> R.-pmf U) (g : U -> R) : - (forall y, 0 <= g y) -> (forall eta, \E?_[eta] g) -> + (forall y, 0 <= g y) -> (forall eta, pmf_esummable eta g) -> \E_[dlet nu mu] g = \E_[mu] (fun x => \E_[nu x] g). -Proof. by move=> g0 sg; rewrite espE (eexp_dlet_esp mu nu g0 sg) -espE. Qed. +Proof. +move=> g0 sg. +rewrite [LHS]pmf_expectationE. +rewrite eexp_dlet_esp//. +by rewrite -pmf_expectationE. +Qed. -Lemma has_expectation_le {V:choiceType} (mu : R.-pmf V) (k h : V -> R) : - (forall x, `|k x| <= `|h x|) -> \E?_[mu] h -> \E?_[mu] k. +Lemma pmf_esummable_le {V : choiceType} (mu : R.-pmf V) (k h : V -> R) : + (forall x, `|k x| <= `|h x|) -> pmf_esummable mu h -> pmf_esummable mu k. Proof. -move=> kh; rewrite /has_expectation_pmf => fh. +move=> kh; rewrite /pmf_esummable => fh. rewrite esummableE ge0_fin_numE. + apply: esum_ge0 => i _; exact: abse_ge0. apply: (le_lt_trans _ fh). @@ -2031,48 +2011,33 @@ by move => ??; rewrite lee_fin !normrM ler_wpM2r. Qed. Lemma hcomp (mu : R.-pmf T) (nu : T -> R.-pmf U) (g : U -> R) : - (forall y, 0 <= g y) -> (forall eta, \E?_[eta] g) -> \E?_[mu] (fun x => \E_[nu x] g). + (forall y, 0 <= g y) -> (forall eta, pmf_esummable eta g) -> pmf_esummable mu (fun x => \E_[nu x] g). Proof. move=> g0 sg. -have hge0 : forall x, 0 <= \E_[nu x] g * mu x. - by move=> x; apply: mulr_ge0; [exact: ge0_expectation |]. -rewrite /has_expectation_pmf esummableE. +have hge0 x : 0 <= \E_[nu x] g * mu x by rewrite mulr_ge0// pmf_expectation_ge0. +rewrite /pmf_esummable esummableE. rewrite (esum.eq_esum _ _ (EFin \o (fun x => \E_[nu x] g * mu x))). + move=> x _ /=; rewrite ger0_norm //. -rewrite -espeEFin -(eexp_dlet_esp mu nu g0 sg) espeEFin. +rewrite -expectation_pmfEFin -(eexp_dlet_esp mu nu g0 sg) expectation_pmfEFin. exact: (esummable_esum_fin_num (sg (dlet nu mu))). Qed. -Lemma expB {V: choiceType} (f g : V -> R) (eta : R.-pmf V) : - \E?_[eta] f -> \E?_[eta] g -> \E_[eta] (f \- g) = \E_[eta] f - \E_[eta] g. -Proof. -move=> sf sg. -rewrite !espE -fineB //. -+ by rewrite espeEFin; exact: (esummable_esum_fin_num sf). -+ by rewrite espeEFin; exact: (esummable_esum_fin_num sg). -congr (fine _). -transitivity ('E_(measure_of_pmf eta)[((EFin \o f) \- (EFin \o g))%E])%E => //. -rewrite {1}(@eexp_eq _ _ _ (fun x => (f x)%:E - (g x)%:E)%E). -+ move => ?. rewrite -EFinB //. -exact : eexpB. -Qed. - Lemma exp_dlet mu (nu : T -> R.-pmf U ) F : - (forall eta, \E?_[eta] F) -> + (forall eta, pmf_esummable eta F) -> \E_[dlet nu mu] F = \E_[mu] (fun x => \E_[nu x] F). Proof. move=> sF. -have spF : forall eta, \E?_[eta] F^\+. -+ by move=> eta //=; apply: (has_expectation_le (le_funrpos F) (sF eta)). -have snF : forall eta, \E?_[eta] F^\-. -+ by move=> eta; apply: (has_expectation_le (le_funrneg F) (sF eta)). +have spF : forall eta, pmf_esummable eta F^\+. ++ by move=> eta //=; apply: (pmf_esummable_le (le_funrpos F) (sF eta)). +have snF : forall eta, pmf_esummable eta F^\-. ++ by move=> eta; apply: (pmf_esummable_le (le_funrneg F) (sF eta)). transitivity (\E_[mu] (fun x => \E_[nu x] F^\+) - \E_[mu] (fun x => \E_[nu x] F^\-)). rewrite -(exp_dlet_ge0 mu nu _ spF) // -(exp_dlet_ge0 mu nu _ snF) //. -rewrite -(expB (spF _) (snF _)); congr (\E_[dlet nu mu] _); exact/esym/funrposBneg. -rewrite -(expB (hcomp mu nu _ spF) (hcomp mu nu _ snF)) //. -apply: eq_exp => x _ /=. -rewrite -(expB (spF _) (snF _)). +rewrite -(pmf_expectationB (spF _) (snF _)); congr (\E_[dlet nu mu] _); exact/esym/funrposBneg. +rewrite -(pmf_expectationB (hcomp mu nu _ spF) (hcomp mu nu _ snF)) //. +apply: eq_pmf_expectation => x _ /=. +rewrite -(pmf_expectationB (spF _) (snF _)). congr (\E_[nu x] _); exact : funrposBneg. Qed. @@ -2080,18 +2045,14 @@ End PrTheory. (* -------------------------------------------------------------------- *) Section mono_esum. -Context - {R : realType} - {T : choiceType} - {f : nat -> R.-pmf T}. +Context {R : realType} {T : choiceType} {f : (R.-pmf T)^nat}. Hypothesis ndf : nd f. Lemma mono_esum_Efn (E: T -> \bar R): (forall m, 0 <= E m)%E -> forall m n, (m <= n)%N -> - (esum [set:T] (fun x => E x * (f m x)%:E) <= - esum [set:T] (fun x => E x * (f n x)%:E))%E. + (\esum_(x in [set:T]) (E x * (f m x)%:E) <= \esum_(x in [set:T]) (E x * (f n x)%:E))%E. Proof. move=> hE m n le_mn. apply /esum.le_esum. @@ -2165,5 +2126,5 @@ split=> [|->] //. case: f1 => f1 [[]ge0_1 s1 le1_1]. case: f2 => f2 [[]ge0_2 s2 le1_2]. move => /funext /= h. -subst;f_equal; f_equal; f_equal => //=. +by subst;f_equal; f_equal; f_equal. Qed. From 469f0529ac9c112a998308e49157c74a9cc57710 Mon Sep 17 00:00:00 2001 From: Lionel Blatter Date: Thu, 5 Nov 2026 11:27:37 +0100 Subject: [PATCH 13/18] - eexp_dunit via the Dirac measure - eexp_dlet via the Giry monad - Some refactoring --- theories/probability_theory/counting_distr.v | 384 +++++++++++-------- 1 file changed, 229 insertions(+), 155 deletions(-) diff --git a/theories/probability_theory/counting_distr.v b/theories/probability_theory/counting_distr.v index f515d04e00..926fdf6e8c 100644 --- a/theories/probability_theory/counting_distr.v +++ b/theories/probability_theory/counting_distr.v @@ -4,7 +4,7 @@ From mathcomp Require Import boolp classical_sets functions filter. From mathcomp Require Import constructive_ereal reals discrete. From mathcomp Require Import esum ereal. From mathcomp Require Import cardinality fsbigop topology normedtype sequences. -From mathcomp Require Import measure lebesgue_measure measurable_realfun lebesgue_integral hoelder random_variable. +From mathcomp Require Import measure lebesgue_measure measurable_realfun lebesgue_integral giry hoelder random_variable. From mathcomp Require Import unstable. (* Should be removed *) @@ -73,6 +73,19 @@ by apply: (@reindex_esum R T (discrete_measurable_space T) [set: T] [set: discrete_measurable_space T] id f); split. Qed. +Lemma measurable_fun_discrete {T : choiceType} {d'} {U : sigmaRingType d'} + (D : set (discrete_measurable_space T)) + (f : discrete_measurable_space T -> U) : + measurable_fun D f. +Proof. by move=> _ Y _. Qed. + +#[global] Hint Resolve measurable_fun_discrete : core. + +Lemma measurable_fun_discreteT {T U : choiceType} (h : T -> U) : + measurable_fun [set: discrete_measurable_space T] + (h : discrete_measurable_space T -> discrete_measurable_space U). +Proof. by move=> _ Y _. Qed. + HB.mixin Record isSubPmf {R : realType} {T : choiceType} (mu : T -> R) := { subpmf_ge0 : forall x, 0 <= mu x ; subpmf_summable : esummable [set: T] (EFin \o mu); @@ -175,9 +188,9 @@ Lemma expectation_pmf0 mu : 'E_(measure_of_pmf mu) [cst 0] = 0. Proof. by rewrite unlock integral0. Qed. (* NB: not used *) -Lemma expection_pmfZ mu F c : (forall x, 0%:E <= F x)%E -> - 'E_(measure_of_pmf mu)[fun x => c * F x] = c * 'E_(measure_of_pmf mu) [F]. -Proof. by move=> /= F0; rewrite unlock ge0_integralZl. Qed. +(* Lemma expection_pmfZ mu F c : (forall x, 0%:E <= F x)%E -> *) +(* 'E_(measure_of_pmf mu)[fun x => c * F x] = c * 'E_(measure_of_pmf mu) [F]. *) +(* Proof. by move=> /= F0; rewrite unlock ge0_integralZl. Qed. *) End expectation_measure_of_pmf. @@ -186,7 +199,7 @@ HB.factory Record uniq_isSubPmf {R : realType} {T : choiceType} (mu : T -> R) := uniq_subpmf_le1 : forall J, uniq J -> \sum_(j <- J) mu j <= 1 }. HB.builders Context {R : realType} {T : choiceType} (mu : T -> R) - of @uniq_isSubPmf R T mu. + & @uniq_isSubPmf R T mu. Local Lemma pmf_ge0 x : 0 <= mu x. Proof. exact: subpmf_ge0. Qed. @@ -500,6 +513,24 @@ Lemma in_dunit t t' : t' \in dinsupp (dunit t) -> t' = t :> T. Proof. by rewrite in_dinsupp /= dunit1E pnatr_eq0 eqb0 negbK => /eqP. Qed. End DRat. +(* -------------------------------------------------------------------- *) +Section MeasureOfDunit. +Context {R : realType} {T : choiceType}. + +Local Open Scope ereal_scope. + +Lemma measure_of_pmf_dunit (x : T) (S : set (discrete_measurable_space T)) : + measure_of_pmf (dunit x) S = \d_(x : discrete_measurable_space T) S :> \bar R. +Proof. +rewrite /measure_of_pmf diracE esum_mkcond esum_setT_discrete. +rewrite (eq_esum _ _ (fun y => if x == y then ((y \in S)%:R)%:E else 0)). + move=> y _ /=; rewrite dunit1E. + by case: (x =P y) => [<-|_]; rewrite ?eqxx; case: ifPn. +by rewrite esum_if_eq_op_set1. +Qed. + +End MeasureOfDunit. + (* -------------------------------------------------------------------- *) Section Flip. Context {R : realType}. @@ -749,6 +780,42 @@ Qed. End BindTheory. +(* -------------------------------------------------------------------- *) +Section MeasureOfDlet. +Context {R : realType} {T U : choiceType}. + +Local Open Scope ereal_scope. + +Lemma measure_of_pmf_dlet (mu : R.-pmf T) (nu : T -> R.-pmf U) + (S : set (discrete_measurable_space U)) : + measure_of_pmf (dlet nu mu) S + = \int[measure_of_pmf mu]_x measure_of_pmf (nu x) S. +Proof. +rewrite integral_measure_of_pmf // /measure_of_pmf. +under eq_esum do rewrite /= dlet_EFin. +rewrite exchange_esum . ++ by move=> i j; rewrite lee_fin mulr_ge0. +apply: eq_esum => x _. +rewrite muleC -esumZ //=. +by move=> y _; rewrite lee_fin. +Qed. + +Lemma measurable_measure_of_pmf (nu : T -> R.-pmf U) : + measurable_fun [set: discrete_measurable_space T] + (fun x => (measure_of_pmf (nu x) : giry (discrete_measurable_space U) R)). +Proof. by move=> _ Y _. Qed. + +Lemma measure_of_pmf_dlet_bind (mu : R.-pmf T) (nu : T -> R.-pmf U) + (S : set (discrete_measurable_space U)) : + measure_of_pmf (dlet nu mu) S = giry_bind (measure_of_pmf mu) (measurable_measure_of_pmf nu) S. +Proof. +rewrite /giry_bind/= giry_int_map//=. ++ by apply: measurable_giry_ev. +exact: measure_of_pmf_dlet. +Qed. + +End MeasureOfDlet. + (* -------------------------------------------------------------------- *) Section DLetDLet. Context {R : realType} {T U V : choiceType} @@ -1209,6 +1276,24 @@ Lemma dmargin_dunit (t : T) (f : T -> U): Proof. by apply/dlet_unit. Qed. End MarginalsTh. +(* -------------------------------------------------------------------- *) +Section MeasureOfDmargin. +Context {R : realType} {T U : choiceType}. + +Local Open Scope ereal_scope. + +Lemma measure_of_pmf_dmargin (h : T -> U) (mu : R.-pmf T) + (S : set (discrete_measurable_space U)) : + measure_of_pmf (dmargin h mu) S + = giry_map (measurable_fun_discreteT h) (measure_of_pmf mu) S. +Proof. +rewrite /dmargin measure_of_pmf_dlet. +under eq_integral do rewrite measure_of_pmf_dunit diracE. +by rewrite /giry_map/= /pushforward -(setIT (h @^-1` S)) -integral_indic. +Qed. + +End MeasureOfDmargin. + Notation dfst mu := (dmargin fst mu). Notation dsnd mu := (dmargin snd mu). @@ -1440,101 +1525,6 @@ Qed. End pmf_expectation_lemmas. -Section PrCoreTheory. -Context {R : realType} {T : choiceType}. - -Implicit Types (mu : R.-pmf T) (A B E : pred T). - -Lemma summable_pr E mu : esummable [set:T] (fun x => ((E x)%:R * mu x)%:E). -Proof. -apply/(le_esummable (g := EFin \o mu)) => [x _|//]. -rewrite !lee_tofin//=. - by rewrite mulr_ge0. -by rewrite ler_piMl //= lern1 leq_b1. -Qed. - -Lemma pr_pred0 mu : \P_[mu] pred0 = 0. -Proof. by rewrite /pr esum1 // => x /=; rewrite mul0r. Qed. - -Lemma pr_pred1 mu x : mu x = \P_[mu] (pred1 x). -Proof. -rewrite /pr. -rewrite (eq_esum _ _ (fun y => if x == y then (mu y)%:E else 0)); last first. -+ by rewrite esum_if_eq_op_set1. -move=> y _ /=; rewrite [y == x]eq_sym. -by case: ifP => xy; rewrite ?xy /= ?mul1r ?mul0r. -Qed. - -Lemma pr_exp mu (Q : pred T) : \P_[mu] Q = \E_[mu] (fun m => (Q m)%:R). -Proof. by []. Qed. - -Lemma pr_predT mu : \P_[mu] predT = fine (esum [set: T] (EFin \o mu)). -Proof. -rewrite /pr /pmf_expectation; congr fine. -by apply/eq_esum=> x; rewrite mul1r. -Qed. - -Lemma expectation_pmf_cst mu r : ('E_(measure_of_pmf mu) [cst r] = (\P_[mu] predT)%:E * r)%E. -Proof. -rewrite expectation_pmf. -rewrite esumZ. - by move=> ?; rewrite lee_fin. -rewrite muleC; congr (_ * _)%E. -rewrite pr_predT. -rewrite fineK//=. -rewrite esum_abse//=. -have := @subpmf_summable _ _ mu. -by rewrite esummableE. -Qed. - -Lemma pr_dunit E x : \P_[dunit x] E = (E x)%:R :> R. -Proof. -rewrite /pr. -rewrite (eq_esum _ _ (fun y => if x == y then ((E y)%:R)%:E else 0)). -+ move=> y _ /=; rewrite dunit1E. - by case: ifP => xy; rewrite ?xy /= ?mulr1 ?mulr0. -by rewrite esum_if_eq_op_set1. -Qed. - -Lemma exp_dunit (f : T -> R) (x : T) : \E_[dunit x] f = f x. -Proof. -rewrite /pmf_expectation. -rewrite (eq_esum _ _ (fun y : T => if x == y then (f y)%:E else 0)%E). -+ move => x0 /=; rewrite dunit1E. - by case (x == x0) => //=; rewrite ?mulr1 ?mulr0. -by rewrite esum_if_eq_op_set1. -Qed. - -Lemma pr_ge0 A mu : 0 <= \P_[mu] A. -Proof. -rewrite /pr. -case h: (esum _ _) => //=. -rewrite -lee_fin -h. -apply/esum_ge0 . -by move => ? _ ; rewrite lee_fin mulr_ge0. -Qed. - -Lemma prc_ge0 A B mu : 0 <= \P_[mu, B] A. -Proof. by rewrite /prc mulr_ge0 ?invr_ge0 // pr_ge0. Qed. - -Lemma eq_in_pr A B mu : {in dinsupp mu, A =i B} -> \P_[mu] A = \P_[mu] B. -Proof. -move=> eq_AB; rewrite /pr; congr fine. -apply/eq_esum => x _ /=. -case/boolP: (x \in dinsupp mu). -+ by move/eq_AB; rewrite -!topredE => /= ->. -+ by move/dinsuppPn => ->; rewrite !mulr0. -Qed. - -Lemma eq_pr A B mu : A =i B -> \P_[mu] A = \P_[mu] B. -Proof. by move=> eq_AB; apply/eq_in_pr=> x _; apply/eq_AB. Qed. - -Lemma pr_pred0_eq (mu : R.-pmf T) (E : pred T) : - E =1 pred0 -> \P_[mu] E = 0. -Proof. by move=> eq; rewrite -(pr_pred0 mu); apply/eq_pr. Qed. - -End PrCoreTheory. - Section EspeCoreTheory. Context {R : realType} {T : choiceType}. Implicit Types (mu : R.-pmf T) (A B E : pred T). @@ -1543,12 +1533,9 @@ Local Open Scope ereal_scope. Lemma eexp_dunit (f : T -> \bar R) (x : T) : 'E_(measure_of_pmf (dunit x)) [f] = f x. Proof. -rewrite expectation_pmf. -(*rewrite /epmf_expectation.*) -rewrite (eq_esum _ _ (fun y : T => if x == y then f y else 0%R)%E). -+ move => x0. rewrite dunit1E. - by case (x == x0) => //=; rewrite ?mule1 ?mule0. -by rewrite esum_if_eq_op_set1. +rewrite expectation_def (eq_measure_integral (\d_(x : discrete_measurable_space T))). + by move=> A _ _; exact: measure_of_pmf_dunit. +by rewrite integral_dirac//= diracT mul1e. Qed. Lemma eexp_dlet {U: choiceType} mu (nu : T -> R.-pmf U) F : @@ -1556,30 +1543,22 @@ Lemma eexp_dlet {U: choiceType} mu (nu : T -> R.-pmf U) F : 'E_(measure_of_pmf (dlet nu mu)) [F] = 'E_(measure_of_pmf mu) [fun x => 'E_(measure_of_pmf (nu x)) [F]]. Proof. -move => HF. -rewrite 2!expectation_pmf. -under [in RHS]eq_esum do rewrite expectation_pmf. -have pos (i : T) (j : U) : (0 <= F j * ((mu i)%:E * (nu i j)%:E))%E. - by rewrite !mule_ge0// lee_fin. -rewrite {1}(eq_esum _ _ (fun x : U => (F x * esum [set:T] (fun y : T => (mu y * nu y x)%:E)))). - move => x ?; rewrite /= dletE. - congr ( _ * _)%E. - rewrite fineK//= esum_abse//=. - by move => i; rewrite mulr_ge0. - have : esummable [set: T] (fun x0 : T => (mu x0 * nu x0 x)%:E)%E. - apply/(le_esummable (g := EFin \o mu)) => //=. - by move => x0; rewrite !lee_fin //= mulr_ge0 //= ler_piMr //= subpmf_le1. - by rewrite esummableE. -symmetry. -rewrite {1}(eq_esum _ _ (fun x => esum [set:U] (fun x0 : U => F x0 * ((mu x)%:E * (nu x x0)%:E))%E)). - move => x _; rewrite muleC -esumZ. - by move => x1; rewrite mule_ge0// lee_fin. - rewrite {1}(eq_esum _ _ (fun x0 : U => F x0 * ((mu x)%:E * (nu x x0)%:E))%E)//. - by move=> ? ?; rewrite muleCA. -rewrite exchange_esum//. -apply: eq_esum => u _. -rewrite esumZ//. -by move => ?; rewrite mule_ge0// lee_fin. +move=> HF; rewrite !expectation_def. +under [in RHS]eq_integral do rewrite expectation_def. +rewrite (eq_measure_integral (giry_bind (measure_of_pmf mu) (measurable_measure_of_pmf nu))). + by move=> A _ _; exact: measure_of_pmf_dlet_bind. +by apply: giry_int_bind. +Qed. + +Lemma eexp_dmargin {U : choiceType} (h : T -> U) mu (F : U -> \bar R) : + (forall y, 0 <= F y)%E -> + 'E_(measure_of_pmf (dmargin h mu)) [F] = 'E_(measure_of_pmf mu) [F \o h]. +Proof. +move=> F0; rewrite !expectation_def. +rewrite (eq_measure_integral + (giry_map (measurable_fun_discreteT h) (measure_of_pmf mu))). + by move=> A _ _; exact: measure_of_pmf_dmargin. +by apply: giry_int_map. Qed. Local Open Scope ereal_scope. @@ -1590,9 +1569,7 @@ Lemma eexp_dlet_esp {U: choiceType} mu (nu : T -> R.-pmf U) (g : U -> R) : 'E_(measure_of_pmf mu) [EFin \o (fun x => \E_[nu x] g)]. Proof. move=> g0 sg. -rewrite (eexp_dlet mu nu)/=. - by move=> x; rewrite /= lee_fin. -rewrite !expectation_pmf. +rewrite (eexp_dlet mu nu)//= !expectation_pmf. apply: eq_esum => t _ //=. rewrite expectation_pmf. congr (_ * _)%E. @@ -1602,6 +1579,7 @@ Qed. End EspeCoreTheory. +(* -------------------------------------------------------------------- *) Section espe_pmf. Import MeasurableR. Context {d} {T : pmeasurableType d} {R : realType} (P : probability T R) @@ -1659,6 +1637,106 @@ Qed. End espe_pmf. +(* -------------------------------------------------------------------- *) +Section PrCoreTheory. +Context {R : realType} {T : choiceType}. + +Implicit Types (mu : R.-pmf T) (A B E : pred T). + +Lemma summable_pr E mu : esummable [set:T] (fun x => ((E x)%:R * mu x)%:E). +Proof. +apply/(le_esummable (g := EFin \o mu)) => [x _|//]. +rewrite !lee_tofin//=. + by rewrite mulr_ge0. +by rewrite ler_piMl //= lern1 leq_b1. +Qed. + +Lemma prE_measure mu E : + (\P_[mu] E)%:E = measure_of_pmf mu [set` E]. +Proof. +have fin : \esum_(x in [set: T]) ((E x)%:R * mu x)%:E \is a fin_num. + rewrite esum_abse. + by move=> ?; rewrite mulr_ge0. + by have := summable_pr E mu; rewrite esummableE. +rewrite /pr fineK//. +rewrite /measure_of_pmf [RHS]esum_mkcond esum_setT_discrete. +apply: eq_esum => x _ /=. +have -> : (x \in [set` E]) = E x by apply/idP/idP => [/set_mem//|/mem_set//]. +by case: (E x); rewrite ?mul1r ?mul0r. +Qed. + +Lemma pr_pred0 mu : \P_[mu] pred0 = 0. +Proof. by rewrite /pr esum1 // => x /=; rewrite mul0r. Qed. + +Lemma pr_pred1 mu x : mu x = \P_[mu] (pred1 x). +Proof. +rewrite /pr. +rewrite (eq_esum _ _ (fun y => if x == y then (mu y)%:E else 0)); last first. ++ by rewrite esum_if_eq_op_set1. +move=> y _ /=; rewrite [y == x]eq_sym. +by case: ifP => xy; rewrite ?xy /= ?mul1r ?mul0r. +Qed. + +Lemma pr_exp mu (Q : pred T) : \P_[mu] Q = \E_[mu] (fun m => (Q m)%:R). +Proof. by []. Qed. + +Lemma pr_predT mu : \P_[mu] predT = fine (esum [set: T] (EFin \o mu)). +Proof. +rewrite /pr /pmf_expectation; congr fine. +by apply/eq_esum=> x; rewrite mul1r. +Qed. + +Lemma expectation_pmf_cst mu r : ('E_(measure_of_pmf mu) [cst r] = (\P_[mu] predT)%:E * r)%E. +Proof. +rewrite expectation_pmf. +rewrite esumZ. + by move=> ?; rewrite lee_fin. +rewrite muleC; congr (_ * _)%E. +rewrite pr_predT. +rewrite fineK//=. +rewrite esum_abse//=. +have := @subpmf_summable _ _ mu. +by rewrite esummableE. +Qed. + +Lemma exp_dunit (f : T -> R) (x : T) : \E_[dunit x] f = f x. +Proof. by rewrite /pmf_expectation -expectation_pmfEFin eexp_dunit. Qed. + +Lemma pr_dunit E x : \P_[dunit x] E = (E x)%:R :> R. +Proof. by rewrite pr_exp exp_dunit. Qed. + +Lemma exp_dmargin {U : choiceType} (h : T -> U) mu (g : U -> R) : + (forall y, 0 <= g y) -> \E_[dmargin h mu] g = \E_[mu] (g \o h). +Proof. +move=> g0. +have g0E y : (0 <= (EFin \o g) y)%E by rewrite /= lee_fin. +by rewrite /pmf_expectation -!expectation_pmfEFin (eexp_dmargin h mu g0E). +Qed. + +Lemma pr_ge0 A mu : 0 <= \P_[mu] A. +Proof. by rewrite -lee_fin prE_measure. Qed. + +Lemma prc_ge0 A B mu : 0 <= \P_[mu, B] A. +Proof. by rewrite /prc mulr_ge0 ?invr_ge0 // pr_ge0. Qed. + +Lemma eq_in_pr A B mu : {in dinsupp mu, A =i B} -> \P_[mu] A = \P_[mu] B. +Proof. +move=> eq_AB; rewrite /pr; congr fine. +apply/eq_esum => x _ /=. +case/boolP: (x \in dinsupp mu). ++ by move/eq_AB; rewrite -!topredE => /= ->. ++ by move/dinsuppPn => ->; rewrite !mulr0. +Qed. + +Lemma eq_pr A B mu : A =i B -> \P_[mu] A = \P_[mu] B. +Proof. by move=> eq_AB; apply/eq_in_pr=> x _; apply/eq_AB. Qed. + +Lemma pr_pred0_eq (mu : R.-pmf T) (E : pred T) : + E =1 pred0 -> \P_[mu] E = 0. +Proof. by move=> eq; rewrite -(pr_pred0 mu); apply/eq_pr. Qed. + +End PrCoreTheory. + (* -------------------------------------------------------------------- *) Section PrTheory. Context {R : realType} {T U : choiceType} {I : eqType}. @@ -1682,28 +1760,6 @@ move=> c0 a0; rewrite -esumZ. - by apply: eq_esum => i _; rewrite EFinM. Qed. -Lemma pr_dlet E f (mu : R.-pmf U) : - \P_[dlet f mu] E = \E_[mu] (fun x => \P_[f x] E). -Proof. -rewrite /pr /pmf_expectation. -congr (fine _). -rewrite {1}(eq_esum _ _ (fun t => \esum_(x in [set: U]) ((E t)%:R * (mu x * f x t))%:E)%E). -+ by move => t _; rewrite EFinM dlet_EFin EFin_esumZ // => ?; rewrite mulr_ge0. -rewrite {1} exchange_esum//. -+ move=> t x;rewrite lee_fin. - by apply: mulr_ge0; [exact: ler0n|exact: mulr_ge0]. -apply: eq_esum => x _ //=. -rewrite EFinM prE muleC -EFin_esumZ //. -+ by move => ?; rewrite mulr_ge0. -by apply: eq_esum => t _; rewrite mulrCA. -Qed. - -Lemma pr_dmargin E f (mu : R.-pmf U) : - \P_[dmargin f mu] E = \P_[mu] [pred x | f x \in E]. -Proof. -by rewrite /dmargin pr_dlet pr_exp; apply/eq_pmf_expectation=> x _; rewrite pr_dunit. -Qed. - Lemma eq0_pr A mu : (forall x, x \in dinsupp mu -> x \notin A) -> \P_[mu] A = 0. Proof. @@ -1739,6 +1795,24 @@ rewrite ge0_fin_numE; last first. by apply: esum_ge0 => x _; rewrite lee_fin. Qed. +Lemma pr_dlet E f (mu : R.-pmf U) : + \P_[dlet f mu] E = \E_[mu] (fun x => \P_[f x] E). +Proof. +have fin : esummable [set: U] (fun x => ((\P_[f x] E) * mu x)%:E). + apply/(le_esummable (g := EFin \o mu)) => [x _|//]. + by rewrite !lee_fin mulr_ge0 ?pr_ge0//= ler_piMl ?le1_pr. +apply: EFin_inj; rewrite prE_measure measure_of_pmf_dlet. +under eq_integral do rewrite -prE_measure. +rewrite -expectation_def expectation_pmfEFin /pmf_expectation fineK//. +exact: esummable_esum_fin_num. +Qed. + +Lemma pr_dmargin E f (mu : R.-pmf U) : + \P_[dmargin f mu] E = \P_[mu] [pred x | f x \in E]. +Proof. +by rewrite /dmargin pr_dlet pr_exp; apply/eq_pmf_expectation=> x _; rewrite pr_dunit. +Qed. + Lemma le_exp mu f1 f2 : pmf_esummable mu f1 -> pmf_esummable mu f2 -> f1 <=1 f2 -> \E_[mu] f1 <= \E_[mu] f2. Proof. From 3efa758686cb0bf249658202eaed634d11589f55 Mon Sep 17 00:00:00 2001 From: Lionel Blatter Date: Sun, 8 Nov 2026 20:16:40 +0100 Subject: [PATCH 14/18] Use giry_map for proof of expectation_pmf_dRV. --- theories/probability_theory/counting_distr.v | 76 +++++++++----------- 1 file changed, 33 insertions(+), 43 deletions(-) diff --git a/theories/probability_theory/counting_distr.v b/theories/probability_theory/counting_distr.v index 926fdf6e8c..7a39f50906 100644 --- a/theories/probability_theory/counting_distr.v +++ b/theories/probability_theory/counting_distr.v @@ -287,7 +287,7 @@ Notation "\P_[ mu ] E" := (pr mu E). Notation "\P_[ mu , A ] E" := (prc mu E A). Notation "\E_[ mu ] f" := (pmf_expectation mu f). Notation "\E_[ mu , A ] f" := (espc mu f A). -Notation dweight mu := (\P_[mu] predT). +Abbreviation dweight mu := (\P_[mu] predT). (* NB: not used *) (*Section Esp. @@ -370,7 +370,7 @@ Import MeasurableR. Context {d} {T : pmeasurableType d} {R : realType} (P : probability T R) (X : {dRV P >-> R}). -Local Notation pmfX := (@pmf _ _ _ P X). +Local Abbreviation pmfX := (@pmf _ _ _ P X). Lemma esum_pmf_range : esum [set: R] (EFin \o pmfX) = \esum_(r in range X) (pmfX r)%:E. @@ -433,7 +433,7 @@ End RestrTheory. Section DRat. Context {R : realType} (T : choiceType). -Local Notation distr := R.-pmf T. +Local Abbreviation distr := R.-pmf T. Implicit Types (s : seq T). @@ -535,7 +535,7 @@ End MeasureOfDunit. Section Flip. Context {R : realType}. -Local Notation clamp := (@clamp R 0 1). +Local Abbreviation clamp := (@clamp R 0 1). Definition dflip_fun (xt : R) := fun b => if b then clamp xt else 1 - clamp xt. @@ -1294,8 +1294,8 @@ Qed. End MeasureOfDmargin. -Notation dfst mu := (dmargin fst mu). -Notation dsnd mu := (dmargin snd mu). +Abbreviation dfst mu := (dmargin fst mu). +Abbreviation dsnd mu := (dmargin snd mu). (* -------------------------------------------------------------------- *) Section DSwap. @@ -1585,56 +1585,46 @@ Import MeasurableR. Context {d} {T : pmeasurableType d} {R : realType} (P : probability T R) (X : {dRV P >-> R}). -Local Notation pmfX := (@pmf d T R P X). +Local Abbreviation pmfX := (@pmf d T R P X). Local Open Scope ereal_scope. -Lemma distribution_integral_counting (A : set R) : measurable A -> - distribution P X A = \int[@counting R R]_(r in A) (pmfX r)%:E. -Proof. -move=> mA. -rewrite -dRV_esum_pmf_distribution// integral_counting_esum//=. -by apply/measurable_EFinP; exact: pmf_measurable. -Qed. +Lemma measure_of_pmf_distribution (A : set R) : + measurable A -> + measure_of_pmf pmfX A = distribution P X A. +Proof. exact: dRV_esum_pmf_distribution. Qed. Lemma ge0_expectation_pmf (f : R -> \bar R) : measurable_fun [set: R] f -> (forall r, 0 <= f r) -> 'E_(measure_of_pmf pmfX) [f] = \int[P]_w f (X w). Proof. move=> mf f0. -(*rewrite unlock/=. -rewrite -ge0_integral_distribution//.*) -rewrite expectation_pmf. -have mfh : measurable_fun [set: R] (fun r => f r * (pmfX r)%:E). - by apply: emeasurable_funM => //; apply/measurable_EFinP; exact: pmf_measurable. -have fh0 r : 0 <= f r * (pmfX r)%:E. - by apply: mule_ge0; [exact: f0|rewrite lee_fin pmf_ge0]. -rewrite [LHS](_ : _ = \int[@counting R R]_r (f r * (pmfX r)%:E)). - by rewrite (*/epmf_expectation*) -integral_counting_esum//; exact: measurable_set1. -have <- : \int[distribution P X]_r f r = - \int[@counting R R]_r (f r * (pmfX r)%:E). - rewrite -(integral_measure_of_density _ (pmf_measurable X))//=. - apply: eq_measure_integral => A mA _ /=. - exact: distribution_integral_counting. -by rewrite /distribution ge0_integral_pushforward. -Qed. - -Lemma expectation_pmf_dRV : 'E_(measure_of_pmf pmfX) [EFin] = 'E_P[EFin \o X]. -Proof. -rewrite expectation_pmf. -rewrite (*/epmf_expectation*) esumE expectation_def integralE; congr (_ - _). -- transitivity ('E_(measure_of_pmf pmfX) [(@EFin R)^\+%E]). - rewrite expectation_pmf. - by apply: eq_esum => r _; rewrite !funeposE maxe_pMl ?lee_fin// mul0e. - rewrite ge0_expectation_pmf => //=; first exact: measurable_funepos. +rewrite unlock /= -ge0_integral_distribution//. +have mid : measurable_fun [set: discrete_measurable_space R] + (idfun : discrete_measurable_space R -> R). + by move=> _ Y _. +transitivity (\int[giry_map mid (measure_of_pmf pmfX)]_y f y). + by symmetry; apply: giry_int_map. +apply: eq_measure_integral => A mA _. +exact: measure_of_pmf_distribution. +Qed. + +Lemma expectation_pmf_RV (f : R -> \bar R) : + measurable_fun [set: R] f -> + 'E_(measure_of_pmf pmfX) [f] = \int[P]_w f (X w). +Proof. +move=> mf; rewrite unlock integralE [RHS]integralE; congr (_ - _). +- rewrite -[LHS]expectation_def ge0_expectation_pmf => //=; + first exact: measurable_funepos. by apply: eq_integral => w _; rewrite !funeposE. -- transitivity ('E_(measure_of_pmf pmfX) [(@EFin R)^\-%E]). - rewrite expectation_pmf. - by apply: eq_esum => r _; rewrite !funenegE maxe_pMl ?lee_fin// mul0e mulNe. - rewrite ge0_expectation_pmf//=; first exact: measurable_funeneg. +- rewrite -[LHS]expectation_def ge0_expectation_pmf => //=; + first exact: measurable_funeneg. by apply: eq_integral => w _; rewrite !funenegE. Qed. +Lemma expectation_pmf_dRV : 'E_(measure_of_pmf pmfX) [EFin] = 'E_P[EFin \o X]. +Proof. by rewrite expectation_pmf_RV //= unlock. Qed. + End espe_pmf. (* -------------------------------------------------------------------- *) From 2340e721f0773bf5960783cdb096a3d2866b96ac Mon Sep 17 00:00:00 2001 From: Lionel Blatter Date: Tue, 10 Nov 2026 11:59:58 +0100 Subject: [PATCH 15/18] Add connection between dnull and mzero --- theories/probability_theory/counting_distr.v | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/theories/probability_theory/counting_distr.v b/theories/probability_theory/counting_distr.v index 7a39f50906..23e0911c47 100644 --- a/theories/probability_theory/counting_distr.v +++ b/theories/probability_theory/counting_distr.v @@ -334,6 +334,18 @@ Lemma lef_dnull {R : realType} {T : choiceType} (mu : R.-pmf T) : dnull <=1 mu. Proof. by move=> x; rewrite dnullE. Qed. +(* -------------------------------------------------------------------- *) +Section MeasureOfDnull. +Context {R : realType} {T : choiceType}. + +Local Open Scope ereal_scope. + +Lemma measure_of_pmf_dnull (S : set (discrete_measurable_space T)) : + measure_of_pmf (dnull : R.-pmf T) S = mzero S :> \bar R. +Proof. by rewrite /measure_of_pmf esum1// => x _ /=; rewrite dnullE. Qed. + +End MeasureOfDnull. + (* -------------------------------------------------------------------- *) Section Restr. Context (R : realType) (T : choiceType) (p : pred T). @@ -1538,6 +1550,14 @@ rewrite expectation_def (eq_measure_integral (\d_(x : discrete_measurable_space by rewrite integral_dirac//= diracT mul1e. Qed. +Lemma eexp_dnull (f : T -> \bar R) : + 'E_(measure_of_pmf (dnull : R.-pmf T)) [f] = 0. +Proof. +rewrite expectation_def (eq_measure_integral mzero). + by move=> A _ _; exact: measure_of_pmf_dnull. +by rewrite integral_measure_zero. +Qed. + Lemma eexp_dlet {U: choiceType} mu (nu : T -> R.-pmf U) F : (forall x, 0 <= F x)%E -> 'E_(measure_of_pmf (dlet nu mu)) [F] = @@ -1695,6 +1715,15 @@ Proof. by rewrite /pmf_expectation -expectation_pmfEFin eexp_dunit. Qed. Lemma pr_dunit E x : \P_[dunit x] E = (E x)%:R :> R. Proof. by rewrite pr_exp exp_dunit. Qed. +Lemma exp_dnull (f : T -> R) : \E_[dnull : R.-pmf T] f = 0. +Proof. by rewrite /pmf_expectation -expectation_pmfEFin eexp_dnull. Qed. + +Lemma pr_dnull E : \P_[dnull : R.-pmf T] E = 0. +Proof. by rewrite pr_exp exp_dnull. Qed. + +Lemma dweight_dnull : dweight (dnull : R.-pmf T) = 0. +Proof. exact: pr_dnull. Qed. + Lemma exp_dmargin {U : choiceType} (h : T -> U) mu (g : U -> R) : (forall y, 0 <= g y) -> \E_[dmargin h mu] g = \E_[mu] (g \o h). Proof. From 04e5c3f38ddc8f8b5288cc312c5316d5396cf1b7 Mon Sep 17 00:00:00 2001 From: Lionel Blatter Date: Tue, 10 Nov 2026 12:21:19 +0100 Subject: [PATCH 16/18] Add connection between drestr and mrestr --- theories/probability_theory/counting_distr.v | 28 ++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/theories/probability_theory/counting_distr.v b/theories/probability_theory/counting_distr.v index 23e0911c47..a3322630eb 100644 --- a/theories/probability_theory/counting_distr.v +++ b/theories/probability_theory/counting_distr.v @@ -73,6 +73,13 @@ by apply: (@reindex_esum R T (discrete_measurable_space T) [set: T] [set: discrete_measurable_space T] id f); split. Qed. +Lemma measurable_discrete {T : choiceType} + (A : set (discrete_measurable_space T)) : + measurable A. +Proof. by []. Qed. + +#[global] Hint Resolve measurable_discrete : core. + Lemma measurable_fun_discrete {T : choiceType} {d'} {U : sigmaRingType d'} (D : set (discrete_measurable_space T)) (f : discrete_measurable_space T -> U) : @@ -377,6 +384,24 @@ Lemma drestrE (mu : R.-pmf T) x : Proof. by unlock drestr. Qed. End Restr. +(* -------------------------------------------------------------------- *) +Section MeasureOfDrestr. +Context {R : realType} {T : choiceType}. + +Local Open Scope ereal_scope. + +Lemma measure_of_pmf_drestr (p : pred T) (mu : R.-pmf T) + (mp : measurable ([set` p] : set (discrete_measurable_space T))) + (S : set (discrete_measurable_space T)) : + measure_of_pmf (drestr p mu) S = mrestr (measure_of_pmf mu) mp S. +Proof. +rewrite /mrestr /measure_of_pmf esum_mkcondr. +apply: eq_esum => x _ /=; rewrite drestrE mem_setE unfold_in. +by case: (p x). +Qed. + +End MeasureOfDrestr. + Section pr_pmf. Import MeasurableR. Context {d} {T : pmeasurableType d} {R : realType} (P : probability T R) @@ -1670,8 +1695,7 @@ have fin : \esum_(x in [set: T]) ((E x)%:R * mu x)%:E \is a fin_num. by have := summable_pr E mu; rewrite esummableE. rewrite /pr fineK//. rewrite /measure_of_pmf [RHS]esum_mkcond esum_setT_discrete. -apply: eq_esum => x _ /=. -have -> : (x \in [set` E]) = E x by apply/idP/idP => [/set_mem//|/mem_set//]. +apply: eq_esum => x _ /=; rewrite mem_setE unfold_in. by case: (E x); rewrite ?mul1r ?mul0r. Qed. From 51c0bdabc0eeec29d8a579038b45ef4856147ad5 Mon Sep 17 00:00:00 2001 From: Lionel Blatter Date: Tue, 10 Nov 2026 17:30:26 +0100 Subject: [PATCH 17/18] Some refactoring --- reals/constructive_ereal.v | 7 + theories/esum.v | 22 ++- theories/probability_theory/counting_distr.v | 138 +++++++------------ theories/sequences.v | 6 + 4 files changed, 79 insertions(+), 94 deletions(-) diff --git a/reals/constructive_ereal.v b/reals/constructive_ereal.v index f19497b94d..3ef84efe72 100644 --- a/reals/constructive_ereal.v +++ b/reals/constructive_ereal.v @@ -1190,6 +1190,13 @@ Lemma fin_numM x y : x \is a fin_num -> y \is a fin_num -> x * y \is a fin_num. Proof. by move: x y => [x| |] [y| |]. Qed. +Lemma fin_numMK (a b : \bar R): + fine (a * b) = (fine a * fine b)%R. +Proof. +by case: a => [r| |]; case: b => [s| |]//=; +rewrite /mule/= ?mulr0 ?mul0r//; do ![case: ifPn => //= _]. +Qed. + Lemma prode_fin_num (I : Type) (s : seq I) (P : pred I) (f : I -> \bar R) : (forall i, P i -> f i \is a fin_num) -> \prod_(i <- s | P i) f i \is a fin_num. diff --git a/theories/esum.v b/theories/esum.v index 2e99454fca..c10252d21c 100644 --- a/theories/esum.v +++ b/theories/esum.v @@ -399,6 +399,11 @@ rewrite funenegN (@ge0_funeposE _ _ B)// => y By; apply: f0. by case: AB => _; exact. Qed. +Lemma esum_abse (f : T -> R) : + (forall i, 0 <= f i)%R -> + (\esum_(x in [set: T]) (f x)%:E = \esum_(x in [set: T]) `|(f x)%:E|)%E. +Proof. by move => ?; apply eq_esum => ?? ; rewrite gee0_abs // lee_tofin. Qed. + End esum. Arguments eq_esum {R T} A f g. @@ -603,9 +608,10 @@ Qed. Arguments infinite_esum_cst {R T} c. Section esumZ. -Context {R : realType} {T : choiceType} (A : set T) (f : T -> \bar R). +Context {R : realType} {T : choiceType} (A : set T). -Let ge0_esumZ c : 0 <= c -> (forall t, A t -> 0 <= f t) -> +Let ge0_esumZ c (f : T -> \bar R) : + 0 <= c -> (forall t, A t -> 0 <= f t) -> \esum_(t in A) c * f t = c * \esum_(t in A) f t. Proof. rewrite le_eqVlt => /predU1P[<- _|c0 f0]. @@ -614,7 +620,8 @@ rewrite [in LHS]ge0_esum; first by move=> x /f0 ax0; rewrite ?mule_ge0// ltW. by rewrite ge0_esum//; apply: PosEsum.pos_esumZ => //; exact: ltW. Qed. -Lemma esumZ c : (forall x, A x -> 0 <= f x) -> +Lemma esumZ c (f : T -> \bar R) : + (forall x, A x -> 0 <= f x) -> \esum_(x in A) c * f x = c * \esum_(x in A) f x. Proof. move=> h; rewrite (eq_esum _ _ (fun x => esg c * (`|c| * f x))). @@ -632,6 +639,15 @@ transitivity (esg c * \esum_(x in A) `|c| * f x). by rewrite (eq_esum _ _ (fun x => `|c| * f x))// ge0_esumZ// muleA -numEesg. Qed. +Lemma EFin_esumZ (c : R) (f : T -> R) : + (0 <= c)%R -> (forall i, 0 <= f i)%R -> + \esum_(i in A) (c * f i)%:E = (c%:E * \esum_(i in A) (f i)%:E)%E. +Proof. + move=> c0 a0; rewrite -esumZ. +- by move=> i ?; rewrite lee_fin; exact: a0. +- by apply: eq_esum => i _; rewrite EFinM. +Qed. + End esumZ. Lemma esumD {R : realType} {T : choiceType} (I : set T) (f g : T -> \bar R) : diff --git a/theories/probability_theory/counting_distr.v b/theories/probability_theory/counting_distr.v index a3322630eb..f1b71c0ce3 100644 --- a/theories/probability_theory/counting_distr.v +++ b/theories/probability_theory/counting_distr.v @@ -599,7 +599,7 @@ Context {R : realType} {T U : choiceType} (f : T -> R.-pmf U) (mu : R.-pmf T). Definition dlet_fun := fun y : U => fine (esum [set:T] (fun x => EFin (mu x * f x y))). -Lemma dlet_pos x : 0 <= fine (\esum_(x0 in [set: T]) (mu x0 * f x0 x)%:E). +Let dlet_ge0 x : 0 <= fine (\esum_(x0 in [set: T]) (mu x0 * f x0 x)%:E). Proof. rewrite /fine. case h : (\esum_(i in [set: T]) _) => //=. @@ -607,16 +607,15 @@ rewrite -lee_fin -{}h esum_ge0 // => ??. by rewrite EFinM mule_ge0 //= lee_tofin. Qed. -Lemma isd_dlet : sub_distr dlet_fun. +Let isd_dlet : sub_distr dlet_fun. Proof. split=> [x|J uqJ]. -+ exact: dlet_pos. ++ exact: dlet_ge0. + rewrite /dlet_fun -lee_fin. have hpos : (forall x i, 0 <= (mu x * f x i)%:E )%E. + by move => ?? ;rewrite EFinM mule_ge0 //= lee_tofin. apply /le_trans. + apply sum_esum_ge => // x. - exact: dlet_pos. apply/(le_trans _ (subpmf_sum_le1 mu)). apply/(le_trans (le_esum_fine _ _ hpos)). rewrite exchange_esum // le_esum // => i ?. @@ -644,12 +643,6 @@ Definition dlift {R : realType} {T : choiceType} (f : T -> R.-pmf T) := Definition diter {R : realType} {T : choiceType} n (f : T -> R.-pmf T) := fun a => (iter n (dlift f) (dunit a)). -(* TODO: move (generic lemma) *) -Lemma esum_abse {R : realType} {T : choiceType} (f : T -> R) : - (forall i, 0 <= f i)%R -> - (\esum_(x in [set: T]) (f x)%:E = \esum_(x in [set: T]) `|(f x)%:E|)%E. -Proof. by move => ?; apply eq_esum => ?? ; rewrite gee0_abs // lee_tofin. Qed. - Lemma summable_mu_wgtd {R : realType} {T : choiceType} (f : T -> R) (mu : R.-pmf T) : (forall x, 0 <= f x <= 1) -> esummable [set: T] (fun x => EFin (mu x * f x)). @@ -895,16 +888,25 @@ Qed. End DLetAlg. (* -------------------------------------------------------------------- *) -Lemma mono_nondecressing {R : realType} (T : choiceType) (f : nat -> T -> R) - (hmono : forall n m, (n <= m)%N -> forall x, f n x <= f m x) : +Section Index. +Context {R : realType} (T : choiceType) (f : nat -> T -> R). + +Lemma mono_nondecressing : + (forall n m, (n <= m)%N -> forall x, f n x <= f m x) -> forall x, nondecreasing_seq (fun n => (f n x)%:E). -Proof. by move=> x n m nm; rewrite lee_fin; exact: hmono. Qed. +Proof. by move=> hmono x n m nm; rewrite lee_fin; exact: hmono. Qed. -Lemma sup_range_lim {R : realType} (u : (\bar R)^nat) : - nondecreasing_seq u -> ereal_sup (range u) = limn u. -Proof. -by move=> ndu; apply/esym/cvg_lim => //; exact: ereal_nondecreasing_cvgn. -Qed. +Definition hmono := forall n m, (n <= m)%N -> f n <=1 f m. + +Definition nd := forall x, nondecreasing_seq (fun n => (f n x)%:E). + +Lemma dhomo_dnd : hmono -> nd. +Proof. by move=> hf; apply: mono_nondecressing => n m nm x; exact: hf. Qed. + +Lemma nd_cvg : nd -> forall x, cvgn (fun n => (f n x)%:E). +Proof. by move=> ndf x; apply: ereal_nondecreasing_is_cvgn; exact: ndf. Qed. + +End Index. (* -------------------------------------------------------------------- *) Section dlim. @@ -931,7 +933,7 @@ apply: nearW => n; apply: (@le_trans _ _ (f n x)%:E); first exact: ge_einfs. by rewrite lee_fin subpmf_le1. Qed. -Lemma fin_liminf f x : limn_einf (fun n => (f n x)%:E) \is a fin_num. +Let fin_liminf f x : limn_einf (fun n => (f n x)%:E) \is a fin_num. Proof. have h0 : (0 <= limn_einf (fun n => (f n x)%:E))%E by exact: liminf_ge0. rewrite ge0_fin_numE//. @@ -941,7 +943,7 @@ Qed. Lemma dlim_fun_EFin f x : (dlim_fun f x)%:E = limn_einf (fun n => (f n x)%:E). Proof. by rewrite /dlim_fun fineK// fin_liminf. Qed. -Lemma sumlim {u : T -> (\bar R)^nat} : +Let sumlim {u : T -> (\bar R)^nat} : (forall j, nondecreasing_seq (u j)) -> (forall j, limn (u j) \is a fin_num) -> forall L, (\sum_(j <- L) limn (u j) = limn (fun n => \sum_(j <- L) u j n))%E. Proof. @@ -958,7 +960,7 @@ move=> ndu fu; elim => [|a L IH]. by apply: lee_sum => j _; exact: ndu. Qed. -Lemma isd_dlim f : sub_distr (dlim_fun f). +Let isd_dlim f : sub_distr (dlim_fun f). Proof. split=> [x|J uqJ]. by rewrite /dlim_fun; apply: fine_ge0; exact: liminf_ge0. @@ -989,28 +991,16 @@ Proof. by unlock dlim. Qed. Lemma dlim_EFin f x : (dlim f x)%:E = limn_einf (fun n => (f n x)%:E). Proof. by unlock dlim; exact: dlim_fun_EFin. Qed. -Definition homo (f : nat -> R.-pmf T) := - forall n m, (n <= m)%N -> f n <=1 f m. - -Definition nd (f : nat -> R.-pmf T) := - forall x, nondecreasing_seq (fun n => (f n x)%:E). - -Lemma dhomo_dnd f : homo f -> nd f. -Proof. by move=> hf; apply: mono_nondecressing => n m nm x; exact: hf. Qed. - -Lemma cvg_dlim f : nd f -> forall x, cvgn (fun n => (f n x)%:E). -Proof. by move=> ndf x; apply: ereal_nondecreasing_is_cvgn; exact: ndf. Qed. - Lemma dlim_limE f : nd f -> forall x, dlim f x = fine (limn (fun n => (f n x)%:E)). Proof. -by move=> ndf x; rewrite dlimE is_cvg_limn_einfE//; exact: cvg_dlim. + by move=> ndf x; rewrite dlimE is_cvg_limn_einfE//=; apply nd_cvg. Qed. Lemma dlim_limEFin f : nd f -> forall x, (dlim f x)%:E = limn (fun n => (f n x)%:E). Proof. -by move=> ndf x; rewrite dlim_EFin is_cvg_limn_einfE//; exact: cvg_dlim. +by move=> ndf x; rewrite dlim_EFin is_cvg_limn_einfE//; apply nd_cvg. Qed. Lemma dlim_sup f : nd f -> @@ -1068,10 +1058,10 @@ move => le x; rewrite -(dlimC mu x). by apply : le_dlim => n y. Qed. -Lemma dlim_ub f k : homo f -> f k <=1 dlim f. +Lemma dlim_ub f k : hmono f -> f k <=1 dlim f. Proof. move=> hf x; rewrite -lee_fin (dlim_limEFin (dhomo_dnd hf)). -apply: lime_ge; first exact: (cvg_dlim (dhomo_dnd hf)). +apply: lime_ge; first exact: (nd_cvg (dhomo_dnd hf)). near=> n; apply: (dhomo_dnd hf x). by near: n; apply: nbhs_infty_ge. Unshelve. all: by end_near. @@ -1162,7 +1152,7 @@ Context (R : realType) (T : choiceType) (f : nat -> nat -> R.-pmf T). Context (hmono1: (forall k n1 n2, (n1 <= n2)%N -> f n1 k <=1 f n2 k)). Context (hmono2: (forall k n1 n2, (n1 <= n2)%N -> f k n1 <=1 f k n2)). -Lemma dhomo_apply2 : homo (fun n => f n n). +Lemma dhomo_apply2 : hmono (fun n => f n n). Proof. move=> n m hnm x. apply /le_trans. @@ -1234,28 +1224,28 @@ End DLimDLim. Section dlet_dlim_diag. Context {R : realType} {T U : choiceType}. Context (d : (R.-pmf T)^nat) (h : nat -> T -> R.-pmf R). -Context (hd : homo d). -Context (hmono: (forall k n1 n2, (n1 <= n2)%N -> h n1 k <=1 h n2 k)). +Context (hd : hmono d). +Context (Hmono: (forall k n1 n2, (n1 <= n2)%N -> h n1 k <=1 h n2 k)). Lemma dhomo_nmu_dlet (nmu : nat -> R.-pmf T) : - homo nmu -> homo (fun n => dlet (h n) (nmu n)). + hmono nmu -> hmono (fun n => dlet (h n) (nmu n)). Proof. move=> hnmu n m hnm x. apply: le_dlet. + by move => ?; apply: hnmu. -move => ???; exact: hmono. +move => ???; exact: Hmono. Qed. Lemma dlet_dlim_diag_n : forall n, \dlet_(x <- d n) (\dlim_(n) (h n x)) <=1 \dlim_(n) (dlet (h n) (d n)). Proof. -move=> n u; rewrite -(dlim_let hmono). +move=> n u; rewrite -(dlim_let Hmono). apply: leub_dlim => m w. apply: (@le_trans _ _ ((\dlet_(i <- d (maxn m n)) h (maxn m n) i) w)); last exact: (@dlim_ub _ _ (fun n => dlet (h n) (d n)) (maxn m n) (dhomo_nmu_dlet hd)). apply: le_dlet. + move=> x; apply: hd; exact: leq_maxr. -by move=> ? _; apply: hmono; exact: leq_maxl. +by move=> ? _; apply: Hmono; exact: leq_maxl. Qed. Lemma dlet_dlim_diag : @@ -1269,7 +1259,7 @@ move=> z; apply/eqP; rewrite eq_le; apply/andP; split. + exact: (@dlim_ub _ _ d n hd). move=> x _. apply: dlim_ub. -by move=> *; exact: hmono. +by move=> *; exact: Hmono. Qed. End dlet_dlim_diag. @@ -1485,22 +1475,6 @@ Qed. End pmf_esummable_lemmas. -(* TODO: move (generic lemma) *) -Lemma fineMK {R : realDomainType} (a b : \bar R): - (0 <= b)%E -> a \is a fin_num -> - fine (a * b) = fine a * fine b. -Proof. -move => hp. -move /(elimT (EFin_fin_numP a)) => [r] ->. -case h: b => //=; last first. by move : hp; rewrite h. -have [hc|hc|->] := comparable_ltgtP (comparableT r 0). -+ rewrite lt0_muley => //=. - by rewrite mulr0. -+ rewrite gt0_muley => //=. - by rewrite mulr0. -by rewrite mul0e //= mulr0. -Qed. - Section pmf_expectation_lemmas. Context {R : realType} {T : choiceType}. Implicit Types (mu : R.-pmf T). @@ -1515,7 +1489,7 @@ have hpos : forall x : T, (0%R <= (f x * mu x)%:E)%E. rewrite esumZ //=. have hsum : (0 <= \esum_(i in [set: T]) (f i * mu i)%:E)%E. + by apply esum_ge0 => ??. -by rewrite fineMK. +by rewrite fin_numMK. Qed. Lemma pmf_expectation_cst mu r : \E_[mu] (fun=> r) = \P_[mu] predT * r. @@ -1678,23 +1652,22 @@ Context {R : realType} {T : choiceType}. Implicit Types (mu : R.-pmf T) (A B E : pred T). -Lemma summable_pr E mu : esummable [set:T] (fun x => ((E x)%:R * mu x)%:E). +Lemma prE E mu : (\P_[mu] E)%:E = \esum_(x in [set: T]) ((E x)%:R * mu x)%:E. Proof. -apply/(le_esummable (g := EFin \o mu)) => [x _|//]. -rewrite !lee_tofin//=. - by rewrite mulr_ge0. -by rewrite ler_piMl //= lern1 leq_b1. +rewrite fineK//. ++ rewrite esum_abse; first by move=> ?; rewrite mulr_ge0. + have : esummable [set:T] (fun x => ((E x)%:R * mu x)%:E). + + apply/(le_esummable (g := EFin \o mu)) => [x _|//]. + rewrite !lee_tofin //. + + by rewrite mulr_ge0. + + by rewrite ler_piMl //= lern1 leq_b1. + by rewrite esummableE. Qed. Lemma prE_measure mu E : (\P_[mu] E)%:E = measure_of_pmf mu [set` E]. Proof. -have fin : \esum_(x in [set: T]) ((E x)%:R * mu x)%:E \is a fin_num. - rewrite esum_abse. - by move=> ?; rewrite mulr_ge0. - by have := summable_pr E mu; rewrite esummableE. -rewrite /pr fineK//. -rewrite /measure_of_pmf [RHS]esum_mkcond esum_setT_discrete. +rewrite prE /measure_of_pmf [RHS]esum_mkcond esum_setT_discrete. apply: eq_esum => x _ /=; rewrite mem_setE unfold_in. by case: (E x); rewrite ?mul1r ?mul0r. Qed. @@ -1786,23 +1759,6 @@ Context {R : realType} {T U : choiceType} {I : eqType}. Implicit Types (mu : R.-pmf T) (A B E : pred T). -Lemma prE (nu : R.-pmf T) (E : pred T) : - (\P_[nu] E)%:E = \esum_(t in [set: T]) ((E t)%:R * nu t)%:E. -Proof. -rewrite /pr fineK// esum_abse//. -+ by move => ?; rewrite mulr_ge0. -by have := summable_pr E nu; rewrite esummableE. -Qed. - -Lemma EFin_esumZ {J : choiceType} {c : R} {a : J -> R} : - 0 <= c -> (forall i, 0 <= a i) -> - \esum_(i in [set: J]) (c * a i)%:E = (c%:E * \esum_(i in [set: J]) (a i)%:E)%E. -Proof. -move=> c0 a0; rewrite -esumZ. -- by move=> i ?; rewrite lee_fin; exact: a0. -- by apply: eq_esum => i _; rewrite EFinM. -Qed. - Lemma eq0_pr A mu : (forall x, x \in dinsupp mu -> x \notin A) -> \P_[mu] A = 0. Proof. @@ -1913,7 +1869,7 @@ have hpr1 : forall x, \P_[mu] [predI pred1 x & A] = (A x)%:R * mu x. by rewrite esum_if_eq_op_set1. rewrite (eq_esum _ _ (fun x => ((\P_[mu] A)^-1 * ((A x)%:R * mu x))%:E)). by move=> x _; rewrite /prc hpr1; congr (_ %:E); rewrite mulrC. -rewrite (EFin_esumZ _ a0); last first. rewrite -prE -EFinM mulVf //. +rewrite (EFin_esumZ _ _ a0); last first. rewrite -prE -EFinM mulVf //. + by rewrite gt_eqF. by rewrite invr_ge0// pr_ge0. Qed. diff --git a/theories/sequences.v b/theories/sequences.v index 4893483e3b..e9f22fbf8d 100644 --- a/theories/sequences.v +++ b/theories/sequences.v @@ -1528,6 +1528,12 @@ Lemma ereal_nonincreasing_is_cvgn (R : realType) (u_ : (\bar R) ^nat) : nonincreasing_seq u_ -> cvgn u_. Proof. by move=> ?; apply/cvg_ex; eexists; apply: ereal_nonincreasing_cvgn. Qed. +Lemma sup_range_lim (R : realType) (u : (\bar R)^nat) : + nondecreasing_seq u -> ereal_sup (range u) = limn u. +Proof. +by move=> ndu; apply/esym/cvg_lim => //; exact: ereal_nondecreasing_cvgn. +Qed. + (* NB: see also nondecreasing_series *) Lemma ereal_nondecreasing_series (R : realDomainType) (u_ : (\bar R)^nat) (P : pred nat) N : (forall n, (N <= n)%N -> P n -> 0 <= u_ n) -> From 4ccfe6d922d4aa2f104b8caa1f50389021b6c707 Mon Sep 17 00:00:00 2001 From: Lionel Blatter Date: Tue, 10 Nov 2026 17:42:44 +0100 Subject: [PATCH 18/18] Rename drat into dcount --- theories/probability_theory/counting_distr.v | 48 ++++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/theories/probability_theory/counting_distr.v b/theories/probability_theory/counting_distr.v index f1b71c0ce3..dd05ae926e 100644 --- a/theories/probability_theory/counting_distr.v +++ b/theories/probability_theory/counting_distr.v @@ -467,20 +467,20 @@ Qed. End RestrTheory. (* -------------------------------------------------------------------- *) -Section DRat. +Section DCount. Context {R : realType} (T : choiceType). Local Abbreviation distr := R.-pmf T. Implicit Types (s : seq T). -Definition drat_fun (s : seq T) : T -> R := +Definition dcount_fun (s : seq T) : T -> R := fun x : T => (count (pred1 x) s)%:R / (size s)%:R. -Lemma drat_ge0 s : forall x, 0 <= drat_fun s x. +Lemma dcount_ge0 s : forall x, 0 <= dcount_fun s x. Proof. by move=> x; rewrite mulr_ge0 ?invr_ge0 // ler0n. Qed. -Lemma has_sup_drat s J : uniq J -> \sum_(i <- J) drat_fun s i <= 1. +Lemma has_sup_dcount s J : uniq J -> \sum_(i <- J) dcount_fun s i <= 1. Proof. move=> uqJ; rewrite -mulr_suml /= -natr_sum; case: (size s =P 0%N). by move=> ->; rewrite invr0 mulr0 ler01. @@ -497,8 +497,8 @@ apply/uniq_perm; rewrite ?filter_uniq ?undup_uniq //. by move=> x; rewrite !mem_filter mem_undup andbC. Qed. -Lemma drat_sup s : (0 < size s)%N -> - \sum_(i <- undup s) drat_fun s i = 1. +Lemma dcount_sup s : (0 < size s)%N -> + \sum_(i <- undup s) dcount_fun s i = 1. Proof. move=> gt0_s; rewrite -mulr_suml -natr_sum. apply/(mulIf (x := (size s)%:R)); first by rewrite pnatr_eq0 -lt0n. @@ -507,48 +507,48 @@ rewrite -sum1_size -[in RHS]big_undup_iterop_count/=; apply: eq_bigr => i _. by rewrite Monoid.iteropE iter_addn addn0 mul1n. Qed. -Lemma summable_drat s: esummable [set :T] (EFin \o (drat_fun s)). +Lemma summable_dcount s: esummable [set :T] (EFin \o (dcount_fun s)). Proof. rewrite /esummable (@le_lt_trans _ _ 1%:E) ?ltey//. rewrite ge0_esum. + by move => ? _;rewrite lee_fin. rewrite ge_ereal_sup//= => _ [X [finX _]] <-. rewrite fsumEFin // lee_fin fsbig_finite //=. -rewrite (eq_bigr (drat_fun s)). -+ move => ??; rewrite ger0_norm ?drat_ge0 //. -by apply/has_sup_drat. +rewrite (eq_bigr (dcount_fun s)). ++ move => ??; rewrite ger0_norm ?dcount_ge0 //. +by apply/has_sup_dcount. Qed. -Lemma isd_drat s : sub_distr (drat_fun s). -Proof. by split; [exact/drat_ge0|exact/has_sup_drat]. Qed. +Lemma isd_dcount s : sub_distr (dcount_fun s). +Proof. by split; [exact/dcount_ge0|exact/has_sup_dcount]. Qed. HB.instance Definition _ (s : seq T) := - @uniq_isSubPmf.Build R T (drat_fun s) (proj1 (isd_drat s)) (proj2 (isd_drat s)). + @uniq_isSubPmf.Build R T (dcount_fun s) (proj1 (isd_dcount s)) (proj2 (isd_dcount s)). -Definition drat (s : seq T) := @locked R.-pmf T (drat_fun s). +Definition dcount (s : seq T) := @locked R.-pmf T (dcount_fun s). -Lemma drat1E s x : - drat s x = (count_mem x s)%:R / (size s)%:R. -Proof. by unlock drat. Qed. +Lemma dcount1E s x : + dcount s x = (count_mem x s)%:R / (size s)%:R. +Proof. by unlock dcount. Qed. -Definition dunit x := drat [:: x]. -Definition duni s := drat (undup s). +Definition dunit x := dcount [:: x]. +Definition duni s := dcount (undup s). Lemma dunit1E x y : (dunit x) y = (x == y)%:R. -Proof. by rewrite /dunit drat1E /= addn0 divr1. Qed. +Proof. by rewrite /dunit dcount1E /= addn0 divr1. Qed. Lemma dunit_id x : (dunit x) x = 1. -Proof. by rewrite /dunit drat1E /= addn0 divr1 eqxx. Qed. +Proof. by rewrite /dunit dcount1E /= addn0 divr1 eqxx. Qed. Lemma dunit_diff x y: x <> y -> (dunit x) y = 0. -Proof. by rewrite /dunit drat1E /= addn0 divr1 => /eqP /negPf ->. Qed. +Proof. by rewrite /dunit dcount1E /= addn0 divr1 => /eqP /negPf ->. Qed. Lemma duni1E s x : (duni s) x = (x \in s)%:R / (size (undup s))%:R. -Proof. by rewrite /duni drat1E count_uniq_mem ?(mem_undup, undup_uniq). Qed. +Proof. by rewrite /duni dcount1E count_uniq_mem ?(mem_undup, undup_uniq). Qed. Lemma in_dunit t t' : t' \in dinsupp (dunit t) -> t' = t :> T. Proof. by rewrite in_dinsupp /= dunit1E pnatr_eq0 eqb0 negbK => /eqP. Qed. -End DRat. +End DCount. (* -------------------------------------------------------------------- *) Section MeasureOfDunit.