wenzelm@33027
|
1 |
(* Title: HOL/Metis_Examples/Abstraction.thy
|
blanchet@44038
|
2 |
Author: Lawrence C. Paulson, Cambridge University Computer Laboratory
|
blanchet@41392
|
3 |
Author: Jasmin Blanchette, TU Muenchen
|
paulson@23449
|
4 |
|
blanchet@44038
|
5 |
Example featuring Metis's support for lambda-abstractions.
|
paulson@23449
|
6 |
*)
|
paulson@23449
|
7 |
|
blanchet@44038
|
8 |
header {* Example Featuring Metis's Support for Lambda-Abstractions *}
|
blanchet@44038
|
9 |
|
haftmann@27368
|
10 |
theory Abstraction
|
blanchet@46443
|
11 |
imports "~~/src/HOL/Library/FuncSet"
|
paulson@23449
|
12 |
begin
|
paulson@23449
|
13 |
|
blanchet@46433
|
14 |
(* For Christoph Benzmüller *)
|
blanchet@46433
|
15 |
lemma "x < 1 \<and> ((op =) = (op =)) \<Longrightarrow> ((op =) = (op =)) \<and> x < (2::nat)"
|
blanchet@46433
|
16 |
by (metis nat_1_add_1 trans_less_add2)
|
paulson@23449
|
17 |
|
blanchet@46443
|
18 |
lemma "(op = ) = (\<lambda>x y. y = x)"
|
blanchet@46433
|
19 |
by metis
|
paulson@23449
|
20 |
|
paulson@23449
|
21 |
consts
|
paulson@23449
|
22 |
monotone :: "['a => 'a, 'a set, ('a *'a)set] => bool"
|
paulson@23449
|
23 |
pset :: "'a set => 'a set"
|
paulson@23449
|
24 |
order :: "'a set => ('a * 'a) set"
|
paulson@23449
|
25 |
|
blanchet@46443
|
26 |
lemma "a \<in> {x. P x} \<Longrightarrow> P a"
|
blanchet@36564
|
27 |
proof -
|
blanchet@36564
|
28 |
assume "a \<in> {x. P x}"
|
blanchet@36564
|
29 |
hence "a \<in> P" by (metis Collect_def)
|
blanchet@46433
|
30 |
thus "P a" by (metis mem_def)
|
paulson@23449
|
31 |
qed
|
paulson@23449
|
32 |
|
blanchet@46443
|
33 |
lemma Collect_triv: "a \<in> {x. P x} \<Longrightarrow> P a"
|
berghofe@23756
|
34 |
by (metis mem_Collect_eq)
|
paulson@23449
|
35 |
|
blanchet@46443
|
36 |
lemma "a \<in> {x. P x --> Q x} \<Longrightarrow> a \<in> {x. P x} \<Longrightarrow> a \<in> {x. Q x}"
|
blanchet@46433
|
37 |
by (metis Collect_imp_eq ComplD UnE)
|
paulson@23449
|
38 |
|
blanchet@46443
|
39 |
lemma "(a, b) \<in> Sigma A B \<Longrightarrow> a \<in> A & b \<in> B a"
|
blanchet@36564
|
40 |
proof -
|
blanchet@36564
|
41 |
assume A1: "(a, b) \<in> Sigma A B"
|
blanchet@36564
|
42 |
hence F1: "b \<in> B a" by (metis mem_Sigma_iff)
|
blanchet@36564
|
43 |
have F2: "a \<in> A" by (metis A1 mem_Sigma_iff)
|
blanchet@36564
|
44 |
have "b \<in> B a" by (metis F1)
|
blanchet@36564
|
45 |
thus "a \<in> A \<and> b \<in> B a" by (metis F2)
|
paulson@23449
|
46 |
qed
|
paulson@23449
|
47 |
|
blanchet@46443
|
48 |
lemma Sigma_triv: "(a, b) \<in> Sigma A B \<Longrightarrow> a \<in> A & b \<in> B a"
|
paulson@23449
|
49 |
by (metis SigmaD1 SigmaD2)
|
paulson@23449
|
50 |
|
blanchet@36564
|
51 |
lemma "(a, b) \<in> (SIGMA x:A. {y. x = f y}) \<Longrightarrow> a \<in> A \<and> a = f b"
|
blanchet@46443
|
52 |
by (metis (full_types, lam_lifting) CollectD SigmaD1 SigmaD2)
|
paulson@24827
|
53 |
|
blanchet@36564
|
54 |
lemma "(a, b) \<in> (SIGMA x:A. {y. x = f y}) \<Longrightarrow> a \<in> A \<and> a = f b"
|
blanchet@36564
|
55 |
proof -
|
blanchet@36564
|
56 |
assume A1: "(a, b) \<in> (SIGMA x:A. {y. x = f y})"
|
blanchet@36564
|
57 |
hence F1: "a \<in> A" by (metis mem_Sigma_iff)
|
blanchet@36564
|
58 |
have "b \<in> {R. a = f R}" by (metis A1 mem_Sigma_iff)
|
blanchet@36564
|
59 |
hence F2: "b \<in> (\<lambda>R. a = f R)" by (metis Collect_def)
|
blanchet@36564
|
60 |
hence "a = f b" by (unfold mem_def)
|
blanchet@36564
|
61 |
thus "a \<in> A \<and> a = f b" by (metis F1)
|
paulson@24827
|
62 |
qed
|
paulson@23449
|
63 |
|
blanchet@46443
|
64 |
lemma "(cl, f) \<in> CLF \<Longrightarrow> CLF = (SIGMA cl: CL.{f. f \<in> pset cl}) \<Longrightarrow> f \<in> pset cl"
|
paulson@24827
|
65 |
by (metis Collect_mem_eq SigmaD2)
|
paulson@23449
|
66 |
|
blanchet@46443
|
67 |
lemma "(cl, f) \<in> CLF \<Longrightarrow> CLF = (SIGMA cl: CL.{f. f \<in> pset cl}) \<Longrightarrow> f \<in> pset cl"
|
blanchet@36564
|
68 |
proof -
|
blanchet@36564
|
69 |
assume A1: "(cl, f) \<in> CLF"
|
blanchet@36564
|
70 |
assume A2: "CLF = (SIGMA cl:CL. {f. f \<in> pset cl})"
|
blanchet@36564
|
71 |
have F1: "\<forall>v. (\<lambda>R. R \<in> v) = v" by (metis Collect_mem_eq Collect_def)
|
blanchet@36564
|
72 |
have "\<forall>v u. (u, v) \<in> CLF \<longrightarrow> v \<in> {R. R \<in> pset u}" by (metis A2 mem_Sigma_iff)
|
blanchet@36564
|
73 |
hence "\<forall>v u. (u, v) \<in> CLF \<longrightarrow> v \<in> pset u" by (metis F1 Collect_def)
|
blanchet@46443
|
74 |
thus "f \<in> pset cl" by (metis A1)
|
paulson@24827
|
75 |
qed
|
paulson@23449
|
76 |
|
paulson@23449
|
77 |
lemma
|
blanchet@46443
|
78 |
"(cl, f) \<in> (SIGMA cl: CL. {f. f \<in> pset cl \<rightarrow> pset cl}) \<Longrightarrow>
|
blanchet@46443
|
79 |
f \<in> pset cl \<rightarrow> pset cl"
|
blanchet@46433
|
80 |
by (metis (no_types) Collect_def Sigma_triv mem_def)
|
blanchet@46433
|
81 |
|
blanchet@46433
|
82 |
lemma
|
blanchet@46443
|
83 |
"(cl, f) \<in> (SIGMA cl: CL. {f. f \<in> pset cl \<rightarrow> pset cl}) \<Longrightarrow>
|
blanchet@46443
|
84 |
f \<in> pset cl \<rightarrow> pset cl"
|
blanchet@36564
|
85 |
proof -
|
blanchet@36564
|
86 |
assume A1: "(cl, f) \<in> (SIGMA cl:CL. {f. f \<in> pset cl \<rightarrow> pset cl})"
|
blanchet@36564
|
87 |
have F1: "\<forall>v. (\<lambda>R. R \<in> v) = v" by (metis Collect_mem_eq Collect_def)
|
blanchet@36564
|
88 |
have "f \<in> {R. R \<in> pset cl \<rightarrow> pset cl}" using A1 by simp
|
blanchet@46443
|
89 |
thus "f \<in> pset cl \<rightarrow> pset cl" by (metis F1 Collect_def)
|
paulson@24827
|
90 |
qed
|
paulson@23449
|
91 |
|
paulson@23449
|
92 |
lemma
|
blanchet@46443
|
93 |
"(cl, f) \<in> (SIGMA cl: CL. {f. f \<in> pset cl \<inter> cl}) \<Longrightarrow>
|
blanchet@46443
|
94 |
f \<in> pset cl \<inter> cl"
|
blanchet@46433
|
95 |
by (metis (no_types) Collect_conj_eq Int_def Sigma_triv inf_idem)
|
blanchet@46433
|
96 |
|
blanchet@46433
|
97 |
lemma
|
blanchet@46443
|
98 |
"(cl, f) \<in> (SIGMA cl: CL. {f. f \<in> pset cl \<inter> cl}) \<Longrightarrow>
|
blanchet@46443
|
99 |
f \<in> pset cl \<inter> cl"
|
blanchet@36564
|
100 |
proof -
|
blanchet@36564
|
101 |
assume A1: "(cl, f) \<in> (SIGMA cl:CL. {f. f \<in> pset cl \<inter> cl})"
|
blanchet@36564
|
102 |
have F1: "\<forall>v. (\<lambda>R. R \<in> v) = v" by (metis Collect_mem_eq Collect_def)
|
blanchet@36564
|
103 |
have "f \<in> {R. R \<in> pset cl \<inter> cl}" using A1 by simp
|
blanchet@36564
|
104 |
hence "f \<in> Id_on cl `` pset cl" by (metis F1 Int_commute Image_Id_on Collect_def)
|
blanchet@36564
|
105 |
hence "f \<in> Id_on cl `` pset cl" by metis
|
blanchet@36564
|
106 |
hence "f \<in> cl \<inter> pset cl" by (metis Image_Id_on)
|
blanchet@36564
|
107 |
thus "f \<in> pset cl \<inter> cl" by (metis Int_commute)
|
paulson@24827
|
108 |
qed
|
paulson@24827
|
109 |
|
paulson@23449
|
110 |
lemma
|
blanchet@46443
|
111 |
"(cl, f) \<in> (SIGMA cl: CL. {f. f \<in> pset cl \<rightarrow> pset cl & monotone f (pset cl) (order cl)}) \<Longrightarrow>
|
paulson@23449
|
112 |
(f \<in> pset cl \<rightarrow> pset cl) & (monotone f (pset cl) (order cl))"
|
paulson@23449
|
113 |
by auto
|
paulson@23449
|
114 |
|
blanchet@46443
|
115 |
lemma
|
blanchet@46443
|
116 |
"(cl, f) \<in> CLF \<Longrightarrow>
|
blanchet@46443
|
117 |
CLF \<subseteq> (SIGMA cl: CL. {f. f \<in> pset cl \<inter> cl}) \<Longrightarrow>
|
paulson@23449
|
118 |
f \<in> pset cl \<inter> cl"
|
blanchet@46443
|
119 |
by (metis (lam_lifting) Collect_def Sigma_triv mem_def subsetD)
|
blanchet@46443
|
120 |
|
blanchet@46443
|
121 |
lemma
|
blanchet@46443
|
122 |
"(cl, f) \<in> CLF \<Longrightarrow>
|
blanchet@46443
|
123 |
CLF = (SIGMA cl: CL. {f. f \<in> pset cl \<inter> cl}) \<Longrightarrow>
|
blanchet@46443
|
124 |
f \<in> pset cl \<inter> cl"
|
blanchet@46443
|
125 |
by (metis (lam_lifting) Int_Collect SigmaD2 inf1I mem_def)
|
blanchet@46443
|
126 |
|
blanchet@46443
|
127 |
lemma
|
blanchet@46443
|
128 |
"(cl, f) \<in> CLF \<Longrightarrow>
|
blanchet@46443
|
129 |
CLF \<subseteq> (SIGMA cl': CL. {f. f \<in> pset cl' \<rightarrow> pset cl'}) \<Longrightarrow>
|
blanchet@46443
|
130 |
f \<in> pset cl \<rightarrow> pset cl"
|
blanchet@46443
|
131 |
by (metis (lam_lifting) Collect_def Sigma_triv mem_def subsetD)
|
blanchet@46443
|
132 |
|
blanchet@46443
|
133 |
lemma
|
blanchet@46443
|
134 |
"(cl, f) \<in> CLF \<Longrightarrow>
|
blanchet@46443
|
135 |
CLF = (SIGMA cl: CL. {f. f \<in> pset cl \<rightarrow> pset cl}) \<Longrightarrow>
|
blanchet@46443
|
136 |
f \<in> pset cl \<rightarrow> pset cl"
|
blanchet@46443
|
137 |
by (metis (lam_lifting) Collect_def Sigma_triv mem_def)
|
blanchet@46443
|
138 |
|
blanchet@46443
|
139 |
lemma
|
blanchet@46443
|
140 |
"(cl, f) \<in> CLF \<Longrightarrow>
|
blanchet@46443
|
141 |
CLF = (SIGMA cl: CL. {f. f \<in> pset cl \<rightarrow> pset cl & monotone f (pset cl) (order cl)}) \<Longrightarrow>
|
blanchet@46443
|
142 |
(f \<in> pset cl \<rightarrow> pset cl) & (monotone f (pset cl) (order cl))"
|
paulson@24827
|
143 |
by auto
|
haftmann@27368
|
144 |
|
blanchet@46443
|
145 |
lemma "map (\<lambda>x. (f x, g x)) xs = zip (map f xs) (map g xs)"
|
paulson@23449
|
146 |
apply (induct xs)
|
blanchet@46433
|
147 |
apply (metis map.simps(1) zip_Nil)
|
blanchet@36564
|
148 |
by auto
|
paulson@23449
|
149 |
|
blanchet@46443
|
150 |
lemma
|
blanchet@46443
|
151 |
"map (\<lambda>w. (w -> w, w \<times> w)) xs =
|
blanchet@46443
|
152 |
zip (map (\<lambda>w. w -> w) xs) (map (\<lambda>w. w \<times> w) xs)"
|
blanchet@46443
|
153 |
apply (induct xs)
|
blanchet@46443
|
154 |
apply (metis map.simps(1) zip_Nil)
|
blanchet@46443
|
155 |
by auto
|
blanchet@46443
|
156 |
|
blanchet@46443
|
157 |
lemma "(\<lambda>x. Suc (f x)) ` {x. even x} \<subseteq> A \<Longrightarrow> \<forall>x. even x --> Suc (f x) \<in> A"
|
blanchet@46433
|
158 |
by (metis Collect_def image_eqI mem_def subsetD)
|
paulson@23449
|
159 |
|
blanchet@46443
|
160 |
lemma
|
blanchet@46443
|
161 |
"(\<lambda>x. f (f x)) ` ((\<lambda>x. Suc(f x)) ` {x. even x}) \<subseteq> A \<Longrightarrow>
|
blanchet@46443
|
162 |
(\<forall>x. even x --> f (f (Suc(f x))) \<in> A)"
|
blanchet@46433
|
163 |
by (metis Collect_def imageI mem_def set_rev_mp)
|
paulson@23449
|
164 |
|
blanchet@46443
|
165 |
lemma "f \<in> (\<lambda>u v. b \<times> u \<times> v) ` A \<Longrightarrow> \<forall>u v. P (b \<times> u \<times> v) \<Longrightarrow> P(f y)"
|
blanchet@46443
|
166 |
by (metis (lam_lifting) imageE)
|
paulson@23449
|
167 |
|
blanchet@46443
|
168 |
lemma image_TimesA: "(\<lambda>(x, y). (f x, g y)) ` (A \<times> B) = (f ` A) \<times> (g ` B)"
|
blanchet@46433
|
169 |
by (metis map_pair_def map_pair_surj_on)
|
paulson@23449
|
170 |
|
paulson@23449
|
171 |
lemma image_TimesB:
|
blanchet@46443
|
172 |
"(\<lambda>(x, y, z). (f x, g y, h z)) ` (A \<times> B \<times> C) = (f ` A) \<times> (g ` B) \<times> (h ` C)"
|
paulson@23449
|
173 |
by force
|
paulson@23449
|
174 |
|
paulson@23449
|
175 |
lemma image_TimesC:
|
blanchet@46443
|
176 |
"(\<lambda>(x, y). (x \<rightarrow> x, y \<times> y)) ` (A \<times> B) =
|
blanchet@46443
|
177 |
((\<lambda>x. x \<rightarrow> x) ` A) \<times> ((\<lambda>y. y \<times> y) ` B)"
|
blanchet@46433
|
178 |
by (metis image_TimesA)
|
paulson@23449
|
179 |
|
paulson@23449
|
180 |
end
|