Pairing function

From testwiki
Jump to navigation Jump to search

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 into a new function .

Definition

A pairing function is a computable bijection

Cantor pairing function

The Cantor pairing function assigns one natural number to each pair of natural numbers

The Cantor pairing function is a primitive recursive pairing function

defined by

The statement that this is the only quadratic pairing function is known as the Fueter–Pólya theorem. Whether this is the only polynomial pairing function is still an open question. When we apply the pairing function to Template:Math and Template:Math we often denote the resulting number as Template:Math.

This definition can be inductively generalized to the Cantor tuple function

for as

with the base case defined above for a pair:

Inverting the Cantor pairing function

Let be an arbitrary natural number. We will show that there exist unique values such that

and hence that Template:Math is invertible. It is helpful to define some intermediate values in the calculation:

where Template:Math is the triangle number of Template:Math. If we solve the quadratic equation

for Template:Math as a function of Template:Math, we get

which is a strictly increasing and continuous function when Template:Math is non-negative real. Since

we get that

and thus

where Template:Math is the floor function. So to calculate Template:Math and Template:Math from Template:Math, we do:

Since the Cantor pairing function is invertible, it must be one-to-one and onto.

Examples

To calculate Template:Math:

Template:Math,
Template:Math,
Template:Math,
Template:Math,
Template:Math,

so Template:Math.

To find Template:Math and Template:Math such that Template:Math:

Template:Math,
Template:Math,
Template:Math,
Template:Math,
Template:Math,
Template:Math,

so Template:Math;

Template:Math,
Template:Math,
Template:Math,

so Template:Math;

Template:Math,

so Template:Math;

Template:Math,

so Template:Math; thus Template:Math.

Derivation

A diagonally incrementing "snaking" function, from same principles as Cantor's pairing function, is often used to demonstrate the countability of the rational numbers.

The graphical shape of Cantor's pairing function, a diagonal progression, is a standard trick in working with infinite sequences and countability.[note 1] 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 Template:Mathth pair, what is the Template:Mathth 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: Template:Math.

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 Template:Math and:

,

so we can match our Template:Math terms to get

Template:Math
Template:Math
Template:Math.

So every parameter can be written in terms of Template:Math except for Template:Math, and we have a final equation, our diagonal step, that will relate them:

Expand and match terms again to get fixed values for Template:Math and Template:Math, and thus all parameters:

Template:Math
Template:Math
Template:Math
Template:Math.

Therefore

is the Cantor pairing function, and we also demonstrated through the derivation that this satisfies all the conditions of induction.

Notes

Template:Reflist

External links


Cite error: <ref> tags exist for a group named "note", but no corresponding <references group="note"/> tag was found