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