src/HOLCF/Cprod.thy
author huffman
Thu Jan 03 22:10:52 2008 +0100 (2008-01-03)
changeset 25815 c7b1e7b7087b
parent 25784 71157f7e671e
child 25827 c2adeb1bae5c
permissions -rw-r--r--
instance unit :: finite_po
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@25784
    18
instantiation unit :: sq_ord
huffman@25784
    19
begin
huffman@16008
    20
huffman@25784
    21
definition
huffman@16008
    22
  less_unit_def [simp]: "x \<sqsubseteq> (y::unit) \<equiv> True"
huffman@16008
    23
huffman@25784
    24
instance ..
huffman@25784
    25
end
huffman@25784
    26
huffman@16008
    27
instance unit :: po
huffman@16008
    28
by intro_classes simp_all
huffman@16008
    29
huffman@25815
    30
instance unit :: finite_po ..
huffman@16008
    31
huffman@16008
    32
instance unit :: pcpo
huffman@16008
    33
by intro_classes simp
huffman@16008
    34
wenzelm@25131
    35
definition
wenzelm@25131
    36
  unit_when :: "'a \<rightarrow> unit \<rightarrow> 'a" where
wenzelm@25131
    37
  "unit_when = (\<Lambda> a _. a)"
huffman@16008
    38
huffman@18289
    39
translations
wenzelm@25131
    40
  "\<Lambda>(). t" == "CONST unit_when\<cdot>t"
huffman@18289
    41
huffman@18289
    42
lemma unit_when [simp]: "unit_when\<cdot>a\<cdot>u = a"
huffman@18289
    43
by (simp add: unit_when_def)
huffman@18289
    44
huffman@18289
    45
huffman@18289
    46
subsection {* Product type is a partial order *}
huffman@15593
    47
huffman@25784
    48
instantiation "*" :: (sq_ord, sq_ord) sq_ord
huffman@25784
    49
begin
huffman@15576
    50
huffman@25784
    51
definition
huffman@16081
    52
  less_cprod_def: "(op \<sqsubseteq>) \<equiv> \<lambda>p1 p2. (fst p1 \<sqsubseteq> fst p2 \<and> snd p1 \<sqsubseteq> snd p2)"
huffman@15576
    53
huffman@25784
    54
instance ..
huffman@25784
    55
end
huffman@15576
    56
huffman@25784
    57
instance "*" :: (po, po) po
huffman@25784
    58
proof
huffman@25784
    59
  fix x :: "'a \<times> 'b"
huffman@25784
    60
  show "x \<sqsubseteq> x"
huffman@25784
    61
    unfolding less_cprod_def by simp
huffman@25784
    62
next
huffman@25784
    63
  fix x y :: "'a \<times> 'b"
huffman@25784
    64
  assume "x \<sqsubseteq> y" "y \<sqsubseteq> x" thus "x = y"
huffman@25784
    65
    unfolding less_cprod_def Pair_fst_snd_eq
huffman@25784
    66
    by (fast intro: antisym_less)
huffman@25784
    67
next
huffman@25784
    68
  fix x y z :: "'a \<times> 'b"
huffman@25784
    69
  assume "x \<sqsubseteq> y" "y \<sqsubseteq> z" thus "x \<sqsubseteq> z"
huffman@25784
    70
    unfolding less_cprod_def
huffman@25784
    71
    by (fast intro: trans_less)
huffman@25784
    72
qed
huffman@15576
    73
huffman@15576
    74
huffman@15593
    75
subsection {* Monotonicity of @{text "(_,_)"}, @{term fst}, @{term snd} *}
huffman@15576
    76
huffman@15593
    77
text {* Pair @{text "(_,_)"}  is monotone in both arguments *}
huffman@15576
    78
huffman@16081
    79
lemma monofun_pair1: "monofun (\<lambda>x. (x, y))"
huffman@16210
    80
by (simp add: monofun_def less_cprod_def)
huffman@15576
    81
huffman@16081
    82
lemma monofun_pair2: "monofun (\<lambda>y. (x, y))"
huffman@16210
    83
by (simp add: monofun_def less_cprod_def)
huffman@15576
    84
huffman@16081
    85
lemma monofun_pair:
huffman@16081
    86
  "\<lbrakk>x1 \<sqsubseteq> x2; y1 \<sqsubseteq> y2\<rbrakk> \<Longrightarrow> (x1, y1) \<sqsubseteq> (x2, y2)"
huffman@16081
    87
by (simp add: less_cprod_def)
huffman@15576
    88
