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