src/HOL/Library/Continuity.thy
author nipkow
Sun Aug 19 21:21:37 2007 +0200 (2007-08-19)
changeset 24331 76f7a8c6e842
parent 23752 15839159f8b6
child 25076 a50b36401c61
permissions -rw-r--r--
Made UN_Un simp
     1 (*  Title:      HOL/Library/Continuity.thy
     2     ID:         $Id$
     3     Author:     David von Oheimb, TU Muenchen
     4 *)
     5 
     6 header {* Continuity and iterations (of set transformers) *}
     7 
     8 theory Continuity
     9 imports Main
    10 begin
    11 
    12 subsection {* Continuity for complete lattices *}
    13 
    14 definition
    15   chain :: "(nat \<Rightarrow> 'a::complete_lattice) \<Rightarrow> bool" where
    16   "chain M \<longleftrightarrow> (\<forall>i. M i \<le> M (Suc i))"
    17 
    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)))"
    21 
    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
    32 
    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
    50 
    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
    84 
    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}. *}
    87 
    88 
    89 subsection "Chains"
    90 
    91 definition
    92   up_chain :: "(nat => 'a set) => bool" where
    93   "up_chain F = (\<forall>i. F i \<subseteq> F (Suc i))"
    94 
    95 lemma up_chainI: "(!!i. F i \<subseteq> F (Suc i)) ==> up_chain F"
    96   by (simp add: up_chain_def)
    97 
    98 lemma up_chainD: "up_chain F ==> F i \<subseteq> F (Suc i)"
    99   by (simp add: up_chain_def)
   100 
   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
   106 
   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
   111 
   112 
   113 definition
   114   down_chain :: "(nat => 'a set) => bool" where
   115   "down_chain F = (\<forall>i. F (Suc i) \<subseteq> F i)"
   116 
   117 lemma down_chainI: "(!!i. F (Suc i) \<subseteq> F i) ==> down_chain F"
   118   by (simp add: down_chain_def)
   119 
   120 lemma down_chainD: "down_chain F ==> F (Suc i) \<subseteq> F i"
   121   by (simp add: down_chain_def)
   122 
   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
   128 
   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
   133 
   134 
   135 subsection "Continuity"
   136 
   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))"
   140 
   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
   146 
   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
   152 
   153 
   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 A else B" 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
   162 
   163 
   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))"
   168 
   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
   175 
   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
   181 
   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 B else A" in down_contD)
   185  apply (rule down_chainI)
   186  apply simp
   187 apply (drule Int_absorb1)
   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^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^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