TITLE: Generalization of Cantor Pairing function to triples and n-tuples
QUESTION [9 upvotes]: Is there a generalization for the Cantor Pairing function to (ordered) triples and ultimately to (ordered) n-tuples? It's however important that the there exists an inverse function: computing z from (w, x, y) and also computing w, x and y from z. In other words:

project(w, x, y) = z
unproject(z) = (w, x, y)

Thinking about it in terms of a three-/n-dimensional coordinate system it should be possible to generalize from ordered pairs to at least ordered triples and most probably also to ordered n-tuples. Is anyone aware of any resources (papers, books, websites...) where such a function is described?

REPLY [3 votes]: The solution, in retrospect, seems "obvious" but I was having a hard time grasping it until I understood an example.
The pairing function takes two numbers as input and returns one: $ \mathbb{N} \times \mathbb{N} \to \mathbb{N}$
So what do you do with, say, a 3-tuple? Pick 2 items, use the pairing function to turn that into 1. Now use the pairing function again to turn your two remaining items into 1.
More formally

In computability we are often forced to resort to dovetailing along 3, 4 or even more dimensions. We can define "higher pairing" functions recursively, by using two-dimensional pairing functions as a base case. Formally, we define the function $  <.,.,...,.>_n$, which pairs $n$ natural numbers recursively as follows:
$<>_0 = 0$ and $<x>_1 = x$,
$<x,y>_2 = <x,y>$,
$<x_1, ..., x_{n-1}, x_n>_n = <x_1, ..., <x_{n-1}, x_n>>_{n-1}$.

https://www.cs.upc.edu/~alvarez/calculabilitat/enumerabilitat.pdf
4-tuple example ( $ \mathbb{N} \times \mathbb{N} \times \mathbb{N} \times \mathbb{N} \to \mathbb{N} \times \mathbb{N} \times \mathbb{N} \to \mathbb{N} \times \mathbb{N} \to \mathbb{N} $ )
$$
a,b,c,d
$$
$$
a,b,(c,d)
$$
$$
a,b,e
$$
$$
a,(b,e)
$$
$$
a,f
$$
$$
(a,f)
$$
$$
g
$$