src/HOL/Library/Order_Continuity.thy
author wenzelm
Sat Oct 01 17:16:35 2016 +0200 (2016-10-01)
changeset 63979 95c3ae4baba8
parent 63540 f8652d0534fa
child 69313 b021008c5397
permissions -rw-r--r--
clarified lfp/gfp statements and proofs;
hoelzl@56020
     1
(*  Title:      HOL/Library/Order_Continuity.thy
hoelzl@62373
     2
    Author:     David von Oheimb, TU München
hoelzl@62373
     3
    Author:     Johannes Hölzl, TU München
oheimb@11351
     4
*)
oheimb@11351
     5
hoelzl@62373
     6
section \<open>Continuity and iterations\<close>
oheimb@11351
     7
hoelzl@56020
     8
theory Order_Continuity
hoelzl@62373
     9
imports Complex_Main Countable_Complete_Lattices
nipkow@15131
    10
begin
oheimb@11351
    11
hoelzl@56020
    12
(* TODO: Generalize theory to chain-complete partial orders *)
hoelzl@56020
    13
hoelzl@56020
    14
lemma SUP_nat_binary:
hoelzl@62373
    15
  "(SUP n::nat. if n = 0 then A else B) = (sup A B::'a::countable_complete_lattice)"
hoelzl@62373
    16
  apply (auto intro!: antisym ccSUP_least)
hoelzl@62373
    17
  apply (rule ccSUP_upper2[where i=0])
hoelzl@56020
    18
  apply simp_all
hoelzl@62373
    19
  apply (rule ccSUP_upper2[where i=1])
hoelzl@56020
    20
  apply simp_all
hoelzl@56020
    21
  done
hoelzl@56020
    22
hoelzl@56020
    23
lemma INF_nat_binary:
hoelzl@62373
    24
  "(INF n::nat. if n = 0 then A else B) = (inf A B::'a::countable_complete_lattice)"
hoelzl@62373
    25
  apply (auto intro!: antisym ccINF_greatest)
hoelzl@62373
    26
  apply (rule ccINF_lower2[where i=0])
hoelzl@56020
    27
  apply simp_all
hoelzl@62373
    28
  apply (rule ccINF_lower2[where i=1])
hoelzl@56020
    29
  apply simp_all
hoelzl@56020
    30
  done
hoelzl@56020
    31
hoelzl@60172
    32
text \<open>
wenzelm@61585
    33
  The name \<open>continuous\<close> is already taken in \<open>Complex_Main\<close>, so we use
wenzelm@61585
    34
  \<open>sup_continuous\<close> and \<open>inf_continuous\<close>. These names appear sometimes in literature
hoelzl@60172
    35
  and have the advantage that these names are duals.
hoelzl@60172
    36
\<close>
hoelzl@60172
    37
hoelzl@60636
    38
named_theorems order_continuous_intros
hoelzl@60636
    39
wenzelm@60500
    40
subsection \<open>Continuity for complete lattices\<close>
nipkow@21312
    41
wenzelm@22367
    42
definition
hoelzl@62373
    43
  sup_continuous :: "('a::countable_complete_lattice \<Rightarrow> 'b::countable_complete_lattice) \<Rightarrow> bool"
hoelzl@62373
    44
where
hoelzl@60172
    45
  "sup_continuous F \<longleftrightarrow> (\<forall>M::nat \<Rightarrow> 'a. mono M \<longrightarrow> F (SUP i. M i) = (SUP i. F (M i)))"
wenzelm@22367
    46
hoelzl@60172
    47
lemma sup_continuousD: "sup_continuous F \<Longrightarrow> mono M \<Longrightarrow> F (SUP i::nat. M i) = (SUP i. F (M i))"
hoelzl@60172
    48
  by (auto simp: sup_continuous_def)
nipkow@21312
    49
hoelzl@60172
    50
lemma sup_continuous_mono:
hoelzl@60172
    51
  assumes [simp]: "sup_continuous F" shows "mono F"
nipkow@21312
    52
proof
hoelzl@56020
    53
  fix A B :: "'a" assume [simp]: "A \<le> B"
hoelzl@56020
    54
  have "F B = F (SUP n::nat. if n = 0 then A else B)"
hoelzl@56020
    55
    by (simp add: sup_absorb2 SUP_nat_binary)
hoelzl@56020
    56
  also have "\<dots> = (SUP n::nat. if n = 0 then F A else F B)"
hoelzl@60172
    57
    by (auto simp: sup_continuousD mono_def intro!: SUP_cong)
hoelzl@56020
    58
  finally show "F A \<le> F B"
hoelzl@56020
    59
    by (simp add: SUP_nat_binary le_iff_sup)
nipkow@21312
    60
qed
nipkow@21312
    61
