src/HOL/Library/Continuity.thy
author Andreas Lochbihler
Fri Sep 20 10:09:16 2013 +0200 (2013-09-20)
changeset 53745 788730ab7da4
parent 46508 ec9630fe9ca7
child 54257 5c7a3b6b05a9
permissions -rw-r--r--
prefer Code.abort over code_abort
oheimb@11351
     1
(*  Title:      HOL/Library/Continuity.thy
wenzelm@11355
     2
    Author:     David von Oheimb, TU Muenchen
oheimb@11351
     3
*)
oheimb@11351
     4
wenzelm@14706
     5
header {* Continuity and iterations (of set transformers) *}
oheimb@11351
     6
nipkow@15131
     7
theory Continuity
wenzelm@46508
     8
imports Main
nipkow@15131
     9
begin
oheimb@11351
    10
wenzelm@22367
    11
subsection {* Continuity for complete lattices *}
nipkow@21312
    12
wenzelm@22367
    13
definition
haftmann@22452
    14
  chain :: "(nat \<Rightarrow> 'a::complete_lattice) \<Rightarrow> bool" where
wenzelm@22367
    15
  "chain M \<longleftrightarrow> (\<forall>i. M i \<le> M (Suc i))"
wenzelm@22367
    16
wenzelm@22367
    17
definition
haftmann@22452
    18
  continuous :: "('a::complete_lattice \<Rightarrow> 'a::complete_lattice) \<Rightarrow> bool" where
wenzelm@22367
    19
  "continuous F \<longleftrightarrow> (\<forall>M. chain M \<longrightarrow> F (SUP i. M i) = (SUP i. F (M i)))"
nipkow@21312
    20
nipkow@21312
    21
lemma SUP_nat_conv:
berghofe@22431
    22
  "(SUP n. M n) = sup (M 0) (SUP n. M(Suc n))"
nipkow@21312
    23
apply(rule order_antisym)
hoelzl@44928
    24
 apply(rule SUP_least)
nipkow@21312
    25
 apply(case_tac n)
nipkow@21312
    26
  apply simp
hoelzl@44928
    27
 apply (fast intro:SUP_upper le_supI2)
nipkow@21312
    28
apply(simp)
hoelzl@44928
    29
apply (blast intro:SUP_least SUP_upper)
nipkow@21312
    30
done
nipkow@21312
    31
haftmann@22452
    32
lemma continuous_mono: fixes F :: "'a::complete_lattice \<Rightarrow> 'a::complete_lattice"
nipkow@21312
    33
  assumes "continuous F" shows "mono F"
nipkow@21312
    34
proof
nipkow@21312
    35
  fix A B :: "'a" assume "A <= B"
nipkow@21312
    36
  let ?C = "%i::nat. if i=0 then A else B"
nipkow@21312
    37
  have "chain ?C" using `A <= B` by(simp add:chain_def)
haftmann@22422
    38
  have "F B = sup (F A) (F B)"
nipkow@21312
    39
  proof -
haftmann@22422
    40
    have "sup A B = B" using `A <= B` by (simp add:sup_absorb2)
berghofe@22431
    41
    hence "F B = F(SUP i. ?C i)" by (subst SUP_nat_conv) simp
nipkow@21312
    42
    also have "\<dots> = (SUP i. F(?C i))"
nipkow@21312
    43
      using `chain ?C` `continuous F` by(simp add:continuous_def)
berghofe@22431
    44
    also have "\<dots> = sup (F A) (F B)" by (subst SUP_nat_conv) simp
nipkow@21312
    45
    finally show ?thesis .
nipkow@21312
    46
  qed
haftmann@22422
    47
  thus "F A \<le> F B" by(subst le_iff_sup, simp)
nipkow@21312
    48
qed
nipkow@21312
    49
nipkow@21312
    50
lemma continuous_lfp:
haftmann@30971
    51
 assumes "continuous F" shows "lfp F = (SUP i. (F ^^ i) bot)"
nipkow@21312
    52
proof -
nipkow@21312
    53
  note mono = continuous_mono[OF `continuous F`]
