Projection onto the second-order cone (source code)

= Projection onto the second-order cone

For $x=(u,t)$ and $\rho=\|u\|_2$,
$$
\Pi_{\mathcal L_{p+1}}(u,t)=
\begin{cases}
(u,t),&\rho\leq t,\\
(0,0),&\rho\leq-t,\\
\displaystyle\frac12\left(1+\frac t\rho\right)(u,\rho),&\rho>|t|.
\end{cases}
$$