src/HOLCF/Ssum.thy
author huffman
Mon May 11 08:28:09 2009 -0700 (2009-05-11)
changeset 31095 b79d140f6d0b
parent 31076 99fe356cbbc2
child 31115 7d6416f0d1e0
permissions -rw-r--r--
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
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@25740
     8
imports Cprod 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@25740
    17
    (cfst\<cdot>p \<sqsubseteq> TT \<longleftrightarrow> csnd\<cdot>(csnd\<cdot>p) = \<bottom>) \<and>
huffman@25740
    18
    (cfst\<cdot>p \<sqsubseteq> FF \<longleftrightarrow> cfst\<cdot>(csnd\<cdot>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@25740
    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@25740
    40
  "sinr = (\<Lambda> b. Abs_Ssum <strictify\<cdot>(\<Lambda> _. FF)\<cdot>b, \<bottom>, b>)"
huffman@25740
    41
huffman@25740
    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@25740
    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@25740
    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@25740
    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@25740
    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@25740
    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@16752
   142
apply (rule_tac x=z in Abs_Ssum_induct)
huffman@25740
   143
apply (rule_tac p=y in cprodE, rename_tac t x)
huffman@25740
   144
apply (rule_tac p=x in cprodE, rename_tac a b)
huffman@25740
   145
apply (rule_tac p=t in trE)
huffman@25740
   146
apply (rule disjI1)
huffman@25740
   147
apply (simp add: Ssum_def cpair_strict Abs_Ssum_strict)
huffman@25740
   148
apply (rule disjI2, rule disjI1, rule_tac x=a in exI)
huffman@25740
   149
apply (simp add: sinl_Abs_Ssum Ssum_def)
huffman@25740
   150
apply (rule disjI2, rule disjI2, rule_tac x=b in exI)
huffman@25740
   151
apply (simp add: sinr_Abs_Ssum Ssum_def)
huffman@15576
   152
done
huffman@15576
   153
huffman@25740
   154
lemma ssumE [cases type: ++]:
huffman@16060
   155
  "\<lbrakk>p = \<bottom> \<Longrightarrow> Q;
huffman@16060
   156
   \<And>x. \<lbrakk>p = sinl\<cdot>x; x \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> Q;
huffman@16060
   157
   \<And>y. \<lbrakk>p = sinr\<cdot>y; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
huffman@16921
   158
by (cut_tac z=p in Exh_Ssum, auto)
huffman@15576
   159
huffman@25756
   160
lemma ssum_induct [induct type: ++]:
huffman@25756
   161
  "\<lbrakk>P \<bottom>;
huffman@25756
   162
   \<And>x. x \<noteq> \<bottom> \<Longrightarrow> P (sinl\<cdot>x);
huffman@25756
   163
   \<And>y. y \<noteq> \<bottom> \<Longrightarrow> P (sinr\<cdot>y)\<rbrakk> \<Longrightarrow> P x"
huffman@25756
   164
by (cases x, simp_all)
huffman@25756
   165
huffman@15576
   166
lemma ssumE2:
huffman@16060
   167
  "\<lbrakk>\<And>x. p = sinl\<cdot>x \<Longrightarrow> Q; \<And>y. p = sinr\<cdot>y \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
huffman@25740
   168
by (cases p, simp only: sinl_strict [symmetric], simp, simp)
huffman@16060
   169
huffman@31076
   170
lemma below_sinlD: "p \<sqsubseteq> sinl\<cdot>x \<Longrightarrow> \<exists>y. p = sinl\<cdot>y \<and> y \<sqsubseteq> x"
huffman@25740
   171
by (cases p, rule_tac x="\<bottom>" in exI, simp_all)
huffman@15576
   172
huffman@31076
   173
lemma below_sinrD: "p \<sqsubseteq> sinr\<cdot>x \<Longrightarrow> \<exists>y. p = sinr\<cdot>y \<and> y \<sqsubseteq> x"
huffman@25740
   174
by (cases p, rule_tac x="\<bottom>" in exI, simp_all)
huffman@16060
   175
huffman@25740
   176
subsection {* Case analysis combinator *}
huffman@16060
   177
wenzelm@25131
   178
definition
wenzelm@25131
   179
  sscase :: "('a \<rightarrow> 'c) \<rightarrow> ('b \<rightarrow> 'c) \<rightarrow> ('a ++ 'b) \<rightarrow> 'c" where
huffman@25740
   180
  "sscase = (\<Lambda> f g s. (\<Lambda><t, x, y>. If t then f\<cdot>x else g\<cdot>y fi)\<cdot>(Rep_Ssum s))"
huffman@16060
   181
huffman@16060
   182
translations
huffman@26046
   183
  "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
   184
huffman@18078
   185
translations
huffman@26046
   186
  "\<Lambda>(XCONST sinl\<cdot>x). t" == "CONST sscase\<cdot>(\<Lambda> x. t)\<cdot>\<bottom>"
huffman@26046
   187
  "\<Lambda>(XCONST sinr\<cdot>y). t" == "CONST sscase\<cdot>\<bottom>\<cdot>(\<Lambda> y. t)"
huffman@16060
   188
huffman@25740
   189
lemma beta_sscase:
huffman@25740
   190
  "sscase\<cdot>f\<cdot>g\<cdot>s = (\<Lambda><t, x, y>. If t then f\<cdot>x else g\<cdot>y fi)\<cdot>(Rep_Ssum s)"
huffman@29530
   191
unfolding sscase_def by (simp add: cont_Rep_Ssum cont2cont_LAM)
huffman@16060
   192
huffman@16060
   193
lemma sscase1 [simp]: "sscase\<cdot>f\<cdot>g\<cdot>\<bottom> = \<bottom>"
huffman@25740
   194
unfolding beta_sscase by (simp add: Rep_Ssum_strict)
huffman@15576
   195
huffman@16060
   196
lemma sscase2 [simp]: "x \<noteq> \<bottom> \<Longrightarrow> sscase\<cdot>f\<cdot>g\<cdot>(sinl\<cdot>x) = f\<cdot>x"
huffman@25740
   197
unfolding beta_sscase by (simp add: Rep_Ssum_sinl)
huffman@15576
   198
huffman@16060
   199
lemma sscase3 [simp]: "y \<noteq> \<bottom> \<Longrightarrow> sscase\<cdot>f\<cdot>g\<cdot>(sinr\<cdot>y) = g\<cdot>y"
huffman@25740
   200
unfolding beta_sscase by (simp add: Rep_Ssum_sinr)
huffman@15593
   201
huffman@16060
   202
lemma sscase4 [simp]: "sscase\<cdot>sinl\<cdot>sinr\<cdot>z = z"
huffman@25756
   203
by (cases z, simp_all)
huffman@15593
   204
huffman@25827
   205
subsection {* Strict sum preserves flatness *}
huffman@25827
   206
huffman@25827
   207
instance "++" :: (flat, flat) flat
huffman@25827
   208
apply (intro_classes, clarify)
huffman@25827
   209
apply (rule_tac p=x in ssumE, simp)
huffman@31076
   210
apply (rule_tac p=y in ssumE, simp_all add: flat_below_iff)
huffman@31076
   211
apply (rule_tac p=y in ssumE, simp_all add: flat_below_iff)
huffman@25827
   212
done
huffman@25827
   213
huffman@25915
   214
subsection {* Strict sum is a bifinite domain *}
huffman@25915
   215
huffman@26962
   216
instantiation "++" :: (bifinite, bifinite) bifinite
huffman@26962
   217
begin
huffman@25915
   218
huffman@26962
   219
definition
huffman@25915
   220
  approx_ssum_def:
huffman@26962
   221
    "approx = (\<lambda>n. sscase\<cdot>(\<Lambda> x. sinl\<cdot>(approx n\<cdot>x))\<cdot>(\<Lambda> y. sinr\<cdot>(approx n\<cdot>y)))"
huffman@25915
   222
huffman@25915
   223
lemma approx_sinl [simp]: "approx i\<cdot>(sinl\<cdot>x) = sinl\<cdot>(approx i\<cdot>x)"
huffman@25915
   224
unfolding approx_ssum_def by (cases "x = \<bottom>") simp_all
huffman@25915
   225
huffman@25915
   226
lemma approx_sinr [simp]: "approx i\<cdot>(sinr\<cdot>x) = sinr\<cdot>(approx i\<cdot>x)"
huffman@25915
   227
unfolding approx_ssum_def by (cases "x = \<bottom>") simp_all
huffman@25915
   228
huffman@26962
   229
instance proof
huffman@25915
   230
  fix i :: nat and x :: "'a \<oplus> 'b"
huffman@27310
   231
  show "chain (approx :: nat \<Rightarrow> 'a \<oplus> 'b \<rightarrow> 'a \<oplus> 'b)"
huffman@25915
   232
    unfolding approx_ssum_def by simp
huffman@25915
   233
  show "(\<Squnion>i. approx i\<cdot>x) = x"
huffman@25915
   234
    unfolding approx_ssum_def
huffman@25915
   235
    by (simp add: lub_distribs eta_cfun)
huffman@25915
   236
  show "approx i\<cdot>(approx i\<cdot>x) = approx i\<cdot>x"
huffman@25915
   237
    by (cases x, simp add: approx_ssum_def, simp, simp)
huffman@25915
   238
  have "{x::'a \<oplus> 'b. approx i\<cdot>x = x} \<subseteq>
huffman@25915
   239
        (\<lambda>x. sinl\<cdot>x) ` {x. approx i\<cdot>x = x} \<union>
huffman@25915
   240
        (\<lambda>x. sinr\<cdot>x) ` {x. approx i\<cdot>x = x}"
huffman@27310
   241
    by (rule subsetI, case_tac x rule: ssumE2, simp, simp)
huffman@25915
   242
  thus "finite {x::'a \<oplus> 'b. approx i\<cdot>x = x}"
huffman@25915
   243
    by (rule finite_subset,
huffman@25915
   244
        intro finite_UnI finite_imageI finite_fixes_approx)
huffman@25915
   245
qed
huffman@25915
   246
huffman@15576
   247
end
huffman@26962
   248
huffman@26962
   249
end