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