src/HOL/HOLCF/Pcpo.thy
author blanchet
Tue Nov 07 15:16:42 2017 +0100 (20 months ago)
changeset 67022 49309fe530fd
parent 62175 8ffc4d0e652d
child 67312 0d25e02759b7
permissions -rw-r--r--
more robust parsing for THF proofs (esp. polymorphic Leo-III proofs)
wenzelm@42151
     1
(*  Title:      HOL/HOLCF/Pcpo.thy
slotosch@2640
     2
    Author:     Franz Regensburger
slotosch@2640
     3
*)
huffman@15576
     4
wenzelm@62175
     5
section \<open>Classes cpo and pcpo\<close>
huffman@15576
     6
huffman@15577
     7
theory Pcpo
huffman@15577
     8
imports Porder
huffman@15577
     9
begin
nipkow@243
    10
wenzelm@62175
    11
subsection \<open>Complete partial orders\<close>
huffman@15588
    12
wenzelm@62175
    13
text \<open>The class cpo of chain complete partial orders\<close>
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
wenzelm@62175
    19
text \<open>in cpo's everthing equal to THE lub has lub properties for every chain\<close>
huffman@15563
    20
haftmann@31071
    21
lemma cpo_lubI: "chain S \<Longrightarrow> range S <<| (\<Squnion>i. S i)"
huffman@40771
    22
  by (fast dest: cpo elim: is_lub_lub)
huffman@26026
    23
haftmann@31071
    24
lemma thelubE: "\<lbrakk>chain S; (\<Squnion>i. S i) = l\<rbrakk> \<Longrightarrow> range S <<| l"
huffman@40771
    25
  by (blast dest: cpo intro: is_lub_lub)
huffman@15563
    26
wenzelm@62175
    27
text \<open>Properties of the lub\<close>
huffman@15563
    28
haftmann@31071
    29
lemma is_ub_thelub: "chain S \<Longrightarrow> S x \<sqsubseteq> (\<Squnion>i. S i)"
huffman@40771
    30
  by (blast dest: cpo intro: is_lub_lub [THEN is_lub_rangeD1])
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"
huffman@40771
    34
  by (blast dest: cpo intro: is_lub_lub [THEN is_lubD2])
huffman@15563
    35
huffman@39969
    36
lemma lub_below_iff: "chain S \<Longrightarrow> (\<Squnion>i. S i) \<sqsubseteq> x \<longleftrightarrow> (\<forall>i. S i \<sqsubseteq> x)"
huffman@39969
    37
  by (simp add: is_lub_below_iff [OF cpo_lubI] is_ub_def)
huffman@39969
    38
huffman@40500
    39
lemma lub_below: "\<lbrakk>chain S; \<And>i. S i \<sqsubseteq> x\<rbrakk> \<Longrightarrow> (\<Squnion>i. S i) \<sqsubseteq> x"
huffman@40500
    40
  by (simp add: lub_below_iff)
huffman@40500
    41
huffman@40500
    42
lemma below_lub: "\<lbrakk>chain S; x \<sqsubseteq> S i\<rbrakk> \<Longrightarrow> x \<sqsubseteq> (\<Squnion>i. S i)"
huffman@40500
    43
  by (erule below_trans, erule is_ub_thelub)
huffman@40500
    44
huffman@16626
    45
lemma lub_range_mono:
haftmann@31071
    46
  "\<lbrakk>range X \<subseteq> range Y; chain Y; chain X\<rbrakk>
huffman@16626
    47
    \<Longrightarrow> (\<Squnion>i. X i) \<sqsubseteq> (\<Squnion>i. Y i)"
huffman@40500
    48
apply (erule lub_below)
huffman@16626
    49
apply (subgoal_tac "\<exists>j. X i = Y j")
huffman@15563
    50
apply  clarsimp
huffman@15563
    51
apply  (erule is_ub_thelub)
huffman@15563
    52
apply auto
huffman@15563
    53
done
huffman@15563
    54
huffman@16626
    55
lemma lub_range_shift:
haftmann@31071
    56
  "chain Y \<Longrightarrow> (\<Squnion>i. Y (i + j)) = (\<Squnion>i. Y i)"
huffman@31076
    57
apply (rule below_antisym)
huffman@15563
    58
apply (rule lub_range_mono)
huffman@15563
    59
apply    fast
huffman@15563
    60
