Skip to content

Commit bb1a51e

Browse files
committed
Started implementation on enumerability.
1 parent bdafd5a commit bb1a51e

File tree

5 files changed

+131
-106
lines changed

5 files changed

+131
-106
lines changed

code/Decidability/DecidablePredicates.v

Lines changed: 4 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Require Import init.imports.
2+
Require Import Inductive.Predicates.
23

34
Section Definitions.
45

@@ -108,7 +109,7 @@ End Properties.
108109

109110
Section ClosureProperties.
110111

111-
Lemma decidabledisj {X : UU} (p q : X → hProp) : (deptypeddecider p) → (deptypeddecider q) → (deptypeddecider (λ (x : X), (p x) ∨ (q x))).
112+
Lemma decidabledisj {X : UU} (p q : X → hProp) : (deptypeddecider p) → (deptypeddecider q) → (deptypeddecider (preddisj p q)).
112113
Proof.
113114
intros decp decq x.
114115
induction (decp x).
@@ -125,7 +126,7 @@ Section ClosureProperties.
125126
* exact (sumofmaps b b0).
126127
Qed.
127128

128-
Lemma decidableconj {X : UU} (p q : X → hProp) : (deptypeddecider p) → (deptypeddecider q) → (deptypeddecider (λ (x : X), (p x) ∧ (q x))).
129+
Lemma decidableconj {X : UU} (p q : X → hProp) : (deptypeddecider p) → (deptypeddecider q) → (deptypeddecider (predconj p q)).
129130
Proof.
130131
intros decp decq x.
131132
induction (decp x), (decq x).
@@ -135,7 +136,7 @@ Section ClosureProperties.
135136
- right. intros [pp qq]. exact (b pp).
136137
Qed.
137138

138-
Lemma decidableneg {X : UU} (p q : X → hProp) : (deptypeddecider p) → (deptypeddecider (λ (x : X), hneg (p x))).
139+
Lemma decidableneg {X : UU} (p : X → hProp) : (deptypeddecider p) → (deptypeddecider (predneg p)).
139140
Proof.
140141
intros decp x.
141142
induction (decp x).
@@ -144,105 +145,3 @@ Section ClosureProperties.
144145
Qed.
145146

