src/HOL/Topological_Spaces.thy
author wenzelm
Wed Apr 08 19:39:08 2015 +0200 (2015-04-08)
changeset 59970 e9f73d87d904
parent 59582 0fbed69ff081
child 59971 ea06500bb092
permissions -rw-r--r--
proper context for Object_Logic operations;
     1 (*  Title:      HOL/Topological_Spaces.thy
     2     Author:     Brian Huffman
     3     Author:     Johannes Hölzl
     4 *)
     5 
     6 section {* Topological Spaces *}
     7 
     8 theory Topological_Spaces
     9 imports Main Conditionally_Complete_Lattices
    10 begin
    11 
    12 named_theorems continuous_intros "structural introduction rules for continuity"
    13 
    14 
    15 subsection {* Topological space *}
    16 
    17 class "open" =
    18   fixes "open" :: "'a set \<Rightarrow> bool"
    19 
    20 class topological_space = "open" +
    21   assumes open_UNIV [simp, intro]: "open UNIV"
    22   assumes open_Int [intro]: "open S \<Longrightarrow> open T \<Longrightarrow> open (S \<inter> T)"
    23   assumes open_Union [intro]: "\<forall>S\<in>K. open S \<Longrightarrow> open (\<Union> K)"
    24 begin
    25 
    26 definition
    27   closed :: "'a set \<Rightarrow> bool" where
    28   "closed S \<longleftrightarrow> open (- S)"
    29 
    30 lemma open_empty [continuous_intros, intro, simp]: "open {}"
    31   using open_Union [of "{}"] by simp
    32 
    33 lemma open_Un [continuous_intros, intro]: "open S \<Longrightarrow> open T \<Longrightarrow> open (S \<union> T)"
    34   using open_Union [of "{S, T}"] by simp
    35 
    36 lemma open_UN [continuous_intros, intro]: "\<forall>x\<in>A. open (B x) \<Longrightarrow> open (\<Union>x\<in>A. B x)"
    37   using open_Union [of "B ` A"] by simp
    38 
    39 lemma open_Inter [continuous_intros, intro]: "finite S \<Longrightarrow> \<forall>T\<in>S. open T \<Longrightarrow> open (\<Inter>S)"
    40   by (induct set: finite) auto
    41 
    42 lemma open_INT [continuous_intros, intro]: "finite A \<Longrightarrow> \<forall>x\<in>A. open (B x) \<Longrightarrow> open (\<Inter>x\<in>A. B x)"
    43   using open_Inter [of "B ` A"] by simp
    44 
    45 lemma openI:
    46   assumes "\<And>x. x \<in> S \<Longrightarrow> \<exists>T. open T \<and> x \<in> T \<and> T \<subseteq> S"
    47   shows "open S"
    48 proof -
    49   have "open (\<Union>{T. open T \<and> T \<subseteq> S})" by auto
    50   moreover have "\<Union>{T. open T \<and> T \<subseteq> S} = S" by (auto dest!: assms)
    51   ultimately show "open S" by simp
    52 qed
    53 
    54 lemma closed_empty [continuous_intros, intro, simp]:  "closed {}"
    55   unfolding closed_def by simp
    56 
    57 lemma closed_Un [continuous_intros, intro]: "closed S \<Longrightarrow> closed T \<Longrightarrow> closed (S \<union> T)"
    58   unfolding closed_def by auto
    59 
    60 lemma closed_UNIV [continuous_intros, intro, simp]: "closed UNIV"
    61   unfolding closed_def by simp
    62 
    63 lemma closed_Int [continuous_intros, intro]: "closed S \<Longrightarrow> closed T \<Longrightarrow> closed (S \<inter> T)"
    64   unfolding closed_def by auto
    65 
    66 lemma closed_INT [continuous_intros, intro]: "\<forall>x\<in>A. closed (B x) \<Longrightarrow> closed (\<Inter>x\<in>A. B x)"
    67   unfolding closed_def by auto
    68 
    69 lemma closed_Inter [continuous_intros, intro]: "\<forall>S\<in>K. closed S \<Longrightarrow> closed (\<Inter> K)"
    70   unfolding closed_def uminus_Inf by auto
    71 
    72 lemma closed_Union [continuous_intros, intro]: "finite S \<Longrightarrow> \<forall>T\<in>S. closed T \<Longrightarrow> closed (\<Union>S)"
    73   by (induct set: finite) auto
    74 
    75 lemma closed_UN [continuous_intros, intro]: "finite A \<Longrightarrow> \<forall>x\<in>A. closed (B x) \<Longrightarrow> closed (\<Union>x\<in>A. B x)"
    76   using closed_Union [of "B ` A"] by simp
    77 
    78 lemma open_closed: "open S \<longleftrightarrow> closed (- S)"
    79   unfolding closed_def by simp
    80 
    81 lemma closed_open: "closed S \<longleftrightarrow> open (- S)"
    82   unfolding closed_def by simp
    83 
    84 lemma open_Diff [continuous_intros, intro]: "open S \<Longrightarrow> closed T \<Longrightarrow> open (S - T)"
    85   unfolding closed_open Diff_eq by (rule open_Int)
    86 
    87 lemma closed_Diff [continuous_intros, intro]: "closed S \<Longrightarrow> open T \<Longrightarrow> closed (S - T)"
    88   unfolding open_closed Diff_eq by (rule closed_Int)
    89 
    90 lemma open_Compl [continuous_intros, intro]: "closed S \<Longrightarrow> open (- S)"
    91   unfolding closed_open .
    92 
    93 lemma closed_Compl [continuous_intros, intro]: "open S \<Longrightarrow> closed (- S)"
    94   unfolding open_closed .
    95 
    96 lemma open_Collect_neg: "closed {x. P x} \<Longrightarrow> open {x. \<not> P x}"
    97   unfolding Collect_neg_eq by (rule open_Compl)
    98 
    99 lemma open_Collect_conj: assumes "open {x. P x}" "open {x. Q x}" shows "open {x. P x \<and> Q x}"
   100   using open_Int[OF assms] by (simp add: Int_def)
   101 
   102 lemma open_Collect_disj: assumes "open {x. P x}" "open {x. Q x}" shows "open {x. P x \<or> Q x}"
   103   using open_Un[OF assms] by (simp add: Un_def)
   104 
   105 lemma open_Collect_ex: "(\<And>i. open {x. P i x}) \<Longrightarrow> open {x. \<exists>i. P i x}"
   106   using open_UN[of UNIV "\<lambda>i. {x. P i x}"] unfolding Collect_ex_eq by simp 
   107 
   108 lemma open_Collect_imp: "closed {x. P x} \<Longrightarrow> open {x. Q x} \<Longrightarrow> open {x. P x \<longrightarrow> Q x}"
   109   unfolding imp_conv_disj by (intro open_Collect_disj open_Collect_neg)
   110 
   111 lemma open_Collect_const: "open {x. P}"
   112   by (cases P) auto
   113 
   114 lemma closed_Collect_neg: "open {x. P x} \<Longrightarrow> closed {x. \<not> P x}"
   115   unfolding Collect_neg_eq by (rule closed_Compl)
   116 
   117 lemma closed_Collect_conj: assumes "closed {x. P x}" "closed {x. Q x}" shows "closed {x. P x \<and> Q x}"
   118   using closed_Int[OF assms] by (simp add: Int_def)
   119 
   120 lemma closed_Collect_disj: assumes "closed {x. P x}" "closed {x. Q x}" shows "closed {x. P x \<or> Q x}"
   121   using closed_Un[OF assms] by (simp add: Un_def)
   122 
   123 lemma closed_Collect_all: "(\<And>i. closed {x. P i x}) \<Longrightarrow> closed {x. \<forall>i. P i x}"
   124   using closed_INT[of UNIV "\<lambda>i. {x. P i x}"] unfolding Collect_all_eq by simp 
   125 
   126 lemma closed_Collect_imp: "open {x. P x} \<Longrightarrow> closed {x. Q x} \<Longrightarrow> closed {x. P x \<longrightarrow> Q x}"
   127   unfolding imp_conv_disj by (intro closed_Collect_disj closed_Collect_neg)
   128 
   129 lemma closed_Collect_const: "closed {x. P}"
   130   by (cases P) auto
   131 
   132 end
   133 
   134 subsection{* Hausdorff and other separation properties *}
   135 
   136 class t0_space = topological_space +
   137   assumes t0_space: "x \<noteq> y \<Longrightarrow> \<exists>U. open U \<and> \<not> (x \<in> U \<longleftrightarrow> y \<in> U)"
   138 
   139 class t1_space = topological_space +
   140   assumes t1_space: "x \<noteq> y \<Longrightarrow> \<exists>U. open U \<and> x \<in> U \<and> y \<notin> U"
   141 
   142 instance t1_space \<subseteq> t0_space
   143 proof qed (fast dest: t1_space)
   144 
   145 lemma separation_t1:
   146   fixes x y :: "'a::t1_space"
   147   shows "x \<noteq> y \<longleftrightarrow> (\<exists>U. open U \<and> x \<in> U \<and> y \<notin> U)"
   148   using t1_space[of x y] by blast
   149 
   150 lemma closed_singleton:
   151   fixes a :: "'a::t1_space"
   152   shows "closed {a}"
   153 proof -
   154   let ?T = "\<Union>{S. open S \<and> a \<notin> S}"
   155   have "open ?T" by (simp add: open_Union)
   156   also have "?T = - {a}"
   157     by (simp add: set_eq_iff separation_t1, auto)
   158   finally show "closed {a}" unfolding closed_def .
   159 qed
   160 
   161 lemma closed_insert [continuous_intros, simp]:
   162   fixes a :: "'a::t1_space"
   163   assumes "closed S" shows "closed (insert a S)"
   164 proof -
   165   from closed_singleton assms
   166   have "closed ({a} \<union> S)" by (rule closed_Un)
   167   thus "closed (insert a S)" by simp
   168 qed
   169 
   170 lemma finite_imp_closed:
   171   fixes S :: "'a::t1_space set"
   172   shows "finite S \<Longrightarrow> closed S"
   173 by (induct set: finite, simp_all)
   174 
   175 text {* T2 spaces are also known as Hausdorff spaces. *}
   176 
   177 class t2_space = topological_space +
   178   assumes hausdorff: "x \<noteq> y \<Longrightarrow> \<exists>U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {}"
   179 
   180 instance t2_space \<subseteq> t1_space
   181 proof qed (fast dest: hausdorff)
   182 
   183 lemma separation_t2:
   184   fixes x y :: "'a::t2_space"
   185   shows "x \<noteq> y \<longleftrightarrow> (\<exists>U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {})"
   186   using hausdorff[of x y] by blast
   187 
   188 lemma separation_t0:
   189   fixes x y :: "'a::t0_space"
   190   shows "x \<noteq> y \<longleftrightarrow> (\<exists>U. open U \<and> ~(x\<in>U \<longleftrightarrow> y\<in>U))"
   191   using t0_space[of x y] by blast
   192 
   193 text {* A perfect space is a topological space with no isolated points. *}
   194 
   195 class perfect_space = topological_space +
   196   assumes not_open_singleton: "\<not> open {x}"
   197 
   198 
   199 subsection {* Generators for toplogies *}
   200 
   201 inductive generate_topology for S where
   202   UNIV: "generate_topology S UNIV"
   203 | Int: "generate_topology S a \<Longrightarrow> generate_topology S b \<Longrightarrow> generate_topology S (a \<inter> b)"
   204 | UN: "(\<And>k. k \<in> K \<Longrightarrow> generate_topology S k) \<Longrightarrow> generate_topology S (\<Union>K)"
   205 | Basis: "s \<in> S \<Longrightarrow> generate_topology S s"
   206 
   207 hide_fact (open) UNIV Int UN Basis 
   208 
   209 lemma generate_topology_Union: 
   210   "(\<And>k. k \<in> I \<Longrightarrow> generate_topology S (K k)) \<Longrightarrow> generate_topology S (\<Union>k\<in>I. K k)"
   211   using generate_topology.UN [of "K ` I"] by auto
   212 
   213 lemma topological_space_generate_topology:
   214   "class.topological_space (generate_topology S)"
   215   by default (auto intro: generate_topology.intros)
   216 
   217 subsection {* Order topologies *}
   218 
   219 class order_topology = order + "open" +
   220   assumes open_generated_order: "open = generate_topology (range (\<lambda>a. {..< a}) \<union> range (\<lambda>a. {a <..}))"
   221 begin
   222 
   223 subclass topological_space
   224   unfolding open_generated_order
   225   by (rule topological_space_generate_topology)
   226 
   227 lemma open_greaterThan [continuous_intros, simp]: "open {a <..}"
   228   unfolding open_generated_order by (auto intro: generate_topology.Basis)
   229 
   230 lemma open_lessThan [continuous_intros, simp]: "open {..< a}"
   231   unfolding open_generated_order by (auto intro: generate_topology.Basis)
   232 
   233 lemma open_greaterThanLessThan [continuous_intros, simp]: "open {a <..< b}"
   234    unfolding greaterThanLessThan_eq by (simp add: open_Int)
   235 
   236 end
   237 
   238 class linorder_topology = linorder + order_topology
   239 
   240 lemma closed_atMost [continuous_intros, simp]: "closed {.. a::'a::linorder_topology}"
   241   by (simp add: closed_open)
   242 
   243 lemma closed_atLeast [continuous_intros, simp]: "closed {a::'a::linorder_topology ..}"
   244   by (simp add: closed_open)
   245 
   246 lemma closed_atLeastAtMost [continuous_intros, simp]: "closed {a::'a::linorder_topology .. b}"
   247 proof -
   248   have "{a .. b} = {a ..} \<inter> {.. b}"
   249     by auto
   250   then show ?thesis
   251     by (simp add: closed_Int)
   252 qed
   253 
   254 lemma (in linorder) less_separate:
   255   assumes "x < y"
   256   shows "\<exists>a b. x \<in> {..< a} \<and> y \<in> {b <..} \<and> {..< a} \<inter> {b <..} = {}"
   257 proof (cases "\<exists>z. x < z \<and> z < y")
   258   case True
   259   then obtain z where "x < z \<and> z < y" ..
   260   then have "x \<in> {..< z} \<and> y \<in> {z <..} \<and> {z <..} \<inter> {..< z} = {}"
   261     by auto
   262   then show ?thesis by blast
   263 next
   264   case False
   265   with `x < y` have "x \<in> {..< y} \<and> y \<in> {x <..} \<and> {x <..} \<inter> {..< y} = {}"
   266     by auto
   267   then show ?thesis by blast
   268 qed
   269 
   270 instance linorder_topology \<subseteq> t2_space
   271 proof
   272   fix x y :: 'a
   273   from less_separate[of x y] less_separate[of y x]
   274   show "x \<noteq> y \<Longrightarrow> \<exists>U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {}"
   275     by (elim neqE) (metis open_lessThan open_greaterThan Int_commute)+
   276 qed
   277 
   278 lemma (in linorder_topology) open_right:
   279   assumes "open S" "x \<in> S" and gt_ex: "x < y" shows "\<exists>b>x. {x ..< b} \<subseteq> S"
   280   using assms unfolding open_generated_order
   281 proof induction
   282   case (Int A B)
   283   then obtain a b where "a > x" "{x ..< a} \<subseteq> A"  "b > x" "{x ..< b} \<subseteq> B" by auto
   284   then show ?case by (auto intro!: exI[of _ "min a b"])
   285 next
   286   case (Basis S) then show ?case by (fastforce intro: exI[of _ y] gt_ex)
   287 qed blast+
   288 
   289 lemma (in linorder_topology) open_left:
   290   assumes "open S" "x \<in> S" and lt_ex: "y < x" shows "\<exists>b<x. {b <.. x} \<subseteq> S"
   291   using assms unfolding open_generated_order
   292 proof induction
   293   case (Int A B)
   294   then obtain a b where "a < x" "{a <.. x} \<subseteq> A"  "b < x" "{b <.. x} \<subseteq> B" by auto
   295   then show ?case by (auto intro!: exI[of _ "max a b"])
   296 next
   297   case (Basis S) then show ?case by (fastforce intro: exI[of _ y] lt_ex)
   298 qed blast+
   299 
   300 subsubsection {* Boolean is an order topology *}
   301 
   302 text {* It also is a discrete topology, but don't have a type class for it (yet). *}
   303 
   304 instantiation bool :: order_topology
   305 begin
   306 
   307 definition open_bool :: "bool set \<Rightarrow> bool" where
   308   "open_bool = generate_topology (range (\<lambda>a. {..< a}) \<union> range (\<lambda>a. {a <..}))"
   309 
   310 instance
   311   proof qed (rule open_bool_def)
   312 
   313 end
   314 
   315 lemma open_bool[simp, intro!]: "open (A::bool set)"
   316 proof -
   317   have *: "{False <..} = {True}" "{..< True} = {False}"
   318     by auto
   319   have "A = UNIV \<or> A = {} \<or> A = {False <..} \<or> A = {..< True}"
   320     using subset_UNIV[of A] unfolding UNIV_bool * by auto
   321   then show "open A"
   322     by auto
   323 qed
   324 
   325 subsection {* Filters *}
   326 
   327 text {*
   328   This definition also allows non-proper filters.
   329 *}
   330 
   331 locale is_filter =
   332   fixes F :: "('a \<Rightarrow> bool) \<Rightarrow> bool"
   333   assumes True: "F (\<lambda>x. True)"
   334   assumes conj: "F (\<lambda>x. P x) \<Longrightarrow> F (\<lambda>x. Q x) \<Longrightarrow> F (\<lambda>x. P x \<and> Q x)"
   335   assumes mono: "\<forall>x. P x \<longrightarrow> Q x \<Longrightarrow> F (\<lambda>x. P x) \<Longrightarrow> F (\<lambda>x. Q x)"
   336 
   337 typedef 'a filter = "{F :: ('a \<Rightarrow> bool) \<Rightarrow> bool. is_filter F}"
   338 proof
   339   show "(\<lambda>x. True) \<in> ?filter" by (auto intro: is_filter.intro)
   340 qed
   341 
   342 lemma is_filter_Rep_filter: "is_filter (Rep_filter F)"
   343   using Rep_filter [of F] by simp
   344 
   345 lemma Abs_filter_inverse':
   346   assumes "is_filter F" shows "Rep_filter (Abs_filter F) = F"
   347   using assms by (simp add: Abs_filter_inverse)
   348 
   349 
   350 subsubsection {* Eventually *}
   351 
   352 definition eventually :: "('a \<Rightarrow> bool) \<Rightarrow> 'a filter \<Rightarrow> bool"
   353   where "eventually P F \<longleftrightarrow> Rep_filter F P"
   354 
   355 lemma eventually_Abs_filter:
   356   assumes "is_filter F" shows "eventually P (Abs_filter F) = F P"
   357   unfolding eventually_def using assms by (simp add: Abs_filter_inverse)
   358 
   359 lemma filter_eq_iff:
   360   shows "F = F' \<longleftrightarrow> (\<forall>P. eventually P F = eventually P F')"
   361   unfolding Rep_filter_inject [symmetric] fun_eq_iff eventually_def ..
   362 
   363 lemma eventually_True [simp]: "eventually (\<lambda>x. True) F"
   364   unfolding eventually_def
   365   by (rule is_filter.True [OF is_filter_Rep_filter])
   366 
   367 lemma always_eventually: "\<forall>x. P x \<Longrightarrow> eventually P F"
   368 proof -
   369   assume "\<forall>x. P x" hence "P = (\<lambda>x. True)" by (simp add: ext)
   370   thus "eventually P F" by simp
   371 qed
   372 
   373 lemma eventually_mono:
   374   "(\<forall>x. P x \<longrightarrow> Q x) \<Longrightarrow> eventually P F \<Longrightarrow> eventually Q F"
   375   unfolding eventually_def
   376   by (rule is_filter.mono [OF is_filter_Rep_filter])
   377 
   378 lemma eventually_conj:
   379   assumes P: "eventually (\<lambda>x. P x) F"
   380   assumes Q: "eventually (\<lambda>x. Q x) F"
   381   shows "eventually (\<lambda>x. P x \<and> Q x) F"
   382   using assms unfolding eventually_def
   383   by (rule is_filter.conj [OF is_filter_Rep_filter])
   384 
   385 lemma eventually_Ball_finite:
   386   assumes "finite A" and "\<forall>y\<in>A. eventually (\<lambda>x. P x y) net"
   387   shows "eventually (\<lambda>x. \<forall>y\<in>A. P x y) net"
   388 using assms by (induct set: finite, simp, simp add: eventually_conj)
   389 
   390 lemma eventually_all_finite:
   391   fixes P :: "'a \<Rightarrow> 'b::finite \<Rightarrow> bool"
   392   assumes "\<And>y. eventually (\<lambda>x. P x y) net"
   393   shows "eventually (\<lambda>x. \<forall>y. P x y) net"
   394 using eventually_Ball_finite [of UNIV P] assms by simp
   395 
   396 lemma eventually_mp:
   397   assumes "eventually (\<lambda>x. P x \<longrightarrow> Q x) F"
   398   assumes "eventually (\<lambda>x. P x) F"
   399   shows "eventually (\<lambda>x. Q x) F"
   400 proof (rule eventually_mono)
   401   show "\<forall>x. (P x \<longrightarrow> Q x) \<and> P x \<longrightarrow> Q x" by simp
   402   show "eventually (\<lambda>x. (P x \<longrightarrow> Q x) \<and> P x) F"
   403     using assms by (rule eventually_conj)
   404 qed
   405 
   406 lemma eventually_rev_mp:
   407   assumes "eventually (\<lambda>x. P x) F"
   408   assumes "eventually (\<lambda>x. P x \<longrightarrow> Q x) F"
   409   shows "eventually (\<lambda>x. Q x) F"
   410 using assms(2) assms(1) by (rule eventually_mp)
   411 
   412 lemma eventually_conj_iff:
   413   "eventually (\<lambda>x. P x \<and> Q x) F \<longleftrightarrow> eventually P F \<and> eventually Q F"
   414   by (auto intro: eventually_conj elim: eventually_rev_mp)
   415 
   416 lemma eventually_elim1:
   417   assumes "eventually (\<lambda>i. P i) F"
   418   assumes "\<And>i. P i \<Longrightarrow> Q i"
   419   shows "eventually (\<lambda>i. Q i) F"
   420   using assms by (auto elim!: eventually_rev_mp)
   421 
   422 lemma eventually_elim2:
   423   assumes "eventually (\<lambda>i. P i) F"
   424   assumes "eventually (\<lambda>i. Q i) F"
   425   assumes "\<And>i. P i \<Longrightarrow> Q i \<Longrightarrow> R i"
   426   shows "eventually (\<lambda>i. R i) F"
   427   using assms by (auto elim!: eventually_rev_mp)
   428 
   429 lemma not_eventually_impI: "eventually P F \<Longrightarrow> \<not> eventually Q F \<Longrightarrow> \<not> eventually (\<lambda>x. P x \<longrightarrow> Q x) F"
   430   by (auto intro: eventually_mp)
   431 
   432 lemma not_eventuallyD: "\<not> eventually P F \<Longrightarrow> \<exists>x. \<not> P x"
   433   by (metis always_eventually)
   434 
   435 lemma eventually_subst:
   436   assumes "eventually (\<lambda>n. P n = Q n) F"
   437   shows "eventually P F = eventually Q F" (is "?L = ?R")
   438 proof -
   439   from assms have "eventually (\<lambda>x. P x \<longrightarrow> Q x) F"
   440       and "eventually (\<lambda>x. Q x \<longrightarrow> P x) F"
   441     by (auto elim: eventually_elim1)
   442   then show ?thesis by (auto elim: eventually_elim2)
   443 qed
   444 
   445 ML {*
   446   fun eventually_elim_tac ctxt thms = SUBGOAL_CASES (fn (_, _, st) =>
   447     let
   448       val mp_thms = thms RL [@{thm eventually_rev_mp}]
   449       val raw_elim_thm =
   450         (@{thm allI} RS @{thm always_eventually})
   451         |> fold (fn thm1 => fn thm2 => thm2 RS thm1) mp_thms
   452         |> fold (fn _ => fn thm => @{thm impI} RS thm) thms
   453       val cases_prop = Thm.prop_of (raw_elim_thm RS st)
   454       val cases = Rule_Cases.make_common ctxt cases_prop [(("elim", []), [])]
   455     in
   456       CASES cases (rtac raw_elim_thm 1)
   457     end) 1
   458 *}
   459 
   460 method_setup eventually_elim = {*
   461   Scan.succeed (fn ctxt => METHOD_CASES (eventually_elim_tac ctxt))
   462 *} "elimination of eventually quantifiers"
   463 
   464 
   465 subsubsection {* Finer-than relation *}
   466 
   467 text {* @{term "F \<le> F'"} means that filter @{term F} is finer than
   468 filter @{term F'}. *}
   469 
   470 instantiation filter :: (type) complete_lattice
   471 begin
   472 
   473 definition le_filter_def:
   474   "F \<le> F' \<longleftrightarrow> (\<forall>P. eventually P F' \<longrightarrow> eventually P F)"
   475 
   476 definition
   477   "(F :: 'a filter) < F' \<longleftrightarrow> F \<le> F' \<and> \<not> F' \<le> F"
   478 
   479 definition
   480   "top = Abs_filter (\<lambda>P. \<forall>x. P x)"
   481 
   482 definition
   483   "bot = Abs_filter (\<lambda>P. True)"
   484 
   485 definition
   486   "sup F F' = Abs_filter (\<lambda>P. eventually P F \<and> eventually P F')"
   487 
   488 definition
   489   "inf F F' = Abs_filter
   490       (\<lambda>P. \<exists>Q R. eventually Q F \<and> eventually R F' \<and> (\<forall>x. Q x \<and> R x \<longrightarrow> P x))"
   491 
   492 definition
   493   "Sup S = Abs_filter (\<lambda>P. \<forall>F\<in>S. eventually P F)"
   494 
   495 definition
   496   "Inf S = Sup {F::'a filter. \<forall>F'\<in>S. F \<le> F'}"
   497 
   498 lemma eventually_top [simp]: "eventually P top \<longleftrightarrow> (\<forall>x. P x)"
   499   unfolding top_filter_def
   500   by (rule eventually_Abs_filter, rule is_filter.intro, auto)
   501 
   502 lemma eventually_bot [simp]: "eventually P bot"
   503   unfolding bot_filter_def
   504   by (subst eventually_Abs_filter, rule is_filter.intro, auto)
   505 
   506 lemma eventually_sup:
   507   "eventually P (sup F F') \<longleftrightarrow> eventually P F \<and> eventually P F'"
   508   unfolding sup_filter_def
   509   by (rule eventually_Abs_filter, rule is_filter.intro)
   510      (auto elim!: eventually_rev_mp)
   511 
   512 lemma eventually_inf:
   513   "eventually P (inf F F') \<longleftrightarrow>
   514    (\<exists>Q R. eventually Q F \<and> eventually R F' \<and> (\<forall>x. Q x \<and> R x \<longrightarrow> P x))"
   515   unfolding inf_filter_def
   516   apply (rule eventually_Abs_filter, rule is_filter.intro)
   517   apply (fast intro: eventually_True)
   518   apply clarify
   519   apply (intro exI conjI)
   520   apply (erule (1) eventually_conj)
   521   apply (erule (1) eventually_conj)
   522   apply simp
   523   apply auto
   524   done
   525 
   526 lemma eventually_Sup:
   527   "eventually P (Sup S) \<longleftrightarrow> (\<forall>F\<in>S. eventually P F)"
   528   unfolding Sup_filter_def
   529   apply (rule eventually_Abs_filter, rule is_filter.intro)
   530   apply (auto intro: eventually_conj elim!: eventually_rev_mp)
   531   done
   532 
   533 instance proof
   534   fix F F' F'' :: "'a filter" and S :: "'a filter set"
   535   { show "F < F' \<longleftrightarrow> F \<le> F' \<and> \<not> F' \<le> F"
   536     by (rule less_filter_def) }
   537   { show "F \<le> F"
   538     unfolding le_filter_def by simp }
   539   { assume "F \<le> F'" and "F' \<le> F''" thus "F \<le> F''"
   540     unfolding le_filter_def by simp }
   541   { assume "F \<le> F'" and "F' \<le> F" thus "F = F'"
   542     unfolding le_filter_def filter_eq_iff by fast }
   543   { show "inf F F' \<le> F" and "inf F F' \<le> F'"
   544     unfolding le_filter_def eventually_inf by (auto intro: eventually_True) }
   545   { assume "F \<le> F'" and "F \<le> F''" thus "F \<le> inf F' F''"
   546     unfolding le_filter_def eventually_inf
   547     by (auto elim!: eventually_mono intro: eventually_conj) }
   548   { show "F \<le> sup F F'" and "F' \<le> sup F F'"
   549     unfolding le_filter_def eventually_sup by simp_all }
   550   { assume "F \<le> F''" and "F' \<le> F''" thus "sup F F' \<le> F''"
   551     unfolding le_filter_def eventually_sup by simp }
   552   { assume "F'' \<in> S" thus "Inf S \<le> F''"
   553     unfolding le_filter_def Inf_filter_def eventually_Sup Ball_def by simp }
   554   { assume "\<And>F'. F' \<in> S \<Longrightarrow> F \<le> F'" thus "F \<le> Inf S"
   555     unfolding le_filter_def Inf_filter_def eventually_Sup Ball_def by simp }
   556   { assume "F \<in> S" thus "F \<le> Sup S"
   557     unfolding le_filter_def eventually_Sup by simp }
   558   { assume "\<And>F. F \<in> S \<Longrightarrow> F \<le> F'" thus "Sup S \<le> F'"
   559     unfolding le_filter_def eventually_Sup by simp }
   560   { show "Inf {} = (top::'a filter)"
   561     by (auto simp: top_filter_def Inf_filter_def Sup_filter_def)
   562       (metis (full_types) top_filter_def always_eventually eventually_top) }
   563   { show "Sup {} = (bot::'a filter)"
   564     by (auto simp: bot_filter_def Sup_filter_def) }
   565 qed
   566 
   567 end
   568 
   569 lemma filter_leD:
   570   "F \<le> F' \<Longrightarrow> eventually P F' \<Longrightarrow> eventually P F"
   571   unfolding le_filter_def by simp
   572 
   573 lemma filter_leI:
   574   "(\<And>P. eventually P F' \<Longrightarrow> eventually P F) \<Longrightarrow> F \<le> F'"
   575   unfolding le_filter_def by simp
   576 
   577 lemma eventually_False:
   578   "eventually (\<lambda>x. False) F \<longleftrightarrow> F = bot"
   579   unfolding filter_eq_iff by (auto elim: eventually_rev_mp)
   580 
   581 abbreviation (input) trivial_limit :: "'a filter \<Rightarrow> bool"
   582   where "trivial_limit F \<equiv> F = bot"
   583 
   584 lemma trivial_limit_def: "trivial_limit F \<longleftrightarrow> eventually (\<lambda>x. False) F"
   585   by (rule eventually_False [symmetric])
   586 
   587 lemma eventually_const: "\<not> trivial_limit net \<Longrightarrow> eventually (\<lambda>x. P) net \<longleftrightarrow> P"
   588   by (cases P) (simp_all add: eventually_False)
   589 
   590 lemma eventually_Inf: "eventually P (Inf B) \<longleftrightarrow> (\<exists>X\<subseteq>B. finite X \<and> eventually P (Inf X))"
   591 proof -
   592   let ?F = "\<lambda>P. \<exists>X\<subseteq>B. finite X \<and> eventually P (Inf X)"
   593   
   594   { fix P have "eventually P (Abs_filter ?F) \<longleftrightarrow> ?F P"
   595     proof (rule eventually_Abs_filter is_filter.intro)+
   596       show "?F (\<lambda>x. True)"
   597         by (rule exI[of _ "{}"]) (simp add: le_fun_def)
   598     next
   599       fix P Q
   600       assume "?F P" then guess X ..
   601       moreover
   602       assume "?F Q" then guess Y ..
   603       ultimately show "?F (\<lambda>x. P x \<and> Q x)"
   604         by (intro exI[of _ "X \<union> Y"])
   605            (auto simp: Inf_union_distrib eventually_inf)
   606     next
   607       fix P Q
   608       assume "?F P" then guess X ..
   609       moreover assume "\<forall>x. P x \<longrightarrow> Q x"
   610       ultimately show "?F Q"
   611         by (intro exI[of _ X]) (auto elim: eventually_elim1)
   612     qed }
   613   note eventually_F = this
   614 
   615   have "Inf B = Abs_filter ?F"
   616   proof (intro antisym Inf_greatest)
   617     show "Inf B \<le> Abs_filter ?F"
   618       by (auto simp: le_filter_def eventually_F dest: Inf_superset_mono)
   619   next
   620     fix F assume "F \<in> B" then show "Abs_filter ?F \<le> F"
   621       by (auto simp add: le_filter_def eventually_F intro!: exI[of _ "{F}"])
   622   qed
   623   then show ?thesis
   624     by (simp add: eventually_F)
   625 qed
   626 
   627 lemma eventually_INF: "eventually P (INF b:B. F b) \<longleftrightarrow> (\<exists>X\<subseteq>B. finite X \<and> eventually P (INF b:X. F b))"
   628   unfolding INF_def[of B] eventually_Inf[of P "F`B"]
   629   by (metis Inf_image_eq finite_imageI image_mono finite_subset_image)
   630 
   631 lemma Inf_filter_not_bot:
   632   fixes B :: "'a filter set"
   633   shows "(\<And>X. X \<subseteq> B \<Longrightarrow> finite X \<Longrightarrow> Inf X \<noteq> bot) \<Longrightarrow> Inf B \<noteq> bot"
   634   unfolding trivial_limit_def eventually_Inf[of _ B]
   635     bot_bool_def [symmetric] bot_fun_def [symmetric] bot_unique by simp
   636 
   637 lemma INF_filter_not_bot:
   638   fixes F :: "'i \<Rightarrow> 'a filter"
   639   shows "(\<And>X. X \<subseteq> B \<Longrightarrow> finite X \<Longrightarrow> (INF b:X. F b) \<noteq> bot) \<Longrightarrow> (INF b:B. F b) \<noteq> bot"
   640   unfolding trivial_limit_def eventually_INF[of _ B]
   641     bot_bool_def [symmetric] bot_fun_def [symmetric] bot_unique by simp
   642 
   643 lemma eventually_Inf_base:
   644   assumes "B \<noteq> {}" and base: "\<And>F G. F \<in> B \<Longrightarrow> G \<in> B \<Longrightarrow> \<exists>x\<in>B. x \<le> inf F G"
   645   shows "eventually P (Inf B) \<longleftrightarrow> (\<exists>b\<in>B. eventually P b)"
   646 proof (subst eventually_Inf, safe)
   647   fix X assume "finite X" "X \<subseteq> B"
   648   then have "\<exists>b\<in>B. \<forall>x\<in>X. b \<le> x"
   649   proof induct
   650     case empty then show ?case
   651       using `B \<noteq> {}` by auto
   652   next
   653     case (insert x X)
   654     then obtain b where "b \<in> B" "\<And>x. x \<in> X \<Longrightarrow> b \<le> x"
   655       by auto
   656     with `insert x X \<subseteq> B` base[of b x] show ?case
   657       by (auto intro: order_trans)
   658   qed
   659   then obtain b where "b \<in> B" "b \<le> Inf X"
   660     by (auto simp: le_Inf_iff)
   661   then show "eventually P (Inf X) \<Longrightarrow> Bex B (eventually P)"
   662     by (intro bexI[of _ b]) (auto simp: le_filter_def)
   663 qed (auto intro!: exI[of _ "{x}" for x])
   664 
   665 lemma eventually_INF_base:
   666   "B \<noteq> {} \<Longrightarrow> (\<And>a b. a \<in> B \<Longrightarrow> b \<in> B \<Longrightarrow> \<exists>x\<in>B. F x \<le> inf (F a) (F b)) \<Longrightarrow>
   667     eventually P (INF b:B. F b) \<longleftrightarrow> (\<exists>b\<in>B. eventually P (F b))"
   668   unfolding INF_def by (subst eventually_Inf_base) auto
   669 
   670 
   671 subsubsection {* Map function for filters *}
   672 
   673 definition filtermap :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a filter \<Rightarrow> 'b filter"
   674   where "filtermap f F = Abs_filter (\<lambda>P. eventually (\<lambda>x. P (f x)) F)"
   675 
   676 lemma eventually_filtermap:
   677   "eventually P (filtermap f F) = eventually (\<lambda>x. P (f x)) F"
   678   unfolding filtermap_def
   679   apply (rule eventually_Abs_filter)
   680   apply (rule is_filter.intro)
   681   apply (auto elim!: eventually_rev_mp)
   682   done
   683 
   684 lemma filtermap_ident: "filtermap (\<lambda>x. x) F = F"
   685   by (simp add: filter_eq_iff eventually_filtermap)
   686 
   687 lemma filtermap_filtermap:
   688   "filtermap f (filtermap g F) = filtermap (\<lambda>x. f (g x)) F"
   689   by (simp add: filter_eq_iff eventually_filtermap)
   690 
   691 lemma filtermap_mono: "F \<le> F' \<Longrightarrow> filtermap f F \<le> filtermap f F'"
   692   unfolding le_filter_def eventually_filtermap by simp
   693 
   694 lemma filtermap_bot [simp]: "filtermap f bot = bot"
   695   by (simp add: filter_eq_iff eventually_filtermap)
   696 
   697 lemma filtermap_sup: "filtermap f (sup F1 F2) = sup (filtermap f F1) (filtermap f F2)"
   698   by (auto simp: filter_eq_iff eventually_filtermap eventually_sup)
   699 
   700 lemma filtermap_inf: "filtermap f (inf F1 F2) \<le> inf (filtermap f F1) (filtermap f F2)"
   701   by (auto simp: le_filter_def eventually_filtermap eventually_inf)
   702 
   703 lemma filtermap_INF: "filtermap f (INF b:B. F b) \<le> (INF b:B. filtermap f (F b))"
   704 proof -
   705   { fix X :: "'c set" assume "finite X"
   706     then have "filtermap f (INFIMUM X F) \<le> (INF b:X. filtermap f (F b))"
   707     proof induct
   708       case (insert x X)
   709       have "filtermap f (INF a:insert x X. F a) \<le> inf (filtermap f (F x)) (filtermap f (INF a:X. F a))"
   710         by (rule order_trans[OF _ filtermap_inf]) simp
   711       also have "\<dots> \<le> inf (filtermap f (F x)) (INF a:X. filtermap f (F a))"
   712         by (intro inf_mono insert order_refl)
   713       finally show ?case
   714         by simp
   715     qed simp }
   716   then show ?thesis
   717     unfolding le_filter_def eventually_filtermap
   718     by (subst (1 2) eventually_INF) auto
   719 qed
   720 subsubsection {* Standard filters *}
   721 
   722 definition principal :: "'a set \<Rightarrow> 'a filter" where
   723   "principal S = Abs_filter (\<lambda>P. \<forall>x\<in>S. P x)"
   724 
   725 lemma eventually_principal: "eventually P (principal S) \<longleftrightarrow> (\<forall>x\<in>S. P x)"
   726   unfolding principal_def
   727   by (rule eventually_Abs_filter, rule is_filter.intro) auto
   728 
   729 lemma eventually_inf_principal: "eventually P (inf F (principal s)) \<longleftrightarrow> eventually (\<lambda>x. x \<in> s \<longrightarrow> P x) F"
   730   unfolding eventually_inf eventually_principal by (auto elim: eventually_elim1)
   731 
   732 lemma principal_UNIV[simp]: "principal UNIV = top"
   733   by (auto simp: filter_eq_iff eventually_principal)
   734 
   735 lemma principal_empty[simp]: "principal {} = bot"
   736   by (auto simp: filter_eq_iff eventually_principal)
   737 
   738 lemma principal_eq_bot_iff: "principal X = bot \<longleftrightarrow> X = {}"
   739   by (auto simp add: filter_eq_iff eventually_principal)
   740 
   741 lemma principal_le_iff[iff]: "principal A \<le> principal B \<longleftrightarrow> A \<subseteq> B"
   742   by (auto simp: le_filter_def eventually_principal)
   743 
   744 lemma le_principal: "F \<le> principal A \<longleftrightarrow> eventually (\<lambda>x. x \<in> A) F"
   745   unfolding le_filter_def eventually_principal
   746   apply safe
   747   apply (erule_tac x="\<lambda>x. x \<in> A" in allE)
   748   apply (auto elim: eventually_elim1)
   749   done
   750 
   751 lemma principal_inject[iff]: "principal A = principal B \<longleftrightarrow> A = B"
   752   unfolding eq_iff by simp
   753 
   754 lemma sup_principal[simp]: "sup (principal A) (principal B) = principal (A \<union> B)"
   755   unfolding filter_eq_iff eventually_sup eventually_principal by auto
   756 
   757 lemma inf_principal[simp]: "inf (principal A) (principal B) = principal (A \<inter> B)"
   758   unfolding filter_eq_iff eventually_inf eventually_principal
   759   by (auto intro: exI[of _ "\<lambda>x. x \<in> A"] exI[of _ "\<lambda>x. x \<in> B"])
   760 
   761 lemma SUP_principal[simp]: "(SUP i : I. principal (A i)) = principal (\<Union>i\<in>I. A i)"
   762   unfolding filter_eq_iff eventually_Sup SUP_def by (auto simp: eventually_principal)
   763 
   764 lemma INF_principal_finite: "finite X \<Longrightarrow> (INF x:X. principal (f x)) = principal (\<Inter>x\<in>X. f x)"
   765   by (induct X rule: finite_induct) auto
   766 
   767 lemma filtermap_principal[simp]: "filtermap f (principal A) = principal (f ` A)"
   768   unfolding filter_eq_iff eventually_filtermap eventually_principal by simp
   769 
   770 subsubsection {* Order filters *}
   771 
   772 definition at_top :: "('a::order) filter"
   773   where "at_top = (INF k. principal {k ..})"
   774 
   775 lemma at_top_sub: "at_top = (INF k:{c::'a::linorder..}. principal {k ..})"
   776   by (auto intro!: INF_eq max.cobounded1 max.cobounded2 simp: at_top_def)
   777 
   778 lemma eventually_at_top_linorder: "eventually P at_top \<longleftrightarrow> (\<exists>N::'a::linorder. \<forall>n\<ge>N. P n)"
   779   unfolding at_top_def
   780   by (subst eventually_INF_base) (auto simp: eventually_principal intro: max.cobounded1 max.cobounded2)
   781 
   782 lemma eventually_ge_at_top:
   783   "eventually (\<lambda>x. (c::_::linorder) \<le> x) at_top"
   784   unfolding eventually_at_top_linorder by auto
   785 
   786 lemma eventually_at_top_dense: "eventually P at_top \<longleftrightarrow> (\<exists>N::'a::{no_top, linorder}. \<forall>n>N. P n)"
   787 proof -
   788   have "eventually P (INF k. principal {k <..}) \<longleftrightarrow> (\<exists>N::'a. \<forall>n>N. P n)"
   789     by (subst eventually_INF_base) (auto simp: eventually_principal intro: max.cobounded1 max.cobounded2)
   790   also have "(INF k. principal {k::'a <..}) = at_top"
   791     unfolding at_top_def 
   792     by (intro INF_eq) (auto intro: less_imp_le simp: Ici_subset_Ioi_iff gt_ex)
   793   finally show ?thesis .
   794 qed
   795 
   796 lemma eventually_gt_at_top:
   797   "eventually (\<lambda>x. (c::_::unbounded_dense_linorder) < x) at_top"
   798   unfolding eventually_at_top_dense by auto
   799 
   800 definition at_bot :: "('a::order) filter"
   801   where "at_bot = (INF k. principal {.. k})"
   802 
   803 lemma at_bot_sub: "at_bot = (INF k:{.. c::'a::linorder}. principal {.. k})"
   804   by (auto intro!: INF_eq min.cobounded1 min.cobounded2 simp: at_bot_def)
   805 
   806 lemma eventually_at_bot_linorder:
   807   fixes P :: "'a::linorder \<Rightarrow> bool" shows "eventually P at_bot \<longleftrightarrow> (\<exists>N. \<forall>n\<le>N. P n)"
   808   unfolding at_bot_def
   809   by (subst eventually_INF_base) (auto simp: eventually_principal intro: min.cobounded1 min.cobounded2)
   810 
   811 lemma eventually_le_at_bot:
   812   "eventually (\<lambda>x. x \<le> (c::_::linorder)) at_bot"
   813   unfolding eventually_at_bot_linorder by auto
   814 
   815 lemma eventually_at_bot_dense: "eventually P at_bot \<longleftrightarrow> (\<exists>N::'a::{no_bot, linorder}. \<forall>n<N. P n)"
   816 proof -
   817   have "eventually P (INF k. principal {..< k}) \<longleftrightarrow> (\<exists>N::'a. \<forall>n<N. P n)"
   818     by (subst eventually_INF_base) (auto simp: eventually_principal intro: min.cobounded1 min.cobounded2)
   819   also have "(INF k. principal {..< k::'a}) = at_bot"
   820     unfolding at_bot_def 
   821     by (intro INF_eq) (auto intro: less_imp_le simp: Iic_subset_Iio_iff lt_ex)
   822   finally show ?thesis .
   823 qed
   824 
   825 lemma eventually_gt_at_bot:
   826   "eventually (\<lambda>x. x < (c::_::unbounded_dense_linorder)) at_bot"
   827   unfolding eventually_at_bot_dense by auto
   828 
   829 lemma trivial_limit_at_bot_linorder: "\<not> trivial_limit (at_bot ::('a::linorder) filter)"
   830   unfolding trivial_limit_def
   831   by (metis eventually_at_bot_linorder order_refl)
   832 
   833 lemma trivial_limit_at_top_linorder: "\<not> trivial_limit (at_top ::('a::linorder) filter)"
   834   unfolding trivial_limit_def
   835   by (metis eventually_at_top_linorder order_refl)
   836 
   837 subsection {* Sequentially *}
   838 
   839 abbreviation sequentially :: "nat filter"
   840   where "sequentially \<equiv> at_top"
   841 
   842 lemma eventually_sequentially:
   843   "eventually P sequentially \<longleftrightarrow> (\<exists>N. \<forall>n\<ge>N. P n)"
   844   by (rule eventually_at_top_linorder)
   845 
   846 lemma sequentially_bot [simp, intro]: "sequentially \<noteq> bot"
   847   unfolding filter_eq_iff eventually_sequentially by auto
   848 
   849 lemmas trivial_limit_sequentially = sequentially_bot
   850 
   851 lemma eventually_False_sequentially [simp]:
   852   "\<not> eventually (\<lambda>n. False) sequentially"
   853   by (simp add: eventually_False)
   854 
   855 lemma le_sequentially:
   856   "F \<le> sequentially \<longleftrightarrow> (\<forall>N. eventually (\<lambda>n. N \<le> n) F)"
   857   by (simp add: at_top_def le_INF_iff le_principal)
   858 
   859 lemma eventually_sequentiallyI:
   860   assumes "\<And>x. c \<le> x \<Longrightarrow> P x"
   861   shows "eventually P sequentially"
   862 using assms by (auto simp: eventually_sequentially)
   863 
   864 lemma eventually_sequentially_seg:
   865   "eventually (\<lambda>n. P (n + k)) sequentially \<longleftrightarrow> eventually P sequentially"
   866   unfolding eventually_sequentially
   867   apply safe
   868    apply (rule_tac x="N + k" in exI)
   869    apply rule
   870    apply (erule_tac x="n - k" in allE)
   871    apply auto []
   872   apply (rule_tac x=N in exI)
   873   apply auto []
   874   done
   875 
   876 subsubsection {* Topological filters *}
   877 
   878 definition (in topological_space) nhds :: "'a \<Rightarrow> 'a filter"
   879   where "nhds a = (INF S:{S. open S \<and> a \<in> S}. principal S)"
   880 
   881 definition (in topological_space) at_within :: "'a \<Rightarrow> 'a set \<Rightarrow> 'a filter" ("at (_) within (_)" [1000, 60] 60)
   882   where "at a within s = inf (nhds a) (principal (s - {a}))"
   883 
   884 abbreviation (in topological_space) at :: "'a \<Rightarrow> 'a filter" ("at") where
   885   "at x \<equiv> at x within (CONST UNIV)"
   886 
   887 abbreviation (in order_topology) at_right :: "'a \<Rightarrow> 'a filter" where
   888   "at_right x \<equiv> at x within {x <..}"
   889 
   890 abbreviation (in order_topology) at_left :: "'a \<Rightarrow> 'a filter" where
   891   "at_left x \<equiv> at x within {..< x}"
   892 
   893 lemma (in topological_space) nhds_generated_topology:
   894   "open = generate_topology T \<Longrightarrow> nhds x = (INF S:{S\<in>T. x \<in> S}. principal S)"
   895   unfolding nhds_def
   896 proof (safe intro!: antisym INF_greatest)
   897   fix S assume "generate_topology T S" "x \<in> S"
   898   then show "(INF S:{S \<in> T. x \<in> S}. principal S) \<le> principal S"
   899     by induction 
   900        (auto intro: INF_lower order_trans simp add: inf_principal[symmetric] simp del: inf_principal)
   901 qed (auto intro!: INF_lower intro: generate_topology.intros)
   902 
   903 lemma (in topological_space) eventually_nhds:
   904   "eventually P (nhds a) \<longleftrightarrow> (\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x))"
   905   unfolding nhds_def by (subst eventually_INF_base) (auto simp: eventually_principal)
   906 
   907 lemma nhds_neq_bot [simp]: "nhds a \<noteq> bot"
   908   unfolding trivial_limit_def eventually_nhds by simp
   909 
   910 lemma at_within_eq: "at x within s = (INF S:{S. open S \<and> x \<in> S}. principal (S \<inter> s - {x}))"
   911   unfolding nhds_def at_within_def by (subst INF_inf_const2[symmetric]) (auto simp add: Diff_Int_distrib)
   912 
   913 lemma eventually_at_filter:
   914   "eventually P (at a within s) \<longleftrightarrow> eventually (\<lambda>x. x \<noteq> a \<longrightarrow> x \<in> s \<longrightarrow> P x) (nhds a)"
   915   unfolding at_within_def eventually_inf_principal by (simp add: imp_conjL[symmetric] conj_commute)
   916 
   917 lemma at_le: "s \<subseteq> t \<Longrightarrow> at x within s \<le> at x within t"
   918   unfolding at_within_def by (intro inf_mono) auto
   919 
   920 lemma eventually_at_topological:
   921   "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))"
   922   unfolding eventually_nhds eventually_at_filter by simp
   923 
   924 lemma at_within_open: "a \<in> S \<Longrightarrow> open S \<Longrightarrow> at a within S = at a"
   925   unfolding filter_eq_iff eventually_at_topological by (metis open_Int Int_iff UNIV_I)
   926 
   927 lemma at_within_empty [simp]: "at a within {} = bot"
   928   unfolding at_within_def by simp
   929 
   930 lemma at_within_union: "at x within (S \<union> T) = sup (at x within S) (at x within T)"
   931   unfolding filter_eq_iff eventually_sup eventually_at_filter
   932   by (auto elim!: eventually_rev_mp)
   933 
   934 lemma at_eq_bot_iff: "at a = bot \<longleftrightarrow> open {a}"
   935   unfolding trivial_limit_def eventually_at_topological
   936   by (safe, case_tac "S = {a}", simp, fast, fast)
   937 
   938 lemma at_neq_bot [simp]: "at (a::'a::perfect_space) \<noteq> bot"
   939   by (simp add: at_eq_bot_iff not_open_singleton)
   940 
   941 lemma (in order_topology) nhds_order: "nhds x =
   942   inf (INF a:{x <..}. principal {..< a}) (INF a:{..< x}. principal {a <..})"
   943 proof -
   944   have 1: "{S \<in> range lessThan \<union> range greaterThan. x \<in> S} = 
   945       (\<lambda>a. {..< a}) ` {x <..} \<union> (\<lambda>a. {a <..}) ` {..< x}"
   946     by auto
   947   show ?thesis
   948     unfolding nhds_generated_topology[OF open_generated_order] INF_union 1 INF_image comp_def ..
   949 qed
   950 
   951 lemma (in linorder_topology) at_within_order: "UNIV \<noteq> {x} \<Longrightarrow> 
   952   at x within s = inf (INF a:{x <..}. principal ({..< a} \<inter> s - {x}))
   953                       (INF a:{..< x}. principal ({a <..} \<inter> s - {x}))"
   954 proof (cases "{x <..} = {}" "{..< x} = {}" rule: case_split[case_product case_split])
   955   assume "UNIV \<noteq> {x}" "{x<..} = {}" "{..< x} = {}"
   956   moreover have "UNIV = {..< x} \<union> {x} \<union> {x <..}"
   957     by auto
   958   ultimately show ?thesis
   959     by auto
   960 qed (auto simp: at_within_def nhds_order Int_Diff inf_principal[symmetric] INF_inf_const2
   961                 inf_sup_aci[where 'a="'a filter"]
   962           simp del: inf_principal)
   963 
   964 lemma (in linorder_topology) at_left_eq:
   965   "y < x \<Longrightarrow> at_left x = (INF a:{..< x}. principal {a <..< x})"
   966   by (subst at_within_order)
   967      (auto simp: greaterThan_Int_greaterThan greaterThanLessThan_eq[symmetric] min.absorb2 INF_constant
   968            intro!: INF_lower2 inf_absorb2)
   969 
   970 lemma (in linorder_topology) eventually_at_left:
   971   "y < x \<Longrightarrow> eventually P (at_left x) \<longleftrightarrow> (\<exists>b<x. \<forall>y>b. y < x \<longrightarrow> P y)"
   972   unfolding at_left_eq by (subst eventually_INF_base) (auto simp: eventually_principal Ball_def)
   973 
   974 lemma (in linorder_topology) at_right_eq:
   975   "x < y \<Longrightarrow> at_right x = (INF a:{x <..}. principal {x <..< a})"
   976   by (subst at_within_order)
   977      (auto simp: lessThan_Int_lessThan greaterThanLessThan_eq[symmetric] max.absorb2 INF_constant Int_commute
   978            intro!: INF_lower2 inf_absorb1)
   979 
   980 lemma (in linorder_topology) eventually_at_right:
   981   "x < y \<Longrightarrow> eventually P (at_right x) \<longleftrightarrow> (\<exists>b>x. \<forall>y>x. y < b \<longrightarrow> P y)"
   982   unfolding at_right_eq by (subst eventually_INF_base) (auto simp: eventually_principal Ball_def)
   983 
   984 lemma trivial_limit_at_right_top: "at_right (top::_::{order_top, linorder_topology}) = bot"
   985   unfolding filter_eq_iff eventually_at_topological by auto
   986 
   987 lemma trivial_limit_at_left_bot: "at_left (bot::_::{order_bot, linorder_topology}) = bot"
   988   unfolding filter_eq_iff eventually_at_topological by auto
   989 
   990 lemma trivial_limit_at_left_real [simp]:
   991   "\<not> trivial_limit (at_left (x::'a::{no_bot, dense_order, linorder_topology}))"
   992   using lt_ex[of x]
   993   by safe (auto simp add: trivial_limit_def eventually_at_left dest: dense)
   994 
   995 lemma trivial_limit_at_right_real [simp]:
   996   "\<not> trivial_limit (at_right (x::'a::{no_top, dense_order, linorder_topology}))"
   997   using gt_ex[of x]
   998   by safe (auto simp add: trivial_limit_def eventually_at_right dest: dense)
   999 
  1000 lemma at_eq_sup_left_right: "at (x::'a::linorder_topology) = sup (at_left x) (at_right x)"
  1001   by (auto simp: eventually_at_filter filter_eq_iff eventually_sup 
  1002            elim: eventually_elim2 eventually_elim1)
  1003 
  1004 lemma eventually_at_split:
  1005   "eventually P (at (x::'a::linorder_topology)) \<longleftrightarrow> eventually P (at_left x) \<and> eventually P (at_right x)"
  1006   by (subst at_eq_sup_left_right) (simp add: eventually_sup)
  1007 
  1008 subsection {* Limits *}
  1009 
  1010 definition filterlim :: "('a \<Rightarrow> 'b) \<Rightarrow> 'b filter \<Rightarrow> 'a filter \<Rightarrow> bool" where
  1011   "filterlim f F2 F1 \<longleftrightarrow> filtermap f F1 \<le> F2"
  1012 
  1013 syntax
  1014   "_LIM" :: "pttrns \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> bool" ("(3LIM (_)/ (_)./ (_) :> (_))" [1000, 10, 0, 10] 10)
  1015 
  1016 translations
  1017   "LIM x F1. f :> F2"   == "CONST filterlim (%x. f) F2 F1"
  1018 
  1019 lemma filterlim_iff:
  1020   "(LIM x F1. f x :> F2) \<longleftrightarrow> (\<forall>P. eventually P F2 \<longrightarrow> eventually (\<lambda>x. P (f x)) F1)"
  1021   unfolding filterlim_def le_filter_def eventually_filtermap ..
  1022 
  1023 lemma filterlim_compose:
  1024   "filterlim g F3 F2 \<Longrightarrow> filterlim f F2 F1 \<Longrightarrow> filterlim (\<lambda>x. g (f x)) F3 F1"
  1025   unfolding filterlim_def filtermap_filtermap[symmetric] by (metis filtermap_mono order_trans)
  1026 
  1027 lemma filterlim_mono:
  1028   "filterlim f F2 F1 \<Longrightarrow> F2 \<le> F2' \<Longrightarrow> F1' \<le> F1 \<Longrightarrow> filterlim f F2' F1'"
  1029   unfolding filterlim_def by (metis filtermap_mono order_trans)
  1030 
  1031 lemma filterlim_ident: "LIM x F. x :> F"
  1032   by (simp add: filterlim_def filtermap_ident)
  1033 
  1034 lemma filterlim_cong:
  1035   "F1 = F1' \<Longrightarrow> F2 = F2' \<Longrightarrow> eventually (\<lambda>x. f x = g x) F2 \<Longrightarrow> filterlim f F1 F2 = filterlim g F1' F2'"
  1036   by (auto simp: filterlim_def le_filter_def eventually_filtermap elim: eventually_elim2)
  1037 
  1038 lemma filterlim_mono_eventually:
  1039   assumes "filterlim f F G" and ord: "F \<le> F'" "G' \<le> G"
  1040   assumes eq: "eventually (\<lambda>x. f x = f' x) G'"
  1041   shows "filterlim f' F' G'"
  1042   apply (rule filterlim_cong[OF refl refl eq, THEN iffD1])
  1043   apply (rule filterlim_mono[OF _ ord])
  1044   apply fact
  1045   done
  1046 
  1047 lemma filtermap_mono_strong: "inj f \<Longrightarrow> filtermap f F \<le> filtermap f G \<longleftrightarrow> F \<le> G"
  1048   apply (auto intro!: filtermap_mono) []
  1049   apply (auto simp: le_filter_def eventually_filtermap)
  1050   apply (erule_tac x="\<lambda>x. P (inv f x)" in allE)
  1051   apply auto
  1052   done
  1053 
  1054 lemma filtermap_eq_strong: "inj f \<Longrightarrow> filtermap f F = filtermap f G \<longleftrightarrow> F = G"
  1055   by (simp add: filtermap_mono_strong eq_iff)
  1056 
  1057 lemma filterlim_principal:
  1058   "(LIM x F. f x :> principal S) \<longleftrightarrow> (eventually (\<lambda>x. f x \<in> S) F)"
  1059   unfolding filterlim_def eventually_filtermap le_principal ..
  1060 
  1061 lemma filterlim_inf:
  1062   "(LIM x F1. f x :> inf F2 F3) \<longleftrightarrow> ((LIM x F1. f x :> F2) \<and> (LIM x F1. f x :> F3))"
  1063   unfolding filterlim_def by simp
  1064 
  1065 lemma filterlim_INF:
  1066   "(LIM x F. f x :> (INF b:B. G b)) \<longleftrightarrow> (\<forall>b\<in>B. LIM x F. f x :> G b)"
  1067   unfolding filterlim_def le_INF_iff ..
  1068 
  1069 lemma filterlim_INF_INF:
  1070   "(\<And>m. m \<in> J \<Longrightarrow> \<exists>i\<in>I. filtermap f (F i) \<le> G m) \<Longrightarrow> LIM x (INF i:I. F i). f x :> (INF j:J. G j)"
  1071   unfolding filterlim_def by (rule order_trans[OF filtermap_INF INF_mono])
  1072 
  1073 lemma filterlim_base:
  1074   "(\<And>m x. m \<in> J \<Longrightarrow> i m \<in> I) \<Longrightarrow> (\<And>m x. m \<in> J \<Longrightarrow> x \<in> F (i m) \<Longrightarrow> f x \<in> G m) \<Longrightarrow> 
  1075     LIM x (INF i:I. principal (F i)). f x :> (INF j:J. principal (G j))"
  1076   by (force intro!: filterlim_INF_INF simp: image_subset_iff)
  1077 
  1078 lemma filterlim_base_iff: 
  1079   assumes "I \<noteq> {}" and chain: "\<And>i j. i \<in> I \<Longrightarrow> j \<in> I \<Longrightarrow> F i \<subseteq> F j \<or> F j \<subseteq> F i"
  1080   shows "(LIM x (INF i:I. principal (F i)). f x :> INF j:J. principal (G j)) \<longleftrightarrow>
  1081     (\<forall>j\<in>J. \<exists>i\<in>I. \<forall>x\<in>F i. f x \<in> G j)"
  1082   unfolding filterlim_INF filterlim_principal
  1083 proof (subst eventually_INF_base)
  1084   fix i j assume "i \<in> I" "j \<in> I"
  1085   with chain[OF this] show "\<exists>x\<in>I. principal (F x) \<le> inf (principal (F i)) (principal (F j))"
  1086     by auto
  1087 qed (auto simp: eventually_principal `I \<noteq> {}`)
  1088 
  1089 lemma filterlim_filtermap: "filterlim f F1 (filtermap g F2) = filterlim (\<lambda>x. f (g x)) F1 F2"
  1090   unfolding filterlim_def filtermap_filtermap ..
  1091 
  1092 lemma filterlim_sup:
  1093   "filterlim f F F1 \<Longrightarrow> filterlim f F F2 \<Longrightarrow> filterlim f F (sup F1 F2)"
  1094   unfolding filterlim_def filtermap_sup by auto
  1095 
  1096 lemma eventually_sequentially_Suc: "eventually (\<lambda>i. P (Suc i)) sequentially \<longleftrightarrow> eventually P sequentially"
  1097   unfolding eventually_sequentially by (metis Suc_le_D Suc_le_mono le_Suc_eq)
  1098 
  1099 lemma filterlim_sequentially_Suc:
  1100   "(LIM x sequentially. f (Suc x) :> F) \<longleftrightarrow> (LIM x sequentially. f x :> F)"
  1101   unfolding filterlim_iff by (subst eventually_sequentially_Suc) simp
  1102 
  1103 lemma filterlim_Suc: "filterlim Suc sequentially sequentially"
  1104   by (simp add: filterlim_iff eventually_sequentially) (metis le_Suc_eq)
  1105 
  1106 subsubsection {* Tendsto *}
  1107 
  1108 abbreviation (in topological_space)
  1109   tendsto :: "('b \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'b filter \<Rightarrow> bool" (infixr "--->" 55) where
  1110   "(f ---> l) F \<equiv> filterlim f (nhds l) F"
  1111 
  1112 definition (in t2_space) Lim :: "'f filter \<Rightarrow> ('f \<Rightarrow> 'a) \<Rightarrow> 'a" where
  1113   "Lim A f = (THE l. (f ---> l) A)"
  1114 
  1115 lemma tendsto_eq_rhs: "(f ---> x) F \<Longrightarrow> x = y \<Longrightarrow> (f ---> y) F"
  1116   by simp
  1117 
  1118 named_theorems tendsto_intros "introduction rules for tendsto"
  1119 setup {*
  1120   Global_Theory.add_thms_dynamic (@{binding tendsto_eq_intros},
  1121     fn context =>
  1122       Named_Theorems.get (Context.proof_of context) @{named_theorems tendsto_intros}
  1123       |> map_filter (try (fn thm => @{thm tendsto_eq_rhs} OF [thm])))
  1124 *}
  1125 
  1126 lemma (in topological_space) tendsto_def:
  1127    "(f ---> l) F \<longleftrightarrow> (\<forall>S. open S \<longrightarrow> l \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) F)"
  1128    unfolding nhds_def filterlim_INF filterlim_principal by auto
  1129 
  1130 lemma tendsto_mono: "F \<le> F' \<Longrightarrow> (f ---> l) F' \<Longrightarrow> (f ---> l) F"
  1131   unfolding tendsto_def le_filter_def by fast
  1132 
  1133 lemma tendsto_within_subset: "(f ---> l) (at x within S) \<Longrightarrow> T \<subseteq> S \<Longrightarrow> (f ---> l) (at x within T)"
  1134   by (blast intro: tendsto_mono at_le)
  1135 
  1136 lemma filterlim_at:
  1137   "(LIM x F. f x :> at b within s) \<longleftrightarrow> (eventually (\<lambda>x. f x \<in> s \<and> f x \<noteq> b) F \<and> (f ---> b) F)"
  1138   by (simp add: at_within_def filterlim_inf filterlim_principal conj_commute)
  1139 
  1140 lemma (in topological_space) topological_tendstoI:
  1141   "(\<And>S. open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) F) \<Longrightarrow> (f ---> l) F"
  1142   unfolding tendsto_def by auto
  1143 
  1144 lemma (in topological_space) topological_tendstoD:
  1145   "(f ---> l) F \<Longrightarrow> open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) F"
  1146   unfolding tendsto_def by auto
  1147 
  1148 lemma (in order_topology) order_tendsto_iff:
  1149   "(f ---> x) F \<longleftrightarrow> (\<forall>l<x. eventually (\<lambda>x. l < f x) F) \<and> (\<forall>u>x. eventually (\<lambda>x. f x < u) F)"
  1150   unfolding nhds_order filterlim_inf filterlim_INF filterlim_principal by auto
  1151 
  1152 lemma (in order_topology) order_tendstoI:
  1153   "(\<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>
  1154     (f ---> y) F"
  1155   unfolding order_tendsto_iff by auto
  1156 
  1157 lemma (in order_topology) order_tendstoD:
  1158   assumes "(f ---> y) F"
  1159   shows "a < y \<Longrightarrow> eventually (\<lambda>x. a < f x) F"
  1160     and "y < a \<Longrightarrow> eventually (\<lambda>x. f x < a) F"
  1161   using assms unfolding order_tendsto_iff by auto
  1162 
  1163 lemma tendsto_bot [simp]: "(f ---> a) bot"
  1164   unfolding tendsto_def by simp
  1165 
  1166 lemma (in linorder_topology) tendsto_max:
  1167   assumes X: "(X ---> x) net"
  1168   assumes Y: "(Y ---> y) net"
  1169   shows "((\<lambda>x. max (X x) (Y x)) ---> max x y) net"
  1170 proof (rule order_tendstoI)
  1171   fix a assume "a < max x y"
  1172   then show "eventually (\<lambda>x. a < max (X x) (Y x)) net"
  1173     using order_tendstoD(1)[OF X, of a] order_tendstoD(1)[OF Y, of a]
  1174     by (auto simp: less_max_iff_disj elim: eventually_elim1)
  1175 next
  1176   fix a assume "max x y < a"
  1177   then show "eventually (\<lambda>x. max (X x) (Y x) < a) net"
  1178     using order_tendstoD(2)[OF X, of a] order_tendstoD(2)[OF Y, of a]
  1179     by (auto simp: eventually_conj_iff)
  1180 qed
  1181 
  1182 lemma (in linorder_topology) tendsto_min:
  1183   assumes X: "(X ---> x) net"
  1184   assumes Y: "(Y ---> y) net"
  1185   shows "((\<lambda>x. min (X x) (Y x)) ---> min x y) net"
  1186 proof (rule order_tendstoI)
  1187   fix a assume "a < min x y"
  1188   then show "eventually (\<lambda>x. a < min (X x) (Y x)) net"
  1189     using order_tendstoD(1)[OF X, of a] order_tendstoD(1)[OF Y, of a]
  1190     by (auto simp: eventually_conj_iff)
  1191 next
  1192   fix a assume "min x y < a"
  1193   then show "eventually (\<lambda>x. min (X x) (Y x) < a) net"
  1194     using order_tendstoD(2)[OF X, of a] order_tendstoD(2)[OF Y, of a]
  1195     by (auto simp: min_less_iff_disj elim: eventually_elim1)
  1196 qed
  1197 
  1198 lemma tendsto_ident_at [tendsto_intros, simp, intro]: "((\<lambda>x. x) ---> a) (at a within s)"
  1199   unfolding tendsto_def eventually_at_topological by auto
  1200 
  1201 lemma (in topological_space) tendsto_const [tendsto_intros, simp, intro]: "((\<lambda>x. k) ---> k) F"
  1202   by (simp add: tendsto_def)
  1203 
  1204 lemma (in t2_space) tendsto_unique:
  1205   assumes "F \<noteq> bot" and "(f ---> a) F" and "(f ---> b) F"
  1206   shows "a = b"
  1207 proof (rule ccontr)
  1208   assume "a \<noteq> b"
  1209   obtain U V where "open U" "open V" "a \<in> U" "b \<in> V" "U \<inter> V = {}"
  1210     using hausdorff [OF `a \<noteq> b`] by fast
  1211   have "eventually (\<lambda>x. f x \<in> U) F"
  1212     using `(f ---> a) F` `open U` `a \<in> U` by (rule topological_tendstoD)
  1213   moreover
  1214   have "eventually (\<lambda>x. f x \<in> V) F"
  1215     using `(f ---> b) F` `open V` `b \<in> V` by (rule topological_tendstoD)
  1216   ultimately
  1217   have "eventually (\<lambda>x. False) F"
  1218   proof eventually_elim
  1219     case (elim x)
  1220     hence "f x \<in> U \<inter> V" by simp
  1221     with `U \<inter> V = {}` show ?case by simp
  1222   qed
  1223   with `\<not> trivial_limit F` show "False"
  1224     by (simp add: trivial_limit_def)
  1225 qed
  1226 
  1227 lemma (in t2_space) tendsto_const_iff:
  1228   assumes "\<not> trivial_limit F" shows "((\<lambda>x. a :: 'a) ---> b) F \<longleftrightarrow> a = b"
  1229   by (auto intro!: tendsto_unique [OF assms tendsto_const])
  1230 
  1231 lemma increasing_tendsto:
  1232   fixes f :: "_ \<Rightarrow> 'a::order_topology"
  1233   assumes bdd: "eventually (\<lambda>n. f n \<le> l) F"
  1234       and en: "\<And>x. x < l \<Longrightarrow> eventually (\<lambda>n. x < f n) F"
  1235   shows "(f ---> l) F"
  1236   using assms by (intro order_tendstoI) (auto elim!: eventually_elim1)
  1237 
  1238 lemma decreasing_tendsto:
  1239   fixes f :: "_ \<Rightarrow> 'a::order_topology"
  1240   assumes bdd: "eventually (\<lambda>n. l \<le> f n) F"
  1241       and en: "\<And>x. l < x \<Longrightarrow> eventually (\<lambda>n. f n < x) F"
  1242   shows "(f ---> l) F"
  1243   using assms by (intro order_tendstoI) (auto elim!: eventually_elim1)
  1244 
  1245 lemma tendsto_sandwich:
  1246   fixes f g h :: "'a \<Rightarrow> 'b::order_topology"
  1247   assumes ev: "eventually (\<lambda>n. f n \<le> g n) net" "eventually (\<lambda>n. g n \<le> h n) net"
  1248   assumes lim: "(f ---> c) net" "(h ---> c) net"
  1249   shows "(g ---> c) net"
  1250 proof (rule order_tendstoI)
  1251   fix a show "a < c \<Longrightarrow> eventually (\<lambda>x. a < g x) net"
  1252     using order_tendstoD[OF lim(1), of a] ev by (auto elim: eventually_elim2)
  1253 next
  1254   fix a show "c < a \<Longrightarrow> eventually (\<lambda>x. g x < a) net"
  1255     using order_tendstoD[OF lim(2), of a] ev by (auto elim: eventually_elim2)
  1256 qed
  1257 
  1258 lemma tendsto_le:
  1259   fixes f g :: "'a \<Rightarrow> 'b::linorder_topology"
  1260   assumes F: "\<not> trivial_limit F"
  1261   assumes x: "(f ---> x) F" and y: "(g ---> y) F"
  1262   assumes ev: "eventually (\<lambda>x. g x \<le> f x) F"
  1263   shows "y \<le> x"
  1264 proof (rule ccontr)
  1265   assume "\<not> y \<le> x"
  1266   with less_separate[of x y] obtain a b where xy: "x < a" "b < y" "{..<a} \<inter> {b<..} = {}"
  1267     by (auto simp: not_le)
  1268   then have "eventually (\<lambda>x. f x < a) F" "eventually (\<lambda>x. b < g x) F"
  1269     using x y by (auto intro: order_tendstoD)
  1270   with ev have "eventually (\<lambda>x. False) F"
  1271     by eventually_elim (insert xy, fastforce)
  1272   with F show False
  1273     by (simp add: eventually_False)
  1274 qed
  1275 
  1276 lemma tendsto_le_const:
  1277   fixes f :: "'a \<Rightarrow> 'b::linorder_topology"
  1278   assumes F: "\<not> trivial_limit F"
  1279   assumes x: "(f ---> x) F" and a: "eventually (\<lambda>i. a \<le> f i) F"
  1280   shows "a \<le> x"
  1281   using F x tendsto_const a by (rule tendsto_le)
  1282 
  1283 lemma tendsto_ge_const:
  1284   fixes f :: "'a \<Rightarrow> 'b::linorder_topology"
  1285   assumes F: "\<not> trivial_limit F"
  1286   assumes x: "(f ---> x) F" and a: "eventually (\<lambda>i. a \<ge> f i) F"
  1287   shows "a \<ge> x"
  1288   by (rule tendsto_le [OF F tendsto_const x a])
  1289 
  1290 subsubsection {* Rules about @{const Lim} *}
  1291 
  1292 lemma tendsto_Lim:
  1293   "\<not>(trivial_limit net) \<Longrightarrow> (f ---> l) net \<Longrightarrow> Lim net f = l"
  1294   unfolding Lim_def using tendsto_unique[of net f] by auto
  1295 
  1296 lemma Lim_ident_at: "\<not> trivial_limit (at x within s) \<Longrightarrow> Lim (at x within s) (\<lambda>x. x) = x"
  1297   by (rule tendsto_Lim[OF _ tendsto_ident_at]) auto
  1298 
  1299 subsection {* Limits to @{const at_top} and @{const at_bot} *}
  1300 
  1301 lemma filterlim_at_top:
  1302   fixes f :: "'a \<Rightarrow> ('b::linorder)"
  1303   shows "(LIM x F. f x :> at_top) \<longleftrightarrow> (\<forall>Z. eventually (\<lambda>x. Z \<le> f x) F)"
  1304   by (auto simp: filterlim_iff eventually_at_top_linorder elim!: eventually_elim1)
  1305 
  1306 lemma filterlim_at_top_mono:
  1307   "LIM x F. f x :> at_top \<Longrightarrow> eventually (\<lambda>x. f x \<le> (g x::'a::linorder)) F \<Longrightarrow>
  1308     LIM x F. g x :> at_top"
  1309   by (auto simp: filterlim_at_top elim: eventually_elim2 intro: order_trans)
  1310 
  1311 lemma filterlim_at_top_dense:
  1312   fixes f :: "'a \<Rightarrow> ('b::unbounded_dense_linorder)"
  1313   shows "(LIM x F. f x :> at_top) \<longleftrightarrow> (\<forall>Z. eventually (\<lambda>x. Z < f x) F)"
  1314   by (metis eventually_elim1[of _ F] eventually_gt_at_top order_less_imp_le
  1315             filterlim_at_top[of f F] filterlim_iff[of f at_top F])
  1316 
  1317 lemma filterlim_at_top_ge:
  1318   fixes f :: "'a \<Rightarrow> ('b::linorder)" and c :: "'b"
  1319   shows "(LIM x F. f x :> at_top) \<longleftrightarrow> (\<forall>Z\<ge>c. eventually (\<lambda>x. Z \<le> f x) F)"
  1320   unfolding at_top_sub[of c] filterlim_INF by (auto simp add: filterlim_principal)
  1321 
  1322 lemma filterlim_at_top_at_top:
  1323   fixes f :: "'a::linorder \<Rightarrow> 'b::linorder"
  1324   assumes mono: "\<And>x y. Q x \<Longrightarrow> Q y \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y"
  1325   assumes bij: "\<And>x. P x \<Longrightarrow> f (g x) = x" "\<And>x. P x \<Longrightarrow> Q (g x)"
  1326   assumes Q: "eventually Q at_top"
  1327   assumes P: "eventually P at_top"
  1328   shows "filterlim f at_top at_top"
  1329 proof -
  1330   from P obtain x where x: "\<And>y. x \<le> y \<Longrightarrow> P y"
  1331     unfolding eventually_at_top_linorder by auto
  1332   show ?thesis
  1333   proof (intro filterlim_at_top_ge[THEN iffD2] allI impI)
  1334     fix z assume "x \<le> z"
  1335     with x have "P z" by auto
  1336     have "eventually (\<lambda>x. g z \<le> x) at_top"
  1337       by (rule eventually_ge_at_top)
  1338     with Q show "eventually (\<lambda>x. z \<le> f x) at_top"
  1339       by eventually_elim (metis mono bij `P z`)
  1340   qed
  1341 qed
  1342 
  1343 lemma filterlim_at_top_gt:
  1344   fixes f :: "'a \<Rightarrow> ('b::unbounded_dense_linorder)" and c :: "'b"
  1345   shows "(LIM x F. f x :> at_top) \<longleftrightarrow> (\<forall>Z>c. eventually (\<lambda>x. Z \<le> f x) F)"
  1346   by (metis filterlim_at_top order_less_le_trans gt_ex filterlim_at_top_ge)
  1347 
  1348 lemma filterlim_at_bot: 
  1349   fixes f :: "'a \<Rightarrow> ('b::linorder)"
  1350   shows "(LIM x F. f x :> at_bot) \<longleftrightarrow> (\<forall>Z. eventually (\<lambda>x. f x \<le> Z) F)"
  1351   by (auto simp: filterlim_iff eventually_at_bot_linorder elim!: eventually_elim1)
  1352 
  1353 lemma filterlim_at_bot_dense:
  1354   fixes f :: "'a \<Rightarrow> ('b::{dense_linorder, no_bot})"
  1355   shows "(LIM x F. f x :> at_bot) \<longleftrightarrow> (\<forall>Z. eventually (\<lambda>x. f x < Z) F)"
  1356 proof (auto simp add: filterlim_at_bot[of f F])
  1357   fix Z :: 'b
  1358   from lt_ex [of Z] obtain Z' where 1: "Z' < Z" ..
  1359   assume "\<forall>Z. eventually (\<lambda>x. f x \<le> Z) F"
  1360   hence "eventually (\<lambda>x. f x \<le> Z') F" by auto
  1361   thus "eventually (\<lambda>x. f x < Z) F"
  1362     apply (rule eventually_mono[rotated])
  1363     using 1 by auto
  1364   next 
  1365     fix Z :: 'b 
  1366     show "\<forall>Z. eventually (\<lambda>x. f x < Z) F \<Longrightarrow> eventually (\<lambda>x. f x \<le> Z) F"
  1367       by (drule spec [of _ Z], erule eventually_mono[rotated], auto simp add: less_imp_le)
  1368 qed
  1369 
  1370 lemma filterlim_at_bot_le:
  1371   fixes f :: "'a \<Rightarrow> ('b::linorder)" and c :: "'b"
  1372   shows "(LIM x F. f x :> at_bot) \<longleftrightarrow> (\<forall>Z\<le>c. eventually (\<lambda>x. Z \<ge> f x) F)"
  1373   unfolding filterlim_at_bot
  1374 proof safe
  1375   fix Z assume *: "\<forall>Z\<le>c. eventually (\<lambda>x. Z \<ge> f x) F"
  1376   with *[THEN spec, of "min Z c"] show "eventually (\<lambda>x. Z \<ge> f x) F"
  1377     by (auto elim!: eventually_elim1)
  1378 qed simp
  1379 
  1380 lemma filterlim_at_bot_lt:
  1381   fixes f :: "'a \<Rightarrow> ('b::unbounded_dense_linorder)" and c :: "'b"
  1382   shows "(LIM x F. f x :> at_bot) \<longleftrightarrow> (\<forall>Z<c. eventually (\<lambda>x. Z \<ge> f x) F)"
  1383   by (metis filterlim_at_bot filterlim_at_bot_le lt_ex order_le_less_trans)
  1384 
  1385 lemma filterlim_at_bot_at_right:
  1386   fixes f :: "'a::linorder_topology \<Rightarrow> 'b::linorder"
  1387   assumes mono: "\<And>x y. Q x \<Longrightarrow> Q y \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y"
  1388   assumes bij: "\<And>x. P x \<Longrightarrow> f (g x) = x" "\<And>x. P x \<Longrightarrow> Q (g x)"
  1389   assumes Q: "eventually Q (at_right a)" and bound: "\<And>b. Q b \<Longrightarrow> a < b"
  1390   assumes P: "eventually P at_bot"
  1391   shows "filterlim f at_bot (at_right a)"
  1392 proof -
  1393   from P obtain x where x: "\<And>y. y \<le> x \<Longrightarrow> P y"
  1394     unfolding eventually_at_bot_linorder by auto
  1395   show ?thesis
  1396   proof (intro filterlim_at_bot_le[THEN iffD2] allI impI)
  1397     fix z assume "z \<le> x"
  1398     with x have "P z" by auto
  1399     have "eventually (\<lambda>x. x \<le> g z) (at_right a)"
  1400       using bound[OF bij(2)[OF `P z`]]
  1401       unfolding eventually_at_right[OF bound[OF bij(2)[OF `P z`]]] by (auto intro!: exI[of _ "g z"])
  1402     with Q show "eventually (\<lambda>x. f x \<le> z) (at_right a)"
  1403       by eventually_elim (metis bij `P z` mono)
  1404   qed
  1405 qed
  1406 
  1407 lemma filterlim_at_top_at_left:
  1408   fixes f :: "'a::linorder_topology \<Rightarrow> 'b::linorder"
  1409   assumes mono: "\<And>x y. Q x \<Longrightarrow> Q y \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y"
  1410   assumes bij: "\<And>x. P x \<Longrightarrow> f (g x) = x" "\<And>x. P x \<Longrightarrow> Q (g x)"
  1411   assumes Q: "eventually Q (at_left a)" and bound: "\<And>b. Q b \<Longrightarrow> b < a"
  1412   assumes P: "eventually P at_top"
  1413   shows "filterlim f at_top (at_left a)"
  1414 proof -
  1415   from P obtain x where x: "\<And>y. x \<le> y \<Longrightarrow> P y"
  1416     unfolding eventually_at_top_linorder by auto
  1417   show ?thesis
  1418   proof (intro filterlim_at_top_ge[THEN iffD2] allI impI)
  1419     fix z assume "x \<le> z"
  1420     with x have "P z" by auto
  1421     have "eventually (\<lambda>x. g z \<le> x) (at_left a)"
  1422       using bound[OF bij(2)[OF `P z`]]
  1423       unfolding eventually_at_left[OF bound[OF bij(2)[OF `P z`]]] by (auto intro!: exI[of _ "g z"])
  1424     with Q show "eventually (\<lambda>x. z \<le> f x) (at_left a)"
  1425       by eventually_elim (metis bij `P z` mono)
  1426   qed
  1427 qed
  1428 
  1429 lemma filterlim_split_at:
  1430   "filterlim f F (at_left x) \<Longrightarrow> filterlim f F (at_right x) \<Longrightarrow> filterlim f F (at (x::'a::linorder_topology))"
  1431   by (subst at_eq_sup_left_right) (rule filterlim_sup)
  1432 
  1433 lemma filterlim_at_split:
  1434   "filterlim f F (at (x::'a::linorder_topology)) \<longleftrightarrow> filterlim f F (at_left x) \<and> filterlim f F (at_right x)"
  1435   by (subst at_eq_sup_left_right) (simp add: filterlim_def filtermap_sup)
  1436 
  1437 lemma eventually_nhds_top:
  1438   fixes P :: "'a :: {order_top, linorder_topology} \<Rightarrow> bool"
  1439   assumes "(b::'a) < top"
  1440   shows "eventually P (nhds top) \<longleftrightarrow> (\<exists>b<top. (\<forall>z. b < z \<longrightarrow> P z))"
  1441   unfolding eventually_nhds
  1442 proof safe
  1443   fix S :: "'a set" assume "open S" "top \<in> S"
  1444   note open_left[OF this `b < top`]
  1445   moreover assume "\<forall>s\<in>S. P s"
  1446   ultimately show "\<exists>b<top. \<forall>z>b. P z"
  1447     by (auto simp: subset_eq Ball_def)
  1448 next
  1449   fix b assume "b < top" "\<forall>z>b. P z"
  1450   then show "\<exists>S. open S \<and> top \<in> S \<and> (\<forall>xa\<in>S. P xa)"
  1451     by (intro exI[of _ "{b <..}"]) auto
  1452 qed
  1453 
  1454 lemma tendsto_at_within_iff_tendsto_nhds:
  1455   "(g ---> g l) (at l within S) \<longleftrightarrow> (g ---> g l) (inf (nhds l) (principal S))"
  1456   unfolding tendsto_def eventually_at_filter eventually_inf_principal
  1457   by (intro ext all_cong imp_cong) (auto elim!: eventually_elim1)
  1458 
  1459 subsection {* Limits on sequences *}
  1460 
  1461 abbreviation (in topological_space)
  1462   LIMSEQ :: "[nat \<Rightarrow> 'a, 'a] \<Rightarrow> bool"
  1463     ("((_)/ ----> (_))" [60, 60] 60) where
  1464   "X ----> L \<equiv> (X ---> L) sequentially"
  1465 
  1466 abbreviation (in t2_space) lim :: "(nat \<Rightarrow> 'a) \<Rightarrow> 'a" where
  1467   "lim X \<equiv> Lim sequentially X"
  1468 
  1469 definition (in topological_space) convergent :: "(nat \<Rightarrow> 'a) \<Rightarrow> bool" where
  1470   "convergent X = (\<exists>L. X ----> L)"
  1471 
  1472 lemma lim_def: "lim X = (THE L. X ----> L)"
  1473   unfolding Lim_def ..
  1474 
  1475 subsubsection {* Monotone sequences and subsequences *}
  1476 
  1477 definition
  1478   monoseq :: "(nat \<Rightarrow> 'a::order) \<Rightarrow> bool" where
  1479     --{*Definition of monotonicity.
  1480         The use of disjunction here complicates proofs considerably.
  1481         One alternative is to add a Boolean argument to indicate the direction.
  1482         Another is to develop the notions of increasing and decreasing first.*}
  1483   "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))"
  1484 
  1485 abbreviation incseq :: "(nat \<Rightarrow> 'a::order) \<Rightarrow> bool" where
  1486   "incseq X \<equiv> mono X"
  1487 
  1488 lemma incseq_def: "incseq X \<longleftrightarrow> (\<forall>m. \<forall>n\<ge>m. X n \<ge> X m)"
  1489   unfolding mono_def ..
  1490 
  1491 abbreviation decseq :: "(nat \<Rightarrow> 'a::order) \<Rightarrow> bool" where
  1492   "decseq X \<equiv> antimono X"
  1493 
  1494 lemma decseq_def: "decseq X \<longleftrightarrow> (\<forall>m. \<forall>n\<ge>m. X n \<le> X m)"
  1495   unfolding antimono_def ..
  1496 
  1497 definition
  1498   subseq :: "(nat \<Rightarrow> nat) \<Rightarrow> bool" where
  1499     --{*Definition of subsequence*}
  1500   "subseq f \<longleftrightarrow> (\<forall>m. \<forall>n>m. f m < f n)"
  1501 
  1502 lemma incseq_SucI:
  1503   "(\<And>n. X n \<le> X (Suc n)) \<Longrightarrow> incseq X"
  1504   using lift_Suc_mono_le[of X]
  1505   by (auto simp: incseq_def)
  1506 
  1507 lemma incseqD: "\<And>i j. incseq f \<Longrightarrow> i \<le> j \<Longrightarrow> f i \<le> f j"
  1508   by (auto simp: incseq_def)
  1509 
  1510 lemma incseq_SucD: "incseq A \<Longrightarrow> A i \<le> A (Suc i)"
  1511   using incseqD[of A i "Suc i"] by auto
  1512 
  1513 lemma incseq_Suc_iff: "incseq f \<longleftrightarrow> (\<forall>n. f n \<le> f (Suc n))"
  1514   by (auto intro: incseq_SucI dest: incseq_SucD)
  1515 
  1516 lemma incseq_const[simp, intro]: "incseq (\<lambda>x. k)"
  1517   unfolding incseq_def by auto
  1518 
  1519 lemma decseq_SucI:
  1520   "(\<And>n. X (Suc n) \<le> X n) \<Longrightarrow> decseq X"
  1521   using order.lift_Suc_mono_le[OF dual_order, of X]
  1522   by (auto simp: decseq_def)
  1523 
  1524 lemma decseqD: "\<And>i j. decseq f \<Longrightarrow> i \<le> j \<Longrightarrow> f j \<le> f i"
  1525   by (auto simp: decseq_def)
  1526 
  1527 lemma decseq_SucD: "decseq A \<Longrightarrow> A (Suc i) \<le> A i"
  1528   using decseqD[of A i "Suc i"] by auto
  1529 
  1530 lemma decseq_Suc_iff: "decseq f \<longleftrightarrow> (\<forall>n. f (Suc n) \<le> f n)"
  1531   by (auto intro: decseq_SucI dest: decseq_SucD)
  1532 
  1533 lemma decseq_const[simp, intro]: "decseq (\<lambda>x. k)"
  1534   unfolding decseq_def by auto
  1535 
  1536 lemma monoseq_iff: "monoseq X \<longleftrightarrow> incseq X \<or> decseq X"
  1537   unfolding monoseq_def incseq_def decseq_def ..
  1538 
  1539 lemma monoseq_Suc:
  1540   "monoseq X \<longleftrightarrow> (\<forall>n. X n \<le> X (Suc n)) \<or> (\<forall>n. X (Suc n) \<le> X n)"
  1541   unfolding monoseq_iff incseq_Suc_iff decseq_Suc_iff ..
  1542 
  1543 lemma monoI1: "\<forall>m. \<forall> n \<ge> m. X m \<le> X n ==> monoseq X"
  1544 by (simp add: monoseq_def)
  1545 
  1546 lemma monoI2: "\<forall>m. \<forall> n \<ge> m. X n \<le> X m ==> monoseq X"
  1547 by (simp add: monoseq_def)
  1548 
  1549 lemma mono_SucI1: "\<forall>n. X n \<le> X (Suc n) ==> monoseq X"
  1550 by (simp add: monoseq_Suc)
  1551 
  1552 lemma mono_SucI2: "\<forall>n. X (Suc n) \<le> X n ==> monoseq X"
  1553 by (simp add: monoseq_Suc)
  1554 
  1555 lemma monoseq_minus:
  1556   fixes a :: "nat \<Rightarrow> 'a::ordered_ab_group_add"
  1557   assumes "monoseq a"
  1558   shows "monoseq (\<lambda> n. - a n)"
  1559 proof (cases "\<forall> m. \<forall> n \<ge> m. a m \<le> a n")
  1560   case True
  1561   hence "\<forall> m. \<forall> n \<ge> m. - a n \<le> - a m" by auto
  1562   thus ?thesis by (rule monoI2)
  1563 next
  1564   case False
  1565   hence "\<forall> m. \<forall> n \<ge> m. - a m \<le> - a n" using `monoseq a`[unfolded monoseq_def] by auto
  1566   thus ?thesis by (rule monoI1)
  1567 qed
  1568 
  1569 text{*Subsequence (alternative definition, (e.g. Hoskins)*}
  1570 
  1571 lemma subseq_Suc_iff: "subseq f = (\<forall>n. (f n) < (f (Suc n)))"
  1572 apply (simp add: subseq_def)
  1573 apply (auto dest!: less_imp_Suc_add)
  1574 apply (induct_tac k)
  1575 apply (auto intro: less_trans)
  1576 done
  1577 
  1578 text{* for any sequence, there is a monotonic subsequence *}
  1579 lemma seq_monosub:
  1580   fixes s :: "nat => 'a::linorder"
  1581   shows "\<exists>f. subseq f \<and> monoseq (\<lambda>n. (s (f n)))"
  1582 proof cases
  1583   assume "\<forall>n. \<exists>p>n. \<forall>m\<ge>p. s m \<le> s p"
  1584   then have "\<exists>f. \<forall>n. (\<forall>m\<ge>f n. s m \<le> s (f n)) \<and> f n < f (Suc n)"
  1585     by (intro dependent_nat_choice) (auto simp: conj_commute)
  1586   then obtain f where "subseq f" and mono: "\<And>n m. f n \<le> m \<Longrightarrow> s m \<le> s (f n)"
  1587     by (auto simp: subseq_Suc_iff)
  1588   moreover 
  1589   then have "incseq f"
  1590     unfolding subseq_Suc_iff incseq_Suc_iff by (auto intro: less_imp_le)
  1591   then have "monoseq (\<lambda>n. s (f n))"
  1592     by (auto simp add: incseq_def intro!: mono monoI2)
  1593   ultimately show ?thesis
  1594     by auto
  1595 next
  1596   assume "\<not> (\<forall>n. \<exists>p>n. (\<forall>m\<ge>p. s m \<le> s p))"
  1597   then obtain N where N: "\<And>p. p > N \<Longrightarrow> \<exists>m>p. s p < s m" by (force simp: not_le le_less)
  1598   have "\<exists>f. \<forall>n. N < f n \<and> f n < f (Suc n) \<and> s (f n) \<le> s (f (Suc n))"
  1599   proof (intro dependent_nat_choice)
  1600     fix x assume "N < x" with N[of x] show "\<exists>y>N. x < y \<and> s x \<le> s y"
  1601       by (auto intro: less_trans)
  1602   qed auto
  1603   then show ?thesis
  1604     by (auto simp: monoseq_iff incseq_Suc_iff subseq_Suc_iff)
  1605 qed
  1606 
  1607 lemma seq_suble: assumes sf: "subseq f" shows "n \<le> f n"
  1608 proof(induct n)
  1609   case 0 thus ?case by simp
  1610 next
  1611   case (Suc n)
  1612   from sf[unfolded subseq_Suc_iff, rule_format, of n] Suc.hyps
  1613   have "n < f (Suc n)" by arith
  1614   thus ?case by arith
  1615 qed
  1616 
  1617 lemma eventually_subseq:
  1618   "subseq r \<Longrightarrow> eventually P sequentially \<Longrightarrow> eventually (\<lambda>n. P (r n)) sequentially"
  1619   unfolding eventually_sequentially by (metis seq_suble le_trans)
  1620 
  1621 lemma not_eventually_sequentiallyD:
  1622   assumes P: "\<not> eventually P sequentially"
  1623   shows "\<exists>r. subseq r \<and> (\<forall>n. \<not> P (r n))"
  1624 proof -
  1625   from P have "\<forall>n. \<exists>m\<ge>n. \<not> P m"
  1626     unfolding eventually_sequentially by (simp add: not_less)
  1627   then obtain r where "\<And>n. r n \<ge> n" "\<And>n. \<not> P (r n)"
  1628     by (auto simp: choice_iff)
  1629   then show ?thesis
  1630     by (auto intro!: exI[of _ "\<lambda>n. r (((Suc \<circ> r) ^^ Suc n) 0)"]
  1631              simp: less_eq_Suc_le subseq_Suc_iff)
  1632 qed
  1633 
  1634 lemma filterlim_subseq: "subseq f \<Longrightarrow> filterlim f sequentially sequentially"
  1635   unfolding filterlim_iff by (metis eventually_subseq)
  1636 
  1637 lemma subseq_o: "subseq r \<Longrightarrow> subseq s \<Longrightarrow> subseq (r \<circ> s)"
  1638   unfolding subseq_def by simp
  1639 
  1640 lemma subseq_mono: assumes "subseq r" "m < n" shows "r m < r n"
  1641   using assms by (auto simp: subseq_def)
  1642 
  1643 lemma incseq_imp_monoseq:  "incseq X \<Longrightarrow> monoseq X"
  1644   by (simp add: incseq_def monoseq_def)
  1645 
  1646 lemma decseq_imp_monoseq:  "decseq X \<Longrightarrow> monoseq X"
  1647   by (simp add: decseq_def monoseq_def)
  1648 
  1649 lemma decseq_eq_incseq:
  1650   fixes X :: "nat \<Rightarrow> 'a::ordered_ab_group_add" shows "decseq X = incseq (\<lambda>n. - X n)" 
  1651   by (simp add: decseq_def incseq_def)
  1652 
  1653 lemma INT_decseq_offset:
  1654   assumes "decseq F"
  1655   shows "(\<Inter>i. F i) = (\<Inter>i\<in>{n..}. F i)"
  1656 proof safe
  1657   fix x i assume x: "x \<in> (\<Inter>i\<in>{n..}. F i)"
  1658   show "x \<in> F i"
  1659   proof cases
  1660     from x have "x \<in> F n" by auto
  1661     also assume "i \<le> n" with `decseq F` have "F n \<subseteq> F i"
  1662       unfolding decseq_def by simp
  1663     finally show ?thesis .
  1664   qed (insert x, simp)
  1665 qed auto
  1666 
  1667 lemma LIMSEQ_const_iff:
  1668   fixes k l :: "'a::t2_space"
  1669   shows "(\<lambda>n. k) ----> l \<longleftrightarrow> k = l"
  1670   using trivial_limit_sequentially by (rule tendsto_const_iff)
  1671 
  1672 lemma LIMSEQ_SUP:
  1673   "incseq X \<Longrightarrow> X ----> (SUP i. X i :: 'a :: {complete_linorder, linorder_topology})"
  1674   by (intro increasing_tendsto)
  1675      (auto simp: SUP_upper less_SUP_iff incseq_def eventually_sequentially intro: less_le_trans)
  1676 
  1677 lemma LIMSEQ_INF:
  1678   "decseq X \<Longrightarrow> X ----> (INF i. X i :: 'a :: {complete_linorder, linorder_topology})"
  1679   by (intro decreasing_tendsto)
  1680      (auto simp: INF_lower INF_less_iff decseq_def eventually_sequentially intro: le_less_trans)
  1681 
  1682 lemma LIMSEQ_ignore_initial_segment:
  1683   "f ----> a \<Longrightarrow> (\<lambda>n. f (n + k)) ----> a"
  1684   unfolding tendsto_def
  1685   by (subst eventually_sequentially_seg[where k=k])
  1686 
  1687 lemma LIMSEQ_offset:
  1688   "(\<lambda>n. f (n + k)) ----> a \<Longrightarrow> f ----> a"
  1689   unfolding tendsto_def
  1690   by (subst (asm) eventually_sequentially_seg[where k=k])
  1691 
  1692 lemma LIMSEQ_Suc: "f ----> l \<Longrightarrow> (\<lambda>n. f (Suc n)) ----> l"
  1693 by (drule_tac k="Suc 0" in LIMSEQ_ignore_initial_segment, simp)
  1694 
  1695 lemma LIMSEQ_imp_Suc: "(\<lambda>n. f (Suc n)) ----> l \<Longrightarrow> f ----> l"
  1696 by (rule_tac k="Suc 0" in LIMSEQ_offset, simp)
  1697 
  1698 lemma LIMSEQ_Suc_iff: "(\<lambda>n. f (Suc n)) ----> l = f ----> l"
  1699 by (blast intro: LIMSEQ_imp_Suc LIMSEQ_Suc)
  1700 
  1701 lemma LIMSEQ_unique:
  1702   fixes a b :: "'a::t2_space"
  1703   shows "\<lbrakk>X ----> a; X ----> b\<rbrakk> \<Longrightarrow> a = b"
  1704   using trivial_limit_sequentially by (rule tendsto_unique)
  1705 
  1706 lemma LIMSEQ_le_const:
  1707   "\<lbrakk>X ----> (x::'a::linorder_topology); \<exists>N. \<forall>n\<ge>N. a \<le> X n\<rbrakk> \<Longrightarrow> a \<le> x"
  1708   using tendsto_le_const[of sequentially X x a] by (simp add: eventually_sequentially)
  1709 
  1710 lemma LIMSEQ_le:
  1711   "\<lbrakk>X ----> x; Y ----> y; \<exists>N. \<forall>n\<ge>N. X n \<le> Y n\<rbrakk> \<Longrightarrow> x \<le> (y::'a::linorder_topology)"
  1712   using tendsto_le[of sequentially Y y X x] by (simp add: eventually_sequentially)
  1713 
  1714 lemma LIMSEQ_le_const2:
  1715   "\<lbrakk>X ----> (x::'a::linorder_topology); \<exists>N. \<forall>n\<ge>N. X n \<le> a\<rbrakk> \<Longrightarrow> x \<le> a"
  1716   by (rule LIMSEQ_le[of X x "\<lambda>n. a"]) auto
  1717 
  1718 lemma convergentD: "convergent X ==> \<exists>L. (X ----> L)"
  1719 by (simp add: convergent_def)
  1720 
  1721 lemma convergentI: "(X ----> L) ==> convergent X"
  1722 by (auto simp add: convergent_def)
  1723 
  1724 lemma convergent_LIMSEQ_iff: "convergent X = (X ----> lim X)"
  1725 by (auto intro: theI LIMSEQ_unique simp add: convergent_def lim_def)
  1726 
  1727 lemma convergent_const: "convergent (\<lambda>n. c)"
  1728   by (rule convergentI, rule tendsto_const)
  1729 
  1730 lemma monoseq_le:
  1731   "monoseq a \<Longrightarrow> a ----> (x::'a::linorder_topology) \<Longrightarrow>
  1732     ((\<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))"
  1733   by (metis LIMSEQ_le_const LIMSEQ_le_const2 decseq_def incseq_def monoseq_iff)
  1734 
  1735 lemma LIMSEQ_subseq_LIMSEQ:
  1736   "\<lbrakk> X ----> L; subseq f \<rbrakk> \<Longrightarrow> (X o f) ----> L"
  1737   unfolding comp_def by (rule filterlim_compose[of X, OF _ filterlim_subseq])
  1738 
  1739 lemma convergent_subseq_convergent:
  1740   "\<lbrakk>convergent X; subseq f\<rbrakk> \<Longrightarrow> convergent (X o f)"
  1741   unfolding convergent_def by (auto intro: LIMSEQ_subseq_LIMSEQ)
  1742 
  1743 lemma limI: "X ----> L ==> lim X = L"
  1744   by (rule tendsto_Lim) (rule trivial_limit_sequentially)
  1745 
  1746 lemma lim_le: "convergent f \<Longrightarrow> (\<And>n. f n \<le> (x::'a::linorder_topology)) \<Longrightarrow> lim f \<le> x"
  1747   using LIMSEQ_le_const2[of f "lim f" x] by (simp add: convergent_LIMSEQ_iff)
  1748 
  1749 subsubsection{*Increasing and Decreasing Series*}
  1750 
  1751 lemma incseq_le: "incseq X \<Longrightarrow> X ----> L \<Longrightarrow> X n \<le> (L::'a::linorder_topology)"
  1752   by (metis incseq_def LIMSEQ_le_const)
  1753 
  1754 lemma decseq_le: "decseq X \<Longrightarrow> X ----> L \<Longrightarrow> (L::'a::linorder_topology) \<le> X n"
  1755   by (metis decseq_def LIMSEQ_le_const2)
  1756 
  1757 subsection {* First countable topologies *}
  1758 
  1759 class first_countable_topology = topological_space +
  1760   assumes first_countable_basis:
  1761     "\<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))"
  1762 
  1763 lemma (in first_countable_topology) countable_basis_at_decseq:
  1764   obtains A :: "nat \<Rightarrow> 'a set" where
  1765     "\<And>i. open (A i)" "\<And>i. x \<in> (A i)"
  1766     "\<And>S. open S \<Longrightarrow> x \<in> S \<Longrightarrow> eventually (\<lambda>i. A i \<subseteq> S) sequentially"
  1767 proof atomize_elim
  1768   from first_countable_basis[of x] obtain A :: "nat \<Rightarrow> 'a set" where
  1769     nhds: "\<And>i. open (A i)" "\<And>i. x \<in> A i"
  1770     and incl: "\<And>S. open S \<Longrightarrow> x \<in> S \<Longrightarrow> \<exists>i. A i \<subseteq> S"  by auto
  1771   def F \<equiv> "\<lambda>n. \<Inter>i\<le>n. A i"
  1772   show "\<exists>A. (\<forall>i. open (A i)) \<and> (\<forall>i. x \<in> A i) \<and>
  1773       (\<forall>S. open S \<longrightarrow> x \<in> S \<longrightarrow> eventually (\<lambda>i. A i \<subseteq> S) sequentially)"
  1774   proof (safe intro!: exI[of _ F])
  1775     fix i
  1776     show "open (F i)" using nhds(1) by (auto simp: F_def)
  1777     show "x \<in> F i" using nhds(2) by (auto simp: F_def)
  1778   next
  1779     fix S assume "open S" "x \<in> S"
  1780     from incl[OF this] obtain i where "F i \<subseteq> S" unfolding F_def by auto
  1781     moreover have "\<And>j. i \<le> j \<Longrightarrow> F j \<subseteq> F i"
  1782       by (auto simp: F_def)
  1783     ultimately show "eventually (\<lambda>i. F i \<subseteq> S) sequentially"
  1784       by (auto simp: eventually_sequentially)
  1785   qed
  1786 qed
  1787 
  1788 lemma (in first_countable_topology) nhds_countable:
  1789   obtains X :: "nat \<Rightarrow> 'a set"
  1790   where "decseq X" "\<And>n. open (X n)" "\<And>n. x \<in> X n" "nhds x = (INF n. principal (X n))"
  1791 proof -
  1792   from first_countable_basis obtain A :: "nat \<Rightarrow> 'a set"
  1793     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"
  1794     by metis
  1795   show thesis
  1796   proof
  1797     show "decseq (\<lambda>n. \<Inter>i\<le>n. A i)"
  1798       by (auto simp: decseq_def)
  1799     show "\<And>n. x \<in> (\<Inter>i\<le>n. A i)" "\<And>n. open (\<Inter>i\<le>n. A i)"
  1800       using A by auto
  1801     show "nhds x = (INF n. principal (\<Inter> i\<le>n. A i))"
  1802       using A unfolding nhds_def
  1803       apply (intro INF_eq)
  1804       apply simp_all
  1805       apply force
  1806       apply (intro exI[of _ "\<Inter> i\<le>n. A i" for n] conjI open_INT)
  1807       apply auto
  1808       done
  1809   qed
  1810 qed
  1811 
  1812 lemma (in first_countable_topology) countable_basis:
  1813   obtains A :: "nat \<Rightarrow> 'a set" where
  1814     "\<And>i. open (A i)" "\<And>i. x \<in> A i"
  1815     "\<And>F. (\<forall>n. F n \<in> A n) \<Longrightarrow> F ----> x"
  1816 proof atomize_elim
  1817   obtain A :: "nat \<Rightarrow> 'a set" where A:
  1818     "\<And>i. open (A i)"
  1819     "\<And>i. x \<in> A i"
  1820     "\<And>S. open S \<Longrightarrow> x \<in> S \<Longrightarrow> eventually (\<lambda>i. A i \<subseteq> S) sequentially"
  1821     by (rule countable_basis_at_decseq) blast
  1822   {
  1823     fix F S assume "\<forall>n. F n \<in> A n" "open S" "x \<in> S"
  1824     with A(3)[of S] have "eventually (\<lambda>n. F n \<in> S) sequentially"
  1825       by (auto elim: eventually_elim1 simp: subset_eq)
  1826   }
  1827   with A show "\<exists>A. (\<forall>i. open (A i)) \<and> (\<forall>i. x \<in> A i) \<and> (\<forall>F. (\<forall>n. F n \<in> A n) \<longrightarrow> F ----> x)"
  1828     by (intro exI[of _ A]) (auto simp: tendsto_def)
  1829 qed
  1830 
  1831 lemma (in first_countable_topology) sequentially_imp_eventually_nhds_within:
  1832   assumes "\<forall>f. (\<forall>n. f n \<in> s) \<and> f ----> a \<longrightarrow> eventually (\<lambda>n. P (f n)) sequentially"
  1833   shows "eventually P (inf (nhds a) (principal s))"
  1834 proof (rule ccontr)
  1835   obtain A :: "nat \<Rightarrow> 'a set" where A:
  1836     "\<And>i. open (A i)"
  1837     "\<And>i. a \<in> A i"
  1838     "\<And>F. \<forall>n. F n \<in> A n \<Longrightarrow> F ----> a"
  1839     by (rule countable_basis) blast
  1840   assume "\<not> ?thesis"
  1841   with A have P: "\<exists>F. \<forall>n. F n \<in> s \<and> F n \<in> A n \<and> \<not> P (F n)"
  1842     unfolding eventually_inf_principal eventually_nhds by (intro choice) fastforce
  1843   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)"
  1844     by blast
  1845   with A have "F ----> a" by auto
  1846   hence "eventually (\<lambda>n. P (F n)) sequentially"
  1847     using assms F0 by simp
  1848   thus "False" by (simp add: F3)
  1849 qed
  1850 
  1851 lemma (in first_countable_topology) eventually_nhds_within_iff_sequentially:
  1852   "eventually P (inf (nhds a) (principal s)) \<longleftrightarrow> 
  1853     (\<forall>f. (\<forall>n. f n \<in> s) \<and> f ----> a \<longrightarrow> eventually (\<lambda>n. P (f n)) sequentially)"
  1854 proof (safe intro!: sequentially_imp_eventually_nhds_within)
  1855   assume "eventually P (inf (nhds a) (principal s))" 
  1856   then obtain S where "open S" "a \<in> S" "\<forall>x\<in>S. x \<in> s \<longrightarrow> P x"
  1857     by (auto simp: eventually_inf_principal eventually_nhds)
  1858   moreover fix f assume "\<forall>n. f n \<in> s" "f ----> a"
  1859   ultimately show "eventually (\<lambda>n. P (f n)) sequentially"
  1860     by (auto dest!: topological_tendstoD elim: eventually_elim1)
  1861 qed
  1862 
  1863 lemma (in first_countable_topology) eventually_nhds_iff_sequentially:
  1864   "eventually P (nhds a) \<longleftrightarrow> (\<forall>f. f ----> a \<longrightarrow> eventually (\<lambda>n. P (f n)) sequentially)"
  1865   using eventually_nhds_within_iff_sequentially[of P a UNIV] by simp
  1866 
  1867 lemma tendsto_at_iff_sequentially:
  1868   fixes f :: "'a :: first_countable_topology \<Rightarrow> _"
  1869   shows "(f ---> a) (at x within s) \<longleftrightarrow> (\<forall>X. (\<forall>i. X i \<in> s - {x}) \<longrightarrow> X ----> x \<longrightarrow> ((f \<circ> X) ----> a))"
  1870   unfolding filterlim_def[of _ "nhds a"] le_filter_def eventually_filtermap at_within_def eventually_nhds_within_iff_sequentially comp_def
  1871   by metis
  1872 
  1873 subsection {* Function limit at a point *}
  1874 
  1875 abbreviation
  1876   LIM :: "('a::topological_space \<Rightarrow> 'b::topological_space) \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> bool"
  1877         ("((_)/ -- (_)/ --> (_))" [60, 0, 60] 60) where
  1878   "f -- a --> L \<equiv> (f ---> L) (at a)"
  1879 
  1880 lemma tendsto_within_open: "a \<in> S \<Longrightarrow> open S \<Longrightarrow> (f ---> l) (at a within S) \<longleftrightarrow> (f -- a --> l)"
  1881   unfolding tendsto_def by (simp add: at_within_open[where S=S])
  1882 
  1883 lemma LIM_const_not_eq[tendsto_intros]:
  1884   fixes a :: "'a::perfect_space"
  1885   fixes k L :: "'b::t2_space"
  1886   shows "k \<noteq> L \<Longrightarrow> \<not> (\<lambda>x. k) -- a --> L"
  1887   by (simp add: tendsto_const_iff)
  1888 
  1889 lemmas LIM_not_zero = LIM_const_not_eq [where L = 0]
  1890 
  1891 lemma LIM_const_eq:
  1892   fixes a :: "'a::perfect_space"
  1893   fixes k L :: "'b::t2_space"
  1894   shows "(\<lambda>x. k) -- a --> L \<Longrightarrow> k = L"
  1895   by (simp add: tendsto_const_iff)
  1896 
  1897 lemma LIM_unique:
  1898   fixes a :: "'a::perfect_space" and L M :: "'b::t2_space"
  1899   shows "f -- a --> L \<Longrightarrow> f -- a --> M \<Longrightarrow> L = M"
  1900   using at_neq_bot by (rule tendsto_unique)
  1901 
  1902 text {* Limits are equal for functions equal except at limit point *}
  1903 
  1904 lemma LIM_equal: "\<forall>x. x \<noteq> a --> (f x = g x) \<Longrightarrow> (f -- a --> l) \<longleftrightarrow> (g -- a --> l)"
  1905   unfolding tendsto_def eventually_at_topological by simp
  1906 
  1907 lemma LIM_cong: "a = b \<Longrightarrow> (\<And>x. x \<noteq> b \<Longrightarrow> f x = g x) \<Longrightarrow> l = m \<Longrightarrow> (f -- a --> l) \<longleftrightarrow> (g -- b --> m)"
  1908   by (simp add: LIM_equal)
  1909 
  1910 lemma LIM_cong_limit: "f -- x --> L \<Longrightarrow> K = L \<Longrightarrow> f -- x --> K"
  1911   by simp
  1912 
  1913 lemma tendsto_at_iff_tendsto_nhds:
  1914   "g -- l --> g l \<longleftrightarrow> (g ---> g l) (nhds l)"
  1915   unfolding tendsto_def eventually_at_filter
  1916   by (intro ext all_cong imp_cong) (auto elim!: eventually_elim1)
  1917 
  1918 lemma tendsto_compose:
  1919   "g -- l --> g l \<Longrightarrow> (f ---> l) F \<Longrightarrow> ((\<lambda>x. g (f x)) ---> g l) F"
  1920   unfolding tendsto_at_iff_tendsto_nhds by (rule filterlim_compose[of g])
  1921 
  1922 lemma LIM_o: "\<lbrakk>g -- l --> g l; f -- a --> l\<rbrakk> \<Longrightarrow> (g \<circ> f) -- a --> g l"
  1923   unfolding o_def by (rule tendsto_compose)
  1924 
  1925 lemma tendsto_compose_eventually:
  1926   "g -- l --> m \<Longrightarrow> (f ---> l) F \<Longrightarrow> eventually (\<lambda>x. f x \<noteq> l) F \<Longrightarrow> ((\<lambda>x. g (f x)) ---> m) F"
  1927   by (rule filterlim_compose[of g _ "at l"]) (auto simp add: filterlim_at)
  1928 
  1929 lemma LIM_compose_eventually:
  1930   assumes f: "f -- a --> b"
  1931   assumes g: "g -- b --> c"
  1932   assumes inj: "eventually (\<lambda>x. f x \<noteq> b) (at a)"
  1933   shows "(\<lambda>x. g (f x)) -- a --> c"
  1934   using g f inj by (rule tendsto_compose_eventually)
  1935 
  1936 lemma tendsto_compose_filtermap: "((g \<circ> f) ---> T) F \<longleftrightarrow> (g ---> T) (filtermap f F)"
  1937   by (simp add: filterlim_def filtermap_filtermap comp_def)
  1938 
  1939 subsubsection {* Relation of LIM and LIMSEQ *}
  1940 
  1941 lemma (in first_countable_topology) sequentially_imp_eventually_within:
  1942   "(\<forall>f. (\<forall>n. f n \<in> s \<and> f n \<noteq> a) \<and> f ----> a \<longrightarrow> eventually (\<lambda>n. P (f n)) sequentially) \<Longrightarrow>
  1943     eventually P (at a within s)"
  1944   unfolding at_within_def
  1945   by (intro sequentially_imp_eventually_nhds_within) auto
  1946 
  1947 lemma (in first_countable_topology) sequentially_imp_eventually_at:
  1948   "(\<forall>f. (\<forall>n. f n \<noteq> a) \<and> f ----> a \<longrightarrow> eventually (\<lambda>n. P (f n)) sequentially) \<Longrightarrow> eventually P (at a)"
  1949   using assms sequentially_imp_eventually_within [where s=UNIV] by simp
  1950 
  1951 lemma LIMSEQ_SEQ_conv1:
  1952   fixes f :: "'a::topological_space \<Rightarrow> 'b::topological_space"
  1953   assumes f: "f -- a --> l"
  1954   shows "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. f (S n)) ----> l"
  1955   using tendsto_compose_eventually [OF f, where F=sequentially] by simp
  1956 
  1957 lemma LIMSEQ_SEQ_conv2:
  1958   fixes f :: "'a::first_countable_topology \<Rightarrow> 'b::topological_space"
  1959   assumes "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. f (S n)) ----> l"
  1960   shows "f -- a --> l"
  1961   using assms unfolding tendsto_def [where l=l] by (simp add: sequentially_imp_eventually_at)
  1962 
  1963 lemma LIMSEQ_SEQ_conv:
  1964   "(\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> (a::'a::first_countable_topology) \<longrightarrow> (\<lambda>n. X (S n)) ----> L) =
  1965    (X -- a --> (L::'b::topological_space))"
  1966   using LIMSEQ_SEQ_conv2 LIMSEQ_SEQ_conv1 ..
  1967 
  1968 lemma sequentially_imp_eventually_at_left:
  1969   fixes a :: "'a :: {dense_linorder, linorder_topology, first_countable_topology}"
  1970   assumes b[simp]: "b < a"
  1971   assumes *: "\<And>f. (\<And>n. b < f n) \<Longrightarrow> (\<And>n. f n < a) \<Longrightarrow> incseq f \<Longrightarrow> f ----> a \<Longrightarrow> eventually (\<lambda>n. P (f n)) sequentially"
  1972   shows "eventually P (at_left a)"
  1973 proof (safe intro!: sequentially_imp_eventually_within)
  1974   fix X assume X: "\<forall>n. X n \<in> {..< a} \<and> X n \<noteq> a" "X ----> a"
  1975   show "eventually (\<lambda>n. P (X n)) sequentially"
  1976   proof (rule ccontr)
  1977     assume neg: "\<not> eventually (\<lambda>n. P (X n)) sequentially"
  1978     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))"
  1979     proof (rule dependent_nat_choice)
  1980       have "\<not> eventually (\<lambda>n. b < X n \<longrightarrow> P (X n)) sequentially"
  1981         by (intro not_eventually_impI neg order_tendstoD(1) [OF X(2) b])
  1982       then show "\<exists>x. \<not> P (X x) \<and> b < X x"
  1983         by (auto dest!: not_eventuallyD)
  1984     next
  1985       fix x n
  1986       have "\<not> eventually (\<lambda>n. Suc x \<le> n \<longrightarrow> b < X n \<longrightarrow> X x < X n \<longrightarrow> P (X n)) sequentially"
  1987         using X by (intro not_eventually_impI order_tendstoD(1)[OF X(2)] eventually_ge_at_top neg) auto
  1988       then show "\<exists>n. (\<not> P (X n) \<and> b < X n) \<and> (X x \<le> X n \<and> Suc x \<le> n)"
  1989         by (auto dest!: not_eventuallyD)
  1990     qed
  1991     then guess s ..
  1992     then have "\<And>n. b < X (s n)" "\<And>n. X (s n) < a" "incseq (\<lambda>n. X (s n))" "(\<lambda>n. X (s n)) ----> a" "\<And>n. \<not> P (X (s n))"
  1993       using X by (auto simp: subseq_Suc_iff Suc_le_eq incseq_Suc_iff intro!: LIMSEQ_subseq_LIMSEQ[OF `X ----> a`, unfolded comp_def])
  1994     from *[OF this(1,2,3,4)] this(5) show False by auto
  1995   qed
  1996 qed
  1997 
  1998 lemma tendsto_at_left_sequentially:
  1999   fixes a :: "_ :: {dense_linorder, linorder_topology, first_countable_topology}"
  2000   assumes "b < a"
  2001   assumes *: "\<And>S. (\<And>n. S n < a) \<Longrightarrow> (\<And>n. b < S n) \<Longrightarrow> incseq S \<Longrightarrow> S ----> a \<Longrightarrow> (\<lambda>n. X (S n)) ----> L"
  2002   shows "(X ---> L) (at_left a)"
  2003   using assms unfolding tendsto_def [where l=L]
  2004   by (simp add: sequentially_imp_eventually_at_left)
  2005 
  2006 lemma sequentially_imp_eventually_at_right:
  2007   fixes a :: "'a :: {dense_linorder, linorder_topology, first_countable_topology}"
  2008   assumes b[simp]: "a < b"
  2009   assumes *: "\<And>f. (\<And>n. a < f n) \<Longrightarrow> (\<And>n. f n < b) \<Longrightarrow> decseq f \<Longrightarrow> f ----> a \<Longrightarrow> eventually (\<lambda>n. P (f n)) sequentially"
  2010   shows "eventually P (at_right a)"
  2011 proof (safe intro!: sequentially_imp_eventually_within)
  2012   fix X assume X: "\<forall>n. X n \<in> {a <..} \<and> X n \<noteq> a" "X ----> a"
  2013   show "eventually (\<lambda>n. P (X n)) sequentially"
  2014   proof (rule ccontr)
  2015     assume neg: "\<not> eventually (\<lambda>n. P (X n)) sequentially"
  2016     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))"
  2017     proof (rule dependent_nat_choice)
  2018       have "\<not> eventually (\<lambda>n. X n < b \<longrightarrow> P (X n)) sequentially"
  2019         by (intro not_eventually_impI neg order_tendstoD(2) [OF X(2) b])
  2020       then show "\<exists>x. \<not> P (X x) \<and> X x < b"
  2021         by (auto dest!: not_eventuallyD)
  2022     next
  2023       fix x n
  2024       have "\<not> eventually (\<lambda>n. Suc x \<le> n \<longrightarrow> X n < b \<longrightarrow> X n < X x \<longrightarrow> P (X n)) sequentially"
  2025         using X by (intro not_eventually_impI order_tendstoD(2)[OF X(2)] eventually_ge_at_top neg) auto
  2026       then show "\<exists>n. (\<not> P (X n) \<and> X n < b) \<and> (X n \<le> X x \<and> Suc x \<le> n)"
  2027         by (auto dest!: not_eventuallyD)
  2028     qed
  2029     then guess s ..
  2030     then have "\<And>n. a < X (s n)" "\<And>n. X (s n) < b" "decseq (\<lambda>n. X (s n))" "(\<lambda>n. X (s n)) ----> a" "\<And>n. \<not> P (X (s n))"
  2031       using X by (auto simp: subseq_Suc_iff Suc_le_eq decseq_Suc_iff intro!: LIMSEQ_subseq_LIMSEQ[OF `X ----> a`, unfolded comp_def])
  2032     from *[OF this(1,2,3,4)] this(5) show False by auto
  2033   qed
  2034 qed
  2035 
  2036 lemma tendsto_at_right_sequentially:
  2037   fixes a :: "_ :: {dense_linorder, linorder_topology, first_countable_topology}"
  2038   assumes "a < b"
  2039   assumes *: "\<And>S. (\<And>n. a < S n) \<Longrightarrow> (\<And>n. S n < b) \<Longrightarrow> decseq S \<Longrightarrow> S ----> a \<Longrightarrow> (\<lambda>n. X (S n)) ----> L"
  2040   shows "(X ---> L) (at_right a)"
  2041   using assms unfolding tendsto_def [where l=L]
  2042   by (simp add: sequentially_imp_eventually_at_right)
  2043 
  2044 subsection {* Continuity *}
  2045 
  2046 subsubsection {* Continuity on a set *}
  2047 
  2048 definition continuous_on :: "'a set \<Rightarrow> ('a :: topological_space \<Rightarrow> 'b :: topological_space) \<Rightarrow> bool" where
  2049   "continuous_on s f \<longleftrightarrow> (\<forall>x\<in>s. (f ---> f x) (at x within s))"
  2050 
  2051 lemma continuous_on_cong [cong]:
  2052   "s = t \<Longrightarrow> (\<And>x. x \<in> t \<Longrightarrow> f x = g x) \<Longrightarrow> continuous_on s f \<longleftrightarrow> continuous_on t g"
  2053   unfolding continuous_on_def by (intro ball_cong filterlim_cong) (auto simp: eventually_at_filter)
  2054 
  2055 lemma continuous_on_topological:
  2056   "continuous_on s f \<longleftrightarrow>
  2057     (\<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)))"
  2058   unfolding continuous_on_def tendsto_def eventually_at_topological by metis
  2059 
  2060 lemma continuous_on_open_invariant:
  2061   "continuous_on s f \<longleftrightarrow> (\<forall>B. open B \<longrightarrow> (\<exists>A. open A \<and> A \<inter> s = f -` B \<inter> s))"
  2062 proof safe
  2063   fix B :: "'b set" assume "continuous_on s f" "open B"
  2064   then have "\<forall>x\<in>f -` B \<inter> s. (\<exists>A. open A \<and> x \<in> A \<and> s \<inter> A \<subseteq> f -` B)"
  2065     by (auto simp: continuous_on_topological subset_eq Ball_def imp_conjL)
  2066   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"
  2067     unfolding bchoice_iff ..
  2068   then show "\<exists>A. open A \<and> A \<inter> s = f -` B \<inter> s"
  2069     by (intro exI[of _ "\<Union>x\<in>f -` B \<inter> s. A x"]) auto
  2070 next
  2071   assume B: "\<forall>B. open B \<longrightarrow> (\<exists>A. open A \<and> A \<inter> s = f -` B \<inter> s)"
  2072   show "continuous_on s f"
  2073     unfolding continuous_on_topological
  2074   proof safe
  2075     fix x B assume "x \<in> s" "open B" "f x \<in> B"
  2076     with B obtain A where A: "open A" "A \<inter> s = f -` B \<inter> s" by auto
  2077     with `x \<in> s` `f x \<in> B` show "\<exists>A. open A \<and> x \<in> A \<and> (\<forall>y\<in>s. y \<in> A \<longrightarrow> f y \<in> B)"
  2078       by (intro exI[of _ A]) auto
  2079   qed
  2080 qed
  2081 
  2082 lemma continuous_on_open_vimage:
  2083   "open s \<Longrightarrow> continuous_on s f \<longleftrightarrow> (\<forall>B. open B \<longrightarrow> open (f -` B \<inter> s))"
  2084   unfolding continuous_on_open_invariant
  2085   by (metis open_Int Int_absorb Int_commute[of s] Int_assoc[of _ _ s])
  2086 
  2087 corollary continuous_imp_open_vimage:
  2088   assumes "continuous_on s f" "open s" "open B" "f -` B \<subseteq> s"
  2089     shows "open (f -` B)"
  2090 by (metis assms continuous_on_open_vimage le_iff_inf)
  2091 
  2092 corollary open_vimage[continuous_intros]:
  2093   assumes "open s" and "continuous_on UNIV f"
  2094   shows "open (f -` s)"
  2095   using assms unfolding continuous_on_open_vimage [OF open_UNIV]
  2096   by simp
  2097 
  2098 lemma continuous_on_closed_invariant:
  2099   "continuous_on s f \<longleftrightarrow> (\<forall>B. closed B \<longrightarrow> (\<exists>A. closed A \<and> A \<inter> s = f -` B \<inter> s))"
  2100 proof -
  2101   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)"
  2102     by (metis double_compl)
  2103   show ?thesis
  2104     unfolding continuous_on_open_invariant by (intro *) (auto simp: open_closed[symmetric])
  2105 qed
  2106 
  2107 lemma continuous_on_closed_vimage:
  2108   "closed s \<Longrightarrow> continuous_on s f \<longleftrightarrow> (\<forall>B. closed B \<longrightarrow> closed (f -` B \<inter> s))"
  2109   unfolding continuous_on_closed_invariant
  2110   by (metis closed_Int Int_absorb Int_commute[of s] Int_assoc[of _ _ s])
  2111 
  2112 corollary closed_vimage[continuous_intros]:
  2113   assumes "closed s" and "continuous_on UNIV f"
  2114   shows "closed (f -` s)"
  2115   using assms unfolding continuous_on_closed_vimage [OF closed_UNIV]
  2116   by simp
  2117 
  2118 lemma continuous_on_open_Union:
  2119   "(\<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"
  2120   unfolding continuous_on_def by safe (metis open_Union at_within_open UnionI)
  2121 
  2122 lemma continuous_on_open_UN:
  2123   "(\<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"
  2124   unfolding Union_image_eq[symmetric] by (rule continuous_on_open_Union) auto
  2125 
  2126 lemma continuous_on_closed_Un:
  2127   "closed s \<Longrightarrow> closed t \<Longrightarrow> continuous_on s f \<Longrightarrow> continuous_on t f \<Longrightarrow> continuous_on (s \<union> t) f"
  2128   by (auto simp add: continuous_on_closed_vimage closed_Un Int_Un_distrib)
  2129 
  2130 lemma continuous_on_If:
  2131   assumes closed: "closed s" "closed t" and cont: "continuous_on s f" "continuous_on t g"
  2132     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"
  2133   shows "continuous_on (s \<union> t) (\<lambda>x. if P x then f x else g x)" (is "continuous_on _ ?h")
  2134 proof-
  2135   from P have "\<forall>x\<in>s. f x = ?h x" "\<forall>x\<in>t. g x = ?h x"
  2136     by auto
  2137   with cont have "continuous_on s ?h" "continuous_on t ?h"
  2138     by simp_all
  2139   with closed show ?thesis
  2140     by (rule continuous_on_closed_Un)
  2141 qed
  2142 
  2143 lemma continuous_on_id[continuous_intros]: "continuous_on s (\<lambda>x. x)"
  2144   unfolding continuous_on_def by fast
  2145 
  2146 lemma continuous_on_const[continuous_intros]: "continuous_on s (\<lambda>x. c)"
  2147   unfolding continuous_on_def by auto
  2148 
  2149 lemma continuous_on_compose[continuous_intros]:
  2150   "continuous_on s f \<Longrightarrow> continuous_on (f ` s) g \<Longrightarrow> continuous_on s (g o f)"
  2151   unfolding continuous_on_topological by simp metis
  2152 
  2153 lemma continuous_on_compose2:
  2154   "continuous_on t g \<Longrightarrow> continuous_on s f \<Longrightarrow> t = f ` s \<Longrightarrow> continuous_on s (\<lambda>x. g (f x))"
  2155   using continuous_on_compose[of s f g] by (simp add: comp_def)
  2156 
  2157 subsubsection {* Continuity at a point *}
  2158 
  2159 definition continuous :: "'a::t2_space filter \<Rightarrow> ('a \<Rightarrow> 'b::topological_space) \<Rightarrow> bool" where
  2160   "continuous F f \<longleftrightarrow> (f ---> f (Lim F (\<lambda>x. x))) F"
  2161 
  2162 lemma continuous_bot[continuous_intros, simp]: "continuous bot f"
  2163   unfolding continuous_def by auto
  2164 
  2165 lemma continuous_trivial_limit: "trivial_limit net \<Longrightarrow> continuous net f"
  2166   by simp
  2167 
  2168 lemma continuous_within: "continuous (at x within s) f \<longleftrightarrow> (f ---> f x) (at x within s)"
  2169   by (cases "trivial_limit (at x within s)") (auto simp add: Lim_ident_at continuous_def)
  2170 
  2171 lemma continuous_within_topological:
  2172   "continuous (at x within s) f \<longleftrightarrow>
  2173     (\<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)))"
  2174   unfolding continuous_within tendsto_def eventually_at_topological by metis
  2175 
  2176 lemma continuous_within_compose[continuous_intros]:
  2177   "continuous (at x within s) f \<Longrightarrow> continuous (at (f x) within f ` s) g \<Longrightarrow>
  2178   continuous (at x within s) (g o f)"
  2179   by (simp add: continuous_within_topological) metis
  2180 
  2181 lemma continuous_within_compose2:
  2182   "continuous (at x within s) f \<Longrightarrow> continuous (at (f x) within f ` s) g \<Longrightarrow>
  2183   continuous (at x within s) (\<lambda>x. g (f x))"
  2184   using continuous_within_compose[of x s f g] by (simp add: comp_def)
  2185 
  2186 lemma continuous_at: "continuous (at x) f \<longleftrightarrow> f -- x --> f x"
  2187   using continuous_within[of x UNIV f] by simp
  2188 
  2189 lemma continuous_ident[continuous_intros, simp]: "continuous (at x within S) (\<lambda>x. x)"
  2190   unfolding continuous_within by (rule tendsto_ident_at)
  2191 
  2192 lemma continuous_const[continuous_intros, simp]: "continuous F (\<lambda>x. c)"
  2193   unfolding continuous_def by (rule tendsto_const)
  2194 
  2195 lemma continuous_on_eq_continuous_within:
  2196   "continuous_on s f \<longleftrightarrow> (\<forall>x\<in>s. continuous (at x within s) f)"
  2197   unfolding continuous_on_def continuous_within ..
  2198 
  2199 abbreviation isCont :: "('a::t2_space \<Rightarrow> 'b::topological_space) \<Rightarrow> 'a \<Rightarrow> bool" where
  2200   "isCont f a \<equiv> continuous (at a) f"
  2201 
  2202 lemma isCont_def: "isCont f a \<longleftrightarrow> f -- a --> f a"
  2203   by (rule continuous_at)
  2204 
  2205 lemma continuous_at_within: "isCont f x \<Longrightarrow> continuous (at x within s) f"
  2206   by (auto intro: tendsto_mono at_le simp: continuous_at continuous_within)
  2207 
  2208 lemma continuous_on_eq_continuous_at: "open s \<Longrightarrow> continuous_on s f \<longleftrightarrow> (\<forall>x\<in>s. isCont f x)"
  2209   by (simp add: continuous_on_def continuous_at at_within_open[of _ s])
  2210 
  2211 lemma continuous_on_subset: "continuous_on s f \<Longrightarrow> t \<subseteq> s \<Longrightarrow> continuous_on t f"
  2212   unfolding continuous_on_def by (metis subset_eq tendsto_within_subset)
  2213 
  2214 lemma continuous_at_imp_continuous_on: "\<forall>x\<in>s. isCont f x \<Longrightarrow> continuous_on s f"
  2215   by (auto intro: continuous_at_within simp: continuous_on_eq_continuous_within)
  2216 
  2217 lemma isContI_continuous: "continuous (at x within UNIV) f \<Longrightarrow> isCont f x"
  2218   by simp
  2219 
  2220 lemma isCont_ident[continuous_intros, simp]: "isCont (\<lambda>x. x) a"
  2221   using continuous_ident by (rule isContI_continuous)
  2222 
  2223 lemmas isCont_const = continuous_const
  2224 
  2225 lemma isCont_o2: "isCont f a \<Longrightarrow> isCont g (f a) \<Longrightarrow> isCont (\<lambda>x. g (f x)) a"
  2226   unfolding isCont_def by (rule tendsto_compose)
  2227 
  2228 lemma isCont_o[continuous_intros]: "isCont f a \<Longrightarrow> isCont g (f a) \<Longrightarrow> isCont (g \<circ> f) a"
  2229   unfolding o_def by (rule isCont_o2)
  2230 
  2231 lemma isCont_tendsto_compose: "isCont g l \<Longrightarrow> (f ---> l) F \<Longrightarrow> ((\<lambda>x. g (f x)) ---> g l) F"
  2232   unfolding isCont_def by (rule tendsto_compose)
  2233 
  2234 lemma continuous_within_compose3:
  2235   "isCont g (f x) \<Longrightarrow> continuous (at x within s) f \<Longrightarrow> continuous (at x within s) (\<lambda>x. g (f x))"
  2236   using continuous_within_compose2[of x s f g] by (simp add: continuous_at_within)
  2237 
  2238 lemma filtermap_nhds_open_map:
  2239   assumes cont: "isCont f a" and open_map: "\<And>S. open S \<Longrightarrow> open (f`S)"
  2240   shows "filtermap f (nhds a) = nhds (f a)"
  2241   unfolding filter_eq_iff
  2242 proof safe
  2243   fix P assume "eventually P (filtermap f (nhds a))"
  2244   then guess S unfolding eventually_filtermap eventually_nhds ..
  2245   then show "eventually P (nhds (f a))"
  2246     unfolding eventually_nhds by (intro exI[of _ "f`S"]) (auto intro!: open_map)
  2247 qed (metis filterlim_iff tendsto_at_iff_tendsto_nhds isCont_def eventually_filtermap cont)
  2248 
  2249 lemma continuous_at_split: 
  2250   "continuous (at (x::'a::linorder_topology)) f = (continuous (at_left x) f \<and> continuous (at_right x) f)"
  2251   by (simp add: continuous_within filterlim_at_split)
  2252 
  2253 subsubsection{* Open-cover compactness *}
  2254 
  2255 context topological_space
  2256 begin
  2257 
  2258 definition compact :: "'a set \<Rightarrow> bool" where
  2259   compact_eq_heine_borel: -- "This name is used for backwards compatibility"
  2260     "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))"
  2261 
  2262 lemma compactI:
  2263   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'"
  2264   shows "compact s"
  2265   unfolding compact_eq_heine_borel using assms by metis
  2266 
  2267 lemma compact_empty[simp]: "compact {}"
  2268   by (auto intro!: compactI)
  2269 
  2270 lemma compactE:
  2271   assumes "compact s" and "\<forall>t\<in>C. open t" and "s \<subseteq> \<Union>C"
  2272   obtains C' where "C' \<subseteq> C" and "finite C'" and "s \<subseteq> \<Union>C'"
  2273   using assms unfolding compact_eq_heine_borel by metis
  2274 
  2275 lemma compactE_image:
  2276   assumes "compact s" and "\<forall>t\<in>C. open (f t)" and "s \<subseteq> (\<Union>c\<in>C. f c)"
  2277   obtains C' where "C' \<subseteq> C" and "finite C'" and "s \<subseteq> (\<Union>c\<in>C'. f c)"
  2278   using assms unfolding ball_simps[symmetric] SUP_def
  2279   by (metis (lifting) finite_subset_image compact_eq_heine_borel[of s])
  2280 
  2281 lemma compact_inter_closed [intro]:
  2282   assumes "compact s" and "closed t"
  2283   shows "compact (s \<inter> t)"
  2284 proof (rule compactI)
  2285   fix C assume C: "\<forall>c\<in>C. open c" and cover: "s \<inter> t \<subseteq> \<Union>C"
  2286   from C `closed t` have "\<forall>c\<in>C \<union> {-t}. open c" by auto
  2287   moreover from cover have "s \<subseteq> \<Union>(C \<union> {-t})" by auto
  2288   ultimately have "\<exists>D\<subseteq>C \<union> {-t}. finite D \<and> s \<subseteq> \<Union>D"
  2289     using `compact s` unfolding compact_eq_heine_borel by auto
  2290   then obtain D where "D \<subseteq> C \<union> {- t} \<and> finite D \<and> s \<subseteq> \<Union>D" ..
  2291   then show "\<exists>D\<subseteq>C. finite D \<and> s \<inter> t \<subseteq> \<Union>D"
  2292     by (intro exI[of _ "D - {-t}"]) auto
  2293 qed
  2294 
  2295 lemma inj_setminus: "inj_on uminus (A::'a set set)"
  2296   by (auto simp: inj_on_def)
  2297 
  2298 lemma compact_fip:
  2299   "compact U \<longleftrightarrow>
  2300     (\<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> {})"
  2301   (is "_ \<longleftrightarrow> ?R")
  2302 proof (safe intro!: compact_eq_heine_borel[THEN iffD2])
  2303   fix A
  2304   assume "compact U"
  2305     and A: "\<forall>a\<in>A. closed a" "U \<inter> \<Inter>A = {}"
  2306     and fi: "\<forall>B \<subseteq> A. finite B \<longrightarrow> U \<inter> \<Inter>B \<noteq> {}"
  2307   from A have "(\<forall>a\<in>uminus`A. open a) \<and> U \<subseteq> \<Union>(uminus`A)"
  2308     by auto
  2309   with `compact U` obtain B where "B \<subseteq> A" "finite (uminus`B)" "U \<subseteq> \<Union>(uminus`B)"
  2310     unfolding compact_eq_heine_borel by (metis subset_image_iff)
  2311   with fi[THEN spec, of B] show False
  2312     by (auto dest: finite_imageD intro: inj_setminus)
  2313 next
  2314   fix A
  2315   assume ?R
  2316   assume "\<forall>a\<in>A. open a" "U \<subseteq> \<Union>A"
  2317   then have "U \<inter> \<Inter>(uminus`A) = {}" "\<forall>a\<in>uminus`A. closed a"
  2318     by auto
  2319   with `?R` obtain B where "B \<subseteq> A" "finite (uminus`B)" "U \<inter> \<Inter>(uminus`B) = {}"
  2320     by (metis subset_image_iff)
  2321   then show "\<exists>T\<subseteq>A. finite T \<and> U \<subseteq> \<Union>T"
  2322     by  (auto intro!: exI[of _ B] inj_setminus dest: finite_imageD)
  2323 qed
  2324 
  2325 lemma compact_imp_fip:
  2326   "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>
  2327     s \<inter> (\<Inter> f) \<noteq> {}"
  2328   unfolding compact_fip by auto
  2329 
  2330 lemma compact_imp_fip_image:
  2331   assumes "compact s"
  2332     and P: "\<And>i. i \<in> I \<Longrightarrow> closed (f i)"
  2333     and Q: "\<And>I'. finite I' \<Longrightarrow> I' \<subseteq> I \<Longrightarrow> (s \<inter> (\<Inter>i\<in>I'. f i) \<noteq> {})"
  2334   shows "s \<inter> (\<Inter>i\<in>I. f i) \<noteq> {}"
  2335 proof -
  2336   note `compact s`
  2337   moreover from P have "\<forall>i \<in> f ` I. closed i" by blast
  2338   moreover have "\<forall>A. finite A \<and> A \<subseteq> f ` I \<longrightarrow> (s \<inter> (\<Inter>A) \<noteq> {})"
  2339   proof (rule, rule, erule conjE)
  2340     fix A :: "'a set set"
  2341     assume "finite A"
  2342     moreover assume "A \<subseteq> f ` I"
  2343     ultimately obtain B where "B \<subseteq> I" and "finite B" and "A = f ` B"
  2344       using finite_subset_image [of A f I] by blast
  2345     with Q [of B] show "s \<inter> \<Inter>A \<noteq> {}" by simp
  2346   qed
  2347   ultimately have "s \<inter> (\<Inter>(f ` I)) \<noteq> {}" by (rule compact_imp_fip)
  2348   then show ?thesis by simp
  2349 qed
  2350 
  2351 end
  2352 
  2353 lemma (in t2_space) compact_imp_closed:
  2354   assumes "compact s" shows "closed s"
  2355 unfolding closed_def
  2356 proof (rule openI)
  2357   fix y assume "y \<in> - s"
  2358   let ?C = "\<Union>x\<in>s. {u. open u \<and> x \<in> u \<and> eventually (\<lambda>y. y \<notin> u) (nhds y)}"
  2359   note `compact s`
  2360   moreover have "\<forall>u\<in>?C. open u" by simp
  2361   moreover have "s \<subseteq> \<Union>?C"
  2362   proof
  2363     fix x assume "x \<in> s"
  2364     with `y \<in> - s` have "x \<noteq> y" by clarsimp
  2365     hence "\<exists>u v. open u \<and> open v \<and> x \<in> u \<and> y \<in> v \<and> u \<inter> v = {}"
  2366       by (rule hausdorff)
  2367     with `x \<in> s` show "x \<in> \<Union>?C"
  2368       unfolding eventually_nhds by auto
  2369   qed
  2370   ultimately obtain D where "D \<subseteq> ?C" and "finite D" and "s \<subseteq> \<Union>D"
  2371     by (rule compactE)
  2372   from `D \<subseteq> ?C` have "\<forall>x\<in>D. eventually (\<lambda>y. y \<notin> x) (nhds y)" by auto
  2373   with `finite D` have "eventually (\<lambda>y. y \<notin> \<Union>D) (nhds y)"
  2374     by (simp add: eventually_Ball_finite)
  2375   with `s \<subseteq> \<Union>D` have "eventually (\<lambda>y. y \<notin> s) (nhds y)"
  2376     by (auto elim!: eventually_mono [rotated])
  2377   thus "\<exists>t. open t \<and> y \<in> t \<and> t \<subseteq> - s"
  2378     by (simp add: eventually_nhds subset_eq)
  2379 qed
  2380 
  2381 lemma compact_continuous_image:
  2382   assumes f: "continuous_on s f" and s: "compact s"
  2383   shows "compact (f ` s)"
  2384 proof (rule compactI)
  2385   fix C assume "\<forall>c\<in>C. open c" and cover: "f`s \<subseteq> \<Union>C"
  2386   with f have "\<forall>c\<in>C. \<exists>A. open A \<and> A \<inter> s = f -` c \<inter> s"
  2387     unfolding continuous_on_open_invariant by blast
  2388   then obtain A where A: "\<forall>c\<in>C. open (A c) \<and> A c \<inter> s = f -` c \<inter> s"
  2389     unfolding bchoice_iff ..
  2390   with cover have "\<forall>c\<in>C. open (A c)" "s \<subseteq> (\<Union>c\<in>C. A c)"
  2391     by (fastforce simp add: subset_eq set_eq_iff)+
  2392   from compactE_image[OF s this] obtain D where "D \<subseteq> C" "finite D" "s \<subseteq> (\<Union>c\<in>D. A c)" .
  2393   with A show "\<exists>D \<subseteq> C. finite D \<and> f`s \<subseteq> \<Union>D"
  2394     by (intro exI[of _ D]) (fastforce simp add: subset_eq set_eq_iff)+
  2395 qed
  2396 
  2397 lemma continuous_on_inv:
  2398   fixes f :: "'a::topological_space \<Rightarrow> 'b::t2_space"
  2399   assumes "continuous_on s f"  "compact s"  "\<forall>x\<in>s. g (f x) = x"
  2400   shows "continuous_on (f ` s) g"
  2401 unfolding continuous_on_topological
  2402 proof (clarsimp simp add: assms(3))
  2403   fix x :: 'a and B :: "'a set"
  2404   assume "x \<in> s" and "open B" and "x \<in> B"
  2405   have 1: "\<forall>x\<in>s. f x \<in> f ` (s - B) \<longleftrightarrow> x \<in> s - B"
  2406     using assms(3) by (auto, metis)
  2407   have "continuous_on (s - B) f"
  2408     using `continuous_on s f` Diff_subset
  2409     by (rule continuous_on_subset)
  2410   moreover have "compact (s - B)"
  2411     using `open B` and `compact s`
  2412     unfolding Diff_eq by (intro compact_inter_closed closed_Compl)
  2413   ultimately have "compact (f ` (s - B))"
  2414     by (rule compact_continuous_image)
  2415   hence "closed (f ` (s - B))"
  2416     by (rule compact_imp_closed)
  2417   hence "open (- f ` (s - B))"
  2418     by (rule open_Compl)
  2419   moreover have "f x \<in> - f ` (s - B)"
  2420     using `x \<in> s` and `x \<in> B` by (simp add: 1)
  2421   moreover have "\<forall>y\<in>s. f y \<in> - f ` (s - B) \<longrightarrow> y \<in> B"
  2422     by (simp add: 1)
  2423   ultimately show "\<exists>A. open A \<and> f x \<in> A \<and> (\<forall>y\<in>s. f y \<in> A \<longrightarrow> y \<in> B)"
  2424     by fast
  2425 qed
  2426 
  2427 lemma continuous_on_inv_into:
  2428   fixes f :: "'a::topological_space \<Rightarrow> 'b::t2_space"
  2429   assumes s: "continuous_on s f" "compact s" and f: "inj_on f s"
  2430   shows "continuous_on (f ` s) (the_inv_into s f)"
  2431   by (rule continuous_on_inv[OF s]) (auto simp: the_inv_into_f_f[OF f])
  2432 
  2433 lemma (in linorder_topology) compact_attains_sup:
  2434   assumes "compact S" "S \<noteq> {}"
  2435   shows "\<exists>s\<in>S. \<forall>t\<in>S. t \<le> s"
  2436 proof (rule classical)
  2437   assume "\<not> (\<exists>s\<in>S. \<forall>t\<in>S. t \<le> s)"
  2438   then obtain t where t: "\<forall>s\<in>S. t s \<in> S" and "\<forall>s\<in>S. s < t s"
  2439     by (metis not_le)
  2440   then have "\<forall>s\<in>S. open {..< t s}" "S \<subseteq> (\<Union>s\<in>S. {..< t s})"
  2441     by auto
  2442   with `compact S` obtain C where "C \<subseteq> S" "finite C" and C: "S \<subseteq> (\<Union>s\<in>C. {..< t s})"
  2443     by (erule compactE_image)
  2444   with `S \<noteq> {}` have Max: "Max (t`C) \<in> t`C" and "\<forall>s\<in>t`C. s \<le> Max (t`C)"
  2445     by (auto intro!: Max_in)
  2446   with C have "S \<subseteq> {..< Max (t`C)}"
  2447     by (auto intro: less_le_trans simp: subset_eq)
  2448   with t Max `C \<subseteq> S` show ?thesis
  2449     by fastforce
  2450 qed
  2451 
  2452 lemma (in linorder_topology) compact_attains_inf:
  2453   assumes "compact S" "S \<noteq> {}"
  2454   shows "\<exists>s\<in>S. \<forall>t\<in>S. s \<le> t"
  2455 proof (rule classical)
  2456   assume "\<not> (\<exists>s\<in>S. \<forall>t\<in>S. s \<le> t)"
  2457   then obtain t where t: "\<forall>s\<in>S. t s \<in> S" and "\<forall>s\<in>S. t s < s"
  2458     by (metis not_le)
  2459   then have "\<forall>s\<in>S. open {t s <..}" "S \<subseteq> (\<Union>s\<in>S. {t s <..})"
  2460     by auto
  2461   with `compact S` obtain C where "C \<subseteq> S" "finite C" and C: "S \<subseteq> (\<Union>s\<in>C. {t s <..})"
  2462     by (erule compactE_image)
  2463   with `S \<noteq> {}` have Min: "Min (t`C) \<in> t`C" and "\<forall>s\<in>t`C. Min (t`C) \<le> s"
  2464     by (auto intro!: Min_in)
  2465   with C have "S \<subseteq> {Min (t`C) <..}"
  2466     by (auto intro: le_less_trans simp: subset_eq)
  2467   with t Min `C \<subseteq> S` show ?thesis
  2468     by fastforce
  2469 qed
  2470 
  2471 lemma continuous_attains_sup:
  2472   fixes f :: "'a::topological_space \<Rightarrow> 'b::linorder_topology"
  2473   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)"
  2474   using compact_attains_sup[of "f ` s"] compact_continuous_image[of s f] by auto
  2475 
  2476 lemma continuous_attains_inf:
  2477   fixes f :: "'a::topological_space \<Rightarrow> 'b::linorder_topology"
  2478   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)"
  2479   using compact_attains_inf[of "f ` s"] compact_continuous_image[of s f] by auto
  2480 
  2481 subsection {* Connectedness *}
  2482 
  2483 context topological_space
  2484 begin
  2485 
  2486 definition "connected S \<longleftrightarrow>
  2487   \<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> {})"
  2488 
  2489 lemma connectedI:
  2490   "(\<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)
  2491   \<Longrightarrow> connected U"
  2492   by (auto simp: connected_def)
  2493 
  2494 lemma connected_empty[simp]: "connected {}"
  2495   by (auto intro!: connectedI)
  2496 
  2497 lemma connectedD:
  2498   "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 = {}" 
  2499   by (auto simp: connected_def)
  2500 
  2501 end
  2502 
  2503 lemma connected_iff_const:
  2504   fixes S :: "'a::topological_space set"
  2505   shows "connected S \<longleftrightarrow> (\<forall>P::'a \<Rightarrow> bool. continuous_on S P \<longrightarrow> (\<exists>c. \<forall>s\<in>S. P s = c))"
  2506 proof safe
  2507   fix P :: "'a \<Rightarrow> bool" assume "connected S" "continuous_on S P"
  2508   then have "\<And>b. \<exists>A. open A \<and> A \<inter> S = P -` {b} \<inter> S"
  2509     unfolding continuous_on_open_invariant by simp
  2510   from this[of True] this[of False]
  2511   obtain t f where "open t" "open f" and *: "f \<inter> S = P -` {False} \<inter> S" "t \<inter> S = P -` {True} \<inter> S"
  2512     by auto
  2513   then have "t \<inter> S = {} \<or> f \<inter> S = {}"
  2514     by (intro connectedD[OF `connected S`])  auto
  2515   then show "\<exists>c. \<forall>s\<in>S. P s = c"
  2516   proof (rule disjE)
  2517     assume "t \<inter> S = {}" then show ?thesis
  2518       unfolding * by (intro exI[of _ False]) auto
  2519   next
  2520     assume "f \<inter> S = {}" then show ?thesis
  2521       unfolding * by (intro exI[of _ True]) auto
  2522   qed
  2523 next
  2524   assume P: "\<forall>P::'a \<Rightarrow> bool. continuous_on S P \<longrightarrow> (\<exists>c. \<forall>s\<in>S. P s = c)"
  2525   show "connected S"
  2526   proof (rule connectedI)
  2527     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"
  2528     have "continuous_on S (\<lambda>x. x \<in> A)"
  2529       unfolding continuous_on_open_invariant
  2530     proof safe
  2531       fix C :: "bool set"
  2532       have "C = UNIV \<or> C = {True} \<or> C = {False} \<or> C = {}"
  2533         using subset_UNIV[of C] unfolding UNIV_bool by auto
  2534       with * show "\<exists>T. open T \<and> T \<inter> S = (\<lambda>x. x \<in> A) -` C \<inter> S"
  2535         by (intro exI[of _ "(if True \<in> C then A else {}) \<union> (if False \<in> C then B else {})"]) auto
  2536     qed
  2537     from P[rule_format, OF this] obtain c where "\<And>s. s \<in> S \<Longrightarrow> (s \<in> A) = c" by blast
  2538     with * show False
  2539       by (cases c) auto
  2540   qed
  2541 qed
  2542 
  2543 lemma connectedD_const:
  2544   fixes P :: "'a::topological_space \<Rightarrow> bool"
  2545   shows "connected S \<Longrightarrow> continuous_on S P \<Longrightarrow> \<exists>c. \<forall>s\<in>S. P s = c"
  2546   unfolding connected_iff_const by auto
  2547 
  2548 lemma connectedI_const:
  2549   "(\<And>P::'a::topological_space \<Rightarrow> bool. continuous_on S P \<Longrightarrow> \<exists>c. \<forall>s\<in>S. P s = c) \<Longrightarrow> connected S"
  2550   unfolding connected_iff_const by auto
  2551 
  2552 lemma connected_local_const:
  2553   assumes "connected A" "a \<in> A" "b \<in> A"
  2554   assumes *: "\<forall>a\<in>A. eventually (\<lambda>b. f a = f b) (at a within A)"
  2555   shows "f a = f b"
  2556 proof -
  2557   obtain S where S: "\<And>a. a \<in> A \<Longrightarrow> a \<in> S a" "\<And>a. a \<in> A \<Longrightarrow> open (S a)"
  2558     "\<And>a x. a \<in> A \<Longrightarrow> x \<in> S a \<Longrightarrow> x \<in> A \<Longrightarrow> f a = f x"
  2559     using * unfolding eventually_at_topological by metis
  2560 
  2561   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"
  2562   have "?P \<inter> A = {} \<or> ?N \<inter> A = {}"
  2563     using `connected A` S `a\<in>A`
  2564     by (intro connectedD) (auto, metis)
  2565   then show "f a = f b"
  2566   proof
  2567     assume "?N \<inter> A = {}"
  2568     then have "\<forall>x\<in>A. f a = f x"
  2569       using S(1) by auto
  2570     with `b\<in>A` show ?thesis by auto
  2571   next
  2572     assume "?P \<inter> A = {}" then show ?thesis
  2573       using `a \<in> A` S(1)[of a] by auto
  2574   qed
  2575 qed
  2576 
  2577 lemma (in linorder_topology) connectedD_interval:
  2578   assumes "connected U" and xy: "x \<in> U" "y \<in> U" and "x \<le> z" "z \<le> y"
  2579   shows "z \<in> U"
  2580 proof -
  2581   have eq: "{..<z} \<union> {z<..} = - {z}"
  2582     by auto
  2583   { assume "z \<notin> U" "x < z" "z < y"
  2584     with xy have "\<not> connected U"
  2585       unfolding connected_def simp_thms
  2586       apply (rule_tac exI[of _ "{..< z}"])
  2587       apply (rule_tac exI[of _ "{z <..}"])
  2588       apply (auto simp add: eq)
  2589       done }
  2590   with assms show "z \<in> U"
  2591     by (metis less_le)
  2592 qed
  2593 
  2594 lemma connected_continuous_image:
  2595   assumes *: "continuous_on s f"
  2596   assumes "connected s"
  2597   shows "connected (f ` s)"
  2598 proof (rule connectedI_const)
  2599   fix P :: "'b \<Rightarrow> bool" assume "continuous_on (f ` s) P"
  2600   then have "continuous_on s (P \<circ> f)"
  2601     by (rule continuous_on_compose[OF *])
  2602   from connectedD_const[OF `connected s` this] show "\<exists>c. \<forall>s\<in>f ` s. P s = c"
  2603     by auto
  2604 qed
  2605 
  2606 section {* Connectedness *}
  2607 
  2608 class linear_continuum_topology = linorder_topology + linear_continuum
  2609 begin
  2610 
  2611 lemma Inf_notin_open:
  2612   assumes A: "open A" and bnd: "\<forall>a\<in>A. x < a"
  2613   shows "Inf A \<notin> A"
  2614 proof
  2615   assume "Inf A \<in> A"
  2616   then obtain b where "b < Inf A" "{b <.. Inf A} \<subseteq> A"
  2617     using open_left[of A "Inf A" x] assms by auto
  2618   with dense[of b "Inf A"] obtain c where "c < Inf A" "c \<in> A"
  2619     by (auto simp: subset_eq)
  2620   then show False
  2621     using cInf_lower[OF `c \<in> A`] bnd by (metis not_le less_imp_le bdd_belowI)
  2622 qed
  2623 
  2624 lemma Sup_notin_open:
  2625   assumes A: "open A" and bnd: "\<forall>a\<in>A. a < x"
  2626   shows "Sup A \<notin> A"
  2627 proof
  2628   assume "Sup A \<in> A"
  2629   then obtain b where "Sup A < b" "{Sup A ..< b} \<subseteq> A"
  2630     using open_right[of A "Sup A" x] assms by auto
  2631   with dense[of "Sup A" b] obtain c where "Sup A < c" "c \<in> A"
  2632     by (auto simp: subset_eq)
  2633   then show False
  2634     using cSup_upper[OF `c \<in> A`] bnd by (metis less_imp_le not_le bdd_aboveI)
  2635 qed
  2636 
  2637 end
  2638 
  2639 instance linear_continuum_topology \<subseteq> perfect_space
  2640 proof
  2641   fix x :: 'a
  2642   obtain y where "x < y \<or> y < x"
  2643     using ex_gt_or_lt [of x] ..
  2644   with Inf_notin_open[of "{x}" y] Sup_notin_open[of "{x}" y]
  2645   show "\<not> open {x}"
  2646     by auto
  2647 qed
  2648 
  2649 lemma connectedI_interval:
  2650   fixes U :: "'a :: linear_continuum_topology set"
  2651   assumes *: "\<And>x y z. x \<in> U \<Longrightarrow> y \<in> U \<Longrightarrow> x \<le> z \<Longrightarrow> z \<le> y \<Longrightarrow> z \<in> U"
  2652   shows "connected U"
  2653 proof (rule connectedI)
  2654   { fix A B assume "open A" "open B" "A \<inter> B \<inter> U = {}" "U \<subseteq> A \<union> B"
  2655     fix x y assume "x < y" "x \<in> A" "y \<in> B" "x \<in> U" "y \<in> U"
  2656 
  2657     let ?z = "Inf (B \<inter> {x <..})"
  2658 
  2659     have "x \<le> ?z" "?z \<le> y"
  2660       using `y \<in> B` `x < y` by (auto intro: cInf_lower cInf_greatest)
  2661     with `x \<in> U` `y \<in> U` have "?z \<in> U"
  2662       by (rule *)
  2663     moreover have "?z \<notin> B \<inter> {x <..}"
  2664       using `open B` by (intro Inf_notin_open) auto
  2665     ultimately have "?z \<in> A"
  2666       using `x \<le> ?z` `A \<inter> B \<inter> U = {}` `x \<in> A` `U \<subseteq> A \<union> B` by auto
  2667 
  2668     { assume "?z < y"
  2669       obtain a where "?z < a" "{?z ..< a} \<subseteq> A"
  2670         using open_right[OF `open A` `?z \<in> A` `?z < y`] by auto
  2671       moreover obtain b where "b \<in> B" "x < b" "b < min a y"
  2672         using cInf_less_iff[of "B \<inter> {x <..}" "min a y"] `?z < a` `?z < y` `x < y` `y \<in> B`
  2673         by (auto intro: less_imp_le)
  2674       moreover have "?z \<le> b"
  2675         using `b \<in> B` `x < b`
  2676         by (intro cInf_lower) auto
  2677       moreover have "b \<in> U"
  2678         using `x \<le> ?z` `?z \<le> b` `b < min a y`
  2679         by (intro *[OF `x \<in> U` `y \<in> U`]) (auto simp: less_imp_le)
  2680       ultimately have "\<exists>b\<in>B. b \<in> A \<and> b \<in> U"
  2681         by (intro bexI[of _ b]) auto }
  2682     then have False
  2683       using `?z \<le> y` `?z \<in> A` `y \<in> B` `y \<in> U` `A \<inter> B \<inter> U = {}` unfolding le_less by blast }
  2684   note not_disjoint = this
  2685 
  2686   fix A B assume AB: "open A" "open B" "U \<subseteq> A \<union> B" "A \<inter> B \<inter> U = {}"
  2687   moreover assume "A \<inter> U \<noteq> {}" then obtain x where x: "x \<in> U" "x \<in> A" by auto
  2688   moreover assume "B \<inter> U \<noteq> {}" then obtain y where y: "y \<in> U" "y \<in> B" by auto
  2689   moreover note not_disjoint[of B A y x] not_disjoint[of A B x y]
  2690   ultimately show False by (cases x y rule: linorder_cases) auto
  2691 qed
  2692 
  2693 lemma connected_iff_interval:
  2694   fixes U :: "'a :: linear_continuum_topology set"
  2695   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)"
  2696   by (auto intro: connectedI_interval dest: connectedD_interval)
  2697 
  2698 lemma connected_UNIV[simp]: "connected (UNIV::'a::linear_continuum_topology set)"
  2699   unfolding connected_iff_interval by auto
  2700 
  2701 lemma connected_Ioi[simp]: "connected {a::'a::linear_continuum_topology <..}"
  2702   unfolding connected_iff_interval by auto
  2703 
  2704 lemma connected_Ici[simp]: "connected {a::'a::linear_continuum_topology ..}"
  2705   unfolding connected_iff_interval by auto
  2706 
  2707 lemma connected_Iio[simp]: "connected {..< a::'a::linear_continuum_topology}"
  2708   unfolding connected_iff_interval by auto
  2709 
  2710 lemma connected_Iic[simp]: "connected {.. a::'a::linear_continuum_topology}"
  2711   unfolding connected_iff_interval by auto
  2712 
  2713 lemma connected_Ioo[simp]: "connected {a <..< b::'a::linear_continuum_topology}"
  2714   unfolding connected_iff_interval by auto
  2715 
  2716 lemma connected_Ioc[simp]: "connected {a <.. b::'a::linear_continuum_topology}"
  2717   unfolding connected_iff_interval by auto
  2718 
  2719 lemma connected_Ico[simp]: "connected {a ..< b::'a::linear_continuum_topology}"
  2720   unfolding connected_iff_interval by auto
  2721 
  2722 lemma connected_Icc[simp]: "connected {a .. b::'a::linear_continuum_topology}"
  2723   unfolding connected_iff_interval by auto
  2724 
  2725 lemma connected_contains_Ioo: 
  2726   fixes A :: "'a :: linorder_topology set"
  2727   assumes A: "connected A" "a \<in> A" "b \<in> A" shows "{a <..< b} \<subseteq> A"
  2728   using connectedD_interval[OF A] by (simp add: subset_eq Ball_def less_imp_le)
  2729 
  2730 subsection {* Intermediate Value Theorem *}
  2731 
  2732 lemma IVT':
  2733   fixes f :: "'a :: linear_continuum_topology \<Rightarrow> 'b :: linorder_topology"
  2734   assumes y: "f a \<le> y" "y \<le> f b" "a \<le> b"
  2735   assumes *: "continuous_on {a .. b} f"
  2736   shows "\<exists>x. a \<le> x \<and> x \<le> b \<and> f x = y"
  2737 proof -
  2738   have "connected {a..b}"
  2739     unfolding connected_iff_interval by auto
  2740   from connected_continuous_image[OF * this, THEN connectedD_interval, of "f a" "f b" y] y
  2741   show ?thesis
  2742     by (auto simp add: atLeastAtMost_def atLeast_def atMost_def)
  2743 qed
  2744 
  2745 lemma IVT2':
  2746   fixes f :: "'a :: linear_continuum_topology \<Rightarrow> 'b :: linorder_topology"
  2747   assumes y: "f b \<le> y" "y \<le> f a" "a \<le> b"
  2748   assumes *: "continuous_on {a .. b} f"
  2749   shows "\<exists>x. a \<le> x \<and> x \<le> b \<and> f x = y"
  2750 proof -
  2751   have "connected {a..b}"
  2752     unfolding connected_iff_interval by auto
  2753   from connected_continuous_image[OF * this, THEN connectedD_interval, of "f b" "f a" y] y
  2754   show ?thesis
  2755     by (auto simp add: atLeastAtMost_def atLeast_def atMost_def)
  2756 qed
  2757 
  2758 lemma IVT:
  2759   fixes f :: "'a :: linear_continuum_topology \<Rightarrow> 'b :: linorder_topology"
  2760   shows "f a \<le> y \<Longrightarrow> y \<le> f b \<Longrightarrow> a \<le> b \<Longrightarrow> (\<forall>x. a \<le> x \<and> x \<le> b \<longrightarrow> isCont f x) \<Longrightarrow> \<exists>x. a \<le> x \<and> x \<le> b \<and> f x = y"
  2761   by (rule IVT') (auto intro: continuous_at_imp_continuous_on)
  2762 
  2763 lemma IVT2:
  2764   fixes f :: "'a :: linear_continuum_topology \<Rightarrow> 'b :: linorder_topology"
  2765   shows "f b \<le> y \<Longrightarrow> y \<le> f a \<Longrightarrow> a \<le> b \<Longrightarrow> (\<forall>x. a \<le> x \<and> x \<le> b \<longrightarrow> isCont f x) \<Longrightarrow> \<exists>x. a \<le> x \<and> x \<le> b \<and> f x = y"
  2766   by (rule IVT2') (auto intro: continuous_at_imp_continuous_on)
  2767 
  2768 lemma continuous_inj_imp_mono:
  2769   fixes f :: "'a::linear_continuum_topology \<Rightarrow> 'b :: linorder_topology"
  2770   assumes x: "a < x" "x < b"
  2771   assumes cont: "continuous_on {a..b} f"
  2772   assumes inj: "inj_on f {a..b}"
  2773   shows "(f a < f x \<and> f x < f b) \<or> (f b < f x \<and> f x < f a)"
  2774 proof -
  2775   note I = inj_on_iff[OF inj]
  2776   { assume "f x < f a" "f x < f b"
  2777     then obtain s t where "x \<le> s" "s \<le> b" "a \<le> t" "t \<le> x" "f s = f t" "f x < f s"
  2778       using IVT'[of f x "min (f a) (f b)" b] IVT2'[of f x "min (f a) (f b)" a] x
  2779       by (auto simp: continuous_on_subset[OF cont] less_imp_le)
  2780     with x I have False by auto }
  2781   moreover
  2782   { assume "f a < f x" "f b < f x"
  2783     then obtain s t where "x \<le> s" "s \<le> b" "a \<le> t" "t \<le> x" "f s = f t" "f s < f x"
  2784       using IVT'[of f a "max (f a) (f b)" x] IVT2'[of f b "max (f a) (f b)" x] x
  2785       by (auto simp: continuous_on_subset[OF cont] less_imp_le)
  2786     with x I have False by auto }
  2787   ultimately show ?thesis
  2788     using I[of a x] I[of x b] x less_trans[OF x] by (auto simp add: le_less less_imp_neq neq_iff)
  2789 qed
  2790 
  2791 lemma continuous_at_Sup_mono:
  2792   fixes f :: "'a :: {linorder_topology, conditionally_complete_linorder} \<Rightarrow> 'b :: {linorder_topology, conditionally_complete_linorder}"
  2793   assumes "mono f"
  2794   assumes cont: "continuous (at_left (Sup S)) f"
  2795   assumes S: "S \<noteq> {}" "bdd_above S"
  2796   shows "f (Sup S) = (SUP s:S. f s)"
  2797 proof (rule antisym)
  2798   have f: "(f ---> f (Sup S)) (at_left (Sup S))"
  2799     using cont unfolding continuous_within .
  2800 
  2801   show "f (Sup S) \<le> (SUP s:S. f s)"
  2802   proof cases
  2803     assume "Sup S \<in> S" then show ?thesis
  2804       by (rule cSUP_upper) (auto intro: bdd_above_image_mono S `mono f`)
  2805   next
  2806     assume "Sup S \<notin> S"
  2807     from `S \<noteq> {}` obtain s where "s \<in> S"
  2808       by auto
  2809     with `Sup S \<notin> S` S have "s < Sup S"
  2810       unfolding less_le by (blast intro: cSup_upper)
  2811     show ?thesis
  2812     proof (rule ccontr)
  2813       assume "\<not> ?thesis"
  2814       with order_tendstoD(1)[OF f, of "SUP s:S. f s"] obtain b where "b < Sup S"
  2815         and *: "\<And>y. b < y \<Longrightarrow> y < Sup S \<Longrightarrow> (SUP s:S. f s) < f y"
  2816         by (auto simp: not_le eventually_at_left[OF `s < Sup S`])
  2817       with `S \<noteq> {}` obtain c where "c \<in> S" "b < c"
  2818         using less_cSupD[of S b] by auto
  2819       with `Sup S \<notin> S` S have "c < Sup S"
  2820         unfolding less_le by (blast intro: cSup_upper)
  2821       from *[OF `b < c` `c < Sup S`] cSUP_upper[OF `c \<in> S` bdd_above_image_mono[of f]]
  2822       show False
  2823         by (auto simp: assms)
  2824     qed
  2825   qed
  2826 qed (intro cSUP_least `mono f`[THEN monoD] cSup_upper S)
  2827 
  2828 lemma continuous_at_Sup_antimono:
  2829   fixes f :: "'a :: {linorder_topology, conditionally_complete_linorder} \<Rightarrow> 'b :: {linorder_topology, conditionally_complete_linorder}"
  2830   assumes "antimono f"
  2831   assumes cont: "continuous (at_left (Sup S)) f"
  2832   assumes S: "S \<noteq> {}" "bdd_above S"
  2833   shows "f (Sup S) = (INF s:S. f s)"
  2834 proof (rule antisym)
  2835   have f: "(f ---> f (Sup S)) (at_left (Sup S))"
  2836     using cont unfolding continuous_within .
  2837 
  2838   show "(INF s:S. f s) \<le> f (Sup S)"
  2839   proof cases
  2840     assume "Sup S \<in> S" then show ?thesis
  2841       by (intro cINF_lower) (auto intro: bdd_below_image_antimono S `antimono f`)
  2842   next
  2843     assume "Sup S \<notin> S"
  2844     from `S \<noteq> {}` obtain s where "s \<in> S"
  2845       by auto
  2846     with `Sup S \<notin> S` S have "s < Sup S"
  2847       unfolding less_le by (blast intro: cSup_upper)
  2848     show ?thesis
  2849     proof (rule ccontr)
  2850       assume "\<not> ?thesis"
  2851       with order_tendstoD(2)[OF f, of "INF s:S. f s"] obtain b where "b < Sup S"
  2852         and *: "\<And>y. b < y \<Longrightarrow> y < Sup S \<Longrightarrow> f y < (INF s:S. f s)"
  2853         by (auto simp: not_le eventually_at_left[OF `s < Sup S`])
  2854       with `S \<noteq> {}` obtain c where "c \<in> S" "b < c"
  2855         using less_cSupD[of S b] by auto
  2856       with `Sup S \<notin> S` S have "c < Sup S"
  2857         unfolding less_le by (blast intro: cSup_upper)
  2858       from *[OF `b < c` `c < Sup S`] cINF_lower[OF bdd_below_image_antimono, of f S c] `c \<in> S`
  2859       show False
  2860         by (auto simp: assms)
  2861     qed
  2862   qed
  2863 qed (intro cINF_greatest `antimono f`[THEN antimonoD] cSup_upper S)
  2864 
  2865 lemma continuous_at_Inf_mono:
  2866   fixes f :: "'a :: {linorder_topology, conditionally_complete_linorder} \<Rightarrow> 'b :: {linorder_topology, conditionally_complete_linorder}"
  2867   assumes "mono f"
  2868   assumes cont: "continuous (at_right (Inf S)) f"
  2869   assumes S: "S \<noteq> {}" "bdd_below S"
  2870   shows "f (Inf S) = (INF s:S. f s)"
  2871 proof (rule antisym)
  2872   have f: "(f ---> f (Inf S)) (at_right (Inf S))"
  2873     using cont unfolding continuous_within .
  2874 
  2875   show "(INF s:S. f s) \<le> f (Inf S)"
  2876   proof cases
  2877     assume "Inf S \<in> S" then show ?thesis
  2878       by (rule cINF_lower[rotated]) (auto intro: bdd_below_image_mono S `mono f`)
  2879   next
  2880     assume "Inf S \<notin> S"
  2881     from `S \<noteq> {}` obtain s where "s \<in> S"
  2882       by auto
  2883     with `Inf S \<notin> S` S have "Inf S < s"
  2884       unfolding less_le by (blast intro: cInf_lower)
  2885     show ?thesis
  2886     proof (rule ccontr)
  2887       assume "\<not> ?thesis"
  2888       with order_tendstoD(2)[OF f, of "INF s:S. f s"] obtain b where "Inf S < b"
  2889         and *: "\<And>y. Inf S < y \<Longrightarrow> y < b \<Longrightarrow> f y < (INF s:S. f s)"
  2890         by (auto simp: not_le eventually_at_right[OF `Inf S < s`])
  2891       with `S \<noteq> {}` obtain c where "c \<in> S" "c < b"
  2892         using cInf_lessD[of S b] by auto
  2893       with `Inf S \<notin> S` S have "Inf S < c"
  2894         unfolding less_le by (blast intro: cInf_lower)
  2895       from *[OF `Inf S < c` `c < b`] cINF_lower[OF bdd_below_image_mono[of f] `c \<in> S`]
  2896       show False
  2897         by (auto simp: assms)
  2898     qed
  2899   qed
  2900 qed (intro cINF_greatest `mono f`[THEN monoD] cInf_lower `bdd_below S` `S \<noteq> {}`)
  2901 
  2902 lemma continuous_at_Inf_antimono:
  2903   fixes f :: "'a :: {linorder_topology, conditionally_complete_linorder} \<Rightarrow> 'b :: {linorder_topology, conditionally_complete_linorder}"
  2904   assumes "antimono f"
  2905   assumes cont: "continuous (at_right (Inf S)) f"
  2906   assumes S: "S \<noteq> {}" "bdd_below S"
  2907   shows "f (Inf S) = (SUP s:S. f s)"
  2908 proof (rule antisym)
  2909   have f: "(f ---> f (Inf S)) (at_right (Inf S))"
  2910     using cont unfolding continuous_within .
  2911 
  2912   show "f (Inf S) \<le> (SUP s:S. f s)"
  2913   proof cases
  2914     assume "Inf S \<in> S" then show ?thesis
  2915       by (rule cSUP_upper) (auto intro: bdd_above_image_antimono S `antimono f`)
  2916   next
  2917     assume "Inf S \<notin> S"
  2918     from `S \<noteq> {}` obtain s where "s \<in> S"
  2919       by auto
  2920     with `Inf S \<notin> S` S have "Inf S < s"
  2921       unfolding less_le by (blast intro: cInf_lower)
  2922     show ?thesis
  2923     proof (rule ccontr)
  2924       assume "\<not> ?thesis"
  2925       with order_tendstoD(1)[OF f, of "SUP s:S. f s"] obtain b where "Inf S < b"
  2926         and *: "\<And>y. Inf S < y \<Longrightarrow> y < b \<Longrightarrow> (SUP s:S. f s) < f y"
  2927         by (auto simp: not_le eventually_at_right[OF `Inf S < s`])
  2928       with `S \<noteq> {}` obtain c where "c \<in> S" "c < b"
  2929         using cInf_lessD[of S b] by auto
  2930       with `Inf S \<notin> S` S have "Inf S < c"
  2931         unfolding less_le by (blast intro: cInf_lower)
  2932       from *[OF `Inf S < c` `c < b`] cSUP_upper[OF `c \<in> S` bdd_above_image_antimono[of f]]
  2933       show False
  2934         by (auto simp: assms)
  2935     qed
  2936   qed
  2937 qed (intro cSUP_least `antimono f`[THEN antimonoD] cInf_lower S)
  2938 
  2939 subsection {* Setup @{typ "'a filter"} for lifting and transfer *}
  2940 
  2941 context begin interpretation lifting_syntax .
  2942 
  2943 definition rel_filter :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'a filter \<Rightarrow> 'b filter \<Rightarrow> bool"
  2944 where "rel_filter R F G = ((R ===> op =) ===> op =) (Rep_filter F) (Rep_filter G)"
  2945 
  2946 lemma rel_filter_eventually:
  2947   "rel_filter R F G \<longleftrightarrow> 
  2948   ((R ===> op =) ===> op =) (\<lambda>P. eventually P F) (\<lambda>P. eventually P G)"
  2949 by(simp add: rel_filter_def eventually_def)
  2950 
  2951 lemma filtermap_id [simp, id_simps]: "filtermap id = id"
  2952 by(simp add: fun_eq_iff id_def filtermap_ident)
  2953 
  2954 lemma filtermap_id' [simp]: "filtermap (\<lambda>x. x) = (\<lambda>F. F)"
  2955 using filtermap_id unfolding id_def .
  2956 
  2957 lemma Quotient_filter [quot_map]:
  2958   assumes Q: "Quotient R Abs Rep T"
  2959   shows "Quotient (rel_filter R) (filtermap Abs) (filtermap Rep) (rel_filter T)"
  2960 unfolding Quotient_alt_def
  2961 proof(intro conjI strip)
  2962   from Q have *: "\<And>x y. T x y \<Longrightarrow> Abs x = y"
  2963     unfolding Quotient_alt_def by blast
  2964 
  2965   fix F G
  2966   assume "rel_filter T F G"
  2967   thus "filtermap Abs F = G" unfolding filter_eq_iff
  2968     by(auto simp add: eventually_filtermap rel_filter_eventually * rel_funI del: iffI elim!: rel_funD)
  2969 next
  2970   from Q have *: "\<And>x. T (Rep x) x" unfolding Quotient_alt_def by blast
  2971 
  2972   fix F
  2973   show "rel_filter T (filtermap Rep F) F" 
  2974     by(auto elim: rel_funD intro: * intro!: ext arg_cong[where f="\<lambda>P. eventually P F"] rel_funI
  2975             del: iffI simp add: eventually_filtermap rel_filter_eventually)
  2976 qed(auto simp add: map_fun_def o_def eventually_filtermap filter_eq_iff fun_eq_iff rel_filter_eventually
  2977          fun_quotient[OF fun_quotient[OF Q identity_quotient] identity_quotient, unfolded Quotient_alt_def])
  2978 
  2979 lemma eventually_parametric [transfer_rule]:
  2980   "((A ===> op =) ===> rel_filter A ===> op =) eventually eventually"
  2981 by(simp add: rel_fun_def rel_filter_eventually)
  2982 
  2983 lemma rel_filter_eq [relator_eq]: "rel_filter op = = op ="
  2984 by(auto simp add: rel_filter_eventually rel_fun_eq fun_eq_iff filter_eq_iff)
  2985 
  2986 lemma rel_filter_mono [relator_mono]:
  2987   "A \<le> B \<Longrightarrow> rel_filter A \<le> rel_filter B"
  2988 unfolding rel_filter_eventually[abs_def]
  2989 by(rule le_funI)+(intro fun_mono fun_mono[THEN le_funD, THEN le_funD] order.refl)
  2990 
  2991 lemma rel_filter_conversep [simp]: "rel_filter A\<inverse>\<inverse> = (rel_filter A)\<inverse>\<inverse>"
  2992 by(auto simp add: rel_filter_eventually fun_eq_iff rel_fun_def)
  2993 
  2994 lemma is_filter_parametric_aux:
  2995   assumes "is_filter F"
  2996   assumes [transfer_rule]: "bi_total A" "bi_unique A"
  2997   and [transfer_rule]: "((A ===> op =) ===> op =) F G"
  2998   shows "is_filter G"
  2999 proof -
  3000   interpret is_filter F by fact
  3001   show ?thesis
  3002   proof
  3003     have "F (\<lambda>_. True) = G (\<lambda>x. True)" by transfer_prover
  3004     thus "G (\<lambda>x. True)" by(simp add: True)
  3005   next
  3006     fix P' Q'
  3007     assume "G P'" "G Q'"
  3008     moreover
  3009     from bi_total_fun[OF `bi_unique A` bi_total_eq, unfolded bi_total_def]
  3010     obtain P Q where [transfer_rule]: "(A ===> op =) P P'" "(A ===> op =) Q Q'" by blast
  3011     have "F P = G P'" "F Q = G Q'" by transfer_prover+
  3012     ultimately have "F (\<lambda>x. P x \<and> Q x)" by(simp add: conj)
  3013     moreover have "F (\<lambda>x. P x \<and> Q x) = G (\<lambda>x. P' x \<and> Q' x)" by transfer_prover
  3014     ultimately show "G (\<lambda>x. P' x \<and> Q' x)" by simp
  3015   next
  3016     fix P' Q'
  3017     assume "\<forall>x. P' x \<longrightarrow> Q' x" "G P'"
  3018     moreover
  3019     from bi_total_fun[OF `bi_unique A` bi_total_eq, unfolded bi_total_def]
  3020     obtain P Q where [transfer_rule]: "(A ===> op =) P P'" "(A ===> op =) Q Q'" by blast
  3021     have "F P = G P'" by transfer_prover
  3022     moreover have "(\<forall>x. P x \<longrightarrow> Q x) \<longleftrightarrow> (\<forall>x. P' x \<longrightarrow> Q' x)" by transfer_prover
  3023     ultimately have "F Q" by(simp add: mono)
  3024     moreover have "F Q = G Q'" by transfer_prover
  3025     ultimately show "G Q'" by simp
  3026   qed
  3027 qed
  3028 
  3029 lemma is_filter_parametric [transfer_rule]:
  3030   "\<lbrakk> bi_total A; bi_unique A \<rbrakk>
  3031   \<Longrightarrow> (((A ===> op =) ===> op =) ===> op =) is_filter is_filter"
  3032 apply(rule rel_funI)
  3033 apply(rule iffI)
  3034  apply(erule (3) is_filter_parametric_aux)
  3035 apply(erule is_filter_parametric_aux[where A="conversep A"])
  3036 apply(auto simp add: rel_fun_def)
  3037 done
  3038 
  3039 lemma left_total_rel_filter [transfer_rule]:
  3040   assumes [transfer_rule]: "bi_total A" "bi_unique A"
  3041   shows "left_total (rel_filter A)"
  3042 proof(rule left_totalI)
  3043   fix F :: "'a filter"
  3044   from bi_total_fun[OF bi_unique_fun[OF `bi_total A` bi_unique_eq] bi_total_eq]
  3045   obtain G where [transfer_rule]: "((A ===> op =) ===> op =) (\<lambda>P. eventually P F) G" 
  3046     unfolding  bi_total_def by blast
  3047   moreover have "is_filter (\<lambda>P. eventually P F) \<longleftrightarrow> is_filter G" by transfer_prover
  3048   hence "is_filter G" by(simp add: eventually_def is_filter_Rep_filter)
  3049   ultimately have "rel_filter A F (Abs_filter G)"
  3050     by(simp add: rel_filter_eventually eventually_Abs_filter)
  3051   thus "\<exists>G. rel_filter A F G" ..
  3052 qed
  3053 
  3054 lemma right_total_rel_filter [transfer_rule]:
  3055   "\<lbrakk> bi_total A; bi_unique A \<rbrakk> \<Longrightarrow> right_total (rel_filter A)"
  3056 using left_total_rel_filter[of "A\<inverse>\<inverse>"] by simp
  3057 
  3058 lemma bi_total_rel_filter [transfer_rule]:
  3059   assumes "bi_total A" "bi_unique A"
  3060   shows "bi_total (rel_filter A)"
  3061 unfolding bi_total_alt_def using assms
  3062 by(simp add: left_total_rel_filter right_total_rel_filter)
  3063 
  3064 lemma left_unique_rel_filter [transfer_rule]:
  3065   assumes "left_unique A"
  3066   shows "left_unique (rel_filter A)"
  3067 proof(rule left_uniqueI)
  3068   fix F F' G
  3069   assume [transfer_rule]: "rel_filter A F G" "rel_filter A F' G"
  3070   show "F = F'"
  3071     unfolding filter_eq_iff
  3072   proof
  3073     fix P :: "'a \<Rightarrow> bool"
  3074     obtain P' where [transfer_rule]: "(A ===> op =) P P'"
  3075       using left_total_fun[OF assms left_total_eq] unfolding left_total_def by blast
  3076     have "eventually P F = eventually P' G" 
  3077       and "eventually P F' = eventually P' G" by transfer_prover+
  3078     thus "eventually P F = eventually P F'" by simp
  3079   qed
  3080 qed
  3081 
  3082 lemma right_unique_rel_filter [transfer_rule]:
  3083   "right_unique A \<Longrightarrow> right_unique (rel_filter A)"
  3084 using left_unique_rel_filter[of "A\<inverse>\<inverse>"] by simp
  3085 
  3086 lemma bi_unique_rel_filter [transfer_rule]:
  3087   "bi_unique A \<Longrightarrow> bi_unique (rel_filter A)"
  3088 by(simp add: bi_unique_alt_def left_unique_rel_filter right_unique_rel_filter)
  3089 
  3090 lemma top_filter_parametric [transfer_rule]:
  3091   "bi_total A \<Longrightarrow> (rel_filter A) top top"
  3092 by(simp add: rel_filter_eventually All_transfer)
  3093 
  3094 lemma bot_filter_parametric [transfer_rule]: "(rel_filter A) bot bot"
  3095 by(simp add: rel_filter_eventually rel_fun_def)
  3096 
  3097 lemma sup_filter_parametric [transfer_rule]:
  3098   "(rel_filter A ===> rel_filter A ===> rel_filter A) sup sup"
  3099 by(fastforce simp add: rel_filter_eventually[abs_def] eventually_sup dest: rel_funD)
  3100 
  3101 lemma Sup_filter_parametric [transfer_rule]:
  3102   "(rel_set (rel_filter A) ===> rel_filter A) Sup Sup"
  3103 proof(rule rel_funI)
  3104   fix S T
  3105   assume [transfer_rule]: "rel_set (rel_filter A) S T"
  3106   show "rel_filter A (Sup S) (Sup T)"
  3107     by(simp add: rel_filter_eventually eventually_Sup) transfer_prover
  3108 qed
  3109 
  3110 lemma principal_parametric [transfer_rule]:
  3111   "(rel_set A ===> rel_filter A) principal principal"
  3112 proof(rule rel_funI)
  3113   fix S S'
  3114   assume [transfer_rule]: "rel_set A S S'"
  3115   show "rel_filter A (principal S) (principal S')"
  3116     by(simp add: rel_filter_eventually eventually_principal) transfer_prover
  3117 qed
  3118 
  3119 context
  3120   fixes A :: "'a \<Rightarrow> 'b \<Rightarrow> bool"
  3121   assumes [transfer_rule]: "bi_unique A" 
  3122 begin
  3123 
  3124 lemma le_filter_parametric [transfer_rule]:
  3125   "(rel_filter A ===> rel_filter A ===> op =) op \<le> op \<le>"
  3126 unfolding le_filter_def[abs_def] by transfer_prover
  3127 
  3128 lemma less_filter_parametric [transfer_rule]:
  3129   "(rel_filter A ===> rel_filter A ===> op =) op < op <"
  3130 unfolding less_filter_def[abs_def] by transfer_prover
  3131 
  3132 context
  3133   assumes [transfer_rule]: "bi_total A"
  3134 begin
  3135 
  3136 lemma Inf_filter_parametric [transfer_rule]:
  3137   "(rel_set (rel_filter A) ===> rel_filter A) Inf Inf"
  3138 unfolding Inf_filter_def[abs_def] by transfer_prover
  3139 
  3140 lemma inf_filter_parametric [transfer_rule]:
  3141   "(rel_filter A ===> rel_filter A ===> rel_filter A) inf inf"
  3142 proof(intro rel_funI)+
  3143   fix F F' G G'
  3144   assume [transfer_rule]: "rel_filter A F F'" "rel_filter A G G'"
  3145   have "rel_filter A (Inf {F, G}) (Inf {F', G'})" by transfer_prover
  3146   thus "rel_filter A (inf F G) (inf F' G')" by simp
  3147 qed
  3148 
  3149 end
  3150 
  3151 end
  3152 
  3153 end
  3154 
  3155 end