apply   assumption
huffman@15563
    61
apply (erule chain_shift)
huffman@40500
    62
apply (rule lub_below)
huffman@15563
    63
apply assumption
huffman@40500
    64
apply (rule_tac i="i" in below_lub)
huffman@40500
    65
apply (erule chain_shift)
huffman@25922
    66
apply (erule chain_mono)
huffman@15563
    67
apply (rule le_add1)
huffman@15563
    68
done
huffman@15563
    69
huffman@16626
    70
lemma maxinch_is_thelub:
haftmann@31071
    71
  "chain Y \<Longrightarrow> max_in_chain i Y = ((\<Squnion>i. Y i) = Y i)"
huffman@15563
    72
apply (rule iffI)
huffman@40771
    73
apply (fast intro!: lub_eqI lub_finch1)
huffman@15563
    74
apply (unfold max_in_chain_def)
huffman@31076
    75
apply (safe intro!: below_antisym)
huffman@25922
    76
apply (fast elim!: chain_mono)
huffman@15563
    77
apply (drule sym)
huffman@15563
    78
apply (force elim!: is_ub_thelub)
huffman@15563
    79
done
huffman@15563
    80
wenzelm@62175
    81
text \<open>the \<open>\<sqsubseteq>\<close> relation between two chains is preserved by their lubs\<close>
huffman@15563
    82
huffman@16626
    83
lemma lub_mono:
haftmann@31071
    84
  "\<lbrakk>chain X; chain Y; \<And>i. X i \<sqsubseteq> Y i\<rbrakk> 
huffman@16626
    85
    \<Longrightarrow> (\<Squnion>i. X i) \<sqsubseteq> (\<Squnion>i. Y i)"
huffman@40500
    86
by (fast elim: lub_below below_lub)
huffman@15563
    87
wenzelm@62175
    88
text \<open>the = relation between two chains is preserved by their lubs\<close>
huffman@15563
    89
huffman@35492
    90
lemma lub_eq:
huffman@35492
    91
  "(\<And>i. X i = Y i) \<Longrightarrow> (\<Squnion>i. X i) = (\<Squnion>i. Y i)"
huffman@35492
    92
  by simp
huffman@35492
    93
huffman@16203
    94
lemma ch2ch_lub:
huffman@16203
    95
  assumes 1: "\<And>j. chain (\<lambda>i. Y i j)"
huffman@16203
    96
  assumes 2: "\<And>i. chain (\<lambda>j. Y i j)"
huffman@16203
    97
  shows "chain (\<lambda>i. \<Squnion>j. Y i j)"
huffman@16203
    98
apply (rule chainI)
huffman@25923
    99
apply (rule lub_mono [OF 2 2])
huffman@16203
   100
apply (rule chainE [OF 1])
huffman@16203
   101
done
huffman@16203
   102
huffman@16201
   103
lemma diag_lub:
huffman@16201
   104
  assumes 1: "\<And>j. chain (\<lambda>i. Y i j)"
huffman@16201
   105
  assumes 2: "\<And>i. chain (\<lambda>j. Y i j)"
huffman@16201
   106
  shows "(\<Squnion>i. \<Squnion>j. Y i j) = (\<Squnion>i. Y i i)"
huffman@31076
   107
proof (rule below_antisym)
huffman@16201
   108
  have 3: "chain (\<lambda>i. Y i i)"
huffman@16201
   109
    apply (rule chainI)
huffman@31076
   110
    apply (rule below_trans)
huffman@16201
   111
    apply (rule chainE [OF 1])
huffman@16201
   112
    apply (rule chainE [OF 2])
huffman@16201
   113
    done
huffman@16201
   114
  have 4: "chain (\<lambda>i. \<Squnion>j. Y i j)"
huffman@16203
   115
    by (rule ch2ch_lub [OF 1 2])
huffman@16201
   116
  show "(\<Squnion>i. \<Squnion>j. Y i j) \<sqsubseteq> (\<Squnion>i. Y i i)"
huffman@40500
   117
    apply (rule lub_below [OF 4])
huffman@40500
   118
    apply (rule lub_below [OF 2])
huffman@40500
   119
    apply (rule below_lub [OF 3])
huffman@31076
   120
    apply (rule below_trans)
haftmann@54863
   121
    apply (rule chain_mono [OF 1 max.cobounded1])
