Module infotheo.toy_examples.expected_value_variance_ordn

Require realType_ext.
From mathcomp Require Import all_ssreflect ssralg ssrnum lra ring.
From mathcomp Require Import reals.
Require Import realType_ext ssralg_ext fdist proba.


Set Implicit Arguments.
Set SsrOldRewriteGoalsOrder.
Unset Strict Implicit.
Import Prenex Implicits.

Local Open Scope reals_ext_scope.
Local Open Scope tuple_ext_scope.
Local Open Scope ring_scope.

Import GRing.Theory Num.Theory Order.Theory.

From mathcomp Require Import normedtype.
Import numFieldNormedType.Exports.

Section expected_value_variance_ordn.

Variable R : realType.

Definition
ord1

ord1 : all_equal_to (ord0 : 'I_1) ord1 is not universe polymorphic Arguments ord1 x ord1 is opaque Expands to: Constant mathcomp.boot.fintype.ord1 Declared in library mathcomp.boot.fintype, line 2260, characters 6-10

{n} := lift ord0 (@ord0 n).
Definition
ord2

ord2 not a defined object.

{n} := lift ord0 (@ord1 n).

Lemma ord0E n : 0%nat = @ord0 n
Proof.
done. Qed.
Lemma ord1E n : 1%nat = @ord1 n
Proof.
done. Qed.
Lemma ord2E n : 2%nat = @ord2 n
Proof.
done. Qed.

Definition
pmf

pmf not a defined object.

: {ffun 'I_3 -> R} :=
  finfun [fun x => 0 with ord0 |-> 1/2, ord1 |-> 1/3, ord2 |-> 1/6].

Lemma pmf_ge0 : [forall a : 'I_3, 0 <= pmf a].
Proof.
apply/forallP => a.
rewrite /pmf ffunE /=.
by do! case: ifP => _; lra.
Qed.

Lemma pmf01 : [forall a, 0 <= pmf a] && (\sum_(a in 'I_3) pmf a == 1).
Proof.
apply/andP; split; first exact: pmf_ge0.
by apply/eqP; rewrite 3!big_ord_recl big_ord0 /= /pmf !ffunE /=; lra.
Qed.

Local Open Scope fdist_scope.
Local Open Scope proba_scope.

Definition
P

P not a defined object.

: {fdist 'I_3} := FDist.mk pmf01.

Definition
X

X not a defined object.

: {RV P -> R} := (fun i => i.+1%:R).

Lemma expected : `E X = 5/3.
Proof.
rewrite /Ex.
rewrite 3!big_ord_recl big_ord0 /=.
rewrite /pmf /X !ffunE /= /bump /= -!mulr_regl.
by field.
Qed.

Lemma variance : `V X = 5/9.
Proof.
rewrite VarE expected /Ex /X !RV_fctE/=.
rewrite 3!big_ord_recl big_ord0 /=.
rewrite !ffunE /bump /= -!mulr_regl.
by field.
Qed.

End expected_value_variance_ordn.