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