Synthetic division

From HandWiki
Short description: Algorithm for Euclidean division of polynomials
Animation showing the use of synthetic division to find the quotient of 2x4+3x2+5x+1 by x2. Note that there is no term in x3, so the fourth column from the right contains a zero.

In algebra, synthetic division is a method for manually performing Euclidean division of polynomials, with less writing and fewer calculations than long division.

It is mostly taught for division by linear monic polynomials (known as Ruffini's rule), but the method can be generalized to division by any polynomial.

The advantages of synthetic division are that it allows one to calculate without writing variables, it uses few calculations, and it takes significantly less space on paper than long division. Also, the subtractions in long division are converted to additions by switching the signs at the very beginning, helping to prevent sign errors.

Regular synthetic division

The first example is synthetic division with only a monic linear denominator xa.

x312x242x3

The numerator can be written as p(x)=x312x2+0x42.

The zero of the denominator g(x) is 3.

The coefficients of p(x) are arranged as follows, with the zero of g(x) on the left:

3 112042

The first coefficient after the bar is "dropped" to the last row.

31120421

The dropped number is multiplied by the number before the bar, and placed in the next column.

311204231

An addition is performed in the next column.

3112042319

The previous two steps are repeated and the following is obtained:

3112042327811927123

Here, the last term (-123) is the remainder while the rest correspond to the coefficients of the quotient.

The terms are written with increasing degree from right to left beginning with degree zero for the remainder and the result.

1x29x27123

Hence the quotient and remainder are:

q(x)=x29x27
r(x)=123

Evaluating polynomials by the remainder theorem

The above form of synthetic division is useful in the context of the polynomial remainder theorem for evaluating univariate polynomials. To summarize, the value of p(x) at a is equal to the remainder of the division of p(x) by xa.

The advantage of calculating the value this way is that it requires just over half as many multiplication steps as naive evaluation. An alternative evaluation strategy is Horner's method.

Expanded synthetic division

This method generalizes to division by any monic polynomial with only a slight modification with changes in bold. Using the same steps as before, perform the following division:

x312x242x2+x3

We concern ourselves only with the coefficients. Write the coefficients of the polynomial to be divided at the top.

 112042

Negate the coefficients of the divisor.

1x21x+3

Write in every coefficient but the first one on the left in an upward right diagonal (see next diagram).

31 112042

Note the change of sign from 1 to −1 and from −3 to 3 . "Drop" the first coefficient after the bar to the last row.

311120421

Multiply the dropped number by the diagonal before the bar, and place the resulting entries diagonally to the right from the dropped entry.

31112042311

Perform an addition in the next column.

3111204231113

Repeat the previous two steps until you would go past the entries at the top with the next diagonal.

3111204233911311316

Then simply add up any remaining columns.

311120423391131131681

Count the terms to the left of the bar. Since there are two, the remainder has degree one and this is the two right-most terms under the bar. Mark the separation with a vertical bar.

1131681

The terms are written with increasing degree from right to left beginning with degree zero for both the remainder and the result.

1x1316x81

The result of our division is:

x312x242x2+x3=x13+16x81x2+x3

For non-monic divisors

With a little prodding, the expanded technique may be generalised even further to work for any polynomial, not just monics. The usual way of doing this would be to divide the divisor g(x) with its leading coefficient (call it a):

h(x)=g(x)a

then using synthetic division with h(x) as the divisor, and then dividing the quotient by a to get the quotient of the original division (the remainder stays the same). But this often produces unsightly fractions which get removed later, and is thus more prone to error. It is possible to do it without first reducing the coefficients of g(x).

As can be observed by first performing long division with such a non-monic divisor, the coefficients of f(x) are divided by the leading coefficient of g(x) after "dropping", and before multiplying.

Let's illustrate by performing the following division:

6x3+5x273x22x1

A slightly modified table is used:

12/36507

Note the extra row at the bottom. This is used to write values found by dividing the "dropped" values by the leading coefficient of g(x) (in this case, indicated by the /3; note that, unlike the rest of the coefficients of g(x), the sign of this number is not changed).

Next, the first coefficient of f(x) is dropped as usual:

12/365076

and then the dropped value is divided by 3 and placed in the row below:

12/3650762

Next, the new (divided) value is used to fill the top rows with multiples of 2 and 1, as in the expanded technique:

12/365072462

The 5 is dropped next, with the obligatory adding of the 4 below it, and the answer is divided again:

12/36507246923

Then the 3 is used to fill the top rows:

12/3650723466923

At this point, if, after getting the third sum, we were to try and use it to fill the top rows, we would "fall off" the right side, thus the third sum is the first coefficient of the remainder, as in regular synthetic division. But the values of the remainder are not divided by the leading coefficient of the divisor:

12/365072346698423

Now we can read off the coefficients of the answer. As in expanded synthetic division, the last two values (2 is the degree of the divisor) are the coefficients of the remainder, and the remaining values are the coefficients of the quotient:

2x+38x4

and the result is

6x3+5x273x22x1=2x+3+8x43x22x1

Compact Expanded Synthetic Division

However, the diagonal format above becomes less space-efficient when the degree of the divisor exceeds half of the degree of the dividend. Consider the following division:

a7x7+a6x6+a5x5+a4x4+a3x3+a2x2+a1x+a0b4x4b3x3b2x2b1xb0

It is easy to see that we have complete freedom to write each product in any row as long as it is in the correct column, so the algorithm can be compactified by a greedy strategy, as illustrated in the division below:

b3b2b1b0/b4q0b3q1b3q1b2q0b2q2b3q2b2q2b1q1b1q0b1q3b3q3b2q3b1q3b0q2b0q1b0q0b0a7a6a5a4a3a2a1a0a7q2q1q0r3r2r1r0q3q2q1q0

The following describes how to perform the algorithm; this algorithm includes steps for dividing non-monic divisors:

  1. Write the coefficients of the dividend on a bar.
     a7a6a5a4a3a2a1a0
  2. Ignoring the first (leading) coefficient of the divisor, negate each coefficients and place them on the left-hand side of the bar.
    b3b2b1b0 a7a6a5a4a3a2a1a0
  3. From the number of coefficients placed on the left side of the bar, count the number of dividend coefficients above the bar, starting from the rightmost column. Then place a vertical bar to the left, and as well as the row below, of that column. This vertical bar marks the separation between the quotient and the remainder.
    b3b2b1b0a7a6a5a4a3a2a1a0
  4. Drop the first coefficient of the dividend below the bar.
    b3b2b1b0a7a6a5a4a3a2a1a0a7
    • Divide the previously dropped/summed number by the leading coefficient of the divisor and place it on the row below (this doesn't need to be done if the leading coefficient is 1).
      In this case q3=a7b4, where the index 3=74 has been chosen by subtracting the index of the divisor from the dividend.
    • Multiply the previously dropped/summed number (or the divided dropped/summed number) to each negated divisor coefficients on the left (starting with the left most); skip if the dropped/summed number is zero. Place each product on top of the subsequent columns.
      b3b2b1b0/b4q3b3q3b2q3b1q3b0a7a6a5a4a3a2a1a0a7q3
  5. Perform a column-wise addition on the next column. In this case, q2=q3b3+a6.
    b3b2b1b0/b4q3b3q3b2q3b1q3b0a7a6a5a4a3a2a1a0a7q2q3
  6. Repeat the previous two steps. Stop when you performed the previous two steps on the number just before the vertical bar.
    1. Let q2=q2b4.
      b3b2b1b0/b4q2b3q2b2q2b1q3b3q3b2q3b1q3b0q2b0a7a6a5a4a3a2a1a0a7q2q1q3q2
    2. Let q1=q1b4.
      b3b2b1b0/b4q1b3q1b2q2b3q2b2q2b1q1b1q3b3q3b2q3b1q3b0q2b0q1b0a7a6a5a4a3a2a1a0a7q2q1q0q3q2q1
    3. Let q0=q0b4.
      b3b2b1b0/b4q0b3q1b3q1b2q0b2q2b3q2b2q2b1q1b1q0b1q3b3q3b2q3b1q3b0q2b0q1b0q0b0a7a6a5a4a3a2a1a0a7q2q1q0r3q3q2q1q0
  7. Perform the remaining column-wise additions on the subsequent columns (calculating the remainder).
    b3b2b1b0/b4q0b3q1b3q1b2q0b2q2b3q2b2q2b1q1b1q0b1q3b3q3b2q3b1q3b0q2b0q1b0q0b0a7a6a5a4a3a2a1a0a7q2q1q0r3r2r1r0q3q2q1q0
  8. The bottommost results below the horizontal bar are coefficients of the polynomials (the quotient and the remainder), where the coefficients of the quotient are to the left of the vertical bar separation and the coefficients of the remainder are to the right. These coefficients are interpreted as having increasing degree from right to left, beginning with degree zero for both the quotient and the remainder.

    We interpret the results to get:

    a7x7+a6x6+a5x5+a4x4+a3x3+a2x2+a1x+a0b4x4b3x3b2x2b1xb0=q3x3+q2x2+q1x+q0+r3x3+r2x2+r1x+r0b4x4b3x3b2x2b1xb0

Python implementation

The following snippet implements Expanded Synthetic Division in Python for arbitrary univariate polynomials:

def expanded_synthetic_division(dividend, divisor):
    """Fast polynomial division by using Expanded Synthetic Division. 
    Also works with non-monic polynomials.

    Dividend and divisor are both polynomials, which are here simply lists of coefficients. 
    E.g.: x**2 + 3*x + 5 will be represented as [1, 3, 5]
    """
    out = list(dividend)  # Copy the dividend
    normalizer = divisor[0]
    for i in range(len(dividend) - len(divisor) + 1):
        # For general polynomial division (when polynomials are non-monic),
        # we need to normalize by dividing the coefficient with the divisor's first coefficient
        out[i] /= normalizer

        coef = out[i]
        if coef != 0:  # Useless to multiply if coef is 0
            # In synthetic division, we always skip the first coefficient of the divisor,
            # because it is only used to normalize the dividend coefficients
            for j in range(1, len(divisor)):
                out[i + j] += -divisor[j] * coef

    # The resulting out contains both the quotient and the remainder,
    # the remainder being the size of the divisor (the remainder
    # has necessarily the same degree as the divisor since it is
    # what we couldn't divide from the dividend), so we compute the index
    # where this separation is, and return the quotient and remainder.
    separator = 1 - len(divisor)
    return out[:separator], out[separator:]  # Return quotient, remainder.

See also

References