src/HOL/Complete_Partial_Order.thy
author Andreas Lochbihler
Tue Apr 14 11:32:01 2015 +0200 (2015-04-14)
changeset 60057 86fa63ce8156
parent 58889 5b7a9633cfa8
child 60061 279472fa0b1d
permissions -rw-r--r--
add lemmas
krauss@40106
     1
(* Title:    HOL/Complete_Partial_Order.thy
krauss@40106
     2
   Author:   Brian Huffman, Portland State University
krauss@40106
     3
   Author:   Alexander Krauss, TU Muenchen
krauss@40106
     4
*)
krauss@40106
     5
wenzelm@58889
     6
section {* Chain-complete partial orders and their fixpoints *}
krauss@40106
     7
krauss@40106
     8
theory Complete_Partial_Order
krauss@40106
     9
imports Product_Type
krauss@40106
    10
begin
krauss@40106
    11
krauss@40106
    12
subsection {* Monotone functions *}
krauss@40106
    13
krauss@40106
    14
text {* Dictionary-passing version of @{const Orderings.mono}. *}
krauss@40106
    15
krauss@40106
    16
definition monotone :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> bool"
krauss@40106
    17
where "monotone orda ordb f \<longleftrightarrow> (\<forall>x y. orda x y \<longrightarrow> ordb (f x) (f y))"
krauss@40106
    18
krauss@40106
    19
lemma monotoneI[intro?]: "(\<And>x y. orda x y \<Longrightarrow> ordb (f x) (f y))
krauss@40106
    20
 \<Longrightarrow> monotone orda ordb f"
krauss@40106
    21
unfolding monotone_def by iprover
krauss@40106
    22
krauss@40106
    23
lemma monotoneD[dest?]: "monotone orda ordb f \<Longrightarrow> orda x y \<Longrightarrow> ordb (f x) (f y)"
krauss@40106
    24
unfolding monotone_def by iprover
krauss@40106
    25
krauss@40106
    26
krauss@40106
    27
subsection {* Chains *}
krauss@40106
    28
krauss@40106
    29
text {* A chain is a totally-ordered set. Chains are parameterized over
krauss@40106
    30
  the order for maximal flexibility, since type classes are not enough.
krauss@40106
    31
*}
krauss@40106
    32
krauss@40106
    33
definition
krauss@40106
    34
  chain :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> bool"
krauss@40106
    35
where
krauss@40106
    36
  "chain ord S \<longleftrightarrow> (\<forall>x\<in>S. \<forall>y\<in>S. ord x y \<or> ord y x)"
krauss@40106
    37
krauss@40106
    38
lemma chainI:
krauss@40106
    39
  assumes "\<And>x y. x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> ord x y \<or> ord y x"
krauss@40106
    40
  shows "chain ord S"
krauss@40106
    41
using assms unfolding chain_def by fast
krauss@40106
    42
krauss@40106
    43
lemma chainD:
krauss@40106
    44
  assumes "chain ord S" and "x \<in> S" and "y \<in> S"
krauss@40106
    45
  shows "ord x y \<or> ord y x"
krauss@40106
    46
using assms unfolding chain_def by fast
krauss@40106
    47
krauss@40106
    48
lemma chainE:
krauss@40106
    49
  assumes "chain ord S" and "x \<in> S" and "y \<in> S"
krauss@40106
    50
  obtains "ord x y" | "ord y x"
krauss@40106
    51
using assms unfolding chain_def by fast
krauss@40106
    52
Andreas@54630
    53
lemma chain_empty: "chain ord {}"
Andreas@54630
    54
by(simp add: chain_def)
Andreas@54630
    55
Andreas@60057
    56
lemma chain_equality: "chain op = A \<longleftrightarrow> (\<forall>x\<in>A. \<forall>y\<in>A. x = y)"
Andreas@60057
    57
by(auto simp add: chain_def)
Andreas@60057
    58
krauss@40106
    59
subsection {* Chain-complete partial orders *}
krauss@40106
    60
krauss@40106
    61
text {*
krauss@40106
    62
  A ccpo has a least upper bound for any chain.  In particular, the
krauss@40106
    63
  empty set is a chain, so every ccpo must have a bottom element.
krauss@40106
    64
*}
krauss@40106
    65
