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