How to calculate the number of solutions of the equation $x_1 + x_2 + x_3 = 9$ when $x_1$, $x_2$ and $x_3$ are integers which can only range from 1
to 6
.

- 7,933
-
3hint: generating function. – Mar 06 '15 at 10:43
-
I don't get why people keep adding answers which will only work for small numbers. To all the people who cast the upvotes, do you really think it's a good answer to count all solutions? – AvZ Mar 07 '15 at 14:45
-
i bet the principle of inclusion and exclusion is involved in the solution. why such a user name? – abel Mar 08 '15 at 16:36
4 Answers
We can find the number of solutions using binomial theorem.
The coefficient of $x^9$ in the following will be the required answer.
$$(x+x^2+\cdots+x^6)^3$$
This above, is a Geometric Progression. Therefore,
$$=\left (\frac{x-x^7}{1-x}\right )^3$$
$$=(x-x^7)^3(1-x)^{-3}$$
Now apply binomial theorem to get the coefficient of $x^9$
$$\left (\binom{3}{0}x^3-\binom{3}{1}x^9+\binom{3}{2}x^{15}-\binom{3}{3}x^{21} \right )\left (\binom{2}{0}+\binom{3}{1}x+\binom{4}{2}x^2+\cdots\infty\right )$$
We can neglect all terms with exponent $>9$
$$\left (\binom{3}{0}x^3-\binom{3}{1}x^9\right )\left (\binom{2}{0}+\binom{3}{1}x+\binom{4}{2}x^2+\cdots+\binom{11}{9}x^9\right )$$
We get the the coefficeient of $x^9$ as
$$\binom{3}{0}\binom{8}{6}-\binom{3}{1}\binom{2}{0}$$
$$=28-3$$
$$=25$$

