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
 A: 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}$
A: It can be shown that $g$ has a symmetry in $c=-\frac 12$.
$\displaystyle g(c)=\int_0^1 \min\left((x-c)^2,(x-c-2)^2\right)\mathop{dx}\quad$ let substitute $u=1-x$
$\displaystyle\phantom{g(c)}=\int_1^0 \min\left((1-u-c)^2,(1-u-c-2)^2\right)(-\mathop{du})\\\displaystyle\phantom{g(c)}=\int_0^1 \min\left((u+c-1)^2,(u+c+1)^2\right)\mathop{du}=g(-c-1)$
So we need only to study $g$ on the interval $[-\frac 12,2]$.

$f_c(x)=\min((x-c)^2,(x-c)^2-4(x-c)+4)=(x-c)^2+4\min(0,1+c-x)$

Let's have $\begin{cases}\displaystyle g_0(c)=\int_0^1(x-c)^2\mathop{dx}=c^2-c+\frac 13\\\displaystyle g_1(c)=4\int_{c+1}^1 (1+c-x)\mathop{dx}=-2c^2\end{cases}$

For $c\in[0,2]\implies g(c)=g_0(c)$ 
with a minimum in $g(\frac 12)=\frac 1{12}$ and a maximum $g(2)=\frac 73$.
For $c\in[-\frac 12,0]\implies g(c)=g_0(c)+g_1(c)$ 
with a maximum $g(-\frac 12)=\frac 7{12}$ and a minimum $g(0)=\frac 13$.

So overall the extrema of $g$ for $c\in[-2,2]$ are 


*

*maximum $g(2)=\frac 73$

*minimum $g(-\frac 32)=g(\frac 12)=\frac 1{12}$

