author | paulson <lp15@cam.ac.uk> |
Thu, 27 Feb 2014 16:07:21 +0000 | |
changeset 55775 | 1557a391a858 |
parent 55770 | f2cf7f92c9ac |
child 55811 | aa1acc25126b |
permissions | -rw-r--r-- |
55059 | 1 |
(* Title: HOL/BNF_LFP.thy |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
2 |
Author: Dmitriy Traytel, TU Muenchen |
53305 | 3 |
Author: Lorenz Panny, TU Muenchen |
4 |
Author: Jasmin Blanchette, TU Muenchen |
|
5 |
Copyright 2012, 2013 |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
6 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
7 |
Least fixed point operation on bounded natural functors. |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
8 |
*) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
9 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
10 |
header {* Least Fixed Point Operation on Bounded Natural Functors *} |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
11 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
12 |
theory BNF_LFP |
53311 | 13 |
imports BNF_FP_Base |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
14 |
keywords |
53305 | 15 |
"datatype_new" :: thy_decl and |
55575
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents:
55571
diff
changeset
|
16 |
"datatype_compat" :: thy_decl |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
17 |
begin |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
18 |
|
49312 | 19 |
lemma subset_emptyI: "(\<And>x. x \<in> A \<Longrightarrow> False) \<Longrightarrow> A \<subseteq> {}" |
20 |
by blast |
|
21 |
||
22 |
lemma image_Collect_subsetI: |
|
23 |
"(\<And>x. P x \<Longrightarrow> f x \<in> B) \<Longrightarrow> f ` {x. P x} \<subseteq> B" |
|
24 |
by blast |
|
25 |
||
26 |
lemma Collect_restrict: "{x. x \<in> X \<and> P x} \<subseteq> X" |
|
27 |
by auto |
|
28 |
||
29 |
lemma prop_restrict: "\<lbrakk>x \<in> Z; Z \<subseteq> {x. x \<in> X \<and> P x}\<rbrakk> \<Longrightarrow> P x" |
|
30 |
by auto |
|
31 |
||
55023
38db7814481d
get rid of 'rel' locale, to facilitate inclusion of 'Order_Relation_More_FP' into 'Order_Relation'
blanchet
parents:
54841
diff
changeset
|
32 |
lemma underS_I: "\<lbrakk>i \<noteq> j; (i, j) \<in> R\<rbrakk> \<Longrightarrow> i \<in> underS R j" |
38db7814481d
get rid of 'rel' locale, to facilitate inclusion of 'Order_Relation_More_FP' into 'Order_Relation'
blanchet
parents:
54841
diff
changeset
|
33 |
unfolding underS_def by simp |
49312 | 34 |
|
55023
38db7814481d
get rid of 'rel' locale, to facilitate inclusion of 'Order_Relation_More_FP' into 'Order_Relation'
blanchet
parents:
54841
diff
changeset
|
35 |
lemma underS_E: "i \<in> underS R j \<Longrightarrow> i \<noteq> j \<and> (i, j) \<in> R" |
38db7814481d
get rid of 'rel' locale, to facilitate inclusion of 'Order_Relation_More_FP' into 'Order_Relation'
blanchet
parents:
54841
diff
changeset
|
36 |
unfolding underS_def by simp |
49312 | 37 |
|
55023
38db7814481d
get rid of 'rel' locale, to facilitate inclusion of 'Order_Relation_More_FP' into 'Order_Relation'
blanchet
parents:
54841
diff
changeset
|
38 |
lemma underS_Field: "i \<in> underS R j \<Longrightarrow> i \<in> Field R" |
38db7814481d
get rid of 'rel' locale, to facilitate inclusion of 'Order_Relation_More_FP' into 'Order_Relation'
blanchet
parents:
54841
diff
changeset
|
39 |
unfolding underS_def Field_def by auto |
49312 | 40 |
|
41 |
lemma FieldI2: "(i, j) \<in> R \<Longrightarrow> j \<in> Field R" |
|
42 |
unfolding Field_def by auto |
|
43 |
||
44 |
lemma fst_convol': "fst (<f, g> x) = f x" |
|
45 |
using fst_convol unfolding convol_def by simp |
|
46 |
||
47 |
lemma snd_convol': "snd (<f, g> x) = g x" |
|
48 |
using snd_convol unfolding convol_def by simp |
|
49 |
||
50 |
lemma convol_expand_snd: "fst o f = g \<Longrightarrow> <g, snd o f> = f" |
|
51 |
unfolding convol_def by auto |
|
52 |
||
51739
3514b90d0a8b
(co)rec is (just as the (un)fold) the unique morphism;
traytel
parents:
49635
diff
changeset
|
53 |
lemma convol_expand_snd': "(fst o f = g) \<Longrightarrow> (h = snd o f) \<longleftrightarrow> (<g, h> = f)" |
3514b90d0a8b
(co)rec is (just as the (un)fold) the unique morphism;
traytel
parents:
49635
diff
changeset
|
54 |
by (metis convol_expand_snd snd_convol) |
3514b90d0a8b
(co)rec is (just as the (un)fold) the unique morphism;
traytel
parents:
49635
diff
changeset
|
55 |
|
49312 | 56 |
definition inver where |
57 |
"inver g f A = (ALL a : A. g (f a) = a)" |
|
58 |
||
59 |
lemma bij_betw_iff_ex: |
|
60 |
"bij_betw f A B = (EX g. g ` B = A \<and> inver g f A \<and> inver f g B)" (is "?L = ?R") |
|
61 |
proof (rule iffI) |
|
62 |
assume ?L |
|
63 |
hence f: "f ` A = B" and inj_f: "inj_on f A" unfolding bij_betw_def by auto |
|
64 |
let ?phi = "% b a. a : A \<and> f a = b" |
|
65 |
have "ALL b : B. EX a. ?phi b a" using f by blast |
|
66 |
then obtain g where g: "ALL b : B. g b : A \<and> f (g b) = b" |
|
67 |
using bchoice[of B ?phi] by blast |
|
68 |
hence gg: "ALL b : f ` A. g b : A \<and> f (g b) = b" using f by blast |
|
49326 | 69 |
have gf: "inver g f A" unfolding inver_def |
70 |
by (metis (no_types) gg imageI[of _ A f] the_inv_into_f_f[OF inj_f]) |
|
49312 | 71 |
moreover have "g ` B \<le> A \<and> inver f g B" using g unfolding inver_def by blast |
72 |
moreover have "A \<le> g ` B" |
|
73 |
proof safe |
|
74 |
fix a assume a: "a : A" |
|
75 |
hence "f a : B" using f by auto |
|
76 |
moreover have "a = g (f a)" using a gf unfolding inver_def by auto |
|
77 |
ultimately show "a : g ` B" by blast |
|
78 |
qed |
|
79 |
ultimately show ?R by blast |
|
80 |
next |
|
81 |
assume ?R |
|
82 |
then obtain g where g: "g ` B = A \<and> inver g f A \<and> inver f g B" by blast |
|
83 |
show ?L unfolding bij_betw_def |
|
84 |
proof safe |
|
85 |
show "inj_on f A" unfolding inj_on_def |
|
86 |
proof safe |
|
87 |
fix a1 a2 assume a: "a1 : A" "a2 : A" and "f a1 = f a2" |
|
88 |
hence "g (f a1) = g (f a2)" by simp |
|
89 |
thus "a1 = a2" using a g unfolding inver_def by simp |
|
90 |
qed |
|
91 |
next |
|
92 |
fix a assume "a : A" |
|
93 |
then obtain b where b: "b : B" and a: "a = g b" using g by blast |
|
94 |
hence "b = f (g b)" using g unfolding inver_def by auto |
|
95 |
thus "f a : B" unfolding a using b by simp |
|
96 |
next |
|
97 |
fix b assume "b : B" |
|
98 |
hence "g b : A \<and> b = f (g b)" using g unfolding inver_def by auto |
|
99 |
thus "b : f ` A" by auto |
|
100 |
qed |
|
101 |
qed |
|
102 |
||
103 |
lemma bij_betw_ex_weakE: |
|
104 |
"\<lbrakk>bij_betw f A B\<rbrakk> \<Longrightarrow> \<exists>g. g ` B \<subseteq> A \<and> inver g f A \<and> inver f g B" |
|
105 |
by (auto simp only: bij_betw_iff_ex) |
|
106 |
||
107 |
lemma inver_surj: "\<lbrakk>g ` B \<subseteq> A; f ` A \<subseteq> B; inver g f A\<rbrakk> \<Longrightarrow> g ` B = A" |
|
108 |
unfolding inver_def by auto (rule rev_image_eqI, auto) |
|
109 |
||
110 |
lemma inver_mono: "\<lbrakk>A \<subseteq> B; inver f g B\<rbrakk> \<Longrightarrow> inver f g A" |
|
111 |
unfolding inver_def by auto |
|
112 |
||
113 |
lemma inver_pointfree: "inver f g A = (\<forall>a \<in> A. (f o g) a = a)" |
|
114 |
unfolding inver_def by simp |
|
115 |
||
116 |
lemma bij_betwE: "bij_betw f A B \<Longrightarrow> \<forall>a\<in>A. f a \<in> B" |
|
117 |
unfolding bij_betw_def by auto |
|
118 |
||
119 |
lemma bij_betw_imageE: "bij_betw f A B \<Longrightarrow> f ` A = B" |
|
120 |
unfolding bij_betw_def by auto |
|
121 |
||
122 |
lemma inverE: "\<lbrakk>inver f f' A; x \<in> A\<rbrakk> \<Longrightarrow> f (f' x) = x" |
|
123 |
unfolding inver_def by auto |
|
124 |
||
125 |
lemma bij_betw_inver1: "bij_betw f A B \<Longrightarrow> inver (inv_into A f) f A" |
|
126 |
unfolding bij_betw_def inver_def by auto |
|
127 |
||
128 |
lemma bij_betw_inver2: "bij_betw f A B \<Longrightarrow> inver f (inv_into A f) B" |
|
129 |
unfolding bij_betw_def inver_def by auto |
|
130 |
||
131 |
lemma bij_betwI: "\<lbrakk>bij_betw g B A; inver g f A; inver f g B\<rbrakk> \<Longrightarrow> bij_betw f A B" |
|
49326 | 132 |
by (drule bij_betw_imageE, unfold bij_betw_iff_ex) blast |
49312 | 133 |
|
134 |
lemma bij_betwI': |
|
135 |
"\<lbrakk>\<And>x y. \<lbrakk>x \<in> X; y \<in> X\<rbrakk> \<Longrightarrow> (f x = f y) = (x = y); |
|
136 |
\<And>x. x \<in> X \<Longrightarrow> f x \<in> Y; |
|
137 |
\<And>y. y \<in> Y \<Longrightarrow> \<exists>x \<in> X. y = f x\<rbrakk> \<Longrightarrow> bij_betw f X Y" |
|
53695 | 138 |
unfolding bij_betw_def inj_on_def by blast |
49312 | 139 |
|
140 |
lemma surj_fun_eq: |
|
141 |
assumes surj_on: "f ` X = UNIV" and eq_on: "\<forall>x \<in> X. (g1 o f) x = (g2 o f) x" |
|
142 |
shows "g1 = g2" |
|
143 |
proof (rule ext) |
|
144 |
fix y |
|
145 |
from surj_on obtain x where "x \<in> X" and "y = f x" by blast |
|
146 |
thus "g1 y = g2 y" using eq_on by simp |
|
147 |
qed |
|
148 |
||
149 |
lemma Card_order_wo_rel: "Card_order r \<Longrightarrow> wo_rel r" |
|
49514 | 150 |
unfolding wo_rel_def card_order_on_def by blast |
49312 | 151 |
|
152 |
lemma Cinfinite_limit: "\<lbrakk>x \<in> Field r; Cinfinite r\<rbrakk> \<Longrightarrow> |
|
153 |
\<exists>y \<in> Field r. x \<noteq> y \<and> (x, y) \<in> r" |
|
154 |
unfolding cinfinite_def by (auto simp add: infinite_Card_order_limit) |
|
155 |
||
156 |
lemma Card_order_trans: |
|
157 |
"\<lbrakk>Card_order r; x \<noteq> y; (x, y) \<in> r; y \<noteq> z; (y, z) \<in> r\<rbrakk> \<Longrightarrow> x \<noteq> z \<and> (x, z) \<in> r" |
|
158 |
unfolding card_order_on_def well_order_on_def linear_order_on_def |
|
159 |
partial_order_on_def preorder_on_def trans_def antisym_def by blast |
|
160 |
||
161 |
lemma Cinfinite_limit2: |
|
162 |
assumes x1: "x1 \<in> Field r" and x2: "x2 \<in> Field r" and r: "Cinfinite r" |
|
163 |
shows "\<exists>y \<in> Field r. (x1 \<noteq> y \<and> (x1, y) \<in> r) \<and> (x2 \<noteq> y \<and> (x2, y) \<in> r)" |
|
164 |
proof - |
|
165 |
from r have trans: "trans r" and total: "Total r" and antisym: "antisym r" |
|
166 |
unfolding card_order_on_def well_order_on_def linear_order_on_def |
|
167 |
partial_order_on_def preorder_on_def by auto |
|
168 |
obtain y1 where y1: "y1 \<in> Field r" "x1 \<noteq> y1" "(x1, y1) \<in> r" |
|
169 |
using Cinfinite_limit[OF x1 r] by blast |
|
170 |
obtain y2 where y2: "y2 \<in> Field r" "x2 \<noteq> y2" "(x2, y2) \<in> r" |
|
171 |
using Cinfinite_limit[OF x2 r] by blast |
|
172 |
show ?thesis |
|
173 |
proof (cases "y1 = y2") |
|
174 |
case True with y1 y2 show ?thesis by blast |
|
175 |
next |
|
176 |
case False |
|
177 |
with y1(1) y2(1) total have "(y1, y2) \<in> r \<or> (y2, y1) \<in> r" |
|
178 |
unfolding total_on_def by auto |
|
179 |
thus ?thesis |
|
180 |
proof |
|
181 |
assume *: "(y1, y2) \<in> r" |
|
182 |
with trans y1(3) have "(x1, y2) \<in> r" unfolding trans_def by blast |
|
183 |
with False y1 y2 * antisym show ?thesis by (cases "x1 = y2") (auto simp: antisym_def) |
|
184 |
next |
|
185 |
assume *: "(y2, y1) \<in> r" |
|
186 |
with trans y2(3) have "(x2, y1) \<in> r" unfolding trans_def by blast |
|
187 |
with False y1 y2 * antisym show ?thesis by (cases "x2 = y1") (auto simp: antisym_def) |
|
188 |
qed |
|
189 |
qed |
|
190 |
qed |
|
191 |
||
192 |
lemma Cinfinite_limit_finite: "\<lbrakk>finite X; X \<subseteq> Field r; Cinfinite r\<rbrakk> |
|
193 |
\<Longrightarrow> \<exists>y \<in> Field r. \<forall>x \<in> X. (x \<noteq> y \<and> (x, y) \<in> r)" |
|
194 |
proof (induct X rule: finite_induct) |
|
195 |
case empty thus ?case unfolding cinfinite_def using ex_in_conv[of "Field r"] finite.emptyI by auto |
|
196 |
next |
|
197 |
case (insert x X) |
|
198 |
then obtain y where y: "y \<in> Field r" "\<forall>x \<in> X. (x \<noteq> y \<and> (x, y) \<in> r)" by blast |
|
199 |
then obtain z where z: "z \<in> Field r" "x \<noteq> z \<and> (x, z) \<in> r" "y \<noteq> z \<and> (y, z) \<in> r" |
|
200 |
using Cinfinite_limit2[OF _ y(1) insert(5), of x] insert(4) by blast |
|
49326 | 201 |
show ?case |
202 |
apply (intro bexI ballI) |
|
203 |
apply (erule insertE) |
|
204 |
apply hypsubst |
|
205 |
apply (rule z(2)) |
|
206 |
using Card_order_trans[OF insert(5)[THEN conjunct2]] y(2) z(3) |
|
207 |
apply blast |
|
208 |
apply (rule z(1)) |
|
209 |
done |
|
49312 | 210 |
qed |
211 |
||
212 |
lemma insert_subsetI: "\<lbrakk>x \<in> A; X \<subseteq> A\<rbrakk> \<Longrightarrow> insert x X \<subseteq> A" |
|
213 |
by auto |
|
214 |
||
215 |
(*helps resolution*) |
|
216 |
lemma well_order_induct_imp: |
|
217 |
"wo_rel r \<Longrightarrow> (\<And>x. \<forall>y. y \<noteq> x \<and> (y, x) \<in> r \<longrightarrow> y \<in> Field r \<longrightarrow> P y \<Longrightarrow> x \<in> Field r \<longrightarrow> P x) \<Longrightarrow> |
|
218 |
x \<in> Field r \<longrightarrow> P x" |
|
219 |
by (erule wo_rel.well_order_induct) |
|
220 |
||
221 |
lemma meta_spec2: |
|
222 |
assumes "(\<And>x y. PROP P x y)" |
|
223 |
shows "PROP P x y" |
|
55084 | 224 |
by (rule assms) |
49312 | 225 |
|
54841
af71b753c459
express weak pullback property of bnfs only in terms of the relator
traytel
parents:
54246
diff
changeset
|
226 |
lemma nchotomy_relcomppE: |
55066 | 227 |
"\<lbrakk>\<And>y. \<exists>x. y = f x; (r OO s) a c; \<And>b. r a (f b) \<Longrightarrow> s (f b) c \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P" |
54841
af71b753c459
express weak pullback property of bnfs only in terms of the relator
traytel
parents:
54246
diff
changeset
|
228 |
by (metis relcompp.cases) |
af71b753c459
express weak pullback property of bnfs only in terms of the relator
traytel
parents:
54246
diff
changeset
|
229 |
|
55066 | 230 |
lemma vimage2p_fun_rel: "fun_rel (vimage2p f g R) R f g" |
52731 | 231 |
unfolding fun_rel_def vimage2p_def by auto |
232 |
||
233 |
lemma predicate2D_vimage2p: "\<lbrakk>R \<le> vimage2p f g S; R x y\<rbrakk> \<Longrightarrow> S (f x) (g y)" |
|
234 |
unfolding vimage2p_def by auto |
|
235 |
||
55084 | 236 |
lemma id_transfer: "fun_rel A A id id" |
237 |
unfolding fun_rel_def by simp |
|
238 |
||
55770
f2cf7f92c9ac
intermediate typedef for the type of the bound (local to lfp)
traytel
parents:
55575
diff
changeset
|
239 |
lemma ssubst_Pair_rhs: "\<lbrakk>(r, s) \<in> R; s' = s\<rbrakk> \<Longrightarrow> (r, s') \<in> R" |
f2cf7f92c9ac
intermediate typedef for the type of the bound (local to lfp)
traytel
parents:
55575
diff
changeset
|
240 |
by simp |
f2cf7f92c9ac
intermediate typedef for the type of the bound (local to lfp)
traytel
parents:
55575
diff
changeset
|
241 |
|
55062 | 242 |
ML_file "Tools/BNF/bnf_lfp_util.ML" |
243 |
ML_file "Tools/BNF/bnf_lfp_tactics.ML" |
|
244 |
ML_file "Tools/BNF/bnf_lfp.ML" |
|
245 |
ML_file "Tools/BNF/bnf_lfp_compat.ML" |
|
55571 | 246 |
ML_file "Tools/BNF/bnf_lfp_rec_sugar_more.ML" |
49309
f20b24214ac2
split basic BNFs into really basic ones and others, and added Andreas Lochbihler's "option" BNF
blanchet
parents:
49308
diff
changeset
|
247 |
|
55084 | 248 |
hide_fact (open) id_transfer |
249 |
||
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
250 |
end |