foundations.Finite.md.

Version of Sunday, January 22, 2023, 10:42 PM

Powered by agda version 2.6.2.2-442c76b and pandoc 2.14.0.3


Investigations on graph-theoretical constructions in Homotopy type theory

Jonathan Prieto-Cubides j.w.w. Håkon Robbestad Gylterud

Department of Informatics

University of Bergen, Norway

{-# OPTIONS --without-K --exact-split #-}
module foundations.Finite where
  open import foundations.Core
  open import foundations.Fin
  open import foundations.NaturalsType
  open import foundations.Nat
  open import foundations.TypesofMorphisms
  isFinite :  {ℓ₁}  Type ℓ₁  Type ℓ₁
  isFinite {} X = ∑[ n   ]  X  Fin  n 

  _is-finite :  {ℓ₁}  Type ℓ₁  Type ℓ₁
  A is-finite = isFinite A

  isDiscrete :  {ℓ₁}  Type ℓ₁  Type ℓ₁
  isDiscrete {} X = ((a b : X)  (a  b) + ( a  b))

  being-discrete-is-prop :  {}  (X : Type )
     isSet X
     isProp (isDiscrete X)
  being-discrete-is-prop X X-is-set
     = pi-is-prop λ _  pi-is-prop  _
        +-prop (X-is-set _ _) (pi-is-prop  _  𝟘-is-prop))
         λ {(p , ¬p)  ⊥-elim (¬p p)})
  Fin-≡-Fin
      :  {}{n m}
       Fin  n  Fin  m
       n  m
  Fin-≡-Fin p = Fin₁-is-inj _ _ _ p
  being-finite-is-prop
    :  {} {X : Type }
     (X is-finite) is-prop

  being-finite-is-prop { = }
    (n , p1) (m , p2) =
      let
        f-prop : ((n , p1)  (m , p2)) is-prop
        f-prop =  (∑-set ℕ-is-set
           a  prop-is-set trunc-is-prop) _ _)
      in
      trunc-elim f-prop (trunc-elim  (pi-is-prop  _  f-prop))
        e1 e2  pair= (Fin₁-is-inj-≃  n m (≃-trans (≃-sym e1) e2)
                        , trunc-is-prop _ _))
        p1)
      p2
  𝟘-is-finite :  {}  (𝟘 ) is-finite
  𝟘-is-finite = (0 ,  qinv-≃  ()) (((λ { (zero , ()) ; (succ _ , ())})
                   ,  {(zero , ()) ; (succ _ , ())})
                   , λ {()})) )
  𝟙-is-finite :  {}  (𝟙 ) is-finite
  𝟙-is-finite { = }
    = (1 ,  qinv-≃  {   zero , }) ((λ { p  })
         ,  { (zero , )  idp ; (succ n , p)  ⊥-elim {}{} (n<0  {n = n} p)})
         , λ {   idp}) )

  Fin-is-finite
    :  {} {n : }
     (Fin  n) is-finite
  Fin-is-finite {n = n} = (n ,  idEqv )
  FinSet :  {}   Type (lsuc )
  FinSet { = } = ∑[ A  Type  ] isFinite A
  cardinal :  { }(X : Type )  isFinite X  
  cardinal X (n , _) = n
  same-cardinal
    :  {}
     {X Y : Type }
     (e : X  Y)
     (fin-X : X is-finite)
     (fin-Y : Y is-finite)
     cardinal X fin-X  cardinal Y fin-Y

  same-cardinal {}{X = X}{Y} e X-is-finite Y-is-finite 
    = trunc-elim (ℕ-is-set _ _) 
         e1 
           trunc-elim (ℕ-is-set _ _) 
             e2  Fin₁-is-inj-≃  _ _   
              (≃-trans (≃-sym e1) (≃-trans e e2))) 
              (π₂ Y-is-finite)) 
        (π₂ (X-is-finite))
  inhabited-has-positive-cardinality
      :  {}{A : Type }
       (af : A is-finite)
       (x : A)
       (cardinal A af)  0   
  inhabited-has-positive-cardinality { = } A-is-finite x idp
       = trunc-elim (⊥-is-prop )
                     e  n<0  {} {π₁ (π₁ e x)} (proj₂ (apply e x)))
                    (proj₂ (A-is-finite))

