Can I determine if the result of a pairing function is the from the inverse of a given pair?

35 Views Asked by At

For example, say you had the following results:

f(a, b) = c

f(b, a) = d

Is there a pairing function that would allow for determining that c is sort of the "inverse" of d without de-pairing the results?

1

There are 1 best solutions below

0
On BEST ANSWER

For this pairing function it’s not hard to test: $c$ and $d$ are related in this way iff there is an $n\in\omega$ such that $\binom{n}2<c,d\le\binom{n+1}2$ and $c+d=\binom{n}2+\binom{n+1}2-1$. Getting rid of the binomial coefficients, we have $c$ and $d$ so related iff there is an $n\in\omega$ such that

$$\frac{n(n+1)}2<c,d\le\frac{(n+1)(n+2)}2$$

and

$$c+d=\frac{n(n+1)}2+\frac{(n+1)(n+2)}2-1=n(n+2)\;.$$

Added: In practice this is more straightforward that it may at first appear. Note that $$n(n+2)=(n+1)^2-1\;,$$ so we first check whether $c+d+1$ is a square; if not, $c$ and $d$ are not related in this way. If it is, we need only check whether

$$m-1<\frac{c}m\le m+1\;,$$

where $m=\sqrt{c+d+1}$.