14
$\begingroup$

Quotients in constructive type theory are a bit of a pain. My understanding is that the first type theory that supported them well was cubical type theory, and in previous type theories the alternative was called "setoid hell".

On the other hand, consider how quotients are handled in CZF set theory:

Let $S$ be a set and $E \subseteq S \times S$ be an equivalence relation. Define $S/E$ as the image of the function that sends $a \in S$ to $$[a] = \{b \in S: (a,b) \in E \}$$ which exists due to the axiom schema of predicative separation. The image of $[ \cdot ]$ exists due to the axiom of replacement.

Theorem: $(a, b) \in E \iff [a] = [b]$ Proof: $(a, b) \in E \\ \iff \forall c \in S. ((a, c) \in E \iff (b, c) \in E) \\ \iff \forall c \in S. (c \in [a] \iff c \in [b]) \\ \iff [a] = [b] \\ \square$

Theorem: if a function $f$ on $S$ respects $E$, it factors through $[ \cdot ]$.
Proof: Let $g = \{([a], y) : (a,y) \in f \}$. Then $[a] = [b] \implies (a,b) \in E \implies f(a) = f(b)$. Thus $\forall x \in S/E. \exists! y. (x,y) \in g$, which is the definition of $g$ being a function in set theory. By definition $g([a]) = f(a)$. $\square$
(Works similarly for higher arity functions, even with multiple quotients as arguments.)

It also perhaps worth demonstrating an example. Let $X$ be a set and consider the following equivalence relation on $\mathbb R ^X$: $$(f,g) \in E \iff \exists k \in \mathbb N. \forall x \in X. |f(x) - g(x)| \le k$$ (i.e. the difference is $O(1)$). Then from a proof of $[f] = [g]$ we can actually construct a $k$ witnessing it! (CZF has the numerical existence property.) This works even if your proof of $[f] = [g]$ isn't directly from the first theorem (like the transitive property of equality, or substitution).

Notice how it is exactly the same as how you do quotients classically. Indeed, one might say that quotients were already constructive without needing any modification! Predicative as well (if you consider the axiom of replacement to be predicative).

Why doesn't this translate to type theory? For example:

  1. Couldn't you model types using sets? $\Sigma$ is just an indexed disjoint union and $\Pi$ is just an indexed product.
  2. Couldn't you model types using the setoids in another type theory?
  3. The above formulation works in topos theory since topoi have power objects. Couldn't you model constructive type theory using topos theory (for example, the free topos is constructive), and then model $S/E$ as a subobject of $\Omega^S$?
$\endgroup$
4
  • 7
    $\begingroup$ I'm not sure at what level of formality you want an answer, but an informal and handwavy one would be something like this: an equivalence class of $S$ under $E$ is a subset $C\subseteq S$ such that any two elements of $C$ are related by $E$, and such that there exists ($\exists$) an element in $C$. But Martin-Löf type theories don't really have an $\exists$: they have a $\Sigma$, which, unlike $\exists$, cannot (by construction) forget the witness that witnesses existence. But forgetting the element of $C$ which serves to construct it is what quotienting is all about! $\endgroup$ Commented Feb 6 at 23:19
  • 2
    $\begingroup$ And as for topoi, they satisfy a number of properties, like Unique Choice, Propositional Extensionality (viꝫ. the fact that if $p,q:\Omega$ and $p\Leftrightarrow q$ then $p=q$), Functional Extensionality (viꝫ. the fact that if $f,g:Y^X$ and $\forall x:X.f(x)=g(x)$ then $f=g$), Proof Irrelevance (viꝫ. if $\Omega$ is represented by subsingletons, so effectively if $p:\Omega$ and $e,e':p$ then $e=e'$), which type theorists don't necessarily want because they can spoil or complicate things like proof extraction. (The exact relations between the various properties I mentioned escape me, however.) $\endgroup$ Commented Feb 6 at 23:27
  • $\begingroup$ @Gro-Tsen I don't think the lack of $∃$ is the problem in MLTT since $∃$ does exist separately from $Σ$ in CIC, which still doesn't have the nice quotients we'd like. The real problem is whether $∃$ is provably proof-irrelevant in your version of type theory, as opposed to consistently proof-irrelevant. If you postulate proof irrelevance, quotients are fine but canonicity is broken. So the main problem really is how to compute with quotients, as Peter LeFanu Lumsdaine nicely explains in his answer. $\endgroup$ Commented Feb 7 at 0:39
  • 1
    $\begingroup$ In Lean there are quotients with pretty much the properties you'd expect, no setoid pain, but that comes at the price of an axiom Quot.sound which breaks canonicity. The Lean standard library has an explicit example of how functional extensionality breaks it, and on the same page you can find a proof that the axiom for quotients implies functional extensionality. To my knowledge, cubical type theory is the only currently available type theory with canonicity and pleasant quotients. $\endgroup$ Commented Feb 7 at 0:41

2 Answers 2

10
$\begingroup$

Allow me to restate part of Peter LeFanu Lumsdaine's great answer in more concrete terms. I should stress that I am not an expert at all, so I hope the actual experts will correct me if needed.

