Solution (source code)

= Solution

First work over a field of characteristic different from two. If a nonzero <symmetric bilinear form> had $\phi(v,v)=0$ for every <vector>, polarization would give
$$
2\phi(u,v)=\phi(u+v,u+v)-\phi(u,u)-\phi(v,v)=0,
$$
a contradiction. Hence choose $e$ with $\phi(e,e)\ne0$. Every $v$ decomposes uniquely as
$$
v=\frac{\phi(v,e)}{\phi(e,e)}e+\left(v-\frac{\phi(v,e)}{\phi(e,e)}e\right),
$$
with the second summand orthogonal to $e$. Induct on the <orthogonal complement> to obtain a diagonal basis. If the restricted form becomes zero, any basis of that remaining space completes the diagonalization. In this basis the <rank of a quadratic form> is exactly the number of nonzero diagonal coefficients; the remaining basis <vectors> span its <radical of a bilinear form>.

Over the reals, rescale the nonzero basis <vectors> so the diagonal entries are $p$ copies of $+1$, $q$ copies of $-1$ and $z=n-p-q$ zeros. Define the <signature of a quadratic form> by $\sigma=p-q$, so $r=p+q$. To prove it is basis independent, note that $p$ is the largest dimension of a <linear subspace> on which the form is <positive-definite>. The positive coordinate <linear subspace> attains dimension $p$; on any other positive <linear subspace>, projection to those positive coordinates is injective, since its kernel has nonpositive quadratic value. Thus its dimension is at most $p$. The same argument for the negative form characterizes $q$. This proves <Sylvester's law of inertia> and that the signature is well-defined.

Let $e_i$ and $f_i$ be positive and negative normalized basis <vectors>, and let $Z$ be the <radical of a bilinear form>. The span of $Z$ and $e_i+f_i$ for $1\leq i\leq\min(p,q)$ is a <totally isotropic subspace>: all mutual bilinear pairings vanish. Its dimension is $z+\min(p,q)$. Conversely, project any <totally isotropic subspace> $U$ to the nondegenerate positive-plus-negative quotient. The projected <linear subspace> is still null, and its projections to both the positive and negative coordinate spaces are injective: a <vector> with one component zero would have strictly signed quadratic value unless it vanished. Its dimension is therefore at most $\min(p,q)$, while the kernel of the quotient map on $U$ has dimension at most $z$. Hence
$$
\boxed{\max\dim U=z+\min(p,q)=n-\frac{r+|\sigma|}{2}}.
$$
This proves both construction and sharpness of the <maximum dimension of a totally isotropic subspace>.

For the five-variable example, the symmetric coefficient <matrix> is
$$
A=\begin{pmatrix}
0&1&0&0&1\\1&0&1&0&0\\0&1&0&1&0\\0&0&1&0&1\\1&0&0&1&0
\end{pmatrix}.
$$
Its cyclic structure makes the <vectors> $(1,\zeta^k,\zeta^{2k},\zeta^{3k},\zeta^{4k})$, $\zeta=e^{2\pi i/5}$, <eigenvectors> with <eigenvalues> $\zeta^k+\zeta^{-k}=2\cos(2\pi k/5)$. Thus the <eigenvalues> are
$$
2,\qquad \frac{\sqrt5-1}{2}\ \text{(twice)},\qquad -\frac{\sqrt5+1}{2}\ \text{(twice)}.
$$
Their product is $2$, and three are positive and two negative. Therefore
$$
\boxed{\det A=2,\qquad r=5,\qquad\sigma=1}.
$$
The real and imaginary parts of each conjugate pair of <eigenvectors> give the corresponding real two-dimensional <eigenspaces>, consistent with the real inertia calculation.