src/HOLCF/Ssum.thy
author haftmann
Tue Jul 10 17:30:50 2007 +0200 (2007-07-10)
changeset 23709 fd31da8f752a
parent 19440 b2877e230b07
child 25131 2c8caac48ade
permissions -rw-r--r--
moved lfp_induct2 here
huffman@15600
     1
(*  Title:      HOLCF/Ssum.thy
huffman@15576
     2
    ID:         $Id$
huffman@16060
     3
    Author:     Franz Regensburger and Brian Huffman
huffman@15576
     4
wenzelm@16070
     5
Strict sum with typedef.
huffman@15576
     6
*)
huffman@15576
     7
huffman@15576
     8
header {* The type of strict sums *}
huffman@15576
     9
huffman@15577
    10
theory Ssum
huffman@16699
    11
imports Cprod
huffman@15577
    12
begin
huffman@15576
    13
huffman@16083
    14
defaultsort pcpo
huffman@16083
    15
huffman@15593
    16
subsection {* Definition of strict sum type *}
huffman@15593
    17
huffman@17817
    18
pcpodef (Ssum)  ('a, 'b) "++" (infixr "++" 10) = 
huffman@16060
    19
        "{p::'a \<times> 'b. cfst\<cdot>p = \<bottom> \<or> csnd\<cdot>p = \<bottom>}"
huffman@16699
    20
by simp
huffman@15576
    21
huffman@15576
    22
syntax (xsymbols)
huffman@15576
    23
  "++"		:: "[type, type] => type"	("(_ \<oplus>/ _)" [21, 20] 20)
huffman@15576
    24
syntax (HTML output)
huffman@15576
    25
  "++"		:: "[type, type] => type"	("(_ \<oplus>/ _)" [21, 20] 20)
huffman@15576
    26
huffman@16060
    27
huffman@16060
    28
subsection {* Definitions of constructors *}
huffman@15576
    29
huffman@16060
    30
constdefs
huffman@16060
    31
  sinl :: "'a \<rightarrow> ('a ++ 'b)"
huffman@16060
    32
  "sinl \<equiv> \<Lambda> a. Abs_Ssum <a, \<bottom>>"
huffman@16060
    33
huffman@16060
    34
  sinr :: "'b \<rightarrow> ('a ++ 'b)"
huffman@16060
    35
  "sinr \<equiv> \<Lambda> b. Abs_Ssum <\<bottom>, b>"
huffman@16060
    36
huffman@16060
    37
subsection {* Properties of @{term sinl} and @{term sinr} *}
huffman@16060
    38
huffman@16060
    39
lemma sinl_Abs_Ssum: "sinl\<cdot>a = Abs_Ssum <a, \<bottom>>"
huffman@16060
    40
by (unfold sinl_def, simp add: cont_Abs_Ssum Ssum_def)
huffman@15576
    41
huffman@16060
    42
lemma sinr_Abs_Ssum: "sinr\<cdot>b = Abs_Ssum <\<bottom>, b>"
huffman@16060
    43
by (unfold sinr_def, simp add: cont_Abs_Ssum Ssum_def)
huffman@16060
    44
huffman@16060
    45
lemma Rep_Ssum_sinl: "Rep_Ssum (sinl\<cdot>a) = <a, \<bottom>>"
huffman@16060
    46
by (unfold sinl_def, simp add: cont_Abs_Ssum Abs_Ssum_inverse Ssum_def)
huffman@16060
    47
huffman@16060
    48
lemma Rep_Ssum_sinr: "Rep_Ssum (sinr\<cdot>b) = <\<bottom>, b>"
huffman@16060
    49
by (unfold sinr_def, simp add: cont_Abs_Ssum Abs_Ssum_inverse Ssum_def)
huffman@15576
    50
huffman@17837
    51
lemma compact_sinl [simp]: "compact x \<Longrightarrow> compact (sinl\<cdot>x)"
huffman@17837
    52
by (rule compact_Ssum, simp add: Rep_Ssum_sinl)
huffman@17837
    53
