Theory Topology_ZF_11

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

    Copyright (C) 2013 Daniel de la Concepcion

    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 Topology 11

theory Topology_ZF_11 imports Topology_ZF_7 Finite_ZF_1

begin

textThis file deals with order topologies. The order topology
is already defined in @{file "Topology_ZF_examples_1.thy"}.

subsectionOrder topologies

textWe will assume
most of the time that the ordered set has more than one point.
It is natural to think that the topological properties
can be translated to properties of the order; since every
order rises one and only one topology in a set.

subsectionSeparation properties

textOrder topologies have a lot of separation properties.

textEvery order topology is Hausdorff.

theorem order_top_T2:
  assumes "IsLinOrder(X,r)" "x y. xyxXyX"
  shows "(OrdTopology X r){is T2}"
proof-
  {
    fix x y assume A1:"x(OrdTopology X r)""y(OrdTopology X r)""xy"
    then have AS:"xX""yX""xy" using union_ordtopology[OF assms(1) assms(2)] by auto
    {
      assume A2:"zX-{x,y}. (x,yrx,zrz,yr)(y,xry,zrz,xr)"
      from AS(1,2) assms(1) have "x,yry,xr" unfolding IsLinOrder_def IsTotal_def by auto moreover
      {
        assume "x,yr"
        with AS A2 obtain z where z:"x,zr""z,yr""zX""zx""zy" by auto
        with AS(1,2) have "xLeftRayX(X,r,z)""yRightRayX(X,r,z)" unfolding LeftRayX_def RightRayX_def
          by auto moreover
        have "LeftRayX(X,r,z)RightRayX(X,r,z)=0" using inter_lray_rray[OF z(3) z(3) assms(1)]
          unfolding IntervalX_def using Order_ZF_2_L4[OF total_is_refl _ z(3)] assms(1) unfolding IsLinOrder_def
          by auto moreover
        have "LeftRayX(X,r,z)(OrdTopology X r)""RightRayX(X,r,z)(OrdTopology X r)"
          using z(3) base_sets_open[OF Ordtopology_is_a_topology(2)[OF assms(1)]] by auto
        ultimately have "U(OrdTopology X r). V(OrdTopology X r). xU  yV  UV=0" by auto
      }
      moreover
      {
        assume "y,xr"
        with AS A2 obtain z where z:"y,zr""z,xr""zX""zx""zy" by auto
        with AS(1,2) have "yLeftRayX(X,r,z)""xRightRayX(X,r,z)" unfolding LeftRayX_def RightRayX_def
          by auto moreover
        have "LeftRayX(X,r,z)RightRayX(X,r,z)=0" using inter_lray_rray[OF z(3) z(3) assms(1)]
          unfolding IntervalX_def using Order_ZF_2_L4[OF total_is_refl _ z(3)] assms(1) unfolding IsLinOrder_def
          by auto moreover
        have "LeftRayX(X,r,z)(OrdTopology X r)""RightRayX(X,r,z)(OrdTopology X r)"
          using z(3) base_sets_open[OF Ordtopology_is_a_topology(2)[OF assms(1)]] by auto
        ultimately have "U(OrdTopology X r). V(OrdTopology X r). xU  yV  UV=0" by auto
      }
      ultimately have "U(OrdTopology X r). V(OrdTopology X r). xU  yV  UV=0" by auto
    }
    moreover
    {
      assume A2:"zX - {x, y}. (x, y  r  (x, z  r  z, y  r))  (y, x  r  (y, z  r  z, x  r))"
      from AS(1,2) assms(1) have disj:"x,yry,xr" unfolding IsLinOrder_def IsTotal_def by auto moreover
      {
        assume TT:"x,yr"
        with AS assms(1) have T:"y,xr" unfolding IsLinOrder_def antisym_def by auto
        from TT AS(1-3) have "xLeftRayX(X,r,y)""yRightRayX(X,r,x)" unfolding LeftRayX_def RightRayX_def
          by auto moreover
        {
          fix z assume "zLeftRayX(X,r,y)RightRayX(X,r,x)"
          then have "z,yr""x,zr""zX-{x,y}" unfolding RightRayX_def LeftRayX_def by auto
          with A2 T have "False" by auto
        }
        then have "LeftRayX(X,r,y)RightRayX(X,r,x)=0" by auto moreover
        have "LeftRayX(X,r,y)(OrdTopology X r)""RightRayX(X,r,x)(OrdTopology X r)"
          using base_sets_open[OF Ordtopology_is_a_topology(2)[OF assms(1)]] AS by auto
        ultimately have "U(OrdTopology X r). V(OrdTopology X r). xU  yV  UV=0" by auto
      }
      moreover
      {
        assume TT:"y,xr"
        with AS assms(1) have T:"x,yr" unfolding IsLinOrder_def antisym_def by auto
        from TT AS(1-3) have "yLeftRayX(X,r,x)""xRightRayX(X,r,y)" unfolding LeftRayX_def RightRayX_def
          by auto moreover
        {
          fix z assume "zLeftRayX(X,r,x)RightRayX(X,r,y)"
          then have "z,xr""y,zr""zX-{x,y}" unfolding RightRayX_def LeftRayX_def by auto
          with A2 T have "False" by auto
        }
        then have "LeftRayX(X,r,x)RightRayX(X,r,y)=0" by auto moreover
        have "LeftRayX(X,r,x)(OrdTopology X r)""RightRayX(X,r,y)(OrdTopology X r)"
          using base_sets_open[OF Ordtopology_is_a_topology(2)[OF assms(1)]] AS by auto
        ultimately have "U(OrdTopology X r). V(OrdTopology X r). xU  yV  UV=0" by auto
      }
      ultimately have "U(OrdTopology X r). V(OrdTopology X r). xU  yV  UV=0" by auto
    }
    ultimately have "U(OrdTopology X r). V(OrdTopology X r). xU  yV  UV=0" by auto
  }
  then show ?thesis unfolding isT2_def by auto
qed

textEvery order topology is $T_4$, but the proof needs lots of machinery.
At the end of the file, we will prove that every order topology is normal; sooner
or later.

subsectionConnectedness properties

textConnectedness is related to two properties of orders: completeness and density

textSome order-dense properties:

definition
  IsDenseSub ("_ {is dense in}_{with respect to}_") where
  "A {is dense in}X{with respect to}r  
  xX. yX. x,yr  xy   (zA-{x,y}. x,zrz,yr)"

definition
  IsDenseUnp ("_ {is not-properly dense in}_{with respect to}_") where
  "A {is not-properly dense in}X{with respect to}r  
  xX. yX. x,yr  xy   (zA. x,zrz,yr)"

definition
  IsWeaklyDenseSub ("_ {is weakly dense in}_{with respect to}_") where
  "A {is weakly dense in}X{with respect to}r  
  xX. yX. x,yr  xy   ((zA-{x,y}. x,zrz,yr) IntervalX(X,r,x,y)=0)"

definition
  IsDense ("_ {is dense with respect to}_") where
  "X {is dense with respect to}r  
  xX. yX. x,yr  xy   (zX-{x,y}. x,zrz,yr)"

lemma dense_sub:
  shows "(X {is dense with respect to}r)  (X {is dense in}X{with respect to}r)"
  unfolding IsDenseSub_def IsDense_def by auto

lemma not_prop_dense_sub:
  shows "(A {is dense in}X{with respect to}r)  (A {is not-properly dense in}X{with respect to}r)"
  unfolding IsDenseSub_def IsDenseUnp_def by auto

textIn densely ordered sets, intervals are infinite.

theorem dense_order_inf_intervals:
  assumes "IsLinOrder(X,r)" "IntervalX(X, r, b, c)0""bX""cX" "X{is dense with respect to}r"
  shows "¬Finite(IntervalX(X, r, b, c))"
proof
  assume fin:"Finite(IntervalX(X, r, b, c))"
  have sub:"IntervalX(X, r, b, c)X" unfolding IntervalX_def by auto
  have p:"Minimum(r,IntervalX(X, r, b, c))IntervalX(X, r, b, c)" using Finite_ZF_1_T2(2)[OF assms(1) Finite_Fin[OF fin sub] assms(2)]
    by auto
  then have "b,Minimum(r,IntervalX(X, r, b, c))r""bMinimum(r,IntervalX(X, r, b, c))"
    unfolding IntervalX_def using Order_ZF_2_L1 by auto
  with assms(3,5) sub p obtain z1 where z1:"z1X""z1b""z1Minimum(r,IntervalX(X, r, b, c))""b,z1r""z1,Minimum(r,IntervalX(X, r, b, c))r"
    unfolding IsDense_def by blast
  from p have B:"Minimum(r,IntervalX(X, r, b, c)),cr" unfolding IntervalX_def using Order_ZF_2_L1 by auto moreover
  have "trans(r)" using assms(1) unfolding IsLinOrder_def by auto moreover
  note z1(5) ultimately have z1a:"z1,cr" unfolding trans_def by fast
  {
    assume "z1=c"
    with B have "Minimum(r,IntervalX(X, r, b, c)),z1r" by auto
    with z1(5) have "z1=Minimum(r,IntervalX(X, r, b, c))" using assms(1) unfolding IsLinOrder_def antisym_def by auto
    then have "False" using z1(3) by auto
  }
  then have "z1c" by auto
  with z1(1,2,4) z1a have "z1IntervalX(X, r, b, c)" unfolding IntervalX_def using Order_ZF_2_L1 by auto
  then have "Minimum(r,IntervalX(X, r, b, c)),z1r" using Finite_ZF_1_T2(4)[OF assms(1) Finite_Fin[OF fin sub] assms(2)] by auto
  with z1(5) have "z1=Minimum(r,IntervalX(X, r, b, c))" using assms(1) unfolding IsLinOrder_def antisym_def by auto
  with z1(3) show "False" by auto
