Given two functions: $$ \begin{align} f(x) &= 1 - |x-1|\\ g(x) &= \begin{cases} x,\ \text {if $x\in \Bbb Q$}\\ 2-x,\ \text {if $x\in \Bbb R\setminus\Bbb Q$} \end{cases} \end{align} $$ Study continuity of the following compositions: $$ \begin{align*} (f\circ g)(x)\tag 1\\ (g\circ f)(x)\tag 2 \end{align*} $$
$\Box$ I've started with case $(1)$. Both $f(x)$ and $g(x)$ are well defined in $\Bbb R$. So we might consider their composition: $$ (f\circ g)(x) = \begin{cases} 1-|x-1|,\ \text{if $x\in\Bbb Q$}\\ 1-|2-x-1|,\ \text{if $x\in\Bbb R\setminus\Bbb Q$} \end{cases} $$ Or simply: $$ (f\circ g)(x) = 1-|x-1|,\ \forall x\in \Bbb R $$
By composition of continuous functions $1-|x-1|$ is continuous.
Conclusion: $(f\circ g)(x)$ is continuous in $\Bbb R$ $\blacksquare$.
$\Box$ Consider case $(2)$. Again both function are well defined in $\Bbb R$, so we migh consider their composition: $$ (g\circ f)(x) = \begin{cases} 1-|x-1|,\ \text{if $x\in\Bbb Q$}\\ 2 - (1-|x-1|),\ \text{if $x\in\Bbb R\setminus\Bbb Q$} \end{cases} $$
Or simplifying: $$ (g\circ f)(x) = \begin{cases} 1 - |x-1|,\ \text{if $x\in\Bbb Q$}\\ 1 + |x-1|),\ \text{if $x\in\Bbb R\setminus\Bbb Q$} \end{cases} $$
1) It feels natural to consider a point $x_0 = 1$ since it will render the absolute value to $0$, by which: $$ (g\circ f)(x_0) = 1 $$
Take any sequence $(x_n)_{n\in\Bbb N}$ of rational or irrational numbers such that: $$ \lim_{n\to\infty}x_n = 1 $$
For a sequence of rationals: $$ \lim_{n\to\infty}(g\circ f)(x_n) = \lim_{n\to\infty}(1-|x_n - 1|) = 1 = (g\circ f)(1) $$
The same is true for any sequence of irrational numbers.
2) Now consider some point $x_0 \ne 1$. Suppose $x_0$ is irrational. Take any sequence $(x_n)_{n\in\Bbb N}$ such that $\forall n\in\Bbb N: x_n \in \Bbb Q$ and: $$ \lim_{n\to\infty}x_n = x_0 $$
For any sequence $(x_n)_{n\in\Bbb N}$ and $\forall n\in\Bbb N: x_n \in\Bbb Q$: $$ \begin{align} \lim_{n\to\infty}(g\circ f)(x_n) &= \lim_{n\to\infty}(1 - |x_n - 1|) \\ &= 1 - |x_0 - 1| < 1 \end{align} $$
But since $x_0$ is irrational: $$ (g\circ f)(x_0) = 1 + |x_0 - 1| > 1 $$
Which means: $$ \lim_{n\to\infty} (g\circ f)(x_n) \ne (g\circ f)(x_0) $$
3) Suppose $x_0$ is rational and $x_0 \ne 1$, take any sequence $(x_n)_{n\in\Bbb N}$ and $\forall n\in \Bbb N: x_n \in\Bbb R\setminus \Bbb Q$: $$ \lim_{n\to\infty}x_n = x_0 $$ Since $x_0$ is rational we have: $$ (g\circ f)(x_0) = 1 - |x_0 - 1| < 1 $$ But: $$ \begin{align} \lim_{n\to\infty}(g\circ f)(x_n) &= \lim_{n\to\infty}(1 + |x_n - 1|) \\ &= 1 + |x_0 - 1| > 1 \end{align} $$ So: $$ \lim_{n\to\infty}(g\circ f)(x_n) \ne (g\circ f)(x_0) $$ And that completes the proof.
Conclusion: $(g\circ f)(x)$ in continuous at $x = 1$ and $(g\circ f)(x)$ is discontinuous $\forall x \in \Bbb R\setminus \{1\}$ $\blacksquare$.
I'm still a bit lost while studying such bizarre functions and not fully sure in the correctness of my reasoning behind the proof. I would like to ask for verification of the above.
Thank you!