I learned this back in high school, but Henrik’s post about making change reminded me of it. I also used this technique with Sandeep for a project in Applied Math 115 a few weeks ago. The technique involves a concept called **generating functions**, and it’s useful for answering questions like

1) How many ways are there to make change for a dollar (using 1c, 5c, 10c, and 25c coins)?

2) How many ways are there to roll two dice so that the sum of the faces is 4? What about for any number of dice and any sum?

The second problem is easier to demonstrate, so I’ll answer it first. First, consider the following polynomial expression and its expansion:

If you think about the exponents in the first and second factors as representing the respective outcomes of the first and second die, then the coefficient of in the expansion counts the number of ways of achieving a sum of when rolling 2 dice. So the number of ways to roll a sum of 4 is given by the coefficient on , which is 3. This can be verified by counting the factors that lead to :

Generalizing to any number of dice involves adding more factors of , and probably the help of a computer algebra system like Mathematica, Maple, or Matlab.

The first problem can be solved by creating a generating function where each factor represents the number of coins of a specific denomination that we use in making change for a dollar. For example, there are ways to make change for a dollar that involve the use of anywhere from 0 to 4 quarters, so one factor will be

Similarly, we can use anywhere from 0 to 10 dimes:

anywhere from 0 to 20 nickels:

and anywhere from 0 to 100 pennies:

The coefficient on in the product of all four of these factors gives the number of ways to make 100 cents with any combination of pennies, nickels, dimes, and quarters. The following snippet of Matlab code does the expansion:

nickels = zeros(1,101); dimes = zeros(1,101); quarters = zeros(1,101);

pennies = poly2sym(ones(1,101));

nickels(1:5:101) = 1; nickels = poly2sym(nickels);

dimes(1:10:101) = 1; dimes = poly2sym(dimes);

quarters(1:25:101) = 1; quarters = poly2sym(quarters);

result = expand(pennies*nickels*dimes*quarters);

result = sym2poly(result);

result(101)

The answer is 242!

### Like this:

Like Loading...

*Related*

How would you do the first question without the program? How would you figure out the coeifficients?

By:

Allieon December 17, 2008at 11:52 am

When the factors of the generating function are all the same (like in the 2nd problem), the multinomial theorem can be used:

http://en.wikipedia.org/wiki/Multinomial_theorem

Your best shot for the 1st problem is either 1) buying a TI-89 to expand the polynomial or 2) buying a lot of scratch paper 🙂

By:

rfgarciaon December 17, 2008at 10:39 pm