Theory UniformSpace_ZF_2

(* 
    This file is a part of IsarMathLib - 
    a library of formalized mathematics written for Isabelle/Isar.

    Copyright (C) 2021-2022 Slawomir Kolodynski

    This program is free software; Redistribution and use in source and binary forms, 
    with or without modification, are permitted provided that the following conditions are met:

   1. Redistributions of source code must retain the above copyright notice, 
   this list of conditions and the following disclaimer.
   2. Redistributions in binary form must reproduce the above copyright notice, 
   this list of conditions and the following disclaimer in the documentation and/or 
   other materials provided with the distribution.
   3. The name of the author may not be used to endorse or promote products 
   derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *)

section ‹ Alternative definitions of uniformity ›

theory UniformSpace_ZF_2 imports UniformSpace_ZF
begin

text‹ The UniformSpace_ZF› theory defines uniform spaces based on entourages (also called surroundings 
  sometimes). In this theory we consider alternative definitions based of the 
  notion of uniform covers and pseudometrics.
  ›

subsection‹ Uniform covers ›

text‹ Given a set $X$ we can consider collections of subsets of $X$ whose unions are equal to $X$. 
  Any such collection is called a cover of $X$. We can define relation on the set of covers
  of $X$, called "star refinement" (definition below). A collection of covers is a 
  "family of uniform covers" if it is a filter with respect to the start refinement ordering. 
  A member of such family is called a "uniform cover", but one has to remember that this notion 
  has meaning only in the contexts a the whole family of uniform covers. Looking at a specific cover
  in isolation we can not say whether it is a uniform cover or not.  ›

text‹ The set of all covers of $X$ is called Covers(X)›. ›

definition 
  "Covers(X)  {P  Pow(Pow(X)). P = X}" 

text‹A cover of a nonempty set must have a nonempty member.›

lemma cover_nonempty: assumes "X0" "P  Covers(X)"
  shows "UP. U0"
  using assms unfolding Covers_def by blast  

text‹ A "star" of $R$ with respect to $\mathcal{R}$ is the union of all $S\in \mathcal{R}$ that
  intersect $R$. ›

definition
  "Star(R,)  {S. SR  0}"

text‹An element of $\mathcal{R}$ is a subset of its star with respect to $\mathcal{R}$. ›

lemma element_subset_star: assumes "UP" shows "U  Star(U,P)"
  using assms unfolding Star_def by auto

text‹An alternative formula for star of a singleton.›

lemma star_singleton: shows "({V×V. VP})``{x} = Star({x},P)"
  unfolding Star_def by blast

text‹Star of a larger set is larger.›

lemma star_mono: assumes "UV" shows "Star(U,P)  Star(V,P)"
  using assms unfolding Star_def by blast

text‹In particular, star of a set is larger than star of any singleton in that set.›

corollary star_single_mono: assumes "xU" shows "Star({x},P)  Star(U,P)"
  using assms star_mono by auto

text‹A cover $\mathcal{R}$ (of $X$) is said to be a "barycentric refinement" of a cover $\mathcal{C}$ 
  iff for every $x\in X$ the star of $\{x\}$ in $\mathcal{R}$ is contained 
  in some $C\in \mathcal{C}$. ›

definition
  IsBarycentricRefinement ("_ <B _" 90) 
  where "P <B Q  xP.UQ.  Star({x},P)  U"

text‹A cover is a barycentric refinement of the collection of stars of the singletons
  $\{x \}$ as $x$ ranges over $X$.›

lemma singl_star_bary: 
  assumes "P  Covers(X)" shows "P <B {Star({x},P). xX}"
  using assms unfolding Covers_def IsBarycentricRefinement_def by blast    

text‹ A cover $\mathcal{R}$ is a "star refinement" of a cover $\mathcal{C}$  iff 
  for each $R\in \mathcal{R}$ there is a $C\in \mathcal{C}$ such that the star of $R$ with 
  respect to $\mathcal{R}$ is contained in $C$. ›

definition
  IsStarRefinement ("_ <* _" 90)
  where "P <* Q  UP.VQ. Star(U,P)  V"

text‹Every cover star-refines the trivial cover $\{ X\}$. ›

lemma cover_stref_triv: assumes "P  Covers(X)" shows "P <* {X}"
  using assms unfolding Star_def IsStarRefinement_def Covers_def by auto