haftmann@30971
    54
  { fix i have "(F ^^ i) bot \<le> lfp F"
nipkow@21312
    55
    proof (induct i)
haftmann@30971
    56
      show "(F ^^ 0) bot \<le> lfp F" by simp
nipkow@21312
    57
    next
nipkow@21312
    58
      case (Suc i)
haftmann@30971
    59
      have "(F ^^ Suc i) bot = F((F ^^ i) bot)" by simp
nipkow@21312
    60
      also have "\<dots> \<le> F(lfp F)" by(rule monoD[OF mono Suc])
nipkow@21312
    61
      also have "\<dots> = lfp F" by(simp add:lfp_unfold[OF mono, symmetric])
nipkow@21312
    62
      finally show ?case .
nipkow@21312
    63
    qed }
hoelzl@44928
    64
  hence "(SUP i. (F ^^ i) bot) \<le> lfp F" by (blast intro!:SUP_least)
haftmann@30971
    65
  moreover have "lfp F \<le> (SUP i. (F ^^ i) bot)" (is "_ \<le> ?U")
nipkow@21312
    66
  proof (rule lfp_lowerbound)
haftmann@30971
    67
    have "chain(%i. (F ^^ i) bot)"
nipkow@21312
    68
    proof -
haftmann@30971
    69
      { fix i have "(F ^^ i) bot \<le> (F ^^ (Suc i)) bot"
wenzelm@32960
    70
        proof (induct i)
wenzelm@32960
    71
          case 0 show ?case by simp
wenzelm@32960
    72
        next
wenzelm@32960
    73
          case Suc thus ?case using monoD[OF mono Suc] by auto
wenzelm@32960
    74
        qed }
nipkow@21312
    75
      thus ?thesis by(auto simp add:chain_def)
nipkow@21312
    76
    qed
haftmann@30971
    77
    hence "F ?U = (SUP i. (F ^^ (i+1)) bot)" using `continuous F` by (simp add:continuous_def)
hoelzl@44928
    78
    also have "\<dots> \<le> ?U" by(fast intro:SUP_least SUP_upper)
nipkow@21312
    79
    finally show "F ?U \<le> ?U" .
nipkow@21312
    80
  qed
nipkow@21312
    81
  ultimately show ?thesis by (blast intro:order_antisym)
nipkow@21312
    82
qed
nipkow@21312
    83
nipkow@21312
    84
text{* The following development is just for sets but presents an up
nipkow@21312
    85
and a down version of chains and continuity and covers @{const gfp}. *}
nipkow@21312
    86
nipkow@21312
    87
oheimb@11351
    88
subsection "Chains"
oheimb@11351
    89
wenzelm@19736
    90
definition
wenzelm@21404
    91
  up_chain :: "(nat => 'a set) => bool" where
wenzelm@19736
    92
  "up_chain F = (\<forall>i. F i \<subseteq> F (Suc i))"
oheimb@11351
    93
wenzelm@11355
    94
lemma up_chainI: "(!!i. F i \<subseteq> F (Suc i)) ==> up_chain F"
wenzelm@11355
    95
  by (simp add: up_chain_def)
oheimb@11351
    96
wenzelm@11355
    97
lemma up_chainD: "up_chain F ==> F i \<subseteq> F (Suc i)"
wenzelm@11355
    98
  by (simp add: up_chain_def)
oheimb@11351
    99
wenzelm@19736
   100
lemma up_chain_less_mono:
wenzelm@19736
   101
    "up_chain F ==> x < y ==> F x \<subseteq> F y"
wenzelm@19736
   102
  apply (induct y)
wenzelm@19736
   103
   apply (blast dest: up_chainD elim: less_SucE)+
wenzelm@11355
   104
  done
oheimb@11351
   105
wenzelm@11355
   106
lemma up_chain_mono: "up_chain F ==> x \<le> y ==> F x \<subseteq> F y"
wenzelm@11355
   107
  apply (drule le_imp_less_or_eq)
wenzelm@11355
   108
  apply (blast dest: up_chain_less_mono)
