author  obua 
Fri, 16 Sep 2005 21:02:15 +0200  
changeset 17440  df77edc4f5d0 
parent 14854  61bdf2ae4dc5 
child 17441  5b5feca0344a 
permissions  rwrr 
0  1 
(* Title: CTT/ctt.thy 
2 
ID: $Id$ 

3 
Author: Lawrence C Paulson, Cambridge University Computer Laboratory 

4 
Copyright 1993 University of Cambridge 

5 

6 
Constructive Type Theory 

7 
*) 

8 

9 
CTT = Pure + 

10 

283  11 
types 
12 
i 

13 
t 

14 
o 

0  15 

16 
consts 

17 
(*Types*) 

18 
F,T :: "t" (*F is empty, T contains one element*) 

19 
contr :: "i=>i" 

20 
tt :: "i" 

21 
(*Natural numbers*) 

22 
N :: "t" 

23 
succ :: "i=>i" 

24 
rec :: "[i, i, [i,i]=>i] => i" 

25 
(*Unions*) 

26 
inl,inr :: "i=>i" 

27 
when :: "[i, i=>i, i=>i]=>i" 

28 
(*General Sum and Binary Product*) 

29 
Sum :: "[t, i=>t]=>t" 

30 
fst,snd :: "i=>i" 

31 
split :: "[i, [i,i]=>i] =>i" 

32 
(*General Product and Function Space*) 

33 
Prod :: "[t, i=>t]=>t" 

14765  34 
(*Types*) 
35 
"+" :: "[t,t]=>t" (infixr 40) 

0  36 
(*Equality type*) 
37 
Eq :: "[t,i,i]=>t" 

38 
eq :: "i" 

39 
(*Judgements*) 

40 
Type :: "t => prop" ("(_ type)" [10] 5) 

10467
e6e7205e9e91
xsymbol support for Pi, Sigma, >, : (membership)
paulson
parents:
3837
diff
changeset

41 
Eqtype :: "[t,t]=>prop" ("(_ =/ _)" [10,10] 5) 
0  42 
Elem :: "[i, t]=>prop" ("(_ /: _)" [10,10] 5) 
10467
e6e7205e9e91
xsymbol support for Pi, Sigma, >, : (membership)
paulson
parents:
3837
diff
changeset

43 
Eqelem :: "[i,i,t]=>prop" ("(_ =/ _ :/ _)" [10,10,10] 5) 
0  44 
Reduce :: "[i,i]=>prop" ("Reduce[_,_]") 
45 
(*Types*) 

14765  46 

0  47 
(*Functions*) 
48 
lambda :: "(i => i) => i" (binder "lam " 10) 

49 
"`" :: "[i,i]=>i" (infixl 60) 

50 
(*Natural numbers*) 

51 
"0" :: "i" ("0") 

52 
(*Pairing*) 

53 
pair :: "[i,i]=>i" ("(1<_,/_>)") 

54 

14765  55 
syntax 
56 
"@PROD" :: "[idt,t,t]=>t" ("(3PROD _:_./ _)" 10) 

57 
"@SUM" :: "[idt,t,t]=>t" ("(3SUM _:_./ _)" 10) 

58 
"@>" :: "[t,t]=>t" ("(_ >/ _)" [31,30] 30) 

59 
"@*" :: "[t,t]=>t" ("(_ */ _)" [51,50] 50) 

60 

0  61 
translations 
62 
"PROD x:A. B" => "Prod(A, %x. B)" 

23  63 
"A > B" => "Prod(A, _K(B))" 
0  64 
"SUM x:A. B" => "Sum(A, %x. B)" 
23  65 
"A * B" => "Sum(A, _K(B))" 
0  66 

10467
e6e7205e9e91
xsymbol support for Pi, Sigma, >, : (membership)
paulson
parents:
3837
diff
changeset

67 
syntax (xsymbols) 
e6e7205e9e91
xsymbol support for Pi, Sigma, >, : (membership)
paulson
parents:
3837
diff
changeset

68 
"@>" :: "[t,t]=>t" ("(_ \\<longrightarrow>/ _)" [31,30] 30) 
e6e7205e9e91
xsymbol support for Pi, Sigma, >, : (membership)
paulson
parents:
3837
diff
changeset

