src/HOLCF/Ssum.thy
author haftmann
Fri Jun 19 21:08:07 2009 +0200 (2009-06-19)
changeset 31726 ffd2dc631d88
parent 31115 7d6416f0d1e0
child 32960 69916a850301
permissions -rw-r--r--
merged
huffman@15600
     1
(*  Title:      HOLCF/Ssum.thy
huffman@16060
     2
    Author:     Franz Regensburger and Brian Huffman
huffman@15576
     3
*)
huffman@15576
     4
huffman@15576
     5
header {* The type of strict sums *}
huffman@15576
     6
huffman@15577
     7
theory Ssum
huffman@31115
     8
imports Tr
huffman@15577
     9
begin
huffman@15576
    10
huffman@16083
    11
defaultsort pcpo
huffman@16083
    12
huffman@15593
    13
subsection {* Definition of strict sum type *}
huffman@15593
    14
huffman@17817
    15
pcpodef (Ssum)  ('a, 'b) "++" (infixr "++" 10) = 
huffman@25740
    16
  "{p :: tr \<times> ('a \<times> 'b).
huffman@31115
    17
    (fst p \<sqsubseteq> TT \<longleftrightarrow> snd (snd p) = \<bottom>) \<and>
huffman@31115
    18
    (fst p \<sqsubseteq> FF \<longleftrightarrow> fst (snd p) = \<bottom>)}"
wenzelm@29063
    19
by simp_all
huffman@15576
    20
huffman@25827
    21
instance "++" :: ("{finite_po,pcpo}", "{finite_po,pcpo}") finite_po
huffman@25827
    22
by (rule typedef_finite_po [OF type_definition_Ssum])
huffman@25827
    23
huffman@25827
    24
instance "++" :: ("{chfin,pcpo}", "{chfin,pcpo}") chfin
huffman@31076
    25
by (rule typedef_chfin [OF type_definition_Ssum below_Ssum_def])
huffman@25827
    26
huffman@15576
    27
syntax (xsymbols)
huffman@15576
    28
  "++"		:: "[type, type] => type"	("(_ \<oplus>/ _)" [21, 20] 20)
huffman@15576
    29
syntax (HTML output)
huffman@15576
    30
  "++"		:: "[type, type] => type"	("(_ \<oplus>/ _)" [21, 20] 20)
huffman@15576
    31
huffman@16060
    32
subsection {* Definitions of constructors *}
huffman@15576
    33
wenzelm@25131
    34
definition
wenzelm@25131
    35
  sinl :: "'a \<rightarrow> ('a ++ 'b)" where
huffman@31115
    36
  "sinl = (\<Lambda> a. Abs_Ssum (strictify\<cdot>(\<Lambda> _. TT)\<cdot>a, a, \<bottom>))"
huffman@16060
    37
wenzelm@25131
    38
definition
wenzelm@25131
    39
  sinr :: "'b \<rightarrow> ('a ++ 'b)" where
huffman@31115
    40
  "sinr = (\<Lambda> b. Abs_Ssum (strictify\<cdot>(\<Lambda> _. FF)\<cdot>b, \<bottom>, b))"
huffman@25740
    41
huffman@31115
    42
lemma sinl_Ssum: "(strictify\<cdot>(\<Lambda> _. TT)\<cdot>a, a, \<bottom>) \<in> Ssum"
huffman@25740
    43
by (simp add: Ssum_def strictify_conv_if)
huffman@25740
    44
huffman@31115
    45
lemma sinr_Ssum: "(strictify\<cdot>(\<Lambda> _. FF)\<cdot>b, \<bottom>, b) \<in> Ssum"
huffman@25740
    46
by (simp add: Ssum_def strictify_conv_if)
huffman@25740
    47
huffman@31115
    48
lemma sinl_Abs_Ssum: "sinl\<cdot>a = Abs_Ssum (strictify\<cdot>(\<Lambda> _. TT)\<cdot>a, a, \<bottom>)"
huffman@25740
    49
by (unfold sinl_def, simp add: cont_Abs_Ssum sinl_Ssum)
huffman@25740
    50
huffman@31115
    51
lemma sinr_Abs_Ssum: "sinr\<cdot>b = Abs_Ssum (strictify\<cdot>(\<Lambda> _. FF)\<cdot>b, \<bottom>, b)"
huffman@25740
    52