huffman@46041
    66
class ccpo = order + Sup +
huffman@46041
    67
  assumes ccpo_Sup_upper: "\<lbrakk>chain (op \<le>) A; x \<in> A\<rbrakk> \<Longrightarrow> x \<le> Sup A"
huffman@46041
    68
  assumes ccpo_Sup_least: "\<lbrakk>chain (op \<le>) A; \<And>x. x \<in> A \<Longrightarrow> x \<le> z\<rbrakk> \<Longrightarrow> Sup A \<le> z"
krauss@40106
    69
begin
krauss@40106
    70
krauss@40106
    71
subsection {* Transfinite iteration of a function *}
krauss@40106
    72
krauss@40106
    73
inductive_set iterates :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a set"
krauss@40106
    74
for f :: "'a \<Rightarrow> 'a"
krauss@40106
    75
where
krauss@40106
    76
  step: "x \<in> iterates f \<Longrightarrow> f x \<in> iterates f"
huffman@46041
    77
| Sup: "chain (op \<le>) M \<Longrightarrow> \<forall>x\<in>M. x \<in> iterates f \<Longrightarrow> Sup M \<in> iterates f"
krauss@40106
    78
krauss@40106
    79
lemma iterates_le_f:
krauss@40106
    80
  "x \<in> iterates f \<Longrightarrow> monotone (op \<le>) (op \<le>) f \<Longrightarrow> x \<le> f x"
krauss@40106
    81
by (induct x rule: iterates.induct)
huffman@46041
    82
  (force dest: monotoneD intro!: ccpo_Sup_upper ccpo_Sup_least)+
krauss@40106
    83
krauss@40106
    84
lemma chain_iterates:
krauss@40106
    85
  assumes f: "monotone (op \<le>) (op \<le>) f"
krauss@40106
    86
  shows "chain (op \<le>) (iterates f)" (is "chain _ ?C")
krauss@40106
    87
proof (rule chainI)
krauss@40106
    88
  fix x y assume "x \<in> ?C" "y \<in> ?C"
krauss@40106
    89
  then show "x \<le> y \<or> y \<le> x"
krauss@40106
    90
  proof (induct x arbitrary: y rule: iterates.induct)
krauss@40106
    91
    fix x y assume y: "y \<in> ?C"
krauss@40106
    92
    and IH: "\<And>z. z \<in> ?C \<Longrightarrow> x \<le> z \<or> z \<le> x"
krauss@40106
    93
    from y show "f x \<le> y \<or> y \<le> f x"
krauss@40106
    94
    proof (induct y rule: iterates.induct)
krauss@40106
    95
      case (step y) with IH f show ?case by (auto dest: monotoneD)
krauss@40106
    96
    next
huffman@46041
    97
      case (Sup M)
krauss@40106
    98
      then have chM: "chain (op \<le>) M"
krauss@40106
    99
        and IH': "\<And>z. z \<in> M \<Longrightarrow> f x \<le> z \<or> z \<le> f x" by auto
huffman@46041
   100
      show "f x \<le> Sup M \<or> Sup M \<le> f x"
krauss@40106
   101
      proof (cases "\<exists>z\<in>M. f x \<le> z")
huffman@46041
   102
        case True then have "f x \<le> Sup M"
krauss@40106
   103
          apply rule
krauss@40106
   104
          apply (erule order_trans)
huffman@46041
   105
          by (rule ccpo_Sup_upper[OF chM])
krauss@40106
   106
        thus ?thesis ..
krauss@40106
   107
      next
krauss@40106
   108
        case False with IH'
huffman@46041
   109
        show ?thesis by (auto intro: ccpo_Sup_least[OF chM])
krauss@40106
   110
      qed
krauss@40106
   111
    qed
krauss@40106
   112
  next
huffman@46041
   113
    case (Sup M y)
krauss@40106
   114
    show ?case
krauss@40106
   115
    proof (cases "\<exists>x\<in>M. y \<le> x")
huffman@46041
   116
      case True then have "y \<le> Sup M"
krauss@40106
   117
        apply rule
krauss@40106
   118
        apply (erule order_trans)
huffman@46041
   119
        by (rule ccpo_Sup_upper[OF Sup(1)])
krauss@40106
   120
      thus ?thesis ..
