The problem is simple: Given a quadratic expression
*a**x*^{2} + *b**x* + *c*,*A**x* + *B*)^{2} + *C*.

(*A**x* + *B*)^{2} = *A*^{2}*x*^{2} + 2*A**x* + *B*^{2}.

We will try to fit this to the given quadratic expression and it the only reasonable way is to start from the higest power.

If we want *A*^{2}*x*^{2}*a**x*^{2},*a* is negative, then obviously this cannot be done and
we leave it as a special case, see below. Otherwise we choose for *A*
the square root of *a*. We get the following:

Now we need to make the linear factor fit, which gives us the equation

Now we have this:

The powers of *x* all fit and it remains to choose *C* in such a
way that also the constants are the same on the left and on the right, so

A simple example will explain it best. We will complete the square in
*x*^{2} + 6*x* + 13.

**Case** *a* < 0:*C* − (*A**x* + *B*)^{2}.

As an example we will complete the square in
*x*^{2} + 2*x*.