src/HOLCF/Pcpo.thy
author huffman
Mon May 11 08:28:09 2009 -0700 (2009-05-11)
changeset 31095 b79d140f6d0b
parent 31076 99fe356cbbc2
child 33523 96730ad673be
permissions -rw-r--r--
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
slotosch@2640
     1
(*  Title:      HOLCF/Pcpo.thy
slotosch@2640
     2
    Author:     Franz Regensburger
slotosch@2640
     3
*)
huffman@15576
     4
huffman@15576
     5
header {* Classes cpo and pcpo *}
huffman@15576
     6
huffman@15577
     7
theory Pcpo
huffman@15577
     8
imports Porder
huffman@15577
     9
begin
nipkow@243
    10
huffman@15588
    11
subsection {* Complete partial orders *}
huffman@15588
    12
huffman@15588
    13
text {* The class cpo of chain complete partial orders *}
huffman@15588
    14
haftmann@29614
    15
class cpo = po +
haftmann@31071
    16
  assumes cpo: "chain S \<Longrightarrow> \<exists>x. range S <<| x"
haftmann@31071
    17
begin
oheimb@2394
    18
huffman@15588
    19
text {* in cpo's everthing equal to THE lub has lub properties for every chain *}
huffman@15563
    20
haftmann@31071
    21
lemma cpo_lubI: "chain S \<Longrightarrow> range S <<| (\<Squnion>i. S i)"
haftmann@31071
    22
  by (fast dest: cpo elim: lubI)
huffman@26026
    23
haftmann@31071
    24
lemma thelubE: "\<lbrakk>chain S; (\<Squnion>i. S i) = l\<rbrakk> \<Longrightarrow> range S <<| l"
haftmann@31071
    25
  by (blast dest: cpo intro: lubI)
huffman@15563
    26
huffman@15588
    27
text {* Properties of the lub *}
huffman@15563
    28
haftmann@31071
    29
lemma is_ub_thelub: "chain S \<Longrightarrow> S x \<sqsubseteq> (\<Squnion>i. S i)"
haftmann@31071
    30
  by (blast dest: cpo intro: lubI [THEN is_ub_lub])
huffman@15563
    31
huffman@16626
    32
lemma is_lub_thelub:
haftmann@31071
    33
  "\<lbrakk>chain S; range S <| x\<rbrakk> \<Longrightarrow> (\<Squnion>i. S i) \<sqsubseteq> x"
haftmann@31071
    34
  by (blast dest: cpo intro: lubI [THEN is_lub_lub])
huffman@15563
    35
huffman@16626
    36
lemma lub_range_mono:
haftmann@31071
    37
  "\<lbrakk>range X \<subseteq> range Y; chain Y; chain X\<rbrakk>
huffman@16626
    38
    \<Longrightarrow> (\<Squnion>i. X i) \<sqsubseteq> (\<Squnion>i. Y i)"
huffman@15563
    39
apply (erule is_lub_thelub)
huffman@15563
    40
apply (rule ub_rangeI)
huffman@16626
    41
apply (subgoal_tac "\<exists>j. X i = Y j")
huffman@15563
    42
apply  clarsimp
huffman@15563
    43
apply  (erule is_ub_thelub)
huffman@15563
    44
apply auto
huffman@15563
    45
done
huffman@15563
    46
huffman@16626
    47
lemma lub_range_shift:
haftmann@31071
    48
  "chain Y \<Longrightarrow> (\<Squnion>i. Y (i + j)) = (\<Squnion>i. Y i)"
huffman@31076
    49
apply (rule below_antisym)
huffman@15563
    50
apply (rule lub_range_mono)
huffman@15563
    51
apply    fast
huffman@15563
    52
apply   assumption
huffman@15563
    53
apply (erule chain_shift)
huffman@15563
    54
apply (rule is_lub_thelub)
huffman@15563
    55
apply assumption
huffman@15563
    56
apply (rule ub_rangeI)
huffman@31076
    57
apply (rule_tac y="Y (i + j)" in below_trans)
huffman@25922
    58
apply (erule chain_mono)
huffman@15563
    59
apply (rule le_add1)
huffman@17813
    60
apply (rule is_ub_thelub)
huffman@17813
    61
apply (erule chain_shift)
huffman@15563
    62
done
huffman@15563
    63
huffman@16626
    64
lemma maxinch_is_thelub:
haftmann@31071
    65
  "chain Y \<Longrightarrow> max_in_chain i Y = ((\<Squnion>i. Y i) = Y i)"
huffman@15563
    66
apply (rule iffI)
huffman@15563
    67
apply (fast intro!: thelubI lub_finch1)
huffman@15563
    68
apply (unfold max_in_chain_def)
huffman@31076
    69
apply (safe intro!: below_antisym)
huffman@25922
    70
apply (fast elim!: chain_mono)
huffman@15563
    71
apply (drule sym)
huffman@15563
    72
apply (force elim!: is_ub_thelub)
huffman@15563
    73
done
huffman@15563
    74
huffman@16626
    75
text {* the @{text "\<sqsubseteq>"} relation between two chains is preserved by their lubs *}
huffman@15563
    76
huffman@16626
    77
lemma lub_mono:
haftmann@31071
    78
  "\<lbrakk>chain X; chain Y; \<And>i. X i \<sqsubseteq> Y i\<rbrakk> 
huffman@16626
    79
    \<Longrightarrow> (\<Squnion>i. X i) \<sqsubseteq> (\<Squnion>i. Y i)"
huffman@15563
    80
apply (erule is_lub_thelub)
huffman@15563
    81
apply (rule ub_rangeI)
huffman@31076
    82
apply (rule below_trans)
huffman@25923
    83
apply (erule meta_spec)
huffman@15563
    84
apply (erule is_ub_thelub)
huffman@15563
    85
done
huffman@15563
    86
huffman@15588
    87
text {* the = relation between two chains is preserved by their lubs *}
huffman@15563
    88
huffman@16626
    89
lemma lub_equal:
haftmann@31071
    90
  "\<lbrakk>chain X; chain Y; \<forall>k. X k = Y k\<rbrakk>
huffman@16626
    91
    \<Longrightarrow> (\<Squnion>i. X i) = (\<Squnion>i. Y i)"
haftmann@31071
    92
  by (simp only: expand_fun_eq [symmetric])
huffman@15563
    93
huffman@15588
    94
text {* more results about mono and = of lubs of chains *}
slotosch@3326
    95
huffman@16626
    96
lemma lub_mono2:
haftmann@31071
    97
  "\<lbrakk>\<exists>j. \<forall>i>j. X i = Y i; chain X; chain Y\<rbrakk>
huffman@16626
    98
    \<Longrightarrow> (\<Squnion>i. X i) \<sqsubseteq> (\<Squnion>i. Y i)"
huffman@15563
    99
apply (erule exE)
huffman@17813
   100
apply (subgoal_tac "(\<Squnion>i. X (i + Suc j)) \<sqsubseteq> (\<Squnion>i. Y (i + Suc j))")
huffman@17813
   101
apply (thin_tac "\<forall>i>j. X i = Y i")
huffman@17813
   102
apply (simp only: lub_range_shift)
huffman@16626
   103
apply simp
huffman@15563
   104
done
huffman@15563
   105
huffman@16626
   106
lemma lub_equal2:
haftmann@31071
   107
  "\<lbrakk>\<exists>j. \<forall>i>j. X i = Y i; chain X; chain Y\<rbrakk>
huffman@16626
   108
    \<Longrightarrow> (\<Squnion>i. X i) = (\<Squnion>i. Y i)"
huffman@31076
   109
  by (blast intro: below_antisym lub_mono2 sym)
huffman@15563
   110
huffman@16626
   111
lemma lub_mono3:
haftmann@31071
   112
  "\<lbrakk>chain Y; chain X; \<forall>i. \<exists>j. Y i \<sqsubseteq> X j\<rbrakk>
huffman@16626
   113
    \<Longrightarrow> (\<Squnion>i. Y i) \<sqsubseteq> (\<Squnion>i. X i)"
huffman@17813
   114
apply (erule is_lub_thelub)
huffman@15563
   115
apply (rule ub_rangeI)
huffman@15563
   116
apply (erule allE)
huffman@15563
   117
apply (erule exE)
huffman@31076
   118
apply (erule below_trans)
huffman@16626
   119
apply (erule is_ub_thelub)
huffman@15563
   120
done
huffman@15563
   121
huffman@16203
   122
lemma ch2ch_lub:
huffman@16203
   123
  assumes 1: "\<And>j. chain (\<lambda>i. Y i j)"
huffman@16203
   124
  assumes 2: "\<And>i. chain (\<lambda>j. Y i j)"
huffman@16203
   125
  shows "chain (\<lambda>i. \<Squnion>j. Y i j)"
huffman@16203
   126
apply (rule chainI)
huffman@25923
   127
apply (rule lub_mono [OF 2 2])
huffman@16203
   128
apply (rule chainE [OF 1])
huffman@16203
   129
done
huffman@16203
   130
huffman@16201
   131
lemma diag_lub:
huffman@16201
   132
  assumes 1: "\<And>j. chain (\<lambda>i. Y i j)"
huffman@16201
   133
  assumes 2: "\<And>i. chain (\<lambda>j. Y i j)"
huffman@16201
   134
  shows "(\<Squnion>i. \<Squnion>j. Y i j) = (\<Squnion>i. Y i i)"
huffman@31076
   135
proof (rule below_antisym)
huffman@16201
   136
  have 3: "chain (\<lambda>i. Y i i)"
huffman@16201
   137
    apply (rule chainI)
huffman@31076
   138
    apply (rule below_trans)
huffman@16201
   139
    apply (rule chainE [OF 1])
huffman@16201
   140
    apply (rule chainE [OF 2])
huffman@16201
   141
    done
huffman@16201
   142
  have 4: "chain (\<lambda>i. \<Squnion>j. Y i j)"
huffman@16203
   143
    by (rule ch2ch_lub [OF 1 2])
huffman@16201
   144
  show "(\<Squnion>i. \<Squnion>j. Y i j) \<sqsubseteq> (\<Squnion>i. Y i i)"
huffman@16201
   145
    apply (rule is_lub_thelub [OF 4])
huffman@16201
   146
    apply (rule ub_rangeI)
huffman@16203
   147
    apply (rule lub_mono3 [rule_format, OF 2 3])
huffman@16201
   148
    apply (rule exI)
huffman@31076
   149
    apply (rule below_trans)
huffman@25922
   150
    apply (rule chain_mono [OF 1 le_maxI1])
huffman@25922
   151
    apply (rule chain_mono [OF 2 le_maxI2])
huffman@16201
   152
    done
huffman@16201
   153
  show "(\<Squnion>i. Y i i) \<sqsubseteq> (\<Squnion>i. \<Squnion>j. Y i j)"
huffman@25923
   154
    apply (rule lub_mono [OF 3 4])
huffman@16201
   155
    apply (rule is_ub_thelub [OF 2])
huffman@16201
   156
    done
huffman@16201
   157
qed
huffman@16201
   158
huffman@16201
   159
lemma ex_lub:
huffman@16201
   160
  assumes 1: "\<And>j. chain (\<lambda>i. Y i j)"
huffman@16201
   161
  assumes 2: "\<And>i. chain (\<lambda>j. Y i j)"
huffman@16201
   162
  shows "(\<Squnion>i. \<Squnion>j. Y i j) = (\<Squnion>j. \<Squnion>i. Y i j)"
haftmann@31071
   163
  by (simp add: diag_lub 1 2)
huffman@16201
   164
haftmann@31071
   165
end
huffman@16201
   166
huffman@15588
   167
subsection {* Pointed cpos *}
huffman@15588
   168
huffman@15588
   169
text {* The class pcpo of pointed cpos *}
huffman@15588
   170
haftmann@29614
   171
class pcpo = cpo +
haftmann@29614
   172
  assumes least: "\<exists>x. \<forall>y. x \<sqsubseteq> y"
haftmann@31071
   173
begin
huffman@25723
   174
haftmann@31071
   175
definition UU :: 'a where
huffman@25723
   176
  "UU = (THE x. \<forall>y. x \<sqsubseteq> y)"
huffman@25723
   177
huffman@25723
   178
notation (xsymbols)
huffman@25723
   179
  UU  ("\<bottom>")
huffman@25723
   180
huffman@25723
   181
text {* derive the old rule minimal *}
huffman@25723
   182
 
huffman@25723
   183
lemma UU_least: "\<forall>z. \<bottom> \<sqsubseteq> z"
huffman@25723
   184
apply (unfold UU_def)
huffman@25723
   185
apply (rule theI')
huffman@25723
   186
apply (rule ex_ex1I)
huffman@25723
   187
apply (rule least)
huffman@31076
   188
apply (blast intro: below_antisym)
huffman@25723
   189
done
huffman@25723
   190
huffman@25723
   191
lemma minimal [iff]: "\<bottom> \<sqsubseteq> x"
huffman@25723
   192
by (rule UU_least [THEN spec])
huffman@25723
   193
haftmann@31071
   194
end
haftmann@31071
   195
huffman@31024
   196
text {* Simproc to rewrite @{term "\<bottom> = x"} to @{term "x = \<bottom>"}. *}
huffman@16739
   197
huffman@31024
   198
setup {*
huffman@31024
   199
  ReorientProc.add
huffman@31024
   200
    (fn Const(@{const_name UU}, _) => true | _ => false)
huffman@31024
   201
*}
huffman@25723
   202
huffman@31024
   203
simproc_setup reorient_bottom ("\<bottom> = x") = ReorientProc.proc
huffman@25723
   204
haftmann@31071
   205
context pcpo
haftmann@31071
   206
begin
haftmann@31071
   207
huffman@25723
   208
text {* useful lemmas about @{term \<bottom>} *}
huffman@25723
   209
huffman@31076
   210
lemma below_UU_iff [simp]: "(x \<sqsubseteq> \<bottom>) = (x = \<bottom>)"
huffman@25723
   211
by (simp add: po_eq_conv)
huffman@25723
   212
huffman@25723
   213
lemma eq_UU_iff: "(x = \<bottom>) = (x \<sqsubseteq> \<bottom>)"
huffman@25723
   214
by simp
huffman@25723
   215
huffman@25723
   216
lemma UU_I: "x \<sqsubseteq> \<bottom> \<Longrightarrow> x = \<bottom>"
huffman@25723
   217
by (subst eq_UU_iff)
huffman@25723
   218
huffman@25723
   219
lemma chain_UU_I: "\<lbrakk>chain Y; (\<Squnion>i. Y i) = \<bottom>\<rbrakk> \<Longrightarrow> \<forall>i. Y i = \<bottom>"
huffman@15563
   220
apply (rule allI)
huffman@16626
   221
apply (rule UU_I)
huffman@15563
   222
apply (erule subst)
huffman@15563
   223
apply (erule is_ub_thelub)
huffman@15563
   224
done
huffman@15563
   225
huffman@16626
   226
lemma chain_UU_I_inverse: "\<forall>i::nat. Y i = \<bottom> \<Longrightarrow> (\<Squnion>i. Y i) = \<bottom>"
huffman@15563
   227
apply (rule lub_chain_maxelem)
huffman@15563
   228
apply (erule spec)
huffman@15588
   229
apply simp
huffman@15563
   230
done
huffman@15563
   231
huffman@16626
   232
lemma chain_UU_I_inverse2: "(\<Squnion>i. Y i) \<noteq> \<bottom> \<Longrightarrow> \<exists>i::nat. Y i \<noteq> \<bottom>"
haftmann@31071
   233
  by (blast intro: chain_UU_I_inverse)
huffman@15563
   234
huffman@16626
   235
lemma notUU_I: "\<lbrakk>x \<sqsubseteq> y; x \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> y \<noteq> \<bottom>"
haftmann@31071
   236
  by (blast intro: UU_I)
huffman@15563
   237
huffman@16627
   238
lemma chain_mono2: "\<lbrakk>\<exists>j. Y j \<noteq> \<bottom>; chain Y\<rbrakk> \<Longrightarrow> \<exists>j. \<forall>i>j. Y i \<noteq> \<bottom>"
haftmann@31071
   239
  by (blast dest: notUU_I chain_mono_less)
haftmann@31071
   240
haftmann@31071
   241
end
huffman@15588
   242
huffman@15588
   243
subsection {* Chain-finite and flat cpos *}
huffman@15563
   244
huffman@15588
   245
text {* further useful classes for HOLCF domains *}
huffman@15588
   246
haftmann@31071
   247
class chfin = po +
haftmann@31071
   248
  assumes chfin: "chain Y \<Longrightarrow> \<exists>n. max_in_chain n Y"
haftmann@31071
   249
begin
huffman@25814
   250
haftmann@31071
   251
subclass cpo
haftmann@31071
   252
apply default
haftmann@31071
   253
apply (frule chfin)
haftmann@31071
   254
apply (blast intro: lub_finch1)
haftmann@31071
   255
done
huffman@15563
   256
haftmann@31071
   257
lemma chfin2finch: "chain Y \<Longrightarrow> finite_chain Y"
haftmann@31071
   258
  by (simp add: chfin finite_chain_def)
haftmann@31071
   259
haftmann@31071
   260
end
huffman@15588
   261
haftmann@31071
   262
class finite_po = finite + po
haftmann@31071
   263
begin
huffman@25814
   264
haftmann@31071
   265
subclass chfin
haftmann@31071
   266
apply default
huffman@25814
   267
apply (drule finite_range_imp_finch)
huffman@25814
   268
apply (rule finite)
huffman@25814
   269
apply (simp add: finite_chain_def)
huffman@25814
   270
done
huffman@25814
   271
haftmann@31071
   272
end
huffman@15640
   273
haftmann@31071
   274
class flat = pcpo +
haftmann@31071
   275
  assumes ax_flat: "x \<sqsubseteq> y \<Longrightarrow> x = \<bottom> \<or> x = y"
haftmann@31071
   276
begin
huffman@15640
   277
haftmann@31071
   278
subclass chfin
haftmann@31071
   279
apply default
huffman@15563
   280
apply (unfold max_in_chain_def)
huffman@16626
   281
apply (case_tac "\<forall>i. Y i = \<bottom>")
huffman@15588
   282
apply simp
huffman@15563
   283
apply simp
huffman@15563
   284
apply (erule exE)
huffman@16626
   285
apply (rule_tac x="i" in exI)
huffman@15588
   286
apply clarify
huffman@25922
   287
apply (blast dest: chain_mono ax_flat)
huffman@15563
   288
done
huffman@15563
   289
huffman@31076
   290
lemma flat_below_iff:
huffman@25826
   291
  shows "(x \<sqsubseteq> y) = (x = \<bottom> \<or> x = y)"
haftmann@31071
   292
  by (safe dest!: ax_flat)
huffman@25826
   293
haftmann@31071
   294
lemma flat_eq: "a \<noteq> \<bottom> \<Longrightarrow> a \<sqsubseteq> b = (a = b)"
haftmann@31071
   295
  by (safe dest!: ax_flat)
huffman@15563
   296
haftmann@31071
   297
end
huffman@15563
   298
huffman@26023
   299
text {* Discrete cpos *}
huffman@26023
   300
huffman@31076
   301
class discrete_cpo = below +
haftmann@29614
   302
  assumes discrete_cpo [simp]: "x \<sqsubseteq> y \<longleftrightarrow> x = y"
haftmann@31071
   303
begin
huffman@26023
   304
haftmann@31071
   305
subclass po
haftmann@29614
   306
proof qed simp_all
huffman@26023
   307
huffman@26023
   308
text {* In a discrete cpo, every chain is constant *}
huffman@26023
   309
huffman@26023
   310
lemma discrete_chain_const:
haftmann@31071
   311
  assumes S: "chain S"
huffman@26023
   312
  shows "\<exists>x. S = (\<lambda>i. x)"
huffman@26023
   313
proof (intro exI ext)
huffman@26023
   314
  fix i :: nat
huffman@26023
   315
  have "S 0 \<sqsubseteq> S i" using S le0 by (rule chain_mono)
huffman@26023
   316
  hence "S 0 = S i" by simp
huffman@26023
   317
  thus "S i = S 0" by (rule sym)
huffman@26023
   318
qed
huffman@26023
   319
haftmann@31071
   320
subclass cpo
huffman@26023
   321
proof
huffman@26023
   322
  fix S :: "nat \<Rightarrow> 'a"
huffman@26023
   323
  assume S: "chain S"
huffman@26023
   324
  hence "\<exists>x. S = (\<lambda>i. x)"
huffman@26023
   325
    by (rule discrete_chain_const)
huffman@26023
   326
  thus "\<exists>x. range S <<| x"
huffman@26023
   327
    by (fast intro: lub_const)
huffman@26023
   328
qed
huffman@26023
   329
haftmann@31071
   330
end
huffman@15576
   331
huffman@16626
   332
end