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