-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinear.v
231 lines (208 loc) · 3.83 KB
/
linear.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#[global]
Set Primitive Projections.
#[global]
Unset Printing Primitive Projection Parameters.
#[global]
Set Universe Polymorphism.
#[global]
Set Default Goal Selector "!".
Require Import Coq.Unicode.Utf8.
Require Import Coq.Lists.List.
Require Import Coq.Strings.String.
Require Import Coq.Bool.Bool.
Require Import Coq.Arith.PeanoNat.
Require Import Coq.Setoids.Setoid.
Require Import Coq.Classes.SetoidClass.
Require Psatz.
Require Import Recdef.
Import IfNotations.
Import ListNotations.
Close Scope nat.
Definition valof {C} (P: C → bool) y := {
val: C | Is_true (implb (P val) y) }.
#[program]
Definition app {C} (P: C → bool) (x: valof P false): valof P true := x.
Next Obligation.
Proof.
destruct (P (proj1_sig x)).
- cbn.
apply I.
- cbn.
apply I.
Defined.
Record fiber {C} (P: C → bool) y := {
tag: valof P true ;
field: { x: valof P false | proj1_sig (app P x) = proj1_sig tag } → y ;
}.
Arguments tag {C P y}.
Arguments field {C P y}.
Record Poly := {
pos: Type ;
dir: pos → bool ;
}.
Definition X := {| dir (_: unit) := false |}.
Definition K A := {| dir (_: A) := true |}.
Definition sum (P Q: Poly) :=
{|
dir (x: pos P + pos Q) :=
match x with
| inl x' => dir P x'
| inr x' => dir Q x'
end ;
|}.
Definition K_in {A B} (x: A): fiber (dir (K A)) B.
Proof.
cbn.
eexists (exist _ x _).
Unshelve.
2: {
cbn.
apply I.
}
intros [[?] ?].
cbn in *.
contradiction.
Defined.
Definition K_out {A B}: fiber (dir (K A)) B → A.
Proof.
intros [a ?].
cbn in *.
apply a.
Defined.
Definition X_in {A} (x: A): fiber (dir X) A.
Proof.
cbn.
eexists (exist _ tt _).
Unshelve.
2: {
cbn.
apply I.
}
intro.
apply x.
Defined.
Definition X_out {A}: fiber (dir X) A → A.
Proof.
intros [? p].
cbn in *.
apply p.
eexists (exist _ tt _).
Unshelve.
2: {
cbn.
apply I.
}
cbn.
destruct tag0.
cbn.
destruct x.
reflexivity.
Defined.
Definition inl_intro {A B C}: fiber (dir A) C → fiber (dir (sum A B)) C.
Proof.
intros [[a j] p].
cbn in *.
exists (exist _ (inl a) j).
cbn.
intros [[? ?] ?].
cbn in *.
subst.
apply p.
eexists.
Unshelve.
2: {
exists a.
apply i.
}
cbn.
reflexivity.
Defined.
Definition inr_intro {A B C}: fiber (dir B) C → fiber (dir (sum A B)) C.
Proof.
intros [[b j] p].
cbn in *.
exists (exist _ (inr b) j).
cbn.
intros [[? ?] ?].
cbn in *.
subst.
apply p.
eexists.
Unshelve.
2: {
exists b.
apply i.
}
cbn.
reflexivity.
Defined.
Definition sum_out {A B C}: fiber (dir (sum A B)) C → fiber (dir A) C + fiber (dir B) C.
Proof.
intros [[[a|b] i] p].
all: cbn in *.
- left.
exists (exist _ a i).
intros [[? j] ?].
cbn in *.
subst.
apply p.
exists (exist _ (inl a) j).
cbn.
reflexivity.
- right.
exists (exist _ b i).
intros [[? j] ?].
cbn in *.
subst.
apply p.
exists (exist _ (inr b) j).
cbn.
reflexivity.
Defined.
(* How bizarre it's a kind of pullback *)
Definition prod (P Q: Poly) :=
{|
dir (x: pos P * pos Q) := eqb (dir P (fst x)) (dir Q (snd x)) ;
|}.
Definition prod_intro {A B C}: fiber (dir A) C → fiber (dir B) C → fiber (dir (prod A B)) C.
Proof.
intros [[a j] p] [[b k] q].
eexists (exist _ (a, b) _).
Unshelve.
2: {
cbn in *.
destruct (dir A a) eqn:r, (dir B b) eqn:s.
all: cbn in *.
all: apply I.
}
intros [[[? ?] ?] ?].
cbn in *.
inversion e.
subst.
destruct (dir A a) eqn:r, (dir B b) eqn:s.
all: cbn in *.
- contradiction.
- apply q.
eexists (exist _ b _).
Unshelve.
2: {
cbn.
rewrite s.
cbn.
apply I.
}
cbn.
reflexivity.
- apply p.
eexists (exist _ a _).
Unshelve.
2: {
cbn.
rewrite r.
cbn.
apply I.
}
cbn.
reflexivity.
- contradiction.
Defined.