src/HOL/Analysis/Topology_Euclidean_Space.thy
author paulson <lp15@cam.ac.uk>
Fri Sep 08 15:27:22 2017 +0100 (20 months ago)
changeset 66643 f7e38b8583a0
parent 66641 ff2e0115fea4
child 66793 deabce3ccf1f
permissions -rw-r--r--
Correction of typos and a bit of streamlining
lp15@63938
     1
(*  Author:     L C Paulson, University of Cambridge
himmelma@33175
     2
    Author:     Amine Chaieb, University of Cambridge
himmelma@33175
     3
    Author:     Robert Himmelmann, TU Muenchen
huffman@44075
     4
    Author:     Brian Huffman, Portland State University
himmelma@33175
     5
*)
himmelma@33175
     6
wenzelm@60420
     7
section \<open>Elementary topology in Euclidean space.\<close>
himmelma@33175
     8
himmelma@33175
     9
theory Topology_Euclidean_Space
immler@50087
    10
imports
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
immler@50087
    16
begin
immler@50087
    17
hoelzl@63593
    18
(* FIXME: move elsewhere *)
lp15@63928
    19
lp15@64122
    20
lemma Times_eq_image_sum:
lp15@64122
    21
  fixes S :: "'a :: comm_monoid_add set" and T :: "'b :: comm_monoid_add set"
lp15@64122
    22
  shows "S \<times> T = {u + v |u v. u \<in> (\<lambda>x. (x, 0)) ` S \<and> v \<in> Pair 0 ` T}"
lp15@64122
    23
  by force
lp15@64122
    24
lp15@63967
    25
lemma halfspace_Int_eq:
lp15@63967
    26
     "{x. a \<bullet> x \<le> b} \<inter> {x. b \<le> a \<bullet> x} = {x. a \<bullet> x = b}"
lp15@63967
    27
     "{x. b \<le> a \<bullet> x} \<inter> {x. a \<bullet> x \<le> b} = {x. a \<bullet> x = b}"
lp15@63967
    28
  by auto
lp15@63967
    29
hoelzl@63593
    30
definition (in monoid_add) support_on :: "'b set \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'b set"
wenzelm@64539
    31
  where "support_on s f = {x\<in>s. f x \<noteq> 0}"
hoelzl@63593
    32
hoelzl@63593
    33
lemma in_support_on: "x \<in> support_on s f \<longleftrightarrow> x \<in> s \<and> f x \<noteq> 0"
hoelzl@63593
    34
  by (simp add: support_on_def)
hoelzl@63593
    35
hoelzl@63593
    36
lemma support_on_simps[simp]:
hoelzl@63593
    37
  "support_on {} f = {}"
hoelzl@63593
    38
  "support_on (insert x s) f =
hoelzl@63593
    39
    (if f x = 0 then support_on s f else insert x (support_on s f))"
hoelzl@63593
    40
  "support_on (s \<union> t) f = support_on s f \<union> support_on t f"
hoelzl@63593
    41
  "support_on (s \<inter> t) f = support_on s f \<inter> support_on t f"
hoelzl@63593
    42
  "support_on (s - t) f = support_on s f - support_on t f"
hoelzl@63593
    43
  "support_on (f ` s) g = f ` (support_on s (g \<circ> f))"
hoelzl@63593
    44
  unfolding support_on_def by auto
hoelzl@63593
    45
hoelzl@63593
    46
lemma support_on_cong:
hoelzl@63593
    47
  "(\<And>x. x \<in> s \<Longrightarrow> f x = 0 \<longleftrightarrow> g x = 0) \<Longrightarrow> support_on s f = support_on s g"
hoelzl@63593
    48
  by (auto simp: support_on_def)
hoelzl@63593
    49
hoelzl@63593
    50
lemma support_on_if: "a \<noteq> 0 \<Longrightarrow> support_on A (\<lambda>x. if P x then a else 0) = {x\<in>A. P x}"
hoelzl@63593
    51
  by (auto simp: support_on_def)
hoelzl@63593
    52
hoelzl@63593
    53
lemma support_on_if_subset: "support_on A (\<lambda>x. if P x then a else 0) \<subseteq> {x \<in> A. P x}"
hoelzl@63593
    54
  by (auto simp: support_on_def)
hoelzl@63593
    55
hoelzl@63593
    56
lemma finite_support[intro]: "finite s \<Longrightarrow> finite (support_on s f)"
hoelzl@63593
    57
  unfolding support_on_def by auto
hoelzl@63593
    58
nipkow@64267
    59
(* TODO: is supp_sum really needed? TODO: Generalize to Finite_Set.fold *)
nipkow@64267
    60
definition (in comm_monoid_add) supp_sum :: "('b \<Rightarrow> 'a) \<Rightarrow> 'b set \<Rightarrow> 'a"
wenzelm@64539
    61
  where "supp_sum f s = (\<Sum>x\<in>support_on s f. f x)"
nipkow@64267
    62
nipkow@64267
    63
lemma supp_sum_empty[simp]: "supp_sum f {} = 0"
nipkow@64267
    64
  unfolding supp_sum_def by auto
nipkow@64267
    65
nipkow@64267
    66
lemma supp_sum_insert[simp]:
hoelzl@63593
    67
  "finite (support_on s f) \<Longrightarrow>
nipkow@64267
    68
    supp_sum f (insert x s) = (if x \<in> s then supp_sum f s else f x + supp_sum f s)"
nipkow@64267
    69
  by (simp add: supp_sum_def in_support_on insert_absorb)
nipkow@64267
    70
nipkow@64267
    71
lemma supp_sum_divide_distrib: "supp_sum f A / (r::'a::field) = supp_sum (\<lambda>n. f n / r) A"
hoelzl@63593
    72
  by (cases "r = 0")
nipkow@64267
    73
     (auto simp: supp_sum_def sum_divide_distrib intro!: sum.cong support_on_cong)
lp15@63305
    74
lp15@63305
    75
(*END OF SUPPORT, ETC.*)
lp15@63305
    76
lp15@61738
    77
lemma image_affinity_interval:
lp15@61738
    78
  fixes c :: "'a::ordered_real_vector"
lp15@61738
    79
  shows "((\<lambda>x. m *\<^sub>R x + c) ` {a..b}) = (if {a..b}={} then {}
lp15@61738
    80
            else if 0 <= m then {m *\<^sub>R a + c .. m  *\<^sub>R b + c}
lp15@61738
    81
            else {m *\<^sub>R b + c .. m *\<^sub>R a + c})"
lp15@61738
    82
  apply (case_tac "m=0", force)
lp15@61738
    83
  apply (auto simp: scaleR_left_mono)
lp15@61738
    84
  apply (rule_tac x="inverse m *\<^sub>R (x-c)" in rev_image_eqI, auto simp: pos_le_divideR_eq le_diff_eq scaleR_left_mono_neg)
lp15@61738
    85
  apply (metis diff_le_eq inverse_inverse_eq order.not_eq_order_implies_strict pos_le_divideR_eq positive_imp_inverse_positive)
lp15@61738
    86
  apply (rule_tac x="inverse m *\<^sub>R (x-c)" in rev_image_eqI, auto simp: not_le neg_le_divideR_eq diff_le_eq)
lp15@61738
    87
  using le_diff_eq scaleR_le_cancel_left_neg
lp15@61738
    88
  apply fastforce
lp15@61738
    89
  done
lp15@61738
    90
wenzelm@53282
    91
lemma countable_PiE:
wenzelm@64910
    92
  "finite I \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> countable (F i)) \<Longrightarrow> countable (Pi\<^sub>E I F)"
hoelzl@50526
    93
  by (induct I arbitrary: F rule: finite_induct) (auto simp: PiE_insert_eq)
hoelzl@50526
    94
lp15@64845
    95
lemma open_sums:
lp15@64845
    96
  fixes T :: "('b::real_normed_vector) set"
lp15@64845
    97
  assumes "open S \<or> open T"
lp15@64845
    98
  shows "open (\<Union>x\<in> S. \<Union>y \<in> T. {x + y})"
lp15@64845
    99
  using assms
lp15@64845
   100
proof
lp15@64845
   101
  assume S: "open S"
lp15@64845
   102
  show ?thesis
lp15@64845
   103
  proof (clarsimp simp: open_dist)
lp15@64845
   104
    fix x y
lp15@64845
   105
    assume "x \<in> S" "y \<in> T"
lp15@64845
   106
    with S obtain e where "e > 0" and e: "\<And>x'. dist x' x < e \<Longrightarrow> x' \<in> S"
lp15@64845
   107
      by (auto simp: open_dist)
lp15@64845
   108
    then have "\<And>z. dist z (x + y) < e \<Longrightarrow> \<exists>x\<in>S. \<exists>y\<in>T. z = x + y"
lp15@64845
   109
      by (metis \<open>y \<in> T\<close> diff_add_cancel dist_add_cancel2)
lp15@64845
   110
    then show "\<exists>e>0. \<forall>z. dist z (x + y) < e \<longrightarrow> (\<exists>x\<in>S. \<exists>y\<in>T. z = x + y)"
lp15@64845
   111
      using \<open>0 < e\<close> \<open>x \<in> S\<close> by blast
lp15@64845
   112
  qed
lp15@64845
   113
next
lp15@64845
   114
  assume T: "open T"
lp15@64845
   115
  show ?thesis
lp15@64845
   116
  proof (clarsimp simp: open_dist)
lp15@64845
   117
    fix x y
lp15@64845
   118
    assume "x \<in> S" "y \<in> T"
lp15@64845
   119
    with T obtain e where "e > 0" and e: "\<And>x'. dist x' y < e \<Longrightarrow> x' \<in> T"
lp15@64845
   120
      by (auto simp: open_dist)
lp15@64845
   121
    then have "\<And>z. dist z (x + y) < e \<Longrightarrow> \<exists>x\<in>S. \<exists>y\<in>T. z = x + y"
