src/HOLCF/Ssum.thy
 author wenzelm Tue Mar 02 23:59:54 2010 +0100 (2010-03-02) changeset 35427 ad039d29e01c parent 33808 31169fdc5ae7 child 35547 991a6af75978 permissions -rw-r--r--
proper (type_)notation;
```     1 (*  Title:      HOLCF/Ssum.thy
```
```     2     Author:     Franz Regensburger and Brian Huffman
```
```     3 *)
```
```     4
```
```     5 header {* The type of strict sums *}
```
```     6
```
```     7 theory Ssum
```
```     8 imports Tr
```
```     9 begin
```
```    10
```
```    11 defaultsort pcpo
```
```    12
```
```    13 subsection {* Definition of strict sum type *}
```
```    14
```
```    15 pcpodef (Ssum)  ('a, 'b) "++" (infixr "++" 10) =
```
```    16   "{p :: tr \<times> ('a \<times> 'b).
```
```    17     (fst p \<sqsubseteq> TT \<longleftrightarrow> snd (snd p) = \<bottom>) \<and>
```
```    18     (fst p \<sqsubseteq> FF \<longleftrightarrow> fst (snd p) = \<bottom>)}"
```
```    19 by simp_all
```
```    20
```
```    21 instance "++" :: ("{finite_po,pcpo}", "{finite_po,pcpo}") finite_po
```
```    22 by (rule typedef_finite_po [OF type_definition_Ssum])
```
```    23
```
```    24 instance "++" :: ("{chfin,pcpo}", "{chfin,pcpo}") chfin
```
```    25 by (rule typedef_chfin [OF type_definition_Ssum below_Ssum_def])
```
```    26
```
```    27 type_notation (xsymbols)
```
```    28   "++"  ("(_ \<oplus>/ _)" [21, 20] 20)
```
```    29 type_notation (HTML output)
```
```    30   "++"  ("(_ \<oplus>/ _)" [21, 20] 20)
```
```    31
```
```    32 subsection {* Definitions of constructors *}
```
```    33
```
```    34 definition
```
```    35   sinl :: "'a \<rightarrow> ('a ++ 'b)" where
```
```    36   "sinl = (\<Lambda> a. Abs_Ssum (strictify\<cdot>(\<Lambda> _. TT)\<cdot>a, a, \<bottom>))"
```
```    37
```
```    38 definition
```
```    39   sinr :: "'b \<rightarrow> ('a ++ 'b)" where
```
```    40   "sinr = (\<Lambda> b. Abs_Ssum (strictify\<cdot>(\<Lambda> _. FF)\<cdot>b, \<bottom>, b))"
```
```    41
```
```    42 lemma sinl_Ssum: "(strictify\<cdot>(\<Lambda> _. TT)\<cdot>a, a, \<bottom>) \<in> Ssum"
```
```    43 by (simp add: Ssum_def strictify_conv_if)
```
```    44
```
```    45 lemma sinr_Ssum: "(strictify\<cdot>(\<Lambda> _. FF)\<cdot>b, \<bottom>, b) \<in> Ssum"
```
```    46 by (simp add: Ssum_def strictify_conv_if)
```
```    47
```
```    48 lemma sinl_Abs_Ssum: "sinl\<cdot>a = Abs_Ssum (strictify\<cdot>(\<Lambda> _. TT)\<cdot>a, a, \<bottom>)"
```
```    49 by (unfold sinl_def, simp add: cont_Abs_Ssum sinl_Ssum)
```
```    50
```
```    51 lemma sinr_Abs_Ssum: "sinr\<cdot>b = Abs_Ssum (strictify\<cdot>(\<Lambda> _. FF)\<cdot>b, \<bottom>, b)"
```
```    52 by (unfold sinr_def, simp add: cont_Abs_Ssum sinr_Ssum)
```
```    53
```
```    54 lemma Rep_Ssum_sinl: "Rep_Ssum (sinl\<cdot>a) = (strictify\<cdot>(\<Lambda> _. TT)\<cdot>a, a, \<bottom>)"
```
```    55 by (simp add: sinl_Abs_Ssum Abs_Ssum_inverse sinl_Ssum)
```
```    56
```
```    57 lemma Rep_Ssum_sinr: "Rep_Ssum (sinr\<cdot>b) = (strictify\<cdot>(\<Lambda> _. FF)\<cdot>b, \<bottom>, b)"
```
```    58 by (simp add: sinr_Abs_Ssum Abs_Ssum_inverse sinr_Ssum)
```
```    59
```
```    60 subsection {* Properties of @{term sinl} and @{term sinr} *}
```
```    61
```
```    62 text {* Ordering *}
```
```    63
```
```    64 lemma sinl_below [simp]: "(sinl\<cdot>x \<sqsubseteq> sinl\<cdot>y) = (x \<sqsubseteq> y)"
```
```    65 by (simp add: below_Ssum_def Rep_Ssum_sinl strictify_conv_if)
```
```    66
```
```    67 lemma sinr_below [simp]: "(sinr\<cdot>x \<sqsubseteq> sinr\<cdot>y) = (x \<sqsubseteq> y)"
```
```    68 by (simp add: below_Ssum_def Rep_Ssum_sinr strictify_conv_if)
```
```    69
```
```    70 lemma sinl_below_sinr [simp]: "(sinl\<cdot>x \<sqsubseteq> sinr\<cdot>y) = (x = \<bottom>)"
```
```    71 by (simp add: below_Ssum_def Rep_Ssum_sinl Rep_Ssum_sinr strictify_conv_if)
```
```    72
```
```    73 lemma sinr_below_sinl [simp]: "(sinr\<cdot>x \<sqsubseteq> sinl\<cdot>y) = (x = \<bottom>)"
```
```    74 by (simp add: below_Ssum_def Rep_Ssum_sinl Rep_Ssum_sinr strictify_conv_if)
```
```    75
```
```    76 text {* Equality *}
```
```    77
```
```    78 lemma sinl_eq [simp]: "(sinl\<cdot>x = sinl\<cdot>y) = (x = y)"
```
```    79 by (simp add: po_eq_conv)
```
```    80
```
```    81 lemma sinr_eq [simp]: "(sinr\<cdot>x = sinr\<cdot>y) = (x = y)"
```
```    82 by (simp add: po_eq_conv)
```
```    83
```
```    84 lemma sinl_eq_sinr [simp]: "(sinl\<cdot>x = sinr\<cdot>y) = (x = \<bottom> \<and> y = \<bottom>)"
```
```    85 by (subst po_eq_conv, simp)
```
```    86
```
```    87 lemma sinr_eq_sinl [simp]: "(sinr\<cdot>x = sinl\<cdot>y) = (x = \<bottom> \<and> y = \<bottom>)"
```
```    88 by (subst po_eq_conv, simp)
```
```    89
```
```    90 lemma sinl_inject: "sinl\<cdot>x = sinl\<cdot>y \<Longrightarrow> x = y"
```
```    91 by (rule sinl_eq [THEN iffD1])
```
```    92
```
```    93 lemma sinr_inject: "sinr\<cdot>x = sinr\<cdot>y \<Longrightarrow> x = y"
```
```    94 by (rule sinr_eq [THEN iffD1])
```
```    95
```
```    96 text {* Strictness *}
```
```    97
```
```    98 lemma sinl_strict [simp]: "sinl\<cdot>\<bottom> = \<bottom>"
```
```    99 by (simp add: sinl_Abs_Ssum Abs_Ssum_strict)
```
```   100
```
```   101 lemma sinr_strict [simp]: "sinr\<cdot>\<bottom> = \<bottom>"
```
```   102 by (simp add: sinr_Abs_Ssum Abs_Ssum_strict)
```
```   103
```
```   104 lemma sinl_defined_iff [simp]: "(sinl\<cdot>x = \<bottom>) = (x = \<bottom>)"
```
```   105 by (cut_tac sinl_eq [of "x" "\<bottom>"], simp)
```
```   106
```
```   107 lemma sinr_defined_iff [simp]: "(sinr\<cdot>x = \<bottom>) = (x = \<bottom>)"
```
```   108 by (cut_tac sinr_eq [of "x" "\<bottom>"], simp)
```
```   109
```
```   110 lemma sinl_defined [intro!]: "x \<noteq> \<bottom> \<Longrightarrow> sinl\<cdot>x \<noteq> \<bottom>"
```
```   111 by simp
```
```   112
```
```   113 lemma sinr_defined [intro!]: "x \<noteq> \<bottom> \<Longrightarrow> sinr\<cdot>x \<noteq> \<bottom>"
```
```   114 by simp
```
```   115
```
```   116 text {* Compactness *}
```
```   117
```
```   118 lemma compact_sinl: "compact x \<Longrightarrow> compact (sinl\<cdot>x)"
```
```   119 by (rule compact_Ssum, simp add: Rep_Ssum_sinl strictify_conv_if)
```
```   120
```
```   121 lemma compact_sinr: "compact x \<Longrightarrow> compact (sinr\<cdot>x)"
```
```   122 by (rule compact_Ssum, simp add: Rep_Ssum_sinr strictify_conv_if)
```
```   123
```
```   124 lemma compact_sinlD: "compact (sinl\<cdot>x) \<Longrightarrow> compact x"
```
```   125 unfolding compact_def
```
```   126 by (drule adm_subst [OF cont_Rep_CFun2 [where f=sinl]], simp)
```
```   127
```
```   128 lemma compact_sinrD: "compact (sinr\<cdot>x) \<Longrightarrow> compact x"
```
```   129 unfolding compact_def
```
```   130 by (drule adm_subst [OF cont_Rep_CFun2 [where f=sinr]], simp)
```
```   131
```
```   132 lemma compact_sinl_iff [simp]: "compact (sinl\<cdot>x) = compact x"
```
```   133 by (safe elim!: compact_sinl compact_sinlD)
```
```   134
```
```   135 lemma compact_sinr_iff [simp]: "compact (sinr\<cdot>x) = compact x"
```
```   136 by (safe elim!: compact_sinr compact_sinrD)
```
```   137
```
```   138 subsection {* Case analysis *}
```
```   139
```
```   140 lemma Exh_Ssum:
```
```   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>)"
```
```   142 apply (induct z rule: Abs_Ssum_induct)
```
```   143 apply (case_tac y, rename_tac t a b)
```
```   144 apply (case_tac t rule: trE)
```
```   145 apply (rule disjI1)
```
```   146 apply (simp add: Ssum_def Abs_Ssum_strict)
```
```   147 apply (rule disjI2, rule disjI1, rule_tac x=a in exI)
```
```   148 apply (simp add: sinl_Abs_Ssum Ssum_def)
```
```   149 apply (rule disjI2, rule disjI2, rule_tac x=b in exI)
```
```   150 apply (simp add: sinr_Abs_Ssum Ssum_def)
```
```   151 done
```
```   152
```
```   153 lemma ssumE [cases type: ++]:
```
```   154   "\<lbrakk>p = \<bottom> \<Longrightarrow> Q;
```
```   155    \<And>x. \<lbrakk>p = sinl\<cdot>x; x \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> Q;
```
```   156    \<And>y. \<lbrakk>p = sinr\<cdot>y; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
```
```   157 by (cut_tac z=p in Exh_Ssum, auto)
```
```   158
```
```   159 lemma ssum_induct [induct type: ++]:
```
```   160   "\<lbrakk>P \<bottom>;
```
```   161    \<And>x. x \<noteq> \<bottom> \<Longrightarrow> P (sinl\<cdot>x);
```
```   162    \<And>y. y \<noteq> \<bottom> \<Longrightarrow> P (sinr\<cdot>y)\<rbrakk> \<Longrightarrow> P x"
```
```   163 by (cases x, simp_all)
```
```   164
```
```   165 lemma ssumE2:
```
```   166   "\<lbrakk>\<And>x. p = sinl\<cdot>x \<Longrightarrow> Q; \<And>y. p = sinr\<cdot>y \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
```
```   167 by (cases p, simp only: sinl_strict [symmetric], simp, simp)
```
```   168
```
```   169 lemma below_sinlD: "p \<sqsubseteq> sinl\<cdot>x \<Longrightarrow> \<exists>y. p = sinl\<cdot>y \<and> y \<sqsubseteq> x"
```
```   170 by (cases p, rule_tac x="\<bottom>" in exI, simp_all)
```
```   171
```
```   172 lemma below_sinrD: "p \<sqsubseteq> sinr\<cdot>x \<Longrightarrow> \<exists>y. p = sinr\<cdot>y \<and> y \<sqsubseteq> x"
```
```   173 by (cases p, rule_tac x="\<bottom>" in exI, simp_all)
```
```   174
```
```   175 subsection {* Case analysis combinator *}
```
```   176
```
```   177 definition
```
```   178   sscase :: "('a \<rightarrow> 'c) \<rightarrow> ('b \<rightarrow> 'c) \<rightarrow> ('a ++ 'b) \<rightarrow> 'c" where
```
```   179   "sscase = (\<Lambda> f g s. (\<lambda>(t, x, y). If t then f\<cdot>x else g\<cdot>y fi) (Rep_Ssum s))"
```
```   180
```
```   181 translations
```
```   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"
```
```   183
```
```   184 translations
```
```   185   "\<Lambda>(XCONST sinl\<cdot>x). t" == "CONST sscase\<cdot>(\<Lambda> x. t)\<cdot>\<bottom>"
```
```   186   "\<Lambda>(XCONST sinr\<cdot>y). t" == "CONST sscase\<cdot>\<bottom>\<cdot>(\<Lambda> y. t)"
```
```   187
```
```   188 lemma beta_sscase:
```
```   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)"
```
```   190 unfolding sscase_def by (simp add: cont_Rep_Ssum [THEN cont_compose])
```
```   191
```
```   192 lemma sscase1 [simp]: "sscase\<cdot>f\<cdot>g\<cdot>\<bottom> = \<bottom>"
```
```   193 unfolding beta_sscase by (simp add: Rep_Ssum_strict)
```
```   194
```
```   195 lemma sscase2 [simp]: "x \<noteq> \<bottom> \<Longrightarrow> sscase\<cdot>f\<cdot>g\<cdot>(sinl\<cdot>x) = f\<cdot>x"
```
```   196 unfolding beta_sscase by (simp add: Rep_Ssum_sinl)
```
```   197
```
```   198 lemma sscase3 [simp]: "y \<noteq> \<bottom> \<Longrightarrow> sscase\<cdot>f\<cdot>g\<cdot>(sinr\<cdot>y) = g\<cdot>y"
```
```   199 unfolding beta_sscase by (simp add: Rep_Ssum_sinr)
```
```   200
```
```   201 lemma sscase4 [simp]: "sscase\<cdot>sinl\<cdot>sinr\<cdot>z = z"
```
```   202 by (cases z, simp_all)
```
```   203
```
```   204 subsection {* Strict sum preserves flatness *}
```
```   205
```
```   206 instance "++" :: (flat, flat) flat
```
```   207 apply (intro_classes, clarify)
```
```   208 apply (case_tac x, simp)
```
```   209 apply (case_tac y, simp_all add: flat_below_iff)
```
```   210 apply (case_tac y, simp_all add: flat_below_iff)
```
```   211 done
```
```   212
```
```   213 subsection {* Map function for strict sums *}
```
```   214
```
```   215 definition
```
```   216   ssum_map :: "('a \<rightarrow> 'b) \<rightarrow> ('c \<rightarrow> 'd) \<rightarrow> 'a \<oplus> 'c \<rightarrow> 'b \<oplus> 'd"
```
```   217 where
```
```   218   "ssum_map = (\<Lambda> f g. sscase\<cdot>(sinl oo f)\<cdot>(sinr oo g))"
```
```   219
```
```   220 lemma ssum_map_strict [simp]: "ssum_map\<cdot>f\<cdot>g\<cdot>\<bottom> = \<bottom>"
```
```   221 unfolding ssum_map_def by simp
```
```   222
```
```   223 lemma ssum_map_sinl [simp]: "x \<noteq> \<bottom> \<Longrightarrow> ssum_map\<cdot>f\<cdot>g\<cdot>(sinl\<cdot>x) = sinl\<cdot>(f\<cdot>x)"
```
```   224 unfolding ssum_map_def by simp
```
```   225
```
```   226 lemma ssum_map_sinr [simp]: "x \<noteq> \<bottom> \<Longrightarrow> ssum_map\<cdot>f\<cdot>g\<cdot>(sinr\<cdot>x) = sinr\<cdot>(g\<cdot>x)"
```
```   227 unfolding ssum_map_def by simp
```
```   228
```
```   229 lemma ssum_map_ID: "ssum_map\<cdot>ID\<cdot>ID = ID"
```
```   230 unfolding ssum_map_def by (simp add: expand_cfun_eq eta_cfun)
```
```   231
```
```   232 lemma ssum_map_map:
```
```   233   "\<lbrakk>f1\<cdot>\<bottom> = \<bottom>; g1\<cdot>\<bottom> = \<bottom>\<rbrakk> \<Longrightarrow>
```
```   234     ssum_map\<cdot>f1\<cdot>g1\<cdot>(ssum_map\<cdot>f2\<cdot>g2\<cdot>p) =
```
```   235      ssum_map\<cdot>(\<Lambda> x. f1\<cdot>(f2\<cdot>x))\<cdot>(\<Lambda> x. g1\<cdot>(g2\<cdot>x))\<cdot>p"
```
```   236 apply (induct p, simp)
```
```   237 apply (case_tac "f2\<cdot>x = \<bottom>", simp, simp)
```
```   238 apply (case_tac "g2\<cdot>y = \<bottom>", simp, simp)
```
```   239 done
```
```   240
```
```   241 lemma ep_pair_ssum_map:
```
```   242   assumes "ep_pair e1 p1" and "ep_pair e2 p2"
```
```   243   shows "ep_pair (ssum_map\<cdot>e1\<cdot>e2) (ssum_map\<cdot>p1\<cdot>p2)"
```
```   244 proof
```
```   245   interpret e1p1: pcpo_ep_pair e1 p1 unfolding pcpo_ep_pair_def by fact
```
```   246   interpret e2p2: pcpo_ep_pair e2 p2 unfolding pcpo_ep_pair_def by fact
```
```   247   fix x show "ssum_map\<cdot>p1\<cdot>p2\<cdot>(ssum_map\<cdot>e1\<cdot>e2\<cdot>x) = x"
```
```   248     by (induct x) simp_all
```
```   249   fix y show "ssum_map\<cdot>e1\<cdot>e2\<cdot>(ssum_map\<cdot>p1\<cdot>p2\<cdot>y) \<sqsubseteq> y"
```
```   250     apply (induct y, simp)
```
```   251     apply (case_tac "p1\<cdot>x = \<bottom>", simp, simp add: e1p1.e_p_below)
```
```   252     apply (case_tac "p2\<cdot>y = \<bottom>", simp, simp add: e2p2.e_p_below)
```
```   253     done
```
```   254 qed
```
```   255
```
```   256 lemma deflation_ssum_map:
```
```   257   assumes "deflation d1" and "deflation d2"
```
```   258   shows "deflation (ssum_map\<cdot>d1\<cdot>d2)"
```
```   259 proof
```
```   260   interpret d1: deflation d1 by fact
```
```   261   interpret d2: deflation d2 by fact
```
```   262   fix x
```
```   263   show "ssum_map\<cdot>d1\<cdot>d2\<cdot>(ssum_map\<cdot>d1\<cdot>d2\<cdot>x) = ssum_map\<cdot>d1\<cdot>d2\<cdot>x"
```
```   264     apply (induct x, simp)
```
```   265     apply (case_tac "d1\<cdot>x = \<bottom>", simp, simp add: d1.idem)
```
```   266     apply (case_tac "d2\<cdot>y = \<bottom>", simp, simp add: d2.idem)
```
```   267     done
```
```   268   show "ssum_map\<cdot>d1\<cdot>d2\<cdot>x \<sqsubseteq> x"
```
```   269     apply (induct x, simp)
```
```   270     apply (case_tac "d1\<cdot>x = \<bottom>", simp, simp add: d1.below)
```
```   271     apply (case_tac "d2\<cdot>y = \<bottom>", simp, simp add: d2.below)
```
```   272     done
```
```   273 qed
```
```   274
```
```   275 lemma finite_deflation_ssum_map:
```
```   276   assumes "finite_deflation d1" and "finite_deflation d2"
```
```   277   shows "finite_deflation (ssum_map\<cdot>d1\<cdot>d2)"
```
```   278 proof (intro finite_deflation.intro finite_deflation_axioms.intro)
```
```   279   interpret d1: finite_deflation d1 by fact
```
```   280   interpret d2: finite_deflation d2 by fact
```
```   281   have "deflation d1" and "deflation d2" by fact+
```
```   282   thus "deflation (ssum_map\<cdot>d1\<cdot>d2)" by (rule deflation_ssum_map)
```
```   283   have "{x. ssum_map\<cdot>d1\<cdot>d2\<cdot>x = x} \<subseteq>
```
```   284         (\<lambda>x. sinl\<cdot>x) ` {x. d1\<cdot>x = x} \<union>
```
```   285         (\<lambda>x. sinr\<cdot>x) ` {x. d2\<cdot>x = x} \<union> {\<bottom>}"
```
```   286     by (rule subsetI, case_tac x, simp_all)
```
```   287   thus "finite {x. ssum_map\<cdot>d1\<cdot>d2\<cdot>x = x}"
```
```   288     by (rule finite_subset, simp add: d1.finite_fixes d2.finite_fixes)
```
```   289 qed
```
```   290
```
```   291 subsection {* Strict sum is a bifinite domain *}
```
```   292
```
```   293 instantiation "++" :: (bifinite, bifinite) bifinite
```
```   294 begin
```
```   295
```
```   296 definition
```
```   297   approx_ssum_def:
```
```   298     "approx = (\<lambda>n. ssum_map\<cdot>(approx n)\<cdot>(approx n))"
```
```   299
```
```   300 lemma approx_sinl [simp]: "approx i\<cdot>(sinl\<cdot>x) = sinl\<cdot>(approx i\<cdot>x)"
```
```   301 unfolding approx_ssum_def by (cases "x = \<bottom>") simp_all
```
```   302
```
```   303 lemma approx_sinr [simp]: "approx i\<cdot>(sinr\<cdot>x) = sinr\<cdot>(approx i\<cdot>x)"
```
```   304 unfolding approx_ssum_def by (cases "x = \<bottom>") simp_all
```
```   305
```
```   306 instance proof
```
```   307   fix i :: nat and x :: "'a \<oplus> 'b"
```
```   308   show "chain (approx :: nat \<Rightarrow> 'a \<oplus> 'b \<rightarrow> 'a \<oplus> 'b)"
```
```   309     unfolding approx_ssum_def by simp
```
```   310   show "(\<Squnion>i. approx i\<cdot>x) = x"
```
```   311     unfolding approx_ssum_def
```
```   312     by (cases x, simp_all add: lub_distribs)
```
```   313   show "approx i\<cdot>(approx i\<cdot>x) = approx i\<cdot>x"
```
```   314     by (cases x, simp add: approx_ssum_def, simp, simp)
```
```   315   show "finite {x::'a \<oplus> 'b. approx i\<cdot>x = x}"
```
```   316     unfolding approx_ssum_def
```
```   317     by (intro finite_deflation.finite_fixes
```
```   318               finite_deflation_ssum_map
```
```   319               finite_deflation_approx)
```
```   320 qed
```
```   321
```
```   322 end
```
```   323
```
```   324 end
```