src/HOL/Library/Bourbaki_Witt_Fixpoint.thy
author Andreas Lochbihler
Tue Dec 01 12:35:11 2015 +0100 (2015-12-01)
changeset 61766 507b39df1a57
child 62058 1cfd5d604937
permissions -rw-r--r--
add formalisation of Bourbaki-Witt fixpoint theorem
Andreas@61766
     1
(* Title: Bourbaki_Witt_Fixpoint.thy
Andreas@61766
     2
   Author: Andreas Lochbihler, ETH Zurich *)
Andreas@61766
     3
Andreas@61766
     4
section \<open>The Bourbaki-Witt tower construction for transfinite iteration\<close>
Andreas@61766
     5
Andreas@61766
     6
theory Bourbaki_Witt_Fixpoint imports Main begin
Andreas@61766
     7
Andreas@61766
     8
lemma ChainsI [intro?]:
Andreas@61766
     9
  "(\<And>a b. \<lbrakk> a \<in> Y; b \<in> Y \<rbrakk> \<Longrightarrow> (a, b) \<in> r \<or> (b, a) \<in> r) \<Longrightarrow> Y \<in> Chains r"
Andreas@61766
    10
unfolding Chains_def by blast
Andreas@61766
    11
Andreas@61766
    12
lemma in_Chains_subset: "\<lbrakk> M \<in> Chains r; M' \<subseteq> M \<rbrakk> \<Longrightarrow> M' \<in> Chains r"
Andreas@61766
    13
by(auto simp add: Chains_def)
Andreas@61766
    14
Andreas@61766
    15
lemma FieldI1: "(i, j) \<in> R \<Longrightarrow> i \<in> Field R"
Andreas@61766
    16
  unfolding Field_def by auto
Andreas@61766
    17
Andreas@61766
    18
lemma Chains_FieldD: "\<lbrakk> M \<in> Chains r; x \<in> M \<rbrakk> \<Longrightarrow> x \<in> Field r"
Andreas@61766
    19
by(auto simp add: Chains_def intro: FieldI1 FieldI2)
Andreas@61766
    20
Andreas@61766
    21
lemma partial_order_on_trans:
Andreas@61766
    22
  "\<lbrakk> partial_order_on A r; (x, y) \<in> r; (y, z) \<in> r \<rbrakk> \<Longrightarrow> (x, z) \<in> r"
Andreas@61766
    23
by(auto simp add: order_on_defs dest: transD)
Andreas@61766
    24
Andreas@61766
    25
locale bourbaki_witt_fixpoint =
Andreas@61766
    26
  fixes lub :: "'a set \<Rightarrow> 'a"
Andreas@61766
    27
  and leq :: "('a \<times> 'a) set"
Andreas@61766
    28
  and f :: "'a \<Rightarrow> 'a"
Andreas@61766
    29
  assumes po: "Partial_order leq"
Andreas@61766
    30
  and lub_least: "\<lbrakk> M \<in> Chains leq; M \<noteq> {}; \<And>x. x \<in> M \<Longrightarrow> (x, z) \<in> leq \<rbrakk> \<Longrightarrow> (lub M, z) \<in> leq"
Andreas@61766
    31
  and lub_upper: "\<lbrakk> M \<in> Chains leq; x \<in> M \<rbrakk> \<Longrightarrow> (x, lub M) \<in> leq"
Andreas@61766
    32
  and lub_in_Field: "\<lbrakk> M \<in> Chains leq; M \<noteq> {} \<rbrakk> \<Longrightarrow> lub M \<in> Field leq"
Andreas@61766
    33
  and increasing: "\<And>x. x \<in> Field leq \<Longrightarrow> (x, f x) \<in> leq"
Andreas@61766
    34
begin
Andreas@61766
    35
Andreas@61766
    36
lemma leq_trans: "\<lbrakk> (x, y) \<in> leq; (y, z) \<in> leq \<rbrakk> \<Longrightarrow> (x, z) \<in> leq"
Andreas@61766
    37
by(rule partial_order_on_trans[OF po])
Andreas@61766
    38
Andreas@61766
    39