hoelzl@60636
    62
lemma [order_continuous_intros]:
hoelzl@60614
    63
  shows sup_continuous_const: "sup_continuous (\<lambda>x. c)"
hoelzl@60614
    64
    and sup_continuous_id: "sup_continuous (\<lambda>x. x)"
hoelzl@60614
    65
    and sup_continuous_apply: "sup_continuous (\<lambda>f. f x)"
hoelzl@60614
    66
    and sup_continuous_fun: "(\<And>s. sup_continuous (\<lambda>x. P x s)) \<Longrightarrow> sup_continuous P"
hoelzl@60636
    67
    and sup_continuous_If: "sup_continuous F \<Longrightarrow> sup_continuous G \<Longrightarrow> sup_continuous (\<lambda>f. if C then F f else G f)"
hoelzl@60636
    68
  by (auto simp: sup_continuous_def)
hoelzl@60614
    69
hoelzl@60614
    70
lemma sup_continuous_compose:
hoelzl@60614
    71
  assumes f: "sup_continuous f" and g: "sup_continuous g"
hoelzl@60614
    72
  shows "sup_continuous (\<lambda>x. f (g x))"
hoelzl@60614
    73
  unfolding sup_continuous_def
hoelzl@60614
    74
proof safe
wenzelm@63540
    75
  fix M :: "nat \<Rightarrow> 'c"
wenzelm@63540
    76
  assume M: "mono M"
wenzelm@63540
    77
  then have "mono (\<lambda>i. g (M i))"
hoelzl@60614
    78
    using sup_continuous_mono[OF g] by (auto simp: mono_def)
wenzelm@63540
    79
  with M show "f (g (SUPREMUM UNIV M)) = (SUP i. f (g (M i)))"
hoelzl@60614
    80
    by (auto simp: sup_continuous_def g[THEN sup_continuousD] f[THEN sup_continuousD])
hoelzl@60614
    81
qed
hoelzl@60614
    82
hoelzl@60636
    83
lemma sup_continuous_sup[order_continuous_intros]:
hoelzl@60636
    84
  "sup_continuous f \<Longrightarrow> sup_continuous g \<Longrightarrow> sup_continuous (\<lambda>x. sup (f x) (g x))"
hoelzl@62373
    85
  by (simp add: sup_continuous_def ccSUP_sup_distrib)
hoelzl@60636
    86
hoelzl@60636
    87
lemma sup_continuous_inf[order_continuous_intros]:
hoelzl@62373
    88
  fixes P Q :: "'a :: countable_complete_lattice \<Rightarrow> 'b :: countable_complete_distrib_lattice"
hoelzl@60636
    89
  assumes P: "sup_continuous P" and Q: "sup_continuous Q"
hoelzl@60636
    90
  shows "sup_continuous (\<lambda>x. inf (P x) (Q x))"
hoelzl@60636
    91
  unfolding sup_continuous_def
hoelzl@60636
    92
proof (safe intro!: antisym)
hoelzl@60636
    93
  fix M :: "nat \<Rightarrow> 'a" assume M: "incseq M"
hoelzl@60636
    94
  have "inf (P (SUP i. M i)) (Q (SUP i. M i)) \<le> (SUP j i. inf (P (M i)) (Q (M j)))"
hoelzl@62373
    95
    by (simp add: sup_continuousD[OF P M] sup_continuousD[OF Q M] inf_ccSUP ccSUP_inf)
hoelzl@60636
    96
  also have "\<dots> \<le> (SUP i. inf (P (M i)) (Q (M i)))"
hoelzl@62373
    97
  proof (intro ccSUP_least)
hoelzl@60636
    98
    fix i j from M assms[THEN sup_continuous_mono] show "inf (P (M i)) (Q (M j)) \<le> (SUP i. inf (P (M i)) (Q (M i)))"
hoelzl@62373
    99
      by (intro ccSUP_upper2[of _ "sup i j"] inf_mono) (auto simp: mono_def)
hoelzl@62373
   100
  qed auto
hoelzl@60636
   101
  finally show "inf (P (SUP i. M i)) (Q (SUP i. M i)) \<le> (SUP i. inf (P (M i)) (Q (M i)))" .
hoelzl@62373
   102
hoelzl@60636
   103
  show "(SUP i. inf (P (M i)) (Q (M i))) \<le> inf (P (SUP i. M i)) (Q (SUP i. M i))"
hoelzl@62373
   104
    unfolding sup_continuousD[OF P M] sup_continuousD[OF Q M] by (intro ccSUP_least inf_mono ccSUP_upper) auto
hoelzl@60636
   105
qed
hoelzl@60636
   106
hoelzl@60636
   107
