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