Consider the problem of defining models of dependent type theory inside dependent type theory. To be concrete, suppose we want an internal definition of a *category with families* (CwF). This and similar problems have been considered before in various settings, and in this note we’ll think about encoding CwFs in the setting of book HoTT. Agda code accompanies, using the HoTT-Agda library (on a 2.6.1-compatible fork).

# Wildcats and their families

A category with families may be defined succinctly as a category \mathscr{C} of “contexts” and “substitutions” with a terminal object ◆, together with a presheaf (\mathrm{Ty}, \mathrm{Tm}) \colon \mathscr{C}^{op} → \mathrm{Fam} valued over the category of families of sets, along with a comprehension for each \sigma \in \mathrm{Ty}\,\Gamma for arbitrary \Gamma \in \mathscr{C} (I might write a short note explaining what all these terms mean in the future).

By expanding the above out in full as a generalized algebraic theory we can define a CwF type-theoretically as a Σ-type consisting of the usual structures and equations. As is usually the case for categorical constructions in HoTT, to make things well behaved we have two options: either set-truncate as needed, or “insert all required coherences”, of which there may be infinitely many. If we were to go the first route and require the contexts and substitutions to be h-sets, the underlying category of contexts would be strict in the HoTT book sense. Going the second route would eventually result in some kind of “∞-CwF”, whatever this might turn out to mean. But for now it’s possible to just ignore the issue and formulate the basic CwF structures on top of so-called *wild* categories without truncation or coherences. I’ll call such structures *wild CwF*s.

Functoriality of \mathrm{Ty} and \mathrm{Tm} means that the equations [Eqs. 1] \sigma [id_{\Gamma}] = \sigma \qquad \sigma [g \circ f] = \sigma [g] [f] t [id_{\Gamma}] = t \qquad t [g \circ f] = t [g] [f] hold for types \sigma and terms t, where · [f] denotes substitution along the morphism f. The important thing to note is that the equations for terms only typecheck up to the equations for types. This means that in book HoTT we need to formulate the latter two equations as *dependent* paths over the former two, and insert the required transports into terms as needed.

With this in mind, and assuming we already have the notion of a category of contexts and substitutions

```
: Type i
Con : Con → Con → Type i
Sub : {Γ : Con} → Sub Γ Γ
id : {Γ Δ Ε : Con} → Sub Δ Ε → Sub Γ Δ → Sub Γ Ε
◦ : Con
◆ : is-terminal ◆ ◆-t
```

with the usual laws, we can define the type and term structure of a CwF as a record with, among other things, the following fields for types, terms, and substitutions thereupon,

```
: Con → Type i
Ty : {Γ : Con} → Ty Γ → Type i
Tm
_[_] : {Γ Δ : Con} → Ty Δ → Sub Γ Δ → Ty Γ
_[_]ₜ : {Γ Δ : Con} {σ : Ty Δ} → Tm σ → (f : Sub Γ Δ) → Tm (σ [ f ])
```

equations for substitution as in [Eqs. 1],

```
: {Γ : Con} {σ : Ty Γ} → σ [ id ] == σ
[]-id : {Γ Δ Ε : Con} {f : Sub Γ Δ} {g : Sub Δ Ε} {σ : Ty Ε}
[]-◦ → σ [ g ◦ f ] == σ [ g ] [ f ]
: {Γ : Con} {σ : Ty Γ} {t : Tm σ} → tr Tm []-id (t [ id ]ₜ) == t
[]ₜ-id : {Γ Δ Ε : Con} {f : Sub Γ Δ} {g : Sub Δ Ε} {σ} {t : Tm σ}
[]ₜ-◦ → tr Tm []-◦ (t [ g ◦ f ]ₜ) == t [ g ]ₜ [ f ]ₜ
```

and context extension and projections.

(To be continued…)

# Related work

Previous work on internal formulations of models of type theory includes

*Type Theory should eat itself*[Ch08]*Shallow embedding of type theory is morally correct*[KKK18]*Internal ∞-Categorical Models of Dependent Type Theory: Towards 2LTT Eating HoTT*[Kr20]

and the paper which introduces CwFs:

The exact settings of these papers vary, in particular with respect to the equality of the theory along two axes: extensional–intensional and homogeneous–heterogeneous. As far as I can see, [Ch08] is intensional but heterogeneous, [KKK18] extensional, [Kr20] intensional homogeneous.

This is a note on work in progress. The concepts mentioned here are formalized in Agda and available on GitHub.