lemma sup_continuous_and[order_continuous_intros]:
hoelzl@60636
   108
  "sup_continuous P \<Longrightarrow> sup_continuous Q \<Longrightarrow> sup_continuous (\<lambda>x. P x \<and> Q x)"
hoelzl@60636
   109
  using sup_continuous_inf[of P Q] by simp
hoelzl@60636
   110
hoelzl@60636
   111
lemma sup_continuous_or[order_continuous_intros]:
hoelzl@60636
   112
  "sup_continuous P \<Longrightarrow> sup_continuous Q \<Longrightarrow> sup_continuous (\<lambda>x. P x \<or> Q x)"
hoelzl@60636
   113
  by (auto simp: sup_continuous_def)
hoelzl@60636
   114
hoelzl@60172
   115
lemma sup_continuous_lfp:
hoelzl@60172
   116
  assumes "sup_continuous F" shows "lfp F = (SUP i. (F ^^ i) bot)" (is "lfp F = ?U")
hoelzl@56020
   117
proof (rule antisym)
wenzelm@60500
   118
  note mono = sup_continuous_mono[OF \<open>sup_continuous F\<close>]
hoelzl@56020
   119
  show "?U \<le> lfp F"
hoelzl@56020
   120
  proof (rule SUP_least)
hoelzl@56020
   121
    fix i show "(F ^^ i) bot \<le> lfp F"
nipkow@21312
   122
    proof (induct i)
nipkow@21312
   123
      case (Suc i)
hoelzl@56020
   124
      have "(F ^^ Suc i) bot = F ((F ^^ i) bot)" by simp
hoelzl@56020
   125
      also have "\<dots> \<le> F (lfp F)" by (rule monoD[OF mono Suc])
wenzelm@63979
   126
      also have "\<dots> = lfp F" by (simp add: lfp_fixpoint[OF mono])
nipkow@21312
   127
      finally show ?case .
hoelzl@56020
   128
    qed simp
hoelzl@56020
   129
  qed
hoelzl@56020
   130
  show "lfp F \<le> ?U"
nipkow@21312
   131
  proof (rule lfp_lowerbound)
hoelzl@56020
   132
    have "mono (\<lambda>i::nat. (F ^^ i) bot)"
nipkow@21312
   133
    proof -
hoelzl@56020
   134
      { fix i::nat have "(F ^^ i) bot \<le> (F ^^ (Suc i)) bot"
wenzelm@32960
   135
        proof (induct i)
wenzelm@32960
   136
          case 0 show ?case by simp
wenzelm@32960
   137
        next
wenzelm@32960
   138
          case Suc thus ?case using monoD[OF mono Suc] by auto
wenzelm@32960
   139
        qed }
hoelzl@56020
   140
      thus ?thesis by (auto simp add: mono_iff_le_Suc)
nipkow@21312
   141
    qed
hoelzl@60172
   142
    hence "F ?U = (SUP i. (F ^^ Suc i) bot)"
wenzelm@60500
   143
      using \<open>sup_continuous F\<close> by (simp add: sup_continuous_def)
hoelzl@60172
   144
    also have "\<dots> \<le> ?U"
hoelzl@60172
   145
      by (fast intro: SUP_least SUP_upper)
nipkow@21312
   146
    finally show "F ?U \<le> ?U" .
nipkow@21312
   147
  qed
nipkow@21312
   148
qed
nipkow@21312
   149
hoelzl@60636
   150
lemma lfp_transfer_bounded:
hoelzl@60636
   151
  assumes P: "P bot" "\<And>x. P x \<Longrightarrow> P (f x)" "\<And>M. (\<And>i. P (M i)) \<Longrightarrow> P (SUP i::nat. M i)"
hoelzl@60636
   152
  assumes \<alpha>: "\<And>M. mono M \<Longrightarrow> (\<And>i::nat. P (M i)) \<Longrightarrow> \<alpha> (SUP i. M i) = (SUP i. \<alpha> (M i))"
hoelzl@60636
   153
  assumes f: "sup_continuous f" and g: "sup_continuous g"
hoelzl@60714
   154
  assumes [simp]: "\<And>x. P x \<Longrightarrow> x \<le> lfp f \<Longrightarrow> \<alpha> (f x) = g (\<alpha> x)"
hoelzl@60636
   155
  assumes g_bound: "\<And>x. \<alpha> bot \<le> g x"
hoelzl@60636
   156
  shows "\<alpha> (lfp f) = lfp g"
hoelzl@60636
   157
proof (rule antisym)
hoelzl@60636
   158
  note mono_g = sup_continuous_mono[OF g]
hoelzl@60714
   159
  note mono_f = sup_continuous_mono[OF f]
hoelzl@60636
   160
  have lfp_bound: "\<alpha> bot \<le> lfp g"