by (unfold sinr_def, simp add: cont_Abs_Ssum sinr_Ssum)
huffman@25740
    53
huffman@31115
    54
lemma Rep_Ssum_sinl: "Rep_Ssum (sinl\<cdot>a) = (strictify\<cdot>(\<Lambda> _. TT)\<cdot>a, a, \<bottom>)"
huffman@25740
    55
by (simp add: sinl_Abs_Ssum Abs_Ssum_inverse sinl_Ssum)
huffman@25740
    56
huffman@31115
    57
lemma Rep_Ssum_sinr: "Rep_Ssum (sinr\<cdot>b) = (strictify\<cdot>(\<Lambda> _. FF)\<cdot>b, \<bottom>, b)"
huffman@25740
    58
by (simp add: sinr_Abs_Ssum Abs_Ssum_inverse sinr_Ssum)
huffman@16060
    59
huffman@16060
    60
subsection {* Properties of @{term sinl} and @{term sinr} *}
huffman@16060
    61
huffman@25740
    62
text {* Ordering *}
huffman@25740
    63
huffman@31076
    64
lemma sinl_below [simp]: "(sinl\<cdot>x \<sqsubseteq> sinl\<cdot>y) = (x \<sqsubseteq> y)"
huffman@31076
    65
by (simp add: below_Ssum_def Rep_Ssum_sinl strictify_conv_if)
huffman@25740
    66
huffman@31076
    67
lemma sinr_below [simp]: "(sinr\<cdot>x \<sqsubseteq> sinr\<cdot>y) = (x \<sqsubseteq> y)"
huffman@31076
    68
by (simp add: below_Ssum_def Rep_Ssum_sinr strictify_conv_if)
huffman@25740
    69
huffman@31076
    70
lemma sinl_below_sinr [simp]: "(sinl\<cdot>x \<sqsubseteq> sinr\<cdot>y) = (x = \<bottom>)"
huffman@31076
    71
by (simp add: below_Ssum_def Rep_Ssum_sinl Rep_Ssum_sinr strictify_conv_if)
huffman@25740
    72
huffman@31076
    73
lemma sinr_below_sinl [simp]: "(sinr\<cdot>x \<sqsubseteq> sinl\<cdot>y) = (x = \<bottom>)"
huffman@31076
    74
by (simp add: below_Ssum_def Rep_Ssum_sinl Rep_Ssum_sinr strictify_conv_if)
huffman@25740
    75
huffman@25740
    76
text {* Equality *}
huffman@25740
    77
huffman@25740
    78
lemma sinl_eq [simp]: "(sinl\<cdot>x = sinl\<cdot>y) = (x = y)"
huffman@25740
    79
by (simp add: po_eq_conv)
huffman@25740
    80
huffman@25740
    81
lemma sinr_eq [simp]: "(sinr\<cdot>x = sinr\<cdot>y) = (x = y)"
huffman@25740
    82
by (simp add: po_eq_conv)
huffman@25740
    83
huffman@25740
    84
lemma sinl_eq_sinr [simp]: "(sinl\<cdot>x = sinr\<cdot>y) = (x = \<bottom> \<and> y = \<bottom>)"
huffman@25740
    85
by (subst po_eq_conv, simp)
huffman@25740
    86
huffman@25740
    87
lemma sinr_eq_sinl [simp]: "(sinr\<cdot>x = sinl\<cdot>y) = (x = \<bottom> \<and> y = \<bottom>)"
huffman@25740
    88
by (subst po_eq_conv, simp)
huffman@25740
    89
huffman@25740
    90
lemma sinl_inject: "sinl\<cdot>x = sinl\<cdot>y \<Longrightarrow> x = y"
huffman@25740
    91
by (rule sinl_eq [THEN iffD1])
huffman@25740
    92
huffman@25740
    93
lemma sinr_inject: "sinr\<cdot>x = sinr\<cdot>y \<Longrightarrow> x = y"
huffman@25740
    94
by (rule sinr_eq [THEN iffD1])
huffman@25740
    95
huffman@25740
    96
text {* Strictness *}
huffman@17837
    97
huffman@16211
    98
