author | wenzelm |
Fri, 09 Oct 2015 20:26:03 +0200 | |
changeset 61378 | 3e04c9ca001a |
parent 60770 | 240563fbf41d |
child 61391 | 2332d9be352b |
permissions | -rw-r--r-- |
17441 | 1 |
(* Title: CTT/CTT.thy |
0 | 2 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
3 |
Copyright 1993 University of Cambridge |
|
4 |
*) |
|
5 |
||
60770 | 6 |
section \<open>Constructive Type Theory\<close> |
0 | 7 |
|
17441 | 8 |
theory CTT |
9 |
imports Pure |
|
10 |
begin |
|
11 |
||
48891 | 12 |
ML_file "~~/src/Provers/typedsimp.ML" |
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
35762
diff
changeset
|
13 |
setup Pure_Thy.old_appl_syntax_setup |
26956
1309a6a0a29f
setup PureThy.old_appl_syntax_setup -- theory Pure provides regular application syntax by default;
wenzelm
parents:
26391
diff
changeset
|
14 |
|
17441 | 15 |
typedecl i |
16 |
typedecl t |
|
17 |
typedecl o |
|
0 | 18 |
|
19 |
consts |
|
20 |
(*Types*) |
|
17441 | 21 |
F :: "t" |
22 |
T :: "t" (*F is empty, T contains one element*) |
|
58977 | 23 |
contr :: "i\<Rightarrow>i" |
0 | 24 |
tt :: "i" |
25 |
(*Natural numbers*) |
|
26 |
N :: "t" |
|
58977 | 27 |
succ :: "i\<Rightarrow>i" |
28 |
rec :: "[i, i, [i,i]\<Rightarrow>i] \<Rightarrow> i" |
|
0 | 29 |
(*Unions*) |
58977 | 30 |
inl :: "i\<Rightarrow>i" |
31 |
inr :: "i\<Rightarrow>i" |
|
60555
51a6997b1384
support 'when' statement, which corresponds to 'presume';
wenzelm
parents:
59780
diff
changeset
|
32 |
"when" :: "[i, i\<Rightarrow>i, i\<Rightarrow>i]\<Rightarrow>i" |
0 | 33 |
(*General Sum and Binary Product*) |
58977 | 34 |
Sum :: "[t, i\<Rightarrow>t]\<Rightarrow>t" |
35 |
fst :: "i\<Rightarrow>i" |
|
36 |
snd :: "i\<Rightarrow>i" |
|
37 |
split :: "[i, [i,i]\<Rightarrow>i] \<Rightarrow>i" |
|
0 | 38 |
(*General Product and Function Space*) |
58977 | 39 |
Prod :: "[t, i\<Rightarrow>t]\<Rightarrow>t" |
14765 | 40 |
(*Types*) |
58977 | 41 |
Plus :: "[t,t]\<Rightarrow>t" (infixr "+" 40) |
0 | 42 |
(*Equality type*) |
58977 | 43 |
Eq :: "[t,i,i]\<Rightarrow>t" |
0 | 44 |
eq :: "i" |
45 |
(*Judgements*) |
|
58977 | 46 |
Type :: "t \<Rightarrow> prop" ("(_ type)" [10] 5) |
47 |
Eqtype :: "[t,t]\<Rightarrow>prop" ("(_ =/ _)" [10,10] 5) |
|
48 |
Elem :: "[i, t]\<Rightarrow>prop" ("(_ /: _)" [10,10] 5) |
|
49 |
Eqelem :: "[i,i,t]\<Rightarrow>prop" ("(_ =/ _ :/ _)" [10,10,10] 5) |
|
50 |
Reduce :: "[i,i]\<Rightarrow>prop" ("Reduce[_,_]") |
|
0 | 51 |
(*Types*) |
14765 | 52 |
|
0 | 53 |
(*Functions*) |
58977 | 54 |
lambda :: "(i \<Rightarrow> i) \<Rightarrow> i" (binder "lam " 10) |
55 |
app :: "[i,i]\<Rightarrow>i" (infixl "`" 60) |
|
0 | 56 |
(*Natural numbers*) |
41310 | 57 |
Zero :: "i" ("0") |
0 | 58 |
(*Pairing*) |
58977 | 59 |
pair :: "[i,i]\<Rightarrow>i" ("(1<_,/_>)") |
0 | 60 |
|
14765 | 61 |
syntax |
58977 | 62 |
"_PROD" :: "[idt,t,t]\<Rightarrow>t" ("(3PROD _:_./ _)" 10) |
63 |
"_SUM" :: "[idt,t,t]\<Rightarrow>t" ("(3SUM _:_./ _)" 10) |
|
0 | 64 |
translations |
58977 | 65 |
"PROD x:A. B" == "CONST Prod(A, \<lambda>x. B)" |
66 |
"SUM x:A. B" == "CONST Sum(A, \<lambda>x. B)" |
|
19761 | 67 |
|
68 |
abbreviation |
|
58977 | 69 |
Arrow :: "[t,t]\<Rightarrow>t" (infixr "-->" 30) where |
19761 | 70 |
"A --> B == PROD _:A. B" |
21404
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21210
diff
changeset
|
71 |
abbreviation |
58977 | 72 |
Times :: "[t,t]\<Rightarrow>t" (infixr "*" 50) where |
19761 | 73 |
"A * B == SUM _:A. B" |
0 | 74 |
|
21210 | 75 |
notation (xsymbols) |
21524 | 76 |
lambda (binder "\<lambda>\<lambda>" 10) and |
21404
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21210
diff
changeset
|
77 |
Elem ("(_ /\<in> _)" [10,10] 5) and |
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21210
diff
changeset
|
78 |
Eqelem ("(2_ =/ _ \<in>/ _)" [10,10,10] 5) and |
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21210
diff
changeset
|
79 |
Arrow (infixr "\<longrightarrow>" 30) and |
19761 | 80 |
Times (infixr "\<times>" 50) |
17441 | 81 |
|
10467
e6e7205e9e91
x-symbol support for Pi, Sigma, -->, : (membership)
paulson
parents:
3837
diff
changeset
|
82 |
syntax (xsymbols) |
58977 | 83 |
"_PROD" :: "[idt,t,t] \<Rightarrow> t" ("(3\<Pi> _\<in>_./ _)" 10) |
84 |
"_SUM" :: "[idt,t,t] \<Rightarrow> t" ("(3\<Sigma> _\<in>_./ _)" 10) |
|
10467
e6e7205e9e91
x-symbol support for Pi, Sigma, -->, : (membership)
paulson
parents:
3837
diff
changeset
|
85 |
|
0 | 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.*) |
|
51308 | 92 |
axiomatization where |
93 |
refl_red: "\<And>a. Reduce[a,a]" and |
|
58977 | 94 |
red_if_equal: "\<And>a b A. a = b : A \<Longrightarrow> Reduce[a,b]" and |
95 |
trans_red: "\<And>a b c A. \<lbrakk>a = b : A; Reduce[b,c]\<rbrakk> \<Longrightarrow> a = c : A" and |
|
0 | 96 |
|
97 |
(*Reflexivity*) |
|
98 |
||
58977 | 99 |
refl_type: "\<And>A. A type \<Longrightarrow> A = A" and |
100 |
refl_elem: "\<And>a A. a : A \<Longrightarrow> a = a : A" and |
|
0 | 101 |
|
102 |
(*Symmetry*) |
|
103 |
||
58977 | 104 |
sym_type: "\<And>A B. A = B \<Longrightarrow> B = A" and |
105 |
sym_elem: "\<And>a b A. a = b : A \<Longrightarrow> b = a : A" and |
|
0 | 106 |
|
107 |
(*Transitivity*) |
|
108 |
||
58977 | 109 |
trans_type: "\<And>A B C. \<lbrakk>A = B; B = C\<rbrakk> \<Longrightarrow> A = C" and |
110 |
trans_elem: "\<And>a b c A. \<lbrakk>a = b : A; b = c : A\<rbrakk> \<Longrightarrow> a = c : A" and |
|
0 | 111 |
|
58977 | 112 |
equal_types: "\<And>a A B. \<lbrakk>a : A; A = B\<rbrakk> \<Longrightarrow> a : B" and |
113 |
equal_typesL: "\<And>a b A B. \<lbrakk>a = b : A; A = B\<rbrakk> \<Longrightarrow> a = b : B" and |
|
0 | 114 |
|
115 |
(*Substitution*) |
|
116 |
||
58977 | 117 |
subst_type: "\<And>a A B. \<lbrakk>a : A; \<And>z. z:A \<Longrightarrow> B(z) type\<rbrakk> \<Longrightarrow> B(a) type" and |
118 |
subst_typeL: "\<And>a c A B D. \<lbrakk>a = c : A; \<And>z. z:A \<Longrightarrow> B(z) = D(z)\<rbrakk> \<Longrightarrow> B(a) = D(c)" and |
|
0 | 119 |
|
58977 | 120 |
subst_elem: "\<And>a b A B. \<lbrakk>a : A; \<And>z. z:A \<Longrightarrow> b(z):B(z)\<rbrakk> \<Longrightarrow> b(a):B(a)" and |
17441 | 121 |
subst_elemL: |
58977 | 122 |
"\<And>a b c d A B. \<lbrakk>a = c : A; \<And>z. z:A \<Longrightarrow> b(z)=d(z) : B(z)\<rbrakk> \<Longrightarrow> b(a)=d(c) : B(a)" and |
0 | 123 |
|
124 |
||
125 |
(*The type N -- natural numbers*) |
|
126 |
||
51308 | 127 |
NF: "N type" and |
128 |
NI0: "0 : N" and |
|
58977 | 129 |
NI_succ: "\<And>a. a : N \<Longrightarrow> succ(a) : N" and |
130 |
NI_succL: "\<And>a b. a = b : N \<Longrightarrow> succ(a) = succ(b) : N" and |
|
0 | 131 |
|
17441 | 132 |
NE: |
58977 | 133 |
"\<And>p a b C. \<lbrakk>p: N; a: C(0); \<And>u v. \<lbrakk>u: N; v: C(u)\<rbrakk> \<Longrightarrow> b(u,v): C(succ(u))\<rbrakk> |
134 |
\<Longrightarrow> rec(p, a, \<lambda>u v. b(u,v)) : C(p)" and |
|
0 | 135 |
|
17441 | 136 |
NEL: |
58977 | 137 |
"\<And>p q a b c d C. \<lbrakk>p = q : N; a = c : C(0); |
138 |
\<And>u v. \<lbrakk>u: N; v: C(u)\<rbrakk> \<Longrightarrow> b(u,v) = d(u,v): C(succ(u))\<rbrakk> |
|
139 |
\<Longrightarrow> rec(p, a, \<lambda>u v. b(u,v)) = rec(q,c,d) : C(p)" and |
|
0 | 140 |
|
17441 | 141 |
NC0: |
58977 | 142 |
"\<And>a b C. \<lbrakk>a: C(0); \<And>u v. \<lbrakk>u: N; v: C(u)\<rbrakk> \<Longrightarrow> b(u,v): C(succ(u))\<rbrakk> |
143 |
\<Longrightarrow> rec(0, a, \<lambda>u v. b(u,v)) = a : C(0)" and |
|
0 | 144 |
|
17441 | 145 |
NC_succ: |
58977 | 146 |
"\<And>p a b C. \<lbrakk>p: N; a: C(0); \<And>u v. \<lbrakk>u: N; v: C(u)\<rbrakk> \<Longrightarrow> b(u,v): C(succ(u))\<rbrakk> \<Longrightarrow> |
147 |
rec(succ(p), a, \<lambda>u v. b(u,v)) = b(p, rec(p, a, \<lambda>u v. b(u,v))) : C(succ(p))" and |
|
0 | 148 |
|
149 |
(*The fourth Peano axiom. See page 91 of Martin-Lof's book*) |
|
58977 | 150 |
zero_ne_succ: "\<And>a. \<lbrakk>a: N; 0 = succ(a) : N\<rbrakk> \<Longrightarrow> 0: F" and |
0 | 151 |
|
152 |
||
153 |
(*The Product of a family of types*) |
|
154 |
||
58977 | 155 |
ProdF: "\<And>A B. \<lbrakk>A type; \<And>x. x:A \<Longrightarrow> B(x) type\<rbrakk> \<Longrightarrow> PROD x:A. B(x) type" and |
0 | 156 |
|
17441 | 157 |
ProdFL: |
58977 | 158 |
"\<And>A B C D. \<lbrakk>A = C; \<And>x. x:A \<Longrightarrow> B(x) = D(x)\<rbrakk> \<Longrightarrow> PROD x:A. B(x) = PROD x:C. D(x)" and |
0 | 159 |
|
17441 | 160 |
ProdI: |
58977 | 161 |
"\<And>b A B. \<lbrakk>A type; \<And>x. x:A \<Longrightarrow> b(x):B(x)\<rbrakk> \<Longrightarrow> lam x. b(x) : PROD x:A. B(x)" and |
0 | 162 |
|
58977 | 163 |
ProdIL: "\<And>b c A B. \<lbrakk>A type; \<And>x. x:A \<Longrightarrow> b(x) = c(x) : B(x)\<rbrakk> \<Longrightarrow> |
164 |
lam x. b(x) = lam x. c(x) : PROD x:A. B(x)" and |
|
0 | 165 |
|
58977 | 166 |
ProdE: "\<And>p a A B. \<lbrakk>p : PROD x:A. B(x); a : A\<rbrakk> \<Longrightarrow> p`a : B(a)" and |
167 |
ProdEL: "\<And>p q a b A B. \<lbrakk>p = q: PROD x:A. B(x); a = b : A\<rbrakk> \<Longrightarrow> p`a = q`b : B(a)" and |
|
0 | 168 |
|
58977 | 169 |
ProdC: "\<And>a b A B. \<lbrakk>a : A; \<And>x. x:A \<Longrightarrow> b(x) : B(x)\<rbrakk> \<Longrightarrow> (lam x. b(x)) ` a = b(a) : B(a)" and |
0 | 170 |
|
58977 | 171 |
ProdC2: "\<And>p A B. p : PROD x:A. B(x) \<Longrightarrow> (lam x. p`x) = p : PROD x:A. B(x)" and |
0 | 172 |
|
173 |
||
174 |
(*The Sum of a family of types*) |
|
175 |
||
58977 | 176 |
SumF: "\<And>A B. \<lbrakk>A type; \<And>x. x:A \<Longrightarrow> B(x) type\<rbrakk> \<Longrightarrow> SUM x:A. B(x) type" and |
177 |
SumFL: "\<And>A B C D. \<lbrakk>A = C; \<And>x. x:A \<Longrightarrow> B(x) = D(x)\<rbrakk> \<Longrightarrow> SUM x:A. B(x) = SUM x:C. D(x)" and |
|
0 | 178 |
|
58977 | 179 |
SumI: "\<And>a b A B. \<lbrakk>a : A; b : B(a)\<rbrakk> \<Longrightarrow> <a,b> : SUM x:A. B(x)" and |
180 |
SumIL: "\<And>a b c d A B. \<lbrakk> a = c : A; b = d : B(a)\<rbrakk> \<Longrightarrow> <a,b> = <c,d> : SUM x:A. B(x)" and |
|
0 | 181 |
|
58977 | 182 |
SumE: "\<And>p c A B C. \<lbrakk>p: SUM x:A. B(x); \<And>x y. \<lbrakk>x:A; y:B(x)\<rbrakk> \<Longrightarrow> c(x,y): C(<x,y>)\<rbrakk> |
183 |
\<Longrightarrow> split(p, \<lambda>x y. c(x,y)) : C(p)" and |
|
0 | 184 |
|
58977 | 185 |
SumEL: "\<And>p q c d A B C. \<lbrakk>p = q : SUM x:A. B(x); |
186 |
\<And>x y. \<lbrakk>x:A; y:B(x)\<rbrakk> \<Longrightarrow> c(x,y)=d(x,y): C(<x,y>)\<rbrakk> |
|
187 |
\<Longrightarrow> split(p, \<lambda>x y. c(x,y)) = split(q, \<lambda>x y. d(x,y)) : C(p)" and |
|
0 | 188 |
|
58977 | 189 |
SumC: "\<And>a b c A B C. \<lbrakk>a: A; b: B(a); \<And>x y. \<lbrakk>x:A; y:B(x)\<rbrakk> \<Longrightarrow> c(x,y): C(<x,y>)\<rbrakk> |
190 |
\<Longrightarrow> split(<a,b>, \<lambda>x y. c(x,y)) = c(a,b) : C(<a,b>)" and |
|
0 | 191 |
|
58977 | 192 |
fst_def: "\<And>a. fst(a) == split(a, \<lambda>x y. x)" and |
193 |
snd_def: "\<And>a. snd(a) == split(a, \<lambda>x y. y)" and |
|
0 | 194 |
|
195 |
||
196 |
(*The sum of two types*) |
|
197 |
||
58977 | 198 |
PlusF: "\<And>A B. \<lbrakk>A type; B type\<rbrakk> \<Longrightarrow> A+B type" and |
199 |
PlusFL: "\<And>A B C D. \<lbrakk>A = C; B = D\<rbrakk> \<Longrightarrow> A+B = C+D" and |
|
0 | 200 |
|
58977 | 201 |
PlusI_inl: "\<And>a A B. \<lbrakk>a : A; B type\<rbrakk> \<Longrightarrow> inl(a) : A+B" and |
202 |
PlusI_inlL: "\<And>a c A B. \<lbrakk>a = c : A; B type\<rbrakk> \<Longrightarrow> inl(a) = inl(c) : A+B" and |
|
0 | 203 |
|
58977 | 204 |
PlusI_inr: "\<And>b A B. \<lbrakk>A type; b : B\<rbrakk> \<Longrightarrow> inr(b) : A+B" and |
205 |
PlusI_inrL: "\<And>b d A B. \<lbrakk>A type; b = d : B\<rbrakk> \<Longrightarrow> inr(b) = inr(d) : A+B" and |
|
0 | 206 |
|
17441 | 207 |
PlusE: |
58977 | 208 |
"\<And>p c d A B C. \<lbrakk>p: A+B; |
209 |
\<And>x. x:A \<Longrightarrow> c(x): C(inl(x)); |
|
210 |
\<And>y. y:B \<Longrightarrow> d(y): C(inr(y)) \<rbrakk> \<Longrightarrow> when(p, \<lambda>x. c(x), \<lambda>y. d(y)) : C(p)" and |
|
0 | 211 |
|
17441 | 212 |
PlusEL: |
58977 | 213 |
"\<And>p q c d e f A B C. \<lbrakk>p = q : A+B; |
214 |
\<And>x. x: A \<Longrightarrow> c(x) = e(x) : C(inl(x)); |
|
215 |
\<And>y. y: B \<Longrightarrow> d(y) = f(y) : C(inr(y))\<rbrakk> |
|
216 |
\<Longrightarrow> when(p, \<lambda>x. c(x), \<lambda>y. d(y)) = when(q, \<lambda>x. e(x), \<lambda>y. f(y)) : C(p)" and |
|
0 | 217 |
|
17441 | 218 |
PlusC_inl: |
58977 | 219 |
"\<And>a c d A C. \<lbrakk>a: A; |
220 |
\<And>x. x:A \<Longrightarrow> c(x): C(inl(x)); |
|
221 |
\<And>y. y:B \<Longrightarrow> d(y): C(inr(y)) \<rbrakk> |
|
222 |
\<Longrightarrow> when(inl(a), \<lambda>x. c(x), \<lambda>y. d(y)) = c(a) : C(inl(a))" and |
|
0 | 223 |
|
17441 | 224 |
PlusC_inr: |
58977 | 225 |
"\<And>b c d A B C. \<lbrakk>b: B; |
226 |
\<And>x. x:A \<Longrightarrow> c(x): C(inl(x)); |
|
227 |
\<And>y. y:B \<Longrightarrow> d(y): C(inr(y))\<rbrakk> |
|
228 |
\<Longrightarrow> when(inr(b), \<lambda>x. c(x), \<lambda>y. d(y)) = d(b) : C(inr(b))" and |
|
0 | 229 |
|
230 |
||
231 |
(*The type Eq*) |
|
232 |
||
58977 | 233 |
EqF: "\<And>a b A. \<lbrakk>A type; a : A; b : A\<rbrakk> \<Longrightarrow> Eq(A,a,b) type" and |
234 |
EqFL: "\<And>a b c d A B. \<lbrakk>A = B; a = c : A; b = d : A\<rbrakk> \<Longrightarrow> Eq(A,a,b) = Eq(B,c,d)" and |
|
235 |
EqI: "\<And>a b A. a = b : A \<Longrightarrow> eq : Eq(A,a,b)" and |
|
236 |
EqE: "\<And>p a b A. p : Eq(A,a,b) \<Longrightarrow> a = b : A" and |
|
0 | 237 |
|
238 |
(*By equality of types, can prove C(p) from C(eq), an elimination rule*) |
|
58977 | 239 |
EqC: "\<And>p a b A. p : Eq(A,a,b) \<Longrightarrow> p = eq : Eq(A,a,b)" and |
0 | 240 |
|
241 |
(*The type F*) |
|
242 |
||
51308 | 243 |
FF: "F type" and |
58977 | 244 |
FE: "\<And>p C. \<lbrakk>p: F; C type\<rbrakk> \<Longrightarrow> contr(p) : C" and |
245 |
FEL: "\<And>p q C. \<lbrakk>p = q : F; C type\<rbrakk> \<Longrightarrow> contr(p) = contr(q) : C" and |
|
0 | 246 |
|
247 |
(*The type T |
|
248 |
Martin-Lof's book (page 68) discusses elimination and computation. |
|
249 |
Elimination can be derived by computation and equality of types, |
|
250 |
but with an extra premise C(x) type x:T. |
|
251 |
Also computation can be derived from elimination. *) |
|
252 |
||
51308 | 253 |
TF: "T type" and |
254 |
TI: "tt : T" and |
|
58977 | 255 |
TE: "\<And>p c C. \<lbrakk>p : T; c : C(tt)\<rbrakk> \<Longrightarrow> c : C(p)" and |
256 |
TEL: "\<And>p q c d C. \<lbrakk>p = q : T; c = d : C(tt)\<rbrakk> \<Longrightarrow> c = d : C(p)" and |
|
257 |
TC: "\<And>p. p : T \<Longrightarrow> p = tt : T" |
|
0 | 258 |
|
19761 | 259 |
|
260 |
subsection "Tactics and derived rules for Constructive Type Theory" |
|
261 |
||
262 |
(*Formation rules*) |
|
263 |
lemmas form_rls = NF ProdF SumF PlusF EqF FF TF |
|
264 |
and formL_rls = ProdFL SumFL PlusFL EqFL |
|
265 |
||
266 |
(*Introduction rules |
|
267 |
OMITTED: EqI, because its premise is an eqelem, not an elem*) |
|
268 |
lemmas intr_rls = NI0 NI_succ ProdI SumI PlusI_inl PlusI_inr TI |
|
269 |
and intrL_rls = NI_succL ProdIL SumIL PlusI_inlL PlusI_inrL |
|
270 |
||
271 |
(*Elimination rules |
|
272 |
OMITTED: EqE, because its conclusion is an eqelem, not an elem |
|
273 |
TE, because it does not involve a constructor *) |
|
274 |
lemmas elim_rls = NE ProdE SumE PlusE FE |
|
275 |
and elimL_rls = NEL ProdEL SumEL PlusEL FEL |
|
276 |
||
277 |
(*OMITTED: eqC are TC because they make rewriting loop: p = un = un = ... *) |
|
278 |
lemmas comp_rls = NC0 NC_succ ProdC SumC PlusC_inl PlusC_inr |
|
279 |
||
280 |
(*rules with conclusion a:A, an elem judgement*) |
|
281 |
lemmas element_rls = intr_rls elim_rls |
|
282 |
||
283 |
(*Definitions are (meta)equality axioms*) |
|
284 |
lemmas basic_defs = fst_def snd_def |
|
285 |
||
286 |
(*Compare with standard version: B is applied to UNSIMPLIFIED expression! *) |
|
58977 | 287 |
lemma SumIL2: "\<lbrakk>c = a : A; d = b : B(a)\<rbrakk> \<Longrightarrow> <c,d> = <a,b> : Sum(A,B)" |
19761 | 288 |
apply (rule sym_elem) |
289 |
apply (rule SumIL) |
|
290 |
apply (rule_tac [!] sym_elem) |
|
291 |
apply assumption+ |
|
292 |
done |
|
293 |
||
294 |
lemmas intrL2_rls = NI_succL ProdIL SumIL2 PlusI_inlL PlusI_inrL |
|
295 |
||
296 |
(*Exploit p:Prod(A,B) to create the assumption z:B(a). |
|
297 |
A more natural form of product elimination. *) |
|
298 |
lemma subst_prodE: |
|
299 |
assumes "p: Prod(A,B)" |
|
300 |
and "a: A" |
|
58977 | 301 |
and "\<And>z. z: B(a) \<Longrightarrow> c(z): C(z)" |
19761 | 302 |
shows "c(p`a): C(p`a)" |
41526 | 303 |
apply (rule assms ProdE)+ |
19761 | 304 |
done |
305 |
||
306 |
||
60770 | 307 |
subsection \<open>Tactics for type checking\<close> |
19761 | 308 |
|
60770 | 309 |
ML \<open> |
19761 | 310 |
|
311 |
local |
|
312 |
||
56250 | 313 |
fun is_rigid_elem (Const(@{const_name Elem},_) $ a $ _) = not(is_Var (head_of a)) |
314 |
| is_rigid_elem (Const(@{const_name Eqelem},_) $ a $ _ $ _) = not(is_Var (head_of a)) |
|
315 |
| is_rigid_elem (Const(@{const_name Type},_) $ a) = not(is_Var (head_of a)) |
|
19761 | 316 |
| is_rigid_elem _ = false |
317 |
||
318 |
in |
|
319 |
||
320 |
(*Try solving a:A or a=b:A by assumption provided a is rigid!*) |
|
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58889
diff
changeset
|
321 |
fun test_assume_tac ctxt = SUBGOAL(fn (prem,i) => |
19761 | 322 |
if is_rigid_elem (Logic.strip_assums_concl prem) |
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58889
diff
changeset
|
323 |
then assume_tac ctxt i else no_tac) |
19761 | 324 |
|
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58889
diff
changeset
|
325 |
fun ASSUME ctxt tf i = test_assume_tac ctxt i ORELSE tf i |
19761 | 326 |
|
327 |
end; |
|
328 |
||
60770 | 329 |
\<close> |
19761 | 330 |
|
331 |
(*For simplification: type formation and checking, |
|
332 |
but no equalities between terms*) |
|
333 |
lemmas routine_rls = form_rls formL_rls refl_type element_rls |
|
334 |
||
60770 | 335 |
ML \<open> |
19761 | 336 |
local |
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
26956
diff
changeset
|
337 |
val equal_rls = @{thms form_rls} @ @{thms element_rls} @ @{thms intrL_rls} @ |
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
26956
diff
changeset
|
338 |
@{thms elimL_rls} @ @{thms refl_elem} |
19761 | 339 |
in |
340 |
||
59164 | 341 |
fun routine_tac rls ctxt prems = |
342 |
ASSUME ctxt (filt_resolve_from_net_tac ctxt 4 (Tactic.build_net (prems @ rls))); |
|
19761 | 343 |
|
344 |
(*Solve all subgoals "A type" using formation rules. *) |
|
59164 | 345 |
val form_net = Tactic.build_net @{thms form_rls}; |
346 |
fun form_tac ctxt = |
|
347 |
REPEAT_FIRST (ASSUME ctxt (filt_resolve_from_net_tac ctxt 1 form_net)); |
|
19761 | 348 |
|
349 |
(*Type checking: solve a:A (a rigid, A flexible) by intro and elim rules. *) |
|
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58889
diff
changeset
|
350 |
fun typechk_tac ctxt thms = |
59164 | 351 |
let val tac = |
352 |
filt_resolve_from_net_tac ctxt 3 |
|
353 |
(Tactic.build_net (thms @ @{thms form_rls} @ @{thms element_rls})) |
|
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58889
diff
changeset
|
354 |
in REPEAT_FIRST (ASSUME ctxt tac) end |
19761 | 355 |
|
356 |
(*Solve a:A (a flexible, A rigid) by introduction rules. |
|
357 |
Cannot use stringtrees (filt_resolve_tac) since |
|
358 |
goals like ?a:SUM(A,B) have a trivial head-string *) |
|
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58889
diff
changeset
|
359 |
fun intr_tac ctxt thms = |
59164 | 360 |
let val tac = |
361 |
filt_resolve_from_net_tac ctxt 1 |
|
362 |
(Tactic.build_net (thms @ @{thms form_rls} @ @{thms intr_rls})) |
|
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58889
diff
changeset
|
363 |
in REPEAT_FIRST (ASSUME ctxt tac) end |
19761 | 364 |
|
365 |
(*Equality proving: solve a=b:A (where a is rigid) by long rules. *) |
|
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58889
diff
changeset
|
366 |
fun equal_tac ctxt thms = |
59164 | 367 |
REPEAT_FIRST |
368 |
(ASSUME ctxt (filt_resolve_from_net_tac ctxt 3 (Tactic.build_net (thms @ equal_rls)))) |
|
0 | 369 |
|
17441 | 370 |
end |
60770 | 371 |
\<close> |
19761 | 372 |
|
60770 | 373 |
method_setup form = \<open>Scan.succeed (fn ctxt => SIMPLE_METHOD (form_tac ctxt))\<close> |
374 |
method_setup typechk = \<open>Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD (typechk_tac ctxt ths))\<close> |
|
375 |
method_setup intr = \<open>Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD (intr_tac ctxt ths))\<close> |
|
376 |
method_setup equal = \<open>Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD (equal_tac ctxt ths))\<close> |
|
19761 | 377 |
|
378 |
||
60770 | 379 |
subsection \<open>Simplification\<close> |
19761 | 380 |
|
381 |
(*To simplify the type in a goal*) |
|
58977 | 382 |
lemma replace_type: "\<lbrakk>B = A; a : A\<rbrakk> \<Longrightarrow> a : B" |
19761 | 383 |
apply (rule equal_types) |
384 |
apply (rule_tac [2] sym_type) |
|
385 |
apply assumption+ |
|
386 |
done |
|
387 |
||
388 |
(*Simplify the parameter of a unary type operator.*) |
|
389 |
lemma subst_eqtyparg: |
|
23467 | 390 |
assumes 1: "a=c : A" |
58977 | 391 |
and 2: "\<And>z. z:A \<Longrightarrow> B(z) type" |
19761 | 392 |
shows "B(a)=B(c)" |
393 |
apply (rule subst_typeL) |
|
394 |
apply (rule_tac [2] refl_type) |
|
23467 | 395 |
apply (rule 1) |
396 |
apply (erule 2) |
|
19761 | 397 |
done |
398 |
||
399 |
(*Simplification rules for Constructive Type Theory*) |
|
400 |
lemmas reduction_rls = comp_rls [THEN trans_elem] |
|
401 |
||
60770 | 402 |
ML \<open> |
19761 | 403 |
(*Converts each goal "e : Eq(A,a,b)" into "a=b:A" for simplification. |
404 |
Uses other intro rules to avoid changing flexible goals.*) |
|
59164 | 405 |
val eqintr_net = Tactic.build_net @{thms EqI intr_rls} |
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58889
diff
changeset
|
406 |
fun eqintr_tac ctxt = |
59164 | 407 |
REPEAT_FIRST (ASSUME ctxt (filt_resolve_from_net_tac ctxt 1 eqintr_net)) |
19761 | 408 |
|
409 |
(** Tactics that instantiate CTT-rules. |
|
410 |
Vars in the given terms will be incremented! |
|
411 |
The (rtac EqE i) lets them apply to equality judgements. **) |
|
412 |
||
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
26956
diff
changeset
|
413 |
fun NE_tac ctxt sp i = |
60754 | 414 |
TRY (resolve_tac ctxt @{thms EqE} i) THEN |
59780 | 415 |
Rule_Insts.res_inst_tac ctxt [((("p", 0), Position.none), sp)] [] @{thm NE} i |
19761 | 416 |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
26956
diff
changeset
|
417 |
fun SumE_tac ctxt sp i = |
60754 | 418 |
TRY (resolve_tac ctxt @{thms EqE} i) THEN |
59780 | 419 |
Rule_Insts.res_inst_tac ctxt [((("p", 0), Position.none), sp)] [] @{thm SumE} i |
19761 | 420 |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
26956
diff
changeset
|
421 |
fun PlusE_tac ctxt sp i = |
60754 | 422 |
TRY (resolve_tac ctxt @{thms EqE} i) THEN |
59780 | 423 |
Rule_Insts.res_inst_tac ctxt [((("p", 0), Position.none), sp)] [] @{thm PlusE} i |
19761 | 424 |
|
425 |
(** Predicate logic reasoning, WITH THINNING!! Procedures adapted from NJ. **) |
|
426 |
||
427 |
(*Finds f:Prod(A,B) and a:A in the assumptions, concludes there is z:B(a) *) |
|
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58889
diff
changeset
|
428 |
fun add_mp_tac ctxt i = |
60754 | 429 |
resolve_tac ctxt @{thms subst_prodE} i THEN assume_tac ctxt i THEN assume_tac ctxt i |
19761 | 430 |
|
431 |
(*Finds P-->Q and P in the assumptions, replaces implication by Q *) |
|
60754 | 432 |
fun mp_tac ctxt i = eresolve_tac ctxt @{thms subst_prodE} i THEN assume_tac ctxt i |
19761 | 433 |
|
434 |
(*"safe" when regarded as predicate calculus rules*) |
|
435 |
val safe_brls = sort (make_ord lessb) |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
26956
diff
changeset
|
436 |
[ (true, @{thm FE}), (true,asm_rl), |
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
26956
diff
changeset
|
437 |
(false, @{thm ProdI}), (true, @{thm SumE}), (true, @{thm PlusE}) ] |
19761 | 438 |
|
439 |
val unsafe_brls = |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
26956
diff
changeset
|
440 |
[ (false, @{thm PlusI_inl}), (false, @{thm PlusI_inr}), (false, @{thm SumI}), |
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
26956
diff
changeset
|
441 |
(true, @{thm subst_prodE}) ] |
19761 | 442 |
|
443 |
(*0 subgoals vs 1 or more*) |
|
444 |
val (safe0_brls, safep_brls) = |
|
445 |
List.partition (curry (op =) 0 o subgoals_of_brl) safe_brls |
|
446 |
||
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58889
diff
changeset
|
447 |
fun safestep_tac ctxt thms i = |
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58889
diff
changeset
|
448 |
form_tac ctxt ORELSE |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
449 |
resolve_tac ctxt thms i ORELSE |
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
450 |
biresolve_tac ctxt safe0_brls i ORELSE mp_tac ctxt i ORELSE |
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
451 |
DETERM (biresolve_tac ctxt safep_brls i) |
19761 | 452 |
|
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58889
diff
changeset
|
453 |
fun safe_tac ctxt thms i = DEPTH_SOLVE_1 (safestep_tac ctxt thms i) |
19761 | 454 |
|
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
455 |
fun step_tac ctxt thms = safestep_tac ctxt thms ORELSE' biresolve_tac ctxt unsafe_brls |
19761 | 456 |
|
457 |
(*Fails unless it solves the goal!*) |
|
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58889
diff
changeset
|
458 |
fun pc_tac ctxt thms = DEPTH_SOLVE_1 o (step_tac ctxt thms) |
60770 | 459 |
\<close> |
19761 | 460 |
|
60770 | 461 |
method_setup eqintr = \<open>Scan.succeed (SIMPLE_METHOD o eqintr_tac)\<close> |
462 |
method_setup NE = \<open> |
|
58975 | 463 |
Scan.lift Args.name_inner_syntax >> (fn s => fn ctxt => SIMPLE_METHOD' (NE_tac ctxt s)) |
60770 | 464 |
\<close> |
465 |
method_setup pc = \<open>Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD' (pc_tac ctxt ths))\<close> |
|
466 |
method_setup add_mp = \<open>Scan.succeed (SIMPLE_METHOD' o add_mp_tac)\<close> |
|
58972 | 467 |
|
48891 | 468 |
ML_file "rew.ML" |
60770 | 469 |
method_setup rew = \<open>Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD (rew_tac ctxt ths))\<close> |
470 |
method_setup hyp_rew = \<open>Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD (hyp_rew_tac ctxt ths))\<close> |
|
58972 | 471 |
|
19761 | 472 |
|
60770 | 473 |
subsection \<open>The elimination rules for fst/snd\<close> |
19761 | 474 |
|
58977 | 475 |
lemma SumE_fst: "p : Sum(A,B) \<Longrightarrow> fst(p) : A" |
19761 | 476 |
apply (unfold basic_defs) |
477 |
apply (erule SumE) |
|
478 |
apply assumption |
|
479 |
done |
|
480 |
||
481 |
(*The first premise must be p:Sum(A,B) !!*) |
|
482 |
lemma SumE_snd: |
|
483 |
assumes major: "p: Sum(A,B)" |
|
484 |
and "A type" |
|
58977 | 485 |
and "\<And>x. x:A \<Longrightarrow> B(x) type" |
19761 | 486 |
shows "snd(p) : B(fst(p))" |
487 |
apply (unfold basic_defs) |
|
488 |
apply (rule major [THEN SumE]) |
|
489 |
apply (rule SumC [THEN subst_eqtyparg, THEN replace_type]) |
|
58972 | 490 |
apply (typechk assms) |
19761 | 491 |
done |
492 |
||
493 |
end |