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