huffman@15593
    89
text {* @{term fst} and @{term snd} are monotone *}
huffman@15576
    90
huffman@15576
    91
lemma monofun_fst: "monofun fst"
huffman@16210
    92
by (simp add: monofun_def less_cprod_def)
huffman@15576
    93
huffman@15576
    94
lemma monofun_snd: "monofun snd"
huffman@16210
    95
by (simp add: monofun_def less_cprod_def)
huffman@15576
    96
huffman@18289
    97
subsection {* Product type is a cpo *}
huffman@15576
    98
huffman@25784
    99
lemma lub_cprod:
huffman@25784
   100
  fixes S :: "nat \<Rightarrow> ('a::cpo \<times> 'b::cpo)"
huffman@25784
   101
  assumes S: "chain S"
huffman@25784
   102
  shows "range S <<| (\<Squnion>i. fst (S i), \<Squnion>i. snd (S i))"
huffman@15576
   103
apply (rule is_lubI)
huffman@15576
   104
apply (rule ub_rangeI)
huffman@15576
   105
apply (rule_tac t = "S i" in surjective_pairing [THEN ssubst])
huffman@15576
   106
apply (rule monofun_pair)
huffman@15576
   107
apply (rule is_ub_thelub)
huffman@25784
   108
apply (rule ch2ch_monofun [OF monofun_fst S])
huffman@15576
   109
apply (rule is_ub_thelub)
huffman@25784
   110
apply (rule ch2ch_monofun [OF monofun_snd S])
huffman@15576
   111
apply (rule_tac t = "u" in surjective_pairing [THEN ssubst])
huffman@15576
   112
apply (rule monofun_pair)
huffman@15576
   113
apply (rule is_lub_thelub)
huffman@25784
   114
apply (rule ch2ch_monofun [OF monofun_fst S])
huffman@15576
   115
apply (erule monofun_fst [THEN ub2ub_monofun])
huffman@15576
   116
apply (rule is_lub_thelub)
huffman@25784
   117
apply (rule ch2ch_monofun [OF monofun_snd S])
huffman@15576
   118
apply (erule monofun_snd [THEN ub2ub_monofun])
huffman@15576
   119
done
huffman@15576
   120
huffman@25784
   121
lemma directed_lub_cprod:
huffman@25784
   122
  fixes S :: "('a::dcpo \<times> 'b::dcpo) set"
huffman@25784
   123
  assumes S: "directed S"
huffman@25784
   124
  shows "S <<| (\<Squnion>x\<in>S. fst x, \<Squnion>x\<in>S. snd x)"
huffman@25784
   125
apply (rule is_lubI)
huffman@25784
   126
apply (rule is_ubI)
huffman@25784
   127
apply (rule_tac t=x in surjective_pairing [THEN ssubst])
huffman@25784
   128
apply (rule monofun_pair)
huffman@25784
   129