haftmann@54863
   122
    apply (rule chain_mono [OF 2 max.cobounded2])
huffman@16201
   123
    done
huffman@16201
   124
  show "(\<Squnion>i. Y i i) \<sqsubseteq> (\<Squnion>i. \<Squnion>j. Y i j)"
huffman@25923
   125
    apply (rule lub_mono [OF 3 4])
huffman@16201
   126
    apply (rule is_ub_thelub [OF 2])
huffman@16201
   127
    done
huffman@16201
   128
qed
huffman@16201
   129
huffman@16201
   130
lemma ex_lub:
huffman@16201
   131
  assumes 1: "\<And>j. chain (\<lambda>i. Y i j)"
huffman@16201
   132
  assumes 2: "\<And>i. chain (\<lambda>j. Y i j)"
huffman@16201
   133
  shows "(\<Squnion>i. \<Squnion>j. Y i j) = (\<Squnion>j. \<Squnion>i. Y i j)"
haftmann@31071
   134
  by (simp add: diag_lub 1 2)
huffman@16201
   135
haftmann@31071
   136
end
huffman@16201
   137
wenzelm@62175
   138
subsection \<open>Pointed cpos\<close>
huffman@15588
   139
wenzelm@62175
   140
text \<open>The class pcpo of pointed cpos\<close>
huffman@15588
   141
haftmann@29614
   142
class pcpo = cpo +
haftmann@29614
   143
  assumes least: "\<exists>x. \<forall>y. x \<sqsubseteq> y"
haftmann@31071
   144
begin
huffman@25723
   145
wenzelm@61998
   146
definition bottom :: "'a"  ("\<bottom>")
huffman@41429
   147
  where "bottom = (THE x. \<forall>y. x \<sqsubseteq> y)"
huffman@25723
   148
huffman@41429
   149
lemma minimal [iff]: "\<bottom> \<sqsubseteq> x"
huffman@41429
   150
unfolding bottom_def
huffman@41429
   151
apply (rule the1I2)
huffman@25723
   152
apply (rule ex_ex1I)
huffman@25723
   153
apply (rule least)
huffman@31076
   154
apply (blast intro: below_antisym)
huffman@41429
   155
apply simp
huffman@25723
   156
done
huffman@25723
   157
huffman@41429
   158
end
huffman@41429
   159
wenzelm@62175
   160
text \<open>Old "UU" syntax:\<close>
huffman@25723
   161
huffman@41429
   162
syntax UU :: logic
huffman@41429
   163
huffman@41429
   164
translations "UU" => "CONST bottom"
haftmann@31071
   165
wenzelm@62175
   166
text \<open>Simproc to rewrite @{term "\<bottom> = x"} to @{term "x = \<bottom>"}.\<close>
huffman@16739
   167
wenzelm@62175
   168
setup \<open>
wenzelm@33523
   169
  Reorient_Proc.add
huffman@41429
   170
    (fn Const(@{const_name bottom}, _) => true | _ => false)
wenzelm@62175
   171
\<close>
huffman@25723
   172
wenzelm@33523
   173
simproc_setup reorient_bottom ("\<bottom> = x") = Reorient_Proc.proc
huffman@25723
   174
wenzelm@62175
   175
text \<open>useful lemmas about @{term \<bottom>}\<close>
huffman@25723
   176
huffman@41430
   177
lemma below_bottom_iff [simp]: "(x \<sqsubseteq> \<bottom>) = (x = \<bottom>)"
huffman@25723
   178
by (simp add: po_eq_conv)
huffman@25723
   179
huffman@41430
   180
lemma eq_bottom_iff: "(x = \<bottom>) = (x \<sqsubseteq> \<bottom>)"
huffman@25723
   181
by simp
huffman@25723
   182
huffman@41430
   183
lemma bottomI: "x \<sqsubseteq> \<bottom> \<Longrightarrow> x = \<bottom>"
huffman@41430
   184
by (subst eq_bottom_iff)
huffman@25723
   185
huffman@40045
   186
lemma lub_eq_bottom_iff: "chain Y \<Longrightarrow> (\<Squnion>i. Y i) = \<bottom> \<longleftrightarrow> (\<forall>i. Y i = \<bottom>)"
huffman@41430
   187
by (simp only: eq_bottom_iff lub_below_iff)
huffman@40045
   188
wenzelm@62175
   189
