Counting the numbers with certain sum Let $n_1$ and $n_2$ be non-negative integers such that $n_1+n_2>0$.
Moreover, let $x_1 \in \{1,\ldots,n_1\}$, $x_2 \in \{1,\ldots,n_2\}$ (where we use the convention $\{1,0\}=\{0\}$) and $y \in \{1,\ldots,n_1+n_2\}$.
In this setting, how many couples of integers, $(x_1,x_2)$, exist such that $x_1+x_2=y$?
Thanks in advance for any help!
My attempt: I started to solve the simpler case where $n_1>0$, $n_2>0$ and $y<min(n_1,n_2)$. In such a case I believe that the answer is simply $y-1$ since you can choose the first number $x_1$ between $\{1,\ldots,n_1-1\}$ as you want and that implies a unique choice of $x_2$.
 A: Hint: $\{1,\dots,n_1\}\times\{1,\dots,n_2\}$ can be visualized as a $n_1\times n_2$ rectangle in $\mathbb Z^2$ with $n_1n_2$ points (pairs).  $y=x_1+x_2$ is a diagonal with slope −1 in the $x_1$-$x_2$ coordinate system.  Depending on where that diagonal intersects the rectangle (and joins points with it) or does not intersect at all etc. you get different cases to analyze.
Work out when the diagonal intersect a corner point of the rectangle, you will get 5 cases bounded by them: If the diagonal runs below the lower left point, there is no solution. Moving the diagonal up from when it meets the lower left point, to when it meets top-left or bottom-right, will give increasing natural numbers as  solution: 1, 2, 3, ... etc. 
A: Let $S(y;n_1,n_2)$ be the aforementioned set of couples, the question is to find its cardinality $|S(y;n_1,n_2)|$.
Answer:
(1) Case $n_1=0$ or $n_2=0$  then $|S(y;n_1,n_2)|=1$.
(2) Case $n_1 * n_2 \ne 0$ then $|S(y;n_1,n_2)|= n_1\wedge(y-1) + n_2\wedge (y-1) -y +1$
Idea of the proof:
Case (1) is trivial, so we consider the case (2).
Notice that, without the restriction to $(n_{j})_{j=1,2}$, this is a special case of the well-known problem of the composition on $y$ in exactly two parts (with cardinalities integers $n_1$ and $n_2$).
The answer in such an unconstrained case is $\binom{y-1}{J-1}$ with $J=2$.
It can be proven by rethinking the problem as choosing where to put a line in $y-1$ spaces splitting $y$ boxes. In this framework, $n_1$ and $n_2$ are the numbers of boxes before and after the line, respectively, thus the previous binomial coefficient.
In our framework, whenever $n_{j}$ are less than $y-1$ we have some restrictions on the possible spaces where we can put the line.
More, precisely, from the original $y-1$ spaces we delete the first and/or the last ones, that is $y-1-n_{j}$ spaces.
