src/HOL/Topological_Spaces.thy
author paulson <lp15@cam.ac.uk>
Tue Apr 25 16:39:54 2017 +0100 (2017-04-25)
changeset 65578 e4997c181cce
parent 65204 d23eded35a33
child 65583 8d53b3bebab4
permissions -rw-r--r--
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
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
wenzelm@63494
   665
wenzelm@60758
   666
subsubsection \<open>Tendsto\<close>
hoelzl@51471
   667
hoelzl@51471
   668
abbreviation (in topological_space)
wenzelm@63494
   669
  tendsto :: "('b \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'b filter \<Rightarrow> bool"  (infixr "\<longlongrightarrow>" 55)
wenzelm@63494
   670
  where "(f \<longlongrightarrow> l) F \<equiv> filterlim f (nhds l) F"
wenzelm@63494
   671
wenzelm@63494
   672
definition (in t2_space) Lim :: "'f filter \<Rightarrow> ('f \<Rightarrow> 'a) \<Rightarrow> 'a"
wenzelm@63494
   673
  where "Lim A f = (THE l. (f \<longlongrightarrow> l) A)"
hoelzl@51478
   674
immler@65204
   675
lemma (in topological_space) tendsto_eq_rhs: "(f \<longlongrightarrow> x) F \<Longrightarrow> x = y \<Longrightarrow> (f \<longlongrightarrow> y) F"
hoelzl@51471
   676
  by simp
hoelzl@51471
   677
wenzelm@57953
   678
named_theorems tendsto_intros "introduction rules for tendsto"
wenzelm@60758
   679
setup \<open>
hoelzl@51471
   680
  Global_Theory.add_thms_dynamic (@{binding tendsto_eq_intros},
wenzelm@57953
   681
    fn context =>
wenzelm@57953
   682
      Named_Theorems.get (Context.proof_of context) @{named_theorems tendsto_intros}
wenzelm@57953
   683
      |> map_filter (try (fn thm => @{thm tendsto_eq_rhs} OF [thm])))
wenzelm@60758
   684
\<close>
hoelzl@51471
   685
immler@65204
   686
context topological_space begin
immler@65204
   687
immler@65204
   688
lemma tendsto_def:
wenzelm@61973
   689
   "(f \<longlongrightarrow> l) F \<longleftrightarrow> (\<forall>S. open S \<longrightarrow> l \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) F)"
hoelzl@57276
   690
   unfolding nhds_def filterlim_INF filterlim_principal by auto
hoelzl@51471
   691
wenzelm@63494
   692
lemma tendsto_cong: "(f \<longlongrightarrow> c) F \<longleftrightarrow> (g \<longlongrightarrow> c) F" if "eventually (\<lambda>x. f x = g x) F"
wenzelm@63494
   693
  by (rule filterlim_cong [OF refl refl that])
eberlm@61531
   694
wenzelm@61973
   695
lemma tendsto_mono: "F \<le> F' \<Longrightarrow> (f \<longlongrightarrow> l) F' \<Longrightarrow> (f \<longlongrightarrow> l) F"
hoelzl@51471
   696
  unfolding tendsto_def le_filter_def by fast
hoelzl@51471
   697
immler@65204
   698
lemma tendsto_ident_at [tendsto_intros, simp, intro]: "((\<lambda>x. x) \<longlongrightarrow> a) (at a within s)"
immler@65204
   699
  by (auto simp: tendsto_def eventually_at_topological)
immler@65204
   700
immler@65204
   701
lemma tendsto_const [tendsto_intros, simp, intro]: "((\<lambda>x. k) \<longlongrightarrow> k) F"
immler@65204
   702
  by (simp add: tendsto_def)
immler@65204
   703
immler@65204
   704
lemma  filterlim_at:
wenzelm@63494
   705
  "(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
   706
  by (simp add: at_within_def filterlim_inf filterlim_principal conj_commute)
hoelzl@51641
   707
immler@65204
   708
lemma  filterlim_at_withinI:
eberlm@63713
   709
  assumes "filterlim f (nhds c) F"
eberlm@63713
   710
  assumes "eventually (\<lambda>x. f x \<in> A - {c}) F"
eberlm@63713
   711
  shows   "filterlim f (at c within A) F"
hoelzl@64008
   712
  using assms by (simp add: filterlim_at)
eberlm@63713
   713
eberlm@63713
   714
lemma filterlim_atI:
eberlm@63713
   715
  assumes "filterlim f (nhds c) F"
eberlm@63713
   716
  assumes "eventually (\<lambda>x. f x \<noteq> c) F"
eberlm@63713
   717
  shows   "filterlim f (at c) F"
eberlm@63713
   718
  using assms by (intro filterlim_at_withinI) simp_all
eberlm@63713
   719
immler@65204
   720
lemma topological_tendstoI:
wenzelm@61973
   721
  "(\<And>S. open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) F) \<Longrightarrow> (f \<longlongrightarrow> l) F"
wenzelm@63494
   722
  by (auto simp: tendsto_def)
hoelzl@51471
   723
immler@65204
   724
lemma topological_tendstoD:
wenzelm@61973
   725
  "(f \<longlongrightarrow> l) F \<Longrightarrow> open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) F"
wenzelm@63494
   726
  by (auto simp: tendsto_def)
hoelzl@51471
   727
immler@65204
   728
lemma tendsto_bot [simp]: "(f \<longlongrightarrow> a) bot"
immler@65204
   729
  by (simp add: tendsto_def)
immler@65204
   730
immler@65204
   731
end
immler@65204
   732
immler@65204
   733
lemma tendsto_within_subset:
immler@65204
   734
  "(f \<longlongrightarrow> l) (at x within S) \<Longrightarrow> T \<subseteq> S \<Longrightarrow> (f \<longlongrightarrow> l) (at x within T)"
immler@65204
   735
  by (blast intro: tendsto_mono at_le)
immler@65204
   736
hoelzl@57448
   737
lemma (in order_topology) order_tendsto_iff:
wenzelm@61973
   738
  "(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
   739
  by (auto simp: nhds_order filterlim_inf filterlim_INF filterlim_principal)
hoelzl@57448
   740
hoelzl@57448
   741
lemma (in order_topology) order_tendstoI:
hoelzl@57448
   742
  "(\<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
   743
    (f \<longlongrightarrow> y) F"
wenzelm@63494
   744
  by (auto simp: order_tendsto_iff)
hoelzl@57448
   745
hoelzl@57448
   746
lemma (in order_topology) order_tendstoD:
wenzelm@61973
   747
  assumes "(f \<longlongrightarrow> y) F"
hoelzl@51471
   748
  shows "a < y \<Longrightarrow> eventually (\<lambda>x. a < f x) F"
hoelzl@51471
   749
    and "y < a \<Longrightarrow> eventually (\<lambda>x. f x < a) F"
wenzelm@63494
   750
  using assms by (auto simp: order_tendsto_iff)
hoelzl@51471
   751
hoelzl@57448
   752
lemma (in linorder_topology) tendsto_max:
wenzelm@61973
   753
  assumes X: "(X \<longlongrightarrow> x) net"
wenzelm@63494
   754
    and Y: "(Y \<longlongrightarrow> y) net"
wenzelm@61973
   755
  shows "((\<lambda>x. max (X x) (Y x)) \<longlongrightarrow> max x y) net"
hoelzl@56949
   756
proof (rule order_tendstoI)
wenzelm@63494
   757
  fix a
wenzelm@63494
   758
  assume "a < max x y"
hoelzl@56949
   759
  then show "eventually (\<lambda>x. a < max (X x) (Y x)) net"
hoelzl@56949
   760
    using order_tendstoD(1)[OF X, of a] order_tendstoD(1)[OF Y, of a]
lp15@61810
   761
    by (auto simp: less_max_iff_disj elim: eventually_mono)
hoelzl@56949
   762
next
wenzelm@63494
   763
  fix a
wenzelm@63494
   764
  assume "max x y < a"
hoelzl@56949
   765
  then show "eventually (\<lambda>x. max (X x) (Y x) < a) net"
hoelzl@56949
   766
    using order_tendstoD(2)[OF X, of a] order_tendstoD(2)[OF Y, of a]
hoelzl@56949
   767
    by (auto simp: eventually_conj_iff)
hoelzl@56949
   768
qed
hoelzl@56949
   769
hoelzl@57448
   770
lemma (in linorder_topology) tendsto_min:
wenzelm@61973
   771
  assumes X: "(X \<longlongrightarrow> x) net"
wenzelm@63494
   772
    and Y: "(Y \<longlongrightarrow> y) net"
wenzelm@61973
   773
  shows "((\<lambda>x. min (X x) (Y x)) \<longlongrightarrow> min x y) net"
hoelzl@56949
   774
proof (rule order_tendstoI)
wenzelm@63494
   775
  fix a
wenzelm@63494
   776
  assume "a < min x y"
hoelzl@56949
   777
  then show "eventually (\<lambda>x. a < min (X x) (Y x)) net"
hoelzl@56949
   778
    using order_tendstoD(1)[OF X, of a] order_tendstoD(1)[OF Y, of a]
hoelzl@56949
   779
    by (auto simp: eventually_conj_iff)
hoelzl@56949
   780
next
wenzelm@63494
   781
  fix a
wenzelm@63494
   782
  assume "min x y < a"
hoelzl@56949
   783
  then show "eventually (\<lambda>x. min (X x) (Y x) < a) net"
hoelzl@56949
   784
    using order_tendstoD(2)[OF X, of a] order_tendstoD(2)[OF Y, of a]
lp15@61810
   785
    by (auto simp: min_less_iff_disj elim: eventually_mono)
hoelzl@56949
   786
qed
hoelzl@56949
   787
immler@65204
   788
lemma (in order_topology)
immler@65204
   789
  assumes "a < b"
immler@65204
   790
  shows at_within_Icc_at_right: "at a within {a..b} = at_right a"
immler@65204
   791
    and at_within_Icc_at_left:  "at b within {a..b} = at_left b"
immler@65204
   792
  using order_tendstoD(2)[OF tendsto_ident_at assms, of "{a<..}"]
immler@65204
   793
  using order_tendstoD(1)[OF tendsto_ident_at assms, of "{..<b}"]
immler@65204
   794
  by (auto intro!: order_class.antisym filter_leI
immler@65204
   795
      simp: eventually_at_filter less_le
immler@65204
   796
      elim: eventually_elim2)
immler@65204
   797
immler@65204
   798
lemma (in order_topology) at_within_Icc_at: "a < x \<Longrightarrow> x < b \<Longrightarrow> at x within {a..b} = at x"
immler@65204
   799
  by (rule at_within_open_subset[where S="{a<..<b}"]) auto
hoelzl@51471
   800
hoelzl@51478
   801
lemma (in t2_space) tendsto_unique:
wenzelm@63494
   802
  assumes "F \<noteq> bot"
wenzelm@63494
   803
    and "(f \<longlongrightarrow> a) F"
wenzelm@63494
   804
    and "(f \<longlongrightarrow> b) F"
hoelzl@51471
   805
  shows "a = b"
hoelzl@51471
   806
proof (rule ccontr)
hoelzl@51471
   807
  assume "a \<noteq> b"
hoelzl@51471
   808
  obtain U V where "open U" "open V" "a \<in> U" "b \<in> V" "U \<inter> V = {}"
wenzelm@60758
   809
    using hausdorff [OF \<open>a \<noteq> b\<close>] by fast
hoelzl@51471
   810
  have "eventually (\<lambda>x. f x \<in> U) F"
wenzelm@61973
   811
    using \<open>(f \<longlongrightarrow> a) F\<close> \<open>open U\<close> \<open>a \<in> U\<close> by (rule topological_tendstoD)
hoelzl@51471
   812
  moreover
hoelzl@51471
   813
  have "eventually (\<lambda>x. f x \<in> V) F"
wenzelm@61973
   814
    using \<open>(f \<longlongrightarrow> b) F\<close> \<open>open V\<close> \<open>b \<in> V\<close> by (rule topological_tendstoD)
hoelzl@51471
   815
  ultimately
hoelzl@51471
   816
  have "eventually (\<lambda>x. False) F"
hoelzl@51471
   817
  proof eventually_elim
hoelzl@51471
   818
    case (elim x)
wenzelm@63494
   819
    then have "f x \<in> U \<inter> V" by simp
wenzelm@60758
   820
    with \<open>U \<inter> V = {}\<close> show ?case by simp
hoelzl@51471
   821
  qed
wenzelm@60758
   822
  with \<open>\<not> trivial_limit F\<close> show "False"
hoelzl@51471
   823
    by (simp add: trivial_limit_def)
hoelzl@51471
   824
qed
hoelzl@51471
   825
hoelzl@51478
   826
lemma (in t2_space) tendsto_const_iff:
wenzelm@63494
   827
  fixes a b :: 'a
wenzelm@63494
   828
  assumes "\<not> trivial_limit F"
wenzelm@63494
   829
  shows "((\<lambda>x. a) \<longlongrightarrow> b) F \<longleftrightarrow> a = b"
hoelzl@58729
   830
  by (auto intro!: tendsto_unique [OF assms tendsto_const])
hoelzl@51471
   831
immler@65204
   832
lemma (in order_topology) increasing_tendsto:
hoelzl@51471
   833
  assumes bdd: "eventually (\<lambda>n. f n \<le> l) F"
wenzelm@63494
   834
    and en: "\<And>x. x < l \<Longrightarrow> eventually (\<lambda>n. x < f n) F"
wenzelm@61973
   835
  shows "(f \<longlongrightarrow> l) F"
lp15@61810
   836
  using assms by (intro order_tendstoI) (auto elim!: eventually_mono)
hoelzl@51471
   837
immler@65204
   838
lemma (in order_topology) decreasing_tendsto:
hoelzl@51471
   839
  assumes bdd: "eventually (\<lambda>n. l \<le> f n) F"
wenzelm@63494
   840
    and en: "\<And>x. l < x \<Longrightarrow> eventually (\<lambda>n. f n < x) F"
wenzelm@61973
   841
  shows "(f \<longlongrightarrow> l) F"
lp15@61810
   842
  using assms by (intro order_tendstoI) (auto elim!: eventually_mono)
hoelzl@51471
   843
immler@65204
   844
lemma (in order_topology) tendsto_sandwich:
hoelzl@51471
   845
  assumes ev: "eventually (\<lambda>n. f n \<le> g n) net" "eventually (\<lambda>n. g n \<le> h n) net"
wenzelm@61973
   846
  assumes lim: "(f \<longlongrightarrow> c) net" "(h \<longlongrightarrow> c) net"
wenzelm@61973
   847
  shows "(g \<longlongrightarrow> c) net"
hoelzl@51471
   848
proof (rule order_tendstoI)
wenzelm@63494
   849
  fix a
wenzelm@63494
   850
  show "a < c \<Longrightarrow> eventually (\<lambda>x. a < g x) net"
hoelzl@51471
   851
    using order_tendstoD[OF lim(1), of a] ev by (auto elim: eventually_elim2)
hoelzl@51471
   852
next
wenzelm@63494
   853
  fix a
wenzelm@63494
   854
  show "c < a \<Longrightarrow> eventually (\<lambda>x. g x < a) net"
hoelzl@51471
   855
    using order_tendstoD[OF lim(2), of a] ev by (auto elim: eventually_elim2)
hoelzl@51471
   856
qed
hoelzl@51471
   857
immler@65204
   858
lemma (in t1_space) limit_frequently_eq:
eberlm@61531
   859
  assumes "F \<noteq> bot"
wenzelm@63494
   860
    and "frequently (\<lambda>x. f x = c) F"
wenzelm@63494
   861
    and "(f \<longlongrightarrow> d) F"
wenzelm@63494
   862
  shows "d = c"
eberlm@61531
   863
proof (rule ccontr)
eberlm@61531
   864
  assume "d \<noteq> c"
wenzelm@63494
   865
  from t1_space[OF this] obtain U where "open U" "d \<in> U" "c \<notin> U"
wenzelm@63494
   866
    by blast
wenzelm@63494
   867
  with assms have "eventually (\<lambda>x. f x \<in> U) F"
wenzelm@63494
   868
    unfolding tendsto_def by blast
wenzelm@63494
   869
  then have "eventually (\<lambda>x. f x \<noteq> c) F"
wenzelm@63494
   870
    by eventually_elim (insert \<open>c \<notin> U\<close>, blast)
wenzelm@63494
   871
  with assms(2) show False
wenzelm@63494
   872
    unfolding frequently_def by contradiction
eberlm@61531
   873
qed
eberlm@61531
   874
immler@65204
   875
lemma (in t1_space) tendsto_imp_eventually_ne:
lp15@64394
   876
  assumes  "(f \<longlongrightarrow> c) F" "c \<noteq> c'"
wenzelm@63494
   877
  shows "eventually (\<lambda>z. f z \<noteq> c') F"
lp15@64394
   878
proof (cases "F=bot")
lp15@64394
   879
  case True
lp15@64394
   880
  thus ?thesis by auto
lp15@64394
   881
next
lp15@64394
   882
  case False
lp15@64394
   883
  show ?thesis
lp15@64394
   884
  proof (rule ccontr)
lp15@64394
   885
    assume "\<not> eventually (\<lambda>z. f z \<noteq> c') F"
lp15@64394
   886
    then have "frequently (\<lambda>z. f z = c') F"
lp15@64394
   887
      by (simp add: frequently_def)
lp15@64394
   888
    from limit_frequently_eq[OF False this \<open>(f \<longlongrightarrow> c) F\<close>] and \<open>c \<noteq> c'\<close> show False
lp15@64394
   889
      by contradiction
lp15@64394
   890
  qed
eberlm@61531
   891