wenzelm@11355
   109
  done
oheimb@11351
   110
oheimb@11351
   111
wenzelm@19736
   112
definition
wenzelm@21404
   113
  down_chain :: "(nat => 'a set) => bool" where
wenzelm@19736
   114
  "down_chain F = (\<forall>i. F (Suc i) \<subseteq> F i)"
oheimb@11351
   115
wenzelm@11355
   116
lemma down_chainI: "(!!i. F (Suc i) \<subseteq> F i) ==> down_chain F"
wenzelm@11355
   117
  by (simp add: down_chain_def)
oheimb@11351
   118
wenzelm@11355
   119
lemma down_chainD: "down_chain F ==> F (Suc i) \<subseteq> F i"
wenzelm@11355
   120
  by (simp add: down_chain_def)
oheimb@11351
   121
wenzelm@19736
   122
lemma down_chain_less_mono:
wenzelm@19736
   123
    "down_chain F ==> x < y ==> F y \<subseteq> F x"
wenzelm@19736
   124
  apply (induct y)
wenzelm@19736
   125
   apply (blast dest: down_chainD elim: less_SucE)+
wenzelm@11355
   126
  done
oheimb@11351
   127
wenzelm@11355
   128
lemma down_chain_mono: "down_chain F ==> x \<le> y ==> F y \<subseteq> F x"
wenzelm@11355
   129
  apply (drule le_imp_less_or_eq)
wenzelm@11355
   130
  apply (blast dest: down_chain_less_mono)
wenzelm@11355
   131
  done
oheimb@11351
   132
oheimb@11351
   133
oheimb@11351
   134
subsection "Continuity"
oheimb@11351
   135
wenzelm@19736
   136
definition
wenzelm@21404
   137
  up_cont :: "('a set => 'a set) => bool" where
wenzelm@19736
   138
  "up_cont f = (\<forall>F. up_chain F --> f (\<Union>(range F)) = \<Union>(f ` range F))"
oheimb@11351
   139
wenzelm@11355
   140
lemma up_contI:
nipkow@24331
   141
  "(!!F. up_chain F ==> f (\<Union>(range F)) = \<Union>(f ` range F)) ==> up_cont f"
nipkow@24331
   142
apply (unfold up_cont_def)
nipkow@24331
   143
apply blast
nipkow@24331
   144
done
oheimb@11351
   145
wenzelm@11355
   146
lemma up_contD:
nipkow@24331
   147
  "up_cont f ==> up_chain F ==> f (\<Union>(range F)) = \<Union>(f ` range F)"
nipkow@24331
   148
apply (unfold up_cont_def)
nipkow@24331
   149
apply auto
nipkow@24331
   150
done
oheimb@11351
   151
oheimb@11351
   152
oheimb@11351
   153
lemma up_cont_mono: "up_cont f ==> mono f"
nipkow@24331
   154
apply (rule monoI)
haftmann@25076
   155
apply (drule_tac F = "\<lambda>i. if i = 0 then x else y" in up_contD)
nipkow@24331
   156
 apply (rule up_chainI)
nipkow@24331
   157
 apply simp
nipkow@24331
   158
apply (drule Un_absorb1)
nipkow@32456
   159
apply (auto split:split_if_asm)
nipkow@24331
   160
done
oheimb@11351
   161
oheimb@11351
   162
wenzelm@19736
   163
definition
wenzelm@21404
   164
  down_cont :: "('a set => 'a set) => bool" where
wenzelm@19736
   165
  "down_cont f =
wenzelm@19736
   166
    (\<forall>F. down_chain F --> f (Inter (range F)) = Inter (f ` range F))"
oheimb@11351
   167
wenzelm@11355
   168
lemma down_contI:
wenzelm@11355
   169
  "(!!F. down_chain F ==> f (Inter (range F)) = Inter (f ` range F)) ==>
wenzelm@11355
   170
    down_cont f"
wenzelm@11355
   171
  apply (unfold down_cont_def)
wenzelm@11355
   172
  apply blast
wenzelm@11355
   173
  done
oheimb@11351
   174
