src/HOLCF/Up.thy
author huffman
Fri Jul 08 02:41:19 2005 +0200 (2005-07-08)
changeset 16753 fb6801c926d2
parent 16553 aa36d41e4263
child 16933 91ded127f5f7
permissions -rw-r--r--
define 'a u with datatype package;
removed obsolete lemmas;
renamed upE1 to upE and Exh_Up1 to Exh_Up;
cleaned 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_cases:
   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 (rule conjI)
   134 apply (simp add: up_lemma4)
   135 apply (rule conjI)
   136 apply (simp add: up_lemma6 [THEN thelubI])
   137 apply (rule_tac x=j in exI)
   138 apply (simp add: up_lemma3)
   139 done
   140 
   141 lemma cpo_up: "chain (Y::nat \<Rightarrow> 'a u) \<Longrightarrow> \<exists>x. range Y <<| x"
   142 apply (frule up_chain_cases, safe)
   143 apply (rule_tac x="Iup (lub (range A))" in exI)
   144 apply (erule_tac j1="j" in is_lub_range_shift [THEN iffD1])
   145 apply (simp add: is_lub_Iup thelubE)
   146 apply (rule_tac x="Ibottom" in exI)
   147 apply (rule lub_const)
   148 done
   149 
   150 instance u :: (cpo) cpo
   151 by intro_classes (rule cpo_up)
   152 
   153 subsection {* Type @{typ "'a u"} is pointed *}
   154 
   155 lemma least_up: "EX x::'a u. ALL y. x\<sqsubseteq>y"
   156 apply (rule_tac x = "Ibottom" in exI)
   157 apply (rule minimal_up [THEN allI])
   158 done
   159 
   160 instance u :: (cpo) pcpo
   161 by intro_classes (rule least_up)
   162 
   163 text {* for compatibility with old HOLCF-Version *}
   164 lemma inst_up_pcpo: "\<bottom> = Ibottom"
   165 by (rule minimal_up [THEN UU_I, symmetric])
   166 
   167 subsection {* Continuity of @{term Iup} and @{term Ifup} *}
   168 
   169 text {* continuity for @{term Iup} *}
   170 
   171 lemma cont_Iup: "cont Iup"
   172 apply (rule contI)
   173 apply (rule is_lub_Iup)
   174 apply (erule thelubE [OF _ refl])
   175 done
   176 
   177 text {* continuity for @{term Ifup} *}
   178 
   179 lemma cont_Ifup1: "cont (\<lambda>f. Ifup f x)"
   180 by (induct x, simp_all)
   181 
   182 lemma monofun_Ifup2: "monofun (\<lambda>x. Ifup f x)"
   183 apply (rule monofunI)
   184 apply (case_tac x, simp)
   185 apply (case_tac y, simp)
   186 apply (simp add: monofun_cfun_arg)
   187 done
   188 
   189 lemma cont_Ifup2: "cont (\<lambda>x. Ifup f x)"
   190 apply (rule contI)
   191 apply (frule up_chain_cases, safe)
   192 apply (rule_tac j1="j" in is_lub_range_shift [THEN iffD1])
   193 apply (erule monofun_Ifup2 [THEN ch2ch_monofun])
   194 apply (simp add: cont_cfun_arg)
   195 apply (simp add: thelub_const lub_const)
   196 done
   197 
   198 subsection {* Continuous versions of constants *}
   199 
   200 constdefs  
   201   up  :: "'a \<rightarrow> 'a u"
   202   "up \<equiv> \<Lambda> x. Iup x"
   203 
   204   fup :: "('a \<rightarrow> 'b::pcpo) \<rightarrow> 'a u \<rightarrow> 'b"
   205   "fup \<equiv> \<Lambda> f p. Ifup f p"
   206 
   207 translations
   208 "case l of up\<cdot>x \<Rightarrow> t" == "fup\<cdot>(LAM x. t)\<cdot>l"
   209 
   210 text {* continuous versions of lemmas for @{typ "('a)u"} *}
   211 
   212 lemma Exh_Up: "z = \<bottom> \<or> (\<exists>x. z = up\<cdot>x)"
   213 apply (induct z)
   214 apply (simp add: inst_up_pcpo)
   215 apply (simp add: up_def cont_Iup)
   216 done
   217 
   218 lemma up_eq [simp]: "(up\<cdot>x = up\<cdot>y) = (x = y)"
   219 by (simp add: up_def cont_Iup)
   220 
   221 lemma up_inject: "up\<cdot>x = up\<cdot>y \<Longrightarrow> x = y"
   222 by simp
   223 
   224 lemma up_defined [simp]: " up\<cdot>x \<noteq> \<bottom>"
   225 by (simp add: up_def cont_Iup inst_up_pcpo)
   226 
   227 lemma not_up_less_UU [simp]: "\<not> up\<cdot>x \<sqsubseteq> \<bottom>"
   228 by (simp add: eq_UU_iff [symmetric])
   229 
   230 lemma up_less [simp]: "(up\<cdot>x \<sqsubseteq> up\<cdot>y) = (x \<sqsubseteq> y)"
   231 by (simp add: up_def cont_Iup)
   232 
   233 lemma upE: "\<lbrakk>p = \<bottom> \<Longrightarrow> Q; \<And>x. p = up\<cdot>x \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
   234 apply (case_tac p)
   235 apply (simp add: inst_up_pcpo)
   236 apply (simp add: up_def cont_Iup)
   237 done
   238 
   239 lemma fup1 [simp]: "fup\<cdot>f\<cdot>\<bottom> = \<bottom>"
   240 by (simp add: fup_def cont_Ifup1 cont_Ifup2 inst_up_pcpo)
   241 
   242 lemma fup2 [simp]: "fup\<cdot>f\<cdot>(up\<cdot>x) = f\<cdot>x"
   243 by (simp add: up_def fup_def cont_Iup cont_Ifup1 cont_Ifup2)
   244 
   245 lemma fup3 [simp]: "fup\<cdot>up\<cdot>x = x"
   246 by (rule_tac p=x in upE, simp_all)
   247 
   248 end