If $X^TAX$ has $\chi^2$ distribution, then $A^2=A$. I'm attempting the following exercise:

Let $X = N(\mu, I_n)$ and $A$ be an $n\times n$ symmetric matrix. Show that
  if $X^TAX$ has the $χ^2_r(\delta)$ distribution (see noncentral chi-squared distribution), then $A^2 = A$, $r$ is the rank of $A$, and $\delta = \mu^TA\mu$.

My issue is that  don't see how I can make use of the assumption that $X^TAX$ has a certain distribution. How can I turn that hypothesis into an actual formula that I can write down and start working with?
 A: Apply the spectral theorem to write $A = O^{\mathsf{T}}DO$ for some orthogonal matrix $O$ and a diagonal matrix $D = \operatorname{diag}(\lambda_1, \cdots, \lambda_n)$. Then by writing $O\mu = \tilde{\mu} = (\tilde{\mu}_1, \cdots, \tilde{\mu}_n)$, the c.f. of $X^{\mathsf{T}}AX$ is
\begin{align*}
\mathsf{E}[e^{it X^{\mathsf{T}}AX}]
&= \int_{\mathbb{R}^n} \frac{1}{(2\pi)^{n/2}} e^{it \mathrm{x}^{\mathsf{T}}D\mathrm{x} - \frac{1}{2}\|\mathrm{x}-\tilde{\mu}\|^2} \, \mathrm{d}\mathrm{x} \\
&= \prod_{k=1}^{n} \int_{\mathbb{R}^n} \frac{1}{\sqrt{2\pi}} e^{it \lambda_k x_k^2 - \tfrac{1}{2} (x_k - \tilde{\mu}_k)^2} \, \mathrm{d}x_k \\
&= \prod_{k=1}^{n} \frac{1}{\sqrt{1 - 2it\lambda_k}} \exp\left\{ \frac{it\lambda_k \tilde{\mu}_k^2}{1 - 2it\lambda_k} \right\}.
\end{align*}
Here, we utilize the principal square root. Then the log-differentiation of $\mathsf{E}[e^{it X^{\mathsf{T}}AX}]$ equals
$$
\frac{\mathrm{d}}{\mathrm{d}t}\log \mathsf{E}[e^{it X^{\mathsf{T}}AX}]
= \sum_{k=1}^{n} \left( \frac{i\lambda_k}{1-2it\lambda_k} + \frac{i\lambda_k \tilde{\mu}_k^2}{(1-2it\lambda_k)^2} \right)
$$
On the other hand, by the assumption we have $X^{\mathsf{T}}AX \sim \chi^2_r(\delta)$ and hence
$$ \frac{\mathrm{d}}{\mathrm{d}t}\log \mathsf{E}[e^{it X^{\mathsf{T}}AX}] = \frac{ir}{1-2it} + \frac{i\delta}{(1-2it)^2}. $$
Comparing both sides, it follows that
(1) $A$ has the eigenvalue $1$ with multiplicity $r$ and the eigenvalue $0$ with multiplicity $n-r$. In particular, $\operatorname{rank}(A) = r$ and $A^2 = A$.
(2) $\delta = \sum_{k=1}^{n} \lambda_k \tilde{\mu}_k^2 = \mu^{\mathsf{T}} A \mu$.
Indeed, since both are rational functions, they are equal as meromorphic functions on all of $\mathbb{C}$. Now we can compare the residue of both sides at each point of $\mathbb{C}$ and conclude that (1) holds. Then (2) follows by a direct comparison.

In general, if we define $\chi^2(A, \mu)$ for a $n\times n$ symmetric matrix and $\mu \in \mathbb{R}^n$ as the law of $X^{\mathsf{T}}AX$ for $X \sim \mathcal{N}(\mu, I_n)$, then

Proposition. $\chi^2(A, \mu) = \chi^2(B, \nu)$ holds if and only if the following two conditions are satisfied:
  
  
*
  
*the sets non-zero eigenvalues (counted with multiplicity) of $A$ and $B$ coincide, and
  
*$\mu^{\mathsf{T}}A^k\mu = \nu^{\mathsf{T}}B^k\nu$ for all $k \geq 1$.
  

