# Michael Shulman dependent types in a 2-category

This is just bits and pieces for now; something more coherent will come later.

# Overview

Of course, we should be able to treat an $n$-type as an $m$-type for any $m\ge n$. When $n=-1$ and $m=0$ this corresponds to replacing a proposition $\phi$ by the set $\left\{*\mid \phi \right\}$, while when $n=0$ and $m=1$ it corresponds to treating a set as a discrete category. It should also be true that the resulting $m$-type is appropriately truncated.

## Type-raising

The following operations allow us to interpret an $n$-type as an $m$-type whenever $m\ge n$.

$\frac{\Gamma ⊢A:n\mathrm{Type}}{\Gamma ⊢\mid A\mid :\left(n+1\right)\mathrm{Type}}\left(n=0,-1\right)$\frac{\Gamma \vdash A:n Type} {\Gamma\vdash {|A|}:(n+1) Type} (n = 0,-1)

$\frac{\Gamma ⊢A:n\mathrm{Type}}{\Gamma ,x:A⊢{i}_{n}\left(x\right):\mid A\mid }\left(n=0,-1\right)$\frac{\Gamma \vdash A:n Type} {\Gamma, x:A \vdash i_n(x) : {|A|}} (n = 0,-1)

$\frac{\Gamma ⊢A:n\mathrm{Type}}{\Gamma ,x:\mid A\mid ⊢{j}_{n}\left(x\right):A}\left(n=0,-1\right)$\frac{\Gamma \vdash A:n Type} {\Gamma, x:{|A|} \vdash j_n(x) : A} (n = 0,-1)

$\frac{\Gamma ⊢A:n\mathrm{Type}}{\Gamma ,x:A⊢x\equiv {j}_{n}\left({i}_{n}\left(x\right)\right):A}\left(n=0,-1\right)$\frac{\Gamma \vdash A:n Type} {\Gamma, x:A \vdash x\equiv j_n(i_n(x)) : A} (n = 0,-1)

$\frac{\Gamma ⊢A:n\mathrm{Type}}{\Gamma ,x:\mid A\mid ⊢x\equiv {i}_{n}\left({j}_{n}\left(x\right)\right):\mid A\mid }\left(n=0,-1\right)$\frac{\Gamma \vdash A:n Type} {\Gamma, x:{|A|} \vdash x\equiv i_n(j_n(x)) : {|A|}} (n = 0,-1)

It follows that if $\phi :\mathrm{Prop}$, then $x:\mid \phi \mid ,y:\mid \phi \mid ⊢x\equiv y$, since ${j}_{-1}\left(x\right)\equiv {j}_{-1}\left(y\right)$ as both are terms of a $\left(-1\right)$-type $\phi$. Thus, $\mid \phi \mid$ is in fact a subsingleton as desired. What remains to assert is that if $A:\mathrm{Set}$ then $\mid A\mid :\mathrm{Cat}$ is a discrete category.

$\frac{\Gamma ⊢A:\mathrm{Set}}{\Gamma ,x:\mid A\mid ,y:\mid A\mid ,f:{\mathrm{hom}}_{\mid A\mid }\left(x,y\right)⊢\left(x\equiv y\right)}$\frac{\Gamma \vdash A:Set} {\Gamma, x:{|A|}, y:{|A|}, f:hom_{|A|}(x,y) \vdash (x \equiv y)}

$\frac{\Gamma ⊢A:\mathrm{Set}}{\Gamma ,x:\mid A\mid ,f:{\mathrm{hom}}_{\mid A\mid }\left(x,x\right)⊢\left(f\equiv {1}_{x}\right)}$\frac{\Gamma \vdash A:Set} {\Gamma, x:{|A|}, f:hom_{|A|}(x,x) \vdash (f \equiv 1_x)}

## Dependent sums

In theory, the ways to type the formation of dependent sums ${\Sigma }_{x:A}B\left(x\right)$ are parametrized by three sorts: the sort of $A$, the sort of $B$, and the sort of the result. In our case, we allow two general classes of dependent sums.