text‹Star refinement implies barycentric refinement. ›

lemma star_is_bary: assumes "QCovers(X)" and "Q <* P"
  shows "Q <B P"
proof -
  from assms(1) have "Q = X" unfolding Covers_def by simp
  { fix x assume "xX"
    with Q = X obtain R where "RQ" and "xR" by auto
    with assms(2) obtain U where "UP" and "Star(R,Q)  U"
      unfolding IsStarRefinement_def by auto
    from xR Star(R,Q)  U have "Star({x},Q)  U"
      using star_single_mono by blast
    with UP have "UP. Star({x},Q)  U" by auto
 } with Q = X show ?thesis unfolding IsBarycentricRefinement_def
    by simp
qed

text‹ Barycentric refinement of a barycentric refinement is a star refinement. ›

lemma bary_bary_star: 
  assumes "PCovers(X)" "QCovers(X)" "RCovers(X)" "P <B Q" "Q <B R" "X0" 
  shows "P <* R"
proof -
  { fix U assume "UP" 
    { assume "U = 0"
      then have "Star(U,P) = 0" unfolding Star_def by simp
      from assms(6,3) obtain V where "VR" using cover_nonempty by auto
      with Star(U,P) = 0 have "VR. Star(U,P)  V" by auto
    }
    moreover 
    { assume "U0"
      then obtain x0 where "x0U" by auto
      with assms(1,2,5) UP obtain V where "VR" and "Star({x0},Q)  V"
        unfolding Covers_def IsBarycentricRefinement_def by auto
      have "Star(U,P)  V"
      proof -
        { fix W assume "WP" and "WU  0"
          from WU  0 obtain x where "xWU" by auto
          with assms(2) UP have  "xP" by auto
          with assms(4) obtain C where "CQ" and "Star({x},P)  C"
            unfolding IsBarycentricRefinement_def by blast
          with UP WP xWU x0U Star({x0},Q)  V have "WV" 
            unfolding Star_def by blast
        } then show "Star(U,P)  V" unfolding Star_def by auto        
      qed
      with VR have "VR. Star(U,P)  V" by auto
    }
    ultimately have "VR. Star(U,P)  V" by auto
  } then show "P <* R" unfolding IsStarRefinement_def by simp
qed

text‹The notion of a filter defined in Topology_ZF_4› is not sufficiently general to use it to 
  define uniform covers, so we write the conditions directly. A nonempty 
  collection $\Theta$ of covers of $X$ is a family of uniform covers if  
  
  a) if $\mathcal{R} \in \Theta$ and $\mathcal{C}$ is any cover of $X$ such that $\mathcal{R}$ is 
  a star refinement of $\mathcal{C}$, then $\mathcal{C} \in \Theta$.
  
  b) For any $\mathcal{C},\mathcal{D} \in \Theta$ there is some $\mathcal{R}\in\Theta$ 
  such that $\mathcal{R}$ is a star refinement of both $\mathcal{C}$ and $\mathcal{R}$.

  This departs slightly from the definition in Wikipedia that requires that $\Theta$ contains the
  trivial cover $\{ X\}$. As we show in lemma unicov_contains_trivial› below we don't loose 
  anything by weakening the definition this way.
  ›

definition
  AreUniformCovers ("_ {are uniform covers of} _" 90)
  where "Θ {are uniform covers of} X   Θ  Covers(X)  Θ0  
  (Θ.𝒞Covers(X). (( <* 𝒞)  𝒞Θ)) 
  (𝒞Θ.𝒟Θ.Θ.( <* 𝒞)  ( <* 𝒟))"

text‹A family of uniform covers contain the trivial cover $\{ X\}$.›

lemma unicov_contains_triv: assumes "Θ {are uniform covers of} X" 
  shows "{X}  Θ"
proof -
  from assms obtain  where "Θ" unfolding AreUniformCovers_def by blast
  with assms show ?thesis using cover_stref_triv 
    unfolding AreUniformCovers_def Covers_def by auto
qed

text‹If $\Theta$ are uniform covers of $X$ then we can recover $X$ from $\Theta$ by taking 
  $\bigcup\bigcup \Theta$. ›

lemma space_from_unicov: assumes "Θ {are uniform covers of} X" shows "X = Θ"
proof
  from assms show "X  Θ" using unicov_contains_triv 
    unfolding AreUniformCovers_def by auto
  from assms show "Θ  X" unfolding AreUniformCovers_def Covers_def 
    by auto
