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