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