subsection \<open>Chain-finite and flat cpos\<close>
huffman@15563
   190
wenzelm@62175
   191
text \<open>further useful classes for HOLCF domains\<close>
huffman@15588
   192
haftmann@31071
   193
class chfin = po +
haftmann@31071
   194
  assumes chfin: "chain Y \<Longrightarrow> \<exists>n. max_in_chain n Y"
haftmann@31071
   195
begin
huffman@25814
   196
haftmann@31071
   197
subclass cpo
wenzelm@61169
   198
apply standard
haftmann@31071
   199
apply (frule chfin)
haftmann@31071
   200
apply (blast intro: lub_finch1)
haftmann@31071
   201
done
huffman@15563
   202
haftmann@31071
   203
lemma chfin2finch: "chain Y \<Longrightarrow> finite_chain Y"
haftmann@31071
   204
  by (simp add: chfin finite_chain_def)
haftmann@31071
   205
haftmann@31071
   206
end
huffman@15588
   207
haftmann@31071
   208
class flat = pcpo +
haftmann@31071
   209
  assumes ax_flat: "x \<sqsubseteq> y \<Longrightarrow> x = \<bottom> \<or> x = y"
haftmann@31071
   210
begin
huffman@15640
   211
haftmann@31071
   212
subclass chfin
wenzelm@61169
   213
apply standard
huffman@15563
   214
apply (unfold max_in_chain_def)
huffman@16626
   215
apply (case_tac "\<forall>i. Y i = \<bottom>")
huffman@15588
   216
apply simp
huffman@15563
   217
apply simp
huffman@15563
   218
apply (erule exE)
huffman@16626
   219
apply (rule_tac x="i" in exI)
huffman@15588
   220
apply clarify
huffman@25922
   221
apply (blast dest: chain_mono ax_flat)
huffman@15563
   222
done
huffman@15563
   223
huffman@31076
   224
lemma flat_below_iff:
huffman@25826
   225
  shows "(x \<sqsubseteq> y) = (x = \<bottom> \<or> x = y)"
haftmann@31071
   226
  by (safe dest!: ax_flat)
huffman@25826
   227
haftmann@31071
   228
lemma flat_eq: "a \<noteq> \<bottom> \<Longrightarrow> a \<sqsubseteq> b = (a = b)"
haftmann@31071
   229
  by (safe dest!: ax_flat)
huffman@15563
   230
haftmann@31071
   231
end
huffman@15563
   232
wenzelm@62175
   233
subsection \<open>Discrete cpos\<close>
huffman@26023
   234
huffman@31076
   235
class discrete_cpo = below +
haftmann@29614
   236
  assumes discrete_cpo [simp]: "x \<sqsubseteq> y \<longleftrightarrow> x = y"
haftmann@31071
   237
begin
huffman@26023
   238
haftmann@31071
   239
subclass po
haftmann@29614
   240
proof qed simp_all
huffman@26023
   241
wenzelm@62175
   242
text \<open>In a discrete cpo, every chain is constant\<close>
huffman@26023
   243
huffman@26023
   244
lemma discrete_chain_const:
haftmann@31071
   245
  assumes S: "chain S"
huffman@26023
   246
  shows "\<exists>x. S = (\<lambda>i. x)"
huffman@26023
   247
proof (intro exI ext)
huffman@26023
   248
  fix i :: nat
huffman@26023
   249
  have "S 0 \<sqsubseteq> S i" using S le0 by (rule chain_mono)
huffman@26023
   250
  hence "S 0 = S i" by simp
huffman@26023
   251
  thus "S i = S 0" by (rule sym)
huffman@26023
   252
qed
huffman@26023
   253
huffman@40091
   254
subclass chfin
huffman@26023
   255
proof
huffman@26023
   256
  fix S :: "nat \<Rightarrow> 'a"
huffman@26023
   257
  assume S: "chain S"
huffman@40091
   258
  hence "\<exists>x. S = (\<lambda>i. x)" by (rule discrete_chain_const)
huffman@40091
   259
  hence "max_in_chain 0 S"
huffman@40091
   260
    unfolding max_in_chain_def by auto
huffman@40091
   261
  thus "\<exists>i. max_in_chain i S" ..
huffman@26023
   262
qed
huffman@26023
   263
haftmann@31071
   264
end
huffman@15576
   265
huffman@16626
   266
end