src/HOL/Multivariate_Analysis/Topology_Euclidean_Space.thy
author wenzelm
Fri Oct 12 18:58:20 2012 +0200 (2012-10-12)
changeset 49834 b27bbb021df1
parent 49711 e5aaae7eadc9
child 49962 a8cc904a6820
permissions -rw-r--r--
discontinued obsolete typedef (open) syntax;
hoelzl@33714
     1
(*  title:      HOL/Library/Topology_Euclidian_Space.thy
himmelma@33175
     2
    Author:     Amine Chaieb, University of Cambridge
himmelma@33175
     3
    Author:     Robert Himmelmann, TU Muenchen
huffman@44075
     4
    Author:     Brian Huffman, Portland State University
himmelma@33175
     5
*)
himmelma@33175
     6
himmelma@33175
     7
header {* Elementary topology in Euclidean space. *}
himmelma@33175
     8
himmelma@33175
     9
theory Topology_Euclidean_Space
huffman@44628
    10
imports SEQ Linear_Algebra "~~/src/HOL/Library/Glbs" Norm_Arith
himmelma@33175
    11
begin
himmelma@33175
    12
huffman@44517
    13
subsection {* General notion of a topology as a value *}
himmelma@33175
    14
huffman@44170
    15
definition "istopology L \<longleftrightarrow> L {} \<and> (\<forall>S T. L S \<longrightarrow> L T \<longrightarrow> L (S \<inter> T)) \<and> (\<forall>K. Ball K L \<longrightarrow> L (\<Union> K))"
wenzelm@49834
    16
typedef 'a topology = "{L::('a set) \<Rightarrow> bool. istopology L}"
himmelma@33175
    17
  morphisms "openin" "topology"
himmelma@33175
    18
  unfolding istopology_def by blast
himmelma@33175
    19
himmelma@33175
    20
lemma istopology_open_in[intro]: "istopology(openin U)"
himmelma@33175
    21
  using openin[of U] by blast
himmelma@33175
    22
himmelma@33175
    23
lemma topology_inverse': "istopology U \<Longrightarrow> openin (topology U) = U"
huffman@44170
    24
  using topology_inverse[unfolded mem_Collect_eq] .
himmelma@33175
    25
himmelma@33175
    26
lemma topology_inverse_iff: "istopology U \<longleftrightarrow> openin (topology U) = U"
himmelma@33175
    27
  using topology_inverse[of U] istopology_open_in[of "topology U"] by auto
himmelma@33175
    28
himmelma@33175
    29
lemma topology_eq: "T1 = T2 \<longleftrightarrow> (\<forall>S. openin T1 S \<longleftrightarrow> openin T2 S)"
himmelma@33175
    30
proof-
wenzelm@49711
    31
  { assume "T1=T2"
wenzelm@49711
    32
    hence "\<forall>S. openin T1 S \<longleftrightarrow> openin T2 S" by simp }
himmelma@33175
    33
  moreover
wenzelm@49711
    34
  { assume H: "\<forall>S. openin T1 S \<longleftrightarrow> openin T2 S"
huffman@44170
    35
    hence "openin T1 = openin T2" by (simp add: fun_eq_iff)
himmelma@33175
    36
    hence "topology (openin T1) = topology (openin T2)" by simp
wenzelm@49711
    37
    hence "T1 = T2" unfolding openin_inverse .
wenzelm@49711
    38
  }
himmelma@33175
    39
  ultimately show ?thesis by blast
himmelma@33175
    40
qed
himmelma@33175
    41
himmelma@33175
    42
text{* Infer the "universe" from union of all sets in the topology. *}
himmelma@33175
    43
himmelma@33175
    44
definition "topspace T =  \<Union>{S. openin T S}"
himmelma@33175
    45
huffman@44210
    46
subsubsection {* Main properties of open sets *}
himmelma@33175
    47
himmelma@33175
    48
lemma openin_clauses:
himmelma@33175
    49
  fixes U :: "'a topology"
himmelma@33175
    50
  shows "openin U {}"
himmelma@33175
    51
  "\<And>S T. openin U S \<Longrightarrow> openin U T \<Longrightarrow> openin U (S\<inter>T)"
himmelma@33175
    52
  "\<And>K. (\<forall>S \<in> K. openin U S) \<Longrightarrow> openin U (\<Union>K)"
huffman@44170
    53
  using openin[of U] unfolding istopology_def mem_Collect_eq
huffman@44170
    54
  by fast+
himmelma@33175
    55
himmelma@33175
    56
lemma openin_subset[intro]: "openin U S \<Longrightarrow> S \<subseteq> topspace U"
himmelma@33175
    57
  unfolding topspace_def by blast
himmelma@33175
    58
lemma openin_empty[simp]: "openin U {}" by (simp add: openin_clauses)
himmelma@33175
    59
himmelma@33175
    60
lemma openin_Int[intro]: "openin U S \<Longrightarrow> openin U T \<Longrightarrow> openin U (S \<inter> T)"
huffman@36362
    61
  using openin_clauses by simp
huffman@36362
    62
huffman@36362
    63
lemma openin_Union[intro]: "(\<forall>S \<in>K. openin U S) \<Longrightarrow> openin U (\<Union> K)"
huffman@36362
    64
  using openin_clauses by simp
himmelma@33175
    65
himmelma@33175
    66
lemma openin_Un[intro]: "openin U S \<Longrightarrow> openin U T \<Longrightarrow> openin U (S \<union> T)"
himmelma@33175
    67
  using openin_Union[of "{S,T}" U] by auto
himmelma@33175
    68
himmelma@33175
    69
lemma openin_topspace[intro, simp]: "openin U (topspace U)" by (simp add: openin_Union topspace_def)
himmelma@33175
    70
wenzelm@49711
    71
lemma openin_subopen: "openin U S \<longleftrightarrow> (\<forall>x \<in> S. \<exists>T. openin U T \<and> x \<in> T \<and> T \<subseteq> S)"
wenzelm@49711
    72
  (is "?lhs \<longleftrightarrow> ?rhs")
huffman@36584
    73
proof
wenzelm@49711
    74
  assume ?lhs
wenzelm@49711
    75
  then show ?rhs by auto
huffman@36584
    76
next
huffman@36584
    77
  assume H: ?rhs
huffman@36584
    78
  let ?t = "\<Union>{T. openin U T \<and> T \<subseteq> S}"
huffman@36584
    79
  have "openin U ?t" by (simp add: openin_Union)
huffman@36584
    80
  also have "?t = S" using H by auto
huffman@36584
    81
  finally show "openin U S" .
himmelma@33175
    82
qed
himmelma@33175
    83
wenzelm@49711
    84
huffman@44210
    85
subsubsection {* Closed sets *}
himmelma@33175
    86
himmelma@33175
    87
definition "closedin U S \<longleftrightarrow> S \<subseteq> topspace U \<and> openin U (topspace U - S)"
himmelma@33175
    88
himmelma@33175
    89
lemma closedin_subset: "closedin U S \<Longrightarrow> S \<subseteq> topspace U" by (metis closedin_def)
himmelma@33175
    90
lemma closedin_empty[simp]: "closedin U {}" by (simp add: closedin_def)
himmelma@33175
    91
lemma closedin_topspace[intro,simp]:
himmelma@33175
    92
  "closedin U (topspace U)" by (simp add: closedin_def)
himmelma@33175
    93
lemma closedin_Un[intro]: "closedin U S \<Longrightarrow> closedin U T \<Longrightarrow> closedin U (S \<union> T)"
himmelma@33175
    94
  by (auto simp add: Diff_Un closedin_def)
himmelma@33175
    95
himmelma@33175
    96
lemma Diff_Inter[intro]: "A - \<Inter>S = \<Union> {A - s|s. s\<in>S}" by auto
himmelma@33175
    97
lemma closedin_Inter[intro]: assumes Ke: "K \<noteq> {}" and Kc: "\<forall>S \<in>K. closedin U S"
himmelma@33175
    98
  shows "closedin U (\<Inter> K)"  using Ke Kc unfolding closedin_def Diff_Inter by auto
himmelma@33175
    99
himmelma@33175
   100
lemma closedin_Int[intro]: "closedin U S \<Longrightarrow> closedin U T \<Longrightarrow> closedin U (S \<inter> T)"
himmelma@33175
   101
  using closedin_Inter[of "{S,T}" U] by auto
himmelma@33175
   102
himmelma@33175
   103
lemma Diff_Diff_Int: "A - (A - B) = A \<inter> B" by blast
himmelma@33175
   104
lemma openin_closedin_eq: "openin U S \<longleftrightarrow> S \<subseteq> topspace U \<and> closedin U (topspace U - S)"
himmelma@33175
   105
  apply (auto simp add: closedin_def Diff_Diff_Int inf_absorb2)
himmelma@33175
   106
  apply (metis openin_subset subset_eq)
himmelma@33175
   107
  done
himmelma@33175
   108
himmelma@33175
   109
lemma openin_closedin:  "S \<subseteq> topspace U \<Longrightarrow> (openin U S \<longleftrightarrow> closedin U (topspace U - S))"
himmelma@33175
   110
  by (simp add: openin_closedin_eq)
himmelma@33175
   111
himmelma@33175
   112
lemma openin_diff[intro]: assumes oS: "openin U S" and cT: "closedin U T" shows "openin U (S - T)"
himmelma@33175
   113
proof-
himmelma@33175
   114
  have "S - T = S \<inter> (topspace U - T)" using openin_subset[of U S]  oS cT
himmelma@33175
   115
    by (auto simp add: topspace_def openin_subset)
himmelma@33175
   116
  then show ?thesis using oS cT by (auto simp add: closedin_def)
himmelma@33175
   117
qed
himmelma@33175
   118
himmelma@33175
   119
lemma closedin_diff[intro]: assumes oS: "closedin U S" and cT: "openin U T" shows "closedin U (S - T)"
himmelma@33175
   120
proof-
himmelma@33175
   121
  have "S - T = S \<inter> (topspace U - T)" using closedin_subset[of U S]  oS cT
himmelma@33175
   122
    by (auto simp add: topspace_def )
himmelma@33175
   123
  then show ?thesis using oS cT by (auto simp add: openin_closedin_eq)
himmelma@33175
   124
qed
himmelma@33175
   125
huffman@44210
   126
subsubsection {* Subspace topology *}
huffman@44170
   127
huffman@44170
   128
definition "subtopology U V = topology (\<lambda>T. \<exists>S. T = S \<inter> V \<and> openin U S)"
huffman@44170
   129
huffman@44170
   130
lemma istopology_subtopology: "istopology (\<lambda>T. \<exists>S. T = S \<inter> V \<and> openin U S)"
huffman@44170
   131
  (is "istopology ?L")
himmelma@33175
   132
proof-
huffman@44170
   133
  have "?L {}" by blast
huffman@44170
   134
  {fix A B assume A: "?L A" and B: "?L B"
himmelma@33175
   135
    from A B obtain Sa and Sb where Sa: "openin U Sa" "A = Sa \<inter> V" and Sb: "openin U Sb" "B = Sb \<inter> V" by blast
himmelma@33175
   136
    have "A\<inter>B = (Sa \<inter> Sb) \<inter> V" "openin U (Sa \<inter> Sb)"  using Sa Sb by blast+
huffman@44170
   137
    then have "?L (A \<inter> B)" by blast}
himmelma@33175
   138
  moreover
huffman@44170
   139
  {fix K assume K: "K \<subseteq> Collect ?L"
huffman@44170
   140
    have th0: "Collect ?L = (\<lambda>S. S \<inter> V) ` Collect (openin U)"
nipkow@39302
   141
      apply (rule set_eqI)
himmelma@33175
   142
      apply (simp add: Ball_def image_iff)
huffman@44170
   143
      by metis
himmelma@33175
   144
    from K[unfolded th0 subset_image_iff]
huffman@44170
   145
    obtain Sk where Sk: "Sk \<subseteq> Collect (openin U)" "K = (\<lambda>S. S \<inter> V) ` Sk" by blast
himmelma@33175
   146
    have "\<Union>K = (\<Union>Sk) \<inter> V" using Sk by auto
huffman@44170
   147
    moreover have "openin U (\<Union> Sk)" using Sk by (auto simp add: subset_eq)
huffman@44170
   148
    ultimately have "?L (\<Union>K)" by blast}
huffman@44170
   149
  ultimately show ?thesis
huffman@44170
   150
    unfolding subset_eq mem_Collect_eq istopology_def by blast
himmelma@33175
   151
qed
himmelma@33175
   152
himmelma@33175
   153
lemma openin_subtopology:
himmelma@33175
   154
  "openin (subtopology U V) S \<longleftrightarrow> (\<exists> T. (openin U T) \<and> (S = T \<inter> V))"
himmelma@33175
   155
  unfolding subtopology_def topology_inverse'[OF istopology_subtopology]
huffman@44170
   156
  by auto
himmelma@33175
   157
himmelma@33175
   158
lemma topspace_subtopology: "topspace(subtopology U V) = topspace U \<inter> V"
himmelma@33175
   159
  by (auto simp add: topspace_def openin_subtopology)
himmelma@33175
   160
himmelma@33175
   161
lemma closedin_subtopology:
himmelma@33175
   162
  "closedin (subtopology U V) S \<longleftrightarrow> (\<exists>T. closedin U T \<and> S = T \<inter> V)"
himmelma@33175
   163
  unfolding closedin_def topspace_subtopology
himmelma@33175
   164
  apply (simp add: openin_subtopology)
himmelma@33175
   165
  apply (rule iffI)
himmelma@33175
   166
  apply clarify
himmelma@33175
   167
  apply (rule_tac x="topspace U - T" in exI)
himmelma@33175
   168
  by auto
himmelma@33175
   169
himmelma@33175
   170
lemma openin_subtopology_refl: "openin (subtopology U V) V \<longleftrightarrow> V \<subseteq> topspace U"
himmelma@33175
   171
  unfolding openin_subtopology
himmelma@33175
   172
  apply (rule iffI, clarify)
himmelma@33175
   173
  apply (frule openin_subset[of U])  apply blast
himmelma@33175
   174
  apply (rule exI[where x="topspace U"])
wenzelm@49711
   175
  apply auto
wenzelm@49711
   176
  done
wenzelm@49711
   177
wenzelm@49711
   178
lemma subtopology_superset:
wenzelm@49711
   179
  assumes UV: "topspace U \<subseteq> V"
himmelma@33175
   180
  shows "subtopology U V = U"
himmelma@33175
   181
proof-
himmelma@33175
   182
  {fix S
himmelma@33175
   183
    {fix T assume T: "openin U T" "S = T \<inter> V"
himmelma@33175
   184
      from T openin_subset[OF T(1)] UV have eq: "S = T" by blast
himmelma@33175
   185
      have "openin U S" unfolding eq using T by blast}
himmelma@33175
   186
    moreover
himmelma@33175
   187
    {assume S: "openin U S"
himmelma@33175
   188
      hence "\<exists>T. openin U T \<and> S = T \<inter> V"
himmelma@33175
   189
        using openin_subset[OF S] UV by auto}
himmelma@33175
   190
    ultimately have "(\<exists>T. openin U T \<and> S = T \<inter> V) \<longleftrightarrow> openin U S" by blast}
himmelma@33175
   191
  then show ?thesis unfolding topology_eq openin_subtopology by blast
himmelma@33175
   192
qed
himmelma@33175
   193
himmelma@33175
   194
lemma subtopology_topspace[simp]: "subtopology U (topspace U) = U"
himmelma@33175
   195
  by (simp add: subtopology_superset)
himmelma@33175
   196
himmelma@33175
   197
lemma subtopology_UNIV[simp]: "subtopology U UNIV = U"
himmelma@33175
   198
  by (simp add: subtopology_superset)
himmelma@33175
   199
huffman@44210
   200
subsubsection {* The standard Euclidean topology *}
himmelma@33175
   201
himmelma@33175
   202
definition
himmelma@33175
   203
  euclidean :: "'a::topological_space topology" where
himmelma@33175
   204
  "euclidean = topology open"
himmelma@33175
   205
himmelma@33175
   206
lemma open_openin: "open S \<longleftrightarrow> openin euclidean S"
himmelma@33175
   207
  unfolding euclidean_def
himmelma@33175
   208
  apply (rule cong[where x=S and y=S])
himmelma@33175
   209
  apply (rule topology_inverse[symmetric])
himmelma@33175
   210
  apply (auto simp add: istopology_def)
huffman@44170
   211
  done
himmelma@33175
   212
himmelma@33175
   213
lemma topspace_euclidean: "topspace euclidean = UNIV"
himmelma@33175
   214
  apply (simp add: topspace_def)
nipkow@39302
   215
  apply (rule set_eqI)
himmelma@33175
   216
  by (auto simp add: open_openin[symmetric])
himmelma@33175
   217
himmelma@33175
   218
lemma topspace_euclidean_subtopology[simp]: "topspace (subtopology euclidean S) = S"
himmelma@33175
   219
  by (simp add: topspace_euclidean topspace_subtopology)
himmelma@33175
   220
himmelma@33175
   221
lemma closed_closedin: "closed S \<longleftrightarrow> closedin euclidean S"
himmelma@33175
   222
  by (simp add: closed_def closedin_def topspace_euclidean open_openin Compl_eq_Diff_UNIV)
himmelma@33175
   223
himmelma@33175
   224
lemma open_subopen: "open S \<longleftrightarrow> (\<forall>x\<in>S. \<exists>T. open T \<and> x \<in> T \<and> T \<subseteq> S)"
himmelma@33175
   225
  by (simp add: open_openin openin_subopen[symmetric])
himmelma@33175
   226
huffman@44210
   227
text {* Basic "localization" results are handy for connectedness. *}
huffman@44210
   228
huffman@44210
   229
lemma openin_open: "openin (subtopology euclidean U) S \<longleftrightarrow> (\<exists>T. open T \<and> (S = U \<inter> T))"
huffman@44210
   230
  by (auto simp add: openin_subtopology open_openin[symmetric])
huffman@44210
   231
huffman@44210
   232
lemma openin_open_Int[intro]: "open S \<Longrightarrow> openin (subtopology euclidean U) (U \<inter> S)"
huffman@44210
   233
  by (auto simp add: openin_open)
huffman@44210
   234
huffman@44210
   235
lemma open_openin_trans[trans]:
huffman@44210
   236
 "open S \<Longrightarrow> open T \<Longrightarrow> T \<subseteq> S \<Longrightarrow> openin (subtopology euclidean S) T"
huffman@44210
   237
  by (metis Int_absorb1  openin_open_Int)
huffman@44210
   238
huffman@44210
   239
lemma open_subset:  "S \<subseteq> T \<Longrightarrow> open S \<Longrightarrow> openin (subtopology euclidean T) S"
huffman@44210
   240
  by (auto simp add: openin_open)
huffman@44210
   241
huffman@44210
   242
lemma closedin_closed: "closedin (subtopology euclidean U) S \<longleftrightarrow> (\<exists>T. closed T \<and> S = U \<inter> T)"
huffman@44210
   243
  by (simp add: closedin_subtopology closed_closedin Int_ac)
huffman@44210
   244
huffman@44210
   245
lemma closedin_closed_Int: "closed S ==> closedin (subtopology euclidean U) (U \<inter> S)"
huffman@44210
   246
  by (metis closedin_closed)
huffman@44210
   247
huffman@44210
   248
lemma closed_closedin_trans: "closed S \<Longrightarrow> closed T \<Longrightarrow> T \<subseteq> S \<Longrightarrow> closedin (subtopology euclidean S) T"
huffman@44210
   249
  apply (subgoal_tac "S \<inter> T = T" )
huffman@44210
   250
  apply auto
huffman@44210
   251
  apply (frule closedin_closed_Int[of T S])
huffman@44210
   252
  by simp
huffman@44210
   253
huffman@44210
   254
lemma closed_subset: "S \<subseteq> T \<Longrightarrow> closed S \<Longrightarrow> closedin (subtopology euclidean T) S"
huffman@44210
   255
  by (auto simp add: closedin_closed)
huffman@44210
   256
huffman@44210
   257
lemma openin_euclidean_subtopology_iff:
huffman@44210
   258
  fixes S U :: "'a::metric_space set"
huffman@44210
   259
  shows "openin (subtopology euclidean U) S
