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