Martin Escardo, December 2020

A notion of disconnectedness. This is different from homotopy
disconnectedness in the sense of the HoTT book. It is based on the
topological, rather than homotopical, interpretation of types.

A discussion of such models is in

  M.H. Escardo and Chuangjie Xu. A constructive manifestation of the
  Kleene-Kreisel continuous functionals. Annals of Pure and Applied
  Logic, 2016.

and

  M.H. Escardo and Thomas Streicher. Annals of Pure and Applied Logic,
  2016.

\begin{code}

{-# OPTIONS --safe --without-K #-}

module TypeTopology.DisconnectedTypes where

open import MLTT.Spartan
open import MLTT.Two-Properties
open import Naturals.Properties
open import UF.DiscreteAndSeparated
open import UF.Equiv
open import UF.Hedberg
open import UF.Retracts

\end{code}

The following notions of disconnectedness are data rather than
property.

\begin{code}

is-disconnected₀ : 𝓤 ̇  𝓤 ̇
is-disconnected₀ X = retract 𝟚 of X

is-disconnected₁ : 𝓤 ̇  𝓤 ̇
is-disconnected₁ X = Σ p  (X  𝟚) , fiber p  × fiber p 

is-disconnected₂ : 𝓤 ̇  𝓤  ̇
is-disconnected₂ {𝓤} X = Σ X₀  𝓤 ̇ , Σ X₁  𝓤 ̇ , X₀ × X₁ × (X  X₀ + X₁)

is-disconnected₃ : 𝓤 ̇  𝓤  ̇
is-disconnected₃ {𝓤} X = Σ X₀  𝓤 ̇ , Σ X₁  𝓤 ̇ , X₀ × X₁ × (retract (X₀ + X₁) of X)

is-disconnected-eq : (X : 𝓤 ̇ )
                    (is-disconnected₀ X  is-disconnected₁ X)
                   × (is-disconnected₁ X  is-disconnected₂ X)
                   × (is-disconnected₂ X  is-disconnected₃ X)
                   × (is-disconnected₃ X  is-disconnected₀ X)

is-disconnected-eq {𝓤} X = (f , g , h , k)
 where
  f : (Σ p  (X  𝟚) , Σ s  (𝟚  X) , p  s  id)
     Σ p  (X  𝟚) , (Σ x  X , p x  ) × (Σ x  X , p x  )
  f (p , s , e) = p , (s  , e ) , (s  , e )

  g : (Σ p  (X  𝟚) , (Σ x  X , p x  ) × (Σ x  X , p x  ))
     Σ X₀  𝓤 ̇ , Σ X₁  𝓤 ̇ , X₀ × X₁ × (X  X₀ + X₁)
  g (p , (x₀ , e₀) , (x₁ , e₁)) = (Σ x  X , p x  ) ,
                                  (Σ x  X , p x  ) ,
                                  (x₀ , e₀) ,
                                  (x₁ , e₁) ,
                                  qinveq ϕ (γ , γϕ , ϕγ)
   where
    ϕ : X  (Σ x  X , p x  ) + (Σ x  X , p x  )
    ϕ x = 𝟚-equality-cases
            (r₀ : p x  )  inl (x , r₀))
            (r₁ : p x  )  inr (x , r₁))

    γ : (Σ x  X , p x  ) + (Σ x  X , p x  )  X
    γ (inl (x , r₀)) = x
    γ (inr (x , r₁)) = x

    ϕγ : ϕ  γ  id
    ϕγ (inl (x , r₀)) = 𝟚-equality-cases₀ r₀
    ϕγ (inr (x , r₁)) = 𝟚-equality-cases₁ r₁

    γϕ : γ  ϕ  id
    γϕ x = 𝟚-equality-cases
            (r₀ : p x  )  ap γ (𝟚-equality-cases₀ r₀))
            (r₁ : p x  )  ap γ (𝟚-equality-cases₁ r₁))

  h : (Σ X₀  𝓤 ̇ , Σ X₁  𝓤 ̇ , X₀ × X₁ × (X  X₀ + X₁))
     (Σ X₀  𝓤 ̇ , Σ X₁  𝓤 ̇ , X₀ × X₁ × (retract (X₀ + X₁) of X))
  h (X₀ , X₁ , x₀ , x₁ , (γ , (ϕ , γϕ) , _)) = (X₀ , X₁ , x₀ , x₁ , (γ , ϕ , γϕ))

  k : (Σ X₀  𝓤 ̇ , Σ X₁  𝓤 ̇ , X₀ × X₁ × (retract (X₀ + X₁) of X))
     Σ p  (X  𝟚) , Σ s  (𝟚  X) , p  s  id
  k (X₀ , X₁ , x₀ , x₁ , (γ , ϕ , γϕ)) = p , s , ps
   where
    p : X  𝟚
    p x = Cases (γ x)  _  )  _  )

    s : 𝟚  X
    s  = ϕ (inl x₀)
    s  = ϕ (inr x₁)

    ps : p  s  id
    ps  = ap (cases  _  )  _  )) (γϕ (inl x₀))
    ps  = ap (cases  _  )  _  )) (γϕ (inr x₁))

\end{code}

The following is our official notion of disconnectedness (logically
equivalent to the other ones):

\begin{code}

is-disconnected : 𝓤 ̇  𝓤 ̇
is-disconnected = is-disconnected₀

\end{code}

Some examples:

\begin{code}

