3

When reading about corecursion for the first time (in my case, on nLab, perhaps unwisely), one is confronted with the extended natural numbers example and a blank statement that it is terminal among all $X\to X+1$ arrows. The nLab article on $\bar{\mathbb N}$ even has a line and a half of a proof that it is terminal.

Unfortunately, this proof on its own gives little insight on why the terminal object should be $\bar{\mathbb N}$. I understand the proof; I understand why $\bar{\mathbb N}$ is terminal, but why a terminal object should be $\bar{\mathbb N}$ is a complete mystery to me. It is plucked out of thin air. I get the "forward" direction of the "X is Y" statement but not the backward.

Moreover, since $\bar{\mathbb N}$ is just semantic notation for $\mathbb N+1$, it's as if we get an arrow $\mathbb N+1\to \mathbb N+2$ which only makes things more confusing.

Is there a way to discover the terminal $X\to X+1$ coalgebra naturally, without guessing the answer upfront?


This is a follow-up question to (Co)recursion: what is the significance of the functor F and the coalgebra $X\to FX$?. My answer there became long enough that I couldn't share my findings on the current topic (I also couldn't find the answer elsewhere on the internet), and I think they are interesting enough that I decided to ask&share separately. When I ask ChatGpt, it spits plain wrong answers - it defines the arrow with a successor and does not use the +1 at all. So.. it's time to fill the gap.

Al.G.
  • 1,802

2 Answers2

2

We're looking for an arrow $\tau : T \to T+\bot$ and some object T, s.t. for any other $X\to X+\bot$, there is a unique $h$ making the diagram $$\require{AMScd} \begin{CD} T @>{\tau}>> T+\bot\\ @A{\exists!\,h}AA @AA{h+\bot}A \\ X @>>> X+\bot \end{CD}$$ commutative.

The way I found the most natural is to probe this commutativity statement with various choices of $X\to X+\bot$ and try to deduce as much as possible from the existence and uniqueness of $h$.

Probing with $X=1$

The simplest one could go is to put $X=1$ ($1$ a singleton set) and probe with the two possible $1\to 1 + \bot$ arrows: $\textrm{id}$ and the constant $\bot$. Even this early on we start getting some insights about $T$:

  1. For $\textrm{id}:1\mapsto 1$, the existence of $h:1\to T$ tells us that $T$ contains some $h(1)$, and the commutativity statement is $\tau(h(1))=h(\textrm{id}(1))=h(1)$.
    That is, we know there's an element of $T$ on which $\tau$ is constant! Uniqueness of $h$ means no other element of $T$ is stable under $\tau$.
  2. For $\bot:1\mapsto \bot$, the story is analogous and we get a unique element in $T$ on which $\tau$ is undefined (commutativity here is $\tau(h(1))=(h+\bot)(\bot(1))=\bot$).

Both of these points we found -- the undefined and the fixed point -- are quite important and their existence and uniqueness will be exploited in the next paragraph in 1. and 2.

Probing with finite $X$

Now that we're done with $1$, it is most natural to put $X=2,3,\ldots$ and see where that goes.

Fix a finite non-empty $X$. A priori it is hard to pick a particular $X\to X+\bot$, so let us focus on the $\bot$ part first.

  1. We already discovered there is a unique point in $T$ at which $\tau$ is undefined, so by commutativity, all inputs at which our $X\to X+\bot$ is undefined will be sent there (by $h$). This simple observation is quite useful, because it restricts the $X\to X+\bot$ arrows with which it makes sense to probe $\tau$ to only those that are undefined at at most one point of $X$. An $X\to X+\bot$ undefined at multiple points will reveal no further information about $T$ and $\tau$ than the same one with all points of undefinedness identified as a single one.
  2. Now that our arrow shall be undefined at at most one point, can it be undefined at none? That is, do we need to probe with arrows of the form $X\to X$? We already discovered a fixpoint of $\tau$, so any choice of $X\to X+\bot$ can be smashed into it. This uniquely determines a $h:X\to T$ (a constant one). We know such a $h$ is unique, so this is the $h$ from our $X\to X+\bot$ to $T\to T+\bot$. That is, the existence of $h$ will not reveal anything further about $T$ if we probe with $X\to X$.
  3. The reasoning in 2. can be strenghtened a bit more: $f$ can be assumed free of invariant subsets $Y\subseteq X$ (s.t. $f(Y)=Y$, read as equality of sets), because $h$ will send all of $Y$ to the fixoint of $\tau$ and will not point (as an arrow :P) us to any new elements of $T$, which are what we're after!

