gizmobench

Polynomial Multiplication Calculator

Type two polynomials and the page multiplies them the way it would be written by hand: every term of the first factor against every term of the second, laid out as a grid, then the like powers added one row at a time to give each coefficient of the answer. The arithmetic runs on exact fractions rather than decimals, so a coefficient of 1/3 stays 1/3 and an integer of a hundred digits is multiplied out in full. Both factors may reach degree 30, which puts the product as high as degree 60, and either box also accepts a plain list of coefficients separated by commas. When both factors have two terms the same four products are labelled first, outer, inner and last, because FOIL is the order this grid already takes rather than a different method. Before anything reaches the screen the terms in the grid are added back up and compared with the printed product.

factorsdegree 1 by degree 2
(2x - 3)(x^2 + 4x - 5)

6 terms before collecting

(2x)(x^2) = 2x^3
(2x)(4x)  = 8x^2
(2x)(-5)  = -10x
(-3)(x^2) = -3x^2
(-3)(4x)  = -12x
(-3)(-5)  = 15
productcollected
      x^2    4x    -5
2x   2x^3  8x^2  -10x
-3  -3x^2  -12x    15

2x^3 + 5x^2 - 22x + 15
Product
2x³ + 5x² - 22x + 15
Degree
3
Terms
6 before collecting
Coefficients
Integer

Degree 1 times degree 2 gives degree 3: the two leading terms multiply, and nothing else can reach that power to cancel it.

  • (x + 2)(x - 3)the FOIL view
    x² - x - 6
  • (x² + 1)(x - 1)a sparse operand
    x³ - x² + x - 1
  • Anything times 0the zero polynomial
    0, with its degree reported as undefined
Accuracy. Exact coefficient convolution over the rationals, so 1/3 stays 1/3 and a hundred digit integer coefficient stays whole. Every distributive term is shown before it is collected, so the grid on screen adds up to the product printed beside it and you can check the arithmetic rather than accept it. Nothing here is evaluated as code.

Every term, before collecting

Each term of the first factor multiplies each term of the second, which is why 2 terms times 3 terms gives 6 products. Nothing has been added yet, so this list is the multiplication itself rather than its answer.

(2x)(x^2) = 2x^3
(2x)(4x)  = 8x^2
(2x)(-5)  = -10x
(-3)(x^2) = -3x^2
(-3)(4x)  = -12x
(-3)(-5)  = 15

Collecting like terms

Terms that carry the same power of x are added together, one row for each power any term landed on, and the sum is the coefficient that reaches the answer. A row that adds to 0 is a cancellation: it stays on the page rather than disappearing, because a missing term is the part of an answer that most often looks like a mistake.

x^3   2x^3         = 2x^3
x^2   8x^2 - 3x^2  = 5x^2
x     -10x - 12x   = -22x
1     15           = 15

The 6 terms above add to 2x^3 + 5x^2 - 22x + 15.

How this is worked out

Coefficients are held as whole-number pairs, a numerator over a denominator, and added and multiplied as fractions. Nothing is ever rounded, so 1/3 is printed as 1/3 and a coefficient of 100 digits is multiplied out in full instead of turning into a float. A decimal you type is read as the fraction it is: 0.75 becomes 3/4 before anything is multiplied.

The coefficient of each power of the answer is the sum of every pair of coefficients whose powers add to it, which is what a convolution is. Two factors of degree 30 give a product of degree 60, and the leading term can never cancel, because only one pair of terms can reach the top power. Before anything is shown, the terms in the grid are added back up and compared with the product, and both factors are evaluated at three points and multiplied to check the same answer a second way.

What you can type

One letter for the variable, whole numbers, fractions such as 2/3, decimals such as 0.75, the signs + - * / ^ and brackets. Multiplication can be left out where it is obvious, so 2x and (x - 1)(x + 2) read the way they are written. A power must be a whole number from 0 to 30, a single coefficient may run to 100 digits, and each box is read up to 4000 characters. A list separated by commas and holding no letter, such as 1, 0, 0, -1, is read as coefficients from the highest power down. Powers are typed with a caret, and the product line and the case list print them raised instead, which is the same polynomial written two ways: the working on the stage and the copied text keep the caret, so both paste back into anything that reads them.

Common questions

How do you multiply two polynomials?
Multiply every term of the first factor by every term of the second, then add the products that carry the same power. Two terms against three terms give six products before anything is added, which is exactly what this page prints: 2x - 3 times x^2 + 4x - 5 gives 2x^3, 8x^2, -10x, -3x^2, -12x and 15, and collecting the two x^2 terms and the two x terms leaves 2x^3 + 5x^2 - 22x + 15.
What is FOIL, and when can I use it?
FOIL names the four products you get when both factors have two terms: first, outer, inner, last. It is the same distributive multiplication in a fixed order, not a different rule, so this page shows the FOIL lines under the grid whenever both factors are binomials and leaves them out otherwise. For (x + 2)(x - 3) the four terms are x^2, -3x, 2x and -6, which collect to x^2 - x - 6. A factor with three or more terms has no FOIL form, and the grid is then the thing to read.
Why did a term disappear from the answer?
Because two of the distributive terms cancelled. (x + 1)(x - 1) makes four terms, but -x and x add to 0, so the product is x^2 - 1 with no x term at all. The collection table keeps that row on the page showing its sum as 0 rather than dropping it, and the line under the readout says which powers cancelled, because a missing term is the part of an answer that most often looks like a mistake.
Does it keep fractions exact, or round them?
Exact. Every coefficient is held as a whole-number numerator over a whole-number denominator and is never turned into a decimal, so (x + 1/3)(x + 1/3) is printed as x^2 + (2/3)x + 1/9 and never as 0.3333. A decimal you type is converted the other way before anything is multiplied, so 0.75 is read as 3/4. The readout says Integer when every coefficient on the page is whole and Rational when any of them is a fraction.
How large can the polynomials be?
Each box is read up to degree 30, so the product can reach degree 60. A single coefficient may run to 100 digits, and its products are multiplied out in full rather than rounded, so a hundred digit number times a hundred digit number prints all of its digits. Each box accepts up to 4000 characters, which holds a degree 30 polynomial with hundred digit coefficients. Anything past those limits is refused with a message that names the limit and what was read.
What can I type into the two boxes?
One letter for the variable, whole numbers, fractions such as 2/3, decimals, the signs + - * / ^ and brackets, with multiplication left out where it is obvious, so 2x and (x - 1)(x + 2) both read correctly. A list separated by commas that holds no letter is read as coefficients from the highest power down, so 1, 0, 0, -1 is the same as x^3 - 1. Powers are typed with a caret, and the result line prints them raised, which is the same polynomial written two ways: the copied working keeps the caret so it pastes back into anything.
What happens if one factor is 0?
The product is 0, and the page reports its degree as undefined rather than as 0, because the zero polynomial has no leading term to take a degree from. That is a real answer and not an error, so it is shown with the same wording however the zero is written, including x - x and 0x^5.
How do I know the answer is right?
Two ways, both run before anything is shown. The terms in the grid are added back up and compared with the printed product, and each factor is evaluated at three separate points, multiplied, and compared with the product at those same points. If either check ever failed the page would say so instead of printing an answer. Beyond that, the working is on the page: the grid, the term list and the collection are there to be checked by eye rather than trusted.

Exact coefficient convolution over the rationals, so 1/3 stays 1/3 and a hundred digit integer coefficient stays whole. Every distributive term is shown before it is collected, so the grid on screen adds up to the product printed beside it and you can check the arithmetic rather than accept it. Nothing here is evaluated as code.