author | nipkow |
Sun, 25 Jan 2004 00:42:22 +0100 | |
changeset 14360 | e654599b114e |
parent 13630 | a013a9dd370f |
child 14401 | 477380c74c1d |
permissions | -rw-r--r-- |
2525 | 1 |
(* Title: HOL/MiniML/Type.thy |
2 |
ID: $Id$ |
|
3 |
Author: Wolfgang Naraschewski and Tobias Nipkow |
|
4 |
Copyright 1996 TU Muenchen |
|
5 |
*) |
|
1300 | 6 |
|
7 |
Addsimps [mgu_eq,mgu_mg,mgu_free]; |
|
8 |
||
2525 | 9 |
|
10 |
(* lemmata for make scheme *) |
|
11 |
||
5069 | 12 |
Goal "mk_scheme t = sch1 =-> sch2 --> (? t1 t2. sch1 = mk_scheme t1 & sch2 = mk_scheme t2)"; |
5184 | 13 |
by (induct_tac "t" 1); |
2525 | 14 |
by (Simp_tac 1); |
15 |
by (Asm_full_simp_tac 1); |
|
16 |
by (Fast_tac 1); |
|
17 |
qed_spec_mp "mk_scheme_Fun"; |
|
1300 | 18 |
|
5069 | 19 |
Goal "!t'. mk_scheme t = mk_scheme t' --> t=t'"; |
5184 | 20 |
by (induct_tac "t" 1); |
3018 | 21 |
by (rtac allI 1); |
5184 | 22 |
by (induct_tac "t'" 1); |
3018 | 23 |
by (Simp_tac 1); |
24 |
by (Asm_full_simp_tac 1); |
|
25 |
by (rtac allI 1); |
|
5184 | 26 |
by (induct_tac "t'" 1); |
3018 | 27 |
by (Simp_tac 1); |
28 |
by (Asm_full_simp_tac 1); |
|
2525 | 29 |
qed_spec_mp "mk_scheme_injective"; |
30 |
||
5118 | 31 |
Goal "free_tv (mk_scheme t) = free_tv t"; |
5184 | 32 |
by (induct_tac "t" 1); |
2525 | 33 |
by (ALLGOALS Asm_simp_tac); |
34 |
qed "free_tv_mk_scheme"; |
|
35 |
||
36 |
Addsimps [free_tv_mk_scheme]; |
|
37 |
||
5118 | 38 |
Goal "$ S (mk_scheme t) = mk_scheme ($ S t)"; |
5184 | 39 |
by (induct_tac "t" 1); |
1300 | 40 |
by (ALLGOALS Asm_simp_tac); |
2525 | 41 |
qed "subst_mk_scheme"; |
42 |
||
43 |
Addsimps [subst_mk_scheme]; |
|
44 |
||
1300 | 45 |
|
2525 | 46 |
(* constructor laws for app_subst *) |
47 |
||
5069 | 48 |
Goalw [app_subst_list] |
2525 | 49 |
"$ S [] = []"; |
50 |
by (Simp_tac 1); |
|
51 |
qed "app_subst_Nil"; |
|
52 |
||
5069 | 53 |
Goalw [app_subst_list] |
2525 | 54 |
"$ S (x#l) = ($ S x)#($ S l)"; |
55 |
by (Simp_tac 1); |
|
56 |
qed "app_subst_Cons"; |
|
57 |
||
58 |
Addsimps [app_subst_Nil,app_subst_Cons]; |
|
59 |
||
60 |
||
61 |
(* constructor laws for new_tv *) |
|
62 |
||
5069 | 63 |
Goalw [new_tv_def] |
2525 | 64 |
"new_tv n (TVar m) = (m<n)"; |
4089 | 65 |
by (fast_tac (HOL_cs addss simpset()) 1); |
2525 | 66 |
qed "new_tv_TVar"; |
67 |
||
5069 | 68 |
Goalw [new_tv_def] |
2525 | 69 |
"new_tv n (FVar m) = (m<n)"; |
4089 | 70 |
by (fast_tac (HOL_cs addss simpset()) 1); |
2525 | 71 |
qed "new_tv_FVar"; |
72 |
||
5069 | 73 |
Goalw [new_tv_def] |
2525 | 74 |
"new_tv n (BVar m) = True"; |
75 |
by (Simp_tac 1); |
|
76 |
qed "new_tv_BVar"; |
|
77 |
||
5069 | 78 |
Goalw [new_tv_def] |
2525 | 79 |
"new_tv n (t1 -> t2) = (new_tv n t1 & new_tv n t2)"; |
4089 | 80 |
by (fast_tac (HOL_cs addss simpset()) 1); |
2525 | 81 |
qed "new_tv_Fun"; |
1300 | 82 |
|
5069 | 83 |
Goalw [new_tv_def] |
2525 | 84 |
"new_tv n (t1 =-> t2) = (new_tv n t1 & new_tv n t2)"; |
4089 | 85 |
by (fast_tac (HOL_cs addss simpset()) 1); |
2525 | 86 |
qed "new_tv_Fun2"; |
87 |
||
5069 | 88 |
Goalw [new_tv_def] |
2525 | 89 |
"new_tv n []"; |
2031 | 90 |
by (Simp_tac 1); |
2525 | 91 |
qed "new_tv_Nil"; |
92 |
||
5069 | 93 |
Goalw [new_tv_def] |
2525 | 94 |
"new_tv n (x#l) = (new_tv n x & new_tv n l)"; |
4089 | 95 |
by (fast_tac (HOL_cs addss simpset()) 1); |
2525 | 96 |
qed "new_tv_Cons"; |
97 |
||
5118 | 98 |
Goalw [new_tv_def] "new_tv n TVar"; |
2525 | 99 |
by (strip_tac 1); |
4089 | 100 |
by (asm_full_simp_tac (simpset() addsimps [free_tv_subst,dom_def,cod_def]) 1); |
2525 | 101 |
qed "new_tv_TVar_subst"; |
102 |
||
103 |
Addsimps [new_tv_TVar,new_tv_FVar,new_tv_BVar,new_tv_Fun,new_tv_Fun2,new_tv_Nil,new_tv_Cons,new_tv_TVar_subst]; |
|
104 |
||
5069 | 105 |
Goalw [id_subst_def,new_tv_def,free_tv_subst,dom_def,cod_def] |
2525 | 106 |
"new_tv n id_subst"; |
3018 | 107 |
by (Simp_tac 1); |
2525 | 108 |
qed "new_tv_id_subst"; |
109 |
Addsimps[new_tv_id_subst]; |
|
110 |
||
5069 | 111 |
Goal "new_tv n (sch::type_scheme) --> \ |
5118 | 112 |
\ $(%k. if k<n then S k else S' k) sch = $S sch"; |
5184 | 113 |
by (induct_tac "sch" 1); |
3018 | 114 |
by (ALLGOALS Asm_simp_tac); |
2625 | 115 |
qed "new_if_subst_type_scheme"; |
116 |
Addsimps [new_if_subst_type_scheme]; |
|
117 |
||
5069 | 118 |
Goal "new_tv n (A::type_scheme list) --> \ |
5118 | 119 |
\ $(%k. if k<n then S k else S' k) A = $S A"; |
5184 | 120 |
by (induct_tac "A" 1); |
3018 | 121 |
by (ALLGOALS Asm_simp_tac); |
2625 | 122 |
qed "new_if_subst_type_scheme_list"; |
123 |
Addsimps [new_if_subst_type_scheme_list]; |
|
124 |
||
2525 | 125 |
|
126 |
(* constructor laws for dom and cod *) |
|
1751 | 127 |
|
5069 | 128 |
Goalw [dom_def,id_subst_def,empty_def] |
1300 | 129 |
"dom id_subst = {}"; |
130 |
by (Simp_tac 1); |
|
131 |
qed "dom_id_subst"; |
|
132 |
Addsimps [dom_id_subst]; |
|
133 |
||
5069 | 134 |
Goalw [cod_def] |
1300 | 135 |
"cod id_subst = {}"; |
136 |
by (Simp_tac 1); |
|
137 |
qed "cod_id_subst"; |
|
138 |
Addsimps [cod_id_subst]; |
|
139 |
||
2525 | 140 |
|
141 |
(* lemmata for free_tv *) |
|
142 |
||
5069 | 143 |
Goalw [free_tv_subst] |
1300 | 144 |
"free_tv id_subst = {}"; |
145 |
by (Simp_tac 1); |
|
146 |
qed "free_tv_id_subst"; |
|
147 |
Addsimps [free_tv_id_subst]; |
|
148 |
||
5118 | 149 |
Goal "!n. n < length A --> x : free_tv (A!n) --> x : free_tv A"; |
5184 | 150 |
by (induct_tac "A" 1); |
2525 | 151 |
by (Asm_full_simp_tac 1); |
152 |
by (rtac allI 1); |
|
9747 | 153 |
by (induct_thm_tac nat_induct "n" 1); |
2525 | 154 |
by (Asm_full_simp_tac 1); |
155 |
by (Asm_full_simp_tac 1); |
|
156 |
qed_spec_mp "free_tv_nth_A_impl_free_tv_A"; |
|
157 |
||
158 |
Addsimps [free_tv_nth_A_impl_free_tv_A]; |
|
159 |
||
5118 | 160 |
Goal "!nat. nat < length A --> x : free_tv (A!nat) --> x : free_tv A"; |
5184 | 161 |
by (induct_tac "A" 1); |
2525 | 162 |
by (Asm_full_simp_tac 1); |
163 |
by (rtac allI 1); |
|
9747 | 164 |
by (induct_thm_tac nat_induct "nat" 1); |
2525 | 165 |
by (strip_tac 1); |
166 |
by (Asm_full_simp_tac 1); |
|
167 |
by (Simp_tac 1); |
|
168 |
qed_spec_mp "free_tv_nth_nat_A"; |
|
169 |
||
170 |
||
171 |
(* if two substitutions yield the same result if applied to a type |
|
172 |
structure the substitutions coincide on the free type variables |
|
173 |
occurring in the type structure *) |
|
174 |
||
5118 | 175 |
Goal "(!x:free_tv t. (S x) = (S' x)) --> $ S (t::typ) = $ S' t"; |
5184 | 176 |
by (induct_tac "t" 1); |
2525 | 177 |
by (Simp_tac 1); |
178 |
by (Asm_full_simp_tac 1); |
|
179 |
qed_spec_mp "typ_substitutions_only_on_free_variables"; |
|
180 |
||
5118 | 181 |
Goal "(!n. n:(free_tv t) --> S1 n = S2 n) ==> $ S1 (t::typ) = $ S2 t"; |
2525 | 182 |
by (rtac typ_substitutions_only_on_free_variables 1); |
4089 | 183 |
by (simp_tac (simpset() addsimps [Ball_def]) 1); |
2525 | 184 |
qed "eq_free_eq_subst_te"; |
185 |
||
5118 | 186 |
Goal "(!x:free_tv sch. (S x) = (S' x)) --> $ S (sch::type_scheme) = $ S' sch"; |
5184 | 187 |
by (induct_tac "sch" 1); |
2525 | 188 |
by (Simp_tac 1); |
189 |
by (Simp_tac 1); |
|
190 |
by (Asm_full_simp_tac 1); |
|
191 |
qed_spec_mp "scheme_substitutions_only_on_free_variables"; |
|
192 |
||
5069 | 193 |
Goal |
5118 | 194 |
"(!n. n:(free_tv sch) --> S1 n = S2 n) ==> $ S1 (sch::type_scheme) = $ S2 sch"; |
2525 | 195 |
by (rtac scheme_substitutions_only_on_free_variables 1); |
4089 | 196 |
by (simp_tac (simpset() addsimps [Ball_def]) 1); |
2525 | 197 |
qed "eq_free_eq_subst_type_scheme"; |
198 |
||
5069 | 199 |
Goal |
2525 | 200 |
"(!n. n:(free_tv A) --> S1 n = S2 n) --> $S1 (A::type_scheme list) = $S2 A"; |
5184 | 201 |
by (induct_tac "A" 1); |
2525 | 202 |
(* case [] *) |
4089 | 203 |
by (fast_tac (HOL_cs addss simpset()) 1); |
2525 | 204 |
(* case x#xl *) |
4089 | 205 |
by (fast_tac (HOL_cs addIs [eq_free_eq_subst_type_scheme] addss (simpset())) 1); |
2525 | 206 |
qed_spec_mp "eq_free_eq_subst_scheme_list"; |
207 |
||
5118 | 208 |
Goal "((!x:A. (P x)) --> Q) ==> ((!x:A Un B. (P x)) --> Q)"; |
2525 | 209 |
by (Fast_tac 1); |
210 |
val weaken_asm_Un = result (); |
|
211 |
||
5118 | 212 |
Goal "(!x:free_tv A. (S x) = (S' x)) --> $ S (A::type_scheme list) = $ S' A"; |
5184 | 213 |
by (induct_tac "A" 1); |
2525 | 214 |
by (Simp_tac 1); |
215 |
by (Asm_full_simp_tac 1); |
|
216 |
by (rtac weaken_asm_Un 1); |
|
217 |
by (strip_tac 1); |
|
218 |
by (etac scheme_substitutions_only_on_free_variables 1); |
|
219 |
qed_spec_mp "scheme_list_substitutions_only_on_free_variables"; |
|
220 |
||
5069 | 221 |
Goal |
2525 | 222 |
"$ S1 (t::typ) = $ S2 t --> n:(free_tv t) --> S1 n = S2 n"; |
5184 | 223 |
by (induct_tac "t" 1); |
2525 | 224 |
(* case TVar n *) |
4089 | 225 |
by (fast_tac (HOL_cs addss simpset()) 1); |
2525 | 226 |
(* case Fun t1 t2 *) |
4089 | 227 |
by (fast_tac (HOL_cs addss simpset()) 1); |
2525 | 228 |
qed_spec_mp "eq_subst_te_eq_free"; |
229 |
||
5069 | 230 |
Goal |
2525 | 231 |
"$ S1 (sch::type_scheme) = $ S2 sch --> n:(free_tv sch) --> S1 n = S2 n"; |
5184 | 232 |
by (induct_tac "sch" 1); |
2525 | 233 |
(* case TVar n *) |
234 |
by (Asm_simp_tac 1); |
|
235 |
(* case BVar n *) |
|
236 |
by (strip_tac 1); |
|
237 |
by (etac mk_scheme_injective 1); |
|
238 |
by (Asm_simp_tac 1); |
|
239 |
(* case Fun t1 t2 *) |
|
240 |
by (Asm_full_simp_tac 1); |
|
241 |
qed_spec_mp "eq_subst_type_scheme_eq_free"; |
|
242 |
||
5069 | 243 |
Goal |
2525 | 244 |
"$S1 (A::type_scheme list) = $S2 A --> n:(free_tv A) --> S1 n = S2 n"; |
5184 | 245 |
by (induct_tac "A" 1); |
2525 | 246 |
(* case [] *) |
4089 | 247 |
by (fast_tac (HOL_cs addss simpset()) 1); |
2525 | 248 |
(* case x#xl *) |
4089 | 249 |
by (fast_tac (HOL_cs addIs [eq_subst_type_scheme_eq_free] addss (simpset())) 1); |
2525 | 250 |
qed_spec_mp "eq_subst_scheme_list_eq_free"; |
251 |
||
5069 | 252 |
Goalw [free_tv_subst] |
5118 | 253 |
"v : cod S ==> v : free_tv S"; |
3385
f59e64fe4058
New statement and proof of free_tv_subst_var in order to cope with new
paulson
parents:
3018
diff
changeset
|
254 |
by (fast_tac set_cs 1); |
2525 | 255 |
qed "codD"; |
256 |
||
5069 | 257 |
Goalw [free_tv_subst,dom_def] |
5118 | 258 |
"x ~: free_tv S ==> S x = TVar x"; |
3385
f59e64fe4058
New statement and proof of free_tv_subst_var in order to cope with new
paulson
parents:
3018
diff
changeset
|
259 |
by (fast_tac set_cs 1); |
2525 | 260 |
qed "not_free_impl_id"; |
261 |
||
5069 | 262 |
Goalw [new_tv_def] |
5118 | 263 |
"[| new_tv n t; m:free_tv t |] ==> m<n"; |
3385
f59e64fe4058
New statement and proof of free_tv_subst_var in order to cope with new
paulson
parents:
3018
diff
changeset
|
264 |
by (fast_tac HOL_cs 1 ); |
2525 | 265 |
qed "free_tv_le_new_tv"; |
266 |
||
5069 | 267 |
Goalw [dom_def,cod_def,UNION_def,Bex_def] |
5118 | 268 |
"[| v : free_tv(S n); v~=n |] ==> v : cod S"; |
1300 | 269 |
by (Simp_tac 1); |
270 |
by (safe_tac (empty_cs addSIs [exI,conjI,notI])); |
|
1465 | 271 |
by (assume_tac 2); |
1300 | 272 |
by (Asm_full_simp_tac 1); |
273 |
qed "cod_app_subst"; |
|
274 |
Addsimps [cod_app_subst]; |
|
275 |
||
5118 | 276 |
Goal "free_tv (S (v::nat)) <= insert v (cod S)"; |
3385
f59e64fe4058
New statement and proof of free_tv_subst_var in order to cope with new
paulson
parents:
3018
diff
changeset
|
277 |
by (expand_case_tac "v:dom S" 1); |
4089 | 278 |
by (fast_tac (set_cs addss (simpset() addsimps [cod_def])) 1); |
279 |
by (fast_tac (set_cs addss (simpset() addsimps [dom_def])) 1); |
|
1300 | 280 |
qed "free_tv_subst_var"; |
281 |
||
5118 | 282 |
Goal "free_tv ($ S (t::typ)) <= cod S Un free_tv t"; |
5184 | 283 |
by (induct_tac "t" 1); |
1300 | 284 |
(* case TVar n *) |
4089 | 285 |
by (simp_tac (simpset() addsimps [free_tv_subst_var]) 1); |
1300 | 286 |
(* case Fun t1 t2 *) |
4089 | 287 |
by (fast_tac (set_cs addss simpset()) 1); |
1300 | 288 |
qed "free_tv_app_subst_te"; |
289 |
||
5118 | 290 |
Goal "free_tv ($ S (sch::type_scheme)) <= cod S Un free_tv sch"; |
5184 | 291 |
by (induct_tac "sch" 1); |
2525 | 292 |
(* case FVar n *) |
4089 | 293 |
by (simp_tac (simpset() addsimps [free_tv_subst_var]) 1); |
2525 | 294 |
(* case BVar n *) |
295 |
by (Simp_tac 1); |
|
296 |
(* case Fun t1 t2 *) |
|
4089 | 297 |
by (fast_tac (set_cs addss simpset()) 1); |
2525 | 298 |
qed "free_tv_app_subst_type_scheme"; |
299 |
||
5118 | 300 |
Goal "free_tv ($ S (A::type_scheme list)) <= cod S Un free_tv A"; |
5184 | 301 |
by (induct_tac "A" 1); |
1300 | 302 |
(* case [] *) |
303 |
by (Simp_tac 1); |
|
304 |
(* case a#al *) |
|
3385
f59e64fe4058
New statement and proof of free_tv_subst_var in order to cope with new
paulson
parents:
3018
diff
changeset
|
305 |
by (cut_facts_tac [free_tv_app_subst_type_scheme] 1); |
4089 | 306 |
by (fast_tac (set_cs addss simpset()) 1); |
2525 | 307 |
qed "free_tv_app_subst_scheme_list"; |
1300 | 308 |
|
5069 | 309 |
Goalw [free_tv_subst,dom_def] |
1521 | 310 |
"free_tv (%u::nat. $ s1 (s2 u) :: typ) <= \ |
311 |
\ free_tv s1 Un free_tv s2"; |
|
2513
d708d8cdc8e8
New miniscoping rules for the bounded quantifiers and UN/INT operators
paulson
parents:
2031
diff
changeset
|
312 |
by (fast_tac (set_cs addSDs [free_tv_app_subst_te RS subsetD, |
3008 | 313 |
free_tv_subst_var RS subsetD] |
4089 | 314 |
addss (simpset() delsimps bex_simps |
3008 | 315 |
addsimps [cod_def,dom_def])) 1); |
1521 | 316 |
qed "free_tv_comp_subst"; |
317 |
||
5069 | 318 |
Goalw [o_def] |
2525 | 319 |
"free_tv ($ S1 o S2) <= free_tv S1 Un free_tv (S2 :: nat => typ)"; |
320 |
by (rtac free_tv_comp_subst 1); |
|
321 |
qed "free_tv_o_subst"; |
|
322 |
||
5118 | 323 |
Goal "n : free_tv t --> free_tv (S n) <= free_tv ($ S t::typ)"; |
5184 | 324 |
by (induct_tac "t" 1); |
2525 | 325 |
by (Simp_tac 1); |
326 |
by (Simp_tac 1); |
|
327 |
by (Fast_tac 1); |
|
328 |
qed_spec_mp "free_tv_of_substitutions_extend_to_types"; |
|
329 |
||
5118 | 330 |
Goal "n : free_tv sch --> free_tv (S n) <= free_tv ($ S sch::type_scheme)"; |
5184 | 331 |
by (induct_tac "sch" 1); |
2525 | 332 |
by (Simp_tac 1); |
333 |
by (Simp_tac 1); |
|
334 |
by (Simp_tac 1); |
|
335 |
by (Fast_tac 1); |
|
336 |
qed_spec_mp "free_tv_of_substitutions_extend_to_schemes"; |
|
337 |
||
5118 | 338 |
Goal "n : free_tv A --> free_tv (S n) <= free_tv ($ S A::type_scheme list)"; |
5184 | 339 |
by (induct_tac "A" 1); |
2525 | 340 |
by (Simp_tac 1); |
341 |
by (Simp_tac 1); |
|
4089 | 342 |
by (fast_tac (claset() addDs [free_tv_of_substitutions_extend_to_schemes]) 1); |
2525 | 343 |
qed_spec_mp "free_tv_of_substitutions_extend_to_scheme_lists"; |
344 |
||
345 |
Addsimps [free_tv_of_substitutions_extend_to_scheme_lists]; |
|
346 |
||
5518 | 347 |
Goal "!!sch::type_scheme. (n : free_tv sch) = (n: set (free_tv_ML sch))"; |
5184 | 348 |
by (induct_tac "sch" 1); |
4686 | 349 |
by (ALLGOALS Asm_simp_tac); |
2525 | 350 |
qed "free_tv_ML_scheme"; |
351 |
||
5518 | 352 |
Goal "!!A::type_scheme list. (n : free_tv A) = (n: set (free_tv_ML A))"; |
5184 | 353 |
by (induct_tac "A" 1); |
2525 | 354 |
by (Simp_tac 1); |
4089 | 355 |
by (asm_simp_tac (simpset() addsimps [free_tv_ML_scheme]) 1); |
2525 | 356 |
qed "free_tv_ML_scheme_list"; |
357 |
||
358 |
||
359 |
(* lemmata for bound_tv *) |
|
360 |
||
5118 | 361 |
Goal "bound_tv (mk_scheme t) = {}"; |
5184 | 362 |
by (induct_tac "t" 1); |
2525 | 363 |
by (ALLGOALS Asm_simp_tac); |
364 |
qed "bound_tv_mk_scheme"; |
|
365 |
||
366 |
Addsimps [bound_tv_mk_scheme]; |
|
367 |
||
5069 | 368 |
Goal "!!sch::type_scheme. bound_tv ($ S sch) = bound_tv sch"; |
5184 | 369 |
by (induct_tac "sch" 1); |
2525 | 370 |
by (ALLGOALS Asm_simp_tac); |
371 |
qed "bound_tv_subst_scheme"; |
|
372 |
||
373 |
Addsimps [bound_tv_subst_scheme]; |
|
374 |
||
5069 | 375 |
Goal "!!A::type_scheme list. bound_tv ($ S A) = bound_tv A"; |
2525 | 376 |
by (rtac list.induct 1); |
377 |
by (Simp_tac 1); |
|
378 |
by (Asm_simp_tac 1); |
|
379 |
qed "bound_tv_subst_scheme_list"; |
|
380 |
||
381 |
Addsimps [bound_tv_subst_scheme_list]; |
|
382 |
||
383 |
||
384 |
(* lemmata for new_tv *) |
|
385 |
||
5069 | 386 |
Goalw [new_tv_def] |
2525 | 387 |
"new_tv n S = ((!m. n <= m --> (S m = TVar m)) & \ |
388 |
\ (! l. l < n --> new_tv n (S l) ))"; |
|
3385
f59e64fe4058
New statement and proof of free_tv_subst_var in order to cope with new
paulson
parents:
3018
diff
changeset
|
389 |
by (safe_tac HOL_cs ); |
2525 | 390 |
(* ==> *) |
4089 | 391 |
by (fast_tac (HOL_cs addDs [leD] addss (simpset() addsimps [free_tv_subst,dom_def])) 1); |
3385
f59e64fe4058
New statement and proof of free_tv_subst_var in order to cope with new
paulson
parents:
3018
diff
changeset
|
392 |
by (subgoal_tac "m:cod S | S l = TVar l" 1); |
f59e64fe4058
New statement and proof of free_tv_subst_var in order to cope with new
paulson
parents:
3018
diff
changeset
|
393 |
by (safe_tac HOL_cs ); |
4089 | 394 |
by (fast_tac (HOL_cs addDs [UnI2] addss (simpset() addsimps [free_tv_subst])) 1); |
3018 | 395 |
by (dres_inst_tac [("P","%x. m:free_tv x")] subst 1 THEN atac 1); |
396 |
by (Asm_full_simp_tac 1); |
|
4089 | 397 |
by (fast_tac (set_cs addss (simpset() addsimps [free_tv_subst,cod_def,dom_def])) 1); |
2525 | 398 |
(* <== *) |
3385
f59e64fe4058
New statement and proof of free_tv_subst_var in order to cope with new
paulson
parents:
3018
diff
changeset
|
399 |
by (rewrite_goals_tac [free_tv_subst,cod_def,dom_def] ); |
f59e64fe4058
New statement and proof of free_tv_subst_var in order to cope with new
paulson
parents:
3018
diff
changeset
|
400 |
by (safe_tac set_cs ); |
f59e64fe4058
New statement and proof of free_tv_subst_var in order to cope with new
paulson
parents:
3018
diff
changeset
|
401 |
by (cut_inst_tac [("m","m"),("n","n")] less_linear 1); |
f59e64fe4058
New statement and proof of free_tv_subst_var in order to cope with new
paulson
parents:
3018
diff
changeset
|
402 |
by (fast_tac (HOL_cs addSIs [less_or_eq_imp_le]) 1); |
f59e64fe4058
New statement and proof of free_tv_subst_var in order to cope with new
paulson
parents:
3018
diff
changeset
|
403 |
by (cut_inst_tac [("m","ma"),("n","n")] less_linear 1); |
f59e64fe4058
New statement and proof of free_tv_subst_var in order to cope with new
paulson
parents:
3018
diff
changeset
|
404 |
by (fast_tac (HOL_cs addSIs [less_or_eq_imp_le]) 1); |
2525 | 405 |
qed "new_tv_subst"; |
406 |
||
5518 | 407 |
Goal "new_tv n x = (!y:set x. new_tv n y)"; |
5184 | 408 |
by (induct_tac "x" 1); |
3018 | 409 |
by (ALLGOALS Asm_simp_tac); |
2525 | 410 |
qed "new_tv_list"; |
411 |
||
412 |
(* substitution affects only variables occurring freely *) |
|
5069 | 413 |
Goal |
2525 | 414 |
"new_tv n (t::typ) --> $(%x. if x=n then t' else S x) t = $S t"; |
5184 | 415 |
by (induct_tac "t" 1); |
4686 | 416 |
by (ALLGOALS Asm_simp_tac); |
2525 | 417 |
qed "subst_te_new_tv"; |
418 |
Addsimps [subst_te_new_tv]; |
|
419 |
||
5069 | 420 |
Goal |
2525 | 421 |
"new_tv n (sch::type_scheme) --> $(%x. if x=n then sch' else S x) sch = $S sch"; |
5184 | 422 |
by (induct_tac "sch" 1); |
4686 | 423 |
by (ALLGOALS Asm_simp_tac); |
2525 | 424 |
qed_spec_mp "subst_te_new_type_scheme"; |
425 |
Addsimps [subst_te_new_type_scheme]; |
|
426 |
||
5069 | 427 |
Goal |
2525 | 428 |
"new_tv n (A::type_scheme list) --> $(%x. if x=n then t else S x) A = $S A"; |
5184 | 429 |
by (induct_tac "A" 1); |
2525 | 430 |
by (ALLGOALS Asm_full_simp_tac); |
431 |
qed_spec_mp "subst_tel_new_scheme_list"; |
|
432 |
Addsimps [subst_tel_new_scheme_list]; |
|
433 |
||
434 |
(* all greater variables are also new *) |
|
5069 | 435 |
Goalw [new_tv_def] |
5118 | 436 |
"n<=m ==> new_tv n t ==> new_tv m t"; |
4153 | 437 |
by Safe_tac; |
2525 | 438 |
by (dtac spec 1); |
439 |
by (mp_tac 1); |
|
5983 | 440 |
by (Simp_tac 1); |
2525 | 441 |
qed "new_tv_le"; |
442 |
Addsimps [lessI RS less_imp_le RS new_tv_le]; |
|
443 |
||
5118 | 444 |
Goal "n<=m ==> new_tv n (t::typ) ==> new_tv m t"; |
4089 | 445 |
by (asm_simp_tac (simpset() addsimps [new_tv_le]) 1); |
2525 | 446 |
qed "new_tv_typ_le"; |
447 |
||
5118 | 448 |
Goal "n<=m ==> new_tv n (A::type_scheme list) ==> new_tv m A"; |
4089 | 449 |
by (asm_simp_tac (simpset() addsimps [new_tv_le]) 1); |
2525 | 450 |
qed "new_scheme_list_le"; |
451 |
||
5118 | 452 |
Goal "n<=m ==> new_tv n (S::subst) ==> new_tv m S"; |
4089 | 453 |
by (asm_simp_tac (simpset() addsimps [new_tv_le]) 1); |
2525 | 454 |
qed "new_tv_subst_le"; |
455 |
||
456 |
(* new_tv property remains if a substitution is applied *) |
|
5069 | 457 |
Goal |
5118 | 458 |
"[| n<m; new_tv m (S::subst) |] ==> new_tv m (S n)"; |
4089 | 459 |
by (asm_full_simp_tac (simpset() addsimps [new_tv_subst]) 1); |
2525 | 460 |
qed "new_tv_subst_var"; |
461 |
||
5069 | 462 |
Goal |
2525 | 463 |
"new_tv n S --> new_tv n (t::typ) --> new_tv n ($ S t)"; |
5184 | 464 |
by (induct_tac "t" 1); |
4089 | 465 |
by (ALLGOALS(fast_tac (HOL_cs addss (simpset() addsimps [new_tv_subst])))); |
2525 | 466 |
qed_spec_mp "new_tv_subst_te"; |
467 |
Addsimps [new_tv_subst_te]; |
|
468 |
||
5069 | 469 |
Goal "new_tv n S --> new_tv n (sch::type_scheme) --> new_tv n ($ S sch)"; |
5184 | 470 |
by (induct_tac "sch" 1); |
2525 | 471 |
by (ALLGOALS (Asm_full_simp_tac)); |
3008 | 472 |
by (rewtac new_tv_def); |
4089 | 473 |
by (simp_tac (simpset() addsimps [free_tv_subst,dom_def,cod_def]) 1); |
2525 | 474 |
by (strip_tac 1); |
475 |
by (case_tac "S nat = TVar nat" 1); |
|
476 |
by (Asm_full_simp_tac 1); |
|
477 |
by (dres_inst_tac [("x","m")] spec 1); |
|
478 |
by (Fast_tac 1); |
|
479 |
qed_spec_mp "new_tv_subst_type_scheme"; |
|
480 |
Addsimps [new_tv_subst_type_scheme]; |
|
481 |
||
5069 | 482 |
Goal |
2525 | 483 |
"new_tv n S --> new_tv n (A::type_scheme list) --> new_tv n ($ S A)"; |
5184 | 484 |
by (induct_tac "A" 1); |
4089 | 485 |
by (ALLGOALS(fast_tac (HOL_cs addss (simpset())))); |
2525 | 486 |
qed_spec_mp "new_tv_subst_scheme_list"; |
487 |
Addsimps [new_tv_subst_scheme_list]; |
|
488 |
||
5518 | 489 |
Goal "new_tv n A --> new_tv (Suc n) ((TVar n)#A)"; |
4089 | 490 |
by (simp_tac (simpset() addsimps [new_tv_list]) 1); |
2525 | 491 |
qed "new_tv_Suc_list"; |
492 |
||
5069 | 493 |
Goalw [new_tv_def] "!!sch::type_scheme. (free_tv sch) = (free_tv sch') --> (new_tv n sch --> new_tv n sch')"; |
2525 | 494 |
by (Asm_simp_tac 1); |
495 |
qed_spec_mp "new_tv_only_depends_on_free_tv_type_scheme"; |
|
496 |
||
5069 | 497 |
Goalw [new_tv_def] "!!A::type_scheme list. (free_tv A) = (free_tv A') --> (new_tv n A --> new_tv n A')"; |
2525 | 498 |
by (Asm_simp_tac 1); |
499 |
qed_spec_mp "new_tv_only_depends_on_free_tv_scheme_list"; |
|
500 |
||
5069 | 501 |
Goalw [new_tv_def] |
5118 | 502 |
"!nat. nat < length A --> new_tv n A --> (new_tv n (A!nat))"; |
5184 | 503 |
by (induct_tac "A" 1); |
2525 | 504 |
by (Asm_full_simp_tac 1); |
505 |
by (rtac allI 1); |
|
9747 | 506 |
by (induct_thm_tac nat_induct "nat" 1); |
2525 | 507 |
by (strip_tac 1); |
508 |
by (Asm_full_simp_tac 1); |
|
509 |
by (Simp_tac 1); |
|
510 |
qed_spec_mp "new_tv_nth_nat_A"; |
|
511 |
||
512 |
||
513 |
(* composition of substitutions preserves new_tv proposition *) |
|
5118 | 514 |
Goal "[| new_tv n (S::subst); new_tv n R |] ==> new_tv n (($ R) o S)"; |
4089 | 515 |
by (asm_full_simp_tac (simpset() addsimps [new_tv_subst]) 1); |
2525 | 516 |
qed "new_tv_subst_comp_1"; |
517 |
||
5118 | 518 |
Goal "[| new_tv n (S::subst); new_tv n R |] ==> new_tv n (%v.$ R (S v))"; |
4089 | 519 |
by (asm_full_simp_tac (simpset() addsimps [new_tv_subst]) 1); |
2525 | 520 |
qed "new_tv_subst_comp_2"; |
521 |
||
522 |
Addsimps [new_tv_subst_comp_1,new_tv_subst_comp_2]; |
|
523 |
||
524 |
(* new type variables do not occur freely in a type structure *) |
|
5069 | 525 |
Goalw [new_tv_def] |
5118 | 526 |
"new_tv n A ==> n~:(free_tv A)"; |
2525 | 527 |
by (fast_tac (HOL_cs addEs [less_irrefl]) 1); |
528 |
qed "new_tv_not_free_tv"; |
|
529 |
Addsimps [new_tv_not_free_tv]; |
|
530 |
||
5069 | 531 |
Goalw [new_tv_def] "!!t::typ. ? n. (new_tv n t)"; |
5184 | 532 |
by (induct_tac "t" 1); |
2525 | 533 |
by (res_inst_tac [("x","Suc nat")] exI 1); |
534 |
by (Asm_simp_tac 1); |
|
535 |
by (REPEAT (etac exE 1)); |
|
536 |
by (rename_tac "n'" 1); |
|
537 |
by (res_inst_tac [("x","max n n'")] exI 1); |
|
6073 | 538 |
by (simp_tac (simpset() addsimps [less_max_iff_disj]) 1); |
539 |
by (Blast_tac 1); |
|
2525 | 540 |
qed "fresh_variable_types"; |
541 |
||
542 |
Addsimps [fresh_variable_types]; |
|
543 |
||
5069 | 544 |
Goalw [new_tv_def] "!!sch::type_scheme. ? n. (new_tv n sch)"; |
5184 | 545 |
by (induct_tac "sch" 1); |
2525 | 546 |
by (res_inst_tac [("x","Suc nat")] exI 1); |
547 |
by (Simp_tac 1); |
|
548 |
by (res_inst_tac [("x","Suc nat")] exI 1); |
|
549 |
by (Simp_tac 1); |
|
550 |
by (REPEAT (etac exE 1)); |
|
551 |
by (rename_tac "n'" 1); |
|
552 |
by (res_inst_tac [("x","max n n'")] exI 1); |
|
6073 | 553 |
by (simp_tac (simpset() addsimps [less_max_iff_disj]) 1); |
554 |
by (Blast_tac 1); |
|
2525 | 555 |
qed "fresh_variable_type_schemes"; |
556 |
||
557 |
Addsimps [fresh_variable_type_schemes]; |
|
558 |
||
5069 | 559 |
Goal "!!A::type_scheme list. ? n. (new_tv n A)"; |
5184 | 560 |
by (induct_tac "A" 1); |
2525 | 561 |
by (Simp_tac 1); |
562 |
by (Simp_tac 1); |
|
563 |
by (etac exE 1); |
|
564 |
by (cut_inst_tac [("sch","a")] fresh_variable_type_schemes 1); |
|
565 |
by (etac exE 1); |
|
566 |
by (rename_tac "n'" 1); |
|
567 |
by (res_inst_tac [("x","(max n n')")] exI 1); |
|
568 |
by (subgoal_tac "n <= (max n n')" 1); |
|
569 |
by (subgoal_tac "n' <= (max n n')" 1); |
|
4089 | 570 |
by (fast_tac (claset() addDs [new_tv_le]) 1); |
6073 | 571 |
by (ALLGOALS (simp_tac (simpset() addsimps [le_max_iff_disj]))); |
2525 | 572 |
qed "fresh_variable_type_scheme_lists"; |
573 |
||
574 |
Addsimps [fresh_variable_type_scheme_lists]; |
|
575 |
||
5118 | 576 |
Goal "[| ? n1. (new_tv n1 x); ? n2. (new_tv n2 y)|] ==> ? n. (new_tv n x) & (new_tv n y)"; |
2525 | 577 |
by (REPEAT (etac exE 1)); |
578 |
by (rename_tac "n1 n2" 1); |
|
579 |
by (res_inst_tac [("x","(max n1 n2)")] exI 1); |
|
580 |
by (subgoal_tac "n1 <= max n1 n2" 1); |
|
581 |
by (subgoal_tac "n2 <= max n1 n2" 1); |
|
4089 | 582 |
by (fast_tac (claset() addDs [new_tv_le]) 1); |
6073 | 583 |
by (ALLGOALS (simp_tac (simpset() addsimps [le_max_iff_disj]))); |
2525 | 584 |
qed "make_one_new_out_of_two"; |
585 |
||
5069 | 586 |
Goal "!!(A::type_scheme list) (A'::type_scheme list) (t::typ) (t'::typ). \ |
2525 | 587 |
\ ? n. (new_tv n A) & (new_tv n A') & (new_tv n t) & (new_tv n t')" ; |
588 |
by (cut_inst_tac [("t","t")] fresh_variable_types 1); |
|
589 |
by (cut_inst_tac [("t","t'")] fresh_variable_types 1); |
|
590 |
by (dtac make_one_new_out_of_two 1); |
|
3018 | 591 |
by (assume_tac 1); |
2525 | 592 |
by (thin_tac "? n. new_tv n t'" 1); |
593 |
by (cut_inst_tac [("A","A")] fresh_variable_type_scheme_lists 1); |
|
594 |
by (cut_inst_tac [("A","A'")] fresh_variable_type_scheme_lists 1); |
|
595 |
by (rotate_tac 1 1); |
|
596 |
by (dtac make_one_new_out_of_two 1); |
|
3018 | 597 |
by (assume_tac 1); |
2525 | 598 |
by (thin_tac "? n. new_tv n A'" 1); |
599 |
by (REPEAT (etac exE 1)); |
|
600 |
by (rename_tac "n2 n1" 1); |
|
601 |
by (res_inst_tac [("x","(max n1 n2)")] exI 1); |
|
3008 | 602 |
by (rewtac new_tv_def); |
6073 | 603 |
by (simp_tac (simpset() addsimps [less_max_iff_disj]) 1); |
604 |
by (Blast_tac 1); |
|
2525 | 605 |
qed "ex_fresh_variable"; |
606 |
||
607 |
(* mgu does not introduce new type variables *) |
|
5069 | 608 |
Goalw [new_tv_def] |
5118 | 609 |
"[|mgu t1 t2 = Some u; new_tv n t1; new_tv n t2|] ==> new_tv n u"; |
3385
f59e64fe4058
New statement and proof of free_tv_subst_var in order to cope with new
paulson
parents:
3018
diff
changeset
|
610 |
by (fast_tac (set_cs addDs [mgu_free]) 1); |
2525 | 611 |
qed "mgu_new"; |
612 |
||
613 |
||
614 |
(* lemmata for substitutions *) |
|
615 |
||
5069 | 616 |
Goalw [app_subst_list] |
3438
8d63ff01d37e
Type constraint added to ensure that "length" refers to lists. Maybe should
paulson
parents:
3385
diff
changeset
|
617 |
"!!A:: ('a::type_struct) list. length ($ S A) = length A"; |
3018 | 618 |
by (Simp_tac 1); |
2525 | 619 |
qed "length_app_subst_list"; |
620 |
Addsimps [length_app_subst_list]; |
|
621 |
||
5069 | 622 |
Goal "!!sch::type_scheme. $ TVar sch = sch"; |
5184 | 623 |
by (induct_tac "sch" 1); |
2525 | 624 |
by (ALLGOALS Asm_simp_tac); |
625 |
qed "subst_TVar_scheme"; |
|
626 |
||
627 |
Addsimps [subst_TVar_scheme]; |
|
628 |
||
5069 | 629 |
Goal "!!A::type_scheme list. $ TVar A = A"; |
2525 | 630 |
by (rtac list.induct 1); |
4089 | 631 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [app_subst_list]))); |
2525 | 632 |
qed "subst_TVar_scheme_list"; |
633 |
||
634 |
Addsimps [subst_TVar_scheme_list]; |
|
635 |
||
636 |
(* application of id_subst does not change type expression *) |
|
5069 | 637 |
Goalw [id_subst_def] |
3842 | 638 |
"$ id_subst = (%t::typ. t)"; |
2525 | 639 |
by (rtac ext 1); |
5184 | 640 |
by (induct_tac "t" 1); |
2525 | 641 |
by (ALLGOALS Asm_simp_tac); |
642 |
qed "app_subst_id_te"; |
|
643 |
Addsimps [app_subst_id_te]; |
|
644 |
||
5069 | 645 |
Goalw [id_subst_def] |
3842 | 646 |
"$ id_subst = (%sch::type_scheme. sch)"; |
2525 | 647 |
by (rtac ext 1); |
5184 | 648 |
by (induct_tac "sch" 1); |
2525 | 649 |
by (ALLGOALS Asm_simp_tac); |
650 |
qed "app_subst_id_type_scheme"; |
|
651 |
Addsimps [app_subst_id_type_scheme]; |
|
652 |
||
653 |
(* application of id_subst does not change list of type expressions *) |
|
5069 | 654 |
Goalw [app_subst_list] |
3842 | 655 |
"$ id_subst = (%A::type_scheme list. A)"; |
2525 | 656 |
by (rtac ext 1); |
5184 | 657 |
by (induct_tac "A" 1); |
2525 | 658 |
by (ALLGOALS Asm_simp_tac); |
659 |
qed "app_subst_id_tel"; |
|
660 |
Addsimps [app_subst_id_tel]; |
|
661 |
||
5069 | 662 |
Goal "!!sch::type_scheme. $ id_subst sch = sch"; |
5184 | 663 |
by (induct_tac "sch" 1); |
4089 | 664 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [id_subst_def]))); |
2525 | 665 |
qed "id_subst_sch"; |
666 |
||
667 |
Addsimps [id_subst_sch]; |
|
668 |
||
5069 | 669 |
Goal "!!A::type_scheme list. $ id_subst A = A"; |
5184 | 670 |
by (induct_tac "A" 1); |
2525 | 671 |
by (Asm_full_simp_tac 1); |
672 |
by (Asm_full_simp_tac 1); |
|
673 |
qed "id_subst_A"; |
|
674 |
||
675 |
Addsimps [id_subst_A]; |
|
676 |
||
677 |
(* composition of substitutions *) |
|
5069 | 678 |
Goalw [id_subst_def,o_def] "$S o id_subst = S"; |
3018 | 679 |
by (rtac ext 1); |
680 |
by (Simp_tac 1); |
|
2525 | 681 |
qed "o_id_subst"; |
682 |
Addsimps[o_id_subst]; |
|
683 |
||
5118 | 684 |
Goal "$ R ($ S t::typ) = $ (%x. $ R (S x) ) t"; |
5184 | 685 |
by (induct_tac "t" 1); |
2525 | 686 |
by (ALLGOALS Asm_simp_tac); |
687 |
qed "subst_comp_te"; |
|
688 |
||
5118 | 689 |
Goal "$ R ($ S sch::type_scheme) = $ (%x. $ R (S x) ) sch"; |
5184 | 690 |
by (induct_tac "sch" 1); |
2525 | 691 |
by (ALLGOALS Asm_full_simp_tac); |
692 |
qed "subst_comp_type_scheme"; |
|
693 |
||
5069 | 694 |
Goalw [app_subst_list] |
2525 | 695 |
"$ R ($ S A::type_scheme list) = $ (%x. $ R (S x)) A"; |
5184 | 696 |
by (induct_tac "A" 1); |
2525 | 697 |
(* case [] *) |
698 |
by (Simp_tac 1); |
|
699 |
(* case x#xl *) |
|
4089 | 700 |
by (asm_full_simp_tac (simpset() addsimps [subst_comp_type_scheme]) 1); |
2525 | 701 |
qed "subst_comp_scheme_list"; |
702 |
||
5069 | 703 |
Goal "!!A::type_scheme list. !x : free_tv A. S x = (TVar x) ==> $ S A = $ id_subst A"; |
2525 | 704 |
by (rtac scheme_list_substitutions_only_on_free_variables 1); |
4089 | 705 |
by (asm_full_simp_tac (simpset() addsimps [id_subst_def]) 1); |
2525 | 706 |
qed "subst_id_on_type_scheme_list'"; |
707 |
||
5069 | 708 |
Goal "!!A::type_scheme list. !x : free_tv A. S x = (TVar x) ==> $ S A = A"; |
2525 | 709 |
by (stac subst_id_on_type_scheme_list' 1); |
3018 | 710 |
by (assume_tac 1); |
2525 | 711 |
by (Simp_tac 1); |
712 |
qed "subst_id_on_type_scheme_list"; |
|
713 |
||
5069 | 714 |
Goal "!n. n < length A --> ($ S A)!n = $S (A!n)"; |
5184 | 715 |
by (induct_tac "A" 1); |
2525 | 716 |
by (Asm_full_simp_tac 1); |
717 |
by (rtac allI 1); |
|
718 |
by (rename_tac "n1" 1); |
|
9747 | 719 |
by (induct_thm_tac nat_induct "n1" 1); |
2525 | 720 |
by (Asm_full_simp_tac 1); |
721 |
by (Asm_full_simp_tac 1); |
|
722 |
qed_spec_mp "nth_subst"; |