Pairing function

From Wikipedia, the free encyclopedia

In mathematics a pairing function is a process to uniquely encode two natural numbers into a single natural number.

Any pairing function can be used in set theory to prove that integers and rational numbers have the same cardinality as natural numbers. In theoretical computer science they are used to encode a function defined on a vector of natural numbers f:Nk β†’ N into a new function g:N β†’ N.

[edit] Definition

A pairing function is a bijective function

\pi:\mathbb{N} \times \mathbb{N} \to \mathbb{N}.

[edit] Cantor pairing function

Red: level curves of the Cantor pairing function corresponding to integer values; blue: couples of integers
Enlarge
Red: level curves of the Cantor pairing function corresponding to integer values; blue: couples of integers

The Cantor pairing function is a pairing function

\pi:\mathbb{N} \times \mathbb{N} \to \mathbb{N}

defined by

\pi(k_1,k_2) := \frac{1}{2}(k_1 + k_2)(k_1 + k_2 + 1)+k_2.

When we apply the pairing function to k1 and k2 we often denote the resulting number as \langle k_1, k_2 \rangle

This definition can be inductively generalized to the Cantor tuple function

\pi^{(n)}:\mathbb{N}^n \to \mathbb{N}

as

\pi^{(n)}(k_1, \ldots, k_{n-1}, k_n) := \pi ( \pi^{(n-1)}(k_1, \ldots, k_{n-1}) , k_n)

[edit] References

In other languages