qed

text‹ Every uniform cover has a star refinement. ›

lemma unicov_has_star_ref: 
  assumes "Θ {are uniform covers of} X" and "PΘ"
  shows "QΘ. (Q <* P)"
  using assms unfolding AreUniformCovers_def by blast

text‹ In particular, every uniform cover has a barycentric refinement. ›

corollary unicov_has_bar_ref:
  assumes "Θ {are uniform covers of} X" and "PΘ"
  shows "QΘ. (Q <B P)"
proof - 
  from assms obtain Q where "QΘ" and "Q <* P" 
    using unicov_has_star_ref by blast
  with assms show ?thesis 
    unfolding AreUniformCovers_def using star_is_bary by blast
qed

text‹ From the definition of uniform covers we know that if a uniform cover $P$ 
  is a star-refinement of a cover $Q$ then $Q$ is in a uniform cover. The next lemma
  shows that in order for $Q$ to be a uniform cover it is sufficient that $P$ is a 
  barycentric refinement of $Q$. ›

lemma unicov_bary_cov: 
  assumes "Θ {are uniform covers of} X" "PΘ" "Q  Covers(X)" "P <B Q" and "X0" 
  shows "QΘ"
proof -
  from assms(1,2) obtain R where "RΘ" and "R <B P"
    using unicov_has_bar_ref by blast
  from assms(1,2,3) RΘ have 
    "P  Covers(X)" "Q  Covers(X)" "R  Covers(X)"
    unfolding AreUniformCovers_def by auto
  with assms(1,3,4,5) RΘ R <B P show ?thesis 
    using bary_bary_star unfolding AreUniformCovers_def by auto
qed

text‹ A technical lemma to simplify proof of the uniformity_from_unicov› theorem. ›

lemma star_ref_mem: assumes "UP" "P<*Q" and "{W×W. WQ}  A"
  shows "U×U  A"
proof -
  from assms(1,2) obtain W where "WQ" and "{SP. SU  0}  W"
    unfolding IsStarRefinement_def Star_def by auto
  with assms(1,3) show "U×U  A" by blast
qed

text‹An identity related to square (in the sense of composition) of a relation of the 
  form $\bigcup \{U\times U : U\in P\}$. 
  I am amazed that Isabelle can see that this is true without an explicit proof, I can't. ›

lemma rel_square_starr: shows 
  "({U×U. UP}) O ({U×U. UP}) = {U×Star(U,P). UP}"
  unfolding Star_def by blast

text‹ An identity similar to rel_square_starr› but with Star› on the left side of the Cartesian 
  product: ›

lemma rel_square_starl: shows 
  "({U×U. UP}) O ({U×U. UP}) = {Star(U,P)×U. UP}"
  unfolding Star_def by blast


text‹A somewhat technical identity about the square of a symmetric relation: ›

lemma rel_sq_image: 
  assumes "W = converse(W)"  "domain(W)  X" 
  shows "Star({x},{W``{t}. tX}) = (W O W)``{x}"
proof
  have I: "Star({x},{W``{t}. tX}) = {S{W``{t}. tX}. xS}" 
    unfolding Star_def by auto
  { fix y assume "y  Star({x},{W``{t}. tX})"
    with I obtain S where "yS" "xS" "S  {W``{t}. tX}" by auto
    from S  {W``{t}. tX} obtain t where "tX" and "S = W``{t}" 
      by auto
    with xS yS have "t,x  W" and "t,y  W" 
      by auto
    from t,x  W have "x,t  converse(W)" by auto
    with assms(1) t,y  W have "y  (W O W)``{x}" 
      using rel_compdef by auto
  } then show "Star({x},{W``{t}. tX})  (W O W)``{x}" 
    by blast
  { fix y assume "y(W O W)``{x}"
    then obtain t where "x,t  W" and "t,y  W"
      using rel_compdef by auto
    from assms(2) t,y  W have "tX" by auto
    from x,t  W have "t,x  converse(W)" by auto
    with assms(1) I t,y  W tX have "y  Star({x},{W``{t}. tX})"
      by auto
  } then show "(W O W)``{x}  Star({x},{W``{t}. tX})"
    by blast
qed