huffman@17837
    54
lemma compact_sinr [simp]: "compact x \<Longrightarrow> compact (sinr\<cdot>x)"
huffman@17837
    55
by (rule compact_Ssum, simp add: Rep_Ssum_sinr)
huffman@17837
    56
huffman@16211
    57
lemma sinl_strict [simp]: "sinl\<cdot>\<bottom> = \<bottom>"
huffman@16752
    58
by (simp add: sinl_Abs_Ssum Abs_Ssum_strict cpair_strict)
huffman@15576
    59
huffman@16211
    60
lemma sinr_strict [simp]: "sinr\<cdot>\<bottom> = \<bottom>"
huffman@16752
    61
by (simp add: sinr_Abs_Ssum Abs_Ssum_strict cpair_strict)
huffman@16060
    62
huffman@16752
    63
lemma sinl_eq [simp]: "(sinl\<cdot>x = sinl\<cdot>y) = (x = y)"
huffman@16060
    64
by (simp add: sinl_Abs_Ssum Abs_Ssum_inject Ssum_def)
huffman@15576
    65
huffman@16752
    66
lemma sinr_eq [simp]: "(sinr\<cdot>x = sinr\<cdot>y) = (x = y)"
huffman@16060
    67
by (simp add: sinr_Abs_Ssum Abs_Ssum_inject Ssum_def)
huffman@15576
    68
huffman@16752
    69
lemma sinl_inject: "sinl\<cdot>x = sinl\<cdot>y \<Longrightarrow> x = y"
huffman@16752
    70
by (rule sinl_eq [THEN iffD1])
huffman@15576
    71
huffman@16752
    72
lemma sinr_inject: "sinr\<cdot>x = sinr\<cdot>y \<Longrightarrow> x = y"
huffman@16752
    73
by (rule sinr_eq [THEN iffD1])
huffman@15576
    74
huffman@16752
    75
lemma sinl_defined_iff [simp]: "(sinl\<cdot>x = \<bottom>) = (x = \<bottom>)"
huffman@17837
    76
by (cut_tac sinl_eq [of "x" "\<bottom>"], simp)
huffman@15576
    77
huffman@16752
    78
lemma sinr_defined_iff [simp]: "(sinr\<cdot>x = \<bottom>) = (x = \<bottom>)"
huffman@17837
    79
by (cut_tac sinr_eq [of "x" "\<bottom>"], simp)
huffman@15576
    80
huffman@16752
    81
lemma sinl_defined [intro!]: "x \<noteq> \<bottom> \<Longrightarrow> sinl\<cdot>x \<noteq> \<bottom>"
huffman@16752
    82
by simp
huffman@16752
    83
huffman@16752
    84
lemma sinr_defined [intro!]: "x \<noteq> \<bottom> \<Longrightarrow> sinr\<cdot>x \<noteq> \<bottom>"
huffman@16752
    85
by simp
huffman@16752
    86
huffman@16060
    87
subsection {* Case analysis *}
huffman@16060
    88
huffman@16921
    89
lemma Exh_Ssum: 
huffman@16060
    90
  "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
    91
apply (rule_tac x=z in Abs_Ssum_induct)
huffman@16752
    92
apply (rule_tac p=y in cprodE)
huffman@16921
    93
apply (simp add: sinl_Abs_Ssum sinr_Abs_Ssum)
huffman@16921
    94
apply (simp add: Abs_Ssum_inject Ssum_def)
huffman@16921
    95
apply (auto simp add: cpair_strict Abs_Ssum_strict)
huffman@15576
    96
done
huffman@15576
    97
huffman@15576
    98
lemma ssumE:
huffman@16060
    99
  "\<lbrakk>p = \<bottom> \<Longrightarrow> Q;
huffman@16060
   100
   \<And>x. \<lbrakk>p = sinl\<cdot>x; x \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> Q;
huffman@16060
   101
   \<And>y. \<lbrakk>p = sinr\<cdot>y; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
