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