Professional Documents
Culture Documents
Discrete Mathematics: Wwlchen
Discrete Mathematics: Wwlchen
Discrete Mathematics: Wwlchen
W W L CHEN
c W W L Chen, 1992, 2003.
This chapter is available free to all individuals, on the understanding that it is not to be used for financial gains,
and may be downloaded and/or photocopied, with or without permission from the author.
However, this document may not be kept on any information storage and retrieval system without permission
from the author, unless such system is not accessible to any individuals other than its owners.
Chapter 15
NUMBER OF SOLUTIONS
OF A LINEAR EQUATION
15.1. Introduction
Example 15.1.1. Suppose that 5 new academic positions are to be awarded to 4 departments in
the university, with the restriction that no department is to be awarded more than 3 such positions,
and that the Mathematics Department is to be awarded at least 1. We would like to find out in how
many ways this could be achieved. If we denote the departments by M, P, C, E, where M denotes
the Mathematics Department, and denote by uM , uP , uC , uE the number of positions awarded to these
departments respectively. Then clearly we must have
(1) uM + uP + uC + uE = 5.
Furthermore,
We therefore need to find the number of solutions of the equation (1), subject to the restriction (2).
In general, we would like to find the number of solutions of an equation of the type
u1 + . . . + uk = n,
where n, k ∈ N are given, and where the variables u1 , . . . , uk are to assume integer values, subject to
certain given restrictions.
15–2 W W L Chen : Discrete Mathematics
Suppose that we are interested in finding the number of solutions of an equation of the type
(3) u1 + . . . + uk = n,
PROPOSITION 15A. The number of solutions of the equation (3), subject to the restriction (4), is
given by the binomial coefficient
n+k−1
.
n
+ + + + + + + + + + + + + + + + ... + + + + + + + + + + + + + + + +
n+k−1
Let us choose n of these + signs and change them to 1’s. Clearly there are exactly (k − 1) + signs
remaining, the same number of + signs as in the equation (3). The new situation is shown in the picture
below:
(5) 1 .
. . 1 + . . . + 1 .
. . 1
u1 uk
k
0 + 4 + 0 + 1 + 3 + 2 + ... + 7 + 4 + 2
(note that consecutive + signs indicate an empty block of 1’s in between, and the + sign at the left-hand
end indicates an empty block of 1’s at the left-hand end; similarly a + sign at the right-hand end would
indicate an empty block of 1’s at the right-hand end). It follows that our choice of the n 1’s corresponds
to a solution of the equation (3), subject to the restriction (4). Conversely, any solution of the equation
(3), subject to the restriction (4), can be illustrated by a picture of the type (5), and so corresponds to
a choice of the n 1’s. Hence the number of solutions of the equation (3), subject to the restriction (4),
is equal to the number of ways we can choose n objects out of (n + k − 1). Clearly this is given by the
binomial coefficient indicated.
Example 15.2.1. The equation u1 + . . . + u4 = 11, where the variables u1 , . . . , u4 ∈ {0, 1, 2, 3, . . .}, has
11 + 4 − 1 14
= = 364
11 11
solutions.
Chapter 15 : Number of Solutions of a Linear Equation 15–3
We next consider the situation when the variables have upper restrictions. Suppose that we are interested
in finding the number of solutions of an equation of the type
(6) u1 + . . . + uk = n,
Our approach is to first of all relax the upper restrictions in (7), and solve instead the Case A
problem of finding the number of solutions of the equation (6), where the variables
solutions. Among these solutions will be some which violate the upper restrictions on the variables
u1 , . . . , uk as given in (7).
For every i = 1, . . . , k, let Si denote the collection of those solutions of (6), subject to the relaxed
restriction (8) but which ui > mi . Then we need to calculate
|S1 ∪ . . . ∪ Sk |,
the number of solutions which violate the upper restrictions on the variables u1 , . . . , uk as given in (7).
This can be achieved by using the Inclusion-exclusion principle, but we need to calculate
|Si1 ∩ . . . ∩ Sij |
PROPOSITION 15B. Suppose that i = 1, . . . , k is chosen and fixed. Then the number of solutions
of the equation (6), subject to the restrictions
(9) ui ∈ {mi + 1, mi + 2, mi + 3, . . .}
and
where B1 , . . . , Bi−1 , Bi+1 , . . . , Bk are all subsets of N ∪ {0}, is equal to the number of solutions of the
equation
(12) vi ∈ {0, 1, 2, 3, . . .}
and (10).
15–4 W W L Chen : Discrete Mathematics
ui = vi + (mi + 1),
then the restrictions (9) and (12) are the same. Furthermore, equation (6) becomes
By applying Proposition 15B successively on the subscripts i1 , . . . , ij , we have the following result.
Proof. Note that |Si1 ∩ . . . ∩ Sij | is the number of solutions of the equation (6), subject to the
restrictions
and
Now write
vi + (mi + 1) if i ∈ {i1 , . . . , ij },
ui =
vi if i ∈
{i1 , . . . , ij }.
Then by repeated application of Proposition 15B, we can show that the number of solutions of the
equation (6), subject to the restrictions (13) and (14), is equal to the number of solutions of the equation
This is a Case A problem, and it follows from Proposition 15A that the number of solutions of the
equation (15), subject to the restriction (16), is given by
n − (mi1 + 1) − . . . − (mij + 1) + k − 1
.
n − (mi1 + 1) − . . . − (mij + 1)
(17) u1 + . . . + u4 = 11,
has
11 + 4 − 1 14
=
11 11
solutions. For every i = 1, . . . , 4, let Si denote the collection of those solutions of (17), subject to the
relaxed restriction (19) but which ui > 3. Then we need to calculate
|S1 ∪ . . . ∪ S4 |.
and
11 − 8 + 4 − 1 6
|S1 ∩ S2 | = |S1 ∩ S3 | = |S1 ∩ S4 | = |S2 ∩ S3 | = |S2 ∩ S4 | = |S3 ∩ S4 | = = .
11 − 8 3
This is meaningless. However, note that |S1 ∩ S2 ∩ S3 | is the number of solutions of the equation
v1 , v2 , v3 , v4 ∈ {0, 1, 2, 3, . . .}.
Similarly
|S1 ∩ S2 ∩ S3 ∩ S4 | = 0.
4
|S1 ∪ S2 ∪ S3 ∪ S4 | = (−1)j+1 |Si1 ∩ . . . ∩ Sij |
j=1 1≤i1 <...<ij ≤4
It now follows that the number of solutions of the equation (17), subject to the restriction (18), is given
by
14 14 4 10 4 6
− |S1 ∪ S2 ∪ S3 ∪ S4 | = − + = 4.
11 11 1 7 2 3
We next consider the situation when the variables have non-standard lower restrictions. Suppose that
we are interested in finding the number of solutions of an equation of the type
(20) u1 + . . . + uk = n,
(21) ui ∈ Ii ,
where
It turns out that we can apply the same idea as in Proposition 15B to reduce the problem to a Case
A problem or a Case B problem. For every i = 1, . . . , k, write ui = vi + pi , and let Ji = {x − pi : x ∈ Ii };
in other words, the set Ji is obtained from the set Ii by subtracting pi from every element of Ii . Clearly
(24) v1 + . . . + vk = n − p1 − . . . − pk .
It is easy to see that the number of solutions of the equation (20), subject to the restrictions (21) and
(22), is the same as the number of solutions of the equation (24), subject to the restrictions vi ∈ Ji and
(23).
(25) u1 + . . . + u4 = 11,
(28) v1 + . . . + v4 = 10.
The number of solutions of the equation (25), subject to the restriction (26), is equal to the number of
solutions of the equation (28), subject to the restriction (27). We therefore have a Case B problem.
Chapter 15 : Number of Solutions of a Linear Equation 15–7
(29) u1 + . . . + u6 = 23,
(32) v1 + . . . + v6 = 13.
The number of solutions of the equation (29), subject to the restriction (30), is equal to the number
of solutions of the equation (32), subject to the restriction (31). We therefore have a Case B problem.
Consider first of all the Case A problem, where the upper restrictions on the variables v1 , . . . , v6 are
relaxed. By Proposition 15A, the number of solutions of the equation (32), subject to the relaxed
restriction
Let
|S1 ∪ . . . ∪ S6 |.
Also
13 − 12 + 6 − 1 6
|S1 ∩ S2 | = |S1 ∩ S3 | = |S2 ∩ S3 | = = ,
13 − 12 1
13 − 10 + 6 − 1 8
|S1 ∩ S4 | = |S1 ∩ S5 | = |S2 ∩ S4 | = |S2 ∩ S5 | = |S3 ∩ S4 | = |S3 ∩ S5 | = = ,
13 − 10 3
13 − 9 + 6 − 1 9
|S1 ∩ S6 | = |S2 ∩ S6 | = |S3 ∩ S6 | = = ,
13 − 9 4
13 − 8 + 6 − 1 10
|S4 ∩ S5 | = = ,
13 − 8 5
13 − 7 + 6 − 1 11
|S4 ∩ S6 | = |S5 ∩ S6 | = = ,
13 − 7 6
and
and
|S1 ∩ . . . ∩ S6 | = 0.
6
|S1 ∪ . . . ∪ S6 | = (−1)j+1 |Si1 ∩ . . . ∩ Sij |
j=1 1≤i1 <...<ij ≤6
12 14 15 6 8 9 10 11 5 7
= 3 +2 + − 3 +6 +3 + +2 + 6 + .
7 9 10 1 3 4 5 6 0 2
Hence the number of solutions of the equation (29), subject to the restriction (30), is equal to
18
− |S1 ∪ . . . ∪ S6 |
13
18 12 14 15
= − 3 +2 +
13 7 9 10
6 8 9 10 11 5 7
+ 3 +6 +3 + +2 − 6 + .
1 3 4 5 6 0 2
Chapter 15 : Number of Solutions of a Linear Equation 15–9
Suppose that we are interested in finding the number of solutions of the equation
u1 + . . . + u4 = 23,
Then it is very difficult and complicated, though possible, to make our methods discussed earlier work.
We therefore need a slightly better approach. We turn to generating functions which we first studied in
Chapter 14.
Suppose that we are interested in finding the number of solutions of an equation of the type
(34) u1 + . . . + uk = n,
(35) ui ∈ Bi ,
where
(36) B1 , . . . , Bk ⊆ N ∪ {0}.
corresponding to the variable ui in the equation (34), and consider the product
f (X) = f1 (X) . . . fk (X) = X u1
... X uk
= ... X u1 +...+uk .
u1 ∈B1 uk ∈Bk u1 ∈B1 uk ∈Bk
We now rearrange the right-hand side and sum over all those terms for which u1 + . . . + uk = n. Then
we have
∞
∞
n
f (X) = X u1 +...+uk = 1
X .
n=0 u1 ∈B1 ,...,uk ∈Bk n=0 u1 ∈B1 ,...,uk ∈Bk
u1 +...+uk =n u1 +...+uk =n
PROPOSITION 15D. The number of solutions of the equation (34), subject to the restrictions (35)
and (36), is given by the coefficient of X n in the formal (possible finite) power series
where, for each i = 1, . . . , k, the formal (possibly finite) power series fi (X) is given by (37).
15–10 W W L Chen : Discrete Mathematics
Example 15.6.1. The number of solutions of the equation (29), subject to the restriction (30), is given
by the coefficient of X 23 in the formal power series
f (X) = (X 1 + . . . + X 6 )3 (X 2 + . . . + X 5 )2 (X 3 + . . . + X 5 )
3 2 2 3
X − X7 X − X6 X − X6
=
1−X 1−X 1−X
= X 10 (1 − X 6 )3 (1 − X 4 )2 (1 − X 3 )(1 − X)−6 ;
where
h(X) = (1 − X 6 )3 (1 − X 4 )2 (1 − X 3 )
= (1 − 3X 6 + 3X 12 − X 18 )(1 − 2X 4 + X 8 )(1 − X 3 )
= 1 − X 3 − 2X 4 − 3X 6 + 2X 7 + X 8 + 3X 9 + 6X 10 − X 11 + 3X 12 − 6X 13
+ terms with higher powers in X.
as in Example 15.4.2.
u1 + . . . + u10 = 37,
f (X) = (X 1 + . . . + X 6 )5 (X 2 + . . . + X 8 )4 (X 5 + X 10 + X 15 + . . .)
5 2 4
X − X7 X − X9 X5
= = X 18 (1 − X 6 )5 (1 − X 7 )4 (1 − X)−9 (1 − X 5 )−1 ;
1−X 1−X 1 − X5
Chapter 15 : Number of Solutions of a Linear Equation 15–11
where
h(X) = (1 − X 6 )5 (1 − X 7 )4
= (1 − 5X 6 + 10X 12 − 10X 18 + 5X 24 − X 30 )(1 − 4X 7 + 6X 14 − 4X 21 + X 28 )
= 1 − 5X 6 − 4X 7 + 10X 12 + 20X 13 + 6X 14 − 10X 18 − 40X 19
+ terms with higher powers in X.
This is equal to
−9 −1 −9 −1 −9 −1
(−1)19 (−1)0 + (−1)14 (−1)1 + (−1)9 (−1)2
19 0 14 1 9 2
−9 −1
+ (−1)4 (−1)3
4 3
−9 −1 −9 −1 −9 −1
− 5 (−1)13 (−1)0 + (−1)8 (−1)1 + (−1)3 (−1)2
13 0 8 1 3 2
−9 −1 −9 −1 −9 −1
− 4 (−1)12 (−1)0 + (−1)7 (−1)1 + (−1)2 (−1)2
12 0 7 1 2 2
−9 −1 −9 −1
+ 10 (−1)7 (−1)0 + (−1)2 (−1)1
7 0 2 1
−9 −1 −9 −1
+ 20 (−1)6 (−1)0 + (−1)1 (−1)1
6 0 1 1
−9 −1 −9 −1
+ 6 (−1)5 (−1)0 + (−1)0 (−1)1
5 0 0 1
−9 −1
− 10 (−1)1 (−1)0
1 0
−9 −1
− 40(−1)0 (−1)0
0 0
27 22 17 12 21 16 11 20 15 10
= + + + −5 + + −4 + +
19 14 9 4 13 8 3 12 7 2
15 10 14 9 13 8 9 8
+ 10 + + 20 + +6 + − 10 − 40 .
7 2 6 1 5 0 1 0
Let us reconsider this same question by using the Inclusion-exclusion principle. In view of Proposition
15B, the problem is similar to the problem of finding the number of solutions of the equation
v1 + . . . + v10 = 19,
subject to the restrictions v1 , . . . , v5 ∈ {0, 1, 2, 3, 4, 5}, v6 , . . . , v9 ∈ {0, 1, 2, 3, 4, 5, 6} and v10 ∈ {0, 5, 10,
15, . . .}. Clearly we must have four cases: (I) v10 = 0; (II) v10 = 5; (III) v10 = 10; and (IV) v10 = 15.
The number of case (I) solutions is equal to the number of solutions of the equation
v1 + . . . + v9 = 19,
15–12 W W L Chen : Discrete Mathematics
Using the Inclusion-exclusion principle, we can show that the number of solutions is given by
27 21 20 15 14 13 9 8
−5 −4 + 10 + 20 +6 − 10 − 40 .
19 13 12 7 6 5 1 0
The number of case (II) solutions is equal to the number of solutions of the equation
v1 + . . . + v9 = 14,
The number of case (III) solutions is equal to the number of solutions of the equation
v1 + . . . + v9 = 9,
Finally, the number of case (IV) solutions is equal to the number of solutions of the equation
v1 + . . . + v9 = 4,
1. Consider the linear equation u1 + . . . + u6 = 29. Use the arguments in Sections 15.2–15.4 to solve
the following problems:
a) How many solutions satisfy u1 , . . . , u6 ∈ {0, 1, 2, 3, . . .}?
b) How many solutions satisfy u1 , . . . , u6 ∈ {0, 1, 2, 3, . . . , 7}?
c) How many solutions satisfy u1 , . . . , u6 ∈ {2, 3, . . . , 7}?
d) How many solutions satisfy u1 , u2 , u3 ∈ {1, 2, 3, . . . , 7} and u4 , u5 , u6 ∈ {2, 3, . . . , 6}?
2. Consider the linear equation u1 + . . . + u7 = 34. Use the arguments in Sections 15.2–15.4 to solve
the following problems:
a) How many solutions satisfy u1 , . . . , u7 ∈ {0, 1, 2, 3, . . .}?
b) How many solutions satisfy u1 , . . . , u7 ∈ {0, 1, 2, 3, . . . , 7}?
c) How many solutions satisfy u1 , . . . , u7 ∈ {2, 3, 4, . . . , 7}?
d) How many solutions satisfy u1 , . . . , u4 ∈ {1, 2, 3, . . . , 8} and u5 , . . . , u7 ∈ {3, 4, 5, . . . , 7}?
3. How many natural numbers x ≤ 99999999 are such that the sum of the digits in x is equal to 35?
How many of these numbers are 8-digit numbers?
Chapter 15 : Number of Solutions of a Linear Equation 15–13
5. Use generating functions to find the number of solutions of the linear equation u1 + . . . + u5 = 25
subject to the restrictions that u1 , . . . , u4 ∈ {1, 2, 3, . . . , 8} and u5 ∈ {2, 3, 13}.
6. Consider again the linear equation u1 + . . . + u7 = 34. How many solutions of this equation satisfy
u1 , . . . , u6 ∈ {1, 2, 3, . . . , 8} and u7 ∈ {2, 3, 5, 7}?