qed

textLeft rays are infinite.

theorem dense_order_inf_lrays:
  assumes "IsLinOrder(X,r)" "LeftRayX(X,r,c)0""cX"  "X{is dense with respect to}r"
  shows "¬Finite(LeftRayX(X,r,c))"
proof-
  from assms(2) obtain b where "bX""b,cr""bc" unfolding LeftRayX_def by auto
  with assms(3) obtain z where "zX-{b,c}""b,zr""z,cr" using assms(4) unfolding IsDense_def by auto
  then have "IntervalX(X, r, b, c)0" unfolding IntervalX_def using Order_ZF_2_L1 by auto
  then have nFIN:"¬Finite(IntervalX(X, r, b, c))" using dense_order_inf_intervals[OF assms(1) _ _ assms(3,4)]
    bX by auto
  {
    fix d assume "dIntervalX(X, r, b, c)"
    then have "b,dr""d,cr""dX""db""dc" unfolding IntervalX_def using Order_ZF_2_L1 by auto
    then have "dLeftRayX(X,r,c)" unfolding LeftRayX_def by auto
  }
  then have "IntervalX(X, r, b, c)LeftRayX(X,r,c)" by auto
  with nFIN show ?thesis using subset_Finite by auto
qed

textRight rays are infinite.

theorem dense_order_inf_rrays:
  assumes "IsLinOrder(X,r)" "RightRayX(X,r,b)0""bX"  "X{is dense with respect to}r"
  shows "¬Finite(RightRayX(X,r,b))"
proof-
  from assms(2) obtain c where "cX""b,cr""bc" unfolding RightRayX_def by auto
  with assms(3) obtain z where "zX-{b,c}""b,zr""z,cr" using assms(4) unfolding IsDense_def by auto
  then have "IntervalX(X, r, b, c)0" unfolding IntervalX_def using Order_ZF_2_L1 by auto
  then have nFIN:"¬Finite(IntervalX(X, r, b, c))" using dense_order_inf_intervals[OF assms(1) _ assms(3) _ assms(4)]
    cX by auto
  {
    fix d assume "dIntervalX(X, r, b, c)"
    then have "b,dr""d,cr""dX""db""dc" unfolding IntervalX_def using Order_ZF_2_L1 by auto
    then have "dRightRayX(X,r,b)" unfolding RightRayX_def by auto
  }
  then have "IntervalX(X, r, b, c)RightRayX(X,r,b)" by auto
  with nFIN show ?thesis using subset_Finite by auto
qed

textThe whole space in a densely ordered set is infinite.

corollary dense_order_infinite:
  assumes "IsLinOrder(X,r)"  "X{is dense with respect to}r"
    "x y. xyxXyX"
  shows "¬(Xnat)"
proof-
  from assms(3) obtain b c where B:"bX""cX""bc" by auto
  {
    assume "b,cr"
    with assms(1) have "c,br" unfolding IsLinOrder_def IsTotal_def using bXcX by auto
    with assms(2) B obtain z where "zX-{b,c}""c,zr""z,br" unfolding IsDense_def by auto
    then have "IntervalX(X,r,c,b)0" unfolding IntervalX_def using Order_ZF_2_L1 by auto
    then have "¬(Finite(IntervalX(X,r,c,b)))" using dense_order_inf_intervals[OF assms(1) _ cXbX assms(2)]
      by auto moreover
    have "IntervalX(X,r,c,b)X" unfolding IntervalX_def by auto
    ultimately have "¬(Finite(X))" using subset_Finite by auto
    then have "¬(Xnat)" using lesspoll_nat_is_Finite by auto
  }
  moreover
  {
    assume "b,cr"
    with assms(2) B obtain z where "zX-{b,c}""b,zr""z,cr" unfolding IsDense_def by auto
    then have "IntervalX(X,r,b,c)0" unfolding IntervalX_def using Order_ZF_2_L1 by auto
    then have "¬(Finite(IntervalX(X,r,b,c)))" using dense_order_inf_intervals[OF assms(1) _ bXcX assms(2)]
      by auto moreover
    have "IntervalX(X,r,b,c)X" unfolding IntervalX_def by auto
    ultimately have "¬(Finite(X))" using subset_Finite by auto
    then have "¬(Xnat)" using lesspoll_nat_is_Finite by auto
  }
  ultimately show ?thesis by auto
qed

textIf an order topology is connected, then the order is complete.
It is equivalent to assume that $r\subseteq X\times X$ or prove that
$r\cap X\times X$ is complete.

theorem conn_imp_complete:
  assumes "IsLinOrder(X,r)" "x y. xyxXyX" "rX×X"
     "(OrdTopology X r){is connected}"
  shows "r{is complete}"
proof-
  {
    assume "¬(r{is complete})"
    then obtain A where A:"A0""IsBoundedAbove(A,r)""¬(HasAminimum(r, bA. r `` {b}))" unfolding
      IsComplete_def by auto
    from A(3) have r1:"mbA. r `` {b}. xbA. r `` {b}. m,xr" unfolding HasAminimum_def
      by force
    from A(1,2) obtain b where r2:"xA. x, b  r" unfolding IsBoundedAbove_def by auto
    with assms(3) A(1) have "AX""bX" by auto
    with assms(3) have r3:"cA. r `` {c}X" using image_iff by auto
    from r2 have "xA. br``{x}" using image_iff by auto
    then have noE:"b(bA. r `` {b})" using A(1) by auto
    {
      fix x assume "x(bA. r `` {b})"
      then have "cA. xr``{c}" by auto
      with A(1) obtain c where "cA" "xr``{c}" by auto
      with r3 have "xX" by auto
    }
    then have sub:"(bA. r `` {b})X" by auto
    {
      fix x assume x:"x(bA. r `` {b})"
      with r1 have "zbA. r `` {b}. x,zr" by auto
      then obtain z where z:"z(bA. r `` {b})""x,zr" by auto
      from x z(1) sub have "xX""zX" by auto
      with z(2) have "z,xr" using assms(1) unfolding IsLinOrder_def IsTotal_def by auto
      then have xx:"xRightRayX(X,r,z)" unfolding RightRayX_def using xXx,zr
        assms(1) unfolding IsLinOrder_def using total_is_refl unfolding refl_def by auto
      {
        fix m assume "mRightRayX(X,r,z)"
        then have m:"mX-{z}""z,mr" unfolding RightRayX_def by auto
        {
          fix c assume "cA"
          with z(1) have "c,zr" using image_iff by auto
          with m(2) have "c,mr" using assms(1) unfolding IsLinOrder_def trans_def by fast
          then have "mr``{c}" using image_iff by auto
        }
        with A(1) have "m(bA. r `` {b})" by auto
      }
      then have sub1:"RightRayX(X,r,z)(bA. r `` {b})" by auto
      have "RightRayX(X,r,z)(OrdTopology X r)" using 
        base_sets_open[OF Ordtopology_is_a_topology(2)[OF assms(1)]] zX by auto
      with sub1 xx have "U(OrdTopology X r). xU  U(bA. r `` {b})" by auto
    }
    then have "(bA. r `` {b})(OrdTopology X r)" using topology0.open_neigh_open[OF topology0_ordtopology[OF assms(1)]]
      by auto moreover
    {
      fix x assume "xX-(bA. r `` {b})"
      then have "xX""x(bA. r `` {b})" by auto
      with A(1) obtain b where "xr``{b}""bA" by auto
      then have "b,xr" using image_iff by auto
      with AX bAxX have "x,br" using assms(1) unfolding IsLinOrder_def
        IsTotal_def by auto
      then have xx:"xLeftRayX(X,r,b)" unfolding LeftRayX_def using xX b,xr
        assms(1) unfolding IsLinOrder_def using total_is_refl unfolding refl_def by auto
      {
        fix y assume "yLeftRayX(X,r,b)(bA. r `` {b})"
        then have "yX-{b}""y,br""cA. yr``{c}" unfolding LeftRayX_def by auto
        then have "yX""y,br""cA. c,yr" using image_iff by auto
        with bA have "y=b" using assms(1) unfolding IsLinOrder_def antisym_def by auto
        then have "False" using yX-{b} by auto
      }
      then have sub1:"LeftRayX(X,r,b)X-(bA. r `` {b})" unfolding LeftRayX_def by auto
      have "LeftRayX(X,r,b)(OrdTopology X r)" using 
        base_sets_open[OF Ordtopology_is_a_topology(2)[OF assms(1)]] bAAX by blast
      with sub1 xx have "U(OrdTopology X r). xUUX-(bA. r `` {b})" by auto
    }
    then have "X - (bA. r `` {b})(OrdTopology X r)" using topology0.open_neigh_open[OF topology0_ordtopology[OF assms(1)]]
      by auto
    then have "(OrdTopology X r)-(bA. r `` {b})(OrdTopology X r)" using union_ordtopology[OF assms(1,2)] by auto
    then have "(bA. r `` {b}){is closed in}(OrdTopology X r)" unfolding IsClosed_def using union_ordtopology[OF assms(1,2)]
      sub by auto
    moreover note assms(4) ultimately
    have "(bA. r `` {b})=0(bA. r `` {b})=X" using union_ordtopology[OF assms(1,2)] unfolding IsConnected_def
      by auto
    then have e1:"(bA. r `` {b})=X" using noE by auto
    then have "xX. bA. xr``{b}" by auto
    then have r4:"xX. bA. b,xr" using image_iff by auto
    {
      fix a1 a2 assume aA:"a1A""a2A""a1a2"
      with AX have aX:"a1X""a2X" by auto
      with r4 aA(1,2) have "a1,a2r""a2,a1r" by auto
      then have "a1=a2" using assms(1) unfolding IsLinOrder_def antisym_def by auto
      with aA(3) have "False" by auto
    }
    moreover
    from A(1) obtain t where "tA" by auto
    ultimately have "A={t}" by auto
    with r4 have "xX. t,xr""tX" using AX by auto
    then have "HasAminimum(r,X)" unfolding HasAminimum_def by auto
    with e1 have "HasAminimum(r,bA. r `` {b})" by auto
    with A(3) have "False" by auto
  }
  then show ?thesis by auto