69 
"@*" :: "[t,t]=>t" ("(_ \\<times>/ _)" [51,50] 50) 
12110
f8b4b11cd79d
eliminated old "symbols" syntax, use "xsymbols" instead;
wenzelm
parents:
10467
diff
changeset

70 
Elem :: "[i, t]=>prop" ("(_ /\\<in> _)" [10,10] 5) 
f8b4b11cd79d
eliminated old "symbols" syntax, use "xsymbols" instead;
wenzelm
parents:
10467
diff
changeset

71 
Eqelem :: "[i,i,t]=>prop" ("(2_ =/ _ \\<in>/ _)" [10,10,10] 5) 
f8b4b11cd79d
eliminated old "symbols" syntax, use "xsymbols" instead;
wenzelm
parents:
10467
diff
changeset

72 
"@SUM" :: "[idt,t,t] => t" ("(3\\<Sigma> _\\<in>_./ _)" 10) 
f8b4b11cd79d
eliminated old "symbols" syntax, use "xsymbols" instead;
wenzelm
parents:
10467
diff
changeset

73 
"@PROD" :: "[idt,t,t] => t" ("(3\\<Pi> _\\<in>_./ _)" 10) 
f8b4b11cd79d
eliminated old "symbols" syntax, use "xsymbols" instead;
wenzelm
parents:
10467
diff
changeset

74 
"lam " :: "[idts, i] => i" ("(3\\<lambda>\\<lambda>_./ _)" 10) 
10467
e6e7205e9e91
xsymbol support for Pi, Sigma, >, : (membership)
paulson
parents:
3837
diff
changeset

75 

14565  76 
syntax (HTML output) 
77 
"@*" :: "[t,t]=>t" ("(_ \\<times>/ _)" [51,50] 50) 

78 
Elem :: "[i, t]=>prop" ("(_ /\\<in> _)" [10,10] 5) 

79 
Eqelem :: "[i,i,t]=>prop" ("(2_ =/ _ \\<in>/ _)" [10,10,10] 5) 

80 
"@SUM" :: "[idt,t,t] => t" ("(3\\<Sigma> _\\<in>_./ _)" 10) 

81 
"@PROD" :: "[idt,t,t] => t" ("(3\\<Pi> _\\<in>_./ _)" 10) 

82 
"lam " :: "[idts, i] => i" ("(3\\<lambda>\\<lambda>_./ _)" 10) 

83 

0  84 
rules 
85 

86 
(*Reduction: a weaker notion than equality; a hack for simplification. 

87 
Reduce[a,b] means either that a=b:A for some A or else that "a" and "b" 

88 
are textually identical.*) 

89 

90 
(*does not verify a:A! Sound because only trans_red uses a Reduce premise 

91 
No new theorems can be proved about the standard judgements.*) 

92 
refl_red "Reduce[a,a]" 

93 
red_if_equal "a = b : A ==> Reduce[a,b]" 

94 
trans_red "[ a = b : A; Reduce[b,c] ] ==> a = c : A" 

95 

96 
(*Reflexivity*) 

97 

98 
refl_type "A type ==> A = A" 

99 
refl_elem "a : A ==> a = a : A" 

100 

101 
(*Symmetry*) 

102 

103 
sym_type "A = B ==> B = A" 

104 
sym_elem "a = b : A ==> b = a : A" 

105 

106 
(*Transitivity*) 

107 

108 
trans_type "[ A = B; B = C ] ==> A = C" 

109 
trans_elem "[ a = b : A; b = c : A ] ==> a = c : A" 

110 

111 
equal_types "[ a : A; A = B ] ==> a : B" 

112 
equal_typesL "[ a = b : A; A = B ] ==> a = b : B" 

113 

114 
(*Substitution*) 

115 

116 
subst_type "[ a : A; !!z. z:A ==> B(z) type ] ==> B(a) type" 

117 
subst_typeL "[ a = c : A; !!z. z:A ==> B(z) = D(z) ] ==> B(a) = D(c)" 

118 

119 
subst_elem "[ a : A; !!z. z:A ==> b(z):B(z) ] ==> b(a):B(a)" 

120 
subst_elemL 

121 
"[ a=c : A; !!z. z:A ==> b(z)=d(z) : B(z) ] ==> b(a)=d(c) : B(a)" 

