Free cocompletion (source code)

= Free cocompletion
{title2=$\widehat{\mathcal C}=[\mathcal C^{\mathrm{op}},\mathbf{Set}]$}

For a <small category> $\mathcal C$, its <presheaf category> is the free enlargement under small <colimits>. Each <categorical presheaf> $P$ is the colimit of the diagram sending $(C,x)\in\int P$ to the <representable presheaf> $yC$. The map at $(C,x)$ sends $f:A\to C$ to $P(f)x$. It is surjective at each $A$ because $z\in P(A)$ is the image of $1_A$ at $(A,z)$. If two representatives have the same image $z$, they are both identified with the representative $1_A$ at $(A,z)$ by arrows in the <category of elements>, proving injectivity. Thus $P\cong\operatorname{colim}_{(C,x)\in\int P}yC$. For a cocomplete target, a functor on $\mathcal C$ extends by these colimits, uniquely up to natural isomorphism among colimit-preserving extensions.