qed

textIf an order topology is connected, then the order is dense.

theorem conn_imp_dense:
  assumes "IsLinOrder(X,r)" "x y. xyxXyX"
     "(OrdTopology X r){is connected}"
  shows "X {is dense with respect to}r"
proof-
  {
    assume "¬(X {is dense with respect to}r)"
    then have "x1X. x2X. x1,x2rx1x2(zX-{x1,x2}. x1,zrz,x2r)"
      unfolding IsDense_def by auto
    then obtain x1 x2 where x:"x1X""x2X""x1,x2r""x1x2""(zX-{x1,x2}. x1,zrz,x2r)" by auto
    from x(1,2) have P:"LeftRayX(X,r,x2)(OrdTopology X r)""RightRayX(X,r,x1)(OrdTopology X r)"
      using  base_sets_open[OF Ordtopology_is_a_topology(2)[OF assms(1)]] by auto
    {
      fix x assume "xX-LeftRayX(X,r,x2)"
      then have "xX" "xLeftRayX(X,r,x2)" by auto
      then have "x,x2rx=x2" unfolding LeftRayX_def by auto
      then have "x2,xrx=x2" using assms(1) xX x2X unfolding IsLinOrder_def
        IsTotal_def by auto
      then have s:"x2,xr" using assms(1) unfolding IsLinOrder_def using total_is_refl x2X
        unfolding refl_def by auto
      with x(3) have "x1,xr" using assms(1) unfolding IsLinOrder_def trans_def by fast
      then have "x=x1xRightRayX(X,r,x1)" unfolding RightRayX_def using xX by auto
      with s have "x2,x1rxRightRayX(X,r,x1)" by auto
      with x(3) have "x1=x2  xRightRayX(X,r,x1)" using assms(1) unfolding IsLinOrder_def
        antisym_def by auto
      with x(4) have "xRightRayX(X,r,x1)" by auto
    }
    then have "X-LeftRayX(X,r,x2)RightRayX(X,r,x1)" by auto moreover
    {
      fix x assume "xRightRayX(X,r,x1)"
      then have xr:"xX-{x1}""x1,xr" unfolding RightRayX_def by auto
      {
        assume "xLeftRayX(X,r,x2)"
        then have xl:"xX-{x2}""x,x2r" unfolding LeftRayX_def by auto
        from xl xr x(5) have "False" by auto
      }
      with xr(1) have "xX-LeftRayX(X,r,x2)" by auto
    }
    ultimately have "RightRayX(X,r,x1)=X-LeftRayX(X,r,x2)" by auto
    then have "LeftRayX(X,r,x2){is closed in}(OrdTopology X r)" using P(2) union_ordtopology[
      OF assms(1,2)] unfolding IsClosed_def LeftRayX_def by auto
    with P(1) have "LeftRayX(X,r,x2)=0LeftRayX(X,r,x2)=X" using union_ordtopology[
      OF assms(1,2)] assms(3) unfolding IsConnected_def by auto
    with x(1,3,4) have "LeftRayX(X,r,x2)=X" unfolding LeftRayX_def by auto
    then have "x2LeftRayX(X,r,x2)" using x(2) by auto
    then have "False" unfolding LeftRayX_def by auto
  }
  then show ?thesis by auto
qed

textActually a connected order topology is one that comes from a dense
and complete order.

textFirst a lemma. In a complete ordered set, every non-empty set bounded from below has
a maximum lower bound.

lemma complete_order_bounded_below:
  assumes "r{is complete}" "IsBoundedBelow(A,r)" "A0" "rX×X"
  shows "HasAmaximum(r,cA. r-``{c})"
proof-
  let ?M="cA. r-``{c}"
  from assms(3) obtain t where A:"tA" by auto
  {
    fix m assume "m?M"
    with A have "mr-``{t}" by auto
    then have "m,tr" by auto
  }
  then have "(xcA. r -`` {c}. x, t  r)" by auto
  then have "IsBoundedAbove(?M,r)" unfolding IsBoundedAbove_def by auto
  moreover
  from assms(2,3) obtain l where " xA. l, x  r" unfolding IsBoundedBelow_def by auto
  then have "xA. l  r-``{x}" using vimage_iff by auto
  with assms(3) have "l?M" by auto
  then have "?M0" by auto moreover note assms(1)
  ultimately have "HasAminimum(r,c?M. r `` {c})" unfolding IsComplete_def by auto
  then obtain rr where rr:"rr(c?M. r `` {c})" "s(c?M. r `` {c}). rr,sr" unfolding HasAminimum_def
    by auto
  {
    fix aa assume A:"aaA"
    {
      fix c assume M:"c?M"
      with A have "c,aar" by auto
      then have "aar``{c}" by auto
    }
    then have "aa(c?M. r `` {c})" using rr(1) by auto
  }
  then have "A(c?M. r `` {c})" by auto
  with rr(2) have "sA. rr,sr" by auto
  then have "rr?M" using assms(3) by auto
  moreover
  {
    fix m assume "m?M"
    then have "rrr``{m}" using rr(1) by auto
    then have "m,rrr" by auto
  }
  then have "m?M. m,rrr" by auto
  ultimately show ?thesis unfolding HasAmaximum_def by auto
qed 

theorem comp_dense_imp_conn:
  assumes "IsLinOrder(X,r)" "x y. xyxXyX" "rX×X"
     "X {is dense with respect to}r" "r{is complete}"
  shows "(OrdTopology X r){is connected}"
