A composition of a positive integer n is an ordered sequence of positve integers that sum to n . A part of a composition refers to one of the numbers in the ordered sequence. For example, the ordered sequence 3 , 3 , 2 is a composition of 8 which has 3 parts.
What is the total number of parts in all of the compositions of the number 8?
Details and assumptions
( 1 , 2 , 1 ) and ( 2 , 1 , 1 ) are different compositions of 4, because the order of the elements is different.
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.
Probably you calculated the sum manually. That's what I did when I first solved the problem. But you can show that if we replace 8 by k , the sum equals 2 k − 2 ( k + 1 ) for all k , which makes the calculation much easier.
Log in to reply
Yes,it can be easily calculated by creating a bijection- In how many ways can you create a committee from k member of any size (without or with assigning a leader)...
Let S n be the set of compositions of n .
Let ∣ S n ∣ be the number of elements of S n , and p ( n ) be the total number of parts in S n .
Now we will present an algorithm for generating elements of S n + 1 based on elements of S n . Define two operations: A B : Append a 1 to the ordered sequence : Add 1 to the last part in the ordered sequence
Since both operations add 1 to the sum of parts, then s ∈ S n implies A ( s ) , B ( s ) ∈ S n + 1 . Further, for any s ∈ S n + 1 we can subtract 1 from its last digit (discarding zeroes) to give a member of S .
Therefore we have a bijection from S n × { A , B } to S n + 1 .
So ∣ S n + 1 ∣ = 2 ∣ S n ∣ .
Further, the operation A adds one part to each member of S n , and the operation B adds no parts. Therefore we have p ( n + 1 ) = ( p ( n ) + ∣ S n ∣ ) + p ( n )
Since S 1 = 1 , we get S n = 2 n − 1 , so p ( n + 1 ) = 2 p ( n ) + 2 n − 1
Solving this recurrence relation gives p ( n ) = 2 n − 2 ( n + 1 )
Proof by induction: p ( 1 ) = 2 − 1 ( 2 ) = 1 which is correct, and the induction step p ( n + 1 ) = 2 p ( n ) + 2 n − 1 = 2 ( 2 n − 2 ( n + 1 ) ) + 2 n − 1 = 2 n − 1 n + 2 n − 1 + 2 n − 1 = 2 n − 1 ( n + 2 ) = 2 ( n + 1 ) − 2 ( ( n + 1 ) + 1 )
The solution we want is p ( 8 ) = 2 6 ⋅ 9 = 5 7 6
To solve the initial relation for p , which isn't actually quite a recurrence relation yet: p ( n + 2 ) = 2 p ( n + 1 ) + 2 n = 4 p ( n ) + 2 n + 2 n = 4 ( p ( n ) + 2 n − 1 ) = 4 ( p ( n + 1 ) − p ( n ) )
This is now a recurrence relation and its characteristic equation is x 2 = 4 x − 4 which is ( x − 2 ) 2 = 0 , with double-root 2 .
So the general solution is p ( n ) = C ⋅ 2 n + D ⋅ n 2 n
Using n = 1 and n = 2 to solve this: 1 3 = 2 C + 2 D = 4 C + 8 D
giving C = D = 4 1 .
Really nice! I never thought of using recurrence relations this way. :)
Nice write up. I won't post my solution because it's mostly the same ... one slight semantic difference being that I regarded the penultimate step as answering the question "What is the average number of parts per component?"
Lemma: There are ( k − 1 n − 1 ) compositions of n that has k parts.
Proof: Note that each part is at least 1 . We remove 1 from each part, so we end up having to partition n − k into k parts. The number of ways to do this is identical to the number of ways to partition n − k balls into k boxes. We line up the balls, and put k − 1 walls collinear with the balls. The walls would then divide the balls into respective boxes. We then arrange the balls and walls. There are n − 1 items: a set of n − k balls and k − 1 walls. Hence, there are ( k − 1 n − 1 ) ways to arrange, thus our lemma is proved.
There are:
( 0 7 ) = 1 ways for 1 part → ( 1 ) ( 1 ) = 1 part.
( 1 7 ) = 7 ways for 2 parts → ( 7 ) ( 2 ) = 1 4 parts.
( 2 7 ) = 2 1 ways for 3 parts → ( 2 1 ) ( 3 ) = 6 3 parts.
( 3 7 ) = 3 5 ways for 4 parts → ( 3 5 ) ( 4 ) = 1 4 0 parts.
( 4 7 ) = 3 5 ways for 5 parts → ( 3 5 ) ( 5 ) = 1 7 5 parts.
( 5 7 ) = 2 1 ways for 6 parts → ( 2 1 ) ( 6 ) = 1 2 6 parts.
( 6 7 ) = 7 ways for 7 parts → ( 7 ) ( 7 ) = 4 9 parts.
( 7 7 ) 1 way for 8 parts → ( 1 ) ( 8 ) = 8 parts.
Adding them together, there are 1 + 1 4 + 6 3 + 1 4 0 + 1 7 5 + 1 2 6 + 4 9 + 8 = 5 7 6 total parts.
First, let's find the number of positive integer solutions to the equation a 1 + a 2 + . . . + a n = 8 , where n is a positive integer ≤ 8 . Since we are finding the number of positive integer solutions, a useful substitution would be a i = b i + 1 , so i = 0 ∑ n a i = i = 0 ∑ n b i + n The equation then reduces to i = 0 ∑ n b i = 8 − n . According to the ball and bars method, this equation has ( 8 − n ( 8 − n + n − 1 ) ) = ( 8 − n 7 ) solutions. So we can conclude that the number of compositions of 8 having n parts is equal to ( 8 − n 7 ) . These ( 8 − n 7 ) compositions contribute n ( 8 − n 7 ) to our final count. Our desired answer will then be n = 1 ∑ 8 n ( 8 − n 7 ) = 5 7 6 This sum can be calculated manually. One can also show by induction that n = 1 ∑ k n ( k − n k − 1 ) = 2 k − 2 ( k + 1 ) for all k ∈ N , which makes the calculation considerably easier.
Calculate the partitions of 8 then the partitions of these as multisets.
Start by defining p(n) to be the total number of parts in all compositions of n and f(n) to be the number of compositions of n.
f(n)=f(n-1)+f(n-2)+...f(1)+f(0) because we can simply subtract the first element and look at what remains. Since f(0)=1, f(n) simplifies to f(n) = 2^(n-1) for all integers n >0.
p(n) is a bit trickier, but you can still get a recurrence. p(n) equals p(n-1)+f(n-1)+p(n-2)+f(n-2)+...+p(0)+f(0). This is because the number parts in all of this is equal to the number of parts in all the ways you can get 1 plus the number of ways to get 1 (if the first part is n-1), plus the number of parts in all the ways to get 2 plus the number of ways to get 2 (if the first part is n-2), etc.
One can simply sum the f(n-1)+f(n-2)+...+f(1)+f(0) to f(n), and with a small number like 8 it is easy to do the calculations by hand.
The fact that order matters here makes the problem simpler.
Let the 8 be written as a row of 8 ones with 7 blank spots between them. 1 _ 1 _ 1 _ 1 _ 1 _ 1 _ 1 _ 1 .
Then the number of compositions with k parts is basically the number of ways we can insert k − 1 dividers into the distinct spots, with no spots allowed to be used twice. So the number of compositions with k parts is ( k − 1 7 )
For example, the number of compositions with one part is ( 0 7 ) , number of compositions with two parts is ( 1 7 ) and so on.
The total number of parts is the given by the sum ( 0 7 ) × 1 + ( 1 7 ) × 2 + . . . + ( 7 7 ) × 8 .
While this sum is easy to do by hand, we can also evaluate using a little trick.
We can consider the sum to be the value of the power series 1 + 2 × ( 1 7 ) x + 3 × ( 2 7 ) x 2 + . . . + 7 × ( 6 7 ) x 6 + 8 × ( 7 7 ) x 7 at x = 1
You can regard this power series as the differential of x ( 1 + x ) 7 . Differentiating (using the chain rule) we get the differential to be 7 x ( 1 + x ) 6 + ( 1 + x ) 7 . Substituting x = 1 gives the answer 7 × 2 6 + 2 7 = 5 7 6
A composition with k-parts of 8 is { x 1 , x 2 , ..., x k }, which is satisfied: x 1 + x 2 + ...+ x k = 8 This equation has C(7, k - 1) positive integer roots, so the number of parts : k * C(7, k - 1) We easily know that k is from 1 to 8, so the number of parts: Sum (k * C(7, k - 1)), k = 1 -> 7, this is also the value of the integration of function x ( 1 + x ) 7 at x = 1. So, the answer is 576
Can you please clarify how this is the value of ∫ x ( 1 + x ) 7 at x = 1 ? If I am correct, an integral needs 2 limits, just 1 value is not sufficient.
Problem Loading...
Note Loading...
Set Loading...
We do casework on how many parts the composition has. If it has 1 part, there is 1 composition. If it has 2 parts, we can think as follows:
1 1 1 1 1 1 1 1
Choose one of the spaces, and insert a divider.
1 1|1 1 1 1 1 1
This corresponds to the composition 2,6. Therefore, there are ( 1 7 ) = 7 compositions of 2 parts.
We can similarly calculate the number of compositions of n parts as ( 8 − n 7 ) . We choose n − 1 dividers out of the 7 spaces possible for dividers. Note that the integers have to be positive, so the calculation isn't ( n − 1 7 + n − 2 ) .
Therefore, the answer is + 1 ( 0 7 ) + 2 ( 1 7 ) + 3 ( 2 7 ) + 4 ( 3 7 ) 5 ( 4 7 ) + 6 ( 5 7 ) + 7 ( 6 7 ) + 8 ( 7 7 ) = 5 7 6