lemma leq_refl: "x \<in> Field leq \<Longrightarrow> (x, x) \<in> leq"
Andreas@61766
    40
using po by(simp add: order_on_defs refl_on_def)
Andreas@61766
    41
Andreas@61766
    42
lemma leq_antisym: "\<lbrakk> (x, y) \<in> leq; (y, x) \<in> leq \<rbrakk> \<Longrightarrow> x = y"
Andreas@61766
    43
using po by(simp add: order_on_defs antisym_def)
Andreas@61766
    44
Andreas@61766
    45
inductive_set iterates_above :: "'a \<Rightarrow> 'a set"
Andreas@61766
    46
  for a
Andreas@61766
    47
where
Andreas@61766
    48
  base: "a \<in> iterates_above a"
Andreas@61766
    49
| step: "x \<in> iterates_above a \<Longrightarrow> f x \<in> iterates_above a"
Andreas@61766
    50
| Sup: "\<lbrakk> M \<in> Chains leq; M \<noteq> {}; \<And>x. x \<in> M \<Longrightarrow> x \<in> iterates_above a \<rbrakk> \<Longrightarrow> lub M \<in> iterates_above a"
Andreas@61766
    51
Andreas@61766
    52
definition fixp_above :: "'a \<Rightarrow> 'a"
Andreas@61766
    53
where "fixp_above a = lub (iterates_above a)"
Andreas@61766
    54
Andreas@61766
    55
context 
Andreas@61766
    56
  notes leq_refl [intro!, simp]
Andreas@61766
    57
  and base [intro]
Andreas@61766
    58
  and step [intro]
Andreas@61766
    59
  and Sup [intro]
Andreas@61766
    60
  and leq_trans [trans]
Andreas@61766
    61
begin
Andreas@61766
    62
Andreas@61766
    63
lemma iterates_above_le_f: "\<lbrakk> x \<in> iterates_above a; a \<in> Field leq \<rbrakk> \<Longrightarrow> (x, f x) \<in> leq"
Andreas@61766
    64
by(induction x rule: iterates_above.induct)(blast intro: increasing FieldI2 lub_in_Field)+
Andreas@61766
    65
Andreas@61766
    66
lemma iterates_above_Field: "\<lbrakk> x \<in> iterates_above a; a \<in> Field leq \<rbrakk> \<Longrightarrow> x \<in> Field leq"
Andreas@61766
    67
by(drule (1) iterates_above_le_f)(rule FieldI1)
Andreas@61766
    68
Andreas@61766
    69
lemma iterates_above_ge:
Andreas@61766
    70
  assumes y: "y \<in> iterates_above a"
Andreas@61766
    71
  and a: "a \<in> Field leq"
Andreas@61766
    72
  shows "(a, y) \<in> leq"
Andreas@61766
    73
using y by(induction)(auto intro: a increasing iterates_above_le_f leq_trans leq_trans[OF _ lub_upper])
Andreas@61766
    74
Andreas@61766
    75
lemma iterates_above_lub:
Andreas@61766
    76
  assumes M: "M \<in> Chains leq"
Andreas@61766
    77
  and nempty: "M \<noteq> {}"
Andreas@61766
    78
  and upper: "\<And>y. y \<in> M \<Longrightarrow> \<exists>z \<in> M. (y, z) \<in> leq \<and> z \<in> iterates_above a"
Andreas@61766
    79
  shows "lub M \<in> iterates_above a"
Andreas@61766
    80
proof -
Andreas@61766
    81
  let ?M = "M \<inter> iterates_above a"
Andreas@61766
    82
  from M have M': "?M \<in> Chains leq" by(rule in_Chains_subset)simp
Andreas@61766
    83
  have "?M \<noteq> {}" using nempty by(auto dest: upper)
Andreas@61766
    84
  with M' have "lub ?M \<in> iterates_above a" by(rule Sup) blast
Andreas@61766
    85
  also have "lub ?M = lub M" using nempty
Andreas@61766
    86
    by(intro leq_antisym)(blast intro!: lub_least[OF M] lub_least[OF M'] intro: lub_upper[OF M'] lub_upper[OF M] leq_trans dest: upper)+
