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