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