Pairing function
Template:Short description Script error: No such module "Unsubst".
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.[1]
Definition
A pairing function is a bijection
Generalization
More generally, a pairing function on a set is a function that maps each pair of elements from into an element of , such that distinct pairs of elements of are associated with distinct elements of ,Template:SfnTemplate:Efn or a bijection from to .Template:Sfn
Instead of abstracting from the domain, the arity of the pairing function can also be generalized: there exists an n-ary generalized Cantor pairing function on .Template:Sfn
Cantor pairing function
The Cantor pairing function is a primitive recursive pairing function
defined by
where .Template:SfnTemplate:Bsn
It can also be expressed as .Template:Sfn
It is also strictly monotonic with respect to each argument, that is, for all , if , then ; similarly, if , then .Script error: No such module "Unsubst".
The statement that this is the only quadratic pairing function is known as the Fueter–Pólya theorem.[2] Whether this is the only polynomial pairing function is still an open question. When we apply the pairing function to k1Script error: No such module "Check for unknown parameters". and k2Script error: No such module "Check for unknown parameters". we often denote the resulting number as ⟨k1, k2⟩Script error: No such module "Check for unknown parameters"..Script error: No such module "Unsubst".
This definition can be inductively generalized to the Template:Citation needed span
for as
with the base case defined above for a pair: Template:Sfn
Another generalization of the Cantor pairing function to a bijection is provided by the combinatorial number system:
Inverting the Cantor pairing function
Let be an arbitrary natural number. We will show that there exist unique values such that
and hence that the function π(x, y)Script error: No such module "Check for unknown parameters". is invertible. It is helpful to define some intermediate values in the calculation:
where tScript error: No such module "Check for unknown parameters". is the triangle number of wScript error: No such module "Check for unknown parameters".. If we solve the quadratic equation
for wScript error: No such module "Check for unknown parameters". as a function of tScript error: No such module "Check for unknown parameters"., we get
which is a strictly increasing and continuous function when tScript error: No such module "Check for unknown parameters". is non-negative real. Since
we get that
and thus
where ⌊ ⌋Script error: No such module "Check for unknown parameters". is the floor function. So to calculate xScript error: No such module "Check for unknown parameters". and yScript error: No such module "Check for unknown parameters". from zScript error: No such module "Check for unknown parameters"., we do:
Since the Cantor pairing function is invertible, it must be one-to-one and onto.Template:SfnTemplate:Additional citation needed
Examples
To calculate π(47, 32)Script error: No such module "Check for unknown parameters".:
- 47 + 32 = 79Script error: No such module "Check for unknown parameters".,
- 79 + 1 = 80Script error: No such module "Check for unknown parameters".,
- 79 × 80 = 6320Script error: No such module "Check for unknown parameters".,
- 6320 ÷ 2 = 3160Script error: No such module "Check for unknown parameters".,
- 3160 + 32 = 3192Script error: No such module "Check for unknown parameters".,
so π(47, 32) = 3192Script error: No such module "Check for unknown parameters"..
To find xScript error: No such module "Check for unknown parameters". and yScript error: No such module "Check for unknown parameters". such that π(x, y) = 1432Script error: No such module "Check for unknown parameters".:
- 8 × 1432 = 11456Script error: No such module "Check for unknown parameters".,
- 11456 + 1 = 11457Script error: No such module "Check for unknown parameters".,
- Template:Radic = 107.037Script error: No such module "Check for unknown parameters".,
- 107.037 − 1 = 106.037Script error: No such module "Check for unknown parameters".,
- 106.037 ÷ 2 = 53.019Script error: No such module "Check for unknown parameters".,
- ⌊53.019⌋ = 53Script error: No such module "Check for unknown parameters".,
so w = 53Script error: No such module "Check for unknown parameters".;
- 53 + 1 = 54Script error: No such module "Check for unknown parameters".,
- 53 × 54 = 2862Script error: No such module "Check for unknown parameters".,
- 2862 ÷ 2 = 1431Script error: No such module "Check for unknown parameters".,
so t = 1431Script error: No such module "Check for unknown parameters".;
- 1432 − 1431 = 1Script error: No such module "Check for unknown parameters".,
so y = 1Script error: No such module "Check for unknown parameters".;
- 53 − 1 = 52Script error: No such module "Check for unknown parameters".,
so x = 52Script error: No such module "Check for unknown parameters".; thus π(52, 1) = 1432Script error: No such module "Check for unknown parameters"..Script error: No such module "Unsubst".
Derivation
The graphical shape of Cantor's pairing function, a diagonal progression, is a standard trick in working with infinite sequences and countability.Template:Efn 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 nScript error: No such module "Check for unknown parameters".th pair, what is the (n+1)Script error: No such module "Check for unknown parameters".th pair? The way Cantor's function progresses diagonally across the plane can be expressed as
- .
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:
- .
Also we need to define the starting point, what will be the initial step in our induction method: π(0, 0) = 0Script error: No such module "Check for unknown parameters"..
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
- .
Plug in our initial and boundary conditions to get f = 0Script error: No such module "Check for unknown parameters". and:
- ,
so we can match our kScript error: No such module "Check for unknown parameters". terms to get
- b = aScript error: No such module "Check for unknown parameters".
- d = 1-aScript error: No such module "Check for unknown parameters".
- e = 1+aScript error: No such module "Check for unknown parameters"..
So every parameter can be written in terms of aScript error: No such module "Check for unknown parameters". except for cScript error: No such module "Check for unknown parameters"., and we have a final equation, our diagonal step, that will relate them:
Expand and match terms again to get fixed values for aScript error: No such module "Check for unknown parameters". and cScript error: No such module "Check for unknown parameters"., and thus all parameters:
- a = Template:Sfrac = b = dScript error: No such module "Check for unknown parameters".
- c = 1Script error: No such module "Check for unknown parameters".
- e = Template:SfracScript error: No such module "Check for unknown parameters".
- f = 0Script error: No such module "Check for unknown parameters"..
Therefore
is the Cantor pairing function, and we also demonstrated through the derivation that this satisfies all the conditions of induction.Script error: No such module "Unsubst".
Shifted Cantor pairing function
The following pairing function: , where .[3] is the same as the Cantor pairing function, but shifted to exclude 0 (i.e., , , and ).Template:Sfn It was used in the popular computer textbook of Hopcroft and Ullman (1979).
Other pairing functions
The function is a pairing function.
In 1990, Regan proposed the first known pairing function that is computable in linear time and with constant space (as the previously known examples can only be computed in linear time if multiplication can be too, which is doubtful). In fact, both this pairing function and its inverse can be computed with finite-state transducers. In the same paper, the author proposed two more monotone pairing functions that can be computed online in linear time and with logarithmic space; the first can also be computed offline with constant space.Template:Sfn
In 2001, Pigeon proposed a pairing function based on bit-interleaving, defined recursively as:
where and are the least significant bits of i and j respectively.Template:SfnTemplate:Bsn
In 2006, Szudzik proposed a "more elegant" pairing function defined by the expression:
Which can be unpaired using the expression:
(Qualitatively, it assigns consecutive numbers to pairs along the edges of squares.) This pairing function orders SK combinator calculus expressions by depth.Template:SfnScript error: No such module "Unsubst". This method is the application to of the idea, found in set theory textbooks,[4] used to establish for any infinite cardinal in ZFC. Define on the binary relation
is then shown to be a well-ordering such that every element has predecessors, which implies that . It follows that is isomorphic to and the pairing function above is nothing more than the enumeration of integer couples in increasing order.Template:Efn
Citations
Notes
Footnotes
<templatestyles src="Reflist/styles.css" />
- ↑ Script error: No such module "Footnotes".:
"Pairing functions arise naturally in the demonstration that the cardinalities of the rationals
and the nonnegative integers
are the same, i.e.,
, originally due to Cantor."
- ↑ Script error: No such module "Footnotes". cited in Script error: No such module "Footnotes"..
- ↑ Script error: No such module "Footnotes". cited in Script error: No such module "Footnotes"..
- ↑ See for instance Script error: No such module "Footnotes"..
Script error: No such module "Check for unknown parameters".
References
- Script error: No such module "Template wrapper".Template:Sfn whitelist
- Script error: No such module "Citation/CS1".
- Script error: No such module "Citation/CS1".
- Script error: No such module "citation/CS1".
- Script error: No such module "citation/CS1".
- Script error: No such module "citation/CS1".
- Script error: No such module "citation/CS1".
- Script error: No such module "citation/CS1".