Pairing function; function <math>v
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 f:Nk → N into a new function g:N → N.
Every pairing function is primitive recursive.
Contents |
Definition
A pairing function is a bijective function
- <math>\pi:\mathbb{N} \times \mathbb{N} \to \mathbb{N}.</math>
Cantor pairing function
The Cantor pairing function is a pairing function
- <math>\pi:\mathbb{N} \times \mathbb{N} \to \mathbb{N}</math>
defined by
- <math>\pi(k_1,k_2) := \frac{1}{2}(k_1 + k_2)(k_1 + k_2 + 1)+k_2.</math>
When we apply the pairing function to <math>k_1</math> and <math>k_2</math> we often denote the resulting number as <math>\langle k_1, k_2 \rangle</math>
This definition can be inductively generalized to the Cantor tuple function
- <math>\pi^{(n)}:\mathbb{N}^n \to \mathbb{N}</math>
as
- <math>\pi^{(n)}(k_1, \ldots, k_{n-1}, k_n) := \pi ( \pi^{(n-1)}(k_1, \ldots, k_{n-1}) , k_n)</math>
Inverting the Cantor pairing function
Suppose we are given z with
- <math> z = \langle x, y \rangle = \frac{(x + y)(x + y + 1)}{2} + y </math>
and we want to find x and y. It is helpful to define some intermediate values in the calculation:
- <math> w = x + y \!</math>
- <math> t = \frac{w(w + 1)}{2} = \frac{w^2 + w}{2} </math>
- <math> z = t + y \!</math>
where t is the triangle number of w. If we solve the quadratic equation
- <math> w^2 + w - 2t = 0 \!</math>
for w as a function of t, we get
- <math> w = \frac{\sqrt{8t + 1} - 1}{2} </math>
which is a strictly increasing and continuous function when 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>.
So to calculate x and y from 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 one-to-one and onto.
References
- APOLLO NEWS :: CUT WINTER UTILITY BILLS AND REDUCE THE CARBON Cut Winter Utility Bills and Reduce the Carbon Footprint ►►Homeowners can cut their utility bills, enjoy a more comfortable homethis winter and curb
- Living On A Dime - Tips for Reducing Electric Bills I was wondering if you have any wise tips on reducing our utility bills? Our utility company just raised their rates, and we received a $300.
- Tips.Net: Reducing Your Utility Bill Your utility bill is one of those bills that you will always have and always have to pay; you can't go without electricity. While it may be a bit pricey
- Talisen Technologies - Utility Bill Management Allow analysis of previous utility bills in order to determine trends and analyze historical information. Further reduce utility costs by ensuring that
- Humidifier can reduce utility bills Chicago Sun-Times - Find Articles Humidifier can reduce utility bills from Chicago Sun-Times in Array provided free by LookSmart Find Articles.
- Business utility bills Reduce the cost of your utility bills by switching business gas supplier Reduce the cost of your business utility bills for calls and line rental
- New Jersey Department of the Public Advocate | FAQs (see How can I use conservation to reduce utility bills? Energy conservation can help a great deal in reducing your utility bill.
- How can I Reduce my Utility Bills? Brief and Straightforward Guide: How can I Reduce my Utility Bills?
- Reduce Utility Costs We will analyze your average utility bill to help you reduce utility costs. Q: How do I know if I’m paying too much on my utility bills?
- Metrix Software You can track utility bills for your facilities, monitor performance, reduce utility cost overruns, and prioritize your facility management resources.
- myGHBA.com: Reduce Utility Bills While Increasing Comfort Concerned homeowners are looking for cost-effective ways to reduce utility bills while increasing the comfort of their homes.