Give an example of a function $h:\mathbb{R}\backslash\mathbb{Q}\rightarrow\ \mathbb{Q}$

373 Views Asked by At

The question is

$h:\mathbb{R}\backslash\mathbb{Q}\rightarrow\ \mathbb{Q}$ so that the image of $h$ is the same as the codomain of $h$.

I couldn't really think of a function that maps irrational numbers to rational numbers. Can anyone give me some hints?

2

There are 2 best solutions below

1
On BEST ANSWER

$h(x)=r$ if $x=\sqrt2+r$ for some $r\in\mathbb Q$, and $h(x)=0$ else.

2
On

Use the floor of the absolute value, $$x\mapsto⌊|x|⌋\ :\ {\mathbb R}\setminus{\mathbb Q}\,\to\,{\mathbb N}$$ which is surjective, and further use that ${\mathbb Q}$ is countable.