src/HOL/HOLCF/Up.thy
author blanchet
Tue Nov 07 15:16:42 2017 +0100 (20 months ago)
changeset 67022 49309fe530fd
parent 63040 eb4ddd18d635
child 67312 0d25e02759b7
permissions -rw-r--r--
more robust parsing for THF proofs (esp. polymorphic Leo-III proofs)
     1 (*  Title:      HOL/HOLCF/Up.thy
     2     Author:     Franz Regensburger
     3     Author:     Brian Huffman
     4 *)
     5 
     6 section \<open>The type of lifted values\<close>
     7 
     8 theory Up
     9 imports Cfun
    10 begin
    11 
    12 default_sort cpo
    13 
    14 subsection \<open>Definition of new type for lifting\<close>
    15 
    16 datatype 'a u  ("(_\<^sub>\<bottom>)" [1000] 999) = Ibottom | Iup 'a
    17 
    18 primrec Ifup :: "('a \<rightarrow> 'b::pcpo) \<Rightarrow> 'a u \<Rightarrow> 'b" where
    19     "Ifup f Ibottom = \<bottom>"
    20  |  "Ifup f (Iup x) = f\<cdot>x"
    21 
    22 subsection \<open>Ordering on lifted cpo\<close>
    23 
    24 instantiation u :: (cpo) below
    25 begin
    26 
    27 definition
    28   below_up_def:
    29     "(op \<sqsubseteq>) \<equiv> (\<lambda>x y. case x of Ibottom \<Rightarrow> True | Iup a \<Rightarrow>
    30       (case y of Ibottom \<Rightarrow> False | Iup b \<Rightarrow> a \<sqsubseteq> b))"
    31 
    32 instance ..
    33 end
    34 
    35 lemma minimal_up [iff]: "Ibottom \<sqsubseteq> z"
    36 by (simp add: below_up_def)
    37 
    38 lemma not_Iup_below [iff]: "Iup x \<notsqsubseteq> Ibottom"
    39 by (simp add: below_up_def)
    40 
    41 lemma Iup_below [iff]: "(Iup x \<sqsubseteq> Iup y) = (x \<sqsubseteq> y)"
    42 by (simp add: below_up_def)
    43 
    44 subsection \<open>Lifted cpo is a partial order\<close>
    45 
    46 instance u :: (cpo) po
    47 proof
    48   fix x :: "'a u"
    49   show "x \<sqsubseteq> x"
    50     unfolding below_up_def by (simp split: u.split)
    51 next
    52   fix x y :: "'a u"
    53   assume "x \<sqsubseteq> y" "y \<sqsubseteq> x" thus "x = y"
    54     unfolding below_up_def
    55     by (auto split: u.split_asm intro: below_antisym)
    56 next
    57   fix x y z :: "'a u"
    58   assume "x \<sqsubseteq> y" "y \<sqsubseteq> z" thus "x \<sqsubseteq> z"
    59     unfolding below_up_def
    60     by (auto split: u.split_asm intro: below_trans)
    61 qed
    62 
    63 subsection \<open>Lifted cpo is a cpo\<close>
    64 
    65 lemma is_lub_Iup:
    66   "range S <<| x \<Longrightarrow> range (\<lambda>i. Iup (S i)) <<| Iup x"
    67 unfolding is_lub_def is_ub_def ball_simps
    68 by (auto simp add: below_up_def split: u.split)
    69 
    70 lemma up_chain_lemma:
    71   assumes Y: "chain Y" obtains "\<forall>i. Y i = Ibottom"
    72   | A k where "\<forall>i. Iup (A i) = Y (i + k)" and "chain A" and "range Y <<| Iup (\<Squnion>i. A i)"
    73 proof (cases "\<exists>k. Y k \<noteq> Ibottom")
    74   case True
    75   then obtain k where k: "Y k \<noteq> Ibottom" ..
    76   define A where "A i = (THE a. Iup a = Y (i + k))" for i
    77   have Iup_A: "\<forall>i. Iup (A i) = Y (i + k)"
    78   proof
    79     fix i :: nat
    80     from Y le_add2 have "Y k \<sqsubseteq> Y (i + k)" by (rule chain_mono)
    81     with k have "Y (i + k) \<noteq> Ibottom" by (cases "Y k", auto)
    82     thus "Iup (A i) = Y (i + k)"
    83       by (cases "Y (i + k)", simp_all add: A_def)
    84   qed
    85   from Y have chain_A: "chain A"
    86     unfolding chain_def Iup_below [symmetric]
    87     by (simp add: Iup_A)
    88   hence "range A <<| (\<Squnion>i. A i)"
    89     by (rule cpo_lubI)
    90   hence "range (\<lambda>i. Iup (A i)) <<| Iup (\<Squnion>i. A i)"
    91     by (rule is_lub_Iup)
    92   hence "range (\<lambda>i. Y (i + k)) <<| Iup (\<Squnion>i. A i)"
    93     by (simp only: Iup_A)
    94   hence "range (\<lambda>i. Y i) <<| Iup (\<Squnion>i. A i)"
    95     by (simp only: is_lub_range_shift [OF Y])
    96   with Iup_A chain_A show ?thesis ..
    97 next
    98   case False
    99   then have "\<forall>i. Y i = Ibottom" by simp
   100   then show ?thesis ..
   101 qed
   102 
   103 instance u :: (cpo) cpo
   104 proof
   105   fix S :: "nat \<Rightarrow> 'a u"
   106   assume S: "chain S"
   107   thus "\<exists>x. range (\<lambda>i. S i) <<| x"
   108   proof (rule up_chain_lemma)
   109     assume "\<forall>i. S i = Ibottom"
   110     hence "range (\<lambda>i. S i) <<| Ibottom"
   111       by (simp add: is_lub_const)
   112     thus ?thesis ..
   113   next
   114     fix A :: "nat \<Rightarrow> 'a"
   115     assume "range S <<| Iup (\<Squnion>i. A i)"
   116     thus ?thesis ..
   117   qed
   118 qed
   119 
   120 subsection \<open>Lifted cpo is pointed\<close>
   121 
   122 instance u :: (cpo) pcpo
   123 by intro_classes fast
   124 
   125 text \<open>for compatibility with old HOLCF-Version\<close>
   126 lemma inst_up_pcpo: "\<bottom> = Ibottom"
   127 by (rule minimal_up [THEN bottomI, symmetric])
   128 
   129 subsection \<open>Continuity of \emph{Iup} and \emph{Ifup}\<close>
   130 
   131 text \<open>continuity for @{term Iup}\<close>
   132 
   133 lemma cont_Iup: "cont Iup"
   134 apply (rule contI)
   135 apply (rule is_lub_Iup)
   136 apply (erule cpo_lubI)
   137 done
   138 
   139 text \<open>continuity for @{term Ifup}\<close>
   140 
   141 lemma cont_Ifup1: "cont (\<lambda>f. Ifup f x)"
   142 by (induct x, simp_all)
   143 
   144 lemma monofun_Ifup2: "monofun (\<lambda>x. Ifup f x)"
   145 apply (rule monofunI)
   146 apply (case_tac x, simp)
   147 apply (case_tac y, simp)
   148 apply (simp add: monofun_cfun_arg)
   149 done
   150 
   151 lemma cont_Ifup2: "cont (\<lambda>x. Ifup f x)"
   152 proof (rule contI2)
   153   fix Y assume Y: "chain Y" and Y': "chain (\<lambda>i. Ifup f (Y i))"
   154   from Y show "Ifup f (\<Squnion>i. Y i) \<sqsubseteq> (\<Squnion>i. Ifup f (Y i))"
   155   proof (rule up_chain_lemma)
   156     fix A and k
   157     assume A: "\<forall>i. Iup (A i) = Y (i + k)"
   158     assume "chain A" and "range Y <<| Iup (\<Squnion>i. A i)"
   159     hence "Ifup f (\<Squnion>i. Y i) = (\<Squnion>i. Ifup f (Iup (A i)))"
   160       by (simp add: lub_eqI contlub_cfun_arg)
   161     also have "\<dots> = (\<Squnion>i. Ifup f (Y (i + k)))"
   162       by (simp add: A)
   163     also have "\<dots> = (\<Squnion>i. Ifup f (Y i))"
   164       using Y' by (rule lub_range_shift)
   165     finally show ?thesis by simp
   166   qed simp
   167 qed (rule monofun_Ifup2)
   168 
   169 subsection \<open>Continuous versions of constants\<close>
   170 
   171 definition
   172   up  :: "'a \<rightarrow> 'a u" where
   173   "up = (\<Lambda> x. Iup x)"
   174 
   175 definition
   176   fup :: "('a \<rightarrow> 'b::pcpo) \<rightarrow> 'a u \<rightarrow> 'b" where
   177   "fup = (\<Lambda> f p. Ifup f p)"
   178 
   179 translations
   180   "case l of XCONST up\<cdot>x \<Rightarrow> t" == "CONST fup\<cdot>(\<Lambda> x. t)\<cdot>l"
   181   "case l of (XCONST up :: 'a)\<cdot>x \<Rightarrow> t" => "CONST fup\<cdot>(\<Lambda> x. t)\<cdot>l"
   182   "\<Lambda>(XCONST up\<cdot>x). t" == "CONST fup\<cdot>(\<Lambda> x. t)"
   183 
   184 text \<open>continuous versions of lemmas for @{typ "('a)u"}\<close>
   185 
   186 lemma Exh_Up: "z = \<bottom> \<or> (\<exists>x. z = up\<cdot>x)"
   187 apply (induct z)
   188 apply (simp add: inst_up_pcpo)
   189 apply (simp add: up_def cont_Iup)
   190 done
   191 
   192 lemma up_eq [simp]: "(up\<cdot>x = up\<cdot>y) = (x = y)"
   193 by (simp add: up_def cont_Iup)
   194 
   195 lemma up_inject: "up\<cdot>x = up\<cdot>y \<Longrightarrow> x = y"
   196 by simp
   197 
   198 lemma up_defined [simp]: "up\<cdot>x \<noteq> \<bottom>"
   199 by (simp add: up_def cont_Iup inst_up_pcpo)
   200 
   201 lemma not_up_less_UU: "up\<cdot>x \<notsqsubseteq> \<bottom>"
   202 by simp (* FIXME: remove? *)
   203 
   204 lemma up_below [simp]: "up\<cdot>x \<sqsubseteq> up\<cdot>y \<longleftrightarrow> x \<sqsubseteq> y"
   205 by (simp add: up_def cont_Iup)
   206 
   207 lemma upE [case_names bottom up, cases type: u]:
   208   "\<lbrakk>p = \<bottom> \<Longrightarrow> Q; \<And>x. p = up\<cdot>x \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
   209 apply (cases p)
   210 apply (simp add: inst_up_pcpo)
   211 apply (simp add: up_def cont_Iup)
   212 done
   213 
   214 lemma up_induct [case_names bottom up, induct type: u]:
   215   "\<lbrakk>P \<bottom>; \<And>x. P (up\<cdot>x)\<rbrakk> \<Longrightarrow> P x"
   216 by (cases x, simp_all)
   217 
   218 text \<open>lifting preserves chain-finiteness\<close>
   219 
   220 lemma up_chain_cases:
   221   assumes Y: "chain Y" obtains "\<forall>i. Y i = \<bottom>"
   222   | A k where "\<forall>i. up\<cdot>(A i) = Y (i + k)" and "chain A" and "(\<Squnion>i. Y i) = up\<cdot>(\<Squnion>i. A i)"
   223 apply (rule up_chain_lemma [OF Y])
   224 apply (simp_all add: inst_up_pcpo up_def cont_Iup lub_eqI)
   225 done
   226 
   227 lemma compact_up: "compact x \<Longrightarrow> compact (up\<cdot>x)"
   228 apply (rule compactI2)
   229 apply (erule up_chain_cases)
   230 apply simp
   231 apply (drule (1) compactD2, simp)
   232 apply (erule exE)
   233 apply (drule_tac f="up" and x="x" in monofun_cfun_arg)
   234 apply (simp, erule exI)
   235 done
   236 
   237 lemma compact_upD: "compact (up\<cdot>x) \<Longrightarrow> compact x"
   238 unfolding compact_def
   239 by (drule adm_subst [OF cont_Rep_cfun2 [where f=up]], simp)
   240 
   241 lemma compact_up_iff [simp]: "compact (up\<cdot>x) = compact x"
   242 by (safe elim!: compact_up compact_upD)
   243 
   244 instance u :: (chfin) chfin
   245 apply intro_classes
   246 apply (erule compact_imp_max_in_chain)
   247 apply (rule_tac p="\<Squnion>i. Y i" in upE, simp_all)
   248 done
   249 
   250 text \<open>properties of fup\<close>
   251 
   252 lemma fup1 [simp]: "fup\<cdot>f\<cdot>\<bottom> = \<bottom>"
   253 by (simp add: fup_def cont_Ifup1 cont_Ifup2 inst_up_pcpo cont2cont_LAM)
   254 
   255 lemma fup2 [simp]: "fup\<cdot>f\<cdot>(up\<cdot>x) = f\<cdot>x"
   256 by (simp add: up_def fup_def cont_Iup cont_Ifup1 cont_Ifup2 cont2cont_LAM)
   257 
   258 lemma fup3 [simp]: "fup\<cdot>up\<cdot>x = x"
   259 by (cases x, simp_all)
   260 
   261 end