The reper­toire method

The reper­toire method of­fers an el­e­gant tech­nique for find­ing closed-form so­lu­tions to re­cur­rence re­la­tions and se­ries sums. Introduced in Chapter 1 of Concrete Mathematics (Graham et al. 1989), it tends to puz­zle new­com­ers at first glance. Yet through­out the book—es­pe­cially Chapters 1 and 2—this method proves re­mark­ably pow­er­ful for tack­ling di­verse sums and re­cur­rences. I’ll be hon­est: the tech­nique takes some ef­fort to mas­ter. In this note, I at­tempt to de­mys­tify the reper­toire method and show how to ap­ply it ef­fec­tively.

Definition

At its core, the reper­toire method seeks co­ef­fi­cients for a lin­ear com­bi­na­tion of re­lated re­cur­rences. It shines bright­est with lin­ear re­cur­rences—those whose so­lu­tions can be ex­pressed as sums of co­ef­fi­cients mul­ti­plied by func­tions of n. If you’re hunt­ing for a closed-form ex­pres­sion of a lin­ear re­cur­rence, this tech­nique de­serves a spot in your toolkit.

Concrete Mathematics does­n’t spell out the method ex­plic­itly—the au­thors con­jure up re­cur­rence sets and ex­tract co­ef­fi­cients al­most mag­i­cally, leav­ing read­ers won­der­ing how they ar­rived at them. Fortunately, Sedgewick’s Analysis of Algorithms (Sedgewick and Flajolet 1996) of­fers clearer guid­ance with sys­tem­atic ex­am­ples. I’ve dis­tilled the ap­proach from (Sedgewick and Flajolet 1996) into a three-step recipe:

  1. Relax the re­cur­rence by adding an ex­tra func­tion term.
  2. Substitute known func­tions into the re­cur­rence to de­rive iden­ti­ties sim­i­lar to the re­cur­rence.
  3. Take lin­ear com­bi­na­tions of such iden­ti­ties to de­rive an equa­tion iden­ti­cal to the re­cur­rence.

Admittedly ab­stract at first glance! Let’s ground it with an ex­am­ple. Consider a re­cur­rence of the form an=an1+stuff. We gen­er­al­ize by re­plac­ing stuff with an ar­bi­trary func­tion f(n), giv­ing us an=an1+f(n). A quick re­arrange­ment yields f(n)=anan1. From here, we build a table of ingredients”—candidate se­quences from which we can con­struct f(n). The fi­nal step de­ter­mines the co­ef­fi­cients for each in­gre­di­ent that to­gether sat­isfy both f(n) and the re­cur­rence’s base case.

For deeper in­sight, I highly rec­om­mend Markus Scheuer’s ex­cel­lent an­swer on Math StackExchange. For prac­tice, Concrete Mathematics (Graham et al. 1989) (Chapters 1, 2, and 6) pro­vides a wealth of ex­er­cises that build in­tu­ition. Additionally, Section 2.5 of (Sedgewick and Flajolet 1996) sur­veys var­i­ous closed-form tech­niques, with the reper­toire method among them—the worked ex­am­ples there are par­tic­u­larly in­struc­tive.

Nothing beats work­ing through ex­am­ples to truly in­ter­nal­ize this tech­nique.

Examples

Closed-form of sums

We can read­ily con­vert a se­ries sum into a lin­ear re­cur­rence. Let’s be­gin with a sim­ple ex­am­ple in­volv­ing n3.

Sn=k=0nk3

This sum can be seen as:

a0=0an=an1+n3

Next, we build a table of an and anan1.

an anan1
1 0
n 1
n2 2n1
n3 3n23n+1
n4 4n36n2+4n1

How do we pop­u­late the an col­umn? Since we want f(n)=n3 and we no­tice that f(n)=anan1 de­pends on the de­gree of n in an, we start with sim­ple power se­quences and com­pute their dif­fer­ences. Observe that f(n) has de­gree ex­actly one less than an. To get f(n)=n3, we’ll need an to in­clude n4. Starting sim­ply, we try n3=α(4n36n2+4n1). Setting α=14 han­dles the lead­ing term, but leaves us with resid­ual n2, n, and con­stant terms to elim­i­nate. In our sec­ond at­tempt, we in­cor­po­rate n3 and n2 into the lin­ear com­bi­na­tion:

α(4n36n2+4n1)+β(3n23n+1)+λ(2n1)=n3{6α+3β=04α3β+2λ=0α+βλ=0

The so­lu­tion is (α,β,λ)=(14,12,14), yield­ing an=αn4+βn3+λn2=14n2(n+1)2. Since a0=0 matches our base case, this is our fi­nal an­swer.

Let’s tackle an­other ex­am­ple—this time an ex­er­cise from Concrete Mathematics (Graham et al. 1989):

Sn=k=0n(1)kk2
an anan1
(1)nn2 (1)n(2n22n+1)
(1)n 2(1)n
(1)nn (1)n(2n1)

The so­lu­tion is Sn=12(1)nn(n+1)—simply add the first and last rows to­gether, then di­vide by 2 to ob­tain f(n). I con­fess that when I first en­coun­tered this sum, no ob­vi­ous can­di­date se­quences came to mind. After some ex­per­i­men­ta­tion, I dis­cov­ered that set­ting an=f(n)=(1)nn2 re­veals the un­der­ly­ing pat­terns quite nat­u­rally.

Linear Recurrences

a0=7an=an1+2n2+7n>0

Drawing from the table we built ear­lier, we can con­struct a lin­ear com­bi­na­tion for this re­cur­rence:

α(3n23n+1)+β(2n1)+λ1=2n2+7{3α=23α+2β=0αβ+λ=7

Solving yields (α,β,λ)=(23,1,223). However, our for­mula cur­rently gives a0=07, so we must add a con­stant term to sat­isfy the ini­tial con­di­tion. The closed-form so­lu­tion is an=23n3+n2+223n+7.

Exercise 1.16 (Graham et al. 1989)

g(1)=αg(2n+j)=3g(n)+γn+βj=0,1;n1

Helpful Resources

After ex­ten­sive search­ing, I’ve col­lected some re­sources that gen­uinely helped me grasp the method:

References

  • Graham, Ronald L., Donald E. Knuth, and Oren Patashnik. 1989. Concrete Mathematics: A Foundation for Computer Science. Addison-Wesley.
  • Sedgewick, Robert, and Philippe Flajolet. 1996. An Introduction to the Analysis of Algorithms. Pearson Education India.