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