proof-
  {
    assume "¬((OrdTopology X r){is connected})"
    then obtain U where U:"U0""UX""U(OrdTopology X r)""U{is closed in}(OrdTopology X r)"
      unfolding IsConnected_def using union_ordtopology[OF assms(1,2)] by auto
    from U(4) have A:"X-U(OrdTopology X r)""UX" unfolding IsClosed_def using union_ordtopology[OF assms(1,2)] by auto
    from U(1) obtain u where "uU" by auto
    from A(2) U(1,2) have "X-U0" by auto
    then obtain v where "vX-U" by auto
    with uU UX have "u,vrv,ur" using assms(1) unfolding IsLinOrder_def IsTotal_def
      by auto
    {
      assume "u,vr"
      have "LeftRayX(X,r,v)(OrdTopology X r)" using base_sets_open[OF Ordtopology_is_a_topology(2)[OF assms(1)]]
        vX-U by auto
      then have "ULeftRayX(X,r,v)(OrdTopology X r)" using U(3) using Ordtopology_is_a_topology(1)
        [OF assms(1)] unfolding IsATopology_def by auto
      {
        fix b assume "b(U)LeftRayX(X,r,v)"
        then have "b,vr" unfolding LeftRayX_def by auto
      }
      then have bound:"IsBoundedAbove(ULeftRayX(X,r,v),r)" unfolding IsBoundedAbove_def by auto moreover
      with u,vruUUXvX-U have nE:"ULeftRayX(X,r,v)0" unfolding LeftRayX_def by auto
      ultimately have Hmin:"HasAminimum(r,cULeftRayX(X,r,v). r``{c})" using assms(5) unfolding IsComplete_def
        by auto
      let ?min="Supremum(r,ULeftRayX(X,r,v))"
      {
        fix c assume "cULeftRayX(X,r,v)"
        then have "c,vr" unfolding LeftRayX_def by auto
      }
      then have a1:"?min,vr" using Order_ZF_5_L3[OF _ nE Hmin] assms(1) unfolding IsLinOrder_def
        by auto
      {
        assume ass:"?minU"
        then obtain V where V:"?minV""VU"
          "V{IntervalX(X,r,b,c). b,cX×X}{LeftRayX(X,r,b). bX}{RightRayX(X,r,b). bX}" using point_open_base_neigh
          [OF Ordtopology_is_a_topology(2)[OF assms(1)] U(OrdTopology X r) ass] by blast
        {
          assume "V{RightRayX(X,r,b). bX}"
          then obtain b where b:"bX" "V=RightRayX(X,r,b)" by auto
          note a1 moreover
          from V(1) b(2) have a2:"b,?minr""?minb" unfolding RightRayX_def by auto
          ultimately have "b,vr" using assms(1) unfolding IsLinOrder_def trans_def by blast moreover
          {
            assume "b=v"
            with a1 a2(1) have "b=?min" using assms(1) unfolding IsLinOrder_def antisym_def by auto
            with a2(2) have "False" by auto
          }
          ultimately have "False" using V(2) b(2) unfolding RightRayX_def using vX-U by auto
        }
        moreover
        {
          assume "V{LeftRayX(X,r,b). bX}"
          then obtain b where b:"V=LeftRayX(X,r,b)" "bX" by auto
          {
            assume "v,br"
            then have "b=vvLeftRayX(X,r,b)" unfolding LeftRayX_def using vX-U by auto
            then have "b=v" using b(1) V(2) vX-U by auto
          }
          then have bv:"b,vr" using assms(1) unfolding IsLinOrder_def IsTotal_def using b(2)
            vX-U by auto
          from b(1) V(1) have "?min,br""?minb" unfolding LeftRayX_def by auto
          with assms(4) obtain z where z:"?min,zr""z,br""zX-{b,?min}" unfolding IsDense_def
            using b(2) V(1,2) UX by blast
          then have rayb:"zLeftRayX(X,r,b)" unfolding LeftRayX_def by auto
          from z(2) bv have "z,vr" using assms(1) unfolding IsLinOrder_def trans_def by fast
          moreover
          {
            assume "z=v"
            with bv have "b,zr" by auto
            with z(2) have "b=z" using assms(1) unfolding IsLinOrder_def antisym_def by auto
            then have "False" using z(3) by auto
          }
          ultimately have "zLeftRayX(X,r,v)" unfolding LeftRayX_def using z(3) by auto
          with rayb have "zULeftRayX(X,r,v)" using V(2) b(1) by auto
          then have "?minr``{z}" using Order_ZF_4_L4(1)[OF _ Hmin] assms(1) unfolding Supremum_def IsLinOrder_def
            by auto
          then have "z,?minr" by auto
          with z(1,3) have "False" using assms(1) unfolding IsLinOrder_def antisym_def by auto
        }
        moreover
        {
          assume "V{IntervalX(X,r,b,c). b,cX×X}"
          then obtain b c where b:"V=IntervalX(X,r,b,c)" "bX""cX" by auto
          from b V(1) have m:"?min,cr""b,?minr""?minb" "?minc" unfolding IntervalX_def Interval_def by auto  
          {
            assume A:"c,vr"
            from m obtain z where z:"z,cr" "?min,zr""zX-{c,?min}" using assms(4) unfolding IsDense_def
              using b(3) V(1,2) UX by blast
            from z(2) have "b,zr" using m(2) assms(1) unfolding IsLinOrder_def trans_def
              by fast
            with z(1) have "zIntervalX(X,r,b,c)z=b" using z(3) unfolding IntervalX_def
              Interval_def by auto
            then have "zIntervalX(X,r,b,c)" using m(2) z(2,3) using assms(1) unfolding IsLinOrder_def
              antisym_def by auto
            with b(1) V(2) have "zU" by auto moreover
            from A z(1) have "z,vr" using assms(1) unfolding IsLinOrder_def trans_def by fast
            moreover have "zv" using A z(1,3) assms(1) unfolding IsLinOrder_def antisym_def by auto
            ultimately have "zULeftRayX(X,r,v)" unfolding LeftRayX_def using z(3) by auto
            then have "?minr``{z}" using Order_ZF_4_L4(1)[OF _ Hmin] assms(1) unfolding Supremum_def IsLinOrder_def
              by auto
            then have "z,?minr" by auto
            with z(2,3) have "False" using assms(1) unfolding IsLinOrder_def antisym_def by auto
          }
          then have vc:"v,cr""vc" using assms(1) unfolding IsLinOrder_def IsTotal_def using vX-U
            b(3) by auto
          {
            assume "?min=v"
            with V(2,1) vX-U have "False" by auto
          }
          then have "?minv" by auto
          with a1 obtain z where z:"?min,zr""z,vr""zX-{?min,v}" using assms(4) unfolding IsDense_def
            using V(1,2) UXvX-U by blast
          from z(2) vc(1) have zc:"z,cr" using assms(1) unfolding IsLinOrder_def trans_def
            by fast moreover
          from m(2) z(1) have "b,zr" using assms(1) unfolding IsLinOrder_def trans_def
            by fast ultimately
          have "zInterval(r,b,c)" using Order_ZF_2_L1B by auto moreover
          {
            assume "z=c"
            then have "False" using z(2) vc using assms(1) unfolding IsLinOrder_def antisym_def
              by fast
          }
          then have "zc" by auto moreover
          {
            assume "z=b"
            then have "z=?min" using m(2) z(1) using assms(1) unfolding IsLinOrder_def
              antisym_def by auto
            with z(3) have "False" by auto
          }
          then have "zb" by auto moreover
          have "zX" using z(3) by auto ultimately
          have "zIntervalX(X,r,b,c)" unfolding IntervalX_def by auto
          then have "zV" using b(1) by auto
          then have "zU" using V(2) by auto moreover
          from z(2,3) have "zLeftRayX(X,r,v)" unfolding LeftRayX_def by auto ultimately
          have "zULeftRayX(X,r,v)" by auto
          then have "?minr``{z}" using Order_ZF_4_L4(1)[OF _ Hmin] assms(1) unfolding Supremum_def IsLinOrder_def
            by auto
          then have "z,?minr" by auto
          with z(1,3) have "False" using assms(1) unfolding IsLinOrder_def antisym_def by auto
        }
        ultimately have "False" using V(3) by auto
      }
      then have ass:"?minX-U" using a1 assms(3) by auto
      then obtain V where V:"?minV""VX-U"
        "V{IntervalX(X,r,b,c). b,cX×X}{LeftRayX(X,r,b). bX}{RightRayX(X,r,b). bX}" using point_open_base_neigh
        [OF Ordtopology_is_a_topology(2)[OF assms(1)] X-U(OrdTopology X r) ass] by blast
      {
        assume "V{IntervalX(X,r,b,c). b,cX×X}"
        then obtain b c where b:"V=IntervalX(X,r,b,c)""bX""cX" by auto
        from b V(1) have m:"?min,cr""b,?minr""?minb" "?minc" unfolding IntervalX_def Interval_def by auto  
        {
          fix x assume A:"xULeftRayX(X,r,v)"
          then have "x,vr""xU" unfolding LeftRayX_def by auto
          then have "xV" using V(2) by auto
          then have "xInterval(r, b, c)  Xx=bx=c" using b(1) unfolding IntervalX_def by auto
          then have "(b,xrx,cr)x=bx=c""xX" using Order_ZF_2_L1B xUUX by auto
          then have "(x,brc,xr)x=bx=c" using assms(1) unfolding IsLinOrder_def IsTotal_def
            using b(2,3) by auto
          then have "(x,brc,xr)" using assms(1) unfolding IsLinOrder_def using total_is_refl
            unfolding refl_def using b(2,3) by auto moreover
          from A have "x,?minr" using Order_ZF_4_L4(1)[OF _ Hmin] assms(1) unfolding Supremum_def IsLinOrder_def
            by auto
          ultimately have "(x,brc,?minr)" using assms(1) unfolding IsLinOrder_def trans_def
            by fast
          with m(1) have "(x,brc=?min)" using assms(1) unfolding IsLinOrder_def antisym_def by auto
          with m(4) have "x,br" by auto
        }
        then have "?min,br" using Order_ZF_5_L3[OF _ nE Hmin] assms(1) unfolding IsLinOrder_def by auto
        with m(2,3) have "False" using assms(1) unfolding IsLinOrder_def antisym_def by auto
      }
      moreover
      {
        assume "V{RightRayX(X,r,b). bX}"
        then obtain b where b:"V=RightRayX(X,r,b)" "bX" by auto
        from b V(1) have m:"b,?minr""?minb" unfolding RightRayX_def by auto
        {
          fix x assume A:"xULeftRayX(X,r,v)"
          then have "x,vr""xU" unfolding LeftRayX_def by auto
          then have "xV" using V(2) by auto
          then have "xRightRayX(X,r, b)" using b(1) by auto
          then have "(b,xrx=b)""xX" unfolding RightRayX_def using xUUX by auto
          then have "x,br" using assms(1) unfolding IsLinOrder_def using total_is_refl unfolding
            refl_def unfolding IsTotal_def using b(2) by auto
        }
        then have "?min,br" using Order_ZF_5_L3[OF _ nE Hmin] assms(1) unfolding IsLinOrder_def by auto
        with m(2,1) have "False" using assms(1) unfolding IsLinOrder_def antisym_def by auto
      } moreover
      {
         assume "V{LeftRayX(X,r,b). bX}"
        then obtain b where b:"V=LeftRayX(X,r,b)" "bX" by auto
        from b V(1) have m:"?min,br""?minb" unfolding LeftRayX_def by auto
        {
          fix x assume A:"xULeftRayX(X,r,v)"
          then have "x,vr""xU" unfolding LeftRayX_def by auto
          then have "xV" using V(2) by auto
          then have "xLeftRayX(X,r, b)" using b(1) by auto
          then have "(x,brx=b)""xX" unfolding LeftRayX_def using xUUX by auto
          then have "b,xr" using assms(1) unfolding IsLinOrder_def using total_is_refl unfolding
            refl_def unfolding IsTotal_def using b(2) by auto
          with m(1) have "?min,xr" using assms(1) unfolding IsLinOrder_def trans_def by fast
          moreover 
          from bound A have "g. yULeftRayX(X,r,v). y,gr" using nE
            unfolding IsBoundedAbove_def by auto
          then obtain g where g:"yULeftRayX(X,r,v). y,gr" by auto
          with nE obtain t where "tULeftRayX(X,r,v)" by auto
          with g have "t,gr" by auto
          with assms(3) have "gX" by auto
          with g have boundX:"gX. yULeftRayX(X,r,v). y,gr" by auto
          have "x,?minr" using Order_ZF_5_L7(2)[OF assms(3) _ assms(5) _  boundX]
            assms(1) UX A unfolding LeftRayX_def IsLinOrder_def by auto
          ultimately have "x=?min" using assms(1) unfolding IsLinOrder_def antisym_def by auto
        }
        then have "ULeftRayX(X,r,v){?min}" by auto moreover
        {
          assume "?minULeftRayX(X,r,v)"
          then have "?minU" by auto
          then have "False" using V(1,2) by auto
        }
        ultimately have "False" using nE by auto
      }
      moreover note V(3)
      ultimately have "False" by auto
    }
    with assms(1) have "v,ur" unfolding IsLinOrder_def IsTotal_def using uUUX
      vX-U by auto
    have "RightRayX(X,r,v)(OrdTopology X r)" using base_sets_open[OF Ordtopology_is_a_topology(2)[OF assms(1)]]
      vX-U by auto
    then have "URightRayX(X,r,v)(OrdTopology X r)" using U(3) using Ordtopology_is_a_topology(1)
      [OF assms(1)] unfolding IsATopology_def by auto
    {
      fix b assume "b(U)RightRayX(X,r,v)"
      then have "v,br" unfolding RightRayX_def by auto
    }
    then have bound:"IsBoundedBelow(URightRayX(X,r,v),r)" unfolding IsBoundedBelow_def by auto
    with v,uruUUXvX-U have nE:"URightRayX(X,r,v)0" unfolding RightRayX_def by auto
    have Hmax:"HasAmaximum(r,cURightRayX(X,r,v). r-``{c})" using complete_order_bounded_below[OF assms(5) bound nE assms(3)].
    let ?max="Infimum(r,URightRayX(X,r,v))"
    {
      fix c assume "cURightRayX(X,r,v)"
      then have "v,cr" unfolding RightRayX_def by auto
    }
    then have a1:"v,?maxr" using Order_ZF_5_L4[OF _ nE Hmax] assms(1) unfolding IsLinOrder_def
      by auto
    {
      assume ass:"?maxU"
      then obtain V where V:"?maxV""VU"
        "V{IntervalX(X,r,b,c). b,cX×X}{LeftRayX(X,r,b). bX}{RightRayX(X,r,b). bX}" using point_open_base_neigh
        [OF Ordtopology_is_a_topology(2)[OF assms(1)] U(OrdTopology X r) ass] by blast
      {
        assume "V{RightRayX(X,r,b). bX}"
        then obtain b where b:"bX" "V=RightRayX(X,r,b)" by auto
        from V(1) b(2) have a2:"b,?maxr""?maxb" unfolding RightRayX_def by auto
        {
          assume "b,vr"
          then have "b=vvRightRayX(X,r,b)" unfolding RightRayX_def using vX-U by auto
          then have "b=v" using b(2) V(2) vX-U by auto
        }
        then have bv:"v,br" using assms(1) unfolding IsLinOrder_def IsTotal_def using b(1)
          vX-U by auto
        from a2 assms(4) obtain z where z:"b,zr""z,?maxr""zX-{b,?max}" unfolding IsDense_def
          using b(1) V(1,2) UX by blast
        then have rayb:"zRightRayX(X,r,b)" unfolding RightRayX_def by auto
        from z(1) bv have "v,zr" using assms(1) unfolding IsLinOrder_def trans_def by fast moreover
        {
          assume "z=v"
          with bv have "z,br" by auto
          with z(1) have "b=z" using assms(1) unfolding IsLinOrder_def antisym_def by auto
          then have "False" using z(3) by auto
        }
        ultimately have "zRightRayX(X,r,v)" unfolding RightRayX_def using z(3) by auto
        with rayb have "zURightRayX(X,r,v)" using V(2) b(2) by auto
        then have "?maxr-``{z}" using Order_ZF_4_L3(1)[OF _ Hmax] assms(1) unfolding Infimum_def IsLinOrder_def
          by auto
        then have "?max,zr" by auto
        with z(2,3) have "False" using assms(1) unfolding IsLinOrder_def antisym_def by auto
      }
      moreover
      {
        assume "V{LeftRayX(X,r,b). bX}"
        then obtain b where b:"V=LeftRayX(X,r,b)" "bX" by auto
        note a1 moreover
        from V(1) b(1) have a2:"?max,br""?maxb" unfolding LeftRayX_def by auto
        ultimately have "v,br" using assms(1) unfolding IsLinOrder_def trans_def by blast moreover
        {
          assume "b=v"
          with a1 a2(1) have "b=?max" using assms(1) unfolding IsLinOrder_def antisym_def by auto
          with a2(2) have "False" by auto
        }
        ultimately have "False" using V(2) b(1) unfolding LeftRayX_def using vX-U by auto
      }
      moreover
      {
        assume "V{IntervalX(X,r,b,c). b,cX×X}"
        then obtain b c where b:"V=IntervalX(X,r,b,c)" "bX""cX" by auto
        from b V(1) have m:"?max,cr""b,?maxr""?maxb" "?maxc" unfolding IntervalX_def Interval_def by auto  
        {
          assume A:"v,br"
          from m obtain z where z:"z,?maxr" "b,zr""zX-{b,?max}" using assms(4) unfolding IsDense_def
            using b(2) V(1,2) UX by blast
          from z(1) have "z,cr" using m(1) assms(1) unfolding IsLinOrder_def trans_def
            by fast
          with z(2) have "zIntervalX(X,r,b,c)z=c" using z(3) unfolding IntervalX_def
            Interval_def by auto
          then have "zIntervalX(X,r,b,c)" using m(1) z(1,3) using assms(1) unfolding IsLinOrder_def
            antisym_def by auto
          with b(1) V(2) have "zU" by auto moreover
          from A z(2) have "v,zr" using assms(1) unfolding IsLinOrder_def trans_def by fast
          moreover have "zv" using A z(2,3) assms(1) unfolding IsLinOrder_def antisym_def by auto
          ultimately have "zURightRayX(X,r,v)" unfolding RightRayX_def using z(3) by auto
          then have "?maxr-``{z}" using Order_ZF_4_L3(1)[OF _ Hmax] assms(1) unfolding Infimum_def IsLinOrder_def
            by auto
          then have "?max,zr" by auto
          with z(1,3) have "False" using assms(1) unfolding IsLinOrder_def antisym_def by auto
        }
        then have vc:"b,vr""vb" using assms(1) unfolding IsLinOrder_def IsTotal_def using vX-U
          b(2) by auto
        {
          assume "?max=v"
          with V(2,1) vX-U have "False" by auto
        }
        then have "v?max" by auto moreover
        note a1 moreover
        have "?maxX" using V(1,2) UX by auto
        moreover have "vX" using vX-U by auto
        ultimately obtain z where z:"v,zr""z,?maxr""zX-{v,?max}" using assms(4) unfolding IsDense_def
          by auto
        from z(1) vc(1) have zc:"b,zr" using assms(1) unfolding IsLinOrder_def trans_def
          by fast moreover
        from m(1) z(2) have "z,cr" using assms(1) unfolding IsLinOrder_def trans_def
          by fast ultimately
        have "zInterval(r,b,c)" using Order_ZF_2_L1B by auto moreover
        {
          assume "z=b"
          then have "False" using z(1) vc using assms(1) unfolding IsLinOrder_def antisym_def
            by fast
        }
        then have "zb" by auto moreover
        {
          assume "z=c"
          then have "z=?max" using m(1) z(2) using assms(1) unfolding IsLinOrder_def
            antisym_def by auto
          with z(3) have "False" by auto
        }
        then have "zc" by auto moreover
        have "zX" using z(3) by auto ultimately
        have "zIntervalX(X,r,b,c)" unfolding IntervalX_def by auto
        then have "zV" using b(1) by auto
        then have "zU" using V(2) by auto moreover
        from z(1,3) have "zRightRayX(X,r,v)" unfolding RightRayX_def by auto ultimately
        have "zURightRayX(X,r,v)" by auto
        then have "?maxr-``{z}" using Order_ZF_4_L3(1)[OF _ Hmax] assms(1) unfolding Infimum_def IsLinOrder_def
          by auto
        then have "?max,zr" by auto
        with z(2,3) have "False" using assms(1) unfolding IsLinOrder_def antisym_def by auto
      }
      ultimately have "False" using V(3) by auto
    }
    then have ass:"?maxX-U" using a1 assms(3) by auto
    then obtain V where V:"?maxV""VX-U"
      "V{IntervalX(X,r,b,c). b,cX×X}{LeftRayX(X,r,b). bX}{RightRayX(X,r,b). bX}" using point_open_base_neigh
      [OF Ordtopology_is_a_topology(2)[OF assms(1)] X-U(OrdTopology X r) ass] by blast
    {
      assume "V{IntervalX(X,r,b,c). b,cX×X}"
      then obtain b c where b:"V=IntervalX(X,r,b,c)""bX""cX" by auto
      from b V(1) have m:"?max,cr""b,?maxr""?maxb" "?maxc" unfolding IntervalX_def Interval_def by auto  
      {
        fix x assume A:"xURightRayX(X,r,v)"
        then have "v,xr""xU" unfolding RightRayX_def by auto
        then have "xV" using V(2) by auto
        then have "xInterval(r, b, c)  Xx=bx=c" using b(1) unfolding IntervalX_def by auto
        then have "(b,xrx,cr)x=bx=c""xX" using Order_ZF_2_L1B xUUX by auto
        then have "(x,brc,xr)x=bx=c" using assms(1) unfolding IsLinOrder_def IsTotal_def
          using b(2,3) by auto
        then have "(x,brc,xr)" using assms(1) unfolding IsLinOrder_def using total_is_refl
          unfolding refl_def using b(2,3) by auto moreover
        from A have "?max,xr" using Order_ZF_4_L3(1)[OF _ Hmax] assms(1) unfolding Infimum_def IsLinOrder_def
          by auto
        ultimately have "(?max,brc,xr)" using assms(1) unfolding IsLinOrder_def trans_def
          by fast
        with m(2) have "(?max=bc,xr)" using assms(1) unfolding IsLinOrder_def antisym_def by auto
        with m(3) have "c,xr" by auto
      }
      then have "c,?maxr" using Order_ZF_5_L4[OF _ nE Hmax] assms(1) unfolding IsLinOrder_def by auto
      with m(1,4) have "False" using assms(1) unfolding IsLinOrder_def antisym_def by auto
    }
    moreover
    {
      assume "V{RightRayX(X,r,b). bX}"
      then obtain b where b:"V=RightRayX(X,r,b)" "bX" by auto
      from b V(1) have m:"b,?maxr""?maxb" unfolding RightRayX_def by auto
      {
        fix x assume A:"xURightRayX(X,r,v)"
        then have "v,xr""xU" unfolding RightRayX_def by auto
        then have "xV" using V(2) by auto
        then have "xRightRayX(X,r, b)" using b(1) by auto
        then have "(b,xrx=b)""xX" unfolding RightRayX_def using xUUX by auto
        then have "x,br" using assms(1) unfolding IsLinOrder_def using total_is_refl unfolding
          refl_def unfolding IsTotal_def using b(2) by auto moreover
        from A have "?max,xr" using Order_ZF_4_L3(1)[OF _ Hmax] assms(1) unfolding Infimum_def IsLinOrder_def
          by auto ultimately
        have "?max,br" using assms(1) unfolding IsLinOrder_def trans_def by fast
        with m have "False" using assms(1) unfolding IsLinOrder_def antisym_def by auto
      }
      then have "False" using nE by auto
    } moreover
    {
       assume "V{LeftRayX(X,r,b). bX}"
      then obtain b where b:"V=LeftRayX(X,r,b)" "bX" by auto
      from b V(1) have m:"?max,br""?maxb" unfolding LeftRayX_def by auto
      {
        fix x assume A:"xURightRayX(X,r,v)"
        then have "v,xr""xU" unfolding RightRayX_def by auto
        then have "xV" using V(2) by auto
        then have "xLeftRayX(X,r, b)" using b(1) by auto
        then have "(x,brx=b)""xX" unfolding LeftRayX_def using xUUX by auto
        then have "b,xr" using assms(1) unfolding IsLinOrder_def using total_is_refl unfolding
          refl_def unfolding IsTotal_def using b(2) by auto
        then have "br-``{x}" by auto
      }
      with nE have "b(cURightRayX(X,r,v). r-``{c})" by auto
      then have "b,?maxr" unfolding Infimum_def using Order_ZF_4_L3(2)[OF _ Hmax] assms(1)
        unfolding IsLinOrder_def by auto
      with m have "False" using assms(1) unfolding IsLinOrder_def antisym_def by auto
    }
    moreover note V(3)
    ultimately have "False" by auto
  } 
  then show ?thesis by auto
