Number of non-negative integer solutions of linear Diophantine equation

288 Views Asked by At

Given $n \ge 0$, find the number of non-negative integer solutions of the following equation $$2x_1+x_2+x_3+x_4+x_5=n$$


I tried putting one $x_1$ on the right-hand side, as follows

$$x_1+x_2+x_3+x_4+x_5=n-x_1.$$

Then I am not sure what to do. On the left-hand side, we now have non-negative numbers, but not sure how to write this sum because of the right-hand side.

2

There are 2 best solutions below

2
On

We choose a value for $x_1$ from $0$ to $\lfloor{\frac{n}{2}}\rfloor$.

Then we use combinations with repetition to distribute $r=n-2x_1$ identical objects into the 4 remaining slots ($x_2,x_3,x_4,x_5$).

So for each choice of $x_1$,

we have $m+r-1 \choose r$ solutions

$m+r-1 \choose r$, where m is 4.

=$n-2x_1+3 \choose n-2x_1$

=$n-2x_1+3 \choose 3$

So the total number of solutions is

$\sum_{x_1=0}^{\lfloor\frac{n}{2}\rfloor} {n-2x_1+3 \choose 3}$

Note sure if there's a simplification of this.

0
On

The number of nonnegative integer solutions of $2 x_1 + x_2 + x_3 + x_4 + x_5 = n$ is the coefficient of $t^n$ in the following generating function

$$\frac{1}{(1-t^2) (1-t)^4} = \frac{1}{(1+t) (1-t)^5}$$

which is the generating function for integer sequence OEIS A001752

$$a(n) = \left\lfloor \frac{((n+3)^2 - 1)((n+3)^2 - 3)}{48} \right\rfloor$$


Code

In Python:

>>> from sympy import *
>>> t = Symbol('t', real=True)
>>> f = 1 / ( (1 - t**2) * (1 - t)**4 )
>>> f.series(t,0,13)
1 + 4*t + 11*t**2 + 24*t**3 + 46*t**4 + 80*t**5 + 130*t**6 + 200*t**7 + 295*t**8 + 420*t**9 + 581*t**10 + 784*t**11 + 1036*t**12 + O(t**13)

In Haskell:

λ> map (\n -> floor(((n+3)^2 - 1)*((n+3)^2 - 3)/48)) [0..12]
[1,4,11,24,46,80,130,200,295,420,581,784,1036]