src/HOL/Topological_Spaces.thy
changeset 65204 d23eded35a33
parent 65036 ab7e11730ad8
child 65583 8d53b3bebab4
equal deleted inserted replaced
65203:314246c6eeaa 65204:d23eded35a33
   148   assumes t1_space: "x \<noteq> y \<Longrightarrow> \<exists>U. open U \<and> x \<in> U \<and> y \<notin> U"
   148   assumes t1_space: "x \<noteq> y \<Longrightarrow> \<exists>U. open U \<and> x \<in> U \<and> y \<notin> U"
   149 
   149 
   150 instance t1_space \<subseteq> t0_space
   150 instance t1_space \<subseteq> t0_space
   151   by standard (fast dest: t1_space)
   151   by standard (fast dest: t1_space)
   152 
   152 
       
   153 context t1_space begin
       
   154 
   153 lemma separation_t1: "x \<noteq> y \<longleftrightarrow> (\<exists>U. open U \<and> x \<in> U \<and> y \<notin> U)"
   155 lemma separation_t1: "x \<noteq> y \<longleftrightarrow> (\<exists>U. open U \<and> x \<in> U \<and> y \<notin> U)"
   154   for x y :: "'a::t1_space"
       
   155   using t1_space[of x y] by blast
   156   using t1_space[of x y] by blast
   156 
   157 
   157 lemma closed_singleton [iff]: "closed {a}"
   158 lemma closed_singleton [iff]: "closed {a}"
   158   for a :: "'a::t1_space"
       
   159 proof -
   159 proof -
   160   let ?T = "\<Union>{S. open S \<and> a \<notin> S}"
   160   let ?T = "\<Union>{S. open S \<and> a \<notin> S}"
   161   have "open ?T"
   161   have "open ?T"
   162     by (simp add: open_Union)
   162     by (simp add: open_Union)
   163   also have "?T = - {a}"
   163   also have "?T = - {a}"
   165   finally show "closed {a}"
   165   finally show "closed {a}"
   166     by (simp only: closed_def)
   166     by (simp only: closed_def)
   167 qed
   167 qed
   168 
   168 
   169 lemma closed_insert [continuous_intros, simp]:
   169 lemma closed_insert [continuous_intros, simp]:
   170   fixes a :: "'a::t1_space"
       
   171   assumes "closed S"
   170   assumes "closed S"
   172   shows "closed (insert a S)"
   171   shows "closed (insert a S)"
   173 proof -
   172 proof -
   174   from closed_singleton assms have "closed ({a} \<union> S)"
   173   from closed_singleton assms have "closed ({a} \<union> S)"
   175     by (rule closed_Un)
   174     by (rule closed_Un)
   176   then show "closed (insert a S)"
   175   then show "closed (insert a S)"
   177     by simp
   176     by simp
   178 qed
   177 qed
   179 
   178 
   180 lemma finite_imp_closed: "finite S \<Longrightarrow> closed S"
   179 lemma finite_imp_closed: "finite S \<Longrightarrow> closed S"
   181   for S :: "'a::t1_space set"
       
   182   by (induct pred: finite) simp_all
   180   by (induct pred: finite) simp_all
   183 
   181 
       
   182 end
   184 
   183 
   185 text \<open>T2 spaces are also known as Hausdorff spaces.\<close>
   184 text \<open>T2 spaces are also known as Hausdorff spaces.\<close>
   186 
   185 
   187 class t2_space = topological_space +
   186 class t2_space = topological_space +
   188   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 = {}"
   187   assumes hausdorff: "x \<noteq> y \<Longrightarrow> \<exists>U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {}"
   189 
   188 
   190 instance t2_space \<subseteq> t1_space
   189 instance t2_space \<subseteq> t1_space
   191   by standard (fast dest: hausdorff)
   190   by standard (fast dest: hausdorff)
   192 
   191 
   193 lemma separation_t2: "x \<noteq> y \<longleftrightarrow> (\<exists>U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {})"
   192 lemma (in t2_space) separation_t2: "x \<noteq> y \<longleftrightarrow> (\<exists>U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {})"
   194   for x y :: "'a::t2_space"
       
   195   using hausdorff [of x y] by blast
   193   using hausdorff [of x y] by blast
   196 
   194 
   197 lemma separation_t0: "x \<noteq> y \<longleftrightarrow> (\<exists>U. open U \<and> \<not> (x \<in> U \<longleftrightarrow> y \<in> U))"
   195 lemma (in t0_space) separation_t0: "x \<noteq> y \<longleftrightarrow> (\<exists>U. open U \<and> \<not> (x \<in> U \<longleftrightarrow> y \<in> U))"
   198   for x y :: "'a::t0_space"
       
   199   using t0_space [of x y] by blast
   196   using t0_space [of x y] by blast
   200 
   197 
   201 
   198 
   202 text \<open>A perfect space is a topological space with no isolated points.\<close>
   199 text \<open>A perfect space is a topological space with no isolated points.\<close>
   203 
   200 
   204 class perfect_space = topological_space +
   201 class perfect_space = topological_space +
   205   assumes not_open_singleton: "\<not> open {x}"
   202   assumes not_open_singleton: "\<not> open {x}"
   206 
   203 
   207 lemma UNIV_not_singleton: "UNIV \<noteq> {x}"
   204 lemma (in perfect_space) UNIV_not_singleton: "UNIV \<noteq> {x}"
   208   for x :: "'a::perfect_space"
   205   for x::'a
   209   by (metis open_UNIV not_open_singleton)
   206   by (metis (no_types) open_UNIV not_open_singleton)
   210 
   207 
   211 
   208 
   212 subsection \<open>Generators for toplogies\<close>
   209 subsection \<open>Generators for toplogies\<close>
   213 
   210 
   214 inductive generate_topology :: "'a set set \<Rightarrow> 'a set \<Rightarrow> bool" for S :: "'a set set"
   211 inductive generate_topology :: "'a set set \<Rightarrow> 'a set \<Rightarrow> bool" for S :: "'a set set"
   474 
   471 
   475 lemma (in topological_space) eventually_nhds_in_open:
   472 lemma (in topological_space) eventually_nhds_in_open:
   476   "open s \<Longrightarrow> x \<in> s \<Longrightarrow> eventually (\<lambda>y. y \<in> s) (nhds x)"
   473   "open s \<Longrightarrow> x \<in> s \<Longrightarrow> eventually (\<lambda>y. y \<in> s) (nhds x)"
   477   by (subst eventually_nhds) blast
   474   by (subst eventually_nhds) blast
   478 
   475 
   479 lemma eventually_nhds_x_imp_x: "eventually P (nhds x) \<Longrightarrow> P x"
   476 lemma (in topological_space) eventually_nhds_x_imp_x: "eventually P (nhds x) \<Longrightarrow> P x"
   480   by (subst (asm) eventually_nhds) blast
   477   by (subst (asm) eventually_nhds) blast
   481 
   478 
   482 lemma nhds_neq_bot [simp]: "nhds a \<noteq> bot"
   479 lemma (in topological_space) nhds_neq_bot [simp]: "nhds a \<noteq> bot"
   483   by (simp add: trivial_limit_def eventually_nhds)
   480   by (simp add: trivial_limit_def eventually_nhds)
   484 
   481 
   485 lemma (in t1_space) t1_space_nhds: "x \<noteq> y \<Longrightarrow> (\<forall>\<^sub>F x in nhds x. x \<noteq> y)"
   482 lemma (in t1_space) t1_space_nhds: "x \<noteq> y \<Longrightarrow> (\<forall>\<^sub>F x in nhds x. x \<noteq> y)"
   486   by (drule t1_space) (auto simp: eventually_nhds)
   483   by (drule t1_space) (auto simp: eventually_nhds)
   487 
   484 
   492   by (simp add: nhds_discrete_open open_discrete)
   489   by (simp add: nhds_discrete_open open_discrete)
   493 
   490 
   494 lemma (in discrete_topology) at_discrete: "at x within S = bot"
   491 lemma (in discrete_topology) at_discrete: "at x within S = bot"
   495   unfolding at_within_def nhds_discrete by simp
   492   unfolding at_within_def nhds_discrete by simp
   496 
   493 
   497 lemma at_within_eq: "at x within s = (INF S:{S. open S \<and> x \<in> S}. principal (S \<inter> s - {x}))"
   494 lemma (in topological_space) at_within_eq:
       
   495   "at x within s = (INF S:{S. open S \<and> x \<in> S}. principal (S \<inter> s - {x}))"
   498   unfolding nhds_def at_within_def
   496   unfolding nhds_def at_within_def
   499   by (subst INF_inf_const2[symmetric]) (auto simp: Diff_Int_distrib)
   497   by (subst INF_inf_const2[symmetric]) (auto simp: Diff_Int_distrib)
   500 
   498 
   501 lemma eventually_at_filter:
   499 lemma (in topological_space) eventually_at_filter:
   502   "eventually P (at a within s) \<longleftrightarrow> eventually (\<lambda>x. x \<noteq> a \<longrightarrow> x \<in> s \<longrightarrow> P x) (nhds a)"
   500   "eventually P (at a within s) \<longleftrightarrow> eventually (\<lambda>x. x \<noteq> a \<longrightarrow> x \<in> s \<longrightarrow> P x) (nhds a)"
   503   by (simp add: at_within_def eventually_inf_principal imp_conjL[symmetric] conj_commute)
   501   by (simp add: at_within_def eventually_inf_principal imp_conjL[symmetric] conj_commute)
   504 
   502 
   505 lemma at_le: "s \<subseteq> t \<Longrightarrow> at x within s \<le> at x within t"
   503 lemma (in topological_space) at_le: "s \<subseteq> t \<Longrightarrow> at x within s \<le> at x within t"
   506   unfolding at_within_def by (intro inf_mono) auto
   504   unfolding at_within_def by (intro inf_mono) auto
   507 
   505 
   508 lemma eventually_at_topological:
   506 lemma (in topological_space) eventually_at_topological:
   509   "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))"
   507   "eventually P (at a within s) \<longleftrightarrow> (\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. x \<noteq> a \<longrightarrow> x \<in> s \<longrightarrow> P x))"
   510   by (simp add: eventually_nhds eventually_at_filter)
   508   by (simp add: eventually_nhds eventually_at_filter)
   511 
   509 
   512 lemma at_within_open: "a \<in> S \<Longrightarrow> open S \<Longrightarrow> at a within S = at a"
   510 lemma (in topological_space) at_within_open: "a \<in> S \<Longrightarrow> open S \<Longrightarrow> at a within S = at a"
   513   unfolding filter_eq_iff eventually_at_topological by (metis open_Int Int_iff UNIV_I)
   511   unfolding filter_eq_iff eventually_at_topological by (metis open_Int Int_iff UNIV_I)
   514 
   512 
   515 lemma at_within_open_NO_MATCH: "a \<in> s \<Longrightarrow> open s \<Longrightarrow> NO_MATCH UNIV s \<Longrightarrow> at a within s = at a"
   513 lemma (in topological_space) at_within_open_NO_MATCH:
       
   514   "a \<in> s \<Longrightarrow> open s \<Longrightarrow> NO_MATCH UNIV s \<Longrightarrow> at a within s = at a"
   516   by (simp only: at_within_open)
   515   by (simp only: at_within_open)
   517 
   516 
   518 lemma at_within_nhd:
   517 lemma (in topological_space) at_within_open_subset:
       
   518   "a \<in> S \<Longrightarrow> open S \<Longrightarrow> S \<subseteq> T \<Longrightarrow> at a within T = at a"
       
   519   by (metis at_le at_within_open dual_order.antisym subset_UNIV)
       
   520 
       
   521 lemma (in topological_space) at_within_nhd:
   519   assumes "x \<in> S" "open S" "T \<inter> S - {x} = U \<inter> S - {x}"
   522   assumes "x \<in> S" "open S" "T \<inter> S - {x} = U \<inter> S - {x}"
   520   shows "at x within T = at x within U"
   523   shows "at x within T = at x within U"
   521   unfolding filter_eq_iff eventually_at_filter
   524   unfolding filter_eq_iff eventually_at_filter
   522 proof (intro allI eventually_subst)
   525 proof (intro allI eventually_subst)
   523   have "eventually (\<lambda>x. x \<in> S) (nhds x)"
   526   have "eventually (\<lambda>x. x \<in> S) (nhds x)"
   524     using \<open>x \<in> S\<close> \<open>open S\<close> by (auto simp: eventually_nhds)
   527     using \<open>x \<in> S\<close> \<open>open S\<close> by (auto simp: eventually_nhds)
   525   then show "\<forall>\<^sub>F n in nhds x. (n \<noteq> x \<longrightarrow> n \<in> T \<longrightarrow> P n) = (n \<noteq> x \<longrightarrow> n \<in> U \<longrightarrow> P n)" for P
   528   then show "\<forall>\<^sub>F n in nhds x. (n \<noteq> x \<longrightarrow> n \<in> T \<longrightarrow> P n) = (n \<noteq> x \<longrightarrow> n \<in> U \<longrightarrow> P n)" for P
   526     by eventually_elim (insert \<open>T \<inter> S - {x} = U \<inter> S - {x}\<close>, blast)
   529     by eventually_elim (insert \<open>T \<inter> S - {x} = U \<inter> S - {x}\<close>, blast)
   527 qed
   530 qed
   528 
   531 
   529 lemma at_within_empty [simp]: "at a within {} = bot"
   532 lemma (in topological_space) at_within_empty [simp]: "at a within {} = bot"
   530   unfolding at_within_def by simp
   533   unfolding at_within_def by simp
   531 
   534 
   532 lemma at_within_union: "at x within (S \<union> T) = sup (at x within S) (at x within T)"
   535 lemma (in topological_space) at_within_union:
       
   536   "at x within (S \<union> T) = sup (at x within S) (at x within T)"
   533   unfolding filter_eq_iff eventually_sup eventually_at_filter
   537   unfolding filter_eq_iff eventually_sup eventually_at_filter
   534   by (auto elim!: eventually_rev_mp)
   538   by (auto elim!: eventually_rev_mp)
   535 
   539 
   536 lemma at_eq_bot_iff: "at a = bot \<longleftrightarrow> open {a}"
   540 lemma (in topological_space) at_eq_bot_iff: "at a = bot \<longleftrightarrow> open {a}"
   537   unfolding trivial_limit_def eventually_at_topological
   541   unfolding trivial_limit_def eventually_at_topological
   538   apply safe
   542   apply safe
   539    apply (case_tac "S = {a}")
   543    apply (case_tac "S = {a}")
   540     apply simp
   544     apply simp
   541    apply fast
   545    apply fast
   542   apply fast
   546   apply fast
   543   done
   547   done
   544 
   548 
   545 lemma at_neq_bot [simp]: "at a \<noteq> bot"
   549 lemma (in perfect_space) at_neq_bot [simp]: "at a \<noteq> bot"
   546   for a :: "'a::perfect_space"
       
   547   by (simp add: at_eq_bot_iff not_open_singleton)
   550   by (simp add: at_eq_bot_iff not_open_singleton)
   548 
   551 
   549 lemma (in order_topology) nhds_order:
   552 lemma (in order_topology) nhds_order:
   550   "nhds x = inf (INF a:{x <..}. principal {..< a}) (INF a:{..< x}. principal {a <..})"
   553   "nhds x = inf (INF a:{x <..}. principal {..< a}) (INF a:{..< x}. principal {a <..})"
   551 proof -
   554 proof -
   554     by auto
   557     by auto
   555   show ?thesis
   558   show ?thesis
   556     by (simp only: nhds_generated_topology[OF open_generated_order] INF_union 1 INF_image comp_def)
   559     by (simp only: nhds_generated_topology[OF open_generated_order] INF_union 1 INF_image comp_def)
   557 qed
   560 qed
   558 
   561 
   559 lemma filterlim_at_within_If:
   562 lemma (in topological_space) filterlim_at_within_If:
   560   assumes "filterlim f G (at x within (A \<inter> {x. P x}))"
   563   assumes "filterlim f G (at x within (A \<inter> {x. P x}))"
   561     and "filterlim g G (at x within (A \<inter> {x. \<not>P x}))"
   564     and "filterlim g G (at x within (A \<inter> {x. \<not>P x}))"
   562   shows "filterlim (\<lambda>x. if P x then f x else g x) G (at x within A)"
   565   shows "filterlim (\<lambda>x. if P x then f x else g x) G (at x within A)"
   563 proof (rule filterlim_If)
   566 proof (rule filterlim_If)
   564   note assms(1)
   567   note assms(1)
   578   also have "inf (nhds x) (principal \<dots>) = inf (at x within A) (principal {x. \<not> P x})"
   581   also have "inf (nhds x) (principal \<dots>) = inf (at x within A) (principal {x. \<not> P x})"
   579     by (simp add: at_within_def inf_assoc)
   582     by (simp add: at_within_def inf_assoc)
   580   finally show "filterlim g G (inf (at x within A) (principal {x. \<not> P x}))" .
   583   finally show "filterlim g G (inf (at x within A) (principal {x. \<not> P x}))" .
   581 qed
   584 qed
   582 
   585 
   583 lemma filterlim_at_If:
   586 lemma (in topological_space) filterlim_at_If:
   584   assumes "filterlim f G (at x within {x. P x})"
   587   assumes "filterlim f G (at x within {x. P x})"
   585     and "filterlim g G (at x within {x. \<not>P x})"
   588     and "filterlim g G (at x within {x. \<not>P x})"
   586   shows "filterlim (\<lambda>x. if P x then f x else g x) G (at x)"
   589   shows "filterlim (\<lambda>x. if P x then f x else g x) G (at x)"
   587   using assms by (intro filterlim_at_within_If) simp_all
   590   using assms by (intro filterlim_at_within_If) simp_all
   588 
   591 
   639 lemma trivial_limit_at_right_real [simp]: "\<not> trivial_limit (at_right x)"
   642 lemma trivial_limit_at_right_real [simp]: "\<not> trivial_limit (at_right x)"
   640   for x :: "'a::{no_top,dense_order,linorder_topology}"
   643   for x :: "'a::{no_top,dense_order,linorder_topology}"
   641   using gt_ex[of x]
   644   using gt_ex[of x]
   642   by safe (auto simp add: trivial_limit_def eventually_at_right dest: dense)
   645   by safe (auto simp add: trivial_limit_def eventually_at_right dest: dense)
   643 
   646 
   644 lemma at_eq_sup_left_right: "at x = sup (at_left x) (at_right x)"
   647 lemma (in linorder_topology) at_eq_sup_left_right: "at x = sup (at_left x) (at_right x)"
   645   for x :: "'a::linorder_topology"
       
   646   by (auto simp: eventually_at_filter filter_eq_iff eventually_sup
   648   by (auto simp: eventually_at_filter filter_eq_iff eventually_sup
   647       elim: eventually_elim2 eventually_mono)
   649       elim: eventually_elim2 eventually_mono)
   648 
   650 
   649 lemma eventually_at_split:
   651 lemma (in linorder_topology) eventually_at_split:
   650   "eventually P (at x) \<longleftrightarrow> eventually P (at_left x) \<and> eventually P (at_right x)"
   652   "eventually P (at x) \<longleftrightarrow> eventually P (at_left x) \<and> eventually P (at_right x)"
   651   for x :: "'a::linorder_topology"
       
   652   by (subst at_eq_sup_left_right) (simp add: eventually_sup)
   653   by (subst at_eq_sup_left_right) (simp add: eventually_sup)
   653 
   654 
   654 lemma eventually_at_leftI:
   655 lemma (in order_topology) eventually_at_leftI:
   655   assumes "\<And>x. x \<in> {a<..<b} \<Longrightarrow> P x" "a < b"
   656   assumes "\<And>x. x \<in> {a<..<b} \<Longrightarrow> P x" "a < b"
   656   shows   "eventually P (at_left b)"
   657   shows   "eventually P (at_left b)"
   657   using assms unfolding eventually_at_topological by (intro exI[of _ "{a<..}"]) auto
   658   using assms unfolding eventually_at_topological by (intro exI[of _ "{a<..}"]) auto
   658 
   659 
   659 lemma eventually_at_rightI:
   660 lemma (in order_topology) eventually_at_rightI:
   660   assumes "\<And>x. x \<in> {a<..<b} \<Longrightarrow> P x" "a < b"
   661   assumes "\<And>x. x \<in> {a<..<b} \<Longrightarrow> P x" "a < b"
   661   shows   "eventually P (at_right a)"
   662   shows   "eventually P (at_right a)"
   662   using assms unfolding eventually_at_topological by (intro exI[of _ "{..<b}"]) auto
   663   using assms unfolding eventually_at_topological by (intro exI[of _ "{..<b}"]) auto
   663 
   664 
   664 
   665 
   669   where "(f \<longlongrightarrow> l) F \<equiv> filterlim f (nhds l) F"
   670   where "(f \<longlongrightarrow> l) F \<equiv> filterlim f (nhds l) F"
   670 
   671 
   671 definition (in t2_space) Lim :: "'f filter \<Rightarrow> ('f \<Rightarrow> 'a) \<Rightarrow> 'a"
   672 definition (in t2_space) Lim :: "'f filter \<Rightarrow> ('f \<Rightarrow> 'a) \<Rightarrow> 'a"
   672   where "Lim A f = (THE l. (f \<longlongrightarrow> l) A)"
   673   where "Lim A f = (THE l. (f \<longlongrightarrow> l) A)"
   673 
   674 
   674 lemma tendsto_eq_rhs: "(f \<longlongrightarrow> x) F \<Longrightarrow> x = y \<Longrightarrow> (f \<longlongrightarrow> y) F"
   675 lemma (in topological_space) tendsto_eq_rhs: "(f \<longlongrightarrow> x) F \<Longrightarrow> x = y \<Longrightarrow> (f \<longlongrightarrow> y) F"
   675   by simp
   676   by simp
   676 
   677 
   677 named_theorems tendsto_intros "introduction rules for tendsto"
   678 named_theorems tendsto_intros "introduction rules for tendsto"
   678 setup \<open>
   679 setup \<open>
   679   Global_Theory.add_thms_dynamic (@{binding tendsto_eq_intros},
   680   Global_Theory.add_thms_dynamic (@{binding tendsto_eq_intros},
   680     fn context =>
   681     fn context =>
   681       Named_Theorems.get (Context.proof_of context) @{named_theorems tendsto_intros}
   682       Named_Theorems.get (Context.proof_of context) @{named_theorems tendsto_intros}
   682       |> map_filter (try (fn thm => @{thm tendsto_eq_rhs} OF [thm])))
   683       |> map_filter (try (fn thm => @{thm tendsto_eq_rhs} OF [thm])))
   683 \<close>
   684 \<close>
   684 
   685 
   685 lemma (in topological_space) tendsto_def:
   686 context topological_space begin
       
   687 
       
   688 lemma tendsto_def:
   686    "(f \<longlongrightarrow> l) F \<longleftrightarrow> (\<forall>S. open S \<longrightarrow> l \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) F)"
   689    "(f \<longlongrightarrow> l) F \<longleftrightarrow> (\<forall>S. open S \<longrightarrow> l \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) F)"
   687    unfolding nhds_def filterlim_INF filterlim_principal by auto
   690    unfolding nhds_def filterlim_INF filterlim_principal by auto
   688 
   691 
   689 lemma tendsto_cong: "(f \<longlongrightarrow> c) F \<longleftrightarrow> (g \<longlongrightarrow> c) F" if "eventually (\<lambda>x. f x = g x) F"
   692 lemma tendsto_cong: "(f \<longlongrightarrow> c) F \<longleftrightarrow> (g \<longlongrightarrow> c) F" if "eventually (\<lambda>x. f x = g x) F"
   690   by (rule filterlim_cong [OF refl refl that])
   693   by (rule filterlim_cong [OF refl refl that])
   691 
   694 
   692 lemma tendsto_mono: "F \<le> F' \<Longrightarrow> (f \<longlongrightarrow> l) F' \<Longrightarrow> (f \<longlongrightarrow> l) F"
   695 lemma tendsto_mono: "F \<le> F' \<Longrightarrow> (f \<longlongrightarrow> l) F' \<Longrightarrow> (f \<longlongrightarrow> l) F"
   693   unfolding tendsto_def le_filter_def by fast
   696   unfolding tendsto_def le_filter_def by fast
   694 
   697 
   695 lemma tendsto_within_subset: "(f \<longlongrightarrow> l) (at x within S) \<Longrightarrow> T \<subseteq> S \<Longrightarrow> (f \<longlongrightarrow> l) (at x within T)"
   698 lemma tendsto_ident_at [tendsto_intros, simp, intro]: "((\<lambda>x. x) \<longlongrightarrow> a) (at a within s)"
   696   by (blast intro: tendsto_mono at_le)
   699   by (auto simp: tendsto_def eventually_at_topological)
   697 
   700 
   698 lemma filterlim_at:
   701 lemma tendsto_const [tendsto_intros, simp, intro]: "((\<lambda>x. k) \<longlongrightarrow> k) F"
       
   702   by (simp add: tendsto_def)
       
   703 
       
   704 lemma  filterlim_at:
   699   "(LIM x F. f x :> at b within s) \<longleftrightarrow> eventually (\<lambda>x. f x \<in> s \<and> f x \<noteq> b) F \<and> (f \<longlongrightarrow> b) F"
   705   "(LIM x F. f x :> at b within s) \<longleftrightarrow> eventually (\<lambda>x. f x \<in> s \<and> f x \<noteq> b) F \<and> (f \<longlongrightarrow> b) F"
   700   by (simp add: at_within_def filterlim_inf filterlim_principal conj_commute)
   706   by (simp add: at_within_def filterlim_inf filterlim_principal conj_commute)
   701 
   707 
   702 lemma filterlim_at_withinI:
   708 lemma  filterlim_at_withinI:
   703   assumes "filterlim f (nhds c) F"
   709   assumes "filterlim f (nhds c) F"
   704   assumes "eventually (\<lambda>x. f x \<in> A - {c}) F"
   710   assumes "eventually (\<lambda>x. f x \<in> A - {c}) F"
   705   shows   "filterlim f (at c within A) F"
   711   shows   "filterlim f (at c within A) F"
   706   using assms by (simp add: filterlim_at)
   712   using assms by (simp add: filterlim_at)
   707 
   713 
   709   assumes "filterlim f (nhds c) F"
   715   assumes "filterlim f (nhds c) F"
   710   assumes "eventually (\<lambda>x. f x \<noteq> c) F"
   716   assumes "eventually (\<lambda>x. f x \<noteq> c) F"
   711   shows   "filterlim f (at c) F"
   717   shows   "filterlim f (at c) F"
   712   using assms by (intro filterlim_at_withinI) simp_all
   718   using assms by (intro filterlim_at_withinI) simp_all
   713 
   719 
   714 lemma (in topological_space) topological_tendstoI:
   720 lemma topological_tendstoI:
   715   "(\<And>S. open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) F) \<Longrightarrow> (f \<longlongrightarrow> l) F"
   721   "(\<And>S. open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) F) \<Longrightarrow> (f \<longlongrightarrow> l) F"
   716   by (auto simp: tendsto_def)
   722   by (auto simp: tendsto_def)
   717 
   723 
   718 lemma (in topological_space) topological_tendstoD:
   724 lemma topological_tendstoD:
   719   "(f \<longlongrightarrow> l) F \<Longrightarrow> open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) F"
   725   "(f \<longlongrightarrow> l) F \<Longrightarrow> open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) F"
   720   by (auto simp: tendsto_def)
   726   by (auto simp: tendsto_def)
       
   727 
       
   728 lemma tendsto_bot [simp]: "(f \<longlongrightarrow> a) bot"
       
   729   by (simp add: tendsto_def)
       
   730 
       
   731 end
       
   732 
       
   733 lemma tendsto_within_subset:
       
   734   "(f \<longlongrightarrow> l) (at x within S) \<Longrightarrow> T \<subseteq> S \<Longrightarrow> (f \<longlongrightarrow> l) (at x within T)"
       
   735   by (blast intro: tendsto_mono at_le)
   721 
   736 
   722 lemma (in order_topology) order_tendsto_iff:
   737 lemma (in order_topology) order_tendsto_iff:
   723   "(f \<longlongrightarrow> x) F \<longleftrightarrow> (\<forall>l<x. eventually (\<lambda>x. l < f x) F) \<and> (\<forall>u>x. eventually (\<lambda>x. f x < u) F)"
   738   "(f \<longlongrightarrow> x) F \<longleftrightarrow> (\<forall>l<x. eventually (\<lambda>x. l < f x) F) \<and> (\<forall>u>x. eventually (\<lambda>x. f x < u) F)"
   724   by (auto simp: nhds_order filterlim_inf filterlim_INF filterlim_principal)
   739   by (auto simp: nhds_order filterlim_inf filterlim_INF filterlim_principal)
   725 
   740 
   731 lemma (in order_topology) order_tendstoD:
   746 lemma (in order_topology) order_tendstoD:
   732   assumes "(f \<longlongrightarrow> y) F"
   747   assumes "(f \<longlongrightarrow> y) F"
   733   shows "a < y \<Longrightarrow> eventually (\<lambda>x. a < f x) F"
   748   shows "a < y \<Longrightarrow> eventually (\<lambda>x. a < f x) F"
   734     and "y < a \<Longrightarrow> eventually (\<lambda>x. f x < a) F"
   749     and "y < a \<Longrightarrow> eventually (\<lambda>x. f x < a) F"
   735   using assms by (auto simp: order_tendsto_iff)
   750   using assms by (auto simp: order_tendsto_iff)
   736 
       
   737 lemma tendsto_bot [simp]: "(f \<longlongrightarrow> a) bot"
       
   738   by (simp add: tendsto_def)
       
   739 
   751 
   740 lemma (in linorder_topology) tendsto_max:
   752 lemma (in linorder_topology) tendsto_max:
   741   assumes X: "(X \<longlongrightarrow> x) net"
   753   assumes X: "(X \<longlongrightarrow> x) net"
   742     and Y: "(Y \<longlongrightarrow> y) net"
   754     and Y: "(Y \<longlongrightarrow> y) net"
   743   shows "((\<lambda>x. max (X x) (Y x)) \<longlongrightarrow> max x y) net"
   755   shows "((\<lambda>x. max (X x) (Y x)) \<longlongrightarrow> max x y) net"
   771   then show "eventually (\<lambda>x. min (X x) (Y x) < a) net"
   783   then show "eventually (\<lambda>x. min (X x) (Y x) < a) net"
   772     using order_tendstoD(2)[OF X, of a] order_tendstoD(2)[OF Y, of a]
   784     using order_tendstoD(2)[OF X, of a] order_tendstoD(2)[OF Y, of a]
   773     by (auto simp: min_less_iff_disj elim: eventually_mono)
   785     by (auto simp: min_less_iff_disj elim: eventually_mono)
   774 qed
   786 qed
   775 
   787 
   776 lemma tendsto_ident_at [tendsto_intros, simp, intro]: "((\<lambda>x. x) \<longlongrightarrow> a) (at a within s)"
   788 lemma (in order_topology)
   777   by (auto simp: tendsto_def eventually_at_topological)
   789   assumes "a < b"
   778 
   790   shows at_within_Icc_at_right: "at a within {a..b} = at_right a"
   779 lemma (in topological_space) tendsto_const [tendsto_intros, simp, intro]: "((\<lambda>x. k) \<longlongrightarrow> k) F"
   791     and at_within_Icc_at_left:  "at b within {a..b} = at_left b"
   780   by (simp add: tendsto_def)
   792   using order_tendstoD(2)[OF tendsto_ident_at assms, of "{a<..}"]
       
   793   using order_tendstoD(1)[OF tendsto_ident_at assms, of "{..<b}"]
       
   794   by (auto intro!: order_class.antisym filter_leI
       
   795       simp: eventually_at_filter less_le
       
   796       elim: eventually_elim2)
       
   797 
       
   798 lemma (in order_topology) at_within_Icc_at: "a < x \<Longrightarrow> x < b \<Longrightarrow> at x within {a..b} = at x"
       
   799   by (rule at_within_open_subset[where S="{a<..<b}"]) auto
   781 
   800 
   782 lemma (in t2_space) tendsto_unique:
   801 lemma (in t2_space) tendsto_unique:
   783   assumes "F \<noteq> bot"
   802   assumes "F \<noteq> bot"
   784     and "(f \<longlongrightarrow> a) F"
   803     and "(f \<longlongrightarrow> a) F"
   785     and "(f \<longlongrightarrow> b) F"
   804     and "(f \<longlongrightarrow> b) F"
   808   fixes a b :: 'a
   827   fixes a b :: 'a
   809   assumes "\<not> trivial_limit F"
   828   assumes "\<not> trivial_limit F"
   810   shows "((\<lambda>x. a) \<longlongrightarrow> b) F \<longleftrightarrow> a = b"
   829   shows "((\<lambda>x. a) \<longlongrightarrow> b) F \<longleftrightarrow> a = b"
   811   by (auto intro!: tendsto_unique [OF assms tendsto_const])
   830   by (auto intro!: tendsto_unique [OF assms tendsto_const])
   812 
   831 
   813 lemma increasing_tendsto:
   832 lemma (in order_topology) increasing_tendsto:
   814   fixes f :: "_ \<Rightarrow> 'a::order_topology"
       
   815   assumes bdd: "eventually (\<lambda>n. f n \<le> l) F"
   833   assumes bdd: "eventually (\<lambda>n. f n \<le> l) F"
   816     and en: "\<And>x. x < l \<Longrightarrow> eventually (\<lambda>n. x < f n) F"
   834     and en: "\<And>x. x < l \<Longrightarrow> eventually (\<lambda>n. x < f n) F"
   817   shows "(f \<longlongrightarrow> l) F"
   835   shows "(f \<longlongrightarrow> l) F"
   818   using assms by (intro order_tendstoI) (auto elim!: eventually_mono)
   836   using assms by (intro order_tendstoI) (auto elim!: eventually_mono)
   819 
   837 
   820 lemma decreasing_tendsto:
   838 lemma (in order_topology) decreasing_tendsto:
   821   fixes f :: "_ \<Rightarrow> 'a::order_topology"
       
   822   assumes bdd: "eventually (\<lambda>n. l \<le> f n) F"
   839   assumes bdd: "eventually (\<lambda>n. l \<le> f n) F"
   823     and en: "\<And>x. l < x \<Longrightarrow> eventually (\<lambda>n. f n < x) F"
   840     and en: "\<And>x. l < x \<Longrightarrow> eventually (\<lambda>n. f n < x) F"
   824   shows "(f \<longlongrightarrow> l) F"
   841   shows "(f \<longlongrightarrow> l) F"
   825   using assms by (intro order_tendstoI) (auto elim!: eventually_mono)
   842   using assms by (intro order_tendstoI) (auto elim!: eventually_mono)
   826 
   843 
   827 lemma tendsto_sandwich:
   844 lemma (in order_topology) tendsto_sandwich:
   828   fixes f g h :: "'a \<Rightarrow> 'b::order_topology"
       
   829   assumes ev: "eventually (\<lambda>n. f n \<le> g n) net" "eventually (\<lambda>n. g n \<le> h n) net"
   845   assumes ev: "eventually (\<lambda>n. f n \<le> g n) net" "eventually (\<lambda>n. g n \<le> h n) net"
   830   assumes lim: "(f \<longlongrightarrow> c) net" "(h \<longlongrightarrow> c) net"
   846   assumes lim: "(f \<longlongrightarrow> c) net" "(h \<longlongrightarrow> c) net"
   831   shows "(g \<longlongrightarrow> c) net"
   847   shows "(g \<longlongrightarrow> c) net"
   832 proof (rule order_tendstoI)
   848 proof (rule order_tendstoI)
   833   fix a
   849   fix a
   837   fix a
   853   fix a
   838   show "c < a \<Longrightarrow> eventually (\<lambda>x. g x < a) net"
   854   show "c < a \<Longrightarrow> eventually (\<lambda>x. g x < a) net"
   839     using order_tendstoD[OF lim(2), of a] ev by (auto elim: eventually_elim2)
   855     using order_tendstoD[OF lim(2), of a] ev by (auto elim: eventually_elim2)
   840 qed
   856 qed
   841 
   857 
   842 lemma limit_frequently_eq:
   858 lemma (in t1_space) limit_frequently_eq:
   843   fixes c d :: "'a::t1_space"
       
   844   assumes "F \<noteq> bot"
   859   assumes "F \<noteq> bot"
   845     and "frequently (\<lambda>x. f x = c) F"
   860     and "frequently (\<lambda>x. f x = c) F"
   846     and "(f \<longlongrightarrow> d) F"
   861     and "(f \<longlongrightarrow> d) F"
   847   shows "d = c"
   862   shows "d = c"
   848 proof (rule ccontr)
   863 proof (rule ccontr)
   855     by eventually_elim (insert \<open>c \<notin> U\<close>, blast)
   870     by eventually_elim (insert \<open>c \<notin> U\<close>, blast)
   856   with assms(2) show False
   871   with assms(2) show False
   857     unfolding frequently_def by contradiction
   872     unfolding frequently_def by contradiction
   858 qed
   873 qed
   859 
   874 
   860 lemma tendsto_imp_eventually_ne:
   875 lemma (in t1_space) tendsto_imp_eventually_ne:
   861   fixes c :: "'a::t1_space"
       
   862   assumes  "(f \<longlongrightarrow> c) F" "c \<noteq> c'"
   876   assumes  "(f \<longlongrightarrow> c) F" "c \<noteq> c'"
   863   shows "eventually (\<lambda>z. f z \<noteq> c') F"
   877   shows "eventually (\<lambda>z. f z \<noteq> c') F"
   864 proof (cases "F=bot")
   878 proof (cases "F=bot")
   865   case True
   879   case True
   866   thus ?thesis by auto
   880   thus ?thesis by auto
   874     from limit_frequently_eq[OF False this \<open>(f \<longlongrightarrow> c) F\<close>] and \<open>c \<noteq> c'\<close> show False
   888     from limit_frequently_eq[OF False this \<open>(f \<longlongrightarrow> c) F\<close>] and \<open>c \<noteq> c'\<close> show False
   875       by contradiction
   889       by contradiction
   876   qed
   890   qed
   877 qed
   891 qed
   878 
   892 
   879 lemma tendsto_le:
   893 lemma (in linorder_topology) tendsto_le:
   880   fixes f g :: "'a \<Rightarrow> 'b::linorder_topology"
       
   881   assumes F: "\<not> trivial_limit F"
   894   assumes F: "\<not> trivial_limit F"
   882     and x: "(f \<longlongrightarrow> x) F"
   895     and x: "(f \<longlongrightarrow> x) F"
   883     and y: "(g \<longlongrightarrow> y) F"
   896     and y: "(g \<longlongrightarrow> y) F"
   884     and ev: "eventually (\<lambda>x. g x \<le> f x) F"
   897     and ev: "eventually (\<lambda>x. g x \<le> f x) F"
   885   shows "y \<le> x"
   898   shows "y \<le> x"
   893     by eventually_elim (insert xy, fastforce)
   906     by eventually_elim (insert xy, fastforce)
   894   with F show False
   907   with F show False
   895     by (simp add: eventually_False)
   908     by (simp add: eventually_False)
   896 qed
   909 qed
   897 
   910 
   898 lemma tendsto_lowerbound:
   911 lemma (in linorder_topology) tendsto_lowerbound:
   899   fixes f :: "'a \<Rightarrow> 'b::linorder_topology"
       
   900   assumes x: "(f \<longlongrightarrow> x) F"
   912   assumes x: "(f \<longlongrightarrow> x) F"
   901       and ev: "eventually (\<lambda>i. a \<le> f i) F"
   913       and ev: "eventually (\<lambda>i. a \<le> f i) F"
   902       and F: "\<not> trivial_limit F"
   914       and F: "\<not> trivial_limit F"
   903   shows "a \<le> x"
   915   shows "a \<le> x"
   904   using F x tendsto_const ev by (rule tendsto_le)
   916   using F x tendsto_const ev by (rule tendsto_le)
   905 
   917 
   906 lemma tendsto_upperbound:
   918 lemma (in linorder_topology) tendsto_upperbound:
   907   fixes f :: "'a \<Rightarrow> 'b::linorder_topology"
       
   908   assumes x: "(f \<longlongrightarrow> x) F"
   919   assumes x: "(f \<longlongrightarrow> x) F"
   909       and ev: "eventually (\<lambda>i. a \<ge> f i) F"
   920       and ev: "eventually (\<lambda>i. a \<ge> f i) F"
   910       and F: "\<not> trivial_limit F"
   921       and F: "\<not> trivial_limit F"
   911   shows "a \<ge> x"
   922   shows "a \<ge> x"
   912   by (rule tendsto_le [OF F tendsto_const x ev])
   923   by (rule tendsto_le [OF F tendsto_const x ev])
  1838 
  1849 
  1839 lemma continuous_on_const[continuous_intros]: "continuous_on s (\<lambda>x. c)"
  1850 lemma continuous_on_const[continuous_intros]: "continuous_on s (\<lambda>x. c)"
  1840   unfolding continuous_on_def by auto
  1851   unfolding continuous_on_def by auto
  1841 
  1852 
  1842 lemma continuous_on_subset: "continuous_on s f \<Longrightarrow> t \<subseteq> s \<Longrightarrow> continuous_on t f"
  1853 lemma continuous_on_subset: "continuous_on s f \<Longrightarrow> t \<subseteq> s \<Longrightarrow> continuous_on t f"
  1843   unfolding continuous_on_def by (metis subset_eq tendsto_within_subset)
  1854   unfolding continuous_on_def
       
  1855   by (metis subset_eq tendsto_within_subset)
  1844 
  1856 
  1845 lemma continuous_on_compose[continuous_intros]:
  1857 lemma continuous_on_compose[continuous_intros]:
  1846   "continuous_on s f \<Longrightarrow> continuous_on (f ` s) g \<Longrightarrow> continuous_on s (g \<circ> f)"
  1858   "continuous_on s f \<Longrightarrow> continuous_on (f ` s) g \<Longrightarrow> continuous_on s (g \<circ> f)"
  1847   unfolding continuous_on_topological by simp metis
  1859   unfolding continuous_on_topological by simp metis
  1848 
  1860 
  1909   qed
  1921   qed
  1910   then show "\<exists>C. open C \<and> C \<inter> A = f -` {b <..} \<inter> A" for b
  1922   then show "\<exists>C. open C \<and> C \<inter> A = f -` {b <..} \<inter> A" for b
  1911     by (intro exI[of _ "(\<Union>x\<in>{x\<in>A. b < f x}. {x <..})"])
  1923     by (intro exI[of _ "(\<Union>x\<in>{x\<in>A. b < f x}. {x <..})"])
  1912        (auto intro: less_le_trans[OF _ mono] less_imp_le)
  1924        (auto intro: less_le_trans[OF _ mono] less_imp_le)
  1913 qed
  1925 qed
       
  1926 
       
  1927 lemma continuous_on_IccI:
       
  1928   "\<lbrakk>(f \<longlongrightarrow> f a) (at_right a);
       
  1929     (f \<longlongrightarrow> f b) (at_left b);
       
  1930     (\<And>x. a < x \<Longrightarrow> x < b \<Longrightarrow> f \<midarrow>x\<rightarrow> f x); a < b\<rbrakk> \<Longrightarrow>
       
  1931     continuous_on {a .. b} f"
       
  1932   for a::"'a::linorder_topology"
       
  1933   using at_within_open[of _ "{a<..<b}"]
       
  1934   by (auto simp: continuous_on_def at_within_Icc_at_right at_within_Icc_at_left le_less
       
  1935       at_within_Icc_at)
       
  1936 
       
  1937 lemma
       
  1938   fixes a b::"'a::linorder_topology"
       
  1939   assumes "continuous_on {a .. b} f" "a < b"
       
  1940   shows continuous_on_Icc_at_rightD: "(f \<longlongrightarrow> f a) (at_right a)"
       
  1941     and continuous_on_Icc_at_leftD: "(f \<longlongrightarrow> f b) (at_left b)"
       
  1942   using assms
       
  1943   by (auto simp: at_within_Icc_at_right at_within_Icc_at_left continuous_on_def
       
  1944       dest: bspec[where x=a] bspec[where x=b])
  1914 
  1945 
  1915 
  1946 
  1916 subsubsection \<open>Continuity at a point\<close>
  1947 subsubsection \<open>Continuity at a point\<close>
  1917 
  1948 
  1918 definition continuous :: "'a::t2_space filter \<Rightarrow> ('a \<Rightarrow> 'b::topological_space) \<Rightarrow> bool"
  1949 definition continuous :: "'a::t2_space filter \<Rightarrow> ('a \<Rightarrow> 'b::topological_space) \<Rightarrow> bool"