I am reading a scientific article in which matrices are handled (which I do not use often). We consider a matrix $X\in\mathbb R^{n\times p}$ and a vector $y\in\mathbb R^n$. The authors show that the optimal value $w^*$ of the following problem:
- $c := \min \frac 1{2\gamma} \big|\big|w\big|\big|^2_2+\frac 1 2 \big|\big|Y-Xw \big|\big|_2^2$ such that $w\in\mathbb R^p$
satisfies $\left(\frac{I_p} \gamma + X^TX \right)w^* = X^TY$.
I understand how they obtained this result but I am stuck at the next step which is: "substituting the expression of $w^*$ back into the optimization problem leads to: $c=\frac 1 2 Y^T Y - \frac 1 2 Y^T X \left(\frac {I_p}\gamma + X^TX \right)^{-1}X^TY$".
I do not understand how this result is obtained. After replacing $w^*$ by its expression in the problem I do not know how to handle the $\ell^2$ norms.
Could you tell me how to obtain this expression?