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