Subfield: Algebra


Question: Let $\mathbb{Z}_{\geqslant 0}$ be the set of all nonnegative integers. Find all the functions $f: \mathbb{Z}_{\geqslant 0} \rightarrow \mathbb{Z}_{\geqslant 0}$ satisfying the relation

$$
f(f(f(n)))=f(n+1)+1
\tag{*}
$$

for all $n \in \mathbb{Z}_{\geqslant 0}$.

(tip: We write $h^{k}(x)$ to abbreviate the $k$ th iteration of function $h$, so $h^{0}$ is the identity function, and $h^{k}(x)=\underbrace{h(\ldots h}_{k \text { times }}(x) \ldots))$ for $k \geqslant 1$.)

Solution:
To start, we get from $(*)$ that

$$
f^{4}(n)=f\left(f^{3}(n)\right)=f(f(n+1)+1) \quad \text { and } \quad f^{4}(n+1)=f^{3}(f(n+1))=f(f(n+1)+1)+1
$$

thus

$$
f^{4}(n)+1=f^{4}(n+1) .
\tag{2}
$$

I. Let us denote by $R_{i}$ the range of $f^{i}$; note that $R_{0}=\mathbb{Z}_{\geqslant 0}$ since $f^{0}$ is the identity function. Obviously, $R_{0} \supseteq R_{1} \supseteq \ldots$ Next, from (2) we get that if $a \in R_{4}$ then also $a+1 \in R_{4}$. This implies that $\mathbb{Z}_{\geqslant 0} \backslash R_{4}$ - and hence $\mathbb{Z}_{\geqslant 0} \backslash R_{1}$ - is finite. In particular, $R_{1}$ is unbounded.

Assume that $f(m)=f(n)$ for some distinct $m$ and $n$. Then from $(*)$ we obtain $f(m+1)=$ $f(n+1)$; by an easy induction we then get that $f(m+c)=f(n+c)$ for every $c \geqslant 0$. So the function $f(k)$ is periodic with period $|m-n|$ for $k \geqslant m$, and thus $R_{1}$ should be bounded, which is false. So, $f$ is injective.

II. Denote now $S_{i}=R_{i-1} \backslash R_{i}$; all these sets are finite for $i \leqslant 4$. On the other hand, by the injectivity we have $n \in S_{i} \Longleftrightarrow f(n) \in S_{i+1}$. By the injectivity again, $f$ implements a bijection between $S_{i}$ and $S_{i+1}$, thus $\left|S_{1}\right|=\left|S_{2}\right|=\ldots$; denote this common cardinality by $k$. If $0 \in R_{3}$ then $0=f(f(f(n)))$ for some $n$, thus from $(*)$ we get $f(n+1)=-1$ which is impossible. Therefore $0 \in R_{0} \backslash R_{3}=S_{1} \cup S_{2} \cup S_{3}$, thus $k \geqslant 1$.

Next, let us describe the elements $b$ of $R_{0} \backslash R_{3}=S_{1} \cup S_{2} \cup S_{3}$. We claim that each such element satisfies at least one of three conditions $(i) b=0,(i i) b=f(0)+1$, and (iii) $b-1 \in S_{1}$. Otherwise $b-1 \in \mathbb{Z}_{\geqslant 0}$, and there exists some $n>0$ such that $f(n)=b-1$; but then $f^{3}(n-1)=f(n)+1=b$, so $b \in R_{3}$.

This yields

$$
3 k=\left|S_{1} \cup S_{2} \cup S_{3}\right| \leqslant 1+1+\left|S_{1}\right|=k+2
$$

or $k \leqslant 1$. Therefore $k=1$, and the inequality above comes to equality. So we have $S_{1}=\{a\}$, $S_{2}=\{f(a)\}$, and $S_{3}=\left\{f^{2}(a)\right\}$ for some $a \in \mathbb{Z}_{\geqslant 0}$, and each one of the three options $(i)$, (ii), and (iii) should be realized exactly once, which means that

$$
\left\{a, f(a), f^{2}(a)\right\}=\{0, a+1, f(0)+1\}
\tag{3}
$$



