src/HOL/Topological_Spaces.thy
author wenzelm
Tue Oct 06 17:46:07 2015 +0200 (2015-10-06)
changeset 61342 b98cd131e2b5
parent 61306 9dd394c866fc
child 61426 d53db136e8fd
permissions -rw-r--r--
isabelle update_cartouches;
wenzelm@52265
     1
(*  Title:      HOL/Topological_Spaces.thy
hoelzl@51471
     2
    Author:     Brian Huffman
hoelzl@51471
     3
    Author:     Johannes Hölzl
hoelzl@51471
     4
*)
hoelzl@51471
     5
wenzelm@60758
     6
section \<open>Topological Spaces\<close>
hoelzl@51471
     7
hoelzl@51471
     8
theory Topological_Spaces
hoelzl@51773
     9
imports Main Conditionally_Complete_Lattices
hoelzl@51471
    10
begin
hoelzl@51471
    11
wenzelm@57953
    12
named_theorems continuous_intros "structural introduction rules for continuity"
wenzelm@57953
    13
hoelzl@56371
    14
wenzelm@60758
    15
subsection \<open>Topological space\<close>
hoelzl@51471
    16
hoelzl@51471
    17
class "open" =
hoelzl@51471
    18
  fixes "open" :: "'a set \<Rightarrow> bool"
hoelzl@51471
    19
hoelzl@51471
    20
class topological_space = "open" +
hoelzl@51471
    21
  assumes open_UNIV [simp, intro]: "open UNIV"
hoelzl@51471
    22
  assumes open_Int [intro]: "open S \<Longrightarrow> open T \<Longrightarrow> open (S \<inter> T)"
wenzelm@60585
    23
  assumes open_Union [intro]: "\<forall>S\<in>K. open S \<Longrightarrow> open (\<Union>K)"
hoelzl@51471
    24
begin
hoelzl@51471
    25
hoelzl@51471
    26
definition
hoelzl@51471
    27
  closed :: "'a set \<Rightarrow> bool" where
hoelzl@51471
    28
  "closed S \<longleftrightarrow> open (- S)"
hoelzl@51471
    29
hoelzl@56371
    30
lemma open_empty [continuous_intros, intro, simp]: "open {}"
hoelzl@51471
    31
  using open_Union [of "{}"] by simp
hoelzl@51471
    32
hoelzl@56371
    33
lemma open_Un [continuous_intros, intro]: "open S \<Longrightarrow> open T \<Longrightarrow> open (S \<union> T)"
hoelzl@51471
    34
  using open_Union [of "{S, T}"] by simp
hoelzl@51471
    35
hoelzl@56371
    36
lemma open_UN [continuous_intros, intro]: "\<forall>x\<in>A. open (B x) \<Longrightarrow> open (\<Union>x\<in>A. B x)"
haftmann@56166
    37
  using open_Union [of "B ` A"] by simp
hoelzl@51471
    38
hoelzl@56371
    39
lemma open_Inter [continuous_intros, intro]: "finite S \<Longrightarrow> \<forall>T\<in>S. open T \<Longrightarrow> open (\<Inter>S)"
hoelzl@51471
    40
  by (induct set: finite) auto
hoelzl@51471
    41
hoelzl@56371
    42
lemma open_INT [continuous_intros, intro]: "finite A \<Longrightarrow> \<forall>x\<in>A. open (B x) \<Longrightarrow> open (\<Inter>x\<in>A. B x)"
haftmann@56166
    43
  using open_Inter [of "B ` A"] by simp
hoelzl@51471
    44
hoelzl@51478
    45
lemma openI:
hoelzl@51478
    46
  assumes "\<And>x. x \<in> S \<Longrightarrow> \<exists>T. open T \<and> x \<in> T \<and> T \<subseteq> S"
hoelzl@51478
    47
  shows "open S"
hoelzl@51478
    48
proof -
hoelzl@51478
    49
  have "open (\<Union>{T. open T \<and> T \<subseteq> S})" by auto
hoelzl@51478
    50
  moreover have "\<Union>{T. open T \<and> T \<subseteq> S} = S" by (auto dest!: assms)
hoelzl@51478
    51
  ultimately show "open S" by simp
hoelzl@51478
    52
qed
hoelzl@51478
    53
hoelzl@56371
    54
lemma closed_empty [continuous_intros, intro, simp]:  "closed {}"
hoelzl@51471
    55
  unfolding closed_def by simp
hoelzl@51471
    56
hoelzl@56371
    57
lemma closed_Un [continuous_intros, intro]: "closed S \<Longrightarrow> closed T \<Longrightarrow> closed (S \<union> T)"
hoelzl@51471
    58
  unfolding closed_def by auto
hoelzl@51471
    59
hoelzl@56371
    60
lemma closed_UNIV [continuous_intros, intro, simp]: "closed UNIV"
hoelzl@51471
    61
  unfolding closed_def by simp
hoelzl@51471
    62
hoelzl@56371
    63
lemma closed_Int [continuous_intros, intro]: "closed S \<Longrightarrow> closed T \<Longrightarrow> closed (S \<inter> T)"
hoelzl@51471
    64
  unfolding closed_def by auto
hoelzl@51471
    65
hoelzl@56371
    66
lemma closed_INT [continuous_intros, intro]: "\<forall>x\<in>A. closed (B x) \<Longrightarrow> closed (\<Inter>x\<in>A. B x)"
hoelzl@51471
    67
  unfolding closed_def by auto
hoelzl@51471
    68
wenzelm@60585
    69
lemma closed_Inter [continuous_intros, intro]: "\<forall>S\<in>K. closed S \<Longrightarrow> closed (\<Inter>K)"
hoelzl@51471
    70
  unfolding closed_def uminus_Inf by auto
hoelzl@51471
    71
hoelzl@56371
    72
lemma closed_Union [continuous_intros, intro]: "finite S \<Longrightarrow> \<forall>T\<in>S. closed T \<Longrightarrow> closed (\<Union>S)"
hoelzl@51471
    73
  by (induct set: finite) auto
hoelzl@51471
    74
hoelzl@56371
    75
lemma closed_UN [continuous_intros, intro]: "finite A \<Longrightarrow> \<forall>x\<in>A. closed (B x) \<Longrightarrow> closed (\<Union>x\<in>A. B x)"
haftmann@56166
    76
  using closed_Union [of "B ` A"] by simp
hoelzl@51471
    77
hoelzl@51471
    78
lemma open_closed: "open S \<longleftrightarrow> closed (- S)"
hoelzl@51471
    79
  unfolding closed_def by simp
hoelzl@51471
    80
hoelzl@51471
    81
lemma closed_open: "closed S \<longleftrightarrow> open (- S)"
hoelzl@51471
    82
  unfolding closed_def by simp
hoelzl@51471
    83
hoelzl@56371
    84
lemma open_Diff [continuous_intros, intro]: "open S \<Longrightarrow> closed T \<Longrightarrow> open (S - T)"
hoelzl@51471
    85
  unfolding closed_open Diff_eq by (rule open_Int)
hoelzl@51471
    86
hoelzl@56371
    87
lemma closed_Diff [continuous_intros, intro]: "closed S \<Longrightarrow> open T \<Longrightarrow> closed (S - T)"
hoelzl@51471
    88
  unfolding open_closed Diff_eq by (rule closed_Int)
hoelzl@51471
    89
hoelzl@56371
    90
lemma open_Compl [continuous_intros, intro]: "closed S \<Longrightarrow> open (- S)"
hoelzl@51471
    91
  unfolding closed_open .
hoelzl@51471
    92
hoelzl@56371
    93
lemma closed_Compl [continuous_intros, intro]: "open S \<Longrightarrow> closed (- S)"
hoelzl@51471
    94
  unfolding open_closed .
hoelzl@51471
    95
hoelzl@57447
    96
lemma open_Collect_neg: "closed {x. P x} \<Longrightarrow> open {x. \<not> P x}"
hoelzl@57447
    97
  unfolding Collect_neg_eq by (rule open_Compl)
hoelzl@57447
    98
hoelzl@57447
    99
lemma open_Collect_conj: assumes "open {x. P x}" "open {x. Q x}" shows "open {x. P x \<and> Q x}"
hoelzl@57447
   100
  using open_Int[OF assms] by (simp add: Int_def)
hoelzl@57447
   101
hoelzl@57447
   102
lemma open_Collect_disj: assumes "open {x. P x}" "open {x. Q x}" shows "open {x. P x \<or> Q x}"
hoelzl@57447
   103
  using open_Un[OF assms] by (simp add: Un_def)
hoelzl@57447
   104
hoelzl@57447
   105
lemma open_Collect_ex: "(\<And>i. open {x. P i x}) \<Longrightarrow> open {x. \<exists>i. P i x}"
hoelzl@57447
   106
  using open_UN[of UNIV "\<lambda>i. {x. P i x}"] unfolding Collect_ex_eq by simp 
hoelzl@57447
   107
hoelzl@57447
   108
lemma open_Collect_imp: "closed {x. P x} \<Longrightarrow> open {x. Q x} \<Longrightarrow> open {x. P x \<longrightarrow> Q x}"
hoelzl@57447
   109
  unfolding imp_conv_disj by (intro open_Collect_disj open_Collect_neg)
hoelzl@57447
   110
hoelzl@57447
   111
lemma open_Collect_const: "open {x. P}"
hoelzl@57447
   112
  by (cases P) auto
hoelzl@57447
   113
hoelzl@57447
   114
lemma closed_Collect_neg: "open {x. P x} \<Longrightarrow> closed {x. \<not> P x}"
hoelzl@57447
   115
  unfolding Collect_neg_eq by (rule closed_Compl)
hoelzl@57447
   116
hoelzl@57447
   117
lemma closed_Collect_conj: assumes "closed {x. P x}" "closed {x. Q x}" shows "closed {x. P x \<and> Q x}"
hoelzl@57447
   118
  using closed_Int[OF assms] by (simp add: Int_def)
hoelzl@57447
   119
hoelzl@57447
   120
lemma closed_Collect_disj: assumes "closed {x. P x}" "closed {x. Q x}" shows "closed {x. P x \<or> Q x}"
hoelzl@57447
   121
  using closed_Un[OF assms] by (simp add: Un_def)
hoelzl@57447
   122
hoelzl@57447
   123
lemma closed_Collect_all: "(\<And>i. closed {x. P i x}) \<Longrightarrow> closed {x. \<forall>i. P i x}"
hoelzl@57447
   124
  using closed_INT[of UNIV "\<lambda>i. {x. P i x}"] unfolding Collect_all_eq by simp 
hoelzl@57447
   125
hoelzl@57447
   126
lemma closed_Collect_imp: "open {x. P x} \<Longrightarrow> closed {x. Q x} \<Longrightarrow> closed {x. P x \<longrightarrow> Q x}"
hoelzl@57447
   127
  unfolding imp_conv_disj by (intro closed_Collect_disj closed_Collect_neg)
hoelzl@57447
   128
hoelzl@57447
   129
lemma closed_Collect_const: "closed {x. P}"
hoelzl@57447
   130
  by (cases P) auto
hoelzl@57447
   131
hoelzl@51471
   132
end
hoelzl@51471
   133
wenzelm@60758
   134
subsection\<open>Hausdorff and other separation properties\<close>
hoelzl@51471
   135
hoelzl@51471
   136
class t0_space = topological_space +
hoelzl@51471
   137
  assumes t0_space: "x \<noteq> y \<Longrightarrow> \<exists>U. open U \<and> \<not> (x \<in> U \<longleftrightarrow> y \<in> U)"
hoelzl@51471
   138
hoelzl@51471
   139
class t1_space = topological_space +
hoelzl@51471
   140
  assumes t1_space: "x \<noteq> y \<Longrightarrow> \<exists>U. open U \<and> x \<in> U \<and> y \<notin> U"
hoelzl@51471
   141
hoelzl@51471
   142
instance t1_space \<subseteq> t0_space
hoelzl@51471
   143
proof qed (fast dest: t1_space)
hoelzl@51471
   144
hoelzl@51471
   145
lemma separation_t1:
hoelzl@51471
   146
  fixes x y :: "'a::t1_space"
hoelzl@51471
   147
  shows "x \<noteq> y \<longleftrightarrow> (\<exists>U. open U \<and> x \<in> U \<and> y \<notin> U)"
hoelzl@51471
   148
  using t1_space[of x y] by blast
hoelzl@51471
   149
hoelzl@51471
   150
lemma closed_singleton:
hoelzl@51471
   151
  fixes a :: "'a::t1_space"
hoelzl@51471
   152
  shows "closed {a}"
hoelzl@51471
   153
proof -
hoelzl@51471
   154
  let ?T = "\<Union>{S. open S \<and> a \<notin> S}"
hoelzl@51471
   155
  have "open ?T" by (simp add: open_Union)
hoelzl@51471
   156
  also have "?T = - {a}"
hoelzl@51471
   157
    by (simp add: set_eq_iff separation_t1, auto)
hoelzl@51471
   158
  finally show "closed {a}" unfolding closed_def .
hoelzl@51471
   159
qed
hoelzl@51471
   160
hoelzl@56371
   161
lemma closed_insert [continuous_intros, simp]:
hoelzl@51471
   162
  fixes a :: "'a::t1_space"
hoelzl@51471
   163
  assumes "closed S" shows "closed (insert a S)"
hoelzl@51471
   164
proof -
hoelzl@51471
   165
  from closed_singleton assms
hoelzl@51471
   166
  have "closed ({a} \<union> S)" by (rule closed_Un)
hoelzl@51471
   167
  thus "closed (insert a S)" by simp
hoelzl@51471
   168
qed
hoelzl@51471
   169
hoelzl@51471
   170
lemma finite_imp_closed:
hoelzl@51471
   171
  fixes S :: "'a::t1_space set"
hoelzl@51471
   172
  shows "finite S \<Longrightarrow> closed S"
hoelzl@51471
   173
by (induct set: finite, simp_all)
hoelzl@51471
   174
wenzelm@60758
   175
text \<open>T2 spaces are also known as Hausdorff spaces.\<close>
hoelzl@51471
   176
hoelzl@51471
   177
class t2_space = topological_space +
hoelzl@51471
   178
  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 = {}"
hoelzl@51471
   179
hoelzl@51471
   180
instance t2_space \<subseteq> t1_space
hoelzl@51471
   181
proof qed (fast dest: hausdorff)
hoelzl@51471
   182
hoelzl@51471
   183
lemma separation_t2:
hoelzl@51471
   184
  fixes x y :: "'a::t2_space"
hoelzl@51471
   185
  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 = {})"
hoelzl@51471
   186
  using hausdorff[of x y] by blast
hoelzl@51471
   187
hoelzl@51471
   188
lemma separation_t0:
hoelzl@51471
   189
  fixes x y :: "'a::t0_space"
hoelzl@51471
   190
  shows "x \<noteq> y \<longleftrightarrow> (\<exists>U. open U \<and> ~(x\<in>U \<longleftrightarrow> y\<in>U))"
hoelzl@51471
   191
  using t0_space[of x y] by blast
hoelzl@51471
   192
wenzelm@60758
   193
text \<open>A perfect space is a topological space with no isolated points.\<close>
hoelzl@51471
   194
hoelzl@51471
   195
class perfect_space = topological_space +
hoelzl@51471
   196
  assumes not_open_singleton: "\<not> open {x}"
hoelzl@51471
   197
hoelzl@51471
   198
wenzelm@60758
   199
subsection \<open>Generators for toplogies\<close>
hoelzl@51471
   200
hoelzl@51471
   201
inductive generate_topology for S where
hoelzl@51471
   202
  UNIV: "generate_topology S UNIV"
hoelzl@51471
   203
| Int: "generate_topology S a \<Longrightarrow> generate_topology S b \<Longrightarrow> generate_topology S (a \<inter> b)"
hoelzl@51471
   204
| UN: "(\<And>k. k \<in> K \<Longrightarrow> generate_topology S k) \<Longrightarrow> generate_topology S (\<Union>K)"
hoelzl@51471
   205
| Basis: "s \<in> S \<Longrightarrow> generate_topology S s"
hoelzl@51471
   206
hoelzl@51471
   207
hide_fact (open) UNIV Int UN Basis 
hoelzl@51471
   208
hoelzl@51471
   209
lemma generate_topology_Union: 
hoelzl@51471
   210
  "(\<And>k. k \<in> I \<Longrightarrow> generate_topology S (K k)) \<Longrightarrow> generate_topology S (\<Union>k\<in>I. K k)"
haftmann@56166
   211
  using generate_topology.UN [of "K ` I"] by auto
hoelzl@51471
   212
hoelzl@51471
   213
lemma topological_space_generate_topology:
hoelzl@51471
   214
  "class.topological_space (generate_topology S)"
wenzelm@61169
   215
  by standard (auto intro: generate_topology.intros)
hoelzl@51471
   216
wenzelm@60758
   217
subsection \<open>Order topologies\<close>
hoelzl@51471
   218
hoelzl@51471
   219
class order_topology = order + "open" +
hoelzl@51471
   220
  assumes open_generated_order: "open = generate_topology (range (\<lambda>a. {..< a}) \<union> range (\<lambda>a. {a <..}))"
hoelzl@51471
   221
begin
hoelzl@51471
   222
hoelzl@51471
   223
subclass topological_space
hoelzl@51471
   224
  unfolding open_generated_order
hoelzl@51471
   225
  by (rule topological_space_generate_topology)
hoelzl@51471
   226
hoelzl@56371
   227
lemma open_greaterThan [continuous_intros, simp]: "open {a <..}"
hoelzl@51471
   228
  unfolding open_generated_order by (auto intro: generate_topology.Basis)
hoelzl@51471
   229
hoelzl@56371
   230
lemma open_lessThan [continuous_intros, simp]: "open {..< a}"
hoelzl@51471
   231
  unfolding open_generated_order by (auto intro: generate_topology.Basis)
hoelzl@51471
   232
hoelzl@56371
   233
lemma open_greaterThanLessThan [continuous_intros, simp]: "open {a <..< b}"
hoelzl@51471
   234
   unfolding greaterThanLessThan_eq by (simp add: open_Int)
hoelzl@51471
   235
hoelzl@51471
   236
end
hoelzl@51471
   237
hoelzl@51471
   238
class linorder_topology = linorder + order_topology
hoelzl@51471
   239
hoelzl@56371
   240
lemma closed_atMost [continuous_intros, simp]: "closed {.. a::'a::linorder_topology}"
hoelzl@51471
   241
  by (simp add: closed_open)
hoelzl@51471
   242
hoelzl@56371
   243
lemma closed_atLeast [continuous_intros, simp]: "closed {a::'a::linorder_topology ..}"
hoelzl@51471
   244
  by (simp add: closed_open)
hoelzl@51471
   245
hoelzl@56371
   246
lemma closed_atLeastAtMost [continuous_intros, simp]: "closed {a::'a::linorder_topology .. b}"
hoelzl@51471
   247
proof -
hoelzl@51471
   248
  have "{a .. b} = {a ..} \<inter> {.. b}"
hoelzl@51471
   249
    by auto
hoelzl@51471
   250
  then show ?thesis
hoelzl@51471
   251
    by (simp add: closed_Int)
hoelzl@51471
   252
qed
hoelzl@51471
   253
hoelzl@51471
   254
lemma (in linorder) less_separate:
hoelzl@51471
   255
  assumes "x < y"
hoelzl@51471
   256
  shows "\<exists>a b. x \<in> {..< a} \<and> y \<in> {b <..} \<and> {..< a} \<inter> {b <..} = {}"
wenzelm@53381
   257
proof (cases "\<exists>z. x < z \<and> z < y")
wenzelm@53381
   258
  case True
wenzelm@53381
   259
  then obtain z where "x < z \<and> z < y" ..
hoelzl@51471
   260
  then have "x \<in> {..< z} \<and> y \<in> {z <..} \<and> {z <..} \<inter> {..< z} = {}"
hoelzl@51471
   261
    by auto
hoelzl@51471
   262
  then show ?thesis by blast
hoelzl@51471
   263
next
wenzelm@53381
   264
  case False
wenzelm@60758
   265
  with \<open>x < y\<close> have "x \<in> {..< y} \<and> y \<in> {x <..} \<and> {x <..} \<inter> {..< y} = {}"
hoelzl@51471
   266
    by auto
hoelzl@51471
   267
  then show ?thesis by blast
hoelzl@51471
   268
qed
hoelzl@51471
   269
hoelzl@51471
   270
instance linorder_topology \<subseteq> t2_space
hoelzl@51471
   271
proof
hoelzl@51471
   272
  fix x y :: 'a
hoelzl@51471
   273
  from less_separate[of x y] less_separate[of y x]
hoelzl@51471
   274
  show "x \<noteq> y \<Longrightarrow> \<exists>U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {}"
hoelzl@51471
   275
    by (elim neqE) (metis open_lessThan open_greaterThan Int_commute)+
hoelzl@51471
   276
qed
hoelzl@51471
   277
hoelzl@51480
   278
lemma (in linorder_topology) open_right:
hoelzl@51480
   279
  assumes "open S" "x \<in> S" and gt_ex: "x < y" shows "\<exists>b>x. {x ..< b} \<subseteq> S"
hoelzl@51471
   280
  using assms unfolding open_generated_order
hoelzl@51471
   281
proof induction
hoelzl@51471
   282
  case (Int A B)
hoelzl@51471
   283
  then obtain a b where "a > x" "{x ..< a} \<subseteq> A"  "b > x" "{x ..< b} \<subseteq> B" by auto
hoelzl@51471
   284
  then show ?case by (auto intro!: exI[of _ "min a b"])
hoelzl@51471
   285
next
hoelzl@51480
   286
  case (Basis S) then show ?case by (fastforce intro: exI[of _ y] gt_ex)
hoelzl@51480
   287
qed blast+
hoelzl@51471
   288
hoelzl@51480
   289
lemma (in linorder_topology) open_left:
hoelzl@51480
   290
  assumes "open S" "x \<in> S" and lt_ex: "y < x" shows "\<exists>b<x. {b <.. x} \<subseteq> S"
hoelzl@51471
   291
  using assms unfolding open_generated_order
hoelzl@51471
   292
proof induction
hoelzl@51471
   293
  case (Int A B)
hoelzl@51471
   294
  then obtain a b where "a < x" "{a <.. x} \<subseteq> A"  "b < x" "{b <.. x} \<subseteq> B" by auto
hoelzl@51471
   295
  then show ?case by (auto intro!: exI[of _ "max a b"])
hoelzl@51471
   296
next
hoelzl@51480
   297
  case (Basis S) then show ?case by (fastforce intro: exI[of _ y] lt_ex)
hoelzl@51480
   298
qed blast+
hoelzl@51471
   299
wenzelm@60758
   300
subsubsection \<open>Boolean is an order topology\<close>
hoelzl@59106
   301
wenzelm@60758
   302
text \<open>It also is a discrete topology, but don't have a type class for it (yet).\<close>
hoelzl@59106
   303
hoelzl@59106
   304
instantiation bool :: order_topology
hoelzl@59106
   305
begin
hoelzl@59106
   306
hoelzl@59106
   307
definition open_bool :: "bool set \<Rightarrow> bool" where
hoelzl@59106
   308
  "open_bool = generate_topology (range (\<lambda>a. {..< a}) \<union> range (\<lambda>a. {a <..}))"
hoelzl@59106
   309
hoelzl@59106
   310
instance
hoelzl@59106
   311
  proof qed (rule open_bool_def)
hoelzl@59106
   312
hoelzl@59106
   313
end
hoelzl@59106
   314
hoelzl@59106
   315
lemma open_bool[simp, intro!]: "open (A::bool set)"
hoelzl@59106
   316
proof -
hoelzl@59106
   317
  have *: "{False <..} = {True}" "{..< True} = {False}"
hoelzl@59106
   318
    by auto
hoelzl@59106
   319
  have "A = UNIV \<or> A = {} \<or> A = {False <..} \<or> A = {..< True}"
hoelzl@59106
   320
    using subset_UNIV[of A] unfolding UNIV_bool * by auto
hoelzl@59106
   321
  then show "open A"
hoelzl@59106
   322
    by auto
hoelzl@59106
   323
qed
hoelzl@59106
   324
wenzelm@60758
   325
subsubsection \<open>Topological filters\<close>
hoelzl@51471
   326
hoelzl@51471
   327
definition (in topological_space) nhds :: "'a \<Rightarrow> 'a filter"
hoelzl@57276
   328
  where "nhds a = (INF S:{S. open S \<and> a \<in> S}. principal S)"
hoelzl@51471
   329
hoelzl@51641
   330
definition (in topological_space) at_within :: "'a \<Rightarrow> 'a set \<Rightarrow> 'a filter" ("at (_) within (_)" [1000, 60] 60)
hoelzl@51641
   331
  where "at a within s = inf (nhds a) (principal (s - {a}))"
hoelzl@51641
   332
hoelzl@51641
   333
abbreviation (in topological_space) at :: "'a \<Rightarrow> 'a filter" ("at") where
hoelzl@51641
   334
  "at x \<equiv> at x within (CONST UNIV)"
hoelzl@51471
   335
hoelzl@51473
   336
abbreviation (in order_topology) at_right :: "'a \<Rightarrow> 'a filter" where
hoelzl@51471
   337
  "at_right x \<equiv> at x within {x <..}"