huffman@16921
   102
by (cut_tac z=p in Exh_Ssum, auto)
huffman@15576
   103
huffman@15576
   104
lemma ssumE2:
huffman@16060
   105
  "\<lbrakk>\<And>x. p = sinl\<cdot>x \<Longrightarrow> Q; \<And>y. p = sinr\<cdot>y \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
huffman@16060
   106
apply (rule_tac p=p in ssumE)
huffman@16211
   107
apply (simp only: sinl_strict [symmetric])
huffman@15576
   108
apply simp
huffman@15576
   109
apply simp
huffman@15576
   110
done
huffman@15576
   111
huffman@16060
   112
subsection {* Ordering properties of @{term sinl} and @{term sinr} *}
huffman@15576
   113
huffman@16752
   114
lemma sinl_less [simp]: "(sinl\<cdot>x \<sqsubseteq> sinl\<cdot>y) = (x \<sqsubseteq> y)"
huffman@18078
   115
by (simp add: less_Ssum_def Rep_Ssum_sinl)
huffman@16060
   116
huffman@16752
   117
lemma sinr_less [simp]: "(sinr\<cdot>x \<sqsubseteq> sinr\<cdot>y) = (x \<sqsubseteq> y)"
huffman@18078
   118
by (simp add: less_Ssum_def Rep_Ssum_sinr)
huffman@16060
   119
huffman@16752
   120
lemma sinl_less_sinr [simp]: "(sinl\<cdot>x \<sqsubseteq> sinr\<cdot>y) = (x = \<bottom>)"
huffman@19440
   121
by (simp add: less_Ssum_def Rep_Ssum_sinl Rep_Ssum_sinr)
huffman@16752
   122
huffman@16752
   123
lemma sinr_less_sinl [simp]: "(sinr\<cdot>x \<sqsubseteq> sinl\<cdot>y) = (x = \<bottom>)"
huffman@19440
   124
by (simp add: less_Ssum_def Rep_Ssum_sinl Rep_Ssum_sinr)
huffman@15576
   125
huffman@16752
   126
lemma sinl_eq_sinr [simp]: "(sinl\<cdot>x = sinr\<cdot>y) = (x = \<bottom> \<and> y = \<bottom>)"
huffman@19440
   127
by (subst po_eq_conv, simp)
huffman@16752
   128
huffman@16752
   129
lemma sinr_eq_sinl [simp]: "(sinr\<cdot>x = sinl\<cdot>y) = (x = \<bottom> \<and> y = \<bottom>)"
huffman@19440
   130
by (subst po_eq_conv, simp)
huffman@16060
   131
huffman@16060
   132
subsection {* Chains of strict sums *}
huffman@16060
   133
huffman@16060
   134
lemma less_sinlD: "p \<sqsubseteq> sinl\<cdot>x \<Longrightarrow> \<exists>y. p = sinl\<cdot>y \<and> y \<sqsubseteq> x"
huffman@16060
   135
apply (rule_tac p=p in ssumE)
huffman@16060
   136
apply (rule_tac x="\<bottom>" in exI, simp)
huffman@16752
   137
apply simp
huffman@16752
   138
apply simp
huffman@15576
   139
done
huffman@15576
   140
huffman@16060
   141
lemma less_sinrD: "p \<sqsubseteq> sinr\<cdot>x \<Longrightarrow> \<exists>y. p = sinr\<cdot>y \<and> y \<sqsubseteq> x"
huffman@16060
   142
apply (rule_tac p=p in ssumE)
huffman@16060
   143
apply (rule_tac x="\<bottom>" in exI, simp)
huffman@16752
   144
apply simp
huffman@16752
   145
apply simp
huffman@16060
   146
done
huffman@16060
   147
huffman@16060
   148
lemma ssum_chain_lemma:
huffman@16060
   149
"chain Y \<Longrightarrow> (\<exists>A. chain A \<and> Y = (\<lambda>i. sinl\<cdot>(A i))) \<or>
huffman@16060
   150
             (\<exists>B. chain B \<and> Y = (\<lambda>i. sinr\<cdot>(B i)))"
