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