hoelzl@51471
   338
hoelzl@51473
   339
abbreviation (in order_topology) at_left :: "'a \<Rightarrow> 'a filter" where
hoelzl@51471
   340
  "at_left x \<equiv> at x within {..< x}"
hoelzl@51471
   341
hoelzl@57448
   342
lemma (in topological_space) nhds_generated_topology:
hoelzl@57448
   343
  "open = generate_topology T \<Longrightarrow> nhds x = (INF S:{S\<in>T. x \<in> S}. principal S)"
hoelzl@57448
   344
  unfolding nhds_def
hoelzl@57448
   345
proof (safe intro!: antisym INF_greatest)
hoelzl@57448
   346
  fix S assume "generate_topology T S" "x \<in> S"
hoelzl@57448
   347
  then show "(INF S:{S \<in> T. x \<in> S}. principal S) \<le> principal S"
hoelzl@57448
   348
    by induction 
hoelzl@57448
   349
       (auto intro: INF_lower order_trans simp add: inf_principal[symmetric] simp del: inf_principal)
hoelzl@57448
   350
qed (auto intro!: INF_lower intro: generate_topology.intros)
hoelzl@57448
   351
hoelzl@51473
   352
lemma (in topological_space) eventually_nhds:
hoelzl@51471
   353
  "eventually P (nhds a) \<longleftrightarrow> (\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x))"
hoelzl@57276
   354
  unfolding nhds_def by (subst eventually_INF_base) (auto simp: eventually_principal)
hoelzl@51471
   355
hoelzl@51471
   356
lemma nhds_neq_bot [simp]: "nhds a \<noteq> bot"
hoelzl@51471
   357
  unfolding trivial_limit_def eventually_nhds by simp
hoelzl@51471
   358
hoelzl@60182
   359
lemma (in t1_space) t1_space_nhds:
hoelzl@60182
   360
  "x \<noteq> y \<Longrightarrow> (\<forall>\<^sub>F x in nhds x. x \<noteq> y)"
hoelzl@60182
   361
  by (drule t1_space) (auto simp: eventually_nhds)
hoelzl@60182
   362
hoelzl@57448
   363
lemma at_within_eq: "at x within s = (INF S:{S. open S \<and> x \<in> S}. principal (S \<inter> s - {x}))"
hoelzl@57448
   364
  unfolding nhds_def at_within_def by (subst INF_inf_const2[symmetric]) (auto simp add: Diff_Int_distrib)
hoelzl@57448
   365
hoelzl@51641
   366
lemma eventually_at_filter:
hoelzl@51641
   367
  "eventually P (at a within s) \<longleftrightarrow> eventually (\<lambda>x. x \<noteq> a \<longrightarrow> x \<in> s \<longrightarrow> P x) (nhds a)"
hoelzl@51641
   368
  unfolding at_within_def eventually_inf_principal by (simp add: imp_conjL[symmetric] conj_commute)
hoelzl@51641
   369
hoelzl@51641
   370
lemma at_le: "s \<subseteq> t \<Longrightarrow> at x within s \<le> at x within t"
hoelzl@51641
   371
  unfolding at_within_def by (intro inf_mono) auto
hoelzl@51641
   372
hoelzl@51471
   373
lemma eventually_at_topological:
hoelzl@51641
   374
  "eventually P (at a within s) \<longleftrightarrow> (\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. x \<noteq> a \<longrightarrow> x \<in> s \<longrightarrow> P x))"
hoelzl@51641
   375
  unfolding eventually_nhds eventually_at_filter by simp
hoelzl@51471
   376
hoelzl@51481
   377
lemma at_within_open: "a \<in> S \<Longrightarrow> open S \<Longrightarrow> at a within S = at a"
hoelzl@51641
   378
  unfolding filter_eq_iff eventually_at_topological by (metis open_Int Int_iff UNIV_I)
hoelzl@51481
   379
lp15@61234
   380
lemma at_within_open_NO_MATCH:
lp15@61234
   381
  "a \<in> s \<Longrightarrow> open s \<Longrightarrow> NO_MATCH UNIV s \<Longrightarrow> at a within s = at a"
lp15@61234
   382
  by (simp only: at_within_open)
lp15@61234
   383
hoelzl@61245
   384
lemma at_within_nhd:
hoelzl@61245
   385
  assumes "x \<in> S" "open S" "T \<inter> S - {x} = U \<inter> S - {x}"
hoelzl@61245
   386
  shows "at x within T = at x within U"
hoelzl@61245
   387
  unfolding filter_eq_iff eventually_at_filter
hoelzl@61245
   388
proof (intro allI eventually_subst)
hoelzl@61245
   389
  have "eventually (\<lambda>x. x \<in> S) (nhds x)"
hoelzl@61245
   390
    using \<open>x \<in> S\<close> \<open>open S\<close> by (auto simp: eventually_nhds)
hoelzl@61245
   391
  then show "\<forall>\<^sub>F n in nhds x. (n \<noteq> x \<longrightarrow> n \<in> T \<longrightarrow> P n) = (n \<noteq> x \<longrightarrow> n \<in> U \<longrightarrow> P n)" for P  
hoelzl@61245
   392
    by eventually_elim (insert \<open>T \<inter> S - {x} = U \<inter> S - {x}\<close>, blast)
hoelzl@61245
   393
qed
hoelzl@61245
   394
huffman@53859
   395
lemma at_within_empty [simp]: "at a within {} = bot"
huffman@53859
   396
  unfolding at_within_def by simp
huffman@53859
   397
huffman@53860
   398
lemma at_within_union: "at x within (S \<union> T) = sup (at x within S) (at x within T)"
huffman@53860
   399
  unfolding filter_eq_iff eventually_sup eventually_at_filter
huffman@53860
   400
  by (auto elim!: eventually_rev_mp)
huffman@53860
   401
hoelzl@51471
   402
lemma at_eq_bot_iff: "at a = bot \<longleftrightarrow> open {a}"
hoelzl@51471
   403
  unfolding trivial_limit_def eventually_at_topological
hoelzl@51471
   404
  by (safe, case_tac "S = {a}", simp, fast, fast)
hoelzl@51471
   405
hoelzl@51471
   406
lemma at_neq_bot [simp]: "at (a::'a::perfect_space) \<noteq> bot"
hoelzl@51471
   407
  by (simp add: at_eq_bot_iff not_open_singleton)
hoelzl@51471
   408
hoelzl@57448
   409
lemma (in order_topology) nhds_order: "nhds x =
hoelzl@57448
   410
  inf (INF a:{x <..}. principal {..< a}) (INF a:{..< x}. principal {a <..})"
hoelzl@57448
   411
proof -
hoelzl@57448
   412
  have 1: "{S \<in> range lessThan \<union> range greaterThan. x \<in> S} = 
hoelzl@57448
   413
      (\<lambda>a. {..< a}) ` {x <..} \<union> (\<lambda>a. {a <..}) ` {..< x}"
hoelzl@57448
   414
    by auto
hoelzl@57448
   415
  show ?thesis
hoelzl@57448
   416
    unfolding nhds_generated_topology[OF open_generated_order] INF_union 1 INF_image comp_def ..
hoelzl@51471
   417
qed
hoelzl@51471
   418
hoelzl@57448
   419
lemma (in linorder_topology) at_within_order: "UNIV \<noteq> {x} \<Longrightarrow> 
hoelzl@57448
   420
  at x within s = inf (INF a:{x <..}. principal ({..< a} \<inter> s - {x}))
hoelzl@57448
   421
                      (INF a:{..< x}. principal ({a <..} \<inter> s - {x}))"
hoelzl@57448
   422
proof (cases "{x <..} = {}" "{..< x} = {}" rule: case_split[case_product case_split])
hoelzl@57448
   423
  assume "UNIV \<noteq> {x}" "{x<..} = {}" "{..< x} = {}"
hoelzl@57448
   424
  moreover have "UNIV = {..< x} \<union> {x} \<union> {x <..}"
hoelzl@57448
   425
    by auto
hoelzl@57448
   426
  ultimately show ?thesis
hoelzl@57448
   427
    by auto
hoelzl@57448
   428
