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