qed
eberlm@61531
   892
immler@65204
   893
lemma (in linorder_topology) tendsto_le:
hoelzl@51471
   894
  assumes F: "\<not> trivial_limit F"
wenzelm@63494
   895
    and x: "(f \<longlongrightarrow> x) F"
wenzelm@63494
   896
    and y: "(g \<longlongrightarrow> y) F"
wenzelm@63494
   897
    and ev: "eventually (\<lambda>x. g x \<le> f x) F"
hoelzl@51471
   898
  shows "y \<le> x"
hoelzl@51471
   899
proof (rule ccontr)
hoelzl@51471
   900
  assume "\<not> y \<le> x"
hoelzl@51471
   901
  with less_separate[of x y] obtain a b where xy: "x < a" "b < y" "{..<a} \<inter> {b<..} = {}"
hoelzl@51471
   902
    by (auto simp: not_le)
hoelzl@51471
   903
  then have "eventually (\<lambda>x. f x < a) F" "eventually (\<lambda>x. b < g x) F"
hoelzl@51471
   904
    using x y by (auto intro: order_tendstoD)
hoelzl@51471
   905
  with ev have "eventually (\<lambda>x. False) F"
hoelzl@51471
   906
    by eventually_elim (insert xy, fastforce)
hoelzl@51471
   907
  with F show False
hoelzl@51471
   908
    by (simp add: eventually_False)
hoelzl@51471
   909
qed
hoelzl@51471
   910
immler@65204
   911
lemma (in linorder_topology) tendsto_lowerbound:
lp15@63952
   912
  assumes x: "(f \<longlongrightarrow> x) F"
lp15@63952
   913
      and ev: "eventually (\<lambda>i. a \<le> f i) F"
lp15@63952
   914
      and F: "\<not> trivial_limit F"
hoelzl@51471
   915
  shows "a \<le> x"
wenzelm@63494
   916
  using F x tendsto_const ev by (rule tendsto_le)
hoelzl@51471
   917
immler@65204
   918
lemma (in linorder_topology) tendsto_upperbound:
lp15@63952
   919
  assumes x: "(f \<longlongrightarrow> x) F"
lp15@63952
   920
      and ev: "eventually (\<lambda>i. a \<ge> f i) F"
lp15@63952
   921
      and F: "\<not> trivial_limit F"
lp15@56289
   922
  shows "a \<ge> x"
wenzelm@63494
   923
  by (rule tendsto_le [OF F tendsto_const x ev])
lp15@56289
   924
eberlm@61531
   925
wenzelm@60758
   926
subsubsection \<open>Rules about @{const Lim}\<close>
hoelzl@51478
   927
wenzelm@63494
   928
lemma tendsto_Lim: "\<not> trivial_limit net \<Longrightarrow> (f \<longlongrightarrow> l) net \<Longrightarrow> Lim net f = l"
wenzelm@63494
   929
  unfolding Lim_def using tendsto_unique [of net f] by auto
hoelzl@51478
   930
hoelzl@51641
   931
lemma Lim_ident_at: "\<not> trivial_limit (at x within s) \<Longrightarrow> Lim (at x within s) (\<lambda>x. x) = x"
hoelzl@51478
   932
  by (rule tendsto_Lim[OF _ tendsto_ident_at]) auto
hoelzl@51478
   933
hoelzl@51471
   934
lemma filterlim_at_bot_at_right:
hoelzl@57275
   935
  fixes f :: "'a::linorder_topology \<Rightarrow> 'b::linorder"
hoelzl@51471
   936
  assumes mono: "\<And>x y. Q x \<Longrightarrow> Q y \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y"
wenzelm@63494
   937
    and bij: "\<And>x. P x \<Longrightarrow> f (g x) = x" "\<And>x. P x \<Longrightarrow> Q (g x)"
wenzelm@63494
   938
    and Q: "eventually Q (at_right a)"
wenzelm@63494
   939
    and bound: "\<And>b. Q b \<Longrightarrow> a < b"
wenzelm@63494
   940
    and P: "eventually P at_bot"
hoelzl@51471
   941
  shows "filterlim f at_bot (at_right a)"
hoelzl@51471
   942
proof -
hoelzl@51471
   943
  from P obtain x where x: "\<And>y. y \<le> x \<Longrightarrow> P y"
hoelzl@51471
   944
    unfolding eventually_at_bot_linorder by auto
hoelzl@51471
   945
  show ?thesis
hoelzl@51471
   946
  proof (intro filterlim_at_bot_le[THEN iffD2] allI impI)
wenzelm@63494
   947
    fix z
wenzelm@63494
   948
    assume "z \<le> x"
hoelzl@51471
   949
    with x have "P z" by auto
hoelzl@51471
   950
    have "eventually (\<lambda>x. x \<le> g z) (at_right a)"
wenzelm@60758
   951
      using bound[OF bij(2)[OF \<open>P z\<close>]]
wenzelm@63494
   952
      unfolding eventually_at_right[OF bound[OF bij(2)[OF \<open>P z\<close>]]]
wenzelm@63494
   953
      by (auto intro!: exI[of _ "g z"])
hoelzl@51471
   954
    with Q show "eventually (\<lambda>x. f x \<le> z) (at_right a)"
wenzelm@60758
   955
      by eventually_elim (metis bij \<open>P z\<close> mono)
hoelzl@51471
   956
  qed
hoelzl@51471
   957
qed
hoelzl@51471
   958
hoelzl@51471
   959
lemma filterlim_at_top_at_left:
hoelzl@57275
   960
  fixes f :: "'a::linorder_topology \<Rightarrow> 'b::linorder"
hoelzl@51471
   961
  assumes mono: "\<And>x y. Q x \<Longrightarrow> Q y \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y"
wenzelm@63494
   962
    and bij: "\<And>x. P x \<Longrightarrow> f (g x) = x" "\<And>x. P x \<Longrightarrow> Q (g x)"
wenzelm@63494
   963
    and Q: "eventually Q (at_left a)"
wenzelm@63494
   964
    and bound: "\<And>b. Q b \<Longrightarrow> b < a"
wenzelm@63494
   965
    and P: "eventually P at_top"
hoelzl@51471
   966
  shows "filterlim f at_top (at_left a)"
hoelzl@51471
   967
proof -
hoelzl@51471
   968
  from P obtain x where x: "\<And>y. x \<le> y \<Longrightarrow> P y"
hoelzl@51471
   969
    unfolding eventually_at_top_linorder by auto
hoelzl@51471
   970
  show ?thesis
hoelzl@51471
   971
  proof (intro filterlim_at_top_ge[THEN iffD2] allI impI)
wenzelm@63494
   972
    fix z
wenzelm@63494
   973
    assume "x \<le> z"
hoelzl@51471
   974
    with x have "P z" by auto
hoelzl@51471
   975
    have "eventually (\<lambda>x. g z \<le> x) (at_left a)"
wenzelm@60758
   976
      using bound[OF bij(2)[OF \<open>P z\<close>]]
wenzelm@63494
   977
      unfolding eventually_at_left[OF bound[OF bij(2)[OF \<open>P z\<close>]]]
wenzelm@63494
   978
      by (auto intro!: exI[of _ "g z"])
hoelzl@51471
   979
    with Q show "eventually (\<lambda>x. z \<le> f x) (at_left a)"
wenzelm@60758
   980
      by eventually_elim (metis bij \<open>P z\<close> mono)
hoelzl@51471
   981
  qed
hoelzl@51471
   982
qed
hoelzl@51471
   983
hoelzl@51471
   984
lemma filterlim_split_at:
wenzelm@63494
   985
  "filterlim f F (at_left x) \<Longrightarrow> filterlim f F (at_right x) \<Longrightarrow>
wenzelm@63494
   986
    filterlim f F (at x)"
wenzelm@63494
   987
  for x :: "'a::linorder_topology"
hoelzl@51471
   988
  by (subst at_eq_sup_left_right) (rule filterlim_sup)
hoelzl@51471
   989
hoelzl@51471
   990
lemma filterlim_at_split:
wenzelm@63494
   991
  "filterlim f F (at x) \<longleftrightarrow> filterlim f F (at_left x) \<and> filterlim f F (at_right x)"
wenzelm@63494
   992
  for x :: "'a::linorder_topology"
hoelzl@51471
   993
  by (subst at_eq_sup_left_right) (simp add: filterlim_def filtermap_sup)
hoelzl@51471
   994
hoelzl@57025
   995
lemma eventually_nhds_top:
wenzelm@63494
   996
  fixes P :: "'a :: {order_top,linorder_topology} \<Rightarrow> bool"
wenzelm@63494
   997
    and b :: 'a
wenzelm@63494
   998
  assumes "b < top"
hoelzl@57025
   999
  shows "eventually P (nhds top) \<longleftrightarrow> (\<exists>b<top. (\<forall>z. b < z \<longrightarrow> P z))"
hoelzl@57025
  1000
  unfolding eventually_nhds
hoelzl@57025
  1001
proof safe
wenzelm@63494
  1002
  fix S :: "'a set"
wenzelm@63494
  1003
  assume "open S" "top \<in> S"
wenzelm@60758
  1004
  note open_left[OF this \<open>b < top\<close>]
hoelzl@57025
  1005
  moreover assume "\<forall>s\<in>S. P s"
hoelzl@57025
  1006
  ultimately show "\<exists>b<top. \<forall>z>b. P z"
hoelzl@57025
  1007
    by (auto simp: subset_eq Ball_def)
hoelzl@57025
  1008
next
wenzelm@63494
  1009
  fix b
wenzelm@63494
  1010
  assume "b < top" "\<forall>z>b. P z"
hoelzl@57025
  1011
  then show "\<exists>S. open S \<and> top \<in> S \<and> (\<forall>xa\<in>S. P xa)"
hoelzl@57025
  1012
    by (intro exI[of _ "{b <..}"]) auto
hoelzl@57025
  1013
qed
hoelzl@51471
  1014
hoelzl@57447
  1015
lemma tendsto_at_within_iff_tendsto_nhds:
wenzelm@61973
  1016
  "(g \<longlongrightarrow> g l) (at l within S) \<longleftrightarrow> (g \<longlongrightarrow> g l) (inf (nhds l) (principal S))"
hoelzl@57447
  1017
  unfolding tendsto_def eventually_at_filter eventually_inf_principal
lp15@61810
  1018
  by (intro ext all_cong imp_cong) (auto elim!: eventually_mono)
hoelzl@57447
  1019
wenzelm@63494
  1020
wenzelm@60758
  1021
subsection \<open>Limits on sequences\<close>
hoelzl@51471
  1022
hoelzl@51471
  1023
abbreviation (in topological_space)
wenzelm@63494
  1024
  LIMSEQ :: "[nat \<Rightarrow> 'a, 'a] \<Rightarrow> bool"  ("((_)/ \<longlonglongrightarrow> (_))" [60, 60] 60)
wenzelm@63494
  1025
  where "X \<longlonglongrightarrow> L \<equiv> (X \<longlongrightarrow> L) sequentially"
wenzelm@63494
  1026
wenzelm@63494
  1027
abbreviation (in t2_space) lim :: "(nat \<Rightarrow> 'a) \<Rightarrow> 'a"
wenzelm@63494
  1028
  where "lim X \<equiv> Lim sequentially X"
wenzelm@63494
  1029
wenzelm@63494
  1030
definition (in topological_space) convergent :: "(nat \<Rightarrow> 'a) \<Rightarrow> bool"
wenzelm@63494
  1031
  where "convergent X = (\<exists>L. X \<longlonglongrightarrow> L)"
hoelzl@51471
  1032
wenzelm@61969
  1033
lemma lim_def: "lim X = (THE L. X \<longlonglongrightarrow> L)"
hoelzl@51478
  1034
  unfolding Lim_def ..
hoelzl@51478
  1035
wenzelm@63494
  1036
wenzelm@60758
  1037
subsubsection \<open>Monotone sequences and subsequences\<close>
hoelzl@51471
  1038
wenzelm@63494
  1039
text \<open>
wenzelm@63494
  1040
  Definition of monotonicity.
wenzelm@63494
  1041
  The use of disjunction here complicates proofs considerably.
wenzelm@63494
  1042
  One alternative is to add a Boolean argument to indicate the direction.
wenzelm@63494
  1043
  Another is to develop the notions of increasing and decreasing first.
wenzelm@63494
  1044
\<close>
wenzelm@63494
  1045
definition monoseq :: "(nat \<Rightarrow> 'a::order) \<Rightarrow> bool"
wenzelm@63494
  1046
  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
  1047
wenzelm@63494
  1048
abbreviation incseq :: "(nat \<Rightarrow> 'a::order) \<Rightarrow> bool"
wenzelm@63494
  1049
  where "incseq X \<equiv> mono X"
hoelzl@56020
  1050
hoelzl@56020
  1051
lemma incseq_def: "incseq X \<longleftrightarrow> (\<forall>m. \<forall>n\<ge>m. X n \<ge> X m)"
hoelzl@56020
  1052
  unfolding mono_def ..
hoelzl@56020
  1053
wenzelm@63494
  1054
abbreviation decseq :: "(nat \<Rightarrow> 'a::order) \<Rightarrow> bool"
wenzelm@63494
  1055
  where "decseq X \<equiv> antimono X"
hoelzl@56020
  1056
hoelzl@56020
  1057
lemma decseq_def: "decseq X \<longleftrightarrow> (\<forall>m. \<forall>n\<ge>m. X n \<le> X m)"
hoelzl@56020
  1058
  unfolding antimono_def ..
hoelzl@51471
  1059
wenzelm@63494
  1060
text \<open>Definition of subsequence.\<close>
wenzelm@63494
  1061
definition subseq :: "(nat \<Rightarrow> nat) \<Rightarrow> bool"
wenzelm@63494
  1062
  where "subseq f \<longleftrightarrow> (\<forall>m. \<forall>n>m. f m < f n)"
wenzelm@63494
  1063
lp15@65036
  1064
lemma subseq_le_mono: "subseq r \<Longrightarrow> m \<le> n \<Longrightarrow> r m \<le> r n"
lp15@65036
  1065
  by (simp add: less_mono_imp_le_mono subseq_def)
lp15@65036
  1066
lp15@65036
  1067
lemma subseq_id: "subseq id"
lp15@65036
  1068
  by (simp add: subseq_def)
lp15@65036
  1069
wenzelm@63494
  1070
lemma incseq_SucI: "(\<And>n. X n \<le> X (Suc n)) \<Longrightarrow> incseq X"
wenzelm@63494
  1071
  using lift_Suc_mono_le[of X] by (auto simp: incseq_def)
wenzelm@63494
  1072
wenzelm@63494
  1073
lemma incseqD: "incseq f \<Longrightarrow> i \<le> j \<Longrightarrow> f i \<le> f j"
hoelzl@51471
  1074
  by (auto simp: incseq_def)
hoelzl@51471
  1075
hoelzl@51471
  1076
lemma incseq_SucD: "incseq A \<Longrightarrow> A i \<le> A (Suc i)"
hoelzl@51471
  1077
  using incseqD[of A i "Suc i"] by auto
hoelzl@51471
  1078
hoelzl@51471
  1079
lemma incseq_Suc_iff: "incseq f \<longleftrightarrow> (\<forall>n. f n \<le> f (Suc n))"
hoelzl@51471
  1080
  by (auto intro: incseq_SucI dest: incseq_SucD)
hoelzl@51471
  1081
hoelzl@51471
  1082
lemma incseq_const[simp, intro]: "incseq (\<lambda>x. k)"
hoelzl@51471
  1083
  unfolding incseq_def by auto
hoelzl@51471
  1084
wenzelm@63494
  1085
lemma decseq_SucI: "(\<And>n. X (Suc n) \<le> X n) \<Longrightarrow> decseq X"
wenzelm@63494
  1086
  using order.lift_Suc_mono_le[OF dual_order, of X] by (auto simp: decseq_def)
wenzelm@63494
  1087
wenzelm@63494
  1088
lemma decseqD: "decseq f \<Longrightarrow> i \<le> j \<Longrightarrow> f j \<le> f i"
hoelzl@51471
  1089
  by (auto simp: decseq_def)
hoelzl@51471
  1090
hoelzl@51471
  1091
lemma decseq_SucD: "decseq A \<Longrightarrow> A (Suc i) \<le> A i"
hoelzl@51471
  1092
  using decseqD[of A i "Suc i"] by auto
hoelzl@51471
  1093
hoelzl@51471
  1094
lemma decseq_Suc_iff: "decseq f \<longleftrightarrow> (\<forall>n. f (Suc n) \<le> f n)"
hoelzl@51471
  1095
  by (auto intro: decseq_SucI dest: decseq_SucD)
hoelzl@51471
  1096
hoelzl@51471
  1097
lemma decseq_const[simp, intro]: "decseq (\<lambda>x. k)"
hoelzl@51471
  1098
  unfolding decseq_def by auto
hoelzl@51471
  1099
hoelzl@51471
  1100
lemma monoseq_iff: "monoseq X \<longleftrightarrow> incseq X \<or> decseq X"
hoelzl@51471
  1101
  unfolding monoseq_def incseq_def decseq_def ..
hoelzl@51471
  1102
wenzelm@63494
  1103
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
  1104
  unfolding monoseq_iff incseq_Suc_iff decseq_Suc_iff ..
hoelzl@51471
  1105
wenzelm@63494
  1106
lemma monoI1: "\<forall>m. \<forall>n \<ge> m. X m \<le> X n \<Longrightarrow> monoseq X"
wenzelm@63494
  1107
  by (simp add: monoseq_def)
wenzelm@63494
  1108
wenzelm@63494
  1109
