15 typedecl i |
15 typedecl i |
16 typedecl t |
16 typedecl t |
17 typedecl o |
17 typedecl o |
18 |
18 |
19 consts |
19 consts |
20 (*Types*) |
20 \<comment> \<open>Types\<close> |
21 F :: "t" |
21 F :: "t" |
22 T :: "t" (*F is empty, T contains one element*) |
22 T :: "t" \<comment> \<open>\<open>F\<close> is empty, \<open>T\<close> contains one element\<close> |
23 contr :: "i\<Rightarrow>i" |
23 contr :: "i\<Rightarrow>i" |
24 tt :: "i" |
24 tt :: "i" |
25 (*Natural numbers*) |
25 \<comment> \<open>Natural numbers\<close> |
26 N :: "t" |
26 N :: "t" |
27 succ :: "i\<Rightarrow>i" |
27 succ :: "i\<Rightarrow>i" |
28 rec :: "[i, i, [i,i]\<Rightarrow>i] \<Rightarrow> i" |
28 rec :: "[i, i, [i,i]\<Rightarrow>i] \<Rightarrow> i" |
29 (*Unions*) |
29 \<comment> \<open>Unions\<close> |
30 inl :: "i\<Rightarrow>i" |
30 inl :: "i\<Rightarrow>i" |
31 inr :: "i\<Rightarrow>i" |
31 inr :: "i\<Rightarrow>i" |
32 "when" :: "[i, i\<Rightarrow>i, i\<Rightarrow>i]\<Rightarrow>i" |
32 "when" :: "[i, i\<Rightarrow>i, i\<Rightarrow>i]\<Rightarrow>i" |
33 (*General Sum and Binary Product*) |
33 \<comment> \<open>General Sum and Binary Product\<close> |
34 Sum :: "[t, i\<Rightarrow>t]\<Rightarrow>t" |
34 Sum :: "[t, i\<Rightarrow>t]\<Rightarrow>t" |
35 fst :: "i\<Rightarrow>i" |
35 fst :: "i\<Rightarrow>i" |
36 snd :: "i\<Rightarrow>i" |
36 snd :: "i\<Rightarrow>i" |
37 split :: "[i, [i,i]\<Rightarrow>i] \<Rightarrow>i" |
37 split :: "[i, [i,i]\<Rightarrow>i] \<Rightarrow>i" |
38 (*General Product and Function Space*) |
38 \<comment> \<open>General Product and Function Space\<close> |
39 Prod :: "[t, i\<Rightarrow>t]\<Rightarrow>t" |
39 Prod :: "[t, i\<Rightarrow>t]\<Rightarrow>t" |
40 (*Types*) |
40 \<comment> \<open>Types\<close> |
41 Plus :: "[t,t]\<Rightarrow>t" (infixr "+" 40) |
41 Plus :: "[t,t]\<Rightarrow>t" (infixr "+" 40) |
42 (*Equality type*) |
42 \<comment> \<open>Equality type\<close> |
43 Eq :: "[t,i,i]\<Rightarrow>t" |
43 Eq :: "[t,i,i]\<Rightarrow>t" |
44 eq :: "i" |
44 eq :: "i" |
45 (*Judgements*) |
45 \<comment> \<open>Judgements\<close> |
46 Type :: "t \<Rightarrow> prop" ("(_ type)" [10] 5) |
46 Type :: "t \<Rightarrow> prop" ("(_ type)" [10] 5) |
47 Eqtype :: "[t,t]\<Rightarrow>prop" ("(_ =/ _)" [10,10] 5) |
47 Eqtype :: "[t,t]\<Rightarrow>prop" ("(_ =/ _)" [10,10] 5) |
48 Elem :: "[i, 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) |
49 Eqelem :: "[i,i,t]\<Rightarrow>prop" ("(_ =/ _ :/ _)" [10,10,10] 5) |
50 Reduce :: "[i,i]\<Rightarrow>prop" ("Reduce[_,_]") |
50 Reduce :: "[i,i]\<Rightarrow>prop" ("Reduce[_,_]") |
51 (*Types*) |
51 |
52 |
52 \<comment> \<open>Types\<close> |
53 (*Functions*) |
53 |
|
54 \<comment> \<open>Functions\<close> |
54 lambda :: "(i \<Rightarrow> i) \<Rightarrow> i" (binder "\<^bold>\<lambda>" 10) |
55 lambda :: "(i \<Rightarrow> i) \<Rightarrow> i" (binder "\<^bold>\<lambda>" 10) |
55 app :: "[i,i]\<Rightarrow>i" (infixl "`" 60) |
56 app :: "[i,i]\<Rightarrow>i" (infixl "`" 60) |
56 (*Natural numbers*) |
57 \<comment> \<open>Natural numbers\<close> |
57 Zero :: "i" ("0") |
58 Zero :: "i" ("0") |
58 (*Pairing*) |
59 \<comment> \<open>Pairing\<close> |
59 pair :: "[i,i]\<Rightarrow>i" ("(1<_,/_>)") |
60 pair :: "[i,i]\<Rightarrow>i" ("(1<_,/_>)") |
60 |
61 |
61 syntax |
62 syntax |
62 "_PROD" :: "[idt,t,t]\<Rightarrow>t" ("(3\<Prod>_:_./ _)" 10) |
63 "_PROD" :: "[idt,t,t]\<Rightarrow>t" ("(3\<Prod>_:_./ _)" 10) |
63 "_SUM" :: "[idt,t,t]\<Rightarrow>t" ("(3\<Sum>_:_./ _)" 10) |
64 "_SUM" :: "[idt,t,t]\<Rightarrow>t" ("(3\<Sum>_:_./ _)" 10) |
64 translations |
65 translations |
65 "\<Prod>x:A. B" \<rightleftharpoons> "CONST Prod(A, \<lambda>x. B)" |
66 "\<Prod>x:A. B" \<rightleftharpoons> "CONST Prod(A, \<lambda>x. B)" |
66 "\<Sum>x:A. B" \<rightleftharpoons> "CONST Sum(A, \<lambda>x. B)" |
67 "\<Sum>x:A. B" \<rightleftharpoons> "CONST Sum(A, \<lambda>x. B)" |
67 |
68 |
68 abbreviation |
69 abbreviation Arrow :: "[t,t]\<Rightarrow>t" (infixr "\<longrightarrow>" 30) |
69 Arrow :: "[t,t]\<Rightarrow>t" (infixr "\<longrightarrow>" 30) where |
70 where "A \<longrightarrow> B \<equiv> \<Prod>_:A. B" |
70 "A \<longrightarrow> B \<equiv> \<Prod>_:A. B" |
71 |
71 abbreviation |
72 abbreviation Times :: "[t,t]\<Rightarrow>t" (infixr "\<times>" 50) |
72 Times :: "[t,t]\<Rightarrow>t" (infixr "\<times>" 50) where |
73 where "A \<times> B \<equiv> \<Sum>_:A. B" |
73 "A \<times> B \<equiv> \<Sum>_:A. B" |
74 |
74 |
75 text \<open> |
75 (*Reduction: a weaker notion than equality; a hack for simplification. |
76 Reduction: a weaker notion than equality; a hack for simplification. |
76 Reduce[a,b] means either that a=b:A for some A or else that "a" and "b" |
77 \<open>Reduce[a,b]\<close> means either that \<open>a = b : A\<close> for some \<open>A\<close> or else |
77 are textually identical.*) |
78 that \<open>a\<close> and \<open>b\<close> are textually identical. |
78 |
79 |
79 (*does not verify a:A! Sound because only trans_red uses a Reduce premise |
80 Does not verify \<open>a:A\<close>! Sound because only \<open>trans_red\<close> uses a \<open>Reduce\<close> |
80 No new theorems can be proved about the standard judgements.*) |
81 premise. No new theorems can be proved about the standard judgements. |
81 axiomatization where |
82 \<close> |
|
83 axiomatization |
|
84 where |
82 refl_red: "\<And>a. Reduce[a,a]" and |
85 refl_red: "\<And>a. Reduce[a,a]" and |
83 red_if_equal: "\<And>a b A. a = b : A \<Longrightarrow> Reduce[a,b]" and |
86 red_if_equal: "\<And>a b A. a = b : A \<Longrightarrow> Reduce[a,b]" and |
84 trans_red: "\<And>a b c A. \<lbrakk>a = b : A; Reduce[b,c]\<rbrakk> \<Longrightarrow> a = c : A" and |
87 trans_red: "\<And>a b c A. \<lbrakk>a = b : A; Reduce[b,c]\<rbrakk> \<Longrightarrow> a = c : A" and |
85 |
88 |
86 (*Reflexivity*) |
89 \<comment> \<open>Reflexivity\<close> |
87 |
90 |
88 refl_type: "\<And>A. A type \<Longrightarrow> A = A" and |
91 refl_type: "\<And>A. A type \<Longrightarrow> A = A" and |
89 refl_elem: "\<And>a A. a : A \<Longrightarrow> a = a : A" and |
92 refl_elem: "\<And>a A. a : A \<Longrightarrow> a = a : A" and |
90 |
93 |
91 (*Symmetry*) |
94 \<comment> \<open>Symmetry\<close> |
92 |
95 |
93 sym_type: "\<And>A B. A = B \<Longrightarrow> B = A" and |
96 sym_type: "\<And>A B. A = B \<Longrightarrow> B = A" and |
94 sym_elem: "\<And>a b A. a = b : A \<Longrightarrow> b = a : A" and |
97 sym_elem: "\<And>a b A. a = b : A \<Longrightarrow> b = a : A" and |
95 |
98 |
96 (*Transitivity*) |
99 \<comment> \<open>Transitivity\<close> |
97 |
100 |
98 trans_type: "\<And>A B C. \<lbrakk>A = B; B = C\<rbrakk> \<Longrightarrow> A = C" and |
101 trans_type: "\<And>A B C. \<lbrakk>A = B; B = C\<rbrakk> \<Longrightarrow> A = C" and |
99 trans_elem: "\<And>a b c A. \<lbrakk>a = b : A; b = c : A\<rbrakk> \<Longrightarrow> a = c : A" and |
102 trans_elem: "\<And>a b c A. \<lbrakk>a = b : A; b = c : A\<rbrakk> \<Longrightarrow> a = c : A" and |
100 |
103 |
101 equal_types: "\<And>a A B. \<lbrakk>a : A; A = B\<rbrakk> \<Longrightarrow> a : B" and |
104 equal_types: "\<And>a A B. \<lbrakk>a : A; A = B\<rbrakk> \<Longrightarrow> a : B" and |
102 equal_typesL: "\<And>a b A B. \<lbrakk>a = b : A; A = B\<rbrakk> \<Longrightarrow> a = b : B" and |
105 equal_typesL: "\<And>a b A B. \<lbrakk>a = b : A; A = B\<rbrakk> \<Longrightarrow> a = b : B" and |
103 |
106 |
104 (*Substitution*) |
107 \<comment> \<open>Substitution\<close> |
105 |
108 |
106 subst_type: "\<And>a A B. \<lbrakk>a : A; \<And>z. z:A \<Longrightarrow> B(z) type\<rbrakk> \<Longrightarrow> B(a) type" and |
109 subst_type: "\<And>a A B. \<lbrakk>a : A; \<And>z. z:A \<Longrightarrow> B(z) type\<rbrakk> \<Longrightarrow> B(a) type" and |
107 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 |
110 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 |
108 |
111 |
109 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 |
112 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 |
110 subst_elemL: |
113 subst_elemL: |
111 "\<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 |
114 "\<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 |
112 |
115 |
113 |
116 |
114 (*The type N -- natural numbers*) |
117 \<comment> \<open>The type \<open>N\<close> -- natural numbers\<close> |
115 |
118 |
116 NF: "N type" and |
119 NF: "N type" and |
117 NI0: "0 : N" and |
120 NI0: "0 : N" and |
118 NI_succ: "\<And>a. a : N \<Longrightarrow> succ(a) : N" and |
121 NI_succ: "\<And>a. a : N \<Longrightarrow> succ(a) : N" and |
119 NI_succL: "\<And>a b. a = b : N \<Longrightarrow> succ(a) = succ(b) : N" and |
122 NI_succL: "\<And>a b. a = b : N \<Longrightarrow> succ(a) = succ(b) : N" and |
215 \<And>x. x:A \<Longrightarrow> c(x): C(inl(x)); |
218 \<And>x. x:A \<Longrightarrow> c(x): C(inl(x)); |
216 \<And>y. y:B \<Longrightarrow> d(y): C(inr(y))\<rbrakk> |
219 \<And>y. y:B \<Longrightarrow> d(y): C(inr(y))\<rbrakk> |
217 \<Longrightarrow> when(inr(b), \<lambda>x. c(x), \<lambda>y. d(y)) = d(b) : C(inr(b))" and |
220 \<Longrightarrow> when(inr(b), \<lambda>x. c(x), \<lambda>y. d(y)) = d(b) : C(inr(b))" and |
218 |
221 |
219 |
222 |
220 (*The type Eq*) |
223 \<comment> \<open>The type \<open>Eq\<close>\<close> |
221 |
224 |
222 EqF: "\<And>a b A. \<lbrakk>A type; a : A; b : A\<rbrakk> \<Longrightarrow> Eq(A,a,b) type" and |
225 EqF: "\<And>a b A. \<lbrakk>A type; a : A; b : A\<rbrakk> \<Longrightarrow> Eq(A,a,b) type" and |
223 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 |
226 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 |
224 EqI: "\<And>a b A. a = b : A \<Longrightarrow> eq : Eq(A,a,b)" and |
227 EqI: "\<And>a b A. a = b : A \<Longrightarrow> eq : Eq(A,a,b)" and |
225 EqE: "\<And>p a b A. p : Eq(A,a,b) \<Longrightarrow> a = b : A" and |
228 EqE: "\<And>p a b A. p : Eq(A,a,b) \<Longrightarrow> a = b : A" and |
226 |
229 |
227 (*By equality of types, can prove C(p) from C(eq), an elimination rule*) |
230 \<comment> \<open>By equality of types, can prove \<open>C(p)\<close> from \<open>C(eq)\<close>, an elimination rule\<close> |
228 EqC: "\<And>p a b A. p : Eq(A,a,b) \<Longrightarrow> p = eq : Eq(A,a,b)" and |
231 EqC: "\<And>p a b A. p : Eq(A,a,b) \<Longrightarrow> p = eq : Eq(A,a,b)" and |
229 |
232 |
230 (*The type F*) |
233 |
|
234 \<comment> \<open>The type \<open>F\<close>\<close> |
231 |
235 |
232 FF: "F type" and |
236 FF: "F type" and |
233 FE: "\<And>p C. \<lbrakk>p: F; C type\<rbrakk> \<Longrightarrow> contr(p) : C" and |
237 FE: "\<And>p C. \<lbrakk>p: F; C type\<rbrakk> \<Longrightarrow> contr(p) : C" and |
234 FEL: "\<And>p q C. \<lbrakk>p = q : F; C type\<rbrakk> \<Longrightarrow> contr(p) = contr(q) : C" and |
238 FEL: "\<And>p q C. \<lbrakk>p = q : F; C type\<rbrakk> \<Longrightarrow> contr(p) = contr(q) : C" and |
235 |
239 |
236 (*The type T |
240 |
237 Martin-Löf's book (page 68) discusses elimination and computation. |
241 \<comment> \<open>The type T\<close> |
238 Elimination can be derived by computation and equality of types, |
242 \<comment> \<open> |
239 but with an extra premise C(x) type x:T. |
243 Martin-Löf's book (page 68) discusses elimination and computation. |
240 Also computation can be derived from elimination. *) |
244 Elimination can be derived by computation and equality of types, |
|
245 but with an extra premise \<open>C(x)\<close> type \<open>x:T\<close>. |
|
246 Also computation can be derived from elimination. |
|
247 \<close> |
241 |
248 |
242 TF: "T type" and |
249 TF: "T type" and |
243 TI: "tt : T" and |
250 TI: "tt : T" and |
244 TE: "\<And>p c C. \<lbrakk>p : T; c : C(tt)\<rbrakk> \<Longrightarrow> c : C(p)" and |
251 TE: "\<And>p c C. \<lbrakk>p : T; c : C(tt)\<rbrakk> \<Longrightarrow> c : C(p)" and |
245 TEL: "\<And>p q c d C. \<lbrakk>p = q : T; c = d : C(tt)\<rbrakk> \<Longrightarrow> c = d : C(p)" and |
252 TEL: "\<And>p q c d C. \<lbrakk>p = q : T; c = d : C(tt)\<rbrakk> \<Longrightarrow> c = d : C(p)" and |
246 TC: "\<And>p. p : T \<Longrightarrow> p = tt : T" |
253 TC: "\<And>p. p : T \<Longrightarrow> p = tt : T" |
247 |
254 |
248 |
255 |
249 subsection "Tactics and derived rules for Constructive Type Theory" |
256 subsection "Tactics and derived rules for Constructive Type Theory" |
250 |
257 |
251 (*Formation rules*) |
258 text \<open>Formation rules.\<close> |
252 lemmas form_rls = NF ProdF SumF PlusF EqF FF TF |
259 lemmas form_rls = NF ProdF SumF PlusF EqF FF TF |
253 and formL_rls = ProdFL SumFL PlusFL EqFL |
260 and formL_rls = ProdFL SumFL PlusFL EqFL |
254 |
261 |
255 (*Introduction rules |
262 text \<open> |
256 OMITTED: EqI, because its premise is an eqelem, not an elem*) |
263 Introduction rules. OMITTED: |
|
264 \<^item> \<open>EqI\<close>, because its premise is an \<open>eqelem\<close>, not an \<open>elem\<close>. |
|
265 \<close> |
257 lemmas intr_rls = NI0 NI_succ ProdI SumI PlusI_inl PlusI_inr TI |
266 lemmas intr_rls = NI0 NI_succ ProdI SumI PlusI_inl PlusI_inr TI |
258 and intrL_rls = NI_succL ProdIL SumIL PlusI_inlL PlusI_inrL |
267 and intrL_rls = NI_succL ProdIL SumIL PlusI_inlL PlusI_inrL |
259 |
268 |
260 (*Elimination rules |
269 text \<open> |
261 OMITTED: EqE, because its conclusion is an eqelem, not an elem |
270 Elimination rules. OMITTED: |
262 TE, because it does not involve a constructor *) |
271 \<^item> \<open>EqE\<close>, because its conclusion is an \<open>eqelem\<close>, not an \<open>elem\<close> |
|
272 \<^item> \<open>TE\<close>, because it does not involve a constructor. |
|
273 \<close> |
263 lemmas elim_rls = NE ProdE SumE PlusE FE |
274 lemmas elim_rls = NE ProdE SumE PlusE FE |
264 and elimL_rls = NEL ProdEL SumEL PlusEL FEL |
275 and elimL_rls = NEL ProdEL SumEL PlusEL FEL |
265 |
276 |
266 (*OMITTED: eqC are TC because they make rewriting loop: p = un = un = ... *) |
277 text \<open>OMITTED: \<open>eqC\<close> are \<open>TC\<close> because they make rewriting loop: \<open>p = un = un = \<dots>\<close>\<close> |
267 lemmas comp_rls = NC0 NC_succ ProdC SumC PlusC_inl PlusC_inr |
278 lemmas comp_rls = NC0 NC_succ ProdC SumC PlusC_inl PlusC_inr |
268 |
279 |
269 (*rules with conclusion a:A, an elem judgement*) |
280 text \<open>Rules with conclusion \<open>a:A\<close>, an elem judgement.\<close> |
270 lemmas element_rls = intr_rls elim_rls |
281 lemmas element_rls = intr_rls elim_rls |
271 |
282 |
272 (*Definitions are (meta)equality axioms*) |
283 text \<open>Definitions are (meta)equality axioms.\<close> |
273 lemmas basic_defs = fst_def snd_def |
284 lemmas basic_defs = fst_def snd_def |
274 |
285 |
275 (*Compare with standard version: B is applied to UNSIMPLIFIED expression! *) |
286 text \<open>Compare with standard version: \<open>B\<close> is applied to UNSIMPLIFIED expression!\<close> |
276 lemma SumIL2: "\<lbrakk>c = a : A; d = b : B(a)\<rbrakk> \<Longrightarrow> <c,d> = <a,b> : Sum(A,B)" |
287 lemma SumIL2: "\<lbrakk>c = a : A; d = b : B(a)\<rbrakk> \<Longrightarrow> <c,d> = <a,b> : Sum(A,B)" |
277 apply (rule sym_elem) |
288 apply (rule sym_elem) |
278 apply (rule SumIL) |
289 apply (rule SumIL) |
279 apply (rule_tac [!] sym_elem) |
290 apply (rule_tac [!] sym_elem) |
280 apply assumption+ |
291 apply assumption+ |
281 done |
292 done |
282 |
293 |
283 lemmas intrL2_rls = NI_succL ProdIL SumIL2 PlusI_inlL PlusI_inrL |
294 lemmas intrL2_rls = NI_succL ProdIL SumIL2 PlusI_inlL PlusI_inrL |
284 |
295 |
285 (*Exploit p:Prod(A,B) to create the assumption z:B(a). |
296 text \<open> |
286 A more natural form of product elimination. *) |
297 Exploit \<open>p:Prod(A,B)\<close> to create the assumption \<open>z:B(a)\<close>. |
|
298 A more natural form of product elimination. |
|
299 \<close> |
287 lemma subst_prodE: |
300 lemma subst_prodE: |
288 assumes "p: Prod(A,B)" |
301 assumes "p: Prod(A,B)" |
289 and "a: A" |
302 and "a: A" |
290 and "\<And>z. z: B(a) \<Longrightarrow> c(z): C(z)" |
303 and "\<And>z. z: B(a) \<Longrightarrow> c(z): C(z)" |
291 shows "c(p`a): C(p`a)" |
304 shows "c(p`a): C(p`a)" |
292 apply (rule assms ProdE)+ |
305 by (rule assms ProdE)+ |
293 done |
|
294 |
306 |
295 |
307 |
296 subsection \<open>Tactics for type checking\<close> |
308 subsection \<open>Tactics for type checking\<close> |
297 |
309 |
298 ML \<open> |
310 ML \<open> |
299 |
|
300 local |
311 local |
301 |
312 |
302 fun is_rigid_elem (Const(@{const_name Elem},_) $ a $ _) = not(is_Var (head_of a)) |
313 fun is_rigid_elem (Const(@{const_name Elem},_) $ a $ _) = not(is_Var (head_of a)) |
303 | is_rigid_elem (Const(@{const_name Eqelem},_) $ a $ _ $ _) = not(is_Var (head_of a)) |
314 | is_rigid_elem (Const(@{const_name Eqelem},_) $ a $ _ $ _) = not(is_Var (head_of a)) |
304 | is_rigid_elem (Const(@{const_name Type},_) $ a) = not(is_Var (head_of a)) |
315 | is_rigid_elem (Const(@{const_name Type},_) $ a) = not(is_Var (head_of a)) |
305 | is_rigid_elem _ = false |
316 | is_rigid_elem _ = false |
306 |
317 |
307 in |
318 in |
308 |
319 |
309 (*Try solving a:A or a=b:A by assumption provided a is rigid!*) |
320 (*Try solving a:A or a=b:A by assumption provided a is rigid!*) |
310 fun test_assume_tac ctxt = SUBGOAL(fn (prem,i) => |
321 fun test_assume_tac ctxt = SUBGOAL (fn (prem, i) => |
311 if is_rigid_elem (Logic.strip_assums_concl prem) |
322 if is_rigid_elem (Logic.strip_assums_concl prem) |
312 then assume_tac ctxt i else no_tac) |
323 then assume_tac ctxt i else no_tac) |
313 |
324 |
314 fun ASSUME ctxt tf i = test_assume_tac ctxt i ORELSE tf i |
325 fun ASSUME ctxt tf i = test_assume_tac ctxt i ORELSE tf i |
315 |
326 |
316 end; |
327 end |
317 |
328 \<close> |
318 \<close> |
329 |
319 |
330 text \<open> |
320 (*For simplification: type formation and checking, |
331 For simplification: type formation and checking, |
321 but no equalities between terms*) |
332 but no equalities between terms. |
|
333 \<close> |
322 lemmas routine_rls = form_rls formL_rls refl_type element_rls |
334 lemmas routine_rls = form_rls formL_rls refl_type element_rls |
323 |
335 |
324 ML \<open> |
336 ML \<open> |
325 local |
|
326 val equal_rls = @{thms form_rls} @ @{thms element_rls} @ @{thms intrL_rls} @ |
|
327 @{thms elimL_rls} @ @{thms refl_elem} |
|
328 in |
|
329 |
|
330 fun routine_tac rls ctxt prems = |
337 fun routine_tac rls ctxt prems = |
331 ASSUME ctxt (filt_resolve_from_net_tac ctxt 4 (Tactic.build_net (prems @ rls))); |
338 ASSUME ctxt (filt_resolve_from_net_tac ctxt 4 (Tactic.build_net (prems @ rls))); |
332 |
339 |
333 (*Solve all subgoals "A type" using formation rules. *) |
340 (*Solve all subgoals "A type" using formation rules. *) |
334 val form_net = Tactic.build_net @{thms form_rls}; |
341 val form_net = Tactic.build_net @{thms form_rls}; |
352 in REPEAT_FIRST (ASSUME ctxt tac) end |
359 in REPEAT_FIRST (ASSUME ctxt tac) end |
353 |
360 |
354 (*Equality proving: solve a=b:A (where a is rigid) by long rules. *) |
361 (*Equality proving: solve a=b:A (where a is rigid) by long rules. *) |
355 fun equal_tac ctxt thms = |
362 fun equal_tac ctxt thms = |
356 REPEAT_FIRST |
363 REPEAT_FIRST |
357 (ASSUME ctxt (filt_resolve_from_net_tac ctxt 3 (Tactic.build_net (thms @ equal_rls)))) |
364 (ASSUME ctxt |
358 |
365 (filt_resolve_from_net_tac ctxt 3 |
359 end |
366 (Tactic.build_net (thms @ @{thms form_rls element_rls intrL_rls elimL_rls refl_elem})))) |
360 \<close> |
367 \<close> |
361 |
368 |
362 method_setup form = \<open>Scan.succeed (fn ctxt => SIMPLE_METHOD (form_tac ctxt))\<close> |
369 method_setup form = \<open>Scan.succeed (fn ctxt => SIMPLE_METHOD (form_tac ctxt))\<close> |
363 method_setup typechk = \<open>Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD (typechk_tac ctxt ths))\<close> |
370 method_setup typechk = \<open>Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD (typechk_tac ctxt ths))\<close> |
364 method_setup intr = \<open>Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD (intr_tac ctxt ths))\<close> |
371 method_setup intr = \<open>Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD (intr_tac ctxt ths))\<close> |
365 method_setup equal = \<open>Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD (equal_tac ctxt ths))\<close> |
372 method_setup equal = \<open>Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD (equal_tac ctxt ths))\<close> |
366 |
373 |
367 |
374 |
368 subsection \<open>Simplification\<close> |
375 subsection \<open>Simplification\<close> |
369 |
376 |
370 (*To simplify the type in a goal*) |
377 text \<open>To simplify the type in a goal.\<close> |
371 lemma replace_type: "\<lbrakk>B = A; a : A\<rbrakk> \<Longrightarrow> a : B" |
378 lemma replace_type: "\<lbrakk>B = A; a : A\<rbrakk> \<Longrightarrow> a : B" |
372 apply (rule equal_types) |
379 apply (rule equal_types) |
373 apply (rule_tac [2] sym_type) |
380 apply (rule_tac [2] sym_type) |
374 apply assumption+ |
381 apply assumption+ |
375 done |
382 done |
376 |
383 |
377 (*Simplify the parameter of a unary type operator.*) |
384 text \<open>Simplify the parameter of a unary type operator.\<close> |
378 lemma subst_eqtyparg: |
385 lemma subst_eqtyparg: |
379 assumes 1: "a=c : A" |
386 assumes 1: "a=c : A" |
380 and 2: "\<And>z. z:A \<Longrightarrow> B(z) type" |
387 and 2: "\<And>z. z:A \<Longrightarrow> B(z) type" |
381 shows "B(a)=B(c)" |
388 shows "B(a) = B(c)" |
382 apply (rule subst_typeL) |
389 apply (rule subst_typeL) |
383 apply (rule_tac [2] refl_type) |
390 apply (rule_tac [2] refl_type) |
384 apply (rule 1) |
391 apply (rule 1) |
385 apply (erule 2) |
392 apply (erule 2) |
386 done |
393 done |
387 |
394 |
388 (*Simplification rules for Constructive Type Theory*) |
395 text \<open>Simplification rules for Constructive Type Theory.\<close> |
389 lemmas reduction_rls = comp_rls [THEN trans_elem] |
396 lemmas reduction_rls = comp_rls [THEN trans_elem] |
390 |
397 |
391 ML \<open> |
398 ML \<open> |
392 (*Converts each goal "e : Eq(A,a,b)" into "a=b:A" for simplification. |
399 (*Converts each goal "e : Eq(A,a,b)" into "a=b:A" for simplification. |
393 Uses other intro rules to avoid changing flexible goals.*) |
400 Uses other intro rules to avoid changing flexible goals.*) |