𝟚-is-disconnected : is-disconnected 𝟚
𝟚-is-disconnected = identity-retraction

ℕ-is-disconnected : is-disconnected 
ℕ-is-disconnected = (r , s , rs)
 where
  r :   𝟚
  r zero     = 
  r (succ n) = 

  s : 𝟚  
  s  = zero
  s  = succ zero

  rs : (n : 𝟚)  r (s n)  n
  rs  = refl
  rs  = refl

types-with-isolated-point-different-from-another-point-are-disconnected
 : {Y : 𝓥 ̇ }
  (Σ y₀  Y , Σ y₁  Y , (y₀  y₁) × is-isolated y₀ )
  is-disconnected Y
types-with-isolated-point-different-from-another-point-are-disconnected
 (y₀ , y₁ , ne , i) = 𝟚-retract-of-non-trivial-type-with-isolated-point ne i

discrete-types-with-two-different-points-are-disconnected
 : {Y : 𝓥 ̇ }
  (Σ y₀  Y , Σ y₁  Y , y₀  y₁)
  is-discrete Y
  is-disconnected Y
discrete-types-with-two-different-points-are-disconnected (y₀ , y₁ , ne) d =
  types-with-isolated-point-different-from-another-point-are-disconnected
   (y₀ , y₁ , ne , d y₀)

ℕ-is-disconnected' : is-disconnected 
ℕ-is-disconnected' = discrete-types-with-two-different-points-are-disconnected
                     (0 , 1 , succ-no-fp 0)
                     ℕ-is-discrete

retract-is-disconnected : {X : 𝓤 ̇ } {Y : 𝓥 ̇ }
                         retract X of Y
                         is-disconnected X
                         is-disconnected Y
retract-is-disconnected = retracts-compose

\end{code}

TODO. Define totally disconnected. Then maybe for compact types the
notions of total disconnectedness and total separatedness agree.

The negation of disconnectedness can be expressed positively in
various equivalent ways.

\begin{code}

open import TypeTopology.TotallySeparated
open import UF.FunExt
open import UF.Subsingletons
open import UF.Subsingletons-FunExt

is-connected₀ : 𝓤 ̇  𝓤 ̇
is-connected₀ X = (f : X  𝟚)  wconstant f

is-connected₁ : 𝓤 ̇  𝓤 ̇
is-connected₁ X = ¬ is-disconnected X

is-connected₂ : 𝓤 ̇  𝓤 ̇
is-connected₂ X = (x y : X)  x =₂ y

connected₀-types-are-connected₂ : {X : 𝓤 ̇ }  is-connected₀ X  is-connected₂ X
connected₀-types-are-connected₂ i x y p = i p x y

connected₂-types-are-connected₀ : {X : 𝓤 ̇ }  is-connected₂ X  is-connected₀ X
connected₂-types-are-connected₀ ϕ f x y = ϕ x y f

connected₀-types-are-connected₁ : {X : 𝓤 ̇ }  is-connected₀ X  is-connected₁ X
connected₀-types-are-connected₁ c (r , s , rs) = n (c r)
 where
  n : ¬ wconstant r
  n κ = zero-is-not-one (       =⟨ (rs )⁻¹ 
                         r (s ) =⟨ κ (s ) (s ) 
                         r (s ) =⟨ rs  
                                )

disconnected-types-are-not-connected : {X : 𝓤 ̇ }
                                      is-disconnected X
                                      ¬ is-connected₀ X
disconnected-types-are-not-connected c d = connected₀-types-are-connected₁ d c

connected₁-types-are-is-connected₀ : {X : 𝓤 ̇ }
                                    is-connected₁ X
                                    is-connected₀ X
connected₁-types-are-is-connected₀ {𝓤} {X} n f x y =
 𝟚-is-¬¬-separated (f x) (f y) ϕ
 where
  ϕ : ¬¬ (f x  f y)
  ϕ u = n (f , s , fs)
   where
    s : 𝟚  X
    s  = 𝟚-equality-cases
            (p₀ : f x  )  x)
            (p₁ : f x  )  y)
    s  = 𝟚-equality-cases
            (p₀ : f x  )  y)
            (p₁ : f x  )  x)

    a : f x    f y  
    a p = different-from-₁-equal-₀  (q : f y  )  u (p  (q ⁻¹)))

    b : f x    f y  
    b p = different-from-₀-equal-₁  (q : f y  )  u (p  q ⁻¹))

    fs : f  s  id
    fs  = 𝟚-equality-cases
            (p₀ : f x  )  f (s ) =⟨ ap f (𝟚-equality-cases₀ p₀) 
                               f x      =⟨ p₀ 
                                       )
            (p₁ : f x  )  f (s ) =⟨ ap f (𝟚-equality-cases₁ p₁) 
                               f y      =⟨ a p₁ 
                                       )
    fs  = 𝟚-equality-cases
            (p₀ : f x  )  f (s ) =⟨ ap f (𝟚-equality-cases₀ p₀) 
                               f y      =⟨ b p₀ 
                                       )
            (p₁ : f x  )  f (s ) =⟨ ap f (𝟚-equality-cases₁ p₁) 
                               f x      =⟨ p₁ 
                                       )

is-connected : 𝓤 ̇  𝓤 ̇
is-connected = is-connected₀

being-connected-is-prop : {X : 𝓤 ̇ }  Fun-Ext  is-prop (is-connected X)
being-connected-is-prop fe = Π₃-is-prop fe  f x y  𝟚-is-set)

\end{code}