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