I want to confirm my solution for the following problem from Ethan D. Bloch’s Proofs and Fundamentals.
Problem: Let $f,g: \mathbb{R} \rightarrow \mathbb{R}$ be real functions of a real variable given by
$$f(x) = \begin{cases} 1-2x, & \text{if} & 0 \leq x \\ |x|, & \text{if} & x < 0 \end{cases}, \quad \forall x \in \mathbb{R} \quad \text{and}$$
$$g(x) = \begin{cases} 3x, & \text{if} & 0 \leq x \\ x-1, & \text{if} & x < 0 \end{cases}, \quad \forall x \in \mathbb{R}.$$
Find $f \circ g$ and $g \circ f$.
Solution: We start with $f \circ g$. First, we observe that $0 \leq g(x)$, for all $x \in [0, \infty)$. So, $(f \circ g) (x) = 1-6x$, for all $x \in [0,\infty)$. Next, we observe that $g(x) < 0$ for all $x \in (-\infty,0)$. Hence, $(f \circ g)(x) = |x-1|$, for all $x \in (-\infty,0)$.
Then, we compute $g \circ f$. Following the same argument, we see that $0 \leq f(x)$, for all $x \in (-\infty,\frac{1}{2}]$. So, we have that $(g \circ f)(x) = 3-6x$, for all $x \in (-\infty,\frac{1}{2}]$. Next, we observe that $f(x) < 0$, for all $x \in (\frac{1}{2},\infty)$. Hence, we have that $(g \circ f)(x)=|x|-1$, for all $x \in (\frac{1}{2},\infty)$.
Therefore, we have that $f \circ g, g \circ f: \mathbb{R} \rightarrow \mathbb{R}$ are defined by
$$ (f \circ g)(x) = \begin{cases} 1-6x, & \text{if} & 0 \leq x \\ |x-1|, & \text{if} & x<0\end{cases}, \quad \forall x \in \mathbb{R} \quad \text{and} $$
$$ (g \circ f)(x) = \begin{cases} 3-6x, & \text{if} & x \leq \frac{1}{2} \\ |x|-1, & \text{if} & \frac{1}{2} < x \end{cases}, \quad \forall x \in \mathbb{R}. $$
My question:
Is this enough and correct?
Is there any online calculator (or the like) that compute this expressions?
Thank you for your attention!
After reading the feedback in the comments, I came with the following solution that a I believe to be the right one. So, we have that $f \circ g, g \circ f: \mathbb{R} \rightarrow \mathbb{R}$, defined by
$$ (f \circ g)(x)= \begin{cases} 1-6x, & \text{if} & 0 \leq x \\ |x-1|, & \text{if} & x < 0 \end{cases}, \quad \forall x \in \mathbb{R} \quad \text{and} $$
$$ (g \circ f)(x)= \begin{cases} 3|x|, & \text{if} & x < 0 \\ 3-6x, & \text{if} & 0 \leq x \leq \frac{1}{2} \\ -2x, & \text{if} & \frac{1}{2} < x \end{cases}, \quad \forall x \in \mathbb{R}. $$
The problem with the initial solution was that I didn’t observe that, for $x \in (-\infty, \frac{1}{2}]$, the function $f$ is different when $x<0$ and $0 \leq x$.