Function defined everywhere but continuous nowhere

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!


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.


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