src/HOL/HOLCF/Sprod.thy
author wenzelm
Sat Nov 04 15:24:40 2017 +0100 (20 months ago)
changeset 67003 49850a679c2c
parent 62175 8ffc4d0e652d
child 67312 0d25e02759b7
permissions -rw-r--r--
more robust sorted_entries;
     1 (*  Title:      HOL/HOLCF/Sprod.thy
     2     Author:     Franz Regensburger
     3     Author:     Brian Huffman
     4 *)
     5 
     6 section \<open>The type of strict products\<close>
     7 
     8 theory Sprod
     9 imports Cfun
    10 begin
    11 
    12 default_sort pcpo
    13 
    14 subsection \<open>Definition of strict product type\<close>
    15 
    16 definition "sprod = {p::'a \<times> 'b. p = \<bottom> \<or> (fst p \<noteq> \<bottom> \<and> snd p \<noteq> \<bottom>)}"
    17 
    18 pcpodef ('a, 'b) sprod  ("(_ \<otimes>/ _)" [21,20] 20) = "sprod :: ('a \<times> 'b) set"
    19   unfolding sprod_def by simp_all
    20 
    21 instance sprod :: ("{chfin,pcpo}", "{chfin,pcpo}") chfin
    22 by (rule typedef_chfin [OF type_definition_sprod below_sprod_def])
    23 
    24 type_notation (ASCII)
    25   sprod  (infixr "**" 20)
    26 
    27 
    28 subsection \<open>Definitions of constants\<close>
    29 
    30 definition
    31   sfst :: "('a ** 'b) \<rightarrow> 'a" where
    32   "sfst = (\<Lambda> p. fst (Rep_sprod p))"
    33 
    34 definition
    35   ssnd :: "('a ** 'b) \<rightarrow> 'b" where
    36   "ssnd = (\<Lambda> p. snd (Rep_sprod p))"
    37 
    38 definition
    39   spair :: "'a \<rightarrow> 'b \<rightarrow> ('a ** 'b)" where
    40   "spair = (\<Lambda> a b. Abs_sprod (seq\<cdot>b\<cdot>a, seq\<cdot>a\<cdot>b))"
    41 
    42 definition
    43   ssplit :: "('a \<rightarrow> 'b \<rightarrow> 'c) \<rightarrow> ('a ** 'b) \<rightarrow> 'c" where
    44   "ssplit = (\<Lambda> f p. seq\<cdot>p\<cdot>(f\<cdot>(sfst\<cdot>p)\<cdot>(ssnd\<cdot>p)))"
    45 
    46 syntax
    47   "_stuple" :: "[logic, args] \<Rightarrow> logic"  ("(1'(:_,/ _:'))")
    48 
    49 translations
    50   "(:x, y, z:)" == "(:x, (:y, z:):)"
    51   "(:x, y:)"    == "CONST spair\<cdot>x\<cdot>y"
    52 
    53 translations
    54   "\<Lambda>(CONST spair\<cdot>x\<cdot>y). t" == "CONST ssplit\<cdot>(\<Lambda> x y. t)"
    55 
    56 subsection \<open>Case analysis\<close>
    57 
    58 lemma spair_sprod: "(seq\<cdot>b\<cdot>a, seq\<cdot>a\<cdot>b) \<in> sprod"
    59 by (simp add: sprod_def seq_conv_if)
    60 
    61 lemma Rep_sprod_spair: "Rep_sprod (:a, b:) = (seq\<cdot>b\<cdot>a, seq\<cdot>a\<cdot>b)"
    62 by (simp add: spair_def cont_Abs_sprod Abs_sprod_inverse spair_sprod)
    63 
    64 lemmas Rep_sprod_simps =
    65   Rep_sprod_inject [symmetric] below_sprod_def
    66   prod_eq_iff below_prod_def
    67   Rep_sprod_strict Rep_sprod_spair
    68 
    69 lemma sprodE [case_names bottom spair, cases type: sprod]:
    70   obtains "p = \<bottom>" | x y where "p = (:x, y:)" and "x \<noteq> \<bottom>" and "y \<noteq> \<bottom>"
    71 using Rep_sprod [of p] by (auto simp add: sprod_def Rep_sprod_simps)
    72 
    73 lemma sprod_induct [case_names bottom spair, induct type: sprod]:
    74   "\<lbrakk>P \<bottom>; \<And>x y. \<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> P (:x, y:)\<rbrakk> \<Longrightarrow> P x"
    75 by (cases x, simp_all)
    76 
    77 subsection \<open>Properties of \emph{spair}\<close>
    78 
    79 lemma spair_strict1 [simp]: "(:\<bottom>, y:) = \<bottom>"
    80 by (simp add: Rep_sprod_simps)
    81 
    82 lemma spair_strict2 [simp]: "(:x, \<bottom>:) = \<bottom>"
    83 by (simp add: Rep_sprod_simps)
    84 
    85 lemma spair_bottom_iff [simp]: "((:x, y:) = \<bottom>) = (x = \<bottom> \<or> y = \<bottom>)"
    86 by (simp add: Rep_sprod_simps seq_conv_if)
    87 
    88 lemma spair_below_iff:
    89   "((:a, b:) \<sqsubseteq> (:c, d:)) = (a = \<bottom> \<or> b = \<bottom> \<or> (a \<sqsubseteq> c \<and> b \<sqsubseteq> d))"
    90 by (simp add: Rep_sprod_simps seq_conv_if)
    91 
    92 lemma spair_eq_iff:
    93   "((:a, b:) = (:c, d:)) =
    94     (a = c \<and> b = d \<or> (a = \<bottom> \<or> b = \<bottom>) \<and> (c = \<bottom> \<or> d = \<bottom>))"
    95 by (simp add: Rep_sprod_simps seq_conv_if)
    96 
    97 lemma spair_strict: "x = \<bottom> \<or> y = \<bottom> \<Longrightarrow> (:x, y:) = \<bottom>"
    98 by simp
    99 
   100 lemma spair_strict_rev: "(:x, y:) \<noteq> \<bottom> \<Longrightarrow> x \<noteq> \<bottom> \<and> y \<noteq> \<bottom>"
   101 by simp
   102 
   103 lemma spair_defined: "\<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> (:x, y:) \<noteq> \<bottom>"
   104 by simp
   105 
   106 lemma spair_defined_rev: "(:x, y:) = \<bottom> \<Longrightarrow> x = \<bottom> \<or> y = \<bottom>"
   107 by simp
   108 
   109 lemma spair_below:
   110   "\<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> (:x, y:) \<sqsubseteq> (:a, b:) = (x \<sqsubseteq> a \<and> y \<sqsubseteq> b)"
   111 by (simp add: spair_below_iff)
   112 
   113 lemma spair_eq:
   114   "\<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> ((:x, y:) = (:a, b:)) = (x = a \<and> y = b)"
   115 by (simp add: spair_eq_iff)
   116 
   117 lemma spair_inject:
   118   "\<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>; (:x, y:) = (:a, b:)\<rbrakk> \<Longrightarrow> x = a \<and> y = b"
   119 by (rule spair_eq [THEN iffD1])
   120 
   121 lemma inst_sprod_pcpo2: "\<bottom> = (:\<bottom>, \<bottom>:)"
   122 by simp
   123 
   124 lemma sprodE2: "(\<And>x y. p = (:x, y:) \<Longrightarrow> Q) \<Longrightarrow> Q"
   125 by (cases p, simp only: inst_sprod_pcpo2, simp)
   126 
   127 subsection \<open>Properties of \emph{sfst} and \emph{ssnd}\<close>
   128 
   129 lemma sfst_strict [simp]: "sfst\<cdot>\<bottom> = \<bottom>"
   130 by (simp add: sfst_def cont_Rep_sprod Rep_sprod_strict)
   131 
   132 lemma ssnd_strict [simp]: "ssnd\<cdot>\<bottom> = \<bottom>"
   133 by (simp add: ssnd_def cont_Rep_sprod Rep_sprod_strict)
   134 
   135 lemma sfst_spair [simp]: "y \<noteq> \<bottom> \<Longrightarrow> sfst\<cdot>(:x, y:) = x"
   136 by (simp add: sfst_def cont_Rep_sprod Rep_sprod_spair)
   137 
   138 lemma ssnd_spair [simp]: "x \<noteq> \<bottom> \<Longrightarrow> ssnd\<cdot>(:x, y:) = y"
   139 by (simp add: ssnd_def cont_Rep_sprod Rep_sprod_spair)
   140 
   141 lemma sfst_bottom_iff [simp]: "(sfst\<cdot>p = \<bottom>) = (p = \<bottom>)"
   142 by (cases p, simp_all)
   143 
   144 lemma ssnd_bottom_iff [simp]: "(ssnd\<cdot>p = \<bottom>) = (p = \<bottom>)"
   145 by (cases p, simp_all)
   146 
   147 lemma sfst_defined: "p \<noteq> \<bottom> \<Longrightarrow> sfst\<cdot>p \<noteq> \<bottom>"
   148 by simp
   149 
   150 lemma ssnd_defined: "p \<noteq> \<bottom> \<Longrightarrow> ssnd\<cdot>p \<noteq> \<bottom>"
   151 by simp
   152 
   153 lemma spair_sfst_ssnd: "(:sfst\<cdot>p, ssnd\<cdot>p:) = p"
   154 by (cases p, simp_all)
   155 
   156 lemma below_sprod: "(x \<sqsubseteq> y) = (sfst\<cdot>x \<sqsubseteq> sfst\<cdot>y \<and> ssnd\<cdot>x \<sqsubseteq> ssnd\<cdot>y)"
   157 by (simp add: Rep_sprod_simps sfst_def ssnd_def cont_Rep_sprod)
   158 
   159 lemma eq_sprod: "(x = y) = (sfst\<cdot>x = sfst\<cdot>y \<and> ssnd\<cdot>x = ssnd\<cdot>y)"
   160 by (auto simp add: po_eq_conv below_sprod)
   161 
   162 lemma sfst_below_iff: "sfst\<cdot>x \<sqsubseteq> y \<longleftrightarrow> x \<sqsubseteq> (:y, ssnd\<cdot>x:)"
   163 apply (cases "x = \<bottom>", simp, cases "y = \<bottom>", simp)
   164 apply (simp add: below_sprod)
   165 done
   166 
   167 lemma ssnd_below_iff: "ssnd\<cdot>x \<sqsubseteq> y \<longleftrightarrow> x \<sqsubseteq> (:sfst\<cdot>x, y:)"
   168 apply (cases "x = \<bottom>", simp, cases "y = \<bottom>", simp)
   169 apply (simp add: below_sprod)
   170 done
   171 
   172 subsection \<open>Compactness\<close>
   173 
   174 lemma compact_sfst: "compact x \<Longrightarrow> compact (sfst\<cdot>x)"
   175 by (rule compactI, simp add: sfst_below_iff)
   176 
   177 lemma compact_ssnd: "compact x \<Longrightarrow> compact (ssnd\<cdot>x)"
   178 by (rule compactI, simp add: ssnd_below_iff)
   179 
   180 lemma compact_spair: "\<lbrakk>compact x; compact y\<rbrakk> \<Longrightarrow> compact (:x, y:)"
   181 by (rule compact_sprod, simp add: Rep_sprod_spair seq_conv_if)
   182 
   183 lemma compact_spair_iff:
   184   "compact (:x, y:) = (x = \<bottom> \<or> y = \<bottom> \<or> (compact x \<and> compact y))"
   185 apply (safe elim!: compact_spair)
   186 apply (drule compact_sfst, simp)
   187 apply (drule compact_ssnd, simp)
   188 apply simp
   189 apply simp
   190 done
   191 
   192 subsection \<open>Properties of \emph{ssplit}\<close>
   193 
   194 lemma ssplit1 [simp]: "ssplit\<cdot>f\<cdot>\<bottom> = \<bottom>"
   195 by (simp add: ssplit_def)
   196 
   197 lemma ssplit2 [simp]: "\<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> ssplit\<cdot>f\<cdot>(:x, y:) = f\<cdot>x\<cdot>y"
   198 by (simp add: ssplit_def)
   199 
   200 lemma ssplit3 [simp]: "ssplit\<cdot>spair\<cdot>z = z"
   201 by (cases z, simp_all)
   202 
   203 subsection \<open>Strict product preserves flatness\<close>
   204 
   205 instance sprod :: (flat, flat) flat
   206 proof
   207   fix x y :: "'a \<otimes> 'b"
   208   assume "x \<sqsubseteq> y" thus "x = \<bottom> \<or> x = y"
   209     apply (induct x, simp)
   210     apply (induct y, simp)
   211     apply (simp add: spair_below_iff flat_below_iff)
   212     done
   213 qed
   214 
   215 end