Function defined everywhere but continuous nowhere I have been recently reading about the Weierstrass function, a function that is continuous everywhere but differentiable nowhere. It made me think of a similar puzzle involving functions: find $f: \mathbb R \to \mathbb R$ such that $f$ can be computed anywhere, is well defined, but is continuous nowhere.
I first thought of maybe mapping the reals on to a fractal and doing something with that point but that’s just a fuzzy idea and I doubt one could compute it everywhere. In my research I could find no such function that is defined for all real numbers, both rational and irrational. If anyone has a proof this is impossible (or even just an idea of how you might prove that), or an example of a function that has those properties, that would be great.
 A: There is a very simple example, the characteristic function of $\mathbb{Q}$, defined as follows :
$$f : x \mapsto \left\{  \begin{matrix} 1 & \textrm{if } x \in \mathbb{Q} \\0 & \textrm{otherwise} \end{matrix} \right.$$
A: First off, the "majority" of functions (where majority is defined properly) have this property, but are insanely hard to describe. An easy example, though, of a function $f:\mathbb R\to\mathbb R$ with the aforementioned property is  $$f(x)=\begin{cases}x&x\in\mathbb Q\\x+1&x\notin\mathbb Q\end{cases}$$This example has the added benefit of being a bijection!
A: You can get a whole bunch of functions like this (and some with even worse properties!) by inspecting the decimal representation of a number. To make sure these functions are well defined, we'll consider the decimal expansion of a terminating decimal to always end with $00...$ rather than the other possibility of ending in $99...$. The condition of continuity at non-terminating decimals $x$ means precisely that, for any bound $\varepsilon$, there is some $N$ such that every number $x'$ with the same first $N$ digits as $x$ has $f(x)-f(x') < \varepsilon$ (and, indeed, if $f(x)$ was also non-terminating, we can replace the $\varepsilon$ by a similar condition of agreement of digits). The case where $x$ is a terminating decimal is slightly different and annoying, so I won't talk about it.
As a starter, we can define a function $f(x)$ that writes $x$ in decimal, then counts how many $9$'s it has. If the count is finite, $f(x)$ is the count. If the count is infinite, $f(x)=-1$. This is discontinuous everywhere because knowing that $x$ and $x'$ share $N$ digits for any $N$ can, at best, tell you that they share some finite number of $9$'s - but the function takes into account every $9$ and we have no control after some point in the decimal expansion.
We can make the previous example somewhat worse by choosing a bijection $k:\{-1,0,1,2,\ldots\}\rightarrow \mathbb Q$ and then considering $k\circ f$ which now, one can check, has the property that the image of any open set is dense in $\mathbb R$. That's not very continuous at all!
Another fun example, along a similar line, would be to define $f(x)$ to be the number of places after the decimal point that the last $9$ in the representation of $x$ appears - or $-1$ if there are infinitely many $9$'s. You could even do worse and let $f(x)$ be the $-1$ if there are infinitely many $9$'s. If there is a last $9$, erase all the digits prior to it, leaving an infinite sequence of digits in $\{0,1,\ldots,8\}$. Write $0.$ before this sequence and interpret it in base $9$. Now, the image of every open set is $[0,1]$. That's pretty nasty. If you choose a bijection between $[0,1]$ and $\mathbb R$, now the image of every open set is $\mathbb R$.
There's also some examples that people actually do care about. For instance, there's a thing called irrationality measure which basically asks "How hard is this number to approximate by rationals?" The irrationality measure of $x$ is defined as the infimum of the $\mu$ such that 
$0 < \left|x - \frac{p}q \right| < \frac{1}{q^{\mu}}$
for infinitely many coprime pairs of integers $(p,q)$. This might be infinite, but you can always fix it up by mapping $\infty$ to some real number. This is $1$ at every rational, $2$ at algebraic irrationals, and can be anything at least $2$ elsewhere. This is actually useful as a tool for showing that things like that are like Liouville numbers (but not quite as extreme) are irrational - but the image of every open set is $\{1\}\cup [2,\infty]$, so a pretty nasty function.
Also: bonus, if you take any continuous function and add it to any discontinuous everywhere function, you get a discontinuous everywhere function - and if you take a discontinuous everywhere function and multiply it by a non-zero constant, it is still discontinuous everywhere. It turns out that, in the grand scheme of things, if you choose a function at random, the probability that it is continuous is $0$ - it's like randomly choosing a point on a plane and hoping that it lies on a line, except that instead of a "plane" you have an infinite dimensional space which is way bigger than the line.
A: Consider the function $f:\mathbb{R} \rightarrow \mathbb{R}$ defined by 
$$ f(x) = \begin{cases} 1, ~~ x \in \mathbb{Q} \\ 0, ~~ x \not\in \mathbb{Q} \end{cases}$$
Now let $x \in \mathbb{R}$. Then there exists a sequence $(x_n)_{n \in \mathbb{N}}$ with $x_n \rightarrow x$ which is entirely contained in $\mathbb{Q}$ and a sequence $(y_n)_{n \in \mathbb{N}}$ with $y_n \rightarrow x$ which is entirely contained in $\mathbb{R} \setminus \mathbb{Q}$. Then both sequences converge to $x$, however the images of the elements in the sequence converge to $1$ and $0$, respectively.
A: G. Chiusole's & Olivier's example is the standard one.
In fact, there are functions $\Bbb R \to \Bbb R$ that are not only discontinuous at every point but spectacularly so: More precisely, there are functions $f : \Bbb R \to \Bbb R$ for which $f(I) = \Bbb R$ for every (nonempty) open interval $I$ no matter how small; thus in a sense they are as far from being continuous as possible. (Functions with this property are called strongly Darboux functions.) The classic example is the Conway base $13$ function:

The Conway base $13$ function is a function $f : \Bbb R \to \Bbb R$ defined as follows. Write the argument $x$ value as a tridecimal (a "decimal" in base $13$) using $13$ symbols as 'digits': $0, 1, \ldots, 9, \textrm{A}, \textrm{B}, \textrm{C}$; there should be no trailing $\textrm{C}$ recurring. There may be a leading sign, and somewhere there will be a tridecimal point to separate the integer part from the fractional part; these should both be ignored in the sequel. These 'digits' can be thought of as having the values $0$ to $12$, respectively; Conway originally used the digits "$+$", "$-$" and "$.$" instead of $\textrm{A}, \textrm{B}, \textrm{C}$, and underlined all of the base $13$ 'digits' to clearly distinguish them from the usual base $10$ digits and symbols.

*

*If from some point onward, the tridecimal expansion of $x$ is of the form $\textrm{A} x_1 x_2 \cdots x_n \textrm{C} y_1 y_2 \cdots$, where all the digits $x_i$ and $y_j$ are in $\{0, \ldots, 9\}$, then $$f(x) = x_1 \cdots x_n . y_1 y_2 \cdots$$ in usual base $10$ notation.

*Similarly, if the tridecimal expansion of $x$ ends with $\textrm{B} x_1 x_2 \cdots x_n \textrm{C} y_1 y_2 \cdots$, then $$f(x) = -x_1 \cdots x_n . y_1 y_2 \cdots$$

*Otherwise, $f(x) = 0$.


A: Consider the function $f:\mathbb{R} \rightarrow \mathbb{R}$ defined by 
$$f(x)=\begin{cases}x&x\in\mathbb Q\setminus\{0\}\\
-x&x\notin\mathbb Q \\
\sqrt{3}&x=0
\end{cases}$$
This function is not continuous for any $x\in\mathbb R$. Suppose $x_0 \neq 0,$ then by taking a sequence of rational numbers converging to $x_0$ and then a sequence of irrational numbers converging to $x_0$, you can see that $\lim_{x\to{x_0}}f(x)$ doesn't exist. As zero is a rational number, it is also a bijection.