Therefore it only makes sense to choose an $X\to X+\bot$ that is undefined at exactly one point of $X$. Let us label the elements of $X=\{0,\ldots,n\}$ of our finite $X$ and put $f(0)=\bot$ (we want the same construction to work for all sizes of $X$, so it makes sense to choose for $f^{-1}(\bot)$ a label that won't change when resizing $X$).

It remains to define $f$ on $\{1\ldots n\}$ with outputs in $\{0 \ldots n\}$. One output label will be left unused. If we let that be $0$, $f$ will get an invariant set $\{1\ldots n\}$, so we won't choose it. Call the unused output label $n$.

Now $f(n)$ can take either $0$ or another unused label. If we choose $f(n)=0$, the rest ($X\setminus\{0,n\}$) will become invariant, so we choose another one $f(n) = n-1$. Likewise, the only fruitful choice for $f$ requires $f(i)=i-1$ for all $i$, all up to $f(1)=0$ (which justifies the label $n$ and the (-1) notation - $f^{n}(\textrm{unused output label})=0$).

Thus we have defined $f=(-1):X\to X+\bot$ and it is time we reap what the corresponding unique $h$ gives us. We get

  • some elements $h_0,\ldots,h_n\in T$;
  • of these $h_0$ is the undefined point (preimage of $\bot$) for $\tau$ we discovered earlier;
  • $\tau(h_{i+1})=h_i$ for all $i=0\ldots n$

We hope the $h_i$ are all distinct, and $(k+1)$-fold application on the equality $h_k=h_l$ (for $k\le l\le n$) shows this is indeed the case.

Varying $X$, we get arbitrarily long sequences $h_0,h_1,\ldots,h_n,\ldots\in T$, where $\tau(h_0)=\bot$ and $\tau(h_{i+1})=h_i$. Uniqueness of $h$ means that for each $i$, $h_i\in T$ is uniquely determined regardless of $f$, which justifies dropping the $h$ label and writing just $0,1,2,\ldots,n,\ldots\in T$, rendering $\tau=(-1)$ on these. Is now also sensible that the fixpoint of $\tau$ is called $\infty$ and denote the discovered subset of $T$ as $\bar{\mathbb N}$.

Minimality

It is not yet clear if $T$ coincides with $\bar{\mathbb N}$ completely. An element $a\in T$ is either a fixpoint, sent to $\bot$, or something else. The first two cases were uniquely determined to be $\infty$ and $0$. In the third case we get a set $2=\{a, \tau(a)\}$. Taking the arrow $X\to X+\bot$ as $$\tau(a)\mapsto a\mapsto\bot,$$ we get a unique $h:X\to T$ which forces $2=\{a, \tau(a)\}$ to coincide with the subset $\{0,1\}\subseteq\bar{\mathbb N}$.

Moral

After playing quite some time with this exercise, I can outline some interesting takeaways (may be obvious to category people, but I hope useful for newbies).

Namely, the particular instance of $\mathbb N \cup \{\infty\}$ is remarkably unremarkable. What I mean is nothing new, just that $T$ is unique up to isomorphism, but I think it's worth a second thought. I always thought of $\bar{\mathbb N}$ as just the naturals with an attached external element interpreted as $\infty$, but the important bits here are in the structure of $\bar{\mathbb N}$, captured by the $\tau$ arrow. Even that $\tau=(-1)$ is unimportant. The only important features are the unique fixpoint, the unique pre-immage of $\bot$, and the lack of invariant subsets of $T$ other than $\{\infty\}$.

In fact, we could even relabel $\infty$ as $0$, use $1$ for $0$ and left-shift the roles of the $1,2,\ldots$. Then $\tau(0)=0,\tau(1)=\bot,\tau(1+n)=n$ defines the same structure without ever mentioning infinities, burying $\infty$ behind 0. So the category information is in the way $\tau$ works on (rearranges) a countable set; the rest is just common labels we put to comunicate and think more easily. I suspect this is quite obvious to the more experienced, but I still wanted to share it out.

Al.G.
  • 1,802
2

The following result is the standard way to identify a terminal coalgebra (and, dually, an initial algebra) for an endofunctor $T$ of a category $\mathcal{C}$:

Assume that $T$ has a terminal object $1$, that the limit of the sequence $$\cdots \xrightarrow{T^2(!)} T^2(1) \xrightarrow{T(!)} T(1) \xrightarrow{!} 1$$ exists, and that $T$ preserves this limit. Then the limit $L$ carries the structure of a terminal $T$-coalgebra $(L, \alpha : L \to T(L))$. Also, $\alpha$ is an isomorphism.

See the nLab for a proof.

In our case, we have the functor $T(X) := 1 + X$ on $\mathbf{Set}$. It preserves all sequential limits. The sequence in question consists of the objects $T^n(1) = 1 + \cdots + 1 = \{0,\dotsc,n\}$. The $n$th transition map is $$t_n : \{0,\dotsc,n+1\} \to \{0,\dotsc,n\},\quad x \mapsto \begin{cases} x & x \leq n \\ n & x = n + 1 \end{cases}.$$ Hence, the limit consists of sequences of integers $(a_n)_{n \geq 0}$ with $0 \leq a_n \leq n$ and $t_n(a_{n+1}) = a_n$ $(\ast)$.

This set has a special sequence, namely $(n)_{n \geq 0}$, which stands for $\infty$. We can visualize it as follows. The $nth$ column depicts $\{0,\dotsc,n\}$, and the colored dot is the one we select for $a_n$.

$$\begin{array}{ccccc} \cdots &&& \\ & \color{red}{\bullet} & & & \\ & \bullet & \color{red}{\bullet}& & \\ & \bullet & \bullet & \color{red}{\bullet} & \\ & \bullet & \bullet & \bullet & \color{red}{\bullet} \end{array}$$

Any other sequence has some $s := a_n < n$ for some index $n$, and then all other values are determined because of $(\ast)$: we have $a_k = s$ for $k \geq n$, and $a_k = s$ for $s \leq k \leq n$, and $a_k = k$ for $0 \leq k < s$.

$$\begin{array}{cccccc} & \bullet &&&& \\ & \bullet & \bullet & & & \\ \cdots & \color{skyblue}{\bullet} & \color{skyblue}{\bullet} & \color{skyblue}{\bullet} & & \\ & \bullet & \bullet & \bullet & \color{skyblue}{\bullet} & \\ & \bullet & \bullet & \bullet & \bullet & \color{skyblue}{\bullet} \end{array}$$

This shows that the limit is isomorphic to $\mathbb{N} \cup \{\infty\}$.

  • Beautiful! This is satisfying, danke! And nice to see you under my Q; I'll keep it open for a few more days just in case. – Al.G. Feb 23 '25 at 09:13