Chuangjie Xu 2026

This module defines the basic structure of a Category with Family (CwF).
Additional structure such as Pi types, Sigma types, and other type 
constructors are developed in separate, specialized modules to maintain 
modularity and clarity of the core definitions.

\begin{code}

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

module C-Spaces.CwFs.Base where

open import MLTT.Spartan

record CwFStructure : (๐“ค โŠ” ๐“ฅ)โบ ฬ‡ where
  field
    -- Category of contexts
    Con : ๐“ค ฬ‡
    Sub : Con โ†’ Con โ†’ ๐“ฅ ฬ‡
    idSub : {ฮ“ : Con} โ†’ Sub ฮ“ ฮ“
    _โ—‹_ : {ฮ“ ฮ” ฮ˜ : Con} โ†’ Sub ฮ” ฮ˜ โ†’ Sub ฮ“ ฮ” โ†’ Sub ฮ“ ฮ˜

    -- Terminal object, i.e., empty context
    ฮต : Con
    ฮตSub : {ฮ“ : Con} โ†’ Sub ฮ“ ฮต

    -- Type functor
    Ty : Con โ†’ ๐“ค ฬ‡
    _[_] : {ฮ“ ฮ” : Con} โ†’ Ty ฮ“ โ†’ Sub ฮ” ฮ“ โ†’ Ty ฮ”

    -- Term functor
    Tm : (ฮ“ : Con) โ†’ Ty ฮ“ โ†’ ๐“ฅ ฬ‡
    _โ…_โ† : {ฮ“ ฮ” : Con} {A : Ty ฮ“} โ†’ Tm ฮ“ A โ†’ (ฯƒ : Sub ฮ” ฮ“) โ†’ Tm ฮ” (A [ ฯƒ ])
    
    -- Context extension
    _โ‚Š_ : (ฮ“ : Con) โ†’ Ty ฮ“ โ†’ Con
    โŸจ_,_โŸฉ : {ฮ“ ฮ” : Con} {A : Ty ฮ“}
          โ†’ (ฯƒ : Sub ฮ” ฮ“) โ†’ Tm ฮ” (A [ ฯƒ ]) โ†’ Sub ฮ” (ฮ“ โ‚Š A)
    p : {ฮ“ : Con} {A : Ty ฮ“} โ†’ Sub (ฮ“ โ‚Š A) ฮ“
    q : {ฮ“ : Con} {A : Ty ฮ“} โ†’ Tm (ฮ“ โ‚Š A) (A [ p ])


record CwFLaws {๐“ค : Universe} {๐“ฅ : Universe}
               (S : CwFStructure {๐“ค} {๐“ฅ})
               : (๐“ค โŠ” ๐“ฅ)โบ ฬ‡ where
  open CwFStructure S
  field
    -- Rules for substitution
    idl : {ฮ“ ฮ” : Con} {ฯƒ : Sub ฮ“ ฮ”}
        โ†’ idSub โ—‹ ฯƒ ๏ผ ฯƒ
    idr : {ฮ“ ฮ” : Con} {ฯƒ : Sub ฮ“ ฮ”}
        โ†’ ฯƒ โ—‹ idSub ๏ผ ฯƒ
    โ—‹-assoc : {ฮ“ ฮ” ฮ˜ ฮž : Con} {ฯƒ : Sub ฮ˜ ฮž} {ฯ„ : Sub ฮ” ฮ˜} {ฯ : Sub ฮ“ ฮ”}
            โ†’ (ฯƒ โ—‹ ฯ„) โ—‹ ฯ ๏ผ ฯƒ โ—‹ (ฯ„ โ—‹ ฯ)
    ฮตSub-unique : {ฮ“ : Con} {ฯƒ : Sub ฮ“ ฮต}
                โ†’ ฯƒ ๏ผ ฮตSub

    -- Substitution laws for types
    ty[id] : {ฮ“ : Con} {A : Ty ฮ“}
           โ†’ A [ idSub ] ๏ผ A
    ty[โ—‹]  : {ฮ“ ฮ” ฮ˜ : Con} {A : Ty ฮ“} {ฯƒ : Sub ฮ” ฮ“} {ฯ„ : Sub ฮ˜ ฮ”}
           โ†’ A [ ฯƒ โ—‹ ฯ„ ] ๏ผ A [ ฯƒ ] [ ฯ„ ]

    -- Substitution laws for terms
    tm[id] : {ฮ“ : Con} {A : Ty ฮ“} {t : Tm ฮ“ A}
           โ†’ transport (Tm ฮ“) ty[id]
             (t โ… idSub โ†) ๏ผ t
    tm[โ—‹] : {ฮ“ ฮ” ฮ˜ : Con} {A : Ty ฮ“} {t : Tm ฮ“ A} {ฯƒ : Sub ฮ” ฮ“} {ฯ„ : Sub ฮ˜ ฮ”}
           โ†’ transport (Tm ฮ˜) ty[โ—‹]
             (t โ… ฯƒ โ—‹ ฯ„ โ†) ๏ผ t โ… ฯƒ โ† โ… ฯ„ โ†

    -- Laws for context extension
    p,-ฮฒ : {ฮ“ ฮ” : Con} {A : Ty ฮ“} {ฯƒ : Sub ฮ” ฮ“} {t : Tm ฮ” (A [ ฯƒ ])}
         โ†’ p โ—‹ โŸจ ฯƒ , t โŸฉ ๏ผ ฯƒ
    q,-ฮฒ : {ฮ“ ฮ” : Con} {A : Ty ฮ“} {ฯƒ : Sub ฮ” ฮ“} {t : Tm ฮ” (A [ ฯƒ ])}
         โ†’ transport (Tm ฮ”) {(A [ p ]) [ โŸจ ฯƒ , t โŸฉ ]} (ty[โ—‹] โปยน โˆ™ ap (A [_]) p,-ฮฒ)
          (q โ… โŸจ ฯƒ , t โŸฉ โ†) ๏ผ t
    p,q-ฮท : {ฮ“ ฮ” : Con} {A : Ty ฮ“} {ฯƒ : Sub ฮ” ฮ“} {t : Tm ฮ” (A [ ฯƒ ])}
          โ†’ โŸจ p , q โŸฉ ๏ผ idSub {ฮ“ โ‚Š A}
    ,โ—‹-distrib : {ฮ“ ฮ” ฮ˜ : Con} {A : Ty ฮ“} {ฯƒ : Sub ฮ” ฮ“} {t : Tm ฮ” (A [ ฯƒ ])} {ฯ„ : Sub ฮ˜ ฮ”}
               โ†’ โŸจ ฯƒ , t โŸฉ โ—‹ ฯ„ ๏ผ โŸจ ฯƒ โ—‹ ฯ„ , transport (Tm ฮ˜) {(A [ ฯƒ ]) [ ฯ„ ]} {A [ ฯƒ โ—‹ ฯ„ ]} (ty[โ—‹] โปยน)
                                           (t โ… ฯ„ โ†) โŸฉ

record CwF : (๐“ค โŠ” ๐“ฅ)โบ ฬ‡ where
  field
    structure : CwFStructure {๐“ค} {๐“ฅ}
    laws : CwFLaws structure

  open CwFStructure structure public
  open CwFLaws laws public

\end{code}