src/HOL/Library/Order_Continuity.thy
author hoelzl
Fri Feb 19 12:25:57 2016 +0100 (2016-02-19)
changeset 62374 cb27a55d868a
parent 62373 ea7a442e9a56
child 63540 f8652d0534fa
permissions -rw-r--r--
remove lattice syntax from countable complete lattice
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
hoelzl@60614
    75
  fix M :: "nat \<Rightarrow> 'c" assume "mono M"
hoelzl@60614
    76
  moreover then have "mono (\<lambda>i. g (M i))"
hoelzl@60614
    77
    using sup_continuous_mono[OF g] by (auto simp: mono_def)
hoelzl@60614
    78
  ultimately show "f (g (SUPREMUM UNIV M)) = (SUP i. f (g (M i)))"
hoelzl@60614
    79
    by (auto simp: sup_continuous_def g[THEN sup_continuousD] f[THEN sup_continuousD])
hoelzl@60614
    80
qed
hoelzl@60614
    81
hoelzl@60636
    82
lemma sup_continuous_sup[order_continuous_intros]:
hoelzl@60636
    83
  "sup_continuous f \<Longrightarrow> sup_continuous g \<Longrightarrow> sup_continuous (\<lambda>x. sup (f x) (g x))"
hoelzl@62373
    84
  by (simp add: sup_continuous_def ccSUP_sup_distrib)
hoelzl@60636
    85
hoelzl@60636
    86
lemma sup_continuous_inf[order_continuous_intros]:
hoelzl@62373
    87
  fixes P Q :: "'a :: countable_complete_lattice \<Rightarrow> 'b :: countable_complete_distrib_lattice"
hoelzl@60636
    88
  assumes P: "sup_continuous P" and Q: "sup_continuous Q"
hoelzl@60636
    89
  shows "sup_continuous (\<lambda>x. inf (P x) (Q x))"
hoelzl@60636
    90
  unfolding sup_continuous_def
hoelzl@60636
    91
proof (safe intro!: antisym)
hoelzl@60636
    92
  fix M :: "nat \<Rightarrow> 'a" assume M: "incseq M"
hoelzl@60636
    93
  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
    94
    by (simp add: sup_continuousD[OF P M] sup_continuousD[OF Q M] inf_ccSUP ccSUP_inf)
hoelzl@60636
    95
  also have "\<dots> \<le> (SUP i. inf (P (M i)) (Q (M i)))"
hoelzl@62373
    96
  proof (intro ccSUP_least)
hoelzl@60636
    97
    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
    98
      by (intro ccSUP_upper2[of _ "sup i j"] inf_mono) (auto simp: mono_def)
hoelzl@62373
    99
  qed auto
hoelzl@60636
   100
  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
   101
hoelzl@60636
   102
  show "(SUP i. inf (P (M i)) (Q (M i))) \<le> inf (P (SUP i. M i)) (Q (SUP i. M i))"
hoelzl@62373
   103
    unfolding sup_continuousD[OF P M] sup_continuousD[OF Q M] by (intro ccSUP_least inf_mono ccSUP_upper) auto
hoelzl@60636
   104
qed
hoelzl@60636
   105
hoelzl@60636
   106
lemma sup_continuous_and[order_continuous_intros]:
hoelzl@60636
   107
  "sup_continuous P \<Longrightarrow> sup_continuous Q \<Longrightarrow> sup_continuous (\<lambda>x. P x \<and> Q x)"
hoelzl@60636
   108
  using sup_continuous_inf[of P Q] by simp
hoelzl@60636
   109
hoelzl@60636
   110
lemma sup_continuous_or[order_continuous_intros]:
hoelzl@60636
   111
  "sup_continuous P \<Longrightarrow> sup_continuous Q \<Longrightarrow> sup_continuous (\<lambda>x. P x \<or> Q x)"
hoelzl@60636
   112
  by (auto simp: sup_continuous_def)
hoelzl@60636
   113
hoelzl@60172
   114
lemma sup_continuous_lfp:
hoelzl@60172
   115
  assumes "sup_continuous F" shows "lfp F = (SUP i. (F ^^ i) bot)" (is "lfp F = ?U")
hoelzl@56020
   116
proof (rule antisym)
wenzelm@60500
   117
  note mono = sup_continuous_mono[OF \<open>sup_continuous F\<close>]
