src/HOLCF/Cont.thy
author huffman
Wed Nov 10 17:56:08 2010 -0800 (2010-11-10)
changeset 40502 8e92772bc0e8
parent 40010 d7fdd84b959f
child 40736 72857de90621
permissions -rw-r--r--
move map functions to new theory file Map_Functions; add theory file Plain_HOLCF
     1 (*  Title:      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 lub_bin_chain [THEN thelubI])
    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_ub_lub)
    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 thelubI [symmetric])
    96 apply (erule (1) contE)
    97 done
    98 
    99 lemma contI2:
   100   assumes mono: "monofun f"
   101   assumes below: "\<And>Y. \<lbrakk>chain Y; chain (\<lambda>i. f (Y i))\<rbrakk>
   102      \<Longrightarrow> f (\<Squnion>i. Y i) \<sqsubseteq> (\<Squnion>i. f (Y i))"
   103   shows "cont f"
   104 apply (rule contI)
   105 apply (rule thelubE)
   106 apply (erule ch2ch_monofun [OF mono])
   107 apply (rule below_antisym)
   108 apply (rule is_lub_thelub)
   109 apply (erule ch2ch_monofun [OF mono])
   110 apply (rule ub2ub_monofun [OF mono])
   111 apply (rule is_lubD1)
   112 apply (erule cpo_lubI)
   113 apply (rule below, assumption)
   114 apply (erule ch2ch_monofun [OF mono])
   115 done
   116 
   117 subsection {* Collection of continuity rules *}
   118 
   119 ML {*
   120 structure Cont2ContData = Named_Thms
   121 (
   122   val name = "cont2cont"
   123   val description = "continuity intro rule"
   124 )
   125 *}
   126 
   127 setup Cont2ContData.setup
   128 
   129 subsection {* Continuity of basic functions *}
   130 
   131 text {* The identity function is continuous *}
   132 
   133 lemma cont_id [simp, cont2cont]: "cont (\<lambda>x. x)"
   134 apply (rule contI)
   135 apply (erule cpo_lubI)
   136 done
   137 
   138 text {* constant functions are continuous *}
   139 
   140 lemma cont_const [simp, cont2cont]: "cont (\<lambda>x. c)"
   141 apply (rule contI)
   142 apply (rule lub_const)
   143 done
   144 
   145 text {* application of functions is continuous *}
   146 
   147 lemma cont_apply:
   148   fixes f :: "'a::cpo \<Rightarrow> 'b::cpo \<Rightarrow> 'c::cpo" and t :: "'a \<Rightarrow> 'b"
   149   assumes 1: "cont (\<lambda>x. t x)"
   150   assumes 2: "\<And>x. cont (\<lambda>y. f x y)"
   151   assumes 3: "\<And>y. cont (\<lambda>x. f x y)"
   152   shows "cont (\<lambda>x. (f x) (t x))"
   153 proof (rule contI2 [OF monofunI])
   154   fix x y :: "'a" assume "x \<sqsubseteq> y"
   155   then show "f x (t x) \<sqsubseteq> f y (t y)"
   156     by (auto intro: cont2monofunE [OF 1]
   157                     cont2monofunE [OF 2]
   158                     cont2monofunE [OF 3]
   159                     below_trans)
   160 next
   161   fix Y :: "nat \<Rightarrow> 'a" assume "chain Y"
   162   then show "f (\<Squnion>i. Y i) (t (\<Squnion>i. Y i)) \<sqsubseteq> (\<Squnion>i. f (Y i) (t (Y i)))"
   163     by (simp only: cont2contlubE [OF 1] ch2ch_cont [OF 1]
   164                    cont2contlubE [OF 2] ch2ch_cont [OF 2]
   165                    cont2contlubE [OF 3] ch2ch_cont [OF 3]
   166                    diag_lub below_refl)
   167 qed
   168 
   169 lemma cont_compose:
   170   "\<lbrakk>cont c; cont (\<lambda>x. f x)\<rbrakk> \<Longrightarrow> cont (\<lambda>x. c (f x))"
   171 by (rule cont_apply [OF _ _ cont_const])
   172 
   173 text {* Least upper bounds preserve continuity *}
   174 
   175 lemma cont2cont_lub [simp]:
   176   assumes chain: "\<And>x. chain (\<lambda>i. F i x)" and cont: "\<And>i. cont (\<lambda>x. F i x)"
   177   shows "cont (\<lambda>x. \<Squnion>i. F i x)"
   178 apply (rule contI2)
   179 apply (simp add: monofunI cont2monofunE [OF cont] lub_mono chain)
   180 apply (simp add: cont2contlubE [OF cont])
   181 apply (simp add: diag_lub ch2ch_cont [OF cont] chain)
   182 done
   183 
   184 text {* if-then-else is continuous *}
   185 
   186 lemma cont_if [simp, cont2cont]:
   187   "\<lbrakk>cont f; cont g\<rbrakk> \<Longrightarrow> cont (\<lambda>x. if b then f x else g x)"
   188 by (induct b) simp_all
   189 
   190 subsection {* Finite chains and flat pcpos *}
   191 
   192 text {* Monotone functions map finite chains to finite chains. *}
   193 
   194 lemma monofun_finch2finch:
   195   "\<lbrakk>monofun f; finite_chain Y\<rbrakk> \<Longrightarrow> finite_chain (\<lambda>n. f (Y n))"
   196 apply (unfold finite_chain_def)
   197 apply (simp add: ch2ch_monofun)
   198 apply (force simp add: max_in_chain_def)
   199 done
   200 
   201 text {* The same holds for continuous functions. *}
   202 
   203 lemma cont_finch2finch:
   204   "\<lbrakk>cont f; finite_chain Y\<rbrakk> \<Longrightarrow> finite_chain (\<lambda>n. f (Y n))"
   205 by (rule cont2mono [THEN monofun_finch2finch])
   206 
   207 text {* All monotone functions with chain-finite domain are continuous. *}
   208 
   209 lemma chfindom_monofun2cont: "monofun f \<Longrightarrow> cont (f::'a::chfin \<Rightarrow> 'b::cpo)"
   210 apply (erule contI2)
   211 apply (frule chfin2finch)
   212 apply (clarsimp simp add: finite_chain_def)
   213 apply (subgoal_tac "max_in_chain i (\<lambda>i. f (Y i))")
   214 apply (simp add: maxinch_is_thelub ch2ch_monofun)
   215 apply (force simp add: max_in_chain_def)
   216 done
   217 
   218 text {* All strict functions with flat domain are continuous. *}
   219 
   220 lemma flatdom_strict2mono: "f \<bottom> = \<bottom> \<Longrightarrow> monofun (f::'a::flat \<Rightarrow> 'b::pcpo)"
   221 apply (rule monofunI)
   222 apply (drule ax_flat)
   223 apply auto
   224 done
   225 
   226 lemma flatdom_strict2cont: "f \<bottom> = \<bottom> \<Longrightarrow> cont (f::'a::flat \<Rightarrow> 'b::pcpo)"
   227 by (rule flatdom_strict2mono [THEN chfindom_monofun2cont])
   228 
   229 text {* All functions with discrete domain are continuous. *}
   230 
   231 lemma cont_discrete_cpo [simp, cont2cont]: "cont (f::'a::discrete_cpo \<Rightarrow> 'b::cpo)"
   232 apply (rule contI)
   233 apply (drule discrete_chain_const, clarify)
   234 apply (simp add: lub_const)
   235 done
   236 
   237 end