hoelzl@60636
   161
    by (subst lfp_unfold[OF mono_g]) (rule g_bound)
hoelzl@60636
   162
hoelzl@60636
   163
  have P_pow: "P ((f ^^ i) bot)" for i
hoelzl@60636
   164
    by (induction i) (auto intro!: P)
hoelzl@60636
   165
  have incseq_pow: "mono (\<lambda>i. (f ^^ i) bot)"
hoelzl@60636
   166
    unfolding mono_iff_le_Suc
hoelzl@60636
   167
  proof
hoelzl@60636
   168
    fix i show "(f ^^ i) bot \<le> (f ^^ (Suc i)) bot"
hoelzl@60636
   169
    proof (induct i)
hoelzl@60636
   170
      case Suc thus ?case using monoD[OF sup_continuous_mono[OF f] Suc] by auto
hoelzl@60636
   171
    qed (simp add: le_fun_def)
hoelzl@60636
   172
  qed
hoelzl@60636
   173
  have P_lfp: "P (lfp f)"
hoelzl@60636
   174
    using P_pow unfolding sup_continuous_lfp[OF f] by (auto intro!: P)
hoelzl@60636
   175
hoelzl@60714
   176
  have iter_le_lfp: "(f ^^ n) bot \<le> lfp f" for n
hoelzl@60714
   177
    apply (induction n)
hoelzl@60714
   178
    apply simp
hoelzl@60714
   179
    apply (subst lfp_unfold[OF mono_f])
hoelzl@60714
   180
    apply (auto intro!: monoD[OF mono_f])
hoelzl@60714
   181
    done
hoelzl@60714
   182
hoelzl@60636
   183
  have "\<alpha> (lfp f) = (SUP i. \<alpha> ((f^^i) bot))"
hoelzl@60636
   184
    unfolding sup_continuous_lfp[OF f] using incseq_pow P_pow by (rule \<alpha>)
hoelzl@60636
   185
  also have "\<dots> \<le> lfp g"
hoelzl@60636
   186
  proof (rule SUP_least)
hoelzl@60636
   187
    fix i show "\<alpha> ((f^^i) bot) \<le> lfp g"
hoelzl@60636
   188
    proof (induction i)
hoelzl@60636
   189
      case (Suc n) then show ?case
hoelzl@60714
   190
        by (subst lfp_unfold[OF mono_g]) (simp add: monoD[OF mono_g] P_pow iter_le_lfp)
hoelzl@60636
   191
    qed (simp add: lfp_bound)
hoelzl@60636
   192
  qed
hoelzl@60636
   193
  finally show "\<alpha> (lfp f) \<le> lfp g" .
hoelzl@60636
   194
hoelzl@60636
   195
  show "lfp g \<le> \<alpha> (lfp f)"
hoelzl@60636
   196
  proof (induction rule: lfp_ordinal_induct[OF mono_g])
hoelzl@60636
   197
    case (1 S) then show ?case
hoelzl@60636
   198
      by (subst lfp_unfold[OF sup_continuous_mono[OF f]])
hoelzl@60636
   199
         (simp add: monoD[OF mono_g] P_lfp)
hoelzl@60636
   200
  qed (auto intro: Sup_least)
hoelzl@60636
   201
qed
hoelzl@60636
   202
hoelzl@60714
   203
lemma lfp_transfer:
hoelzl@60714
   204
  "sup_continuous \<alpha> \<Longrightarrow> sup_continuous f \<Longrightarrow> sup_continuous g \<Longrightarrow>
hoelzl@60714
   205
    (\<And>x. \<alpha> bot \<le> g x) \<Longrightarrow> (\<And>x. x \<le> lfp f \<Longrightarrow> \<alpha> (f x) = g (\<alpha> x)) \<Longrightarrow> \<alpha> (lfp f) = lfp g"
hoelzl@60714
   206
  by (rule lfp_transfer_bounded[where P=top]) (auto dest: sup_continuousD)
hoelzl@60714
   207
wenzelm@19736
   208
definition
hoelzl@62373
   209
  inf_continuous :: "('a::countable_complete_lattice \<Rightarrow> 'b::countable_complete_lattice) \<Rightarrow> bool"
hoelzl@62373
   210
where
hoelzl@60172
   211
  "inf_continuous F \<longleftrightarrow> (\<forall>M::nat \<Rightarrow> 'a. antimono M \<longrightarrow> F (INF i. M i) = (INF i. F (M i)))"
oheimb@11351
   212
hoelzl@60172
   213
lemma inf_continuousD: "inf_continuous F \<Longrightarrow> antimono M \<Longrightarrow> F (INF i::nat. M i) = (INF i. F (M i))"
hoelzl@60172
   214
  by (auto simp: inf_continuous_def)
oheimb@11351
   215
