<s>[INST] 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?
 [/INST] 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}}$.
</s>