Wolfram Research

Function Repository Resource:

CompleteSquare

Source Notebook

Algebraically rewrites an expression by completing the square

Contributed by: Paco Jain (Wolfram Research)

ResourceFunction["CompleteSquare"][expr,x]

returns an expression equivalent to expr, when possible, of the form (a x+b)^2 + c where a,b, and c are FreeQ of x.

Details and Options

If no expression of the required form can be found, CompleteSquare returns $Failed:

Examples

Basic Examples

Complete the square of a quadratic:

In[1]:=
ResourceFunction["CompleteSquare"][x^2 - 6 x + 13, x]
Out[1]=

Complete the square of a quadratic with a mixture of numeric and symbolic coefficients :

In[2]:=
ResourceFunction["CompleteSquare"][x^2 - b x  + 13, x]
Out[2]=

Complete the square of the generic quadratic:

In[3]:=
ResourceFunction["CompleteSquare"][a x^2 + b x + c, x]
Out[3]=

Complete the square of a non-quadratic, even-ordered polynomial:

In[4]:=
ResourceFunction["CompleteSquare"][7 x^6 + 3 x^3 + 1, x]
Out[4]=

Properties and Relations

If no expression of the required form can be found, CompleteSquare returns $Failed:

In[5]:=
ResourceFunction["CompleteSquare"][x^4 - 3 x^2 - 7 x + 1, x]
Out[5]=

Resource History

License Information