src/HOL/Library/Topology_Euclidean_Space.thy
author paulson
Tue Oct 27 12:59:57 2009 +0000 (2009-10-27)
changeset 33269 3b7e2dbbd684
parent 32960 69916a850301
permissions -rw-r--r--
New theory SupInf of the supremum and infimum operators for sets of reals.
wenzelm@32960
     1
(*  Title:      HOL/Library/Topology_Euclidian_Space.thy
wenzelm@32960
     2
    Author:     Amine Chaieb, University of Cambridge
wenzelm@32960
     3
    Author:     Robert Himmelmann, TU Muenchen
wenzelm@30267
     4
*)
chaieb@30262
     5
chaieb@30262
     6
header {* Elementary topology in Euclidean space. *}
chaieb@30262
     7
chaieb@30262
     8
theory Topology_Euclidean_Space
huffman@31560
     9
imports SEQ Euclidean_Space Product_Vector
chaieb@30262
    10
begin
chaieb@30262
    11
chaieb@30262
    12
declare fstcart_pastecart[simp] sndcart_pastecart[simp]
chaieb@30262
    13
chaieb@30262
    14
subsection{* General notion of a topology *}
chaieb@30262
    15
chaieb@30262
    16
definition "istopology L \<longleftrightarrow> {} \<in> L \<and> (\<forall>S \<in>L. \<forall>T \<in>L. S \<inter> T \<in> L) \<and> (\<forall>K. K \<subseteq>L \<longrightarrow> \<Union> K \<in> L)"
huffman@30488
    17
typedef (open) 'a topology = "{L::('a set) set. istopology L}"
chaieb@30262
    18
  morphisms "openin" "topology"
chaieb@30262
    19
  unfolding istopology_def by blast
chaieb@30262
    20
chaieb@30262
    21
lemma istopology_open_in[intro]: "istopology(openin U)"
chaieb@30262
    22
  using openin[of U] by blast
chaieb@30262
    23
chaieb@30262
    24
lemma topology_inverse': "istopology U \<Longrightarrow> openin (topology U) = U"
chaieb@30262
    25
  using topology_inverse[unfolded mem_def Collect_def] .
chaieb@30262
    26
chaieb@30262
    27
lemma topology_inverse_iff: "istopology U \<longleftrightarrow> openin (topology U) = U"
chaieb@30262
    28
  using topology_inverse[of U] istopology_open_in[of "topology U"] by auto
chaieb@30262
    29
chaieb@30262
    30
lemma topology_eq: "T1 = T2 \<longleftrightarrow> (\<forall>S. openin T1 S \<longleftrightarrow> openin T2 S)"
chaieb@30262
    31
proof-
chaieb@30262
    32
  {assume "T1=T2" hence "\<forall>S. openin T1 S \<longleftrightarrow> openin T2 S" by simp}
chaieb@30262
    33
  moreover
chaieb@30262
    34
  {assume H: "\<forall>S. openin T1 S \<longleftrightarrow> openin T2 S"
chaieb@30262
    35
    hence "openin T1 = openin T2" by (metis mem_def set_ext)
chaieb@30262
    36
    hence "topology (openin T1) = topology (openin T2)" by simp
chaieb@30262
    37
    hence "T1 = T2" unfolding openin_inverse .}
chaieb@30262
    38
  ultimately show ?thesis by blast
chaieb@30262
    39
qed
chaieb@30262
    40
chaieb@30262
    41
text{* Infer the "universe" from union of all sets in the topology. *}
chaieb@30262
    42
chaieb@30262
    43
definition "topspace T =  \<Union>{S. openin T S}"
chaieb@30262
    44
chaieb@30262
    45
subsection{* Main properties of open sets *}
chaieb@30262
    46
chaieb@30262
    47
lemma openin_clauses:
chaieb@30262
    48
  fixes U :: "'a topology"
chaieb@30262
    49
  shows "openin U {}"
chaieb@30262
    50
  "\<And>S T. openin U S \<Longrightarrow> openin U T \<Longrightarrow> openin U (S\<inter>T)"
chaieb@30262
    51
  "\<And>K. (\<forall>S \<in> K. openin U S) \<Longrightarrow> openin U (\<Union>K)"
chaieb@30262
    52
  using openin[of U] unfolding istopology_def Collect_def mem_def
chaieb@30262
    53
  by (metis mem_def subset_eq)+
chaieb@30262
    54
chaieb@30262
    55
lemma openin_subset[intro]: "openin U S \<Longrightarrow> S \<subseteq> topspace U"
chaieb@30262
    56
  unfolding topspace_def by blast
chaieb@30262
    57
lemma openin_empty[simp]: "openin U {}" by (simp add: openin_clauses)
chaieb@30262
    58
chaieb@30262
    59
lemma openin_Int[intro]: "openin U S \<Longrightarrow> openin U T \<Longrightarrow> openin U (S \<inter> T)"
chaieb@30262
    60
  by (simp add: openin_clauses)
chaieb@30262
    61
chaieb@30262
    62
lemma openin_Union[intro]: "(\<forall>S \<in>K. openin U S) \<Longrightarrow> openin U (\<Union> K)" by (simp add: openin_clauses)
chaieb@30262
    63
chaieb@30262
    64
lemma openin_Un[intro]: "openin U S \<Longrightarrow> openin U T \<Longrightarrow> openin U (S \<union> T)"
chaieb@30262
    65
  using openin_Union[of "{S,T}" U] by auto
chaieb@30262
    66
chaieb@30262
    67
lemma openin_topspace[intro, simp]: "openin U (topspace U)" by (simp add: openin_Union topspace_def)
chaieb@30262
    68
chaieb@30262
    69
lemma openin_subopen: "openin U S \<longleftrightarrow> (\<forall>x \<in> S. \<exists>T. openin U T \<and> x \<in> T \<and> T \<subseteq> S)" (is "?lhs \<longleftrightarrow> ?rhs")
chaieb@30262
    70
proof-
chaieb@30262
    71
  {assume ?lhs then have ?rhs by auto }
chaieb@30262
    72
  moreover
chaieb@30262
    73
  {assume H: ?rhs
huffman@30488
    74
    then obtain t where t: "\<forall>x\<in>S. openin U (t x) \<and> x \<in> t x \<and> t x \<subseteq> S"
chaieb@30262
    75
      unfolding Ball_def ex_simps(6)[symmetric] choice_iff by blast
chaieb@30262
    76
    from t have th0: "\<forall>x\<in> t`S. openin U x" by auto
huffman@30488
    77
    have "\<Union> t`S = S" using t by auto
chaieb@30262
    78
    with openin_Union[OF th0] have "openin U S" by simp }
chaieb@30262
    79
  ultimately show ?thesis by blast
chaieb@30262
    80
qed
chaieb@30262
    81
chaieb@30262
    82
subsection{* Closed sets *}
chaieb@30262
    83
chaieb@30262
    84
definition "closedin U S \<longleftrightarrow> S \<subseteq> topspace U \<and> openin U (topspace U - S)"
chaieb@30262
    85
chaieb@30262
    86
lemma closedin_subset: "closedin U S \<Longrightarrow> S \<subseteq> topspace U" by (metis closedin_def)
chaieb@30262
    87
lemma closedin_empty[simp]: "closedin U {}" by (simp add: closedin_def)
huffman@30488
    88
lemma closedin_topspace[intro,simp]:
chaieb@30262
    89
  "closedin U (topspace U)" by (simp add: closedin_def)
chaieb@30262
    90
lemma closedin_Un[intro]: "closedin U S \<Longrightarrow> closedin U T \<Longrightarrow> closedin U (S \<union> T)"
chaieb@30262
    91
  by (auto simp add: Diff_Un closedin_def)
chaieb@30262
    92
chaieb@30262
    93
lemma Diff_Inter[intro]: "A - \<Inter>S = \<Union> {A - s|s. s\<in>S}" by auto
chaieb@30262
    94
lemma closedin_Inter[intro]: assumes Ke: "K \<noteq> {}" and Kc: "\<forall>S \<in>K. closedin U S"
chaieb@30262
    95
  shows "closedin U (\<Inter> K)"  using Ke Kc unfolding closedin_def Diff_Inter by auto
chaieb@30262
    96
chaieb@30262
    97
lemma closedin_Int[intro]: "closedin U S \<Longrightarrow> closedin U T \<Longrightarrow> closedin U (S \<inter> T)"
chaieb@30262
    98
  using closedin_Inter[of "{S,T}" U] by auto
chaieb@30262
    99
chaieb@30262
   100
lemma Diff_Diff_Int: "A - (A - B) = A \<inter> B" by blast
chaieb@30262
   101
lemma openin_closedin_eq: "openin U S \<longleftrightarrow> S \<subseteq> topspace U \<and> closedin U (topspace U - S)"
haftmann@32698
   102
  apply (auto simp add: closedin_def Diff_Diff_Int inf_absorb2)
chaieb@30262
   103
  apply (metis openin_subset subset_eq)
haftmann@32685
   104
  done
chaieb@30262
   105
chaieb@30262
   106
lemma openin_closedin:  "S \<subseteq> topspace U \<Longrightarrow> (openin U S \<longleftrightarrow> closedin U (topspace U - S))"
chaieb@30262
   107
  by (simp add: openin_closedin_eq)
chaieb@30262
   108
chaieb@30262
   109
lemma openin_diff[intro]: assumes oS: "openin U S" and cT: "closedin U T" shows "openin U (S - T)"
chaieb@30262
   110
proof-
chaieb@30262
   111
  have "S - T = S \<inter> (topspace U - T)" using openin_subset[of U S]  oS cT
chaieb@30262
   112
    by (auto simp add: topspace_def openin_subset)
chaieb@30262
   113
  then show ?thesis using oS cT by (auto simp add: closedin_def)
huffman@30488
   114
qed
chaieb@30262
   115
chaieb@30262
   116
lemma closedin_diff[intro]: assumes oS: "closedin U S" and cT: "openin U T" shows "closedin U (S - T)"
chaieb@30262
   117
proof-
huffman@30488
   118
  have "S - T = S \<inter> (topspace U - T)" using closedin_subset[of U S]  oS cT
chaieb@30262
   119
    by (auto simp add: topspace_def )
chaieb@30262
   120
  then show ?thesis using oS cT by (auto simp add: openin_closedin_eq)
chaieb@30262
   121
qed
chaieb@30262
   122
chaieb@30262
   123
subsection{* Subspace topology. *}
chaieb@30262
   124
chaieb@30262
   125
definition "subtopology U V = topology {S \<inter> V |S. openin U S}"
chaieb@30262
   126
chaieb@30262
   127
lemma istopology_subtopology: "istopology {S \<inter> V |S. openin U S}" (is "istopology ?L")
chaieb@30262
   128
proof-
chaieb@30262
   129
  have "{} \<in> ?L" by blast
chaieb@30262
   130
  {fix A B assume A: "A \<in> ?L" and B: "B \<in> ?L"
chaieb@30262
   131
    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
chaieb@30262
   132
    have "A\<inter>B = (Sa \<inter> Sb) \<inter> V" "openin U (Sa \<inter> Sb)"  using Sa Sb by blast+
chaieb@30262
   133
    then have "A \<inter> B \<in> ?L" by blast}
chaieb@30262
   134
  moreover
chaieb@30262
   135
  {fix K assume K: "K \<subseteq> ?L"
huffman@30488
   136
    have th0: "?L = (\<lambda>S. S \<inter> V) ` openin U "
huffman@30488
   137
      apply (rule set_ext)
huffman@30488
   138
      apply (simp add: Ball_def image_iff)
chaieb@30262
   139
      by (metis mem_def)
chaieb@30262
   140
    from K[unfolded th0 subset_image_iff]
chaieb@30262
   141
    obtain Sk where Sk: "Sk \<subseteq> openin U" "K = (\<lambda>S. S \<inter> V) ` Sk" by blast
chaieb@30262
   142
    have "\<Union>K = (\<Union>Sk) \<inter> V" using Sk by auto
chaieb@30262
   143
    moreover have "openin U (\<Union> Sk)" using Sk by (auto simp add: subset_eq mem_def)
chaieb@30262
   144
    ultimately have "\<Union>K \<in> ?L" by blast}
huffman@30488
   145
  ultimately show ?thesis unfolding istopology_def by blast
huffman@30488
   146
qed
huffman@30488
   147
huffman@30488
   148
lemma openin_subtopology:
chaieb@30262
   149
  "openin (subtopology U V) S \<longleftrightarrow> (\<exists> T. (openin U T) \<and> (S = T \<inter> V))"
huffman@30488
   150
  unfolding subtopology_def topology_inverse'[OF istopology_subtopology]
huffman@30488
   151
  by (auto simp add: Collect_def)
chaieb@30262
   152
chaieb@30262
   153
lemma topspace_subtopology: "topspace(subtopology U V) = topspace U \<inter> V"
chaieb@30262
   154
  by (auto simp add: topspace_def openin_subtopology)
chaieb@30262
   155
huffman@30488
   156
lemma closedin_subtopology:
chaieb@30262
   157
  "closedin (subtopology U V) S \<longleftrightarrow> (\<exists>T. closedin U T \<and> S = T \<inter> V)"
chaieb@30262
   158
  unfolding closedin_def topspace_subtopology
chaieb@30262
   159
  apply (simp add: openin_subtopology)
chaieb@30262
   160
  apply (rule iffI)
chaieb@30262
   161
  apply clarify
chaieb@30262
   162
  apply (rule_tac x="topspace U - T" in exI)
chaieb@30262
   163
  by auto
chaieb@30262
   164
chaieb@30262
   165
lemma openin_subtopology_refl: "openin (subtopology U V) V \<longleftrightarrow> V \<subseteq> topspace U"
chaieb@30262
   166
  unfolding openin_subtopology
chaieb@30262
   167
  apply (rule iffI, clarify)
chaieb@30262
   168
  apply (frule openin_subset[of U])  apply blast
chaieb@30262
   169
  apply (rule exI[where x="topspace U"])
chaieb@30262
   170
  by auto
chaieb@30262
   171
huffman@30488
   172
lemma subtopology_superset: assumes UV: "topspace U \<subseteq> V"
chaieb@30262
   173
  shows "subtopology U V = U"
chaieb@30262
   174
proof-
chaieb@30262
   175
  {fix S
chaieb@30262
   176
    {fix T assume T: "openin U T" "S = T \<inter> V"
chaieb@30262
   177
      from T openin_subset[OF T(1)] UV have eq: "S = T" by blast
chaieb@30262
   178
      have "openin U S" unfolding eq using T by blast}
chaieb@30262
   179
    moreover
chaieb@30262
   180
    {assume S: "openin U S"
chaieb@30262
   181
      hence "\<exists>T. openin U T \<and> S = T \<inter> V"
wenzelm@32960
   182
        using openin_subset[OF S] UV by auto}
chaieb@30262
   183
    ultimately have "(\<exists>T. openin U T \<and> S = T \<inter> V) \<longleftrightarrow> openin U S" by blast}
chaieb@30262
   184
  then show ?thesis unfolding topology_eq openin_subtopology by blast
chaieb@30262
   185
qed
chaieb@30262
   186
chaieb@30262
   187
chaieb@30262
   188
lemma subtopology_topspace[simp]: "subtopology U (topspace U) = U"
chaieb@30262
   189
  by (simp add: subtopology_superset)
chaieb@30262
   190
chaieb@30262
   191
lemma subtopology_UNIV[simp]: "subtopology U UNIV = U"
chaieb@30262
   192
  by (simp add: subtopology_superset)
chaieb@30262
   193
chaieb@30262
   194
subsection{* The universal Euclidean versions are what we use most of the time *}
huffman@31418
   195
huffman@31285
   196
definition
huffman@31418
   197
  euclidean :: "'a::topological_space topology" where
huffman@31418
   198
  "euclidean = topology open"
huffman@31418
   199
chaieb@30262
   200
lemma open_openin: "open S \<longleftrightarrow> openin euclidean S"
chaieb@30262
   201
  unfolding euclidean_def
chaieb@30262
   202
  apply (rule cong[where x=S and y=S])
chaieb@30262
   203
  apply (rule topology_inverse[symmetric])
chaieb@30262
   204
  apply (auto simp add: istopology_def)
chaieb@30262
   205
  by (auto simp add: mem_def subset_eq)
chaieb@30262
   206
chaieb@30262
   207
lemma topspace_euclidean: "topspace euclidean = UNIV"
chaieb@30262
   208
  apply (simp add: topspace_def)
chaieb@30262
   209
  apply (rule set_ext)
chaieb@30262
   210
  by (auto simp add: open_openin[symmetric])
chaieb@30262
   211
chaieb@30262
   212
lemma topspace_euclidean_subtopology[simp]: "topspace (subtopology euclidean S) = S"
chaieb@30262
   213
  by (simp add: topspace_euclidean topspace_subtopology)
chaieb@30262
   214
chaieb@30262
   215
lemma closed_closedin: "closed S \<longleftrightarrow> closedin euclidean S"
huffman@31490
   216
  by (simp add: closed_def closedin_def topspace_euclidean open_openin Compl_eq_Diff_UNIV)
chaieb@30262
   217
chaieb@30262
   218
lemma open_subopen: "open S \<longleftrightarrow> (\<forall>x\<in>S. \<exists>T. open T \<and> x \<in> T \<and> T \<subseteq> S)"
chaieb@30262
   219
  by (simp add: open_openin openin_subopen[symmetric])
chaieb@30262
   220
chaieb@30262
   221
subsection{* Open and closed balls. *}
chaieb@30262
   222
huffman@31285
   223
definition
huffman@31345
   224
  ball :: "'a::metric_space \<Rightarrow> real \<Rightarrow> 'a set" where
huffman@31285
   225
  "ball x e = {y. dist x y < e}"
huffman@31285
   226
huffman@31285
   227
definition
huffman@31345
   228
  cball :: "'a::metric_space \<Rightarrow> real \<Rightarrow> 'a set" where
huffman@31285
   229
  "cball x e = {y. dist x y \<le> e}"
chaieb@30262
   230
huffman@30488
   231
lemma mem_ball[simp]: "y \<in> ball x e \<longleftrightarrow> dist x y < e" by (simp add: ball_def)
huffman@30488
   232
lemma mem_cball[simp]: "y \<in> cball x e \<longleftrightarrow> dist x y \<le> e" by (simp add: cball_def)
huffman@31345
   233
huffman@31345
   234
lemma mem_ball_0 [simp]:
huffman@31345
   235
  fixes x :: "'a::real_normed_vector"
huffman@31345
   236
  shows "x \<in> ball 0 e \<longleftrightarrow> norm x < e"
huffman@31345
   237
  by (simp add: dist_norm)
huffman@31345
   238
huffman@31345
   239
lemma mem_cball_0 [simp]:
huffman@31345
   240
  fixes x :: "'a::real_normed_vector"
huffman@31345
   241
  shows "x \<in> cball 0 e \<longleftrightarrow> norm x \<le> e"
huffman@31345
   242
  by (simp add: dist_norm)
huffman@31345
   243
chaieb@30262
   244
lemma centre_in_cball[simp]: "x \<in> cball x e \<longleftrightarrow> 0\<le> e"  by simp
chaieb@30262
   245
lemma ball_subset_cball[simp,intro]: "ball x e \<subseteq> cball x e" by (simp add: subset_eq)
chaieb@30262
   246
lemma subset_ball[intro]: "d <= e ==> ball x d \<subseteq> ball x e" by (simp add: subset_eq)
chaieb@30262
   247
lemma subset_cball[intro]: "d <= e ==> cball x d \<subseteq> cball x e" by (simp add: subset_eq)
chaieb@30262
   248
lemma ball_max_Un: "ball a (max r s) = ball a r \<union> ball a s"
chaieb@30262
   249
  by (simp add: expand_set_eq) arith
chaieb@30262
   250
chaieb@30262
   251
lemma ball_min_Int: "ball a (min r s) = ball a r \<inter> ball a s"
huffman@30488
   252
  by (simp add: expand_set_eq)
chaieb@30262
   253
chaieb@30262
   254
subsection{* Topological properties of open balls *}
chaieb@30262
   255
huffman@30488
   256
lemma diff_less_iff: "(a::real) - b > 0 \<longleftrightarrow> a > b"
huffman@30488
   257
  "(a::real) - b < 0 \<longleftrightarrow> a < b"
chaieb@30262
   258
  "a - b < c \<longleftrightarrow> a < c +b" "a - b > c \<longleftrightarrow> a > c +b" by arith+
huffman@30488
   259
lemma diff_le_iff: "(a::real) - b \<ge> 0 \<longleftrightarrow> a \<ge> b" "(a::real) - b \<le> 0 \<longleftrightarrow> a \<le> b"
chaieb@30262
   260
  "a - b \<le> c \<longleftrightarrow> a \<le> c +b" "a - b \<ge> c \<longleftrightarrow> a \<ge> c +b"  by arith+
chaieb@30262
   261
chaieb@30262
   262
lemma open_ball[intro, simp]: "open (ball x e)"
huffman@31418
   263
  unfolding open_dist ball_def Collect_def Ball_def mem_def
huffman@31285
   264
  unfolding dist_commute
