Counter example restriction of a function

Let $f: D \rightarrow \mathbb{R}$ be a function and $\left.f\right|_{G}: G \rightarrow \mathbb{R}$ the restriction of that function, with $G$ being open relative to $D$. I know that $f$ continuous on $G$ $\Leftrightarrow$ $\left.f\right|_{G}$ continuous. Can someone show me an counter example, that doesn't satisfy that equivalence with G not being relative open?


Solution 1:

I would think this is the archetypal example: Take $D = \Bbb R$, $G = \Bbb Q$ and $$ f(x) = \cases{1 & if $x\in G$\\0 & otherwise} $$ Then $f$ as a function on $D$ is not continuous anywhere, and thus not continuous on $G$, but $f|_G$ is the constant function $1$, which is clearly continuous.

Solution 2:

I don't know if the example is appropriate or not but, $f:(-1,1)\to \mathbb R$ by $$f(x)=\begin{cases} 1\ \text{ for }x\in(-\frac{1}{2},\frac{1}{2})\\ 2\text{ elsewhere}\end{cases}$$ for all $x\in(0,1)$. Then $f|_{(-1/2,1/2)}$ is continuous as it is a constant map but $f$ is not continuous.

Solution 3:

The following is a counterexample:

$$D=[0,1], G=\left\{\frac12\right\}$$

$$f(x)=\begin{cases} 0, & \text{if } x < \frac12\\ 1, & \text{otherwise.} \end{cases}$$

That $f$, when considered as $f: D \to \mathbb R$, is certainly not continuous at $x=\frac12$. However, when restricted to $G=\left\{\frac12\right\}$, $f_{|G}$ is continuous (constant).

To see this consider any sequence $(x_1, x_2, \ldots)$ in $G$ that tends to a point in $G$. There isn't much choice, the sequence has to be $(\frac12, \frac12, \ldots)$, tending to $\frac12$. So certainly the sequence $(f(x_1), f(x_2), \ldots)$ will tend to $f(\frac12)$.

The "overarching" reason why this counterexample works is that you can exclude the "bad" points less than $\frac12$ from $G$, even the ones very near $\frac12$. That isn't possible with open sets $G$.