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
232
233
234
235
|
(* Title: HoTT/Proj.thy
Author: Josh Chen
Date: Jun 2018
Projection functions \<open>fst\<close> and \<open>snd\<close> for the dependent sum type.
*)
theory Proj
imports
HoTT_Methods
Prod
Sum
begin
consts
fst :: "[Term, 'a] \<Rightarrow> Term" ("(1fst[/_,/ _])")
snd :: "[Term, 'a] \<Rightarrow> Term" ("(1snd[/_,/ _])")
section \<open>Overloaded syntax for dependent and nondependent pairs\<close>
overloading
fst_dep \<equiv> fst
fst_nondep \<equiv> fst
begin
definition fst_dep :: "[Term, Typefam] \<Rightarrow> Term" where
"fst_dep A B \<equiv> \<^bold>\<lambda>p: (\<Sum>x:A. B x). indSum[A,B] (\<lambda>_. A) (\<lambda>x y. x) p"
definition fst_nondep :: "[Term, Term] \<Rightarrow> Term" where
"fst_nondep A B \<equiv> \<^bold>\<lambda>p: A \<times> B. indSum[A, \<lambda>_. B] (\<lambda>_. A) (\<lambda>x y. x) p"
end
overloading
snd_dep \<equiv> snd
snd_nondep \<equiv> snd
begin
definition snd_dep :: "[Term, Typefam] \<Rightarrow> Term" where
"snd_dep A B \<equiv> \<^bold>\<lambda>p: (\<Sum>x:A. B x). indSum[A,B] (\<lambda>q. B (fst[A,B]`q)) (\<lambda>x y. y) p"
definition snd_nondep :: "[Term, Term] \<Rightarrow> Term" where
"snd_nondep A B \<equiv> \<^bold>\<lambda>p: A \<times> B. indSum[A, \<lambda>_. B] (\<lambda>_. B) (\<lambda>x y. y) p"
end
section \<open>Properties\<close>
text "Typing judgments and computation rules for the dependent and non-dependent projection functions."
lemma fst_dep_type:
assumes "p : \<Sum>x:A. B x"
shows "fst[A,B]`p : A"
proof
show "fst[A,B]: (\<Sum>x:A. B x) \<rightarrow> A"
proof (unfold fst_dep_def, standard)
show "\<And>p. p : \<Sum>x:A. B x \<Longrightarrow> indSum[A,B] (\<lambda>_. A) (\<lambda>x y. x) p : A"
proof
show "A : U" by (wellformed jdgmt: assms)
qed
qed (wellformed jdgmt: assms)
qed (rule assms)
lemma fst_dep_comp:
assumes "B: A \<rightarrow> U" and "a : A" and "b : B a"
shows "fst[A,B]`(a,b) \<equiv> a"
proof -
have "fst[A,B]`(a,b) \<equiv> indSum[A,B] (\<lambda>_. A) (\<lambda>x y. x) (a,b)"
proof (unfold fst_dep_def, standard)
show "(a,b) : \<Sum>x:A. B x" using assms ..
show "\<And>p. p : \<Sum>x:A. B x \<Longrightarrow> indSum[A,B] (\<lambda>_. A) (\<lambda>x y. x) p : A"
proof
show "A : U" by (wellformed jdgmt: assms(2))
qed
qed
also have "indSum[A,B] (\<lambda>_. A) (\<lambda>x y. x) (a,b) \<equiv> a"
proof
show "A : U" by (wellformed jdgmt: assms(2))
qed (assumption, (rule assms)+)
finally show "fst[A,B]`(a,b) \<equiv> a" .
qed
text "In proving results about the second dependent projection function we often use the following two lemmas."
lemma lemma1:
assumes "p : \<Sum>x:A. B x"
shows "B (fst[A,B]`p) : U"
proof -
have *: "B: A \<rightarrow> U" by (wellformed jdgmt: assms)
have "fst[A,B]`p : A" using assms by (rule fst_dep_type)
then show "B (fst[A,B]`p) : U" by (rule *)
qed
lemma lemma2:
assumes "B: A \<rightarrow> U" and "x : A" and "y : B x"
shows "y : B (fst[A,B]`(x,y))"
proof -
have "fst[A,B]`(x,y) \<equiv> x" using assms by (rule fst_dep_comp)
then show "y : B (fst[A,B]`(x,y))" using assms by simp
qed
lemma snd_dep_type:
assumes "p : \<Sum>x:A. B x"
shows "snd[A,B]`p : B (fst[A,B]`p)"
proof
show "snd[A, B] : \<Prod>p:(\<Sum>x:A. B x). B (fst[A,B]`p)"
proof (unfold snd_dep_def, standard)
show "\<And>p. p : \<Sum>x:A. B x \<Longrightarrow> indSum[A,B] (\<lambda>q. B (fst[A,B]`q)) (\<lambda>x y. y) p : B (fst[A,B]`p)"
proof (standard, elim lemma1)
fix p assume *: "p : \<Sum>x:A. B x"
have **: "B: A \<rightarrow> U" by (wellformed jdgmt: *)
fix x y assume "x : A" and "y : B x"
with ** show "y : B (fst[A,B]`(x,y))" by (rule lemma2)
qed
qed (wellformed jdgmt: assms)
qed (rule assms)
lemma snd_dep_comp:
assumes "B: A \<rightarrow> U" and "a : A" and "b : B a"
shows "snd[A,B]`(a,b) \<equiv> b"
proof -
have "snd[A,B]`(a,b) \<equiv> indSum[A, B] (\<lambda>q. B (fst[A,B]`q)) (\<lambda>x y. y) (a,b)"
proof (unfold snd_dep_def, standard)
show "(a,b) : \<Sum>x:A. B x" using assms ..
fix p assume *: "p : \<Sum>x:A. B x"
show "indSum[A,B] (\<lambda>q. B (fst[A,B]`q)) (\<lambda>x y. y) p : B (fst[A,B]`p)"
proof (standard, elim lemma1)
fix x y assume "x : A" and "y : B x"
with assms(1) show "y : B (fst[A,B]`(x,y))" by (rule lemma2)
qed (rule *)
qed
also have "indSum[A, B] (\<lambda>q. B (fst[A,B]`q)) (\<lambda>x y. y) (a,b) \<equiv> b"
proof (standard, elim lemma1)
fix x y assume "x : A" and "y : B x"
with assms(1) show "y : B (fst[A,B]`(x,y))" by (rule lemma2)
qed (rule assms)+
finally show "snd[A,B]`(a,b) \<equiv> b" .
qed
text "For non-dependent projection functions:"
lemma fst_nondep_type:
assumes "p : A \<times> B"
shows "fst[A,B]`p : A"
proof
show "fst[A,B] : A \<times> B \<rightarrow> A"
proof (unfold fst_nondep_def, standard)
fix q assume *: "q : A \<times> B"
show "indSum[A, \<lambda>_. B] (\<lambda>_. A) (\<lambda>x y. x) q : A"
proof
show "A : U" by (wellformed jdgmt: assms)
qed (assumption, rule *)
qed (wellformed jdgmt: assms)
qed (rule assms)
lemma fst_nondep_comp:
assumes "a : A" and "b : B"
shows "fst[A,B]`(a,b) \<equiv> a"
proof -
have "fst[A,B]`(a,b) \<equiv> indSum[A, \<lambda>_. B] (\<lambda>_. A) (\<lambda>x y. x) (a,b)"
proof (unfold fst_nondep_def, standard)
show "(a,b) : A \<times> B" using assms ..
show "\<And>p. p : A \<times> B \<Longrightarrow> indSum[A, \<lambda>_. B] (\<lambda>_. A) (\<lambda>x y. x) p : A"
proof
show "A : U" by (wellformed jdgmt: assms(1))
qed
qed
also have "indSum[A, \<lambda>_. B] (\<lambda>_. A) (\<lambda>x y. x) (a,b) \<equiv> a"
proof
show "A : U" by (wellformed jdgmt: assms(1))
qed (assumption, (rule assms)+)
finally show "fst[A,B]`(a,b) \<equiv> a" .
qed
lemma snd_nondep_type:
assumes "p : A \<times> B"
shows "snd[A,B]`p : B"
proof
show "snd[A,B] : A \<times> B \<rightarrow> B"
proof (unfold snd_nondep_def, standard)
fix q assume *: "q : A \<times> B"
show "indSum[A, \<lambda>_. B] (\<lambda>_. B) (\<lambda>x y. y) q : B"
proof
have **: "\<lambda>_. B: A \<rightarrow> U" by (wellformed jdgmt: assms)
have "fst[A,B]`p : A" using assms by (rule fst_nondep_type)
then show "B : U" by (rule **)
qed (assumption, rule *)
qed (wellformed jdgmt: assms)
qed (rule assms)
lemma snd_nondep_comp:
assumes "a : A" and "b : B"
shows "snd[A,B]`(a,b) \<equiv> b"
proof -
have "snd[A,B]`(a,b) \<equiv> indSum[A, \<lambda>_. B] (\<lambda>_. B) (\<lambda>x y. y) (a,b)"
proof (unfold snd_nondep_def, standard)
show "(a,b) : A \<times> B" using assms ..
show "\<And>p. p : A \<times> B \<Longrightarrow> indSum[A, \<lambda>_. B] (\<lambda>_. B) (\<lambda>x y. y) p : B"
proof
show "B : U" by (wellformed jdgmt: assms(2))
qed
qed
also have "indSum[A, \<lambda>_. B] (\<lambda>_. B) (\<lambda>x y. y) (a,b) \<equiv> b"
proof
show "B : U" by (wellformed jdgmt: assms(2))
qed (assumption, (rule assms)+)
finally show "snd[A,B]`(a,b) \<equiv> b" .
qed
end
|