- 1,691
- 1
- 11
- 24
-
Thanks for answering but can you please explain how you got $(x+x^2+\cdots+x^6)^3$. – Very Professional Username Mar 06 '15 at 12:07
-
1@StupidMan We have to find how many ways can we get $9$ from sum of each variable. $(x+x^2+\cdots+x^6)^3= (x+x^2+\cdots+x^6) (x+x^2+\cdots+x^6) (x+x^2+\cdots+x^6)$ This accounts for each variable with the value $1\leq x_1,x_2,x_3 \leq 6$. – AvZ Mar 06 '15 at 12:12
-
1Note that if we get $x^9$, all the exponents will add up to $9$. Denoting all the possible ways to get $9$ with given restrictions. For example, if you wanted only even solutions, you would have something like this $(x^2+x^4+x^6)^3$ – AvZ Mar 06 '15 at 12:14
-
1In $(x+x^2+\cdots+x^6)$, the exponent of $x$ accounts for all the possible values of a variable. Since all the variables are identical, we get $(x+x^2+\cdots+x^6)^3$. The coefficient of $x^9$ in the expansion of this will give us all the possible ways the exponent of $x$ can add up to $9$. – AvZ Mar 06 '15 at 12:22
-
Can you also explain how you got the second part of the product $\left (\binom{3}{0}-\binom{3}{1}x^6+\binom{3}{2}x^{12}-\binom{3}{3}x^{18} \right )\left (\binom{2}{0}+\binom{3}{1}x+\binom{4}{2}x^2+\cdots\infty\right )$? I read the binomial theorem for negative exponents here http://bsunewtonproject.wikispaces.com/file/view/Newton+project.pdf (only 100 kb file) but I still dont understand that part of your solution. – Very Professional Username Mar 07 '15 at 14:34
-
@StupidMan It is just binomial theorem for negative integral exponent. http://mathworld.wolfram.com/NegativeBinomialSeries.html – AvZ Mar 07 '15 at 14:44
-
@StupidMan Check out the $(1-x)^{-5}$ expansion in the answer sheet of the PDF. It's quite similar. – AvZ Mar 07 '15 at 14:53
-
Your sum of geometric progression is wrong. $x+ \cdots+ x^6 = \frac{(x-x^7)}{(1-x)}$, you have miraculously fluked the right answer though, as the sum you want is $$\binom{3}{0}\binom{8}{6}-\binom{3}{1}\binom{2}{0},$$ which still evaluates to $25$. But your method is incorrect, but almost very nice! – CameronJWhitehead Mar 08 '15 at 16:15
-
@CameronJWhitehead The method is correct (I have used it countless times before). I, myself, am prone to many errors (unfortunately). – AvZ Mar 08 '15 at 16:19
-
@CameronJWhitehead Fixed. Thanks for pointing that out. I make a lot of errors everywhere. (including my exams,
:(
) – AvZ Mar 08 '15 at 16:25
Write $x_i = y_i + 1$, where $0\le y_1 \le 5$
Then you have:
$$y_1 + y_2 + y_3 = 6$$
And according to stars and bars we have: $$\binom{6+3-1}{6} = 28 \text{ combinations}$$
Now just exclude the $(6,0,0), (0,6,0)$ and $(0,0,6)$ and you have $25$ solutions
UPDATE:
Now to find all the solutions we should exclude let $y_1 = 6 + z_1$, where $z_1 \ge 0$, then you have: $z_1 + y_2 + y_3 = 0$, and according to stars and bars we have:
$$\binom{0+3-1}{0} = 1 \text{ solution}$$
Now since we have three varaibles we have $3\cdot 1$ solution to exclude.
Note working with bigger numbers you'll exclude some solutions twice. To add them again let $y_1=6+z_1$ and $y_2=6+z_2$ and you'll have:
$$z_1 + z_2 + y_3 = -6$$
which obviously doesn't yield any solution. Now since we have $\binom{3}{2} = 3$ such pairs we need to add $3 \cdot 0 = 0$ solutions. Also you need to exclude the solution when $y_1 = 6+z_1; y_2 = 6+z_2; y_3=6+z_3$, which gives you:
$$z_1 + z_2 + z_3 = -12$$
obviously this doesn't yield any solutions, so we need to exclude $\binom{3}{3} \cdot 0 = 0$ solutions.

- 35,843
-
How did you count (6, 0, 0), (0, 6, 0) and (0, 0, 6)? – Very Professional Username Mar 07 '15 at 14:37
-
This is a bad approach IMHO. You're literally counting all the answers which will not fit. I bet you wouldn't even try this if I gave you $x_1+x_2+x_3=1000$ and $0\leq x_1,x_2,x_3\leq 750$ – AvZ Mar 07 '15 at 14:51
-
I have not explicitly mentioned in my question that the solution must work for larger cases also. @AvZ Your approach is great and I understand that it's a general method that can be used for other similar questions but the solution posted here does answer my question so I upvoted it. – Very Professional Username Mar 07 '15 at 14:55
-
1@StupidMan Since you are studying this. Odds are that questions with a bit larger numbers might appear in your examination/test/et cetera and counting all the solutions which don't fit would not really be a practical approach at all. Besides, almost all the other answers seem to be doing about the same. – AvZ Mar 07 '15 at 14:57
-
@AvZ It seems like you are trying to advertise your answer. I know that generating functions are a powerful tool, but somethimes they get messy and you need some calculation. Anyway do you know that counting combinations/permutations/variations using generating functions uses the include/exclude principle? This is pretty much the same, I will post an update just in second. – Stefan4024 Mar 07 '15 at 15:58
-
@Stefan4024 Let me get this straight. You really think counting all solutions is a good approach? Also, I don't see any "PLEASE UPVOTE MY ANSWER! IT'S BETTER!" anywhere in my previous comments. Neither have I mentioned it at all on your post. – AvZ Mar 07 '15 at 16:03
-
@AvZ You commented on every other answer, asking "What about bigger numbers?". I'm not counting solutions here, let's say I'm showing how generating functions method works and actually this is how it works. And I think it's the better way, since beginners are puzzled by how generating functions work. – Stefan4024 Mar 07 '15 at 16:07
-
@Stefan4024 You're entitled to your opinion. Please elaborate how pointing out something wrong in someone's answer counts as advertising? Is it simply due to the fact that I posted an answer which doesn't have that issue? I feel that generating functions is the best general method for beginners. Do you really expect the OP to count all the cases in their examination if they get a similar question, perhaps with a larger number? – AvZ Mar 07 '15 at 16:12
-
@AvZ There's an old saying: "give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime". So with this I mean to say that it's better to first start with simplier, more obvious things and gradually indtroducing the more complex method (teaching him how to fish), rather than giving them to him straight away (giving him a fish). For example when you were first introduced to Pascal's Triangle did you started constructing every number of it as a sum of the upper two, or did the teacher calculated it using $\binom{n}{k} = \frac{n!}{k!(n-k)!}$? – Stefan4024 Mar 07 '15 at 16:20
-
There is an old saying "A closed mouth gathers no feet." which is not really relevant at all but I still put it here. But getting on topic, there is a great rule of thumb the author provided on a famous physics textbook (Problems in General Physics by I.E Irodov) "General solutions are always better than specific ones" and I believe this applies to mathematics too. Besides, we should let the OP be the judge of what they think is too advanced for them. – AvZ Mar 07 '15 at 16:28
-
You're telling me that this method won't work in general? If yes, then you're saying that your method would fail, since generating functions are based on this principle. Anyway I agree that general solutions are better, but when you're introducing something new to somebody it's better to start working on specific ones, since it's much easier to understand. BTW here's another saying, which I hope I have translated it OK: "The smarter one lays off", which means that I have no intentions of fighting and arguing over something stupid. So goodbye – Stefan4024 Mar 07 '15 at 17:08
-
@G-man I think both Stefan and I have mutual agreement that it's fruitless and a waste of time to discuss any further. Besides, my comments were left there to point out an issue that all the other answer shared. Furthermore, I have seen you doing it as well on some ocassions and frankly, there is nothing wrong with it. Just because you have a competing answer there doesn't mean you lose the right to point out issues in others. – AvZ Mar 07 '15 at 20:31
-
@G-man Despite the fact that you chose to ignore the first sentence of my comment. Here goes, I think one of them was on a user RaghuramanR's answer and the rest I can't be bothered to remember. – AvZ Mar 07 '15 at 20:41
-
@G-man Precisely. I didn't "sign off". I just stopped posting comments. He doesn't care, I don't care. Mutual agreement. By the way, why do you care? – AvZ Mar 07 '15 at 20:45
-
@G-man It's irrelevant whether he called your answer wrong or not. The fact is, that he had posted on your answer. Then you posted on his answer, pointing out an issue with it, which is precisely what I did (pointing out an issue). – AvZ Mar 07 '15 at 20:49
A very simple way first count no.of Positive solutions by $(n-1)C(r-1)$. I hope you understand the meaning of $C$.Then if $x_1$ is $7$ then no. of solutions is $1$ similarly for $x_2$ & $x_3$ is also $1$, so number of solution is $28-3=25$.

- 76,571
-
-
Simply use the formula n-1Cr-1 and then find solutions by assuming variables out of the range and subtract from the original solution – Caratheodory_Enthusiast Mar 06 '15 at 11:44
-
How does "This was an easy one . Try my trigonometry bash" contribute to the answer? – JiK Mar 06 '15 at 11:53
-
I wanted to say that I have posted a question on trigonometry and want you to try it and give me a solution – Caratheodory_Enthusiast Mar 06 '15 at 11:58
-
I removed the irrelevant parts of your answer. Please see this tutorial on how to format mathematics on this site. – N. F. Taussig Mar 06 '15 at 14:44
There are six situations. 126,135,144,225,234 and 333,it's easy to know there is no other situation. So,we can add each of them together using permutation theorem. $$P_3^3+P_3^3+\frac{P_3^3}{P_2^2}+\frac{P_3^3}{P_2^2}+P_3^3+\frac{P_3^3}{P_3^3}=25$$

- 1,814
-
-
-
@Coffee What is the arrangement theorem? I googled but didnt find anything. – Very Professional Username Mar 06 '15 at 11:59