How many non-negative solutions for $x_{1} + x_{2} + x_{3} + x_{4} = 40$ where $2 \leq x_{1} \leq 8, x_{2} \leq 4, x_{3} \geq 4, x_{4} \leq 5$? My solution:
We have:
$x_{1} + x_{2} + x_{3} + x_{4} = 40$ where $2 \leq x_{1} \leq 8, x_{2} \leq 4, x_{3} \geq 4, x_{4} \leq 5$
$\Leftrightarrow  x_{2} + x_{3} + x_{4} = 40 - x_{1} \quad (*)$
Consider:
$x_{2} + x_{3} + x_{4} = 40 - x_{1}$ where $x_{2} \geq 0, x_{3} \geq 4, x_{4} \geq 0 \quad (**)$
$x_{2} + x_{3} + x_{4} = 40 - x_{1}$ where $x_{2} \geq 5, x_{3} \geq 4, x_{4} \geq 6 \quad (***)$
Let $f$ is the function that compute the number of non-negative solutions of an equation.
$\implies f(*) = f(**) - f(***)$ 
Thus, the number of non-negative solutions of (*) is $\sum_{x_{1} = 2}^{8}( {40 - x_{1} + 3 - 1  \choose 3 - 1} - {25-x_{1}+3 - 1 \choose 3 - 1}) = 3045$
I found that the right answer is 210 by trying some programming script. But I don't know what was wrong with my solution. Please help me. Thank you!

$x_1 + x_2 + x_4 \le 8  + 4 + 5 = 17$ so $x_3=40 - x_1 + s_2 + x_4 \ge 40 -17 \ge 4$ so we can ignore the restriction on $x_3$.
$2 \le x_1 \le 6$ so there are $7$ values that $x_1$ can be, $x\le 4$ so there are $5$ values it can be. $x_4 \le 5$ so there are $6$ values it can be and $x_3$ must be $40 - x_1 - x_2 -x_4$ there is only one option dependant on the other three options.
So there $7*5*6 = 210$ options.
Your solution dosn't take $x_3 \ge 4$ into account (which you can be seting it up so that the some is $36$ and not $40$-- I haven't done the math to figure it out but that will lower you answer significantly.  Also by subtracting you are removing the cases with both $x_2 \ge 5$ and $x_4 \ge 6$ but not removing the cases where one or the other is.)
I think to fix your problem using inclusion exclusion you'd want 
$\sum_{x_1=2}^8({{40 - 4 -x_1 + 3-1}\choose {3-1}} - {{40 - 4-5 -x_1 + 3-1}\choose {3-1}}-{{40 - 4-6 -x_1 + 3-1}\choose {3-1}}+{{40 - 4 -5-6-x_1 + 3-1}\choose {3-1}})=$
And I'm too lazy to finish.