krauss@40106
   121
    next
huffman@46041
   122
      case False with Sup
huffman@46041
   123
      show ?thesis by (auto intro: ccpo_Sup_least)
krauss@40106
   124
    qed
krauss@40106
   125
  qed
krauss@40106
   126
qed
krauss@40106
   127
Andreas@54630
   128
lemma bot_in_iterates: "Sup {} \<in> iterates f"
Andreas@54630
   129
by(auto intro: iterates.Sup simp add: chain_empty)
Andreas@54630
   130
krauss@40106
   131
subsection {* Fixpoint combinator *}
krauss@40106
   132
krauss@40106
   133
definition
krauss@40106
   134
  fixp :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a"
krauss@40106
   135
where
huffman@46041
   136
  "fixp f = Sup (iterates f)"
krauss@40106
   137
krauss@40106
   138
lemma iterates_fixp:
krauss@40106
   139
  assumes f: "monotone (op \<le>) (op \<le>) f" shows "fixp f \<in> iterates f"
krauss@40106
   140
unfolding fixp_def
huffman@46041
   141
by (simp add: iterates.Sup chain_iterates f)
krauss@40106
   142
krauss@40106
   143
lemma fixp_unfold:
krauss@40106
   144
  assumes f: "monotone (op \<le>) (op \<le>) f"
krauss@40106
   145
  shows "fixp f = f (fixp f)"
krauss@40106
   146
proof (rule antisym)
krauss@40106
   147
  show "fixp f \<le> f (fixp f)"
krauss@40106
   148
    by (intro iterates_le_f iterates_fixp f)
huffman@46041
   149
  have "f (fixp f) \<le> Sup (iterates f)"
huffman@46041
   150
    by (intro ccpo_Sup_upper chain_iterates f iterates.step iterates_fixp)
krauss@40106
   151
  thus "f (fixp f) \<le> fixp f"
krauss@40106
   152
    unfolding fixp_def .
krauss@40106
   153
qed
krauss@40106
   154
krauss@40106
   155
lemma fixp_lowerbound:
krauss@40106
   156
  assumes f: "monotone (op \<le>) (op \<le>) f" and z: "f z \<le> z" shows "fixp f \<le> z"
krauss@40106
   157
unfolding fixp_def
huffman@46041
   158
proof (rule ccpo_Sup_least[OF chain_iterates[OF f]])
krauss@40106
   159
  fix x assume "x \<in> iterates f"
krauss@40106
   160
  thus "x \<le> z"
krauss@40106
   161
  proof (induct x rule: iterates.induct)
krauss@40106
   162
    fix x assume "x \<le> z" with f have "f x \<le> f z" by (rule monotoneD)
krauss@40106
   163
    also note z finally show "f x \<le> z" .
huffman@46041
   164
  qed (auto intro: ccpo_Sup_least)
krauss@40106
   165
qed
krauss@40106
   166
Andreas@53361
   167
end
krauss@40106
   168
krauss@40106
   169
subsection {* Fixpoint induction *}
krauss@40106
   170
Andreas@53361
   171
setup {* Sign.map_naming (Name_Space.mandatory_path "ccpo") *}
Andreas@53361
   172
Andreas@53361
   173
definition admissible :: "('a set \<Rightarrow> 'a) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool"
Andreas@54630
   174
where "admissible lub ord P = (\<forall>A. chain ord A \<longrightarrow> (A \<noteq> {}) \<longrightarrow> (\<forall>x\<in>A. P x) \<longrightarrow> P (lub A))"
krauss@40106
   175
krauss@40106
   176
lemma admissibleI:
Andreas@54630
   177
  assumes "\<And>A. chain ord A \<Longrightarrow> A \<noteq> {} \<Longrightarrow> \<forall>x\<in>A. P x \<Longrightarrow> P (lub A)"
Andreas@53361
   178
  shows "ccpo.admissible lub ord P"
Andreas@53361
   179
using assms unfolding ccpo.admissible_def by fast
krauss@40106
   180
krauss@40106
   181
lemma admissibleD:
Andreas@53361
   182
  assumes "ccpo.admissible lub ord P"
Andreas@53361
   183
  assumes "chain ord A"
Andreas@54630
   184
  assumes "A \<noteq> {}"