qed

subsectionNumerability axioms

textA $\kappa$-separable order topology is in relation with order density.

textIf an order topology has a subset $A$ which is topologically
dense, then that subset is weakly order-dense in $X$.

lemma dense_top_imp_Wdense_ord:
  assumes "IsLinOrder(X,r)" "Closure(A,OrdTopology X r)=X" "AX" "x y. x  y  x  X  y  X"
  shows "A{is weakly dense in}X{with respect to}r"
proof-
  {
    fix r1 r2 assume "r1X""r2X""r1r2" "r1,r2r"
    then have "IntervalX(X,r,r1,r2){IntervalX(X, r, b, c) . b,c  X × X}  {LeftRayX(X, r, b) . b  X} 
      {RightRayX(X, r, b) . b  X}" by auto
    then have P:"IntervalX(X,r,r1,r2)(OrdTopology X r)" using base_sets_open[OF Ordtopology_is_a_topology(2)[OF assms(1)]]
      by auto
    have "IntervalX(X,r,r1,r2)X" unfolding IntervalX_def by auto
    then have int:"Closure(A,OrdTopology X r)IntervalX(X,r,r1,r2)=IntervalX(X,r,r1,r2)" using assms(2) by auto
    {
      assume "IntervalX(X,r,r1,r2)0"
      then have "A(IntervalX(X,r,r1,r2))0" using topology0.cl_inter_neigh[OF topology0_ordtopology[OF assms(1)] _ P , of "A"]
        using assms(3) union_ordtopology[OF assms(1,4)] int by auto
    }
    then have "(zA-{r1,r2}. r1,zrz,r2r)IntervalX(X,r,r1,r2)=0" unfolding IntervalX_def
      Interval_def by auto
  }
  then show ?thesis unfolding IsWeaklyDenseSub_def by auto
