fbpx
Wikipedia

Pairing function

In mathematics, a pairing function is a process to uniquely encode two natural numbers into a single natural number.[1][2]

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[verification needed]

 [1][2]

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,[3] or a bijection from   to A.[4]

Hopcroft and Ullman pairing function

Hopcroft and Ullman (1979) define the following pairing function:  , where  .[1] This is the same as the Cantor pairing function below, shifted to exclude 0 (i.e.,  ,  , and  ).

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

 [1][verification needed]

where  .[1]

It can also be expressed as  .[3]

It is also strictly monotonic w.r.t. each argument, that is, for all  , if  , then  ; similarly, if  , then  .[citation needed]

The statement that this is the only quadratic pairing function is known as the Fueter–Pólya theorem.[1][verification needed] Whether this is the only polynomial pairing function is still an open question. When we apply the pairing function to k1 and k2 we often denote the resulting number as k1, k2.[citation needed]

This definition can be inductively generalized to the Cantor tuple function[citation needed]

 

for   as

 

with the base case defined above for a pair:  [1][2]

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) is invertible. It is helpful to define some intermediate values in the calculation:

 
 
 

where t is the triangle number of w. If we solve the quadratic equation

 

for w as a function of t, we get

 

which is a strictly increasing and continuous function when t is non-negative real. Since

 

we get that

 

and thus

 

where ⌊ ⌋ is the floor function. So to calculate x and y from z, we do:

 
 
 
 

Since the Cantor pairing function is invertible, it must be one-to-one and onto.[3][additional citation(s) needed]

Examples

To calculate π(47, 32):

47 + 32 = 79,
79 + 1 = 80,
79 × 80 = 6320,
6320 ÷ 2 = 3160,
3160 + 32 = 3192,

so π(47, 32) = 3192.

To find x and y such that π(x, y) = 1432:

8 × 1432 = 11456,
11456 + 1 = 11457,
11457 = 107.037,
107.037 − 1 = 106.037,
106.037 ÷ 2 = 53.019,
⌊53.019⌋ = 53,

so w = 53;

53 + 1 = 54,
53 × 54 = 2862,
2862 ÷ 2 = 1431,

so t = 1431;

1432 − 1431 = 1,

so y = 1;

53 − 1 = 52,

so x = 52; thus π(52, 1) = 1432.[citation needed]

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.[a] 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 nth pair, what is the (n+1)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) = 0.

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 = 0 and:

 ,

so we can match our k terms to get

b = a
d = 1-a
e = 1+a.

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

 

Expand and match terms again to get fixed values for a and c, and thus all parameters:

a = 1/2 = b = d
c = 1
e = 3/2
f = 0.

Therefore

 

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

Other pairing functions

