I've attempted a problem in Spivak's Calculus on Manifolds and I can't find a solution online. This is question 2-27, which is as follows
Define $g,h:\{x\in\mathbb{R}^2:|x|\le1\}\rightarrow\mathbb{R}^3$ by $$\begin{split} g(x,y)&=(x,y,\sqrt{1-x^2-y^2})\\ h(x,y)&=(x,y,-\sqrt{1-x^2-y^2}) \end{split}$$ Show that the maximum of $f$ on $\{x\in\mathbb{R}^3:|x|=1\}$ is either the maximum of $f\circ g$ or the maximum of $f\circ h$ on $\{x\in\mathbb{R}^2:|x|\le1\}$.
My solution is as follws
Assume that the maximum of $f$ occurs at some point $g(a)\in\mathbb{R}^3$ where $a\in\{x\in\mathbb{R}^2:|x|<1\}$, and that $D_i\left(f\circ g\right)(a)$ exists. Then by the chain rule $$D_i(f\circ g)(a)=D_if(g(a))\cdot D_ig(a)$$ since the maximum of $f$ appears at $g(a)$, by theorem 2-6 $D_if(g(a))=0$, and so $D_i(f\circ g)(a)=0$. This shows that the maximum of $f$ occurs at the maximum of $f\circ g$.
I have some issues with my solution, mainly that since the theorem only works in the interior so for points $|x|=1$ where $x\in\mathbb{R}^2$ the conclusion I've drawn doesn't hold on the boundary. However, since it would seem that $f=g$ on the boundary it might not count?
Also I'm not sure whether I've essentially done "$D_if(b)=0$ so the maximum is at $b$", but I've tried to word it as similarly as the theorem to check that I haven't.