hoelzl@56020
   118
  show "?U \<le> lfp F"
hoelzl@56020
   119
  proof (rule SUP_least)
hoelzl@56020
   120
    fix i show "(F ^^ i) bot \<le> lfp F"
nipkow@21312
   121
    proof (induct i)
nipkow@21312
   122
      case (Suc i)
hoelzl@56020
   123
      have "(F ^^ Suc i) bot = F ((F ^^ i) bot)" by simp
hoelzl@56020
   124
      also have "\<dots> \<le> F (lfp F)" by (rule monoD[OF mono Suc])
hoelzl@56020
   125
      also have "\<dots> = lfp F" by (simp add: lfp_unfold[OF mono, symmetric])
nipkow@21312
   126
      finally show ?case .
hoelzl@56020
   127
    qed simp
hoelzl@56020
   128
  qed
hoelzl@56020
   129
  show "lfp F \<le> ?U"
nipkow@21312
   130
  proof (rule lfp_lowerbound)
hoelzl@56020
   131
    have "mono (\<lambda>i::nat. (F ^^ i) bot)"
nipkow@21312
   132
    proof -
hoelzl@56020
   133
      { fix i::nat have "(F ^^ i) bot \<le> (F ^^ (Suc i)) bot"
wenzelm@32960
   134
        proof (induct i)
wenzelm@32960
   135
          case 0 show ?case by simp
wenzelm@32960
   136
        next
wenzelm@32960
   137
          case Suc thus ?case using monoD[OF mono Suc] by auto
wenzelm@32960
   138
        qed }
hoelzl@56020
   139
      thus ?thesis by (auto simp add: mono_iff_le_Suc)
nipkow@21312
   140
    qed
hoelzl@60172
   141
    hence "F ?U = (SUP i. (F ^^ Suc i) bot)"
wenzelm@60500
   142
      using \<open>sup_continuous F\<close> by (simp add: sup_continuous_def)
hoelzl@60172
   143
    also have "\<dots> \<le> ?U"
hoelzl@60172
   144
      by (fast intro: SUP_least SUP_upper)
nipkow@21312
   145
    finally show "F ?U \<le> ?U" .
nipkow@21312
   146
  qed
nipkow@21312
   147
qed
nipkow@21312
   148
hoelzl@60636
   149
lemma lfp_transfer_bounded:
hoelzl@60636
   150
  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
   151
  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
   152
  assumes f: "sup_continuous f" and g: "sup_continuous g"
hoelzl@60714
   153
  assumes [simp]: "\<And>x. P x \<Longrightarrow> x \<le> lfp f \<Longrightarrow> \<alpha> (f x) = g (\<alpha> x)"
hoelzl@60636
   154
  assumes g_bound: "\<And>x. \<alpha> bot \<le> g x"
hoelzl@60636
   155
  shows "\<alpha> (lfp f) = lfp g"
hoelzl@60636
   156
proof (rule antisym)
hoelzl@60636
   157
  note mono_g = sup_continuous_mono[OF g]
hoelzl@60714
   158
  note mono_f = sup_continuous_mono[OF f]
hoelzl@60636
   159
  have lfp_bound: "\<alpha> bot \<le> lfp g"
hoelzl@60636
   160
    by (subst lfp_unfold[OF mono_g]) (rule g_bound)
hoelzl@60636
   161
hoelzl@60636
   162
  have P_pow: "P ((f ^^ i) bot)" for i
hoelzl@60636
   163
    by (induction i) (auto intro!: P)
hoelzl@60636
   164
  have incseq_pow: "mono (\<lambda>i. (f ^^ i) bot)"
hoelzl@60636
   165
    unfolding mono_iff_le_Suc
hoelzl@60636
   166
  proof
hoelzl@60636
   167
    fix i show "(f ^^ i) bot \<le> (f ^^ (Suc i)) bot"
hoelzl@60636
   168
    proof (induct i)
hoelzl@60636
   169
      case Suc thus ?case using monoD[OF sup_continuous_mono[OF f] Suc] by auto
hoelzl@60636
   170
    qed (simp add: le_fun_def)
hoelzl@60636
   171
  qed
hoelzl@60636
   172
  have P_lfp: "P (lfp f)"
