# The Number Of Integer Solutions Of Equations With Constraints

This question contains formulas from my previous question The Number Of Integer Solutions Of Equations.

I understand the following thus far:

1. The number of distinct positive integer-valued vectors $(x_1,x_2,...,x_r)$ such that $$x_1 + x_2 + ... + x_r = n$$ is equal to $n-1\choose r-1$.

2. The number of distinct non-negative integer-valued vectors $(x_1,x_2,...,x_r)$ such that $$x_1 + x_2 + ... + x_r = n$$ is equal to $n+r-1\choose r-1$.

• Problem 1

Suppose I want to count the number of distinct integer-valued vectors of the form $(x_1, x_2,...,x_r)$ such that $$x_1 + x_2 + ... + x_r = n$$

But now there are constraints involved $$x_1 \geq 0$$ $$x_r \geq 0$$ $$x_i > 0, i = 2,...,r-1$$

In words: the first and last integers are greater or equal to zero and all in-between must be greater than zero.

How many such distinct vectors are possible?

• My Approach To Problem 1

Let $$y_1 = x_1 + 1$$ $$y_i = x_i, i = 2,...,r-1$$ $$y_r = x_r + 1$$

This gives the positive integer-valued vector of the form $(y_1, y_2, ... , y_r)$ such that $$y_1 + y_2 + ... + y_r = n + 2$$

By (1), the number of distinct integer-valued vectors is equal to $n+2-1\choose r-1$ $=$ $n+1\choose r-1$

• Problem 2

Suppose I want to count the number of distinct integer-valued vectors of the form $(x_1, x_2,...,x_r)$ such that $$x_1 + x_2 + ... + x_r = n$$

The constraints involved are $$x_1 \geq 0$$ $$x_i \geq 2, i = 2,...,r-1$$ $$x_r \geq 0$$

In words: the first and last integers are greater or equal to zero and all in-between are greater or equal to two.

How many such distinct vectors are possible?

• My Approach To Problem 2

Let $$y_1 = x_1 + 1$$ $$y_i = x_i + 2, i = 2,...,r-1$$ $$y_r = x_r + 1$$

This gives the positive integer-valued vector of the form $(y_1, y_2, ... , y_r)$ such that $$y_1 + y_2 + ... + y_r = n + 2 + 2(r-2) = n + 2r-2$$

By (1), the number of distinct integer-valued vectors is equal to $n+2r-2-1\choose r-1$ $=$ $n+2r-3\choose r-1$

I would appreciate it if you could verify my solutions and provide hints/suggestions.

• In problem 2, perhaps you mean to define $y_i=x_i-1$, when $i=2,\ldots,r-1$? Otherwise using your current definition, $y_i=x_i+2\geq2+2=4$, when $i=2,\ldots,r-1$. Commented Sep 9, 2014 at 23:54
• @Peter That makes sense now, thank you. Commented Sep 10, 2014 at 0:32

I don't like the $y_i$ for the second. Either let $y_i=x_i-2$ for the middle ones, and use the formula for the number of solutions in non-negative integers of a suitable equation, or let $y_i=x_i+1$ for the end ones, and $y_i=x_i-1$ for the middle ones, and use the formula for the number of positive solutions of a suitable equation.
• At this moment I can't seem to figure out where the $-2$ in $y_i = x_i -2$ and the $-1$ in $y_i = x_i -1$ comes from? Commented Sep 10, 2014 at 0:03
• Wait, $-2$ for the non-negative since at least $2$ needs to be added to $y_i$ for the equation to be suited for using (2), and similarly for $-1$ and positive integer-valued vector? Commented Sep 10, 2014 at 0:06
• It depends on whether we want to reduce the problem to $\sum y_i=A$, with $y_i\ge 0$, or $\sum y_i=B$, where $y_i\ge 1$. Let's do the first. We want to distribute $n$ identical candies to $r$ kids, so that Kids $2$ to $r-1$ get $\ge 2$ candies. So give them each $2$ cndies, and distribute the remaining $n-2(r-2)$ among the $r$ kids, with possibly some getting $0$ in the second distribution. Of course this only works for $r\ge 2$. Commented Sep 10, 2014 at 0:10
• If we want to use the formula for the number of solutions where everybody is $\ge 1$, then $x_1=y_1-1$, since we must allow $x_1=0$, same for $y_r$. For the middle ones, we need $y_i=x_i-1$ since $x_i\ge 2$. We end up finding the number of positive solutions of $\sum y_i=n-(r-2)+2$. Commented Sep 10, 2014 at 0:14