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