Module mathcomp.experimental_reals.discrete
From Corelib Require Setoid.
From HB Require Import structures.
From mathcomp Require Import boot order algebra.
From mathcomp.classical Require Import boolp.
From mathcomp Require Import xfinmap reals.
Unset SsrOldRewriteGoalsOrder.
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GRing.Theory Num.Theory.
Local Open Scope ring_scope.
Local Open Scope real_scope.
Section ProofIrrelevantChoice.
Context { : choiceType}.
Lemma
existsTP
Source code
( : T -> Prop) : { : T | P x } + (forall , ~ P x).Source code
Proof.
End ProofIrrelevantChoice.
Section PredSubtype.
Section Def.
Variable : Type.
Variable : pred T.
Record
pred_sub
Source code
: Type :=Source code
PSubSub {
rsval
Source code
:> T; Source code
rsvalP
Source code
: rsval \in E }.Source code
.
instance
Source code
Source code
Definition
Source code
Source code
[isSub
Source code
for rsval].Source code
End Def.
.
instance
Source code
Source code
Definition
Source code
(Source code
eqType
Source code
) (E : pred T) :=Source code
[Equality of pred_sub E by <:].
.
instance
Source code
Source code
Definition
Source code
(Source code
choiceType
Source code
) (E : pred T) :=Source code
[Choice of pred_sub E by <:].
.
instance
Source code
Source code
Definition
Source code
(Source code
countType
Source code
) (E : pred T) :=Source code
[Countable of pred_sub E by <:].
End PredSubtype.
Notation
"[ 'psub' E ]"
Source code
:= (@pred_sub _ E)Source code
(format "[ 'psub' E ]").
Section PIncl.
Variables ( : Type) ( : pred T) ( : {subset E <= F}).
Definition
pincl
Source code
( : [psub E]) : [psub F] :=Source code
PSubSub (le (valP x)).
End PIncl.
Section Countable.
Variable ( : Type) ( : pred T).
Variant
countable
Source code
: Type :=Source code
Countable
Source code
Source code
(
rpickle
Source code
: [psub E] -> nat)Source code
(
runpickle
Source code
: nat -> option [psub E])Source code
of pcancel rpickle runpickle.
Definition
rpickle
Source code
( : countable) :=Source code
let: Countable p _ _ := c in p.
Definition
runpickle
Source code
( : countable) :=Source code
let: Countable _ p _ := c in p.
Lemma
rpickleK
Source code
: pcancel (rpickle c) (runpickle c).Source code
Proof.
by case: c. Qed.
Section CountableTheory.
Lemma
countable_countable
Source code
( : countType) ( : pred T) : countable E.Source code
Section CanCountable.
Variables ( : Type) ( : countType) ( : pred T).
Variables ( : [psub E] -> U) ( : U -> [psub E]).
Lemma
can_countable
Source code
: cancel f g -> countable E.Source code
Proof.
Section CountType.
Variables ( : eqType) ( : pred T) ( : countable E).
Definition
countable_countMixin
Source code
:= Countable.copy [psub E]Source code
(pcan_type (rpickleK c)).
Definition
countable_choiceMixin
Source code
:= Choice.copy [psub E]Source code
(pcan_type (rpickleK c)).
End CountType.
End CountableTheory.
Section Finite.
Variables ( : eqType).
CoInductive
finite
Source code
( : pred T) : Type :=Source code
|
Finite
Source code
of uniq s & {subset E <= s}.Source code
End Finite.
Section FiniteTheory.
Context { : choiceType}.
Lemma
finiteP
Source code
( : pred T) : (exists : seq T, {subset E <= s}) -> finite E.Source code
Proof.
case/cid=> s sEs; exists (undup s); first by rewrite undup_uniq.
by move=> x; rewrite mem_undup; exact: sEs.
Qed.
by move=> x; rewrite mem_undup; exact: sEs.
Qed.
Lemma
finiteNP
Source code
( : pred T): (forall : seq T, ~ {subset E <= s}) ->Source code
forall , exists : seq T, [/\ size s = n, uniq s & {subset s <= E}].
Proof.
move=> finN; elim=> [|n [s] [<- uq_s sE]]; first by exists [::].
have [x sxN xE]: exists2 , x \notin s & x \in E.
apply: contra_notP (finN (filter (mem E) s)) => /forall2NP finE x Ex.
move/or_asboolP: (finE x).
by rewrite !asbool_neg !asboolb negbK Ex mem_filter orbF [(mem E) x]Ex.
exists (x :: s) => /=; rewrite sxN; split=> // y.
by rewrite in_cons => /orP[/eqP->//|/sE].
Qed.
have [x sxN xE]: exists2 , x \notin s & x \in E.
apply: contra_notP (finN (filter (mem E) s)) => /forall2NP finE x Ex.
move/or_asboolP: (finE x).
by rewrite !asbool_neg !asboolb negbK Ex mem_filter orbF [(mem E) x]Ex.
exists (x :: s) => /=; rewrite sxN; split=> // y.
by rewrite in_cons => /orP[/eqP->//|/sE].
Qed.
End FiniteTheory.
Section FiniteCountable.
Variables ( : eqType) ( : pred T).
Lemma
finite_countable
Source code
: finite E -> countable E.Source code
Proof.
case=> s uqs Es; pose t := pmap (fun => (insub x : option [psub E])) s.
pose f := index x t; pose g := nth None [seq Some x | <- t] i.
apply (@Countable _ E f g) => x; rewrite {}/f {}/g /=.
have x_in_t: x \in t; first case: x => x h.
by rewrite {}/t mem_pmap_sub /= Es.
by rewrite (nth_map x) ?index_mem ?nth_index.
Qed.
pose f := index x t; pose g := nth None [seq Some x | <- t] i.
apply (@Countable _ E f g) => x; rewrite {}/f {}/g /=.
have x_in_t: x \in t; first case: x => x h.
by rewrite {}/t mem_pmap_sub /= Es.
by rewrite (nth_map x) ?index_mem ?nth_index.
Qed.
Section CountSub.
Variables ( : eqType) ( : pred T).
Lemma
countable_sub
Source code
: {subset E <= F} -> countable F -> countable E.Source code
Proof.
Section CountableUnion.
Variables ( : eqType) ( : nat -> pred T).
Hypothesis : forall , countable (E i).
Lemma
cunion_countable
Source code
: countable [pred | `[< exists , x \in E i >]].Source code
Proof.
pose Ci : countType := HB.pack [psub (E i)] (countable_countMixin (cE i)).
pose S := { : nat & Ci i }; set F := [pred | _].
have H: forall ( : [psub F]), exists : nat, val x \in E i.
by case=> x /= /asboolP[i] Eix; exists i.
have G: forall ( : S), val (tagged x) \in F.
by case=> i [x /= Eix]; apply/asboolP; exists i.
pose f ( : [psub F]) : S := Tagged (fun => [psub E i])
(PSubSub (xchooseP (H x))).
pose g ( : S) := PSubSub (G x).
by have /can_countable: cancel f g by case=> x hx; apply/val_inj.
Qed.
pose S := { : nat & Ci i }; set F := [pred | _].
have H: forall ( : [psub F]), exists : nat, val x \in E i.
by case=> x /= /asboolP[i] Eix; exists i.
have G: forall ( : S), val (tagged x) \in F.
by case=> i [x /= Eix]; apply/asboolP; exists i.
pose f ( : [psub F]) : S := Tagged (fun => [psub E i])
(PSubSub (xchooseP (H x))).
pose g ( : S) := PSubSub (G x).
by have /can_countable: cancel f g by case=> x hx; apply/val_inj.
Qed.