Andreas@61766
    87
  finally show ?thesis .
Andreas@61766
    88
qed
Andreas@61766
    89
Andreas@61766
    90
lemma iterates_above_successor:
Andreas@61766
    91
  assumes y: "y \<in> iterates_above a"
Andreas@61766
    92
  and a: "a \<in> Field leq"
Andreas@61766
    93
  shows "y = a \<or> y \<in> iterates_above (f a)"
Andreas@61766
    94
using y
Andreas@61766
    95
proof induction
Andreas@61766
    96
  case base thus ?case by simp
Andreas@61766
    97
next
Andreas@61766
    98
  case (step x) thus ?case by auto
Andreas@61766
    99
next
Andreas@61766
   100
  case (Sup M)
Andreas@61766
   101
  show ?case
Andreas@61766
   102
  proof(cases "\<exists>x. M \<subseteq> {x}")
Andreas@61766
   103
    case True
Andreas@61766
   104
    with \<open>M \<noteq> {}\<close> obtain y where M: "M = {y}" by auto
Andreas@61766
   105
    have "lub M = y"
Andreas@61766
   106
      by(rule leq_antisym)(auto intro!: lub_upper Sup lub_least ChainsI simp add: a M Sup.hyps(3)[of y, THEN iterates_above_Field] dest: iterates_above_Field)
Andreas@61766
   107
    with Sup.IH[of y] M show ?thesis by simp
Andreas@61766
   108
  next
Andreas@61766
   109
    case False
Andreas@61766
   110
    from Sup(1-2) have "lub M \<in> iterates_above (f a)"
Andreas@61766
   111
    proof(rule iterates_above_lub)
Andreas@61766
   112
      fix y
Andreas@61766
   113
      assume y: "y \<in> M"
Andreas@61766
   114
      from Sup.IH[OF this] show "\<exists>z\<in>M. (y, z) \<in> leq \<and> z \<in> iterates_above (f a)"
Andreas@61766
   115
      proof
Andreas@61766
   116
        assume "y = a"
Andreas@61766
   117
        from y False obtain z where z: "z \<in> M" and neq: "y \<noteq> z" by (metis insertI1 subsetI)
Andreas@61766
   118
        with Sup.IH[OF z] \<open>y = a\<close> Sup.hyps(3)[OF z]
Andreas@61766
   119
        show ?thesis by(auto dest: iterates_above_ge intro: a)
Andreas@61766
   120
      next
Andreas@61766
   121
        assume "y \<in> iterates_above (f a)"
Andreas@61766
   122
        moreover with increasing[OF a] have "y \<in> Field leq"
Andreas@61766
   123
          by(auto dest!: iterates_above_Field intro: FieldI2)
Andreas@61766
   124
        ultimately show ?thesis using y by(auto)
Andreas@61766
   125
      qed
Andreas@61766
   126
    qed
Andreas@61766
   127
    thus ?thesis by simp
Andreas@61766
   128
  qed
Andreas@61766
   129
qed
Andreas@61766
   130
Andreas@61766
   131
lemma iterates_above_Sup_aux:
Andreas@61766
   132
  assumes M: "M \<in> Chains leq" "M \<noteq> {}"
Andreas@61766
   133
  and M': "M' \<in> Chains leq" "M' \<noteq> {}"
Andreas@61766
   134
  and comp: "\<And>x. x \<in> M \<Longrightarrow> x \<in> iterates_above (lub M') \<or> lub M' \<in> iterates_above x"
Andreas@61766
   135
  shows "(lub M, lub M') \<in> leq \<or> lub M \<in> iterates_above (lub M')"
Andreas@61766
   136
proof(cases "\<exists>x \<in> M. x \<in> iterates_above (lub M')")
Andreas@61766
   137
  case True
Andreas@61766
   138
  then obtain x where x: "x \<in> M" "x \<in> iterates_above (lub M')" by blast
Andreas@61766
   139
  have lub_M': "lub M' \<in> Field leq" using M' by(rule lub_in_Field)
