Probability of a number being rational

The function $f$ is indeed not Riemann-integrable, but it is Lebesgue-integrable. And its integral is $0$. Therefore, the answer is $0$. That is natural, since $\mathbb Q\cap[0,1]$ is countable, whereas $[0,1]$ is uncountable. It follows that there is no bijection between $\mathbb Q\cap[0,1]$ and $[0,1]\setminus\mathbb Q$.


This answer might miss the real goal, but is inspired by the tag "probability".


In your question it is not explicitly mentioned how probability $P$ is defined.

So actually the question: "what is the probability that $x$ is rational?" makes no sense in this context.

Your try indicates that you are thinking of uniform distribution on interval $[0,1]$ where: $$P(B):=\lambda(B\cap[0,1])$$ for every Borel set and $\lambda$ denotes the Lebesgue measure on the $\sigma$-algebra of Borel sets $B\subseteq\mathbb R$.

It is well known that $\lambda(\{x\})=0$ for any $x\in\mathbb R$ and consequently we have $\lambda(S)=\sum_{x\in S}\lambda(\{x\})=0$ for every countable set, and of course $\mathbb Q$ is countable.

So under uniform distribution on $[0,1]$ we have $P(\mathbb Q)=0$.

In probability theory Riemann-integrability is (as far as I know) not practicized.

Notation $P(x\in \mathbb Q)$ only makes sense if $x$ denotes a random variable here.

So your problem setting: "if $x\in[0,1]$ then what is $P(x\in\mathbb Q)$?" is not okay.


I want to try comparing the cardinalities of the rational set and the irrational set by using a one-to-one mapping between the two sets

You can't. The set of rationals is countable. The set of irrationals is uncountable (see Proof that the irrational numbers are uncountable). Cantor proved by diagonalization that such that mapping cannot exist.