# Function $f: \mathbb{R} \to \mathbb{R}$ that takes each value in $\mathbb{R}$ three times

Does there exist a function $f: \mathbb{R} \to \mathbb{R}$ that takes each value in $\mathbb{R}$ three times? If not, how could I prove that such a function does not exist?

• Is it three times only, or $\geq3$ times?
– user122283
Apr 1 '14 at 23:10
• $\geq 3$ times is very trivial Apr 1 '14 at 23:11
• Exactly three times Apr 1 '14 at 23:11
• If you don't require $f$ to be continuous, no problem. Apr 1 '14 at 23:11
• Six answers so far and zero up votes on the question, really? Apr 1 '14 at 23:35

Here's a continuous solution:

$$f(x) = \begin{cases} 4x-3\lfloor x\rfloor & \text{when \lfloor x\rfloor is even} \\ 3\lfloor x\rfloor + 3 - 2x & \text{when \lfloor x \rfloor is odd} \end{cases}$$

This takes on the values $0,4,2,6,4,8,6,10,8,\ldots$ at integer $x$ and interpolates linearly between them. Any even number $2m$ is hit at $f(2m)$ (a local minimum), $f(2m-\frac32)$ (the middle of an increasing line segment), and $f(2m-3)$ (a local maximum). All other numbers are hit by a point in an increasing line segment, then a decreasing one, and finally another increasing one.

A smoother function with the same overall shape would be $g(x)=ax+\sin x$, except the coefficient $a$ has to be just right in order to get the local maxima and minima to coincide, and I'm too lazy to figure out what it should be.

• @Henning Makholm: Just looking at the graph the first half of the first segment does not seem to attain every height 3 times (visually). That is, values $y<2$. Perhaps you mean the graph extends to negative region too? Apr 2 '14 at 0:25
• @PVanchinathan: The function is $\mathbb R\to\mathbb R$; the graph (contributed by Omnomnomnom) shows it only for $x$ between $0$ and $10$, but it is to be understood that it extends indefinitely below and above that interval. Apr 2 '14 at 0:30
• Sorry if I sounded like asking something too obvious. I am curious to know the answer to the same question if we are looking for functions on bounded open interval.Seems like metric or order plays a role. I am not able to see it clearly. Apr 2 '14 at 1:11
• @PVanchinathan: From/to an open interval, just compose this function with your favorite homeomorphism between $\mathbb R$ and the open interval -- arctan, erf, tanh, whatever. Apr 2 '14 at 9:52
• Continuity is ok. As we are composing with a bijection, the number of inverse images remains the same. Nice example. By the way what is erf? Apr 2 '14 at 16:43

I am exporting the answer I gave to a closed question.

$$f(x)=2\left\lfloor\frac{x}{3\pi}\right\rfloor-\cos\left(3\pi\left\{\frac{x}{3\pi}\right\}\right)\tag{1}$$ is a differentiable function that attains any real value in exaclty three points, whose graphics is the following one:

$\hskip2in$ If in $(1)$ you replace "$3$" with the positive odd integer $2m+1$, you get a function that attains any real value in exactly $2m+1$ points. You can also take:

$$f(x) = T_{2m+1}\left(x-2\left\lceil\frac{x-1}{2}\right\rceil\right)+2\left\lceil\frac{x-1}{2}\right\rceil,$$

where $T_{2m+1}$ is the $(2m+1)$-th Chebyshev polynomial of the first kind. This is a $C^1(\mathbb{R})$ function, too.

• I noticed that you posted a comment about it not being a duplicate, but so far I am the only one who has voted to reopen. Aug 12 '14 at 22:28
• I'm gonna vote too. Aug 12 '14 at 22:40
• @JackD'Aurizio : Could you please see this wolfram plot , I think it shows that the first function is discontinuous ..... www4f.wolframalpha.com/Calculate/MSP/…
– user228168
May 16 '15 at 12:50

Continuity works :

$$f(x) = \left\{ \begin{array}{ll} 3(x-k)+k & 0\le x-k\le \frac{1}3 \\ −3(x−k)+2+k & \frac{1}{3}\le x-k\le \frac{2}3 \\3(x−k)−2+k &\frac{2}{3}\le x-k\le 1 \end{array} \right.$$

In fact one can prove the following statement : There exists a continuous function that takes all the values ​​of its image exactly $n$ times if and only if $n$ is odd.

• Nice general result. The example here generalizes easily to show the "if" direction, but is there a sleek way to show "only if"? Apr 1 '14 at 23:43

Yes, in fact there is a very general way to construct functions like this. For example, essentially the same proof works for any $n$ instead of just $3$.

It suffices to note that $\mathbb R$ and $\mathbb R\times \{0,1,2\}$ have the same cardinality. To see this, note that we have an obvious injection $\mathbb R\to \mathbb R\times \{0,1,2\}$, and we can define an injection the other way by $$f(x,y)=\begin{cases} \arctan x\ &\text{if } y = 0\\ \arctan x + \pi &\text{if } y = 1\\ \arctan x + 2\pi &\text{if } y = 2 \end{cases}$$ thus by Bernstein-Schroeder there exists some bijection $g:\mathbb R\to \mathbb R\times \{0,1,2\}$. Now let $h(x)$ be the first component of $g(x)$.

• @AymanHourieh I do indeed. Apr 1 '14 at 23:26

If you can construct a bijection $\varphi:[0,1)\to(0,1)$, then you can construct bijections $f:(-\infty,0)\to(-\infty,\infty),\ g:[0,1)\to(-\infty,\infty)$, and $h:[1,\infty)\to(-\infty,\infty)$, and take their union.

Namely, let $f(x)=\log(-x),\ g(x)=\tan(\pi(\varphi(x)-\frac12)),\ h(x)=g(\frac2{\pi}\arctan(x-1))$.

Here's a continuous, non-piecewise function that does it, and it's very simple too. Consider $$f(x) = \sin(x) + \frac{2x}{3\pi} \text{.}$$

• No, $\frac{2}{3\pi}$ is not the right coefficient. Your $f(x)$ has five roots, approximately $\{-4.7, -4.3, 0, 4.3, 4.7\}$. Apr 1 '14 at 23:40
• You're right. There's gonna be some disgusting math in getting the slope of that $x$ term. I figured I'd just solve $\sin(\frac{3\pi}{2}) + a\frac{3\pi}{2} = 0$ and the slope would be $a$, but it's really not that easy. Apr 1 '14 at 23:53
• See math.stackexchange.com/a/1030738/50776: You want the $a$ in $f(x)=\sin x+ax$ to be the unique solution of $\sqrt{1-a^2}=\pi+\cos^{-1}a$ with the usual branch for $\cos^{-1}$, roughly $a\approx0.217234$. This is equivalent to demanding that the unique local minimum of $f(x)$ in the region $[0,2\pi]$ has value $0$. (Also it is more impressive if you say your solution is analytic rather than just continuous, like the other solutions.) Dec 7 '15 at 19:30

$\text{cotan}(\frac{3\pi}{1+e^{-x}})$ will do. Here is the plot of the function: • Right - couldn't we just take three lines, if we are able to restrict the domain? Dec 7 '15 at 18:56
• Please note that I changed the function, and the domain the entire $\mathbb{R}$ now.
– Sobi
Dec 7 '15 at 19:29