src/HOLCF/Up.thy
author huffman
Thu Nov 19 21:44:37 2009 -0800 (2009-11-19)
changeset 33808 31169fdc5ae7
parent 33587 54f98d225163
child 34941 156925dd67af
permissions -rw-r--r--
add map_ID lemmas
     1 (*  Title:      HOLCF/Up.thy
     2     Author:     Franz Regensburger and Brian Huffman
     3 *)
     4 
     5 header {* The type of lifted values *}
     6 
     7 theory Up
     8 imports Bifinite
     9 begin
    10 
    11 defaultsort cpo
    12 
    13 subsection {* Definition of new type for lifting *}
    14 
    15 datatype 'a u = Ibottom | Iup 'a
    16 
    17 syntax (xsymbols)
    18   "u" :: "type \<Rightarrow> type" ("(_\<^sub>\<bottom>)" [1000] 999)
    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 lifted cpo *}
    28 
    29 instantiation u :: (cpo) below
    30 begin
    31 
    32 definition
    33   below_up_def:
    34     "(op \<sqsubseteq>) \<equiv> (\<lambda>x y. case x of Ibottom \<Rightarrow> True | Iup a \<Rightarrow>
    35       (case y of Ibottom \<Rightarrow> False | Iup b \<Rightarrow> a \<sqsubseteq> b))"
    36 
    37 instance ..
    38 end
    39 
    40 lemma minimal_up [iff]: "Ibottom \<sqsubseteq> z"
    41 by (simp add: below_up_def)
    42 
    43 lemma not_Iup_below [iff]: "\<not> Iup x \<sqsubseteq> Ibottom"
    44 by (simp add: below_up_def)
    45 
    46 lemma Iup_below [iff]: "(Iup x \<sqsubseteq> Iup y) = (x \<sqsubseteq> y)"
    47 by (simp add: below_up_def)
    48 
    49 subsection {* Lifted cpo is a partial order *}
    50 
    51 instance u :: (cpo) po
    52 proof
    53   fix x :: "'a u"
    54   show "x \<sqsubseteq> x"
    55     unfolding below_up_def by (simp split: u.split)
    56 next
    57   fix x y :: "'a u"
    58   assume "x \<sqsubseteq> y" "y \<sqsubseteq> x" thus "x = y"
    59     unfolding below_up_def
    60     by (auto split: u.split_asm intro: below_antisym)
    61 next
    62   fix x y z :: "'a u"
    63   assume "x \<sqsubseteq> y" "y \<sqsubseteq> z" thus "x \<sqsubseteq> z"
    64     unfolding below_up_def
    65     by (auto split: u.split_asm intro: below_trans)
    66 qed
    67 
    68 lemma u_UNIV: "UNIV = insert Ibottom (range Iup)"
    69 by (auto, case_tac x, auto)
    70 
    71 instance u :: (finite_po) finite_po
    72 by (intro_classes, simp add: u_UNIV)
    73 
    74 
    75 subsection {* Lifted cpo is a cpo *}
    76 
    77 lemma is_lub_Iup:
    78   "range S <<| x \<Longrightarrow> range (\<lambda>i. Iup (S i)) <<| Iup x"
    79 apply (rule is_lubI)
    80 apply (rule ub_rangeI)
    81 apply (subst Iup_below)
    82 apply (erule is_ub_lub)
    83 apply (case_tac u)
    84 apply (drule ub_rangeD)
    85 apply simp
    86 apply simp
    87 apply (erule is_lub_lub)
    88 apply (rule ub_rangeI)
    89 apply (drule_tac i=i in ub_rangeD)
    90 apply simp
    91 done
    92 
    93 text {* Now some lemmas about chains of @{typ "'a u"} elements *}
    94 
    95 lemma up_lemma1: "z \<noteq> Ibottom \<Longrightarrow> Iup (THE a. Iup a = z) = z"
    96 by (case_tac z, simp_all)
    97 
    98 lemma up_lemma2:
    99   "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk> \<Longrightarrow> Y (i + j) \<noteq> Ibottom"
   100 apply (erule contrapos_nn)
   101 apply (drule_tac i="j" and j="i + j" in chain_mono)
   102 apply (rule le_add2)
   103 apply (case_tac "Y j")
   104 apply assumption
   105 apply simp
   106 done
   107 
   108 lemma up_lemma3:
   109   "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk> \<Longrightarrow> Iup (THE a. Iup a = Y (i + j)) = Y (i + j)"
   110 by (rule up_lemma1 [OF up_lemma2])
   111 
   112 lemma up_lemma4:
   113   "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk> \<Longrightarrow> chain (\<lambda>i. THE a. Iup a = Y (i + j))"
   114 apply (rule chainI)
   115 apply (rule Iup_below [THEN iffD1])
   116 apply (subst up_lemma3, assumption+)+
   117 apply (simp add: chainE)
   118 done
   119 
   120 lemma up_lemma5:
   121   "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk> \<Longrightarrow>
   122     (\<lambda>i. Y (i + j)) = (\<lambda>i. Iup (THE a. Iup a = Y (i + j)))"
   123 by (rule ext, rule up_lemma3 [symmetric])
   124 
   125 lemma up_lemma6:
   126   "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk>
   127       \<Longrightarrow> range Y <<| Iup (\<Squnion>i. THE a. Iup a = Y(i + j))"
   128 apply (rule_tac j1 = j in is_lub_range_shift [THEN iffD1])
   129 apply assumption
   130 apply (subst up_lemma5, assumption+)
   131 apply (rule is_lub_Iup)
   132 apply (rule cpo_lubI)
   133 apply (erule (1) up_lemma4)
   134 done
   135 
   136 lemma up_chain_lemma:
   137   "chain Y \<Longrightarrow>
   138    (\<exists>A. chain A \<and> (\<Squnion>i. Y i) = Iup (\<Squnion>i. A i) \<and>
   139    (\<exists>j. \<forall>i. Y (i + j) = Iup (A i))) \<or> (Y = (\<lambda>i. Ibottom))"
   140 apply (rule disjCI)
   141 apply (simp add: expand_fun_eq)
   142 apply (erule exE, rename_tac j)
   143 apply (rule_tac x="\<lambda>i. THE a. Iup a = Y (i + j)" in exI)
   144 apply (simp add: up_lemma4)
   145 apply (simp add: up_lemma6 [THEN thelubI])
   146 apply (rule_tac x=j in exI)
   147 apply (simp add: up_lemma3)
   148 done
   149 
   150 lemma cpo_up: "chain (Y::nat \<Rightarrow> 'a u) \<Longrightarrow> \<exists>x. range Y <<| x"
   151 apply (frule up_chain_lemma, safe)
   152 apply (rule_tac x="Iup (\<Squnion>i. A i)" in exI)
   153 apply (erule_tac j="j" in is_lub_range_shift [THEN iffD1, standard])
   154 apply (simp add: is_lub_Iup cpo_lubI)
   155 apply (rule exI, rule lub_const)
   156 done
   157 
   158 instance u :: (cpo) cpo
   159 by intro_classes (rule cpo_up)
   160 
   161 subsection {* Lifted cpo is pointed *}
   162 
   163 lemma least_up: "\<exists>x::'a u. \<forall>y. x \<sqsubseteq> y"
   164 apply (rule_tac x = "Ibottom" in exI)
   165 apply (rule minimal_up [THEN allI])
   166 done
   167 
   168 instance u :: (cpo) pcpo
   169 by intro_classes (rule least_up)
   170 
   171 text {* for compatibility with old HOLCF-Version *}
   172 lemma inst_up_pcpo: "\<bottom> = Ibottom"
   173 by (rule minimal_up [THEN UU_I, symmetric])
   174 
   175 subsection {* Continuity of @{term Iup} and @{term Ifup} *}
   176 
   177 text {* continuity for @{term Iup} *}
   178 
   179 lemma cont_Iup: "cont Iup"
   180 apply (rule contI)
   181 apply (rule is_lub_Iup)
   182 apply (erule cpo_lubI)
   183 done
   184 
   185 text {* continuity for @{term Ifup} *}
   186 
   187 lemma cont_Ifup1: "cont (\<lambda>f. Ifup f x)"
   188 by (induct x, simp_all)
   189 
   190 lemma monofun_Ifup2: "monofun (\<lambda>x. Ifup f x)"
   191 apply (rule monofunI)
   192 apply (case_tac x, simp)
   193 apply (case_tac y, simp)
   194 apply (simp add: monofun_cfun_arg)
   195 done
   196 
   197 lemma cont_Ifup2: "cont (\<lambda>x. Ifup f x)"
   198 apply (rule contI)
   199 apply (frule up_chain_lemma, safe)
   200 apply (rule_tac j="j" in is_lub_range_shift [THEN iffD1, standard])
   201 apply (erule monofun_Ifup2 [THEN ch2ch_monofun])
   202 apply (simp add: cont_cfun_arg)
   203 apply (simp add: lub_const)
   204 done
   205 
   206 subsection {* Continuous versions of constants *}
   207 
   208 definition
   209   up  :: "'a \<rightarrow> 'a u" where
   210   "up = (\<Lambda> x. Iup x)"
   211 
   212 definition
   213   fup :: "('a \<rightarrow> 'b::pcpo) \<rightarrow> 'a u \<rightarrow> 'b" where
   214   "fup = (\<Lambda> f p. Ifup f p)"
   215 
   216 translations
   217   "case l of XCONST up\<cdot>x \<Rightarrow> t" == "CONST fup\<cdot>(\<Lambda> x. t)\<cdot>l"
   218   "\<Lambda>(XCONST up\<cdot>x). t" == "CONST fup\<cdot>(\<Lambda> x. t)"
   219 
   220 text {* continuous versions of lemmas for @{typ "('a)u"} *}
   221 
   222 lemma Exh_Up: "z = \<bottom> \<or> (\<exists>x. z = up\<cdot>x)"
   223 apply (induct z)
   224 apply (simp add: inst_up_pcpo)
   225 apply (simp add: up_def cont_Iup)
   226 done
   227 
   228 lemma up_eq [simp]: "(up\<cdot>x = up\<cdot>y) = (x = y)"
   229 by (simp add: up_def cont_Iup)
   230 
   231 lemma up_inject: "up\<cdot>x = up\<cdot>y \<Longrightarrow> x = y"
   232 by simp
   233 
   234 lemma up_defined [simp]: "up\<cdot>x \<noteq> \<bottom>"
   235 by (simp add: up_def cont_Iup inst_up_pcpo)
   236 
   237 lemma not_up_less_UU: "\<not> up\<cdot>x \<sqsubseteq> \<bottom>"
   238 by simp (* FIXME: remove? *)
   239 
   240 lemma up_below [simp]: "up\<cdot>x \<sqsubseteq> up\<cdot>y \<longleftrightarrow> x \<sqsubseteq> y"
   241 by (simp add: up_def cont_Iup)
   242 
   243 lemma upE [cases type: u]: "\<lbrakk>p = \<bottom> \<Longrightarrow> Q; \<And>x. p = up\<cdot>x \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
   244 apply (cases p)
   245 apply (simp add: inst_up_pcpo)
   246 apply (simp add: up_def cont_Iup)
   247 done
   248 
   249 lemma up_induct [induct type: u]: "\<lbrakk>P \<bottom>; \<And>x. P (up\<cdot>x)\<rbrakk> \<Longrightarrow> P x"
   250 by (cases x, simp_all)
   251 
   252 text {* lifting preserves chain-finiteness *}
   253 
   254 lemma up_chain_cases:
   255   "chain Y \<Longrightarrow>
   256   (\<exists>A. chain A \<and> (\<Squnion>i. Y i) = up\<cdot>(\<Squnion>i. A i) \<and>
   257   (\<exists>j. \<forall>i. Y (i + j) = up\<cdot>(A i))) \<or> Y = (\<lambda>i. \<bottom>)"
   258 by (simp add: inst_up_pcpo up_def cont_Iup up_chain_lemma)
   259 
   260 lemma compact_up: "compact x \<Longrightarrow> compact (up\<cdot>x)"
   261 apply (rule compactI2)
   262 apply (drule up_chain_cases, safe)
   263 apply (drule (1) compactD2, simp)
   264 apply (erule exE, rule_tac x="i + j" in exI)
   265 apply simp
   266 apply simp
   267 done
   268 
   269 lemma compact_upD: "compact (up\<cdot>x) \<Longrightarrow> compact x"
   270 unfolding compact_def
   271 by (drule adm_subst [OF cont_Rep_CFun2 [where f=up]], simp)
   272 
   273 lemma compact_up_iff [simp]: "compact (up\<cdot>x) = compact x"
   274 by (safe elim!: compact_up compact_upD)
   275 
   276 instance u :: (chfin) chfin
   277 apply intro_classes
   278 apply (erule compact_imp_max_in_chain)
   279 apply (rule_tac p="\<Squnion>i. Y i" in upE, simp_all)
   280 done
   281 
   282 text {* properties of fup *}
   283 
   284 lemma fup1 [simp]: "fup\<cdot>f\<cdot>\<bottom> = \<bottom>"
   285 by (simp add: fup_def cont_Ifup1 cont_Ifup2 inst_up_pcpo cont2cont_LAM)
   286 
   287 lemma fup2 [simp]: "fup\<cdot>f\<cdot>(up\<cdot>x) = f\<cdot>x"
   288 by (simp add: up_def fup_def cont_Iup cont_Ifup1 cont_Ifup2 cont2cont_LAM)
   289 
   290 lemma fup3 [simp]: "fup\<cdot>up\<cdot>x = x"
   291 by (cases x, simp_all)
   292 
   293 subsection {* Map function for lifted cpo *}
   294 
   295 definition
   296   u_map :: "('a \<rightarrow> 'b) \<rightarrow> 'a u \<rightarrow> 'b u"
   297 where
   298   "u_map = (\<Lambda> f. fup\<cdot>(up oo f))"
   299 
   300 lemma u_map_strict [simp]: "u_map\<cdot>f\<cdot>\<bottom> = \<bottom>"
   301 unfolding u_map_def by simp
   302 
   303 lemma u_map_up [simp]: "u_map\<cdot>f\<cdot>(up\<cdot>x) = up\<cdot>(f\<cdot>x)"
   304 unfolding u_map_def by simp
   305 
   306 lemma u_map_ID: "u_map\<cdot>ID = ID"
   307 unfolding u_map_def by (simp add: expand_cfun_eq eta_cfun)
   308 
   309 lemma u_map_map: "u_map\<cdot>f\<cdot>(u_map\<cdot>g\<cdot>p) = u_map\<cdot>(\<Lambda> x. f\<cdot>(g\<cdot>x))\<cdot>p"
   310 by (induct p) simp_all
   311 
   312 lemma ep_pair_u_map: "ep_pair e p \<Longrightarrow> ep_pair (u_map\<cdot>e) (u_map\<cdot>p)"
   313 apply default
   314 apply (case_tac x, simp, simp add: ep_pair.e_inverse)
   315 apply (case_tac y, simp, simp add: ep_pair.e_p_below)
   316 done
   317 
   318 lemma deflation_u_map: "deflation d \<Longrightarrow> deflation (u_map\<cdot>d)"
   319 apply default
   320 apply (case_tac x, simp, simp add: deflation.idem)
   321 apply (case_tac x, simp, simp add: deflation.below)
   322 done
   323 
   324 lemma finite_deflation_u_map:
   325   assumes "finite_deflation d" shows "finite_deflation (u_map\<cdot>d)"
   326 proof (intro finite_deflation.intro finite_deflation_axioms.intro)
   327   interpret d: finite_deflation d by fact
   328   have "deflation d" by fact
   329   thus "deflation (u_map\<cdot>d)" by (rule deflation_u_map)
   330   have "{x. u_map\<cdot>d\<cdot>x = x} \<subseteq> insert \<bottom> ((\<lambda>x. up\<cdot>x) ` {x. d\<cdot>x = x})"
   331     by (rule subsetI, case_tac x, simp_all)
   332   thus "finite {x. u_map\<cdot>d\<cdot>x = x}"
   333     by (rule finite_subset, simp add: d.finite_fixes)
   334 qed
   335 
   336 subsection {* Lifted cpo is a bifinite domain *}
   337 
   338 instantiation u :: (profinite) bifinite
   339 begin
   340 
   341 definition
   342   approx_up_def:
   343     "approx = (\<lambda>n. u_map\<cdot>(approx n))"
   344 
   345 instance proof
   346   fix i :: nat and x :: "'a u"
   347   show "chain (approx :: nat \<Rightarrow> 'a u \<rightarrow> 'a u)"
   348     unfolding approx_up_def by simp
   349   show "(\<Squnion>i. approx i\<cdot>x) = x"
   350     unfolding approx_up_def
   351     by (induct x, simp, simp add: lub_distribs)
   352   show "approx i\<cdot>(approx i\<cdot>x) = approx i\<cdot>x"
   353     unfolding approx_up_def
   354     by (induct x) simp_all
   355   show "finite {x::'a u. approx i\<cdot>x = x}"
   356     unfolding approx_up_def
   357     by (intro finite_deflation.finite_fixes
   358               finite_deflation_u_map
   359               finite_deflation_approx)
   360 qed
   361 
   362 end
   363 
   364 lemma approx_up [simp]: "approx i\<cdot>(up\<cdot>x) = up\<cdot>(approx i\<cdot>x)"
   365 unfolding approx_up_def by simp
   366 
   367 end