# A function that is both continuous and discontinuous

I was asked to find a function that is continuous on Z but discontinuous on R\Z. as I'm new to continuity I want a feedback on the function I've created, and also tips on what to look for in these types of question!

$$f: \mathbb{R}\to \mathbb{R}$$ such that \begin{align} f(x) = \begin{cases} 1 & \text{if x\notin \mathbb{Z}} \\ \lfloor x \rfloor & \text{if x \in \mathbb{Z}} \end{cases} \end{align}

• That one is continuous for $1≤x<2$, for example. – lulu Dec 28 '20 at 17:31
• A tip for this type of question: to show continuity at a point $x\in\mathbb{R}$, you can apply the usual $\epsilon$-$\delta$ definition of continuity. Do you know it? – JWP_HTX Dec 28 '20 at 17:32
• To get started, I suggest looking at the function defined on rationals by $f\left(\frac pq\right)=\frac pq$ and by $f(x)=0$ if $x$ is irrational. Show that $f$ is continuous only at $x=0$. Use that to build your example. – lulu Dec 28 '20 at 17:33
• $\lfloor x \rfloor =x$ when $x \in \mathbb Z$ so you suggestion is continuous if $x=1$ or $x \in \mathbb R \backslash \mathbb Z$, but is discontinuous if $x \in \mathbb Z \backslash \{1\}$. Almost the opposite of what you are asking for – Henry Dec 28 '20 at 18:01

Actually, the function is discontinuous at every integer other than $$1$$.
You can take, for instance,$$f(x)=\begin{cases}\sin(\pi x)&\text{ if }x\in\Bbb Q\\0&\text{ otherwise.}\end{cases}$$Can you check that it works?
• I guess any non-zero value would work in place of $\sin(\pi x)$? – Al.G. Dec 28 '20 at 18:12
• If I put $1$ instead of $\sin(\pi x)$, then I get a function which is discontinuous everywhere. – José Carlos Santos Dec 28 '20 at 18:15
• Oh I get it, I misunderstood the question -- I was thinking about the restriction $f|_{\mathbb Z}$ being continuous (albeit on a discrete set...). – Al.G. Dec 28 '20 at 18:24