hoelzl@60172
   216
lemma inf_continuous_mono:
hoelzl@60172
   217
  assumes [simp]: "inf_continuous F" shows "mono F"
hoelzl@56020
   218
proof
hoelzl@56020
   219
  fix A B :: "'a" assume [simp]: "A \<le> B"
hoelzl@56020
   220
  have "F A = F (INF n::nat. if n = 0 then B else A)"
hoelzl@56020
   221
    by (simp add: inf_absorb2 INF_nat_binary)
hoelzl@56020
   222
  also have "\<dots> = (INF n::nat. if n = 0 then F B else F A)"
hoelzl@60172
   223
    by (auto simp: inf_continuousD antimono_def intro!: INF_cong)
hoelzl@56020
   224
  finally show "F A \<le> F B"
hoelzl@56020
   225
    by (simp add: INF_nat_binary le_iff_inf inf_commute)
hoelzl@56020
   226
qed
oheimb@11351
   227
hoelzl@60636
   228
lemma [order_continuous_intros]:
hoelzl@60614
   229
  shows inf_continuous_const: "inf_continuous (\<lambda>x. c)"
hoelzl@60614
   230
    and inf_continuous_id: "inf_continuous (\<lambda>x. x)"
hoelzl@60614
   231
    and inf_continuous_apply: "inf_continuous (\<lambda>f. f x)"
hoelzl@60614
   232
    and inf_continuous_fun: "(\<And>s. inf_continuous (\<lambda>x. P x s)) \<Longrightarrow> inf_continuous P"
hoelzl@60636
   233
    and inf_continuous_If: "inf_continuous F \<Longrightarrow> inf_continuous G \<Longrightarrow> inf_continuous (\<lambda>f. if C then F f else G f)"
hoelzl@60636
   234
  by (auto simp: inf_continuous_def)
hoelzl@60636
   235
hoelzl@60636
   236
lemma inf_continuous_inf[order_continuous_intros]:
hoelzl@60636
   237
  "inf_continuous f \<Longrightarrow> inf_continuous g \<Longrightarrow> inf_continuous (\<lambda>x. inf (f x) (g x))"
hoelzl@62373
   238
  by (simp add: inf_continuous_def ccINF_inf_distrib)
hoelzl@60636
   239
hoelzl@60636
   240
lemma inf_continuous_sup[order_continuous_intros]:
hoelzl@62373
   241
  fixes P Q :: "'a :: countable_complete_lattice \<Rightarrow> 'b :: countable_complete_distrib_lattice"
hoelzl@60636
   242
  assumes P: "inf_continuous P" and Q: "inf_continuous Q"
hoelzl@60636
   243
  shows "inf_continuous (\<lambda>x. sup (P x) (Q x))"
hoelzl@60636
   244
  unfolding inf_continuous_def
hoelzl@60636
   245
proof (safe intro!: antisym)
hoelzl@60636
   246
  fix M :: "nat \<Rightarrow> 'a" assume M: "decseq M"
hoelzl@60636
   247
  show "sup (P (INF i. M i)) (Q (INF i. M i)) \<le> (INF i. sup (P (M i)) (Q (M i)))"
hoelzl@62373
   248
    unfolding inf_continuousD[OF P M] inf_continuousD[OF Q M] by (intro ccINF_greatest sup_mono ccINF_lower) auto
hoelzl@60636
   249
hoelzl@60636
   250
  have "(INF i. sup (P (M i)) (Q (M i))) \<le> (INF j i. sup (P (M i)) (Q (M j)))"
hoelzl@62373
   251
  proof (intro ccINF_greatest)
hoelzl@60636
   252
    fix i j from M assms[THEN inf_continuous_mono] show "sup (P (M i)) (Q (M j)) \<ge> (INF i. sup (P (M i)) (Q (M i)))"
hoelzl@62373
   253
      by (intro ccINF_lower2[of _ "sup i j"] sup_mono) (auto simp: mono_def antimono_def)
hoelzl@62373
   254
  qed auto
hoelzl@60636
   255
  also have "\<dots> \<le> sup (P (INF i. M i)) (Q (INF i. M i))"
hoelzl@62373
   256
    by (simp add: inf_continuousD[OF P M] inf_continuousD[OF Q M] ccINF_sup sup_ccINF)
hoelzl@60636
   257
  finally show "sup (P (INF i. M i)) (Q (INF i. M i)) \<ge> (INF i. sup (P (M i)) (Q (M i)))" .
hoelzl@60636
   258
qed
hoelzl@60636
   259
hoelzl@60636
   260
lemma inf_continuous_and[order_continuous_intros]:
hoelzl@60636
   261
  "inf_continuous P \<Longrightarrow> inf_continuous Q \<Longrightarrow> inf_continuous (\<lambda>x. P x \<and> Q x)"