hoelzl@60636
   173
    using P_pow unfolding sup_continuous_lfp[OF f] by (auto intro!: P)
hoelzl@60636
   174
hoelzl@60714
   175
  have iter_le_lfp: "(f ^^ n) bot \<le> lfp f" for n
hoelzl@60714
   176
    apply (induction n)
hoelzl@60714
   177
    apply simp
hoelzl@60714
   178
    apply (subst lfp_unfold[OF mono_f])
hoelzl@60714
   179
    apply (auto intro!: monoD[OF mono_f])
hoelzl@60714
   180
    done
hoelzl@60714
   181
hoelzl@60636
   182
  have "\<alpha> (lfp f) = (SUP i. \<alpha> ((f^^i) bot))"
hoelzl@60636
   183
    unfolding sup_continuous_lfp[OF f] using incseq_pow P_pow by (rule \<alpha>)
hoelzl@60636
   184
  also have "\<dots> \<le> lfp g"
hoelzl@60636
   185
  proof (rule SUP_least)
hoelzl@60636
   186
    fix i show "\<alpha> ((f^^i) bot) \<le> lfp g"
hoelzl@60636
   187
    proof (induction i)
hoelzl@60636
   188
      case (Suc n) then show ?case
hoelzl@60714
   189
        by (subst lfp_unfold[OF mono_g]) (simp add: monoD[OF mono_g] P_pow iter_le_lfp)
hoelzl@60636
   190
    qed (simp add: lfp_bound)
hoelzl@60636
   191
  qed
hoelzl@60636
   192
  finally show "\<alpha> (lfp f) \<le> lfp g" .
hoelzl@60636
   193
hoelzl@60636
   194
  show "lfp g \<le> \<alpha> (lfp f)"
hoelzl@60636
   195
  proof (induction rule: lfp_ordinal_induct[OF mono_g])
hoelzl@60636
   196
    case (1 S) then show ?case
hoelzl@60636
   197
      by (subst lfp_unfold[OF sup_continuous_mono[OF f]])
hoelzl@60636
   198
         (simp add: monoD[OF mono_g] P_lfp)
hoelzl@60636
   199
  qed (auto intro: Sup_least)
hoelzl@60636
   200
qed
hoelzl@60636
   201
hoelzl@60714
   202
lemma lfp_transfer:
hoelzl@60714
   203
  "sup_continuous \<alpha> \<Longrightarrow> sup_continuous f \<Longrightarrow> sup_continuous g \<Longrightarrow>