qed

textConversely, a weakly order-dense set is topologically dense if it is also considered
that: if there is a maximum or a minimum elements whose singletons are open, this points
have to be in $A$. In conclusion, weakly order-density is a property closed to topological density.

textAnother way to see this: Consider a weakly order-dense set $A$:
\begin{itemize}
\item If $X$ has a maximum and a minimum and $\{min,max\}$ is open: $A$ is topologically dense in $X\setminus\{min,max\}$, where $min$ is the minimum in $X$ and $max$ is the maximum in $X$.
\item If $X$ has a maximum, $\{max\}$ is open and $X$ has no minimum
  or $\{min\}$ isn't open: $A$ is topologically dense in $X\setminus\{max\}$, where $max$ is the maximum in $X$.
\item If $X$ has a minimum, $\{min\}$ is open and $X$ has no maximum
  or $\{max\}$ isn't open $A$ is topologically dense in $X\setminus\{min\}$, where $min$ is the minimum in $X$.
\item If $X$ has no minimum or maximum, or $\{min,max\}$ has no proper open sets: $A$ is topologically dense in $X$.
\end{itemize}


lemma Wdense_ord_imp_dense_top:
  assumes "IsLinOrder(X,r)" "A{is weakly dense in}X{with respect to}r" "AX" "x y. x  y  x  X  y  X"
    "HasAminimum(r,X){Minimum(r,X)}(OrdTopology X r)Minimum(r,X)A"
    "HasAmaximum(r,X){Maximum(r,X)}(OrdTopology X r)Maximum(r,X)A"
  shows "Closure(A,OrdTopology X r)=X"