text‹ Given a family of uniform covers of $X$ we can create a uniformity on $X$ by taking the supersets
  of $\bigcup \{A\times A: A\in P \}$ as $P$ ranges over the uniform covers. The next definition
  specifies the operation creating entourages from uniform covers. ›

definition
  "UniformityFromUniCov(X,Θ)  Supersets(X×X,{{U×U. UP}. PΘ})"

text‹For any member $P$ of a cover $\Theta$ the set $\bigcup \{U\times U : U\in P\}$ 
  is a member of UniformityFromUniCov(X,Θ)›. ›

lemma basic_unif: assumes "Θ  Covers(X)" "PΘ"
  shows "{U×U. UP}  UniformityFromUniCov(X,Θ)"
  using assms unfolding UniformityFromUniCov_def Supersets_def Covers_def
  by blast

text‹If $\Theta$ is a family of uniform covers of $X$ then 
  UniformityFromUniCov(X,Θ)› is a uniformity on $X$ › 

theorem uniformity_from_unicov: 
  assumes "Θ {are uniform covers of} X" "X0"
  shows "UniformityFromUniCov(X,Θ) {is a uniformity on} X"
proof -
  let  = "UniformityFromUniCov(X,Θ)"
  have " {is a filter on} (X×X)"
  proof -
    have "0  "
    proof -
      { assume "0  "
        then obtain P where "PΘ" and "0 = {U×U. UP}"
          unfolding UniformityFromUniCov_def Supersets_def by auto
        hence "P = 0" by auto
        with assms PΘ have False unfolding AreUniformCovers_def Covers_def
          by auto
      } thus ?thesis by auto
    qed
    moreover have "X×X  "
    proof -
      from assms have "X×X  {{U×U. UP}. PΘ}" 
        using unicov_contains_triv unfolding AreUniformCovers_def 
        by auto
      then show ?thesis unfolding Supersets_def UniformityFromUniCov_def 
        by blast
    qed
    moreover have "  Pow(X×X)" 
      unfolding UniformityFromUniCov_def Supersets_def by auto
    moreover have "A.B. AB  "
    proof -
      { fix A B assume "A" "B"
        then have "AB  X×X" unfolding UniformityFromUniCov_def Supersets_def
          by auto
        from A B obtain PA PB where 
          "PAΘ" "PBΘ" and I:"{U×U. UPA}  A"  "{U×U. UPB}  B" 
          unfolding UniformityFromUniCov_def Supersets_def by auto
        from assms(1) PAΘ PBΘ obtain P 
          where "PΘ" and "P<*PA" and "P<*PB"
          unfolding AreUniformCovers_def by blast
        have "{U×U. UP}  AB"
        proof -
          { fix U assume "UP" 
            with P<*PA  P<*PB I have "U×U  A" and "U×U  B" 
              using star_ref_mem by auto
          } thus ?thesis by blast
        qed
        with AB  X×X PΘ have "AB  " 
          unfolding Supersets_def UniformityFromUniCov_def by auto
      } thus ?thesis by auto
    qed
    moreover have 
      "B.CPow(X×X). BC  C"
    proof -
      { fix B C assume "B" "CPow(X×X)" "BC"
        from B obtain PB where  "{U×U. UPB}  B" "PBΘ"
          unfolding UniformityFromUniCov_def Supersets_def by auto
        with CPow(X×X) BC have "C"
          unfolding UniformityFromUniCov_def Supersets_def by blast
      } thus ?thesis by auto
    qed
    ultimately show ?thesis unfolding IsFilter_def by simp
  qed
  moreover have "A. id(X)  A  (B. B O B  A)  converse(A)  "
  proof
    fix A assume "A"
    then obtain P where "{U×U. UP}  A" "PΘ" 
      unfolding UniformityFromUniCov_def Supersets_def by auto
    have "id(X)A"
    proof -
      from assms(1) PΘ have "P = X" unfolding AreUniformCovers_def Covers_def
        by auto
      with {U×U. UP}  A show ?thesis by auto
    qed
    moreover have "B. B O B  A"
    proof -
      from assms(1) PΘ have "{U×U. UP}  " 
        unfolding AreUniformCovers_def Covers_def UniformityFromUniCov_def Supersets_def
        by auto
      from assms(1) PΘ obtain Q where "QΘ" and  "Q <* P" using unicov_has_star_ref
        by blast
      let ?B = "{U×U. UQ}"
      from assms(1) QΘ have "?B  " 
        unfolding AreUniformCovers_def Covers_def UniformityFromUniCov_def Supersets_def
        by auto
      moreover have "?B O ?B  A"
      proof -
        have II: "?B O ?B = {U×Star(U,Q). UQ}" using rel_square_starr 
          by simp
        have "UQ. VP. U×Star(U,Q)  V×V"
        proof
          fix U assume "UQ"
          with Q <* P obtain V where "VP" and "Star(U,Q)  V"
            unfolding IsStarRefinement_def by blast
          with UQ have "VP" and "U×Star(U,Q)  V×V" using element_subset_star
            by auto
          thus "VP. U×Star(U,Q)  V×V" by auto
        qed
        hence "{U×Star(U,Q). UQ}  {V×V. VP}" by blast 
        with {V×V. VP}  A have "{U×Star(U,Q). UQ}  A" by blast
        with II show ?thesis by simp
      qed
      ultimately show ?thesis by auto
    qed
    moreover from A PΘ {U×U. UP}  A have "converse(A)  "
      unfolding AreUniformCovers_def UniformityFromUniCov_def Supersets_def 
      by auto
    ultimately show "id(X)  A  (B. B O B  A)  converse(A)  " 
      by simp
  qed
  ultimately show "  {is a uniformity on} X" unfolding IsUniformity_def 
    by simp