huffman@44210
   260
  \<longleftrightarrow> S \<subseteq> U \<and> (\<forall>x\<in>S. \<exists>e>0. \<forall>x'\<in>U. dist x' x < e \<longrightarrow> x'\<in> S)" (is "?lhs \<longleftrightarrow> ?rhs")
huffman@44210
   261
proof
huffman@44210
   262
  assume ?lhs thus ?rhs unfolding openin_open open_dist by blast
huffman@44210
   263
next
huffman@44210
   264
  def T \<equiv> "{x. \<exists>a\<in>S. \<exists>d>0. (\<forall>y\<in>U. dist y a < d \<longrightarrow> y \<in> S) \<and> dist x a < d}"
huffman@44210
   265
  have 1: "\<forall>x\<in>T. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> T"
huffman@44210
   266
    unfolding T_def
huffman@44210
   267
    apply clarsimp
huffman@44210
   268
    apply (rule_tac x="d - dist x a" in exI)
huffman@44210
   269
    apply (clarsimp simp add: less_diff_eq)
huffman@44210
   270
    apply (erule rev_bexI)
huffman@44210
   271
    apply (rule_tac x=d in exI, clarify)
huffman@44210
   272
    apply (erule le_less_trans [OF dist_triangle])
huffman@44210
   273
    done
huffman@44210
   274
  assume ?rhs hence 2: "S = U \<inter> T"
huffman@44210
   275
    unfolding T_def
huffman@44210
   276
    apply auto
huffman@44210
   277
    apply (drule (1) bspec, erule rev_bexI)
huffman@44210
   278
    apply auto
huffman@44210
   279
    done
huffman@44210
   280
  from 1 2 show ?lhs
huffman@44210
   281
    unfolding openin_open open_dist by fast
huffman@44210
   282
qed
huffman@44210
   283
huffman@44210
   284
text {* These "transitivity" results are handy too *}
huffman@44210
   285
huffman@44210
   286
lemma openin_trans[trans]: "openin (subtopology euclidean T) S \<Longrightarrow> openin (subtopology euclidean U) T
huffman@44210
   287
  \<Longrightarrow> openin (subtopology euclidean U) S"
huffman@44210
   288
  unfolding open_openin openin_open by blast
huffman@44210
   289
huffman@44210
   290
lemma openin_open_trans: "openin (subtopology euclidean T) S \<Longrightarrow> open T \<Longrightarrow> open S"
huffman@44210
   291
  by (auto simp add: openin_open intro: openin_trans)
huffman@44210
   292
huffman@44210
   293
lemma closedin_trans[trans]:
huffman@44210
   294
 "closedin (subtopology euclidean T) S \<Longrightarrow>
huffman@44210
   295
           closedin (subtopology euclidean U) T
huffman@44210
   296
           ==> closedin (subtopology euclidean U) S"
huffman@44210
   297
  by (auto simp add: closedin_closed closed_closedin closed_Inter Int_assoc)
huffman@44210
   298
huffman@44210
   299
lemma closedin_closed_trans: "closedin (subtopology euclidean T) S \<Longrightarrow> closed T \<Longrightarrow> closed S"
huffman@44210
   300
  by (auto simp add: closedin_closed intro: closedin_trans)
huffman@44210
   301
huffman@44210
   302
huffman@44210
   303
subsection {* Open and closed balls *}
himmelma@33175
   304
himmelma@33175
   305
definition
himmelma@33175
   306
  ball :: "'a::metric_space \<Rightarrow> real \<Rightarrow> 'a set" where
himmelma@33175
   307
  "ball x e = {y. dist x y < e}"
himmelma@33175
   308
himmelma@33175
   309
definition
himmelma@33175
   310
  cball :: "'a::metric_space \<Rightarrow> real \<Rightarrow> 'a set" where
himmelma@33175
   311
  "cball x e = {y. dist x y \<le> e}"
himmelma@33175
   312
huffman@45776
   313
lemma mem_ball [simp]: "y \<in> ball x e \<longleftrightarrow> dist x y < e"
huffman@45776
   314
  by (simp add: ball_def)
huffman@45776
   315
huffman@45776
   316
lemma mem_cball [simp]: "y \<in> cball x e \<longleftrightarrow> dist x y \<le> e"
huffman@45776
   317
  by (simp add: cball_def)
huffman@45776
   318
huffman@45776
   319
lemma mem_ball_0:
himmelma@33175
   320
  fixes x :: "'a::real_normed_vector"
himmelma@33175
   321
  shows "x \<in> ball 0 e \<longleftrightarrow> norm x < e"
himmelma@33175
   322
  by (simp add: dist_norm)
himmelma@33175
   323
huffman@45776
   324
lemma mem_cball_0:
himmelma@33175
   325
  fixes x :: "'a::real_normed_vector"
himmelma@33175
   326
  shows "x \<in> cball 0 e \<longleftrightarrow> norm x \<le> e"
himmelma@33175
   327
  by (simp add: dist_norm)
himmelma@33175
   328
huffman@45776
   329
lemma centre_in_ball: "x \<in> ball x e \<longleftrightarrow> 0 < e"
huffman@45776
   330
  by simp
huffman@45776
   331
huffman@45776
   332
lemma centre_in_cball: "x \<in> cball x e \<longleftrightarrow> 0 \<le> e"
huffman@45776
   333
  by simp
huffman@45776
   334
himmelma@33175
   335
lemma ball_subset_cball[simp,intro]: "ball x e \<subseteq> cball x e" by (simp add: subset_eq)
himmelma@33175
   336
lemma subset_ball[intro]: "d <= e ==> ball x d \<subseteq> ball x e" by (simp add: subset_eq)
himmelma@33175
   337
lemma subset_cball[intro]: "d <= e ==> cball x d \<subseteq> cball x e" by (simp add: subset_eq)
himmelma@33175
   338
lemma ball_max_Un: "ball a (max r s) = ball a r \<union> ball a s"
nipkow@39302
   339
  by (simp add: set_eq_iff) arith
himmelma@33175
   340
himmelma@33175
   341
lemma ball_min_Int: "ball a (min r s) = ball a r \<inter> ball a s"
nipkow@39302
   342
  by (simp add: set_eq_iff)
himmelma@33175
   343
himmelma@33175
   344
lemma diff_less_iff: "(a::real) - b > 0 \<longleftrightarrow> a > b"
himmelma@33175
   345
  "(a::real) - b < 0 \<longleftrightarrow> a < b"
himmelma@33175
   346
  "a - b < c \<longleftrightarrow> a < c +b" "a - b > c \<longleftrightarrow> a > c +b" by arith+
himmelma@33175
   347
lemma diff_le_iff: "(a::real) - b \<ge> 0 \<longleftrightarrow> a \<ge> b" "(a::real) - b \<le> 0 \<longleftrightarrow> a \<le> b"
himmelma@33175
   348
  "a - b \<le> c \<longleftrightarrow> a \<le> c +b" "a - b \<ge> c \<longleftrightarrow> a \<ge> c +b"  by arith+
himmelma@33175
   349
himmelma@33175
   350
lemma open_ball[intro, simp]: "open (ball x e)"
huffman@44170
   351
  unfolding open_dist ball_def mem_Collect_eq Ball_def
himmelma@33175
   352
  unfolding dist_commute
himmelma@33175
   353
  apply clarify
himmelma@33175
   354
  apply (rule_tac x="e - dist xa x" in exI)
himmelma@33175
   355
  using dist_triangle_alt[where z=x]
himmelma@33175
   356
  apply (clarsimp simp add: diff_less_iff)
himmelma@33175
   357
  apply atomize
himmelma@33175
   358
  apply (erule_tac x="y" in allE)
himmelma@33175
   359
  apply (erule_tac x="xa" in allE)
himmelma@33175
   360
  by arith
himmelma@33175
   361
himmelma@33175
   362
lemma open_contains_ball: "open S \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0. ball x e \<subseteq> S)"
himmelma@33175
   363
  unfolding open_dist subset_eq mem_ball Ball_def dist_commute ..
himmelma@33175
   364
hoelzl@33714
   365
lemma openE[elim?]:
hoelzl@33714
   366
  assumes "open S" "x\<in>S" 
hoelzl@33714
   367
  obtains e where "e>0" "ball x e \<subseteq> S"
hoelzl@33714
   368
  using assms unfolding open_contains_ball by auto
hoelzl@33714
   369
himmelma@33175
   370
lemma open_contains_ball_eq: "open S \<Longrightarrow> \<forall>x. x\<in>S \<longleftrightarrow> (\<exists>e>0. ball x e \<subseteq> S)"
himmelma@33175
   371
  by (metis open_contains_ball subset_eq centre_in_ball)
himmelma@33175
   372
himmelma@33175
   373
lemma ball_eq_empty[simp]: "ball x e = {} \<longleftrightarrow> e \<le> 0"
nipkow@39302
   374
  unfolding mem_ball set_eq_iff
himmelma@33175
   375
  apply (simp add: not_less)
himmelma@33175
   376
  by (metis zero_le_dist order_trans dist_self)
himmelma@33175
   377
himmelma@33175
   378
lemma ball_empty[intro]: "e \<le> 0 ==> ball x e = {}" by simp
himmelma@33175
   379
himmelma@33175
   380
himmelma@33175
   381
subsection{* Connectedness *}
himmelma@33175
   382
himmelma@33175
   383
definition "connected S \<longleftrightarrow>
himmelma@33175
   384
  ~(\<exists>e1 e2. open e1 \<and> open e2 \<and> S \<subseteq> (e1 \<union> e2) \<and> (e1 \<inter> e2 \<inter> S = {})
himmelma@33175
   385
  \<and> ~(e1 \<inter> S = {}) \<and> ~(e2 \<inter> S = {}))"
himmelma@33175
   386
himmelma@33175
   387
lemma connected_local:
himmelma@33175
   388
 "connected S \<longleftrightarrow> ~(\<exists>e1 e2.
himmelma@33175
   389
                 openin (subtopology euclidean S) e1 \<and>
himmelma@33175
   390
                 openin (subtopology euclidean S) e2 \<and>
himmelma@33175
   391
                 S \<subseteq> e1 \<union> e2 \<and>
himmelma@33175
   392
                 e1 \<inter> e2 = {} \<and>
himmelma@33175
   393
                 ~(e1 = {}) \<and>
himmelma@33175
   394
                 ~(e2 = {}))"
himmelma@33175
   395
unfolding connected_def openin_open by (safe, blast+)
himmelma@33175
   396
huffman@34105
   397
lemma exists_diff:
huffman@34105
   398
  fixes P :: "'a set \<Rightarrow> bool"
huffman@34105
   399
  shows "(\<exists>S. P(- S)) \<longleftrightarrow> (\<exists>S. P S)" (is "?lhs \<longleftrightarrow> ?rhs")
himmelma@33175
   400
proof-
himmelma@33175
   401
  {assume "?lhs" hence ?rhs by blast }
himmelma@33175
   402
  moreover
himmelma@33175
   403
  {fix S assume H: "P S"
huffman@34105
   404
    have "S = - (- S)" by auto
huffman@34105
   405
    with H have "P (- (- S))" by metis }
himmelma@33175
   406
  ultimately show ?thesis by metis
himmelma@33175
   407
qed
himmelma@33175
   408
himmelma@33175
   409
lemma connected_clopen: "connected S \<longleftrightarrow>
himmelma@33175
   410
        (\<forall>T. openin (subtopology euclidean S) T \<and>
himmelma@33175
   411
            closedin (subtopology euclidean S) T \<longrightarrow> T = {} \<or> T = S)" (is "?lhs \<longleftrightarrow> ?rhs")
himmelma@33175
   412
proof-
huffman@34105
   413
  have " \<not> connected S \<longleftrightarrow> (\<exists>e1 e2. open e1 \<and> open (- e2) \<and> S \<subseteq> e1 \<union> (- e2) \<and> e1 \<inter> (- e2) \<inter> S = {} \<and> e1 \<inter> S \<noteq> {} \<and> (- e2) \<inter> S \<noteq> {})"
himmelma@33175
   414
    unfolding connected_def openin_open closedin_closed
himmelma@33175
   415
    apply (subst exists_diff) by blast
huffman@34105
   416
  hence th0: "connected S \<longleftrightarrow> \<not> (\<exists>e2 e1. closed e2 \<and> open e1 \<and> S \<subseteq> e1 \<union> (- e2) \<and> e1 \<inter> (- e2) \<inter> S = {} \<and> e1 \<inter> S \<noteq> {} \<and> (- e2) \<inter> S \<noteq> {})"
huffman@34105
   417
    (is " _ \<longleftrightarrow> \<not> (\<exists>e2 e1. ?P e2 e1)") apply (simp add: closed_def) by metis
himmelma@33175
   418
himmelma@33175
   419
  have th1: "?rhs \<longleftrightarrow> \<not> (\<exists>t' t. closed t'\<and>t = S\<inter>t' \<and> t\<noteq>{} \<and> t\<noteq>S \<and> (\<exists>t'. open t' \<and> t = S \<inter> t'))"
himmelma@33175
   420
    (is "_ \<longleftrightarrow> \<not> (\<exists>t' t. ?Q t' t)")
himmelma@33175
   421
    unfolding connected_def openin_open closedin_closed by auto
himmelma@33175
   422
  {fix e2
himmelma@33175
   423
    {fix e1 have "?P e2 e1 \<longleftrightarrow> (\<exists>t.  closed e2 \<and> t = S\<inter>e2 \<and> open e1 \<and> t = S\<inter>e1 \<and> t\<noteq>{} \<and> t\<noteq>S)"
himmelma@33175
   424
        by auto}
himmelma@33175
   425
    then have "(\<exists>e1. ?P e2 e1) \<longleftrightarrow> (\<exists>t. ?Q e2 t)" by metis}
himmelma@33175
   426
  then have "\<forall>e2. (\<exists>e1. ?P e2 e1) \<longleftrightarrow> (\<exists>t. ?Q e2 t)" by blast
himmelma@33175
   427
  then show ?thesis unfolding th0 th1 by simp
himmelma@33175
   428
qed
himmelma@33175
   429
himmelma@33175
   430
lemma connected_empty[simp, intro]: "connected {}"
himmelma@33175
   431
  by (simp add: connected_def)
himmelma@33175
   432
huffman@44210
   433
himmelma@33175
   434
subsection{* Limit points *}
himmelma@33175
   435
huffman@44207
   436
definition (in topological_space)
huffman@44207
   437
  islimpt:: "'a \<Rightarrow> 'a set \<Rightarrow> bool" (infixr "islimpt" 60) where
himmelma@33175
   438
  "x islimpt S \<longleftrightarrow> (\<forall>T. x\<in>T \<longrightarrow> open T \<longrightarrow> (\<exists>y\<in>S. y\<in>T \<and> y\<noteq>x))"
himmelma@33175
   439
himmelma@33175
   440
lemma islimptI:
himmelma@33175
   441
  assumes "\<And>T. x \<in> T \<Longrightarrow> open T \<Longrightarrow> \<exists>y\<in>S. y \<in> T \<and> y \<noteq> x"
himmelma@33175
   442
  shows "x islimpt S"
himmelma@33175
   443
  using assms unfolding islimpt_def by auto
himmelma@33175
   444
himmelma@33175
   445
lemma islimptE:
himmelma@33175
   446
  assumes "x islimpt S" and "x \<in> T" and "open T"
himmelma@33175
   447
  obtains y where "y \<in> S" and "y \<in> T" and "y \<noteq> x"
himmelma@33175
   448
  using assms unfolding islimpt_def by auto
himmelma@33175
   449
huffman@44584
   450
lemma islimpt_iff_eventually: "x islimpt S \<longleftrightarrow> \<not> eventually (\<lambda>y. y \<notin> S) (at x)"
huffman@44584
   451
  unfolding islimpt_def eventually_at_topological by auto
huffman@44584
   452
huffman@44584
   453
lemma islimpt_subset: "\<lbrakk>x islimpt S; S \<subseteq> T\<rbrakk> \<Longrightarrow> x islimpt T"
huffman@44584
   454
  unfolding islimpt_def by fast
himmelma@33175
   455
himmelma@33175
   456
lemma islimpt_approachable:
himmelma@33175
   457
  fixes x :: "'a::metric_space"
himmelma@33175
   458
  shows "x islimpt S \<longleftrightarrow> (\<forall>e>0. \<exists>x'\<in>S. x' \<noteq> x \<and> dist x' x < e)"
huffman@44584
   459
  unfolding islimpt_iff_eventually eventually_at by fast
himmelma@33175
   460
himmelma@33175
   461
lemma islimpt_approachable_le:
himmelma@33175
   462
  fixes x :: "'a::metric_space"
himmelma@33175
   463
  shows "x islimpt S \<longleftrightarrow> (\<forall>e>0. \<exists>x'\<in> S. x' \<noteq> x \<and> dist x' x <= e)"
himmelma@33175
   464
  unfolding islimpt_approachable
huffman@44584
   465
  using approachable_lt_le [where f="\<lambda>y. dist y x" and P="\<lambda>y. y \<notin> S \<or> y = x",
huffman@44584
   466
    THEN arg_cong [where f=Not]]
huffman@44584
   467
  by (simp add: Bex_def conj_commute conj_left_commute)
himmelma@33175
   468
huffman@44571
   469
lemma islimpt_UNIV_iff: "x islimpt UNIV \<longleftrightarrow> \<not> open {x}"
huffman@44571
   470
  unfolding islimpt_def by (safe, fast, case_tac "T = {x}", fast, fast)
huffman@44571
   471
huffman@44210
   472
text {* A perfect space has no isolated points. *}
huffman@44210
   473
huffman@44571
   474
lemma islimpt_UNIV [simp, intro]: "(x::'a::perfect_space) islimpt UNIV"
huffman@44571
   475
  unfolding islimpt_UNIV_iff by (rule not_open_singleton)
himmelma@33175
   476
himmelma@33175
   477
lemma perfect_choose_dist:
huffman@44072
   478
  fixes x :: "'a::{perfect_space, metric_space}"
himmelma@33175
   479
  shows "0 < r \<Longrightarrow> \<exists>a. a \<noteq> x \<and> dist a x < r"
himmelma@33175
   480
using islimpt_UNIV [of x]
himmelma@33175
   481
by (simp add: islimpt_approachable)
himmelma@33175
   482
himmelma@33175
   483
lemma closed_limpt: "closed S \<longleftrightarrow> (\<forall>x. x islimpt S \<longrightarrow> x \<in> S)"
himmelma@33175
   484
  unfolding closed_def
himmelma@33175
   485
  apply (subst open_subopen)
huffman@34105
   486
  apply (simp add: islimpt_def subset_eq)
huffman@44170
   487
  by (metis ComplE ComplI)
himmelma@33175
   488
himmelma@33175
   489
lemma islimpt_EMPTY[simp]: "\<not> x islimpt {}"
himmelma@33175
   490
  unfolding islimpt_def by auto
himmelma@33175
   491
himmelma@33175
   492
lemma finite_set_avoid:
himmelma@33175
   493
  fixes a :: "'a::metric_space"
himmelma@33175
   494
  assumes fS: "finite S" shows  "\<exists>d>0. \<forall>x\<in>S. x \<noteq> a \<longrightarrow> d <= dist a x"
himmelma@33175
   495
proof(induct rule: finite_induct[OF fS])
boehmes@41863
   496
  case 1 thus ?case by (auto intro: zero_less_one)
himmelma@33175
   497
next
himmelma@33175
   498
  case (2 x F)
himmelma@33175
   499
  from 2 obtain d where d: "d >0" "\<forall>x\<in>F. x\<noteq>a \<longrightarrow> d \<le> dist a x" by blast
himmelma@33175
   500
  {assume "x = a" hence ?case using d by auto  }
himmelma@33175
   501
  moreover
himmelma@33175
   502
  {assume xa: "x\<noteq>a"
himmelma@33175
   503
    let ?d = "min d (dist a x)"
himmelma@33175
   504
    have dp: "?d > 0" using xa d(1) using dist_nz by auto
himmelma@33175
   505
    from d have d': "\<forall>x\<in>F. x\<noteq>a \<longrightarrow> ?d \<le> dist a x" by auto
himmelma@33175
   506
    with dp xa have ?case by(auto intro!: exI[where x="?d"]) }
himmelma@33175
   507
  ultimately show ?case by blast
himmelma@33175
   508
qed
himmelma@33175
   509
himmelma@33175
   510
lemma islimpt_finite:
himmelma@33175
   511
  fixes S :: "'a::metric_space set"
himmelma@33175
   512
  assumes fS: "finite S" shows "\<not> a islimpt S"
himmelma@33175
   513
  unfolding islimpt_approachable
himmelma@33175
   514
  using finite_set_avoid[OF fS, of a] by (metis dist_commute  not_le)
himmelma@33175
   515
himmelma@33175
   516
lemma islimpt_Un: "x islimpt (S \<union> T) \<longleftrightarrow> x islimpt S \<or> x islimpt T"
himmelma@33175
   517
  apply (rule iffI)
himmelma@33175
   518
  defer
himmelma@33175
   519
  apply (metis Un_upper1 Un_upper2 islimpt_subset)
himmelma@33175
   520
  unfolding islimpt_def
himmelma@33175
   521
  apply (rule ccontr, clarsimp, rename_tac A B)
himmelma@33175
   522
  apply (drule_tac x="A \<inter> B" in spec)
himmelma@33175
   523
  apply (auto simp add: open_Int)
himmelma@33175
   524
  done
himmelma@33175
   525
himmelma@33175
   526
lemma discrete_imp_closed:
himmelma@33175
   527
  fixes S :: "'a::metric_space set"
himmelma@33175
   528
  assumes e: "0 < e" and d: "\<forall>x \<in> S. \<forall>y \<in> S. dist y x < e \<longrightarrow> y = x"
himmelma@33175
   529
  shows "closed S"
himmelma@33175
   530
proof-
himmelma@33175
   531
  {fix x assume C: "\<forall>e>0. \<exists>x'\<in>S. x' \<noteq> x \<and> dist x' x < e"
himmelma@33175
   532
    from e have e2: "e/2 > 0" by arith
himmelma@33175
   533
    from C[rule_format, OF e2] obtain y where y: "y \<in> S" "y\<noteq>x" "dist y x < e/2" by blast
himmelma@33175
   534
    let ?m = "min (e/2) (dist x y) "
himmelma@33175
   535
    from e2 y(2) have mp: "?m > 0" by (simp add: dist_nz[THEN sym])
himmelma@33175
   536
    from C[rule_format, OF mp] obtain z where z: "z \<in> S" "z\<noteq>x" "dist z x < ?m" by blast
himmelma@33175
   537
    have th: "dist z y < e" using z y
himmelma@33175
   538
      by (intro dist_triangle_lt [where z=x], simp)
himmelma@33175
   539
    from d[rule_format, OF y(1) z(1) th] y z
himmelma@33175
   540
    have False by (auto simp add: dist_commute)}
himmelma@33175
   541
  then show ?thesis by (metis islimpt_approachable closed_limpt [where 'a='a])
himmelma@33175
   542
qed
himmelma@33175
   543
huffman@44210
   544
huffman@44210
   545
subsection {* Interior of a Set *}
huffman@44210
   546
huffman@44519
   547
definition "interior S = \<Union>{T. open T \<and> T \<subseteq> S}"
huffman@44519
   548
huffman@44519
   549
lemma interiorI [intro?]:
huffman@44519
   550
  assumes "open T" and "x \<in> T" and "T \<subseteq> S"
huffman@44519
   551
  shows "x \<in> interior S"
huffman@44519
   552
  using assms unfolding interior_def by fast
huffman@44519
   553
huffman@44519
   554
lemma interiorE [elim?]:
huffman@44519
   555
  assumes "x \<in> interior S"
huffman@44519
   556
  obtains T where "open T" and "x \<in> T" and "T \<subseteq> S"
huffman@44519
   557
  using assms unfolding interior_def by fast
huffman@44519
   558
huffman@44519
   559
lemma open_interior [simp, intro]: "open (interior S)"
huffman@44519
   560
  by (simp add: interior_def open_Union)
huffman@44519
   561
huffman@44519
   562
lemma interior_subset: "interior S \<subseteq> S"
huffman@44519
   563
  by (auto simp add: interior_def)
huffman@44519
   564
huffman@44519
   565
lemma interior_maximal: "T \<subseteq> S \<Longrightarrow> open T \<Longrightarrow> T \<subseteq> interior S"
huffman@44519
   566
  by (auto simp add: interior_def)
