For other exponents, the general formula is reached the same way. By applying the distributive property, we get a long sum of terms, each of which has a degree of . This is similar to the step for the square case. Using the commutative property, some of these terms are the same, so we can add them together.
Each term needs to have a total of n values. Call the number of as k; the number of bs then has to be . We can combine all these terms into a single one where the variables are . The coefficient of this term is all the number of ways you can have a word of length n with kas when the rest are bs.
This problem is equivalent to "How many different ways can we choose k positions to be a, out of n possible positions?" Mathematicians call this a combinations problem, and can be solved in terms of factorials. The number of combinations is written with the notation
The term with parentheses is read as "n choose k". Because of its role in binomial expansion, this is also called the binomial coefficient of n and k.
The formula for a general binomial expansion, where the binomial has two variables x and y and is raised to a power n, is then given as:
Relation to Pascal's triangle
Constructing Pascal's triangle. Each row matches the binomial coefficients of the matching degree (the first row is row 0).
Pascal's triangle is a mathematical construction that represents binomial coefficients. It starts with a row of one element,
The rest of the triangle is given by adding a new row, one unit larger than the previous, below it. The numbers in that row are the sum of the two numbers above it, with anything outside the triangle being treated as 0.
Pascal's triangle shows a recurrence relation on binomial coefficients:
In other words, the binomial coefficient of n and k can be found by adding the binomial coefficient of and to the binomial coefficient of and k. In terms of terms in the binomial expansion, this says that every term with kas has to either have come from adding an a to a shorter term with as, or adding a b to a shorter term with kas.