Domains of continuity

I was playing around with the definition of uniform continuity, and realized that a nice application of it is the possibility to extend functions.

For example, suppose we are given a uniformly continuous function $f:\mathbb{Q}\to\mathbb{R}$.

By uniform continuity, it is easy to see that such a function extends (uniquely of course) to a continuous function $f:\mathbb{R}\to\mathbb{R}$.

If we drop the uniform continuity assumption and demand only that $f$ to be continuous, this is no longer true, as easily demonstrated by $f(x) = \frac{1}{x-\pi}$ which is continuous on $\mathbb{Q}$ but cannot be extended to a continuous function on all of $\mathbb{R}$.

Which brings me to my question: Is there a nice description of the sets $A\subseteq \mathbb{R}$ which have the following property: there is a function $f:A\to \mathbb{R}$ which is continuous, but for any $x \notin A$, $f$ cannot be extended to a continuous function on $A\cup \{x\}$ ?

Certainly open sets have this property, because if $A$ is open and $B$ is its complement, then we may define $f:A\to \mathbb{R}$ by $f(x) = \frac{1}{dist(x,B)}$.

Conversely, are all such sets open?

Edit: per Robert Israel nice examples, it appear that not all such sets are open. I still wonder if there is a nice description of this sets?

-
Not all open sets, just the dense ones. If $x \notin \overline{A}$ you can extend $f$ to a continuous function on $A \cup \{x\}$ by choosing $f(x)$ arbitrarily. – Robert Israel Jan 16 '12 at 22:16
Right, my bad... – the L Jan 16 '12 at 22:22
I'd be interested to know whether the rationals, or the irrationals, have this property. – Nate Eldredge Jan 17 '12 at 1:19
The irrationals do have the property. Let $r_j, j \in \mathbb N$ be an enumeration of the rationals, and define $f$ on the irrationals by $f(x) = \sum_{j=1}^\infty 2^{-j} \sin(1/(x - r_j))$. This has the desired property. – Robert Israel Jan 17 '12 at 8:42
The rationals, on the other hand, do not have the property. Suppose $f$ is a continuous function on the rationals, and let $r_j$ be an enumeration of the rationals. It's easy to construct a sequence of closed intervals $I_j$ such that $r_j \notin I_j$, $I_{j+1} \subset \text{Int}(I_j)$, $\text{length}(I_j) < 1/j$ and $|f(x) - f(y)|< 1/j$ for all rationals $x,y \in I_j$. The intersection of the $I_j$ consists of an irrational number to which $f$ can be extended continuously. – Robert Israel Jan 17 '12 at 22:59

The sets with the property are exactly the dense $G_\delta$'s.

1) Suppose $A \subset \mathbb R$, and $f$ a function defined on $A$. Let $G$ be the set of points $x$ such that either $x$ is not a limit point of $A$ or $\lim_{t \to x} f(t)$ exists. Then $G = \bigcap_{n \in {\mathbb N}} U_n$ where $$U_n = \{x \in {\mathbb R}: \text{ there is }\delta > 0 \text{ such that for all } y,z \in A \cap (x-\delta, x+\delta),\ |f(x) - f(y)| < 1/n\}$$ Note that $U_n$ is open, so $G$ is a $G_\delta$ set. If $A$ has the property, we must have $A = G$, because $f$ can be extended continuously to any member of $G$ not in $A$; in particular, $A$ must be a $G_\delta$. As previously noted, $A$ must be dense.

2) If $A$ is a dense $G_\delta$, write $A^c = \bigcup_{n} E_n$ where $E_n$ is closed and nowhere dense. Define $$f(x) = \sum_{n} 3^{-n} \sin(1/\text{dist}(x,E_n))$$. Since each summand is continuous on $A$ and the series converges uniformly there, $f$ is continuous on $A$. On the other hand, if $x \notin A$, say $x \in E_n \backslash \bigcup_{m < n} E_m$, there are points $y,z \in A$ arbitrarily close to $x$ with $|f(y) - f(z)| > 3^{-n-1}$.

-
This generalizes easily to ${\mathbb R}^n$. How far can it be pushed? What about complete metric spaces? – Robert Israel Jan 20 '12 at 2:38

No, they are not all open. For example, if $A^c = \{b_i: i \in {\mathbb N}\}$ is a discrete set (i.e. all points isolated), then $A$ has this property: let $g(x) = \sin(\pi/x)$ for $0 <|x|<1$, $0$ for $|x|>1$, and take $f(x) = \sum_{i=1}^\infty 2^{-i} g((x - b_i)/r_i)$ where $r_i$ are chosen so that the intervals $[b_i - r_i, b_i + r_i]$ are disjoint. But $A$ will not be open if the sequence $b_i$ has a limit point.

-
Thanks. So my question remains - is there a nice description of this sets? – the L Jan 16 '12 at 22:37