src/HOL/HOLCF/Ssum.thy
changeset 62175 8ffc4d0e652d
parent 61998 b66d2ca1f907
child 67312 0d25e02759b7
equal deleted inserted replaced
62174:fae6233c5f37 62175:8ffc4d0e652d
     1 (*  Title:      HOL/HOLCF/Ssum.thy
     1 (*  Title:      HOL/HOLCF/Ssum.thy
     2     Author:     Franz Regensburger
     2     Author:     Franz Regensburger
     3     Author:     Brian Huffman
     3     Author:     Brian Huffman
     4 *)
     4 *)
     5 
     5 
     6 section {* The type of strict sums *}
     6 section \<open>The type of strict sums\<close>
     7 
     7 
     8 theory Ssum
     8 theory Ssum
     9 imports Tr
     9 imports Tr
    10 begin
    10 begin
    11 
    11 
    12 default_sort pcpo
    12 default_sort pcpo
    13 
    13 
    14 subsection {* Definition of strict sum type *}
    14 subsection \<open>Definition of strict sum type\<close>
    15 
    15 
    16 definition
    16 definition
    17   "ssum =
    17   "ssum =
    18     {p :: tr \<times> ('a \<times> 'b). p = \<bottom> \<or>
    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>
    19       (fst p = TT \<and> fst (snd p) \<noteq> \<bottom> \<and> snd (snd p) = \<bottom>) \<or>
    27 
    27 
    28 type_notation (ASCII)
    28 type_notation (ASCII)
    29   ssum  (infixr "++" 10)
    29   ssum  (infixr "++" 10)
    30 
    30 
    31 
    31 
    32 subsection {* Definitions of constructors *}
    32 subsection \<open>Definitions of constructors\<close>
    33 
    33 
    34 definition
    34 definition
    35   sinl :: "'a \<rightarrow> ('a ++ 'b)" where
    35   sinl :: "'a \<rightarrow> ('a ++ 'b)" where
    36   "sinl = (\<Lambda> a. Abs_ssum (seq\<cdot>a\<cdot>TT, a, \<bottom>))"
    36   "sinl = (\<Lambda> a. Abs_ssum (seq\<cdot>a\<cdot>TT, a, \<bottom>))"
    37 
    37 
    54 lemmas Rep_ssum_simps =
    54 lemmas Rep_ssum_simps =
    55   Rep_ssum_inject [symmetric] below_ssum_def
    55   Rep_ssum_inject [symmetric] below_ssum_def
    56   prod_eq_iff below_prod_def
    56   prod_eq_iff below_prod_def
    57   Rep_ssum_strict Rep_ssum_sinl Rep_ssum_sinr
    57   Rep_ssum_strict Rep_ssum_sinl Rep_ssum_sinr
    58 
    58 
    59 subsection {* Properties of \emph{sinl} and \emph{sinr} *}
    59 subsection \<open>Properties of \emph{sinl} and \emph{sinr}\<close>
    60 
    60 
    61 text {* Ordering *}
    61 text \<open>Ordering\<close>
    62 
    62 
    63 lemma sinl_below [simp]: "(sinl\<cdot>x \<sqsubseteq> sinl\<cdot>y) = (x \<sqsubseteq> y)"
    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)
    64 by (simp add: Rep_ssum_simps seq_conv_if)
    65 
    65 
    66 lemma sinr_below [simp]: "(sinr\<cdot>x \<sqsubseteq> sinr\<cdot>y) = (x \<sqsubseteq> y)"
    66 lemma sinr_below [simp]: "(sinr\<cdot>x \<sqsubseteq> sinr\<cdot>y) = (x \<sqsubseteq> y)"
    70 by (simp add: Rep_ssum_simps seq_conv_if)
    70 by (simp add: Rep_ssum_simps seq_conv_if)
    71 
    71 
    72 lemma sinr_below_sinl [simp]: "(sinr\<cdot>x \<sqsubseteq> sinl\<cdot>y) = (x = \<bottom>)"
    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)
    73 by (simp add: Rep_ssum_simps seq_conv_if)
    74 
    74 
    75 text {* Equality *}
    75 text \<open>Equality\<close>
    76 
    76 
    77 lemma sinl_eq [simp]: "(sinl\<cdot>x = sinl\<cdot>y) = (x = y)"
    77 lemma sinl_eq [simp]: "(sinl\<cdot>x = sinl\<cdot>y) = (x = y)"
    78 by (simp add: po_eq_conv)
    78 by (simp add: po_eq_conv)
    79 
    79 
    80 lemma sinr_eq [simp]: "(sinr\<cdot>x = sinr\<cdot>y) = (x = y)"
    80 lemma sinr_eq [simp]: "(sinr\<cdot>x = sinr\<cdot>y) = (x = y)"
    90 by (rule sinl_eq [THEN iffD1])
    90 by (rule sinl_eq [THEN iffD1])
    91 
    91 
    92 lemma sinr_inject: "sinr\<cdot>x = sinr\<cdot>y \<Longrightarrow> x = y"
    92 lemma sinr_inject: "sinr\<cdot>x = sinr\<cdot>y \<Longrightarrow> x = y"
    93 by (rule sinr_eq [THEN iffD1])
    93 by (rule sinr_eq [THEN iffD1])
    94 
    94 
    95 text {* Strictness *}
    95 text \<open>Strictness\<close>
    96 
    96 
    97 lemma sinl_strict [simp]: "sinl\<cdot>\<bottom> = \<bottom>"
    97 lemma sinl_strict [simp]: "sinl\<cdot>\<bottom> = \<bottom>"
    98 by (simp add: Rep_ssum_simps)
    98 by (simp add: Rep_ssum_simps)
    99 
    99 
   100 lemma sinr_strict [simp]: "sinr\<cdot>\<bottom> = \<bottom>"
   100 lemma sinr_strict [simp]: "sinr\<cdot>\<bottom> = \<bottom>"
   110 by simp
   110 by simp
   111 
   111 
   112 lemma sinr_defined: "x \<noteq> \<bottom> \<Longrightarrow> sinr\<cdot>x \<noteq> \<bottom>"
   112 lemma sinr_defined: "x \<noteq> \<bottom> \<Longrightarrow> sinr\<cdot>x \<noteq> \<bottom>"
   113 by simp
   113 by simp
   114 
   114 
   115 text {* Compactness *}
   115 text \<open>Compactness\<close>
   116 
   116 
   117 lemma compact_sinl: "compact x \<Longrightarrow> compact (sinl\<cdot>x)"
   117 lemma compact_sinl: "compact x \<Longrightarrow> compact (sinl\<cdot>x)"
   118 by (rule compact_ssum, simp add: Rep_ssum_sinl)
   118 by (rule compact_ssum, simp add: Rep_ssum_sinl)
   119 
   119 
   120 lemma compact_sinr: "compact x \<Longrightarrow> compact (sinr\<cdot>x)"
   120 lemma compact_sinr: "compact x \<Longrightarrow> compact (sinr\<cdot>x)"
   132 by (safe elim!: compact_sinl compact_sinlD)
   132 by (safe elim!: compact_sinl compact_sinlD)
   133 
   133 
   134 lemma compact_sinr_iff [simp]: "compact (sinr\<cdot>x) = compact x"
   134 lemma compact_sinr_iff [simp]: "compact (sinr\<cdot>x) = compact x"
   135 by (safe elim!: compact_sinr compact_sinrD)
   135 by (safe elim!: compact_sinr compact_sinrD)
   136 
   136 
   137 subsection {* Case analysis *}
   137 subsection \<open>Case analysis\<close>
   138 
   138 
   139 lemma ssumE [case_names bottom sinl sinr, cases type: ssum]:
   139 lemma ssumE [case_names bottom sinl sinr, cases type: ssum]:
   140   obtains "p = \<bottom>"
   140   obtains "p = \<bottom>"
   141   | x where "p = sinl\<cdot>x" and "x \<noteq> \<bottom>"
   141   | x where "p = sinl\<cdot>x" and "x \<noteq> \<bottom>"
   142   | y where "p = sinr\<cdot>y" and "y \<noteq> \<bottom>"
   142   | y where "p = sinr\<cdot>y" and "y \<noteq> \<bottom>"
   156 by (cases p, rule_tac x="\<bottom>" in exI, simp_all)
   156 by (cases p, rule_tac x="\<bottom>" in exI, simp_all)
   157 
   157 
   158 lemma below_sinrD: "p \<sqsubseteq> sinr\<cdot>x \<Longrightarrow> \<exists>y. p = sinr\<cdot>y \<and> y \<sqsubseteq> x"
   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)
   159 by (cases p, rule_tac x="\<bottom>" in exI, simp_all)
   160 
   160 
   161 subsection {* Case analysis combinator *}
   161 subsection \<open>Case analysis combinator\<close>
   162 
   162 
   163 definition
   163 definition
   164   sscase :: "('a \<rightarrow> 'c) \<rightarrow> ('b \<rightarrow> 'c) \<rightarrow> ('a ++ 'b) \<rightarrow> 'c" where
   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))"
   165   "sscase = (\<Lambda> f g s. (\<lambda>(t, x, y). If t then f\<cdot>x else g\<cdot>y) (Rep_ssum s))"
   166 
   166 
   186 unfolding beta_sscase by (simp add: Rep_ssum_sinr)
   186 unfolding beta_sscase by (simp add: Rep_ssum_sinr)
   187 
   187 
   188 lemma sscase4 [simp]: "sscase\<cdot>sinl\<cdot>sinr\<cdot>z = z"
   188 lemma sscase4 [simp]: "sscase\<cdot>sinl\<cdot>sinr\<cdot>z = z"
   189 by (cases z, simp_all)
   189 by (cases z, simp_all)
   190 
   190 
   191 subsection {* Strict sum preserves flatness *}
   191 subsection \<open>Strict sum preserves flatness\<close>
   192 
   192 
   193 instance ssum :: (flat, flat) flat
   193 instance ssum :: (flat, flat) flat
   194 apply (intro_classes, clarify)
   194 apply (intro_classes, clarify)
   195 apply (case_tac x, simp)
   195 apply (case_tac x, simp)
   196 apply (case_tac y, simp_all add: flat_below_iff)
   196 apply (case_tac y, simp_all add: flat_below_iff)