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