Bijective function N -> Q and N -> N x {1,...,n}

54 Views Asked by At

For N -> Q I tried the following:

j : N -> Q, j(n) = j(2^v * u) = p/q with p = v+1 and q = (u+1)/2
n : p/q
1 : 1/1
2 : 2/1
3 : 1/2
4 : 3/1
5 : 1/3
6 : 2/2

n=1 and n=6 return the same result '1' with different p and q.
Therefore it is not injective. => j(n) is not bijective.

Does anyone know a better solution? I would prefer the simplest function.

For N -> N x {1,...,n} I really dont have an idea.

1

There are 1 best solutions below

0
On

$\Bbb N \leftrightarrow \Bbb Q$ is hard because fractions reduce. You can look up the Cantor pairing function for $\Bbb N \leftrightarrow \Bbb {N \times N}$. There are many answers on this site involving it.

For $\Bbb N \leftrightarrow \Bbb N \times \{1,2,3,\ldots n\}$ there is $$k \leftrightarrow (\lfloor \frac kn \rfloor, k \bmod n)$$ if you accept $0 \in \Bbb N$