Just for practicallity, we need the following consequence of being finite. Any property for \([n]\) holds for any finite \(n\) elements.

  isFinite-→-isSet
    :  {} (X : Type )
     isFinite X
     isSet X
  isFinite-→-isSet { = }
    X (n , ∥X≃[n]∥)
      = trunc-elim
            set-is-prop
             e  equiv-preserves-sets (≃-sym e) (Fin-is-set ))
            ∥X≃[n]∥
  equiv-preserves-finiteness
    :  {}{A B : Type } -- The levels may be different in theory.
     A  B
     isFinite A
     isFinite B
  equiv-preserves-finiteness {A = A} A≃B A-is-finite
    = trunc-elim being-finite-is-prop  A≃[n] 
    (π₁ A-is-finite) ,  (≃-trans (≃-sym A≃B) A≃[n]) )
    (π₂ A-is-finite)

  equiv-preserves-decidable-equality
    :  {}{A B : Type } -- The levels may be different in theory.
     A  B
     isDiscrete B
     isDiscrete A
  equiv-preserves-decidable-equality {A = A} f-≃@(f , _) B-is-discrete
    x y with B-is-discrete (f x) (f y)
  ... | inl fx=fy = inl helper
      where
      helper : x  y
      helper = ! (rlmap-inverse-h f-≃ x)
               · (ap (rapply f-≃) fx=fy) · rlmap-inverse-h f-≃ y
  ... | inr fx≠fy = inr  x=y  ⊥-elim (fx≠fy (ap f x=y)))

  isFinite-→-isDec
    :  {} {X : Type }
     isFinite X
     isDiscrete X

  isFinite-→-isDec {}{X = X} X-is-Finite@(n , ∥X≃[n]∥)
    = trunc-elim
        (pi-is-prop  p  pi-is-prop (\ q
         +-prop
          (isFinite-→-isSet X X-is-Finite _ _)
          (pi-is-prop  p  ⊥-is-prop))
          λ {(p≡q , p≠q)  p≠q p≡q})))
       e  equiv-preserves-decidable-equality e (FinIsDec ))
      ∥X≃[n]∥


  decidable-→-≡-is-finite
    :  {} {X : Type }
     ((a b : X)  (a  b) + ( a  b))
      x y  (x  y) is-finite
  decidable-→-≡-is-finite {}{X = X} dec x y = helper
      where
      X-is-set : isSet X
      X-is-set = hedberg dec

      helper : _
      helper with dec x y
      ... | inl idp = equiv-preserves-finiteness (≃-sym eq) 𝟙-is-finite
        where
        eq : (x  y)  𝟙 
        eq = prop-inhabited-≃𝟙 (X-is-set x x) idp
      ... | inr x≠y = equiv-preserves-finiteness (≃-sym eq) 𝟘-is-finite
        where
        eq : (x  y)  𝟘 
        eq = qinv-≃  {idp  ⊥-elim (x≠y idp)})
          (((λ ()) ,  {()}) , λ {p  ⊥-elim (x≠y p)}))

  ≡-finite
    :  {} {X : Type }
     isFinite X
      {x y : X}  isFinite (x  y)
  ≡-finite {X = X} X-is-finite {x}{y} =
    decidable-→-≡-is-finite (isFinite-→-isDec X-is-finite) x y


  decidable-prop-is-finite
    :  {} {X : Type }
     isProp X
     X + ¬ X
     isFinite X
  decidable-prop-is-finite {} {X} X-is-prop (inl x)
    = equiv-preserves-finiteness (≃-sym X-≃-𝟙) 𝟙-is-finite
    where
    X-≃-𝟙 : X  𝟙 
    X-≃-𝟙 = prop-inhabited-≃𝟙 X-is-prop x
  decidable-prop-is-finite {} {X} X-is-prop (inr ¬X)
    = equiv-preserves-finiteness (≃-sym X-≃-𝟘) 𝟘-is-finite
    where
    X-≃-𝟘 : X  𝟘 
    X-≃-𝟘 = prop-ext-≃ X-is-prop 𝟘-is-prop (¬X , λ ())

  trunc-finite-lemma :  {}  {X : Type }
     isFinite X
     X
     isFinite  X 
  trunc-finite-lemma {} {X} X-is-finite a
    = equiv-preserves-finiteness (≃-sym helper) 𝟙-is-finite
    where
    helper :  X   𝟙 
    helper = prop-ext-≃ trunc-is-prop 𝟙-is-prop
           ((λ _  )  , λ {    a } )

  trunc-finite-zero-size :  {}  {X : Type }
     isFinite X
     X  𝟘 
     isFinite  X 
  trunc-finite-zero-size {} {X} X-is-finite e
    = equiv-preserves-finiteness (≃-sym helper) 𝟘-is-finite
    where
    helper :  X   𝟘 
    helper = prop-ext-≃ trunc-is-prop 𝟘-is-prop
     ((λ x  trunc-elim 𝟘-is-prop (apply e) x) , λ {()})

  trunc-is-finite-positive-size :  {}  {X : Type }
     ((m , p) : isFinite X)
     _<_  0 m
     isFinite ( X )
  trunc-is-finite-positive-size {} {X} (m , p) o
    = 1 , trunc-elim trunc-is-prop  e 
         ≃-trans
          ( prop-ext-≃ trunc-is-prop 𝟙-is-prop ((λ _  )
            , λ _   (rapply e) (zero , o) ))
          (𝟙-≃-⟦1⟧ )  ) p

  ∥∥-finite
    :  {}  {X : Type }
     isFinite X
     isFinite  X 
  ∥∥-finite {}{X} X-is-finite
    with _≟nat_  (π₁ X-is-finite) zero
  ... | yes idp = trunc-elim being-finite-is-prop
      ( λ X≃[0]  trunc-finite-zero-size X-is-finite
          (≃-trans X≃[0] (≃-sym (𝟘-≃-⟦0⟧ ))) ) (π₂ X-is-finite)
  ... | no  n>0 = trunc-is-finite-positive-size X-is-finite (n≠0  n>0)

  module
    _
    (∏-finite :  {ℓ₁ ℓ₂} {A : Type ℓ₁} {B : A  Type ℓ₂}
                 isFinite A  ((a : A)  isFinite (B a))  isFinite ( A B))
    (∑-finite :  {ℓ₁ ℓ₂} {A : Type ℓ₁} {B : A  Type ℓ₂}
          isFinite A  ((a : A)  isFinite (B a))  isFinite ( A B))
    where

    ≃-finite
      :  {}  {X Y : Type }
       isFinite X  isFinite Y
      -- ──────────────────────
       isFinite (X  Y)
    ≃-finite {X = X} {Y} X-is-finite Y-is-finite
      = ∑-finite (∏-finite X-is-finite  _  Y-is-finite))
                  _  ∏-finite Y-is-finite
                    _  contr-is-finite))
        where
        fib-is-finite :  {f : X  Y}  {b : Y}  isFinite (fib f b)
        fib-is-finite {f = f} {b}
          = ∑-finite X-is-finite  _  ≡-finite Y-is-finite)

        contr-is-finite :  {f : X  Y}  {b : Y}  isFinite (isContr (fib f b))
        contr-is-finite {f = f} {b} = ∑-finite fib-is-finite  _ 
                           ∏-finite fib-is-finite  _  ≡-finite fib-is-finite))

