src/HOL/HOLCF/Ssum.thy
changeset 41022 0437dbc127b3
parent 41015 a3e505b236e7
child 41082 a1249aeff5b6
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/HOLCF/Ssum.thy	Sat Nov 27 16:08:10 2010 -0800
     1.3 @@ -0,0 +1,198 @@
     1.4 +(*  Title:      HOLCF/Ssum.thy
     1.5 +    Author:     Franz Regensburger
     1.6 +    Author:     Brian Huffman
     1.7 +*)
     1.8 +
     1.9 +header {* The type of strict sums *}
    1.10 +
    1.11 +theory Ssum
    1.12 +imports Tr
    1.13 +begin
    1.14 +
    1.15 +default_sort pcpo
    1.16 +
    1.17 +subsection {* Definition of strict sum type *}
    1.18 +
    1.19 +pcpodef ('a, 'b) ssum (infixr "++" 10) = 
    1.20 +  "{p :: tr \<times> ('a \<times> 'b). p = \<bottom> \<or>
    1.21 +    (fst p = TT \<and> fst (snd p) \<noteq> \<bottom> \<and> snd (snd p) = \<bottom>) \<or>
    1.22 +    (fst p = FF \<and> fst (snd p) = \<bottom> \<and> snd (snd p) \<noteq> \<bottom>) }"
    1.23 +by simp_all
    1.24 +
    1.25 +instance ssum :: ("{chfin,pcpo}", "{chfin,pcpo}") chfin
    1.26 +by (rule typedef_chfin [OF type_definition_ssum below_ssum_def])
    1.27 +
    1.28 +type_notation (xsymbols)
    1.29 +  ssum  ("(_ \<oplus>/ _)" [21, 20] 20)
    1.30 +type_notation (HTML output)
    1.31 +  ssum  ("(_ \<oplus>/ _)" [21, 20] 20)
    1.32 +
    1.33 +
    1.34 +subsection {* Definitions of constructors *}
    1.35 +
    1.36 +definition
    1.37 +  sinl :: "'a \<rightarrow> ('a ++ 'b)" where
    1.38 +  "sinl = (\<Lambda> a. Abs_ssum (seq\<cdot>a\<cdot>TT, a, \<bottom>))"
    1.39 +
    1.40 +definition
    1.41 +  sinr :: "'b \<rightarrow> ('a ++ 'b)" where
    1.42 +  "sinr = (\<Lambda> b. Abs_ssum (seq\<cdot>b\<cdot>FF, \<bottom>, b))"
    1.43 +
    1.44 +lemma sinl_ssum: "(seq\<cdot>a\<cdot>TT, a, \<bottom>) \<in> ssum"
    1.45 +by (simp add: ssum_def seq_conv_if)
    1.46 +
    1.47 +lemma sinr_ssum: "(seq\<cdot>b\<cdot>FF, \<bottom>, b) \<in> ssum"
    1.48 +by (simp add: ssum_def seq_conv_if)
    1.49 +
    1.50 +lemma Rep_ssum_sinl: "Rep_ssum (sinl\<cdot>a) = (seq\<cdot>a\<cdot>TT, a, \<bottom>)"
    1.51 +by (simp add: sinl_def cont_Abs_ssum Abs_ssum_inverse sinl_ssum)
    1.52 +
    1.53 +lemma Rep_ssum_sinr: "Rep_ssum (sinr\<cdot>b) = (seq\<cdot>b\<cdot>FF, \<bottom>, b)"
    1.54 +by (simp add: sinr_def cont_Abs_ssum Abs_ssum_inverse sinr_ssum)
    1.55 +
    1.56 +lemmas Rep_ssum_simps =
    1.57 +  Rep_ssum_inject [symmetric] below_ssum_def
    1.58 +  Pair_fst_snd_eq below_prod_def
    1.59 +  Rep_ssum_strict Rep_ssum_sinl Rep_ssum_sinr
    1.60 +
    1.61 +subsection {* Properties of \emph{sinl} and \emph{sinr} *}
    1.62 +
    1.63 +text {* Ordering *}
    1.64 +
    1.65 +lemma sinl_below [simp]: "(sinl\<cdot>x \<sqsubseteq> sinl\<cdot>y) = (x \<sqsubseteq> y)"
    1.66 +by (simp add: Rep_ssum_simps seq_conv_if)
    1.67 +
    1.68 +lemma sinr_below [simp]: "(sinr\<cdot>x \<sqsubseteq> sinr\<cdot>y) = (x \<sqsubseteq> y)"
    1.69 +by (simp add: Rep_ssum_simps seq_conv_if)
    1.70 +
    1.71 +lemma sinl_below_sinr [simp]: "(sinl\<cdot>x \<sqsubseteq> sinr\<cdot>y) = (x = \<bottom>)"
    1.72 +by (simp add: Rep_ssum_simps seq_conv_if)
    1.73 +
    1.74 +lemma sinr_below_sinl [simp]: "(sinr\<cdot>x \<sqsubseteq> sinl\<cdot>y) = (x = \<bottom>)"
    1.75 +by (simp add: Rep_ssum_simps seq_conv_if)
    1.76 +
    1.77 +text {* Equality *}
    1.78 +
    1.79 +lemma sinl_eq [simp]: "(sinl\<cdot>x = sinl\<cdot>y) = (x = y)"
    1.80 +by (simp add: po_eq_conv)
    1.81 +
    1.82 +lemma sinr_eq [simp]: "(sinr\<cdot>x = sinr\<cdot>y) = (x = y)"
    1.83 +by (simp add: po_eq_conv)
    1.84 +
    1.85 +lemma sinl_eq_sinr [simp]: "(sinl\<cdot>x = sinr\<cdot>y) = (x = \<bottom> \<and> y = \<bottom>)"
    1.86 +by (subst po_eq_conv, simp)
    1.87 +
    1.88 +lemma sinr_eq_sinl [simp]: "(sinr\<cdot>x = sinl\<cdot>y) = (x = \<bottom> \<and> y = \<bottom>)"
    1.89 +by (subst po_eq_conv, simp)
    1.90 +
    1.91 +lemma sinl_inject: "sinl\<cdot>x = sinl\<cdot>y \<Longrightarrow> x = y"
    1.92 +by (rule sinl_eq [THEN iffD1])
    1.93 +
    1.94 +lemma sinr_inject: "sinr\<cdot>x = sinr\<cdot>y \<Longrightarrow> x = y"
    1.95 +by (rule sinr_eq [THEN iffD1])
    1.96 +
    1.97 +text {* Strictness *}
    1.98 +
    1.99 +lemma sinl_strict [simp]: "sinl\<cdot>\<bottom> = \<bottom>"
   1.100 +by (simp add: Rep_ssum_simps)
   1.101 +
   1.102 +lemma sinr_strict [simp]: "sinr\<cdot>\<bottom> = \<bottom>"
   1.103 +by (simp add: Rep_ssum_simps)
   1.104 +
   1.105 +lemma sinl_bottom_iff [simp]: "(sinl\<cdot>x = \<bottom>) = (x = \<bottom>)"
   1.106 +using sinl_eq [of "x" "\<bottom>"] by simp
   1.107 +
   1.108 +lemma sinr_bottom_iff [simp]: "(sinr\<cdot>x = \<bottom>) = (x = \<bottom>)"
   1.109 +using sinr_eq [of "x" "\<bottom>"] by simp
   1.110 +
   1.111 +lemma sinl_defined: "x \<noteq> \<bottom> \<Longrightarrow> sinl\<cdot>x \<noteq> \<bottom>"
   1.112 +by simp
   1.113 +
   1.114 +lemma sinr_defined: "x \<noteq> \<bottom> \<Longrightarrow> sinr\<cdot>x \<noteq> \<bottom>"
   1.115 +by simp
   1.116 +
   1.117 +text {* Compactness *}
   1.118 +
   1.119 +lemma compact_sinl: "compact x \<Longrightarrow> compact (sinl\<cdot>x)"
   1.120 +by (rule compact_ssum, simp add: Rep_ssum_sinl)
   1.121 +
   1.122 +lemma compact_sinr: "compact x \<Longrightarrow> compact (sinr\<cdot>x)"
   1.123 +by (rule compact_ssum, simp add: Rep_ssum_sinr)
   1.124 +
   1.125 +lemma compact_sinlD: "compact (sinl\<cdot>x) \<Longrightarrow> compact x"
   1.126 +unfolding compact_def
   1.127 +by (drule adm_subst [OF cont_Rep_cfun2 [where f=sinl]], simp)
   1.128 +
   1.129 +lemma compact_sinrD: "compact (sinr\<cdot>x) \<Longrightarrow> compact x"
   1.130 +unfolding compact_def
   1.131 +by (drule adm_subst [OF cont_Rep_cfun2 [where f=sinr]], simp)
   1.132 +
   1.133 +lemma compact_sinl_iff [simp]: "compact (sinl\<cdot>x) = compact x"
   1.134 +by (safe elim!: compact_sinl compact_sinlD)
   1.135 +
   1.136 +lemma compact_sinr_iff [simp]: "compact (sinr\<cdot>x) = compact x"
   1.137 +by (safe elim!: compact_sinr compact_sinrD)
   1.138 +
   1.139 +subsection {* Case analysis *}
   1.140 +
   1.141 +lemma ssumE [case_names bottom sinl sinr, cases type: ssum]:
   1.142 +  obtains "p = \<bottom>"
   1.143 +  | x where "p = sinl\<cdot>x" and "x \<noteq> \<bottom>"
   1.144 +  | y where "p = sinr\<cdot>y" and "y \<noteq> \<bottom>"
   1.145 +using Rep_ssum [of p] by (auto simp add: ssum_def Rep_ssum_simps)
   1.146 +
   1.147 +lemma ssum_induct [case_names bottom sinl sinr, induct type: ssum]:
   1.148 +  "\<lbrakk>P \<bottom>;
   1.149 +   \<And>x. x \<noteq> \<bottom> \<Longrightarrow> P (sinl\<cdot>x);
   1.150 +   \<And>y. y \<noteq> \<bottom> \<Longrightarrow> P (sinr\<cdot>y)\<rbrakk> \<Longrightarrow> P x"
   1.151 +by (cases x, simp_all)
   1.152 +
   1.153 +lemma ssumE2 [case_names sinl sinr]:
   1.154 +  "\<lbrakk>\<And>x. p = sinl\<cdot>x \<Longrightarrow> Q; \<And>y. p = sinr\<cdot>y \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
   1.155 +by (cases p, simp only: sinl_strict [symmetric], simp, simp)
   1.156 +
   1.157 +lemma below_sinlD: "p \<sqsubseteq> sinl\<cdot>x \<Longrightarrow> \<exists>y. p = sinl\<cdot>y \<and> y \<sqsubseteq> x"
   1.158 +by (cases p, rule_tac x="\<bottom>" in exI, simp_all)
   1.159 +
   1.160 +lemma below_sinrD: "p \<sqsubseteq> sinr\<cdot>x \<Longrightarrow> \<exists>y. p = sinr\<cdot>y \<and> y \<sqsubseteq> x"
   1.161 +by (cases p, rule_tac x="\<bottom>" in exI, simp_all)
   1.162 +
   1.163 +subsection {* Case analysis combinator *}
   1.164 +
   1.165 +definition
   1.166 +  sscase :: "('a \<rightarrow> 'c) \<rightarrow> ('b \<rightarrow> 'c) \<rightarrow> ('a ++ 'b) \<rightarrow> 'c" where
   1.167 +  "sscase = (\<Lambda> f g s. (\<lambda>(t, x, y). If t then f\<cdot>x else g\<cdot>y) (Rep_ssum s))"
   1.168 +
   1.169 +translations
   1.170 +  "case s of XCONST sinl\<cdot>x \<Rightarrow> t1 | XCONST sinr\<cdot>y \<Rightarrow> t2" == "CONST sscase\<cdot>(\<Lambda> x. t1)\<cdot>(\<Lambda> y. t2)\<cdot>s"
   1.171 +
   1.172 +translations
   1.173 +  "\<Lambda>(XCONST sinl\<cdot>x). t" == "CONST sscase\<cdot>(\<Lambda> x. t)\<cdot>\<bottom>"
   1.174 +  "\<Lambda>(XCONST sinr\<cdot>y). t" == "CONST sscase\<cdot>\<bottom>\<cdot>(\<Lambda> y. t)"
   1.175 +
   1.176 +lemma beta_sscase:
   1.177 +  "sscase\<cdot>f\<cdot>g\<cdot>s = (\<lambda>(t, x, y). If t then f\<cdot>x else g\<cdot>y) (Rep_ssum s)"
   1.178 +unfolding sscase_def by (simp add: cont_Rep_ssum [THEN cont_compose])
   1.179 +
   1.180 +lemma sscase1 [simp]: "sscase\<cdot>f\<cdot>g\<cdot>\<bottom> = \<bottom>"
   1.181 +unfolding beta_sscase by (simp add: Rep_ssum_strict)
   1.182 +
   1.183 +lemma sscase2 [simp]: "x \<noteq> \<bottom> \<Longrightarrow> sscase\<cdot>f\<cdot>g\<cdot>(sinl\<cdot>x) = f\<cdot>x"
   1.184 +unfolding beta_sscase by (simp add: Rep_ssum_sinl)
   1.185 +
   1.186 +lemma sscase3 [simp]: "y \<noteq> \<bottom> \<Longrightarrow> sscase\<cdot>f\<cdot>g\<cdot>(sinr\<cdot>y) = g\<cdot>y"
   1.187 +unfolding beta_sscase by (simp add: Rep_ssum_sinr)
   1.188 +
   1.189 +lemma sscase4 [simp]: "sscase\<cdot>sinl\<cdot>sinr\<cdot>z = z"
   1.190 +by (cases z, simp_all)
   1.191 +
   1.192 +subsection {* Strict sum preserves flatness *}
   1.193 +
   1.194 +instance ssum :: (flat, flat) flat
   1.195 +apply (intro_classes, clarify)
   1.196 +apply (case_tac x, simp)
   1.197 +apply (case_tac y, simp_all add: flat_below_iff)
   1.198 +apply (case_tac y, simp_all add: flat_below_iff)
   1.199 +done
   1.200 +
   1.201 +end