Continuity almost everywhere

A function $f:X\to Y$ is continuous almost everywhere if it is only discontinuous on a set of measure $0$. Informally, this means that if we choose a random point on the function, the probability that it is continuous is exactly $1$.

For example, any countable set, such as $\mathbb Q$, will be of measure $0$ in an uncountable one, such as $\mathbb R$.


There is an important distinction to make here: a function is continuous almost everywhere if it is continuous on a "large" subset. But it must be continuous on that subset. Your function $g$ is continuous at every irrational point, and hence we can say that it is continuous almost everywhere.

That is not the same as removing a countable set of values from the function, because in doing so, you can damage the continuity of the remaining points. In the case of $f$, you are left with a function that is nowhere continuous!

This only works if you remove a countable set, but make sure that the remaining points are still continuous.


To prove that $g$ is continuous on $\mathbb R \setminus \mathbb Q$, fix $x\in\mathbb R \setminus \mathbb Q$ and $\epsilon > 0$. Let $N = \lceil \frac1\epsilon \rceil$.
Let $a$ be such that $x\in [\frac a{M}, \frac{a+1}{M}] =: I$, chosing $M > N$ such that there is no $q = \frac nm\in\mathbb Q$ with $\gcd(m,n) = 1$ and $m < N$, therefore any $q\in I$ has the reduced form $\frac nm$ with $m \ge N$ so $g(q) \le \frac1N \le \epsilon$ thus if be chose $\delta > 0$ such that $B_\delta(x_0) \subset I$, we have found $\delta$ with $$|g(x) - g(x_0)| = g(x) \le \epsilon \qquad \forall x: |x-x_0| < \delta$$ qed.

Note that $x_0$ must be irrational for the existence of such an $I$ wich doesn't contain any fractions with "small" denominator.