hoelzl@60714
   204
    (\<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
   205
  by (rule lfp_transfer_bounded[where P=top]) (auto dest: sup_continuousD)
hoelzl@60714
   206
wenzelm@19736
   207
definition
hoelzl@62373
   208
  inf_continuous :: "('a::countable_complete_lattice \<Rightarrow> 'b::countable_complete_lattice) \<Rightarrow> bool"
hoelzl@62373
   209
where
hoelzl@60172
   210
  "inf_continuous F \<longleftrightarrow> (\<forall>M::nat \<Rightarrow> 'a. antimono M \<longrightarrow> F (INF i. M i) = (INF i. F (M i)))"
oheimb@11351
   211
hoelzl@60172
   212
lemma inf_continuousD: "inf_continuous F \<Longrightarrow> antimono M \<Longrightarrow> F (INF i::nat. M i) = (INF i. F (M i))"
hoelzl@60172
   213
  by (auto simp: inf_continuous_def)
oheimb@11351
   214
hoelzl@60172
   215
lemma inf_continuous_mono:
hoelzl@60172
   216
  assumes [simp]: "inf_continuous F" shows "mono F"
hoelzl@56020
   217
proof
hoelzl@56020
   218
  fix A B :: "'a" assume [simp]: "A \<le> B"
hoelzl@56020
   219
  have "F A = F (INF n::nat. if n = 0 then B else A)"
hoelzl@56020
   220
    by (simp add: inf_absorb2 INF_nat_binary)
hoelzl@56020
   221
  also have "\<dots> = (INF n::nat. if n = 0 then F B else F A)"
hoelzl@60172
   222
    by (auto simp: inf_continuousD antimono_def intro!: INF_cong)
hoelzl@56020
   223
  finally show "F A \<le> F B"
hoelzl@56020
   224
    by (simp add: INF_nat_binary le_iff_inf inf_commute)
hoelzl@56020
   225
qed
oheimb@11351
   226
hoelzl@60636
   227
lemma [order_continuous_intros]:
hoelzl@60614
   228
  shows inf_continuous_const: "inf_continuous (\<lambda>x. c)"
hoelzl@60614
   229
    and inf_continuous_id: "inf_continuous (\<lambda>x. x)"
hoelzl@60614
   230
    and inf_continuous_apply: "inf_continuous (\<lambda>f. f x)"
hoelzl@60614
   231
    and inf_continuous_fun: "(\<And>s. inf_continuous (\<lambda>x. P x s)) \<Longrightarrow> inf_continuous P"
hoelzl@60636
   232
    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
   233
  by (auto simp: inf_continuous_def)
hoelzl@60636
   234
hoelzl@60636
   235
lemma inf_continuous_inf[order_continuous_intros]:
hoelzl@60636
   236
  "inf_continuous f \<Longrightarrow> inf_continuous g \<Longrightarrow> inf_continuous (\<lambda>x. inf (f x) (g x))"
hoelzl@62373
   237
  by (simp add: inf_continuous_def ccINF_inf_distrib)
hoelzl@60636
   238
hoelzl@60636
   239
lemma inf_continuous_sup[order_continuous_intros]:
hoelzl@62373
   240
  fixes P Q :: "'a :: countable_complete_lattice \<Rightarrow> 'b :: countable_complete_distrib_lattice"
hoelzl@60636
   241
  assumes P: "inf_continuous P" and Q: "inf_continuous Q"
hoelzl@60636
   242
  shows "inf_continuous (\<lambda>x. sup (P x) (Q x))"
hoelzl@60636
   243
  unfolding inf_continuous_def
hoelzl@60636
   244
proof (safe intro!: antisym)
hoelzl@60636
   245
  fix M :: "nat \<Rightarrow> 'a" assume M: "decseq M"
hoelzl@60636
   246
  show "sup (P (INF i. M i)) (Q (INF i. M i)) \<le> (INF i. sup (P (M i)) (Q (M i)))"
hoelzl@62373
   247
    unfolding inf_continuousD[OF P M] inf_continuousD[OF Q M] by (intro ccINF_greatest sup_mono ccINF_lower) auto
hoelzl@60636
   248
hoelzl@60636
   249
  have "(INF i. sup (P (M i)) (Q (M i))) \<le> (INF j i. sup (P (M i)) (Q (M j)))"
hoelzl@62373
   250
  proof (intro ccINF_greatest)
hoelzl@60636
   251
    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
   252
      by (intro ccINF_lower2[of _ "sup i j"] sup_mono) (auto simp: mono_def antimono_def)
hoelzl@62373
   253
  qed auto
hoelzl@60636
   254
  also have "\<dots> \<le> sup (P (INF i. M i)) (Q (INF i. M i))"
hoelzl@62373
   255
    by (simp add: inf_continuousD[OF P M] inf_continuousD[OF Q M] ccINF_sup sup_ccINF)
hoelzl@60636
   256
  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
   257
qed
hoelzl@60636
   258
hoelzl@60636
   259
lemma inf_continuous_and[order_continuous_intros]:
hoelzl@60636
   260
  "inf_continuous P \<Longrightarrow> inf_continuous Q \<Longrightarrow> inf_continuous (\<lambda>x. P x \<and> Q x)"
hoelzl@60636
   261
  using inf_continuous_inf[of P Q] by simp
hoelzl@60636
   262
hoelzl@60636
   263
lemma inf_continuous_or[order_continuous_intros]:
hoelzl@60636
   264
  "inf_continuous P \<Longrightarrow> inf_continuous Q \<Longrightarrow> inf_continuous (\<lambda>x. P x \<or> Q x)"
hoelzl@60636
   265
  using inf_continuous_sup[of P Q] by simp
hoelzl@60614
   266
hoelzl@60614
   267
lemma inf_continuous_compose:
hoelzl@60614
   268
  assumes f: "inf_continuous f" and g: "inf_continuous g"
hoelzl@60614
   269
  shows "inf_continuous (\<lambda>x. f (g x))"
hoelzl@60614
   270
  unfolding inf_continuous_def
hoelzl@60614
   271
proof safe
hoelzl@60614
   272
  fix M :: "nat \<Rightarrow> 'c" assume "antimono M"
hoelzl@60614
   273
  moreover then have "antimono (\<lambda>i. g (M i))"
hoelzl@60614
   274
    using inf_continuous_mono[OF g] by (auto simp: mono_def antimono_def)
hoelzl@60614
   275
  ultimately show "f (g (INFIMUM UNIV M)) = (INF i. f (g (M i)))"
hoelzl@60614
   276
    by (auto simp: inf_continuous_def g[THEN inf_continuousD] f[THEN inf_continuousD])
hoelzl@60614
   277
qed
hoelzl@60614
   278
hoelzl@60172
   279
lemma inf_continuous_gfp:
hoelzl@60172
   280
  assumes "inf_continuous F" shows "gfp F = (INF i. (F ^^ i) top)" (is "gfp F = ?U")
hoelzl@56020
   281
proof (rule antisym)
wenzelm@60500
   282
  note mono = inf_continuous_mono[OF \<open>inf_continuous F\<close>]
hoelzl@56020
   283
  show "gfp F \<le> ?U"
hoelzl@56020
   284
  proof (rule INF_greatest)
hoelzl@56020
   285
    fix i show "gfp F \<le> (F ^^ i) top"
hoelzl@56020
   286
    proof (induct i)
hoelzl@56020
   287
      case (Suc i)
hoelzl@56020
   288
      have "gfp F = F (gfp F)" by (simp add: gfp_unfold[OF mono, symmetric])
hoelzl@56020
   289
      also have "\<dots> \<le> F ((F ^^ i) top)" by (rule monoD[OF mono Suc])
hoelzl@56020
   290
      also have "\<dots> = (F ^^ Suc i) top" by simp
hoelzl@56020
   291
      finally show ?case .
hoelzl@56020
   292
    qed simp
hoelzl@56020
   293
  qed
hoelzl@56020
   294
  show "?U \<le> gfp F"
hoelzl@56020
   295
  proof (rule gfp_upperbound)
hoelzl@56020
   296
    have *: "antimono (\<lambda>i::nat. (F ^^ i) top)"
hoelzl@56020
   297
    proof -
hoelzl@56020
   298
      { fix i::nat have "(F ^^ Suc i) top \<le> (F ^^ i) top"
hoelzl@56020
   299
        proof (induct i)
hoelzl@56020
   300
          case 0 show ?case by simp
hoelzl@56020
   301
        next
hoelzl@56020
   302
          case Suc thus ?case using monoD[OF mono Suc] by auto
hoelzl@56020
   303
        qed }
hoelzl@56020
   304
      thus ?thesis by (auto simp add: antimono_iff_le_Suc)
hoelzl@56020
   305
    qed
hoelzl@56020
   306
    have "?U \<le> (INF i. (F ^^ Suc i) top)"
hoelzl@56020
   307
      by (fast intro: INF_greatest INF_lower)
hoelzl@56020
   308
    also have "\<dots> \<le> F ?U"
wenzelm@60500
   309
      by (simp add: inf_continuousD \<open>inf_continuous F\<close> *)
hoelzl@56020
   310
    finally show "?U \<le> F ?U" .
hoelzl@56020
   311
  qed
hoelzl@56020
   312
qed
oheimb@11351
   313
hoelzl@60427
   314
lemma gfp_transfer:
hoelzl@60427
   315
  assumes \<alpha>: "inf_continuous \<alpha>" and f: "inf_continuous f" and g: "inf_continuous g"
hoelzl@60427
   316
  assumes [simp]: "\<alpha> top = top" "\<And>x. \<alpha> (f x) = g (\<alpha> x)"
hoelzl@60427
   317
  shows "\<alpha> (gfp f) = gfp g"
hoelzl@60427
   318
proof -
hoelzl@60427
   319
  have "\<alpha> (gfp f) = (INF i. \<alpha> ((f^^i) top))"
hoelzl@60427
   320
    unfolding inf_continuous_gfp[OF f] by (intro f \<alpha> inf_continuousD antimono_funpow inf_continuous_mono)
hoelzl@60427
   321
  moreover have "\<alpha> ((f^^i) top) = (g^^i) top" for i
hoelzl@60427
   322
    by (induction i; simp)
hoelzl@60427
   323
  ultimately show ?thesis
hoelzl@60427
   324
    unfolding inf_continuous_gfp[OF g] by simp
hoelzl@60427
   325
qed
hoelzl@60427
   326
hoelzl@60636
   327
lemma gfp_transfer_bounded:
hoelzl@60636
   328
  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
   329
  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
   330
  assumes f: "inf_continuous f" and g: "inf_continuous g"
hoelzl@60636
   331
  assumes [simp]: "\<And>x. P x \<Longrightarrow> \<alpha> (f x) = g (\<alpha> x)"
hoelzl@60636
   332
  assumes g_bound: "\<And>x. g x \<le> \<alpha> (f top)"
hoelzl@60636
   333
  shows "\<alpha> (gfp f) = gfp g"
hoelzl@60636
   334
proof (rule antisym)
hoelzl@60636
   335
  note mono_g = inf_continuous_mono[OF g]
hoelzl@60636
   336
hoelzl@60636
   337
  have P_pow: "P ((f ^^ i) (f top))" for i
hoelzl@60636
   338
    by (induction i) (auto intro!: P)
hoelzl@60636
   339
hoelzl@60636
   340
  have antimono_pow: "antimono (\<lambda>i. (f ^^ i) top)"
hoelzl@60636
   341
    unfolding antimono_iff_le_Suc
hoelzl@60636
   342
  proof
hoelzl@60636
   343
    fix i show "(f ^^ Suc i) top \<le> (f ^^ i) top"
hoelzl@60636
   344
    proof (induct i)
hoelzl@60636
   345
      case Suc thus ?case using monoD[OF inf_continuous_mono[OF f] Suc] by auto
hoelzl@60636
   346
    qed (simp add: le_fun_def)
hoelzl@60636
   347
  qed
hoelzl@60636
   348
  have antimono_pow2: "antimono (\<lambda>i. (f ^^ i) (f top))"
hoelzl@60636
   349
  proof
hoelzl@60636
   350
    show "x \<le> y \<Longrightarrow> (f ^^ y) (f top) \<le> (f ^^ x) (f top)" for x y
hoelzl@60636
   351
      using antimono_pow[THEN antimonoD, of "Suc x" "Suc y"]
hoelzl@60636
   352
      unfolding funpow_Suc_right by simp
hoelzl@60636
   353
  qed
hoelzl@62373
   354
hoelzl@60636
   355
  have gfp_f: "gfp f = (INF i. (f ^^ i) (f top))"
hoelzl@60636
   356
    unfolding inf_continuous_gfp[OF f]
hoelzl@60636
   357
  proof (rule INF_eq)
hoelzl@60636
   358
    show "\<exists>j\<in>UNIV. (f ^^ j) (f top) \<le> (f ^^ i) top" for i
hoelzl@60636
   359
      by (intro bexI[of _ "i - 1"]) (auto simp: diff_Suc funpow_Suc_right simp del: funpow.simps(2) split: nat.split)
hoelzl@60636
   360
    show "\<exists>j\<in>UNIV. (f ^^ j) top \<le> (f ^^ i) (f top)" for i
hoelzl@60636
   361
      by (intro bexI[of _ "Suc i"]) (auto simp: funpow_Suc_right simp del: funpow.simps(2))
hoelzl@60636
   362
  qed
hoelzl@60636
   363
hoelzl@60636
   364
  have P_lfp: "P (gfp f)"
hoelzl@60636
   365
    unfolding gfp_f by (auto intro!: P P_pow antimono_pow2)
hoelzl@60636
   366
hoelzl@60636
   367
  have "\<alpha> (gfp f) = (INF i. \<alpha> ((f^^i) (f top)))"
hoelzl@60636
   368
    unfolding gfp_f by (rule \<alpha>) (auto intro!: P_pow antimono_pow2)
hoelzl@60636
   369
  also have "\<dots> \<ge> gfp g"
hoelzl@60636
   370
  proof (rule INF_greatest)
hoelzl@60636
   371
    fix i show "gfp g \<le> \<alpha> ((f^^i) (f top))"
hoelzl@60636
   372
    proof (induction i)
hoelzl@60636
   373
      case (Suc n) then show ?case
hoelzl@60636
   374
        by (subst gfp_unfold[OF mono_g]) (simp add: monoD[OF mono_g] P_pow)
hoelzl@60636
   375
    next
hoelzl@60636
   376
      case 0
hoelzl@60636
   377
      have "gfp g \<le> \<alpha> (f top)"
hoelzl@60636
   378
        by (subst gfp_unfold[OF mono_g]) (rule g_bound)
hoelzl@60636
   379
      then show ?case
hoelzl@60636
   380
        by simp
hoelzl@60636
   381
    qed
hoelzl@60636
   382
  qed
hoelzl@60636
   383
  finally show "gfp g \<le> \<alpha> (gfp f)" .
hoelzl@60636
   384
hoelzl@60636
   385
  show "\<alpha> (gfp f) \<le> gfp g"
hoelzl@60636
   386
  proof (induction rule: gfp_ordinal_induct[OF mono_g])
hoelzl@60636
   387
    case (1 S) then show ?case
hoelzl@60636
   388
      by (subst gfp_unfold[OF inf_continuous_mono[OF f]])
hoelzl@60636
   389
         (simp add: monoD[OF mono_g] P_lfp)
hoelzl@60636
   390
  qed (auto intro: Inf_greatest)
hoelzl@60636
   391
qed
hoelzl@60636
   392
hoelzl@62373
   393
subsubsection \<open>Least fixed points in countable complete lattices\<close>
hoelzl@62373
   394
hoelzl@62373
   395
definition (in countable_complete_lattice) cclfp :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a"
hoelzl@62374
   396
  where "cclfp f = (SUP i. (f ^^ i) bot)"
hoelzl@62373
   397
hoelzl@62373
   398
lemma cclfp_unfold:
hoelzl@62373
   399
  assumes "sup_continuous F" shows "cclfp F = F (cclfp F)"
hoelzl@62373
   400
proof -
hoelzl@62374
   401
  have "cclfp F = (SUP i. F ((F ^^ i) bot))"
hoelzl@62373
   402
    unfolding cclfp_def by (subst UNIV_nat_eq) auto
hoelzl@62373
   403
  also have "\<dots> = F (cclfp F)"
hoelzl@62373
   404
    unfolding cclfp_def
hoelzl@62373
   405
    by (intro sup_continuousD[symmetric] assms mono_funpow sup_continuous_mono)
hoelzl@62373
   406
  finally show ?thesis .
hoelzl@62373
   407
qed
hoelzl@62373
   408
hoelzl@62373
   409
lemma cclfp_lowerbound: assumes f: "mono f" and A: "f A \<le> A" shows "cclfp f \<le> A"
hoelzl@62373
   410
  unfolding cclfp_def
hoelzl@62373
   411
proof (intro ccSUP_least)
hoelzl@62374
   412
  fix i show "(f ^^ i) bot \<le> A"
hoelzl@62373
   413
  proof (induction i)
hoelzl@62373
   414
    case (Suc i) from monoD[OF f this] A show ?case
hoelzl@62373
   415
      by auto
hoelzl@62373
   416
  qed simp
hoelzl@62373
   417
qed simp
hoelzl@62373
   418
hoelzl@62373
   419
lemma cclfp_transfer:
hoelzl@62373
   420
  assumes "sup_continuous \<alpha>" "mono f"
hoelzl@62374
   421
  assumes "\<alpha> bot = bot" "\<And>x. \<alpha> (f x) = g (\<alpha> x)"
hoelzl@62373
   422
  shows "\<alpha> (cclfp f) = cclfp g"
hoelzl@62373
   423
proof -
hoelzl@62374
   424
  have "\<alpha> (cclfp f) = (SUP i. \<alpha> ((f ^^ i) bot))"
hoelzl@62373
   425
    unfolding cclfp_def by (intro sup_continuousD assms mono_funpow sup_continuous_mono)
hoelzl@62374
   426
  moreover have "\<alpha> ((f ^^ i) bot) = (g ^^ i) bot" for i
hoelzl@62373
   427
    by (induction i) (simp_all add: assms)
hoelzl@62373
   428
  ultimately show ?thesis
hoelzl@62373
   429
    by (simp add: cclfp_def)
hoelzl@62373
   430
qed
hoelzl@62373
   431
oheimb@11351
   432
end