src/HOLCF/Sprod.thy
author wenzelm
Thu Dec 11 16:50:18 2008 +0100 (2008-12-11)
changeset 29063 7619f0561cd7
parent 27310 d0229bc6c461
child 29138 661a8db7e647
permissions -rw-r--r--
pcpodef package: state two goals, instead of encoded conjunction;
     1 (*  Title:      HOLCF/Sprod.thy
     2     ID:         $Id$
     3     Author:     Franz Regensburger and Brian Huffman
     4 
     5 Strict product with typedef.
     6 *)
     7 
     8 header {* The type of strict products *}
     9 
    10 theory Sprod
    11 imports Cprod
    12 begin
    13 
    14 defaultsort pcpo
    15 
    16 subsection {* Definition of strict product type *}
    17 
    18 pcpodef (Sprod)  ('a, 'b) "**" (infixr "**" 20) =
    19         "{p::'a \<times> 'b. p = \<bottom> \<or> (cfst\<cdot>p \<noteq> \<bottom> \<and> csnd\<cdot>p \<noteq> \<bottom>)}"
    20 by simp_all
    21 
    22 instance "**" :: ("{finite_po,pcpo}", "{finite_po,pcpo}") finite_po
    23 by (rule typedef_finite_po [OF type_definition_Sprod])
    24 
    25 instance "**" :: ("{chfin,pcpo}", "{chfin,pcpo}") chfin
    26 by (rule typedef_chfin [OF type_definition_Sprod less_Sprod_def])
    27 
    28 syntax (xsymbols)
    29   "**"		:: "[type, type] => type"	 ("(_ \<otimes>/ _)" [21,20] 20)
    30 syntax (HTML output)
    31   "**"		:: "[type, type] => type"	 ("(_ \<otimes>/ _)" [21,20] 20)
    32 
    33 lemma spair_lemma:
    34   "<strictify\<cdot>(\<Lambda> b. a)\<cdot>b, strictify\<cdot>(\<Lambda> a. b)\<cdot>a> \<in> Sprod"
    35 by (simp add: Sprod_def strictify_conv_if)
    36 
    37 subsection {* Definitions of constants *}
    38 
    39 definition
    40   sfst :: "('a ** 'b) \<rightarrow> 'a" where
    41   "sfst = (\<Lambda> p. cfst\<cdot>(Rep_Sprod p))"
    42 
    43 definition
    44   ssnd :: "('a ** 'b) \<rightarrow> 'b" where
    45   "ssnd = (\<Lambda> p. csnd\<cdot>(Rep_Sprod p))"
    46 
    47 definition
    48   spair :: "'a \<rightarrow> 'b \<rightarrow> ('a ** 'b)" where
    49   "spair = (\<Lambda> a b. Abs_Sprod
    50              <strictify\<cdot>(\<Lambda> b. a)\<cdot>b, strictify\<cdot>(\<Lambda> a. b)\<cdot>a>)"
    51 
    52 definition
    53   ssplit :: "('a \<rightarrow> 'b \<rightarrow> 'c) \<rightarrow> ('a ** 'b) \<rightarrow> 'c" where
    54   "ssplit = (\<Lambda> f. strictify\<cdot>(\<Lambda> p. f\<cdot>(sfst\<cdot>p)\<cdot>(ssnd\<cdot>p)))"
    55 
    56 syntax
    57   "@stuple" :: "['a, args] => 'a ** 'b"  ("(1'(:_,/ _:'))")
    58 translations
    59   "(:x, y, z:)" == "(:x, (:y, z:):)"
    60   "(:x, y:)"    == "CONST spair\<cdot>x\<cdot>y"
    61 
    62 translations
    63   "\<Lambda>(CONST spair\<cdot>x\<cdot>y). t" == "CONST ssplit\<cdot>(\<Lambda> x y. t)"
    64 
    65 subsection {* Case analysis *}
    66 
    67 lemma Rep_Sprod_spair:
    68   "Rep_Sprod (:a, b:) = <strictify\<cdot>(\<Lambda> b. a)\<cdot>b, strictify\<cdot>(\<Lambda> a. b)\<cdot>a>"
    69 unfolding spair_def
    70 by (simp add: cont_Abs_Sprod Abs_Sprod_inverse spair_lemma)
    71 
    72 lemmas Rep_Sprod_simps =
    73   Rep_Sprod_inject [symmetric] less_Sprod_def
    74   Rep_Sprod_strict Rep_Sprod_spair
    75 
    76 lemma Exh_Sprod:
    77   "z = \<bottom> \<or> (\<exists>a b. z = (:a, b:) \<and> a \<noteq> \<bottom> \<and> b \<noteq> \<bottom>)"
    78 apply (insert Rep_Sprod [of z])
    79 apply (simp add: Rep_Sprod_simps eq_cprod)
    80 apply (simp add: Sprod_def)
    81 apply (erule disjE, simp)
    82 apply (simp add: strictify_conv_if)
    83 apply fast
    84 done
    85 
    86 lemma sprodE [cases type: **]:
    87   "\<lbrakk>p = \<bottom> \<Longrightarrow> Q; \<And>x y. \<lbrakk>p = (:x, y:); x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
    88 by (cut_tac z=p in Exh_Sprod, auto)
    89 
    90 lemma sprod_induct [induct type: **]:
    91   "\<lbrakk>P \<bottom>; \<And>x y. \<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> P (:x, y:)\<rbrakk> \<Longrightarrow> P x"
    92 by (cases x, simp_all)
    93 
    94 subsection {* Properties of @{term spair} *}
    95 
    96 lemma spair_strict1 [simp]: "(:\<bottom>, y:) = \<bottom>"
    97 by (simp add: Rep_Sprod_simps strictify_conv_if)
    98 
    99 lemma spair_strict2 [simp]: "(:x, \<bottom>:) = \<bottom>"
   100 by (simp add: Rep_Sprod_simps strictify_conv_if)
   101 
   102 lemma spair_strict_iff [simp]: "((:x, y:) = \<bottom>) = (x = \<bottom> \<or> y = \<bottom>)"
   103 by (simp add: Rep_Sprod_simps strictify_conv_if)
   104 
   105 lemma spair_less_iff:
   106   "((:a, b:) \<sqsubseteq> (:c, d:)) = (a = \<bottom> \<or> b = \<bottom> \<or> (a \<sqsubseteq> c \<and> b \<sqsubseteq> d))"
   107 by (simp add: Rep_Sprod_simps strictify_conv_if)
   108 
   109 lemma spair_eq_iff:
   110   "((:a, b:) = (:c, d:)) =
   111     (a = c \<and> b = d \<or> (a = \<bottom> \<or> b = \<bottom>) \<and> (c = \<bottom> \<or> d = \<bottom>))"
   112 by (simp add: Rep_Sprod_simps strictify_conv_if)
   113 
   114 lemma spair_strict: "x = \<bottom> \<or> y = \<bottom> \<Longrightarrow> (:x, y:) = \<bottom>"
   115 by simp
   116 
   117 lemma spair_strict_rev: "(:x, y:) \<noteq> \<bottom> \<Longrightarrow> x \<noteq> \<bottom> \<and> y \<noteq> \<bottom>"
   118 by simp
   119 
   120 lemma spair_defined: "\<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> (:x, y:) \<noteq> \<bottom>"
   121 by simp
   122 
   123 lemma spair_defined_rev: "(:x, y:) = \<bottom> \<Longrightarrow> x = \<bottom> \<or> y = \<bottom>"
   124 by simp
   125 
   126 lemma spair_eq:
   127   "\<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> ((:x, y:) = (:a, b:)) = (x = a \<and> y = b)"
   128 by (simp add: spair_eq_iff)
   129 
   130 lemma spair_inject:
   131   "\<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>; (:x, y:) = (:a, b:)\<rbrakk> \<Longrightarrow> x = a \<and> y = b"
   132 by (rule spair_eq [THEN iffD1])
   133 
   134 lemma inst_sprod_pcpo2: "UU = (:UU,UU:)"
   135 by simp
   136 
   137 subsection {* Properties of @{term sfst} and @{term ssnd} *}
   138 
   139 lemma sfst_strict [simp]: "sfst\<cdot>\<bottom> = \<bottom>"
   140 by (simp add: sfst_def cont_Rep_Sprod Rep_Sprod_strict)
   141 
   142 lemma ssnd_strict [simp]: "ssnd\<cdot>\<bottom> = \<bottom>"
   143 by (simp add: ssnd_def cont_Rep_Sprod Rep_Sprod_strict)
   144 
   145 lemma sfst_spair [simp]: "y \<noteq> \<bottom> \<Longrightarrow> sfst\<cdot>(:x, y:) = x"
   146 by (simp add: sfst_def cont_Rep_Sprod Rep_Sprod_spair)
   147 
   148 lemma ssnd_spair [simp]: "x \<noteq> \<bottom> \<Longrightarrow> ssnd\<cdot>(:x, y:) = y"
   149 by (simp add: ssnd_def cont_Rep_Sprod Rep_Sprod_spair)
   150 
   151 lemma sfst_defined_iff [simp]: "(sfst\<cdot>p = \<bottom>) = (p = \<bottom>)"
   152 by (cases p, simp_all)
   153 
   154 lemma ssnd_defined_iff [simp]: "(ssnd\<cdot>p = \<bottom>) = (p = \<bottom>)"
   155 by (cases p, simp_all)
   156 
   157 lemma sfst_defined: "p \<noteq> \<bottom> \<Longrightarrow> sfst\<cdot>p \<noteq> \<bottom>"
   158 by simp
   159 
   160 lemma ssnd_defined: "p \<noteq> \<bottom> \<Longrightarrow> ssnd\<cdot>p \<noteq> \<bottom>"
   161 by simp
   162 
   163 lemma surjective_pairing_Sprod2: "(:sfst\<cdot>p, ssnd\<cdot>p:) = p"
   164 by (cases p, simp_all)
   165 
   166 lemma less_sprod: "x \<sqsubseteq> y = (sfst\<cdot>x \<sqsubseteq> sfst\<cdot>y \<and> ssnd\<cdot>x \<sqsubseteq> ssnd\<cdot>y)"
   167 apply (simp add: less_Sprod_def sfst_def ssnd_def cont_Rep_Sprod)
   168 apply (rule less_cprod)
   169 done
   170 
   171 lemma eq_sprod: "(x = y) = (sfst\<cdot>x = sfst\<cdot>y \<and> ssnd\<cdot>x = ssnd\<cdot>y)"
   172 by (auto simp add: po_eq_conv less_sprod)
   173 
   174 lemma spair_less:
   175   "\<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> (:x, y:) \<sqsubseteq> (:a, b:) = (x \<sqsubseteq> a \<and> y \<sqsubseteq> b)"
   176 apply (cases "a = \<bottom>", simp)
   177 apply (cases "b = \<bottom>", simp)
   178 apply (simp add: less_sprod)
   179 done
   180 
   181 lemma sfst_less_iff: "sfst\<cdot>x \<sqsubseteq> y = x \<sqsubseteq> (:y, ssnd\<cdot>x:)"
   182 apply (cases "x = \<bottom>", simp, cases "y = \<bottom>", simp)
   183 apply (simp add: less_sprod)
   184 done
   185 
   186 lemma ssnd_less_iff: "ssnd\<cdot>x \<sqsubseteq> y = x \<sqsubseteq> (:sfst\<cdot>x, y:)"
   187 apply (cases "x = \<bottom>", simp, cases "y = \<bottom>", simp)
   188 apply (simp add: less_sprod)
   189 done
   190 
   191 subsection {* Compactness *}
   192 
   193 lemma compact_sfst: "compact x \<Longrightarrow> compact (sfst\<cdot>x)"
   194 by (rule compactI, simp add: sfst_less_iff)
   195 
   196 lemma compact_ssnd: "compact x \<Longrightarrow> compact (ssnd\<cdot>x)"
   197 by (rule compactI, simp add: ssnd_less_iff)
   198 
   199 lemma compact_spair: "\<lbrakk>compact x; compact y\<rbrakk> \<Longrightarrow> compact (:x, y:)"
   200 by (rule compact_Sprod, simp add: Rep_Sprod_spair strictify_conv_if)
   201 
   202 lemma compact_spair_iff:
   203   "compact (:x, y:) = (x = \<bottom> \<or> y = \<bottom> \<or> (compact x \<and> compact y))"
   204 apply (safe elim!: compact_spair)
   205 apply (drule compact_sfst, simp)
   206 apply (drule compact_ssnd, simp)
   207 apply simp
   208 apply simp
   209 done
   210 
   211 subsection {* Properties of @{term ssplit} *}
   212 
   213 lemma ssplit1 [simp]: "ssplit\<cdot>f\<cdot>\<bottom> = \<bottom>"
   214 by (simp add: ssplit_def)
   215 
   216 lemma ssplit2 [simp]: "\<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> ssplit\<cdot>f\<cdot>(:x, y:) = f\<cdot>x\<cdot>y"
   217 by (simp add: ssplit_def)
   218 
   219 lemma ssplit3 [simp]: "ssplit\<cdot>spair\<cdot>z = z"
   220 by (cases z, simp_all)
   221 
   222 subsection {* Strict product preserves flatness *}
   223 
   224 instance "**" :: (flat, flat) flat
   225 proof
   226   fix x y :: "'a \<otimes> 'b"
   227   assume "x \<sqsubseteq> y" thus "x = \<bottom> \<or> x = y"
   228     apply (induct x, simp)
   229     apply (induct y, simp)
   230     apply (simp add: spair_less_iff flat_less_iff)
   231     done
   232 qed
   233 
   234 subsection {* Strict product is a bifinite domain *}
   235 
   236 instantiation "**" :: (bifinite, bifinite) bifinite
   237 begin
   238 
   239 definition
   240   approx_sprod_def:
   241     "approx = (\<lambda>n. \<Lambda>(:x, y:). (:approx n\<cdot>x, approx n\<cdot>y:))"
   242 
   243 instance proof
   244   fix i :: nat and x :: "'a \<otimes> 'b"
   245   show "chain (approx :: nat \<Rightarrow> 'a \<otimes> 'b \<rightarrow> 'a \<otimes> 'b)"
   246     unfolding approx_sprod_def by simp
   247   show "(\<Squnion>i. approx i\<cdot>x) = x"
   248     unfolding approx_sprod_def
   249     by (simp add: lub_distribs eta_cfun)
   250   show "approx i\<cdot>(approx i\<cdot>x) = approx i\<cdot>x"
   251     unfolding approx_sprod_def
   252     by (simp add: ssplit_def strictify_conv_if)
   253   have "Rep_Sprod ` {x::'a \<otimes> 'b. approx i\<cdot>x = x} \<subseteq> {x. approx i\<cdot>x = x}"
   254     unfolding approx_sprod_def
   255     apply (clarify, case_tac x)
   256      apply (simp add: Rep_Sprod_strict)
   257     apply (simp add: Rep_Sprod_spair spair_eq_iff)
   258     done
   259   hence "finite (Rep_Sprod ` {x::'a \<otimes> 'b. approx i\<cdot>x = x})"
   260     using finite_fixes_approx by (rule finite_subset)
   261   thus "finite {x::'a \<otimes> 'b. approx i\<cdot>x = x}"
   262     by (rule finite_imageD, simp add: inj_on_def Rep_Sprod_inject)
   263 qed
   264 
   265 end
   266 
   267 lemma approx_spair [simp]:
   268   "approx i\<cdot>(:x, y:) = (:approx i\<cdot>x, approx i\<cdot>y:)"
   269 unfolding approx_sprod_def
   270 by (simp add: ssplit_def strictify_conv_if)
   271 
   272 end