apply (erule is_ub_thelub' [OF dir2dir_monofun [OF monofun_fst S] imageI])
huffman@25784
   130
apply (erule is_ub_thelub' [OF dir2dir_monofun [OF monofun_snd S] imageI])
huffman@25784
   131
apply (rule_tac t=u in surjective_pairing [THEN ssubst])
huffman@25784
   132
apply (rule monofun_pair)
huffman@25784
   133
apply (rule is_lub_thelub')
huffman@25784
   134
apply (rule dir2dir_monofun [OF monofun_fst S])
huffman@25784
   135
apply (erule ub2ub_monofun' [OF monofun_fst])
huffman@25784
   136
apply (rule is_lub_thelub')
huffman@25784
   137
apply (rule dir2dir_monofun [OF monofun_snd S])
huffman@25784
   138
apply (erule ub2ub_monofun' [OF monofun_snd])
huffman@25784
   139
done
huffman@25784
   140
huffman@16081
   141
lemma thelub_cprod:
huffman@25784
   142
  "chain (S::nat \<Rightarrow> 'a::cpo \<times> 'b::cpo)
huffman@25784
   143
    \<Longrightarrow> lub (range S) = (\<Squnion>i. fst (S i), \<Squnion>i. snd (S i))"
huffman@16081
   144
by (rule lub_cprod [THEN thelubI])
huffman@15576
   145
huffman@25784
   146
instance "*" :: (cpo, cpo) cpo
huffman@25784
   147
proof
huffman@25784
   148
  fix S :: "nat \<Rightarrow> ('a \<times> 'b)"
huffman@25784
   149
  assume "chain S"
huffman@25784
   150
  hence "range S <<| (\<Squnion>i. fst (S i), \<Squnion>i. snd (S i))"
huffman@25784
   151
    by (rule lub_cprod)
huffman@25784
   152
  thus "\<exists>x. range S <<| x" ..
huffman@25784
   153
qed
huffman@15593
   154
huffman@25784
   155
instance "*" :: (dcpo, dcpo) dcpo
huffman@25784
   156
proof
huffman@25784
   157
  fix S :: "('a \<times> 'b) set"
huffman@25784
   158
  assume "directed S"
huffman@25784
   159
  hence "S <<| (\<Squnion>x\<in>S. fst x, \<Squnion>x\<in>S. snd x)"
huffman@25784
   160
    by (rule directed_lub_cprod)
huffman@25784
   161
  thus "\<exists>x. S <<| x" ..
huffman@25784
   162
qed
huffman@15593
   163
huffman@18289
   164
subsection {* Product type is pointed *}
huffman@15593
   165
huffman@16081
   166
lemma minimal_cprod: "(\<bottom>, \<bottom>) \<sqsubseteq> p"
huffman@16081
   167
by (simp add: less_cprod_def)
huffman@15593
   168
huffman@16081
   169
lemma least_cprod: "EX x::'a::pcpo * 'b::pcpo. ALL y. x \<sqsubseteq> y"
huffman@16081
   170
apply (rule_tac x = "(\<bottom>, \<bottom>)" in exI)
huffman@15593
   171
apply (rule minimal_cprod [THEN allI])
huffman@15593
   172
done
huffman@15593
   173
huffman@15609
   174
instance "*" :: (pcpo, pcpo) pcpo
huffman@15593
   175
by intro_classes (rule least_cprod)
huffman@15593
   176
huffman@15593
   177
text {* for compatibility with old HOLCF-Version *}
huffman@15593
   178
lemma inst_cprod_pcpo: "UU = (UU,UU)"
huffman@16081
   179
by (rule minimal_cprod [THEN UU_I, symmetric])
huffman@16081
   180
huffman@15593
   181
huffman@15593
   182
subsection {* Continuity of @{text "(_,_)"}, @{term fst}, @{term snd} *}
huffman@15593
   183
huffman@16916
   184
lemma contlub_pair1: "contlub (\<lambda>x. (x, y))"
huffman@16210
   185
apply (rule contlubI)
huffman@15593
   186
apply (subst thelub_cprod)
huffman@15593
   187
apply (erule monofun_pair1 [THEN ch2ch_monofun])
huffman@18077
   188
apply simp
huffman@15576
   189
done
huffman@15576
   190
huffman@16081
   191
lemma contlub_pair2: "contlub (\<lambda>y. (x, y))"
huffman@16210
   192
apply (rule contlubI)
huffman@15593
   193
apply (subst thelub_cprod)
huffman@15593
   194
apply (erule monofun_pair2 [THEN ch2ch_monofun])
huffman@18077
   195
apply simp
huffman@15593
   196
done
huffman@15593
   197
huffman@16081
   198
lemma cont_pair1: "cont (\<lambda>x. (x, y))"
huffman@15593
   199
apply (rule monocontlub2cont)
huffman@15593
   200
apply (rule monofun_pair1)
huffman@15593
   201
apply (rule contlub_pair1)
huffman@15593
   202
done
huffman@15593
   203
huffman@16081
   204
lemma cont_pair2: "cont (\<lambda>y. (x, y))"
huffman@15593
   205
apply (rule monocontlub2cont)
huffman@15593
   206
apply (rule monofun_pair2)
huffman@15593
   207
apply (rule contlub_pair2)
huffman@15593
   208
done
huffman@15576
   209
huffman@16081
   210
lemma contlub_fst: "contlub fst"
huffman@16210
   211
apply (rule contlubI)
huffman@16210
   212
apply (simp add: thelub_cprod)
huffman@15593
   213
done
huffman@15593
   214
huffman@16081
   215
lemma contlub_snd: "contlub snd"
huffman@16210
   216
apply (rule contlubI)
huffman@16210
   217
apply (simp add: thelub_cprod)
huffman@15593
   218
done
huffman@15576
   219
huffman@16081
   220
lemma cont_fst: "cont fst"
huffman@15593
   221
apply (rule monocontlub2cont)
huffman@15593
   222
apply (rule monofun_fst)
huffman@15593
   223
apply (rule contlub_fst)
huffman@15593
   224
done
huffman@15593
   225
huffman@16081
   226
lemma cont_snd: "cont snd"
huffman@15593
   227
apply (rule monocontlub2cont)
huffman@15593
   228
apply (rule monofun_snd)
huffman@15593
   229
apply (rule contlub_snd)
huffman@15593
   230
done
huffman@15593
   231
huffman@15593
   232
subsection {* Continuous versions of constants *}
huffman@15576
   233
wenzelm@25131
   234
definition
wenzelm@25131
   235
  cpair :: "'a \<rightarrow> 'b \<rightarrow> ('a * 'b)"  -- {* continuous pairing *}  where
wenzelm@25131
   236
  "cpair = (\<Lambda> x y. (x, y))"
wenzelm@25131
   237
wenzelm@25131
   238
definition
wenzelm@25131
   239
  cfst :: "('a * 'b) \<rightarrow> 'a" where
wenzelm@25131
   240
  "cfst = (\<Lambda> p. fst p)"
huffman@17834
   241
wenzelm@25131
   242
definition
wenzelm@25131
   243
  csnd :: "('a * 'b) \<rightarrow> 'b" where
wenzelm@25131
   244
  "csnd = (\<Lambda> p. snd p)"      
huffman@17834
   245
wenzelm@25131
   246
definition
wenzelm@25131
   247
  csplit :: "('a \<rightarrow> 'b \<rightarrow> 'c) \<rightarrow> ('a * 'b) \<rightarrow> 'c" where
wenzelm@25131
   248
  "csplit = (\<Lambda> f p. f\<cdot>(cfst\<cdot>p)\<cdot>(csnd\<cdot>p))"
huffman@15576
   249
huffman@15576
   250
syntax
huffman@17834
   251
  "_ctuple" :: "['a, args] \<Rightarrow> 'a * 'b"  ("(1<_,/ _>)")
huffman@17834
   252
huffman@17834
   253
syntax (xsymbols)
huffman@17834
   254
  "_ctuple" :: "['a, args] \<Rightarrow> 'a * 'b"  ("(1\<langle>_,/ _\<rangle>)")
huffman@15576
   255
huffman@15576
   256
translations
huffman@18078
   257
  "\<langle>x, y, z\<rangle>" == "\<langle>x, \<langle>y, z\<rangle>\<rangle>"
wenzelm@25131
   258
  "\<langle>x, y\<rangle>"    == "CONST cpair\<cdot>x\<cdot>y"
huffman@17834
   259
huffman@17816
   260
translations
wenzelm@25131
   261
  "\<Lambda>(CONST cpair\<cdot>x\<cdot>y). t" == "CONST csplit\<cdot>(\<Lambda> x y. t)"
huffman@17816
   262
huffman@15576
   263
huffman@15593
   264
subsection {* Convert all lemmas to the continuous versions *}
huffman@15576
   265
huffman@16081
   266
lemma cpair_eq_pair: "<x, y> = (x, y)"
huffman@16081
   267
by (simp add: cpair_def cont_pair1 cont_pair2)
huffman@16081
   268
huffman@16081
   269
lemma inject_cpair: "<a,b> = <aa,ba> \<Longrightarrow> a = aa \<and> b = ba"
huffman@16081
   270
by (simp add: cpair_eq_pair)
huffman@15576
   271
huffman@16081
   272
lemma cpair_eq [iff]: "(<a, b> = <a', b'>) = (a = a' \<and> b = b')"
huffman@16081
   273
by (simp add: cpair_eq_pair)
huffman@15576
   274
huffman@18077
   275
lemma cpair_less [iff]: "(<a, b> \<sqsubseteq> <a', b'>) = (a \<sqsubseteq> a' \<and> b \<sqsubseteq> b')"
huffman@16081
   276
by (simp add: cpair_eq_pair less_cprod_def)
huffman@16057
   277
huffman@18077
   278
lemma cpair_defined_iff [iff]: "(<x, y> = \<bottom>) = (x = \<bottom> \<and> y = \<bottom>)"
huffman@16916
   279
by (simp add: inst_cprod_pcpo cpair_eq_pair)
huffman@16916
   280
huffman@16210
   281
lemma cpair_strict: "<\<bottom>, \<bottom>> = \<bottom>"
huffman@18077
   282
by simp
huffman@16210
   283
huffman@16081
   284
lemma inst_cprod_pcpo2: "\<bottom> = <\<bottom>, \<bottom>>"
huffman@16916
   285
by (rule cpair_strict [symmetric])
huffman@15576
   286
huffman@15576
   287
lemma defined_cpair_rev: 
huffman@16081
   288
 "<a,b> = \<bottom> \<Longrightarrow> a = \<bottom> \<and> b = \<bottom>"
huffman@18077
   289
by simp
huffman@16081
   290
huffman@16081
   291
lemma Exh_Cprod2: "\<exists>a b. z = <a, b>"
huffman@16081
   292
by (simp add: cpair_eq_pair)
huffman@16081
   293
huffman@16081
   294
lemma cprodE: "\<lbrakk>\<And>x y. p = <x, y> \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
huffman@16081
   295
by (cut_tac Exh_Cprod2, auto)
huffman@16081
   296
huffman@16210
   297
lemma cfst_cpair [simp]: "cfst\<cdot><x, y> = x"
huffman@16081
   298
by (simp add: cpair_eq_pair cfst_def cont_fst)
huffman@15576
   299
huffman@16210
   300
lemma csnd_cpair [simp]: "csnd\<cdot><x, y> = y"
huffman@16081
   301
by (simp add: cpair_eq_pair csnd_def cont_snd)
huffman@16081
   302
huffman@16081
   303
lemma cfst_strict [simp]: "cfst\<cdot>\<bottom> = \<bottom>"
huffman@16081
   304
by (simp add: inst_cprod_pcpo2)
huffman@16081
   305
huffman@16081
   306
lemma csnd_strict [simp]: "csnd\<cdot>\<bottom> = \<bottom>"
huffman@16081
   307
by (simp add: inst_cprod_pcpo2)
huffman@16081
   308
huffman@16081
   309
lemma surjective_pairing_Cprod2: "<cfst\<cdot>p, csnd\<cdot>p> = p"
huffman@16081
   310
apply (unfold cfst_def csnd_def)
huffman@16081
   311
apply (simp add: cont_fst cont_snd cpair_eq_pair)
huffman@15576
   312
done
huffman@15576
   313
huffman@16750
   314
lemma less_cprod: "x \<sqsubseteq> y = (cfst\<cdot>x \<sqsubseteq> cfst\<cdot>y \<and> csnd\<cdot>x \<sqsubseteq> csnd\<cdot>y)"
huffman@16315
   315
by (simp add: less_cprod_def cfst_def csnd_def cont_fst cont_snd)
huffman@16315
   316
huffman@16750
   317
lemma eq_cprod: "(x = y) = (cfst\<cdot>x = cfst\<cdot>y \<and> csnd\<cdot>x = csnd\<cdot>y)"
huffman@16750
   318
by (auto simp add: po_eq_conv less_cprod)
huffman@16750
   319
huffman@17837
   320
lemma compact_cpair [simp]: "\<lbrakk>compact x; compact y\<rbrakk> \<Longrightarrow> compact <x, y>"
huffman@17837
   321
by (rule compactI, simp add: less_cprod)
huffman@17837
   322
huffman@15576
   323
lemma lub_cprod2: 
huffman@16081
   324
  "chain S \<Longrightarrow> range S <<| <\<Squnion>i. cfst\<cdot>(S i), \<Squnion>i. csnd\<cdot>(S i)>"
huffman@16081
   325
apply (simp add: cpair_eq_pair cfst_def csnd_def cont_fst cont_snd)
huffman@15593
   326
apply (erule lub_cprod)
huffman@15576
   327
done
huffman@15576
   328
huffman@16081
   329
lemma thelub_cprod2:
huffman@16081
   330
  "chain S \<Longrightarrow> lub (range S) = <\<Squnion>i. cfst\<cdot>(S i), \<Squnion>i. csnd\<cdot>(S i)>"
huffman@16081
   331
by (rule lub_cprod2 [THEN thelubI])
huffman@15576
   332
huffman@18077
   333
lemma csplit1 [simp]: "csplit\<cdot>f\<cdot>\<bottom> = f\<cdot>\<bottom>\<cdot>\<bottom>"
huffman@18077
   334
by (simp add: csplit_def)
huffman@18077
   335
huffman@16081
   336
lemma csplit2 [simp]: "csplit\<cdot>f\<cdot><x,y> = f\<cdot>x\<cdot>y"
huffman@15593
   337
by (simp add: csplit_def)
huffman@15576
   338
huffman@16553
   339
lemma csplit3 [simp]: "csplit\<cdot>cpair\<cdot>z = z"
huffman@15593
   340
by (simp add: csplit_def surjective_pairing_Cprod2)
huffman@15576
   341
huffman@16210
   342
lemmas Cprod_rews = cfst_cpair csnd_cpair csplit2
huffman@15576
   343
huffman@15576
   344
end