How to construct a real valued function which is continuous only on a given $G_\delta$ subset of $\mathbb{R}$? I know that the set of continuity of a function $f:\mathbb{R} \to \mathbb{R}$ forms a $G_{\delta}$ subset of $\mathbb{R}$.
My question is, given any $G_{\delta}$ subset of $\mathbb{R}$ , how can I construct continuous map which is continuous only on that $G_\delta$ subset of $\mathbb{R}$ ?
For some specific $G_\delta$ subset of $\mathbb{R}$ , I can construct such function.
I want to know is there any general procedure to construct such functions? Thanks
 A: A $G_\delta$ subset is, by definition, a countable intersection of open sets $A = \bigcap_{n \in \Bbb{N}} U_n$. Define $V_n = \bigcap_{i=1}^n U_i$, and note that the family $\{V_n\}$ is open, nested, and intersects to $A$. Define, for each $n$,
$$f_n(x) = \begin{cases} 2^{-(n + 1)} & \text{if } x \in V_n \\ 2^{-(n - 1)} & \text{if } x \in \Bbb{Q} \setminus V_n \\ 2^{-n} & \text{otherwise.} \end{cases}$$
Note that $f_n$ is continuous at every point in $V_n$, as $V_n$ is open. At every other point $x$, $f_n$ is discontinuous. If $x \in \overline{V_n}$, then there are points accumulating around $x$ in $V_n$, at which $f_n$ takes the value $2^{-(n+1)}$, which is minimum distance of $2^{-n} - 2^{-(n+1)} = 2^{-(n+1)}$ from $f(x)$ (the actual distance depends on whether $x \in \Bbb{Q}$ or not).
Otherwise, if $x \notin \overline{V_n}$, then some interval around $x$ exists in the compliment of $V_n$, on which the function is locally equal to $2^{-n}i_\Bbb{Q} + 2^{-n}$, where $i_\Bbb{Q}$ is the indicator function on the rationals. Such a function is discontinuous everywhere, proving $f_n$ is discontinuous at $x$.
Now, define
$$f(x) = \sum_{n \in \Bbb{N}} f_n(x).$$
The sum converges for all $x$, simply by comparing to the geometric series $\sum_{n \in \Bbb{N}} 2^{-(n-1)}$. I claim that $f$ is continuous precisely on $A$.
First, let us compute the range of $f$. If $x \in A = \bigcap_{n \in \Bbb{N}} V_n$, then
$$f_n(x) = \sum_{n=0}^\infty f_n(x) = \sum_{n=0}^\infty 2^{-(n + 1)} = 1.$$
Otherwise, if $x \notin A$, then some minimal $m$ exists such that $x \notin V_m$. Since the $V_m$s are nested this means that $x \in V_n$ if and only if $n < m$.
If we assume $x \in \Bbb{Q}$, then
\begin{align*}
f(x) &= \sum_{m=0}^{n-1}f_m(x) + \sum_{m=n}^\infty f_m(x) \\
&= \sum_{m=0}^{n-1}2^{-(m+1)} + \sum_{m=n}^\infty 2^{-(m - 1)} \\
&= \sum_{m=0}^{n-1}2^{-(m+1)} + 4\sum_{m=n}^\infty 2^{-(m + 1)} \\
&= \sum_{m=0}^{\infty}2^{-(m+1)} + 3\sum_{m=n}^\infty 2^{-(m + 1)} \\
&= 1 + 3 \cdot 2^{-m}.
\end{align*}
Otherwise, if $x \notin \Bbb{Q}$, then similar calculation reveals
$$f(x) = 1 + 2^{-m}.$$
This shows that every point of the range of $f$ isolated, except $1$. This means that continuity of $f$ at $x$ can only happen in two ways: either the function is constant on some neighbourhood of $x$, or $f(x) = 1$ (though the latter is not sufficient to show continuity).
Now, if $x \notin A$ and $f$ were continuous at $A$, $f$ must therefore be constant on some interval containing $x$. Note that $1 + 2^{-i} \neq 1 + 3 \cdot 2^{-j}$ for any $i$ and $j$, and neither is equal to $1$, so this would imply that this entire interval lies in the complement of $A$, and also that every point in this interval is rational, or every point is irrational. This contradicts the density of the rationals and irrationals. So, $f$ is not locally constant, and hence $f$ fails to be continuous at any $x \notin A$.
So, let's suppose $x \in A$. We can prove continuity sequentially: start by assuming $x_n \to x$, and aim to conclude that $f(x_n) \to f(x) = 1$.
If $x_n$ is eventually inside $A$, then $f(x_n)$ is eventually constantly $1$, so we are done. Otherwise, we can find a subsequence that does not lie inside $A$. Replace $x_n$ by this subsequence, i.e. assume without loss of generality that $x_n \notin A$ for all $n$.
As $x_n \notin A$, we once again have some $m_n$ such that $x_n \in V_m$ for $m < m_n$ and $x_n \notin V_m$ for $m \ge m_n$. Note that this implies $f_m(x_n) \le 2^{-(m - 1)}$ for $m \ge m_n$. Hence,
\begin{align*}
f(x_n) &= \sum_{m=0}^{m_n} f_m(x) + \sum_{m=m_n}^\infty f_m(x) \\
&\le \sum_{m=0}^{m_n} 2^{-(m+1)} + \sum_{m=m_n}^\infty 2^{-(m - 1)} \\
&= \sum_{m=0}^\infty 2^{-(m+1)} + 3\sum_{m=m_n}^\infty 2^{-(m + 1)} \\
&= 1 + 3 \cdot 2^{-m_n} \to 1,
\end{align*}
as $n \to \infty$. Naturally, we have a lower bound of $1$ too, so squeeze theorem applies. This gives us continuity at $x \in A$, as required.
