src/HOL/Topological_Spaces.thy
changeset 57276 49c51eeaa623
parent 57275 0ddb5b755cdc
child 57447 87429bdecad5
equal deleted inserted replaced
57275:0ddb5b755cdc 57276:49c51eeaa623
   528   by (rule eventually_False [symmetric])
   528   by (rule eventually_False [symmetric])
   529 
   529 
   530 lemma eventually_const: "\<not> trivial_limit net \<Longrightarrow> eventually (\<lambda>x. P) net \<longleftrightarrow> P"
   530 lemma eventually_const: "\<not> trivial_limit net \<Longrightarrow> eventually (\<lambda>x. P) net \<longleftrightarrow> P"
   531   by (cases P) (simp_all add: eventually_False)
   531   by (cases P) (simp_all add: eventually_False)
   532 
   532 
       
   533 lemma eventually_Inf: "eventually P (Inf B) \<longleftrightarrow> (\<exists>X\<subseteq>B. finite X \<and> eventually P (Inf X))"
       
   534 proof -
       
   535   let ?F = "\<lambda>P. \<exists>X\<subseteq>B. finite X \<and> eventually P (Inf X)"
       
   536   
       
   537   { fix P have "eventually P (Abs_filter ?F) \<longleftrightarrow> ?F P"
       
   538     proof (rule eventually_Abs_filter is_filter.intro)+
       
   539       show "?F (\<lambda>x. True)"
       
   540         by (rule exI[of _ "{}"]) (simp add: le_fun_def)
       
   541     next
       
   542       fix P Q
       
   543       assume "?F P" then guess X ..
       
   544       moreover
       
   545       assume "?F Q" then guess Y ..
       
   546       ultimately show "?F (\<lambda>x. P x \<and> Q x)"
       
   547         by (intro exI[of _ "X \<union> Y"])
       
   548            (auto simp: Inf_union_distrib eventually_inf)
       
   549     next
       
   550       fix P Q
       
   551       assume "?F P" then guess X ..
       
   552       moreover assume "\<forall>x. P x \<longrightarrow> Q x"
       
   553       ultimately show "?F Q"
       
   554         by (intro exI[of _ X]) (auto elim: eventually_elim1)
       
   555     qed }
       
   556   note eventually_F = this
       
   557 
       
   558   have "Inf B = Abs_filter ?F"
       
   559   proof (intro antisym Inf_greatest)
       
   560     show "Inf B \<le> Abs_filter ?F"
       
   561       by (auto simp: le_filter_def eventually_F dest: Inf_superset_mono)
       
   562   next
       
   563     fix F assume "F \<in> B" then show "Abs_filter ?F \<le> F"
       
   564       by (auto simp add: le_filter_def eventually_F intro!: exI[of _ "{F}"])
       
   565   qed
       
   566   then show ?thesis
       
   567     by (simp add: eventually_F)
       
   568 qed
       
   569 
       
   570 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))"
       
   571   unfolding INF_def[of B] eventually_Inf[of P "F`B"]
       
   572   by (metis Inf_image_eq finite_imageI image_mono finite_subset_image)
       
   573 
       
   574 lemma Inf_filter_not_bot:
       
   575   fixes B :: "'a filter set"
       
   576   shows "(\<And>X. X \<subseteq> B \<Longrightarrow> finite X \<Longrightarrow> Inf X \<noteq> bot) \<Longrightarrow> Inf B \<noteq> bot"
       
   577   unfolding trivial_limit_def eventually_Inf[of _ B]
       
   578     bot_bool_def [symmetric] bot_fun_def [symmetric] bot_unique by simp
       
   579 
       
   580 lemma INF_filter_not_bot:
       
   581   fixes F :: "'i \<Rightarrow> 'a filter"
       
   582   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"
       
   583   unfolding trivial_limit_def eventually_INF[of _ B]
       
   584     bot_bool_def [symmetric] bot_fun_def [symmetric] bot_unique by simp
       
   585 
       
   586 lemma eventually_Inf_base:
       
   587   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"
       
   588   shows "eventually P (Inf B) \<longleftrightarrow> (\<exists>b\<in>B. eventually P b)"
       
   589 proof (subst eventually_Inf, safe)
       
   590   fix X assume "finite X" "X \<subseteq> B"
       
   591   then have "\<exists>b\<in>B. \<forall>x\<in>X. b \<le> x"
       
   592   proof induct
       
   593     case empty then show ?case
       
   594       using `B \<noteq> {}` by auto
       
   595   next
       
   596     case (insert x X)
       
   597     then obtain b where "b \<in> B" "\<And>x. x \<in> X \<Longrightarrow> b \<le> x"
       
   598       by auto
       
   599     with `insert x X \<subseteq> B` base[of b x] show ?case
       
   600       by (auto intro: order_trans)
       
   601   qed
       
   602   then obtain b where "b \<in> B" "b \<le> Inf X"
       
   603     by (auto simp: le_Inf_iff)
       
   604   then show "eventually P (Inf X) \<Longrightarrow> Bex B (eventually P)"
       
   605     by (intro bexI[of _ b]) (auto simp: le_filter_def)
       
   606 qed (auto intro!: exI[of _ "{x}" for x])
       
   607 
       
   608 lemma eventually_INF_base:
       
   609   "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>
       
   610     eventually P (INF b:B. F b) \<longleftrightarrow> (\<exists>b\<in>B. eventually P (F b))"
       
   611   unfolding INF_def by (subst eventually_Inf_base) auto
       
   612 
   533 
   613 
   534 subsubsection {* Map function for filters *}
   614 subsubsection {* Map function for filters *}
   535 
   615 
   536 definition filtermap :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a filter \<Rightarrow> 'b filter"
   616 definition filtermap :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a filter \<Rightarrow> 'b filter"
   537   where "filtermap f F = Abs_filter (\<lambda>P. eventually (\<lambda>x. P (f x)) F)"
   617   where "filtermap f F = Abs_filter (\<lambda>P. eventually (\<lambda>x. P (f x)) F)"
   558   by (simp add: filter_eq_iff eventually_filtermap)
   638   by (simp add: filter_eq_iff eventually_filtermap)
   559 
   639 
   560 lemma filtermap_sup: "filtermap f (sup F1 F2) = sup (filtermap f F1) (filtermap f F2)"
   640 lemma filtermap_sup: "filtermap f (sup F1 F2) = sup (filtermap f F1) (filtermap f F2)"
   561   by (auto simp: filter_eq_iff eventually_filtermap eventually_sup)
   641   by (auto simp: filter_eq_iff eventually_filtermap eventually_sup)
   562 
   642 
       
   643 lemma filtermap_inf: "filtermap f (inf F1 F2) \<le> inf (filtermap f F1) (filtermap f F2)"
       
   644   by (auto simp: le_filter_def eventually_filtermap eventually_inf)
       
   645 
       
   646 lemma filtermap_INF: "filtermap f (INF b:B. F b) \<le> (INF b:B. filtermap f (F b))"
       
   647 proof -
       
   648   { fix X :: "'c set" assume "finite X"
       
   649     then have "filtermap f (INFIMUM X F) \<le> (INF b:X. filtermap f (F b))"
       
   650     proof induct
       
   651       case (insert x X)
       
   652       have "filtermap f (INF a:insert x X. F a) \<le> inf (filtermap f (F x)) (filtermap f (INF a:X. F a))"
       
   653         by (rule order_trans[OF _ filtermap_inf]) simp
       
   654       also have "\<dots> \<le> inf (filtermap f (F x)) (INF a:X. filtermap f (F a))"
       
   655         by (intro inf_mono insert order_refl)
       
   656       finally show ?case
       
   657         by simp
       
   658     qed simp }
       
   659   then show ?thesis
       
   660     unfolding le_filter_def eventually_filtermap
       
   661     by (subst (1 2) eventually_INF) auto
       
   662 qed
       
   663 subsubsection {* Standard filters *}
       
   664 
       
   665 definition principal :: "'a set \<Rightarrow> 'a filter" where
       
   666   "principal S = Abs_filter (\<lambda>P. \<forall>x\<in>S. P x)"
       
   667 
       
   668 lemma eventually_principal: "eventually P (principal S) \<longleftrightarrow> (\<forall>x\<in>S. P x)"
       
   669   unfolding principal_def
       
   670   by (rule eventually_Abs_filter, rule is_filter.intro) auto
       
   671 
       
   672 lemma eventually_inf_principal: "eventually P (inf F (principal s)) \<longleftrightarrow> eventually (\<lambda>x. x \<in> s \<longrightarrow> P x) F"
       
   673   unfolding eventually_inf eventually_principal by (auto elim: eventually_elim1)
       
   674 
       
   675 lemma principal_UNIV[simp]: "principal UNIV = top"
       
   676   by (auto simp: filter_eq_iff eventually_principal)
       
   677 
       
   678 lemma principal_empty[simp]: "principal {} = bot"
       
   679   by (auto simp: filter_eq_iff eventually_principal)
       
   680 
       
   681 lemma principal_eq_bot_iff: "principal X = bot \<longleftrightarrow> X = {}"
       
   682   by (auto simp add: filter_eq_iff eventually_principal)
       
   683 
       
   684 lemma principal_le_iff[iff]: "principal A \<le> principal B \<longleftrightarrow> A \<subseteq> B"
       
   685   by (auto simp: le_filter_def eventually_principal)
       
   686 
       
   687 lemma le_principal: "F \<le> principal A \<longleftrightarrow> eventually (\<lambda>x. x \<in> A) F"
       
   688   unfolding le_filter_def eventually_principal
       
   689   apply safe
       
   690   apply (erule_tac x="\<lambda>x. x \<in> A" in allE)
       
   691   apply (auto elim: eventually_elim1)
       
   692   done
       
   693 
       
   694 lemma principal_inject[iff]: "principal A = principal B \<longleftrightarrow> A = B"
       
   695   unfolding eq_iff by simp
       
   696 
       
   697 lemma sup_principal[simp]: "sup (principal A) (principal B) = principal (A \<union> B)"
       
   698   unfolding filter_eq_iff eventually_sup eventually_principal by auto
       
   699 
       
   700 lemma inf_principal[simp]: "inf (principal A) (principal B) = principal (A \<inter> B)"
       
   701   unfolding filter_eq_iff eventually_inf eventually_principal
       
   702   by (auto intro: exI[of _ "\<lambda>x. x \<in> A"] exI[of _ "\<lambda>x. x \<in> B"])
       
   703 
       
   704 lemma SUP_principal[simp]: "(SUP i : I. principal (A i)) = principal (\<Union>i\<in>I. A i)"
       
   705   unfolding filter_eq_iff eventually_Sup SUP_def by (auto simp: eventually_principal)
       
   706 
       
   707 lemma INF_principal_finite: "finite X \<Longrightarrow> (INF x:X. principal (f x)) = principal (\<Inter>x\<in>X. f x)"
       
   708   by (induct X rule: finite_induct) auto
       
   709 
       
   710 lemma filtermap_principal[simp]: "filtermap f (principal A) = principal (f ` A)"
       
   711   unfolding filter_eq_iff eventually_filtermap eventually_principal by simp
       
   712 
   563 subsubsection {* Order filters *}
   713 subsubsection {* Order filters *}
   564 
   714 
   565 definition at_top :: "('a::order) filter"
   715 definition at_top :: "('a::order) filter"
   566   where "at_top = Abs_filter (\<lambda>P. \<exists>k. \<forall>n\<ge>k. P n)"
   716   where "at_top = (INF k. principal {k ..})"
   567 
   717 
   568 lemma eventually_at_top_linorder: "eventually P at_top \<longleftrightarrow> (\<exists>N::'a::linorder. \<forall>n\<ge>N. P n)"
   718 lemma eventually_at_top_linorder: "eventually P at_top \<longleftrightarrow> (\<exists>N::'a::linorder. \<forall>n\<ge>N. P n)"
   569   unfolding at_top_def
   719   unfolding at_top_def
   570 proof (rule eventually_Abs_filter, rule is_filter.intro)
   720   by (subst eventually_INF_base) (auto simp: eventually_principal intro: max.cobounded1 max.cobounded2)
   571   fix P Q :: "'a \<Rightarrow> bool"
       
   572   assume "\<exists>i. \<forall>n\<ge>i. P n" and "\<exists>j. \<forall>n\<ge>j. Q n"
       
   573   then obtain i j where "\<forall>n\<ge>i. P n" and "\<forall>n\<ge>j. Q n" by auto
       
   574   then have "\<forall>n\<ge>max i j. P n \<and> Q n" by simp
       
   575   then show "\<exists>k. \<forall>n\<ge>k. P n \<and> Q n" ..
       
   576 qed auto
       
   577 
   721 
   578 lemma eventually_ge_at_top:
   722 lemma eventually_ge_at_top:
   579   "eventually (\<lambda>x. (c::_::linorder) \<le> x) at_top"
   723   "eventually (\<lambda>x. (c::_::linorder) \<le> x) at_top"
   580   unfolding eventually_at_top_linorder by auto
   724   unfolding eventually_at_top_linorder by auto
   581 
   725 
   582 lemma eventually_at_top_dense: "eventually P at_top \<longleftrightarrow> (\<exists>N::'a::unbounded_dense_linorder. \<forall>n>N. P n)"
   726 lemma (in linorder) Ici_subset_Ioi_iff: "{a ..} \<subseteq> {b <..} \<longleftrightarrow> b < a"
   583   unfolding eventually_at_top_linorder
   727   by auto
   584 proof safe
   728 
   585   fix N assume "\<forall>n\<ge>N. P n"
   729 lemma (in linorder) Iic_subset_Iio_iff: "{.. a} \<subseteq> {..< b} \<longleftrightarrow> a < b"
   586   then show "\<exists>N. \<forall>n>N. P n" by (auto intro!: exI[of _ N])
   730   by auto
   587 next
   731 
   588   fix N assume "\<forall>n>N. P n"
   732 lemma eventually_at_top_dense: "eventually P at_top \<longleftrightarrow> (\<exists>N::'a::{no_top, linorder}. \<forall>n>N. P n)"
   589   moreover obtain y where "N < y" using gt_ex[of N] ..
   733 proof -
   590   ultimately show "\<exists>N. \<forall>n\<ge>N. P n" by (auto intro!: exI[of _ y])
   734   have "eventually P (INF k. principal {k <..}) \<longleftrightarrow> (\<exists>N::'a. \<forall>n>N. P n)"
       
   735     by (subst eventually_INF_base) (auto simp: eventually_principal intro: max.cobounded1 max.cobounded2)
       
   736   also have "(INF k. principal {k::'a <..}) = at_top"
       
   737     unfolding at_top_def 
       
   738     by (intro INF_eq) (auto intro: less_imp_le simp: Ici_subset_Ioi_iff gt_ex)
       
   739   finally show ?thesis .
   591 qed
   740 qed
   592 
   741 
   593 lemma eventually_gt_at_top:
   742 lemma eventually_gt_at_top:
   594   "eventually (\<lambda>x. (c::_::unbounded_dense_linorder) < x) at_top"
   743   "eventually (\<lambda>x. (c::_::unbounded_dense_linorder) < x) at_top"
   595   unfolding eventually_at_top_dense by auto
   744   unfolding eventually_at_top_dense by auto
   596 
   745 
   597 definition at_bot :: "('a::order) filter"
   746 definition at_bot :: "('a::order) filter"
   598   where "at_bot = Abs_filter (\<lambda>P. \<exists>k. \<forall>n\<le>k. P n)"
   747   where "at_bot = (INF k. principal {.. k})"
   599 
   748 
   600 lemma eventually_at_bot_linorder:
   749 lemma eventually_at_bot_linorder:
   601   fixes P :: "'a::linorder \<Rightarrow> bool" shows "eventually P at_bot \<longleftrightarrow> (\<exists>N. \<forall>n\<le>N. P n)"
   750   fixes P :: "'a::linorder \<Rightarrow> bool" shows "eventually P at_bot \<longleftrightarrow> (\<exists>N. \<forall>n\<le>N. P n)"
   602   unfolding at_bot_def
   751   unfolding at_bot_def
   603 proof (rule eventually_Abs_filter, rule is_filter.intro)
   752   by (subst eventually_INF_base) (auto simp: eventually_principal intro: min.cobounded1 min.cobounded2)
   604   fix P Q :: "'a \<Rightarrow> bool"
       
   605   assume "\<exists>i. \<forall>n\<le>i. P n" and "\<exists>j. \<forall>n\<le>j. Q n"
       
   606   then obtain i j where "\<forall>n\<le>i. P n" and "\<forall>n\<le>j. Q n" by auto
       
   607   then have "\<forall>n\<le>min i j. P n \<and> Q n" by simp
       
   608   then show "\<exists>k. \<forall>n\<le>k. P n \<and> Q n" ..
       
   609 qed auto
       
   610 
   753 
   611 lemma eventually_le_at_bot:
   754 lemma eventually_le_at_bot:
   612   "eventually (\<lambda>x. x \<le> (c::_::linorder)) at_bot"
   755   "eventually (\<lambda>x. x \<le> (c::_::linorder)) at_bot"
   613   unfolding eventually_at_bot_linorder by auto
   756   unfolding eventually_at_bot_linorder by auto
   614 
   757 
   615 lemma eventually_at_bot_dense:
   758 lemma eventually_at_bot_dense: "eventually P at_bot \<longleftrightarrow> (\<exists>N::'a::{no_bot, linorder}. \<forall>n<N. P n)"
   616   fixes P :: "'a::unbounded_dense_linorder \<Rightarrow> bool" shows "eventually P at_bot \<longleftrightarrow> (\<exists>N. \<forall>n<N. P n)"
   759 proof -
   617   unfolding eventually_at_bot_linorder
   760   have "eventually P (INF k. principal {..< k}) \<longleftrightarrow> (\<exists>N::'a. \<forall>n<N. P n)"
   618 proof safe
   761     by (subst eventually_INF_base) (auto simp: eventually_principal intro: min.cobounded1 min.cobounded2)
   619   fix N assume "\<forall>n\<le>N. P n" then show "\<exists>N. \<forall>n<N. P n" by (auto intro!: exI[of _ N])
   762   also have "(INF k. principal {..< k::'a}) = at_bot"
   620 next
   763     unfolding at_bot_def 
   621   fix N assume "\<forall>n<N. P n" 
   764     by (intro INF_eq) (auto intro: less_imp_le simp: Iic_subset_Iio_iff lt_ex)
   622   moreover obtain y where "y < N" using lt_ex[of N] ..
   765   finally show ?thesis .
   623   ultimately show "\<exists>N. \<forall>n\<le>N. P n" by (auto intro!: exI[of _ y])
       
   624 qed
   766 qed
   625 
   767 
   626 lemma eventually_gt_at_bot:
   768 lemma eventually_gt_at_bot:
   627   "eventually (\<lambda>x. x < (c::_::unbounded_dense_linorder)) at_bot"
   769   "eventually (\<lambda>x. x < (c::_::unbounded_dense_linorder)) at_bot"
   628   unfolding eventually_at_bot_dense by auto
   770   unfolding eventually_at_bot_dense by auto
   636   by (metis eventually_at_top_linorder order_refl)
   778   by (metis eventually_at_top_linorder order_refl)
   637 
   779 
   638 subsection {* Sequentially *}
   780 subsection {* Sequentially *}
   639 
   781 
   640 abbreviation sequentially :: "nat filter"
   782 abbreviation sequentially :: "nat filter"
   641   where "sequentially == at_top"
   783   where "sequentially \<equiv> at_top"
   642 
       
   643 lemma sequentially_def: "sequentially = Abs_filter (\<lambda>P. \<exists>k. \<forall>n\<ge>k. P n)"
       
   644   unfolding at_top_def by simp
       
   645 
   784 
   646 lemma eventually_sequentially:
   785 lemma eventually_sequentially:
   647   "eventually P sequentially \<longleftrightarrow> (\<exists>N. \<forall>n\<ge>N. P n)"
   786   "eventually P sequentially \<longleftrightarrow> (\<exists>N. \<forall>n\<ge>N. P n)"
   648   by (rule eventually_at_top_linorder)
   787   by (rule eventually_at_top_linorder)
   649 
   788 
   656   "\<not> eventually (\<lambda>n. False) sequentially"
   795   "\<not> eventually (\<lambda>n. False) sequentially"
   657   by (simp add: eventually_False)
   796   by (simp add: eventually_False)
   658 
   797 
   659 lemma le_sequentially:
   798 lemma le_sequentially:
   660   "F \<le> sequentially \<longleftrightarrow> (\<forall>N. eventually (\<lambda>n. N \<le> n) F)"
   799   "F \<le> sequentially \<longleftrightarrow> (\<forall>N. eventually (\<lambda>n. N \<le> n) F)"
   661   unfolding le_filter_def eventually_sequentially
   800   by (simp add: at_top_def le_INF_iff le_principal)
   662   by (safe, fast, drule_tac x=N in spec, auto elim: eventually_rev_mp)
       
   663 
   801 
   664 lemma eventually_sequentiallyI:
   802 lemma eventually_sequentiallyI:
   665   assumes "\<And>x. c \<le> x \<Longrightarrow> P x"
   803   assumes "\<And>x. c \<le> x \<Longrightarrow> P x"
   666   shows "eventually P sequentially"
   804   shows "eventually P sequentially"
   667 using assms by (auto simp: eventually_sequentially)
   805 using assms by (auto simp: eventually_sequentially)
   676    apply auto []
   814    apply auto []
   677   apply (rule_tac x=N in exI)
   815   apply (rule_tac x=N in exI)
   678   apply auto []
   816   apply auto []
   679   done
   817   done
   680 
   818 
   681 subsubsection {* Standard filters *}
       
   682 
       
   683 definition principal :: "'a set \<Rightarrow> 'a filter" where
       
   684   "principal S = Abs_filter (\<lambda>P. \<forall>x\<in>S. P x)"
       
   685 
       
   686 lemma eventually_principal: "eventually P (principal S) \<longleftrightarrow> (\<forall>x\<in>S. P x)"
       
   687   unfolding principal_def
       
   688   by (rule eventually_Abs_filter, rule is_filter.intro) auto
       
   689 
       
   690 lemma eventually_inf_principal: "eventually P (inf F (principal s)) \<longleftrightarrow> eventually (\<lambda>x. x \<in> s \<longrightarrow> P x) F"
       
   691   unfolding eventually_inf eventually_principal by (auto elim: eventually_elim1)
       
   692 
       
   693 lemma principal_UNIV[simp]: "principal UNIV = top"
       
   694   by (auto simp: filter_eq_iff eventually_principal)
       
   695 
       
   696 lemma principal_empty[simp]: "principal {} = bot"
       
   697   by (auto simp: filter_eq_iff eventually_principal)
       
   698 
       
   699 lemma principal_le_iff[iff]: "principal A \<le> principal B \<longleftrightarrow> A \<subseteq> B"
       
   700   by (auto simp: le_filter_def eventually_principal)
       
   701 
       
   702 lemma le_principal: "F \<le> principal A \<longleftrightarrow> eventually (\<lambda>x. x \<in> A) F"
       
   703   unfolding le_filter_def eventually_principal
       
   704   apply safe
       
   705   apply (erule_tac x="\<lambda>x. x \<in> A" in allE)
       
   706   apply (auto elim: eventually_elim1)
       
   707   done
       
   708 
       
   709 lemma principal_inject[iff]: "principal A = principal B \<longleftrightarrow> A = B"
       
   710   unfolding eq_iff by simp
       
   711 
       
   712 lemma sup_principal[simp]: "sup (principal A) (principal B) = principal (A \<union> B)"
       
   713   unfolding filter_eq_iff eventually_sup eventually_principal by auto
       
   714 
       
   715 lemma inf_principal[simp]: "inf (principal A) (principal B) = principal (A \<inter> B)"
       
   716   unfolding filter_eq_iff eventually_inf eventually_principal
       
   717   by (auto intro: exI[of _ "\<lambda>x. x \<in> A"] exI[of _ "\<lambda>x. x \<in> B"])
       
   718 
       
   719 lemma SUP_principal[simp]: "(SUP i : I. principal (A i)) = principal (\<Union>i\<in>I. A i)"
       
   720   unfolding filter_eq_iff eventually_Sup SUP_def by (auto simp: eventually_principal)
       
   721 
       
   722 lemma filtermap_principal[simp]: "filtermap f (principal A) = principal (f ` A)"
       
   723   unfolding filter_eq_iff eventually_filtermap eventually_principal by simp
       
   724 
       
   725 subsubsection {* Topological filters *}
   819 subsubsection {* Topological filters *}
   726 
   820 
   727 definition (in topological_space) nhds :: "'a \<Rightarrow> 'a filter"
   821 definition (in topological_space) nhds :: "'a \<Rightarrow> 'a filter"
   728   where "nhds a = Abs_filter (\<lambda>P. \<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x))"
   822   where "nhds a = (INF S:{S. open S \<and> a \<in> S}. principal S)"
   729 
   823 
   730 definition (in topological_space) at_within :: "'a \<Rightarrow> 'a set \<Rightarrow> 'a filter" ("at (_) within (_)" [1000, 60] 60)
   824 definition (in topological_space) at_within :: "'a \<Rightarrow> 'a set \<Rightarrow> 'a filter" ("at (_) within (_)" [1000, 60] 60)
   731   where "at a within s = inf (nhds a) (principal (s - {a}))"
   825   where "at a within s = inf (nhds a) (principal (s - {a}))"
   732 
   826 
   733 abbreviation (in topological_space) at :: "'a \<Rightarrow> 'a filter" ("at") where
   827 abbreviation (in topological_space) at :: "'a \<Rightarrow> 'a filter" ("at") where
   739 abbreviation (in order_topology) at_left :: "'a \<Rightarrow> 'a filter" where
   833 abbreviation (in order_topology) at_left :: "'a \<Rightarrow> 'a filter" where
   740   "at_left x \<equiv> at x within {..< x}"
   834   "at_left x \<equiv> at x within {..< x}"
   741 
   835 
   742 lemma (in topological_space) eventually_nhds:
   836 lemma (in topological_space) eventually_nhds:
   743   "eventually P (nhds a) \<longleftrightarrow> (\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x))"
   837   "eventually P (nhds a) \<longleftrightarrow> (\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x))"
   744   unfolding nhds_def
   838   unfolding nhds_def by (subst eventually_INF_base) (auto simp: eventually_principal)
   745 proof (rule eventually_Abs_filter, rule is_filter.intro)
       
   746   have "open UNIV \<and> a \<in> UNIV \<and> (\<forall>x\<in>UNIV. True)" by simp
       
   747   thus "\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. True)" ..
       
   748 next
       
   749   fix P Q
       
   750   assume "\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x)"
       
   751      and "\<exists>T. open T \<and> a \<in> T \<and> (\<forall>x\<in>T. Q x)"
       
   752   then obtain S T where
       
   753     "open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x)"
       
   754     "open T \<and> a \<in> T \<and> (\<forall>x\<in>T. Q x)" by auto
       
   755   hence "open (S \<inter> T) \<and> a \<in> S \<inter> T \<and> (\<forall>x\<in>(S \<inter> T). P x \<and> Q x)"
       
   756     by (simp add: open_Int)
       
   757   thus "\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x \<and> Q x)" ..
       
   758 qed auto
       
   759 
   839 
   760 lemma nhds_neq_bot [simp]: "nhds a \<noteq> bot"
   840 lemma nhds_neq_bot [simp]: "nhds a \<noteq> bot"
   761   unfolding trivial_limit_def eventually_nhds by simp
   841   unfolding trivial_limit_def eventually_nhds by simp
   762 
   842 
   763 lemma eventually_at_filter:
   843 lemma eventually_at_filter:
   891 
   971 
   892 lemma filterlim_inf:
   972 lemma filterlim_inf:
   893   "(LIM x F1. f x :> inf F2 F3) \<longleftrightarrow> ((LIM x F1. f x :> F2) \<and> (LIM x F1. f x :> F3))"
   973   "(LIM x F1. f x :> inf F2 F3) \<longleftrightarrow> ((LIM x F1. f x :> F2) \<and> (LIM x F1. f x :> F3))"
   894   unfolding filterlim_def by simp
   974   unfolding filterlim_def by simp
   895 
   975 
       
   976 lemma filterlim_INF:
       
   977   "(LIM x F. f x :> (INF b:B. G b)) \<longleftrightarrow> (\<forall>b\<in>B. LIM x F. f x :> G b)"
       
   978   unfolding filterlim_def le_INF_iff ..
       
   979 
   896 lemma filterlim_filtermap: "filterlim f F1 (filtermap g F2) = filterlim (\<lambda>x. f (g x)) F1 F2"
   980 lemma filterlim_filtermap: "filterlim f F1 (filtermap g F2) = filterlim (\<lambda>x. f (g x)) F1 F2"
   897   unfolding filterlim_def filtermap_filtermap ..
   981   unfolding filterlim_def filtermap_filtermap ..
   898 
   982 
   899 lemma filterlim_sup:
   983 lemma filterlim_sup:
   900   "filterlim f F F1 \<Longrightarrow> filterlim f F F2 \<Longrightarrow> filterlim f F (sup F1 F2)"
   984   "filterlim f F F1 \<Longrightarrow> filterlim f F F2 \<Longrightarrow> filterlim f F (sup F1 F2)"
   931     map_filter (try (fn thm => @{thm tendsto_eq_rhs} OF [thm])) o Tendsto_Intros.get o Context.proof_of);
  1015     map_filter (try (fn thm => @{thm tendsto_eq_rhs} OF [thm])) o Tendsto_Intros.get o Context.proof_of);
   932 *}
  1016 *}
   933 
  1017 
   934 lemma (in topological_space) tendsto_def:
  1018 lemma (in topological_space) tendsto_def:
   935    "(f ---> l) F \<longleftrightarrow> (\<forall>S. open S \<longrightarrow> l \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) F)"
  1019    "(f ---> l) F \<longleftrightarrow> (\<forall>S. open S \<longrightarrow> l \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) F)"
   936   unfolding filterlim_def
  1020    unfolding nhds_def filterlim_INF filterlim_principal by auto
   937 proof safe
       
   938   fix S assume "open S" "l \<in> S" "filtermap f F \<le> nhds l"
       
   939   then show "eventually (\<lambda>x. f x \<in> S) F"
       
   940     unfolding eventually_nhds eventually_filtermap le_filter_def
       
   941     by (auto elim!: allE[of _ "\<lambda>x. x \<in> S"] eventually_rev_mp)
       
   942 qed (auto elim!: eventually_rev_mp simp: eventually_nhds eventually_filtermap le_filter_def)
       
   943 
  1021 
   944 lemma tendsto_mono: "F \<le> F' \<Longrightarrow> (f ---> l) F' \<Longrightarrow> (f ---> l) F"
  1022 lemma tendsto_mono: "F \<le> F' \<Longrightarrow> (f ---> l) F' \<Longrightarrow> (f ---> l) F"
   945   unfolding tendsto_def le_filter_def by fast
  1023   unfolding tendsto_def le_filter_def by fast
   946 
  1024 
   947 lemma tendsto_within_subset: "(f ---> l) (at x within S) \<Longrightarrow> T \<subseteq> S \<Longrightarrow> (f ---> l) (at x within T)"
  1025 lemma tendsto_within_subset: "(f ---> l) (at x within S) \<Longrightarrow> T \<subseteq> S \<Longrightarrow> (f ---> l) (at x within T)"
  1118   shows "a \<ge> x"
  1196   shows "a \<ge> x"
  1119   by (rule tendsto_le [OF F tendsto_const x a])
  1197   by (rule tendsto_le [OF F tendsto_const x a])
  1120 
  1198 
  1121 subsubsection {* Rules about @{const Lim} *}
  1199 subsubsection {* Rules about @{const Lim} *}
  1122 
  1200 
  1123 lemma (in t2_space) tendsto_Lim:
  1201 lemma tendsto_Lim:
  1124   "\<not>(trivial_limit net) \<Longrightarrow> (f ---> l) net \<Longrightarrow> Lim net f = l"
  1202   "\<not>(trivial_limit net) \<Longrightarrow> (f ---> l) net \<Longrightarrow> Lim net f = l"
  1125   unfolding Lim_def using tendsto_unique[of net f] by auto
  1203   unfolding Lim_def using tendsto_unique[of net f] by auto
  1126 
  1204 
  1127 lemma Lim_ident_at: "\<not> trivial_limit (at x within s) \<Longrightarrow> Lim (at x within s) (\<lambda>x. x) = x"
  1205 lemma Lim_ident_at: "\<not> trivial_limit (at x within s) \<Longrightarrow> Lim (at x within s) (\<lambda>x. x) = x"
  1128   by (rule tendsto_Lim[OF _ tendsto_ident_at]) auto
  1206   by (rule tendsto_Lim[OF _ tendsto_ident_at]) auto
  1563 lemma convergent_subseq_convergent:
  1641 lemma convergent_subseq_convergent:
  1564   "\<lbrakk>convergent X; subseq f\<rbrakk> \<Longrightarrow> convergent (X o f)"
  1642   "\<lbrakk>convergent X; subseq f\<rbrakk> \<Longrightarrow> convergent (X o f)"
  1565   unfolding convergent_def by (auto intro: LIMSEQ_subseq_LIMSEQ)
  1643   unfolding convergent_def by (auto intro: LIMSEQ_subseq_LIMSEQ)
  1566 
  1644 
  1567 lemma limI: "X ----> L ==> lim X = L"
  1645 lemma limI: "X ----> L ==> lim X = L"
  1568 apply (simp add: lim_def)
  1646   by (rule tendsto_Lim) (rule trivial_limit_sequentially)
  1569 apply (blast intro: LIMSEQ_unique)
       
  1570 done
       
  1571 
  1647 
  1572 lemma lim_le: "convergent f \<Longrightarrow> (\<And>n. f n \<le> (x::'a::linorder_topology)) \<Longrightarrow> lim f \<le> x"
  1648 lemma lim_le: "convergent f \<Longrightarrow> (\<And>n. f n \<le> (x::'a::linorder_topology)) \<Longrightarrow> lim f \<le> x"
  1573   using LIMSEQ_le_const2[of f "lim f" x] by (simp add: convergent_LIMSEQ_iff)
  1649   using LIMSEQ_le_const2[of f "lim f" x] by (simp add: convergent_LIMSEQ_iff)
  1574 
  1650 
  1575 subsubsection{*Increasing and Decreasing Series*}
  1651 subsubsection{*Increasing and Decreasing Series*}
  1765   shows "eventually P (at_left a)"
  1841   shows "eventually P (at_left a)"
  1766 proof (safe intro!: sequentially_imp_eventually_within)
  1842 proof (safe intro!: sequentially_imp_eventually_within)
  1767   fix X assume X: "\<forall>n. X n \<in> {..<a} \<and> X n \<noteq> a" "X ----> a"
  1843   fix X assume X: "\<forall>n. X n \<in> {..<a} \<and> X n \<noteq> a" "X ----> a"
  1768   show "eventually (\<lambda>n. P (X n)) sequentially"
  1844   show "eventually (\<lambda>n. P (X n)) sequentially"
  1769   proof (rule ccontr)
  1845   proof (rule ccontr)
       
  1846 
  1770     assume "\<not> eventually (\<lambda>n. P (X n)) sequentially"
  1847     assume "\<not> eventually (\<lambda>n. P (X n)) sequentially"
  1771     from not_eventually_sequentiallyD[OF this]
  1848     from not_eventually_sequentiallyD[OF this]
  1772     obtain r where "subseq r" "\<And>n. \<not> P (X (r n))"
  1849     obtain r where "subseq r" "\<And>n. \<not> P (X (r n))"
  1773       by auto
  1850       by auto
  1774     with X have "(X \<circ> r) ----> a"
  1851     with X have "(X \<circ> r) ----> a"