146147
End ClosureProperties.
147-
148-
Section EqualityDeciders.
149-
150-
Definition iseqdecider (X : UU) (f : X → X → bool) : UU := ∏ (x1 x2 : X), x1 = x2 <-> f x1 x2 = true.
151-
152-
Definition eqdecider (X : UU) := ∑ (f : X → X → bool), (iseqdecider X f).
153-
154-
Definition make_eqdecider {X : UU} {f : X → X → bool} : (iseqdecider X f) → eqdecider (X) := (λ is : (iseqdecider X f), (f,, is)).
155-
156-
Lemma eqdecidertodeptypedeqdecider (X : UU) : (eqdecider X) → (isdeceq X).
157-
Proof.
158-
intros [f is] x y.
159-
destruct (is x y) as [impl1 impl2].
160-
induction (f x y).
161-
- left; apply impl2; apply idpath.
162-
- right. intros eq. apply nopathsfalsetotrue. exact (impl1 eq).
163-
Qed.
164-
165-
Lemma deptypedeqdecidertoeqdecider (X : UU) : (isdeceq X) → (eqdecider X).
166-
Proof.
167-
intros is.
168-
use tpair.
169-
- intros x y.
170-
induction (is x y).
171-
+ exact true.
172-
+ exact false.
173-
- intros x y.
174-
induction (is x y); simpl; split.
175-
+ exact (λ a : (x = y), (idpath true)).
176-
+ exact (λ b : (true = true), a).
177-
+ intros; apply fromempty; exact (b X0).
178-
+ intros; apply fromempty; exact (nopathsfalsetotrue X0).
179-
Qed.
180-
181-
Lemma eqdecidertoisapropeq (X : UU) (f : eqdecider X) : ∏ (x y : X) ,(isaprop (x = y)).
182-
Proof.
183-
intros x.
184-
apply isaproppathsfromisolated.
185-
intros y.
186-
set (dec := eqdecidertodeptypedeqdecider X f).
187-
apply (dec x).
188-
Qed.
189-
190-
Lemma isapropiseqdecider (X : UU) (f : X → X → bool) : (isaprop (iseqdecider X f)).
191-
Proof.
192-
apply isofhlevelsn.
193-
intros is.
194-
repeat (apply impred_isaprop + intros).
195-
apply isapropdirprod; apply isapropimpl.
196-
- induction (f t).
197-
+ apply isapropifcontr.
198-
use iscontrloopsifisaset.
199-
exact isasetbool.
200-
+ apply isapropifnegtrue.
201-
exact nopathsfalsetotrue.
202-
- apply eqdecidertoisapropeq.
203-
use make_eqdecider.
204-
+ exact f.
205-
+ exact is.
206-
Qed.
207-
208-
Lemma pathseqdeciders (X : UU) (f g : X → X → bool) (isf : iseqdecider X f) (isg : iseqdecider X g) : f = g.
209-
Proof.
210-
apply funextsec; intros x.
211-
apply funextsec; intros y.
212-
destruct (isf x y) as [implf1 implf2].
213-
destruct (isg x y) as [implg1 implg2].
214-
induction (g x y).
215-
- apply implf1; apply implg2.
216-
apply idpath.
217-
- induction (f x y).
218-
+ apply fromempty, nopathsfalsetotrue, implg1, implf2.
219-
exact (idpath true).
220-
+ exact (idpath false).
221-
Qed.
222-
223-
Lemma isapropeqdecider (X : UU) : (isaprop (eqdecider X)).
224-
Proof.
225-
apply invproofirrelevance.
226-
intros [f isf] [g isg].
227-
induction (pathseqdeciders X f g isf isg).
228-
assert (eq : isf = isg).
229-
- apply proofirrelevance.
230-
apply isapropiseqdecider.
231-
- induction eq.
232-
apply idpath.
233-
Qed.
234-
235-
Lemma weqisdeceqiseqdecider (X : UU) : (isdeceq X) ≃ (eqdecider X).
236-
Proof.
237-
use make_weq.
238-
- exact (deptypedeqdecidertoeqdecider X).
239-
- apply isweqimplimpl.
240-
+ exact (eqdecidertodeptypedeqdecider X).
241-
+ exact (isapropisdeceq X).
242-
+ exact (isapropeqdecider X).
243-
Qed.
244-
End EqualityDeciders.
245-
246-
Section ChoiceFunction.
247-
248-
End ChoiceFunction.

