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