TITLE: How many solutions for an equation with simple restrictions
QUESTION [9 upvotes]: I'm working on an assignment in which I have to count the number of solutions for this particular equation: $$x_1+x_2+x_3+x_4=20$$for non negative integers with $x_1<8 $ and $x_2<6$ 
I'm aware that this kind of a task isn't that complicated, but I don't get combinatorics in general that well.
So I've tried two following approaches to get this done.
Firstly I tried to substitute the variable x:
$x_1+x_2+x_3+x_4=20 \Leftrightarrow y_1+y_2+y_3+y_4=34$
in which $y_1=x_1+8$ and $y_2=x_2+6$ (casue $x_1=y_1-8$ and $x_2=y_1-6$)
Following this approach the total number of possible solutions would be
$${34+3 \choose 3} $$
But I'm not sure if its the right solution.
The second approach is to sum all of the possible values that $x_1$ and $x_2$ could possibly take, also $x_1=0,1,2,3,4,5,6,7$ and $x_2=0,1,2,3,4,5,6$
And then  count all the possibilities for each of the variables $${20 -x_1-x_2+1\choose 1}$$
and sum them together like this:
$${21\choose 1}+{20\choose 1}+{19\choose 1}+{18\choose 1}+... $$
and so on...
I'm sure I'll get the correct number with this one, but I'm not feeling like summing all of this possibilities. There's got to be a better, more elegant way to deal with this.
My professor gave me a hint that I should do it using the complement.

REPLY [9 votes]: To determine the number of solutions of the equation 
$$x_1 + x_2 + x_3 + x_4 = 20 \tag{1}$$
in the non-negative integers subject to the restrictions $x_1 < 7$ and $x_2 < 6$, we subtract the number of solutions in which $x_1 > 7$ or $x_2 > 5$ from the number of solutions of the equation. 
A particular solution of equation 1 corresponds to the placement of three addition signs in a row of $20$ ones.  For instance,
$$1 1 1 1 + 1 1 1 1 1 + 1 1 1 1 1 1 + 1 1 1 1 1$$
corresponds to the solution $x_1 = 4$, $x_2 = 5$, $x_3 = 6$, and $x_4 = 5$, while 
$$+ 1 1 1 1 1 1 1 1 1 + 1 1 1 1 1 1 1 + 1 1 1 1$$
corresponds to the solution $x_1 = 0$, $x_2 = 9$, $x_3 = 7$, and $x_4 = 4$.  Thus, the number of solutions of equation 1 is the number of ways three addition signs can be inserted into a row of $20$ ones, which is 
$$\binom{20 + 3}{3}$$
since we must choose which three of the $23$ symbols ($20$ ones and $3$ addition signs) will be addition signs.
Suppose $x_1 > 7$.  Then $y_1 = x_1 - 8$ is a non-negative integer.  Substituting $y_1 + 8$ for $x_1$ in equation 1 yields
\begin{align*}
y_1 + 8 + x_2 + x_3 + x_4 & = 20\\
y_1 + x_2 + x_3 + x_4 & = 12 \tag{2}
\end{align*}
Equation 2 is an equation in the non-negative integers with 

 $$\binom{12 + 3}{3} = \binom{15}{3}$$

solutions.
Suppose $x_2 > 5$.  Then $y_2 = x_2 - 6$ is a non-negative integer.  Substituting $y_2 + 6$ for $x_2$ in equation 1 yields
\begin{align*}
x_1 + y_2 + 6 + x_3 + x_4 & = 20\\
x_1 + y_2 + x_3 + x_4 & = 14 \tag{3}
\end{align*}
Equation 3 is an equation in the non-negative integers with 

 $$\binom{14 + 3}{3} = \binom{17}{3}$$

solutions.
If we subtract the number of solutions of equation 2 and equation 3 from the number of solutions of equation 1, we will have subtracted those solutions in which $x_1 > 7$ and $x_2 > 5$ twice.  Thus, we must add the number of solutions in which $x_1 > 7$ and $x_2 > 5$.  
Suppose $x_1 > 7$ and $x_2 > 5$.  Then $y_1 = x_1 - 8$ and $y_2 = x_2 - 6$ are non-negative integers.  Substituting $y_1 + 8$ for $x_1$ and $y_2 + 6$ for $x_2$ in equation 1 yields
\begin{align*}
y_1 + 8 + y_2 + 6 + x_3 + x_4 & = 20\\
y_1 + y_2 + x_3 + x_4 & = 6 \tag{4}
\end{align*}
Equation 4 is an equation in the non-negative integers with 

 $$\binom{6 + 3}{3} = \binom{9}{3}$$

solutions.
By the Inclusion-Exclusion Principle, the number of solutions of equation 1 in the non-negative integers subject to the restrictions that $x_1 < 7$ and $x_2 < 6$ is 

 $$\binom{23}{3} - \binom{15}{3} - \binom{17}{3} + \binom{9}{3}$$