Function of two integers that has not repeated values

46 Views Asked by At

In order to implement a software I need a function $f:\mathbb{N} \times \mathbb{N} \rightarrow \mathbb{N}$ such that: $$(x' \neq x \lor y' \neq y) \Rightarrow f(x,y) \neq f(x',y') $$

It's very easy to implement an algorithm that implements such a function, but I was not able to find an analytical representation of it.

coult you help me?

2

There are 2 best solutions below

3
On BEST ANSWER

The usual "Cantor zig-zag" mapping can be defined as

$$ (x,y) \mapsto \frac{(x+y)(x+y+1)}{2} + x $$

It has the (sometimes) nice property that it is surjective, that is, every natural number is the image of some pair, so nothing goes to waste.

2
On

If you are not afraid of being wasteful, try $f(x,y)=2^x3^y$. This is however hardly suitable for limited software.