author | blanchet |
Thu, 24 Mar 2011 17:49:27 +0100 | |
changeset 42103 | 6066a35f6678 |
parent 41413 | 64cd30d6b0b8 |
child 42757 | ebf603e54061 |
permissions | -rw-r--r-- |
33027 | 1 |
(* Title: HOL/Metis_Examples/Abstraction.thy |
23449 | 2 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
41144 | 3 |
Author: Jasmin Blanchette, TU Muenchen |
23449 | 4 |
|
41144 | 5 |
Testing Metis. |
23449 | 6 |
*) |
7 |
||
27368 | 8 |
theory Abstraction |
41413
64cd30d6b0b8
explicit file specifications -- avoid secondary load path;
wenzelm
parents:
41144
diff
changeset
|
9 |
imports Main "~~/src/HOL/Library/FuncSet" |
23449 | 10 |
begin |
11 |
||
42103
6066a35f6678
Metis examples use the new Skolemizer to test it
blanchet
parents:
41413
diff
changeset
|
12 |
declare [[metis_new_skolemizer]] |
6066a35f6678
Metis examples use the new Skolemizer to test it
blanchet
parents:
41413
diff
changeset
|
13 |
|
23449 | 14 |
(*For Christoph Benzmueller*) |
15 |
lemma "x<1 & ((op=) = (op=)) ==> ((op=) = (op=)) & (x<(2::nat))"; |
|
16 |
by (metis One_nat_def less_Suc0 not_less0 not_less_eq numeral_2_eq_2) |
|
17 |
||
18 |
(*this is a theorem, but we can't prove it unless ext is applied explicitly |
|
19 |
lemma "(op=) = (%x y. y=x)" |
|
20 |
*) |
|
21 |
||
22 |
consts |
|
23 |
monotone :: "['a => 'a, 'a set, ('a *'a)set] => bool" |
|
24 |
pset :: "'a set => 'a set" |
|
25 |
order :: "'a set => ('a * 'a) set" |
|
26 |
||
38991 | 27 |
declare [[ sledgehammer_problem_prefix = "Abstraction__Collect_triv" ]] |
23449 | 28 |
lemma (*Collect_triv:*) "a \<in> {x. P x} ==> P a" |
36566 | 29 |
proof - |
30 |
assume "a \<in> {x. P x}" |
|
31 |
hence "a \<in> P" by (metis Collect_def) |
|
32 |
hence "P a" by (metis mem_def) |
|
33 |
thus "P a" by metis |
|
23449 | 34 |
qed |
35 |
||
36 |
lemma Collect_triv: "a \<in> {x. P x} ==> P a" |
|
23756 | 37 |
by (metis mem_Collect_eq) |
23449 | 38 |
|
39 |
||
38991 | 40 |
declare [[ sledgehammer_problem_prefix = "Abstraction__Collect_mp" ]] |
23449 | 41 |
lemma "a \<in> {x. P x --> Q x} ==> a \<in> {x. P x} ==> a \<in> {x. Q x}" |
36566 | 42 |
by (metis Collect_imp_eq ComplD UnE) |
23449 | 43 |
|
38991 | 44 |
declare [[ sledgehammer_problem_prefix = "Abstraction__Sigma_triv" ]] |
23449 | 45 |
lemma "(a,b) \<in> Sigma A B ==> a \<in> A & b \<in> B a" |
36566 | 46 |
proof - |
47 |
assume A1: "(a, b) \<in> Sigma A B" |
|
48 |
hence F1: "b \<in> B a" by (metis mem_Sigma_iff) |
|
49 |
have F2: "a \<in> A" by (metis A1 mem_Sigma_iff) |
|
50 |
have "b \<in> B a" by (metis F1) |
|
51 |
thus "a \<in> A \<and> b \<in> B a" by (metis F2) |
|
23449 | 52 |
qed |
53 |
||
54 |
lemma Sigma_triv: "(a,b) \<in> Sigma A B ==> a \<in> A & b \<in> B a" |
|
55 |
by (metis SigmaD1 SigmaD2) |
|
56 |
||
38991 | 57 |
declare [[ sledgehammer_problem_prefix = "Abstraction__Sigma_Collect" ]] |
36566 | 58 |
lemma "(a, b) \<in> (SIGMA x:A. {y. x = f y}) \<Longrightarrow> a \<in> A \<and> a = f b" |
59 |
(* Metis says this is satisfiable! |
|
29676 | 60 |
by (metis CollectD SigmaD1 SigmaD2) |
61 |
*) |
|
23449 | 62 |
by (meson CollectD SigmaD1 SigmaD2) |
63 |
||
64 |
||
36566 | 65 |
lemma "(a, b) \<in> (SIGMA x:A. {y. x = f y}) \<Longrightarrow> a \<in> A \<and> a = f b" |
66 |
by (metis mem_Sigma_iff singleton_conv2 vimage_Collect_eq vimage_singleton_eq) |
|
24827 | 67 |
|
36566 | 68 |
lemma "(a, b) \<in> (SIGMA x:A. {y. x = f y}) \<Longrightarrow> a \<in> A \<and> a = f b" |
69 |
proof - |
|
70 |
assume A1: "(a, b) \<in> (SIGMA x:A. {y. x = f y})" |
|
71 |
have F1: "\<forall>u. {u} = op = u" by (metis singleton_conv2 Collect_def) |
|
36571 | 72 |
have F2: "\<forall>y w v. v \<in> w -` op = y \<longrightarrow> w v = y" |
73 |
by (metis F1 vimage_singleton_eq) |
|
74 |
have F3: "\<forall>x w. (\<lambda>R. w (x R)) = x -` w" |
|
75 |
by (metis vimage_Collect_eq Collect_def) |
|
76 |
show "a \<in> A \<and> a = f b" by (metis A1 F2 F3 mem_Sigma_iff Collect_def) |
|
24827 | 77 |
qed |
78 |
||
36566 | 79 |
(* Alternative structured proof *) |
80 |
lemma "(a, b) \<in> (SIGMA x:A. {y. x = f y}) \<Longrightarrow> a \<in> A \<and> a = f b" |
|
81 |
proof - |
|
82 |
assume A1: "(a, b) \<in> (SIGMA x:A. {y. x = f y})" |
|
83 |
hence F1: "a \<in> A" by (metis mem_Sigma_iff) |
|
84 |
have "b \<in> {R. a = f R}" by (metis A1 mem_Sigma_iff) |
|
85 |
hence F2: "b \<in> (\<lambda>R. a = f R)" by (metis Collect_def) |
|
86 |
hence "a = f b" by (unfold mem_def) |
|
87 |
thus "a \<in> A \<and> a = f b" by (metis F1) |
|
24827 | 88 |
qed |
23449 | 89 |
|
90 |
||
38991 | 91 |
declare [[ sledgehammer_problem_prefix = "Abstraction__CLF_eq_in_pp" ]] |
23449 | 92 |
lemma "(cl,f) \<in> CLF ==> CLF = (SIGMA cl: CL.{f. f \<in> pset cl}) ==> f \<in> pset cl" |
24827 | 93 |
by (metis Collect_mem_eq SigmaD2) |
23449 | 94 |
|
24742
73b8b42a36b6
removal of some "ref"s from res_axioms.ML; a side-effect is that the ordering
paulson
parents:
24632
diff
changeset
|
95 |
lemma "(cl,f) \<in> CLF ==> CLF = (SIGMA cl: CL.{f. f \<in> pset cl}) ==> f \<in> pset cl" |
36566 | 96 |
proof - |
97 |
assume A1: "(cl, f) \<in> CLF" |
|
98 |
assume A2: "CLF = (SIGMA cl:CL. {f. f \<in> pset cl})" |
|
99 |
have F1: "\<forall>v. (\<lambda>R. R \<in> v) = v" by (metis Collect_mem_eq Collect_def) |
|
100 |
have "\<forall>v u. (u, v) \<in> CLF \<longrightarrow> v \<in> {R. R \<in> pset u}" by (metis A2 mem_Sigma_iff) |
|
101 |
hence "\<forall>v u. (u, v) \<in> CLF \<longrightarrow> v \<in> pset u" by (metis F1 Collect_def) |
|
102 |
hence "f \<in> pset cl" by (metis A1) |
|
103 |
thus "f \<in> pset cl" by metis |
|
24827 | 104 |
qed |
23449 | 105 |
|
38991 | 106 |
declare [[ sledgehammer_problem_prefix = "Abstraction__Sigma_Collect_Pi" ]] |
23449 | 107 |
lemma |
108 |
"(cl,f) \<in> (SIGMA cl: CL. {f. f \<in> pset cl \<rightarrow> pset cl}) ==> |
|
109 |
f \<in> pset cl \<rightarrow> pset cl" |
|
36566 | 110 |
proof - |
111 |
assume A1: "(cl, f) \<in> (SIGMA cl:CL. {f. f \<in> pset cl \<rightarrow> pset cl})" |
|
112 |
have F1: "\<forall>v. (\<lambda>R. R \<in> v) = v" by (metis Collect_mem_eq Collect_def) |
|
113 |
have "f \<in> {R. R \<in> pset cl \<rightarrow> pset cl}" using A1 by simp |
|
114 |
hence "f \<in> pset cl \<rightarrow> pset cl" by (metis F1 Collect_def) |
|
115 |
thus "f \<in> pset cl \<rightarrow> pset cl" by metis |
|
24827 | 116 |
qed |
23449 | 117 |
|
38991 | 118 |
declare [[ sledgehammer_problem_prefix = "Abstraction__Sigma_Collect_Int" ]] |
23449 | 119 |
lemma |
120 |
"(cl,f) \<in> (SIGMA cl: CL. {f. f \<in> pset cl \<inter> cl}) ==> |
|
121 |
f \<in> pset cl \<inter> cl" |
|
36566 | 122 |
proof - |
123 |
assume A1: "(cl, f) \<in> (SIGMA cl:CL. {f. f \<in> pset cl \<inter> cl})" |
|
124 |
have F1: "\<forall>v. (\<lambda>R. R \<in> v) = v" by (metis Collect_mem_eq Collect_def) |
|
125 |
have "f \<in> {R. R \<in> pset cl \<inter> cl}" using A1 by simp |
|
126 |
hence "f \<in> Id_on cl `` pset cl" by (metis F1 Int_commute Image_Id_on Collect_def) |
|
127 |
hence "f \<in> Id_on cl `` pset cl" by metis |
|
128 |
hence "f \<in> cl \<inter> pset cl" by (metis Image_Id_on) |
|
129 |
thus "f \<in> pset cl \<inter> cl" by (metis Int_commute) |
|
24827 | 130 |
qed |
131 |
||
23449 | 132 |
|
38991 | 133 |
declare [[ sledgehammer_problem_prefix = "Abstraction__Sigma_Collect_Pi_mono" ]] |
23449 | 134 |
lemma |
135 |
"(cl,f) \<in> (SIGMA cl: CL. {f. f \<in> pset cl \<rightarrow> pset cl & monotone f (pset cl) (order cl)}) ==> |
|
136 |
(f \<in> pset cl \<rightarrow> pset cl) & (monotone f (pset cl) (order cl))" |
|
137 |
by auto |
|
138 |
||
38991 | 139 |
declare [[ sledgehammer_problem_prefix = "Abstraction__CLF_subset_Collect_Int" ]] |
23449 | 140 |
lemma "(cl,f) \<in> CLF ==> |
141 |
CLF \<subseteq> (SIGMA cl: CL. {f. f \<in> pset cl \<inter> cl}) ==> |
|
142 |
f \<in> pset cl \<inter> cl" |
|
24827 | 143 |
by auto |
27368 | 144 |
|
23449 | 145 |
|
38991 | 146 |
declare [[ sledgehammer_problem_prefix = "Abstraction__CLF_eq_Collect_Int" ]] |
23449 | 147 |
lemma "(cl,f) \<in> CLF ==> |
148 |
CLF = (SIGMA cl: CL. {f. f \<in> pset cl \<inter> cl}) ==> |
|
149 |
f \<in> pset cl \<inter> cl" |
|
24827 | 150 |
by auto |
36566 | 151 |
|
23449 | 152 |
|
38991 | 153 |
declare [[ sledgehammer_problem_prefix = "Abstraction__CLF_subset_Collect_Pi" ]] |
23449 | 154 |
lemma |
155 |
"(cl,f) \<in> CLF ==> |
|
156 |
CLF \<subseteq> (SIGMA cl': CL. {f. f \<in> pset cl' \<rightarrow> pset cl'}) ==> |
|
157 |
f \<in> pset cl \<rightarrow> pset cl" |
|
31754 | 158 |
by fast |
36566 | 159 |
|
23449 | 160 |
|
38991 | 161 |
declare [[ sledgehammer_problem_prefix = "Abstraction__CLF_eq_Collect_Pi" ]] |
23449 | 162 |
lemma |
163 |
"(cl,f) \<in> CLF ==> |
|
164 |
CLF = (SIGMA cl: CL. {f. f \<in> pset cl \<rightarrow> pset cl}) ==> |
|
165 |
f \<in> pset cl \<rightarrow> pset cl" |
|
24827 | 166 |
by auto |
36566 | 167 |
|
23449 | 168 |
|
38991 | 169 |
declare [[ sledgehammer_problem_prefix = "Abstraction__CLF_eq_Collect_Pi_mono" ]] |
23449 | 170 |
lemma |
171 |
"(cl,f) \<in> CLF ==> |
|
172 |
CLF = (SIGMA cl: CL. {f. f \<in> pset cl \<rightarrow> pset cl & monotone f (pset cl) (order cl)}) ==> |
|
173 |
(f \<in> pset cl \<rightarrow> pset cl) & (monotone f (pset cl) (order cl))" |
|
174 |
by auto |
|
175 |
||
38991 | 176 |
declare [[ sledgehammer_problem_prefix = "Abstraction__map_eq_zipA" ]] |
23449 | 177 |
lemma "map (%x. (f x, g x)) xs = zip (map f xs) (map g xs)" |
178 |
apply (induct xs) |
|
36566 | 179 |
apply (metis map_is_Nil_conv zip.simps(1)) |
180 |
by auto |
|
23449 | 181 |
|
38991 | 182 |
declare [[ sledgehammer_problem_prefix = "Abstraction__map_eq_zipB" ]] |
23449 | 183 |
lemma "map (%w. (w -> w, w \<times> w)) xs = |
184 |
zip (map (%w. w -> w) xs) (map (%w. w \<times> w) xs)" |
|
185 |
apply (induct xs) |
|
36566 | 186 |
apply (metis Nil_is_map_conv zip_Nil) |
187 |
by auto |
|
23449 | 188 |
|
38991 | 189 |
declare [[ sledgehammer_problem_prefix = "Abstraction__image_evenA" ]] |
36566 | 190 |
lemma "(%x. Suc(f x)) ` {x. even x} <= A ==> (\<forall>x. even x --> Suc(f x) \<in> A)" |
191 |
by (metis Collect_def image_subset_iff mem_def) |
|
23449 | 192 |
|
38991 | 193 |
declare [[ sledgehammer_problem_prefix = "Abstraction__image_evenB" ]] |
23449 | 194 |
lemma "(%x. f (f x)) ` ((%x. Suc(f x)) ` {x. even x}) <= A |
195 |
==> (\<forall>x. even x --> f (f (Suc(f x))) \<in> A)"; |
|
36566 | 196 |
by (metis Collect_def imageI image_image image_subset_iff mem_def) |
23449 | 197 |
|
38991 | 198 |
declare [[ sledgehammer_problem_prefix = "Abstraction__image_curry" ]] |
23449 | 199 |
lemma "f \<in> (%u v. b \<times> u \<times> v) ` A ==> \<forall>u v. P (b \<times> u \<times> v) ==> P(f y)" |
36566 | 200 |
(*sledgehammer*) |
23449 | 201 |
by auto |
202 |
||
38991 | 203 |
declare [[ sledgehammer_problem_prefix = "Abstraction__image_TimesA" ]] |
23449 | 204 |
lemma image_TimesA: "(%(x,y). (f x, g y)) ` (A \<times> B) = (f`A) \<times> (g`B)" |
36566 | 205 |
(*sledgehammer*) |
23449 | 206 |
apply (rule equalityI) |
207 |
(***Even the two inclusions are far too difficult |
|
38991 | 208 |
using [[ sledgehammer_problem_prefix = "Abstraction__image_TimesA_simpler"]] |
23449 | 209 |
***) |
210 |
apply (rule subsetI) |
|
211 |
apply (erule imageE) |
|
212 |
(*V manages from here with help: Abstraction__image_TimesA_simpler_1_b.p*) |
|
213 |
apply (erule ssubst) |
|
214 |
apply (erule SigmaE) |
|
215 |
(*V manages from here: Abstraction__image_TimesA_simpler_1_a.p*) |
|
216 |
apply (erule ssubst) |
|
217 |
apply (subst split_conv) |
|
218 |
apply (rule SigmaI) |
|
219 |
apply (erule imageI) + |
|
220 |
txt{*subgoal 2*} |
|
221 |
apply (clarify ); |
|
222 |
apply (simp add: ); |
|
223 |
apply (rule rev_image_eqI) |
|
224 |
apply (blast intro: elim:); |
|
225 |
apply (simp add: ); |
|
226 |
done |
|
227 |
||
228 |
(*Given the difficulty of the previous problem, these two are probably |
|
229 |
impossible*) |
|
230 |
||
38991 | 231 |
declare [[ sledgehammer_problem_prefix = "Abstraction__image_TimesB" ]] |
23449 | 232 |
lemma image_TimesB: |
36566 | 233 |
"(%(x,y,z). (f x, g y, h z)) ` (A \<times> B \<times> C) = (f`A) \<times> (g`B) \<times> (h`C)" |
234 |
(*sledgehammer*) |
|
23449 | 235 |
by force |
236 |
||
38991 | 237 |
declare [[ sledgehammer_problem_prefix = "Abstraction__image_TimesC" ]] |
23449 | 238 |
lemma image_TimesC: |
239 |
"(%(x,y). (x \<rightarrow> x, y \<times> y)) ` (A \<times> B) = |
|
240 |
((%x. x \<rightarrow> x) ` A) \<times> ((%y. y \<times> y) ` B)" |
|
36566 | 241 |
(*sledgehammer*) |
23449 | 242 |
by auto |
243 |
||
244 |
end |