Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Pairing function
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Inverting the Cantor pairing function === Let <math>z \in \mathbb{N}</math> be an arbitrary natural number. We will show that there exist unique values <math>x, y \in \mathbb{N}</math> such that :<math> z = \pi(x, y) = \frac{(x + y + 1)(x + y)}{2} + y </math> and hence that the function {{math|''Ο(x, y)''}} is invertible. It is helpful to define some intermediate values in the calculation: :<math> w = x + y \!</math> :<math> t = \frac{1}{2}w(w + 1) = \frac{w^2 + w}{2} </math> :<math> z = t + y \!</math> where {{math|''t''}} is the [[triangular number|triangle number]] of {{math|''w''}}. If we solve the [[quadratic equation]] :<math> w^2 + w - 2t = 0 \!</math> for {{math|''w''}} as a function of {{math|''t''}}, we get :<math> w = \frac{\sqrt{8t + 1} - 1}{2} </math> which is a strictly increasing and continuous function when {{math|''t''}} is non-negative real. Since :<math> t \leq z = t + y < t + (w + 1) = \frac{(w + 1)^2 + (w + 1)}{2} </math> we get that :<math> w \leq \frac{\sqrt{8z + 1} - 1}{2} < w + 1 </math> and thus :<math> w = \left\lfloor \frac{\sqrt{8z + 1} - 1}{2} \right\rfloor. </math> where {{math|β β}} is the [[floor function]]. So to calculate {{math|''x''}} and {{math|''y''}} from {{math|''z''}}, we do: :<math> w = \left\lfloor \frac{\sqrt{8z + 1} - 1}{2} \right\rfloor </math> :<math> t = \frac{w^2 + w}{2} </math> :<math> y = z - t \!</math> :<math> x = w - y. \!</math> Since the Cantor pairing function is invertible, it must be [[injective function|one-to-one]] and [[surjective function|onto]].{{sfn|Szudzik|2006}}{{Additional citation needed|date=August 2021}}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)