# Finding rank of a symmetric matrix

Let $$A$$ be an $$n\times n$$ symmetric matrix and let $$l_1,l_2,...,l_{r+s}$$ be $$r+s$$ linearly independent $$n\times 1$$ vectors such that for all $$n\times 1$$ vectors $$x$$ we have

$$x^TAx=(l_1^Tx)^2+...+(l_r^Tx)-(l_{r+1}^Tx)^2-...-(l_{r+s}^Tx)^2$$

We have to prove that $$rank(A)=r+s$$.

I cannot think of any approach to this problem.

By plugging $$e_i$$ in $$x$$ I am getting

$$(A)_{ii}=(l_1^T)_{i1}^2+...+(l_r^T)^2_{i1}-(l_{r+1}^T)^2_{i1}-...-(l_{r+s}^T)^2_{i1}$$

How can I obtain $$rank(A)$$ from the above equations?

Edit: As @angryavian answered, then A can be written as $$A=\sum_\limits{1\le i \le r} l_il_i^T - \sum_\limits{r+1 \le i \le s} l_il_i^T$$

we know that if $$A,B$$ be $$n \times n$$ symmetric matrix with $$x^TAx=x^TBx$$ for all $$x \in \mathbb{R}^n$$ then $$A=B$$.

Using the above information it remains to show that $$\sum_\limits{1\le i \le r} l_il_i^T - \sum_\limits{r+1 \le i \le s} l_il_i^T$$ has rank $$r+s$$.

How do I show this?

Hint: Note that $$(l_i^\top x)^2 = x^\top l_i l_i^\top x$$. Does this suggest a way to write $$A$$ in terms of the $$l_i$$?
Hint: Show that $$A=LL^\top$$ for a certain $$n \times (r+s)$$ matrix with rank $$r+s$$.