lp15@64845
   122
      by (metis \<open>x \<in> S\<close> add_diff_cancel_left' add_diff_eq diff_diff_add dist_norm)
lp15@64845
   123
    then show "\<exists>e>0. \<forall>z. dist z (x + y) < e \<longrightarrow> (\<exists>x\<in>S. \<exists>y\<in>T. z = x + y)"
lp15@64845
   124
      using \<open>0 < e\<close> \<open>y \<in> T\<close> by blast
lp15@64845
   125
  qed
lp15@64845
   126
qed
lp15@64845
   127
wenzelm@53255
   128
wenzelm@60420
   129
subsection \<open>Topological Basis\<close>
immler@50087
   130
immler@50087
   131
context topological_space
immler@50087
   132
begin
immler@50087
   133
wenzelm@53291
   134
definition "topological_basis B \<longleftrightarrow>
wenzelm@53291
   135
  (\<forall>b\<in>B. open b) \<and> (\<forall>x. open x \<longrightarrow> (\<exists>B'. B' \<subseteq> B \<and> \<Union>B' = x))"
hoelzl@51343
   136
hoelzl@51343
   137
lemma topological_basis:
wenzelm@53291
   138
  "topological_basis B \<longleftrightarrow> (\<forall>x. open x \<longleftrightarrow> (\<exists>B'. B' \<subseteq> B \<and> \<Union>B' = x))"
hoelzl@50998
   139
  unfolding topological_basis_def
hoelzl@50998
   140
  apply safe
hoelzl@50998
   141
     apply fastforce
hoelzl@50998
   142
    apply fastforce
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"
himmelma@33175
   264
begin
himmelma@33175
   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
wenzelm@49711
   679
wenzelm@60420
   680
subsubsection \<open>Closed sets\<close>
himmelma@33175
   681
himmelma@33175
   682
definition "closedin U S \<longleftrightarrow> S \<subseteq> topspace U \<and> openin U (topspace U - S)"
himmelma@33175
   683
wenzelm@53255
   684
lemma closedin_subset: "closedin U S \<Longrightarrow> S \<subseteq> topspace U"
wenzelm@53255
   685
  by (metis closedin_def)
wenzelm@53255
   686
wenzelm@53255
   687
lemma closedin_empty[simp]: "closedin U {}"
wenzelm@53255
   688
  by (simp add: closedin_def)
wenzelm@53255
   689
wenzelm@53255
   690
lemma closedin_topspace[intro, simp]: "closedin U (topspace U)"
wenzelm@53255
   691
  by (simp add: closedin_def)
wenzelm@53255
   692
himmelma@33175
   693
lemma closedin_Un[intro]: "closedin U S \<Longrightarrow> closedin U T \<Longrightarrow> closedin U (S \<union> T)"
lp15@66643
   694
  by (auto simp: Diff_Un closedin_def)
himmelma@33175
   695
wenzelm@60585
   696
lemma Diff_Inter[intro]: "A - \<Inter>S = \<Union>{A - s|s. s\<in>S}"
wenzelm@53255
   697
  by auto
wenzelm@53255
   698
lp15@63955
   699
lemma closedin_Union:
lp15@63955
   700
  assumes "finite S" "\<And>T. T \<in> S \<Longrightarrow> closedin U T"
lp15@63955
   701
    shows "closedin U (\<Union>S)"
lp15@63955
   702
  using assms by induction auto
lp15@63955
   703
wenzelm@53255
   704
lemma closedin_Inter[intro]:
wenzelm@53255
   705
  assumes Ke: "K \<noteq> {}"
paulson@62131
   706
    and Kc: "\<And>S. S \<in>K \<Longrightarrow> closedin U S"
wenzelm@60585
   707
  shows "closedin U (\<Inter>K)"
wenzelm@53255
   708
  using Ke Kc unfolding closedin_def Diff_Inter by auto
himmelma@33175
   709
paulson@62131
   710
lemma closedin_INT[intro]:
paulson@62131
   711
  assumes "A \<noteq> {}" "\<And>x. x \<in> A \<Longrightarrow> closedin U (B x)"
paulson@62131
   712
  shows "closedin U (\<Inter>x\<in>A. B x)"
paulson@62131
   713
  apply (rule closedin_Inter)
paulson@62131
   714
  using assms
paulson@62131
   715
  apply auto
paulson@62131
   716
  done
paulson@62131
   717
himmelma@33175
   718
lemma closedin_Int[intro]: "closedin U S \<Longrightarrow> closedin U T \<Longrightarrow> closedin U (S \<inter> T)"
himmelma@33175
   719
  using closedin_Inter[of "{S,T}" U] by auto
himmelma@33175
   720
himmelma@33175
   721
lemma openin_closedin_eq: "openin U S \<longleftrightarrow> S \<subseteq> topspace U \<and> closedin U (topspace U - S)"
lp15@66643
   722
  apply (auto simp: closedin_def Diff_Diff_Int inf_absorb2)
himmelma@33175
   723
  apply (metis openin_subset subset_eq)
himmelma@33175
   724
  done
himmelma@33175
   725
wenzelm@53255
   726
lemma openin_closedin: "S \<subseteq> topspace U \<Longrightarrow> (openin U S \<longleftrightarrow> closedin U (topspace U - S))"
himmelma@33175
   727
  by (simp add: openin_closedin_eq)
himmelma@33175
   728
wenzelm@53255
   729
lemma openin_diff[intro]:
wenzelm@53255
   730
  assumes oS: "openin U S"
wenzelm@53255
   731
    and cT: "closedin U T"
wenzelm@53255
   732
  shows "openin U (S - T)"
wenzelm@53255
   733
proof -
himmelma@33175
   734
  have "S - T = S \<inter> (topspace U - T)" using openin_subset[of U S]  oS cT
lp15@66643
   735
    by (auto simp: topspace_def openin_subset)
wenzelm@53282
   736
  then show ?thesis using oS cT
lp15@66643
   737
    by (auto simp: closedin_def)
himmelma@33175
   738
qed
himmelma@33175
   739
wenzelm@53255
   740
lemma closedin_diff[intro]:
wenzelm@53255
   741
  assumes oS: "closedin U S"
wenzelm@53255
   742
    and cT: "openin U T"
wenzelm@53255
   743
  shows "closedin U (S - T)"
wenzelm@53255
   744
proof -
wenzelm@53255
   745
  have "S - T = S \<inter> (topspace U - T)"
lp15@66643
   746
    using closedin_subset[of U S] oS cT by (auto simp: topspace_def)
wenzelm@53255
   747
  then show ?thesis
lp15@66643
   748
    using oS cT by (auto simp: openin_closedin_eq)
wenzelm@53255
   749
qed
wenzelm@53255
   750
himmelma@33175
   751
wenzelm@60420
   752
subsubsection \<open>Subspace topology\<close>
huffman@44170
   753
huffman@44170
   754
definition "subtopology U V = topology (\<lambda>T. \<exists>S. T = S \<inter> V \<and> openin U S)"
huffman@44170
   755
huffman@44170
   756
lemma istopology_subtopology: "istopology (\<lambda>T. \<exists>S. T = S \<inter> V \<and> openin U S)"
huffman@44170
   757
  (is "istopology ?L")
wenzelm@53255
   758
proof -
huffman@44170
   759
  have "?L {}" by blast
wenzelm@53255
   760
  {
wenzelm@53255
   761
    fix A B
wenzelm@53255
   762
    assume A: "?L A" and B: "?L B"
wenzelm@53255
   763
    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
   764
      by blast
wenzelm@53255
   765
    have "A \<inter> B = (Sa \<inter> Sb) \<inter> V" "openin U (Sa \<inter> Sb)"
wenzelm@53255
   766
      using Sa Sb by blast+
wenzelm@53255
   767
    then have "?L (A \<inter> B)" by blast
wenzelm@53255
   768
  }
himmelma@33175
   769
  moreover
wenzelm@53255
   770
  {
wenzelm@53282
   771
    fix K
wenzelm@53282
   772
    assume K: "K \<subseteq> Collect ?L"
huffman@44170
   773
    have th0: "Collect ?L = (\<lambda>S. S \<inter> V) ` Collect (openin U)"
lp15@55775
   774
      by blast
himmelma@33175
   775
    from K[unfolded th0 subset_image_iff]
wenzelm@53255
   776
    obtain Sk where Sk: "Sk \<subseteq> Collect (openin U)" "K = (\<lambda>S. S \<inter> V) ` Sk"
wenzelm@53255
   777
      by blast
wenzelm@53255
   778
    have "\<Union>K = (\<Union>Sk) \<inter> V"
wenzelm@53255
   779
      using Sk by auto
wenzelm@60585
   780
    moreover have "openin U (\<Union>Sk)"
lp15@66643
   781
      using Sk by (auto simp: subset_eq)
wenzelm@53255
   782
    ultimately have "?L (\<Union>K)" by blast
wenzelm@53255
   783
  }
huffman@44170
   784
  ultimately show ?thesis
haftmann@62343
   785
    unfolding subset_eq mem_Collect_eq istopology_def by auto
himmelma@33175
   786
qed
himmelma@33175
   787
wenzelm@53255
   788
lemma openin_subtopology: "openin (subtopology U V) S \<longleftrightarrow> (\<exists>T. openin U T \<and> S = T \<inter> V)"
himmelma@33175
   789
  unfolding subtopology_def topology_inverse'[OF istopology_subtopology]
huffman@44170
   790
  by auto
himmelma@33175
   791
wenzelm@53255
   792
lemma topspace_subtopology: "topspace (subtopology U V) = topspace U \<inter> V"
lp15@66643
   793
  by (auto simp: topspace_def openin_subtopology)
himmelma@33175
   794
wenzelm@53255
   795
lemma closedin_subtopology: "closedin (subtopology U V) S \<longleftrightarrow> (\<exists>T. closedin U T \<and> S = T \<inter> V)"
himmelma@33175
   796
  unfolding closedin_def topspace_subtopology
lp15@66643
   797
  by (auto simp: openin_subtopology)
himmelma@33175
   798
himmelma@33175
   799
lemma openin_subtopology_refl: "openin (subtopology U V) V \<longleftrightarrow> V \<subseteq> topspace U"
himmelma@33175
   800
  unfolding openin_subtopology
lp15@55775
   801
  by auto (metis IntD1 in_mono openin_subset)
wenzelm@49711
   802
wenzelm@49711
   803
lemma subtopology_superset:
wenzelm@49711
   804
  assumes UV: "topspace U \<subseteq> V"
himmelma@33175
   805
  shows "subtopology U V = U"
wenzelm@53255
   806
proof -
wenzelm@53255
   807
  {
wenzelm@53255
   808
    fix S
wenzelm@53255
   809
    {
wenzelm@53255
   810
      fix T
wenzelm@53255
   811
      assume T: "openin U T" "S = T \<inter> V"
wenzelm@53255
   812
      from T openin_subset[OF T(1)] UV have eq: "S = T"
wenzelm@53255
   813
        by blast
wenzelm@53255
   814
      have "openin U S"
wenzelm@53255
   815
        unfolding eq using T by blast
wenzelm@53255
   816
    }
himmelma@33175
   817
    moreover
wenzelm@53255
   818
    {
wenzelm@53255
   819
      assume S: "openin U S"
wenzelm@53255
   820
      then have "\<exists>T. openin U T \<and> S = T \<inter> V"
wenzelm@53255
   821
        using openin_subset[OF S] UV by auto
wenzelm@53255
   822
    }
wenzelm@53255
   823
    ultimately have "(\<exists>T. openin U T \<and> S = T \<inter> V) \<longleftrightarrow> openin U S"
wenzelm@53255
   824
      by blast
wenzelm@53255
   825
  }
wenzelm@53255
   826
  then show ?thesis
wenzelm@53255
   827
    unfolding topology_eq openin_subtopology by blast
himmelma@33175
   828
qed
himmelma@33175
   829
himmelma@33175
   830
lemma subtopology_topspace[simp]: "subtopology U (topspace U) = U"
himmelma@33175
   831
  by (simp add: subtopology_superset)
himmelma@33175
   832
himmelma@33175
   833
lemma subtopology_UNIV[simp]: "subtopology U UNIV = U"
himmelma@33175
   834
  by (simp add: subtopology_superset)
himmelma@33175
   835
lp15@62948
   836
lemma openin_subtopology_empty:
lp15@64758
   837
   "openin (subtopology U {}) S \<longleftrightarrow> S = {}"
lp15@62948
   838
by (metis Int_empty_right openin_empty openin_subtopology)
lp15@62948
   839
lp15@62948
   840
lemma closedin_subtopology_empty:
lp15@64758
   841
   "closedin (subtopology U {}) S \<longleftrightarrow> S = {}"
lp15@62948
   842
by (metis Int_empty_right closedin_empty closedin_subtopology)
lp15@62948
   843
lp15@64758
   844
lemma closedin_subtopology_refl [simp]:
lp15@64758
   845
   "closedin (subtopology U X) X \<longleftrightarrow> X \<subseteq> topspace U"
lp15@62948
   846
by (metis closedin_def closedin_topspace inf.absorb_iff2 le_inf_iff topspace_subtopology)
lp15@62948
   847
lp15@62948
   848
lemma openin_imp_subset:
lp15@64758
   849
   "openin (subtopology U S) T \<Longrightarrow> T \<subseteq> S"
lp15@62948
   850
by (metis Int_iff openin_subtopology subsetI)
lp15@62948
   851
lp15@62948
   852
lemma closedin_imp_subset:
lp15@64758
   853
   "closedin (subtopology U S) T \<Longrightarrow> T \<subseteq> S"
lp15@62948
   854
by (simp add: closedin_def topspace_subtopology)
lp15@62948
   855
lp15@62948
   856
lemma openin_subtopology_Un:
lp15@64758
   857
    "openin (subtopology U T) S \<and> openin (subtopology U u) S
lp15@64758
   858
     \<Longrightarrow> openin (subtopology U (T \<union> u)) S"
lp15@62948
   859
by (simp add: openin_subtopology) blast
lp15@62948
   860
wenzelm@53255
   861
wenzelm@60420
   862
subsubsection \<open>The standard Euclidean topology\<close>
himmelma@33175
   863
wenzelm@53255
   864
definition euclidean :: "'a::topological_space topology"
wenzelm@53255
   865
  where "euclidean = topology open"
himmelma@33175
   866
himmelma@33175
   867
lemma open_openin: "open S \<longleftrightarrow> openin euclidean S"
himmelma@33175
   868
  unfolding euclidean_def
himmelma@33175
   869
  apply (rule cong[where x=S and y=S])
himmelma@33175
   870
  apply (rule topology_inverse[symmetric])
lp15@66643
   871
  apply (auto simp: istopology_def)
huffman@44170
   872
  done
himmelma@33175
   873
lp15@64122
   874
declare open_openin [symmetric, simp]
lp15@64122
   875
lp15@63492
   876
lemma topspace_euclidean [simp]: "topspace euclidean = UNIV"
lp15@66643
   877
  by (force simp: topspace_def)
himmelma@33175
   878
himmelma@33175
   879
lemma topspace_euclidean_subtopology[simp]: "topspace (subtopology euclidean S) = S"
lp15@64122
   880
  by (simp add: topspace_subtopology)
himmelma@33175
   881
himmelma@33175
   882
lemma closed_closedin: "closed S \<longleftrightarrow> closedin euclidean S"
lp15@64122
   883
  by (simp add: closed_def closedin_def Compl_eq_Diff_UNIV)
himmelma@33175
   884
himmelma@33175
   885
lemma open_subopen: "open S \<longleftrightarrow> (\<forall>x\<in>S. \<exists>T. open T \<and> x \<in> T \<and> T \<subseteq> S)"
lp15@64122
   886
  using openI by auto
himmelma@33175
   887
lp15@62948
   888
lemma openin_subtopology_self [simp]: "openin (subtopology euclidean S) S"
lp15@62948
   889
  by (metis openin_topspace topspace_euclidean_subtopology)
lp15@62948
   890
wenzelm@60420
   891
text \<open>Basic "localization" results are handy for connectedness.\<close>
huffman@44210
   892
huffman@44210
   893
lemma openin_open: "openin (subtopology euclidean U) S \<longleftrightarrow> (\<exists>T. open T \<and> (S = U \<inter> T))"
lp15@66643
   894
  by (auto simp: openin_subtopology)
huffman@44210
   895
lp15@63305
   896
lemma openin_Int_open:
lp15@63305
   897
   "\<lbrakk>openin (subtopology euclidean U) S; open T\<rbrakk>
lp15@63305
   898
        \<Longrightarrow> openin (subtopology euclidean U) (S \<inter> T)"
lp15@63305
   899
by (metis open_Int Int_assoc openin_open)
lp15@63305
   900
huffman@44210
   901
lemma openin_open_Int[intro]: "open S \<Longrightarrow> openin (subtopology euclidean U) (U \<inter> S)"
lp15@66643
   902
  by (auto simp: openin_open)
huffman@44210
   903
huffman@44210
   904
lemma open_openin_trans[trans]:
wenzelm@53255
   905
  "open S \<Longrightarrow> open T \<Longrightarrow> T \<subseteq> S \<Longrightarrow> openin (subtopology euclidean S) T"
huffman@44210
   906
  by (metis Int_absorb1  openin_open_Int)
huffman@44210
   907
wenzelm@53255
   908
lemma open_subset: "S \<subseteq> T \<Longrightarrow> open S \<Longrightarrow> openin (subtopology euclidean T) S"
lp15@66643
   909
  by (auto simp: openin_open)
huffman@44210
   910
huffman@44210
   911
lemma closedin_closed: "closedin (subtopology euclidean U) S \<longleftrightarrow> (\<exists>T. closed T \<and> S = U \<inter> T)"
huffman@44210
   912
  by (simp add: closedin_subtopology closed_closedin Int_ac)
huffman@44210
   913
wenzelm@53291
   914
lemma closedin_closed_Int: "closed S \<Longrightarrow> closedin (subtopology euclidean U) (U \<inter> S)"
huffman@44210
   915
  by (metis closedin_closed)
huffman@44210
   916
huffman@44210
   917
lemma closed_subset: "S \<subseteq> T \<Longrightarrow> closed S \<Longrightarrow> closedin (subtopology euclidean T) S"
lp15@66643
   918
  by (auto simp: closedin_closed)
huffman@44210
   919
lp15@64791
   920
lemma closedin_closed_subset:
lp15@64791
   921
 "\<lbrakk>closedin (subtopology euclidean U) V; T \<subseteq> U; S = V \<inter> T\<rbrakk>
lp15@64791
   922
             \<Longrightarrow> closedin (subtopology euclidean T) S"
lp15@64791
   923
  by (metis (no_types, lifting) Int_assoc Int_commute closedin_closed inf.orderE)
lp15@64791
   924
lp15@63928
   925
lemma finite_imp_closedin:
lp15@63928
   926
  fixes S :: "'a::t1_space set"
lp15@63928
   927
  shows "\<lbrakk>finite S; S \<subseteq> T\<rbrakk> \<Longrightarrow> closedin (subtopology euclidean T) S"
lp15@63928
   928
    by (simp add: finite_imp_closed closed_subset)
lp15@63928
   929
lp15@63305
   930
lemma closedin_singleton [simp]:
lp15@63305
   931
  fixes a :: "'a::t1_space"
lp15@63305
   932
  shows "closedin (subtopology euclidean U) {a} \<longleftrightarrow> a \<in> U"
lp15@63305
   933
using closedin_subset  by (force intro: closed_subset)
lp15@63305
   934
huffman@44210
   935
lemma openin_euclidean_subtopology_iff:
huffman@44210
   936
  fixes S U :: "'a::metric_space set"
wenzelm@53255
   937
  shows "openin (subtopology euclidean U) S \<longleftrightarrow>
wenzelm@53255
   938
    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
   939
  (is "?lhs \<longleftrightarrow> ?rhs")
huffman@44210
   940
proof
wenzelm@53255
   941
  assume ?lhs
wenzelm@53282
   942
  then show ?rhs
wenzelm@53282
   943
    unfolding openin_open open_dist by blast
huffman@44210
   944
next
wenzelm@63040
   945
  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
   946
  have 1: "\<forall>x\<in>T. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> T"
huffman@44210
   947
    unfolding T_def
huffman@44210
   948
    apply clarsimp
huffman@44210
   949
    apply (rule_tac x="d - dist x a" in exI)
huffman@44210
   950
    apply (clarsimp simp add: less_diff_eq)
lp15@55775
   951
    by (metis dist_commute dist_triangle_lt)
wenzelm@53282
   952
  assume ?rhs then have 2: "S = U \<inter> T"
lp15@60141
   953
    unfolding T_def
lp15@55775
   954
    by auto (metis dist_self)
huffman@44210
   955
  from 1 2 show ?lhs
huffman@44210
   956
    unfolding openin_open open_dist by fast
huffman@44210
   957
qed
lp15@61609
   958
lp15@62843
   959
lemma connected_openin:
lp15@61306
   960
      "connected s \<longleftrightarrow>
lp15@61306
   961
       ~(\<exists>e1 e2. openin (subtopology euclidean s) e1 \<and>
lp15@61306
   962
                 openin (subtopology euclidean s) e2 \<and>
lp15@61306
   963
                 s \<subseteq> e1 \<union> e2 \<and> e1 \<inter> e2 = {} \<and> e1 \<noteq> {} \<and> e2 \<noteq> {})"
lp15@61306
   964
  apply (simp add: connected_def openin_open, safe)
wenzelm@63988
   965
  apply (simp_all, blast+)  (* SLOW *)
lp15@61306
   966
  done
lp15@61306
   967
lp15@62843
   968
lemma connected_openin_eq:
lp15@61306
   969
      "connected s \<longleftrightarrow>
lp15@61306
   970
       ~(\<exists>e1 e2. openin (subtopology euclidean s) e1 \<and>
lp15@61306
   971
                 openin (subtopology euclidean s) e2 \<and>
lp15@61306
   972
                 e1 \<union> e2 = s \<and> e1 \<inter> e2 = {} \<and>
lp15@61306
   973
                 e1 \<noteq> {} \<and> e2 \<noteq> {})"
lp15@66643
   974
  apply (simp add: connected_openin, safe, blast)
lp15@61306
   975
  by (metis Int_lower1 Un_subset_iff openin_open subset_antisym)
lp15@61306
   976
lp15@62843
   977
lemma connected_closedin:
lp15@61306
   978
      "connected s \<longleftrightarrow>
lp15@61306
   979
       ~(\<exists>e1 e2.
lp15@61306
   980
             closedin (subtopology euclidean s) e1 \<and>
lp15@61306
   981
             closedin (subtopology euclidean s) e2 \<and>
lp15@61306
   982
             s \<subseteq> e1 \<union> e2 \<and> e1 \<inter> e2 = {} \<and>
lp15@61306
   983
             e1 \<noteq> {} \<and> e2 \<noteq> {})"
lp15@61306
   984
proof -
lp15@61306
   985
  { fix A B x x'
lp15@61306
   986
    assume s_sub: "s \<subseteq> A \<union> B"
lp15@61306
   987
       and disj: "A \<inter> B \<inter> s = {}"
lp15@61306
   988
       and x: "x \<in> s" "x \<in> B" and x': "x' \<in> s" "x' \<in> A"
lp15@61306
   989
       and cl: "closed A" "closed B"
lp15@61306
   990
    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
   991
    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
   992
      by (metis (no_types) Int_Un_distrib Int_assoc)
lp15@61306
   993
    moreover have "s \<inter> (A \<inter> B) = {}" "s \<inter> (A \<union> B) = s" "s \<inter> B \<noteq> {}"
lp15@61306
   994
      using disj s_sub x by blast+
lp15@61306
   995
    ultimately have "s \<inter> A = {}"
lp15@61306
   996
      using cl by (metis inf.left_commute inf_bot_right order_refl)
lp15@61306
   997
    then have False
lp15@61306
   998
      using x' by blast
lp15@61306
   999
  } note * = this
lp15@61306
  1000
  show ?thesis
lp15@61306
  1001
    apply (simp add: connected_closed closedin_closed)
lp15@61306
  1002
    apply (safe; simp)
lp15@61306
  1003
    apply blast
lp15@61306
  1004
    apply (blast intro: *)
lp15@61306
  1005
    done
lp15@61306
  1006
qed
lp15@61306
  1007
lp15@62843
  1008
lemma connected_closedin_eq:
lp15@61306
  1009
      "connected s \<longleftrightarrow>
lp15@61306
  1010
           ~(\<exists>e1 e2.
lp15@61306
  1011
                 closedin (subtopology euclidean s) e1 \<and>
lp15@61306
  1012
                 closedin (subtopology euclidean s) e2 \<and>
lp15@61306
  1013
                 e1 \<union> e2 = s \<and> e1 \<inter> e2 = {} \<and>
lp15@61306
  1014
                 e1 \<noteq> {} \<and> e2 \<noteq> {})"
lp15@66643
  1015
  apply (simp add: connected_closedin, safe, blast)
lp15@61306
  1016
  by (metis Int_lower1 Un_subset_iff closedin_closed subset_antisym)
lp15@61609
  1017
wenzelm@60420
  1018
text \<open>These "transitivity" results are handy too\<close>
huffman@44210
  1019
wenzelm@53255
  1020
lemma openin_trans[trans]:
wenzelm@53255
  1021
  "openin (subtopology euclidean T) S \<Longrightarrow> openin (subtopology euclidean U) T \<Longrightarrow>
wenzelm@53255
  1022
    openin (subtopology euclidean U) S"
huffman@44210
  1023
  unfolding open_openin openin_open by blast
huffman@44210
  1024
huffman@44210
  1025
lemma openin_open_trans: "openin (subtopology euclidean T) S \<Longrightarrow> open T \<Longrightarrow> open S"
lp15@66643
  1026
  by (auto simp: openin_open intro: openin_trans)
huffman@44210
  1027
huffman@44210
  1028
lemma closedin_trans[trans]:
wenzelm@53255
  1029
  "closedin (subtopology euclidean T) S \<Longrightarrow> closedin (subtopology euclidean U) T \<Longrightarrow>
wenzelm@53255
  1030
    closedin (subtopology euclidean U) S"
lp15@66643
  1031
  by (auto simp: closedin_closed closed_closedin closed_Inter Int_assoc)
huffman@44210
  1032
huffman@44210
  1033
lemma closedin_closed_trans: "closedin (subtopology euclidean T) S \<Longrightarrow> closed T \<Longrightarrow> closed S"
lp15@66643
  1034
  by (auto simp: closedin_closed intro: closedin_trans)
huffman@44210
  1035
lp15@62843
  1036
lemma openin_subtopology_Int_subset:
lp15@62843
  1037
   "\<lbrakk>openin (subtopology euclidean u) (u \<inter> S); v \<subseteq> u\<rbrakk> \<Longrightarrow> openin (subtopology euclidean v) (v \<inter> S)"
paulson@61518
  1038
  by (auto simp: openin_subtopology)
paulson@61518
  1039
paulson@61518
  1040
lemma openin_open_eq: "open s \<Longrightarrow> (openin (subtopology euclidean s) t \<longleftrightarrow> open t \<and> t \<subseteq> s)"
paulson@61518
  1041
  using open_subset openin_open_trans openin_subset by fastforce
paulson@61518
  1042
huffman@44210
  1043
wenzelm@60420
  1044
subsection \<open>Open and closed balls\<close>
himmelma@33175
  1045
wenzelm@53255
  1046
definition ball :: "'a::metric_space \<Rightarrow> real \<Rightarrow> 'a set"
wenzelm@53255
  1047
  where "ball x e = {y. dist x y < e}"
wenzelm@53255
  1048
wenzelm@53255
  1049
definition cball :: "'a::metric_space \<Rightarrow> real \<Rightarrow> 'a set"
wenzelm@53255
  1050
  where "cball x e = {y. dist x y \<le> e}"
himmelma@33175
  1051
lp15@61762
  1052
definition sphere :: "'a::metric_space \<Rightarrow> real \<Rightarrow> 'a set"
lp15@61762
  1053
  where "sphere x e = {y. dist x y = e}"
lp15@61762
  1054
huffman@45776
  1055
lemma mem_ball [simp]: "y \<in> ball x e \<longleftrightarrow> dist x y < e"
huffman@45776
  1056
  by (simp add: ball_def)
huffman@45776
  1057
huffman@45776
  1058
lemma mem_cball [simp]: "y \<in> cball x e \<longleftrightarrow> dist x y \<le> e"
huffman@45776
  1059
  by (simp add: cball_def)
huffman@45776
  1060
lp15@61848
  1061
lemma mem_sphere [simp]: "y \<in> sphere x e \<longleftrightarrow> dist x y = e"
lp15@61848
  1062
  by (simp add: sphere_def)
lp15@61848
  1063
paulson@61518
  1064
lemma ball_trivial [simp]: "ball x 0 = {}"
paulson@61518
  1065
  by (simp add: ball_def)
paulson@61518
  1066
paulson@61518
  1067
lemma cball_trivial [simp]: "cball x 0 = {x}"
paulson@61518
  1068
  by (simp add: cball_def)
paulson@61518
  1069
lp15@63469
  1070
lemma sphere_trivial [simp]: "sphere x 0 = {x}"
lp15@63469
  1071
  by (simp add: sphere_def)
lp15@63469
  1072
wenzelm@64539
  1073
lemma mem_ball_0 [simp]: "x \<in> ball 0 e \<longleftrightarrow> norm x < e"
wenzelm@64539
  1074
  for x :: "'a::real_normed_vector"
himmelma@33175
  1075
  by (simp add: dist_norm)
himmelma@33175
  1076
wenzelm@64539
  1077
lemma mem_cball_0 [simp]: "x \<in> cball 0 e \<longleftrightarrow> norm x \<le> e"
wenzelm@64539
  1078
  for x :: "'a::real_normed_vector"
himmelma@33175
  1079
  by (simp add: dist_norm)
himmelma@33175
  1080
wenzelm@64539
  1081
lemma disjoint_ballI: "dist x y \<ge> r+s \<Longrightarrow> ball x r \<inter> ball y s = {}"
lp15@64287
  1082
  using dist_triangle_less_add not_le by fastforce
lp15@64287
  1083
wenzelm@64539
  1084
lemma disjoint_cballI: "dist x y > r + s \<Longrightarrow> cball x r \<inter> cball y s = {}"
lp15@64287
  1085
  by (metis add_mono disjoint_iff_not_equal dist_triangle2 dual_order.trans leD mem_cball)
lp15@64287
  1086
wenzelm@64539
  1087
lemma mem_sphere_0 [simp]: "x \<in> sphere 0 e \<longleftrightarrow> norm x = e"
wenzelm@64539
  1088
  for x :: "'a::real_normed_vector"
lp15@63114
  1089
  by (simp add: dist_norm)
lp15@63114
  1090
wenzelm@64539
  1091
lemma sphere_empty [simp]: "r < 0 \<Longrightarrow> sphere a r = {}"
wenzelm@64539
  1092
  for a :: "'a::metric_space"
wenzelm@64539
  1093
  by auto
lp15@63881
  1094
paulson@61518
  1095
lemma centre_in_ball [simp]: "x \<in> ball x e \<longleftrightarrow> 0 < e"
huffman@45776
  1096
  by simp
huffman@45776
  1097
paulson@61518
  1098
lemma centre_in_cball [simp]: "x \<in> cball x e \<longleftrightarrow> 0 \<le> e"
huffman@45776
  1099
  by simp
huffman@45776
  1100
wenzelm@64539
  1101
lemma ball_subset_cball [simp, intro]: "ball x e \<subseteq> cball x e"
wenzelm@53255
  1102
  by (simp add: subset_eq)
wenzelm@53255
  1103
lp15@61907
  1104
lemma sphere_cball [simp,intro]: "sphere z r \<subseteq> cball z r"
lp15@61907
  1105
  by force
lp15@61907
  1106
lp15@64758
  1107
lemma cball_diff_sphere: "cball a r - sphere a r = ball a r"
lp15@64758
  1108
  by auto
lp15@64758
  1109
wenzelm@53282
  1110
lemma subset_ball[intro]: "d \<le> e \<Longrightarrow> ball x d \<subseteq> ball x e"
wenzelm@53255
  1111
  by (simp add: subset_eq)
wenzelm@53255
  1112
wenzelm@53282
  1113
lemma subset_cball[intro]: "d \<le> e \<Longrightarrow> cball x d \<subseteq> cball x e"
wenzelm@53255
  1114
  by (simp add: subset_eq)
wenzelm@53255
  1115
himmelma@33175
  1116
lemma ball_max_Un: "ball a (max r s) = ball a r \<union> ball a s"
nipkow@39302
  1117
  by (simp add: set_eq_iff) arith
himmelma@33175
  1118
himmelma@33175
  1119
lemma ball_min_Int: "ball a (min r s) = ball a r \<inter> ball a s"
nipkow@39302
  1120
  by (simp add: set_eq_iff)
himmelma@33175
  1121
lp15@64758
  1122
lemma cball_max_Un: "cball a (max r s) = cball a r \<union> cball a s"
lp15@64758
  1123
  by (simp add: set_eq_iff) arith
lp15@64758
  1124
lp15@64758
  1125
lemma cball_min_Int: "cball a (min r s) = cball a r \<inter> cball a s"
lp15@64758
  1126
  by (simp add: set_eq_iff)
lp15@64758
  1127
lp15@64788
  1128
lemma cball_diff_eq_sphere: "cball a r - ball a r =  sphere a r"
lp15@61426
  1129
  by (auto simp: cball_def ball_def dist_commute)
lp15@61426
  1130
lp15@62533
  1131
lemma image_add_ball [simp]:
lp15@62533
  1132
  fixes a :: "'a::real_normed_vector"
lp15@62533
  1133
  shows "op + b ` ball a r = ball (a+b) r"
lp15@62533
  1134
apply (intro equalityI subsetI)
lp15@62533
  1135
apply (force simp: dist_norm)
lp15@62533
  1136
apply (rule_tac x="x-b" in image_eqI)
lp15@62533
  1137
apply (auto simp: dist_norm algebra_simps)
lp15@62533
  1138
done
lp15@62533
  1139
lp15@62533
  1140
lemma image_add_cball [simp]:
lp15@62533
  1141
  fixes a :: "'a::real_normed_vector"
lp15@62533
  1142
  shows "op + b ` cball a r = cball (a+b) r"
lp15@62533
  1143
apply (intro equalityI subsetI)
lp15@62533
  1144
apply (force simp: dist_norm)
lp15@62533
  1145
apply (rule_tac x="x-b" in image_eqI)
lp15@62533
  1146
apply (auto simp: dist_norm algebra_simps)
lp15@62533
  1147
done
lp15@62533
  1148
huffman@54070
  1149
lemma open_ball [intro, simp]: "open (ball x e)"
huffman@54070
  1150
proof -
huffman@54070
  1151
  have "open (dist x -` {..<e})"
hoelzl@56371
  1152
    by (intro open_vimage open_lessThan continuous_intros)
huffman@54070
  1153
  also have "dist x -` {..<e} = ball x e"
huffman@54070
  1154
    by auto
huffman@54070
  1155
  finally show ?thesis .
huffman@54070
  1156
qed
himmelma@33175
  1157
himmelma@33175
  1158
lemma open_contains_ball: "open S \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0. ball x e \<subseteq> S)"
wenzelm@63170
  1159
  by (simp add: open_dist subset_eq mem_ball Ball_def dist_commute)
himmelma@33175
  1160
lp15@62381
  1161
lemma openI [intro?]: "(\<And>x. x\<in>S \<Longrightarrow> \<exists>e>0. ball x e \<subseteq> S) \<Longrightarrow> open S"
lp15@62381
  1162
  by (auto simp: open_contains_ball)
lp15@62381
  1163
hoelzl@33714
  1164
lemma openE[elim?]:
wenzelm@53282
  1165
  assumes "open S" "x\<in>S"
hoelzl@33714
  1166
  obtains e where "e>0" "ball x e \<subseteq> S"
hoelzl@33714
  1167
  using assms unfolding open_contains_ball by auto
hoelzl@33714
  1168
lp15@62381
  1169
lemma open_contains_ball_eq: "open S \<Longrightarrow> x\<in>S \<longleftrightarrow> (\<exists>e>0. ball x e \<subseteq> S)"
himmelma@33175
  1170
  by (metis open_contains_ball subset_eq centre_in_ball)
himmelma@33175
  1171
lp15@62843
  1172
lemma openin_contains_ball:
lp15@62843
  1173
    "openin (subtopology euclidean t) s \<longleftrightarrow>
lp15@62843
  1174
     s \<subseteq> t \<and> (\<forall>x \<in> s. \<exists>e. 0 < e \<and> ball x e \<inter> t \<subseteq> s)"
lp15@62843
  1175
    (is "?lhs = ?rhs")
lp15@62843
  1176
proof
lp15@62843
  1177
  assume ?lhs
lp15@62843
  1178
  then show ?rhs
lp15@62843
  1179
    apply (simp add: openin_open)
lp15@62843
  1180
    apply (metis Int_commute Int_mono inf.cobounded2 open_contains_ball order_refl subsetCE)
lp15@62843
  1181
    done
lp15@62843
  1182
next
lp15@62843
  1183
  assume ?rhs
lp15@62843
  1184
  then show ?lhs
lp15@62843
  1185
    apply (simp add: openin_euclidean_subtopology_iff)
lp15@62843
  1186
    by (metis (no_types) Int_iff dist_commute inf.absorb_iff2 mem_ball)
lp15@62843
  1187
qed
lp15@62843
  1188
lp15@62843
  1189
lemma openin_contains_cball:
lp15@62843
  1190
   "openin (subtopology euclidean t) s \<longleftrightarrow>
lp15@62843
  1191
        s \<subseteq> t \<and>
lp15@62843
  1192
        (\<forall>x \<in> s. \<exists>e. 0 < e \<and> cball x e \<inter> t \<subseteq> s)"
lp15@62843
  1193
apply (simp add: openin_contains_ball)
lp15@62843
  1194
apply (rule iffI)
lp15@62843
  1195
apply (auto dest!: bspec)
lp15@66643
  1196
apply (rule_tac x="e/2" in exI, force+)
lp15@62843
  1197
done
lp15@63075
  1198
himmelma@33175
  1199
lemma ball_eq_empty[simp]: "ball x e = {} \<longleftrightarrow> e \<le> 0"
nipkow@39302
  1200
  unfolding mem_ball set_eq_iff
himmelma@33175
  1201
  apply (simp add: not_less)
wenzelm@52624
  1202
  apply (metis zero_le_dist order_trans dist_self)
wenzelm@52624
  1203
  done
himmelma@33175
  1204
lp15@61694
  1205
lemma ball_empty: "e \<le> 0 \<Longrightarrow> ball x e = {}" by simp
himmelma@33175
  1206
hoelzl@50526
  1207
lemma euclidean_dist_l2:
hoelzl@50526
  1208
  fixes x y :: "'a :: euclidean_space"
hoelzl@50526
  1209
  shows "dist x y = setL2 (\<lambda>i. dist (x \<bullet> i) (y \<bullet> i)) Basis"
hoelzl@50526
  1210
  unfolding dist_norm norm_eq_sqrt_inner setL2_def
hoelzl@50526
  1211
  by (subst euclidean_inner) (simp add: power2_eq_square inner_diff_left)
hoelzl@50526
  1212
eberlm@61531
  1213
lemma eventually_nhds_ball: "d > 0 \<Longrightarrow> eventually (\<lambda>x. x \<in> ball z d) (nhds z)"
eberlm@61531
  1214
  by (rule eventually_nhds_in_open) simp_all
eberlm@61531
  1215
eberlm@61531
  1216
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
  1217
  unfolding eventually_at by (intro exI[of _ d]) (simp_all add: dist_commute)
eberlm@61531
  1218
eberlm@61531
  1219
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
  1220
  unfolding eventually_at by (intro exI[of _ d]) (simp_all add: dist_commute)
eberlm@61531
  1221
immler@56189
  1222
wenzelm@60420
  1223
subsection \<open>Boxes\<close>
immler@56189
  1224
hoelzl@57447
  1225
abbreviation One :: "'a::euclidean_space"
hoelzl@57447
  1226
  where "One \<equiv> \<Sum>Basis"
hoelzl@57447
  1227
lp15@63114
  1228
lemma One_non_0: assumes "One = (0::'a::euclidean_space)" shows False
lp15@63114
  1229
proof -
lp15@63114
  1230
  have "dependent (Basis :: 'a set)"
lp15@63114
  1231
    apply (simp add: dependent_finite)
lp15@63114
  1232
    apply (rule_tac x="\<lambda>i. 1" in exI)
lp15@63114
  1233
    using SOME_Basis apply (auto simp: assms)
lp15@63114
  1234
    done
lp15@63114
  1235
  with independent_Basis show False by force
lp15@63114
  1236
qed
lp15@63114
  1237
lp15@63114
  1238
corollary One_neq_0[iff]: "One \<noteq> 0"
lp15@63114
  1239
  by (metis One_non_0)
lp15@63114
  1240
lp15@63114
  1241
corollary Zero_neq_One[iff]: "0 \<noteq> One"
lp15@63114
  1242
  by (metis One_non_0)
lp15@63114
  1243
immler@54775
  1244
definition (in euclidean_space) eucl_less (infix "<e" 50)
immler@54775
  1245
  where "eucl_less a b \<longleftrightarrow> (\<forall>i\<in>Basis. a \<bullet> i < b \<bullet> i)"
immler@54775
  1246
immler@54775
  1247
definition box_eucl_less: "box a b = {x. a <e x \<and> x <e b}"
immler@56188
  1248
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
  1249
immler@54775
  1250
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
  1251
  and in_box_eucl_less: "x \<in> box a b \<longleftrightarrow> a <e x \<and> x <e b"
immler@56188
  1252
  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
  1253
    "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
  1254
  by (auto simp: box_eucl_less eucl_less_def cbox_def)
immler@56188
  1255
lp15@60615
  1256
lemma cbox_Pair_eq: "cbox (a, c) (b, d) = cbox a b \<times> cbox c d"
lp15@60615
  1257
  by (force simp: cbox_def Basis_prod_def)
lp15@60615
  1258
lp15@60615
  1259
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
  1260
  by (force simp: cbox_Pair_eq)
lp15@60615
  1261
lp15@65587
  1262
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
  1263
  apply (auto simp: cbox_def Basis_complex_def)
lp15@65587
  1264
  apply (rule_tac x = "(Re x, Im x)" in image_eqI)
lp15@65587
  1265
  using complex_eq by auto
lp15@65587
  1266
lp15@60615
  1267
lemma cbox_Pair_eq_0: "cbox (a, c) (b, d) = {} \<longleftrightarrow> cbox a b = {} \<or> cbox c d = {}"
lp15@60615
  1268
  by (force simp: cbox_Pair_eq)
lp15@60615
  1269
lp15@60615
  1270
lemma swap_cbox_Pair [simp]: "prod.swap ` cbox (c, a) (d, b) = cbox (a,c) (b,d)"
lp15@60615
  1271
  by auto
lp15@60615
  1272
immler@56188
  1273
lemma mem_box_real[simp]:
immler@56188
  1274
  "(x::real) \<in> box a b \<longleftrightarrow> a < x \<and> x < b"
immler@56188
  1275
  "(x::real) \<in> cbox a b \<longleftrightarrow> a \<le> x \<and> x \<le> b"
immler@56188
  1276
  by (auto simp: mem_box)
immler@56188
  1277
immler@56188
  1278
lemma box_real[simp]:
immler@56188
  1279
  fixes a b:: real
immler@56188
  1280
  shows "box a b = {a <..< b}" "cbox a b = {a .. b}"
immler@56188
  1281
  by auto
hoelzl@50526
  1282
hoelzl@57447
  1283
lemma box_Int_box:
hoelzl@57447
  1284
  fixes a :: "'a::euclidean_space"
hoelzl@57447
  1285
  shows "box a b \<inter> box c d =
hoelzl@57447
  1286
    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
  1287
  unfolding set_eq_iff and Int_iff and mem_box by auto
hoelzl@57447
  1288
immler@50087
  1289
lemma rational_boxes:
wenzelm@61076
  1290
  fixes x :: "'a::euclidean_space"
wenzelm@53291
  1291
  assumes "e > 0"
lp15@66643
  1292
  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
  1293
proof -
wenzelm@63040
  1294
  define e' where "e' = e / (2 * sqrt (real (DIM ('a))))"
wenzelm@53291
  1295
  then have e: "e' > 0"
nipkow@56541
  1296
    using assms by (auto simp: DIM_positive)
hoelzl@50526
  1297
  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
  1298
  proof
wenzelm@53255
  1299
    fix i
wenzelm@53255
  1300
    from Rats_dense_in_real[of "x \<bullet> i - e'" "x \<bullet> i"] e
wenzelm@53255
  1301
    show "?th i" by auto
immler@50087
  1302
  qed
wenzelm@55522
  1303
  from choice[OF this] obtain a where
wenzelm@55522
  1304
    a: "\<forall>xa. a xa \<in> \<rat> \<and> a xa < x \<bullet> xa \<and> x \<bullet> xa - a xa < e'" ..
hoelzl@50526
  1305
  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
  1306
  proof
wenzelm@53255
  1307
    fix i
wenzelm@53255
  1308
    from Rats_dense_in_real[of "x \<bullet> i" "x \<bullet> i + e'"] e
wenzelm@53255
  1309
    show "?th i" by auto
immler@50087
  1310
  qed
wenzelm@55522
  1311
  from choice[OF this] obtain b where
wenzelm@55522
  1312
    b: "\<forall>xa. b xa \<in> \<rat> \<and> x \<bullet> xa < b xa \<and> b xa - x \<bullet> xa < e'" ..
hoelzl@50526
  1313
  let ?a = "\<Sum>i\<in>Basis. a i *\<^sub>R i" and ?b = "\<Sum>i\<in>Basis. b i *\<^sub>R i"
hoelzl@50526
  1314
  show ?thesis
hoelzl@50526
  1315
  proof (rule exI[of _ ?a], rule exI[of _ ?b], safe)
wenzelm@53255
  1316
    fix y :: 'a
wenzelm@53255
  1317
    assume *: "y \<in> box ?a ?b"
wenzelm@53015
  1318
    have "dist x y = sqrt (\<Sum>i\<in>Basis. (dist (x \<bullet> i) (y \<bullet> i))\<^sup>2)"
immler@50087
  1319
      unfolding setL2_def[symmetric] by (rule euclidean_dist_l2)
hoelzl@50526
  1320
    also have "\<dots> < sqrt (\<Sum>(i::'a)\<in>Basis. e^2 / real (DIM('a)))"
nipkow@64267
  1321
    proof (rule real_sqrt_less_mono, rule sum_strict_mono)
wenzelm@53255
  1322
      fix i :: "'a"
wenzelm@53255
  1323
      assume i: "i \<in> Basis"
wenzelm@53255
  1324
      have "a i < y\<bullet>i \<and> y\<bullet>i < b i"
wenzelm@53255
  1325
        using * i by (auto simp: box_def)
wenzelm@53255
  1326
      moreover have "a i < x\<bullet>i" "x\<bullet>i - a i < e'"
wenzelm@53255
  1327
        using a by auto
wenzelm@53255
  1328
      moreover have "x\<bullet>i < b i" "b i - x\<bullet>i < e'"
wenzelm@53255
  1329
        using b by auto
wenzelm@53255
  1330
      ultimately have "\<bar>x\<bullet>i - y\<bullet>i\<bar> < 2 * e'"
wenzelm@53255
  1331
        by auto
hoelzl@50526
  1332
      then have "dist (x \<bullet> i) (y \<bullet> i) < e/sqrt (real (DIM('a)))"
immler@50087
  1333
        unfolding e'_def by (auto simp: dist_real_def)
wenzelm@53015
  1334
      then have "(dist (x \<bullet> i) (y \<bullet> i))\<^sup>2 < (e/sqrt (real (DIM('a))))\<^sup>2"
immler@50087
  1335
        by (rule power_strict_mono) auto
wenzelm@53015
  1336
      then show "(dist (x \<bullet> i) (y \<bullet> i))\<^sup>2 < e\<^sup>2 / real DIM('a)"
immler@50087
  1337
        by (simp add: power_divide)
immler@50087
  1338
    qed auto
wenzelm@53255
  1339
    also have "\<dots> = e"
lp15@61609
  1340
      using \<open>0 < e\<close> by simp
wenzelm@53255
  1341
    finally show "y \<in> ball x e"
wenzelm@53255
  1342
      by (auto simp: ball_def)
hoelzl@50526
  1343
  qed (insert a b, auto simp: box_def)
hoelzl@50526
  1344
qed
immler@51103
  1345
hoelzl@50526
  1346
lemma open_UNION_box:
wenzelm@61076
  1347
  fixes M :: "'a::euclidean_space set"
wenzelm@53282
  1348
  assumes "open M"
hoelzl@50526
  1349
  defines "a' \<equiv> \<lambda>f :: 'a \<Rightarrow> real \<times> real. (\<Sum>(i::'a)\<in>Basis. fst (f i) *\<^sub>R i)"
hoelzl@50526
  1350
  defines "b' \<equiv> \<lambda>f :: 'a \<Rightarrow> real \<times> real. (\<Sum>(i::'a)\<in>Basis. snd (f i) *\<^sub>R i)"
wenzelm@53015
  1351
  defines "I \<equiv> {f\<in>Basis \<rightarrow>\<^sub>E \<rat> \<times> \<rat>. box (a' f) (b' f) \<subseteq> M}"
hoelzl@50526
  1352
  shows "M = (\<Union>f\<in>I. box (a' f) (b' f))"
wenzelm@52624
  1353
proof -
wenzelm@60462
  1354
  have "x \<in> (\<Union>f\<in>I. box (a' f) (b' f))" if "x \<in> M" for x
wenzelm@60462
  1355
  proof -
wenzelm@52624
  1356
    obtain e where e: "e > 0" "ball x e \<subseteq> M"
wenzelm@60420
  1357
      using openE[OF \<open>open M\<close> \<open>x \<in> M\<close>] by auto
wenzelm@53282
  1358
    moreover obtain a b where ab:
wenzelm@53282
  1359
      "x \<in> box a b"
wenzelm@53282
  1360
      "\<forall>i \<in> Basis. a \<bullet> i \<in> \<rat>"
wenzelm@53282
  1361
      "\<forall>i\<in>Basis. b \<bullet> i \<in> \<rat>"
wenzelm@53282
  1362
      "box a b \<subseteq> ball x e"
wenzelm@52624
  1363
      using rational_boxes[OF e(1)] by metis
wenzelm@60462
  1364
    ultimately show ?thesis
wenzelm@52624
  1365
       by (intro UN_I[of "\<lambda>i\<in>Basis. (a \<bullet> i, b \<bullet> i)"])
wenzelm@52624
  1366
          (auto simp: euclidean_representation I_def a'_def b'_def)
wenzelm@60462
  1367
  qed
wenzelm@52624
  1368
  then show ?thesis by (auto simp: I_def)
wenzelm@52624
  1369
qed
wenzelm@52624
  1370
lp15@66154
  1371
corollary open_countable_Union_open_box:
lp15@66154
  1372
  fixes S :: "'a :: euclidean_space set"
lp15@66154
  1373
  assumes "open S"
lp15@66154
  1374
  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
  1375
proof -
lp15@66154
  1376
  let ?a = "\<lambda>f. (\<Sum>(i::'a)\<in>Basis. fst (f i) *\<^sub>R i)"
lp15@66154
  1377
  let ?b = "\<lambda>f. (\<Sum>(i::'a)\<in>Basis. snd (f i) *\<^sub>R i)"
lp15@66154
  1378
  let ?I = "{f\<in>Basis \<rightarrow>\<^sub>E \<rat> \<times> \<rat>. box (?a f) (?b f) \<subseteq> S}"
lp15@66154
  1379
  let ?\<D> = "(\<lambda>f. box (?a f) (?b f)) ` ?I"
lp15@66154
  1380
  show ?thesis
lp15@66154
  1381
  proof
lp15@66154
  1382
    have "countable ?I"
lp15@66154
  1383
      by (simp add: countable_PiE countable_rat)
lp15@66154
  1384
    then show "countable ?\<D>"
lp15@66154
  1385
      by blast
lp15@66154
  1386
    show "\<Union>?\<D> = S"
lp15@66154
  1387
      using open_UNION_box [OF assms] by metis
lp15@66154
  1388
  qed auto
lp15@66154
  1389
qed
lp15@66154
  1390
lp15@66154
  1391
lemma rational_cboxes:
lp15@66154
  1392
  fixes x :: "'a::euclidean_space"
lp15@66154
  1393
  assumes "e > 0"
lp15@66154
  1394
  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
  1395
proof -
lp15@66154
  1396
  define e' where "e' = e / (2 * sqrt (real (DIM ('a))))"
lp15@66154
  1397
  then have e: "e' > 0"
lp15@66154
  1398
    using assms by auto
lp15@66154
  1399
  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
  1400
  proof
lp15@66154
  1401
    fix i
lp15@66154
  1402
    from Rats_dense_in_real[of "x \<bullet> i - e'" "x \<bullet> i"] e
lp15@66154
  1403
    show "?th i" by auto
lp15@66154
  1404
  qed
lp15@66154
  1405
  from choice[OF this] obtain a where
lp15@66154
  1406
    a: "\<forall>u. a u \<in> \<rat> \<and> a u < x \<bullet> u \<and> x \<bullet> u - a u < e'" ..
lp15@66154
  1407
  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
  1408
  proof
lp15@66154
  1409
    fix i
lp15@66154
  1410
    from Rats_dense_in_real[of "x \<bullet> i" "x \<bullet> i + e'"] e
lp15@66154
  1411
    show "?th i" by auto
lp15@66154
  1412
  qed
lp15@66154
  1413
  from choice[OF this] obtain b where
lp15@66154
  1414
    b: "\<forall>u. b u \<in> \<rat> \<and> x \<bullet> u < b u \<and> b u - x \<bullet> u < e'" ..
lp15@66154
  1415
  let ?a = "\<Sum>i\<in>Basis. a i *\<^sub>R i" and ?b = "\<Sum>i\<in>Basis. b i *\<^sub>R i"
lp15@66154
  1416
  show ?thesis
lp15@66154
  1417
  proof (rule exI[of _ ?a], rule exI[of _ ?b], safe)
lp15@66154
  1418
    fix y :: 'a
lp15@66154
  1419
    assume *: "y \<in> cbox ?a ?b"
lp15@66154
  1420
    have "dist x y = sqrt (\<Sum>i\<in>Basis. (dist (x \<bullet> i) (y \<bullet> i))\<^sup>2)"
lp15@66154
  1421
      unfolding setL2_def[symmetric] by (rule euclidean_dist_l2)
lp15@66154
  1422
    also have "\<dots> < sqrt (\<Sum>(i::'a)\<in>Basis. e^2 / real (DIM('a)))"
lp15@66154
  1423
    proof (rule real_sqrt_less_mono, rule sum_strict_mono)
lp15@66154
  1424
      fix i :: "'a"
lp15@66154
  1425
      assume i: "i \<in> Basis"
lp15@66154
  1426
      have "a i \<le> y\<bullet>i \<and> y\<bullet>i \<le> b i"
lp15@66154
  1427
        using * i by (auto simp: cbox_def)
lp15@66154
  1428
      moreover have "a i < x\<bullet>i" "x\<bullet>i - a i < e'"
lp15@66154
  1429
        using a by auto
lp15@66154
  1430
      moreover have "x\<bullet>i < b i" "b i - x\<bullet>i < e'"
lp15@66154
  1431
        using b by auto
lp15@66154
  1432
      ultimately have "\<bar>x\<bullet>i - y\<bullet>i\<bar> < 2 * e'"
lp15@66154
  1433
        by auto
lp15@66154
  1434
      then have "dist (x \<bullet> i) (y \<bullet> i) < e/sqrt (real (DIM('a)))"
lp15@66154
  1435
        unfolding e'_def by (auto simp: dist_real_def)
lp15@66154
  1436
      then have "(dist (x \<bullet> i) (y \<bullet> i))\<^sup>2 < (e/sqrt (real (DIM('a))))\<^sup>2"
lp15@66154
  1437
        by (rule power_strict_mono) auto
lp15@66154
  1438
      then show "(dist (x \<bullet> i) (y \<bullet> i))\<^sup>2 < e\<^sup>2 / real DIM('a)"
lp15@66154
  1439
        by (simp add: power_divide)
lp15@66154
  1440
    qed auto
lp15@66154
  1441
    also have "\<dots> = e"
lp15@66154
  1442
      using \<open>0 < e\<close> by simp
lp15@66154
  1443
    finally show "y \<in> ball x e"
lp15@66154
  1444
      by (auto simp: ball_def)
lp15@66154
  1445
  next
lp15@66154
  1446
    show "x \<in> cbox (\<Sum>i\<in>Basis. a i *\<^sub>R i) (\<Sum>i\<in>Basis. b i *\<^sub>R i)"
lp15@66154
  1447
      using a b less_imp_le by (auto simp: cbox_def)
lp15@66154
  1448
  qed (use a b cbox_def in auto)
lp15@66154
  1449
qed
lp15@66154
  1450
lp15@66154
  1451
lemma open_UNION_cbox:
lp15@66154
  1452
  fixes M :: "'a::euclidean_space set"
lp15@66154
  1453
  assumes "open M"
lp15@66154
  1454
  defines "a' \<equiv> \<lambda>f. (\<Sum>(i::'a)\<in>Basis. fst (f i) *\<^sub>R i)"
lp15@66154
  1455
  defines "b' \<equiv> \<lambda>f. (\<Sum>(i::'a)\<in>Basis. snd (f i) *\<^sub>R i)"
lp15@66154
  1456
  defines "I \<equiv> {f\<in>Basis \<rightarrow>\<^sub>E \<rat> \<times> \<rat>. cbox (a' f) (b' f) \<subseteq> M}"
lp15@66154
  1457
  shows "M = (\<Union>f\<in>I. cbox (a' f) (b' f))"
lp15@66154
  1458
proof -
lp15@66154
  1459
  have "x \<in> (\<Union>f\<in>I. cbox (a' f) (b' f))" if "x \<in> M" for x
lp15@66154
  1460
  proof -
lp15@66154
  1461
    obtain e where e: "e > 0" "ball x e \<subseteq> M"
lp15@66154
  1462
      using openE[OF \<open>open M\<close> \<open>x \<in> M\<close>] by auto
lp15@66154
  1463
    moreover obtain a b where ab: "x \<in> cbox a b" "\<forall>i \<in> Basis. a \<bullet> i \<in> \<rat>"
lp15@66154
  1464
                                  "\<forall>i \<in> Basis. b \<bullet> i \<in> \<rat>" "cbox a b \<subseteq> ball x e"
lp15@66154
  1465
      using rational_cboxes[OF e(1)] by metis
lp15@66154
  1466
    ultimately show ?thesis
lp15@66154
  1467
       by (intro UN_I[of "\<lambda>i\<in>Basis. (a \<bullet> i, b \<bullet> i)"])
lp15@66154
  1468
          (auto simp: euclidean_representation I_def a'_def b'_def)
lp15@66154
  1469
  qed
lp15@66154
  1470
  then show ?thesis by (auto simp: I_def)
lp15@66154
  1471
qed
lp15@66154
  1472
lp15@66154
  1473
corollary open_countable_Union_open_cbox:
lp15@66154
  1474
  fixes S :: "'a :: euclidean_space set"
lp15@66154
  1475
  assumes "open S"
lp15@66154
  1476
  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
  1477
proof -
lp15@66154
  1478
  let ?a = "\<lambda>f. (\<Sum>(i::'a)\<in>Basis. fst (f i) *\<^sub>R i)"
lp15@66154
  1479
  let ?b = "\<lambda>f. (\<Sum>(i::'a)\<in>Basis. snd (f i) *\<^sub>R i)"
lp15@66154
  1480
  let ?I = "{f\<in>Basis \<rightarrow>\<^sub>E \<rat> \<times> \<rat>. cbox (?a f) (?b f) \<subseteq> S}"
lp15@66154
  1481
  let ?\<D> = "(\<lambda>f. cbox (?a f) (?b f)) ` ?I"
lp15@66154
  1482
  show ?thesis
lp15@66154
  1483
  proof
lp15@66154
  1484
    have "countable ?I"
lp15@66154
  1485
      by (simp add: countable_PiE countable_rat)
lp15@66154
  1486
    then show "countable ?\<D>"
lp15@66154
  1487
      by blast
lp15@66154
  1488
    show "\<Union>?\<D> = S"
lp15@66154
  1489
      using open_UNION_cbox [OF assms] by metis
lp15@66154
  1490
  qed auto
lp15@66154
  1491
qed
lp15@66154
  1492
immler@56189
  1493
lemma box_eq_empty:
immler@56189
  1494
  fixes a :: "'a::euclidean_space"
immler@56189
  1495
  shows "(box a b = {} \<longleftrightarrow> (\<exists>i\<in>Basis. b\<bullet>i \<le> a\<bullet>i))" (is ?th1)
immler@56189
  1496
    and "(cbox a b = {} \<longleftrightarrow> (\<exists>i\<in>Basis. b\<bullet>i < a\<bullet>i))" (is ?th2)
immler@56189
  1497
proof -
immler@56189
  1498
  {
immler@56189
  1499
    fix i x
immler@56189
  1500
    assume i: "i\<in>Basis" and as:"b\<bullet>i \<le> a\<bullet>i" and x:"x\<in>box a b"
immler@56189
  1501
    then have "a \<bullet> i < x \<bullet> i \<and> x \<bullet> i < b \<bullet> i"
immler@56189
  1502
      unfolding mem_box by (auto simp: box_def)
immler@56189
  1503
    then have "a\<bullet>i < b\<bullet>i" by auto
immler@56189
  1504
    then have False using as by auto
immler@56189
  1505
  }
immler@56189
  1506
  moreover
immler@56189
  1507
  {
immler@56189
  1508
    assume as: "\<forall>i\<in>Basis. \<not> (b\<bullet>i \<le> a\<bullet>i)"
immler@56189
  1509
    let ?x = "(1/2) *\<^sub>R (a + b)"
immler@56189
  1510
    {
immler@56189
  1511
      fix i :: 'a
immler@56189
  1512
      assume i: "i \<in> Basis"
immler@56189
  1513
      have "a\<bullet>i < b\<bullet>i"
immler@56189
  1514
        using as[THEN bspec[where x=i]] i by auto
immler@56189
  1515
      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
  1516
        by (auto simp: inner_add_left)
immler@56189
  1517
    }
immler@56189
  1518
    then have "box a b \<noteq> {}"
immler@56189
  1519
      using mem_box(1)[of "?x" a b] by auto
immler@56189
  1520
  }
immler@56189
  1521
  ultimately show ?th1 by blast
immler@56189
  1522
immler@56189
  1523
  {
immler@56189
  1524
    fix i x
immler@56189
  1525
    assume i: "i \<in> Basis" and as:"b\<bullet>i < a\<bullet>i" and x:"x\<in>cbox a b"
immler@56189
  1526
    then have "a \<bullet> i \<le> x \<bullet> i \<and> x \<bullet> i \<le> b \<bullet> i"
immler@56189
  1527
      unfolding mem_box by auto
immler@56189
  1528
    then have "a\<bullet>i \<le> b\<bullet>i" by auto
immler@56189
  1529
    then have False using as by auto
immler@56189
  1530
  }
immler@56189
  1531
  moreover
immler@56189
  1532
  {
immler@56189
  1533
    assume as:"\<forall>i\<in>Basis. \<not> (b\<bullet>i < a\<bullet>i)"
immler@56189
  1534
    let ?x = "(1/2) *\<^sub>R (a + b)"
immler@56189
  1535
    {
immler@56189
  1536
      fix i :: 'a
immler@56189
  1537
      assume i:"i \<in> Basis"
immler@56189
  1538
      have "a\<bullet>i \<le> b\<bullet>i"
immler@56189
  1539
        using as[THEN bspec[where x=i]] i by auto
immler@56189
  1540
      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
  1541
        by (auto simp: inner_add_left)
immler@56189
  1542
    }
immler@56189
  1543
    then have "cbox a b \<noteq> {}"
immler@56189
  1544
      using mem_box(2)[of "?x" a b] by auto
immler@56189
  1545
  }
immler@56189
  1546
  ultimately show ?th2 by blast
immler@56189
  1547
qed
immler@56189
  1548
immler@56189
  1549
lemma box_ne_empty:
immler@56189
  1550
  fixes a :: "'a::euclidean_space"
immler@56189
  1551
  shows "cbox a b \<noteq> {} \<longleftrightarrow> (\<forall>i\<in>Basis. a\<bullet>i \<le> b\<bullet>i)"
immler@56189
  1552
  and "box a b \<noteq> {} \<longleftrightarrow> (\<forall>i\<in>Basis. a\<bullet>i < b\<bullet>i)"
immler@56189
  1553
  unfolding box_eq_empty[of a b] by fastforce+
immler@56189
  1554
immler@56189
  1555
lemma
immler@56189
  1556
  fixes a :: "'a::euclidean_space"
lp15@66112
  1557
  shows cbox_sing [simp]: "cbox a a = {a}"
lp15@66112
  1558
    and box_sing [simp]: "box a a = {}"
immler@56189
  1559
  unfolding set_eq_iff mem_box eq_iff [symmetric]
immler@56189
  1560
  by (auto intro!: euclidean_eqI[where 'a='a])
immler@56189
  1561
     (metis all_not_in_conv nonempty_Basis)
immler@56189
  1562
immler@56189
  1563
lemma subset_box_imp:
immler@56189
  1564
  fixes a :: "'a::euclidean_space"
immler@56189
  1565
  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
  1566
    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
  1567
    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
  1568
     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
  1569
  unfolding subset_eq[unfolded Ball_def] unfolding mem_box
wenzelm@58757
  1570
  by (best intro: order_trans less_le_trans le_less_trans less_imp_le)+
immler@56189
  1571
immler@56189
  1572
lemma box_subset_cbox:
immler@56189
  1573
  fixes a :: "'a::euclidean_space"
immler@56189
  1574
  shows "box a b \<subseteq> cbox a b"
immler@56189
  1575
  unfolding subset_eq [unfolded Ball_def] mem_box
immler@56189
  1576
  by (fast intro: less_imp_le)
immler@56189
  1577
immler@56189
  1578
lemma subset_box:
immler@56189
  1579
  fixes a :: "'a::euclidean_space"
wenzelm@64539
  1580
  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
  1581
    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
  1582
    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
  1583
    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
  1584
proof -
immler@56189
  1585
  show ?th1
immler@56189
  1586
    unfolding subset_eq and Ball_def and mem_box
immler@56189
  1587
    by (auto intro: order_trans)
immler@56189
  1588
  show ?th2
immler@56189
  1589
    unfolding subset_eq and Ball_def and mem_box
immler@56189
  1590
    by (auto intro: le_less_trans less_le_trans order_trans less_imp_le)
immler@56189
  1591
  {
immler@56189
  1592
    assume as: "box c d \<subseteq> cbox a b" "\<forall>i\<in>Basis. c\<bullet>i < d\<bullet>i"
immler@56189
  1593
    then have "box c d \<noteq> {}"
immler@56189
  1594
      unfolding box_eq_empty by auto
immler@56189
  1595
    fix i :: 'a
immler@56189
  1596
    assume i: "i \<in> Basis"
immler@56189
  1597
    (** TODO combine the following two parts as done in the HOL_light version. **)
immler@56189
  1598
    {
immler@56189
  1599
      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
  1600
      assume as2: "a\<bullet>i > c\<bullet>i"
immler@56189
  1601
      {
immler@56189
  1602
        fix j :: 'a
immler@56189
  1603
        assume j: "j \<in> Basis"
immler@56189
  1604
        then have "c \<bullet> j < ?x \<bullet> j \<and> ?x \<bullet> j < d \<bullet> j"
immler@56189
  1605
          apply (cases "j = i")
immler@56189
  1606
          using as(2)[THEN bspec[where x=j]] i
lp15@66643
  1607
          apply (auto simp: as2)
immler@56189
  1608
          done
immler@56189
  1609
      }
immler@56189
  1610
      then have "?x\<in>box c d"
immler@56189
  1611
        using i unfolding mem_box by auto
immler@56189
  1612
      moreover
immler@56189
  1613
      have "?x \<notin> cbox a b"
immler@56189
  1614
        unfolding mem_box
immler@56189
  1615
        apply auto
immler@56189
  1616
        apply (rule_tac x=i in bexI)
immler@56189
  1617
        using as(2)[THEN bspec[where x=i]] and as2 i
immler@56189
  1618
        apply auto
immler@56189
  1619
        done
immler@56189
  1620
      ultimately have False using as by auto
immler@56189
  1621
    }
immler@56189
  1622
    then have "a\<bullet>i \<le> c\<bullet>i" by (rule ccontr) auto
immler@56189
  1623
    moreover
immler@56189
  1624
    {
immler@56189
  1625
      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
  1626
      assume as2: "b\<bullet>i < d\<bullet>i"
immler@56189
  1627
      {
immler@56189
  1628
        fix j :: 'a
immler@56189
  1629
        assume "j\<in>Basis"
immler@56189
  1630
        then have "d \<bullet> j > ?x \<bullet> j \<and> ?x \<bullet> j > c \<bullet> j"
immler@56189
  1631
          apply (cases "j = i")
immler@56189
  1632
          using as(2)[THEN bspec[where x=j]]
lp15@66643
  1633
          apply (auto simp: as2)
immler@56189
  1634
          done
immler@56189
  1635
      }
immler@56189
  1636
      then have "?x\<in>box c d"
immler@56189
  1637
        unfolding mem_box by auto
immler@56189
  1638
      moreover
immler@56189
  1639
      have "?x\<notin>cbox a b"
immler@56189
  1640
        unfolding mem_box
immler@56189
  1641
        apply auto
immler@56189
  1642
        apply (rule_tac x=i in bexI)
immler@56189
  1643
        using as(2)[THEN bspec[where x=i]] and as2 using i
immler@56189
  1644
        apply auto
immler@56189
  1645
        done
immler@56189
  1646
      ultimately have False using as by auto
immler@56189
  1647
    }
immler@56189
  1648
    then have "b\<bullet>i \<ge> d\<bullet>i" by (rule ccontr) auto
immler@56189
  1649
    ultimately
immler@56189
  1650
    have "a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i" by auto
immler@56189
  1651
  } note part1 = this
immler@56189
  1652
  show ?th3
immler@56189
  1653
    unfolding subset_eq and Ball_def and mem_box
immler@56189
  1654
    apply (rule, rule, rule, rule)
immler@56189
  1655
    apply (rule part1)
immler@56189
  1656
    unfolding subset_eq and Ball_def and mem_box
immler@56189
  1657
    prefer 4
immler@56189
  1658
    apply auto
immler@56189
  1659
    apply (erule_tac x=xa in allE, erule_tac x=xa in allE, fastforce)+
immler@56189
  1660
    done
immler@56189
  1661
  {
immler@56189
  1662
    assume as: "box c d \<subseteq> box a b" "\<forall>i\<in>Basis. c\<bullet>i < d\<bullet>i"
immler@56189
  1663
    fix i :: 'a
immler@56189
  1664
    assume i:"i\<in>Basis"
immler@56189
  1665
    from as(1) have "box c d \<subseteq> cbox a b"
immler@56189
  1666
      using box_subset_cbox[of a b] by auto
immler@56189
  1667
    then have "a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i"
immler@56189
  1668
      using part1 and as(2) using i by auto
immler@56189
  1669
  } note * = this
immler@56189
  1670
  show ?th4
immler@56189
  1671
    unfolding subset_eq and Ball_def and mem_box
immler@56189
  1672
    apply (rule, rule, rule, rule)
immler@56189
  1673
    apply (rule *)
immler@56189
  1674
    unfolding subset_eq and Ball_def and mem_box
immler@56189
  1675
    prefer 4
immler@56189
  1676
    apply auto
immler@56189
  1677
    apply (erule_tac x=xa in allE, simp)+
immler@56189
  1678
    done
immler@56189
  1679
qed
immler@56189
  1680
lp15@63945
  1681
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
  1682
      (is "?lhs = ?rhs")
lp15@63945
  1683
proof
lp15@63945
  1684
  assume ?lhs
lp15@63945
  1685
  then have "cbox a b \<subseteq> cbox c d" "cbox c d \<subseteq> cbox a b"
lp15@63945
  1686
    by auto
lp15@63945
  1687
  then show ?rhs
lp15@66643
  1688
    by (force simp: subset_box box_eq_empty intro: antisym euclidean_eqI)
lp15@63945
  1689
next
lp15@63945
  1690
  assume ?rhs
lp15@63945
  1691
  then show ?lhs
lp15@63945
  1692
    by force
lp15@63945
  1693
qed
lp15@63945
  1694
lp15@63945
  1695
lemma eq_cbox_box [simp]: "cbox a b = box c d \<longleftrightarrow> cbox a b = {} \<and> box c d = {}"
wenzelm@64539
  1696
  (is "?lhs \<longleftrightarrow> ?rhs")
lp15@63945
  1697
proof
lp15@63945
  1698
  assume ?lhs
lp15@63945
  1699
  then have "cbox a b \<subseteq> box c d" "box c d \<subseteq>cbox a b"
lp15@63945
  1700
    by auto
lp15@63945
  1701
  then show ?rhs
hoelzl@63957
  1702
    apply (simp add: subset_box)
lp15@63945
  1703
    using \<open>cbox a b = box c d\<close> box_ne_empty box_sing
lp15@63945
  1704
    apply (fastforce simp add:)
lp15@63945
  1705
    done
lp15@63945
  1706
next
lp15@63945
  1707
  assume ?rhs
lp15@63945
  1708
  then show ?lhs
lp15@63945
  1709
    by force
lp15@63945
  1710
qed
lp15@63945
  1711
lp15@63945
  1712
lemma eq_box_cbox [simp]: "box a b = cbox c d \<longleftrightarrow> box a b = {} \<and> cbox c d = {}"
lp15@63945
  1713
  by (metis eq_cbox_box)
lp15@63945
  1714
lp15@63945
  1715
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
  1716
  (is "?lhs \<longleftrightarrow> ?rhs")
lp15@63945
  1717
proof
lp15@63945
  1718
  assume ?lhs
lp15@63945
  1719
  then have "box a b \<subseteq> box c d" "box c d \<subseteq> box a b"
lp15@63945
  1720
    by auto
lp15@63945
  1721
  then show ?rhs
lp15@63945
  1722
    apply (simp add: subset_box)
hoelzl@63957
  1723
    using box_ne_empty(2) \<open>box a b = box c d\<close>
lp15@63945
  1724
    apply auto
lp15@63945
  1725
     apply (meson euclidean_eqI less_eq_real_def not_less)+
lp15@63945
  1726
    done
lp15@63945
  1727
next
lp15@63945
  1728
  assume ?rhs
lp15@63945
  1729
  then show ?lhs
lp15@63945
  1730
    by force
lp15@63945
  1731
qed
lp15@63945
  1732
eberlm@66466
  1733
lemma subset_box_complex:
lp15@66643
  1734
   "cbox a b \<subseteq> cbox c d \<longleftrightarrow>
eberlm@66466
  1735
      (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
  1736
   "cbox a b \<subseteq> box c d \<longleftrightarrow>
eberlm@66466
  1737
      (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
  1738
   "box a b \<subseteq> cbox c d \<longleftrightarrow>
eberlm@66466
  1739
      (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
  1740
   "box a b \<subseteq> box c d \<longleftrightarrow>
eberlm@66466
  1741
      (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
  1742
  by (subst subset_box; force simp: Basis_complex_def)+
eberlm@66466
  1743
lp15@63945
  1744
lemma Int_interval:
immler@56189
  1745
  fixes a :: "'a::euclidean_space"
immler@56189
  1746
  shows "cbox a b \<inter> cbox c d =
immler@56189
  1747
    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
  1748
  unfolding set_eq_iff and Int_iff and mem_box
immler@56189
  1749
  by auto
immler@56189
  1750
immler@56189
  1751
lemma disjoint_interval:
immler@56189
  1752
  fixes a::"'a::euclidean_space"
immler@56189
  1753
  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
  1754
    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
  1755
    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
  1756
    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
  1757
proof -
immler@56189
  1758
  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
  1759
  have **: "\<And>P Q. (\<And>i :: 'a. i \<in> Basis \<Longrightarrow> Q ?z i \<Longrightarrow> P i) \<Longrightarrow>
immler@56189
  1760
      (\<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
  1761
    by blast
immler@56189
  1762
  note * = set_eq_iff Int_iff empty_iff mem_box ball_conj_distrib[symmetric] eq_False ball_simps(10)
immler@56189
  1763
  show ?th1 unfolding * by (intro **) auto
immler@56189
  1764
  show ?th2 unfolding * by (intro **) auto
immler@56189
  1765
  show ?th3 unfolding * by (intro **) auto
immler@56189
  1766
  show ?th4 unfolding * by (intro **) auto
immler@56189
  1767
qed
immler@56189
  1768
hoelzl@57447
  1769
lemma UN_box_eq_UNIV: "(\<Union>i::nat. box (- (real i *\<^sub>R One)) (real i *\<^sub>R One)) = UNIV"
hoelzl@57447
  1770
proof -
wenzelm@61942
  1771
  have "\<bar>x \<bullet> b\<bar> < real_of_int (\<lceil>Max ((\<lambda>b. \<bar>x \<bullet> b\<bar>)`Basis)\<rceil> + 1)"
wenzelm@60462
  1772
    if [simp]: "b \<in> Basis" for x b :: 'a
wenzelm@60462
  1773
  proof -
wenzelm@61942
  1774
    have "\<bar>x \<bullet> b\<bar> \<le> real_of_int \<lceil>\<bar>x \<bullet> b\<bar>\<rceil>"
lp15@61609
  1775
      by (rule le_of_int_ceiling)
wenzelm@61942
  1776
    also have "\<dots> \<le> real_of_int \<lceil>Max ((\<lambda>b. \<bar>x \<bullet> b\<bar>)`Basis)\<rceil>"
nipkow@59587
  1777
      by (auto intro!: ceiling_mono)
wenzelm@61942
  1778
    also have "\<dots> < real_of_int (\<lceil>Max ((\<lambda>b. \<bar>x \<bullet> b\<bar>)`Basis)\<rceil> + 1)"
hoelzl@57447
  1779
      by simp
wenzelm@60462
  1780
    finally show ?thesis .
wenzelm@60462
  1781
  qed
wenzelm@60462
  1782
  then have "\<exists>n::nat. \<forall>b\<in>Basis. \<bar>x \<bullet> b\<bar> < real n" for x :: 'a
nipkow@59587
  1783
    by (metis order.strict_trans reals_Archimedean2)
hoelzl@57447
  1784
  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
  1785
    by auto
hoelzl@57447
  1786
  ultimately show ?thesis
nipkow@64267
  1787
    by (auto simp: box_def inner_sum_left inner_Basis sum.If_cases)
hoelzl@57447
  1788
qed
hoelzl@57447
  1789
wenzelm@60420
  1790
text \<open>Intervals in general, including infinite and mixtures of open and closed.\<close>
immler@56189
  1791
immler@56189
  1792
definition "is_interval (s::('a::euclidean_space) set) \<longleftrightarrow>
immler@56189
  1793
  (\<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
  1794
lp15@66089
  1795
lemma is_interval_cbox [simp]: "is_interval (cbox a (b::'a::euclidean_space))" (is ?th1)
lp15@66089
  1796
  and is_interval_box [simp]: "is_interval (box a b)" (is ?th2)
immler@56189
  1797
  unfolding is_interval_def mem_box Ball_def atLeastAtMost_iff
immler@56189
  1798
  by (meson order_trans le_less_trans less_le_trans less_trans)+
immler@56189
  1799
lp15@61609
  1800
lemma is_interval_empty [iff]: "is_interval {}"
lp15@61609
  1801
  unfolding is_interval_def  by simp
lp15@61609
  1802
lp15@61609
  1803
lemma is_interval_univ [iff]: "is_interval UNIV"
lp15@61609
  1804
  unfolding is_interval_def  by simp
immler@56189
  1805
immler@56189
  1806
lemma mem_is_intervalI:
immler@56189
  1807
  assumes "is_interval s"
wenzelm@64539
  1808
    and "a \<in> s" "b \<in> s"
wenzelm@64539
  1809
    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
  1810
  shows "x \<in> s"
immler@56189
  1811
  by (rule assms(1)[simplified is_interval_def, rule_format, OF assms(2,3,4)])
immler@56189
  1812
immler@56189
  1813
lemma interval_subst:
immler@56189
  1814
  fixes S::"'a::euclidean_space set"
immler@56189
  1815
  assumes "is_interval S"
wenzelm@64539
  1816
    and "x \<in> S" "y j \<in> S"
wenzelm@64539
  1817
    and "j \<in> Basis"
immler@56189
  1818
  shows "(\<Sum>i\<in>Basis. (if i = j then y i \<bullet> i else x \<bullet> i) *\<^sub>R i) \<in> S"
immler@56189
  1819
  by (rule mem_is_intervalI[OF assms(1,2)]) (auto simp: assms)
immler@56189
  1820
immler@56189
  1821
lemma mem_box_componentwiseI:
immler@56189
  1822
  fixes S::"'a::euclidean_space set"
immler@56189
  1823
  assumes "is_interval S"
immler@56189
  1824
  assumes "\<And>i. i \<in> Basis \<Longrightarrow> x \<bullet> i \<in> ((\<lambda>x. x \<bullet> i) ` S)"
immler@56189
  1825
  shows "x \<in> S"
immler@56189
  1826
proof -
immler@56189
  1827
  from assms have "\<forall>i \<in> Basis. \<exists>s \<in> S. x \<bullet> i = s \<bullet> i"
immler@56189
  1828
    by auto
wenzelm@64539
  1829
  with finite_Basis obtain s and bs::"'a list"
wenzelm@64539
  1830
    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
  1831
      and bs: "set bs = Basis" "distinct bs"
immler@56189
  1832
    by (metis finite_distinct_list)
wenzelm@64539
  1833
  from nonempty_Basis s obtain j where j: "j \<in> Basis" "s j \<in> S"
wenzelm@64539
  1834
    by blast
wenzelm@63040
  1835
  define y where
wenzelm@63040
  1836
    "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
  1837
  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
  1838
    using bs by (auto simp: s(1)[symmetric] euclidean_representation)
immler@56189
  1839
  also have [symmetric]: "y bs = \<dots>"
immler@56189
  1840
    using bs(2) bs(1)[THEN equalityD1]
immler@56189
  1841
    by (induct bs) (auto simp: y_def euclidean_representation intro!: euclidean_eqI[where 'a='a])
immler@56189
  1842
  also have "y bs \<in> S"
immler@56189
  1843
    using bs(1)[THEN equalityD1]
immler@56189
  1844
    apply (induct bs)
wenzelm@64539
  1845
     apply (auto simp: y_def j)
immler@56189
  1846
    apply (rule interval_subst[OF assms(1)])
wenzelm@64539
  1847
      apply (auto simp: s)
immler@56189
  1848
    done
immler@56189
  1849
  finally show ?thesis .
immler@56189
  1850
qed
immler@56189
  1851
lp15@63007
  1852
lemma cbox01_nonempty [simp]: "cbox 0 One \<noteq> {}"
nipkow@64267
  1853
  by (simp add: box_ne_empty inner_Basis inner_sum_left sum_nonneg)
lp15@63007
  1854
lp15@63007
  1855
lemma box01_nonempty [simp]: "box 0 One \<noteq> {}"
lp15@66089
  1856
  by (simp add: box_ne_empty inner_Basis inner_sum_left)
lp15@63075
  1857
lp15@64773
  1858
lemma empty_as_interval: "{} = cbox One (0::'a::euclidean_space)"
lp15@64773
  1859
  using nonempty_Basis box01_nonempty box_eq_empty(1) box_ne_empty(1) by blast
lp15@64773
  1860
lp15@66089
  1861
lemma interval_subset_is_interval:
lp15@66089
  1862
  assumes "is_interval S"
lp15@66089
  1863
  shows "cbox a b \<subseteq> S \<longleftrightarrow> cbox a b = {} \<or> a \<in> S \<and> b \<in> S" (is "?lhs = ?rhs")
lp15@66089
  1864
proof
lp15@66089
  1865
  assume ?lhs
lp15@66089
  1866
  then show ?rhs  using box_ne_empty(1) mem_box(2) by fastforce
lp15@66089
  1867
next
lp15@66089
  1868
  assume ?rhs
lp15@66089
  1869
  have "cbox a b \<subseteq> S" if "a \<in> S" "b \<in> S"
lp15@66089
  1870
    using assms unfolding is_interval_def
lp15@66089
  1871
    apply (clarsimp simp add: mem_box)
lp15@66089
  1872
    using that by blast
lp15@66089
  1873
  with \<open>?rhs\<close> show ?lhs
lp15@66089
  1874
    by blast
lp15@66089
  1875
qed
lp15@66089
  1876
lp15@66643
  1877
wenzelm@64539
  1878
subsection \<open>Connectedness\<close>
himmelma@33175
  1879
himmelma@33175
  1880
lemma connected_local:
wenzelm@53255
  1881
 "connected S \<longleftrightarrow>
wenzelm@53255
  1882
  \<not> (\<exists>e1 e2.
wenzelm@53255
  1883
      openin (subtopology euclidean S) e1 \<and>
wenzelm@53255
  1884
      openin (subtopology euclidean S) e2 \<and>
wenzelm@53255
  1885
      S \<subseteq> e1 \<union> e2 \<and>
wenzelm@53255
  1886
      e1 \<inter> e2 = {} \<and>
wenzelm@53255
  1887
      e1 \<noteq> {} \<and>
wenzelm@53255
  1888
      e2 \<noteq> {})"
wenzelm@53282
  1889
  unfolding connected_def openin_open
lp15@59765
  1890
  by safe blast+
himmelma@33175
  1891
huffman@34105
  1892
lemma exists_diff:
huffman@34105
  1893
  fixes P :: "'a set \<Rightarrow> bool"
wenzelm@64539
  1894
  shows "(\<exists>S. P (- S)) \<longleftrightarrow> (\<exists>S. P S)"
wenzelm@64539
  1895
    (is "?lhs \<longleftrightarrow> ?rhs")
wenzelm@64539
  1896
proof -
wenzelm@64539
  1897
  have ?rhs if ?lhs
wenzelm@64539
  1898
    using that by blast
wenzelm@64539
  1899
  moreover have "P (- (- S))" if "P S" for S
wenzelm@64539
  1900
  proof -
wenzelm@64539
  1901
    have "S = - (- S)" by simp
wenzelm@64539
  1902
    with that show ?thesis by metis
wenzelm@64539
  1903
  qed
himmelma@33175
  1904
  ultimately show ?thesis by metis
himmelma@33175
  1905
qed
himmelma@33175
  1906
himmelma@33175
  1907
lemma connected_clopen: "connected S \<longleftrightarrow>
wenzelm@53255
  1908
  (\<forall>T. openin (subtopology euclidean S) T \<and>
wenzelm@53255
  1909
     closedin (subtopology euclidean S) T \<longrightarrow> T = {} \<or> T = S)" (is "?lhs \<longleftrightarrow> ?rhs")
wenzelm@53255
  1910
proof -
wenzelm@53255
  1911
  have "\<not> connected S \<longleftrightarrow>
wenzelm@53255
  1912
    (\<exists>e1 e2. open e1 \<and> open (- e2) \<and> S \<subseteq> e1 \<union> (- e2) \<and> e1 \<inter> (- e2) \<inter> S = {} \<and> e1 \<inter> S \<noteq> {} \<and> (- e2) \<inter> S \<noteq> {})"
himmelma@33175
  1913
    unfolding connected_def openin_open closedin_closed
lp15@55775
  1914
    by (metis double_complement)
wenzelm@53282
  1915
  then have th0: "connected S \<longleftrightarrow>
wenzelm@53255
  1916
    \<not> (\<exists>e2 e1. closed e2 \<and> open e1 \<and> S \<subseteq> e1 \<union> (- e2) \<and> e1 \<inter> (- e2) \<inter> S = {} \<and> e1 \<inter> S \<noteq> {} \<and> (- e2) \<inter> S \<noteq> {})"
wenzelm@52624
  1917
    (is " _ \<longleftrightarrow> \<not> (\<exists>e2 e1. ?P e2 e1)")
wenzelm@64539
  1918
    by (simp add: closed_def) metis
himmelma@33175
  1919
  have th1: "?rhs \<longleftrightarrow> \<not> (\<exists>t' t. closed t'\<and>t = S\<inter>t' \<and> t\<noteq>{} \<and> t\<noteq>S \<and> (\<exists>t'. open t' \<and> t = S \<inter> t'))"
himmelma@33175
  1920
    (is "_ \<longleftrightarrow> \<not> (\<exists>t' t. ?Q t' t)")
himmelma@33175
  1921
    unfolding connected_def openin_open closedin_closed by auto
wenzelm@64539
  1922
  have "(\<exists>e1. ?P e2 e1) \<longleftrightarrow> (\<exists>t. ?Q e2 t)" for e2
wenzelm@64539
  1923
  proof -
wenzelm@64539
  1924
    have "?P e2 e1 \<longleftrightarrow> (\<exists>t. closed e2 \<and> t = S\<inter>e2 \<and> open e1 \<and> t = S\<inter>e1 \<and> t\<noteq>{} \<and> t \<noteq> S)" for e1
wenzelm@64539
  1925
      by auto
wenzelm@64539
  1926
    then show ?thesis
wenzelm@53255
  1927
      by metis
wenzelm@64539
  1928
  qed
wenzelm@53255
  1929
  then have "\<forall>e2. (\<exists>e1. ?P e2 e1) \<longleftrightarrow> (\<exists>t. ?Q e2 t)"
wenzelm@53255
  1930
    by blast
wenzelm@53255
  1931
  then show ?thesis
wenzelm@64539
  1932
    by (simp add: th0 th1)
wenzelm@64539
  1933
qed
wenzelm@64539
  1934
wenzelm@64539
  1935
wenzelm@64539
  1936
subsection \<open>Limit points\<close>
himmelma@33175
  1937
wenzelm@53282
  1938
definition (in topological_space) islimpt:: "'a \<Rightarrow> 'a set \<Rightarrow> bool"  (infixr "islimpt" 60)
wenzelm@53255
  1939
  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
  1940
himmelma@33175
  1941
lemma islimptI:
himmelma@33175
  1942
  assumes "\<And>T. x \<in> T \<Longrightarrow> open T \<Longrightarrow> \<exists>y\<in>S. y \<in> T \<and> y \<noteq> x"
himmelma@33175
  1943
  shows "x islimpt S"
himmelma@33175
  1944
  using assms unfolding islimpt_def by auto
himmelma@33175
  1945
himmelma@33175
  1946
lemma islimptE:
himmelma@33175
  1947
  assumes "x islimpt S" and "x \<in> T" and "open T"
himmelma@33175
  1948
  obtains y where "y \<in> S" and "y \<in> T" and "y \<noteq> x"
himmelma@33175
  1949
  using assms unfolding islimpt_def by auto
himmelma@33175
  1950
huffman@44584
  1951
lemma islimpt_iff_eventually: "x islimpt S \<longleftrightarrow> \<not> eventually (\<lambda>y. y \<notin> S) (at x)"
huffman@44584
  1952
  unfolding islimpt_def eventually_at_topological by auto
huffman@44584
  1953
wenzelm@53255
  1954
lemma islimpt_subset: "x islimpt S \<Longrightarrow> S \<subseteq> T \<Longrightarrow> x islimpt T"
huffman@44584
  1955
  unfolding islimpt_def by fast
himmelma@33175
  1956
himmelma@33175
  1957
lemma islimpt_approachable:
himmelma@33175
  1958
  fixes x :: "'a::metric_space"
himmelma@33175
  1959
  shows "x islimpt S \<longleftrightarrow> (\<forall>e>0. \<exists>x'\<in>S. x' \<noteq> x \<and> dist x' x < e)"
huffman@44584
  1960
  unfolding islimpt_iff_eventually eventually_at by fast
himmelma@33175
  1961
wenzelm@64539
  1962
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
  1963
  for x :: "'a::metric_space"
himmelma@33175
  1964
  unfolding islimpt_approachable
huffman@44584
  1965
  using approachable_lt_le [where f="\<lambda>y. dist y x" and P="\<lambda>y. y \<notin> S \<or> y = x",
huffman@44584
  1966
    THEN arg_cong [where f=Not]]
huffman@44584
  1967
  by (simp add: Bex_def conj_commute conj_left_commute)
himmelma@33175
  1968
huffman@44571
  1969
lemma islimpt_UNIV_iff: "x islimpt UNIV \<longleftrightarrow> \<not> open {x}"
huffman@44571
  1970
  unfolding islimpt_def by (safe, fast, case_tac "T = {x}", fast, fast)
huffman@44571
  1971
hoelzl@51351
  1972
lemma islimpt_punctured: "x islimpt S = x islimpt (S-{x})"
hoelzl@51351
  1973
  unfolding islimpt_def by blast
hoelzl@51351
  1974
wenzelm@60420
  1975
text \<open>A perfect space has no isolated points.\<close>
huffman@44210
  1976
wenzelm@64539
  1977
lemma islimpt_UNIV [simp, intro]: "x islimpt UNIV"
wenzelm@64539
  1978
  for x :: "'a::perfect_space"
huffman@44571
  1979
  unfolding islimpt_UNIV_iff by (rule not_open_singleton)
himmelma@33175
  1980
wenzelm@64539
  1981
lemma perfect_choose_dist: "0 < r \<Longrightarrow> \<exists>a. a \<noteq> x \<and> dist a x < r"
wenzelm@64539
  1982
  for x :: "'a::{perfect_space,metric_space}"
wenzelm@64539
  1983
  using islimpt_UNIV [of x] by (simp add: islimpt_approachable)
himmelma@33175
  1984
himmelma@33175
  1985
lemma closed_limpt: "closed S \<longleftrightarrow> (\<forall>x. x islimpt S \<longrightarrow> x \<in> S)"
himmelma@33175
  1986
  unfolding closed_def
himmelma@33175
  1987
  apply (subst open_subopen)
huffman@34105
  1988
  apply (simp add: islimpt_def subset_eq)
wenzelm@52624
  1989
  apply (metis ComplE ComplI)
wenzelm@52624
  1990
  done
himmelma@33175
  1991
himmelma@33175
  1992
lemma islimpt_EMPTY[simp]: "\<not> x islimpt {}"
lp15@66643
  1993
  by (auto simp: islimpt_def)
himmelma@33175
  1994
himmelma@33175
  1995
lemma finite_set_avoid:
himmelma@33175
  1996
  fixes a :: "'a::metric_space"
wenzelm@53255
  1997
  assumes fS: "finite S"
wenzelm@64539
  1998
  shows "\<exists>d>0. \<forall>x\<in>S. x \<noteq> a \<longrightarrow> d \<le> dist a x"
wenzelm@53255
  1999
proof (induct rule: finite_induct[OF fS])
wenzelm@53255
  2000
  case 1
wenzelm@53255
  2001
  then show ?case by (auto intro: zero_less_one)
himmelma@33175
  2002
next
himmelma@33175
  2003
  case (2 x F)
wenzelm@60462
  2004
  from 2 obtain d where d: "d > 0" "\<forall>x\<in>F. x \<noteq> a \<longrightarrow> d \<le> dist a x"
wenzelm@53255
  2005
    by blast
wenzelm@53255
  2006
  show ?case
wenzelm@53255
  2007
  proof (cases "x = a")
wenzelm@53255
  2008
    case True
wenzelm@64539
  2009
    with d show ?thesis by auto
wenzelm@53255
  2010
  next
wenzelm@53255
  2011
    case False
himmelma@33175
  2012
    let ?d = "min d (dist a x)"
wenzelm@64539
  2013
    from False d(1) have dp: "?d > 0"
wenzelm@64539
  2014
      by auto
wenzelm@60462
  2015
    from d have d': "\<forall>x\<in>F. x \<noteq> a \<longrightarrow> ?d \<le> dist a x"
wenzelm@53255
  2016
      by auto
wenzelm@53255
  2017
    with dp False show ?thesis
wenzelm@53255
  2018
      by (auto intro!: exI[where x="?d"])
wenzelm@53255
  2019
  qed
himmelma@33175
  2020
qed
himmelma@33175
  2021
himmelma@33175
  2022
lemma islimpt_Un: "x islimpt (S \<union> T) \<longleftrightarrow> x islimpt S \<or> x islimpt T"
huffman@50897
  2023
  by (simp add: islimpt_iff_eventually eventually_conj_iff)
himmelma@33175
  2024
himmelma@33175
  2025
lemma discrete_imp_closed:
himmelma@33175
  2026
  fixes S :: "'a::metric_space set"
wenzelm@53255
  2027
  assumes e: "0 < e"
wenzelm@53255
  2028
    and d: "\<forall>x \<in> S. \<forall>y \<in> S. dist y x < e \<longrightarrow> y = x"
himmelma@33175
  2029
  shows "closed S"
wenzelm@53255
  2030
proof -
wenzelm@64539
  2031
  have False if C: "\<forall>e>0. \<exists>x'\<in>S. x' \<noteq> x \<and> dist x' x < e" for x
wenzelm@64539
  2032
  proof -
himmelma@33175
  2033
    from e have e2: "e/2 > 0" by arith
wenzelm@53282
  2034
    from C[rule_format, OF e2] obtain y where y: "y \<in> S" "y \<noteq> x" "dist y x < e/2"
wenzelm@53255
  2035
      by blast
himmelma@33175
  2036
    let ?m = "min (e/2) (dist x y) "
wenzelm@53255
  2037
    from e2 y(2) have mp: "?m > 0"
paulson@62087
  2038
      by simp
wenzelm@53282
  2039
    from C[rule_format, OF mp] obtain z where z: "z \<in> S" "z \<noteq> x" "dist z x < ?m"
wenzelm@53255
  2040
      by blast
wenzelm@64539
  2041
    from z y have "dist z y < e"
wenzelm@64539
  2042
      by (intro dist_triangle_lt [where z=x]) simp
wenzelm@64539
  2043
    from d[rule_format, OF y(1) z(1) this] y z show ?thesis
lp15@66643
  2044
      by (auto simp: dist_commute)
wenzelm@64539
  2045
  qed
wenzelm@53255
  2046
  then show ?thesis
wenzelm@53255
  2047
    by (metis islimpt_approachable closed_limpt [where 'a='a])
himmelma@33175
  2048
qed
himmelma@33175
  2049
wenzelm@64539
  2050
lemma closed_of_nat_image: "closed (of_nat ` A :: 'a::real_normed_algebra_1 set)"
eberlm@61524
  2051
  by (rule discrete_imp_closed[of 1]) (auto simp: dist_of_nat)
eberlm@61524
  2052
wenzelm@64539
  2053
lemma closed_of_int_image: "closed (of_int ` A :: 'a::real_normed_algebra_1 set)"
eberlm@61524
  2054
  by (rule discrete_imp_closed[of 1]) (auto simp: dist_of_int)
eberlm@61524
  2055
eberlm@61524
  2056
lemma closed_Nats [simp]: "closed (\<nat> :: 'a :: real_normed_algebra_1 set)"
eberlm@61524
  2057
  unfolding Nats_def by (rule closed_of_nat_image)
eberlm@61524
  2058
eberlm@61524
  2059
lemma closed_Ints [simp]: "closed (\<int> :: 'a :: real_normed_algebra_1 set)"
eberlm@61524
  2060
  unfolding Ints_def by (rule closed_of_int_image)
eberlm@61524
  2061
lp15@66643
  2062
lemma closed_subset_Ints:
eberlm@66286
  2063
  fixes A :: "'a :: real_normed_algebra_1 set"
eberlm@66286
  2064
  assumes "A \<subseteq> \<int>"
eberlm@66286
  2065
  shows   "closed A"
eberlm@66286
  2066
proof (intro discrete_imp_closed[OF zero_less_one] ballI impI, goal_cases)
eberlm@66286
  2067
  case (1 x y)
eberlm@66286
  2068
  with assms have "x \<in> \<int>" and "y \<in> \<int>" by auto
eberlm@66286
  2069
  with \<open>dist y x < 1\<close> show "y = x"
eberlm@66286
  2070
    by (auto elim!: Ints_cases simp: dist_of_int)
eberlm@66286
  2071
qed
eberlm@66286
  2072
huffman@44210
  2073
wenzelm@60420
  2074
subsection \<open>Interior of a Set\<close>
huffman@44210
  2075
huffman@44519
  2076
definition "interior S = \<Union>{T. open T \<and> T \<subseteq> S}"
huffman@44519
  2077
huffman@44519
  2078
lemma interiorI [intro?]:
huffman@44519
  2079
  assumes "open T" and "x \<in> T" and "T \<subseteq> S"
huffman@44519
  2080
  shows "x \<in> interior S"
huffman@44519
  2081
  using assms unfolding interior_def by fast
huffman@44519
  2082
huffman@44519
  2083
lemma interiorE [elim?]:
huffman@44519
  2084
  assumes "x \<in> interior S"
huffman@44519
  2085
  obtains T where "open T" and "x \<in> T" and "T \<subseteq> S"
huffman@44519
  2086
  using assms unfolding interior_def by fast
huffman@44519
  2087
huffman@44519
  2088
lemma open_interior [simp, intro]: "open (interior S)"
huffman@44519
  2089
  by (simp add: interior_def open_Union)
huffman@44519
  2090
huffman@44519
  2091
lemma interior_subset: "interior S \<subseteq> S"
lp15@66643
  2092
  by (auto simp: interior_def)
huffman@44519
  2093
huffman@44519
  2094
lemma interior_maximal: "T \<subseteq> S \<Longrightarrow> open T \<Longrightarrow> T \<subseteq> interior S"
lp15@66643
  2095
  by (auto simp: interior_def)
huffman@44519
  2096
huffman@44519
  2097
lemma interior_open: "open S \<Longrightarrow> interior S = S"
huffman@44519
  2098
  by (intro equalityI interior_subset interior_maximal subset_refl)
himmelma@33175
  2099
himmelma@33175
  2100
lemma interior_eq: "interior S = S \<longleftrightarrow> open S"
huffman@44519
  2101
  by (metis open_interior interior_open)
huffman@44519
  2102
huffman@44519
  2103
lemma open_subset_interior: "open S \<Longrightarrow> S \<subseteq> interior T \<longleftrightarrow> S \<subseteq> T"
himmelma@33175
  2104
  by (metis interior_maximal interior_subset subset_trans)
himmelma@33175
  2105
huffman@44519
  2106
lemma interior_empty [simp]: "interior {} = {}"
huffman@44519
  2107
  using open_empty by (rule interior_open)
huffman@44519
  2108
huffman@44522
  2109
lemma interior_UNIV [simp]: "interior UNIV = UNIV"
huffman@44522
  2110
  using open_UNIV by (rule interior_open)
huffman@44522
  2111
huffman@44519
  2112
lemma interior_interior [simp]: "interior (interior S) = interior S"
huffman@44519
  2113
  using open_interior by (rule interior_open)
huffman@44519
  2114
huffman@44522
  2115
lemma interior_mono: "S \<subseteq> T \<Longrightarrow> interior S \<subseteq> interior T"
lp15@66643
  2116
  by (auto simp: interior_def)
huffman@44519
  2117
huffman@44519
  2118
lemma interior_unique:
huffman@44519
  2119
  assumes "T \<subseteq> S" and "open T"
huffman@44519
  2120
  assumes "\<And>T'. T' \<subseteq> S \<Longrightarrow> open T' \<Longrightarrow> T' \<subseteq> T"
huffman@44519
  2121
  shows "interior S = T"
huffman@44519
  2122
  by (intro equalityI assms interior_subset open_interior interior_maximal)
huffman@44519
  2123
wenzelm@64539
  2124
lemma interior_singleton [simp]: "interior {a} = {}"
wenzelm@64539
  2125
  for a :: "'a::perfect_space"
lp15@66643
  2126
  apply (rule interior_unique, simp_all)
wenzelm@64539
  2127
  using not_open_singleton subset_singletonD
wenzelm@64539
  2128
  apply fastforce
wenzelm@64539
  2129
  done
paulson@61518
  2130
paulson@61518
  2131
lemma interior_Int [simp]: "interior (S \<inter> T) = interior S \<inter> interior T"
huffman@44522
  2132
  by (intro equalityI Int_mono Int_greatest interior_mono Int_lower1
huffman@44519
  2133
    Int_lower2 interior_maximal interior_subset open_Int open_interior)
huffman@44519
  2134
huffman@44519
  2135
lemma mem_interior: "x \<in> interior S \<longleftrightarrow> (\<exists>e>0. ball x e \<subseteq> S)"
huffman@44519
  2136
  using open_contains_ball_eq [where S="interior S"]
huffman@44519
  2137
  by (simp add: open_subset_interior)
himmelma@33175
  2138
eberlm@61531
  2139
lemma eventually_nhds_in_nhd: "x \<in> interior s \<Longrightarrow> eventually (\<lambda>y. y \<in> s) (nhds x)"
eberlm@61531
  2140
  using interior_subset[of s] by (subst eventually_nhds) blast
eberlm@61531
  2141
himmelma@33175
  2142
lemma interior_limit_point [intro]:
himmelma@33175
  2143
  fixes x :: "'a::perfect_space"
wenzelm@53255
  2144
  assumes x: "x \<in> interior S"
wenzelm@53255
  2145
  shows "x islimpt S"
huffman@44072
  2146
  using x islimpt_UNIV [of x]
huffman@44072
  2147
  unfolding interior_def islimpt_def
huffman@44072
  2148
  apply (clarsimp, rename_tac T T')
huffman@44072
  2149
  apply (drule_tac x="T \<inter> T'" in spec)
lp15@66643
  2150
  apply (auto simp: open_Int)
huffman@44072
  2151
  done
himmelma@33175
  2152
himmelma@33175
  2153
lemma interior_closed_Un_empty_interior:
wenzelm@53255
  2154
  assumes cS: "closed S"
wenzelm@53255
  2155
    and iT: "interior T = {}"
huffman@44519
  2156
  shows "interior (S \<union> T) = interior S"
himmelma@33175
  2157
proof
huffman@44519
  2158
  show "interior S \<subseteq> interior (S \<union> T)"
wenzelm@53255
  2159
    by (rule interior_mono) (rule Un_upper1)
himmelma@33175
  2160
  show "interior (S \<union> T) \<subseteq> interior S"
himmelma@33175
  2161
  proof
wenzelm@53255
  2162
    fix x
wenzelm@53255
  2163
    assume "x \<in> interior (S \<union> T)"
huffman@44519
  2164
    then obtain R where "open R" "x \<in> R" "R \<subseteq> S \<union> T" ..
himmelma@33175
  2165
    show "x \<in> interior S"
himmelma@33175
  2166
    proof (rule ccontr)
himmelma@33175
  2167
      assume "x \<notin> interior S"
wenzelm@60420
  2168
      with \<open>x \<in> R\<close> \<open>open R\<close> obtain y where "y \<in> R - S"
huffman@44519
  2169
        unfolding interior_def by fast
wenzelm@60420
  2170
      from \<open>open R\<close> \<open>closed S\<close> have "open (R - S)"
wenzelm@53282
  2171
        by (rule open_Diff)
wenzelm@60420
  2172
      from \<open>R \<subseteq> S \<union> T\<close> have "R - S \<subseteq> T"
wenzelm@53282
  2173
        by fast
wenzelm@60420
  2174
      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
  2175
        unfolding interior_def by fast
himmelma@33175
  2176
    qed
himmelma@33175
  2177
  qed
himmelma@33175
  2178
qed
himmelma@33175
  2179
huffman@44365
  2180
lemma interior_Times: "interior (A \<times> B) = interior A \<times> interior B"
huffman@44365
  2181
proof (rule interior_unique)
huffman@44365
  2182
  show "interior A \<times> interior B \<subseteq> A \<times> B"
huffman@44365
  2183
    by (intro Sigma_mono interior_subset)
huffman@44365
  2184
  show "open (interior A \<times> interior B)"
huffman@44365
  2185
    by (intro open_Times open_interior)
wenzelm@53255
  2186
  fix T
wenzelm@53255
  2187
  assume "T \<subseteq> A \<times> B" and "open T"
wenzelm@53255
  2188
  then show "T \<subseteq> interior A \<times> interior B"
wenzelm@53282
  2189
  proof safe
wenzelm@53255
  2190
    fix x y
wenzelm@53255
  2191
    assume "(x, y) \<in> T"
huffman@44519
  2192
    then obtain C D where "open C" "open D" "C \<times> D \<subseteq> T" "x \<in> C" "y \<in> D"
wenzelm@60420
  2193
      using \<open>open T\<close> unfolding open_prod_def by fast
wenzelm@53255
  2194
    then have "open C" "open D" "C \<subseteq> A" "D \<subseteq> B" "x \<in> C" "y \<in> D"
wenzelm@60420
  2195
      using \<open>T \<subseteq> A \<times> B\<close> by auto
wenzelm@53255
  2196
    then show "x \<in> interior A" and "y \<in> interior B"
huffman@44519
  2197
      by (auto intro: interiorI)
huffman@44519
  2198
  qed
huffman@44365
  2199
qed
huffman@44365
  2200
hoelzl@61245
  2201
lemma interior_Ici:
wenzelm@64539
  2202
  fixes x :: "'a :: {dense_linorder,linorder_topology}"
hoelzl@61245
  2203
  assumes "b < x"
wenzelm@64539
  2204
  shows "interior {x ..} = {x <..}"
hoelzl@61245
  2205
proof (rule interior_unique)
wenzelm@64539
  2206
  fix T
wenzelm@64539
  2207
  assume "T \<subseteq> {x ..}" "open T"
hoelzl@61245
  2208
  moreover have "x \<notin> T"
hoelzl@61245
  2209
  proof
hoelzl@61245
  2210
    assume "x \<in> T"
hoelzl@61245
  2211
    obtain y where "y < x" "{y <.. x} \<subseteq> T"
hoelzl@61245
  2212
      using open_left[OF \<open>open T\<close> \<open>x \<in> T\<close> \<open>b < x\<close>] by auto
hoelzl@61245
  2213
    with dense[OF \<open>y < x\<close>] obtain z where "z \<in> T" "z < x"
hoelzl@61245
  2214
      by (auto simp: subset_eq Ball_def)
hoelzl@61245
  2215
    with \<open>T \<subseteq> {x ..}\<close> show False by auto
hoelzl@61245
  2216
  qed
hoelzl@61245
  2217
  ultimately show "T \<subseteq> {x <..}"
hoelzl@61245
  2218
    by (auto simp: subset_eq less_le)
hoelzl@61245
  2219
qed auto
hoelzl@61245
  2220
hoelzl@61245
  2221
lemma interior_Iic:
wenzelm@64539
  2222
  fixes x :: "'a ::{dense_linorder,linorder_topology}"
hoelzl@61245
  2223
  assumes "x < b"
hoelzl@61245
  2224
  shows "interior {.. x} = {..< x}"
hoelzl@61245
  2225
proof (rule interior_unique)
wenzelm@64539
  2226
  fix T
wenzelm@64539
  2227
  assume "T \<subseteq> {.. x}" "open T"
hoelzl@61245
  2228
  moreover have "x \<notin> T"
hoelzl@61245
  2229
  proof
hoelzl@61245
  2230
    assume "x \<in> T"
hoelzl@61245
  2231
    obtain y where "x < y" "{x ..< y} \<subseteq> T"
hoelzl@61245
  2232
      using open_right[OF \<open>open T\<close> \<open>x \<in> T\<close> \<open>x < b\<close>] by auto
hoelzl@61245
  2233
    with dense[OF \<open>x < y\<close>] obtain z where "z \<in> T" "x < z"
hoelzl@61245
  2234
      by (auto simp: subset_eq Ball_def less_le)
hoelzl@61245
  2235
    with \<open>T \<subseteq> {.. x}\<close> show False by auto
hoelzl@61245
  2236
  qed
hoelzl@61245
  2237
  ultimately show "T \<subseteq> {..< x}"
hoelzl@61245
  2238
    by (auto simp: subset_eq less_le)
hoelzl@61245
  2239
qed auto
himmelma@33175
  2240
wenzelm@64539
  2241
wenzelm@60420
  2242
subsection \<open>Closure of a Set\<close>
himmelma@33175
  2243
himmelma@33175
  2244
definition "closure S = S \<union> {x | x. x islimpt S}"
himmelma@33175
  2245
huffman@44518
  2246
lemma interior_closure: "interior S = - (closure (- S))"
lp15@66643
  2247
  by (auto simp: interior_def closure_def islimpt_def)
huffman@44518
  2248
huffman@34105
  2249
lemma closure_interior: "closure S = - interior (- S)"
wenzelm@64539
  2250
  by (simp add: interior_closure)
himmelma@33175
  2251
himmelma@33175
  2252
lemma closed_closure[simp, intro]: "closed (closure S)"
wenzelm@64539
  2253
  by (simp add: closure_interior closed_Compl)
huffman@44518