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