<s>[INST] Maximum and minimum values of function 
For any number $c$ we let $f_c(x)$ be the smaller of the two numbers
  $(x-c)^2$ and $(x-c-2)^2$. Then we define $g(c)=\int_0^1f_c(x)dx$.
  Find the maximum and minimum values of $g(c)$ if $-2\le c \le 2$.

So the maximum/minimum values are either $g(\pm2)$ (the endpoints) or $g(c)$ where $g'(c)=0$. 
$$g(2)=\int_0^1f_2(x)dx=\int_0^1\min((x-2)^2,(x-4)^2)dx\\=\int_0^1(x-2)^2dx=\frac{(1-2)^3}{3}-\frac{(0-2)^3}{3}=\frac{7}{3}$$
The last step I was thinking was because on the interval $[0,1]$, $|x-2|$ is always smaller than $|x-4|$.
In the same way, $$g(-2)=\int_0^1f_{-2}(x)dx=\int_0^1\min((x+2)^2,x^2)dx\\=\int_0^1x^2dx=\frac{1}{3}$$
So $7$ thirds and $1$ third for the endpoints. When the derivative is zero, I am having trouble. I am struggling to understand how the derivative and antiderivative of $g$ and $f_c$ would operate. Thanks.
Problem Source: James Stewart, Calculus, Integrals Chapter
 [/INST] Hint $f_c(x)$ depends only on $x-c$, in fact $f_c(x) = f_0(x-c)$, hence
$$g(c)= \int_0^1 f_0(x - c) d x = \int_{-c}^{1-c}f_0(t) d t$$ 
Edit: As ${f}_{0}$ is continuous, it follows that $g$ has the
derivative
$${g'} \left(c\right) =-{f}_{0} \left(1-c\right)+{f}_{0} \left({-c}\right) = \min  \left({d}^{2} \left(c , {-2}\right) , {d}^{2} \left(c , 0\right)\right)-\min  \left({d}^{2} \left(c , {-1}\right) , {d}^{2} \left(c , 1\right)\right)$$
where $d \left(a , b\right) = \left|a-b\right|$ is the usual distance in $\mathbb{R}$.
It follows easily that
$$\renewcommand{\arraystretch}{1.5}  {g'} \left(c\right) = \left\{\begin{array}{l}{d}^{2} \left(c , {-2}\right)-{d}^{2} \left(c , {-1}\right) \quad  \text{ if } c \in  \left[{-2} , {-1}\right]\\
{d}^{2} \left(c , 0\right)-{d}^{2} \left(c , {-1}\right) \quad  \text{ if } c \in  \left[{-1} , 0\right]\\
{d}^{2} \left(c , 0\right)-{d}^{2} \left(c , 1\right) \quad  \text{ if } c \in  \left[0 , 1\right]
\end{array}\right.$$
Now we use that given $a , b \in  \mathbb{R}$, the antiderivative of
${\varphi} \left(x\right) = {d}^{2} \left(x , a\right)-{d}^{2} \left(x , b\right) = 2 \left(b-a\right) \left(x-\frac{a+b}{2}\right)$
is ${\phi} \left(x\right) = \left(b-a\right) {d}^{2} \left(x , \frac{a+b}{2}\right)+K$ where $K$ is a constant.
Note that $K = {\phi} \left(\frac{a+b}{2}\right)$ and that
${\phi} \left(a\right) = {\phi} \left(b\right) = \frac{{\left(b-a\right)}^{3}}{4}+{\phi} \left(\frac{a+b}{2}\right)$. Also note that
${\phi}$ has a unique extremum at $\frac{a+b}{2}$. It follows that
$$\renewcommand{\arraystretch}{2}  g \left(c\right) = \left\{\begin{array}{l}g \left({-\frac{3}{2}}\right)+{d}^{2} \left(x , {-\frac{3}{2}}\right) \quad  \text{ if } c \in  \left[{-2} , {-1}\right]\\
g \left({-\frac{1}{2}}\right)-{d}^{2} \left(x , {-\frac{1}{2}}\right) \quad  \text{ if } c \in  \left[{-1} , 0\right]\\
g \left(\frac{1}{2}\right)+{d}^{2} \left(x , \frac{1}{2}\right) \quad  \text{ if } c \in  \left[0 , 1\right]
\end{array}\right.$$
Hence $g$ has a local minimum at $x =-\frac{3}{2}$ and $g \left({-\frac{3}{2}}\right) = g \left({-2}\right)-\frac{1}{4} = \frac{1}{12}$, a local maximum at $x =-\frac{1}{2}$ and $g \left({-\frac{1}{2}}\right) = g \left({-1}\right)+\frac{1}{4} = \frac{7}{12}$, and a local minimum at $x = \frac{1}{2}$ and $g \left(\frac{1}{2}\right) = g \left(0\right)-\frac{1}{4} = \frac{1}{12}$
Thus, the maximum of $g$ is $g \left(2\right) = \frac{7}{3}$, the minimum is
$g \left(\frac{1}{2}\right) = g \left({-\frac{3}{2}}\right) = \frac{1}{12}$
</s>