lemma sinl_strict [simp]: "sinl\<cdot>\<bottom> = \<bottom>"
huffman@25915
    99
by (simp add: sinl_Abs_Ssum Abs_Ssum_strict)
huffman@15576
   100
huffman@16211
   101
lemma sinr_strict [simp]: "sinr\<cdot>\<bottom> = \<bottom>"
huffman@25915
   102
by (simp add: sinr_Abs_Ssum Abs_Ssum_strict)
huffman@16060
   103
huffman@16752
   104
lemma sinl_defined_iff [simp]: "(sinl\<cdot>x = \<bottom>) = (x = \<bottom>)"
huffman@17837
   105
by (cut_tac sinl_eq [of "x" "\<bottom>"], simp)
huffman@15576
   106
huffman@16752
   107
lemma sinr_defined_iff [simp]: "(sinr\<cdot>x = \<bottom>) = (x = \<bottom>)"
huffman@17837
   108
by (cut_tac sinr_eq [of "x" "\<bottom>"], simp)
huffman@15576
   109
huffman@16752
   110
lemma sinl_defined [intro!]: "x \<noteq> \<bottom> \<Longrightarrow> sinl\<cdot>x \<noteq> \<bottom>"
huffman@16752
   111
by simp
huffman@16752
   112
huffman@16752
   113
lemma sinr_defined [intro!]: "x \<noteq> \<bottom> \<Longrightarrow> sinr\<cdot>x \<noteq> \<bottom>"
huffman@16752
   114
by simp
huffman@16752
   115
huffman@25882
   116
text {* Compactness *}
huffman@25882
   117
huffman@25882
   118
lemma compact_sinl: "compact x \<Longrightarrow> compact (sinl\<cdot>x)"
huffman@25882
   119
by (rule compact_Ssum, simp add: Rep_Ssum_sinl strictify_conv_if)
huffman@25882
   120
huffman@25882
   121
lemma compact_sinr: "compact x \<Longrightarrow> compact (sinr\<cdot>x)"
huffman@25882
   122
by (rule compact_Ssum, simp add: Rep_Ssum_sinr strictify_conv_if)
huffman@25882
   123
huffman@25882
   124
lemma compact_sinlD: "compact (sinl\<cdot>x) \<Longrightarrow> compact x"
huffman@25882
   125
unfolding compact_def
huffman@25882
   126
by (drule adm_subst [OF cont_Rep_CFun2 [where f=sinl]], simp)
huffman@25882
   127
huffman@25882
   128
lemma compact_sinrD: "compact (sinr\<cdot>x) \<Longrightarrow> compact x"
huffman@25882
   129
unfolding compact_def
huffman@25882
   130
by (drule adm_subst [OF cont_Rep_CFun2 [where f=sinr]], simp)
huffman@25882
   131
huffman@25882
   132
lemma compact_sinl_iff [simp]: "compact (sinl\<cdot>x) = compact x"
huffman@25882
   133
by (safe elim!: compact_sinl compact_sinlD)
huffman@25882
   134
huffman@25882
   135
lemma compact_sinr_iff [simp]: "compact (sinr\<cdot>x) = compact x"
huffman@25882
   136
by (safe elim!: compact_sinr compact_sinrD)
huffman@25882
   137
huffman@16060
   138
subsection {* Case analysis *}
huffman@16060
   139
huffman@16921
   140
lemma Exh_Ssum: 
huffman@16060
   141
  "z = \<bottom> \<or> (\<exists>a. z = sinl\<cdot>a \<and> a \<noteq> \<bottom>) \<or> (\<exists>b. z = sinr\<cdot>b \<and> b \<noteq> \<bottom>)"
huffman@31115
   142
apply (induct z rule: Abs_Ssum_induct)
huffman@31115
   143
apply (case_tac y, rename_tac t a b)
huffman@31115
   144
apply (case_tac t rule: trE)
huffman@25740
   145
apply (rule disjI1)
huffman@31115
   146
apply (simp add: Ssum_def Abs_Ssum_strict)
huffman@25740
   147
apply (rule disjI2, rule disjI1, rule_tac x=a in exI)
huffman@25740
   148
apply (simp add: sinl_Abs_Ssum Ssum_def)
huffman@25740
   149
