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

module Deltaplus where

{- Chapter 9.2: Semi-Simplicial Types

   This file contains the definition of the index category 
   for semi-simplicial with judgmental categorical laws: Δ₊
   In other words, we check Proposition 9.2.1.

   We want to keep it independent of the other files,
   so we do not import anything. -}

{- For simplicity, we only use the lowest universe
   (totally sufficient) -} 
Type = Set 

-- the empty type
data Empty : Type where

-- the unit type
data  : Type where
  * : 

-- the natural numbers
data  : Type where
  O : 
  S : (n : )  


{- Finite types: these are the 

   ===  OBJECTS of Δ₊ ===

-}
data Fin :   Type where
  fz : {n : }  Fin (S n)
  fs : {n : }  Fin n  Fin (S n)

-- >-relation on finite types
_>fin_ : {n : }  (i j : Fin n)  Set
fz >fin i = Empty
fs j >fin fz = 
fs j >fin fs i = j >fin i

{- the proposition [we do not need to prove propositionality here, but 
   we could prove it easily] that a function is increasing;
   this is the tricky part: it needs to be done in a way which ensures
   that composition will behave nicely (strictly associative etc) later -}
is-increasing : {m n : }  (Fin m  Fin n)  Type
is-increasing {m} {n} f = {j i : Fin m}  (j >fin i)  ((f j) >fin (f i))


infixr 1 _,_

record Σ (A : Type) (B : A  Type) : Type where
  constructor _,_
  field
    fst : A
    snd : B fst

{- Strictly increasing maps: these are the

   === MORPHISMS of Δ₊ ===

-}
_⇒+_ :     Set
m ⇒+ n = Σ (Fin m  Fin n) is-increasing

_∘+_ : {l m n : }  (m ⇒+ n)  (l ⇒+ m)  (l ⇒+ n)
(g , p₂) ∘+ (f , p₁) =  i  g(f(i))) ,  p  p₂ (p₁ p))


-- === IDENTITY MORPHISMS of Δ₊ ===

idΔ₊ :  {n}  n ⇒+ n
idΔ₊ =  x  x) ,  p  p)


{- Now, let us check that the categorical laws hold judgmentally.
   To do this, we use the usual notion of equality. -}

infix 3 _==_

data _==_ {A : Type} (a : A) : A  Type where
  idp : a == a


-- === IDENTITY LAWS ===

id-comp :  {m n}  (f : m ⇒+ n)  (idΔ₊ ∘+ f) == f
id-comp f = idp

comp-id :  {m n}  (f : m ⇒+ n)  (f ∘+ idΔ₊) == f
comp-id f = idp

-- === ASSOCIATIVITY LAW ===

comp-assoc :  {i j m n}  (f : i ⇒+ j)  (g : j ⇒+ m)  (h : m ⇒+ n)
              h ∘+ (g ∘+ f) == (h ∘+ g) ∘+ f
comp-assoc f g h = idp