wenzelm@11355
   175
lemma down_contD: "down_cont f ==> down_chain F ==>
wenzelm@11355
   176
    f (Inter (range F)) = Inter (f ` range F)"
wenzelm@11355
   177
  apply (unfold down_cont_def)
wenzelm@11355
   178
  apply auto
wenzelm@11355
   179
  done
oheimb@11351
   180
oheimb@11351
   181
lemma down_cont_mono: "down_cont f ==> mono f"
nipkow@24331
   182
apply (rule monoI)
haftmann@25076
   183
apply (drule_tac F = "\<lambda>i. if i = 0 then y else x" in down_contD)
nipkow@24331
   184
 apply (rule down_chainI)
nipkow@24331
   185
 apply simp
nipkow@24331
   186
apply (drule Int_absorb1)
nipkow@32456
   187
apply (auto split:split_if_asm)
nipkow@24331
   188
done
oheimb@11351
   189
oheimb@11351
   190
oheimb@11351
   191
subsection "Iteration"
oheimb@11351
   192
wenzelm@19736
   193
definition
wenzelm@21404
   194
  up_iterate :: "('a set => 'a set) => nat => 'a set" where
haftmann@30971
   195
  "up_iterate f n = (f ^^ n) {}"
oheimb@11351
   196
oheimb@11351
   197
lemma up_iterate_0 [simp]: "up_iterate f 0 = {}"
wenzelm@11355
   198
  by (simp add: up_iterate_def)
oheimb@11351
   199
wenzelm@11355
   200
lemma up_iterate_Suc [simp]: "up_iterate f (Suc i) = f (up_iterate f i)"
wenzelm@11355
   201
  by (simp add: up_iterate_def)
oheimb@11351
   202
oheimb@11351
   203
lemma up_iterate_chain: "mono F ==> up_chain (up_iterate F)"
wenzelm@11355
   204
  apply (rule up_chainI)
wenzelm@11355
   205
  apply (induct_tac i)
wenzelm@11355
   206
   apply simp+
wenzelm@11355
   207
  apply (erule (1) monoD)
wenzelm@11355
   208
  done
oheimb@11351
   209
wenzelm@11355
   210
lemma UNION_up_iterate_is_fp:
wenzelm@11355
   211
  "up_cont F ==>
wenzelm@11355
   212
    F (UNION UNIV (up_iterate F)) = UNION UNIV (up_iterate F)"
wenzelm@11355
   213
  apply (frule up_cont_mono [THEN up_iterate_chain])
wenzelm@11355
   214
  apply (drule (1) up_contD)
wenzelm@11355
   215
  apply simp
wenzelm@11355
   216
  apply (auto simp del: up_iterate_Suc simp add: up_iterate_Suc [symmetric])
wenzelm@11355
   217
  apply (case_tac xa)
wenzelm@11355
   218
   apply auto
wenzelm@11355
   219
  done
oheimb@11351
   220
wenzelm@11355
   221
lemma UNION_up_iterate_lowerbound:
wenzelm@11355
   222
    "mono F ==> F P = P ==> UNION UNIV (up_iterate F) \<subseteq> P"
wenzelm@11355
   223
  apply (subgoal_tac "(!!i. up_iterate F i \<subseteq> P)")
wenzelm@11355
   224
   apply fast
wenzelm@11355
   225
  apply (induct_tac i)
wenzelm@11355
   226
  prefer 2 apply (drule (1) monoD)
wenzelm@11355
   227
   apply auto
wenzelm@11355
   228
  done
oheimb@11351
   229
wenzelm@11355
   230
lemma UNION_up_iterate_is_lfp:
wenzelm@11355
   231
    "up_cont F ==> lfp F = UNION UNIV (up_iterate F)"
wenzelm@11355
   232
  apply (rule set_eq_subset [THEN iffD2])
wenzelm@11355
   233
  apply (rule conjI)
wenzelm@11355
   234
   prefer 2
wenzelm@11355
   235
   apply (drule up_cont_mono)
wenzelm@11355
   236
   apply (rule UNION_up_iterate_lowerbound)
wenzelm@11355
   237
    apply assumption
wenzelm@11355
   238
   apply (erule lfp_unfold [symmetric])
wenzelm@11355
   239
  apply (rule lfp_lowerbound)
wenzelm@11355
   240
  apply (rule set_eq_subset [THEN iffD1, THEN conjunct2])
wenzelm@11355
   241
  apply (erule UNION_up_iterate_is_fp [symmetric])
wenzelm@11355
   242
  done
oheimb@11351
   243
oheimb@11351
   244
wenzelm@19736
   245
definition
wenzelm@21404
   246
  down_iterate :: "('a set => 'a set) => nat => 'a set" where
haftmann@30971
   247
  "down_iterate f n = (f ^^ n) UNIV"
oheimb@11351
   248
oheimb@11351
   249
lemma down_iterate_0 [simp]: "down_iterate f 0 = UNIV"
wenzelm@11355
   250
  by (simp add: down_iterate_def)
oheimb@11351
   251
wenzelm@11355
   252
lemma down_iterate_Suc [simp]:
wenzelm@11355
   253
    "down_iterate f (Suc i) = f (down_iterate f i)"
wenzelm@11355
   254
  by (simp add: down_iterate_def)
oheimb@11351
   255
oheimb@11351
   256
lemma down_iterate_chain: "mono F ==> down_chain (down_iterate F)"
wenzelm@11355
   257
  apply (rule down_chainI)
wenzelm@11355
   258
  apply (induct_tac i)
wenzelm@11355
   259
   apply simp+
wenzelm@11355
   260
  apply (erule (1) monoD)
wenzelm@11355
   261
  done
oheimb@11351
   262
wenzelm@11355
   263
lemma INTER_down_iterate_is_fp:
wenzelm@11355
   264
  "down_cont F ==>
wenzelm@11355
   265
    F (INTER UNIV (down_iterate F)) = INTER UNIV (down_iterate F)"
wenzelm@11355
   266
  apply (frule down_cont_mono [THEN down_iterate_chain])
wenzelm@11355
   267
  apply (drule (1) down_contD)
wenzelm@11355
   268
  apply simp
wenzelm@11355
   269
  apply (auto simp del: down_iterate_Suc simp add: down_iterate_Suc [symmetric])
wenzelm@11355
   270
  apply (case_tac xa)
wenzelm@11355
   271
   apply auto
wenzelm@11355
   272
  done
oheimb@11351
   273
wenzelm@11355
   274
lemma INTER_down_iterate_upperbound:
wenzelm@11355
   275
    "mono F ==> F P = P ==> P \<subseteq> INTER UNIV (down_iterate F)"
wenzelm@11355
   276
  apply (subgoal_tac "(!!i. P \<subseteq> down_iterate F i)")
wenzelm@11355
   277
   apply fast
wenzelm@11355
   278
  apply (induct_tac i)
wenzelm@11355
   279
  prefer 2 apply (drule (1) monoD)
wenzelm@11355
   280
   apply auto
wenzelm@11355
   281
  done
oheimb@11351
   282
wenzelm@11355
   283
lemma INTER_down_iterate_is_gfp:
wenzelm@11355
   284
    "down_cont F ==> gfp F = INTER UNIV (down_iterate F)"
wenzelm@11355
   285
  apply (rule set_eq_subset [THEN iffD2])
wenzelm@11355
   286
  apply (rule conjI)
wenzelm@11355
   287
   apply (drule down_cont_mono)
wenzelm@11355
   288
   apply (rule INTER_down_iterate_upperbound)
wenzelm@11355
   289
    apply assumption
wenzelm@11355
   290
   apply (erule gfp_unfold [symmetric])
wenzelm@11355
   291
  apply (rule gfp_upperbound)
wenzelm@11355
   292
  apply (rule set_eq_subset [THEN iffD1, THEN conjunct2])
wenzelm@11355
   293
  apply (erule INTER_down_iterate_is_fp)
wenzelm@11355
   294
  done
oheimb@11351
   295
oheimb@11351
   296
end