Andreas@61766
   140
  have "lub M \<in> iterates_above (lub M')" using M
Andreas@61766
   141
  proof(rule iterates_above_lub)
Andreas@61766
   142
    fix y
Andreas@61766
   143
    assume y: "y \<in> M"
Andreas@61766
   144
    from comp[OF y] show "\<exists>z\<in>M. (y, z) \<in> leq \<and> z \<in> iterates_above (lub M')"
Andreas@61766
   145
    proof
Andreas@61766
   146
      assume "y \<in> iterates_above (lub M')"
Andreas@61766
   147
      from this iterates_above_Field[OF this] y lub_M' show ?thesis by blast
Andreas@61766
   148
    next
Andreas@61766
   149
      assume "lub M' \<in> iterates_above y"
Andreas@61766
   150
      hence "(y, lub M') \<in> leq" using Chains_FieldD[OF M(1) y] by(rule iterates_above_ge)
Andreas@61766
   151
      also have "(lub M', x) \<in> leq" using x(2) lub_M' by(rule iterates_above_ge)
Andreas@61766
   152
      finally show ?thesis using x by blast
Andreas@61766
   153
    qed
Andreas@61766
   154
  qed
Andreas@61766
   155
  thus ?thesis ..
Andreas@61766
   156
next
Andreas@61766
   157
  case False
Andreas@61766
   158
  have "(lub M, lub M') \<in> leq" using M
Andreas@61766
   159
  proof(rule lub_least)
Andreas@61766
   160
    fix x
Andreas@61766
   161
    assume x: "x \<in> M"
Andreas@61766
   162
    from comp[OF x] x False have "lub M' \<in> iterates_above x" by auto
Andreas@61766
   163
    moreover from M(1) x have "x \<in> Field leq" by(rule Chains_FieldD)
Andreas@61766
   164
    ultimately show "(x, lub M') \<in> leq" by(rule iterates_above_ge)
Andreas@61766
   165
  qed
Andreas@61766
   166
  thus ?thesis ..
Andreas@61766
   167
qed
Andreas@61766
   168
Andreas@61766
   169
lemma iterates_above_triangle:
Andreas@61766
   170
  assumes x: "x \<in> iterates_above a"
Andreas@61766
   171
  and y: "y \<in> iterates_above a"
Andreas@61766
   172
  and a: "a \<in> Field leq"
Andreas@61766
   173
  shows "x \<in> iterates_above y \<or> y \<in> iterates_above x"
Andreas@61766
   174
using x y
Andreas@61766
   175
proof(induction arbitrary: y)
Andreas@61766
   176
  case base then show ?case by simp
Andreas@61766
   177
next
Andreas@61766
   178
  case (step x) thus ?case using a
Andreas@61766
   179
    by(auto dest: iterates_above_successor intro: iterates_above_Field)
Andreas@61766
   180
next
Andreas@61766
   181
  case x: (Sup M)
Andreas@61766
   182
  hence lub: "lub M \<in> iterates_above a" by blast
Andreas@61766
   183
  from \<open>y \<in> iterates_above a\<close> show ?case
Andreas@61766
   184
  proof(induction)
Andreas@61766
   185
    case base show ?case using lub by simp
Andreas@61766
   186
  next
Andreas@61766
   187
    case (step y) thus ?case using a
Andreas@61766
   188
      by(auto dest: iterates_above_successor intro: iterates_above_Field)
Andreas@61766
   189
  next
