src/HOL/Library/Continuity.thy
author haftmann
Fri Apr 24 17:45:15 2009 +0200 (2009-04-24)
changeset 30971 7fbebf75b3ef
parent 30952 7ab2716dd93b
child 32456 341c83339aeb
permissions -rw-r--r--
funpow and relpow with shared "^^" syntax
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
haftmann@30952
     8
imports Transitive_Closure 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)
nipkow@21312
    24
 apply(rule SUP_leI)
nipkow@21312
    25
 apply(case_tac n)
nipkow@21312
    26
  apply simp
berghofe@22431
    27
 apply (fast intro:le_SUPI le_supI2)
nipkow@21312
    28
apply(simp)
nipkow@21312
    29
apply (blast intro:SUP_leI le_SUPI)
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 }
haftmann@30971
    64
  hence "(SUP i. (F ^^ i) bot) \<le> lfp F" by (blast intro!:SUP_leI)
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"
nipkow@21312
    70
	proof (induct i)
nipkow@21312
    71
	  case 0 show ?case by simp
nipkow@21312
    72
	next
nipkow@21312
    73
	  case Suc thus ?case using monoD[OF mono Suc] by auto
nipkow@21312
    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)
berghofe@22431
    78
    also have "\<dots> \<le> ?U" by(fast intro:SUP_leI le_SUPI)
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@24331
   159
apply (auto simp add: nat_not_singleton)
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)
haftmann@25076
   187
apply auto
nipkow@24331
   188
apply (auto simp add: nat_not_singleton)
nipkow@24331
   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
haftmann@30971
   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
haftmann@30971
   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