qed (auto simp: at_within_def nhds_order Int_Diff inf_principal[symmetric] INF_inf_const2
hoelzl@57448
   429
                inf_sup_aci[where 'a="'a filter"]
hoelzl@57448
   430
          simp del: inf_principal)
hoelzl@57448
   431
hoelzl@57448
   432
lemma (in linorder_topology) at_left_eq:
hoelzl@57448
   433
  "y < x \<Longrightarrow> at_left x = (INF a:{..< x}. principal {a <..< x})"
hoelzl@57448
   434
  by (subst at_within_order)
hoelzl@57448
   435
     (auto simp: greaterThan_Int_greaterThan greaterThanLessThan_eq[symmetric] min.absorb2 INF_constant
hoelzl@57448
   436
           intro!: INF_lower2 inf_absorb2)
hoelzl@57448
   437
hoelzl@57448
   438
lemma (in linorder_topology) eventually_at_left:
hoelzl@57448
   439
  "y < x \<Longrightarrow> eventually P (at_left x) \<longleftrightarrow> (\<exists>b<x. \<forall>y>b. y < x \<longrightarrow> P y)"
hoelzl@57448
   440
  unfolding at_left_eq by (subst eventually_INF_base) (auto simp: eventually_principal Ball_def)
hoelzl@57448
   441
hoelzl@57448
   442
lemma (in linorder_topology) at_right_eq:
hoelzl@57448
   443
  "x < y \<Longrightarrow> at_right x = (INF a:{x <..}. principal {x <..< a})"
hoelzl@57448
   444
  by (subst at_within_order)
hoelzl@57448
   445
     (auto simp: lessThan_Int_lessThan greaterThanLessThan_eq[symmetric] max.absorb2 INF_constant Int_commute
hoelzl@57448
   446
           intro!: INF_lower2 inf_absorb1)
hoelzl@57448
   447
hoelzl@57448
   448
lemma (in linorder_topology) eventually_at_right:
hoelzl@57448
   449
  "x < y \<Longrightarrow> eventually P (at_right x) \<longleftrightarrow> (\<exists>b>x. \<forall>y>x. y < b \<longrightarrow> P y)"
hoelzl@57448
   450
  unfolding at_right_eq by (subst eventually_INF_base) (auto simp: eventually_principal Ball_def)
hoelzl@51471
   451
hoelzl@57275
   452
lemma trivial_limit_at_right_top: "at_right (top::_::{order_top, linorder_topology}) = bot"
hoelzl@57275
   453
  unfolding filter_eq_iff eventually_at_topological by auto
hoelzl@57275
   454
hoelzl@57275
   455
lemma trivial_limit_at_left_bot: "at_left (bot::_::{order_bot, linorder_topology}) = bot"
hoelzl@57275
   456
  unfolding filter_eq_iff eventually_at_topological by auto
hoelzl@57275
   457
hoelzl@51471
   458
lemma trivial_limit_at_left_real [simp]:
hoelzl@57275
   459
  "\<not> trivial_limit (at_left (x::'a::{no_bot, dense_order, linorder_topology}))"
hoelzl@57275
   460
  using lt_ex[of x]
hoelzl@57275
   461
  by safe (auto simp add: trivial_limit_def eventually_at_left dest: dense)
hoelzl@51471
   462
hoelzl@51471
   463
lemma trivial_limit_at_right_real [simp]:
hoelzl@57275
   464
  "\<not> trivial_limit (at_right (x::'a::{no_top, dense_order, linorder_topology}))"
hoelzl@57275
   465
  using gt_ex[of x]
hoelzl@57275
   466
  by safe (auto simp add: trivial_limit_def eventually_at_right dest: dense)
hoelzl@51471
   467
hoelzl@51471
   468
lemma at_eq_sup_left_right: "at (x::'a::linorder_topology) = sup (at_left x) (at_right x)"
hoelzl@51641
   469
  by (auto simp: eventually_at_filter filter_eq_iff eventually_sup 
hoelzl@51471
   470
           elim: eventually_elim2 eventually_elim1)
hoelzl@51471
   471
hoelzl@51471
   472
lemma eventually_at_split:
hoelzl@51471
   473
  "eventually P (at (x::'a::linorder_topology)) \<longleftrightarrow> eventually P (at_left x) \<and> eventually P (at_right x)"
hoelzl@51471
   474
  by (subst at_eq_sup_left_right) (simp add: eventually_sup)
hoelzl@51471
   475
wenzelm@60758
   476
subsubsection \<open>Tendsto\<close>
hoelzl@51471
   477
hoelzl@51471
   478
abbreviation (in topological_space)
hoelzl@51471
   479
  tendsto :: "('b \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'b filter \<Rightarrow> bool" (infixr "--->" 55) where
hoelzl@51471
   480
  "(f ---> l) F \<equiv> filterlim f (nhds l) F"
hoelzl@51471
   481
hoelzl@51478
   482
definition (in t2_space) Lim :: "'f filter \<Rightarrow> ('f \<Rightarrow> 'a) \<Rightarrow> 'a" where
hoelzl@51478
   483
  "Lim A f = (THE l. (f ---> l) A)"
hoelzl@51478
   484
hoelzl@51471
   485
lemma tendsto_eq_rhs: "(f ---> x) F \<Longrightarrow> x = y \<Longrightarrow> (f ---> y) F"
hoelzl@51471
   486
  by simp
hoelzl@51471
   487
wenzelm@57953
   488
named_theorems tendsto_intros "introduction rules for tendsto"
wenzelm@60758
   489
setup \<open>
hoelzl@51471
   490
  Global_Theory.add_thms_dynamic (@{binding tendsto_eq_intros},
wenzelm@57953
   491
    fn context =>
wenzelm@57953
   492
      Named_Theorems.get (Context.proof_of context) @{named_theorems tendsto_intros}
wenzelm@57953
   493
      |> map_filter (try (fn thm => @{thm tendsto_eq_rhs} OF [thm])))
wenzelm@60758
   494
\<close>
hoelzl@51471
   495
hoelzl@51473
   496
lemma (in topological_space) tendsto_def:
hoelzl@51473
   497
   "(f ---> l) F \<longleftrightarrow> (\<forall>S. open S \<longrightarrow> l \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) F)"
hoelzl@57276
   498
   unfolding nhds_def filterlim_INF filterlim_principal by auto
hoelzl@51471
   499
hoelzl@51471
   500
lemma tendsto_mono: "F \<le> F' \<Longrightarrow> (f ---> l) F' \<Longrightarrow> (f ---> l) F"
hoelzl@51471
   501
  unfolding tendsto_def le_filter_def by fast
hoelzl@51471
   502
hoelzl@51641
   503
lemma tendsto_within_subset: "(f ---> l) (at x within S) \<Longrightarrow> T \<subseteq> S \<Longrightarrow> (f ---> l) (at x within T)"
hoelzl@51641
   504
  by (blast intro: tendsto_mono at_le)
hoelzl@51641
   505
hoelzl@51641
   506
lemma filterlim_at:
hoelzl@51641
   507
  "(LIM x F. f x :> at b within s) \<longleftrightarrow> (eventually (\<lambda>x. f x \<in> s \<and> f x \<noteq> b) F \<and> (f ---> b) F)"
hoelzl@51641
   508
  by (simp add: at_within_def filterlim_inf filterlim_principal conj_commute)
hoelzl@51641
   509
hoelzl@51473
   510
lemma (in topological_space) topological_tendstoI:
hoelzl@51641
   511
  "(\<And>S. open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) F) \<Longrightarrow> (f ---> l) F"
hoelzl@51471
   512
  unfolding tendsto_def by auto
hoelzl@51471
   513
hoelzl@51473
   514
lemma (in topological_space) topological_tendstoD:
hoelzl@51471
   515
  "(f ---> l) F \<Longrightarrow> open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) F"
hoelzl@51471
   516
  unfolding tendsto_def by auto
hoelzl@51471
   517
hoelzl@57448
   518
lemma (in order_topology) order_tendsto_iff:
hoelzl@57448
   519
  "(f ---> x) F \<longleftrightarrow> (\<forall>l<x. eventually (\<lambda>x. l < f x) F) \<and> (\<forall>u>x. eventually (\<lambda>x. f x < u) F)"
hoelzl@57448
   520
  unfolding nhds_order filterlim_inf filterlim_INF filterlim_principal by auto
hoelzl@57448
   521
hoelzl@57448
   522
lemma (in order_topology) order_tendstoI:
hoelzl@57448
   523
  "(\<And>a. a < y \<Longrightarrow> eventually (\<lambda>x. a < f x) F) \<Longrightarrow> (\<And>a. y < a \<Longrightarrow> eventually (\<lambda>x. f x < a) F) \<Longrightarrow>
hoelzl@57448
   524
    (f ---> y) F"
hoelzl@57448
   525
  unfolding order_tendsto_iff by auto
hoelzl@57448
   526
hoelzl@57448
   527
lemma (in order_topology) order_tendstoD:
hoelzl@57448
   528
  assumes "(f ---> y) F"
hoelzl@51471
   529
  shows "a < y \<Longrightarrow> eventually (\<lambda>x. a < f x) F"
hoelzl@51471
   530
    and "y < a \<Longrightarrow> eventually (\<lambda>x. f x < a) F"
hoelzl@57448
   531
  using assms unfolding order_tendsto_iff by auto
hoelzl@51471
   532
hoelzl@51471
   533
lemma tendsto_bot [simp]: "(f ---> a) bot"
hoelzl@51471
   534
  unfolding tendsto_def by simp
hoelzl@51471
   535
hoelzl@57448
   536
lemma (in linorder_topology) tendsto_max:
hoelzl@56949
   537
  assumes X: "(X ---> x) net"
hoelzl@56949
   538
  assumes Y: "(Y ---> y) net"
hoelzl@56949
   539
  shows "((\<lambda>x. max (X x) (Y x)) ---> max x y) net"
hoelzl@56949
   540
proof (rule order_tendstoI)
hoelzl@56949
   541
  fix a assume "a < max x y"
hoelzl@56949
   542
  then show "eventually (\<lambda>x. a < max (X x) (Y x)) net"
hoelzl@56949
   543
    using order_tendstoD(1)[OF X, of a] order_tendstoD(1)[OF Y, of a]
hoelzl@56949
   544
    by (auto simp: less_max_iff_disj elim: eventually_elim1)
hoelzl@56949
   545
next
hoelzl@56949
   546
  fix a assume "max x y < a"
hoelzl@56949
   547
  then show "eventually (\<lambda>x. max (X x) (Y x) < a) net"
hoelzl@56949
   548
    using order_tendstoD(2)[OF X, of a] order_tendstoD(2)[OF Y, of a]
hoelzl@56949
   549
    by (auto simp: eventually_conj_iff)
hoelzl@56949
   550
qed
hoelzl@56949
   551
hoelzl@57448
   552
lemma (in linorder_topology) tendsto_min:
hoelzl@56949
   553
  assumes X: "(X ---> x) net"
hoelzl@56949
   554
  assumes Y: "(Y ---> y) net"
hoelzl@56949
   555
  shows "((\<lambda>x. min (X x) (Y x)) ---> min x y) net"
hoelzl@56949
   556
proof (rule order_tendstoI)
hoelzl@56949
   557
  fix a assume "a < min x y"
hoelzl@56949
   558
  then show "eventually (\<lambda>x. a < min (X x) (Y x)) net"
hoelzl@56949
   559
    using order_tendstoD(1)[OF X, of a] order_tendstoD(1)[OF Y, of a]
hoelzl@56949
   560
    by (auto simp: eventually_conj_iff)
hoelzl@56949
   561
next
hoelzl@56949
   562
  fix a assume "min x y < a"
hoelzl@56949
   563
  then show "eventually (\<lambda>x. min (X x) (Y x) < a) net"
hoelzl@56949
   564
    using order_tendstoD(2)[OF X, of a] order_tendstoD(2)[OF Y, of a]
hoelzl@56949
   565
    by (auto simp: min_less_iff_disj elim: eventually_elim1)
hoelzl@56949
   566
qed
hoelzl@56949
   567
hoelzl@58729
   568
lemma tendsto_ident_at [tendsto_intros, simp, intro]: "((\<lambda>x. x) ---> a) (at a within s)"
hoelzl@51471
   569
  unfolding tendsto_def eventually_at_topological by auto
hoelzl@51471
   570
hoelzl@58729
   571
lemma (in topological_space) tendsto_const [tendsto_intros, simp, intro]: "((\<lambda>x. k) ---> k) F"
hoelzl@51471
   572
  by (simp add: tendsto_def)
hoelzl@51471
   573
hoelzl@51478
   574
lemma (in t2_space) tendsto_unique:
hoelzl@57448
   575
  assumes "F \<noteq> bot" and "(f ---> a) F" and "(f ---> b) F"
hoelzl@51471
   576
  shows "a = b"
hoelzl@51471
   577
proof (rule ccontr)
hoelzl@51471
   578
  assume "a \<noteq> b"
hoelzl@51471
   579
  obtain U V where "open U" "open V" "a \<in> U" "b \<in> V" "U \<inter> V = {}"
wenzelm@60758
   580
    using hausdorff [OF \<open>a \<noteq> b\<close>] by fast
hoelzl@51471
   581
  have "eventually (\<lambda>x. f x \<in> U) F"
wenzelm@60758
   582
    using \<open>(f ---> a) F\<close> \<open>open U\<close> \<open>a \<in> U\<close> by (rule topological_tendstoD)
hoelzl@51471
   583
  moreover
hoelzl@51471
   584
  have "eventually (\<lambda>x. f x \<in> V) F"
wenzelm@60758
   585
    using \<open>(f ---> b) F\<close> \<open>open V\<close> \<open>b \<in> V\<close> by (rule topological_tendstoD)
hoelzl@51471
   586
  ultimately
hoelzl@51471
   587
  have "eventually (\<lambda>x. False) F"
hoelzl@51471
   588
  proof eventually_elim
hoelzl@51471
   589
    case (elim x)
hoelzl@51471
   590
    hence "f x \<in> U \<inter> V" by simp
wenzelm@60758
   591
    with \<open>U \<inter> V = {}\<close> show ?case by simp
hoelzl@51471
   592
  qed
wenzelm@60758
   593
  with \<open>\<not> trivial_limit F\<close> show "False"
hoelzl@51471
   594
    by (simp add: trivial_limit_def)
hoelzl@51471
   595
qed
hoelzl@51471
   596
hoelzl@51478
   597
lemma (in t2_space) tendsto_const_iff:
hoelzl@51478
   598
  assumes "\<not> trivial_limit F" shows "((\<lambda>x. a :: 'a) ---> b) F \<longleftrightarrow> a = b"
hoelzl@58729
   599
  by (auto intro!: tendsto_unique [OF assms tendsto_const])
hoelzl@51471
   600
hoelzl@51471
   601
lemma increasing_tendsto:
hoelzl@51471
   602
  fixes f :: "_ \<Rightarrow> 'a::order_topology"
hoelzl@51471
   603
  assumes bdd: "eventually (\<lambda>n. f n \<le> l) F"
hoelzl@51471
   604
      and en: "\<And>x. x < l \<Longrightarrow> eventually (\<lambda>n. x < f n) F"
hoelzl@51471
   605
  shows "(f ---> l) F"
hoelzl@51471
   606
  using assms by (intro order_tendstoI) (auto elim!: eventually_elim1)
hoelzl@51471
   607
hoelzl@51471
   608
lemma decreasing_tendsto:
hoelzl@51471
   609
  fixes f :: "_ \<Rightarrow> 'a::order_topology"
hoelzl@51471
   610
  assumes bdd: "eventually (\<lambda>n. l \<le> f n) F"
hoelzl@51471
   611
      and en: "\<And>x. l < x \<Longrightarrow> eventually (\<lambda>n. f n < x) F"
hoelzl@51471
   612
  shows "(f ---> l) F"
hoelzl@51471
   613
  using assms by (intro order_tendstoI) (auto elim!: eventually_elim1)
hoelzl@51471
   614
hoelzl@51471
   615
lemma tendsto_sandwich:
hoelzl@51471
   616
  fixes f g h :: "'a \<Rightarrow> 'b::order_topology"
hoelzl@51471
   617
  assumes ev: "eventually (\<lambda>n. f n \<le> g n) net" "eventually (\<lambda>n. g n \<le> h n) net"
hoelzl@51471
   618
  assumes lim: "(f ---> c) net" "(h ---> c) net"
hoelzl@51471
   619
  shows "(g ---> c) net"
hoelzl@51471
   620
proof (rule order_tendstoI)
hoelzl@51471
   621
  fix a show "a < c \<Longrightarrow> eventually (\<lambda>x. a < g x) net"
hoelzl@51471
   622
    using order_tendstoD[OF lim(1), of a] ev by (auto elim: eventually_elim2)
hoelzl@51471
   623
next
hoelzl@51471
   624
  fix a show "c < a \<Longrightarrow> eventually (\<lambda>x. g x < a) net"
hoelzl@51471
   625
    using order_tendstoD[OF lim(2), of a] ev by (auto elim: eventually_elim2)
hoelzl@51471
   626
qed
hoelzl@51471
   627
hoelzl@51471
   628
lemma tendsto_le:
hoelzl@51471
   629
  fixes f g :: "'a \<Rightarrow> 'b::linorder_topology"
hoelzl@51471
   630
  assumes F: "\<not> trivial_limit F"
hoelzl@51471
   631
  assumes x: "(f ---> x) F" and y: "(g ---> y) F"
hoelzl@51471
   632
  assumes ev: "eventually (\<lambda>x. g x \<le> f x) F"
hoelzl@51471
   633
  shows "y \<le> x"
hoelzl@51471
   634
proof (rule ccontr)
hoelzl@51471
   635
  assume "\<not> y \<le> x"
hoelzl@51471
   636
  with less_separate[of x y] obtain a b where xy: "x < a" "b < y" "{..<a} \<inter> {b<..} = {}"
hoelzl@51471
   637
    by (auto simp: not_le)
hoelzl@51471
   638
  then have "eventually (\<lambda>x. f x < a) F" "eventually (\<lambda>x. b < g x) F"
hoelzl@51471
   639
    using x y by (auto intro: order_tendstoD)
hoelzl@51471
   640
  with ev have "eventually (\<lambda>x. False) F"
hoelzl@51471
   641
    by eventually_elim (insert xy, fastforce)
hoelzl@51471
   642
  with F show False
hoelzl@51471
   643
    by (simp add: eventually_False)
hoelzl@51471
   644
qed
hoelzl@51471
   645
hoelzl@51471
   646
lemma tendsto_le_const:
hoelzl@51471
   647
  fixes f :: "'a \<Rightarrow> 'b::linorder_topology"
hoelzl@51471
   648
  assumes F: "\<not> trivial_limit F"
lp15@56289
   649
  assumes x: "(f ---> x) F" and a: "eventually (\<lambda>i. a \<le> f i) F"
hoelzl@51471
   650
  shows "a \<le> x"
hoelzl@51471
   651
  using F x tendsto_const a by (rule tendsto_le)
hoelzl@51471
   652
lp15@56289
   653
lemma tendsto_ge_const:
lp15@56289
   654
  fixes f :: "'a \<Rightarrow> 'b::linorder_topology"
lp15@56289
   655
  assumes F: "\<not> trivial_limit F"
lp15@56289
   656
  assumes x: "(f ---> x) F" and a: "eventually (\<lambda>i. a \<ge> f i) F"
lp15@56289
   657
  shows "a \<ge> x"
lp15@56289
   658
  by (rule tendsto_le [OF F tendsto_const x a])
lp15@56289
   659
wenzelm@60758
   660
subsubsection \<open>Rules about @{const Lim}\<close>
hoelzl@51478
   661
hoelzl@57276
   662
lemma tendsto_Lim:
hoelzl@51478
   663
  "\<not>(trivial_limit net) \<Longrightarrow> (f ---> l) net \<Longrightarrow> Lim net f = l"
hoelzl@51478
   664
  unfolding Lim_def using tendsto_unique[of net f] by auto
hoelzl@51478
   665
hoelzl@51641
   666
lemma Lim_ident_at: "\<not> trivial_limit (at x within s) \<Longrightarrow> Lim (at x within s) (\<lambda>x. x) = x"
hoelzl@51478
   667
  by (rule tendsto_Lim[OF _ tendsto_ident_at]) auto
hoelzl@51478
   668
hoelzl@51471
   669
lemma filterlim_at_bot_at_right:
hoelzl@57275
   670
  fixes f :: "'a::linorder_topology \<Rightarrow> 'b::linorder"
hoelzl@51471
   671
  assumes mono: "\<And>x y. Q x \<Longrightarrow> Q y \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y"
hoelzl@51471
   672
  assumes bij: "\<And>x. P x \<Longrightarrow> f (g x) = x" "\<And>x. P x \<Longrightarrow> Q (g x)"
hoelzl@51471
   673
  assumes Q: "eventually Q (at_right a)" and bound: "\<And>b. Q b \<Longrightarrow> a < b"
hoelzl@51471
   674
  assumes P: "eventually P at_bot"
hoelzl@51471
   675
  shows "filterlim f at_bot (at_right a)"
hoelzl@51471
   676
proof -
hoelzl@51471
   677
  from P obtain x where x: "\<And>y. y \<le> x \<Longrightarrow> P y"
hoelzl@51471
   678
    unfolding eventually_at_bot_linorder by auto
hoelzl@51471
   679
  show ?thesis
hoelzl@51471
   680
  proof (intro filterlim_at_bot_le[THEN iffD2] allI impI)
hoelzl@51471
   681
    fix z assume "z \<le> x"
hoelzl@51471
   682
    with x have "P z" by auto
hoelzl@51471
   683
    have "eventually (\<lambda>x. x \<le> g z) (at_right a)"
wenzelm@60758
   684
      using bound[OF bij(2)[OF \<open>P z\<close>]]
wenzelm@60758
   685
      unfolding eventually_at_right[OF bound[OF bij(2)[OF \<open>P z\<close>]]] by (auto intro!: exI[of _ "g z"])
hoelzl@51471
   686
    with Q show "eventually (\<lambda>x. f x \<le> z) (at_right a)"
wenzelm@60758
   687
      by eventually_elim (metis bij \<open>P z\<close> mono)
hoelzl@51471
   688
  qed
hoelzl@51471
   689
qed
hoelzl@51471
   690
hoelzl@51471
   691
lemma filterlim_at_top_at_left:
hoelzl@57275
   692
  fixes f :: "'a::linorder_topology \<Rightarrow> 'b::linorder"
hoelzl@51471
   693
  assumes mono: "\<And>x y. Q x \<Longrightarrow> Q y \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y"
hoelzl@51471
   694
  assumes bij: "\<And>x. P x \<Longrightarrow> f (g x) = x" "\<And>x. P x \<Longrightarrow> Q (g x)"
hoelzl@51471
   695
  assumes Q: "eventually Q (at_left a)" and bound: "\<And>b. Q b \<Longrightarrow> b < a"
hoelzl@51471
   696
  assumes P: "eventually P at_top"
hoelzl@51471
   697
  shows "filterlim f at_top (at_left a)"
hoelzl@51471
   698
proof -
hoelzl@51471
   699
  from P obtain x where x: "\<And>y. x \<le> y \<Longrightarrow> P y"
hoelzl@51471
   700
    unfolding eventually_at_top_linorder by auto
hoelzl@51471
   701
  show ?thesis
hoelzl@51471
   702
  proof (intro filterlim_at_top_ge[THEN iffD2] allI impI)
hoelzl@51471
   703
    fix z assume "x \<le> z"
hoelzl@51471
   704
    with x have "P z" by auto
hoelzl@51471
   705
    have "eventually (\<lambda>x. g z \<le> x) (at_left a)"
wenzelm@60758
   706
      using bound[OF bij(2)[OF \<open>P z\<close>]]
wenzelm@60758
   707
      unfolding eventually_at_left[OF bound[OF bij(2)[OF \<open>P z\<close>]]] by (auto intro!: exI[of _ "g z"])
hoelzl@51471
   708
    with Q show "eventually (\<lambda>x. z \<le> f x) (at_left a)"
wenzelm@60758
   709
      by eventually_elim (metis bij \<open>P z\<close> mono)
hoelzl@51471
   710
  qed
hoelzl@51471
   711
qed
hoelzl@51471
   712
hoelzl@51471
   713
lemma filterlim_split_at:
hoelzl@51471
   714
  "filterlim f F (at_left x) \<Longrightarrow> filterlim f F (at_right x) \<Longrightarrow> filterlim f F (at (x::'a::linorder_topology))"
hoelzl@51471
   715
  by (subst at_eq_sup_left_right) (rule filterlim_sup)
hoelzl@51471
   716
hoelzl@51471
   717
lemma filterlim_at_split:
hoelzl@51471
   718
  "filterlim f F (at (x::'a::linorder_topology)) \<longleftrightarrow> filterlim f F (at_left x) \<and> filterlim f F (at_right x)"
hoelzl@51471
   719
  by (subst at_eq_sup_left_right) (simp add: filterlim_def filtermap_sup)
hoelzl@51471
   720
hoelzl@57025
   721
lemma eventually_nhds_top:
hoelzl@57025
   722
  fixes P :: "'a :: {order_top, linorder_topology} \<Rightarrow> bool"
hoelzl@57025
   723
  assumes "(b::'a) < top"
hoelzl@57025
   724
  shows "eventually P (nhds top) \<longleftrightarrow> (\<exists>b<top. (\<forall>z. b < z \<longrightarrow> P z))"
hoelzl@57025
   725
  unfolding eventually_nhds
hoelzl@57025
   726
proof safe
hoelzl@57025
   727
  fix S :: "'a set" assume "open S" "top \<in> S"
wenzelm@60758
   728
  note open_left[OF this \<open>b < top\<close>]
hoelzl@57025
   729
  moreover assume "\<forall>s\<in>S. P s"
hoelzl@57025
   730
  ultimately show "\<exists>b<top. \<forall>z>b. P z"
hoelzl@57025
   731
    by (auto simp: subset_eq Ball_def)
hoelzl@57025
   732
next
hoelzl@57025
   733
  fix b assume "b < top" "\<forall>z>b. P z"
hoelzl@57025
   734
  then show "\<exists>S. open S \<and> top \<in> S \<and> (\<forall>xa\<in>S. P xa)"
hoelzl@57025
   735
    by (intro exI[of _ "{b <..}"]) auto
hoelzl@57025
   736
qed
hoelzl@51471
   737
hoelzl@57447
   738
lemma tendsto_at_within_iff_tendsto_nhds:
hoelzl@57447
   739
  "(g ---> g l) (at l within S) \<longleftrightarrow> (g ---> g l) (inf (nhds l) (principal S))"
hoelzl@57447
   740
  unfolding tendsto_def eventually_at_filter eventually_inf_principal
hoelzl@57447
   741
  by (intro ext all_cong imp_cong) (auto elim!: eventually_elim1)
hoelzl@57447
   742
wenzelm@60758
   743
subsection \<open>Limits on sequences\<close>
hoelzl@51471
   744
hoelzl@51471
   745
abbreviation (in topological_space)
hoelzl@51471
   746
  LIMSEQ :: "[nat \<Rightarrow> 'a, 'a] \<Rightarrow> bool"
hoelzl@51471
   747
    ("((_)/ ----> (_))" [60, 60] 60) where
hoelzl@51471
   748
  "X ----> L \<equiv> (X ---> L) sequentially"
hoelzl@51471
   749
hoelzl@51478
   750
abbreviation (in t2_space) lim :: "(nat \<Rightarrow> 'a) \<Rightarrow> 'a" where
hoelzl@51478
   751
  "lim X \<equiv> Lim sequentially X"
hoelzl@51471
   752
hoelzl@51471
   753
definition (in topological_space) convergent :: "(nat \<Rightarrow> 'a) \<Rightarrow> bool" where
hoelzl@51471
   754
  "convergent X = (\<exists>L. X ----> L)"
hoelzl@51471
   755
hoelzl@51478
   756
lemma lim_def: "lim X = (THE L. X ----> L)"
hoelzl@51478
   757
  unfolding Lim_def ..
hoelzl@51478
   758
wenzelm@60758
   759
subsubsection \<open>Monotone sequences and subsequences\<close>
hoelzl@51471
   760
hoelzl@51471
   761
definition
hoelzl@51471
   762
  monoseq :: "(nat \<Rightarrow> 'a::order) \<Rightarrow> bool" where
wenzelm@60758
   763
    --\<open>Definition of monotonicity.
hoelzl@51471
   764
        The use of disjunction here complicates proofs considerably.
hoelzl@51471
   765
        One alternative is to add a Boolean argument to indicate the direction.
wenzelm@60758
   766
        Another is to develop the notions of increasing and decreasing first.\<close>
hoelzl@56020
   767
  "monoseq X = ((\<forall>m. \<forall>n\<ge>m. X m \<le> X n) \<or> (\<forall>m. \<forall>n\<ge>m. X n \<le> X m))"
hoelzl@56020
   768
hoelzl@56020
   769
abbreviation incseq :: "(nat \<Rightarrow> 'a::order) \<Rightarrow> bool" where
hoelzl@56020
   770
  "incseq X \<equiv> mono X"
hoelzl@56020
   771
hoelzl@56020
   772
lemma incseq_def: "incseq X \<longleftrightarrow> (\<forall>m. \<forall>n\<ge>m. X n \<ge> X m)"
hoelzl@56020
   773
  unfolding mono_def ..
hoelzl@56020
   774
hoelzl@56020
   775
abbreviation decseq :: "(nat \<Rightarrow> 'a::order) \<Rightarrow> bool" where
hoelzl@56020
   776
  "decseq X \<equiv> antimono X"
hoelzl@56020
   777
hoelzl@56020
   778
lemma decseq_def: "decseq X \<longleftrightarrow> (\<forall>m. \<forall>n\<ge>m. X n \<le> X m)"
hoelzl@56020
   779
  unfolding antimono_def ..
hoelzl@51471
   780
hoelzl@51471
   781
definition
hoelzl@51471
   782
  subseq :: "(nat \<Rightarrow> nat) \<Rightarrow> bool" where
wenzelm@60758
   783
    --\<open>Definition of subsequence\<close>
hoelzl@51471
   784
  "subseq f \<longleftrightarrow> (\<forall>m. \<forall>n>m. f m < f n)"
hoelzl@51471
   785
hoelzl@51471
   786
lemma incseq_SucI:
hoelzl@51471
   787
  "(\<And>n. X n \<le> X (Suc n)) \<Longrightarrow> incseq X"
hoelzl@51471
   788
  using lift_Suc_mono_le[of X]
hoelzl@51471
   789
  by (auto simp: incseq_def)
hoelzl@51471
   790
hoelzl@51471
   791
lemma incseqD: "\<And>i j. incseq f \<Longrightarrow> i \<le> j \<Longrightarrow> f i \<le> f j"
hoelzl@51471
   792
  by (auto simp: incseq_def)
hoelzl@51471
   793
hoelzl@51471
   794
lemma incseq_SucD: "incseq A \<Longrightarrow> A i \<le> A (Suc i)"
hoelzl@51471
   795
  using incseqD[of A i "Suc i"] by auto
hoelzl@51471
   796
hoelzl@51471
   797
lemma incseq_Suc_iff: "incseq f \<longleftrightarrow> (\<forall>n. f n \<le> f (Suc n))"
hoelzl@51471
   798
  by (auto intro: incseq_SucI dest: incseq_SucD)
hoelzl@51471
   799
hoelzl@51471
   800
lemma incseq_const[simp, intro]: "incseq (\<lambda>x. k)"
hoelzl@51471
   801
  unfolding incseq_def by auto
hoelzl@51471
   802
hoelzl@51471
   803
lemma decseq_SucI:
hoelzl@51471
   804
  "(\<And>n. X (Suc n) \<le> X n) \<Longrightarrow> decseq X"
hoelzl@51471
   805
  using order.lift_Suc_mono_le[OF dual_order, of X]
hoelzl@51471
   806
  by (auto simp: decseq_def)
hoelzl@51471
   807
hoelzl@51471
   808
lemma decseqD: "\<And>i j. decseq f \<Longrightarrow> i \<le> j \<Longrightarrow> f j \<le> f i"
hoelzl@51471
   809
  by (auto simp: decseq_def)
hoelzl@51471
   810
hoelzl@51471
   811
lemma decseq_SucD: "decseq A \<Longrightarrow> A (Suc i) \<le> A i"
hoelzl@51471
   812
  using decseqD[of A i "Suc i"] by auto
hoelzl@51471
   813
hoelzl@51471
   814
lemma decseq_Suc_iff: "decseq f \<longleftrightarrow> (\<forall>n. f (Suc n) \<le> f n)"
hoelzl@51471
   815
  by (auto intro: decseq_SucI dest: decseq_SucD)
hoelzl@51471
   816
hoelzl@51471
   817
lemma decseq_const[simp, intro]: "decseq (\<lambda>x. k)"
hoelzl@51471
   818
  unfolding decseq_def by auto
hoelzl@51471
   819
hoelzl@51471
   820
lemma monoseq_iff: "monoseq X \<longleftrightarrow> incseq X \<or> decseq X"
hoelzl@51471
   821
  unfolding monoseq_def incseq_def decseq_def ..
hoelzl@51471
   822
hoelzl@51471
   823
lemma monoseq_Suc:
hoelzl@51471
   824
  "monoseq X \<longleftrightarrow> (\<forall>n. X n \<le> X (Suc n)) \<or> (\<forall>n. X (Suc n) \<le> X n)"
hoelzl@51471
   825
  unfolding monoseq_iff incseq_Suc_iff decseq_Suc_iff ..
hoelzl@51471
   826
hoelzl@51471
   827
lemma monoI1: "\<forall>m. \<forall> n \<ge> m. X m \<le> X n ==> monoseq X"
hoelzl@51471
   828
by (simp add: monoseq_def)
hoelzl@51471
   829
hoelzl@51471
   830
lemma monoI2: "\<forall>m. \<forall> n \<ge> m. X n \<le> X m ==> monoseq X"
hoelzl@51471
   831
by (simp add: monoseq_def)
hoelzl@51471
   832
hoelzl@51471
   833
lemma mono_SucI1: "\<forall>n. X n \<le> X (Suc n) ==> monoseq X"
hoelzl@51471
   834
by (simp add: monoseq_Suc)
hoelzl@51471
   835
hoelzl@51471
   836
lemma mono_SucI2: "\<forall>n. X (Suc n) \<le> X n ==> monoseq X"
hoelzl@51471
   837
by (simp add: monoseq_Suc)
hoelzl@51471
   838
hoelzl@51471
   839
lemma monoseq_minus:
hoelzl@51471
   840
  fixes a :: "nat \<Rightarrow> 'a::ordered_ab_group_add"
hoelzl@51471
   841
  assumes "monoseq a"
hoelzl@51471
   842
  shows "monoseq (\<lambda> n. - a n)"
hoelzl@51471
   843
proof (cases "\<forall> m. \<forall> n \<ge> m. a m \<le> a n")
hoelzl@51471
   844
  case True
hoelzl@51471
   845
  hence "\<forall> m. \<forall> n \<ge> m. - a n \<le> - a m" by auto
hoelzl@51471
   846
  thus ?thesis by (rule monoI2)
hoelzl@51471
   847
next
hoelzl@51471
   848
  case False
wenzelm@60758
   849
  hence "\<forall> m. \<forall> n \<ge> m. - a m \<le> - a n" using \<open>monoseq a\<close>[unfolded monoseq_def] by auto
hoelzl@51471
   850
  thus ?thesis by (rule monoI1)
hoelzl@51471
   851
qed
hoelzl@51471
   852
wenzelm@60758
   853
text\<open>Subsequence (alternative definition, (e.g. Hoskins)\<close>
hoelzl@51471
   854
hoelzl@51471
   855
lemma subseq_Suc_iff: "subseq f = (\<forall>n. (f n) < (f (Suc n)))"
hoelzl@51471
   856
apply (simp add: subseq_def)
hoelzl@51471
   857
apply (auto dest!: less_imp_Suc_add)
hoelzl@51471
   858
apply (induct_tac k)
hoelzl@51471
   859
apply (auto intro: less_trans)
hoelzl@51471
   860
done
hoelzl@51471
   861
wenzelm@60758
   862
text\<open>for any sequence, there is a monotonic subsequence\<close>
hoelzl@51471
   863
lemma seq_monosub:
hoelzl@51471
   864
  fixes s :: "nat => 'a::linorder"
hoelzl@57448
   865
  shows "\<exists>f. subseq f \<and> monoseq (\<lambda>n. (s (f n)))"
hoelzl@51471
   866
proof cases
hoelzl@57448
   867
  assume "\<forall>n. \<exists>p>n. \<forall>m\<ge>p. s m \<le> s p"
hoelzl@57448
   868
  then have "\<exists>f. \<forall>n. (\<forall>m\<ge>f n. s m \<le> s (f n)) \<and> f n < f (Suc n)"
hoelzl@57448
   869
    by (intro dependent_nat_choice) (auto simp: conj_commute)
hoelzl@57448
   870
  then obtain f where "subseq f" and mono: "\<And>n m. f n \<le> m \<Longrightarrow> s m \<le> s (f n)"
hoelzl@57448
   871
    by (auto simp: subseq_Suc_iff)
hoelzl@57448
   872
  moreover 
hoelzl@57448
   873
  then have "incseq f"
hoelzl@57448
   874
    unfolding subseq_Suc_iff incseq_Suc_iff by (auto intro: less_imp_le)
hoelzl@57448
   875
  then have "monoseq (\<lambda>n. s (f n))"
hoelzl@57448
   876
    by (auto simp add: incseq_def intro!: mono monoI2)
hoelzl@57448
   877
  ultimately show ?thesis
hoelzl@57448
   878
    by auto
hoelzl@51471
   879
next
hoelzl@51471
   880
  assume "\<not> (\<forall>n. \<exists>p>n. (\<forall>m\<ge>p. s m \<le> s p))"
hoelzl@51471
   881
  then obtain N where N: "\<And>p. p > N \<Longrightarrow> \<exists>m>p. s p < s m" by (force simp: not_le le_less)
hoelzl@57448
   882
  have "\<exists>f. \<forall>n. N < f n \<and> f n < f (Suc n) \<and> s (f n) \<le> s (f (Suc n))"
hoelzl@57448
   883
  proof (intro dependent_nat_choice)
hoelzl@57448
   884
    fix x assume "N < x" with N[of x] show "\<exists>y>N. x < y \<and> s x \<le> s y"
hoelzl@57448
   885
      by (auto intro: less_trans)
hoelzl@57448
   886
  qed auto
hoelzl@57448
   887
  then show ?thesis
hoelzl@57448
   888
    by (auto simp: monoseq_iff incseq_Suc_iff subseq_Suc_iff)
hoelzl@51471
   889
qed
hoelzl@51471
   890
hoelzl@51471
   891
lemma seq_suble: assumes sf: "subseq f" shows "n \<le> f n"
hoelzl@51471
   892
proof(induct n)
hoelzl@51471
   893
  case 0 thus ?case by simp
hoelzl@51471
   894
next
hoelzl@51471
   895
  case (Suc n)
hoelzl@51471
   896
  from sf[unfolded subseq_Suc_iff, rule_format, of n] Suc.hyps
hoelzl@51471
   897
  have "n < f (Suc n)" by arith
hoelzl@51471
   898
  thus ?case by arith
hoelzl@51471
   899
qed
hoelzl@51471
   900
hoelzl@51471
   901
lemma eventually_subseq:
hoelzl@51471
   902
  "subseq r \<Longrightarrow> eventually P sequentially \<Longrightarrow> eventually (\<lambda>n. P (r n)) sequentially"
hoelzl@51471
   903
  unfolding eventually_sequentially by (metis seq_suble le_trans)
hoelzl@51471
   904
hoelzl@51473
   905
lemma not_eventually_sequentiallyD:
hoelzl@51473
   906
  assumes P: "\<not> eventually P sequentially"
hoelzl@51473
   907
  shows "\<exists>r. subseq r \<and> (\<forall>n. \<not> P (r n))"
hoelzl@51473
   908
proof -
hoelzl@51473
   909
  from P have "\<forall>n. \<exists>m\<ge>n. \<not> P m"
hoelzl@51473
   910
    unfolding eventually_sequentially by (simp add: not_less)
hoelzl@51473
   911
  then obtain r where "\<And>n. r n \<ge> n" "\<And>n. \<not> P (r n)"
hoelzl@51473
   912
    by (auto simp: choice_iff)
hoelzl@51473
   913
  then show ?thesis
hoelzl@51473
   914
    by (auto intro!: exI[of _ "\<lambda>n. r (((Suc \<circ> r) ^^ Suc n) 0)"]
hoelzl@51473
   915
             simp: less_eq_Suc_le subseq_Suc_iff)
hoelzl@51473
   916
qed
hoelzl@51473
   917
hoelzl@51471
   918
lemma filterlim_subseq: "subseq f \<Longrightarrow> filterlim f sequentially sequentially"
hoelzl@51471
   919
  unfolding filterlim_iff by (metis eventually_subseq)
hoelzl@51471
   920
hoelzl@51471
   921
lemma subseq_o: "subseq r \<Longrightarrow> subseq s \<Longrightarrow> subseq (r \<circ> s)"
hoelzl@51471
   922
  unfolding subseq_def by simp
hoelzl@51471
   923
hoelzl@51471
   924
lemma subseq_mono: assumes "subseq r" "m < n" shows "r m < r n"
hoelzl@51471
   925
  using assms by (auto simp: subseq_def)
hoelzl@51471
   926
hoelzl@51471
   927
lemma incseq_imp_monoseq:  "incseq X \<Longrightarrow> monoseq X"
hoelzl@51471
   928
  by (simp add: incseq_def monoseq_def)
hoelzl@51471
   929
hoelzl@51471
   930
lemma decseq_imp_monoseq:  "decseq X \<Longrightarrow> monoseq X"
hoelzl@51471
   931
  by (simp add: decseq_def monoseq_def)
hoelzl@51471
   932
hoelzl@51471
   933
lemma decseq_eq_incseq:
hoelzl@51471
   934
  fixes X :: "nat \<Rightarrow> 'a::ordered_ab_group_add" shows "decseq X = incseq (\<lambda>n. - X n)" 
hoelzl@51471
   935
  by (simp add: decseq_def incseq_def)
hoelzl@51471
   936
hoelzl@51471
   937
lemma INT_decseq_offset:
hoelzl@51471
   938
  assumes "decseq F"
hoelzl@51471
   939
  shows "(\<Inter>i. F i) = (\<Inter>i\<in>{n..}. F i)"
hoelzl@51471
   940
proof safe
hoelzl@51471
   941
  fix x i assume x: "x \<in> (\<Inter>i\<in>{n..}. F i)"
hoelzl@51471
   942
  show "x \<in> F i"
hoelzl@51471
   943
  proof cases
hoelzl@51471
   944
    from x have "x \<in> F n" by auto
wenzelm@60758
   945
    also assume "i \<le> n" with \<open>decseq F\<close> have "F n \<subseteq> F i"
hoelzl@51471
   946
      unfolding decseq_def by simp
hoelzl@51471
   947
    finally show ?thesis .
hoelzl@51471
   948
  qed (insert x, simp)
hoelzl@51471
   949
qed auto
hoelzl@51471
   950
hoelzl@51471
   951
lemma LIMSEQ_const_iff:
hoelzl@51471
   952
  fixes k l :: "'a::t2_space"
hoelzl@51471
   953
  shows "(\<lambda>n. k) ----> l \<longleftrightarrow> k = l"
hoelzl@51471
   954
  using trivial_limit_sequentially by (rule tendsto_const_iff)
hoelzl@51471
   955
hoelzl@51471
   956
lemma LIMSEQ_SUP:
hoelzl@51471
   957
  "incseq X \<Longrightarrow> X ----> (SUP i. X i :: 'a :: {complete_linorder, linorder_topology})"
hoelzl@51471
   958
  by (intro increasing_tendsto)
hoelzl@51471
   959
     (auto simp: SUP_upper less_SUP_iff incseq_def eventually_sequentially intro: less_le_trans)
hoelzl@51471
   960
hoelzl@51471
   961
lemma LIMSEQ_INF:
hoelzl@51471
   962
  "decseq X \<Longrightarrow> X ----> (INF i. X i :: 'a :: {complete_linorder, linorder_topology})"
hoelzl@51471
   963
  by (intro decreasing_tendsto)
hoelzl@51471
   964
     (auto simp: INF_lower INF_less_iff decseq_def eventually_sequentially intro: le_less_trans)
hoelzl@51471
   965
hoelzl@51471
   966
lemma LIMSEQ_ignore_initial_segment:
hoelzl@51471
   967
  "f ----> a \<Longrightarrow> (\<lambda>n. f (n + k)) ----> a"
hoelzl@51474
   968
  unfolding tendsto_def
hoelzl@51474
   969
  by (subst eventually_sequentially_seg[where k=k])
hoelzl@51471
   970
hoelzl@51471
   971
lemma LIMSEQ_offset:
hoelzl@51471
   972
  "(\<lambda>n. f (n + k)) ----> a \<Longrightarrow> f ----> a"
hoelzl@51474
   973
  unfolding tendsto_def
hoelzl@51474
   974
  by (subst (asm) eventually_sequentially_seg[where k=k])
hoelzl@51471
   975
hoelzl@51471
   976
lemma LIMSEQ_Suc: "f ----> l \<Longrightarrow> (\<lambda>n. f (Suc n)) ----> l"
hoelzl@51471
   977
by (drule_tac k="Suc 0" in LIMSEQ_ignore_initial_segment, simp)
hoelzl@51471
   978
hoelzl@51471
   979
lemma LIMSEQ_imp_Suc: "(\<lambda>n. f (Suc n)) ----> l \<Longrightarrow> f ----> l"
hoelzl@51471
   980
by (rule_tac k="Suc 0" in LIMSEQ_offset, simp)
hoelzl@51471
   981
hoelzl@51471
   982
lemma LIMSEQ_Suc_iff: "(\<lambda>n. f (Suc n)) ----> l = f ----> l"
hoelzl@51471
   983
by (blast intro: LIMSEQ_imp_Suc LIMSEQ_Suc)
hoelzl@51471
   984
hoelzl@51471
   985
lemma LIMSEQ_unique:
hoelzl@51471
   986
  fixes a b :: "'a::t2_space"
hoelzl@51471
   987
  shows "\<lbrakk>X ----> a; X ----> b\<rbrakk> \<Longrightarrow> a = b"
hoelzl@51471
   988
  using trivial_limit_sequentially by (rule tendsto_unique)
hoelzl@51471
   989
hoelzl@51471
   990
lemma LIMSEQ_le_const:
hoelzl@51471
   991
  "\<lbrakk>X ----> (x::'a::linorder_topology); \<exists>N. \<forall>n\<ge>N. a \<le> X n\<rbrakk> \<Longrightarrow> a \<le> x"
hoelzl@51471
   992
  using tendsto_le_const[of sequentially X x a] by (simp add: eventually_sequentially)
hoelzl@51471
   993
hoelzl@51471
   994
lemma LIMSEQ_le:
hoelzl@51471
   995
  "\<lbrakk>X ----> x; Y ----> y; \<exists>N. \<forall>n\<ge>N. X n \<le> Y n\<rbrakk> \<Longrightarrow> x \<le> (y::'a::linorder_topology)"
hoelzl@51471
   996
  using tendsto_le[of sequentially Y y X x] by (simp add: eventually_sequentially)
hoelzl@51471
   997
hoelzl@51471
   998
lemma LIMSEQ_le_const2:
hoelzl@51471
   999
  "\<lbrakk>X ----> (x::'a::linorder_topology); \<exists>N. \<forall>n\<ge>N. X n \<le> a\<rbrakk> \<Longrightarrow> x \<le> a"
hoelzl@58729
  1000
  by (rule LIMSEQ_le[of X x "\<lambda>n. a"]) auto
hoelzl@51471
  1001
hoelzl@51471
  1002
lemma convergentD: "convergent X ==> \<exists>L. (X ----> L)"
hoelzl@51471
  1003
by (simp add: convergent_def)
hoelzl@51471
  1004
hoelzl@51471
  1005
lemma convergentI: "(X ----> L) ==> convergent X"
hoelzl@51471
  1006
by (auto simp add: convergent_def)
hoelzl@51471
  1007
hoelzl@51471
  1008
lemma convergent_LIMSEQ_iff: "convergent X = (X ----> lim X)"
hoelzl@51471
  1009
by (auto intro: theI LIMSEQ_unique simp add: convergent_def lim_def)
hoelzl@51471
  1010
hoelzl@51471
  1011
lemma convergent_const: "convergent (\<lambda>n. c)"
hoelzl@51471
  1012
  by (rule convergentI, rule tendsto_const)
hoelzl@51471
  1013
hoelzl@51471
  1014
lemma monoseq_le:
hoelzl@51471
  1015
  "monoseq a \<Longrightarrow> a ----> (x::'a::linorder_topology) \<Longrightarrow>
hoelzl@51471
  1016
    ((\<forall> n. a n \<le> x) \<and> (\<forall>m. \<forall>n\<ge>m. a m \<le> a n)) \<or> ((\<forall> n. x \<le> a n) \<and> (\<forall>m. \<forall>n\<ge>m. a n \<le> a m))"
hoelzl@51471
  1017
  by (metis LIMSEQ_le_const LIMSEQ_le_const2 decseq_def incseq_def monoseq_iff)
hoelzl@51471
  1018
hoelzl@51471
  1019
lemma LIMSEQ_subseq_LIMSEQ:
hoelzl@51471
  1020
  "\<lbrakk> X ----> L; subseq f \<rbrakk> \<Longrightarrow> (X o f) ----> L"
hoelzl@51471
  1021
  unfolding comp_def by (rule filterlim_compose[of X, OF _ filterlim_subseq])
hoelzl@51471
  1022
hoelzl@51471
  1023
lemma convergent_subseq_convergent:
hoelzl@51471
  1024
  "\<lbrakk>convergent X; subseq f\<rbrakk> \<Longrightarrow> convergent (X o f)"
hoelzl@51471
  1025
  unfolding convergent_def by (auto intro: LIMSEQ_subseq_LIMSEQ)
hoelzl@51471
  1026
hoelzl@51471
  1027
lemma limI: "X ----> L ==> lim X = L"
hoelzl@57276
  1028
  by (rule tendsto_Lim) (rule trivial_limit_sequentially)
hoelzl@51471
  1029
hoelzl@51471
  1030
lemma lim_le: "convergent f \<Longrightarrow> (\<And>n. f n \<le> (x::'a::linorder_topology)) \<Longrightarrow> lim f \<le> x"
hoelzl@51471
  1031
  using LIMSEQ_le_const2[of f "lim f" x] by (simp add: convergent_LIMSEQ_iff)
hoelzl@51471
  1032
wenzelm@60758
  1033
subsubsection\<open>Increasing and Decreasing Series\<close>
hoelzl@51471
  1034
hoelzl@51471
  1035
lemma incseq_le: "incseq X \<Longrightarrow> X ----> L \<Longrightarrow> X n \<le> (L::'a::linorder_topology)"
hoelzl@51471
  1036
  by (metis incseq_def LIMSEQ_le_const)
hoelzl@51471
  1037
hoelzl@51471
  1038
lemma decseq_le: "decseq X \<Longrightarrow> X ----> L \<Longrightarrow> (L::'a::linorder_topology) \<le> X n"
hoelzl@51471
  1039
  by (metis decseq_def LIMSEQ_le_const2)
hoelzl@51471
  1040
wenzelm@60758
  1041
subsection \<open>First countable topologies\<close>
hoelzl@51473
  1042
hoelzl@51473
  1043
class first_countable_topology = topological_space +
hoelzl@51473
  1044
  assumes first_countable_basis:
hoelzl@51473
  1045
    "\<exists>A::nat \<Rightarrow> 'a set. (\<forall>i. x \<in> A i \<and> open (A i)) \<and> (\<forall>S. open S \<and> x \<in> S \<longrightarrow> (\<exists>i. A i \<subseteq> S))"
hoelzl@51473
  1046
hoelzl@51473
  1047
lemma (in first_countable_topology) countable_basis_at_decseq:
hoelzl@51473
  1048
  obtains A :: "nat \<Rightarrow> 'a set" where
hoelzl@51473
  1049
    "\<And>i. open (A i)" "\<And>i. x \<in> (A i)"
hoelzl@51473
  1050
    "\<And>S. open S \<Longrightarrow> x \<in> S \<Longrightarrow> eventually (\<lambda>i. A i \<subseteq> S) sequentially"
hoelzl@51473
  1051
proof atomize_elim
hoelzl@51473
  1052
  from first_countable_basis[of x] obtain A :: "nat \<Rightarrow> 'a set" where
hoelzl@51473
  1053
    nhds: "\<And>i. open (A i)" "\<And>i. x \<in> A i"
hoelzl@51473
  1054
    and incl: "\<And>S. open S \<Longrightarrow> x \<in> S \<Longrightarrow> \<exists>i. A i \<subseteq> S"  by auto
hoelzl@51473
  1055
  def F \<equiv> "\<lambda>n. \<Inter>i\<le>n. A i"
hoelzl@51473
  1056
  show "\<exists>A. (\<forall>i. open (A i)) \<and> (\<forall>i. x \<in> A i) \<and>
hoelzl@51473
  1057
      (\<forall>S. open S \<longrightarrow> x \<in> S \<longrightarrow> eventually (\<lambda>i. A i \<subseteq> S) sequentially)"
hoelzl@51473
  1058
  proof (safe intro!: exI[of _ F])
hoelzl@51473
  1059
    fix i
hoelzl@51480
  1060
    show "open (F i)" using nhds(1) by (auto simp: F_def)
hoelzl@51473
  1061
    show "x \<in> F i" using nhds(2) by (auto simp: F_def)
hoelzl@51473
  1062
  next
hoelzl@51473
  1063
    fix S assume "open S" "x \<in> S"
hoelzl@51473
  1064
    from incl[OF this] obtain i where "F i \<subseteq> S" unfolding F_def by auto
hoelzl@51473
  1065
    moreover have "\<And>j. i \<le> j \<Longrightarrow> F j \<subseteq> F i"
hoelzl@51473
  1066
      by (auto simp: F_def)
hoelzl@51473
  1067
    ultimately show "eventually (\<lambda>i. F i \<subseteq> S) sequentially"
hoelzl@51473
  1068
      by (auto simp: eventually_sequentially)
hoelzl@51473
  1069
  qed
hoelzl@51473
  1070
qed
hoelzl@51473
  1071
hoelzl@57448
  1072
lemma (in first_countable_topology) nhds_countable:
hoelzl@57448
  1073
  obtains X :: "nat \<Rightarrow> 'a set"
hoelzl@57448
  1074
  where "decseq X" "\<And>n. open (X n)" "\<And>n. x \<in> X n" "nhds x = (INF n. principal (X n))"
hoelzl@57448
  1075
proof -
hoelzl@57448
  1076
  from first_countable_basis obtain A :: "nat \<Rightarrow> 'a set"
hoelzl@57448
  1077
    where A: "\<And>n. x \<in> A n" "\<And>n. open (A n)" "\<And>S. open S \<Longrightarrow> x \<in> S \<Longrightarrow> \<exists>i. A i \<subseteq> S"
hoelzl@57448
  1078
    by metis
hoelzl@57448
  1079
  show thesis
hoelzl@57448
  1080
  proof
hoelzl@57448
  1081
    show "decseq (\<lambda>n. \<Inter>i\<le>n. A i)"
hoelzl@57448
  1082
      by (auto simp: decseq_def)
hoelzl@57448
  1083
    show "\<And>n. x \<in> (\<Inter>i\<le>n. A i)" "\<And>n. open (\<Inter>i\<le>n. A i)"
hoelzl@57448
  1084
      using A by auto
wenzelm@60585
  1085
    show "nhds x = (INF n. principal (\<Inter>i\<le>n. A i))"
hoelzl@57448
  1086
      using A unfolding nhds_def
hoelzl@57448
  1087
      apply (intro INF_eq)
hoelzl@57448
  1088
      apply simp_all
hoelzl@57448
  1089
      apply force
wenzelm@60585
  1090
      apply (intro exI[of _ "\<Inter>i\<le>n. A i" for n] conjI open_INT)
hoelzl@57448
  1091
      apply auto
hoelzl@57448
  1092
      done
hoelzl@57448
  1093
  qed
hoelzl@57448
  1094
qed
hoelzl@57448
  1095
hoelzl@51473
  1096
lemma (in first_countable_topology) countable_basis:
hoelzl@51473
  1097
  obtains A :: "nat \<Rightarrow> 'a set" where
hoelzl@51473
  1098
    "\<And>i. open (A i)" "\<And>i. x \<in> A i"
hoelzl@51473
  1099
    "\<And>F. (\<forall>n. F n \<in> A n) \<Longrightarrow> F ----> x"
hoelzl@51473
  1100
proof atomize_elim
wenzelm@53381
  1101
  obtain A :: "nat \<Rightarrow> 'a set" where A:
wenzelm@53381
  1102
    "\<And>i. open (A i)"
wenzelm@53381
  1103
    "\<And>i. x \<in> A i"
wenzelm@53381
  1104
    "\<And>S. open S \<Longrightarrow> x \<in> S \<Longrightarrow> eventually (\<lambda>i. A i \<subseteq> S) sequentially"
wenzelm@53381
  1105
    by (rule countable_basis_at_decseq) blast
wenzelm@53381
  1106
  {
wenzelm@53381
  1107
    fix F S assume "\<forall>n. F n \<in> A n" "open S" "x \<in> S"
hoelzl@51473
  1108
    with A(3)[of S] have "eventually (\<lambda>n. F n \<in> S) sequentially"
wenzelm@53381
  1109
      by (auto elim: eventually_elim1 simp: subset_eq)
wenzelm@53381
  1110
  }
hoelzl@51473
  1111
  with A show "\<exists>A. (\<forall>i. open (A i)) \<and> (\<forall>i. x \<in> A i) \<and> (\<forall>F. (\<forall>n. F n \<in> A n) \<longrightarrow> F ----> x)"
hoelzl@51473
  1112
    by (intro exI[of _ A]) (auto simp: tendsto_def)
hoelzl@51473
  1113
qed
hoelzl@51473
  1114
hoelzl@51473
  1115
lemma (in first_countable_topology) sequentially_imp_eventually_nhds_within:
hoelzl@51473
  1116
  assumes "\<forall>f. (\<forall>n. f n \<in> s) \<and> f ----> a \<longrightarrow> eventually (\<lambda>n. P (f n)) sequentially"
hoelzl@51641
  1117
  shows "eventually P (inf (nhds a) (principal s))"
hoelzl@51473
  1118
proof (rule ccontr)
wenzelm@53381
  1119
  obtain A :: "nat \<Rightarrow> 'a set" where A:
wenzelm@53381
  1120
    "\<And>i. open (A i)"
wenzelm@53381
  1121
    "\<And>i. a \<in> A i"
wenzelm@53381
  1122
    "\<And>F. \<forall>n. F n \<in> A n \<Longrightarrow> F ----> a"
wenzelm@53381
  1123
    by (rule countable_basis) blast
wenzelm@53381
  1124
  assume "\<not> ?thesis"
hoelzl@51473
  1125
  with A have P: "\<exists>F. \<forall>n. F n \<in> s \<and> F n \<in> A n \<and> \<not> P (F n)"
hoelzl@51641
  1126
    unfolding eventually_inf_principal eventually_nhds by (intro choice) fastforce
wenzelm@53381
  1127
  then obtain F where F0: "\<forall>n. F n \<in> s" and F2: "\<forall>n. F n \<in> A n" and F3: "\<forall>n. \<not> P (F n)"
wenzelm@53381
  1128
    by blast
hoelzl@51473
  1129
  with A have "F ----> a" by auto
hoelzl@51473
  1130
  hence "eventually (\<lambda>n. P (F n)) sequentially"
hoelzl@51473
  1131
    using assms F0 by simp
hoelzl@51473
  1132
  thus "False" by (simp add: F3)
hoelzl@51473
  1133
qed
hoelzl@51473
  1134
hoelzl@51473
  1135
lemma (in first_countable_topology) eventually_nhds_within_iff_sequentially:
hoelzl@51641
  1136
  "eventually P (inf (nhds a) (principal s)) \<longleftrightarrow> 
hoelzl@51473
  1137
    (\<forall>f. (\<forall>n. f n \<in> s) \<and> f ----> a \<longrightarrow> eventually (\<lambda>n. P (f n)) sequentially)"
hoelzl@51473
  1138
proof (safe intro!: sequentially_imp_eventually_nhds_within)
hoelzl@51641
  1139
  assume "eventually P (inf (nhds a) (principal s))" 
hoelzl@51473
  1140
  then obtain S where "open S" "a \<in> S" "\<forall>x\<in>S. x \<in> s \<longrightarrow> P x"
hoelzl@51641
  1141
    by (auto simp: eventually_inf_principal eventually_nhds)
hoelzl@51473
  1142
  moreover fix f assume "\<forall>n. f n \<in> s" "f ----> a"
hoelzl@51473
  1143
  ultimately show "eventually (\<lambda>n. P (f n)) sequentially"
hoelzl@51473
  1144
    by (auto dest!: topological_tendstoD elim: eventually_elim1)
hoelzl@51473
  1145
qed
hoelzl@51473
  1146
hoelzl@51473
  1147
lemma (in first_countable_topology) eventually_nhds_iff_sequentially:
hoelzl@51473
  1148
  "eventually P (nhds a) \<longleftrightarrow> (\<forall>f. f ----> a \<longrightarrow> eventually (\<lambda>n. P (f n)) sequentially)"
hoelzl@51473
  1149
  using eventually_nhds_within_iff_sequentially[of P a UNIV] by simp
hoelzl@51473
  1150
hoelzl@57447
  1151
lemma tendsto_at_iff_sequentially:
hoelzl@57447
  1152
  fixes f :: "'a :: first_countable_topology \<Rightarrow> _"
hoelzl@57447
  1153
  shows "(f ---> a) (at x within s) \<longleftrightarrow> (\<forall>X. (\<forall>i. X i \<in> s - {x}) \<longrightarrow> X ----> x \<longrightarrow> ((f \<circ> X) ----> a))"
hoelzl@57447
  1154
  unfolding filterlim_def[of _ "nhds a"] le_filter_def eventually_filtermap at_within_def eventually_nhds_within_iff_sequentially comp_def
hoelzl@57447
  1155
  by metis
hoelzl@57447
  1156
wenzelm@60758
  1157
subsection \<open>Function limit at a point\<close>
hoelzl@51471
  1158
hoelzl@51471
  1159
abbreviation
hoelzl@51471
  1160
  LIM :: "('a::topological_space \<Rightarrow> 'b::topological_space) \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> bool"
hoelzl@51471
  1161
        ("((_)/ -- (_)/ --> (_))" [60, 0, 60] 60) where
hoelzl@51471
  1162
  "f -- a --> L \<equiv> (f ---> L) (at a)"
hoelzl@51471
  1163
hoelzl@51481
  1164
lemma tendsto_within_open: "a \<in> S \<Longrightarrow> open S \<Longrightarrow> (f ---> l) (at a within S) \<longleftrightarrow> (f -- a --> l)"
hoelzl@51641
  1165
  unfolding tendsto_def by (simp add: at_within_open[where S=S])
hoelzl@51481
  1166
hoelzl@51471
  1167
lemma LIM_const_not_eq[tendsto_intros]:
hoelzl@51471
  1168
  fixes a :: "'a::perfect_space"
hoelzl@51471
  1169
  fixes k L :: "'b::t2_space"
hoelzl@51471
  1170
  shows "k \<noteq> L \<Longrightarrow> \<not> (\<lambda>x. k) -- a --> L"
hoelzl@51471
  1171
  by (simp add: tendsto_const_iff)
hoelzl@51471
  1172
hoelzl@51471
  1173
lemmas LIM_not_zero = LIM_const_not_eq [where L = 0]
hoelzl@51471
  1174
hoelzl@51471
  1175
lemma LIM_const_eq:
hoelzl@51471
  1176
  fixes a :: "'a::perfect_space"
hoelzl@51471
  1177
  fixes k L :: "'b::t2_space"
hoelzl@51471
  1178
  shows "(\<lambda>x. k) -- a --> L \<Longrightarrow> k = L"
hoelzl@51471
  1179
  by (simp add: tendsto_const_iff)
hoelzl@51471
  1180
hoelzl@51471
  1181
lemma LIM_unique:
hoelzl@51471
  1182
  fixes a :: "'a::perfect_space" and L M :: "'b::t2_space"
hoelzl@51471
  1183
  shows "f -- a --> L \<Longrightarrow> f -- a --> M \<Longrightarrow> L = M"
hoelzl@51471
  1184
  using at_neq_bot by (rule tendsto_unique)
hoelzl@51471
  1185
wenzelm@60758
  1186
text \<open>Limits are equal for functions equal except at limit point\<close>
hoelzl@51471
  1187
hoelzl@51471
  1188
lemma LIM_equal: "\<forall>x. x \<noteq> a --> (f x = g x) \<Longrightarrow> (f -- a --> l) \<longleftrightarrow> (g -- a --> l)"
hoelzl@51471
  1189
  unfolding tendsto_def eventually_at_topological by simp
hoelzl@51471
  1190
hoelzl@51471
  1191
lemma LIM_cong: "a = b \<Longrightarrow> (\<And>x. x \<noteq> b \<Longrightarrow> f x = g x) \<Longrightarrow> l = m \<Longrightarrow> (f -- a --> l) \<longleftrightarrow> (g -- b --> m)"
hoelzl@51471
  1192
  by (simp add: LIM_equal)
hoelzl@51471
  1193
hoelzl@51471
  1194
lemma LIM_cong_limit: "f -- x --> L \<Longrightarrow> K = L \<Longrightarrow> f -- x --> K"
hoelzl@51471
  1195
  by simp
hoelzl@51471
  1196
hoelzl@51471
  1197
lemma tendsto_at_iff_tendsto_nhds:
hoelzl@51471
  1198
  "g -- l --> g l \<longleftrightarrow> (g ---> g l) (nhds l)"
hoelzl@51641
  1199
  unfolding tendsto_def eventually_at_filter
hoelzl@51471
  1200
  by (intro ext all_cong imp_cong) (auto elim!: eventually_elim1)
hoelzl@51471
  1201
hoelzl@51471
  1202
lemma tendsto_compose:
hoelzl@51471
  1203
  "g -- l --> g l \<Longrightarrow> (f ---> l) F \<Longrightarrow> ((\<lambda>x. g (f x)) ---> g l) F"
hoelzl@51471
  1204
  unfolding tendsto_at_iff_tendsto_nhds by (rule filterlim_compose[of g])
hoelzl@51471
  1205
hoelzl@51471
  1206
lemma LIM_o: "\<lbrakk>g -- l --> g l; f -- a --> l\<rbrakk> \<Longrightarrow> (g \<circ> f) -- a --> g l"
hoelzl@51471
  1207
  unfolding o_def by (rule tendsto_compose)
hoelzl@51471
  1208
hoelzl@51471
  1209
lemma tendsto_compose_eventually:
hoelzl@51471
  1210
  "g -- l --> m \<Longrightarrow> (f ---> l) F \<Longrightarrow> eventually (\<lambda>x. f x \<noteq> l) F \<Longrightarrow> ((\<lambda>x. g (f x)) ---> m) F"
hoelzl@51471
  1211
  by (rule filterlim_compose[of g _ "at l"]) (auto simp add: filterlim_at)
hoelzl@51471
  1212
hoelzl@51471
  1213
lemma LIM_compose_eventually:
hoelzl@51471
  1214
  assumes f: "f -- a --> b"
hoelzl@51471
  1215
  assumes g: "g -- b --> c"
hoelzl@51471
  1216
  assumes inj: "eventually (\<lambda>x. f x \<noteq> b) (at a)"
hoelzl@51471
  1217
  shows "(\<lambda>x. g (f x)) -- a --> c"
hoelzl@51471
  1218
  using g f inj by (rule tendsto_compose_eventually)
hoelzl@51471
  1219
hoelzl@57447
  1220
lemma tendsto_compose_filtermap: "((g \<circ> f) ---> T) F \<longleftrightarrow> (g ---> T) (filtermap f F)"
hoelzl@57447
  1221
  by (simp add: filterlim_def filtermap_filtermap comp_def)
hoelzl@57447
  1222
wenzelm@60758
  1223
subsubsection \<open>Relation of LIM and LIMSEQ\<close>
hoelzl@51473
  1224
hoelzl@51473
  1225
lemma (in first_countable_topology) sequentially_imp_eventually_within:
hoelzl@51473
  1226
  "(\<forall>f. (\<forall>n. f n \<in> s \<and> f n \<noteq> a) \<and> f ----> a \<longrightarrow> eventually (\<lambda>n. P (f n)) sequentially) \<Longrightarrow>
hoelzl@51473
  1227
    eventually P (at a within s)"
hoelzl@51641
  1228
  unfolding at_within_def
hoelzl@51473
  1229
  by (intro sequentially_imp_eventually_nhds_within) auto
hoelzl@51473
  1230
hoelzl@51473
  1231
lemma (in first_countable_topology) sequentially_imp_eventually_at:
hoelzl@51473
  1232
  "(\<forall>f. (\<forall>n. f n \<noteq> a) \<and> f ----> a \<longrightarrow> eventually (\<lambda>n. P (f n)) sequentially) \<Longrightarrow> eventually P (at a)"
hoelzl@51473
  1233
  using assms sequentially_imp_eventually_within [where s=UNIV] by simp
hoelzl@51473
  1234
hoelzl@51473
  1235
lemma LIMSEQ_SEQ_conv1:
hoelzl@51473
  1236
  fixes f :: "'a::topological_space \<Rightarrow> 'b::topological_space"
hoelzl@51473
  1237
  assumes f: "f -- a --> l"
hoelzl@51473
  1238
  shows "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. f (S n)) ----> l"
hoelzl@51473
  1239
  using tendsto_compose_eventually [OF f, where F=sequentially] by simp
hoelzl@51473
  1240
hoelzl@51473
  1241
lemma LIMSEQ_SEQ_conv2:
hoelzl@51473
  1242
  fixes f :: "'a::first_countable_topology \<Rightarrow> 'b::topological_space"
hoelzl@51473
  1243
  assumes "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. f (S n)) ----> l"
hoelzl@51473
  1244
  shows "f -- a --> l"
hoelzl@51473
  1245
  using assms unfolding tendsto_def [where l=l] by (simp add: sequentially_imp_eventually_at)
hoelzl@51473
  1246
hoelzl@51473
  1247
lemma LIMSEQ_SEQ_conv:
hoelzl@51473
  1248
  "(\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> (a::'a::first_countable_topology) \<longrightarrow> (\<lambda>n. X (S n)) ----> L) =
hoelzl@51473
  1249
   (X -- a --> (L::'b::topological_space))"
hoelzl@51473
  1250
  using LIMSEQ_SEQ_conv2 LIMSEQ_SEQ_conv1 ..
hoelzl@51473
  1251
hoelzl@57025
  1252
lemma sequentially_imp_eventually_at_left:
hoelzl@60172
  1253
  fixes a :: "'a :: {linorder_topology, first_countable_topology}"
hoelzl@57025
  1254
  assumes b[simp]: "b < a"
hoelzl@57025
  1255
  assumes *: "\<And>f. (\<And>n. b < f n) \<Longrightarrow> (\<And>n. f n < a) \<Longrightarrow> incseq f \<Longrightarrow> f ----> a \<Longrightarrow> eventually (\<lambda>n. P (f n)) sequentially"
hoelzl@57025
  1256
  shows "eventually P (at_left a)"
hoelzl@57025
  1257
proof (safe intro!: sequentially_imp_eventually_within)
hoelzl@57447
  1258
  fix X assume X: "\<forall>n. X n \<in> {..< a} \<and> X n \<noteq> a" "X ----> a"
hoelzl@57025
  1259
  show "eventually (\<lambda>n. P (X n)) sequentially"
hoelzl@57025
  1260
  proof (rule ccontr)
hoelzl@57447
  1261
    assume neg: "\<not> eventually (\<lambda>n. P (X n)) sequentially"
hoelzl@57447
  1262
    have "\<exists>s. \<forall>n. (\<not> P (X (s n)) \<and> b < X (s n)) \<and> (X (s n) \<le> X (s (Suc n)) \<and> Suc (s n) \<le> s (Suc n))"
hoelzl@57447
  1263
    proof (rule dependent_nat_choice)
hoelzl@57447
  1264
      have "\<not> eventually (\<lambda>n. b < X n \<longrightarrow> P (X n)) sequentially"
hoelzl@57447
  1265
        by (intro not_eventually_impI neg order_tendstoD(1) [OF X(2) b])
hoelzl@57447
  1266
      then show "\<exists>x. \<not> P (X x) \<and> b < X x"
hoelzl@57447
  1267
        by (auto dest!: not_eventuallyD)
hoelzl@57447
  1268
    next
hoelzl@57447
  1269
      fix x n
hoelzl@57447
  1270
      have "\<not> eventually (\<lambda>n. Suc x \<le> n \<longrightarrow> b < X n \<longrightarrow> X x < X n \<longrightarrow> P (X n)) sequentially"
hoelzl@57447
  1271
        using X by (intro not_eventually_impI order_tendstoD(1)[OF X(2)] eventually_ge_at_top neg) auto
hoelzl@57447
  1272
      then show "\<exists>n. (\<not> P (X n) \<and> b < X n) \<and> (X x \<le> X n \<and> Suc x \<le> n)"
hoelzl@57447
  1273
        by (auto dest!: not_eventuallyD)
hoelzl@57025
  1274
    qed
hoelzl@57447
  1275
    then guess s ..
hoelzl@57447
  1276
    then have "\<And>n. b < X (s n)" "\<And>n. X (s n) < a" "incseq (\<lambda>n. X (s n))" "(\<lambda>n. X (s n)) ----> a" "\<And>n. \<not> P (X (s n))"
wenzelm@60758
  1277
      using X by (auto simp: subseq_Suc_iff Suc_le_eq incseq_Suc_iff intro!: LIMSEQ_subseq_LIMSEQ[OF \<open>X ----> a\<close>, unfolded comp_def])
hoelzl@57447
  1278
    from *[OF this(1,2,3,4)] this(5) show False by auto
hoelzl@57025
  1279
  qed
hoelzl@57025
  1280
qed
hoelzl@57025
  1281
hoelzl@57025
  1282
lemma tendsto_at_left_sequentially:
hoelzl@60172
  1283
  fixes a :: "_ :: {linorder_topology, first_countable_topology}"
hoelzl@57025
  1284
  assumes "b < a"
hoelzl@57025
  1285
  assumes *: "\<And>S. (\<And>n. S n < a) \<Longrightarrow> (\<And>n. b < S n) \<Longrightarrow> incseq S \<Longrightarrow> S ----> a \<Longrightarrow> (\<lambda>n. X (S n)) ----> L"
hoelzl@57025
  1286
  shows "(X ---> L) (at_left a)"
hoelzl@57025
  1287
  using assms unfolding tendsto_def [where l=L]
hoelzl@57025
  1288
  by (simp add: sequentially_imp_eventually_at_left)
hoelzl@57025
  1289
hoelzl@57447
  1290
lemma sequentially_imp_eventually_at_right:
hoelzl@60172
  1291
  fixes a :: "'a :: {linorder_topology, first_countable_topology}"
hoelzl@57447
  1292
  assumes b[simp]: "a < b"
hoelzl@57447
  1293
  assumes *: "\<And>f. (\<And>n. a < f n) \<Longrightarrow> (\<And>n. f n < b) \<Longrightarrow> decseq f \<Longrightarrow> f ----> a \<Longrightarrow> eventually (\<lambda>n. P (f n)) sequentially"
hoelzl@57447
  1294
  shows "eventually P (at_right a)"
hoelzl@57447
  1295
proof (safe intro!: sequentially_imp_eventually_within)
hoelzl@57447
  1296
  fix X assume X: "\<forall>n. X n \<in> {a <..} \<and> X n \<noteq> a" "X ----> a"
hoelzl@57447
  1297
  show "eventually (\<lambda>n. P (X n)) sequentially"
hoelzl@57447
  1298
  proof (rule ccontr)
hoelzl@57447
  1299
    assume neg: "\<not> eventually (\<lambda>n. P (X n)) sequentially"
hoelzl@57447
  1300
    have "\<exists>s. \<forall>n. (\<not> P (X (s n)) \<and> X (s n) < b) \<and> (X (s (Suc n)) \<le> X (s n) \<and> Suc (s n) \<le> s (Suc n))"
hoelzl@57447
  1301
    proof (rule dependent_nat_choice)
hoelzl@57447
  1302
      have "\<not> eventually (\<lambda>n. X n < b \<longrightarrow> P (X n)) sequentially"
hoelzl@57447
  1303
        by (intro not_eventually_impI neg order_tendstoD(2) [OF X(2) b])
hoelzl@57447
  1304
      then show "\<exists>x. \<not> P (X x) \<and> X x < b"
hoelzl@57447
  1305
        by (auto dest!: not_eventuallyD)
hoelzl@57447
  1306
    next
hoelzl@57447
  1307
      fix x n
hoelzl@57447
  1308
      have "\<not> eventually (\<lambda>n. Suc x \<le> n \<longrightarrow> X n < b \<longrightarrow> X n < X x \<longrightarrow> P (X n)) sequentially"
hoelzl@57447
  1309
        using X by (intro not_eventually_impI order_tendstoD(2)[OF X(2)] eventually_ge_at_top neg) auto
hoelzl@57447
  1310
      then show "\<exists>n. (\<not> P (X n) \<and> X n < b) \<and> (X n \<le> X x \<and> Suc x \<le> n)"
hoelzl@57447
  1311
        by (auto dest!: not_eventuallyD)
hoelzl@57447
  1312
    qed
hoelzl@57447
  1313
    then guess s ..
hoelzl@57447
  1314
    then have "\<And>n. a < X (s n)" "\<And>n. X (s n) < b" "decseq (\<lambda>n. X (s n))" "(\<lambda>n. X (s n)) ----> a" "\<And>n. \<not> P (X (s n))"
wenzelm@60758
  1315
      using X by (auto simp: subseq_Suc_iff Suc_le_eq decseq_Suc_iff intro!: LIMSEQ_subseq_LIMSEQ[OF \<open>X ----> a\<close>, unfolded comp_def])
hoelzl@57447
  1316
    from *[OF this(1,2,3,4)] this(5) show False by auto
hoelzl@57447
  1317
  qed
hoelzl@57447
  1318
qed
hoelzl@57447
  1319
hoelzl@57447
  1320
lemma tendsto_at_right_sequentially:
hoelzl@60172
  1321
  fixes a :: "_ :: {linorder_topology, first_countable_topology}"
hoelzl@57447
  1322
  assumes "a < b"
hoelzl@57447
  1323
  assumes *: "\<And>S. (\<And>n. a < S n) \<Longrightarrow> (\<And>n. S n < b) \<Longrightarrow> decseq S \<Longrightarrow> S ----> a \<Longrightarrow> (\<lambda>n. X (S n)) ----> L"
hoelzl@57447
  1324
  shows "(X ---> L) (at_right a)"
hoelzl@57447
  1325
  using assms unfolding tendsto_def [where l=L]
hoelzl@57447
  1326
  by (simp add: sequentially_imp_eventually_at_right)
hoelzl@57447
  1327
wenzelm@60758
  1328
subsection \<open>Continuity\<close>
hoelzl@51471
  1329
wenzelm@60758
  1330
subsubsection \<open>Continuity on a set\<close>
hoelzl@51478
  1331
hoelzl@51478
  1332
definition continuous_on :: "'a set \<Rightarrow> ('a :: topological_space \<Rightarrow> 'b :: topological_space) \<Rightarrow> bool" where
hoelzl@51478
  1333
  "continuous_on s f \<longleftrightarrow> (\<forall>x\<in>s. (f ---> f x) (at x within s))"
hoelzl@51478
  1334
hoelzl@51481
  1335
lemma continuous_on_cong [cong]:
hoelzl@51481
  1336
  "s = t \<Longrightarrow> (\<And>x. x \<in> t \<Longrightarrow> f x = g x) \<Longrightarrow> continuous_on s f \<longleftrightarrow> continuous_on t g"
hoelzl@51641
  1337
  unfolding continuous_on_def by (intro ball_cong filterlim_cong) (auto simp: eventually_at_filter)
hoelzl@51481
  1338
hoelzl@51478
  1339
lemma continuous_on_topological:
hoelzl@51478
  1340
  "continuous_on s f \<longleftrightarrow>
hoelzl@51478
  1341
    (\<forall>x\<in>s. \<forall>B. open B \<longrightarrow> f x \<in> B \<longrightarrow> (\<exists>A. open A \<and> x \<in> A \<and> (\<forall>y\<in>s. y \<in> A \<longrightarrow> f y \<in> B)))"
hoelzl@51641
  1342
  unfolding continuous_on_def tendsto_def eventually_at_topological by metis
hoelzl@51478
  1343
hoelzl@51478
  1344
lemma continuous_on_open_invariant:
hoelzl@51478
  1345
  "continuous_on s f \<longleftrightarrow> (\<forall>B. open B \<longrightarrow> (\<exists>A. open A \<and> A \<inter> s = f -` B \<inter> s))"
hoelzl@51478
  1346
proof safe
hoelzl@51478
  1347
  fix B :: "'b set" assume "continuous_on s f" "open B"
hoelzl@51478
  1348
  then have "\<forall>x\<in>f -` B \<inter> s. (\<exists>A. open A \<and> x \<in> A \<and> s \<inter> A \<subseteq> f -` B)"
hoelzl@51478
  1349
    by (auto simp: continuous_on_topological subset_eq Ball_def imp_conjL)
wenzelm@53381
  1350
  then obtain A where "\<forall>x\<in>f -` B \<inter> s. open (A x) \<and> x \<in> A x \<and> s \<inter> A x \<subseteq> f -` B"
wenzelm@53381
  1351
    unfolding bchoice_iff ..
hoelzl@51478
  1352
  then show "\<exists>A. open A \<and> A \<inter> s = f -` B \<inter> s"
hoelzl@51478
  1353
    by (intro exI[of _ "\<Union>x\<in>f -` B \<inter> s. A x"]) auto
hoelzl@51478
  1354
next
hoelzl@51478
  1355
  assume B: "\<forall>B. open B \<longrightarrow> (\<exists>A. open A \<and> A \<inter> s = f -` B \<inter> s)"
hoelzl@51478
  1356
  show "continuous_on s f"
hoelzl@51478
  1357
    unfolding continuous_on_topological
hoelzl@51478
  1358
  proof safe
hoelzl@51478
  1359
    fix x B assume "x \<in> s" "open B" "f x \<in> B"
hoelzl@51478
  1360
    with B obtain A where A: "open A" "A \<inter> s = f -` B \<inter> s" by auto
wenzelm@60758
  1361
    with \<open>x \<in> s\<close> \<open>f x \<in> B\<close> show "\<exists>A. open A \<and> x \<in> A \<and> (\<forall>y\<in>s. y \<in> A \<longrightarrow> f y \<in> B)"
hoelzl@51478
  1362
      by (intro exI[of _ A]) auto
hoelzl@51478
  1363
  qed
hoelzl@51478
  1364
qed
hoelzl@51478
  1365
hoelzl@51481
  1366
lemma continuous_on_open_vimage:
hoelzl@51481
  1367
  "open s \<Longrightarrow> continuous_on s f \<longleftrightarrow> (\<forall>B. open B \<longrightarrow> open (f -` B \<inter> s))"
hoelzl@51481
  1368
  unfolding continuous_on_open_invariant
hoelzl@51481
  1369
  by (metis open_Int Int_absorb Int_commute[of s] Int_assoc[of _ _ s])
hoelzl@51481
  1370
lp15@55734
  1371
corollary continuous_imp_open_vimage:
lp15@55734
  1372
  assumes "continuous_on s f" "open s" "open B" "f -` B \<subseteq> s"
lp15@55734
  1373
    shows "open (f -` B)"
lp15@55734
  1374
by (metis assms continuous_on_open_vimage le_iff_inf)
lp15@55734
  1375
hoelzl@56371
  1376
corollary open_vimage[continuous_intros]:
lp15@55775
  1377
  assumes "open s" and "continuous_on UNIV f"
lp15@55775
  1378
  shows "open (f -` s)"
lp15@55775
  1379
  using assms unfolding continuous_on_open_vimage [OF open_UNIV]
lp15@55775
  1380
  by simp
lp15@55775
  1381
hoelzl@51478
  1382
lemma continuous_on_closed_invariant:
hoelzl@51478
  1383
  "continuous_on s f \<longleftrightarrow> (\<forall>B. closed B \<longrightarrow> (\<exists>A. closed A \<and> A \<inter> s = f -` B \<inter> s))"
hoelzl@51478
  1384
proof -
hoelzl@51478
  1385
  have *: "\<And>P Q::'b set\<Rightarrow>bool. (\<And>A. P A \<longleftrightarrow> Q (- A)) \<Longrightarrow> (\<forall>A. P A) \<longleftrightarrow> (\<forall>A. Q A)"
hoelzl@51478
  1386
    by (metis double_compl)
hoelzl@51478
  1387
  show ?thesis
hoelzl@51478
  1388
    unfolding continuous_on_open_invariant by (intro *) (auto simp: open_closed[symmetric])
hoelzl@51478
  1389
qed
hoelzl@51478
  1390
hoelzl@51481
  1391
lemma continuous_on_closed_vimage:
hoelzl@51481
  1392
  "closed s \<Longrightarrow> continuous_on s f \<longleftrightarrow> (\<forall>B. closed B \<longrightarrow> closed (f -` B \<inter> s))"
hoelzl@51481
  1393
  unfolding continuous_on_closed_invariant
hoelzl@51481
  1394
  by (metis closed_Int Int_absorb Int_commute[of s] Int_assoc[of _ _ s])
hoelzl@51481
  1395
hoelzl@56371
  1396
corollary closed_vimage[continuous_intros]:
hoelzl@56371
  1397
  assumes "closed s" and "continuous_on UNIV f"
hoelzl@56371
  1398
  shows "closed (f -` s)"
hoelzl@56371
  1399
  using assms unfolding continuous_on_closed_vimage [OF closed_UNIV]
hoelzl@56371
  1400
  by simp
hoelzl@56371
  1401
hoelzl@51481
  1402
lemma continuous_on_open_Union:
hoelzl@51481
  1403
  "(\<And>s. s \<in> S \<Longrightarrow> open s) \<Longrightarrow> (\<And>s. s \<in> S \<Longrightarrow> continuous_on s f) \<Longrightarrow> continuous_on (\<Union>S) f"
hoelzl@51641
  1404
  unfolding continuous_on_def by safe (metis open_Union at_within_open UnionI)
hoelzl@51481
  1405
hoelzl@51481
  1406
lemma continuous_on_open_UN:
hoelzl@51481
  1407
  "(\<And>s. s \<in> S \<Longrightarrow> open (A s)) \<Longrightarrow> (\<And>s. s \<in> S \<Longrightarrow> continuous_on (A s) f) \<Longrightarrow> continuous_on (\<Union>s\<in>S. A s) f"
hoelzl@51481
  1408
  unfolding Union_image_eq[symmetric] by (rule continuous_on_open_Union) auto
hoelzl@51481
  1409
paulson@61204
  1410
lemma continuous_on_open_Un:
paulson@61204
  1411
  "open s \<Longrightarrow> open t \<Longrightarrow> continuous_on s f \<Longrightarrow> continuous_on t f \<Longrightarrow> continuous_on (s \<union> t) f"
paulson@61204
  1412
  using continuous_on_open_Union [of "{s,t}"] by auto
paulson@61204
  1413
hoelzl@51481
  1414
lemma continuous_on_closed_Un:
hoelzl@51481
  1415
  "closed s \<Longrightarrow> closed t \<Longrightarrow> continuous_on s f \<Longrightarrow> continuous_on t f \<Longrightarrow> continuous_on (s \<union> t) f"
hoelzl@51481
  1416
  by (auto simp add: continuous_on_closed_vimage closed_Un Int_Un_distrib)
hoelzl@51481
  1417
hoelzl@51481
  1418
lemma continuous_on_If:
hoelzl@51481
  1419
  assumes closed: "closed s" "closed t" and cont: "continuous_on s f" "continuous_on t g"
hoelzl@51481
  1420
    and P: "\<And>x. x \<in> s \<Longrightarrow> \<not> P x \<Longrightarrow> f x = g x" "\<And>x. x \<in> t \<Longrightarrow> P x \<Longrightarrow> f x = g x"
hoelzl@51481
  1421
  shows "continuous_on (s \<union> t) (\<lambda>x. if P x then f x else g x)" (is "continuous_on _ ?h")
hoelzl@51481
  1422
proof-
hoelzl@51481
  1423
  from P have "\<forall>x\<in>s. f x = ?h x" "\<forall>x\<in>t. g x = ?h x"
hoelzl@51481
  1424
    by auto
hoelzl@51481
  1425
  with cont have "continuous_on s ?h" "continuous_on t ?h"
hoelzl@51481
  1426
    by simp_all
hoelzl@51481
  1427
  with closed show ?thesis
hoelzl@51481
  1428
    by (rule continuous_on_closed_Un)
hoelzl@51481
  1429
qed
hoelzl@51481
  1430
hoelzl@56371
  1431
lemma continuous_on_id[continuous_intros]: "continuous_on s (\<lambda>x. x)"
hoelzl@58729
  1432
  unfolding continuous_on_def by fast
hoelzl@51478
  1433
hoelzl@56371
  1434
lemma continuous_on_const[continuous_intros]: "continuous_on s (\<lambda>x. c)"
hoelzl@58729
  1435
  unfolding continuous_on_def by auto
hoelzl@51478
  1436
hoelzl@56371
  1437
lemma continuous_on_compose[continuous_intros]:
hoelzl@51478
  1438
  "continuous_on s f \<Longrightarrow> continuous_on (f ` s) g \<Longrightarrow> continuous_on s (g o f)"
hoelzl@51478
  1439
  unfolding continuous_on_topological by simp metis
hoelzl@51478
  1440
hoelzl@51481
  1441
lemma continuous_on_compose2:
hoelzl@51481
  1442
  "continuous_on t g \<Longrightarrow> continuous_on s f \<Longrightarrow> t = f ` s \<Longrightarrow> continuous_on s (\<lambda>x. g (f x))"
hoelzl@51481
  1443
  using continuous_on_compose[of s f g] by (simp add: comp_def)
hoelzl@51481
  1444
hoelzl@60720
  1445
lemma continuous_on_generate_topology:
hoelzl@60720
  1446
  assumes *: "open = generate_topology X"
hoelzl@60720
  1447
  assumes **: "\<And>B. B \<in> X \<Longrightarrow> \<exists>C. open C \<and> C \<inter> A = f -` B \<inter> A"
hoelzl@60720
  1448
  shows "continuous_on A f"
hoelzl@60720
  1449
  unfolding continuous_on_open_invariant
hoelzl@60720
  1450
proof safe
hoelzl@60720
  1451
  fix B :: "'a set" assume "open B" then show "\<exists>C. open C \<and> C \<inter> A = f -` B \<inter> A"
hoelzl@60720
  1452
    unfolding *
hoelzl@60720
  1453
  proof induction
hoelzl@60720
  1454
    case (UN K)
hoelzl@60720
  1455
    then obtain C where "\<And>k. k \<in> K \<Longrightarrow> open (C k)" "\<And>k. k \<in> K \<Longrightarrow> C k \<inter> A = f -` k \<inter> A"
hoelzl@60720
  1456
      by metis
hoelzl@60720
  1457
    then show ?case
hoelzl@60720
  1458
      by (intro exI[of _ "\<Union>k\<in>K. C k"]) blast
hoelzl@60720
  1459
  qed (auto intro: **)
hoelzl@60720
  1460
qed
hoelzl@60720
  1461
hoelzl@60720
  1462
lemma continuous_onI_mono:
hoelzl@60720
  1463
  fixes f :: "'a::linorder_topology \<Rightarrow> 'b::{dense_order, linorder_topology}"
hoelzl@60720
  1464
  assumes "open (f`A)"
hoelzl@60720
  1465
  assumes mono: "\<And>x y. x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y"
hoelzl@60720
  1466
  shows "continuous_on A f"
hoelzl@60720
  1467
proof (rule continuous_on_generate_topology[OF open_generated_order], safe)
hoelzl@60720
  1468
  have monoD: "\<And>x y. x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> f x < f y \<Longrightarrow> x < y"
hoelzl@60720
  1469
    by (auto simp: not_le[symmetric] mono)
hoelzl@60720
  1470
hoelzl@60720
  1471
  { fix a b assume "a \<in> A" "f a < b"
hoelzl@60720
  1472
    moreover
hoelzl@60720
  1473
    with open_right[OF \<open>open (f`A)\<close>, of "f a" b] obtain y where "f a < y" "{f a ..< y} \<subseteq> f`A"
hoelzl@60720
  1474
      by auto
hoelzl@60720
  1475
    moreover then obtain z where "f a < z" "z < min b y"
hoelzl@60720
  1476
      using dense[of "f a" "min b y"] \<open>f a < y\<close> \<open>f a < b\<close> by auto
hoelzl@60720
  1477
    moreover then obtain c where "z = f c" "c \<in> A"
hoelzl@60720
  1478
      using \<open>{f a ..< y} \<subseteq> f`A\<close>[THEN subsetD, of z] by (auto simp: less_imp_le)
hoelzl@60720
  1479
    ultimately have "\<exists>x. x \<in> A \<and> f x < b \<and> a < x"
hoelzl@60720
  1480
      by (auto intro!: exI[of _ c] simp: monoD) }
hoelzl@60720
  1481
  then show "\<exists>C. open C \<and> C \<inter> A = f -` {..<b} \<inter> A" for b
hoelzl@60720
  1482
    by (intro exI[of _ "(\<Union>x\<in>{x\<in>A. f x < b}. {..< x})"])
hoelzl@60720
  1483
       (auto intro: le_less_trans[OF mono] less_imp_le)
hoelzl@60720
  1484
hoelzl@60720
  1485
  { fix a b assume "a \<in> A" "b < f a"
hoelzl@60720
  1486
    moreover
hoelzl@60720
  1487
    with open_left[OF \<open>open (f`A)\<close>, of "f a" b] obtain y where "y < f a" "{y <.. f a} \<subseteq> f`A"
hoelzl@60720
  1488
      by auto
hoelzl@60720
  1489
    moreover then obtain z where "max b y < z" "z < f a"
hoelzl@60720
  1490
      using dense[of "max b y" "f a"] \<open>y < f a\<close> \<open>b < f a\<close> by auto
hoelzl@60720
  1491
    moreover then obtain c where "z = f c" "c \<in> A"
hoelzl@60720
  1492
      using \<open>{y <.. f a} \<subseteq> f`A\<close>[THEN subsetD, of z] by (auto simp: less_imp_le)
hoelzl@60720
  1493
    ultimately have "\<exists>x. x \<in> A \<and> b < f x \<and> x < a"
hoelzl@60720
  1494
      by (auto intro!: exI[of _ c] simp: monoD) }
hoelzl@60720
  1495
  then show "\<exists>C. open C \<and> C \<inter> A = f -` {b <..} \<inter> A" for b
hoelzl@60720
  1496
    by (intro exI[of _ "(\<Union>x\<in>{x\<in>A. b < f x}. {x <..})"])
hoelzl@60720
  1497
       (auto intro: less_le_trans[OF _ mono] less_imp_le)
hoelzl@60720
  1498
qed
hoelzl@60720
  1499
wenzelm@60758
  1500
subsubsection \<open>Continuity at a point\<close>
hoelzl@51478
  1501
hoelzl@51478
  1502
definition continuous :: "'a::t2_space filter \<Rightarrow> ('a \<Rightarrow> 'b::topological_space) \<Rightarrow> bool" where
hoelzl@51478
  1503
  "continuous F f \<longleftrightarrow> (f ---> f (Lim F (\<lambda>x. x))) F"
hoelzl@51478
  1504
hoelzl@51478
  1505
lemma continuous_bot[continuous_intros, simp]: "continuous bot f"
hoelzl@51478
  1506
  unfolding continuous_def by auto
hoelzl@51478
  1507
hoelzl@51478
  1508
lemma continuous_trivial_limit: "trivial_limit net \<Longrightarrow> continuous net f"
hoelzl@51478
  1509
  by simp
hoelzl@51478
  1510
hoelzl@51478
  1511
lemma continuous_within: "continuous (at x within s) f \<longleftrightarrow> (f ---> f x) (at x within s)"
hoelzl@51641
  1512
  by (cases "trivial_limit (at x within s)") (auto simp add: Lim_ident_at continuous_def)
hoelzl@51478
  1513
hoelzl@51478
  1514
lemma continuous_within_topological:
hoelzl@51478
  1515
  "continuous (at x within s) f \<longleftrightarrow>
hoelzl@51478
  1516
    (\<forall>B. open B \<longrightarrow> f x \<in> B \<longrightarrow> (\<exists>A. open A \<and> x \<in> A \<and> (\<forall>y\<in>s. y \<in> A \<longrightarrow> f y \<in> B)))"
hoelzl@51641
  1517
  unfolding continuous_within tendsto_def eventually_at_topological by metis
hoelzl@51478
  1518
hoelzl@51478
  1519
lemma continuous_within_compose[continuous_intros]:
hoelzl@51478
  1520
  "continuous (at x within s) f \<Longrightarrow> continuous (at (f x) within f ` s) g \<Longrightarrow>
hoelzl@51478
  1521
  continuous (at x within s) (g o f)"
hoelzl@51478
  1522
  by (simp add: continuous_within_topological) metis
hoelzl@51478
  1523
hoelzl@51478
  1524
lemma continuous_within_compose2:
hoelzl@51478
  1525
  "continuous (at x within s) f \<Longrightarrow> continuous (at (f x) within f ` s) g \<Longrightarrow>
hoelzl@51478
  1526
  continuous (at x within s) (\<lambda>x. g (f x))"
hoelzl@51478
  1527
  using continuous_within_compose[of x s f g] by (simp add: comp_def)
hoelzl@51471
  1528
hoelzl@51478
  1529
lemma continuous_at: "continuous (at x) f \<longleftrightarrow> f -- x --> f x"
hoelzl@51478
  1530
  using continuous_within[of x UNIV f] by simp
hoelzl@51478
  1531
hoelzl@51478
  1532
lemma continuous_ident[continuous_intros, simp]: "continuous (at x within S) (\<lambda>x. x)"
hoelzl@51641
  1533
  unfolding continuous_within by (rule tendsto_ident_at)
hoelzl@51478
  1534
hoelzl@51478
  1535
lemma continuous_const[continuous_intros, simp]: "continuous F (\<lambda>x. c)"
hoelzl@51478
  1536
  unfolding continuous_def by (rule tendsto_const)
hoelzl@51478
  1537
hoelzl@51478
  1538
lemma continuous_on_eq_continuous_within:
hoelzl@51478
  1539
  "continuous_on s f \<longleftrightarrow> (\<forall>x\<in>s. continuous (at x within s) f)"
hoelzl@51478
  1540
  unfolding continuous_on_def continuous_within ..
hoelzl@51478
  1541
hoelzl@51478
  1542
abbreviation isCont :: "('a::t2_space \<Rightarrow> 'b::topological_space) \<Rightarrow> 'a \<Rightarrow> bool" where
hoelzl@51478
  1543
  "isCont f a \<equiv> continuous (at a) f"
hoelzl@51478
  1544
hoelzl@51478
  1545
lemma isCont_def: "isCont f a \<longleftrightarrow> f -- a --> f a"
hoelzl@51478
  1546
  by (rule continuous_at)
hoelzl@51478
  1547
paulson@60762
  1548
lemma continuous_at_imp_continuous_at_within: "isCont f x \<Longrightarrow> continuous (at x within s) f"
hoelzl@51641
  1549
  by (auto intro: tendsto_mono at_le simp: continuous_at continuous_within)
hoelzl@51478
  1550
hoelzl@51481
  1551
lemma continuous_on_eq_continuous_at: "open s \<Longrightarrow> continuous_on s f \<longleftrightarrow> (\<forall>x\<in>s. isCont f x)"
hoelzl@51641
  1552
  by (simp add: continuous_on_def continuous_at at_within_open[of _ s])
hoelzl@51481
  1553
hoelzl@51481
  1554
lemma continuous_on_subset: "continuous_on s f \<Longrightarrow> t \<subseteq> s \<Longrightarrow> continuous_on t f"
hoelzl@51481
  1555
  unfolding continuous_on_def by (metis subset_eq tendsto_within_subset)
hoelzl@51481
  1556
hoelzl@51478
  1557
lemma continuous_at_imp_continuous_on: "\<forall>x\<in>s. isCont f x \<Longrightarrow> continuous_on s f"
paulson@60762
  1558
  by (auto intro: continuous_at_imp_continuous_at_within simp: continuous_on_eq_continuous_within)
hoelzl@51478
  1559
hoelzl@51478
  1560
lemma isCont_o2: "isCont f a \<Longrightarrow> isCont g (f a) \<Longrightarrow> isCont (\<lambda>x. g (f x)) a"
hoelzl@51478
  1561
  unfolding isCont_def by (rule tendsto_compose)
hoelzl@51478
  1562
hoelzl@51478
  1563
lemma isCont_o[continuous_intros]: "isCont f a \<Longrightarrow> isCont g (f a) \<Longrightarrow> isCont (g \<circ> f) a"
hoelzl@51478
  1564
  unfolding o_def by (rule isCont_o2)
hoelzl@51471
  1565
hoelzl@51471
  1566
lemma isCont_tendsto_compose: "isCont g l \<Longrightarrow> (f ---> l) F \<Longrightarrow> ((\<lambda>x. g (f x)) ---> g l) F"
hoelzl@51471
  1567
  unfolding isCont_def by (rule tendsto_compose)
hoelzl@51471
  1568
hoelzl@51478
  1569
lemma continuous_within_compose3:
hoelzl@51478
  1570
  "isCont g (f x) \<Longrightarrow> continuous (at x within s) f \<Longrightarrow> continuous (at x within s) (\<lambda>x. g (f x))"
paulson@60762
  1571
  using continuous_within_compose2[of x s f g] by (simp add: continuous_at_imp_continuous_at_within)
hoelzl@51471
  1572
hoelzl@57447
  1573
lemma filtermap_nhds_open_map:
hoelzl@57447
  1574
  assumes cont: "isCont f a" and open_map: "\<And>S. open S \<Longrightarrow> open (f`S)"
hoelzl@57447
  1575
  shows "filtermap f (nhds a) = nhds (f a)"
hoelzl@57447
  1576
  unfolding filter_eq_iff
hoelzl@57447
  1577
proof safe
hoelzl@57447
  1578
  fix P assume "eventually P (filtermap f (nhds a))"
hoelzl@57447
  1579
  then guess S unfolding eventually_filtermap eventually_nhds ..
hoelzl@57447
  1580
  then show "eventually P (nhds (f a))"
hoelzl@57447
  1581
    unfolding eventually_nhds by (intro exI[of _ "f`S"]) (auto intro!: open_map)
hoelzl@57447
  1582
qed (metis filterlim_iff tendsto_at_iff_tendsto_nhds isCont_def eventually_filtermap cont)
hoelzl@57447
  1583
hoelzl@57447
  1584
lemma continuous_at_split: 
hoelzl@57447
  1585
  "continuous (at (x::'a::linorder_topology)) f = (continuous (at_left x) f \<and> continuous (at_right x) f)"
hoelzl@57447
  1586
  by (simp add: continuous_within filterlim_at_split)
hoelzl@57447
  1587
hoelzl@61245
  1588
subsubsection \<open>Open-cover compactness\<close>
hoelzl@51479
  1589
hoelzl@51479
  1590
context topological_space
hoelzl@51479
  1591
begin
hoelzl@51479
  1592
hoelzl@51479
  1593
definition compact :: "'a set \<Rightarrow> bool" where
hoelzl@51479
  1594
  compact_eq_heine_borel: -- "This name is used for backwards compatibility"
hoelzl@51479
  1595
    "compact S \<longleftrightarrow> (\<forall>C. (\<forall>c\<in>C. open c) \<and> S \<subseteq> \<Union>C \<longrightarrow> (\<exists>D\<subseteq>C. finite D \<and> S \<subseteq> \<Union>D))"
hoelzl@51479
  1596
hoelzl@51479
  1597
lemma compactI:
wenzelm@60585
  1598
  assumes "\<And>C. \<forall>t\<in>C. open t \<Longrightarrow> s \<subseteq> \<Union>C \<Longrightarrow> \<exists>C'. C' \<subseteq> C \<and> finite C' \<and> s \<subseteq> \<Union>C'"
hoelzl@51479
  1599
  shows "compact s"
hoelzl@51479
  1600
  unfolding compact_eq_heine_borel using assms by metis
hoelzl@51479
  1601
hoelzl@51479
  1602
lemma compact_empty[simp]: "compact {}"
hoelzl@51479
  1603
  by (auto intro!: compactI)
hoelzl@51479
  1604
hoelzl@51479
  1605
lemma compactE:
hoelzl@51479
  1606
  assumes "compact s" and "\<forall>t\<in>C. open t" and "s \<subseteq> \<Union>C"
hoelzl@51479
  1607
  obtains C' where "C' \<subseteq> C" and "finite C'" and "s \<subseteq> \<Union>C'"
hoelzl@51479
  1608
  using assms unfolding compact_eq_heine_borel by metis
hoelzl@51479
  1609
hoelzl@51479
  1610
lemma compactE_image:
hoelzl@51479
  1611
  assumes "compact s" and "\<forall>t\<in>C. open (f t)" and "s \<subseteq> (\<Union>c\<in>C. f c)"
hoelzl@51479
  1612
  obtains C' where "C' \<subseteq> C" and "finite C'" and "s \<subseteq> (\<Union>c\<in>C'. f c)"
hoelzl@51479
  1613
  using assms unfolding ball_simps[symmetric] SUP_def
hoelzl@51479
  1614
  by (metis (lifting) finite_subset_image compact_eq_heine_borel[of s])
hoelzl@51479
  1615
hoelzl@51481
  1616
lemma compact_inter_closed [intro]:
hoelzl@51481
  1617
  assumes "compact s" and "closed t"
hoelzl@51481
  1618
  shows "compact (s \<inter> t)"
hoelzl@51481
  1619
proof (rule compactI)
hoelzl@51481
  1620
  fix C assume C: "\<forall>c\<in>C. open c" and cover: "s \<inter> t \<subseteq> \<Union>C"
wenzelm@60758
  1621
  from C \<open>closed t\<close> have "\<forall>c\<in>C \<union> {-t}. open c" by auto
hoelzl@51481
  1622
  moreover from cover have "s \<subseteq> \<Union>(C \<union> {-t})" by auto
hoelzl@51481
  1623
  ultimately have "\<exists>D\<subseteq>C \<union> {-t}. finite D \<and> s \<subseteq> \<Union>D"
wenzelm@60758
  1624
    using \<open>compact s\<close> unfolding compact_eq_heine_borel by auto
wenzelm@53381
  1625
  then obtain D where "D \<subseteq> C \<union> {- t} \<and> finite D \<and> s \<subseteq> \<Union>D" ..
hoelzl@51481
  1626
  then show "\<exists>D\<subseteq>C. finite D \<and> s \<inter> t \<subseteq> \<Union>D"
hoelzl@51481
  1627
    by (intro exI[of _ "D - {-t}"]) auto
hoelzl@51481
  1628
qed
hoelzl@51481
  1629
hoelzl@54797
  1630
lemma inj_setminus: "inj_on uminus (A::'a set set)"
hoelzl@54797
  1631
  by (auto simp: inj_on_def)
hoelzl@54797
  1632
hoelzl@54797
  1633
lemma compact_fip:
hoelzl@54797
  1634
  "compact U \<longleftrightarrow>
hoelzl@54797
  1635
    (\<forall>A. (\<forall>a\<in>A. closed a) \<longrightarrow> (\<forall>B \<subseteq> A. finite B \<longrightarrow> U \<inter> \<Inter>B \<noteq> {}) \<longrightarrow> U \<inter> \<Inter>A \<noteq> {})"
hoelzl@54797
  1636
  (is "_ \<longleftrightarrow> ?R")
hoelzl@54797
  1637
proof (safe intro!: compact_eq_heine_borel[THEN iffD2])
hoelzl@54797
  1638
  fix A
hoelzl@54797
  1639
  assume "compact U"
hoelzl@54797
  1640
    and A: "\<forall>a\<in>A. closed a" "U \<inter> \<Inter>A = {}"
hoelzl@54797
  1641
    and fi: "\<forall>B \<subseteq> A. finite B \<longrightarrow> U \<inter> \<Inter>B \<noteq> {}"
hoelzl@54797
  1642
  from A have "(\<forall>a\<in>uminus`A. open a) \<and> U \<subseteq> \<Union>(uminus`A)"
hoelzl@54797
  1643
    by auto
wenzelm@60758
  1644
  with \<open>compact U\<close> obtain B where "B \<subseteq> A" "finite (uminus`B)" "U \<subseteq> \<Union>(uminus`B)"
hoelzl@54797
  1645
    unfolding compact_eq_heine_borel by (metis subset_image_iff)
hoelzl@54797
  1646
  with fi[THEN spec, of B] show False
hoelzl@54797
  1647
    by (auto dest: finite_imageD intro: inj_setminus)
hoelzl@54797
  1648
next
hoelzl@54797
  1649
  fix A
hoelzl@54797
  1650
  assume ?R
hoelzl@54797
  1651
  assume "\<forall>a\<in>A. open a" "U \<subseteq> \<Union>A"
hoelzl@54797
  1652
  then have "U \<inter> \<Inter>(uminus`A) = {}" "\<forall>a\<in>uminus`A. closed a"
hoelzl@54797
  1653
    by auto
wenzelm@60758
  1654
  with \<open>?R\<close> obtain B where "B \<subseteq> A" "finite (uminus`B)" "U \<inter> \<Inter>(uminus`B) = {}"
hoelzl@54797
  1655
    by (metis subset_image_iff)
hoelzl@54797
  1656
  then show "\<exists>T\<subseteq>A. finite T \<and> U \<subseteq> \<Union>T"
hoelzl@54797
  1657
    by  (auto intro!: exI[of _ B] inj_setminus dest: finite_imageD)
hoelzl@54797
  1658
qed
hoelzl@54797
  1659
hoelzl@54797
  1660
lemma compact_imp_fip:
wenzelm@60585
  1661
  "compact s \<Longrightarrow> \<forall>t \<in> f. closed t \<Longrightarrow> \<forall>f'. finite f' \<and> f' \<subseteq> f \<longrightarrow> (s \<inter> (\<Inter>f') \<noteq> {}) \<Longrightarrow>
wenzelm@60585
  1662
    s \<inter> (\<Inter>f) \<noteq> {}"
hoelzl@54797
  1663
  unfolding compact_fip by auto
hoelzl@54797
  1664
hoelzl@54797
  1665
lemma compact_imp_fip_image:
haftmann@56166
  1666
  assumes "compact s"
haftmann@56166
  1667
    and P: "\<And>i. i \<in> I \<Longrightarrow> closed (f i)"
haftmann@56166
  1668
    and Q: "\<And>I'. finite I' \<Longrightarrow> I' \<subseteq> I \<Longrightarrow> (s \<inter> (\<Inter>i\<in>I'. f i) \<noteq> {})"
haftmann@56166
  1669
  shows "s \<inter> (\<Inter>i\<in>I. f i) \<noteq> {}"
haftmann@56166
  1670
proof -
wenzelm@60758
  1671
  note \<open>compact s\<close>
haftmann@56166
  1672
  moreover from P have "\<forall>i \<in> f ` I. closed i" by blast
haftmann@56166
  1673
  moreover have "\<forall>A. finite A \<and> A \<subseteq> f ` I \<longrightarrow> (s \<inter> (\<Inter>A) \<noteq> {})"
haftmann@56166
  1674
  proof (rule, rule, erule conjE)
haftmann@56166
  1675
    fix A :: "'a set set"
haftmann@56166
  1676
    assume "finite A"
haftmann@56166
  1677
    moreover assume "A \<subseteq> f ` I"
haftmann@56166
  1678
    ultimately obtain B where "B \<subseteq> I" and "finite B" and "A = f ` B"
haftmann@56166
  1679
      using finite_subset_image [of A f I] by blast
haftmann@56166
  1680
    with Q [of B] show "s \<inter> \<Inter>A \<noteq> {}" by simp
haftmann@56166
  1681
  qed
haftmann@56166
  1682
  ultimately have "s \<inter> (\<Inter>(f ` I)) \<noteq> {}" by (rule compact_imp_fip)
haftmann@56166
  1683
  then show ?thesis by simp
haftmann@56166
  1684
qed
hoelzl@54797
  1685
hoelzl@51471
  1686
end
hoelzl@51471
  1687
hoelzl@51481
  1688
lemma (in t2_space) compact_imp_closed:
hoelzl@51481
  1689
  assumes "compact s" shows "closed s"
hoelzl@51481
  1690
unfolding closed_def
hoelzl@51481
  1691
proof (rule openI)
hoelzl@51481
  1692
  fix y assume "y \<in> - s"
hoelzl@51481
  1693
  let ?C = "\<Union>x\<in>s. {u. open u \<and> x \<in> u \<and> eventually (\<lambda>y. y \<notin> u) (nhds y)}"
wenzelm@60758
  1694
  note \<open>compact s\<close>
hoelzl@51481
  1695
  moreover have "\<forall>u\<in>?C. open u" by simp
hoelzl@51481
  1696
  moreover have "s \<subseteq> \<Union>?C"
hoelzl@51481
  1697
  proof
hoelzl@51481
  1698
    fix x assume "x \<in> s"
wenzelm@60758
  1699
    with \<open>y \<in> - s\<close> have "x \<noteq> y" by clarsimp
hoelzl@51481
  1700
    hence "\<exists>u v. open u \<and> open v \<and> x \<in> u \<and> y \<in> v \<and> u \<inter> v = {}"
hoelzl@51481
  1701
      by (rule hausdorff)
wenzelm@60758
  1702
    with \<open>x \<in> s\<close> show "x \<in> \<Union>?C"
hoelzl@51481
  1703
      unfolding eventually_nhds by auto
hoelzl@51481
  1704
  qed
hoelzl@51481
  1705
  ultimately obtain D where "D \<subseteq> ?C" and "finite D" and "s \<subseteq> \<Union>D"
hoelzl@51481
  1706
    by (rule compactE)
wenzelm@60758
  1707
  from \<open>D \<subseteq> ?C\<close> have "\<forall>x\<in>D. eventually (\<lambda>y. y \<notin> x) (nhds y)" by auto
wenzelm@60758
  1708
  with \<open>finite D\<close> have "eventually (\<lambda>y. y \<notin> \<Union>D) (nhds y)"
hoelzl@60040
  1709
    by (simp add: eventually_ball_finite)
wenzelm@60758
  1710
  with \<open>s \<subseteq> \<Union>D\<close> have "eventually (\<lambda>y. y \<notin> s) (nhds y)"
hoelzl@51481
  1711
    by (auto elim!: eventually_mono [rotated])
hoelzl@51481
  1712
  thus "\<exists>t. open t \<and> y \<in> t \<and> t \<subseteq> - s"
hoelzl@51481
  1713
    by (simp add: eventually_nhds subset_eq)
hoelzl@51481
  1714
qed
hoelzl@51481
  1715
hoelzl@51481
  1716
lemma compact_continuous_image:
hoelzl@51481
  1717
  assumes f: "continuous_on s f" and s: "compact s"
hoelzl@51481
  1718
  shows "compact (f ` s)"
hoelzl@51481
  1719
proof (rule compactI)
hoelzl@51481
  1720
  fix C assume "\<forall>c\<in>C. open c" and cover: "f`s \<subseteq> \<Union>C"
hoelzl@51481
  1721
  with f have "\<forall>c\<in>C. \<exists>A. open A \<and> A \<inter> s = f -` c \<inter> s"
hoelzl@51481
  1722
    unfolding continuous_on_open_invariant by blast
wenzelm@53381
  1723
  then obtain A where A: "\<forall>c\<in>C. open (A c) \<and> A c \<inter> s = f -` c \<inter> s"
wenzelm@53381
  1724
    unfolding bchoice_iff ..
hoelzl@51481
  1725
  with cover have "\<forall>c\<in>C. open (A c)" "s \<subseteq> (\<Union>c\<in>C. A c)"
hoelzl@51481
  1726
    by (fastforce simp add: subset_eq set_eq_iff)+
hoelzl@51481
  1727
  from compactE_image[OF s this] obtain D where "D \<subseteq> C" "finite D" "s \<subseteq> (\<Union>c\<in>D. A c)" .
hoelzl@51481
  1728
  with A show "\<exists>D \<subseteq> C. finite D \<and> f`s \<subseteq> \<Union>D"
hoelzl@51481
  1729
    by (intro exI[of _ D]) (fastforce simp add: subset_eq set_eq_iff)+
hoelzl@51481
  1730
qed
hoelzl@51481
  1731
hoelzl@51481
  1732
lemma continuous_on_inv:
hoelzl@51481
  1733
  fixes f :: "'a::topological_space \<Rightarrow> 'b::t2_space"
hoelzl@51481
  1734
  assumes "continuous_on s f"  "compact s"  "\<forall>x\<in>s. g (f x) = x"
hoelzl@51481
  1735
  shows "continuous_on (f ` s) g"
hoelzl@51481
  1736
unfolding continuous_on_topological
hoelzl@51481
  1737
proof (clarsimp simp add: assms(3))
hoelzl@51481
  1738
  fix x :: 'a and B :: "'a set"
hoelzl@51481
  1739
  assume "x \<in> s" and "open B" and "x \<in> B"
hoelzl@51481
  1740
  have 1: "\<forall>x\<in>s. f x \<in> f ` (s - B) \<longleftrightarrow> x \<in> s - B"
hoelzl@51481
  1741
    using assms(3) by (auto, metis)
hoelzl@51481
  1742
  have "continuous_on (s - B) f"
wenzelm@60758
  1743
    using \<open>continuous_on s f\<close> Diff_subset
hoelzl@51481
  1744
    by (rule continuous_on_subset)
hoelzl@51481
  1745
  moreover have "compact (s - B)"
wenzelm@60758
  1746
    using \<open>open B\<close> and \<open>compact s\<close>
hoelzl@51481
  1747
    unfolding Diff_eq by (intro compact_inter_closed closed_Compl)
hoelzl@51481
  1748
  ultimately have "compact (f ` (s - B))"
hoelzl@51481
  1749
    by (rule compact_continuous_image)
hoelzl@51481
  1750
  hence "closed (f ` (s - B))"
hoelzl@51481
  1751
    by (rule compact_imp_closed)
hoelzl@51481
  1752
  hence "open (- f ` (s - B))"
hoelzl@51481
  1753
    by (rule open_Compl)
hoelzl@51481
  1754
  moreover have "f x \<in> - f ` (s - B)"
wenzelm@60758
  1755
    using \<open>x \<in> s\<close> and \<open>x \<in> B\<close> by (simp add: 1)
hoelzl@51481
  1756
  moreover have "\<forall>y\<in>s. f y \<in> - f ` (s - B) \<longrightarrow> y \<in> B"
hoelzl@51481
  1757
    by (simp add: 1)
hoelzl@51481
  1758
  ultimately show "\<exists>A. open A \<and> f x \<in> A \<and> (\<forall>y\<in>s. f y \<in> A \<longrightarrow> y \<in> B)"
hoelzl@51481
  1759
    by fast
hoelzl@51481
  1760
qed
hoelzl@51481
  1761
hoelzl@51481
  1762
lemma continuous_on_inv_into:
hoelzl@51481
  1763
  fixes f :: "'a::topological_space \<Rightarrow> 'b::t2_space"
hoelzl@51481
  1764
  assumes s: "continuous_on s f" "compact s" and f: "inj_on f s"
hoelzl@51481
  1765
  shows "continuous_on (f ` s) (the_inv_into s f)"
hoelzl@51481
  1766
  by (rule continuous_on_inv[OF s]) (auto simp: the_inv_into_f_f[OF f])
hoelzl@51481
  1767
hoelzl@51479
  1768
lemma (in linorder_topology) compact_attains_sup:
hoelzl@51479
  1769
  assumes "compact S" "S \<noteq> {}"
hoelzl@51479
  1770
  shows "\<exists>s\<in>S. \<forall>t\<in>S. t \<le> s"
hoelzl@51479
  1771
proof (rule classical)
hoelzl@51479
  1772
  assume "\<not> (\<exists>s\<in>S. \<forall>t\<in>S. t \<le> s)"
hoelzl@51479
  1773
  then obtain t where t: "\<forall>s\<in>S. t s \<in> S" and "\<forall>s\<in>S. s < t s"
hoelzl@51479
  1774
    by (metis not_le)
hoelzl@51479
  1775
  then have "\<forall>s\<in>S. open {..< t s}" "S \<subseteq> (\<Union>s\<in>S. {..< t s})"
hoelzl@51479
  1776
    by auto
wenzelm@60758
  1777
  with \<open>compact S\<close> obtain C where "C \<subseteq> S" "finite C" and C: "S \<subseteq> (\<Union>s\<in>C. {..< t s})"
hoelzl@51479
  1778
    by (erule compactE_image)
wenzelm@60758
  1779
  with \<open>S \<noteq> {}\<close> have Max: "Max (t`C) \<in> t`C" and "\<forall>s\<in>t`C. s \<le> Max (t`C)"
hoelzl@51479
  1780
    by (auto intro!: Max_in)
hoelzl@51479
  1781
  with C have "S \<subseteq> {..< Max (t`C)}"
hoelzl@51479
  1782
    by (auto intro: less_le_trans simp: subset_eq)
wenzelm@60758
  1783
  with t Max \<open>C \<subseteq> S\<close> show ?thesis
hoelzl@51479
  1784
    by fastforce
hoelzl@51479
  1785
qed
hoelzl@51479
  1786
hoelzl@51479
  1787
lemma (in linorder_topology) compact_attains_inf:
hoelzl@51479
  1788
  assumes "compact S" "S \<noteq> {}"
hoelzl@51479
  1789
  shows "\<exists>s\<in>S. \<forall>t\<in>S. s \<le> t"
hoelzl@51479
  1790
proof (rule classical)
hoelzl@51479
  1791
  assume "\<not> (\<exists>s\<in>S. \<forall>t\<in>S. s \<le> t)"
hoelzl@51479
  1792
  then obtain t where t: "\<forall>s\<in>S. t s \<in> S" and "\<forall>s\<in>S. t s < s"
hoelzl@51479
  1793
    by (metis not_le)
hoelzl@51479
  1794
  then have "\<forall>s\<in>S. open {t s <..}" "S \<subseteq> (\<Union>s\<in>S. {t s <..})"
hoelzl@51479
  1795
    by auto
wenzelm@60758
  1796
  with \<open>compact S\<close> obtain C where "C \<subseteq> S" "finite C" and C: "S \<subseteq> (\<Union>s\<in>C. {t s <..})"
hoelzl@51479
  1797
    by (erule compactE_image)
wenzelm@60758
  1798
  with \<open>S \<noteq> {}\<close> have Min: "Min (t`C) \<in> t`C" and "\<forall>s\<in>t`C. Min (t`C) \<le> s"
hoelzl@51479
  1799
    by (auto intro!: Min_in)
hoelzl@51479
  1800
  with C have "S \<subseteq> {Min (t`C) <..}"
hoelzl@51479
  1801
    by (auto intro: le_less_trans simp: subset_eq)
wenzelm@60758
  1802
  with t Min \<open>C \<subseteq> S\<close> show ?thesis
hoelzl@51479
  1803
    by fastforce
hoelzl@51479
  1804
qed
hoelzl@51479
  1805
hoelzl@51479
  1806
lemma continuous_attains_sup:
hoelzl@51479
  1807
  fixes f :: "'a::topological_space \<Rightarrow> 'b::linorder_topology"
hoelzl@51479
  1808
  shows "compact s \<Longrightarrow> s \<noteq> {} \<Longrightarrow> continuous_on s f \<Longrightarrow> (\<exists>x\<in>s. \<forall>y\<in>s.  f y \<le> f x)"
hoelzl@51479
  1809
  using compact_attains_sup[of "f ` s"] compact_continuous_image[of s f] by auto
hoelzl@51479
  1810
hoelzl@51479
  1811
lemma continuous_attains_inf:
hoelzl@51479
  1812
  fixes f :: "'a::topological_space \<Rightarrow> 'b::linorder_topology"
hoelzl@51479
  1813
  shows "compact s \<Longrightarrow> s \<noteq> {} \<Longrightarrow> continuous_on s f \<Longrightarrow> (\<exists>x\<in>s. \<forall>y\<in>s. f x \<le> f y)"
hoelzl@51479
  1814
  using compact_attains_inf[of "f ` s"] compact_continuous_image[of s f] by auto
hoelzl@51479
  1815
wenzelm@60758
  1816
subsection \<open>Connectedness\<close>
hoelzl@51480
  1817
hoelzl@51480
  1818
context topological_space
hoelzl@51480
  1819
begin
hoelzl@51480
  1820
hoelzl@51480
  1821
definition "connected S \<longleftrightarrow>
hoelzl@51480
  1822
  \<not> (\<exists>A B. open A \<and> open B \<and> S \<subseteq> A \<union> B \<and> A \<inter> B \<inter> S = {} \<and> A \<inter> S \<noteq> {} \<and> B \<inter> S \<noteq> {})"
hoelzl@51480
  1823
hoelzl@51480
  1824
lemma connectedI:
hoelzl@51480
  1825
  "(\<And>A B. open A \<Longrightarrow> open B \<Longrightarrow> A \<inter> U \<noteq> {} \<Longrightarrow> B \<inter> U \<noteq> {} \<Longrightarrow> A \<inter> B \<inter> U = {} \<Longrightarrow> U \<subseteq> A \<union> B \<Longrightarrow> False)
hoelzl@51480
  1826
  \<Longrightarrow> connected U"
hoelzl@51480
  1827
  by (auto simp: connected_def)
hoelzl@51480
  1828
lp15@61306
  1829
lemma connected_empty [simp]: "connected {}"
lp15@61306
  1830
  by (auto intro!: connectedI)
lp15@61306
  1831
lp15@61306
  1832
lemma connected_sing [simp]: "connected {x}"
hoelzl@51480
  1833
  by (auto intro!: connectedI)
hoelzl@51480
  1834
hoelzl@56329
  1835
lemma connectedD:
hoelzl@56329
  1836
  "connected A \<Longrightarrow> open U \<Longrightarrow> open V \<Longrightarrow> U \<inter> V \<inter> A = {} \<Longrightarrow> A \<subseteq> U \<union> V \<Longrightarrow> U \<inter> A = {} \<or> V \<inter> A = {}" 
hoelzl@56329
  1837
  by (auto simp: connected_def)
hoelzl@56329
  1838
hoelzl@51479
  1839
end
hoelzl@51479
  1840
lp15@61306
  1841
lemma connected_closed:
lp15@61306
  1842
    "connected s \<longleftrightarrow>
lp15@61306
  1843
     ~ (\<exists>A B. closed A \<and> closed B \<and> s \<subseteq> A \<union> B \<and> A \<inter> B \<inter> s = {} \<and> A \<inter> s \<noteq> {} \<and> B \<inter> s \<noteq> {})"
lp15@61306
  1844
apply (simp add: connected_def del: ex_simps, safe)
lp15@61306
  1845
apply (drule_tac x="-A" in spec)
lp15@61306
  1846
apply (drule_tac x="-B" in spec)
lp15@61306
  1847
apply (fastforce simp add: closed_def [symmetric])
lp15@61306
  1848
apply (drule_tac x="-A" in spec)
lp15@61306
  1849
apply (drule_tac x="-B" in spec)
lp15@61306
  1850
apply (fastforce simp add: open_closed [symmetric])
lp15@61306
  1851
done
lp15@61306
  1852
lp15@61306
  1853
lp15@61306
  1854
lemma connected_Union:
lp15@61306
  1855
  assumes cs: "\<And>s. s \<in> S \<Longrightarrow> connected s" and ne: "\<Inter>S \<noteq> {}"
lp15@61306
  1856
    shows "connected(\<Union>S)"
lp15@61306
  1857
proof (rule connectedI)
lp15@61306
  1858
  fix A B
lp15@61306
  1859
  assume A: "open A" and B: "open B" and Alap: "A \<inter> \<Union>S \<noteq> {}" and Blap: "B \<inter> \<Union>S \<noteq> {}"
lp15@61306
  1860
     and disj: "A \<inter> B \<inter> \<Union>S = {}" and cover: "\<Union>S \<subseteq> A \<union> B"
lp15@61306
  1861
  have disjs:"\<And>s. s \<in> S \<Longrightarrow> A \<inter> B \<inter> s = {}"
lp15@61306
  1862
    using disj by auto
lp15@61306
  1863
  obtain sa where sa: "sa \<in> S" "A \<inter> sa \<noteq> {}"
lp15@61306
  1864
    using Alap by auto
lp15@61306
  1865
  obtain sb where sb: "sb \<in> S" "B \<inter> sb \<noteq> {}"
lp15@61306
  1866
    using Blap by auto
lp15@61306
  1867
  obtain x where x: "\<And>s. s \<in> S \<Longrightarrow> x \<in> s"
lp15@61306
  1868
    using ne by auto
lp15@61306
  1869
  then have "x \<in> \<Union>S"
wenzelm@61342
  1870
    using \<open>sa \<in> S\<close> by blast
lp15@61306
  1871
  then have "x \<in> A \<or> x \<in> B"
lp15@61306
  1872
    using cover by auto
lp15@61306
  1873
  then show False
lp15@61306
  1874
    using cs [unfolded connected_def]
lp15@61306
  1875
    by (metis A B IntI Sup_upper sa sb disjs x cover empty_iff subset_trans)
lp15@61306
  1876
qed
lp15@61306
  1877
lp15@61306
  1878
lemma connected_Un: "\<lbrakk>connected s; connected t; s \<inter> t \<noteq> {}\<rbrakk> \<Longrightarrow> connected (s \<union> t)"
lp15@61306
  1879
  using connected_Union [of "{s,t}"] by auto
lp15@61306
  1880
lp15@61306
  1881
lemma connected_diff_open_from_closed:
lp15@61306
  1882
  assumes st: "s \<subseteq> t" and tu: "t \<subseteq> u" and s: "open s"
lp15@61306
  1883
      and t: "closed t" and u: "connected u" and ts: "connected (t - s)"
lp15@61306
  1884
  shows "connected(u - s)"
lp15@61306
  1885
proof (rule connectedI)
lp15@61306
  1886
  fix A B
lp15@61306
  1887
  assume AB: "open A" "open B" "A \<inter> (u - s) \<noteq> {}" "B \<inter> (u - s) \<noteq> {}"
lp15@61306
  1888
     and disj: "A \<inter> B \<inter> (u - s) = {}" and cover: "u - s \<subseteq> A \<union> B"
lp15@61306
  1889
  then consider "A \<inter> (t - s) = {}" | "B \<inter> (t - s) = {}"
lp15@61306
  1890
    using st ts tu connectedD [of "t-s" "A" "B"]
lp15@61306
  1891
    by auto
lp15@61306
  1892
  then show False
lp15@61306
  1893
  proof cases
lp15@61306
  1894
    case 1
lp15@61306
  1895
    then have "(A - t) \<inter> (B \<union> s) \<inter> u = {}"
lp15@61306
  1896
      using disj st by auto
lp15@61306
  1897
    moreover have  "u \<subseteq> (A - t) \<union> (B \<union> s)" using 1 cover by auto
lp15@61306
  1898
    ultimately show False
lp15@61306
  1899
      using connectedD [of u "A - t" "B \<union> s"] AB s t 1 u
lp15@61306
  1900
      by auto
lp15@61306
  1901
  next
lp15@61306
  1902
    case 2
lp15@61306
  1903
    then have "(A \<union> s) \<inter> (B - t) \<inter> u = {}"
lp15@61306
  1904
      using disj st
lp15@61306
  1905
      by auto
lp15@61306
  1906
    moreover have "u \<subseteq> (A \<union> s) \<union> (B - t)" using 2 cover by auto
lp15@61306
  1907
    ultimately show False
lp15@61306
  1908
      using connectedD [of u "A \<union> s" "B - t"] AB s t 2 u
lp15@61306
  1909
      by auto
lp15@61306
  1910
  qed
lp15@61306
  1911
qed
lp15@61306
  1912
hoelzl@59106
  1913
lemma connected_iff_const:
hoelzl@59106
  1914
  fixes S :: "'a::topological_space set"
hoelzl@59106
  1915
  shows "connected S \<longleftrightarrow> (\<forall>P::'a \<Rightarrow> bool. continuous_on S P \<longrightarrow> (\<exists>c. \<forall>s\<in>S. P s = c))"
hoelzl@59106
  1916
proof safe
hoelzl@59106
  1917
  fix P :: "'a \<Rightarrow> bool" assume "connected S" "continuous_on S P"
hoelzl@59106
  1918
  then have "\<And>b. \<exists>A. open A \<and> A \<inter> S = P -` {b} \<inter> S"
hoelzl@59106
  1919
    unfolding continuous_on_open_invariant by simp
hoelzl@59106
  1920
  from this[of True] this[of False]
hoelzl@59106
  1921
  obtain t f where "open t" "open f" and *: "f \<inter> S = P -` {False} \<inter> S" "t \<inter> S = P -` {True} \<inter> S"
hoelzl@59106
  1922
    by auto
hoelzl@59106
  1923
  then have "t \<inter> S = {} \<or> f \<inter> S = {}"
wenzelm@60758
  1924
    by (intro connectedD[OF \<open>connected S\<close>])  auto
hoelzl@59106
  1925
  then show "\<exists>c. \<forall>s\<in>S. P s = c"
hoelzl@59106
  1926
  proof (rule disjE)
hoelzl@59106
  1927
    assume "t \<inter> S = {}" then show ?thesis
hoelzl@59106
  1928
      unfolding * by (intro exI[of _ False]) auto
hoelzl@59106
  1929
  next
hoelzl@59106
  1930
    assume "f \<inter> S = {}" then show ?thesis
hoelzl@59106
  1931
      unfolding * by (intro exI[of _ True]) auto
hoelzl@59106
  1932
  qed
hoelzl@59106
  1933
next
hoelzl@59106
  1934
  assume P: "\<forall>P::'a \<Rightarrow> bool. continuous_on S P \<longrightarrow> (\<exists>c. \<forall>s\<in>S. P s = c)"
hoelzl@59106
  1935
  show "connected S"
hoelzl@59106
  1936
  proof (rule connectedI)
hoelzl@59106
  1937
    fix A B assume *: "open A" "open B" "A \<inter> S \<noteq> {}" "B \<inter> S \<noteq> {}" "A \<inter> B \<inter> S = {}" "S \<subseteq> A \<union> B"
hoelzl@59106
  1938
    have "continuous_on S (\<lambda>x. x \<in> A)"
hoelzl@59106
  1939
      unfolding continuous_on_open_invariant
hoelzl@59106
  1940
    proof safe
hoelzl@59106
  1941
      fix C :: "bool set"
hoelzl@59106
  1942
      have "C = UNIV \<or> C = {True} \<or> C = {False} \<or> C = {}"
hoelzl@59106
  1943
        using subset_UNIV[of C] unfolding UNIV_bool by auto
hoelzl@59106
  1944
      with * show "\<exists>T. open T \<and> T \<inter> S = (\<lambda>x. x \<in> A) -` C \<inter> S"
hoelzl@59106
  1945
        by (intro exI[of _ "(if True \<in> C then A else {}) \<union> (if False \<in> C then B else {})"]) auto
hoelzl@59106
  1946
    qed
hoelzl@59106
  1947
    from P[rule_format, OF this] obtain c where "\<And>s. s \<in> S \<Longrightarrow> (s \<in> A) = c" by blast
hoelzl@59106
  1948
    with * show False
hoelzl@59106
  1949
      by (cases c) auto
hoelzl@59106
  1950
  qed
hoelzl@59106
  1951
qed
hoelzl@59106
  1952
hoelzl@59106
  1953
lemma connectedD_const:
hoelzl@59106
  1954
  fixes P :: "'a::topological_space \<Rightarrow> bool"
hoelzl@59106
  1955
  shows "connected S \<Longrightarrow> continuous_on S P \<Longrightarrow> \<exists>c. \<forall>s\<in>S. P s = c"
hoelzl@59106
  1956
  unfolding connected_iff_const by auto
hoelzl@59106
  1957
hoelzl@59106
  1958
lemma connectedI_const:
hoelzl@59106
  1959
  "(\<And>P::'a::topological_space \<Rightarrow> bool. continuous_on S P \<Longrightarrow> \<exists>c. \<forall>s\<in>S. P s = c) \<Longrightarrow> connected S"
hoelzl@59106
  1960
  unfolding connected_iff_const by auto
hoelzl@59106
  1961
hoelzl@56329
  1962
lemma connected_local_const:
hoelzl@56329
  1963
  assumes "connected A" "a \<in> A" "b \<in> A"
hoelzl@56329
  1964
  assumes *: "\<forall>a\<in>A. eventually (\<lambda>b. f a = f b) (at a within A)"
hoelzl@56329
  1965
  shows "f a = f b"
hoelzl@56329
  1966
proof -
hoelzl@56329
  1967
  obtain S where S: "\<And>a. a \<in> A \<Longrightarrow> a \<in> S a" "\<And>a. a \<in> A \<Longrightarrow> open (S a)"
hoelzl@56329
  1968
    "\<And>a x. a \<in> A \<Longrightarrow> x \<in> S a \<Longrightarrow> x \<in> A \<Longrightarrow> f a = f x"
hoelzl@56329
  1969
    using * unfolding eventually_at_topological by metis
hoelzl@56329
  1970
hoelzl@56329
  1971
  let ?P = "\<Union>b\<in>{b\<in>A. f a = f b}. S b" and ?N = "\<Union>b\<in>{b\<in>A. f a \<noteq> f b}. S b"
hoelzl@56329
  1972
  have "?P \<inter> A = {} \<or> ?N \<inter> A = {}"
wenzelm@60758
  1973
    using \<open>connected A\<close> S \<open>a\<in>A\<close>
hoelzl@56329
  1974
    by (intro connectedD) (auto, metis)
hoelzl@56329
  1975
  then show "f a = f b"
hoelzl@56329
  1976
  proof
hoelzl@56329
  1977
    assume "?N \<inter> A = {}"
hoelzl@56329
  1978
    then have "\<forall>x\<in>A. f a = f x"
hoelzl@56329
  1979
      using S(1) by auto
wenzelm@60758
  1980
    with \<open>b\<in>A\<close> show ?thesis by auto
hoelzl@56329
  1981
  next
hoelzl@56329
  1982
    assume "?P \<inter> A = {}" then show ?thesis
wenzelm@60758
  1983
      using \<open>a \<in> A\<close> S(1)[of a] by auto
hoelzl@56329
  1984
  qed
hoelzl@56329
  1985
qed
hoelzl@56329
  1986
hoelzl@51480
  1987
lemma (in linorder_topology) connectedD_interval:
hoelzl@51480
  1988
  assumes "connected U" and xy: "x \<in> U" "y \<in> U" and "x \<le> z" "z \<le> y"
hoelzl@51480
  1989
  shows "z \<in> U"
hoelzl@51480
  1990
proof -
hoelzl@51480
  1991
  have eq: "{..<z} \<union> {z<..} = - {z}"
hoelzl@51480
  1992
    by auto
hoelzl@51480
  1993
  { assume "z \<notin> U" "x < z" "z < y"
hoelzl@51480
  1994
    with xy have "\<not> connected U"
hoelzl@51480
  1995
      unfolding connected_def simp_thms
hoelzl@51480
  1996
      apply (rule_tac exI[of _ "{..< z}"])
hoelzl@51480
  1997
      apply (rule_tac exI[of _ "{z <..}"])
hoelzl@51480
  1998
      apply (auto simp add: eq)
hoelzl@51480
  1999
      done }
hoelzl@51480
  2000
  with assms show "z \<in> U"
hoelzl@51480
  2001
    by (metis less_le)
hoelzl@51480
  2002
qed
hoelzl@51480
  2003
hoelzl@51480
  2004
lemma connected_continuous_image:
hoelzl@51480
  2005
  assumes *: "continuous_on s f"
hoelzl@51480
  2006
  assumes "connected s"
hoelzl@51480
  2007
  shows "connected (f ` s)"
hoelzl@59106
  2008
proof (rule connectedI_const)
hoelzl@59106
  2009
  fix P :: "'b \<Rightarrow> bool" assume "continuous_on (f ` s) P"
hoelzl@59106
  2010
  then have "continuous_on s (P \<circ> f)"
hoelzl@59106
  2011
    by (rule continuous_on_compose[OF *])
wenzelm@60758
  2012
  from connectedD_const[OF \<open>connected s\<close> this] show "\<exists>c. \<forall>s\<in>f ` s. P s = c"
hoelzl@59106
  2013
    by auto
hoelzl@51480
  2014
qed
hoelzl@51480
  2015
lp15@61306
  2016
lp15@61306
  2017
section \<open>Linear Continuum Topologies\<close>
hoelzl@51518
  2018
hoelzl@51775
  2019
class linear_continuum_topology = linorder_topology + linear_continuum
hoelzl@51518
  2020
begin
hoelzl@51518
  2021
hoelzl@51518
  2022
lemma Inf_notin_open:
hoelzl@51518
  2023
  assumes A: "open A" and bnd: "\<forall>a\<in>A. x < a"
hoelzl@51518
  2024
  shows "Inf A \<notin> A"
hoelzl@51518
  2025
proof
hoelzl@51518
  2026
  assume "Inf A \<in> A"
hoelzl@51518
  2027
  then obtain b where "b < Inf A" "{b <.. Inf A} \<subseteq> A"
hoelzl@51518
  2028
    using open_left[of A "Inf A" x] assms by auto
hoelzl@51518
  2029
  with dense[of b "Inf A"] obtain c where "c < Inf A" "c \<in> A"
hoelzl@51518
  2030
    by (auto simp: subset_eq)
hoelzl@51518
  2031
  then show False
wenzelm@60758
  2032
    using cInf_lower[OF \<open>c \<in> A\<close>] bnd by (metis not_le less_imp_le bdd_belowI)
hoelzl@51518
  2033
qed
hoelzl@51518
  2034
hoelzl@51518
  2035
lemma Sup_notin_open:
hoelzl@51518
  2036
  assumes A: "open A" and bnd: "\<forall>a\<in>A. a < x"
hoelzl@51518
  2037
  shows "Sup A \<notin> A"
hoelzl@51518
  2038
proof
hoelzl@51518
  2039
  assume "Sup A \<in> A"
hoelzl@51518
  2040
  then obtain b where "Sup A < b" "{Sup A ..< b} \<subseteq> A"
hoelzl@51518
  2041
    using open_right[of A "Sup A" x] assms by auto
hoelzl@51518
  2042
  with dense[of "Sup A" b] obtain c where "Sup A < c" "c \<in> A"
hoelzl@51518
  2043
    by (auto simp: subset_eq)
hoelzl@51518
  2044
  then show False
wenzelm@60758
  2045
    using cSup_upper[OF \<open>c \<in> A\<close>] bnd by (metis less_imp_le not_le bdd_aboveI)
hoelzl@51518
  2046
qed
hoelzl@51518
  2047
hoelzl@51480
  2048
end
hoelzl@51480
  2049
hoelzl@51775
  2050
instance linear_continuum_topology \<subseteq> perfect_space
hoelzl@51775
  2051
proof
hoelzl@51775
  2052
  fix x :: 'a
wenzelm@53381
  2053
  obtain y where "x < y \<or> y < x"
wenzelm@53381
  2054
    using ex_gt_or_lt [of x] ..
hoelzl@51775
  2055
  with Inf_notin_open[of "{x}" y] Sup_notin_open[of "{x}" y]
hoelzl@51775
  2056
  show "\<not> open {x}"
hoelzl@51775
  2057
    by auto
hoelzl@51775
  2058
qed
hoelzl@51775
  2059
hoelzl@51518
  2060
lemma connectedI_interval:
hoelzl@51775
  2061
  fixes U :: "'a :: linear_continuum_topology set"
hoelzl@51518
  2062
  assumes *: "\<And>x y z. x \<in> U \<Longrightarrow> y \<in> U \<Longrightarrow> x \<le> z \<Longrightarrow> z \<le> y \<Longrightarrow> z \<in> U"
hoelzl@51518
  2063
  shows "connected U"
hoelzl@51518
  2064
proof (rule connectedI)
hoelzl@51518
  2065
  { fix A B assume "open A" "open B" "A \<inter> B \<inter> U = {}" "U \<subseteq> A \<union> B"
hoelzl@51518
  2066
    fix x y assume "x < y" "x \<in> A" "y \<in> B" "x \<in> U" "y \<in> U"
hoelzl@51518
  2067
hoelzl@51518
  2068
    let ?z = "Inf (B \<inter> {x <..})"
hoelzl@51518
  2069
hoelzl@51518
  2070
    have "x \<le> ?z" "?z \<le> y"
wenzelm@60758
  2071
      using \<open>y \<in> B\<close> \<open>x < y\<close> by (auto intro: cInf_lower cInf_greatest)
wenzelm@60758
  2072
    with \<open>x \<in> U\<close> \<open>y \<in> U\<close> have "?z \<in> U"
hoelzl@51518
  2073
      by (rule *)
hoelzl@51518
  2074
    moreover have "?z \<notin> B \<inter> {x <..}"
wenzelm@60758
  2075
      using \<open>open B\<close> by (intro Inf_notin_open) auto
hoelzl@51518
  2076
    ultimately have "?z \<in> A"
wenzelm@60758
  2077
      using \<open>x \<le> ?z\<close> \<open>A \<inter> B \<inter> U = {}\<close> \<open>x \<in> A\<close> \<open>U \<subseteq> A \<union> B\<close> by auto
hoelzl@51518
  2078
hoelzl@51518
  2079
    { assume "?z < y"
hoelzl@51518
  2080
      obtain a where "?z < a" "{?z ..< a} \<subseteq> A"
wenzelm@60758
  2081
        using open_right[OF \<open>open A\<close> \<open>?z \<in> A\<close> \<open>?z < y\<close>] by auto
hoelzl@51518
  2082
      moreover obtain b where "b \<in> B" "x < b" "b < min a y"
wenzelm@60758
  2083
        using cInf_less_iff[of "B \<inter> {x <..}" "min a y"] \<open>?z < a\<close> \<open>?z < y\<close> \<open>x < y\<close> \<open>y \<in> B\<close>
hoelzl@51518
  2084
        by (auto intro: less_imp_le)
wenzelm@53374
  2085
      moreover have "?z \<le> b"
wenzelm@60758
  2086
        using \<open>b \<in> B\<close> \<open>x < b\<close>
hoelzl@54258
  2087
        by (intro cInf_lower) auto
hoelzl@51518
  2088
      moreover have "b \<in> U"
wenzelm@60758
  2089
        using \<open>x \<le> ?z\<close> \<open>?z \<le> b\<close> \<open>b < min a y\<close>
wenzelm@60758
  2090
        by (intro *[OF \<open>x \<in> U\<close> \<open>y \<in> U\<close>]) (auto simp: less_imp_le)
hoelzl@51518
  2091
      ultimately have "\<exists>b\<in>B. b \<in> A \<and> b \<in> U"
hoelzl@51518
  2092
        by (intro bexI[of _ b]) auto }
hoelzl@51518
  2093
    then have False
wenzelm@60758
  2094
      using \<open>?z \<le> y\<close> \<open>?z \<in> A\<close> \<open>y \<in> B\<close> \<open>y \<in> U\<close> \<open>A \<inter> B \<inter> U = {}\<close> unfolding le_less by blast }
hoelzl@51518
  2095
  note not_disjoint = this
hoelzl@51518
  2096
hoelzl@51518
  2097
  fix A B assume AB: "open A" "open B" "U \<subseteq> A \<union> B" "A \<inter> B \<inter> U = {}"
hoelzl@51518
  2098
  moreover assume "A \<inter> U \<noteq> {}" then obtain x where x: "x \<in> U" "x \<in> A" by auto
hoelzl@51518
  2099
  moreover assume "B \<inter> U \<noteq> {}" then obtain y where y: "y \<in> U" "y \<in> B" by auto
hoelzl@51518
  2100
  moreover note not_disjoint[of B A y x] not_disjoint[of A B x y]
hoelzl@51518
  2101
  ultimately show False by (cases x y rule: linorder_cases) auto
hoelzl@51518
  2102
qed
hoelzl@51518
  2103
hoelzl@51518
  2104
lemma connected_iff_interval:
hoelzl@51775
  2105
  fixes U :: "'a :: linear_continuum_topology set"
hoelzl@51518
  2106
  shows "connected U \<longleftrightarrow> (\<forall>x\<in>U. \<forall>y\<in>U. \<forall>z. x \<le> z \<longrightarrow> z \<le> y \<longrightarrow> z \<in> U)"
hoelzl@51518
  2107
  by (auto intro: connectedI_interval dest: connectedD_interval)
hoelzl@51518
  2108
hoelzl@51775
  2109
lemma connected_UNIV[simp]: "connected (UNIV::'a::linear_continuum_topology set)"
hoelzl@51518
  2110
  unfolding connected_iff_interval by auto
hoelzl@51518
  2111
hoelzl@51775
  2112
lemma connected_Ioi[simp]: "connected {a::'a::linear_continuum_topology <..}"
hoelzl@51518
  2113
  unfolding connected_iff_interval by auto
hoelzl@51518
  2114
hoelzl@51775
  2115
lemma connected_Ici[simp]: "connected {a::'a::linear_continuum_topology ..}"
hoelzl@51518
  2116
  unfolding connected_iff_interval by auto
hoelzl@51518
  2117
hoelzl@51775
  2118
lemma connected_Iio[simp]: "connected {..< a::'a::linear_continuum_topology}"
hoelzl@51518
  2119
  unfolding connected_iff_interval by auto
hoelzl@51518
  2120
hoelzl@51775
  2121
lemma connected_Iic[simp]: "connected {.. a::'a::linear_continuum_topology}"
hoelzl@51518
  2122
  unfolding connected_iff_interval by auto
hoelzl@51518
  2123
hoelzl@51775
  2124
lemma connected_Ioo[simp]: "connected {a <..< b::'a::linear_continuum_topology}"
hoelzl@51518
  2125
  unfolding connected_iff_interval by auto
hoelzl@51518
  2126
hoelzl@51775
  2127
lemma connected_Ioc[simp]: "connected {a <.. b::'a::linear_continuum_topology}"
hoelzl@51518
  2128
  unfolding connected_iff_interval by auto
hoelzl@51518
  2129
hoelzl@51775
  2130
lemma connected_Ico[simp]: "connected {a ..< b::'a::linear_continuum_topology}"
hoelzl@51518
  2131
  unfolding connected_iff_interval by auto
hoelzl@51518
  2132
hoelzl@51775
  2133
lemma connected_Icc[simp]: "connected {a .. b::'a::linear_continuum_topology}"
hoelzl@51518
  2134
  unfolding connected_iff_interval by auto
hoelzl@51518
  2135
hoelzl@51518
  2136
lemma connected_contains_Ioo: 
hoelzl@51518
  2137
  fixes A :: "'a :: linorder_topology set"
hoelzl@51518
  2138
  assumes A: "connected A" "a \<in> A" "b \<in> A" shows "{a <..< b} \<subseteq> A"
hoelzl@51518
  2139
  using connectedD_interval[OF A] by (simp add: subset_eq Ball_def less_imp_le)
hoelzl@51518
  2140
wenzelm@60758
  2141
subsection \<open>Intermediate Value Theorem\<close>
hoelzl@51518
  2142
hoelzl@51518
  2143
lemma IVT':
hoelzl@51775
  2144
  fixes f :: "'a :: linear_continuum_topology \<Rightarrow> 'b :: linorder_topology"
hoelzl@51518
  2145
  assumes y: "f a \<le> y" "y \<le> f b" "a \<le> b"
hoelzl@51518
  2146
  assumes *: "continuous_on {a .. b} f"
hoelzl@51518
  2147
  shows "\<exists>x. a \<le> x \<and> x \<le> b \<and> f x = y"
hoelzl@51518
  2148
proof -
hoelzl@51518
  2149
  have "connected {a..b}"
hoelzl@51518
  2150
    unfolding connected_iff_interval by auto
hoelzl@51518
  2151
  from connected_continuous_image[OF * this, THEN connectedD_interval, of "f a" "f b" y] y
hoelzl@51518
  2152
  show ?thesis
hoelzl@51518
  2153
    by (auto simp add: atLeastAtMost_def atLeast_def atMost_def)
hoelzl@51518
  2154
qed
hoelzl@51518
  2155
hoelzl@51518
  2156
lemma IVT2':
hoelzl@51775
  2157
  fixes f :: "'a :: linear_continuum_topology \<Rightarrow> 'b :: linorder_topology"
hoelzl@51518
  2158
  assumes y: "f b \<le> y" "y \<le> f a" "a \<le> b"
hoelzl@51518
  2159
  assumes *: "continuous_on {a .. b} f"
hoelzl@51518
  2160
  shows "\<exists>x. a \<le> x \<and> x \<le> b \<and> f x = y"
hoelzl@51518
  2161
proof -
hoelzl@51518
  2162
  have "connected {a..b}"
hoelzl@51518
  2163
    unfolding connected_iff_interval by auto
hoelzl@51518
  2164
  from connected_continuous_image[OF * this, THEN connectedD_interval, of "f b" "f a" y] y
hoelzl@51518
  2165
  show ?thesis
hoelzl@51518
  2166
    by (auto simp add: atLeastAtMost_def atLeast_def atMost_def)
hoelzl@51518
  2167
qed
hoelzl@51518
  2168
hoelzl@51518
  2169
lemma IVT:
hoelzl@51775
  2170
  fixes f :: "'a :: linear_continuum_topology \<Rightarrow> 'b :: linorder_topology"
hoelzl@51518
  2171
  shows "f a \<le> y \<Longrightarrow> y \<le> f b \<Longrightarrow> a \<le> b \<Longrightarrow> (\<forall>x. a \<le> x \<and> x \<le> b \<longrightarrow> isCont f x) \<Longrightarrow> \<exists>x. a \<le> x \<and> x \<le> b \<and> f x = y"
hoelzl@51518
  2172
  by (rule IVT') (auto intro: continuous_at_imp_continuous_on)
hoelzl@51518
  2173
hoelzl@51518
  2174
lemma IVT2:
hoelzl@51775
  2175
  fixes f :: "'a :: linear_continuum_topology \<Rightarrow> 'b :: linorder_topology"
hoelzl@51518
  2176
  shows "f b \<le> y \<Longrightarrow> y \<le> f a \<Longrightarrow> a \<le> b \<Longrightarrow> (\<forall>x. a \<le> x \<and> x \<le> b \<longrightarrow> isCont f x) \<Longrightarrow> \<exists>x. a \<le> x \<and> x \<le> b \<and> f x = y"
hoelzl@51518
  2177
  by (rule IVT2') (auto intro: continuous_at_imp_continuous_on)
hoelzl@51518
  2178
hoelzl@51518
  2179
lemma continuous_inj_imp_mono:
hoelzl@51775
  2180
  fixes f :: "'a::linear_continuum_topology \<Rightarrow> 'b :: linorder_topology"
hoelzl@51518
  2181
  assumes x: "a < x" "x < b"
hoelzl@51518
  2182
  assumes cont: "continuous_on {a..b} f"
hoelzl@51518
  2183
  assumes inj: "inj_on f {a..b}"
hoelzl@51518
  2184
  shows "(f a < f x \<and> f x < f b) \<or> (f b < f x \<and> f x < f a)"
hoelzl@51518
  2185
proof -
hoelzl@51518
  2186
  note I = inj_on_iff[OF inj]
hoelzl@51518
  2187
  { assume "f x < f a" "f x < f b"
hoelzl@51518
  2188
    then obtain s t where "x \<le> s" "s \<le> b" "a \<le> t" "t \<le> x" "f s = f t" "f x < f s"
hoelzl@51518
  2189
      using IVT'[of f x "min (f a) (f b)" b] IVT2'[of f x "min (f a) (f b)" a] x
hoelzl@51518
  2190
      by (auto simp: continuous_on_subset[OF cont] less_imp_le)
hoelzl@51518
  2191
    with x I have False by auto }
hoelzl@51518
  2192
  moreover
hoelzl@51518
  2193
  { assume "f a < f x" "f b < f x"
hoelzl@51518
  2194
    then obtain s t where "x \<le> s" "s \<le> b" "a \<le> t" "t \<le> x" "f s = f t" "f s < f x"
hoelzl@51518
  2195
      using IVT'[of f a "max (f a) (f b)" x] IVT2'[of f b "max (f a) (f b)" x] x
hoelzl@51518
  2196
      by (auto simp: continuous_on_subset[OF cont] less_imp_le)
hoelzl@51518
  2197
    with x I have False by auto }
hoelzl@51518
  2198
  ultimately show ?thesis
hoelzl@51518
  2199
    using I[of a x] I[of x b] x less_trans[OF x] by (auto simp add: le_less less_imp_neq neq_iff)
hoelzl@51518
  2200
qed
hoelzl@51518
  2201
hoelzl@59452
  2202
lemma continuous_at_Sup_mono:
hoelzl@59452
  2203
  fixes f :: "'a :: {linorder_topology, conditionally_complete_linorder} \<Rightarrow> 'b :: {linorder_topology, conditionally_complete_linorder}"
hoelzl@59452
  2204
  assumes "mono f"
hoelzl@59452
  2205
  assumes cont: "continuous (at_left (Sup S)) f"
hoelzl@59452
  2206
  assumes S: "S \<noteq> {}" "bdd_above S"
hoelzl@59452
  2207
  shows "f (Sup S) = (SUP s:S. f s)"
hoelzl@59452
  2208
proof (rule antisym)
hoelzl@59452
  2209
  have f: "(f ---> f (Sup S)) (at_left (Sup S))"
hoelzl@59452
  2210
    using cont unfolding continuous_within .
hoelzl@59452
  2211
hoelzl@59452
  2212
  show "f (Sup S) \<le> (SUP s:S. f s)"
hoelzl@59452
  2213
  proof cases
hoelzl@59452
  2214
    assume "Sup S \<in> S" then show ?thesis
wenzelm@60758
  2215
      by (rule cSUP_upper) (auto intro: bdd_above_image_mono S \<open>mono f\<close>)
hoelzl@59452
  2216
  next
hoelzl@59452
  2217
    assume "Sup S \<notin> S"
wenzelm@60758
  2218
    from \<open>S \<noteq> {}\<close> obtain s where "s \<in> S"
hoelzl@59452
  2219
      by auto
wenzelm@60758
  2220
    with \<open>Sup S \<notin> S\<close> S have "s < Sup S"
hoelzl@59452
  2221
      unfolding less_le by (blast intro: cSup_upper)
hoelzl@59452
  2222
    show ?thesis
hoelzl@59452
  2223
    proof (rule ccontr)
hoelzl@59452
  2224
      assume "\<not> ?thesis"
hoelzl@59452
  2225
      with order_tendstoD(1)[OF f, of "SUP s:S. f s"] obtain b where "b < Sup S"
hoelzl@59452
  2226
        and *: "\<And>y. b < y \<Longrightarrow> y < Sup S \<Longrightarrow> (SUP s:S. f s) < f y"
wenzelm@60758
  2227
        by (auto simp: not_le eventually_at_left[OF \<open>s < Sup S\<close>])
wenzelm@60758
  2228
      with \<open>S \<noteq> {}\<close> obtain c where "c \<in> S" "b < c"
hoelzl@59452
  2229
        using less_cSupD[of S b] by auto
wenzelm@60758
  2230
      with \<open>Sup S \<notin> S\<close> S have "c < Sup S"
hoelzl@59452
  2231
        unfolding less_le by (blast intro: cSup_upper)
wenzelm@60758
  2232
      from *[OF \<open>b < c\<close> \<open>c < Sup S\<close>] cSUP_upper[OF \<open>c \<in> S\<close> bdd_above_image_mono[of f]]
hoelzl@59452
  2233
      show False
hoelzl@59452
  2234
        by (auto simp: assms)
hoelzl@59452
  2235
    qed
hoelzl@59452
  2236
  qed
wenzelm@60758
  2237
qed (intro cSUP_least \<open>mono f\<close>[THEN monoD] cSup_upper S)
hoelzl@59452
  2238
hoelzl@59452
  2239
lemma continuous_at_Sup_antimono:
hoelzl@59452
  2240
  fixes f :: "'a :: {linorder_topology, conditionally_complete_linorder} \<Rightarrow> 'b :: {linorder_topology, conditionally_complete_linorder}"
hoelzl@59452
  2241
  assumes "antimono f"
hoelzl@59452
  2242
  assumes cont: "continuous (at_left (Sup S)) f"
hoelzl@59452
  2243
  assumes S: "S \<noteq> {}" "bdd_above S"
hoelzl@59452
  2244
  shows "f (Sup S) = (INF s:S. f s)"
hoelzl@59452
  2245
proof (rule antisym)
hoelzl@59452
  2246
  have f: "(f ---> f (Sup S)) (at_left (Sup S))"
hoelzl@59452
  2247
    using cont unfolding continuous_within .
hoelzl@59452
  2248
hoelzl@59452
  2249
  show "(INF s:S. f s) \<le> f (Sup S)"
hoelzl@59452
  2250
  proof cases
hoelzl@59452
  2251
    assume "Sup S \<in> S" then show ?thesis
wenzelm@60758
  2252
      by (intro cINF_lower) (auto intro: bdd_below_image_antimono S \<open>antimono f\<close>)
hoelzl@59452
  2253
  next
hoelzl@59452
  2254
    assume "Sup S \<notin> S"
wenzelm@60758
  2255
    from \<open>S \<noteq> {}\<close> obtain s where "s \<in> S"
hoelzl@59452
  2256
      by auto
wenzelm@60758
  2257
    with \<open>Sup S \<notin> S\<close> S have "s < Sup S"
hoelzl@59452
  2258
      unfolding less_le by (blast intro: cSup_upper)
hoelzl@59452
  2259
    show ?thesis
hoelzl@59452
  2260
    proof (rule ccontr)
hoelzl@59452
  2261
      assume "\<not> ?thesis"
hoelzl@59452
  2262
      with order_tendstoD(2)[OF f, of "INF s:S. f s"] obtain b where "b < Sup S"
hoelzl@59452
  2263
        and *: "\<And>y. b < y \<Longrightarrow> y < Sup S \<Longrightarrow> f y < (INF s:S. f s)"
wenzelm@60758
  2264
        by (auto simp: not_le eventually_at_left[OF \<open>s < Sup S\<close>])
wenzelm@60758
  2265
      with \<open>S \<noteq> {}\<close> obtain c where "c \<in> S" "b < c"
hoelzl@59452
  2266
        using less_cSupD[of S b] by auto
wenzelm@60758
  2267
      with \<open>Sup S \<notin> S\<close> S have "c < Sup S"
hoelzl@59452
  2268
        unfolding less_le by (blast intro: cSup_upper)
wenzelm@60758
  2269
      from *[OF \<open>b < c\<close> \<open>c < Sup S\<close>] cINF_lower[OF bdd_below_image_antimono, of f S c] \<open>c \<in> S\<close>
hoelzl@59452
  2270
      show False
hoelzl@59452
  2271
        by (auto simp: assms)
hoelzl@59452
  2272
    qed
hoelzl@59452
  2273
  qed
wenzelm@60758
  2274
qed (intro cINF_greatest \<open>antimono f\<close>[THEN antimonoD] cSup_upper S)
hoelzl@59452
  2275
hoelzl@59452
  2276
lemma continuous_at_Inf_mono:
hoelzl@59452
  2277
  fixes f :: "'a :: {linorder_topology, conditionally_complete_linorder} \<Rightarrow> 'b :: {linorder_topology, conditionally_complete_linorder}"
hoelzl@59452
  2278
  assumes "mono f"
hoelzl@59452
  2279
  assumes cont: "continuous (at_right (Inf S)) f"
hoelzl@59452
  2280
  assumes S: "S \<noteq> {}" "bdd_below S"
hoelzl@59452
  2281
  shows "f (Inf S) = (INF s:S. f s)"
hoelzl@59452
  2282
proof (rule antisym)
hoelzl@59452
  2283
  have f: "(f ---> f (Inf S)) (at_right (Inf S))"
hoelzl@59452
  2284
    using cont unfolding continuous_within .
hoelzl@59452
  2285
hoelzl@59452
  2286
  show "(INF s:S. f s) \<le> f (Inf S)"
hoelzl@59452
  2287
  proof cases
hoelzl@59452
  2288
    assume "Inf S \<in> S" then show ?thesis
wenzelm@60758
  2289
      by (rule cINF_lower[rotated]) (auto intro: bdd_below_image_mono S \<open>mono f\<close>)
hoelzl@59452
  2290
  next
hoelzl@59452
  2291
    assume "Inf S \<notin> S"
wenzelm@60758
  2292
    from \<open>S \<noteq> {}\<close> obtain s where "s \<in> S"
hoelzl@59452
  2293
      by auto
wenzelm@60758
  2294
    with \<open>Inf S \<notin> S\<close> S have "Inf S < s"
hoelzl@59452
  2295
      unfolding less_le by (blast intro: cInf_lower)
hoelzl@59452
  2296
    show ?thesis
hoelzl@59452
  2297
    proof (rule ccontr)
hoelzl@59452
  2298
      assume "\<not> ?thesis"
hoelzl@59452
  2299
      with order_tendstoD(2)[OF f, of "INF s:S. f s"] obtain b where "Inf S < b"
hoelzl@59452
  2300
        and *: "\<And>y. Inf S < y \<Longrightarrow> y < b \<Longrightarrow> f y < (INF s:S. f s)"
wenzelm@60758
  2301
        by (auto simp: not_le eventually_at_right[OF \<open>Inf S < s\<close>])
wenzelm@60758
  2302
      with \<open>S \<noteq> {}\<close> obtain c where "c \<in> S" "c < b"
hoelzl@59452
  2303
        using cInf_lessD[of S b] by auto
wenzelm@60758
  2304
      with \<open>Inf S \<notin> S\<close> S have "Inf S < c"
hoelzl@59452
  2305
        unfolding less_le by (blast intro: cInf_lower)
wenzelm@60758
  2306
      from *[OF \<open>Inf S < c\<close> \<open>c < b\<close>] cINF_lower[OF bdd_below_image_mono[of f] \<open>c \<in> S\<close>]
hoelzl@59452
  2307
      show False
hoelzl@59452
  2308
        by (auto simp: assms)
hoelzl@59452
  2309
    qed
hoelzl@59452
  2310
  qed
wenzelm@60758
  2311
qed (intro cINF_greatest \<open>mono f\<close>[THEN monoD] cInf_lower \<open>bdd_below S\<close> \<open>S \<noteq> {}\<close>)
hoelzl@59452
  2312