huffman@44519
   567
huffman@44519
   568
lemma interior_open: "open S \<Longrightarrow> interior S = S"
huffman@44519
   569
  by (intro equalityI interior_subset interior_maximal subset_refl)
himmelma@33175
   570
himmelma@33175
   571
lemma interior_eq: "interior S = S \<longleftrightarrow> open S"
huffman@44519
   572
  by (metis open_interior interior_open)
huffman@44519
   573
huffman@44519
   574
lemma open_subset_interior: "open S \<Longrightarrow> S \<subseteq> interior T \<longleftrightarrow> S \<subseteq> T"
himmelma@33175
   575
  by (metis interior_maximal interior_subset subset_trans)
himmelma@33175
   576
huffman@44519
   577
lemma interior_empty [simp]: "interior {} = {}"
huffman@44519
   578
  using open_empty by (rule interior_open)
huffman@44519
   579
huffman@44522
   580
lemma interior_UNIV [simp]: "interior UNIV = UNIV"
huffman@44522
   581
  using open_UNIV by (rule interior_open)
huffman@44522
   582
huffman@44519
   583
lemma interior_interior [simp]: "interior (interior S) = interior S"
huffman@44519
   584
  using open_interior by (rule interior_open)
huffman@44519
   585
huffman@44522
   586
lemma interior_mono: "S \<subseteq> T \<Longrightarrow> interior S \<subseteq> interior T"
huffman@44522
   587
  by (auto simp add: interior_def)
huffman@44519
   588
huffman@44519
   589
lemma interior_unique:
huffman@44519
   590
  assumes "T \<subseteq> S" and "open T"
huffman@44519
   591
  assumes "\<And>T'. T' \<subseteq> S \<Longrightarrow> open T' \<Longrightarrow> T' \<subseteq> T"
huffman@44519
   592
  shows "interior S = T"
huffman@44519
   593
  by (intro equalityI assms interior_subset open_interior interior_maximal)
huffman@44519
   594
huffman@44519
   595
lemma interior_inter [simp]: "interior (S \<inter> T) = interior S \<inter> interior T"
huffman@44522
   596
  by (intro equalityI Int_mono Int_greatest interior_mono Int_lower1
huffman@44519
   597
    Int_lower2 interior_maximal interior_subset open_Int open_interior)
huffman@44519
   598
huffman@44519
   599
lemma mem_interior: "x \<in> interior S \<longleftrightarrow> (\<exists>e>0. ball x e \<subseteq> S)"
huffman@44519
   600
  using open_contains_ball_eq [where S="interior S"]
huffman@44519
   601
  by (simp add: open_subset_interior)
himmelma@33175
   602
himmelma@33175
   603
lemma interior_limit_point [intro]:
himmelma@33175
   604
  fixes x :: "'a::perfect_space"
himmelma@33175
   605
  assumes x: "x \<in> interior S" shows "x islimpt S"
huffman@44072
   606
  using x islimpt_UNIV [of x]
huffman@44072
   607
  unfolding interior_def islimpt_def