proof-
  {
    fix x assume "xX"
  {
    fix U assume ass:"xU""U(OrdTopology X r)"
    then have "V{IntervalX(X, r, b, c) . b,c  X × X}  {LeftRayX(X, r, b) . b  X}  {RightRayX(X, r, b) . b  X} . VUxV"
      using point_open_base_neigh[OF Ordtopology_is_a_topology(2)[OF assms(1)]] by auto
    then obtain V where V:"V{IntervalX(X, r, b, c) . b,c  X × X}  {LeftRayX(X, r, b) . b  X}  {RightRayX(X, r, b) . b  X}" "VU" "xV"
      by blast
    note V(1) moreover
    {
      assume "V{IntervalX(X, r, b, c) . b,c  X × X}"
      then obtain b c where b:"bX""cX""V=IntervalX(X, r, b, c)" by auto
      with V(3) have x:"b,xr" "x,cr" "xb" "xc" unfolding IntervalX_def Interval_def by auto
      then have "b,cr" using assms(1) unfolding IsLinOrder_def trans_def by fast
      moreover from x(1-3) have "bc" using assms(1) unfolding IsLinOrder_def antisym_def by fast
      moreover note assms(2) b V(3)
      ultimately have "zA-{b,c}. b,zrz,cr" unfolding IsWeaklyDenseSub_def by auto
      then obtain z where "zA""zb""zc""b,zr""z,cr" by auto
      with assms(3) have "zA""zIntervalX(X, r, b, c)" unfolding IntervalX_def Interval_def by auto
      then have "AU0" using V(2) b(3) by auto
    }
    moreover
    {
      assume "V{RightRayX(X, r, b) . b  X}"
      then obtain b where b:"bX""V=RightRayX(X, r, b)" by auto
      with V(3) have x:"b,xr" "bx" unfolding RightRayX_def by auto moreover
      note b(1) moreover
      have "U(OrdTopology X r)" using ass(2) by auto
      then have "UX" using union_ordtopology[OF assms(1,4)] by auto
      then have "xX" using ass(1) by auto moreover
      note assms(2) ultimately
      have disj:"(zA-{b,x}. b,zrz,xr) IntervalX(X, r, b, x) = 0" unfolding IsWeaklyDenseSub_def by auto
      {
        assume B:"IntervalX(X, r, b, x) = 0"
        {
          assume "yX. x,yr  xy"
          then obtain y where y:"yX""x,yr" "xy" by auto
          with x have "xIntervalX(X,r,b,y)" unfolding IntervalX_def Interval_def
            using xX by auto moreover
          have "b,yr" using y(2) x(1) assms(1) unfolding IsLinOrder_def trans_def by fast
          moreover have "by" using y(2,3) x(1) assms(1) unfolding IsLinOrder_def antisym_def by fast
          ultimately
          have "(zA-{b,y}. b,zrz,yr)" using assms(2) unfolding IsWeaklyDenseSub_def
            using y(1) b(1) by auto
          then obtain z where "zA""b,zr""bz" by auto
          then have "zAV" using b(2) unfolding RightRayX_def using assms(3) by auto
          then have "zAU" using V(2) by auto
          then have "AU0" by auto
        }
        moreover
        {
          assume R:"yX. x,yrx=y"
          {
            fix y assume "yRightRayX(X,r,b)"
            then have y:"b,yr" "yX-{b}" unfolding RightRayX_def by auto
            {
              assume A:"yx"
              then have "x,yr" using R y(2) by auto
              then have "y,xr" using assms(1) unfolding IsLinOrder_def IsTotal_def
                using xX y(2) by auto
              with A y have "yIntervalX(X,r,b,x)" unfolding IntervalX_def Interval_def
                by auto
              then have "False" using B by auto
            }
            then have "y=x" by auto
          }
          then have "RightRayX(X,r,b)={x}" using V(3) b(2) by blast
          moreover
          {
            fix t assume T:"tX"
            {
              assume "t=x"
              then have "t,xr" using assms(1) unfolding IsLinOrder_def
                using Order_ZF_1_L1 T by auto
            }
            moreover
            {
              assume "tx"
              then have "x,tr" using R T by auto
              then have "t,xr" using assms(1) unfolding IsLinOrder_def IsTotal_def
                using T xX by auto
            }
            ultimately have "t,xr" by auto
          }
          with xX have HM:"HasAmaximum(r,X)" unfolding HasAmaximum_def by auto
          then have "Maximum(r,X)X""tX. t,Maximum(r,X)r" using Order_ZF_4_L3 assms(1) unfolding IsLinOrder_def
            by auto
          with R xX have xm:"x=Maximum(r,X)" by auto
          moreover note b(2)
          ultimately have "V={Maximum(r,X)}" by auto
          then have "{Maximum(r,X)}(OrdTopology X r)" using base_sets_open[OF Ordtopology_is_a_topology(2)[OF assms(1)]]
            V(1) by auto
          with HM have "Maximum(r,X)A" using assms(6) by auto
          with xm have "xA" by auto
          with V(2,3) have "AU0" by auto
        }
        ultimately have "AU0" by auto
      }
      moreover
      {
        assume "IntervalX(X, r, b, x)  0"
        with disj have "zA-{b,x}. b,zrz,xr" by auto
        then obtain z where "zA""zb""b,zr" by auto
        then have "zA""zRightRayX(X,r,b)" unfolding RightRayX_def using assms(3) by auto
        then have "zAU" using V(2) b(2) by auto
        then have "AU0" by auto
      }
      ultimately have "AU0" by auto
    }
    moreover
    {
      assume "V{LeftRayX(X, r, b) . b  X}"
      then obtain b where b:"bX""V=LeftRayX(X, r, b)" by auto
      with V(3) have x:"x,br" "bx" unfolding LeftRayX_def by auto moreover
      note b(1) moreover
      have "U(OrdTopology X r)" using ass(2) by auto
      then have "UX" using union_ordtopology[OF assms(1,4)] by auto
      then have "xX" using ass(1) by auto moreover
      note assms(2) ultimately
      have disj:"(zA-{b,x}. x,zrz,br) IntervalX(X, r, x, b) = 0" unfolding IsWeaklyDenseSub_def by auto
      {
        assume B:"IntervalX(X, r, x, b) = 0"
        {
          assume "yX. y,xr  xy"
          then obtain y where y:"yX""y,xr" "xy" by auto
          with x have "xIntervalX(X,r,y,b)" unfolding IntervalX_def Interval_def
            using xX by auto moreover
          have "y,br" using y(2) x(1) assms(1) unfolding IsLinOrder_def trans_def by fast
          moreover have "by" using y(2,3) x(1) assms(1) unfolding IsLinOrder_def antisym_def by fast
          ultimately
          have "(zA-{b,y}. y,zrz,br)" using assms(2) unfolding IsWeaklyDenseSub_def
            using y(1) b(1) by auto
          then obtain z where "zA""z,br""bz" by auto
          then have "zAV" using b(2) unfolding LeftRayX_def using assms(3) by auto
          then have "zAU" using V(2) by auto
          then have "AU0" by auto
        }
        moreover
        {
          assume R:"yX. y,xrx=y"
          {
            fix y assume "yLeftRayX(X,r,b)"
            then have y:"y,br" "yX-{b}" unfolding LeftRayX_def by auto
            {
              assume A:"yx"
              then have "y,xr" using R y(2) by auto
              then have "x,yr" using assms(1) unfolding IsLinOrder_def IsTotal_def
                using xX y(2) by auto
              with A y have "yIntervalX(X,r,x,b)" unfolding IntervalX_def Interval_def
                by auto
              then have "False" using B by auto
            }
            then have "y=x" by auto
          }
          then have "LeftRayX(X,r,b)={x}" using V(3) b(2) by blast
          moreover
          {
            fix t assume T:"tX"
            {
              assume "t=x"
              then have "x,tr" using assms(1) unfolding IsLinOrder_def
                using Order_ZF_1_L1 T by auto
            }
            moreover
            {
              assume "tx"
              then have "t,xr" using R T by auto
              then have "x,tr" using assms(1) unfolding IsLinOrder_def IsTotal_def
                using T xX by auto
            }
            ultimately have "x,tr" by auto
          }
          with xX have HM:"HasAminimum(r,X)" unfolding HasAminimum_def by auto
          then have "Minimum(r,X)X""tX. Minimum(r,X),tr" using Order_ZF_4_L4 assms(1) unfolding IsLinOrder_def
            by auto
          with R xX have xm:"x=Minimum(r,X)" by auto
          moreover note b(2)
          ultimately have "V={Minimum(r,X)}" by auto
          then have "{Minimum(r,X)}(OrdTopology X r)" using base_sets_open[OF Ordtopology_is_a_topology(2)[OF assms(1)]]
            V(1) by auto
          with HM have "Minimum(r,X)A" using assms(5) by auto
          with xm have "xA" by auto
          with V(2,3) have "AU0" by auto
        }
        ultimately have "AU0" by auto
      }
      moreover
      {
        assume "IntervalX(X, r, x, b)  0"
        with disj have "zA-{b,x}. x,zrz,br" by auto
        then obtain z where "zA""zb""z,br" by auto
        then have "zA""zLeftRayX(X,r,b)" unfolding LeftRayX_def using assms(3) by auto
        then have "zAU" using V(2) b(2) by auto
        then have "AU0" by auto
      }
      ultimately have "AU0" by auto
    }
    ultimately have "AU0" by auto
  }
  then have "U(OrdTopology X r). xU  UA0" by auto
  moreover note xX moreover
  note assms(3) topology0.inter_neigh_cl[OF topology0_ordtopology[OF assms(1)]]
  union_ordtopology[OF assms(1,4)] ultimately have "xClosure(A,OrdTopology X r)"
    by auto
  }
  then have "XClosure(A,OrdTopology X r)" by auto
  with topology0.Top_3_L11(1)[OF topology0_ordtopology[OF assms(1)]]
    assms(3) union_ordtopology[OF assms(1,4)] show ?thesis by auto