apply (rule disjI2, rule disjI2, rule_tac x=b in exI)
huffman@25740
   150
apply (simp add: sinr_Abs_Ssum Ssum_def)
huffman@15576
   151
done
huffman@15576
   152
huffman@25740
   153
lemma ssumE [cases type: ++]:
huffman@16060
   154
  "\<lbrakk>p = \<bottom> \<Longrightarrow> Q;
huffman@16060
   155
   \<And>x. \<lbrakk>p = sinl\<cdot>x; x \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> Q;
huffman@16060
   156
   \<And>y. \<lbrakk>p = sinr\<cdot>y; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
huffman@16921
   157
by (cut_tac z=p in Exh_Ssum, auto)
huffman@15576
   158
huffman@25756
   159
lemma ssum_induct [induct type: ++]:
huffman@25756
   160
  "\<lbrakk>P \<bottom>;
huffman@25756
   161
   \<And>x. x \<noteq> \<bottom> \<Longrightarrow> P (sinl\<cdot>x);
huffman@25756
   162
   \<And>y. y \<noteq> \<bottom> \<Longrightarrow> P (sinr\<cdot>y)\<rbrakk> \<Longrightarrow> P x"
huffman@25756
   163
by (cases x, simp_all)
huffman@25756
   164
huffman@15576
   165
lemma ssumE2:
huffman@16060
   166
  "\<lbrakk>\<And>x. p = sinl\<cdot>x \<Longrightarrow> Q; \<And>y. p = sinr\<cdot>y \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
huffman@25740
   167
by (cases p, simp only: sinl_strict [symmetric], simp, simp)
huffman@16060
   168
huffman@31076
   169
lemma below_sinlD: "p \<sqsubseteq> sinl\<cdot>x \<Longrightarrow> \<exists>y. p = sinl\<cdot>y \<and> y \<sqsubseteq> x"
huffman@25740
   170
by (cases p, rule_tac x="\<bottom>" in exI, simp_all)
huffman@15576
   171
huffman@31076
   172
lemma below_sinrD: "p \<sqsubseteq> sinr\<cdot>x \<Longrightarrow> \<exists>y. p = sinr\<cdot>y \<and> y \<sqsubseteq> x"
huffman@25740
   173
by (cases p, rule_tac x="\<bottom>" in exI, simp_all)
huffman@16060
   174
huffman@25740
   175
subsection {* Case analysis combinator *}
huffman@16060
   176
wenzelm@25131
   177
definition
wenzelm@25131
   178
  sscase :: "('a \<rightarrow> 'c) \<rightarrow> ('b \<rightarrow> 'c) \<rightarrow> ('a ++ 'b) \<rightarrow> 'c" where
huffman@31115
   179
  "sscase = (\<Lambda> f g s. (\<lambda>(t, x, y). If t then f\<cdot>x else g\<cdot>y fi) (Rep_Ssum s))"
huffman@16060
   180
huffman@16060
   181
translations
huffman@26046
   182
  "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
   183
huffman@18078
   184
translations
huffman@26046
   185
  "\<Lambda>(XCONST sinl\<cdot>x). t" == "CONST sscase\<cdot>(\<Lambda> x. t)\<cdot>\<bottom>"
huffman@26046
   186
  "\<Lambda>(XCONST sinr\<cdot>y). t" == "CONST sscase\<cdot>\<bottom>\<cdot>(\<Lambda> y. t)"
huffman@16060
   187
huffman@25740
   188
lemma beta_sscase:
huffman@31115
   189
  "sscase\<cdot>f\<cdot>g\<cdot>s = (\<lambda>(t, x, y). If t then f\<cdot>x else g\<cdot>y fi) (Rep_Ssum s)"
huffman@31115
   190
unfolding sscase_def by (simp add: cont_Rep_Ssum [THEN cont_compose])
huffman@16060
   191
huffman@16060
   192
lemma sscase1 [simp]: "sscase\<cdot>f\<cdot>g\<cdot>\<bottom> = \<bottom>"
huffman@25740
   193
unfolding beta_sscase by (simp add: Rep_Ssum_strict)
huffman@15576
   194
huffman@16060
   195
lemma sscase2 [simp]: "x \<noteq> \<bottom> \<Longrightarrow> sscase\<cdot>f\<cdot>g\<cdot>(sinl\<cdot>x) = f\<cdot>x"
huffman@25740
   196