Andreas@61766
   190
    case y: (Sup M')
Andreas@61766
   191
    hence lub': "lub M' \<in> iterates_above a" by blast
Andreas@61766
   192
    have *: "x \<in> iterates_above (lub M') \<or> lub M' \<in> iterates_above x" if "x \<in> M" for x
Andreas@61766
   193
      using that lub' by(rule x.IH)
Andreas@61766
   194
    with x(1-2) y(1-2) have "(lub M, lub M') \<in> leq \<or> lub M \<in> iterates_above (lub M')"
Andreas@61766
   195
      by(rule iterates_above_Sup_aux)
Andreas@61766
   196
    moreover from y(1-2) x(1-2) have "(lub M', lub M) \<in> leq \<or> lub M' \<in> iterates_above (lub M)"
Andreas@61766
   197
      by(rule iterates_above_Sup_aux)(blast dest: y.IH)
Andreas@61766
   198
    ultimately show ?case by(auto 4 3 dest: leq_antisym)
Andreas@61766
   199
  qed
Andreas@61766
   200
qed
Andreas@61766
   201
Andreas@61766
   202
lemma chain_iterates_above: 
Andreas@61766
   203
  assumes a: "a \<in> Field leq"
Andreas@61766
   204
  shows "iterates_above a \<in> Chains leq" (is "?C \<in> _")
Andreas@61766
   205
proof (rule ChainsI)
Andreas@61766
   206
  fix x y
Andreas@61766
   207
  assume "x \<in> ?C" "y \<in> ?C"
Andreas@61766
   208
  hence "x \<in> iterates_above y \<or> y \<in> iterates_above x" using a by(rule iterates_above_triangle)
Andreas@61766
   209
  moreover from \<open>x \<in> ?C\<close> a have "x \<in> Field leq" by(rule iterates_above_Field)
Andreas@61766
   210
  moreover from \<open>y \<in> ?C\<close> a have "y \<in> Field leq" by(rule iterates_above_Field)
Andreas@61766
   211
  ultimately show "(x, y) \<in> leq \<or> (y, x) \<in> leq" by(auto dest: iterates_above_ge)
Andreas@61766
   212
qed
Andreas@61766
   213
Andreas@61766
   214
lemma fixp_iterates_above: "a \<in> Field leq \<Longrightarrow> fixp_above a \<in> iterates_above a"
Andreas@61766
   215
unfolding fixp_above_def by(rule iterates_above.Sup)(blast intro: chain_iterates_above)+
Andreas@61766
   216
Andreas@61766
   217
lemma
Andreas@61766
   218
  assumes b: "b \<in> iterates_above a"
Andreas@61766
   219
  and fb: "f b = b"
Andreas@61766
   220
  and x: "x \<in> iterates_above a"
Andreas@61766
   221
  and a: "a \<in> Field leq"
Andreas@61766
   222
  shows "b \<in> iterates_above x"
Andreas@61766
   223
using x
Andreas@61766
   224
proof(induction)
Andreas@61766
   225
  case base show ?case using b by simp
Andreas@61766
   226
next
Andreas@61766
   227
  case (step x)
Andreas@61766
   228
  from step.hyps a have "x \<in> Field leq" by(rule iterates_above_Field)
Andreas@61766
   229
  from iterates_above_successor[OF step.IH this] fb
Andreas@61766
   230
  show ?case by(auto)
Andreas@61766
   231
next
Andreas@61766
   232
  case (Sup M)
Andreas@61766
   233
  oops
Andreas@61766
   234
Andreas@61766
   235
lemma fixp_above_Field: "a \<in> Field leq \<Longrightarrow> fixp_above a \<in> Field leq"
Andreas@61766
   236
using fixp_iterates_above by(rule iterates_above_Field)
Andreas@61766
   237
Andreas@61766
   238
lemma fixp_above_unfold:
Andreas@61766
   239
  assumes a: "a \<in> Field leq"
Andreas@61766
   240
  shows "fixp_above a = f (fixp_above a)" (is "?a = f ?a")
Andreas@61766
   241
proof(rule leq_antisym)
Andreas@61766
   242
  show "(?a, f ?a) \<in> leq" using fixp_above_Field[OF a] by(rule increasing)
Andreas@61766
   243
  
Andreas@61766
   244
  have "f ?a \<in> iterates_above a" using fixp_iterates_above[OF a] by(rule iterates_above.step)
Andreas@61766
   245
  with chain_iterates_above[OF a] show "(f ?a, ?a) \<in> leq" unfolding fixp_above_def by(rule lub_upper)
Andreas@61766
   246
qed
Andreas@61766
   247
Andreas@61766
   248
end
Andreas@61766
   249
Andreas@61766
   250
end
Andreas@61766
   251
Andreas@61766
   252
end