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
     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 Cprod 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     (cfst\<cdot>p \<sqsubseteq> TT \<longleftrightarrow> csnd\<cdot>(csnd\<cdot>p) = \<bottom>) \<and>
    18     (cfst\<cdot>p \<sqsubseteq> FF \<longleftrightarrow> cfst\<cdot>(csnd\<cdot>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 syntax (xsymbols)
    28   "++"		:: "[type, type] => type"	("(_ \<oplus>/ _)" [21, 20] 20)
    29 syntax (HTML output)
    30   "++"		:: "[type, type] => type"	("(_ \<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 (rule_tac x=z in Abs_Ssum_induct)
   143 apply (rule_tac p=y in cprodE, rename_tac t x)
   144 apply (rule_tac p=x in cprodE, rename_tac a b)
   145 apply (rule_tac p=t in trE)
   146 apply (rule disjI1)
   147 apply (simp add: Ssum_def cpair_strict Abs_Ssum_strict)
   148 apply (rule disjI2, rule disjI1, rule_tac x=a in exI)
   149 apply (simp add: sinl_Abs_Ssum Ssum_def)
   150 apply (rule disjI2, rule disjI2, rule_tac x=b in exI)
   151 apply (simp add: sinr_Abs_Ssum Ssum_def)
   152 done
   153 
   154 lemma ssumE [cases type: ++]:
   155   "\<lbrakk>p = \<bottom> \<Longrightarrow> Q;
   156    \<And>x. \<lbrakk>p = sinl\<cdot>x; x \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> Q;
   157    \<And>y. \<lbrakk>p = sinr\<cdot>y; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
   158 by (cut_tac z=p in Exh_Ssum, auto)
   159 
   160 lemma ssum_induct [induct type: ++]:
   161   "\<lbrakk>P \<bottom>;
   162    \<And>x. x \<noteq> \<bottom> \<Longrightarrow> P (sinl\<cdot>x);
   163    \<And>y. y \<noteq> \<bottom> \<Longrightarrow> P (sinr\<cdot>y)\<rbrakk> \<Longrightarrow> P x"
   164 by (cases x, simp_all)
   165 
   166 lemma ssumE2:
   167   "\<lbrakk>\<And>x. p = sinl\<cdot>x \<Longrightarrow> Q; \<And>y. p = sinr\<cdot>y \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
   168 by (cases p, simp only: sinl_strict [symmetric], simp, simp)
   169 
   170 lemma below_sinlD: "p \<sqsubseteq> sinl\<cdot>x \<Longrightarrow> \<exists>y. p = sinl\<cdot>y \<and> y \<sqsubseteq> x"
   171 by (cases p, rule_tac x="\<bottom>" in exI, simp_all)
   172 
   173 lemma below_sinrD: "p \<sqsubseteq> sinr\<cdot>x \<Longrightarrow> \<exists>y. p = sinr\<cdot>y \<and> y \<sqsubseteq> x"
   174 by (cases p, rule_tac x="\<bottom>" in exI, simp_all)
   175 
   176 subsection {* Case analysis combinator *}
   177 
   178 definition
   179   sscase :: "('a \<rightarrow> 'c) \<rightarrow> ('b \<rightarrow> 'c) \<rightarrow> ('a ++ 'b) \<rightarrow> 'c" where
   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))"
   181 
   182 translations
   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"
   184 
   185 translations
   186   "\<Lambda>(XCONST sinl\<cdot>x). t" == "CONST sscase\<cdot>(\<Lambda> x. t)\<cdot>\<bottom>"
   187   "\<Lambda>(XCONST sinr\<cdot>y). t" == "CONST sscase\<cdot>\<bottom>\<cdot>(\<Lambda> y. t)"
   188 
   189 lemma beta_sscase:
   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)"
   191 unfolding sscase_def by (simp add: cont_Rep_Ssum cont2cont_LAM)
   192 
   193 lemma sscase1 [simp]: "sscase\<cdot>f\<cdot>g\<cdot>\<bottom> = \<bottom>"
   194 unfolding beta_sscase by (simp add: Rep_Ssum_strict)
   195 
   196 lemma sscase2 [simp]: "x \<noteq> \<bottom> \<Longrightarrow> sscase\<cdot>f\<cdot>g\<cdot>(sinl\<cdot>x) = f\<cdot>x"
   197 unfolding beta_sscase by (simp add: Rep_Ssum_sinl)
   198 
   199 lemma sscase3 [simp]: "y \<noteq> \<bottom> \<Longrightarrow> sscase\<cdot>f\<cdot>g\<cdot>(sinr\<cdot>y) = g\<cdot>y"
   200 unfolding beta_sscase by (simp add: Rep_Ssum_sinr)
   201 
   202 lemma sscase4 [simp]: "sscase\<cdot>sinl\<cdot>sinr\<cdot>z = z"
   203 by (cases z, simp_all)
   204 
   205 subsection {* Strict sum preserves flatness *}
   206 
   207 instance "++" :: (flat, flat) flat
   208 apply (intro_classes, clarify)
   209 apply (rule_tac p=x in ssumE, simp)
   210 apply (rule_tac p=y in ssumE, simp_all add: flat_below_iff)
   211 apply (rule_tac p=y in ssumE, simp_all add: flat_below_iff)
   212 done
   213 
   214 subsection {* Strict sum is a bifinite domain *}
   215 
   216 instantiation "++" :: (bifinite, bifinite) bifinite
   217 begin
   218 
   219 definition
   220   approx_ssum_def:
   221     "approx = (\<lambda>n. sscase\<cdot>(\<Lambda> x. sinl\<cdot>(approx n\<cdot>x))\<cdot>(\<Lambda> y. sinr\<cdot>(approx n\<cdot>y)))"
   222 
   223 lemma approx_sinl [simp]: "approx i\<cdot>(sinl\<cdot>x) = sinl\<cdot>(approx i\<cdot>x)"
   224 unfolding approx_ssum_def by (cases "x = \<bottom>") simp_all
   225 
   226 lemma approx_sinr [simp]: "approx i\<cdot>(sinr\<cdot>x) = sinr\<cdot>(approx i\<cdot>x)"
   227 unfolding approx_ssum_def by (cases "x = \<bottom>") simp_all
   228 
   229 instance proof
   230   fix i :: nat and x :: "'a \<oplus> 'b"
   231   show "chain (approx :: nat \<Rightarrow> 'a \<oplus> 'b \<rightarrow> 'a \<oplus> 'b)"
   232     unfolding approx_ssum_def by simp
   233   show "(\<Squnion>i. approx i\<cdot>x) = x"
   234     unfolding approx_ssum_def
   235     by (simp add: lub_distribs eta_cfun)
   236   show "approx i\<cdot>(approx i\<cdot>x) = approx i\<cdot>x"
   237     by (cases x, simp add: approx_ssum_def, simp, simp)
   238   have "{x::'a \<oplus> 'b. approx i\<cdot>x = x} \<subseteq>
   239         (\<lambda>x. sinl\<cdot>x) ` {x. approx i\<cdot>x = x} \<union>
   240         (\<lambda>x. sinr\<cdot>x) ` {x. approx i\<cdot>x = x}"
   241     by (rule subsetI, case_tac x rule: ssumE2, simp, simp)
   242   thus "finite {x::'a \<oplus> 'b. approx i\<cdot>x = x}"
   243     by (rule finite_subset,
   244         intro finite_UnI finite_imageI finite_fixes_approx)
   245 qed
   246 
   247 end
   248 
   249 end