Hello out there!
Tja... die Menge der rationalen Zahlen ist nicht endlich und wahrscheinlich auch nicht bijektiv auf die natürlichen Zahlen abbildbar - oder hast Du die Formel?
Jetzt auch die. Der Einfachhalt halber nicht für ℚ ↔ ℕ, sondern für ℕ² ↔ ℕ. Wie [MudGuard] sagte, müsste bei ℚ noch auf die Teilerfremdheit von Zähler und Nenner geachtet werden.
Folgende Durchnumerierung der Paare (x₁, x₂):
x₁ 0 1 2 3 4 ⋯
x₂
0 0 1 4 9 16
1 3 2 5 10 17
2 8 7 6 11 18
3 15 14 13 12 19
4 24 23 22 21 20
⋮ ⋱
Die Nummer y ergibt sich aus:
[latex]f: \mathbb{N}^2 \longrightarrow \mathbb{N}[/latex]
[latex]y = f(x_1,x_2) = \begin{cases} x_1^2+x_2, & x_1 \ge x_2 \ \left( x_2+1\right) ^2-x_1-1, & x_1 < x_2 \end{cases}[/latex]
Andersherum ergibt sich (x₁, x₂) aus der Nummer:
[latex]f^{-1}: \mathbb{N} \longrightarrow \mathbb{N}^2[/latex]
[latex]\begin{pmatrix} x_1 \ x_2 \end{pmatrix} = f^{-1}(y) = \begin{cases} \begin{pmatrix} \lfloor \sqrt{y} \rfloor \ y- \lfloor \sqrt{y} \rfloor^2 \end{pmatrix}, & y - \lfloor \sqrt{y} \rfloor ^2 \le \lfloor \sqrt{y} \rfloor +1 \ \begin{pmatrix} \left( \lfloor \sqrt{y} \rfloor +1 \right)^2-y-1 \ \lfloor \sqrt{y} \rfloor \end{pmatrix}, & y - \lfloor \sqrt{y} \rfloor ^2 > \lfloor \sqrt{y} \rfloor +1\end{cases}[/latex]
See ya up the road,
Gunnar
PS: [latex]\lfloor a \rfloor[/latex] bedeutet floor(a)
PPS: Hoffe, ich hab mich nicht vertan.
“Remember, in the end, nobody wins unless everybody wins.” (Bruce Springsteen)