qed

text‹Given a uniformity $\Phi$ on $X$ we can create a family of uniform covers by taking the 
  collection of covers $P$ for which there exist an entourage $U\in \Phi$ such that 
  for each $x\in X$, there is an $A\in P$ such that $U(\{ x\}) \subseteq A$. The next definition
  specifies the operation of creating a family of uniform covers from a uniformity. ›

definition
  "UniCovFromUniformity(X,Φ)  {PCovers(X). UΦ.xX.AP. U``({x})  A}"

text‹When we convert the quantifiers into unions and intersections in the definition
  of UniCovFromUniformity› we get an alternative definition of the operation
  that creates a family of uniform covers from a uniformity. Just a curiosity, not used anywhere.›

lemma UniCovFromUniformityDef: assumes "X0"
  shows "UniCovFromUniformity(X,Φ) = (UΦ.xX. {PCovers(X). AP. U``({x})  A})"
proof -
  have "{PCovers(X). UΦ.xX.AP. U``({x})  A} = 
  (UΦ.xX. {PCovers(X). AP. U``({x})  A})"
  proof
  { fix P assume "P{PCovers(X). UΦ.xX.AP. U``({x})  A}"
    then have "PCovers(X)" and "UΦ.xX.AP. U``({x})  A" by auto
    then obtain U where "UΦ" and "xX.AP. U``({x})  A" by auto
    with assms PCovers(X) have "P  (xX. {PCovers(X). AP. U``({x})  A})" 
      by auto
    with UΦ  have "P(UΦ.xX. {PCovers(X). AP. U``({x})  A})" 
      by blast
  } then show 
    "{PCovers(X). UΦ.xX.AP. U``({x})  A}  
    (UΦ.xX. {PCovers(X). AP. U``({x})  A})"
    using subset_iff by simp
  { fix P assume "P(UΦ.xX. {PCovers(X). AP. U``({x})  A})"
    then obtain U where "UΦ" "P  (xX. {PCovers(X). AP. U``({x})  A})" 
      by auto
    with assms have "PCovers(X)" and "xX.AP. U``({x})  A" by auto
    with UΦ have "P{PCovers(X). UΦ.xX.AP. U``({x})  A}"
      by auto
  } then show "(UΦ.xX. {PCovers(X). AP. U``({x})  A})  
    {PCovers(X). UΦ.xX.AP. U``({x})  A}" by auto
  qed
  then show ?thesis unfolding UniCovFromUniformity_def by simp
qed

text‹If $\Phi$ is a (diagonal) uniformity on $X$, then covers of the form 
  $\{ W\{ x\} : x\in X\}$ are members of UniCovFromUniformity(X,Φ)›. ›

lemma cover_image: 
  assumes "Φ {is a uniformity on} X" "WΦ" 
  shows "{W``{x}. xX}  UniCovFromUniformity(X,Φ)"
