author | oheimb |
Tue, 04 Jul 2000 10:54:32 +0200 | |
changeset 9240 | f4d76cb26433 |
parent 8442 | 96023903c2df |
child 9345 | 2f5f6824f888 |
permissions | -rw-r--r-- |
8011 | 1 |
(* Title: HOL/MicroJava/J/JBasis.ML |
2 |
ID: $Id$ |
|
3 |
Author: David von Oheimb |
|
4 |
Copyright 1999 TU Muenchen |
|
5 |
*) |
|
6 |
||
7 |
val strip_tac1 = SELECT_GOAL (safe_tac (HOL_cs delrules [conjI, disjE, impCE])); |
|
8 |
||
9 |
Goalw [image_def] |
|
10 |
"x \\<in> f``A \\<Longrightarrow> \\<exists>y. y \\<in> A \\<and> x = f y"; |
|
11 |
by(Auto_tac); |
|
12 |
qed "image_rev"; |
|
13 |
||
14 |
fun case_tac1 s i = EVERY [case_tac s i, rotate_tac ~1 i, rotate_tac ~1 (i+1)]; |
|
15 |
||
16 |
val select_split = prove_goalw Prod.thy [split_def] |
|
17 |
"(\\<epsilon>(x,y). P x y) = (\\<epsilon>xy. P (fst xy) (snd xy))" (K [rtac refl 1]); |
|
18 |
||
19 |
||
20 |
val split_beta = prove_goal Prod.thy "(\\<lambda>(x,y). P x y) z = P (fst z) (snd z)" |
|
21 |
(fn _ => [stac surjective_pairing 1, stac split 1, rtac refl 1]); |
|
22 |
val split_beta2 = prove_goal Prod.thy "(\\<lambda>(x,y). P x y) (w,z) = P w z" |
|
23 |
(fn _ => [Auto_tac]); |
|
24 |
val splitE2 = prove_goal Prod.thy "\\<lbrakk>Q (split P z); \\<And>x y. \\<lbrakk>z = (x, y); Q (P x y)\\<rbrakk> \\<Longrightarrow> R\\<rbrakk> \\<Longrightarrow> R" (fn prems => [ |
|
25 |
REPEAT (resolve_tac (prems@[surjective_pairing]) 1), |
|
26 |
rtac (split_beta RS subst) 1, |
|
27 |
rtac (hd prems) 1]); |
|
28 |
val splitE2' = prove_goal Prod.thy "\\<lbrakk>((\\<lambda>(x,y). P x y) z) w; \\<And>x y. \\<lbrakk>z = (x, y); (P x y) w\\<rbrakk> \\<Longrightarrow> R\\<rbrakk> \\<Longrightarrow> R" (fn prems => [ |
|
29 |
REPEAT (resolve_tac (prems@[surjective_pairing]) 1), |
|
30 |
res_inst_tac [("P1","P")] (split_beta RS subst) 1, |
|
31 |
rtac (hd prems) 1]); |
|
32 |
||
33 |
||
34 |
fun pair_tac s = res_inst_tac [("p",s)] PairE THEN' hyp_subst_tac; |
|
35 |
||
36 |
val BallE = prove_goal thy "\\<lbrakk>Ball A P; x \\<notin> A \\<Longrightarrow> Q; P x \\<Longrightarrow> Q \\<rbrakk> \\<Longrightarrow> Q" |
|
37 |
(fn prems => [rtac ballE 1, resolve_tac prems 1, |
|
38 |
eresolve_tac prems 1, eresolve_tac prems 1]); |
|
39 |
||
40 |
val set_cs2 = set_cs delrules [ballE] addSEs [BallE]; |
|
41 |
||
42 |
Addsimps [Let_def]; |
|
43 |
Addsimps [surjective_pairing RS sym]; |
|
44 |
||
45 |
(* To HOL.ML *) |
|
46 |
||
47 |
val ex1_Eps_eq = prove_goal HOL.thy "\\<lbrakk> \\<exists>!x. P x; P y \\<rbrakk> \\<Longrightarrow> Eps P = y" |
|
48 |
(fn prems => [ |
|
49 |
cut_facts_tac prems 1, |
|
50 |
rtac select_equality 1, |
|
51 |
atac 1, |
|
52 |
etac ex1E 1, |
|
53 |
etac all_dupE 1, |
|
54 |
fast_tac HOL_cs 1]); |
|
55 |
||
56 |
||
57 |
val ball_insert = prove_goalw equalities.thy [Ball_def] |
|
58 |
"Ball (insert x A) P = (P x \\<and> Ball A P)" (fn _ => [ |
|
59 |
fast_tac set_cs 1]); |
|
60 |
||
61 |
fun option_case_tac i = EVERY [ |
|
62 |
etac option_caseE i, |
|
63 |
rotate_tac ~2 (i+1), asm_full_simp_tac HOL_basic_ss (i+1), |
|
64 |
rotate_tac ~2 i , asm_full_simp_tac HOL_basic_ss i]; |
|
65 |
||
66 |
val not_None_tac = EVERY' [dtac (not_None_eq RS iffD1),rotate_tac ~1,etac exE, |
|
67 |
rotate_tac ~1,asm_full_simp_tac |
|
68 |
(simpset() delsimps [split_paired_All,split_paired_Ex])]; |
|
69 |
||
8116 | 70 |
Goal "{y. x = Some y} \\<subseteq> {the x}"; |
71 |
by Auto_tac; |
|
72 |
qed "some_subset_the"; |
|
73 |
||
8011 | 74 |
fun ex_ftac thm = EVERY' [forward_tac [thm], REPEAT o (etac exE), rotate_tac ~1, |
75 |
asm_full_simp_tac (simpset() delsimps [split_paired_All,split_paired_Ex])]; |
|
76 |
||
77 |
val optionE = prove_goal thy |
|
78 |
"\\<lbrakk> opt = None \\<Longrightarrow> P; \\<And>x. opt = Some x \\<Longrightarrow> P \\<rbrakk> \\<Longrightarrow> P" |
|
79 |
(fn prems => [ |
|
80 |
case_tac "opt = None" 1, |
|
81 |
eresolve_tac prems 1, |
|
82 |
not_None_tac 1, |
|
83 |
eresolve_tac prems 1]); |
|
84 |
||
85 |
fun option_case_tac2 s i = EVERY [ |
|
8442
96023903c2df
case_tac now subsumes both boolean and datatype cases;
wenzelm
parents:
8423
diff
changeset
|
86 |
case_tac s i, |
8011 | 87 |
rotate_tac ~1 (i+1), asm_full_simp_tac HOL_basic_ss (i+1), |
88 |
rotate_tac ~1 i , asm_full_simp_tac HOL_basic_ss i]; |
|
89 |
||
90 |
val option_map_SomeD = prove_goalw thy [option_map_def] |
|
91 |
"\\<And>x. option_map f x = Some y \\<Longrightarrow> \\<exists>z. x = Some z \\<and> f z = y" (K [ |
|
92 |
option_case_tac2 "x" 1, |
|
93 |
Auto_tac]); |
|
94 |
||
95 |
||
96 |
section "unique"; |
|
97 |
||
98 |
Goal "(x, y) : set l --> x : fst `` set l"; |
|
99 |
by (induct_tac "l" 1); |
|
100 |
by Auto_tac; |
|
101 |
qed_spec_mp "fst_in_set_lemma"; |
|
102 |
||
103 |
Goalw [unique_def] "unique []"; |
|
104 |
by (Simp_tac 1); |
|
105 |
qed "unique_Nil"; |
|
106 |
||
107 |
Goalw [unique_def] "unique ((x,y)#l) = (unique l \\<and> (!y. (x,y) ~: set l))"; |
|
108 |
by (auto_tac (claset() addDs [fst_in_set_lemma],simpset())); |
|
109 |
qed "unique_Cons"; |
|
110 |
||
111 |
Addsimps [unique_Nil,unique_Cons]; |
|
112 |
||
113 |
Goal "unique l' ==> unique l --> \ |
|
114 |
\ (!(x,y):set l. !(x',y'):set l'. x' ~= x) --> unique (l @ l')"; |
|
115 |
by (induct_tac "l" 1); |
|
116 |
by (auto_tac (claset() addDs [fst_in_set_lemma],simpset())); |
|
117 |
qed_spec_mp "unique_append"; |
|
118 |
||
119 |
Goal "unique l --> inj f --> unique (map (%(k,x). (f k, g k x)) l)"; |
|
120 |
by (induct_tac "l" 1); |
|
8082 | 121 |
by (auto_tac (claset() addDs [fst_in_set_lemma],simpset()addsimps[inj_eq])); |
8011 | 122 |
qed_spec_mp "unique_map_inj"; |
123 |
||
124 |
Goal "\\<And>l. unique l \\<Longrightarrow> unique (map (split (\\<lambda>k. Pair (k, C))) l)"; |
|
125 |
by(etac unique_map_inj 1); |
|
126 |
by(rtac injI 1); |
|
127 |
by Auto_tac; |
|
128 |
qed "unique_map_Pair"; |
|
129 |
||
130 |
Goal "\\<lbrakk>M = N; \\<And>x. x\\<in>N \\<Longrightarrow> f x = g x\\<rbrakk> \\<Longrightarrow> f``M = g``N"; |
|
131 |
by(rtac set_ext 1); |
|
132 |
by(simp_tac (simpset() addsimps image_def::premises()) 1); |
|
133 |
qed "image_cong"; |
|
134 |
||
135 |
val split_Pair_eq = prove_goal Prod.thy |
|
136 |
"\\<And>X. ((x, y), z) \\<in> split (\\<lambda>x. Pair (x, Y)) `` A \\<Longrightarrow> y = Y" (K [ |
|
137 |
etac imageE 1, |
|
138 |
split_all_tac 1, |
|
139 |
auto_tac(claset_of Prod.thy,simpset_of Prod.thy)]); |
|
140 |
||
141 |
||
142 |
(* More about Maps *) |
|
143 |
||
144 |
val override_SomeD = prove_goalw thy [override_def] "(s \\<oplus> t) k = Some x \\<Longrightarrow> \ |
|
145 |
\ t k = Some x | t k = None \\<and> s k = Some x" (fn prems => [ |
|
146 |
cut_facts_tac prems 1, |
|
147 |
case_tac "\\<exists>x. t k = Some x" 1, |
|
148 |
etac exE 1, |
|
149 |
rotate_tac ~1 1, |
|
150 |
Asm_full_simp_tac 1, |
|
151 |
asm_full_simp_tac (HOL_ss addsimps [not_None_eq RS sym]) 1, |
|
152 |
rotate_tac ~1 1, |
|
153 |
Asm_full_simp_tac 1]); |
|
154 |
||
155 |
Addsimps [fun_upd_same, fun_upd_other]; |
|
156 |
||
157 |
Goal "unique xys \\<longrightarrow> (map_of xys x = Some y) = ((x,y) \\<in> set xys)"; |
|
158 |
by(induct_tac "xys" 1); |
|
159 |
by(Simp_tac 1); |
|
160 |
by(force_tac (claset(), simpset() addsimps [unique_Cons]) 1); |
|
161 |
qed_spec_mp "unique_map_of_Some_conv"; |
|
162 |
||
163 |
val in_set_get = unique_map_of_Some_conv RS iffD2; |
|
164 |
val get_in_set = unique_map_of_Some_conv RS iffD1; |
|
165 |
||
166 |
Goal "(\\<forall>(x,y)\\<in>set l. P x y) \\<longrightarrow> (\\<forall>x. \\<forall>y. map_of l x = Some y \\<longrightarrow> P x y)"; |
|
167 |
by(induct_tac "l" 1); |
|
168 |
by(ALLGOALS Simp_tac); |
|
169 |
by Safe_tac; |
|
170 |
by Auto_tac; |
|
171 |
bind_thm("Ball_set_table",result() RS mp); |
|
172 |
||
173 |
val table_mono = prove_goal thy |
|
174 |
"unique l' \\<longrightarrow> (\\<forall>xy. (xy)\\<in>set l \\<longrightarrow> (xy)\\<in>set l') \\<longrightarrow>\ |
|
175 |
\ (\\<forall>k y. map_of l k = Some y \\<longrightarrow> map_of l' k = Some y)" (fn _ => [ |
|
176 |
induct_tac "l" 1, |
|
177 |
Auto_tac, |
|
178 |
fast_tac (HOL_cs addSIs [in_set_get]) 1]) |
|
179 |
RS mp RS mp RS spec RS spec RS mp; |
|
180 |
||
181 |
val table_map_Some' = prove_goal thy "map_of t k = Some (k', x) \\<longrightarrow> \ |
|
182 |
\ map_of (map (\\<lambda>u. ((fst u, fst (snd u)), snd (snd u))) t) (k, k') = Some x" (K [ |
|
183 |
induct_tac "t" 1, |
|
184 |
ALLGOALS Simp_tac, |
|
185 |
case_tac1 "k = fst a" 1, |
|
186 |
Auto_tac]) RS mp; |
|
187 |
val table_map_Some = prove_goal thy |
|
188 |
"map_of (map (\\<lambda>((k,k'),x). (k,(k',x))) t) k = Some (k',x) \\<longrightarrow> \ |
|
189 |
\map_of t (k, k') = Some x" (K [ |
|
190 |
induct_tac "t" 1, |
|
191 |
Auto_tac]) RS mp; |
|
192 |
||
193 |
||
194 |
val table_mapf_Some = prove_goal thy "\\<And>f. \\<forall>x y. f x = f y \\<longrightarrow> x = y \\<Longrightarrow> \ |
|
195 |
\ map_of (map (\\<lambda>(k,x). (k,f x)) t) k = Some (f x) \\<longrightarrow> map_of t k = Some x" (K [ |
|
196 |
induct_tac "t" 1, |
|
197 |
Auto_tac]) RS mp; |
|
198 |
val table_mapf_SomeD = prove_goal thy |
|
199 |
"map_of (map (\\<lambda>(k,x). (k, f x)) t) k = Some z \\<longrightarrow> (\\<exists>y. (k,y)\\<in>set t \\<and> z = f y)"(K [ |
|
200 |
induct_tac "t" 1, |
|
201 |
Auto_tac]) RS mp; |
|
202 |
||
203 |
val table_mapf_Some2 = prove_goal thy |
|
204 |
"\\<And>k. map_of (map (\\<lambda>(k,x). (k,C,x)) t) k = Some (D,x) \\<Longrightarrow> C = D \\<and> map_of t k = Some x" (K [ |
|
205 |
forward_tac [table_mapf_SomeD] 1, |
|
206 |
Auto_tac, |
|
207 |
rtac table_mapf_Some 1, |
|
208 |
atac 2, |
|
209 |
Fast_tac 1]); |
|
210 |
||
211 |
val finite_map_of = rewrite_rule [dom_def] finite_dom_map_of; |
|
212 |
||
213 |
Goal |
|
214 |
"map_of (map (\\<lambda>(a,b). (a,f b)) xs) x = option_map f (map_of xs x)"; |
|
215 |
by (induct_tac "xs" 1); |
|
216 |
auto(); |
|
217 |
qed "map_of_map"; |
|
218 |
||
219 |