Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does there exist a function $f:[0,1]\to [0,1]$ such that the graph of $f$ is dense in $[0,1]\times[0,1]$?

Not necessarily continuous.

share|cite|improve this question
The image is a subset of [0,1]. Then you want it to be dense in [0,1]. – alpha.Debi May 2 '12 at 7:46
@alpha.Debi: Perhaps OP means the "graph" of $f$, so $$\{\big(x,f(x)\big):x\in[0,1]\}\subset [0,1]\times[0,1].$$ – anon May 2 '12 at 7:51
Yes, is in the graph, sorry. I have a mistake when I was typing. – Gastón Burrull May 2 '12 at 8:06
Would Hilbert curves be something of interest? – Jean-Luc Bouchot May 2 '12 at 8:49
@Jean-Luc: No, those are (images of) functions $[0,1]\to[0,1]\times[0,1]$. – anon May 2 '12 at 9:12

Yes. Let $Q=[0,1]\cap\Bbb Q$, the set of rational numbers in $[0,1]$; $Q$ is countable, so we can enumerate it as $Q=\{q_n:n\in\Bbb Z^+\}$. Let $P$ be the set of prime numbers, and let $A=\{\sqrt{p}:p\in P\}$; $A$ is a countably infinite set of real numbers with the property that $a-b$ is irrational whenever $a,b\in A$ with $a\ne b$.

For each $a\in A$ let $Q_a=\{x\in[0,1]:x-a\in\Bbb Q\}$; For $n\in\Bbb Z^+$ let $a_n=\sqrt{p_n}$, where $p_n$ is the $n$-th prime, and let $Q_n=\{x\in[0,1]:x-a_n\in\Bbb Q\}$; the sets $\{Q_n:n\in\Bbb Z^+\}$ are pairwise disjoint, and each is dense in $[0,1]$. Now let $$f:[0,1]\to[0,1]:x\mapsto\begin{cases} q_n,&\text{if }x\in Q_n\\\\ 0,&\text{if }x\in[0,1]\setminus\bigcup_{n\in\Bbb Z^+}Q_n\;; \end{cases}$$

the construction ensures that the graph of $f$ is dense in $[0,1]\times[0,1]$, since it is dense on a dense set of horizontal slices through the square.

share|cite|improve this answer

Graph of any discontinous linear function is dense in $\mathbb{R}^2$, let $f :\mathbb{R}\rightarrow\mathbb{ R}$ is a function such that$ f(x + y) = f(x) + f(y)\forall x,y\in\mathbb{R}$. If $f$ is cont, then of course it has to be linear. But here $f$ is NOT cont. Then show that the set $\{(x, f(x)) : x\in\mathbb{R}\}$ is dense in $\mathbb{R}^2.$ take $x_1\neq 0$, If $f$ is not of the form $f(x)=cx$, then there exist $x_2\neq 0$ such that $f(x_1)/ x_1\neq f(x_2) /x_2$ In other words if you write in the determinant form in which first and second row are $(x_1, f(x_1))$ , $(x_2, f(x_2))$ respectively, then the determinant will be non zero. So the vectors $v_1 =(x_1, f(x_1))$ and $v_2 =(x_2, f(x_2))$ are linearly indipendent and thus span the whole plane $\mathbb{R}^2$. From Now on I guess denseness of rationality will help!

share|cite|improve this answer
See also here. – Martin Sleziak May 2 '12 at 14:26

Conway's base-13 function takes on every real number in any closed interval $[a,b]$. So you just have to restrict its range to $[0,1]$ to get your function $f$.

share|cite|improve this answer
Some of the examples given as answers to this question or in a related MO thread have the same property; so they might be interesting for the OP too. – Martin Sleziak May 2 '12 at 14:28

If $x$ is a terminating decimal, $x=.d_1d_2\dots d_n$, let $f(x)=.d_n\dots d_2d_1$. Define $f$ any way you want to elsewhere. Can you show that the image is dense?

EDIT: As Robert points out in his comment, this doesn't quite work. Perhaps this works instead: if $x=.d_1d_2\dots d_{2n}$ is a terminating decimal with an even number of digits (not counting any terminating zeros), let $f(x)=.d_{n+1}d_{n+2}\dots d_{2n}d_1d_2\dots d_n$. Again, for other $x$, define $f(X)$ arbitrarily.

share|cite|improve this answer
Yes, I can. Is a nice function. But is dense in the image I'm not sure if graph is dense in [0,1]x[0,1], I have a mistake when I wrote question. I need a function such graph is dense in [0,1]x[0,1]. Sorry. – Gastón Burrull May 2 '12 at 8:06
@GerryMyerson: This almost works. The problem is that if trailing zeros are part of the terminating decimal, the function is not well-defined; if they are not, the first digit of $f(x)$ can't be $0$. – Robert Israel May 2 '12 at 8:56
It works if you take (for $n > 1$, and not counting trailing zeros) $f(x) = .d_{n-1}d_{n-2} \ldots d_2 d_1$. – Robert Israel May 2 '12 at 18:03

For a probabilistic example, let $\{U_n\}$ be an independent and identically distributed sequence of random variables with the uniform distribution on $[0,1]$. Enumerate the rationals as $\{q_n\}$, and set $f(q_n) = U_n$ and $f(x) = 0$ for irrational $x$. I claim $f$ has dense graph with probability 1.

Consider an open square $(a,b) \times (c,d) \subset [0,1]^2$, with $a,b,c,d$ rational (and half-open intervals at the boundary, like $(a,1]$, etc, also allowed). Choose infinitely many rationals $\{q_{n_k}\}$ lying in $(a,b)$. For each $k$, the probability that $U_{n_k} \in (c,d)$ is $d-c > 0$. By independence, the probability that at least one of $U_{n_1}, \dots, U_{n_m}$ is in $(c,d)$ is $1-(1-(d-c))^m$. As $m \to \infty$, this tends to 1, and so with probability 1, there exists some $k$ with $f(q_{n_k}) = U_{n_k} \in (c,d)$, i.e. the graph of $f$ contains a point of $(a,b) \times (c,d)$.

Since there are countably many rational squares, the event that the graph of $f$ contains a point in every rational square is a countable intersection of events of probability 1, hence itself has probability 1. But every open set in $[0,1]^2$ contains a rational square, so on this event, the graph of $f$ is dense.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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