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