Solution (source code)

= Solution

Associate to $f$ the symmetric <bilinear form> $B(u,v)=\tfrac12(f(u+v)-f(u)-f(v))$. If $f$ is identically zero, every <basis> is diagonal. Otherwise choose $v$ with $f(v)\ne0$. Every $w$ has the decomposition
$$
w=\frac{B(w,v)}{B(v,v)}v+\left(w-\frac{B(w,v)}{B(v,v)}v\right),
$$
whose second term lies in $v^\perp$. Thus $V=\mathbb Rv\oplus v^\perp$, with no cross term in $f$. Induction on dimension gives a diagonal <basis>. Rescaling its nonzero entries reduces the form to
$$
f=\sum_{i=1}^px_i^2-\sum_{j=1}^qy_j^2,
$$
with $k$ additional zero coordinates. Define the <rank of a quadratic form> $r=p+q$ and its <signature> $s=p-q$. Rank is intrinsic, since it is the rank of $v\mapsto B(v,\cdot)$, equivalently $n-\dim\operatorname{rad}B$. Also $p$ is the greatest dimension of a subspace on which the restriction of $f$ is a <positive-definite quadratic form>: any such subspace intersects the negative-plus-zero coordinate space only at zero, so its dimension is at most $p$, while the positive coordinate space attains $p$. The corresponding negative statement identifies $q$. This proves the basis independence of $r$ and $s$, the <Sylvester's law of inertia> conclusion.

For a <totally isotropic subspace> $W$ on which $f$ vanishes, <polarization identity> also makes $B$ vanish on $W\times W$. Quotient by the <radical of a bilinear form>. In the resulting nondegenerate form, projection of an isotropic subspace to either the positive or negative coordinate space is injective, so its dimension is at most $\min(p,q)$. Consequently $\dim W\le k+\min(p,q)$. The <radical of a bilinear form> together with the vectors $e_i^++e_i^-$, $1\le i\le\min(p,q)$, attains this bound. The <maximum dimension of a totally isotropic subspace> is therefore
$$
\boxed{\dim W_{\max}=n-r+\frac{r-|s|}{2}=n-\frac{r+|s|}{2}.}
$$
The <criterion for membership in a diagonal basis> follows similarly: a nonzero vector can belong to a diagonal <basis> if it has nonzero quadratic value, by the same orthogonal splitting, or if it lies in the <radical of a bilinear form>, by choosing a radical basis containing it. An <isotropic vector> in a diagonal <basis> must be orthogonal to every basis vector, and hence must lie in that radical. For the specified form, its radical is the $z$-axis, giving exactly
$$
\boxed{v=(x,y,z)\text{ qualifies iff }(x^2\ne y^2)\text{ or }(x=y=0\text{ and }z\ne0).}
$$
The zero vector never belongs to a <basis>.