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