Change of variables to a desirable form Suppose we have smooth function $\varphi: \mathbb{R}^n \to \mathbb{R}$ and let $x_0 \in \mathbb{R}^n$ be a non-degenerate critical point. That is,
$$\begin{equation}
\varphi'(x_0) = \nabla \varphi(x_0) = 0, \quad \text{and} \quad \text{det }(\varphi''(x_0)) \neq 0
\end{equation}$$
where $\varphi ''(x)$ stands for the Hessian matrix of second partial derivatives. 
Suppose that $(r,n-r)$ is the signature of $\varphi '' (x_0)$ (this means that the number of postive and negative eigenvalues is $r$ and $n - r$ respectively).
I am currently trying to understand a proof for the Morse Lemma, in which it is taken for granted that I see the following statement as trivial:
Given the above assumptions, after a translation and a linear change of coordinates, we may assume that $x_0 = 0$ and that
$$\begin{equation}
\varphi(x) = \frac{1}{2}(x^2_1 + \cdots + x_r^2 - x^2_{r + 1} - \cdots - x_n^2) + \mathcal{O}(|x|^3) \quad x \to 0
\end{equation} $$
Why is this so? 
I understand that the translation $y(x) = x - x_0$ gives me the result that $y(x_0) = 0$.
Then I think I need to apply a linear transformation that somehow involves the Hessian $\varphi^''(x_0)$, but I need to diagonalize and rescale it, that is I need to transform to a basis of its eigenvectors that are scaled by the inverses of the eigenvalues, so that I get the $\pm \frac{1}{2}$ - coefficients.
Then I think I need to use Taylor's expansion? I can use the fact that the gradient at $x_0$ is zero. But then I would still need the value $\varphi(0)$ in the above equation$\ldots$ here I guess the text I am using might have a typo.
If I could get some feedback on whether the above rough reasoning goes into the right direction that would be a huge help! Many thanks!
 A: First get
$$
\phi(x) - \phi(0) = \sum x_if_i(x)
$$
where the functions $f_i$ are smooth in the coordinates and satisfy $f_i(0) = \partial_i\phi(0)$.
Since $\partial_i\phi(0) = 0$ you can expand each of the $f_i$ as
$$
f_i(x) = \sum x_ih_{ij}(x)\ .
$$
with $h_{ij}(0) = \partial_j f_i(0) = \partial_i\partial_j \phi(0)$ so that $h_{ij}(0)$ defines a nondegenerate matrix. Set $g_{ij} = h_{ij}+h_{ji}$ and apply a linear transformation to ensure $g_{11}(0)$ nonzero. Now change
$$
\tilde{x}_1 = \sqrt{\pm g_{11}(x)} \left(x_1 +\sum_{k>1}x_k \frac{g_{k1}(x)}{ g_{11}(x)}\right)\,
$$
depending on sign of $g_{11}(0)$.
Look at $\phi(x)-\frac{1}{2}\tilde{x}_1^2$ and see how to proceed further.
A: First change coordinates so that the $\frac{\partial^2 \phi ( x_0)}{\partial x^2}$ is the diagonal matrix with $r$ ones and $n-r$ minus ones. The details are rather tedious.
Since $\phi$ is smooth, $\frac{\partial^2 \phi ( x_0)}{\partial x^2}$ is symmetric, and hence can be written as $\frac{\partial^2 \phi ( x_0)}{\partial x^2} = U \Lambda U^T$, where $\Lambda$ is a diagonal matrix of real eigenvalues, and $U$ is an orthonormal matrix of corresponding eigenvectors. Choose a suitable permutation matrix $\Pi$ so that the (still diagonal) matrix $\Pi^T \Lambda \Pi$ has diagonal entries $\lambda_1,...,\lambda_n$, where $\lambda_1,...,\lambda_r$ are positive and the remainder negative. Let $\Sigma$ be the diagonal matrix with entries $\frac{1}{\sqrt{|\lambda_1|}},...,\frac{1}{\sqrt{|\lambda_n|}}$. It should be clear that $J = \Sigma \Pi^T \Lambda \Pi \Sigma$ is a diagonal matrix with the first $r$ entries of $+1$, and the remaining entries $-1$. We can now write $\frac{\partial^2 \phi ( x_0)}{\partial x^2} = U \Pi \Sigma^{-1} (\Sigma \Pi^T \Lambda \Pi \Sigma) \Sigma^{-1} \Pi^T U^T = U \Pi \Sigma^{-1} J \Sigma^{-1} \Pi^T U^T$. Now let $\tilde{\phi}(x) = \phi(U \Pi \Sigma x)$, and $\tilde{x_0} = \Sigma^{-1} \Pi^T U^T x_0$. More tedious manipulation yields 
$$\frac{\partial^2 \tilde{\phi} ( \tilde{x_0})}{\partial x^2} = \Sigma \Pi^T U^T \frac{\partial^2 \phi ( x_0)}{\partial x^2} U \Pi \Sigma = J$$
To reduce subsequent notational clutter, I am going to revert to the $\phi, x_0$ notation, and just assume that $\frac{\partial^2 \phi ( x_0)}{\partial x^2} = J$ (ie, I am dropping the tildes).
Now obtain the desired representation using a Taylor expansion. We have:
$$\phi(x) = \phi(x_0) + \frac{\partial \phi (x_0)}{\partial x} (x-x_0) + \int_0^1 (1-t) (x-x_0)^T \frac{\partial^2 \phi ( x_0+t(x-x_0))}{\partial x^2} (x-x_0) \; dt$$
Now use the fact that the gradient is $0$, and add and subtract the term $\frac{1}{2}(x-x_0)^T \frac{\partial^2 \phi (x_0)}{\partial x^2} (x-x_0)$ to get:
$$\phi(x) = \phi(x_0) + \frac{1}{2}(x-x_0)^T J (x-x_0) + \int_0^1 (1-t) (x-x_0)^T (\frac{\partial^2 \phi ( x_0+t(x-x_0))}{\partial x^2} - \frac{\partial^2 \phi (x_0)}{\partial x^2}) (x-x_0) \; dt$$
Since the second derivative is smooth, it is locally Lipschitz, so we can locally bound the difference of the Hessians by $M ||x-x_0||$ for some constant $M$. Then the rest of the integral can be bounded to get:
$$|\phi(x) - ( \phi(x_0) + \frac{1}{2}(x-x_0)^T J (x-x_0))| \leq \frac{1}{2} M || x-x_o||^3$$
Rewriting the above (and using the form of J above) gives:
$$\phi(x) - \phi(x_0) = [(x-x_0)]_1^2 + \cdots [(x-x_0)]_r^2 - [(x-x_0)]_{r+1}^2 -\cdots [(x-x_0)]_n^2 + \mathcal{O}(||x-x_0||^3)$$
which was the desired form. (And yes, the original was missing a term of $\phi(0)$.)