lemma monoI2: "\<forall>m. \<forall>n \<ge> m. X n \<le> X m \<Longrightarrow> monoseq X"
wenzelm@63494
  1110
  by (simp add: monoseq_def)
wenzelm@63494
  1111
wenzelm@63494
  1112
lemma mono_SucI1: "\<forall>n. X n \<le> X (Suc n) \<Longrightarrow> monoseq X"
wenzelm@63494
  1113
  by (simp add: monoseq_Suc)
wenzelm@63494
  1114
wenzelm@63494
  1115
lemma mono_SucI2: "\<forall>n. X (Suc n) \<le> X n \<Longrightarrow> monoseq X"
wenzelm@63494
  1116
  by (simp add: monoseq_Suc)
hoelzl@51471
  1117
hoelzl@51471
  1118
lemma monoseq_minus:
hoelzl@51471
  1119
  fixes a :: "nat \<Rightarrow> 'a::ordered_ab_group_add"
hoelzl@51471
  1120
  assumes "monoseq a"
hoelzl@51471
  1121
  shows "monoseq (\<lambda> n. - a n)"
wenzelm@63494
  1122
proof (cases "\<forall>m. \<forall>n \<ge> m. a m \<le> a n")
hoelzl@51471
  1123
  case True
wenzelm@63494
  1124
  then have "\<forall>m. \<forall>n \<ge> m. - a n \<le> - a m" by auto
wenzelm@63494
  1125
  then show ?thesis by (rule monoI2)
hoelzl@51471
  1126
next
hoelzl@51471
  1127
  case False
wenzelm@63494
  1128
  then have "\<forall>m. \<forall>n \<ge> m. - a m \<le> - a n"
wenzelm@63494
  1129
    using \<open>monoseq a\<close>[unfolded monoseq_def] by auto
wenzelm@63494
  1130
  then show ?thesis by (rule monoI1)
hoelzl@51471
  1131
qed
hoelzl@51471
  1132
wenzelm@63494
  1133
wenzelm@63494
  1134
