The heart of recursion is to assume that you know previous elements of a sequence and then find a way to construct the next element in that sequence. Not only will explicit recursion problems appear of the AIME, USAMO, or USAJMO, often counting or combinatoric problems include them as well.
These notes are adapted in part from Jeffrey Chenβs Recursion in the AIME handout and the generating-functions section of the summations notes.
A recurrence relation expresses a term of a sequence in terms of earlier terms. For example,
a n = 3 a n β 1 a_n = 3a_{n-1} a n β = 3 a n β 1 β
means that every term is three times the previous one. If a 1 = 1 a_1=1 a 1 β = 1 , then
a 2 = 3 , a 3 = 9 , a 4 = 27 , a_2=3,\qquad a_3=9,\qquad a_4=27, a 2 β = 3 , a 3 β = 9 , a 4 β = 27 ,
so the sequence begins
1 , 3 , 9 , 27 , 81 , β¦ 1,3,9,27,81,\dots 1 , 3 , 9 , 27 , 81 , β¦
Because the relation holds for every valid n n n , we can repeatedly substitute backwards. For instance, if
a n = 3 a n β 1 and a n β 1 = 3 a n β 2 , a_n=3a_{n-1}
\qquad\text{and}\qquad
a_{n-1}=3a_{n-2}, a n β = 3 a n β 1 β and a n β 1 β = 3 a n β 2 β ,
then
a n = 9 a n β 2 . a_n=9a_{n-2}. a n β = 9 a n β 2 β .
In contest math, we often do not need a closed form.
Problem-solving strategy
Define a sequence clearly.
Find a recurrence.
Compute initial values.
Build a short table until you reach the term you want.
Recursion becomes especially useful when direct counting is messy but a βlast moveβ or βfinal case splitβ is easy to describe.
Example 2.1. Fred wants to climb a 10 10 10 -step staircase. He can climb either 1 1 1 or 2 2 2 steps at a time. In how many ways can he climb the staircase?
Solution. Instead of counting only the 10 10 10 -step case, define
a n = theΒ numberΒ ofΒ waysΒ toΒ climbΒ n Β stairs . a_n = \text{the number of ways to climb } n \text{ stairs}. a n β = theΒ numberΒ ofΒ waysΒ toΒ climbΒ n Β stairs .
Now think about Fredβs last move:
If his last move is a single step, then before that he had climbed n β 1 n-1 n β 1 stairs.
If his last move is a double step, then before that he had climbed n β 2 n-2 n β 2 stairs.
These are the only possibilities, so
a n = a n β 1 + a n β 2 . a_n = a_{n-1} + a_{n-2}. a n β = a n β 1 β + a n β 2 β .
The initial values are
a 1 = 1 , a 2 = 2. a_1=1,\qquad a_2=2. a 1 β = 1 , a 2 β = 2.
So the sequence begins
1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89. 1,2,3,5,8,13,21,34,55,89. 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89.
Therefore,
a 10 = 89. a_{10}=89. a 10 β = 89.
This is the Fibonacci recurrence in disguise, which appears constantly in AMC and AIME counting problems.
Example 3.1 (2007 AMC 12). Call a set of integers spacy if it contains no more than one out of any three consecutive integers. How many subsets of { 1 , 2 , 3 , β¦ , 12 } \{1,2,3,\dots,12\} { 1 , 2 , 3 , β¦ , 12 } , including the empty set, are spacy?
Solution. Let
a n = theΒ numberΒ ofΒ spacyΒ subsetsΒ ofΒ { 1 , 2 , β¦ , n } . a_n = \text{the number of spacy subsets of } \{1,2,\dots,n\}. a n β = theΒ numberΒ ofΒ spacyΒ subsetsΒ ofΒ { 1 , 2 , β¦ , n } .
Now split into two cases:
If a spacy subset contains n n n , then it cannot contain n β 1 n-1 n β 1 or n β 2 n-2 n β 2 . So the rest of the set is a spacy subset of { 1 , 2 , β¦ , n β 3 } \{1,2,\dots,n-3\} { 1 , 2 , β¦ , n β 3 } , giving a n β 3 a_{n-3} a n β 3 β possibilities.
If a spacy subset does not contain n n n , then it is just a spacy subset of { 1 , 2 , β¦ , n β 1 } \{1,2,\dots,n-1\} { 1 , 2 , β¦ , n β 1 } , giving a n β 1 a_{n-1} a n β 1 β possibilities.
Hence
a n = a n β 1 + a n β 3 . a_n=a_{n-1}+a_{n-3}. a n β = a n β 1 β + a n β 3 β .
The initial values are
a 1 = 2 , a 2 = 3 , a 3 = 4 , a_1=2,\qquad a_2=3,\qquad a_3=4, a 1 β = 2 , a 2 β = 3 , a 3 β = 4 ,
since the spacy subsets are:
for n = 1 n=1 n = 1 : β
, { 1 } \varnothing,\{1\} β
, { 1 } ,
for n = 2 n=2 n = 2 : β
, { 1 } , { 2 } \varnothing,\{1\},\{2\} β
, { 1 } , { 2 } ,
for n = 3 n=3 n = 3 : β
, { 1 } , { 2 } , { 3 } \varnothing,\{1\},\{2\},\{3\} β
, { 1 } , { 2 } , { 3 } .
Now compute forward:
a 4 = 6 , a 5 = 9 , a 6 = 13 , a 7 = 19 , a 8 = 28 , a 9 = 41 , a 10 = 60 , a 11 = 88 , a 12 = 129. \begin{aligned}
a_4&=6, & a_5&=9, & a_6&=13, \\
a_7&=19, & a_8&=28, & a_9&=41, \\
a_{10}&=60, & a_{11}&=88, & a_{12}&=129.
\end{aligned} a 4 β a 7 β a 10 β β = 6 , = 19 , = 60 , β a 5 β a 8 β a 11 β β = 9 , = 28 , = 88 , β a 6 β a 9 β a 12 β β = 13 , = 41 , = 129. β
So the answer is
129. 129. 129.
Example 3.2 (AIME 2006). A collection of eight cubes consists of one cube with edge length k k k for each integer k k k from 1 1 1 to 8 8 8 . A tower is built using all eight cubes, and the cube immediately on top of a cube with edge length k k k must have edge length at most k + 2 k+2 k + 2 . How many towers can be constructed?
Solution. Define
a n = theΒ numberΒ ofΒ validΒ towersΒ usingΒ cubesΒ 1 , 2 , β¦ , n . a_n=\text{the number of valid towers using cubes }1,2,\dots,n. a n β = theΒ numberΒ ofΒ validΒ towersΒ usingΒ cubesΒ 1 , 2 , β¦ , n .
Look at the cube of edge length n n n . In a valid tower, it can be:
at the bottom,
directly above cube n β 1 n-1 n β 1 ,
directly above cube n β 2 n-2 n β 2 .
So for each valid tower on n β 1 n-1 n β 1 cubes, there are exactly three ways to insert cube n n n . Thus
a n = 3 a n β 1 . a_n=3a_{n-1}. a n β = 3 a n β 1 β .
We begin with
a 2 = 2 , a_2=2, a 2 β = 2 ,
since either the cube of side length 1 1 1 is on the bottom and 2 2 2 is on top, or vice versa.
Then
a 8 = 3 6 β
a 2 = 3 6 β
2 = 1458. a_8 = 3^6 \cdot a_2 = 3^6 \cdot 2 = 1458. a 8 β = 3 6 β
a 2 β = 3 6 β
2 = 1458.
This is a good reminder that some recurrences only become valid after the first few terms; here the relation is not meant to be applied at n = 2 n=2 n = 2 itself.
Catalan numbers arise in many recursive counting problems where a structure splits naturally into a left part and a right part.
Example 4.1. How many paths are there from ( 0 , 0 ) (0,0) ( 0 , 0 ) to ( n , n ) (n,n) ( n , n ) using only right and up steps, such that the path never goes above the line y = x y=x y = x ?
Let
C n = theΒ numberΒ ofΒ suchΒ pathsΒ fromΒ ( 0 , 0 ) Β toΒ ( n , n ) . C_n=\text{the number of such paths from }(0,0)\text{ to }(n,n). C n β = theΒ numberΒ ofΒ suchΒ pathsΒ fromΒ ( 0 , 0 ) Β toΒ ( n , n ) .
To get a recurrence, look at the first point ( i , i ) (i,i) ( i , i ) after ( 0 , 0 ) (0,0) ( 0 , 0 ) where the path returns to the diagonal.
Then:
the initial portion of the path contributes C i β 1 C_{i-1} C i β 1 β possibilities,
the remaining portion contributes C n β i C_{n-i} C n β i β possibilities.
Summing over all possible first return points gives
C n = C 0 C n β 1 + C 1 C n β 2 + β― + C n β 1 C 0 = β i = 0 n β 1 C i C n β i β 1 . C_n = C_0C_{n-1}+C_1C_{n-2}+\cdots+C_{n-1}C_0
=\sum_{i=0}^{n-1} C_iC_{n-i-1}. C n β = C 0 β C n β 1 β + C 1 β C n β 2 β + β― + C n β 1 β C 0 β = i = 0 β n β 1 β C i β C n β i β 1 β .
For example, when n = 3 n=3 n = 3 , there are 5 5 5 such paths.
Theorem 4.2 (Catalan Numbers). The n n n th Catalan number has explicit formula
C n = 1 n + 1 ( 2 n n ) . C_n=\frac{1}{n+1}\binom{2n}{n}. C n β = n + 1 1 β ( n 2 n β ) .
We will not prove the closed form here, but it is one of the most important counting sequences in olympiad combinatorics.
Example 4.3. How many ways are there to arrange n n n open brackets and n n n closed brackets so that, reading from left to right, the number of closed brackets never exceeds the number of open brackets?
Solution. This is a Catalan-number problem.
Make the following bijection:
each open bracket corresponds to a step to the right,
each closed bracket corresponds to a step upward.
Then a bracket string with n n n opens and n n n closes becomes a path from ( 0 , 0 ) (0,0) ( 0 , 0 ) to ( n , n ) (n,n) ( n , n ) . The condition that the number of closed brackets never exceeds the number of open brackets means the path never goes above the line y = x y=x y = x .
So the answer is simply
C n = 1 n + 1 ( 2 n n ) . C_n=\frac{1}{n+1}\binom{2n}{n}. C n β = n + 1 1 β ( n 2 n β ) .
These are good recursion problems to revisit after you are comfortable with the examples above.
Exercise 5.1. How many ways are there to tile a 10 Γ 2 10 \times 2 10 Γ 2 board with 1 Γ 2 1 \times 2 1 Γ 2 dominoes?
Exercise 5.2 (AMC 12 2019). How many binary sequences of length 19 19 19 begin with 0 0 0 , end with 0 0 0 , contain no two consecutive 0 0 0 βs, and contain no three consecutive 1 1 1 βs?
Exercise 5.3 (AIME 2015). There are 2 10 = 1024 2^{10}=1024 2 10 = 1024 possible 10 10 10 -letter strings using only A A A and B B B . How many do not contain more than three adjacent identical letters?
Exercise 5.4. Given a regular 2 n 2n 2 n -gon, how many ways are there to pair vertices with nonintersecting chords?
Exercise 5.5 (AIME 2001). A mail carrier delivers mail to the nineteen houses on one side of Elm Street. No two adjacent houses receive mail on the same day, and there are never more than two consecutive houses that get no mail. How many delivery patterns are possible?
Generating functions turn linear recurrences into algebraic equations and can also help evaluate sums. This section adapts the generating-functions material from the summations handout to recurrence problems.
The basic idea is this: given a sequence a n a_n a n β , package it into the formal power series
A ( x ) = β n β₯ 0 a n x n . A(x) = \sum_{n \ge 0} a_n x^n. A ( x ) = n β₯ 0 β β a n β x n .
That lets us turn a whole sequence into one algebraic object. This is useful because:
A ( x ) A(x) A ( x ) may have a nice closed form.
The coefficients of A ( x ) A(x) A ( x ) encode the entire sequence.
Recurrence relations often turn into algebraic equations in A ( x ) A(x) A ( x ) .
Once you get a rational expression for A ( x ) A(x) A ( x ) , partial fractions can recover a closed form.
Example 5.1. Show that
β n β₯ 0 ( 1000 n ) = 2 1000 . \sum_{n \ge 0} \binom{1000}{n} = 2^{1000}. n β₯ 0 β β ( n 1000 β ) = 2 1000 .
Let a n = ( 1000 n ) a_n=\binom{1000}{n} a n β = ( n 1000 β ) . Then
A ( x ) = β n β₯ 0 a n x n = β n β₯ 0 ( 1000 n ) x n = ( 1 + x ) 1000 . A(x)=\sum_{n \ge 0} a_nx^n=\sum_{n \ge 0}\binom{1000}{n}x^n=(1+x)^{1000}. A ( x ) = n β₯ 0 β β a n β x n = n β₯ 0 β β ( n 1000 β ) x n = ( 1 + x ) 1000 .
Plugging in x = 1 x=1 x = 1 gives the identity immediately.
Example 5.2. Compute
β n β₯ 0 n ( 1000 n ) . \sum_{n \ge 0} n\binom{1000}{n}. n β₯ 0 β β n ( n 1000 β ) .
Differentiate the previous generating function:
β n β₯ 1 n ( 1000 n ) x n β 1 = 1000 ( 1 + x ) 999 . \sum_{n \ge 1} n\binom{1000}{n}x^{n-1} = 1000(1+x)^{999}. n β₯ 1 β β n ( n 1000 β ) x n β 1 = 1000 ( 1 + x ) 999 .
Now set x = 1 x=1 x = 1 :
β n β₯ 0 n ( 1000 n ) = 1000 β
2 999 . \sum_{n \ge 0} n\binom{1000}{n}=1000\cdot 2^{999}. n β₯ 0 β β n ( n 1000 β ) = 1000 β
2 999 .
Exercise 5.3. Compute
β n β₯ 0 n 2 ( 1000 n ) . \sum_{n \ge 0} n^2\binom{1000}{n}. n β₯ 0 β β n 2 ( n 1000 β ) .
Consider the Lucas numbers L n L_n L n β defined by
L 0 = 2 , L 1 = 1 , L n + 2 = L n + 1 + L n . L_0=2,\qquad L_1=1,\qquad L_{n+2}=L_{n+1}+L_n. L 0 β = 2 , L 1 β = 1 , L n + 2 β = L n + 1 β + L n β .
The first few terms are
2 , 1 , 3 , 4 , 7 , 11 , 18 , 29 , β¦ 2,1,3,4,7,11,18,29,\dots 2 , 1 , 3 , 4 , 7 , 11 , 18 , 29 , β¦
Theorem 5.4 (Closed Form for Lucas Numbers). Let
Ξ± = 1 + 5 2 , Ξ² = 1 β 5 2 . \alpha=\frac{1+\sqrt5}{2},
\qquad
\beta=\frac{1-\sqrt5}{2}. Ξ± = 2 1 + 5 β β , Ξ² = 2 1 β 5 β β .
Then
L n = Ξ± n + Ξ² n . L_n=\alpha^n+\beta^n. L n β = Ξ± n + Ξ² n .
Proof. Consider the generating function
L ( x ) = β n β₯ 0 L n x n = 2 + x + 3 x 2 + 4 x 3 + 7 x 4 + β― β . L(x)=\sum_{n \ge 0} L_nx^n = 2+x+3x^2+4x^3+7x^4+\cdots. L ( x ) = n β₯ 0 β β L n β x n = 2 + x + 3 x 2 + 4 x 3 + 7 x 4 + β― .
Now write shifted copies:
x L ( x ) = 2 x + x 2 + 3 x 3 + 4 x 4 + β― β , xL(x)=2x+x^2+3x^3+4x^4+\cdots, xL ( x ) = 2 x + x 2 + 3 x 3 + 4 x 4 + β― ,
x 2 L ( x ) = 2 x 2 + x 3 + 3 x 4 + β― β . x^2L(x)=2x^2+x^3+3x^4+\cdots. x 2 L ( x ) = 2 x 2 + x 3 + 3 x 4 + β― .
Because L n + 2 = L n + 1 + L n L_{n+2}=L_{n+1}+L_n L n + 2 β = L n + 1 β + L n β , subtracting gives
L ( x ) β x L ( x ) β x 2 L ( x ) = 2 β x . L(x)-xL(x)-x^2L(x)=2-x. L ( x ) β xL ( x ) β x 2 L ( x ) = 2 β x .
So
( 1 β x β x 2 ) L ( x ) = 2 β x , (1-x-x^2)L(x)=2-x, ( 1 β x β x 2 ) L ( x ) = 2 β x ,
hence
L ( x ) = 2 β x 1 β x β x 2 . L(x)=\frac{2-x}{1-x-x^2}. L ( x ) = 1 β x β x 2 2 β x β .
Factor the denominator:
1 β x β x 2 = ( 1 β Ξ± x ) ( 1 β Ξ² x ) . 1-x-x^2=(1-\alpha x)(1-\beta x). 1 β x β x 2 = ( 1 β Ξ± x ) ( 1 β Ξ² x ) .
Then partial fractions give
L ( x ) = 1 1 β Ξ± x + 1 1 β Ξ² x . L(x)=\frac{1}{1-\alpha x}+\frac{1}{1-\beta x}. L ( x ) = 1 β Ξ± x 1 β + 1 β Ξ² x 1 β .
Expand each as a geometric series:
L ( x ) = β n β₯ 0 ( Ξ± x ) n + β n β₯ 0 ( Ξ² x ) n = β n β₯ 0 ( Ξ± n + Ξ² n ) x n . L(x)=\sum_{n \ge 0}(\alpha x)^n + \sum_{n \ge 0}(\beta x)^n
=\sum_{n \ge 0}(\alpha^n+\beta^n)x^n. L ( x ) = n β₯ 0 β β ( Ξ± x ) n + n β₯ 0 β β ( Ξ² x ) n = n β₯ 0 β β ( Ξ± n + Ξ² n ) x n .
Matching coefficients yields
L n = Ξ± n + Ξ² n . L_n=\alpha^n+\beta^n. L n β = Ξ± n + Ξ² n .
Exercise 5.5. Derive Binetβs formula for Fibonacci numbers:
F n = 1 5 ( Ξ± n β Ξ² n ) . F_n=\frac{1}{\sqrt5}(\alpha^n-\beta^n). F n β = 5 β 1 β ( Ξ± n β Ξ² n ) .
As an intermediate step, show that the Fibonacci generating function is
x 1 β x β x 2 . \frac{x}{1-x-x^2}. 1 β x β x 2 x β .
We already know
1 1 β x = 1 + x + x 2 + β― \frac{1}{1-x}=1+x+x^2+\cdots 1 β x 1 β = 1 + x + x 2 + β―
and
( 1 + x ) n = β k β₯ 0 ( n k ) x k . (1+x)^n=\sum_{k \ge 0}\binom{n}{k}x^k. ( 1 + x ) n = k β₯ 0 β β ( k n β ) x k .
The next result gives many more useful expansions.
Theorem 5.6 (Generalized Binomial Theorem). For any real number r r r ,
( 1 + x ) r = β n β₯ 0 ( r n ) x n , (1+x)^r = \sum_{n \ge 0} \binom{r}{n}x^n, ( 1 + x ) r = n β₯ 0 β β ( n r β ) x n ,
where
( r n ) = r ( r β 1 ) β― ( r β n + 1 ) n ! . \binom{r}{n} = \frac{r(r-1)\cdots(r-n+1)}{n!}. ( n r β ) = n ! r ( r β 1 ) β― ( r β n + 1 ) β .
Proof sketch. Write
( 1 + x ) r = a 0 + a 1 x + a 2 x 2 + a 3 x 3 + β― (1+x)^r = a_0+a_1x+a_2x^2+a_3x^3+\cdots ( 1 + x ) r = a 0 β + a 1 β x + a 2 β x 2 + a 3 β x 3 + β―
and differentiate enough times to isolate the coefficient you want. For example, comparing constant terms after three derivatives gives
a 3 = r ( r β 1 ) ( r β 2 ) 3 ! . a_3=\frac{r(r-1)(r-2)}{3!}. a 3 β = 3 ! r ( r β 1 ) ( r β 2 ) β .
Important consequences:
Setting r = β 1 r=-1 r = β 1 gives
1 1 + x = β n β₯ 0 ( β x ) n . \frac{1}{1+x}=\sum_{n \ge 0}(-x)^n. 1 + x 1 β = n β₯ 0 β β ( β x ) n .
More generally,
1 ( 1 β x ) m + 1 = β k β₯ 0 ( k + m m ) x k . \frac{1}{(1-x)^{m+1}}=\sum_{k \ge 0}\binom{k+m}{m}x^k. ( 1 β x ) m + 1 1 β = k β₯ 0 β β ( m k + m β ) x k .
Also,
x m ( 1 β x ) m + 1 = β k β₯ 0 ( k m ) x k . \frac{x^m}{(1-x)^{m+1}}=\sum_{k \ge 0}\binom{k}{m}x^k. ( 1 β x ) m + 1 x m β = k β₯ 0 β β ( m k β ) x k .
A very important identity is
1 1 β 4 x = β k β₯ 0 ( 2 k k ) x k . \frac{1}{\sqrt{1-4x}}=\sum_{k \ge 0}\binom{2k}{k}x^k. 1 β 4 x β 1 β = k β₯ 0 β β ( k 2 k β ) x k .
Integrating that identity gives the Catalan generating function:
1 β 1 β 4 x 2 x = β k β₯ 0 C k x k , \frac{1-\sqrt{1-4x}}{2x}=\sum_{k \ge 0} C_kx^k, 2 x 1 β 1 β 4 x β β = k β₯ 0 β β C k β x k ,
where
C k = 1 k + 1 ( 2 k k ) . C_k=\frac{1}{k+1}\binom{2k}{k}. C k β = k + 1 1 β ( k 2 k β ) .
The exponential series is
e x = β k β₯ 0 x k k ! . e^x=\sum_{k \ge 0}\frac{x^k}{k!}. e x = k β₯ 0 β β k ! x k β .
For quick reference:
Generating function Sequence ( 1 + x ) n (1+x)^n ( 1 + x ) n β k β₯ 0 ( n k ) x k \displaystyle \sum_{k \ge 0}\binom{n}{k}x^k k β₯ 0 β β ( k n β ) x k 1 ( 1 β x ) m + 1 \dfrac{1}{(1-x)^{m+1}} ( 1 β x ) m + 1 1 β β k β₯ 0 ( k + m m ) x k \displaystyle \sum_{k \ge 0}\binom{k+m}{m}x^k k β₯ 0 β β ( m k + m β ) x k x m ( 1 β x ) m + 1 \dfrac{x^m}{(1-x)^{m+1}} ( 1 β x ) m + 1 x m β β k β₯ 0 ( k m ) x k \displaystyle \sum_{k \ge 0}\binom{k}{m}x^k k β₯ 0 β β ( m k β ) x k 1 1 β 4 x \dfrac{1}{\sqrt{1-4x}} 1 β 4 x β 1 β β k β₯ 0 ( 2 k k ) x k \displaystyle \sum_{k \ge 0}\binom{2k}{k}x^k k β₯ 0 β β ( k 2 k β ) x k 1 β 1 β 4 x 2 x \dfrac{1-\sqrt{1-4x}}{2x} 2 x 1 β 1 β 4 x β β β k β₯ 0 C k x k \displaystyle \sum_{k \ge 0} C_kx^k k β₯ 0 β β C k β x k e x e^x e x β k β₯ 0 x k k ! \displaystyle \sum_{k \ge 0}\frac{x^k}{k!} k β₯ 0 β β k ! x k β
Example 5.8 (HMMT 2007 Combinatorics #9). Let S S S be the set of triples ( i , j , k ) (i,j,k) ( i , j , k ) of positive integers satisfying i + j + k = 17 i+j+k=17 i + j + k = 17 . Compute
β ( i , j , k ) β S i j k . \sum_{(i,j,k)\in S} ijk. ( i , j , k ) β S β β ij k .
Consider
F ( x ) = ( β i β₯ 0 i x i ) ( β j β₯ 0 j x j ) ( β k β₯ 0 k x k ) . F(x)=\left(\sum_{i \ge 0} ix^i\right)\left(\sum_{j \ge 0} jx^j\right)\left(\sum_{k \ge 0} kx^k\right). F ( x ) = ( i β₯ 0 β β i x i ) ( j β₯ 0 β β j x j ) ( k β₯ 0 β β k x k ) .
We want the coefficient of x 17 x^{17} x 17 . Since
β n β₯ 0 n x n = x ( 1 β x ) 2 , \sum_{n \ge 0} nx^n = \frac{x}{(1-x)^2}, n β₯ 0 β β n x n = ( 1 β x ) 2 x β ,
we get
F ( x ) = ( x ( 1 β x ) 2 ) 3 = x 3 ( 1 β x ) 6 . F(x)=\left(\frac{x}{(1-x)^2}\right)^3 = \frac{x^3}{(1-x)^6}. F ( x ) = ( ( 1 β x ) 2 x β ) 3 = ( 1 β x ) 6 x 3 β .
So we need the coefficient of x 14 x^{14} x 14 in 1 ( 1 β x ) 6 \frac{1}{(1-x)^6} ( 1 β x ) 6 1 β , which is
( 19 5 ) . \binom{19}{5}. ( 5 19 β ) .
The βSnake Oilβ method is a systematic way to evaluate a sum depending on a free variable. Suppose
a n = β k F ( k , n ) . a_n=\sum_k F(k,n). a n β = k β β F ( k , n ) .
Problem-solving strategy
Instead of attacking a n a_n a n β directly, form the generating function A ( x ) = β n β₯ 0 a n x n = β n β₯ 0 β k F ( k , n ) x n A(x)=\sum_{n \ge 0} a_nx^n = \sum_{n \ge 0}\sum_k F(k,n)x^n A ( x ) = β n β₯ 0 β a n β x n = β n β₯ 0 β β k β F ( k , n ) x n .
Switch the order of summation to get A ( x ) = β k β n β₯ 0 F ( k , n ) x n A(x)=\sum_k \sum_{n \ge 0} F(k,n)x^n A ( x ) = β k β β n β₯ 0 β F ( k , n ) x n .
If the inner sums become recognizable generating functions, the problem becomes much easier.
Example 5.9. For n β₯ 0 n \ge 0 n β₯ 0 , compute
β k β₯ 0 ( n + k 2 k ) 2 n β k . \sum_{k \ge 0}\binom{n+k}{2k}2^{n-k}. k β₯ 0 β β ( 2 k n + k β ) 2 n β k .
Let
A ( x ) = β n β₯ 0 [ β k β₯ 0 ( n + k 2 k ) 2 n β k ] x n . A(x)=\sum_{n \ge 0}\left[\sum_{k \ge 0}\binom{n+k}{2k}2^{n-k}\right]x^n. A ( x ) = n β₯ 0 β β [ k β₯ 0 β β ( 2 k n + k β ) 2 n β k ] x n .
Then
A ( x ) = β k β₯ 0 β n β₯ 0 ( n + k 2 k ) 2 n β k x n . A(x)=\sum_{k \ge 0}\sum_{n \ge 0}\binom{n+k}{2k}2^{n-k}x^n. A ( x ) = k β₯ 0 β β n β₯ 0 β β ( 2 k n + k β ) 2 n β k x n .
After shifting indices and using
β a β₯ 0 ( a + 2 k 2 k ) ( 2 x ) a = 1 ( 1 β 2 x ) 2 k + 1 , \sum_{a \ge 0}\binom{a+2k}{2k}(2x)^a = \frac{1}{(1-2x)^{2k+1}}, a β₯ 0 β β ( 2 k a + 2 k β ) ( 2 x ) a = ( 1 β 2 x ) 2 k + 1 1 β ,
we obtain
A ( x ) = β k β₯ 0 x k 1 ( 1 β 2 x ) 2 k + 1 = 1 1 β 2 x β k β₯ 0 ( x ( 1 β 2 x ) 2 ) k . A(x)=\sum_{k \ge 0} x^k\frac{1}{(1-2x)^{2k+1}}
= \frac{1}{1-2x}\sum_{k \ge 0}\left(\frac{x}{(1-2x)^2}\right)^k. A ( x ) = k β₯ 0 β β x k ( 1 β 2 x ) 2 k + 1 1 β = 1 β 2 x 1 β k β₯ 0 β β ( ( 1 β 2 x ) 2 x β ) k .
This is geometric:
A ( x ) = 1 1 β 2 x β
1 1 β x ( 1 β 2 x ) 2 = 1 β 2 x 1 β 5 x + 4 x 2 . A(x)=\frac{1}{1-2x}\cdot \frac{1}{1-\frac{x}{(1-2x)^2}}
= \frac{1-2x}{1-5x+4x^2}. A ( x ) = 1 β 2 x 1 β β
1 β ( 1 β 2 x ) 2 x β 1 β = 1 β 5 x + 4 x 2 1 β 2 x β .
Partial fractions give
A ( x ) = 1 3 β
1 1 β x + 2 3 β
1 1 β 4 x . A(x)=\frac{1}{3}\cdot \frac{1}{1-x} + \frac{2}{3}\cdot \frac{1}{1-4x}. A ( x ) = 3 1 β β
1 β x 1 β + 3 2 β β
1 β 4 x 1 β .
Therefore
A ( x ) = β n β₯ 0 ( 1 3 + 2 3 β
4 n ) x n , A(x)=\sum_{n \ge 0}\left(\frac13+\frac23\cdot 4^n\right)x^n, A ( x ) = n β₯ 0 β β ( 3 1 β + 3 2 β β
4 n ) x n ,
so
β k β₯ 0 ( n + k 2 k ) 2 n β k = 1 3 + 2 3 β
4 n . \sum_{k \ge 0}\binom{n+k}{2k}2^{n-k}=\frac13+\frac23\cdot 4^n. k β₯ 0 β β ( 2 k n + k β ) 2 n β k = 3 1 β + 3 2 β β
4 n .
Example 5.10. For n β₯ 0 n \ge 0 n β₯ 0 , compute
β k β₯ 0 ( k n β k ) . \sum_{k \ge 0}\binom{k}{n-k}. k β₯ 0 β β ( n β k k β ) .
Again,
β n β₯ 0 [ β k β₯ 0 ( k n β k ) ] x n = β k β₯ 0 β n β₯ 0 ( k n β k ) x n . \sum_{n \ge 0}\left[\sum_{k \ge 0}\binom{k}{n-k}\right]x^n
= \sum_{k \ge 0}\sum_{n \ge 0}\binom{k}{n-k}x^n. n β₯ 0 β β [ k β₯ 0 β β ( n β k k β ) ] x n = k β₯ 0 β β n β₯ 0 β β ( n β k k β ) x n .
Rewrite using x k x^k x k :
= β k β₯ 0 x k β k β€ n β€ 2 k ( k n β k ) x n β k = β k β₯ 0 x k ( 1 + x ) k . = \sum_{k \ge 0} x^k \sum_{k \le n \le 2k}\binom{k}{n-k}x^{n-k}
= \sum_{k \ge 0} x^k(1+x)^k. = k β₯ 0 β β x k k β€ n β€ 2 k β β ( n β k k β ) x n β k = k β₯ 0 β β x k ( 1 + x ) k .
Thus
= 1 1 β x ( 1 + x ) = 1 1 β x β x 2 . = \frac{1}{1-x(1+x)}
= \frac{1}{1-x-x^2}. = 1 β x ( 1 + x ) 1 β = 1 β x β x 2 1 β .
This is the Fibonacci generating function, so the sum equals F n + 1 F_{n+1} F n + 1 β .
If the free variable appears in many places at once, Snake Oil often works better after you first generalize the identity.
Problem 5.11. Prove that for every integer n β₯ 0 n \ge 0 n β₯ 0 ,
β a + b = n ( 2 a a ) ( 2 b b ) = 4 n . \sum_{a+b=n}\binom{2a}{a}\binom{2b}{b}=4^n. a + b = n β β ( a 2 a β ) ( b 2 b β ) = 4 n .
Problem 5.12. For integers m , n β₯ 0 m,n \ge 0 m , n β₯ 0 , prove that
β a + b = m ( β 1 ) a ( n a ) ( n + b β 1 b ) = { 1 m = 0 , 0 m > 0. \sum_{a+b=m}(-1)^a \binom{n}{a}\binom{n+b-1}{b}
=
\begin{cases}
1 & m=0, \\
0 & m>0.
\end{cases} a + b = m β β ( β 1 ) a ( a n β ) ( b n + b β 1 β ) = { 1 0 β m = 0 , m > 0. β
Problem 5.13. Let m β€ n m \le n m β€ n be positive integers. Compute
β k = m n ( n k ) ( k m ) . \sum_{k=m}^{n}\binom{n}{k}\binom{k}{m}. k = m β n β ( k n β ) ( m k β ) .
Problem 5.14. For m , n β₯ 1 m,n \ge 1 m , n β₯ 1 , compute
β k β₯ 0 ( n + k m + 2 k ) ( 2 k k ) ( β 1 ) k k + 1 . \sum_{k \ge 0}\binom{n+k}{m+2k}\binom{2k}{k}\frac{(-1)^k}{k+1}. k β₯ 0 β β ( m + 2 k n + k β ) ( k 2 k β ) k + 1 ( β 1 ) k β .