hoelzl@60636
   262
  using inf_continuous_inf[of P Q] by simp
hoelzl@60636
   263
hoelzl@60636
   264
lemma inf_continuous_or[order_continuous_intros]:
hoelzl@60636
   265
  "inf_continuous P \<Longrightarrow> inf_continuous Q \<Longrightarrow> inf_continuous (\<lambda>x. P x \<or> Q x)"
hoelzl@60636
   266
  using inf_continuous_sup[of P Q] by simp
hoelzl@60614
   267
hoelzl@60614
   268
lemma inf_continuous_compose:
hoelzl@60614
   269
  assumes f: "inf_continuous f" and g: "inf_continuous g"
hoelzl@60614
   270
  shows "inf_continuous (\<lambda>x. f (g x))"
hoelzl@60614
   271
  unfolding inf_continuous_def
hoelzl@60614
   272
proof safe
wenzelm@63540
   273
  fix M :: "nat \<Rightarrow> 'c"
wenzelm@63540
   274
  assume M: "antimono M"
wenzelm@63540
   275
  then have "antimono (\<lambda>i. g (M i))"
hoelzl@60614
   276
    using inf_continuous_mono[OF g] by (auto simp: mono_def antimono_def)
wenzelm@63540
   277
  with M show "f (g (INFIMUM UNIV M)) = (INF i. f (g (M i)))"
hoelzl@60614
   278
    by (auto simp: inf_continuous_def g[THEN inf_continuousD] f[THEN inf_continuousD])
hoelzl@60614
   279
qed
hoelzl@60614
   280
hoelzl@60172
   281
lemma inf_continuous_gfp:
hoelzl@60172
   282
  assumes "inf_continuous F" shows "gfp F = (INF i. (F ^^ i) top)" (is "gfp F = ?U")
hoelzl@56020
   283
proof (rule antisym)
wenzelm@60500
   284
  note mono = inf_continuous_mono[OF \<open>inf_continuous F\<close>]
hoelzl@56020
   285
  show "gfp F \<le> ?U"
hoelzl@56020
   286
  proof (rule INF_greatest)
hoelzl@56020
   287
    fix i show "gfp F \<le> (F ^^ i) top"
hoelzl@56020
   288
    proof (induct i)
hoelzl@56020
   289
      case (Suc i)
wenzelm@63979
   290
      have "gfp F = F (gfp F)" by (simp add: gfp_fixpoint[OF mono])
hoelzl@56020
   291
      also have "\<dots> \<le> F ((F ^^ i) top)" by (rule monoD[OF mono Suc])
hoelzl@56020
   292
      also have "\<dots> = (F ^^ Suc i) top" by simp
hoelzl@56020
   293
      finally show ?case .
hoelzl@56020
   294
    qed simp
hoelzl@56020
   295
  qed
hoelzl@56020
   296
  show "?U \<le> gfp F"
hoelzl@56020
   297
  proof (rule gfp_upperbound)
hoelzl@56020
   298
    have *: "antimono (\<lambda>i::nat. (F ^^ i) top)"
hoelzl@56020
   299
    proof -
hoelzl@56020
   300
      { fix i::nat have "(F ^^ Suc i) top \<le> (F ^^ i) top"
hoelzl@56020
   301
        proof (induct i)
hoelzl@56020
   302
          case 0 show ?case by simp
hoelzl@56020
   303
        next
hoelzl@56020
   304
          case Suc thus ?case using monoD[OF mono Suc] by auto
hoelzl@56020
   305
        qed }
hoelzl@56020
   306
      thus ?thesis by (auto simp add: antimono_iff_le_Suc)
hoelzl@56020
   307
    qed
hoelzl@56020
   308
    have "?U \<le> (INF i. (F ^^ Suc i) top)"
hoelzl@56020
   309
      by (fast intro: INF_greatest INF_lower)
hoelzl@56020
   310
    also have "\<dots> \<le> F ?U"
wenzelm@60500
   311
      by (simp add: inf_continuousD \<open>inf_continuous F\<close> *)
hoelzl@56020
   312
    finally show "?U \<le> F ?U" .
hoelzl@56020
   313
  qed
hoelzl@56020
   314
qed
oheimb@11351
   315
hoelzl@60427
   316
lemma gfp_transfer:
hoelzl@60427
   317
  assumes \<alpha>: "inf_continuous \<alpha>" and f: "inf_continuous f" and g: "inf_continuous g"
hoelzl@60427
   318
  assumes [simp]: "\<alpha> top = top" "\<And>x. \<alpha> (f x) = g (\<alpha> x)"
hoelzl@60427
   319
  shows "\<alpha> (gfp f) = gfp g"
hoelzl@60427
   320