122 

123 

124 
(*The type N  natural numbers*) 

125 

126 
NF "N type" 

127 
NI0 "0 : N" 

128 
NI_succ "a : N ==> succ(a) : N" 

129 
NI_succL "a = b : N ==> succ(a) = succ(b) : N" 

130 

131 
NE 

1149  132 
"[ p: N; a: C(0); !!u v. [ u: N; v: C(u) ] ==> b(u,v): C(succ(u)) ] 
3837  133 
==> rec(p, a, %u v. b(u,v)) : C(p)" 
0  134 

135 
NEL 

1149  136 
"[ p = q : N; a = c : C(0); 
137 
!!u v. [ u: N; v: C(u) ] ==> b(u,v) = d(u,v): C(succ(u)) ] 

3837  138 
==> rec(p, a, %u v. b(u,v)) = rec(q,c,d) : C(p)" 
0  139 

140 
NC0 

1149  141 
"[ a: C(0); !!u v. [ u: N; v: C(u) ] ==> b(u,v): C(succ(u)) ] 
3837  142 
==> rec(0, a, %u v. b(u,v)) = a : C(0)" 
0  143 

144 
NC_succ 

1149  145 
"[ p: N; a: C(0); 
146 
!!u v. [ u: N; v: C(u) ] ==> b(u,v): C(succ(u)) ] ==> 

3837  147 
rec(succ(p), a, %u v. b(u,v)) = b(p, rec(p, a, %u v. b(u,v))) : C(succ(p))" 
0  148 

149 
(*The fourth Peano axiom. See page 91 of MartinLof's book*) 

150 
zero_ne_succ 

151 
"[ a: N; 0 = succ(a) : N ] ==> 0: F" 

152 

153 

154 
(*The Product of a family of types*) 

155 

3837  156 
ProdF "[ A type; !!x. x:A ==> B(x) type ] ==> PROD x:A. B(x) type" 
0  157 

158 
ProdFL 

1149  159 
"[ A = C; !!x. x:A ==> B(x) = D(x) ] ==> 
3837  160 
PROD x:A. B(x) = PROD x:C. D(x)" 
0  161 

162 
ProdI 

3837  163 
"[ A type; !!x. x:A ==> b(x):B(x)] ==> lam x. b(x) : PROD x:A. B(x)" 
0  164 

165 
ProdIL 

1149  166 
"[ A type; !!x. x:A ==> b(x) = c(x) : B(x)] ==> 
3837  167 
lam x. b(x) = lam x. c(x) : PROD x:A. B(x)" 
0  168 

3837  169 
ProdE "[ p : PROD x:A. B(x); a : A ] ==> p`a : B(a)" 
170 
ProdEL "[ p=q: PROD x:A. B(x); a=b : A ] ==> p`a = q`b : B(a)" 

0  171 

172 
ProdC 

1149  173 
"[ a : A; !!x. x:A ==> b(x) : B(x)] ==> 
3837  174 
(lam x. b(x)) ` a = b(a) : B(a)" 
0  175 

176 
ProdC2 

3837  177 
"p : PROD x:A. B(x) ==> (lam x. p`x) = p : PROD x:A. B(x)" 
0  178 

179 

180 
(*The Sum of a family of types*) 

181 

3837  182 
SumF "[ A type; !!x. x:A ==> B(x) type ] ==> SUM x:A. B(x) type" 
0  183 
SumFL 
3837  184 
"[ A = C; !!x. x:A ==> B(x) = D(x) ] ==> SUM x:A. B(x) = SUM x:C. D(x)" 
0  185 

3837  186 
SumI "[ a : A; b : B(a) ] ==> <a,b> : SUM x:A. B(x)" 
187 
SumIL "[ a=c:A; b=d:B(a) ] ==> <a,b> = <c,d> : SUM x:A. B(x)" 

0  188 

189 
SumE 

3837  190 
"[ p: SUM x:A. B(x); !!x y. [ x:A; y:B(x) ] ==> c(x,y): C(<x,y>) ] 
191 
==> split(p, %x y. c(x,y)) : C(p)" 

0  192 

193 
SumEL 