• In the first, $B$ must be a proposition, while $A$ can be anything, and in this case the result is a proposition. This construction gives existential quantifiers, so we will notate it as $\left(\exists x:A\right)B\left(x\right)$.
• In the second, $A$ must be a set, while $B$ can be anything, and the result has the same sort as $B$. This construction gives “indexed disjoint unions,” and we will use the ordinary dependent sum notation ${\Sigma }_{x:A}B\left(x\right)$ for it.

Note that in the overlap case when $A$ is a set and $B$ is a proposition, we get two different ways to form a dependent sum ${\Sigma }_{x:A}B\left(x\right)$ depending on what the result type is. If the result is a proposition, then it is the proposition $\left(\exists x:A\right)B\left(x\right)$, while if the result is a set, then it is the set $\left\{x:A\mid B\left(x\right)\right\}$. The difference from a computational point of view is that in the second case, it is possible to extract the witness $x:A$, while in the first it is not.

There should also be dependent sums of the second sort where $A$ is a category, with the result being a category. However, in this case, unless the dependence of $B$ on $A$ is given functorially, then it is not possible to determine the morphisms in the dependent sum. We will study the general case of functorially dependent types elsewhere, but here we do need one particular case.

### Strong dependent sums

$\frac{\Gamma ⊢A:\mathrm{Set}\phantom{\rule{2em}{0ex}}\Gamma ,x:A⊢B\left(x\right):n\mathrm{Type}}{\Gamma ⊢{\Sigma }_{x:A}B\left(x\right):n\mathrm{Type}}$\frac{\Gamma \vdash A:Set \qquad \Gamma, x:A \vdash B(x):n Type}{ \Gamma \vdash \Sigma_{x:A}B(x) :n Type}

$\frac{\Gamma ⊢A:\mathrm{Set}\phantom{\rule{2em}{0ex}}\Gamma ,x:A⊢B\left(x\right):n\mathrm{Type}}{\Gamma ,x:A,y:B\left(x\right)⊢⟨x,y⟩:{\Sigma }_{x:A}B\left(x\right)}$\frac{\Gamma \vdash A:Set \qquad \Gamma, x:A \vdash B(x):n Type}{\Gamma, x:A, y:B(x) \vdash \langle x,y\rangle : \Sigma_{x:A} B(x)}

$\frac{\Gamma ⊢A:\mathrm{Set}\phantom{\rule{2em}{0ex}}\Gamma ,x:A⊢B\left(x\right):n\mathrm{Type}}{\Gamma ,z:{\Sigma }_{x:A}B\left(x\right)⊢{\pi }_{1}\left(z\right):A}$\frac{\Gamma \vdash A:Set \qquad \Gamma, x:A \vdash B(x):n Type} {\Gamma, z: \Sigma_{x:A}B(x) \vdash \pi_1(z) :A}

$\frac{\Gamma ⊢A:\mathrm{Set}\phantom{\rule{2em}{0ex}}\Gamma ,x:A⊢B\left(x\right):n\mathrm{Type}}{\Gamma ,z:{\Sigma }_{x:A}B\left(x\right)⊢{\pi }_{2}\left(z\right):B\left({\pi }_{1}\left(x\right)\right)}$\frac{\Gamma \vdash A:Set \qquad \Gamma, x:A \vdash B(x):n Type} {\Gamma, z: \Sigma_{x:A}B(x) \vdash \pi_2(z) :B(\pi_1(x))}

$\frac{\Gamma ⊢A:\mathrm{Set}\phantom{\rule{2em}{0ex}}\Gamma ,x:A⊢B\left(x\right):n\mathrm{Type}}{\Gamma ,x:A,y:B\left(x\right)⊢{\pi }_{1}\left(⟨x,y⟩\right)\equiv x:A}$\frac{\Gamma \vdash A:Set \qquad \Gamma, x:A \vdash B(x):n Type}{\Gamma, x:A, y:B(x) \vdash \pi_1(\langle x,y\rangle) \equiv x : A}

