1.1 --- a/src/HOLCF/Domain.thy Sat Nov 27 14:34:54 2010 -0800
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,352 +0,0 @@
1.4 -(* Title: HOLCF/Domain.thy
1.5 - Author: Brian Huffman
1.6 -*)
1.7 -
1.8 -header {* Domain package *}
1.9 -
1.10 -theory Domain
1.11 -imports Bifinite Domain_Aux
1.12 -uses
1.13 - ("Tools/domaindef.ML")
1.14 - ("Tools/Domain/domain_isomorphism.ML")
1.15 - ("Tools/Domain/domain_axioms.ML")
1.16 - ("Tools/Domain/domain.ML")
1.17 -begin
1.18 -
1.19 -default_sort "domain"
1.20 -
1.21 -subsection {* Representations of types *}
1.22 -
1.23 -lemma emb_prj: "emb\<cdot>((prj\<cdot>x)::'a) = cast\<cdot>DEFL('a)\<cdot>x"
1.24 -by (simp add: cast_DEFL)
1.25 -
1.26 -lemma emb_prj_emb:
1.27 - fixes x :: "'a"
1.28 - assumes "DEFL('a) \<sqsubseteq> DEFL('b)"
1.29 - shows "emb\<cdot>(prj\<cdot>(emb\<cdot>x) :: 'b) = emb\<cdot>x"
1.30 -unfolding emb_prj
1.31 -apply (rule cast.belowD)
1.32 -apply (rule monofun_cfun_arg [OF assms])
1.33 -apply (simp add: cast_DEFL)
1.34 -done
1.35 -
1.36 -lemma prj_emb_prj:
1.37 - assumes "DEFL('a) \<sqsubseteq> DEFL('b)"
1.38 - shows "prj\<cdot>(emb\<cdot>(prj\<cdot>x :: 'b)) = (prj\<cdot>x :: 'a)"
1.39 - apply (rule emb_eq_iff [THEN iffD1])
1.40 - apply (simp only: emb_prj)
1.41 - apply (rule deflation_below_comp1)
1.42 - apply (rule deflation_cast)
1.43 - apply (rule deflation_cast)
1.44 - apply (rule monofun_cfun_arg [OF assms])
1.45 -done
1.46 -
1.47 -text {* Isomorphism lemmas used internally by the domain package: *}
1.48 -
1.49 -lemma domain_abs_iso:
1.50 - fixes abs and rep
1.51 - assumes DEFL: "DEFL('b) = DEFL('a)"
1.52 - assumes abs_def: "(abs :: 'a \<rightarrow> 'b) \<equiv> prj oo emb"
1.53 - assumes rep_def: "(rep :: 'b \<rightarrow> 'a) \<equiv> prj oo emb"
1.54 - shows "rep\<cdot>(abs\<cdot>x) = x"
1.55 -unfolding abs_def rep_def
1.56 -by (simp add: emb_prj_emb DEFL)
1.57 -
1.58 -lemma domain_rep_iso:
1.59 - fixes abs and rep
1.60 - assumes DEFL: "DEFL('b) = DEFL('a)"
1.61 - assumes abs_def: "(abs :: 'a \<rightarrow> 'b) \<equiv> prj oo emb"
1.62 - assumes rep_def: "(rep :: 'b \<rightarrow> 'a) \<equiv> prj oo emb"
1.63 - shows "abs\<cdot>(rep\<cdot>x) = x"
1.64 -unfolding abs_def rep_def
1.65 -by (simp add: emb_prj_emb DEFL)
1.66 -
1.67 -subsection {* Deflations as sets *}
1.68 -
1.69 -definition defl_set :: "defl \<Rightarrow> udom set"
1.70 -where "defl_set A = {x. cast\<cdot>A\<cdot>x = x}"
1.71 -
1.72 -lemma adm_defl_set: "adm (\<lambda>x. x \<in> defl_set A)"
1.73 -unfolding defl_set_def by simp
1.74 -
1.75 -lemma defl_set_bottom: "\<bottom> \<in> defl_set A"
1.76 -unfolding defl_set_def by simp
1.77 -
1.78 -lemma defl_set_cast [simp]: "cast\<cdot>A\<cdot>x \<in> defl_set A"
1.79 -unfolding defl_set_def by simp
1.80 -
1.81 -lemma defl_set_subset_iff: "defl_set A \<subseteq> defl_set B \<longleftrightarrow> A \<sqsubseteq> B"
1.82 -apply (simp add: defl_set_def subset_eq cast_below_cast [symmetric])
1.83 -apply (auto simp add: cast.belowI cast.belowD)
1.84 -done
1.85 -
1.86 -subsection {* Proving a subtype is representable *}
1.87 -
1.88 -text {* Temporarily relax type constraints. *}
1.89 -
1.90 -setup {*
1.91 - fold Sign.add_const_constraint
1.92 - [ (@{const_name defl}, SOME @{typ "'a::pcpo itself \<Rightarrow> defl"})
1.93 - , (@{const_name emb}, SOME @{typ "'a::pcpo \<rightarrow> udom"})
1.94 - , (@{const_name prj}, SOME @{typ "udom \<rightarrow> 'a::pcpo"})
1.95 - , (@{const_name liftdefl}, SOME @{typ "'a::pcpo itself \<Rightarrow> defl"})
1.96 - , (@{const_name liftemb}, SOME @{typ "'a::pcpo u \<rightarrow> udom"})
1.97 - , (@{const_name liftprj}, SOME @{typ "udom \<rightarrow> 'a::pcpo u"}) ]
1.98 -*}
1.99 -
1.100 -lemma typedef_liftdomain_class:
1.101 - fixes Rep :: "'a::pcpo \<Rightarrow> udom"
1.102 - fixes Abs :: "udom \<Rightarrow> 'a::pcpo"
1.103 - fixes t :: defl
1.104 - assumes type: "type_definition Rep Abs (defl_set t)"
1.105 - assumes below: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
1.106 - assumes emb: "emb \<equiv> (\<Lambda> x. Rep x)"
1.107 - assumes prj: "prj \<equiv> (\<Lambda> x. Abs (cast\<cdot>t\<cdot>x))"
1.108 - assumes defl: "defl \<equiv> (\<lambda> a::'a itself. t)"
1.109 - assumes liftemb: "(liftemb :: 'a u \<rightarrow> udom) \<equiv> udom_emb u_approx oo u_map\<cdot>emb"
1.110 - assumes liftprj: "(liftprj :: udom \<rightarrow> 'a u) \<equiv> u_map\<cdot>prj oo udom_prj u_approx"
1.111 - assumes liftdefl: "(liftdefl :: 'a itself \<Rightarrow> defl) \<equiv> (\<lambda>t. u_defl\<cdot>DEFL('a))"
1.112 - shows "OFCLASS('a, liftdomain_class)"
1.113 -using liftemb [THEN meta_eq_to_obj_eq]
1.114 -using liftprj [THEN meta_eq_to_obj_eq]
1.115 -proof (rule liftdomain_class_intro)
1.116 - have emb_beta: "\<And>x. emb\<cdot>x = Rep x"
1.117 - unfolding emb
1.118 - apply (rule beta_cfun)
1.119 - apply (rule typedef_cont_Rep [OF type below adm_defl_set])
1.120 - done
1.121 - have prj_beta: "\<And>y. prj\<cdot>y = Abs (cast\<cdot>t\<cdot>y)"
1.122 - unfolding prj
1.123 - apply (rule beta_cfun)
1.124 - apply (rule typedef_cont_Abs [OF type below adm_defl_set])
1.125 - apply simp_all
1.126 - done
1.127 - have prj_emb: "\<And>x::'a. prj\<cdot>(emb\<cdot>x) = x"
1.128 - using type_definition.Rep [OF type]
1.129 - unfolding prj_beta emb_beta defl_set_def
1.130 - by (simp add: type_definition.Rep_inverse [OF type])
1.131 - have emb_prj: "\<And>y. emb\<cdot>(prj\<cdot>y :: 'a) = cast\<cdot>t\<cdot>y"
1.132 - unfolding prj_beta emb_beta
1.133 - by (simp add: type_definition.Abs_inverse [OF type])
1.134 - show "ep_pair (emb :: 'a \<rightarrow> udom) prj"
1.135 - apply default
1.136 - apply (simp add: prj_emb)
1.137 - apply (simp add: emb_prj cast.below)
1.138 - done
1.139 - show "cast\<cdot>DEFL('a) = emb oo (prj :: udom \<rightarrow> 'a)"
1.140 - by (rule cfun_eqI, simp add: defl emb_prj)
1.141 - show "LIFTDEFL('a) = u_defl\<cdot>DEFL('a)"
1.142 - unfolding liftdefl ..
1.143 -qed
1.144 -
1.145 -lemma typedef_DEFL:
1.146 - assumes "defl \<equiv> (\<lambda>a::'a::pcpo itself. t)"
1.147 - shows "DEFL('a::pcpo) = t"
1.148 -unfolding assms ..
1.149 -
1.150 -text {* Restore original typing constraints. *}
1.151 -
1.152 -setup {*
1.153 - fold Sign.add_const_constraint
1.154 - [ (@{const_name defl}, SOME @{typ "'a::domain itself \<Rightarrow> defl"})
1.155 - , (@{const_name emb}, SOME @{typ "'a::domain \<rightarrow> udom"})
1.156 - , (@{const_name prj}, SOME @{typ "udom \<rightarrow> 'a::domain"})
1.157 - , (@{const_name liftdefl}, SOME @{typ "'a::predomain itself \<Rightarrow> defl"})
1.158 - , (@{const_name liftemb}, SOME @{typ "'a::predomain u \<rightarrow> udom"})
1.159 - , (@{const_name liftprj}, SOME @{typ "udom \<rightarrow> 'a::predomain u"}) ]
1.160 -*}
1.161 -
1.162 -use "Tools/domaindef.ML"
1.163 -
1.164 -subsection {* Isomorphic deflations *}
1.165 -
1.166 -definition
1.167 - isodefl :: "('a \<rightarrow> 'a) \<Rightarrow> defl \<Rightarrow> bool"
1.168 -where
1.169 - "isodefl d t \<longleftrightarrow> cast\<cdot>t = emb oo d oo prj"
1.170 -
1.171 -lemma isodeflI: "(\<And>x. cast\<cdot>t\<cdot>x = emb\<cdot>(d\<cdot>(prj\<cdot>x))) \<Longrightarrow> isodefl d t"
1.172 -unfolding isodefl_def by (simp add: cfun_eqI)
1.173 -
1.174 -lemma cast_isodefl: "isodefl d t \<Longrightarrow> cast\<cdot>t = (\<Lambda> x. emb\<cdot>(d\<cdot>(prj\<cdot>x)))"
1.175 -unfolding isodefl_def by (simp add: cfun_eqI)
1.176 -
1.177 -lemma isodefl_strict: "isodefl d t \<Longrightarrow> d\<cdot>\<bottom> = \<bottom>"
1.178 -unfolding isodefl_def
1.179 -by (drule cfun_fun_cong [where x="\<bottom>"], simp)
1.180 -
1.181 -lemma isodefl_imp_deflation:
1.182 - fixes d :: "'a \<rightarrow> 'a"
1.183 - assumes "isodefl d t" shows "deflation d"
1.184 -proof
1.185 - note assms [unfolded isodefl_def, simp]
1.186 - fix x :: 'a
1.187 - show "d\<cdot>(d\<cdot>x) = d\<cdot>x"
1.188 - using cast.idem [of t "emb\<cdot>x"] by simp
1.189 - show "d\<cdot>x \<sqsubseteq> x"
1.190 - using cast.below [of t "emb\<cdot>x"] by simp
1.191 -qed
1.192 -
1.193 -lemma isodefl_ID_DEFL: "isodefl (ID :: 'a \<rightarrow> 'a) DEFL('a)"
1.194 -unfolding isodefl_def by (simp add: cast_DEFL)
1.195 -
1.196 -lemma isodefl_LIFTDEFL:
1.197 - "isodefl (u_map\<cdot>(ID :: 'a \<rightarrow> 'a)) LIFTDEFL('a::predomain)"
1.198 -unfolding u_map_ID DEFL_u [symmetric]
1.199 -by (rule isodefl_ID_DEFL)
1.200 -
1.201 -lemma isodefl_DEFL_imp_ID: "isodefl (d :: 'a \<rightarrow> 'a) DEFL('a) \<Longrightarrow> d = ID"
1.202 -unfolding isodefl_def
1.203 -apply (simp add: cast_DEFL)
1.204 -apply (simp add: cfun_eq_iff)
1.205 -apply (rule allI)
1.206 -apply (drule_tac x="emb\<cdot>x" in spec)
1.207 -apply simp
1.208 -done
1.209 -
1.210 -lemma isodefl_bottom: "isodefl \<bottom> \<bottom>"
1.211 -unfolding isodefl_def by (simp add: cfun_eq_iff)
1.212 -
1.213 -lemma adm_isodefl:
1.214 - "cont f \<Longrightarrow> cont g \<Longrightarrow> adm (\<lambda>x. isodefl (f x) (g x))"
1.215 -unfolding isodefl_def by simp
1.216 -
1.217 -lemma isodefl_lub:
1.218 - assumes "chain d" and "chain t"
1.219 - assumes "\<And>i. isodefl (d i) (t i)"
1.220 - shows "isodefl (\<Squnion>i. d i) (\<Squnion>i. t i)"
1.221 -using prems unfolding isodefl_def
1.222 -by (simp add: contlub_cfun_arg contlub_cfun_fun)
1.223 -
1.224 -lemma isodefl_fix:
1.225 - assumes "\<And>d t. isodefl d t \<Longrightarrow> isodefl (f\<cdot>d) (g\<cdot>t)"
1.226 - shows "isodefl (fix\<cdot>f) (fix\<cdot>g)"
1.227 -unfolding fix_def2
1.228 -apply (rule isodefl_lub, simp, simp)
1.229 -apply (induct_tac i)
1.230 -apply (simp add: isodefl_bottom)
1.231 -apply (simp add: assms)
1.232 -done
1.233 -
1.234 -lemma isodefl_abs_rep:
1.235 - fixes abs and rep and d
1.236 - assumes DEFL: "DEFL('b) = DEFL('a)"
1.237 - assumes abs_def: "(abs :: 'a \<rightarrow> 'b) \<equiv> prj oo emb"
1.238 - assumes rep_def: "(rep :: 'b \<rightarrow> 'a) \<equiv> prj oo emb"
1.239 - shows "isodefl d t \<Longrightarrow> isodefl (abs oo d oo rep) t"
1.240 -unfolding isodefl_def
1.241 -by (simp add: cfun_eq_iff assms prj_emb_prj emb_prj_emb)
1.242 -
1.243 -lemma isodefl_sfun:
1.244 - "isodefl d1 t1 \<Longrightarrow> isodefl d2 t2 \<Longrightarrow>
1.245 - isodefl (sfun_map\<cdot>d1\<cdot>d2) (sfun_defl\<cdot>t1\<cdot>t2)"
1.246 -apply (rule isodeflI)
1.247 -apply (simp add: cast_sfun_defl cast_isodefl)
1.248 -apply (simp add: emb_sfun_def prj_sfun_def)
1.249 -apply (simp add: sfun_map_map isodefl_strict)
1.250 -done
1.251 -
1.252 -lemma isodefl_ssum:
1.253 - "isodefl d1 t1 \<Longrightarrow> isodefl d2 t2 \<Longrightarrow>
1.254 - isodefl (ssum_map\<cdot>d1\<cdot>d2) (ssum_defl\<cdot>t1\<cdot>t2)"
1.255 -apply (rule isodeflI)
1.256 -apply (simp add: cast_ssum_defl cast_isodefl)
1.257 -apply (simp add: emb_ssum_def prj_ssum_def)
1.258 -apply (simp add: ssum_map_map isodefl_strict)
1.259 -done
1.260 -
1.261 -lemma isodefl_sprod:
1.262 - "isodefl d1 t1 \<Longrightarrow> isodefl d2 t2 \<Longrightarrow>
1.263 - isodefl (sprod_map\<cdot>d1\<cdot>d2) (sprod_defl\<cdot>t1\<cdot>t2)"
1.264 -apply (rule isodeflI)
1.265 -apply (simp add: cast_sprod_defl cast_isodefl)
1.266 -apply (simp add: emb_sprod_def prj_sprod_def)
1.267 -apply (simp add: sprod_map_map isodefl_strict)
1.268 -done
1.269 -
1.270 -lemma isodefl_cprod:
1.271 - "isodefl d1 t1 \<Longrightarrow> isodefl d2 t2 \<Longrightarrow>
1.272 - isodefl (cprod_map\<cdot>d1\<cdot>d2) (prod_defl\<cdot>t1\<cdot>t2)"
1.273 -apply (rule isodeflI)
1.274 -apply (simp add: cast_prod_defl cast_isodefl)
1.275 -apply (simp add: emb_prod_def prj_prod_def)
1.276 -apply (simp add: cprod_map_map cfcomp1)
1.277 -done
1.278 -
1.279 -lemma isodefl_u:
1.280 - fixes d :: "'a::liftdomain \<rightarrow> 'a"
1.281 - shows "isodefl (d :: 'a \<rightarrow> 'a) t \<Longrightarrow> isodefl (u_map\<cdot>d) (u_defl\<cdot>t)"
1.282 -apply (rule isodeflI)
1.283 -apply (simp add: cast_u_defl cast_isodefl)
1.284 -apply (simp add: emb_u_def prj_u_def liftemb_eq liftprj_eq)
1.285 -apply (simp add: u_map_map)
1.286 -done
1.287 -
1.288 -lemma encode_prod_u_map:
1.289 - "encode_prod_u\<cdot>(u_map\<cdot>(cprod_map\<cdot>f\<cdot>g)\<cdot>(decode_prod_u\<cdot>x))
1.290 - = sprod_map\<cdot>(u_map\<cdot>f)\<cdot>(u_map\<cdot>g)\<cdot>x"
1.291 -unfolding encode_prod_u_def decode_prod_u_def
1.292 -apply (case_tac x, simp, rename_tac a b)
1.293 -apply (case_tac a, simp, case_tac b, simp, simp)
1.294 -done
1.295 -
1.296 -lemma isodefl_cprod_u:
1.297 - assumes "isodefl (u_map\<cdot>d1) t1" and "isodefl (u_map\<cdot>d2) t2"
1.298 - shows "isodefl (u_map\<cdot>(cprod_map\<cdot>d1\<cdot>d2)) (sprod_defl\<cdot>t1\<cdot>t2)"
1.299 -using assms unfolding isodefl_def
1.300 -apply (simp add: emb_u_def prj_u_def liftemb_prod_def liftprj_prod_def)
1.301 -apply (simp add: emb_u_def [symmetric] prj_u_def [symmetric])
1.302 -apply (simp add: cfcomp1 encode_prod_u_map cast_sprod_defl sprod_map_map)
1.303 -done
1.304 -
1.305 -lemma encode_cfun_map:
1.306 - "encode_cfun\<cdot>(cfun_map\<cdot>f\<cdot>g\<cdot>(decode_cfun\<cdot>x))
1.307 - = sfun_map\<cdot>(u_map\<cdot>f)\<cdot>g\<cdot>x"
1.308 -unfolding encode_cfun_def decode_cfun_def
1.309 -apply (simp add: sfun_eq_iff cfun_map_def sfun_map_def)
1.310 -apply (rule cfun_eqI, rename_tac y, case_tac y, simp_all)
1.311 -done
1.312 -
1.313 -lemma isodefl_cfun:
1.314 - "isodefl (u_map\<cdot>d1) t1 \<Longrightarrow> isodefl d2 t2 \<Longrightarrow>
1.315 - isodefl (cfun_map\<cdot>d1\<cdot>d2) (sfun_defl\<cdot>t1\<cdot>t2)"
1.316 -apply (rule isodeflI)
1.317 -apply (simp add: cast_sfun_defl cast_isodefl)
1.318 -apply (simp add: emb_cfun_def prj_cfun_def encode_cfun_map)
1.319 -apply (simp add: sfun_map_map isodefl_strict)
1.320 -done
1.321 -
1.322 -subsection {* Setting up the domain package *}
1.323 -
1.324 -use "Tools/Domain/domain_isomorphism.ML"
1.325 -use "Tools/Domain/domain_axioms.ML"
1.326 -use "Tools/Domain/domain.ML"
1.327 -
1.328 -setup Domain_Isomorphism.setup
1.329 -
1.330 -lemmas [domain_defl_simps] =
1.331 - DEFL_cfun DEFL_sfun DEFL_ssum DEFL_sprod DEFL_prod DEFL_u
1.332 - liftdefl_eq LIFTDEFL_prod
1.333 -
1.334 -lemmas [domain_map_ID] =
1.335 - cfun_map_ID sfun_map_ID ssum_map_ID sprod_map_ID cprod_map_ID u_map_ID
1.336 -
1.337 -lemmas [domain_isodefl] =
1.338 - isodefl_u isodefl_sfun isodefl_ssum isodefl_sprod
1.339 - isodefl_cfun isodefl_cprod isodefl_cprod_u
1.340 -
1.341 -lemmas [domain_deflation] =
1.342 - deflation_cfun_map deflation_sfun_map deflation_ssum_map
1.343 - deflation_sprod_map deflation_cprod_map deflation_u_map
1.344 -
1.345 -setup {*
1.346 - fold Domain_Take_Proofs.add_rec_type
1.347 - [(@{type_name cfun}, [true, true]),
1.348 - (@{type_name "sfun"}, [true, true]),
1.349 - (@{type_name ssum}, [true, true]),
1.350 - (@{type_name sprod}, [true, true]),
1.351 - (@{type_name prod}, [true, true]),
1.352 - (@{type_name "u"}, [true])]
1.353 -*}
1.354 -
1.355 -end