unfolding beta_sscase by (simp add: Rep_Ssum_sinl)
huffman@15576
   197
huffman@16060
   198
lemma sscase3 [simp]: "y \<noteq> \<bottom> \<Longrightarrow> sscase\<cdot>f\<cdot>g\<cdot>(sinr\<cdot>y) = g\<cdot>y"
huffman@25740
   199
unfolding beta_sscase by (simp add: Rep_Ssum_sinr)
huffman@15593
   200
huffman@16060
   201
lemma sscase4 [simp]: "sscase\<cdot>sinl\<cdot>sinr\<cdot>z = z"
huffman@25756
   202
by (cases z, simp_all)
huffman@15593
   203
huffman@25827
   204
subsection {* Strict sum preserves flatness *}
huffman@25827
   205
huffman@25827
   206
instance "++" :: (flat, flat) flat
huffman@25827
   207
apply (intro_classes, clarify)
huffman@31115
   208
apply (case_tac x, simp)
huffman@31115
   209
apply (case_tac y, simp_all add: flat_below_iff)
huffman@31115
   210
apply (case_tac y, simp_all add: flat_below_iff)
huffman@25827
   211
done
huffman@25827
   212
huffman@25915
   213
subsection {* Strict sum is a bifinite domain *}
huffman@25915
   214
huffman@26962
   215
instantiation "++" :: (bifinite, bifinite) bifinite
huffman@26962
   216
begin
huffman@25915
   217
huffman@26962
   218
definition
huffman@25915
   219
  approx_ssum_def:
huffman@26962
   220
    "approx = (\<lambda>n. sscase\<cdot>(\<Lambda> x. sinl\<cdot>(approx n\<cdot>x))\<cdot>(\<Lambda> y. sinr\<cdot>(approx n\<cdot>y)))"
huffman@25915
   221
huffman@25915
   222
lemma approx_sinl [simp]: "approx i\<cdot>(sinl\<cdot>x) = sinl\<cdot>(approx i\<cdot>x)"
huffman@25915
   223
unfolding approx_ssum_def by (cases "x = \<bottom>") simp_all
huffman@25915
   224
huffman@25915
   225
lemma approx_sinr [simp]: "approx i\<cdot>(sinr\<cdot>x) = sinr\<cdot>(approx i\<cdot>x)"
huffman@25915
   226
unfolding approx_ssum_def by (cases "x = \<bottom>") simp_all
huffman@25915
   227
huffman@26962
   228
instance proof
huffman@25915
   229
  fix i :: nat and x :: "'a \<oplus> 'b"
huffman@27310
   230
  show "chain (approx :: nat \<Rightarrow> 'a \<oplus> 'b \<rightarrow> 'a \<oplus> 'b)"
huffman@25915
   231
    unfolding approx_ssum_def by simp
huffman@25915
   232
  show "(\<Squnion>i. approx i\<cdot>x) = x"
huffman@25915
   233
    unfolding approx_ssum_def
huffman@25915
   234
    by (simp add: lub_distribs eta_cfun)
huffman@25915
   235
  show "approx i\<cdot>(approx i\<cdot>x) = approx i\<cdot>x"
huffman@25915
   236
    by (cases x, simp add: approx_ssum_def, simp, simp)
huffman@25915
   237
  have "{x::'a \<oplus> 'b. approx i\<cdot>x = x} \<subseteq>
huffman@25915
   238
        (\<lambda>x. sinl\<cdot>x) ` {x. approx i\<cdot>x = x} \<union>
huffman@25915
   239
        (\<lambda>x. sinr\<cdot>x) ` {x. approx i\<cdot>x = x}"
huffman@27310
   240
    by (rule subsetI, case_tac x rule: ssumE2, simp, simp)
huffman@25915
   241
  thus "finite {x::'a \<oplus> 'b. approx i\<cdot>x = x}"
huffman@25915
   242
    by (rule finite_subset,
huffman@25915
   243
        intro finite_UnI finite_imageI finite_fixes_approx)
huffman@25915
   244
qed
huffman@25915
   245
huffman@15576
   246
end
huffman@26962
   247
huffman@26962
   248
end