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