On the one hand, CZF and IZF-with-replacement have the disjunction and numerical existence properties, making them seem constructively acceptable. On the other hand, the problems we have with quotients in type theory are strongly related to how we compute with them. So where's the disconnect? In a word: canonicity.

Recall or learn that for a type theory to have the canonicity property means by definition that any closed normal term of an inductive type is headed by a constructor.

In particular, if canonicity is satisfied, by normalizing a proof of a closed proposition $∃ n ∈ ℕ. P(n)$, we get a term of the form $(n, x)$ (headed by the dependent pair constructor), and $n$ is in turn a normal term of type $ℕ$, hence a numeral, and $x$ is a proof of $P(n)$: we have the numerical existence property. Likewise we get the disjunction property. (Here I assume that $∨$ and $∃$ are inductive types as e.g. in the calculus of inductive constructions; the same applies mutatis mutandis with other variants.) But canonicity is a stronger property.

Stated very informally, type theory follows the Curry-Howard correspondence, which is an instance of the Brouwer-Heyting-Kolmogorov interpretation of proofs, and the canonicity property is a check that CH actually follows BHK. In set theory, there is no native notion of computation with proofs, so the best we can expect is simply an extraction of proofs to programs. But in type theory, we do have native computation — namely, proofs are terms, and there is a reduction relation on terms, which is a core part of the type theory because it is used to define when terms are convertible (definitional a.k.a. judgmental equality). In such a setting, we can hope that the reduction relation actually corresponds to the notion of executing the proof as a program that BHK tells us should exist. Even more informally, canonicity says that the type theory not only has a realizability model, but is its own realizability model.

Now, if we simply go through the construction of quotients we have in CZF to redo it in type theory, we have $S : \mathsf{Type}$, $E : S → S → \mathsf{Prop}$, and for $a : S$ we start by constructing the equivalence class $[a] :≡ λ x . E(a, x) : S → \mathsf{Prop}$. Next, we want to prove $E(a, b) ⇒ [a] = [b]$, so assume $E(a, b)$. In order to equate the equivalent propositions $E(a, x)$ and $E(b, x)$ for $x : A$, we need propositional extensionality. After that, in order to equate the pointwise equal functions $λ x . E(a, x)$ and $λ x . E(b, x)$, we need functional extensionality. In CZF, this is all taken care of by the set extensionality axiom $(∀ x, x ∈ a ⇔ x ∈ b) ⇒ a = b$. But type theorists don't much like simply bolting functional and propositional extensionality onto, say, the calculus of inductive constructions, because they break canonicity. (They do not break disjunction or numerical existence: basically, you can still convert terms with these axioms to executable programs, which theoreticians call interpreting in a realizability model and practitioners call code extraction. That is, for example, Rocq's extraction to OCaml, or Lean's bytecode interpreter. The point is that just reducing the terms blocks on unreducible applications of the axioms, but the extraction performs an amount of type erasure which dissolves the problem.)

Conversely, let's see why at least some amount of extensionality is necessary to have well-behaved quotients. This page of the Lean documentation shows that they entail functional extensionality. Given a type $A$ and an equivalence relation $R : A → A → \mathsf{Prop}$ on it, you certainly want that every function $f : A → B$ which respects $R$ factors through $\tilde{f} : A/R → B$, so that $\tilde{f}([x]) = f(x)$; but arguably, this should really be a definitional equality, because it is practically really annoying if it is not, and this is very similar to inductive types, for which the computation rules are always definitional. But then, consider the function space $A → B$ quotiented by $R$ the pointwise equality. For $a : A$, the function $λ (f : A → B) . f(a) : (A → B) → B$ obviously respects $R$, so it factors through a function $\mathsf{app}_a : (A → B)/R → B$ which satisfies $\mathsf{app}_a([f]) ≡ f(a)$ as a definitional equality. Then, if $f \ R \ g$, we have by η-expansion $f ≡ λ a . f(a) ≡ λ a . \mathsf{app}_a([f]) = λ a . \mathsf{app}_a([g]) ≡ λ a . g(a) ≡ g$.

This is far from the end of the story, but it does show that to get well-behaved quotients you need functional extensionality, and making that compatible with canonicity is already a major problem. To my knowledge, the only existing answer is cubical type theory, which proves univalence and in particular functional extensionality, and if I understand correctly can do quotients with higher inductive types.

$\endgroup$
9
  • $\begingroup$ Does cubical type theory actually have canonicity though? It seems like it has something people call homotopy canonicity, but the definitions I've seen of that seem to be roughly equivalent to just the existence property. I can't really see a reason why it would be inaccurate to say that IZF with replacement and CZF have homotopy canonicity. $\endgroup$ Commented Feb 17 at 17:05
  • $\begingroup$ @JamesEHanson Homotopy type theory as presented in the HoTT book (basically MLTT + univalence + higher inductive types) has only “homotopy canonicity”/“propositional canonicity” as per the paper from this answer that I linked earlier. $\endgroup$ Commented Feb 17 at 17:11
  • $\begingroup$ Cubical type theory is a more recent type theory, it features a special “interval” type and equalities become paths parameterized by an element in this type. It was proved early on to have propositional canonicity, and more recently to have in fact full canonicity. $\endgroup$ Commented Feb 17 at 17:11
  • $\begingroup$ Would there be something inaccurate about saying that CZF has homotopy canonicity or propositional canonicity? $\endgroup$ Commented Feb 17 at 17:13
  • $\begingroup$ No, I think that would be accurate. $\endgroup$ Commented Feb 17 at 17:15
