randRangeNonZero(-10, 10) B2 * 2 randRangeNonZero(-100, 100) pow(B2, 2) new Polynomial(0, 2, [C, B, 1], "x") POLY.text()

Complete the square to rewrite this expression in the form `(x + a)^2 + b`.
`a` and `b` can be positive or negative.

`\qquad POLY_TEXT`

(x + B2)^2 + C - D

If we square the sum of `x` and another number, we get

`\begin{align} \qquad (x + a)^2 &= (x + a)(x + a) \\ &= x^2 + \pink{2a}x + a^2\end{align}`

The number multiplying the `x` term is `2` times the number that was added inside the square.

In the problem we're trying to solve, the number multiplying the `x` term is `B`, so when we rewrite the expression, the number added inside the square will be half of `B`. (Which is `B2`)

`\qquad (x + B2)^2 + b`

How can we find the value of `b`?

If we multiply out the square in this expression, we get

`\begin{align} \qquad (x + B2)^2 + b &= (x + B2)(x + B2) + b \\ &= x^2 + Bx + D + b \end{align}`

This looks just like the given expression if

`\qquad D + b = C`

So `b` must be `C- D`.

`POLY_TEXT` can be rewritten as:

`\qquad (x + B2)^2 + C - D`