src/HOL/Multivariate_Analysis/Topology_Euclidean_Space.thy
author huffman
Tue, 15 Jan 2013 19:28:48 -0800
changeset 51963 8c742f9de9f5
parent 51959 03b11adf1f33
child 51964 a5689bb4ed7e
permissions -rw-r--r--
generalize topology lemmas; simplify proofs
hoelzl@33711
     1
(*  title:      HOL/Library/Topology_Euclidian_Space.thy
himmelma@33175
     2
    Author:     Amine Chaieb, University of Cambridge
himmelma@33175
     3
    Author:     Robert Himmelmann, TU Muenchen
huffman@44946
     4
    Author:     Brian Huffman, Portland State University
himmelma@33175
     5
*)
himmelma@33175
     6
himmelma@33175
     7
header {* Elementary topology in Euclidean space. *}
himmelma@33175
     8
himmelma@33175
     9
theory Topology_Euclidean_Space
immler@51102
    10
imports
hoelzl@51953
    11
  Complex_Main
immler@51102
    12
  "~~/src/HOL/Library/Diagonal_Subsequence"
immler@51260
    13
  "~~/src/HOL/Library/Countable_Set"
immler@51102
    14
  "~~/src/HOL/Library/Glbs"
hoelzl@51541
    15
  "~~/src/HOL/Library/FuncSet"
hoelzl@51953
    16
  Linear_Algebra
immler@51102
    17
  Norm_Arith
himmelma@33175
    18
begin
himmelma@33175
    19
hoelzl@51958
    20
lemma dist_double: "dist x y < d / 2 \<Longrightarrow> dist x z < d / 2 \<Longrightarrow> dist y z < d"
hoelzl@51958
    21
  using dist_triangle[of y z x] by (simp add: dist_commute)
hoelzl@51958
    22
hoelzl@51957
    23
(* TODO: Move this to RComplete.thy -- would need to include Glb into RComplete *)
hoelzl@51957
    24
lemma real_isGlb_unique: "[| isGlb R S x; isGlb R S y |] ==> x = (y::real)"
hoelzl@51957
    25
  apply (frule isGlb_isLb)
hoelzl@51957
    26
  apply (frule_tac x = y in isGlb_isLb)
hoelzl@51957
    27
  apply (blast intro!: order_antisym dest!: isGlb_le_isLb)
hoelzl@51957
    28
  done
hoelzl@51957
    29
hoelzl@51541
    30
lemma countable_PiE: 
hoelzl@51541
    31
  "finite I \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> countable (F i)) \<Longrightarrow> countable (PiE I F)"
hoelzl@51541
    32
  by (induct I arbitrary: F rule: finite_induct) (auto simp: PiE_insert_eq)
hoelzl@51541
    33
immler@51102
    34
subsection {* Topological Basis *}
immler@51102
    35
immler@51102
    36
context topological_space
immler@51102
    37
begin
immler@51102
    38
immler@51102
    39
definition "topological_basis B =
immler@51102
    40
  ((\<forall>b\<in>B. open b) \<and> (\<forall>x. open x \<longrightarrow> (\<exists>B'. B' \<subseteq> B \<and> Union B' = x)))"
immler@51102
    41
immler@51102
    42
lemma topological_basis_iff:
immler@51102
    43
  assumes "\<And>B'. B' \<in> B \<Longrightarrow> open B'"
immler@51102
    44
  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@51102
    45
    (is "_ \<longleftrightarrow> ?rhs")
immler@51102
    46
proof safe
immler@51102
    47
  fix O' and x::'a
immler@51102
    48
  assume H: "topological_basis B" "open O'" "x \<in> O'"
immler@51102
    49
  hence "(\<exists>B'\<subseteq>B. \<Union>B' = O')" by (simp add: topological_basis_def)
immler@51102
    50
  then obtain B' where "B' \<subseteq> B" "O' = \<Union>B'" by auto
immler@51102
    51
  thus "\<exists>B'\<in>B. x \<in> B' \<and> B' \<subseteq> O'" using H by auto
immler@51102
    52
next
immler@51102
    53
  assume H: ?rhs
immler@51102
    54
  show "topological_basis B" using assms unfolding topological_basis_def
immler@51102
    55
  proof safe
immler@51102
    56
    fix O'::"'a set" assume "open O'"
immler@51102
    57
    with H obtain f where "\<forall>x\<in>O'. f x \<in> B \<and> x \<in> f x \<and> f x \<subseteq> O'"
immler@51102
    58
      by (force intro: bchoice simp: Bex_def)
immler@51102
    59
    thus "\<exists>B'\<subseteq>B. \<Union>B' = O'"
immler@51102
    60
      by (auto intro: exI[where x="{f x |x. x \<in> O'}"])
immler@51102
    61
  qed
immler@51102
    62
qed
immler@51102
    63
immler@51102
    64
lemma topological_basisI:
immler@51102
    65
  assumes "\<And>B'. B' \<in> B \<Longrightarrow> open B'"
immler@51102
    66
  assumes "\<And>O' x. open O' \<Longrightarrow> x \<in> O' \<Longrightarrow> \<exists>B'\<in>B. x \<in> B' \<and> B' \<subseteq> O'"
immler@51102
    67
  shows "topological_basis B"
immler@51102
    68
  using assms by (subst topological_basis_iff) auto
immler@51102
    69
immler@51102
    70
lemma topological_basisE:
immler@51102
    71
  fixes O'
immler@51102
    72
  assumes "topological_basis B"
immler@51102
    73
  assumes "open O'"
immler@51102
    74
  assumes "x \<in> O'"
immler@51102
    75
  obtains B' where "B' \<in> B" "x \<in> B'" "B' \<subseteq> O'"
immler@51102
    76
proof atomize_elim
immler@51102
    77
  from assms have "\<And>B'. B'\<in>B \<Longrightarrow> open B'" by (simp add: topological_basis_def)
immler@51102
    78
  with topological_basis_iff assms
immler@51102
    79
  show  "\<exists>B'. B' \<in> B \<and> x \<in> B' \<and> B' \<subseteq> O'" using assms by (simp add: Bex_def)
immler@51102
    80
qed
immler@51102
    81
immler@51109
    82
lemma topological_basis_open:
immler@51109
    83
  assumes "topological_basis B"
immler@51109
    84
  assumes "X \<in> B"
immler@51109
    85
  shows "open X"
immler@51109
    86
  using assms
immler@51109
    87
  by (simp add: topological_basis_def)
immler@51109
    88
immler@51260
    89
lemma basis_dense:
immler@51260
    90
  fixes B::"'a set set" and f::"'a set \<Rightarrow> 'a"
immler@51260
    91
  assumes "topological_basis B"
immler@51260
    92
  assumes choosefrom_basis: "\<And>B'. B' \<noteq> {} \<Longrightarrow> f B' \<in> B'"
immler@51260
    93
  shows "(\<forall>X. open X \<longrightarrow> X \<noteq> {} \<longrightarrow> (\<exists>B' \<in> B. f B' \<in> X))"
immler@51260
    94
proof (intro allI impI)
immler@51260
    95
  fix X::"'a set" assume "open X" "X \<noteq> {}"
immler@51260
    96
  from topological_basisE[OF `topological_basis B` `open X` choosefrom_basis[OF `X \<noteq> {}`]]
immler@51260
    97
  guess B' . note B' = this
immler@51260
    98
  thus "\<exists>B'\<in>B. f B' \<in> X" by (auto intro!: choosefrom_basis)
immler@51260
    99
qed
immler@51260
   100
immler@51102
   101
end
immler@51102
   102
hoelzl@51897
   103
lemma topological_basis_prod:
hoelzl@51897
   104
  assumes A: "topological_basis A" and B: "topological_basis B"
hoelzl@51897
   105
  shows "topological_basis ((\<lambda>(a, b). a \<times> b) ` (A \<times> B))"
hoelzl@51897
   106
  unfolding topological_basis_def
hoelzl@51897
   107
proof (safe, simp_all del: ex_simps add: subset_image_iff ex_simps(1)[symmetric])
hoelzl@51897
   108
  fix S :: "('a \<times> 'b) set" assume "open S"
hoelzl@51897
   109
  then show "\<exists>X\<subseteq>A \<times> B. (\<Union>(a,b)\<in>X. a \<times> b) = S"
hoelzl@51897
   110
  proof (safe intro!: exI[of _ "{x\<in>A \<times> B. fst x \<times> snd x \<subseteq> S}"])
hoelzl@51897
   111
    fix x y assume "(x, y) \<in> S"
hoelzl@51897
   112
    from open_prod_elim[OF `open S` this]
hoelzl@51897
   113
    obtain a b where a: "open a""x \<in> a" and b: "open b" "y \<in> b" and "a \<times> b \<subseteq> S"
hoelzl@51897
   114
      by (metis mem_Sigma_iff)
hoelzl@51897
   115
    moreover from topological_basisE[OF A a] guess A0 .
hoelzl@51897
   116
    moreover from topological_basisE[OF B b] guess B0 .
hoelzl@51897
   117
    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@51897
   118
      by (intro UN_I[of "(A0, B0)"]) auto
hoelzl@51897
   119
  qed auto
hoelzl@51897
   120
qed (metis A B topological_basis_open open_Times)
hoelzl@51897
   121
immler@51260
   122
subsection {* Countable Basis *}
immler@51260
   123
immler@51260
   124
locale countable_basis =
immler@51260
   125
  fixes B::"'a::topological_space set set"
immler@51260
   126
  assumes is_basis: "topological_basis B"
immler@51260
   127
  assumes countable_basis: "countable B"
immler@51102
   128
begin
immler@51102
   129
immler@51260
   130
lemma open_countable_basis_ex:
immler@51102
   131
  assumes "open X"
immler@51260
   132
  shows "\<exists>B' \<subseteq> B. X = Union B'"
immler@51260
   133
  using assms countable_basis is_basis unfolding topological_basis_def by blast
immler@51260
   134
immler@51260
   135
lemma open_countable_basisE:
immler@51260
   136
  assumes "open X"
immler@51260
   137
  obtains B' where "B' \<subseteq> B" "X = Union B'"
immler@51260
   138
  using assms open_countable_basis_ex by (atomize_elim) simp
immler@51260
   139
immler@51260
   140
lemma countable_dense_exists:
immler@51260
   141
  shows "\<exists>D::'a set. countable D \<and> (\<forall>X. open X \<longrightarrow> X \<noteq> {} \<longrightarrow> (\<exists>d \<in> D. d \<in> X))"
immler@51102
   142
proof -
immler@51260
   143
  let ?f = "(\<lambda>B'. SOME x. x \<in> B')"
immler@51260
   144
  have "countable (?f ` B)" using countable_basis by simp
immler@51260
   145
  with basis_dense[OF is_basis, of ?f] show ?thesis
immler@51260
   146
    by (intro exI[where x="?f ` B"]) (metis (mono_tags) all_not_in_conv imageI someI)
immler@51102
   147
qed
immler@51102
   148
immler@51102
   149
lemma countable_dense_setE:
immler@51260
   150
  obtains D :: "'a set"
immler@51260
   151
  where "countable D" "\<And>X. open X \<Longrightarrow> X \<noteq> {} \<Longrightarrow> \<exists>d \<in> D. d \<in> X"
immler@51260
   152
  using countable_dense_exists by blast
immler@51260
   153
immler@51260
   154
text {* Construction of an increasing sequence approximating open sets,
immler@51260
   155
  therefore basis which is closed under union. *}
immler@51260
   156
immler@51260
   157
definition union_closed_basis::"'a set set" where
immler@51260
   158
  "union_closed_basis = (\<lambda>l. \<Union>set l) ` lists B"
immler@51260
   159
immler@51260
   160
lemma basis_union_closed_basis: "topological_basis union_closed_basis"
immler@51109
   161
proof (rule topological_basisI)
immler@51109
   162
  fix O' and x::'a assume "open O'" "x \<in> O'"
immler@51260
   163
  from topological_basisE[OF is_basis this] guess B' . note B' = this
immler@51260
   164
  thus "\<exists>B'\<in>union_closed_basis. x \<in> B' \<and> B' \<subseteq> O'" unfolding union_closed_basis_def
immler@51260
   165
    by (auto intro!: bexI[where x="[B']"])
immler@51109
   166
next
immler@51260
   167
  fix B' assume "B' \<in> union_closed_basis"
immler@51260
   168
  thus "open B'"
immler@51260
   169
    using topological_basis_open[OF is_basis]
immler@51260
   170
    by (auto simp: union_closed_basis_def)
immler@51260
   171
qed
immler@51260
   172
immler@51260
   173
lemma countable_union_closed_basis: "countable union_closed_basis"
immler@51260
   174
  unfolding union_closed_basis_def using countable_basis by simp
immler@51260
   175
immler@51260
   176
lemmas open_union_closed_basis = topological_basis_open[OF basis_union_closed_basis]
immler@51260
   177
immler@51260
   178
lemma union_closed_basis_ex:
immler@51260
   179
 assumes X: "X \<in> union_closed_basis"
immler@51260
   180
 shows "\<exists>B'. finite B' \<and> X = \<Union>B' \<and> B' \<subseteq> B"
immler@51260
   181
proof -
immler@51260
   182
  from X obtain l where "\<And>x. x\<in>set l \<Longrightarrow> x\<in>B" "X = \<Union>set l" by (auto simp: union_closed_basis_def)
immler@51260
   183
  thus ?thesis by auto
immler@51260
   184
qed
immler@51260
   185
immler@51260
   186
lemma union_closed_basisE:
immler@51260
   187
  assumes "X \<in> union_closed_basis"
immler@51260
   188
  obtains B' where "finite B'" "X = \<Union>B'" "B' \<subseteq> B" using union_closed_basis_ex[OF assms] by blast
immler@51260
   189
immler@51260
   190
lemma union_closed_basisI:
immler@51260
   191
  assumes "finite B'" "X = \<Union>B'" "B' \<subseteq> B"
immler@51260
   192
  shows "X \<in> union_closed_basis"
immler@51260
   193
proof -
immler@51260
   194
  from finite_list[OF `finite B'`] guess l ..
immler@51260
   195
  thus ?thesis using assms unfolding union_closed_basis_def by (auto intro!: image_eqI[where x=l])
immler@51260
   196
qed
immler@51260
   197
immler@51260
   198
lemma empty_basisI[intro]: "{} \<in> union_closed_basis"
immler@51260
   199
  by (rule union_closed_basisI[of "{}"]) auto
immler@51102
   200
immler@51102
   201
lemma union_basisI[intro]:
immler@51260
   202
  assumes "X \<in> union_closed_basis" "Y \<in> union_closed_basis"
immler@51260
   203
  shows "X \<union> Y \<in> union_closed_basis"
immler@51260
   204
  using assms by (auto intro: union_closed_basisI elim!:union_closed_basisE)
immler@51102
   205
immler@51102
   206
lemma open_imp_Union_of_incseq:
immler@51102
   207
  assumes "open X"
immler@51260
   208
  shows "\<exists>S. incseq S \<and> (\<Union>j. S j) = X \<and> range S \<subseteq> union_closed_basis"
immler@51102
   209
proof -
immler@51260
   210
  from open_countable_basis_ex[OF `open X`]
immler@51260
   211
  obtain B' where B': "B'\<subseteq>B" "X = \<Union>B'" by auto
immler@51260
   212
  from this(1) countable_basis have "countable B'" by (rule countable_subset)
immler@51260
   213
  show ?thesis
immler@51260
   214
  proof cases
immler@51260
   215
    assume "B' \<noteq> {}"
immler@51260
   216
    def S \<equiv> "\<lambda>n. \<Union>i\<in>{0..n}. from_nat_into B' i"
immler@51260
   217
    have S:"\<And>n. S n = \<Union>{from_nat_into B' i|i. i\<in>{0..n}}" unfolding S_def by force
immler@51260
   218
    have "incseq S" by (force simp: S_def incseq_Suc_iff)
immler@51260
   219
    moreover
immler@51260
   220
    have "(\<Union>j. S j) = X" unfolding B'
immler@51260
   221
    proof safe
immler@51260
   222
      fix x X assume "X \<in> B'" "x \<in> X"
immler@51260
   223
      then obtain n where "X = from_nat_into B' n"
immler@51260
   224
        by (metis `countable B'` from_nat_into_surj)
immler@51260
   225
      also have "\<dots> \<subseteq> S n" by (auto simp: S_def)
immler@51260
   226
      finally show "x \<in> (\<Union>j. S j)" using `x \<in> X` by auto
immler@51260
   227
    next
immler@51260
   228
      fix x n
immler@51260
   229
      assume "x \<in> S n"
immler@51260
   230
      also have "\<dots> = (\<Union>i\<in>{0..n}. from_nat_into B' i)"
immler@51260
   231
        by (simp add: S_def)
immler@51260
   232
      also have "\<dots> \<subseteq> (\<Union>i. from_nat_into B' i)" by auto
immler@51260
   233
      also have "\<dots> \<subseteq> \<Union>B'" using `B' \<noteq> {}` by (auto intro: from_nat_into)
immler@51260
   234
      finally show "x \<in> \<Union>B'" .
immler@51260
   235
    qed
immler@51260
   236
    moreover have "range S \<subseteq> union_closed_basis" using B'
immler@51260
   237
      by (auto intro!: union_closed_basisI[OF _ S] simp: from_nat_into `B' \<noteq> {}`)
immler@51260
   238
    ultimately show ?thesis by auto
immler@51260
   239
  qed (auto simp: B')
immler@51102
   240
qed
immler@51102
   241
immler@51102
   242
lemma open_incseqE:
immler@51102
   243
  assumes "open X"
immler@51260
   244
  obtains S where "incseq S" "(\<Union>j. S j) = X" "range S \<subseteq> union_closed_basis"
immler@51102
   245
  using open_imp_Union_of_incseq assms by atomize_elim
immler@51102
   246
immler@51102
   247
end
immler@51102
   248
hoelzl@51898
   249
class first_countable_topology = topological_space +
hoelzl@51898
   250
  assumes first_countable_basis:
hoelzl@51898
   251
    "\<exists>A. countable A \<and> (\<forall>a\<in>A. x \<in> a \<and> open a) \<and> (\<forall>S. open S \<and> x \<in> S \<longrightarrow> (\<exists>a\<in>A. a \<subseteq> S))"
hoelzl@51898
   252
hoelzl@51898
   253
lemma (in first_countable_topology) countable_basis_at_decseq:
hoelzl@51898
   254
  obtains A :: "nat \<Rightarrow> 'a set" where
hoelzl@51898
   255
    "\<And>i. open (A i)" "\<And>i. x \<in> (A i)"
hoelzl@51898
   256
    "\<And>S. open S \<Longrightarrow> x \<in> S \<Longrightarrow> eventually (\<lambda>i. A i \<subseteq> S) sequentially"
hoelzl@51898
   257
proof atomize_elim
hoelzl@51898
   258
  from first_countable_basis[of x] obtain A
hoelzl@51898
   259
    where "countable A"
hoelzl@51898
   260
    and nhds: "\<And>a. a \<in> A \<Longrightarrow> open a" "\<And>a. a \<in> A \<Longrightarrow> x \<in> a"
hoelzl@51898
   261
    and incl: "\<And>S. open S \<Longrightarrow> x \<in> S \<Longrightarrow> \<exists>a\<in>A. a \<subseteq> S"  by auto
hoelzl@51898
   262
  then have "A \<noteq> {}" by auto
hoelzl@51898
   263
  with `countable A` have r: "A = range (from_nat_into A)" by auto
hoelzl@51898
   264
  def F \<equiv> "\<lambda>n. \<Inter>i\<le>n. from_nat_into A i"
hoelzl@51898
   265
  show "\<exists>A. (\<forall>i. open (A i)) \<and> (\<forall>i. x \<in> A i) \<and>
hoelzl@51898
   266
      (\<forall>S. open S \<longrightarrow> x \<in> S \<longrightarrow> eventually (\<lambda>i. A i \<subseteq> S) sequentially)"
hoelzl@51898
   267
  proof (safe intro!: exI[of _ F])
hoelzl@51898
   268
    fix i
hoelzl@51898
   269
    show "open (F i)" using nhds(1) r by (auto simp: F_def intro!: open_INT)
hoelzl@51898
   270
    show "x \<in> F i" using nhds(2) r by (auto simp: F_def)
hoelzl@51898
   271
  next
hoelzl@51898
   272
    fix S assume "open S" "x \<in> S"
hoelzl@51898
   273
    from incl[OF this] obtain i where "F i \<subseteq> S"
hoelzl@51898
   274
      by (subst (asm) r) (auto simp: F_def)
hoelzl@51898
   275
    moreover have "\<And>j. i \<le> j \<Longrightarrow> F j \<subseteq> F i"
hoelzl@51898
   276
      by (auto simp: F_def)
hoelzl@51898
   277
    ultimately show "eventually (\<lambda>i. F i \<subseteq> S) sequentially"
hoelzl@51898
   278
      by (auto simp: eventually_sequentially)
hoelzl@51898
   279
  qed
hoelzl@51898
   280
qed
hoelzl@51898
   281
hoelzl@51898
   282
lemma (in first_countable_topology) first_countable_basisE:
hoelzl@51898
   283
  obtains A where "countable A" "\<And>a. a \<in> A \<Longrightarrow> x \<in> a" "\<And>a. a \<in> A \<Longrightarrow> open a"
hoelzl@51898
   284
    "\<And>S. open S \<Longrightarrow> x \<in> S \<Longrightarrow> (\<exists>a\<in>A. a \<subseteq> S)"
hoelzl@51898
   285
  using first_countable_basis[of x]
hoelzl@51898
   286
  by atomize_elim auto
hoelzl@51898
   287
hoelzl@51898
   288
instance prod :: (first_countable_topology, first_countable_topology) first_countable_topology
hoelzl@51898
   289
proof
hoelzl@51898
   290
  fix x :: "'a \<times> 'b"
hoelzl@51898
   291
  from first_countable_basisE[of "fst x"] guess A :: "'a set set" . note A = this
hoelzl@51898
   292
  from first_countable_basisE[of "snd x"] guess B :: "'b set set" . note B = this
hoelzl@51898
   293
  show "\<exists>A::('a\<times>'b) set set. countable A \<and> (\<forall>a\<in>A. x \<in> a \<and> open a) \<and> (\<forall>S. open S \<and> x \<in> S \<longrightarrow> (\<exists>a\<in>A. a \<subseteq> S))"
hoelzl@51898
   294
  proof (intro exI[of _ "(\<lambda>(a, b). a \<times> b) ` (A \<times> B)"], safe)
hoelzl@51898
   295
    fix a b assume x: "a \<in> A" "b \<in> B"
hoelzl@51898
   296
    with A(2, 3)[of a] B(2, 3)[of b] show "x \<in> a \<times> b" "open (a \<times> b)"
hoelzl@51898
   297
      unfolding mem_Times_iff by (auto intro: open_Times)
hoelzl@51898
   298
  next
hoelzl@51898
   299
    fix S assume "open S" "x \<in> S"
hoelzl@51898
   300
    from open_prod_elim[OF this] guess a' b' .
hoelzl@51898
   301
    moreover with A(4)[of a'] B(4)[of b']
hoelzl@51898
   302
    obtain a b where "a \<in> A" "a \<subseteq> a'" "b \<in> B" "b \<subseteq> b'" by auto
hoelzl@51898
   303
    ultimately show "\<exists>a\<in>(\<lambda>(a, b). a \<times> b) ` (A \<times> B). a \<subseteq> S"
hoelzl@51898
   304
      by (auto intro!: bexI[of _ "a \<times> b"] bexI[of _ a] bexI[of _ b])
hoelzl@51898
   305
  qed (simp add: A B)
hoelzl@51898
   306
qed
hoelzl@51898
   307
hoelzl@51898
   308
instance metric_space \<subseteq> first_countable_topology
hoelzl@51898
   309
proof
hoelzl@51898
   310
  fix x :: 'a
hoelzl@51898
   311
  show "\<exists>A. countable A \<and> (\<forall>a\<in>A. x \<in> a \<and> open a) \<and> (\<forall>S. open S \<and> x \<in> S \<longrightarrow> (\<exists>a\<in>A. a \<subseteq> S))"
hoelzl@51898
   312
  proof (intro exI, safe)
hoelzl@51898
   313
    fix S assume "open S" "x \<in> S"
hoelzl@51898
   314
    then obtain r where "0 < r" "{y. dist x y < r} \<subseteq> S"
hoelzl@51898
   315
      by (auto simp: open_dist dist_commute subset_eq)
hoelzl@51898
   316
    moreover from reals_Archimedean[OF `0 < r`] guess n ..
hoelzl@51898
   317
    moreover
hoelzl@51898
   318
    then have "{y. dist x y < inverse (Suc n)} \<subseteq> {y. dist x y < r}"
hoelzl@51898
   319
      by (auto simp: inverse_eq_divide)
hoelzl@51898
   320
    ultimately show "\<exists>a\<in>range (\<lambda>n. {y. dist x y < inverse (Suc n)}). a \<subseteq> S"
hoelzl@51898
   321
      by auto
hoelzl@51898
   322
  qed (auto intro: open_ball)
hoelzl@51898
   323
qed
hoelzl@51898
   324
hoelzl@51896
   325
class second_countable_topology = topological_space +
immler@51260
   326
  assumes ex_countable_basis:
immler@51260
   327
    "\<exists>B::'a::topological_space set set. countable B \<and> topological_basis B"
immler@51260
   328
hoelzl@51896
   329
sublocale second_countable_topology < countable_basis "SOME B. countable B \<and> topological_basis B"
immler@51260
   330
  using someI_ex[OF ex_countable_basis] by unfold_locales safe
immler@51109
   331
hoelzl@51897
   332
instance prod :: (second_countable_topology, second_countable_topology) second_countable_topology
hoelzl@51897
   333
proof
hoelzl@51897
   334
  obtain A :: "'a set set" where "countable A" "topological_basis A"
hoelzl@51897
   335
    using ex_countable_basis by auto
hoelzl@51897
   336
  moreover
hoelzl@51897
   337
  obtain B :: "'b set set" where "countable B" "topological_basis B"
hoelzl@51897
   338
    using ex_countable_basis by auto
hoelzl@51897
   339
  ultimately show "\<exists>B::('a \<times> 'b) set set. countable B \<and> topological_basis B"
hoelzl@51897
   340
    by (auto intro!: exI[of _ "(\<lambda>(a, b). a \<times> b) ` (A \<times> B)"] topological_basis_prod)
hoelzl@51897
   341
qed
hoelzl@51897
   342
hoelzl@51898
   343
instance second_countable_topology \<subseteq> first_countable_topology
hoelzl@51898
   344
proof
hoelzl@51898
   345
  fix x :: 'a
hoelzl@51898
   346
  def B \<equiv> "SOME B::'a set set. countable B \<and> topological_basis B"
hoelzl@51898
   347
  then have B: "countable B" "topological_basis B"
hoelzl@51898
   348
    using countable_basis is_basis
hoelzl@51898
   349
    by (auto simp: countable_basis is_basis)
hoelzl@51898
   350
  then show "\<exists>A. countable A \<and> (\<forall>a\<in>A. x \<in> a \<and> open a) \<and> (\<forall>S. open S \<and> x \<in> S \<longrightarrow> (\<exists>a\<in>A. a \<subseteq> S))"
hoelzl@51898
   351
    by (intro exI[of _ "{b\<in>B. x \<in> b}"])
hoelzl@51898
   352
       (fastforce simp: topological_space_class.topological_basis_def)
hoelzl@51898
   353
qed
hoelzl@51898
   354
immler@51102
   355
subsection {* Polish spaces *}
immler@51102
   356
immler@51102
   357
text {* Textbooks define Polish spaces as completely metrizable.
immler@51102
   358
  We assume the topology to be complete for a given metric. *}
immler@51102
   359
hoelzl@51896
   360
class polish_space = complete_space + second_countable_topology
immler@51102
   361
huffman@45372
   362
subsection {* General notion of a topology as a value *}
himmelma@33175
   363
huffman@45035
   364
definition "istopology L \<longleftrightarrow> 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@50849
   365
typedef 'a topology = "{L::('a set) \<Rightarrow> bool. istopology L}"
himmelma@33175
   366
  morphisms "openin" "topology"
himmelma@33175
   367
  unfolding istopology_def by blast
himmelma@33175
   368
himmelma@33175
   369
lemma istopology_open_in[intro]: "istopology(openin U)"
himmelma@33175
   370
  using openin[of U] by blast
himmelma@33175
   371
himmelma@33175
   372
lemma topology_inverse': "istopology U \<Longrightarrow> openin (topology U) = U"
huffman@45035
   373
  using topology_inverse[unfolded mem_Collect_eq] .
himmelma@33175
   374
himmelma@33175
   375
lemma topology_inverse_iff: "istopology U \<longleftrightarrow> openin (topology U) = U"
himmelma@33175
   376
  using topology_inverse[of U] istopology_open_in[of "topology U"] by auto
himmelma@33175
   377
himmelma@33175
   378
lemma topology_eq: "T1 = T2 \<longleftrightarrow> (\<forall>S. openin T1 S \<longleftrightarrow> openin T2 S)"
himmelma@33175
   379
proof-
wenzelm@50726
   380
  { assume "T1=T2"
wenzelm@50726
   381
    hence "\<forall>S. openin T1 S \<longleftrightarrow> openin T2 S" by simp }
himmelma@33175
   382
  moreover
wenzelm@50726
   383
  { assume H: "\<forall>S. openin T1 S \<longleftrightarrow> openin T2 S"
huffman@45035
   384
    hence "openin T1 = openin T2" by (simp add: fun_eq_iff)
himmelma@33175
   385
    hence "topology (openin T1) = topology (openin T2)" by simp
wenzelm@50726
   386
    hence "T1 = T2" unfolding openin_inverse .
wenzelm@50726
   387
  }
himmelma@33175
   388
  ultimately show ?thesis by blast
himmelma@33175
   389
qed
himmelma@33175
   390
himmelma@33175
   391
text{* Infer the "universe" from union of all sets in the topology. *}
himmelma@33175
   392
himmelma@33175
   393
definition "topspace T =  \<Union>{S. openin T S}"
himmelma@33175
   394
huffman@45081
   395
subsubsection {* Main properties of open sets *}
himmelma@33175
   396
himmelma@33175
   397
lemma openin_clauses:
himmelma@33175
   398
  fixes U :: "'a topology"
himmelma@33175
   399
  shows "openin U {}"
himmelma@33175
   400
  "\<And>S T. openin U S \<Longrightarrow> openin U T \<Longrightarrow> openin U (S\<inter>T)"
himmelma@33175
   401
  "\<And>K. (\<forall>S \<in> K. openin U S) \<Longrightarrow> openin U (\<Union>K)"
huffman@45035
   402
  using openin[of U] unfolding istopology_def mem_Collect_eq
huffman@45035
   403
  by fast+
himmelma@33175
   404
himmelma@33175
   405
lemma openin_subset[intro]: "openin U S \<Longrightarrow> S \<subseteq> topspace U"
himmelma@33175
   406
  unfolding topspace_def by blast
himmelma@33175
   407
lemma openin_empty[simp]: "openin U {}" by (simp add: openin_clauses)
himmelma@33175
   408
himmelma@33175
   409
lemma openin_Int[intro]: "openin U S \<Longrightarrow> openin U T \<Longrightarrow> openin U (S \<inter> T)"
huffman@36358
   410
  using openin_clauses by simp
huffman@36358
   411
huffman@36358
   412
lemma openin_Union[intro]: "(\<forall>S \<in>K. openin U S) \<Longrightarrow> openin U (\<Union> K)"
huffman@36358
   413
  using openin_clauses by simp
himmelma@33175
   414
himmelma@33175
   415
lemma openin_Un[intro]: "openin U S \<Longrightarrow> openin U T \<Longrightarrow> openin U (S \<union> T)"
himmelma@33175
   416
  using openin_Union[of "{S,T}" U] by auto
himmelma@33175
   417
himmelma@33175
   418
lemma openin_topspace[intro, simp]: "openin U (topspace U)" by (simp add: openin_Union topspace_def)
himmelma@33175
   419
wenzelm@50726
   420
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@50726
   421
  (is "?lhs \<longleftrightarrow> ?rhs")
huffman@36584
   422
proof
wenzelm@50726
   423
  assume ?lhs
wenzelm@50726
   424
  then show ?rhs by auto
huffman@36584
   425
next
huffman@36584
   426
  assume H: ?rhs
huffman@36584
   427
  let ?t = "\<Union>{T. openin U T \<and> T \<subseteq> S}"
huffman@36584
   428
  have "openin U ?t" by (simp add: openin_Union)
huffman@36584
   429
  also have "?t = S" using H by auto
huffman@36584
   430
  finally show "openin U S" .
himmelma@33175
   431
qed
himmelma@33175
   432
wenzelm@50726
   433
huffman@45081
   434
subsubsection {* Closed sets *}
himmelma@33175
   435
himmelma@33175
   436
definition "closedin U S \<longleftrightarrow> S \<subseteq> topspace U \<and> openin U (topspace U - S)"
himmelma@33175
   437
himmelma@33175
   438
lemma closedin_subset: "closedin U S \<Longrightarrow> S \<subseteq> topspace U" by (metis closedin_def)
himmelma@33175
   439
lemma closedin_empty[simp]: "closedin U {}" by (simp add: closedin_def)
himmelma@33175
   440
lemma closedin_topspace[intro,simp]:
himmelma@33175
   441
  "closedin U (topspace U)" by (simp add: closedin_def)
himmelma@33175
   442
lemma closedin_Un[intro]: "closedin U S \<Longrightarrow> closedin U T \<Longrightarrow> closedin U (S \<union> T)"
himmelma@33175
   443
  by (auto simp add: Diff_Un closedin_def)
himmelma@33175
   444
himmelma@33175
   445
lemma Diff_Inter[intro]: "A - \<Inter>S = \<Union> {A - s|s. s\<in>S}" by auto
himmelma@33175
   446
lemma closedin_Inter[intro]: assumes Ke: "K \<noteq> {}" and Kc: "\<forall>S \<in>K. closedin U S"
himmelma@33175
   447
  shows "closedin U (\<Inter> K)"  using Ke Kc unfolding closedin_def Diff_Inter by auto
himmelma@33175
   448
himmelma@33175
   449
lemma closedin_Int[intro]: "closedin U S \<Longrightarrow> closedin U T \<Longrightarrow> closedin U (S \<inter> T)"
himmelma@33175
   450
  using closedin_Inter[of "{S,T}" U] by auto
himmelma@33175
   451
himmelma@33175
   452
lemma Diff_Diff_Int: "A - (A - B) = A \<inter> B" by blast
himmelma@33175
   453
lemma openin_closedin_eq: "openin U S \<longleftrightarrow> S \<subseteq> topspace U \<and> closedin U (topspace U - S)"
himmelma@33175
   454
  apply (auto simp add: closedin_def Diff_Diff_Int inf_absorb2)
himmelma@33175
   455
  apply (metis openin_subset subset_eq)
himmelma@33175
   456
  done
himmelma@33175
   457
himmelma@33175
   458
lemma openin_closedin:  "S \<subseteq> topspace U \<Longrightarrow> (openin U S \<longleftrightarrow> closedin U (topspace U - S))"
himmelma@33175
   459
  by (simp add: openin_closedin_eq)
himmelma@33175
   460
himmelma@33175
   461
lemma openin_diff[intro]: assumes oS: "openin U S" and cT: "closedin U T" shows "openin U (S - T)"
himmelma@33175
   462
proof-
himmelma@33175
   463
  have "S - T = S \<inter> (topspace U - T)" using openin_subset[of U S]  oS cT
himmelma@33175
   464
    by (auto simp add: topspace_def openin_subset)
himmelma@33175
   465
  then show ?thesis using oS cT by (auto simp add: closedin_def)
himmelma@33175
   466
qed
himmelma@33175
   467
himmelma@33175
   468
lemma closedin_diff[intro]: assumes oS: "closedin U S" and cT: "openin U T" shows "closedin U (S - T)"
himmelma@33175
   469
proof-
himmelma@33175
   470
  have "S - T = S \<inter> (topspace U - T)" using closedin_subset[of U S]  oS cT
himmelma@33175
   471
    by (auto simp add: topspace_def )
himmelma@33175
   472
  then show ?thesis using oS cT by (auto simp add: openin_closedin_eq)
himmelma@33175
   473
qed
himmelma@33175
   474
huffman@45081
   475
subsubsection {* Subspace topology *}
huffman@45035
   476
huffman@45035
   477
definition "subtopology U V = topology (\<lambda>T. \<exists>S. T = S \<inter> V \<and> openin U S)"
huffman@45035
   478
huffman@45035
   479
lemma istopology_subtopology: "istopology (\<lambda>T. \<exists>S. T = S \<inter> V \<and> openin U S)"
huffman@45035
   480
  (is "istopology ?L")
himmelma@33175
   481
proof-
huffman@45035
   482
  have "?L {}" by blast
huffman@45035
   483
  {fix A B assume A: "?L A" and B: "?L B"
himmelma@33175
   484
    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" by blast
himmelma@33175
   485
    have "A\<inter>B = (Sa \<inter> Sb) \<inter> V" "openin U (Sa \<inter> Sb)"  using Sa Sb by blast+
huffman@45035
   486
    then have "?L (A \<inter> B)" by blast}
himmelma@33175
   487
  moreover
huffman@45035
   488
  {fix K assume K: "K \<subseteq> Collect ?L"
huffman@45035
   489
    have th0: "Collect ?L = (\<lambda>S. S \<inter> V) ` Collect (openin U)"
nipkow@39535
   490
      apply (rule set_eqI)
himmelma@33175
   491
      apply (simp add: Ball_def image_iff)
huffman@45035
   492
      by metis
himmelma@33175
   493
    from K[unfolded th0 subset_image_iff]
huffman@45035
   494
    obtain Sk where Sk: "Sk \<subseteq> Collect (openin U)" "K = (\<lambda>S. S \<inter> V) ` Sk" by blast
himmelma@33175
   495
    have "\<Union>K = (\<Union>Sk) \<inter> V" using Sk by auto
huffman@45035
   496
    moreover have "openin U (\<Union> Sk)" using Sk by (auto simp add: subset_eq)
huffman@45035
   497
    ultimately have "?L (\<Union>K)" by blast}
huffman@45035
   498
  ultimately show ?thesis
huffman@45035
   499
    unfolding subset_eq mem_Collect_eq istopology_def by blast
himmelma@33175
   500
qed
himmelma@33175
   501
himmelma@33175
   502
lemma openin_subtopology:
himmelma@33175
   503
  "openin (subtopology U V) S \<longleftrightarrow> (\<exists> T. (openin U T) \<and> (S = T \<inter> V))"
himmelma@33175
   504
  unfolding subtopology_def topology_inverse'[OF istopology_subtopology]
huffman@45035
   505
  by auto
himmelma@33175
   506
himmelma@33175
   507
lemma topspace_subtopology: "topspace(subtopology U V) = topspace U \<inter> V"
himmelma@33175
   508
  by (auto simp add: topspace_def openin_subtopology)
himmelma@33175
   509
himmelma@33175
   510
lemma closedin_subtopology:
himmelma@33175
   511
  "closedin (subtopology U V) S \<longleftrightarrow> (\<exists>T. closedin U T \<and> S = T \<inter> V)"
himmelma@33175
   512
  unfolding closedin_def topspace_subtopology
himmelma@33175
   513
  apply (simp add: openin_subtopology)
himmelma@33175
   514
  apply (rule iffI)
himmelma@33175
   515
  apply clarify
himmelma@33175
   516
  apply (rule_tac x="topspace U - T" in exI)
himmelma@33175
   517
  by auto
himmelma@33175
   518
himmelma@33175
   519
lemma openin_subtopology_refl: "openin (subtopology U V) V \<longleftrightarrow> V \<subseteq> topspace U"
himmelma@33175
   520
  unfolding openin_subtopology
himmelma@33175
   521
  apply (rule iffI, clarify)
himmelma@33175
   522
  apply (frule openin_subset[of U])  apply blast
himmelma@33175
   523
  apply (rule exI[where x="topspace U"])
wenzelm@50726
   524
  apply auto
wenzelm@50726
   525
  done
wenzelm@50726
   526
wenzelm@50726
   527
lemma subtopology_superset:
wenzelm@50726
   528
  assumes UV: "topspace U \<subseteq> V"
himmelma@33175
   529
  shows "subtopology U V = U"
himmelma@33175
   530
proof-
himmelma@33175
   531
  {fix S
himmelma@33175
   532
    {fix T assume T: "openin U T" "S = T \<inter> V"
himmelma@33175
   533
      from T openin_subset[OF T(1)] UV have eq: "S = T" by blast
himmelma@33175
   534
      have "openin U S" unfolding eq using T by blast}
himmelma@33175
   535
    moreover
himmelma@33175
   536
    {assume S: "openin U S"
himmelma@33175
   537
      hence "\<exists>T. openin U T \<and> S = T \<inter> V"
himmelma@33175
   538
        using openin_subset[OF S] UV by auto}
himmelma@33175
   539
    ultimately have "(\<exists>T. openin U T \<and> S = T \<inter> V) \<longleftrightarrow> openin U S" by blast}
himmelma@33175
   540
  then show ?thesis unfolding topology_eq openin_subtopology by blast
himmelma@33175
   541
qed
himmelma@33175
   542
himmelma@33175
   543
lemma subtopology_topspace[simp]: "subtopology U (topspace U) = U"
himmelma@33175
   544
  by (simp add: subtopology_superset)
himmelma@33175
   545
himmelma@33175
   546
lemma subtopology_UNIV[simp]: "subtopology U UNIV = U"
himmelma@33175
   547
  by (simp add: subtopology_superset)
himmelma@33175
   548
huffman@45081
   549
subsubsection {* The standard Euclidean topology *}
himmelma@33175
   550
himmelma@33175
   551
definition
himmelma@33175
   552
  euclidean :: "'a::topological_space topology" where
himmelma@33175
   553
  "euclidean = topology open"
himmelma@33175
   554
himmelma@33175
   555
lemma open_openin: "open S \<longleftrightarrow> openin euclidean S"
himmelma@33175
   556
  unfolding euclidean_def
himmelma@33175
   557
  apply (rule cong[where x=S and y=S])
himmelma@33175
   558
  apply (rule topology_inverse[symmetric])
himmelma@33175
   559
  apply (auto simp add: istopology_def)
huffman@45035
   560
  done
himmelma@33175
   561
himmelma@33175
   562
lemma topspace_euclidean: "topspace euclidean = UNIV"
himmelma@33175
   563
  apply (simp add: topspace_def)
nipkow@39535
   564
  apply (rule set_eqI)
himmelma@33175
   565
  by (auto simp add: open_openin[symmetric])
himmelma@33175
   566
himmelma@33175
   567
lemma topspace_euclidean_subtopology[simp]: "topspace (subtopology euclidean S) = S"
himmelma@33175
   568
  by (simp add: topspace_euclidean topspace_subtopology)
himmelma@33175
   569
himmelma@33175
   570
lemma closed_closedin: "closed S \<longleftrightarrow> closedin euclidean S"
himmelma@33175
   571
  by (simp add: closed_def closedin_def topspace_euclidean open_openin Compl_eq_Diff_UNIV)
himmelma@33175
   572
himmelma@33175
   573
lemma open_subopen: "open S \<longleftrightarrow> (\<forall>x\<in>S. \<exists>T. open T \<and> x \<in> T \<and> T \<subseteq> S)"
himmelma@33175
   574
  by (simp add: open_openin openin_subopen[symmetric])
himmelma@33175
   575
huffman@45081
   576
text {* Basic "localization" results are handy for connectedness. *}
huffman@45081
   577
huffman@45081
   578
lemma openin_open: "openin (subtopology euclidean U) S \<longleftrightarrow> (\<exists>T. open T \<and> (S = U \<inter> T))"
huffman@45081
   579
  by (auto simp add: openin_subtopology open_openin[symmetric])
huffman@45081
   580
huffman@45081
   581
lemma openin_open_Int[intro]: "open S \<Longrightarrow> openin (subtopology euclidean U) (U \<inter> S)"
huffman@45081
   582
  by (auto simp add: openin_open)
huffman@45081
   583
huffman@45081
   584
lemma open_openin_trans[trans]:
huffman@45081
   585
 "open S \<Longrightarrow> open T \<Longrightarrow> T \<subseteq> S \<Longrightarrow> openin (subtopology euclidean S) T"
huffman@45081
   586
  by (metis Int_absorb1  openin_open_Int)
huffman@45081
   587
huffman@45081
   588
lemma open_subset:  "S \<subseteq> T \<Longrightarrow> open S \<Longrightarrow> openin (subtopology euclidean T) S"
huffman@45081
   589
  by (auto simp add: openin_open)
huffman@45081
   590
huffman@45081
   591
lemma closedin_closed: "closedin (subtopology euclidean U) S \<longleftrightarrow> (\<exists>T. closed T \<and> S = U \<inter> T)"
huffman@45081
   592
  by (simp add: closedin_subtopology closed_closedin Int_ac)
huffman@45081
   593
huffman@45081
   594
lemma closedin_closed_Int: "closed S ==> closedin (subtopology euclidean U) (U \<inter> S)"
huffman@45081
   595
  by (metis closedin_closed)
huffman@45081
   596
huffman@45081
   597
lemma closed_closedin_trans: "closed S \<Longrightarrow> closed T \<Longrightarrow> T \<subseteq> S \<Longrightarrow> closedin (subtopology euclidean S) T"
huffman@45081
   598
  apply (subgoal_tac "S \<inter> T = T" )
huffman@45081
   599
  apply auto
huffman@45081
   600
  apply (frule closedin_closed_Int[of T S])
huffman@45081
   601
  by simp
huffman@45081
   602
huffman@45081
   603
lemma closed_subset: "S \<subseteq> T \<Longrightarrow> closed S \<Longrightarrow> closedin (subtopology euclidean T) S"
huffman@45081
   604
  by (auto simp add: closedin_closed)
huffman@45081
   605
huffman@45081
   606
lemma openin_euclidean_subtopology_iff:
huffman@45081
   607
  fixes S U :: "'a::metric_space set"
huffman@45081
   608
  shows "openin (subtopology euclidean U) S
huffman@45081
   609
  \<longleftrightarrow> S \<subseteq> U \<and> (\<forall>x\<in>S. \<exists>e>0. \<forall>x'\<in>U. dist x' x < e \<longrightarrow> x'\<in> S)" (is "?lhs \<longleftrightarrow> ?rhs")
huffman@45081
   610
proof
huffman@45081
   611
  assume ?lhs thus ?rhs unfolding openin_open open_dist by blast
huffman@45081
   612
next
huffman@45081
   613
  def T \<equiv> "{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@45081
   614
  have 1: "\<forall>x\<in>T. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> T"
huffman@45081
   615
    unfolding T_def
huffman@45081
   616
    apply clarsimp
huffman@45081
   617
    apply (rule_tac x="d - dist x a" in exI)
huffman@45081
   618
    apply (clarsimp simp add: less_diff_eq)
huffman@45081
   619
    apply (erule rev_bexI)
huffman@45081
   620
    apply (rule_tac x=d in exI, clarify)
huffman@45081
   621
    apply (erule le_less_trans [OF dist_triangle])
huffman@45081
   622
    done
huffman@45081
   623
  assume ?rhs hence 2: "S = U \<inter> T"
huffman@45081
   624
    unfolding T_def
huffman@45081
   625
    apply auto
huffman@45081
   626
    apply (drule (1) bspec, erule rev_bexI)
huffman@45081
   627
    apply auto
huffman@45081
   628
    done
huffman@45081
   629
  from 1 2 show ?lhs
huffman@45081
   630
    unfolding openin_open open_dist by fast
huffman@45081
   631
qed
huffman@45081
   632
huffman@45081
   633
text {* These "transitivity" results are handy too *}
huffman@45081
   634
huffman@45081
   635
lemma openin_trans[trans]: "openin (subtopology euclidean T) S \<Longrightarrow> openin (subtopology euclidean U) T
huffman@45081
   636
  \<Longrightarrow> openin (subtopology euclidean U) S"
huffman@45081
   637
  unfolding open_openin openin_open by blast
huffman@45081
   638
huffman@45081
   639
lemma openin_open_trans: "openin (subtopology euclidean T) S \<Longrightarrow> open T \<Longrightarrow> open S"
huffman@45081
   640
  by (auto simp add: openin_open intro: openin_trans)
huffman@45081
   641
huffman@45081
   642
lemma closedin_trans[trans]:
huffman@45081
   643
 "closedin (subtopology euclidean T) S \<Longrightarrow>
huffman@45081
   644
           closedin (subtopology euclidean U) T
huffman@45081
   645
           ==> closedin (subtopology euclidean U) S"
huffman@45081
   646
  by (auto simp add: closedin_closed closed_closedin closed_Inter Int_assoc)
huffman@45081
   647
huffman@45081
   648
lemma closedin_closed_trans: "closedin (subtopology euclidean T) S \<Longrightarrow> closed T \<Longrightarrow> closed S"
huffman@45081
   649
  by (auto simp add: closedin_closed intro: closedin_trans)
huffman@45081
   650
huffman@45081
   651
huffman@45081
   652
subsection {* Open and closed balls *}
himmelma@33175
   653
himmelma@33175
   654
definition
himmelma@33175
   655
  ball :: "'a::metric_space \<Rightarrow> real \<Rightarrow> 'a set" where
himmelma@33175
   656
  "ball x e = {y. dist x y < e}"
himmelma@33175
   657
himmelma@33175
   658
definition
himmelma@33175
   659
  cball :: "'a::metric_space \<Rightarrow> real \<Rightarrow> 'a set" where
himmelma@33175
   660
  "cball x e = {y. dist x y \<le> e}"
himmelma@33175
   661
huffman@46647
   662
lemma mem_ball [simp]: "y \<in> ball x e \<longleftrightarrow> dist x y < e"
huffman@46647
   663
  by (simp add: ball_def)
huffman@46647
   664
huffman@46647
   665
lemma mem_cball [simp]: "y \<in> cball x e \<longleftrightarrow> dist x y \<le> e"
huffman@46647
   666
  by (simp add: cball_def)
huffman@46647
   667
huffman@46647
   668
lemma mem_ball_0:
himmelma@33175
   669
  fixes x :: "'a::real_normed_vector"
himmelma@33175
   670
  shows "x \<in> ball 0 e \<longleftrightarrow> norm x < e"
himmelma@33175
   671
  by (simp add: dist_norm)
himmelma@33175
   672
huffman@46647
   673
lemma mem_cball_0:
himmelma@33175
   674
  fixes x :: "'a::real_normed_vector"
himmelma@33175
   675
  shows "x \<in> cball 0 e \<longleftrightarrow> norm x \<le> e"
himmelma@33175
   676
  by (simp add: dist_norm)
himmelma@33175
   677
huffman@46647
   678
lemma centre_in_ball: "x \<in> ball x e \<longleftrightarrow> 0 < e"
huffman@46647
   679
  by simp
huffman@46647
   680
huffman@46647
   681
lemma centre_in_cball: "x \<in> cball x e \<longleftrightarrow> 0 \<le> e"
huffman@46647
   682
  by simp
huffman@46647
   683
himmelma@33175
   684
lemma ball_subset_cball[simp,intro]: "ball x e \<subseteq> cball x e" by (simp add: subset_eq)
himmelma@33175
   685
lemma subset_ball[intro]: "d <= e ==> ball x d \<subseteq> ball x e" by (simp add: subset_eq)
himmelma@33175
   686
lemma subset_cball[intro]: "d <= e ==> cball x d \<subseteq> cball x e" by (simp add: subset_eq)
himmelma@33175
   687
lemma ball_max_Un: "ball a (max r s) = ball a r \<union> ball a s"
nipkow@39535
   688
  by (simp add: set_eq_iff) arith
himmelma@33175
   689
himmelma@33175
   690
lemma ball_min_Int: "ball a (min r s) = ball a r \<inter> ball a s"
nipkow@39535
   691
  by (simp add: set_eq_iff)
himmelma@33175
   692
himmelma@33175
   693
lemma diff_less_iff: "(a::real) - b > 0 \<longleftrightarrow> a > b"
himmelma@33175
   694
  "(a::real) - b < 0 \<longleftrightarrow> a < b"
himmelma@33175
   695
  "a - b < c \<longleftrightarrow> a < c +b" "a - b > c \<longleftrightarrow> a > c +b" by arith+
himmelma@33175
   696
lemma diff_le_iff: "(a::real) - b \<ge> 0 \<longleftrightarrow> a \<ge> b" "(a::real) - b \<le> 0 \<longleftrightarrow> a \<le> b"
himmelma@33175
   697
  "a - b \<le> c \<longleftrightarrow> a \<le> c +b" "a - b \<ge> c \<longleftrightarrow> a \<ge> c +b"  by arith+
himmelma@33175
   698
himmelma@33175
   699
lemma open_ball[intro, simp]: "open (ball x e)"
huffman@45035
   700
  unfolding open_dist ball_def mem_Collect_eq Ball_def
himmelma@33175
   701
  unfolding dist_commute
himmelma@33175
   702
  apply clarify
himmelma@33175
   703
  apply (rule_tac x="e - dist xa x" in exI)
himmelma@33175
   704
  using dist_triangle_alt[where z=x]
himmelma@33175
   705
  apply (clarsimp simp add: diff_less_iff)
himmelma@33175
   706
  apply atomize
himmelma@33175
   707
  apply (erule_tac x="y" in allE)
himmelma@33175
   708
  apply (erule_tac x="xa" in allE)
himmelma@33175
   709
  by arith
himmelma@33175
   710
himmelma@33175
   711
lemma open_contains_ball: "open S \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0. ball x e \<subseteq> S)"
himmelma@33175
   712
  unfolding open_dist subset_eq mem_ball Ball_def dist_commute ..
himmelma@33175
   713
hoelzl@33711
   714
lemma openE[elim?]:
hoelzl@33711
   715
  assumes "open S" "x\<in>S" 
hoelzl@33711
   716
  obtains e where "e>0" "ball x e \<subseteq> S"
hoelzl@33711
   717
  using assms unfolding open_contains_ball by auto
hoelzl@33711
   718
himmelma@33175
   719
lemma open_contains_ball_eq: "open S \<Longrightarrow> \<forall>x. x\<in>S \<longleftrightarrow> (\<exists>e>0. ball x e \<subseteq> S)"
himmelma@33175
   720
  by (metis open_contains_ball subset_eq centre_in_ball)
himmelma@33175
   721
himmelma@33175
   722
lemma ball_eq_empty[simp]: "ball x e = {} \<longleftrightarrow> e \<le> 0"
nipkow@39535
   723
  unfolding mem_ball set_eq_iff
himmelma@33175
   724
  apply (simp add: not_less)
himmelma@33175
   725
  by (metis zero_le_dist order_trans dist_self)
himmelma@33175
   726
himmelma@33175
   727
lemma ball_empty[intro]: "e \<le> 0 ==> ball x e = {}" by simp
himmelma@33175
   728
hoelzl@51541
   729
lemma euclidean_dist_l2:
hoelzl@51541
   730
  fixes x y :: "'a :: euclidean_space"
hoelzl@51541
   731
  shows "dist x y = setL2 (\<lambda>i. dist (x \<bullet> i) (y \<bullet> i)) Basis"
hoelzl@51541
   732
  unfolding dist_norm norm_eq_sqrt_inner setL2_def
hoelzl@51541
   733
  by (subst euclidean_inner) (simp add: power2_eq_square inner_diff_left)
hoelzl@51541
   734
hoelzl@51541
   735
definition "box a b = {x. \<forall>i\<in>Basis. a \<bullet> i < x \<bullet> i \<and> x \<bullet> i < b \<bullet> i}"
hoelzl@51541
   736
immler@51102
   737
lemma rational_boxes:
hoelzl@51541
   738
  fixes x :: "'a\<Colon>euclidean_space"
immler@51102
   739
  assumes "0 < e"
hoelzl@51541
   740
  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@51102
   741
proof -
immler@51102
   742
  def e' \<equiv> "e / (2 * sqrt (real (DIM ('a))))"
hoelzl@51541
   743
  then have e: "0 < e'" using assms by (auto intro!: divide_pos_pos simp: DIM_positive)
hoelzl@51541
   744
  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@51102
   745
  proof
hoelzl@51541
   746
    fix i from Rats_dense_in_real[of "x \<bullet> i - e'" "x \<bullet> i"] e show "?th i" by auto
immler@51102
   747
  qed
immler@51102
   748
  from choice[OF this] guess a .. note a = this
hoelzl@51541
   749
  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@51102
   750
  proof
hoelzl@51541
   751
    fix i from Rats_dense_in_real[of "x \<bullet> i" "x \<bullet> i + e'"] e show "?th i" by auto
immler@51102
   752
  qed
immler@51102
   753
  from choice[OF this] guess b .. note b = this
hoelzl@51541
   754
  let ?a = "\<Sum>i\<in>Basis. a i *\<^sub>R i" and ?b = "\<Sum>i\<in>Basis. b i *\<^sub>R i"
hoelzl@51541
   755
  show ?thesis
hoelzl@51541
   756
  proof (rule exI[of _ ?a], rule exI[of _ ?b], safe)
hoelzl@51541
   757
    fix y :: 'a assume *: "y \<in> box ?a ?b"
hoelzl@51541
   758
    have "dist x y = sqrt (\<Sum>i\<in>Basis. (dist (x \<bullet> i) (y \<bullet> i))\<twosuperior>)"
immler@51102
   759
      unfolding setL2_def[symmetric] by (rule euclidean_dist_l2)
hoelzl@51541
   760
    also have "\<dots> < sqrt (\<Sum>(i::'a)\<in>Basis. e^2 / real (DIM('a)))"
immler@51102
   761
    proof (rule real_sqrt_less_mono, rule setsum_strict_mono)
hoelzl@51541
   762
      fix i :: "'a" assume i: "i \<in> Basis"
hoelzl@51541
   763
      have "a i < y\<bullet>i \<and> y\<bullet>i < b i" using * i by (auto simp: box_def)
hoelzl@51541
   764
      moreover have "a i < x\<bullet>i" "x\<bullet>i - a i < e'" using a by auto
hoelzl@51541
   765
      moreover have "x\<bullet>i < b i" "b i - x\<bullet>i < e'" using b by auto
hoelzl@51541
   766
      ultimately have "\<bar>x\<bullet>i - y\<bullet>i\<bar> < 2 * e'" by auto
hoelzl@51541
   767
      then have "dist (x \<bullet> i) (y \<bullet> i) < e/sqrt (real (DIM('a)))"
immler@51102
   768
        unfolding e'_def by (auto simp: dist_real_def)
hoelzl@51541
   769
      then have "(dist (x \<bullet> i) (y \<bullet> i))\<twosuperior> < (e/sqrt (real (DIM('a))))\<twosuperior>"
immler@51102
   770
        by (rule power_strict_mono) auto
hoelzl@51541
   771
      then show "(dist (x \<bullet> i) (y \<bullet> i))\<twosuperior> < e\<twosuperior> / real DIM('a)"
immler@51102
   772
        by (simp add: power_divide)
immler@51102
   773
    qed auto
hoelzl@51541
   774
    also have "\<dots> = e" using `0 < e` by (simp add: real_eq_of_nat)
hoelzl@51541
   775
    finally show "y \<in> ball x e" by (auto simp: ball_def)
hoelzl@51541
   776
  qed (insert a b, auto simp: box_def)
hoelzl@51541
   777
qed
hoelzl@51541
   778
 
hoelzl@51541
   779
lemma open_UNION_box:
hoelzl@51541
   780
  fixes M :: "'a\<Colon>euclidean_space set"
hoelzl@51541
   781
  assumes "open M" 
hoelzl@51541
   782
  defines "a' \<equiv> \<lambda>f :: 'a \<Rightarrow> real \<times> real. (\<Sum>(i::'a)\<in>Basis. fst (f i) *\<^sub>R i)"
hoelzl@51541
   783
  defines "b' \<equiv> \<lambda>f :: 'a \<Rightarrow> real \<times> real. (\<Sum>(i::'a)\<in>Basis. snd (f i) *\<^sub>R i)"
hoelzl@51541
   784
  defines "I \<equiv> {f\<in>Basis \<rightarrow>\<^isub>E \<rat> \<times> \<rat>. box (a' f) (b' f) \<subseteq> M}"
hoelzl@51541
   785
  shows "M = (\<Union>f\<in>I. box (a' f) (b' f))"
immler@51102
   786
proof safe
immler@51102
   787
  fix x assume "x \<in> M"
immler@51102
   788
  obtain e where e: "e > 0" "ball x e \<subseteq> M"
hoelzl@51541
   789
    using openE[OF `open M` `x \<in> M`] by auto
hoelzl@51541
   790
  moreover then obtain a b where ab: "x \<in> box a b"
hoelzl@51541
   791
    "\<forall>i \<in> Basis. a \<bullet> i \<in> \<rat>" "\<forall>i\<in>Basis. b \<bullet> i \<in> \<rat>" "box a b \<subseteq> ball x e"
hoelzl@51541
   792
    using rational_boxes[OF e(1)] by metis
hoelzl@51541
   793
  ultimately show "x \<in> (\<Union>f\<in>I. box (a' f) (b' f))"
hoelzl@51541
   794
     by (intro UN_I[of "\<lambda>i\<in>Basis. (a \<bullet> i, b \<bullet> i)"])
hoelzl@51541
   795
        (auto simp: euclidean_representation I_def a'_def b'_def)
hoelzl@51541
   796
qed (auto simp: I_def)
himmelma@33175
   797
himmelma@33175
   798
subsection{* Connectedness *}
himmelma@33175
   799
himmelma@33175
   800
definition "connected S \<longleftrightarrow>
himmelma@33175
   801
  ~(\<exists>e1 e2. open e1 \<and> open e2 \<and> S \<subseteq> (e1 \<union> e2) \<and> (e1 \<inter> e2 \<inter> S = {})
himmelma@33175
   802
  \<and> ~(e1 \<inter> S = {}) \<and> ~(e2 \<inter> S = {}))"
himmelma@33175
   803
himmelma@33175
   804
lemma connected_local:
himmelma@33175
   805
 "connected S \<longleftrightarrow> ~(\<exists>e1 e2.
himmelma@33175
   806
                 openin (subtopology euclidean S) e1 \<and>
himmelma@33175
   807
                 openin (subtopology euclidean S) e2 \<and>
himmelma@33175
   808
                 S \<subseteq> e1 \<union> e2 \<and>
himmelma@33175
   809
                 e1 \<inter> e2 = {} \<and>
himmelma@33175
   810
                 ~(e1 = {}) \<and>
himmelma@33175
   811
                 ~(e2 = {}))"
himmelma@33175
   812
unfolding connected_def openin_open by (safe, blast+)
himmelma@33175
   813
huffman@34099
   814
lemma exists_diff:
huffman@34099
   815
  fixes P :: "'a set \<Rightarrow> bool"
huffman@34099
   816
  shows "(\<exists>S. P(- S)) \<longleftrightarrow> (\<exists>S. P S)" (is "?lhs \<longleftrightarrow> ?rhs")
himmelma@33175
   817
proof-
himmelma@33175
   818
  {assume "?lhs" hence ?rhs by blast }
himmelma@33175
   819
  moreover
himmelma@33175
   820
  {fix S assume H: "P S"
huffman@34099
   821
    have "S = - (- S)" by auto
huffman@34099
   822
    with H have "P (- (- S))" by metis }
himmelma@33175
   823
  ultimately show ?thesis by metis
himmelma@33175
   824
qed
himmelma@33175
   825
himmelma@33175
   826
lemma connected_clopen: "connected S \<longleftrightarrow>
himmelma@33175
   827
        (\<forall>T. openin (subtopology euclidean S) T \<and>
himmelma@33175
   828
            closedin (subtopology euclidean S) T \<longrightarrow> T = {} \<or> T = S)" (is "?lhs \<longleftrightarrow> ?rhs")
himmelma@33175
   829
proof-
huffman@34099
   830
  have " \<not> connected S \<longleftrightarrow> (\<exists>e1 e2. open e1 \<and> open (- e2) \<and> S \<subseteq> e1 \<union> (- e2) \<and> e1 \<inter> (- e2) \<inter> S = {} \<and> e1 \<inter> S \<noteq> {} \<and> (- e2) \<inter> S \<noteq> {})"
himmelma@33175
   831
    unfolding connected_def openin_open closedin_closed
himmelma@33175
   832
    apply (subst exists_diff) by blast
huffman@34099
   833
  hence th0: "connected S \<longleftrightarrow> \<not> (\<exists>e2 e1. closed e2 \<and> open e1 \<and> S \<subseteq> e1 \<union> (- e2) \<and> e1 \<inter> (- e2) \<inter> S = {} \<and> e1 \<inter> S \<noteq> {} \<and> (- e2) \<inter> S \<noteq> {})"
huffman@34099
   834
    (is " _ \<longleftrightarrow> \<not> (\<exists>e2 e1. ?P e2 e1)") apply (simp add: closed_def) by metis
himmelma@33175
   835
himmelma@33175
   836
  have th1: "?rhs \<longleftrightarrow> \<not> (\<exists>t' t. closed t'\<and>t = S\<inter>t' \<and> t\<noteq>{} \<and> t\<noteq>S \<and> (\<exists>t'. open t' \<and> t = S \<inter> t'))"
himmelma@33175
   837
    (is "_ \<longleftrightarrow> \<not> (\<exists>t' t. ?Q t' t)")
himmelma@33175
   838
    unfolding connected_def openin_open closedin_closed by auto
himmelma@33175
   839
  {fix e2
himmelma@33175
   840
    {fix e1 have "?P e2 e1 \<longleftrightarrow> (\<exists>t.  closed e2 \<and> t = S\<inter>e2 \<and> open e1 \<and> t = S\<inter>e1 \<and> t\<noteq>{} \<and> t\<noteq>S)"
himmelma@33175
   841
        by auto}
himmelma@33175
   842
    then have "(\<exists>e1. ?P e2 e1) \<longleftrightarrow> (\<exists>t. ?Q e2 t)" by metis}
himmelma@33175
   843
  then have "\<forall>e2. (\<exists>e1. ?P e2 e1) \<longleftrightarrow> (\<exists>t. ?Q e2 t)" by blast
himmelma@33175
   844
  then show ?thesis unfolding th0 th1 by simp
himmelma@33175
   845
qed
himmelma@33175
   846
himmelma@33175
   847
lemma connected_empty[simp, intro]: "connected {}"
himmelma@33175
   848
  by (simp add: connected_def)
himmelma@33175
   849
huffman@45081
   850
himmelma@33175
   851
subsection{* Limit points *}
himmelma@33175
   852
huffman@45078
   853
definition (in topological_space)
huffman@45078
   854
  islimpt:: "'a \<Rightarrow> 'a set \<Rightarrow> bool" (infixr "islimpt" 60) where
himmelma@33175
   855
  "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
   856
himmelma@33175
   857
lemma islimptI:
himmelma@33175
   858
  assumes "\<And>T. x \<in> T \<Longrightarrow> open T \<Longrightarrow> \<exists>y\<in>S. y \<in> T \<and> y \<noteq> x"
himmelma@33175
   859
  shows "x islimpt S"
himmelma@33175
   860
  using assms unfolding islimpt_def by auto
himmelma@33175
   861
himmelma@33175
   862
lemma islimptE:
himmelma@33175
   863
  assumes "x islimpt S" and "x \<in> T" and "open T"
himmelma@33175
   864
  obtains y where "y \<in> S" and "y \<in> T" and "y \<noteq> x"
himmelma@33175
   865
  using assms unfolding islimpt_def by auto
himmelma@33175
   866
huffman@45448
   867
lemma islimpt_iff_eventually: "x islimpt S \<longleftrightarrow> \<not> eventually (\<lambda>y. y \<notin> S) (at x)"
huffman@45448
   868
  unfolding islimpt_def eventually_at_topological by auto
huffman@45448
   869
huffman@45448
   870
lemma islimpt_subset: "\<lbrakk>x islimpt S; S \<subseteq> T\<rbrakk> \<Longrightarrow> x islimpt T"
huffman@45448
   871
  unfolding islimpt_def by fast
himmelma@33175
   872
himmelma@33175
   873
lemma islimpt_approachable:
himmelma@33175
   874
  fixes x :: "'a::metric_space"
himmelma@33175
   875
  shows "x islimpt S \<longleftrightarrow> (\<forall>e>0. \<exists>x'\<in>S. x' \<noteq> x \<and> dist x' x < e)"
huffman@45448
   876
  unfolding islimpt_iff_eventually eventually_at by fast
himmelma@33175
   877
himmelma@33175
   878
lemma islimpt_approachable_le:
himmelma@33175
   879
  fixes x :: "'a::metric_space"
himmelma@33175
   880
  shows "x islimpt S \<longleftrightarrow> (\<forall>e>0. \<exists>x'\<in> S. x' \<noteq> x \<and> dist x' x <= e)"
himmelma@33175
   881
  unfolding islimpt_approachable
huffman@45448
   882
  using approachable_lt_le [where f="\<lambda>y. dist y x" and P="\<lambda>y. y \<notin> S \<or> y = x",
huffman@45448
   883
    THEN arg_cong [where f=Not]]
huffman@45448
   884
  by (simp add: Bex_def conj_commute conj_left_commute)
himmelma@33175
   885
huffman@45442
   886
lemma islimpt_UNIV_iff: "x islimpt UNIV \<longleftrightarrow> \<not> open {x}"
huffman@45442
   887
  unfolding islimpt_def by (safe, fast, case_tac "T = {x}", fast, fast)
huffman@45442
   888
huffman@45081
   889
text {* A perfect space has no isolated points. *}
huffman@45081
   890
huffman@45442
   891
lemma islimpt_UNIV [simp, intro]: "(x::'a::perfect_space) islimpt UNIV"
huffman@45442
   892
  unfolding islimpt_UNIV_iff by (rule not_open_singleton)
himmelma@33175
   893
himmelma@33175
   894
lemma perfect_choose_dist:
huffman@44943
   895
  fixes x :: "'a::{perfect_space, metric_space}"
himmelma@33175
   896
  shows "0 < r \<Longrightarrow> \<exists>a. a \<noteq> x \<and> dist a x < r"
himmelma@33175
   897
using islimpt_UNIV [of x]
himmelma@33175
   898
by (simp add: islimpt_approachable)
himmelma@33175
   899
himmelma@33175
   900
lemma closed_limpt: "closed S \<longleftrightarrow> (\<forall>x. x islimpt S \<longrightarrow> x \<in> S)"
himmelma@33175
   901
  unfolding closed_def
himmelma@33175
   902
  apply (subst open_subopen)
huffman@34099
   903
  apply (simp add: islimpt_def subset_eq)
huffman@45035
   904
  by (metis ComplE ComplI)
himmelma@33175
   905
himmelma@33175
   906
lemma islimpt_EMPTY[simp]: "\<not> x islimpt {}"
himmelma@33175
   907
  unfolding islimpt_def by auto
himmelma@33175
   908
himmelma@33175
   909
lemma finite_set_avoid:
himmelma@33175
   910
  fixes a :: "'a::metric_space"
himmelma@33175
   911
  assumes fS: "finite S" shows  "\<exists>d>0. \<forall>x\<in>S. x \<noteq> a \<longrightarrow> d <= dist a x"
himmelma@33175
   912
proof(induct rule: finite_induct[OF fS])
boehmes@42734
   913
  case 1 thus ?case by (auto intro: zero_less_one)
himmelma@33175
   914
next
himmelma@33175
   915
  case (2 x F)
himmelma@33175
   916
  from 2 obtain d where d: "d >0" "\<forall>x\<in>F. x\<noteq>a \<longrightarrow> d \<le> dist a x" by blast
himmelma@33175
   917
  {assume "x = a" hence ?case using d by auto  }
himmelma@33175
   918
  moreover
himmelma@33175
   919
  {assume xa: "x\<noteq>a"
himmelma@33175
   920
    let ?d = "min d (dist a x)"
himmelma@33175
   921
    have dp: "?d > 0" using xa d(1) using dist_nz by auto
himmelma@33175
   922
    from d have d': "\<forall>x\<in>F. x\<noteq>a \<longrightarrow> ?d \<le> dist a x" by auto
himmelma@33175
   923
    with dp xa have ?case by(auto intro!: exI[where x="?d"]) }
himmelma@33175
   924
  ultimately show ?case by blast
himmelma@33175
   925
qed
himmelma@33175
   926
himmelma@33175
   927
lemma islimpt_Un: "x islimpt (S \<union> T) \<longleftrightarrow> x islimpt S \<or> x islimpt T"
huffman@51912
   928
  by (simp add: islimpt_iff_eventually eventually_conj_iff)
himmelma@33175
   929
himmelma@33175
   930
lemma discrete_imp_closed:
himmelma@33175
   931
  fixes S :: "'a::metric_space set"
himmelma@33175
   932
  assumes e: "0 < e" and d: "\<forall>x \<in> S. \<forall>y \<in> S. dist y x < e \<longrightarrow> y = x"
himmelma@33175
   933
  shows "closed S"
himmelma@33175
   934
proof-
himmelma@33175
   935
  {fix x assume C: "\<forall>e>0. \<exists>x'\<in>S. x' \<noteq> x \<and> dist x' x < e"
himmelma@33175
   936
    from e have e2: "e/2 > 0" by arith
himmelma@33175
   937
    from C[rule_format, OF e2] obtain y where y: "y \<in> S" "y\<noteq>x" "dist y x < e/2" by blast
himmelma@33175
   938
    let ?m = "min (e/2) (dist x y) "
himmelma@33175
   939
    from e2 y(2) have mp: "?m > 0" by (simp add: dist_nz[THEN sym])
himmelma@33175
   940
    from C[rule_format, OF mp] obtain z where z: "z \<in> S" "z\<noteq>x" "dist z x < ?m" by blast
himmelma@33175
   941
    have th: "dist z y < e" using z y
himmelma@33175
   942
      by (intro dist_triangle_lt [where z=x], simp)
himmelma@33175
   943
    from d[rule_format, OF y(1) z(1) th] y z
himmelma@33175
   944
    have False by (auto simp add: dist_commute)}
himmelma@33175
   945
  then show ?thesis by (metis islimpt_approachable closed_limpt [where 'a='a])
himmelma@33175
   946
qed
himmelma@33175
   947
huffman@45081
   948
huffman@45081
   949
subsection {* Interior of a Set *}
huffman@45081
   950
huffman@45374
   951
definition "interior S = \<Union>{T. open T \<and> T \<subseteq> S}"
huffman@45374
   952
huffman@45374
   953
lemma interiorI [intro?]:
huffman@45374
   954
  assumes "open T" and "x \<in> T" and "T \<subseteq> S"
huffman@45374
   955
  shows "x \<in> interior S"
huffman@45374
   956
  using assms unfolding interior_def by fast
huffman@45374
   957
huffman@45374
   958
lemma interiorE [elim?]:
huffman@45374
   959
  assumes "x \<in> interior S"
huffman@45374
   960
  obtains T where "open T" and "x \<in> T" and "T \<subseteq> S"
huffman@45374
   961
  using assms unfolding interior_def by fast
huffman@45374
   962
huffman@45374
   963
lemma open_interior [simp, intro]: "open (interior S)"
huffman@45374
   964
  by (simp add: interior_def open_Union)
huffman@45374
   965
huffman@45374
   966
lemma interior_subset: "interior S \<subseteq> S"
huffman@45374
   967
  by (auto simp add: interior_def)
huffman@45374
   968
huffman@45374
   969
lemma interior_maximal: "T \<subseteq> S \<Longrightarrow> open T \<Longrightarrow> T \<subseteq> interior S"
huffman@45374
   970
  by (auto simp add: interior_def)
huffman@45374
   971
huffman@45374
   972
lemma interior_open: "open S \<Longrightarrow> interior S = S"
huffman@45374
   973
  by (intro equalityI interior_subset interior_maximal subset_refl)
himmelma@33175
   974
himmelma@33175
   975
lemma interior_eq: "interior S = S \<longleftrightarrow> open S"
huffman@45374
   976
  by (metis open_interior interior_open)
huffman@45374
   977
huffman@45374
   978
lemma open_subset_interior: "open S \<Longrightarrow> S \<subseteq> interior T \<longleftrightarrow> S \<subseteq> T"
himmelma@33175
   979
  by (metis interior_maximal interior_subset subset_trans)
himmelma@33175
   980
huffman@45374
   981
lemma interior_empty [simp]: "interior {} = {}"
huffman@45374
   982
  using open_empty by (rule interior_open)
huffman@45374
   983
huffman@45377
   984
lemma interior_UNIV [simp]: "interior UNIV = UNIV"
huffman@45377
   985
  using open_UNIV by (rule interior_open)
huffman@45377
   986
huffman@45374
   987
lemma interior_interior [simp]: "interior (interior S) = interior S"
huffman@45374
   988
  using open_interior by (rule interior_open)
huffman@45374
   989
huffman@45377
   990
lemma interior_mono: "S \<subseteq> T \<Longrightarrow> interior S \<subseteq> interior T"
huffman@45377
   991
  by (auto simp add: interior_def)
huffman@45374
   992
huffman@45374
   993
lemma interior_unique:
huffman@45374
   994
  assumes "T \<subseteq> S" and "open T"
huffman@45374
   995
  assumes "\<And>T'. T' \<subseteq> S \<Longrightarrow> open T' \<Longrightarrow> T' \<subseteq> T"
huffman@45374
   996
  shows "interior S = T"
huffman@45374
   997
  by (intro equalityI assms interior_subset open_interior interior_maximal)
huffman@45374
   998
huffman@45374
   999
lemma interior_inter [simp]: "interior (S \<inter> T) = interior S \<inter> interior T"
huffman@45377
  1000
  by (intro equalityI Int_mono Int_greatest interior_mono Int_lower1
huffman@45374
  1001
    Int_lower2 interior_maximal interior_subset open_Int open_interior)
huffman@45374
  1002
huffman@45374
  1003
lemma mem_interior: "x \<in> interior S \<longleftrightarrow> (\<exists>e>0. ball x e \<subseteq> S)"
huffman@45374
  1004
  using open_contains_ball_eq [where S="interior S"]
huffman@45374
  1005
  by (simp add: open_subset_interior)
himmelma@33175
  1006
himmelma@33175
  1007
lemma interior_limit_point [intro]:
himmelma@33175
  1008
  fixes x :: "'a::perfect_space"
himmelma@33175
  1009
  assumes x: "x \<in> interior S" shows "x islimpt S"
huffman@44943
  1010
  using x islimpt_UNIV [of x]
huffman@44943
  1011
  unfolding interior_def islimpt_def
huffman@44943
  1012
  apply (clarsimp, rename_tac T T')
huffman@44943
  1013
  apply (drule_tac x="T \<inter> T'" in spec)
huffman@44943
  1014
  apply (auto simp add: open_Int)
huffman@44943
  1015
  done
himmelma@33175
  1016
himmelma@33175
  1017
lemma interior_closed_Un_empty_interior:
himmelma@33175
  1018
  assumes cS: "closed S" and iT: "interior T = {}"
huffman@45374
  1019
  shows "interior (S \<union> T) = interior S"
himmelma@33175
  1020
proof
huffman@45374
  1021
  show "interior S \<subseteq> interior (S \<union> T)"
huffman@45377
  1022
    by (rule interior_mono, rule Un_upper1)
himmelma@33175
  1023
next
himmelma@33175
  1024
  show "interior (S \<union> T) \<subseteq> interior S"
himmelma@33175
  1025
  proof
himmelma@33175
  1026
    fix x assume "x \<in> interior (S \<union> T)"
huffman@45374
  1027
    then obtain R where "open R" "x \<in> R" "R \<subseteq> S \<union> T" ..
himmelma@33175
  1028
    show "x \<in> interior S"
himmelma@33175
  1029
    proof (rule ccontr)
himmelma@33175
  1030
      assume "x \<notin> interior S"
himmelma@33175
  1031
      with `x \<in> R` `open R` obtain y where "y \<in> R - S"
huffman@45374
  1032
        unfolding interior_def by fast
himmelma@33175
  1033
      from `open R` `closed S` have "open (R - S)" by (rule open_Diff)
himmelma@33175
  1034
      from `R \<subseteq> S \<union> T` have "R - S \<subseteq> T" by fast
himmelma@33175
  1035
      from `y \<in> R - S` `open (R - S)` `R - S \<subseteq> T` `interior T = {}`
himmelma@33175
  1036
      show "False" unfolding interior_def by fast
himmelma@33175
  1037
    qed
himmelma@33175
  1038
  qed
himmelma@33175
  1039
qed
himmelma@33175
  1040
huffman@45236
  1041
lemma interior_Times: "interior (A \<times> B) = interior A \<times> interior B"
huffman@45236
  1042
proof (rule interior_unique)
huffman@45236
  1043
  show "interior A \<times> interior B \<subseteq> A \<times> B"
huffman@45236
  1044
    by (intro Sigma_mono interior_subset)
huffman@45236
  1045
  show "open (interior A \<times> interior B)"
huffman@45236
  1046
    by (intro open_Times open_interior)
huffman@45374
  1047
  fix T assume "T \<subseteq> A \<times> B" and "open T" thus "T \<subseteq> interior A \<times> interior B"
huffman@45374
  1048
  proof (safe)
huffman@45374
  1049
    fix x y assume "(x, y) \<in> T"
huffman@45374
  1050
    then obtain C D where "open C" "open D" "C \<times> D \<subseteq> T" "x \<in> C" "y \<in> D"
huffman@45374
  1051
      using `open T` unfolding open_prod_def by fast
huffman@45374
  1052
    hence "open C" "open D" "C \<subseteq> A" "D \<subseteq> B" "x \<in> C" "y \<in> D"
huffman@45374
  1053
      using `T \<subseteq> A \<times> B` by auto
huffman@45374
  1054
    thus "x \<in> interior A" and "y \<in> interior B"
huffman@45374
  1055
      by (auto intro: interiorI)
huffman@45374
  1056
  qed
huffman@45236
  1057
qed
huffman@45236
  1058
himmelma@33175
  1059
huffman@45081
  1060
subsection {* Closure of a Set *}
himmelma@33175
  1061
himmelma@33175
  1062
definition "closure S = S \<union> {x | x. x islimpt S}"
himmelma@33175
  1063
huffman@45373
  1064
lemma interior_closure: "interior S = - (closure (- S))"
huffman@45373
  1065
  unfolding interior_def closure_def islimpt_def by auto
huffman@45373
  1066
huffman@34099
  1067
lemma closure_interior: "closure S = - interior (- S)"
huffman@45373
  1068
  unfolding interior_closure by simp
himmelma@33175
  1069
himmelma@33175
  1070
lemma closed_closure[simp, intro]: "closed (closure S)"
huffman@45373
  1071
  unfolding closure_interior by (simp add: closed_Compl)
huffman@45373
  1072
huffman@45373
  1073
lemma closure_subset: "S \<subseteq> closure S"
huffman@45373
  1074
  unfolding closure_def by simp
himmelma@33175
  1075
himmelma@33175
  1076
lemma closure_hull: "closure S = closed hull S"
huffman@45374
  1077
  unfolding hull_def closure_interior interior_def by auto
himmelma@33175
  1078
himmelma@33175
  1079
lemma closure_eq: "closure S = S \<longleftrightarrow> closed S"
huffman@45374
  1080
  unfolding closure_hull using closed_Inter by (rule hull_eq)
huffman@45374
  1081
huffman@45374
  1082
lemma closure_closed [simp]: "closed S \<Longrightarrow> closure S = S"
huffman@45374
  1083
  unfolding closure_eq .
huffman@45374
  1084
huffman@45374
  1085
lemma closure_closure [simp]: "closure (closure S) = closure S"
huffman@45373
  1086
  unfolding closure_hull by (rule hull_hull)
himmelma@33175
  1087
huffman@45377
  1088
lemma closure_mono: "S \<subseteq> T \<Longrightarrow> closure S \<subseteq> closure T"
huffman@45373
  1089
  unfolding closure_hull by (rule hull_mono)
himmelma@33175
  1090
huffman@45374
  1091
lemma closure_minimal: "S \<subseteq> T \<Longrightarrow> closed T \<Longrightarrow> closure S \<subseteq> T"
huffman@45373
  1092
  unfolding closure_hull by (rule hull_minimal)
himmelma@33175
  1093
huffman@45374
  1094
lemma closure_unique:
huffman@45374
  1095
  assumes "S \<subseteq> T" and "closed T"
huffman@45374
  1096
  assumes "\<And>T'. S \<subseteq> T' \<Longrightarrow> closed T' \<Longrightarrow> T \<subseteq> T'"
huffman@45374
  1097
  shows "closure S = T"
huffman@45374
  1098
  using assms unfolding closure_hull by (rule hull_unique)
huffman@45374
  1099
huffman@45374
  1100
lemma closure_empty [simp]: "closure {} = {}"
huffman@45373
  1101
  using closed_empty by (rule closure_closed)
himmelma@33175
  1102
huffman@45377
  1103
lemma closure_UNIV [simp]: "closure UNIV = UNIV"
huffman@45373
  1104
  using closed_UNIV by (rule closure_closed)
huffman@45373
  1105
huffman@45373
  1106
lemma closure_union [simp]: "closure (S \<union> T) = closure S \<union> closure T"
huffman@45373
  1107
  unfolding closure_interior by simp
himmelma@33175
  1108
himmelma@33175
  1109
lemma closure_eq_empty: "closure S = {} \<longleftrightarrow> S = {}"
himmelma@33175
  1110
  using closure_empty closure_subset[of S]
himmelma@33175
  1111
  by blast
himmelma@33175
  1112
himmelma@33175
  1113
lemma closure_subset_eq: "closure S \<subseteq> S \<longleftrightarrow> closed S"
himmelma@33175
  1114
  using closure_eq[of S] closure_subset[of S]
himmelma@33175
  1115
  by simp
himmelma@33175
  1116
himmelma@33175
  1117
lemma open_inter_closure_eq_empty:
himmelma@33175
  1118
  "open S \<Longrightarrow> (S \<inter> closure T) = {} \<longleftrightarrow> S \<inter> T = {}"
huffman@34099
  1119
  using open_subset_interior[of S "- T"]
huffman@34099
  1120
  using interior_subset[of "- T"]
himmelma@33175
  1121
  unfolding closure_interior
himmelma@33175
  1122
  by auto
himmelma@33175
  1123
himmelma@33175
  1124
lemma open_inter_closure_subset:
himmelma@33175
  1125
  "open S \<Longrightarrow> (S \<inter> (closure T)) \<subseteq> closure(S \<inter> T)"
himmelma@33175
  1126
proof
himmelma@33175
  1127
  fix x
himmelma@33175
  1128
  assume as: "open S" "x \<in> S \<inter> closure T"
himmelma@33175
  1129
  { assume *:"x islimpt T"
himmelma@33175
  1130
    have "x islimpt (S \<inter> T)"
himmelma@33175
  1131
    proof (rule islimptI)
himmelma@33175
  1132
      fix A
himmelma@33175
  1133
      assume "x \<in> A" "open A"
himmelma@33175
  1134
      with as have "x \<in> A \<inter> S" "open (A \<inter> S)"
himmelma@33175
  1135
        by (simp_all add: open_Int)
himmelma@33175
  1136
      with * obtain y where "y \<in> T" "y \<in> A \<inter> S" "y \<noteq> x"
himmelma@33175
  1137
        by (rule islimptE)
himmelma@33175
  1138
      hence "y \<in> S \<inter> T" "y \<in> A \<and> y \<noteq> x"
himmelma@33175
  1139
        by simp_all
himmelma@33175
  1140
      thus "\<exists>y\<in>(S \<inter> T). y \<in> A \<and> y \<noteq> x" ..
himmelma@33175
  1141
    qed
himmelma@33175
  1142
  }
himmelma@33175
  1143
  then show "x \<in> closure (S \<inter> T)" using as
himmelma@33175
  1144
    unfolding closure_def
himmelma@33175
  1145
    by blast
himmelma@33175
  1146
qed
himmelma@33175
  1147
huffman@45374
  1148
lemma closure_complement: "closure (- S) = - interior S"
huffman@45373
  1149
  unfolding closure_interior by simp
himmelma@33175
  1150
huffman@45374
  1151
lemma interior_complement: "interior (- S) = - closure S"
huffman@45373
  1152
  unfolding closure_interior by simp
himmelma@33175
  1153
huffman@45236
  1154
lemma closure_Times: "closure (A \<times> B) = closure A \<times> closure B"
huffman@45374
  1155
proof (rule closure_unique)
huffman@45236
  1156
  show "A \<times> B \<subseteq> closure A \<times> closure B"
huffman@45236
  1157
    by (intro Sigma_mono closure_subset)
huffman@45236
  1158
  show "closed (closure A \<times> closure B)"
huffman@45236
  1159
    by (intro closed_Times closed_closure)
huffman@45374
  1160
  fix T assume "A \<times> B \<subseteq> T" and "closed T" thus "closure A \<times> closure B \<subseteq> T"
huffman@45236
  1161
    apply (simp add: closed_def open_prod_def, clarify)
huffman@45236
  1162
    apply (rule ccontr)
huffman@45236
  1163
    apply (drule_tac x="(a, b)" in bspec, simp, clarify, rename_tac C D)
huffman@45236
  1164
    apply (simp add: closure_interior interior_def)
huffman@45236
  1165
    apply (drule_tac x=C in spec)
huffman@45236
  1166
    apply (drule_tac x=D in spec)
huffman@45236
  1167
    apply auto
huffman@45236
  1168
    done
huffman@45236
  1169
qed
huffman@45236
  1170
huffman@45081
  1171
huffman@45081
  1172
subsection {* Frontier (aka boundary) *}
himmelma@33175
  1173
himmelma@33175
  1174
definition "frontier S = closure S - interior S"
himmelma@33175
  1175
himmelma@33175
  1176
lemma frontier_closed: "closed(frontier S)"
himmelma@33175
  1177
  by (simp add: frontier_def closed_Diff)
himmelma@33175
  1178
huffman@34099
  1179
lemma frontier_closures: "frontier S = (closure S) \<inter> (closure(- S))"
himmelma@33175
  1180
  by (auto simp add: frontier_def interior_closure)
himmelma@33175
  1181
himmelma@33175
  1182
lemma frontier_straddle:
himmelma@33175
  1183
  fixes a :: "'a::metric_space"
huffman@45780
  1184
  shows "a \<in> frontier S \<longleftrightarrow> (\<forall>e>0. (\<exists>x\<in>S. dist a x < e) \<and> (\<exists>x. x \<notin> S \<and> dist a x < e))"
huffman@45780
  1185
  unfolding frontier_def closure_interior
huffman@45780
  1186
  by (auto simp add: mem_interior subset_eq ball_def)
himmelma@33175
  1187
himmelma@33175
  1188
lemma frontier_subset_closed: "closed S \<Longrightarrow> frontier S \<subseteq> S"
himmelma@33175
  1189
  by (metis frontier_def closure_closed Diff_subset)
himmelma@33175
  1190
hoelzl@34951
  1191
lemma frontier_empty[simp]: "frontier {} = {}"
huffman@36358
  1192
  by (simp add: frontier_def)
himmelma@33175
  1193
himmelma@33175
  1194
lemma frontier_subset_eq: "frontier S \<subseteq> S \<longleftrightarrow> closed S"
himmelma@33175
  1195
proof-
himmelma@33175
  1196
  { assume "frontier S \<subseteq> S"
himmelma@33175
  1197
    hence "closure S \<subseteq> S" using interior_subset unfolding frontier_def by auto
himmelma@33175
  1198
    hence "closed S" using closure_subset_eq by auto
himmelma@33175
  1199
  }
huffman@36358
  1200
  thus ?thesis using frontier_subset_closed[of S] ..
himmelma@33175
  1201
qed
himmelma@33175
  1202
huffman@34099
  1203
lemma frontier_complement: "frontier(- S) = frontier S"
himmelma@33175
  1204
  by (auto simp add: frontier_def closure_complement interior_complement)
himmelma@33175
  1205
himmelma@33175
  1206
lemma frontier_disjoint_eq: "frontier S \<inter> S = {} \<longleftrightarrow> open S"
huffman@34099
  1207
  using frontier_complement frontier_subset_eq[of "- S"]
huffman@34099
  1208
  unfolding open_closed by auto
himmelma@33175
  1209
huffman@44952
  1210
subsection {* Filters and the ``eventually true'' quantifier *}
huffman@44952
  1211
himmelma@33175
  1212
definition
huffman@44952
  1213
  indirection :: "'a::real_normed_vector \<Rightarrow> 'a \<Rightarrow> 'a filter"
huffman@44952
  1214
    (infixr "indirection" 70) where
himmelma@33175
  1215
  "a indirection v = (at a) within {b. \<exists>c\<ge>0. b - a = scaleR c v}"
himmelma@33175
  1216
huffman@36433
  1217
text {* Identify Trivial limits, where we can't approach arbitrarily closely. *}
himmelma@33175
  1218
himmelma@33175
  1219
lemma trivial_limit_within:
himmelma@33175
  1220
  shows "trivial_limit (at a within S) \<longleftrightarrow> \<not> a islimpt S"
himmelma@33175
  1221
proof
himmelma@33175
  1222
  assume "trivial_limit (at a within S)"
himmelma@33175
  1223
  thus "\<not> a islimpt S"
himmelma@33175
  1224
    unfolding trivial_limit_def
huffman@36354
  1225
    unfolding eventually_within eventually_at_topological
himmelma@33175
  1226
    unfolding islimpt_def
nipkow@39535
  1227
    apply (clarsimp simp add: set_eq_iff)
himmelma@33175
  1228
    apply (rename_tac T, rule_tac x=T in exI)
huffman@36354
  1229
    apply (clarsimp, drule_tac x=y in bspec, simp_all)
himmelma@33175
  1230
    done
himmelma@33175
  1231
next
himmelma@33175
  1232
  assume "\<not> a islimpt S"
himmelma@33175
  1233
  thus "trivial_limit (at a within S)"
himmelma@33175
  1234
    unfolding trivial_limit_def
huffman@36354
  1235
    unfolding eventually_within eventually_at_topological
himmelma@33175
  1236
    unfolding islimpt_def
huffman@36354
  1237
    apply clarsimp
huffman@36354
  1238
    apply (rule_tac x=T in exI)
huffman@36354
  1239
    apply auto
himmelma@33175
  1240
    done
himmelma@33175
  1241
qed
himmelma@33175
  1242
himmelma@33175
  1243
lemma trivial_limit_at_iff: "trivial_limit (at a) \<longleftrightarrow> \<not> a islimpt UNIV"
huffman@45896
  1244
  using trivial_limit_within [of a UNIV] by simp
himmelma@33175
  1245
himmelma@33175
  1246
lemma trivial_limit_at:
himmelma@33175
  1247
  fixes a :: "'a::perfect_space"
himmelma@33175
  1248
  shows "\<not> trivial_limit (at a)"
huffman@45442
  1249
  by (rule at_neq_bot)
himmelma@33175
  1250
himmelma@33175
  1251
lemma trivial_limit_at_infinity:
huffman@44952
  1252
  "\<not> trivial_limit (at_infinity :: ('a::{real_normed_vector,perfect_space}) filter)"
huffman@36354
  1253
  unfolding trivial_limit_def eventually_at_infinity
huffman@36354
  1254
  apply clarsimp
huffman@44943
  1255
  apply (subgoal_tac "\<exists>x::'a. x \<noteq> 0", clarify)
huffman@44943
  1256
   apply (rule_tac x="scaleR (b / norm x) x" in exI, simp)
huffman@44943
  1257
  apply (cut_tac islimpt_UNIV [of "0::'a", unfolded islimpt_def])
huffman@44943
  1258
  apply (drule_tac x=UNIV in spec, simp)
himmelma@33175
  1259
  done
himmelma@33175
  1260
huffman@36433
  1261
text {* Some property holds "sufficiently close" to the limit point. *}
himmelma@33175
  1262
himmelma@33175
  1263
lemma eventually_at: (* FIXME: this replaces Limits.eventually_at *)
himmelma@33175
  1264
  "eventually P (at a) \<longleftrightarrow> (\<exists>d>0. \<forall>x. 0 < dist x a \<and> dist x a < d \<longrightarrow> P x)"
himmelma@33175
  1265
unfolding eventually_at dist_nz by auto
himmelma@33175
  1266
hoelzl@51541
  1267
lemma eventually_within: (* FIXME: this replaces Limits.eventually_within *)
hoelzl@51541
  1268
  "eventually P (at a within S) \<longleftrightarrow>
himmelma@33175
  1269
        (\<exists>d>0. \<forall>x\<in>S. 0 < dist x a \<and> dist x a < d \<longrightarrow> P x)"
hoelzl@51541
  1270
  by (rule eventually_within_less)
himmelma@33175
  1271
himmelma@33175
  1272
lemma eventually_happens: "eventually P net ==> trivial_limit net \<or> (\<exists>x. P x)"
huffman@36354
  1273
  unfolding trivial_limit_def
huffman@36354
  1274
  by (auto elim: eventually_rev_mp)
himmelma@33175
  1275
himmelma@33175
  1276
lemma trivial_limit_eventually: "trivial_limit net \<Longrightarrow> eventually P net"
huffman@45896
  1277
  by simp
himmelma@33175
  1278
himmelma@33175
  1279
lemma trivial_limit_eq: "trivial_limit net \<longleftrightarrow> (\<forall>P. eventually P net)"
huffman@45201
  1280
  by (simp add: filter_eq_iff)
himmelma@33175
  1281
himmelma@33175
  1282
text{* Combining theorems for "eventually" *}
himmelma@33175
  1283
himmelma@33175
  1284
lemma eventually_rev_mono:
himmelma@33175
  1285
  "eventually P net \<Longrightarrow> (\<forall>x. P x \<longrightarrow> Q x) \<Longrightarrow> eventually Q net"
himmelma@33175
  1286
using eventually_mono [of P Q] by fast
himmelma@33175
  1287
himmelma@33175
  1288
lemma not_eventually: "(\<forall>x. \<not> P x ) \<Longrightarrow> ~(trivial_limit net) ==> ~(eventually (\<lambda>x. P x) net)"
himmelma@33175
  1289
  by (simp add: eventually_False)
himmelma@33175
  1290
huffman@45081
  1291
huffman@36433
  1292
subsection {* Limits *}
himmelma@33175
  1293
huffman@44952
  1294
text{* Notation Lim to avoid collition with lim defined in analysis *}
huffman@44952
  1295
huffman@44952
  1296
definition Lim :: "'a filter \<Rightarrow> ('a \<Rightarrow> 'b::t2_space) \<Rightarrow> 'b"
huffman@44952
  1297
  where "Lim A f = (THE l. (f ---> l) A)"
himmelma@33175
  1298
himmelma@33175
  1299
lemma Lim:
himmelma@33175
  1300
 "(f ---> l) net \<longleftrightarrow>
himmelma@33175
  1301
        trivial_limit net \<or>
himmelma@33175
  1302
        (\<forall>e>0. eventually (\<lambda>x. dist (f x) l < e) net)"
himmelma@33175
  1303
  unfolding tendsto_iff trivial_limit_eq by auto
himmelma@33175
  1304
himmelma@33175
  1305
text{* Show that they yield usual definitions in the various cases. *}
himmelma@33175
  1306
himmelma@33175
  1307
lemma Lim_within_le: "(f ---> l)(at a within S) \<longleftrightarrow>
himmelma@33175
  1308
           (\<forall>e>0. \<exists>d>0. \<forall>x\<in>S. 0 < dist x a  \<and> dist x a  <= d \<longrightarrow> dist (f x) l < e)"
himmelma@33175
  1309
  by (auto simp add: tendsto_iff eventually_within_le)
himmelma@33175
  1310
himmelma@33175
  1311
lemma Lim_within: "(f ---> l) (at a within S) \<longleftrightarrow>
himmelma@33175
  1312
        (\<forall>e >0. \<exists>d>0. \<forall>x \<in> S. 0 < dist x a  \<and> dist x a  < d  \<longrightarrow> dist (f x) l < e)"
himmelma@33175
  1313
  by (auto simp add: tendsto_iff eventually_within)
himmelma@33175
  1314
himmelma@33175
  1315
lemma Lim_at: "(f ---> l) (at a) \<longleftrightarrow>
himmelma@33175
  1316
        (\<forall>e >0. \<exists>d>0. \<forall>x. 0 < dist x a  \<and> dist x a  < d  \<longrightarrow> dist (f x) l < e)"
himmelma@33175
  1317
  by (auto simp add: tendsto_iff eventually_at)
himmelma@33175
  1318
himmelma@33175
  1319
lemma Lim_at_infinity:
himmelma@33175
  1320
  "(f ---> l) at_infinity \<longleftrightarrow> (\<forall>e>0. \<exists>b. \<forall>x. norm x >= b \<longrightarrow> dist (f x) l < e)"
himmelma@33175
  1321
  by (auto simp add: tendsto_iff eventually_at_infinity)
himmelma@33175
  1322
himmelma@33175
  1323
lemma Lim_eventually: "eventually (\<lambda>x. f x = l) net \<Longrightarrow> (f ---> l) net"
himmelma@33175
  1324
  by (rule topological_tendstoI, auto elim: eventually_rev_mono)
himmelma@33175
  1325
himmelma@33175
  1326
text{* The expected monotonicity property. *}
himmelma@33175
  1327
himmelma@33175
  1328
lemma Lim_within_empty: "(f ---> l) (net within {})"
himmelma@33175
  1329
  unfolding tendsto_def Limits.eventually_within by simp
himmelma@33175
  1330
himmelma@33175
  1331
lemma Lim_within_subset: "(f ---> l) (net within S) \<Longrightarrow> T \<subseteq> S \<Longrightarrow> (f ---> l) (net within T)"
himmelma@33175
  1332
  unfolding tendsto_def Limits.eventually_within
himmelma@33175
  1333
  by (auto elim!: eventually_elim1)
himmelma@33175
  1334
himmelma@33175
  1335
lemma Lim_Un: assumes "(f ---> l) (net within S)" "(f ---> l) (net within T)"
himmelma@33175
  1336
  shows "(f ---> l) (net within (S \<union> T))"
himmelma@33175
  1337
  using assms unfolding tendsto_def Limits.eventually_within
himmelma@33175
  1338
  apply clarify
himmelma@33175
  1339
  apply (drule spec, drule (1) mp, drule (1) mp)
himmelma@33175
  1340
  apply (drule spec, drule (1) mp, drule (1) mp)
himmelma@33175
  1341
  apply (auto elim: eventually_elim2)
himmelma@33175
  1342
  done
himmelma@33175
  1343
himmelma@33175
  1344
lemma Lim_Un_univ:
himmelma@33175
  1345
 "(f ---> l) (net within S) \<Longrightarrow> (f ---> l) (net within T) \<Longrightarrow>  S \<union> T = UNIV
himmelma@33175
  1346
        ==> (f ---> l) net"
himmelma@33175
  1347
  by (metis Lim_Un within_UNIV)
himmelma@33175
  1348
himmelma@33175
  1349
text{* Interrelations between restricted and unrestricted limits. *}
himmelma@33175
  1350
himmelma@33175
  1351
lemma Lim_at_within: "(f ---> l) net ==> (f ---> l)(net within S)"
himmelma@33175
  1352
  (* FIXME: rename *)
himmelma@33175
  1353
  unfolding tendsto_def Limits.eventually_within
himmelma@33175
  1354
  apply (clarify, drule spec, drule (1) mp, drule (1) mp)
himmelma@33175
  1355
  by (auto elim!: eventually_elim1)
himmelma@33175
  1356
huffman@45081
  1357
lemma eventually_within_interior:
huffman@45081
  1358
  assumes "x \<in> interior S"
huffman@45081
  1359
  shows "eventually P (at x within S) \<longleftrightarrow> eventually P (at x)" (is "?lhs = ?rhs")
huffman@45081
  1360
proof-
huffman@45374
  1361
  from assms obtain T where T: "open T" "x \<in> T" "T \<subseteq> S" ..
huffman@45081
  1362
  { assume "?lhs"
huffman@45081
  1363
    then obtain A where "open A" "x \<in> A" "\<forall>y\<in>A. y \<noteq> x \<longrightarrow> y \<in> S \<longrightarrow> P y"
huffman@45081
  1364
      unfolding Limits.eventually_within Limits.eventually_at_topological
huffman@45081
  1365
      by auto
huffman@45081
  1366
    with T have "open (A \<inter> T)" "x \<in> A \<inter> T" "\<forall>y\<in>(A \<inter> T). y \<noteq> x \<longrightarrow> P y"
huffman@45081
  1367
      by auto
huffman@45081
  1368
    then have "?rhs"
huffman@45081
  1369
      unfolding Limits.eventually_at_topological by auto
huffman@45081
  1370
  } moreover
huffman@45081
  1371
  { assume "?rhs" hence "?lhs"
huffman@45081
  1372
      unfolding Limits.eventually_within
huffman@45081
  1373
      by (auto elim: eventually_elim1)
huffman@45081
  1374
  } ultimately
huffman@45081
  1375
  show "?thesis" ..
huffman@45081
  1376
qed
huffman@45081
  1377
huffman@45081
  1378
lemma at_within_interior:
huffman@45081
  1379
  "x \<in> interior S \<Longrightarrow> at x within S = at x"
huffman@45081
  1380
  by (simp add: filter_eq_iff eventually_within_interior)
huffman@45081
  1381
huffman@45081
  1382
lemma at_within_open:
huffman@45081
  1383
  "\<lbrakk>x \<in> S; open S\<rbrakk> \<Longrightarrow> at x within S = at x"
huffman@45081
  1384
  by (simp only: at_within_interior interior_open)
huffman@45081
  1385
himmelma@33175
  1386
lemma Lim_within_open:
himmelma@33175
  1387
  fixes f :: "'a::topological_space \<Rightarrow> 'b::topological_space"
himmelma@33175
  1388
  assumes"a \<in> S" "open S"
huffman@45081
  1389
  shows "(f ---> l)(at a within S) \<longleftrightarrow> (f ---> l)(at a)"
huffman@45081
  1390
  using assms by (simp only: at_within_open)
himmelma@33175
  1391
hoelzl@44195
  1392
lemma Lim_within_LIMSEQ:
huffman@45448
  1393
  fixes a :: "'a::metric_space"
hoelzl@44195
  1394
  assumes "\<forall>S. (\<forall>n. S n \<noteq> a \<and> S n \<in> T) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L"
hoelzl@44195
  1395
  shows "(X ---> L) (at a within T)"
huffman@45448
  1396
  using assms unfolding tendsto_def [where l=L]
huffman@45448
  1397
  by (simp add: sequentially_imp_eventually_within)
hoelzl@44195
  1398
hoelzl@44195
  1399
lemma Lim_right_bound:
hoelzl@44195
  1400
  fixes f :: "real \<Rightarrow> real"
hoelzl@44195
  1401
  assumes mono: "\<And>a b. a \<in> I \<Longrightarrow> b \<in> I \<Longrightarrow> x < a \<Longrightarrow> a \<le> b \<Longrightarrow> f a \<le> f b"
hoelzl@44195
  1402
  assumes bnd: "\<And>a. a \<in> I \<Longrightarrow> x < a \<Longrightarrow> K \<le> f a"
hoelzl@44195
  1403
  shows "(f ---> Inf (f ` ({x<..} \<inter> I))) (at x within ({x<..} \<inter> I))"
hoelzl@44195
  1404
proof cases
hoelzl@44195
  1405
  assume "{x<..} \<inter> I = {}" then show ?thesis by (simp add: Lim_within_empty)
hoelzl@44195
  1406
next
hoelzl@44195
  1407
  assume [simp]: "{x<..} \<inter> I \<noteq> {}"
hoelzl@44195
  1408
  show ?thesis
hoelzl@44195
  1409
  proof (rule Lim_within_LIMSEQ, safe)
hoelzl@44195
  1410
    fix S assume S: "\<forall>n. S n \<noteq> x \<and> S n \<in> {x <..} \<inter> I" "S ----> x"
hoelzl@44195
  1411
    
hoelzl@44195
  1412
    show "(\<lambda>n. f (S n)) ----> Inf (f ` ({x<..} \<inter> I))"
hoelzl@44195
  1413
    proof (rule LIMSEQ_I, rule ccontr)
hoelzl@44195
  1414
      fix r :: real assume "0 < r"
hoelzl@44195
  1415
      with Inf_close[of "f ` ({x<..} \<inter> I)" r]
hoelzl@44195
  1416
      obtain y where y: "x < y" "y \<in> I" "f y < Inf (f ` ({x <..} \<inter> I)) + r" by auto
hoelzl@44195
  1417
      from `x < y` have "0 < y - x" by auto
hoelzl@44195
  1418
      from S(2)[THEN LIMSEQ_D, OF this]
hoelzl@44195
  1419
      obtain N where N: "\<And>n. N \<le> n \<Longrightarrow> \<bar>S n - x\<bar> < y - x" by auto
hoelzl@44195
  1420
      
hoelzl@44195
  1421
      assume "\<not> (\<exists>N. \<forall>n\<ge>N. norm (f (S n) - Inf (f ` ({x<..} \<inter> I))) < r)"
hoelzl@44195
  1422
      moreover have "\<And>n. Inf (f ` ({x<..} \<inter> I)) \<le> f (S n)"
hoelzl@44195
  1423
        using S bnd by (intro Inf_lower[where z=K]) auto
hoelzl@44195
  1424
      ultimately obtain n where n: "N \<le> n" "r + Inf (f ` ({x<..} \<inter> I)) \<le> f (S n)"
hoelzl@44195
  1425
        by (auto simp: not_less field_simps)
hoelzl@44195
  1426
      with N[OF n(1)] mono[OF _ `y \<in> I`, of "S n"] S(1)[THEN spec, of n] y
hoelzl@44195
  1427
      show False by auto
hoelzl@44195
  1428
    qed
hoelzl@44195
  1429
  qed
hoelzl@44195
  1430
qed
hoelzl@44195
  1431
himmelma@33175
  1432
text{* Another limit point characterization. *}
himmelma@33175
  1433
himmelma@33175
  1434
lemma islimpt_sequential:
hoelzl@51898
  1435
  fixes x :: "'a::first_countable_topology"
hoelzl@51898
  1436
  shows "x islimpt S \<longleftrightarrow> (\<exists>f. (\<forall>n::nat. f n \<in> S - {x}) \<and> (f ---> x) sequentially)"
himmelma@33175
  1437
    (is "?lhs = ?rhs")
himmelma@33175
  1438
proof
himmelma@33175
  1439
  assume ?lhs
hoelzl@51898
  1440
  from countable_basis_at_decseq[of x] guess A . note A = this
hoelzl@51898
  1441
  def f \<equiv> "\<lambda>n. SOME y. y \<in> S \<and> y \<in> A n \<and> x \<noteq> y"
hoelzl@51898
  1442
  { fix n
hoelzl@51898
  1443
    from `?lhs` have "\<exists>y. y \<in> S \<and> y \<in> A n \<and> x \<noteq> y"
hoelzl@51898
  1444
      unfolding islimpt_def using A(1,2)[of n] by auto
hoelzl@51898
  1445
    then have "f n \<in> S \<and> f n \<in> A n \<and> x \<noteq> f n"
hoelzl@51898
  1446
      unfolding f_def by (rule someI_ex)
hoelzl@51898
  1447
    then have "f n \<in> S" "f n \<in> A n" "x \<noteq> f n" by auto }
hoelzl@51898
  1448
  then have "\<forall>n. f n \<in> S - {x}" by auto
hoelzl@51898
  1449
  moreover have "(\<lambda>n. f n) ----> x"
hoelzl@51898
  1450
  proof (rule topological_tendstoI)
hoelzl@51898
  1451
    fix S assume "open S" "x \<in> S"
hoelzl@51898
  1452
    from A(3)[OF this] `\<And>n. f n \<in> A n`
hoelzl@51898
  1453
    show "eventually (\<lambda>x. f x \<in> S) sequentially" by (auto elim!: eventually_elim1)
huffman@45448
  1454
  qed
huffman@45448
  1455
  ultimately show ?rhs by fast
himmelma@33175
  1456
next
himmelma@33175
  1457
  assume ?rhs
hoelzl@51898
  1458
  then obtain f :: "nat \<Rightarrow> 'a" where f: "\<And>n. f n \<in> S - {x}" and lim: "f ----> x" by auto
hoelzl@51898
  1459
  show ?lhs
hoelzl@51898
  1460
    unfolding islimpt_def
hoelzl@51898
  1461
  proof safe
hoelzl@51898
  1462
    fix T assume "open T" "x \<in> T"
hoelzl@51898
  1463
    from lim[THEN topological_tendstoD, OF this] f
hoelzl@51898
  1464
    show "\<exists>y\<in>S. y \<in> T \<and> y \<noteq> x"
hoelzl@51898
  1465
      unfolding eventually_sequentially by auto
hoelzl@51898
  1466
  qed
himmelma@33175
  1467
qed
himmelma@33175
  1468
huffman@44983
  1469
lemma Lim_inv: (* TODO: delete *)
huffman@44952
  1470
  fixes f :: "'a \<Rightarrow> real" and A :: "'a filter"
huffman@44952
  1471
  assumes "(f ---> l) A" and "l \<noteq> 0"
huffman@44952
  1472
  shows "((inverse o f) ---> inverse l) A"
huffman@36433
  1473
  unfolding o_def using assms by (rule tendsto_inverse)
huffman@36433
  1474
himmelma@33175
  1475
lemma Lim_null:
himmelma@33175
  1476
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
huffman@44983
  1477
  shows "(f ---> l) net \<longleftrightarrow> ((\<lambda>x. f(x) - l) ---> 0) net"
himmelma@33175
  1478
  by (simp add: Lim dist_norm)
himmelma@33175
  1479
himmelma@33175
  1480
lemma Lim_null_comparison:
himmelma@33175
  1481
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
himmelma@33175
  1482
  assumes "eventually (\<lambda>x. norm (f x) \<le> g x) net" "(g ---> 0) net"
himmelma@33175
  1483
  shows "(f ---> 0) net"
huffman@45119
  1484
proof (rule metric_tendsto_imp_tendsto)
huffman@45119
  1485
  show "(g ---> 0) net" by fact
huffman@45119
  1486
  show "eventually (\<lambda>x. dist (f x) 0 \<le> dist (g x) 0) net"
huffman@45119
  1487
    using assms(1) by (rule eventually_elim1, simp add: dist_norm)
himmelma@33175
  1488
qed
himmelma@33175
  1489
himmelma@33175
  1490
lemma Lim_transform_bound:
himmelma@33175
  1491
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
himmelma@33175
  1492
  fixes g :: "'a \<Rightarrow> 'c::real_normed_vector"
himmelma@33175
  1493
  assumes "eventually (\<lambda>n. norm(f n) <= norm(g n)) net"  "(g ---> 0) net"
himmelma@33175
  1494
  shows "(f ---> 0) net"
huffman@45119
  1495
  using assms(1) tendsto_norm_zero [OF assms(2)]
huffman@45119
  1496
  by (rule Lim_null_comparison)
himmelma@33175
  1497
himmelma@33175
  1498
text{* Deducing things about the limit from the elements. *}
himmelma@33175
  1499
himmelma@33175
  1500
lemma Lim_in_closed_set:
himmelma@33175
  1501
  assumes "closed S" "eventually (\<lambda>x. f(x) \<in> S) net" "\<not>(trivial_limit net)" "(f ---> l) net"
himmelma@33175
  1502
  shows "l \<in> S"
himmelma@33175
  1503
proof (rule ccontr)
himmelma@33175
  1504
  assume "l \<notin> S"
himmelma@33175
  1505
  with `closed S` have "open (- S)" "l \<in> - S"
himmelma@33175
  1506
    by (simp_all add: open_Compl)
himmelma@33175
  1507
  with assms(4) have "eventually (\<lambda>x. f x \<in> - S) net"
himmelma@33175
  1508
    by (rule topological_tendstoD)
himmelma@33175
  1509
  with assms(2) have "eventually (\<lambda>x. False) net"
himmelma@33175
  1510
    by (rule eventually_elim2) simp
himmelma@33175
  1511
  with assms(3) show "False"
himmelma@33175
  1512
    by (simp add: eventually_False)
himmelma@33175
  1513
qed
himmelma@33175
  1514
himmelma@33175
  1515
text{* Need to prove closed(cball(x,e)) before deducing this as a corollary. *}
himmelma@33175
  1516
himmelma@33175
  1517
lemma Lim_dist_ubound:
himmelma@33175
  1518
  assumes "\<not>(trivial_limit net)" "(f ---> l) net" "eventually (\<lambda>x. dist a (f x) <= e) net"
himmelma@33175
  1519
  shows "dist a l <= e"
huffman@45119
  1520
proof-
huffman@45119
  1521
  have "dist a l \<in> {..e}"
huffman@45119
  1522
  proof (rule Lim_in_closed_set)
huffman@45119
  1523
    show "closed {..e}" by simp
huffman@45119
  1524
    show "eventually (\<lambda>x. dist a (f x) \<in> {..e}) net" by (simp add: assms)
huffman@45119
  1525
    show "\<not> trivial_limit net" by fact
huffman@45119
  1526
    show "((\<lambda>x. dist a (f x)) ---> dist a l) net" by (intro tendsto_intros assms)
huffman@45119
  1527
  qed
huffman@45119
  1528
  thus ?thesis by simp
himmelma@33175
  1529
qed
himmelma@33175
  1530
himmelma@33175
  1531
lemma Lim_norm_ubound:
himmelma@33175
  1532
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
himmelma@33175
  1533
  assumes "\<not>(trivial_limit net)" "(f ---> l) net" "eventually (\<lambda>x. norm(f x) <= e) net"
himmelma@33175
  1534
  shows "norm(l) <= e"
huffman@45119
  1535
proof-
huffman@45119
  1536
  have "norm l \<in> {..e}"
huffman@45119
  1537
  proof (rule Lim_in_closed_set)
huffman@45119
  1538
    show "closed {..e}" by simp
huffman@45119
  1539
    show "eventually (\<lambda>x. norm (f x) \<in> {..e}) net" by (simp add: assms)
huffman@45119
  1540
    show "\<not> trivial_limit net" by fact
huffman@45119
  1541
    show "((\<lambda>x. norm (f x)) ---> norm l) net" by (intro tendsto_intros assms)
huffman@45119
  1542
  qed
huffman@45119
  1543
  thus ?thesis by simp
himmelma@33175
  1544
qed
himmelma@33175
  1545
himmelma@33175
  1546
lemma Lim_norm_lbound:
himmelma@33175
  1547
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
himmelma@33175
  1548
  assumes "\<not> (trivial_limit net)"  "(f ---> l) net"  "eventually (\<lambda>x. e <= norm(f x)) net"
himmelma@33175
  1549
  shows "e \<le> norm l"
huffman@45119
  1550
proof-
huffman@45119
  1551
  have "norm l \<in> {e..}"
huffman@45119
  1552
  proof (rule Lim_in_closed_set)
huffman@45119
  1553
    show "closed {e..}" by simp
huffman@45119
  1554
    show "eventually (\<lambda>x. norm (f x) \<in> {e..}) net" by (simp add: assms)
huffman@45119
  1555
    show "\<not> trivial_limit net" by fact
huffman@45119
  1556
    show "((\<lambda>x. norm (f x)) ---> norm l) net" by (intro tendsto_intros assms)
huffman@45119
  1557
  qed
huffman@45119
  1558
  thus ?thesis by simp
himmelma@33175
  1559
qed
himmelma@33175
  1560
himmelma@33175
  1561
text{* Uniqueness of the limit, when nontrivial. *}
himmelma@33175
  1562
himmelma@33175
  1563
lemma tendsto_Lim:
himmelma@33175
  1564
  fixes f :: "'a \<Rightarrow> 'b::t2_space"
himmelma@33175
  1565
  shows "~(trivial_limit net) \<Longrightarrow> (f ---> l) net ==> Lim net f = l"
hoelzl@42841
  1566
  unfolding Lim_def using tendsto_unique[of net f] by auto
himmelma@33175
  1567
himmelma@33175
  1568
text{* Limit under bilinear function *}
himmelma@33175
  1569
himmelma@33175
  1570
lemma Lim_bilinear:
himmelma@33175
  1571
  assumes "(f ---> l) net" and "(g ---> m) net" and "bounded_bilinear h"
himmelma@33175
  1572
  shows "((\<lambda>x. h (f x) (g x)) ---> (h l m)) net"
himmelma@33175
  1573
using `bounded_bilinear h` `(f ---> l) net` `(g ---> m) net`
himmelma@33175
  1574
by (rule bounded_bilinear.tendsto)
himmelma@33175
  1575
himmelma@33175
  1576
text{* These are special for limits out of the same vector space. *}
himmelma@33175
  1577
himmelma@33175
  1578
lemma Lim_within_id: "(id ---> a) (at a within s)"
huffman@45896
  1579
  unfolding id_def by (rule tendsto_ident_at_within)
himmelma@33175
  1580
himmelma@33175
  1581
lemma Lim_at_id: "(id ---> a) (at a)"
huffman@45896
  1582
  unfolding id_def by (rule tendsto_ident_at)
himmelma@33175
  1583
himmelma@33175
  1584
lemma Lim_at_zero:
himmelma@33175
  1585
  fixes a :: "'a::real_normed_vector"
himmelma@33175
  1586
  fixes l :: "'b::topological_space"
himmelma@33175
  1587
  shows "(f ---> l) (at a) \<longleftrightarrow> ((\<lambda>x. f(a + x)) ---> l) (at 0)" (is "?lhs = ?rhs")
huffman@45119
  1588
  using LIM_offset_zero LIM_offset_zero_cancel ..
himmelma@33175
  1589
huffman@44952
  1590
text{* It's also sometimes useful to extract the limit point from the filter. *}
himmelma@33175
  1591
himmelma@33175
  1592
definition
huffman@44952
  1593
  netlimit :: "'a::t2_space filter \<Rightarrow> 'a" where
himmelma@33175
  1594
  "netlimit net = (SOME a. ((\<lambda>x. x) ---> a) net)"
himmelma@33175
  1595
himmelma@33175
  1596
lemma netlimit_within:
himmelma@33175
  1597
  assumes "\<not> trivial_limit (at a within S)"
himmelma@33175
  1598
  shows "netlimit (at a within S) = a"
himmelma@33175
  1599
unfolding netlimit_def
himmelma@33175
  1600
apply (rule some_equality)
himmelma@33175
  1601
apply (rule Lim_at_within)
huffman@45439
  1602
apply (rule tendsto_ident_at)
hoelzl@42841
  1603
apply (erule tendsto_unique [OF assms])
himmelma@33175
  1604
apply (rule Lim_at_within)
huffman@45439
  1605
apply (rule tendsto_ident_at)
himmelma@33175
  1606
done
himmelma@33175
  1607
himmelma@33175
  1608
lemma netlimit_at:
huffman@44943
  1609
  fixes a :: "'a::{perfect_space,t2_space}"
himmelma@33175
  1610
  shows "netlimit (at a) = a"
huffman@45896
  1611
  using netlimit_within [of a UNIV] by simp
himmelma@33175
  1612
huffman@45081
  1613
lemma lim_within_interior:
huffman@45081
  1614
  "x \<in> interior S \<Longrightarrow> (f ---> l) (at x within S) \<longleftrightarrow> (f ---> l) (at x)"
huffman@45081
  1615
  by (simp add: at_within_interior)
huffman@45081
  1616
huffman@45081
  1617
lemma netlimit_within_interior:
huffman@45081
  1618
  fixes x :: "'a::{t2_space,perfect_space}"
huffman@45081
  1619
  assumes "x \<in> interior S"
huffman@45081
  1620
  shows "netlimit (at x within S) = x"
huffman@45081
  1621
using assms by (simp add: at_within_interior netlimit_at)
huffman@45081
  1622
himmelma@33175
  1623
text{* Transformation of limit. *}
himmelma@33175
  1624
himmelma@33175
  1625
lemma Lim_transform:
himmelma@33175
  1626
  fixes f g :: "'a::type \<Rightarrow> 'b::real_normed_vector"
himmelma@33175
  1627
  assumes "((\<lambda>x. f x - g x) ---> 0) net" "(f ---> l) net"
himmelma@33175
  1628
  shows "(g ---> l) net"
huffman@45119
  1629
  using tendsto_diff [OF assms(2) assms(1)] by simp
himmelma@33175
  1630
himmelma@33175
  1631
lemma Lim_transform_eventually:
huffman@36667
  1632
  "eventually (\<lambda>x. f x = g x) net \<Longrightarrow> (f ---> l) net \<Longrightarrow> (g ---> l) net"
himmelma@33175
  1633
  apply (rule topological_tendstoI)
himmelma@33175
  1634
  apply (drule (2) topological_tendstoD)
himmelma@33175
  1635
  apply (erule (1) eventually_elim2, simp)
himmelma@33175
  1636
  done
himmelma@33175
  1637
himmelma@33175
  1638
lemma Lim_transform_within:
huffman@36667
  1639
  assumes "0 < d" and "\<forall>x'\<in>S. 0 < dist x' x \<and> dist x' x < d \<longrightarrow> f x' = g x'"
huffman@36667
  1640
  and "(f ---> l) (at x within S)"
huffman@36667
  1641
  shows "(g ---> l) (at x within S)"
huffman@36667
  1642
proof (rule Lim_transform_eventually)
huffman@36667
  1643
  show "eventually (\<lambda>x. f x = g x) (at x within S)"
huffman@36667
  1644
    unfolding eventually_within
huffman@36667
  1645
    using assms(1,2) by auto
huffman@36667
  1646
  show "(f ---> l) (at x within S)" by fact
huffman@36667
  1647
qed
himmelma@33175
  1648
himmelma@33175
  1649
lemma Lim_transform_at:
huffman@36667
  1650
  assumes "0 < d" and "\<forall>x'. 0 < dist x' x \<and> dist x' x < d \<longrightarrow> f x' = g x'"
huffman@36667
  1651
  and "(f ---> l) (at x)"
huffman@36667
  1652
  shows "(g ---> l) (at x)"
huffman@36667
  1653
proof (rule Lim_transform_eventually)
huffman@36667
  1654
  show "eventually (\<lambda>x. f x = g x) (at x)"
huffman@36667
  1655
    unfolding eventually_at
huffman@36667
  1656
    using assms(1,2) by auto
huffman@36667
  1657
  show "(f ---> l) (at x)" by fact
huffman@36667
  1658
qed
himmelma@33175
  1659
himmelma@33175
  1660
text{* Common case assuming being away from some crucial point like 0. *}
himmelma@33175
  1661
himmelma@33175
  1662
lemma Lim_transform_away_within:
huffman@36669
  1663
  fixes a b :: "'a::t1_space"
huffman@36667
  1664
  assumes "a \<noteq> b" and "\<forall>x\<in>S. x \<noteq> a \<and> x \<noteq> b \<longrightarrow> f x = g x"
himmelma@33175
  1665
  and "(f ---> l) (at a within S)"
himmelma@33175
  1666
  shows "(g ---> l) (at a within S)"
huffman@36669
  1667
proof (rule Lim_transform_eventually)
huffman@36669
  1668
  show "(f ---> l) (at a within S)" by fact
huffman@36669
  1669
  show "eventually (\<lambda>x. f x = g x) (at a within S)"
huffman@36669
  1670
    unfolding Limits.eventually_within eventually_at_topological
huffman@36669
  1671
    by (rule exI [where x="- {b}"], simp add: open_Compl assms)
himmelma@33175
  1672
qed
himmelma@33175
  1673
himmelma@33175
  1674
lemma Lim_transform_away_at:
huffman@36669
  1675
  fixes a b :: "'a::t1_space"
himmelma@33175
  1676
  assumes ab: "a\<noteq>b" and fg: "\<forall>x. x \<noteq> a \<and> x \<noteq> b \<longrightarrow> f x = g x"
himmelma@33175
  1677
  and fl: "(f ---> l) (at a)"
himmelma@33175
  1678
  shows "(g ---> l) (at a)"
himmelma@33175
  1679
  using Lim_transform_away_within[OF ab, of UNIV f g l] fg fl
huffman@45896
  1680
  by simp
himmelma@33175
  1681
himmelma@33175
  1682
text{* Alternatively, within an open set. *}
himmelma@33175
  1683
himmelma@33175
  1684
lemma Lim_transform_within_open:
huffman@36667
  1685
  assumes "open S" and "a \<in> S" and "\<forall>x\<in>S. x \<noteq> a \<longrightarrow> f x = g x"
huffman@36667
  1686
  and "(f ---> l) (at a)"
himmelma@33175
  1687
  shows "(g ---> l) (at a)"
huffman@36667
  1688
proof (rule Lim_transform_eventually)
huffman@36667
  1689
  show "eventually (\<lambda>x. f x = g x) (at a)"
huffman@36667
  1690
    unfolding eventually_at_topological
huffman@36667
  1691
    using assms(1,2,3) by auto
huffman@36667
  1692
  show "(f ---> l) (at a)" by fact
himmelma@33175
  1693
qed
himmelma@33175
  1694
himmelma@33175
  1695
text{* A congruence rule allowing us to transform limits assuming not at point. *}
himmelma@33175
  1696
himmelma@33175
  1697
(* FIXME: Only one congruence rule for tendsto can be used at a time! *)
himmelma@33175
  1698
huffman@36358
  1699
lemma Lim_cong_within(*[cong add]*):
hoelzl@44195
  1700
  assumes "a = b" "x = y" "S = T"
hoelzl@44195
  1701
  assumes "\<And>x. x \<noteq> b \<Longrightarrow> x \<in> T \<Longrightarrow> f x = g x"
hoelzl@44195
  1702
  shows "(f ---> x) (at a within S) \<longleftrightarrow> (g ---> y) (at b within T)"
huffman@36667
  1703
  unfolding tendsto_def Limits.eventually_within eventually_at_topological
huffman@36667
  1704
  using assms by simp
huffman@36667
  1705
huffman@36667
  1706
lemma Lim_cong_at(*[cong add]*):
hoelzl@44195
  1707
  assumes "a = b" "x = y"
huffman@36667
  1708
  assumes "\<And>x. x \<noteq> a \<Longrightarrow> f x = g x"
hoelzl@44195
  1709
  shows "((\<lambda>x. f x) ---> x) (at a) \<longleftrightarrow> ((g ---> y) (at a))"
huffman@36667
  1710
  unfolding tendsto_def eventually_at_topological
huffman@36667
  1711
  using assms by simp
himmelma@33175
  1712
himmelma@33175
  1713
text{* Useful lemmas on closure and set of possible sequential limits.*}
himmelma@33175
  1714
himmelma@33175
  1715
lemma closure_sequential:
hoelzl@51898
  1716
  fixes l :: "'a::first_countable_topology"
himmelma@33175
  1717
  shows "l \<in> closure S \<longleftrightarrow> (\<exists>x. (\<forall>n. x n \<in> S) \<and> (x ---> l) sequentially)" (is "?lhs = ?rhs")
himmelma@33175
  1718
proof
himmelma@33175
  1719
  assume "?lhs" moreover
himmelma@33175
  1720
  { assume "l \<in> S"
huffman@44983
  1721
    hence "?rhs" using tendsto_const[of l sequentially] by auto
himmelma@33175
  1722
  } moreover
himmelma@33175
  1723
  { assume "l islimpt S"
himmelma@33175
  1724
    hence "?rhs" unfolding islimpt_sequential by auto
himmelma@33175
  1725
  } ultimately
himmelma@33175
  1726
  show "?rhs" unfolding closure_def by auto
himmelma@33175
  1727
next
himmelma@33175
  1728
  assume "?rhs"
himmelma@33175
  1729
  thus "?lhs" unfolding closure_def unfolding islimpt_sequential by auto
himmelma@33175
  1730
qed
himmelma@33175
  1731
himmelma@33175
  1732
lemma closed_sequential_limits:
hoelzl@51898
  1733
  fixes S :: "'a::first_countable_topology set"
himmelma@33175
  1734
  shows "closed S \<longleftrightarrow> (\<forall>x l. (\<forall>n. x n \<in> S) \<and> (x ---> l) sequentially \<longrightarrow> l \<in> S)"
himmelma@33175
  1735
  unfolding closed_limpt
himmelma@33175
  1736
  using closure_sequential [where 'a='a] closure_closed [where 'a='a] closed_limpt [where 'a='a] islimpt_sequential [where 'a='a] mem_delete [where 'a='a]
himmelma@33175
  1737
  by metis
himmelma@33175
  1738
himmelma@33175
  1739
lemma closure_approachable:
himmelma@33175
  1740
  fixes S :: "'a::metric_space set"
himmelma@33175
  1741
  shows "x \<in> closure S \<longleftrightarrow> (\<forall>e>0. \<exists>y\<in>S. dist y x < e)"
himmelma@33175
  1742
  apply (auto simp add: closure_def islimpt_approachable)
himmelma@33175
  1743
  by (metis dist_self)
himmelma@33175
  1744
himmelma@33175
  1745
lemma closed_approachable:
himmelma@33175
  1746
  fixes S :: "'a::metric_space set"
himmelma@33175
  1747
  shows "closed S ==> (\<forall>e>0. \<exists>y\<in>S. dist y x < e) \<longleftrightarrow> x \<in> S"
himmelma@33175
  1748
  by (metis closure_closed closure_approachable)
himmelma@33175
  1749
immler@51102
  1750
subsection {* Infimum Distance *}
immler@51102
  1751
immler@51102
  1752
definition "infdist x A = (if A = {} then 0 else Inf {dist x a|a. a \<in> A})"
immler@51102
  1753
immler@51102
  1754
lemma infdist_notempty: "A \<noteq> {} \<Longrightarrow> infdist x A = Inf {dist x a|a. a \<in> A}"
immler@51102
  1755
  by (simp add: infdist_def)
immler@51102
  1756
immler@51102
  1757
lemma infdist_nonneg:
immler@51102
  1758
  shows "0 \<le> infdist x A"
immler@51102
  1759
  using assms by (auto simp add: infdist_def)
immler@51102
  1760
immler@51102
  1761
lemma infdist_le:
immler@51102
  1762
  assumes "a \<in> A"
immler@51102
  1763
  assumes "d = dist x a"
immler@51102
  1764
  shows "infdist x A \<le> d"
immler@51102
  1765
  using assms by (auto intro!: SupInf.Inf_lower[where z=0] simp add: infdist_def)
immler@51102
  1766
immler@51102
  1767
lemma infdist_zero[simp]:
immler@51102
  1768
  assumes "a \<in> A" shows "infdist a A = 0"
immler@51102
  1769
proof -
immler@51102
  1770
  from infdist_le[OF assms, of "dist a a"] have "infdist a A \<le> 0" by auto
immler@51102
  1771
  with infdist_nonneg[of a A] assms show "infdist a A = 0" by auto
immler@51102
  1772
qed
immler@51102
  1773
immler@51102
  1774
lemma infdist_triangle:
immler@51102
  1775
  shows "infdist x A \<le> infdist y A + dist x y"
immler@51102
  1776
proof cases
immler@51102
  1777
  assume "A = {}" thus ?thesis by (simp add: infdist_def)
immler@51102
  1778
next
immler@51102
  1779
  assume "A \<noteq> {}" then obtain a where "a \<in> A" by auto
immler@51102
  1780
  have "infdist x A \<le> Inf {dist x y + dist y a |a. a \<in> A}"
immler@51102
  1781
  proof
immler@51102
  1782
    from `A \<noteq> {}` show "{dist x y + dist y a |a. a \<in> A} \<noteq> {}" by simp
immler@51102
  1783
    fix d assume "d \<in> {dist x y + dist y a |a. a \<in> A}"
immler@51102
  1784
    then obtain a where d: "d = dist x y + dist y a" "a \<in> A" by auto
immler@51102
  1785
    show "infdist x A \<le> d"
immler@51102
  1786
      unfolding infdist_notempty[OF `A \<noteq> {}`]
immler@51102
  1787
    proof (rule Inf_lower2)
immler@51102
  1788
      show "dist x a \<in> {dist x a |a. a \<in> A}" using `a \<in> A` by auto
immler@51102
  1789
      show "dist x a \<le> d" unfolding d by (rule dist_triangle)
immler@51102
  1790
      fix d assume "d \<in> {dist x a |a. a \<in> A}"
immler@51102
  1791
      then obtain a where "a \<in> A" "d = dist x a" by auto
immler@51102
  1792
      thus "infdist x A \<le> d" by (rule infdist_le)
immler@51102
  1793
    qed
immler@51102
  1794
  qed
immler@51102
  1795
  also have "\<dots> = dist x y + infdist y A"
immler@51102
  1796
  proof (rule Inf_eq, safe)
immler@51102
  1797
    fix a assume "a \<in> A"
immler@51102
  1798
    thus "dist x y + infdist y A \<le> dist x y + dist y a" by (auto intro: infdist_le)
immler@51102
  1799
  next
immler@51102
  1800
    fix i assume inf: "\<And>d. d \<in> {dist x y + dist y a |a. a \<in> A} \<Longrightarrow> i \<le> d"
immler@51102
  1801
    hence "i - dist x y \<le> infdist y A" unfolding infdist_notempty[OF `A \<noteq> {}`] using `a \<in> A`
immler@51102
  1802
      by (intro Inf_greatest) (auto simp: field_simps)
immler@51102
  1803
    thus "i \<le> dist x y + infdist y A" by simp
immler@51102
  1804
  qed
immler@51102
  1805
  finally show ?thesis by simp
immler@51102
  1806
qed
immler@51102
  1807
immler@51102
  1808
lemma
immler@51102
  1809
  in_closure_iff_infdist_zero:
immler@51102
  1810
  assumes "A \<noteq> {}"
immler@51102
  1811
  shows "x \<in> closure A \<longleftrightarrow> infdist x A = 0"
immler@51102
  1812
proof
immler@51102
  1813
  assume "x \<in> closure A"
immler@51102
  1814
  show "infdist x A = 0"
immler@51102
  1815
  proof (rule ccontr)
immler@51102
  1816
    assume "infdist x A \<noteq> 0"
immler@51102
  1817
    with infdist_nonneg[of x A] have "infdist x A > 0" by auto
immler@51102
  1818
    hence "ball x (infdist x A) \<inter> closure A = {}" apply auto
immler@51102
  1819
      by (metis `0 < infdist x A` `x \<in> closure A` closure_approachable dist_commute
immler@51102
  1820
        eucl_less_not_refl euclidean_trans(2) infdist_le)
immler@51102
  1821
    hence "x \<notin> closure A" by (metis `0 < infdist x A` centre_in_ball disjoint_iff_not_equal)
immler@51102
  1822
    thus False using `x \<in> closure A` by simp
immler@51102
  1823
  qed
immler@51102
  1824
next
immler@51102
  1825
  assume x: "infdist x A = 0"
immler@51102
  1826
  then obtain a where "a \<in> A" by atomize_elim (metis all_not_in_conv assms)
immler@51102
  1827
  show "x \<in> closure A" unfolding closure_approachable
immler@51102
  1828
  proof (safe, rule ccontr)
immler@51102
  1829
    fix e::real assume "0 < e"
immler@51102
  1830
    assume "\<not> (\<exists>y\<in>A. dist y x < e)"
immler@51102
  1831
    hence "infdist x A \<ge> e" using `a \<in> A`
immler@51102
  1832
      unfolding infdist_def
hoelzl@51541
  1833
      by (force simp: dist_commute)
immler@51102
  1834
    with x `0 < e` show False by auto
immler@51102
  1835
  qed
immler@51102
  1836
qed
immler@51102
  1837
immler@51102
  1838
lemma
immler@51102
  1839
  in_closed_iff_infdist_zero:
immler@51102
  1840
  assumes "closed A" "A \<noteq> {}"
immler@51102
  1841
  shows "x \<in> A \<longleftrightarrow> infdist x A = 0"
immler@51102
  1842
proof -
immler@51102
  1843
  have "x \<in> closure A \<longleftrightarrow> infdist x A = 0"
immler@51102
  1844
    by (rule in_closure_iff_infdist_zero) fact
immler@51102
  1845
  with assms show ?thesis by simp
immler@51102
  1846
qed
immler@51102
  1847
immler@51102
  1848
lemma tendsto_infdist [tendsto_intros]:
immler@51102
  1849
  assumes f: "(f ---> l) F"
immler@51102
  1850
  shows "((\<lambda>x. infdist (f x) A) ---> infdist l A) F"
immler@51102
  1851
proof (rule tendstoI)
immler@51102
  1852
  fix e ::real assume "0 < e"
immler@51102
  1853
  from tendstoD[OF f this]
immler@51102
  1854
  show "eventually (\<lambda>x. dist (infdist (f x) A) (infdist l A) < e) F"
immler@51102
  1855
  proof (eventually_elim)
immler@51102
  1856
    fix x
immler@51102
  1857
    from infdist_triangle[of l A "f x"] infdist_triangle[of "f x" A l]
immler@51102
  1858
    have "dist (infdist (f x) A) (infdist l A) \<le> dist (f x) l"
immler@51102
  1859
      by (simp add: dist_commute dist_real_def)
immler@51102
  1860
    also assume "dist (f x) l < e"
immler@51102
  1861
    finally show "dist (infdist (f x) A) (infdist l A) < e" .
immler@51102
  1862
  qed
immler@51102
  1863
qed
immler@51102
  1864
himmelma@33175
  1865
text{* Some other lemmas about sequences. *}
himmelma@33175
  1866
huffman@36437
  1867
lemma sequentially_offset:
huffman@36437
  1868
  assumes "eventually (\<lambda>i. P i) sequentially"
huffman@36437
  1869
  shows "eventually (\<lambda>i. P (i + k)) sequentially"
huffman@36437
  1870
  using assms unfolding eventually_sequentially by (metis trans_le_add1)
huffman@36437
  1871
himmelma@33175
  1872
lemma seq_offset:
huffman@36437
  1873
  assumes "(f ---> l) sequentially"
huffman@36437
  1874
  shows "((\<lambda>i. f (i + k)) ---> l) sequentially"
huffman@45448
  1875
  using assms by (rule LIMSEQ_ignore_initial_segment) (* FIXME: redundant *)
himmelma@33175
  1876
himmelma@33175
  1877
lemma seq_offset_neg:
himmelma@33175
  1878
  "(f ---> l) sequentially ==> ((\<lambda>i. f(i - k)) ---> l) sequentially"
himmelma@33175
  1879
  apply (rule topological_tendstoI)
himmelma@33175
  1880
  apply (drule (2) topological_tendstoD)
himmelma@33175
  1881
  apply (simp only: eventually_sequentially)
himmelma@33175
  1882
  apply (subgoal_tac "\<And>N k (n::nat). N + k <= n ==> N <= n - k")
himmelma@33175
  1883
  apply metis
himmelma@33175
  1884
  by arith
himmelma@33175
  1885
himmelma@33175
  1886
lemma seq_offset_rev:
himmelma@33175
  1887
  "((\<lambda>i. f(i + k)) ---> l) sequentially ==> (f ---> l) sequentially"
huffman@45448
  1888
  by (rule LIMSEQ_offset) (* FIXME: redundant *)
himmelma@33175
  1889
himmelma@33175
  1890
lemma seq_harmonic: "((\<lambda>n. inverse (real n)) ---> 0) sequentially"
huffman@45448
  1891
  using LIMSEQ_inverse_real_of_nat by (rule LIMSEQ_imp_Suc)
himmelma@33175
  1892
huffman@45081
  1893
subsection {* More properties of closed balls *}
himmelma@33175
  1894
himmelma@33175
  1895
lemma closed_cball: "closed (cball x e)"
himmelma@33175
  1896
unfolding cball_def closed_def
himmelma@33175
  1897
unfolding Collect_neg_eq [symmetric] not_le
himmelma@33175
  1898
apply (clarsimp simp add: open_dist, rename_tac y)
himmelma@33175
  1899
apply (rule_tac x="dist x y - e" in exI, clarsimp)
himmelma@33175
  1900
apply (rename_tac x')
himmelma@33175
  1901
apply (cut_tac x=x and y=x' and z=y in dist_triangle)
himmelma@33175
  1902
apply simp
himmelma@33175
  1903
done
himmelma@33175
  1904
himmelma@33175
  1905
lemma open_contains_cball: "open S \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0.  cball x e \<subseteq> S)"
himmelma@33175
  1906
proof-
himmelma@33175
  1907
  { fix x and e::real assume "x\<in>S" "e>0" "ball x e \<subseteq> S"
himmelma@33175
  1908
    hence "\<exists>d>0. cball x d \<subseteq> S" unfolding subset_eq by (rule_tac x="e/2" in exI, auto)
himmelma@33175
  1909
  } moreover
himmelma@33175
  1910
  { fix x and e::real assume "x\<in>S" "e>0" "cball x e \<subseteq> S"
himmelma@33175
  1911
    hence "\<exists>d>0. ball x d \<subseteq> S" unfolding subset_eq apply(rule_tac x="e/2" in exI) by auto
himmelma@33175
  1912
  } ultimately
himmelma@33175
  1913
  show ?thesis unfolding open_contains_ball by auto
himmelma@33175
  1914
qed
himmelma@33175
  1915
himmelma@33175
  1916
lemma open_contains_cball_eq: "open S ==> (\<forall>x. x \<in> S \<longleftrightarrow> (\<exists>e>0. cball x e \<subseteq> S))"
huffman@45035
  1917
  by (metis open_contains_cball subset_eq order_less_imp_le centre_in_cball)
himmelma@33175
  1918
himmelma@33175
  1919
lemma mem_interior_cball: "x \<in> interior S \<longleftrightarrow> (\<exists>e>0. cball x e \<subseteq> S)"
himmelma@33175
  1920
  apply (simp add: interior_def, safe)
himmelma@33175
  1921
  apply (force simp add: open_contains_cball)
himmelma@33175
  1922
  apply (rule_tac x="ball x e" in exI)
huffman@36358
  1923
  apply (simp add: subset_trans [OF ball_subset_cball])
himmelma@33175
  1924
  done
himmelma@33175
  1925
himmelma@33175
  1926
lemma islimpt_ball:
himmelma@33175
  1927
  fixes x y :: "'a::{real_normed_vector,perfect_space}"
himmelma@33175
  1928
  shows "y islimpt ball x e \<longleftrightarrow> 0 < e \<and> y \<in> cball x e" (is "?lhs = ?rhs")
himmelma@33175
  1929
proof
himmelma@33175
  1930
  assume "?lhs"
himmelma@33175
  1931
  { assume "e \<le> 0"
himmelma@33175
  1932
    hence *:"ball x e = {}" using ball_eq_empty[of x e] by auto
himmelma@33175
  1933
    have False using `?lhs` unfolding * using islimpt_EMPTY[of y] by auto
himmelma@33175
  1934
  }
himmelma@33175
  1935
  hence "e > 0" by (metis not_less)
himmelma@33175
  1936
  moreover
himmelma@33175
  1937
  have "y \<in> cball x e" using closed_cball[of x e] islimpt_subset[of y "ball x e" "cball x e"] ball_subset_cball[of x e] `?lhs` unfolding closed_limpt by auto
himmelma@33175
  1938
  ultimately show "?rhs" by auto
himmelma@33175
  1939
next
himmelma@33175
  1940
  assume "?rhs" hence "e>0"  by auto
himmelma@33175
  1941
  { fix d::real assume "d>0"
himmelma@33175
  1942
    have "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
himmelma@33175
  1943
    proof(cases "d \<le> dist x y")
himmelma@33175
  1944
      case True thus "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
himmelma@33175
  1945
      proof(cases "x=y")
himmelma@33175
  1946
        case True hence False using `d \<le> dist x y` `d>0` by auto
himmelma@33175
  1947
        thus "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d" by auto
himmelma@33175
  1948
      next
himmelma@33175
  1949
        case False
himmelma@33175
  1950
himmelma@33175
  1951
        have "dist x (y - (d / (2 * dist y x)) *\<^sub>R (y - x))
himmelma@33175
  1952
              = norm (x - y + (d / (2 * norm (y - x))) *\<^sub>R (y - x))"
himmelma@33175
  1953
          unfolding mem_cball mem_ball dist_norm diff_diff_eq2 diff_add_eq[THEN sym] by auto
himmelma@33175
  1954
        also have "\<dots> = \<bar>- 1 + d / (2 * norm (x - y))\<bar> * norm (x - y)"
himmelma@33175
  1955
          using scaleR_left_distrib[of "- 1" "d / (2 * norm (y - x))", THEN sym, of "y - x"]
himmelma@33175
  1956
          unfolding scaleR_minus_left scaleR_one
himmelma@33175
  1957
          by (auto simp add: norm_minus_commute)
himmelma@33175
  1958
        also have "\<dots> = \<bar>- norm (x - y) + d / 2\<bar>"
himmelma@33175
  1959
          unfolding abs_mult_pos[of "norm (x - y)", OF norm_ge_zero[of "x - y"]]
webertj@50977
  1960
          unfolding distrib_right using `x\<noteq>y`[unfolded dist_nz, unfolded dist_norm] by auto
himmelma@33175
  1961
        also have "\<dots> \<le> e - d/2" using `d \<le> dist x y` and `d>0` and `?rhs` by(auto simp add: dist_norm)
himmelma@33175
  1962
        finally have "y - (d / (2 * dist y x)) *\<^sub>R (y - x) \<in> ball x e" using `d>0` by auto
himmelma@33175
  1963
himmelma@33175
  1964
        moreover
himmelma@33175
  1965
himmelma@33175
  1966
        have "(d / (2*dist y x)) *\<^sub>R (y - x) \<noteq> 0"
himmelma@33175
  1967
          using `x\<noteq>y`[unfolded dist_nz] `d>0` unfolding scaleR_eq_0_iff by (auto simp add: dist_commute)
himmelma@33175
  1968
        moreover
himmelma@33175
  1969
        have "dist (y - (d / (2 * dist y x)) *\<^sub>R (y - x)) y < d" unfolding dist_norm apply simp unfolding norm_minus_cancel
himmelma@33175
  1970
          using `d>0` `x\<noteq>y`[unfolded dist_nz] dist_commute[of x y]
himmelma@33175
  1971
          unfolding dist_norm by auto
himmelma@33175
  1972
        ultimately show "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d" by (rule_tac  x="y - (d / (2*dist y x)) *\<^sub>R (y - x)" in bexI) auto
himmelma@33175
  1973
      qed
himmelma@33175
  1974
    next
himmelma@33175
  1975
      case False hence "d > dist x y" by auto
himmelma@33175
  1976
      show "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
himmelma@33175
  1977
      proof(cases "x=y")
himmelma@33175
  1978
        case True
himmelma@33175
  1979
        obtain z where **: "z \<noteq> y" "dist z y < min e d"
himmelma@33175
  1980
          using perfect_choose_dist[of "min e d" y]
himmelma@33175
  1981
          using `d > 0` `e>0` by auto
himmelma@33175
  1982
        show "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
himmelma@33175
  1983
          unfolding `x = y`
himmelma@33175
  1984
          using `z \<noteq> y` **
himmelma@33175
  1985
          by (rule_tac x=z in bexI, auto simp add: dist_commute)
himmelma@33175
  1986
      next
himmelma@33175
  1987
        case False thus "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
himmelma@33175
  1988
          using `d>0` `d > dist x y` `?rhs` by(rule_tac x=x in bexI, auto)
himmelma@33175
  1989
      qed
himmelma@33175
  1990
    qed  }
himmelma@33175
  1991
  thus "?lhs" unfolding mem_cball islimpt_approachable mem_ball by auto
himmelma@33175
  1992
qed
himmelma@33175
  1993
himmelma@33175
  1994
lemma closure_ball_lemma:
himmelma@33175
  1995
  fixes x y :: "'a::real_normed_vector"
himmelma@33175
  1996
  assumes "x \<noteq> y" shows "y islimpt ball x (dist x y)"
himmelma@33175
  1997
proof (rule islimptI)
himmelma@33175
  1998
  fix T assume "y \<in> T" "open T"
himmelma@33175
  1999
  then obtain r where "0 < r" "\<forall>z. dist z y < r \<longrightarrow> z \<in> T"
himmelma@33175
  2000
    unfolding open_dist by fast
himmelma@33175
  2001
  (* choose point between x and y, within distance r of y. *)
himmelma@33175
  2002
  def k \<equiv> "min 1 (r / (2 * dist x y))"
himmelma@33175
  2003
  def z \<equiv> "y + scaleR k (x - y)"
himmelma@33175
  2004
  have z_def2: "z = x + scaleR (1 - k) (y - x)"
himmelma@33175
  2005
    unfolding z_def by (simp add: algebra_simps)
himmelma@33175
  2006
  have "dist z y < r"
himmelma@33175
  2007
    unfolding z_def k_def using `0 < r`
himmelma@33175
  2008
    by (simp add: dist_norm min_def)
himmelma@33175
  2009
  hence "z \<in> T" using `\<forall>z. dist z y < r \<longrightarrow> z \<in> T` by simp
himmelma@33175
  2010
  have "dist x z < dist x y"
himmelma@33175
  2011
    unfolding z_def2 dist_norm
himmelma@33175
  2012
    apply (simp add: norm_minus_commute)
himmelma@33175
  2013
    apply (simp only: dist_norm [symmetric])
himmelma@33175
  2014
    apply (subgoal_tac "\<bar>1 - k\<bar> * dist x y < 1 * dist x y", simp)
himmelma@33175
  2015
    apply (rule mult_strict_right_mono)
himmelma@33175
  2016
    apply (simp add: k_def divide_pos_pos zero_less_dist_iff `0 < r` `x \<noteq> y`)
himmelma@33175
  2017
    apply (simp add: zero_less_dist_iff `x \<noteq> y`)
himmelma@33175
  2018
    done
himmelma@33175
  2019
  hence "z \<in> ball x (dist x y)" by simp
himmelma@33175
  2020
  have "z \<noteq> y"
himmelma@33175
  2021
    unfolding z_def k_def using `x \<noteq> y` `0 < r`
himmelma@33175
  2022
    by (simp add: min_def)
himmelma@33175
  2023
  show "\<exists>z\<in>ball x (dist x y). z \<in> T \<and> z \<noteq> y"
himmelma@33175
  2024
    using `z \<in> ball x (dist x y)` `z \<in> T` `z \<noteq> y`
himmelma@33175
  2025
    by fast
himmelma@33175
  2026
qed
himmelma@33175
  2027
himmelma@33175
  2028
lemma closure_ball:
himmelma@33175
  2029
  fixes x :: "'a::real_normed_vector"
himmelma@33175
  2030
  shows "0 < e \<Longrightarrow> closure (ball x e) = cball x e"
himmelma@33175
  2031
apply (rule equalityI)
himmelma@33175
  2032
apply (rule closure_minimal)
himmelma@33175
  2033
apply (rule ball_subset_cball)
himmelma@33175
  2034
apply (rule closed_cball)
himmelma@33175
  2035
apply (rule subsetI, rename_tac y)
himmelma@33175
  2036
apply (simp add: le_less [where 'a=real])
himmelma@33175
  2037
apply (erule disjE)
himmelma@33175
  2038
apply (rule subsetD [OF closure_subset], simp)
himmelma@33175
  2039
apply (simp add: closure_def)
himmelma@33175
  2040
apply clarify
himmelma@33175
  2041
apply (rule closure_ball_lemma)
himmelma@33175
  2042
apply (simp add: zero_less_dist_iff)
himmelma@33175
  2043
done
himmelma@33175
  2044
himmelma@33175
  2045
(* In a trivial vector space, this fails for e = 0. *)
himmelma@33175
  2046
lemma interior_cball:
himmelma@33175
  2047
  fixes x :: "'a::{real_normed_vector, perfect_space}"
himmelma@33175
  2048
  shows "interior (cball x e) = ball x e"
himmelma@33175
  2049
proof(cases "e\<ge>0")
himmelma@33175
  2050
  case False note cs = this
himmelma@33175
  2051
  from cs have "ball x e = {}" using ball_empty[of e x] by auto moreover
himmelma@33175
  2052
  { fix y assume "y \<in> cball x e"
himmelma@33175
  2053
    hence False unfolding mem_cball using dist_nz[of x y] cs by auto  }
himmelma@33175
  2054
  hence "cball x e = {}" by auto
himmelma@33175
  2055
  hence "interior (cball x e) = {}" using interior_empty by auto
himmelma@33175
  2056
  ultimately show ?thesis by blast
himmelma@33175
  2057
next
himmelma@33175
  2058
  case True note cs = this
himmelma@33175
  2059
  have "ball x e \<subseteq> cball x e" using ball_subset_cball by auto moreover
himmelma@33175
  2060
  { fix S y assume as: "S \<subseteq> cball x e" "open S" "y\<in>S"
himmelma@33175
  2061
    then obtain d where "d>0" and d:"\<forall>x'. dist x' y < d \<longrightarrow> x' \<in> S" unfolding open_dist by blast
himmelma@33175
  2062
himmelma@33175
  2063
    then obtain xa where xa_y: "xa \<noteq> y" and xa: "dist xa y < d"
himmelma@33175
  2064
      using perfect_choose_dist [of d] by auto
himmelma@33175
  2065
    have "xa\<in>S" using d[THEN spec[where x=xa]] using xa by(auto simp add: dist_commute)
himmelma@33175
  2066
    hence xa_cball:"xa \<in> cball x e" using as(1) by auto
himmelma@33175
  2067
himmelma@33175
  2068
    hence "y \<in> ball x e" proof(cases "x = y")
himmelma@33175
  2069
      case True
himmelma@33175
  2070
      hence "e>0" using xa_y[unfolded dist_nz] xa_cball[unfolded mem_cball] by (auto simp add: dist_commute)
himmelma@33175
  2071
      thus "y \<in> ball x e" using `x = y ` by simp
himmelma@33175
  2072
    next
himmelma@33175
  2073
      case False
himmelma@33175
  2074
      have "dist (y + (d / 2 / dist y x) *\<^sub>R (y - x)) y < d" unfolding dist_norm
himmelma@33175
  2075
        using `d>0` norm_ge_zero[of "y - x"] `x \<noteq> y` by auto
himmelma@33175
  2076
      hence *:"y + (d / 2 / dist y x) *\<^sub>R (y - x) \<in> cball x e" using d as(1)[unfolded subset_eq] by blast
himmelma@33175
  2077
      have "y - x \<noteq> 0" using `x \<noteq> y` by auto
himmelma@33175
  2078
      hence **:"d / (2 * norm (y - x)) > 0" unfolding zero_less_norm_iff[THEN sym]
himmelma@33175
  2079
        using `d>0` divide_pos_pos[of d "2*norm (y - x)"] by auto
himmelma@33175
  2080
himmelma@33175
  2081
      have "dist (y + (d / 2 / dist y x) *\<^sub>R (y - x)) x = norm (y + (d / (2 * norm (y - x))) *\<^sub>R y - (d / (2 * norm (y - x))) *\<^sub>R x - x)"
himmelma@33175
  2082
        by (auto simp add: dist_norm algebra_simps)
himmelma@33175
  2083
      also have "\<dots> = norm ((1 + d / (2 * norm (y - x))) *\<^sub>R (y - x))"
himmelma@33175
  2084
        by (auto simp add: algebra_simps)
himmelma@33175
  2085
      also have "\<dots> = \<bar>1 + d / (2 * norm (y - x))\<bar> * norm (y - x)"
himmelma@33175
  2086
        using ** by auto
webertj@50977
  2087
      also have "\<dots> = (dist y x) + d/2"using ** by (auto simp add: distrib_right dist_norm)
himmelma@33175
  2088
      finally have "e \<ge> dist x y +d/2" using *[unfolded mem_cball] by (auto simp add: dist_commute)
himmelma@33175
  2089
      thus "y \<in> ball x e" unfolding mem_ball using `d>0` by auto
himmelma@33175
  2090
    qed  }
himmelma@33175
  2091
  hence "\<forall>S \<subseteq> cball x e. open S \<longrightarrow> S \<subseteq> ball x e" by auto
himmelma@33175
  2092
  ultimately show ?thesis using interior_unique[of "ball x e" "cball x e"] using open_ball[of x e] by auto
himmelma@33175
  2093
qed
himmelma@33175
  2094
himmelma@33175
  2095
lemma frontier_ball:
himmelma@33175
  2096
  fixes a :: "'a::real_normed_vector"
himmelma@33175
  2097
  shows "0 < e ==> frontier(ball a e) = {x. dist a x = e}"
huffman@36358
  2098
  apply (simp add: frontier_def closure_ball interior_open order_less_imp_le)
nipkow@39535
  2099
  apply (simp add: set_eq_iff)
himmelma@33175
  2100
  by arith
himmelma@33175
  2101
himmelma@33175
  2102
lemma frontier_cball:
himmelma@33175
  2103
  fixes a :: "'a::{real_normed_vector, perfect_space}"
himmelma@33175
  2104
  shows "frontier(cball a e) = {x. dist a x = e}"
huffman@36358
  2105
  apply (simp add: frontier_def interior_cball closed_cball order_less_imp_le)
nipkow@39535
  2106
  apply (simp add: set_eq_iff)
himmelma@33175
  2107
  by arith
himmelma@33175
  2108
himmelma@33175
  2109
lemma cball_eq_empty: "(cball x e = {}) \<longleftrightarrow> e < 0"
nipkow@39535
  2110
  apply (simp add: set_eq_iff not_le)
himmelma@33175
  2111
  by (metis zero_le_dist dist_self order_less_le_trans)
himmelma@33175
  2112
lemma cball_empty: "e < 0 ==> cball x e = {}" by (simp add: cball_eq_empty)
himmelma@33175
  2113
himmelma@33175
  2114
lemma cball_eq_sing:
huffman@44943
  2115
  fixes x :: "'a::{metric_space,perfect_space}"
himmelma@33175
  2116
  shows "(cball x e = {x}) \<longleftrightarrow> e = 0"
himmelma@33175
  2117
proof (rule linorder_cases)
himmelma@33175
  2118
  assume e: "0 < e"
himmelma@33175
  2119
  obtain a where "a \<noteq> x" "dist a x < e"
himmelma@33175
  2120
    using perfect_choose_dist [OF e] by auto
himmelma@33175
  2121
  hence "a \<noteq> x" "dist x a \<le> e" by (auto simp add: dist_commute)
nipkow@39535
  2122
  with e show ?thesis by (auto simp add: set_eq_iff)
himmelma@33175
  2123
qed auto
himmelma@33175
  2124
himmelma@33175
  2125
lemma cball_sing:
himmelma@33175
  2126
  fixes x :: "'a::metric_space"
himmelma@33175
  2127
  shows "e = 0 ==> cball x e = {x}"
nipkow@39535
  2128
  by (auto simp add: set_eq_iff)
himmelma@33175
  2129
huffman@45081
  2130
huffman@45081
  2131
subsection {* Boundedness *}
himmelma@33175
  2132
himmelma@33175
  2133
  (* FIXME: This has to be unified with BSEQ!! *)
huffman@45078
  2134
definition (in metric_space)
huffman@45078
  2135
  bounded :: "'a set \<Rightarrow> bool" where
himmelma@33175
  2136
  "bounded S \<longleftrightarrow> (\<exists>x e. \<forall>y\<in>S. dist x y \<le> e)"
himmelma@33175
  2137
himmelma@33175
  2138
lemma bounded_any_center: "bounded S \<longleftrightarrow> (\<exists>e. \<forall>y\<in>S. dist a y \<le> e)"
himmelma@33175
  2139
unfolding bounded_def
himmelma@33175
  2140
apply safe
himmelma@33175
  2141
apply (rule_tac x="dist a x + e" in exI, clarify)
himmelma@33175
  2142
apply (drule (1) bspec)
himmelma@33175
  2143
apply (erule order_trans [OF dist_triangle add_left_mono])
himmelma@33175
  2144
apply auto
himmelma@33175
  2145
done
himmelma@33175
  2146
himmelma@33175
  2147
lemma bounded_iff: "bounded S \<longleftrightarrow> (\<exists>a. \<forall>x\<in>S. norm x \<le> a)"
himmelma@33175
  2148
unfolding bounded_any_center [where a=0]
himmelma@33175
  2149
by (simp add: dist_norm)
himmelma@33175
  2150
hoelzl@51119
  2151
lemma bounded_realI: assumes "\<forall>x\<in>s. abs (x::real) \<le> B" shows "bounded s"
hoelzl@51119
  2152
  unfolding bounded_def dist_real_def apply(rule_tac x=0 in exI)
hoelzl@51119
  2153
  using assms by auto
hoelzl@51119
  2154
huffman@51963
  2155
lemma bounded_empty [simp]: "bounded {}"
huffman@51963
  2156
  by (simp add: bounded_def)
huffman@51963
  2157
himmelma@33175
  2158
lemma bounded_subset: "bounded T \<Longrightarrow> S \<subseteq> T ==> bounded S"
himmelma@33175
  2159
  by (metis bounded_def subset_eq)
himmelma@33175
  2160
himmelma@33175
  2161
lemma bounded_interior[intro]: "bounded S ==> bounded(interior S)"
himmelma@33175
  2162
  by (metis bounded_subset interior_subset)
himmelma@33175
  2163
himmelma@33175
  2164
lemma bounded_closure[intro]: assumes "bounded S" shows "bounded(closure S)"
himmelma@33175
  2165
proof-
himmelma@33175
  2166
  from assms obtain x and a where a: "\<forall>y\<in>S. dist x y \<le> a" unfolding bounded_def by auto
himmelma@33175
  2167
  { fix y assume "y \<in> closure S"
himmelma@33175
  2168
    then obtain f where f: "\<forall>n. f n \<in> S"  "(f ---> y) sequentially"
himmelma@33175
  2169
      unfolding closure_sequential by auto
himmelma@33175
  2170
    have "\<forall>n. f n \<in> S \<longrightarrow> dist x (f n) \<le> a" using a by simp
himmelma@33175
  2171
    hence "eventually (\<lambda>n. dist x (f n) \<le> a) sequentially"
himmelma@33175
  2172
      by (rule eventually_mono, simp add: f(1))
himmelma@33175
  2173
    have "dist x y \<le> a"
himmelma@33175
  2174
      apply (rule Lim_dist_ubound [of sequentially f])
himmelma@33175
  2175
      apply (rule trivial_limit_sequentially)
himmelma@33175
  2176
      apply (rule f(2))
himmelma@33175
  2177
      apply fact
himmelma@33175
  2178
      done
himmelma@33175
  2179
  }
himmelma@33175
  2180
  thus ?thesis unfolding bounded_def by auto
himmelma@33175
  2181
qed
himmelma@33175
  2182
himmelma@33175
  2183
lemma bounded_cball[simp,intro]: "bounded (cball x e)"
himmelma@33175
  2184
  apply (simp add: bounded_def)
himmelma@33175
  2185
  apply (rule_tac x=x in exI)
himmelma@33175
  2186
  apply (rule_tac x=e in exI)
himmelma@33175
  2187
  apply auto
himmelma@33175
  2188
  done
himmelma@33175
  2189
himmelma@33175
  2190
lemma bounded_ball[simp,intro]: "bounded(ball x e)"
himmelma@33175
  2191
  by (metis ball_subset_cball bounded_cball bounded_subset)
himmelma@33175
  2192
himmelma@33175
  2193
lemma bounded_Un[simp]: "bounded (S \<union> T) \<longleftrightarrow> bounded S \<and> bounded T"
himmelma@33175
  2194
  apply (auto simp add: bounded_def)
himmelma@33175
  2195
  apply (rename_tac x y r s)
himmelma@33175
  2196
  apply (rule_tac x=x in exI)
himmelma@33175
  2197
  apply (rule_tac x="max r (dist x y + s)" in exI)
himmelma@33175
  2198
  apply (rule ballI, rename_tac z, safe)
himmelma@33175
  2199
  apply (drule (1) bspec, simp)
himmelma@33175
  2200
  apply (drule (1) bspec)
himmelma@33175
  2201
  apply (rule min_max.le_supI2)
himmelma@33175
  2202
  apply (erule order_trans [OF dist_triangle add_left_mono])
himmelma@33175
  2203
  done
himmelma@33175
  2204
himmelma@33175
  2205
lemma bounded_Union[intro]: "finite F \<Longrightarrow> (\<forall>S\<in>F. bounded S) \<Longrightarrow> bounded(\<Union>F)"
himmelma@33175
  2206
  by (induct rule: finite_induct[of F], auto)
himmelma@33175
  2207
huffman@51963
  2208
lemma bounded_insert [simp]: "bounded (insert x S) \<longleftrightarrow> bounded S"
huffman@51963
  2209
proof -
huffman@51963
  2210
  have "\<forall>y\<in>{x}. dist x y \<le> 0" by simp
huffman@51963
  2211
  hence "bounded {x}" unfolding bounded_def by fast
huffman@51963
  2212
  thus ?thesis by (metis insert_is_Un bounded_Un)
huffman@51963
  2213
qed
huffman@51963
  2214
huffman@51963
  2215
lemma finite_imp_bounded [intro]: "finite S \<Longrightarrow> bounded S"
huffman@51963
  2216
  by (induct set: finite, simp_all)
huffman@51963
  2217
himmelma@33175
  2218
lemma bounded_pos: "bounded S \<longleftrightarrow> (\<exists>b>0. \<forall>x\<in> S. norm x <= b)"
himmelma@33175
  2219
  apply (simp add: bounded_iff)
himmelma@33175
  2220
  apply (subgoal_tac "\<And>x (y::real). 0 < 1 + abs y \<and> (x <= y \<longrightarrow> x <= 1 + abs y)")
himmelma@33175
  2221
  by metis arith
himmelma@33175
  2222
himmelma@33175
  2223
lemma bounded_Int[intro]: "bounded S \<or> bounded T \<Longrightarrow> bounded (S \<inter> T)"
himmelma@33175
  2224
  by (metis Int_lower1 Int_lower2 bounded_subset)
himmelma@33175
  2225
himmelma@33175
  2226
lemma bounded_diff[intro]: "bounded S ==> bounded (S - T)"
himmelma@33175
  2227
apply (metis Diff_subset bounded_subset)
himmelma@33175
  2228
done
himmelma@33175
  2229
himmelma@33175
  2230
lemma not_bounded_UNIV[simp, intro]:
himmelma@33175
  2231
  "\<not> bounded (UNIV :: 'a::{real_normed_vector, perfect_space} set)"
himmelma@33175
  2232
proof(auto simp add: bounded_pos not_le)
himmelma@33175
  2233
  obtain x :: 'a where "x \<noteq> 0"
himmelma@33175
  2234
    using perfect_choose_dist [OF zero_less_one] by fast
himmelma@33175
  2235
  fix b::real  assume b: "b >0"
himmelma@33175
  2236
  have b1: "b +1 \<ge> 0" using b by simp
himmelma@33175
  2237
  with `x \<noteq> 0` have "b < norm (scaleR (b + 1) (sgn x))"
himmelma@33175
  2238
    by (simp add: norm_sgn)
himmelma@33175
  2239
  then show "\<exists>x::'a. b < norm x" ..
himmelma@33175
  2240
qed
himmelma@33175
  2241
himmelma@33175
  2242
lemma bounded_linear_image:
himmelma@33175
  2243
  assumes "bounded S" "bounded_linear f"
himmelma@33175
  2244
  shows "bounded(f ` S)"
himmelma@33175
  2245
proof-
himmelma@33175
  2246
  from assms(1) obtain b where b:"b>0" "\<forall>x\<in>S. norm x \<le> b" unfolding bounded_pos by auto
himmelma@33175
  2247
  from assms(2) obtain B where B:"B>0" "\<forall>x. norm (f x) \<le> B * norm x" using bounded_linear.pos_bounded by (auto simp add: mult_ac)
himmelma@33175
  2248
  { fix x assume "x\<in>S"
himmelma@33175
  2249
    hence "norm x \<le> b" using b by auto
himmelma@33175
  2250
    hence "norm (f x) \<le> B * b" using B(2) apply(erule_tac x=x in allE)
huffman@36770
  2251
      by (metis B(1) B(2) order_trans mult_le_cancel_left_pos)
himmelma@33175
  2252
  }
himmelma@33175
  2253
  thus ?thesis unfolding bounded_pos apply(rule_tac x="b*B" in exI)
huffman@36770
  2254
    using b B mult_pos_pos [of b B] by (auto simp add: mult_commute)
himmelma@33175
  2255
qed
himmelma@33175
  2256
himmelma@33175
  2257
lemma bounded_scaling:
himmelma@33175
  2258
  fixes S :: "'a::real_normed_vector set"
himmelma@33175
  2259
  shows "bounded S \<Longrightarrow> bounded ((\<lambda>x. c *\<^sub>R x) ` S)"
himmelma@33175
  2260
  apply (rule bounded_linear_image, assumption)
huffman@45145
  2261
  apply (rule bounded_linear_scaleR_right)
himmelma@33175
  2262
  done
himmelma@33175
  2263
himmelma@33175
  2264
lemma bounded_translation:
himmelma@33175
  2265
  fixes S :: "'a::real_normed_vector set"
himmelma@33175
  2266
  assumes "bounded S" shows "bounded ((\<lambda>x. a + x) ` S)"
himmelma@33175
  2267
proof-
himmelma@33175
  2268
  from assms obtain b where b:"b>0" "\<forall>x\<in>S. norm x \<le> b" unfolding bounded_pos by auto
himmelma@33175
  2269
  { fix x assume "x\<in>S"
himmelma@33175
  2270
    hence "norm (a + x) \<le> b + norm a" using norm_triangle_ineq[of a x] b by auto
himmelma@33175
  2271
  }
himmelma@33175
  2272
  thus ?thesis unfolding bounded_pos using norm_ge_zero[of a] b(1) using add_strict_increasing[of b 0 "norm a"]
huffman@49063
  2273
    by (auto intro!: exI[of _ "b + norm a"])
himmelma@33175
  2274
qed
himmelma@33175
  2275
himmelma@33175
  2276
himmelma@33175
  2277
text{* Some theorems on sups and infs using the notion "bounded". *}
himmelma@33175
  2278
himmelma@33175
  2279
lemma bounded_real:
himmelma@33175
  2280
  fixes S :: "real set"
himmelma@33175
  2281
  shows "bounded S \<longleftrightarrow>  (\<exists>a. \<forall>x\<in>S. abs x <= a)"
himmelma@33175
  2282
  by (simp add: bounded_iff)
himmelma@33175
  2283
paulson@33270
  2284
lemma bounded_has_Sup:
paulson@33270
  2285
  fixes S :: "real set"
paulson@33270
  2286
  assumes "bounded S" "S \<noteq> {}"
paulson@33270
  2287
  shows "\<forall>x\<in>S. x <= Sup S" and "\<forall>b. (\<forall>x\<in>S. x <= b) \<longrightarrow> Sup S <= b"
paulson@33270
  2288
proof
paulson@33270
  2289
  fix x assume "x\<in>S"
paulson@33270
  2290
  thus "x \<le> Sup S"
paulson@33270
  2291
    by (metis SupInf.Sup_upper abs_le_D1 assms(1) bounded_real)
paulson@33270
  2292
next
paulson@33270
  2293
  show "\<forall>b. (\<forall>x\<in>S. x \<le> b) \<longrightarrow> Sup S \<le> b" using assms
paulson@33270
  2294
    by (metis SupInf.Sup_least)
paulson@33270
  2295
qed
paulson@33270
  2296
paulson@33270
  2297
lemma Sup_insert:
paulson@33270
  2298
  fixes S :: "real set"
paulson@33270
  2299
  shows "bounded S ==> Sup(insert x S) = (if S = {} then x else max x (Sup S))" 
paulson@33270
  2300
by auto (metis Int_absorb Sup_insert_nonempty assms bounded_has_Sup(1) disjoint_iff_not_equal) 
paulson@33270
  2301
paulson@33270
  2302
lemma Sup_insert_finite:
paulson@33270
  2303
  fixes S :: "real set"
paulson@33270
  2304
  shows "finite S \<Longrightarrow> Sup(insert x S) = (if S = {} then x else max x (Sup S))"
paulson@33270
  2305
  apply (rule Sup_insert)
paulson@33270
  2306
  apply (rule finite_imp_bounded)
paulson@33270
  2307
  by simp
paulson@33270
  2308
paulson@33270
  2309
lemma bounded_has_Inf:
paulson@33270
  2310
  fixes S :: "real set"
paulson@33270
  2311
  assumes "bounded S"  "S \<noteq> {}"
paulson@33270
  2312
  shows "\<forall>x\<in>S. x >= Inf S" and "\<forall>b. (\<forall>x\<in>S. x >= b) \<longrightarrow> Inf S >= b"
himmelma@33175
  2313
proof
himmelma@33175
  2314
  fix x assume "x\<in>S"
himmelma@33175
  2315
  from assms(1) obtain a where a:"\<forall>x\<in>S. \<bar>x\<bar> \<le> a" unfolding bounded_real by auto
paulson@33270
  2316
  thus "x \<ge> Inf S" using `x\<in>S`
paulson@33270
  2317
    by (metis Inf_lower_EX abs_le_D2 minus_le_iff)
himmelma@33175
  2318
next
paulson@33270
  2319
  show "\<forall>b. (\<forall>x\<in>S. x >= b) \<longrightarrow> Inf S \<ge> b" using assms
paulson@33270
  2320
    by (metis SupInf.Inf_greatest)
paulson@33270
  2321
qed
paulson@33270
  2322
paulson@33270
  2323
lemma Inf_insert:
paulson@33270
  2324
  fixes S :: "real set"
paulson@33270
  2325
  shows "bounded S ==> Inf(insert x S) = (if S = {} then x else min x (Inf S))" 
hoelzl@51959
  2326
by auto (metis Int_absorb Inf_insert_nonempty bounded_has_Inf(1) disjoint_iff_not_equal)
hoelzl@51959
  2327
paulson@33270
  2328
lemma Inf_insert_finite:
paulson@33270
  2329
  fixes S :: "real set"
paulson@33270
  2330
  shows "finite S ==> Inf(insert x S) = (if S = {} then x else min x (Inf S))"
paulson@33270
  2331
  by (rule Inf_insert, rule finite_imp_bounded, simp)
paulson@33270
  2332
hoelzl@51899
  2333
subsection {* Compactness *}
hoelzl@51899
  2334
hoelzl@51899
  2335
subsubsection{* Open-cover compactness *}
hoelzl@51899
  2336
hoelzl@51899
  2337
definition compact :: "'a::topological_space set \<Rightarrow> bool" where
hoelzl@51899
  2338
  compact_eq_heine_borel: -- "This name is used for backwards compatibility"
hoelzl@51899
  2339
    "compact S \<longleftrightarrow> (\<forall>C. (\<forall>c\<in>C. open c) \<and> S \<subseteq> \<Union>C \<longrightarrow> (\<exists>D\<subseteq>C. finite D \<and> S \<subseteq> \<Union>D))"
hoelzl@51899
  2340
huffman@51913
  2341
lemma compactI:
huffman@51913
  2342
  assumes "\<And>C. \<forall>t\<in>C. open t \<Longrightarrow> s \<subseteq> \<Union> C \<Longrightarrow> \<exists>C'. C' \<subseteq> C \<and> finite C' \<and> s \<subseteq> \<Union> C'"
huffman@51913
  2343
  shows "compact s"
huffman@51913
  2344
  unfolding compact_eq_heine_borel using assms by metis
huffman@51913
  2345
huffman@51913
  2346
lemma compactE:
huffman@51913
  2347
  assumes "compact s" and "\<forall>t\<in>C. open t" and "s \<subseteq> \<Union>C"
huffman@51913
  2348
  obtains C' where "C' \<subseteq> C" and "finite C'" and "s \<subseteq> \<Union>C'"
huffman@51913
  2349
  using assms unfolding compact_eq_heine_borel by metis
huffman@51913
  2350
hoelzl@51959
  2351
lemma compactE_image:
hoelzl@51959
  2352
  assumes "compact s" and "\<forall>t\<in>C. open (f t)" and "s \<subseteq> (\<Union>c\<in>C. f c)"
hoelzl@51959
  2353
  obtains C' where "C' \<subseteq> C" and "finite C'" and "s \<subseteq> (\<Union>c\<in>C'. f c)"
hoelzl@51959
  2354
  using assms unfolding ball_simps[symmetric] SUP_def
hoelzl@51959
  2355
  by (metis (lifting) finite_subset_image compact_eq_heine_borel[of s])
hoelzl@51959
  2356
hoelzl@51899
  2357
subsubsection {* Bolzano-Weierstrass property *}
hoelzl@51899
  2358
hoelzl@51899
  2359
lemma heine_borel_imp_bolzano_weierstrass:
hoelzl@51899
  2360
  assumes "compact s" "infinite t"  "t \<subseteq> s"
hoelzl@51899
  2361
  shows "\<exists>x \<in> s. x islimpt t"
hoelzl@51899
  2362
proof(rule ccontr)
hoelzl@51899
  2363
  assume "\<not> (\<exists>x \<in> s. x islimpt t)"
hoelzl@51899
  2364
  then obtain f where f:"\<forall>x\<in>s. x \<in> f x \<and> open (f x) \<and> (\<forall>y\<in>t. y \<in> f x \<longrightarrow> y = x)" unfolding islimpt_def
hoelzl@51899
  2365
    using bchoice[of s "\<lambda> x T. x \<in> T \<and> open T \<and> (\<forall>y\<in>t. y \<in> T \<longrightarrow> y = x)"] by auto
hoelzl@51899
  2366
  obtain g where g:"g\<subseteq>{t. \<exists>x. x \<in> s \<and> t = f x}" "finite g" "s \<subseteq> \<Union>g"
hoelzl@51899
  2367
    using assms(1)[unfolded compact_eq_heine_borel, THEN spec[where x="{t. \<exists>x. x\<in>s \<and> t = f x}"]] using f by auto
hoelzl@51899
  2368
  from g(1,3) have g':"\<forall>x\<in>g. \<exists>xa \<in> s. x = f xa" by auto
hoelzl@51899
  2369
  { fix x y assume "x\<in>t" "y\<in>t" "f x = f y"
hoelzl@51899
  2370
    hence "x \<in> f x"  "y \<in> f x \<longrightarrow> y = x" using f[THEN bspec[where x=x]] and `t\<subseteq>s` by auto
hoelzl@51899
  2371
    hence "x = y" using `f x = f y` and f[THEN bspec[where x=y]] and `y\<in>t` and `t\<subseteq>s` by auto  }
hoelzl@51899
  2372
  hence "inj_on f t" unfolding inj_on_def by simp
hoelzl@51899
  2373
  hence "infinite (f ` t)" using assms(2) using finite_imageD by auto
hoelzl@51899
  2374
  moreover
hoelzl@51899
  2375
  { fix x assume "x\<in>t" "f x \<notin> g"
hoelzl@51899
  2376
    from g(3) assms(3) `x\<in>t` obtain h where "h\<in>g" and "x\<in>h" by auto
hoelzl@51899
  2377
    then obtain y where "y\<in>s" "h = f y" using g'[THEN bspec[where x=h]] by auto
hoelzl@51899
  2378
    hence "y = x" using f[THEN bspec[where x=y]] and `x\<in>t` and `x\<in>h`[unfolded `h = f y`] by auto
hoelzl@51899
  2379
    hence False using `f x \<notin> g` `h\<in>g` unfolding `h = f y` by auto  }
hoelzl@51899
  2380
  hence "f ` t \<subseteq> g" by auto
hoelzl@51899
  2381
  ultimately show False using g(2) using finite_subset by auto
hoelzl@51899
  2382
qed
hoelzl@51899
  2383
hoelzl@51958
  2384
lemma acc_point_range_imp_convergent_subsequence:
hoelzl@51958
  2385
  fixes l :: "'a :: first_countable_topology"
hoelzl@51958
  2386
  assumes l: "\<forall>U. l\<in>U \<longrightarrow> open U \<longrightarrow> infinite (U \<inter> range f)"
hoelzl@51958
  2387
  shows "\<exists>r. subseq r \<and> (f \<circ> r) ----> l"
hoelzl@51899
  2388
proof -
hoelzl@51958
  2389
  from countable_basis_at_decseq[of l] guess A . note A = this
hoelzl@51899
  2390
hoelzl@51899
  2391
  def s \<equiv> "\<lambda>n i. SOME j. i < j \<and> f j \<in> A (Suc n)"
hoelzl@51899
  2392
  { fix n i
hoelzl@51958
  2393
    have "infinite (A (Suc n) \<inter> range f - f`{.. i})"
hoelzl@51958
  2394
      using l A by auto
hoelzl@51958
  2395
    then have "\<exists>x. x \<in> A (Suc n) \<inter> range f - f`{.. i}"
hoelzl@51958
  2396
      unfolding ex_in_conv by (intro notI) simp
hoelzl@51958
  2397
    then have "\<exists>j. f j \<in> A (Suc n) \<and> j \<notin> {.. i}"
hoelzl@51958
  2398
      by auto
hoelzl@51958
  2399
    then have "\<exists>a. i < a \<and> f a \<in> A (Suc n)"
hoelzl@51958
  2400
      by (auto simp: not_le)
hoelzl@51899
  2401
    then have "i < s n i" "f (s n i) \<in> A (Suc n)"
hoelzl@51899
  2402
      unfolding s_def by (auto intro: someI2_ex) }
hoelzl@51899
  2403
  note s = this
hoelzl@51899
  2404
  def r \<equiv> "nat_rec (s 0 0) s"
hoelzl@51899
  2405
  have "subseq r"
hoelzl@51899
  2406
    by (auto simp: r_def s subseq_Suc_iff)
hoelzl@51899
  2407
  moreover
hoelzl@51899
  2408
  have "(\<lambda>n. f (r n)) ----> l"
hoelzl@51899
  2409
  proof (rule topological_tendstoI)
hoelzl@51899
  2410
    fix S assume "open S" "l \<in> S"
hoelzl@51899
  2411
    with A(3) have "eventually (\<lambda>i. A i \<subseteq> S) sequentially" by auto
hoelzl@51899
  2412
    moreover
hoelzl@51899
  2413
    { fix i assume "Suc 0 \<le> i" then have "f (r i) \<in> A i"
hoelzl@51899
  2414
        by (cases i) (simp_all add: r_def s) }
hoelzl@51899
  2415
    then have "eventually (\<lambda>i. f (r i) \<in> A i) sequentially" by (auto simp: eventually_sequentially)
hoelzl@51899
  2416
    ultimately show "eventually (\<lambda>i. f (r i) \<in> S) sequentially"
hoelzl@51899
  2417
      by eventually_elim auto
hoelzl@51899
  2418
  qed
hoelzl@51899
  2419
  ultimately show "\<exists>r. subseq r \<and> (f \<circ> r) ----> l"
hoelzl@51899
  2420
    by (auto simp: convergent_def comp_def)
hoelzl@51899
  2421
qed
hoelzl@51899
  2422
hoelzl@51899
  2423
lemma sequence_infinite_lemma:
hoelzl@51899
  2424
  fixes f :: "nat \<Rightarrow> 'a::t1_space"
hoelzl@51899
  2425
  assumes "\<forall>n. f n \<noteq> l" and "(f ---> l) sequentially"
hoelzl@51899
  2426
  shows "infinite (range f)"
hoelzl@51899
  2427
proof
hoelzl@51899
  2428
  assume "finite (range f)"
hoelzl@51899
  2429
  hence "closed (range f)" by (rule finite_imp_closed)
hoelzl@51899
  2430
  hence "open (- range f)" by (rule open_Compl)
hoelzl@51899
  2431
  from assms(1) have "l \<in> - range f" by auto
hoelzl@51899
  2432
  from assms(2) have "eventually (\<lambda>n. f n \<in> - range f) sequentially"
hoelzl@51899
  2433
    using `open (- range f)` `l \<in> - range f` by (rule topological_tendstoD)
hoelzl@51899
  2434
  thus False unfolding eventually_sequentially by auto
hoelzl@51899
  2435
qed
hoelzl@51899
  2436
hoelzl@51899
  2437
lemma closure_insert:
hoelzl@51899
  2438
  fixes x :: "'a::t1_space"
hoelzl@51899
  2439
  shows "closure (insert x s) = insert x (closure s)"
hoelzl@51899
  2440
apply (rule closure_unique)
hoelzl@51899
  2441
apply (rule insert_mono [OF closure_subset])
hoelzl@51899
  2442
apply (rule closed_insert [OF closed_closure])
hoelzl@51899
  2443
apply (simp add: closure_minimal)
hoelzl@51899
  2444
done
hoelzl@51899
  2445
hoelzl@51899
  2446
lemma islimpt_insert:
hoelzl@51899
  2447
  fixes x :: "'a::t1_space"
hoelzl@51899
  2448
  shows "x islimpt (insert a s) \<longleftrightarrow> x islimpt s"
hoelzl@51899
  2449
proof
hoelzl@51899
  2450
  assume *: "x islimpt (insert a s)"
hoelzl@51899
  2451
  show "x islimpt s"
hoelzl@51899
  2452
  proof (rule islimptI)
hoelzl@51899
  2453
    fix t assume t: "x \<in> t" "open t"
hoelzl@51899
  2454
    show "\<exists>y\<in>s. y \<in> t \<and> y \<noteq> x"
hoelzl@51899
  2455
    proof (cases "x = a")
hoelzl@51899
  2456
      case True
hoelzl@51899
  2457
      obtain y where "y \<in> insert a s" "y \<in> t" "y \<noteq> x"
hoelzl@51899
  2458
        using * t by (rule islimptE)
hoelzl@51899
  2459
      with `x = a` show ?thesis by auto
hoelzl@51899
  2460
    next
hoelzl@51899
  2461
      case False
hoelzl@51899
  2462
      with t have t': "x \<in> t - {a}" "open (t - {a})"
hoelzl@51899
  2463
        by (simp_all add: open_Diff)
hoelzl@51899
  2464
      obtain y where "y \<in> insert a s" "y \<in> t - {a}" "y \<noteq> x"
hoelzl@51899
  2465
        using * t' by (rule islimptE)
hoelzl@51899
  2466
      thus ?thesis by auto
hoelzl@51899
  2467
    qed
hoelzl@51899
  2468
  qed
hoelzl@51899
  2469
next
hoelzl@51899
  2470
  assume "x islimpt s" thus "x islimpt (insert a s)"
hoelzl@51899
  2471
    by (rule islimpt_subset) auto
hoelzl@51899
  2472
qed
hoelzl@51899
  2473
huffman@51912
  2474
lemma islimpt_finite:
huffman@51912
  2475
  fixes x :: "'a::t1_space"
huffman@51912
  2476
  shows "finite s \<Longrightarrow> \<not> x islimpt s"
huffman@51912
  2477
by (induct set: finite, simp_all add: islimpt_insert)
huffman@51912
  2478
hoelzl@51899
  2479
lemma islimpt_union_finite:
hoelzl@51899
  2480
  fixes x :: "'a::t1_space"
hoelzl@51899
  2481
  shows "finite s \<Longrightarrow> x islimpt (s \<union> t) \<longleftrightarrow> x islimpt t"
huffman@51912
  2482
by (simp add: islimpt_Un islimpt_finite)
huffman@51912
  2483
hoelzl@51958
  2484
lemma islimpt_eq_acc_point:
hoelzl@51958
  2485
  fixes l :: "'a :: t1_space"
hoelzl@51958
  2486
  shows "l islimpt S \<longleftrightarrow> (\<forall>U. l\<in>U \<longrightarrow> open U \<longrightarrow> infinite (U \<inter> S))"
hoelzl@51958
  2487
proof (safe intro!: islimptI)
hoelzl@51958
  2488
  fix U assume "l islimpt S" "l \<in> U" "open U" "finite (U \<inter> S)"
hoelzl@51958
  2489
  then have "l islimpt S" "l \<in> (U - (U \<inter> S - {l}))" "open (U - (U \<inter> S - {l}))"
hoelzl@51958
  2490
    by (auto intro: finite_imp_closed)
hoelzl@51958
  2491
  then show False
hoelzl@51958
  2492
    by (rule islimptE) auto
hoelzl@51958
  2493
next
hoelzl@51958
  2494
  fix T assume *: "\<forall>U. l\<in>U \<longrightarrow> open U \<longrightarrow> infinite (U \<inter> S)" "l \<in> T" "open T"
hoelzl@51958
  2495
  then have "infinite (T \<inter> S - {l})" by auto
hoelzl@51958
  2496
  then have "\<exists>x. x \<in> (T \<inter> S - {l})"
hoelzl@51958
  2497
    unfolding ex_in_conv by (intro notI) simp
hoelzl@51958
  2498
  then show "\<exists>y\<in>S. y \<in> T \<and> y \<noteq> l"
hoelzl@51958
  2499
    by auto
hoelzl@51958
  2500
qed
hoelzl@51958
  2501
hoelzl@51958
  2502
lemma islimpt_range_imp_convergent_subsequence:
hoelzl@51958
  2503
  fixes l :: "'a :: {t1_space, first_countable_topology}"
hoelzl@51958
  2504
  assumes l: "l islimpt (range f)"
hoelzl@51958
  2505
  shows "\<exists>r. subseq r \<and> (f \<circ> r) ----> l"
hoelzl@51958
  2506
  using l unfolding islimpt_eq_acc_point
hoelzl@51958
  2507
  by (rule acc_point_range_imp_convergent_subsequence)
hoelzl@51958
  2508
hoelzl@51899
  2509
lemma sequence_unique_limpt:
hoelzl@51899
  2510
  fixes f :: "nat \<Rightarrow> 'a::t2_space"
hoelzl@51899
  2511
  assumes "(f ---> l) sequentially" and "l' islimpt (range f)"
hoelzl@51899
  2512
  shows "l' = l"
hoelzl@51899
  2513
proof (rule ccontr)
hoelzl@51899
  2514
  assume "l' \<noteq> l"
hoelzl@51899
  2515
  obtain s t where "open s" "open t" "l' \<in> s" "l \<in> t" "s \<inter> t = {}"
hoelzl@51899
  2516
    using hausdorff [OF `l' \<noteq> l`] by auto
hoelzl@51899
  2517
  have "eventually (\<lambda>n. f n \<in> t) sequentially"
hoelzl@51899
  2518
    using assms(1) `open t` `l \<in> t` by (rule topological_tendstoD)
hoelzl@51899
  2519
  then obtain N where "\<forall>n\<ge>N. f n \<in> t"
hoelzl@51899
  2520
    unfolding eventually_sequentially by auto
hoelzl@51899
  2521
hoelzl@51899
  2522
  have "UNIV = {..<N} \<union> {N..}" by auto
hoelzl@51899
  2523
  hence "l' islimpt (f ` ({..<N} \<union> {N..}))" using assms(2) by simp
hoelzl@51899
  2524
  hence "l' islimpt (f ` {..<N} \<union> f ` {N..})" by (simp add: image_Un)
hoelzl@51899
  2525
  hence "l' islimpt (f ` {N..})" by (simp add: islimpt_union_finite)
hoelzl@51899
  2526
  then obtain y where "y \<in> f ` {N..}" "y \<in> s" "y \<noteq> l'"
hoelzl@51899
  2527
    using `l' \<in> s` `open s` by (rule islimptE)
hoelzl@51899
  2528
  then obtain n where "N \<le> n" "f n \<in> s" "f n \<noteq> l'" by auto
hoelzl@51899
  2529
  with `\<forall>n\<ge>N. f n \<in> t` have "f n \<in> s \<inter> t" by simp
hoelzl@51899
  2530
  with `s \<inter> t = {}` show False by simp
hoelzl@51899
  2531
qed
hoelzl@51899
  2532
hoelzl@51899
  2533
lemma bolzano_weierstrass_imp_closed:
hoelzl@51899
  2534
  fixes s :: "'a::{first_countable_topology, t2_space} set"
hoelzl@51899
  2535
  assumes "\<forall>t. infinite t \<and> t \<subseteq> s --> (\<exists>x \<in> s. x islimpt t)"
hoelzl@51899
  2536
  shows "closed s"
hoelzl@51899
  2537
proof-
hoelzl@51899
  2538
  { fix x l assume as: "\<forall>n::nat. x n \<in> s" "(x ---> l) sequentially"
hoelzl@51899
  2539
    hence "l \<in> s"
hoelzl@51899
  2540
    proof(cases "\<forall>n. x n \<noteq> l")
hoelzl@51899
  2541
      case False thus "l\<in>s" using as(1) by auto
hoelzl@51899
  2542
    next
hoelzl@51899
  2543
      case True note cas = this
hoelzl@51899
  2544
      with as(2) have "infinite (range x)" using sequence_infinite_lemma[of x l] by auto
hoelzl@51899
  2545
      then obtain l' where "l'\<in>s" "l' islimpt (range x)" using assms[THEN spec[where x="range x"]] as(1) by auto
hoelzl@51899
  2546
      thus "l\<in>s" using sequence_unique_limpt[of x l l'] using as cas by auto
hoelzl@51899
  2547
    qed  }
hoelzl@51899
  2548
  thus ?thesis unfolding closed_sequential_limits by fast
hoelzl@51899
  2549
qed
hoelzl@51899
  2550
hoelzl@51899
  2551
lemma compact_imp_closed:
huffman@51913
  2552
  fixes s :: "'a::t2_space set"
huffman@51913
  2553
  assumes "compact s" shows "closed s"
huffman@51913
  2554
unfolding closed_def
huffman@51913
  2555
proof (rule openI)
huffman@51913
  2556
  fix y assume "y \<in> - s"
huffman@51913
  2557
  let ?C = "\<Union>x\<in>s. {u. open u \<and> x \<in> u \<and> eventually (\<lambda>y. y \<notin> u) (nhds y)}"
huffman@51913
  2558
  note `compact s`
huffman@51913
  2559
  moreover have "\<forall>u\<in>?C. open u" by simp
huffman@51913
  2560
  moreover have "s \<subseteq> \<Union>?C"
huffman@51913
  2561
  proof
huffman@51913
  2562
    fix x assume "x \<in> s"
huffman@51913
  2563
    with `y \<in> - s` have "x \<noteq> y" by clarsimp
huffman@51913
  2564
    hence "\<exists>u v. open u \<and> open v \<and> x \<in> u \<and> y \<in> v \<and> u \<inter> v = {}"
huffman@51913
  2565
      by (rule hausdorff)
huffman@51913
  2566
    with `x \<in> s` show "x \<in> \<Union>?C"
huffman@51913
  2567
      unfolding eventually_nhds by auto
huffman@51913
  2568
  qed
huffman@51913
  2569
  ultimately obtain D where "D \<subseteq> ?C" and "finite D" and "s \<subseteq> \<Union>D"
huffman@51913
  2570
    by (rule compactE)
huffman@51913
  2571
  from `D \<subseteq> ?C` have "\<forall>x\<in>D. eventually (\<lambda>y. y \<notin> x) (nhds y)" by auto
huffman@51913
  2572
  with `finite D` have "eventually (\<lambda>y. y \<notin> \<Union>D) (nhds y)"
huffman@51913
  2573
    by (simp add: eventually_Ball_finite)
huffman@51913
  2574
  with `s \<subseteq> \<Union>D` have "eventually (\<lambda>y. y \<notin> s) (nhds y)"
huffman@51913
  2575
    by (auto elim!: eventually_mono [rotated])
huffman@51913
  2576
  thus "\<exists>t. open t \<and> y \<in> t \<and> t \<subseteq> - s"
huffman@51913
  2577
    by (simp add: eventually_nhds subset_eq)
hoelzl@51899
  2578
qed
hoelzl@51899
  2579
hoelzl@51959
  2580
lemma compact_imp_bounded:
hoelzl@51959
  2581
  assumes "compact U" shows "bounded U"
hoelzl@51959
  2582
proof -
hoelzl@51959
  2583
  have "compact U" "\<forall>x\<in>U. open (ball x 1)" "U \<subseteq> (\<Union>x\<in>U. ball x 1)" using assms by auto
hoelzl@51959
  2584
  then obtain D where D: "D \<subseteq> U" "finite D" "U \<subseteq> (\<Union>x\<in>D. ball x 1)"
hoelzl@51959
  2585
    by (elim compactE_image)
hoelzl@51959
  2586
  def d \<equiv> "SOME d. d \<in> D"
hoelzl@51959
  2587
  show "bounded U"
hoelzl@51959
  2588
    unfolding bounded_def
hoelzl@51959
  2589
  proof (intro exI, safe)
hoelzl@51959
  2590
    fix x assume "x \<in> U"
hoelzl@51959
  2591
    with D obtain d' where "d' \<in> D" "x \<in> ball d' 1" by auto
hoelzl@51959
  2592
    moreover have "dist d x \<le> dist d d' + dist d' x"
hoelzl@51959
  2593
      using dist_triangle[of d x d'] by (simp add: dist_commute)
hoelzl@51959
  2594
    moreover
hoelzl@51959
  2595
    from `x\<in>U` D have "d \<in> D"
hoelzl@51959
  2596
      unfolding d_def by (rule_tac someI_ex) auto
hoelzl@51959
  2597
    ultimately
hoelzl@51959
  2598
    show "dist d x \<le> Max ((\<lambda>d'. dist d d' + 1) ` D)"
hoelzl@51959
  2599
      using D by (subst Max_ge_iff) (auto intro!: bexI[of _ d'])
hoelzl@51959
  2600
  qed
hoelzl@51959
  2601
qed
hoelzl@51959
  2602
hoelzl@51899
  2603
text{* In particular, some common special cases. *}
hoelzl@51899
  2604
hoelzl@51899
  2605
lemma compact_empty[simp]:
hoelzl@51899
  2606
 "compact {}"
hoelzl@51899
  2607
  unfolding compact_eq_heine_borel
hoelzl@51899
  2608
  by auto
hoelzl@51899
  2609
hoelzl@51899
  2610
lemma compact_union [intro]:
hoelzl@51899
  2611
  assumes "compact s" "compact t" shows " compact (s \<union> t)"
huffman@51913
  2612
proof (rule compactI)
huffman@51913
  2613
  fix f assume *: "Ball f open" "s \<union> t \<subseteq> \<Union>f"
hoelzl@51899
  2614
  from * `compact s` obtain s' where "s' \<subseteq> f \<and> finite s' \<and> s \<subseteq> \<Union>s'"
hoelzl@51899
  2615
    unfolding compact_eq_heine_borel by (auto elim!: allE[of _ f]) metis
hoelzl@51899
  2616
  moreover from * `compact t` obtain t' where "t' \<subseteq> f \<and> finite t' \<and> t \<subseteq> \<Union>t'"
hoelzl@51899
  2617
    unfolding compact_eq_heine_borel by (auto elim!: allE[of _ f]) metis
hoelzl@51899
  2618
  ultimately show "\<exists>f'\<subseteq>f. finite f' \<and> s \<union> t \<subseteq> \<Union>f'"
hoelzl@51899
  2619
    by (auto intro!: exI[of _ "s' \<union> t'"])
hoelzl@51899
  2620
qed
hoelzl@51899
  2621
hoelzl@51899
  2622
lemma compact_Union [intro]: "finite S \<Longrightarrow> (\<And>T. T \<in> S \<Longrightarrow> compact T) \<Longrightarrow> compact (\<Union>S)"
hoelzl@51899
  2623
  by (induct set: finite) auto
hoelzl@51899
  2624
hoelzl@51899
  2625
lemma compact_UN [intro]:
hoelzl@51899
  2626
  "finite A \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> compact (B x)) \<Longrightarrow> compact (\<Union>x\<in>A. B x)"
hoelzl@51899
  2627
  unfolding SUP_def by (rule compact_Union) auto
hoelzl@51899
  2628
hoelzl@51899
  2629
lemma compact_inter_closed [intro]:
hoelzl@51899
  2630
  assumes "compact s" and "closed t"
hoelzl@51899
  2631
  shows "compact (s \<inter> t)"
huffman@51913
  2632
proof (rule compactI)
hoelzl@51899
  2633
  fix C assume C: "\<forall>c\<in>C. open c" and cover: "s \<inter> t \<subseteq> \<Union>C"
hoelzl@51899
  2634
  from C `closed t` have "\<forall>c\<in>C \<union> {-t}. open c" by auto
hoelzl@51899
  2635
  moreover from cover have "s \<subseteq> \<Union>(C \<union> {-t})" by auto
hoelzl@51899
  2636
  ultimately have "\<exists>D\<subseteq>C \<union> {-t}. finite D \<and> s \<subseteq> \<Union>D"
hoelzl@51899
  2637
    using `compact s` unfolding compact_eq_heine_borel by auto
hoelzl@51899
  2638
  then guess D ..
hoelzl@51899
  2639
  then show "\<exists>D\<subseteq>C. finite D \<and> s \<inter> t \<subseteq> \<Union>D"
hoelzl@51899
  2640
    by (intro exI[of _ "D - {-t}"]) auto
hoelzl@51899
  2641
qed
hoelzl@51899
  2642
hoelzl@51899
  2643
lemma closed_inter_compact [intro]:
hoelzl@51899
  2644
  assumes "closed s" and "compact t"
hoelzl@51899
  2645
  shows "compact (s \<inter> t)"
hoelzl@51899
  2646
  using compact_inter_closed [of t s] assms
hoelzl@51899
  2647
  by (simp add: Int_commute)
hoelzl@51899
  2648
hoelzl@51899
  2649
lemma compact_inter [intro]:
huffman@51913
  2650
  fixes s t :: "'a :: t2_space set"
hoelzl@51899
  2651
  assumes "compact s" and "compact t"
hoelzl@51899
  2652
  shows "compact (s \<inter> t)"
hoelzl@51899
  2653
  using assms by (intro compact_inter_closed compact_imp_closed)
hoelzl@51899
  2654
hoelzl@51899
  2655
lemma compact_sing [simp]: "compact {a}"
hoelzl@51899
  2656
  unfolding compact_eq_heine_borel by auto
hoelzl@51899
  2657
hoelzl@51899
  2658
lemma compact_insert [simp]:
hoelzl@51899
  2659
  assumes "compact s" shows "compact (insert x s)"
hoelzl@51899
  2660
proof -
hoelzl@51899
  2661
  have "compact ({x} \<union> s)"
hoelzl@51899
  2662
    using compact_sing assms by (rule compact_union)
hoelzl@51899
  2663
  thus ?thesis by simp
hoelzl@51899
  2664
qed
hoelzl@51899
  2665
hoelzl@51899
  2666
lemma finite_imp_compact:
hoelzl@51899
  2667
  shows "finite s \<Longrightarrow> compact s"
hoelzl@51899
  2668
  by (induct set: finite) simp_all
hoelzl@51899
  2669
hoelzl@51899
  2670
lemma open_delete:
hoelzl@51899
  2671
  fixes s :: "'a::t1_space set"
hoelzl@51899
  2672
  shows "open s \<Longrightarrow> open (s - {x})"
hoelzl@51899
  2673
  by (simp add: open_Diff)
hoelzl@51899
  2674
hoelzl@51899
  2675
text{* Finite intersection property *}
hoelzl@51899
  2676
hoelzl@51899
  2677
lemma inj_setminus: "inj_on uminus (A::'a set set)"
hoelzl@51899
  2678
  by (auto simp: inj_on_def)
hoelzl@51899
  2679
hoelzl@51899
  2680
lemma compact_fip:
hoelzl@51899
  2681
  "compact U \<longleftrightarrow>
hoelzl@51899
  2682
    (\<forall>A. (\<forall>a\<in>A. closed a) \<longrightarrow> (\<forall>B \<subseteq> A. finite B \<longrightarrow> U \<inter> \<Inter>B \<noteq> {}) \<longrightarrow> U \<inter> \<Inter>A \<noteq> {})"
hoelzl@51899
  2683
  (is "_ \<longleftrightarrow> ?R")
hoelzl@51899
  2684
proof (safe intro!: compact_eq_heine_borel[THEN iffD2])
hoelzl@51899
  2685
  fix A assume "compact U" and A: "\<forall>a\<in>A. closed a" "U \<inter> \<Inter>A = {}"
hoelzl@51899
  2686
    and fi: "\<forall>B \<subseteq> A. finite B \<longrightarrow> U \<inter> \<Inter>B \<noteq> {}"
hoelzl@51899
  2687
  from A have "(\<forall>a\<in>uminus`A. open a) \<and> U \<subseteq> \<Union>uminus`A"
hoelzl@51899
  2688
    by auto
hoelzl@51899
  2689
  with `compact U` obtain B where "B \<subseteq> A" "finite (uminus`B)" "U \<subseteq> \<Union>(uminus`B)"
hoelzl@51899
  2690
    unfolding compact_eq_heine_borel by (metis subset_image_iff)
hoelzl@51899
  2691
  with fi[THEN spec, of B] show False
hoelzl@51899
  2692
    by (auto dest: finite_imageD intro: inj_setminus)
hoelzl@51899
  2693
next
hoelzl@51899
  2694
  fix A assume ?R and cover: "\<forall>a\<in>A. open a" "U \<subseteq> \<Union>A"
hoelzl@51899
  2695
  from cover have "U \<inter> \<Inter>(uminus`A) = {}" "\<forall>a\<in>uminus`A. closed a"
hoelzl@51899
  2696
    by auto
hoelzl@51899
  2697
  with `?R` obtain B where "B \<subseteq> A" "finite (uminus`B)" "U \<inter> \<Inter>uminus`B = {}"
hoelzl@51899
  2698
    by (metis subset_image_iff)
hoelzl@51899
  2699
  then show "\<exists>T\<subseteq>A. finite T \<and> U \<subseteq> \<Union>T"
hoelzl@51899
  2700
    by  (auto intro!: exI[of _ B] inj_setminus dest: finite_imageD)
hoelzl@51899
  2701
qed
hoelzl@51899
  2702
hoelzl@51899
  2703
lemma compact_imp_fip:
hoelzl@51899
  2704
  "compact s \<Longrightarrow> \<forall>t \<in> f. closed t \<Longrightarrow> \<forall>f'. finite f' \<and> f' \<subseteq> f \<longrightarrow> (s \<inter> (\<Inter> f') \<noteq> {}) \<Longrightarrow>
hoelzl@51899
  2705
    s \<inter> (\<Inter> f) \<noteq> {}"
hoelzl@51899
  2706
  unfolding compact_fip by auto
hoelzl@51899
  2707
hoelzl@51899
  2708
text{*Compactness expressed with filters*}
hoelzl@51899
  2709
hoelzl@51899
  2710
definition "filter_from_subbase B = Abs_filter (\<lambda>P. \<exists>X \<subseteq> B. finite X \<and> Inf X \<le> P)"
hoelzl@51899
  2711
hoelzl@51899
  2712
lemma eventually_filter_from_subbase:
hoelzl@51899
  2713
  "eventually P (filter_from_subbase B) \<longleftrightarrow> (\<exists>X \<subseteq> B. finite X \<and> Inf X \<le> P)"
hoelzl@51899
  2714
    (is "_ \<longleftrightarrow> ?R P")
hoelzl@51899
  2715
  unfolding filter_from_subbase_def
hoelzl@51899
  2716
proof (rule eventually_Abs_filter is_filter.intro)+
hoelzl@51899
  2717
  show "?R (\<lambda>x. True)"
hoelzl@51899
  2718
    by (rule exI[of _ "{}"]) (simp add: le_fun_def)
hoelzl@51899
  2719
next
hoelzl@51899
  2720
  fix P Q assume "?R P" then guess X ..
hoelzl@51899
  2721
  moreover assume "?R Q" then guess Y ..
hoelzl@51899
  2722
  ultimately show "?R (\<lambda>x. P x \<and> Q x)"
hoelzl@51899
  2723
    by (intro exI[of _ "X \<union> Y"]) auto
hoelzl@51899
  2724
next
hoelzl@51899
  2725
  fix P Q
hoelzl@51899
  2726
  assume "?R P" then guess X ..
hoelzl@51899
  2727
  moreover assume "\<forall>x. P x \<longrightarrow> Q x"
hoelzl@51899
  2728
  ultimately show "?R Q"
hoelzl@51899
  2729
    by (intro exI[of _ X]) auto
hoelzl@51899
  2730
qed
hoelzl@51899
  2731
hoelzl@51899
  2732
lemma eventually_filter_from_subbaseI: "P \<in> B \<Longrightarrow> eventually P (filter_from_subbase B)"
hoelzl@51899
  2733
  by (subst eventually_filter_from_subbase) (auto intro!: exI[of _ "{P}"])
hoelzl@51899
  2734
hoelzl@51899
  2735
lemma filter_from_subbase_not_bot:
hoelzl@51899
  2736
  "\<forall>X \<subseteq> B. finite X \<longrightarrow> Inf X \<noteq> bot \<Longrightarrow> filter_from_subbase B \<noteq> bot"
hoelzl@51899
  2737
  unfolding trivial_limit_def eventually_filter_from_subbase by auto
hoelzl@51899
  2738
hoelzl@51899
  2739
lemma closure_iff_nhds_not_empty:
hoelzl@51899
  2740
  "x \<in> closure X \<longleftrightarrow> (\<forall>A. \<forall>S\<subseteq>A. open S \<longrightarrow> x \<in> S \<longrightarrow> X \<inter> A \<noteq> {})"
hoelzl@51899
  2741
proof safe
hoelzl@51899
  2742
  assume x: "x \<in> closure X"
hoelzl@51899
  2743
  fix S A assume "open S" "x \<in> S" "X \<inter> A = {}" "S \<subseteq> A"
hoelzl@51899
  2744
  then have "x \<notin> closure (-S)" 
hoelzl@51899
  2745
    by (auto simp: closure_complement subset_eq[symmetric] intro: interiorI)
hoelzl@51899
  2746
  with x have "x \<in> closure X - closure (-S)"
hoelzl@51899
  2747
    by auto
hoelzl@51899
  2748
  also have "\<dots> \<subseteq> closure (X \<inter> S)"
hoelzl@51899
  2749
    using `open S` open_inter_closure_subset[of S X] by (simp add: closed_Compl ac_simps)
hoelzl@51899
  2750
  finally have "X \<inter> S \<noteq> {}" by auto
hoelzl@51899
  2751
  then show False using `X \<inter> A = {}` `S \<subseteq> A` by auto
hoelzl@51899
  2752
next
hoelzl@51899
  2753
  assume "\<forall>A S. S \<subseteq> A \<longrightarrow> open S \<longrightarrow> x \<in> S \<longrightarrow> X \<inter> A \<noteq> {}"
hoelzl@51899
  2754
  from this[THEN spec, of "- X", THEN spec, of "- closure X"]
hoelzl@51899
  2755
  show "x \<in> closure X"
hoelzl@51899
  2756
    by (simp add: closure_subset open_Compl)
hoelzl@51899
  2757
qed
hoelzl@51899
  2758
hoelzl@51899
  2759
lemma compact_filter:
hoelzl@51899
  2760
  "compact U \<longleftrightarrow> (\<forall>F. F \<noteq> bot \<longrightarrow> eventually (\<lambda>x. x \<in> U) F \<longrightarrow> (\<exists>x\<in>U. inf (nhds x) F \<noteq> bot))"
hoelzl@51899
  2761
proof (intro allI iffI impI compact_fip[THEN iffD2] notI)
hoelzl@51899
  2762
  fix F assume "compact U" and F: "F \<noteq> bot" "eventually (\<lambda>x. x \<in> U) F"
hoelzl@51899
  2763
  from F have "U \<noteq> {}"
hoelzl@51899
  2764
    by (auto simp: eventually_False)
hoelzl@51899
  2765
hoelzl@51899
  2766
  def Z \<equiv> "closure ` {A. eventually (\<lambda>x. x \<in> A) F}"
hoelzl@51899
  2767
  then have "\<forall>z\<in>Z. closed z"
hoelzl@51899
  2768
    by auto
hoelzl@51899
  2769
  moreover 
hoelzl@51899
  2770
  have ev_Z: "\<And>z. z \<in> Z \<Longrightarrow> eventually (\<lambda>x. x \<in> z) F"
hoelzl@51899
  2771
    unfolding Z_def by (auto elim: eventually_elim1 intro: set_mp[OF closure_subset])
hoelzl@51899
  2772
  have "(\<forall>B \<subseteq> Z. finite B \<longrightarrow> U \<inter> \<Inter>B \<noteq> {})"
hoelzl@51899
  2773
  proof (intro allI impI)
hoelzl@51899
  2774
    fix B assume "finite B" "B \<subseteq> Z"
hoelzl@51899
  2775
    with `finite B` ev_Z have "eventually (\<lambda>x. \<forall>b\<in>B. x \<in> b) F"
hoelzl@51899
  2776
      by (auto intro!: eventually_Ball_finite)
hoelzl@51899
  2777
    with F(2) have "eventually (\<lambda>x. x \<in> U \<inter> (\<Inter>B)) F"
hoelzl@51899
  2778
      by eventually_elim auto
hoelzl@51899
  2779
    with F show "U \<inter> \<Inter>B \<noteq> {}"
hoelzl@51899
  2780
      by (intro notI) (simp add: eventually_False)
hoelzl@51899
  2781
  qed
hoelzl@51899
  2782
  ultimately have "U \<inter> \<Inter>Z \<noteq> {}"
hoelzl@51899
  2783
    using `compact U` unfolding compact_fip by blast
hoelzl@51899
  2784
  then obtain x where "x \<in> U" and x: "\<And>z. z \<in> Z \<Longrightarrow> x \<in> z" by auto
hoelzl@51899
  2785
hoelzl@51899
  2786
  have "\<And>P. eventually P (inf (nhds x) F) \<Longrightarrow> P \<noteq> bot"
hoelzl@51899
  2787
    unfolding eventually_inf eventually_nhds
hoelzl@51899
  2788
  proof safe
hoelzl@51899
  2789
    fix P Q R S
hoelzl@51899
  2790
    assume "eventually R F" "open S" "x \<in> S"
hoelzl@51899
  2791
    with open_inter_closure_eq_empty[of S "{x. R x}"] x[of "closure {x. R x}"]
hoelzl@51899
  2792
    have "S \<inter> {x. R x} \<noteq> {}" by (auto simp: Z_def)
hoelzl@51899
  2793
    moreover assume "Ball S Q" "\<forall>x. Q x \<and> R x \<longrightarrow> bot x"
hoelzl@51899
  2794
    ultimately show False by (auto simp: set_eq_iff)
hoelzl@51899
  2795
  qed
hoelzl@51899
  2796
  with `x \<in> U` show "\<exists>x\<in>U. inf (nhds x) F \<noteq> bot"
hoelzl@51899
  2797
    by (metis eventually_bot)
hoelzl@51899
  2798
next
hoelzl@51899
  2799
  fix A assume A: "\<forall>a\<in>A. closed a" "\<forall>B\<subseteq>A. finite B \<longrightarrow> U \<inter> \<Inter>B \<noteq> {}" "U \<inter> \<Inter>A = {}"
hoelzl@51899
  2800
hoelzl@51899
  2801
  def P' \<equiv> "(\<lambda>a (x::'a). x \<in> a)"
hoelzl@51899
  2802
  then have inj_P': "\<And>A. inj_on P' A"
hoelzl@51899
  2803
    by (auto intro!: inj_onI simp: fun_eq_iff)
hoelzl@51899
  2804
  def F \<equiv> "filter_from_subbase (P' ` insert U A)"
hoelzl@51899
  2805
  have "F \<noteq> bot"
hoelzl@51899
  2806
    unfolding F_def
hoelzl@51899
  2807
  proof (safe intro!: filter_from_subbase_not_bot)
hoelzl@51899
  2808
    fix X assume "X \<subseteq> P' ` insert U A" "finite X" "Inf X = bot"
hoelzl@51899
  2809
    then obtain B where "B \<subseteq> insert U A" "finite B" and B: "Inf (P' ` B) = bot"
hoelzl@51899
  2810
      unfolding subset_image_iff by (auto intro: inj_P' finite_imageD)
hoelzl@51899
  2811
    with A(2)[THEN spec, of "B - {U}"] have "U \<inter> \<Inter>(B - {U}) \<noteq> {}" by auto
hoelzl@51899
  2812
    with B show False by (auto simp: P'_def fun_eq_iff)
hoelzl@51899
  2813
  qed
hoelzl@51899
  2814
  moreover have "eventually (\<lambda>x. x \<in> U) F"
hoelzl@51899
  2815
    unfolding F_def by (rule eventually_filter_from_subbaseI) (auto simp: P'_def)
hoelzl@51899
  2816
  moreover assume "\<forall>F. F \<noteq> bot \<longrightarrow> eventually (\<lambda>x. x \<in> U) F \<longrightarrow> (\<exists>x\<in>U. inf (nhds x) F \<noteq> bot)"
hoelzl@51899
  2817
  ultimately obtain x where "x \<in> U" and x: "inf (nhds x) F \<noteq> bot"
hoelzl@51899
  2818
    by auto
hoelzl@51899
  2819
hoelzl@51899
  2820
  { fix V assume "V \<in> A"
hoelzl@51899
  2821
    then have V: "eventually (\<lambda>x. x \<in> V) F"
hoelzl@51899
  2822
      by (auto simp add: F_def image_iff P'_def intro!: eventually_filter_from_subbaseI)
hoelzl@51899
  2823
    have "x \<in> closure V"
hoelzl@51899
  2824
      unfolding closure_iff_nhds_not_empty
hoelzl@51899
  2825
    proof (intro impI allI)
hoelzl@51899
  2826
      fix S A assume "open S" "x \<in> S" "S \<subseteq> A"
hoelzl@51899
  2827
      then have "eventually (\<lambda>x. x \<in> A) (nhds x)" by (auto simp: eventually_nhds)
hoelzl@51899
  2828
      with V have "eventually (\<lambda>x. x \<in> V \<inter> A) (inf (nhds x) F)"
hoelzl@51899
  2829
        by (auto simp: eventually_inf)
hoelzl@51899
  2830
      with x show "V \<inter> A \<noteq> {}"
hoelzl@51899
  2831
        by (auto simp del: Int_iff simp add: trivial_limit_def)
hoelzl@51899
  2832
    qed
hoelzl@51899
  2833
    then have "x \<in> V"
hoelzl@51899
  2834
      using `V \<in> A` A(1) by simp }
hoelzl@51899
  2835
  with `x\<in>U` have "x \<in> U \<inter> \<Inter>A" by auto
hoelzl@51899
  2836
  with `U \<inter> \<Inter>A = {}` show False by auto
hoelzl@51899
  2837
qed
hoelzl@51899
  2838
hoelzl@51956
  2839
definition "countably_compact U \<longleftrightarrow>
hoelzl@51899
  2840
    (\<forall>A. countable A \<longrightarrow> (\<forall>a\<in>A. open a) \<longrightarrow> U \<subseteq> \<Union>A \<longrightarrow> (\<exists>T\<subseteq>A. finite T \<and> U \<subseteq> \<Union>T))"
hoelzl@51956
  2841
hoelzl@51956
  2842
lemma countably_compactE:
hoelzl@51956
  2843
  assumes "countably_compact s" and "\<forall>t\<in>C. open t" and "s \<subseteq> \<Union>C" "countable C"
hoelzl@51956
  2844
  obtains C' where "C' \<subseteq> C" and "finite C'" and "s \<subseteq> \<Union>C'"
hoelzl@51956
  2845
  using assms unfolding countably_compact_def by metis
hoelzl@51956
  2846
hoelzl@51956
  2847
lemma countably_compactI:
hoelzl@51956
  2848
  assumes "\<And>C. \<forall>t\<in>C. open t \<Longrightarrow> s \<subseteq> \<Union>C \<Longrightarrow> countable C \<Longrightarrow> (\<exists>C'\<subseteq>C. finite C' \<and> s \<subseteq> \<Union>C')"
hoelzl@51956
  2849
  shows "countably_compact s"
hoelzl@51956
  2850
  using assms unfolding countably_compact_def by metis
hoelzl@51956
  2851
hoelzl@51956
  2852
lemma compact_imp_countably_compact: "compact U \<Longrightarrow> countably_compact U"
hoelzl@51956
  2853
  by (auto simp: compact_eq_heine_borel countably_compact_def)
hoelzl@51956
  2854
hoelzl@51956
  2855
lemma countably_compact_imp_compact:
hoelzl@51956
  2856
  assumes "countably_compact U"
hoelzl@51956
  2857
  assumes ccover: "countable B" "\<forall>b\<in>B. open b"
hoelzl@51956
  2858
  assumes basis: "\<And>T x. open T \<Longrightarrow> x \<in> T \<Longrightarrow> x \<in> U \<Longrightarrow> \<exists>b\<in>B. x \<in> b \<and> b \<inter> U \<subseteq> T"
hoelzl@51956
  2859
  shows "compact U"
hoelzl@51956
  2860
  using `countably_compact U` unfolding compact_eq_heine_borel countably_compact_def
hoelzl@51956
  2861
proof safe
hoelzl@51899
  2862
  fix A assume A: "\<forall>a\<in>A. open a" "U \<subseteq> \<Union>A"
hoelzl@51899
  2863
  assume *: "\<forall>A. countable A \<longrightarrow> (\<forall>a\<in>A. open a) \<longrightarrow> U \<subseteq> \<Union>A \<longrightarrow> (\<exists>T\<subseteq>A. finite T \<and> U \<subseteq> \<Union>T)"
hoelzl@51956
  2864
hoelzl@51956
  2865
  moreover def C \<equiv> "{b\<in>B. \<exists>a\<in>A. b \<inter> U \<subseteq> a}"
hoelzl@51899
  2866
  ultimately have "countable C" "\<forall>a\<in>C. open a"
hoelzl@51956
  2867
    unfolding C_def using ccover by auto
hoelzl@51899
  2868
  moreover
hoelzl@51956
  2869
  have "\<Union>A \<inter> U \<subseteq> \<Union>C"
hoelzl@51899
  2870
  proof safe
hoelzl@51956
  2871
    fix x a assume "x \<in> U" "x \<in> a" "a \<in> A"
hoelzl@51956
  2872
    with basis[of a x] A obtain b where "b \<in> B" "x \<in> b" "b \<inter> U \<subseteq> a" by blast
hoelzl@51956
  2873
    with `a \<in> A` show "x \<in> \<Union>C" unfolding C_def
hoelzl@51956
  2874
      by auto
hoelzl@51899
  2875
  qed
hoelzl@51899
  2876
  then have "U \<subseteq> \<Union>C" using `U \<subseteq> \<Union>A` by auto
hoelzl@51899
  2877
  ultimately obtain T where "T\<subseteq>C" "finite T" "U \<subseteq> \<Union>T"
hoelzl@51899
  2878
    using * by metis
hoelzl@51956
  2879
  moreover then have "\<forall>t\<in>T. \<exists>a\<in>A. t \<inter> U \<subseteq> a"
hoelzl@51899
  2880
    by (auto simp: C_def)
hoelzl@51899
  2881
  then guess f unfolding bchoice_iff Bex_def ..
hoelzl@51899
  2882
  ultimately show "\<exists>T\<subseteq>A. finite T \<and> U \<subseteq> \<Union>T"
hoelzl@51899
  2883
    unfolding C_def by (intro exI[of _ "f`T"]) fastforce
hoelzl@51956
  2884
qed
hoelzl@51956
  2885
hoelzl@51956
  2886
lemma countably_compact_imp_compact_second_countable:
hoelzl@51956
  2887
  "countably_compact U \<Longrightarrow> compact (U :: 'a :: second_countable_topology set)"
hoelzl@51956
  2888
proof (rule countably_compact_imp_compact)
hoelzl@51956
  2889
  fix T and x :: 'a assume "open T" "x \<in> T"
hoelzl@51956
  2890
  from topological_basisE[OF is_basis this] guess b .
hoelzl@51956
  2891
  then show "\<exists>b\<in>SOME B. countable B \<and> topological_basis B. x \<in> b \<and> b \<inter> U \<subseteq> T" by auto
hoelzl@51956
  2892
qed (insert countable_basis topological_basis_open[OF is_basis], auto)
huffman@36433
  2893
hoelzl@51958
  2894
lemma countably_compact_eq_compact:
hoelzl@51958
  2895
  "countably_compact U \<longleftrightarrow> compact (U :: 'a :: second_countable_topology set)"
hoelzl@51958
  2896
  using countably_compact_imp_compact_second_countable compact_imp_countably_compact by blast
hoelzl@51958
  2897
  
huffman@36433
  2898
subsubsection{* Sequential compactness *}
himmelma@33175
  2899
himmelma@33175
  2900
definition
hoelzl@51899
  2901
  seq_compact :: "'a::topological_space set \<Rightarrow> bool" where
hoelzl@51899
  2902
  "seq_compact S \<longleftrightarrow>
himmelma@33175
  2903
   (\<forall>f. (\<forall>n. f n \<in> S) \<longrightarrow>
himmelma@33175
  2904
       (\<exists>l\<in>S. \<exists>r. subseq r \<and> ((f o r) ---> l) sequentially))"
himmelma@33175
  2905
hoelzl@51956
  2906
lemma seq_compact_imp_countably_compact:
hoelzl@51956
  2907
  fixes U :: "'a :: first_countable_topology set"
hoelzl@51899
  2908
  assumes "seq_compact U"
hoelzl@51956
  2909
  shows "countably_compact U"
hoelzl@51956
  2910
proof (safe intro!: countably_compactI)
hoelzl@51899
  2911
  fix A assume A: "\<forall>a\<in>A. open a" "U \<subseteq> \<Union>A" "countable A"
hoelzl@51899
  2912
  have subseq: "\<And>X. range X \<subseteq> U \<Longrightarrow> \<exists>r x. x \<in> U \<and> subseq r \<and> (X \<circ> r) ----> x"
hoelzl@51899
  2913
    using `seq_compact U` by (fastforce simp: seq_compact_def subset_eq)
hoelzl@51899
  2914
  show "\<exists>T\<subseteq>A. finite T \<and> U \<subseteq> \<Union>T"
hoelzl@51899
  2915
  proof cases
hoelzl@51899
  2916
    assume "finite A" with A show ?thesis by auto
hoelzl@51899
  2917
  next
hoelzl@51899
  2918
    assume "infinite A"
hoelzl@51899
  2919
    then have "A \<noteq> {}" by auto
hoelzl@51899
  2920
    show ?thesis
hoelzl@51899
  2921
    proof (rule ccontr)
hoelzl@51899
  2922
      assume "\<not> (\<exists>T\<subseteq>A. finite T \<and> U \<subseteq> \<Union>T)"
hoelzl@51899
  2923
      then have "\<forall>T. \<exists>x. T \<subseteq> A \<and> finite T \<longrightarrow> (x \<in> U - \<Union>T)" by auto
hoelzl@51899
  2924
      then obtain X' where T: "\<And>T. T \<subseteq> A \<Longrightarrow> finite T \<Longrightarrow> X' T \<in> U - \<Union>T" by metis
hoelzl@51899
  2925
      def X \<equiv> "\<lambda>n. X' (from_nat_into A ` {.. n})"
hoelzl@51899
  2926
      have X: "\<And>n. X n \<in> U - (\<Union>i\<le>n. from_nat_into A i)"
hoelzl@51899
  2927
        using `A \<noteq> {}` unfolding X_def SUP_def by (intro T) (auto intro: from_nat_into)
hoelzl@51899
  2928
      then have "range X \<subseteq> U" by auto
hoelzl@51899
  2929
      with subseq[of X] obtain r x where "x \<in> U" and r: "subseq r" "(X \<circ> r) ----> x" by auto
hoelzl@51899
  2930
      from `x\<in>U` `U \<subseteq> \<Union>A` from_nat_into_surj[OF `countable A`]
hoelzl@51899
  2931
      obtain n where "x \<in> from_nat_into A n" by auto
hoelzl@51899
  2932
      with r(2) A(1) from_nat_into[OF `A \<noteq> {}`, of n]
hoelzl@51899
  2933
      have "eventually (\<lambda>i. X (r i) \<in> from_nat_into A n) sequentially"
hoelzl@51899
  2934
        unfolding tendsto_def by (auto simp: comp_def)
hoelzl@51899
  2935
      then obtain N where "\<And>i. N \<le> i \<Longrightarrow> X (r i) \<in> from_nat_into A n"
hoelzl@51899
  2936
        by (auto simp: eventually_sequentially)
hoelzl@51899
  2937
      moreover from X have "\<And>i. n \<le> r i \<Longrightarrow> X (r i) \<notin> from_nat_into A n"
hoelzl@51899
  2938
        by auto
hoelzl@51899
  2939
      moreover from `subseq r`[THEN seq_suble, of "max n N"] have "\<exists>i. n \<le> r i \<and> N \<le> i"
hoelzl@51899
  2940
        by (auto intro!: exI[of _ "max n N"])
hoelzl@51899
  2941
      ultimately show False
hoelzl@51899
  2942
        by auto
hoelzl@51899
  2943
    qed
hoelzl@51899
  2944
  qed
hoelzl@51899
  2945
qed
hoelzl@51899
  2946
hoelzl@51899
  2947
lemma compact_imp_seq_compact:
hoelzl@51899
  2948
  fixes U :: "'a :: first_countable_topology set"
hoelzl@51899
  2949
  assumes "compact U" shows "seq_compact U"
hoelzl@51899
  2950
  unfolding seq_compact_def
hoelzl@51899
  2951
proof safe
hoelzl@51899
  2952
  fix X :: "nat \<Rightarrow> 'a" assume "\<forall>n. X n \<in> U"
hoelzl@51899
  2953
  then have "eventually (\<lambda>x. x \<in> U) (filtermap X sequentially)"
hoelzl@51899
  2954
    by (auto simp: eventually_filtermap)
hoelzl@51899
  2955
  moreover have "filtermap X sequentially \<noteq> bot"
hoelzl@51899
  2956
    by (simp add: trivial_limit_def eventually_filtermap)
hoelzl@51899
  2957
  ultimately obtain x where "x \<in> U" and x: "inf (nhds x) (filtermap X sequentially) \<noteq> bot" (is "?F \<noteq> _")
hoelzl@51899
  2958
    using `compact U` by (auto simp: compact_filter)
hoelzl@51899
  2959
hoelzl@51899
  2960
  from countable_basis_at_decseq[of x] guess A . note A = this
hoelzl@51899
  2961
  def s \<equiv> "\<lambda>n i. SOME j. i < j \<and> X j \<in> A (Suc n)"
hoelzl@51899
  2962
  { fix n i
hoelzl@51899
  2963
    have "\<exists>a. i < a \<and> X a \<in> A (Suc n)"
hoelzl@51899
  2964
    proof (rule ccontr)
hoelzl@51899
  2965
      assume "\<not> (\<exists>a>i. X a \<in> A (Suc n))"
hoelzl@51899
  2966
      then have "\<And>a. Suc i \<le> a \<Longrightarrow> X a \<notin> A (Suc n)" by auto
hoelzl@51899
  2967
      then have "eventually (\<lambda>x. x \<notin> A (Suc n)) (filtermap X sequentially)"
hoelzl@51899
  2968
        by (auto simp: eventually_filtermap eventually_sequentially)
hoelzl@51899
  2969
      moreover have "eventually (\<lambda>x. x \<in> A (Suc n)) (nhds x)"
hoelzl@51899
  2970
        using A(1,2)[of "Suc n"] by (auto simp: eventually_nhds)
hoelzl@51899
  2971
      ultimately have "eventually (\<lambda>x. False) ?F"
hoelzl@51899
  2972
        by (auto simp add: eventually_inf)
hoelzl@51899
  2973
      with x show False
hoelzl@51899
  2974
        by (simp add: eventually_False)
hoelzl@51899
  2975
    qed
hoelzl@51899
  2976
    then have "i < s n i" "X (s n i) \<in> A (Suc n)"
hoelzl@51899
  2977
      unfolding s_def by (auto intro: someI2_ex) }
hoelzl@51899
  2978
  note s = this
hoelzl@51899
  2979
  def r \<equiv> "nat_rec (s 0 0) s"
hoelzl@51899
  2980
  have "subseq r"
hoelzl@51899
  2981
    by (auto simp: r_def s subseq_Suc_iff)
hoelzl@51899
  2982
  moreover
hoelzl@51899
  2983
  have "(\<lambda>n. X (r n)) ----> x"
hoelzl@51899
  2984
  proof (rule topological_tendstoI)
hoelzl@51899
  2985
    fix S assume "open S" "x \<in> S"
hoelzl@51899
  2986
    with A(3) have "eventually (\<lambda>i. A i \<subseteq> S) sequentially" by auto
hoelzl@51899
  2987
    moreover
hoelzl@51899
  2988
    { fix i assume "Suc 0 \<le> i" then have "X (r i) \<in> A i"
hoelzl@51899
  2989
        by (cases i) (simp_all add: r_def s) }
hoelzl@51899
  2990
    then have "eventually (\<lambda>i. X (r i) \<in> A i) sequentially" by (auto simp: eventually_sequentially)
hoelzl@51899
  2991
    ultimately show "eventually (\<lambda>i. X (r i) \<in> S) sequentially"
hoelzl@51899
  2992
      by eventually_elim auto
hoelzl@51899
  2993
  qed
hoelzl@51899
  2994
  ultimately show "\<exists>x \<in> U. \<exists>r. subseq r \<and> (X \<circ> r) ----> x"
hoelzl@51899
  2995
    using `x \<in> U` by (auto simp: convergent_def comp_def)
hoelzl@51899
  2996
qed
hoelzl@51899
  2997
hoelzl@51899
  2998
lemma seq_compactI:
huffman@44946
  2999
  assumes "\<And>f. \<forall>n. f n \<in> S \<Longrightarrow> \<exists>l\<in>S. \<exists>r. subseq r \<and> ((f o r) ---> l) sequentially"
hoelzl@51899
  3000
  shows "seq_compact S"
hoelzl@51899
  3001
  unfolding seq_compact_def using assms by fast
hoelzl@51899
  3002
hoelzl@51899
  3003
lemma seq_compactE:
hoelzl@51899
  3004
  assumes "seq_compact S" "\<forall>n. f n \<in> S"
huffman@44946
  3005
  obtains l r where "l \<in> S" "subseq r" "((f \<circ> r) ---> l) sequentially"
hoelzl@51899
  3006
  using assms unfolding seq_compact_def by fast
hoelzl@51899
  3007
hoelzl@51958
  3008
lemma countably_compact_imp_acc_point:
hoelzl@51958
  3009
  assumes "countably_compact s" "countable t" "infinite t"  "t \<subseteq> s"
hoelzl@51958
  3010
  shows "\<exists>x\<in>s. \<forall>U. x\<in>U \<and> open U \<longrightarrow> infinite (U \<inter> t)"
hoelzl@51958
  3011
proof (rule ccontr)
hoelzl@51958
  3012
  def C \<equiv> "(\<lambda>F. interior (F \<union> (- t))) ` {F. finite F \<and> F \<subseteq> t }"  
hoelzl@51958
  3013
  note `countably_compact s`
hoelzl@51958
  3014
  moreover have "\<forall>t\<in>C. open t" 
hoelzl@51958
  3015
    by (auto simp: C_def)
hoelzl@51958
  3016
  moreover
hoelzl@51958
  3017
  assume "\<not> (\<exists>x\<in>s. \<forall>U. x\<in>U \<and> open U \<longrightarrow> infinite (U \<inter> t))"
hoelzl@51958
  3018
  then have s: "\<And>x. x \<in> s \<Longrightarrow> \<exists>U. x\<in>U \<and> open U \<and> finite (U \<inter> t)" by metis
hoelzl@51958
  3019
  have "s \<subseteq> \<Union>C"
hoelzl@51958
  3020
    using `t \<subseteq> s`
hoelzl@51958
  3021
    unfolding C_def Union_image_eq
hoelzl@51958
  3022
    apply (safe dest!: s)
hoelzl@51958
  3023
    apply (rule_tac a="U \<inter> t" in UN_I)
hoelzl@51958
  3024
    apply (auto intro!: interiorI simp add: finite_subset)
hoelzl@51958
  3025
    done
hoelzl@51958
  3026
  moreover
hoelzl@51958
  3027
  from `countable t` have "countable C"
hoelzl@51958
  3028
    unfolding C_def by (auto intro: countable_Collect_finite_subset)
hoelzl@51958
  3029
  ultimately guess D by (rule countably_compactE)
hoelzl@51958
  3030
  then obtain E where E: "E \<subseteq> {F. finite F \<and> F \<subseteq> t }" "finite E" and
hoelzl@51958
  3031
    s: "s \<subseteq> (\<Union>F\<in>E. interior (F \<union> (- t)))"
hoelzl@51958
  3032
    by (metis (lifting) Union_image_eq finite_subset_image C_def)
hoelzl@51958
  3033
  from s `t \<subseteq> s` have "t \<subseteq> \<Union>E"
hoelzl@51958
  3034
    using interior_subset by blast
hoelzl@51958
  3035
  moreover have "finite (\<Union>E)"
hoelzl@51958
  3036
    using E by auto
hoelzl@51958
  3037
  ultimately show False using `infinite t` by (auto simp: finite_subset)
hoelzl@51958
  3038
qed
hoelzl@51958
  3039
hoelzl@51958
  3040
lemma countable_acc_point_imp_seq_compact:
hoelzl@51958
  3041
  fixes s :: "'a::first_countable_topology set"
hoelzl@51958
  3042
  assumes "\<forall>t. infinite t \<and> countable t \<and> t \<subseteq> s --> (\<exists>x\<in>s. \<forall>U. x\<in>U \<and> open U \<longrightarrow> infinite (U \<inter> t))"
hoelzl@51899
  3043
  shows "seq_compact s"
hoelzl@51899
  3044
proof -
hoelzl@51899
  3045
  { fix f :: "nat \<Rightarrow> 'a" assume f: "\<forall>n. f n \<in> s"
hoelzl@51958
  3046
    have "\<exists>l\<in>s. \<exists>r. subseq r \<and> ((f \<circ> r) ---> l) sequentially"
hoelzl@51899
  3047
    proof (cases "finite (range f)")
hoelzl@51899
  3048
      case True
hoelzl@51956
  3049
      obtain l where "infinite {n. f n = f l}"
hoelzl@51956
  3050
        using pigeonhole_infinite[OF _ True] by auto
hoelzl@51956
  3051
      then obtain r where "subseq r" and fr: "\<forall>n. f (r n) = f l"
hoelzl@51956
  3052
        using infinite_enumerate by blast
hoelzl@51956
  3053
      hence "subseq r \<and> (f \<circ> r) ----> f l"
hoelzl@51956
  3054
        by (simp add: fr tendsto_const o_def)
hoelzl@51956
  3055
      with f show "\<exists>l\<in>s. \<exists>r. subseq r \<and> (f \<circ> r) ----> l"
hoelzl@51956
  3056
        by auto
hoelzl@51899
  3057
    next
hoelzl@51899
  3058
      case False
hoelzl@51958
  3059
      with f assms have "\<exists>x\<in>s. \<forall>U. x\<in>U \<and> open U \<longrightarrow> infinite (U \<inter> range f)" by auto
hoelzl@51958
  3060
      then obtain l where "l \<in> s" "\<forall>U. l\<in>U \<and> open U \<longrightarrow> infinite (U \<inter> range f)" ..
hoelzl@51958
  3061
      from this(2) have "\<exists>r. subseq r \<and> ((f \<circ> r) ---> l) sequentially"
hoelzl@51958
  3062
        using acc_point_range_imp_convergent_subsequence[of l f] by auto
hoelzl@51958
  3063
      with `l \<in> s` show "\<exists>l\<in>s. \<exists>r. subseq r \<and> ((f \<circ> r) ---> l) sequentially" ..
hoelzl@51899
  3064
    qed
hoelzl@51899
  3065
  }
hoelzl@51899
  3066
  thus ?thesis unfolding seq_compact_def by auto
hoelzl@51899
  3067
qed
huffman@44946
  3068
hoelzl@51958
  3069
lemma seq_compact_eq_countably_compact:
hoelzl@51958
  3070
  fixes U :: "'a :: first_countable_topology set"
hoelzl@51958
  3071
  shows "seq_compact U \<longleftrightarrow> countably_compact U"
hoelzl@51958
  3072
  using
hoelzl@51958
  3073
    countable_acc_point_imp_seq_compact
hoelzl@51958
  3074
    countably_compact_imp_acc_point
hoelzl@51958
  3075
    seq_compact_imp_countably_compact
hoelzl@51958
  3076
  by metis
hoelzl@51958
  3077
hoelzl@51958
  3078
lemma seq_compact_eq_acc_point:
hoelzl@51958
  3079
  fixes s :: "'a :: first_countable_topology set"
hoelzl@51958
  3080
  shows "seq_compact s \<longleftrightarrow> (\<forall>t. infinite t \<and> countable t \<and> t \<subseteq> s --> (\<exists>x\<in>s. \<forall>U. x\<in>U \<and> open U \<longrightarrow> infinite (U \<inter> t)))"
hoelzl@51958
  3081
  using
hoelzl@51958
  3082
    countable_acc_point_imp_seq_compact[of s]
hoelzl@51958
  3083
    countably_compact_imp_acc_point[of s]
hoelzl@51958
  3084
    seq_compact_imp_countably_compact[of s]
hoelzl@51958
  3085
  by metis
hoelzl@51958
  3086
hoelzl@51958
  3087
lemma seq_compact_eq_compact:
hoelzl@51958
  3088
  fixes U :: "'a :: second_countable_topology set"
hoelzl@51958
  3089
  shows "seq_compact U \<longleftrightarrow> compact U"
hoelzl@51958
  3090
  using seq_compact_eq_countably_compact countably_compact_eq_compact by blast
hoelzl@51958
  3091
hoelzl@51958
  3092
lemma bolzano_weierstrass_imp_seq_compact:
hoelzl@51958
  3093
  fixes s :: "'a::{t1_space, first_countable_topology} set"
hoelzl@51958
  3094
  shows "\<forall>t. infinite t \<and> t \<subseteq> s --> (\<exists>x \<in> s. x islimpt t) \<Longrightarrow> seq_compact s"
hoelzl@51958
  3095
  by (rule countable_acc_point_imp_seq_compact) (metis islimpt_eq_acc_point)
hoelzl@51958
  3096
hoelzl@51955
  3097
subsubsection{* Total boundedness *}
hoelzl@51955
  3098
hoelzl@51955
  3099
lemma cauchy_def:
hoelzl@51955
  3100
  "Cauchy s \<longleftrightarrow> (\<forall>e>0. \<exists>N. \<forall>m n. m \<ge> N \<and> n \<ge> N --> dist(s m)(s n) < e)"
hoelzl@51955
  3101
unfolding Cauchy_def by blast
hoelzl@51955
  3102
hoelzl@51955
  3103
fun helper_1::"('a::metric_space set) \<Rightarrow> real \<Rightarrow> nat \<Rightarrow> 'a" where
hoelzl@51955
  3104
  "helper_1 s e n = (SOME y::'a. y \<in> s \<and> (\<forall>m<n. \<not> (dist (helper_1 s e m) y < e)))"
hoelzl@51955
  3105
declare helper_1.simps[simp del]
hoelzl@51955
  3106
hoelzl@51955
  3107
lemma seq_compact_imp_totally_bounded:
hoelzl@51955
  3108
  assumes "seq_compact s"
hoelzl@51955
  3109
  shows "\<forall>e>0. \<exists>k. finite k \<and> k \<subseteq> s \<and> s \<subseteq> (\<Union>((\<lambda>x. ball x e) ` k))"
hoelzl@51955
  3110
proof(rule, rule, rule ccontr)
hoelzl@51955
  3111
  fix e::real assume "e>0" and assm:"\<not> (\<exists>k. finite k \<and> k \<subseteq> s \<and> s \<subseteq> \<Union>(\<lambda>x. ball x e) ` k)"
hoelzl@51955
  3112
  def x \<equiv> "helper_1 s e"
hoelzl@51955
  3113
  { fix n
hoelzl@51955
  3114
    have "x n \<in> s \<and> (\<forall>m<n. \<not> dist (x m) (x n) < e)"
hoelzl@51955
  3115
    proof(induct_tac rule:nat_less_induct)
hoelzl@51955
  3116
      fix n  def Q \<equiv> "(\<lambda>y. y \<in> s \<and> (\<forall>m<n. \<not> dist (x m) y < e))"
hoelzl@51955
  3117
      assume as:"\<forall>m<n. x m \<in> s \<and> (\<forall>ma<m. \<not> dist (x ma) (x m) < e)"
hoelzl@51955
  3118
      have "\<not> s \<subseteq> (\<Union>x\<in>x ` {0..<n}. ball x e)" using assm apply simp apply(erule_tac x="x ` {0 ..< n}" in allE) using as by auto
hoelzl@51955
  3119
      then obtain z where z:"z\<in>s" "z \<notin> (\<Union>x\<in>x ` {0..<n}. ball x e)" unfolding subset_eq by auto
hoelzl@51955
  3120
      have "Q (x n)" unfolding x_def and helper_1.simps[of s e n]
hoelzl@51955
  3121
        apply(rule someI2[where a=z]) unfolding x_def[symmetric] and Q_def using z by auto
hoelzl@51955
  3122
      thus "x n \<in> s \<and> (\<forall>m<n. \<not> dist (x m) (x n) < e)" unfolding Q_def by auto
hoelzl@51955
  3123
    qed }
hoelzl@51955
  3124
  hence "\<forall>n::nat. x n \<in> s" and x:"\<forall>n. \<forall>m < n. \<not> (dist (x m) (x n) < e)" by blast+
hoelzl@51955
  3125
  then obtain l r where "l\<in>s" and r:"subseq r" and "((x \<circ> r) ---> l) sequentially" using assms(1)[unfolded seq_compact_def, THEN spec[where x=x]] by auto
hoelzl@51955
  3126
  from this(3) have "Cauchy (x \<circ> r)" using LIMSEQ_imp_Cauchy by auto
hoelzl@51955
  3127
  then obtain N::nat where N:"\<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist ((x \<circ> r) m) ((x \<circ> r) n) < e" unfolding cauchy_def using `e>0` by auto
hoelzl@51955
  3128
  show False
hoelzl@51955
  3129
    using N[THEN spec[where x=N], THEN spec[where x="N+1"]]
hoelzl@51955
  3130
    using r[unfolded subseq_def, THEN spec[where x=N], THEN spec[where x="N+1"]]
hoelzl@51955
  3131
    using x[THEN spec[where x="r (N+1)"], THEN spec[where x="r (N)"]] by auto
hoelzl@51955
  3132
qed
hoelzl@51955
  3133
hoelzl@51955
  3134
subsubsection{* Heine-Borel theorem *}
hoelzl@51955
  3135
hoelzl@51955
  3136
lemma seq_compact_imp_heine_borel:
hoelzl@51955
  3137
  fixes s :: "'a :: metric_space set"
hoelzl@51958
  3138
  assumes "seq_compact s" shows "compact s"
hoelzl@51958
  3139
proof -
hoelzl@51958
  3140
  from seq_compact_imp_totally_bounded[OF `seq_compact s`]
hoelzl@51958
  3141
  guess f unfolding choice_iff' .. note f = this
hoelzl@51958
  3142
  def K \<equiv> "(\<lambda>(x, r). ball x r) ` ((\<Union>e \<in> \<rat> \<inter> {0 <..}. f e) \<times> \<rat>)"
hoelzl@51958
  3143
  have "countably_compact s"
hoelzl@51958
  3144
    using `seq_compact s` by (rule seq_compact_imp_countably_compact)
hoelzl@51958
  3145
  then show "compact s"
hoelzl@51958
  3146
  proof (rule countably_compact_imp_compact)
hoelzl@51958
  3147
    show "countable K"
hoelzl@51958
  3148
      unfolding K_def using f
hoelzl@51958
  3149
      by (auto intro: countable_finite countable_subset countable_rat
hoelzl@51958
  3150
               intro!: countable_image countable_SIGMA countable_UN)
hoelzl@51958
  3151
    show "\<forall>b\<in>K. open b" by (auto simp: K_def)
hoelzl@51958
  3152
  next
hoelzl@51958
  3153
    fix T x assume T: "open T" "x \<in> T" and x: "x \<in> s"
hoelzl@51958
  3154
    from openE[OF T] obtain e where "0 < e" "ball x e \<subseteq> T" by auto
hoelzl@51958
  3155
    then have "0 < e / 2" "ball x (e / 2) \<subseteq> T" by auto
hoelzl@51958
  3156
    from Rats_dense_in_real[OF `0 < e / 2`] obtain r where "r \<in> \<rat>" "0 < r" "r < e / 2" by auto
hoelzl@51958
  3157
    from f[rule_format, of r] `0 < r` `x \<in> s` obtain k where "k \<in> f r" "x \<in> ball k r"
hoelzl@51958
  3158
      unfolding Union_image_eq by auto
hoelzl@51958
  3159
    from `r \<in> \<rat>` `0 < r` `k \<in> f r` have "ball k r \<in> K" by (auto simp: K_def)
hoelzl@51958
  3160
    then show "\<exists>b\<in>K. x \<in> b \<and> b \<inter> s \<subseteq> T"
hoelzl@51958
  3161
    proof (rule bexI[rotated], safe)
hoelzl@51958
  3162
      fix y assume "y \<in> ball k r"
hoelzl@51958
  3163
      with `r < e / 2` `x \<in> ball k r` have "dist x y < e"
hoelzl@51958
  3164
        by (intro dist_double[where x = k and d=e]) (auto simp: dist_commute)
hoelzl@51958
  3165
      with `ball x e \<subseteq> T` show "y \<in> T" by auto
hoelzl@51958
  3166
    qed (rule `x \<in> ball k r`)
hoelzl@51958
  3167
  qed
hoelzl@51955
  3168
qed
hoelzl@51955
  3169
hoelzl@51955
  3170
lemma compact_eq_seq_compact_metric:
hoelzl@51955
  3171
  "compact (s :: 'a::metric_space set) \<longleftrightarrow> seq_compact s"
hoelzl@51955
  3172
  using compact_imp_seq_compact seq_compact_imp_heine_borel by blast
hoelzl@51955
  3173
hoelzl@51955
  3174
lemma compact_def:
hoelzl@51955
  3175
  "compact (S :: 'a::metric_space set) \<longleftrightarrow>
hoelzl@51958
  3176
   (\<forall>f. (\<forall>n. f n \<in> S) \<longrightarrow> (\<exists>l\<in>S. \<exists>r. subseq r \<and> (f o r) ----> l))"
hoelzl@51955
  3177
  unfolding compact_eq_seq_compact_metric seq_compact_def by auto
hoelzl@51955
  3178
hoelzl@51959
  3179
subsubsection {* Complete the chain of compactness variants *}
hoelzl@51959
  3180
hoelzl@51959
  3181
lemma compact_eq_bolzano_weierstrass:
hoelzl@51959
  3182
  fixes s :: "'a::metric_space set"
hoelzl@51959
  3183
  shows "compact s \<longleftrightarrow> (\<forall>t. infinite t \<and> t \<subseteq> s --> (\<exists>x \<in> s. x islimpt t))" (is "?lhs = ?rhs")
hoelzl@51959
  3184
proof
hoelzl@51959
  3185
  assume ?lhs thus ?rhs using heine_borel_imp_bolzano_weierstrass[of s] by auto
hoelzl@51959
  3186
next
hoelzl@51959
  3187
  assume ?rhs thus ?lhs
hoelzl@51959
  3188
    unfolding compact_eq_seq_compact_metric by (rule bolzano_weierstrass_imp_seq_compact)
hoelzl@51959
  3189
qed
hoelzl@51959
  3190
hoelzl@51959
  3191
lemma bolzano_weierstrass_imp_bounded:
hoelzl@51959
  3192
  "\<forall>t. infinite t \<and> t \<subseteq> s --> (\<exists>x \<in> s. x islimpt t) \<Longrightarrow> bounded s"
hoelzl@51959
  3193
  using compact_imp_bounded unfolding compact_eq_bolzano_weierstrass .
hoelzl@51959
  3194
himmelma@33175
  3195
text {*
himmelma@33175
  3196
  A metric space (or topological vector space) is said to have the
himmelma@33175
  3197
  Heine-Borel property if every closed and bounded subset is compact.
himmelma@33175
  3198
*}
himmelma@33175
  3199
huffman@45078
  3200
class heine_borel = metric_space +
himmelma@33175
  3201
  assumes bounded_imp_convergent_subsequence:
himmelma@33175
  3202
    "bounded s \<Longrightarrow> \<forall>n. f n \<in> s
himmelma@33175
  3203
      \<Longrightarrow> \<exists>l r. subseq r \<and> ((f \<circ> r) ---> l) sequentially"
himmelma@33175
  3204
hoelzl@51899
  3205
lemma bounded_closed_imp_seq_compact:
himmelma@33175
  3206
  fixes s::"'a::heine_borel set"
hoelzl@51899
  3207
  assumes "bounded s" and "closed s" shows "seq_compact s"
hoelzl@51899
  3208
proof (unfold seq_compact_def, clarify)
himmelma@33175
  3209
  fix f :: "nat \<Rightarrow> 'a" assume f: "\<forall>n. f n \<in> s"
himmelma@33175
  3210
  obtain l r where r: "subseq r" and l: "((f \<circ> r) ---> l) sequentially"
himmelma@33175
  3211
    using bounded_imp_convergent_subsequence [OF `bounded s` `\<forall>n. f n \<in> s`] by auto
himmelma@33175
  3212
  from f have fr: "\<forall>n. (f \<circ> r) n \<in> s" by simp
himmelma@33175
  3213
  have "l \<in> s" using `closed s` fr l
himmelma@33175
  3214
    unfolding closed_sequential_limits by blast
himmelma@33175
  3215
  show "\<exists>l\<in>s. \<exists>r. subseq r \<and> ((f \<circ> r) ---> l) sequentially"
himmelma@33175
  3216
    using `l \<in> s` r l by blast
himmelma@33175
  3217
qed
himmelma@33175
  3218
hoelzl@51959
  3219
lemma compact_eq_bounded_closed:
hoelzl@51959
  3220
  fixes s :: "'a::heine_borel set"
hoelzl@51959
  3221
  shows "compact s \<longleftrightarrow> bounded s \<and> closed s"  (is "?lhs = ?rhs")
hoelzl@51959
  3222
proof
hoelzl@51959
  3223
  assume ?lhs thus ?rhs
hoelzl@51959
  3224
    using compact_imp_closed compact_imp_bounded by blast
hoelzl@51959
  3225
next
hoelzl@51959
  3226
  assume ?rhs thus ?lhs
hoelzl@51959
  3227
    using bounded_closed_imp_seq_compact[of s] unfolding compact_eq_seq_compact_metric by auto
hoelzl@51959
  3228
qed
hoelzl@51959
  3229
himmelma@33175
  3230
lemma lim_subseq:
himmelma@33175
  3231
  "subseq r \<Longrightarrow> (s ---> l) sequentially \<Longrightarrow> ((s o r) ---> l) sequentially"
himmelma@33175
  3232
unfolding tendsto_def eventually_sequentially o_def
hoelzl@51952
  3233
by (metis seq_suble le_trans)
himmelma@33175
  3234
himmelma@33175
  3235
lemma num_Axiom: "EX! g. g 0 = e \<and> (\<forall>n. g (Suc n) = f n (g n))"
himmelma@33175
  3236
  unfolding Ex1_def
himmelma@33175
  3237
  apply (rule_tac x="nat_rec e f" in exI)
himmelma@33175
  3238
  apply (rule conjI)+
himmelma@33175
  3239
apply (rule def_nat_rec_0, simp)
himmelma@33175
  3240
apply (rule allI, rule def_nat_rec_Suc, simp)
himmelma@33175
  3241
apply (rule allI, rule impI, rule ext)
himmelma@33175
  3242
apply (erule conjE)
himmelma@33175
  3243
apply (induct_tac x)
huffman@36358
  3244
apply simp
himmelma@33175
  3245
apply (erule_tac x="n" in allE)
himmelma@33175
  3246
apply (simp)
himmelma@33175
  3247
done
himmelma@33175
  3248
himmelma@33175
  3249
lemma convergent_bounded_increasing: fixes s ::"nat\<Rightarrow>real"
himmelma@33175
  3250
  assumes "incseq s" and "\<forall>n. abs(s n) \<le> b"
himmelma@33175
  3251
  shows "\<exists> l. \<forall>e::real>0. \<exists> N. \<forall>n \<ge> N.  abs(s n - l) < e"
himmelma@33175
  3252
proof-
himmelma@33175
  3253
  have "isUb UNIV (range s) b" using assms(2) and abs_le_D1 unfolding isUb_def and setle_def by auto
himmelma@33175
  3254
  then obtain t where t:"isLub UNIV (range s) t" using reals_complete[of "range s" ] by auto
himmelma@33175
  3255
  { fix e::real assume "e>0" and as:"\<forall>N. \<exists>n\<ge>N. \<not> \<bar>s n - t\<bar> < e"
himmelma@33175
  3256
    { fix n::nat
himmelma@33175
  3257
      obtain N where "N\<ge>n" and n:"\<bar>s N - t\<bar> \<ge> e" using as[THEN spec[where x=n]] by auto
himmelma@33175
  3258
      have "t \<ge> s N" using isLub_isUb[OF t, unfolded isUb_def setle_def] by auto
himmelma@33175
  3259
      with n have "s N \<le> t - e" using `e>0` by auto
himmelma@33175
  3260
      hence "s n \<le> t - e" using assms(1)[unfolded incseq_def, THEN spec[where x=n], THEN spec[where x=N]] using `n\<le>N` by auto  }
himmelma@33175
  3261
    hence "isUb UNIV (range s) (t - e)" unfolding isUb_def and setle_def by auto
himmelma@33175
  3262
    hence False using isLub_le_isUb[OF t, of "t - e"] and `e>0` by auto  }
himmelma@33175
  3263
  thus ?thesis by blast
himmelma@33175
  3264
qed
himmelma@33175
  3265
himmelma@33175
  3266
lemma convergent_bounded_monotone: fixes s::"nat \<Rightarrow> real"
himmelma@33175
  3267
  assumes "\<forall>n. abs(s n) \<le> b" and "monoseq s"
himmelma@33175
  3268
  shows "\<exists>l. \<forall>e::real>0. \<exists>N. \<forall>n\<ge>N. abs(s n - l) < e"
himmelma@33175
  3269
  using convergent_bounded_increasing[of s b] assms using convergent_bounded_increasing[of "\<lambda>n. - s n" b]
himmelma@33175
  3270
  unfolding monoseq_def incseq_def
himmelma@33175
  3271
  apply auto unfolding minus_add_distrib[THEN sym, unfolded diff_minus[THEN sym]]
himmelma@33175
  3272
  unfolding abs_minus_cancel by(rule_tac x="-l" in exI)auto
himmelma@33175
  3273
hoelzl@37489
  3274
(* TODO: merge this lemma with the ones above *)
hoelzl@37489
  3275
lemma bounded_increasing_convergent: fixes s::"nat \<Rightarrow> real"
hoelzl@37489
  3276
  assumes "bounded {s n| n::nat. True}"  "\<forall>n. (s n) \<le>(s(Suc n))"
hoelzl@37489
  3277
  shows "\<exists>l. (s ---> l) sequentially"
hoelzl@37489
  3278
proof-
hoelzl@37489
  3279
  obtain a where a:"\<forall>n. \<bar> (s n)\<bar> \<le>  a" using assms(1)[unfolded bounded_iff] by auto
hoelzl@37489
  3280
  { fix m::nat
hoelzl@37489
  3281
    have "\<And> n. n\<ge>m \<longrightarrow>  (s m) \<le> (s n)"
hoelzl@37489
  3282
      apply(induct_tac n) apply simp using assms(2) apply(erule_tac x="na" in allE)
hoelzl@37489
  3283
      apply(case_tac "m \<le> na") unfolding not_less_eq_eq by(auto simp add: not_less_eq_eq)  }
hoelzl@37489
  3284
  hence "\<forall>m n. m \<le> n \<longrightarrow> (s m) \<le> (s n)" by auto
hoelzl@37489
  3285
  then obtain l where "\<forall>e>0. \<exists>N. \<forall>n\<ge>N. \<bar> (s n) - l\<bar> < e" using convergent_bounded_monotone[OF a]
hoelzl@37489
  3286
    unfolding monoseq_def by auto
huffman@45778
  3287
  thus ?thesis unfolding LIMSEQ_def apply(rule_tac x="l" in exI)
hoelzl@37489
  3288
    unfolding dist_norm  by auto
hoelzl@37489
  3289
qed
hoelzl@37489
  3290
himmelma@33175
  3291
lemma compact_real_lemma:
himmelma@33175
  3292
  assumes "\<forall>n::nat. abs(s n) \<le> b"
himmelma@33175
  3293
  shows "\<exists>(l::real) r. subseq r \<and> ((s \<circ> r) ---> l) sequentially"
himmelma@33175
  3294
proof-
himmelma@33175
  3295
  obtain r where r:"subseq r" "monoseq (\<lambda>n. s (r n))"
himmelma@33175
  3296
    using seq_monosub[of s] by auto
himmelma@33175
  3297
  thus ?thesis using convergent_bounded_monotone[of "\<lambda>n. s (r n)" b] and assms
himmelma@33175
  3298
    unfolding tendsto_iff dist_norm eventually_sequentially by auto
himmelma@33175
  3299
qed
himmelma@33175
  3300
himmelma@33175
  3301
instance real :: heine_borel
himmelma@33175
  3302
proof
himmelma@33175
  3303
  fix s :: "real set" and f :: "nat \<Rightarrow> real"
himmelma@33175
  3304
  assume s: "bounded s" and f: "\<forall>n. f n \<in> s"
himmelma@33175
  3305
  then obtain b where b: "\<forall>n. abs (f n) \<le> b"
himmelma@33175
  3306
    unfolding bounded_iff by auto
himmelma@33175
  3307
  obtain l :: real and r :: "nat \<Rightarrow> nat" where
himmelma@33175
  3308
    r: "subseq r" and l: "((f \<circ> r) ---> l) sequentially"
himmelma@33175
  3309
    using compact_real_lemma [OF b] by auto
himmelma@33175
  3310
  thus "\<exists>l r. subseq r \<and> ((f \<circ> r) ---> l) sequentially"
himmelma@33175
  3311
    by auto
himmelma@33175
  3312
qed
himmelma@33175
  3313
himmelma@33175
  3314
lemma compact_lemma:
hoelzl@37489
  3315
  fixes f :: "nat \<Rightarrow> 'a::euclidean_space"
himmelma@33175
  3316
  assumes "bounded s" and "\<forall>n. f n \<in> s"
hoelzl@51541
  3317
  shows "\<forall>d\<subseteq>Basis. \<exists>l::'a. \<exists> r. subseq r \<and>
hoelzl@51541
  3318
        (\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r n) \<bullet> i) (l \<bullet> i) < e) sequentially)"
hoelzl@51541
  3319
proof safe
hoelzl@51541
  3320
  fix d :: "'a set" assume d: "d \<subseteq> Basis" 
hoelzl@51541
  3321
  with finite_Basis have "finite d" by (blast intro: finite_subset)
hoelzl@51541
  3322
  from this d show "\<exists>l::'a. \<exists>r. subseq r \<and>
hoelzl@51541
  3323
      (\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r n) \<bullet> i) (l \<bullet> i) < e) sequentially)"
himmelma@33175
  3324
  proof(induct d) case empty thus ?case unfolding subseq_def by auto
hoelzl@51541
  3325
  next case (insert k d) have k[intro]:"k\<in>Basis" using insert by auto
hoelzl@51541
  3326
    have s': "bounded ((\<lambda>x. x \<bullet> k) ` s)" using `bounded s`
hoelzl@51541
  3327
      by (auto intro!: bounded_linear_image bounded_linear_inner_left)
hoelzl@37489
  3328
    obtain l1::"'a" and r1 where r1:"subseq r1" and
hoelzl@51541
  3329
      lr1:"\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r1 n) \<bullet> i) (l1 \<bullet> i) < e) sequentially"
hoelzl@37489
  3330
      using insert(3) using insert(4) by auto
hoelzl@51541
  3331
    have f': "\<forall>n. f (r1 n) \<bullet> k \<in> (\<lambda>x. x \<bullet> k) ` s" using `\<forall>n. f n \<in> s` by simp
hoelzl@51541
  3332
    obtain l2 r2 where r2:"subseq r2" and lr2:"((\<lambda>i. f (r1 (r2 i)) \<bullet> k) ---> l2) sequentially"
himmelma@33175
  3333
      using bounded_imp_convergent_subsequence[OF s' f'] unfolding o_def by auto
himmelma@33175
  3334
    def r \<equiv> "r1 \<circ> r2" have r:"subseq r"
himmelma@33175
  3335
      using r1 and r2 unfolding r_def o_def subseq_def by auto
himmelma@33175
  3336
    moreover
hoelzl@51541
  3337
    def l \<equiv> "(\<Sum>i\<in>Basis. (if i = k then l2 else l1\<bullet>i) *\<^sub>R i)::'a"
himmelma@33175
  3338
    { fix e::real assume "e>0"
hoelzl@51541
  3339
      from lr1 `e>0` have N1:"eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r1 n) \<bullet> i) (l1 \<bullet> i) < e) sequentially" by blast
hoelzl@51541
  3340
      from lr2 `e>0` have N2:"eventually (\<lambda>n. dist (f (r1 (r2 n)) \<bullet> k) l2 < e) sequentially" by (rule tendstoD)
hoelzl@51541
  3341
      from r2 N1 have N1': "eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r1 (r2 n)) \<bullet> i) (l1 \<bullet> i) < e) sequentially"
himmelma@33175
  3342
        by (rule eventually_subseq)
hoelzl@51541
  3343
      have "eventually (\<lambda>n. \<forall>i\<in>(insert k d). dist (f (r n) \<bullet> i) (l \<bullet> i) < e) sequentially"
hoelzl@51541
  3344
        using N1' N2 
hoelzl@51541
  3345
        by eventually_elim (insert insert.prems, auto simp: l_def r_def o_def)
himmelma@33175
  3346
    }
himmelma@33175
  3347
    ultimately show ?case by auto
himmelma@33175
  3348
  qed
hoelzl@37489
  3349
qed
hoelzl@37489
  3350
hoelzl@37489
  3351
instance euclidean_space \<subseteq> heine_borel
himmelma@33175
  3352
proof
hoelzl@37489
  3353
  fix s :: "'a set" and f :: "nat \<Rightarrow> 'a"
himmelma@33175
  3354
  assume s: "bounded s" and f: "\<forall>n. f n \<in> s"
hoelzl@37489
  3355
  then obtain l::'a and r where r: "subseq r"
hoelzl@51541
  3356
    and l: "\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>Basis. dist (f (r n) \<bullet> i) (l \<bullet> i) < e) sequentially"
himmelma@33175
  3357
    using compact_lemma [OF s f] by blast
himmelma@33175
  3358
  { fix e::real assume "e>0"
hoelzl@51541
  3359
    hence "0 < e / real_of_nat DIM('a)" by (auto intro!: divide_pos_pos DIM_positive)
hoelzl@51541
  3360
    with l have "eventually (\<lambda>n. \<forall>i\<in>Basis. dist (f (r n) \<bullet> i) (l \<bullet> i) < e / (real_of_nat DIM('a))) sequentially"
himmelma@33175
  3361
      by simp
himmelma@33175
  3362
    moreover
hoelzl@51541
  3363
    { fix n assume n: "\<forall>i\<in>Basis. dist (f (r n) \<bullet> i) (l \<bullet> i) < e / (real_of_nat DIM('a))"
hoelzl@51541
  3364
      have "dist (f (r n)) l \<le> (\<Sum>i\<in>Basis. dist (f (r n) \<bullet> i) (l \<bullet> i))"
hoelzl@37489
  3365
        apply(subst euclidean_dist_l2) using zero_le_dist by (rule setL2_le_setsum)
hoelzl@51541
  3366
      also have "\<dots> < (\<Sum>i\<in>(Basis::'a set). e / (real_of_nat DIM('a)))"
hoelzl@37489
  3367
        apply(rule setsum_strict_mono) using n by auto
hoelzl@51541
  3368
      finally have "dist (f (r n)) l < e" 
hoelzl@51541
  3369
        by auto
himmelma@33175
  3370
    }
himmelma@33175
  3371
    ultimately have "eventually (\<lambda>n. dist (f (r n)) l < e) sequentially"
himmelma@33175
  3372
      by (rule eventually_elim1)
himmelma@33175
  3373
  }
himmelma@33175
  3374
  hence *:"((f \<circ> r) ---> l) sequentially" unfolding o_def tendsto_iff by simp
himmelma@33175
  3375
  with r show "\<exists>l r. subseq r \<and> ((f \<circ> r) ---> l) sequentially" by auto
himmelma@33175
  3376
qed
himmelma@33175
  3377
himmelma@33175
  3378
lemma bounded_fst: "bounded s \<Longrightarrow> bounded (fst ` s)"
himmelma@33175
  3379
unfolding bounded_def
himmelma@33175
  3380
apply clarify
himmelma@33175
  3381
apply (rule_tac x="a" in exI)
himmelma@33175
  3382
apply (rule_tac x="e" in exI)
himmelma@33175
  3383
apply clarsimp
himmelma@33175
  3384
apply (drule (1) bspec)
himmelma@33175
  3385
apply (simp add: dist_Pair_Pair)
himmelma@33175
  3386
apply (erule order_trans [OF real_sqrt_sum_squares_ge1])
himmelma@33175
  3387
done
himmelma@33175
  3388
himmelma@33175
  3389
lemma bounded_snd: "bounded s \<Longrightarrow> bounded (snd ` s)"
himmelma@33175
  3390
unfolding bounded_def
himmelma@33175
  3391
apply clarify
himmelma@33175
  3392
apply (rule_tac x="b" in exI)
himmelma@33175
  3393
apply (rule_tac x="e" in exI)
himmelma@33175
  3394
apply clarsimp
himmelma@33175
  3395
apply (drule (1) bspec)
himmelma@33175
  3396
apply (simp add: dist_Pair_Pair)
himmelma@33175
  3397
apply (erule order_trans [OF real_sqrt_sum_squares_ge2])
himmelma@33175
  3398
done
himmelma@33175
  3399
haftmann@37678
  3400
instance prod :: (heine_borel, heine_borel) heine_borel
himmelma@33175
  3401
proof
himmelma@33175
  3402
  fix s :: "('a * 'b) set" and f :: "nat \<Rightarrow> 'a * 'b"
himmelma@33175
  3403
  assume s: "bounded s" and f: "\<forall>n. f n \<in> s"
himmelma@33175
  3404
  from s have s1: "bounded (fst ` s)" by (rule bounded_fst)
himmelma@33175
  3405
  from f have f1: "\<forall>n. fst (f n) \<in> fst ` s" by simp
himmelma@33175
  3406
  obtain l1 r1 where r1: "subseq r1"
himmelma@33175
  3407
    and l1: "((\<lambda>n. fst (f (r1 n))) ---> l1) sequentially"
himmelma@33175
  3408
    using bounded_imp_convergent_subsequence [OF s1 f1]
himmelma@33175
  3409
    unfolding o_def by fast
himmelma@33175
  3410
  from s have s2: "bounded (snd ` s)" by (rule bounded_snd)
himmelma@33175
  3411
  from f have f2: "\<forall>n. snd (f (r1 n)) \<in> snd ` s" by simp
himmelma@33175
  3412
  obtain l2 r2 where r2: "subseq r2"
himmelma@33175
  3413
    and l2: "((\<lambda>n. snd (f (r1 (r2 n)))) ---> l2) sequentially"
himmelma@33175
  3414
    using bounded_imp_convergent_subsequence [OF s2 f2]
himmelma@33175
  3415
    unfolding o_def by fast
himmelma@33175
  3416
  have l1': "((\<lambda>n. fst (f (r1 (r2 n)))) ---> l1) sequentially"
himmelma@33175
  3417
    using lim_subseq [OF r2 l1] unfolding o_def .
himmelma@33175
  3418
  have l: "((f \<circ> (r1 \<circ> r2)) ---> (l1, l2)) sequentially"
himmelma@33175
  3419
    using tendsto_Pair [OF l1' l2] unfolding o_def by simp
himmelma@33175
  3420
  have r: "subseq (r1 \<circ> r2)"
himmelma@33175
  3421
    using r1 r2 unfolding subseq_def by simp
himmelma@33175
  3422
  show "\<exists>l r. subseq r \<and> ((f \<circ> r) ---> l) sequentially"
himmelma@33175
  3423
    using l r by fast
himmelma@33175
  3424
qed
himmelma@33175
  3425
huffman@36433
  3426
subsubsection{* Completeness *}
himmelma@33175
  3427
himmelma@33175
  3428
definition
himmelma@33175
  3429
  complete :: "'a::metric_space set \<Rightarrow> bool" where
himmelma@33175
  3430
  "complete s \<longleftrightarrow> (\<forall>f. (\<forall>n. f n \<in> s) \<and> Cauchy f
himmelma@33175
  3431
                      --> (\<exists>l \<in> s. (f ---> l) sequentially))"
himmelma@33175
  3432
himmelma@33175
  3433
lemma cauchy: "Cauchy s \<longleftrightarrow> (\<forall>e>0.\<exists> N::nat. \<forall>n\<ge>N. dist(s n)(s N) < e)" (is "?lhs = ?rhs")
himmelma@33175
  3434
proof-
himmelma@33175
  3435
  { assume ?rhs
himmelma@33175
  3436
    { fix e::real
himmelma@33175
  3437
      assume "e>0"
himmelma@33175
  3438
      with `?rhs` obtain N where N:"\<forall>n\<ge>N. dist (s n) (s N) < e/2"
himmelma@33175
  3439
        by (erule_tac x="e/2" in allE) auto
himmelma@33175
  3440
      { fix n m
himmelma@33175
  3441
        assume nm:"N \<le> m \<and> N \<le> n"
himmelma@33175
  3442
        hence "dist (s m) (s n) < e" using N
himmelma@33175
  3443
          using dist_triangle_half_l[of "s m" "s N" "e" "s n"]
himmelma@33175
  3444
          by blast
himmelma@33175
  3445
      }
himmelma@33175
  3446
      hence "\<exists>N. \<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (s m) (s n) < e"
himmelma@33175
  3447
        by blast
himmelma@33175
  3448
    }
himmelma@33175
  3449
    hence ?lhs
himmelma@33175
  3450
      unfolding cauchy_def
himmelma@33175
  3451
      by blast
himmelma@33175
  3452
  }
himmelma@33175
  3453
  thus ?thesis
himmelma@33175
  3454
    unfolding cauchy_def
himmelma@33175
  3455
    using dist_triangle_half_l
himmelma@33175
  3456
    by blast
himmelma@33175
  3457
qed
himmelma@33175
  3458
huffman@34098
  3459
lemma cauchy_imp_bounded: assumes "Cauchy s" shows "bounded (range s)"
himmelma@33175
  3460
proof-
himmelma@33175
  3461
  from assms obtain N::nat where "\<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (s m) (s n) < 1" unfolding cauchy_def apply(erule_tac x= 1 in allE) by auto
himmelma@33175
  3462
  hence N:"\<forall>n. N \<le> n \<longrightarrow> dist (s N) (s n) < 1" by auto
himmelma@33175
  3463
  moreover
himmelma@33175
  3464
  have "bounded (s ` {0..N})" using finite_imp_bounded[of "s ` {1..N}"] by auto
himmelma@33175
  3465
  then obtain a where a:"\<forall>x\<in>s ` {0..N}. dist (s N) x \<le> a"
himmelma@33175
  3466
    unfolding bounded_any_center [where a="s N"] by auto
himmelma@33175
  3467
  ultimately show "?thesis"
himmelma@33175
  3468
    unfolding bounded_any_center [where a="s N"]
himmelma@33175
  3469
    apply(rule_tac x="max a 1" in exI) apply auto
huffman@34098
  3470
    apply(erule_tac x=y in allE) apply(erule_tac x=y in ballE) by auto
himmelma@33175
  3471
qed
himmelma@33175
  3472
hoelzl@51899
  3473
lemma seq_compact_imp_complete: assumes "seq_compact s" shows "complete s"
himmelma@33175
  3474
proof-
himmelma@33175
  3475
  { fix f assume as: "(\<forall>n::nat. f n \<in> s)" "Cauchy f"
hoelzl@51899
  3476
    from as(1) obtain l r where lr: "l\<in>s" "subseq r" "((f \<circ> r) ---> l) sequentially" using assms unfolding seq_compact_def by blast
himmelma@33175
  3477
hoelzl@51952
  3478
    note lr' = seq_suble [OF lr(2)]
himmelma@33175
  3479
himmelma@33175
  3480
    { fix e::real assume "e>0"
himmelma@33175
  3481
      from as(2) obtain N where N:"\<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (f m) (f n) < e/2" unfolding cauchy_def using `e>0` apply (erule_tac x="e/2" in allE) by auto
huffman@45778
  3482
      from lr(3)[unfolded LIMSEQ_def, THEN spec[where x="e/2"]] obtain M where M:"\<forall>n\<ge>M. dist ((f \<circ> r) n) l < e/2" using `e>0` by auto
himmelma@33175
  3483
      { fix n::nat assume n:"n \<ge> max N M"
himmelma@33175
  3484
        have "dist ((f \<circ> r) n) l < e/2" using n M by auto
himmelma@33175
  3485
        moreover have "r n \<ge> N" using lr'[of n] n by auto
himmelma@33175
  3486
        hence "dist (f n) ((f \<circ> r) n) < e / 2" using N using n by auto
himmelma@33175
  3487
        ultimately have "dist (f n) l < e" using dist_triangle_half_r[of "f (r n)" "f n" e l] by (auto simp add: dist_commute)  }
himmelma@33175
  3488
      hence "\<exists>N. \<forall>n\<ge>N. dist (f n) l < e" by blast  }
huffman@45778
  3489
    hence "\<exists>l\<in>s. (f ---> l) sequentially" using `l\<in>s` unfolding LIMSEQ_def by auto  }
himmelma@33175
  3490
  thus ?thesis unfolding complete_def by auto
himmelma@33175
  3491
qed
himmelma@33175
  3492
himmelma@33175
  3493
instance heine_borel < complete_space
himmelma@33175
  3494
proof
himmelma@33175
  3495
  fix f :: "nat \<Rightarrow> 'a" assume "Cauchy f"
huffman@34098
  3496
  hence "bounded (range f)"
huffman@34098
  3497
    by (rule cauchy_imp_bounded)
hoelzl@51899
  3498
  hence "seq_compact (closure (range f))"
hoelzl@51899
  3499
    using bounded_closed_imp_seq_compact [of "closure (range f)"] by auto
himmelma@33175
  3500
  hence "complete (closure (range f))"
hoelzl@51899
  3501
    by (rule seq_compact_imp_complete)
himmelma@33175
  3502
  moreover have "\<forall>n. f n \<in> closure (range f)"
himmelma@33175
  3503
    using closure_subset [of "range f"] by auto
himmelma@33175
  3504
  ultimately have "\<exists>l\<in>closure (range f). (f ---> l) sequentially"
himmelma@33175
  3505
    using `Cauchy f` unfolding complete_def by auto
himmelma@33175
  3506
  then show "convergent f"
huffman@36660
  3507
    unfolding convergent_def by auto
himmelma@33175
  3508
qed
himmelma@33175
  3509
huffman@45490
  3510
instance euclidean_space \<subseteq> banach ..
huffman@45490
  3511
himmelma@33175
  3512
lemma complete_univ: "complete (UNIV :: 'a::complete_space set)"
himmelma@33175
  3513
proof(simp add: complete_def, rule, rule)
himmelma@33175
  3514
  fix f :: "nat \<Rightarrow> 'a" assume "Cauchy f"
himmelma@33175
  3515
  hence "convergent f" by (rule Cauchy_convergent)
huffman@36660
  3516
  thus "\<exists>l. f ----> l" unfolding convergent_def .  
himmelma@33175
  3517
qed
himmelma@33175
  3518
himmelma@33175
  3519
lemma complete_imp_closed: assumes "complete s" shows "closed s"
himmelma@33175
  3520
proof -
himmelma@33175
  3521
  { fix x assume "x islimpt s"
himmelma@33175
  3522
    then obtain f where f: "\<forall>n. f n \<in> s - {x}" "(f ---> x) sequentially"
himmelma@33175
  3523
      unfolding islimpt_sequential by auto
himmelma@33175
  3524
    then obtain l where l: "l\<in>s" "(f ---> l) sequentially"
hoelzl@51954
  3525
      using `complete s`[unfolded complete_def] using LIMSEQ_imp_Cauchy[of f x] by auto
hoelzl@42841
  3526
    hence "x \<in> s"  using tendsto_unique[of sequentially f l x] trivial_limit_sequentially f(2) by auto
himmelma@33175
  3527
  }
himmelma@33175
  3528
  thus "closed s" unfolding closed_limpt by auto
himmelma@33175
  3529
qed
himmelma@33175
  3530
himmelma@33175
  3531
lemma complete_eq_closed:
himmelma@33175
  3532
  fixes s :: "'a::complete_space set"
himmelma@33175
  3533
  shows "complete s \<longleftrightarrow> closed s" (is "?lhs = ?rhs")
himmelma@33175
  3534
proof
himmelma@33175
  3535
  assume ?lhs thus ?rhs by (rule complete_imp_closed)
himmelma@33175
  3536
next
himmelma@33175
  3537
  assume ?rhs
himmelma@33175
  3538
  { fix f assume as:"\<forall>n::nat. f n \<in> s" "Cauchy f"
himmelma@33175
  3539
    then obtain l where "(f ---> l) sequentially" using complete_univ[unfolded complete_def, THEN spec[where x=f]] by auto
himmelma@33175
  3540
    hence "\<exists>l\<in>s. (f ---> l) sequentially" using `?rhs`[unfolded closed_sequential_limits, THEN spec[where x=f], THEN spec[where x=l]] using as(1) by auto  }
himmelma@33175
  3541
  thus ?lhs unfolding complete_def by auto
himmelma@33175
  3542
qed
himmelma@33175
  3543
himmelma@33175
  3544
lemma convergent_eq_cauchy:
himmelma@33175
  3545
  fixes s :: "nat \<Rightarrow> 'a::complete_space"
huffman@45490
  3546
  shows "(\<exists>l. (s ---> l) sequentially) \<longleftrightarrow> Cauchy s"
huffman@45490
  3547
  unfolding Cauchy_convergent_iff convergent_def ..
himmelma@33175
  3548
himmelma@33175
  3549
lemma convergent_imp_bounded:
himmelma@33175
  3550
  fixes s :: "nat \<Rightarrow> 'a::metric_space"
huffman@45490
  3551
  shows "(s ---> l) sequentially \<Longrightarrow> bounded (range s)"
hoelzl@51954
  3552
  by (intro cauchy_imp_bounded LIMSEQ_imp_Cauchy)
himmelma@33175
  3553
immler@51102
  3554
lemma nat_approx_posE:
immler@51102
  3555
  fixes e::real
immler@51102
  3556
  assumes "0 < e"
immler@51102
  3557
  obtains n::nat where "1 / (Suc n) < e"
immler@51102
  3558
proof atomize_elim
immler@51102
  3559
  have " 1 / real (Suc (nat (ceiling (1/e)))) < 1 / (ceiling (1/e))"
immler@51102
  3560
    by (rule divide_strict_left_mono) (auto intro!: mult_pos_pos simp: `0 < e`)
immler@51102
  3561
  also have "1 / (ceiling (1/e)) \<le> 1 / (1/e)"
immler@51102
  3562
    by (rule divide_left_mono) (auto intro!: divide_pos_pos simp: `0 < e`)
immler@51102
  3563
  also have "\<dots> = e" by simp
immler@51102
  3564
  finally show  "\<exists>n. 1 / real (Suc n) < e" ..
immler@51102
  3565
qed
immler@51102
  3566
immler@51102
  3567
lemma compact_eq_totally_bounded:
hoelzl@51899
  3568
  "compact s \<longleftrightarrow> complete s \<and> (\<forall>e>0. \<exists>k. finite k \<and> s \<subseteq> (\<Union>((\<lambda>x. ball x e) ` k)))"
hoelzl@51899
  3569
proof (safe intro!: seq_compact_imp_complete[unfolded  compact_eq_seq_compact_metric[symmetric]])
immler@51102
  3570
  fix e::real
immler@51102
  3571
  def f \<equiv> "(\<lambda>x::'a. ball x e) ` UNIV"
immler@51102
  3572
  assume "0 < e" "compact s"
immler@51102
  3573
  hence "(\<forall>t\<in>f. open t) \<and> s \<subseteq> \<Union>f \<longrightarrow> (\<exists>f'\<subseteq>f. finite f' \<and> s \<subseteq> \<Union>f')"
immler@51102
  3574
    by (simp add: compact_eq_heine_borel)
immler@51102
  3575
  moreover
immler@51102
  3576
  have d0: "\<And>x::'a. dist x x < e" using `0 < e` by simp
immler@51102
  3577
  hence "(\<forall>t\<in>f. open t) \<and> s \<subseteq> \<Union>f" by (auto simp: f_def intro!: d0)
immler@51102
  3578
  ultimately have "(\<exists>f'\<subseteq>f. finite f' \<and> s \<subseteq> \<Union>f')" ..
immler@51102
  3579
  then guess K .. note K = this
immler@51102
  3580
  have "\<forall>K'\<in>K. \<exists>k. K' = ball k e" using K by (auto simp: f_def)
immler@51102
  3581
  then obtain k where "\<And>K'. K' \<in> K \<Longrightarrow> K' = ball (k K') e" unfolding bchoice_iff by blast
immler@51102
  3582
  thus "\<exists>k. finite k \<and> s \<subseteq> \<Union>(\<lambda>x. ball x e) ` k" using K
immler@51102
  3583
    by (intro exI[where x="k ` K"]) (auto simp: f_def)
immler@51102
  3584
next
immler@51102
  3585
  assume assms: "complete s" "\<forall>e>0. \<exists>k. finite k \<and> s \<subseteq> \<Union>(\<lambda>x. ball x e) ` k"
immler@51102
  3586
  show "compact s"
immler@51102
  3587
  proof cases
immler@51102
  3588
    assume "s = {}" thus "compact s" by (simp add: compact_def)
immler@51102
  3589
  next
immler@51102
  3590
    assume "s \<noteq> {}"
immler@51102
  3591
    show ?thesis
immler@51102
  3592
      unfolding compact_def
immler@51102
  3593
    proof safe
immler@51102
  3594
      fix f::"nat \<Rightarrow> _" assume "\<forall>n. f n \<in> s" hence f: "\<And>n. f n \<in> s" by simp
immler@51102
  3595
      from assms have "\<forall>e. \<exists>k. e>0 \<longrightarrow> finite k \<and> s \<subseteq> (\<Union>((\<lambda>x. ball x e) ` k))" by simp
immler@51102
  3596
      then obtain K where
immler@51102
  3597
        K: "\<And>e. e > 0 \<Longrightarrow> finite (K e) \<and> s \<subseteq> (\<Union>((\<lambda>x. ball x e) ` (K e)))"
immler@51102
  3598
        unfolding choice_iff by blast
immler@51102
  3599
      {
immler@51102
  3600
        fix e::real and f' have f': "\<And>n::nat. (f o f') n \<in> s" using f by auto
immler@51102
  3601
        assume "e > 0"
immler@51102
  3602
        from K[OF this] have K: "finite (K e)" "s \<subseteq> (\<Union>((\<lambda>x. ball x e) ` (K e)))"
immler@51102
  3603
          by simp_all
immler@51102
  3604
        have "\<exists>k\<in>(K e). \<exists>r. subseq r \<and> (\<forall>i. (f o f' o r) i \<in> ball k e)"
immler@51102
  3605
        proof (rule ccontr)
immler@51102
  3606
          from K have "finite (K e)" "K e \<noteq> {}" "s \<subseteq> (\<Union>((\<lambda>x. ball x e) ` (K e)))"
immler@51102
  3607
            using `s \<noteq> {}`
immler@51102
  3608
            by auto
immler@51102
  3609
          moreover
immler@51102
  3610
          assume "\<not> (\<exists>k\<in>K e. \<exists>r. subseq r \<and> (\<forall>i. (f \<circ> f' o r) i \<in> ball k e))"
immler@51102
  3611
          hence "\<And>r k. k \<in> K e \<Longrightarrow> subseq r \<Longrightarrow> (\<exists>i. (f o f' o r) i \<notin> ball k e)" by simp
immler@51102
  3612
          ultimately
immler@51102
  3613
          show False using f'
immler@51102
  3614
          proof (induct arbitrary: s f f' rule: finite_ne_induct)
immler@51102
  3615
            case (singleton x)
immler@51102
  3616
            have "\<exists>i. (f \<circ> f' o id) i \<notin> ball x e" by (rule singleton) (auto simp: subseq_def)
immler@51102
  3617
            thus ?case using singleton by (auto simp: ball_def)
immler@51102
  3618
          next
immler@51102
  3619
            case (insert x A)
immler@51102
  3620
            show ?case
immler@51102
  3621
            proof cases
immler@51102
  3622
              have inf_ms: "infinite ((f o f') -` s)" using insert by (simp add: vimage_def)
immler@51102
  3623
              have "infinite ((f o f') -` \<Union>((\<lambda>x. ball x e) ` (insert x A)))"
immler@51102
  3624
                using insert by (intro infinite_super[OF _ inf_ms]) auto
immler@51102
  3625
              also have "((f o f') -` \<Union>((\<lambda>x. ball x e) ` (insert x A))) =
immler@51102
  3626
                {m. (f o f') m \<in> ball x e} \<union> {m. (f o f') m \<in> \<Union>((\<lambda>x. ball x e) ` A)}" by auto
immler@51102
  3627
              finally have "infinite \<dots>" .
immler@51102
  3628
              moreover assume "finite {m. (f o f') m \<in> ball x e}"
immler@51102
  3629
              ultimately have inf: "infinite {m. (f o f') m \<in> \<Union>((\<lambda>x. ball x e) ` A)}" by blast
immler@51102
  3630
              hence "A \<noteq> {}" by auto then obtain k where "k \<in> A" by auto
immler@51102
  3631
              def r \<equiv> "enumerate {m. (f o f') m \<in> \<Union>((\<lambda>x. ball x e) ` A)}"
immler@51102
  3632
              have r_mono: "\<And>n m. n < m \<Longrightarrow> r n < r m"
immler@51102
  3633
                using enumerate_mono[OF _ inf] by (simp add: r_def)
immler@51102
  3634
              hence "subseq r" by (simp add: subseq_def)
immler@51102
  3635
              have r_in_set: "\<And>n. r n \<in> {m. (f o f') m \<in> \<Union>((\<lambda>x. ball x e) ` A)}"
immler@51102
  3636
                using enumerate_in_set[OF inf] by (simp add: r_def)
immler@51102
  3637
              show False
immler@51102
  3638
              proof (rule insert)
immler@51102
  3639
                show "\<Union>(\<lambda>x. ball x e) ` A \<subseteq> \<Union>(\<lambda>x. ball x e) ` A" by simp
immler@51102
  3640
                fix k s assume "k \<in> A" "subseq s"
immler@51102
  3641
                thus "\<exists>i. (f o f' o r o s) i \<notin> ball k e" using `subseq r`
immler@51102
  3642
                  by (subst (2) o_assoc[symmetric]) (intro insert(6) subseq_o, simp_all)
immler@51102
  3643
              next
immler@51102
  3644
                fix n show "(f \<circ> f' o r) n \<in> \<Union>(\<lambda>x. ball x e) ` A" using r_in_set by auto
immler@51102
  3645
              qed
immler@51102
  3646
            next
immler@51102
  3647
              assume inf: "infinite {m. (f o f') m \<in> ball x e}"
immler@51102
  3648
              def r \<equiv> "enumerate {m. (f o f') m \<in> ball x e}"
immler@51102
  3649
              have r_mono: "\<And>n m. n < m \<Longrightarrow> r n < r m"
immler@51102
  3650
                using enumerate_mono[OF _ inf] by (simp add: r_def)
immler@51102
  3651
              hence "subseq r" by (simp add: subseq_def)
immler@51102
  3652
              from insert(6)[OF insertI1 this] obtain i where "(f o f') (r i) \<notin> ball x e" by auto
immler@51102
  3653
              moreover
immler@51102
  3654
              have r_in_set: "\<And>n. r n \<in> {m. (f o f') m \<in> ball x e}"
immler@51102
  3655
                using enumerate_in_set[OF inf] by (simp add: r_def)
immler@51102
  3656
              hence "(f o f') (r i) \<in> ball x e" by simp
immler@51102
  3657
              ultimately show False by simp
immler@51102
  3658
            qed
immler@51102
  3659
          qed
immler@51102
  3660
        qed
immler@51102
  3661
      }
immler@51102
  3662
      hence ex: "\<forall>f'. \<forall>e > 0. (\<exists>k\<in>K e. \<exists>r. subseq r \<and> (\<forall>i. (f o f' \<circ> r) i \<in> ball k e))" by simp
immler@51102
  3663
      let ?e = "\<lambda>n. 1 / real (Suc n)"
immler@51102
  3664
      let ?P = "\<lambda>n s. \<exists>k\<in>K (?e n). (\<forall>i. (f o s) i \<in> ball k (?e n))"
immler@51102
  3665
      interpret subseqs ?P using ex by unfold_locales force
immler@51102
  3666
      from `complete s` have limI: "\<And>f. (\<And>n. f n \<in> s) \<Longrightarrow> Cauchy f \<Longrightarrow> (\<exists>l\<in>s. f ----> l)"
immler@51102
  3667
        by (simp add: complete_def)
immler@51102
  3668
      have "\<exists>l\<in>s. (f o diagseq) ----> l"
immler@51102
  3669
      proof (intro limI metric_CauchyI)
immler@51102
  3670
        fix e::real assume "0 < e" hence "0 < e / 2" by auto
immler@51102
  3671
        from nat_approx_posE[OF this] guess n . note n = this
immler@51102
  3672
        show "\<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. dist ((f \<circ> diagseq) m) ((f \<circ> diagseq) n) < e"
immler@51102
  3673
        proof (rule exI[where x="Suc n"], safe)
immler@51102
  3674
          fix m mm assume "Suc n \<le> m" "Suc n \<le> mm"
immler@51102
  3675
          let ?e = "1 / real (Suc n)"
immler@51102
  3676
          from reducer_reduces[of n] obtain k where
immler@51102
  3677
            "k\<in>K ?e"  "\<And>i. (f o seqseq (Suc n)) i \<in> ball k ?e"
immler@51102
  3678
            unfolding seqseq_reducer by auto
immler@51102
  3679
          moreover
immler@51102
  3680
          note diagseq_sub[OF `Suc n \<le> m`] diagseq_sub[OF `Suc n \<le> mm`]
immler@51102
  3681
          ultimately have "{(f o diagseq) m, (f o diagseq) mm} \<subseteq> ball k ?e" by auto
immler@51102
  3682
          also have "\<dots> \<subseteq> ball k (e / 2)" using n by (intro subset_ball) simp
immler@51102
  3683
          finally
immler@51102
  3684
          have "dist k ((f \<circ> diagseq) m) + dist k ((f \<circ> diagseq) mm) < e / 2 + e /2"
immler@51102
  3685
            by (intro add_strict_mono) auto
immler@51102
  3686
          hence "dist ((f \<circ> diagseq) m) k + dist ((f \<circ> diagseq) mm) k < e"
immler@51102
  3687
            by (simp add: dist_commute)
immler@51102
  3688
          moreover have "dist ((f \<circ> diagseq) m) ((f \<circ> diagseq) mm) \<le>
immler@51102
  3689
            dist ((f \<circ> diagseq) m) k + dist ((f \<circ> diagseq) mm) k"
immler@51102
  3690
            by (rule dist_triangle2)
immler@51102
  3691
          ultimately show "dist ((f \<circ> diagseq) m) ((f \<circ> diagseq) mm) < e"
immler@51102
  3692
            by simp
immler@51102
  3693
        qed
immler@51102
  3694
      next
immler@51102
  3695
        fix n show "(f o diagseq) n \<in> s" using f by simp
immler@51102
  3696
      qed
immler@51102
  3697
      thus "\<exists>l\<in>s. \<exists>r. subseq r \<and> (f \<circ> r) ----> l" using subseq_diagseq by auto
immler@51102
  3698
    qed
immler@51102
  3699
  qed
immler@51102
  3700
qed
immler@51102
  3701
himmelma@33175
  3702
lemma compact_cball[simp]:
himmelma@33175
  3703
  fixes x :: "'a::heine_borel"
himmelma@33175
  3704
  shows "compact(cball x e)"
himmelma@33175
  3705
  using compact_eq_bounded_closed bounded_cball closed_cball
himmelma@33175
  3706
  by blast
himmelma@33175
  3707
himmelma@33175
  3708
lemma compact_frontier_bounded[intro]:
himmelma@33175
  3709
  fixes s :: "'a::heine_borel set"
himmelma@33175
  3710
  shows "bounded s ==> compact(frontier s)"
himmelma@33175
  3711
  unfolding frontier_def
himmelma@33175
  3712
  using compact_eq_bounded_closed
himmelma@33175
  3713
  by blast
himmelma@33175
  3714
himmelma@33175
  3715
lemma compact_frontier[intro]:
himmelma@33175
  3716
  fixes s :: "'a::heine_borel set"
himmelma@33175
  3717
  shows "compact s ==> compact (frontier s)"
himmelma@33175
  3718
  using compact_eq_bounded_closed compact_frontier_bounded
himmelma@33175
  3719
  by blast
himmelma@33175
  3720
himmelma@33175
  3721
lemma frontier_subset_compact:
himmelma@33175
  3722
  fixes s :: "'a::heine_borel set"
himmelma@33175
  3723
  shows "compact s ==> frontier s \<subseteq> s"
himmelma@33175
  3724
  using frontier_subset_closed compact_eq_bounded_closed
himmelma@33175
  3725
  by blast
himmelma@33175
  3726
huffman@45081
  3727
subsection {* Bounded closed nest property (proof does not use Heine-Borel) *}
himmelma@33175
  3728
himmelma@33175
  3729
lemma bounded_closed_nest:
himmelma@33175
  3730
  assumes "\<forall>n. closed(s n)" "\<forall>n. (s n \<noteq> {})"
himmelma@33175
  3731
  "(\<forall>m n. m \<le> n --> s n \<subseteq> s m)"  "bounded(s 0)"
himmelma@33175
  3732
  shows "\<exists>a::'a::heine_borel. \<forall>n::nat. a \<in> s(n)"
himmelma@33175
  3733
proof-
himmelma@33175
  3734
  from assms(2) obtain x where x:"\<forall>n::nat. x n \<in> s n" using choice[of "\<lambda>n x. x\<in> s n"] by auto
hoelzl@51899
  3735
  from assms(4,1) have *:"seq_compact (s 0)" using bounded_closed_imp_seq_compact[of "s 0"] by auto
himmelma@33175
  3736
himmelma@33175
  3737
  then obtain l r where lr:"l\<in>s 0" "subseq r" "((x \<circ> r) ---> l) sequentially"
hoelzl@51899
  3738
    unfolding seq_compact_def apply(erule_tac x=x in allE)  using x using assms(3) by blast
himmelma@33175
  3739
himmelma@33175
  3740
  { fix n::nat
himmelma@33175
  3741
    { fix e::real assume "e>0"
huffman@45778
  3742
      with lr(3) obtain N where N:"\<forall>m\<ge>N. dist ((x \<circ> r) m) l < e" unfolding LIMSEQ_def by auto
himmelma@33175
  3743
      hence "dist ((x \<circ> r) (max N n)) l < e" by auto
himmelma@33175
  3744
      moreover
hoelzl@51952
  3745
      have "r (max N n) \<ge> n" using lr(2) using seq_suble[of r "max N n"] by auto
himmelma@33175
  3746
      hence "(x \<circ> r) (max N n) \<in> s n"
himmelma@33175
  3747
        using x apply(erule_tac x=n in allE)
himmelma@33175
  3748
        using x apply(erule_tac x="r (max N n)" in allE)
hoelzl@51899
  3749
        using assms(3) apply(erule_tac x=n in allE) apply(erule_tac x="r (max N n)" in allE) by auto
himmelma@33175
  3750
      ultimately have "\<exists>y\<in>s n. dist y l < e" by auto
himmelma@33175
  3751
    }
himmelma@33175
  3752
    hence "l \<in> s n" using closed_approachable[of "s n" l] assms(1) by blast
himmelma@33175
  3753
  }
himmelma@33175
  3754
  thus ?thesis by auto
himmelma@33175
  3755
qed
himmelma@33175
  3756
huffman@45081
  3757
text {* Decreasing case does not even need compactness, just completeness. *}
himmelma@33175
  3758
himmelma@33175
  3759
lemma decreasing_closed_nest:
himmelma@33175
  3760
  assumes "\<forall>n. closed(s n)"
himmelma@33175
  3761
          "\<forall>n. (s n \<noteq> {})"
himmelma@33175
  3762
          "\<forall>m n. m \<le> n --> s n \<subseteq> s m"
himmelma@33175
  3763
          "\<forall>e>0. \<exists>n. \<forall>x \<in> (s n). \<forall> y \<in> (s n). dist x y < e"
huffman@45490
  3764
  shows "\<exists>a::'a::complete_space. \<forall>n::nat. a \<in> s n"
himmelma@33175
  3765
proof-
himmelma@33175
  3766
  have "\<forall>n. \<exists> x. x\<in>s n" using assms(2) by auto
himmelma@33175
  3767
  hence "\<exists>t. \<forall>n. t n \<in> s n" using choice[of "\<lambda> n x. x \<in> s n"] by auto
himmelma@33175
  3768
  then obtain t where t: "\<forall>n. t n \<in> s n" by auto
himmelma@33175
  3769
  { fix e::real assume "e>0"
himmelma@33175
  3770
    then obtain N where N:"\<forall>x\<in>s N. \<forall>y\<in>s N. dist x y < e" using assms(4) by auto
himmelma@33175
  3771
    { fix m n ::nat assume "N \<le> m \<and> N \<le> n"
himmelma@33175
  3772
      hence "t m \<in> s N" "t n \<in> s N" using assms(3) t unfolding  subset_eq t by blast+
himmelma@33175
  3773
      hence "dist (t m) (t n) < e" using N by auto
himmelma@33175
  3774
    }
himmelma@33175
  3775
    hence "\<exists>N. \<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (t m) (t n) < e" by auto
himmelma@33175
  3776
  }
himmelma@33175
  3777
  hence  "Cauchy t" unfolding cauchy_def by auto
himmelma@33175
  3778
  then obtain l where l:"(t ---> l) sequentially" using complete_univ unfolding complete_def by auto
himmelma@33175
  3779
  { fix n::nat
himmelma@33175
  3780
    { fix e::real assume "e>0"
huffman@45778
  3781
      then obtain N::nat where N:"\<forall>n\<ge>N. dist (t n) l < e" using l[unfolded LIMSEQ_def] by auto
himmelma@33175
  3782
      have "t (max n N) \<in> s n" using assms(3) unfolding subset_eq apply(erule_tac x=n in allE) apply (erule_tac x="max n N" in allE) using t by auto
himmelma@33175
  3783
      hence "\<exists>y\<in>s n. dist y l < e" apply(rule_tac x="t (max n N)" in bexI) using N by auto
himmelma@33175
  3784
    }
himmelma@33175
  3785
    hence "l \<in> s n" using closed_approachable[of "s n" l] assms(1) by auto
himmelma@33175
  3786
  }
himmelma@33175
  3787
  then show ?thesis by auto
himmelma@33175
  3788
qed
himmelma@33175
  3789
huffman@45081
  3790
text {* Strengthen it to the intersection actually being a singleton. *}
himmelma@33175
  3791
himmelma@33175
  3792
lemma decreasing_closed_nest_sing:
huffman@45490
  3793
  fixes s :: "nat \<Rightarrow> 'a::complete_space set"
himmelma@33175
  3794
  assumes "\<forall>n. closed(s n)"
himmelma@33175
  3795
          "\<forall>n. s n \<noteq> {}"
himmelma@33175
  3796
          "\<forall>m n. m \<le> n --> s n \<subseteq> s m"
himmelma@33175
  3797
          "\<forall>e>0. \<exists>n. \<forall>x \<in> (s n). \<forall> y\<in>(s n). dist x y < e"
huffman@34098
  3798
  shows "\<exists>a. \<Inter>(range s) = {a}"
himmelma@33175
  3799
proof-
himmelma@33175
  3800
  obtain a where a:"\<forall>n. a \<in> s n" using decreasing_closed_nest[of s] using assms by auto
huffman@34098
  3801
  { fix b assume b:"b \<in> \<Inter>(range s)"
himmelma@33175
  3802
    { fix e::real assume "e>0"
himmelma@33175
  3803
      hence "dist a b < e" using assms(4 )using b using a by blast
himmelma@33175
  3804
    }
huffman@36770
  3805
    hence "dist a b = 0" by (metis dist_eq_0_iff dist_nz less_le)
himmelma@33175
  3806
  }
huffman@34098
  3807
  with a have "\<Inter>(range s) = {a}" unfolding image_def by auto
huffman@34098
  3808
  thus ?thesis ..
himmelma@33175
  3809
qed
himmelma@33175
  3810
himmelma@33175
  3811
text{* Cauchy-type criteria for uniform convergence. *}
himmelma@33175
  3812
himmelma@33175
  3813
lemma uniformly_convergent_eq_cauchy: fixes s::"nat \<Rightarrow> 'b \<Rightarrow> 'a::heine_borel" shows
himmelma@33175
  3814
 "(\<exists>l. \<forall>e>0. \<exists>N. \<forall>n x. N \<le> n \<and> P x --> dist(s n x)(l x) < e) \<longleftrightarrow>
himmelma@33175
  3815
  (\<forall>e>0. \<exists>N. \<forall>m n x. N \<le> m \<and> N \<le> n \<and> P x  --> dist (s m x) (s n x) < e)" (is "?lhs = ?rhs")
himmelma@33175
  3816
proof(rule)
himmelma@33175
  3817
  assume ?lhs
himmelma@33175
  3818
  then obtain l where l:"\<forall>e>0. \<exists>N. \<forall>n x. N \<le> n \<and> P x \<longrightarrow> dist (s n x) (l x) < e" by auto
himmelma@33175
  3819
  { fix e::real assume "e>0"
himmelma@33175
  3820
    then obtain N::nat where N:"\<forall>n x. N \<le> n \<and> P x \<longrightarrow> dist (s n x) (l x) < e / 2" using l[THEN spec[where x="e/2"]] by auto
himmelma@33175
  3821
    { fix n m::nat and x::"'b" assume "N \<le> m \<and> N \<le> n \<and> P x"
himmelma@33175
  3822
      hence "dist (s m x) (s n x) < e"
himmelma@33175
  3823
        using N[THEN spec[where x=m], THEN spec[where x=x]]
himmelma@33175
  3824
        using N[THEN spec[where x=n], THEN spec[where x=x]]
himmelma@33175
  3825
        using dist_triangle_half_l[of "s m x" "l x" e "s n x"] by auto  }
himmelma@33175
  3826
    hence "\<exists>N. \<forall>m n x. N \<le> m \<and> N \<le> n \<and> P x  --> dist (s m x) (s n x) < e"  by auto  }
himmelma@33175
  3827
  thus ?rhs by auto
himmelma@33175
  3828
next
himmelma@33175
  3829
  assume ?rhs
himmelma@33175
  3830
  hence "\<forall>x. P x \<longrightarrow> Cauchy (\<lambda>n. s n x)" unfolding cauchy_def apply auto by (erule_tac x=e in allE)auto
himmelma@33175
  3831
  then obtain l where l:"\<forall>x. P x \<longrightarrow> ((\<lambda>n. s n x) ---> l x) sequentially" unfolding convergent_eq_cauchy[THEN sym]
himmelma@33175
  3832
    using choice[of "\<lambda>x l. P x \<longrightarrow> ((\<lambda>n. s n x) ---> l) sequentially"] by auto
himmelma@33175
  3833
  { fix e::real assume "e>0"
himmelma@33175
  3834
    then obtain N where N:"\<forall>m n x. N \<le> m \<and> N \<le> n \<and> P x \<longrightarrow> dist (s m x) (s n x) < e/2"
himmelma@33175
  3835
      using `?rhs`[THEN spec[where x="e/2"]] by auto
himmelma@33175
  3836
    { fix x assume "P x"
himmelma@33175
  3837
      then obtain M where M:"\<forall>n\<ge>M. dist (s n x) (l x) < e/2"
huffman@45778
  3838
        using l[THEN spec[where x=x], unfolded LIMSEQ_def] using `e>0` by(auto elim!: allE[where x="e/2"])
himmelma@33175
  3839
      fix n::nat assume "n\<ge>N"
himmelma@33175
  3840
      hence "dist(s n x)(l x) < e"  using `P x`and N[THEN spec[where x=n], THEN spec[where x="N+M"], THEN spec[where x=x]]
himmelma@33175
  3841
        using M[THEN spec[where x="N+M"]] and dist_triangle_half_l[of "s n x" "s (N+M) x" e "l x"] by (auto simp add: dist_commute)  }
himmelma@33175
  3842
    hence "\<exists>N. \<forall>n x. N \<le> n \<and> P x \<longrightarrow> dist(s n x)(l x) < e" by auto }
himmelma@33175
  3843
  thus ?lhs by auto
himmelma@33175
  3844
qed
himmelma@33175
  3845
himmelma@33175
  3846
lemma uniformly_cauchy_imp_uniformly_convergent:
himmelma@33175
  3847
  fixes s :: "nat \<Rightarrow> 'a \<Rightarrow> 'b::heine_borel"
himmelma@33175
  3848
  assumes "\<forall>e>0.\<exists>N. \<forall>m (n::nat) x. N \<le> m \<and> N \<le> n \<and> P x --> dist(s m x)(s n x) < e"
himmelma@33175
  3849
          "\<forall>x. P x --> (\<forall>e>0. \<exists>N. \<forall>n. N \<le> n --> dist(s n x)(l x) < e)"
himmelma@33175
  3850
  shows "\<forall>e>0. \<exists>N. \<forall>n x. N \<le> n \<and> P x --> dist(s n x)(l x) < e"
himmelma@33175
  3851
proof-
himmelma@33175
  3852
  obtain l' where l:"\<forall>e>0. \<exists>N. \<forall>n x. N \<le> n \<and> P x \<longrightarrow> dist (s n x) (l' x) < e"
himmelma@33175
  3853
    using assms(1) unfolding uniformly_convergent_eq_cauchy[THEN sym] by auto
himmelma@33175
  3854
  moreover
himmelma@33175
  3855
  { fix x assume "P x"
hoelzl@42841
  3856
    hence "l x = l' x" using tendsto_unique[OF trivial_limit_sequentially, of "\<lambda>n. s n x" "l x" "l' x"]
huffman@45778
  3857
      using l and assms(2) unfolding LIMSEQ_def by blast  }
himmelma@33175
  3858
  ultimately show ?thesis by auto
himmelma@33175
  3859
qed
himmelma@33175
  3860
huffman@45081
  3861
huffman@36433
  3862
subsection {* Continuity *}
huffman@36433
  3863
huffman@36433
  3864
text {* Define continuity over a net to take in restrictions of the set. *}
himmelma@33175
  3865
himmelma@33175
  3866
definition
huffman@44952
  3867
  continuous :: "'a::t2_space filter \<Rightarrow> ('a \<Rightarrow> 'b::topological_space) \<Rightarrow> bool"
huffman@44952
  3868
  where "continuous net f \<longleftrightarrow> (f ---> f(netlimit net)) net"
himmelma@33175
  3869
himmelma@33175
  3870
lemma continuous_trivial_limit:
himmelma@33175
  3871
 "trivial_limit net ==> continuous net f"
himmelma@33175
  3872
  unfolding continuous_def tendsto_def trivial_limit_eq by auto
himmelma@33175
  3873
himmelma@33175
  3874
lemma continuous_within: "continuous (at x within s) f \<longleftrightarrow> (f ---> f(x)) (at x within s)"
himmelma@33175
  3875
  unfolding continuous_def
himmelma@33175
  3876
  unfolding tendsto_def
himmelma@33175
  3877
  using netlimit_within[of x s]
himmelma@33175
  3878
  by (cases "trivial_limit (at x within s)") (auto simp add: trivial_limit_eventually)
himmelma@33175
  3879
himmelma@33175
  3880
lemma continuous_at: "continuous (at x) f \<longleftrightarrow> (f ---> f(x)) (at x)"
huffman@45896
  3881
  using continuous_within [of x UNIV f] by simp
himmelma@33175
  3882
himmelma@33175
  3883
lemma continuous_at_within:
himmelma@33175
  3884
  assumes "continuous (at x) f"  shows "continuous (at x within s) f"
himmelma@33175
  3885
  using assms unfolding continuous_at continuous_within
himmelma@33175
  3886
  by (rule Lim_at_within)
himmelma@33175
  3887
himmelma@33175
  3888
text{* Derive the epsilon-delta forms, which we often use as "definitions" *}
himmelma@33175
  3889
himmelma@33175
  3890
lemma continuous_within_eps_delta:
himmelma@33175
  3891
  "continuous (at x within s) f \<longleftrightarrow> (\<forall>e>0. \<exists>d>0. \<forall>x'\<in> s.  dist x' x < d --> dist (f x') (f x) < e)"
himmelma@33175
  3892
  unfolding continuous_within and Lim_within
huffman@45448
  3893
  apply auto unfolding dist_nz[THEN sym] apply(auto del: allE elim!:allE) apply(rule_tac x=d in exI) by auto
himmelma@33175
  3894
himmelma@33175
  3895
lemma continuous_at_eps_delta: "continuous (at x) f \<longleftrightarrow>  (\<forall>e>0. \<exists>d>0.
himmelma@33175
  3896
                           \<forall>x'. dist x' x < d --> dist(f x')(f x) < e)"
huffman@45896
  3897
  using continuous_within_eps_delta [of x UNIV f] by simp
himmelma@33175
  3898
himmelma@33175
  3899
text{* Versions in terms of open balls. *}
himmelma@33175
  3900
himmelma@33175
  3901
lemma continuous_within_ball:
himmelma@33175
  3902
 "continuous (at x within s) f \<longleftrightarrow> (\<forall>e>0. \<exists>d>0.
himmelma@33175
  3903
                            f ` (ball x d \<inter> s) \<subseteq> ball (f x) e)" (is "?lhs = ?rhs")
himmelma@33175
  3904
proof
himmelma@33175
  3905
  assume ?lhs
himmelma@33175
  3906
  { fix e::real assume "e>0"
himmelma@33175
  3907
    then obtain d where d: "d>0" "\<forall>xa\<in>s. 0 < dist xa x \<and> dist xa x < d \<longrightarrow> dist (f xa) (f x) < e"
himmelma@33175
  3908
      using `?lhs`[unfolded continuous_within Lim_within] by auto
himmelma@33175
  3909
    { fix y assume "y\<in>f ` (ball x d \<inter> s)"
himmelma@33175
  3910
      hence "y \<in> ball (f x) e" using d(2) unfolding dist_nz[THEN sym]
huffman@36358
  3911
        apply (auto simp add: dist_commute) apply(erule_tac x=xa in ballE) apply auto using `e>0` by auto
himmelma@33175
  3912
    }
himmelma@33175
  3913
    hence "\<exists>d>0. f ` (ball x d \<inter> s) \<subseteq> ball (f x) e" using `d>0` unfolding subset_eq ball_def by (auto simp add: dist_commute)  }
himmelma@33175
  3914
  thus ?rhs by auto
himmelma@33175
  3915
next
himmelma@33175
  3916
  assume ?rhs thus ?lhs unfolding continuous_within Lim_within ball_def subset_eq
himmelma@33175
  3917
    apply (auto simp add: dist_commute) apply(erule_tac x=e in allE) by auto
himmelma@33175
  3918
qed
himmelma@33175
  3919
himmelma@33175
  3920
lemma continuous_at_ball:
himmelma@33175
  3921
  "continuous (at x) f \<longleftrightarrow> (\<forall>e>0. \<exists>d>0. f ` (ball x d) \<subseteq> ball (f x) e)" (is "?lhs = ?rhs")
himmelma@33175
  3922
proof
himmelma@33175
  3923
  assume ?lhs thus ?rhs unfolding continuous_at Lim_at subset_eq Ball_def Bex_def image_iff mem_ball
himmelma@33175
  3924
    apply auto apply(erule_tac x=e in allE) apply auto apply(rule_tac x=d in exI) apply auto apply(erule_tac x=xa in allE) apply (auto simp add: dist_commute dist_nz)
himmelma@33175
  3925
    unfolding dist_nz[THEN sym] by auto
himmelma@33175
  3926
next
himmelma@33175
  3927
  assume ?rhs thus ?lhs unfolding continuous_at Lim_at subset_eq Ball_def Bex_def image_iff mem_ball
himmelma@33175
  3928
    apply auto apply(erule_tac x=e in allE) apply auto apply(rule_tac x=d in exI) apply auto apply(erule_tac x="f xa" in allE) by (auto simp add: dist_commute dist_nz)
himmelma@33175
  3929
qed
himmelma@33175
  3930
huffman@36436
  3931
text{* Define setwise continuity in terms of limits within the set. *}
himmelma@33175
  3932
himmelma@33175
  3933
definition
huffman@36355
  3934
  continuous_on ::
huffman@36355
  3935
    "'a set \<Rightarrow> ('a::topological_space \<Rightarrow> 'b::topological_space) \<Rightarrow> bool"
huffman@36355
  3936
where
huffman@36436
  3937
  "continuous_on s f \<longleftrightarrow> (\<forall>x\<in>s. (f ---> f x) (at x within s))"
huffman@36436
  3938
huffman@36436
  3939
lemma continuous_on_topological:
huffman@36355
  3940
  "continuous_on s f \<longleftrightarrow>
huffman@36355
  3941
    (\<forall>x\<in>s. \<forall>B. open B \<longrightarrow> f x \<in> B \<longrightarrow>
huffman@36436
  3942
      (\<exists>A. open A \<and> x \<in> A \<and> (\<forall>y\<in>s. y \<in> A \<longrightarrow> f y \<in> B)))"
huffman@36436
  3943
unfolding continuous_on_def tendsto_def
huffman@36436
  3944
unfolding Limits.eventually_within eventually_at_topological
huffman@36436
  3945
by (intro ball_cong [OF refl] all_cong imp_cong ex_cong conj_cong refl) auto
huffman@36355
  3946
huffman@36355
  3947
lemma continuous_on_iff:
huffman@36355
  3948
  "continuous_on s f \<longleftrightarrow>
huffman@36436
  3949
    (\<forall>x\<in>s. \<forall>e>0. \<exists>d>0. \<forall>x'\<in>s. dist x' x < d \<longrightarrow> dist (f x') (f x) < e)"
huffman@36436
  3950
unfolding continuous_on_def Lim_within
huffman@36436
  3951
apply (intro ball_cong [OF refl] all_cong ex_cong)
huffman@36436
  3952
apply (rename_tac y, case_tac "y = x", simp)
huffman@36436
  3953
apply (simp add: dist_nz)
huffman@36355
  3954
done
himmelma@33175
  3955
himmelma@33175
  3956
definition
himmelma@33175
  3957
  uniformly_continuous_on ::
huffman@36436
  3958
    "'a set \<Rightarrow> ('a::metric_space \<Rightarrow> 'b::metric_space) \<Rightarrow> bool"
huffman@36436
  3959
where
himmelma@33175
  3960
  "uniformly_continuous_on s f \<longleftrightarrow>
huffman@36436
  3961
    (\<forall>e>0. \<exists>d>0. \<forall>x\<in>s. \<forall>x'\<in>s. dist x' x < d \<longrightarrow> dist (f x') (f x) < e)"
himmelma@35172
  3962
himmelma@33175
  3963
text{* Some simple consequential lemmas. *}
himmelma@33175
  3964
himmelma@33175
  3965
lemma uniformly_continuous_imp_continuous:
himmelma@33175
  3966
 " uniformly_continuous_on s f ==> continuous_on s f"
huffman@36355
  3967
  unfolding uniformly_continuous_on_def continuous_on_iff by blast
himmelma@33175
  3968
himmelma@33175
  3969
lemma continuous_at_imp_continuous_within:
himmelma@33175
  3970
 "continuous (at x) f ==> continuous (at x within s) f"
himmelma@33175
  3971
  unfolding continuous_within continuous_at using Lim_at_within by auto
himmelma@33175
  3972
huffman@36436
  3973
lemma Lim_trivial_limit: "trivial_limit net \<Longrightarrow> (f ---> l) net"
huffman@36436
  3974
unfolding tendsto_def by (simp add: trivial_limit_eq)
huffman@36436
  3975
huffman@36355
  3976
lemma continuous_at_imp_continuous_on:
huffman@36436
  3977
  assumes "\<forall>x\<in>s. continuous (at x) f"
himmelma@33175
  3978
  shows "continuous_on s f"
huffman@36436
  3979
unfolding continuous_on_def
huffman@36436
  3980
proof
huffman@36436
  3981
  fix x assume "x \<in> s"
huffman@36436
  3982
  with assms have *: "(f ---> f (netlimit (at x))) (at x)"
huffman@36436
  3983
    unfolding continuous_def by simp
huffman@36436
  3984
  have "(f ---> f x) (at x)"
huffman@36436
  3985
  proof (cases "trivial_limit (at x)")
huffman@36436
  3986
    case True thus ?thesis
huffman@36436
  3987
      by (rule Lim_trivial_limit)
huffman@36436
  3988
  next
huffman@36436
  3989
    case False
huffman@36667
  3990
    hence 1: "netlimit (at x) = x"
huffman@45896
  3991
      using netlimit_within [of x UNIV] by simp
huffman@36436
  3992
    with * show ?thesis by simp
huffman@36436
  3993
  qed
huffman@36436
  3994
  thus "(f ---> f x) (at x within s)"
huffman@36436
  3995
    by (rule Lim_at_within)
himmelma@33175
  3996
qed
himmelma@33175
  3997
himmelma@33175
  3998
lemma continuous_on_eq_continuous_within:
huffman@36436
  3999
  "continuous_on s f \<longleftrightarrow> (\<forall>x \<in> s. continuous (at x within s) f)"
huffman@36436
  4000
unfolding continuous_on_def continuous_def
huffman@36436
  4001
apply (rule ball_cong [OF refl])
huffman@36436
  4002
apply (case_tac "trivial_limit (at x within s)")
huffman@36436
  4003
apply (simp add: Lim_trivial_limit)
huffman@36436
  4004
apply (simp add: netlimit_within)
huffman@36436
  4005
done
huffman@36436
  4006
huffman@36436
  4007
lemmas continuous_on = continuous_on_def -- "legacy theorem name"
himmelma@33175
  4008
himmelma@33175
  4009
lemma continuous_on_eq_continuous_at:
huffman@36355
  4010
  shows "open s ==> (continuous_on s f \<longleftrightarrow> (\<forall>x \<in> s. continuous (at x) f))"
himmelma@33175
  4011
  by (auto simp add: continuous_on continuous_at Lim_within_open)
himmelma@33175
  4012
himmelma@33175
  4013
lemma continuous_within_subset:
himmelma@33175
  4014
 "continuous (at x within s) f \<Longrightarrow> t \<subseteq> s
himmelma@33175
  4015
             ==> continuous (at x within t) f"
himmelma@33175
  4016
  unfolding continuous_within by(metis Lim_within_subset)
himmelma@33175
  4017
himmelma@33175
  4018
lemma continuous_on_subset:
huffman@36355
  4019
  shows "continuous_on s f \<Longrightarrow> t \<subseteq> s ==> continuous_on t f"
himmelma@33175
  4020
  unfolding continuous_on by (metis subset_eq Lim_within_subset)
himmelma@33175
  4021
himmelma@33175
  4022
lemma continuous_on_interior:
huffman@45374
  4023
  shows "continuous_on s f \<Longrightarrow> x \<in> interior s \<Longrightarrow> continuous (at x) f"
huffman@45374
  4024
  by (erule interiorE, drule (1) continuous_on_subset,
huffman@45374
  4025
    simp add: continuous_on_eq_continuous_at)
himmelma@33175
  4026
himmelma@33175
  4027
lemma continuous_on_eq:
huffman@36436
  4028
  "(\<forall>x \<in> s. f x = g x) \<Longrightarrow> continuous_on s f \<Longrightarrow> continuous_on s g"
huffman@36436
  4029
  unfolding continuous_on_def tendsto_def Limits.eventually_within
huffman@36436
  4030
  by simp
himmelma@33175
  4031
huffman@45081
  4032
text {* Characterization of various kinds of continuity in terms of sequences. *}
himmelma@33175
  4033
himmelma@33175
  4034
lemma continuous_within_sequentially:
huffman@45388
  4035
  fixes f :: "'a::metric_space \<Rightarrow> 'b::topological_space"
himmelma@33175
  4036
  shows "continuous (at a within s) f \<longleftrightarrow>
himmelma@33175
  4037
                (\<forall>x. (\<forall>n::nat. x n \<in> s) \<and> (x ---> a) sequentially
himmelma@33175
  4038
                     --> ((f o x) ---> f a) sequentially)" (is "?lhs = ?rhs")
himmelma@33175
  4039
proof
himmelma@33175
  4040
  assume ?lhs
huffman@45388
  4041
  { fix x::"nat \<Rightarrow> 'a" assume x:"\<forall>n. x n \<in> s" "\<forall>e>0. eventually (\<lambda>n. dist (x n) a < e) sequentially"
huffman@45388
  4042
    fix T::"'b set" assume "open T" and "f a \<in> T"
huffman@45388
  4043
    with `?lhs` obtain d where "d>0" and d:"\<forall>x\<in>s. 0 < dist x a \<and> dist x a < d \<longrightarrow> f x \<in> T"
huffman@45388
  4044
      unfolding continuous_within tendsto_def eventually_within by auto
huffman@45388
  4045
    have "eventually (\<lambda>n. dist (x n) a < d) sequentially"
huffman@45388
  4046
      using x(2) `d>0` by simp
huffman@45388
  4047
    hence "eventually (\<lambda>n. (f \<circ> x) n \<in> T) sequentially"
noschinl@47755
  4048
    proof eventually_elim
noschinl@47755
  4049
      case (elim n) thus ?case
huffman@45388
  4050
        using d x(1) `f a \<in> T` unfolding dist_nz[THEN sym] by auto
huffman@45388
  4051
    qed
himmelma@33175
  4052
  }
huffman@45388
  4053
  thus ?rhs unfolding tendsto_iff unfolding tendsto_def by simp
himmelma@33175
  4054
next
huffman@45388
  4055
  assume ?rhs thus ?lhs
huffman@45388
  4056
    unfolding continuous_within tendsto_def [where l="f a"]
huffman@45388
  4057
    by (simp add: sequentially_imp_eventually_within)
himmelma@33175
  4058
qed
himmelma@33175
  4059
himmelma@33175
  4060
lemma continuous_at_sequentially:
huffman@45388
  4061
  fixes f :: "'a::metric_space \<Rightarrow> 'b::topological_space"
himmelma@33175
  4062
  shows "continuous (at a) f \<longleftrightarrow> (\<forall>x. (x ---> a) sequentially
himmelma@33175
  4063
                  --> ((f o x) ---> f a) sequentially)"
huffman@45896
  4064
  using continuous_within_sequentially[of a UNIV f] by simp
himmelma@33175
  4065
himmelma@33175
  4066
lemma continuous_on_sequentially:
huffman@45388
  4067
  fixes f :: "'a::metric_space \<Rightarrow> 'b::topological_space"
huffman@36355
  4068
  shows "continuous_on s f \<longleftrightarrow>
huffman@36355
  4069
    (\<forall>x. \<forall>a \<in> s. (\<forall>n. x(n) \<in> s) \<and> (x ---> a) sequentially
himmelma@33175
  4070
                    --> ((f o x) ---> f(a)) sequentially)" (is "?lhs = ?rhs")
himmelma@33175
  4071
proof
himmelma@33175
  4072
  assume ?rhs thus ?lhs using continuous_within_sequentially[of _ s f] unfolding continuous_on_eq_continuous_within by auto
himmelma@33175
  4073
next
himmelma@33175
  4074
  assume ?lhs thus ?rhs unfolding continuous_on_eq_continuous_within using continuous_within_sequentially[of _ s f] by auto
himmelma@33175
  4075
qed
himmelma@33175
  4076
huffman@45512
  4077
lemma uniformly_continuous_on_sequentially:
huffman@36437
  4078
  "uniformly_continuous_on s f \<longleftrightarrow> (\<forall>x y. (\<forall>n. x n \<in> s) \<and> (\<forall>n. y n \<in> s) \<and>
huffman@36437
  4079
                    ((\<lambda>n. dist (x n) (y n)) ---> 0) sequentially
huffman@36437
  4080
                    \<longrightarrow> ((\<lambda>n. dist (f(x n)) (f(y n))) ---> 0) sequentially)" (is "?lhs = ?rhs")
himmelma@33175
  4081
proof
himmelma@33175
  4082
  assume ?lhs
huffman@36437
  4083
  { fix x y assume x:"\<forall>n. x n \<in> s" and y:"\<forall>n. y n \<in> s" and xy:"((\<lambda>n. dist (x n) (y n)) ---> 0) sequentially"
himmelma@33175
  4084
    { fix e::real assume "e>0"
himmelma@33175
  4085
      then obtain d where "d>0" and d:"\<forall>x\<in>s. \<forall>x'\<in>s. dist x' x < d \<longrightarrow> dist (f x') (f x) < e"
himmelma@33175
  4086
        using `?lhs`[unfolded uniformly_continuous_on_def, THEN spec[where x=e]] by auto
huffman@45778
  4087
      obtain N where N:"\<forall>n\<ge>N. dist (x n) (y n) < d" using xy[unfolded LIMSEQ_def dist_norm] and `d>0` by auto
himmelma@33175
  4088
      { fix n assume "n\<ge>N"
huffman@36437
  4089
        hence "dist (f (x n)) (f (y n)) < e"
himmelma@33175
  4090
          using N[THEN spec[where x=n]] using d[THEN bspec[where x="x n"], THEN bspec[where x="y n"]] using x and y
huffman@36437
  4091
          unfolding dist_commute by simp  }
huffman@36437
  4092
      hence "\<exists>N. \<forall>n\<ge>N. dist (f (x n)) (f (y n)) < e"  by auto  }
huffman@45778
  4093
    hence "((\<lambda>n. dist (f(x n)) (f(y n))) ---> 0) sequentially" unfolding LIMSEQ_def and dist_real_def by auto  }
himmelma@33175
  4094
  thus ?rhs by auto
himmelma@33175
  4095
next
himmelma@33175
  4096
  assume ?rhs
himmelma@33175
  4097
  { assume "\<not> ?lhs"
himmelma@33175
  4098
    then obtain e where "e>0" "\<forall>d>0. \<exists>x\<in>s. \<exists>x'\<in>s. dist x' x < d \<and> \<not> dist (f x') (f x) < e" unfolding uniformly_continuous_on_def by auto
himmelma@33175
  4099
    then obtain fa where fa:"\<forall>x.  0 < x \<longrightarrow> fst (fa x) \<in> s \<and> snd (fa x) \<in> s \<and> dist (fst (fa x)) (snd (fa x)) < x \<and> \<not> dist (f (fst (fa x))) (f (snd (fa x))) < e"
himmelma@33175
  4100
      using choice[of "\<lambda>d x. d>0 \<longrightarrow> fst x \<in> s \<and> snd x \<in> s \<and> dist (snd x) (fst x) < d \<and> \<not> dist (f (snd x)) (f (fst x)) < e"] unfolding Bex_def
himmelma@33175
  4101
      by (auto simp add: dist_commute)
himmelma@33175
  4102
    def x \<equiv> "\<lambda>n::nat. fst (fa (inverse (real n + 1)))"
himmelma@33175
  4103
    def y \<equiv> "\<lambda>n::nat. snd (fa (inverse (real n + 1)))"
himmelma@33175
  4104
    have xyn:"\<forall>n. x n \<in> s \<and> y n \<in> s" and xy0:"\<forall>n. dist (x n) (y n) < inverse (real n + 1)" and fxy:"\<forall>n. \<not> dist (f (x n)) (f (y n)) < e"
himmelma@33175
  4105
      unfolding x_def and y_def using fa by auto
himmelma@33175
  4106
    { fix e::real assume "e>0"
himmelma@33175
  4107
      then obtain N::nat where "N \<noteq> 0" and N:"0 < inverse (real N) \<and> inverse (real N) < e" unfolding real_arch_inv[of e]   by auto
himmelma@33175
  4108
      { fix n::nat assume "n\<ge>N"
himmelma@33175
  4109
        hence "inverse (real n + 1) < inverse (real N)" using real_of_nat_ge_zero and `N\<noteq>0` by auto
himmelma@33175
  4110
        also have "\<dots> < e" using N by auto
himmelma@33175
  4111
        finally have "inverse (real n + 1) < e" by auto
huffman@36437
  4112
        hence "dist (x n) (y n) < e" using xy0[THEN spec[where x=n]] by auto  }
huffman@36437
  4113
      hence "\<exists>N. \<forall>n\<ge>N. dist (x n) (y n) < e" by auto  }
huffman@45778
  4114
    hence "\<forall>e>0. \<exists>N. \<forall>n\<ge>N. dist (f (x n)) (f (y n)) < e" using `?rhs`[THEN spec[where x=x], THEN spec[where x=y]] and xyn unfolding LIMSEQ_def dist_real_def by auto
huffman@36437
  4115
    hence False using fxy and `e>0` by auto  }
himmelma@33175
  4116
  thus ?lhs unfolding uniformly_continuous_on_def by blast
himmelma@33175
  4117
qed
himmelma@33175
  4118
himmelma@33175
  4119
text{* The usual transformation theorems. *}
himmelma@33175
  4120
himmelma@33175
  4121
lemma continuous_transform_within:
huffman@36667
  4122
  fixes f g :: "'a::metric_space \<Rightarrow> 'b::topological_space"
himmelma@33175
  4123
  assumes "0 < d" "x \<in> s" "\<forall>x' \<in> s. dist x' x < d --> f x' = g x'"
himmelma@33175
  4124
          "continuous (at x within s) f"
himmelma@33175
  4125
  shows "continuous (at x within s) g"
huffman@36667
  4126
unfolding continuous_within
huffman@36667
  4127
proof (rule Lim_transform_within)
huffman@36667
  4128
  show "0 < d" by fact
huffman@36667
  4129
  show "\<forall>x'\<in>s. 0 < dist x' x \<and> dist x' x < d \<longrightarrow> f x' = g x'"
huffman@36667
  4130
    using assms(3) by auto
huffman@36667
  4131
  have "f x = g x"
huffman@36667
  4132
    using assms(1,2,3) by auto
huffman@36667
  4133
  thus "(f ---> g x) (at x within s)"
huffman@36667
  4134
    using assms(4) unfolding continuous_within by simp
himmelma@33175
  4135
qed
himmelma@33175
  4136
himmelma@33175
  4137
lemma continuous_transform_at:
huffman@36667
  4138
  fixes f g :: "'a::metric_space \<Rightarrow> 'b::topological_space"
himmelma@33175
  4139
  assumes "0 < d" "\<forall>x'. dist x' x < d --> f x' = g x'"
himmelma@33175
  4140
          "continuous (at x) f"
himmelma@33175
  4141
  shows "continuous (at x) g"
huffman@45896
  4142
  using continuous_transform_within [of d x UNIV f g] assms by simp
himmelma@33175
  4143
huffman@45512
  4144
subsubsection {* Structural rules for pointwise continuity *}
himmelma@33175
  4145
huffman@45511
  4146
lemma continuous_within_id: "continuous (at a within s) (\<lambda>x. x)"
huffman@45511
  4147
  unfolding continuous_within by (rule tendsto_ident_at_within)
huffman@45511
  4148
huffman@45511
  4149
lemma continuous_at_id: "continuous (at a) (\<lambda>x. x)"
huffman@45511
  4150
  unfolding continuous_at by (rule tendsto_ident_at)
huffman@45511
  4151
huffman@45511
  4152
lemma continuous_const: "continuous F (\<lambda>x. c)"
huffman@45511
  4153
  unfolding continuous_def by (rule tendsto_const)
huffman@45511
  4154
huffman@45511
  4155
lemma continuous_dist:
huffman@45511
  4156
  assumes "continuous F f" and "continuous F g"
huffman@45511
  4157
  shows "continuous F (\<lambda>x. dist (f x) (g x))"
huffman@45511
  4158
  using assms unfolding continuous_def by (rule tendsto_dist)
huffman@45511
  4159
immler@51102
  4160
lemma continuous_infdist:
immler@51102
  4161
  assumes "continuous F f"
immler@51102
  4162
  shows "continuous F (\<lambda>x. infdist (f x) A)"
immler@51102
  4163
  using assms unfolding continuous_def by (rule tendsto_infdist)
immler@51102
  4164
huffman@45511
  4165
lemma continuous_norm:
huffman@45511
  4166
  shows "continuous F f \<Longrightarrow> continuous F (\<lambda>x. norm (f x))"
huffman@45511
  4167
  unfolding continuous_def by (rule tendsto_norm)
huffman@45511
  4168
huffman@45511
  4169
lemma continuous_infnorm:
huffman@45511
  4170
  shows "continuous F f \<Longrightarrow> continuous F (\<lambda>x. infnorm (f x))"
huffman@45511
  4171
  unfolding continuous_def by (rule tendsto_infnorm)
himmelma@33175
  4172
himmelma@33175
  4173
lemma continuous_add:
himmelma@33175
  4174
  fixes f g :: "'a::t2_space \<Rightarrow> 'b::real_normed_vector"
huffman@45511
  4175
  shows "\<lbrakk>continuous F f; continuous F g\<rbrakk> \<Longrightarrow> continuous F (\<lambda>x. f x + g x)"
huffman@45511
  4176
  unfolding continuous_def by (rule tendsto_add)
huffman@45511
  4177
huffman@45511
  4178
lemma continuous_minus:
huffman@45511
  4179
  fixes f :: "'a::t2_space \<Rightarrow> 'b::real_normed_vector"
huffman@45511
  4180
  shows "continuous F f \<Longrightarrow> continuous F (\<lambda>x. - f x)"
huffman@45511
  4181
  unfolding continuous_def by (rule tendsto_minus)
huffman@45511
  4182
huffman@45511
  4183
lemma continuous_diff:
himmelma@33175
  4184
  fixes f g :: "'a::t2_space \<Rightarrow> 'b::real_normed_vector"
huffman@45511
  4185
  shows "\<lbrakk>continuous F f; continuous F g\<rbrakk> \<Longrightarrow> continuous F (\<lambda>x. f x - g x)"
huffman@45511
  4186
  unfolding continuous_def by (rule tendsto_diff)
huffman@45511
  4187
huffman@45511
  4188
lemma continuous_scaleR:
huffman@45511
  4189
  fixes g :: "'a::t2_space \<Rightarrow> 'b::real_normed_vector"
huffman@45511
  4190
  shows "\<lbrakk>continuous F f; continuous F g\<rbrakk> \<Longrightarrow> continuous F (\<lambda>x. f x *\<^sub>R g x)"
huffman@45511
  4191
  unfolding continuous_def by (rule tendsto_scaleR)
huffman@45511
  4192
huffman@45511
  4193
lemma continuous_mult:
huffman@45511
  4194
  fixes f g :: "'a::t2_space \<Rightarrow> 'b::real_normed_algebra"
huffman@45511
  4195
  shows "\<lbrakk>continuous F f; continuous F g\<rbrakk> \<Longrightarrow> continuous F (\<lambda>x. f x * g x)"
huffman@45511
  4196
  unfolding continuous_def by (rule tendsto_mult)
huffman@45511
  4197
huffman@45511
  4198
lemma continuous_inner:
huffman@45511
  4199
  assumes "continuous F f" and "continuous F g"
huffman@45511
  4200
  shows "continuous F (\<lambda>x. inner (f x) (g x))"
huffman@45511
  4201
  using assms unfolding continuous_def by (rule tendsto_inner)
huffman@45511
  4202
huffman@45511
  4203
lemma continuous_inverse:
huffman@45511
  4204
  fixes f :: "'a::t2_space \<Rightarrow> 'b::real_normed_div_algebra"
huffman@45511
  4205
  assumes "continuous F f" and "f (netlimit F) \<noteq> 0"
huffman@45511
  4206
  shows "continuous F (\<lambda>x. inverse (f x))"
huffman@45511
  4207
  using assms unfolding continuous_def by (rule tendsto_inverse)
huffman@45511
  4208
huffman@45511
  4209
lemma continuous_at_within_inverse:
huffman@45511
  4210
  fixes f :: "'a::t2_space \<Rightarrow> 'b::real_normed_div_algebra"
huffman@45511
  4211
  assumes "continuous (at a within s) f" and "f a \<noteq> 0"
huffman@45511
  4212
  shows "continuous (at a within s) (\<lambda>x. inverse (f x))"
huffman@45511
  4213
  using assms unfolding continuous_within by (rule tendsto_inverse)
huffman@45511
  4214
huffman@45511
  4215
lemma continuous_at_inverse:
huffman@45511
  4216
  fixes f :: "'a::t2_space \<Rightarrow> 'b::real_normed_div_algebra"
huffman@45511
  4217
  assumes "continuous (at a) f" and "f a \<noteq> 0"
huffman@45511
  4218
  shows "continuous (at a) (\<lambda>x. inverse (f x))"
huffman@45511
  4219
  using assms unfolding continuous_at by (rule tendsto_inverse)
huffman@45511
  4220
huffman@45511
  4221
lemmas continuous_intros = continuous_at_id continuous_within_id
huffman@45511
  4222
  continuous_const continuous_dist continuous_norm continuous_infnorm
hoelzl@51541
  4223
  continuous_add continuous_minus continuous_diff continuous_scaleR continuous_mult
hoelzl@51541
  4224
  continuous_inner continuous_at_inverse continuous_at_within_inverse
hoelzl@34951
  4225
huffman@45512
  4226
subsubsection {* Structural rules for setwise continuity *}
himmelma@33175
  4227
huffman@45511
  4228
lemma continuous_on_id: "continuous_on s (\<lambda>x. x)"
huffman@45511
  4229
  unfolding continuous_on_def by (fast intro: tendsto_ident_at_within)
huffman@45511
  4230
huffman@45386
  4231
lemma continuous_on_const: "continuous_on s (\<lambda>x. c)"
huffman@44983
  4232
  unfolding continuous_on_def by (auto intro: tendsto_intros)
himmelma@33175
  4233
huffman@45511
  4234
lemma continuous_on_norm:
huffman@45511
  4235
  shows "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. norm (f x))"
huffman@45511
  4236
  unfolding continuous_on_def by (fast intro: tendsto_norm)
huffman@45511
  4237
huffman@45511
  4238
lemma continuous_on_infnorm:
huffman@45511
  4239
  shows "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. infnorm (f x))"
huffman@45511
  4240
  unfolding continuous_on by (fast intro: tendsto_infnorm)
huffman@45511
  4241
huffman@45386
  4242
lemma continuous_on_minus:
huffman@36436
  4243
  fixes f :: "'a::topological_space \<Rightarrow> 'b::real_normed_vector"
himmelma@33175
  4244
  shows "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. - f x)"
huffman@36436
  4245
  unfolding continuous_on_def by (auto intro: tendsto_intros)
himmelma@33175
  4246
himmelma@33175
  4247
lemma continuous_on_add:
huffman@36436
  4248
  fixes f g :: "'a::topological_space \<Rightarrow> 'b::real_normed_vector"
himmelma@33175
  4249
  shows "continuous_on s f \<Longrightarrow> continuous_on s g
himmelma@33175
  4250
           \<Longrightarrow> continuous_on s (\<lambda>x. f x + g x)"
huffman@36436
  4251
  unfolding continuous_on_def by (auto intro: tendsto_intros)
himmelma@33175
  4252
huffman@45386
  4253
lemma continuous_on_diff:
huffman@36436
  4254
  fixes f g :: "'a::topological_space \<Rightarrow> 'b::real_normed_vector"
himmelma@33175
  4255
  shows "continuous_on s f \<Longrightarrow> continuous_on s g
himmelma@33175
  4256
           \<Longrightarrow> continuous_on s (\<lambda>x. f x - g x)"
huffman@36436
  4257
  unfolding continuous_on_def by (auto intro: tendsto_intros)
himmelma@33175
  4258
huffman@45386
  4259
lemma (in bounded_linear) continuous_on:
huffman@45386
  4260
  "continuous_on s g \<Longrightarrow> continuous_on s (\<lambda>x. f (g x))"
huffman@45386
  4261
  unfolding continuous_on_def by (fast intro: tendsto)
huffman@45386
  4262
huffman@45386
  4263
lemma (in bounded_bilinear) continuous_on:
huffman@45386
  4264
  "\<lbrakk>continuous_on s f; continuous_on s g\<rbrakk> \<Longrightarrow> continuous_on s (\<lambda>x. f x ** g x)"
huffman@45386
  4265
  unfolding continuous_on_def by (fast intro: tendsto)
huffman@45386
  4266
huffman@45386
  4267
lemma continuous_on_scaleR:
huffman@45386
  4268
  fixes g :: "'a::topological_space \<Rightarrow> 'b::real_normed_vector"
huffman@45386
  4269
  assumes "continuous_on s f" and "continuous_on s g"
huffman@45386
  4270
  shows "continuous_on s (\<lambda>x. f x *\<^sub>R g x)"
huffman@45386
  4271
  using bounded_bilinear_scaleR assms
huffman@45386
  4272
  by (rule bounded_bilinear.continuous_on)
huffman@45386
  4273
huffman@45386
  4274
lemma continuous_on_mult:
huffman@45386
  4275
  fixes g :: "'a::topological_space \<Rightarrow> 'b::real_normed_algebra"
huffman@45386
  4276
  assumes "continuous_on s f" and "continuous_on s g"
huffman@45386
  4277
  shows "continuous_on s (\<lambda>x. f x * g x)"
huffman@45386
  4278
  using bounded_bilinear_mult assms
huffman@45386
  4279
  by (rule bounded_bilinear.continuous_on)
huffman@45386
  4280
huffman@45386
  4281
lemma continuous_on_inner:
huffman@45386
  4282
  fixes g :: "'a::topological_space \<Rightarrow> 'b::real_inner"
huffman@45386
  4283
  assumes "continuous_on s f" and "continuous_on s g"
huffman@45386
  4284
  shows "continuous_on s (\<lambda>x. inner (f x) (g x))"
huffman@45386
  4285
  using bounded_bilinear_inner assms
huffman@45386
  4286
  by (rule bounded_bilinear.continuous_on)
huffman@45386
  4287
huffman@45511
  4288
lemma continuous_on_inverse:
huffman@45511
  4289
  fixes f :: "'a::topological_space \<Rightarrow> 'b::real_normed_div_algebra"
huffman@45511
  4290
  assumes "continuous_on s f" and "\<forall>x\<in>s. f x \<noteq> 0"
huffman@45511
  4291
  shows "continuous_on s (\<lambda>x. inverse (f x))"
huffman@45511
  4292
  using assms unfolding continuous_on by (fast intro: tendsto_inverse)
huffman@45511
  4293
huffman@45512
  4294
subsubsection {* Structural rules for uniform continuity *}
himmelma@33175
  4295
huffman@45511
  4296
lemma uniformly_continuous_on_id:
huffman@45512
  4297
  shows "uniformly_continuous_on s (\<lambda>x. x)"
huffman@45511
  4298
  unfolding uniformly_continuous_on_def by auto
huffman@45511
  4299
himmelma@33175
  4300
lemma uniformly_continuous_on_const:
huffman@45512
  4301
  shows "uniformly_continuous_on s (\<lambda>x. c)"
himmelma@33175
  4302
  unfolding uniformly_continuous_on_def by simp
himmelma@33175
  4303
huffman@45512
  4304
lemma uniformly_continuous_on_dist:
huffman@45512
  4305
  fixes f g :: "'a::metric_space \<Rightarrow> 'b::metric_space"
huffman@45512
  4306
  assumes "uniformly_continuous_on s f"
huffman@45512
  4307
  assumes "uniformly_continuous_on s g"
huffman@45512
  4308
  shows "uniformly_continuous_on s (\<lambda>x. dist (f x) (g x))"
huffman@45512
  4309
proof -
huffman@45512
  4310
  { fix a b c d :: 'b have "\<bar>dist a b - dist c d\<bar> \<le> dist a c + dist b d"
huffman@45512
  4311
      using dist_triangle2 [of a b c] dist_triangle2 [of b c d]
huffman@45512
  4312
      using dist_triangle3 [of c d a] dist_triangle [of a d b]
huffman@45512
  4313
      by arith
huffman@45512
  4314
  } note le = this
huffman@45512
  4315
  { fix x y
huffman@45512
  4316
    assume f: "(\<lambda>n. dist (f (x n)) (f (y n))) ----> 0"
huffman@45512
  4317
    assume g: "(\<lambda>n. dist (g (x n)) (g (y n))) ----> 0"
huffman@45512
  4318
    have "(\<lambda>n. \<bar>dist (f (x n)) (g (x n)) - dist (f (y n)) (g (y n))\<bar>) ----> 0"
huffman@45512
  4319
      by (rule Lim_transform_bound [OF _ tendsto_add_zero [OF f g]],
huffman@45512
  4320
        simp add: le)
huffman@45512
  4321
  }
huffman@45512
  4322
  thus ?thesis using assms unfolding uniformly_continuous_on_sequentially
huffman@45512
  4323
    unfolding dist_real_def by simp
huffman@45512
  4324
qed
huffman@45512
  4325
huffman@45512
  4326
lemma uniformly_continuous_on_norm:
huffman@45512
  4327
  assumes "uniformly_continuous_on s f"
huffman@45512
  4328
  shows "uniformly_continuous_on s (\<lambda>x. norm (f x))"
huffman@45512
  4329
  unfolding norm_conv_dist using assms
huffman@45512
  4330
  by (intro uniformly_continuous_on_dist uniformly_continuous_on_const)
huffman@45512
  4331
huffman@45512
  4332
lemma (in bounded_linear) uniformly_continuous_on:
huffman@45512
  4333
  assumes "uniformly_continuous_on s g"
huffman@45512
  4334
  shows "uniformly_continuous_on s (\<lambda>x. f (g x))"
huffman@45512
  4335
  using assms unfolding uniformly_continuous_on_sequentially
huffman@45512
  4336
  unfolding dist_norm tendsto_norm_zero_iff diff[symmetric]
huffman@45512
  4337
  by (auto intro: tendsto_zero)
huffman@45512
  4338
himmelma@33175
  4339
lemma uniformly_continuous_on_cmul:
huffman@36437
  4340
  fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
himmelma@33175
  4341
  assumes "uniformly_continuous_on s f"
himmelma@33175
  4342
  shows "uniformly_continuous_on s (\<lambda>x. c *\<^sub>R f(x))"
huffman@45512
  4343
  using bounded_linear_scaleR_right assms
huffman@45512
  4344
  by (rule bounded_linear.uniformly_continuous_on)
himmelma@33175
  4345
himmelma@33175
  4346
lemma dist_minus:
himmelma@33175
  4347
  fixes x y :: "'a::real_normed_vector"
himmelma@33175
  4348
  shows "dist (- x) (- y) = dist x y"
himmelma@33175
  4349
  unfolding dist_norm minus_diff_minus norm_minus_cancel ..
himmelma@33175
  4350
huffman@45512
  4351
lemma uniformly_continuous_on_minus:
himmelma@33175
  4352
  fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
huffman@45512
  4353
  shows "uniformly_continuous_on s f \<Longrightarrow> uniformly_continuous_on s (\<lambda>x. - f x)"
himmelma@33175
  4354
  unfolding uniformly_continuous_on_def dist_minus .
himmelma@33175
  4355
himmelma@33175
  4356
lemma uniformly_continuous_on_add:
huffman@36437
  4357
  fixes f g :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
huffman@45512
  4358
  assumes "uniformly_continuous_on s f"
huffman@45512
  4359
  assumes "uniformly_continuous_on s g"
himmelma@33175
  4360
  shows "uniformly_continuous_on s (\<lambda>x. f x + g x)"
huffman@45512
  4361
  using assms unfolding uniformly_continuous_on_sequentially
huffman@45512
  4362
  unfolding dist_norm tendsto_norm_zero_iff add_diff_add
huffman@45512
  4363
  by (auto intro: tendsto_add_zero)
huffman@45512
  4364
huffman@45512
  4365
lemma uniformly_continuous_on_diff:
huffman@36437
  4366
  fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
huffman@45512
  4367
  assumes "uniformly_continuous_on s f" and "uniformly_continuous_on s g"
huffman@45512
  4368
  shows "uniformly_continuous_on s (\<lambda>x. f x - g x)"
huffman@45512
  4369
  unfolding ab_diff_minus using assms
huffman@45512
  4370
  by (intro uniformly_continuous_on_add uniformly_continuous_on_minus)
himmelma@33175
  4371
himmelma@33175
  4372
text{* Continuity of all kinds is preserved under composition. *}
himmelma@33175
  4373
huffman@36437
  4374
lemma continuous_within_topological:
huffman@36437
  4375
  "continuous (at x within s) f \<longleftrightarrow>
huffman@36437
  4376
    (\<forall>B. open B \<longrightarrow> f x \<in> B \<longrightarrow>
huffman@36437
  4377
      (\<exists>A. open A \<and> x \<in> A \<and> (\<forall>y\<in>s. y \<in> A \<longrightarrow> f y \<in> B)))"
huffman@36437
  4378
unfolding continuous_within
huffman@36437
  4379
unfolding tendsto_def Limits.eventually_within eventually_at_topological
huffman@36437
  4380
by (intro ball_cong [OF refl] all_cong imp_cong ex_cong conj_cong refl) auto
huffman@36437
  4381
himmelma@33175
  4382
lemma continuous_within_compose:
huffman@36437
  4383
  assumes "continuous (at x within s) f"
huffman@36437
  4384
  assumes "continuous (at (f x) within f ` s) g"
himmelma@33175
  4385
  shows "continuous (at x within s) (g o f)"
huffman@36437
  4386
using assms unfolding continuous_within_topological by simp metis
himmelma@33175
  4387
himmelma@33175
  4388
lemma continuous_at_compose:
huffman@45896
  4389
  assumes "continuous (at x) f" and "continuous (at (f x)) g"
himmelma@33175
  4390
  shows "continuous (at x) (g o f)"
himmelma@33175
  4391
proof-
huffman@45896
  4392
  have "continuous (at (f x) within range f) g" using assms(2)
huffman@45896
  4393
    using continuous_within_subset[of "f x" UNIV g "range f"] by simp
huffman@45896
  4394
  thus ?thesis using assms(1)
huffman@45896
  4395
    using continuous_within_compose[of x UNIV f g] by simp
himmelma@33175
  4396
qed
himmelma@33175
  4397
himmelma@33175
  4398
lemma continuous_on_compose:
huffman@36436
  4399
  "continuous_on s f \<Longrightarrow> continuous_on (f ` s) g \<Longrightarrow> continuous_on s (g o f)"
huffman@36436
  4400
  unfolding continuous_on_topological by simp metis
himmelma@33175
  4401
himmelma@33175
  4402
lemma uniformly_continuous_on_compose:
himmelma@33175
  4403
  assumes "uniformly_continuous_on s f"  "uniformly_continuous_on (f ` s) g"
himmelma@33175
  4404
  shows "uniformly_continuous_on s (g o f)"
himmelma@33175
  4405
proof-
himmelma@33175
  4406
  { fix e::real assume "e>0"
himmelma@33175
  4407
    then obtain d where "d>0" and d:"\<forall>x\<in>f ` s. \<forall>x'\<in>f ` s. dist x' x < d \<longrightarrow> dist (g x') (g x) < e" using assms(2) unfolding uniformly_continuous_on_def by auto
himmelma@33175
  4408
    obtain d' where "d'>0" "\<forall>x\<in>s. \<forall>x'\<in>s. dist x' x < d' \<longrightarrow> dist (f x') (f x) < d" using `d>0` using assms(1) unfolding uniformly_continuous_on_def by auto
himmelma@33175
  4409
    hence "\<exists>d>0. \<forall>x\<in>s. \<forall>x'\<in>s. dist x' x < d \<longrightarrow> dist ((g \<circ> f) x') ((g \<circ> f) x) < e" using `d>0` using d by auto  }
himmelma@33175
  4410
  thus ?thesis using assms unfolding uniformly_continuous_on_def by auto
himmelma@33175
  4411
qed
himmelma@33175
  4412
huffman@45511
  4413
lemmas continuous_on_intros = continuous_on_id continuous_on_const
huffman@45511
  4414
  continuous_on_compose continuous_on_norm continuous_on_infnorm
huffman@45511
  4415
  continuous_on_add continuous_on_minus continuous_on_diff
huffman@45511
  4416
  continuous_on_scaleR continuous_on_mult continuous_on_inverse
hoelzl@51541
  4417
  continuous_on_inner
huffman@45512
  4418
  uniformly_continuous_on_id uniformly_continuous_on_const
huffman@45512
  4419
  uniformly_continuous_on_dist uniformly_continuous_on_norm
huffman@45512
  4420
  uniformly_continuous_on_compose uniformly_continuous_on_add
huffman@45512
  4421
  uniformly_continuous_on_minus uniformly_continuous_on_diff
huffman@45512
  4422
  uniformly_continuous_on_cmul
huffman@45511
  4423
himmelma@33175
  4424
text{* Continuity in terms of open preimages. *}
himmelma@33175
  4425
himmelma@33175
  4426
lemma continuous_at_open:
huffman@36437
  4427
  shows "continuous (at x) f \<longleftrightarrow> (\<forall>t. open t \<and> f x \<in> t --> (\<exists>s. open s \<and> x \<in> s \<and> (\<forall>x' \<in> s. (f x') \<in> t)))"
huffman@36437
  4428
unfolding continuous_within_topological [of x UNIV f, unfolded within_UNIV]
huffman@36437
  4429
unfolding imp_conjL by (intro all_cong imp_cong ex_cong conj_cong refl) auto
himmelma@33175
  4430
himmelma@33175
  4431
lemma continuous_on_open:
huffman@36437
  4432
  shows "continuous_on s f \<longleftrightarrow>
himmelma@33175
  4433
        (\<forall>t. openin (subtopology euclidean (f ` s)) t
himmelma@33175
  4434
            --> openin (subtopology euclidean s) {x \<in> s. f x \<in> t})" (is "?lhs = ?rhs")
huffman@36437
  4435
proof (safe)
huffman@36437
  4436
  fix t :: "'b set"
huffman@36437
  4437
  assume 1: "continuous_on s f"
huffman@36437
  4438
  assume 2: "openin (subtopology euclidean (f ` s)) t"
huffman@36437
  4439
  from 2 obtain B where B: "open B" and t: "t = f ` s \<inter> B"
huffman@36437
  4440
    unfolding openin_open by auto
huffman@36437
  4441
  def U == "\<Union>{A. open A \<and> (\<forall>x\<in>s. x \<in> A \<longrightarrow> f x \<in> B)}"
huffman@36437
  4442
  have "open U" unfolding U_def by (simp add: open_Union)
huffman@36437
  4443
  moreover have "\<forall>x\<in>s. x \<in> U \<longleftrightarrow> f x \<in> t"
huffman@36437
  4444
  proof (intro ballI iffI)
huffman@36437
  4445
    fix x assume "x \<in> s" and "x \<in> U" thus "f x \<in> t"
huffman@36437
  4446
      unfolding U_def t by auto
huffman@36437
  4447
  next
huffman@36437
  4448
    fix x assume "x \<in> s" and "f x \<in> t"
huffman@36437
  4449
    hence "x \<in> s" and "f x \<in> B"
huffman@36437
  4450
      unfolding t by auto
huffman@36437
  4451
    with 1 B obtain A where "open A" "x \<in> A" "\<forall>y\<in>s. y \<in> A \<longrightarrow> f y \<in> B"
huffman@36437
  4452
      unfolding t continuous_on_topological by metis
huffman@36437
  4453
    then show "x \<in> U"
huffman@36437
  4454
      unfolding U_def by auto
huffman@36437
  4455
  qed
huffman@36437
  4456
  ultimately have "open U \<and> {x \<in> s. f x \<in> t} = s \<inter> U" by auto
huffman@36437
  4457
  then show "openin (subtopology euclidean s) {x \<in> s. f x \<in> t}"
huffman@36437
  4458
    unfolding openin_open by fast
himmelma@33175
  4459
next
huffman@36437
  4460
  assume "?rhs" show "continuous_on s f"
huffman@36437
  4461
  unfolding continuous_on_topological
huffman@36437
  4462
  proof (clarify)
huffman@36437
  4463
    fix x and B assume "x \<in> s" and "open B" and "f x \<in> B"
huffman@36437
  4464
    have "openin (subtopology euclidean (f ` s)) (f ` s \<inter> B)"
huffman@36437
  4465
      unfolding openin_open using `open B` by auto
huffman@36437
  4466
    then have "openin (subtopology euclidean s) {x \<in> s. f x \<in> f ` s \<inter> B}"
huffman@36437
  4467
      using `?rhs` by fast
huffman@36437
  4468
    then show "\<exists>A. open A \<and> x \<in> A \<and> (\<forall>y\<in>s. y \<in> A \<longrightarrow> f y \<in> B)"
huffman@36437
  4469
      unfolding openin_open using `x \<in> s` and `f x \<in> B` by auto
huffman@36437
  4470
  qed
huffman@36437
  4471
qed
huffman@36437
  4472
huffman@36437
  4473
text {* Similarly in terms of closed sets. *}
himmelma@33175
  4474
himmelma@33175
  4475
lemma continuous_on_closed:
huffman@36355
  4476
  shows "continuous_on s f \<longleftrightarrow>  (\<forall>t. closedin (subtopology euclidean (f ` s)) t  --> closedin (subtopology euclidean s) {x \<in> s. f x \<in> t})" (is "?lhs = ?rhs")
himmelma@33175
  4477
proof
himmelma@33175
  4478
  assume ?lhs
himmelma@33175
  4479
  { fix t
himmelma@33175
  4480
    have *:"s - {x \<in> s. f x \<in> f ` s - t} = {x \<in> s. f x \<in> t}" by auto
himmelma@33175
  4481
    have **:"f ` s - (f ` s - (f ` s - t)) = f ` s - t" by auto
himmelma@33175
  4482
    assume as:"closedin (subtopology euclidean (f ` s)) t"
himmelma@33175
  4483
    hence "closedin (subtopology euclidean (f ` s)) (f ` s - (f ` s - t))" unfolding closedin_def topspace_euclidean_subtopology unfolding ** by auto
himmelma@33175
  4484
    hence "closedin (subtopology euclidean s) {x \<in> s. f x \<in> t}" using `?lhs`[unfolded continuous_on_open, THEN spec[where x="(f ` s) - t"]]
himmelma@33175
  4485
      unfolding openin_closedin_eq topspace_euclidean_subtopology unfolding * by auto  }
himmelma@33175
  4486
  thus ?rhs by auto
himmelma@33175
  4487
next
himmelma@33175
  4488
  assume ?rhs
himmelma@33175
  4489
  { fix t
himmelma@33175
  4490
    have *:"s - {x \<in> s. f x \<in> f ` s - t} = {x \<in> s. f x \<in> t}" by auto
himmelma@33175
  4491
    assume as:"openin (subtopology euclidean (f ` s)) t"
himmelma@33175
  4492
    hence "openin (subtopology euclidean s) {x \<in> s. f x \<in> t}" using `?rhs`[THEN spec[where x="(f ` s) - t"]]
himmelma@33175
  4493
      unfolding openin_closedin_eq topspace_euclidean_subtopology *[THEN sym] closedin_subtopology by auto }
himmelma@33175
  4494
  thus ?lhs unfolding continuous_on_open by auto
himmelma@33175
  4495
qed
himmelma@33175
  4496
huffman@45081
  4497
text {* Half-global and completely global cases. *}
himmelma@33175
  4498
himmelma@33175
  4499
lemma continuous_open_in_preimage:
himmelma@33175
  4500
  assumes "continuous_on s f"  "open t"
himmelma@33175
  4501
  shows "openin (subtopology euclidean s) {x \<in> s. f x \<in> t}"
himmelma@33175
  4502
proof-
himmelma@33175
  4503
  have *:"\<forall>x. x \<in> s \<and> f x \<in> t \<longleftrightarrow> x \<in> s \<and> f x \<in> (t \<inter> f ` s)" by auto
himmelma@33175
  4504
  have "openin (subtopology euclidean (f ` s)) (t \<inter> f ` s)"
himmelma@33175
  4505
    using openin_open_Int[of t "f ` s", OF assms(2)] unfolding openin_open by auto
himmelma@33175
  4506
  thus ?thesis using assms(1)[unfolded continuous_on_open, THEN spec[where x="t \<inter> f ` s"]] using * by auto
himmelma@33175
  4507
qed
himmelma@33175
  4508
himmelma@33175
  4509
lemma continuous_closed_in_preimage:
himmelma@33175
  4510
  assumes "continuous_on s f"  "closed t"
himmelma@33175
  4511
  shows "closedin (subtopology euclidean s) {x \<in> s. f x \<in> t}"
himmelma@33175
  4512
proof-
himmelma@33175
  4513
  have *:"\<forall>x. x \<in> s \<and> f x \<in> t \<longleftrightarrow> x \<in> s \<and> f x \<in> (t \<inter> f ` s)" by auto
himmelma@33175
  4514
  have "closedin (subtopology euclidean (f ` s)) (t \<inter> f ` s)"
himmelma@33175
  4515
    using closedin_closed_Int[of t "f ` s", OF assms(2)] unfolding Int_commute by auto
himmelma@33175
  4516
  thus ?thesis
himmelma@33175
  4517
    using assms(1)[unfolded continuous_on_closed, THEN spec[where x="t \<inter> f ` s"]] using * by auto
himmelma@33175
  4518
qed
himmelma@33175
  4519
himmelma@33175
  4520
lemma continuous_open_preimage:
himmelma@33175
  4521
  assumes "continuous_on s f" "open s" "open t"
himmelma@33175
  4522
  shows "open {x \<in> s. f x \<in> t}"
himmelma@33175
  4523
proof-
himmelma@33175
  4524
  obtain T where T: "open T" "{x \<in> s. f x \<in> t} = s \<inter> T"
himmelma@33175
  4525
    using continuous_open_in_preimage[OF assms(1,3)] unfolding openin_open by auto
himmelma@33175
  4526
  thus ?thesis using open_Int[of s T, OF assms(2)] by auto
himmelma@33175
  4527
qed
himmelma@33175
  4528
himmelma@33175
  4529
lemma continuous_closed_preimage:
himmelma@33175
  4530
  assumes "continuous_on s f" "closed s" "closed t"
himmelma@33175
  4531
  shows "closed {x \<in> s. f x \<in> t}"
himmelma@33175
  4532
proof-
himmelma@33175
  4533
  obtain T where T: "closed T" "{x \<in> s. f x \<in> t} = s \<inter> T"
himmelma@33175
  4534
    using continuous_closed_in_preimage[OF assms(1,3)] unfolding closedin_closed by auto
himmelma@33175
  4535
  thus ?thesis using closed_Int[of s T, OF assms(2)] by auto
himmelma@33175
  4536
qed
himmelma@33175
  4537
himmelma@33175
  4538
lemma continuous_open_preimage_univ:
himmelma@33175
  4539
  shows "\<forall>x. continuous (at x) f \<Longrightarrow> open s \<Longrightarrow> open {x. f x \<in> s}"
himmelma@33175
  4540
  using continuous_open_preimage[of UNIV f s] open_UNIV continuous_at_imp_continuous_on by auto
himmelma@33175
  4541
himmelma@33175
  4542
lemma continuous_closed_preimage_univ:
himmelma@33175
  4543
  shows "(\<forall>x. continuous (at x) f) \<Longrightarrow> closed s ==> closed {x. f x \<in> s}"
himmelma@33175
  4544
  using continuous_closed_preimage[of UNIV f s] closed_UNIV continuous_at_imp_continuous_on by auto
himmelma@33175
  4545
himmelma@33175
  4546
lemma continuous_open_vimage:
himmelma@33175
  4547
  shows "\<forall>x. continuous (at x) f \<Longrightarrow> open s \<Longrightarrow> open (f -` s)"
himmelma@33175
  4548
  unfolding vimage_def by (rule continuous_open_preimage_univ)
himmelma@33175
  4549
himmelma@33175
  4550
lemma continuous_closed_vimage:
himmelma@33175
  4551
  shows "\<forall>x. continuous (at x) f \<Longrightarrow> closed s \<Longrightarrow> closed (f -` s)"
himmelma@33175
  4552
  unfolding vimage_def by (rule continuous_closed_preimage_univ)
himmelma@33175
  4553
huffman@36437
  4554
lemma interior_image_subset:
himmelma@35172
  4555
  assumes "\<forall>x. continuous (at x) f" "inj f"
himmelma@35172
  4556
  shows "interior (f ` s) \<subseteq> f ` (interior s)"
huffman@45374
  4557
proof
huffman@45374
  4558
  fix x assume "x \<in> interior (f ` s)"
huffman@45374
  4559
  then obtain T where as: "open T" "x \<in> T" "T \<subseteq> f ` s" ..
huffman@45374
  4560
  hence "x \<in> f ` s" by auto
huffman@45374
  4561
  then obtain y where y: "y \<in> s" "x = f y" by auto
huffman@45374
  4562
  have "open (vimage f T)"
huffman@45374
  4563
    using assms(1) `open T` by (rule continuous_open_vimage)
huffman@45374
  4564
  moreover have "y \<in> vimage f T"
huffman@45374
  4565
    using `x = f y` `x \<in> T` by simp
huffman@45374
  4566
  moreover have "vimage f T \<subseteq> s"
huffman@45374
  4567
    using `T \<subseteq> image f s` `inj f` unfolding inj_on_def subset_eq by auto
huffman@45374
  4568
  ultimately have "y \<in> interior s" ..
huffman@45374
  4569
  with `x = f y` show "x \<in> f ` interior s" ..
huffman@45374
  4570
qed
himmelma@35172
  4571
huffman@45081
  4572
text {* Equality of continuous functions on closure and related results. *}
himmelma@33175
  4573
himmelma@33175
  4574
lemma continuous_closed_in_preimage_constant:
huffman@36668
  4575
  fixes f :: "_ \<Rightarrow> 'b::t1_space"
huffman@36355
  4576
  shows "continuous_on s f ==> closedin (subtopology euclidean s) {x \<in> s. f x = a}"
huffman@36668
  4577
  using continuous_closed_in_preimage[of s f "{a}"] by auto
himmelma@33175
  4578
himmelma@33175
  4579
lemma continuous_closed_preimage_constant:
huffman@36668
  4580
  fixes f :: "_ \<Rightarrow> 'b::t1_space"
huffman@36355
  4581
  shows "continuous_on s f \<Longrightarrow> closed s ==> closed {x \<in> s. f x = a}"
huffman@36668
  4582
  using continuous_closed_preimage[of s f "{a}"] by auto
himmelma@33175
  4583
himmelma@33175
  4584
lemma continuous_constant_on_closure:
huffman@36668
  4585
  fixes f :: "_ \<Rightarrow> 'b::t1_space"
himmelma@33175
  4586
  assumes "continuous_on (closure s) f"
himmelma@33175
  4587
          "\<forall>x \<in> s. f x = a"
himmelma@33175
  4588
  shows "\<forall>x \<in> (closure s). f x = a"
himmelma@33175
  4589
    using continuous_closed_preimage_constant[of "closure s" f a]
himmelma@33175
  4590
    assms closure_minimal[of s "{x \<in> closure s. f x = a}"] closure_subset unfolding subset_eq by auto
himmelma@33175
  4591
himmelma@33175
  4592
lemma image_closure_subset:
himmelma@33175
  4593
  assumes "continuous_on (closure s) f"  "closed t"  "(f ` s) \<subseteq> t"
himmelma@33175
  4594
  shows "f ` (closure s) \<subseteq> t"
himmelma@33175
  4595
proof-
himmelma@33175
  4596
  have "s \<subseteq> {x \<in> closure s. f x \<in> t}" using assms(3) closure_subset by auto
himmelma@33175
  4597
  moreover have "closed {x \<in> closure s. f x \<in> t}"
himmelma@33175
  4598
    using continuous_closed_preimage[OF assms(1)] and assms(2) by auto
himmelma@33175
  4599
  ultimately have "closure s = {x \<in> closure s . f x \<in> t}"
himmelma@33175
  4600
    using closure_minimal[of s "{x \<in> closure s. f x \<in> t}"] by auto
himmelma@33175
  4601
  thus ?thesis by auto
himmelma@33175
  4602
qed
himmelma@33175
  4603
himmelma@33175
  4604
lemma continuous_on_closure_norm_le:
himmelma@33175
  4605
  fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
himmelma@33175
  4606
  assumes "continuous_on (closure s) f"  "\<forall>y \<in> s. norm(f y) \<le> b"  "x \<in> (closure s)"
himmelma@33175
  4607
  shows "norm(f x) \<le> b"
himmelma@33175
  4608
proof-
himmelma@33175
  4609
  have *:"f ` s \<subseteq> cball 0 b" using assms(2)[unfolded mem_cball_0[THEN sym]] by auto
himmelma@33175
  4610
  show ?thesis
himmelma@33175
  4611
    using image_closure_subset[OF assms(1) closed_cball[of 0 b] *] assms(3)
himmelma@33175
  4612
    unfolding subset_eq apply(erule_tac x="f x" in ballE) by (auto simp add: dist_norm)
himmelma@33175
  4613
qed
himmelma@33175
  4614
huffman@45081
  4615
text {* Making a continuous function avoid some value in a neighbourhood. *}
himmelma@33175
  4616
himmelma@33175
  4617
lemma continuous_within_avoid:
huffman@51913
  4618
  fixes f :: "'a::metric_space \<Rightarrow> 'b::t1_space"
huffman@51913
  4619
  assumes "continuous (at x within s) f" and "f x \<noteq> a"
himmelma@33175
  4620
  shows "\<exists>e>0. \<forall>y \<in> s. dist x y < e --> f y \<noteq> a"
himmelma@33175
  4621
proof-
huffman@51913
  4622
  obtain U where "open U" and "f x \<in> U" and "a \<notin> U"
huffman@51913
  4623
    using t1_space [OF `f x \<noteq> a`] by fast
huffman@51913
  4624
  have "(f ---> f x) (at x within s)"
huffman@51913
  4625
    using assms(1) by (simp add: continuous_within)
huffman@51913
  4626
  hence "eventually (\<lambda>y. f y \<in> U) (at x within s)"
huffman@51913
  4627
    using `open U` and `f x \<in> U`
huffman@51913
  4628
    unfolding tendsto_def by fast
huffman@51913
  4629
  hence "eventually (\<lambda>y. f y \<noteq> a) (at x within s)"
huffman@51913
  4630
    using `a \<notin> U` by (fast elim: eventually_mono [rotated])
huffman@51913
  4631
  thus ?thesis
huffman@51913
  4632
    unfolding Limits.eventually_within Limits.eventually_at
huffman@51913
  4633
    by (rule ex_forward, cut_tac `f x \<noteq> a`, auto simp: dist_commute)
himmelma@33175
  4634
qed
himmelma@33175
  4635
himmelma@33175
  4636
lemma continuous_at_avoid:
huffman@51913
  4637
  fixes f :: "'a::metric_space \<Rightarrow> 'b::t1_space"
huffman@45896
  4638
  assumes "continuous (at x) f" and "f x \<noteq> a"
himmelma@33175
  4639
  shows "\<exists>e>0. \<forall>y. dist x y < e \<longrightarrow> f y \<noteq> a"
huffman@45896
  4640
  using assms continuous_within_avoid[of x UNIV f a] by simp
himmelma@33175
  4641
himmelma@33175
  4642
lemma continuous_on_avoid:
huffman@51913
  4643
  fixes f :: "'a::metric_space \<Rightarrow> 'b::t1_space"
himmelma@33175
  4644
  assumes "continuous_on s f"  "x \<in> s"  "f x \<noteq> a"
himmelma@33175
  4645
  shows "\<exists>e>0. \<forall>y \<in> s. dist x y < e \<longrightarrow> f y \<noteq> a"
huffman@51913
  4646
using assms(1)[unfolded continuous_on_eq_continuous_within, THEN bspec[where x=x], OF assms(2)]  continuous_within_avoid[of x s f a]  assms(3) by auto
himmelma@33175
  4647
himmelma@33175
  4648
lemma continuous_on_open_avoid:
huffman@51913
  4649
  fixes f :: "'a::metric_space \<Rightarrow> 'b::t1_space"
himmelma@33175
  4650
  assumes "continuous_on s f"  "open s"  "x \<in> s"  "f x \<noteq> a"
himmelma@33175
  4651
  shows "\<exists>e>0. \<forall>y. dist x y < e \<longrightarrow> f y \<noteq> a"
huffman@51913
  4652
using assms(1)[unfolded continuous_on_eq_continuous_at[OF assms(2)], THEN bspec[where x=x], OF assms(3)]  continuous_at_avoid[of x f a]  assms(4) by auto
himmelma@33175
  4653
huffman@45081
  4654
text {* Proving a function is constant by proving open-ness of level set. *}
himmelma@33175
  4655
himmelma@33175
  4656
lemma continuous_levelset_open_in_cases:
huffman@36668
  4657
  fixes f :: "_ \<Rightarrow> 'b::t1_space"
huffman@36355
  4658
  shows "connected s \<Longrightarrow> continuous_on s f \<Longrightarrow>
himmelma@33175
  4659
        openin (subtopology euclidean s) {x \<in> s. f x = a}
himmelma@33175
  4660
        ==> (\<forall>x \<in> s. f x \<noteq> a) \<or> (\<forall>x \<in> s. f x = a)"
himmelma@33175
  4661
unfolding connected_clopen using continuous_closed_in_preimage_constant by auto
himmelma@33175
  4662
himmelma@33175
  4663
lemma continuous_levelset_open_in:
huffman@36668
  4664
  fixes f :: "_ \<Rightarrow> 'b::t1_space"
huffman@36355
  4665
  shows "connected s \<Longrightarrow> continuous_on s f \<Longrightarrow>
himmelma@33175
  4666
        openin (subtopology euclidean s) {x \<in> s. f x = a} \<Longrightarrow>
himmelma@33175
  4667
        (\<exists>x \<in> s. f x = a)  ==> (\<forall>x \<in> s. f x = a)"
himmelma@33175
  4668
using continuous_levelset_open_in_cases[of s f ]
himmelma@33175
  4669
by meson
himmelma@33175
  4670
himmelma@33175
  4671
lemma continuous_levelset_open:
huffman@36668
  4672
  fixes f :: "_ \<Rightarrow> 'b::t1_space"
himmelma@33175
  4673
  assumes "connected s"  "continuous_on s f"  "open {x \<in> s. f x = a}"  "\<exists>x \<in> s.  f x = a"
himmelma@33175
  4674
  shows "\<forall>x \<in> s. f x = a"
huffman@36358
  4675
using continuous_levelset_open_in[OF assms(1,2), of a, unfolded openin_open] using assms (3,4) by fast
himmelma@33175
  4676
huffman@45081
  4677
text {* Some arithmetical combinations (more to prove). *}
himmelma@33175
  4678
himmelma@33175
  4679
lemma open_scaling[intro]:
himmelma@33175
  4680
  fixes s :: "'a::real_normed_vector set"
himmelma@33175
  4681
  assumes "c \<noteq> 0"  "open s"
himmelma@33175
  4682
  shows "open((\<lambda>x. c *\<^sub>R x) ` s)"
himmelma@33175
  4683
proof-
himmelma@33175
  4684
  { fix x assume "x \<in> s"
himmelma@33175
  4685
    then obtain e where "e>0" and e:"\<forall>x'. dist x' x < e \<longrightarrow> x' \<in> s" using assms(2)[unfolded open_dist, THEN bspec[where x=x]] by auto
huffman@36770
  4686
    have "e * abs c > 0" using assms(1)[unfolded zero_less_abs_iff[THEN sym]] using mult_pos_pos[OF `e>0`] by auto
himmelma@33175
  4687
    moreover
himmelma@33175
  4688
    { fix y assume "dist y (c *\<^sub>R x) < e * \<bar>c\<bar>"
himmelma@33175
  4689
      hence "norm ((1 / c) *\<^sub>R y - x) < e" unfolding dist_norm
himmelma@33175
  4690
        using norm_scaleR[of c "(1 / c) *\<^sub>R y - x", unfolded scaleR_right_diff_distrib, unfolded scaleR_scaleR] assms(1)
himmelma@33175
  4691
          assms(1)[unfolded zero_less_abs_iff[THEN sym]] by (simp del:zero_less_abs_iff)
himmelma@33175
  4692
      hence "y \<in> op *\<^sub>R c ` s" using rev_image_eqI[of "(1 / c) *\<^sub>R y" s y "op *\<^sub>R c"]  e[THEN spec[where x="(1 / c) *\<^sub>R y"]]  assms(1) unfolding dist_norm scaleR_scaleR by auto  }
himmelma@33175
  4693
    ultimately have "\<exists>e>0. \<forall>x'. dist x' (c *\<^sub>R x) < e \<longrightarrow> x' \<in> op *\<^sub>R c ` s" apply(rule_tac x="e * abs c" in exI) by auto  }
himmelma@33175
  4694
  thus ?thesis unfolding open_dist by auto
himmelma@33175
  4695
qed
himmelma@33175
  4696
himmelma@33175
  4697
lemma minus_image_eq_vimage:
himmelma@33175
  4698
  fixes A :: "'a::ab_group_add set"
himmelma@33175
  4699
  shows "(\<lambda>x. - x) ` A = (\<lambda>x. - x) -` A"
himmelma@33175
  4700
  by (auto intro!: image_eqI [where f="\<lambda>x. - x"])
himmelma@33175
  4701
himmelma@33175
  4702
lemma open_negations:
himmelma@33175
  4703
  fixes s :: "'a::real_normed_vector set"
himmelma@33175
  4704
  shows "open s ==> open ((\<lambda> x. -x) ` s)"
himmelma@33175
  4705
  unfolding scaleR_minus1_left [symmetric]
himmelma@33175
  4706
  by (rule open_scaling, auto)
himmelma@33175
  4707
himmelma@33175
  4708
lemma open_translation:
himmelma@33175
  4709
  fixes s :: "'a::real_normed_vector set"
himmelma@33175
  4710
  assumes "open s"  shows "open((\<lambda>x. a + x) ` s)"
himmelma@33175
  4711
proof-
huffman@45511
  4712
  { fix x have "continuous (at x) (\<lambda>x. x - a)"
huffman@45511
  4713
      by (intro continuous_diff continuous_at_id continuous_const) }
huffman@45511
  4714
  moreover have "{x. x - a \<in> s} = op + a ` s" by force
himmelma@33175
  4715
  ultimately show ?thesis using continuous_open_preimage_univ[of "\<lambda>x. x - a" s] using assms by auto
himmelma@33175
  4716
qed
himmelma@33175
  4717
himmelma@33175
  4718
lemma open_affinity:
himmelma@33175
  4719
  fixes s :: "'a::real_normed_vector set"
himmelma@33175
  4720
  assumes "open s"  "c \<noteq> 0"
himmelma@33175
  4721
  shows "open ((\<lambda>x. a + c *\<^sub>R x) ` s)"
himmelma@33175
  4722
proof-
himmelma@33175
  4723
  have *:"(\<lambda>x. a + c *\<^sub>R x) = (\<lambda>x. a + x) \<circ> (\<lambda>x. c *\<^sub>R x)" unfolding o_def ..
himmelma@33175
  4724
  have "op + a ` op *\<^sub>R c ` s = (op + a \<circ> op *\<^sub>R c) ` s" by auto
himmelma@33175
  4725
  thus ?thesis using assms open_translation[of "op *\<^sub>R c ` s" a] unfolding * by auto
himmelma@33175
  4726
qed
himmelma@33175
  4727
himmelma@33175
  4728
lemma interior_translation:
himmelma@33175
  4729
  fixes s :: "'a::real_normed_vector set"
himmelma@33175
  4730
  shows "interior ((\<lambda>x. a + x) ` s) = (\<lambda>x. a + x) ` (interior s)"
nipkow@39535
  4731
proof (rule set_eqI, rule)
himmelma@33175
  4732
  fix x assume "x \<in> interior (op + a ` s)"
himmelma@33175
  4733
  then obtain e where "e>0" and e:"ball x e \<subseteq> op + a ` s" unfolding mem_interior by auto
himmelma@33175
  4734
  hence "ball (x - a) e \<subseteq> s" unfolding subset_eq Ball_def mem_ball dist_norm apply auto apply(erule_tac x="a + xa" in allE) unfolding ab_group_add_class.diff_diff_eq[THEN sym] by auto
himmelma@33175
  4735
  thus "x \<in> op + a ` interior s" unfolding image_iff apply(rule_tac x="x - a" in bexI) unfolding mem_interior using `e > 0` by auto
himmelma@33175
  4736
next
himmelma@33175
  4737
  fix x assume "x \<in> op + a ` interior s"
himmelma@33175
  4738
  then obtain y e where "e>0" and e:"ball y e \<subseteq> s" and y:"x = a + y" unfolding image_iff Bex_def mem_interior by auto
himmelma@33175
  4739
  { fix z have *:"a + y - z = y + a - z" by auto
himmelma@33175
  4740
    assume "z\<in>ball x e"
huffman@46419
  4741
    hence "z - a \<in> s" using e[unfolded subset_eq, THEN bspec[where x="z - a"]] unfolding mem_ball dist_norm y group_add_class.diff_diff_eq2 * by auto
himmelma@33175
  4742
    hence "z \<in> op + a ` s" unfolding image_iff by(auto intro!: bexI[where x="z - a"])  }
himmelma@33175
  4743
  hence "ball x e \<subseteq> op + a ` s" unfolding subset_eq by auto
himmelma@33175
  4744
  thus "x \<in> interior (op + a ` s)" unfolding mem_interior using `e>0` by auto
himmelma@33175
  4745
qed
himmelma@33175
  4746
huffman@36433
  4747
text {* Topological properties of linear functions. *}
huffman@36433
  4748
huffman@36433
  4749
lemma linear_lim_0:
huffman@36433
  4750
  assumes "bounded_linear f" shows "(f ---> 0) (at (0))"
huffman@36433
  4751
proof-
huffman@36433
  4752
  interpret f: bounded_linear f by fact
huffman@36433
  4753
  have "(f ---> f 0) (at 0)"
huffman@36433
  4754
    using tendsto_ident_at by (rule f.tendsto)
huffman@36433
  4755
  thus ?thesis unfolding f.zero .
huffman@36433
  4756
qed
huffman@36433
  4757
huffman@36433
  4758
lemma linear_continuous_at:
huffman@36433
  4759
  assumes "bounded_linear f"  shows "continuous (at a) f"
huffman@36433
  4760
  unfolding continuous_at using assms
huffman@36433
  4761
  apply (rule bounded_linear.tendsto)
huffman@36433
  4762
  apply (rule tendsto_ident_at)
huffman@36433
  4763
  done
huffman@36433
  4764
huffman@36433
  4765
lemma linear_continuous_within:
huffman@36433
  4766
  shows "bounded_linear f ==> continuous (at x within s) f"
huffman@36433
  4767
  using continuous_at_imp_continuous_within[of x f s] using linear_continuous_at[of f] by auto
huffman@36433
  4768
huffman@36433
  4769
lemma linear_continuous_on:
huffman@36433
  4770
  shows "bounded_linear f ==> continuous_on s f"
huffman@36433
  4771
  using continuous_at_imp_continuous_on[of s f] using linear_continuous_at[of f] by auto
huffman@36433
  4772
huffman@45081
  4773
text {* Also bilinear functions, in composition form. *}
huffman@36433
  4774
huffman@36433
  4775
lemma bilinear_continuous_at_compose:
huffman@36433
  4776
  shows "continuous (at x) f \<Longrightarrow> continuous (at x) g \<Longrightarrow> bounded_bilinear h
huffman@36433
  4777
        ==> continuous (at x) (\<lambda>x. h (f x) (g x))"
huffman@36433
  4778
  unfolding continuous_at using Lim_bilinear[of f "f x" "(at x)" g "g x" h] by auto
huffman@36433
  4779
huffman@36433
  4780
lemma bilinear_continuous_within_compose:
huffman@36433
  4781
  shows "continuous (at x within s) f \<Longrightarrow> continuous (at x within s) g \<Longrightarrow> bounded_bilinear h
huffman@36433
  4782
        ==> continuous (at x within s) (\<lambda>x. h (f x) (g x))"
huffman@36433
  4783
  unfolding continuous_within using Lim_bilinear[of f "f x"] by auto
huffman@36433
  4784
huffman@36433
  4785
lemma bilinear_continuous_on_compose:
huffman@36433
  4786
  shows "continuous_on s f \<Longrightarrow> continuous_on s g \<Longrightarrow> bounded_bilinear h
huffman@36433
  4787
             ==> continuous_on s (\<lambda>x. h (f x) (g x))"
huffman@36437
  4788
  unfolding continuous_on_def
huffman@36437
  4789
  by (fast elim: bounded_bilinear.tendsto)
huffman@36433
  4790
huffman@45081
  4791
text {* Preservation of compactness and connectedness under continuous function. *}
himmelma@33175
  4792
huffman@51913
  4793
lemma compact_eq_openin_cover:
huffman@51913
  4794
  "compact S \<longleftrightarrow>
huffman@51913
  4795
    (\<forall>C. (\<forall>c\<in>C. openin (subtopology euclidean S) c) \<and> S \<subseteq> \<Union>C \<longrightarrow>
huffman@51913
  4796
      (\<exists>D\<subseteq>C. finite D \<and> S \<subseteq> \<Union>D))"
huffman@51913
  4797
proof safe
huffman@51913
  4798
  fix C
huffman@51913
  4799
  assume "compact S" and "\<forall>c\<in>C. openin (subtopology euclidean S) c" and "S \<subseteq> \<Union>C"
huffman@51913
  4800
  hence "\<forall>c\<in>{T. open T \<and> S \<inter> T \<in> C}. open c" and "S \<subseteq> \<Union>{T. open T \<and> S \<inter> T \<in> C}"
huffman@51913
  4801
    unfolding openin_open by force+
huffman@51913
  4802
  with `compact S` obtain D where "D \<subseteq> {T. open T \<and> S \<inter> T \<in> C}" and "finite D" and "S \<subseteq> \<Union>D"
huffman@51913
  4803
    by (rule compactE)
huffman@51913
  4804
  hence "image (\<lambda>T. S \<inter> T) D \<subseteq> C \<and> finite (image (\<lambda>T. S \<inter> T) D) \<and> S \<subseteq> \<Union>(image (\<lambda>T. S \<inter> T) D)"
huffman@51913
  4805
    by auto
huffman@51913
  4806
  thus "\<exists>D\<subseteq>C. finite D \<and> S \<subseteq> \<Union>D" ..
huffman@51913
  4807
next
huffman@51913
  4808
  assume 1: "\<forall>C. (\<forall>c\<in>C. openin (subtopology euclidean S) c) \<and> S \<subseteq> \<Union>C \<longrightarrow>
huffman@51913
  4809
        (\<exists>D\<subseteq>C. finite D \<and> S \<subseteq> \<Union>D)"
huffman@51913
  4810
  show "compact S"
huffman@51913
  4811
  proof (rule compactI)
huffman@51913
  4812
    fix C
huffman@51913
  4813
    let ?C = "image (\<lambda>T. S \<inter> T) C"
huffman@51913
  4814
    assume "\<forall>t\<in>C. open t" and "S \<subseteq> \<Union>C"
huffman@51913
  4815
    hence "(\<forall>c\<in>?C. openin (subtopology euclidean S) c) \<and> S \<subseteq> \<Union>?C"
huffman@51913
  4816
      unfolding openin_open by auto
huffman@51913
  4817
    with 1 obtain D where "D \<subseteq> ?C" and "finite D" and "S \<subseteq> \<Union>D"
huffman@51913
  4818
      by metis
huffman@51913
  4819
    let ?D = "inv_into C (\<lambda>T. S \<inter> T) ` D"
huffman@51913
  4820
    have "?D \<subseteq> C \<and> finite ?D \<and> S \<subseteq> \<Union>?D"
huffman@51913
  4821
    proof (intro conjI)
huffman@51913
  4822
      from `D \<subseteq> ?C` show "?D \<subseteq> C"
huffman@51913
  4823
        by (fast intro: inv_into_into)
huffman@51913
  4824
      from `finite D` show "finite ?D"
huffman@51913
  4825
        by (rule finite_imageI)
huffman@51913
  4826
      from `S \<subseteq> \<Union>D` show "S \<subseteq> \<Union>?D"
huffman@51913
  4827
        apply (rule subset_trans)
huffman@51913
  4828
        apply clarsimp
huffman@51913
  4829
        apply (frule subsetD [OF `D \<subseteq> ?C`, THEN f_inv_into_f])
huffman@51913
  4830
        apply (erule rev_bexI, fast)
huffman@51913
  4831
        done
huffman@51913
  4832
    qed
huffman@51913
  4833
    thus "\<exists>D\<subseteq>C. finite D \<and> S \<subseteq> \<Union>D" ..
huffman@51913
  4834
  qed
huffman@51913
  4835
qed
huffman@51913
  4836
himmelma@33175
  4837
lemma compact_continuous_image:
huffman@51913
  4838
  assumes "continuous_on s f" and "compact s"
huffman@51913
  4839
  shows "compact (f ` s)"
huffman@51913
  4840
using assms (* FIXME: long unstructured proof *)
huffman@51913
  4841
unfolding continuous_on_open
huffman@51913
  4842
unfolding compact_eq_openin_cover
huffman@51913
  4843
apply clarify
huffman@51913
  4844
apply (drule_tac x="image (\<lambda>t. {x \<in> s. f x \<in> t}) C" in spec)
huffman@51913
  4845
apply (drule mp)
huffman@51913
  4846
apply (rule conjI)
huffman@51913
  4847
apply simp
huffman@51913
  4848
apply clarsimp
huffman@51913
  4849
apply (drule subsetD)
huffman@51913
  4850
apply (erule imageI)
huffman@51913
  4851
apply fast
huffman@51913
  4852
apply (erule thin_rl)
huffman@51913
  4853
apply clarify
huffman@51913
  4854
apply (rule_tac x="image (inv_into C (\<lambda>t. {x \<in> s. f x \<in> t})) D" in exI)
huffman@51913
  4855
apply (intro conjI)
huffman@51913
  4856
apply clarify
huffman@51913
  4857
apply (rule inv_into_into)
huffman@51913
  4858
apply (erule (1) subsetD)
huffman@51913
  4859
apply (erule finite_imageI)
huffman@51913
  4860
apply (clarsimp, rename_tac x)
huffman@51913
  4861
apply (drule (1) subsetD, clarify)
huffman@51913
  4862
apply (drule (1) subsetD, clarify)
huffman@51913
  4863
apply (rule rev_bexI)
huffman@51913
  4864
apply assumption
huffman@51913
  4865
apply (subgoal_tac "{x \<in> s. f x \<in> t} \<in> (\<lambda>t. {x \<in> s. f x \<in> t}) ` C")
huffman@51913
  4866
apply (drule f_inv_into_f)
huffman@51913
  4867
apply fast
huffman@51913
  4868
apply (erule imageI)
huffman@51913
  4869
done
himmelma@33175
  4870
himmelma@33175
  4871
lemma connected_continuous_image:
himmelma@33175
  4872
  assumes "continuous_on s f"  "connected s"
himmelma@33175
  4873
  shows "connected(f ` s)"
himmelma@33175
  4874
proof-
himmelma@33175
  4875
  { fix T assume as: "T \<noteq> {}"  "T \<noteq> f ` s"  "openin (subtopology euclidean (f ` s)) T"  "closedin (subtopology euclidean (f ` s)) T"
himmelma@33175
  4876
    have "{x \<in> s. f x \<in> T} = {} \<or> {x \<in> s. f x \<in> T} = s"
himmelma@33175
  4877
      using assms(1)[unfolded continuous_on_open, THEN spec[where x=T]]
himmelma@33175
  4878
      using assms(1)[unfolded continuous_on_closed, THEN spec[where x=T]]
himmelma@33175
  4879
      using assms(2)[unfolded connected_clopen, THEN spec[where x="{x \<in> s. f x \<in> T}"]] as(3,4) by auto
himmelma@33175
  4880
    hence False using as(1,2)
himmelma@33175
  4881
      using as(4)[unfolded closedin_def topspace_euclidean_subtopology] by auto }
himmelma@33175
  4882
  thus ?thesis unfolding connected_clopen by auto
himmelma@33175
  4883
qed
himmelma@33175
  4884
huffman@45081
  4885
text {* Continuity implies uniform continuity on a compact domain. *}
hoelzl@51958
  4886
  
himmelma@33175
  4887
lemma compact_uniformly_continuous:
hoelzl@51958
  4888
  assumes f: "continuous_on s f" and s: "compact s"
himmelma@33175
  4889
  shows "uniformly_continuous_on s f"
hoelzl@51958
  4890
  unfolding uniformly_continuous_on_def
hoelzl@51958
  4891
proof (cases, safe)
hoelzl@51958
  4892
  fix e :: real assume "0 < e" "s \<noteq> {}"
hoelzl@51958
  4893
  def [simp]: R \<equiv> "{(y, d). y \<in> s \<and> 0 < d \<and> ball y d \<inter> s \<subseteq> {x \<in> s. f x \<in> ball (f y) (e/2) } }"
hoelzl@51959
  4894
  let ?b = "(\<lambda>(y, d). ball y (d/2))"
hoelzl@51959
  4895
  have "(\<forall>r\<in>R. open (?b r))" "s \<subseteq> (\<Union>r\<in>R. ?b r)"
hoelzl@51958
  4896
  proof safe
hoelzl@51958
  4897
    fix y assume "y \<in> s"
hoelzl@51958
  4898
    from continuous_open_in_preimage[OF f open_ball]
hoelzl@51958
  4899
    obtain T where "open T" and T: "{x \<in> s. f x \<in> ball (f y) (e/2)} = T \<inter> s"
hoelzl@51958
  4900
      unfolding openin_subtopology open_openin by metis
hoelzl@51958
  4901
    then obtain d where "ball y d \<subseteq> T" "0 < d"
hoelzl@51958
  4902
      using `0 < e` `y \<in> s` by (auto elim!: openE)
hoelzl@51959
  4903
    with T `y \<in> s` show "y \<in> (\<Union>r\<in>R. ?b r)"
hoelzl@51959
  4904
      by (intro UN_I[of "(y, d)"]) auto
hoelzl@51958
  4905
  qed auto
hoelzl@51959
  4906
  with s obtain D where D: "finite D" "D \<subseteq> R" "s \<subseteq> (\<Union>(y, d)\<in>D. ball y (d/2))"
hoelzl@51959
  4907
    by (rule compactE_image)
hoelzl@51958
  4908
  with `s \<noteq> {}` have [simp]: "\<And>x. x < Min (snd ` D) \<longleftrightarrow> (\<forall>(y, d)\<in>D. x < d)"
hoelzl@51958
  4909
    by (subst Min_gr_iff) auto
hoelzl@51958
  4910
  show "\<exists>d>0. \<forall>x\<in>s. \<forall>x'\<in>s. dist x' x < d \<longrightarrow> dist (f x') (f x) < e"
hoelzl@51958
  4911
  proof (rule, safe)
hoelzl@51958
  4912
    fix x x' assume in_s: "x' \<in> s" "x \<in> s"
hoelzl@51958
  4913
    with D obtain y d where x: "x \<in> ball y (d/2)" "(y, d) \<in> D"
hoelzl@51958
  4914
      by blast
hoelzl@51958
  4915
    moreover assume "dist x x' < Min (snd`D) / 2"
hoelzl@51958
  4916
    ultimately have "dist y x' < d"
hoelzl@51958
  4917
      by (intro dist_double[where x=x and d=d]) (auto simp: dist_commute)
hoelzl@51958
  4918
    with D x in_s show  "dist (f x) (f x') < e"
hoelzl@51958
  4919
      by (intro dist_double[where x="f y" and d=e]) (auto simp: dist_commute subset_eq)
hoelzl@51958
  4920
  qed (insert D, auto)
hoelzl@51958
  4921
qed auto
himmelma@33175
  4922
himmelma@33175
  4923
text{* Continuity of inverse function on compact domain. *}
himmelma@33175
  4924
huffman@45511
  4925
lemma continuous_on_inv:
huffman@51913
  4926
  fixes f :: "'a::topological_space \<Rightarrow> 'b::t2_space"
himmelma@33175
  4927
  assumes "continuous_on s f"  "compact s"  "\<forall>x \<in> s. g (f x) = x"
himmelma@33175
  4928
  shows "continuous_on (f ` s) g"
huffman@51913
  4929
unfolding continuous_on_topological
huffman@51913
  4930
proof (clarsimp simp add: assms(3))
huffman@51913
  4931
  fix x :: 'a and B :: "'a set"
huffman@51913
  4932
  assume "x \<in> s" and "open B" and "x \<in> B"
huffman@51913
  4933
  have 1: "\<forall>x\<in>s. f x \<in> f ` (s - B) \<longleftrightarrow> x \<in> s - B"
huffman@51913
  4934
    using assms(3) by (auto, metis)
huffman@51913
  4935
  have "continuous_on (s - B) f"
huffman@51913
  4936
    using `continuous_on s f` Diff_subset
huffman@51913
  4937
    by (rule continuous_on_subset)
huffman@51913
  4938
  moreover have "compact (s - B)"
huffman@51913
  4939
    using `open B` and `compact s`
huffman@51913
  4940
    unfolding Diff_eq by (intro compact_inter_closed closed_Compl)
huffman@51913
  4941
  ultimately have "compact (f ` (s - B))"
huffman@51913
  4942
    by (rule compact_continuous_image)
huffman@51913
  4943
  hence "closed (f ` (s - B))"
huffman@51913
  4944
    by (rule compact_imp_closed)
huffman@51913
  4945
  hence "open (- f ` (s - B))"
huffman@51913
  4946
    by (rule open_Compl)
huffman@51913
  4947
  moreover have "f x \<in> - f ` (s - B)"
huffman@51913
  4948
    using `x \<in> s` and `x \<in> B` by (simp add: 1)
huffman@51913
  4949
  moreover have "\<forall>y\<in>s. f y \<in> - f ` (s - B) \<longrightarrow> y \<in> B"
huffman@51913
  4950
    by (simp add: 1)
huffman@51913
  4951
  ultimately show "\<exists>A. open A \<and> f x \<in> A \<and> (\<forall>y\<in>s. f y \<in> A \<longrightarrow> y \<in> B)"
huffman@51913
  4952
    by fast
himmelma@33175
  4953
qed
himmelma@33175
  4954
huffman@36433
  4955
text {* A uniformly convergent limit of continuous functions is continuous. *}
himmelma@33175
  4956
himmelma@33175
  4957
lemma continuous_uniform_limit:
huffman@45083
  4958
  fixes f :: "'a \<Rightarrow> 'b::metric_space \<Rightarrow> 'c::metric_space"
huffman@45083
  4959
  assumes "\<not> trivial_limit F"
huffman@45083
  4960
  assumes "eventually (\<lambda>n. continuous_on s (f n)) F"
huffman@45083
  4961
  assumes "\<forall>e>0. eventually (\<lambda>n. \<forall>x\<in>s. dist (f n x) (g x) < e) F"
himmelma@33175
  4962
  shows "continuous_on s g"
himmelma@33175
  4963
proof-
himmelma@33175
  4964
  { fix x and e::real assume "x\<in>s" "e>0"
huffman@45083
  4965
    have "eventually (\<lambda>n. \<forall>x\<in>s. dist (f n x) (g x) < e / 3) F"
huffman@45083
  4966
      using `e>0` assms(3)[THEN spec[where x="e/3"]] by auto
huffman@45083
  4967
    from eventually_happens [OF eventually_conj [OF this assms(2)]]
huffman@45083
  4968
    obtain n where n:"\<forall>x\<in>s. dist (f n x) (g x) < e / 3"  "continuous_on s (f n)"
huffman@45083
  4969
      using assms(1) by blast
himmelma@33175
  4970
    have "e / 3 > 0" using `e>0` by auto
himmelma@33175
  4971
    then obtain d where "d>0" and d:"\<forall>x'\<in>s. dist x' x < d \<longrightarrow> dist (f n x') (f n x) < e / 3"
huffman@36355
  4972
      using n(2)[unfolded continuous_on_iff, THEN bspec[where x=x], OF `x\<in>s`, THEN spec[where x="e/3"]] by blast
huffman@45083
  4973
    { fix y assume "y \<in> s" and "dist y x < d"
huffman@45083
  4974
      hence "dist (f n y) (f n x) < e / 3"
huffman@45083
  4975
        by (rule d [rule_format])
huffman@45083
  4976
      hence "dist (f n y) (g x) < 2 * e / 3"
huffman@45083
  4977
        using dist_triangle [of "f n y" "g x" "f n x"]
huffman@45083
  4978
        using n(1)[THEN bspec[where x=x], OF `x\<in>s`]
huffman@45083
  4979
        by auto
huffman@45083
  4980
      hence "dist (g y) (g x) < e"
huffman@45083
  4981
        using n(1)[THEN bspec[where x=y], OF `y\<in>s`]
huffman@45083
  4982
        using dist_triangle3 [of "g y" "g x" "f n y"]
huffman@45083
  4983
        by auto }
huffman@45083
  4984
    hence "\<exists>d>0. \<forall>x'\<in>s. dist x' x < d \<longrightarrow> dist (g x') (g x) < e"
huffman@45083
  4985
      using `d>0` by auto }
huffman@36355
  4986
  thus ?thesis unfolding continuous_on_iff by auto
himmelma@33175
  4987
qed
himmelma@33175
  4988
huffman@45081
  4989
huffman@45081
  4990
subsection {* Topological stuff lifted from and dropped to R *}
himmelma@33175
  4991
himmelma@33175
  4992
lemma open_real:
himmelma@33175
  4993
  fixes s :: "real set" shows
himmelma@33175
  4994
 "open s \<longleftrightarrow>
himmelma@33175
  4995
        (\<forall>x \<in> s. \<exists>e>0. \<forall>x'. abs(x' - x) < e --> x' \<in> s)" (is "?lhs = ?rhs")
himmelma@33175
  4996
  unfolding open_dist dist_norm by simp
himmelma@33175
  4997
himmelma@33175
  4998
lemma islimpt_approachable_real:
himmelma@33175
  4999
  fixes s :: "real set"
himmelma@33175
  5000
  shows "x islimpt s \<longleftrightarrow> (\<forall>e>0.  \<exists>x'\<in> s. x' \<noteq> x \<and> abs(x' - x) < e)"
himmelma@33175
  5001
  unfolding islimpt_approachable dist_norm by simp
himmelma@33175
  5002
himmelma@33175
  5003
lemma closed_real:
himmelma@33175
  5004
  fixes s :: "real set"
himmelma@33175
  5005
  shows "closed s \<longleftrightarrow>
himmelma@33175
  5006
        (\<forall>x. (\<forall>e>0.  \<exists>x' \<in> s. x' \<noteq> x \<and> abs(x' - x) < e)
himmelma@33175
  5007
            --> x \<in> s)"
himmelma@33175
  5008
  unfolding closed_limpt islimpt_approachable dist_norm by simp
himmelma@33175
  5009
himmelma@33175
  5010
lemma continuous_at_real_range:
himmelma@33175
  5011
  fixes f :: "'a::real_normed_vector \<Rightarrow> real"
himmelma@33175
  5012
  shows "continuous (at x) f \<longleftrightarrow> (\<forall>e>0. \<exists>d>0.
himmelma@33175
  5013
        \<forall>x'. norm(x' - x) < d --> abs(f x' - f x) < e)"
himmelma@33175
  5014
  unfolding continuous_at unfolding Lim_at
himmelma@33175
  5015
  unfolding dist_nz[THEN sym] unfolding dist_norm apply auto
himmelma@33175
  5016
  apply(erule_tac x=e in allE) apply auto apply (rule_tac x=d in exI) apply auto apply (erule_tac x=x' in allE) apply auto
himmelma@33175
  5017
  apply(erule_tac x=e in allE) by auto
himmelma@33175
  5018
himmelma@33175
  5019
lemma continuous_on_real_range:
himmelma@33175
  5020
  fixes f :: "'a::real_normed_vector \<Rightarrow> real"
himmelma@33175
  5021
  shows "continuous_on s f \<longleftrightarrow> (\<forall>x \<in> s. \<forall>e>0. \<exists>d>0. (\<forall>x' \<in> s. norm(x' - x) < d --> abs(f x' - f x) < e))"
huffman@36355
  5022
  unfolding continuous_on_iff dist_norm by simp
himmelma@33175
  5023
huffman@45081
  5024
text {* Hence some handy theorems on distance, diameter etc. of/from a set. *}
himmelma@33175
  5025
himmelma@33175
  5026
lemma compact_attains_sup:
himmelma@33175
  5027
  fixes s :: "real set"
himmelma@33175
  5028
  assumes "compact s"  "s \<noteq> {}"
himmelma@33175
  5029
  shows "\<exists>x \<in> s. \<forall>y \<in> s. y \<le> x"
himmelma@33175
  5030
proof-
himmelma@33175
  5031
  from assms(1) have a:"bounded s" "closed s" unfolding compact_eq_bounded_closed by auto
paulson@33270
  5032
  { fix e::real assume as: "\<forall>x\<in>s. x \<le> Sup s" "Sup s \<notin> s"  "0 < e" "\<forall>x'\<in>s. x' = Sup s \<or> \<not> Sup s - x' < e"
paulson@33270
  5033
    have "isLub UNIV s (Sup s)" using Sup[OF assms(2)] unfolding setle_def using as(1) by auto
paulson@33270
  5034
    moreover have "isUb UNIV s (Sup s - e)" unfolding isUb_def unfolding setle_def using as(4,2) by auto
paulson@33270
  5035
    ultimately have False using isLub_le_isUb[of UNIV s "Sup s" "Sup s - e"] using `e>0` by auto  }
paulson@33270
  5036
  thus ?thesis using bounded_has_Sup(1)[OF a(1) assms(2)] using a(2)[unfolded closed_real, THEN spec[where x="Sup s"]]
paulson@33270
  5037
    apply(rule_tac x="Sup s" in bexI) by auto
paulson@33270
  5038
qed
paulson@33270
  5039
paulson@33270
  5040
lemma Inf:
paulson@33270
  5041
  fixes S :: "real set"
paulson@33270
  5042
  shows "S \<noteq> {} ==> (\<exists>b. b <=* S) ==> isGlb UNIV S (Inf S)"
paulson@33270
  5043
by (auto simp add: isLb_def setle_def setge_def isGlb_def greatestP_def) 
himmelma@33175
  5044
himmelma@33175
  5045
lemma compact_attains_inf:
himmelma@33175
  5046
  fixes s :: "real set"
himmelma@33175
  5047
  assumes "compact s" "s \<noteq> {}"  shows "\<exists>x \<in> s. \<forall>y \<in> s. x \<le> y"
himmelma@33175
  5048
proof-
himmelma@33175
  5049
  from assms(1) have a:"bounded s" "closed s" unfolding compact_eq_bounded_closed by auto
paulson@33270
  5050
  { fix e::real assume as: "\<forall>x\<in>s. x \<ge> Inf s"  "Inf s \<notin> s"  "0 < e"
paulson@33270
  5051
      "\<forall>x'\<in>s. x' = Inf s \<or> \<not> abs (x' - Inf s) < e"
paulson@33270
  5052
    have "isGlb UNIV s (Inf s)" using Inf[OF assms(2)] unfolding setge_def using as(1) by auto
himmelma@33175
  5053
    moreover
himmelma@33175
  5054
    { fix x assume "x \<in> s"
paulson@33270
  5055
      hence *:"abs (x - Inf s) = x - Inf s" using as(1)[THEN bspec[where x=x]] by auto
paulson@33270
  5056
      have "Inf s + e \<le> x" using as(4)[THEN bspec[where x=x]] using as(2) `x\<in>s` unfolding * by auto }
paulson@33270
  5057
    hence "isLb UNIV s (Inf s + e)" unfolding isLb_def and setge_def by auto
paulson@33270
  5058
    ultimately have False using isGlb_le_isLb[of UNIV s "Inf s" "Inf s + e"] using `e>0` by auto  }
paulson@33270
  5059
  thus ?thesis using bounded_has_Inf(1)[OF a(1) assms(2)] using a(2)[unfolded closed_real, THEN spec[where x="Inf s"]]
paulson@33270
  5060
    apply(rule_tac x="Inf s" in bexI) by auto
himmelma@33175
  5061
qed
himmelma@33175
  5062
himmelma@33175
  5063
lemma continuous_attains_sup:
huffman@51963
  5064
  fixes f :: "'a::topological_space \<Rightarrow> real"
himmelma@33175
  5065
  shows "compact s \<Longrightarrow> s \<noteq> {} \<Longrightarrow> continuous_on s f
himmelma@33175
  5066
        ==> (\<exists>x \<in> s. \<forall>y \<in> s.  f y \<le> f x)"
himmelma@33175
  5067
  using compact_attains_sup[of "f ` s"]
himmelma@33175
  5068
  using compact_continuous_image[of s f] by auto
himmelma@33175
  5069
himmelma@33175
  5070
lemma continuous_attains_inf:
huffman@51963
  5071
  fixes f :: "'a::topological_space \<Rightarrow> real"
himmelma@33175
  5072
  shows "compact s \<Longrightarrow> s \<noteq> {} \<Longrightarrow> continuous_on s f
himmelma@33175
  5073
        \<Longrightarrow> (\<exists>x \<in> s. \<forall>y \<in> s. f x \<le> f y)"
himmelma@33175
  5074
  using compact_attains_inf[of "f ` s"]
himmelma@33175
  5075
  using compact_continuous_image[of s f] by auto
himmelma@33175
  5076
himmelma@33175
  5077
lemma distance_attains_sup:
himmelma@33175
  5078
  assumes "compact s" "s \<noteq> {}"
himmelma@33175
  5079
  shows "\<exists>x \<in> s. \<forall>y \<in> s. dist a y \<le> dist a x"
himmelma@33175
  5080
proof (rule continuous_attains_sup [OF assms])
himmelma@33175
  5081
  { fix x assume "x\<in>s"
himmelma@33175
  5082
    have "(dist a ---> dist a x) (at x within s)"
huffman@45439
  5083
      by (intro tendsto_dist tendsto_const Lim_at_within tendsto_ident_at)
himmelma@33175
  5084
  }
himmelma@33175
  5085
  thus "continuous_on s (dist a)"
himmelma@33175
  5086
    unfolding continuous_on ..
himmelma@33175
  5087
qed
himmelma@33175
  5088
huffman@45081
  5089
text {* For \emph{minimal} distance, we only need closure, not compactness. *}
himmelma@33175
  5090
himmelma@33175
  5091
lemma distance_attains_inf:
himmelma@33175
  5092
  fixes a :: "'a::heine_borel"
himmelma@33175
  5093
  assumes "closed s"  "s \<noteq> {}"
himmelma@33175
  5094
  shows "\<exists>x \<in> s. \<forall>y \<in> s. dist a x \<le> dist a y"
himmelma@33175
  5095
proof-
himmelma@33175
  5096
  from assms(2) obtain b where "b\<in>s" by auto
himmelma@33175
  5097
  let ?B = "cball a (dist b a) \<inter> s"
himmelma@33175
  5098
  have "b \<in> ?B" using `b\<in>s` by (simp add: dist_commute)
himmelma@33175
  5099
  hence "?B \<noteq> {}" by auto
himmelma@33175
  5100
  moreover
himmelma@33175
  5101
  { fix x assume "x\<in>?B"
himmelma@33175
  5102
    fix e::real assume "e>0"
himmelma@33175
  5103
    { fix x' assume "x'\<in>?B" and as:"dist x' x < e"
himmelma@33175
  5104
      from as have "\<bar>dist a x' - dist a x\<bar> < e"
himmelma@33175
  5105
        unfolding abs_less_iff minus_diff_eq
himmelma@33175
  5106
        using dist_triangle2 [of a x' x]
himmelma@33175
  5107
        using dist_triangle [of a x x']
himmelma@33175
  5108
        by arith
himmelma@33175
  5109
    }
himmelma@33175
  5110
    hence "\<exists>d>0. \<forall>x'\<in>?B. dist x' x < d \<longrightarrow> \<bar>dist a x' - dist a x\<bar> < e"
himmelma@33175
  5111
      using `e>0` by auto
himmelma@33175
  5112
  }
himmelma@33175
  5113
  hence "continuous_on (cball a (dist b a) \<inter> s) (dist a)"
himmelma@33175
  5114
    unfolding continuous_on Lim_within dist_norm real_norm_def
himmelma@33175
  5115
    by fast
himmelma@33175
  5116
  moreover have "compact ?B"
himmelma@33175
  5117
    using compact_cball[of a "dist b a"]
himmelma@33175
  5118
    unfolding compact_eq_bounded_closed
himmelma@33175
  5119
    using bounded_Int and closed_Int and assms(1) by auto
himmelma@33175
  5120
  ultimately obtain x where "x\<in>cball a (dist b a) \<inter> s" "\<forall>y\<in>cball a (dist b a) \<inter> s. dist a x \<le> dist a y"
nipkow@45761
  5121
    using continuous_attains_inf[of ?B "dist a"] by fastforce
nipkow@45761
  5122
  thus ?thesis by fastforce
himmelma@33175
  5123
qed
himmelma@33175
  5124
huffman@45081
  5125
huffman@36433
  5126
subsection {* Pasted sets *}
himmelma@33175
  5127
himmelma@33175
  5128
lemma bounded_Times:
himmelma@33175
  5129
  assumes "bounded s" "bounded t" shows "bounded (s \<times> t)"
himmelma@33175
  5130
proof-
himmelma@33175
  5131
  obtain x y a b where "\<forall>z\<in>s. dist x z \<le> a" "\<forall>z\<in>t. dist y z \<le> b"
himmelma@33175
  5132
    using assms [unfolded bounded_def] by auto
himmelma@33175
  5133
  then have "\<forall>z\<in>s \<times> t. dist (x, y) z \<le> sqrt (a\<twosuperior> + b\<twosuperior>)"
himmelma@33175
  5134
    by (auto simp add: dist_Pair_Pair real_sqrt_le_mono add_mono power_mono)
himmelma@33175
  5135
  thus ?thesis unfolding bounded_any_center [where a="(x, y)"] by auto
himmelma@33175
  5136
qed
himmelma@33175
  5137
himmelma@33175
  5138
lemma mem_Times_iff: "x \<in> A \<times> B \<longleftrightarrow> fst x \<in> A \<and> snd x \<in> B"
himmelma@33175
  5139
by (induct x) simp
himmelma@33175
  5140
hoelzl@51899
  5141
lemma seq_compact_Times: "seq_compact s \<Longrightarrow> seq_compact t \<Longrightarrow> seq_compact (s \<times> t)"
hoelzl@51899
  5142
unfolding seq_compact_def
himmelma@33175
  5143
apply clarify
himmelma@33175
  5144
apply (drule_tac x="fst \<circ> f" in spec)
himmelma@33175
  5145
apply (drule mp, simp add: mem_Times_iff)
himmelma@33175
  5146
apply (clarify, rename_tac l1 r1)
himmelma@33175
  5147
apply (drule_tac x="snd \<circ> f \<circ> r1" in spec)
himmelma@33175
  5148
apply (drule mp, simp add: mem_Times_iff)
himmelma@33175
  5149
apply (clarify, rename_tac l2 r2)
himmelma@33175
  5150
apply (rule_tac x="(l1, l2)" in rev_bexI, simp)
himmelma@33175
  5151
apply (rule_tac x="r1 \<circ> r2" in exI)
himmelma@33175
  5152
apply (rule conjI, simp add: subseq_def)
wenzelm@49140
  5153
apply (drule_tac r=r2 in lim_subseq [rotated], assumption)
himmelma@33175
  5154
apply (drule (1) tendsto_Pair) back
himmelma@33175
  5155
apply (simp add: o_def)
himmelma@33175
  5156
done
himmelma@33175
  5157
hoelzl@51899
  5158
text {* Generalize to @{class topological_space} *}
hoelzl@51899
  5159
lemma compact_Times: 
hoelzl@51899
  5160
  fixes s :: "'a::metric_space set" and t :: "'b::metric_space set"
hoelzl@51899
  5161
  shows "compact s \<Longrightarrow> compact t \<Longrightarrow> compact (s \<times> t)"
hoelzl@51899
  5162
  unfolding compact_eq_seq_compact_metric by (rule seq_compact_Times)
hoelzl@51899
  5163
huffman@45081
  5164
text{* Hence some useful properties follow quite easily. *}
himmelma@33175
  5165
himmelma@33175
  5166
lemma compact_scaling:
himmelma@33175
  5167
  fixes s :: "'a::real_normed_vector set"
himmelma@33175
  5168
  assumes "compact s"  shows "compact ((\<lambda>x. c *\<^sub>R x) ` s)"
himmelma@33175
  5169
proof-
himmelma@33175
  5170
  let ?f = "\<lambda>x. scaleR c x"
huffman@45145
  5171
  have *:"bounded_linear ?f" by (rule bounded_linear_scaleR_right)
himmelma@33175
  5172
  show ?thesis using compact_continuous_image[of s ?f] continuous_at_imp_continuous_on[of s ?f]
himmelma@33175
  5173
    using linear_continuous_at[OF *] assms by auto
himmelma@33175
  5174
qed
himmelma@33175
  5175
himmelma@33175
  5176
lemma compact_negations:
himmelma@33175
  5177
  fixes s :: "'a::real_normed_vector set"
himmelma@33175
  5178
  assumes "compact s"  shows "compact ((\<lambda>x. -x) ` s)"
himmelma@33175
  5179
  using compact_scaling [OF assms, of "- 1"] by auto
himmelma@33175
  5180
himmelma@33175
  5181
lemma compact_sums:
himmelma@33175
  5182
  fixes s t :: "'a::real_normed_vector set"
himmelma@33175
  5183
  assumes "compact s"  "compact t"  shows "compact {x + y | x y. x \<in> s \<and> y \<in> t}"
himmelma@33175
  5184
proof-
himmelma@33175
  5185
  have *:"{x + y | x y. x \<in> s \<and> y \<in> t} = (\<lambda>z. fst z + snd z) ` (s \<times> t)"
himmelma@33175
  5186
    apply auto unfolding image_iff apply(rule_tac x="(xa, y)" in bexI) by auto
himmelma@33175
  5187
  have "continuous_on (s \<times> t) (\<lambda>z. fst z + snd z)"
himmelma@33175
  5188
    unfolding continuous_on by (rule ballI) (intro tendsto_intros)
himmelma@33175
  5189
  thus ?thesis unfolding * using compact_continuous_image compact_Times [OF assms] by auto
himmelma@33175
  5190
qed
himmelma@33175
  5191
himmelma@33175
  5192
lemma compact_differences:
himmelma@33175
  5193
  fixes s t :: "'a::real_normed_vector set"
himmelma@33175
  5194
  assumes "compact s" "compact t"  shows "compact {x - y | x y. x \<in> s \<and> y \<in> t}"
himmelma@33175
  5195
proof-
himmelma@33175
  5196
  have "{x - y | x y. x\<in>s \<and> y \<in> t} =  {x + y | x y. x \<in> s \<and> y \<in> (uminus ` t)}"
himmelma@33175
  5197
    apply auto apply(rule_tac x= xa in exI) apply auto apply(rule_tac x=xa in exI) by auto
himmelma@33175
  5198
  thus ?thesis using compact_sums[OF assms(1) compact_negations[OF assms(2)]] by auto
himmelma@33175
  5199
qed
himmelma@33175
  5200
himmelma@33175
  5201
lemma compact_translation:
himmelma@33175
  5202
  fixes s :: "'a::real_normed_vector set"
himmelma@33175
  5203
  assumes "compact s"  shows "compact ((\<lambda>x. a + x) ` s)"
himmelma@33175
  5204
proof-
himmelma@33175
  5205
  have "{x + y |x y. x \<in> s \<and> y \<in> {a}} = (\<lambda>x. a + x) ` s" by auto
himmelma@33175
  5206
  thus ?thesis using compact_sums[OF assms compact_sing[of a]] by auto
himmelma@33175
  5207
qed
himmelma@33175
  5208
himmelma@33175
  5209
lemma compact_affinity:
himmelma@33175
  5210
  fixes s :: "'a::real_normed_vector set"
himmelma@33175
  5211
  assumes "compact s"  shows "compact ((\<lambda>x. a + c *\<^sub>R x) ` s)"
himmelma@33175
  5212
proof-
himmelma@33175
  5213
  have "op + a ` op *\<^sub>R c ` s = (\<lambda>x. a + c *\<^sub>R x) ` s" by auto
himmelma@33175
  5214
  thus ?thesis using compact_translation[OF compact_scaling[OF assms], of a c] by auto
himmelma@33175
  5215
qed
himmelma@33175
  5216
huffman@45081
  5217
text {* Hence we get the following. *}
himmelma@33175
  5218
himmelma@33175
  5219
lemma compact_sup_maxdistance:
himmelma@33175
  5220
  fixes s :: "'a::real_normed_vector set"
himmelma@33175
  5221
  assumes "compact s"  "s \<noteq> {}"
himmelma@33175
  5222
  shows "\<exists>x\<in>s. \<exists>y\<in>s. \<forall>u\<in>s. \<forall>v\<in>s. norm(u - v) \<le> norm(x - y)"
himmelma@33175
  5223
proof-
himmelma@33175
  5224
  have "{x - y | x y . x\<in>s \<and> y\<in>s} \<noteq> {}" using `s \<noteq> {}` by auto
himmelma@33175
  5225
  then obtain x where x:"x\<in>{x - y |x y. x \<in> s \<and> y \<in> s}"  "\<forall>y\<in>{x - y |x y. x \<in> s \<and> y \<in> s}. norm y \<le> norm x"
himmelma@33175
  5226
    using compact_differences[OF assms(1) assms(1)]
huffman@36358
  5227
    using distance_attains_sup[where 'a="'a", unfolded dist_norm, of "{x - y | x y . x\<in>s \<and> y\<in>s}" 0] by auto
himmelma@33175
  5228
  from x(1) obtain a b where "a\<in>s" "b\<in>s" "x = a - b" by auto
himmelma@33175
  5229
  thus ?thesis using x(2)[unfolded `x = a - b`] by blast
himmelma@33175
  5230
qed
himmelma@33175
  5231
huffman@45081
  5232
text {* We can state this in terms of diameter of a set. *}
himmelma@33175
  5233
paulson@33270
  5234
definition "diameter s = (if s = {} then 0::real else Sup {norm(x - y) | x y. x \<in> s \<and> y \<in> s})"
himmelma@33175
  5235
  (* TODO: generalize to class metric_space *)
himmelma@33175
  5236
himmelma@33175
  5237
lemma diameter_bounded:
himmelma@33175
  5238
  assumes "bounded s"
himmelma@33175
  5239
  shows "\<forall>x\<in>s. \<forall>y\<in>s. norm(x - y) \<le> diameter s"
himmelma@33175
  5240
        "\<forall>d>0. d < diameter s --> (\<exists>x\<in>s. \<exists>y\<in>s. norm(x - y) > d)"
himmelma@33175
  5241
proof-
himmelma@33175
  5242
  let ?D = "{norm (x - y) |x y. x \<in> s \<and> y \<in> s}"
himmelma@33175
  5243
  obtain a where a:"\<forall>x\<in>s. norm x \<le> a" using assms[unfolded bounded_iff] by auto
himmelma@33175
  5244
  { fix x y assume "x \<in> s" "y \<in> s"
haftmann@36349
  5245
    hence "norm (x - y) \<le> 2 * a" using norm_triangle_ineq[of x "-y", unfolded norm_minus_cancel] a[THEN bspec[where x=x]] a[THEN bspec[where x=y]] by (auto simp add: field_simps)  }
himmelma@33175
  5246
  note * = this
himmelma@33175
  5247
  { fix x y assume "x\<in>s" "y\<in>s"  hence "s \<noteq> {}" by auto
huffman@36358
  5248
    have "norm(x - y) \<le> diameter s" unfolding diameter_def using `s\<noteq>{}` *[OF `x\<in>s` `y\<in>s`] `x\<in>s` `y\<in>s`
huffman@45448
  5249
      by simp (blast del: Sup_upper intro!: * Sup_upper) }
himmelma@33175
  5250
  moreover
himmelma@33175
  5251
  { fix d::real assume "d>0" "d < diameter s"
himmelma@33175
  5252
    hence "s\<noteq>{}" unfolding diameter_def by auto
himmelma@33175
  5253
    have "\<exists>d' \<in> ?D. d' > d"
himmelma@33175
  5254
    proof(rule ccontr)
himmelma@33175
  5255
      assume "\<not> (\<exists>d'\<in>{norm (x - y) |x y. x \<in> s \<and> y \<in> s}. d < d')"
paulson@33307
  5256
      hence "\<forall>d'\<in>?D. d' \<le> d" by auto (metis not_leE) 
paulson@33307
  5257
      thus False using `d < diameter s` `s\<noteq>{}` 
paulson@33307
  5258
        apply (auto simp add: diameter_def) 
paulson@33307
  5259
        apply (drule Sup_real_iff [THEN [2] rev_iffD2])
paulson@33307
  5260
        apply (auto, force) 
paulson@33307
  5261
        done
himmelma@33175
  5262
    qed
himmelma@33175
  5263
    hence "\<exists>x\<in>s. \<exists>y\<in>s. norm(x - y) > d" by auto  }
himmelma@33175
  5264
  ultimately show "\<forall>x\<in>s. \<forall>y\<in>s. norm(x - y) \<le> diameter s"
himmelma@33175
  5265
        "\<forall>d>0. d < diameter s --> (\<exists>x\<in>s. \<exists>y\<in>s. norm(x - y) > d)" by auto
himmelma@33175
  5266
qed
himmelma@33175
  5267
himmelma@33175
  5268
lemma diameter_bounded_bound:
himmelma@33175
  5269
 "bounded s \<Longrightarrow> x \<in> s \<Longrightarrow> y \<in> s ==> norm(x - y) \<le> diameter s"
himmelma@33175
  5270
  using diameter_bounded by blast
himmelma@33175
  5271
himmelma@33175
  5272
lemma diameter_compact_attained:
himmelma@33175
  5273
  fixes s :: "'a::real_normed_vector set"
himmelma@33175
  5274
  assumes "compact s"  "s \<noteq> {}"
himmelma@33175
  5275
  shows "\<exists>x\<in>s. \<exists>y\<in>s. (norm(x - y) = diameter s)"
himmelma@33175
  5276
proof-
himmelma@33175
  5277
  have b:"bounded s" using assms(1) by (rule compact_imp_bounded)
himmelma@33175
  5278
  then obtain x y where xys:"x\<in>s" "y\<in>s" and xy:"\<forall>u\<in>s. \<forall>v\<in>s. norm (u - v) \<le> norm (x - y)" using compact_sup_maxdistance[OF assms] by auto
huffman@36358
  5279
  hence "diameter s \<le> norm (x - y)"
huffman@36358
  5280
    unfolding diameter_def by clarsimp (rule Sup_least, fast+)
paulson@33307
  5281
  thus ?thesis
huffman@36358
  5282
    by (metis b diameter_bounded_bound order_antisym xys)
himmelma@33175
  5283
qed
himmelma@33175
  5284
huffman@45081
  5285
text {* Related results with closure as the conclusion. *}
himmelma@33175
  5286
himmelma@33175
  5287
lemma closed_scaling:
himmelma@33175
  5288
  fixes s :: "'a::real_normed_vector set"
himmelma@33175
  5289
  assumes "closed s" shows "closed ((\<lambda>x. c *\<^sub>R x) ` s)"
himmelma@33175
  5290
proof(cases "s={}")
himmelma@33175
  5291
  case True thus ?thesis by auto
himmelma@33175
  5292
next
himmelma@33175
  5293
  case False
himmelma@33175
  5294
  show ?thesis
himmelma@33175
  5295
  proof(cases "c=0")
himmelma@33175
  5296
    have *:"(\<lambda>x. 0) ` s = {0}" using `s\<noteq>{}` by auto
huffman@36668
  5297
    case True thus ?thesis apply auto unfolding * by auto
himmelma@33175
  5298
  next
himmelma@33175
  5299
    case False
himmelma@33175
  5300
    { fix x l assume as:"\<forall>n::nat. x n \<in> scaleR c ` s"  "(x ---> l) sequentially"
himmelma@33175
  5301
      { fix n::nat have "scaleR (1 / c) (x n) \<in> s"
himmelma@33175
  5302
          using as(1)[THEN spec[where x=n]]
hoelzl@37489
  5303
          using `c\<noteq>0` by auto
himmelma@33175
  5304
      }
himmelma@33175
  5305
      moreover
himmelma@33175
  5306
      { fix e::real assume "e>0"
himmelma@33175
  5307
        hence "0 < e *\<bar>c\<bar>"  using `c\<noteq>0` mult_pos_pos[of e "abs c"] by auto
himmelma@33175
  5308
        then obtain N where "\<forall>n\<ge>N. dist (x n) l < e * \<bar>c\<bar>"
huffman@45778
  5309
          using as(2)[unfolded LIMSEQ_def, THEN spec[where x="e * abs c"]] by auto
himmelma@33175
  5310
        hence "\<exists>N. \<forall>n\<ge>N. dist (scaleR (1 / c) (x n)) (scaleR (1 / c) l) < e"
himmelma@33175
  5311
          unfolding dist_norm unfolding scaleR_right_diff_distrib[THEN sym]
himmelma@33175
  5312
          using mult_imp_div_pos_less[of "abs c" _ e] `c\<noteq>0` by auto  }
huffman@45778
  5313
      hence "((\<lambda>n. scaleR (1 / c) (x n)) ---> scaleR (1 / c) l) sequentially" unfolding LIMSEQ_def by auto
himmelma@33175
  5314
      ultimately have "l \<in> scaleR c ` s"
himmelma@33175
  5315
        using assms[unfolded closed_sequential_limits, THEN spec[where x="\<lambda>n. scaleR (1/c) (x n)"], THEN spec[where x="scaleR (1/c) l"]]
himmelma@33175
  5316
        unfolding image_iff using `c\<noteq>0` apply(rule_tac x="scaleR (1 / c) l" in bexI) by auto  }
himmelma@33175
  5317
    thus ?thesis unfolding closed_sequential_limits by fast
himmelma@33175
  5318
  qed
himmelma@33175
  5319
qed
himmelma@33175
  5320
himmelma@33175
  5321
lemma closed_negations:
himmelma@33175
  5322
  fixes s :: "'a::real_normed_vector set"
himmelma@33175
  5323
  assumes "closed s"  shows "closed ((\<lambda>x. -x) ` s)"
himmelma@33175
  5324
  using closed_scaling[OF assms, of "- 1"] by simp
himmelma@33175
  5325
himmelma@33175
  5326
lemma compact_closed_sums:
himmelma@33175
  5327
  fixes s :: "'a::real_normed_vector set"
himmelma@33175
  5328
  assumes "compact s"  "closed t"  shows "closed {x + y | x y. x \<in> s \<and> y \<in> t}"
himmelma@33175
  5329
proof-
himmelma@33175
  5330
  let ?S = "{x + y |x y. x \<in> s \<and> y \<in> t}"
himmelma@33175
  5331
  { fix x l assume as:"\<forall>n. x n \<in> ?S"  "(x ---> l) sequentially"
himmelma@33175
  5332
    from as(1) obtain f where f:"\<forall>n. x n = fst (f n) + snd (f n)"  "\<forall>n. fst (f n) \<in> s"  "\<forall>n. snd (f n) \<in> t"
himmelma@33175
  5333
      using choice[of "\<lambda>n y. x n = (fst y) + (snd y) \<and> fst y \<in> s \<and> snd y \<in> t"] by auto
himmelma@33175
  5334
    obtain l' r where "l'\<in>s" and r:"subseq r" and lr:"(((\<lambda>n. fst (f n)) \<circ> r) ---> l') sequentially"
himmelma@33175
  5335
      using assms(1)[unfolded compact_def, THEN spec[where x="\<lambda> n. fst (f n)"]] using f(2) by auto
himmelma@33175
  5336
    have "((\<lambda>n. snd (f (r n))) ---> l - l') sequentially"
huffman@44983
  5337
      using tendsto_diff[OF lim_subseq[OF r as(2)] lr] and f(1) unfolding o_def by auto
himmelma@33175
  5338
    hence "l - l' \<in> t"
himmelma@33175
  5339
      using assms(2)[unfolded closed_sequential_limits, THEN spec[where x="\<lambda> n. snd (f (r n))"], THEN spec[where x="l - l'"]]
himmelma@33175
  5340
      using f(3) by auto
himmelma@33175
  5341
    hence "l \<in> ?S" using `l' \<in> s` apply auto apply(rule_tac x=l' in exI) apply(rule_tac x="l - l'" in exI) by auto
himmelma@33175
  5342
  }
himmelma@33175
  5343
  thus ?thesis unfolding closed_sequential_limits by fast
himmelma@33175
  5344
qed
himmelma@33175
  5345
himmelma@33175
  5346
lemma closed_compact_sums:
himmelma@33175
  5347
  fixes s t :: "'a::real_normed_vector set"
himmelma@33175
  5348
  assumes "closed s"  "compact t"
himmelma@33175
  5349
  shows "closed {x + y | x y. x \<in> s \<and> y \<in> t}"
himmelma@33175
  5350
proof-
himmelma@33175
  5351
  have "{x + y |x y. x \<in> t \<and> y \<in> s} = {x + y |x y. x \<in> s \<and> y \<in> t}" apply auto
himmelma@33175
  5352
    apply(rule_tac x=y in exI) apply auto apply(rule_tac x=y in exI) by auto
himmelma@33175
  5353
  thus ?thesis using compact_closed_sums[OF assms(2,1)] by simp
himmelma@33175
  5354
qed
himmelma@33175
  5355
himmelma@33175
  5356
lemma compact_closed_differences:
himmelma@33175
  5357
  fixes s t :: "'a::real_normed_vector set"
himmelma@33175
  5358
  assumes "compact s"  "closed t"
himmelma@33175
  5359
  shows "closed {x - y | x y. x \<in> s \<and> y \<in> t}"
himmelma@33175
  5360
proof-
himmelma@33175
  5361
  have "{x + y |x y. x \<in> s \<and> y \<in> uminus ` t} =  {x - y |x y. x \<in> s \<and> y \<in> t}"
himmelma@33175
  5362
    apply auto apply(rule_tac x=xa in exI) apply auto apply(rule_tac x=xa in exI) by auto
himmelma@33175
  5363
  thus ?thesis using compact_closed_sums[OF assms(1) closed_negations[OF assms(2)]] by auto
himmelma@33175
  5364
qed
himmelma@33175
  5365
himmelma@33175
  5366
lemma closed_compact_differences:
himmelma@33175
  5367
  fixes s t :: "'a::real_normed_vector set"
himmelma@33175
  5368
  assumes "closed s" "compact t"
himmelma@33175
  5369
  shows "closed {x - y | x y. x \<in> s \<and> y \<in> t}"
himmelma@33175
  5370
proof-
himmelma@33175
  5371
  have "{x + y |x y. x \<in> s \<and> y \<in> uminus ` t} = {x - y |x y. x \<in> s \<and> y \<in> t}"
himmelma@33175
  5372
    apply auto apply(rule_tac x=xa in exI) apply auto apply(rule_tac x=xa in exI) by auto
himmelma@33175
  5373
 thus ?thesis using closed_compact_sums[OF assms(1) compact_negations[OF assms(2)]] by simp
himmelma@33175
  5374
qed
himmelma@33175
  5375
himmelma@33175
  5376
lemma closed_translation:
himmelma@33175
  5377
  fixes a :: "'a::real_normed_vector"
himmelma@33175
  5378
  assumes "closed s"  shows "closed ((\<lambda>x. a + x) ` s)"
himmelma@33175
  5379
proof-
himmelma@33175
  5380
  have "{a + y |y. y \<in> s} = (op + a ` s)" by auto
himmelma@33175
  5381
  thus ?thesis using compact_closed_sums[OF compact_sing[of a] assms] by auto
himmelma@33175
  5382
qed
himmelma@33175
  5383
huffman@34099
  5384
lemma translation_Compl:
huffman@34099
  5385
  fixes a :: "'a::ab_group_add"
huffman@34099
  5386
  shows "(\<lambda>x. a + x) ` (- t) = - ((\<lambda>x. a + x) ` t)"
huffman@34099
  5387
  apply (auto simp add: image_iff) apply(rule_tac x="x - a" in bexI) by auto
huffman@34099
  5388
himmelma@33175
  5389
lemma translation_UNIV:
himmelma@33175
  5390
  fixes a :: "'a::ab_group_add" shows "range (\<lambda>x. a + x) = UNIV"
himmelma@33175
  5391
  apply (auto simp add: image_iff) apply(rule_tac x="x - a" in exI) by auto
himmelma@33175
  5392
himmelma@33175
  5393
lemma translation_diff:
himmelma@33175
  5394
  fixes a :: "'a::ab_group_add"
himmelma@33175
  5395
  shows "(\<lambda>x. a + x) ` (s - t) = ((\<lambda>x. a + x) ` s) - ((\<lambda>x. a + x) ` t)"
himmelma@33175
  5396
  by auto
himmelma@33175
  5397
himmelma@33175
  5398
lemma closure_translation:
himmelma@33175
  5399
  fixes a :: "'a::real_normed_vector"
himmelma@33175
  5400
  shows "closure ((\<lambda>x. a + x) ` s) = (\<lambda>x. a + x) ` (closure s)"
himmelma@33175
  5401
proof-
huffman@34099
  5402
  have *:"op + a ` (- s) = - op + a ` s"
himmelma@33175
  5403
    apply auto unfolding image_iff apply(rule_tac x="x - a" in bexI) by auto
huffman@34099
  5404
  show ?thesis unfolding closure_interior translation_Compl
huffman@34099
  5405
    using interior_translation[of a "- s"] unfolding * by auto
himmelma@33175
  5406
qed
himmelma@33175
  5407
himmelma@33175
  5408
lemma frontier_translation:
himmelma@33175
  5409
  fixes a :: "'a::real_normed_vector"
himmelma@33175
  5410
  shows "frontier((\<lambda>x. a + x) ` s) = (\<lambda>x. a + x) ` (frontier s)"
himmelma@33175
  5411
  unfolding frontier_def translation_diff interior_translation closure_translation by auto
himmelma@33175
  5412
huffman@45081
  5413
huffman@45081
  5414
subsection {* Separation between points and sets *}
himmelma@33175
  5415
himmelma@33175
  5416
lemma separate_point_closed:
himmelma@33175
  5417
  fixes s :: "'a::heine_borel set"
himmelma@33175
  5418
  shows "closed s \<Longrightarrow> a \<notin> s  ==> (\<exists>d>0. \<forall>x\<in>s. d \<le> dist a x)"
himmelma@33175
  5419
proof(cases "s = {}")
himmelma@33175
  5420
  case True
himmelma@33175
  5421
  thus ?thesis by(auto intro!: exI[where x=1])
himmelma@33175
  5422
next
himmelma@33175
  5423
  case False
himmelma@33175
  5424
  assume "closed s" "a \<notin> s"
himmelma@33175
  5425
  then obtain x where "x\<in>s" "\<forall>y\<in>s. dist a x \<le> dist a y" using `s \<noteq> {}` distance_attains_inf [of s a] by blast
himmelma@33175
  5426
  with `x\<in>s` show ?thesis using dist_pos_lt[of a x] and`a \<notin> s` by blast
himmelma@33175
  5427
qed
himmelma@33175
  5428
himmelma@33175
  5429
lemma separate_compact_closed:
himmelma@33175
  5430
  fixes s t :: "'a::{heine_borel, real_normed_vector} set"
himmelma@33175
  5431
    (* TODO: does this generalize to heine_borel? *)
himmelma@33175
  5432
  assumes "compact s" and "closed t" and "s \<inter> t = {}"
himmelma@33175
  5433
  shows "\<exists>d>0. \<forall>x\<in>s. \<forall>y\<in>t. d \<le> dist x y"
himmelma@33175
  5434
proof-
himmelma@33175
  5435
  have "0 \<notin> {x - y |x y. x \<in> s \<and> y \<in> t}" using assms(3) by auto
himmelma@33175
  5436
  then obtain d where "d>0" and d:"\<forall>x\<in>{x - y |x y. x \<in> s \<and> y \<in> t}. d \<le> dist 0 x"
himmelma@33175
  5437
    using separate_point_closed[OF compact_closed_differences[OF assms(1,2)], of 0] by auto
himmelma@33175
  5438
  { fix x y assume "x\<in>s" "y\<in>t"
himmelma@33175
  5439
    hence "x - y \<in> {x - y |x y. x \<in> s \<and> y \<in> t}" by auto
himmelma@33175
  5440
    hence "d \<le> dist (x - y) 0" using d[THEN bspec[where x="x - y"]] using dist_commute
himmelma@33175
  5441
      by (auto  simp add: dist_commute)
himmelma@33175
  5442
    hence "d \<le> dist x y" unfolding dist_norm by auto  }
himmelma@33175
  5443
  thus ?thesis using `d>0` by auto
himmelma@33175
  5444
qed
himmelma@33175
  5445
himmelma@33175
  5446
lemma separate_closed_compact:
himmelma@33175
  5447
  fixes s t :: "'a::{heine_borel, real_normed_vector} set"
himmelma@33175
  5448
  assumes "closed s" and "compact t" and "s \<inter> t = {}"
himmelma@33175
  5449
  shows "\<exists>d>0. \<forall>x\<in>s. \<forall>y\<in>t. d \<le> dist x y"
himmelma@33175
  5450
proof-
himmelma@33175
  5451
  have *:"t \<inter> s = {}" using assms(3) by auto
himmelma@33175
  5452
  show ?thesis using separate_compact_closed[OF assms(2,1) *]
himmelma@33175
  5453
    apply auto apply(rule_tac x=d in exI) apply auto apply (erule_tac x=y in ballE)
himmelma@33175
  5454
    by (auto simp add: dist_commute)
himmelma@33175
  5455
qed
himmelma@33175
  5456
huffman@45081
  5457
huffman@36435
  5458
subsection {* Intervals *}
hoelzl@37489
  5459
  
hoelzl@37489
  5460
lemma interval: fixes a :: "'a::ordered_euclidean_space" shows
hoelzl@51541
  5461
  "{a <..< b} = {x::'a. \<forall>i\<in>Basis. a\<bullet>i < x\<bullet>i \<and> x\<bullet>i < b\<bullet>i}" and
hoelzl@51541
  5462
  "{a .. b} = {x::'a. \<forall>i\<in>Basis. a\<bullet>i \<le> x\<bullet>i \<and> x\<bullet>i \<le> b\<bullet>i}"
nipkow@39535
  5463
  by(auto simp add:set_eq_iff eucl_le[where 'a='a] eucl_less[where 'a='a])
hoelzl@37489
  5464
hoelzl@37489
  5465
lemma mem_interval: fixes a :: "'a::ordered_euclidean_space" shows
hoelzl@51541
  5466
  "x \<in> {a<..<b} \<longleftrightarrow> (\<forall>i\<in>Basis. a\<bullet>i < x\<bullet>i \<and> x\<bullet>i < b\<bullet>i)"
hoelzl@51541
  5467
  "x \<in> {a .. b} \<longleftrightarrow> (\<forall>i\<in>Basis. a\<bullet>i \<le> x\<bullet>i \<and> x\<bullet>i \<le> b\<bullet>i)"
nipkow@39535
  5468
  using interval[of a b] by(auto simp add: set_eq_iff eucl_le[where 'a='a] eucl_less[where 'a='a])
hoelzl@37489
  5469
hoelzl@37489
  5470
lemma interval_eq_empty: fixes a :: "'a::ordered_euclidean_space" shows
hoelzl@51541
  5471
 "({a <..< b} = {} \<longleftrightarrow> (\<exists>i\<in>Basis. b\<bullet>i \<le> a\<bullet>i))" (is ?th1) and
hoelzl@51541
  5472
 "({a  ..  b} = {} \<longleftrightarrow> (\<exists>i\<in>Basis. b\<bullet>i < a\<bullet>i))" (is ?th2)
himmelma@33175
  5473
proof-
hoelzl@51541
  5474
  { fix i x assume i:"i\<in>Basis" and as:"b\<bullet>i \<le> a\<bullet>i" and x:"x\<in>{a <..< b}"
hoelzl@51541
  5475
    hence "a \<bullet> i < x \<bullet> i \<and> x \<bullet> i < b \<bullet> i" unfolding mem_interval by auto
hoelzl@51541
  5476
    hence "a\<bullet>i < b\<bullet>i" by auto
himmelma@33175
  5477
    hence False using as by auto  }
himmelma@33175
  5478
  moreover
hoelzl@51541
  5479
  { assume as:"\<forall>i\<in>Basis. \<not> (b\<bullet>i \<le> a\<bullet>i)"
himmelma@33175
  5480
    let ?x = "(1/2) *\<^sub>R (a + b)"
hoelzl@51541
  5481
    { fix i :: 'a assume i:"i\<in>Basis" 
hoelzl@51541
  5482
      have "a\<bullet>i < b\<bullet>i" using as[THEN bspec[where x=i]] i by auto
hoelzl@51541
  5483
      hence "a\<bullet>i < ((1/2) *\<^sub>R (a+b)) \<bullet> i" "((1/2) *\<^sub>R (a+b)) \<bullet> i < b\<bullet>i"
hoelzl@51541
  5484
        by (auto simp: inner_add_left) }
himmelma@33175
  5485
    hence "{a <..< b} \<noteq> {}" using mem_interval(1)[of "?x" a b] by auto  }
himmelma@33175
  5486
  ultimately show ?th1 by blast
himmelma@33175
  5487
hoelzl@51541
  5488
  { fix i x assume i:"i\<in>Basis" and as:"b\<bullet>i < a\<bullet>i" and x:"x\<in>{a .. b}"
hoelzl@51541
  5489
    hence "a \<bullet> i \<le> x \<bullet> i \<and> x \<bullet> i \<le> b \<bullet> i" unfolding mem_interval by auto
hoelzl@51541
  5490
    hence "a\<bullet>i \<le> b\<bullet>i" by auto
himmelma@33175
  5491
    hence False using as by auto  }
himmelma@33175
  5492
  moreover
hoelzl@51541
  5493
  { assume as:"\<forall>i\<in>Basis. \<not> (b\<bullet>i < a\<bullet>i)"
himmelma@33175
  5494
    let ?x = "(1/2) *\<^sub>R (a + b)"
hoelzl@51541
  5495
    { fix i :: 'a assume i:"i\<in>Basis"
hoelzl@51541
  5496
      have "a\<bullet>i \<le> b\<bullet>i" using as[THEN bspec[where x=i]] i by auto
hoelzl@51541
  5497
      hence "a\<bullet>i \<le> ((1/2) *\<^sub>R (a+b)) \<bullet> i" "((1/2) *\<^sub>R (a+b)) \<bullet> i \<le> b\<bullet>i"
hoelzl@51541
  5498
        by (auto simp: inner_add_left) }
himmelma@33175
  5499
    hence "{a .. b} \<noteq> {}" using mem_interval(2)[of "?x" a b] by auto  }
himmelma@33175
  5500
  ultimately show ?th2 by blast
himmelma@33175
  5501
qed
himmelma@33175
  5502
hoelzl@37489
  5503
lemma interval_ne_empty: fixes a :: "'a::ordered_euclidean_space" shows
hoelzl@51541
  5504
  "{a  ..  b} \<noteq> {} \<longleftrightarrow> (\<forall>i\<in>Basis. a\<bullet>i \<le> b\<bullet>i)" and
hoelzl@51541
  5505
  "{a <..< b} \<noteq> {} \<longleftrightarrow> (\<forall>i\<in>Basis. a\<bullet>i < b\<bullet>i)"
nipkow@45761
  5506
  unfolding interval_eq_empty[of a b] by fastforce+
hoelzl@37489
  5507
huffman@45448
  5508
lemma interval_sing:
huffman@45448
  5509
  fixes a :: "'a::ordered_euclidean_space"
huffman@45448
  5510
  shows "{a .. a} = {a}" and "{a<..<a} = {}"
huffman@45448
  5511
  unfolding set_eq_iff mem_interval eq_iff [symmetric]
hoelzl@51541
  5512
  by (auto intro: euclidean_eqI simp: ex_in_conv)
hoelzl@37489
  5513
hoelzl@37489
  5514
lemma subset_interval_imp: fixes a :: "'a::ordered_euclidean_space" shows
hoelzl@51541
  5515
 "(\<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i) \<Longrightarrow> {c .. d} \<subseteq> {a .. b}" and
hoelzl@51541
  5516
 "(\<forall>i\<in>Basis. a\<bullet>i < c\<bullet>i \<and> d\<bullet>i < b\<bullet>i) \<Longrightarrow> {c .. d} \<subseteq> {a<..<b}" and
hoelzl@51541
  5517
 "(\<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i) \<Longrightarrow> {c<..<d} \<subseteq> {a .. b}" and
hoelzl@51541
  5518
 "(\<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i) \<Longrightarrow> {c<..<d} \<subseteq> {a<..<b}"
huffman@45448
  5519
  unfolding subset_eq[unfolded Ball_def] unfolding mem_interval
huffman@45448
  5520
  by (best intro: order_trans less_le_trans le_less_trans less_imp_le)+
huffman@45448
  5521
huffman@45448
  5522
lemma interval_open_subset_closed:
huffman@45448
  5523
  fixes a :: "'a::ordered_euclidean_space"
huffman@45448
  5524
  shows "{a<..<b} \<subseteq> {a .. b}"
huffman@45448
  5525
  unfolding subset_eq [unfolded Ball_def] mem_interval
huffman@45448
  5526
  by (fast intro: less_imp_le)
hoelzl@37489
  5527
hoelzl@37489
  5528
lemma subset_interval: fixes a :: "'a::ordered_euclidean_space" shows
hoelzl@51541
  5529
 "{c .. d} \<subseteq> {a .. b} \<longleftrightarrow> (\<forall>i\<in>Basis. c\<bullet>i \<le> d\<bullet>i) --> (\<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i)" (is ?th1) and
hoelzl@51541
  5530
 "{c .. d} \<subseteq> {a<..<b} \<longleftrightarrow> (\<forall>i\<in>Basis. c\<bullet>i \<le> d\<bullet>i) --> (\<forall>i\<in>Basis. a\<bullet>i < c\<bullet>i \<and> d\<bullet>i < b\<bullet>i)" (is ?th2) and
hoelzl@51541
  5531
 "{c<..<d} \<subseteq> {a .. b} \<longleftrightarrow> (\<forall>i\<in>Basis. c\<bullet>i < d\<bullet>i) --> (\<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i)" (is ?th3) and
hoelzl@51541
  5532
 "{c<..<d} \<subseteq> {a<..<b} \<longleftrightarrow> (\<forall>i\<in>Basis. c\<bullet>i < d\<bullet>i) --> (\<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i)" (is ?th4)
himmelma@33175
  5533
proof-
himmelma@33175
  5534
  show ?th1 unfolding subset_eq and Ball_def and mem_interval by (auto intro: order_trans)
himmelma@33175
  5535
  show ?th2 unfolding subset_eq and Ball_def and mem_interval by (auto intro: le_less_trans less_le_trans order_trans less_imp_le)
hoelzl@51541
  5536
  { assume as: "{c<..<d} \<subseteq> {a .. b}" "\<forall>i\<in>Basis. c\<bullet>i < d\<bullet>i"
hoelzl@37489
  5537
    hence "{c<..<d} \<noteq> {}" unfolding interval_eq_empty by auto
hoelzl@51541
  5538
    fix i :: 'a assume i:"i\<in>Basis"
himmelma@33175
  5539
    (** TODO combine the following two parts as done in the HOL_light version. **)
hoelzl@51541
  5540
    { 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"
hoelzl@51541
  5541
      assume as2: "a\<bullet>i > c\<bullet>i"
hoelzl@51541
  5542
      { fix j :: 'a assume j:"j\<in>Basis"
hoelzl@51541
  5543
        hence "c \<bullet> j < ?x \<bullet> j \<and> ?x \<bullet> j < d \<bullet> j"
hoelzl@51541
  5544
          apply(cases "j=i") using as(2)[THEN bspec[where x=j]] i
hoelzl@37489
  5545
          by (auto simp add: as2)  }
hoelzl@37489
  5546
      hence "?x\<in>{c<..<d}" using i unfolding mem_interval by auto
hoelzl@37489
  5547
      moreover
hoelzl@37489
  5548
      have "?x\<notin>{a .. b}"
hoelzl@51541
  5549
        unfolding mem_interval apply auto apply(rule_tac x=i in bexI)
hoelzl@51541
  5550
        using as(2)[THEN bspec[where x=i]] and as2 i
hoelzl@37489
  5551
        by auto
hoelzl@37489
  5552
      ultimately have False using as by auto  }
hoelzl@51541
  5553
    hence "a\<bullet>i \<le> c\<bullet>i" by(rule ccontr)auto
hoelzl@37489
  5554
    moreover
hoelzl@51541
  5555
    { 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"
hoelzl@51541
  5556
      assume as2: "b\<bullet>i < d\<bullet>i"
hoelzl@51541
  5557
      { fix j :: 'a assume "j\<in>Basis"
hoelzl@51541
  5558
        hence "d \<bullet> j > ?x \<bullet> j \<and> ?x \<bullet> j > c \<bullet> j" 
hoelzl@51541
  5559
          apply(cases "j=i") using as(2)[THEN bspec[where x=j]]
hoelzl@51541
  5560
          by (auto simp add: as2) }
himmelma@33175
  5561
      hence "?x\<in>{c<..<d}" unfolding mem_interval by auto
himmelma@33175
  5562
      moreover
himmelma@33175
  5563
      have "?x\<notin>{a .. b}"
hoelzl@51541
  5564
        unfolding mem_interval apply auto apply(rule_tac x=i in bexI)
hoelzl@51541
  5565
        using as(2)[THEN bspec[where x=i]] and as2 using i
huffman@36358
  5566
        by auto
himmelma@33175
  5567
      ultimately have False using as by auto  }
hoelzl@51541
  5568
    hence "b\<bullet>i \<ge> d\<bullet>i" by(rule ccontr)auto
himmelma@33175
  5569
    ultimately
hoelzl@51541
  5570
    have "a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i" by auto
himmelma@33175
  5571
  } note part1 = this
hoelzl@51541
  5572
  show ?th3
hoelzl@51541
  5573
    unfolding subset_eq and Ball_def and mem_interval 
hoelzl@51541
  5574
    apply(rule,rule,rule,rule) 
hoelzl@51541
  5575
    apply(rule part1)
hoelzl@51541
  5576
    unfolding subset_eq and Ball_def and mem_interval
hoelzl@51541
  5577
    prefer 4
hoelzl@51541
  5578
    apply auto 
hoelzl@51541
  5579
    by(erule_tac x=xa in allE,erule_tac x=xa in allE,fastforce)+ 
hoelzl@51541
  5580
  { assume as:"{c<..<d} \<subseteq> {a<..<b}" "\<forall>i\<in>Basis. c\<bullet>i < d\<bullet>i"
hoelzl@51541
  5581
    fix i :: 'a assume i:"i\<in>Basis"
himmelma@33175
  5582
    from as(1) have "{c<..<d} \<subseteq> {a..b}" using interval_open_subset_closed[of a b] by auto
hoelzl@51541
  5583
    hence "a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i" using part1 and as(2) using i by auto  } note * = this
hoelzl@37489
  5584
  show ?th4 unfolding subset_eq and Ball_def and mem_interval 
hoelzl@37489
  5585
    apply(rule,rule,rule,rule) apply(rule *) unfolding subset_eq and Ball_def and mem_interval prefer 4
hoelzl@51541
  5586
    apply auto by(erule_tac x=xa in allE, simp)+ 
hoelzl@51541
  5587
qed
hoelzl@51541
  5588
hoelzl@51541
  5589
lemma inter_interval: fixes a :: "'a::ordered_euclidean_space" shows
hoelzl@51541
  5590
 "{a .. b} \<inter> {c .. d} =  {(\<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@51541
  5591
  unfolding set_eq_iff and Int_iff and mem_interval by auto
hoelzl@37489
  5592
hoelzl@37489
  5593
lemma disjoint_interval: fixes a::"'a::ordered_euclidean_space" shows
hoelzl@51541
  5594
  "{a .. b} \<inter> {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) and
hoelzl@51541
  5595
  "{a .. b} \<inter> {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) and
hoelzl@51541
  5596
  "{a<..<b} \<inter> {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) and
hoelzl@51541
  5597
  "{a<..<b} \<inter> {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)
himmelma@33175
  5598
proof-
hoelzl@51541
  5599
  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"
hoelzl@51541
  5600
  have **: "\<And>P Q. (\<And>i :: 'a. i \<in> Basis \<Longrightarrow> Q ?z i \<Longrightarrow> P i) \<Longrightarrow>
hoelzl@51541
  5601
      (\<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)" 
hoelzl@51541
  5602
    by blast
hoelzl@51541
  5603
  note * = set_eq_iff Int_iff empty_iff mem_interval ball_conj_distrib[symmetric] eq_False ball_simps(10)
hoelzl@51541
  5604
  show ?th1 unfolding * by (intro **) auto
hoelzl@51541
  5605
  show ?th2 unfolding * by (intro **) auto
hoelzl@51541
  5606
  show ?th3 unfolding * by (intro **) auto
hoelzl@51541
  5607
  show ?th4 unfolding * by (intro **) auto
hoelzl@51541
  5608
qed
himmelma@33175
  5609
himmelma@33175
  5610
(* Moved interval_open_subset_closed a bit upwards *)
himmelma@33175
  5611
huffman@45117
  5612
lemma open_interval[intro]:
huffman@45117
  5613
  fixes a b :: "'a::ordered_euclidean_space" shows "open {a<..<b}"
himmelma@33175
  5614
proof-
hoelzl@51541
  5615
  have "open (\<Inter>i\<in>Basis. (\<lambda>x. x\<bullet>i) -` {a\<bullet>i<..<b\<bullet>i})"
huffman@45117
  5616
    by (intro open_INT finite_lessThan ballI continuous_open_vimage allI
hoelzl@51541
  5617
      linear_continuous_at open_real_greaterThanLessThan finite_Basis bounded_linear_inner_left)
hoelzl@51541
  5618
  also have "(\<Inter>i\<in>Basis. (\<lambda>x. x\<bullet>i) -` {a\<bullet>i<..<b\<bullet>i}) = {a<..<b}"
huffman@45117
  5619
    by (auto simp add: eucl_less [where 'a='a])
huffman@45117
  5620
  finally show "open {a<..<b}" .
huffman@45117
  5621
qed
huffman@45117
  5622
huffman@45117
  5623
lemma closed_interval[intro]:
huffman@45117
  5624
  fixes a b :: "'a::ordered_euclidean_space" shows "closed {a .. b}"
himmelma@33175
  5625
proof-
hoelzl@51541
  5626
  have "closed (\<Inter>i\<in>Basis. (\<lambda>x. x\<bullet>i) -` {a\<bullet>i .. b\<bullet>i})"
huffman@45117
  5627
    by (intro closed_INT ballI continuous_closed_vimage allI
hoelzl@51541
  5628
      linear_continuous_at closed_real_atLeastAtMost finite_Basis bounded_linear_inner_left)
hoelzl@51541
  5629
  also have "(\<Inter>i\<in>Basis. (\<lambda>x. x\<bullet>i) -` {a\<bullet>i .. b\<bullet>i}) = {a .. b}"
huffman@45117
  5630
    by (auto simp add: eucl_le [where 'a='a])
huffman@45117
  5631
  finally show "closed {a .. b}" .
himmelma@33175
  5632
qed
himmelma@33175
  5633
huffman@45374
  5634
lemma interior_closed_interval [intro]:
huffman@45374
  5635
  fixes a b :: "'a::ordered_euclidean_space"
huffman@45374
  5636
  shows "interior {a..b} = {a<..<b}" (is "?L = ?R")
himmelma@33175
  5637
proof(rule subset_antisym)
huffman@45374
  5638
  show "?R \<subseteq> ?L" using interval_open_subset_closed open_interval
huffman@45374
  5639
    by (rule interior_maximal)
himmelma@33175
  5640
next
huffman@45374
  5641
  { fix x assume "x \<in> interior {a..b}"
huffman@45374
  5642
    then obtain s where s:"open s" "x \<in> s" "s \<subseteq> {a..b}" ..
himmelma@33175
  5643
    then obtain e where "e>0" and e:"\<forall>x'. dist x' x < e \<longrightarrow> x' \<in> {a..b}" unfolding open_dist and subset_eq by auto
hoelzl@51541
  5644
    { fix i :: 'a assume i:"i\<in>Basis"
hoelzl@51541
  5645
      have "dist (x - (e / 2) *\<^sub>R i) x < e"
hoelzl@51541
  5646
           "dist (x + (e / 2) *\<^sub>R i) x < e"
himmelma@33175
  5647
        unfolding dist_norm apply auto
hoelzl@51541
  5648
        unfolding norm_minus_cancel using norm_Basis[OF i] `e>0` by auto
hoelzl@51541
  5649
      hence "a \<bullet> i \<le> (x - (e / 2) *\<^sub>R i) \<bullet> i"
hoelzl@51541
  5650
                     "(x + (e / 2) *\<^sub>R i) \<bullet> i \<le> b \<bullet> i"
hoelzl@51541
  5651
        using e[THEN spec[where x="x - (e/2) *\<^sub>R i"]]
hoelzl@51541
  5652
        and   e[THEN spec[where x="x + (e/2) *\<^sub>R i"]]
huffman@45448
  5653
        unfolding mem_interval using i by blast+
hoelzl@51541
  5654
      hence "a \<bullet> i < x \<bullet> i" and "x \<bullet> i < b \<bullet> i"
hoelzl@51541
  5655
        using `e>0` i by (auto simp: inner_diff_left inner_Basis inner_add_left) }
himmelma@33175
  5656
    hence "x \<in> {a<..<b}" unfolding mem_interval by auto  }
huffman@45374
  5657
  thus "?L \<subseteq> ?R" ..
himmelma@33175
  5658
qed
himmelma@33175
  5659
hoelzl@37489
  5660
lemma bounded_closed_interval: fixes a :: "'a::ordered_euclidean_space" shows "bounded {a .. b}"
himmelma@33175
  5661
proof-
hoelzl@51541
  5662
  let ?b = "\<Sum>i\<in>Basis. \<bar>a\<bullet>i\<bar> + \<bar>b\<bullet>i\<bar>"
hoelzl@51541
  5663
  { fix x::"'a" assume x:"\<forall>i\<in>Basis. a \<bullet> i \<le> x \<bullet> i \<and> x \<bullet> i \<le> b \<bullet> i"
hoelzl@51541
  5664
    { fix i :: 'a assume "i\<in>Basis"
hoelzl@51541
  5665
      hence "\<bar>x\<bullet>i\<bar> \<le> \<bar>a\<bullet>i\<bar> + \<bar>b\<bullet>i\<bar>" using x[THEN bspec[where x=i]] by auto  }
hoelzl@51541
  5666
    hence "(\<Sum>i\<in>Basis. \<bar>x \<bullet> i\<bar>) \<le> ?b" apply-apply(rule setsum_mono) by auto
himmelma@33175
  5667
    hence "norm x \<le> ?b" using norm_le_l1[of x] by auto  }
himmelma@33175
  5668
  thus ?thesis unfolding interval and bounded_iff by auto
himmelma@33175
  5669
qed
himmelma@33175
  5670
hoelzl@37489
  5671
lemma bounded_interval: fixes a :: "'a::ordered_euclidean_space" shows
himmelma@33175
  5672
 "bounded {a .. b} \<and> bounded {a<..<b}"
himmelma@33175
  5673
  using bounded_closed_interval[of a b]
himmelma@33175
  5674
  using interval_open_subset_closed[of a b]
himmelma@33175
  5675
  using bounded_subset[of "{a..b}" "{a<..<b}"]
himmelma@33175
  5676
  by simp
himmelma@33175
  5677
hoelzl@37489
  5678
lemma not_interval_univ: fixes a :: "'a::ordered_euclidean_space" shows
himmelma@33175
  5679
 "({a .. b} \<noteq> UNIV) \<and> ({a<..<b} \<noteq> UNIV)"
hoelzl@37489
  5680
  using bounded_interval[of a b] by auto
hoelzl@37489
  5681
hoelzl@37489
  5682
lemma compact_interval: fixes a :: "'a::ordered_euclidean_space" shows "compact {a .. b}"
hoelzl@51899
  5683
  using bounded_closed_imp_seq_compact[of "{a..b}"] using bounded_interval[of a b]
hoelzl@51899
  5684
  by (auto simp: compact_eq_seq_compact_metric)
himmelma@33175
  5685
hoelzl@37489
  5686
lemma open_interval_midpoint: fixes a :: "'a::ordered_euclidean_space"
himmelma@33175
  5687
  assumes "{a<..<b} \<noteq> {}" shows "((1/2) *\<^sub>R (a + b)) \<in> {a<..<b}"
himmelma@33175
  5688
proof-
hoelzl@51541
  5689
  { fix i :: 'a assume "i\<in>Basis"
hoelzl@51541
  5690
    hence "a \<bullet> i < ((1 / 2) *\<^sub>R (a + b)) \<bullet> i \<and> ((1 / 2) *\<^sub>R (a + b)) \<bullet> i < b \<bullet> i"
hoelzl@51541
  5691
      using assms[unfolded interval_ne_empty, THEN bspec[where x=i]] by (auto simp: inner_add_left)  }
himmelma@33175
  5692
  thus ?thesis unfolding mem_interval by auto
himmelma@33175
  5693
qed
himmelma@33175
  5694
hoelzl@37489
  5695
lemma open_closed_interval_convex: fixes x :: "'a::ordered_euclidean_space"
himmelma@33175
  5696
  assumes x:"x \<in> {a<..<b}" and y:"y \<in> {a .. b}" and e:"0 < e" "e \<le> 1"
himmelma@33175
  5697
  shows "(e *\<^sub>R x + (1 - e) *\<^sub>R y) \<in> {a<..<b}"
himmelma@33175
  5698
proof-
hoelzl@51541
  5699
  { fix i :: 'a assume i:"i\<in>Basis"
hoelzl@51541
  5700
    have "a \<bullet> i = e * (a \<bullet> i) + (1 - e) * (a \<bullet> i)" unfolding left_diff_distrib by simp
hoelzl@51541
  5701
    also have "\<dots> < e * (x \<bullet> i) + (1 - e) * (y \<bullet> i)" apply(rule add_less_le_mono)
himmelma@33175
  5702
      using e unfolding mult_less_cancel_left and mult_le_cancel_left apply simp_all
hoelzl@37489
  5703
      using x unfolding mem_interval using i apply simp
hoelzl@37489
  5704
      using y unfolding mem_interval using i apply simp
himmelma@33175
  5705
      done
hoelzl@51541
  5706
    finally have "a \<bullet> i < (e *\<^sub>R x + (1 - e) *\<^sub>R y) \<bullet> i" unfolding inner_simps by auto
himmelma@33175
  5707
    moreover {
hoelzl@51541
  5708
    have "b \<bullet> i = e * (b\<bullet>i) + (1 - e) * (b\<bullet>i)" unfolding left_diff_distrib by simp
hoelzl@51541
  5709
    also have "\<dots> > e * (x \<bullet> i) + (1 - e) * (y \<bullet> i)" apply(rule add_less_le_mono)
himmelma@33175
  5710
      using e unfolding mult_less_cancel_left and mult_le_cancel_left apply simp_all
hoelzl@37489
  5711
      using x unfolding mem_interval using i apply simp
hoelzl@37489
  5712
      using y unfolding mem_interval using i apply simp
himmelma@33175
  5713
      done
hoelzl@51541
  5714
    finally have "(e *\<^sub>R x + (1 - e) *\<^sub>R y) \<bullet> i < b \<bullet> i" unfolding inner_simps by auto
hoelzl@51541
  5715
    } ultimately have "a \<bullet> i < (e *\<^sub>R x + (1 - e) *\<^sub>R y) \<bullet> i \<and> (e *\<^sub>R x + (1 - e) *\<^sub>R y) \<bullet> i < b \<bullet> i" by auto }
himmelma@33175
  5716
  thus ?thesis unfolding mem_interval by auto
himmelma@33175
  5717
qed
himmelma@33175
  5718
hoelzl@37489
  5719
lemma closure_open_interval: fixes a :: "'a::ordered_euclidean_space"
himmelma@33175
  5720
  assumes "{a<..<b} \<noteq> {}"
himmelma@33175
  5721
  shows "closure {a<..<b} = {a .. b}"
himmelma@33175
  5722
proof-
hoelzl@37489
  5723
  have ab:"a < b" using assms[unfolded interval_ne_empty] apply(subst eucl_less) by auto
himmelma@33175
  5724
  let ?c = "(1 / 2) *\<^sub>R (a + b)"
himmelma@33175
  5725
  { fix x assume as:"x \<in> {a .. b}"
himmelma@33175
  5726
    def f == "\<lambda>n::nat. x + (inverse (real n + 1)) *\<^sub>R (?c - x)"
himmelma@33175
  5727
    { fix n assume fn:"f n < b \<longrightarrow> a < f n \<longrightarrow> f n = x" and xc:"x \<noteq> ?c"
himmelma@33175
  5728
      have *:"0 < inverse (real n + 1)" "inverse (real n + 1) \<le> 1" unfolding inverse_le_1_iff by auto
himmelma@33175
  5729
      have "(inverse (real n + 1)) *\<^sub>R ((1 / 2) *\<^sub>R (a + b)) + (1 - inverse (real n + 1)) *\<^sub>R x =
himmelma@33175
  5730
        x + (inverse (real n + 1)) *\<^sub>R (((1 / 2) *\<^sub>R (a + b)) - x)"
himmelma@33175
  5731
        by (auto simp add: algebra_simps)
himmelma@33175
  5732
      hence "f n < b" and "a < f n" using open_closed_interval_convex[OF open_interval_midpoint[OF assms] as *] unfolding f_def by auto
hoelzl@37489
  5733
      hence False using fn unfolding f_def using xc by auto  }
himmelma@33175
  5734
    moreover
himmelma@33175
  5735
    { assume "\<not> (f ---> x) sequentially"
himmelma@33175
  5736
      { fix e::real assume "e>0"
himmelma@33175
  5737
        hence "\<exists>N::nat. inverse (real (N + 1)) < e" using real_arch_inv[of e] apply (auto simp add: Suc_pred') apply(rule_tac x="n - 1" in exI) by auto
himmelma@33175
  5738
        then obtain N::nat where "inverse (real (N + 1)) < e" by auto
himmelma@33175
  5739
        hence "\<forall>n\<ge>N. inverse (real n + 1) < e" by (auto, metis Suc_le_mono le_SucE less_imp_inverse_less nat_le_real_less order_less_trans real_of_nat_Suc real_of_nat_Suc_gt_zero)
himmelma@33175
  5740
        hence "\<exists>N::nat. \<forall>n\<ge>N. inverse (real n + 1) < e" by auto  }
himmelma@33175
  5741
      hence "((\<lambda>n. inverse (real n + 1)) ---> 0) sequentially"
huffman@45778
  5742
        unfolding LIMSEQ_def by(auto simp add: dist_norm)
himmelma@33175
  5743
      hence "(f ---> x) sequentially" unfolding f_def
huffman@44983
  5744
        using tendsto_add[OF tendsto_const, of "\<lambda>n::nat. (inverse (real n + 1)) *\<^sub>R ((1 / 2) *\<^sub>R (a + b) - x)" 0 sequentially x]
huffman@45145
  5745
        using tendsto_scaleR [OF _ tendsto_const, of "\<lambda>n::nat. inverse (real n + 1)" 0 sequentially "((1 / 2) *\<^sub>R (a + b) - x)"] by auto  }
himmelma@33175
  5746
    ultimately have "x \<in> closure {a<..<b}"
himmelma@33175
  5747
      using as and open_interval_midpoint[OF assms] unfolding closure_def unfolding islimpt_sequential by(cases "x=?c")auto  }
himmelma@33175
  5748
  thus ?thesis using closure_minimal[OF interval_open_subset_closed closed_interval, of a b] by blast
himmelma@33175
  5749
qed
himmelma@33175
  5750
hoelzl@37489
  5751
lemma bounded_subset_open_interval_symmetric: fixes s::"('a::ordered_euclidean_space) set"
himmelma@33175
  5752
  assumes "bounded s"  shows "\<exists>a. s \<subseteq> {-a<..<a}"
himmelma@33175
  5753
proof-
himmelma@33175
  5754
  obtain b where "b>0" and b:"\<forall>x\<in>s. norm x \<le> b" using assms[unfolded bounded_pos] by auto
hoelzl@51541
  5755
  def a \<equiv> "(\<Sum>i\<in>Basis. (b + 1) *\<^sub>R i)::'a"
himmelma@33175
  5756
  { fix x assume "x\<in>s"
hoelzl@51541
  5757
    fix i :: 'a assume i:"i\<in>Basis"
hoelzl@51541
  5758
    hence "(-a)\<bullet>i < x\<bullet>i" and "x\<bullet>i < a\<bullet>i" using b[THEN bspec[where x=x], OF `x\<in>s`]
hoelzl@51541
  5759
      and Basis_le_norm[OF i, of x] unfolding inner_simps and a_def by auto }
hoelzl@37489
  5760
  thus ?thesis by(auto intro: exI[where x=a] simp add: eucl_less[where 'a='a])
himmelma@33175
  5761
qed
himmelma@33175
  5762
himmelma@33175
  5763
lemma bounded_subset_open_interval:
hoelzl@37489
  5764
  fixes s :: "('a::ordered_euclidean_space) set"
himmelma@33175
  5765
  shows "bounded s ==> (\<exists>a b. s \<subseteq> {a<..<b})"
himmelma@33175
  5766
  by (auto dest!: bounded_subset_open_interval_symmetric)
himmelma@33175
  5767
himmelma@33175
  5768
lemma bounded_subset_closed_interval_symmetric:
hoelzl@37489
  5769
  fixes s :: "('a::ordered_euclidean_space) set"
himmelma@33175
  5770
  assumes "bounded s" shows "\<exists>a. s \<subseteq> {-a .. a}"
himmelma@33175
  5771
proof-
himmelma@33175
  5772
  obtain a where "s \<subseteq> {- a<..<a}" using bounded_subset_open_interval_symmetric[OF assms] by auto
himmelma@33175
  5773
  thus ?thesis using interval_open_subset_closed[of "-a" a] by auto
himmelma@33175
  5774
qed
himmelma@33175
  5775
himmelma@33175
  5776
lemma bounded_subset_closed_interval:
hoelzl@37489
  5777
  fixes s :: "('a::ordered_euclidean_space) set"
himmelma@33175
  5778
  shows "bounded s ==> (\<exists>a b. s \<subseteq> {a .. b})"
himmelma@33175
  5779
  using bounded_subset_closed_interval_symmetric[of s] by auto
himmelma@33175
  5780
himmelma@33175
  5781
lemma frontier_closed_interval:
hoelzl@37489
  5782
  fixes a b :: "'a::ordered_euclidean_space"
himmelma@33175
  5783
  shows "frontier {a .. b} = {a .. b} - {a<..<b}"
himmelma@33175
  5784
  unfolding frontier_def unfolding interior_closed_interval and closure_closed[OF closed_interval] ..
himmelma@33175
  5785
himmelma@33175
  5786
lemma frontier_open_interval:
hoelzl@37489
  5787
  fixes a b :: "'a::ordered_euclidean_space"
himmelma@33175
  5788
  shows "frontier {a<..<b} = (if {a<..<b} = {} then {} else {a .. b} - {a<..<b})"
himmelma@33175
  5789
proof(cases "{a<..<b} = {}")
himmelma@33175
  5790
  case True thus ?thesis using frontier_empty by auto
himmelma@33175
  5791
next
himmelma@33175
  5792
  case False thus ?thesis unfolding frontier_def and closure_open_interval[OF False] and interior_open[OF open_interval] by auto
himmelma@33175
  5793
qed
himmelma@33175
  5794
hoelzl@37489
  5795
lemma inter_interval_mixed_eq_empty: fixes a :: "'a::ordered_euclidean_space"
himmelma@33175
  5796
  assumes "{c<..<d} \<noteq> {}"  shows "{a<..<b} \<inter> {c .. d} = {} \<longleftrightarrow> {a<..<b} \<inter> {c<..<d} = {}"
himmelma@33175
  5797
  unfolding closure_open_interval[OF assms, THEN sym] unfolding open_inter_closure_eq_empty[OF open_interval] ..
himmelma@33175
  5798
himmelma@33175
  5799
himmelma@33175
  5800
(* Some stuff for half-infinite intervals too; FIXME: notation?  *)
himmelma@33175
  5801
huffman@37673
  5802
lemma closed_interval_left: fixes b::"'a::euclidean_space"
hoelzl@51541
  5803
  shows "closed {x::'a. \<forall>i\<in>Basis. x\<bullet>i \<le> b\<bullet>i}"
himmelma@33175
  5804
proof-
hoelzl@51541
  5805
  { fix i :: 'a assume i:"i\<in>Basis"
hoelzl@51541
  5806
    fix x::"'a" assume x:"\<forall>e>0. \<exists>x'\<in>{x. \<forall>i\<in>Basis. x \<bullet> i \<le> b \<bullet> i}. x' \<noteq> x \<and> dist x' x < e"
hoelzl@51541
  5807
    { assume "x\<bullet>i > b\<bullet>i"
hoelzl@51541
  5808
      then obtain y where "y \<bullet> i \<le> b \<bullet> i"  "y \<noteq> x"  "dist y x < x\<bullet>i - b\<bullet>i"
hoelzl@51541
  5809
        using x[THEN spec[where x="x\<bullet>i - b\<bullet>i"]] using i by auto
hoelzl@51541
  5810
      hence False using Basis_le_norm[OF i, of "y - x"] unfolding dist_norm inner_simps using i 
hoelzl@51541
  5811
        by auto }
hoelzl@51541
  5812
    hence "x\<bullet>i \<le> b\<bullet>i" by(rule ccontr)auto  }
himmelma@33175
  5813
  thus ?thesis unfolding closed_limpt unfolding islimpt_approachable by blast
himmelma@33175
  5814
qed
himmelma@33175
  5815
huffman@37673
  5816
lemma closed_interval_right: fixes a::"'a::euclidean_space"
hoelzl@51541
  5817
  shows "closed {x::'a. \<forall>i\<in>Basis. a\<bullet>i \<le> x\<bullet>i}"
himmelma@33175
  5818
proof-
hoelzl@51541
  5819
  { fix i :: 'a assume i:"i\<in>Basis"
hoelzl@51541
  5820
    fix x::"'a" assume x:"\<forall>e>0. \<exists>x'\<in>{x. \<forall>i\<in>Basis. a \<bullet> i \<le> x \<bullet> i}. x' \<noteq> x \<and> dist x' x < e"
hoelzl@51541
  5821
    { assume "a\<bullet>i > x\<bullet>i"
hoelzl@51541
  5822
      then obtain y where "a \<bullet> i \<le> y \<bullet> i"  "y \<noteq> x"  "dist y x < a\<bullet>i - x\<bullet>i"
hoelzl@51541
  5823
        using x[THEN spec[where x="a\<bullet>i - x\<bullet>i"]] i by auto
hoelzl@51541
  5824
      hence False using Basis_le_norm[OF i, of "y - x"] unfolding dist_norm inner_simps by auto }
hoelzl@51541
  5825
    hence "a\<bullet>i \<le> x\<bullet>i" by(rule ccontr)auto  }
himmelma@33175
  5826
  thus ?thesis unfolding closed_limpt unfolding islimpt_approachable by blast
himmelma@33175
  5827
qed
himmelma@33175
  5828
hoelzl@51541
  5829
lemma open_box: "open (box a b)"
hoelzl@51541
  5830
proof -
hoelzl@51541
  5831
  have "open (\<Inter>i\<in>Basis. (op \<bullet> i) -` {a \<bullet> i <..< b \<bullet> i})"
hoelzl@51541
  5832
    by (auto intro!: continuous_open_vimage continuous_inner continuous_at_id continuous_const)
hoelzl@51541
  5833
  also have "(\<Inter>i\<in>Basis. (op \<bullet> i) -` {a \<bullet> i <..< b \<bullet> i}) = box a b"
hoelzl@51541
  5834
    by (auto simp add: box_def inner_commute)
hoelzl@51541
  5835
  finally show ?thesis .
hoelzl@51541
  5836
qed
hoelzl@51541
  5837
hoelzl@51896
  5838
instance euclidean_space \<subseteq> second_countable_topology
immler@51102
  5839
proof
hoelzl@51541
  5840
  def a \<equiv> "\<lambda>f :: 'a \<Rightarrow> (real \<times> real). \<Sum>i\<in>Basis. fst (f i) *\<^sub>R i"
hoelzl@51541
  5841
  then have a: "\<And>f. (\<Sum>i\<in>Basis. fst (f i) *\<^sub>R i) = a f" by simp
hoelzl@51541
  5842
  def b \<equiv> "\<lambda>f :: 'a \<Rightarrow> (real \<times> real). \<Sum>i\<in>Basis. snd (f i) *\<^sub>R i"
hoelzl@51541
  5843
  then have b: "\<And>f. (\<Sum>i\<in>Basis. snd (f i) *\<^sub>R i) = b f" by simp
hoelzl@51541
  5844
  def B \<equiv> "(\<lambda>f. box (a f) (b f)) ` (Basis \<rightarrow>\<^isub>E (\<rat> \<times> \<rat>))"
hoelzl@51541
  5845
hoelzl@51541
  5846
  have "countable B" unfolding B_def 
hoelzl@51541
  5847
    by (intro countable_image countable_PiE finite_Basis countable_SIGMA countable_rat)
immler@51260
  5848
  moreover
hoelzl@51541
  5849
  have "Ball B open" by (simp add: B_def open_box)
hoelzl@51541
  5850
  moreover have "(\<forall>A. open A \<longrightarrow> (\<exists>B'\<subseteq>B. \<Union>B' = A))"
immler@51102
  5851
  proof safe
hoelzl@51541
  5852
    fix A::"'a set" assume "open A"
hoelzl@51541
  5853
    show "\<exists>B'\<subseteq>B. \<Union>B' = A"
hoelzl@51541
  5854
      apply (rule exI[of _ "{b\<in>B. b \<subseteq> A}"])
hoelzl@51541
  5855
      apply (subst (3) open_UNION_box[OF `open A`])
hoelzl@51541
  5856
      apply (auto simp add: a b B_def)
hoelzl@51541
  5857
      done
immler@51102
  5858
  qed
immler@51102
  5859
  ultimately
immler@51260
  5860
  show "\<exists>B::'a set set. countable B \<and> topological_basis B" unfolding topological_basis_def by blast
immler@51102
  5861
qed
immler@51102
  5862
immler@51102
  5863
instance ordered_euclidean_space \<subseteq> polish_space ..
immler@51102
  5864
huffman@36435
  5865
text {* Intervals in general, including infinite and mixtures of open and closed. *}
himmelma@33175
  5866
huffman@37731
  5867
definition "is_interval (s::('a::euclidean_space) set) \<longleftrightarrow>
hoelzl@51541
  5868
  (\<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)"
hoelzl@37489
  5869
hoelzl@37489
  5870
lemma is_interval_interval: "is_interval {a .. b::'a::ordered_euclidean_space}" (is ?th1)
hoelzl@39320
  5871
  "is_interval {a<..<b}" (is ?th2) proof -
himmelma@33175
  5872
  show ?th1 ?th2  unfolding is_interval_def mem_interval Ball_def atLeastAtMost_iff
huffman@45448
  5873
    by(meson order_trans le_less_trans less_le_trans less_trans)+ qed
himmelma@33175
  5874
himmelma@33175
  5875
lemma is_interval_empty:
himmelma@33175
  5876
 "is_interval {}"
himmelma@33175
  5877
  unfolding is_interval_def
himmelma@33175
  5878
  by simp
himmelma@33175
  5879
himmelma@33175
  5880
lemma is_interval_univ:
himmelma@33175
  5881
 "is_interval UNIV"
himmelma@33175
  5882
  unfolding is_interval_def
himmelma@33175
  5883
  by simp
himmelma@33175
  5884
huffman@45081
  5885
huffman@45081
  5886
subsection {* Closure of halfspaces and hyperplanes *}
himmelma@33175
  5887
huffman@45090
  5888
lemma isCont_open_vimage:
huffman@45090
  5889
  assumes "\<And>x. isCont f x" and "open s" shows "open (f -` s)"
huffman@45090
  5890
proof -
huffman@45090
  5891
  from assms(1) have "continuous_on UNIV f"
huffman@45090
  5892
    unfolding isCont_def continuous_on_def within_UNIV by simp
huffman@45090
  5893
  hence "open {x \<in> UNIV. f x \<in> s}"
huffman@45090
  5894
    using open_UNIV `open s` by (rule continuous_open_preimage)
huffman@45090
  5895
  thus "open (f -` s)"
huffman@45090
  5896
    by (simp add: vimage_def)
huffman@45090
  5897
qed
huffman@45090
  5898
huffman@45090
  5899
lemma isCont_closed_vimage:
huffman@45090
  5900
  assumes "\<And>x. isCont f x" and "closed s" shows "closed (f -` s)"
huffman@45090
  5901
  using assms unfolding closed_def vimage_Compl [symmetric]
huffman@45090
  5902
  by (rule isCont_open_vimage)
huffman@45090
  5903
huffman@45084
  5904
lemma open_Collect_less:
huffman@45090
  5905
  fixes f g :: "'a::topological_space \<Rightarrow> real"
huffman@45090
  5906
  assumes f: "\<And>x. isCont f x"
huffman@45090
  5907
  assumes g: "\<And>x. isCont g x"
huffman@45084
  5908
  shows "open {x. f x < g x}"
huffman@45084
  5909
proof -
huffman@45084
  5910
  have "open ((\<lambda>x. g x - f x) -` {0<..})"
huffman@45090
  5911
    using isCont_diff [OF g f] open_real_greaterThan
huffman@45090
  5912
    by (rule isCont_open_vimage)
huffman@45084
  5913
  also have "((\<lambda>x. g x - f x) -` {0<..}) = {x. f x < g x}"
huffman@45084
  5914
    by auto
huffman@45084
  5915
  finally show ?thesis .
huffman@45084
  5916
qed
huffman@45084
  5917
huffman@45084
  5918
lemma closed_Collect_le:
huffman@45090
  5919
  fixes f g :: "'a::topological_space \<Rightarrow> real"
huffman@45090
  5920
  assumes f: "\<And>x. isCont f x"
huffman@45090
  5921
  assumes g: "\<And>x. isCont g x"
huffman@45084
  5922
  shows "closed {x. f x \<le> g x}"
huffman@45084
  5923
proof -
huffman@45084
  5924
  have "closed ((\<lambda>x. g x - f x) -` {0..})"
huffman@45090
  5925
    using isCont_diff [OF g f] closed_real_atLeast
huffman@45090
  5926
    by (rule isCont_closed_vimage)
huffman@45084
  5927
  also have "((\<lambda>x. g x - f x) -` {0..}) = {x. f x \<le> g x}"
huffman@45084
  5928
    by auto
huffman@45084
  5929
  finally show ?thesis .
huffman@45084
  5930
qed
huffman@45084
  5931
huffman@45084
  5932
lemma closed_Collect_eq:
huffman@45090
  5933
  fixes f g :: "'a::topological_space \<Rightarrow> 'b::t2_space"
huffman@45090
  5934
  assumes f: "\<And>x. isCont f x"
huffman@45090
  5935
  assumes g: "\<And>x. isCont g x"
huffman@45084
  5936
  shows "closed {x. f x = g x}"
huffman@45084
  5937
proof -
huffman@45087
  5938
  have "open {(x::'b, y::'b). x \<noteq> y}"
huffman@45087
  5939
    unfolding open_prod_def by (auto dest!: hausdorff)
huffman@45087
  5940
  hence "closed {(x::'b, y::'b). x = y}"
huffman@45087
  5941
    unfolding closed_def split_def Collect_neg_eq .
huffman@45090
  5942
  with isCont_Pair [OF f g]
huffman@45087
  5943
  have "closed ((\<lambda>x. (f x, g x)) -` {(x, y). x = y})"
huffman@45090
  5944
    by (rule isCont_closed_vimage)
huffman@45087
  5945
  also have "\<dots> = {x. f x = g x}" by auto
huffman@45084
  5946
  finally show ?thesis .
huffman@45084
  5947
qed
huffman@45084
  5948
himmelma@33175
  5949
lemma continuous_at_inner: "continuous (at x) (inner a)"
himmelma@33175
  5950
  unfolding continuous_at by (intro tendsto_intros)
himmelma@33175
  5951
himmelma@33175
  5952
lemma closed_halfspace_le: "closed {x. inner a x \<le> b}"
huffman@45104
  5953
  by (simp add: closed_Collect_le)
himmelma@33175
  5954
himmelma@33175
  5955
lemma closed_halfspace_ge: "closed {x. inner a x \<ge> b}"
huffman@45104
  5956
  by (simp add: closed_Collect_le)
himmelma@33175
  5957
himmelma@33175
  5958
lemma closed_hyperplane: "closed {x. inner a x = b}"
huffman@45104
  5959
  by (simp add: closed_Collect_eq)
himmelma@33175
  5960
himmelma@33175
  5961
lemma closed_halfspace_component_le:
hoelzl@51541
  5962
  shows "closed {x::'a::euclidean_space. x\<bullet>i \<le> a}"
huffman@45104
  5963
  by (simp add: closed_Collect_le)
himmelma@33175
  5964
himmelma@33175
  5965
lemma closed_halfspace_component_ge:
hoelzl@51541
  5966
  shows "closed {x::'a::euclidean_space. x\<bullet>i \<ge> a}"
huffman@45104
  5967
  by (simp add: closed_Collect_le)
himmelma@33175
  5968
huffman@45081
  5969
text {* Openness of halfspaces. *}
himmelma@33175
  5970
himmelma@33175
  5971
lemma open_halfspace_lt: "open {x. inner a x < b}"
huffman@45104
  5972
  by (simp add: open_Collect_less)
himmelma@33175
  5973
himmelma@33175
  5974
lemma open_halfspace_gt: "open {x. inner a x > b}"
huffman@45104
  5975
  by (simp add: open_Collect_less)
himmelma@33175
  5976
himmelma@33175
  5977
lemma open_halfspace_component_lt:
hoelzl@51541
  5978
  shows "open {x::'a::euclidean_space. x\<bullet>i < a}"
huffman@45104
  5979
  by (simp add: open_Collect_less)
himmelma@33175
  5980
himmelma@33175
  5981
lemma open_halfspace_component_gt:
hoelzl@51541
  5982
  shows "open {x::'a::euclidean_space. x\<bullet>i > a}"
huffman@45104
  5983
  by (simp add: open_Collect_less)
himmelma@33175
  5984
hoelzl@38902
  5985
text{* Instantiation for intervals on @{text ordered_euclidean_space} *}
hoelzl@38902
  5986
hoelzl@38902
  5987
lemma eucl_lessThan_eq_halfspaces:
hoelzl@38902
  5988
  fixes a :: "'a\<Colon>ordered_euclidean_space"
hoelzl@51541
  5989
  shows "{..<a} = (\<Inter>i\<in>Basis. {x. x \<bullet> i < a \<bullet> i})"
hoelzl@38902
  5990
 by (auto simp: eucl_less[where 'a='a])
hoelzl@38902
  5991
hoelzl@38902
  5992
lemma eucl_greaterThan_eq_halfspaces:
hoelzl@38902
  5993
  fixes a :: "'a\<Colon>ordered_euclidean_space"
hoelzl@51541
  5994
  shows "{a<..} = (\<Inter>i\<in>Basis. {x. a \<bullet> i < x \<bullet> i})"
hoelzl@38902
  5995
 by (auto simp: eucl_less[where 'a='a])
hoelzl@38902
  5996
hoelzl@38902
  5997
lemma eucl_atMost_eq_halfspaces:
hoelzl@38902
  5998
  fixes a :: "'a\<Colon>ordered_euclidean_space"
hoelzl@51541
  5999
  shows "{.. a} = (\<Inter>i\<in>Basis. {x. x \<bullet> i \<le> a \<bullet> i})"
hoelzl@38902
  6000
 by (auto simp: eucl_le[where 'a='a])
hoelzl@38902
  6001
hoelzl@38902
  6002
lemma eucl_atLeast_eq_halfspaces:
hoelzl@38902
  6003
  fixes a :: "'a\<Colon>ordered_euclidean_space"
hoelzl@51541
  6004
  shows "{a ..} = (\<Inter>i\<in>Basis. {x. a \<bullet> i \<le> x \<bullet> i})"
hoelzl@38902
  6005
 by (auto simp: eucl_le[where 'a='a])
hoelzl@38902
  6006
hoelzl@38902
  6007
lemma open_eucl_lessThan[simp, intro]:
hoelzl@38902
  6008
  fixes a :: "'a\<Colon>ordered_euclidean_space"
hoelzl@38902
  6009
  shows "open {..< a}"
hoelzl@38902
  6010
  by (auto simp: eucl_lessThan_eq_halfspaces open_halfspace_component_lt)
hoelzl@38902
  6011
hoelzl@38902
  6012
lemma open_eucl_greaterThan[simp, intro]:
hoelzl@38902
  6013
  fixes a :: "'a\<Colon>ordered_euclidean_space"
hoelzl@38902
  6014
  shows "open {a <..}"
hoelzl@38902
  6015
  by (auto simp: eucl_greaterThan_eq_halfspaces open_halfspace_component_gt)
hoelzl@38902
  6016
hoelzl@38902
  6017
lemma closed_eucl_atMost[simp, intro]:
hoelzl@38902
  6018
  fixes a :: "'a\<Colon>ordered_euclidean_space"
hoelzl@38902
  6019
  shows "closed {.. a}"
hoelzl@38902
  6020
  unfolding eucl_atMost_eq_halfspaces
huffman@45104
  6021
  by (simp add: closed_INT closed_Collect_le)
hoelzl@38902
  6022
hoelzl@38902
  6023
lemma closed_eucl_atLeast[simp, intro]:
hoelzl@38902
  6024
  fixes a :: "'a\<Colon>ordered_euclidean_space"
hoelzl@38902
  6025
  shows "closed {a ..}"
hoelzl@38902
  6026
  unfolding eucl_atLeast_eq_halfspaces
huffman@45104
  6027
  by (simp add: closed_INT closed_Collect_le)
hoelzl@38902
  6028
huffman@45081
  6029
text {* This gives a simple derivation of limit component bounds. *}
himmelma@33175
  6030
huffman@37673
  6031
lemma Lim_component_le: fixes f :: "'a \<Rightarrow> 'b::euclidean_space"
hoelzl@51541
  6032
  assumes "(f ---> l) net" "\<not> (trivial_limit net)"  "eventually (\<lambda>x. f(x)\<bullet>i \<le> b) net"
hoelzl@51541
  6033
  shows "l\<bullet>i \<le> b"
hoelzl@51541
  6034
  by (rule tendsto_le[OF assms(2) tendsto_const tendsto_inner[OF assms(1) tendsto_const] assms(3)])
hoelzl@37489
  6035
huffman@37673
  6036
lemma Lim_component_ge: fixes f :: "'a \<Rightarrow> 'b::euclidean_space"
hoelzl@51541
  6037
  assumes "(f ---> l) net"  "\<not> (trivial_limit net)"  "eventually (\<lambda>x. b \<le> (f x)\<bullet>i) net"
hoelzl@51541
  6038
  shows "b \<le> l\<bullet>i"
hoelzl@51541
  6039
  by (rule tendsto_le[OF assms(2) tendsto_inner[OF assms(1) tendsto_const] tendsto_const assms(3)])
hoelzl@37489
  6040
huffman@37673
  6041
lemma Lim_component_eq: fixes f :: "'a \<Rightarrow> 'b::euclidean_space"
hoelzl@51541
  6042
  assumes net:"(f ---> l) net" "~(trivial_limit net)" and ev:"eventually (\<lambda>x. f(x)\<bullet>i = b) net"
hoelzl@51541
  6043
  shows "l\<bullet>i = b"
hoelzl@51541
  6044
  using ev[unfolded order_eq_iff eventually_conj_iff]
hoelzl@51541
  6045
  using Lim_component_ge[OF net, of b i] and Lim_component_le[OF net, of i b] by auto
hoelzl@51541
  6046
himmelma@33175
  6047
text{* Limits relative to a union.                                               *}
himmelma@33175
  6048
himmelma@33175
  6049
lemma eventually_within_Un:
himmelma@33175
  6050
  "eventually P (net within (s \<union> t)) \<longleftrightarrow>
himmelma@33175
  6051
    eventually P (net within s) \<and> eventually P (net within t)"
himmelma@33175
  6052
  unfolding Limits.eventually_within
himmelma@33175
  6053
  by (auto elim!: eventually_rev_mp)
himmelma@33175
  6054
himmelma@33175
  6055
lemma Lim_within_union:
himmelma@33175
  6056
 "(f ---> l) (net within (s \<union> t)) \<longleftrightarrow>
himmelma@33175
  6057
  (f ---> l) (net within s) \<and> (f ---> l) (net within t)"
himmelma@33175
  6058
  unfolding tendsto_def
himmelma@33175
  6059
  by (auto simp add: eventually_within_Un)
himmelma@33175
  6060
huffman@36438
  6061
lemma Lim_topological:
huffman@36438
  6062
 "(f ---> l) net \<longleftrightarrow>
huffman@36438
  6063
        trivial_limit net \<or>
huffman@36438
  6064
        (\<forall>S. open S \<longrightarrow> l \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) net)"
huffman@36438
  6065
  unfolding tendsto_def trivial_limit_eq by auto
huffman@36438
  6066
himmelma@33175
  6067
lemma continuous_on_union:
himmelma@33175
  6068
  assumes "closed s" "closed t" "continuous_on s f" "continuous_on t f"
himmelma@33175
  6069
  shows "continuous_on (s \<union> t) f"
huffman@36438
  6070
  using assms unfolding continuous_on Lim_within_union
huffman@36438
  6071
  unfolding Lim_topological trivial_limit_within closed_limpt by auto
himmelma@33175
  6072
himmelma@33175
  6073
lemma continuous_on_cases:
himmelma@33175
  6074
  assumes "closed s" "closed t" "continuous_on s f" "continuous_on t g"
himmelma@33175
  6075
          "\<forall>x. (x\<in>s \<and> \<not> P x) \<or> (x \<in> t \<and> P x) \<longrightarrow> f x = g x"
himmelma@33175
  6076
  shows "continuous_on (s \<union> t) (\<lambda>x. if P x then f x else g x)"
himmelma@33175
  6077
proof-
himmelma@33175
  6078
  let ?h = "(\<lambda>x. if P x then f x else g x)"
himmelma@33175
  6079
  have "\<forall>x\<in>s. f x = (if P x then f x else g x)" using assms(5) by auto
himmelma@33175
  6080
  hence "continuous_on s ?h" using continuous_on_eq[of s f ?h] using assms(3) by auto
himmelma@33175
  6081
  moreover
himmelma@33175
  6082
  have "\<forall>x\<in>t. g x = (if P x then f x else g x)" using assms(5) by auto
himmelma@33175
  6083
  hence "continuous_on t ?h" using continuous_on_eq[of t g ?h] using assms(4) by auto
himmelma@33175
  6084
  ultimately show ?thesis using continuous_on_union[OF assms(1,2), of ?h] by auto
himmelma@33175
  6085
qed
himmelma@33175
  6086
himmelma@33175
  6087
himmelma@33175
  6088
text{* Some more convenient intermediate-value theorem formulations.             *}
himmelma@33175
  6089
himmelma@33175
  6090
lemma connected_ivt_hyperplane:
himmelma@33175
  6091
  assumes "connected s" "x \<in> s" "y \<in> s" "inner a x \<le> b" "b \<le> inner a y"
himmelma@33175
  6092
  shows "\<exists>z \<in> s. inner a z = b"
himmelma@33175
  6093
proof(rule ccontr)
himmelma@33175
  6094
  assume as:"\<not> (\<exists>z\<in>s. inner a z = b)"
himmelma@33175
  6095
  let ?A = "{x. inner a x < b}"
himmelma@33175
  6096
  let ?B = "{x. inner a x > b}"
himmelma@33175
  6097
  have "open ?A" "open ?B" using open_halfspace_lt and open_halfspace_gt by auto
himmelma@33175
  6098
  moreover have "?A \<inter> ?B = {}" by auto
himmelma@33175
  6099
  moreover have "s \<subseteq> ?A \<union> ?B" using as by auto
himmelma@33175
  6100
  ultimately show False using assms(1)[unfolded connected_def not_ex, THEN spec[where x="?A"], THEN spec[where x="?B"]] and assms(2-5) by auto
himmelma@33175
  6101
qed
himmelma@33175
  6102
huffman@37673
  6103
lemma connected_ivt_component: fixes x::"'a::euclidean_space" shows
hoelzl@51541
  6104
 "connected s \<Longrightarrow> x \<in> s \<Longrightarrow> y \<in> s \<Longrightarrow> x\<bullet>k \<le> a \<Longrightarrow> a \<le> y\<bullet>k \<Longrightarrow> (\<exists>z\<in>s.  z\<bullet>k = a)"
hoelzl@51541
  6105
  using connected_ivt_hyperplane[of s x y "k::'a" a] by (auto simp: inner_commute)
himmelma@33175
  6106
huffman@45081
  6107
huffman@36433
  6108
subsection {* Homeomorphisms *}
himmelma@33175
  6109
himmelma@33175
  6110
definition "homeomorphism s t f g \<equiv>
himmelma@33175
  6111
     (\<forall>x\<in>s. (g(f x) = x)) \<and> (f ` s = t) \<and> continuous_on s f \<and>
himmelma@33175
  6112
     (\<forall>y\<in>t. (f(g y) = y)) \<and> (g ` t = s) \<and> continuous_on t g"
himmelma@33175
  6113
himmelma@33175
  6114
definition
huffman@51913
  6115
  homeomorphic :: "'a::topological_space set \<Rightarrow> 'b::topological_space set \<Rightarrow> bool"
himmelma@33175
  6116
    (infixr "homeomorphic" 60) where
himmelma@33175
  6117
  homeomorphic_def: "s homeomorphic t \<equiv> (\<exists>f g. homeomorphism s t f g)"
himmelma@33175
  6118
himmelma@33175
  6119
lemma homeomorphic_refl: "s homeomorphic s"
himmelma@33175
  6120
  unfolding homeomorphic_def
himmelma@33175
  6121
  unfolding homeomorphism_def
himmelma@33175
  6122
  using continuous_on_id
himmelma@33175
  6123
  apply(rule_tac x = "(\<lambda>x. x)" in exI)
himmelma@33175
  6124
  apply(rule_tac x = "(\<lambda>x. x)" in exI)
himmelma@33175
  6125
  by blast
himmelma@33175
  6126
himmelma@33175
  6127
lemma homeomorphic_sym:
himmelma@33175
  6128
 "s homeomorphic t \<longleftrightarrow> t homeomorphic s"
himmelma@33175
  6129
unfolding homeomorphic_def
himmelma@33175
  6130
unfolding homeomorphism_def
paulson@33307
  6131
by blast 
himmelma@33175
  6132
himmelma@33175
  6133
lemma homeomorphic_trans:
himmelma@33175
  6134
  assumes "s homeomorphic t" "t homeomorphic u" shows "s homeomorphic u"
himmelma@33175
  6135
proof-
himmelma@33175
  6136
  obtain f1 g1 where fg1:"\<forall>x\<in>s. g1 (f1 x) = x"  "f1 ` s = t" "continuous_on s f1" "\<forall>y\<in>t. f1 (g1 y) = y" "g1 ` t = s" "continuous_on t g1"
himmelma@33175
  6137
    using assms(1) unfolding homeomorphic_def homeomorphism_def by auto
himmelma@33175
  6138
  obtain f2 g2 where fg2:"\<forall>x\<in>t. g2 (f2 x) = x"  "f2 ` t = u" "continuous_on t f2" "\<forall>y\<in>u. f2 (g2 y) = y" "g2 ` u = t" "continuous_on u g2"
himmelma@33175
  6139
    using assms(2) unfolding homeomorphic_def homeomorphism_def by auto
himmelma@33175
  6140
himmelma@33175
  6141
  { fix x assume "x\<in>s" hence "(g1 \<circ> g2) ((f2 \<circ> f1) x) = x" using fg1(1)[THEN bspec[where x=x]] and fg2(1)[THEN bspec[where x="f1 x"]] and fg1(2) by auto }
himmelma@33175
  6142
  moreover have "(f2 \<circ> f1) ` s = u" using fg1(2) fg2(2) by auto
himmelma@33175
  6143
  moreover have "continuous_on s (f2 \<circ> f1)" using continuous_on_compose[OF fg1(3)] and fg2(3) unfolding fg1(2) by auto
himmelma@33175
  6144
  moreover { fix y assume "y\<in>u" hence "(f2 \<circ> f1) ((g1 \<circ> g2) y) = y" using fg2(4)[THEN bspec[where x=y]] and fg1(4)[THEN bspec[where x="g2 y"]] and fg2(5) by auto }
himmelma@33175
  6145
  moreover have "(g1 \<circ> g2) ` u = s" using fg1(5) fg2(5) by auto
himmelma@33175
  6146
  moreover have "continuous_on u (g1 \<circ> g2)" using continuous_on_compose[OF fg2(6)] and fg1(6)  unfolding fg2(5) by auto
himmelma@33175
  6147
  ultimately show ?thesis unfolding homeomorphic_def homeomorphism_def apply(rule_tac x="f2 \<circ> f1" in exI) apply(rule_tac x="g1 \<circ> g2" in exI) by auto
himmelma@33175
  6148
qed
himmelma@33175
  6149
himmelma@33175
  6150
lemma homeomorphic_minimal:
himmelma@33175
  6151
 "s homeomorphic t \<longleftrightarrow>
himmelma@33175
  6152
    (\<exists>f g. (\<forall>x\<in>s. f(x) \<in> t \<and> (g(f(x)) = x)) \<and>
himmelma@33175
  6153
           (\<forall>y\<in>t. g(y) \<in> s \<and> (f(g(y)) = y)) \<and>
himmelma@33175
  6154
           continuous_on s f \<and> continuous_on t g)"
himmelma@33175
  6155
unfolding homeomorphic_def homeomorphism_def
himmelma@33175
  6156
apply auto apply (rule_tac x=f in exI) apply (rule_tac x=g in exI)
himmelma@33175
  6157
apply auto apply (rule_tac x=f in exI) apply (rule_tac x=g in exI) apply auto
himmelma@33175
  6158
unfolding image_iff
himmelma@33175
  6159
apply(erule_tac x="g x" in ballE) apply(erule_tac x="x" in ballE)
himmelma@33175
  6160
apply auto apply(rule_tac x="g x" in bexI) apply auto
himmelma@33175
  6161
apply(erule_tac x="f x" in ballE) apply(erule_tac x="x" in ballE)
himmelma@33175
  6162
apply auto apply(rule_tac x="f x" in bexI) by auto
himmelma@33175
  6163
huffman@36433
  6164
text {* Relatively weak hypotheses if a set is compact. *}
himmelma@33175
  6165
himmelma@33175
  6166
lemma homeomorphism_compact:
huffman@51913
  6167
  fixes f :: "'a::topological_space \<Rightarrow> 'b::t2_space"
himmelma@33175
  6168
  assumes "compact s" "continuous_on s f"  "f ` s = t"  "inj_on f s"
himmelma@33175
  6169
  shows "\<exists>g. homeomorphism s t f g"
himmelma@33175
  6170
proof-
himmelma@33175
  6171
  def g \<equiv> "\<lambda>x. SOME y. y\<in>s \<and> f y = x"
himmelma@33175
  6172
  have g:"\<forall>x\<in>s. g (f x) = x" using assms(3) assms(4)[unfolded inj_on_def] unfolding g_def by auto
himmelma@33175
  6173
  { fix y assume "y\<in>t"
himmelma@33175
  6174
    then obtain x where x:"f x = y" "x\<in>s" using assms(3) by auto
himmelma@33175
  6175
    hence "g (f x) = x" using g by auto
himmelma@33175
  6176
    hence "f (g y) = y" unfolding x(1)[THEN sym] by auto  }
himmelma@33175
  6177
  hence g':"\<forall>x\<in>t. f (g x) = x" by auto
himmelma@33175
  6178
  moreover
himmelma@33175
  6179
  { fix x
himmelma@33175
  6180
    have "x\<in>s \<Longrightarrow> x \<in> g ` t" using g[THEN bspec[where x=x]] unfolding image_iff using assms(3) by(auto intro!: bexI[where x="f x"])
himmelma@33175
  6181
    moreover
himmelma@33175
  6182
    { assume "x\<in>g ` t"
himmelma@33175
  6183
      then obtain y where y:"y\<in>t" "g y = x" by auto
himmelma@33175
  6184
      then obtain x' where x':"x'\<in>s" "f x' = y" using assms(3) by auto
himmelma@33175
  6185
      hence "x \<in> s" unfolding g_def using someI2[of "\<lambda>b. b\<in>s \<and> f b = y" x' "\<lambda>x. x\<in>s"] unfolding y(2)[THEN sym] and g_def by auto }
huffman@36358
  6186
    ultimately have "x\<in>s \<longleftrightarrow> x \<in> g ` t" ..  }
himmelma@33175
  6187
  hence "g ` t = s" by auto
himmelma@33175
  6188
  ultimately
himmelma@33175
  6189
  show ?thesis unfolding homeomorphism_def homeomorphic_def
huffman@45511
  6190
    apply(rule_tac x=g in exI) using g and assms(3) and continuous_on_inv[OF assms(2,1), of g, unfolded assms(3)] and assms(2) by auto
himmelma@33175
  6191
qed
himmelma@33175
  6192
himmelma@33175
  6193
lemma homeomorphic_compact:
huffman@51913
  6194
  fixes f :: "'a::topological_space \<Rightarrow> 'b::t2_space"
himmelma@33175
  6195
  shows "compact s \<Longrightarrow> continuous_on s f \<Longrightarrow> (f ` s = t) \<Longrightarrow> inj_on f s
himmelma@33175
  6196
          \<Longrightarrow> s homeomorphic t"
blanchet@37486
  6197
  unfolding homeomorphic_def by (metis homeomorphism_compact)
himmelma@33175
  6198
himmelma@33175
  6199
text{* Preservation of topological properties.                                   *}
himmelma@33175
  6200
himmelma@33175
  6201
lemma homeomorphic_compactness:
himmelma@33175
  6202
 "s homeomorphic t ==> (compact s \<longleftrightarrow> compact t)"
himmelma@33175
  6203
unfolding homeomorphic_def homeomorphism_def
himmelma@33175
  6204
by (metis compact_continuous_image)
himmelma@33175
  6205
himmelma@33175
  6206
text{* Results on translation, scaling etc.                                      *}
himmelma@33175
  6207
himmelma@33175
  6208
lemma homeomorphic_scaling:
himmelma@33175
  6209
  fixes s :: "'a::real_normed_vector set"
himmelma@33175
  6210
  assumes "c \<noteq> 0"  shows "s homeomorphic ((\<lambda>x. c *\<^sub>R x) ` s)"
himmelma@33175
  6211
  unfolding homeomorphic_minimal
himmelma@33175
  6212
  apply(rule_tac x="\<lambda>x. c *\<^sub>R x" in exI)
himmelma@33175
  6213
  apply(rule_tac x="\<lambda>x. (1 / c) *\<^sub>R x" in exI)
huffman@45386
  6214
  using assms by (auto simp add: continuous_on_intros)
himmelma@33175
  6215
himmelma@33175
  6216
lemma homeomorphic_translation:
himmelma@33175
  6217
  fixes s :: "'a::real_normed_vector set"
himmelma@33175
  6218
  shows "s homeomorphic ((\<lambda>x. a + x) ` s)"
himmelma@33175
  6219
  unfolding homeomorphic_minimal
himmelma@33175
  6220
  apply(rule_tac x="\<lambda>x. a + x" in exI)
himmelma@33175
  6221
  apply(rule_tac x="\<lambda>x. -a + x" in exI)
himmelma@33175
  6222
  using continuous_on_add[OF continuous_on_const continuous_on_id] by auto
himmelma@33175
  6223
himmelma@33175
  6224
lemma homeomorphic_affinity:
himmelma@33175
  6225
  fixes s :: "'a::real_normed_vector set"
himmelma@33175
  6226
  assumes "c \<noteq> 0"  shows "s homeomorphic ((\<lambda>x. a + c *\<^sub>R x) ` s)"
himmelma@33175
  6227
proof-
himmelma@33175
  6228
  have *:"op + a ` op *\<^sub>R c ` s = (\<lambda>x. a + c *\<^sub>R x) ` s" by auto
himmelma@33175
  6229
  show ?thesis
himmelma@33175
  6230
    using homeomorphic_trans
himmelma@33175
  6231
    using homeomorphic_scaling[OF assms, of s]
himmelma@33175
  6232
    using homeomorphic_translation[of "(\<lambda>x. c *\<^sub>R x) ` s" a] unfolding * by auto
himmelma@33175
  6233
qed
himmelma@33175
  6234
himmelma@33175
  6235
lemma homeomorphic_balls:
huffman@51913
  6236
  fixes a b ::"'a::real_normed_vector"
himmelma@33175
  6237
  assumes "0 < d"  "0 < e"
himmelma@33175
  6238
  shows "(ball a d) homeomorphic  (ball b e)" (is ?th)
himmelma@33175
  6239
        "(cball a d) homeomorphic (cball b e)" (is ?cth)
himmelma@33175
  6240
proof-
himmelma@33175
  6241
  show ?th unfolding homeomorphic_minimal
himmelma@33175
  6242
    apply(rule_tac x="\<lambda>x. b + (e/d) *\<^sub>R (x - a)" in exI)
himmelma@33175
  6243
    apply(rule_tac x="\<lambda>x. a + (d/e) *\<^sub>R (x - b)" in exI)
himmelma@33175
  6244
    using assms apply (auto simp add: dist_commute)
himmelma@33175
  6245
    unfolding dist_norm
himmelma@33175
  6246
    apply (auto simp add: pos_divide_less_eq mult_strict_left_mono)
himmelma@33175
  6247
    unfolding continuous_on
huffman@36659
  6248
    by (intro ballI tendsto_intros, simp)+
himmelma@33175
  6249
next
himmelma@33175
  6250
  show ?cth unfolding homeomorphic_minimal
himmelma@33175
  6251
    apply(rule_tac x="\<lambda>x. b + (e/d) *\<^sub>R (x - a)" in exI)
himmelma@33175
  6252
    apply(rule_tac x="\<lambda>x. a + (d/e) *\<^sub>R (x - b)" in exI)
himmelma@33175
  6253
    using assms apply (auto simp add: dist_commute)
himmelma@33175
  6254
    unfolding dist_norm
himmelma@33175
  6255
    apply (auto simp add: pos_divide_le_eq)
himmelma@33175
  6256
    unfolding continuous_on
huffman@36659
  6257
    by (intro ballI tendsto_intros, simp)+
himmelma@33175
  6258
qed
himmelma@33175
  6259
himmelma@33175
  6260
text{* "Isometry" (up to constant bounds) of injective linear map etc.           *}
himmelma@33175
  6261
himmelma@33175
  6262
lemma cauchy_isometric:
hoelzl@37489
  6263
  fixes x :: "nat \<Rightarrow> 'a::euclidean_space"
himmelma@33175
  6264
  assumes e:"0 < e" and s:"subspace s" and f:"bounded_linear f" and normf:"\<forall>x\<in>s. norm(f x) \<ge> e * norm(x)" and xs:"\<forall>n::nat. x n \<in> s" and cf:"Cauchy(f o x)"
himmelma@33175
  6265
  shows "Cauchy x"
himmelma@33175
  6266
proof-
himmelma@33175
  6267
  interpret f: bounded_linear f by fact
himmelma@33175
  6268
  { fix d::real assume "d>0"
himmelma@33175
  6269
    then obtain N where N:"\<forall>n\<ge>N. norm (f (x n) - f (x N)) < e * d"
himmelma@33175
  6270
      using cf[unfolded cauchy o_def dist_norm, THEN spec[where x="e*d"]] and e and mult_pos_pos[of e d] by auto
himmelma@33175
  6271
    { fix n assume "n\<ge>N"
huffman@46141
  6272
      have "e * norm (x n - x N) \<le> norm (f (x n - x N))"
himmelma@33175
  6273
        using subspace_sub[OF s, of "x n" "x N"] using xs[THEN spec[where x=N]] and xs[THEN spec[where x=n]]
himmelma@33175
  6274
        using normf[THEN bspec[where x="x n - x N"]] by auto
huffman@46141
  6275
      also have "norm (f (x n - x N)) < e * d"
huffman@46141
  6276
        using `N \<le> n` N unfolding f.diff[THEN sym] by auto
huffman@46141
  6277
      finally have "norm (x n - x N) < d" using `e>0` by simp }
himmelma@33175
  6278
    hence "\<exists>N. \<forall>n\<ge>N. norm (x n - x N) < d" by auto }
himmelma@33175
  6279
  thus ?thesis unfolding cauchy and dist_norm by auto
himmelma@33175
  6280
qed
himmelma@33175
  6281
himmelma@33175
  6282
lemma complete_isometric_image:
hoelzl@37489
  6283
  fixes f :: "'a::euclidean_space => 'b::euclidean_space"
himmelma@33175
  6284
  assumes "0 < e" and s:"subspace s" and f:"bounded_linear f" and normf:"\<forall>x\<in>s. norm(f x) \<ge> e * norm(x)" and cs:"complete s"
himmelma@33175
  6285
  shows "complete(f ` s)"
himmelma@33175
  6286
proof-
himmelma@33175
  6287
  { fix g assume as:"\<forall>n::nat. g n \<in> f ` s" and cfg:"Cauchy g"
paulson@33307
  6288
    then obtain x where "\<forall>n. x n \<in> s \<and> g n = f (x n)" 
himmelma@33175
  6289
      using choice[of "\<lambda> n xa. xa \<in> s \<and> g n = f xa"] by auto
himmelma@33175
  6290
    hence x:"\<forall>n. x n \<in> s"  "\<forall>n. g n = f (x n)" by auto
nipkow@39535
  6291
    hence "f \<circ> x = g" unfolding fun_eq_iff by auto
himmelma@33175
  6292
    then obtain l where "l\<in>s" and l:"(x ---> l) sequentially"
himmelma@33175
  6293
      using cs[unfolded complete_def, THEN spec[where x="x"]]
himmelma@33175
  6294
      using cauchy_isometric[OF `0<e` s f normf] and cfg and x(1) by auto
himmelma@33175
  6295
    hence "\<exists>l\<in>f ` s. (g ---> l) sequentially"
himmelma@33175
  6296
      using linear_continuous_at[OF f, unfolded continuous_at_sequentially, THEN spec[where x=x], of l]
himmelma@33175
  6297
      unfolding `f \<circ> x = g` by auto  }
himmelma@33175
  6298
  thus ?thesis unfolding complete_def by auto
himmelma@33175
  6299
qed
himmelma@33175
  6300
himmelma@33175
  6301
lemma dist_0_norm:
himmelma@33175
  6302
  fixes x :: "'a::real_normed_vector"
himmelma@33175
  6303
  shows "dist 0 x = norm x"
himmelma@33175
  6304
unfolding dist_norm by simp
himmelma@33175
  6305
hoelzl@37489
  6306
lemma injective_imp_isometric: fixes f::"'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
himmelma@33175
  6307
  assumes s:"closed s"  "subspace s"  and f:"bounded_linear f" "\<forall>x\<in>s. (f x = 0) \<longrightarrow> (x = 0)"
himmelma@33175
  6308
  shows "\<exists>e>0. \<forall>x\<in>s. norm (f x) \<ge> e * norm(x)"
hoelzl@37489
  6309
proof(cases "s \<subseteq> {0::'a}")
himmelma@33175
  6310
  case True
himmelma@33175
  6311
  { fix x assume "x \<in> s"
himmelma@33175
  6312
    hence "x = 0" using True by auto
himmelma@33175
  6313
    hence "norm x \<le> norm (f x)" by auto  }
himmelma@33175
  6314
  thus ?thesis by(auto intro!: exI[where x=1])
himmelma@33175
  6315
next
himmelma@33175
  6316
  interpret f: bounded_linear f by fact
himmelma@33175
  6317
  case False
himmelma@33175
  6318
  then obtain a where a:"a\<noteq>0" "a\<in>s" by auto
himmelma@33175
  6319
  from False have "s \<noteq> {}" by auto
himmelma@33175
  6320
  let ?S = "{f x| x. (x \<in> s \<and> norm x = norm a)}"
hoelzl@37489
  6321
  let ?S' = "{x::'a. x\<in>s \<and> norm x = norm a}"
hoelzl@37489
  6322
  let ?S'' = "{x::'a. norm x = norm a}"
himmelma@33175
  6323
huffman@36358
  6324
  have "?S'' = frontier(cball 0 (norm a))" unfolding frontier_cball and dist_norm by auto
himmelma@33175
  6325
  hence "compact ?S''" using compact_frontier[OF compact_cball, of 0 "norm a"] by auto
himmelma@33175
  6326
  moreover have "?S' = s \<inter> ?S''" by auto
himmelma@33175
  6327
  ultimately have "compact ?S'" using closed_inter_compact[of s ?S''] using s(1) by auto
himmelma@33175
  6328
  moreover have *:"f ` ?S' = ?S" by auto
himmelma@33175
  6329
  ultimately have "compact ?S" using compact_continuous_image[OF linear_continuous_on[OF f(1)], of ?S'] by auto
himmelma@33175
  6330
  hence "closed ?S" using compact_imp_closed by auto
himmelma@33175
  6331
  moreover have "?S \<noteq> {}" using a by auto
himmelma@33175
  6332
  ultimately obtain b' where "b'\<in>?S" "\<forall>y\<in>?S. norm b' \<le> norm y" using distance_attains_inf[of ?S 0] unfolding dist_0_norm by auto
himmelma@33175
  6333
  then obtain b where "b\<in>s" and ba:"norm b = norm a" and b:"\<forall>x\<in>{x \<in> s. norm x = norm a}. norm (f b) \<le> norm (f x)" unfolding *[THEN sym] unfolding image_iff by auto
himmelma@33175
  6334
himmelma@33175
  6335
  let ?e = "norm (f b) / norm b"
himmelma@33175
  6336
  have "norm b > 0" using ba and a and norm_ge_zero by auto
himmelma@33175
  6337
  moreover have "norm (f b) > 0" using f(2)[THEN bspec[where x=b], OF `b\<in>s`] using `norm b >0` unfolding zero_less_norm_iff by auto
himmelma@33175
  6338
  ultimately have "0 < norm (f b) / norm b" by(simp only: divide_pos_pos)
himmelma@33175
  6339
  moreover
himmelma@33175
  6340
  { fix x assume "x\<in>s"
himmelma@33175
  6341
    hence "norm (f b) / norm b * norm x \<le> norm (f x)"
himmelma@33175
  6342
    proof(cases "x=0")
himmelma@33175
  6343
      case True thus "norm (f b) / norm b * norm x \<le> norm (f x)" by auto
himmelma@33175
  6344
    next
himmelma@33175
  6345
      case False
himmelma@33175
  6346
      hence *:"0 < norm a / norm x" using `a\<noteq>0` unfolding zero_less_norm_iff[THEN sym] by(simp only: divide_pos_pos)
hoelzl@37489
  6347
      have "\<forall>c. \<forall>x\<in>s. c *\<^sub>R x \<in> s" using s[unfolded subspace_def] by auto
himmelma@33175
  6348
      hence "(norm a / norm x) *\<^sub>R x \<in> {x \<in> s. norm x = norm a}" using `x\<in>s` and `x\<noteq>0` by auto
himmelma@33175
  6349
      thus "norm (f b) / norm b * norm x \<le> norm (f x)" using b[THEN bspec[where x="(norm a / norm x) *\<^sub>R x"]]
himmelma@33175
  6350
        unfolding f.scaleR and ba using `x\<noteq>0` `a\<noteq>0`
huffman@36770
  6351
        by (auto simp add: mult_commute pos_le_divide_eq pos_divide_le_eq)
himmelma@33175
  6352
    qed }
himmelma@33175
  6353
  ultimately
himmelma@33175
  6354
  show ?thesis by auto
himmelma@33175
  6355
qed
himmelma@33175
  6356
himmelma@33175
  6357
lemma closed_injective_image_subspace:
hoelzl@37489
  6358
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
himmelma@33175
  6359
  assumes "subspace s" "bounded_linear f" "\<forall>x\<in>s. f x = 0 --> x = 0" "closed s"
himmelma@33175
  6360
  shows "closed(f ` s)"
himmelma@33175
  6361
proof-
himmelma@33175
  6362
  obtain e where "e>0" and e:"\<forall>x\<in>s. e * norm x \<le> norm (f x)" using injective_imp_isometric[OF assms(4,1,2,3)] by auto
himmelma@33175
  6363
  show ?thesis using complete_isometric_image[OF `e>0` assms(1,2) e] and assms(4)
himmelma@33175
  6364
    unfolding complete_eq_closed[THEN sym] by auto
himmelma@33175
  6365
qed
himmelma@33175
  6366
huffman@45081
  6367
huffman@45081
  6368
subsection {* Some properties of a canonical subspace *}
himmelma@33175
  6369
himmelma@33175
  6370
lemma subspace_substandard:
hoelzl@51541
  6371
  "subspace {x::'a::euclidean_space. (\<forall>i\<in>Basis. P i \<longrightarrow> x\<bullet>i = 0)}"
hoelzl@51541
  6372
  unfolding subspace_def by (auto simp: inner_add_left)
himmelma@33175
  6373
himmelma@33175
  6374
lemma closed_substandard:
hoelzl@51541
  6375
 "closed {x::'a::euclidean_space. \<forall>i\<in>Basis. P i --> x\<bullet>i = 0}" (is "closed ?A")
himmelma@33175
  6376
proof-
hoelzl@51541
  6377
  let ?D = "{i\<in>Basis. P i}"
hoelzl@51541
  6378
  have "closed (\<Inter>i\<in>?D. {x::'a. x\<bullet>i = 0})"
huffman@45314
  6379
    by (simp add: closed_INT closed_Collect_eq)
hoelzl@51541
  6380
  also have "(\<Inter>i\<in>?D. {x::'a. x\<bullet>i = 0}) = ?A"
huffman@45314
  6381
    by auto
huffman@45314
  6382
  finally show "closed ?A" .
himmelma@33175
  6383
qed
himmelma@33175
  6384
hoelzl@51541
  6385
lemma dim_substandard: assumes d: "d \<subseteq> Basis"
hoelzl@51541
  6386
  shows "dim {x::'a::euclidean_space. \<forall>i\<in>Basis. i \<notin> d \<longrightarrow> x\<bullet>i = 0} = card d" (is "dim ?A = _")
himmelma@33175
  6387
proof-
hoelzl@51541
  6388
  let ?D = "Basis :: 'a set"
hoelzl@51541
  6389
  have "d \<subseteq> ?A" using d by (auto simp: inner_Basis)
himmelma@33175
  6390
  moreover
hoelzl@51541
  6391
  { fix x::"'a" assume "x \<in> ?A"
hoelzl@51541
  6392
    hence "finite d" "x \<in> ?A" using assms by(auto intro: finite_subset[OF _ finite_Basis])
hoelzl@51541
  6393
    from this d have "x \<in> span d"
himmelma@33175
  6394
    proof(induct d arbitrary: x)
hoelzl@51541
  6395
      case empty hence "x=0" apply(rule_tac euclidean_eqI) by auto
himmelma@33175
  6396
      thus ?case using subspace_0[OF subspace_span[of "{}"]] by auto
himmelma@33175
  6397
    next
himmelma@33175
  6398
      case (insert k F)
hoelzl@51541
  6399
      hence *:"\<forall>i\<in>Basis. i \<notin> insert k F \<longrightarrow> x \<bullet> i = 0" by auto
himmelma@33175
  6400
      have **:"F \<subseteq> insert k F" by auto
hoelzl@51541
  6401
      def y \<equiv> "x - (x\<bullet>k) *\<^sub>R k"
hoelzl@51541
  6402
      have y:"x = y + (x\<bullet>k) *\<^sub>R k" unfolding y_def by auto
hoelzl@51541
  6403
      { fix i assume i': "i \<notin> F" "i \<in> Basis"
hoelzl@51541
  6404
        hence "y \<bullet> i = 0" unfolding y_def 
hoelzl@51541
  6405
          using *[THEN bspec[where x=i]] insert by (auto simp: inner_simps inner_Basis) }
hoelzl@51541
  6406
      hence "y \<in> span F" using insert by auto
hoelzl@51541
  6407
      hence "y \<in> span (insert k F)"
hoelzl@51541
  6408
        using span_mono[of F "insert k F"] using assms by auto
himmelma@33175
  6409
      moreover
hoelzl@51541
  6410
      have "k \<in> span (insert k F)" by(rule span_superset, auto)
hoelzl@51541
  6411
      hence "(x\<bullet>k) *\<^sub>R k \<in> span (insert k F)"
huffman@36593
  6412
        using span_mul by auto
himmelma@33175
  6413
      ultimately
hoelzl@51541
  6414
      have "y + (x\<bullet>k) *\<^sub>R k \<in> span (insert k F)"
himmelma@33175
  6415
        using span_add by auto
himmelma@33175
  6416
      thus ?case using y by auto
himmelma@33175
  6417
    qed
himmelma@33175
  6418
  }
hoelzl@51541
  6419
  hence "?A \<subseteq> span d" by auto
himmelma@33175
  6420
  moreover
hoelzl@51541
  6421
  { fix x assume "x \<in> d" hence "x \<in> ?D" using assms by auto  }
hoelzl@51541
  6422
  hence "independent d" using independent_mono[OF independent_Basis, of d] and assms by auto
himmelma@33175
  6423
  moreover
himmelma@33175
  6424
  have "d \<subseteq> ?D" unfolding subset_eq using assms by auto
hoelzl@51541
  6425
  ultimately show ?thesis using dim_unique[of d ?A] by auto
himmelma@33175
  6426
qed
himmelma@33175
  6427
himmelma@33175
  6428
text{* Hence closure and completeness of all subspaces.                          *}
himmelma@33175
  6429
hoelzl@51541
  6430
lemma ex_card: assumes "n \<le> card A" shows "\<exists>S\<subseteq>A. card S = n"
hoelzl@51541
  6431
proof cases
hoelzl@51541
  6432
  assume "finite A"
hoelzl@51541
  6433
  from ex_bij_betw_nat_finite[OF this] guess f ..
hoelzl@51541
  6434
  moreover with `n \<le> card A` have "{..< n} \<subseteq> {..< card A}" "inj_on f {..< n}"
hoelzl@51541
  6435
    by (auto simp: bij_betw_def intro: subset_inj_on)
hoelzl@51541
  6436
  ultimately have "f ` {..< n} \<subseteq> A" "card (f ` {..< n}) = n"
hoelzl@51541
  6437
    by (auto simp: bij_betw_def card_image)
hoelzl@51541
  6438
  then show ?thesis by blast
hoelzl@51541
  6439
next
hoelzl@51541
  6440
  assume "\<not> finite A" with `n \<le> card A` show ?thesis by force
hoelzl@51541
  6441
qed
himmelma@33175
  6442
hoelzl@37489
  6443
lemma closed_subspace: fixes s::"('a::euclidean_space) set"
himmelma@33175
  6444
  assumes "subspace s" shows "closed s"
himmelma@33175
  6445
proof-
hoelzl@51541
  6446
  have "dim s \<le> card (Basis :: 'a set)" using dim_subset_UNIV by auto
hoelzl@51541
  6447
  with ex_card[OF this] obtain d :: "'a set" where t: "card d = dim s" and d: "d \<subseteq> Basis" by auto
hoelzl@51541
  6448
  let ?t = "{x::'a. \<forall>i\<in>Basis. i \<notin> d \<longrightarrow> x\<bullet>i = 0}"
hoelzl@51541
  6449
  have "\<exists>f. linear f \<and> f ` {x::'a. \<forall>i\<in>Basis. i \<notin> d \<longrightarrow> x \<bullet> i = 0} = s \<and>
hoelzl@51541
  6450
      inj_on f {x::'a. \<forall>i\<in>Basis. i \<notin> d \<longrightarrow> x \<bullet> i = 0}"
hoelzl@51541
  6451
    using dim_substandard[of d] t d assms
hoelzl@51541
  6452
    by (intro subspace_isomorphism[OF subspace_substandard[of "\<lambda>i. i \<notin> d"]]) (auto simp: inner_Basis)
hoelzl@51541
  6453
  then guess f by (elim exE conjE) note f = this
hoelzl@37489
  6454
  interpret f: bounded_linear f using f unfolding linear_conv_bounded_linear by auto
hoelzl@51541
  6455
  { fix x have "x\<in>?t \<Longrightarrow> f x = 0 \<Longrightarrow> x = 0" using f.zero d f(3)[THEN inj_onD, of x 0] by auto }
himmelma@33175
  6456
  moreover have "closed ?t" using closed_substandard .
himmelma@33175
  6457
  moreover have "subspace ?t" using subspace_substandard .
himmelma@33175
  6458
  ultimately show ?thesis using closed_injective_image_subspace[of ?t f]
hoelzl@37489
  6459
    unfolding f(2) using f(1) unfolding linear_conv_bounded_linear by auto
himmelma@33175
  6460
qed
himmelma@33175
  6461
himmelma@33175
  6462
lemma complete_subspace:
hoelzl@37489
  6463
  fixes s :: "('a::euclidean_space) set" shows "subspace s ==> complete s"
himmelma@33175
  6464
  using complete_eq_closed closed_subspace
himmelma@33175
  6465
  by auto
himmelma@33175
  6466
himmelma@33175
  6467
lemma dim_closure:
hoelzl@37489
  6468
  fixes s :: "('a::euclidean_space) set"
himmelma@33175
  6469
  shows "dim(closure s) = dim s" (is "?dc = ?d")
himmelma@33175
  6470
proof-
himmelma@33175
  6471
  have "?dc \<le> ?d" using closure_minimal[OF span_inc, of s]
himmelma@33175
  6472
    using closed_subspace[OF subspace_span, of s]
himmelma@33175
  6473
    using dim_subset[of "closure s" "span s"] unfolding dim_span by auto
himmelma@33175
  6474
  thus ?thesis using dim_subset[OF closure_subset, of s] by auto
himmelma@33175
  6475
qed
himmelma@33175
  6476
huffman@45081
  6477
huffman@36433
  6478
subsection {* Affine transformations of intervals *}
himmelma@33175
  6479
himmelma@33175
  6480
lemma real_affinity_le:
haftmann@35028
  6481
 "0 < (m::'a::linordered_field) ==> (m * x + c \<le> y \<longleftrightarrow> x \<le> inverse(m) * y + -(c / m))"
himmelma@33175
  6482
  by (simp add: field_simps inverse_eq_divide)
himmelma@33175
  6483
himmelma@33175
  6484
lemma real_le_affinity:
haftmann@35028
  6485
 "0 < (m::'a::linordered_field) ==> (y \<le> m * x + c \<longleftrightarrow> inverse(m) * y + -(c / m) \<le> x)"
himmelma@33175
  6486
  by (simp add: field_simps inverse_eq_divide)
himmelma@33175
  6487
himmelma@33175
  6488
lemma real_affinity_lt:
haftmann@35028
  6489
 "0 < (m::'a::linordered_field) ==> (m * x + c < y \<longleftrightarrow> x < inverse(m) * y + -(c / m))"
himmelma@33175
  6490
  by (simp add: field_simps inverse_eq_divide)
himmelma@33175
  6491
himmelma@33175
  6492
lemma real_lt_affinity:
haftmann@35028
  6493
 "0 < (m::'a::linordered_field) ==> (y < m * x + c \<longleftrightarrow> inverse(m) * y + -(c / m) < x)"
himmelma@33175
  6494
  by (simp add: field_simps inverse_eq_divide)
himmelma@33175
  6495
himmelma@33175
  6496
lemma real_affinity_eq:
haftmann@35028
  6497
 "(m::'a::linordered_field) \<noteq> 0 ==> (m * x + c = y \<longleftrightarrow> x = inverse(m) * y + -(c / m))"
himmelma@33175
  6498
  by (simp add: field_simps inverse_eq_divide)
himmelma@33175
  6499
himmelma@33175
  6500
lemma real_eq_affinity:
haftmann@35028
  6501
 "(m::'a::linordered_field) \<noteq> 0 ==> (y = m * x + c  \<longleftrightarrow> inverse(m) * y + -(c / m) = x)"
himmelma@33175
  6502
  by (simp add: field_simps inverse_eq_divide)
himmelma@33175
  6503
himmelma@33175
  6504
lemma image_affinity_interval: fixes m::real
hoelzl@37489
  6505
  fixes a b c :: "'a::ordered_euclidean_space"
himmelma@33175
  6506
  shows "(\<lambda>x. m *\<^sub>R x + c) ` {a .. b} =
himmelma@33175
  6507
            (if {a .. b} = {} then {}
himmelma@33175
  6508
            else (if 0 \<le> m then {m *\<^sub>R a + c .. m *\<^sub>R b + c}
himmelma@33175
  6509
            else {m *\<^sub>R b + c .. m *\<^sub>R a + c}))"
hoelzl@37489
  6510
proof(cases "m=0")  
himmelma@33175
  6511
  { fix x assume "x \<le> c" "c \<le> x"
hoelzl@37489
  6512
    hence "x=c" unfolding eucl_le[where 'a='a] apply-
hoelzl@51541
  6513
      apply(subst euclidean_eq_iff) by (auto intro: order_antisym) }
himmelma@33175
  6514
  moreover case True
hoelzl@37489
  6515
  moreover have "c \<in> {m *\<^sub>R a + c..m *\<^sub>R b + c}" unfolding True by(auto simp add: eucl_le[where 'a='a])
himmelma@33175
  6516
  ultimately show ?thesis by auto
himmelma@33175
  6517
next
himmelma@33175
  6518
  case False
himmelma@33175
  6519
  { fix y assume "a \<le> y" "y \<le> b" "m > 0"
himmelma@33175
  6520
    hence "m *\<^sub>R a + c \<le> m *\<^sub>R y + c"  "m *\<^sub>R y + c \<le> m *\<^sub>R b + c"
hoelzl@51541
  6521
      unfolding eucl_le[where 'a='a] by (auto simp: inner_simps)
himmelma@33175
  6522
  } moreover
himmelma@33175
  6523
  { fix y assume "a \<le> y" "y \<le> b" "m < 0"
himmelma@33175
  6524
    hence "m *\<^sub>R b + c \<le> m *\<^sub>R y + c"  "m *\<^sub>R y + c \<le> m *\<^sub>R a + c"
hoelzl@51541
  6525
      unfolding eucl_le[where 'a='a] by(auto simp add: mult_left_mono_neg inner_simps)
himmelma@33175
  6526
  } moreover
himmelma@33175
  6527
  { fix y assume "m > 0"  "m *\<^sub>R a + c \<le> y"  "y \<le> m *\<^sub>R b + c"
himmelma@33175
  6528
    hence "y \<in> (\<lambda>x. m *\<^sub>R x + c) ` {a..b}"
hoelzl@37489
  6529
      unfolding image_iff Bex_def mem_interval eucl_le[where 'a='a]
huffman@45371
  6530
      apply (intro exI[where x="(1 / m) *\<^sub>R (y - c)"])
hoelzl@51541
  6531
      by(auto simp add: pos_le_divide_eq pos_divide_le_eq mult_commute diff_le_iff inner_simps)
himmelma@33175
  6532
  } moreover
himmelma@33175
  6533
  { fix y assume "m *\<^sub>R b + c \<le> y" "y \<le> m *\<^sub>R a + c" "m < 0"
himmelma@33175
  6534
    hence "y \<in> (\<lambda>x. m *\<^sub>R x + c) ` {a..b}"
hoelzl@37489
  6535
      unfolding image_iff Bex_def mem_interval eucl_le[where 'a='a]
huffman@45371
  6536
      apply (intro exI[where x="(1 / m) *\<^sub>R (y - c)"])
hoelzl@51541
  6537
      by(auto simp add: neg_le_divide_eq neg_divide_le_eq mult_commute diff_le_iff inner_simps)
himmelma@33175
  6538
  }
himmelma@33175
  6539
  ultimately show ?thesis using False by auto
himmelma@33175
  6540
qed
himmelma@33175
  6541
hoelzl@37489
  6542
lemma image_smult_interval:"(\<lambda>x. m *\<^sub>R (x::_::ordered_euclidean_space)) ` {a..b} =
himmelma@33175
  6543
  (if {a..b} = {} then {} else if 0 \<le> m then {m *\<^sub>R a..m *\<^sub>R b} else {m *\<^sub>R b..m *\<^sub>R a})"
himmelma@33175
  6544
  using image_affinity_interval[of m 0 a b] by auto
himmelma@33175
  6545
huffman@45081
  6546
huffman@45081
  6547
subsection {* Banach fixed point theorem (not really topological...) *}
himmelma@33175
  6548
himmelma@33175
  6549
lemma banach_fix:
himmelma@33175
  6550
  assumes s:"complete s" "s \<noteq> {}" and c:"0 \<le> c" "c < 1" and f:"(f ` s) \<subseteq> s" and
himmelma@33175
  6551
          lipschitz:"\<forall>x\<in>s. \<forall>y\<in>s. dist (f x) (f y) \<le> c * dist x y"
himmelma@33175
  6552
  shows "\<exists>! x\<in>s. (f x = x)"
himmelma@33175
  6553
proof-
himmelma@33175
  6554
  have "1 - c > 0" using c by auto
himmelma@33175
  6555
himmelma@33175
  6556
  from s(2) obtain z0 where "z0 \<in> s" by auto
himmelma@33175
  6557
  def z \<equiv> "\<lambda>n. (f ^^ n) z0"
himmelma@33175
  6558
  { fix n::nat
himmelma@33175
  6559
    have "z n \<in> s" unfolding z_def
himmelma@33175
  6560
    proof(induct n) case 0 thus ?case using `z0 \<in>s` by auto
himmelma@33175
  6561
    next case Suc thus ?case using f by auto qed }
himmelma@33175
  6562
  note z_in_s = this
himmelma@33175
  6563
himmelma@33175
  6564
  def d \<equiv> "dist (z 0) (z 1)"
himmelma@33175
  6565
himmelma@33175
  6566
  have fzn:"\<And>n. f (z n) = z (Suc n)" unfolding z_def by auto
himmelma@33175
  6567
  { fix n::nat
himmelma@33175
  6568
    have "dist (z n) (z (Suc n)) \<le> (c ^ n) * d"
himmelma@33175
  6569
    proof(induct n)
himmelma@33175
  6570
      case 0 thus ?case unfolding d_def by auto
himmelma@33175
  6571
    next
himmelma@33175
  6572
      case (Suc m)
himmelma@33175
  6573
      hence "c * dist (z m) (z (Suc m)) \<le> c ^ Suc m * d"
haftmann@38880
  6574
        using `0 \<le> c` using mult_left_mono[of "dist (z m) (z (Suc m))" "c ^ m * d" c] by auto
himmelma@33175
  6575
      thus ?case using lipschitz[THEN bspec[where x="z m"], OF z_in_s, THEN bspec[where x="z (Suc m)"], OF z_in_s]
himmelma@33175
  6576
        unfolding fzn and mult_le_cancel_left by auto
himmelma@33175
  6577
    qed
himmelma@33175
  6578
  } note cf_z = this
himmelma@33175
  6579
himmelma@33175
  6580
  { fix n m::nat
himmelma@33175
  6581
    have "(1 - c) * dist (z m) (z (m+n)) \<le> (c ^ m) * d * (1 - c ^ n)"
himmelma@33175
  6582
    proof(induct n)
himmelma@33175
  6583
      case 0 show ?case by auto
himmelma@33175
  6584
    next
himmelma@33175
  6585
      case (Suc k)
himmelma@33175
  6586
      have "(1 - c) * dist (z m) (z (m + Suc k)) \<le> (1 - c) * (dist (z m) (z (m + k)) + dist (z (m + k)) (z (Suc (m + k))))"
himmelma@33175
  6587
        using dist_triangle and c by(auto simp add: dist_triangle)
himmelma@33175
  6588
      also have "\<dots> \<le> (1 - c) * (dist (z m) (z (m + k)) + c ^ (m + k) * d)"
himmelma@33175
  6589
        using cf_z[of "m + k"] and c by auto
himmelma@33175
  6590
      also have "\<dots> \<le> c ^ m * d * (1 - c ^ k) + (1 - c) * c ^ (m + k) * d"
haftmann@36349
  6591
        using Suc by (auto simp add: field_simps)
himmelma@33175
  6592
      also have "\<dots> = (c ^ m) * (d * (1 - c ^ k) + (1 - c) * c ^ k * d)"
haftmann@36349
  6593
        unfolding power_add by (auto simp add: field_simps)
himmelma@33175
  6594
      also have "\<dots> \<le> (c ^ m) * d * (1 - c ^ Suc k)"
haftmann@36349
  6595
        using c by (auto simp add: field_simps)
himmelma@33175
  6596
      finally show ?case by auto
himmelma@33175
  6597
    qed
himmelma@33175
  6598
  } note cf_z2 = this
himmelma@33175
  6599
  { fix e::real assume "e>0"
himmelma@33175
  6600
    hence "\<exists>N. \<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (z m) (z n) < e"
himmelma@33175
  6601
    proof(cases "d = 0")
himmelma@33175
  6602
      case True
boehmes@42734
  6603
      have *: "\<And>x. ((1 - c) * x \<le> 0) = (x \<le> 0)" using `1 - c > 0`
huffman@45916
  6604
        by (metis mult_zero_left mult_commute real_mult_le_cancel_iff1)
boehmes@42734
  6605
      from True have "\<And>n. z n = z0" using cf_z2[of 0] and c unfolding z_def
boehmes@42734
  6606
        by (simp add: *)
himmelma@33175
  6607
      thus ?thesis using `e>0` by auto
himmelma@33175
  6608
    next
himmelma@33175
  6609
      case False hence "d>0" unfolding d_def using zero_le_dist[of "z 0" "z 1"]
huffman@36770
  6610
        by (metis False d_def less_le)
himmelma@33175
  6611
      hence "0 < e * (1 - c) / d" using `e>0` and `1-c>0`
himmelma@33175
  6612
        using divide_pos_pos[of "e * (1 - c)" d] and mult_pos_pos[of e "1 - c"] by auto
himmelma@33175
  6613
      then obtain N where N:"c ^ N < e * (1 - c) / d" using real_arch_pow_inv[of "e * (1 - c) / d" c] and c by auto
himmelma@33175
  6614
      { fix m n::nat assume "m>n" and as:"m\<ge>N" "n\<ge>N"
himmelma@33175
  6615
        have *:"c ^ n \<le> c ^ N" using `n\<ge>N` and c using power_decreasing[OF `n\<ge>N`, of c] by auto
himmelma@33175
  6616
        have "1 - c ^ (m - n) > 0" using c and power_strict_mono[of c 1 "m - n"] using `m>n` by auto
himmelma@33175
  6617
        hence **:"d * (1 - c ^ (m - n)) / (1 - c) > 0"
huffman@36770
  6618
          using mult_pos_pos[OF `d>0`, of "1 - c ^ (m - n)"]
himmelma@33175
  6619
          using divide_pos_pos[of "d * (1 - c ^ (m - n))" "1 - c"]
himmelma@33175
  6620
          using `0 < 1 - c` by auto
himmelma@33175
  6621
himmelma@33175
  6622
        have "dist (z m) (z n) \<le> c ^ n * d * (1 - c ^ (m - n)) / (1 - c)"
himmelma@33175
  6623
          using cf_z2[of n "m - n"] and `m>n` unfolding pos_le_divide_eq[OF `1-c>0`]
huffman@36770
  6624
          by (auto simp add: mult_commute dist_commute)
himmelma@33175
  6625
        also have "\<dots> \<le> c ^ N * d * (1 - c ^ (m - n)) / (1 - c)"
himmelma@33175
  6626
          using mult_right_mono[OF * order_less_imp_le[OF **]]
huffman@36770
  6627
          unfolding mult_assoc by auto
himmelma@33175
  6628
        also have "\<dots> < (e * (1 - c) / d) * d * (1 - c ^ (m - n)) / (1 - c)"
huffman@36770
  6629
          using mult_strict_right_mono[OF N **] unfolding mult_assoc by auto
himmelma@33175
  6630
        also have "\<dots> = e * (1 - c ^ (m - n))" using c and `d>0` and `1 - c > 0` by auto
himmelma@33175
  6631
        also have "\<dots> \<le> e" using c and `1 - c ^ (m - n) > 0` and `e>0` using mult_right_le_one_le[of e "1 - c ^ (m - n)"] by auto
himmelma@33175
  6632
        finally have  "dist (z m) (z n) < e" by auto
himmelma@33175
  6633
      } note * = this
himmelma@33175
  6634
      { fix m n::nat assume as:"N\<le>m" "N\<le>n"
himmelma@33175
  6635
        hence "dist (z n) (z m) < e"
himmelma@33175
  6636
        proof(cases "n = m")
himmelma@33175
  6637
          case True thus ?thesis using `e>0` by auto
himmelma@33175
  6638
        next
himmelma@33175
  6639
          case False thus ?thesis using as and *[of n m] *[of m n] unfolding nat_neq_iff by (auto simp add: dist_commute)
himmelma@33175
  6640
        qed }
himmelma@33175
  6641
      thus ?thesis by auto
himmelma@33175
  6642
    qed
himmelma@33175
  6643
  }
himmelma@33175
  6644
  hence "Cauchy z" unfolding cauchy_def by auto
himmelma@33175
  6645
  then obtain x where "x\<in>s" and x:"(z ---> x) sequentially" using s(1)[unfolded compact_def complete_def, THEN spec[where x=z]] and z_in_s by auto
himmelma@33175
  6646
himmelma@33175
  6647
  def e \<equiv> "dist (f x) x"
himmelma@33175
  6648
  have "e = 0" proof(rule ccontr)
himmelma@33175
  6649
    assume "e \<noteq> 0" hence "e>0" unfolding e_def using zero_le_dist[of "f x" x]
himmelma@33175
  6650
      by (metis dist_eq_0_iff dist_nz e_def)
himmelma@33175
  6651
    then obtain N where N:"\<forall>n\<ge>N. dist (z n) x < e / 2"
huffman@45778
  6652
      using x[unfolded LIMSEQ_def, THEN spec[where x="e/2"]] by auto
himmelma@33175
  6653
    hence N':"dist (z N) x < e / 2" by auto
himmelma@33175
  6654
himmelma@33175
  6655
    have *:"c * dist (z N) x \<le> dist (z N) x" unfolding mult_le_cancel_right2
himmelma@33175
  6656
      using zero_le_dist[of "z N" x] and c
huffman@36770
  6657
      by (metis dist_eq_0_iff dist_nz order_less_asym less_le)
himmelma@33175
  6658
    have "dist (f (z N)) (f x) \<le> c * dist (z N) x" using lipschitz[THEN bspec[where x="z N"], THEN bspec[where x=x]]
himmelma@33175
  6659
      using z_in_s[of N] `x\<in>s` using c by auto
himmelma@33175
  6660
    also have "\<dots> < e / 2" using N' and c using * by auto
himmelma@33175
  6661
    finally show False unfolding fzn
himmelma@33175
  6662
      using N[THEN spec[where x="Suc N"]] and dist_triangle_half_r[of "z (Suc N)" "f x" e x]
himmelma@33175
  6663
      unfolding e_def by auto
himmelma@33175
  6664
  qed
himmelma@33175
  6665
  hence "f x = x" unfolding e_def by auto
himmelma@33175
  6666
  moreover
himmelma@33175
  6667
  { fix y assume "f y = y" "y\<in>s"
himmelma@33175
  6668
    hence "dist x y \<le> c * dist x y" using lipschitz[THEN bspec[where x=x], THEN bspec[where x=y]]
himmelma@33175
  6669
      using `x\<in>s` and `f x = x` by auto
himmelma@33175
  6670
    hence "dist x y = 0" unfolding mult_le_cancel_right1
himmelma@33175
  6671
      using c and zero_le_dist[of x y] by auto
himmelma@33175
  6672
    hence "y = x" by auto
himmelma@33175
  6673
  }
hoelzl@34986
  6674
  ultimately show ?thesis using `x\<in>s` by blast+
himmelma@33175
  6675
qed
himmelma@33175
  6676
huffman@45081
  6677
subsection {* Edelstein fixed point theorem *}
himmelma@33175
  6678
himmelma@33175
  6679
lemma edelstein_fix:
himmelma@33175
  6680
  fixes s :: "'a::real_normed_vector set"
himmelma@33175
  6681
  assumes s:"compact s" "s \<noteq> {}" and gs:"(g ` s) \<subseteq> s"
himmelma@33175
  6682
      and dist:"\<forall>x\<in>s. \<forall>y\<in>s. x \<noteq> y \<longrightarrow> dist (g x) (g y) < dist x y"
himmelma@33175
  6683
  shows "\<exists>! x\<in>s. g x = x"
himmelma@33175
  6684
proof(cases "\<exists>x\<in>s. g x \<noteq> x")
himmelma@33175
  6685
  obtain x where "x\<in>s" using s(2) by auto
himmelma@33175
  6686
  case False hence g:"\<forall>x\<in>s. g x = x" by auto
himmelma@33175
  6687
  { fix y assume "y\<in>s"
himmelma@33175
  6688
    hence "x = y" using `x\<in>s` and dist[THEN bspec[where x=x], THEN bspec[where x=y]]
himmelma@33175
  6689
      unfolding g[THEN bspec[where x=x], OF `x\<in>s`]
himmelma@33175
  6690
      unfolding g[THEN bspec[where x=y], OF `y\<in>s`] by auto  }
hoelzl@34986
  6691
  thus ?thesis using `x\<in>s` and g by blast+
himmelma@33175
  6692
next
himmelma@33175
  6693
  case True
himmelma@33175
  6694
  then obtain x where [simp]:"x\<in>s" and "g x \<noteq> x" by auto
himmelma@33175
  6695
  { fix x y assume "x \<in> s" "y \<in> s"
himmelma@33175
  6696
    hence "dist (g x) (g y) \<le> dist x y"
himmelma@33175
  6697
      using dist[THEN bspec[where x=x], THEN bspec[where x=y]] by auto } note dist' = this
himmelma@33175
  6698
  def y \<equiv> "g x"
himmelma@33175
  6699
  have [simp]:"y\<in>s" unfolding y_def using gs[unfolded image_subset_iff] and `x\<in>s` by blast
himmelma@33175
  6700
  def f \<equiv> "\<lambda>n. g ^^ n"
himmelma@33175
  6701
  have [simp]:"\<And>n z. g (f n z) = f (Suc n) z" unfolding f_def by auto
himmelma@33175
  6702
  have [simp]:"\<And>z. f 0 z = z" unfolding f_def by auto
himmelma@33175
  6703
  { fix n::nat and z assume "z\<in>s"
himmelma@33175
  6704
    have "f n z \<in> s" unfolding f_def
himmelma@33175
  6705
    proof(induct n)
himmelma@33175
  6706
      case 0 thus ?case using `z\<in>s` by simp
himmelma@33175
  6707
    next
himmelma@33175
  6708
      case (Suc n) thus ?case using gs[unfolded image_subset_iff] by auto
himmelma@33175
  6709
    qed } note fs = this
himmelma@33175
  6710
  { fix m n ::nat assume "m\<le>n"
himmelma@33175
  6711
    fix w z assume "w\<in>s" "z\<in>s"
himmelma@33175
  6712
    have "dist (f n w) (f n z) \<le> dist (f m w) (f m z)" using `m\<le>n`
himmelma@33175
  6713
    proof(induct n)
himmelma@33175
  6714
      case 0 thus ?case by auto
himmelma@33175
  6715
    next
himmelma@33175
  6716
      case (Suc n)
himmelma@33175
  6717
      thus ?case proof(cases "m\<le>n")
himmelma@33175
  6718
        case True thus ?thesis using Suc(1)
himmelma@33175
  6719
          using dist'[OF fs fs, OF `w\<in>s` `z\<in>s`, of n n] by auto
himmelma@33175
  6720
      next
himmelma@33175
  6721
        case False hence mn:"m = Suc n" using Suc(2) by simp
himmelma@33175
  6722
        show ?thesis unfolding mn  by auto
himmelma@33175
  6723
      qed
himmelma@33175
  6724
    qed } note distf = this
himmelma@33175
  6725
himmelma@33175
  6726
  def h \<equiv> "\<lambda>n. (f n x, f n y)"
himmelma@33175
  6727
  let ?s2 = "s \<times> s"
himmelma@33175
  6728
  obtain l r where "l\<in>?s2" and r:"subseq r" and lr:"((h \<circ> r) ---> l) sequentially"
himmelma@33175
  6729
    using compact_Times [OF s(1) s(1), unfolded compact_def, THEN spec[where x=h]] unfolding  h_def
himmelma@33175
  6730
    using fs[OF `x\<in>s`] and fs[OF `y\<in>s`] by blast
himmelma@33175
  6731
  def a \<equiv> "fst l" def b \<equiv> "snd l"
himmelma@33175
  6732
  have lab:"l = (a, b)" unfolding a_def b_def by simp
himmelma@33175
  6733
  have [simp]:"a\<in>s" "b\<in>s" unfolding a_def b_def using `l\<in>?s2` by auto
himmelma@33175
  6734
himmelma@33175
  6735
  have lima:"((fst \<circ> (h \<circ> r)) ---> a) sequentially"
himmelma@33175
  6736
   and limb:"((snd \<circ> (h \<circ> r)) ---> b) sequentially"
himmelma@33175
  6737
    using lr
huffman@45032
  6738
    unfolding o_def a_def b_def by (rule tendsto_intros)+
himmelma@33175
  6739
himmelma@33175
  6740
  { fix n::nat
himmelma@33175
  6741
    have *:"\<And>fx fy (x::'a) y. dist fx fy \<le> dist x y \<Longrightarrow> \<not> (dist (fx - fy) (a - b) < dist a b - dist x y)" unfolding dist_norm by norm
himmelma@33175
  6742
    { fix x y :: 'a
himmelma@33175
  6743
      have "dist (-x) (-y) = dist x y" unfolding dist_norm
himmelma@33175
  6744
        using norm_minus_cancel[of "x - y"] by (auto simp add: uminus_add_conv_diff) } note ** = this
himmelma@33175
  6745
himmelma@33175
  6746
    { assume as:"dist a b > dist (f n x) (f n y)"
himmelma@33175
  6747
      then obtain Na Nb where "\<forall>m\<ge>Na. dist (f (r m) x) a < (dist a b - dist (f n x) (f n y)) / 2"
himmelma@33175
  6748
        and "\<forall>m\<ge>Nb. dist (f (r m) y) b < (dist a b - dist (f n x) (f n y)) / 2"
huffman@47978
  6749
        using lima limb unfolding h_def LIMSEQ_def by (fastforce simp del: less_divide_eq_numeral1)
himmelma@33175
  6750
      hence "dist (f (r (Na + Nb + n)) x - f (r (Na + Nb + n)) y) (a - b) < dist a b - dist (f n x) (f n y)"
himmelma@33175
  6751
        apply(erule_tac x="Na+Nb+n" in allE)
himmelma@33175
  6752
        apply(erule_tac x="Na+Nb+n" in allE) apply simp
himmelma@33175
  6753
        using dist_triangle_add_half[of a "f (r (Na + Nb + n)) x" "dist a b - dist (f n x) (f n y)"
himmelma@33175
  6754
          "-b"  "- f (r (Na + Nb + n)) y"]
haftmann@36349
  6755
        unfolding ** by (auto simp add: algebra_simps dist_commute)
himmelma@33175
  6756
      moreover
himmelma@33175
  6757
      have "dist (f (r (Na + Nb + n)) x - f (r (Na + Nb + n)) y) (a - b) \<ge> dist a b - dist (f n x) (f n y)"
himmelma@33175
  6758
        using distf[of n "r (Na+Nb+n)", OF _ `x\<in>s` `y\<in>s`]
hoelzl@51952
  6759
        using seq_suble[OF r, of "Na+Nb+n"]
himmelma@33175
  6760
        using *[of "f (r (Na + Nb + n)) x" "f (r (Na + Nb + n)) y" "f n x" "f n y"] by auto
himmelma@33175
  6761
      ultimately have False by simp
himmelma@33175
  6762
    }
himmelma@33175
  6763
    hence "dist a b \<le> dist (f n x) (f n y)" by(rule ccontr)auto }
himmelma@33175
  6764
  note ab_fn = this
himmelma@33175
  6765
himmelma@33175
  6766
  have [simp]:"a = b" proof(rule ccontr)
himmelma@33175
  6767
    def e \<equiv> "dist a b - dist (g a) (g b)"
nipkow@45761
  6768
    assume "a\<noteq>b" hence "e > 0" unfolding e_def using dist by fastforce
himmelma@33175
  6769
    hence "\<exists>n. dist (f n x) a < e/2 \<and> dist (f n y) b < e/2"
huffman@45778
  6770
      using lima limb unfolding LIMSEQ_def
huffman@45778
  6771
      apply (auto elim!: allE[where x="e/2"]) apply(rename_tac N N', rule_tac x="r (max N N')" in exI) unfolding h_def by fastforce
himmelma@33175
  6772
    then obtain n where n:"dist (f n x) a < e/2 \<and> dist (f n y) b < e/2" by auto
himmelma@33175
  6773
    have "dist (f (Suc n) x) (g a) \<le> dist (f n x) a"
himmelma@33175
  6774
      using dist[THEN bspec[where x="f n x"], THEN bspec[where x="a"]] and fs by auto
himmelma@33175
  6775
    moreover have "dist (f (Suc n) y) (g b) \<le> dist (f n y) b"
himmelma@33175
  6776
      using dist[THEN bspec[where x="f n y"], THEN bspec[where x="b"]] and fs by auto
himmelma@33175
  6777
    ultimately have "dist (f (Suc n) x) (g a) + dist (f (Suc n) y) (g b) < e" using n by auto
himmelma@33175
  6778
    thus False unfolding e_def using ab_fn[of "Suc n"] by norm
himmelma@33175
  6779
  qed
himmelma@33175
  6780
himmelma@33175
  6781
  have [simp]:"\<And>n. f (Suc n) x = f n y" unfolding f_def y_def by(induct_tac n)auto
himmelma@33175
  6782
  { fix x y assume "x\<in>s" "y\<in>s" moreover
himmelma@33175
  6783
    fix e::real assume "e>0" ultimately
nipkow@45761
  6784
    have "dist y x < e \<longrightarrow> dist (g y) (g x) < e" using dist by fastforce }
huffman@36355
  6785
  hence "continuous_on s g" unfolding continuous_on_iff by auto
himmelma@33175
  6786
himmelma@33175
  6787
  hence "((snd \<circ> h \<circ> r) ---> g a) sequentially" unfolding continuous_on_sequentially
himmelma@33175
  6788
    apply (rule allE[where x="\<lambda>n. (fst \<circ> h \<circ> r) n"]) apply (erule ballE[where x=a])
himmelma@33175
  6789
    using lima unfolding h_def o_def using fs[OF `x\<in>s`] by (auto simp add: y_def)
hoelzl@42841
  6790
  hence "g a = a" using tendsto_unique[OF trivial_limit_sequentially limb, of "g a"]
himmelma@33175
  6791
    unfolding `a=b` and o_assoc by auto
himmelma@33175
  6792
  moreover
himmelma@33175
  6793
  { fix x assume "x\<in>s" "g x = x" "x\<noteq>a"
himmelma@33175
  6794
    hence "False" using dist[THEN bspec[where x=a], THEN bspec[where x=x]]
himmelma@33175
  6795
      using `g a = a` and `a\<in>s` by auto  }
hoelzl@34986
  6796
  ultimately show "\<exists>!x\<in>s. g x = x" using `a\<in>s` by blast
himmelma@33175
  6797
qed
himmelma@33175
  6798
huffman@44989
  6799
declare tendsto_const [intro] (* FIXME: move *)
huffman@44989
  6800
himmelma@33175
  6801
end