proof -
  let ?P = "{W``{x}. xX}"
  have "?P  Covers(X)"
  proof -
    from assms have "W  X×X" and "?P  Pow(Pow(X))" 
      using entourage_props(1) by auto
    moreover have "?P = X"
    proof
      from W  X×X show "?P  X" by auto
      from assms show "X  ?P" using neigh_not_empty(2) by auto
    qed
    ultimately show ?thesis unfolding Covers_def by simp
  qed
  moreover from assms(2) have "WΦ. xX. A?P. W``{x}  A" 
    by auto
  ultimately show ?thesis unfolding UniCovFromUniformity_def
    by simp
qed

text‹If $\Phi$ is a (diagonal) uniformity on $X$, then every two elements 
  of  UniCovFromUniformity(X,Φ)› have a common barycentric refinement.›

lemma common_bar_refinemnt: 
  assumes 
    "Φ {is a uniformity on} X" 
    "Θ = UniCovFromUniformity(X,Φ)"
    "𝒞Θ" "𝒟Θ"
  shows "Θ.( <B 𝒞)  ( <B 𝒟)"
proof -
  from assms(2,3) obtain U where "UΦ" and I: "xX.C𝒞. U``{x}  C"
    unfolding UniCovFromUniformity_def by auto
  from assms(2,4) obtain V where "VΦ" and II: "xX.D𝒟. V``{x}  D"
    unfolding UniCovFromUniformity_def by auto    
  from assms(1) UΦ VΦ have "UV  Φ"  
    unfolding IsUniformity_def IsFilter_def by auto
  with assms(1) obtain W where "WΦ" and "W O W  UV" and "W=converse(W)"
    using half_size_symm by blast
  from assms(1) WΦ have "domain(W)  X" 
    unfolding IsUniformity_def IsFilter_def by auto
  let ?P = "{W``{t}. tX}"
  have "?PΘ" "?P <B 𝒞" "?P <B 𝒟"
  proof -
    from assms(1,2) WΦ show "?PΘ" using cover_image by simp
    with assms(2) have "?P = X" unfolding UniCovFromUniformity_def Covers_def
      by simp
    { fix x assume "xX"
      from W=converse(W) domain(W)  X W O W  UV 
      have "Star({x},?P)  U``{x}" and "Star({x},?P)  V``{x}"
        using rel_sq_image by auto
      from xX I obtain C where "C𝒞" and "U``{x}  C"
        by auto
      with Star({x},?P)  U``{x} C𝒞 have "C𝒞. Star({x},?P)  C"
        by auto
      moreover 
      from xX II obtain D where "D𝒟" and "V``{x}  D"
        by auto
      with Star({x},?P)  V``{x} D𝒟 have "D𝒟. Star({x},?P)  D"
        by auto
      ultimately have "C𝒞. Star({x},?P)  C" and "D𝒟. Star({x},?P)  D"
        by auto
    } hence "xX. C𝒞. Star({x},?P)  C" and "xX.D𝒟. Star({x},?P)  D"
      by auto 
    with ?P = X show "?P <B 𝒞" and "?P <B 𝒟"
      unfolding IsBarycentricRefinement_def by auto
  qed
  thus ?thesis by auto
qed

text‹If $\Phi$ is a (diagonal) uniformity on $X$, then every element
  of  UniCovFromUniformity(X,Φ)› has a barycentric refinement there.›

corollary bar_refinement_ex:
  assumes "Φ {is a uniformity on} X" "Θ = UniCovFromUniformity(X,Φ)" "𝒞  Θ"
  shows "Θ. ( <B 𝒞)"
  using assms common_bar_refinemnt by blast


text‹ If $\Phi$ is a (diagonal) uniformity on $X$, then UniCovFromUniformity(X,Φ)› is 
  a family of uniform covers.›

theorem unicov_from_uniformity: assumes "Φ {is a uniformity on} X" and "X0" 
  shows "UniCovFromUniformity(X,Φ) {are uniform covers of} X"
