HOME

TheInfoList



OR:

In
mathematics Mathematics is an area of knowledge that includes the topics of numbers, formulas and related structures, shapes and the spaces in which they are contained, and quantities and their changes. These topics are represented in modern mathematics ...
, a pairing function is a process to uniquely encode two
natural number In mathematics, the natural numbers are those numbers used for counting (as in "there are ''six'' coins on the table") and ordering (as in "this is the ''third'' largest city in the country"). Numbers used for counting are called ''Cardinal n ...
s into a single natural number. Any pairing function can be used in
set theory Set theory is the branch of mathematical logic that studies sets, which can be informally described as collections of objects. Although objects of any kind can be collected into a set, set theory, as a branch of mathematics, is mostly conce ...
to prove that
integer An integer is the number zero (), a positive natural number (, , , etc.) or a negative integer with a minus sign (−1, −2, −3, etc.). The negative numbers are the additive inverses of the corresponding positive numbers. In the language ...
s and
rational number In mathematics, a rational number is a number that can be expressed as the quotient or fraction of two integers, a numerator and a non-zero denominator . For example, is a rational number, as is every integer (e.g. ). The set of all ration ...
s have the same
cardinality In mathematics, the cardinality of a set is a measure of the number of elements of the set. For example, the set A = \ contains 3 elements, and therefore A has a cardinality of 3. Beginning in the late 19th century, this concept was generalized ...
as natural numbers.


Definition

A pairing function is a
bijection In mathematics, a bijection, also known as a bijective function, one-to-one correspondence, or invertible function, is a function between the elements of two sets, where each element of one set is paired with exactly one element of the other s ...
:\pi:\mathbb \times \mathbb \to \mathbb. More generally, a pairing function on a set ''A'' is a function that maps each pair of elements from ''A'' into an element of ''A'', such that any two pairs of elements of ''A'' are associated with different elements of ''A,'' or a bijection from A^2 to ''A''.


Hopcroft and Ullman pairing function

Hopcroft and Ullman (1979) define the following pairing function: \langle i, j\rangle := \frac(i+j-2)(i+j-1) + i, where i, j\in\. This is the same as the Cantor pairing function below, shifted to exclude 0 (i.e., i=k_2+1, j=k_1+1, and \langle i, j\rangle - 1 = \pi(k_2,k_1)).


Cantor pairing function

The Cantor pairing function is a
primitive recursive In computability theory, a primitive recursive function is roughly speaking a function that can be computed by a computer program whose loops are all "for" loops (that is, an upper bound of the number of iterations of every loop can be determined ...
pairing function :\pi:\mathbb \times \mathbb \to \mathbb defined by :\pi(k_1,k_2) := \frac(k_1 + k_2)(k_1 + k_2 + 1)+k_2 where k_1, k_2\in\. It can also be expressed as Pair
, y The comma is a punctuation mark that appears in several variants in different languages. It has the same shape as an apostrophe or single closing quotation mark () in many typefaces, but it differs from them in being placed on the baseline ...
:= \frac. It is also strictly monotonic w.r.t. each argument, that is, for all k_1, k_1', k_2, k_2' \in \mathbb, if k_1 < k_', then \pi(k_1, k_2) < \pi(k_1', k_2); similarly, if k_2 < k_', then \pi(k_1, k_2) < \pi(k_1, k_2'). The statement that this is the only quadratic pairing function is known as the
Fueter–Pólya theorem The Fueter–Pólya theorem, first proved by Rudolf Fueter and George Pólya, states that the only quadratic polynomial pairing functions are the Cantor polynomials. Introduction In 1873, Georg Cantor showed that the so-called Cantor polynom ...
. Whether this is the only polynomial pairing function is still an open question. When we apply the pairing function to and we often denote the resulting number as . This definition can be inductively generalized to the :\pi^:\mathbb^n \to \mathbb for n > 2 as :\pi^(k_1, \ldots, k_, k_n) := \pi ( \pi^(k_1, \ldots, k_) , k_n) with the base case defined above for a pair: \pi^(k_1,k_2) := \pi(k_1,k_2).


