Truncation levels › Decidable equality and Hedberg’s theorem [01FN]
A famous result of type theory says that any type whose identification types are decidable (“has decidable equality” for short) is a set. This is not easy to prove directly, and in fact there are a number of proofs that work using different assumptions. We haven’t assumed much yet, so some of those proofs are not yet accessible to us. But there is one proof that we can do based on the idea of a “weakly constant function”. First we define decidable equality formally:
Definition Decidability [01GR]
A type A is said to be decidable when we have either an element of A or a proof that there can be no such element. This is formalised in the following type:
\mathsf {isDec}(A) :\equiv A + (A\to \mathsf {empty})Definition Decidable equality [01GG]
A type A is said to have decidable equality when all of its identification types are decidable:
\mathsf {hasDecEq}(A) :\equiv {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x,y:A)}} \mathsf {isDec}(A) x=_Ay + (x=_Ay\to \mathsf {empty})Warm-up How shall we proceed? [01GO]
We assume that some type A has decidable equality, so that we have d_A:\mathsf {hasDecEq}(A) in our pocket. Fixing x,y:A and p,q:x=_Ay we need to show that p=_{x=_Ay}q.
We can’t just use identification elimination
First of all, we note that using identification elimination here gets us nowhere: if we contract (y,p) to (x,\mathsf {refl}_x) then we are trying to show that q=_{x=_Ax}\mathsf {refl}_x for all x and q and that is not any easier than what we started with. (The symmetric thing will happen if we instead contract (y,q).)
Idea: a weakly constant identity function
Another idea would be to try to find some further identifications r,s:x=_Ay where it is easy to show that p=_{x=_Ay}r and and r=_{x=_Ay}s and s=_{x=_Ay}q and thus p=_{x=_Ay}q. It doesn’t seem like at first like this would help, but one rule of thumb is that adding extra “flex” into the problem can really help in univalent foundations. If we make just one leap and decide that we shall obtain r from p and s from q respectively by means of some function, then we can get a good idea of what properties that function needs to have:
- In order to make p=r and q=s, our function needs to behave like the identity function.
- In order to make r=s our function needs to give equal outputs regardless of the inputs (i.e., it should be “constant” in a certain sense).
Of course, this is all a little magical and you might not have any reason as-yet to believe that we can carry out the idea above. But it will happen that it is possible and not too difficult. First we must make a few preliminary definitions:
Definition Weakly constant function [01GP]
A function f:A\to B is called weakly constant when any two of its values can be identified. In other words, we have an element of the following type:
\mathsf {isWeaklyConstant}(f) :\equiv {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x,y:A)}} fx=_A fyDefinition Identity function [01GQ]
A function f:A\to A is called an identity function when we its value on #x:A can be identified with x; in other words, when we have an element of the following type:
\mathsf {isIdentity}(f) :\equiv {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x:A)}} fx=_AxTheorem Hedberg’s theorem [01GM]
Any type A that has decidable equality is a set. Assuming H_A:\mathsf {hasDecEq(A)}, we must check that for all x,y:A and p,q:x=_Ay we have p=_{x=_Ay}q. Putting that aside for now, we first consider that when an individual identification type x=_Ay is decidable, we can “replace” any specific identification p:x=_Ay with the result of the decision procedure.
\begin {aligned} &\mathsf {repl}_{x,y}:\mathsf {isDec}(x=_Ay)\to x=_Ay\to x=_Ay \\ &\mathsf {repl}_{x,y}~(\mathsf {inl}~q)~p :\equiv q \\ &\mathsf {repl}_{x,y}~(\mathsf {inr}~h)~p :\equiv \mathsf {abort}~(hp) \end {aligned}We can show that for each d:\mathsf {isDec}(x=_Ay), the function \mathsf {repl}_{x,y}~d is weakly constant without much difficulty by cases on d:
\begin {aligned} &\mathsf {replIsWeaklyConstant}_{x,y}: {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(d:\mathsf {isDec}(x=_Ay))}} \mathsf {isWeaklyConstant}~(\mathsf {repl}_{x,y}~d) \\ &\mathsf {replIsWeaklyConstant}_{x,y}~(\mathsf {inl}~r)~p~q :\equiv \mathsf {refl}_{r} \\ &\mathsf {replIsWeaklyConstant}_{x,y}~(\mathsf {inr}~h)~p~q :\equiv \mathsf {abort}~(hp) \end {aligned}Unfortunately, we cannot seem to show that \mathsf {repl}_{x,y}~d is the identity function. Indeed, to define the case for d\equiv \mathsf {inl}~r we would need to show that any identification p:x=_Ay is equal to r, which is just as hard as our main goal. We can wriggle out of this tough spot using a trick we’ve seen before: we can “pad” \mathsf {repl}_{x,y} with a flipped instance of \mathsf {refl}_{x,x} on either the left-hand or the right-hand side. Then later on, the two will cancel out. Using our witness h_A:\mathsf {hasDecEq}(A), let us define a new function to “clean” an identification:
\begin {aligned} &\mathsf {clean}^{h_A}_{x,y}:x=_Ay\to x=_Ay \\ &\mathsf {clean}^{h_A}_{x,y}~p :\equiv \overline { \mathsf {repl}_{x,x}~(h_Axx)~\mathsf {refl}_x } \cdot \mathsf {repl}_{x,y}~p \end {aligned}First we check that \mathsf {clean}_{x,y} is the identity function:
\begin {aligned} & \mathsf {cleanIsIdentity}_{h_A}: {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x,y:A)}} \mathsf {isIdentity}(\mathsf {clean}^{h_A}_{x,y}) \\ & \mathsf {cleanIsIdentity}_{h_A}~x~y~p :\equiv \bigl \{ ?: \mathsf {clean}^{h_A}_{x,y}~p =_{x=_Ay} p \bigr \} \end {aligned}We proceed by identification elimination on (y,p) and unravel the definition of \mathsf {clean}:
\begin {aligned} & \mathsf {cleanIsIdentity}_{h_A}: {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x,y:A)}} \mathsf {isIdentity}(\mathsf {clean}^{h_A}_{x,y}) \\ & \mathsf {cleanIsIdentity}_{h_Axx}~\mathsf {refl}_x :\equiv \bigl \{ ?: \overline { \mathsf {repl}_{x,x}~(h_Axx)~\mathsf {refl}_x } \cdot \mathsf {repl}_{x,x}~(h_Axx)~\mathsf {refl}_x =_{x=_Ax} \mathsf {refl}_x \bigr \} \end {aligned}But that is just the left unit law for flipping:
\begin {aligned} & \mathsf {cleanIsIdentity}_{h_A}: {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x,y:A)}} \mathsf {isIdentity}(\mathsf {clean}^{h_A}_{x,y}) \\ & \mathsf {cleanIsIdentity}_{h_A}~x~x~\mathsf {refl}_x :\equiv \mathsf {flipLeftUnit}(\mathsf {repl}_{x,x}~(h_Axx)~\mathsf {refl}_{x}) \end {aligned}We still need to check that \mathsf {clean}^{h_A}_{x,y} is weakly constant; luckily, we can reuse our proof that \mathsf {repl}_{x,y} is weakly constant:
\begin {aligned} & \mathsf {cleanIsWeaklyConstant}^{h_A}_{x,y} : \mathsf {isWeaklyConstant}(\mathsf {clean}^{h_A}_{x,y}) \\ & \mathsf {cleanIsWeaklyConstant}^{h_A}_{x,y}~p~q :\equiv \\ &\quad \bigl \{ ?: \overline {\mathsf {repl}_{x,x}~(h_Axx)~\mathsf {refl}_x} \cdot \mathsf {repl}_{x,y}~(h_Axy)~p =_{x=_Ay} \overline {\mathsf {repl}_{x,x}~(h_Axx)~\mathsf {refl}_x} \cdot \mathsf {repl}_{x,y}~(h_Axy)~q \bigr \} \end {aligned}We already know that \mathsf {repl}_{x,y}~(h_Axy)~p=_{x=_Ay}\mathsf {repl}_{x,y}~(h_Axy)~q because we have shown that \mathsf {repl}_{x,y} is weakly constant. So we use the action on identifications:
\begin {aligned} & \mathsf {cleanIsWeaklyConstant}_{x,y} : \mathsf {isWeaklyConstant}(\mathsf {clean}^{h_A}_{x,y}) \\ & \mathsf {cleanIsWeaklyConstant}_{x,y}~p~q :\equiv \mathsf {act}_{\lambda r\mathpunct {.} \overline {\mathsf {repl}_{x,x}~\mathsf {refl}_x}\cdot r} \bigl (\mathsf {replIsWeaklyConstant}_{x,y}~(h_Axy)\bigr ) \end {aligned}Finally we can combine all this to verify Hedberg’s theorem:
\begin {aligned} & \mathsf {hedberg}:\mathsf {hasDecEq}(A)\to \mathsf {isSet}(A) \\ & \mathsf {hedberg}~h_A~x~y~p~q :\equiv \\ &\begin {array}{l} \overline {\mathsf {cleanIsIdentity}_{h_A}~x~y~p} \\ {}\cdot \mathsf {cleanIsWeaklyConstant}^{h_A}_{x,y}~p~q \\ {}\cdot \mathsf {cleanIsIdentity}_{h_A}~x~y~q \end {array} \end {aligned}