2525
|
1 |
(* Title: HOL/MiniML/Instance.ML
|
|
2 |
ID: $Id$
|
|
3 |
Author: Wolfgang Naraschewski and Tobias Nipkow
|
|
4 |
Copyright 1996 TU Muenchen
|
|
5 |
*)
|
|
6 |
|
|
7 |
(* lemmatas for instatiation *)
|
|
8 |
|
|
9 |
|
|
10 |
(* lemmatas for bound_typ_inst *)
|
|
11 |
|
5069
|
12 |
Goal "bound_typ_inst S (mk_scheme t) = t";
|
2525
|
13 |
by (typ.induct_tac "t" 1);
|
|
14 |
by (ALLGOALS Asm_simp_tac);
|
|
15 |
qed "bound_typ_inst_mk_scheme";
|
|
16 |
|
|
17 |
Addsimps [bound_typ_inst_mk_scheme];
|
2625
|
18 |
|
5118
|
19 |
Goal "bound_typ_inst ($S o R) ($S sch) = $S (bound_typ_inst R sch)";
|
2525
|
20 |
by (type_scheme.induct_tac "sch" 1);
|
|
21 |
by (ALLGOALS Asm_full_simp_tac);
|
|
22 |
qed "bound_typ_inst_composed_subst";
|
|
23 |
|
|
24 |
Addsimps [bound_typ_inst_composed_subst];
|
|
25 |
|
5118
|
26 |
Goal "S = S' ==> sch = sch' ==> bound_typ_inst S sch = bound_typ_inst S' sch'";
|
2525
|
27 |
by (Asm_full_simp_tac 1);
|
|
28 |
qed "bound_typ_inst_eq";
|
|
29 |
|
|
30 |
|
2625
|
31 |
|
2525
|
32 |
(* lemmatas for bound_scheme_inst *)
|
|
33 |
|
5118
|
34 |
Goal "bound_scheme_inst B (mk_scheme t) = mk_scheme t";
|
2525
|
35 |
by (typ.induct_tac "t" 1);
|
|
36 |
by (Simp_tac 1);
|
|
37 |
by (Asm_simp_tac 1);
|
|
38 |
qed "bound_scheme_inst_mk_scheme";
|
|
39 |
|
|
40 |
Addsimps [bound_scheme_inst_mk_scheme];
|
|
41 |
|
5118
|
42 |
Goal "$S (bound_scheme_inst B sch) = (bound_scheme_inst ($S o B) ($ S sch))";
|
2525
|
43 |
by (type_scheme.induct_tac "sch" 1);
|
|
44 |
by (Simp_tac 1);
|
|
45 |
by (Simp_tac 1);
|
|
46 |
by (Asm_simp_tac 1);
|
|
47 |
qed "substitution_lemma";
|
|
48 |
|
5069
|
49 |
Goal "!t. mk_scheme t = bound_scheme_inst B sch --> \
|
2525
|
50 |
\ (? S. !x:bound_tv sch. B x = mk_scheme (S x))";
|
|
51 |
by (type_scheme.induct_tac "sch" 1);
|
|
52 |
by (Simp_tac 1);
|
4153
|
53 |
by Safe_tac;
|
2525
|
54 |
by (rtac exI 1);
|
|
55 |
by (rtac ballI 1);
|
|
56 |
by (rtac sym 1);
|
|
57 |
by (Asm_full_simp_tac 1);
|
|
58 |
by (Asm_full_simp_tac 1);
|
|
59 |
by (dtac mk_scheme_Fun 1);
|
|
60 |
by (REPEAT (etac exE 1));
|
|
61 |
by (etac conjE 1);
|
|
62 |
by (dtac sym 1);
|
|
63 |
by (dtac sym 1);
|
|
64 |
by (REPEAT ((dtac mp 1) THEN (Fast_tac 1)));
|
4153
|
65 |
by Safe_tac;
|
2525
|
66 |
by (rename_tac "S1 S2" 1);
|
|
67 |
by (res_inst_tac [("x","%x. if x:bound_tv type_scheme1 then (S1 x) else (S2 x)")] exI 1);
|
4153
|
68 |
by Safe_tac;
|
4686
|
69 |
by (Asm_simp_tac 1);
|
|
70 |
by (Asm_simp_tac 1);
|
2525
|
71 |
by (strip_tac 1);
|
|
72 |
by (dres_inst_tac [("x","x")] bspec 1);
|
3018
|
73 |
by (assume_tac 1);
|
2525
|
74 |
by (dres_inst_tac [("x","x")] bspec 1);
|
|
75 |
by (Asm_simp_tac 1);
|
|
76 |
by (Asm_full_simp_tac 1);
|
|
77 |
qed_spec_mp "bound_scheme_inst_type";
|
|
78 |
|
|
79 |
|
5118
|
80 |
(* lemmas for subst_to_scheme *)
|
2525
|
81 |
|
5118
|
82 |
Goal "new_tv n sch --> subst_to_scheme (%k. if n <= k then BVar (k - n) else FVar k) \
|
2525
|
83 |
\ (bound_typ_inst (%k. TVar (k + n)) sch) = sch";
|
|
84 |
by (type_scheme.induct_tac "sch" 1);
|
4686
|
85 |
by (simp_tac (simpset() addsimps [leD]) 1);
|
|
86 |
by (simp_tac (simpset() addsimps [le_add2,diff_add_inverse2]) 1);
|
2525
|
87 |
by (Asm_simp_tac 1);
|
|
88 |
qed_spec_mp "subst_to_scheme_inverse";
|
|
89 |
|
5118
|
90 |
Goal "t = t' ==> \
|
|
91 |
\ subst_to_scheme (%k. if n <= k then BVar (k - n) else FVar k) t = \
|
|
92 |
\ subst_to_scheme (%k. if n <= k then BVar (k - n) else FVar k) t'";
|
2525
|
93 |
by (Fast_tac 1);
|
|
94 |
val aux = result ();
|
|
95 |
|
5069
|
96 |
Goal "new_tv n sch --> \
|
5118
|
97 |
\ subst_to_scheme (%k. if n <= k then BVar (k - n) else FVar k) (bound_typ_inst S sch) = \
|
|
98 |
\ bound_scheme_inst ((subst_to_scheme (%k. if n <= k then BVar (k - n) else FVar k)) o S) sch";
|
2525
|
99 |
by (type_scheme.induct_tac "sch" 1);
|
4686
|
100 |
by (simp_tac (simpset() addsimps [leD]) 1);
|
2525
|
101 |
by (Asm_simp_tac 1);
|
4686
|
102 |
by (asm_full_simp_tac (simpset() addsimps [leD]) 1);
|
2525
|
103 |
val aux2 = result () RS mp;
|
|
104 |
|
|
105 |
|
|
106 |
(* lemmata for <= *)
|
|
107 |
|
5069
|
108 |
Goalw [le_type_scheme_def,is_bound_typ_instance]
|
5118
|
109 |
"!!(sch::type_scheme) sch'. \
|
|
110 |
\ (sch' <= sch) = (? B. sch' = bound_scheme_inst B sch)";
|
2525
|
111 |
by (rtac iffI 1);
|
|
112 |
by (cut_inst_tac [("sch","sch")] fresh_variable_type_schemes 1);
|
|
113 |
by (cut_inst_tac [("sch","sch'")] fresh_variable_type_schemes 1);
|
|
114 |
by (dtac make_one_new_out_of_two 1);
|
3018
|
115 |
by (assume_tac 1);
|
2525
|
116 |
by (thin_tac "? n. new_tv n sch'" 1);
|
|
117 |
by (etac exE 1);
|
|
118 |
by (etac allE 1);
|
|
119 |
by (dtac mp 1);
|
|
120 |
by (res_inst_tac [("x","(%k. TVar (k + n))")] exI 1);
|
|
121 |
by (rtac refl 1);
|
|
122 |
by (etac exE 1);
|
|
123 |
by (REPEAT (etac conjE 1));
|
|
124 |
by (dres_inst_tac [("n","n")] aux 1);
|
4089
|
125 |
by (asm_full_simp_tac (simpset() addsimps [subst_to_scheme_inverse]) 1);
|
2525
|
126 |
by (res_inst_tac [("x","(subst_to_scheme (%k. if n <= k then BVar (k - n) else FVar k)) o S")] exI 1);
|
4089
|
127 |
by (asm_simp_tac (simpset() addsimps [aux2]) 1);
|
4153
|
128 |
by Safe_tac;
|
2525
|
129 |
by (res_inst_tac [("x","%n. bound_typ_inst S (B n)")] exI 1);
|
|
130 |
by (type_scheme.induct_tac "sch" 1);
|
|
131 |
by (Simp_tac 1);
|
|
132 |
by (Simp_tac 1);
|
|
133 |
by (Asm_simp_tac 1);
|
|
134 |
qed "le_type_scheme_def2";
|
|
135 |
|
5069
|
136 |
Goalw [is_bound_typ_instance] "(mk_scheme t) <= sch = t <| sch";
|
4089
|
137 |
by (simp_tac (simpset() addsimps [le_type_scheme_def2]) 1);
|
2525
|
138 |
by (rtac iffI 1);
|
|
139 |
by (etac exE 1);
|
|
140 |
by (forward_tac [bound_scheme_inst_type] 1);
|
|
141 |
by (etac exE 1);
|
|
142 |
by (rtac exI 1);
|
|
143 |
by (rtac mk_scheme_injective 1);
|
|
144 |
by (Asm_full_simp_tac 1);
|
|
145 |
by (rotate_tac 1 1);
|
|
146 |
by (rtac mp 1);
|
3018
|
147 |
by (assume_tac 2);
|
2525
|
148 |
by (type_scheme.induct_tac "sch" 1);
|
|
149 |
by (Simp_tac 1);
|
|
150 |
by (Asm_full_simp_tac 1);
|
|
151 |
by (Fast_tac 1);
|
|
152 |
by (strip_tac 1);
|
|
153 |
by (Asm_full_simp_tac 1);
|
|
154 |
by (etac exE 1);
|
|
155 |
by (Asm_full_simp_tac 1);
|
|
156 |
by (rtac exI 1);
|
|
157 |
by (type_scheme.induct_tac "sch" 1);
|
|
158 |
by (Simp_tac 1);
|
|
159 |
by (Simp_tac 1);
|
|
160 |
by (Asm_full_simp_tac 1);
|
|
161 |
qed_spec_mp "le_type_eq_is_bound_typ_instance";
|
|
162 |
|
5069
|
163 |
Goalw [le_env_def]
|
2525
|
164 |
"(sch # A <= sch' # B) = (sch <= (sch'::type_scheme) & A <= B)";
|
3018
|
165 |
by (Simp_tac 1);
|
|
166 |
by (rtac iffI 1);
|
4153
|
167 |
by (SELECT_GOAL Safe_tac 1);
|
3018
|
168 |
by (eres_inst_tac [("x","0")] allE 1);
|
|
169 |
by (Asm_full_simp_tac 1);
|
|
170 |
by (eres_inst_tac [("x","Suc i")] allE 1);
|
|
171 |
by (Asm_full_simp_tac 1);
|
|
172 |
by (rtac conjI 1);
|
|
173 |
by (Fast_tac 1);
|
|
174 |
by (rtac allI 1);
|
|
175 |
by (nat_ind_tac "i" 1);
|
|
176 |
by (ALLGOALS Asm_simp_tac);
|
2525
|
177 |
qed "le_env_Cons";
|
|
178 |
AddIffs [le_env_Cons];
|
|
179 |
|
5118
|
180 |
Goalw [is_bound_typ_instance]"t <| sch ==> $S t <| $S sch";
|
2525
|
181 |
by (etac exE 1);
|
|
182 |
by (rename_tac "SA" 1);
|
|
183 |
by (hyp_subst_tac 1);
|
|
184 |
by (res_inst_tac [("x","$S o SA")] exI 1);
|
|
185 |
by (Simp_tac 1);
|
|
186 |
qed "is_bound_typ_instance_closed_subst";
|
|
187 |
|
5069
|
188 |
Goal "!!(sch::type_scheme) sch'. sch' <= sch ==> $S sch' <= $ S sch";
|
4089
|
189 |
by (asm_full_simp_tac (simpset() addsimps [le_type_scheme_def2]) 1);
|
2525
|
190 |
by (etac exE 1);
|
4089
|
191 |
by (asm_full_simp_tac (simpset() addsimps [substitution_lemma]) 1);
|
2525
|
192 |
by (Fast_tac 1);
|
|
193 |
qed "S_compatible_le_scheme";
|
|
194 |
|
5118
|
195 |
Goalw [le_env_def,app_subst_list]
|
|
196 |
"!!(A::type_scheme list) A'. A' <= A ==> $S A' <= $ S A";
|
4089
|
197 |
by (simp_tac (simpset() addcongs [conj_cong]) 1);
|
|
198 |
by (fast_tac (claset() addSIs [S_compatible_le_scheme]) 1);
|
2525
|
199 |
qed "S_compatible_le_scheme_lists";
|
|
200 |
|
5118
|
201 |
Goalw [le_type_scheme_def] "[| t <| sch; sch <= sch' |] ==> t <| sch'";
|
3018
|
202 |
by (Fast_tac 1);
|
2525
|
203 |
qed "bound_typ_instance_trans";
|
|
204 |
|
5069
|
205 |
Goalw [le_type_scheme_def] "sch <= (sch::type_scheme)";
|
3018
|
206 |
by (Fast_tac 1);
|
2525
|
207 |
qed "le_type_scheme_refl";
|
|
208 |
AddIffs [le_type_scheme_refl];
|
|
209 |
|
5069
|
210 |
Goalw [le_env_def] "A <= (A::type_scheme list)";
|
3018
|
211 |
by (Fast_tac 1);
|
2525
|
212 |
qed "le_env_refl";
|
|
213 |
AddIffs [le_env_refl];
|
|
214 |
|
5069
|
215 |
Goalw [le_type_scheme_def,is_bound_typ_instance] "sch <= BVar n";
|
3018
|
216 |
by (strip_tac 1);
|
3842
|
217 |
by (res_inst_tac [("x","%a. t")]exI 1);
|
3018
|
218 |
by (Simp_tac 1);
|
2525
|
219 |
qed "bound_typ_instance_BVar";
|
|
220 |
AddIffs [bound_typ_instance_BVar];
|
|
221 |
|
5118
|
222 |
Goalw [le_type_scheme_def,is_bound_typ_instance]
|
|
223 |
"(sch <= FVar n) = (sch = FVar n)";
|
3018
|
224 |
by (type_scheme.induct_tac "sch" 1);
|
|
225 |
by (Simp_tac 1);
|
|
226 |
by (Simp_tac 1);
|
|
227 |
by (Fast_tac 1);
|
|
228 |
by (Asm_full_simp_tac 1);
|
|
229 |
by (Fast_tac 1);
|
2525
|
230 |
qed "le_FVar";
|
|
231 |
Addsimps [le_FVar];
|
|
232 |
|
5069
|
233 |
Goalw [le_type_scheme_def,is_bound_typ_instance] "~(FVar n <= sch1 =-> sch2)";
|
3018
|
234 |
by (Simp_tac 1);
|
2525
|
235 |
qed "not_FVar_le_Fun";
|
|
236 |
AddIffs [not_FVar_le_Fun];
|
|
237 |
|
5069
|
238 |
Goalw [le_type_scheme_def,is_bound_typ_instance] "~(BVar n <= sch1 =-> sch2)";
|
3018
|
239 |
by (Simp_tac 1);
|
|
240 |
by (res_inst_tac [("x","TVar n")] exI 1);
|
|
241 |
by (Simp_tac 1);
|
|
242 |
by (Fast_tac 1);
|
2525
|
243 |
qed "not_BVar_le_Fun";
|
|
244 |
AddIffs [not_BVar_le_Fun];
|
|
245 |
|
5069
|
246 |
Goalw [le_type_scheme_def,is_bound_typ_instance]
|
5118
|
247 |
"(sch1 =-> sch2 <= sch1' =-> sch2') ==> sch1 <= sch1' & sch2 <= sch2'";
|
4089
|
248 |
by (fast_tac (claset() addss simpset()) 1);
|
2525
|
249 |
qed "Fun_le_FunD";
|
|
250 |
|
5069
|
251 |
Goal "(sch' <= sch1 =-> sch2) --> (? sch'1 sch'2. sch' = sch'1 =-> sch'2)";
|
2525
|
252 |
by (type_scheme.induct_tac "sch'" 1);
|
|
253 |
by (Asm_simp_tac 1);
|
|
254 |
by (Asm_simp_tac 1);
|
|
255 |
by (Fast_tac 1);
|
|
256 |
qed_spec_mp "scheme_le_Fun";
|
|
257 |
|
5069
|
258 |
Goal "!sch'::type_scheme. sch <= sch' --> free_tv sch' <= free_tv sch";
|
3018
|
259 |
by (type_scheme.induct_tac "sch" 1);
|
|
260 |
by (rtac allI 1);
|
|
261 |
by (type_scheme.induct_tac "sch'" 1);
|
|
262 |
by (Simp_tac 1);
|
|
263 |
by (Simp_tac 1);
|
|
264 |
by (Simp_tac 1);
|
|
265 |
by (rtac allI 1);
|
|
266 |
by (type_scheme.induct_tac "sch'" 1);
|
|
267 |
by (Simp_tac 1);
|
|
268 |
by (Simp_tac 1);
|
|
269 |
by (Simp_tac 1);
|
|
270 |
by (rtac allI 1);
|
|
271 |
by (type_scheme.induct_tac "sch'" 1);
|
|
272 |
by (Simp_tac 1);
|
|
273 |
by (Simp_tac 1);
|
|
274 |
by (Asm_full_simp_tac 1);
|
|
275 |
by (strip_tac 1);
|
|
276 |
by (dtac Fun_le_FunD 1);
|
|
277 |
by (Fast_tac 1);
|
2525
|
278 |
qed_spec_mp "le_type_scheme_free_tv";
|
|
279 |
|
5069
|
280 |
Goal "!A::type_scheme list. A <= B --> free_tv B <= free_tv A";
|
3018
|
281 |
by (list.induct_tac "B" 1);
|
|
282 |
by (Simp_tac 1);
|
|
283 |
by (rtac allI 1);
|
|
284 |
by (list.induct_tac "A" 1);
|
4089
|
285 |
by (simp_tac (simpset() addsimps [le_env_def]) 1);
|
3018
|
286 |
by (Simp_tac 1);
|
4089
|
287 |
by (fast_tac (claset() addDs [le_type_scheme_free_tv]) 1);
|
2525
|
288 |
qed_spec_mp "le_env_free_tv";
|