src/HOLCF/Up.thy
author huffman
Thu Nov 03 01:11:39 2005 +0100 (2005-11-03)
changeset 18078 20e5a6440790
parent 17838 3032e90c4975
child 18290 5fc309770840
permissions -rw-r--r--
change syntax for LAM to use expressions as patterns; define LAM pattern syntax for cpair, spair, sinl, sinr, up
     1 (*  Title:      HOLCF/Up.thy
     2     ID:         $Id$
     3     Author:     Franz Regensburger and Brian Huffman
     4 
     5 Lifting.
     6 *)
     7 
     8 header {* The type of lifted values *}
     9 
    10 theory Up
    11 imports Cfun Sum_Type Datatype
    12 begin
    13 
    14 defaultsort cpo
    15 
    16 subsection {* Definition of new type for lifting *}
    17 
    18 datatype 'a u = Ibottom | Iup 'a
    19 
    20 consts
    21   Ifup :: "('a \<rightarrow> 'b::pcpo) \<Rightarrow> 'a u \<Rightarrow> 'b"
    22 
    23 primrec
    24   "Ifup f Ibottom = \<bottom>"
    25   "Ifup f (Iup x) = f\<cdot>x"
    26 
    27 subsection {* Ordering on type @{typ "'a u"} *}
    28 
    29 instance u :: (sq_ord) sq_ord ..
    30 
    31 defs (overloaded)
    32   less_up_def:
    33     "(op \<sqsubseteq>) \<equiv> (\<lambda>x y. case x of Ibottom \<Rightarrow> True | Iup a \<Rightarrow>
    34       (case y of Ibottom \<Rightarrow> False | Iup b \<Rightarrow> a \<sqsubseteq> b))"
    35 
    36 lemma minimal_up [iff]: "Ibottom \<sqsubseteq> z"
    37 by (simp add: less_up_def)
    38 
    39 lemma not_Iup_less [iff]: "\<not> Iup x \<sqsubseteq> Ibottom"
    40 by (simp add: less_up_def)
    41 
    42 lemma Iup_less [iff]: "(Iup x \<sqsubseteq> Iup y) = (x \<sqsubseteq> y)"
    43 by (simp add: less_up_def)
    44 
    45 subsection {* Type @{typ "'a u"} is a partial order *}
    46 
    47 lemma refl_less_up: "(x::'a u) \<sqsubseteq> x"
    48 by (simp add: less_up_def split: u.split)
    49 
    50 lemma antisym_less_up: "\<lbrakk>(x::'a u) \<sqsubseteq> y; y \<sqsubseteq> x\<rbrakk> \<Longrightarrow> x = y"
    51 apply (simp add: less_up_def split: u.split_asm)
    52 apply (erule (1) antisym_less)
    53 done
    54 
    55 lemma trans_less_up: "\<lbrakk>(x::'a u) \<sqsubseteq> y; y \<sqsubseteq> z\<rbrakk> \<Longrightarrow> x \<sqsubseteq> z"
    56 apply (simp add: less_up_def split: u.split_asm)
    57 apply (erule (1) trans_less)
    58 done
    59 
    60 instance u :: (cpo) po
    61 by intro_classes
    62   (assumption | rule refl_less_up antisym_less_up trans_less_up)+
    63 
    64 subsection {* Type @{typ "'a u"} is a cpo *}
    65 
    66 lemma is_lub_Iup:
    67   "range S <<| x \<Longrightarrow> range (\<lambda>i. Iup (S i)) <<| Iup x"
    68 apply (rule is_lubI)
    69 apply (rule ub_rangeI)
    70 apply (subst Iup_less)
    71 apply (erule is_ub_lub)
    72 apply (case_tac u)
    73 apply (drule ub_rangeD)
    74 apply simp
    75 apply simp
    76 apply (erule is_lub_lub)
    77 apply (rule ub_rangeI)
    78 apply (drule_tac i=i in ub_rangeD)
    79 apply simp
    80 done
    81 
    82 text {* Now some lemmas about chains of @{typ "'a u"} elements *}
    83 
    84 lemma up_lemma1: "z \<noteq> Ibottom \<Longrightarrow> Iup (THE a. Iup a = z) = z"
    85 by (case_tac z, simp_all)
    86 
    87 lemma up_lemma2:
    88   "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk> \<Longrightarrow> Y (i + j) \<noteq> Ibottom"
    89 apply (erule contrapos_nn)
    90 apply (drule_tac x="j" and y="i + j" in chain_mono3)
    91 apply (rule le_add2)
    92 apply (case_tac "Y j")
    93 apply assumption
    94 apply simp
    95 done
    96 
    97 lemma up_lemma3:
    98   "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk> \<Longrightarrow> Iup (THE a. Iup a = Y (i + j)) = Y (i + j)"
    99 by (rule up_lemma1 [OF up_lemma2])
   100 
   101 lemma up_lemma4:
   102   "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk> \<Longrightarrow> chain (\<lambda>i. THE a. Iup a = Y (i + j))"
   103 apply (rule chainI)
   104 apply (rule Iup_less [THEN iffD1])
   105 apply (subst up_lemma3, assumption+)+
   106 apply (simp add: chainE)
   107 done
   108 
   109 lemma up_lemma5:
   110   "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk> \<Longrightarrow>
   111     (\<lambda>i. Y (i + j)) = (\<lambda>i. Iup (THE a. Iup a = Y (i + j)))"
   112 by (rule ext, rule up_lemma3 [symmetric])
   113 
   114 lemma up_lemma6:
   115   "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk>  
   116       \<Longrightarrow> range Y <<| Iup (\<Squnion>i. THE a. Iup a = Y(i + j))"
   117 apply (rule_tac j1 = j in is_lub_range_shift [THEN iffD1])
   118 apply assumption
   119 apply (subst up_lemma5, assumption+)
   120 apply (rule is_lub_Iup)
   121 apply (rule thelubE [OF _ refl])
   122 apply (erule (1) up_lemma4)
   123 done
   124 
   125 lemma up_chain_lemma:
   126   "chain Y \<Longrightarrow>
   127    (\<exists>A. chain A \<and> lub (range Y) = Iup (lub (range A)) \<and>
   128    (\<exists>j. \<forall>i. Y (i + j) = Iup (A i))) \<or> (Y = (\<lambda>i. Ibottom))"
   129 apply (rule disjCI)
   130 apply (simp add: expand_fun_eq)
   131 apply (erule exE, rename_tac j)
   132 apply (rule_tac x="\<lambda>i. THE a. Iup a = Y (i + j)" in exI)
   133 apply (simp add: up_lemma4)
   134 apply (simp add: up_lemma6 [THEN thelubI])
   135 apply (rule_tac x=j in exI)
   136 apply (simp add: up_lemma3)
   137 done
   138 
   139 lemma cpo_up: "chain (Y::nat \<Rightarrow> 'a u) \<Longrightarrow> \<exists>x. range Y <<| x"
   140 apply (frule up_chain_lemma, safe)
   141 apply (rule_tac x="Iup (lub (range A))" in exI)
   142 apply (erule_tac j="j" in is_lub_range_shift [THEN iffD1, standard])
   143 apply (simp add: is_lub_Iup thelubE)
   144 apply (rule exI, rule lub_const)
   145 done
   146 
   147 instance u :: (cpo) cpo
   148 by intro_classes (rule cpo_up)
   149 
   150 subsection {* Type @{typ "'a u"} is pointed *}
   151 
   152 lemma least_up: "\<exists>x::'a u. \<forall>y. x \<sqsubseteq> y"
   153 apply (rule_tac x = "Ibottom" in exI)
   154 apply (rule minimal_up [THEN allI])
   155 done
   156 
   157 instance u :: (cpo) pcpo
   158 by intro_classes (rule least_up)
   159 
   160 text {* for compatibility with old HOLCF-Version *}
   161 lemma inst_up_pcpo: "\<bottom> = Ibottom"
   162 by (rule minimal_up [THEN UU_I, symmetric])
   163 
   164 subsection {* Continuity of @{term Iup} and @{term Ifup} *}
   165 
   166 text {* continuity for @{term Iup} *}
   167 
   168 lemma cont_Iup: "cont Iup"
   169 apply (rule contI)
   170 apply (rule is_lub_Iup)
   171 apply (erule thelubE [OF _ refl])
   172 done
   173 
   174 text {* continuity for @{term Ifup} *}
   175 
   176 lemma cont_Ifup1: "cont (\<lambda>f. Ifup f x)"
   177 by (induct x, simp_all)
   178 
   179 lemma monofun_Ifup2: "monofun (\<lambda>x. Ifup f x)"
   180 apply (rule monofunI)
   181 apply (case_tac x, simp)
   182 apply (case_tac y, simp)
   183 apply (simp add: monofun_cfun_arg)
   184 done
   185 
   186 lemma cont_Ifup2: "cont (\<lambda>x. Ifup f x)"
   187 apply (rule contI)
   188 apply (frule up_chain_lemma, safe)
   189 apply (rule_tac j="j" in is_lub_range_shift [THEN iffD1, standard])
   190 apply (erule monofun_Ifup2 [THEN ch2ch_monofun])
   191 apply (simp add: cont_cfun_arg)
   192 apply (simp add: lub_const)
   193 done
   194 
   195 subsection {* Continuous versions of constants *}
   196 
   197 constdefs  
   198   up  :: "'a \<rightarrow> 'a u"
   199   "up \<equiv> \<Lambda> x. Iup x"
   200 
   201   fup :: "('a \<rightarrow> 'b::pcpo) \<rightarrow> 'a u \<rightarrow> 'b"
   202   "fup \<equiv> \<Lambda> f p. Ifup f p"
   203 
   204 translations
   205   "case l of up\<cdot>x \<Rightarrow> t" == "fup\<cdot>(\<Lambda> x. t)\<cdot>l"
   206   "\<Lambda>(up\<cdot>x). t" == "fup\<cdot>(\<Lambda> x. t)"
   207 
   208 text {* continuous versions of lemmas for @{typ "('a)u"} *}
   209 
   210 lemma Exh_Up: "z = \<bottom> \<or> (\<exists>x. z = up\<cdot>x)"
   211 apply (induct z)
   212 apply (simp add: inst_up_pcpo)
   213 apply (simp add: up_def cont_Iup)
   214 done
   215 
   216 lemma up_eq [simp]: "(up\<cdot>x = up\<cdot>y) = (x = y)"
   217 by (simp add: up_def cont_Iup)
   218 
   219 lemma up_inject: "up\<cdot>x = up\<cdot>y \<Longrightarrow> x = y"
   220 by simp
   221 
   222 lemma up_defined [simp]: "up\<cdot>x \<noteq> \<bottom>"
   223 by (simp add: up_def cont_Iup inst_up_pcpo)
   224 
   225 lemma not_up_less_UU [simp]: "\<not> up\<cdot>x \<sqsubseteq> \<bottom>"
   226 by (simp add: eq_UU_iff [symmetric])
   227 
   228 lemma up_less [simp]: "(up\<cdot>x \<sqsubseteq> up\<cdot>y) = (x \<sqsubseteq> y)"
   229 by (simp add: up_def cont_Iup)
   230 
   231 lemma upE: "\<lbrakk>p = \<bottom> \<Longrightarrow> Q; \<And>x. p = up\<cdot>x \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
   232 apply (case_tac p)
   233 apply (simp add: inst_up_pcpo)
   234 apply (simp add: up_def cont_Iup)
   235 done
   236 
   237 lemma up_chain_cases:
   238   "chain Y \<Longrightarrow>
   239   (\<exists>A. chain A \<and> (\<Squnion>i. Y i) = up\<cdot>(\<Squnion>i. A i) \<and>
   240   (\<exists>j. \<forall>i. Y (i + j) = up\<cdot>(A i))) \<or> Y = (\<lambda>i. \<bottom>)"
   241 by (simp add: inst_up_pcpo up_def cont_Iup up_chain_lemma)
   242 
   243 lemma compact_up [simp]: "compact x \<Longrightarrow> compact (up\<cdot>x)"
   244 apply (unfold compact_def)
   245 apply (rule admI)
   246 apply (drule up_chain_cases)
   247 apply (elim disjE exE conjE)
   248 apply simp
   249 apply (erule (1) admD)
   250 apply (rule allI, drule_tac x="i + j" in spec)
   251 apply simp
   252 apply simp
   253 done
   254 
   255 text {* properties of fup *}
   256 
   257 lemma fup1 [simp]: "fup\<cdot>f\<cdot>\<bottom> = \<bottom>"
   258 by (simp add: fup_def cont_Ifup1 cont_Ifup2 inst_up_pcpo)
   259 
   260 lemma fup2 [simp]: "fup\<cdot>f\<cdot>(up\<cdot>x) = f\<cdot>x"
   261 by (simp add: up_def fup_def cont_Iup cont_Ifup1 cont_Ifup2)
   262 
   263 lemma fup3 [simp]: "fup\<cdot>up\<cdot>x = x"
   264 by (rule_tac p=x in upE, simp_all)
   265 
   266 end