3837  194 
"[ p=q : SUM x:A. B(x); 
1149  195 
!!x y. [ x:A; y:B(x) ] ==> c(x,y)=d(x,y): C(<x,y>)] 
3837  196 
==> split(p, %x y. c(x,y)) = split(q, % x y. d(x,y)) : C(p)" 
0  197 

198 
SumC 

1149  199 
"[ a: A; b: B(a); !!x y. [ x:A; y:B(x) ] ==> c(x,y): C(<x,y>) ] 
3837  200 
==> split(<a,b>, %x y. c(x,y)) = c(a,b) : C(<a,b>)" 
0  201 

3837  202 
fst_def "fst(a) == split(a, %x y. x)" 
203 
snd_def "snd(a) == split(a, %x y. y)" 

0  204 

205 

206 
(*The sum of two types*) 

207 

208 
PlusF "[ A type; B type ] ==> A+B type" 

209 
PlusFL "[ A = C; B = D ] ==> A+B = C+D" 

210 

211 
PlusI_inl "[ a : A; B type ] ==> inl(a) : A+B" 

212 
PlusI_inlL "[ a = c : A; B type ] ==> inl(a) = inl(c) : A+B" 

213 

214 
PlusI_inr "[ A type; b : B ] ==> inr(b) : A+B" 

215 
PlusI_inrL "[ A type; b = d : B ] ==> inr(b) = inr(d) : A+B" 

216 

217 
PlusE 

1149  218 
"[ p: A+B; !!x. x:A ==> c(x): C(inl(x)); 
219 
!!y. y:B ==> d(y): C(inr(y)) ] 

3837  220 
==> when(p, %x. c(x), %y. d(y)) : C(p)" 
0  221 

222 
PlusEL 

1149  223 
"[ p = q : A+B; !!x. x: A ==> c(x) = e(x) : C(inl(x)); 
224 
!!y. y: B ==> d(y) = f(y) : C(inr(y)) ] 

3837  225 
==> when(p, %x. c(x), %y. d(y)) = when(q, %x. e(x), %y. f(y)) : C(p)" 
0  226 

227 
PlusC_inl 

1149  228 
"[ a: A; !!x. x:A ==> c(x): C(inl(x)); 
229 
!!y. y:B ==> d(y): C(inr(y)) ] 

3837  230 
==> when(inl(a), %x. c(x), %y. d(y)) = c(a) : C(inl(a))" 
0  231 

232 
PlusC_inr 

1149  233 
"[ b: B; !!x. x:A ==> c(x): C(inl(x)); 
234 
!!y. y:B ==> d(y): C(inr(y)) ] 

3837  235 
==> when(inr(b), %x. c(x), %y. d(y)) = d(b) : C(inr(b))" 
0  236 

237 

238 
(*The type Eq*) 

239 

240 
EqF "[ A type; a : A; b : A ] ==> Eq(A,a,b) type" 

241 
EqFL "[ A=B; a=c: A; b=d : A ] ==> Eq(A,a,b) = Eq(B,c,d)" 

242 
EqI "a = b : A ==> eq : Eq(A,a,b)" 

243 
EqE "p : Eq(A,a,b) ==> a = b : A" 

244 

245 
(*By equality of types, can prove C(p) from C(eq), an elimination rule*) 

246 
EqC "p : Eq(A,a,b) ==> p = eq : Eq(A,a,b)" 

247 

248 
(*The type F*) 

249 

250 
FF "F type" 

251 
FE "[ p: F; C type ] ==> contr(p) : C" 

252 
FEL "[ p = q : F; C type ] ==> contr(p) = contr(q) : C" 

253 

254 
(*The type T 

255 
MartinLof's book (page 68) discusses elimination and computation. 

256 
Elimination can be derived by computation and equality of types, 

257 
but with an extra premise C(x) type x:T. 

258 
Also computation can be derived from elimination. *) 

259 

260 
TF "T type" 

261 
TI "tt : T" 

262 
TE "[ p : T; c : C(tt) ] ==> c : C(p)" 

263 
TEL "[ p = q : T; c = d : C(tt) ] ==> c = d : C(p)" 

264 
TC "p : T ==> p = tt : T" 

265 
end 

266 

267 

268 
ML 

269 

270 
val print_translation = 

271 
[("Prod", dependent_tr' ("@PROD", "@>")), 

272 
("Sum", dependent_tr' ("@SUM", "@*"))]; 

273 