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