code/Enumerability/Definitions.v

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
Require Import init.imports.
2+
Require Import Inductive.Option.
3+
4+
Definition rangeequiv {X : UU} {Y : UU} (f g : X → Y) := ∏ (y : Y), ∥hfiber f y∥ <-> ∥hfiber g y∥.
5+
6+
Notation "f ≡ᵣ g" := (rangeequiv f g) (at level 50).
7+
8+
Section EmbedNaturals.
9+
10+
(* Bijective maps from pairs of natural numbers to natural numbers.*)
11+
12+
Definition embed (p : nat×nat) : nat :=
13+
(pr2 p) + (nat_rec _ 0 (λ i m, (S i) + m) ((pr2 p) + (pr1 p))).
14+
15+
Definition unembed (n : nat) : nat × nat :=
16+
nat_rec _ (0,, 0) (fun _ a => match (pr1 a) with S x => (x,, S (pr2 a)) | _ => (S (pr2 a),, 0) end) n.
17+
18+
(*Proofs that embed and unembed are inverses of each other. *)
19+
20+
Lemma embedinv (n : nat) : (embed (unembed n)) = n.
21+
Proof.
22+
(*TODO*)
23+
Admitted.
24+
25+
Lemma unembedinv (n : nat × nat) : (unembed (embed n)) = n.
26+
Proof.
27+
(* TODO *)
28+
Admitted.
29+
End EmbedNaturals.
30+
31+
Section EnumerablePredicates.
32+
33+
Definition ispredenum {X : UU} (p : X → hProp) (f : nat → option) := ∏ (x : X), (p x) <-> ∥(hfiber f (some x))∥.
34+
35+
Definition predenum {X : UU} (p : X → hProp) := ∑ (f : nat → option), (ispredenum p f).
36+
37+
Definition isenumerablepred {X : UU} (p : X → hProp) := ∥predenum p∥.
38+
39+
Lemma isapropispredenum {X : UU} (p : X → hProp) (f : nat → option) : (isaprop (ispredenum p f)).
40+
Proof.
41+
apply impred_isaprop.
42+
intros t.
43+
apply isapropdirprod; apply isapropimpl, propproperty.
44+
Qed.
45+
46+
Lemma rangeequivtohomot {X : UU} (p q : X → hProp) (e1 : (predenum p)) (e2 : (predenum q)) : ((pr1 e1) ≡ᵣ (pr1 e2)) → p ~ q.
47+
Proof.
48+
intros req x.
49+
destruct e1 as [f ispf].
50+
destruct e2 as [g ispg].
51+
destruct (req (some x)) as [impl1 impl2].
52+
destruct (ispf x) as [if1 if2].
53+
destruct (ispg x) as [ig1 ig2].
54+
use hPropUnivalence.
55+
- intros px.
56+
apply ig2, impl1, if1.
57+
exact px.
58+
- intros qx.
59+
apply if2, impl2, ig1.
60+
exact qx.
61+
Qed.
62+
63+
(* Closure properties *)
64+
Lemma enumconj {X : UU} (p q : X → hProp) : (predenum p) → (predenum q) → (predenum (λ x : X, p x ∧ q x)).
65+
Admitted.
66+
67+
Lemma enumdisj {X : UU} (p q : X → hProp) : (predenum p) → (predenum q) → (predenum (λ x : X, p x ∨ q x)).
68+
Admitted.
69+
70+
Lemma enumdirprod {X Y : UU} (p : X → hProp) (q : Y → hProp) : (predenum p) → (predenum q) → (predenum (λ a, (p (pr1 a)) ∧ (q (pr2 a)))).
71+
Proof.
72+
Admitted.
73+
74+
Lemma enumcoprod {X Y : UU} (p : X → hProp) (q : Y → hProp) : (predenum p) → (predenum q) → (predenum (λ a, (
75+
76+
77+
End EnumerablePredicates.
78+
79+
80+
81+

code/Inductive/Predicates.v

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Require Import init.imports.
2+
3+
(*
4+
5+
This file contains definitions of the used operations on predicates and a number of useful
6+
properties.
7+
8+
*)
9+
10+
11+
Section Operations.
12+
13+
Definition predconj {X : UU} (p q : X → hProp) : X → hProp := (λ x : X, (p x) ∧ (q x)).
14+
15+
Infix "p ∧ q" := (predconj p q) (at level 25).
16+
17+
Definition preddisj {X : UU} (p q : X → hProp) : X → hProp := (λ x : X, (p x) ∨ (q x)).
18+
19+
Infix "p ∨ q" := (preddisj p q) (at level 25).
20+
21+
Definition predneg {X : UU} (p : X → hProp) : X → hProp := (λ x : X, hneg (p x)).
22+
23+
Notation "¬ p" := (predneg p) (at level 35).
24+
25+
Definition preddirprod {X Y : UU} (p : X → hProp) (q : Y → hProp) : (X × Y) → hProp := (λ x : X × Y, (p (pr1 x)) ∧ (q (pr2 x))).
26+
27+
Infix "p × q" := (preddirprod p q) (at level 25).
28+
29+
Definition predcoprod {X Y : UU} (p : X → hProp) (q : Y → hProp) : (X ⨿ Y) → hProp.
30+
Proof.
31+
intros x.
32+
induction x.
33+
- exact (p a).
34+
- exact (q b).
35+
Defined.
36+
37+
End Operations.

code/_CoqProject

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ COQC = coqc
22
COQDEP = coqdep
33
-R . "sem"
44

5-
-o -arg "-w -notation-overridden -type-in-type"
5+
-arg "-w -notation-overridden -type-in-type"
66

77
init/imports.v
88
init/all.v
99

10+
util/range_equiv.v
11+
12+
Inductive/Predicates.v
1013
Inductive/Option.v
1114

1215
Decidability/DecidablePredicates.v

code/util/range_equiv.v

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Require Import init.imports.
2+
3+
Definition rangeequiv {X : UU} {Y : UU} (f g : X → Y) := ∏ (y : Y), ∥hfiber f y∥ <-> ∥hfiber g y∥.
4+
5+
Notation "f ≡ᵣ g" := (rangeequiv f g) (at level 50).

0 commit comments

Comments
 (0)