chaieb@30262
   265
  apply clarify
chaieb@30262
   266
  apply (rule_tac x="e - dist xa x" in exI)
chaieb@30262
   267
  using dist_triangle_alt[where z=x]
chaieb@30262
   268
  apply (clarsimp simp add: diff_less_iff)
chaieb@30262
   269
  apply atomize
huffman@31492
   270
  apply (erule_tac x="y" in allE)
chaieb@30262
   271
  apply (erule_tac x="xa" in allE)
chaieb@30262
   272
  by arith
chaieb@30262
   273
huffman@31285
   274
lemma centre_in_ball[simp]: "x \<in> ball x e \<longleftrightarrow> e > 0" by (metis mem_ball dist_self)
chaieb@30262
   275
lemma open_contains_ball: "open S \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0. ball x e \<subseteq> S)"
huffman@31418
   276
  unfolding open_dist subset_eq mem_ball Ball_def dist_commute ..
chaieb@30262
   277
chaieb@30262
   278
lemma open_contains_ball_eq: "open S \<Longrightarrow> \<forall>x. x\<in>S \<longleftrightarrow> (\<exists>e>0. ball x e \<subseteq> S)"
chaieb@30262
   279
  by (metis open_contains_ball subset_eq centre_in_ball)
chaieb@30262
   280
chaieb@30262
   281
lemma ball_eq_empty[simp]: "ball x e = {} \<longleftrightarrow> e \<le> 0"
chaieb@30262
   282
  unfolding mem_ball expand_set_eq
chaieb@30262
   283
  apply (simp add: not_less)
huffman@31285
   284
  by (metis zero_le_dist order_trans dist_self)
chaieb@30262
   285
chaieb@30262
   286
lemma ball_empty[intro]: "e \<le> 0 ==> ball x e = {}" by simp
chaieb@30262
   287
chaieb@30262
   288
subsection{* Basic "localization" results are handy for connectedness. *}
chaieb@30262
   289
chaieb@30262
   290
lemma openin_open: "openin (subtopology euclidean U) S \<longleftrightarrow> (\<exists>T. open T \<and> (S = U \<inter> T))"
chaieb@30262
   291
  by (auto simp add: openin_subtopology open_openin[symmetric])
chaieb@30262
   292
chaieb@30262
   293
lemma openin_open_Int[intro]: "open S \<Longrightarrow> openin (subtopology euclidean U) (U \<inter> S)"
huffman@30488
   294
  by (auto simp add: openin_open)
huffman@30488
   295
huffman@30488
   296
lemma open_openin_trans[trans]:
chaieb@30262
   297
 "open S \<Longrightarrow> open T \<Longrightarrow> T \<subseteq> S \<Longrightarrow> openin (subtopology euclidean S) T"
chaieb@30262
   298
  by (metis Int_absorb1  openin_open_Int)
chaieb@30262
   299
chaieb@30262
   300
lemma open_subset:  "S \<subseteq> T \<Longrightarrow> open S \<Longrightarrow> openin (subtopology euclidean T) S"
chaieb@30262
   301
  by (auto simp add: openin_open)
chaieb@30262
   302
chaieb@30262
   303
lemma closedin_closed: "closedin (subtopology euclidean U) S \<longleftrightarrow> (\<exists>T. closed T \<and> S = U \<inter> T)"
chaieb@30262
   304
  by (simp add: closedin_subtopology closed_closedin Int_ac)
chaieb@30262
   305
chaieb@30262
   306
lemma closedin_closed_Int: "closed S ==> closedin (subtopology euclidean U) (U \<inter> S)"
chaieb@30262
   307
  by (metis closedin_closed)
chaieb@30262
   308
chaieb@30262
   309
lemma closed_closedin_trans: "closed S \<Longrightarrow> closed T \<Longrightarrow> T \<subseteq> S \<Longrightarrow> closedin (subtopology euclidean S) T"
chaieb@30262
   310
  apply (subgoal_tac "S \<inter> T = T" )
chaieb@30262
   311
  apply auto
chaieb@30262
   312
  apply (frule closedin_closed_Int[of T S])
chaieb@30262
   313
  by simp
chaieb@30262
   314
chaieb@30262
   315
lemma closed_subset: "S \<subseteq> T \<Longrightarrow> closed S \<Longrightarrow> closedin (subtopology euclidean T) S"
chaieb@30262
   316
  by (auto simp add: closedin_closed)
chaieb@30262
   317
huffman@31418
   318
lemma openin_euclidean_subtopology_iff:
huffman@31418
   319
  fixes S U :: "'a::metric_space set"
huffman@31418
   320
  shows "openin (subtopology euclidean U) S
chaieb@30262
   321
  \<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")
chaieb@30262
   322
proof-
chaieb@30262
   323
  {assume ?lhs hence ?rhs unfolding openin_subtopology open_openin[symmetric]
huffman@31418
   324
      by (simp add: open_dist) blast}
chaieb@30262
   325
  moreover
chaieb@30262
   326
  {assume SU: "S \<subseteq> U" and H: "\<And>x. x \<in> S \<Longrightarrow> \<exists>e>0. \<forall>x'\<in>U. dist x' x < e \<longrightarrow> x' \<in> S"
chaieb@30262
   327
    from H obtain d where d: "\<And>x . x\<in> S \<Longrightarrow> d x > 0 \<and> (\<forall>x' \<in> U. dist x' x < d x \<longrightarrow> x' \<in> S)"
chaieb@30262
   328
      by metis
chaieb@30262
   329
    let ?T = "\<Union>{B. \<exists>x\<in>S. B = ball x (d x)}"
chaieb@30262
   330
    have oT: "open ?T" by auto
chaieb@30262
   331
    { fix x assume "x\<in>S"
chaieb@30262
   332
      hence "x \<in> \<Union>{B. \<exists>x\<in>S. B = ball x (d x)}"
wenzelm@32960
   333
        apply simp apply(rule_tac x="ball x(d x)" in exI) apply auto
huffman@31285
   334
        by (rule d [THEN conjunct1])
chaieb@30262
   335
      hence "x\<in> ?T \<inter> U" using SU and `x\<in>S` by auto  }
chaieb@30262
   336
    moreover
chaieb@30262
   337
    { fix y assume "y\<in>?T"
chaieb@30262
   338
      then obtain B where "y\<in>B" "B\<in>{B. \<exists>x\<in>S. B = ball x (d x)}" by auto
chaieb@30262
   339
      then obtain x where "x\<in>S" and x:"y \<in> ball x (d x)" by auto
chaieb@30262
   340
      assume "y\<in>U"
huffman@31285
   341
      hence "y\<in>S" using d[OF `x\<in>S`] and x by(auto simp add: dist_commute) }
huffman@30488
   342
    ultimately have "S = ?T \<inter> U" by blast
chaieb@30262
   343
    with oT have ?lhs unfolding openin_subtopology open_openin[symmetric] by blast}
chaieb@30262
   344
  ultimately show ?thesis by blast
chaieb@30262
   345
qed
chaieb@30262
   346
chaieb@30262
   347
text{* These "transitivity" results are handy too. *}
chaieb@30262
   348
huffman@30488
   349
lemma openin_trans[trans]: "openin (subtopology euclidean T) S \<Longrightarrow> openin (subtopology euclidean U) T
chaieb@30262
   350
  \<Longrightarrow> openin (subtopology euclidean U) S"
chaieb@30262
   351
  unfolding open_openin openin_open by blast
chaieb@30262
   352
chaieb@30262
   353
lemma openin_open_trans: "openin (subtopology euclidean T) S \<Longrightarrow> open T \<Longrightarrow> open S"
chaieb@30262
   354
  by (auto simp add: openin_open intro: openin_trans)
chaieb@30262
   355
huffman@30488
   356
lemma closedin_trans[trans]:
huffman@30488
   357
 "closedin (subtopology euclidean T) S \<Longrightarrow>
chaieb@30262
   358
           closedin (subtopology euclidean U) T
chaieb@30262
   359
           ==> closedin (subtopology euclidean U) S"
chaieb@30262
   360
  by (auto simp add: closedin_closed closed_closedin closed_Inter Int_assoc)
chaieb@30262
   361
chaieb@30262
   362
lemma closedin_closed_trans: "closedin (subtopology euclidean T) S \<Longrightarrow> closed T \<Longrightarrow> closed S"
chaieb@30262
   363
  by (auto simp add: closedin_closed intro: closedin_trans)
chaieb@30262
   364
chaieb@30262
   365
subsection{* Connectedness *}
chaieb@30262
   366
chaieb@30262
   367
definition "connected S \<longleftrightarrow>
huffman@30488
   368
  ~(\<exists>e1 e2. open e1 \<and> open e2 \<and> S \<subseteq> (e1 \<union> e2) \<and> (e1 \<inter> e2 \<inter> S = {})
chaieb@30262
   369
  \<and> ~(e1 \<inter> S = {}) \<and> ~(e2 \<inter> S = {}))"
chaieb@30262
   370
huffman@30488
   371
lemma connected_local:
chaieb@30262
   372
 "connected S \<longleftrightarrow> ~(\<exists>e1 e2.
chaieb@30262
   373
                 openin (subtopology euclidean S) e1 \<and>
chaieb@30262
   374
                 openin (subtopology euclidean S) e2 \<and>
chaieb@30262
   375
                 S \<subseteq> e1 \<union> e2 \<and>
chaieb@30262
   376
                 e1 \<inter> e2 = {} \<and>
chaieb@30262
   377
                 ~(e1 = {}) \<and>
chaieb@30262
   378
                 ~(e2 = {}))"
huffman@31418
   379
unfolding connected_def openin_open by (safe, blast+)
chaieb@30262
   380
chaieb@30262
   381
lemma exists_diff: "(\<exists>S. P(UNIV - S)) \<longleftrightarrow> (\<exists>S. P S)" (is "?lhs \<longleftrightarrow> ?rhs")
chaieb@30262
   382
proof-
huffman@30488
   383
chaieb@30262
   384
  {assume "?lhs" hence ?rhs by blast }
chaieb@30262
   385
  moreover
chaieb@30262
   386
  {fix S assume H: "P S"
chaieb@30262
   387
    have "S = UNIV - (UNIV - S)" by auto
chaieb@30262
   388
    with H have "P (UNIV - (UNIV - S))" by metis }
chaieb@30262
   389
  ultimately show ?thesis by metis
chaieb@30262
   390
qed
chaieb@30262
   391
chaieb@30262
   392
lemma connected_clopen: "connected S \<longleftrightarrow>
chaieb@30262
   393
        (\<forall>T. openin (subtopology euclidean S) T \<and>
chaieb@30262
   394
            closedin (subtopology euclidean S) T \<longrightarrow> T = {} \<or> T = S)" (is "?lhs \<longleftrightarrow> ?rhs")
chaieb@30262
   395
proof-
huffman@30488
   396
  have " \<not> connected S \<longleftrightarrow> (\<exists>e1 e2. open e1 \<and> open (UNIV - e2) \<and> S \<subseteq> e1 \<union> (UNIV - e2) \<and> e1 \<inter> (UNIV - e2) \<inter> S = {} \<and> e1 \<inter> S \<noteq> {} \<and> (UNIV - e2) \<inter> S \<noteq> {})"
huffman@30488
   397
    unfolding connected_def openin_open closedin_closed
chaieb@30262
   398
    apply (subst exists_diff) by blast
huffman@30488
   399
  hence th0: "connected S \<longleftrightarrow> \<not> (\<exists>e2 e1. closed e2 \<and> open e1 \<and> S \<subseteq> e1 \<union> (UNIV - e2) \<and> e1 \<inter> (UNIV - e2) \<inter> S = {} \<and> e1 \<inter> S \<noteq> {} \<and> (UNIV - e2) \<inter> S \<noteq> {})"
huffman@31490
   400
    (is " _ \<longleftrightarrow> \<not> (\<exists>e2 e1. ?P e2 e1)") apply (simp add: closed_def Compl_eq_Diff_UNIV) by metis
chaieb@30262
   401
chaieb@30262
   402
  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'))"
chaieb@30262
   403
    (is "_ \<longleftrightarrow> \<not> (\<exists>t' t. ?Q t' t)")
chaieb@30262
   404
    unfolding connected_def openin_open closedin_closed by auto
chaieb@30262
   405
  {fix e2
chaieb@30262
   406
    {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)"
wenzelm@32960
   407
        by auto}
chaieb@30262
   408
    then have "(\<exists>e1. ?P e2 e1) \<longleftrightarrow> (\<exists>t. ?Q e2 t)" by metis}
chaieb@30262
   409
  then have "\<forall>e2. (\<exists>e1. ?P e2 e1) \<longleftrightarrow> (\<exists>t. ?Q e2 t)" by blast
chaieb@30262
   410
  then show ?thesis unfolding th0 th1 by simp
chaieb@30262
   411
qed
chaieb@30262
   412
chaieb@30262
   413
lemma connected_empty[simp, intro]: "connected {}"
chaieb@30262
   414
  by (simp add: connected_def)
chaieb@30262
   415
chaieb@30262
   416
subsection{* Hausdorff and other separation properties *}
chaieb@30262
   417
haftmann@31457
   418
class t0_space =
haftmann@31457
   419
  assumes t0_space: "x \<noteq> y \<Longrightarrow> \<exists>U. open U \<and> \<not> (x \<in> U \<longleftrightarrow> y \<in> U)"
haftmann@31457
   420
haftmann@31457
   421
class t1_space =
haftmann@31457
   422
  assumes t1_space: "x \<noteq> y \<Longrightarrow> \<exists>U V. open U \<and> open V \<and> x \<in> U \<and> y \<notin> U \<and> x \<notin> V \<and> y \<in> V"
haftmann@31457
   423
begin
haftmann@31457
   424
haftmann@31457
   425
subclass t0_space
haftmann@31457
   426
proof
haftmann@31457
   427
qed (fast dest: t1_space)
haftmann@31457
   428
haftmann@31457
   429
end
huffman@31421
   430
huffman@31421
   431
text {* T2 spaces are also known as Hausdorff spaces. *}
huffman@31421
   432
haftmann@31457
   433
class t2_space =
haftmann@31457
   434
  assumes hausdorff: "x \<noteq> y \<Longrightarrow> \<exists>U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {}"
haftmann@31457
   435
begin
haftmann@31457
   436
haftmann@31457
   437
subclass t1_space
haftmann@31457
   438
proof
haftmann@31457
   439
qed (fast dest: hausdorff)
haftmann@31457
   440
haftmann@31457
   441
end
huffman@31421
   442
huffman@31421
   443
instance metric_space \<subseteq> t2_space
huffman@31421
   444
proof
huffman@31421
   445
  fix x y :: "'a::metric_space"
huffman@31421
   446
  assume xy: "x \<noteq> y"
chaieb@30262
   447
  let ?U = "ball x (dist x y / 2)"
chaieb@30262
   448
  let ?V = "ball y (dist x y / 2)"
chaieb@30262
   449
  have th0: "\<And>d x y z. (d x z :: real) <= d x y + d y z \<Longrightarrow> d y z = d z y
chaieb@30262
   450
               ==> ~(d x y * 2 < d x z \<and> d z y * 2 < d x z)" by arith
huffman@31421
   451
  have "open ?U \<and> open ?V \<and> x \<in> ?U \<and> y \<in> ?V \<and> ?U \<inter> ?V = {}"
huffman@31421
   452
    using dist_pos_lt[OF xy] th0[of dist,OF dist_triangle dist_commute]
huffman@31421
   453
    by (auto simp add: expand_set_eq)
huffman@31421
   454
  then show "\<exists>U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {}"
huffman@31421
   455
    by blast
chaieb@30262
   456
qed
chaieb@30262
   457
huffman@31418
   458
lemma separation_t2:
huffman@31421
   459
  fixes x y :: "'a::t2_space"
huffman@31418
   460
  shows "x \<noteq> y \<longleftrightarrow> (\<exists>U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {})"
huffman@30488
   461
  using hausdorff[of x y] by blast
chaieb@30262
   462
huffman@31418
   463
lemma separation_t1:
huffman@31421
   464
  fixes x y :: "'a::t1_space"
huffman@31418
   465
  shows "x \<noteq> y \<longleftrightarrow> (\<exists>U V. open U \<and> open V \<and> x \<in>U \<and> y\<notin> U \<and> x\<notin>V \<and> y\<in>V)"
huffman@31421
   466
  using t1_space[of x y] by blast
chaieb@30262
   467
huffman@31418
   468
lemma separation_t0:
huffman@31421
   469
  fixes x y :: "'a::t0_space"
huffman@31421
   470
  shows "x \<noteq> y \<longleftrightarrow> (\<exists>U. open U \<and> ~(x\<in>U \<longleftrightarrow> y\<in>U))"
huffman@31421
   471
  using t0_space[of x y] by blast
chaieb@30262
   472
chaieb@30262
   473
subsection{* Limit points *}
chaieb@30262
   474
huffman@31345
   475
definition
huffman@31420
   476
  islimpt:: "'a::topological_space \<Rightarrow> 'a set \<Rightarrow> bool"
huffman@31420
   477
    (infixr "islimpt" 60) where
huffman@31345
   478
  "x islimpt S \<longleftrightarrow> (\<forall>T. x\<in>T \<longrightarrow> open T \<longrightarrow> (\<exists>y\<in>S. y\<in>T \<and> y\<noteq>x))"
chaieb@30262
   479
huffman@31489
   480
lemma islimptI:
huffman@31489
   481
  assumes "\<And>T. x \<in> T \<Longrightarrow> open T \<Longrightarrow> \<exists>y\<in>S. y \<in> T \<and> y \<noteq> x"
huffman@31489
   482
  shows "x islimpt S"
huffman@31489
   483
  using assms unfolding islimpt_def by auto
huffman@31489
   484
huffman@31489
   485
lemma islimptE:
huffman@31489
   486
  assumes "x islimpt S" and "x \<in> T" and "open T"
huffman@31489
   487
  obtains y where "y \<in> S" and "y \<in> T" and "y \<noteq> x"
chaieb@30262
   488
  using assms unfolding islimpt_def by auto
chaieb@30262
   489
chaieb@30262
   490
lemma islimpt_subset: "x islimpt S \<Longrightarrow> S \<subseteq> T ==> x islimpt T" by (auto simp add: islimpt_def)
huffman@31420
   491
huffman@31420
   492
lemma islimpt_approachable:
huffman@31420
   493
  fixes x :: "'a::metric_space"
huffman@31420
   494
  shows "x islimpt S \<longleftrightarrow> (\<forall>e>0. \<exists>x'\<in>S. x' \<noteq> x \<and> dist x' x < e)"
chaieb@30262
   495
  unfolding islimpt_def
chaieb@30262
   496
  apply auto
chaieb@30262
   497
  apply(erule_tac x="ball x e" in allE)
huffman@31285
   498
  apply auto
huffman@31285
   499
  apply(rule_tac x=y in bexI)
huffman@31285
   500
  apply (auto simp add: dist_commute)
huffman@31418
   501
  apply (simp add: open_dist, drule (1) bspec)
huffman@31285
   502
  apply (clarify, drule spec, drule (1) mp, auto)
huffman@31285
   503
  done
chaieb@30262
   504
huffman@31420
   505
lemma islimpt_approachable_le:
huffman@31420
   506
  fixes x :: "'a::metric_space"
huffman@31420
   507
  shows "x islimpt S \<longleftrightarrow> (\<forall>e>0. \<exists>x'\<in> S. x' \<noteq> x \<and> dist x' x <= e)"
chaieb@30262
   508
  unfolding islimpt_approachable
chaieb@30262
   509
  using approachable_lt_le[where f="\<lambda>x'. dist x' x" and P="\<lambda>x'. \<not> (x'\<in>S \<and> x'\<noteq>x)"]
huffman@31285
   510
  by metis (* FIXME: VERY slow! *)
chaieb@30262
   511
haftmann@31457
   512
class perfect_space =
huffman@31420
   513
  (* FIXME: perfect_space should inherit from topological_space *)
haftmann@31457
   514
  assumes islimpt_UNIV [simp, intro]: "(x::'a::metric_space) islimpt UNIV"
huffman@31345
   515
huffman@31345
   516
lemma perfect_choose_dist:
huffman@31345
   517
  fixes x :: "'a::perfect_space"
huffman@31345
   518
  shows "0 < r \<Longrightarrow> \<exists>a. a \<noteq> x \<and> dist a x < r"
huffman@31345
   519
using islimpt_UNIV [of x]
huffman@31345
   520
by (simp add: islimpt_approachable)
huffman@31345
   521
huffman@31345
   522
instance real :: perfect_space
huffman@31345
   523
apply default
huffman@31345
   524
apply (rule islimpt_approachable [THEN iffD2])
huffman@31345
   525
apply (clarify, rule_tac x="x + e/2" in bexI)
huffman@31345
   526
apply (auto simp add: dist_norm)
huffman@31345
   527
done
huffman@31420
   528
huffman@31345
   529
instance "^" :: (perfect_space, finite) perfect_space
huffman@31345
   530
proof
huffman@31345
   531
  fix x :: "'a ^ 'b"