$\frac{\Gamma ⊢A:\mathrm{Set}\phantom{\rule{2em}{0ex}}\Gamma ,x:A⊢B\left(x\right):n\mathrm{Type}}{\Gamma ,x:A,y:B\left(x\right)⊢{\pi }_{2}\left(⟨x,y⟩\right)\equiv y:A\left(x\right)}$\frac{\Gamma \vdash A:Set \qquad \Gamma, x:A \vdash B(x):n Type}{\Gamma, x:A, y:B(x) \vdash \pi_2(\langle x,y\rangle) \equiv y : A(x)}

$\frac{\Gamma ⊢A:\mathrm{Set}\phantom{\rule{2em}{0ex}}\Gamma ,x:A⊢B\left(x\right):n\mathrm{Type}}{\Gamma ,z:{\Sigma }_{x:A}B\left(x\right)⊢z\equiv ⟨{\pi }_{1}\left(z\right),{\pi }_{2}\left(z\right)⟩:{\Sigma }_{x:A}B\left(x\right)}$\frac{\Gamma \vdash A:Set \qquad \Gamma, x:A \vdash B(x):n Type} {\Gamma, z: \Sigma_{x:A}B(x) \vdash z \equiv \langle \pi_1(z), \pi_2(z)\rangle :\Sigma_{x:A}B(x)}

Note that when $n=0$ and $B\left(x\right)$ is independent of $x$, then ${\Sigma }_{x:A}B\left(x\right)$ is canonically isomomorphic to $A×B$. In ordinary type theory, one doesn’t need to define both binary products and dependent sums, since the former can be constructed from the latter in this way. However, since we aren’t allowing dependent sums over categories, we need binary products for categories given separately.

When $n=1$ we also have rules for morphisms.

$\frac{\Gamma ⊢A:\mathrm{Set}\phantom{\rule{2em}{0ex}}\Gamma ,x:A⊢B\left(x\right):\mathrm{Cat}}{\Gamma ,x:A,{y}_{1}:B\left(x\right),{y}_{2}:B\left(x\right),f:{\mathrm{hom}}_{B\left(x\right)}\left({y}_{1},{y}_{2}\right)⊢⟨x,f⟩:{\mathrm{hom}}_{{\Sigma }_{x:A}B\left(x\right)}\left(⟨x,{y}_{1}⟩,⟨x,{y}_{2}⟩\right)}$\frac{\Gamma \vdash A:Set \qquad \Gamma, x:A \vdash B(x):Cat} {\Gamma, x:A, y_1:B(x), y_2:B(x), f:hom_{B(x)}(y_1,y_2) \vdash \langle x,f\rangle : hom_{\Sigma_{x:A} B(x)}(\langle x,y_1\rangle, \langle x,y_2\rangle)}

$\frac{\Gamma ⊢A:\mathrm{Set}\phantom{\rule{2em}{0ex}}\Gamma ,x:A⊢B\left(x\right):\mathrm{Cat}}{\Gamma ,{z}_{1}:{\Sigma }_{x:A}B\left(x\right),{z}_{2}:{\Sigma }_{x:A}B\left(x\right),f:{\mathrm{hom}}_{{\Sigma }_{x:A}B\left(x\right)}\left({z}_{1},{z}_{2}\right)⊢{\pi }_{1}\left({z}_{1}\right)\equiv {\pi }_{2}\left({z}_{2}\right):A}$\frac{\Gamma \vdash A:Set \qquad \Gamma, x:A \vdash B(x):Cat} {\Gamma, z_1: \Sigma_{x:A}B(x), z_2 : \Sigma_{x:A}B(x), f:hom_{\Sigma_{x:A}B(x)}(z_1,z_2) \vdash \pi_1(z_1)\equiv \pi_2(z_2): A}

