bsc-leon-vatthauer/agda/bsc-thesis/Category.Ambient.Setoids.md
2024-02-09 17:53:52 +01:00

63 KiB
Raw Blame History

The category of Setoids can be used as instance for ambient category

Most of the required properties are already proven in the agda-categories library, we are only left to construct the natural numbers object.

module Category.Ambient.Setoids {} where
  open _⟶_ using (cong)

  -- equality on setoid functions
  private
    _≋_ :  {A B : Setoid  }  A  B  A  B  Set 
    _≋_ {A} {B} f g = Setoid._≈_ (A  B) f g
    ≋-sym :  {A B : Setoid  } {f g : A  B}  f  g  g  f
    ≋-sym {A} {B} {f} {g} = IsEquivalence.sym (Setoid.isEquivalence (A  B)) {f} {g}
    ≋-trans :  {A B : Setoid  } {f g h : A  B}  f  g  g  h  f  h
    ≋-trans {A} {B} {f} {g} {h} = IsEquivalence.trans (Setoid.isEquivalence (A  B)) {f} {g} {h}

  -- we define  ourselves, instead of importing it, to avoid lifting the universe levels (builtin Nats are defined on Set₀)
  data  : Set  where
    zero : 
    suc :   

  suc-cong :  {n m}  n  m  suc n  suc m
  suc-cong n≡m rewrite n≡m = Eq.refl

  suc-inj :  {n m}  suc n  suc m  n  m
  suc-inj Eq.refl = Eq.refl

  -eq : Rel  
  -eq zero zero = 
  -eq zero (suc m) = 
  -eq (suc n) zero = 
  -eq (suc n) (suc m) = -eq n m

  -setoid : Setoid  
  -setoid = record { Carrier =  ; _≈_ = _≡_ ; isEquivalence = Eq.isEquivalence }

  -setoid : Setoid  
  -setoid = record 
    { Carrier =  
    ; _≈_ = _≡_ -- -eq 
    ; isEquivalence = Eq.isEquivalence 
    }
  
  zero⟶ : SingletonSetoid {} {}  -setoid
  zero⟶ = record { to = λ _  zero ; cong = λ x  Eq.refl } 
  suc⟶ : -setoid  -setoid
  suc⟶ = record { to = suc ; cong = suc-cong }

  -universal :  {A : Setoid  }  SingletonSetoid {} {}  A  A  A  -setoid  A
  -universal {A} z s = record { to = app ; cong = cong' }
    where
      app :   Setoid.Carrier A
      app zero = z ⟨$⟩ tt
      app (suc n) = s ⟨$⟩ (app n)
      cong' :  {n m : }  n  m  Setoid._≈_ A (app n) (app m)
      cong' Eq.refl = IsEquivalence.refl (Setoid.isEquivalence A)
    
  -z-commute :  {A : Setoid  } {q : SingletonSetoid {} {}  A} {f : A  A}  q  (-universal q f  zero⟶)
  -z-commute {A} {q} {f} {lift t} = IsEquivalence.refl (Setoid.isEquivalence A)

  -s-commute :  {A : Setoid  } {q : SingletonSetoid {} {}  A} {f : A  A}  (f  (-universal q f))  (-universal q f  suc⟶)
  -s-commute {A} {q} {f} {n} = IsEquivalence.refl (Setoid.isEquivalence A)

  -unique :  {A : Setoid  } {q : SingletonSetoid {} {}  A} {f : A  A} {u : -setoid  A}  q  (u  zero⟶)  (f  u)  (u  suc⟶)  u  -universal q f
  -unique {A} {q} {f} {u} qz fs {zero} = ≋-sym {SingletonSetoid} {A} {q} {u  zero⟶} qz
  -unique {A} {q} {f} {u} qz fs {suc n} = AR.begin 
    u ⟨$⟩ suc n                                            AR.≈⟨ ≋-sym {-setoid} {A} {f  u} {u  suc⟶} fs  
    f  u ⟨$⟩ n                                            AR.≈⟨ cong f (-unique {A} {q} {f} {u} qz fs {n})  
    f  -universal q f ⟨$⟩ n                              AR.≈⟨ -s-commute {A} {q} {f} {n}  
    -universal q f ⟨$⟩ suc n                              AR.∎
    where module AR = SetoidR A

  setoidNNO : NNO (Setoids  ) SingletonSetoid-
  setoidNNO = record 
    { N = -setoid 
    ; isNNO = record
      { z = zero⟶
      ; s = suc⟶
      ; universal = -universal
      ; z-commute = λ {A} {q} {f}  -z-commute {A} {q} {f}
      ; s-commute = λ {A} {q} {f} {n}  -s-commute {A} {q} {f} {n}
      ; unique = λ {A} {q} {f} {u} qz fs  -unique {A} {q} {f} {u} qz fs
      }
    }

  setoidAmbient : Ambient (-suc )  
  setoidAmbient = record { C = Setoids   ; extensive = Setoids-Extensive  ; cartesian = Setoids-Cartesian ;  = NNO×CCC⇒PNNO (record { U = Setoids   ; cartesianClosed = Setoids-CCC  }) (Cocartesian.coproducts (Setoids-Cocartesian {} {})) setoidNNO }