chaieb@30262
   532
  {
huffman@31345
   533
    fix e :: real assume "0 < e"
haftmann@31804
   534
    def a \<equiv> "x $ undefined"
huffman@31345
   535
    have "a islimpt UNIV" by (rule islimpt_UNIV)
huffman@31345
   536
    with `0 < e` obtain b where "b \<noteq> a" and "dist b a < e"
huffman@31345
   537
      unfolding islimpt_approachable by auto
haftmann@31804
   538
    def y \<equiv> "Cart_lambda ((Cart_nth x)(undefined := b))"
huffman@31345
   539
    from `b \<noteq> a` have "y \<noteq> x"
huffman@31345
   540
      unfolding a_def y_def by (simp add: Cart_eq)
huffman@31345
   541
    from `dist b a < e` have "dist y x < e"
huffman@31345
   542
      unfolding dist_vector_def a_def y_def
huffman@31345
   543
      apply simp
huffman@31345
   544
      apply (rule le_less_trans [OF setL2_le_setsum [OF zero_le_dist]])
haftmann@31804
   545
      apply (subst setsum_diff1' [where a=undefined], simp, simp, simp)
huffman@31345
   546
      done
huffman@31345
   547
    from `y \<noteq> x` and `dist y x < e`
huffman@31345
   548
    have "\<exists>y\<in>UNIV. y \<noteq> x \<and> dist y x < e" by auto
huffman@31345
   549
  }
huffman@31345
   550
  then show "x islimpt UNIV" unfolding islimpt_approachable by blast
chaieb@30262
   551
qed
chaieb@30262
   552
chaieb@30262
   553
lemma closed_limpt: "closed S \<longleftrightarrow> (\<forall>x. x islimpt S \<longrightarrow> x \<in> S)"
chaieb@30262
   554
  unfolding closed_def
chaieb@30262
   555
  apply (subst open_subopen)
huffman@31490
   556
  apply (simp add: islimpt_def subset_eq Compl_eq_Diff_UNIV)
chaieb@30262
   557
  by (metis DiffE DiffI UNIV_I insertCI insert_absorb mem_def)
chaieb@30262
   558
chaieb@30262
   559
lemma islimpt_EMPTY[simp]: "\<not> x islimpt {}"
huffman@31420
   560
  unfolding islimpt_def by auto
chaieb@30262
   561
huffman@30582
   562
lemma closed_positive_orthant: "closed {x::real^'n::finite. \<forall>i. 0 \<le>x$i}"
chaieb@30262
   563
proof-
huffman@30582
   564
  let ?U = "UNIV :: 'n set"
huffman@30582
   565
  let ?O = "{x::real^'n. \<forall>i. x$i\<ge>0}"
huffman@30582
   566
  {fix x:: "real^'n" and i::'n assume H: "\<forall>e>0. \<exists>x'\<in>?O. x' \<noteq> x \<and> dist x' x < e"
chaieb@30262
   567
    and xi: "x$i < 0"
chaieb@30262
   568
    from xi have th0: "-x$i > 0" by arith
chaieb@30262
   569
    from H[rule_format, OF th0] obtain x' where x': "x' \<in>?O" "x' \<noteq> x" "dist x' x < -x $ i" by blast
chaieb@30262
   570
      have th:" \<And>b a (x::real). abs x <= b \<Longrightarrow> b <= a ==> ~(a + x < 0)" by arith
chaieb@30262
   571
      have th': "\<And>x (y::real). x < 0 \<Longrightarrow> 0 <= y ==> abs x <= abs (y - x)" by arith
huffman@30582
   572
      have th1: "\<bar>x$i\<bar> \<le> \<bar>(x' - x)$i\<bar>" using x'(1) xi
wenzelm@32960
   573
        apply (simp only: vector_component)
wenzelm@32960
   574
        by (rule th') auto
huffman@30582
   575
      have th2: "\<bar>dist x x'\<bar> \<ge> \<bar>(x' - x)$i\<bar>" using  component_le_norm[of "x'-x" i]
wenzelm@32960
   576
        apply (simp add: dist_norm) by norm
huffman@31285
   577
      from th[OF th1 th2] x'(3) have False by (simp add: dist_commute) }
huffman@30488
   578
  then show ?thesis unfolding closed_limpt islimpt_approachable
chaieb@30262
   579
    unfolding not_le[symmetric] by blast
chaieb@30262
   580
qed
chaieb@30262
   581
huffman@31289
   582
lemma finite_set_avoid:
huffman@31345
   583
  fixes a :: "'a::metric_space"
huffman@31289
   584
  assumes fS: "finite S" shows  "\<exists>d>0. \<forall>x\<in>S. x \<noteq> a \<longrightarrow> d <= dist a x"
chaieb@30262
   585
proof(induct rule: finite_induct[OF fS])
chaieb@30262
   586
  case 1 thus ?case apply auto by ferrack
chaieb@30262
   587
next
huffman@30488
   588
  case (2 x F)
chaieb@30262
   589
  from 2 obtain d where d: "d >0" "\<forall>x\<in>F. x\<noteq>a \<longrightarrow> d \<le> dist a x" by blast
chaieb@30262
   590
  {assume "x = a" hence ?case using d by auto  }
chaieb@30262
   591
  moreover
chaieb@30262
   592
  {assume xa: "x\<noteq>a"
chaieb@30262
   593
    let ?d = "min d (dist a x)"
chaieb@30262
   594
    have dp: "?d > 0" using xa d(1) using dist_nz by auto
chaieb@30262
   595
    from d have d': "\<forall>x\<in>F. x\<noteq>a \<longrightarrow> ?d \<le> dist a x" by auto
chaieb@30262
   596
    with dp xa have ?case by(auto intro!: exI[where x="?d"]) }
chaieb@30262
   597
  ultimately show ?case by blast
chaieb@30262
   598
qed
chaieb@30262
   599
huffman@31420
   600
lemma islimpt_finite:
huffman@31420
   601
  fixes S :: "'a::metric_space set"
huffman@31420
   602
  assumes fS: "finite S" shows "\<not> a islimpt S"
huffman@30488
   603
  unfolding islimpt_approachable
huffman@31285
   604
  using finite_set_avoid[OF fS, of a] by (metis dist_commute  not_le)
chaieb@30262
   605
chaieb@30262
   606
lemma islimpt_Un: "x islimpt (S \<union> T) \<longleftrightarrow> x islimpt S \<or> x islimpt T"
chaieb@30262
   607
  apply (rule iffI)
chaieb@30262
   608
  defer
chaieb@30262
   609
  apply (metis Un_upper1 Un_upper2 islimpt_subset)
huffman@31420
   610
  unfolding islimpt_def
huffman@31420
   611
  apply (rule ccontr, clarsimp, rename_tac A B)
huffman@31420
   612
  apply (drule_tac x="A \<inter> B" in spec)
huffman@31490
   613
  apply (auto simp add: open_Int)
chaieb@30262
   614
  done
chaieb@30262
   615
huffman@30488
   616
lemma discrete_imp_closed:
huffman@31418
   617
  fixes S :: "'a::metric_space set"
huffman@31345
   618
  assumes e: "0 < e" and d: "\<forall>x \<in> S. \<forall>y \<in> S. dist y x < e \<longrightarrow> y = x"
chaieb@30262
   619
  shows "closed S"
huffman@30488
   620
proof-
chaieb@30262
   621
  {fix x assume C: "\<forall>e>0. \<exists>x'\<in>S. x' \<noteq> x \<and> dist x' x < e"
chaieb@30262
   622
    from e have e2: "e/2 > 0" by arith
chaieb@30262
   623
    from C[rule_format, OF e2] obtain y where y: "y \<in> S" "y\<noteq>x" "dist y x < e/2" by blast
chaieb@30262
   624
    let ?m = "min (e/2) (dist x y) "
chaieb@30262
   625
    from e2 y(2) have mp: "?m > 0" by (simp add: dist_nz[THEN sym])
chaieb@30262
   626
    from C[rule_format, OF mp] obtain z where z: "z \<in> S" "z\<noteq>x" "dist z x < ?m" by blast
huffman@31345
   627
    have th: "dist z y < e" using z y
huffman@31285
   628
      by (intro dist_triangle_lt [where z=x], simp)
huffman@30488
   629
    from d[rule_format, OF y(1) z(1) th] y z
huffman@31285
   630
    have False by (auto simp add: dist_commute)}
huffman@31420
   631
  then show ?thesis by (metis islimpt_approachable closed_limpt [where 'a='a])
chaieb@30262
   632
qed
chaieb@30262
   633
chaieb@30262
   634
subsection{* Interior of a Set *}
chaieb@30262
   635
definition "interior S = {x. \<exists>T. open T \<and> x \<in> T \<and> T \<subseteq> S}"
chaieb@30262
   636
chaieb@30262
   637
lemma interior_eq: "interior S = S \<longleftrightarrow> open S"
chaieb@30262
   638
  apply (simp add: expand_set_eq interior_def)
huffman@31418
   639
  apply (subst (2) open_subopen) by (safe, blast+)
chaieb@30262
   640
chaieb@30262
   641
lemma interior_open: "open S ==> (interior S = S)" by (metis interior_eq)
chaieb@30262
   642
chaieb@30262
   643
lemma interior_empty[simp]: "interior {} = {}" by (simp add: interior_def)
chaieb@30262
   644
chaieb@30262
   645
lemma open_interior[simp, intro]: "open(interior S)"
chaieb@30262
   646
  apply (simp add: interior_def)
chaieb@30262
   647
  apply (subst open_subopen) by blast
chaieb@30262
   648
chaieb@30262
   649
lemma interior_interior[simp]: "interior(interior S) = interior S" by (metis interior_eq open_interior)
huffman@30488
   650
lemma interior_subset: "interior S \<subseteq> S" by (auto simp add: interior_def)
chaieb@30262
   651
lemma subset_interior: "S \<subseteq> T ==> (interior S) \<subseteq> (interior T)" by (auto simp add: interior_def)
chaieb@30262
   652
lemma interior_maximal: "T \<subseteq> S \<Longrightarrow> open T ==> T \<subseteq> (interior S)" by (auto simp add: interior_def)
chaieb@30262
   653
lemma interior_unique: "T \<subseteq> S \<Longrightarrow> open T  \<Longrightarrow> (\<forall>T'. T' \<subseteq> S \<and> open T' \<longrightarrow> T' \<subseteq> T) \<Longrightarrow> interior S = T"
chaieb@30262
   654
  by (metis equalityI interior_maximal interior_subset open_interior)
chaieb@30262
   655
lemma mem_interior: "x \<in> interior S \<longleftrightarrow> (\<exists>e. 0 < e \<and> ball x e \<subseteq> S)"
chaieb@30262
   656
  apply (simp add: interior_def)
chaieb@30262
   657
  by (metis open_contains_ball centre_in_ball open_ball subset_trans)
chaieb@30262
   658
chaieb@30262
   659
lemma open_subset_interior: "open S ==> S \<subseteq> interior T \<longleftrightarrow> S \<subseteq> T"
chaieb@30262
   660
  by (metis interior_maximal interior_subset subset_trans)
chaieb@30262
   661
chaieb@30262
   662
lemma interior_inter[simp]: "interior(S \<inter> T) = interior S \<inter> interior T"
chaieb@30262
   663
  apply (rule equalityI, simp)
chaieb@30262
   664
  apply (metis Int_lower1 Int_lower2 subset_interior)
huffman@31490
   665
  by (metis Int_mono interior_subset open_Int open_interior open_subset_interior)
chaieb@30262
   666
huffman@31345
   667
lemma interior_limit_point [intro]:
huffman@31345
   668
  fixes x :: "'a::perfect_space"
huffman@31345
   669
  assumes x: "x \<in> interior S" shows "x islimpt S"
chaieb@30262
   670
proof-
chaieb@30262
   671
  from x obtain e where e: "e>0" "\<forall>x'. dist x x' < e \<longrightarrow> x' \<in> S"
chaieb@30262
   672
    unfolding mem_interior subset_eq Ball_def mem_ball by blast
huffman@31345
   673
  {
huffman@31345
   674
    fix d::real assume d: "d>0"
huffman@31345
   675
    let ?m = "min d e"
huffman@31345
   676
    have mde2: "0 < ?m" using e(1) d(1) by simp
huffman@31345
   677
    from perfect_choose_dist [OF mde2, of x]
huffman@31345
   678
    obtain y where "y \<noteq> x" and "dist y x < ?m" by blast
huffman@31345
   679
    then have "dist y x < e" "dist y x < d" by simp_all
huffman@31345
   680
    from `dist y x < e` e(2) have "y \<in> S" by (simp add: dist_commute)
huffman@30488
   681
    have "\<exists>x'\<in>S. x'\<noteq> x \<and> dist x' x < d"
huffman@31345
   682
      using `y \<in> S` `y \<noteq> x` `dist y x < d` by fast
huffman@31345
   683
  }
chaieb@30262
   684
  then show ?thesis unfolding islimpt_approachable by blast
chaieb@30262
   685
qed
chaieb@30262
   686
huffman@30488
   687
lemma interior_closed_Un_empty_interior:
chaieb@30262
   688
  assumes cS: "closed S" and iT: "interior T = {}"
chaieb@30262
   689
  shows "interior(S \<union> T) = interior S"
huffman@31394
   690
proof
huffman@31394
   691
  show "interior S \<subseteq> interior (S\<union>T)"
chaieb@30262
   692
    by (rule subset_interior, blast)
huffman@31394
   693
next
huffman@31394
   694
  show "interior (S \<union> T) \<subseteq> interior S"
huffman@31394
   695
  proof
huffman@31394
   696
    fix x assume "x \<in> interior (S \<union> T)"
huffman@31394
   697
    then obtain R where "open R" "x \<in> R" "R \<subseteq> S \<union> T"
huffman@31394
   698
      unfolding interior_def by fast
huffman@31394
   699
    show "x \<in> interior S"
huffman@31394
   700
    proof (rule ccontr)
huffman@31394
   701
      assume "x \<notin> interior S"
huffman@31394
   702
      with `x \<in> R` `open R` obtain y where "y \<in> R - S"
huffman@31394
   703
        unfolding interior_def expand_set_eq by fast
huffman@31490
   704
      from `open R` `closed S` have "open (R - S)" by (rule open_Diff)
huffman@31394
   705
      from `R \<subseteq> S \<union> T` have "R - S \<subseteq> T" by fast
huffman@31394
   706
      from `y \<in> R - S` `open (R - S)` `R - S \<subseteq> T` `interior T = {}`
huffman@31394
   707
      show "False" unfolding interior_def by fast
huffman@31394
   708
    qed
huffman@31394
   709
  qed
chaieb@30262
   710
qed
chaieb@30262
   711
chaieb@30262
   712
chaieb@30262
   713
subsection{* Closure of a Set *}
chaieb@30262
   714
chaieb@30262
   715
definition "closure S = S \<union> {x | x. x islimpt S}"
chaieb@30262
   716
chaieb@30262
   717
lemma closure_interior: "closure S = UNIV - interior (UNIV - S)"
chaieb@30262
   718
proof-
chaieb@30262
   719
  { fix x
chaieb@30262
   720
    have "x\<in>UNIV - interior (UNIV - S) \<longleftrightarrow> x \<in> closure S"  (is "?lhs = ?rhs")
chaieb@30262
   721
    proof
chaieb@30262
   722
      let ?exT = "\<lambda> y. (\<exists>T. open T \<and> y \<in> T \<and> T \<subseteq> UNIV - S)"
chaieb@30262
   723
      assume "?lhs"
chaieb@30262
   724
      hence *:"\<not> ?exT x"
wenzelm@32960
   725
        unfolding interior_def
wenzelm@32960
   726
        by simp
chaieb@30262
   727
      { assume "\<not> ?rhs"
wenzelm@32960
   728
        hence False using *
wenzelm@32960
   729
          unfolding closure_def islimpt_def
wenzelm@32960
   730
          by blast
chaieb@30262
   731
      }
chaieb@30262
   732
      thus "?rhs"
wenzelm@32960
   733
        by blast
chaieb@30262
   734
    next
chaieb@30262
   735
      assume "?rhs" thus "?lhs"
wenzelm@32960
   736
        unfolding closure_def interior_def islimpt_def
wenzelm@32960
   737
        by blast
chaieb@30262
   738
    qed
chaieb@30262
   739
  }
chaieb@30262
   740
  thus ?thesis
chaieb@30262
   741
    by blast
chaieb@30262
   742
qed
chaieb@30262
   743
chaieb@30262
   744
lemma interior_closure: "interior S = UNIV - (closure (UNIV - S))"
chaieb@30262
   745
proof-
chaieb@30262
   746
  { fix x
chaieb@30262
   747
    have "x \<in> interior S \<longleftrightarrow> x \<in> UNIV - (closure (UNIV - S))"
chaieb@30262
   748
      unfolding interior_def closure_def islimpt_def
huffman@31585
   749
      by blast (* FIXME: VERY slow! *)
chaieb@30262
   750
  }
chaieb@30262
   751
  thus ?thesis
chaieb@30262
   752
    by blast
chaieb@30262
   753
qed
chaieb@30262
   754
chaieb@30262
   755
lemma closed_closure[simp, intro]: "closed (closure S)"
chaieb@30262
   756
proof-
chaieb@30262
   757
  have "closed (UNIV - interior (UNIV -S))" by blast
chaieb@30262
   758
  thus ?thesis using closure_interior[of S] by simp
chaieb@30262
   759
qed
chaieb@30262
   760
chaieb@30262
   761
lemma closure_hull: "closure S = closed hull S"
chaieb@30262
   762
proof-
chaieb@30262
   763
  have "S \<subseteq> closure S"
chaieb@30262
   764
    unfolding closure_def
chaieb@30262
   765
    by blast
chaieb@30262
   766
  moreover
chaieb@30262
   767
  have "closed (closure S)"
chaieb@30262
   768
    using closed_closure[of S]
chaieb@30262
   769
    by assumption
chaieb@30262
   770
  moreover
chaieb@30262
   771
  { fix t
chaieb@30262
   772
    assume *:"S \<subseteq> t" "closed t"
chaieb@30262
   773
    { fix x
chaieb@30262
   774
      assume "x islimpt S"
chaieb@30262
   775
      hence "x islimpt t" using *(1)
wenzelm@32960
   776
        using islimpt_subset[of x, of S, of t]
wenzelm@32960
   777
        by blast
chaieb@30262
   778
    }
chaieb@30262
   779
    with * have "closure S \<subseteq> t"
chaieb@30262
   780
      unfolding closure_def
chaieb@30262
   781
      using closed_limpt[of t]
huffman@31345
   782
      by auto
chaieb@30262
   783
  }
chaieb@30262
   784
  ultimately show ?thesis
chaieb@30262
   785
    using hull_unique[of S, of "closure S", of closed]
chaieb@30262
   786
    unfolding mem_def
chaieb@30262
   787
    by simp
chaieb@30262
   788
qed
chaieb@30262
   789
chaieb@30262
   790
lemma closure_eq: "closure S = S \<longleftrightarrow> closed S"
chaieb@30262
   791
  unfolding closure_hull
chaieb@30262
   792
  using hull_eq[of closed, unfolded mem_def, OF  closed_Inter, of S]
chaieb@30262
   793
  by (metis mem_def subset_eq)
chaieb@30262
   794
chaieb@30262
   795
lemma closure_closed[simp]: "closed S \<Longrightarrow> closure S = S"
chaieb@30262
   796
  using closure_eq[of S]
chaieb@30262
   797
  by simp
chaieb@30262
   798
chaieb@30262
   799
lemma closure_closure[simp]: "closure (closure S) = closure S"
chaieb@30262
   800
  unfolding closure_hull
chaieb@30262
   801
  using hull_hull[of closed S]
chaieb@30262
   802
  by assumption
chaieb@30262
   803
chaieb@30262
   804
lemma closure_subset: "S \<subseteq> closure S"
chaieb@30262
   805
  unfolding closure_hull
chaieb@30262
   806
  using hull_subset[of S closed]
chaieb@30262
   807
  by assumption
chaieb@30262
   808
chaieb@30262
   809
lemma subset_closure: "S \<subseteq> T \<Longrightarrow> closure S \<subseteq> closure T"
chaieb@30262
   810
  unfolding closure_hull
chaieb@30262
   811
  using hull_mono[of S T closed]
chaieb@30262
   812
  by assumption
chaieb@30262
   813
chaieb@30262
   814
lemma closure_minimal: "S \<subseteq> T \<Longrightarrow>  closed T \<Longrightarrow> closure S \<subseteq> T"
chaieb@30262
   815
  using hull_minimal[of S T closed]
chaieb@30262
   816
  unfolding closure_hull mem_def
chaieb@30262
   817
  by simp
chaieb@30262
   818
chaieb@30262
   819
lemma closure_unique: "S \<subseteq> T \<and> closed T \<and> (\<forall> T'. S \<subseteq> T' \<and> closed T' \<longrightarrow> T \<subseteq> T') \<Longrightarrow> closure S = T"
chaieb@30262
   820
  using hull_unique[of S T closed]
chaieb@30262
   821
  unfolding closure_hull mem_def
chaieb@30262
   822
  by simp
chaieb@30262
   823
chaieb@30262
   824
lemma closure_empty[simp]: "closure {} = {}"
chaieb@30262
   825
  using closed_empty closure_closed[of "{}"]
chaieb@30262
   826
  by simp
chaieb@30262
   827
chaieb@30262
   828
lemma closure_univ[simp]: "closure UNIV = UNIV"
chaieb@30262
   829
  using closure_closed[of UNIV]
chaieb@30262
   830
  by simp
chaieb@30262
   831
chaieb@30262
   832
lemma closure_eq_empty: "closure S = {} \<longleftrightarrow> S = {}"
chaieb@30262
   833
  using closure_empty closure_subset[of S]
chaieb@30262
   834
  by blast
chaieb@30262
   835
chaieb@30262
   836
lemma closure_subset_eq: "closure S \<subseteq> S \<longleftrightarrow> closed S"
chaieb@30262
   837
  using closure_eq[of S] closure_subset[of S]
chaieb@30262
   838
  by simp
chaieb@30262
   839
chaieb@30262
   840
lemma open_inter_closure_eq_empty:
chaieb@30262
   841
  "open S \<Longrightarrow> (S \<inter> closure T) = {} \<longleftrightarrow> S \<inter> T = {}"
chaieb@30262
   842
  using open_subset_interior[of S "UNIV - T"]
chaieb@30262
   843
  using interior_subset[of "UNIV - T"]
chaieb@30262
   844
  unfolding closure_interior
chaieb@30262
   845
  by auto
chaieb@30262
   846
huffman@31420
   847
lemma open_inter_closure_subset:
huffman@31489
   848
  "open S \<Longrightarrow> (S \<inter> (closure T)) \<subseteq> closure(S \<inter> T)"
chaieb@30262
   849
proof
chaieb@30262
   850
  fix x
chaieb@30262
   851
  assume as: "open S" "x \<in> S \<inter> closure T"
chaieb@30262
   852
  { assume *:"x islimpt T"
huffman@31489
   853
    have "x islimpt (S \<inter> T)"
huffman@31489
   854
    proof (rule islimptI)
huffman@31489
   855
      fix A
huffman@31489
   856
      assume "x \<in> A" "open A"
huffman@31489
   857
      with as have "x \<in> A \<inter> S" "open (A \<inter> S)"
huffman@31490
   858
        by (simp_all add: open_Int)
huffman@31489
   859
      with * obtain y where "y \<in> T" "y \<in> A \<inter> S" "y \<noteq> x"
huffman@31489
   860
        by (rule islimptE)
huffman@31489
   861
      hence "y \<in> S \<inter> T" "y \<in> A \<and> y \<noteq> x"
huffman@31489
   862
        by simp_all
huffman@31489
   863
      thus "\<exists>y\<in>(S \<inter> T). y \<in> A \<and> y \<noteq> x" ..
huffman@31489
   864
    qed
chaieb@30262
   865
  }
chaieb@30262
   866
  then show "x \<in> closure (S \<inter> T)" using as
chaieb@30262
   867
    unfolding closure_def
chaieb@30262
   868
    by blast
chaieb@30262
   869
qed
chaieb@30262
   870
chaieb@30262
   871
lemma closure_complement: "closure(UNIV - S) = UNIV - interior(S)"
chaieb@30262
   872
proof-
chaieb@30262
   873
  have "S = UNIV - (UNIV - S)"
chaieb@30262
   874
    by auto
chaieb@30262
   875
  thus ?thesis
chaieb@30262
   876
    unfolding closure_interior
chaieb@30262
   877
    by auto
chaieb@30262
   878
qed
chaieb@30262
   879
chaieb@30262
   880
lemma interior_complement: "interior(UNIV - S) = UNIV - closure(S)"
chaieb@30262
   881
  unfolding closure_interior
chaieb@30262
   882
  by blast
chaieb@30262
   883
chaieb@30262
   884
subsection{* Frontier (aka boundary) *}
chaieb@30262
   885
chaieb@30262
   886
definition "frontier S = closure S - interior S"
chaieb@30262
   887
chaieb@30262
   888
lemma frontier_closed: "closed(frontier S)"
huffman@31490
   889
  by (simp add: frontier_def closed_Diff)
chaieb@30262
   890
chaieb@30262
   891
lemma frontier_closures: "frontier S = (closure S) \<inter> (closure(UNIV - S))"
chaieb@30262
   892
  by (auto simp add: frontier_def interior_closure)
chaieb@30262
   893
huffman@31420
   894
lemma frontier_straddle:
huffman@31420
   895
  fixes a :: "'a::metric_space"
huffman@31420
   896
  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))" (is "?lhs \<longleftrightarrow> ?rhs")
chaieb@30262
   897
proof
chaieb@30262
   898
  assume "?lhs"
chaieb@30262
   899
  { fix e::real
chaieb@30262
   900
    assume "e > 0"
chaieb@30262
   901
    let ?rhse = "(\<exists>x\<in>S. dist a x < e) \<and> (\<exists>x. x \<notin> S \<and> dist a x < e)"
chaieb@30262
   902
    { assume "a\<in>S"
huffman@31285
   903
      have "\<exists>x\<in>S. dist a x < e" using `e>0` `a\<in>S` by(rule_tac x=a in bexI) auto
chaieb@30262
   904
      moreover have "\<exists>x. x \<notin> S \<and> dist a x < e" using `?lhs` `a\<in>S`
wenzelm@32960
   905
        unfolding frontier_closures closure_def islimpt_def using `e>0`
wenzelm@32960
   906
        by (auto, erule_tac x="ball a e" in allE, auto)
chaieb@30262
   907
      ultimately have ?rhse by auto
chaieb@30262
   908
    }
chaieb@30262
   909
    moreover
chaieb@30262
   910
    { assume "a\<notin>S"
chaieb@30262
   911
      hence ?rhse using `?lhs`
wenzelm@32960
   912
        unfolding frontier_closures closure_def islimpt_def
wenzelm@32960
   913
        using open_ball[of a e] `e > 0`
wenzelm@32960
   914
        by (auto, erule_tac x = "ball a e" in allE, auto) (* FIXME: VERY slow! *)
chaieb@30262
   915
    }
huffman@30488
   916
    ultimately have ?rhse by auto
chaieb@30262
   917
  }
chaieb@30262
   918
  thus ?rhs by auto
chaieb@30262
   919
next
chaieb@30262
   920
  assume ?rhs
chaieb@30262
   921
  moreover
chaieb@30262
   922
  { fix T assume "a\<notin>S" and
chaieb@30262
   923
    as:"\<forall>e>0. (\<exists>x\<in>S. dist a x < e) \<and> (\<exists>x. x \<notin> S \<and> dist a x < e)" "a \<notin> S" "a \<in> T" "open T"
chaieb@30262
   924
    from `open T` `a \<in> T` have "\<exists>e>0. ball a e \<subseteq> T" unfolding open_contains_ball[of T] by auto
chaieb@30262
   925
    then obtain e where "e>0" "ball a e \<subseteq> T" by auto
chaieb@30262
   926
    then obtain y where y:"y\<in>S" "dist a y < e"  using as(1) by auto
chaieb@30262
   927
    have "\<exists>y\<in>S. y \<in> T \<and> y \<noteq> a"
chaieb@30262
   928
      using `dist a y < e` `ball a e \<subseteq> T` unfolding ball_def using `y\<in>S` `a\<notin>S` by auto
chaieb@30262
   929
  }
chaieb@30262
   930
  hence "a \<in> closure S" unfolding closure_def islimpt_def using `?rhs` by auto
chaieb@30262
   931
  moreover
chaieb@30262
   932
  { fix T assume "a \<in> T"  "open T" "a\<in>S"
chaieb@30262
   933
    then obtain e where "e>0" and balle: "ball a e \<subseteq> T" unfolding open_contains_ball using `?rhs` by auto
chaieb@30262
   934
    obtain x where "x \<notin> S" "dist a x < e" using `?rhs` using `e>0` by auto
chaieb@30262
   935
    hence "\<exists>y\<in>UNIV - S. y \<in> T \<and> y \<noteq> a" using balle `a\<in>S` unfolding ball_def by (rule_tac x=x in bexI)auto
chaieb@30262
   936
  }
chaieb@30262
   937
  hence "a islimpt (UNIV - S) \<or> a\<notin>S" unfolding islimpt_def by auto
chaieb@30262
   938
  ultimately show ?lhs unfolding frontier_closures using closure_def[of "UNIV - S"] by auto
chaieb@30262
   939
qed
chaieb@30262
   940
huffman@30488
   941
lemma frontier_subset_closed: "closed S \<Longrightarrow> frontier S \<subseteq> S"
chaieb@30262
   942
  by (metis frontier_def closure_closed Diff_subset)
chaieb@30262
   943
chaieb@30262
   944
lemma frontier_empty: "frontier {} = {}"
chaieb@30262
   945
  by (simp add: frontier_def closure_empty)
chaieb@30262
   946
chaieb@30262
   947
lemma frontier_subset_eq: "frontier S \<subseteq> S \<longleftrightarrow> closed S"
chaieb@30262
   948
proof-
chaieb@30262
   949
  { assume "frontier S \<subseteq> S"
chaieb@30262
   950
    hence "closure S \<subseteq> S" using interior_subset unfolding frontier_def by auto
chaieb@30262
   951
    hence "closed S" using closure_subset_eq by auto
chaieb@30262
   952
  }
chaieb@30262
   953
  thus ?thesis using frontier_subset_closed[of S] by auto
chaieb@30262
   954
qed
chaieb@30262
   955
huffman@30488
   956
lemma frontier_complement: "frontier(UNIV - S) = frontier S"
chaieb@30262
   957
  by (auto simp add: frontier_def closure_complement interior_complement)
chaieb@30262
   958
chaieb@30262
   959
lemma frontier_disjoint_eq: "frontier S \<inter> S = {} \<longleftrightarrow> open S"
huffman@30488
   960
  using frontier_complement frontier_subset_eq[of "UNIV - S"]
huffman@31490
   961
  unfolding open_closed Compl_eq_Diff_UNIV by auto
chaieb@30262
   962
chaieb@30262
   963
subsection{* Common nets and The "within" modifier for nets. *}
chaieb@30262
   964
huffman@31285
   965
definition
huffman@31346
   966
  at_infinity :: "'a::real_normed_vector net" where
huffman@31390
   967
  "at_infinity = Abs_net (range (\<lambda>r. {x. r \<le> norm x}))"
huffman@31346
   968
huffman@31346
   969
definition
huffman@31530
   970
  indirection :: "'a::real_normed_vector \<Rightarrow> 'a \<Rightarrow> 'a net" (infixr "indirection" 70) where
huffman@31530
   971
  "a indirection v = (at a) within {b. \<exists>c\<ge>0. b - a = scaleR c v}"
chaieb@30262
   972
chaieb@30262
   973
text{* Prove That They are all nets. *}
chaieb@30262
   974
huffman@31390
   975
lemma Rep_net_at_infinity:
huffman@31390
   976
  "Rep_net at_infinity = range (\<lambda>r. {x. r \<le> norm x})"
huffman@31390
   977
unfolding at_infinity_def
huffman@31390
   978
apply (rule Abs_net_inverse')
huffman@31390
   979
apply (rule image_nonempty, simp)
huffman@31390
   980
apply (clarsimp, rename_tac r s)
huffman@31390
   981
apply (rule_tac x="max r s" in exI, auto)
huffman@31390
   982
done
huffman@31390
   983
huffman@31346
   984
lemma within_UNIV: "net within UNIV = net"
huffman@31390
   985
  by (simp add: Rep_net_inject [symmetric] Rep_net_within)
chaieb@30262
   986
chaieb@30262
   987
subsection{* Identify Trivial limits, where we can't approach arbitrarily closely. *}
chaieb@30262
   988
huffman@31346
   989
definition
huffman@31346
   990
  trivial_limit :: "'a net \<Rightarrow> bool" where
huffman@31390
   991
  "trivial_limit net \<longleftrightarrow> {} \<in> Rep_net net"
huffman@31346
   992
huffman@31346
   993
lemma trivial_limit_within:
huffman@31346
   994
  shows "trivial_limit (at a within S) \<longleftrightarrow> \<not> a islimpt S"
huffman@31390
   995
proof
huffman@31390
   996
  assume "trivial_limit (at a within S)"
huffman@31390
   997
  thus "\<not> a islimpt S"
huffman@31390
   998
    unfolding trivial_limit_def
huffman@31390
   999
    unfolding Rep_net_within Rep_net_at
huffman@31492
  1000
    unfolding islimpt_def
huffman@31447
  1001
    apply (clarsimp simp add: expand_set_eq)
huffman@31447
  1002
    apply (rename_tac T, rule_tac x=T in exI)
huffman@31447
  1003
    apply (clarsimp, drule_tac x=y in spec, simp)
huffman@31390
  1004
    done
huffman@31390
  1005
next
huffman@31390
  1006
  assume "\<not> a islimpt S"
huffman@31390
  1007
  thus "trivial_limit (at a within S)"
huffman@31390
  1008
    unfolding trivial_limit_def
huffman@31390
  1009
    unfolding Rep_net_within Rep_net_at
huffman@31492
  1010
    unfolding islimpt_def
huffman@31447
  1011
    apply (clarsimp simp add: image_image)
huffman@31447
  1012
    apply (rule_tac x=T in image_eqI)
huffman@31390
  1013
    apply (auto simp add: expand_set_eq)
huffman@31390
  1014
    done
chaieb@30262
  1015
qed
chaieb@30262
  1016
huffman@31391
  1017
lemma trivial_limit_at_iff: "trivial_limit (at a) \<longleftrightarrow> \<not> a islimpt UNIV"
huffman@31346
  1018
  using trivial_limit_within [of a UNIV]
huffman@31346
  1019
  by (simp add: within_UNIV)
huffman@31346
  1020
huffman@31391
  1021
lemma trivial_limit_at:
huffman@31391
  1022
  fixes a :: "'a::perfect_space"
huffman@31391
  1023
  shows "\<not> trivial_limit (at a)"
huffman@31391
  1024
  by (simp add: trivial_limit_at_iff)
huffman@31391
  1025
huffman@31346
  1026
lemma trivial_limit_at_infinity:
huffman@31346
  1027
  "\<not> trivial_limit (at_infinity :: ('a::{real_normed_vector,zero_neq_one}) net)"
huffman@31391
  1028
  (* FIXME: find a more appropriate type class *)
huffman@31390
  1029
  unfolding trivial_limit_def Rep_net_at_infinity
huffman@31390
  1030
  apply (clarsimp simp add: expand_set_eq)
huffman@31390
  1031
  apply (drule_tac x="scaleR r (sgn 1)" in spec)
huffman@31587
  1032
  apply (simp add: norm_sgn)
huffman@31390
  1033
  done
chaieb@30262
  1034
huffman@31346
  1035
lemma trivial_limit_sequentially: "\<not> trivial_limit sequentially"
huffman@31390
  1036
  by (auto simp add: trivial_limit_def Rep_net_sequentially)
chaieb@30262
  1037
chaieb@30262
  1038
subsection{* Some property holds "sufficiently close" to the limit point. *}
chaieb@30262
  1039
huffman@31447
  1040
lemma eventually_at: (* FIXME: this replaces Limits.eventually_at *)
huffman@31390
  1041
  "eventually P (at a) \<longleftrightarrow> (\<exists>d>0. \<forall>x. 0 < dist x a \<and> dist x a < d \<longrightarrow> P x)"
huffman@31447
  1042
unfolding eventually_at dist_nz by auto
huffman@31390
  1043
huffman@31390
  1044
lemma eventually_at_infinity:
huffman@31390
  1045
  "eventually P at_infinity \<longleftrightarrow> (\<exists>b. \<forall>x. norm x >= b \<longrightarrow> P x)"
huffman@31390
  1046
unfolding eventually_def Rep_net_at_infinity by auto
huffman@31390
  1047
huffman@31346
  1048
lemma eventually_within: "eventually P (at a within S) \<longleftrightarrow>
chaieb@30262
  1049
        (\<exists>d>0. \<forall>x\<in>S. 0 < dist x a \<and> dist x a < d \<longrightarrow> P x)"
huffman@31393
  1050
unfolding eventually_within eventually_at dist_nz by auto
huffman@31390
  1051
huffman@31390
  1052
lemma eventually_within_le: "eventually P (at a within S) \<longleftrightarrow>
huffman@31390
  1053
        (\<exists>d>0. \<forall>x\<in>S. 0 < dist x a \<and> dist x a <= d \<longrightarrow> P x)" (is "?lhs = ?rhs")
huffman@31390
  1054
unfolding eventually_within
huffman@31390
  1055
apply safe
huffman@31390
  1056
apply (rule_tac x="d/2" in exI, simp)
huffman@31390
  1057
apply (rule_tac x="d" in exI, simp)
huffman@31390
  1058
done
huffman@31390
  1059
huffman@31390
  1060
lemma eventually_happens: "eventually P net ==> trivial_limit net \<or> (\<exists>x. P x)"
huffman@31390
  1061
  unfolding eventually_def trivial_limit_def
huffman@31390
  1062
  using Rep_net_nonempty [of net] by auto
chaieb@30262
  1063
huffman@31347
  1064
lemma always_eventually: "(\<forall>x. P x) ==> eventually P net"
huffman@31390
  1065
  unfolding eventually_def trivial_limit_def
huffman@31390
  1066
  using Rep_net_nonempty [of net] by auto
huffman@31347
  1067
huffman@31348
  1068
lemma trivial_limit_eventually: "trivial_limit net \<Longrightarrow> eventually P net"
huffman@31390
  1069
  unfolding trivial_limit_def eventually_def by auto
huffman@31390
  1070
huffman@31390
  1071
lemma eventually_False: "eventually (\<lambda>x. False) net \<longleftrightarrow> trivial_limit net"
huffman@31390
  1072
  unfolding trivial_limit_def eventually_def by auto
huffman@31348
  1073
huffman@31348
  1074
lemma trivial_limit_eq: "trivial_limit net \<longleftrightarrow> (\<forall>P. eventually P net)"
huffman@31390
  1075
  apply (safe elim!: trivial_limit_eventually)
huffman@31390
  1076
  apply (simp add: eventually_False [symmetric])
huffman@31390
  1077
  done
huffman@31348
  1078
chaieb@30262
  1079
text{* Combining theorems for "eventually" *}
chaieb@30262
  1080
huffman@31390
  1081
lemma eventually_conjI:
huffman@31390
  1082
  "\<lbrakk>eventually (\<lambda>x. P x) net; eventually (\<lambda>x. Q x) net\<rbrakk>
huffman@31390
  1083
    \<Longrightarrow> eventually (\<lambda>x. P x \<and> Q x) net"
huffman@31393
  1084
by (rule eventually_conj)
chaieb@30262
  1085
huffman@31390
  1086
lemma eventually_rev_mono:
huffman@31390
  1087
  "eventually P net \<Longrightarrow> (\<forall>x. P x \<longrightarrow> Q x) \<Longrightarrow> eventually Q net"
huffman@31390
  1088
using eventually_mono [of P Q] by fast
huffman@31390
  1089
huffman@31390
  1090
lemma eventually_and: " eventually (\<lambda>x. P x \<and> Q x) net \<longleftrightarrow> eventually P net \<and> eventually Q net"
huffman@31390
  1091
  by (auto intro!: eventually_conjI elim: eventually_rev_mono)
huffman@31390
  1092
chaieb@30262
  1093
lemma eventually_false: "eventually (\<lambda>x. False) net \<longleftrightarrow> trivial_limit net"
huffman@31390
  1094
  by (auto simp add: eventually_False)
huffman@31390
  1095
huffman@31390
  1096
lemma not_eventually: "(\<forall>x. \<not> P x ) \<Longrightarrow> ~(trivial_limit net) ==> ~(eventually (\<lambda>x. P x) net)"
huffman@31390
  1097
  by (simp add: eventually_False)
huffman@31347
  1098
chaieb@30262
  1099
subsection{* Limits, defined as vacuously true when the limit is trivial. *}
chaieb@30262
  1100
chaieb@30262
  1101
  text{* Notation Lim to avoid collition with lim defined in analysis *}
huffman@31488
  1102
definition
huffman@31654
  1103
  Lim :: "'a net \<Rightarrow> ('a \<Rightarrow> 'b::t2_space) \<Rightarrow> 'b" where
huffman@31488
  1104
  "Lim net f = (THE l. (f ---> l) net)"
chaieb@30262
  1105
huffman@30488
  1106
lemma Lim:
chaieb@30262
  1107
 "(f ---> l) net \<longleftrightarrow>
chaieb@30262
  1108
        trivial_limit net \<or>
huffman@31348
  1109
        (\<forall>e>0. eventually (\<lambda>x. dist (f x) l < e) net)"
huffman@31488
  1110
  unfolding tendsto_iff trivial_limit_eq by auto
chaieb@30262
  1111
chaieb@30262
  1112
chaieb@30262
  1113
text{* Show that they yield usual definitions in the various cases. *}
chaieb@30262
  1114
chaieb@30262
  1115
lemma Lim_within_le: "(f ---> l)(at a within S) \<longleftrightarrow>
chaieb@30262
  1116
           (\<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)"
huffman@31488
  1117
  by (auto simp add: tendsto_iff eventually_within_le)
chaieb@30262
  1118
chaieb@30262
  1119
lemma Lim_within: "(f ---> l) (at a within S) \<longleftrightarrow>
chaieb@30262
  1120
        (\<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)"
huffman@31488
  1121
  by (auto simp add: tendsto_iff eventually_within)
chaieb@30262
  1122
chaieb@30262
  1123
lemma Lim_at: "(f ---> l) (at a) \<longleftrightarrow>
chaieb@30262
  1124
        (\<forall>e >0. \<exists>d>0. \<forall>x. 0 < dist x a  \<and> dist x a  < d  \<longrightarrow> dist (f x) l < e)"
huffman@31488
  1125
  by (auto simp add: tendsto_iff eventually_at)
chaieb@30262
  1126
huffman@31342
  1127
lemma Lim_at_iff_LIM: "(f ---> l) (at a) \<longleftrightarrow> f -- a --> l"
huffman@31342
  1128
  unfolding Lim_at LIM_def by (simp only: zero_less_dist_iff)
huffman@31342
  1129
chaieb@30262
  1130
lemma Lim_at_infinity:
huffman@31531
  1131
  "(f ---> l) at_infinity \<longleftrightarrow> (\<forall>e>0. \<exists>b. \<forall>x. norm x >= b \<longrightarrow> dist (f x) l < e)"
huffman@31488
  1132
  by (auto simp add: tendsto_iff eventually_at_infinity)
chaieb@30262
  1133
huffman@30488
  1134
lemma Lim_sequentially:
chaieb@30262
  1135
 "(S ---> l) sequentially \<longleftrightarrow>
chaieb@30262
  1136
          (\<forall>e>0. \<exists>N. \<forall>n\<ge>N. dist (S n) l < e)"
huffman@31488
  1137
  by (auto simp add: tendsto_iff eventually_sequentially)
chaieb@30262
  1138
huffman@31342
  1139
lemma Lim_sequentially_iff_LIMSEQ: "(S ---> l) sequentially \<longleftrightarrow> S ----> l"
huffman@31342
  1140
  unfolding Lim_sequentially LIMSEQ_def ..
huffman@31342
  1141
huffman@31525
  1142
lemma Lim_eventually: "eventually (\<lambda>x. f x = l) net \<Longrightarrow> (f ---> l) net"
huffman@31525
  1143
  by (rule topological_tendstoI, auto elim: eventually_rev_mono)
chaieb@30262
  1144
chaieb@30262
  1145
text{* The expected monotonicity property. *}
chaieb@30262
  1146
huffman@31447
  1147
lemma Lim_within_empty: "(f ---> l) (net within {})"
huffman@31447
  1148
  unfolding tendsto_def Limits.eventually_within by simp
huffman@31447
  1149
huffman@31447
  1150
lemma Lim_within_subset: "(f ---> l) (net within S) \<Longrightarrow> T \<subseteq> S \<Longrightarrow> (f ---> l) (net within T)"
huffman@31447
  1151
  unfolding tendsto_def Limits.eventually_within
huffman@31447
  1152
  by (auto elim!: eventually_elim1)
huffman@31447
  1153
huffman@31447
  1154
lemma Lim_Un: assumes "(f ---> l) (net within S)" "(f ---> l) (net within T)"
huffman@31447
  1155
  shows "(f ---> l) (net within (S \<union> T))"
huffman@31447
  1156
  using assms unfolding tendsto_def Limits.eventually_within
huffman@31447
  1157
  apply clarify
huffman@31492
  1158
  apply (drule spec, drule (1) mp, drule (1) mp)
huffman@31492
  1159
  apply (drule spec, drule (1) mp, drule (1) mp)
huffman@31447
  1160
  apply (auto elim: eventually_elim2)
huffman@31447
  1161
  done
chaieb@30262
  1162
huffman@30488
  1163
lemma Lim_Un_univ:
huffman@31447
  1164
 "(f ---> l) (net within S) \<Longrightarrow> (f ---> l) (net within T) \<Longrightarrow>  S \<union> T = UNIV
huffman@31447
  1165
        ==> (f ---> l) net"
chaieb@30262
  1166
  by (metis Lim_Un within_UNIV)
chaieb@30262
  1167
chaieb@30262
  1168
text{* Interrelations between restricted and unrestricted limits. *}
chaieb@30262
  1169
huffman@31447
  1170
lemma Lim_at_within: "(f ---> l) net ==> (f ---> l)(net within S)"
huffman@31525
  1171
  (* FIXME: rename *)
huffman@31447
  1172
  unfolding tendsto_def Limits.eventually_within
huffman@31492
  1173
  apply (clarify, drule spec, drule (1) mp, drule (1) mp)
huffman@31447
  1174
  by (auto elim!: eventually_elim1)
chaieb@30262
  1175
chaieb@30262
  1176
lemma Lim_within_open:
huffman@31525
  1177
  fixes f :: "'a::topological_space \<Rightarrow> 'b::topological_space"
chaieb@30262
  1178
  assumes"a \<in> S" "open S"
chaieb@30262
  1179
  shows "(f ---> l)(at a within S) \<longleftrightarrow> (f ---> l)(at a)" (is "?lhs \<longleftrightarrow> ?rhs")
chaieb@30262
  1180
proof
chaieb@30262
  1181
  assume ?lhs
huffman@31525
  1182
  { fix A assume "open A" "l \<in> A"
huffman@31525
  1183
    with `?lhs` have "eventually (\<lambda>x. f x \<in> A) (at a within S)"
huffman@31525
  1184
      by (rule topological_tendstoD)
huffman@31525
  1185
    hence "eventually (\<lambda>x. x \<in> S \<longrightarrow> f x \<in> A) (at a)"
huffman@31447
  1186
      unfolding Limits.eventually_within .
huffman@31525
  1187
    then obtain T where "open T" "a \<in> T" "\<forall>x\<in>T. x \<noteq> a \<longrightarrow> x \<in> S \<longrightarrow> f x \<in> A"
huffman@31492
  1188
      unfolding eventually_at_topological by fast
huffman@31525
  1189
    hence "open (T \<inter> S)" "a \<in> T \<inter> S" "\<forall>x\<in>(T \<inter> S). x \<noteq> a \<longrightarrow> f x \<in> A"
huffman@31447
  1190
      using assms by auto
huffman@31525
  1191
    hence "\<exists>T. open T \<and> a \<in> T \<and> (\<forall>x\<in>T. x \<noteq> a \<longrightarrow> f x \<in> A)"
huffman@31447
  1192
      by fast
huffman@31525
  1193
    hence "eventually (\<lambda>x. f x \<in> A) (at a)"
huffman@31492
  1194
      unfolding eventually_at_topological .
chaieb@30262
  1195
  }
huffman@31525
  1196
  thus ?rhs by (rule topological_tendstoI)
chaieb@30262
  1197
next
chaieb@30262
  1198
  assume ?rhs
huffman@31447
  1199
  thus ?lhs by (rule Lim_at_within)
chaieb@30262
  1200
qed
chaieb@30262
  1201
chaieb@30262
  1202
text{* Another limit point characterization. *}
chaieb@30262
  1203
huffman@30488
  1204
lemma islimpt_sequential:
huffman@31488
  1205
  fixes x :: "'a::metric_space" (* FIXME: generalize to topological_space *)
huffman@31488
  1206
  shows "x islimpt S \<longleftrightarrow> (\<exists>f. (\<forall>n::nat. f n \<in> S -{x}) \<and> (f ---> x) sequentially)"
huffman@31488
  1207
    (is "?lhs = ?rhs")
chaieb@30262
  1208
proof
chaieb@30262
  1209
  assume ?lhs
huffman@30488
  1210
  then obtain f where f:"\<forall>y. y>0 \<longrightarrow> f y \<in> S \<and> f y \<noteq> x \<and> dist (f y) x < y"
chaieb@30262
  1211
    unfolding islimpt_approachable using choice[of "\<lambda>e y. e>0 \<longrightarrow> y\<in>S \<and> y\<noteq>x \<and> dist y x < e"] by auto
chaieb@30262
  1212
  { fix n::nat
chaieb@30262
  1213
    have "f (inverse (real n + 1)) \<in> S - {x}" using f by auto
chaieb@30262
  1214
  }
chaieb@30262
  1215
  moreover
chaieb@30262
  1216
  { fix e::real assume "e>0"
chaieb@30262
  1217
    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
chaieb@30262
  1218
    then obtain N::nat where "inverse (real (N + 1)) < e" by auto
chaieb@30262
  1219
    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)
chaieb@30262
  1220
    moreover have "\<forall>n\<ge>N. dist (f (inverse (real n + 1))) x < (inverse (real n + 1))" using f `e>0` by auto
chaieb@30262
  1221
    ultimately have "\<exists>N::nat. \<forall>n\<ge>N. dist (f (inverse (real n + 1))) x < e" apply(rule_tac x=N in exI) apply auto apply(erule_tac x=n in allE)+ by auto
chaieb@30262
  1222
  }
chaieb@30262
  1223
  hence " ((\<lambda>n. f (inverse (real n + 1))) ---> x) sequentially"
chaieb@30262
  1224
    unfolding Lim_sequentially using f by auto
huffman@30488
  1225
  ultimately show ?rhs apply (rule_tac x="(\<lambda>n::nat. f (inverse (real n + 1)))" in exI) by auto
chaieb@30262
  1226
next
chaieb@30262
  1227
  assume ?rhs
huffman@31345
  1228
  then obtain f::"nat\<Rightarrow>'a"  where f:"(\<forall>n. f n \<in> S - {x})" "(\<forall>e>0. \<exists>N. \<forall>n\<ge>N. dist (f n) x < e)" unfolding Lim_sequentially by auto
chaieb@30262
  1229
  { fix e::real assume "e>0"
chaieb@30262
  1230
    then obtain N where "dist (f N) x < e" using f(2) by auto
chaieb@30262
  1231
    moreover have "f N\<in>S" "f N \<noteq> x" using f(1) by auto
chaieb@30262
  1232
    ultimately have "\<exists>x'\<in>S. x' \<noteq> x \<and> dist x' x < e" by auto
chaieb@30262
  1233
  }
chaieb@30262
  1234
  thus ?lhs unfolding islimpt_approachable by auto
chaieb@30262
  1235
qed
chaieb@30262
  1236
chaieb@30262
  1237
text{* Basic arithmetical combining theorems for limits. *}
chaieb@30262
  1238
huffman@31658
  1239
lemma Lim_linear:
huffman@31657
  1240
  assumes "(f ---> l) net" "bounded_linear h"
chaieb@30262
  1241
  shows "((\<lambda>x. h (f x)) ---> h l) net"
huffman@31657
  1242
using `bounded_linear h` `(f ---> l) net`
huffman@31529
  1243
by (rule bounded_linear.tendsto)
chaieb@30262
  1244
huffman@31558
  1245
lemma Lim_ident_at: "((\<lambda>x. x) ---> a) (at a)"
huffman@31558
  1246
  unfolding tendsto_def Limits.eventually_at_topological by fast
huffman@31558
  1247
chaieb@30262
  1248
lemma Lim_const: "((\<lambda>x. a) ---> a) net"
huffman@31525
  1249
  by (rule tendsto_const)
chaieb@30262
  1250
huffman@31343
  1251
lemma Lim_cmul:
huffman@31658
  1252
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
huffman@31585
  1253
  shows "(f ---> l) net ==> ((\<lambda>x. c *\<^sub>R f x) ---> c *\<^sub>R l) net"
huffman@31585
  1254
  by (intro tendsto_intros)
chaieb@30262
  1255
huffman@31343
  1256
lemma Lim_neg:
huffman@31343
  1257
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
huffman@31343
  1258
  shows "(f ---> l) net ==> ((\<lambda>x. -(f x)) ---> -l) net"
huffman@31525
  1259
  by (rule tendsto_minus)
chaieb@30262
  1260
huffman@31343
  1261
lemma Lim_add: fixes f :: "'a \<Rightarrow> 'b::real_normed_vector" shows
chaieb@30262
  1262
 "(f ---> l) net \<Longrightarrow> (g ---> m) net \<Longrightarrow> ((\<lambda>x. f(x) + g(x)) ---> l + m) net"
huffman@31525
  1263
  by (rule tendsto_add)
chaieb@30262
  1264
huffman@31343
  1265
lemma Lim_sub:
huffman@31343
  1266
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
huffman@31343
  1267
  shows "(f ---> l) net \<Longrightarrow> (g ---> m) net \<Longrightarrow> ((\<lambda>x. f(x) - g(x)) ---> l - m) net"
huffman@31525
  1268
  by (rule tendsto_diff)
chaieb@30262
  1269
huffman@31343
  1270
lemma Lim_null:
huffman@31343
  1271
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
huffman@31343
  1272
  shows "(f ---> l) net \<longleftrightarrow> ((\<lambda>x. f(x) - l) ---> 0) net" by (simp add: Lim dist_norm)
huffman@31343
  1273
huffman@31343
  1274
lemma Lim_null_norm:
huffman@31343
  1275
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
huffman@31558
  1276
  shows "(f ---> 0) net \<longleftrightarrow> ((\<lambda>x. norm(f x)) ---> 0) net"
huffman@31558
  1277
  by (simp add: Lim dist_norm)
chaieb@30262
  1278
huffman@30488
  1279
lemma Lim_null_comparison:
huffman@31343
  1280
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
huffman@31558
  1281
  assumes "eventually (\<lambda>x. norm (f x) \<le> g x) net" "(g ---> 0) net"
huffman@30488
  1282
  shows "(f ---> 0) net"
huffman@31488
  1283
proof(simp add: tendsto_iff, rule+)
chaieb@30262
  1284
  fix e::real assume "0<e"
chaieb@30262
  1285
  { fix x
huffman@31558
  1286
    assume "norm (f x) \<le> g x" "dist (g x) 0 < e"
huffman@31558
  1287
    hence "dist (f x) 0 < e" by (simp add: dist_norm)
chaieb@30262
  1288
  }
huffman@30488
  1289
  thus "eventually (\<lambda>x. dist (f x) 0 < e) net"
huffman@31558
  1290
    using eventually_and[of "\<lambda>x. norm(f x) <= g x" "\<lambda>x. dist (g x) 0 < e" net]
huffman@31558
  1291
    using eventually_mono[of "(\<lambda>x. norm (f x) \<le> g x \<and> dist (g x) 0 < e)" "(\<lambda>x. dist (f x) 0 < e)" net]
huffman@31488
  1292
    using assms `e>0` unfolding tendsto_iff by auto
chaieb@30262
  1293
qed
chaieb@30262
  1294
huffman@31558
  1295
lemma Lim_component:
huffman@31558
  1296
  fixes f :: "'a \<Rightarrow> 'b::metric_space ^ 'n::finite"
huffman@31558
  1297
  shows "(f ---> l) net \<Longrightarrow> ((\<lambda>a. f a $i) ---> l$i) net"
huffman@31488
  1298
  unfolding tendsto_iff
huffman@31558
  1299
  apply (clarify)
huffman@31558
  1300
  apply (drule spec, drule (1) mp)
huffman@31558
  1301
  apply (erule eventually_elim1)
huffman@31558
  1302
  apply (erule le_less_trans [OF dist_nth_le])
huffman@31558
  1303
  done
chaieb@30262
  1304
huffman@30488
  1305
lemma Lim_transform_bound:
huffman@31343
  1306
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
huffman@31343
  1307
  fixes g :: "'a \<Rightarrow> 'c::real_normed_vector"
chaieb@30262
  1308
  assumes "eventually (\<lambda>n. norm(f n) <= norm(g n)) net"  "(g ---> 0) net"
chaieb@30262
  1309
  shows "(f ---> 0) net"
huffman@31525
  1310
proof (rule tendstoI)
chaieb@30262
  1311
  fix e::real assume "e>0"
chaieb@30262
  1312
  { fix x
chaieb@30262
  1313
    assume "norm (f x) \<le> norm (g x)" "dist (g x) 0 < e"
huffman@31343
  1314
    hence "dist (f x) 0 < e" by (simp add: dist_norm)}
chaieb@30262
  1315
  thus "eventually (\<lambda>x. dist (f x) 0 < e) net"
chaieb@30262
  1316
    using eventually_and[of "\<lambda>x. norm (f x) \<le> norm (g x)" "\<lambda>x. dist (g x) 0 < e" net]
chaieb@30262
  1317
    using eventually_mono[of "\<lambda>x. norm (f x) \<le> norm (g x) \<and> dist (g x) 0 < e" "\<lambda>x. dist (f x) 0 < e" net]
huffman@31488
  1318
    using assms `e>0` unfolding tendsto_iff by blast
chaieb@30262
  1319
qed
chaieb@30262
  1320
chaieb@30262
  1321
text{* Deducing things about the limit from the elements. *}
chaieb@30262
  1322
chaieb@30262
  1323
lemma Lim_in_closed_set:
huffman@31525
  1324
  assumes "closed S" "eventually (\<lambda>x. f(x) \<in> S) net" "\<not>(trivial_limit net)" "(f ---> l) net"
chaieb@30262
  1325
  shows "l \<in> S"
huffman@31347
  1326
proof (rule ccontr)
huffman@31347
  1327
  assume "l \<notin> S"
huffman@31525
  1328
  with `closed S` have "open (- S)" "l \<in> - S"
huffman@31525
  1329
    by (simp_all add: open_Compl)
huffman@31525
  1330
  with assms(4) have "eventually (\<lambda>x. f x \<in> - S) net"
huffman@31525
  1331
    by (rule topological_tendstoD)
huffman@31525
  1332
  with assms(2) have "eventually (\<lambda>x. False) net"
huffman@31525
  1333
    by (rule eventually_elim2) simp
huffman@31525
  1334
  with assms(3) show "False"
huffman@31525
  1335
    by (simp add: eventually_False)
chaieb@30262
  1336
qed
chaieb@30262
  1337
chaieb@30262
  1338
text{* Need to prove closed(cball(x,e)) before deducing this as a corollary. *}
chaieb@30262
  1339
huffman@31533
  1340
lemma Lim_dist_ubound:
huffman@31533
  1341
  assumes "\<not>(trivial_limit net)" "(f ---> l) net" "eventually (\<lambda>x. dist a (f x) <= e) net"
huffman@31533
  1342
  shows "dist a l <= e"
huffman@31533
  1343
proof (rule ccontr)
huffman@31533
  1344
  assume "\<not> dist a l \<le> e"
huffman@31533
  1345
  then have "0 < dist a l - e" by simp
huffman@31533
  1346
  with assms(2) have "eventually (\<lambda>x. dist (f x) l < dist a l - e) net"
huffman@31533
  1347
    by (rule tendstoD)
huffman@31533
  1348
  with assms(3) have "eventually (\<lambda>x. dist a (f x) \<le> e \<and> dist (f x) l < dist a l - e) net"
huffman@31533
  1349
    by (rule eventually_conjI)
huffman@31533
  1350
  then obtain w where "dist a (f w) \<le> e" "dist (f w) l < dist a l - e"
huffman@31533
  1351
    using assms(1) eventually_happens by auto
huffman@31533
  1352
  hence "dist a (f w) + dist (f w) l < e + (dist a l - e)"
huffman@31533
  1353
    by (rule add_le_less_mono)
huffman@31533
  1354
  hence "dist a (f w) + dist (f w) l < dist a l"
huffman@31533
  1355
    by simp
huffman@31533
  1356
  also have "\<dots> \<le> dist a (f w) + dist (f w) l"
huffman@31533
  1357
    by (rule dist_triangle)
huffman@31533
  1358
  finally show False by simp
huffman@31533
  1359
qed
huffman@31533
  1360
huffman@30488
  1361
lemma Lim_norm_ubound:
huffman@31343
  1362
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
chaieb@30262
  1363
  assumes "\<not>(trivial_limit net)" "(f ---> l) net" "eventually (\<lambda>x. norm(f x) <= e) net"
chaieb@30262
  1364
  shows "norm(l) <= e"
huffman@31347
  1365
proof (rule ccontr)
huffman@31347
  1366
  assume "\<not> norm l \<le> e"
huffman@31347
  1367
  then have "0 < norm l - e" by simp
huffman@31347
  1368
  with assms(2) have "eventually (\<lambda>x. dist (f x) l < norm l - e) net"
huffman@31347
  1369
    by (rule tendstoD)
huffman@31347
  1370
  with assms(3) have "eventually (\<lambda>x. norm (f x) \<le> e \<and> dist (f x) l < norm l - e) net"
huffman@31347
  1371
    by (rule eventually_conjI)
huffman@31347
  1372
  then obtain w where "norm (f w) \<le> e" "dist (f w) l < norm l - e"
huffman@31347
  1373
    using assms(1) eventually_happens by auto
huffman@31347
  1374
  hence "norm (f w - l) < norm l - e" "norm (f w) \<le> e" by (simp_all add: dist_norm)
huffman@31347
  1375
  hence "norm (f w - l) + norm (f w) < norm l" by simp
huffman@31347
  1376
  hence "norm (f w - l - f w) < norm l" by (rule le_less_trans [OF norm_triangle_ineq4])
huffman@31347
  1377
  thus False using `\<not> norm l \<le> e` by simp
chaieb@30262
  1378
qed
chaieb@30262
  1379
chaieb@30262
  1380
lemma Lim_norm_lbound:
huffman@31343
  1381
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
chaieb@30262
  1382
  assumes "\<not> (trivial_limit net)"  "(f ---> l) net"  "eventually (\<lambda>x. e <= norm(f x)) net"
chaieb@30262
  1383
  shows "e \<le> norm l"
huffman@31347
  1384
proof (rule ccontr)
huffman@31347
  1385
  assume "\<not> e \<le> norm l"
huffman@31347
  1386
  then have "0 < e - norm l" by simp
huffman@31347
  1387
  with assms(2) have "eventually (\<lambda>x. dist (f x) l < e - norm l) net"
huffman@31347
  1388
    by (rule tendstoD)
huffman@31347
  1389
  with assms(3) have "eventually (\<lambda>x. e \<le> norm (f x) \<and> dist (f x) l < e - norm l) net"
huffman@31347
  1390
    by (rule eventually_conjI)
huffman@31347
  1391
  then obtain w where "e \<le> norm (f w)" "dist (f w) l < e - norm l"
huffman@31347
  1392
    using assms(1) eventually_happens by auto
huffman@31347
  1393
  hence "norm (f w - l) + norm l < e" "e \<le> norm (f w)" by (simp_all add: dist_norm)
huffman@31347
  1394
  hence "norm (f w - l) + norm l < norm (f w)" by (rule less_le_trans)
huffman@31347
  1395
  hence "norm (f w - l + l) < norm (f w)" by (rule le_less_trans [OF norm_triangle_ineq])
huffman@31347
  1396
  thus False by simp
chaieb@30262
  1397
qed
chaieb@30262
  1398
chaieb@30262
  1399
text{* Uniqueness of the limit, when nontrivial. *}
chaieb@30262
  1400
chaieb@30262
  1401
lemma Lim_unique:
huffman@31654
  1402
  fixes f :: "'a \<Rightarrow> 'b::t2_space"
huffman@31397
  1403
  assumes "\<not> trivial_limit net"  "(f ---> l) net"  "(f ---> l') net"
chaieb@30262
  1404
  shows "l = l'"
huffman@31397
  1405
proof (rule ccontr)
huffman@31397
  1406
  assume "l \<noteq> l'"
huffman@31654
  1407
  obtain U V where "open U" "open V" "l \<in> U" "l' \<in> V" "U \<inter> V = {}"
huffman@31654
  1408
    using hausdorff [OF `l \<noteq> l'`] by fast
huffman@31654
  1409
  have "eventually (\<lambda>x. f x \<in> U) net"
huffman@31654
  1410
    using `(f ---> l) net` `open U` `l \<in> U` by (rule topological_tendstoD)
huffman@31397
  1411
  moreover
huffman@31654
  1412
  have "eventually (\<lambda>x. f x \<in> V) net"
huffman@31654
  1413
    using `(f ---> l') net` `open V` `l' \<in> V` by (rule topological_tendstoD)
huffman@31397
  1414
  ultimately
huffman@31397
  1415
  have "eventually (\<lambda>x. False) net"
huffman@31397
  1416
  proof (rule eventually_elim2)
huffman@31397
  1417
    fix x
huffman@31654
  1418
    assume "f x \<in> U" "f x \<in> V"
huffman@31654
  1419
    hence "f x \<in> U \<inter> V" by simp
huffman@31654
  1420
    with `U \<inter> V = {}` show "False" by simp
huffman@31397
  1421
  qed
huffman@31397
  1422
  with `\<not> trivial_limit net` show "False"
huffman@31397
  1423
    by (simp add: eventually_False)
chaieb@30262
  1424
qed
chaieb@30262
  1425
huffman@30488
  1426
lemma tendsto_Lim:
huffman@31654
  1427
  fixes f :: "'a \<Rightarrow> 'b::t2_space"
huffman@31343
  1428
  shows "~(trivial_limit net) \<Longrightarrow> (f ---> l) net ==> Lim net f = l"
chaieb@30262
  1429
  unfolding Lim_def using Lim_unique[of net f] by auto
chaieb@30262
  1430
huffman@31529
  1431
text{* Limit under bilinear function *}
chaieb@30262
  1432
huffman@30488
  1433
lemma Lim_bilinear:
huffman@31657
  1434
  assumes "(f ---> l) net" and "(g ---> m) net" and "bounded_bilinear h"
chaieb@30262
  1435
  shows "((\<lambda>x. h (f x) (g x)) ---> (h l m)) net"
huffman@31657
  1436
using `bounded_bilinear h` `(f ---> l) net` `(g ---> m) net`
huffman@31529
  1437
by (rule bounded_bilinear.tendsto)
chaieb@30262
  1438
chaieb@30262
  1439
text{* These are special for limits out of the same vector space. *}
chaieb@30262
  1440
huffman@31488
  1441
lemma Lim_within_id: "(id ---> a) (at a within s)"
huffman@31488
  1442
  unfolding tendsto_def Limits.eventually_within eventually_at_topological
huffman@31488
  1443
  by auto
huffman@31488
  1444
chaieb@30262
  1445
lemma Lim_at_id: "(id ---> a) (at a)"
chaieb@30262
  1446
apply (subst within_UNIV[symmetric]) by (simp add: Lim_within_id)
chaieb@30262
  1447
huffman@31346
  1448
lemma Lim_at_zero:
huffman@31391
  1449
  fixes a :: "'a::real_normed_vector"
huffman@31526
  1450
  fixes l :: "'b::topological_space"
huffman@31346
  1451
  shows "(f ---> l) (at a) \<longleftrightarrow> ((\<lambda>x. f(a + x)) ---> l) (at 0)" (is "?lhs = ?rhs")
chaieb@30262
  1452
proof
chaieb@30262
  1453
  assume "?lhs"
huffman@31526
  1454
  { fix S assume "open S" "l \<in> S"
huffman@31526
  1455
    with `?lhs` have "eventually (\<lambda>x. f x \<in> S) (at a)"
huffman@31526
  1456
      by (rule topological_tendstoD)
huffman@31526
  1457
    then obtain d where d: "d>0" "\<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> f x \<in> S"
huffman@31526
  1458
      unfolding Limits.eventually_at by fast
huffman@31526
  1459
    { fix x::"'a" assume "x \<noteq> 0 \<and> dist x 0 < d"
huffman@31526
  1460
      hence "f (a + x) \<in> S" using d
huffman@31526
  1461
      apply(erule_tac x="x+a" in allE)
huffman@31526
  1462
      by(auto simp add: comm_monoid_add.mult_commute dist_norm dist_commute)
chaieb@30262
  1463
    }
huffman@31526
  1464
    hence "\<exists>d>0. \<forall>x. x \<noteq> 0 \<and> dist x 0 < d \<longrightarrow> f (a + x) \<in> S"
huffman@31526
  1465
      using d(1) by auto
huffman@31526
  1466
    hence "eventually (\<lambda>x. f (a + x) \<in> S) (at 0)"
huffman@31526
  1467
      unfolding Limits.eventually_at .
chaieb@30262
  1468
  }
huffman@31526
  1469
  thus "?rhs" by (rule topological_tendstoI)
chaieb@30262
  1470
next
chaieb@30262
  1471
  assume "?rhs"
huffman@31526
  1472
  { fix S assume "open S" "l \<in> S"
huffman@31526
  1473
    with `?rhs` have "eventually (\<lambda>x. f (a + x) \<in> S) (at 0)"
huffman@31526
  1474
      by (rule topological_tendstoD)
huffman@31526
  1475
    then obtain d where d: "d>0" "\<forall>x. x \<noteq> 0 \<and> dist x 0 < d \<longrightarrow> f (a + x) \<in> S"
huffman@31526
  1476
      unfolding Limits.eventually_at by fast
huffman@31526
  1477
    { fix x::"'a" assume "x \<noteq> a \<and> dist x a < d"
huffman@31526
  1478
      hence "f x \<in> S" using d apply(erule_tac x="x-a" in allE)
wenzelm@32960
  1479
        by(auto simp add: comm_monoid_add.mult_commute dist_norm dist_commute)
chaieb@30262
  1480
    }
huffman@31526
  1481
    hence "\<exists>d>0. \<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> f x \<in> S" using d(1) by auto
huffman@31526
  1482
    hence "eventually (\<lambda>x. f x \<in> S) (at a)" unfolding Limits.eventually_at .
chaieb@30262
  1483
  }
huffman@31526
  1484
  thus "?lhs" by (rule topological_tendstoI)
chaieb@30262
  1485
qed
chaieb@30262
  1486
chaieb@30262
  1487
text{* It's also sometimes useful to extract the limit point from the net.  *}
chaieb@30262
  1488
huffman@31390
  1489
definition
huffman@31655
  1490
  netlimit :: "'a::t2_space net \<Rightarrow> 'a" where
huffman@31655
  1491
  "netlimit net = (SOME a. ((\<lambda>x. x) ---> a) net)"
huffman@31390
  1492
huffman@31390
  1493
lemma netlimit_within:
huffman@31390
  1494
  assumes "\<not> trivial_limit (at a within S)"
huffman@31390
  1495
  shows "netlimit (at a within S) = a"
huffman@31655
  1496
unfolding netlimit_def
huffman@31655
  1497
apply (rule some_equality)
huffman@31655
  1498
apply (rule Lim_at_within)
huffman@31655
  1499
apply (rule Lim_ident_at)
huffman@31655
  1500
apply (erule Lim_unique [OF assms])
huffman@31655
  1501
apply (rule Lim_at_within)
huffman@31655
  1502
apply (rule Lim_ident_at)
huffman@31390
  1503
done
chaieb@30262
  1504
huffman@31391
  1505
lemma netlimit_at:
huffman@31391
  1506
  fixes a :: "'a::perfect_space"
huffman@31391
  1507
  shows "netlimit (at a) = a"
chaieb@30262
  1508
  apply (subst within_UNIV[symmetric])
chaieb@30262
  1509
  using netlimit_within[of a UNIV]
chaieb@30262
  1510
  by (simp add: trivial_limit_at within_UNIV)
chaieb@30262
  1511
chaieb@30262
  1512
text{* Transformation of limit. *}
chaieb@30262
  1513
huffman@31343
  1514
lemma Lim_transform:
huffman@31343
  1515
  fixes f g :: "'a::type \<Rightarrow> 'b::real_normed_vector"
huffman@31343
  1516
  assumes "((\<lambda>x. f x - g x) ---> 0) net" "(f ---> l) net"
chaieb@30262
  1517
  shows "(g ---> l) net"
chaieb@30262
  1518
proof-
chaieb@30262
  1519
  from assms have "((\<lambda>x. f x - g x - f x) ---> 0 - l) net" using Lim_sub[of "\<lambda>x. f x - g x" 0 net f l] by auto
chaieb@30262
  1520
  thus "?thesis" using Lim_neg [of "\<lambda> x. - g x" "-l" net] by auto
chaieb@30262
  1521
qed
chaieb@30262
  1522
huffman@31343
  1523
lemma Lim_transform_eventually:
huffman@31526
  1524
  "eventually (\<lambda>x. f x = g x) net \<Longrightarrow> (f ---> l) net ==> (g ---> l) net"
huffman@31526
  1525
  apply (rule topological_tendstoI)
huffman@31526
  1526
  apply (drule (2) topological_tendstoD)
huffman@31395
  1527
  apply (erule (1) eventually_elim2, simp)
huffman@31395
  1528
  done
chaieb@30262
  1529
huffman@30488
  1530
lemma Lim_transform_within:
huffman@31488
  1531
  fixes l :: "'b::metric_space" (* TODO: generalize *)
chaieb@30262
  1532
  assumes "0 < d" "(\<forall>x'\<in>S. 0 < dist x' x \<and> dist x' x < d \<longrightarrow> f x' = g x')"
chaieb@30262
  1533
          "(f ---> l) (at x within S)"
chaieb@30262
  1534
  shows   "(g ---> l) (at x within S)"
huffman@31395
  1535
  using assms(1,3) unfolding Lim_within
huffman@31395
  1536
  apply -
huffman@31395
  1537
  apply (clarify, rename_tac e)
huffman@31395
  1538
  apply (drule_tac x=e in spec, clarsimp, rename_tac r)
huffman@31395
  1539
  apply (rule_tac x="min d r" in exI, clarsimp, rename_tac y)
huffman@31395
  1540
  apply (drule_tac x=y in bspec, assumption, clarsimp)
huffman@31395
  1541
  apply (simp add: assms(2))
huffman@31395
  1542
  done
chaieb@30262
  1543
huffman@31343
  1544
lemma Lim_transform_at:
huffman@31488
  1545
  fixes l :: "'b::metric_space" (* TODO: generalize *)
huffman@31343
  1546
  shows "0 < d \<Longrightarrow> (\<forall>x'. 0 < dist x' x \<and> dist x' x < d \<longrightarrow> f x' = g x') \<Longrightarrow>
chaieb@30262
  1547
  (f ---> l) (at x) ==> (g ---> l) (at x)"
chaieb@30262
  1548
  apply (subst within_UNIV[symmetric])
chaieb@30262
  1549
  using Lim_transform_within[of d UNIV x f g l]
chaieb@30262
  1550
  by (auto simp add: within_UNIV)
chaieb@30262
  1551
chaieb@30262
  1552
text{* Common case assuming being away from some crucial point like 0. *}
chaieb@30262
  1553
huffman@30488
  1554
lemma Lim_transform_away_within:
huffman@31447
  1555
  fixes a b :: "'a::metric_space"
huffman@31488
  1556
  fixes l :: "'b::metric_space" (* TODO: generalize *)
huffman@30488
  1557
  assumes "a\<noteq>b" "\<forall>x\<in> S. x \<noteq> a \<and> x \<noteq> b \<longrightarrow> f x = g x"
chaieb@30262
  1558
  and "(f ---> l) (at a within S)"
chaieb@30262
  1559
  shows "(g ---> l) (at a within S)"
chaieb@30262
  1560
proof-
huffman@30488
  1561
  have "\<forall>x'\<in>S. 0 < dist x' a \<and> dist x' a < dist a b \<longrightarrow> f x' = g x'" using assms(2)
huffman@31285
  1562
    apply auto apply(erule_tac x=x' in ballE) by (auto simp add: dist_commute)
chaieb@30262
  1563
  thus ?thesis using Lim_transform_within[of "dist a b" S a f g l] using assms(1,3) unfolding dist_nz by auto
chaieb@30262
  1564
qed
chaieb@30262
  1565
huffman@30488
  1566
lemma Lim_transform_away_at:
huffman@31447
  1567
  fixes a b :: "'a::metric_space"
huffman@31488
  1568
  fixes l :: "'b::metric_space" (* TODO: generalize *)
huffman@30488
  1569
  assumes ab: "a\<noteq>b" and fg: "\<forall>x. x \<noteq> a \<and> x \<noteq> b \<longrightarrow> f x = g x"
chaieb@30262
  1570
  and fl: "(f ---> l) (at a)"
chaieb@30262
  1571
  shows "(g ---> l) (at a)"
huffman@30488
  1572
  using Lim_transform_away_within[OF ab, of UNIV f g l] fg fl
chaieb@30262
  1573
  by (auto simp add: within_UNIV)
chaieb@30262
  1574
chaieb@30262
  1575
text{* Alternatively, within an open set. *}
chaieb@30262
  1576
huffman@30488
  1577
lemma Lim_transform_within_open:
huffman@31447
  1578
  fixes a :: "'a::metric_space"
huffman@31488
  1579
  fixes l :: "'b::metric_space" (* TODO: generalize *)
chaieb@30262
  1580
  assumes "open S"  "a \<in> S"  "\<forall>x\<in>S. x \<noteq> a \<longrightarrow> f x = g x"  "(f ---> l) (at a)"
chaieb@30262
  1581
  shows "(g ---> l) (at a)"
chaieb@30262
  1582
proof-
chaieb@30262
  1583
  from assms(1,2) obtain e::real where "e>0" and e:"ball a e \<subseteq> S" unfolding open_contains_ball by auto
huffman@30488
  1584
  hence "\<forall>x'. 0 < dist x' a \<and> dist x' a < e \<longrightarrow> f x' = g x'" using assms(3)
huffman@31285
  1585
    unfolding ball_def subset_eq apply auto apply(erule_tac x=x' in allE) apply(erule_tac x=x' in ballE) by(auto simp add: dist_commute)
chaieb@30262
  1586
  thus ?thesis using Lim_transform_at[of e a f g l] `e>0` assms(4) by auto
chaieb@30262
  1587
qed
chaieb@30262
  1588
chaieb@30262
  1589
text{* A congruence rule allowing us to transform limits assuming not at point. *}
chaieb@30262
  1590
huffman@31395
  1591
(* FIXME: Only one congruence rule for tendsto can be used at a time! *)
huffman@31395
  1592
huffman@30488
  1593
lemma Lim_cong_within[cong add]:
huffman@31488
  1594
  fixes a :: "'a::metric_space"
huffman@31488
  1595
  fixes l :: "'b::metric_space" (* TODO: generalize *)
huffman@31488
  1596
  shows "(\<And>x. x \<noteq> a \<Longrightarrow> f x = g x) ==> ((\<lambda>x. f x) ---> l) (at a within S) \<longleftrightarrow> ((g ---> l) (at a within S))"
chaieb@30262
  1597
  by (simp add: Lim_within dist_nz[symmetric])
chaieb@30262
  1598
huffman@30488
  1599
lemma Lim_cong_at[cong add]:
huffman@31488
  1600
  fixes a :: "'a::metric_space"
huffman@31488
  1601
  fixes l :: "'b::metric_space" (* TODO: generalize *)
huffman@31488
  1602
  shows "(\<And>x. x \<noteq> a ==> f x = g x) ==> (((\<lambda>x. f x) ---> l) (at a) \<longleftrightarrow> ((g ---> l) (at a)))"
chaieb@30262
  1603
  by (simp add: Lim_at dist_nz[symmetric])
chaieb@30262
  1604
chaieb@30262
  1605
text{* Useful lemmas on closure and set of possible sequential limits.*}
chaieb@30262
  1606
huffman@30488
  1607
lemma closure_sequential:
huffman@31488
  1608
  fixes l :: "'a::metric_space" (* TODO: generalize *)
huffman@31488
  1609
  shows "l \<in> closure S \<longleftrightarrow> (\<exists>x. (\<forall>n. x n \<in> S) \<and> (x ---> l) sequentially)" (is "?lhs = ?rhs")
chaieb@30262
  1610
proof
chaieb@30262
  1611
  assume "?lhs" moreover
chaieb@30262
  1612
  { assume "l \<in> S"
chaieb@30262
  1613
    hence "?rhs" using Lim_const[of l sequentially] by auto
chaieb@30262
  1614
  } moreover
chaieb@30262
  1615
  { assume "l islimpt S"
chaieb@30262
  1616
    hence "?rhs" unfolding islimpt_sequential by auto
chaieb@30262
  1617
  } ultimately
chaieb@30262
  1618
  show "?rhs" unfolding closure_def by auto
chaieb@30262
  1619
next
chaieb@30262
  1620
  assume "?rhs"
chaieb@30262
  1621
  thus "?lhs" unfolding closure_def unfolding islimpt_sequential by auto
chaieb@30262
  1622
qed
chaieb@30262
  1623
huffman@30488
  1624
lemma closed_sequential_limits:
huffman@31420
  1625
  fixes S :: "'a::metric_space set"
huffman@31420
  1626
  shows "closed S \<longleftrightarrow> (\<forall>x l. (\<forall>n. x n \<in> S) \<and> (x ---> l) sequentially \<longrightarrow> l \<in> S)"
chaieb@30262
  1627
  unfolding closed_limpt
huffman@31420
  1628
  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]
huffman@31420
  1629
  by metis
huffman@31420
  1630
huffman@31420
  1631
lemma closure_approachable:
huffman@31420
  1632
  fixes S :: "'a::metric_space set"
huffman@31420
  1633
  shows "x \<in> closure S \<longleftrightarrow> (\<forall>e>0. \<exists>y\<in>S. dist y x < e)"
chaieb@30262
  1634
  apply (auto simp add: closure_def islimpt_approachable)
huffman@31285
  1635
  by (metis dist_self)
chaieb@30262
  1636
huffman@31418
  1637
lemma closed_approachable:
huffman@31418
  1638
  fixes S :: "'a::metric_space set"
huffman@31418
  1639
  shows "closed S ==> (\<forall>e>0. \<exists>y\<in>S. dist y x < e) \<longleftrightarrow> x \<in> S"
chaieb@30262
  1640
  by (metis closure_closed closure_approachable)
chaieb@30262
  1641
chaieb@30262
  1642
text{* Some other lemmas about sequences. *}
chaieb@30262
  1643
huffman@31488
  1644
lemma seq_offset:
huffman@31488
  1645
  fixes l :: "'a::metric_space" (* TODO: generalize *)
huffman@31488
  1646
  shows "(f ---> l) sequentially ==> ((\<lambda>i. f( i + k)) ---> l) sequentially"
chaieb@30262
  1647
  apply (auto simp add: Lim_sequentially)
chaieb@30262
  1648
  by (metis trans_le_add1 )
chaieb@30262
  1649
huffman@31488
  1650
lemma seq_offset_neg:
huffman@31526
  1651
  "(f ---> l) sequentially ==> ((\<lambda>i. f(i - k)) ---> l) sequentially"
huffman@31526
  1652
  apply (rule topological_tendstoI)
huffman@31526
  1653
  apply (drule (2) topological_tendstoD)
huffman@31526
  1654
  apply (simp only: eventually_sequentially)
chaieb@30262
  1655
  apply (subgoal_tac "\<And>N k (n::nat). N + k <= n ==> N <= n - k")
chaieb@30262
  1656
  apply metis
chaieb@30262
  1657
  by arith
chaieb@30262
  1658
huffman@31488
  1659
lemma seq_offset_rev:
huffman@31526
  1660
  "((\<lambda>i. f(i + k)) ---> l) sequentially ==> (f ---> l) sequentially"
huffman@31526
  1661
  apply (rule topological_tendstoI)
huffman@31526
  1662
  apply (drule (2) topological_tendstoD)
huffman@31526
  1663
  apply (simp only: eventually_sequentially)
chaieb@30262
  1664
  apply (subgoal_tac "\<And>N k (n::nat). N + k <= n ==> N <= n - k \<and> (n - k) + k = n")
chaieb@30262
  1665
  by metis arith
chaieb@30262
  1666
huffman@31558
  1667
lemma seq_harmonic: "((\<lambda>n. inverse (real n)) ---> 0) sequentially"
chaieb@30262
  1668
proof-
chaieb@30262
  1669
  { fix e::real assume "e>0"
chaieb@30262
  1670
    hence "\<exists>N::nat. \<forall>n::nat\<ge>N. inverse (real n) < e"
chaieb@30262
  1671
      using real_arch_inv[of e] apply auto apply(rule_tac x=n in exI)
huffman@31558
  1672
      by (metis not_le le_imp_inverse_le not_less real_of_nat_gt_zero_cancel_iff real_of_nat_less_iff xt1(7))
chaieb@30262
  1673
  }
huffman@31558
  1674
  thus ?thesis unfolding Lim_sequentially dist_norm by simp
chaieb@30262
  1675
qed
chaieb@30262
  1676
chaieb@30262
  1677
text{* More properties of closed balls. *}
chaieb@30262
  1678
huffman@31396
  1679
lemma closed_cball: "closed (cball x e)"
huffman@31526
  1680
unfolding cball_def closed_def
huffman@31396
  1681
unfolding Collect_neg_eq [symmetric] not_le
huffman@31418
  1682
apply (clarsimp simp add: open_dist, rename_tac y)
huffman@31396
  1683
apply (rule_tac x="dist x y - e" in exI, clarsimp)
huffman@31492
  1684
apply (rename_tac x')
huffman@31396
  1685
apply (cut_tac x=x and y=x' and z=y in dist_triangle)
huffman@31396
  1686
apply simp
huffman@31396
  1687
done
huffman@30488
  1688
chaieb@30262
  1689
lemma open_contains_cball: "open S \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0.  cball x e \<subseteq> S)"
chaieb@30262
  1690
proof-
chaieb@30262
  1691
  { fix x and e::real assume "x\<in>S" "e>0" "ball x e \<subseteq> S"
chaieb@30262
  1692
    hence "\<exists>d>0. cball x d \<subseteq> S" unfolding subset_eq by (rule_tac x="e/2" in exI, auto)
chaieb@30262
  1693
  } moreover
chaieb@30262
  1694
  { fix x and e::real assume "x\<in>S" "e>0" "cball x e \<subseteq> S"
chaieb@30262
  1695
    hence "\<exists>d>0. ball x d \<subseteq> S" unfolding subset_eq apply(rule_tac x="e/2" in exI) by auto
chaieb@30262
  1696
  } ultimately
chaieb@30262
  1697
  show ?thesis unfolding open_contains_ball by auto
chaieb@30262
  1698
qed
chaieb@30262
  1699
chaieb@30262
  1700
lemma open_contains_cball_eq: "open S ==> (\<forall>x. x \<in> S \<longleftrightarrow> (\<exists>e>0. cball x e \<subseteq> S))"
chaieb@30262
  1701
  by (metis open_contains_cball subset_eq order_less_imp_le centre_in_cball mem_def)
chaieb@30262
  1702
chaieb@30262
  1703
lemma mem_interior_cball: "x \<in> interior S \<longleftrightarrow> (\<exists>e>0. cball x e \<subseteq> S)"
huffman@31345
  1704
  apply (simp add: interior_def, safe)
huffman@31345
  1705
  apply (force simp add: open_contains_cball)
huffman@31345
  1706
  apply (rule_tac x="ball x e" in exI)
huffman@31345
  1707
  apply (simp add: open_ball centre_in_ball subset_trans [OF ball_subset_cball])
huffman@31345
  1708
  done
huffman@31345
  1709
huffman@31345
  1710
lemma islimpt_ball:
huffman@31345
  1711
  fixes x y :: "'a::{real_normed_vector,perfect_space}"
huffman@31345
  1712
  shows "y islimpt ball x e \<longleftrightarrow> 0 < e \<and> y \<in> cball x e" (is "?lhs = ?rhs")
chaieb@30262
  1713
proof
chaieb@30262
  1714
  assume "?lhs"
chaieb@30262
  1715
  { assume "e \<le> 0"
chaieb@30262
  1716
    hence *:"ball x e = {}" using ball_eq_empty[of x e] by auto
huffman@30488
  1717
    have False using `?lhs` unfolding * using islimpt_EMPTY[of y] by auto
chaieb@30262
  1718
  }
huffman@31526
  1719
  hence "e > 0" by (metis not_less)
chaieb@30262
  1720
  moreover
chaieb@30262
  1721
  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
chaieb@30262
  1722
  ultimately show "?rhs" by auto
chaieb@30262
  1723
next
chaieb@30262
  1724
  assume "?rhs" hence "e>0"  by auto
chaieb@30262
  1725
  { fix d::real assume "d>0"
chaieb@30262
  1726
    have "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
chaieb@30262
  1727
    proof(cases "d \<le> dist x y")
chaieb@30262
  1728
      case True thus "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
chaieb@30262
  1729
      proof(cases "x=y")
wenzelm@32960
  1730
        case True hence False using `d \<le> dist x y` `d>0` by auto
wenzelm@32960
  1731
        thus "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d" by auto
chaieb@30262
  1732
      next
wenzelm@32960
  1733
        case False
wenzelm@32960
  1734
wenzelm@32960
  1735
        have "dist x (y - (d / (2 * dist y x)) *\<^sub>R (y - x))
wenzelm@32960
  1736
              = norm (x - y + (d / (2 * norm (y - x))) *\<^sub>R (y - x))"
wenzelm@32960
  1737
          unfolding mem_cball mem_ball dist_norm diff_diff_eq2 diff_add_eq[THEN sym] by auto
wenzelm@32960
  1738
        also have "\<dots> = \<bar>- 1 + d / (2 * norm (x - y))\<bar> * norm (x - y)"
wenzelm@32960
  1739
          using scaleR_left_distrib[of "- 1" "d / (2 * norm (y - x))", THEN sym, of "y - x"]
wenzelm@32960
  1740
          unfolding scaleR_minus_left scaleR_one
wenzelm@32960
  1741
          by (auto simp add: norm_minus_commute)
wenzelm@32960
  1742
        also have "\<dots> = \<bar>- norm (x - y) + d / 2\<bar>"
wenzelm@32960
  1743
          unfolding abs_mult_pos[of "norm (x - y)", OF norm_ge_zero[of "x - y"]]
wenzelm@32960
  1744
          unfolding real_add_mult_distrib using `x\<noteq>y`[unfolded dist_nz, unfolded dist_norm] by auto
wenzelm@32960
  1745
        also have "\<dots> \<le> e - d/2" using `d \<le> dist x y` and `d>0` and `?rhs` by(auto simp add: dist_norm)
wenzelm@32960
  1746
        finally have "y - (d / (2 * dist y x)) *\<^sub>R (y - x) \<in> ball x e" using `d>0` by auto
wenzelm@32960
  1747
wenzelm@32960
  1748
        moreover
wenzelm@32960
  1749
wenzelm@32960
  1750
        have "(d / (2*dist y x)) *\<^sub>R (y - x) \<noteq> 0"
wenzelm@32960
  1751
          using `x\<noteq>y`[unfolded dist_nz] `d>0` unfolding scaleR_eq_0_iff by (auto simp add: dist_commute)
wenzelm@32960
  1752
        moreover
wenzelm@32960
  1753
        have "dist (y - (d / (2 * dist y x)) *\<^sub>R (y - x)) y < d" unfolding dist_norm apply simp unfolding norm_minus_cancel
wenzelm@32960
  1754
          using `d>0` `x\<noteq>y`[unfolded dist_nz] dist_commute[of x y]
wenzelm@32960
  1755
          unfolding dist_norm by auto
wenzelm@32960
  1756
        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
chaieb@30262
  1757
      qed
chaieb@30262
  1758
    next
chaieb@30262
  1759
      case False hence "d > dist x y" by auto
chaieb@30262
  1760
      show "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
chaieb@30262
  1761
      proof(cases "x=y")
wenzelm@32960
  1762
        case True
wenzelm@32960
  1763
        obtain z where **: "z \<noteq> y" "dist z y < min e d"
huffman@31345
  1764
          using perfect_choose_dist[of "min e d" y]
wenzelm@32960
  1765
          using `d > 0` `e>0` by auto
wenzelm@32960
  1766
        show "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
huffman@31345
  1767
          unfolding `x = y`
huffman@31345
  1768
          using `z \<noteq> y` **
huffman@31345
  1769
          by (rule_tac x=z in bexI, auto simp add: dist_commute)
chaieb@30262
  1770
      next
wenzelm@32960
  1771
        case False thus "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
wenzelm@32960
  1772
          using `d>0` `d > dist x y` `?rhs` by(rule_tac x=x in bexI, auto)
chaieb@30262
  1773
      qed
chaieb@30262
  1774
    qed  }
chaieb@30262
  1775
  thus "?lhs" unfolding mem_cball islimpt_approachable mem_ball by auto
chaieb@30262
  1776
qed
chaieb@30262
  1777
huffman@31526
  1778
lemma closure_ball_lemma:
huffman@31526
  1779
  fixes x y :: "'a::real_normed_vector"
huffman@31526
  1780
  assumes "x \<noteq> y" shows "y islimpt ball x (dist x y)"
huffman@31526
  1781
proof (rule islimptI)
huffman@31526
  1782
  fix T assume "y \<in> T" "open T"
huffman@31526
  1783
  then obtain r where "0 < r" "\<forall>z. dist z y < r \<longrightarrow> z \<in> T"
huffman@31526
  1784
    unfolding open_dist by fast
huffman@31526
  1785
  (* choose point between x and y, within distance r of y. *)
huffman@31526
  1786
  def k \<equiv> "min 1 (r / (2 * dist x y))"
huffman@31526
  1787
  def z \<equiv> "y + scaleR k (x - y)"
huffman@31526
  1788
  have z_def2: "z = x + scaleR (1 - k) (y - x)"
huffman@31526
  1789
    unfolding z_def by (simp add: algebra_simps)
huffman@31526
  1790
  have "dist z y < r"
huffman@31526
  1791
    unfolding z_def k_def using `0 < r`
huffman@31587
  1792
    by (simp add: dist_norm min_def)
huffman@31526
  1793
  hence "z \<in> T" using `\<forall>z. dist z y < r \<longrightarrow> z \<in> T` by simp
huffman@31526
  1794
  have "dist x z < dist x y"
huffman@31526
  1795
    unfolding z_def2 dist_norm
huffman@31587
  1796
    apply (simp add: norm_minus_commute)
huffman@31526
  1797
    apply (simp only: dist_norm [symmetric])
huffman@31526
  1798
    apply (subgoal_tac "\<bar>1 - k\<bar> * dist x y < 1 * dist x y", simp)
huffman@31526
  1799
    apply (rule mult_strict_right_mono)
huffman@31526
  1800
    apply (simp add: k_def divide_pos_pos zero_less_dist_iff `0 < r` `x \<noteq> y`)
huffman@31526
  1801
    apply (simp add: zero_less_dist_iff `x \<noteq> y`)
huffman@31526
  1802
    done
huffman@31526
  1803
  hence "z \<in> ball x (dist x y)" by simp
huffman@31526
  1804
  have "z \<noteq> y"
huffman@31526
  1805
    unfolding z_def k_def using `x \<noteq> y` `0 < r`
huffman@31526
  1806
    by (simp add: min_def)
huffman@31526
  1807
  show "\<exists>z\<in>ball x (dist x y). z \<in> T \<and> z \<noteq> y"
huffman@31526
  1808
    using `z \<in> ball x (dist x y)` `z \<in> T` `z \<noteq> y`
huffman@31526
  1809
    by fast
huffman@31526
  1810
qed
huffman@31526
  1811
huffman@31345
  1812
lemma closure_ball:
huffman@31526
  1813
  fixes x :: "'a::real_normed_vector"
huffman@31526
  1814
  shows "0 < e \<Longrightarrow> closure (ball x e) = cball x e"
huffman@31526
  1815
apply (rule equalityI)
huffman@31526
  1816
apply (rule closure_minimal)
huffman@31526
  1817
apply (rule ball_subset_cball)
huffman@31526
  1818
apply (rule closed_cball)
huffman@31526
  1819
apply (rule subsetI, rename_tac y)
huffman@31526
  1820
apply (simp add: le_less [where 'a=real])
huffman@31526
  1821
apply (erule disjE)
huffman@31526
  1822
apply (rule subsetD [OF closure_subset], simp)
huffman@31526
  1823
apply (simp add: closure_def)
huffman@31526
  1824
apply clarify
huffman@31526
  1825
apply (rule closure_ball_lemma)
huffman@31526
  1826
apply (simp add: zero_less_dist_iff)
huffman@31526
  1827
done
chaieb@30262
  1828
huffman@31569
  1829
(* In a trivial vector space, this fails for e = 0. *)
huffman@31345
  1830
lemma interior_cball:
huffman@31569
  1831
  fixes x :: "'a::{real_normed_vector, perfect_space}"
huffman@31569
  1832
  shows "interior (cball x e) = ball x e"
chaieb@30262
  1833
proof(cases "e\<ge>0")
chaieb@30262
  1834
  case False note cs = this
chaieb@30262
  1835
  from cs have "ball x e = {}" using ball_empty[of e x] by auto moreover
chaieb@30262
  1836
  { fix y assume "y \<in> cball x e"
huffman@31285
  1837
    hence False unfolding mem_cball using dist_nz[of x y] cs by auto  }
chaieb@30262
  1838
  hence "cball x e = {}" by auto
chaieb@30262
  1839
  hence "interior (cball x e) = {}" using interior_empty by auto
huffman@30488
  1840
  ultimately show ?thesis by blast
chaieb@30262
  1841
next
chaieb@30262
  1842
  case True note cs = this
chaieb@30262
  1843
  have "ball x e \<subseteq> cball x e" using ball_subset_cball by auto moreover
chaieb@30262
  1844
  { fix S y assume as: "S \<subseteq> cball x e" "open S" "y\<in>S"
huffman@31418
  1845
    then obtain d where "d>0" and d:"\<forall>x'. dist x' y < d \<longrightarrow> x' \<in> S" unfolding open_dist by blast
huffman@30488
  1846
huffman@31569
  1847
    then obtain xa where xa_y: "xa \<noteq> y" and xa: "dist xa y < d"
huffman@31569
  1848
      using perfect_choose_dist [of d] by auto
huffman@31569
  1849
    have "xa\<in>S" using d[THEN spec[where x=xa]] using xa by(auto simp add: dist_commute)
chaieb@30262
  1850
    hence xa_cball:"xa \<in> cball x e" using as(1) by auto
chaieb@30262
  1851
chaieb@30262
  1852
    hence "y \<in> ball x e" proof(cases "x = y")
chaieb@30262
  1853
      case True
huffman@31285
  1854
      hence "e>0" using xa_y[unfolded dist_nz] xa_cball[unfolded mem_cball] by (auto simp add: dist_commute)
chaieb@30262
  1855
      thus "y \<in> ball x e" using `x = y ` by simp
chaieb@30262
  1856
    next
chaieb@30262
  1857
      case False
huffman@31569
  1858
      have "dist (y + (d / 2 / dist y x) *\<^sub>R (y - x)) y < d" unfolding dist_norm
wenzelm@32960
  1859
        using `d>0` norm_ge_zero[of "y - x"] `x \<noteq> y` by auto
huffman@31569
  1860
      hence *:"y + (d / 2 / dist y x) *\<^sub>R (y - x) \<in> cball x e" using d as(1)[unfolded subset_eq] by blast
chaieb@30262
  1861
      have "y - x \<noteq> 0" using `x \<noteq> y` by auto
chaieb@30262
  1862
      hence **:"d / (2 * norm (y - x)) > 0" unfolding zero_less_norm_iff[THEN sym]
wenzelm@32960
  1863
        using `d>0` divide_pos_pos[of d "2*norm (y - x)"] by auto
chaieb@30262
  1864
huffman@31569
  1865
      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)"
huffman@31569
  1866
        by (auto simp add: dist_norm algebra_simps)
huffman@31569
  1867
      also have "\<dots> = norm ((1 + d / (2 * norm (y - x))) *\<^sub>R (y - x))"
huffman@31569
  1868
        by (auto simp add: algebra_simps)
huffman@31569
  1869
      also have "\<dots> = \<bar>1 + d / (2 * norm (y - x))\<bar> * norm (y - x)"
huffman@31587
  1870
        using ** by auto
huffman@31289
  1871
      also have "\<dots> = (dist y x) + d/2"using ** by (auto simp add: left_distrib dist_norm)
huffman@31285
  1872
      finally have "e \<ge> dist x y +d/2" using *[unfolded mem_cball] by (auto simp add: dist_commute)
chaieb@30262
  1873
      thus "y \<in> ball x e" unfolding mem_ball using `d>0` by auto
chaieb@30262
  1874
    qed  }
chaieb@30262
  1875
  hence "\<forall>S \<subseteq> cball x e. open S \<longrightarrow> S \<subseteq> ball x e" by auto
chaieb@30262
  1876
  ultimately show ?thesis using interior_unique[of "ball x e" "cball x e"] using open_ball[of x e] by auto
huffman@30488
  1877
qed
chaieb@30262
  1878
huffman@31345
  1879
lemma frontier_ball:
huffman@31569
  1880
  fixes a :: "'a::real_normed_vector"
huffman@31345
  1881
  shows "0 < e ==> frontier(ball a e) = {x. dist a x = e}"
huffman@30488
  1882
  apply (simp add: frontier_def closure_ball interior_open open_ball order_less_imp_le)
chaieb@30262
  1883
  apply (simp add: expand_set_eq)
chaieb@30262
  1884
  by arith
chaieb@30262
  1885
huffman@31345
  1886
lemma frontier_cball:
huffman@31569
  1887
  fixes a :: "'a::{real_normed_vector, perfect_space}"
huffman@31345
  1888
  shows "frontier(cball a e) = {x. dist a x = e}"
chaieb@30262
  1889
  apply (simp add: frontier_def interior_cball closed_cball closure_closed order_less_imp_le)
chaieb@30262
  1890
  apply (simp add: expand_set_eq)
chaieb@30262
  1891
  by arith
chaieb@30262
  1892
chaieb@30262
  1893
lemma cball_eq_empty: "(cball x e = {}) \<longleftrightarrow> e < 0"
chaieb@30262
  1894
  apply (simp add: expand_set_eq not_le)
huffman@31285
  1895
  by (metis zero_le_dist dist_self order_less_le_trans)
chaieb@30262
  1896
lemma cball_empty: "e < 0 ==> cball x e = {}" by (simp add: cball_eq_empty)
chaieb@30262
  1897
huffman@31345
  1898
lemma cball_eq_sing:
huffman@31569
  1899
  fixes x :: "'a::perfect_space"
huffman@31345
  1900
  shows "(cball x e = {x}) \<longleftrightarrow> e = 0"
huffman@31569
  1901
proof (rule linorder_cases)
huffman@31569
  1902
  assume e: "0 < e"
huffman@31569
  1903
  obtain a where "a \<noteq> x" "dist a x < e"
huffman@31569
  1904
    using perfect_choose_dist [OF e] by auto
huffman@31569
  1905
  hence "a \<noteq> x" "dist x a \<le> e" by (auto simp add: dist_commute)
huffman@31569
  1906
  with e show ?thesis by (auto simp add: expand_set_eq)
huffman@31569
  1907
qed auto
chaieb@30262
  1908
huffman@31345
  1909
lemma cball_sing:
huffman@31569
  1910
  fixes x :: "'a::metric_space"
huffman@31569
  1911
  shows "e = 0 ==> cball x e = {x}"
huffman@31569
  1912
  by (auto simp add: expand_set_eq)
chaieb@30262
  1913
chaieb@30262
  1914
text{* For points in the interior, localization of limits makes no difference.   *}
chaieb@30262
  1915
huffman@31447
  1916
lemma eventually_within_interior:
huffman@31447
  1917
  assumes "x \<in> interior S"
chaieb@30262
  1918
  shows "eventually P (at x within S) \<longleftrightarrow> eventually P (at x)" (is "?lhs = ?rhs")
chaieb@30262
  1919
proof-
huffman@31527
  1920
  from assms obtain T where T: "open T" "x \<in> T" "T \<subseteq> S"
huffman@31527
  1921
    unfolding interior_def by fast
huffman@31527
  1922
  { assume "?lhs"
huffman@31527
  1923
    then obtain A where "open A" "x \<in> A" "\<forall>y\<in>A. y \<noteq> x \<longrightarrow> y \<in> S \<longrightarrow> P y"
huffman@31527
  1924
      unfolding Limits.eventually_within Limits.eventually_at_topological
huffman@31527
  1925
      by auto
huffman@31527
  1926
    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@31527
  1927
      by auto
huffman@31527
  1928
    then have "?rhs"
huffman@31527
  1929
      unfolding Limits.eventually_at_topological by auto
chaieb@30262
  1930
  } moreover
huffman@31527
  1931
  { assume "?rhs" hence "?lhs"
huffman@31527
  1932
      unfolding Limits.eventually_within
huffman@31527
  1933
      by (auto elim: eventually_elim1)
chaieb@30262
  1934
  } ultimately
huffman@31527
  1935
  show "?thesis" ..
chaieb@30262
  1936
qed
chaieb@30262
  1937
huffman@31447
  1938
lemma lim_within_interior:
huffman@31527
  1939
  "x \<in> interior S \<Longrightarrow> (f ---> l) (at x within S) \<longleftrightarrow> (f ---> l) (at x)"
huffman@31527
  1940
  unfolding tendsto_def by (simp add: eventually_within_interior)
chaieb@30262
  1941
huffman@31346
  1942
lemma netlimit_within_interior:
huffman@31346
  1943
  fixes x :: "'a::{perfect_space, real_normed_vector}"
huffman@31346
  1944
    (* FIXME: generalize to perfect_space *)
huffman@31346
  1945
  assumes "x \<in> interior S"
chaieb@30262
  1946
  shows "netlimit(at x within S) = x" (is "?lhs = ?rhs")
chaieb@30262
  1947
proof-
chaieb@30262
  1948
  from assms obtain e::real where e:"e>0" "ball x e \<subseteq> S" using open_interior[of S] unfolding open_contains_ball using interior_subset[of S] by auto
chaieb@30262
  1949
  hence "\<not> trivial_limit (at x within S)" using islimpt_subset[of x "ball x e" S] unfolding trivial_limit_within islimpt_ball centre_in_cball by auto
chaieb@30262
  1950
  thus ?thesis using netlimit_within by auto
chaieb@30262
  1951
qed
chaieb@30262
  1952
chaieb@30262
  1953
subsection{* Boundedness. *}
chaieb@30262
  1954
chaieb@30262
  1955
  (* FIXME: This has to be unified with BSEQ!! *)
huffman@31400
  1956
definition
huffman@31533
  1957
  bounded :: "'a::metric_space set \<Rightarrow> bool" where
huffman@31533
  1958
  "bounded S \<longleftrightarrow> (\<exists>x e. \<forall>y\<in>S. dist x y \<le> e)"
huffman@31533
  1959
huffman@31533
  1960
lemma bounded_any_center: "bounded S \<longleftrightarrow> (\<exists>e. \<forall>y\<in>S. dist a y \<le> e)"
huffman@31533
  1961
unfolding bounded_def
huffman@31533
  1962
apply safe
huffman@31533
  1963
apply (rule_tac x="dist a x + e" in exI, clarify)
huffman@31533
  1964
apply (drule (1) bspec)
huffman@31533
  1965
apply (erule order_trans [OF dist_triangle add_left_mono])
huffman@31533
  1966
apply auto
huffman@31533
  1967
done
huffman@31533
  1968
huffman@31533
  1969
lemma bounded_iff: "bounded S \<longleftrightarrow> (\<exists>a. \<forall>x\<in>S. norm x \<le> a)"
huffman@31533
  1970
unfolding bounded_any_center [where a=0]
huffman@31533
  1971
by (simp add: dist_norm)
chaieb@30262
  1972
chaieb@30262
  1973
lemma bounded_empty[simp]: "bounded {}" by (simp add: bounded_def)
chaieb@30262
  1974
lemma bounded_subset: "bounded T \<Longrightarrow> S \<subseteq> T ==> bounded S"
chaieb@30262
  1975
  by (metis bounded_def subset_eq)
chaieb@30262
  1976
chaieb@30262
  1977
lemma bounded_interior[intro]: "bounded S ==> bounded(interior S)"
chaieb@30262
  1978
  by (metis bounded_subset interior_subset)
chaieb@30262
  1979
chaieb@30262
  1980
lemma bounded_closure[intro]: assumes "bounded S" shows "bounded(closure S)"
chaieb@30262
  1981
proof-
huffman@31533
  1982
  from assms obtain x and a where a: "\<forall>y\<in>S. dist x y \<le> a" unfolding bounded_def by auto
huffman@31533
  1983
  { fix y assume "y \<in> closure S"
huffman@31533
  1984
    then obtain f where f: "\<forall>n. f n \<in> S"  "(f ---> y) sequentially"
huffman@31533
  1985
      unfolding closure_sequential by auto
huffman@31533
  1986
    have "\<forall>n. f n \<in> S \<longrightarrow> dist x (f n) \<le> a" using a by simp
huffman@31533
  1987
    hence "eventually (\<lambda>n. dist x (f n) \<le> a) sequentially"
huffman@31533
  1988
      by (rule eventually_mono, simp add: f(1))
huffman@31533
  1989
    have "dist x y \<le> a"
huffman@31533
  1990
      apply (rule Lim_dist_ubound [of sequentially f])
huffman@31347
  1991
      apply (rule trivial_limit_sequentially)
huffman@31533
  1992
      apply (rule f(2))
huffman@31347
  1993
      apply fact
huffman@31347
  1994
      done
chaieb@30262
  1995
  }
chaieb@30262
  1996
  thus ?thesis unfolding bounded_def by auto
chaieb@30262
  1997
qed
chaieb@30262
  1998
chaieb@30262
  1999
lemma bounded_cball[simp,intro]: "bounded (cball x e)"
chaieb@30262
  2000
  apply (simp add: bounded_def)
huffman@31533
  2001
  apply (rule_tac x=x in exI)
huffman@31533
  2002
  apply (rule_tac x=e in exI)
huffman@31533
  2003
  apply auto
huffman@31400
  2004
  done
chaieb@30262
  2005
chaieb@30262
  2006
lemma bounded_ball[simp,intro]: "bounded(ball x e)"
chaieb@30262
  2007
  by (metis ball_subset_cball bounded_cball bounded_subset)
chaieb@30262
  2008
chaieb@30262
  2009
lemma finite_imp_bounded[intro]: assumes "finite S" shows "bounded S"
chaieb@30262
  2010
proof-
huffman@31533
  2011
  { fix a F assume as:"bounded F"
huffman@31533
  2012
    then obtain x e where "\<forall>y\<in>F. dist x y \<le> e" unfolding bounded_def by auto
huffman@31533
  2013
    hence "\<forall>y\<in>(insert a F). dist x y \<le> max e (dist x a)" by auto
huffman@31533
  2014
    hence "bounded (insert a F)" unfolding bounded_def by (intro exI)
chaieb@30262
  2015
  }
chaieb@30262
  2016
  thus ?thesis using finite_induct[of S bounded]  using bounded_empty assms by auto
huffman@30488
  2017
qed
chaieb@30262
  2018
chaieb@30262
  2019
lemma bounded_Un[simp]: "bounded (S \<union> T) \<longleftrightarrow> bounded S \<and> bounded T"
chaieb@30262
  2020
  apply (auto simp add: bounded_def)
huffman@31533
  2021
  apply (rename_tac x y r s)
huffman@31533
  2022
  apply (rule_tac x=x in exI)
huffman@31533
  2023
  apply (rule_tac x="max r (dist x y + s)" in exI)
huffman@31533
  2024
  apply (rule ballI, rename_tac z, safe)
huffman@31533
  2025
  apply (drule (1) bspec, simp)
huffman@31533
  2026
  apply (drule (1) bspec)
huffman@31533
  2027
  apply (rule min_max.le_supI2)
huffman@31533
  2028
  apply (erule order_trans [OF dist_triangle add_left_mono])
huffman@31533
  2029
  done
chaieb@30262
  2030
huffman@30488
  2031
lemma bounded_Union[intro]: "finite F \<Longrightarrow> (\<forall>S\<in>F. bounded S) \<Longrightarrow> bounded(\<Union>F)"
chaieb@30262
  2032
  by (induct rule: finite_induct[of F], auto)
chaieb@30262
  2033
chaieb@30262
  2034
lemma bounded_pos: "bounded S \<longleftrightarrow> (\<exists>b>0. \<forall>x\<in> S. norm x <= b)"
huffman@31533
  2035
  apply (simp add: bounded_iff)
chaieb@30262
  2036
  apply (subgoal_tac "\<And>x (y::real). 0 < 1 + abs y \<and> (x <= y \<longrightarrow> x <= 1 + abs y)")
chaieb@30262
  2037
  by metis arith
chaieb@30262
  2038
chaieb@30262
  2039
lemma bounded_Int[intro]: "bounded S \<or> bounded T \<Longrightarrow> bounded (S \<inter> T)"
chaieb@30262
  2040
  by (metis Int_lower1 Int_lower2 bounded_subset)
chaieb@30262
  2041
chaieb@30262
  2042
lemma bounded_diff[intro]: "bounded S ==> bounded (S - T)"
chaieb@30262
  2043
apply (metis Diff_subset bounded_subset)
chaieb@30262
  2044
done
chaieb@30262
  2045
chaieb@30262
  2046
lemma bounded_insert[intro]:"bounded(insert x S) \<longleftrightarrow> bounded S"
chaieb@30262
  2047
  by (metis Diff_cancel Un_empty_right Un_insert_right bounded_Un bounded_subset finite.emptyI finite_imp_bounded infinite_remove subset_insertI)
chaieb@30262
  2048
huffman@31531
  2049
lemma not_bounded_UNIV[simp, intro]:
huffman@31531
  2050
  "\<not> bounded (UNIV :: 'a::{real_normed_vector, perfect_space} set)"
chaieb@30262
  2051
proof(auto simp add: bounded_pos not_le)
huffman@31531
  2052
  obtain x :: 'a where "x \<noteq> 0"
huffman@31531
  2053
    using perfect_choose_dist [OF zero_less_one] by fast
chaieb@30262
  2054
  fix b::real  assume b: "b >0"
chaieb@30262
  2055
  have b1: "b +1 \<ge> 0" using b by simp
huffman@31531
  2056
  with `x \<noteq> 0` have "b < norm (scaleR (b + 1) (sgn x))"
huffman@31587
  2057
    by (simp add: norm_sgn)
huffman@31531
  2058
  then show "\<exists>x::'a. b < norm x" ..
chaieb@30262
  2059
qed
chaieb@30262
  2060
huffman@30488
  2061
lemma bounded_linear_image:
huffman@31657
  2062
  assumes "bounded S" "bounded_linear f"
chaieb@30262
  2063
  shows "bounded(f ` S)"
chaieb@30262
  2064
proof-
chaieb@30262
  2065
  from assms(1) obtain b where b:"b>0" "\<forall>x\<in>S. norm x \<le> b" unfolding bounded_pos by auto
huffman@31657
  2066
  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)
chaieb@30262
  2067
  { fix x assume "x\<in>S"
chaieb@30262
  2068
    hence "norm x \<le> b" using b by auto
chaieb@30262
  2069
    hence "norm (f x) \<le> B * b" using B(2) apply(erule_tac x=x in allE)
chaieb@30262
  2070
      by (metis B(1) B(2) real_le_trans real_mult_le_cancel_iff2)
chaieb@30262
  2071
  }
chaieb@30262
  2072
  thus ?thesis unfolding bounded_pos apply(rule_tac x="b*B" in exI)
chaieb@30262
  2073
    using b B real_mult_order[of b B] by (auto simp add: real_mult_commute)
chaieb@30262
  2074
qed
chaieb@30262
  2075
huffman@31400
  2076
lemma bounded_scaling:
huffman@31658
  2077
  fixes S :: "'a::real_normed_vector set"
huffman@31585
  2078
  shows "bounded S \<Longrightarrow> bounded ((\<lambda>x. c *\<^sub>R x) ` S)"
chaieb@30262
  2079
  apply (rule bounded_linear_image, assumption)
huffman@31585
  2080
  apply (rule scaleR.bounded_linear_right)
huffman@31585
  2081
  done
chaieb@30262
  2082
huffman@31533
  2083
lemma bounded_translation:
huffman@31533
  2084
  fixes S :: "'a::real_normed_vector set"
huffman@31533
  2085
  assumes "bounded S" shows "bounded ((\<lambda>x. a + x) ` S)"
chaieb@30262
  2086
proof-
chaieb@30262
  2087
  from assms obtain b where b:"b>0" "\<forall>x\<in>S. norm x \<le> b" unfolding bounded_pos by auto
chaieb@30262
  2088
  { fix x assume "x\<in>S"
chaieb@30262
  2089
    hence "norm (a + x) \<le> b + norm a" using norm_triangle_ineq[of a x] b by auto
chaieb@30262
  2090
  }
huffman@30488
  2091
  thus ?thesis unfolding bounded_pos using norm_ge_zero[of a] b(1) using add_strict_increasing[of b 0 "norm a"]
chaieb@30262
  2092
    by (auto intro!: add exI[of _ "b + norm a"])
chaieb@30262
  2093
qed
chaieb@30262
  2094
chaieb@30262
  2095
chaieb@30262
  2096
text{* Some theorems on sups and infs using the notion "bounded". *}
chaieb@30262
  2097
huffman@31558
  2098
lemma bounded_real:
huffman@31400
  2099
  fixes S :: "real set"
huffman@31558
  2100
  shows "bounded S \<longleftrightarrow>  (\<exists>a. \<forall>x\<in>S. abs x <= a)"
huffman@31558
  2101
  by (simp add: bounded_iff)
huffman@31558
  2102
paulson@33269
  2103
lemma bounded_has_Sup:
paulson@33269
  2104
  fixes S :: "real set"
paulson@33269
  2105
  assumes "bounded S" "S \<noteq> {}"
paulson@33269
  2106
  shows "\<forall>x\<in>S. x <= Sup S" and "\<forall>b. (\<forall>x\<in>S. x <= b) \<longrightarrow> Sup S <= b"
paulson@33269
  2107
proof
paulson@33269
  2108
  fix x assume "x\<in>S"
paulson@33269
  2109
  thus "x \<le> Sup S"
paulson@33269
  2110
    by (metis SupInf.Sup_upper abs_le_D1 assms(1) bounded_real)
paulson@33269
  2111
next
paulson@33269
  2112
  show "\<forall>b. (\<forall>x\<in>S. x \<le> b) \<longrightarrow> Sup S \<le> b" using assms
paulson@33269
  2113
    by (metis SupInf.Sup_least)
paulson@33269
  2114
qed
paulson@33269
  2115
paulson@33269
  2116
lemma Sup_insert:
paulson@33269
  2117
  fixes S :: "real set"
paulson@33269
  2118
  shows "bounded S ==> Sup(insert x S) = (if S = {} then x else max x (Sup S))" 
paulson@33269
  2119
by auto (metis Int_absorb Sup_insert_nonempty assms bounded_has_Sup(1) disjoint_iff_not_equal) 
paulson@33269
  2120
paulson@33269
  2121
lemma Sup_insert_finite:
paulson@33269
  2122
  fixes S :: "real set"
paulson@33269
  2123
  shows "finite S \<Longrightarrow> Sup(insert x S) = (if S = {} then x else max x (Sup S))"
paulson@33269
  2124
  apply (rule Sup_insert)
paulson@33269
  2125
  apply (rule finite_imp_bounded)
paulson@33269
  2126
  by simp
paulson@33269
  2127
paulson@33269
  2128
lemma bounded_has_Inf:
paulson@33269
  2129
  fixes S :: "real set"
paulson@33269
  2130
  assumes "bounded S"  "S \<noteq> {}"
paulson@33269
  2131
  shows "\<forall>x\<in>S. x >= Inf S" and "\<forall>b. (\<forall>x\<in>S. x >= b) \<longrightarrow> Inf S >= b"
chaieb@30262
  2132
proof
chaieb@30262
  2133
  fix x assume "x\<in>S"
huffman@31558
  2134
  from assms(1) obtain a where a:"\<forall>x\<in>S. \<bar>x\<bar> \<le> a" unfolding bounded_real by auto
paulson@33269
  2135
  thus "x \<ge> Inf S" using `x\<in>S`
paulson@33269
  2136
    by (metis Inf_lower_EX abs_le_D2 minus_le_iff)
chaieb@30262
  2137
next
paulson@33269
  2138
  show "\<forall>b. (\<forall>x\<in>S. x >= b) \<longrightarrow> Inf S \<ge> b" using assms
paulson@33269
  2139
    by (metis SupInf.Inf_greatest)
paulson@33269
  2140
qed
paulson@33269
  2141
paulson@33269
  2142
lemma Inf_insert:
paulson@33269
  2143
  fixes S :: "real set"
paulson@33269
  2144
  shows "bounded S ==> Inf(insert x S) = (if S = {} then x else min x (Inf S))" 
paulson@33269
  2145
by auto (metis Int_absorb Inf_insert_nonempty bounded_has_Inf(1) disjoint_iff_not_equal) 
paulson@33269
  2146
lemma Inf_insert_finite:
paulson@33269
  2147
  fixes S :: "real set"
paulson@33269
  2148
  shows "finite S ==> Inf(insert x S) = (if S = {} then x else min x (Inf S))"
paulson@33269
  2149
  by (rule Inf_insert, rule finite_imp_bounded, simp)
paulson@33269
  2150
chaieb@30262
  2151
chaieb@30262
  2152
(* TODO: Move this to RComplete.thy -- would need to include Glb into RComplete *)
chaieb@30262
  2153
lemma real_isGlb_unique: "[| isGlb R S x; isGlb R S y |] ==> x = (y::real)"
chaieb@30262
  2154
  apply (frule isGlb_isLb)
chaieb@30262
  2155
  apply (frule_tac x = y in isGlb_isLb)
chaieb@30262
  2156
  apply (blast intro!: order_antisym dest!: isGlb_le_isLb)
chaieb@30262
  2157
  done
chaieb@30262
  2158
chaieb@30262
  2159
subsection{* Compactness (the definition is the one based on convegent subsequences). *}
chaieb@30262
  2160
huffman@31488
  2161
definition
huffman@31488
  2162
  compact :: "'a::metric_space set \<Rightarrow> bool" where (* TODO: generalize *)
huffman@31488
  2163
  "compact S \<longleftrightarrow>
huffman@31559
  2164
   (\<forall>f. (\<forall>n. f n \<in> S) \<longrightarrow>
huffman@31559
  2165
       (\<exists>l\<in>S. \<exists>r. subseq r \<and> ((f o r) ---> l) sequentially))"
chaieb@30262
  2166
huffman@31536
  2167
text {*
huffman@31536
  2168
  A metric space (or topological vector space) is said to have the
huffman@31536
  2169
  Heine-Borel property if every closed and bounded subset is compact.
huffman@31536
  2170
*}
huffman@31536
  2171
huffman@31536
  2172
class heine_borel =
huffman@31536
  2173
  assumes bounded_imp_convergent_subsequence:
huffman@31559
  2174
    "bounded s \<Longrightarrow> \<forall>n. f n \<in> s
huffman@31559
  2175
      \<Longrightarrow> \<exists>l r. subseq r \<and> ((f \<circ> r) ---> l) sequentially"
huffman@31536
  2176
huffman@31536
  2177
lemma bounded_closed_imp_compact:
huffman@31536
  2178
  fixes s::"'a::heine_borel set"
huffman@31536
  2179
  assumes "bounded s" and "closed s" shows "compact s"
huffman@31536
  2180
proof (unfold compact_def, clarify)
huffman@31536
  2181
  fix f :: "nat \<Rightarrow> 'a" assume f: "\<forall>n. f n \<in> s"
huffman@31559
  2182
  obtain l r where r: "subseq r" and l: "((f \<circ> r) ---> l) sequentially"
huffman@31536
  2183
    using bounded_imp_convergent_subsequence [OF `bounded s` `\<forall>n. f n \<in> s`] by auto
huffman@31536
  2184
  from f have fr: "\<forall>n. (f \<circ> r) n \<in> s" by simp