proof -
hoelzl@60427
   321
  have "\<alpha> (gfp f) = (INF i. \<alpha> ((f^^i) top))"
hoelzl@60427
   322
    unfolding inf_continuous_gfp[OF f] by (intro f \<alpha> inf_continuousD antimono_funpow inf_continuous_mono)
hoelzl@60427
   323
  moreover have "\<alpha> ((f^^i) top) = (g^^i) top" for i
hoelzl@60427
   324
    by (induction i; simp)
hoelzl@60427
   325
  ultimately show ?thesis
hoelzl@60427
   326
    unfolding inf_continuous_gfp[OF g] by simp
hoelzl@60427
   327
qed
hoelzl@60427
   328
hoelzl@60636
   329
lemma gfp_transfer_bounded:
hoelzl@60636
   330
  assumes P: "P (f top)" "\<And>x. P x \<Longrightarrow> P (f x)" "\<And>M. antimono M \<Longrightarrow> (\<And>i. P (M i)) \<Longrightarrow> P (INF i::nat. M i)"
hoelzl@60636
   331
  assumes \<alpha>: "\<And>M. antimono M \<Longrightarrow> (\<And>i::nat. P (M i)) \<Longrightarrow> \<alpha> (INF i. M i) = (INF i. \<alpha> (M i))"
hoelzl@60636
   332
  assumes f: "inf_continuous f" and g: "inf_continuous g"
hoelzl@60636
   333
  assumes [simp]: "\<And>x. P x \<Longrightarrow> \<alpha> (f x) = g (\<alpha> x)"
hoelzl@60636
   334
  assumes g_bound: "\<And>x. g x \<le> \<alpha> (f top)"
hoelzl@60636
   335
  shows "\<alpha> (gfp f) = gfp g"
hoelzl@60636
   336
proof (rule antisym)
hoelzl@60636
   337
  note mono_g = inf_continuous_mono[OF g]
hoelzl@60636
   338
hoelzl@60636
   339
  have P_pow: "P ((f ^^ i) (f top))" for i
hoelzl@60636
   340
    by (induction i) (auto intro!: P)
hoelzl@60636
   341
hoelzl@60636
   342
  have antimono_pow: "antimono (\<lambda>i. (f ^^ i) top)"
hoelzl@60636
   343
    unfolding antimono_iff_le_Suc
hoelzl@60636
   344
  proof
hoelzl@60636
   345
    fix i show "(f ^^ Suc i) top \<le> (f ^^ i) top"
hoelzl@60636
   346
    proof (induct i)
hoelzl@60636
   347
      case Suc thus ?case using monoD[OF inf_continuous_mono[OF f] Suc] by auto
hoelzl@60636
   348
    qed (simp add: le_fun_def)
hoelzl@60636
   349
  qed
hoelzl@60636
   350
  have antimono_pow2: "antimono (\<lambda>i. (f ^^ i) (f top))"
hoelzl@60636
   351
  proof
hoelzl@60636
   352
    show "x \<le> y \<Longrightarrow> (f ^^ y) (f top) \<le> (f ^^ x) (f top)" for x y
hoelzl@60636
   353
      using antimono_pow[THEN antimonoD, of "Suc x" "Suc y"]
hoelzl@60636
   354
      unfolding funpow_Suc_right by simp
hoelzl@60636
   355
  qed
hoelzl@62373
   356
hoelzl@60636
   357
  have gfp_f: "gfp f = (INF i. (f ^^ i) (f top))"
hoelzl@60636
   358
    unfolding inf_continuous_gfp[OF f]
hoelzl@60636
   359
  proof (rule INF_eq)
hoelzl@60636
   360
    show "\<exists>j\<in>UNIV. (f ^^ j) (f top) \<le> (f ^^ i) top" for i
hoelzl@60636
   361
      by (intro bexI[of _ "i - 1"]) (auto simp: diff_Suc funpow_Suc_right simp del: funpow.simps(2) split: nat.split)
hoelzl@60636
   362
    show "\<exists>j\<in>UNIV. (f ^^ j) top \<le> (f ^^ i) (f top)" for i
hoelzl@60636
   363
      by (intro bexI[of _ "Suc i"]) (auto simp: funpow_Suc_right simp del: funpow.simps(2))
hoelzl@60636
   364
  qed
hoelzl@60636
   365
hoelzl@60636
   366
  have P_lfp: "P (gfp f)"
hoelzl@60636
   367
    unfolding gfp_f by (auto intro!: P P_pow antimono_pow2)
hoelzl@60636
   368
hoelzl@60636
   369
  have "\<alpha> (gfp f) = (INF i. \<alpha> ((f^^i) (f top)))"
