How do you construct a continuous function over the interval $(0,1)$ whose image is the entire real line?

When I first saw this problem, I thought $\frac{1}{x(x-1)}$ might work since it is continuous on $(0,1)$, but when I graphed it, I saw that there is a minimum at $(1/2,4)$, so the image is $[4,\infty)$ and not $(-\infty,\infty)$.

Apparently, one answer to this question is:


But how is one supposed to arrive at this answer without using a graphing calculator?

  • 3
    $\begingroup$ Modify the tangent function $\endgroup$ – Sri-Amirthan Theivendran Mar 25 '17 at 22:42
  • $\begingroup$ The question is "how do you construct a function?", not "gimme functions plz". Please answer the question, not answer the question that the question is asking about. $\endgroup$ – wizzwizz4 Mar 26 '17 at 8:56
  • $\begingroup$ You're wrong about your function's values. $1/x(x-1)$ is always negative and so can't have a minimum at $4$ notice that $x$ is positive and $x-1$ is negative on your interval. The value at $1/2$ is $-1$. $\endgroup$ – Stella Biderman Mar 26 '17 at 13:32

Hopefully you agree that you want functions with vertical asymptotes at $0$ and $1$, which is why you wanted to try $\frac{1}{x(x-1)}$. The problem with it is that, on the interval $(0,1)$, it goes to $-\infty$ both near $0$ and near $1$ (the easiest calculator-free way to notice this is to note that it is always negative).

How can we fix this problem? By multiplying by a continuous function which is positive near $1$ (so the product still goes to $-\infty$ near $1$) and negative near $0$ (so it goes to $+\infty$ near $0$). One simple function like this is $2x-1$.


I'd like to provide a different flavor of function. For $x \in (0,1)$

$$f(x) = \tan\bigg(\pi x-\frac{\pi}{2}\bigg)$$

EDIT: How we get to above result?

We start with $\tan(x)$, which is continuous over $x \in (-\pi/2, \pi/2)$ whose image is the entire real line.

We want $x$ to be $(0,1)$ instead. So one easy way is we find a linear transformation (thus is continuous) of $x$ to transform $x$ from $(-\pi/2, \pi/2)$ to $(0,1)$.

Notice that if $\pi x \in (-\pi/2, \pi/2)$, then we have $x \in (-1/2, 1/2)$.

And if $(\pi x - \pi/2) \in (-\pi/2, \pi/2)$, then we have $x\in (0,1)$, and that is what we want.


You've come up with a function symmetric about $x=\frac{1}{2}$: it's an "even function" except that it's "even about $x=\frac{1}{2}$" rather than about $x=0$.

Translate left by $\frac{1}{2}$; then you've made a bona fide even function ("even about $x=0$"). Now, to get a function which is "odd about $x=\frac{1}{2}$", just multiply the translated version by $x$ to get a bona fide odd function, and then translate back. That's what you've done (up to a factor of $2$).


This is a common question, often about a continuous function mapping $(-1,1)$ onto $\mathbb{R}$. For that setup, I have long enjoyed the Inverse Hyperbolic Tangent, $\tanh^{-1}$, as a function that does exactly the trick. However, the interval you begin with here is instead $(0,1)$, so to use this function would require first mapping $(0,1) \rightarrow (-1,1)$, which can be done via $x \mapsto 2x-1$.

And so that gives yet another answer: $x \mapsto \tanh^{-1}(2x-1)$ maps $(0,1)$ onto $\mathbb{R}$.



$${(2x - 1)}\over{x(x - 1)}$$

Or, look at tan and scale it a bit.

How to do it without a graphing calculator? Learn the shapes of various simple functions e.g. $x^2$, $x^3$ and $1/x$. Look up even and odd functions that others have mentioned. Learn what happens when you add and mutiply functions. Learn how to scale and shift the functions.

I didn't use a graphing calculator and I guess that the other responders didn't either.

  • $\begingroup$ The OP knows this is an answer; they ask how one arrives at this answer. $\endgroup$ – Patrick Stevens Mar 25 '17 at 22:49
  • $\begingroup$ At the time that I posted it, he didn't. $\endgroup$ – badjohn Mar 25 '17 at 23:05
  • $\begingroup$ I added some suggestions on how to get the answer. $\endgroup$ – badjohn Mar 25 '17 at 23:14

Keeping in mind that (cumulative) distribution functions in statistics take the real line to the unit interval, inverse cdfs for variables defined over the whole real line are a rich and convenient source of these.

An example of this would be the $\log(\frac{x}{1-x})$, which is the inverse cdf for the standard logistic distribution (this particular one is sometimes called the logit function).

If you scroll to the bottom of the page at that link, you'll see a couple of dozen possibilities in the table at the bottom, mostly under "Continuous univariate supported on the whole real line". Some of those will not have convenient inverse cdfs, but a number of them do.

Once you have a few of them you can combine them with functions from the real line to the real line or the unit interval to the unit interval to get a very wide range of easily-obtained functions.


Try $f(x) = {1 \over x} - {1 \over 1-x}$.

(Note that $f(x) = {2x -1\over x (x-1)}$.)

Here is the idea behind this approach:

In general, if $\phi:(0,1) \to \mathbb{R}$ satisfies $\lim_{x \downarrow 0} \phi(x) = \infty$ and $\phi$ is bounded on $[a,1)$ for any $a>0$ you can construct a suitable function by $f(x) = \phi(x)-\phi(1-x)$.

  • $\begingroup$ I would prefer to write this as $\frac1x+\frac1{x-1}$, the sum of two terms with negative derivatives on their respective domains (I'm not sure I should call them "everywhere decreasing functions"), and with poles at $0$ and $1$, so clearly giving a sum decreasing on $(0,1)$ with range $\Bbb R$. +1 $\endgroup$ – Marc van Leeuwen Mar 26 '17 at 8:40
  • $\begingroup$ @MarcvanLeeuwen: I thought about that, but decided on the above form since it has some 'symmetry' about $x={1 \over 2}$. I should have elaborated why... $\endgroup$ – copper.hat Mar 26 '17 at 8:54
  • $\begingroup$ The question is "How do I do this?" not "Can you give me an example?" $\endgroup$ – David Richerby Mar 26 '17 at 12:26
  • $\begingroup$ @DavidRicherby: My first comment explains how this is a very natural thing to do, and gives you guarantee of the desired result without much computation (moreover it is certain to be bijective $(0,1)\to\Bbb R$, which the approach in the (currently accepted) answer by Micah does not ensure). $\endgroup$ – Marc van Leeuwen Mar 26 '17 at 16:47
  • $\begingroup$ @MarcvanLeeuwen The answer is supposed to answer the question, not the comments below it. $\endgroup$ – David Richerby Mar 26 '17 at 16:56

Here's another example. Take the continuous function $f:(0,1)\to\mathbb R$ defined by $$f(x)=\frac{1}{x}\cos\frac{\pi}x.$$ For $n\in\mathbb N$ we have $f(\frac1{2n})=2n$ and $f(\frac1{2n+1})=-2n-1$, so $[-2n-1,2n]$ lies in the image of $f$ for each $n\in\mathbb N$. Therefore, the image of $f$ is $\mathbb R$.

This example has the further property that $\lim_{x\to1}f(x)=-1\in\mathbb R$ exists. (So $f$ can be extended to yield a surjection from $(0,1]$ onto $\mathbb R$.)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.