How can you tell whether a quadratic expression is always positive? For real quadratic forms, this is the same as asking whether it can be written as a sum of squares, and it is decided by the associated symmetric matrix. This post collects the practical tests: completing the square, Sylvester’s criterion, Cholesky factorization and the law of inertia.
1. Quadratic forms hide symmetric matrices
A quadratic form in two variables is an expression such as Q(x,y)=ax^2+2bxy+cy^2. It can be written compactly as
Q(x,y)=\begin{pmatrix}x&y\end{pmatrix}\begin{pmatrix}a&b\\b&c\end{pmatrix}\begin{pmatrix}x\\y\end{pmatrix}.
More generally, Q(\mathbf{x})=\mathbf{x}^{T}A\mathbf{x} for a real symmetric matrix A. We may always choose a symmetric matrix because the skew-symmetric part contributes zero to \mathbf{x}^{T}A\mathbf{x}.
2. Positive definite versus positive semidefinite
A real symmetric matrix A is positive definite if \mathbf{x}^{T}A\mathbf{x}>0 for every nonzero real vector \mathbf{x}. It is positive semidefinite if the expression is nonnegative for every vector.
For example, x^2+y^2 is positive definite, whereas (x+y)^2 is only positive semidefinite: it vanishes on the line y=-x.
3. Completing the square
Consider Q(x,y)=2x^2+2xy+2y^2. Completing the square gives
Q(x,y)=2\left(x+\frac y2\right)^2+\frac32y^2.
Both coefficients are positive, so Q is positive definite. Another representation is Q=x^2+(x+y)^2+y^2. Thus the sum-of-squares representation need not be unique.
For a general real two-variable form with a>0,
ax^2+2bxy+cy^2=a\left(x+\frac ba y\right)^2+\left(c-\frac{b^2}{a}\right)y^2.
It follows that the form is positive definite exactly when a>0 and ac-b^2>0.
4. Sylvester’s criterion
For a real symmetric n\times n matrix, Sylvester’s criterion says that positive definiteness is equivalent to positivity of every leading principal minor: the determinants of the upper-left 1\times1, 2\times2, and so on, up to n\times n blocks.
For example, take
A=\begin{pmatrix}2&1\\1&2\end{pmatrix}.
The leading principal minors are 2 and \det A=3, both positive. Therefore A is positive definite.
Warning: Checking only that the diagonal entries are positive is not sufficient. For example, \begin{pmatrix}1&2\\2&1\end{pmatrix} has positive diagonal entries but determinant -3, so it is not positive definite.
5. Cholesky factorization: a systematic sum of squares
Every real symmetric positive definite matrix has a unique factorization A=LL^T where L is lower triangular with positive diagonal entries. Consequently,
\mathbf{x}^TA\mathbf{x}=\mathbf{x}^TLL^T\mathbf{x}=\lVert L^T\mathbf{x}\rVert^2.
This is explicitly a sum of squares of linear forms. For our example,
L=\begin{pmatrix}\sqrt2&0\\1/\sqrt2&\sqrt{3/2}\end{pmatrix},\qquad A=LL^T.
Thus Q(x,y)=\left(\sqrt2x+y/\sqrt2\right)^2+\left(\sqrt{3/2}\,y\right)^2.
6. A fourth test: eigenvalues
A real symmetric matrix is positive definite exactly when all its eigenvalues are positive, and positive semidefinite exactly when they are all nonnegative. For the matrix above, the eigenvalues are 3 and 1. Eigenvalues also explain the geometry: rotating the axes removes the mixed term. That viewpoint, with a complete worked example, is in How Matrices Turn Quadratic Forms into Sums of Squares.
7. Congruence and inertia
A change of variables \mathbf{x}=S\mathbf{y}, with invertible S, transforms the matrix to S^TAS. This is called congruence, not similarity. It preserves positive definiteness and positive semidefiniteness.
More generally, Sylvester’s law of inertia says that the numbers of positive, negative, and zero coefficients in a diagonalized real quadratic form do not depend on the invertible change of variables. An indefinite form, such as x^2-y^2, cannot become a sum of squares of real linear forms under such a change.
8. When is a sum-of-squares representation possible?
Theorem. For a real symmetric matrix A, the quadratic form \mathbf{x}^TA\mathbf{x} is a sum of squares of real linear forms if and only if A is positive semidefinite.
Proof. If Q=\sum_j(\mathbf{b}_j^T\mathbf{x})^2, then Q\ge0 for every \mathbf{x}, so A is positive semidefinite. Conversely, by the spectral theorem, write A=U\Lambda U^T with all \lambda_j\ge0. Then
Q(\mathbf{x})=\sum_j\left(\sqrt{\lambda_j}\,\mathbf{u}_j^T\mathbf{x}\right)^2,
which is the required sum of squares. \square
This theorem concerns quadratic forms over the real numbers. Requiring integer or rational coefficients in the squares introduces additional arithmetic questions; the theorem does not automatically give such representations.
9. Why does this matter in optimization?
A quadratic function f(\mathbf{x})=\tfrac12\mathbf{x}^TA\mathbf{x}-\mathbf{b}^T\mathbf{x}+c has Hessian A. If A is positive definite, then f is strictly convex and has the unique global minimizer \mathbf{x}=A^{-1}\mathbf{b}. Positive semidefiniteness gives convexity but not necessarily uniqueness or even existence of a minimizer for an arbitrary linear term.
10. Try it yourself
Exercise 1. Write 3x^2+6xy+5y^2 as a sum of squares.
Solution. 3(x+y)^2+2y^2. The form is positive definite.
Exercise 2. Determine whether A=\begin{pmatrix}4&3\\3&2\end{pmatrix} is positive definite.
Solution. The first leading principal minor is 4>0, but \det A=8-9=-1. Thus A is indefinite, not positive definite.
Exercise 3. Use Sylvester’s criterion to classify the quadratic form of \begin{pmatrix}5&2\\2&5\end{pmatrix}.
Solution. The leading principal minors are 5 and 25-4=21. Both are positive, so the form is positive definite.
Exercise 4. Show that x^2+2xy+y^2 is positive semidefinite but not positive definite.
Solution. It equals (x+y)^2\ge0, but vanishes for the nonzero vector (1,-1).
Challenge 5. For which real values of t is Q_t(x,y)=x^2+2txy+y^2 positive definite? When is it positive semidefinite?
Solution. The associated matrix is \begin{pmatrix}1&t\\t&1\end{pmatrix}. By Sylvester’s criterion it is positive definite exactly when 1-t^2>0. Equivalently, its eigenvalues are 1+t and 1-t. Thus it is positive definite for -1<t<1 and positive semidefinite for -1\le t\le1. At t=\pm1, the form is one square.
Further reading
Olga Taussky, “Sums of Squares,” The American Mathematical Monthly 77 (1970), 805–830, especially Section 4, “Positive definite (p.d.) matrices.” JSTOR record.
For the eigenvalue viewpoint, where rotating the axes turns a quadratic form into a sum of squares, see How Matrices Turn Quadratic Forms into Sums of Squares.
For another connection between complex numbers and sums of squares, see How to Generate Infinitely Many Pythagorean Triples Using Complex Numbers. For a related but different question, see When Is a Polynomial a Sum of Squares?

Leave a Reply