# Does there exist a function $f: \to$ such its graph is dense in $\times$?

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.

#### Solutions Collecting From Web of "Does there exist a function $f: \to$ such its graph is dense in $\times$?"

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.

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!

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$.

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.

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.