Popcorn function I need to construct a function whose set of points of discontinuities is a given
F-sigma set.
At the Follow-Up section of Wikipedia's article on the popcorn function, they give an example of such a function.
I just don't see why would we need closedness of the sets in the proof.
Could somebody briefly explain the proof?
Thanks
 A: It’s convenient to assume that the closed sets $F_n$ are increasing, so that $F_1 \subseteq F_2 \subseteq F_3 \subseteq \dots$. This is a harmless assumption, since the union of any finite number of closed sets is closed: just replace $F_n$ by $\bigcup_{i=1}^n F_i$. Now we have $A = \bigcup_{n=1}^\infty F_n$, and we define the function $$f_A(x) = \begin{cases}
\frac1n,&\text{ if }x\text{ is rational and }n\text{ is minimal so that }x\in F_n\\
\frac{-1}{n}&\text{ if }x\text{ is irrational and }n\text{ is minimal so that }x\in F_n\\
0,&\text{ if }x \notin A.
\end{cases}$$
First we show that $f_A$ is continuous at each point of $\mathbb{R}\setminus A$. Suppose that $x \in \mathbb{R}\setminus A$; clearly $f_A(x)=0$. If $x$ has a nbhd $V$ disjoint from $A$, then $f_A(y)=0$ for every $y \in V$, so $f_A$ is certainly continuous at $x$. Assume now that $x$ has no such nbhd, so that every nbhd of $x$ meets $A$. 
For $n \in \mathbb{Z}^+$ let $V_n = \mathbb{R}\setminus F_n$; each $V_n$ is a nbhd of $x$. Suppose that $y \in V_m$ for some $m$. If $y \notin A$, then $f_A(y) = 0$. Otherwise, $f_A(y) = \pm 1/n$, where $n$ is minimal with $y \in F_n$. Since $y \in V_m$, $y \notin F_m$; and since the $F_i$ are nested, $y \notin F_i$ for any $i \le m$. Thus, $n>m$. This shows that $$\vert f_A(y)\vert < \frac1m$$ for every $y \in V_m$. In other words, given any $\epsilon > 0$, we can choose a positive integer $m$ such that $1/m < \epsilon$, and $V_m$ will be a nbhd of $x$ such that $\vert f_A(y)-f_A(x)\vert < \epsilon$ for every $y \in V_m$. This of course means that $f_A$ is continuous at $x$.
It remains to show that $f_A$ is discontinuous at each point of $A$. Fix $x\in A$, and assume that $x$ is rational. (The argument for irrational $x$ is almost identical.) Then $f_A(x) = 1/n$ for some $n \in \mathbb{Z}^+$, and we have to consider two possibilities. First, it may happen that $x$ has a nbhd $V\subseteq F_n$. If $n>1$, we may further assume that $V \subseteq V_{n-1}$, since $x$ is not in the closed set $F_{n-1}$. (Here I’m using the fact that $F_{n-1}$ is closed.) Let $W$ be any nbhd of $x$; then $W\cap V$ is a nbhd of $x$, so it contains some irrational $y$. But $W \cap V \subseteq F_n$, so $y\in F_n$; moreover, $y\in V_{n-1}$ if $n>1$, so $f_A(y) = -1/n$. Thus, each nbhd of $x$ contains a point $y$ such that $$\vert f_A(y)-f_A(x)\vert = \left\vert\frac1n-\frac{-1}n\right\vert=\frac2n,$$ and $f_A$ must be discontinuous at $x$.
The other possibility is that no nbhd of $x$ is contained in $F_n$. Then if $V$ is a nbhd of $x$, $V\cap V_n \ne \varnothing$. Let $y \in V\cap V_n$ be irrational. (Here again I’m using the fact that $F_n$ is closed: I need to know that $V\cap V_n$ is open in order to be sure that it contains an irrational.) If $y\in A$, $f_A(y)<0$, and if $y\in \mathbb{R}\setminus A$, $f_A(y)=0$, so in any case $f_A(y)\le 0$. But then $$\vert f_A(y)-f_A(x)\vert = f_A(x)-f_A(y) \ge f_A(x) = \frac1n,$$ so again $f_A$ must be discontinuous at $x$.
A: For the record, $A=\bigcup_{n=1}^\infty F_n\subseteq\mathbb{R}$ where each $F_n$ is closed and
$$f_A(x)=
\begin{cases}
1/n, & \text{if } x \text{ is rational and } n \text{ is minimal so that }x\in F_n \\
-1/n, & \text{if } x \text{ is irrational and } n \text{ is minimal so that }x\in F_n \\
0, & \text{if } x\notin A.
\end{cases} $$
The closedness of $F_n$'s is needed for $f_A$ to be continuous in $\mathbb{R}\setminus A$. Let's look more closely at this.
Continuity at each point of $\mathbb{R}\setminus A$: Pick $x\in\mathbb{R}\setminus A$. Then $f(x)=0$. Let $\epsilon>0$ and pick $n\in\{1,2,\ldots\}$ so that $1/n<\epsilon$. Because each of the sets $F_1,\ldots,F_n$ are closed, we can choose $\delta>0$ so that $(x-\delta,x+\delta)$ does not intersect any of the sets $F_1,\ldots,F_n$. But then
$$|f(y)-f(x)|=|f(y)|<1/n<\epsilon\quad\text{for all } y\in(x-\delta,x+\delta).$$
Hence $f_A$ is continuous at $x$.
For completeness:
Discontinuity at each point of $A$: Pick $x\in A$. For simplicity assume that $x$ is rational (the other case is very similar). Then $f(x)=1/n$ for some $n\in\{1,2,\ldots\}$. Let $\delta>0$. Now there is an irrational number $y$ in $(x-\delta,x+\delta)$. If $y\in\mathbb{R}\setminus A$, then $f(y)=0$; if $y\in A$, then $f(y)<0$. In any case $f(y)\leq 0$, hence $|f(y)-f(x)|\geq 1/n$. This means $f_A$ is discontinuous at $x$.