proof -
  let  = "UniCovFromUniformity(X,Φ)"
  from assms(1) have "  Covers(X)" unfolding UniCovFromUniformity_def 
    by auto
  moreover 
  from assms(1) have "{X}  "
    unfolding Covers_def IsUniformity_def IsFilter_def UniCovFromUniformity_def
    by auto
  hence "  0" by auto
  moreover have ".𝒞Covers(X). (( <* 𝒞)  𝒞)"
  proof -
    { fix  𝒞 assume "" "𝒞Covers(X)" " <* 𝒞"
      have "𝒞"
      proof -
        from  obtain U where "UΦ" and I: "xX.R. U``({x})  R"
          unfolding UniCovFromUniformity_def by auto
        { fix x assume "xX" 
          with I obtain R where "R" and "U``({x})  R" by auto
          from R  <* 𝒞 obtain C where "C𝒞" and "Star(R,)  C"
            unfolding IsStarRefinement_def by auto
          with U``({x})  R R have "U``({x})  C" 
            using element_subset_star by blast
          with C𝒞 have "C𝒞. U``({x})  C" by auto
        } hence "xX.C𝒞. U``({x})  C" by auto
        with UΦ 𝒞Covers(X) show ?thesis unfolding UniCovFromUniformity_def
          by auto
      qed
    } thus ?thesis by auto
  qed
  moreover have "𝒞.𝒟..( <* 𝒞)  ( <* 𝒟)"
  proof -
    { fix 𝒞 𝒟 assume "𝒞" "𝒟" 
      with assms(1) obtain P where "P" and "P <B 𝒞" "P <B 𝒟"
        using common_bar_refinemnt by blast
      from assms(1) P obtain  where "" and " <B P"
        using bar_refinement_ex by blast
      from  P 𝒞 𝒟 have 
        "P  Covers(X)" "  Covers(X)" "𝒞  Covers(X)" "𝒟  Covers(X)"
        unfolding UniCovFromUniformity_def by auto
      with assms(2)  <B P P <B 𝒞 P <B 𝒟 have " <* 𝒞" and " <* 𝒟" 
        using bary_bary_star by auto
      with  have ".( <* 𝒞)  ( <* 𝒟)" by auto
    } thus ?thesis by simp
  qed
  ultimately show ?thesis unfolding AreUniformCovers_def by simp
qed

text‹ The UniCovFromUniformity› operation is the inverse of UniformityFromUniCov›. ›

theorem unicov_from_unif_inv: assumes "Θ {are uniform covers of} X" "X0"
  shows "UniCovFromUniformity(X,UniformityFromUniCov(X,Θ)) = Θ"
proof
  let  = "UniformityFromUniCov(X,Θ)"
  let ?L = "UniCovFromUniformity(X,)"
  from assms have I: " {is a uniformity on} X" 
    using uniformity_from_unicov by simp
  with assms(2) have II: "?L {are uniform covers of} X" 
    using unicov_from_uniformity by simp
  { fix P assume "P?L"
    with I obtain Q where "Q?L" and "Q <B P" 
      using bar_refinement_ex by blast
    from Q?L obtain U where "U" and III:"xX.AQ. U``{x}  A"
      unfolding UniCovFromUniformity_def by auto
    from U have "U  Supersets(X×X,{{U×U. UP}. PΘ})"
      unfolding UniformityFromUniCov_def by simp
    then obtain B where "BX×X" "BU" and "C{{U×U. UP}. PΘ}. CB" 
      unfolding Supersets_def by auto
    then obtain C where "C  {{U×U. UP}. PΘ}" and "CB" by auto
    then obtain R where "RΘ" and "C = {V×V. VR}" by auto
    with CB BU have "{V×V. VR}  U" by auto
    from assms(1) II P?L Q?L RΘ have
      IV: "PCovers(X)" "QCovers(X)" "RCovers(X)"
      unfolding AreUniformCovers_def by auto
    have "R <B Q"
    proof -
      { fix x assume "xX"
        with III obtain A where "AQ" and "U``{x}  A" by auto
        with {V×V. VR}  U have "({V×V. VR})``{x}  A"
          by auto
        with AQ have "AQ. Star({x},R)  A" using star_singleton by auto
      } then have "xX. AQ. Star({x},R)  A" by simp
      moreover from RCovers(X) have "R = X" unfolding Covers_def
        by simp
      ultimately show ?thesis unfolding IsBarycentricRefinement_def
        by simp
    qed
    with assms(2) Q <B P IV have "R <* P" using bary_bary_star by simp
    with assms(1) RΘ PCovers(X) have "PΘ" 
      unfolding AreUniformCovers_def by simp
  } thus "?LΘ" by auto
  { fix P assume "PΘ"
    with assms(1) have "P  Covers(X)" 
      unfolding AreUniformCovers_def by auto
    from assms(1) PΘ obtain Q where "Q  Θ" and "Q <B P" 
      using unicov_has_bar_ref by blast
    let ?A = "{V×V. VQ}"
    have "?A  " 
    proof -
      from assms(1) QΘ have "?A  X×X" and "?A  {{V×V. VQ}. QΘ}"
        unfolding AreUniformCovers_def Covers_def by auto 
      then show ?thesis 
        using superset_gen unfolding UniformityFromUniCov_def 
        by auto
    qed
    with I obtain B where "B" "B O B  ?A" and "B=converse(B)"
      using half_size_symm by blast
    let ?R = "{B``{x}. xX}"
    from I II B have "?R?L" and "?R =X"
      using cover_image unfolding UniCovFromUniformity_def Covers_def
      by auto
    have "?R <B P"
    proof -
      { fix x assume "xX"
        from assms(1) Q  Θ have "Q = X" 
          unfolding AreUniformCovers_def Covers_def by auto
        with Q <B P xX obtain C where "CP" and "Star({x},Q)  C"
          unfolding IsBarycentricRefinement_def by auto
        from B=converse(B) I B have "Star({x},?R) = (B O B)``{x}"
          using  uni_domain rel_sq_image by auto
        moreover from  (B O B)  ?A have "(B O B)``{x}  ?A``{x}" by blast
        moreover have "?A``{x} = Star({x},Q)" using star_singleton by simp
        ultimately have "Star({x},?R)  Star({x},Q)" by auto
        with Star({x},Q)  C CP have "CP. Star({x},?R)  C"
          by auto
      } with ?R = X show ?thesis unfolding IsBarycentricRefinement_def
        by auto
    qed
    with assms(2) II P  Covers(X) ?R?L ?R <B P have "P?L" 
       using unicov_bary_cov by simp
  } thus "Θ?L" by auto
