Quantcast
Channel: Mike Shulman – Homotopy Type Theory
Viewing all articles
Browse latest Browse all 10

Impredicative Encodings, Part 3

$
0
0

In this post I will argue that, improving on previous work of Awodey-Frey-Speight, (higher) inductive types can be defined using impredicative encodings with their full dependent induction principles — in particular, eliminating into all type families without any truncation hypotheses — in ordinary (impredicative) Book HoTT without any further bells or whistles. But before explaining that and what it means, let me review the state of the art.

Categorically, a (higher) inductive type is an initial object in some category. For instance, the coproduct of A and B is the initial object of the category of types X equipped with maps A\to X and B\to X; and the circle S^1 is the initial object of the category of types X equipped with a point b:X and an equality l:b=_X b. A (H)IT is therefore a kind of “colimity” thing, while an “impredicative encoding” of it is a way to construct it (or an approximation thereof) using limits instead — specifically, large limits, which requires a universe closed under impredicative quantification (i.e. \Pi-types whose domain is not necessarily an element of the universe).

The most basic such encodings (usually associated with System F) approximate the initial object of a category by the product of all objects of that category. For instance, the System F coproduct A+B is the product of all types X equipped with maps A\to X and B\to X, which in type-theoretic syntax becomes

\prod_{X:\mathcal{U}} (A\to X)\to (B\to X) \to X.

Such impredicative encodings of ordinary inductive types are well-known in type theory, and back when we were first discovering HITs I blogged here about the fact that they can also be encoded impredicatively. However, these basic encodings have the problem that they don’t satisfy the “uniqueness principle” or \eta-conversion, and (equivalently) they don’t support a “dependent eliminator” or “induction principle”, only the non-dependent “recursion principle”. In categorical language, the product of all objects of a category, even if it exists, is only a weak initial object.

Last year, Sam Speight blogged here about a way to fix this problem (paper here with Awodey and Frey), by defining a (higher) inductive type to be the limit of the identity functor of the category in question, and appealing to this theorem. Such a limit, if constructed out of products and equalizers, appears as a subobject of the product of all objects; and if we “compile out” this definition in type theory, it adds additional assertions that System F encoding data is natural. For instance, the coproduct becomes

\sum_{\alpha:\prod_{X:\mathsf{Set}_{\mathcal{U}}} (A\to X)\to (B\to X) \to X} \prod_{X,Y:\mathsf{Set}_{\mathcal{U}}} \prod_{f:X\to Y} \prod_{h:A\to X} \prod_{k:B\to X} f(\alpha_X(h,k)) = \alpha_Y(f\circ h, f\circ k).

This approach is very nice, but unfortunately it only works for h-sets, i.e. 0-types. That is, given two sets A,B, it produces a coproduct set A+B, which has a dependent induction principle that can only eliminate into other sets. Categorically, the point is that the construction of limits out of products and equalizers works in a 1-category, but not in a higher category. We can boost up the dimension one at a time by adding additional coherence conditions — the paper ends with an example of S^1 constructed as a 1-type with a dependent induction principle that can eliminate into other 1-types (but not higher types) — but this approach offers no hope of an induction principle into types that are not n-truncated for any n. If we could solve the “problem of infinite objects” (perhaps by working in a context like two-level type theory) maybe we could add “all the coherence conditions at once”, although the path algebra would probably get quite hairy.

Surprisingly (to me), it turns out that there is a different solution, which works in (impredicative) Book HoTT without any bells or whistles. Recall that theorem about initial objects as limits of identity functors, and note that it’s proven using this lemma, which says that if I is an object of a category equipped with a natural transformation from the constant functor \Delta I to the identity functor, i.e. a cone consisting of maps p_X:I\to X for all objects X such that f\circ p_X = p_Y for all morphisms f:X\to Y, and moreover p_I:I\to I is the identity morphism, then I is initial. Can we use this lemma directly?