krauss@40106
   185
  assumes "\<And>x. x \<in> A \<Longrightarrow> P x"
Andreas@53361
   186
  shows "P (lub A)"
Andreas@53361
   187
using assms by (auto simp: ccpo.admissible_def)
krauss@40106
   188
Andreas@53361
   189
setup {* Sign.map_naming Name_Space.parent_path *}
Andreas@53361
   190
Andreas@53361
   191
lemma (in ccpo) fixp_induct:
Andreas@53361
   192
  assumes adm: "ccpo.admissible Sup (op \<le>) P"
krauss@40106
   193
  assumes mono: "monotone (op \<le>) (op \<le>) f"
Andreas@54630
   194
  assumes bot: "P (Sup {})"
krauss@40106
   195
  assumes step: "\<And>x. P x \<Longrightarrow> P (f x)"
krauss@40106
   196
  shows "P (fixp f)"
krauss@40106
   197
unfolding fixp_def using adm chain_iterates[OF mono]
Andreas@53361
   198
proof (rule ccpo.admissibleD)
Andreas@54630
   199
  show "iterates f \<noteq> {}" using bot_in_iterates by auto
krauss@40106
   200
  fix x assume "x \<in> iterates f"
krauss@40106
   201
  thus "P x"
krauss@40106
   202
    by (induct rule: iterates.induct)
Andreas@54630
   203
      (case_tac "M = {}", auto intro: step bot ccpo.admissibleD adm)
krauss@40106
   204
qed
krauss@40106
   205
Andreas@53361
   206
lemma admissible_True: "ccpo.admissible lub ord (\<lambda>x. True)"
Andreas@53361
   207
unfolding ccpo.admissible_def by simp
krauss@40106
   208
Andreas@54630
   209
(*lemma admissible_False: "\<not> ccpo.admissible lub ord (\<lambda>x. False)"
Andreas@53361
   210
unfolding ccpo.admissible_def chain_def by simp
Andreas@54630
   211
*)
Andreas@54630
   212
lemma admissible_const: "ccpo.admissible lub ord (\<lambda>x. t)"
Andreas@54630
   213
by(auto intro: ccpo.admissibleI)
krauss@40106
   214
krauss@40106
   215
lemma admissible_conj:
Andreas@53361
   216
  assumes "ccpo.admissible lub ord (\<lambda>x. P x)"
Andreas@53361
   217
  assumes "ccpo.admissible lub ord (\<lambda>x. Q x)"
Andreas@53361
   218
  shows "ccpo.admissible lub ord (\<lambda>x. P x \<and> Q x)"
Andreas@53361
   219
using assms unfolding ccpo.admissible_def by simp
krauss@40106
   220
krauss@40106
   221
lemma admissible_all:
Andreas@53361
   222
  assumes "\<And>y. ccpo.admissible lub ord (\<lambda>x. P x y)"
Andreas@53361
   223
  shows "ccpo.admissible lub ord (\<lambda>x. \<forall>y. P x y)"
Andreas@53361
   224
using assms unfolding ccpo.admissible_def by fast
krauss@40106
   225
krauss@40106
   226
lemma admissible_ball:
Andreas@53361
   227
  assumes "\<And>y. y \<in> A \<Longrightarrow> ccpo.admissible lub ord (\<lambda>x. P x y)"
Andreas@53361
   228
  shows "ccpo.admissible lub ord (\<lambda>x. \<forall>y\<in>A. P x y)"
Andreas@53361
   229
using assms unfolding ccpo.admissible_def by fast
krauss@40106
   230
Andreas@53361
   231
lemma chain_compr: "chain ord A \<Longrightarrow> chain ord {x \<in> A. P x}"
krauss@40106
   232
unfolding chain_def by fast
krauss@40106
   233
Andreas@53361
   234
context ccpo begin
Andreas@53361
   235
krauss@40106
   236
lemma admissible_disj_lemma:
krauss@40106
   237
  assumes A: "chain (op \<le>)A"
krauss@40106
   238
  assumes P: "\<forall>x\<in>A. \<exists>y\<in>A. x \<le> y \<and> P y"
huffman@46041
   239
  shows "Sup A = Sup {x \<in> A. P x}"
krauss@40106
   240
proof (rule antisym)
krauss@40106
   241
  have *: "chain (op \<le>) {x \<in> A. P x}"
