(****************************************************************************** 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.

(*----------------------------------------------------------------------------- The 'other half' of cntabl_P0; just proving two common definitions of countability equivalent.  g assigns a 'serial number' to each set in the countable collection, and the two hypotheses say g is proof-irrelevant and injective. -----------------------------------------------------------------------------*)
Lemma cntabl_P1(U:Type)(C:Ensemble(Ensemble U))
:forall g:forall c,C c->nat,
(forall c c' c'',g c c'=g c c'')->
(forall c cc c' cc',g c c'=g cc cc'->c=cc)->cntabl _ C.