qed

text‹The UniformityFromUniCov› operation is the inverse of UniCovFromUniformity›. ›

theorem unif_from_unicov_inv: assumes "Φ {is a uniformity on} X" "X0"
  shows "UniformityFromUniCov(X,UniCovFromUniformity(X,Φ)) = Φ"
proof 
  let  = "UniCovFromUniformity(X,Φ)"
  let ?L = "UniformityFromUniCov(X,)"
  from assms have I: " {are uniform covers of} X"
    using unicov_from_uniformity by simp
  with assms have II: "?L {is a uniformity on} X" 
    using uniformity_from_unicov by simp
  { fix A assume "AΦ"
    with assms(1) obtain B where "BΦ" "B O B  A" and "B = converse(B)"
      using half_size_symm by blast
    from assms(1) AΦ have "A  X×X" using uni_domain(1)
      by simp
    let ?P = "{B``{x}. xX}"
    from assms(1) BΦ have "?P" using cover_image
      by simp
    let ?C = "{U×U. U?P}"
    from I ?P have "?C?L" 
      unfolding AreUniformCovers_def using basic_unif by blast  
    from assms(1) BΦ B = converse(B) B O B  A have "?C  A" 
      using uni_domain(2) symm_sq_prod_image by simp
    with II A  X×X ?C?L have "A?L"
      unfolding IsUniformity_def IsFilter_def by simp
  } thus "Φ?L" by auto
  { fix A assume "A?L" 
    with II have "A  X×X" using entourage_props(1) by simp
    from A?L obtain P where "P" and "{U×U. UP}  A"
      unfolding UniformityFromUniCov_def Supersets_def by blast
    from P obtain B where "BΦ" and III: "xX. VP. B``{x}  V"
      unfolding UniCovFromUniformity_def by auto
    have "BA"
    proof -
      from assms(1) BΦ have "B  {B``{x}×B``{x}. xX}"
        using entourage_props(1,2) refl_union_singl_image by simp
      moreover have "{B``{x}×B``{x}. xX}  A"
      proof -
        { fix x assume "xX"
          with III obtain V where "VP" and "B``{x}  V" by auto
          hence "B``{x}×B``{x}  {U×U. UP}" by auto
        } hence "{B``{x}×B``{x}. xX}  {U×U. UP}" by blast
        with {U×U. UP}  A show ?thesis by blast
      qed
      ultimately show ?thesis by auto
    qed
    with assms(1) BΦ A  X×X have "AΦ"
      unfolding IsUniformity_def IsFilter_def by simp
  } thus "?LΦ" by auto
qed

end