krauss@40106
   242
    by (rule chain_compr [OF A])
huffman@46041
   243
  show "Sup A \<le> Sup {x \<in> A. P x}"
huffman@46041
   244
    apply (rule ccpo_Sup_least [OF A])
krauss@40106
   245
    apply (drule P [rule_format], clarify)
krauss@40106
   246
    apply (erule order_trans)
huffman@46041
   247
    apply (simp add: ccpo_Sup_upper [OF *])
krauss@40106
   248
    done
huffman@46041
   249
  show "Sup {x \<in> A. P x} \<le> Sup A"
huffman@46041
   250
    apply (rule ccpo_Sup_least [OF *])
krauss@40106
   251
    apply clarify
huffman@46041
   252
    apply (simp add: ccpo_Sup_upper [OF A])
krauss@40106
   253
    done
krauss@40106
   254
qed
krauss@40106
   255
krauss@40106
   256
lemma admissible_disj:
krauss@40106
   257
  fixes P Q :: "'a \<Rightarrow> bool"
Andreas@53361
   258
  assumes P: "ccpo.admissible Sup (op \<le>) (\<lambda>x. P x)"
Andreas@53361
   259
  assumes Q: "ccpo.admissible Sup (op \<le>) (\<lambda>x. Q x)"
Andreas@53361
   260
  shows "ccpo.admissible Sup (op \<le>) (\<lambda>x. P x \<or> Q x)"
Andreas@53361
   261
proof (rule ccpo.admissibleI)
krauss@40106
   262
  fix A :: "'a set" assume A: "chain (op \<le>) A"
Andreas@54630
   263
  assume "A \<noteq> {}"
Andreas@54630
   264
    and "\<forall>x\<in>A. P x \<or> Q x"
Andreas@54630
   265
  hence "(\<exists>x\<in>A. P x) \<and> (\<forall>x\<in>A. \<exists>y\<in>A. x \<le> y \<and> P y) \<or> (\<exists>x\<in>A. Q x) \<and> (\<forall>x\<in>A. \<exists>y\<in>A. x \<le> y \<and> Q y)"
krauss@40106
   266
    using chainD[OF A] by blast
Andreas@54630
   267
  hence "(\<exists>x. x \<in> A \<and> P x) \<and> Sup A = Sup {x \<in> A. P x} \<or> (\<exists>x. x \<in> A \<and> Q x) \<and> Sup A = Sup {x \<in> A. Q x}"
Andreas@54630
   268
    using admissible_disj_lemma [OF A] by blast
huffman@46041
   269
  thus "P (Sup A) \<or> Q (Sup A)"
krauss@40106
   270
    apply (rule disjE, simp_all)
Andreas@54630
   271
    apply (rule disjI1, rule ccpo.admissibleD [OF P chain_compr [OF A]], simp, simp)
Andreas@54630
   272
    apply (rule disjI2, rule ccpo.admissibleD [OF Q chain_compr [OF A]], simp, simp)
krauss@40106
   273
    done
krauss@40106
   274
qed
krauss@40106
   275
krauss@40106
   276
end
krauss@40106
   277
huffman@46041
   278
instance complete_lattice \<subseteq> ccpo
huffman@46041
   279
  by default (fast intro: Sup_upper Sup_least)+
huffman@46041
   280
huffman@46041
   281
lemma lfp_eq_fixp:
huffman@46041
   282
  assumes f: "mono f" shows "lfp f = fixp f"
huffman@46041
   283
proof (rule antisym)
huffman@46041
   284
  from f have f': "monotone (op \<le>) (op \<le>) f"
huffman@46041
   285
    unfolding mono_def monotone_def .
huffman@46041
   286
  show "lfp f \<le> fixp f"
huffman@46041
   287
    by (rule lfp_lowerbound, subst fixp_unfold [OF f'], rule order_refl)
huffman@46041
   288
  show "fixp f \<le> lfp f"
huffman@46041
   289
    by (rule fixp_lowerbound [OF f'], subst lfp_unfold [OF f], rule order_refl)
huffman@46041
   290
qed
huffman@46041
   291
Andreas@53361
   292
hide_const (open) iterates fixp
krauss@40106
   293
krauss@40106
   294
end