Maximum value of $(x−1)^2+ (y−1)^2+ (z−1)^2$ with constraint $x^2+y^2+z^2 ≤2 , z≤1$ So the problem is that I have $D(f)=\{(x,y,z), x^2+y^2+z^2 ≤2 , z≤1\}$ and I have to determine the maximum value for the function $(x−1)^2+ (y−1)^2+ (z−1)^2$ in $D$.
I'm just confused as I don't actually know if $z\le1$  counts as a constraint as well, or is it just for me to sketch the area, which is actually a part of the question.
Furthermore, I know that I have to use Lagrange multiplier method, but I honestly don't know how because $\le$ is making the question hard for me. Do I just calculate as usual and count $\le$ the same as $=$?
appreciate all the feedback
Edit: I have calculated the grad f =0 which is = $D(f)=(2(x-1), 2(y-1), 2(z-1))$ where I've got that $x=y=z= 1$ and $f(1, 1, 1)=0$. (I don't know what to do with this though). Then I calculated $L(x, y, x, λ) = (x−1)^2+(y−1)^2+(z−1)^2 +λ(x^2+y^2+z^2-2)$, then the four cases where I got the same value which is $-2λ= 2(x-1)/x = 2(y-1)/y = 2(z-1)/z$. Which means that $x=y=z$, put it in the $D$ function $x^2+ x^2+ x^2$ and ended up with $x=y=z= −+√2/√3$. I took the minus sign for the maximum distance from $(1,1,1)$. which means that the answer is $x=y=z= −√2/√3$. Is it correct?
 A: Hint. Find first the maximum value for the function $(x−1)^2+(y−1)^2+(z−1)^2$, which is the square of the distance of the point $(x,y,z)$ from $P=(1,1,1)$, in the larger set
$$D_1=\{(x,y,z): x^2+y^2+z^2 ≤2\}$$
which is the closed ball centered at $(0,0,0)$ of radius $\sqrt{2}$. This should be easy to find by using a geometric approach with very few calculations: the maximum point is on the boundary of $D_1$ along the line which joins the center $(0,0,0)$ and the point $(1,1,1)$.

Does this maximum point satisfy the constrain $z\leq 1$? What may we conclude?
A: From the inequality: $(a+b)^2 \le 2(a^2+b^2) $, we have $$(-(x+y))^2 \le 2(x^2+y^2) \implies -(x+y) \le\sqrt{2(x^2+y^2)}$$
And by applying the constraint $x^2+y^2+z^2 ≤2$,
\begin{align}
(x−1)^2+ (y−1)^2 &=  (x^2+y^2) -2(x+y)+2 \\
& \le (x^2+y^2) +2 \sqrt{2(x^2+y^2)}+2\\
& \le (2-z^2) +2 \sqrt{2(2-z^2)}+2\\
\end{align}
So, we can deduce that $$(x−1)^2+ (y−1)^2 +(z-1)^2  \le 5-2z + 2 \sqrt{2(2-z^2)}$$ with $-\sqrt{2} \le z\le 1$
Let's study the function $g(z)= -z+\sqrt{2(2-z^2)}$ in the interval $z\in(-\sqrt{2},1)$. We have $g'(z)=-1 -\frac{2z}{\sqrt{4-2z^2}}$ and reaches its maximum at $\sqrt{4-2z^2} = -2z$ or $z =-\frac{\sqrt{2}}{\sqrt{3}}$. We verify that this value is in the interval $z = -\frac{\sqrt{2}}{\sqrt{3}} \in(-\sqrt{2},1)$.
Note: we can use Cauchy Schwart inequality to find the maximum value of $g(z)$. This approach is more direct but not orthodox.
Finally, $(x−1)^2+ (y−1)^2 +(z-1)^2$ reaches the maximum value when ($z =-\frac{\sqrt{2}}{\sqrt{3}} $ and $x = y$ and $x^2+y^2 +z^2 =2$), or $x=y=z = -\frac{\sqrt{2}}{\sqrt{3}}$.
A: Using Lagrange multipliers method.
Calling $p = (x,y,z),\ p_0=(1,1,1),\ p_1 = (0,0,1), f = \|p-p_0\|^2$ and using $e_1, e_2$ as slack variables to avoid the inequalities we have
$$
L = f + \lambda(\|p\|^2-2+e_1^2)+\mu(p\cdot p_1-1-e_2^2)
$$
The stationary points are the solutions for
$$
\nabla L = \cases{2(1+\lambda)p-2p_0-\mu p_1=0\\
\|p\|^2-2+e_1^2=0\\
p\cdot p_1-1-e_2^2=0\\
\lambda e_1=0\\
\mu e_2 = 0}
$$
obtaining
$$
\left[
\begin{array}{cccccc}
f & x & y & z & e_1^2 & e_2^2\\
0 & 1 & 1 & 1 & 1 & 0 \\
 3+2 \sqrt{2} & -\frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} & 1 & 0 & 0 \\
 3-2 \sqrt{2} & \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} & 1 & 0 & 0 \\
\end{array}
\right]
$$
NOTE
Null $e_k$'s represent actuating restrictions.
