(****************************************************************************** Markov's inequality.  Based on Wikipedia proof Copyright 2008 Robert Kam  This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.  You should have received a copy of the GNU Lesser General Public License along with this program.  If not, see <http://www.gnu.org/licenses/>. ******************************************************************************)
(* sigalg = sigma algebra preimg = preimage cntabl = countable msur = measure function msurable = measurable simple = simple function lebint = Lebesgue integral lebint_s = Lebesgue integral for simple function borl = Borel set unoin = union *)
(****************************************************************************** Note: chicli_pottier_simpson, classic, Extensionality_Ensembles, NNPP are used frequently Also lemmas from Rtopology which use classic as well as R_total_order ******************************************************************************)
Require Export Powerset.
Require Export Rtopology.
Require Export Raxioms.
Require Export Rfunctions.
Require Export Image.
Require Export RIneq.
Require Export PartSum.
intros EM. pose(select:=fun b:bool=>if b then P else ~P). assert{b:bool|
select b}as([|],HP). apply constructive_definite_description. rewrite<-
unique_existence;split. destruct EM. exists true;trivial. exists false;trivial.
intros[|][|]H1 H2;simpl in *;reflexivity||contradiction. left;trivial. right;
trivial. Qed.
Definition cntabl(U:Type)(C:Ensemble(Ensemble U)):=
exists f:nat->Ensemble U,forall c,C c->exists i:nat,f i=c.
(**)
intros sIH n. induction n. intros n' Hn'. apply sIH. intros. elimtype False;
intuition. intuition. Qed.
(**)
intros k. apply aaron_stump_cse545 with(Q:=fun z=>Q z->exists m,Q m/\forall n
,Q n->m<=n)(n:=k). 2:auto. intros n H H1. elim(classic(forall i,i<n->~Q i)).
intro H2. exists n. split. auto. intros j H3. apply NNPP. red;intro H4. apply(
H2 j). intuition. auto.
(**)
intro H2. assert(H3:exists i:nat,i<n/\Q i). apply NNPP. red;intro H3. apply H2.
intros i H4. red;intro H5. apply H3. exists i. auto. elim H3. intros ii H4.
elim(H ii). intros m H5. exists m. auto. tauto. tauto. Qed.
(**)
intros H. elim H. intros f H1. assert(H2:forall c,C c->{i|f i=c/\forall j,f
j=c->i<=j}). intros c H2. apply constructive_definite_description. elim(H1 c).
intros k H3. elim(first_sat(fun i=>f i=c)k). intros m H4. exists m. red. split.
auto. intuition. auto. auto.
(**)
exists(fun c c'=>proj1_sig(H2 c c')). split. intros. elim(proj2_sig(H2 c c')).
elim(proj2_sig(H2 c c'')). intuition. intros c cc c' cc' H3. elim(proj2_sig(H2
c c')). elim(proj2_sig(H2 cc cc')). intros H4 H5 H6 H7. rewrite<-H4. rewrite<-
H6. auto. Qed.
(**)
intros g g' g''. red. elim(classic(Inhabited _ C)). 2:intro H;exists(fun _:
nat=>Empty_set U);intros;elimtype False;apply H;exists c;auto. intro H. elim H.
intros d d'. assert(Q:forall i,{c|C c/\(forall z z',g z z'=i->c=z)/\((forall z
z',g z z'<>i)->c=d)}). intro. elim(chicli_pottier_simpson(exists z,C z/\forall
z',g z z'=i)(classic(exists z,C z/\forall z',g z z'=i))).
(**)
intro H1. assert(H2:exists!z,C z/\forall z',g z z'=i). elim H1. intros z z'.
exists z. split. auto. intros Z Z'. elim z';elim Z'. intros Z'' Z''' z'' z'''.
apply(g'' z Z z'' Z''). rewrite(Z''' Z''). auto. elim(
constructive_definite_description _ _ H2). intros z z'. elim z'. intros z''
z'''. exists z. split. auto. split. intros Z Z' Z''. apply(g'' z Z z'' Z').
rewrite Z'';auto. intro H3. elimtype False. apply(H3 z z''). auto.
(**)
intro H1. exists d. split. auto. split. intros z z' z''. elimtype False. apply
H1. exists z. split. auto. intro z'''. rewrite<-z''. apply g'. auto.
(**)
exists(fun i=>proj1_sig(Q i)). intros c c'. exists(g c c'). elim(proj2_sig(Q(g
c c'))). intros H1 H2. elim H2;intros H3 H4. eapply H3. intuition. Qed.
Definition unoin(U:Type)(C:Ensemble(Ensemble U)):=
fun x:U=>exists c,C c/\c x.
(*----------------------------------------------------------------------------- This and the following other two Definitions are the three parts of the definition of what it means to be a sigma-algebra. -----------------------------------------------------------------------------*)
Definition sigalg_0(U:Type)(F:Ensemble(Ensemble U)):=
Inhabited _ F.
Definition sigalg_1(U:Type)(F:Ensemble(Ensemble U)):=
forall A:Ensemble U,F A->F(Complement _ A).
Definition sigalg_2(U:Type)(F:Ensemble(Ensemble U)):=
forall C:Ensemble(Ensemble U),Included _ C F->cntabl _ C
->F(unoin _ C).
(**)
intros U F F' F'' F''' A B A' B'. set(f:=fun i:nat=>if(eq_nat_dec i 0)then A
else B). assert(H:unoin _(fun A=>exists i,f i=A)=Union _ A B). apply(
Extensionality_Ensembles U). split. red. intros x H. elim H. intros c H1. elim
H1. intros H2 H3. elim H2. intros i H4. rewrite<-H4 in H3. red in H3. elim(
eq_nat_dec i 0). intro a. rewrite a in H3. intuition. intro b. assert(H5:(if
eq_nat_dec i 0 then A else B)=B). elim(eq_nat_dec i 0). intuition. auto.
rewrite H5 in H3. intuition.
(**)
red. intros x H. elim H. intros. exists A. split. exists 0. auto. auto. intros.
exists B. split. exists 1. auto. auto. rewrite<-H. apply F'''. red. intros c c'
. elim c'. intros i i'. elim i'. elim(eq_nat_dec i 0). intro a. rewrite a. auto
. intro b. assert(H1:f i=B). unfold f. elim(eq_nat_dec i 0). intuition. auto.
rewrite H1. auto. red. exists f. auto. Qed.
(**)
intros. elim F'. intros A A'. cut(Empty_set U=Complement _(Union _ A(Complement
_ A))). intro H. rewrite H. apply F''. apply(sigalg_P0 _ F F' F'' F'''). auto.
apply F''. auto.
(**)
apply Extensionality_Ensembles. split. intuition. red. intros x x'. elimtype
False. elim(classic(A x)). intuition. intuition. Qed.
(**)
intros U F F' F'' F''' A B A' B'. cut(Intersection _ A B=Complement _(Union _(
Complement _ A)(Complement _ B))). intro H. rewrite H. apply F''. apply(
sigalg_P0 _ F F' F'' F'''). apply F''. auto. apply F''. auto.
(**)
apply Extensionality_Ensembles. split. red. unfold Complement;unfold In;unfold
not. intros x x' x''. elim(Intersection_inv _ _ _ _ x'). elim(Union_inv _ _ _ _
x''). auto. auto. split. apply NNPP. auto with sets. apply NNPP. auto with sets
. Qed.
(**)
intros. cut(Full_set U=Complement _(Empty_set U)). intro H. rewrite H. apply
F''. apply(sigalg_P1 _ F F' F'' F'''). apply Extensionality_Ensembles. split.
red. unfold Complement;unfold In. intuition. red. intros. apply Full_intro. Qed
.
Inductive borl(D:Ensemble R):Prop:=
|borl_0:open_set D->borl D
|borl_1:borl(Complement _ D)->borl D
|borl_2:forall C:Ensemble(Ensemble R),(forall c,C c->borl c)
->cntabl _ C->D=_D(unoin _ C)->borl D.
Definition preimg(U:Type)(f:U->R)(D:Ensemble R):=
fun x:U=>D(f x).
Definition msurable(U:Type)(F:Ensemble(Ensemble U))
(F':sigalg_0 _ F)(F'':sigalg_1 _ F)(F''':sigalg_2 _ F)
(f:U->R):=forall(D:Ensemble R),borl D->F(preimg _ f D).
(**)
intros. apply(Extensionality_Ensembles U). split. red;unfold In. intros x x'.
elim x'. unfold P. intuition. red;unfold In. intros x x'. unfold P. elim(
archimed(f x-a)). intros H H1;clear H1. induction(up(f x-a)). simpl in H.
elimtype False. apply(Rlt_not_ge(f x-a)0). auto. apply(Rplus_ge_reg_l a).
replace(a+(f x-a))%R with(f x). 2:ring. replace(a+0)%R with a. 2:ring. auto.
(**)
exists(nat_of_P p). split. intuition. unfold IZR in H. rewrite <- INR_IPR in H. apply Rge_le. apply Rgt_ge.
apply(Rplus_gt_reg_l(-a)%R). replace(-a+(a+INR(nat_of_P p)))%R with (INR(
nat_of_P p)). 2:ring. replace(-a+f x)%R with(f x-a)%R. 2:ring. auto.
(**)
unfold IZR in H; rewrite <- INR_IPR in H. elimtype False. apply(Rlt_not_ge(f x-a)0). apply Rgt_trans with(-
INR(nat_of_P p))%R. intuition. auto. apply(Rplus_ge_reg_l a). replace(a+(f x-a)
)%R with(f x). 2:ring. replace(a+0)%R with a. 2:ring. auto. Qed.

(*----------------------------------------------------------------------------- That 'f(x)>=a' set which is central to the proof (and statement) of Markov's inequality is indeed measurable. -----------------------------------------------------------------------------*)
Lemma msurable_P1:
(forall(U:Type)(F:Ensemble(Ensemble U))(F':sigalg_0 _ F)(F'':sigalg_1 _ F)(F'''
:sigalg_2 _ F)(f:U->R)(f':forall x:U,f x>=0)(f'':msurable _ _ F' F'' F''' f),
forall a:R,0<a->F(fun x:U=>f x>=a))%R.