mutual recursion

Mutual recursion is a way of defining functions via recursion involving several functions simultaneously. In mutual recursion, the value of the next argument of any function involved depends on values of the current arguments of all functions involved. The following are two simple examples:

• the pair of functions $f,g$ such that $f(0)=0$ and $g(0)=1$, with $f(n+1)=f(n)g(n)$ and $g(n+1)=f(n)+g(n)$ is defined via mutual recursion. It is easy to see that $f(n)=0$ and $g(n)=1$.

• Fibonacci numbers can be interpreted via mutual recursion: $F(0)=1$ and $G(0)=1$, with $F(n+1)=F(n)+G(n)$ and $G(n+1)=F(n)$.

Formally,

Definition. Functions $f_{1},\ldots,f_{m}:\mathbb{N}^{k+1}\to\mathbb{N}$ are said to be defined by mutual recursion via functions $g_{1},\ldots g_{m}:\mathbb{N}^{k}\to\mathbb{N}$ and functions $h_{1},\ldots,h_{m}:\mathbb{N}^{k+m+1}\to\mathbb{N}$, if

 $\displaystyle f_{i}(\boldsymbol{x},0)$ $\displaystyle=$ $\displaystyle g_{i}(\boldsymbol{x}),$ $\displaystyle f_{i}(\boldsymbol{x},n+1)$ $\displaystyle=$ $\displaystyle h_{i}(\boldsymbol{x},n,f_{1}(\boldsymbol{x},n),\ldots,f_{m}(% \boldsymbol{x},n)),$

for any $\boldsymbol{x}\in\mathbb{N}^{k}$, and $i=1,\ldots,m$.

Mutual recursion is an apparent generalization of primitive recursion, where the value of the next argument of a function depends on the value of the current argument of the same function, apparent because it is in fact equivalent to primitive recursion.

Proposition 1.

As above, if all of $g_{i}$ and $h_{i}$ are primitive recursive, so are all of $f_{i}$.

Proof.

We use the multiplicative encoding technique. Define function $F:\mathbb{N}^{k+1}\to\mathbb{N}$ as follows:

 $F(\boldsymbol{x},n)=\operatorname{exp}(p_{1},f_{1}(\boldsymbol{x},n))\cdots% \operatorname{exp}(p_{m},f_{m}(\boldsymbol{x},n)),$

where $p_{i}$ is the $i$-th prime number ($p_{1}=2$, etc…). Furthermore,

 $(F(\boldsymbol{x},n))_{i}=f_{i}(\boldsymbol{x},n),$

where $(z)_{i}$ denotes the exponent of prime $p_{i}$ in $z$. Then

 $\displaystyle F(\boldsymbol{x},0)$ $\displaystyle=$ $\displaystyle\prod_{i=1}^{m}\operatorname{exp}(p_{i},g_{i}(\boldsymbol{x}))=G(% \boldsymbol{x}),\mbox{ and}$ $\displaystyle F(\boldsymbol{x},n+1)$ $\displaystyle=$ $\displaystyle\prod_{i=1}^{m}\operatorname{exp}(p_{1},f_{1}(\boldsymbol{x},n+1))$ $\displaystyle=$ $\displaystyle\prod_{i=1}^{m}\operatorname{exp}(p_{i},h_{i}(\boldsymbol{x},n,f_% {1}(\boldsymbol{x},n),\ldots,f_{m}(\boldsymbol{x},n)))$ $\displaystyle=$ $\displaystyle\prod_{i=1}^{m}\operatorname{exp}(p_{i},h_{i}(\boldsymbol{x},n,(F% (\boldsymbol{x},n))_{1},\ldots,(F(\boldsymbol{x},n))_{m})$ $\displaystyle=$ $\displaystyle H(\boldsymbol{x},n,F(\boldsymbol{x},n))$

where

 $G(\boldsymbol{x})=\prod_{i=1}^{m}\operatorname{exp}(p_{i},g_{i}(\boldsymbol{x}% )),$

and

 $H(\boldsymbol{x},y,z)=\prod_{i=1}^{m}\operatorname{exp}(p_{i},h_{i}(% \boldsymbol{x},y,(z)_{1},\ldots,(z)_{m})$

Since each of the $g_{i}$ is primitive recursive, $G$ is primitive recursive. Since each of the $h_{i}$ is primitive recursive, $H$ is primitive recursive. So $F$ is primitive recursive, as it is defined via primitive recursion by $G$ and $H$. Therefore, each $f_{i}=(F)_{i}$ is primitive recursive. ∎

Remark. The primitive recursiveness of mutual recursion can be derived from course-of-values recursion. The idea is the following: list the $f_{i}$’s in order, and construct a single function $F$ so the its values correspond to the values of the $f_{i}$’s in the order given. For example, if two unary functions $f_{1}$ and $f_{2}$ defined by mutual recursion, then

 $f_{1}(0)$ $f_{2}(0)$ $f_{1}(1)$ $f_{2}(1)$ $f_{1}(2)$ $\cdots$ $f_{1}(k)$ $f_{2}(k)$ $f_{1}(k+1)$ $f_{2}(k+1)$ $\cdots$ $F(0)$ $F(1)$ $F(2)$ $F(3)$ $F(4)$ $\cdots$ $F(2k)$ $F(2k+1)$ $F(2k+2)$ $F(2k+3)$ $\cdots$

${}\end{center}Thenitisnothardtoseethat$F(k+1)$dependson$F(k),F(k-1)$,and$F(k-2)$,andanexplicitformulacanbederivedexpressingthedependency.Furthermore,% thisformulaiseasilyseentobeprimitiverecursive,andhencesois$F(k)${{{.\begin{flushright}\begin{tabular}[]{|ll|}\hline Title&mutual recursion\\ Canonical name&MutualRecursion\\ Date of creation&2013-03-22 19:06:31\\ Last modified on&2013-03-22 19:06:31\\ Owner&CWoo (3771)\\ Last modified by&CWoo (3771)\\ Numerical id&9\\ Author&CWoo (3771)\\ Entry type&Definition\\ Classification&msc 03D20\\ Synonym&simultaneous recursion\\ \hline}\end{tabular}}}\end{flushright}\end{document}$