You might think this is no better, since even obtaining a fully-coherent \infty-natural transformation p_X:I\to X already involves infinitely many coherence conditions. However, inspecting the proof of this lemma, we see that it will work in HoTT even for an “incoherent” natural transformation, essentially because the definition of contractibility is a propositions-as-types translation of being a singleton set. That is, to show that I is initial in \mathcal{C}, we want to show that \hom_{\mathcal{C}}(I,X) is contractible. We take its center to be p_X, and then we must show that any f:I\to X is equal to p_X. But by incoherent naturality, we have p_X = f\circ p_I, which is equal to f since p_I = \mathsf{id}_I.

This is great, because the 0-type version of the Awodey-Frey-Speight construction, if written down with the full universe \mathcal{U} in place of \mathsf{Set}_{\mathcal{U}}, already comes with an incoherent cone over the identity functor. So “all” we need to do is ensure p_I = \mathsf{id}_I. (Note that this is a version of \eta for an inductive type.)

Here’s the trick. Note that the proof of the lemma shows I is initial by applying the naturality property in a case where one of the objects is I itself. Let’s try to prove p_I is the identity by applying that same naturality property in the case where the morphism is p_I:I\to I itself. This gives us p_I \circ p_I = p_I. In other words, although p_I may not (yet) be the identity, it’s already the next best thing: an idempotent. And in the words of Robinson and Rosolini,

No category theorist can see an idempotent without feeling the urge to split it.

This is especially true when we were hoping that that idempotent would turn out to be an identity, since splitting it is a way to “make” it an identity. And in fact it’s not hard to show with categorical algebra that if r:I\to J and s:J\to I are a splitting of p_I (so that s r = p_I and r s = \mathsf{id}_J), where p_X:I\to X is a cone over the identity functor, then J is initial. For we have another cone p_X s : J\to X, whose J-component is p_J s. And we have p_J = r s p_J = r p_I = r s r = r, using naturality s p_J = p_I and the splitting equations, so p_J s = r s = \mathsf{id}_J, so the lemma applies. Note that this argument also uses no higher coherence, and so should work just fine for an incoherent natural transformation.

What’s left is to split the idempotent p_I in type theory. Fortunately, I wrote a paper a few years ago (original blog posts here and here) about precisely this problem, inspired by analogous results of Lurie in higher category theory. It turns out that an arbitrary “incoherent idempotent” (a map q equipped with an equality q\circ q = q) may not be splittable, but as soon as the “witness of idempotency” h: q\circ q = q satisfies one additional coherence condition (not the infinite tower of such one might expect), the map q can be split. And in our situation, we can obtain this one additional coherence condition for the naturality triangle p_I \circ p_I = p_I by using the 1-type version of the Awodey-Frey-Speight construction. (Actually, we can even omit their unit condition; all we need is the composition coherence for pseudonaturality.)

I’ve verified in Coq that this works for coproducts, using type-in-type for impredicativity. (I don’t think Coq’s built-in impredicative-set option is compatible with the HoTT library, which has tried to excise Coq’s built-in smallest universe Set as much as possible.) Most of the proof is quite easy; the longest part (40 lines of path algebra) is deducing the idempotence coherence condition from the naturality coherence condition. As expected, we only get typal computation rules for the induction principle — although we do have definitional computation rules for the recursion principle (i.e. the non-dependent eliminator). More precisely, there is a non-dependent eliminator (a special one, not just the dependent eliminator specialized to a non-dependent motive) that satisfies a definitional computation rule.

I’m working on coding it up for higher inductive types as well, but the path algebra gets quite annoying. Further bulletins as events warrant.

To conclude, let me point out that I find this a very satisfying answer to the question with which I ended my second idempotents post:

… [For equivalences] we also have a “fully coherent” notion \mathsf{IsEquiv}(f)… that is a retract of a type \mathsf{QInv}(f) of “partially coherent” objects…. Are there any other structures that behave like this? Are there any other “fully coherent” gadgets that we can obtain by splitting an idempotent on a type of partially-coherent ones?

The answer is yes: a fully-coherent impredicative encoding can be obtained by splitting an idempotent on a partially-coherent one.


Viewing all articles
Browse latest Browse all 10

Trending Articles