src/HOL/Library/Continuity.thy
 author chaieb Mon Feb 09 17:21:46 2009 +0000 (2009-02-09) changeset 29847 af32126ee729 parent 27487 c8a6ce181805 child 30663 0b6aff7451b2 permissions -rw-r--r--
1 (*  Title:      HOL/Library/Continuity.thy
2     ID:         \$Id\$
3     Author:     David von Oheimb, TU Muenchen
4 *)
6 header {* Continuity and iterations (of set transformers) *}
8 theory Continuity
9 imports Plain "~~/src/HOL/Relation_Power"
10 begin
12 subsection {* Continuity for complete lattices *}
14 definition
15   chain :: "(nat \<Rightarrow> 'a::complete_lattice) \<Rightarrow> bool" where
16   "chain M \<longleftrightarrow> (\<forall>i. M i \<le> M (Suc i))"
18 definition
19   continuous :: "('a::complete_lattice \<Rightarrow> 'a::complete_lattice) \<Rightarrow> bool" where
20   "continuous F \<longleftrightarrow> (\<forall>M. chain M \<longrightarrow> F (SUP i. M i) = (SUP i. F (M i)))"
22 lemma SUP_nat_conv:
23   "(SUP n. M n) = sup (M 0) (SUP n. M(Suc n))"
24 apply(rule order_antisym)
25  apply(rule SUP_leI)
26  apply(case_tac n)
27   apply simp
28  apply (fast intro:le_SUPI le_supI2)
29 apply(simp)
30 apply (blast intro:SUP_leI le_SUPI)
31 done
33 lemma continuous_mono: fixes F :: "'a::complete_lattice \<Rightarrow> 'a::complete_lattice"
34   assumes "continuous F" shows "mono F"
35 proof
36   fix A B :: "'a" assume "A <= B"
37   let ?C = "%i::nat. if i=0 then A else B"
38   have "chain ?C" using `A <= B` by(simp add:chain_def)
39   have "F B = sup (F A) (F B)"
40   proof -
41     have "sup A B = B" using `A <= B` by (simp add:sup_absorb2)
42     hence "F B = F(SUP i. ?C i)" by (subst SUP_nat_conv) simp
43     also have "\<dots> = (SUP i. F(?C i))"
44       using `chain ?C` `continuous F` by(simp add:continuous_def)
45     also have "\<dots> = sup (F A) (F B)" by (subst SUP_nat_conv) simp
46     finally show ?thesis .
47   qed
48   thus "F A \<le> F B" by(subst le_iff_sup, simp)
49 qed
51 lemma continuous_lfp:
52  assumes "continuous F" shows "lfp F = (SUP i. (F^i) bot)"
53 proof -
54   note mono = continuous_mono[OF `continuous F`]
55   { fix i have "(F^i) bot \<le> lfp F"
56     proof (induct i)
57       show "(F^0) bot \<le> lfp F" by simp
58     next
59       case (Suc i)
60       have "(F^(Suc i)) bot = F((F^i) bot)" by simp
61       also have "\<dots> \<le> F(lfp F)" by(rule monoD[OF mono Suc])
62       also have "\<dots> = lfp F" by(simp add:lfp_unfold[OF mono, symmetric])
63       finally show ?case .
64     qed }
65   hence "(SUP i. (F^i) bot) \<le> lfp F" by (blast intro!:SUP_leI)
66   moreover have "lfp F \<le> (SUP i. (F^i) bot)" (is "_ \<le> ?U")
67   proof (rule lfp_lowerbound)
68     have "chain(%i. (F^i) bot)"
69     proof -
70       { fix i have "(F^i) bot \<le> (F^(Suc i)) bot"
71 	proof (induct i)
72 	  case 0 show ?case by simp
73 	next
74 	  case Suc thus ?case using monoD[OF mono Suc] by auto
75 	qed }
76       thus ?thesis by(auto simp add:chain_def)
77     qed
78     hence "F ?U = (SUP i. (F^(i+1)) bot)" using `continuous F` by (simp add:continuous_def)
79     also have "\<dots> \<le> ?U" by(fast intro:SUP_leI le_SUPI)
80     finally show "F ?U \<le> ?U" .
81   qed
82   ultimately show ?thesis by (blast intro:order_antisym)
83 qed
85 text{* The following development is just for sets but presents an up
86 and a down version of chains and continuity and covers @{const gfp}. *}
89 subsection "Chains"
91 definition
92   up_chain :: "(nat => 'a set) => bool" where
93   "up_chain F = (\<forall>i. F i \<subseteq> F (Suc i))"
95 lemma up_chainI: "(!!i. F i \<subseteq> F (Suc i)) ==> up_chain F"
98 lemma up_chainD: "up_chain F ==> F i \<subseteq> F (Suc i)"
101 lemma up_chain_less_mono:
102     "up_chain F ==> x < y ==> F x \<subseteq> F y"
103   apply (induct y)
104    apply (blast dest: up_chainD elim: less_SucE)+
105   done
107 lemma up_chain_mono: "up_chain F ==> x \<le> y ==> F x \<subseteq> F y"
108   apply (drule le_imp_less_or_eq)
109   apply (blast dest: up_chain_less_mono)
110   done
113 definition
114   down_chain :: "(nat => 'a set) => bool" where
115   "down_chain F = (\<forall>i. F (Suc i) \<subseteq> F i)"
117 lemma down_chainI: "(!!i. F (Suc i) \<subseteq> F i) ==> down_chain F"
120 lemma down_chainD: "down_chain F ==> F (Suc i) \<subseteq> F i"
123 lemma down_chain_less_mono:
124     "down_chain F ==> x < y ==> F y \<subseteq> F x"
125   apply (induct y)
126    apply (blast dest: down_chainD elim: less_SucE)+
127   done
129 lemma down_chain_mono: "down_chain F ==> x \<le> y ==> F y \<subseteq> F x"
130   apply (drule le_imp_less_or_eq)
131   apply (blast dest: down_chain_less_mono)
132   done
135 subsection "Continuity"
137 definition
138   up_cont :: "('a set => 'a set) => bool" where
139   "up_cont f = (\<forall>F. up_chain F --> f (\<Union>(range F)) = \<Union>(f ` range F))"
141 lemma up_contI:
142   "(!!F. up_chain F ==> f (\<Union>(range F)) = \<Union>(f ` range F)) ==> up_cont f"
143 apply (unfold up_cont_def)
144 apply blast
145 done
147 lemma up_contD:
148   "up_cont f ==> up_chain F ==> f (\<Union>(range F)) = \<Union>(f ` range F)"
149 apply (unfold up_cont_def)
150 apply auto
151 done
154 lemma up_cont_mono: "up_cont f ==> mono f"
155 apply (rule monoI)
156 apply (drule_tac F = "\<lambda>i. if i = 0 then x else y" in up_contD)
157  apply (rule up_chainI)
158  apply simp
159 apply (drule Un_absorb1)
160 apply (auto simp add: nat_not_singleton)
161 done
164 definition
165   down_cont :: "('a set => 'a set) => bool" where
166   "down_cont f =
167     (\<forall>F. down_chain F --> f (Inter (range F)) = Inter (f ` range F))"
169 lemma down_contI:
170   "(!!F. down_chain F ==> f (Inter (range F)) = Inter (f ` range F)) ==>
171     down_cont f"
172   apply (unfold down_cont_def)
173   apply blast
174   done
176 lemma down_contD: "down_cont f ==> down_chain F ==>
177     f (Inter (range F)) = Inter (f ` range F)"
178   apply (unfold down_cont_def)
179   apply auto
180   done
182 lemma down_cont_mono: "down_cont f ==> mono f"
183 apply (rule monoI)
184 apply (drule_tac F = "\<lambda>i. if i = 0 then y else x" in down_contD)
185  apply (rule down_chainI)
186  apply simp
187 apply (drule Int_absorb1)
188 apply auto
189 apply (auto simp add: nat_not_singleton)
190 done
193 subsection "Iteration"
195 definition
196   up_iterate :: "('a set => 'a set) => nat => 'a set" where
197   "up_iterate f n = (f^n) {}"
199 lemma up_iterate_0 [simp]: "up_iterate f 0 = {}"
202 lemma up_iterate_Suc [simp]: "up_iterate f (Suc i) = f (up_iterate f i)"
205 lemma up_iterate_chain: "mono F ==> up_chain (up_iterate F)"
206   apply (rule up_chainI)
207   apply (induct_tac i)
208    apply simp+
209   apply (erule (1) monoD)
210   done
212 lemma UNION_up_iterate_is_fp:
213   "up_cont F ==>
214     F (UNION UNIV (up_iterate F)) = UNION UNIV (up_iterate F)"
215   apply (frule up_cont_mono [THEN up_iterate_chain])
216   apply (drule (1) up_contD)
217   apply simp
218   apply (auto simp del: up_iterate_Suc simp add: up_iterate_Suc [symmetric])
219   apply (case_tac xa)
220    apply auto
221   done
223 lemma UNION_up_iterate_lowerbound:
224     "mono F ==> F P = P ==> UNION UNIV (up_iterate F) \<subseteq> P"
225   apply (subgoal_tac "(!!i. up_iterate F i \<subseteq> P)")
226    apply fast
227   apply (induct_tac i)
228   prefer 2 apply (drule (1) monoD)
229    apply auto
230   done
232 lemma UNION_up_iterate_is_lfp:
233     "up_cont F ==> lfp F = UNION UNIV (up_iterate F)"
234   apply (rule set_eq_subset [THEN iffD2])
235   apply (rule conjI)
236    prefer 2
237    apply (drule up_cont_mono)
238    apply (rule UNION_up_iterate_lowerbound)
239     apply assumption
240    apply (erule lfp_unfold [symmetric])
241   apply (rule lfp_lowerbound)
242   apply (rule set_eq_subset [THEN iffD1, THEN conjunct2])
243   apply (erule UNION_up_iterate_is_fp [symmetric])
244   done
247 definition
248   down_iterate :: "('a set => 'a set) => nat => 'a set" where
249   "down_iterate f n = (f^n) UNIV"
251 lemma down_iterate_0 [simp]: "down_iterate f 0 = UNIV"
254 lemma down_iterate_Suc [simp]:
255     "down_iterate f (Suc i) = f (down_iterate f i)"
258 lemma down_iterate_chain: "mono F ==> down_chain (down_iterate F)"
259   apply (rule down_chainI)
260   apply (induct_tac i)
261    apply simp+
262   apply (erule (1) monoD)
263   done
265 lemma INTER_down_iterate_is_fp:
266   "down_cont F ==>
267     F (INTER UNIV (down_iterate F)) = INTER UNIV (down_iterate F)"
268   apply (frule down_cont_mono [THEN down_iterate_chain])
269   apply (drule (1) down_contD)
270   apply simp
271   apply (auto simp del: down_iterate_Suc simp add: down_iterate_Suc [symmetric])
272   apply (case_tac xa)
273    apply auto
274   done
276 lemma INTER_down_iterate_upperbound:
277     "mono F ==> F P = P ==> P \<subseteq> INTER UNIV (down_iterate F)"
278   apply (subgoal_tac "(!!i. P \<subseteq> down_iterate F i)")
279    apply fast
280   apply (induct_tac i)
281   prefer 2 apply (drule (1) monoD)
282    apply auto
283   done
285 lemma INTER_down_iterate_is_gfp:
286     "down_cont F ==> gfp F = INTER UNIV (down_iterate F)"
287   apply (rule set_eq_subset [THEN iffD2])
288   apply (rule conjI)
289    apply (drule down_cont_mono)
290    apply (rule INTER_down_iterate_upperbound)
291     apply assumption
292    apply (erule gfp_unfold [symmetric])
293   apply (rule gfp_upperbound)
294   apply (rule set_eq_subset [THEN iffD1, THEN conjunct2])
295   apply (erule INTER_down_iterate_is_fp)
296   done
298 end