Function Repository Resource:

CompleteSquare

Source Notebook

Algebraically rewrite an expression by completing the square

Contributed by: Wolfram|Alpha Math Team

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

If no expression of the required form can be found, ResourceFunction["CompleteSquare"] returns $Failed.

Examples

Basic Examples (4) 

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 (1) 

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]=

Publisher

Wolfram|Alpha Math Team

Version History

  • 5.0.0 – 23 March 2023
  • 4.1.0 – 11 May 2021
  • 4.0.0 – 24 January 2020
  • 3.0.0 – 06 September 2019
  • 2.0.0 – 12 June 2019
  • 1.0.0 – 01 February 2019

Related Resources

License Information