f(r) = if (r == 0) { 0 } { else f(p(r)) + 1 }
If your objection is "You can't determine what the previous real number is." Then my counter-objection is "Please prove that you can't." Which I don't think is possible without first assuming reals are uncountable.Given real number r, assume there exists a real number q such that q < r and there does not exist a real number x such that q < x < r. Let real number y = (q + r) / 2. It is trivial to show that q < y < r. Therefore we have a contradiction, and therefore there does not exist a real number q that meets our conditions for a "previous real number".
If you take issue with this, then I suggest you read up on the standard construction of the number systems from the naturals up to the reals. This is all very rigorously defined in terms of ZFC set theory.
Cantor's diagonal argument shows that any mapping from the natural numbers to the real numbers must necessarily miss some real numbers out. It takes some time to get your head around if you aren't used to mathematical proofs, but it's definitely worth looking it up and trying to work through it if you're interested in this subject.
So for example, the set of natural numbers is countably infinite and we know this because we can write a function that maps each natural number to exactly one natural number: the id function.
We can extend this and say that the set of even natural numbers is countably infinite because it has a mapping function of x => x / 2.
The same is true for all integers (natural numbers + negative numbers): x => if (x < 0) { x * -1 * 2 } else if (x == 0) { 0 } else { x * 2 + 1 }, i.e. if it's negative map it to an even number and if it is positive map it to an odd number, if it's zero map it to itself.
You can even write a function that maps all rational numbers to the natural numbers, since each rational number can be written as a fraction of two integers. (Figuring out the function is a fun exercise but it is also easy to google)
However, you can't write a function that maps any real number to a natural number. The easiest to understand proof of this is Cantor's Diagonal Argument[0], which is a proof by contradiction that shows that any attempted function must exclude some real numbers. Therefore, the real numbers are not countably infinite, and we call them uncountably infinite.
EDIT: In response to your edit, Cantor's Diagonal Argument basically shows that for any given function (and you have to define the function completely ahead of time - that's key) I can give you a real number that is not included in the domain of your function.
[0]: https://en.wikipedia.org/wiki/Cantor%27s_diagonal_argument