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