There are balls, balls, and balls.
How many different ways can you pick balls such that there is at least one ball for each color?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Relevant wiki: Generating Functions
I will show two ways to solve this problem, both making use of generating functions .
1 s t w a y
First, we can transform the question into a + b + c = 1 3 , removing the "at least one ball" part. Then, look at a more general question of finding the number of solutions in non-negative integers to the equation a + b + c = n .[From here we can solve it with stars and bars , but we will use generating functions here instead] Since the value of a can be any non-negative integer 0 , 1 , 2 , 3 , … , i , … (see note below), we can represent this as the generating function A ( x ) = 1 + x + x 2 + ⋯ + x i + ⋯ . We have the same generating function for the possible values of b and c . So our generating function for the number of solutions is A ( x ) × B ( x ) × C ( x ) = [ A ( x ) ] 3 . However, finding this product could be extremely tedious.
We instead transform A ( x ) into the rational function 1 − x 1 , which we recognize from the sum of a geometric progression. Thus, we are interested in [ A ( x ) ] 3 = ( 1 − x ) 3 1 . This can be expanded using the negative binomial theorem , which gives
( 1 − x ) 3 1 = ( 2 2 ) + ( 2 3 ) x + ( 2 4 ) x 2 + ⋯ + ( 2 i + 2 ) x i + ⋯ .
Therefore, the answer when n = 1 3 is given by ( 2 1 5 ) = 1 0 5 . This agrees with what we know from the stars and bars .
But we only have 9 balls each. Hence we need to deduct the possibilities where one type of ball are > 9 .
We now draw a table and write down all the possibilities.
Hence 1 0 5 − 3 0 = 7 5 □
Note: It might be confusing why we allow a to be any non-negative integer, even those which are larger than n , which clearly would not lead to a solution. Consider what would happen if we let a = n + 1 or a = n + 2 or any larger integer: In the final product of polynomials, the exponents of these terms would be larger than n , so they will not contribute to the term we want, which has exponent n .
2 n d w a y
First, we look at a more general question of finding the number of solutions in non-negative integers to the equation a + b + c = n . Since the value of a can be any positive integer 1 , 2 , 3 , … , 1 0 , we can represent this as the generating function A ( x ) = x + x 2 + ⋯ + x 1 0 = x ( 1 + x + x 2 + ⋯ + x 9 ) = ( 1 − x ) 3 x 3 ( 1 − x 1 0 ) 3 . We have the same generating function for the possible values of b and c . So our generating function for the number of solutions is A ( x ) × B ( x ) × C ( x ) = [ A ( x ) ] 3 .
A ( x ) × B ( x ) × C ( x ) = [ A ( x ) ] 3 = ( 1 − x ) 3 x 3 ( 1 − x 1 0 ) 3 = x 3 ( 1 − x 1 0 ) 3 ( 1 − x ) − 3 = x 3 ( 1 − 3 x 1 0 + 3 x 2 0 − x 3 0 ) k = 0 ∑ ∞ ( k k + 2 ) x k
The coefficient of x 1 6 is then the number of ways the balls can be picked. To compute this, take the 1 from the first bracket and let k = 1 3 , and take − 3 x 1 0 from the first bracket and let k = 3 :
( 2 1 5 ) − 3 ( 2 5 ) = 7 5 □