qed

textThe conclusion is that an order topology is $\kappa$-separable
iff there is a set $A$ with cardinality strictly less than $\kappa$
which is weakly-dense in $X$.

theorem separable_imp_wdense:
  assumes "(OrdTopology X r){is separable of cardinal}Q" "x y. x  y  x  X  y  X"
    "IsLinOrder(X,r)"
  shows "APow(X). AQ  (A{is weakly dense in}X{with respect to}r)"
proof-
  from assms obtain U where "UPow((OrdTopology X r))" "Closure(U,OrdTopology X r)=(OrdTopology X r)" "UQ"
    unfolding IsSeparableOfCard_def by auto
  then have "UPow(X)" "Closure(U,OrdTopology X r)=X" "UQ" using union_ordtopology[OF assms(3,2)]
    by auto
  with dense_top_imp_Wdense_ord[OF assms(3) _ _ assms(2)] show ?thesis by auto
qed

theorem wdense_imp_separable:
  assumes "x y. x  y  x  X  y  X" "(A{is weakly dense in}X{with respect to}r)"
    "IsLinOrder(X,r)" "AQ" "InfCard(Q)" "AX"
  shows "(OrdTopology X r){is separable of cardinal}Q"
proof-
  {
    assume Hmin:"HasAmaximum(r,X)"
    then have MaxX:"Maximum(r,X)X" using Order_ZF_4_L3(1) assms(3) unfolding IsLinOrder_def
      by auto
    {
      assume HMax:"HasAminimum(r,X)"
      then have MinX:"Minimum(r,X)X" using Order_ZF_4_L4(1) assms(3) unfolding IsLinOrder_def
        by auto
      let ?A="A {Maximum(r,X),Minimum(r,X)}"
      have "Finite({Maximum(r,X),Minimum(r,X)})" by auto
      then have "{Maximum(r,X),Minimum(r,X)}nat" using n_lesspoll_nat
        unfolding Finite_def using eq_lesspoll_trans by auto
      moreover
      from assms(5) have "natQnat=Q" unfolding InfCard_def
        using lt_Card_imp_lesspoll[of "Q""nat"] unfolding lt_def succ_def
        using Card_is_Ord[of "Q"] by auto
      ultimately have "{Maximum(r,X),Minimum(r,X)}Q" using lesspoll_trans by auto
      with assms(4,5) have C:"?AQ" using less_less_imp_un_less
        by auto
      have WeakDense:"?A{is weakly dense in}X{with respect to}r" using assms(2) unfolding
        IsWeaklyDenseSub_def by auto
      from MaxX MinX assms(6) have S:"?AX" by auto
      then have "Closure(?A,OrdTopology X r)=X" using Wdense_ord_imp_dense_top
        [OF assms(3) WeakDense _ assms(1)] by auto
      then have ?thesis unfolding IsSeparableOfCard_def using union_ordtopology[OF assms(3,1)]
        S C by auto
    }
    moreover
    {
      assume nmin:"¬HasAminimum(r,X)"
       let ?A="A {Maximum(r,X)}"
      have "Finite({Maximum(r,X)})" by auto
      then have "{Maximum(r,X)}nat" using n_lesspoll_nat
        unfolding Finite_def using eq_lesspoll_trans by auto
      moreover
      from assms(5) have "natQnat=Q" unfolding InfCard_def
        using lt_Card_imp_lesspoll[of "Q""nat"] unfolding lt_def succ_def
        using Card_is_Ord[of "Q"] by auto
      ultimately have "{Maximum(r,X)}Q" using lesspoll_trans by auto
      with assms(4,5) have C:"?AQ" using less_less_imp_un_less
        by auto
      have WeakDense:"?A{is weakly dense in}X{with respect to}r" using assms(2) unfolding
        IsWeaklyDenseSub_def by auto
      from MaxX assms(6) have S:"?AX" by auto
      then have "Closure(?A,OrdTopology X r)=X" using Wdense_ord_imp_dense_top
        [OF assms(3) WeakDense _ assms(1)] nmin by auto
      then have ?thesis unfolding IsSeparableOfCard_def using union_ordtopology[OF assms(3,1)]
        S C by auto
    }
    ultimately have ?thesis by auto
  }
  moreover
  {
    assume nmax:"¬HasAmaximum(r,X)"
    {
      assume HMin:"HasAminimum(r,X)"
      then have MinX:"Minimum(r,X)X" using Order_ZF_4_L4(1) assms(3) unfolding IsLinOrder_def
        by auto
      let ?A="A {Minimum(r,X)}"
      have "Finite({Minimum(r,X)})" by auto
      then have "{Minimum(r,X)}nat" using n_lesspoll_nat
        unfolding Finite_def using eq_lesspoll_trans by auto
      moreover
      from assms(5) have "natQnat=Q" unfolding InfCard_def
        using lt_Card_imp_lesspoll[of "Q""nat"] unfolding lt_def succ_def
        using Card_is_Ord[of "Q"] by auto
      ultimately have "{Minimum(r,X)}Q" using lesspoll_trans by auto
      with assms(4,5) have C:"?AQ" using less_less_imp_un_less
        by auto
      have WeakDense:"?A{is weakly dense in}X{with respect to}r" using assms(2) unfolding
        IsWeaklyDenseSub_def by auto
      from MinX assms(6) have S:"?AX" by auto
      then have "Closure(?A,OrdTopology X r)=X" using Wdense_ord_imp_dense_top
        [OF assms(3) WeakDense _ assms(1)] nmax by auto
      then have ?thesis unfolding IsSeparableOfCard_def using union_ordtopology[OF assms(3,1)]
        S C by auto
    }
    moreover
    {
      assume nmin:"¬HasAminimum(r,X)"
      let ?A="A"
      from assms(4,5) have C:"?AQ" by auto
      have WeakDense:"?A{is weakly dense in}X{with respect to}r" using assms(2) unfolding
        IsWeaklyDenseSub_def by auto
      from assms(6) have S:"?AX" by auto
      then have "Closure(?A,OrdTopology X r)=X" using Wdense_ord_imp_dense_top
        [OF assms(3) WeakDense _ assms(1)] nmin nmax by auto
      then have ?thesis unfolding IsSeparableOfCard_def using union_ordtopology[OF assms(3,1)]
        S C by auto
    }
    ultimately have ?thesis by auto
  }
  ultimately show ?thesis by auto
qed


end