III. From (3), we get $a+1 \in\left\{f(a), f^{2}(a)\right\}$ (the case $a+1=a$ is impossible). If $a+1=f^{2}(a)$ then we have $f(a+1)=f^{3}(a)=f(a+1)+1$ which is absurd. Therefore

$$
f(a)=a+1
\tag{4}
$$

Next, again from (3) we have $0 \in\left\{a, f^{2}(a)\right\}$. Let us consider these two cases separately.

Case 1. Assume that $a=0$, then $f(0)=f(a)=a+1=1$. Also from (3) we get $f(1)=f^{2}(a)=$ $f(0)+1=2$. Now, let us show that $f(n)=n+1$ by induction on $n$; the base cases $n \leqslant 1$ are established. Next, if $n \geqslant 2$ then the induction hypothesis implies

$$
n+1=f(n-1)+1=f^{3}(n-2)=f^{2}(n-1)=f(n),
$$

establishing the step. In this case we have obtained the first of two answers; checking that is satisfies (*) is straightforward.

Case 2. Assume now that $f^{2}(a)=0$; then by (3) we get $a=f(0)+1$. By (4) we get $f(a+1)=$ $f^{2}(a)=0$, then $f(0)=f^{3}(a)=f(a+1)+1=1$, hence $a=f(0)+1=2$ and $f(2)=3$ by (4). To summarize,

$$
f(0)=1, \quad f(2)=3, \quad f(3)=0
$$

Now let us prove by induction on $m$ that (1) holds for all $n=4 k, 4 k+2,4 k+3$ with $k \leqslant m$ and for all $n=4 k+1$ with $k<m$. The base case $m=0$ is established above. For the step, assume that $m \geqslant 1$. From $(*)$ we get $f^{3}(4 m-3)=f(4 m-2)+1=4 m$. Next, by $(2)$ we have

$$
f(4 m)=f^{4}(4 m-3)=f^{4}(4 m-4)+1=f^{3}(4 m-3)+1=4 m+1 .
$$

Then by the induction hypothesis together with (*) we successively obtain

$$
\begin{aligned}
& f(4 m-3)=f^{3}(4 m-1)=f(4 m)+1=4 m+2, \\
& f(4 m+2)=f^{3}(4 m-4)=f(4 m-3)+1=4 m+3, \\
& f(4 m+3)=f^{3}(4 m-3)=f(4 m-2)+1=4 m
\end{aligned}
$$

thus finishing the induction step.

Finally, it is straightforward to check that the constructed function works:

$$
\begin{aligned}
& f^{3}(4 k)=4 k+7=f(4 k+1)+1, \quad f^{3}(4 k+1)=4 k+4=f(4 k+2)+1, \\
& f^{3}(4 k+2)=4 k+1=f(4 k+3)+1, \quad f^{3}(4 k+3)=4 k+6=f(4 k+4)+1 .
\end{aligned}
$$
I. For convenience, let us introduce the function $g(n)=f(n)+1$. Substituting $f(n)$ instead of $n$ into $(*)$ we obtain

$$
f^{4}(n)=f(f(n)+1)+1, \quad \text { or } \quad f^{4}(n)=g^{2}(n) .
\tag{5}
$$

Applying $f$ to both parts of $(*)$ and using (5) we get

$$
f^{4}(n)+1=f(f(n+1)+1)+1=f^{4}(n+1) .
\tag{6}
$$

Thus, if $g^{2}(0)=f^{4}(0)=c$ then an easy induction on $n$ shows that

$$
g^{2}(n)=f^{4}(n)=n+c, \quad n \in \mathbb{Z}_{\geqslant 0}
\tag{7}
$$



This relation implies that both $f$ and $g$ are injective: if, say, $f(m)=f(n)$ then $m+c=$ $f^{4}(m)=f^{4}(n)=n+c$. Next, since $g(n) \geqslant 1$ for every $n$, we have $c=g^{2}(0) \geqslant 1$. Thus from (7) again we obtain $f(n) \neq n$ and $g(n) \neq n$ for all $n \in \mathbb{Z}_{\geqslant 0}$.

II. Next, application of $f$ and $g$ to (7) yields

$$
f(n+c)=f^{5}(n)=f^{4}(f(n))=f(n)+c \quad \text { and } \quad g(n+c)=g^{3}(n)=g(n)+c .
\tag{8}
$$