$\frac{\Gamma ⊢A:\mathrm{Set}\phantom{\rule{2em}{0ex}}\Gamma ,x:A⊢B\left(x\right):\mathrm{Cat}}{\Gamma ,{z}_{1}:{\Sigma }_{x:A}B\left(x\right),{z}_{2}:{\Sigma }_{x:A}B\left(x\right),f:{\mathrm{hom}}_{{\Sigma }_{x:A}B\left(x\right)}\left({z}_{1},{z}_{2}\right)⊢{\pi }_{2}\left(f\right):{\mathrm{hom}}_{B\left({\pi }_{1}\left(x\right)\right)}\left({\pi }_{2}\left({z}_{1}\right),{\pi }_{2}\left({z}_{2}\right)\right)}$\frac{\Gamma \vdash A:Set \qquad \Gamma, x:A \vdash B(x):Cat} {\Gamma, z_1: \Sigma_{x:A}B(x), z_2 : \Sigma_{x:A}B(x), f:hom_{\Sigma_{x:A}B(x)}(z_1,z_2) \vdash \pi_2(f): hom_{B(\pi_1(x))}(\pi_2(z_1),\pi_2(z_2))}

$\frac{\Gamma ⊢A:\mathrm{Set}\phantom{\rule{2em}{0ex}}\Gamma ,x:A⊢B\left(x\right):\mathrm{Cat}}{\Gamma ,x:A,{y}_{1}:B\left(x\right),{y}_{2}:B\left(x\right),f:{\mathrm{hom}}_{B\left(x\right)}\left({y}_{1},{y}_{2}\right)⊢f\equiv {\pi }_{2}\left(⟨x,f⟩\right):{\mathrm{hom}}_{B\left(x\right)}\left({y}_{1},{y}_{2}\right)}$\frac{\Gamma \vdash A:Set \qquad \Gamma, x:A \vdash B(x):Cat} {\Gamma, x:A, y_1:B(x), y_2:B(x), f:hom_{B(x)}(y_1,y_2) \vdash f \equiv \pi_2(\langle x,f\rangle) : hom_{B(x)}(y_1,y_2)}

$\frac{\Gamma ⊢A:\mathrm{Set}\phantom{\rule{2em}{0ex}}\Gamma ,x:A⊢B\left(x\right):\mathrm{Cat}}{\Gamma ,{z}_{1}:{\Sigma }_{x:A}B\left(x\right),{z}_{2}:{\Sigma }_{x:A}B\left(x\right),f:{\mathrm{hom}}_{{\Sigma }_{x:A}B\left(x\right)}\left({z}_{1},{z}_{2}\right)⊢f\equiv ⟨{\pi }_{1}\left(z\right),{\pi }_{2}\left(f\right)⟩:{\mathrm{hom}}_{{\Sigma }_{x:A}B\left(x\right)}\left({z}_{1},{z}_{2}\right)}$\frac{\Gamma \vdash A:Set \qquad \Gamma, x:A \vdash B(x):Cat} {\Gamma, z_1: \Sigma_{x:A}B(x), z_2 : \Sigma_{x:A}B(x), f:hom_{\Sigma_{x:A}B(x)}(z_1,z_2) \vdash f\equiv \langle \pi_1(z), \pi_2(f)\rangle: hom_{\Sigma_{x:A}B(x)}(z_1,z_2)}

## Dependent products

As with dependent sums, in general the operation ${\Pi }_{x:A}B\left(x\right)$ is parametrized by the sorts of $A$, of $B\left(x\right)$, and of the result. Since exponentials in a 2-category require fibrations and variance, for now we restrict to the case when $B\left(x\right)$ and ${\Pi }_{x:A}B\left(x\right)$ are both propositions. When $A$ is a set or a category, this gives universal quantification, which we write as $\left(\forall x:A\right)B\left(x\right)$, while when $A$ is also a proposition it gives implication, which we write as $A⇒B$.