[proofplan]
Existence of the canonical form follows from the Diagonalisation theorem plus rescaling by square roots of absolute values.
Uniqueness of the signature $(p, q)$ is proved by a dimension argument: we show $p$ equals the maximal dimension of a subspace on which $\phi$ is positive definite, which is a basis-independent quantity.
The key idea is that a positive-definite subspace and a negative-semidefinite subspace can intersect only in $\{\mathbf{0}\}$, so the dimension formula bounds $\dim W \leq p$.
An identical argument with signs reversed establishes the invariance of $q$.
[/proofplan]
[step:Construct the canonical form by diagonalising and rescaling]
By the [Diagonalisation of Symmetric Bilinear Forms](/theorems/427), choose a basis $(e_1, \dots, e_n)$ with $\phi(e_i, e_j) = d_i \delta_{ij}$.
Reorder so that $d_1, \dots, d_p > 0$, then $d_{p+1}, \dots, d_{p+q} < 0$, then $d_{p+q+1} = \cdots = d_n = 0$.
For $i \leq p$: replace $e_i$ by $f_i = d_i^{-1/2}\,e_i$, giving $\phi(f_i, f_i) = 1$.
For $p < i \leq p + q$: replace $e_i$ by $f_i = |d_i|^{-1/2}\,e_i$, giving $\phi(f_i, f_i) = -1$.
For $i > p + q$: set $f_i = e_i$.
The matrix of $\phi$ with respect to $(f_1, \dots, f_n)$ is $\mathrm{diag}(\underbrace{1,\dots,1}_p, \underbrace{-1,\dots,-1}_q, \underbrace{0,\dots,0}_{n-p-q})$.
[/step]
[step:Prove $p$ is invariant as the maximal dimension of a positive-definite subspace]
Let $P = \langle f_1, \dots, f_p \rangle$ and $N_0 = \langle f_{p+1}, \dots, f_n \rangle$.
Then $\phi|_P$ is positive definite and $\phi|_{N_0}$ is negative semi-definite.
Let $W \subseteq V$ be any subspace on which $\phi|_W$ is positive definite.
If $w \in W \cap N_0$ with $w \neq \mathbf{0}$, then $\phi(w, w) > 0$ (since $w \in W$) and $\phi(w, w) \leq 0$ (since $w \in N_0$), a contradiction.
So $W \cap N_0 = \{\mathbf{0}\}$.
By the [Dimension Formula for Sums and Intersections](/theorems/374):
\begin{align*}
\dim W = \dim W - \dim(W \cap N_0) \leq \dim V - \dim N_0 = n - (n - p) = p.
\end{align*}
Since $P$ achieves dimension $p$ with $\phi|_P$ positive definite, $p = \max\{\dim W : \phi|_W \text{ is positive definite}\}$.
This maximum depends only on $\phi$, not on the basis, so $p$ is a congruence invariant.
[guided]
The uniqueness argument hinges on a simple but powerful observation: a positive-definite subspace and a negative-semidefinite subspace cannot share a nonzero vector.
Let $W$ be any subspace on which $\phi$ is positive definite, and let $N_0 = \langle f_{p+1}, \dots, f_n \rangle$ be the span of the negative and zero eigenvectors.
For any $w \in W \cap N_0$ with $w \neq \mathbf{0}$:
- From $w \in W$: $\phi(w, w) > 0$.
- From $w \in N_0$: write $w = \sum_{i=p+1}^n a_i f_i$, so $\phi(w, w) = \sum_{i=p+1}^{p+q} (-1) a_i^2 + 0 \leq 0$.
These two facts contradict each other, so $W \cap N_0 = \{\mathbf{0}\}$.
Now use the dimension formula.
Since $W \cap N_0 = \{\mathbf{0}\}$, $\dim(W + N_0) = \dim W + \dim N_0$.
Since $W + N_0 \subseteq V$, $\dim W + \dim N_0 \leq n$.
Therefore $\dim W \leq n - \dim N_0 = n - (n - p) = p$.
The subspace $P = \langle f_1, \dots, f_p \rangle$ achieves $\dim P = p$ with $\phi|_P$ positive definite (the matrix is $I_p$).
So $p$ is the maximum possible dimension of a positive-definite subspace, which is determined by $\phi$ alone, independent of any choice of diagonalising basis.
[/guided]
[/step]
[step:Prove $q$ is invariant by the same argument with signs reversed]
Let $Q = \langle f_{p+1}, \dots, f_{p+q} \rangle$ and $P_0 = \langle f_1, \dots, f_p, f_{p+q+1}, \dots, f_n \rangle$.
Then $\phi|_Q$ is negative definite and $\phi|_{P_0}$ is positive semi-definite.
Any subspace $W$ on which $\phi$ is negative definite satisfies $W \cap P_0 = \{\mathbf{0}\}$ (a nonzero vector in the intersection would have $\phi(w, w) < 0$ and $\phi(w, w) \geq 0$ simultaneously).
So $\dim W \leq n - \dim P_0 = n - (n - q) = q$.
Since $Q$ achieves dimension $q$, $q = \max\{\dim W : \phi|_W \text{ is negative definite}\}$, and $q$ is invariant.
[/step]