The function   is a pairing function.[2]

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 iff multiplication can be too, which is doubtful).[5] In fact, both this pairing function and its inverse can be computed with finite-state transducers that run in real time.[5][clarification needed] 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 zero space.[5][clarification needed]

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.[1][verification needed]

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.[3][clarification needed] This method is the mere application to   of the idea, found in most textbooks on Set Theory,[6] 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. (See also Talk:Tarski's theorem about choice#Proof of the converse.)

Notes

  1. ^ The term "diagonal argument" is sometimes used to refer to this type of enumeration, but it is not directly related to Cantor's diagonal argument.[citation needed]

References

  1. ^ a b c d e f g h i Steven Pigeon. "Pairing function". MathWorld. Retrieved 16 August 2021.
  2. ^ a b c d "pairing function". planetmath.org. 22 March 2013. Retrieved 16 August 2021.{{cite web}}: CS1 maint: url-status (link)
  3. ^ a b c d Szudzik, Matthew (2006). "An Elegant Pairing Function" (PDF). szudzik.com. (PDF) from the original on 25 November 2011. Retrieved 16 August 2021.
  4. ^ Szudzik, Matthew P. (2017-06-01). "The Rosenberg-Strong Pairing Function". arXiv:1706.04129 [cs.DM].
  5. ^ a b c Regan, Kenneth W. (1992-12-01). "Minimum-complexity pairing functions". Journal of Computer and System Sciences. 45 (3): 285–295. doi:10.1016/0022-0000(92)90027-G. ISSN 0022-0000.
  6. ^ See for instance Thomas, Jech (2006). Set theory: the third millennium edition. Springer Monographs in Mathematics. Springer-Verlag. p. 30. doi:10.1007/3-540-44761-X. ISBN 3-540-44085-2.

pairing, function, this, article, multiple, issues, please, help, improve, discuss, these, issues, talk, page, learn, when, remove, these, template, messages, this, article, needs, additional, citations, verification, please, help, improve, this, article, addi. This article has multiple issues Please help improve it or discuss these issues on the talk page Learn how and when to remove these template messages This article needs additional citations for verification Please help improve this article by adding citations to reliable sources Unsourced material may be challenged and removed Find sources Pairing function news newspapers books scholar JSTOR August 2021 Learn how and when to remove this template message This article may be confusing or unclear to readers In particular the notation for pairing functions is inconsistent throughout the article Please help clarify the article There might be a discussion about this on the talk page August 2021 Learn how and when to remove this template message Learn how and when to remove this template message In mathematics a pairing function is a process to uniquely encode two natural numbers into a single natural number 1 2 Any pairing function can be used in set theory to prove that integers and rational numbers have the same cardinality as natural numbers 1 Contents 1 Definition 2 Hopcroft and Ullman pairing function 3 Cantor pairing function 3 1 Inverting the Cantor pairing function 3 2 Examples 3 3 Derivation 4 Other pairing functions 5 Notes 6 ReferencesDefinition EditA pairing function is a bijection verification needed p N N N displaystyle pi mathbb N times mathbb N to mathbb N 1 2 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 3 or a bijection from A 2 displaystyle A 2 to A 4 Hopcroft and Ullman pairing function EditHopcroft and Ullman 1979 define the following pairing function i j 1 2 i j 2 i j 1 i displaystyle langle i j rangle frac 1 2 i j 2 i j 1 i where i j 1 2 3 displaystyle i j in 1 2 3 dots 1 This is the same as the Cantor pairing function below shifted to exclude 0 i e i k 2 1 displaystyle i k 2 1 j k 1 1 displaystyle j k 1 1 and i j 1 p k 2 k 1 displaystyle langle i j rangle 1 pi k 2 k 1 Cantor pairing function Edit The Cantor pairing function assigns one natural number to each pair of natural numbers The Cantor pairing function is a primitive recursive pairing function p N N N displaystyle pi mathbb N times mathbb N to mathbb N defined by p k 1 k 2 1 2 k 1 k 2 k 1 k 2 1 k 2 displaystyle pi k 1 k 2 frac 1 2 k 1 k 2 k 1 k 2 1 k 2 1 verification needed where k 1 k 2 0 1 2 3 displaystyle k 1 k 2 in 0 1 2 3 dots 1 It can also be expressed as P a i r x y x 2 x 2 x y 3 y y 2 2 displaystyle Pair x y frac x 2 x 2xy 3y y 2 2 3 It is also strictly monotonic w r t each argument that is for all k 1 k 1 k 2 k 2 N displaystyle k 1 k 1 k 2 k 2 in mathbb N if k 1 lt k 1 displaystyle k 1 lt k 1 then p k 1 k 2 lt p k 1 k 2 displaystyle pi k 1 k 2 lt pi k 1 k 2 similarly if k 2 lt k 2 displaystyle k 2 lt k 2 then p k 1 k 2 lt p k 1 k 2 displaystyle pi k 1 k 2 lt pi k 1 k 2 citation needed The statement that this is the only quadratic pairing function is known as the Fueter Polya theorem 1 verification needed Whether this is the only polynomial pairing function is still an open question When we apply the pairing function to k1 and k2 we often denote the resulting number as k1 k2 citation needed This definition can be inductively generalized to the Cantor tuple function citation needed p n N n N displaystyle pi n mathbb N n to mathbb N for n gt 2 displaystyle n gt 2 as p n k 1 k n 1 k n p p n 1 k 1 k n 1 k n displaystyle pi n k 1 ldots k n 1 k n pi pi n 1 k 1 ldots k n 1 k n with the base case defined above for a pair p 2 k 1 k 2 p k 1 k 2 displaystyle pi 2 k 1 k 2 pi k 1 k 2 1 2 Inverting the Cantor pairing function Edit Let z N displaystyle z in mathbb N be an arbitrary natural number We will show that there exist unique values x y N displaystyle x y in mathbb N such that z p x y x y 1 x y 2 y displaystyle z pi x y frac x y 1 x y 2 y and hence that the function p x y is invertible It is helpful to define some intermediate values in the calculation w x y displaystyle w x y t 1 2 w w 1 w 2 w 2 displaystyle t frac 1 2 w w 1 frac w 2 w 2 z t y displaystyle z t y where t is the triangle number of w If we solve the quadratic equation w 2 w 2 t 0 displaystyle w 2 w 2t 0 for w as a function of t we get w 8 t 1 1 2 displaystyle w frac sqrt 8t 1 1 2 which is a strictly increasing and continuous function when t is non negative real Since t z t y lt t w 1 w 1 2 w 1 2 displaystyle t leq z t y lt t w 1 frac w 1 2 w 1 2 we get that w 8 z 1 1 2 lt w 1 displaystyle w leq frac sqrt 8z 1 1 2 lt w 1 and thus w 8 z 1 1 2 displaystyle w left lfloor frac sqrt 8z 1 1 2 right rfloor where is the floor function So to calculate x and y from z we do w 8 z 1 1 2 displaystyle w left lfloor frac sqrt 8z 1 1 2 right rfloor t w 2 w 2 displaystyle t frac w 2 w 2 y z t displaystyle y z t x w y displaystyle x w y Since the Cantor pairing function is invertible it must be one to one and onto 3 additional citation s needed Examples Edit To calculate p 47 32 47 32 79 79 1 80 79 80 6320 6320 2 3160 3160 32 3192 so p 47 32 3192 To find x and y such that p x y 1432 8 1432 11456 11456 1 11457 11457 107 037 107 037 1 106 037 106 037 2 53 019 53 019 53 so w 53 53 1 54 53 54 2862 2862 2 1431 so t 1431 1432 1431 1 so y 1 53 1 52 so x 52 thus p 52 1 1432 citation needed Derivation Edit 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 a 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 n th pair what is the n 1 th pair The way Cantor s function progresses diagonally across the plane can be expressed as p x y 1 p x 1 y 1 displaystyle 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 p 0 k 1 p k 1 0 displaystyle 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 p 0 0 0 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 p x y a x 2 b y 2 c x y d x e y f displaystyle pi x y ax 2 by 2 cxy dx ey f Plug in our initial and boundary conditions to get f 0 and b k 2 e k 1 a k 1 2 d k 1 displaystyle bk 2 ek 1 a k 1 2 d k 1 so we can match our k terms to get b a d 1 a e 1 a So every parameter can be written in terms of a except for c and we have a final equation our diagonal step that will relate them p x y 1 a x 2 y 2 c x y 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 displaystyle begin aligned pi x y 1 amp a x 2 y 2 cxy 1 a x 1 a y 1 amp a x 1 2 y 1 2 c x 1 y 1 1 a x 1 1 a y 1 end aligned Expand and match terms again to get fixed values for a and c and thus all parameters a 1 2 b d c 1 e 3 2 f 0 Therefore p x y 1 2 x 2 y 2 x y 1 2 x 3 2 y 1 2 x y x y 1 y displaystyle begin aligned pi x y amp frac 1 2 x 2 y 2 xy frac 1 2 x frac 3 2 y amp frac 1 2 x y x y 1 y end aligned is the Cantor pairing function and we also demonstrated through the derivation that this satisfies all the conditions of induction citation needed Other pairing functions EditThe function P 2 x y 2 x 2 y 1 1 displaystyle P 2 x y 2 x 2y 1 1 is a pairing function 2 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 iff multiplication can be too which is doubtful 5 In fact both this pairing function and its inverse can be computed with finite state transducers that run in real time 5 clarification needed 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 zero space 5 clarification needed In 2001 Pigeon proposed a pairing function based on bit interleaving defined recursively as i j P T if i j 0 i 2 j 2 P i 0 j 0 otherwise displaystyle langle i j rangle P begin cases T amp text if i j 0 langle lfloor i 2 rfloor lfloor j 2 rfloor rangle P i 0 j 0 amp text otherwise end cases where i 0 displaystyle i 0 and j 0 displaystyle j 0 are the least significant bits of i and j respectively 1 verification needed In 2006 Szudzik proposed a more elegant pairing function defined by the expression ElegantPair x y y 2 x if x max x y x 2 x y if x max x y displaystyle operatorname ElegantPair x y begin cases y 2 x amp text if x neq max x y x 2 x y amp text if x max x y end cases Which can be unpaired using the expression ElegantUnpair z z z 2 z if z z 2 lt z z z z 2 z if z z 2 z displaystyle operatorname ElegantUnpair z begin cases left z lfloor sqrt z rfloor 2 lfloor sqrt z rfloor right amp text if z lfloor sqrt z rfloor 2 lt lfloor sqrt z rfloor left lfloor sqrt z rfloor z lfloor sqrt z rfloor 2 lfloor sqrt z rfloor right amp text if z lfloor sqrt z rfloor 2 geq lfloor sqrt z rfloor end cases Qualitatively it assigns consecutive numbers to pairs along the edges of squares This pairing function orders SK combinator calculus expressions by depth 3 clarification needed This method is the mere application to N displaystyle mathbb N of the idea found in most textbooks on Set Theory 6 used to establish k 2 k displaystyle kappa 2 kappa for any infinite cardinal k displaystyle kappa in ZFC Define on k k displaystyle kappa times kappa the binary relation a b g d if either a b g d max a b lt max g d max a b max g d and a lt g or max a b max g d and a g and b lt d displaystyle alpha beta preccurlyeq gamma delta text if either begin cases alpha beta gamma delta 4pt max alpha beta lt max gamma delta 4pt max alpha beta max gamma delta text and alpha lt gamma text or 4pt max alpha beta max gamma delta text and alpha gamma text and beta lt delta end cases displaystyle preccurlyeq is then shown to be a well ordering such that every element has lt k displaystyle lt kappa predecessors which implies that k 2 k displaystyle kappa 2 kappa It follows that N N displaystyle mathbb N times mathbb N preccurlyeq is isomorphic to N displaystyle mathbb 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 Edit The term diagonal argument is sometimes used to refer to this type of enumeration but it is not directly related to Cantor s diagonal argument citation needed References Edit a b c d e f g h i Steven Pigeon Pairing function MathWorld Retrieved 16 August 2021 a b c d pairing function planetmath org 22 March 2013 Retrieved 16 August 2021 a href Template Cite web html title Template Cite web cite web a CS1 maint url status link a b c d Szudzik Matthew 2006 An Elegant Pairing Function PDF szudzik com Archived PDF from the original on 25 November 2011 Retrieved 16 August 2021 Szudzik Matthew P 2017 06 01 The Rosenberg Strong Pairing Function arXiv 1706 04129 cs DM a b c Regan Kenneth W 1992 12 01 Minimum complexity pairing functions Journal of Computer and System Sciences 45 3 285 295 doi 10 1016 0022 0000 92 90027 G ISSN 0022 0000 See for instance Thomas Jech 2006 Set theory the third millennium edition Springer Monographs in Mathematics Springer Verlag p 30 doi 10 1007 3 540 44761 X ISBN 3 540 44085 2 Retrieved from https en wikipedia org w index php title Pairing function amp oldid 1124972738, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.