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