15
$\begingroup$

This “problem” is I think often overstated — I’ll return to this as I go on. But yes, there are two rather different main senses in which quotients are somewhat problematic in constructive type theories:

  1. Can you construct them, as you can classically? (Answer: yes in some type theories, not in others.) Or do you need to assume them as primitive, or use a workaround like setoids?

  2. Whatever quotients you’ve got, how nice are they to work with? Do functions on them compute well? What about types dependent over them?

The first point is not such a big problem. Provided you have a small universe of propositions, the construction via equivalence classes still works just as it does classically — for instance, UniMath uses it. In the absence of that, you can assume quotients as primitive (as in the HoTT book) or fall back to setoids instead. So some constructive type theories don’t include enough assumptions to get quotients — but there are several clear well-established approaches to take if you do want them.

The second point is the bigger one, where we still don’t (I think) have a fully satisfactory answer: a way of setting up quotients which computes as nicely as we’d like, especially in types dependent over them. But it’s worth emphasising that this is not a shortcoming compared to classical foundations — in first-order set theory, you have no computation or dependent types at all, on quotients or anything else! But in type-theoretic foundations, you’re used to having decent computation (i.e. reduction within the theory) and making free use of native dependent typing — so when you don’t have these, it’s felt as a problem.

That said, modern type-theoretic presentations of quotients are pretty satisfactory for non-dependent computation. The ones I’ve worked with a bit are in UniMath and the HoTT library (over Coq) and in cubical Agda, and they’re all pretty decent — . I’ve not worked much with quotients in Lean, but my impression is they’re also fine. And working with setoids is also pretty OK for non-dependent algebra — you need a bit of extra boilerplate throughout (proving constructions respect equality), but with good discipline and modern type-class infrastructure, that’s not really much work. It’s really only dependent types over quotients (or setoids) that get nasty to work with — for that, things really do get rough, at least in all the implementations and approaches I’ve ever seen or tried. The core issue is that you want judgemental proof-irrelevancy, especially for equality (so that equality-transport in dependent structures doesn’t get weighed down by the proof-terms it’s carrying around), but this is in some tension with keeping good computation in the type theory; and quotients, where computationally meaningful proofs get pushed into equality types, bring this tension out most sharply. But there is a lot of recent work and progress, both theoretical and implemented, on having a delimited amount of judgemental proof-irrelevance while retaining good computation — so there’s definite hope of improvement on this front!

$\endgroup$
24
  • 4
    $\begingroup$ @ChristopherKing: For both computation and type dependency the version available in e.g. IZF (extracted computation; simulated dependent types) is different from, and weaker than, the version desired and usually available in type theories (normalisation, or at least a good convertibility algorithm; native dependent types) — particularly for convenience of working with them in implementations. The “unsatisfactory” interaction of type-theoretic quotients with computation/dependency is only relative to that desideratum. $\endgroup$ Commented Feb 7 at 9:48
  • 2
    $\begingroup$ Indeed, simulating dependency via functions is one of the various fallback options in type theory when type dependency over quotients gets messy — I’ve seen it used sometimes, but there are usually still other better approaches (sticking with the native type dependency, and finding ways to handle the awkwardness). $\endgroup$ Commented Feb 7 at 9:55
  • 3
    $\begingroup$ @JamesEHanson: Indeed, I don’t mean weaker in computational power. I mean that having a computational interpretation (as some first-order set theories and most type theories do) is a weaker property, heuristically, than having strong normalisation or decidable conversion for terms of the system (which many type theories have, but by definition first-order theories don’t — the system doesn’t involve a conversion/equality judgement for terms). Having this sort of computation within the system is one of the nice features of working in type-theoretic systems. $\endgroup$ Commented Feb 7 at 19:15
  • 2
    $\begingroup$ By analogy: I feel we’re comparing buses and trains; the question is “Why do people say such-and-such train route isn’t so nice?”, and I’m saying “Because the café doesn’t serve full meals, only light snacks. But still there’s an onboard café, which the bus doesn’t have.” You’re saying “But you do have food on the bus — you can bring it yourself!” Sure, and you can bring your own on the train as well, but having an onboard café is different. The café only serving snacks certainly weakens one nice feature of the train, but it’s not itself a shortcoming compared to the bus. $\endgroup$ Commented Feb 7 at 19:16
  • 2
    $\begingroup$ @JamesEHanson I added another answer which I hope clarifies this. $\endgroup$ Commented Feb 7 at 19:22

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.