Skip to main content.

Multinomial theorem

Suppose you have an expression of the form (a + b + c + d + e + f) squared , and you need to expand the square in order to solve some larger equation. How do you actually do that? More generally, is there an approach we can use to expand any group of added-together terms with any exponent?

Yes. It's called the multinomial theorem.

Let's get started

The multinomial theorem can be used to expand any expression of the form (x1 + x2 + ... + xm) to the nth power . Let's take a look at the equation:

(x1 + x2 + ... + xm) to the nth power  = Σ for all k1 + k2 + ... + km = n; k1,k2,...,km ≥ 0 do: ((
  • n
  • choose
  • k1,k2,...,km
  • )
    × Π from t = 1 through m do: (xt to the ktth power ) )

    Oh. Uh...

    Well, to start with, those values below the summation symbol (Σ) represent conditions. We have m variables named ksomething, named k1 through km, and we have two conditions that apply to the lot of them. We are going to take every possible combination of values that meets these conditions, feed those values into the summation "body," and then compute the results and sum them all.

    The summation "body," meanwhile, has us multiply a collection of values — that's the capital-pi (Π) symbol; it's the multiplication version of Σ — and then multiply that by something else. The result is then added as part of the summation loop.

    The first condition on our summation loop is that the values must all add up to n, and the second condition is that they must all be greater than or equal to zero. This in turn implies that no one single value can be greater than n, as otherwise we'd need at least one of the others to be negative in order for this to work.

    Hear that one bit with the word "choose?" That's the notation for binomial coefficients. If we call the top number n and the bottom number k, then given the expression (1 + x) to the kth power , we can compute the coefficient of x to the kth power  as follows:

    n! ÷ (k!(n - k)!)

    Wikipedia offers one example: (1 + x) to the 4th power  is:

    (1 + x) to the 4th power  = (
  • 4
  • choose
  • 0
  • )
    x to the zeroth power  + (
  • 4
  • choose
  • 1
  • )
    x to the first power  + (
  • 4
  • choose
  • 2
  • )
    x squared  + (
  • 4
  • choose
  • 3
  • )
    x cubed  + (
  • 4
  • choose
  • 4
  • )
    x to the 4th power 
    (1 + x) to the 4th power  = ( 4! ÷ (0!(4 - 0)!))x to the zeroth power  + ( 4! ÷ (1!(4 - 1)!))x to the first power  + ( 4! ÷ (2!(4 - 2)!))x squared  + ( 4! ÷ (3!(4 - 3)!))x cubed  + ( 4! ÷ (4!(4 - 4)!))x to the 4th power  (1 + x) to the 4th power  = (24 ÷ (24)) × 1 + (24 ÷ (6)) x to the first power  + (24 ÷ (2 × 2)) x squared  + (24 ÷ (6)) x cubed  + (24 ÷ (24)) x to the 4th power  (1 + x) to the 4th power  = 1 + 4x to the first power  + 6x squared  + 4x cubed  + x to the 4th power 

    Apparently, that generalizes to larger "multinomials;" if your multinomial has r terms in it, then you'd do:

    (
  • n
  • choose
  • k1,k2,...,kr
  • )
    = n! ÷ (k1!k2!...kr!)

    Given a multinomial with r terms, the variable ki is defined below — and as a reminder, this is summation, not a single variable:

    Σ from i = 1 through r do: (ki) = n

    This is all getting pretty out-there, so let's come back to Earth by actually using this.

    An example

    We'll go with the example I led in with: (a + b + c + d + e + f) squared . We have a multinomial that we want to square, so n is 2. Our multinomial has six terms, so m is 6.

    (x1 + x2 + x3 + x4 + x5 + x6) squared  = Σ for all k1 + k2 + ... + k6 = 2; k1,k2,...,k6 ≥ 0 do: ((
  • 2
  • choose
  • k1,k2,...,k6
  • )
    × Π from t = 1 through 6 do: (xt to the ktth power ) )
    (x1 + x2 + x3 + x4 + x5 + x6) squared  = Σ for all k1 + k2 + ... + k6 = 2; k1,k2,...,k6 ≥ 0 do: (2! ÷ (k1!k2!...k6!) × Π from t = 1 through 6 do: (xt to the ktth power ) )

    This equation is a nested loop. The outermost loop has six iterator variables, and the innermost loop just goes over those. It's a bit like this:

    int[...][6] all_possible_k_arrays = ...;
    
    int[6] k;
    
    // summation (big weird "E" symbol):
    sum = 0;
    for each k[1], k[2], k[3], k[4], k[5], k[6] matching conditions, do:
    
       // capital-pi thing:
       product = 1;
       for t = 1 to k.length do
          product *= ...;
       end
       
       // multiply by factorial fraction:
       product *= ...;
       
       sum += product;
    end

    We need to start at the innermost loop and work our way outward to understand this, but the innermost loop uses the six "loop index" variables, ki, that belong to our outer loop. That means that we need to figure out what those variables are.

    Computing our outer loop variables

    Let's compute the values of all possible combinations of ki for our 6-term monomial. We know that there must be six of these values, they must sum to 2, and none of them can be negative.

    Here's a list of every possible combination of numbers (between zero and 2, inclusive) that can add up to 2:

    • 2
    • 1 + 1

    Of course, we need to distribute those possibilities across sets of six total numbers, where any extra numbers just get set to zero. This means we'll have a lot of repeats — the same numbers being added together, but with the numbers in different slots among the six we have available. Here's what that looks like:

    Form k1 k2 k3 k4 k5 k6 Expression Sum
    2 + 0 2000002 + 0 + 0 + 0 + 0 + 0 2
    0200000 + 2 + 0 + 0 + 0 + 0 2
    0020000 + 0 + 2 + 0 + 0 + 0 2
    0002000 + 0 + 0 + 2 + 0 + 0 2
    0000200 + 0 + 0 + 0 + 2 + 0 2
    0000020 + 0 + 0 + 0 + 0 + 2 2
    1 + 1 1100001 + 1 + 0 + 0 + 0 + 0 2
    1010001 + 0 + 1 + 0 + 0 + 0 2
    1001001 + 0 + 0 + 1 + 0 + 0 2
    1000101 + 0 + 0 + 0 + 1 + 0 2
    1000011 + 0 + 0 + 0 + 0 + 1 2
    0110000 + 1 + 1 + 0 + 0 + 0 2
    0101000 + 1 + 0 + 1 + 0 + 0 2
    0100100 + 1 + 0 + 0 + 1 + 0 2
    0100010 + 1 + 0 + 0 + 0 + 1 2
    0011000 + 0 + 1 + 1 + 0 + 0 2
    0010100 + 0 + 1 + 0 + 1 + 0 2
    0010010 + 0 + 1 + 0 + 0 + 1 2
    0001100 + 0 + 0 + 1 + 1 + 0 2
    0001010 + 0 + 0 + 1 + 0 + 1 2
    0000110 + 0 + 0 + 0 + 1 + 1 2

    Dealing with the inner loop

    That's a lot of combinations up there, but let's actually use them and see how that shakes out. The ki variables are used in two ways:

    • For each ki in any valid set of values, we compute xi to the kith power . We then multply all of these together; this is the inner loop, called a sequence of products and indicated with the capital pi (Π).
    • After the inner loop is done, we compute the multinomial coefficient (the fraction with the factorials in it), and multiply that with the sequence of products.

    So let's start by substituting in our xi to the kith power  values. We'll keep things simple: instead of using the actual terms from our multinomial (for xi), we'll represent the whole multinomial as a + b + c + d + e + f.

    Form x1 to the k1th power  x2 to the k2th power  x3 to the k3th power  x4 to the k4th power  x5 to the k5th power  x6 to the k6th power 
    2 + 0 a squared  b to the zeroth power  c to the zeroth power  d to the zeroth power  e to the zeroth power  f to the zeroth power 
    a to the zeroth power  b squared  c to the zeroth power  d to the zeroth power  e to the zeroth power  f to the zeroth power 
    a to the zeroth power  b to the zeroth power  c squared  d to the zeroth power  e to the zeroth power  f to the zeroth power 
    a to the zeroth power  b to the zeroth power  c to the zeroth power  d squared  e to the zeroth power  f to the zeroth power 
    a to the zeroth power  b to the zeroth power  c to the zeroth power  d to the zeroth power  e squared  f to the zeroth power 
    a to the zeroth power  b to the zeroth power  c to the zeroth power  d to the zeroth power  e to the zeroth power  f squared 
    1 + 1 a to the first power  b to the first power  c to the zeroth power  d to the zeroth power  e to the zeroth power  f to the zeroth power 
    a to the first power  b to the zeroth power  c to the first power  d to the zeroth power  e to the zeroth power  f to the zeroth power 
    a to the first power  b to the zeroth power  c to the zeroth power  d to the first power  e to the zeroth power  f to the zeroth power 
    a to the first power  b to the zeroth power  c to the zeroth power  d to the zeroth power  e to the first power  f to the zeroth power 
    a to the first power  b to the zeroth power  c to the zeroth power  d to the zeroth power  e to the zeroth power  f to the first power 
    a to the zeroth power  b to the first power  c to the first power  d to the zeroth power  e to the zeroth power  f to the zeroth power 
    a to the zeroth power  b to the first power  c to the zeroth power  d to the first power  e to the zeroth power  f to the zeroth power 
    a to the zeroth power  b to the first power  c to the zeroth power  d to the zeroth power  e to the first power  f to the zeroth power 
    a to the zeroth power  b to the first power  c to the zeroth power  d to the zeroth power  e to the zeroth power  f to the first power 
    a to the zeroth power  b to the zeroth power  c to the first power  d to the first power  e to the zeroth power  f to the zeroth power 
    a to the zeroth power  b to the zeroth power  c to the first power  d to the zeroth power  e to the first power  f to the zeroth power 
    a to the zeroth power  b to the zeroth power  c to the first power  d to the zeroth power  e to the zeroth power  f to the first power 
    a to the zeroth power  b to the zeroth power  c to the zeroth power  d to the first power  e to the first power  f to the zeroth power 
    a to the zeroth power  b to the zeroth power  c to the zeroth power  d to the first power  e to the zeroth power  f to the first power 
    a to the zeroth power  b to the zeroth power  c to the zeroth power  d to the zeroth power  e to the first power  f to the first power 

    Now, if you take any value to the zeroth power, then you get 1, so we can strike a lot of terms from that table and just replace them with ones. Similarly, a term to the first power is just itself, so we can strip the exponent.

    Form x1 to the k1th power  x2 to the k2th power  x3 to the k3th power  x4 to the k4th power  x5 to the k5th power  x6 to the k6th power 
    2 + 0 a squared 11111
    1 b squared 1111
    11 c squared 111
    111 d squared 11
    1111 e squared 1
    11111 f squared 
    1 + 1 a b1111
    a1 c111
    a11 d11
    a111 e1
    a1111 f
    1 b c111
    1 b1 d11
    1 b11 e1
    1 b111 f
    11 c d11
    11 c1 e1
    11 c11 f
    111 d e1
    111 d1 f
    1111 e f

    Now let's add the multinomial coefficients to the table:

    Form i = 1 i = 2 i = 3 i = 4 i = 5 i = 6 MCs
    2 + 0 a squared 111111
    1 b squared 11111
    11 c squared 1111
    111 d squared 111
    1111 e squared 11
    11111 f squared 1
    1 + 1 a b11112
    a1 c1112
    a11 d112
    a111 e12
    a1111 f2
    1 b c1112
    1 b1 d112
    1 b11 e12
    1 b111 f2
    11 c d112
    11 c1 e12
    11 c11 f2
    111 d e12
    111 d1 f2
    1111 e f2

    Putting it all together

    Remember that each row represents a valid set of possible values for the k1 through k6 variables. Each row represents the values we'll use in this part of the formula:

    2! ÷ (k1!k2!...k6!) × Π from t = 1 through 6 do: (xt to the ktth power )

    If we multiply all the items in a row together, then we'll get the result of that expression for that given set of ki values. Let's see what that looks like. We can skip every cell in the table that's just the number 1, so in practice, 90% of that table is gone:

    Form Full entry Collapsed Final
    2 + 0 a squared  × 1 × 1 × 1 × 1 × 1 × 1 a squared  × 1 a squared 
    1 × b squared  × 1 × 1 × 1 × 1 × 1 b squared  × 1 b squared 
    1 × 1 × c squared  × 1 × 1 × 1 × 1 c squared  × 1 c squared 
    1 × 1 × 1 × d squared  × 1 × 1 × 1 d squared  × 1 d squared 
    1 × 1 × 1 × 1 × e squared  × 1 × 1 e squared  × 1 e squared 
    1 × 1 × 1 × 1 × 1 × f squared  × 1 f squared  × 1 f squared 
    1 + 1 a × b × 1 × 1 × 1 × 1 × 2 a × b × 2 2ab
    a × 1 × c × 1 × 1 × 1 × 2 a × c × 2 2ac
    a × 1 × 1 × d × 1 × 1 × 2 a × d × 2 2ad
    a × 1 × 1 × 1 × e × 1 × 2 a × e × 2 2ae
    a × 1 × 1 × 1 × 1 × f × 2 a × f × 2 2af
    1 × b × c × 1 × 1 × 1 × 2 b × c × 2 2bc
    1 × b × 1 × d × 1 × 1 × 2 b × d × 2 2bd
    1 × b × 1 × 1 × e × 1 × 2 b × e × 2 2be
    1 × b × 1 × 1 × 1 × f × 2 b × f × 2 2bf
    1 × 1 × c × d × 1 × 1 × 2 c × d × 2 2cd
    1 × 1 × c × 1 × e × 1 × 2 c × e × 2 2ce
    1 × 1 × c × 1 × 1 × f × 2 c × f × 2 2cf
    1 × 1 × 1 × d × e × 1 × 2 d × e × 2 2de
    1 × 1 × 1 × d × 1 × f × 2 d × f × 2 2df
    1 × 1 × 1 × 1 × e × f × 2 e × f × 2 2ef

    So those are all the possible values of that one expression. Where were we using it again?

    (a + b + c + d + e + f) squared  = Σ ()

    Right! We were going to add those final items together. Let's see what that looks like:

    (a + b + c + d + e + f) squared  = a squared  + b squared  + c squared  + d squared  + e squared  + f squared  + 2ab + 2ac + 2ad + 2ae + 2af + 2bc + 2bd + 2be + 2bf + 2cd + 2ce + 2cf + 2de + 2df + 2ef

    Conclusion

    This overall process can be followed for a multinomial of any size m, being raised to any exponent n. You want to create a table like the ones above, listing out every combination of m many numbers (each between 0 and n) that add up to n. You can then mimic the process above, and get your result.