Is there a function $f\colon\mathbb{R}\to\mathbb{R}$ such that every non-empty open interval is mapped onto $\mathbb{R}$?

Solution 1:

The Conway base 13 function is one such function. From Wikipedia:

$f$ takes as its value every real number somewhere within every open interval $(a,b)$.

The construction of the function is a little bit complicated. Refer to the wiki page for details.

Solution 2:

My answer to this question is precisely such a function, constructed in an easy way:

There is in fact a rather easy example of a function $\mathbb R \to \mathbb R$ such that the image of every open set is $\mathbb R$: Let $(x_i)_{i\in\mathbb Z_+}$ be the binary decimal expansion of $x$, so that each $x_i\in\{0,1\}$. Let then $$f(x)=\sum_{k=1}^∞\frac{(−1)^{x_k}}k\quad \textrm{if the series converges}$$ $$f(x)=0\quad\textrm{otherwise.}$$ Since the harmonic series (or a tail of it) can be made to converge to any real number by changing signs in the appropriate way, this function has $f((a,b))=\mathbb R$ for any real $a,b$.

The harmonic series can be substituted with any other unbounded series where the summand goes to zero.

Solution 3:

Let $K$ be the Cantor set. For any $a, b\in \mathbb R,$ $a\ne 0,$ I'll also call $aK+b$ a Cantor set. Since $K$ has the cardinality of $\mathbb R,$ so do these other Cantor sets.

Note that if $U$ is any nonempty open subset of $\mathbb R,$ there exists a Cantor set inside of $U.$

Let $I_1,I_2, \dots$ be the open intervals in $\mathbb R$ with rational end points.

Claim: There are pairwise disjoint Cantor sets $K_1,K_2, \dots$ such that for each $n,$ $K_n \subset I_n.$

The claim is a nice exercise. Let's assume the result. For each $n$ there exists a bijection $f_n:K_n \to \mathbb R.$ Define $f:\mathbb R \to \mathbb R$ as follows. For each $n,$ set $f= f_n$ on $K_n.$ Set $f=0$ everywhere else.

Then $f$ has the desired property. Proof: Suppose $I$ is a nonempty open interval. Then $I_n\subset I$ for some $n.$ Since $K_n \subset I_n,$ we have $\mathbb R = f(K_n) \subset f(I_n) \subset f(I),$ and we're done.

Solution 4:

I find it easier to define one from $(0,1)$ to $(0,1)$. You can use your favorite bijection to stretch each axis to $\Bbb R$. Express $x \in (0,1)$ in base $3$, choosing the expansion ending in all $2$'s for numbers which would terminate. If $x$ has an infinite number of $2$'s in the expansion, set $f(x)=x$ and ignore it in the rest. If $x$ has a finite number of $2$'s in the expansion, multiply it by $3^k$ so that the last two is just to the left of the ternary point. The expansion is now all $0$'s and $1$'s. Read it as a binary number and return that value. To show it takes all values in an interval, let somebody give you a value $y$ it should take. Express $y$ in binary. Find an interval $(\frac {3m+2}{3^k},\frac {3m+3}{3^k})$ that is within the given interval for some naturals $m,k$. Express $\frac {3m+2}{3^k}$ in ternary and append the binary of $y$ on the right. That will give you an $x$ such that $f(x)=y$ This needs a slight patch because some numbers are mapped to $1$, which is outside the range, so map them to $0.5$ and we are done.