huffman@44072
   608
  apply (clarsimp, rename_tac T T')
huffman@44072
   609
  apply (drule_tac x="T \<inter> T'" in spec)
huffman@44072
   610
  apply (auto simp add: open_Int)
huffman@44072
   611
  done
himmelma@33175
   612
himmelma@33175
   613
lemma interior_closed_Un_empty_interior:
himmelma@33175
   614
  assumes cS: "closed S" and iT: "interior T = {}"
huffman@44519
   615
  shows "interior (S \<union> T) = interior S"
himmelma@33175
   616
proof
huffman@44519
   617
  show "interior S \<subseteq> interior (S \<union> T)"
huffman@44522
   618
    by (rule interior_mono, rule Un_upper1)
himmelma@33175
   619
next
himmelma@33175
   620
  show "interior (S \<union> T) \<subseteq> interior S"
himmelma@33175
   621
  proof
himmelma@33175
   622
    fix x assume "x \<in> interior (S \<union> T)"
huffman@44519
   623
    then obtain R where "open R" "x \<in> R" "R \<subseteq> S \<union> T" ..
himmelma@33175
   624
    show "x \<in> interior S"
himmelma@33175
   625
    proof (rule ccontr)
himmelma@33175
   626
      assume "x \<notin> interior S"
himmelma@33175
   627
      with `x \<in> R` `open R` obtain y where "y \<in> R - S"
huffman@44519
   628
        unfolding interior_def by fast
himmelma@33175
   629
      from `open R` `closed S` have "open (R - S)" by (rule open_Diff)
himmelma@33175
   630
      from `R \<subseteq> S \<union> T` have "R - S \<subseteq> T" by fast
himmelma@33175
   631
      from `y \<in> R - S` `open (R - S)` `R - S \<subseteq> T` `interior T = {}`
himmelma@33175
   632
      show "False" unfolding interior_def by fast
himmelma@33175
   633
    qed
himmelma@33175
   634
  qed
himmelma@33175
   635
qed
himmelma@33175
   636
huffman@44365
   637
lemma interior_Times: "interior (A \<times> B) = interior A \<times> interior B"
huffman@44365
   638
proof (rule interior_unique)
huffman@44365
   639
  show "interior A \<times> interior B \<subseteq> A \<times> B"
huffman@44365
   640
    by (intro Sigma_mono interior_subset)
huffman@44365
   641
  show "open (interior A \<times> interior B)"
huffman@44365
   642
    by (intro open_Times open_interior)
huffman@44519
   643
  fix T assume "T \<subseteq> A \<times> B" and "open T" thus "T \<subseteq> interior A \<times> interior B"
huffman@44519
   644
  proof (safe)
huffman@44519
   645
    fix x y assume "(x, y) \<in> T"
huffman@44519
   646
    then obtain C D where "open C" "open D" "C \<times> D \<subseteq> T" "x \<in> C" "y \<in> D"
huffman@44519
   647
      using `open T` unfolding open_prod_def by fast
huffman@44519
   648
    hence "open C" "open D" "C \<subseteq> A" "D \<subseteq> B" "x \<in> C" "y \<in> D"
huffman@44519
   649
      using `T \<subseteq> A \<times> B` by auto
huffman@44519
   650
    thus "x \<in> interior A" and "y \<in> interior B"
huffman@44519
   651
      by (auto intro: interiorI)
huffman@44519
   652
  qed
huffman@44365
   653
qed
huffman@44365
   654
himmelma@33175
   655
huffman@44210
   656
subsection {* Closure of a Set *}
himmelma@33175
   657
himmelma@33175
   658
definition "closure S = S \<union> {x | x. x islimpt S}"
himmelma@33175
   659
huffman@44518
   660
lemma interior_closure: "interior S = - (closure (- S))"
huffman@44518
   661
  unfolding interior_def closure_def islimpt_def by auto
huffman@44518
   662
huffman@34105
   663
lemma closure_interior: "closure S = - interior (- S)"
huffman@44518
   664
  unfolding interior_closure by simp
himmelma@33175
   665
himmelma@33175
   666
lemma closed_closure[simp, intro]: "closed (closure S)"
huffman@44518
   667
  unfolding closure_interior by (simp add: closed_Compl)
huffman@44518
   668
huffman@44518
   669
lemma closure_subset: "S \<subseteq> closure S"
huffman@44518
   670
  unfolding closure_def by simp
himmelma@33175
   671
himmelma@33175
   672
lemma closure_hull: "closure S = closed hull S"
huffman@44519
   673
  unfolding hull_def closure_interior interior_def by auto
himmelma@33175
   674
himmelma@33175
   675
lemma closure_eq: "closure S = S \<longleftrightarrow> closed S"
huffman@44519
   676
  unfolding closure_hull using closed_Inter by (rule hull_eq)
huffman@44519
   677
huffman@44519
   678
lemma closure_closed [simp]: "closed S \<Longrightarrow> closure S = S"
huffman@44519
   679
  unfolding closure_eq .
huffman@44519
   680
huffman@44519
   681
lemma closure_closure [simp]: "closure (closure S) = closure S"
huffman@44518
   682
  unfolding closure_hull by (rule hull_hull)
himmelma@33175
   683
huffman@44522
   684
lemma closure_mono: "S \<subseteq> T \<Longrightarrow> closure S \<subseteq> closure T"
huffman@44518
   685
  unfolding closure_hull by (rule hull_mono)
himmelma@33175
   686
huffman@44519
   687
lemma closure_minimal: "S \<subseteq> T \<Longrightarrow> closed T \<Longrightarrow> closure S \<subseteq> T"
huffman@44518
   688
  unfolding closure_hull by (rule hull_minimal)
himmelma@33175
   689
huffman@44519
   690
lemma closure_unique:
huffman@44519
   691
  assumes "S \<subseteq> T" and "closed T"
huffman@44519
   692
  assumes "\<And>T'. S \<subseteq> T' \<Longrightarrow> closed T' \<Longrightarrow> T \<subseteq> T'"
huffman@44519
   693
  shows "closure S = T"
huffman@44519
   694
  using assms unfolding closure_hull by (rule hull_unique)
huffman@44519
   695
huffman@44519
   696
lemma closure_empty [simp]: "closure {} = {}"
huffman@44518
   697
  using closed_empty by (rule closure_closed)
himmelma@33175
   698
huffman@44522
   699
lemma closure_UNIV [simp]: "closure UNIV = UNIV"
huffman@44518
   700
  using closed_UNIV by (rule closure_closed)
huffman@44518
   701
huffman@44518
   702
lemma closure_union [simp]: "closure (S \<union> T) = closure S \<union> closure T"
huffman@44518
   703
  unfolding closure_interior by simp
himmelma@33175
   704
himmelma@33175
   705
lemma closure_eq_empty: "closure S = {} \<longleftrightarrow> S = {}"
himmelma@33175
   706
  using closure_empty closure_subset[of S]
himmelma@33175
   707
  by blast
himmelma@33175
   708
himmelma@33175
   709
lemma closure_subset_eq: "closure S \<subseteq> S \<longleftrightarrow> closed S"
himmelma@33175
   710
  using closure_eq[of S] closure_subset[of S]
himmelma@33175
   711
  by simp
himmelma@33175
   712
himmelma@33175
   713
lemma open_inter_closure_eq_empty:
himmelma@33175
   714
  "open S \<Longrightarrow> (S \<inter> closure T) = {} \<longleftrightarrow> S \<inter> T = {}"
huffman@34105
   715
  using open_subset_interior[of S "- T"]
huffman@34105
   716
  using interior_subset[of "- T"]
himmelma@33175
   717
  unfolding closure_interior
himmelma@33175
   718
  by auto
himmelma@33175
   719
himmelma@33175
   720
lemma open_inter_closure_subset:
himmelma@33175
   721
  "open S \<Longrightarrow> (S \<inter> (closure T)) \<subseteq> closure(S \<inter> T)"
himmelma@33175
   722
proof
himmelma@33175
   723
  fix x
himmelma@33175
   724
  assume as: "open S" "x \<in> S \<inter> closure T"
himmelma@33175
   725
  { assume *:"x islimpt T"
himmelma@33175
   726
    have "x islimpt (S \<inter> T)"
himmelma@33175
   727
    proof (rule islimptI)
himmelma@33175
   728
      fix A
himmelma@33175
   729
      assume "x \<in> A" "open A"
himmelma@33175
   730
      with as have "x \<in> A \<inter> S" "open (A \<inter> S)"
himmelma@33175
   731
        by (simp_all add: open_Int)
himmelma@33175
   732
      with * obtain y where "y \<in> T" "y \<in> A \<inter> S" "y \<noteq> x"
himmelma@33175
   733
        by (rule islimptE)
himmelma@33175
   734
      hence "y \<in> S \<inter> T" "y \<in> A \<and> y \<noteq> x"
himmelma@33175
   735
        by simp_all
himmelma@33175
   736
      thus "\<exists>y\<in>(S \<inter> T). y \<in> A \<and> y \<noteq> x" ..
himmelma@33175
   737
    qed
himmelma@33175
   738
  }
himmelma@33175
   739
  then show "x \<in> closure (S \<inter> T)" using as
himmelma@33175
   740
    unfolding closure_def
himmelma@33175
   741
    by blast
himmelma@33175
   742
qed
himmelma@33175
   743
huffman@44519
   744
lemma closure_complement: "closure (- S) = - interior S"
huffman@44518
   745
  unfolding closure_interior by simp
himmelma@33175
   746
huffman@44519
   747
lemma interior_complement: "interior (- S) = - closure S"
huffman@44518
   748
  unfolding closure_interior by simp
himmelma@33175
   749
huffman@44365
   750
lemma closure_Times: "closure (A \<times> B) = closure A \<times> closure B"
huffman@44519
   751
proof (rule closure_unique)
huffman@44365
   752
  show "A \<times> B \<subseteq> closure A \<times> closure B"
huffman@44365
   753
    by (intro Sigma_mono closure_subset)
huffman@44365
   754
  show "closed (closure A \<times> closure B)"
huffman@44365
   755
    by (intro closed_Times closed_closure)
huffman@44519
   756
  fix T assume "A \<times> B \<subseteq> T" and "closed T" thus "closure A \<times> closure B \<subseteq> T"
huffman@44365
   757
    apply (simp add: closed_def open_prod_def, clarify)
huffman@44365
   758
    apply (rule ccontr)
huffman@44365
   759
    apply (drule_tac x="(a, b)" in bspec, simp, clarify, rename_tac C D)
huffman@44365
   760
    apply (simp add: closure_interior interior_def)
huffman@44365
   761
    apply (drule_tac x=C in spec)
huffman@44365
   762
    apply (drule_tac x=D in spec)
huffman@44365
   763
    apply auto
huffman@44365
   764
    done
huffman@44365
   765
qed
huffman@44365
   766
huffman@44210
   767
huffman@44210
   768
subsection {* Frontier (aka boundary) *}
himmelma@33175
   769
himmelma@33175
   770
definition "frontier S = closure S - interior S"
himmelma@33175
   771
himmelma@33175
   772
lemma frontier_closed: "closed(frontier S)"
himmelma@33175
   773
  by (simp add: frontier_def closed_Diff)
himmelma@33175
   774
huffman@34105
   775
lemma frontier_closures: "frontier S = (closure S) \<inter> (closure(- S))"
himmelma@33175
   776
  by (auto simp add: frontier_def interior_closure)
himmelma@33175
   777
himmelma@33175
   778
lemma frontier_straddle:
himmelma@33175
   779
  fixes a :: "'a::metric_space"
huffman@44909
   780
  shows "a \<in> frontier S \<longleftrightarrow> (\<forall>e>0. (\<exists>x\<in>S. dist a x < e) \<and> (\<exists>x. x \<notin> S \<and> dist a x < e))"
huffman@44909
   781
  unfolding frontier_def closure_interior
huffman@44909
   782
  by (auto simp add: mem_interior subset_eq ball_def)
himmelma@33175
   783
himmelma@33175
   784
lemma frontier_subset_closed: "closed S \<Longrightarrow> frontier S \<subseteq> S"
himmelma@33175
   785
  by (metis frontier_def closure_closed Diff_subset)
himmelma@33175
   786
hoelzl@34964
   787
lemma frontier_empty[simp]: "frontier {} = {}"
huffman@36362
   788
  by (simp add: frontier_def)
himmelma@33175
   789
himmelma@33175
   790
lemma frontier_subset_eq: "frontier S \<subseteq> S \<longleftrightarrow> closed S"
himmelma@33175
   791
proof-
himmelma@33175
   792
  { assume "frontier S \<subseteq> S"
himmelma@33175
   793
    hence "closure S \<subseteq> S" using interior_subset unfolding frontier_def by auto
himmelma@33175
   794
    hence "closed S" using closure_subset_eq by auto
himmelma@33175
   795
  }
huffman@36362
   796
  thus ?thesis using frontier_subset_closed[of S] ..
himmelma@33175
   797
qed
himmelma@33175
   798
huffman@34105
   799
lemma frontier_complement: "frontier(- S) = frontier S"
himmelma@33175
   800
  by (auto simp add: frontier_def closure_complement interior_complement)
himmelma@33175
   801
himmelma@33175
   802
lemma frontier_disjoint_eq: "frontier S \<inter> S = {} \<longleftrightarrow> open S"
huffman@34105
   803
  using frontier_complement frontier_subset_eq[of "- S"]
huffman@34105
   804
  unfolding open_closed by auto
himmelma@33175
   805
huffman@44210
   806
huffman@44081
   807
subsection {* Filters and the ``eventually true'' quantifier *}
huffman@44081
   808
himmelma@33175
   809
definition
huffman@44081
   810
  at_infinity :: "'a::real_normed_vector filter" where
huffman@44081
   811
  "at_infinity = Abs_filter (\<lambda>P. \<exists>r. \<forall>x. r \<le> norm x \<longrightarrow> P x)"
himmelma@33175
   812
himmelma@33175
   813
definition
huffman@44081
   814
  indirection :: "'a::real_normed_vector \<Rightarrow> 'a \<Rightarrow> 'a filter"
huffman@44081
   815
    (infixr "indirection" 70) where
himmelma@33175
   816
  "a indirection v = (at a) within {b. \<exists>c\<ge>0. b - a = scaleR c v}"
himmelma@33175
   817
huffman@44081
   818
text{* Prove That They are all filters. *}
himmelma@33175
   819
huffman@36358
   820
lemma eventually_at_infinity:
huffman@36358
   821
  "eventually P at_infinity \<longleftrightarrow> (\<exists>b. \<forall>x. norm x >= b \<longrightarrow> P x)"
himmelma@33175
   822
unfolding at_infinity_def
huffman@44081
   823
proof (rule eventually_Abs_filter, rule is_filter.intro)
huffman@36358
   824
  fix P Q :: "'a \<Rightarrow> bool"
huffman@36358
   825
  assume "\<exists>r. \<forall>x. r \<le> norm x \<longrightarrow> P x" and "\<exists>s. \<forall>x. s \<le> norm x \<longrightarrow> Q x"
huffman@36358
   826
  then obtain r s where
huffman@36358
   827
    "\<forall>x. r \<le> norm x \<longrightarrow> P x" and "\<forall>x. s \<le> norm x \<longrightarrow> Q x" by auto
huffman@36358
   828
  then have "\<forall>x. max r s \<le> norm x \<longrightarrow> P x \<and> Q x" by simp
huffman@36358
   829
  then show "\<exists>r. \<forall>x. r \<le> norm x \<longrightarrow> P x \<and> Q x" ..
huffman@36358
   830
qed auto
himmelma@33175
   831
huffman@36437
   832
text {* Identify Trivial limits, where we can't approach arbitrarily closely. *}
himmelma@33175
   833
himmelma@33175
   834
lemma trivial_limit_within:
himmelma@33175
   835
  shows "trivial_limit (at a within S) \<longleftrightarrow> \<not> a islimpt S"
himmelma@33175
   836
proof
himmelma@33175
   837
  assume "trivial_limit (at a within S)"
himmelma@33175
   838
  thus "\<not> a islimpt S"
himmelma@33175
   839
    unfolding trivial_limit_def
huffman@36358
   840
    unfolding eventually_within eventually_at_topological
himmelma@33175
   841
    unfolding islimpt_def
nipkow@39302
   842
    apply (clarsimp simp add: set_eq_iff)
himmelma@33175
   843
    apply (rename_tac T, rule_tac x=T in exI)
huffman@36358
   844
    apply (clarsimp, drule_tac x=y in bspec, simp_all)
himmelma@33175
   845
    done
himmelma@33175
   846
next
himmelma@33175
   847
  assume "\<not> a islimpt S"
himmelma@33175
   848
  thus "trivial_limit (at a within S)"
himmelma@33175
   849
    unfolding trivial_limit_def
huffman@36358
   850
    unfolding eventually_within eventually_at_topological
himmelma@33175
   851
    unfolding islimpt_def
huffman@36358
   852
    apply clarsimp
huffman@36358
   853
    apply (rule_tac x=T in exI)
huffman@36358
   854
    apply auto
himmelma@33175
   855
    done
himmelma@33175
   856
qed
himmelma@33175
   857
himmelma@33175
   858
lemma trivial_limit_at_iff: "trivial_limit (at a) \<longleftrightarrow> \<not> a islimpt UNIV"
huffman@45031
   859
  using trivial_limit_within [of a UNIV] by simp
himmelma@33175
   860
himmelma@33175
   861
lemma trivial_limit_at:
himmelma@33175
   862
  fixes a :: "'a::perfect_space"
himmelma@33175
   863
  shows "\<not> trivial_limit (at a)"
huffman@44571
   864
  by (rule at_neq_bot)
himmelma@33175
   865
himmelma@33175
   866
lemma trivial_limit_at_infinity:
huffman@44081
   867
  "\<not> trivial_limit (at_infinity :: ('a::{real_normed_vector,perfect_space}) filter)"
huffman@36358
   868
  unfolding trivial_limit_def eventually_at_infinity
huffman@36358
   869
  apply clarsimp
huffman@44072
   870
  apply (subgoal_tac "\<exists>x::'a. x \<noteq> 0", clarify)
huffman@44072
   871
   apply (rule_tac x="scaleR (b / norm x) x" in exI, simp)
huffman@44072
   872
  apply (cut_tac islimpt_UNIV [of "0::'a", unfolded islimpt_def])
huffman@44072
   873
  apply (drule_tac x=UNIV in spec, simp)
himmelma@33175
   874
  done
himmelma@33175
   875
huffman@36437
   876
text {* Some property holds "sufficiently close" to the limit point. *}
himmelma@33175
   877
himmelma@33175
   878
lemma eventually_at: (* FIXME: this replaces Limits.eventually_at *)
himmelma@33175
   879
  "eventually P (at a) \<longleftrightarrow> (\<exists>d>0. \<forall>x. 0 < dist x a \<and> dist x a < d \<longrightarrow> P x)"
himmelma@33175
   880
unfolding eventually_at dist_nz by auto
himmelma@33175
   881
himmelma@33175
   882
lemma eventually_within: "eventually P (at a within S) \<longleftrightarrow>
himmelma@33175
   883
        (\<exists>d>0. \<forall>x\<in>S. 0 < dist x a \<and> dist x a < d \<longrightarrow> P x)"
himmelma@33175
   884
unfolding eventually_within eventually_at dist_nz by auto
himmelma@33175
   885
himmelma@33175
   886
lemma eventually_within_le: "eventually P (at a within S) \<longleftrightarrow>
himmelma@33175
   887
        (\<exists>d>0. \<forall>x\<in>S. 0 < dist x a \<and> dist x a <= d \<longrightarrow> P x)" (is "?lhs = ?rhs")
himmelma@33175
   888
unfolding eventually_within
huffman@44668
   889
by auto (metis dense order_le_less_trans)
himmelma@33175
   890
himmelma@33175
   891
lemma eventually_happens: "eventually P net ==> trivial_limit net \<or> (\<exists>x. P x)"
huffman@36358
   892
  unfolding trivial_limit_def
huffman@36358
   893
  by (auto elim: eventually_rev_mp)
himmelma@33175
   894
himmelma@33175
   895
lemma trivial_limit_eventually: "trivial_limit net \<Longrightarrow> eventually P net"
huffman@45031
   896
  by simp
himmelma@33175
   897
himmelma@33175
   898
lemma trivial_limit_eq: "trivial_limit net \<longleftrightarrow> (\<forall>P. eventually P net)"
huffman@44342
   899
  by (simp add: filter_eq_iff)
himmelma@33175
   900
himmelma@33175
   901
text{* Combining theorems for "eventually" *}
himmelma@33175
   902
himmelma@33175
   903
lemma eventually_rev_mono:
himmelma@33175
   904
  "eventually P net \<Longrightarrow> (\<forall>x. P x \<longrightarrow> Q x) \<Longrightarrow> eventually Q net"
himmelma@33175
   905
using eventually_mono [of P Q] by fast
himmelma@33175
   906
himmelma@33175
   907
lemma not_eventually: "(\<forall>x. \<not> P x ) \<Longrightarrow> ~(trivial_limit net) ==> ~(eventually (\<lambda>x. P x) net)"
himmelma@33175
   908
  by (simp add: eventually_False)
himmelma@33175
   909
huffman@44210
   910
huffman@36437
   911
subsection {* Limits *}
himmelma@33175
   912
huffman@44081
   913
text{* Notation Lim to avoid collition with lim defined in analysis *}
huffman@44081
   914
huffman@44081
   915
definition Lim :: "'a filter \<Rightarrow> ('a \<Rightarrow> 'b::t2_space) \<Rightarrow> 'b"
huffman@44081
   916
  where "Lim A f = (THE l. (f ---> l) A)"
himmelma@33175
   917
himmelma@33175
   918
lemma Lim:
himmelma@33175
   919
 "(f ---> l) net \<longleftrightarrow>
himmelma@33175
   920
        trivial_limit net \<or>
himmelma@33175
   921
        (\<forall>e>0. eventually (\<lambda>x. dist (f x) l < e) net)"
himmelma@33175
   922
  unfolding tendsto_iff trivial_limit_eq by auto
himmelma@33175
   923
himmelma@33175
   924
text{* Show that they yield usual definitions in the various cases. *}
himmelma@33175
   925
himmelma@33175
   926
lemma Lim_within_le: "(f ---> l)(at a within S) \<longleftrightarrow>
himmelma@33175
   927
           (\<forall>e>0. \<exists>d>0. \<forall>x\<in>S. 0 < dist x a  \<and> dist x a  <= d \<longrightarrow> dist (f x) l < e)"
himmelma@33175
   928
  by (auto simp add: tendsto_iff eventually_within_le)
himmelma@33175
   929
himmelma@33175
   930
lemma Lim_within: "(f ---> l) (at a within S) \<longleftrightarrow>
himmelma@33175
   931
        (\<forall>e >0. \<exists>d>0. \<forall>x \<in> S. 0 < dist x a  \<and> dist x a  < d  \<longrightarrow> dist (f x) l < e)"
himmelma@33175
   932
  by (auto simp add: tendsto_iff eventually_within)
himmelma@33175
   933
himmelma@33175
   934
lemma Lim_at: "(f ---> l) (at a) \<longleftrightarrow>
himmelma@33175
   935
        (\<forall>e >0. \<exists>d>0. \<forall>x. 0 < dist x a  \<and> dist x a  < d  \<longrightarrow> dist (f x) l < e)"
himmelma@33175
   936
  by (auto simp add: tendsto_iff eventually_at)
himmelma@33175
   937
himmelma@33175
   938
lemma Lim_at_infinity:
himmelma@33175
   939
  "(f ---> l) at_infinity \<longleftrightarrow> (\<forall>e>0. \<exists>b. \<forall>x. norm x >= b \<longrightarrow> dist (f x) l < e)"
himmelma@33175
   940
  by (auto simp add: tendsto_iff eventually_at_infinity)
himmelma@33175
   941
himmelma@33175
   942
lemma Lim_eventually: "eventually (\<lambda>x. f x = l) net \<Longrightarrow> (f ---> l) net"
himmelma@33175
   943
  by (rule topological_tendstoI, auto elim: eventually_rev_mono)
himmelma@33175
   944
himmelma@33175
   945
text{* The expected monotonicity property. *}
himmelma@33175
   946
himmelma@33175
   947
lemma Lim_within_empty: "(f ---> l) (net within {})"
himmelma@33175
   948
  unfolding tendsto_def Limits.eventually_within by simp
himmelma@33175
   949
himmelma@33175
   950
lemma Lim_within_subset: "(f ---> l) (net within S) \<Longrightarrow> T \<subseteq> S \<Longrightarrow> (f ---> l) (net within T)"
himmelma@33175
   951
  unfolding tendsto_def Limits.eventually_within
himmelma@33175
   952
  by (auto elim!: eventually_elim1)
himmelma@33175
   953
himmelma@33175
   954
lemma Lim_Un: assumes "(f ---> l) (net within S)" "(f ---> l) (net within T)"
himmelma@33175
   955
  shows "(f ---> l) (net within (S \<union> T))"
himmelma@33175
   956
  using assms unfolding tendsto_def Limits.eventually_within
himmelma@33175
   957
  apply clarify
himmelma@33175
   958
  apply (drule spec, drule (1) mp, drule (1) mp)
himmelma@33175
   959
  apply (drule spec, drule (1) mp, drule (1) mp)
himmelma@33175
   960
  apply (auto elim: eventually_elim2)
himmelma@33175
   961
  done
himmelma@33175
   962
himmelma@33175
   963
lemma Lim_Un_univ:
himmelma@33175
   964
 "(f ---> l) (net within S) \<Longrightarrow> (f ---> l) (net within T) \<Longrightarrow>  S \<union> T = UNIV
himmelma@33175
   965
        ==> (f ---> l) net"
himmelma@33175
   966
  by (metis Lim_Un within_UNIV)
himmelma@33175
   967
himmelma@33175
   968
text{* Interrelations between restricted and unrestricted limits. *}
himmelma@33175
   969
himmelma@33175
   970
lemma Lim_at_within: "(f ---> l) net ==> (f ---> l)(net within S)"
himmelma@33175
   971
  (* FIXME: rename *)
himmelma@33175
   972
  unfolding tendsto_def Limits.eventually_within
himmelma@33175
   973
  apply (clarify, drule spec, drule (1) mp, drule (1) mp)
himmelma@33175
   974
  by (auto elim!: eventually_elim1)
himmelma@33175
   975
huffman@44210
   976
lemma eventually_within_interior:
huffman@44210
   977
  assumes "x \<in> interior S"
huffman@44210
   978
  shows "eventually P (at x within S) \<longleftrightarrow> eventually P (at x)" (is "?lhs = ?rhs")
huffman@44210
   979
proof-
huffman@44519
   980
  from assms obtain T where T: "open T" "x \<in> T" "T \<subseteq> S" ..
huffman@44210
   981
  { assume "?lhs"
huffman@44210
   982
    then obtain A where "open A" "x \<in> A" "\<forall>y\<in>A. y \<noteq> x \<longrightarrow> y \<in> S \<longrightarrow> P y"
huffman@44210
   983
      unfolding Limits.eventually_within Limits.eventually_at_topological
huffman@44210
   984
      by auto
huffman@44210
   985
    with T have "open (A \<inter> T)" "x \<in> A \<inter> T" "\<forall>y\<in>(A \<inter> T). y \<noteq> x \<longrightarrow> P y"
huffman@44210
   986
      by auto
huffman@44210
   987
    then have "?rhs"
huffman@44210
   988
      unfolding Limits.eventually_at_topological by auto
huffman@44210
   989
  } moreover
huffman@44210
   990
  { assume "?rhs" hence "?lhs"
huffman@44210
   991
      unfolding Limits.eventually_within
huffman@44210
   992
      by (auto elim: eventually_elim1)
huffman@44210
   993
  } ultimately
huffman@44210
   994
  show "?thesis" ..
huffman@44210
   995
qed
huffman@44210
   996
huffman@44210
   997
lemma at_within_interior:
huffman@44210
   998
  "x \<in> interior S \<Longrightarrow> at x within S = at x"
huffman@44210
   999
  by (simp add: filter_eq_iff eventually_within_interior)
huffman@44210
  1000
huffman@44210
  1001
lemma at_within_open:
huffman@44210
  1002
  "\<lbrakk>x \<in> S; open S\<rbrakk> \<Longrightarrow> at x within S = at x"
huffman@44210
  1003
  by (simp only: at_within_interior interior_open)
huffman@44210
  1004
himmelma@33175
  1005
lemma Lim_within_open:
himmelma@33175
  1006
  fixes f :: "'a::topological_space \<Rightarrow> 'b::topological_space"
himmelma@33175
  1007
  assumes"a \<in> S" "open S"
huffman@44210
  1008
  shows "(f ---> l)(at a within S) \<longleftrightarrow> (f ---> l)(at a)"
huffman@44210
  1009
  using assms by (simp only: at_within_open)
himmelma@33175
  1010
hoelzl@43338
  1011
lemma Lim_within_LIMSEQ:
huffman@44584
  1012
  fixes a :: "'a::metric_space"
hoelzl@43338
  1013
  assumes "\<forall>S. (\<forall>n. S n \<noteq> a \<and> S n \<in> T) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L"
hoelzl@43338
  1014
  shows "(X ---> L) (at a within T)"
huffman@44584
  1015
  using assms unfolding tendsto_def [where l=L]
huffman@44584
  1016
  by (simp add: sequentially_imp_eventually_within)
hoelzl@43338
  1017
hoelzl@43338
  1018
lemma Lim_right_bound:
hoelzl@43338
  1019
  fixes f :: "real \<Rightarrow> real"
hoelzl@43338
  1020
  assumes mono: "\<And>a b. a \<in> I \<Longrightarrow> b \<in> I \<Longrightarrow> x < a \<Longrightarrow> a \<le> b \<Longrightarrow> f a \<le> f b"
hoelzl@43338
  1021
  assumes bnd: "\<And>a. a \<in> I \<Longrightarrow> x < a \<Longrightarrow> K \<le> f a"
hoelzl@43338
  1022
  shows "(f ---> Inf (f ` ({x<..} \<inter> I))) (at x within ({x<..} \<inter> I))"
hoelzl@43338
  1023
proof cases
hoelzl@43338
  1024
  assume "{x<..} \<inter> I = {}" then show ?thesis by (simp add: Lim_within_empty)
hoelzl@43338
  1025
next
hoelzl@43338
  1026
  assume [simp]: "{x<..} \<inter> I \<noteq> {}"
hoelzl@43338
  1027
  show ?thesis
hoelzl@43338
  1028
  proof (rule Lim_within_LIMSEQ, safe)
hoelzl@43338
  1029
    fix S assume S: "\<forall>n. S n \<noteq> x \<and> S n \<in> {x <..} \<inter> I" "S ----> x"
hoelzl@43338
  1030
    
hoelzl@43338
  1031
    show "(\<lambda>n. f (S n)) ----> Inf (f ` ({x<..} \<inter> I))"
hoelzl@43338
  1032
    proof (rule LIMSEQ_I, rule ccontr)
hoelzl@43338
  1033
      fix r :: real assume "0 < r"
hoelzl@43338
  1034
      with Inf_close[of "f ` ({x<..} \<inter> I)" r]
hoelzl@43338
  1035
      obtain y where y: "x < y" "y \<in> I" "f y < Inf (f ` ({x <..} \<inter> I)) + r" by auto
hoelzl@43338
  1036
      from `x < y` have "0 < y - x" by auto
hoelzl@43338
  1037
      from S(2)[THEN LIMSEQ_D, OF this]
hoelzl@43338
  1038
      obtain N where N: "\<And>n. N \<le> n \<Longrightarrow> \<bar>S n - x\<bar> < y - x" by auto
hoelzl@43338
  1039
      
hoelzl@43338
  1040
      assume "\<not> (\<exists>N. \<forall>n\<ge>N. norm (f (S n) - Inf (f ` ({x<..} \<inter> I))) < r)"
hoelzl@43338
  1041
      moreover have "\<And>n. Inf (f ` ({x<..} \<inter> I)) \<le> f (S n)"
hoelzl@43338
  1042
        using S bnd by (intro Inf_lower[where z=K]) auto
hoelzl@43338
  1043
      ultimately obtain n where n: "N \<le> n" "r + Inf (f ` ({x<..} \<inter> I)) \<le> f (S n)"
hoelzl@43338
  1044
        by (auto simp: not_less field_simps)
hoelzl@43338
  1045
      with N[OF n(1)] mono[OF _ `y \<in> I`, of "S n"] S(1)[THEN spec, of n] y
hoelzl@43338
  1046
      show False by auto
hoelzl@43338
  1047
    qed
hoelzl@43338
  1048
  qed
hoelzl@43338
  1049
qed
hoelzl@43338
  1050
himmelma@33175
  1051
text{* Another limit point characterization. *}
himmelma@33175
  1052
himmelma@33175
  1053
lemma islimpt_sequential:
huffman@36667
  1054
  fixes x :: "'a::metric_space"
himmelma@33175
  1055
  shows "x islimpt S \<longleftrightarrow> (\<exists>f. (\<forall>n::nat. f n \<in> S -{x}) \<and> (f ---> x) sequentially)"
himmelma@33175
  1056
    (is "?lhs = ?rhs")
himmelma@33175
  1057
proof
himmelma@33175
  1058
  assume ?lhs
himmelma@33175
  1059
  then obtain f where f:"\<forall>y. y>0 \<longrightarrow> f y \<in> S \<and> f y \<noteq> x \<and> dist (f y) x < y"
huffman@44584
  1060
    unfolding islimpt_approachable
huffman@44584
  1061
    using choice[of "\<lambda>e y. e>0 \<longrightarrow> y\<in>S \<and> y\<noteq>x \<and> dist y x < e"] by auto
huffman@44584
  1062
  let ?I = "\<lambda>n. inverse (real (Suc n))"
huffman@44584
  1063
  have "\<forall>n. f (?I n) \<in> S - {x}" using f by simp
huffman@44584
  1064
  moreover have "(\<lambda>n. f (?I n)) ----> x"
huffman@44584
  1065
  proof (rule metric_tendsto_imp_tendsto)
huffman@44584
  1066
    show "?I ----> 0"
huffman@44584
  1067
      by (rule LIMSEQ_inverse_real_of_nat)
huffman@44584
  1068
    show "eventually (\<lambda>n. dist (f (?I n)) x \<le> dist (?I n) 0) sequentially"
huffman@44584
  1069
      by (simp add: norm_conv_dist [symmetric] less_imp_le f)
huffman@44584
  1070
  qed
huffman@44584
  1071
  ultimately show ?rhs by fast
himmelma@33175
  1072
next
himmelma@33175
  1073
  assume ?rhs
huffman@44907
  1074
  then obtain f::"nat\<Rightarrow>'a"  where f:"(\<forall>n. f n \<in> S - {x})" "(\<forall>e>0. \<exists>N. \<forall>n\<ge>N. dist (f n) x < e)" unfolding LIMSEQ_def by auto
himmelma@33175
  1075
  { fix e::real assume "e>0"
himmelma@33175
  1076
    then obtain N where "dist (f N) x < e" using f(2) by auto
himmelma@33175
  1077
    moreover have "f N\<in>S" "f N \<noteq> x" using f(1) by auto
himmelma@33175
  1078
    ultimately have "\<exists>x'\<in>S. x' \<noteq> x \<and> dist x' x < e" by auto
himmelma@33175
  1079
  }
himmelma@33175
  1080
  thus ?lhs unfolding islimpt_approachable by auto
himmelma@33175
  1081
qed
himmelma@33175
  1082
huffman@44125
  1083
lemma Lim_inv: (* TODO: delete *)
huffman@44081
  1084
  fixes f :: "'a \<Rightarrow> real" and A :: "'a filter"
huffman@44081
  1085
  assumes "(f ---> l) A" and "l \<noteq> 0"
huffman@44081
  1086
  shows "((inverse o f) ---> inverse l) A"
huffman@36437
  1087
  unfolding o_def using assms by (rule tendsto_inverse)
huffman@36437
  1088
himmelma@33175
  1089
lemma Lim_null:
himmelma@33175
  1090
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
huffman@44125
  1091
  shows "(f ---> l) net \<longleftrightarrow> ((\<lambda>x. f(x) - l) ---> 0) net"
himmelma@33175
  1092
  by (simp add: Lim dist_norm)
himmelma@33175
  1093
himmelma@33175
  1094
lemma Lim_null_comparison:
himmelma@33175
  1095
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
himmelma@33175
  1096
  assumes "eventually (\<lambda>x. norm (f x) \<le> g x) net" "(g ---> 0) net"
himmelma@33175
  1097
  shows "(f ---> 0) net"
huffman@44252
  1098
proof (rule metric_tendsto_imp_tendsto)
huffman@44252
  1099
  show "(g ---> 0) net" by fact
huffman@44252
  1100
  show "eventually (\<lambda>x. dist (f x) 0 \<le> dist (g x) 0) net"
huffman@44252
  1101
    using assms(1) by (rule eventually_elim1, simp add: dist_norm)
himmelma@33175
  1102
qed
himmelma@33175
  1103
himmelma@33175
  1104
lemma Lim_transform_bound:
himmelma@33175
  1105
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
himmelma@33175
  1106
  fixes g :: "'a \<Rightarrow> 'c::real_normed_vector"
himmelma@33175
  1107
  assumes "eventually (\<lambda>n. norm(f n) <= norm(g n)) net"  "(g ---> 0) net"
himmelma@33175
  1108
  shows "(f ---> 0) net"
huffman@44252
  1109
  using assms(1) tendsto_norm_zero [OF assms(2)]
huffman@44252
  1110
  by (rule Lim_null_comparison)
himmelma@33175
  1111
himmelma@33175
  1112
text{* Deducing things about the limit from the elements. *}
himmelma@33175
  1113
himmelma@33175
  1114
lemma Lim_in_closed_set:
himmelma@33175
  1115
  assumes "closed S" "eventually (\<lambda>x. f(x) \<in> S) net" "\<not>(trivial_limit net)" "(f ---> l) net"
himmelma@33175
  1116
  shows "l \<in> S"
himmelma@33175
  1117
proof (rule ccontr)
himmelma@33175
  1118
  assume "l \<notin> S"
himmelma@33175
  1119
  with `closed S` have "open (- S)" "l \<in> - S"
himmelma@33175
  1120
    by (simp_all add: open_Compl)
himmelma@33175
  1121
  with assms(4) have "eventually (\<lambda>x. f x \<in> - S) net"
himmelma@33175
  1122
    by (rule topological_tendstoD)
himmelma@33175
  1123
  with assms(2) have "eventually (\<lambda>x. False) net"
himmelma@33175
  1124
    by (rule eventually_elim2) simp
himmelma@33175
  1125
  with assms(3) show "False"
himmelma@33175
  1126
    by (simp add: eventually_False)
himmelma@33175
  1127
qed
himmelma@33175
  1128
himmelma@33175
  1129
text{* Need to prove closed(cball(x,e)) before deducing this as a corollary. *}
himmelma@33175
  1130
himmelma@33175
  1131
lemma Lim_dist_ubound:
himmelma@33175
  1132
  assumes "\<not>(trivial_limit net)" "(f ---> l) net" "eventually (\<lambda>x. dist a (f x) <= e) net"
himmelma@33175
  1133
  shows "dist a l <= e"
huffman@44252
  1134
proof-
huffman@44252
  1135
  have "dist a l \<in> {..e}"
huffman@44252
  1136
  proof (rule Lim_in_closed_set)
huffman@44252
  1137
    show "closed {..e}" by simp
huffman@44252
  1138
    show "eventually (\<lambda>x. dist a (f x) \<in> {..e}) net" by (simp add: assms)
huffman@44252
  1139
    show "\<not> trivial_limit net" by fact
huffman@44252
  1140
    show "((\<lambda>x. dist a (f x)) ---> dist a l) net" by (intro tendsto_intros assms)
huffman@44252
  1141
  qed
huffman@44252
  1142
  thus ?thesis by simp
himmelma@33175
  1143
qed
himmelma@33175
  1144
himmelma@33175
  1145
lemma Lim_norm_ubound:
himmelma@33175
  1146
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
himmelma@33175
  1147
  assumes "\<not>(trivial_limit net)" "(f ---> l) net" "eventually (\<lambda>x. norm(f x) <= e) net"
himmelma@33175
  1148
  shows "norm(l) <= e"
huffman@44252
  1149
proof-
huffman@44252
  1150
  have "norm l \<in> {..e}"
huffman@44252
  1151
  proof (rule Lim_in_closed_set)
huffman@44252
  1152
    show "closed {..e}" by simp
huffman@44252
  1153
    show "eventually (\<lambda>x. norm (f x) \<in> {..e}) net" by (simp add: assms)
huffman@44252
  1154
    show "\<not> trivial_limit net" by fact
huffman@44252
  1155
    show "((\<lambda>x. norm (f x)) ---> norm l) net" by (intro tendsto_intros assms)
huffman@44252
  1156
  qed
huffman@44252
  1157
  thus ?thesis by simp
himmelma@33175
  1158
qed
himmelma@33175
  1159
himmelma@33175
  1160
lemma Lim_norm_lbound:
himmelma@33175
  1161
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
himmelma@33175
  1162
  assumes "\<not> (trivial_limit net)"  "(f ---> l) net"  "eventually (\<lambda>x. e <= norm(f x)) net"
himmelma@33175
  1163
  shows "e \<le> norm l"
huffman@44252
  1164
proof-
huffman@44252
  1165
  have "norm l \<in> {e..}"
huffman@44252
  1166
  proof (rule Lim_in_closed_set)
huffman@44252
  1167
    show "closed {e..}" by simp
huffman@44252
  1168
    show "eventually (\<lambda>x. norm (f x) \<in> {e..}) net" by (simp add: assms)
huffman@44252
  1169
    show "\<not> trivial_limit net" by fact
huffman@44252
  1170
    show "((\<lambda>x. norm (f x)) ---> norm l) net" by (intro tendsto_intros assms)
huffman@44252
  1171
  qed
huffman@44252
  1172
  thus ?thesis by simp
himmelma@33175
  1173
qed
himmelma@33175
  1174
himmelma@33175
  1175
text{* Uniqueness of the limit, when nontrivial. *}
himmelma@33175
  1176
himmelma@33175
  1177
lemma tendsto_Lim:
himmelma@33175
  1178
  fixes f :: "'a \<Rightarrow> 'b::t2_space"
himmelma@33175
  1179
  shows "~(trivial_limit net) \<Longrightarrow> (f ---> l) net ==> Lim net f = l"
hoelzl@41970
  1180
  unfolding Lim_def using tendsto_unique[of net f] by auto
himmelma@33175
  1181
himmelma@33175
  1182
text{* Limit under bilinear function *}
himmelma@33175
  1183
himmelma@33175
  1184
lemma Lim_bilinear:
himmelma@33175
  1185
  assumes "(f ---> l) net" and "(g ---> m) net" and "bounded_bilinear h"
himmelma@33175
  1186
  shows "((\<lambda>x. h (f x) (g x)) ---> (h l m)) net"
himmelma@33175
  1187
using `bounded_bilinear h` `(f ---> l) net` `(g ---> m) net`
himmelma@33175
  1188
by (rule bounded_bilinear.tendsto)
himmelma@33175
  1189
himmelma@33175
  1190
text{* These are special for limits out of the same vector space. *}
himmelma@33175
  1191
himmelma@33175
  1192
lemma Lim_within_id: "(id ---> a) (at a within s)"
huffman@45031
  1193
  unfolding id_def by (rule tendsto_ident_at_within)
himmelma@33175
  1194
himmelma@33175
  1195
lemma Lim_at_id: "(id ---> a) (at a)"
huffman@45031
  1196
  unfolding id_def by (rule tendsto_ident_at)
himmelma@33175
  1197
himmelma@33175
  1198
lemma Lim_at_zero:
himmelma@33175
  1199
  fixes a :: "'a::real_normed_vector"
himmelma@33175
  1200
  fixes l :: "'b::topological_space"
himmelma@33175
  1201
  shows "(f ---> l) (at a) \<longleftrightarrow> ((\<lambda>x. f(a + x)) ---> l) (at 0)" (is "?lhs = ?rhs")
huffman@44252
  1202
  using LIM_offset_zero LIM_offset_zero_cancel ..
himmelma@33175
  1203
huffman@44081
  1204
text{* It's also sometimes useful to extract the limit point from the filter. *}
himmelma@33175
  1205
himmelma@33175
  1206
definition
huffman@44081
  1207
  netlimit :: "'a::t2_space filter \<Rightarrow> 'a" where
himmelma@33175
  1208
  "netlimit net = (SOME a. ((\<lambda>x. x) ---> a) net)"
himmelma@33175
  1209
himmelma@33175
  1210
lemma netlimit_within:
himmelma@33175
  1211
  assumes "\<not> trivial_limit (at a within S)"
himmelma@33175
  1212
  shows "netlimit (at a within S) = a"
himmelma@33175
  1213
unfolding netlimit_def
himmelma@33175
  1214
apply (rule some_equality)
himmelma@33175
  1215
apply (rule Lim_at_within)
huffman@44568
  1216
apply (rule tendsto_ident_at)
hoelzl@41970
  1217
apply (erule tendsto_unique [OF assms])
himmelma@33175
  1218
apply (rule Lim_at_within)
huffman@44568
  1219
apply (rule tendsto_ident_at)
himmelma@33175
  1220
done
himmelma@33175
  1221
himmelma@33175
  1222
lemma netlimit_at:
huffman@44072
  1223
  fixes a :: "'a::{perfect_space,t2_space}"
himmelma@33175
  1224
  shows "netlimit (at a) = a"
huffman@45031
  1225
  using netlimit_within [of a UNIV] by simp
himmelma@33175
  1226
huffman@44210
  1227
lemma lim_within_interior:
huffman@44210
  1228
  "x \<in> interior S \<Longrightarrow> (f ---> l) (at x within S) \<longleftrightarrow> (f ---> l) (at x)"
huffman@44210
  1229
  by (simp add: at_within_interior)
huffman@44210
  1230
huffman@44210
  1231
lemma netlimit_within_interior:
huffman@44210
  1232
  fixes x :: "'a::{t2_space,perfect_space}"
huffman@44210
  1233
  assumes "x \<in> interior S"
huffman@44210
  1234
  shows "netlimit (at x within S) = x"
huffman@44210
  1235
using assms by (simp add: at_within_interior netlimit_at)
huffman@44210
  1236
himmelma@33175
  1237
text{* Transformation of limit. *}
himmelma@33175
  1238
himmelma@33175
  1239
lemma Lim_transform:
himmelma@33175
  1240
  fixes f g :: "'a::type \<Rightarrow> 'b::real_normed_vector"
himmelma@33175
  1241
  assumes "((\<lambda>x. f x - g x) ---> 0) net" "(f ---> l) net"
himmelma@33175
  1242
  shows "(g ---> l) net"
huffman@44252
  1243
  using tendsto_diff [OF assms(2) assms(1)] by simp
himmelma@33175
  1244
himmelma@33175
  1245
lemma Lim_transform_eventually:
huffman@36667
  1246
  "eventually (\<lambda>x. f x = g x) net \<Longrightarrow> (f ---> l) net \<Longrightarrow> (g ---> l) net"
himmelma@33175
  1247
  apply (rule topological_tendstoI)
himmelma@33175
  1248
  apply (drule (2) topological_tendstoD)
himmelma@33175
  1249
  apply (erule (1) eventually_elim2, simp)
himmelma@33175
  1250
  done
himmelma@33175
  1251
himmelma@33175
  1252
lemma Lim_transform_within:
huffman@36667
  1253
  assumes "0 < d" and "\<forall>x'\<in>S. 0 < dist x' x \<and> dist x' x < d \<longrightarrow> f x' = g x'"
huffman@36667
  1254
  and "(f ---> l) (at x within S)"
huffman@36667
  1255
  shows "(g ---> l) (at x within S)"
huffman@36667
  1256
proof (rule Lim_transform_eventually)
huffman@36667
  1257
  show "eventually (\<lambda>x. f x = g x) (at x within S)"
huffman@36667
  1258
    unfolding eventually_within
huffman@36667
  1259
    using assms(1,2) by auto
huffman@36667
  1260
  show "(f ---> l) (at x within S)" by fact
huffman@36667
  1261
qed
himmelma@33175
  1262
himmelma@33175
  1263
lemma Lim_transform_at:
huffman@36667
  1264
  assumes "0 < d" and "\<forall>x'. 0 < dist x' x \<and> dist x' x < d \<longrightarrow> f x' = g x'"
huffman@36667
  1265
  and "(f ---> l) (at x)"
huffman@36667
  1266
  shows "(g ---> l) (at x)"
huffman@36667
  1267
proof (rule Lim_transform_eventually)
huffman@36667
  1268
  show "eventually (\<lambda>x. f x = g x) (at x)"
huffman@36667
  1269
    unfolding eventually_at
huffman@36667
  1270
    using assms(1,2) by auto
huffman@36667
  1271
  show "(f ---> l) (at x)" by fact
huffman@36667
  1272
qed
himmelma@33175
  1273
himmelma@33175
  1274
text{* Common case assuming being away from some crucial point like 0. *}
himmelma@33175
  1275
himmelma@33175
  1276
lemma Lim_transform_away_within:
huffman@36669
  1277
  fixes a b :: "'a::t1_space"
huffman@36667
  1278
  assumes "a \<noteq> b" and "\<forall>x\<in>S. x \<noteq> a \<and> x \<noteq> b \<longrightarrow> f x = g x"
himmelma@33175
  1279
  and "(f ---> l) (at a within S)"
himmelma@33175
  1280
  shows "(g ---> l) (at a within S)"
huffman@36669
  1281
proof (rule Lim_transform_eventually)
huffman@36669
  1282
  show "(f ---> l) (at a within S)" by fact
huffman@36669
  1283
  show "eventually (\<lambda>x. f x = g x) (at a within S)"
huffman@36669
  1284
    unfolding Limits.eventually_within eventually_at_topological
huffman@36669
  1285
    by (rule exI [where x="- {b}"], simp add: open_Compl assms)
himmelma@33175
  1286
qed
himmelma@33175
  1287
himmelma@33175
  1288
lemma Lim_transform_away_at:
huffman@36669
  1289
  fixes a b :: "'a::t1_space"
himmelma@33175
  1290
  assumes ab: "a\<noteq>b" and fg: "\<forall>x. x \<noteq> a \<and> x \<noteq> b \<longrightarrow> f x = g x"
himmelma@33175
  1291
  and fl: "(f ---> l) (at a)"
himmelma@33175
  1292
  shows "(g ---> l) (at a)"
himmelma@33175
  1293
  using Lim_transform_away_within[OF ab, of UNIV f g l] fg fl
huffman@45031
  1294
  by simp
himmelma@33175
  1295
himmelma@33175
  1296
text{* Alternatively, within an open set. *}
himmelma@33175
  1297
himmelma@33175
  1298
lemma Lim_transform_within_open:
huffman@36667
  1299
  assumes "open S" and "a \<in> S" and "\<forall>x\<in>S. x \<noteq> a \<longrightarrow> f x = g x"
huffman@36667
  1300
  and "(f ---> l) (at a)"
himmelma@33175
  1301
  shows "(g ---> l) (at a)"
huffman@36667
  1302
proof (rule Lim_transform_eventually)
huffman@36667
  1303
  show "eventually (\<lambda>x. f x = g x) (at a)"
huffman@36667
  1304
    unfolding eventually_at_topological
huffman@36667
  1305
    using assms(1,2,3) by auto
huffman@36667
  1306
  show "(f ---> l) (at a)" by fact
himmelma@33175
  1307
qed
himmelma@33175
  1308
himmelma@33175
  1309
text{* A congruence rule allowing us to transform limits assuming not at point. *}
himmelma@33175
  1310
himmelma@33175
  1311
(* FIXME: Only one congruence rule for tendsto can be used at a time! *)
himmelma@33175
  1312
huffman@36362
  1313
lemma Lim_cong_within(*[cong add]*):
hoelzl@43338
  1314
  assumes "a = b" "x = y" "S = T"
hoelzl@43338
  1315
  assumes "\<And>x. x \<noteq> b \<Longrightarrow> x \<in> T \<Longrightarrow> f x = g x"
hoelzl@43338
  1316
  shows "(f ---> x) (at a within S) \<longleftrightarrow> (g ---> y) (at b within T)"
huffman@36667
  1317
  unfolding tendsto_def Limits.eventually_within eventually_at_topological
huffman@36667
  1318
  using assms by simp
huffman@36667
  1319
huffman@36667
  1320
lemma Lim_cong_at(*[cong add]*):
hoelzl@43338
  1321
  assumes "a = b" "x = y"
huffman@36667
  1322
  assumes "\<And>x. x \<noteq> a \<Longrightarrow> f x = g x"
hoelzl@43338
  1323
  shows "((\<lambda>x. f x) ---> x) (at a) \<longleftrightarrow> ((g ---> y) (at a))"
huffman@36667
  1324
  unfolding tendsto_def eventually_at_topological
huffman@36667
  1325
  using assms by simp
himmelma@33175
  1326
himmelma@33175
  1327
text{* Useful lemmas on closure and set of possible sequential limits.*}
himmelma@33175
  1328
himmelma@33175
  1329
lemma closure_sequential:
huffman@36667
  1330
  fixes l :: "'a::metric_space"
himmelma@33175
  1331
  shows "l \<in> closure S \<longleftrightarrow> (\<exists>x. (\<forall>n. x n \<in> S) \<and> (x ---> l) sequentially)" (is "?lhs = ?rhs")
himmelma@33175
  1332
proof
himmelma@33175
  1333
  assume "?lhs" moreover
himmelma@33175
  1334
  { assume "l \<in> S"
huffman@44125
  1335
    hence "?rhs" using tendsto_const[of l sequentially] by auto
himmelma@33175
  1336
  } moreover
himmelma@33175
  1337
  { assume "l islimpt S"
himmelma@33175
  1338
    hence "?rhs" unfolding islimpt_sequential by auto
himmelma@33175
  1339
  } ultimately
himmelma@33175
  1340
  show "?rhs" unfolding closure_def by auto
himmelma@33175
  1341
next
himmelma@33175
  1342
  assume "?rhs"
himmelma@33175
  1343
  thus "?lhs" unfolding closure_def unfolding islimpt_sequential by auto
himmelma@33175
  1344
qed
himmelma@33175
  1345
himmelma@33175
  1346
lemma closed_sequential_limits:
himmelma@33175
  1347
  fixes S :: "'a::metric_space set"
himmelma@33175
  1348
  shows "closed S \<longleftrightarrow> (\<forall>x l. (\<forall>n. x n \<in> S) \<and> (x ---> l) sequentially \<longrightarrow> l \<in> S)"
himmelma@33175
  1349
  unfolding closed_limpt
himmelma@33175
  1350
  using closure_sequential [where 'a='a] closure_closed [where 'a='a] closed_limpt [where 'a='a] islimpt_sequential [where 'a='a] mem_delete [where 'a='a]
himmelma@33175
  1351
  by metis
himmelma@33175
  1352
himmelma@33175
  1353
lemma closure_approachable:
himmelma@33175
  1354
  fixes S :: "'a::metric_space set"
himmelma@33175
  1355
  shows "x \<in> closure S \<longleftrightarrow> (\<forall>e>0. \<exists>y\<in>S. dist y x < e)"
himmelma@33175
  1356
  apply (auto simp add: closure_def islimpt_approachable)
himmelma@33175
  1357
  by (metis dist_self)
himmelma@33175
  1358
himmelma@33175
  1359
lemma closed_approachable:
himmelma@33175
  1360
  fixes S :: "'a::metric_space set"
himmelma@33175
  1361
  shows "closed S ==> (\<forall>e>0. \<exists>y\<in>S. dist y x < e) \<longleftrightarrow> x \<in> S"
himmelma@33175
  1362
  by (metis closure_closed closure_approachable)
himmelma@33175
  1363
himmelma@33175
  1364
text{* Some other lemmas about sequences. *}
himmelma@33175
  1365
huffman@36441
  1366
lemma sequentially_offset:
huffman@36441
  1367
  assumes "eventually (\<lambda>i. P i) sequentially"
huffman@36441
  1368
  shows "eventually (\<lambda>i. P (i + k)) sequentially"
huffman@36441
  1369
  using assms unfolding eventually_sequentially by (metis trans_le_add1)
huffman@36441
  1370
himmelma@33175
  1371
lemma seq_offset:
huffman@36441
  1372
  assumes "(f ---> l) sequentially"
huffman@36441
  1373
  shows "((\<lambda>i. f (i + k)) ---> l) sequentially"
huffman@44584
  1374
  using assms by (rule LIMSEQ_ignore_initial_segment) (* FIXME: redundant *)
himmelma@33175
  1375
himmelma@33175
  1376
lemma seq_offset_neg:
himmelma@33175
  1377
  "(f ---> l) sequentially ==> ((\<lambda>i. f(i - k)) ---> l) sequentially"
himmelma@33175
  1378
  apply (rule topological_tendstoI)
himmelma@33175
  1379
  apply (drule (2) topological_tendstoD)
himmelma@33175
  1380
  apply (simp only: eventually_sequentially)
himmelma@33175
  1381
  apply (subgoal_tac "\<And>N k (n::nat). N + k <= n ==> N <= n - k")
himmelma@33175
  1382
  apply metis
himmelma@33175
  1383
  by arith
himmelma@33175
  1384
himmelma@33175
  1385
lemma seq_offset_rev:
himmelma@33175
  1386
  "((\<lambda>i. f(i + k)) ---> l) sequentially ==> (f ---> l) sequentially"
huffman@44584
  1387
  by (rule LIMSEQ_offset) (* FIXME: redundant *)
himmelma@33175
  1388
himmelma@33175
  1389
lemma seq_harmonic: "((\<lambda>n. inverse (real n)) ---> 0) sequentially"
huffman@44584
  1390
  using LIMSEQ_inverse_real_of_nat by (rule LIMSEQ_imp_Suc)
himmelma@33175
  1391
huffman@44210
  1392
subsection {* More properties of closed balls *}
himmelma@33175
  1393
himmelma@33175
  1394
lemma closed_cball: "closed (cball x e)"
himmelma@33175
  1395
unfolding cball_def closed_def
himmelma@33175
  1396
unfolding Collect_neg_eq [symmetric] not_le
himmelma@33175
  1397
apply (clarsimp simp add: open_dist, rename_tac y)
himmelma@33175
  1398
apply (rule_tac x="dist x y - e" in exI, clarsimp)
himmelma@33175
  1399
apply (rename_tac x')
himmelma@33175
  1400
apply (cut_tac x=x and y=x' and z=y in dist_triangle)
himmelma@33175
  1401
apply simp
himmelma@33175
  1402
done
himmelma@33175
  1403
himmelma@33175
  1404
lemma open_contains_cball: "open S \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0.  cball x e \<subseteq> S)"
himmelma@33175
  1405
proof-
himmelma@33175
  1406
  { fix x and e::real assume "x\<in>S" "e>0" "ball x e \<subseteq> S"
himmelma@33175
  1407
    hence "\<exists>d>0. cball x d \<subseteq> S" unfolding subset_eq by (rule_tac x="e/2" in exI, auto)
himmelma@33175
  1408
  } moreover
himmelma@33175
  1409
  { fix x and e::real assume "x\<in>S" "e>0" "cball x e \<subseteq> S"
himmelma@33175
  1410
    hence "\<exists>d>0. ball x d \<subseteq> S" unfolding subset_eq apply(rule_tac x="e/2" in exI) by auto
himmelma@33175
  1411
  } ultimately
himmelma@33175
  1412
  show ?thesis unfolding open_contains_ball by auto
himmelma@33175
  1413
qed
himmelma@33175
  1414
himmelma@33175
  1415
lemma open_contains_cball_eq: "open S ==> (\<forall>x. x \<in> S \<longleftrightarrow> (\<exists>e>0. cball x e \<subseteq> S))"
huffman@44170
  1416
  by (metis open_contains_cball subset_eq order_less_imp_le centre_in_cball)
himmelma@33175
  1417
himmelma@33175
  1418
lemma mem_interior_cball: "x \<in> interior S \<longleftrightarrow> (\<exists>e>0. cball x e \<subseteq> S)"
himmelma@33175
  1419
  apply (simp add: interior_def, safe)
himmelma@33175
  1420
  apply (force simp add: open_contains_cball)
himmelma@33175
  1421
  apply (rule_tac x="ball x e" in exI)
huffman@36362
  1422
  apply (simp add: subset_trans [OF ball_subset_cball])
himmelma@33175
  1423
  done
himmelma@33175
  1424
himmelma@33175
  1425
lemma islimpt_ball:
himmelma@33175
  1426
  fixes x y :: "'a::{real_normed_vector,perfect_space}"
himmelma@33175
  1427
  shows "y islimpt ball x e \<longleftrightarrow> 0 < e \<and> y \<in> cball x e" (is "?lhs = ?rhs")
himmelma@33175
  1428
proof
himmelma@33175
  1429
  assume "?lhs"
himmelma@33175
  1430
  { assume "e \<le> 0"
himmelma@33175
  1431
    hence *:"ball x e = {}" using ball_eq_empty[of x e] by auto
himmelma@33175
  1432
    have False using `?lhs` unfolding * using islimpt_EMPTY[of y] by auto
himmelma@33175
  1433
  }
himmelma@33175
  1434
  hence "e > 0" by (metis not_less)
himmelma@33175
  1435
  moreover
himmelma@33175
  1436
  have "y \<in> cball x e" using closed_cball[of x e] islimpt_subset[of y "ball x e" "cball x e"] ball_subset_cball[of x e] `?lhs` unfolding closed_limpt by auto
himmelma@33175
  1437
  ultimately show "?rhs" by auto
himmelma@33175
  1438
next
himmelma@33175
  1439
  assume "?rhs" hence "e>0"  by auto
himmelma@33175
  1440
  { fix d::real assume "d>0"
himmelma@33175
  1441
    have "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
himmelma@33175
  1442
    proof(cases "d \<le> dist x y")
himmelma@33175
  1443
      case True thus "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
himmelma@33175
  1444
      proof(cases "x=y")
himmelma@33175
  1445
        case True hence False using `d \<le> dist x y` `d>0` by auto
himmelma@33175
  1446
        thus "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d" by auto
himmelma@33175
  1447
      next
himmelma@33175
  1448
        case False
himmelma@33175
  1449
himmelma@33175
  1450
        have "dist x (y - (d / (2 * dist y x)) *\<^sub>R (y - x))
himmelma@33175
  1451
              = norm (x - y + (d / (2 * norm (y - x))) *\<^sub>R (y - x))"
himmelma@33175
  1452
          unfolding mem_cball mem_ball dist_norm diff_diff_eq2 diff_add_eq[THEN sym] by auto
himmelma@33175
  1453
        also have "\<dots> = \<bar>- 1 + d / (2 * norm (x - y))\<bar> * norm (x - y)"
himmelma@33175
  1454
          using scaleR_left_distrib[of "- 1" "d / (2 * norm (y - x))", THEN sym, of "y - x"]
himmelma@33175
  1455
          unfolding scaleR_minus_left scaleR_one
himmelma@33175
  1456
          by (auto simp add: norm_minus_commute)
himmelma@33175
  1457
        also have "\<dots> = \<bar>- norm (x - y) + d / 2\<bar>"
himmelma@33175
  1458
          unfolding abs_mult_pos[of "norm (x - y)", OF norm_ge_zero[of "x - y"]]
huffman@36778
  1459
          unfolding left_distrib using `x\<noteq>y`[unfolded dist_nz, unfolded dist_norm] by auto
himmelma@33175
  1460
        also have "\<dots> \<le> e - d/2" using `d \<le> dist x y` and `d>0` and `?rhs` by(auto simp add: dist_norm)
himmelma@33175
  1461
        finally have "y - (d / (2 * dist y x)) *\<^sub>R (y - x) \<in> ball x e" using `d>0` by auto
himmelma@33175
  1462
himmelma@33175
  1463
        moreover
himmelma@33175
  1464
himmelma@33175
  1465
        have "(d / (2*dist y x)) *\<^sub>R (y - x) \<noteq> 0"
himmelma@33175
  1466
          using `x\<noteq>y`[unfolded dist_nz] `d>0` unfolding scaleR_eq_0_iff by (auto simp add: dist_commute)
himmelma@33175
  1467
        moreover
himmelma@33175
  1468
        have "dist (y - (d / (2 * dist y x)) *\<^sub>R (y - x)) y < d" unfolding dist_norm apply simp unfolding norm_minus_cancel
himmelma@33175
  1469
          using `d>0` `x\<noteq>y`[unfolded dist_nz] dist_commute[of x y]
himmelma@33175
  1470
          unfolding dist_norm by auto
himmelma@33175
  1471
        ultimately show "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d" by (rule_tac  x="y - (d / (2*dist y x)) *\<^sub>R (y - x)" in bexI) auto
himmelma@33175
  1472
      qed
himmelma@33175
  1473
    next
himmelma@33175
  1474
      case False hence "d > dist x y" by auto
himmelma@33175
  1475
      show "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
himmelma@33175
  1476
      proof(cases "x=y")
himmelma@33175
  1477
        case True
himmelma@33175
  1478
        obtain z where **: "z \<noteq> y" "dist z y < min e d"
himmelma@33175
  1479
          using perfect_choose_dist[of "min e d" y]
himmelma@33175
  1480
          using `d > 0` `e>0` by auto
himmelma@33175
  1481
        show "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
himmelma@33175
  1482
          unfolding `x = y`
himmelma@33175
  1483
          using `z \<noteq> y` **
himmelma@33175
  1484
          by (rule_tac x=z in bexI, auto simp add: dist_commute)
himmelma@33175
  1485
      next
himmelma@33175
  1486
        case False thus "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
himmelma@33175
  1487
          using `d>0` `d > dist x y` `?rhs` by(rule_tac x=x in bexI, auto)
himmelma@33175
  1488
      qed
himmelma@33175
  1489
    qed  }
himmelma@33175
  1490
  thus "?lhs" unfolding mem_cball islimpt_approachable mem_ball by auto
himmelma@33175
  1491
qed
himmelma@33175
  1492
himmelma@33175
  1493
lemma closure_ball_lemma:
himmelma@33175
  1494
  fixes x y :: "'a::real_normed_vector"
himmelma@33175
  1495
  assumes "x \<noteq> y" shows "y islimpt ball x (dist x y)"
himmelma@33175
  1496
proof (rule islimptI)
himmelma@33175
  1497
  fix T assume "y \<in> T" "open T"
himmelma@33175
  1498
  then obtain r where "0 < r" "\<forall>z. dist z y < r \<longrightarrow> z \<in> T"
himmelma@33175
  1499
    unfolding open_dist by fast
himmelma@33175
  1500
  (* choose point between x and y, within distance r of y. *)
himmelma@33175
  1501
  def k \<equiv> "min 1 (r / (2 * dist x y))"
himmelma@33175
  1502
  def z \<equiv> "y + scaleR k (x - y)"
himmelma@33175
  1503
  have z_def2: "z = x + scaleR (1 - k) (y - x)"
himmelma@33175
  1504
    unfolding z_def by (simp add: algebra_simps)
himmelma@33175
  1505
  have "dist z y < r"
himmelma@33175
  1506
    unfolding z_def k_def using `0 < r`
himmelma@33175
  1507
    by (simp add: dist_norm min_def)
himmelma@33175
  1508
  hence "z \<in> T" using `\<forall>z. dist z y < r \<longrightarrow> z \<in> T` by simp
himmelma@33175
  1509
  have "dist x z < dist x y"
himmelma@33175
  1510
    unfolding z_def2 dist_norm
himmelma@33175
  1511
    apply (simp add: norm_minus_commute)
himmelma@33175
  1512
    apply (simp only: dist_norm [symmetric])
himmelma@33175
  1513
    apply (subgoal_tac "\<bar>1 - k\<bar> * dist x y < 1 * dist x y", simp)
himmelma@33175
  1514
    apply (rule mult_strict_right_mono)
himmelma@33175
  1515
    apply (simp add: k_def divide_pos_pos zero_less_dist_iff `0 < r` `x \<noteq> y`)
himmelma@33175
  1516
    apply (simp add: zero_less_dist_iff `x \<noteq> y`)
himmelma@33175
  1517
    done
himmelma@33175
  1518
  hence "z \<in> ball x (dist x y)" by simp
himmelma@33175
  1519
  have "z \<noteq> y"
himmelma@33175
  1520
    unfolding z_def k_def using `x \<noteq> y` `0 < r`
himmelma@33175
  1521
    by (simp add: min_def)
himmelma@33175
  1522
  show "\<exists>z\<in>ball x (dist x y). z \<in> T \<and> z \<noteq> y"
himmelma@33175
  1523
    using `z \<in> ball x (dist x y)` `z \<in> T` `z \<noteq> y`
himmelma@33175
  1524
    by fast
himmelma@33175
  1525
qed
himmelma@33175
  1526
himmelma@33175
  1527
lemma closure_ball:
himmelma@33175
  1528
  fixes x :: "'a::real_normed_vector"
himmelma@33175
  1529
  shows "0 < e \<Longrightarrow> closure (ball x e) = cball x e"
himmelma@33175
  1530
apply (rule equalityI)
himmelma@33175
  1531
apply (rule closure_minimal)
himmelma@33175
  1532
apply (rule ball_subset_cball)
himmelma@33175
  1533
apply (rule closed_cball)
himmelma@33175
  1534
apply (rule subsetI, rename_tac y)
himmelma@33175
  1535
apply (simp add: le_less [where 'a=real])
himmelma@33175
  1536
apply (erule disjE)
himmelma@33175
  1537
apply (rule subsetD [OF closure_subset], simp)
himmelma@33175
  1538
apply (simp add: closure_def)
himmelma@33175
  1539
apply clarify
himmelma@33175
  1540
apply (rule closure_ball_lemma)
himmelma@33175
  1541
apply (simp add: zero_less_dist_iff)
himmelma@33175
  1542
done
himmelma@33175
  1543
himmelma@33175
  1544
(* In a trivial vector space, this fails for e = 0. *)
himmelma@33175
  1545
lemma interior_cball:
himmelma@33175
  1546
  fixes x :: "'a::{real_normed_vector, perfect_space}"
himmelma@33175
  1547
  shows "interior (cball x e) = ball x e"
himmelma@33175
  1548
proof(cases "e\<ge>0")
himmelma@33175
  1549
  case False note cs = this
himmelma@33175
  1550
  from cs have "ball x e = {}" using ball_empty[of e x] by auto moreover
himmelma@33175
  1551
  { fix y assume "y \<in> cball x e"
himmelma@33175
  1552
    hence False unfolding mem_cball using dist_nz[of x y] cs by auto  }
himmelma@33175
  1553
  hence "cball x e = {}" by auto
himmelma@33175
  1554
  hence "interior (cball x e) = {}" using interior_empty by auto
himmelma@33175
  1555
  ultimately show ?thesis by blast
himmelma@33175
  1556
next
himmelma@33175
  1557
  case True note cs = this
himmelma@33175
  1558
  have "ball x e \<subseteq> cball x e" using ball_subset_cball by auto moreover
himmelma@33175
  1559
  { fix S y assume as: "S \<subseteq> cball x e" "open S" "y\<in>S"
himmelma@33175
  1560
    then obtain d where "d>0" and d:"\<forall>x'. dist x' y < d \<longrightarrow> x' \<in> S" unfolding open_dist by blast
himmelma@33175
  1561
himmelma@33175
  1562
    then obtain xa where xa_y: "xa \<noteq> y" and xa: "dist xa y < d"
himmelma@33175
  1563
      using perfect_choose_dist [of d] by auto
himmelma@33175
  1564
    have "xa\<in>S" using d[THEN spec[where x=xa]] using xa by(auto simp add: dist_commute)
himmelma@33175
  1565
    hence xa_cball:"xa \<in> cball x e" using as(1) by auto
himmelma@33175
  1566
himmelma@33175
  1567
    hence "y \<in> ball x e" proof(cases "x = y")
himmelma@33175
  1568
      case True
himmelma@33175
  1569
      hence "e>0" using xa_y[unfolded dist_nz] xa_cball[unfolded mem_cball] by (auto simp add: dist_commute)
himmelma@33175
  1570
      thus "y \<in> ball x e" using `x = y ` by simp
himmelma@33175
  1571
    next
himmelma@33175
  1572
      case False
himmelma@33175
  1573
      have "dist (y + (d / 2 / dist y x) *\<^sub>R (y - x)) y < d" unfolding dist_norm
himmelma@33175
  1574
        using `d>0` norm_ge_zero[of "y - x"] `x \<noteq> y` by auto
himmelma@33175
  1575
      hence *:"y + (d / 2 / dist y x) *\<^sub>R (y - x) \<in> cball x e" using d as(1)[unfolded subset_eq] by blast
himmelma@33175
  1576
      have "y - x \<noteq> 0" using `x \<noteq> y` by auto
himmelma@33175
  1577
      hence **:"d / (2 * norm (y - x)) > 0" unfolding zero_less_norm_iff[THEN sym]
himmelma@33175
  1578
        using `d>0` divide_pos_pos[of d "2*norm (y - x)"] by auto
himmelma@33175
  1579
himmelma@33175
  1580
      have "dist (y + (d / 2 / dist y x) *\<^sub>R (y - x)) x = norm (y + (d / (2 * norm (y - x))) *\<^sub>R y - (d / (2 * norm (y - x))) *\<^sub>R x - x)"
himmelma@33175
  1581
        by (auto simp add: dist_norm algebra_simps)
himmelma@33175
  1582
      also have "\<dots> = norm ((1 + d / (2 * norm (y - x))) *\<^sub>R (y - x))"
himmelma@33175
  1583
        by (auto simp add: algebra_simps)
himmelma@33175
  1584
      also have "\<dots> = \<bar>1 + d / (2 * norm (y - x))\<bar> * norm (y - x)"
himmelma@33175
  1585
        using ** by auto
himmelma@33175
  1586
      also have "\<dots> = (dist y x) + d/2"using ** by (auto simp add: left_distrib dist_norm)
himmelma@33175
  1587
      finally have "e \<ge> dist x y +d/2" using *[unfolded mem_cball] by (auto simp add: dist_commute)
himmelma@33175
  1588
      thus "y \<in> ball x e" unfolding mem_ball using `d>0` by auto
himmelma@33175
  1589
    qed  }
himmelma@33175
  1590
  hence "\<forall>S \<subseteq> cball x e. open S \<longrightarrow> S \<subseteq> ball x e" by auto
himmelma@33175
  1591
  ultimately show ?thesis using interior_unique[of "ball x e" "cball x e"] using open_ball[of x e] by auto
himmelma@33175
  1592
qed
himmelma@33175
  1593
himmelma@33175
  1594
lemma frontier_ball:
himmelma@33175
  1595
  fixes a :: "'a::real_normed_vector"
himmelma@33175
  1596
  shows "0 < e ==> frontier(ball a e) = {x. dist a x = e}"
huffman@36362
  1597
  apply (simp add: frontier_def closure_ball interior_open order_less_imp_le)
nipkow@39302
  1598
  apply (simp add: set_eq_iff)
himmelma@33175
  1599
  by arith
himmelma@33175
  1600
himmelma@33175
  1601
lemma frontier_cball:
himmelma@33175
  1602
  fixes a :: "'a::{real_normed_vector, perfect_space}"
himmelma@33175
  1603
  shows "frontier(cball a e) = {x. dist a x = e}"
huffman@36362
  1604
  apply (simp add: frontier_def interior_cball closed_cball order_less_imp_le)
nipkow@39302
  1605
  apply (simp add: set_eq_iff)
himmelma@33175
  1606
  by arith
himmelma@33175
  1607
himmelma@33175
  1608
lemma cball_eq_empty: "(cball x e = {}) \<longleftrightarrow> e < 0"
nipkow@39302
  1609
  apply (simp add: set_eq_iff not_le)
himmelma@33175
  1610
  by (metis zero_le_dist dist_self order_less_le_trans)
himmelma@33175
  1611
lemma cball_empty: "e < 0 ==> cball x e = {}" by (simp add: cball_eq_empty)
himmelma@33175
  1612
himmelma@33175
  1613
lemma cball_eq_sing:
huffman@44072
  1614
  fixes x :: "'a::{metric_space,perfect_space}"
himmelma@33175
  1615
  shows "(cball x e = {x}) \<longleftrightarrow> e = 0"
himmelma@33175
  1616
proof (rule linorder_cases)
himmelma@33175
  1617
  assume e: "0 < e"
himmelma@33175
  1618
  obtain a where "a \<noteq> x" "dist a x < e"
himmelma@33175
  1619
    using perfect_choose_dist [OF e] by auto
himmelma@33175
  1620
  hence "a \<noteq> x" "dist x a \<le> e" by (auto simp add: dist_commute)
nipkow@39302
  1621
  with e show ?thesis by (auto simp add: set_eq_iff)
himmelma@33175
  1622
qed auto
himmelma@33175
  1623
himmelma@33175
  1624
lemma cball_sing:
himmelma@33175
  1625
  fixes x :: "'a::metric_space"
himmelma@33175
  1626
  shows "e = 0 ==> cball x e = {x}"
nipkow@39302
  1627
  by (auto simp add: set_eq_iff)
himmelma@33175
  1628
huffman@44210
  1629
huffman@44210
  1630
subsection {* Boundedness *}
himmelma@33175
  1631
himmelma@33175
  1632
  (* FIXME: This has to be unified with BSEQ!! *)
huffman@44207
  1633
definition (in metric_space)
huffman@44207
  1634
  bounded :: "'a set \<Rightarrow> bool" where
himmelma@33175
  1635
  "bounded S \<longleftrightarrow> (\<exists>x e. \<forall>y\<in>S. dist x y \<le> e)"
himmelma@33175
  1636
himmelma@33175
  1637
lemma bounded_any_center: "bounded S \<longleftrightarrow> (\<exists>e. \<forall>y\<in>S. dist a y \<le> e)"
himmelma@33175
  1638
unfolding bounded_def
himmelma@33175
  1639
apply safe
himmelma@33175
  1640
apply (rule_tac x="dist a x + e" in exI, clarify)
himmelma@33175
  1641
apply (drule (1) bspec)
himmelma@33175
  1642
apply (erule order_trans [OF dist_triangle add_left_mono])
himmelma@33175
  1643
apply auto
himmelma@33175
  1644
done
himmelma@33175
  1645
himmelma@33175
  1646
lemma bounded_iff: "bounded S \<longleftrightarrow> (\<exists>a. \<forall>x\<in>S. norm x \<le> a)"
himmelma@33175
  1647
unfolding bounded_any_center [where a=0]
himmelma@33175
  1648
by (simp add: dist_norm)
himmelma@33175
  1649
himmelma@33175
  1650
lemma bounded_empty[simp]: "bounded {}" by (simp add: bounded_def)
himmelma@33175
  1651
lemma bounded_subset: "bounded T \<Longrightarrow> S \<subseteq> T ==> bounded S"
himmelma@33175
  1652
  by (metis bounded_def subset_eq)
himmelma@33175
  1653
himmelma@33175
  1654
lemma bounded_interior[intro]: "bounded S ==> bounded(interior S)"
himmelma@33175
  1655
  by (metis bounded_subset interior_subset)
himmelma@33175
  1656
himmelma@33175
  1657
lemma bounded_closure[intro]: assumes "bounded S" shows "bounded(closure S)"
himmelma@33175
  1658
proof-
himmelma@33175
  1659
  from assms obtain x and a where a: "\<forall>y\<in>S. dist x y \<le> a" unfolding bounded_def by auto
himmelma@33175
  1660
  { fix y assume "y \<in> closure S"
himmelma@33175
  1661
    then obtain f where f: "\<forall>n. f n \<in> S"  "(f ---> y) sequentially"
himmelma@33175
  1662
      unfolding closure_sequential by auto
himmelma@33175
  1663
    have "\<forall>n. f n \<in> S \<longrightarrow> dist x (f n) \<le> a" using a by simp
himmelma@33175
  1664
    hence "eventually (\<lambda>n. dist x (f n) \<le> a) sequentially"
himmelma@33175
  1665
      by (rule eventually_mono, simp add: f(1))
himmelma@33175
  1666
    have "dist x y \<le> a"
himmelma@33175
  1667
      apply (rule Lim_dist_ubound [of sequentially f])
himmelma@33175
  1668
      apply (rule trivial_limit_sequentially)
himmelma@33175
  1669
      apply (rule f(2))
himmelma@33175
  1670
      apply fact
himmelma@33175
  1671
      done
himmelma@33175
  1672
  }
himmelma@33175
  1673
  thus ?thesis unfolding bounded_def by auto
himmelma@33175
  1674
qed
himmelma@33175
  1675
himmelma@33175
  1676
lemma bounded_cball[simp,intro]: "bounded (cball x e)"
himmelma@33175
  1677
  apply (simp add: bounded_def)
himmelma@33175
  1678
  apply (rule_tac x=x in exI)
himmelma@33175
  1679
  apply (rule_tac x=e in exI)
himmelma@33175
  1680
  apply auto
himmelma@33175
  1681
  done
himmelma@33175
  1682
himmelma@33175
  1683
lemma bounded_ball[simp,intro]: "bounded(ball x e)"
himmelma@33175
  1684
  by (metis ball_subset_cball bounded_cball bounded_subset)
himmelma@33175
  1685
huffman@36362
  1686
lemma finite_imp_bounded[intro]:
huffman@36362
  1687
  fixes S :: "'a::metric_space set" assumes "finite S" shows "bounded S"
himmelma@33175
  1688
proof-
huffman@36362
  1689
  { fix a and F :: "'a set" assume as:"bounded F"
himmelma@33175
  1690
    then obtain x e where "\<forall>y\<in>F. dist x y \<le> e" unfolding bounded_def by auto
himmelma@33175
  1691
    hence "\<forall>y\<in>(insert a F). dist x y \<le> max e (dist x a)" by auto
himmelma@33175
  1692
    hence "bounded (insert a F)" unfolding bounded_def by (intro exI)
himmelma@33175
  1693
  }
himmelma@33175
  1694
  thus ?thesis using finite_induct[of S bounded]  using bounded_empty assms by auto
himmelma@33175
  1695
qed
himmelma@33175
  1696
himmelma@33175
  1697
lemma bounded_Un[simp]: "bounded (S \<union> T) \<longleftrightarrow> bounded S \<and> bounded T"
himmelma@33175
  1698
  apply (auto simp add: bounded_def)
himmelma@33175
  1699
  apply (rename_tac x y r s)
himmelma@33175
  1700
  apply (rule_tac x=x in exI)
himmelma@33175
  1701
  apply (rule_tac x="max r (dist x y + s)" in exI)
himmelma@33175
  1702
  apply (rule ballI, rename_tac z, safe)
himmelma@33175
  1703
  apply (drule (1) bspec, simp)
himmelma@33175
  1704
  apply (drule (1) bspec)
himmelma@33175
  1705
  apply (rule min_max.le_supI2)
himmelma@33175
  1706
  apply (erule order_trans [OF dist_triangle add_left_mono])
himmelma@33175
  1707
  done
himmelma@33175
  1708
himmelma@33175
  1709
lemma bounded_Union[intro]: "finite F \<Longrightarrow> (\<forall>S\<in>F. bounded S) \<Longrightarrow> bounded(\<Union>F)"
himmelma@33175
  1710
  by (induct rule: finite_induct[of F], auto)
himmelma@33175
  1711
himmelma@33175
  1712
lemma bounded_pos: "bounded S \<longleftrightarrow> (\<exists>b>0. \<forall>x\<in> S. norm x <= b)"
himmelma@33175
  1713
  apply (simp add: bounded_iff)
himmelma@33175
  1714
  apply (subgoal_tac "\<And>x (y::real). 0 < 1 + abs y \<and> (x <= y \<longrightarrow> x <= 1 + abs y)")
himmelma@33175
  1715
  by metis arith
himmelma@33175
  1716
himmelma@33175
  1717
lemma bounded_Int[intro]: "bounded S \<or> bounded T \<Longrightarrow> bounded (S \<inter> T)"
himmelma@33175
  1718
  by (metis Int_lower1 Int_lower2 bounded_subset)
himmelma@33175
  1719
himmelma@33175
  1720
lemma bounded_diff[intro]: "bounded S ==> bounded (S - T)"
himmelma@33175
  1721
apply (metis Diff_subset bounded_subset)
himmelma@33175
  1722
done
himmelma@33175
  1723
himmelma@33175
  1724
lemma bounded_insert[intro]:"bounded(insert x S) \<longleftrightarrow> bounded S"
himmelma@33175
  1725
  by (metis Diff_cancel Un_empty_right Un_insert_right bounded_Un bounded_subset finite.emptyI finite_imp_bounded infinite_remove subset_insertI)
himmelma@33175
  1726
himmelma@33175
  1727
lemma not_bounded_UNIV[simp, intro]:
himmelma@33175
  1728
  "\<not> bounded (UNIV :: 'a::{real_normed_vector, perfect_space} set)"
himmelma@33175
  1729
proof(auto simp add: bounded_pos not_le)
himmelma@33175
  1730
  obtain x :: 'a where "x \<noteq> 0"
himmelma@33175
  1731
    using perfect_choose_dist [OF zero_less_one] by fast
himmelma@33175
  1732
  fix b::real  assume b: "b >0"
himmelma@33175
  1733
  have b1: "b +1 \<ge> 0" using b by simp
himmelma@33175
  1734
  with `x \<noteq> 0` have "b < norm (scaleR (b + 1) (sgn x))"
himmelma@33175
  1735
    by (simp add: norm_sgn)
himmelma@33175
  1736
  then show "\<exists>x::'a. b < norm x" ..
himmelma@33175
  1737
qed
himmelma@33175
  1738
himmelma@33175
  1739
lemma bounded_linear_image:
himmelma@33175
  1740
  assumes "bounded S" "bounded_linear f"
himmelma@33175
  1741
  shows "bounded(f ` S)"
himmelma@33175
  1742
proof-
himmelma@33175
  1743
  from assms(1) obtain b where b:"b>0" "\<forall>x\<in>S. norm x \<le> b" unfolding bounded_pos by auto
himmelma@33175
  1744
  from assms(2) obtain B where B:"B>0" "\<forall>x. norm (f x) \<le> B * norm x" using bounded_linear.pos_bounded by (auto simp add: mult_ac)
himmelma@33175
  1745
  { fix x assume "x\<in>S"
himmelma@33175
  1746
    hence "norm x \<le> b" using b by auto
himmelma@33175
  1747
    hence "norm (f x) \<le> B * b" using B(2) apply(erule_tac x=x in allE)
huffman@36778
  1748
      by (metis B(1) B(2) order_trans mult_le_cancel_left_pos)
himmelma@33175
  1749
  }
himmelma@33175
  1750
  thus ?thesis unfolding bounded_pos apply(rule_tac x="b*B" in exI)
huffman@36778
  1751
    using b B mult_pos_pos [of b B] by (auto simp add: mult_commute)
himmelma@33175
  1752
qed
himmelma@33175
  1753
himmelma@33175
  1754
lemma bounded_scaling:
himmelma@33175
  1755
  fixes S :: "'a::real_normed_vector set"
himmelma@33175
  1756
  shows "bounded S \<Longrightarrow> bounded ((\<lambda>x. c *\<^sub>R x) ` S)"
himmelma@33175
  1757
  apply (rule bounded_linear_image, assumption)
huffman@44282
  1758
  apply (rule bounded_linear_scaleR_right)
himmelma@33175
  1759
  done
himmelma@33175
  1760
himmelma@33175
  1761
lemma bounded_translation:
himmelma@33175
  1762
  fixes S :: "'a::real_normed_vector set"
himmelma@33175
  1763
  assumes "bounded S" shows "bounded ((\<lambda>x. a + x) ` S)"
himmelma@33175
  1764
proof-
himmelma@33175
  1765
  from assms obtain b where b:"b>0" "\<forall>x\<in>S. norm x \<le> b" unfolding bounded_pos by auto
himmelma@33175
  1766
  { fix x assume "x\<in>S"
himmelma@33175
  1767
    hence "norm (a + x) \<le> b + norm a" using norm_triangle_ineq[of a x] b by auto
himmelma@33175
  1768
  }
himmelma@33175
  1769
  thus ?thesis unfolding bounded_pos using norm_ge_zero[of a] b(1) using add_strict_increasing[of b 0 "norm a"]
huffman@48048
  1770
    by (auto intro!: exI[of _ "b + norm a"])
himmelma@33175
  1771
qed
himmelma@33175
  1772
himmelma@33175
  1773
himmelma@33175
  1774
text{* Some theorems on sups and infs using the notion "bounded". *}
himmelma@33175
  1775
himmelma@33175
  1776
lemma bounded_real:
himmelma@33175
  1777
  fixes S :: "real set"
himmelma@33175
  1778
  shows "bounded S \<longleftrightarrow>  (\<exists>a. \<forall>x\<in>S. abs x <= a)"
himmelma@33175
  1779
  by (simp add: bounded_iff)
himmelma@33175
  1780
paulson@33270
  1781
lemma bounded_has_Sup:
paulson@33270
  1782
  fixes S :: "real set"
paulson@33270
  1783
  assumes "bounded S" "S \<noteq> {}"
paulson@33270
  1784
  shows "\<forall>x\<in>S. x <= Sup S" and "\<forall>b. (\<forall>x\<in>S. x <= b) \<longrightarrow> Sup S <= b"
paulson@33270
  1785
proof
paulson@33270
  1786
  fix x assume "x\<in>S"
paulson@33270
  1787
  thus "x \<le> Sup S"
paulson@33270
  1788
    by (metis SupInf.Sup_upper abs_le_D1 assms(1) bounded_real)
paulson@33270
  1789
next
paulson@33270
  1790
  show "\<forall>b. (\<forall>x\<in>S. x \<le> b) \<longrightarrow> Sup S \<le> b" using assms
paulson@33270
  1791
    by (metis SupInf.Sup_least)
paulson@33270
  1792
qed
paulson@33270
  1793
paulson@33270
  1794
lemma Sup_insert:
paulson@33270
  1795
  fixes S :: "real set"
paulson@33270
  1796
  shows "bounded S ==> Sup(insert x S) = (if S = {} then x else max x (Sup S))" 
paulson@33270
  1797
by auto (metis Int_absorb Sup_insert_nonempty assms bounded_has_Sup(1) disjoint_iff_not_equal) 
paulson@33270
  1798
paulson@33270
  1799
lemma Sup_insert_finite:
paulson@33270
  1800
  fixes S :: "real set"
paulson@33270
  1801
  shows "finite S \<Longrightarrow> Sup(insert x S) = (if S = {} then x else max x (Sup S))"
paulson@33270
  1802
  apply (rule Sup_insert)
paulson@33270
  1803
  apply (rule finite_imp_bounded)
paulson@33270
  1804
  by simp
paulson@33270
  1805
paulson@33270
  1806
lemma bounded_has_Inf:
paulson@33270
  1807
  fixes S :: "real set"
paulson@33270
  1808
  assumes "bounded S"  "S \<noteq> {}"
paulson@33270
  1809
  shows "\<forall>x\<in>S. x >= Inf S" and "\<forall>b. (\<forall>x\<in>S. x >= b) \<longrightarrow> Inf S >= b"
himmelma@33175
  1810
proof
himmelma@33175
  1811
  fix x assume "x\<in>S"
himmelma@33175
  1812
  from assms(1) obtain a where a:"\<forall>x\<in>S. \<bar>x\<bar> \<le> a" unfolding bounded_real by auto
paulson@33270
  1813
  thus "x \<ge> Inf S" using `x\<in>S`
paulson@33270
  1814
    by (metis Inf_lower_EX abs_le_D2 minus_le_iff)
himmelma@33175
  1815
next
paulson@33270
  1816
  show "\<forall>b. (\<forall>x\<in>S. x >= b) \<longrightarrow> Inf S \<ge> b" using assms
paulson@33270
  1817
    by (metis SupInf.Inf_greatest)
paulson@33270
  1818
qed
paulson@33270
  1819
paulson@33270
  1820
lemma Inf_insert:
paulson@33270
  1821
  fixes S :: "real set"
paulson@33270
  1822
  shows "bounded S ==> Inf(insert x S) = (if S = {} then x else min x (Inf S))" 
paulson@33270
  1823
by auto (metis Int_absorb Inf_insert_nonempty bounded_has_Inf(1) disjoint_iff_not_equal) 
paulson@33270
  1824
lemma Inf_insert_finite:
paulson@33270
  1825
  fixes S :: "real set"
paulson@33270
  1826
  shows "finite S ==> Inf(insert x S) = (if S = {} then x else min x (Inf S))"
paulson@33270
  1827
  by (rule Inf_insert, rule finite_imp_bounded, simp)
paulson@33270
  1828
himmelma@33175
  1829
(* TODO: Move this to RComplete.thy -- would need to include Glb into RComplete *)
himmelma@33175
  1830
lemma real_isGlb_unique: "[| isGlb R S x; isGlb R S y |] ==> x = (y::real)"
himmelma@33175
  1831
  apply (frule isGlb_isLb)
himmelma@33175
  1832
  apply (frule_tac x = y in isGlb_isLb)
himmelma@33175
  1833
  apply (blast intro!: order_antisym dest!: isGlb_le_isLb)
himmelma@33175
  1834
  done
himmelma@33175
  1835
huffman@44210
  1836
huffman@36437
  1837
subsection {* Equivalent versions of compactness *}
huffman@36437
  1838
huffman@36437
  1839
subsubsection{* Sequential compactness *}
himmelma@33175
  1840
himmelma@33175
  1841
definition
himmelma@33175
  1842
  compact :: "'a::metric_space set \<Rightarrow> bool" where (* TODO: generalize *)
himmelma@33175
  1843
  "compact S \<longleftrightarrow>
himmelma@33175
  1844
   (\<forall>f. (\<forall>n. f n \<in> S) \<longrightarrow>
himmelma@33175
  1845
       (\<exists>l\<in>S. \<exists>r. subseq r \<and> ((f o r) ---> l) sequentially))"
himmelma@33175
  1846
huffman@44075
  1847
lemma compactI:
huffman@44075
  1848
  assumes "\<And>f. \<forall>n. f n \<in> S \<Longrightarrow> \<exists>l\<in>S. \<exists>r. subseq r \<and> ((f o r) ---> l) sequentially"
huffman@44075
  1849
  shows "compact S"
huffman@44075
  1850
  unfolding compact_def using assms by fast
huffman@44075
  1851
huffman@44075
  1852
lemma compactE:
huffman@44075
  1853
  assumes "compact S" "\<forall>n. f n \<in> S"
huffman@44075
  1854
  obtains l r where "l \<in> S" "subseq r" "((f \<circ> r) ---> l) sequentially"
huffman@44075
  1855
  using assms unfolding compact_def by fast
huffman@44075
  1856
himmelma@33175
  1857
text {*
himmelma@33175
  1858
  A metric space (or topological vector space) is said to have the
himmelma@33175
  1859
  Heine-Borel property if every closed and bounded subset is compact.
himmelma@33175
  1860
*}
himmelma@33175
  1861
huffman@44207
  1862
class heine_borel = metric_space +
himmelma@33175
  1863
  assumes bounded_imp_convergent_subsequence:
himmelma@33175
  1864
    "bounded s \<Longrightarrow> \<forall>n. f n \<in> s
himmelma@33175
  1865
      \<Longrightarrow> \<exists>l r. subseq r \<and> ((f \<circ> r) ---> l) sequentially"
himmelma@33175
  1866
himmelma@33175
  1867
lemma bounded_closed_imp_compact:
himmelma@33175
  1868
  fixes s::"'a::heine_borel set"
himmelma@33175
  1869
  assumes "bounded s" and "closed s" shows "compact s"
himmelma@33175
  1870
proof (unfold compact_def, clarify)
himmelma@33175
  1871
  fix f :: "nat \<Rightarrow> 'a" assume f: "\<forall>n. f n \<in> s"
himmelma@33175
  1872
  obtain l r where r: "subseq r" and l: "((f \<circ> r) ---> l) sequentially"
himmelma@33175
  1873
    using bounded_imp_convergent_subsequence [OF `bounded s` `\<forall>n. f n \<in> s`] by auto
himmelma@33175
  1874
  from f have fr: "\<forall>n. (f \<circ> r) n \<in> s" by simp
himmelma@33175
  1875
  have "l \<in> s" using `closed s` fr l
himmelma@33175
  1876
    unfolding closed_sequential_limits by blast
himmelma@33175
  1877
  show "\<exists>l\<in>s. \<exists>r. subseq r \<and> ((f \<circ> r) ---> l) sequentially"
himmelma@33175
  1878
    using `l \<in> s` r l by blast
himmelma@33175
  1879
qed
himmelma@33175
  1880
himmelma@33175
  1881
lemma subseq_bigger: assumes "subseq r" shows "n \<le> r n"
himmelma@33175
  1882
proof(induct n)
himmelma@33175
  1883
  show "0 \<le> r 0" by auto
himmelma@33175
  1884
next
himmelma@33175
  1885
  fix n assume "n \<le> r n"
himmelma@33175
  1886
  moreover have "r n < r (Suc n)"
himmelma@33175
  1887
    using assms [unfolded subseq_def] by auto
himmelma@33175
  1888
  ultimately show "Suc n \<le> r (Suc n)" by auto
himmelma@33175
  1889
qed
himmelma@33175
  1890
himmelma@33175
  1891
lemma eventually_subseq:
himmelma@33175
  1892
  assumes r: "subseq r"
himmelma@33175
  1893
  shows "eventually P sequentially \<Longrightarrow> eventually (\<lambda>n. P (r n)) sequentially"
himmelma@33175
  1894
unfolding eventually_sequentially
himmelma@33175
  1895
by (metis subseq_bigger [OF r] le_trans)
himmelma@33175
  1896
himmelma@33175
  1897
lemma lim_subseq:
himmelma@33175
  1898
  "subseq r \<Longrightarrow> (s ---> l) sequentially \<Longrightarrow> ((s o r) ---> l) sequentially"
himmelma@33175
  1899
unfolding tendsto_def eventually_sequentially o_def
himmelma@33175
  1900
by (metis subseq_bigger le_trans)
himmelma@33175
  1901
himmelma@33175
  1902
lemma num_Axiom: "EX! g. g 0 = e \<and> (\<forall>n. g (Suc n) = f n (g n))"
himmelma@33175
  1903
  unfolding Ex1_def
himmelma@33175
  1904
  apply (rule_tac x="nat_rec e f" in exI)
himmelma@33175
  1905
  apply (rule conjI)+
himmelma@33175
  1906
apply (rule def_nat_rec_0, simp)
himmelma@33175
  1907
apply (rule allI, rule def_nat_rec_Suc, simp)
himmelma@33175
  1908
apply (rule allI, rule impI, rule ext)
himmelma@33175
  1909
apply (erule conjE)
himmelma@33175
  1910
apply (induct_tac x)
huffman@36362
  1911
apply simp
himmelma@33175
  1912
apply (erule_tac x="n" in allE)
himmelma@33175
  1913
apply (simp)
himmelma@33175
  1914
done
himmelma@33175
  1915
himmelma@33175
  1916
lemma convergent_bounded_increasing: fixes s ::"nat\<Rightarrow>real"
himmelma@33175
  1917
  assumes "incseq s" and "\<forall>n. abs(s n) \<le> b"
himmelma@33175
  1918
  shows "\<exists> l. \<forall>e::real>0. \<exists> N. \<forall>n \<ge> N.  abs(s n - l) < e"
himmelma@33175
  1919
proof-
himmelma@33175
  1920
  have "isUb UNIV (range s) b" using assms(2) and abs_le_D1 unfolding isUb_def and setle_def by auto
himmelma@33175
  1921
  then obtain t where t:"isLub UNIV (range s) t" using reals_complete[of "range s" ] by auto
himmelma@33175
  1922
  { fix e::real assume "e>0" and as:"\<forall>N. \<exists>n\<ge>N. \<not> \<bar>s n - t\<bar> < e"
himmelma@33175
  1923
    { fix n::nat
himmelma@33175
  1924
      obtain N where "N\<ge>n" and n:"\<bar>s N - t\<bar> \<ge> e" using as[THEN spec[where x=n]] by auto
himmelma@33175
  1925
      have "t \<ge> s N" using isLub_isUb[OF t, unfolded isUb_def setle_def] by auto
himmelma@33175
  1926
      with n have "s N \<le> t - e" using `e>0` by auto
himmelma@33175
  1927
      hence "s n \<le> t - e" using assms(1)[unfolded incseq_def, THEN spec[where x=n], THEN spec[where x=N]] using `n\<le>N` by auto  }
himmelma@33175
  1928
    hence "isUb UNIV (range s) (t - e)" unfolding isUb_def and setle_def by auto
himmelma@33175
  1929
    hence False using isLub_le_isUb[OF t, of "t - e"] and `e>0` by auto  }
himmelma@33175
  1930
  thus ?thesis by blast
himmelma@33175
  1931
qed
himmelma@33175
  1932
himmelma@33175
  1933
lemma convergent_bounded_monotone: fixes s::"nat \<Rightarrow> real"
himmelma@33175
  1934
  assumes "\<forall>n. abs(s n) \<le> b" and "monoseq s"
himmelma@33175
  1935
  shows "\<exists>l. \<forall>e::real>0. \<exists>N. \<forall>n\<ge>N. abs(s n - l) < e"
himmelma@33175
  1936
  using convergent_bounded_increasing[of s b] assms using convergent_bounded_increasing[of "\<lambda>n. - s n" b]
himmelma@33175
  1937
  unfolding monoseq_def incseq_def
himmelma@33175
  1938
  apply auto unfolding minus_add_distrib[THEN sym, unfolded diff_minus[THEN sym]]
himmelma@33175
  1939
  unfolding abs_minus_cancel by(rule_tac x="-l" in exI)auto
himmelma@33175
  1940
hoelzl@37489
  1941
(* TODO: merge this lemma with the ones above *)
hoelzl@37489
  1942
lemma bounded_increasing_convergent: fixes s::"nat \<Rightarrow> real"
hoelzl@37489
  1943
  assumes "bounded {s n| n::nat. True}"  "\<forall>n. (s n) \<le>(s(Suc n))"
hoelzl@37489
  1944
  shows "\<exists>l. (s ---> l) sequentially"
hoelzl@37489
  1945
proof-
hoelzl@37489
  1946
  obtain a where a:"\<forall>n. \<bar> (s n)\<bar> \<le>  a" using assms(1)[unfolded bounded_iff] by auto
hoelzl@37489
  1947
  { fix m::nat
hoelzl@37489
  1948
    have "\<And> n. n\<ge>m \<longrightarrow>  (s m) \<le> (s n)"
hoelzl@37489
  1949
      apply(induct_tac n) apply simp using assms(2) apply(erule_tac x="na" in allE)
hoelzl@37489
  1950
      apply(case_tac "m \<le> na") unfolding not_less_eq_eq by(auto simp add: not_less_eq_eq)  }
hoelzl@37489
  1951
  hence "\<forall>m n. m \<le> n \<longrightarrow> (s m) \<le> (s n)" by auto
hoelzl@37489
  1952
  then obtain l where "\<forall>e>0. \<exists>N. \<forall>n\<ge>N. \<bar> (s n) - l\<bar> < e" using convergent_bounded_monotone[OF a]
hoelzl@37489
  1953
    unfolding monoseq_def by auto
huffman@44907
  1954
  thus ?thesis unfolding LIMSEQ_def apply(rule_tac x="l" in exI)
hoelzl@37489
  1955
    unfolding dist_norm  by auto
hoelzl@37489
  1956
qed
hoelzl@37489
  1957
himmelma@33175
  1958
lemma compact_real_lemma:
himmelma@33175
  1959
  assumes "\<forall>n::nat. abs(s n) \<le> b"
himmelma@33175
  1960
  shows "\<exists>(l::real) r. subseq r \<and> ((s \<circ> r) ---> l) sequentially"
himmelma@33175
  1961
proof-
himmelma@33175
  1962
  obtain r where r:"subseq r" "monoseq (\<lambda>n. s (r n))"
himmelma@33175
  1963
    using seq_monosub[of s] by auto
himmelma@33175
  1964
  thus ?thesis using convergent_bounded_monotone[of "\<lambda>n. s (r n)" b] and assms
himmelma@33175
  1965
    unfolding tendsto_iff dist_norm eventually_sequentially by auto
himmelma@33175
  1966
qed
himmelma@33175
  1967
himmelma@33175
  1968
instance real :: heine_borel
himmelma@33175
  1969
proof
himmelma@33175
  1970
  fix s :: "real set" and f :: "nat \<Rightarrow> real"
himmelma@33175
  1971
  assume s: "bounded s" and f: "\<forall>n. f n \<in> s"
himmelma@33175
  1972
  then obtain b where b: "\<forall>n. abs (f n) \<le> b"
himmelma@33175
  1973
    unfolding bounded_iff by auto
himmelma@33175
  1974
  obtain l :: real and r :: "nat \<Rightarrow> nat" where
himmelma@33175
  1975
    r: "subseq r" and l: "((f \<circ> r) ---> l) sequentially"
himmelma@33175
  1976
    using compact_real_lemma [OF b] by auto
himmelma@33175
  1977
  thus "\<exists>l r. subseq r \<and> ((f \<circ> r) ---> l) sequentially"
himmelma@33175
  1978
    by auto
himmelma@33175
  1979
qed
himmelma@33175
  1980
huffman@44138
  1981
lemma bounded_component: "bounded s \<Longrightarrow> bounded ((\<lambda>x. x $$ i) ` s)"
huffman@44138
  1982
  apply (erule bounded_linear_image)
huffman@44138
  1983
  apply (rule bounded_linear_euclidean_component)
huffman@44138
  1984
  done
himmelma@33175
  1985
himmelma@33175
  1986
lemma compact_lemma:
hoelzl@37489
  1987
  fixes f :: "nat \<Rightarrow> 'a::euclidean_space"
himmelma@33175
  1988
  assumes "bounded s" and "\<forall>n. f n \<in> s"
hoelzl@37489
  1989
  shows "\<forall>d. \<exists>l::'a. \<exists> r. subseq r \<and>
hoelzl@37489
  1990
        (\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r n) $$ i) (l $$ i) < e) sequentially)"
himmelma@33175
  1991
proof
hoelzl@37489
  1992
  fix d'::"nat set" def d \<equiv> "d' \<inter> {..<DIM('a)}"
hoelzl@37489
  1993
  have "finite d" "d\<subseteq>{..<DIM('a)}" unfolding d_def by auto
hoelzl@37489
  1994
  hence "\<exists>l::'a. \<exists>r. subseq r \<and>
hoelzl@37489
  1995
      (\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r n) $$ i) (l $$ i) < e) sequentially)"
himmelma@33175
  1996
  proof(induct d) case empty thus ?case unfolding subseq_def by auto
hoelzl@37489
  1997
  next case (insert k d) have k[intro]:"k<DIM('a)" using insert by auto
hoelzl@37489
  1998
    have s': "bounded ((\<lambda>x. x $$ k) ` s)" using `bounded s` by (rule bounded_component)
hoelzl@37489
  1999
    obtain l1::"'a" and r1 where r1:"subseq r1" and
hoelzl@37489
  2000
      lr1:"\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r1 n) $$ i) (l1 $$ i) < e) sequentially"
hoelzl@37489
  2001
      using insert(3) using insert(4) by auto
hoelzl@37489
  2002
    have f': "\<forall>n. f (r1 n) $$ k \<in> (\<lambda>x. x $$ k) ` s" using `\<forall>n. f n \<in> s` by simp
hoelzl@37489
  2003
    obtain l2 r2 where r2:"subseq r2" and lr2:"((\<lambda>i. f (r1 (r2 i)) $$ k) ---> l2) sequentially"
himmelma@33175
  2004
      using bounded_imp_convergent_subsequence[OF s' f'] unfolding o_def by auto
himmelma@33175
  2005
    def r \<equiv> "r1 \<circ> r2" have r:"subseq r"
himmelma@33175
  2006
      using r1 and r2 unfolding r_def o_def subseq_def by auto
himmelma@33175
  2007
    moreover
hoelzl@37489
  2008
    def l \<equiv> "(\<chi>\<chi> i. if i = k then l2 else l1$$i)::'a"
himmelma@33175
  2009
    { fix e::real assume "e>0"
hoelzl@37489
  2010
      from lr1 `e>0` have N1:"eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r1 n) $$ i) (l1 $$ i) < e) sequentially" by blast
hoelzl@37489
  2011
      from lr2 `e>0` have N2:"eventually (\<lambda>n. dist (f (r1 (r2 n)) $$ k) l2 < e) sequentially" by (rule tendstoD)
hoelzl@37489
  2012
      from r2 N1 have N1': "eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r1 (r2 n)) $$ i) (l1 $$ i) < e) sequentially"
himmelma@33175
  2013
        by (rule eventually_subseq)
hoelzl@37489
  2014
      have "eventually (\<lambda>n. \<forall>i\<in>(insert k d). dist (f (r n) $$ i) (l $$ i) < e) sequentially"
hoelzl@37489
  2015
        using N1' N2 apply(rule eventually_elim2) unfolding l_def r_def o_def
hoelzl@37489
  2016
        using insert.prems by auto
himmelma@33175
  2017
    }
himmelma@33175
  2018
    ultimately show ?case by auto
himmelma@33175
  2019
  qed
hoelzl@37489
  2020
  thus "\<exists>l::'a. \<exists>r. subseq r \<and>
hoelzl@37489
  2021
      (\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>d'. dist (f (r n) $$ i) (l $$ i) < e) sequentially)"
hoelzl@37489
  2022
    apply safe apply(rule_tac x=l in exI,rule_tac x=r in exI) apply safe
hoelzl@37489
  2023
    apply(erule_tac x=e in allE) unfolding d_def eventually_sequentially apply safe 
hoelzl@37489
  2024
    apply(rule_tac x=N in exI) apply safe apply(erule_tac x=n in allE,safe)
hoelzl@37489
  2025
    apply(erule_tac x=i in ballE) 
hoelzl@37489
  2026
  proof- fix i and r::"nat=>nat" and n::nat and e::real and l::'a
hoelzl@37489
  2027
    assume "i\<in>d'" "i \<notin> d' \<inter> {..<DIM('a)}" and e:"e>0"
hoelzl@37489
  2028
    hence *:"i\<ge>DIM('a)" by auto
hoelzl@37489
  2029
    thus "dist (f (r n) $$ i) (l $$ i) < e" using e by auto
hoelzl@37489
  2030
  qed
hoelzl@37489
  2031
qed
hoelzl@37489
  2032
hoelzl@37489
  2033
instance euclidean_space \<subseteq> heine_borel
himmelma@33175
  2034
proof
hoelzl@37489
  2035
  fix s :: "'a set" and f :: "nat \<Rightarrow> 'a"
himmelma@33175
  2036
  assume s: "bounded s" and f: "\<forall>n. f n \<in> s"
hoelzl@37489
  2037
  then obtain l::'a and r where r: "subseq r"
hoelzl@37489
  2038
    and l: "\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>UNIV. dist (f (r n) $$ i) (l $$ i) < e) sequentially"
himmelma@33175
  2039
    using compact_lemma [OF s f] by blast
hoelzl@37489
  2040
  let ?d = "{..<DIM('a)}"
himmelma@33175
  2041
  { fix e::real assume "e>0"
himmelma@33175
  2042
    hence "0 < e / (real_of_nat (card ?d))"
hoelzl@37489
  2043
      using DIM_positive using divide_pos_pos[of e, of "real_of_nat (card ?d)"] by auto
hoelzl@37489
  2044
    with l have "eventually (\<lambda>n. \<forall>i. dist (f (r n) $$ i) (l $$ i) < e / (real_of_nat (card ?d))) sequentially"
himmelma@33175
  2045
      by simp
himmelma@33175
  2046
    moreover
hoelzl@37489
  2047
    { fix n assume n: "\<forall>i. dist (f (r n) $$ i) (l $$ i) < e / (real_of_nat (card ?d))"
hoelzl@37489
  2048
      have "dist (f (r n)) l \<le> (\<Sum>i\<in>?d. dist (f (r n) $$ i) (l $$ i))"
hoelzl@37489
  2049
        apply(subst euclidean_dist_l2) using zero_le_dist by (rule setL2_le_setsum)
himmelma@33175
  2050
      also have "\<dots> < (\<Sum>i\<in>?d. e / (real_of_nat (card ?d)))"
hoelzl@37489
  2051
        apply(rule setsum_strict_mono) using n by auto
hoelzl@37489
  2052
      finally have "dist (f (r n)) l < e" unfolding setsum_constant
hoelzl@37489
  2053
        using DIM_positive[where 'a='a] by auto
himmelma@33175
  2054
    }
himmelma@33175
  2055
    ultimately have "eventually (\<lambda>n. dist (f (r n)) l < e) sequentially"
himmelma@33175
  2056
      by (rule eventually_elim1)
himmelma@33175
  2057
  }
himmelma@33175
  2058
  hence *:"((f \<circ> r) ---> l) sequentially" unfolding o_def tendsto_iff by simp
himmelma@33175
  2059
  with r show "\<exists>l r. subseq r \<and> ((f \<circ> r) ---> l) sequentially" by auto
himmelma@33175
  2060
qed
himmelma@33175
  2061
himmelma@33175
  2062
lemma bounded_fst: "bounded s \<Longrightarrow> bounded (fst ` s)"
himmelma@33175
  2063
unfolding bounded_def
himmelma@33175
  2064
apply clarify
himmelma@33175
  2065
apply (rule_tac x="a" in exI)
himmelma@33175
  2066
apply (rule_tac x="e" in exI)
himmelma@33175
  2067
apply clarsimp
himmelma@33175
  2068
apply (drule (1) bspec)
himmelma@33175
  2069
apply (simp add: dist_Pair_Pair)
himmelma@33175
  2070
apply (erule order_trans [OF real_sqrt_sum_squares_ge1])
himmelma@33175
  2071
done
himmelma@33175
  2072
himmelma@33175
  2073
lemma bounded_snd: "bounded s \<Longrightarrow> bounded (snd ` s)"
himmelma@33175
  2074
unfolding bounded_def
himmelma@33175
  2075
apply clarify
himmelma@33175
  2076
apply (rule_tac x="b" in exI)
himmelma@33175
  2077
apply (rule_tac x="e" in exI)
himmelma@33175
  2078
apply clarsimp
himmelma@33175
  2079
apply (drule (1) bspec)
himmelma@33175
  2080
apply (simp add: dist_Pair_Pair)
himmelma@33175
  2081
apply (erule order_trans [OF real_sqrt_sum_squares_ge2])
himmelma@33175
  2082
done
himmelma@33175
  2083
haftmann@37678
  2084
instance prod :: (heine_borel, heine_borel) heine_borel
himmelma@33175
  2085
proof
himmelma@33175
  2086
  fix s :: "('a * 'b) set" and f :: "nat \<Rightarrow> 'a * 'b"
himmelma@33175
  2087
  assume s: "bounded s" and f: "\<forall>n. f n \<in> s"
himmelma@33175
  2088
  from s have s1: "bounded (fst ` s)" by (rule bounded_fst)
himmelma@33175
  2089
  from f have f1: "\<forall>n. fst (f n) \<in> fst ` s" by simp
himmelma@33175
  2090
  obtain l1 r1 where r1: "subseq r1"
himmelma@33175
  2091
    and l1: "((\<lambda>n. fst (f (r1 n))) ---> l1) sequentially"
himmelma@33175
  2092
    using bounded_imp_convergent_subsequence [OF s1 f1]
himmelma@33175
  2093
    unfolding o_def by fast
himmelma@33175
  2094
  from s have s2: "bounded (snd ` s)" by (rule bounded_snd)
himmelma@33175
  2095
  from f have f2: "\<forall>n. snd (f (r1 n)) \<in> snd ` s" by simp
himmelma@33175
  2096
  obtain l2 r2 where r2: "subseq r2"
himmelma@33175
  2097
    and l2: "((\<lambda>n. snd (f (r1 (r2 n)))) ---> l2) sequentially"
himmelma@33175
  2098
    using bounded_imp_convergent_subsequence [OF s2 f2]
himmelma@33175
  2099
    unfolding o_def by fast
himmelma@33175
  2100
  have l1': "((\<lambda>n. fst (f (r1 (r2 n)))) ---> l1) sequentially"
himmelma@33175
  2101
    using lim_subseq [OF r2 l1] unfolding o_def .
himmelma@33175
  2102
  have l: "((f \<circ> (r1 \<circ> r2)) ---> (l1, l2)) sequentially"
himmelma@33175
  2103
    using tendsto_Pair [OF l1' l2] unfolding o_def by simp
himmelma@33175
  2104
  have r: "subseq (r1 \<circ> r2)"
himmelma@33175
  2105
    using r1 r2 unfolding subseq_def by simp
himmelma@33175
  2106
  show "\<exists>l r. subseq r \<and> ((f \<circ> r) ---> l) sequentially"
himmelma@33175
  2107
    using l r by fast
himmelma@33175
  2108
qed
himmelma@33175
  2109
huffman@36437
  2110
subsubsection{* Completeness *}
himmelma@33175
  2111
himmelma@33175
  2112
lemma cauchy_def:
himmelma@33175
  2113
  "Cauchy s \<longleftrightarrow> (\<forall>e>0. \<exists>N. \<forall>m n. m \<ge> N \<and> n \<ge> N --> dist(s m)(s n) < e)"
himmelma@33175
  2114
unfolding Cauchy_def by blast
himmelma@33175
  2115
himmelma@33175
  2116
definition
himmelma@33175
  2117
  complete :: "'a::metric_space set \<Rightarrow> bool" where
himmelma@33175
  2118
  "complete s \<longleftrightarrow> (\<forall>f. (\<forall>n. f n \<in> s) \<and> Cauchy f
himmelma@33175
  2119
                      --> (\<exists>l \<in> s. (f ---> l) sequentially))"
himmelma@33175
  2120
himmelma@33175
  2121
lemma cauchy: "Cauchy s \<longleftrightarrow> (\<forall>e>0.\<exists> N::nat. \<forall>n\<ge>N. dist(s n)(s N) < e)" (is "?lhs = ?rhs")
himmelma@33175
  2122
proof-
himmelma@33175
  2123
  { assume ?rhs
himmelma@33175
  2124
    { fix e::real
himmelma@33175
  2125
      assume "e>0"
himmelma@33175
  2126
      with `?rhs` obtain N where N:"\<forall>n\<ge>N. dist (s n) (s N) < e/2"
himmelma@33175
  2127
        by (erule_tac x="e/2" in allE) auto
himmelma@33175
  2128
      { fix n m
himmelma@33175
  2129
        assume nm:"N \<le> m \<and> N \<le> n"
himmelma@33175
  2130
        hence "dist (s m) (s n) < e" using N
himmelma@33175
  2131
          using dist_triangle_half_l[of "s m" "s N" "e" "s n"]
himmelma@33175
  2132
          by blast
himmelma@33175
  2133
      }
himmelma@33175
  2134
      hence "\<exists>N. \<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (s m) (s n) < e"
himmelma@33175
  2135
        by blast
himmelma@33175
  2136
    }
himmelma@33175
  2137
    hence ?lhs
himmelma@33175
  2138
      unfolding cauchy_def
himmelma@33175
  2139
      by blast
himmelma@33175
  2140
  }
himmelma@33175
  2141
  thus ?thesis
himmelma@33175
  2142
    unfolding cauchy_def
himmelma@33175
  2143
    using dist_triangle_half_l
himmelma@33175
  2144
    by blast
himmelma@33175
  2145
qed
himmelma@33175
  2146
himmelma@33175
  2147
lemma convergent_imp_cauchy:
himmelma@33175
  2148
 "(s ---> l) sequentially ==> Cauchy s"
himmelma@33175
  2149
proof(simp only: cauchy_def, rule, rule)
himmelma@33175
  2150
  fix e::real assume "e>0" "(s ---> l) sequentially"
huffman@44907
  2151
  then obtain N::nat where N:"\<forall>n\<ge>N. dist (s n) l < e/2" unfolding LIMSEQ_def by(erule_tac x="e/2" in allE) auto
himmelma@33175
  2152
  thus "\<exists>N. \<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (s m) (s n) < e"  using dist_triangle_half_l[of _ l e _] by (rule_tac x=N in exI) auto
himmelma@33175
  2153
qed
himmelma@33175
  2154
huffman@34104
  2155
lemma cauchy_imp_bounded: assumes "Cauchy s" shows "bounded (range s)"
himmelma@33175
  2156
proof-
himmelma@33175
  2157
  from assms obtain N::nat where "\<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (s m) (s n) < 1" unfolding cauchy_def apply(erule_tac x= 1 in allE) by auto
himmelma@33175
  2158
  hence N:"\<forall>n. N \<le> n \<longrightarrow> dist (s N) (s n) < 1" by auto
himmelma@33175
  2159
  moreover
himmelma@33175
  2160
  have "bounded (s ` {0..N})" using finite_imp_bounded[of "s ` {1..N}"] by auto
himmelma@33175
  2161
  then obtain a where a:"\<forall>x\<in>s ` {0..N}. dist (s N) x \<le> a"
himmelma@33175
  2162
    unfolding bounded_any_center [where a="s N"] by auto
himmelma@33175
  2163
  ultimately show "?thesis"
himmelma@33175
  2164
    unfolding bounded_any_center [where a="s N"]
himmelma@33175
  2165
    apply(rule_tac x="max a 1" in exI) apply auto
huffman@34104
  2166
    apply(erule_tac x=y in allE) apply(erule_tac x=y in ballE) by auto
himmelma@33175
  2167
qed
himmelma@33175
  2168
himmelma@33175
  2169
lemma compact_imp_complete: assumes "compact s" shows "complete s"
himmelma@33175
  2170
proof-
himmelma@33175
  2171
  { fix f assume as: "(\<forall>n::nat. f n \<in> s)" "Cauchy f"
himmelma@33175
  2172
    from as(1) obtain l r where lr: "l\<in>s" "subseq r" "((f \<circ> r) ---> l) sequentially" using assms unfolding compact_def by blast
himmelma@33175
  2173
himmelma@33175
  2174
    note lr' = subseq_bigger [OF lr(2)]
himmelma@33175
  2175
himmelma@33175
  2176
    { fix e::real assume "e>0"
himmelma@33175
  2177
      from as(2) obtain N where N:"\<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (f m) (f n) < e/2" unfolding cauchy_def using `e>0` apply (erule_tac x="e/2" in allE) by auto
huffman@44907
  2178
      from lr(3)[unfolded LIMSEQ_def, THEN spec[where x="e/2"]] obtain M where M:"\<forall>n\<ge>M. dist ((f \<circ> r) n) l < e/2" using `e>0` by auto
himmelma@33175
  2179
      { fix n::nat assume n:"n \<ge> max N M"
himmelma@33175
  2180
        have "dist ((f \<circ> r) n) l < e/2" using n M by auto
himmelma@33175
  2181
        moreover have "r n \<ge> N" using lr'[of n] n by auto
himmelma@33175
  2182
        hence "dist (f n) ((f \<circ> r) n) < e / 2" using N using n by auto
himmelma@33175
  2183
        ultimately have "dist (f n) l < e" using dist_triangle_half_r[of "f (r n)" "f n" e l] by (auto simp add: dist_commute)  }
himmelma@33175
  2184
      hence "\<exists>N. \<forall>n\<ge>N. dist (f n) l < e" by blast  }
huffman@44907
  2185
    hence "\<exists>l\<in>s. (f ---> l) sequentially" using `l\<in>s` unfolding LIMSEQ_def by auto  }
himmelma@33175
  2186
  thus ?thesis unfolding complete_def by auto
himmelma@33175
  2187
qed
himmelma@33175
  2188
himmelma@33175
  2189
instance heine_borel < complete_space
himmelma@33175
  2190
proof
himmelma@33175
  2191
  fix f :: "nat \<Rightarrow> 'a" assume "Cauchy f"
huffman@34104
  2192
  hence "bounded (range f)"
huffman@34104
  2193
    by (rule cauchy_imp_bounded)
himmelma@33175
  2194
  hence "compact (closure (range f))"
himmelma@33175
  2195
    using bounded_closed_imp_compact [of "closure (range f)"] by auto
himmelma@33175
  2196
  hence "complete (closure (range f))"
huffman@34104
  2197
    by (rule compact_imp_complete)
himmelma@33175
  2198
  moreover have "\<forall>n. f n \<in> closure (range f)"
himmelma@33175
  2199
    using closure_subset [of "range f"] by auto
himmelma@33175
  2200
  ultimately have "\<exists>l\<in>closure (range f). (f ---> l) sequentially"
himmelma@33175
  2201
    using `Cauchy f` unfolding complete_def by auto
himmelma@33175
  2202
  then show "convergent f"
huffman@36660
  2203
    unfolding convergent_def by auto
himmelma@33175
  2204
qed
himmelma@33175
  2205
huffman@44632
  2206
instance euclidean_space \<subseteq> banach ..
huffman@44632
  2207
himmelma@33175
  2208
lemma complete_univ: "complete (UNIV :: 'a::complete_space set)"
himmelma@33175
  2209
proof(simp add: complete_def, rule, rule)
himmelma@33175
  2210
  fix f :: "nat \<Rightarrow> 'a" assume "Cauchy f"
himmelma@33175
  2211
  hence "convergent f" by (rule Cauchy_convergent)
huffman@36660
  2212
  thus "\<exists>l. f ----> l" unfolding convergent_def .  
himmelma@33175
  2213
qed
himmelma@33175
  2214
himmelma@33175
  2215
lemma complete_imp_closed: assumes "complete s" shows "closed s"
himmelma@33175
  2216
proof -
himmelma@33175
  2217
  { fix x assume "x islimpt s"
himmelma@33175
  2218
    then obtain f where f: "\<forall>n. f n \<in> s - {x}" "(f ---> x) sequentially"
himmelma@33175
  2219
      unfolding islimpt_sequential by auto
himmelma@33175
  2220
    then obtain l where l: "l\<in>s" "(f ---> l) sequentially"
himmelma@33175
  2221
      using `complete s`[unfolded complete_def] using convergent_imp_cauchy[of f x] by auto
hoelzl@41970
  2222
    hence "x \<in> s"  using tendsto_unique[of sequentially f l x] trivial_limit_sequentially f(2) by auto
himmelma@33175
  2223
  }
himmelma@33175
  2224
  thus "closed s" unfolding closed_limpt by auto
himmelma@33175
  2225
qed
himmelma@33175
  2226
himmelma@33175
  2227
lemma complete_eq_closed:
himmelma@33175
  2228
  fixes s :: "'a::complete_space set"
himmelma@33175
  2229
  shows "complete s \<longleftrightarrow> closed s" (is "?lhs = ?rhs")
himmelma@33175
  2230
proof
himmelma@33175
  2231
  assume ?lhs thus ?rhs by (rule complete_imp_closed)
himmelma@33175
  2232
next
himmelma@33175
  2233
  assume ?rhs
himmelma@33175
  2234
  { fix f assume as:"\<forall>n::nat. f n \<in> s" "Cauchy f"
himmelma@33175
  2235
    then obtain l where "(f ---> l) sequentially" using complete_univ[unfolded complete_def, THEN spec[where x=f]] by auto
himmelma@33175
  2236
    hence "\<exists>l\<in>s. (f ---> l) sequentially" using `?rhs`[unfolded closed_sequential_limits, THEN spec[where x=f], THEN spec[where x=l]] using as(1) by auto  }
himmelma@33175
  2237
  thus ?lhs unfolding complete_def by auto
himmelma@33175
  2238
qed
himmelma@33175
  2239
himmelma@33175
  2240
lemma convergent_eq_cauchy:
himmelma@33175
  2241
  fixes s :: "nat \<Rightarrow> 'a::complete_space"
huffman@44632
  2242
  shows "(\<exists>l. (s ---> l) sequentially) \<longleftrightarrow> Cauchy s"
huffman@44632
  2243
  unfolding Cauchy_convergent_iff convergent_def ..
himmelma@33175
  2244
himmelma@33175
  2245
lemma convergent_imp_bounded:
himmelma@33175
  2246
  fixes s :: "nat \<Rightarrow> 'a::metric_space"
huffman@44632
  2247
  shows "(s ---> l) sequentially \<Longrightarrow> bounded (range s)"
huffman@44632
  2248
  by (intro cauchy_imp_bounded convergent_imp_cauchy)
himmelma@33175
  2249
huffman@36437
  2250
subsubsection{* Total boundedness *}
himmelma@33175
  2251
himmelma@33175
  2252
fun helper_1::"('a::metric_space set) \<Rightarrow> real \<Rightarrow> nat \<Rightarrow> 'a" where
himmelma@33175
  2253
  "helper_1 s e n = (SOME y::'a. y \<in> s \<and> (\<forall>m<n. \<not> (dist (helper_1 s e m) y < e)))"
himmelma@33175
  2254
declare helper_1.simps[simp del]
himmelma@33175
  2255
himmelma@33175
  2256
lemma compact_imp_totally_bounded:
himmelma@33175
  2257
  assumes "compact s"
himmelma@33175
  2258
  shows "\<forall>e>0. \<exists>k. finite k \<and> k \<subseteq> s \<and> s \<subseteq> (\<Union>((\<lambda>x. ball x e) ` k))"
himmelma@33175
  2259
proof(rule, rule, rule ccontr)
himmelma@33175
  2260
  fix e::real assume "e>0" and assm:"\<not> (\<exists>k. finite k \<and> k \<subseteq> s \<and> s \<subseteq> \<Union>(\<lambda>x. ball x e) ` k)"
himmelma@33175
  2261