huffman@16060
   151
 apply (rule_tac p="lub (range Y)" in ssumE2)
huffman@16060
   152
  apply (rule disjI1)
huffman@16060
   153
  apply (rule_tac x="\<lambda>i. cfst\<cdot>(Rep_Ssum (Y i))" in exI)
huffman@16060
   154
  apply (rule conjI)
huffman@16060
   155
   apply (rule chain_monofun)
huffman@16742
   156
   apply (erule cont_Rep_Ssum [THEN ch2ch_cont])
huffman@16060
   157
  apply (rule ext, drule_tac x=i in is_ub_thelub, simp)
huffman@16060
   158
  apply (drule less_sinlD, clarify)
huffman@16752
   159
  apply (simp add: Rep_Ssum_sinl)
huffman@16060
   160
 apply (rule disjI2)
huffman@16060
   161
 apply (rule_tac x="\<lambda>i. csnd\<cdot>(Rep_Ssum (Y i))" in exI)
huffman@16060
   162
 apply (rule conjI)
huffman@16060
   163
  apply (rule chain_monofun)
huffman@16742
   164
  apply (erule cont_Rep_Ssum [THEN ch2ch_cont])
huffman@16060
   165
 apply (rule ext, drule_tac x=i in is_ub_thelub, simp)
huffman@16060
   166
 apply (drule less_sinrD, clarify)
huffman@16752
   167
 apply (simp add: Rep_Ssum_sinr)
huffman@15576
   168
done
huffman@15576
   169
huffman@16060
   170
subsection {* Definitions of constants *}
huffman@16060
   171
huffman@16060
   172
constdefs
huffman@16060
   173
  Iwhen :: "['a \<rightarrow> 'c, 'b \<rightarrow> 'c, 'a ++ 'b] \<Rightarrow> 'c"
huffman@16060
   174
  "Iwhen \<equiv> \<lambda>f g s.
huffman@16060
   175
    if cfst\<cdot>(Rep_Ssum s) \<noteq> \<bottom> then f\<cdot>(cfst\<cdot>(Rep_Ssum s)) else
huffman@16060
   176
    if csnd\<cdot>(Rep_Ssum s) \<noteq> \<bottom> then g\<cdot>(csnd\<cdot>(Rep_Ssum s)) else \<bottom>"
huffman@16060
   177
huffman@16060
   178
text {* rewrites for @{term Iwhen} *}
huffman@16060
   179
huffman@16060
   180
lemma Iwhen1 [simp]: "Iwhen f g \<bottom> = \<bottom>"
huffman@16211
   181
by (simp add: Iwhen_def Rep_Ssum_strict)
huffman@16060
   182
huffman@16060
   183
lemma Iwhen2 [simp]: "x \<noteq> \<bottom> \<Longrightarrow> Iwhen f g (sinl\<cdot>x) = f\<cdot>x"
huffman@16060
   184
by (simp add: Iwhen_def Rep_Ssum_sinl)
huffman@16060
   185
huffman@16060
   186
lemma Iwhen3 [simp]: "y \<noteq> \<bottom> \<Longrightarrow> Iwhen f g (sinr\<cdot>y) = g\<cdot>y"
huffman@16060
   187
by (simp add: Iwhen_def Rep_Ssum_sinr)
huffman@16060
   188
huffman@16060
   189
lemma Iwhen4: "Iwhen f g (sinl\<cdot>x) = strictify\<cdot>f\<cdot>x"
huffman@16211
   190
by (simp add: strictify_conv_if)
huffman@15576
   191
huffman@16060
   192
lemma Iwhen5: "Iwhen f g (sinr\<cdot>y) = strictify\<cdot>g\<cdot>y"
huffman@16211
   193
by (simp add: strictify_conv_if)
huffman@16060
   194
huffman@16060
   195
subsection {* Continuity of @{term Iwhen} *}
huffman@16060
   196
