src/HOL/HOLCF/Ssum.thy
author wenzelm
Tue Mar 29 17:47:11 2011 +0200 (2011-03-29)
changeset 42151 4da4fc77664b
parent 40834 a1249aeff5b6
child 44066 d74182c93f04
permissions -rw-r--r--
tuned headers;
     1 (*  Title:      HOL/HOLCF/Ssum.thy
     2     Author:     Franz Regensburger
     3     Author:     Brian Huffman
     4 *)
     5 
     6 header {* The type of strict sums *}
     7 
     8 theory Ssum
     9 imports Tr
    10 begin
    11 
    12 default_sort pcpo
    13 
    14 subsection {* Definition of strict sum type *}
    15 
    16 pcpodef ('a, 'b) ssum (infixr "++" 10) = 
    17   "{p :: tr \<times> ('a \<times> 'b). p = \<bottom> \<or>
    18     (fst p = TT \<and> fst (snd p) \<noteq> \<bottom> \<and> snd (snd p) = \<bottom>) \<or>
    19     (fst p = FF \<and> fst (snd p) = \<bottom> \<and> snd (snd p) \<noteq> \<bottom>) }"
    20 by simp_all
    21 
    22 instance ssum :: ("{chfin,pcpo}", "{chfin,pcpo}") chfin
    23 by (rule typedef_chfin [OF type_definition_ssum below_ssum_def])
    24 
    25 type_notation (xsymbols)
    26   ssum  ("(_ \<oplus>/ _)" [21, 20] 20)
    27 type_notation (HTML output)
    28   ssum  ("(_ \<oplus>/ _)" [21, 20] 20)
    29 
    30 
    31 subsection {* Definitions of constructors *}
    32 
    33 definition
    34   sinl :: "'a \<rightarrow> ('a ++ 'b)" where
    35   "sinl = (\<Lambda> a. Abs_ssum (seq\<cdot>a\<cdot>TT, a, \<bottom>))"
    36 
    37 definition
    38   sinr :: "'b \<rightarrow> ('a ++ 'b)" where
    39   "sinr = (\<Lambda> b. Abs_ssum (seq\<cdot>b\<cdot>FF, \<bottom>, b))"
    40 
    41 lemma sinl_ssum: "(seq\<cdot>a\<cdot>TT, a, \<bottom>) \<in> ssum"
    42 by (simp add: ssum_def seq_conv_if)
    43 
    44 lemma sinr_ssum: "(seq\<cdot>b\<cdot>FF, \<bottom>, b) \<in> ssum"
    45 by (simp add: ssum_def seq_conv_if)
    46 
    47 lemma Rep_ssum_sinl: "Rep_ssum (sinl\<cdot>a) = (seq\<cdot>a\<cdot>TT, a, \<bottom>)"
    48 by (simp add: sinl_def cont_Abs_ssum Abs_ssum_inverse sinl_ssum)
    49 
    50 lemma Rep_ssum_sinr: "Rep_ssum (sinr\<cdot>b) = (seq\<cdot>b\<cdot>FF, \<bottom>, b)"
    51 by (simp add: sinr_def cont_Abs_ssum Abs_ssum_inverse sinr_ssum)
    52 
    53 lemmas Rep_ssum_simps =
    54   Rep_ssum_inject [symmetric] below_ssum_def
    55   Pair_fst_snd_eq below_prod_def
    56   Rep_ssum_strict Rep_ssum_sinl Rep_ssum_sinr
    57 
    58 subsection {* Properties of \emph{sinl} and \emph{sinr} *}
    59 
    60 text {* Ordering *}
    61 
    62 lemma sinl_below [simp]: "(sinl\<cdot>x \<sqsubseteq> sinl\<cdot>y) = (x \<sqsubseteq> y)"
    63 by (simp add: Rep_ssum_simps seq_conv_if)
    64 
    65 lemma sinr_below [simp]: "(sinr\<cdot>x \<sqsubseteq> sinr\<cdot>y) = (x \<sqsubseteq> y)"
    66 by (simp add: Rep_ssum_simps seq_conv_if)
    67 
    68 lemma sinl_below_sinr [simp]: "(sinl\<cdot>x \<sqsubseteq> sinr\<cdot>y) = (x = \<bottom>)"
    69 by (simp add: Rep_ssum_simps seq_conv_if)
    70 
    71 lemma sinr_below_sinl [simp]: "(sinr\<cdot>x \<sqsubseteq> sinl\<cdot>y) = (x = \<bottom>)"
    72 by (simp add: Rep_ssum_simps seq_conv_if)
    73 
    74 text {* Equality *}
    75 
    76 lemma sinl_eq [simp]: "(sinl\<cdot>x = sinl\<cdot>y) = (x = y)"
    77 by (simp add: po_eq_conv)
    78 
    79 lemma sinr_eq [simp]: "(sinr\<cdot>x = sinr\<cdot>y) = (x = y)"
    80 by (simp add: po_eq_conv)
    81 
    82 lemma sinl_eq_sinr [simp]: "(sinl\<cdot>x = sinr\<cdot>y) = (x = \<bottom> \<and> y = \<bottom>)"
    83 by (subst po_eq_conv, simp)
    84 
    85 lemma sinr_eq_sinl [simp]: "(sinr\<cdot>x = sinl\<cdot>y) = (x = \<bottom> \<and> y = \<bottom>)"
    86 by (subst po_eq_conv, simp)
    87 
    88 lemma sinl_inject: "sinl\<cdot>x = sinl\<cdot>y \<Longrightarrow> x = y"
    89 by (rule sinl_eq [THEN iffD1])
    90 
    91 lemma sinr_inject: "sinr\<cdot>x = sinr\<cdot>y \<Longrightarrow> x = y"
    92 by (rule sinr_eq [THEN iffD1])
    93 
    94 text {* Strictness *}
    95 
    96 lemma sinl_strict [simp]: "sinl\<cdot>\<bottom> = \<bottom>"
    97 by (simp add: Rep_ssum_simps)
    98 
    99 lemma sinr_strict [simp]: "sinr\<cdot>\<bottom> = \<bottom>"
   100 by (simp add: Rep_ssum_simps)
   101 
   102 lemma sinl_bottom_iff [simp]: "(sinl\<cdot>x = \<bottom>) = (x = \<bottom>)"
   103 using sinl_eq [of "x" "\<bottom>"] by simp
   104 
   105 lemma sinr_bottom_iff [simp]: "(sinr\<cdot>x = \<bottom>) = (x = \<bottom>)"
   106 using sinr_eq [of "x" "\<bottom>"] by simp
   107 
   108 lemma sinl_defined: "x \<noteq> \<bottom> \<Longrightarrow> sinl\<cdot>x \<noteq> \<bottom>"
   109 by simp
   110 
   111 lemma sinr_defined: "x \<noteq> \<bottom> \<Longrightarrow> sinr\<cdot>x \<noteq> \<bottom>"
   112 by simp
   113 
   114 text {* Compactness *}
   115 
   116 lemma compact_sinl: "compact x \<Longrightarrow> compact (sinl\<cdot>x)"
   117 by (rule compact_ssum, simp add: Rep_ssum_sinl)
   118 
   119 lemma compact_sinr: "compact x \<Longrightarrow> compact (sinr\<cdot>x)"
   120 by (rule compact_ssum, simp add: Rep_ssum_sinr)
   121 
   122 lemma compact_sinlD: "compact (sinl\<cdot>x) \<Longrightarrow> compact x"
   123 unfolding compact_def
   124 by (drule adm_subst [OF cont_Rep_cfun2 [where f=sinl]], simp)
   125 
   126 lemma compact_sinrD: "compact (sinr\<cdot>x) \<Longrightarrow> compact x"
   127 unfolding compact_def
   128 by (drule adm_subst [OF cont_Rep_cfun2 [where f=sinr]], simp)
   129 
   130 lemma compact_sinl_iff [simp]: "compact (sinl\<cdot>x) = compact x"
   131 by (safe elim!: compact_sinl compact_sinlD)
   132 
   133 lemma compact_sinr_iff [simp]: "compact (sinr\<cdot>x) = compact x"
   134 by (safe elim!: compact_sinr compact_sinrD)
   135 
   136 subsection {* Case analysis *}
   137 
   138 lemma ssumE [case_names bottom sinl sinr, cases type: ssum]:
   139   obtains "p = \<bottom>"
   140   | x where "p = sinl\<cdot>x" and "x \<noteq> \<bottom>"
   141   | y where "p = sinr\<cdot>y" and "y \<noteq> \<bottom>"
   142 using Rep_ssum [of p] by (auto simp add: ssum_def Rep_ssum_simps)
   143 
   144 lemma ssum_induct [case_names bottom sinl sinr, induct type: ssum]:
   145   "\<lbrakk>P \<bottom>;
   146    \<And>x. x \<noteq> \<bottom> \<Longrightarrow> P (sinl\<cdot>x);
   147    \<And>y. y \<noteq> \<bottom> \<Longrightarrow> P (sinr\<cdot>y)\<rbrakk> \<Longrightarrow> P x"
   148 by (cases x, simp_all)
   149 
   150 lemma ssumE2 [case_names sinl sinr]:
   151   "\<lbrakk>\<And>x. p = sinl\<cdot>x \<Longrightarrow> Q; \<And>y. p = sinr\<cdot>y \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
   152 by (cases p, simp only: sinl_strict [symmetric], simp, simp)
   153 
   154 lemma below_sinlD: "p \<sqsubseteq> sinl\<cdot>x \<Longrightarrow> \<exists>y. p = sinl\<cdot>y \<and> y \<sqsubseteq> x"
   155 by (cases p, rule_tac x="\<bottom>" in exI, simp_all)
   156 
   157 lemma below_sinrD: "p \<sqsubseteq> sinr\<cdot>x \<Longrightarrow> \<exists>y. p = sinr\<cdot>y \<and> y \<sqsubseteq> x"
   158 by (cases p, rule_tac x="\<bottom>" in exI, simp_all)
   159 
   160 subsection {* Case analysis combinator *}
   161 
   162 definition
   163   sscase :: "('a \<rightarrow> 'c) \<rightarrow> ('b \<rightarrow> 'c) \<rightarrow> ('a ++ 'b) \<rightarrow> 'c" where
   164   "sscase = (\<Lambda> f g s. (\<lambda>(t, x, y). If t then f\<cdot>x else g\<cdot>y) (Rep_ssum s))"
   165 
   166 translations
   167   "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"
   168 
   169 translations
   170   "\<Lambda>(XCONST sinl\<cdot>x). t" == "CONST sscase\<cdot>(\<Lambda> x. t)\<cdot>\<bottom>"
   171   "\<Lambda>(XCONST sinr\<cdot>y). t" == "CONST sscase\<cdot>\<bottom>\<cdot>(\<Lambda> y. t)"
   172 
   173 lemma beta_sscase:
   174   "sscase\<cdot>f\<cdot>g\<cdot>s = (\<lambda>(t, x, y). If t then f\<cdot>x else g\<cdot>y) (Rep_ssum s)"
   175 unfolding sscase_def by (simp add: cont_Rep_ssum)
   176 
   177 lemma sscase1 [simp]: "sscase\<cdot>f\<cdot>g\<cdot>\<bottom> = \<bottom>"
   178 unfolding beta_sscase by (simp add: Rep_ssum_strict)
   179 
   180 lemma sscase2 [simp]: "x \<noteq> \<bottom> \<Longrightarrow> sscase\<cdot>f\<cdot>g\<cdot>(sinl\<cdot>x) = f\<cdot>x"
   181 unfolding beta_sscase by (simp add: Rep_ssum_sinl)
   182 
   183 lemma sscase3 [simp]: "y \<noteq> \<bottom> \<Longrightarrow> sscase\<cdot>f\<cdot>g\<cdot>(sinr\<cdot>y) = g\<cdot>y"
   184 unfolding beta_sscase by (simp add: Rep_ssum_sinr)
   185 
   186 lemma sscase4 [simp]: "sscase\<cdot>sinl\<cdot>sinr\<cdot>z = z"
   187 by (cases z, simp_all)
   188 
   189 subsection {* Strict sum preserves flatness *}
   190 
   191 instance ssum :: (flat, flat) flat
   192 apply (intro_classes, clarify)
   193 apply (case_tac x, simp)
   194 apply (case_tac y, simp_all add: flat_below_iff)
   195 apply (case_tac y, simp_all add: flat_below_iff)
   196 done
   197 
   198 end