hoelzl@60636
   370
    unfolding gfp_f by (rule \<alpha>) (auto intro!: P_pow antimono_pow2)
hoelzl@60636
   371
  also have "\<dots> \<ge> gfp g"
hoelzl@60636
   372
  proof (rule INF_greatest)
hoelzl@60636
   373
    fix i show "gfp g \<le> \<alpha> ((f^^i) (f top))"
hoelzl@60636
   374
    proof (induction i)
hoelzl@60636
   375
      case (Suc n) then show ?case
hoelzl@60636
   376
        by (subst gfp_unfold[OF mono_g]) (simp add: monoD[OF mono_g] P_pow)
hoelzl@60636
   377
    next
hoelzl@60636
   378
      case 0
hoelzl@60636
   379
      have "gfp g \<le> \<alpha> (f top)"
hoelzl@60636
   380
        by (subst gfp_unfold[OF mono_g]) (rule g_bound)
hoelzl@60636
   381
      then show ?case
hoelzl@60636
   382
        by simp
hoelzl@60636
   383
    qed
hoelzl@60636
   384
  qed
hoelzl@60636
   385
  finally show "gfp g \<le> \<alpha> (gfp f)" .
hoelzl@60636
   386
hoelzl@60636
   387
  show "\<alpha> (gfp f) \<le> gfp g"
hoelzl@60636
   388
  proof (induction rule: gfp_ordinal_induct[OF mono_g])
hoelzl@60636
   389
    case (1 S) then show ?case
hoelzl@60636
   390
      by (subst gfp_unfold[OF inf_continuous_mono[OF f]])
hoelzl@60636
   391
         (simp add: monoD[OF mono_g] P_lfp)
hoelzl@60636
   392
  qed (auto intro: Inf_greatest)
hoelzl@60636
   393
qed
hoelzl@60636
   394
hoelzl@62373
   395
subsubsection \<open>Least fixed points in countable complete lattices\<close>
hoelzl@62373
   396
hoelzl@62373
   397
definition (in countable_complete_lattice) cclfp :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a"
hoelzl@62374
   398
  where "cclfp f = (SUP i. (f ^^ i) bot)"
hoelzl@62373
   399
hoelzl@62373
   400
lemma cclfp_unfold:
hoelzl@62373
   401
  assumes "sup_continuous F" shows "cclfp F = F (cclfp F)"
hoelzl@62373
   402
proof -
hoelzl@62374
   403
  have "cclfp F = (SUP i. F ((F ^^ i) bot))"
hoelzl@62373
   404
    unfolding cclfp_def by (subst UNIV_nat_eq) auto
hoelzl@62373
   405
  also have "\<dots> = F (cclfp F)"
hoelzl@62373
   406
    unfolding cclfp_def
hoelzl@62373
   407
    by (intro sup_continuousD[symmetric] assms mono_funpow sup_continuous_mono)
hoelzl@62373
   408
  finally show ?thesis .
hoelzl@62373
   409
qed
hoelzl@62373
   410
hoelzl@62373
   411
lemma cclfp_lowerbound: assumes f: "mono f" and A: "f A \<le> A" shows "cclfp f \<le> A"
hoelzl@62373
   412
  unfolding cclfp_def
hoelzl@62373
   413
proof (intro ccSUP_least)
hoelzl@62374
   414
  fix i show "(f ^^ i) bot \<le> A"
hoelzl@62373
   415
  proof (induction i)
hoelzl@62373
   416
    case (Suc i) from monoD[OF f this] A show ?case
hoelzl@62373
   417
      by auto
hoelzl@62373
   418
  qed simp
hoelzl@62373
   419
qed simp
hoelzl@62373
   420
hoelzl@62373
   421
lemma cclfp_transfer:
hoelzl@62373
   422
  assumes "sup_continuous \<alpha>" "mono f"
hoelzl@62374
   423
  assumes "\<alpha> bot = bot" "\<And>x. \<alpha> (f x) = g (\<alpha> x)"
hoelzl@62373
   424
  shows "\<alpha> (cclfp f) = cclfp g"
hoelzl@62373
   425
proof -
hoelzl@62374
   426
  have "\<alpha> (cclfp f) = (SUP i. \<alpha> ((f ^^ i) bot))"
hoelzl@62373
   427
    unfolding cclfp_def by (intro sup_continuousD assms mono_funpow sup_continuous_mono)
hoelzl@62374
   428
  moreover have "\<alpha> ((f ^^ i) bot) = (g ^^ i) bot" for i
hoelzl@62373
   429
    by (induction i) (simp_all add: assms)
hoelzl@62373
   430
  ultimately show ?thesis
hoelzl@62373
   431
    by (simp add: cclfp_def)
hoelzl@62373
   432
qed
hoelzl@62373
   433
oheimb@11351
   434
end