src/HOLCF/Cprod.thy
author huffman
Thu Nov 03 01:02:29 2005 +0100 (2005-11-03)
changeset 18077 f1f4f951ec8d
parent 17837 2922be3544f8
child 18078 20e5a6440790
permissions -rw-r--r--
make cpair_less, cpair_defined_iff into iff rules; add lemma csplit1
     1 (*  Title:      HOLCF/Cprod.thy
     2     ID:         $Id$
     3     Author:     Franz Regensburger
     4 
     5 Partial ordering for cartesian product of HOL products.
     6 *)
     7 
     8 header {* The cpo of cartesian products *}
     9 
    10 theory Cprod
    11 imports Cfun
    12 begin
    13 
    14 defaultsort cpo
    15 
    16 subsection {* Type @{typ unit} is a pcpo *}
    17 
    18 instance unit :: sq_ord ..
    19 
    20 defs (overloaded)
    21   less_unit_def [simp]: "x \<sqsubseteq> (y::unit) \<equiv> True"
    22 
    23 instance unit :: po
    24 by intro_classes simp_all
    25 
    26 instance unit :: cpo
    27 by intro_classes (simp add: is_lub_def is_ub_def)
    28 
    29 instance unit :: pcpo
    30 by intro_classes simp
    31 
    32 
    33 subsection {* Type @{typ "'a * 'b"} is a partial order *}
    34 
    35 instance "*" :: (sq_ord, sq_ord) sq_ord ..
    36 
    37 defs (overloaded)
    38   less_cprod_def: "(op \<sqsubseteq>) \<equiv> \<lambda>p1 p2. (fst p1 \<sqsubseteq> fst p2 \<and> snd p1 \<sqsubseteq> snd p2)"
    39 
    40 lemma refl_less_cprod: "(p::'a * 'b) \<sqsubseteq> p"
    41 by (simp add: less_cprod_def)
    42 
    43 lemma antisym_less_cprod: "\<lbrakk>(p1::'a * 'b) \<sqsubseteq> p2; p2 \<sqsubseteq> p1\<rbrakk> \<Longrightarrow> p1 = p2"
    44 apply (unfold less_cprod_def)
    45 apply (rule injective_fst_snd)
    46 apply (fast intro: antisym_less)
    47 apply (fast intro: antisym_less)
    48 done
    49 
    50 lemma trans_less_cprod: "\<lbrakk>(p1::'a*'b) \<sqsubseteq> p2; p2 \<sqsubseteq> p3\<rbrakk> \<Longrightarrow> p1 \<sqsubseteq> p3"
    51 apply (unfold less_cprod_def)
    52 apply (fast intro: trans_less)
    53 done
    54 
    55 instance "*" :: (cpo, cpo) po
    56 by intro_classes
    57   (assumption | rule refl_less_cprod antisym_less_cprod trans_less_cprod)+
    58 
    59 
    60 subsection {* Monotonicity of @{text "(_,_)"}, @{term fst}, @{term snd} *}
    61 
    62 text {* Pair @{text "(_,_)"}  is monotone in both arguments *}
    63 
    64 lemma monofun_pair1: "monofun (\<lambda>x. (x, y))"
    65 by (simp add: monofun_def less_cprod_def)
    66 
    67 lemma monofun_pair2: "monofun (\<lambda>y. (x, y))"
    68 by (simp add: monofun_def less_cprod_def)
    69 
    70 lemma monofun_pair:
    71   "\<lbrakk>x1 \<sqsubseteq> x2; y1 \<sqsubseteq> y2\<rbrakk> \<Longrightarrow> (x1, y1) \<sqsubseteq> (x2, y2)"
    72 by (simp add: less_cprod_def)
    73 
    74 text {* @{term fst} and @{term snd} are monotone *}
    75 
    76 lemma monofun_fst: "monofun fst"
    77 by (simp add: monofun_def less_cprod_def)
    78 
    79 lemma monofun_snd: "monofun snd"
    80 by (simp add: monofun_def less_cprod_def)
    81 
    82 subsection {* Type @{typ "'a * 'b"} is a cpo *}
    83 
    84 lemma lub_cprod: 
    85   "chain S \<Longrightarrow> range S <<| (\<Squnion>i. fst (S i), \<Squnion>i. snd (S i))"
    86 apply (rule is_lubI)
    87 apply (rule ub_rangeI)
    88 apply (rule_tac t = "S i" in surjective_pairing [THEN ssubst])
    89 apply (rule monofun_pair)
    90 apply (rule is_ub_thelub)
    91 apply (erule monofun_fst [THEN ch2ch_monofun])
    92 apply (rule is_ub_thelub)
    93 apply (erule monofun_snd [THEN ch2ch_monofun])
    94 apply (rule_tac t = "u" in surjective_pairing [THEN ssubst])
    95 apply (rule monofun_pair)
    96 apply (rule is_lub_thelub)
    97 apply (erule monofun_fst [THEN ch2ch_monofun])
    98 apply (erule monofun_fst [THEN ub2ub_monofun])
    99 apply (rule is_lub_thelub)
   100 apply (erule monofun_snd [THEN ch2ch_monofun])
   101 apply (erule monofun_snd [THEN ub2ub_monofun])
   102 done
   103 
   104 lemma thelub_cprod:
   105   "chain S \<Longrightarrow> lub (range S) = (\<Squnion>i. fst (S i), \<Squnion>i. snd (S i))"
   106 by (rule lub_cprod [THEN thelubI])
   107 
   108 lemma cpo_cprod:
   109   "chain (S::nat \<Rightarrow> 'a::cpo * 'b::cpo) \<Longrightarrow> \<exists>x. range S <<| x"
   110 by (rule exI, erule lub_cprod)
   111 
   112 instance "*" :: (cpo, cpo) cpo
   113 by intro_classes (rule cpo_cprod)
   114 
   115 subsection {* Type @{typ "'a * 'b"} is pointed *}
   116 
   117 lemma minimal_cprod: "(\<bottom>, \<bottom>) \<sqsubseteq> p"
   118 by (simp add: less_cprod_def)
   119 
   120 lemma least_cprod: "EX x::'a::pcpo * 'b::pcpo. ALL y. x \<sqsubseteq> y"
   121 apply (rule_tac x = "(\<bottom>, \<bottom>)" in exI)
   122 apply (rule minimal_cprod [THEN allI])
   123 done
   124 
   125 instance "*" :: (pcpo, pcpo) pcpo
   126 by intro_classes (rule least_cprod)
   127 
   128 text {* for compatibility with old HOLCF-Version *}
   129 lemma inst_cprod_pcpo: "UU = (UU,UU)"
   130 by (rule minimal_cprod [THEN UU_I, symmetric])
   131 
   132 
   133 subsection {* Continuity of @{text "(_,_)"}, @{term fst}, @{term snd} *}
   134 
   135 lemma contlub_pair1: "contlub (\<lambda>x. (x, y))"
   136 apply (rule contlubI)
   137 apply (subst thelub_cprod)
   138 apply (erule monofun_pair1 [THEN ch2ch_monofun])
   139 apply simp
   140 done
   141 
   142 lemma contlub_pair2: "contlub (\<lambda>y. (x, y))"
   143 apply (rule contlubI)
   144 apply (subst thelub_cprod)
   145 apply (erule monofun_pair2 [THEN ch2ch_monofun])
   146 apply simp
   147 done
   148 
   149 lemma cont_pair1: "cont (\<lambda>x. (x, y))"
   150 apply (rule monocontlub2cont)
   151 apply (rule monofun_pair1)
   152 apply (rule contlub_pair1)
   153 done
   154 
   155 lemma cont_pair2: "cont (\<lambda>y. (x, y))"
   156 apply (rule monocontlub2cont)
   157 apply (rule monofun_pair2)
   158 apply (rule contlub_pair2)
   159 done
   160 
   161 lemma contlub_fst: "contlub fst"
   162 apply (rule contlubI)
   163 apply (simp add: thelub_cprod)
   164 done
   165 
   166 lemma contlub_snd: "contlub snd"
   167 apply (rule contlubI)
   168 apply (simp add: thelub_cprod)
   169 done
   170 
   171 lemma cont_fst: "cont fst"
   172 apply (rule monocontlub2cont)
   173 apply (rule monofun_fst)
   174 apply (rule contlub_fst)
   175 done
   176 
   177 lemma cont_snd: "cont snd"
   178 apply (rule monocontlub2cont)
   179 apply (rule monofun_snd)
   180 apply (rule contlub_snd)
   181 done
   182 
   183 subsection {* Continuous versions of constants *}
   184 
   185 constdefs
   186   cpair :: "'a \<rightarrow> 'b \<rightarrow> ('a * 'b)" (* continuous pairing *)
   187   "cpair \<equiv> (\<Lambda> x y. (x, y))"
   188 
   189   cfst :: "('a * 'b) \<rightarrow> 'a"
   190   "cfst \<equiv> (\<Lambda> p. fst p)"
   191 
   192   csnd :: "('a * 'b) \<rightarrow> 'b"
   193   "csnd \<equiv> (\<Lambda> p. snd p)"      
   194 
   195   csplit :: "('a \<rightarrow> 'b \<rightarrow> 'c) \<rightarrow> ('a * 'b) \<rightarrow> 'c"
   196   "csplit \<equiv> (\<Lambda> f p. f\<cdot>(cfst\<cdot>p)\<cdot>(csnd\<cdot>p))"
   197 
   198 syntax
   199   "_ctuple" :: "['a, args] \<Rightarrow> 'a * 'b"  ("(1<_,/ _>)")
   200 
   201 syntax (xsymbols)
   202   "_ctuple" :: "['a, args] \<Rightarrow> 'a * 'b"  ("(1\<langle>_,/ _\<rangle>)")
   203 
   204 translations
   205   "<x, y, z>" == "<x, <y, z>>"
   206   "<x, y>"    == "cpair$x$y"
   207 
   208 text {* syntax for @{text "LAM <x,y,z>.e"} *}
   209 
   210 syntax
   211   "_ctuple_pttrn" :: "[pttrn, patterns] => pttrn"  ("<_,/ _>")
   212 
   213 syntax (xsymbols)
   214   "_ctuple_pttrn" :: "[pttrn, patterns] => pttrn"  ("\<langle>_,/ _\<rangle>")
   215 
   216 translations
   217   "LAM <x,y,zs>. t"       == "csplit$(LAM x <y,zs>. t)"
   218   "LAM <x,y>. t"          == "csplit$(LAM x y. t)"
   219 
   220 
   221 subsection {* Convert all lemmas to the continuous versions *}
   222 
   223 lemma cpair_eq_pair: "<x, y> = (x, y)"
   224 by (simp add: cpair_def cont_pair1 cont_pair2)
   225 
   226 lemma inject_cpair: "<a,b> = <aa,ba> \<Longrightarrow> a = aa \<and> b = ba"
   227 by (simp add: cpair_eq_pair)
   228 
   229 lemma cpair_eq [iff]: "(<a, b> = <a', b'>) = (a = a' \<and> b = b')"
   230 by (simp add: cpair_eq_pair)
   231 
   232 lemma cpair_less [iff]: "(<a, b> \<sqsubseteq> <a', b'>) = (a \<sqsubseteq> a' \<and> b \<sqsubseteq> b')"
   233 by (simp add: cpair_eq_pair less_cprod_def)
   234 
   235 lemma cpair_defined_iff [iff]: "(<x, y> = \<bottom>) = (x = \<bottom> \<and> y = \<bottom>)"
   236 by (simp add: inst_cprod_pcpo cpair_eq_pair)
   237 
   238 lemma cpair_strict: "<\<bottom>, \<bottom>> = \<bottom>"
   239 by simp
   240 
   241 lemma inst_cprod_pcpo2: "\<bottom> = <\<bottom>, \<bottom>>"
   242 by (rule cpair_strict [symmetric])
   243 
   244 lemma defined_cpair_rev: 
   245  "<a,b> = \<bottom> \<Longrightarrow> a = \<bottom> \<and> b = \<bottom>"
   246 by simp
   247 
   248 lemma Exh_Cprod2: "\<exists>a b. z = <a, b>"
   249 by (simp add: cpair_eq_pair)
   250 
   251 lemma cprodE: "\<lbrakk>\<And>x y. p = <x, y> \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
   252 by (cut_tac Exh_Cprod2, auto)
   253 
   254 lemma cfst_cpair [simp]: "cfst\<cdot><x, y> = x"
   255 by (simp add: cpair_eq_pair cfst_def cont_fst)
   256 
   257 lemma csnd_cpair [simp]: "csnd\<cdot><x, y> = y"
   258 by (simp add: cpair_eq_pair csnd_def cont_snd)
   259 
   260 lemma cfst_strict [simp]: "cfst\<cdot>\<bottom> = \<bottom>"
   261 by (simp add: inst_cprod_pcpo2)
   262 
   263 lemma csnd_strict [simp]: "csnd\<cdot>\<bottom> = \<bottom>"
   264 by (simp add: inst_cprod_pcpo2)
   265 
   266 lemma surjective_pairing_Cprod2: "<cfst\<cdot>p, csnd\<cdot>p> = p"
   267 apply (unfold cfst_def csnd_def)
   268 apply (simp add: cont_fst cont_snd cpair_eq_pair)
   269 done
   270 
   271 lemma less_cprod: "x \<sqsubseteq> y = (cfst\<cdot>x \<sqsubseteq> cfst\<cdot>y \<and> csnd\<cdot>x \<sqsubseteq> csnd\<cdot>y)"
   272 by (simp add: less_cprod_def cfst_def csnd_def cont_fst cont_snd)
   273 
   274 lemma eq_cprod: "(x = y) = (cfst\<cdot>x = cfst\<cdot>y \<and> csnd\<cdot>x = csnd\<cdot>y)"
   275 by (auto simp add: po_eq_conv less_cprod)
   276 
   277 lemma compact_cpair [simp]: "\<lbrakk>compact x; compact y\<rbrakk> \<Longrightarrow> compact <x, y>"
   278 by (rule compactI, simp add: less_cprod)
   279 
   280 lemma lub_cprod2: 
   281   "chain S \<Longrightarrow> range S <<| <\<Squnion>i. cfst\<cdot>(S i), \<Squnion>i. csnd\<cdot>(S i)>"
   282 apply (simp add: cpair_eq_pair cfst_def csnd_def cont_fst cont_snd)
   283 apply (erule lub_cprod)
   284 done
   285 
   286 lemma thelub_cprod2:
   287   "chain S \<Longrightarrow> lub (range S) = <\<Squnion>i. cfst\<cdot>(S i), \<Squnion>i. csnd\<cdot>(S i)>"
   288 by (rule lub_cprod2 [THEN thelubI])
   289 
   290 lemma csplit1 [simp]: "csplit\<cdot>f\<cdot>\<bottom> = f\<cdot>\<bottom>\<cdot>\<bottom>"
   291 by (simp add: csplit_def)
   292 
   293 lemma csplit2 [simp]: "csplit\<cdot>f\<cdot><x,y> = f\<cdot>x\<cdot>y"
   294 by (simp add: csplit_def)
   295 
   296 lemma csplit3 [simp]: "csplit\<cdot>cpair\<cdot>z = z"
   297 by (simp add: csplit_def surjective_pairing_Cprod2)
   298 
   299 lemmas Cprod_rews = cfst_cpair csnd_cpair csplit2
   300 
   301 end