src/HOLCF/Cprod.thy
author huffman
Thu May 26 02:23:27 2005 +0200 (2005-05-26)
changeset 16081 81a4b4a245b0
parent 16070 4a83dd540b88
child 16093 cdcbf5a7f38d
permissions -rw-r--r--
cleaned up, added cpair_less and cpair_eq_pair, removed some obsolete stuff
     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 (rule conjI)
    53 apply (fast intro: trans_less)
    54 apply (fast intro: trans_less)
    55 done
    56 
    57 instance "*" :: (cpo, cpo) po
    58 by intro_classes
    59   (assumption | rule refl_less_cprod antisym_less_cprod trans_less_cprod)+
    60 
    61 
    62 subsection {* Monotonicity of @{text "(_,_)"}, @{term fst}, @{term snd} *}
    63 
    64 text {* Pair @{text "(_,_)"}  is monotone in both arguments *}
    65 
    66 lemma monofun_pair1: "monofun (\<lambda>x. (x, y))"
    67 by (simp add: monofun less_cprod_def)
    68 
    69 lemma monofun_pair2: "monofun (\<lambda>y. (x, y))"
    70 by (simp add: monofun less_cprod_def)
    71 
    72 lemma monofun_pair:
    73   "\<lbrakk>x1 \<sqsubseteq> x2; y1 \<sqsubseteq> y2\<rbrakk> \<Longrightarrow> (x1, y1) \<sqsubseteq> (x2, y2)"
    74 by (simp add: less_cprod_def)
    75 
    76 text {* @{term fst} and @{term snd} are monotone *}
    77 
    78 lemma monofun_fst: "monofun fst"
    79 by (simp add: monofun less_cprod_def)
    80 
    81 lemma monofun_snd: "monofun snd"
    82 by (simp add: monofun less_cprod_def)
    83 
    84 subsection {* Type @{typ "'a * 'b"} is a cpo *}
    85 
    86 lemma lub_cprod: 
    87 "chain S \<Longrightarrow> range S <<| (\<Squnion>i. fst (S i), \<Squnion>i. snd (S i))"
    88 apply (rule is_lubI)
    89 apply (rule ub_rangeI)
    90 apply (rule_tac t = "S i" in surjective_pairing [THEN ssubst])
    91 apply (rule monofun_pair)
    92 apply (rule is_ub_thelub)
    93 apply (erule monofun_fst [THEN ch2ch_monofun])
    94 apply (rule is_ub_thelub)
    95 apply (erule monofun_snd [THEN ch2ch_monofun])
    96 apply (rule_tac t = "u" in surjective_pairing [THEN ssubst])
    97 apply (rule monofun_pair)
    98 apply (rule is_lub_thelub)
    99 apply (erule monofun_fst [THEN ch2ch_monofun])
   100 apply (erule monofun_fst [THEN ub2ub_monofun])
   101 apply (rule is_lub_thelub)
   102 apply (erule monofun_snd [THEN ch2ch_monofun])
   103 apply (erule monofun_snd [THEN ub2ub_monofun])
   104 done
   105 
   106 lemma thelub_cprod:
   107   "chain S \<Longrightarrow> lub (range S) = (\<Squnion>i. fst (S i), \<Squnion>i. snd (S i))"
   108 by (rule lub_cprod [THEN thelubI])
   109 
   110 lemma cpo_cprod:
   111   "chain (S::nat \<Rightarrow> 'a::cpo * 'b::cpo) \<Longrightarrow> \<exists>x. range S <<| x"
   112 by (rule exI, erule lub_cprod)
   113 
   114 instance "*" :: (cpo, cpo) cpo
   115 by intro_classes (rule cpo_cprod)
   116 
   117 subsection {* Type @{typ "'a * 'b"} is pointed *}
   118 
   119 lemma minimal_cprod: "(\<bottom>, \<bottom>) \<sqsubseteq> p"
   120 by (simp add: less_cprod_def)
   121 
   122 lemma least_cprod: "EX x::'a::pcpo * 'b::pcpo. ALL y. x \<sqsubseteq> y"
   123 apply (rule_tac x = "(\<bottom>, \<bottom>)" in exI)
   124 apply (rule minimal_cprod [THEN allI])
   125 done
   126 
   127 instance "*" :: (pcpo, pcpo) pcpo
   128 by intro_classes (rule least_cprod)
   129 
   130 text {* for compatibility with old HOLCF-Version *}
   131 lemma inst_cprod_pcpo: "UU = (UU,UU)"
   132 by (rule minimal_cprod [THEN UU_I, symmetric])
   133 
   134 
   135 subsection {* Continuity of @{text "(_,_)"}, @{term fst}, @{term snd} *}
   136 
   137 lemma contlub_pair1: "contlub (\<lambda>x. (x,y))"
   138 apply (rule contlubI [rule_format])
   139 apply (subst thelub_cprod)
   140 apply (erule monofun_pair1 [THEN ch2ch_monofun])
   141 apply (simp add: lub_const [THEN thelubI])
   142 done
   143 
   144 lemma contlub_pair2: "contlub (\<lambda>y. (x, y))"
   145 apply (rule contlubI [rule_format])
   146 apply (subst thelub_cprod)
   147 apply (erule monofun_pair2 [THEN ch2ch_monofun])
   148 apply (simp add: lub_const [THEN thelubI])
   149 done
   150 
   151 lemma cont_pair1: "cont (\<lambda>x. (x, y))"
   152 apply (rule monocontlub2cont)
   153 apply (rule monofun_pair1)
   154 apply (rule contlub_pair1)
   155 done
   156 
   157 lemma cont_pair2: "cont (\<lambda>y. (x, y))"
   158 apply (rule monocontlub2cont)
   159 apply (rule monofun_pair2)
   160 apply (rule contlub_pair2)
   161 done
   162 
   163 lemma contlub_fst: "contlub fst"
   164 apply (rule contlubI [rule_format])
   165 apply (simp add: lub_cprod [THEN thelubI])
   166 done
   167 
   168 lemma contlub_snd: "contlub snd"
   169 apply (rule contlubI [rule_format])
   170 apply (simp add: lub_cprod [THEN thelubI])
   171 done
   172 
   173 lemma cont_fst: "cont fst"
   174 apply (rule monocontlub2cont)
   175 apply (rule monofun_fst)
   176 apply (rule contlub_fst)
   177 done
   178 
   179 lemma cont_snd: "cont snd"
   180 apply (rule monocontlub2cont)
   181 apply (rule monofun_snd)
   182 apply (rule contlub_snd)
   183 done
   184 
   185 subsection {* Continuous versions of constants *}
   186 
   187 consts
   188   cpair  :: "'a \<rightarrow> 'b \<rightarrow> ('a * 'b)" (* continuous pairing *)
   189   cfst   :: "('a * 'b) \<rightarrow> 'a"
   190   csnd   :: "('a * 'b) \<rightarrow> 'b"
   191   csplit :: "('a \<rightarrow> 'b \<rightarrow> 'c) \<rightarrow> ('a * 'b) \<rightarrow> 'c"
   192 
   193 syntax
   194   "@ctuple" :: "['a, args] \<Rightarrow> 'a * 'b"  ("(1<_,/ _>)")
   195 
   196 translations
   197   "<x, y, z>" == "<x, <y, z>>"
   198   "<x, y>"    == "cpair$x$y"
   199 
   200 defs
   201   cpair_def:  "cpair  \<equiv> (\<Lambda> x y. (x, y))"
   202   cfst_def:   "cfst   \<equiv> (\<Lambda> p. fst p)"
   203   csnd_def:   "csnd   \<equiv> (\<Lambda> p. snd p)"      
   204   csplit_def: "csplit \<equiv> (\<Lambda> f p. f\<cdot>(cfst\<cdot>p)\<cdot>(csnd\<cdot>p))"
   205 
   206 subsection {* Syntax *}
   207 
   208 text {* syntax for @{text "LAM <x,y,z>.e"} *}
   209 
   210 syntax
   211   "_LAM" :: "[patterns, 'a \<Rightarrow> 'b] \<Rightarrow> ('a \<rightarrow> 'b)"  ("(3LAM <_>./ _)" [0, 10] 10)
   212 
   213 translations
   214   "LAM <x,y,zs>. b"       == "csplit$(LAM x. LAM <y,zs>. b)"
   215   "LAM <x,y>. LAM zs. b"  <= "csplit$(LAM x y zs. b)"
   216   "LAM <x,y>.b"           == "csplit$(LAM x y. b)"
   217 
   218 syntax (xsymbols)
   219   "_LAM" :: "[patterns, 'a => 'b] => ('a -> 'b)"  ("(3\<Lambda>()<_>./ _)" [0, 10] 10)
   220 
   221 text {* syntax for Let *}
   222 
   223 constdefs
   224   CLet :: "'a \<rightarrow> ('a \<rightarrow> 'b) \<rightarrow> 'b"
   225   "CLet \<equiv> \<Lambda> s f. f\<cdot>s"
   226 
   227 nonterminals
   228   Cletbinds  Cletbind
   229 
   230 syntax
   231   "_Cbind"  :: "[pttrn, 'a] => Cletbind"             ("(2_ =/ _)" 10)
   232   "_Cbindp" :: "[patterns, 'a] => Cletbind"          ("(2<_> =/ _)" 10)
   233   ""        :: "Cletbind => Cletbinds"               ("_")
   234   "_Cbinds" :: "[Cletbind, Cletbinds] => Cletbinds"  ("_;/ _")
   235   "_CLet"   :: "[Cletbinds, 'a] => 'a"               ("(Let (_)/ in (_))" 10)
   236 
   237 translations
   238   "_CLet (_Cbinds b bs) e"  == "_CLet b (_CLet bs e)"
   239   "Let x = a in LAM ys. e"  == "CLet$a$(LAM x ys. e)"
   240   "Let x = a in e"          == "CLet$a$(LAM x. e)"
   241   "Let <xs> = a in e"       == "CLet$a$(LAM <xs>. e)"
   242 
   243 subsection {* Convert all lemmas to the continuous versions *}
   244 
   245 lemma cpair_eq_pair: "<x, y> = (x, y)"
   246 by (simp add: cpair_def cont_pair1 cont_pair2)
   247 
   248 lemma inject_cpair: "<a,b> = <aa,ba> \<Longrightarrow> a = aa \<and> b = ba"
   249 by (simp add: cpair_eq_pair)
   250 
   251 lemma cpair_eq [iff]: "(<a, b> = <a', b'>) = (a = a' \<and> b = b')"
   252 by (simp add: cpair_eq_pair)
   253 
   254 lemma cpair_less: "(<a, b> \<sqsubseteq> <a', b'>) = (a \<sqsubseteq> a' \<and> b \<sqsubseteq> b')"
   255 by (simp add: cpair_eq_pair less_cprod_def)
   256 
   257 lemma inst_cprod_pcpo2: "\<bottom> = <\<bottom>, \<bottom>>"
   258 by (simp add: cpair_eq_pair inst_cprod_pcpo)
   259 
   260 lemma defined_cpair_rev: 
   261  "<a,b> = \<bottom> \<Longrightarrow> a = \<bottom> \<and> b = \<bottom>"
   262 by (simp add: inst_cprod_pcpo cpair_eq_pair)
   263 
   264 lemma Exh_Cprod2: "\<exists>a b. z = <a, b>"
   265 by (simp add: cpair_eq_pair)
   266 
   267 lemma cprodE: "\<lbrakk>\<And>x y. p = <x, y> \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
   268 by (cut_tac Exh_Cprod2, auto)
   269 
   270 lemma cfst2 [simp]: "cfst\<cdot><x, y> = x"
   271 by (simp add: cpair_eq_pair cfst_def cont_fst)
   272 
   273 lemma csnd2 [simp]: "csnd\<cdot><x, y> = y"
   274 by (simp add: cpair_eq_pair csnd_def cont_snd)
   275 
   276 lemma cfst_strict [simp]: "cfst\<cdot>\<bottom> = \<bottom>"
   277 by (simp add: inst_cprod_pcpo2)
   278 
   279 lemma csnd_strict [simp]: "csnd\<cdot>\<bottom> = \<bottom>"
   280 by (simp add: inst_cprod_pcpo2)
   281 
   282 lemma surjective_pairing_Cprod2: "<cfst\<cdot>p, csnd\<cdot>p> = p"
   283 apply (unfold cfst_def csnd_def)
   284 apply (simp add: cont_fst cont_snd cpair_eq_pair)
   285 done
   286 
   287 lemma lub_cprod2: 
   288   "chain S \<Longrightarrow> range S <<| <\<Squnion>i. cfst\<cdot>(S i), \<Squnion>i. csnd\<cdot>(S i)>"
   289 apply (simp add: cpair_eq_pair cfst_def csnd_def cont_fst cont_snd)
   290 apply (erule lub_cprod)
   291 done
   292 
   293 lemma thelub_cprod2:
   294   "chain S \<Longrightarrow> lub (range S) = <\<Squnion>i. cfst\<cdot>(S i), \<Squnion>i. csnd\<cdot>(S i)>"
   295 by (rule lub_cprod2 [THEN thelubI])
   296 
   297 lemma csplit2 [simp]: "csplit\<cdot>f\<cdot><x,y> = f\<cdot>x\<cdot>y"
   298 by (simp add: csplit_def)
   299 
   300 lemma csplit3: "csplit\<cdot>cpair\<cdot>z = z"
   301 by (simp add: csplit_def surjective_pairing_Cprod2)
   302 
   303 lemmas Cprod_rews = cfst2 csnd2 csplit2
   304 
   305 end