src/HOL/Analysis/Elementary_Topology.thy
changeset 82522 62afd98e3f3e
parent 80914 d97fdabd9e2b
equal deleted inserted replaced
82521:819688d4cc45 82522:62afd98e3f3e
    52   (\<forall>b\<in>B. open b) \<and> (\<forall>x. open x \<longrightarrow> (\<exists>B'. B' \<subseteq> B \<and> \<Union>B' = x))"
    52   (\<forall>b\<in>B. open b) \<and> (\<forall>x. open x \<longrightarrow> (\<exists>B'. B' \<subseteq> B \<and> \<Union>B' = x))"
    53 
    53 
    54 lemma topological_basis:
    54 lemma topological_basis:
    55   "topological_basis B \<longleftrightarrow> (\<forall>x. open x \<longleftrightarrow> (\<exists>B'. B' \<subseteq> B \<and> \<Union>B' = x))"
    55   "topological_basis B \<longleftrightarrow> (\<forall>x. open x \<longleftrightarrow> (\<exists>B'. B' \<subseteq> B \<and> \<Union>B' = x))"
    56     (is "?lhs = ?rhs")
    56     (is "?lhs = ?rhs")
    57 proof
    57   by (metis bot.extremum cSup_singleton insert_subset open_Union subsetD
    58   show "?lhs \<Longrightarrow> ?rhs"
    58       topological_basis_def)
    59     by (meson local.open_Union subsetD topological_basis_def)
       
    60   show "?rhs \<Longrightarrow> ?lhs"
       
    61     unfolding topological_basis_def
       
    62     by (metis cSup_singleton empty_subsetI insert_subset)
       
    63 qed
       
    64 
    59 
    65 lemma topological_basis_iff:
    60 lemma topological_basis_iff:
    66   assumes "\<And>B'. B' \<in> B \<Longrightarrow> open B'"
    61   assumes "\<And>B'. B' \<in> B \<Longrightarrow> open B'"
    67   shows "topological_basis B \<longleftrightarrow> (\<forall>O'. open O' \<longrightarrow> (\<forall>x\<in>O'. \<exists>B'\<in>B. x \<in> B' \<and> B' \<subseteq> O'))"
    62   shows "topological_basis B \<longleftrightarrow> (\<forall>O'. open O' \<longrightarrow> (\<forall>x\<in>O'. \<exists>B'\<in>B. x \<in> B' \<and> B' \<subseteq> O'))"
    68     (is "_ \<longleftrightarrow> ?rhs")
    63     (is "_ \<longleftrightarrow> ?rhs")
    69 proof safe
    64 proof safe
    70   fix O' and x::'a
    65   fix O' and x::'a
    71   assume H: "topological_basis B" "open O'" "x \<in> O'"
    66   assume H: "topological_basis B" "open O'" "x \<in> O'"
    72   then have "(\<exists>B'\<subseteq>B. \<Union>B' = O')" by (simp add: topological_basis_def)
    67   then obtain B' where "B'\<subseteq>B" "\<Union>B' = O'"
    73   then obtain B' where "B' \<subseteq> B" "O' = \<Union>B'" by auto
    68     by (force simp add: topological_basis_def)
    74   then show "\<exists>B'\<in>B. x \<in> B' \<and> B' \<subseteq> O'" using H by auto
    69   then show "\<exists>B'\<in>B. x \<in> B' \<and> B' \<subseteq> O'" 
       
    70     using H by auto
    75 next
    71 next
    76   assume H: ?rhs
    72   assume H: ?rhs
    77   show "topological_basis B"
    73   show "topological_basis B"
    78     using assms unfolding topological_basis_def
    74     unfolding topological_basis_def
    79   proof safe
    75   proof (intro conjI strip assms)
    80     fix O' :: "'a set"
    76     fix O' :: "'a set"
    81     assume "open O'"
    77     assume "open O'"
    82     with H obtain f where "\<forall>x\<in>O'. f x \<in> B \<and> x \<in> f x \<and> f x \<subseteq> O'"
    78     with H obtain f where "\<forall>x\<in>O'. f x \<in> B \<and> x \<in> f x \<and> f x \<subseteq> O'"
    83       by (force intro: bchoice simp: Bex_def)
    79       by metis
    84     then show "\<exists>B'\<subseteq>B. \<Union>B' = O'"
    80     then show "\<exists>B'\<subseteq>B. \<Union>B' = O'"
    85       by (auto intro: exI[where x="{f x |x. x \<in> O'}"])
    81       by (auto intro: exI[where x="{f x |x. x \<in> O'}"])
    86   qed
    82   qed
    87 qed
    83 qed
    88 
    84 
   154     then have "(\<Union>(a, b)\<in>{x \<in> A \<times> B. fst x \<times> snd x \<subseteq> S}. a \<times> b) = S"
   150     then have "(\<Union>(a, b)\<in>{x \<in> A \<times> B. fst x \<times> snd x \<subseteq> S}. a \<times> b) = S"
   155       by force
   151       by force
   156     then show ?thesis
   152     then show ?thesis
   157       using subset_eq by force
   153       using subset_eq by force
   158   qed
   154   qed
   159   with A B show ?thesis
   155   with A B open_Times show ?thesis
   160     unfolding topological_basis_def
   156     unfolding topological_basis_def
   161     by (smt (verit) SigmaE imageE image_mono open_Times case_prod_conv)
   157     by (smt (verit) SigmaE imageE image_mono case_prod_conv)
   162 qed
   158 qed
   163 
   159 
   164 
   160 
   165 subsection \<open>Countable Basis\<close>
   161 subsection \<open>Countable Basis\<close>
   166 
   162 
   229     by (rule first_countable_basisE) blast
   225     by (rule first_countable_basisE) blast
   230   define \<A> where [abs_def]:
   226   define \<A> where [abs_def]:
   231     "\<A> = (\<lambda>N. \<Inter>((\<lambda>n. from_nat_into \<B> n) ` N)) ` (Collect finite::nat set set)"
   227     "\<A> = (\<lambda>N. \<Inter>((\<lambda>n. from_nat_into \<B> n) ` N)) ` (Collect finite::nat set set)"
   232   then show "\<exists>\<A>. countable \<A> \<and> (\<forall>A. A \<in> \<A> \<longrightarrow> x \<in> A) \<and> (\<forall>A. A \<in> \<A> \<longrightarrow> open A) \<and>
   228   then show "\<exists>\<A>. countable \<A> \<and> (\<forall>A. A \<in> \<A> \<longrightarrow> x \<in> A) \<and> (\<forall>A. A \<in> \<A> \<longrightarrow> open A) \<and>
   233         (\<forall>S. open S \<longrightarrow> x \<in> S \<longrightarrow> (\<exists>A\<in>\<A>. A \<subseteq> S)) \<and> (\<forall>A B. A \<in> \<A> \<longrightarrow> B \<in> \<A> \<longrightarrow> A \<inter> B \<in> \<A>)"
   229         (\<forall>S. open S \<longrightarrow> x \<in> S \<longrightarrow> (\<exists>A\<in>\<A>. A \<subseteq> S)) \<and> (\<forall>A B. A \<in> \<A> \<longrightarrow> B \<in> \<A> \<longrightarrow> A \<inter> B \<in> \<A>)"
   234   proof (safe intro!: exI[where x=\<A>])
   230   proof (intro exI conjI strip)
   235     show "countable \<A>"
   231     show "countable \<A>"
   236       unfolding \<A>_def by (intro countable_image countable_Collect_finite)
   232       unfolding \<A>_def by (intro countable_image countable_Collect_finite)
   237     fix A
   233     fix A
   238     assume "A \<in> \<A>"
   234     assume "A \<in> \<A>"
   239     then show "x \<in> A" "open A"
   235     then show "x \<in> A" "open A"
   264 lemma (in topological_space) first_countableI:
   260 lemma (in topological_space) first_countableI:
   265   assumes "countable \<A>"
   261   assumes "countable \<A>"
   266     and 1: "\<And>A. A \<in> \<A> \<Longrightarrow> x \<in> A" "\<And>A. A \<in> \<A> \<Longrightarrow> open A"
   262     and 1: "\<And>A. A \<in> \<A> \<Longrightarrow> x \<in> A" "\<And>A. A \<in> \<A> \<Longrightarrow> open A"
   267     and 2: "\<And>S. open S \<Longrightarrow> x \<in> S \<Longrightarrow> \<exists>A\<in>\<A>. A \<subseteq> S"
   263     and 2: "\<And>S. open S \<Longrightarrow> x \<in> S \<Longrightarrow> \<exists>A\<in>\<A>. A \<subseteq> S"
   268   shows "\<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))"
   264   shows "\<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))"
   269 proof (safe intro!: exI[of _ "from_nat_into \<A>"])
   265 proof (intro exI[of _ "from_nat_into _"] conjI strip)
   270   fix i
   266   fix i
   271   have "\<A> \<noteq> {}" using 2[of UNIV] by auto
   267   have "\<A> \<noteq> {}" using 2[of UNIV] by auto
   272   show "x \<in> from_nat_into \<A> i" "open (from_nat_into \<A> i)"
   268   show "x \<in> from_nat_into \<A> i" "open (from_nat_into \<A> i)"
   273     using range_from_nat_into_subset[OF \<open>\<A> \<noteq> {}\<close>] 1 by auto
   269     using range_from_nat_into_subset[OF \<open>\<A> \<noteq> {}\<close>] 1 by auto
   274 next
   270 next
   275   fix S
   271   fix S
   276   assume "open S" "x\<in>S" 
   272   assume "open S \<and> x\<in>S" 
   277   then show "\<exists>i. from_nat_into \<A> i \<subseteq> S"
   273   then show "\<exists>i. from_nat_into \<A> i \<subseteq> S"
   278     by (metis "2" \<open>countable \<A>\<close> from_nat_into_surj)
   274     by (metis "2" \<open>countable \<A>\<close> from_nat_into_surj)
   279 qed
   275 qed
   280 
   276 
   281 instance prod :: (first_countable_topology, first_countable_topology) first_countable_topology
   277 instance prod :: (first_countable_topology, first_countable_topology) first_countable_topology
   329 
   325 
   330   show ?thesis
   326   show ?thesis
   331   proof (intro exI conjI)
   327   proof (intro exI conjI)
   332     show "countable ?B"
   328     show "countable ?B"
   333       by (intro countable_image countable_Collect_finite_subset B)
   329       by (intro countable_image countable_Collect_finite_subset B)
   334     {
   330     have "\<exists>B'\<subseteq>Inter ` {b. finite b \<and> b \<subseteq> B}. \<Union>B' = S" if "open S" for S
   335       fix S
   331     proof -
   336       assume "open S"
   332       have "\<exists>B'\<subseteq>{b. finite b \<and> b \<subseteq> B}. (\<Union>b\<in>B'. \<Inter>b) = S"
   337       then have "\<exists>B'\<subseteq>{b. finite b \<and> b \<subseteq> B}. (\<Union>b\<in>B'. \<Inter>b) = S"
   333         using that unfolding B 
   338         unfolding B
       
   339       proof induct
   334       proof induct
   340         case UNIV
   335         case UNIV
   341         show ?case by (intro exI[of _ "{{}}"]) simp
   336         show ?case by (intro exI[of _ "{{}}"]) simp
   342       next
   337       next
   343         case (Int a b)
   338         case (Int a b)
   358       next
   353       next
   359         case (Basis S)
   354         case (Basis S)
   360         then show ?case
   355         then show ?case
   361           by (intro exI[of _ "{{S}}"]) auto
   356           by (intro exI[of _ "{{S}}"]) auto
   362       qed
   357       qed
   363       then have "(\<exists>B'\<subseteq>Inter ` {b. finite b \<and> b \<subseteq> B}. \<Union>B' = S)"
   358       then show ?thesis
   364         unfolding subset_image_iff by blast }
   359         unfolding subset_image_iff by blast 
       
   360     qed
   365     then show "topological_basis ?B"
   361     then show "topological_basis ?B"
   366       unfolding topological_basis_def
   362       unfolding topological_basis_def
   367       by (safe intro!: open_Inter)
   363       by (safe intro!: open_Inter) (simp_all add: B generate_topology.Basis subset_eq)
   368          (simp_all add: B generate_topology.Basis subset_eq)
       
   369   qed
   364   qed
   370 qed
   365 qed
   371 
   366 
   372 
   367 
   373 end
   368 end
   392     by (simp add: \<D>_def \<open>countable \<B>\<close>)
   387     by (simp add: \<D>_def \<open>countable \<B>\<close>)
   393   have "\<And>S. \<exists>U. S \<in> \<D> \<longrightarrow> U \<in> \<F> \<and> S \<subseteq> U"
   388   have "\<And>S. \<exists>U. S \<in> \<D> \<longrightarrow> U \<in> \<F> \<and> S \<subseteq> U"
   394     by (simp add: \<D>_def)
   389     by (simp add: \<D>_def)
   395   then obtain G where G: "\<And>S. S \<in> \<D> \<longrightarrow> G S \<in> \<F> \<and> S \<subseteq> G S"
   390   then obtain G where G: "\<And>S. S \<in> \<D> \<longrightarrow> G S \<in> \<F> \<and> S \<subseteq> G S"
   396     by metis
   391     by metis
   397   have "\<Union>\<F> \<subseteq> \<Union>\<D>"
   392   have eq1: "\<Union>\<F> = \<Union>\<D>"
   398     unfolding \<D>_def by (blast dest: \<F> \<B>)
   393     unfolding \<D>_def by (blast dest: \<F> \<B>)
   399   moreover have "\<Union>\<D> \<subseteq> \<Union>\<F>"
   394   also have "\<dots> = \<Union> (G ` \<D>)"
   400     using \<D>_def by blast
       
   401   ultimately have eq1: "\<Union>\<F> = \<Union>\<D>" ..
       
   402   moreover have "\<Union>\<D> = \<Union> (G ` \<D>)"
       
   403     using G eq1 by auto
   395     using G eq1 by auto
   404   ultimately show ?thesis
   396   finally show ?thesis
   405     by (metis G \<open>countable \<D>\<close> countable_image image_subset_iff that)
   397     by (metis G \<open>countable \<D>\<close> countable_image image_subset_iff that)
   406 qed
   398 qed
   407 
   399 
   408 lemma countable_disjoint_open_subsets:
   400 lemma countable_disjoint_open_subsets:
   409   fixes \<F> :: "'a::second_countable_topology set set"
   401   fixes \<F> :: "'a::second_countable_topology set set"
   462   define B1 where "B1 = {(LEAST x. x \<in> U)| U. U \<in> A}"
   454   define B1 where "B1 = {(LEAST x. x \<in> U)| U. U \<in> A}"
   463   then have "countable B1" using \<open>countable A\<close> by (simp add: Setcompr_eq_image)
   455   then have "countable B1" using \<open>countable A\<close> by (simp add: Setcompr_eq_image)
   464   define B2 where "B2 = {(SOME x. x \<in> U)| U. U \<in> A}"
   456   define B2 where "B2 = {(SOME x. x \<in> U)| U. U \<in> A}"
   465   then have "countable B2" using \<open>countable A\<close> by (simp add: Setcompr_eq_image)
   457   then have "countable B2" using \<open>countable A\<close> by (simp add: Setcompr_eq_image)
   466   have "\<exists>b \<in> B1 \<union> B2. x < b \<and> b \<le> y" if "x < y" for x y
   458   have "\<exists>b \<in> B1 \<union> B2. x < b \<and> b \<le> y" if "x < y" for x y
   467   proof (cases)
   459   proof (cases "\<exists>z. x < z \<and> z < y")
   468     assume "\<exists>z. x < z \<and> z < y"
   460     case True
   469     then obtain z where z: "x < z \<and> z < y" by auto
   461     then obtain z where z: "x < z \<and> z < y" by auto
   470     define U where "U = {x<..<y}"
   462     define U where "U = {x<..<y}"
   471     then have "open U" by simp
   463     then have "open U" by simp
   472     moreover have "z \<in> U" using z U_def by simp
   464     then obtain V where "V \<in> A" "z \<in> V" "V \<subseteq> U" 
   473     ultimately obtain V where "V \<in> A" "z \<in> V" "V \<subseteq> U" 
   465       using topological_basisE[OF \<open>topological_basis A\<close>]
   474       using topological_basisE[OF \<open>topological_basis A\<close>] by auto
   466       by (metis U_def greaterThanLessThan_iff z)
   475     define w where "w = (SOME x. x \<in> V)"
   467     define w where "w = (SOME x. x \<in> V)"
   476     then have "w \<in> V" using \<open>z \<in> V\<close> by (metis someI2)
   468     then have "w \<in> V" using \<open>z \<in> V\<close> by (metis someI2)
   477     then have "x < w \<and> w \<le> y" using \<open>w \<in> V\<close> \<open>V \<subseteq> U\<close> U_def by fastforce
   469     with \<open>V \<in> A\<close> \<open>V \<subseteq> U\<close> show ?thesis
   478     moreover have "w \<in> B1 \<union> B2" using w_def B2_def \<open>V \<in> A\<close> by auto
   470       by (force simp: B2_def U_def w_def)
   479     ultimately show ?thesis by auto
       
   480   next
   471   next
   481     assume "\<not>(\<exists>z. x < z \<and> z < y)"
   472     case False
   482     then have *: "\<And>z. z > x \<Longrightarrow> z \<ge> y" by auto
   473     then have *: "\<And>z. z > x \<Longrightarrow> z \<ge> y" by auto
   483     define U where "U = {x<..}"
   474     define U where "U = {x<..}"
   484     then have "open U" by simp
   475     then have "open U" by simp
   485     moreover have "y \<in> U" using \<open>x < y\<close> U_def by simp
   476     then obtain "V" where "V \<in> A" "y \<in> V" "V \<subseteq> U" 
   486     ultimately obtain "V" where "V \<in> A" "y \<in> V" "V \<subseteq> U" 
   477       using topological_basisE[OF \<open>topological_basis A\<close>] U_def \<open>x < y\<close> by blast
   487       using topological_basisE[OF \<open>topological_basis A\<close>] by auto
       
   488     have "U = {y..}" unfolding U_def using * \<open>x < y\<close> by auto
   478     have "U = {y..}" unfolding U_def using * \<open>x < y\<close> by auto
   489     then have "V \<subseteq> {y..}" using \<open>V \<subseteq> U\<close> by simp
   479     then have "V \<subseteq> {y..}" using \<open>V \<subseteq> U\<close> by simp
   490     then have "(LEAST w. w \<in> V) = y" using \<open>y \<in> V\<close> by (meson Least_equality atLeast_iff subsetCE)
   480     then have "(LEAST w. w \<in> V) = y" using \<open>y \<in> V\<close> by (meson Least_equality atLeast_iff subsetCE)
   491     then have "y \<in> B1 \<union> B2" using \<open>V \<in> A\<close> B1_def by auto
   481     then show ?thesis
   492     moreover have "x < y \<and> y \<le> y" using \<open>x < y\<close> by simp
   482       using B1_def \<open>V \<in> A\<close> that by blast
   493     ultimately show ?thesis by auto
       
   494   qed
   483   qed
   495   moreover have "countable (B1 \<union> B2)" using \<open>countable B1\<close> \<open>countable B2\<close> by simp
   484   moreover have "countable (B1 \<union> B2)" using \<open>countable B1\<close> \<open>countable B2\<close> by simp
   496   ultimately show ?thesis by auto
   485   ultimately show ?thesis by auto
   497 qed
   486 qed
   498 
   487 
   503   define B1 where "B1 = {(GREATEST x. x \<in> U) | U. U \<in> A}"
   492   define B1 where "B1 = {(GREATEST x. x \<in> U) | U. U \<in> A}"
   504   then have "countable B1" using \<open>countable A\<close> by (simp add: Setcompr_eq_image)
   493   then have "countable B1" using \<open>countable A\<close> by (simp add: Setcompr_eq_image)
   505   define B2 where "B2 = {(SOME x. x \<in> U)| U. U \<in> A}"
   494   define B2 where "B2 = {(SOME x. x \<in> U)| U. U \<in> A}"
   506   then have "countable B2" using \<open>countable A\<close> by (simp add: Setcompr_eq_image)
   495   then have "countable B2" using \<open>countable A\<close> by (simp add: Setcompr_eq_image)
   507   have "\<exists>b \<in> B1 \<union> B2. x \<le> b \<and> b < y" if "x < y" for x y
   496   have "\<exists>b \<in> B1 \<union> B2. x \<le> b \<and> b < y" if "x < y" for x y
   508   proof (cases)
   497   proof (cases "\<exists>z. x < z \<and> z < y")
   509     assume "\<exists>z. x < z \<and> z < y"
   498     case True
   510     then obtain z where z: "x < z \<and> z < y" by auto
   499     then obtain z where z: "x < z \<and> z < y" by auto
   511     define U where "U = {x<..<y}"
   500     define U where "U = {x<..<y}"
   512     then have "open U" by simp
   501     then have "open U" by simp
   513     moreover have "z \<in> U" using z U_def by simp
   502     then obtain "V" where "V \<in> A" "z \<in> V" "V \<subseteq> U" 
   514     ultimately obtain "V" where "V \<in> A" "z \<in> V" "V \<subseteq> U" 
   503       using topological_basisE[OF \<open>topological_basis A\<close>]
   515       using topological_basisE[OF \<open>topological_basis A\<close>] by auto
   504       by (metis U_def greaterThanLessThan_iff z)
   516     define w where "w = (SOME x. x \<in> V)"
   505     define w where "w = (SOME x. x \<in> V)"
   517     then have "w \<in> V" using \<open>z \<in> V\<close> by (metis someI2)
   506     then have "w \<in> V" 
   518     then have "x \<le> w \<and> w < y" using \<open>w \<in> V\<close> \<open>V \<subseteq> U\<close> U_def by fastforce
   507       using \<open>z \<in> V\<close> by (metis someI2)
   519     moreover have "w \<in> B1 \<union> B2" using w_def B2_def \<open>V \<in> A\<close> by auto
   508     then have "x \<le> w \<and> w < y" 
   520     ultimately show ?thesis by auto
   509       using \<open>w \<in> V\<close> \<open>V \<subseteq> U\<close> U_def by fastforce
       
   510     then show ?thesis
       
   511       using B2_def \<open>V \<in> A\<close> w_def by blast
   521   next
   512   next
   522     assume "\<not>(\<exists>z. x < z \<and> z < y)"
   513     case False
   523     then have *: "\<And>z. z < y \<Longrightarrow> z \<le> x" using leI by blast
   514     then have *: "\<And>z. z < y \<Longrightarrow> z \<le> x" using leI by blast
   524     define U where "U = {..<y}"
   515     define U where "U = {..<y}"
   525     then have "open U" by simp
   516     then have "open U" by simp
   526     moreover have "x \<in> U" using \<open>x < y\<close> U_def by simp
   517     then obtain "V" where "V \<in> A" "x \<in> V" "V \<subseteq> U" 
   527     ultimately obtain "V" where "V \<in> A" "x \<in> V" "V \<subseteq> U" 
   518       using topological_basisE[OF \<open>topological_basis A\<close>] U_def \<open>x < y\<close> by blast
   528       using topological_basisE[OF \<open>topological_basis A\<close>] by auto
       
   529     have "U = {..x}" unfolding U_def using * \<open>x < y\<close> by auto
   519     have "U = {..x}" unfolding U_def using * \<open>x < y\<close> by auto
   530     then have "V \<subseteq> {..x}" using \<open>V \<subseteq> U\<close> by simp
   520     then have "V \<subseteq> {..x}" 
   531     then have "(GREATEST x. x \<in> V) = x" using \<open>x \<in> V\<close> by (meson Greatest_equality atMost_iff subsetCE)
   521       using \<open>V \<subseteq> U\<close> by simp
   532     then have "x \<in> B1 \<union> B2" using \<open>V \<in> A\<close> B1_def by auto
   522     then have "(GREATEST x. x \<in> V) = x" 
   533     moreover have "x \<le> x \<and> x < y" using \<open>x < y\<close> by simp
   523       using \<open>x \<in> V\<close> by (meson Greatest_equality atMost_iff subsetCE)
   534     ultimately show ?thesis by auto
   524     then show ?thesis
       
   525       using B1_def \<open>V \<in> A\<close> that by blast
   535   qed
   526   qed
   536   moreover have "countable (B1 \<union> B2)" using \<open>countable B1\<close> \<open>countable B2\<close> by simp
   527   moreover have "countable (B1 \<union> B2)" using \<open>countable B1\<close> \<open>countable B2\<close> by simp
   537   ultimately show ?thesis by auto
   528   ultimately show ?thesis by auto
   538 qed
   529 qed
   539 
   530 
   544     using countable_separating_set_linorder1 by auto
   535     using countable_separating_set_linorder1 by auto
   545   have "\<exists>b \<in> B. x < b \<and> b < y" if "x < y" for x y
   536   have "\<exists>b \<in> B. x < b \<and> b < y" if "x < y" for x y
   546   proof -
   537   proof -
   547     obtain z where "x < z" "z < y" using \<open>x < y\<close> dense by blast
   538     obtain z where "x < z" "z < y" using \<open>x < y\<close> dense by blast
   548     then obtain b where "b \<in> B" "x < b \<and> b \<le> z" using B(2) by auto
   539     then obtain b where "b \<in> B" "x < b \<and> b \<le> z" using B(2) by auto
   549     then have "x < b \<and> b < y" using \<open>z < y\<close> by auto
   540     then show ?thesis
   550     then show ?thesis using \<open>b \<in> B\<close> by auto
   541       using \<open>z < y\<close> by auto
   551   qed
   542   qed
   552   then show ?thesis using B(1) by auto
   543   then show ?thesis using B(1) by auto
   553 qed
   544 qed
   554 
   545 
   555 
   546 
   684     fix S
   675     fix S
   685     assume "open S" "l \<in> S"
   676     assume "open S" "l \<in> S"
   686     with A(3) have "eventually (\<lambda>i. A i \<subseteq> S) sequentially"
   677     with A(3) have "eventually (\<lambda>i. A i \<subseteq> S) sequentially"
   687       by auto
   678       by auto
   688     moreover
   679     moreover
   689     {
   680     have "eventually (\<lambda>i. f (r i) \<in> A i) sequentially"
   690       fix i
   681     proof
   691       assume "Suc 0 \<le> i"
   682       fix i assume "Suc 0 \<le> i" then show "f (r i) \<in> A i"
   692       then have "f (r i) \<in> A i"
       
   693         by (cases i) (simp_all add: r_def s)
   683         by (cases i) (simp_all add: r_def s)
   694     }
   684     qed
   695     then have "eventually (\<lambda>i. f (r i) \<in> A i) sequentially"
       
   696       by (auto simp: eventually_sequentially)
       
   697     ultimately show "eventually (\<lambda>i. f (r i) \<in> S) sequentially"
   685     ultimately show "eventually (\<lambda>i. f (r i) \<in> S) sequentially"
   698       by eventually_elim auto
   686       by eventually_elim auto
   699   qed
   687   qed
   700   ultimately show "\<exists>r::nat\<Rightarrow>nat. strict_mono r \<and> (f \<circ> r) \<longlonglongrightarrow> l"
   688   ultimately show "\<exists>r::nat\<Rightarrow>nat. strict_mono r \<and> (f \<circ> r) \<longlonglongrightarrow> l"
   701     by (auto simp: convergent_def comp_def)
   689     by (auto simp: convergent_def comp_def)
   708   using l unfolding islimpt_eq_acc_point
   696   using l unfolding islimpt_eq_acc_point
   709   by (rule acc_point_range_imp_convergent_subsequence)
   697   by (rule acc_point_range_imp_convergent_subsequence)
   710 
   698 
   711 lemma sequence_unique_limpt:
   699 lemma sequence_unique_limpt:
   712   fixes f :: "nat \<Rightarrow> 'a::t2_space"
   700   fixes f :: "nat \<Rightarrow> 'a::t2_space"
   713   assumes f: "(f \<longlongrightarrow> l) sequentially"
   701   assumes f: "(f \<longlongrightarrow> l) sequentially" and l': "l' islimpt (range f)"
   714     and "l' islimpt (range f)"
       
   715   shows "l' = l"
   702   shows "l' = l"
   716 proof (rule ccontr)
   703 proof (rule ccontr)
   717   assume "l' \<noteq> l"
   704   assume "l' \<noteq> l"
   718   obtain s t where "open s" "open t" "l' \<in> s" "l \<in> t" "s \<inter> t = {}"
   705   obtain s t where "open s" "open t" "l' \<in> s" "l \<in> t" "s \<inter> t = {}"
   719     using hausdorff [OF \<open>l' \<noteq> l\<close>] by auto
   706     using hausdorff [OF \<open>l' \<noteq> l\<close>] by auto
   720   then obtain N where "\<forall>n\<ge>N. f n \<in> t"
   707   then obtain N where "\<forall>n\<ge>N. f n \<in> t"
   721     by (meson f lim_explicit)
   708     by (meson f lim_explicit)
   722 
   709 
   723   have "UNIV = {..<N} \<union> {N..}"
   710   have "UNIV = {..<N} \<union> {N..}"
   724     by auto
   711     by auto
   725   then have "l' islimpt (f ` ({..<N} \<union> {N..}))"
       
   726     using assms(2) by simp
       
   727   then have "l' islimpt (f ` {..<N} \<union> f ` {N..})"
   712   then have "l' islimpt (f ` {..<N} \<union> f ` {N..})"
   728     by (simp add: image_Un)
   713     by (metis l' image_Un)
   729   then have "l' islimpt (f ` {N..})"
   714   then have "l' islimpt (f ` {N..})"
   730     by (simp add: islimpt_Un_finite)
   715     by (simp add: islimpt_Un_finite)
   731   then obtain y where "y \<in> f ` {N..}" "y \<in> s" "y \<noteq> l'"
   716   then obtain y where "y \<in> f ` {N..}" "y \<in> s" "y \<noteq> l'"
   732     using \<open>l' \<in> s\<close> \<open>open s\<close> by (rule islimptE)
   717     using \<open>l' \<in> s\<close> \<open>open s\<close> by (rule islimptE)
   733   then obtain n where "N \<le> n" "f n \<in> s" "f n \<noteq> l'"
       
   734     by auto
       
   735   with \<open>\<forall>n\<ge>N. f n \<in> t\<close> \<open>s \<inter> t = {}\<close> show False
   718   with \<open>\<forall>n\<ge>N. f n \<in> t\<close> \<open>s \<inter> t = {}\<close> show False
   736     by blast
   719     by blast
   737 qed
   720 qed
   738 
   721 
   739 (*could prove directly from islimpt_sequential_inj, but only for metric spaces*)
   722 (*could prove directly from islimpt_sequential_inj, but only for metric spaces*)
   804 qed
   787 qed
   805 
   788 
   806 lemma islimpt_image:
   789 lemma islimpt_image:
   807   assumes "z islimpt g -` A \<inter> B" "g z \<notin> A" "z \<in> B" "continuous_on B g"
   790   assumes "z islimpt g -` A \<inter> B" "g z \<notin> A" "z \<in> B" "continuous_on B g"
   808   shows   "g z islimpt A"
   791   shows   "g z islimpt A"
   809   by (smt (verit, best) IntD1 assms continuous_on_topological inf_le2 islimpt_def subset_eq vimageE)
   792   using assms
       
   793   by (simp add: islimpt_def vimage_def continuous_on_topological Bex_def) metis
   810   
   794   
   811 
   795 
   812 subsection \<open>Interior of a Set\<close>
   796 subsection \<open>Interior of a Set\<close>
   813 
   797 
   814 definition\<^marker>\<open>tag important\<close> interior :: "('a::topological_space) set \<Rightarrow> 'a set" where
   798 definition\<^marker>\<open>tag important\<close> interior :: "('a::topological_space) set \<Rightarrow> 'a set" where
   863 lemma interior_singleton [simp]: "interior {a} = {}"
   847 lemma interior_singleton [simp]: "interior {a} = {}"
   864   for a :: "'a::perfect_space"
   848   for a :: "'a::perfect_space"
   865   by (meson interior_eq interior_subset not_open_singleton subset_singletonD)
   849   by (meson interior_eq interior_subset not_open_singleton subset_singletonD)
   866 
   850 
   867 lemma interior_Int [simp]: "interior (S \<inter> T) = interior S \<inter> interior T"
   851 lemma interior_Int [simp]: "interior (S \<inter> T) = interior S \<inter> interior T"
   868   by (meson Int_mono Int_subset_iff antisym_conv interior_maximal interior_subset open_Int open_interior)
   852 proof
       
   853   show "interior S \<inter> interior T \<subseteq> interior (S \<inter> T)"
       
   854     by (meson Int_mono interior_subset open_Int open_interior open_subset_interior)
       
   855 qed (simp add: interior_mono)
   869 
   856 
   870 lemma eventually_nhds_in_nhd: "x \<in> interior s \<Longrightarrow> eventually (\<lambda>y. y \<in> s) (nhds x)"
   857 lemma eventually_nhds_in_nhd: "x \<in> interior s \<Longrightarrow> eventually (\<lambda>y. y \<in> s) (nhds x)"
   871   using interior_subset[of s] by (subst eventually_nhds) blast
   858   using interior_subset[of s] by (subst eventually_nhds) blast
   872 
   859 
   873 lemma interior_limit_point [intro]:
   860 lemma interior_limit_point [intro]:
   911     by (rule interior_mono) (rule Un_upper1)
   898     by (rule interior_mono) (rule Un_upper1)
   912   show "interior (S \<union> T) \<subseteq> interior S"
   899   show "interior (S \<union> T) \<subseteq> interior S"
   913   proof
   900   proof
   914     fix x
   901     fix x
   915     assume "x \<in> interior (S \<union> T)"
   902     assume "x \<in> interior (S \<union> T)"
   916     then obtain R where "open R" "x \<in> R" "R \<subseteq> S \<union> T" ..
   903     then obtain R where R: "open R" "x \<in> R" "R \<subseteq> S \<union> T" ..
   917     show "x \<in> interior S"
   904     show "x \<in> interior S"
   918     proof (rule ccontr)
   905     proof (rule ccontr)
   919       assume "x \<notin> interior S"
   906       assume "x \<notin> interior S"
   920       with \<open>x \<in> R\<close> \<open>open R\<close> obtain y where "y \<in> R - S"
   907       with \<open>x \<in> R\<close> \<open>open R\<close> obtain y where "y \<in> R - S"
   921         unfolding interior_def by fast
   908         unfolding interior_def by fast
   922       then show False
   909       with R show False
   923         by (metis Diff_subset_conv \<open>R \<subseteq> S \<union> T\<close> \<open>open R\<close> cS empty_iff iT interiorI open_Diff)
   910         by (metis Diff_subset_conv cS empty_iff iT interiorI open_Diff)
   924     qed
   911     qed
   925   qed
   912   qed
   926 qed
   913 qed
   927 
   914 
   928 lemma interior_Times: "interior (A \<times> B) = interior A \<times> interior B"
   915 lemma interior_Times: "interior (A \<times> B) = interior A \<times> interior B"
   994   have "disjoint (interior ` \<F>)"
   981   have "disjoint (interior ` \<F>)"
   995     using pw by (simp add: disjoint_image_subset interior_subset)
   982     using pw by (simp add: disjoint_image_subset interior_subset)
   996   then show "countable (interior ` \<F>)"
   983   then show "countable (interior ` \<F>)"
   997     by (auto intro: countable_disjoint_open_subsets)
   984     by (auto intro: countable_disjoint_open_subsets)
   998   show "inj_on interior \<F>"
   985   show "inj_on interior \<F>"
   999     using pw apply (clarsimp simp: inj_on_def pairwise_def)
   986     using pw
  1000     apply (metis disjnt_def disjnt_subset1 inf.orderE int interior_subset)
   987     unfolding inj_on_def pairwise_def disjnt_def
  1001     done
   988     by (metis inf.idem int interior_Int interior_empty)
  1002 qed
   989 qed
  1003 
   990 
  1004 subsection \<open>Closure of a Set\<close>
   991 subsection \<open>Closure of a Set\<close>
  1005 
   992 
  1006 definition\<^marker>\<open>tag important\<close> closure :: "('a::topological_space) set \<Rightarrow> 'a set" where
   993 definition\<^marker>\<open>tag important\<close> closure :: "('a::topological_space) set \<Rightarrow> 'a set" where
  1087   show "A \<times> B \<subseteq> closure A \<times> closure B"
  1074   show "A \<times> B \<subseteq> closure A \<times> closure B"
  1088     by (intro Sigma_mono closure_subset)
  1075     by (intro Sigma_mono closure_subset)
  1089   show "closed (closure A \<times> closure B)"
  1076   show "closed (closure A \<times> closure B)"
  1090     by (intro closed_Times closed_closure)
  1077     by (intro closed_Times closed_closure)
  1091   fix T
  1078   fix T
  1092   assume "A \<times> B \<subseteq> T" and "closed T"
  1079   assume T: "A \<times> B \<subseteq> T" "closed T"
       
  1080   have False
       
  1081     if ab: "a \<in> closure A" "b \<in> closure B" and "(a, b) \<notin> T" for a b
       
  1082   proof -
       
  1083     obtain C D where "open C" "open D" "C \<times> D \<subseteq> - T" "a \<in> C" "b \<in> D"
       
  1084       by (metis ComplI SigmaE2 \<open>closed T\<close> \<open>(a, b) \<notin> T\<close> open_Compl open_prod_elim)
       
  1085     then obtain "\<not> C \<subseteq> - A" "\<not> D \<subseteq> - B"
       
  1086       by (meson ab disjoint_iff inf_shunt open_Int_closure_eq_empty)
       
  1087     then show False
       
  1088       using T \<open>C \<times> D \<subseteq> - T\<close> by auto
       
  1089   qed
  1093   then show "closure A \<times> closure B \<subseteq> T"
  1090   then show "closure A \<times> closure B \<subseteq> T"
  1094     apply (simp add: closed_def open_prod_def, clarify)
  1091     by blast
  1095     apply (rule ccontr)
       
  1096     apply (drule_tac x="(a, b)" in bspec, simp, clarify, rename_tac C D)
       
  1097     apply (simp add: closure_interior interior_def)
       
  1098     apply (drule_tac x=C in spec)
       
  1099     apply (drule_tac x=D in spec, auto)
       
  1100     done
       
  1101 qed
  1092 qed
  1102 
  1093 
  1103 lemma closure_open_Int_superset:
  1094 lemma closure_open_Int_superset:
  1104   assumes "open S" "S \<subseteq> closure T"
  1095   assumes "open S" "S \<subseteq> closure T"
  1105   shows "closure(S \<inter> T) = closure S"
  1096   shows "closure(S \<inter> T) = closure S"
  1106   by (metis Int_Un_distrib Un_Int_eq(4) assms closure_Un closure_closure open_Int_closure_subset sup.orderE)
  1097 proof
       
  1098   show "closure S \<subseteq> closure (S \<inter> T)"
       
  1099     by (metis assms closed_closure closure_minimal inf.absorb_iff1 open_Int_closure_subset)
       
  1100 qed (simp add: closure_mono)
  1107 
  1101 
  1108 lemma closure_Int: "closure (\<Inter>I) \<subseteq> \<Inter>{closure S |S. S \<in> I}"
  1102 lemma closure_Int: "closure (\<Inter>I) \<subseteq> \<Inter>{closure S |S. S \<in> I}"
  1109   by (simp add: INF_greatest Inter_lower Setcompr_eq_image closure_mono)
  1103   by (simp add: INF_greatest Inter_lower Setcompr_eq_image closure_mono)
  1110 
  1104 
  1111 lemma islimpt_in_closure: "(x islimpt S) = (x\<in>closure(S-{x}))"
  1105 lemma islimpt_in_closure: "(x islimpt S) = (x\<in>closure(S-{x}))"
  1152   by (auto simp: frontier_Int)
  1146   by (auto simp: frontier_Int)
  1153 
  1147 
  1154 lemma frontier_Int_closed:
  1148 lemma frontier_Int_closed:
  1155   assumes "closed S" "closed T"
  1149   assumes "closed S" "closed T"
  1156   shows "frontier(S \<inter> T) = (frontier S \<inter> T) \<union> (S \<inter> frontier T)"
  1150   shows "frontier(S \<inter> T) = (frontier S \<inter> T) \<union> (S \<inter> frontier T)"
  1157   by (smt (verit, best) Diff_Int Int_Diff assms closed_Int closure_eq frontier_def inf_commute interior_Int)
  1151   by (simp add: Int_Un_distrib assms closed_Int frontier_closures inf_commute inf_left_commute)
  1158 
  1152 
  1159 lemma frontier_subset_closed: "closed S \<Longrightarrow> frontier S \<subseteq> S"
  1153 lemma frontier_subset_closed: "closed S \<Longrightarrow> frontier S \<subseteq> S"
  1160   by (metis frontier_def closure_closed Diff_subset)
  1154   by (metis frontier_def closure_closed Diff_subset)
  1161 
  1155 
  1162 lemma frontier_empty [simp]: "frontier {} = {}"
  1156 lemma frontier_empty [simp]: "frontier {} = {}"
  1207   using islimpt_in_closure by (metis trivial_limit_within)
  1201   using islimpt_in_closure by (metis trivial_limit_within)
  1208 
  1202 
  1209 lemma not_in_closure_trivial_limitI:
  1203 lemma not_in_closure_trivial_limitI:
  1210   "x \<notin> closure S \<Longrightarrow> trivial_limit (at x within S)"
  1204   "x \<notin> closure S \<Longrightarrow> trivial_limit (at x within S)"
  1211   using not_trivial_limit_within[of x S]
  1205   using not_trivial_limit_within[of x S]
  1212   by safe (metis Diff_empty Diff_insert0 closure_subset contra_subsetD)
  1206   by (metis Diff_empty Diff_insert0 closure_subset subsetD)
  1213 
  1207 
  1214 lemma filterlim_at_within_closure_implies_filterlim: "filterlim f l (at x within S)"
  1208 lemma filterlim_at_within_closure_implies_filterlim: "filterlim f l (at x within S)"
  1215   if "x \<in> closure S \<Longrightarrow> filterlim f l (at x within S)"
  1209   if "x \<in> closure S \<Longrightarrow> filterlim f l (at x within S)"
  1216   by (metis bot.extremum filterlim_iff_le_filtercomap not_in_closure_trivial_limitI that)
  1210   by (metis bot.extremum filterlim_iff_le_filtercomap not_in_closure_trivial_limitI that)
  1217 
  1211 
  1320 text\<open>Useful lemmas on closure and set of possible sequential limits.\<close>
  1314 text\<open>Useful lemmas on closure and set of possible sequential limits.\<close>
  1321 
  1315 
  1322 lemma closure_sequential:
  1316 lemma closure_sequential:
  1323   fixes l :: "'a::first_countable_topology"
  1317   fixes l :: "'a::first_countable_topology"
  1324   shows "l \<in> closure S \<longleftrightarrow> (\<exists>x. (\<forall>n. x n \<in> S) \<and> (x \<longlongrightarrow> l) sequentially)"
  1318   shows "l \<in> closure S \<longleftrightarrow> (\<exists>x. (\<forall>n. x n \<in> S) \<and> (x \<longlongrightarrow> l) sequentially)"
  1325   by (metis Diff_empty Diff_insert0 Un_iff closure_def islimpt_sequential mem_Collect_eq tendsto_const)
  1319   by (auto simp: closure_def islimpt_sequential)
  1326 
  1320 
  1327 lemma closed_sequential_limits:
  1321 lemma closed_sequential_limits:
  1328   fixes S :: "'a::first_countable_topology set"
  1322   fixes S :: "'a::first_countable_topology set"
  1329   shows "closed S \<longleftrightarrow> (\<forall>x l. (\<forall>n. x n \<in> S) \<and> (x \<longlongrightarrow> l) sequentially \<longrightarrow> l \<in> S)"
  1323   shows "closed S \<longleftrightarrow> (\<forall>x l. (\<forall>n. x n \<in> S) \<and> (x \<longlongrightarrow> l) sequentially \<longrightarrow> l \<in> S)"
  1330 by (metis closure_sequential closure_subset_eq subset_iff)
  1324 by (metis closure_sequential closure_subset_eq subset_iff)
  1338   shows "((\<lambda>x. if x \<in> S then f x else g x) \<longlongrightarrow> l x) (at x within S \<union> T)"
  1332   shows "((\<lambda>x. if x \<in> S then f x else g x) \<longlongrightarrow> l x) (at x within S \<union> T)"
  1339 proof -
  1333 proof -
  1340   have *: "(S \<union> T) \<inter> {x. x \<in> S} = S" "(S \<union> T) \<inter> {x. x \<notin> S} = T - S"
  1334   have *: "(S \<union> T) \<inter> {x. x \<in> S} = S" "(S \<union> T) \<inter> {x. x \<notin> S} = T - S"
  1341     by auto
  1335     by auto
  1342   have "(f \<longlongrightarrow> l x) (at x within S)"
  1336   have "(f \<longlongrightarrow> l x) (at x within S)"
  1343     by (rule filterlim_at_within_closure_implies_filterlim)
  1337     using tendsto_within_subset[OF f] \<open>x \<in> S \<union> T\<close>
  1344        (use \<open>x \<in> _\<close> in \<open>auto simp: inf_commute closure_def intro: tendsto_within_subset[OF f]\<close>)
  1338     by (metis Int_iff Un_iff Un_upper1 closure_def filterlim_at_within_closure_implies_filterlim)
  1345   moreover
  1339   moreover
  1346   have "(g \<longlongrightarrow> l x) (at x within T - S)"
  1340   have "(g \<longlongrightarrow> l x) (at x within T - S)"
  1347     by (rule filterlim_at_within_closure_implies_filterlim)
  1341     using tendsto_within_subset g \<open>x \<in> S \<union> T\<close>
  1348       (use \<open>x \<in> _\<close> in
  1342     by (metis IntI Un_Diff_Int Un_iff Un_upper1 closure_def filterlim_at_within_closure_implies_filterlim) 
  1349         \<open>auto intro!: tendsto_within_subset[OF g] simp: closure_def intro: islimpt_subset\<close>)
       
  1350   ultimately show ?thesis
  1343   ultimately show ?thesis
  1351     by (intro filterlim_at_within_If) (simp_all only: *)
  1344     by (intro filterlim_at_within_If) (simp_all only: *)
  1352 qed
  1345 qed
  1353 
  1346 
  1354 
  1347 
  1391     using assms(1)[unfolded compact_eq_Heine_Borel, THEN spec[where x="{T. \<exists>x. x\<in>S \<and> T = f x}"]]
  1384     using assms(1)[unfolded compact_eq_Heine_Borel, THEN spec[where x="{T. \<exists>x. x\<in>S \<and> T = f x}"]]
  1392     using f by auto
  1385     using f by auto
  1393   then have g': "\<forall>x\<in>g. \<exists>y \<in> S. x = f y"
  1386   then have g': "\<forall>x\<in>g. \<exists>y \<in> S. x = f y"
  1394     by auto
  1387     by auto
  1395   have "inj_on f T"
  1388   have "inj_on f T"
  1396     by (smt (verit, best) assms(3) f inj_onI subsetD)
  1389     unfolding inj_on_def using \<open>T \<subseteq> S\<close> f by blast
  1397   then have "infinite (f ` T)"
  1390   then have "infinite (f ` T)"
  1398     using assms(2) using finite_imageD by auto
  1391     using assms(2) using finite_imageD by auto
  1399   moreover
  1392   moreover
  1400     have False if "x \<in> T" "f x \<notin> g" for x
  1393   have False if "x \<in> T" "f x \<notin> g" for x
  1401       by (smt (verit) UnionE assms(3) f g' g(3) subsetD that)
  1394     using \<open>T \<subseteq> S\<close>  f g' \<open>S \<subseteq> \<Union>g\<close> that by force
  1402   then have "f ` T \<subseteq> g" by auto
  1395   then have "f ` T \<subseteq> g" by auto
  1403   ultimately show False
  1396   ultimately show False
  1404     using g(2) using finite_subset by auto
  1397     using g(2) using finite_subset by auto
  1405 qed
  1398 qed
  1406 
  1399 
  1407 lemma sequence_infinite_lemma:
  1400 lemma sequence_infinite_lemma:
  1408   fixes f :: "nat \<Rightarrow> 'a::t1_space"
  1401   fixes f :: "nat \<Rightarrow> 'a::t1_space"
  1409   assumes "\<forall>n. f n \<noteq> l"
  1402   assumes "\<And>n. f n \<noteq> l"
  1410     and "(f \<longlongrightarrow> l) sequentially"
  1403     and "(f \<longlongrightarrow> l) sequentially"
  1411   shows "infinite (range f)"
  1404   shows "infinite (range f)"
  1412 proof
  1405 proof
  1413   assume "finite (range f)"
  1406   assume "finite (range f)"
  1414   then have "l \<notin> range f \<and> closed (range f)"
  1407   then have "l \<notin> range f \<and> closed (range f)"
  1424   assumes "\<forall>T. infinite T \<and> T \<subseteq> S --> (\<exists>x \<in> S. x islimpt T)"
  1417   assumes "\<forall>T. infinite T \<and> T \<subseteq> S --> (\<exists>x \<in> S. x islimpt T)"
  1425   shows "closed S"
  1418   shows "closed S"
  1426 proof -
  1419 proof -
  1427   {
  1420   {
  1428     fix x l
  1421     fix x l
  1429     assume as: "\<forall>n::nat. x n \<in> S" "(x \<longlongrightarrow> l) sequentially"
  1422     assume \<section>: "\<forall>n. x n \<in> S" "(x \<longlongrightarrow> l) sequentially"
  1430     have "l \<in> S"
  1423     have "l \<in> S"
  1431     proof (cases "\<forall>n. x n \<noteq> l")
  1424     proof (cases "\<forall>n. x n \<noteq> l")
  1432       case False
       
  1433       then show "l\<in>S" using as(1) by auto
       
  1434     next
       
  1435       case True
  1425       case True
  1436       with as(2) have "infinite (range x)"
  1426       with \<section> have "infinite (range x)"
  1437         using sequence_infinite_lemma[of x l] by auto
  1427         using sequence_infinite_lemma[of x l] by auto
  1438       then obtain l' where "l'\<in>S" "l' islimpt (range x)"
  1428       with \<section> assms show "l\<in>S" 
  1439         using as(1) assms by auto
  1429         using sequence_unique_limpt \<section> True by blast 
  1440       then show "l\<in>S" using sequence_unique_limpt as True by auto
  1430     qed (use \<section> in auto)
  1441     qed
       
  1442   }
  1431   }
  1443   then show ?thesis
  1432   then show ?thesis
  1444     unfolding closed_sequential_limits by fast
  1433     unfolding closed_sequential_limits by auto
  1445 qed
  1434 qed
  1446 
  1435 
  1447 lemma closure_insert:
  1436 lemma closure_insert:
  1448   fixes x :: "'a::t1_space"
  1437   fixes x :: "'a::t1_space"
  1449   shows "closure (insert x S) = insert x (closure S)"
  1438   shows "closure (insert x S) = insert x (closure S)"
  1511 
  1500 
  1512 text\<open>Compactness expressed with filters\<close>
  1501 text\<open>Compactness expressed with filters\<close>
  1513 
  1502 
  1514 lemma closure_iff_nhds_not_empty:
  1503 lemma closure_iff_nhds_not_empty:
  1515   "x \<in> closure X \<longleftrightarrow> (\<forall>A. \<forall>S\<subseteq>A. open S \<longrightarrow> x \<in> S \<longrightarrow> X \<inter> A \<noteq> {})"
  1504   "x \<in> closure X \<longleftrightarrow> (\<forall>A. \<forall>S\<subseteq>A. open S \<longrightarrow> x \<in> S \<longrightarrow> X \<inter> A \<noteq> {})"
  1516 proof safe
  1505 proof -
  1517   assume x: "x \<in> closure X"
  1506   have "\<forall>A S. S \<subseteq> A \<longrightarrow> open S \<longrightarrow> x \<in> S \<longrightarrow> X \<inter> A \<noteq> {} \<Longrightarrow> x \<in> closure X"
  1518   fix S A
  1507     by (metis ComplI Diff_disjoint Diff_eq closure_interior inf_top_left 
  1519   assume \<section>: "open S" "x \<in> S" "X \<inter> A = {}" "S \<subseteq> A"
  1508         interior_subset open_interior)
  1520   then have "x \<notin> closure (-S)"
  1509   then show ?thesis
  1521     by (simp add: closed_open)
  1510     using open_Int_closure_eq_empty by fastforce
  1522   with x have "x \<in> closure X - closure (-S)"
       
  1523     by auto
       
  1524   with \<section> show False
       
  1525     by (metis Compl_iff Diff_iff closure_mono disjoint_iff subsetD subsetI)
       
  1526 next
       
  1527   assume "\<forall>A S. S \<subseteq> A \<longrightarrow> open S \<longrightarrow> x \<in> S \<longrightarrow> X \<inter> A \<noteq> {}"
       
  1528   then show "x \<in> closure X"
       
  1529     by (metis ComplI Compl_disjoint closure_interior interior_subset open_interior)
       
  1530 qed
  1511 qed
  1531 
  1512 
  1532 lemma compact_filter:
  1513 lemma compact_filter:
  1533   "compact U \<longleftrightarrow> (\<forall>F. F \<noteq> bot \<longrightarrow> eventually (\<lambda>x. x \<in> U) F \<longrightarrow> (\<exists>x\<in>U. inf (nhds x) F \<noteq> bot))"
  1514   "compact U \<longleftrightarrow> (\<forall>F. F \<noteq> bot \<longrightarrow> eventually (\<lambda>x. x \<in> U) F \<longrightarrow> (\<exists>x\<in>U. inf (nhds x) F \<noteq> bot))"
  1534 proof (intro allI iffI impI compact_fip[THEN iffD2] notI)
  1515 proof (intro allI iffI impI compact_fip[THEN iffD2] notI)
  1593   ultimately obtain x where "x \<in> U" and x: "inf (nhds x) F \<noteq> bot"
  1574   ultimately obtain x where "x \<in> U" and x: "inf (nhds x) F \<noteq> bot"
  1594     by auto
  1575     by auto
  1595 
  1576 
  1596   { fix V assume "V \<in> A"
  1577   { fix V assume "V \<in> A"
  1597     then have "F \<le> principal V"
  1578     then have "F \<le> principal V"
  1598       unfolding F_def by (intro INF_lower2[of V]) auto
  1579       by (metis INF_lower F_def insertCI)
  1599     then have V: "eventually (\<lambda>x. x \<in> V) F"
  1580     then have V: "eventually (\<lambda>x. x \<in> V) F"
  1600       by (auto simp: le_filter_def eventually_principal)
  1581       by (auto simp: le_filter_def eventually_principal)
  1601     have "x \<in> closure V"
  1582     have "x \<in> closure V"
  1602       unfolding closure_iff_nhds_not_empty
  1583       unfolding closure_iff_nhds_not_empty
  1603     proof (intro impI allI)
  1584     proof (intro impI allI)
  1626   assumes "countably_compact s" and "\<forall>t\<in>C. open t" and "s \<subseteq> \<Union>C" "countable C"
  1607   assumes "countably_compact s" and "\<forall>t\<in>C. open t" and "s \<subseteq> \<Union>C" "countable C"
  1627   obtains C' where "C' \<subseteq> C" and "finite C'" and "s \<subseteq> \<Union>C'"
  1608   obtains C' where "C' \<subseteq> C" and "finite C'" and "s \<subseteq> \<Union>C'"
  1628   using assms unfolding countably_compact_def by metis
  1609   using assms unfolding countably_compact_def by metis
  1629 
  1610 
  1630 lemma countably_compactI:
  1611 lemma countably_compactI:
  1631   assumes "\<And>C. \<forall>t\<in>C. open t \<Longrightarrow> s \<subseteq> \<Union>C \<Longrightarrow> countable C \<Longrightarrow> (\<exists>C'\<subseteq>C. finite C' \<and> s \<subseteq> \<Union>C')"
  1612   assumes "\<And>C. \<forall>t\<in>C. open t \<Longrightarrow> s \<subseteq> \<Union>C \<Longrightarrow> countable C \<Longrightarrow> \<exists>C'\<subseteq>C. finite C' \<and> s \<subseteq> \<Union>C'"
  1632   shows "countably_compact s"
  1613   shows "countably_compact s"
  1633   using assms unfolding countably_compact_def by metis
  1614   using assms unfolding countably_compact_def by metis
  1634 
  1615 
  1635 lemma compact_imp_countably_compact: "compact U \<Longrightarrow> countably_compact U"
  1616 lemma compact_imp_countably_compact: "compact U \<Longrightarrow> countably_compact U"
  1636   by (auto simp: compact_eq_Heine_Borel countably_compact_def)
  1617   by (auto simp: compact_eq_Heine_Borel countably_compact_def)
  1649   moreover define C where "C = {b\<in>B. \<exists>a\<in>A. b \<inter> U \<subseteq> a}"
  1630   moreover define C where "C = {b\<in>B. \<exists>a\<in>A. b \<inter> U \<subseteq> a}"
  1650   ultimately have "countable C" "\<forall>a\<in>C. open a"
  1631   ultimately have "countable C" "\<forall>a\<in>C. open a"
  1651     unfolding C_def using ccover by auto
  1632     unfolding C_def using ccover by auto
  1652   moreover
  1633   moreover
  1653   have "\<Union>A \<inter> U \<subseteq> \<Union>C"
  1634   have "\<Union>A \<inter> U \<subseteq> \<Union>C"
  1654   proof safe
  1635   proof clarify
  1655     fix x a
  1636     fix x a
  1656     assume "x \<in> U" "x \<in> a" "a \<in> A"
  1637     assume "x \<in> U" "x \<in> a" "a \<in> A"
  1657     with basis[of a x] A obtain b where "b \<in> B" "x \<in> b" "b \<inter> U \<subseteq> a"
  1638     with basis[of a x] A show "x \<in> \<Union>C"
  1658       by blast
       
  1659     with \<open>a \<in> A\<close> show "x \<in> \<Union>C"
       
  1660       unfolding C_def by auto
  1639       unfolding C_def by auto
  1661   qed
  1640   qed
  1662   then have "U \<subseteq> \<Union>C" using \<open>U \<subseteq> \<Union>A\<close> by auto
  1641   then have "U \<subseteq> \<Union>C" using \<open>U \<subseteq> \<Union>A\<close> by auto
  1663   ultimately obtain T where T: "T\<subseteq>C" "finite T" "U \<subseteq> \<Union>T"
  1642   ultimately obtain T where T: "T\<subseteq>C" "finite T" "U \<subseteq> \<Union>T"
  1664     using * by metis
  1643     using * by metis
  1673 proposition countably_compact_imp_compact_second_countable:
  1652 proposition countably_compact_imp_compact_second_countable:
  1674   "countably_compact U \<Longrightarrow> compact (U :: 'a :: second_countable_topology set)"
  1653   "countably_compact U \<Longrightarrow> compact (U :: 'a :: second_countable_topology set)"
  1675 proof (rule countably_compact_imp_compact)
  1654 proof (rule countably_compact_imp_compact)
  1676   fix T and x :: 'a
  1655   fix T and x :: 'a
  1677   assume "open T" "x \<in> T"
  1656   assume "open T" "x \<in> T"
  1678   from topological_basisE[OF is_basis this] obtain b where
  1657   from topological_basisE[OF is_basis this] 
  1679     "b \<in> (SOME B. countable B \<and> topological_basis B)" "x \<in> b" "b \<subseteq> T" .
  1658   show "\<exists>b\<in>SOME B. countable B \<and> topological_basis B. x \<in> b \<and> b \<inter> U \<subseteq> T"
  1680   then show "\<exists>b\<in>SOME B. countable B \<and> topological_basis B. x \<in> b \<and> b \<inter> U \<subseteq> T"
  1659     by (metis le_infI1)
  1681     by blast
       
  1682 qed (insert countable_basis topological_basis_open[OF is_basis], auto)
  1660 qed (insert countable_basis topological_basis_open[OF is_basis], auto)
  1683 
  1661 
  1684 lemma countably_compact_eq_compact:
  1662 lemma countably_compact_eq_compact:
  1685   "countably_compact U \<longleftrightarrow> compact (U :: 'a :: second_countable_topology set)"
  1663   "countably_compact U \<longleftrightarrow> compact (U :: 'a :: second_countable_topology set)"
  1686   using countably_compact_imp_compact_second_countable compact_imp_countably_compact by blast
  1664   using countably_compact_imp_compact_second_countable compact_imp_countably_compact by blast
  1724 
  1702 
  1725 lemma seq_compact_imp_countably_compact:
  1703 lemma seq_compact_imp_countably_compact:
  1726   fixes U :: "'a :: first_countable_topology set"
  1704   fixes U :: "'a :: first_countable_topology set"
  1727   assumes "seq_compact U"
  1705   assumes "seq_compact U"
  1728   shows "countably_compact U"
  1706   shows "countably_compact U"
  1729 proof (safe intro!: countably_compactI)
  1707 proof (intro countably_compactI)
  1730   fix A
  1708   fix A
  1731   assume A: "\<forall>a\<in>A. open a" "U \<subseteq> \<Union>A" "countable A"
  1709   assume A: "\<forall>a\<in>A. open a" "U \<subseteq> \<Union>A" "countable A"
  1732   have subseq: "\<And>X. range X \<subseteq> U \<Longrightarrow> \<exists>r x. x \<in> U \<and> strict_mono (r :: nat \<Rightarrow> nat) \<and> (X \<circ> r) \<longlonglongrightarrow> x"
  1710   have subseq: "\<And>X. range X \<subseteq> U \<Longrightarrow> \<exists>r x. x \<in> U \<and> strict_mono (r :: nat \<Rightarrow> nat) \<and> (X \<circ> r) \<longlonglongrightarrow> x"
  1733     using \<open>seq_compact U\<close> by (fastforce simp: seq_compact_def subset_eq)
  1711     using \<open>seq_compact U\<close> by (fastforce simp: seq_compact_def subset_eq)
  1734   show "\<exists>T\<subseteq>A. finite T \<and> U \<subseteq> \<Union>T"
  1712   show "\<exists>T\<subseteq>A. finite T \<and> U \<subseteq> \<Union>T"
  1822     fix S
  1800     fix S
  1823     assume "open S" "x \<in> S"
  1801     assume "open S" "x \<in> S"
  1824     with A(3) have "eventually (\<lambda>i. A i \<subseteq> S) sequentially"
  1802     with A(3) have "eventually (\<lambda>i. A i \<subseteq> S) sequentially"
  1825       by auto
  1803       by auto
  1826     moreover
  1804     moreover
  1827     {
  1805     have "X (r i) \<in> A i" if "Suc 0 \<le> i" for i
  1828       fix i
  1806       using that by (cases i) (simp_all add: r_def s)
  1829       assume "Suc 0 \<le> i"
       
  1830       then have "X (r i) \<in> A i"
       
  1831         by (cases i) (simp_all add: r_def s)
       
  1832     }
       
  1833     then have "eventually (\<lambda>i. X (r i) \<in> A i) sequentially"
  1807     then have "eventually (\<lambda>i. X (r i) \<in> A i) sequentially"
  1834       by (auto simp: eventually_sequentially)
  1808       by (auto simp: eventually_sequentially)
  1835     ultimately show "eventually (\<lambda>i. X (r i) \<in> S) sequentially"
  1809     ultimately show "eventually (\<lambda>i. X (r i) \<in> S) sequentially"
  1836       by eventually_elim auto
  1810       by eventually_elim auto
  1837   qed
  1811   qed
  1851   moreover have "\<forall>T\<in>C. open T"
  1825   moreover have "\<forall>T\<in>C. open T"
  1852     by (auto simp: C_def)
  1826     by (auto simp: C_def)
  1853   moreover
  1827   moreover
  1854   assume "\<not> (\<exists>x\<in>S. \<forall>U. x\<in>U \<and> open U \<longrightarrow> infinite (U \<inter> T))"
  1828   assume "\<not> (\<exists>x\<in>S. \<forall>U. x\<in>U \<and> open U \<longrightarrow> infinite (U \<inter> T))"
  1855   then have S: "\<And>x. x \<in> S \<Longrightarrow> \<exists>U. x\<in>U \<and> open U \<and> finite (U \<inter> T)" by metis
  1829   then have S: "\<And>x. x \<in> S \<Longrightarrow> \<exists>U. x\<in>U \<and> open U \<and> finite (U \<inter> T)" by metis
  1856   have "S \<subseteq> \<Union>C"
  1830   have "\<And>x U. \<lbrakk>T \<subseteq> S; x \<in> U; open U; finite (U \<inter> T)\<rbrakk> \<Longrightarrow> x \<in> \<Union> C"
  1857     using \<open>T \<subseteq> S\<close>
       
  1858     unfolding C_def
  1831     unfolding C_def
  1859     apply (safe dest!: S)
  1832     by (auto intro!: UN_I [where a="U \<inter> T"] interiorI simp add: finite_subset)
  1860     apply (rule_tac a="U \<inter> T" in UN_I)
  1833   then have "S \<subseteq> \<Union>C"
  1861     apply (auto intro!: interiorI simp add: finite_subset)
  1834     using \<open>T \<subseteq> S\<close> S by force
  1862     done
       
  1863   moreover
  1835   moreover
  1864   from \<open>countable T\<close> have "countable C"
  1836   from \<open>countable T\<close> have "countable C"
  1865     unfolding C_def by (auto intro: countable_Collect_finite_subset)
  1837     unfolding C_def by (auto intro: countable_Collect_finite_subset)
  1866   ultimately
  1838   ultimately
  1867   obtain D where "D \<subseteq> C" "finite D" "S \<subseteq> \<Union>D"
  1839   obtain D where "D \<subseteq> C" "finite D" "S \<subseteq> \<Union>D"
  1973     with compactE_image[OF \<open>compact T\<close>] obtain D where D: "D \<subseteq> T" "finite D" "T \<subseteq> (\<Union>y\<in>D. b y)"
  1945     with compactE_image[OF \<open>compact T\<close>] obtain D where D: "D \<subseteq> T" "finite D" "T \<subseteq> (\<Union>y\<in>D. b y)"
  1974       by metis
  1946       by metis
  1975     moreover from D c have "(\<Inter>y\<in>D. a y) \<times> T \<subseteq> (\<Union>y\<in>D. c y)"
  1947     moreover from D c have "(\<Inter>y\<in>D. a y) \<times> T \<subseteq> (\<Union>y\<in>D. c y)"
  1976       by (fastforce simp: subset_eq)
  1948       by (fastforce simp: subset_eq)
  1977     ultimately show "\<exists>a. open a \<and> x \<in> a \<and> (\<exists>d\<subseteq>\<C>. finite d \<and> a \<times> T \<subseteq> \<Union>d)"
  1949     ultimately show "\<exists>a. open a \<and> x \<in> a \<and> (\<exists>d\<subseteq>\<C>. finite d \<and> a \<times> T \<subseteq> \<Union>d)"
  1978       using c by (intro exI[of _ "c`D"] exI[of _ "\<Inter>(a`D)"] conjI) (auto intro!: open_INT)
  1950       using c exI[of _ "c`D"] exI[of _ "\<Inter>(a`D)"] by (simp add: open_INT subset_eq)
  1979   qed
  1951   qed
  1980   then obtain a d where a: "\<And>x. x\<in>S \<Longrightarrow> open (a x)" "S \<subseteq> (\<Union>x\<in>S. a x)"
  1952   then obtain a d where a: "\<And>x. x\<in>S \<Longrightarrow> open (a x)" "S \<subseteq> (\<Union>x\<in>S. a x)"
  1981     and d: "\<And>x. x \<in> S \<Longrightarrow> d x \<subseteq> \<C> \<and> finite (d x) \<and> a x \<times> T \<subseteq> \<Union>(d x)"
  1953     and d: "\<And>x. x \<in> S \<Longrightarrow> d x \<subseteq> \<C> \<and> finite (d x) \<and> a x \<times> T \<subseteq> \<Union>(d x)"
  1982     unfolding subset_eq UN_iff by metis
  1954     unfolding subset_eq UN_iff by metis
  1983   moreover
  1955   moreover
  1986     by auto
  1958     by auto
  1987   moreover
  1959   moreover
  1988   have "S \<times> T \<subseteq> (\<Union>x\<in>e. \<Union>(d x))"
  1960   have "S \<times> T \<subseteq> (\<Union>x\<in>e. \<Union>(d x))"
  1989     by (smt (verit, del_insts) S SigmaE UN_iff d e(1) mem_Sigma_iff subset_eq)
  1961     by (smt (verit, del_insts) S SigmaE UN_iff d e(1) mem_Sigma_iff subset_eq)
  1990   ultimately show "\<exists>C'\<subseteq>\<C>. finite C' \<and> S \<times> T \<subseteq> \<Union>C'"
  1962   ultimately show "\<exists>C'\<subseteq>\<C>. finite C' \<and> S \<times> T \<subseteq> \<Union>C'"
  1991     by (intro exI[of _ "(\<Union>x\<in>e. d x)"]) (auto simp: subset_eq)
  1963     by (force simp: subset_eq intro!: exI[of _ "\<Union>x\<in>e. d x"])
  1992 qed
  1964 qed
  1993 
  1965 
  1994 
  1966 
  1995 lemma tube_lemma:
  1967 lemma tube_lemma:
  1996   assumes "compact K"
  1968   assumes "compact K"
  1997   assumes "open W"
  1969   assumes "open W"
  1998   assumes "{x0} \<times> K \<subseteq> W"
  1970   assumes "{x0} \<times> K \<subseteq> W"
  1999   shows "\<exists>X0. x0 \<in> X0 \<and> open X0 \<and> X0 \<times> K \<subseteq> W"
  1971   shows "\<exists>X0. x0 \<in> X0 \<and> open X0 \<and> X0 \<times> K \<subseteq> W"
  2000 proof -
  1972 proof -
  2001   {
  1973     have "\<exists>X0 Y. open X0 \<and> open Y \<and> x0 \<in> X0 \<and> y \<in> Y \<and> X0 \<times> Y \<subseteq> W" if "y \<in> K" for y
  2002     fix y assume "y \<in> K"
  1974       using assms open_prod_def subsetD that by fastforce
  2003     then have "(x0, y) \<in> W" using assms by auto
       
  2004     with \<open>open W\<close>
       
  2005     have "\<exists>X0 Y. open X0 \<and> open Y \<and> x0 \<in> X0 \<and> y \<in> Y \<and> X0 \<times> Y \<subseteq> W"
       
  2006       by (rule open_prod_elim) blast
       
  2007   }
       
  2008   then obtain X0 Y where
  1975   then obtain X0 Y where
  2009     *: "\<forall>y \<in> K. open (X0 y) \<and> open (Y y) \<and> x0 \<in> X0 y \<and> y \<in> Y y \<and> X0 y \<times> Y y \<subseteq> W"
  1976     *: "\<forall>y \<in> K. open (X0 y) \<and> open (Y y) \<and> x0 \<in> X0 y \<and> y \<in> Y y \<and> X0 y \<times> Y y \<subseteq> W"
  2010     by metis
  1977     by metis
  2011   from * have "\<forall>t\<in>Y ` K. open t" "K \<subseteq> \<Union>(Y ` K)" by auto
  1978   from * have "\<forall>t\<in>Y ` K. open t" "K \<subseteq> \<Union>(Y ` K)" by auto
  2012   with \<open>compact K\<close> obtain CC where CC: "CC \<subseteq> Y ` K" "finite CC" "K \<subseteq> \<Union>CC"
  1979   with \<open>compact K\<close> obtain CC where CC: "CC \<subseteq> Y ` K" "finite CC" "K \<subseteq> \<Union>CC"
  2013     by (meson compactE)
  1980     by (meson compactE)
  2014   then obtain c where c: "\<And>C. C \<in> CC \<Longrightarrow> c C \<in> K \<and> C = Y (c C)"
  1981   then obtain c where c: "\<And>C. C \<in> CC \<Longrightarrow> c C \<in> K \<and> C = Y (c C)"
  2015     by (force intro!: choice)
  1982     by (force intro!: choice)
  2016   with * CC show ?thesis
  1983   with * CC show ?thesis
  2017     by (force intro!: exI[where x="\<Inter>C\<in>CC. X0 (c C)"]) (* SLOW *)
  1984     by (bestsimp intro!: exI[where x="\<Inter>C\<in>CC. X0 (c C)"]) (* SLOW *)
  2018 qed
  1985 qed
  2019 
  1986 
  2020 lemma continuous_on_prod_compactE:
  1987 lemma continuous_on_prod_compactE:
  2021   fixes fx::"'a::topological_space \<times> 'b::topological_space \<Rightarrow> 'c::metric_space"
  1988   fixes fx::"'a::topological_space \<times> 'b::topological_space \<Rightarrow> 'c::metric_space"
  2022     and e::real
  1989     and e::real
  2045   from tube_lemma[OF \<open>compact C\<close> \<open>open W\<close> this]
  2012   from tube_lemma[OF \<open>compact C\<close> \<open>open W\<close> this]
  2046   obtain X0 where X0: "x0 \<in> X0" "open X0" "X0 \<times> C \<subseteq> W"
  2013   obtain X0 where X0: "x0 \<in> X0" "open X0" "X0 \<times> C \<subseteq> W"
  2047     by blast
  2014     by blast
  2048 
  2015 
  2049   have "\<forall>x\<in>X0 \<inter> U. \<forall>t \<in> C. dist (fx (x, t)) (fx (x0, t)) \<le> e"
  2016   have "\<forall>x\<in>X0 \<inter> U. \<forall>t \<in> C. dist (fx (x, t)) (fx (x0, t)) \<le> e"
  2050   proof safe
  2017   proof clarify
  2051     fix x assume x: "x \<in> X0" "x \<in> U"
  2018     fix x assume x: "x \<in> X0" "x \<in> U"
  2052     fix t assume t: "t \<in> C"
  2019     fix t assume t: "t \<in> C"
  2053     have "dist (fx (x, t)) (fx (x0, t)) = psi (x, t)"
  2020     have "dist (fx (x, t)) (fx (x0, t)) = psi (x, t)"
  2054       by (auto simp: psi_def)
  2021       by (auto simp: psi_def)
  2055     also have "psi (x, t) < e"
  2022     also have "psi (x, t) < e"
  2105     using "*" f continuous_within filterlim_compose tendsto_at_within_iff_tendsto_nhds by blast
  2072     using "*" f continuous_within filterlim_compose tendsto_at_within_iff_tendsto_nhds by blast
  2106 qed
  2073 qed
  2107 
  2074 
  2108 lemma continuous_within_tendsto_compose':
  2075 lemma continuous_within_tendsto_compose':
  2109   fixes f::"'a::t2_space \<Rightarrow> 'b::topological_space"
  2076   fixes f::"'a::t2_space \<Rightarrow> 'b::topological_space"
  2110   assumes "continuous (at a within S) f"
  2077   assumes "continuous (at a within S) f" "\<And>n. x n \<in> S" "(x \<longlongrightarrow> a) F "
  2111     "\<And>n. x n \<in> S"
       
  2112     "(x \<longlongrightarrow> a) F "
       
  2113   shows "((\<lambda>n. f (x n)) \<longlongrightarrow> f a) F"
  2078   shows "((\<lambda>n. f (x n)) \<longlongrightarrow> f a) F"
  2114   using always_eventually assms continuous_within_tendsto_compose by blast
  2079   using always_eventually assms continuous_within_tendsto_compose by blast
  2115 
  2080 
  2116 lemma continuous_within_sequentially:
  2081 lemma continuous_within_sequentially:
  2117   fixes f :: "'a::{first_countable_topology, t2_space} \<Rightarrow> 'b::topological_space"
  2082   fixes f :: "'a::{first_countable_topology, t2_space} \<Rightarrow> 'b::topological_space"
  2118   shows "continuous (at a within S) f \<longleftrightarrow>
  2083   shows "continuous (at a within S) f \<longleftrightarrow>
  2119     (\<forall>x. (\<forall>n::nat. x n \<in> S) \<and> (x \<longlongrightarrow> a) sequentially
  2084     (\<forall>x. (\<forall>n::nat. x n \<in> S) \<and> (x \<longlongrightarrow> a) sequentially
  2120          \<longrightarrow> ((f \<circ> x) \<longlongrightarrow> f a) sequentially)"
  2085          \<longrightarrow> ((f \<circ> x) \<longlongrightarrow> f a) sequentially)"
  2121   using continuous_within_tendsto_compose'[of a S f _ sequentially]
  2086   using continuous_within_tendsto_compose'[of a S f _ sequentially]
  2122     continuous_within_sequentiallyI[of a S f]
  2087   using continuous_within_sequentiallyI[of a S f]
  2123   by (auto simp: o_def)
  2088   by (auto simp: o_def)
  2124 
  2089 
  2125 lemma continuous_at_sequentiallyI:
  2090 lemma continuous_at_sequentiallyI:
  2126   fixes f :: "'a::{first_countable_topology, t2_space} \<Rightarrow> 'b::topological_space"
  2091   fixes f :: "'a::{first_countable_topology, t2_space} \<Rightarrow> 'b::topological_space"
  2127   assumes "\<And>u. u \<longlonglongrightarrow> a \<Longrightarrow> (\<lambda>n. f (u n)) \<longlonglongrightarrow> f a"
  2092   assumes "\<And>u. u \<longlonglongrightarrow> a \<Longrightarrow> (\<lambda>n. f (u n)) \<longlonglongrightarrow> f a"
  2213 lemma continuous_on_translation_eq:
  2178 lemma continuous_on_translation_eq:
  2214   fixes g :: "'a :: real_normed_vector \<Rightarrow> 'b :: real_normed_vector"
  2179   fixes g :: "'a :: real_normed_vector \<Rightarrow> 'b :: real_normed_vector"
  2215   shows "continuous_on A ((+) a \<circ> g) = continuous_on A g"
  2180   shows "continuous_on A ((+) a \<circ> g) = continuous_on A g"
  2216 proof -
  2181 proof -
  2217   have g: "g = (\<lambda>x. -a + x) \<circ> ((\<lambda>x. a + x) \<circ> g)"
  2182   have g: "g = (\<lambda>x. -a + x) \<circ> ((\<lambda>x. a + x) \<circ> g)"
  2218     by (rule ext) simp
  2183     by force
  2219   show ?thesis
  2184   show ?thesis
  2220     by (metis (no_types, opaque_lifting) g continuous_on_compose homeomorphism_def homeomorphism_translation)
  2185     by (metis (no_types, opaque_lifting) g continuous_on_compose homeomorphism_def homeomorphism_translation)
  2221 qed
  2186 qed
  2222 
  2187 
  2223 definition\<^marker>\<open>tag important\<close> homeomorphic :: "'a::topological_space set \<Rightarrow> 'b::topological_space set \<Rightarrow> bool"
  2188 definition\<^marker>\<open>tag important\<close> homeomorphic :: "'a::topological_space set \<Rightarrow> 'b::topological_space set \<Rightarrow> bool"
  2243 
  2208 
  2244 lemma homeomorphic_minimal:
  2209 lemma homeomorphic_minimal:
  2245   "S homeomorphic T \<longleftrightarrow>
  2210   "S homeomorphic T \<longleftrightarrow>
  2246     (\<exists>f g. (\<forall>x\<in>S. f(x) \<in> T \<and> (g(f(x)) = x)) \<and>
  2211     (\<exists>f g. (\<forall>x\<in>S. f(x) \<in> T \<and> (g(f(x)) = x)) \<and>
  2247            (\<forall>y\<in>T. g(y) \<in> S \<and> (f(g(y)) = y)) \<and>
  2212            (\<forall>y\<in>T. g(y) \<in> S \<and> (f(g(y)) = y)) \<and>
  2248            continuous_on S f \<and> continuous_on T g)"
  2213            continuous_on S f \<and> continuous_on T g)" (is "?L=?R")
  2249   by (smt (verit, ccfv_threshold) homeomorphic_def homeomorphismI homeomorphism_def image_eqI image_subset_iff)
  2214 proof
       
  2215   assume "S homeomorphic T"
       
  2216   then obtain f g where \<section>: "homeomorphism S T f g"
       
  2217     using homeomorphic_def by blast
       
  2218   show ?R
       
  2219   proof (intro exI conjI)
       
  2220     show "\<forall>x\<in>S. f x \<in> T \<and> g (f x) = x" "\<forall>y\<in>T. g y \<in> S \<and> f (g y) = y"
       
  2221       by (metis "\<section>" homeomorphism_def imageI)+
       
  2222     show "continuous_on S f" "continuous_on T g"
       
  2223       using "\<section>" homeomorphism_def by blast+
       
  2224   qed
       
  2225 qed (force simp: homeomorphic_def homeomorphism_def image_iff)
  2250 
  2226 
  2251 lemma homeomorphicI [intro?]:
  2227 lemma homeomorphicI [intro?]:
  2252    "\<lbrakk>f ` S = T; g ` T = S;
  2228    "\<lbrakk>f ` S = T; g ` T = S;
  2253      continuous_on S f; continuous_on T g;
  2229      continuous_on S f; continuous_on T g;
  2254      \<And>x. x \<in> S \<Longrightarrow> g(f(x)) = x;
  2230      \<And>x. x \<in> S \<Longrightarrow> g(f(x)) = x;
  2289 by (metis continuous_on_no_limpt islimpt_finite)
  2265 by (metis continuous_on_no_limpt islimpt_finite)
  2290 
  2266 
  2291 lemma homeomorphic_finite:
  2267 lemma homeomorphic_finite:
  2292   fixes S :: "'a::t1_space set" and T :: "'b::t1_space set"
  2268   fixes S :: "'a::t1_space set" and T :: "'b::t1_space set"
  2293   assumes "finite T"
  2269   assumes "finite T"
  2294   shows "S homeomorphic T \<longleftrightarrow> finite S \<and> finite T \<and> card S = card T" (is "?lhs = ?rhs")
  2270   shows "S homeomorphic T \<longleftrightarrow> finite S \<and> card S = card T" (is "?lhs = ?rhs")
  2295 proof
  2271 proof
  2296   assume "S homeomorphic T"
  2272   assume "S homeomorphic T"
  2297   with assms show ?rhs
  2273   with assms show ?rhs
  2298     by (metis (full_types) card_image_le finite_imageI homeomorphic_def homeomorphism_def le_antisym)
  2274     by (metis (full_types) card_image_le finite_imageI homeomorphic_def homeomorphism_def le_antisym)
  2299 next
  2275 next
  2300   assume R: ?rhs
  2276   assume R: ?rhs
  2301   with finite_same_card_bij obtain h where "bij_betw h S T"
  2277   with finite_same_card_bij assms obtain h where h: "bij_betw h S T"
  2302     by auto
  2278     by auto
  2303   with R show ?lhs
  2279   show ?lhs
  2304     apply (simp only: homeomorphic_def homeomorphism_def continuous_on_finite)
  2280     unfolding homeomorphic_def homeomorphism_def 
  2305     by (smt (verit, ccfv_SIG) bij_betw_imp_surj_on bij_betw_inv_into bij_betw_inv_into_left bij_betw_inv_into_right)
  2281   proof (intro exI conjI)
       
  2282     show "continuous_on S h" "continuous_on T (inv_into S h)"
       
  2283       by (simp_all add: assms R continuous_on_finite)
       
  2284   qed (use h in \<open>auto simp: bij_betw_def\<close>)
  2306 qed
  2285 qed
  2307 
  2286 
  2308 text \<open>Relatively weak hypotheses if a set is compact.\<close>
  2287 text \<open>Relatively weak hypotheses if a set is compact.\<close>
  2309 
  2288 
  2310 lemma homeomorphism_compact:
  2289 lemma homeomorphism_compact: