Skip to content

Commit 33447e3

Browse files
committed
fix after rebase
1 parent ba8406d commit 33447e3

File tree

5 files changed

+90
-105
lines changed

5 files changed

+90
-105
lines changed

theories/lang_syntax.v

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ move/left_right_continuousP.
151151
apply/not_andP; left.
152152
move/(@cvgrPdist_le _ R^o).
153153
apply/existsNP.
154-
exists (2%:R^-1)%R.
154+
exists 2%:R^-1%R.
155155
rewrite not_implyE; split; first by rewrite invr_gt0.
156156
move=> [e /= e0].
157157
move/(_ (-(e / 2))%R).
@@ -690,7 +690,7 @@ split.
690690
exact: exprn_continuous.
691691
Qed.
692692

693-
Lemma derive_onemXn {R : realType} (n : nat) x :
693+
Lemma derive_onemXn {R : realType} n x :
694694
((fun y : R => `1-y ^+ n.+1 : R^o)^`() x = - n.+1%:R * `1-x ^+ n)%R.
695695
Proof.
696696
rewrite (@derive1_comp _ (@onem R) (fun x => GRing.exp x n.+1))//; last first.
@@ -700,7 +700,8 @@ by rewrite -derive1E derive1_cst derive_id sub0r mulrN1 [in RHS]mulNr.
700700
Qed.
701701

702702
Lemma integral_onemXn {R : realType} n :
703-
fine (\int[lebesgue_measure]_(x in `[0%R, 1%R]) (`1-x ^+ n)%:E) = n.+1%:R^-1%R :> R.
703+
fine (\int[lebesgue_measure]_(x in `[0%R, 1%R]) (`1-x ^+ n)%:E)
704+
= (n.+1%:R^-1)%R :> R.
704705
Proof.
705706
rewrite (@continuous_FTC2 _ _ (fun x : R => ((1 - x) ^+ n.+1 / - n.+1%:R))%R)//=.
706707
- rewrite subrr subr0 expr0n/= mul0r expr1n mul1r sub0r.
@@ -723,7 +724,7 @@ exact: continuous_XMonemX.
723724
Qed.
724725

725726
Lemma Rintegral_onemXn {R : realType} n :
726-
(\int[lebesgue_measure]_(x in `[0%R, 1%R]) (`1-x ^+ n))%R = n.+1%:R^-1%R :> R.
727+
(\int[lebesgue_measure]_(x in `[0%R, 1%R]) (`1-x ^+ n) = n.+1%:R^-1 :> R)%R.
727728
Proof.
728729
rewrite /Rintegral.
729730
rewrite (@continuous_FTC2 _ _ (fun x : R => ((1 - x) ^+ n.+1 / - n.+1%:R))%R)//=.
@@ -1991,8 +1992,8 @@ Inductive evalD : forall g t, exp D g t ->
19911992

19921993
| eval_poisson g n (e : exp D g _) f mf :
19931994
e -D> f ; mf ->
1994-
exp_poisson n e -D> poisson_pdf n \o f ;
1995-
measurableT_comp (measurable_poisson_pdf n) mf
1995+
exp_poisson n e -D> poisson_pmf ^~ n \o f ;
1996+
measurableT_comp (measurable_poisson_pmf n measurableT) mf
19961997

19971998
| eval_normalize g t (e : exp P g t) k :
19981999
e -P> k ->
@@ -2381,7 +2382,7 @@ all: rewrite {z g t}.
23812382
- by eexists; eexists; exact: eval_uniform.
23822383
- by eexists; eexists; exact: eval_beta.
23832384
- move=> g h e [f [mf H]].
2384-
by exists (poisson_pdf h \o f); eexists; exact: eval_poisson.
2385+
by exists (poisson_pmf ^~ h \o f); eexists; exact: eval_poisson.
23852386
- move=> g t e [k ek].
23862387
by exists (normalize_pt k); eexists; exact: eval_normalize.
23872388
- move=> g t1 t2 x e1 [k1 ev1] e2 [k2 ev2].
@@ -2579,8 +2580,9 @@ Proof. exact/execD_evalD/eval_normalize/evalP_execP. Qed.
25792580

25802581
Lemma execD_poisson g n (e : exp D g Real) :
25812582
execD (exp_poisson n e) =
2582-
existT _ (poisson_pdf n \o projT1 (execD e))
2583-
(measurableT_comp (measurable_poisson_pdf n) (projT2 (execD e))).
2583+
existT _ (poisson_pmf ^~ n \o projT1 (execD e))
2584+
(measurableT_comp (measurable_poisson_pmf n measurableT)
2585+
(projT2 (execD e))).
25842586
Proof. exact/execD_evalD/eval_poisson/evalD_execD. Qed.
25852587

25862588
Lemma execP_if g st e1 e2 e3 :

theories/lang_syntax_examples.v

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,8 @@ Let ite_3_10 : R.-sfker mbool * munit ~> measurableTypeR R :=
713713
ite macc0of2 (@ret _ _ _ (measurableTypeR R) R _ (kr 3)) (@ret _ _ _ (measurableTypeR R) R _ (kr 10)).
714714

715715
Let score_poisson4 : R.-sfker measurableTypeR R * (mbool * munit) ~> munit :=
716-
score (measurableT_comp (measurable_poisson_pdf 4) (@macc0of2 _ _ (measurableTypeR R) _)).
716+
score (measurableT_comp (measurable_poisson_pmf 4 measurableT)
717+
(@macc0of2 _ _ (measurableTypeR R) _)).
717718

718719
Let kstaton_bus' :=
719720
letin' sample_bern
@@ -755,7 +756,7 @@ Lemma exec_staton_bus : execD staton_bus_syntax =
755756
existT _ (normalize_pt kstaton_bus') (measurable_normalize_pt _).
756757
Proof. by rewrite execD_normalize_pt exec_staton_bus0'. Qed.
757758

758-
Let poisson4 := @poisson_pdf R 4%N.
759+
Let poisson4 := @poisson_pmf R ^~ 4%N.
759760

760761
Let staton_bus_probability U :=
761762
((2 / 7)%:E * (poisson4 3)%:E * \d_true U +
@@ -773,13 +774,13 @@ rewrite -!muleA; congr (_ * _ + _ * _)%E.
773774
rewrite letin'_retk//.
774775
rewrite letin'_kret//.
775776
rewrite /score_poisson4.
776-
by rewrite /score/= /mscale/= ger0_norm//= poisson_pdf_ge0.
777+
by rewrite /score/= /mscale/= ger0_norm//= poisson_pmf_ge0.
777778
- by rewrite onem27.
778779
- rewrite letin'_iteF//.
779780
rewrite letin'_retk//.
780781
rewrite letin'_kret//.
781782
rewrite /score_poisson4.
782-
by rewrite /score/= /mscale/= ger0_norm//= poisson_pdf_ge0.
783+
by rewrite /score/= /mscale/= ger0_norm//= poisson_pmf_ge0.
783784
Qed.
784785

785786
End staton_bus.
@@ -808,7 +809,8 @@ Let ite_3_10 : R.-sfker mbool * munit ~> measurableTypeR R :=
808809
ite macc0of2 (@ret _ _ _ (measurableTypeR R) R _ (kr 3)) (@ret _ _ _ (measurableTypeR R) R _ (kr 10)).
809810

810811
Let score_poisson4 : R.-sfker measurableTypeR R * (mbool * munit) ~> munit :=
811-
score (measurableT_comp (measurable_poisson_pdf 4) (@macc0of3' _ _ _ (measurableTypeR R) _ _)).
812+
score (measurableT_comp (measurable_poisson_pmf 4 measurableT)
813+
(@macc0of3' _ _ _ (measurableTypeR R) _ _)).
812814

813815
(* same as kstaton_bus _ (measurable_poisson 4) but expressed with letin'
814816
instead of letin *)
@@ -884,7 +886,7 @@ rewrite execP_return exp_var'E/= (execD_var_erefl "x") //=.
884886
by apply/eq_sfkernel => /= -[[] [a [b []]]] U0.
885887
Qed.
886888

887-
Let poisson4 := @poisson_pdf R 4%N.
889+
Let poisson4 := @poisson_pmf R ^~ 4%N.
888890

889891
Lemma exec_staton_busA0 U : execP staton_busA_syntax0 tt U =
890892
((2 / 7%:R)%:E * (poisson4 3%:R)%:E * \d_true U +

theories/prob_lang.v

Lines changed: 23 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ From mathcomp Require Import lebesgue_integral trigo probability kernel charge.
1818
(* ESOP 2017 *)
1919
(* *)
2020
(* ``` *)
21-
(* poisson_pdf == Poisson pdf *)
22-
(* exponential_pdf == exponential distribution pdf *)
2321
(* measurable_sum X Y == the type X + Y, as a measurable type *)
2422
(* ``` *)
2523
(* *)
@@ -113,61 +111,26 @@ subst p2.
113111
by f_equal.
114112
Qed.
115113

116-
(* NB: to be PRed to probability.v *)
117-
Section poisson_pdf.
118-
Variable R : realType.
119-
Local Open Scope ring_scope.
120-
121-
(* density function for Poisson *)
122-
Definition poisson_pdf k r : R :=
123-
if r > 0 then r ^+ k / k`!%:R^-1 * expR (- r) else 1%:R.
124-
125-
Lemma poisson_pdf_ge0 k r : 0 <= poisson_pdf k r.
126-
Proof.
127-
rewrite /poisson_pdf; case: ifPn => r0//.
128-
by rewrite mulr_ge0 ?expR_ge0// mulr_ge0// exprn_ge0 ?ltW.
129-
Qed.
114+
Definition poisson3 {R : realType} := @poisson_pmf R 3%:R 4. (* 0.168 *)
115+
Definition poisson10 {R : realType} := @poisson_pmf R 10%:R 4. (* 0.019 *)
130116

131-
Lemma poisson_pdf_gt0 k r : 0 < r -> 0 < poisson_pdf k.+1 r.
117+
(* TODO: move *)
118+
Lemma poisson_pmf_gt0 {R : realType} k (r : R) :
119+
(0 < r -> 0 < poisson_pmf r k.+1)%R.
132120
Proof.
133-
move=> r0; rewrite /poisson_pdf r0 mulr_gt0 ?expR_gt0//.
121+
move=> r0; rewrite /poisson_pmf r0 mulr_gt0 ?expR_gt0//.
134122
by rewrite divr_gt0// ?exprn_gt0// invr_gt0 ltr0n fact_gt0.
135123
Qed.
136124

137-
Lemma measurable_poisson_pdf k : measurable_fun setT (poisson_pdf k).
138-
Proof.
139-
rewrite /poisson_pdf; apply: measurable_fun_if => //.
140-
exact: measurable_fun_ltr.
141-
by apply: measurable_funM => /=;
142-
[exact: measurable_funM|exact: measurableT_comp].
143-
Qed.
144-
145-
Definition poisson3 := poisson_pdf 4 3%:R. (* 0.168 *)
146-
Definition poisson10 := poisson_pdf 4 10%:R. (* 0.019 *)
147-
148-
End poisson_pdf.
149-
150-
Section exponential_pdf.
151-
Variable R : realType.
152-
Local Open Scope ring_scope.
153-
154-
(* density function for exponential *)
155-
Definition exponential_pdf x r : R := r * expR (- r * x).
156-
157-
Lemma exponential_pdf_gt0 x r : 0 < r -> 0 < exponential_pdf x r.
158-
Proof. by move=> r0; rewrite /exponential_pdf mulr_gt0// expR_gt0. Qed.
159-
160-
Lemma exponential_pdf_ge0 x r : 0 <= r -> 0 <= exponential_pdf x r.
161-
Proof. by move=> r0; rewrite /exponential_pdf mulr_ge0// expR_ge0. Qed.
162-
163-
Lemma measurable_exponential_pdf x : measurable_fun setT (exponential_pdf x).
125+
Lemma exponential_pdf_gt0 {R : realType} (r : R) x :
126+
(0 < r -> 0 < x -> 0 < exponential_pdf r x)%R.
164127
Proof.
165-
apply: measurable_funM => //=; apply: measurableT_comp => //.
166-
exact: measurable_funM.
128+
move=> r0 x0; rewrite /exponential_pdf/=.
129+
rewrite patchE/= ifT; last first.
130+
by rewrite inE/= in_itv/= (ltW x0).
131+
by rewrite mulr_gt0// expR_gt0.
167132
Qed.
168133

169-
End exponential_pdf.
170-
171134
(* X + Y is a measurableType if X and Y are *)
172135
HB.instance Definition _ (X Y : pointedType) :=
173136
isPointed.Build (X + Y)%type (@inl X Y point).
@@ -1704,8 +1667,8 @@ End staton_bus.
17041667
Section staton_bus_poisson.
17051668
Import Notations.
17061669
Context d (T : measurableType d) (R : realType).
1707-
Let poisson4 := @poisson_pdf R 4%N.
1708-
Let mpoisson4 := @measurable_poisson_pdf R 4%N.
1670+
Let poisson4 r := @poisson_pmf R r 4%N.
1671+
Let mpoisson4 := @measurable_poisson_pmf R setT 4%N measurableT.
17091672

17101673
Definition kstaton_bus_poisson : R.-sfker R ~> mbool :=
17111674
kstaton_bus _ mpoisson4.
@@ -1720,12 +1683,12 @@ rewrite -!muleA; congr (_ * _ + _ * _).
17201683
- rewrite letin_kret//.
17211684
rewrite letin_iteT//.
17221685
rewrite letin_retk//.
1723-
by rewrite scoreE//= => r r0; exact: poisson_pdf_ge0.
1686+
by rewrite scoreE//= => r r0; exact: poisson_pmf_ge0.
17241687
- by rewrite onem27.
17251688
rewrite letin_kret//.
17261689
rewrite letin_iteF//.
17271690
rewrite letin_retk//.
1728-
by rewrite scoreE//= => r r0; exact: poisson_pdf_ge0.
1691+
by rewrite scoreE//= => r r0; exact: poisson_pmf_ge0.
17291692
Qed.
17301693

17311694
(* true -> 2/7 * 0.168 = 2/7 * 3^4 e^-3 / 4! *)
@@ -1740,7 +1703,7 @@ Lemma staton_busE P (t : R) U :
17401703
Proof.
17411704
rewrite /staton_bus normalizeE !kstaton_bus_poissonE !diracT !mule1 ifF //.
17421705
apply/negbTE; rewrite gt_eqF// lte_fin.
1743-
by rewrite addr_gt0// mulr_gt0//= ?divr_gt0// ?ltr0n// poisson_pdf_gt0// ltr0n.
1706+
by rewrite addr_gt0// mulr_gt0//= ?divr_gt0// ?ltr0n// poisson_pmf_gt0// ltr0n.
17441707
Qed.
17451708

17461709
End staton_bus_poisson.
@@ -1770,12 +1733,14 @@ rewrite -!muleA; congr (_ * _ + _ * _).
17701733
- rewrite letin_kret//.
17711734
rewrite letin_iteT//.
17721735
rewrite letin_retk//.
1773-
rewrite scoreE//= => r r0; exact: exponential_pdf_ge0.
1736+
rewrite scoreE//= => r r0; apply: exponential_pdf_ge0 => //.
1737+
by rewrite ler0q; lra.
17741738
- by rewrite onem27.
17751739
rewrite letin_kret//.
17761740
rewrite letin_iteF//.
17771741
rewrite letin_retk//.
1778-
by rewrite scoreE//= => r r0; exact: exponential_pdf_ge0.
1742+
rewrite scoreE//= => r r0; apply: exponential_pdf_ge0.
1743+
by rewrite ler0q; lra.
17791744
Qed.
17801745

17811746
(* true -> 5/7 * 0.019 = 5/7 * 10^4 e^-10 / 4! *)
@@ -1791,12 +1756,12 @@ Proof.
17911756
rewrite /staton_bus.
17921757
rewrite normalizeE /= !kstaton_bus_exponentialE !diracT !mule1 ifF //.
17931758
apply/negbTE; rewrite gt_eqF// lte_fin.
1794-
by rewrite addr_gt0// mulr_gt0//= ?divr_gt0// ?ltr0n// exponential_pdf_gt0 ?ltr0n.
1759+
by rewrite addr_gt0// mulr_gt0//= ?divr_gt0// ?ltr0n//;
1760+
rewrite exponential_pdf_gt0 ?ltr0n// ltr0q; lra.
17951761
Qed.
17961762

17971763
End staton_bus_exponential.
17981764

1799-
18001765
Section von_neumann_trick.
18011766
Context d {T : measurableType d} {R : realType}.
18021767

theories/prob_lang_wip.v

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,27 @@ Variable R : realType.
2828
Local Open Scope ring_scope.
2929
Notation mu := (@lebesgue_measure R).
3030
Hypothesis integral_poisson_density : forall k,
31-
(\int[mu]_x (@poisson_pdf R k x)%:E = 1%E)%E.
31+
(\int[mu]_x (@poisson_pmf R x k)%:E = 1%E)%E.
3232

3333
(* density function for poisson *)
34-
Definition poisson1 := @poisson_pdf R 1%N.
34+
Definition poisson1 r := @poisson_pmf R r 1%N.
3535

3636
Lemma poisson1_ge0 (x : R) : 0 <= poisson1 x.
37-
Proof. exact: poisson_pdf_ge0. Qed.
37+
Proof. exact: poisson_pmf_ge0. Qed.
3838

3939
Definition mpoisson1 (V : set R) : \bar R :=
4040
(\int[lebesgue_measure]_(x in V) (poisson1 x)%:E)%E.
4141

4242
Lemma measurable_fun_poisson1 : measurable_fun setT poisson1.
43-
Proof. exact: measurable_poisson_pdf. Qed.
43+
Proof. exact: measurable_poisson_pmf. Qed.
4444

4545
Let mpoisson10 : mpoisson1 set0 = 0%E.
4646
Proof. by rewrite /mpoisson1 integral_set0. Qed.
4747

4848
Lemma mpoisson1_ge0 A : (0 <= mpoisson1 A)%E.
4949
Proof.
5050
apply: integral_ge0 => x Ax.
51-
by rewrite lee_fin poisson1_ge0.
51+
rewrite lee_fin poisson1_ge0//.
5252
Qed.
5353

5454
Let mpoisson1_sigma_additive : semi_sigma_additive mpoisson1.
@@ -57,12 +57,12 @@ move=> /= F mF tF mUF.
5757
rewrite /mpoisson1/= integral_bigcup//=; last first.
5858
apply/integrableP; split.
5959
apply/measurable_EFinP.
60-
exact: measurable_funS (measurable_poisson_pdf _).
60+
exact: measurable_funS (measurable_poisson_pmf _ measurableT).
6161
rewrite (_ : (fun x => _) = (EFin \o poisson1)); last first.
6262
by apply/funext => x; rewrite gee0_abs// lee_fin poisson1_ge0//.
6363
apply: le_lt_trans.
6464
apply: (@ge0_subset_integral _ _ _ _ _ setT) => //=.
65-
by apply/measurable_EFinP; exact: measurable_poisson_pdf.
65+
by apply/measurable_EFinP; exact: measurable_poisson_pmf.
6666
by move=> ? _; rewrite lee_fin poisson1_ge0//.
6767
by rewrite /= integral_poisson_density// ltry.
6868
apply: is_cvg_ereal_nneg_natsum_cond => n _ _.
@@ -90,19 +90,19 @@ Variable R : realType.
9090
Notation mu := (@lebesgue_measure R).
9191
Import Notations.
9292
Hypothesis integral_poisson_density : forall k,
93-
(\int[mu]_x (@poisson_pdf R k x)%:E = 1%E)%E.
93+
(\int[mu]_x (@poisson_pmf R x k)%:E = 1%E)%E.
9494

95-
Let f1 x := ((poisson1 (x : R)) ^-1)%R.
95+
Let f1 x := ((poisson1 (x : R))^-1)%R.
9696

9797
Let mf1 : measurable_fun setT f1.
98-
rewrite /f1 /poisson1 /poisson_pdf.
98+
rewrite /f1 /poisson1 /poisson_pmf.
9999
apply: (measurable_comp (F := [set r : R | r != 0%R])) => //.
100100
- exact: open_measurable.
101101
- move=> /= r [t ? <-].
102102
by case: ifPn => // t0; rewrite gt_eqF ?mulr_gt0 ?expR_gt0//= invrK ltr0n.
103103
- apply: open_continuous_measurable_fun => //.
104104
by apply/in_setP => x /= x0; exact: inv_continuous.
105-
- exact: measurable_poisson_pdf.
105+
- exact: measurable_poisson_pmf.
106106
Qed.
107107

108108
Definition staton_counting : R.-sfker X ~> _ :=

0 commit comments

Comments
 (0)