Jump to content

Cantor pairing function: Difference between revisions

From Wikibase
No edit summary
No edit summary
 
Line 1: Line 1:
[[Category:Proper name]]
[[Category:Proper name]][[Category:Coding function]]
The '''Cantor pairing function''' [[function#Formal_definition|bijectively]] maps ordered pairs of natural numbers to natural numbers.
The '''Cantor pairing function''' [[function#Formal_definition|bijectively]] maps ordered pairs of natural numbers to natural numbers.



Latest revision as of 09:39, 10 November 2026

Languages: English · français · Esperanto

The Cantor pairing function bijectively maps ordered pairs of natural numbers to natural numbers.

$$ \langle \ \rangle: \mathbb{N} \times \mathbb{N} \to \mathbb{N} $$

$$\langle x,y \rangle = (\sum_{i=0}^{x+y} i) + x +1$$

where $x,y \in \mathbb{N}$

[1]

Graphical intuition

The results of the Cantor pairing function fit into a 2-dimensional array.

As can be observed, there is a steady increase with a step of 1 along each diagonal and between the last element of a diagonal and the 1st of the successive diagonal. Therefore, each natural number should appear only once in the results, corresponding to exactly one ordered pair of natural numbers (bijectivity).

[1]

Recursivity

A recursive composite of Cantor pairing functions maps an ordered array of natural numbers of any length $n\ge 2$ to natural numbers.

$$\begin{gathered} \langle \ \rangle: \mathbb{N}^n \to \mathbb{N}\\ \langle x_1,x_2 \rangle = (\sum_{i=0}^{x_1+x_2} i) + x_1 +1 \\ \langle x_1,x_2,\cdots,x_n \rangle= \langle x_1, \langle x_2, \cdots, x_n \rangle \rangle \end{gathered}$$

[1]