In particular, this means that if $m \equiv n(\bmod c)$ then $f(m) \equiv f(n)(\bmod c)$. Conversely, if $f(m) \equiv f(n)(\bmod c)$ then we get $m+c=f^{4}(m) \equiv f^{4}(n)=n+c(\bmod c)$. Thus,

$$
m \equiv n \quad(\bmod c) \Longleftrightarrow f(m) \equiv f(n) \quad(\bmod c) \Longleftrightarrow g(m) \equiv g(n) \quad(\bmod c)
\tag{9}
$$

Now, let us introduce the function $\delta(n)=f(n)-n=g(n)-n-1$. Set

$$
S=\sum_{n=0}^{c-1} \delta(n)
$$

Using (8), we get that for every complete residue system $n_{1}, \ldots, n_{c}$ modulo $c$ we also have

$$
S=\sum_{i=1}^{c} \delta\left(n_{i}\right)
$$

By (9), we get that $\left\{f^{k}(n): n=0, \ldots, c-1\right\}$ and $\left\{g^{k}(n): n=0, \ldots, c-1\right\}$ are complete residue systems modulo $c$ for all $k$. Thus we have

$$
c^{2}=\sum_{n=0}^{c-1}\left(f^{4}(n)-n\right)=\sum_{k=0}^{3} \sum_{n=0}^{c-1}\left(f^{k+1}(n)-f^{k}(n)\right)=\sum_{k=0}^{3} \sum_{n=0}^{c-1} \delta\left(f^{k}(n)\right)=4 S
$$

and similarly

$$
c^{2}=\sum_{n=0}^{c-1}\left(g^{2}(n)-n\right)=\sum_{k=0}^{1} \sum_{n=0}^{c-1}\left(g^{k+1}(n)-g^{k}(n)\right)=\sum_{k=0}^{1} \sum_{n=0}^{c-1}\left(\delta\left(g^{k}(n)\right)+1\right)=2 S+2 c
$$

Therefore $c^{2}=4 S=2 \cdot 2 S=2\left(c^{2}-2 c\right)$, or $c^{2}=4 c$. Since $c \neq 0$, we get $c=4$. Thus, in view of (8) it is sufficient to determine the values of $f$ on the numbers $0,1,2,3$.

III. Let $d=g(0) \geqslant 1$. Then $g(d)=g^{2}(0)=0+c=4$. Now, if $d \geqslant 4$, then we would have $g(d-4)=g(d)-4=0$ which is impossible. Thus $d \in\{1,2,3\}$. If $d=1$ then we have $f(0)=g(0)-1=0$ which is impossible since $f(n) \neq n$ for all $n$. If $d=3$ then $g(3)=g^{2}(0)=4$ and hence $f(3)=3$ which is also impossible. Thus $g(0)=2$ and hence $g(2)=g^{2}(0)=4$.

Next, if $g(1)=1+4 k$ for some integer $k$, then $5=g^{2}(1)=g(1+4 k)=g(1)+4 k=1+8 k$ which is impossible. Thus, since $\{g(n): n=0,1,2,3\}$ is a complete residue system modulo 4 , we get $g(1)=3+4 k$ and hence $g(3)=g^{2}(1)-4 k=5-4 k$, leading to $k=0$ or $k=1$. So, we obtain iether

$$
f(0)=1, f(1)=2, f(2)=3, f(3)=4, \quad \text { or } \quad f(0)=1, f(1)=6, f(2)=3, f(3)=0
$$

thus arriving to the two functions listed in the answer.

One may simplify the checking by noticing that (8) allows us to reduce it to $n=0,1,2,3$.

Final answer: There are two such functions: $f(n)=n+1$ for all $n \in \mathbb{Z}_{\geqslant 0}$, and

$$
f(n)=\left\{\begin{array}{ll}
n+1, & n \equiv 0(\bmod 4) \text { or } n \equiv 2(\bmod 4) \\
n+5, & n \equiv 1(\bmod 4) \\
n-3, & n \equiv 3(\bmod 4)
\end{array} \quad \text { for all } n \in \mathbb{Z}_{\geqslant 0}\right.
$$