I don't think that works, though. Take for example these two coordinates:
(30, 75)
(90, 225)
Those would both map to the same rational—2/5—and that would make it not a one-to-one mapping.I don't think that works, though. Take for example these two coordinates:
(30, 75)
(90, 225)
Those would both map to the same rational—2/5—and that would make it not a one-to-one mapping.0 1 2 3 4
0 -1 1 -2 2
in c code: if(x<0) ? (x * -2)-1 : x * 2;
(pretend that's fixed width above)
Next, any rational can be broken down into a unique prime factorization. 4/6 = 2^1 * 3^-1, 4/15 = 2^2 * 3^-1 * 5^-1
From the factorization, define a transform where the exponent for each prime is replaced using the mapping above: so (2^2 * 3^-1 * 5^-1) becomes (2^4 * 3^1 * 5^1) = 240.
Since the original rational can be negative, you'll need to use the first transformation again, so 4/15 = 240, -4/15 = -240, which work out to 480 and 479 respectively.
0 and 1 are left unchanged by the factorization process so 0 maps to 0, 1 to 2, and -1 to 1.
For example, the set of all pairs of natural numbers can be counted something like this:
1,1
2,1
2,2
1,2
3,1
3,2
3,3
1,3
2,3
...