text \<open>Subsequence (alternative definition, (e.g. Hoskins)\<close>
wenzelm@63494
  1135
wenzelm@63494
  1136
lemma subseq_Suc_iff: "subseq f \<longleftrightarrow> (\<forall>n. f n < f (Suc n))"
wenzelm@63494
  1137
  apply (simp add: subseq_def)
wenzelm@63494
  1138
  apply (auto dest!: less_imp_Suc_add)
wenzelm@63494
  1139
  apply (induct_tac k)
wenzelm@63494
  1140
   apply (auto intro: less_trans)
wenzelm@63494
  1141
  done
hoelzl@51471
  1142
eberlm@63317
  1143
lemma subseq_add: "subseq (\<lambda>n. n + k)"
eberlm@63317
  1144
  by (auto simp: subseq_Suc_iff)
eberlm@63317
  1145
wenzelm@63494
  1146
text \<open>For any sequence, there is a monotonic subsequence.\<close>
hoelzl@51471
  1147
lemma seq_monosub:
wenzelm@63494
  1148
  fixes s :: "nat \<Rightarrow> 'a::linorder"
hoelzl@57448
  1149
  shows "\<exists>f. subseq f \<and> monoseq (\<lambda>n. (s (f n)))"
wenzelm@63494
  1150
proof (cases "\<forall>n. \<exists>p>n. \<forall>m\<ge>p. s m \<le> s p")
wenzelm@63494
  1151
  case True
hoelzl@57448
  1152
  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
  1153
    by (intro dependent_nat_choice) (auto simp: conj_commute)
wenzelm@63494
  1154
  then obtain f where f: "subseq f" and mono: "\<And>n m. f n \<le> m \<Longrightarrow> s m \<le> s (f n)"
hoelzl@57448
  1155
    by (auto simp: subseq_Suc_iff)
hoelzl@57448
  1156
  then have "incseq f"
hoelzl@57448
  1157
    unfolding subseq_Suc_iff incseq_Suc_iff by (auto intro: less_imp_le)
hoelzl@57448
  1158
  then have "monoseq (\<lambda>n. s (f n))"
hoelzl@57448
  1159
    by (auto simp add: incseq_def intro!: mono monoI2)
wenzelm@63494
  1160
  with f show ?thesis
hoelzl@57448
  1161
    by auto
hoelzl@51471
  1162
next
wenzelm@63494
  1163
  case False
wenzelm@63494
  1164
  then obtain N where N: "p > N \<Longrightarrow> \<exists>m>p. s p < s m" for p
wenzelm@63494
  1165
    by (force simp: not_le le_less)
hoelzl@57448
  1166
  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
  1167
  proof (intro dependent_nat_choice)
wenzelm@63494
  1168
    fix x
wenzelm@63494
  1169
    assume "N < x" with N[of x]
wenzelm@63494
  1170
    show "\<exists>y>N. x < y \<and> s x \<le> s y"
hoelzl@57448
  1171
      by (auto intro: less_trans)
hoelzl@57448
  1172
  qed auto
hoelzl@57448
  1173
  then show ?thesis
hoelzl@57448
  1174
    by (auto simp: monoseq_iff incseq_Suc_iff subseq_Suc_iff)
hoelzl@51471
  1175
qed
hoelzl@51471
  1176
wenzelm@63494
  1177
lemma seq_suble:
wenzelm@63494
  1178
  assumes sf: "subseq f"
wenzelm@63494
  1179
  shows "n \<le> f n"
wenzelm@63494
  1180
proof (induct n)
wenzelm@63494
  1181
  case 0
wenzelm@63494
  1182
  show ?case by simp
hoelzl@51471
  1183
next
hoelzl@51471
  1184
  case (Suc n)
wenzelm@63494
  1185
  with sf [unfolded subseq_Suc_iff, rule_format, of n] have "n < f (Suc n)"
wenzelm@63494
  1186
     by arith
wenzelm@63494
  1187
  then show ?case by arith
hoelzl@51471
  1188
qed
hoelzl@51471
  1189
hoelzl@51471
  1190
lemma eventually_subseq:
hoelzl@51471
  1191
  "subseq r \<Longrightarrow> eventually P sequentially \<Longrightarrow> eventually (\<lambda>n. P (r n)) sequentially"
hoelzl@51471
  1192
  unfolding eventually_sequentially by (metis seq_suble le_trans)
hoelzl@51471
  1193
hoelzl@51473
  1194
lemma not_eventually_sequentiallyD:
wenzelm@63494
  1195
  assumes "\<not> eventually P sequentially"
hoelzl@51473
  1196
  shows "\<exists>r. subseq r \<and> (\<forall>n. \<not> P (r n))"
hoelzl@51473
  1197
proof -
wenzelm@63494
  1198
  from assms have "\<forall>n. \<exists>m\<ge>n. \<not> P m"
hoelzl@51473
  1199
    unfolding eventually_sequentially by (simp add: not_less)
hoelzl@51473
  1200
  then obtain r where "\<And>n. r n \<ge> n" "\<And>n. \<not> P (r n)"
hoelzl@51473
  1201
    by (auto simp: choice_iff)
hoelzl@51473
  1202
  then show ?thesis
hoelzl@51473
  1203
    by (auto intro!: exI[of _ "\<lambda>n. r (((Suc \<circ> r) ^^ Suc n) 0)"]
hoelzl@51473
  1204
             simp: less_eq_Suc_le subseq_Suc_iff)
hoelzl@51473
  1205
qed
hoelzl@51473
  1206
hoelzl@51471
  1207
lemma filterlim_subseq: "subseq f \<Longrightarrow> filterlim f sequentially sequentially"
hoelzl@51471
  1208
  unfolding filterlim_iff by (metis eventually_subseq)
hoelzl@51471
  1209
hoelzl@51471
  1210
lemma subseq_o: "subseq r \<Longrightarrow> subseq s \<Longrightarrow> subseq (r \<circ> s)"
hoelzl@51471
  1211
  unfolding subseq_def by simp
hoelzl@51471
  1212
wenzelm@63494
  1213
lemma subseq_mono: "subseq r \<Longrightarrow> m < n \<Longrightarrow> r m < r n"
wenzelm@63494
  1214
  by (auto simp: subseq_def)
hoelzl@51471
  1215
eberlm@61531
  1216
lemma subseq_imp_inj_on: "subseq g \<Longrightarrow> inj_on g A"
eberlm@61531
  1217
proof (rule inj_onI)
eberlm@61531
  1218
  assume g: "subseq g"
wenzelm@63494
  1219
  fix x y
wenzelm@63494
  1220
  assume "g x = g y"
hoelzl@62102
  1221
  with subseq_mono[OF g, of x y] subseq_mono[OF g, of y x] show "x = y"
eberlm@61531
  1222
    by (cases x y rule: linorder_cases) simp_all
eberlm@61531
  1223
qed
eberlm@61531
  1224
eberlm@61531
  1225
lemma subseq_strict_mono: "subseq g \<Longrightarrow> strict_mono g"
eberlm@61531
  1226
  by (intro strict_monoI subseq_mono[of g])
eberlm@61531
  1227
hoelzl@51471
  1228
lemma incseq_imp_monoseq:  "incseq X \<Longrightarrow> monoseq X"
hoelzl@51471
  1229
  by (simp add: incseq_def monoseq_def)
hoelzl@51471
  1230
hoelzl@51471
  1231
lemma decseq_imp_monoseq:  "decseq X \<Longrightarrow> monoseq X"
hoelzl@51471
  1232
  by (simp add: decseq_def monoseq_def)
hoelzl@51471
  1233
wenzelm@63494
  1234
lemma decseq_eq_incseq: "decseq X = incseq (\<lambda>n. - X n)"
wenzelm@63494
  1235
  for X :: "nat \<Rightarrow> 'a::ordered_ab_group_add"
hoelzl@51471
  1236
  by (simp add: decseq_def incseq_def)
hoelzl@51471
  1237
hoelzl@51471
  1238
lemma INT_decseq_offset:
hoelzl@51471
  1239
  assumes "decseq F"
hoelzl@51471
  1240
  shows "(\<Inter>i. F i) = (\<Inter>i\<in>{n..}. F i)"
hoelzl@51471
  1241
proof safe
wenzelm@63494
  1242
  fix x i
wenzelm@63494
  1243
  assume x: "x \<in> (\<Inter>i\<in>{n..}. F i)"
hoelzl@51471
  1244
  show "x \<in> F i"
hoelzl@51471
  1245
  proof cases
hoelzl@51471
  1246
    from x have "x \<in> F n" by auto
wenzelm@60758
  1247
    also assume "i \<le> n" with \<open>decseq F\<close> have "F n \<subseteq> F i"
hoelzl@51471
  1248
      unfolding decseq_def by simp
hoelzl@51471
  1249
    finally show ?thesis .
hoelzl@51471
  1250
  qed (insert x, simp)
hoelzl@51471
  1251
qed auto
hoelzl@51471
  1252
wenzelm@63494
  1253
lemma LIMSEQ_const_iff: "(\<lambda>n. k) \<longlonglongrightarrow> l \<longleftrightarrow> k = l"
wenzelm@63494
  1254
  for k l :: "'a::t2_space"
hoelzl@51471
  1255
  using trivial_limit_sequentially by (rule tendsto_const_iff)
hoelzl@51471
  1256
wenzelm@63494
  1257
lemma LIMSEQ_SUP: "incseq X \<Longrightarrow> X \<longlonglongrightarrow> (SUP i. X i :: 'a::{complete_linorder,linorder_topology})"
hoelzl@51471
  1258
  by (intro increasing_tendsto)
wenzelm@63494
  1259
    (auto simp: SUP_upper less_SUP_iff incseq_def eventually_sequentially intro: less_le_trans)
wenzelm@63494
  1260
wenzelm@63494
  1261
lemma LIMSEQ_INF: "decseq X \<Longrightarrow> X \<longlonglongrightarrow> (INF i. X i :: 'a::{complete_linorder,linorder_topology})"
hoelzl@51471
  1262
  by (intro decreasing_tendsto)
wenzelm@63494
  1263
    (auto simp: INF_lower INF_less_iff decseq_def eventually_sequentially intro: le_less_trans)
wenzelm@63494
  1264
wenzelm@63494
  1265
lemma LIMSEQ_ignore_initial_segment: "f \<longlonglongrightarrow> a \<Longrightarrow> (\<lambda>n. f (n + k)) \<longlonglongrightarrow> a"
wenzelm@63494
  1266
  unfolding tendsto_def by (subst eventually_sequentially_seg[where k=k])
wenzelm@63494
  1267
wenzelm@63494
  1268
lemma LIMSEQ_offset: "(\<lambda>n. f (n + k)) \<longlonglongrightarrow> a \<Longrightarrow> f \<longlonglongrightarrow> a"
hoelzl@51474
  1269
  unfolding tendsto_def
hoelzl@51474
  1270
  by (subst (asm) eventually_sequentially_seg[where k=k])
hoelzl@51471
  1271
wenzelm@61969
  1272
lemma LIMSEQ_Suc: "f \<longlonglongrightarrow> l \<Longrightarrow> (\<lambda>n. f (Suc n)) \<longlonglongrightarrow> l"
wenzelm@63494
  1273
  by (drule LIMSEQ_ignore_initial_segment [where k="Suc 0"]) simp
hoelzl@51471
  1274
wenzelm@61969
  1275
lemma LIMSEQ_imp_Suc: "(\<lambda>n. f (Suc n)) \<longlonglongrightarrow> l \<Longrightarrow> f \<longlonglongrightarrow> l"
wenzelm@63494
  1276
  by (rule LIMSEQ_offset [where k="Suc 0"]) simp
hoelzl@51471
  1277
wenzelm@61969
  1278
lemma LIMSEQ_Suc_iff: "(\<lambda>n. f (Suc n)) \<longlonglongrightarrow> l = f \<longlonglongrightarrow> l"
wenzelm@63494
  1279
  by (blast intro: LIMSEQ_imp_Suc LIMSEQ_Suc)
wenzelm@63494
  1280
wenzelm@63494
  1281
lemma LIMSEQ_unique: "X \<longlonglongrightarrow> a \<Longrightarrow> X \<longlonglongrightarrow> b \<Longrightarrow> a = b"
wenzelm@63494
  1282
  for a b :: "'a::t2_space"
hoelzl@51471
  1283
  using trivial_limit_sequentially by (rule tendsto_unique)
hoelzl@51471
  1284
wenzelm@63494
  1285
lemma LIMSEQ_le_const: "X \<longlonglongrightarrow> x \<Longrightarrow> \<exists>N. \<forall>n\<ge>N. a \<le> X n \<Longrightarrow> a \<le> x"
wenzelm@63494
  1286
  for a x :: "'a::linorder_topology"
lp15@63952
  1287
  by (simp add: eventually_at_top_linorder tendsto_lowerbound)
hoelzl@51471
  1288
wenzelm@63494
  1289
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
  1290
  for x y :: "'a::linorder_topology"
hoelzl@51471
  1291
  using tendsto_le[of sequentially Y y X x] by (simp add: eventually_sequentially)
hoelzl@51471
  1292
wenzelm@63494
  1293
lemma LIMSEQ_le_const2: "X \<longlonglongrightarrow> x \<Longrightarrow> \<exists>N. \<forall>n\<ge>N. X n \<le> a \<Longrightarrow> x \<le> a"
wenzelm@63494
  1294
  for a x :: "'a::linorder_topology"
hoelzl@58729
  1295
  by (rule LIMSEQ_le[of X x "\<lambda>n. a"]) auto
hoelzl@51471
  1296
wenzelm@63494
  1297
lemma convergentD: "convergent X \<Longrightarrow> \<exists>L. X \<longlonglongrightarrow> L"
wenzelm@63494
  1298
  by (simp add: convergent_def)
wenzelm@63494
  1299
wenzelm@63494
  1300
lemma convergentI: "X \<longlonglongrightarrow> L \<Longrightarrow> convergent X"
wenzelm@63494
  1301
  by (auto simp add: convergent_def)
wenzelm@63494
  1302
wenzelm@63494
  1303
lemma convergent_LIMSEQ_iff: "convergent X \<longleftrightarrow> X \<longlonglongrightarrow> lim X"
wenzelm@63494
  1304
  by (auto intro: theI LIMSEQ_unique simp add: convergent_def lim_def)
hoelzl@51471
  1305
hoelzl@51471
  1306
lemma convergent_const: "convergent (\<lambda>n. c)"
wenzelm@63494
  1307
  by (rule convergentI) (rule tendsto_const)
hoelzl@51471
  1308
hoelzl@51471
  1309
lemma monoseq_le:
wenzelm@63494
  1310
  "monoseq a \<Longrightarrow> a \<longlonglongrightarrow> x \<Longrightarrow>
wenzelm@63494
  1311
    (\<forall>n. a n \<le> x) \<and> (\<forall>m. \<forall>n\<ge>m. a m \<le> a n) \<or>
wenzelm@63494
  1312
    (\<forall>n. x \<le> a n) \<and> (\<forall>m. \<forall>n\<ge>m. a n \<le> a m)"
wenzelm@63494
  1313
  for x :: "'a::linorder_topology"
hoelzl@51471
  1314
  by (metis LIMSEQ_le_const LIMSEQ_le_const2 decseq_def incseq_def monoseq_iff)
hoelzl@51471
  1315
wenzelm@63494
  1316
lemma LIMSEQ_subseq_LIMSEQ: "X \<longlonglongrightarrow> L \<Longrightarrow> subseq f \<Longrightarrow> (X \<circ> f) \<longlonglongrightarrow> L"
wenzelm@63494
  1317
  unfolding comp_def by (rule filterlim_compose [of X, OF _ filterlim_subseq])
wenzelm@63494
  1318
wenzelm@63494
  1319
lemma convergent_subseq_convergent: "convergent X \<Longrightarrow> subseq f \<Longrightarrow> convergent (X \<circ> f)"
wenzelm@63494
  1320
  by (auto simp: convergent_def intro: LIMSEQ_subseq_LIMSEQ)
wenzelm@63494
  1321
wenzelm@63494
  1322
lemma limI: "X \<longlonglongrightarrow> L \<Longrightarrow> lim X = L"
hoelzl@57276
  1323
  by (rule tendsto_Lim) (rule trivial_limit_sequentially)
hoelzl@51471
  1324
wenzelm@63494
  1325
lemma lim_le: "convergent f \<Longrightarrow> (\<And>n. f n \<le> x) \<Longrightarrow> lim f \<le> x"
wenzelm@63494
  1326
  for x :: "'a::linorder_topology"
hoelzl@51471
  1327
  using LIMSEQ_le_const2[of f "lim f" x] by (simp add: convergent_LIMSEQ_iff)
hoelzl@51471
  1328
lp15@62217
  1329
lemma lim_const [simp]: "lim (\<lambda>m. a) = a"
lp15@62217
  1330
  by (simp add: limI)
lp15@62217
  1331
wenzelm@63494
  1332
wenzelm@63494
  1333
subsubsection \<open>Increasing and Decreasing Series\<close>
wenzelm@63494
  1334
wenzelm@63494
  1335
lemma incseq_le: "incseq X \<Longrightarrow> X \<longlonglongrightarrow> L \<Longrightarrow> X n \<le> L"
wenzelm@63494
  1336
  for L :: "'a::linorder_topology"
hoelzl@51471
  1337
  by (metis incseq_def LIMSEQ_le_const)
hoelzl@51471
  1338
wenzelm@63494
  1339
lemma decseq_le: "decseq X \<Longrightarrow> X \<longlonglongrightarrow> L \<Longrightarrow> L \<le> X n"
wenzelm@63494
  1340
  for L :: "'a::linorder_topology"
hoelzl@51471
  1341
  by (metis decseq_def LIMSEQ_le_const2)
hoelzl@51471
  1342
wenzelm@63494
  1343
wenzelm@60758
  1344
subsection \<open>First countable topologies\<close>
hoelzl@51473
  1345
hoelzl@51473
  1346
class first_countable_topology = topological_space +
hoelzl@51473
  1347
  assumes first_countable_basis:
hoelzl@51473
  1348
    "\<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
  1349
hoelzl@51473
  1350
lemma (in first_countable_topology) countable_basis_at_decseq:
hoelzl@51473
  1351
  obtains A :: "nat \<Rightarrow> 'a set" where
hoelzl@51473
  1352
    "\<And>i. open (A i)" "\<And>i. x \<in> (A i)"
hoelzl@51473
  1353
    "\<And>S. open S \<Longrightarrow> x \<in> S \<Longrightarrow> eventually (\<lambda>i. A i \<subseteq> S) sequentially"
hoelzl@51473
  1354
proof atomize_elim
wenzelm@63494
  1355
  from first_countable_basis[of x] obtain A :: "nat \<Rightarrow> 'a set"
wenzelm@63494
  1356
    where nhds: "\<And>i. open (A i)" "\<And>i. x \<in> A i"
wenzelm@63494
  1357
      and incl: "\<And>S. open S \<Longrightarrow> x \<in> S \<Longrightarrow> \<exists>i. A i \<subseteq> S"
wenzelm@63494
  1358
    by auto
wenzelm@63040
  1359
  define F where "F n = (\<Inter>i\<le>n. A i)" for n
hoelzl@51473
  1360
  show "\<exists>A. (\<forall>i. open (A i)) \<and> (\<forall>i. x \<in> A i) \<and>
wenzelm@63494
  1361
    (\<forall>S. open S \<longrightarrow> x \<in> S \<longrightarrow> eventually (\<lambda>i. A i \<subseteq> S) sequentially)"
hoelzl@51473
  1362
  proof (safe intro!: exI[of _ F])
hoelzl@51473
  1363
    fix i
wenzelm@63494
  1364
    show "open (F i)"
wenzelm@63494
  1365
      using nhds(1) by (auto simp: F_def)
wenzelm@63494
  1366
    show "x \<in> F i"
wenzelm@63494
  1367
      using nhds(2) by (auto simp: F_def)
hoelzl@51473
  1368
  next
wenzelm@63494
  1369
    fix S
wenzelm@63494
  1370
    assume "open S" "x \<in> S"
wenzelm@63494
  1371
    from incl[OF this] obtain i where "F i \<subseteq> S"
wenzelm@63494
  1372
      unfolding F_def by auto
hoelzl@51473
  1373
    moreover have "\<And>j. i \<le> j \<Longrightarrow> F j \<subseteq> F i"
wenzelm@63171
  1374
      by (simp add: Inf_superset_mono F_def image_mono)
hoelzl@51473
  1375
    ultimately show "eventually (\<lambda>i. F i \<subseteq> S) sequentially"
hoelzl@51473
  1376
      by (auto simp: eventually_sequentially)
hoelzl@51473
  1377
  qed
hoelzl@51473
  1378
qed
hoelzl@51473
  1379
hoelzl@57448
  1380
lemma (in first_countable_topology) nhds_countable:
hoelzl@57448
  1381
  obtains X :: "nat \<Rightarrow> 'a set"
hoelzl@57448
  1382
  where "decseq X" "\<And>n. open (X n)" "\<And>n. x \<in> X n" "nhds x = (INF n. principal (X n))"
hoelzl@57448
  1383
proof -
hoelzl@57448
  1384
  from first_countable_basis obtain A :: "nat \<Rightarrow> 'a set"
wenzelm@63494
  1385
    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
  1386
    by metis
hoelzl@57448
  1387
  show thesis
hoelzl@57448
  1388
  proof
hoelzl@57448
  1389
    show "decseq (\<lambda>n. \<Inter>i\<le>n. A i)"
wenzelm@63171
  1390
      by (simp add: antimono_iff_le_Suc atMost_Suc)
wenzelm@63494
  1391
    show "x \<in> (\<Inter>i\<le>n. A i)" "\<And>n. open (\<Inter>i\<le>n. A i)" for n
wenzelm@63494
  1392
      using * by auto
wenzelm@60585
  1393
    show "nhds x = (INF n. principal (\<Inter>i\<le>n. A i))"
wenzelm@63494
  1394
      using *
wenzelm@63494
  1395
      unfolding nhds_def
haftmann@62343
  1396
      apply -
haftmann@62343
  1397
      apply (rule INF_eq)
wenzelm@63494
  1398
       apply simp_all
wenzelm@63494
  1399
       apply fastforce
haftmann@62343
  1400
      apply (intro exI [of _ "\<Inter>i\<le>n. A i" for n] conjI open_INT)
wenzelm@63494
  1401
         apply auto
hoelzl@57448
  1402
      done
hoelzl@57448
  1403
  qed
hoelzl@57448
  1404
qed
hoelzl@57448
  1405
hoelzl@51473
  1406
lemma (in first_countable_topology) countable_basis:
hoelzl@51473
  1407
  obtains A :: "nat \<Rightarrow> 'a set" where
hoelzl@51473
  1408
    "\<And>i. open (A i)" "\<And>i. x \<in> A i"
wenzelm@61969
  1409
    "\<And>F. (\<forall>n. F n \<in> A n) \<Longrightarrow> F \<longlonglongrightarrow> x"
hoelzl@51473
  1410
proof atomize_elim
wenzelm@63494
  1411
  obtain A :: "nat \<Rightarrow> 'a set" where *:
wenzelm@53381
  1412
    "\<And>i. open (A i)"
wenzelm@53381
  1413
    "\<And>i. x \<in> A i"
wenzelm@53381
  1414
    "\<And>S. open S \<Longrightarrow> x \<in> S \<Longrightarrow> eventually (\<lambda>i. A i \<subseteq> S) sequentially"
wenzelm@53381
  1415
    by (rule countable_basis_at_decseq) blast
wenzelm@63494
  1416
  have "eventually (\<lambda>n. F n \<in> S) sequentially"
wenzelm@63494
  1417
    if "\<forall>n. F n \<in> A n" "open S" "x \<in> S" for F S
wenzelm@63494
  1418
    using *(3)[of S] that by (auto elim: eventually_mono simp: subset_eq)
wenzelm@63494
  1419
  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
  1420
    by (intro exI[of _ A]) (auto simp: tendsto_def)
hoelzl@51473
  1421
qed
hoelzl@51473
  1422
hoelzl@51473
  1423
lemma (in first_countable_topology) sequentially_imp_eventually_nhds_within:
wenzelm@61969
  1424
  assumes "\<forall>f. (\<forall>n. f n \<in> s) \<and> f \<longlonglongrightarrow> a \<longrightarrow> eventually (\<lambda>n. P (f n)) sequentially"
hoelzl@51641
  1425
  shows "eventually P (inf (nhds a) (principal s))"
hoelzl@51473
  1426
proof (rule ccontr)
wenzelm@63494
  1427
  obtain A :: "nat \<Rightarrow> 'a set" where *:
wenzelm@53381
  1428
    "\<And>i. open (A i)"
wenzelm@53381
  1429
    "\<And>i. a \<in> A i"
wenzelm@61969
  1430
    "\<And>F. \<forall>n. F n \<in> A n \<Longrightarrow> F \<longlonglongrightarrow> a"
wenzelm@53381
  1431
    by (rule countable_basis) blast
wenzelm@53381
  1432
  assume "\<not> ?thesis"
wenzelm@63494
  1433
  with * have "\<exists>F. \<forall>n. F n \<in> s \<and> F n \<in> A n \<and> \<not> P (F n)"
wenzelm@63494
  1434
    unfolding eventually_inf_principal eventually_nhds
wenzelm@63494
  1435
    by (intro choice) fastforce
wenzelm@63494
  1436
  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
  1437
    by blast
wenzelm@63494
  1438
  with * have "F \<longlonglongrightarrow> a"
wenzelm@63494
  1439
    by auto
wenzelm@63494
  1440
  then have "eventually (\<lambda>n. P (F n)) sequentially"
wenzelm@63494
  1441
    using assms F by simp
wenzelm@63494
  1442
  then show False
wenzelm@63494
  1443
    by (simp add: F')
hoelzl@51473
  1444
qed
hoelzl@51473
  1445
hoelzl@51473
  1446
lemma (in first_countable_topology) eventually_nhds_within_iff_sequentially:
hoelzl@62102
  1447
  "eventually P (inf (nhds a) (principal s)) \<longleftrightarrow>
wenzelm@61969
  1448
    (\<forall>f. (\<forall>n. f n \<in> s) \<and> f \<longlonglongrightarrow> a \<longrightarrow> eventually (\<lambda>n. P (f n)) sequentially)"
hoelzl@51473
  1449
proof (safe intro!: sequentially_imp_eventually_nhds_within)
hoelzl@62102
  1450
  assume "eventually P (inf (nhds a) (principal s))"
hoelzl@51473
  1451
  then obtain S where "open S" "a \<in> S" "\<forall>x\<in>S. x \<in> s \<longrightarrow> P x"
hoelzl@51641
  1452
    by (auto simp: eventually_inf_principal eventually_nhds)
wenzelm@63494
  1453
  moreover
wenzelm@63494
  1454
  fix f
wenzelm@63494
  1455
  assume "\<forall>n. f n \<in> s" "f \<longlonglongrightarrow> a"
hoelzl@51473
  1456
  ultimately show "eventually (\<lambda>n. P (f n)) sequentially"
lp15@61810
  1457
    by (auto dest!: topological_tendstoD elim: eventually_mono)
hoelzl@51473
  1458
qed
hoelzl@51473
  1459
hoelzl@51473
  1460
lemma (in first_countable_topology) eventually_nhds_iff_sequentially:
wenzelm@61969
  1461
  "eventually P (nhds a) \<longleftrightarrow> (\<forall>f. f \<longlonglongrightarrow> a \<longrightarrow> eventually (\<lambda>n. P (f n)) sequentially)"
hoelzl@51473
  1462
  using eventually_nhds_within_iff_sequentially[of P a UNIV] by simp
hoelzl@51473
  1463
hoelzl@57447
  1464
lemma tendsto_at_iff_sequentially:
wenzelm@63494
  1465
  "(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
  1466
  for f :: "'a::first_countable_topology \<Rightarrow> _"
wenzelm@63494
  1467
  unfolding filterlim_def[of _ "nhds a"] le_filter_def eventually_filtermap
wenzelm@63494
  1468
    at_within_def eventually_nhds_within_iff_sequentially comp_def
hoelzl@57447
  1469
  by metis
hoelzl@57447
  1470
hoelzl@64283
  1471
lemma approx_from_above_dense_linorder:
hoelzl@64283
  1472
  fixes x::"'a::{dense_linorder, linorder_topology, first_countable_topology}"
hoelzl@64283
  1473
  assumes "x < y"
hoelzl@64283
  1474
  shows "\<exists>u. (\<forall>n. u n > x) \<and> (u \<longlonglongrightarrow> x)"
hoelzl@64283
  1475
proof -
hoelzl@64283
  1476
  obtain A :: "nat \<Rightarrow> 'a set" where A: "\<And>i. open (A i)" "\<And>i. x \<in> A i"
hoelzl@64283
  1477
                                      "\<And>F. (\<forall>n. F n \<in> A n) \<Longrightarrow> F \<longlonglongrightarrow> x"
hoelzl@64283
  1478
    by (metis first_countable_topology_class.countable_basis)
hoelzl@64283
  1479
  define u where "u = (\<lambda>n. SOME z. z \<in> A n \<and> z > x)"
hoelzl@64283
  1480
  have "\<exists>z. z \<in> U \<and> x < z" if "x \<in> U" "open U" for U
hoelzl@64283
  1481
    using open_right[OF `open U` `x \<in> U` `x < y`]
hoelzl@64283
  1482
    by (meson atLeastLessThan_iff dense less_imp_le subset_eq)
hoelzl@64283
  1483
  then have *: "u n \<in> A n \<and> x < u n" for n
hoelzl@64283
  1484
    using `x \<in> A n` `open (A n)` unfolding u_def by (metis (no_types, lifting) someI_ex)
hoelzl@64283
  1485
  then have "u \<longlonglongrightarrow> x" using A(3) by simp
hoelzl@64283
  1486
  then show ?thesis using * by auto
hoelzl@64283
  1487
qed
hoelzl@64283
  1488
hoelzl@64283
  1489
lemma approx_from_below_dense_linorder:
hoelzl@64283
  1490
  fixes x::"'a::{dense_linorder, linorder_topology, first_countable_topology}"
hoelzl@64283
  1491
  assumes "x > y"
hoelzl@64283
  1492
  shows "\<exists>u. (\<forall>n. u n < x) \<and> (u \<longlonglongrightarrow> x)"
hoelzl@64283
  1493
proof -
hoelzl@64283
  1494
  obtain A :: "nat \<Rightarrow> 'a set" where A: "\<And>i. open (A i)" "\<And>i. x \<in> A i"
hoelzl@64283
  1495
                                      "\<And>F. (\<forall>n. F n \<in> A n) \<Longrightarrow> F \<longlonglongrightarrow> x"
hoelzl@64283
  1496
    by (metis first_countable_topology_class.countable_basis)
hoelzl@64283
  1497
  define u where "u = (\<lambda>n. SOME z. z \<in> A n \<and> z < x)"
hoelzl@64283
  1498
  have "\<exists>z. z \<in> U \<and> z < x" if "x \<in> U" "open U" for U
hoelzl@64283
  1499
    using open_left[OF `open U` `x \<in> U` `x > y`]
hoelzl@64283
  1500
    by (meson dense greaterThanAtMost_iff less_imp_le subset_eq)
hoelzl@64283
  1501
  then have *: "u n \<in> A n \<and> u n < x" for n
hoelzl@64283
  1502
    using `x \<in> A n` `open (A n)` unfolding u_def by (metis (no_types, lifting) someI_ex)
hoelzl@64283
  1503
  then have "u \<longlonglongrightarrow> x" using A(3) by simp
hoelzl@64283
  1504
  then show ?thesis using * by auto
hoelzl@64283
  1505
qed
hoelzl@64283
  1506
wenzelm@63494
  1507
wenzelm@60758
  1508
subsection \<open>Function limit at a point\<close>
hoelzl@51471
  1509
wenzelm@63494
  1510
abbreviation LIM :: "('a::topological_space \<Rightarrow> 'b::topological_space) \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> bool"
wenzelm@63494
  1511
    ("((_)/ \<midarrow>(_)/\<rightarrow> (_))" [60, 0, 60] 60)
wenzelm@63494
  1512
  where "f \<midarrow>a\<rightarrow> L \<equiv> (f \<longlongrightarrow> L) (at a)"
hoelzl@51471
  1513
wenzelm@61976
  1514
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
  1515
  by (simp add: tendsto_def at_within_open[where S = S])
hoelzl@51481
  1516
lp15@62397
  1517
lemma tendsto_within_open_NO_MATCH:
wenzelm@63494
  1518
  "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
  1519
  for f :: "'a::topological_space \<Rightarrow> 'b::topological_space"
wenzelm@63494
  1520
  using tendsto_within_open by blast
wenzelm@63494
  1521
wenzelm@63494
  1522
lemma LIM_const_not_eq[tendsto_intros]: "k \<noteq> L \<Longrightarrow> \<not> (\<lambda>x. k) \<midarrow>a\<rightarrow> L"
wenzelm@63494
  1523
  for a :: "'a::perfect_space" and k L :: "'b::t2_space"
hoelzl@51471
  1524
  by (simp add: tendsto_const_iff)
hoelzl@51471
  1525
hoelzl@51471
  1526
lemmas LIM_not_zero = LIM_const_not_eq [where L = 0]
hoelzl@51471
  1527
wenzelm@63494
  1528
lemma LIM_const_eq: "(\<lambda>x. k) \<midarrow>a\<rightarrow> L \<Longrightarrow> k = L"
wenzelm@63494
  1529
  for a :: "'a::perfect_space" and k L :: "'b::t2_space"
hoelzl@51471
  1530
  by (simp add: tendsto_const_iff)
hoelzl@51471
  1531
wenzelm@63494
  1532
lemma LIM_unique: "f \<midarrow>a\<rightarrow> L \<Longrightarrow> f \<midarrow>a\<rightarrow> M \<Longrightarrow> L = M"
wenzelm@63494
  1533
  for a :: "'a::perfect_space" and L M :: "'b::t2_space"
hoelzl@51471
  1534
  using at_neq_bot by (rule tendsto_unique)
hoelzl@51471
  1535
wenzelm@63494
  1536
wenzelm@63494
  1537
text \<open>Limits are equal for functions equal except at limit point.\<close>
wenzelm@63494
  1538
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
  1539
  by (simp add: tendsto_def eventually_at_topological)
hoelzl@51471
  1540
wenzelm@61976
  1541
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
  1542
  by (simp add: LIM_equal)
hoelzl@51471
  1543
wenzelm@61976
  1544
lemma LIM_cong_limit: "f \<midarrow>x\<rightarrow> L \<Longrightarrow> K = L \<Longrightarrow> f \<midarrow>x\<rightarrow> K"
hoelzl@51471
  1545
  by simp
hoelzl@51471
  1546
wenzelm@63494
  1547
lemma tendsto_at_iff_tendsto_nhds: "g \<midarrow>l\<rightarrow> g l \<longleftrightarrow> (g \<longlongrightarrow> g l) (nhds l)"
hoelzl@51641
  1548
  unfolding tendsto_def eventually_at_filter
lp15@61810
  1549
  by (intro ext all_cong imp_cong) (auto elim!: eventually_mono)
hoelzl@51471
  1550
wenzelm@63494
  1551
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
  1552
  unfolding tendsto_at_iff_tendsto_nhds by (rule filterlim_compose[of g])
hoelzl@51471
  1553
hoelzl@51471
  1554
lemma tendsto_compose_eventually:
wenzelm@61976
  1555
  "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
  1556
  by (rule filterlim_compose[of g _ "at l"]) (auto simp add: filterlim_at)
hoelzl@51471
  1557
hoelzl@51471
  1558
lemma LIM_compose_eventually:
wenzelm@63494
  1559
  assumes "f \<midarrow>a\<rightarrow> b"
wenzelm@63494
  1560
    and "g \<midarrow>b\<rightarrow> c"
wenzelm@63494
  1561
    and "eventually (\<lambda>x. f x \<noteq> b) (at a)"
wenzelm@61976
  1562
  shows "(\<lambda>x. g (f x)) \<midarrow>a\<rightarrow> c"
wenzelm@63494
  1563
  using assms(2,1,3) by (rule tendsto_compose_eventually)
hoelzl@51471
  1564
wenzelm@61973
  1565
lemma tendsto_compose_filtermap: "((g \<circ> f) \<longlongrightarrow> T) F \<longleftrightarrow> (g \<longlongrightarrow> T) (filtermap f F)"
hoelzl@57447
  1566
  by (simp add: filterlim_def filtermap_filtermap comp_def)
hoelzl@57447
  1567
lp15@64758
  1568
lemma tendsto_compose_at:
lp15@64758
  1569
  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
  1570
  shows "((g \<circ> f) \<longlongrightarrow> z) F"
lp15@64758
  1571
proof -
lp15@64758
  1572
  have "(\<forall>\<^sub>F a in F. f a \<noteq> y) \<or> g y = z"
lp15@64758
  1573
    using fg by force
lp15@64758
  1574
  moreover have "(g \<longlongrightarrow> z) (filtermap f F) \<or> \<not> (\<forall>\<^sub>F a in F. f a \<noteq> y)"
lp15@64758
  1575
    by (metis (no_types) filterlim_atI filterlim_def tendsto_mono f g)
lp15@64758
  1576
  ultimately show ?thesis
lp15@64758
  1577
    by (metis (no_types) f filterlim_compose filterlim_filtermap g tendsto_at_iff_tendsto_nhds tendsto_compose_filtermap)
lp15@64758
  1578
qed
lp15@64758
  1579
wenzelm@63494
  1580
wenzelm@63494
  1581
subsubsection \<open>Relation of \<open>LIM\<close> and \<open>LIMSEQ\<close>\<close>
hoelzl@51473
  1582
hoelzl@51473
  1583
lemma (in first_countable_topology) sequentially_imp_eventually_within:
wenzelm@61969
  1584
  "(\<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
  1585
    eventually P (at a within s)"
hoelzl@51641
  1586
  unfolding at_within_def
hoelzl@51473
  1587
  by (intro sequentially_imp_eventually_nhds_within) auto
hoelzl@51473
  1588
hoelzl@51473
  1589
lemma (in first_countable_topology) sequentially_imp_eventually_at:
wenzelm@61969
  1590
  "(\<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
  1591
  using sequentially_imp_eventually_within [where s=UNIV] by simp
hoelzl@51473
  1592
hoelzl@51473
  1593
lemma LIMSEQ_SEQ_conv1:
hoelzl@51473
  1594
  fixes f :: "'a::topological_space \<Rightarrow> 'b::topological_space"
wenzelm@61976
  1595
  assumes f: "f \<midarrow>a\<rightarrow> l"
wenzelm@61969
  1596
  shows "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S \<longlonglongrightarrow> a \<longrightarrow> (\<lambda>n. f (S n)) \<longlonglongrightarrow> l"
hoelzl@51473
  1597
  using tendsto_compose_eventually [OF f, where F=sequentially] by simp
hoelzl@51473
  1598
hoelzl@51473
  1599
lemma LIMSEQ_SEQ_conv2:
hoelzl@51473
  1600
  fixes f :: "'a::first_countable_topology \<Rightarrow> 'b::topological_space"
wenzelm@61969
  1601
  assumes "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S \<longlonglongrightarrow> a \<longrightarrow> (\<lambda>n. f (S n)) \<longlonglongrightarrow> l"
wenzelm@61976
  1602
  shows "f \<midarrow>a\<rightarrow> l"
hoelzl@51473
  1603
  using assms unfolding tendsto_def [where l=l] by (simp add: sequentially_imp_eventually_at)
hoelzl@51473
  1604
wenzelm@63494
  1605
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
  1606
  for a :: "'a::first_countable_topology" and L :: "'b::topological_space"
hoelzl@51473
  1607
  using LIMSEQ_SEQ_conv2 LIMSEQ_SEQ_conv1 ..
hoelzl@51473
  1608
hoelzl@57025
  1609
lemma sequentially_imp_eventually_at_left:
wenzelm@63494
  1610
  fixes a :: "'a::{linorder_topology,first_countable_topology}"
hoelzl@57025
  1611
  assumes b[simp]: "b < a"
wenzelm@63494
  1612
    and *: "\<And>f. (\<And>n. b < f n) \<Longrightarrow> (\<And>n. f n < a) \<Longrightarrow> incseq f \<Longrightarrow> f \<longlonglongrightarrow> a \<Longrightarrow>
wenzelm@63494
  1613
      eventually (\<lambda>n. P (f n)) sequentially"
hoelzl@57025
  1614
  shows "eventually P (at_left a)"
hoelzl@57025
  1615
proof (safe intro!: sequentially_imp_eventually_within)
wenzelm@63494
  1616
  fix X
wenzelm@63494
  1617
  assume X: "\<forall>n. X n \<in> {..< a} \<and> X n \<noteq> a" "X \<longlonglongrightarrow> a"
hoelzl@57025
  1618
  show "eventually (\<lambda>n. P (X n)) sequentially"
hoelzl@57025
  1619
  proof (rule ccontr)
wenzelm@63494
  1620
    assume neg: "\<not> ?thesis"
hoelzl@57447
  1621
    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
  1622
      (is "\<exists>s. ?P s")
hoelzl@57447
  1623
    proof (rule dependent_nat_choice)
hoelzl@57447
  1624
      have "\<not> eventually (\<lambda>n. b < X n \<longrightarrow> P (X n)) sequentially"
hoelzl@57447
  1625
        by (intro not_eventually_impI neg order_tendstoD(1) [OF X(2) b])
hoelzl@57447
  1626
      then show "\<exists>x. \<not> P (X x) \<and> b < X x"
hoelzl@57447
  1627
        by (auto dest!: not_eventuallyD)
hoelzl@57447
  1628
    next
hoelzl@57447
  1629
      fix x n
hoelzl@57447
  1630
      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
  1631
        using X
wenzelm@63494
  1632
        by (intro not_eventually_impI order_tendstoD(1)[OF X(2)] eventually_ge_at_top neg) auto
hoelzl@57447
  1633
      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
  1634
        by (auto dest!: not_eventuallyD)
hoelzl@57025
  1635
    qed
wenzelm@63494
  1636
    then obtain s where "?P s" ..
wenzelm@63494
  1637
    with X have "b < X (s n)"
wenzelm@63494
  1638
      and "X (s n) < a"
wenzelm@63494
  1639
      and "incseq (\<lambda>n. X (s n))"
wenzelm@63494
  1640
      and "(\<lambda>n. X (s n)) \<longlonglongrightarrow> a"
wenzelm@63494
  1641
      and "\<not> P (X (s n))"
wenzelm@63494
  1642
      for n
wenzelm@63494
  1643
      by (auto simp: subseq_Suc_iff Suc_le_eq incseq_Suc_iff
wenzelm@63494
  1644
          intro!: LIMSEQ_subseq_LIMSEQ[OF \<open>X \<longlonglongrightarrow> a\<close>, unfolded comp_def])
wenzelm@63494
  1645
    from *[OF this(1,2,3,4)] this(5) show False
wenzelm@63494
  1646
      by auto
hoelzl@57025
  1647
  qed
hoelzl@57025
  1648
qed
hoelzl@57025
  1649
hoelzl@57025
  1650
lemma tendsto_at_left_sequentially:
wenzelm@63494
  1651
  fixes a b :: "'b::{linorder_topology,first_countable_topology}"
hoelzl@57025
  1652
  assumes "b < a"
wenzelm@63494
  1653
  assumes *: "\<And>S. (\<And>n. S n < a) \<Longrightarrow> (\<And>n. b < S n) \<Longrightarrow> incseq S \<Longrightarrow> S \<longlonglongrightarrow> a \<Longrightarrow>
wenzelm@63494
  1654
    (\<lambda>n. X (S n)) \<longlonglongrightarrow> L"
wenzelm@61973
  1655
  shows "(X \<longlongrightarrow> L) (at_left a)"
wenzelm@63494
  1656
  using assms by (simp add: tendsto_def [where l=L] sequentially_imp_eventually_at_left)
hoelzl@57025
  1657
hoelzl@57447
  1658
lemma sequentially_imp_eventually_at_right:
wenzelm@63494
  1659
  fixes a b :: "'a::{linorder_topology,first_countable_topology}"
hoelzl@57447
  1660
  assumes b[simp]: "a < b"
wenzelm@63494
  1661
  assumes *: "\<And>f. (\<And>n. a < f n) \<Longrightarrow> (\<And>n. f n < b) \<Longrightarrow> decseq f \<Longrightarrow> f \<longlonglongrightarrow> a \<Longrightarrow>
wenzelm@63494
  1662
    eventually (\<lambda>n. P (f n)) sequentially"
hoelzl@57447
  1663
  shows "eventually P (at_right a)"
hoelzl@57447
  1664
proof (safe intro!: sequentially_imp_eventually_within)
wenzelm@63494
  1665
  fix X
wenzelm@63494
  1666
  assume X: "\<forall>n. X n \<in> {a <..} \<and> X n \<noteq> a" "X \<longlonglongrightarrow> a"
hoelzl@57447
  1667
  show "eventually (\<lambda>n. P (X n)) sequentially"
hoelzl@57447
  1668
  proof (rule ccontr)
wenzelm@63494
  1669
    assume neg: "\<not> ?thesis"
hoelzl@57447
  1670
    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
  1671
      (is "\<exists>s. ?P s")
hoelzl@57447
  1672
    proof (rule dependent_nat_choice)
hoelzl@57447
  1673
      have "\<not> eventually (\<lambda>n. X n < b \<longrightarrow> P (X n)) sequentially"
hoelzl@57447
  1674
        by (intro not_eventually_impI neg order_tendstoD(2) [OF X(2) b])
hoelzl@57447
  1675
      then show "\<exists>x. \<not> P (X x) \<and> X x < b"
hoelzl@57447
  1676
        by (auto dest!: not_eventuallyD)
hoelzl@57447
  1677
    next
hoelzl@57447
  1678
      fix x n
hoelzl@57447
  1679
      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
  1680
        using X
wenzelm@63494
  1681
        by (intro not_eventually_impI order_tendstoD(2)[OF X(2)] eventually_ge_at_top neg) auto
hoelzl@57447
  1682
      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
  1683
        by (auto dest!: not_eventuallyD)
hoelzl@57447
  1684
    qed
wenzelm@63494
  1685
    then obtain s where "?P s" ..
wenzelm@63494
  1686
    with X have "a < X (s n)"
wenzelm@63494
  1687
      and "X (s n) < b"
wenzelm@63494
  1688
      and "decseq (\<lambda>n. X (s n))"
wenzelm@63494
  1689
      and "(\<lambda>n. X (s n)) \<longlonglongrightarrow> a"
wenzelm@63494
  1690
      and "\<not> P (X (s n))"
wenzelm@63494
  1691
      for n
wenzelm@63494
  1692
      by (auto simp: subseq_Suc_iff Suc_le_eq decseq_Suc_iff
wenzelm@63494
  1693
          intro!: LIMSEQ_subseq_LIMSEQ[OF \<open>X \<longlonglongrightarrow> a\<close>, unfolded comp_def])
wenzelm@63494
  1694
    from *[OF this(1,2,3,4)] this(5) show False
wenzelm@63494
  1695
      by auto
hoelzl@57447
  1696
  qed
hoelzl@57447
  1697
qed
hoelzl@57447
  1698
hoelzl@57447
  1699
lemma tendsto_at_right_sequentially:
hoelzl@60172
  1700
  fixes a :: "_ :: {linorder_topology, first_countable_topology}"
hoelzl@57447
  1701
  assumes "a < b"
wenzelm@63494
  1702
    and *: "\<And>S. (\<And>n. a < S n) \<Longrightarrow> (\<And>n. S n < b) \<Longrightarrow> decseq S \<Longrightarrow> S \<longlonglongrightarrow> a \<Longrightarrow>
wenzelm@63494
  1703
      (\<lambda>n. X (S n)) \<longlonglongrightarrow> L"
wenzelm@61973
  1704
  shows "(X \<longlongrightarrow> L) (at_right a)"
wenzelm@63494
  1705
  using assms by (simp add: tendsto_def [where l=L] sequentially_imp_eventually_at_right)
wenzelm@63494
  1706
hoelzl@57447
  1707
wenzelm@60758
  1708
subsection \<open>Continuity\<close>
hoelzl@51471
  1709
wenzelm@60758
  1710
subsubsection \<open>Continuity on a set\<close>
hoelzl@51478
  1711
wenzelm@63494
  1712
definition continuous_on :: "'a set \<Rightarrow> ('a::topological_space \<Rightarrow> 'b::topological_space) \<Rightarrow> bool"
wenzelm@63494
  1713
  where "continuous_on s f \<longleftrightarrow> (\<forall>x\<in>s. (f \<longlongrightarrow> f x) (at x within s))"
hoelzl@51478
  1714
hoelzl@51481
  1715
lemma continuous_on_cong [cong]:
hoelzl@51481
  1716
  "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
  1717
  unfolding continuous_on_def
wenzelm@63494
  1718
  by (intro ball_cong filterlim_cong) (auto simp: eventually_at_filter)
hoelzl@51481
  1719
hoelzl@64008
  1720
lemma continuous_on_strong_cong:
hoelzl@64008
  1721
  "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
  1722
  unfolding simp_implies_def by (rule continuous_on_cong)
hoelzl@64008
  1723
hoelzl@51478
  1724
lemma continuous_on_topological:
hoelzl@51478
  1725
  "continuous_on s f \<longleftrightarrow>
hoelzl@51478
  1726
    (\<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
  1727
  unfolding continuous_on_def tendsto_def eventually_at_topological by metis
hoelzl@51478
  1728
hoelzl@51478
  1729
lemma continuous_on_open_invariant:
hoelzl@51478
  1730
  "continuous_on s f \<longleftrightarrow> (\<forall>B. open B \<longrightarrow> (\<exists>A. open A \<and> A \<inter> s = f -` B \<inter> s))"
hoelzl@51478
  1731
proof safe
wenzelm@63494
  1732
  fix B :: "'b set"
wenzelm@63494
  1733
  assume "continuous_on s f" "open B"
hoelzl@51478
  1734
  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
  1735
    by (auto simp: continuous_on_topological subset_eq Ball_def imp_conjL)
wenzelm@53381
  1736
  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
  1737
    unfolding bchoice_iff ..
hoelzl@51478
  1738
  then show "\<exists>A. open A \<and> A \<inter> s = f -` B \<inter> s"
hoelzl@51478
  1739
    by (intro exI[of _ "\<Union>x\<in>f -` B \<inter> s. A x"]) auto
hoelzl@51478
  1740
next
hoelzl@51478
  1741
  assume B: "\<forall>B. open B \<longrightarrow> (\<exists>A. open A \<and> A \<inter> s = f -` B \<inter> s)"
hoelzl@51478
  1742
  show "continuous_on s f"
hoelzl@51478
  1743
    unfolding continuous_on_topological
hoelzl@51478
  1744
  proof safe
wenzelm@63494
  1745
    fix x B
wenzelm@63494
  1746
    assume "x \<in> s" "open B" "f x \<in> B"
wenzelm@63494
  1747
    with B obtain A where A: "open A" "A \<inter> s = f -` B \<inter> s"
wenzelm@63494
  1748
      by auto
wenzelm@60758
  1749
    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
  1750
      by (intro exI[of _ A]) auto
hoelzl@51478
  1751
  qed
hoelzl@51478
  1752
qed
hoelzl@51478
  1753
hoelzl@51481
  1754
lemma continuous_on_open_vimage:
hoelzl@51481
  1755
  "open s \<Longrightarrow> continuous_on s f \<longleftrightarrow> (\<forall>B. open B \<longrightarrow> open (f -` B \<inter> s))"
hoelzl@51481
  1756
  unfolding continuous_on_open_invariant
hoelzl@51481
  1757
  by (metis open_Int Int_absorb Int_commute[of s] Int_assoc[of _ _ s])
hoelzl@51481
  1758
lp15@55734
  1759
corollary continuous_imp_open_vimage:
lp15@55734
  1760
  assumes "continuous_on s f" "open s" "open B" "f -` B \<subseteq> s"
wenzelm@63494
  1761
  shows "open (f -` B)"
wenzelm@63494
  1762
  by (metis assms continuous_on_open_vimage le_iff_inf)
lp15@55734
  1763
hoelzl@56371
  1764
corollary open_vimage[continuous_intros]:
wenzelm@63494
  1765
  assumes "open s"
wenzelm@63494
  1766
    and "continuous_on UNIV f"
lp15@55775
  1767
  shows "open (f -` s)"
wenzelm@63494
  1768
  using assms by (simp add: continuous_on_open_vimage [OF open_UNIV])
lp15@55775
  1769
hoelzl@51478
  1770
lemma continuous_on_closed_invariant:
hoelzl@51478
  1771
  "continuous_on s f \<longleftrightarrow> (\<forall>B. closed B \<longrightarrow> (\<exists>A. closed A \<and> A \<inter> s = f -` B \<inter> s))"
hoelzl@51478
  1772
proof -
wenzelm@63494
  1773
  have *: "(\<And>A. P A \<longleftrightarrow> Q (- A)) \<Longrightarrow> (\<forall>A. P A) \<longleftrightarrow> (\<forall>A. Q A)"
wenzelm@63494
  1774
    for P Q :: "'b set \<Rightarrow> bool"
hoelzl@51478
  1775
    by (metis double_compl)
hoelzl@51478
  1776
  show ?thesis
wenzelm@63494
  1777
    unfolding continuous_on_open_invariant
wenzelm@63494
  1778
    by (intro *) (auto simp: open_closed[symmetric])
hoelzl@51478
  1779
qed
hoelzl@51478
  1780
hoelzl@51481
  1781
lemma continuous_on_closed_vimage:
hoelzl@51481
  1782
  "closed s \<Longrightarrow> continuous_on s f \<longleftrightarrow> (\<forall>B. closed B \<longrightarrow> closed (f -` B \<inter> s))"
hoelzl@51481
  1783
  unfolding continuous_on_closed_invariant
hoelzl@51481
  1784
  by (metis closed_Int Int_absorb Int_commute[of s] Int_assoc[of _ _ s])
hoelzl@51481
  1785
lp15@61426
  1786
corollary closed_vimage_Int[continuous_intros]:
wenzelm@63494
  1787
  assumes "closed s"
wenzelm@63494
  1788
    and "continuous_on t f"
wenzelm@63494
  1789
    and t: "closed t"
lp15@61426
  1790
  shows "closed (f -` s \<inter> t)"
wenzelm@63494
  1791
  using assms by (simp add: continuous_on_closed_vimage [OF t])
lp15@61426
  1792
hoelzl@56371
  1793
corollary closed_vimage[continuous_intros]:
wenzelm@63494
  1794
  assumes "closed s"
wenzelm@63494
  1795
    and "continuous_on UNIV f"
hoelzl@56371
  1796
  shows "closed (f -` s)"
lp15@61426
  1797
  using closed_vimage_Int [OF assms] by simp
hoelzl@56371
  1798
lp15@62843
  1799
lemma continuous_on_empty [simp]: "continuous_on {} f"
lp15@61907
  1800
  by (simp add: continuous_on_def)
lp15@61907
  1801
lp15@62843
  1802
lemma continuous_on_sing [simp]: "continuous_on {x} f"
lp15@61907
  1803
  by (simp add: continuous_on_def at_within_def)
lp15@61907
  1804
hoelzl@51481
  1805
lemma continuous_on_open_Union:
hoelzl@51481
  1806
  "(\<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
  1807
  unfolding continuous_on_def
wenzelm@63494
  1808
  by safe (metis open_Union at_within_open UnionI)
hoelzl@51481
  1809
hoelzl@51481
  1810
lemma continuous_on_open_UN:
wenzelm@63494
  1811
  "(\<And>s. s \<in> S \<Longrightarrow> open (A s)) \<Longrightarrow> (\<And>s. s \<in> S \<Longrightarrow> continuous_on (A s) f) \<Longrightarrow>
wenzelm@63494
  1812
    continuous_on (\<Union>s\<in>S. A s) f"
haftmann@62343
  1813
  by (rule continuous_on_open_Union) auto
hoelzl@51481
  1814
paulson@61204
  1815
lemma continuous_on_open_Un:
paulson@61204
  1816
  "open s \<Longrightarrow> open t \<Longrightarrow> continuous_on s f \<Longrightarrow> continuous_on t f \<Longrightarrow> continuous_on (s \<union> t) f"
paulson@61204
  1817
  using continuous_on_open_Union [of "{s,t}"] by auto
paulson@61204
  1818
hoelzl@51481
  1819
lemma continuous_on_closed_Un:
hoelzl@51481
  1820
  "closed s \<Longrightarrow> closed t \<Longrightarrow> continuous_on s f \<Longrightarrow> continuous_on t f \<Longrightarrow> continuous_on (s \<union> t) f"
hoelzl@51481
  1821
  by (auto simp add: continuous_on_closed_vimage closed_Un Int_Un_distrib)
hoelzl@51481
  1822
hoelzl@51481
  1823
lemma continuous_on_If:
wenzelm@63494
  1824
  assumes closed: "closed s" "closed t"
wenzelm@63494
  1825
    and cont: "continuous_on s f" "continuous_on t g"
hoelzl@51481
  1826
    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
  1827
  shows "continuous_on (s \<union> t) (\<lambda>x. if P x then f x else g x)"
wenzelm@63494
  1828
    (is "continuous_on _ ?h")
hoelzl@51481
  1829
proof-
hoelzl@51481
  1830
  from P have "\<forall>x\<in>s. f x = ?h x" "\<forall>x\<in>t. g x = ?h x"
hoelzl@51481
  1831
    by auto
hoelzl@51481
  1832
  with cont have "continuous_on s ?h" "continuous_on t ?h"
hoelzl@51481
  1833
    by simp_all
hoelzl@51481
  1834
  with closed show ?thesis
hoelzl@51481
  1835
    by (rule continuous_on_closed_Un)
hoelzl@51481
  1836
qed
hoelzl@51481
  1837
lp15@65036
  1838
lemma continuous_on_cases:
lp15@65036
  1839
  "closed s \<Longrightarrow> closed t \<Longrightarrow> continuous_on s f \<Longrightarrow> continuous_on t g \<Longrightarrow>
lp15@65036
  1840
    \<forall>x. (x\<in>s \<and> \<not> P x) \<or> (x \<in> t \<and> P x) \<longrightarrow> f x = g x \<Longrightarrow>
lp15@65036
  1841
    continuous_on (s \<union> t) (\<lambda>x. if P x then f x else g x)"
lp15@65036
  1842
  by (rule continuous_on_If) auto
lp15@65036
  1843
hoelzl@56371
  1844
lemma continuous_on_id[continuous_intros]: "continuous_on s (\<lambda>x. x)"
hoelzl@58729
  1845
  unfolding continuous_on_def by fast
hoelzl@51478
  1846
lp15@63301
  1847
lemma continuous_on_id'[continuous_intros]: "continuous_on s id"
lp15@63301
  1848
  unfolding continuous_on_def id_def by fast
lp15@63301
  1849
hoelzl@56371
  1850
lemma continuous_on_const[continuous_intros]: "continuous_on s (\<lambda>x. c)"
hoelzl@58729
  1851
  unfolding continuous_on_def by auto
hoelzl@51478
  1852
lp15@61738
  1853
lemma continuous_on_subset: "continuous_on s f \<Longrightarrow> t \<subseteq> s \<Longrightarrow> continuous_on t f"
immler@65204
  1854
  unfolding continuous_on_def
immler@65204
  1855
  by (metis subset_eq tendsto_within_subset)
lp15@61738
  1856
hoelzl@56371
  1857
lemma continuous_on_compose[continuous_intros]:
wenzelm@63494
  1858
  "continuous_on s f \<Longrightarrow> continuous_on (f ` s) g \<Longrightarrow> continuous_on s (g \<circ> f)"
hoelzl@51478
  1859
  unfolding continuous_on_topological by simp metis
hoelzl@51478
  1860
hoelzl@51481
  1861
lemma continuous_on_compose2:
lp15@61738
  1862
  "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
  1863
  using continuous_on_compose[of s f g] continuous_on_subset by (force simp add: comp_def)
hoelzl@51481
  1864
hoelzl@60720
  1865
lemma continuous_on_generate_topology:
hoelzl@60720
  1866
  assumes *: "open = generate_topology X"
wenzelm@63494
  1867
    and **: "\<And>B. B \<in> X \<Longrightarrow> \<exists>C. open C \<and> C \<inter> A = f -` B \<inter> A"
hoelzl@60720
  1868
  shows "continuous_on A f"
hoelzl@60720
  1869
  unfolding continuous_on_open_invariant
hoelzl@60720
  1870
proof safe
wenzelm@63494
  1871
  fix B :: "'a set"
wenzelm@63494
  1872
  assume "open B"
wenzelm@63494
  1873
  then show "\<exists>C. open C \<and> C \<inter> A = f -` B \<inter> A"
hoelzl@60720
  1874
    unfolding *
wenzelm@63494
  1875
  proof induct
hoelzl@60720
  1876
    case (UN K)
hoelzl@60720
  1877
    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
  1878
      by metis
hoelzl@60720
  1879
    then show ?case
hoelzl@60720
  1880
      by (intro exI[of _ "\<Union>k\<in>K. C k"]) blast
hoelzl@60720
  1881
  qed (auto intro: **)
hoelzl@60720
  1882
qed
hoelzl@60720
  1883
hoelzl@60720
  1884
lemma continuous_onI_mono:
wenzelm@63494
  1885
  fixes f :: "'a::linorder_topology \<Rightarrow> 'b::{dense_order,linorder_topology}"
hoelzl@60720
  1886
  assumes "open (f`A)"
wenzelm@63494
  1887
    and mono: "\<And>x y. x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y"
hoelzl@60720
  1888
  shows "continuous_on A f"
hoelzl@60720
  1889
proof (rule continuous_on_generate_topology[OF open_generated_order], safe)
hoelzl@60720
  1890
  have monoD: "\<And>x y. x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> f x < f y \<Longrightarrow> x < y"
hoelzl@60720
  1891
    by (auto simp: not_le[symmetric] mono)
wenzelm@63494
  1892
  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
  1893
  proof -
wenzelm@63494
  1894
    obtain y where "f a < y" "{f a ..< y} \<subseteq> f`A"
wenzelm@63494
  1895
      using open_right[OF \<open>open (f`A)\<close>, of "f a" b] a fa
hoelzl@60720
  1896
      by auto
wenzelm@63494
  1897
    obtain z where z: "f a < z" "z < min b y"
hoelzl@60720
  1898
      using dense[of "f a" "min b y"] \<open>f a < y\<close> \<open>f a < b\<close> by auto
wenzelm@63494
  1899
    then obtain c where "z = f c" "c \<in> A"
hoelzl@60720
  1900
      using \<open>{f a ..< y} \<subseteq> f`A\<close>[THEN subsetD, of z] by (auto simp: less_imp_le)
wenzelm@63494
  1901
    with a z show ?thesis
wenzelm@63494
  1902
      by (auto intro!: exI[of _ c] simp: monoD)
wenzelm@63494
  1903
  qed
hoelzl@60720
  1904
  then show "\<exists>C. open C \<and> C \<inter> A = f -` {..<b} \<inter> A" for b
hoelzl@60720
  1905
    by (intro exI[of _ "(\<Union>x\<in>{x\<in>A. f x < b}. {..< x})"])
hoelzl@60720
  1906
       (auto intro: le_less_trans[OF mono] less_imp_le)
hoelzl@60720
  1907
wenzelm@63494
  1908
  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
  1909
  proof -
wenzelm@63494
  1910
    note a fa
hoelzl@60720
  1911
    moreover
wenzelm@63494
  1912
    obtain y where "y < f a" "{y <.. f a} \<subseteq> f`A"
wenzelm@63494
  1913
      using open_left[OF \<open>open (f`A)\<close>, of "f a" b]  a fa
hoelzl@60720
  1914
      by auto
wenzelm@63494
  1915
    then obtain z where z: "max b y < z" "z < f a"
hoelzl@60720
  1916
      using dense[of "max b y" "f a"] \<open>y < f a\<close> \<open>b < f a\<close> by auto
wenzelm@63494
  1917
    then obtain c where "z = f c" "c \<in> A"
hoelzl@60720
  1918
      using \<open>{y <.. f a} \<subseteq> f`A\<close>[THEN subsetD, of z] by (auto simp: less_imp_le)
wenzelm@63494
  1919
    with a z show ?thesis
wenzelm@63494
  1920
      by (auto intro!: exI[of _ c] simp: monoD)
wenzelm@63494
  1921
  qed
hoelzl@60720
  1922
  then show "\<exists>C. open C \<and> C \<inter> A = f -` {b <..} \<inter> A" for b
hoelzl@60720
  1923
    by (intro exI[of _ "(\<Union>x\<in>{x\<in>A. b < f x}. {x <..})"])
hoelzl@60720
  1924
       (auto intro: less_le_trans[OF _ mono] less_imp_le)
hoelzl@60720
  1925
qed
hoelzl@60720
  1926
immler@65204
  1927
lemma continuous_on_IccI:
immler@65204
  1928
  "\<lbrakk>(f \<longlongrightarrow> f a) (at_right a);
immler@65204
  1929
    (f \<longlongrightarrow> f b) (at_left b);
immler@65204
  1930
    (\<And>x. a < x \<Longrightarrow> x < b \<Longrightarrow> f \<midarrow>x\<rightarrow> f x); a < b\<rbrakk> \<Longrightarrow>
immler@65204
  1931
    continuous_on {a .. b} f"
immler@65204
  1932
  for a::"'a::linorder_topology"
immler@65204
  1933
  using at_within_open[of _ "{a<..<b}"]
immler@65204
  1934
  by (auto simp: continuous_on_def at_within_Icc_at_right at_within_Icc_at_left le_less
immler@65204
  1935
      at_within_Icc_at)
immler@65204
  1936
immler@65204
  1937
lemma
immler@65204
  1938
  fixes a b::"'a::linorder_topology"
immler@65204
  1939
  assumes "continuous_on {a .. b} f" "a < b"
immler@65204
  1940
  shows continuous_on_Icc_at_rightD: "(f \<longlongrightarrow> f a) (at_right a)"
immler@65204
  1941
    and continuous_on_Icc_at_leftD: "(f \<longlongrightarrow> f b) (at_left b)"
immler@65204
  1942
  using assms
immler@65204
  1943
  by (auto simp: at_within_Icc_at_right at_within_Icc_at_left continuous_on_def
immler@65204
  1944
      dest: bspec[where x=a] bspec[where x=b])
immler@65204
  1945
wenzelm@63494
  1946
wenzelm@60758
  1947
subsubsection \<open>Continuity at a point\<close>
hoelzl@51478
  1948
wenzelm@63494
  1949
definition continuous :: "'a::t2_space filter \<Rightarrow> ('a \<Rightarrow> 'b::topological_space) \<Rightarrow> bool"
wenzelm@63494
  1950
  where "continuous F f \<longleftrightarrow> (f \<longlongrightarrow> f (Lim F (\<lambda>x. x))) F"
hoelzl@51478
  1951
hoelzl@51478
  1952
lemma continuous_bot[continuous_intros, simp]: "continuous bot f"
hoelzl@51478
  1953
  unfolding continuous_def by auto
hoelzl@51478
  1954
hoelzl@51478
  1955
lemma continuous_trivial_limit: "trivial_limit net \<Longrightarrow> continuous net f"
hoelzl@51478
  1956
  by simp
hoelzl@51478
  1957
wenzelm@61973
  1958
lemma continuous_within: "continuous (at x within s) f \<longleftrightarrow> (f \<longlongrightarrow> f x) (at x within s)"
hoelzl@51641
  1959
  by (cases "trivial_limit (at x within s)") (auto simp add: Lim_ident_at continuous_def)
hoelzl@51478
  1960
hoelzl@51478
  1961
lemma continuous_within_topological:
hoelzl@51478
  1962
  "continuous (at x within s) f \<longleftrightarrow>
hoelzl@51478
  1963
    (\<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
  1964
  unfolding continuous_within tendsto_def eventually_at_topological by metis
hoelzl@51478
  1965
hoelzl@51478
  1966
lemma continuous_within_compose[continuous_intros]:
hoelzl@51478
  1967
  "continuous (at x within s) f \<Longrightarrow> continuous (at (f x) within f ` s) g \<Longrightarrow>
wenzelm@63494
  1968
    continuous (at x within s) (g \<circ> f)"
hoelzl@51478
  1969
  by (simp add: continuous_within_topological) metis
hoelzl@51478
  1970
hoelzl@51478
  1971
lemma continuous_within_compose2:
hoelzl@51478
  1972
  "continuous (at x within s) f \<Longrightarrow> continuous (at (f x) within f ` s) g \<Longrightarrow>
wenzelm@63494
  1973
    continuous (at x within s) (\<lambda>x. g (f x))"
hoelzl@51478
  1974
  using continuous_within_compose[of x s f g] by (simp add: comp_def)
hoelzl@51471
  1975
wenzelm@61976
  1976
lemma continuous_at: "continuous (at x) f \<longleftrightarrow> f \<midarrow>x\<rightarrow> f x"
hoelzl@51478
  1977
  using continuous_within[of x UNIV f] by simp
hoelzl@51478
  1978
hoelzl@51478
  1979
lemma continuous_ident[continuous_intros, simp]: "continuous (at x within S) (\<lambda>x. x)"
hoelzl@51641
  1980
  unfolding continuous_within by (rule tendsto_ident_at)
hoelzl@51478
  1981
hoelzl@51478
  1982
lemma continuous_const[continuous_intros, simp]: "continuous F (\<lambda>x. c)"
hoelzl@51478
  1983
  unfolding continuous_def by (rule tendsto_const)
hoelzl@51478
  1984
hoelzl@51478
  1985
lemma continuous_on_eq_continuous_within:
hoelzl@51478
  1986
  "continuous_on s f \<longleftrightarrow> (\<forall>x\<in>s. continuous (at x within s) f)"
hoelzl@51478
  1987
  unfolding continuous_on_def continuous_within ..
hoelzl@51478
  1988
wenzelm@63494
  1989
abbreviation isCont :: "('a::t2_space \<Rightarrow> 'b::topological_space) \<Rightarrow> 'a \<Rightarrow> bool"
wenzelm@63494
  1990
  where "isCont f a \<equiv> continuous (at a) f"
hoelzl@51478
  1991
wenzelm@61976
  1992
lemma isCont_def: "isCont f a \<longleftrightarrow> f \<midarrow>a\<rightarrow> f a"
hoelzl@51478
  1993
  by (rule continuous_at)
hoelzl@51478
  1994
eberlm@63295
  1995
lemma isCont_cong:
eberlm@63295
  1996
  assumes "eventually (\<lambda>x. f x = g x) (nhds x)"
wenzelm@63494
  1997
  shows "isCont f x \<longleftrightarrow> isCont g x"
eberlm@63295
  1998
proof -
wenzelm@63494
  1999
  from assms have [simp]: "f x = g x"
wenzelm@63494
  2000
    by (rule eventually_nhds_x_imp_x)
eberlm@63295
  2001
  from assms have "eventually (\<lambda>x. f x = g x) (at x)"
eberlm@63295
  2002
    by (auto simp: eventually_at_filter elim!: eventually_mono)
eberlm@63295
  2003
  with assms have "isCont f x \<longleftrightarrow> isCont g x" unfolding isCont_def
eberlm@63295
  2004
    by (intro filterlim_cong) (auto elim!: eventually_mono)
eberlm@63295
  2005
  with assms show ?thesis by simp
eberlm@63295
  2006
qed
eberlm@63295
  2007
paulson@60762
  2008
lemma continuous_at_imp_continuous_at_within: "isCont f x \<Longrightarrow> continuous (at x within s) f"
hoelzl@51641
  2009
  by (auto intro: tendsto_mono at_le simp: continuous_at continuous_within)
hoelzl@51478
  2010
hoelzl@51481
  2011
lemma continuous_on_eq_continuous_at: "open s \<Longrightarrow> continuous_on s f \<longleftrightarrow> (\<forall>x\<in>s. isCont f x)"
hoelzl@51641
  2012
  by (simp add: continuous_on_def continuous_at at_within_open[of _ s])
hoelzl@51481
  2013
hoelzl@62083
  2014
lemma continuous_within_open: "a \<in> A \<Longrightarrow> open A \<Longrightarrow> continuous (at a within A) f \<longleftrightarrow> isCont f a"
hoelzl@62083
  2015
  by (simp add: at_within_open_NO_MATCH)
hoelzl@62083
  2016
hoelzl@51478
  2017
lemma continuous_at_imp_continuous_on: "\<forall>x\<in>s. isCont f x \<Longrightarrow> continuous_on s f"
paulson@60762
  2018
  by (auto intro: continuous_at_imp_continuous_at_within simp: continuous_on_eq_continuous_within)
hoelzl@51478
  2019
hoelzl@51478
  2020
lemma isCont_o2: "isCont f a \<Longrightarrow> isCont g (f a) \<Longrightarrow> isCont (\<lambda>x. g (f x)) a"
hoelzl@51478
  2021
  unfolding isCont_def by (rule tendsto_compose)
hoelzl@51478
  2022
hoelzl@51478
  2023
lemma isCont_o[continuous_intros]: "isCont f a \<Longrightarrow> isCont g (f a) \<Longrightarrow> isCont (g \<circ> f) a"
hoelzl@51478
  2024
  unfolding o_def by (rule isCont_o2)
hoelzl@51471
  2025
wenzelm@61973
  2026
lemma isCont_tendsto_compose: "isCont g l \<Longrightarrow> (f \<longlongrightarrow> l) F \<Longrightarrow> ((\<lambda>x. g (f x)) \<longlongrightarrow> g l) F"
hoelzl@51471
  2027
  unfolding isCont_def by (rule tendsto_compose)
hoelzl@62102
  2028
eberlm@62049
  2029
lemma continuous_on_tendsto_compose:
eberlm@62049
  2030
  assumes f_cont: "continuous_on s f"
wenzelm@63494
  2031
    and g: "(g \<longlongrightarrow> l) F"
wenzelm@63494
  2032
    and l: "l \<in> s"
wenzelm@63494
  2033
    and ev: "\<forall>\<^sub>Fx in F. g x \<in> s"
eberlm@62049
  2034
  shows "((\<lambda>x. f (g x)) \<longlongrightarrow> f l) F"
eberlm@62049
  2035
proof -
eberlm@62049
  2036
  from f_cont l have f: "(f \<longlongrightarrow> f l) (at l within s)"
eberlm@62049
  2037
    by (simp add: continuous_on_def)
eberlm@62049
  2038
  have i: "((\<lambda>x. if g x = l then f l else f (g x)) \<longlongrightarrow> f l) F"
eberlm@62049
  2039
    by (rule filterlim_If)
eberlm@62049
  2040
       (auto intro!: filterlim_compose[OF f] eventually_conj tendsto_mono[OF _ g]
eberlm@62049
  2041
             simp: filterlim_at eventually_inf_principal eventually_mono[OF ev])
eberlm@62049
  2042
  show ?thesis
eberlm@62049
  2043
    by (rule filterlim_cong[THEN iffD1[OF _ i]]) auto
eberlm@62049
  2044
qed
hoelzl@51471
  2045
hoelzl@51478
  2046
lemma continuous_within_compose3:
hoelzl@51478
  2047
  "isCont g (f x) \<Longrightarrow> continuous (at x within s) f \<Longrightarrow> continuous (at x within s) (\<lambda>x. g (f x))"
wenzelm@63171
  2048
  using continuous_at_imp_continuous_at_within continuous_within_compose2 by blast
hoelzl@51471
  2049
hoelzl@57447
  2050
lemma filtermap_nhds_open_map:
wenzelm@63494
  2051
  assumes cont: "isCont f a"
wenzelm@63494
  2052
    and open_map: "\<And>S. open S \<Longrightarrow> open (f`S)"
hoelzl@57447
  2053
  shows "filtermap f (nhds a) = nhds (f a)"
hoelzl@57447
  2054
  unfolding filter_eq_iff
hoelzl@57447
  2055
proof safe
wenzelm@63494
  2056
  fix P
wenzelm@63494
  2057
  assume "eventually P (filtermap f (nhds a))"
wenzelm@63494
  2058
  then obtain S where "open S" "a \<in> S" "\<forall>x\<in>S. P (f x)"
wenzelm@63494
  2059
    by (auto simp: eventually_filtermap eventually_nhds)
hoelzl@57447
  2060
  then show "eventually P (nhds (f a))"
hoelzl@57447
  2061
    unfolding eventually_nhds by (intro exI[of _ "f`S"]) (auto intro!: open_map)
hoelzl@57447
  2062
qed (metis filterlim_iff tendsto_at_iff_tendsto_nhds isCont_def eventually_filtermap cont)
hoelzl@57447
  2063
hoelzl@62102
  2064
lemma continuous_at_split:
wenzelm@63494
  2065
  "continuous (at x) f \<longleftrightarrow> continuous (at_left x) f \<and> continuous (at_right x) f"
wenzelm@63494
  2066
  for x :: "'a::linorder_topology"
hoelzl@57447
  2067
  by (simp add: continuous_within filterlim_at_split)
hoelzl@57447
  2068
wenzelm@63494
  2069
text \<open>
wenzelm@63495
  2070
  The following open/closed Collect lemmas are ported from
wenzelm@63495
  2071
  Sébastien Gouëzel's \<open>Ergodic_Theory\<close>.
wenzelm@63494
  2072
\<close>
hoelzl@63332
  2073
lemma open_Collect_neq:
wenzelm@63494
  2074
  fixes f g :: "'a::topological_space \<Rightarrow> 'b::t2_space"
hoelzl@63332
  2075
  assumes f: "continuous_on UNIV f" and g: "continuous_on UNIV g"
hoelzl@63332
  2076
  shows "open {x. f x \<noteq> g x}"
hoelzl@63332
  2077
proof (rule openI)
wenzelm@63494
  2078
  fix t
wenzelm@63494
  2079
  assume "t \<in> {x. f x \<noteq> g x}"
hoelzl@63332
  2080
  then obtain U V where *: "open U" "open V" "f t \<in> U" "g t \<in> V" "U \<inter> V = {}"
hoelzl@63332
  2081
    by (auto simp add: separation_t2)
hoelzl@63332
  2082
  with open_vimage[OF \<open>open U\<close> f] open_vimage[OF \<open>open V\<close> g]
hoelzl@63332
  2083
  show "\<exists>T. open T \<and> t \<in> T \<and> T \<subseteq> {x. f x \<noteq> g x}"
hoelzl@63332
  2084
    by (intro exI[of _ "f -` U \<inter> g -` V"]) auto
hoelzl@63332
  2085
qed
hoelzl@63332
  2086
hoelzl@63332
  2087
lemma closed_Collect_eq:
wenzelm@63494
  2088
  fixes f g :: "'a::topological_space \<Rightarrow> 'b::t2_space"
hoelzl@63332
  2089
  assumes f: "continuous_on UNIV f" and g: "continuous_on UNIV g"
hoelzl@63332
  2090
  shows "closed {x. f x = g x}"
hoelzl@63332
  2091
  using open_Collect_neq[OF f g] by (simp add: closed_def Collect_neg_eq)
hoelzl@63332
  2092
hoelzl@63332
  2093
lemma open_Collect_less:
wenzelm@63494
  2094
  fixes f g :: "'a::topological_space \<Rightarrow> 'b::linorder_topology"
hoelzl@63332
  2095
  assumes f: "continuous_on UNIV f" and g: "continuous_on UNIV g"
hoelzl@63332
  2096
  shows "open {x. f x < g x}"
hoelzl@63332
  2097
proof (rule openI)
wenzelm@63494
  2098
  fix t
wenzelm@63494
  2099
  assume t: "t \<in> {x. f x < g x}"
hoelzl@63332
  2100
  show "\<exists>T. open T \<and> t \<in> T \<and> T \<subseteq> {x. f x < g x}"
wenzelm@63494
  2101
  proof (cases "\<exists>z. f t < z \<and> z < g t")
wenzelm@63494
  2102
    case True
wenzelm@63494
  2103
    then obtain z where "f t < z \<and> z < g t" by blast
hoelzl@63332
  2104
    then show ?thesis
hoelzl@63332
  2105
      using open_vimage[OF _ f, of "{..< z}"] open_vimage[OF _ g, of "{z <..}"]
hoelzl@63332
  2106
      by (intro exI[of _ "f -` {..<z} \<inter> g -` {z<..}"]) auto
hoelzl@63332
  2107
  next
wenzelm@63494
  2108
    case False
hoelzl@63332
  2109
    then have *: "{g t ..} = {f t <..}" "{..< g t} = {.. f t}"
hoelzl@63332
  2110
      using t by (auto intro: leI)
hoelzl@63332
  2111
    show ?thesis
hoelzl@63332
  2112
      using open_vimage[OF _ f, of "{..< g t}"] open_vimage[OF _ g, of "{f t <..}"] t
hoelzl@63332
  2113
      apply (intro exI[of _ "f -` {..< g t} \<inter> g -` {f t<..}"])
hoelzl@63332
  2114
      apply (simp add: open_Int)
hoelzl@63332
  2115
      apply (auto simp add: *)
hoelzl@63332
  2116
      done
hoelzl@63332
  2117
  qed
hoelzl@63332
  2118
qed
hoelzl@63332
  2119
hoelzl@63332
  2120
lemma closed_Collect_le:
hoelzl@63332
  2121
  fixes f g :: "'a :: topological_space \<Rightarrow> 'b::linorder_topology"
wenzelm@63494
  2122
  assumes f: "continuous_on UNIV f"
wenzelm@63494
  2123
    and g: "continuous_on UNIV g"
hoelzl@63332
  2124
  shows "closed {x. f x \<le> g x}"
wenzelm@63494
  2125
  using open_Collect_less [OF g f]
wenzelm@63494
  2126
  by (simp add: closed_def Collect_neg_eq[symmetric] not_le)
wenzelm@63494
  2127
hoelzl@63332
  2128
hoelzl@61245
  2129
subsubsection \<open>Open-cover compactness\<close>
hoelzl@51479
  2130
hoelzl@51479
  2131
context topological_space
hoelzl@51479
  2132
begin
hoelzl@51479
  2133
wenzelm@63494
  2134
definition compact :: "'a set \<Rightarrow> bool"
wenzelm@63494
  2135
  where compact_eq_heine_borel:  (* This name is used for backwards compatibility *)
hoelzl@51479
  2136
    "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
  2137
hoelzl@51479
  2138
lemma compactI:
wenzelm@60585
  2139
  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
  2140
  shows "compact s"
hoelzl@51479
  2141
  unfolding compact_eq_heine_borel using assms by metis
hoelzl@51479
  2142
hoelzl@51479
  2143
lemma compact_empty[simp]: "compact {}"
hoelzl@51479
  2144
  by (auto intro!: compactI)
hoelzl@51479
  2145
lp15@64758
  2146
lemma compactE: (*related to COMPACT_IMP_HEINE_BOREL in HOL Light*)
lp15@64758
  2147
  assumes "compact S" "S \<subseteq> \<Union>\<T>" "\<And>B. B \<in> \<T> \<Longrightarrow> open B"
lp15@64758
  2148
  obtains \<T>' where "\<T>' \<subseteq> \<T>" "finite \<T>'" "S \<subseteq> \<Union>\<T>'"
lp15@64758
  2149
  by (meson assms compact_eq_heine_borel)
hoelzl@51479
  2150
hoelzl@51479
  2151
lemma compactE_image:
lp15@64845
  2152
  assumes "compact S"
lp15@64845
  2153
    and "\<forall>T\<in>C. open (f T)"
lp15@64845
  2154
    and "S \<subseteq> (\<Union>c\<in>C. f c)"
lp15@64845
  2155
  obtains C' where "C' \<subseteq> C" and "finite C'" and "S \<subseteq> (\<Union>c\<in>C'. f c)"
haftmann@62343
  2156
  using assms unfolding ball_simps [symmetric]
lp15@64845
  2157
  by (metis (lifting) finite_subset_image compact_eq_heine_borel[of S])
hoelzl@51479
  2158
lp15@62843
  2159
lemma compact_Int_closed [intro]:
lp15@64845
  2160
  assumes "compact S"
lp15@64845
  2161
    and "closed T"
lp15@64845
  2162
  shows "compact (S \<inter> T)"
hoelzl@51481
  2163
proof (rule compactI)
wenzelm@63494
  2164
  fix C
wenzelm@63494
  2165
  assume C: "\<forall>c\<in>C. open c"
lp15@64845
  2166
  assume cover: "S \<inter> T \<subseteq> \<Union>C"
lp15@64845
  2167
  from C \<open>closed T\<close> have "\<forall>c\<in>C \<union> {- T}. open c"
wenzelm@63494
  2168
    by auto
lp15@64845
  2169
  moreover from cover have "S \<subseteq> \<Union>(C \<union> {- T})"
wenzelm@63494
  2170
    by auto
lp15@64845
  2171
  ultimately have "\<exists>D\<subseteq>C \<union> {- T}. finite D \<and> S \<subseteq> \<Union>D"
lp15@64845
  2172
    using \<open>compact S\<close> unfolding compact_eq_heine_borel by auto
lp15@64845
  2173
  then obtain D where "D \<subseteq> C \<union> {- T} \<and> finite D \<and> S \<subseteq> \<Union>D" ..
lp15@64845
  2174
  then show "\<exists>D\<subseteq>C. finite D \<and> S \<inter> T \<subseteq> \<Union>D"
lp15@64845
  2175
    by (intro exI[of _ "D - {-T}"]) auto
hoelzl@51481
  2176
qed
hoelzl@51481
  2177
lp15@64845
  2178
lemma compact_diff: "\<lbrakk>compact S; open T\<rbrakk> \<Longrightarrow> compact(S - T)"
lp15@64845
  2179
  by (simp add: Diff_eq compact_Int_closed open_closed)
lp15@64845
  2180
hoelzl@54797
  2181
lemma inj_setminus: "inj_on uminus (A::'a set set)"
hoelzl@54797
  2182
  by (auto simp: inj_on_def)
hoelzl@54797
  2183
wenzelm@63494
  2184
wenzelm@63494
  2185
subsection \<open>Finite intersection property\<close>
lp15@63301
  2186
hoelzl@54797
  2187
lemma compact_fip:
hoelzl@54797
  2188
  "compact U \<longleftrightarrow>
hoelzl@54797
  2189
    (\<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
  2190
  (is "_ \<longleftrightarrow> ?R")
hoelzl@54797
  2191
proof (safe intro!: compact_eq_heine_borel[THEN iffD2])
hoelzl@54797
  2192
  fix A
hoelzl@54797
  2193
  assume "compact U"
wenzelm@63494
  2194
  assume A: "\<forall>a\<in>A. closed a" "U \<inter> \<Inter>A = {}"
wenzelm@63494
  2195
  assume fin: "\<forall>B \<subseteq> A. finite B \<longrightarrow> U \<inter> \<Inter>B \<noteq> {}"
hoelzl@54797
  2196
  from A have "(\<forall>a\<in>uminus`A. open a) \<and> U \<subseteq> \<Union>(uminus`A)"
hoelzl@54797
  2197
    by auto
wenzelm@60758
  2198
  with \<open>compact U\<close> obtain B where "B \<subseteq> A" "finite (uminus`B)" "U \<subseteq> \<Union>(uminus`B)"
hoelzl@54797
  2199
    unfolding compact_eq_heine_borel by (metis subset_image_iff)
wenzelm@63494
  2200
  with fin[THEN spec, of B] show False
hoelzl@54797
  2201
    by (auto dest: finite_imageD intro: inj_setminus)
hoelzl@54797
  2202
next
hoelzl@54797
  2203
  fix A
hoelzl@54797
  2204
  assume ?R
hoelzl@54797
  2205
  assume "\<forall>a\<in>A. open a" "U \<subseteq> \<Union>A"
hoelzl@54797
  2206
  then have "U \<inter> \<Inter>(uminus`A) = {}" "\<forall>a\<in>uminus`A. closed a"
hoelzl@54797
  2207
    by auto
wenzelm@60758
  2208
  with \<open>?R\<close> obtain B where "B \<subseteq> A" "finite (uminus`B)" "U \<inter> \<Inter>(uminus`B) = {}"
hoelzl@54797
  2209
    by (metis subset_image_iff)
hoelzl@54797
  2210
  then show "\<exists>T\<subseteq>A. finite T \<and> U \<subseteq> \<Union>T"
wenzelm@63494
  2211
    by (auto intro!: exI[of _ B] inj_setminus dest: finite_imageD)
hoelzl@54797
  2212
qed
hoelzl@54797
  2213
hoelzl@54797
  2214
lemma compact_imp_fip:
wenzelm@63494
  2215
  assumes "compact S"
wenzelm@63494
  2216
    and "\<And>T. T \<in> F \<Longrightarrow> closed T"
wenzelm@63494
  2217
    and "\<And>F'. finite F' \<Longrightarrow> F' \<subseteq> F \<Longrightarrow> S \<inter> (\<Inter>F') \<noteq> {}"
wenzelm@63494
  2218
  shows "S \<inter> (\<Inter>F) \<noteq> {}"
wenzelm@63494
  2219
  using assms unfolding compact_fip by auto
hoelzl@54797
  2220
hoelzl@54797
  2221
lemma compact_imp_fip_image:
haftmann@56166
  2222
  assumes "compact s"
haftmann@56166
  2223
    and P: "\<And>i. i \<in> I \<Longrightarrow> closed (f i)"
haftmann@56166
  2224
    and Q: "\<And>I'. finite I' \<Longrightarrow> I' \<subseteq> I \<Longrightarrow> (s \<inter> (\<Inter>i\<in>I'. f i) \<noteq> {})"
haftmann@56166
  2225
  shows "s \<inter> (\<Inter>i\<in>I. f i) \<noteq> {}"
haftmann@56166
  2226
proof -
wenzelm@60758
  2227
  note \<open>compact s\<close>
wenzelm@63494
  2228
  moreover from P have "\<forall>i \<in> f ` I. closed i"
wenzelm@63494
  2229
    by blast
haftmann@56166
  2230
  moreover have "\<forall>A. finite A \<and> A \<subseteq> f ` I \<longrightarrow> (s \<inter> (\<Inter>A) \<noteq> {})"
wenzelm@63494
  2231
    apply rule
wenzelm@63494
  2232
    apply rule
wenzelm@63494
  2233
    apply (erule conjE)
wenzelm@63494
  2234
  proof -
haftmann@56166
  2235
    fix A :: "'a set set"
wenzelm@63494
  2236
    assume "finite A" and "A \<subseteq> f ` I"
wenzelm@63494
  2237
    then obtain B where "B \<subseteq> I" and "finite B" and "A = f ` B"
haftmann@56166
  2238
      using finite_subset_image [of A f I] by blast
wenzelm@63494
  2239
    with Q [of B] show "s \<inter> \<Inter>A \<noteq> {}"
wenzelm@63494
  2240
      by simp
haftmann@56166
  2241
  qed
wenzelm@63494
  2242
  ultimately have "s \<inter> (\<Inter>(f ` I)) \<noteq> {}"
wenzelm@63494
  2243
    by (metis compact_imp_fip)
haftmann@56166
  2244
  then show ?thesis by simp
haftmann@56166
  2245
qed
hoelzl@54797
  2246
hoelzl@51471
  2247
end
hoelzl@51471
  2248
hoelzl@51481
  2249
lemma (in t2_space) compact_imp_closed:
wenzelm@63494
  2250
  assumes "compact s"
wenzelm@63494
  2251
  shows "closed s"
wenzelm@63494
  2252
  unfolding closed_def
hoelzl@51481
  2253
proof (rule openI)
wenzelm@63494
  2254
  fix y
wenzelm@63494
  2255
  assume "y \<in> - s"
hoelzl@51481
  2256
  let ?C = "\<Union>x\<in>s. {u. open u \<and> x \<in> u \<and> eventually (\<lambda>y. y \<notin> u) (nhds y)}"
lp15@64758
  2257
  have "s \<subseteq> \<Union>?C"
hoelzl@51481
  2258
  proof
wenzelm@63494
  2259
    fix x
wenzelm@63494
  2260
    assume "x \<in> s"
wenzelm@60758
  2261
    with \<open>y \<in> - s\<close> have "x \<noteq> y" by clarsimp
wenzelm@63494
  2262
    then have "\<exists>u v. open u \<and> open v \<and> x \<in> u \<and> y \<in> v \<and> u \<inter> v = {}"
hoelzl@51481
  2263
      by (rule hausdorff)
wenzelm@60758
  2264
    with \<open>x \<in> s\<close> show "x \<in> \<Union>?C"
hoelzl@51481
  2265
      unfolding eventually_nhds by auto
hoelzl@51481
  2266
  qed
lp15@64758
  2267
  then obtain D where "D \<subseteq> ?C" and "finite D" and "s \<subseteq> \<Union>D"
lp15@64758
  2268
    by (rule compactE [OF \<open>compact s\<close>]) auto
wenzelm@63494
  2269
  from \<open>D \<subseteq> ?C\<close> have "\<forall>x\<in>D. eventually (\<lambda>y. y \<notin> x) (nhds y)"
wenzelm@63494
  2270
    by auto
wenzelm@60758
  2271
  with \<open>finite D\<close> have "eventually (\<lambda>y. y \<notin> \<Union>D) (nhds y)"
hoelzl@60040
  2272
    by (simp add: eventually_ball_finite)
wenzelm@60758
  2273
  with \<open>s \<subseteq> \<Union>D\<close> have "eventually (\<lambda>y. y \<notin> s) (nhds y)"
lp15@61810
  2274
    by (auto elim!: eventually_mono)
wenzelm@63494
  2275
  then show "\<exists>t. open t \<and> y \<in> t \<and> t \<subseteq> - s"
hoelzl@51481
  2276
    by (simp add: eventually_nhds subset_eq)
hoelzl@51481
  2277
qed
hoelzl@51481
  2278
hoelzl@51481
  2279
lemma compact_continuous_image:
wenzelm@63494
  2280
  assumes f: "continuous_on s f"
wenzelm@63494
  2281
    and s: "compact s"
hoelzl@51481
  2282
  shows "compact (f ` s)"
hoelzl@51481
  2283
proof (rule compactI)
wenzelm@63494
  2284
  fix C
wenzelm@63494
  2285
  assume "\<forall>c\<in>C. open c" and cover: "f`s \<subseteq> \<Union>C"
hoelzl@51481
  2286
  with f have "\<forall>c\<in>C. \<exists>A. open A \<and> A \<inter> s = f -` c \<inter> s"
hoelzl@51481
  2287
    unfolding continuous_on_open_invariant by blast
wenzelm@53381
  2288
  then obtain A where A: "\<forall>c\<in>C. open (A c) \<and> A c \<inter> s = f -` c \<inter> s"
wenzelm@53381
  2289
    unfolding bchoice_iff ..
hoelzl@51481
  2290
  with cover have "\<forall>c\<in>C. open (A c)" "s \<subseteq> (\<Union>c\<in>C. A c)"
hoelzl@51481
  2291
    by (fastforce simp add: subset_eq set_eq_iff)+
hoelzl@51481
  2292
  from compactE_image[OF s this] obtain D where "D \<subseteq> C" "finite D" "s \<subseteq> (\<Union>c\<in>D. A c)" .
hoelzl@51481
  2293
  with A show "\<exists>D \<subseteq> C. finite D \<and> f`s \<subseteq> \<Union>D"
hoelzl@51481
  2294
    by (intro exI[of _ D]) (fastforce simp add: subset_eq set_eq_iff)+
hoelzl@51481
  2295
qed
hoelzl@51481
  2296
hoelzl@51481
  2297
lemma continuous_on_inv:
hoelzl@51481
  2298
  fixes f :: "'a::topological_space \<Rightarrow> 'b::t2_space"
wenzelm@63494
  2299
  assumes "continuous_on s f"
wenzelm@63494
  2300
    and "compact s"
wenzelm@63494
  2301
    and "\<forall>x\<in>s. g (f x) = x"
hoelzl@51481
  2302
  shows "continuous_on (f ` s) g"
wenzelm@63494
  2303
  unfolding continuous_on_topological
hoelzl@51481
  2304
proof (clarsimp simp add: assms(3))
hoelzl@51481
  2305
  fix x :: 'a and B :: "'a set"
hoelzl@51481
  2306
  assume "x \<in> s" and "open B" and "x \<in> B"
hoelzl@51481
  2307
  have 1: "\<forall>x\<in>s. f x \<in> f ` (s - B) \<longleftrightarrow> x \<in> s - B"
hoelzl@51481
  2308
    using assms(3) by (auto, metis)
hoelzl@51481
  2309
  have "continuous_on (s - B) f"
wenzelm@60758
  2310
    using \<open>continuous_on s f\<close> Diff_subset
hoelzl@51481
  2311
    by (rule continuous_on_subset)
hoelzl@51481
  2312
  moreover have "compact (s - B)"
wenzelm@60758
  2313
    using \<open>open B\<close> and \<open>compact s\<close>
lp15@62843
  2314
    unfolding Diff_eq by (intro compact_Int_closed closed_Compl)
hoelzl@51481
  2315
  ultimately have "compact (f ` (s - B))"
hoelzl@51481
  2316
    by (rule compact_continuous_image)
wenzelm@63494
  2317
  then have "closed (f ` (s - B))"
hoelzl@51481
  2318
    by (rule compact_imp_closed)
wenzelm@63494
  2319
  then have "open (- f ` (s - B))"
hoelzl@51481
  2320
    by (rule open_Compl)
hoelzl@51481
  2321
  moreover have "f x \<in> - f ` (s - B)"
wenzelm@60758
  2322
    using \<open>x \<in> s\<close> and \<open>x \<in> B\<close> by (simp add: 1)
hoelzl@51481
  2323
  moreover have "\<forall>y\<in>s. f y \<in> - f ` (s - B) \<longrightarrow> y \<in> B"
hoelzl@51481
  2324
    by (simp add: 1)
hoelzl@51481
  2325
  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
  2326
    by fast
hoelzl@51481
  2327
qed
hoelzl@51481
  2328
hoelzl@51481
  2329
lemma continuous_on_inv_into:
hoelzl@51481
  2330
  fixes f :: "'a::topological_space \<Rightarrow> 'b::t2_space"
wenzelm@63494
  2331
  assumes s: "continuous_on s f" "compact s"
wenzelm@63494
  2332
    and f: "inj_on f s"
hoelzl@51481
  2333
  shows "continuous_on (f ` s) (the_inv_into s f)"
hoelzl@51481
  2334
  by (rule continuous_on_inv[OF s]) (auto simp: the_inv_into_f_f[OF f])
hoelzl@51481
  2335
hoelzl@51479
  2336
lemma (in linorder_topology) compact_attains_sup:
hoelzl@51479
  2337
  assumes "compact S" "S \<noteq> {}"
hoelzl@51479
  2338
  shows "\<exists>s\<in>S. \<forall>t\<in>S. t \<le> s"
hoelzl@51479
  2339
proof (rule classical)
hoelzl@51479
  2340
  assume "\<not> (\<exists>s\<in>S. \<forall>t\<in>S. t \<le> s)"
hoelzl@51479
  2341
  then obtain t where t: "\<forall>s\<in>S. t s \<in> S" and "\<forall>s\<in>S. s < t s"
hoelzl@51479
  2342
    by (metis not_le)
hoelzl@51479
  2343
  then have "\<forall>s\<in>S. open {..< t s}" "S \<subseteq> (\<Union>s\<in>S. {..< t s})"
hoelzl@51479
  2344
    by auto
wenzelm@60758
  2345
  with \<open>compact S\<close> obtain C where "C \<subseteq> S" "finite C" and C: "S \<subseteq> (\<Union>s\<in>C. {..< t s})"
hoelzl@51479
  2346
    by (erule compactE_image)
wenzelm@60758
  2347
  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
  2348
    by (auto intro!: Max_in)
hoelzl@51479
  2349
  with C have "S \<subseteq> {..< Max (t`C)}"
hoelzl@51479
  2350
    by (auto intro: less_le_trans simp: subset_eq)
wenzelm@60758
  2351
  with t Max \<open>C \<subseteq> S\<close> show ?thesis
hoelzl@51479
  2352
    by fastforce
hoelzl@51479
  2353
qed
hoelzl@51479
  2354
hoelzl@51479
  2355
lemma (in linorder_topology) compact_attains_inf:
hoelzl@51479
  2356
  assumes "compact S" "S \<noteq> {}"
hoelzl@51479
  2357
  shows "\<exists>s\<in>S. \<forall>t\<in>S. s \<le> t"
hoelzl@51479
  2358
proof (rule classical)
hoelzl@51479
  2359
  assume "\<not> (\<exists>s\<in>S. \<forall>t\<in>S. s \<le> t)"
hoelzl@51479
  2360
  then obtain t where t: "\<forall>s\<in>S. t s \<in> S" and "\<forall>s\<in>S. t s < s"
hoelzl@51479
  2361
    by (metis not_le)
hoelzl@51479
  2362
  then have "\<forall>s\<in>S. open {t s <..}" "S \<subseteq> (\<Union>s\<in>S. {t s <..})"
hoelzl@51479
  2363
    by auto
wenzelm@60758
  2364
  with \<open>compact S\<close> obtain C where "C \<subseteq> S" "finite C" and C: "S \<subseteq> (\<Union>s\<in>C. {t s <..})"
hoelzl@51479
  2365
    by (erule compactE_image)
wenzelm@60758
  2366
  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
  2367
    by (auto intro!: Min_in)
hoelzl@51479
  2368
  with C have "S \<subseteq> {Min (t`C) <..}"
hoelzl@51479
  2369
    by (auto intro: le_less_trans simp: subset_eq)
wenzelm@60758
  2370
  with t Min \<open>C \<subseteq> S\<close> show ?thesis
hoelzl@51479
  2371
    by fastforce
hoelzl@51479
  2372
qed
hoelzl@51479
  2373
hoelzl@51479
  2374
lemma continuous_attains_sup:
hoelzl@51479
  2375
  fixes f :: "'a::topological_space \<Rightarrow> 'b::linorder_topology"
hoelzl@51479
  2376
  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
  2377
  using compact_attains_sup[of "f ` s"] compact_continuous_image[of s f] by auto
hoelzl@51479
  2378
hoelzl@51479
  2379
lemma continuous_attains_inf:
hoelzl@51479
  2380
  fixes f :: "'a::topological_space \<Rightarrow> 'b::linorder_topology"
hoelzl@51479
  2381
  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
  2382
  using compact_attains_inf[of "f ` s"] compact_continuous_image[of s f] by auto
hoelzl@51479
  2383
wenzelm@63494
  2384
wenzelm@60758
  2385
subsection \<open>Connectedness\<close