src/HOLCF/Sprod.thy
author huffman
Tue Mar 02 17:21:10 2010 -0800 (2010-03-02)
changeset 35525 fa231b86cb1e
parent 35491 92e0028a46f2
child 35547 991a6af75978
permissions -rw-r--r--
proper names for types cfun, sprod, ssum
     1 (*  Title:      HOLCF/Sprod.thy
     2     Author:     Franz Regensburger and Brian Huffman
     3 *)
     4 
     5 header {* The type of strict products *}
     6 
     7 theory Sprod
     8 imports Bifinite
     9 begin
    10 
    11 defaultsort pcpo
    12 
    13 subsection {* Definition of strict product type *}
    14 
    15 pcpodef (Sprod)  ('a, 'b) sprod (infixr "**" 20) =
    16         "{p::'a \<times> 'b. p = \<bottom> \<or> (fst p \<noteq> \<bottom> \<and> snd p \<noteq> \<bottom>)}"
    17 by simp_all
    18 
    19 instance sprod :: ("{finite_po,pcpo}", "{finite_po,pcpo}") finite_po
    20 by (rule typedef_finite_po [OF type_definition_Sprod])
    21 
    22 instance sprod :: ("{chfin,pcpo}", "{chfin,pcpo}") chfin
    23 by (rule typedef_chfin [OF type_definition_Sprod below_Sprod_def])
    24 
    25 syntax (xsymbols)
    26   sprod          :: "[type, type] => type"        ("(_ \<otimes>/ _)" [21,20] 20)
    27 syntax (HTML output)
    28   sprod          :: "[type, type] => type"        ("(_ \<otimes>/ _)" [21,20] 20)
    29 
    30 lemma spair_lemma:
    31   "(strictify\<cdot>(\<Lambda> b. a)\<cdot>b, strictify\<cdot>(\<Lambda> a. b)\<cdot>a) \<in> Sprod"
    32 by (simp add: Sprod_def strictify_conv_if)
    33 
    34 subsection {* Definitions of constants *}
    35 
    36 definition
    37   sfst :: "('a ** 'b) \<rightarrow> 'a" where
    38   "sfst = (\<Lambda> p. fst (Rep_Sprod p))"
    39 
    40 definition
    41   ssnd :: "('a ** 'b) \<rightarrow> 'b" where
    42   "ssnd = (\<Lambda> p. snd (Rep_Sprod p))"
    43 
    44 definition
    45   spair :: "'a \<rightarrow> 'b \<rightarrow> ('a ** 'b)" where
    46   "spair = (\<Lambda> a b. Abs_Sprod
    47              (strictify\<cdot>(\<Lambda> b. a)\<cdot>b, strictify\<cdot>(\<Lambda> a. b)\<cdot>a))"
    48 
    49 definition
    50   ssplit :: "('a \<rightarrow> 'b \<rightarrow> 'c) \<rightarrow> ('a ** 'b) \<rightarrow> 'c" where
    51   "ssplit = (\<Lambda> f. strictify\<cdot>(\<Lambda> p. f\<cdot>(sfst\<cdot>p)\<cdot>(ssnd\<cdot>p)))"
    52 
    53 syntax
    54   "_stuple" :: "['a, args] => 'a ** 'b"  ("(1'(:_,/ _:'))")
    55 translations
    56   "(:x, y, z:)" == "(:x, (:y, z:):)"
    57   "(:x, y:)"    == "CONST spair\<cdot>x\<cdot>y"
    58 
    59 translations
    60   "\<Lambda>(CONST spair\<cdot>x\<cdot>y). t" == "CONST ssplit\<cdot>(\<Lambda> x y. t)"
    61 
    62 subsection {* Case analysis *}
    63 
    64 lemma Rep_Sprod_spair:
    65   "Rep_Sprod (:a, b:) = (strictify\<cdot>(\<Lambda> b. a)\<cdot>b, strictify\<cdot>(\<Lambda> a. b)\<cdot>a)"
    66 unfolding spair_def
    67 by (simp add: cont_Abs_Sprod Abs_Sprod_inverse spair_lemma)
    68 
    69 lemmas Rep_Sprod_simps =
    70   Rep_Sprod_inject [symmetric] below_Sprod_def
    71   Rep_Sprod_strict Rep_Sprod_spair
    72 
    73 lemma Exh_Sprod:
    74   "z = \<bottom> \<or> (\<exists>a b. z = (:a, b:) \<and> a \<noteq> \<bottom> \<and> b \<noteq> \<bottom>)"
    75 apply (insert Rep_Sprod [of z])
    76 apply (simp add: Rep_Sprod_simps Pair_fst_snd_eq)
    77 apply (simp add: Sprod_def)
    78 apply (erule disjE, simp)
    79 apply (simp add: strictify_conv_if)
    80 apply fast
    81 done
    82 
    83 lemma sprodE [cases type: sprod]:
    84   "\<lbrakk>p = \<bottom> \<Longrightarrow> Q; \<And>x y. \<lbrakk>p = (:x, y:); x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
    85 by (cut_tac z=p in Exh_Sprod, auto)
    86 
    87 lemma sprod_induct [induct type: sprod]:
    88   "\<lbrakk>P \<bottom>; \<And>x y. \<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> P (:x, y:)\<rbrakk> \<Longrightarrow> P x"
    89 by (cases x, simp_all)
    90 
    91 subsection {* Properties of @{term spair} *}
    92 
    93 lemma spair_strict1 [simp]: "(:\<bottom>, y:) = \<bottom>"
    94 by (simp add: Rep_Sprod_simps strictify_conv_if)
    95 
    96 lemma spair_strict2 [simp]: "(:x, \<bottom>:) = \<bottom>"
    97 by (simp add: Rep_Sprod_simps strictify_conv_if)
    98 
    99 lemma spair_strict_iff [simp]: "((:x, y:) = \<bottom>) = (x = \<bottom> \<or> y = \<bottom>)"
   100 by (simp add: Rep_Sprod_simps strictify_conv_if)
   101 
   102 lemma spair_below_iff:
   103   "((:a, b:) \<sqsubseteq> (:c, d:)) = (a = \<bottom> \<or> b = \<bottom> \<or> (a \<sqsubseteq> c \<and> b \<sqsubseteq> d))"
   104 by (simp add: Rep_Sprod_simps strictify_conv_if)
   105 
   106 lemma spair_eq_iff:
   107   "((:a, b:) = (:c, d:)) =
   108     (a = c \<and> b = d \<or> (a = \<bottom> \<or> b = \<bottom>) \<and> (c = \<bottom> \<or> d = \<bottom>))"
   109 by (simp add: Rep_Sprod_simps strictify_conv_if)
   110 
   111 lemma spair_strict: "x = \<bottom> \<or> y = \<bottom> \<Longrightarrow> (:x, y:) = \<bottom>"
   112 by simp
   113 
   114 lemma spair_strict_rev: "(:x, y:) \<noteq> \<bottom> \<Longrightarrow> x \<noteq> \<bottom> \<and> y \<noteq> \<bottom>"
   115 by simp
   116 
   117 lemma spair_defined: "\<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> (:x, y:) \<noteq> \<bottom>"
   118 by simp
   119 
   120 lemma spair_defined_rev: "(:x, y:) = \<bottom> \<Longrightarrow> x = \<bottom> \<or> y = \<bottom>"
   121 by simp
   122 
   123 lemma spair_eq:
   124   "\<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> ((:x, y:) = (:a, b:)) = (x = a \<and> y = b)"
   125 by (simp add: spair_eq_iff)
   126 
   127 lemma spair_inject:
   128   "\<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>; (:x, y:) = (:a, b:)\<rbrakk> \<Longrightarrow> x = a \<and> y = b"
   129 by (rule spair_eq [THEN iffD1])
   130 
   131 lemma inst_sprod_pcpo2: "UU = (:UU,UU:)"
   132 by simp
   133 
   134 lemma sprodE2: "(\<And>x y. p = (:x, y:) \<Longrightarrow> Q) \<Longrightarrow> Q"
   135 by (cases p, simp only: inst_sprod_pcpo2, 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 below_sprod: "x \<sqsubseteq> y = (sfst\<cdot>x \<sqsubseteq> sfst\<cdot>y \<and> ssnd\<cdot>x \<sqsubseteq> ssnd\<cdot>y)"
   167 apply (simp add: below_Sprod_def sfst_def ssnd_def cont_Rep_Sprod)
   168 apply (simp only: below_prod_def)
   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 below_sprod)
   173 
   174 lemma spair_below:
   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: below_sprod)
   179 done
   180 
   181 lemma sfst_below_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: below_sprod)
   184 done
   185 
   186 lemma ssnd_below_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: below_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_below_iff)
   195 
   196 lemma compact_ssnd: "compact x \<Longrightarrow> compact (ssnd\<cdot>x)"
   197 by (rule compactI, simp add: ssnd_below_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 sprod :: (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_below_iff flat_below_iff)
   231     done
   232 qed
   233 
   234 subsection {* Map function for strict products *}
   235 
   236 definition
   237   sprod_map :: "('a \<rightarrow> 'b) \<rightarrow> ('c \<rightarrow> 'd) \<rightarrow> 'a \<otimes> 'c \<rightarrow> 'b \<otimes> 'd"
   238 where
   239   "sprod_map = (\<Lambda> f g. ssplit\<cdot>(\<Lambda> x y. (:f\<cdot>x, g\<cdot>y:)))"
   240 
   241 lemma sprod_map_strict [simp]: "sprod_map\<cdot>a\<cdot>b\<cdot>\<bottom> = \<bottom>"
   242 unfolding sprod_map_def by simp
   243 
   244 lemma sprod_map_spair [simp]:
   245   "x \<noteq> \<bottom> \<Longrightarrow> y \<noteq> \<bottom> \<Longrightarrow> sprod_map\<cdot>f\<cdot>g\<cdot>(:x, y:) = (:f\<cdot>x, g\<cdot>y:)"
   246 by (simp add: sprod_map_def)
   247 
   248 lemma sprod_map_spair':
   249   "f\<cdot>\<bottom> = \<bottom> \<Longrightarrow> g\<cdot>\<bottom> = \<bottom> \<Longrightarrow> sprod_map\<cdot>f\<cdot>g\<cdot>(:x, y:) = (:f\<cdot>x, g\<cdot>y:)"
   250 by (cases "x = \<bottom> \<or> y = \<bottom>") auto
   251 
   252 lemma sprod_map_ID: "sprod_map\<cdot>ID\<cdot>ID = ID"
   253 unfolding sprod_map_def by (simp add: expand_cfun_eq eta_cfun)
   254 
   255 lemma sprod_map_map:
   256   "\<lbrakk>f1\<cdot>\<bottom> = \<bottom>; g1\<cdot>\<bottom> = \<bottom>\<rbrakk> \<Longrightarrow>
   257     sprod_map\<cdot>f1\<cdot>g1\<cdot>(sprod_map\<cdot>f2\<cdot>g2\<cdot>p) =
   258      sprod_map\<cdot>(\<Lambda> x. f1\<cdot>(f2\<cdot>x))\<cdot>(\<Lambda> x. g1\<cdot>(g2\<cdot>x))\<cdot>p"
   259 apply (induct p, simp)
   260 apply (case_tac "f2\<cdot>x = \<bottom>", simp)
   261 apply (case_tac "g2\<cdot>y = \<bottom>", simp)
   262 apply simp
   263 done
   264 
   265 lemma ep_pair_sprod_map:
   266   assumes "ep_pair e1 p1" and "ep_pair e2 p2"
   267   shows "ep_pair (sprod_map\<cdot>e1\<cdot>e2) (sprod_map\<cdot>p1\<cdot>p2)"
   268 proof
   269   interpret e1p1: pcpo_ep_pair e1 p1 unfolding pcpo_ep_pair_def by fact
   270   interpret e2p2: pcpo_ep_pair e2 p2 unfolding pcpo_ep_pair_def by fact
   271   fix x show "sprod_map\<cdot>p1\<cdot>p2\<cdot>(sprod_map\<cdot>e1\<cdot>e2\<cdot>x) = x"
   272     by (induct x) simp_all
   273   fix y show "sprod_map\<cdot>e1\<cdot>e2\<cdot>(sprod_map\<cdot>p1\<cdot>p2\<cdot>y) \<sqsubseteq> y"
   274     apply (induct y, simp)
   275     apply (case_tac "p1\<cdot>x = \<bottom>", simp, case_tac "p2\<cdot>y = \<bottom>", simp)
   276     apply (simp add: monofun_cfun e1p1.e_p_below e2p2.e_p_below)
   277     done
   278 qed
   279 
   280 lemma deflation_sprod_map:
   281   assumes "deflation d1" and "deflation d2"
   282   shows "deflation (sprod_map\<cdot>d1\<cdot>d2)"
   283 proof
   284   interpret d1: deflation d1 by fact
   285   interpret d2: deflation d2 by fact
   286   fix x
   287   show "sprod_map\<cdot>d1\<cdot>d2\<cdot>(sprod_map\<cdot>d1\<cdot>d2\<cdot>x) = sprod_map\<cdot>d1\<cdot>d2\<cdot>x"
   288     apply (induct x, simp)
   289     apply (case_tac "d1\<cdot>x = \<bottom>", simp, case_tac "d2\<cdot>y = \<bottom>", simp)
   290     apply (simp add: d1.idem d2.idem)
   291     done
   292   show "sprod_map\<cdot>d1\<cdot>d2\<cdot>x \<sqsubseteq> x"
   293     apply (induct x, simp)
   294     apply (simp add: monofun_cfun d1.below d2.below)
   295     done
   296 qed
   297 
   298 lemma finite_deflation_sprod_map:
   299   assumes "finite_deflation d1" and "finite_deflation d2"
   300   shows "finite_deflation (sprod_map\<cdot>d1\<cdot>d2)"
   301 proof (intro finite_deflation.intro finite_deflation_axioms.intro)
   302   interpret d1: finite_deflation d1 by fact
   303   interpret d2: finite_deflation d2 by fact
   304   have "deflation d1" and "deflation d2" by fact+
   305   thus "deflation (sprod_map\<cdot>d1\<cdot>d2)" by (rule deflation_sprod_map)
   306   have "{x. sprod_map\<cdot>d1\<cdot>d2\<cdot>x = x} \<subseteq> insert \<bottom>
   307         ((\<lambda>(x, y). (:x, y:)) ` ({x. d1\<cdot>x = x} \<times> {y. d2\<cdot>y = y}))"
   308     by (rule subsetI, case_tac x, auto simp add: spair_eq_iff)
   309   thus "finite {x. sprod_map\<cdot>d1\<cdot>d2\<cdot>x = x}"
   310     by (rule finite_subset, simp add: d1.finite_fixes d2.finite_fixes)
   311 qed
   312 
   313 subsection {* Strict product is a bifinite domain *}
   314 
   315 instantiation sprod :: (bifinite, bifinite) bifinite
   316 begin
   317 
   318 definition
   319   approx_sprod_def:
   320     "approx = (\<lambda>n. sprod_map\<cdot>(approx n)\<cdot>(approx n))"
   321 
   322 instance proof
   323   fix i :: nat and x :: "'a \<otimes> 'b"
   324   show "chain (approx :: nat \<Rightarrow> 'a \<otimes> 'b \<rightarrow> 'a \<otimes> 'b)"
   325     unfolding approx_sprod_def by simp
   326   show "(\<Squnion>i. approx i\<cdot>x) = x"
   327     unfolding approx_sprod_def sprod_map_def
   328     by (simp add: lub_distribs eta_cfun)
   329   show "approx i\<cdot>(approx i\<cdot>x) = approx i\<cdot>x"
   330     unfolding approx_sprod_def sprod_map_def
   331     by (simp add: ssplit_def strictify_conv_if)
   332   show "finite {x::'a \<otimes> 'b. approx i\<cdot>x = x}"
   333     unfolding approx_sprod_def
   334     by (intro finite_deflation.finite_fixes
   335               finite_deflation_sprod_map
   336               finite_deflation_approx)
   337 qed
   338 
   339 end
   340 
   341 lemma approx_spair [simp]:
   342   "approx i\<cdot>(:x, y:) = (:approx i\<cdot>x, approx i\<cdot>y:)"
   343 unfolding approx_sprod_def sprod_map_def
   344 by (simp add: ssplit_def strictify_conv_if)
   345 
   346 end