TITLE: "Pythagorean theorem" for projection onto convex set
QUESTION [5 upvotes]: I'm going through the book on online convex optimization by Hazan, (http://ocobook.cs.princeton.edu/OCObook.pdf) and in the first chapter I saw this assertion (which Hazan calls the "pythagorean theorem"):
Let $K \subset \mathbb{R}^d$ be a convex set, $y \in \mathbb{R}^d$, and $x = \Pi_K(y)$. Then for any $z \in K$ we have:
$$
\|y - z \| \geq \|x - z\|.
$$
It is presented without proof - what is a proof for this? Also, how does it relate to the pythagorean theorem?

REPLY [4 votes]: Suppose $x$ is the closest point to $y$ in the closed convex set $K$.
If $x=y$ there is nothing to prove, so we can suppose $x\neq y$.
The we have that $\langle x-y, z -x \rangle \ge 0$ for all $z \in K$ (this is essentially the dual problem).
If $z \in K$, we can write $z-y = t(x-y)+ d$, where $d \bot (x-y)$. Then the above gives
$\langle x-y, t(x-y)+ d +y -x \rangle = (t-1)\|x-y\|^2\ge 0$ from which we
get $t \ge 1$.
Then $\|z-y\|^2 = \|d\|^2+ t^2 \|x-y\|^2 \ge \|x-y\|^2$ which is the desired result.
Addendum: To see the first condition, suppose $\|z-y\| \ge \|y-x\|$ for all $z \in K$.
We have $\|z-y\|^2 = \|z-x+x-y\|^2 = \|z-x\|^2 + \|x-y\|^2 + 2 \langle z-x,x-y \rangle $ (this is where Pythagoras appears) which gives
$\|z-x\|^2 + 2 \langle z-x,x-y \rangle \ge 0$ for all $z \in K$.
Since $w(t)=x+t(z-x) \in K$ for all $t \in [0,1]$, we have
$t^2 \|z-x\|^2 + 2 t \langle z-x,x-y \rangle \ge 0$, dividing across by $t$ and letting $t \downarrow 0$ yields the desired result.