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