Writing the sequence backwards

105 Views Asked by At

Let $\pi^{(n)}: \mathbb N^n\to \mathbb N$ be the Cantor tuple function. So $\pi^{(2)}$ is the Cantor pairing function. Let $\mathbb N^\ast$ be the set of finite sequences of natural numbers (a sequence is written as $\langle n_1,\dots, n_k\rangle$) and let $p:\mathbb N^\ast\to\mathbb N$ be the function $$p(\epsilon)=\pi^{(2)}(0,0)\\ p(\langle n_1,\dots, n_k\rangle)=\pi^{(2)}(k-1, \pi^{(k)}(\langle n_1,\dots, n_k\rangle)) \text { for } k\ge 1$$

Suppose we know that there exists a (computable) function $sum:\mathbb N\to \mathbb N,\ sum(p(\langle n_1,\dots, n_k\rangle))=\sum_{i=1}^k n_i$. How to deduce that there is also a computable function $backwards:\mathbb N\to \mathbb N$ such that $backwards: p(\langle n_1,\dots, n_k\rangle)\mapsto p(\langle n_k,\dots, n_1\rangle)$?

I think one needs to use somehow the fact that $sum(p(\langle n_1,\dots, n_k\rangle))=n_1+\dots+n_k=\\ n_k+\dots+n_1=sum(p(\langle n_k,\dots, n_1\rangle))$

but this symmetry doesn't tell me much about the function $backwards$.

1

There are 1 best solutions below

2
On

Per this Wikipedia article, the pairing function $\pi^{(2)} : \Bbb N^2 \to \Bbb N$ is invertible, and therefore a bijection. $\pi^{(1)} : \Bbb N \to \Bbb N : k \mapsto k$ is also a bijection.

For $n > 2$, suppose $\pi^{(n-1)}$ is a bijection. Then the map $$k \overset {{\pi^{(2)}}^{-1}}\mapsto (\alpha, k_n)\overset {{\pi^{(n-1)}}^{-1}\times id } \mapsto (\langle k_1, k_2, ..., k_{n-1}\rangle, k_n)\mapsto \langle k_1, k_2, ..., k_{n-1}, k_n\rangle$$ defines an inverse for $\pi^{(n)}$, which is therefore a bijection.

I assume $\epsilon$ is the empty sequence. Then the map $$k \overset {{\pi^{(2)}}^{-1}}\mapsto \langle k_1, k_2\rangle \mapsto {\pi^{(k_1+1)}}^{-1}(k_2) $$ Is an inverse function for the restriction of $p$ to $\Bbb N^* \setminus \{\epsilon\}$. On the other hand, $$p(\epsilon) = p(\langle 0 \rangle) = 0$$

So, $$sum(k) = \sum_{i=1}^{|p^{-1}(k)|} (p^{-1}(k))_i$$ and $$backwards(k) = p(rev(p^{-1}(k))$$ where $rev(\langle k_1, ..., k_n\rangle) := \langle k_n, ..., k_1\rangle$.

The only place where computability seems even slightly questionable is in this step of computing the inverse of $\pi^{(2)}$: $$z \mapsto \left\lfloor \dfrac{\sqrt{8z - 1}-1}2\right\rfloor$$ I'm no expert on computability, but it seems computable to me. And all the rest is just a finite (for any given input) application of functions known to be computable.

Now there is that small detail of $p(\epsilon) = p(\langle 0 \rangle)$, but can you see why it makes no difference to $sum$ and $backwards$?