Inverting the Cantor pairing function

Let z \in \mathbb be an arbitrary natural number. We will show that there exist unique values x, y \in \mathbb such that : z = \pi(x, y) = \frac + y and hence that the function is invertible. It is helpful to define some intermediate values in the calculation: : w = x + y \! : t = \fracw(w + 1) = \frac : z = t + y \! where is the
triangle number A triangular number or triangle number counts objects arranged in an equilateral triangle. Triangular numbers are a type of figurate number, other examples being square numbers and cube numbers. The th triangular number is the number of dots in ...
of . If we solve the
quadratic equation In algebra, a quadratic equation () is any equation that can be rearranged in standard form as ax^2 + bx + c = 0\,, where represents an unknown (mathematics), unknown value, and , , and represent known numbers, where . (If and then the equati ...
: w^2 + w - 2t = 0 \! for as a function of , we get : w = \frac which is a strictly increasing and continuous function when is non-negative real. Since : t \leq z = t + y < t + (w + 1) = \frac we get that : w \leq \frac < w + 1 and thus : w = \left\lfloor \frac \right\rfloor. where is the
floor function In mathematics and computer science, the floor function is the function that takes as input a real number , and gives as output the greatest integer less than or equal to , denoted or . Similarly, the ceiling function maps to the least int ...
. So to calculate and from , we do: : w = \left\lfloor \frac \right\rfloor : t = \frac : y = z - t \! : x = w - y. \! Since the Cantor pairing function is invertible, it must be one-to-one and
onto In mathematics, a surjective function (also known as surjection, or onto function) is a function that every element can be mapped from element so that . In other words, every element of the function's codomain is the image of one element of i ...
.


Examples

To calculate : :, :, :, :, :, so . To find and such that : :, :, :, :, :, :, so ; :, :, :, so ; :, so ; :, so ; thus .


Derivation

The graphical shape of Cantor's pairing function, a diagonal progression, is a standard trick in working with
infinite sequence In mathematics, a sequence is an enumerated collection of objects in which repetitions are allowed and order matters. Like a set, it contains members (also called ''elements'', or ''terms''). The number of elements (possibly infinite) is called t ...
s and
countability In mathematics, a set is countable if either it is finite or it can be made in one to one correspondence with the set of natural numbers. Equivalently, a set is ''countable'' if there exists an injective function from it into the natural number ...
. The algebraic rules of this diagonal-shaped function can verify its validity for a range of polynomials, of which a quadratic will turn out to be the simplest, using the method of induction. Indeed, this same technique can also be followed to try and derive any number of other functions for any variety of schemes for enumerating the plane. A pairing function can usually be defined inductively – that is, given the th pair, what is the th pair? The way Cantor's function progresses diagonally across the plane can be expressed as :\pi(x,y)+1 = \pi(x-1,y+1). The function must also define what to do when it hits the boundaries of the 1st quadrant – Cantor's pairing function resets back to the x-axis to resume its diagonal progression one step further out, or algebraically: :\pi(0,k)+1 = \pi(k+1,0). Also we need to define the starting point, what will be the initial step in our induction method: . Assume that there is a quadratic 2-dimensional polynomial that can fit these conditions (if there were not, one could just repeat by trying a higher-degree polynomial). The general form is then :\pi(x,y) = ax^2+by^2+cxy+dx+ey+f. Plug in our initial and boundary conditions to get and: :bk^2+ek+1 = a(k+1)^2+d(k+1), so we can match our terms to get : : :. So every parameter can be written in terms of except for , and we have a final equation, our diagonal step, that will relate them: :\begin \pi(x,y)+1 &= a(x^2+y^2) + cxy + (1-a)x + (1+a)y + 1 \\ &= a((x-1)^2+(y+1)^2) + c(x-1)(y+1) + (1-a)(x-1) + (1+a)(y+1). \end Expand and match terms again to get fixed values for and , and thus all parameters: : : : :. Therefore :\begin \pi(x,y) &= \frac(x^2+y^2) + xy + \fracx + \fracy \\ &= \frac(x+y)(x+y+1) + y, \end is the Cantor pairing function, and we also demonstrated through the derivation that this satisfies all the conditions of induction.


Other pairing functions

The function P_2(x, y):= 2^x(2y + 1) - 1 is a pairing function. In 1990, Regan proposed the first known pairing function that is computable in
linear time In computer science, the time complexity is the computational complexity that describes the amount of computer time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations performed by ...
and with constant space (as the previously known examples can only be computed in linear time iff multiplication can be too, which is doubtful). In fact, both this pairing function and its inverse can be computed with finite-state transducers that run in real time. In the same paper, the author proposed two more monotone pairing functions that can be computed online in linear time and with
logarithmic space In computational complexity theory, L (also known as LSPACE or DLOGSPACE) is the complexity class containing decision problems that can be solved by a deterministic Turing machine using a logarithmic amount of writable memory space., Definition& ...
; the first can also be computed offline with zero space. In 2001, Pigeon proposed a pairing function based on
bit-interleaving In computing, telecommunication, information theory, and coding theory, an error correction code, sometimes error correcting code, (ECC) is used for controlling errors in data over unreliable or noisy communication channels. The central idea is ...
, defined recursively as: :\langle i,j\rangle_=\begin T & \text\ i=j=0;\\ \langle\lfloor i/2\rfloor,\lfloor j/2\rfloor\rangle_:i_0:j_0&\text \end where i_0 and j_0 are the least significant bits of ''i'' and ''j'' respectively. In 2006, Szudzik proposed a "more elegant" pairing function defined by the expression: :\operatorname
, y The comma is a punctuation mark that appears in several variants in different languages. It has the same shape as an apostrophe or single closing quotation mark () in many typefaces, but it differs from them in being placed on the baseline ...
:= \begin y^2 + x&\text\ x\neq\max\,\\ x^2 + x + y&\text\ x = \max\.\\ \end Which can be unpaired using the expression: :\operatorname := \begin \left\ & \textz - \lfloor\sqrt\rfloor^2 < \lfloor\sqrt\rfloor, \\ \left\ & \textz - \lfloor\sqrt\rfloor^2\geq\lfloor\sqrt\rfloor. \end (Qualitatively, it assigns consecutive numbers to pairs along the edges of squares.) This pairing function orders
SK combinator calculus The SKI combinator calculus is a combinatory logic, combinatory logic system and a model of computation, computational system. It can be thought of as a computer programming language, though it is not convenient for writing software. Instead, it is ...
expressions by depth. This method is the mere application to \N of the idea, found in most textbooks on Set Theory,See for instance used to establish \kappa^2=\kappa for any infinite cardinal \kappa in ZFC. Define on \kappa\times\kappa the binary relation :(\alpha,\beta)\preccurlyeq(\gamma,\delta) \text \begin (\alpha,\beta) = (\gamma,\delta),\\ pt\max(\alpha,\beta) < \max(\gamma,\delta),\\ pt\max(\alpha,\beta) = \max(\gamma,\delta)\ \text\ \alpha<\gamma,\text\\ pt\max(\alpha,\beta) = \max(\gamma,\delta)\ \text\ \alpha=\gamma\ \text\ \beta<\delta. \end \preccurlyeq is then shown to be a well-ordering such that every element has <\kappa predecessors, which implies that \kappa^2=\kappa. It follows that (\N\times\N,\preccurlyeq) is isomorphic to (\N,\leqslant) and the pairing function above is nothing more than the enumeration of integer couples in increasing order. (See also Talk:Tarski's theorem about choice#Proof of the converse.)


Notes


References

{{reflist Set theory Georg Cantor Functions and mappings