Latest changes

(2022-12-28)(57c278b4) Last updated: 2021-09-16 15:00:00 by jonathan.cubides
(2022-07-06)(d3a4a8cf) minors by jonathan.cubides
(2022-01-26)(4aef326b) [ reports ] added some revisions by jonathan.cubides
(2021-12-20)(049db6a8) Added code of cubical experiments. by jonathan.cubides
(2021-12-20)(961730c9) [ html ] regular update by jonathan.cubides
(2021-12-20)(e0ef9faa) Fixed compilation and format, remove hidden parts by jonathan.cubides
(2021-12-20)(5120e5d1) Added cubical experiment to the master by jonathan.cubides
(2021-12-17)(828fdd0a) More revisions added for CPP by jonathan.cubides
(2021-12-15)(0d6a99d8) Fixed some broken links and descriptions by jonathan.cubides
(2021-12-15)(662a1f2d) [ .gitignore ] add by jonathan.cubides
(2021-12-15)(0630ce66) Minor fixes by jonathan.cubides
(2021-12-13)(04f10eba) Fixed a lot of details by jonathan.cubides
(2021-12-10)(24195c9f) [ .gitignore ] ignore .zip and arxiv related files by jonathan.cubides
(2021-12-09)(538d2859) minor fixes before dinner by jonathan.cubides
(2021-12-09)(36a1a69f) [ planar.pdf ] w.i.p revisions to share on arxiv first by jonathan.cubides