src/HOL/HOLCF/Cont.thy
author kuncar
Fri Dec 09 18:07:04 2011 +0100 (2011-12-09)
changeset 45802 b16f976db515
parent 45294 3c5d3d286055
child 57945 cacb00a569e0
permissions -rw-r--r--
Quotient_Info stores only relation maps
     1 (*  Title:      HOL/HOLCF/Cont.thy
     2     Author:     Franz Regensburger
     3     Author:     Brian Huffman
     4 *)
     5 
     6 header {* Continuity and monotonicity *}
     7 
     8 theory Cont
     9 imports Pcpo
    10 begin
    11 
    12 text {*
    13    Now we change the default class! Form now on all untyped type variables are
    14    of default class po
    15 *}
    16 
    17 default_sort po
    18 
    19 subsection {* Definitions *}
    20 
    21 definition
    22   monofun :: "('a \<Rightarrow> 'b) \<Rightarrow> bool"  -- "monotonicity"  where
    23   "monofun f = (\<forall>x y. x \<sqsubseteq> y \<longrightarrow> f x \<sqsubseteq> f y)"
    24 
    25 definition
    26   cont :: "('a::cpo \<Rightarrow> 'b::cpo) \<Rightarrow> bool"
    27 where
    28   "cont f = (\<forall>Y. chain Y \<longrightarrow> range (\<lambda>i. f (Y i)) <<| f (\<Squnion>i. Y i))"
    29 
    30 lemma contI:
    31   "\<lbrakk>\<And>Y. chain Y \<Longrightarrow> range (\<lambda>i. f (Y i)) <<| f (\<Squnion>i. Y i)\<rbrakk> \<Longrightarrow> cont f"
    32 by (simp add: cont_def)
    33 
    34 lemma contE:
    35   "\<lbrakk>cont f; chain Y\<rbrakk> \<Longrightarrow> range (\<lambda>i. f (Y i)) <<| f (\<Squnion>i. Y i)"
    36 by (simp add: cont_def)
    37 
    38 lemma monofunI: 
    39   "\<lbrakk>\<And>x y. x \<sqsubseteq> y \<Longrightarrow> f x \<sqsubseteq> f y\<rbrakk> \<Longrightarrow> monofun f"
    40 by (simp add: monofun_def)
    41 
    42 lemma monofunE: 
    43   "\<lbrakk>monofun f; x \<sqsubseteq> y\<rbrakk> \<Longrightarrow> f x \<sqsubseteq> f y"
    44 by (simp add: monofun_def)
    45 
    46 
    47 subsection {* Equivalence of alternate definition *}
    48 
    49 text {* monotone functions map chains to chains *}
    50 
    51 lemma ch2ch_monofun: "\<lbrakk>monofun f; chain Y\<rbrakk> \<Longrightarrow> chain (\<lambda>i. f (Y i))"
    52 apply (rule chainI)
    53 apply (erule monofunE)
    54 apply (erule chainE)
    55 done
    56 
    57 text {* monotone functions map upper bound to upper bounds *}
    58 
    59 lemma ub2ub_monofun: 
    60   "\<lbrakk>monofun f; range Y <| u\<rbrakk> \<Longrightarrow> range (\<lambda>i. f (Y i)) <| f u"
    61 apply (rule ub_rangeI)
    62 apply (erule monofunE)
    63 apply (erule ub_rangeD)
    64 done
    65 
    66 text {* a lemma about binary chains *}
    67 
    68 lemma binchain_cont:
    69   "\<lbrakk>cont f; x \<sqsubseteq> y\<rbrakk> \<Longrightarrow> range (\<lambda>i::nat. f (if i = 0 then x else y)) <<| f y"
    70 apply (subgoal_tac "f (\<Squnion>i::nat. if i = 0 then x else y) = f y")
    71 apply (erule subst)
    72 apply (erule contE)
    73 apply (erule bin_chain)
    74 apply (rule_tac f=f in arg_cong)
    75 apply (erule is_lub_bin_chain [THEN lub_eqI])
    76 done
    77 
    78 text {* continuity implies monotonicity *}
    79 
    80 lemma cont2mono: "cont f \<Longrightarrow> monofun f"
    81 apply (rule monofunI)
    82 apply (drule (1) binchain_cont)
    83 apply (drule_tac i=0 in is_lub_rangeD1)
    84 apply simp
    85 done
    86 
    87 lemmas cont2monofunE = cont2mono [THEN monofunE]
    88 
    89 lemmas ch2ch_cont = cont2mono [THEN ch2ch_monofun]
    90 
    91 text {* continuity implies preservation of lubs *}
    92 
    93 lemma cont2contlubE:
    94   "\<lbrakk>cont f; chain Y\<rbrakk> \<Longrightarrow> f (\<Squnion> i. Y i) = (\<Squnion> i. f (Y i))"
    95 apply (rule lub_eqI [symmetric])
    96 apply (erule (1) contE)
    97 done
    98 
    99 lemma contI2:
   100   fixes f :: "'a::cpo \<Rightarrow> 'b::cpo"
   101   assumes mono: "monofun f"
   102   assumes below: "\<And>Y. \<lbrakk>chain Y; chain (\<lambda>i. f (Y i))\<rbrakk>
   103      \<Longrightarrow> f (\<Squnion>i. Y i) \<sqsubseteq> (\<Squnion>i. f (Y i))"
   104   shows "cont f"
   105 proof (rule contI)
   106   fix Y :: "nat \<Rightarrow> 'a"
   107   assume Y: "chain Y"
   108   with mono have fY: "chain (\<lambda>i. f (Y i))"
   109     by (rule ch2ch_monofun)
   110   have "(\<Squnion>i. f (Y i)) = f (\<Squnion>i. Y i)"
   111     apply (rule below_antisym)
   112     apply (rule lub_below [OF fY])
   113     apply (rule monofunE [OF mono])
   114     apply (rule is_ub_thelub [OF Y])
   115     apply (rule below [OF Y fY])
   116     done
   117   with fY show "range (\<lambda>i. f (Y i)) <<| f (\<Squnion>i. Y i)"
   118     by (rule thelubE)
   119 qed
   120 
   121 subsection {* Collection of continuity rules *}
   122 
   123 ML {*
   124 structure Cont2ContData = Named_Thms
   125 (
   126   val name = @{binding cont2cont}
   127   val description = "continuity intro rule"
   128 )
   129 *}
   130 
   131 setup Cont2ContData.setup
   132 
   133 subsection {* Continuity of basic functions *}
   134 
   135 text {* The identity function is continuous *}
   136 
   137 lemma cont_id [simp, cont2cont]: "cont (\<lambda>x. x)"
   138 apply (rule contI)
   139 apply (erule cpo_lubI)
   140 done
   141 
   142 text {* constant functions are continuous *}
   143 
   144 lemma cont_const [simp, cont2cont]: "cont (\<lambda>x. c)"
   145   using is_lub_const by (rule contI)
   146 
   147 text {* application of functions is continuous *}
   148 
   149 lemma cont_apply:
   150   fixes f :: "'a::cpo \<Rightarrow> 'b::cpo \<Rightarrow> 'c::cpo" and t :: "'a \<Rightarrow> 'b"
   151   assumes 1: "cont (\<lambda>x. t x)"
   152   assumes 2: "\<And>x. cont (\<lambda>y. f x y)"
   153   assumes 3: "\<And>y. cont (\<lambda>x. f x y)"
   154   shows "cont (\<lambda>x. (f x) (t x))"
   155 proof (rule contI2 [OF monofunI])
   156   fix x y :: "'a" assume "x \<sqsubseteq> y"
   157   then show "f x (t x) \<sqsubseteq> f y (t y)"
   158     by (auto intro: cont2monofunE [OF 1]
   159                     cont2monofunE [OF 2]
   160                     cont2monofunE [OF 3]
   161                     below_trans)
   162 next
   163   fix Y :: "nat \<Rightarrow> 'a" assume "chain Y"
   164   then show "f (\<Squnion>i. Y i) (t (\<Squnion>i. Y i)) \<sqsubseteq> (\<Squnion>i. f (Y i) (t (Y i)))"
   165     by (simp only: cont2contlubE [OF 1] ch2ch_cont [OF 1]
   166                    cont2contlubE [OF 2] ch2ch_cont [OF 2]
   167                    cont2contlubE [OF 3] ch2ch_cont [OF 3]
   168                    diag_lub below_refl)
   169 qed
   170 
   171 lemma cont_compose:
   172   "\<lbrakk>cont c; cont (\<lambda>x. f x)\<rbrakk> \<Longrightarrow> cont (\<lambda>x. c (f x))"
   173 by (rule cont_apply [OF _ _ cont_const])
   174 
   175 text {* Least upper bounds preserve continuity *}
   176 
   177 lemma cont2cont_lub [simp]:
   178   assumes chain: "\<And>x. chain (\<lambda>i. F i x)" and cont: "\<And>i. cont (\<lambda>x. F i x)"
   179   shows "cont (\<lambda>x. \<Squnion>i. F i x)"
   180 apply (rule contI2)
   181 apply (simp add: monofunI cont2monofunE [OF cont] lub_mono chain)
   182 apply (simp add: cont2contlubE [OF cont])
   183 apply (simp add: diag_lub ch2ch_cont [OF cont] chain)
   184 done
   185 
   186 text {* if-then-else is continuous *}
   187 
   188 lemma cont_if [simp, cont2cont]:
   189   "\<lbrakk>cont f; cont g\<rbrakk> \<Longrightarrow> cont (\<lambda>x. if b then f x else g x)"
   190 by (induct b) simp_all
   191 
   192 subsection {* Finite chains and flat pcpos *}
   193 
   194 text {* Monotone functions map finite chains to finite chains. *}
   195 
   196 lemma monofun_finch2finch:
   197   "\<lbrakk>monofun f; finite_chain Y\<rbrakk> \<Longrightarrow> finite_chain (\<lambda>n. f (Y n))"
   198 apply (unfold finite_chain_def)
   199 apply (simp add: ch2ch_monofun)
   200 apply (force simp add: max_in_chain_def)
   201 done
   202 
   203 text {* The same holds for continuous functions. *}
   204 
   205 lemma cont_finch2finch:
   206   "\<lbrakk>cont f; finite_chain Y\<rbrakk> \<Longrightarrow> finite_chain (\<lambda>n. f (Y n))"
   207 by (rule cont2mono [THEN monofun_finch2finch])
   208 
   209 text {* All monotone functions with chain-finite domain are continuous. *}
   210 
   211 lemma chfindom_monofun2cont: "monofun f \<Longrightarrow> cont (f::'a::chfin \<Rightarrow> 'b::cpo)"
   212 apply (erule contI2)
   213 apply (frule chfin2finch)
   214 apply (clarsimp simp add: finite_chain_def)
   215 apply (subgoal_tac "max_in_chain i (\<lambda>i. f (Y i))")
   216 apply (simp add: maxinch_is_thelub ch2ch_monofun)
   217 apply (force simp add: max_in_chain_def)
   218 done
   219 
   220 text {* All strict functions with flat domain are continuous. *}
   221 
   222 lemma flatdom_strict2mono: "f \<bottom> = \<bottom> \<Longrightarrow> monofun (f::'a::flat \<Rightarrow> 'b::pcpo)"
   223 apply (rule monofunI)
   224 apply (drule ax_flat)
   225 apply auto
   226 done
   227 
   228 lemma flatdom_strict2cont: "f \<bottom> = \<bottom> \<Longrightarrow> cont (f::'a::flat \<Rightarrow> 'b::pcpo)"
   229 by (rule flatdom_strict2mono [THEN chfindom_monofun2cont])
   230 
   231 text {* All functions with discrete domain are continuous. *}
   232 
   233 lemma cont_discrete_cpo [simp, cont2cont]: "cont (f::'a::discrete_cpo \<Rightarrow> 'b::cpo)"
   234 apply (rule contI)
   235 apply (drule discrete_chain_const, clarify)
   236 apply (simp add: is_lub_const)
   237 done
   238 
   239 end