huffman@16060
   197
text {* @{term Iwhen} is continuous in all arguments *}
huffman@16060
   198
huffman@16060
   199
lemma cont_Iwhen1: "cont (\<lambda>f. Iwhen f g s)"
huffman@16060
   200
by (rule_tac p=s in ssumE, simp_all)
huffman@16060
   201
huffman@16060
   202
lemma cont_Iwhen2: "cont (\<lambda>g. Iwhen f g s)"
huffman@16060
   203
by (rule_tac p=s in ssumE, simp_all)
huffman@16060
   204
huffman@16060
   205
lemma cont_Iwhen3: "cont (\<lambda>s. Iwhen f g s)"
huffman@16211
   206
apply (rule contI)
huffman@16060
   207
apply (drule ssum_chain_lemma, safe)
huffman@16060
   208
apply (simp add: contlub_cfun_arg [symmetric])
huffman@16823
   209
apply (simp add: Iwhen4 cont_cfun_arg)
huffman@16060
   210
apply (simp add: contlub_cfun_arg [symmetric])
huffman@16823
   211
apply (simp add: Iwhen5 cont_cfun_arg)
huffman@15576
   212
done
huffman@15576
   213
huffman@16060
   214
subsection {* Continuous versions of constants *}
huffman@16060
   215
huffman@16060
   216
constdefs
huffman@16060
   217
  sscase :: "('a \<rightarrow> 'c) \<rightarrow> ('b \<rightarrow> 'c) \<rightarrow> ('a ++ 'b) \<rightarrow> 'c"
huffman@16060
   218
  "sscase \<equiv> \<Lambda> f g s. Iwhen f g s"
huffman@16060
   219
huffman@16060
   220
translations
huffman@18078
   221
  "case s of sinl\<cdot>x \<Rightarrow> t1 | sinr\<cdot>y \<Rightarrow> t2" == "sscase\<cdot>(\<Lambda> x. t1)\<cdot>(\<Lambda> y. t2)\<cdot>s"
huffman@18078
   222
huffman@18078
   223
translations
huffman@18078
   224
  "\<Lambda>(sinl\<cdot>x). t" == "sscase\<cdot>(\<Lambda> x. t)\<cdot>\<bottom>"
huffman@18078
   225
  "\<Lambda>(sinr\<cdot>y). t" == "sscase\<cdot>\<bottom>\<cdot>(\<Lambda> y. t)"
huffman@16060
   226
huffman@16060
   227
text {* continuous versions of lemmas for @{term sscase} *}
huffman@15576
   228
huffman@16060
   229
lemma beta_sscase: "sscase\<cdot>f\<cdot>g\<cdot>s = Iwhen f g s"
huffman@16060
   230
by (simp add: sscase_def cont_Iwhen1 cont_Iwhen2 cont_Iwhen3)
huffman@16060
   231
huffman@16060
   232
lemma sscase1 [simp]: "sscase\<cdot>f\<cdot>g\<cdot>\<bottom> = \<bottom>"
huffman@16060
   233
by (simp add: beta_sscase)
huffman@15576
   234
huffman@16060
   235
lemma sscase2 [simp]: "x \<noteq> \<bottom> \<Longrightarrow> sscase\<cdot>f\<cdot>g\<cdot>(sinl\<cdot>x) = f\<cdot>x"
huffman@16060
   236
by (simp add: beta_sscase)
huffman@15576
   237
huffman@16060
   238
lemma sscase3 [simp]: "y \<noteq> \<bottom> \<Longrightarrow> sscase\<cdot>f\<cdot>g\<cdot>(sinr\<cdot>y) = g\<cdot>y"
huffman@16060
   239
by (simp add: beta_sscase)
huffman@15593
   240
huffman@16060
   241
lemma sscase4 [simp]: "sscase\<cdot>sinl\<cdot>sinr\<cdot>z = z"
huffman@16060
   242
by (rule_tac p=z in ssumE, simp_all)
huffman@15593
   243
huffman@15576
   244
end