Mascot image.
← MA0 2 · Introduction to Algorithms and Numerical Analysis

Lesson 2

Recurrences and Sums

.

Taught

Recurrences

A recurrence defines a quantity at one value of nn in terms of its values at smaller ones, together with enough starting values to get the definition off the ground. Counting problems produce recurrences readily, because the natural way to attack a problem of size nn is often to remove one piece and be left with a problem of the same kind and smaller size. What a recurrence does not do is answer a question quickly: getting at the millionth term by following the definition means computing the first million, and the work of this chapter is to replace such a definition by a formula that can be evaluated in one step.

The Tower of Hanoi

Édouard Lucas put the following puzzle on sale in 1883. Three pegs stand in a row, and on the first of them sit nn discs of distinct sizes, stacked largest at the bottom and smallest on top. A move lifts the top disc off one peg and drops it onto another, and it is illegal to place a disc on top of a smaller one. The object is to move the whole stack onto a different peg.

ABC
Figure 2.1. The Tower of Hanoi with four discs. No disc may ever rest on a smaller one.

Write TnT_n for the least number of legal moves that carries a stack of nn discs from one peg to another. With one disc a single move does it, so T1=1T_1 = 1. With two, the small disc goes to the spare peg, the large one to the target, and the small one on top of it: T2=3T_2 = 3. With three the shortest solution takes seven moves,

d1C,d2B,d1B,d3C,d1A,d2C,d1C,\begin{aligned} &d_1 \to C, \quad d_2 \to B, \quad d_1 \to B, \quad d_3 \to C, \\ &d_1 \to A, \quad d_2 \to C, \quad d_1 \to C, \end{aligned}

and with four it takes fifteen. The counts so far run 1,3,7,15,31,631, 3, 7, 15, 31, 63.

Proposition 2.1 (The Hanoi recurrence).

For every nNn \in \mathbb{N},

Tn=2Tn1+1,T_n = 2T_{n-1} + 1,

and T0=0T_0 = 0.

Discussion.

An equality between two counts is two inequalities, and each is argued differently. For Tn2Tn1+1T_n \leqslant 2T_{n-1} + 1 we exhibit a strategy costing that many moves and appeal to TnT_n being the least cost: shift the top n1n-1 discs to the spare peg, move the largest, shift the n1n-1 back on top of it. The two shifts are legal because the largest disc is out of the way in the first and sits below everything in the second, so neither is obstructed. For Tn2Tn1+1T_n \geqslant 2T_{n-1} + 1 we argue about an arbitrary solution rather than a chosen one, and the pivot is the largest disc: it has to move at some point, and at the first moment it moves, the other n1n-1 discs are on one peg and not on either of the two the largest disc occupies, since none of them may sit on top of it or under it in the destination. Reaching that position costs at least Tn1T_{n-1}, the move itself costs one, and rebuilding the stack afterwards costs at least Tn1T_{n-1} again.

Proof.

There are no discs to move when n=0n = 0, so T0=0T_0 = 0.

Let nNn \in \mathbb{N}. For the upper bound, carry out the following. Move the top n1n-1 discs from the source peg to the spare peg, which is possible in Tn1T_{n-1} moves and remains legal with the largest disc left in place, since that disc is larger than all of them and lies at the bottom of the source peg. Move the largest disc to the target peg: one move. Move the n1n-1 discs from the spare peg onto the target peg, again Tn1T_{n-1} moves, legal because they all land on the largest disc. That is 2Tn1+12T_{n-1} + 1 moves in all, so Tn2Tn1+1T_n \leqslant 2T_{n-1} + 1.

For the lower bound, take any legal sequence of moves carrying the stack from the source to the target. The largest disc must move at least once. Consider the first move that lifts it. Just before that move the other n1n-1 discs lie neither on the peg it leaves nor on the peg it arrives at: not the first, because they are all smaller and would have to be above it; not the second, because it may not land on a smaller disc. So all n1n-1 of them are stacked on the remaining peg, and getting them there from the source peg took at least Tn1T_{n-1} moves. After the largest disc has reached the target for the last time, the n1n-1 discs must be brought from that third peg onto it, which takes at least Tn1T_{n-1} moves more, and the moves of the largest disc themselves account for at least one. Hence Tn2Tn1+1T_n \geqslant 2T_{n-1} + 1.

Closed Forms

Computing T100T_{100} from the recurrence means computing T1T_1 through T99T_{99} first. What we want instead is a function ff with f(n)=Tnf(n) = T_n for every nn, evaluable on its own. The sequence 0,1,3,7,15,31,630, 1, 3, 7, 15, 31, 63 sits one below the powers of two, which is enough to make a guess.

Proposition 2.2 (Closed form for the Tower of Hanoi).

For every nN0n \in \mathbb{N}_0 we have Tn=2n1T_n = 2^n - 1.

Discussion.

The recurrence defines TnT_n from Tn1T_{n-1}, so a claim about all nn is proved by induction, and the induction has exactly the shape of the recurrence: one base case at n=0n = 0, and a step that rewrites TnT_n as 2Tn1+12T_{n-1} + 1, replaces Tn1T_{n-1} by the inductive hypothesis, and simplifies. Nothing has to be discovered during the proof; the formula was guessed from the first few terms, and induction only certifies it.

Proof.

For n=0n = 0 we have T0=0T_0 = 0 and 201=02^0 - 1 = 0.

Suppose Tn1=2n11T_{n-1} = 2^{n-1} - 1 for some nNn \in \mathbb{N}. By the recurrence,

Tn=2Tn1+1=2(2n11)+1=2n2+1=2n1,T_n = 2T_{n-1} + 1 = 2\bigl(2^{n-1} - 1\bigr) + 1 = 2^n - 2 + 1 = 2^n - 1,

which is the claim at nn.

Induction certifies a formula but does not produce one, and guessing from a handful of terms is not a method. Two techniques that do produce the formula follow.

Unrolling. Apply the recurrence to itself repeatedly and watch what accumulates:

Tn=2Tn1+1=2(2Tn2+1)+1=4Tn2+2+1=4(2Tn3+1)+2+1=8Tn3+4+2+1.\begin{aligned} T_n &= 2T_{n-1} + 1 \\ &= 2\bigl(2T_{n-2} + 1\bigr) + 1 = 4T_{n-2} + 2 + 1 \\ &= 4\bigl(2T_{n-3} + 1\bigr) + 2 + 1 = 8T_{n-3} + 4 + 2 + 1 . \end{aligned}

The pattern is

Tn=2kTnk+2k1+2k2++2+1=2kTnk+2k1,T_n = 2^k T_{n-k} + 2^{k-1} + 2^{k-2} + \cdots + 2 + 1 = 2^k T_{n-k} + 2^k - 1,

and one more application confirms that it reproduces itself:

2kTnk+2k1=2k(2Tnk1+1)+2k1=2k+1Tnk1+2k+11,2^k T_{n-k} + 2^k - 1 = 2^k\bigl(2T_{n-k-1} + 1\bigr) + 2^k - 1 = 2^{k+1}T_{n-k-1} + 2^{k+1} - 1,

which is the same expression with k+1k+1 in place of kk. Since the case k=1k = 1 is the recurrence itself, the displayed identity holds for every kk with 1kn1 \leqslant k \leqslant n by induction on kk. Taking k=nk = n leaves TnT_n in terms of a value we know,

Tn=2nT0+2n1=2n1.T_n = 2^n T_0 + 2^n - 1 = 2^n - 1 .

Remark (The geometric sum).

The step from 2k1++2+12^{k-1} + \cdots + 2 + 1 to 2k12^k - 1 is worth doing once. Writing S=2k1++2+1S = 2^{k-1} + \cdots + 2 + 1 and doubling gives 2S=2k+2k1++22S = 2^k + 2^{k-1} + \cdots + 2, so 2SS=2k12S - S = 2^k - 1, that is S=2k1S = 2^k - 1. The same trick evaluates 1+q++qk11 + q + \cdots + q^{k-1} as (qk1)/(q1)(q^k - 1)/(q - 1) for any q1q \neq 1.

Substitution. Rather than solve the recurrence, change the unknown so that the recurrence becomes one we can already solve. Adding 11 to both sides of Tn=2Tn1+1T_n = 2T_{n-1} + 1 gives

Tn+1=2Tn1+2=2(Tn1+1),T_n + 1 = 2T_{n-1} + 2 = 2\bigl(T_{n-1} + 1\bigr),

so if we set Un=Tn+1U_n = T_n + 1 then U0=1U_0 = 1 and Un=2Un1U_n = 2U_{n-1} for n1n \geqslant 1. That recurrence doubles at every step, so Un=2nU_n = 2^n, and therefore Tn=Un1=2n1T_n = U_n - 1 = 2^n - 1.

Problem 2.1.

Show that in the strategy of the proof of the Hanoi recurrence every disc moves at least once, and that the smallest disc moves on every second move.

Problem 2.2.

Suppose the three pegs are arranged in a row and a disc may only be moved between adjacent pegs, so that a move from the left peg to the right peg is forbidden. Let SnS_n be the least number of moves needed to transfer a stack of nn discs from the left peg to the right peg. Find a recurrence for SnS_n and solve it.

Lines in the Plane

Here is a second problem of the same shape. What is the largest number LnL_n of regions into which nn straight lines can cut the plane?

With no lines there is one region, so L0=1L_0 = 1. One line cuts the plane in two however it is drawn, so L1=2L_1 = 2. Two lines do best when they are not parallel, giving L2=4L_2 = 4. At this point 1,2,41, 2, 4 invites the guess Ln=2nL_n = 2^n, and the guess fails at once: a third line meets the two existing ones in at most two points, which divide it into at most three pieces, and each piece splits one old region in two. So the third line adds at most three regions and L3=7L_3 = 7, not 88.

1234567
Figure 2.2. Three lines, no two parallel and no three through a common point, cut the plane into seven regions.

Proposition 2.3 (The line recurrence).

For every nNn \in \mathbb{N},

Ln=Ln1+n,L_n = L_{n-1} + n,

and L0=1L_0 = 1.

Discussion.

Again the equality splits into two inequalities about the nnth line added to n1n-1 already drawn. For the upper bound, the new line gains exactly as many regions as the number of old regions it passes through, and it passes through one more region than the number of points at which it meets the old lines. Two distinct lines meet in at most one point, so the new line meets n1n-1 old lines in at most n1n-1 points and gains at most nn regions. For the lower bound we must place the new line so that both estimates are attained: not parallel to any old line, which forces it to meet each of them, and not through any existing intersection point, which keeps the n1n-1 meeting points distinct. Only finitely many directions and finitely many points have to be avoided, so such a line exists.

Proof.

With no lines drawn the plane is a single region, so L0=1L_0 = 1.

Let nNn \in \mathbb{N} and suppose n1n-1 lines have been drawn. Adding a line \ell increases the number of regions by exactly the number of old regions that \ell passes through, since each such region is cut into two and no other region is touched. The old lines meet \ell in some set of points, and those points cut \ell into one more piece than there are points, with each piece lying in one old region. Two distinct lines meet in at most one point, so \ell meets the n1n-1 old lines in at most n1n-1 points and therefore passes through at most nn old regions. Hence LnLn1+nL_n \leqslant L_{n-1} + n.

For the reverse, take n1n-1 lines realising Ln1L_{n-1} regions. The old lines have n1n-1 directions and finitely many pairwise intersection points, so we may choose \ell parallel to none of them and passing through none of those points. Then \ell meets every old line, in n1n-1 distinct points, so it passes through exactly nn old regions and adds nn new ones. Hence LnLn1+nL_n \geqslant L_{n-1} + n.

Unrolling this recurrence gives

Ln=Ln1+n=Ln2+(n1)+n=Ln3+(n2)+(n1)+n=L0+1+2++n=1+n(n+1)2,\begin{aligned} L_n &= L_{n-1} + n = L_{n-2} + (n-1) + n = L_{n-3} + (n-2) + (n-1) + n \\ &= L_0 + 1 + 2 + \cdots + n = 1 + \frac{n(n+1)}{2}, \end{aligned}

using the sum of the first nn positive integers.

Problem 2.3.

Prove by induction that Ln=1+12n(n+1)L_n = 1 + \tfrac{1}{2}n(n+1) for every nN0n \in \mathbb{N}_0.

Problem 2.4.

Prove that 1+2++n=12n(n+1)1 + 2 + \cdots + n = \tfrac{1}{2}n(n+1) for every nN0n \in \mathbb{N}_0, by pairing the first term with the last, the second with the second-last, and so on.

Problem 2.5.

What is the largest number of regions into which nn lines can cut the plane if all nn lines are required to pass through a common point?

Problem 2.6.

A zig is a bent line, made of two rays issuing from a common point. Find and solve a recurrence for the largest number of regions into which nn zigs can cut the plane.

Linear Recurrences

Guessing and unrolling both depend on the recurrence being simple enough to see through. A large family of recurrences can be solved by a recipe that needs no insight at all, and this section develops it.

How many ways are there to climb a staircase of nn steps, if each stride goes up either one step or two? For four steps there are five ways:

1,1,1,12,22,1,11,2,11,1,2\begin{aligned} &1,1,1,1 \qquad 2,2 \qquad 2,1,1 \\ &1,2,1 \qquad 1,1,2 \end{aligned}

There is one way to climb no steps, namely to do nothing, and one way to climb one step. For n2n \geqslant 2 any ascent begins with either a stride of one, leaving an ascent of n1n-1 steps, or a stride of two, leaving an ascent of n2n-2; the two cases are exclusive and exhaust the possibilities. Writing f(n)f(n) for the number of ascents of nn steps,

f(0)=1,f(1)=1,f(n)=f(n1)+f(n2)(n2).f(0) = 1, \qquad f(1) = 1, \qquad f(n) = f(n-1) + f(n-2) \quad (n \geqslant 2).

This is the Fibonacci recurrence, introduced in 1202 to model rabbit populations and unsolved in closed form for nearly six centuries. We use f(n)f(n) rather than fnf_n from here on, since the argument will shortly be something other than an integer.

Definition 2.4 (Linear recurrence).

A homogeneous linear recurrence of order dd is one of the form

f(n)=a1f(n1)+a2f(n2)++adf(nd),f(n) = a_1 f(n-1) + a_2 f(n-2) + \cdots + a_d f(n-d),

where a1,,ada_1, \ldots, a_d are constants with ad0a_d \neq 0. Values of ff prescribed at finitely many points are its boundary conditions. Adding a further term g(n)g(n) on the right, where gg is a fixed function, gives an inhomogeneous linear recurrence.

The Fibonacci recurrence has order 22 with a1=a2=1a_1 = a_2 = 1, and the boundary conditions f(0)=f(1)=1f(0) = f(1) = 1.

Theorem 2.5 (Solutions form a linear space).

Let ff and gg both satisfy the homogeneous linear recurrence with coefficients a1,,ada_1, \ldots, a_d. Then for all s,tRs, t \in \mathbb{R} the function h(n)=sf(n)+tg(n)h(n) = s f(n) + t g(n) satisfies it too.

Discussion.

The recurrence is an identity that must hold at every nn, so the proof evaluates the right-hand side of the recurrence at hh and pushes it back to h(n)h(n). Two facts do all the work, and both are about arithmetic rather than about recurrences: the right-hand side is a sum of terms each of which is a constant times a value of the function, so it distributes over the combination sf+tgsf + tg; and the hypotheses on ff and gg let each of the two resulting sums collapse to f(n)f(n) and g(n)g(n). Regrouping the terms is the whole argument, and it is why the solution set behaves like a plane through the origin rather than a scattered collection.

Proof.

Let ndn \geqslant d. Using the definition of hh, then the hypotheses on ff and gg,

a1h(n1)++adh(nd)=a1(sf(n1)+tg(n1))++ad(sf(nd)+tg(nd))=s(a1f(n1)++adf(nd))+t(a1g(n1)++adg(nd))=sf(n)+tg(n)=h(n).\begin{aligned} a_1 h(n-1) + \cdots + a_d h(n-d) &= a_1\bigl(sf(n-1) + tg(n-1)\bigr) + \cdots + a_d\bigl(sf(n-d) + tg(n-d)\bigr) \\ &= s\bigl(a_1 f(n-1) + \cdots + a_d f(n-d)\bigr) + t\bigl(a_1 g(n-1) + \cdots + a_d g(n-d)\bigr) \\ &= s f(n) + t g(n) = h(n). \end{aligned}

Linear recurrences tend to have exponential solutions, so we look for one of the form f(n)=xnf(n) = x^n and let the recurrence decide which xx will serve. Substituting into f(n)=f(n1)+f(n2)f(n) = f(n-1) + f(n-2) gives xn=xn1+xn2x^n = x^{n-1} + x^{n-2}, and dividing by xn2x^{n-2}, which is legitimate since x=0x = 0 does not satisfy the boundary conditions, leaves

x2=x+1.x^2 = x + 1 .

Its roots are

φ=1+52=1.618,φ^=152=0.618,\varphi = \frac{1 + \sqrt{5}}{2} = 1.618\ldots, \qquad \hat{\varphi} = \frac{1 - \sqrt{5}}{2} = -0.618\ldots,

so φn\varphi^n and φ^n\hat{\varphi}^n both satisfy the recurrence, and by the theorem above so does sφn+tφ^ns\varphi^n + t\hat{\varphi}^n for every ss and tt. Two constants are exactly what two boundary conditions can pin down.

Definition 2.6 (Characteristic equation).

The characteristic equation of the homogeneous linear recurrence f(n)=a1f(n1)++adf(nd)f(n) = a_1f(n-1) + \cdots + a_df(n-d) is

xd=a1xd1+a2xd2++ad1x+ad,x^d = a_1 x^{d-1} + a_2 x^{d-2} + \cdots + a_{d-1}x + a_d ,

obtained by substituting f(n)=xnf(n) = x^n and dividing by xndx^{n-d}. Its coefficients are read straight off the recurrence.

Theorem 2.7 (Binet's formula).

Let ff satisfy f(0)=f(1)=1f(0) = f(1) = 1 and f(n)=f(n1)+f(n2)f(n) = f(n-1) + f(n-2) for n2n \geqslant 2. Then for every nN0n \in \mathbb{N}_0,

f(n)=15(φn+1φ^n+1),φ=1+52,φ^=152.f(n) = \frac{1}{\sqrt{5}}\left( \varphi^{\,n+1} - \hat{\varphi}^{\,n+1} \right), \qquad \varphi = \frac{1 + \sqrt{5}}{2}, \quad \hat{\varphi} = \frac{1 - \sqrt{5}}{2}.

Discussion.

The two exponentials φn\varphi^n and φ^n\hat\varphi^n satisfy the recurrence because φ\varphi and φ^\hat\varphi solve the characteristic equation, and the previous theorem then makes every combination sφn+tφ^ns\varphi^n + t\hat\varphi^n a solution as well. What remains is to choose ss and tt so that the combination also meets the two boundary conditions, and each condition is one linear equation in the two unknowns. Solving the pair is routine once one notices that φφ^=5\varphi - \hat\varphi = \sqrt5 and 1φ^=φ1 - \hat\varphi = \varphi, which is what turns the answer into a single difference of powers. Since the recurrence and the two boundary conditions determine ff at every point, a function meeting all three is the function.

Proof.

Both φ\varphi and φ^\hat\varphi satisfy x2=x+1x^2 = x + 1, so multiplying by xn2x^{n-2} shows that φn\varphi^n and φ^n\hat\varphi^n satisfy the recurrence; by the previous theorem so does h(n)=sφn+tφ^nh(n) = s\varphi^n + t\hat\varphi^n for any reals s,ts, t.

The boundary conditions require h(0)=1h(0) = 1 and h(1)=1h(1) = 1, that is

s+t=1,sφ+tφ^=1.s + t = 1, \qquad s\varphi + t\hat\varphi = 1 .

Substituting t=1st = 1 - s into the second gives s(φφ^)=1φ^s(\varphi - \hat\varphi) = 1 - \hat\varphi. Now φφ^=5\varphi - \hat\varphi = \sqrt5 and 1φ^=12(1+5)=φ1 - \hat\varphi = \tfrac{1}{2}(1 + \sqrt5) = \varphi, so s=φ/5s = \varphi/\sqrt5; and then t=1φ/5=(5φ)/5=φ^/5t = 1 - \varphi/\sqrt5 = (\sqrt5 - \varphi)/\sqrt5 = -\hat\varphi/\sqrt5, since 5φ=12(51)=φ^\sqrt5 - \varphi = \tfrac{1}{2}(\sqrt5 - 1) = -\hat\varphi. Therefore

h(n)=φ5φnφ^5φ^n=15(φn+1φ^n+1).h(n) = \frac{\varphi}{\sqrt5}\varphi^n - \frac{\hat\varphi}{\sqrt5}\hat\varphi^n = \frac{1}{\sqrt5}\left(\varphi^{\,n+1} - \hat\varphi^{\,n+1}\right).

The recurrence together with the values at 00 and 11 determines f(n)f(n) for every nn, and hh satisfies all three, so f=hf = h.

Remark (Integers out of square roots).

Every value of ff is a whole number, yet the formula is built entirely from 5\sqrt5; the irrational parts cancel at every nn. Since φ^<1|\hat\varphi| < 1 the second term is smaller than 12\tfrac12 in absolute value at every nn, so f(n)f(n) is the nearest integer to φn+1/5\varphi^{\,n+1}/\sqrt5 throughout. For instance φ20/5=6765.000029\varphi^{20}/\sqrt5 = 6765.000029\ldots, and f(19)=6765f(19) = 6765. The same estimate shows that consecutive values have ratio tending to φ\varphi, the golden ratio.

Example 2.8 (A recurrence of order two).

Let f(0)=0f(0) = 0, f(1)=1f(1) = 1 and f(n)=5f(n1)6f(n2)f(n) = 5f(n-1) - 6f(n-2) for n2n \geqslant 2. The characteristic equation is x2=5x6x^2 = 5x - 6, that is (x2)(x3)=0(x-2)(x-3) = 0, with roots 22 and 33. So f(n)=s2n+t3nf(n) = s\,2^n + t\,3^n, and the boundary conditions give s+t=0s + t = 0 and 2s+3t=12s + 3t = 1, whence t=1t = 1 and s=1s = -1. Therefore f(n)=3n2nf(n) = 3^n - 2^n.

When the characteristic equation has a repeated root, the powers of that root alone do not supply enough independent solutions, and the missing ones carry a factor of nn.

Proposition 2.9 (Repeated roots).

Let r0r \neq 0 be a root of multiplicity at least 22 of the characteristic equation of a homogeneous linear recurrence. Then f(n)=nrnf(n) = n r^n satisfies the recurrence.

Discussion.

Saying that rr is a root of multiplicity at least two means that the characteristic polynomial and its derivative both vanish at rr, and the factor of nn in the claimed solution is exactly what a derivative produces from a power. So the proof multiplies the characteristic polynomial by xndx^{n-d} to obtain a polynomial whose vanishing at rr is the statement that rnr^n solves the recurrence, differentiates it, and multiplies by xx; the result, evaluated at rr, is precisely the statement that nrnnr^n solves the recurrence. The hypothesis r0r \neq 0 is what lets the multiplicity survive the multiplication by xndx^{n-d}.

Proof.

Write p(x)=xda1xd1adp(x) = x^d - a_1x^{d-1} - \cdots - a_d for the characteristic polynomial and fix ndn \geqslant d. Put

q(x)=xndp(x)=xna1xn1adxnd.q(x) = x^{n-d}p(x) = x^n - a_1x^{n-1} - \cdots - a_d x^{n-d} .

Since r0r \neq 0 is a root of pp of multiplicity at least 22, it is a root of qq of multiplicity at least 22, so q(r)=0q(r) = 0 and q(r)=0q'(r) = 0. Differentiating,

q(x)=nxn1a1(n1)xn2ad(nd)xnd1,q'(x) = n x^{n-1} - a_1(n-1)x^{n-2} - \cdots - a_d(n-d)x^{n-d-1},

and multiplying by xx,

xq(x)=nxna1(n1)xn1ad(nd)xnd.x\,q'(x) = n x^{n} - a_1(n-1)x^{n-1} - \cdots - a_d(n-d)x^{n-d} .

Evaluating at x=rx = r and using q(r)=0q'(r) = 0 gives

nrn=a1(n1)rn1++ad(nd)rnd,n r^n = a_1 (n-1) r^{n-1} + \cdots + a_d (n-d) r^{n-d},

which says exactly that f(n)=nrnf(n) = nr^n satisfies the recurrence.

More generally, a root rr of multiplicity kk contributes the kk solutions rnr^n, nrnnr^n, n2rnn^2r^n, up to nk1rnn^{k-1}r^n, and a recurrence of order dd is solved by taking a linear combination of the dd solutions collected in this way from all the roots. If the characteristic equation of an order-four recurrence has roots ss, tt and uu twice, the general solution is

f(n)=asn+btn+cun+dnun,f(n) = a\,s^n + b\,t^n + c\,u^n + d\,n\,u^n,

and four boundary conditions give four linear equations in a,b,c,da, b, c, d.

Inhomogeneous Recurrences

The Hanoi recurrence f(n)=2f(n1)+1f(n) = 2f(n-1) + 1 is not homogeneous: the extra 11 is a term g(n)g(n) on the right. Such recurrences are solved in five steps.

  1. Delete g(n)g(n) and find the roots of the characteristic equation of what is left.
  2. Write down the general solution of that homogeneous recurrence, leaving its constants undetermined. This is the homogeneous solution.
  3. Restore g(n)g(n) and find any one function satisfying the full recurrence, ignoring the boundary conditions. This is a particular solution.
  4. Add the two. This is the general solution.
  5. Use the boundary conditions to fix the constants.

Example 2.10 (Hanoi with heavy discs).

Suppose moving a disc costs its size in seconds, so that moving the nnth disc takes nn seconds rather than one. The total time obeys

f(1)=1,f(n)=2f(n1)+n(n2).f(1) = 1, \qquad f(n) = 2f(n-1) + n \quad (n \geqslant 2).

Deleting the nn leaves f(n)=2f(n1)f(n) = 2f(n-1), whose characteristic equation is x=2x = 2, so the homogeneous solution is c2nc\,2^n.

For a particular solution, g(n)=ng(n) = n is a polynomial of degree one, so try f(n)=an+bf(n) = an + b. Substituting,

an+b=2(a(n1)+b)+n0=(a+1)n+(b2a),an + b = 2\bigl(a(n-1) + b\bigr) + n \quad\Longleftrightarrow\quad 0 = (a+1)n + (b - 2a),

which holds for every nn exactly when a=1a = -1 and b=2b = -2. So n2-n-2 is a particular solution and the general solution is f(n)=c2nn2f(n) = c\,2^n - n - 2.

The boundary condition f(1)=1f(1) = 1 gives 2c3=12c - 3 = 1, so c=2c = 2 and

f(n)=2n+1n2.f(n) = 2^{\,n+1} - n - 2 .

Against 2n12^n - 1 for the original puzzle, the heavy discs cost roughly twice as long.

Remark (Guessing a particular solution).

Finding a particular solution is the one step that involves a guess, and the guess is usually shaped like g(n)g(n) itself.

If g(n)g(n) is constant, try f(n)=cf(n) = c; if that fails, try bn+cbn + c, then an2+bn+can^2 + bn + c, and so on. If g(n)g(n) is a polynomial, try a polynomial of the same degree first and then of higher degree. If g(n)g(n) is an exponential such as 3n3^n, try f(n)=c3nf(n) = c\,3^n, then bn3n+c3nbn3^n + c3^n, and so on. A guess fails when substituting it leaves an equation with no constant solution, and raising the degree by one is then the next move.

Problem 2.7.

Solve f(0)=0f(0) = 0, f(1)=1f(1) = 1, f(n)=4f(n1)4f(n2)f(n) = 4f(n-1) - 4f(n-2) for n2n \geqslant 2. (The characteristic equation has a repeated root.)

Problem 2.8.

Solve f(0)=1f(0) = 1 and f(n)=3f(n1)+2nf(n) = 3f(n-1) + 2^n for n1n \geqslant 1.

Problem 2.9.

Let rr be a root of multiplicity at least 33 of the characteristic equation of a homogeneous linear recurrence, with r0r \neq 0. Prove that n2rnn^2 r^n satisfies the recurrence.

Problem 2.10.

How many ways are there to climb nn stairs if a stride may go up one, two or three steps? Write down the recurrence, its characteristic equation, and compute the number of ways for n6n \leqslant 6.

Problem 2.11.

Let ff satisfy the Fibonacci recurrence with f(0)=f(1)=1f(0) = f(1) = 1. Prove that f(n)f(n) is the nearest integer to φn+1/5\varphi^{\,n+1}/\sqrt{5} for every n1n \geqslant 1.

The Josephus Problem

Flavius Josephus, a first-century historian, was said to have been trapped in a cave with forty-one other rebels who preferred death to capture and agreed to stand in a circle and kill every third man. Josephus worked out where to stand.

The version we take is this. Number nn people 11 to nn around a circle and go round eliminating every second person until one is left. Which number survives? Call it J(n)J(n).

12346789105
Figure 2.3. Ten people in a circle. Eliminating every second one leaves number 55, so J(10)=5J(10) = 5.

Proposition 2.11 (The Josephus recurrence).

For every N\ell \in \mathbb{N},

J(2)=2J()1,J(2+1)=2J()+1,J(2\ell) = 2J(\ell) - 1, \qquad J(2\ell + 1) = 2J(\ell) + 1,

and J(1)=1J(1) = 1.

Discussion.

One person survives trivially. For the rest, the point is that after one lap of the circle exactly the even-numbered people have gone, and what is left is a circle of half the size with the same rule about to be applied to it. So the problem of size nn reduces to the problem of size n/2\lfloor n/2 \rfloor, and all that is needed is the dictionary between the numbering of the survivors and their original numbers. The two cases differ only in where the second lap starts. If nn is even the lap ends by killing person nn and the next to die is the second of the survivors; if nn is odd the lap ends by killing person n1n-1, then person 11 dies immediately, and the survivors start from person 33. Reading off the kkth survivor’s original number in each case, 2k12k-1 and 2k+12k+1, converts J()J(\ell) into J(n)J(n).

Proof.

With one person there is nobody to eliminate, so J(1)=1J(1) = 1.

Suppose n=2n = 2\ell with N\ell \in \mathbb{N}. Going round once eliminates 2,4,,22, 4, \ldots, 2\ell and leaves the \ell odd-numbered people 1,3,,211, 3, \ldots, 2\ell - 1, with the next elimination falling on the second of them. So what remains is the same problem for \ell people, counted from 11, and the kkth of those people carries the original number 2k12k - 1. The survivor is the J()J(\ell)th of them, so its original number is 2J()12J(\ell) - 1.

Suppose instead n=2+1n = 2\ell + 1 with N\ell \in \mathbb{N}. Going round once eliminates 2,4,,22, 4, \ldots, 2\ell; the count then passes from 2+12\ell+1 to 11, which is eliminated next. That leaves the \ell people 3,5,,2+13, 5, \ldots, 2\ell + 1, with the next elimination falling on the second of them. Again this is the problem for \ell people, and the kkth of them carries the original number 2k+12k + 1. The survivor is therefore numbered 2J()+12J(\ell) + 1.

Tabulating the first sixteen values, grouped by powers of two, makes the pattern plain:

n12345678910111213141516J(n)1131357135791113151\begin{array}{c|cc|cccc|cccccccc|c} n & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\ \hline J(n) & 1 & 1 & 3 & 1 & 3 & 5 & 7 & 1 & 3 & 5 & 7 & 9 & 11 & 13 & 15 & 1 \end{array}

Each block begins at 11 when nn reaches a power of two and climbs through the odd numbers. That suggests measuring nn from the power of two below it.

Theorem 2.12 (Closed form for the Josephus problem).

Let nNn \in \mathbb{N} and write n=2m+rn = 2^m + r where 2m2^m is the largest power of two with 2mn2^m \leqslant n, so that m0m \geqslant 0 and 0r<2m0 \leqslant r < 2^m. Then

J(n)=2r+1.J(n) = 2r + 1 .

Discussion.

The recurrence takes nn to n/2\lfloor n/2 \rfloor, so the proof is an induction in which the inductive hypothesis is applied at a smaller value rather than at the immediate predecessor; strong induction on nn is what fits. Everything then turns on how the decomposition n=2m+rn = 2^m + r behaves under halving. If nn is even then rr is even too, since r=n2mr = n - 2^m and m1m \geqslant 1, and halving nn gives 2m1+r/22^{m-1} + r/2 with the remainder still in range. If nn is odd then rr is odd, and n/2=2m1+(r1)/2\lfloor n/2 \rfloor = 2^{m-1} + (r-1)/2, again in range. In both cases the hypothesis supplies the survivor for the halved circle, and the two clauses of the recurrence turn it into 2r+12r+1; the arithmetic works out to the same answer either way, which is why the formula has no cases in it.

Proof.

We induct on nn, assuming the claim for all smaller values.

If n=1n = 1 then m=0m = 0 and r=0r = 0, and J(1)=1=20+1J(1) = 1 = 2 \cdot 0 + 1.

Let n2n \geqslant 2 and write n=2m+rn = 2^m + r with 0r<2m0 \leqslant r < 2^m; since n2n \geqslant 2 we have m1m \geqslant 1.

Suppose nn is even, say n=2n = 2\ell. Then r=n2mr = n - 2^m is even, and

=n2=2m1+r2,0r2<2m1,\ell = \frac{n}{2} = 2^{m-1} + \frac{r}{2}, \qquad 0 \leqslant \frac{r}{2} < 2^{m-1},

so the decomposition of \ell has exponent m1m-1 and remainder r/2r/2. As <n\ell < n, the inductive hypothesis gives J()=2(r/2)+1=r+1J(\ell) = 2(r/2) + 1 = r + 1, and the recurrence gives

J(n)=2J()1=2(r+1)1=2r+1.J(n) = 2J(\ell) - 1 = 2(r+1) - 1 = 2r + 1 .

Suppose instead nn is odd, say n=2+1n = 2\ell + 1 with 1\ell \geqslant 1. Then r=n2mr = n - 2^m is odd, and

=n12=2m1+r12,0r12<2m1,\ell = \frac{n-1}{2} = 2^{m-1} + \frac{r-1}{2}, \qquad 0 \leqslant \frac{r-1}{2} < 2^{m-1},

the upper bound because r<2mr < 2^m forces r1<2m1r - 1 < 2^m - 1 and hence (r1)/2<2m1(r-1)/2 < 2^{m-1}. The inductive hypothesis gives J()=2r12+1=rJ(\ell) = 2\cdot\frac{r-1}{2} + 1 = r, and the recurrence gives

J(n)=2J()+1=2r+1.J(n) = 2J(\ell) + 1 = 2r + 1 .

Reading the Answer in Binary

The decomposition n=2m+rn = 2^m + r is exactly what binary notation records. Writing

n=(1bm1bm2b1b0)2n = (1\,b_{m-1}\,b_{m-2}\cdots b_1\,b_0)_2

with leading digit 11, the remainder is r=(0bm1b1b0)2r = (0\,b_{m-1}\cdots b_1\,b_0)_2, so 2r=(bm1b1b00)22r = (b_{m-1}\cdots b_1\,b_0\,0)_2 and

J(n)=2r+1=(bm1bm2b1b01)2.J(n) = 2r + 1 = (b_{m-1}\,b_{m-2}\cdots b_1\,b_0\,1)_2 .

Since the leading digit that was dropped is a 11, the answer is obtained from nn by moving its leading digit to the end: a one-bit cyclic shift to the left.

Example 2.13 (A cyclic shift).

Take n=100=(1100100)2n = 100 = (1100100)_2. Shifting the leading digit round to the end gives (1001001)2=73(1001001)_2 = 73, so J(100)=73J(100) = 73. Checking against the closed form, 100=64+36100 = 64 + 36, so r=36r = 36 and 2r+1=732r + 1 = 73.

Remark (Iterating the shift).

Applying JJ repeatedly does not cycle back to nn after m+1m+1 shifts, because J(n)nJ(n) \leqslant n always, and once a value drops it can never climb again. What happens instead is that whenever the leading digit is a 00 it is simply dropped, so each application deletes a zero. After enough applications only the ones remain, and the value settles at

(111ν(n))2=2ν(n)1,(\underbrace{11\cdots1}_{\nu(n)})_2 = 2^{\nu(n)} - 1,

where ν(n)\nu(n) is the number of ones in the binary representation of nn. For instance J(11)=J((1011)2)=(111)2=7J(11) = J((1011)_2) = (111)_2 = 7, and J(7)=7J(7) = 7.

Proposition 2.14 (When the survivor is halfway round).

Let n=2m+rn = 2^m + r with 0r<2m0 \leqslant r < 2^m. Then J(n)=n/2J(n) = n/2 if and only if mm is odd and r=(2m2)/3r = (2^m - 2)/3.

Discussion.

Substituting the closed form turns the condition J(n)=n/2J(n) = n/2 into a linear equation in rr and 2m2^m, and solving it gives r=(2m2)/3r = (2^m-2)/3 outright, so the only question left is for which mm that number is an integer lying below 2m2^m. The bound is immediate. Integrality is a statement about 2m2^m modulo 33, and the powers of two alternate between 11 and 22 there, since doubling exchanges the two; so 2m22^m - 2 is divisible by 33 exactly for odd mm.

Proof.

By the closed form, J(n)=n/2J(n) = n/2 says 2r+1=(2m+r)/22r + 1 = (2^m + r)/2, that is 4r+2=2m+r4r + 2 = 2^m + r, that is

3r=2m2,sor=2m23.3r = 2^m - 2, \qquad\text{so}\qquad r = \frac{2^m - 2}{3}.

This rr satisfies r<2mr < 2^m automatically. It is an integer exactly when 2m2(mod3)2^m \equiv 2 \pmod 3. Now 20=12^0 = 1 leaves remainder 11, and doubling a number that leaves remainder 11 gives one that leaves remainder 22, while doubling a number that leaves remainder 22 gives 44, which leaves remainder 11. So the remainders alternate 1,2,1,2,1, 2, 1, 2, \ldots as m=0,1,2,3,m = 0, 1, 2, 3, \ldots, and 2m22^m \equiv 2 exactly when mm is odd.

The first few such nn are

mrn=2m+rJ(n)=n/2n in binary10211032105101051042211010107421708510101010\begin{array}{c|c|c|c|c} m & r & n = 2^m + r & J(n) = n/2 & n \text{ in binary} \\ \hline 1 & 0 & 2 & 1 & 10 \\ 3 & 2 & 10 & 5 & 1010 \\ 5 & 10 & 42 & 21 & 101010 \\ 7 & 42 & 170 & 85 & 10101010 \end{array}

These are the nn for which shifting the leading bit to the end has the same effect as deleting the last bit.

The Repertoire Method

Guessing worked for the Josephus recurrence because its answers were small numbers with a visible pattern. When a guess is not available, the following method manufactures one. Consider the recurrence with three undetermined constants,

f(n)={α,n=1,2f()+β,n=2,  N,2f()+γ,n=2+1,  N,f(n) = \begin{cases} \alpha, & n = 1, \\ 2f(\ell) + \beta, & n = 2\ell, \; \ell \in \mathbb{N}, \\ 2f(\ell) + \gamma, & n = 2\ell + 1, \; \ell \in \mathbb{N}, \end{cases}

of which the Josephus recurrence is the case α=1\alpha = 1, β=1\beta = -1, γ=1\gamma = 1. Its first few values are

nf(n)1α22α+β32α+γ44α+3β54α+2β+γ64α+β+2γ74α+3γ88α+7β98α+6β+γ\begin{array}{c|l} n & f(n) \\ \hline 1 & \alpha \\ 2 & 2\alpha + \beta \\ 3 & 2\alpha + \gamma \\ 4 & 4\alpha + 3\beta \\ 5 & 4\alpha + 2\beta + \gamma \\ 6 & 4\alpha + \beta + 2\gamma \\ 7 & 4\alpha + 3\gamma \\ 8 & 8\alpha + 7\beta \\ 9 & 8\alpha + 6\beta + \gamma \end{array}

Every entry is a combination of α\alpha, β\beta and γ\gamma with coefficients depending only on nn, so we may write

f(n)=A(n)α+B(n)β+C(n)γ,f(n) = A(n)\,\alpha + B(n)\,\beta + C(n)\,\gamma ,

and the task becomes finding the three functions AA, BB, CC. The method is to substitute values of α,β,γ\alpha, \beta, \gamma, or functions ff, for which the recurrence can be solved by inspection; each substitution yields one equation relating AA, BB and CC, and three independent equations determine them.

Proposition 2.15 (The coefficient of α\alpha).

Let n=2m+rn = 2^m + r with 0r<2m0 \leqslant r < 2^m. Then A(n)=2mA(n) = 2^m.

Discussion.

Setting α=1\alpha = 1 and β=γ=0\beta = \gamma = 0 makes f(n)f(n) equal to A(n)A(n) and collapses the recurrence to A(1)=1A(1) = 1 with A(n)=2A(n/2)A(n) = 2A(\lfloor n/2 \rfloor) in both the even and the odd case. That recurrence doubles once per halving and never distinguishes the two cases, so it depends on nn only through how often nn can be halved, which is mm. The induction is the same strong induction as before, using that n/2\lfloor n/2 \rfloor has exponent m1m - 1 in its own decomposition.

Proof.

Putting α=1\alpha = 1 and β=γ=0\beta = \gamma = 0 gives f=Af = A and

A(1)=1,A(2)=2A(),A(2+1)=2A().A(1) = 1, \qquad A(2\ell) = 2A(\ell), \qquad A(2\ell+1) = 2A(\ell) .

We induct on nn. For n=1n = 1 we have m=0m = 0 and A(1)=1=20A(1) = 1 = 2^0. For n2n \geqslant 2 write n=2m+rn = 2^m + r with m1m \geqslant 1, and put =n/2\ell = \lfloor n/2 \rfloor. As in the proof of the closed form for JJ, the decomposition of \ell has exponent m1m-1, whichever parity nn has. Both clauses of the recurrence give A(n)=2A()A(n) = 2A(\ell), and the inductive hypothesis gives A()=2m1A(\ell) = 2^{m-1}, so A(n)=2mA(n) = 2^m.

Two more substitutions finish the job, and this time we choose the function rather than the constants.

Take f(n)=1f(n) = 1 for every nn. The three clauses become 1=α1 = \alpha, 1=2+β1 = 2 + \beta and 1=2+γ1 = 2 + \gamma, so this constant function is the solution for α=1\alpha = 1, β=γ=1\beta = \gamma = -1. Substituting those values into f(n)=A(n)α+B(n)β+C(n)γf(n) = A(n)\alpha + B(n)\beta + C(n)\gamma gives

1=A(n)B(n)C(n).1 = A(n) - B(n) - C(n) .

Take f(n)=nf(n) = n. The clauses become 1=α1 = \alpha, 2=2+β2\ell = 2\ell + \beta and 2+1=2+γ2\ell + 1 = 2\ell + \gamma, so this is the solution for α=1\alpha = 1, β=0\beta = 0, γ=1\gamma = 1, and

n=A(n)+C(n).n = A(n) + C(n) .

Now solve. From A(n)=2mA(n) = 2^m and A(n)+C(n)=n=2m+rA(n) + C(n) = n = 2^m + r we get C(n)=rC(n) = r; and then B(n)=A(n)C(n)1=2m1rB(n) = A(n) - C(n) - 1 = 2^m - 1 - r.

Theorem 2.16 (Solution of the generalised Josephus recurrence).

Let α,β,γ\alpha, \beta, \gamma be constants and let ff satisfy the recurrence above. Then for n=2m+rn = 2^m + r with 0r<2m0 \leqslant r < 2^m,

f(n)=2mα+(2m1r)β+rγ.f(n) = 2^m \alpha + \bigl(2^m - 1 - r\bigr)\beta + r\gamma .

Discussion.

The repertoire method produced this formula but did not prove it, since it assumed at the outset that f(n)f(n) is a combination of α\alpha, β\beta and γ\gamma with coefficients independent of them. That assumption is easy to justify after the fact: the right-hand side is a specific function of nn, so it is enough to check that it satisfies the three clauses of the recurrence, and a solution of the recurrence is unique because the clauses determine f(n)f(n) from f(n/2)f(\lfloor n/2 \rfloor) and f(1)f(1) is given. The verification is the same case split on the parity of nn used twice already, with the decomposition of n/2\lfloor n/2 \rfloor read off as before.

Proof.

Write F(2m+r)=2mα+(2m1r)β+rγF(2^m + r) = 2^m\alpha + (2^m - 1 - r)\beta + r\gamma for 0r<2m0 \leqslant r < 2^m. Since the clauses determine f(n)f(n) from f(n/2)f(\lfloor n/2\rfloor) for n2n \geqslant 2 and fix f(1)f(1), at most one function satisfies them; so it suffices to check that FF does.

At n=1n = 1 we have m=r=0m = r = 0 and F(1)=αF(1) = \alpha.

Let n=22n = 2\ell \geqslant 2, so m1m \geqslant 1 and rr is even, and =2m1+r/2\ell = 2^{m-1} + r/2 with 0r/2<2m10 \leqslant r/2 < 2^{m-1}. Then

2F()+β=2[2m1α+(2m11r2)β+r2γ]+β=2mα+(2m2r+1)β+rγ,2F(\ell) + \beta = 2\left[2^{m-1}\alpha + \left(2^{m-1} - 1 - \tfrac{r}{2}\right)\beta + \tfrac{r}{2}\gamma\right] + \beta = 2^m\alpha + \bigl(2^m - 2 - r + 1\bigr)\beta + r\gamma,

which is F(n)F(n).

Let n=2+13n = 2\ell + 1 \geqslant 3, so m1m \geqslant 1 and rr is odd, and =2m1+(r1)/2\ell = 2^{m-1} + (r-1)/2 with 0(r1)/2<2m10 \leqslant (r-1)/2 < 2^{m-1}. Then

2F()+γ=2[2m1α+(2m11r12)β+r12γ]+γ=2mα+(2m1r)β+rγ,2F(\ell) + \gamma = 2\left[2^{m-1}\alpha + \left(2^{m-1} - 1 - \tfrac{r-1}{2}\right)\beta + \tfrac{r-1}{2}\gamma\right] + \gamma = 2^m\alpha + \bigl(2^m - 1 - r\bigr)\beta + r\gamma,

which is F(n)F(n) again.

Setting α=1\alpha = 1, β=1\beta = -1, γ=1\gamma = 1 recovers 2m(2m1r)+r=2r+12^m - (2^m - 1 - r) + r = 2r + 1, the Josephus answer.

Radix Notation

The generalised recurrence has a shorter description if the two constants added at each step are indexed by the bit that decides between them. Write β0=β\beta_0 = \beta and β1=γ\beta_1 = \gamma; then the three clauses become

f(1)=α,f(2+j)=2f()+βj(j{0,1}),f(1) = \alpha, \qquad f(2\ell + j) = 2f(\ell) + \beta_j \quad (j \in \{0, 1\}),

and jj is the last binary digit of nn. Unrolling the second clause strips one digit at a time:

f((1bm1b1b0)2)=2f((1bm1b1)2)+βb0=4f((1bm1b2)2)+2βb1+βb0    =2mα+2m1βbm1++2βb1+βb0.\begin{aligned} f\bigl((1\,b_{m-1}\cdots b_1 b_0)_2\bigr) &= 2 f\bigl((1\,b_{m-1}\cdots b_1)_2\bigr) + \beta_{b_0} \\ &= 4 f\bigl((1\,b_{m-1}\cdots b_2)_2\bigr) + 2\beta_{b_1} + \beta_{b_0} \\ &\;\;\vdots \\ &= 2^m \alpha + 2^{m-1}\beta_{b_{m-1}} + \cdots + 2\beta_{b_1} + \beta_{b_0} . \end{aligned}

The right-hand side has the shape of a binary expansion whose digits are the constants rather than 00 and 11, so we write it

f(n)=(α  βbm1  βbm2βb1  βb0)2,f(n) = \bigl(\alpha\;\beta_{b_{m-1}}\;\beta_{b_{m-2}}\cdots\beta_{b_1}\;\beta_{b_0}\bigr)_2 ,

meaning that each entry is multiplied by the appropriate power of two and the results added. Recovering the earlier table is a matter of reading off digits: 6=(110)26 = (110)_2 gives 22α+2γ+β2^2\alpha + 2\gamma + \beta, and 9=(1001)29 = (1001)_2 gives 23α+22β+2β+γ2^3\alpha + 2^2\beta + 2\beta + \gamma.

Example 2.17 (The Josephus survivor for n=100n = 100).

With α=1\alpha = 1, β0=1\beta_0 = -1 and β1=1\beta_1 = 1, and 100=(1100100)2100 = (1100100)_2,

J(100)=26(1)+25(1)+24(1)+23(1)+22(1)+2(1)+(1)=64+32168+421=73,\begin{aligned} J(100) &= 2^6(1) + 2^5(1) + 2^4(-1) + 2^3(-1) + 2^2(1) + 2(-1) + (-1) \\ &= 64 + 32 - 16 - 8 + 4 - 2 - 1 = 73 , \end{aligned}

agreeing with the cyclic shift (1100100)2(1001001)2(1100100)_2 \mapsto (1001001)_2.

Nothing in the argument used the base 22 or the multiplier 22 separately, and separating them gives the general statement.

Theorem 2.18 (Recurrences that strip a digit).

Let d2d \geqslant 2 and cc be constants, let α1,,αd1\alpha_1, \ldots, \alpha_{d-1} and β0,,βd1\beta_0, \ldots, \beta_{d-1} be constants, and let ff satisfy

f(i)=αi(1id1),f(dn+j)=cf(n)+βj(n1,  0j<d).f(i) = \alpha_i \quad (1 \leqslant i \leqslant d-1), \qquad f(dn + j) = c\,f(n) + \beta_j \quad (n \geqslant 1, \; 0 \leqslant j < d).

Then for n=(bmbm1b1b0)dn = (b_m\,b_{m-1}\cdots b_1\,b_0)_d with bm0b_m \neq 0,

f(n)=(αbm  βbm1βb1  βb0)c=cmαbm+cm1βbm1++cβb1+βb0.f(n) = \bigl(\alpha_{b_m}\;\beta_{b_{m-1}}\cdots\beta_{b_1}\;\beta_{b_0}\bigr)_c = c^m \alpha_{b_m} + c^{m-1}\beta_{b_{m-1}} + \cdots + c\,\beta_{b_1} + \beta_{b_0}.

Discussion.

The second clause consumes exactly one base-dd digit of its argument, because writing n=dn+jn = dn' + j with 0j<d0 \leqslant j < d is the same as splitting off the last digit b0=jb_0 = j and leaving n=(bmb1)dn' = (b_m \cdots b_1)_d. So each application of the clause peels a digit and multiplies what has accumulated by cc, and after mm applications the argument has been reduced to its leading digit bmb_m, which lies between 11 and d1d-1 and is therefore covered by the first clause. The proof is an induction on the number of digits, and the only thing to check carefully is that the split of nn into dn+jdn' + j really does correspond to the split of the digit string, which is where the uniqueness of base-dd representation is used.

Proof.

We induct on mm, the number of digits after the leading one.

If m=0m = 0 then n=b0n = b_0 with 1b0d11 \leqslant b_0 \leqslant d-1, and the first clause gives f(n)=αb0f(n) = \alpha_{b_0}, which is the claim.

Let m1m \geqslant 1 and write n=(bmb1b0)dn = (b_m \cdots b_1 b_0)_d, that is

n=bmdm+bm1dm1++b1d+b0=d(bmdm1++b1)+b0.n = b_m d^m + b_{m-1}d^{m-1} + \cdots + b_1 d + b_0 = d\bigl(b_m d^{m-1} + \cdots + b_1\bigr) + b_0 .

Setting n=(bmb1)dn' = (b_m \cdots b_1)_d and j=b0j = b_0, we have n=dn+jn = dn' + j with 0j<d0 \leqslant j < d and n1n' \geqslant 1. The second clause and the inductive hypothesis applied to nn', which has m1m-1 digits after its leading one, give

f(n)=cf(n)+βb0=c(cm1αbm+cm2βbm1++βb1)+βb0,f(n) = c\,f(n') + \beta_{b_0} = c\left(c^{m-1}\alpha_{b_m} + c^{m-2}\beta_{b_{m-1}} + \cdots + \beta_{b_1}\right) + \beta_{b_0},

and expanding the bracket is the claim at mm.

Representation in a Base

The theorem above took for granted that nn has a base-dd digit string and that the string is determined by nn. Both facts need proof, and the tools are the floor function and the remainder.

Definition 2.19 (Floor, ceiling and remainder).

For xRx \in \mathbb{R},

x=max{kZkx},x=min{kZkx}.\lfloor x \rfloor = \max\{k \in \mathbb{Z} \mid k \leqslant x\}, \qquad \lceil x \rceil = \min\{k \in \mathbb{Z} \mid k \geqslant x\} .

For xZx \in \mathbb{Z} and yNy \in \mathbb{N} the remainder of xx on division by yy is

xmody=xyxy.x \bmod y = x - y\left\lfloor \frac{x}{y} \right\rfloor .

Rearranging the last definition gives the identity we shall use repeatedly: for zN0z \in \mathbb{N}_0 and bNb \in \mathbb{N},

z=bzb+(zmodb),0zmodb<b.z = b\left\lfloor \frac{z}{b} \right\rfloor + (z \bmod b), \qquad 0 \leqslant z \bmod b < b .

Example 2.20 (Floors and remainders).

13.2=13\lfloor 13.2 \rfloor = 13 and 13.2=14\lceil 13.2 \rceil = 14. For the remainder,

23mod6=236236=2363=5,23=36+5.23 \bmod 6 = 23 - 6\left\lfloor \tfrac{23}{6} \right\rfloor = 23 - 6 \cdot 3 = 5, \qquad 23 = 3 \cdot 6 + 5 .

Theorem 2.21 (Representation in a base).

Let b,nNb, n \in \mathbb{N} with b>1b > 1. Every zN0z \in \mathbb{N}_0 with 0zbn10 \leqslant z \leqslant b^n - 1 can be written as

z=i=0n1zibi,zi{0,1,,b1},z = \sum_{i=0}^{n-1} z_i b^i, \qquad z_i \in \{0, 1, \ldots, b-1\},

and the digits z0,,zn1z_0, \ldots, z_{n-1} are uniquely determined by zz.

Discussion.

There are two claims, and they are proved by different means.

Existence is an induction on the number of digits nn, and the step is division by bb. Given zz below bn+1b^{n+1}, split it as z=bz^+z0z = b\hat{z} + z_0 with z0=zmodbz_0 = z \bmod b the last digit and z^=z/b\hat{z} = \lfloor z/b \rfloor what remains. The point to check is that z^\hat{z} falls in the range the inductive hypothesis covers, namely below bnb^n, and it does because dividing by bb shrinks the bound by a factor of bb. The hypothesis then supplies nn digits for z^\hat{z}, and multiplying the whole expansion by bb shifts every digit up one place, leaving room at the bottom for z0z_0.

Uniqueness is an argument by contradiction that needs no induction. Suppose two different digit strings give the same value, and look at the highest place mm where they disagree. Above mm the terms are equal and cancel, so the difference of the two sums is a single term (zmz^m)bm(z_m - \hat{z}_m)b^m, which is at least bmb^m, plus lower terms, each of which is at least (b1)bi-(b-1)b^i. Summing those lower bounds telescopes to 1bm1 - b^m, so the total is at least bm+1bm=1b^m + 1 - b^m = 1; but the total is 00. The heart of it is that one unit in a place outweighs everything below it, which is what makes positional notation work at all.

Proof.

Existence. We induct on nn.

For n=0n = 0 the only zz in range is z=0z = 0, represented by the empty sum.

Suppose every z^\hat{z} with 0z^bn10 \leqslant \hat{z} \leqslant b^n - 1 has a representation with nn digits, and let 0zbn+110 \leqslant z \leqslant b^{n+1} - 1. Put

z0=zmodb,z^=zb,soz=bz^+z0,0z0<b.z_0 = z \bmod b, \qquad \hat{z} = \left\lfloor \frac{z}{b} \right\rfloor, \qquad\text{so}\qquad z = b\hat{z} + z_0, \quad 0 \leqslant z_0 < b .

We check that z^\hat{z} lies in the range covered by the hypothesis. From zbn+11<bn+1z \leqslant b^{n+1} - 1 < b^{n+1} we get z/b<bnz/b < b^n, and z^z/b\hat z \leqslant z/b, so z^<bn\hat{z} < b^n; being an integer, z^bn1\hat{z} \leqslant b^n - 1. Also z^0\hat{z} \geqslant 0. So the hypothesis applies and gives digits z^0,,z^n1\hat{z}_0, \ldots, \hat{z}_{n-1} in {0,,b1}\{0, \ldots, b-1\} with z^=i=0n1z^ibi\hat{z} = \sum_{i=0}^{n-1}\hat{z}_i b^i. Then

z=bi=0n1z^ibi+z0=i=0n1z^ibi+1+z0=i=1nz^i1bi+z0=i=0nzibi,z = b\sum_{i=0}^{n-1}\hat{z}_i b^i + z_0 = \sum_{i=0}^{n-1}\hat{z}_i b^{i+1} + z_0 = \sum_{i=1}^{n}\hat{z}_{i-1} b^{i} + z_0 = \sum_{i=0}^{n} z_i b^i,

where the third step reindexed the sum by ii+1i \mapsto i+1 and the last set zi=z^i1z_i = \hat{z}_{i-1} for 1in1 \leqslant i \leqslant n, with z0z_0 as chosen. Every digit lies in {0,,b1}\{0, \ldots, b-1\}, and there are n+1n+1 of them, which is the claim for n+1n+1.

Uniqueness. Suppose

i=0n1zibi=i=0n1z^ibi\sum_{i=0}^{n-1} z_i b^i = \sum_{i=0}^{n-1} \hat{z}_i b^i

with all digits in {0,,b1}\{0, \ldots, b-1\}, and suppose the two strings are not identical. Let

m=max{i0in1,  ziz^i},m = \max\{\, i \mid 0 \leqslant i \leqslant n-1, \; z_i \neq \hat{z}_i \,\},

and assume without loss of generality that zm>z^mz_m > \hat{z}_m. All terms with i>mi > m agree and cancel, so subtracting one sum from the other leaves

0=i=0m(ziz^i)bi=(zmz^m)bm+i=0m1(ziz^i)bi.0 = \sum_{i=0}^{m} (z_i - \hat{z}_i)\,b^i = (z_m - \hat{z}_m)\,b^m + \sum_{i=0}^{m-1}(z_i - \hat{z}_i)\,b^i .

Now bound the two pieces from below. The digits are integers with zm>z^mz_m > \hat z_m, so zmz^m1z_m - \hat{z}_m \geqslant 1 and the first term is at least bmb^m. For i<mi < m we have zi0z_i \geqslant 0 and z^ib1\hat{z}_i \leqslant b-1, so ziz^i1bz_i - \hat{z}_i \geqslant 1 - b and

i=0m1(ziz^i)bi    (1b)i=0m1bi=i=0m1bii=0m1bi+1=i=0m1bii=1mbi=b0bm,\sum_{i=0}^{m-1}(z_i - \hat{z}_i)\,b^i \;\geqslant\; (1-b)\sum_{i=0}^{m-1} b^i = \sum_{i=0}^{m-1}b^i - \sum_{i=0}^{m-1}b^{i+1} = \sum_{i=0}^{m-1}b^i - \sum_{i=1}^{m}b^{i} = b^0 - b^m,

the last step because the two sums share every term with 1im11 \leqslant i \leqslant m-1. Adding the two bounds,

0    bm+(1bm)=1,0 \;\geqslant\; b^m + \bigl(1 - b^m\bigr) = 1,

which is false. So no two distinct digit strings represent the same zz.

Corollary 2.22 (Radix notation).

Let b>1b > 1. For a digit string zn1,,z0z_{n-1}, \ldots, z_0 with entries in {0,,b1}\{0, \ldots, b-1\} write

(zn1zn2z1z0)b=i=0n1zibi.(z_{n-1}\,z_{n-2}\cdots z_1\,z_0)_b = \sum_{i=0}^{n-1} z_i b^i .

Then every zNz \in \mathbb{N} is (zn1z0)b(z_{n-1}\cdots z_0)_b for exactly one digit string with leading digit zn10z_{n-1} \neq 0, and its length is n=logbz+1n = \lfloor \log_b z \rfloor + 1.

Proof.

Let zNz \in \mathbb{N} and put n=logbz+1n = \lfloor \log_b z \rfloor + 1, so that n1logbz<nn - 1 \leqslant \log_b z < n and hence bn1z<bnb^{n-1} \leqslant z < b^n. The theorem applies with this nn and gives digits z0,,zn1z_0, \ldots, z_{n-1}, unique for this length. The leading digit is not zero: if zn1=0z_{n-1} = 0 then z=i=0n2zibi(b1)i=0n2bi=bn11z = \sum_{i=0}^{n-2}z_ib^i \leqslant (b-1)\sum_{i=0}^{n-2}b^i = b^{n-1} - 1, contradicting zbn1z \geqslant b^{n-1}.

Conversely, suppose z=(zn1z0)bz = (z_{n'-1}\cdots z_0)_b for some length nn' with zn10z_{n'-1} \neq 0. Then zbn1z \geqslant b^{n'-1}, and also z(b1)i=0n1bi=bn1<bnz \leqslant (b-1)\sum_{i=0}^{n'-1}b^i = b^{n'} - 1 < b^{n'}. So bn1z<bnb^{n'-1} \leqslant z < b^{n'}, which forces n=nn' = n, and the theorem then makes the digits the ones already found.

Remark (Horner's scheme).

Evaluating (zn1z0)b(z_{n-1}\cdots z_0)_b by computing each power bib^i and multiplying costs about 2n2n multiplications. Nesting the expression,

i=0n1zibi=z0+b(z1+b(z2++b(zn2+bzn1))),\sum_{i=0}^{n-1} z_i b^i = z_0 + b\Bigl(z_1 + b\bigl(z_2 + \cdots + b(z_{n-2} + b\,z_{n-1})\cdots\bigr)\Bigr),

evaluates it from the inside out with n1n-1 multiplications and n1n-1 additions, and never forms a power of bb explicitly. This is Horner’s scheme, and the same nesting evaluates any polynomial at any point.

Problem 2.12.

Compute J(1000)J(1000) two ways, from the closed form and from the cyclic shift, and check that they agree.

Problem 2.13.

Show that J(n)=nJ(n) = n if and only if n=2k1n = 2^k - 1 for some kN0k \in \mathbb{N}_0.

Problem 2.14.

For which nn does person 11 survive? Show that person 22 never survives, whatever nn may be.

Problem 2.15.

Use the repertoire method to solve

f(1)=α,f(2)=3f()+β,f(2+1)=3f()+γ.f(1) = \alpha, \qquad f(2\ell) = 3f(\ell) + \beta, \qquad f(2\ell + 1) = 3f(\ell) + \gamma .

Problem 2.16.

Write ν(n)\nu(n) for the number of ones in the binary representation of nn. Prove that repeated application of JJ to any nNn \in \mathbb{N} eventually reaches 2ν(n)12^{\nu(n)} - 1 and stays there.

Problem 2.17.

Let b>1b > 1 and kNk \in \mathbb{N}. Show that the last kk digits of zNz \in \mathbb{N} in base bb are the digits of zmodbkz \bmod b^{k}, padded with leading zeros if need be.

Sums

A recurrence adds one term to what came before, so every recurrence of the form Sn=Sn1+anS_n = S_{n-1} + a_n is a sum in disguise and every sum is such a recurrence. This chapter sets up the notation for sums, establishes the laws that let them be rearranged, and turns the correspondence with recurrences into a method that evaluates sums the previous chapter could not touch.

Sequences

Definition 2.23 (Sequence).

A sequence of elements of a set AA is a function f:N0Af : \mathbb{N}_0 \to A. The value f(n)f(n) is the nnth term and is written ana_n, and the sequence itself is written

{an}nN0,or {an} when the index set is understood.\{a_n\}_{n \in \mathbb{N}_0}, \qquad \text{or } \{a_n\} \text{ when the index set is understood.}

The function and the list of its values are the same object seen two ways. Defining f:N0Rf : \mathbb{N}_0 \to \mathbb{R} by f(n)=n+nf(n) = n + \sqrt{n} is the same as writing an=n+na_n = n + \sqrt{n}, and the same again as writing out

0,2,2+2,3+3,,n+n,0, \quad 2, \quad 2 + \sqrt{2}, \quad 3 + \sqrt{3}, \quad \ldots, \quad n + \sqrt{n}, \quad \ldots

A sequence in this sense is infinite, since its domain is, and it is countably infinite: the terms can be laid out in a list indexed by 0,1,2,0, 1, 2, \ldots with no term left out.

Definition 2.24 (Countably infinite).

A set TT is countably infinite if there is a bijection N0T\mathbb{N}_0 \to T, and we then write #T=#N0\#T = \#\mathbb{N}_0.

Removing finitely many elements from N0\mathbb{N}_0 leaves a countably infinite set, so the index set of a sequence need not be N0\mathbb{N}_0 itself; any countably infinite set of indices will do, and the terms can then be listed in the order that a bijection with N0\mathbb{N}_0 supplies.

Example 2.25 (Indexing by another set).

The even numbers E={0,2,4,}E = \{0, 2, 4, \ldots\} are countably infinite, since n2nn \mapsto 2n is a bijection N0E\mathbb{N}_0 \to E. So {ak}kE\{a_k\}_{k \in E} is a sequence, with terms a0,a2,a4,a_0, a_2, a_4, \ldots listed in that order.

A formula may exclude some indices of its own accord. For

an=n(n2)(n5)a_n = \frac{n}{(n-2)(n-5)}

the denominator vanishes at n=2n = 2 and n=5n = 5, so the sequence is the function f:N{2,5}Rf : \mathbb{N} \setminus \{2, 5\} \to \mathbb{R}, and its index set is again countably infinite.

Definition 2.26 (Finite sequence).

A finite sequence of elements of AA is a function f:KAf : K \to A with KK finite. When KK is a non-empty set of natural numbers we take K={1,2,,n}K = \{1, 2, \ldots, n\} and call nn the length, writing f={ak}k=1,,nf = \{a_k\}_{k=1,\ldots,n}. For K=K = \emptyset the function is empty and ff is the empty sequence, written ε\varepsilon.

Sigma Notation

Definition 2.27 (Finite sum).

Let {ak}\{a_k\} be a sequence of real numbers. For nNn \in \mathbb{N} we write

k=1nak=a1+a2++an.\sum_{k=1}^{n} a_k = a_1 + a_2 + \cdots + a_n .

Each aka_k appearing is a term, the expression aka_k after the \textstyle\sum is the summand, and kk is the index of summation, which is bound to the \textstyle\sum and has no meaning outside it.

The notation says: include exactly those terms aka_k whose index is an integer between the lower and upper limits, inclusive. That reading has a delimited form and a general form, and the two are interchangeable:

k=1nak  =  1knak  =  k{1,,n}ak  =  Kakfor K={1,,n}.\sum_{k=1}^{n} a_k \;=\; \sum_{1 \leqslant k \leqslant n} a_k \;=\; \sum_{k \in \{1, \ldots, n\}} a_k \;=\; \sum_{K} a_k \quad\text{for } K = \{1, \ldots, n\}.

More generally, one or more conditions written under the \textstyle\sum specify which indices take part. The sum of the squares of the odd positive integers below 100100 is

1k<100k oddk2,\sum_{\substack{1 \leqslant k < 100 \\ k \text{ odd}}} k^2 ,

whose delimited form k=049(2k+1)2\sum_{k=0}^{49}(2k+1)^2 is harder to read; and the sum of the reciprocals of the primes up to NN is

pNp prime1p,\sum_{\substack{p \leqslant N \\ p \text{ prime}}} \frac{1}{p} ,

whose delimited form needs a function counting the primes before it can even be written down.

The general form also survives a change of index more transparently. Replacing kk by k+1k+1 turns

1knakinto1k+1nak+1,\sum_{1 \leqslant k \leqslant n} a_k \qquad\text{into}\qquad \sum_{1 \leqslant k+1 \leqslant n} a_{k+1} ,

where the substitution can be made without thought, while in delimited form the same change reads

k=1nak=k=0n1ak+1,\sum_{k=1}^{n} a_k = \sum_{k=0}^{n-1} a_{k+1} ,

and the limits have to be recomputed by hand.

Definition 2.28 (Summation over a property).

Let P(k)P(k) be a statement about integers which is true or false for each kk, and suppose only finitely many kk with P(k)P(k) true have ak0a_k \neq 0. Then

P(k)ak=kKak=Kak,K={kZP(k)}.\sum_{P(k)} a_k = \sum_{k \in K} a_k = \sum_{K} a_k, \qquad K = \{\, k \in \mathbb{Z} \mid P(k) \,\} .

If P(k)P(k) is false for every kk the sum is empty, and its value is 00.

Example 2.29 (Reading a condition).

Let P(n)P(n) be the property ”1n<1001 \leqslant n < 100 and nn is odd”. Then

K={nNP(n)}={1,3,5,,99}={2j+10j49},K = \{\, n \in \mathbb{N} \mid P(n) \,\} = \{1, 3, 5, \ldots, 99\} = \{\, 2j+1 \mid 0 \leqslant j \leqslant 49 \,\},

so

P(n)an=Kak=j=049a2j+1=a1+a3++a99.\sum_{P(n)} a_n = \sum_{K} a_k = \sum_{j=0}^{49} a_{2j+1} = a_1 + a_3 + \cdots + a_{99} .

Dropping the parity condition gives K={1,2,,99}K = \{1, 2, \ldots, 99\} and P(n)an=k=199ak\sum_{P(n)}a_n = \sum_{k=1}^{99}a_k. Taking the summand to be an=(2n+1)2a_n = (2n+1)^2 instead gives

1n<100(2n+1)2=32+52++1992.\sum_{1 \leqslant n < 100} (2n+1)^2 = 3^2 + 5^2 + \cdots + 199^2 .

Remark (Keeping limits simple).

Terms equal to zero do no harm, and excluding them usually costs more than it saves. In

k=0nk(k1)(nk)\sum_{k=0}^{n} k(k-1)(n-k)

the terms at k=0k = 0, k=1k = 1 and k=nk = n all vanish, and one is tempted to write k=2n1\sum_{k=2}^{n-1} instead. That form is worse: it is harder to manipulate, and its meaning is unclear when n=0n = 0 or n=1n = 1. Simple limits are worth more than a short list of terms.

Remark (Two conventions for empty sums).

An empty sum is 00, which fixes the value of k=abak\sum_{k=a}^{b}a_k when b<ab < a:

k=abak=0whenever b<a.\sum_{k=a}^{b} a_k = 0 \qquad \text{whenever } b < a .

In particular k=10ak=0\sum_{k=1}^{0}a_k = 0 and k=01ak=0\sum_{k=0}^{-1}a_k = 0. With this convention the splitting rules hold without exception: for every nN0n \in \mathbb{N}_0,

k=1n+1ak=k=1nak+an+1,k=0nak=k=0n1ak+an,\sum_{k=1}^{n+1} a_k = \sum_{k=1}^{n} a_k + a_{n+1}, \qquad \sum_{k=0}^{n} a_k = \sum_{k=0}^{n-1} a_k + a_n ,

the second reading correctly at n=0n = 0 as a0=0+a0a_0 = 0 + a_0.

Iverson Brackets

Kenneth Iverson introduced a device that removes conditions from beneath the \textstyle\sum altogether.

Definition 2.30 (Iverson bracket).

For a statement PP that is either true or false, write

[P]={1if P is true,0if P is false.[P] = \begin{cases} 1 & \text{if } P \text{ is true}, \\ 0 & \text{if } P \text{ is false}. \end{cases}

A term multiplied by a bracket that evaluates to 00 is taken to be 00 even when the other factor is undefined.

With brackets, a sum over a condition becomes a sum over all integers,

P(k)ak=kak[P(k)],\sum_{P(k)} a_k = \sum_{k} a_k\,[P(k)] ,

since the terms failing PP contribute nothing. The index may then be manipulated freely, with no boundary conditions to fuss over. The reciprocals of the primes up to NN become

p[p prime][pN]p,\sum_{p} \frac{[\,p \text{ prime}\,]\,[\,p \leqslant N\,]}{p} ,

and the term at p=0p = 0 is 00 rather than a division by zero, by the convention in the definition.

Proposition 2.31 (Laws of summation).

Let KK be a finite set of integers, let {ak}\{a_k\} and {bk}\{b_k\} be sequences of reals, and let cRc \in \mathbb{R}. Then

  1. kKcak=ckKak\displaystyle \sum_{k \in K} c\,a_k = c \sum_{k \in K} a_k;
  2. kK(ak+bk)=kKak+kKbk\displaystyle \sum_{k \in K} (a_k + b_k) = \sum_{k \in K} a_k + \sum_{k \in K} b_k;
  3. kKak=kKaσ(k)\displaystyle \sum_{k \in K} a_k = \sum_{k \in K} a_{\sigma(k)} for every bijection σ:KK\sigma : K \to K.

Discussion.

Each law is a property of addition of reals lifted to a finite list of terms, so each is proved by induction on the size of KK, peeling off one element at a time. The first is distributivity, the second is associativity and commutativity used together to interleave two lists, and the third is commutativity alone: reordering the terms of a finite sum does not change it, and a bijection of the index set with itself is exactly a reordering. The third is the one that needs the index set to be finite, since rearranging infinitely many terms can change a sum.

Proof.

We induct on #K\#K. If K=K = \emptyset all three sums are empty and every claim reads 0=00 = 0.

Let KK be non-empty, pick jKj \in K and write K=K{j}K' = K \setminus \{j\}, so that kKxk=xj+kKxk\sum_{k \in K}x_k = x_j + \sum_{k \in K'}x_k for any sequence xx.

For the first law, kKcak=caj+kKcak=caj+ckKak=c(aj+kKak)\sum_{k\in K}ca_k = ca_j + \sum_{k \in K'}ca_k = ca_j + c\sum_{k\in K'}a_k = c\bigl(a_j + \sum_{k\in K'}a_k\bigr), using the inductive hypothesis and then distributivity in R\mathbb{R}.

For the second, kK(ak+bk)=(aj+bj)+kKak+kKbk\sum_{k\in K}(a_k+b_k) = (a_j+b_j) + \sum_{k\in K'}a_k + \sum_{k\in K'}b_k by the hypothesis, and regrouping the four terms by commutativity and associativity gives (aj+kKak)+(bj+kKbk)\bigl(a_j + \sum_{k\in K'}a_k\bigr) + \bigl(b_j + \sum_{k\in K'}b_k\bigr).

For the third, let σ:KK\sigma : K \to K be a bijection and let jKj \in K be arbitrary. Then σ\sigma restricts to a bijection K{σ1(j)}KK \setminus \{\sigma^{-1}(j)\} \to K', and splitting both sums so that the term aja_j is taken first reduces the claim to the same statement on a set with one fewer element.

The laws above all concern a single index set. Two different index sets combine as well.

Proposition 2.32 (Combining index sets).

Let KK and KK' be finite sets of integers. Then

kKak+kKak=kKKak+kKKak.\sum_{k \in K} a_k + \sum_{k \in K'} a_k = \sum_{k \in K \cap K'} a_k + \sum_{k \in K \cup K'} a_k .

Discussion.

Counting elements suggests the shape of the answer, since #K+#K=#(KK)+#(KK)\#K + \#K' = \#(K \cup K') + \#(K \cap K'): an element of both sets is counted twice on each side. Iverson brackets turn that count into a proof, because they replace membership by a number that can be added. The identity to establish is then [kK]+[kK]=[kKK]+[kKK][k \in K] + [k \in K'] = [k \in K \cap K'] + [k \in K \cup K'] for each single kk, which is checked by looking at the four possible cases; summing it over all kk and using the law for sums of sequences gives the claim.

Proof.

Fix an integer kk and compare the two sides of

[kK]+[kK]=[kKK]+[kKK].[k \in K] + [k \in K'] = [k \in K \cap K'] + [k \in K \cup K'] .

If kk lies in both sets, both sides are 22. If it lies in exactly one, both sides are 11, the right-hand side because the intersection bracket is 00 and the union bracket is 11. If it lies in neither, both sides are 00.

Multiplying by aka_k and summing over all integers kk, the second law of summation gives

kak[kK]+kak[kK]=kak[kKK]+kak[kKK],\sum_k a_k[k \in K] + \sum_k a_k[k \in K'] = \sum_k a_k[k \in K \cap K'] + \sum_k a_k[k \in K \cup K'],

and each of the four sums is the corresponding sum over its index set.

Problem 2.18.

Show that [P][Q]=[PQ][P]\,[Q] = [P \wedge Q] and [P]+[Q][P][Q]=[PQ][P] + [Q] - [P]\,[Q] = [P \vee Q] for all statements PP and QQ, and use the first of these to write

1knk oddak\sum_{\substack{1 \leqslant k \leqslant n \\ k \text{ odd}}} a_k

as a sum over all integers kk with no condition beneath the sign.

Geometric Sums

Definition 2.33 (Geometric sequence).

A sequence {an}\{a_n\} of reals is geometric with ratio qq if an+1=qana_{n+1} = q\,a_n for every nN0n \in \mathbb{N}_0, equivalently if an=a0qna_n = a_0 q^n for every nn.

Proposition 2.34 (Geometric sum).

Let q1q \neq 1 and nN0n \in \mathbb{N}_0. Then

k=0na0qk=a01qn+11q.\sum_{k=0}^{n} a_0 q^k = a_0\,\frac{1 - q^{\,n+1}}{1 - q} .

Discussion.

Multiplying the sum by qq shifts every term one place along, so the product and the original share all their terms but two: the original has a0a_0 where the product has nothing, and the product has a0qn+1a_0q^{n+1} where the original has nothing. Subtracting therefore cancels everything in the middle and leaves those two terms, which is a linear equation for the sum. The hypothesis q1q \neq 1 is what allows the division at the end, and it is needed: at q=1q = 1 every term is a0a_0 and the sum is (n+1)a0(n+1)a_0.

Proof.

Write S=k=0na0qk=a0+a0q++a0qnS = \sum_{k=0}^{n}a_0q^k = a_0 + a_0q + \cdots + a_0q^n. By the first law of summation,

qS=a0q+a0q2++a0qn+a0qn+1.qS = a_0q + a_0q^2 + \cdots + a_0q^{n} + a_0q^{\,n+1} .

Every term of qSqS with exponent between 11 and nn appears in SS as well, so subtracting leaves only the extremes:

SqS=a0a0qn+1,that isS(1q)=a0(1qn+1).S - qS = a_0 - a_0 q^{\,n+1}, \qquad\text{that is}\qquad S(1 - q) = a_0\bigl(1 - q^{\,n+1}\bigr).

Since q1q \neq 1 we may divide by 1q1 - q.

Example 2.35 (Halving).

With a0=1a_0 = 1 and q=12q = \tfrac12,

k=0n(12)k=1(1/2)n+111/2=2(12)n.\sum_{k=0}^{n} \left(\tfrac{1}{2}\right)^{k} = \frac{1 - (1/2)^{n+1}}{1 - 1/2} = 2 - \left(\tfrac{1}{2}\right)^{n}.

Starting the sum at k=1k = 1 removes the term 11, so

k=1n(12)k=1(12)n,\sum_{k=1}^{n} \left(\tfrac{1}{2}\right)^{k} = 1 - \left(\tfrac{1}{2}\right)^{n},

which is what one expects: halving repeatedly closes all but the last gap.

Sums and Recurrences

Writing Sn=k=0nakS_n = \sum_{k=0}^{n} a_k and splitting off the last term gives Sn=Sn1+anS_n = S_{n-1} + a_n, so a sum is a recurrence and the methods of the previous chapter apply to it. The correspondence runs both ways, and this section uses it in each direction.

Proposition 2.36 (A sum is a recurrence).

Let {ak}\{a_k\} be a sequence of reals and put Sn=k=0nakS_n = \sum_{k=0}^{n}a_k. Then SS is the unique function N0R\mathbb{N}_0 \to \mathbb{R} with

S0=a0,Sn=Sn1+an(n1),S_0 = a_0, \qquad S_n = S_{n-1} + a_n \quad (n \geqslant 1),

and conversely any function satisfying those two conditions is given by that sum.

Discussion.

Both halves come from the splitting rule for sums, which is where the convention that an empty sum is 00 earns its place: it makes S0S_0 come out as a0a_0 with no separate argument. For the forward direction, split the last term off the sum defining SnS_n. For the converse, the two conditions determine the value at every nn from the value below it, so at most one function satisfies them, and the sum has just been shown to be one.

Proof.

At n=0n = 0 the sum has the single term a0a_0, so S0=a0S_0 = a_0. For n1n \geqslant 1, splitting off the term at k=nk = n gives

Sn=k=0nak=k=0n1ak+an=Sn1+an.S_n = \sum_{k=0}^{n} a_k = \sum_{k=0}^{n-1}a_k + a_n = S_{n-1} + a_n .

Conversely, suppose R:N0RR : \mathbb{N}_0 \to \mathbb{R} satisfies R0=a0R_0 = a_0 and Rn=Rn1+anR_n = R_{n-1} + a_n for n1n \geqslant 1. Then R0=S0R_0 = S_0, and if Rn1=Sn1R_{n-1} = S_{n-1} then Rn=Rn1+an=Sn1+an=SnR_n = R_{n-1} + a_n = S_{n-1} + a_n = S_n. By induction R=SR = S.

Used from left to right, this turns a sum into a recurrence to be solved by the techniques already available. The repertoire method of the previous chapter applies without change, and the recurrence to feed it is the general first-order one with a linear term.

Theorem 2.37 (A linear sum-recurrence).

Let α,β,γR\alpha, \beta, \gamma \in \mathbb{R} and let RR satisfy

R0=α,Rn=Rn1+β+γn(n1).R_0 = \alpha, \qquad R_n = R_{n-1} + \beta + \gamma n \quad (n \geqslant 1).

Then

Rn=α+βn+γn2+n2.R_n = \alpha + \beta n + \gamma\,\frac{n^2 + n}{2} .

Discussion.

Computing R1=α+β+γR_1 = \alpha + \beta + \gamma, R2=α+2β+3γR_2 = \alpha + 2\beta + 3\gamma and R3=α+3β+6γR_3 = \alpha + 3\beta + 6\gamma shows every value to be a combination A(n)α+B(n)β+C(n)γA(n)\alpha + B(n)\beta + C(n)\gamma whose coefficients do not depend on the three constants, so the repertoire method applies: choose functions RR that satisfy the recurrence for some values of α,β,γ\alpha, \beta, \gamma, and read off one equation in AA, BB, CC from each. The constant function 11 forces β=γ=0\beta = \gamma = 0 and gives AA outright; the function nn forces β=1\beta = 1, γ=0\gamma = 0 and gives BB; and the function n2n^2 forces β=1\beta = -1, γ=2\gamma = 2, which involves BB and CC together and so needs the previous two results to finish. Three substitutions give three equations, and the system is triangular.

Proof.

Write Rn=A(n)α+B(n)β+C(n)γR_n = A(n)\alpha + B(n)\beta + C(n)\gamma, which the first few values show to be the right shape, and determine the coefficients by substitution. Each substitution takes a function RR, asks which α,β,γ\alpha, \beta, \gamma make it satisfy the recurrence, and then reads the displayed identity at those values.

Take Rn=1R_n = 1. Then R0=1R_0 = 1 forces α=1\alpha = 1, and the recurrence reads 1=1+β+γn1 = 1 + \beta + \gamma n, that is β+γn=0\beta + \gamma n = 0 for every nn, which forces β=γ=0\beta = \gamma = 0. Substituting (α,β,γ)=(1,0,0)(\alpha, \beta, \gamma) = (1, 0, 0) gives

1=A(n).1 = A(n) .

Take Rn=nR_n = n. Then R0=0R_0 = 0 forces α=0\alpha = 0, and the recurrence reads n=(n1)+β+γnn = (n-1) + \beta + \gamma n, that is 1=β+γn1 = \beta + \gamma n for every nn, which forces β=1\beta = 1 and γ=0\gamma = 0. Substituting (0,1,0)(0, 1, 0) gives

n=B(n).n = B(n) .

Take Rn=n2R_n = n^2. Then α=0\alpha = 0, and the recurrence reads n2=(n1)2+β+γnn^2 = (n-1)^2 + \beta + \gamma n, that is

0=2n+1+β+γn=(1+β)+(γ2)n0 = -2n + 1 + \beta + \gamma n = (1 + \beta) + (\gamma - 2)n

for every nn, which forces β=1\beta = -1 and γ=2\gamma = 2. Substituting (0,1,2)(0, -1, 2) gives

n2=B(n)+2C(n)=n+2C(n),soC(n)=n2+n2.n^2 = -B(n) + 2C(n) = -n + 2C(n), \qquad\text{so}\qquad C(n) = \frac{n^2+n}{2}.

Assembling, Rn=α+βn+γ(n2+n)/2R_n = \alpha + \beta n + \gamma(n^2+n)/2. Finally this function does satisfy the recurrence, as substituting it into Rn1+β+γnR_{n-1} + \beta + \gamma n confirms, and the recurrence with its boundary condition has only one solution.

Example 2.38 (Summing an arithmetic progression).

Let a,bRa, b \in \mathbb{R} and Sn=k=0n(a+bk)S_n = \sum_{k=0}^{n}(a + bk). By the correspondence above, S0=aS_0 = a and Sn=Sn1+(a+bn)S_n = S_{n-1} + (a + bn), which is the recurrence of the theorem with α=a\alpha = a, β=a\beta = a and γ=b\gamma = b. Hence

k=0n(a+bk)=a+na+n2+n2b=(n+1)a+n(n+1)2b.\sum_{k=0}^{n}(a + bk) = a + na + \frac{n^2+n}{2}b = (n+1)a + \frac{n(n+1)}{2}b .

The same answer comes out of the summation laws directly: splitting the summand and pulling out the constants,

k=0n(a+bk)=k=0na+bk=0nk=(n+1)a+bn(n+1)2,\sum_{k=0}^{n}(a + bk) = \sum_{k=0}^{n}a + b\sum_{k=0}^{n}k = (n+1)a + b\,\frac{n(n+1)}{2},

since a sum of n+1n+1 copies of aa is (n+1)a(n+1)a. The repertoire method earns its keep on recurrences that are not sums of anything recognisable.

The Summation Factor

Used from right to left, the correspondence turns a recurrence into a sum. A recurrence of the form Sn=Sn1+cnS_n = S_{n-1} + c_n is immediately a sum, so the problem is to bring a given recurrence into that shape, and multiplying through by a well-chosen factor does it.

Theorem 2.39 (Summation factor).

Let {an}\{a_n\}, {bn}\{b_n\}, {cn}\{c_n\} be sequences of reals with an0a_n \neq 0 and bn0b_n \neq 0 for every n1n \geqslant 1, and let TT satisfy

anTn=bnTn1+cn(n1),a_n T_n = b_n T_{n-1} + c_n \qquad (n \geqslant 1),

with T0T_0 given. Put s1=1s_1 = 1 and

sn=a1a2an1b2b3bn(n2).s_n = \frac{a_1 a_2 \cdots a_{n-1}}{b_2 b_3 \cdots b_n} \qquad (n \geqslant 2).

Then snbn=sn1an1s_n b_n = s_{n-1}a_{n-1} for every n2n \geqslant 2, and

Tn=1snan(s1b1T0+k=1nskck)(n1).T_n = \frac{1}{s_n a_n}\left( s_1 b_1 T_0 + \sum_{k=1}^{n} s_k c_k \right) \qquad (n \geqslant 1).

Discussion.

The obstruction to reading the recurrence as a sum is that TnT_n and Tn1T_{n-1} carry different coefficients. Multiplying the whole equation by a factor sns_n removes the obstruction provided the new coefficient of Tn1T_{n-1}, namely snbns_nb_n, equals the coefficient that Tn1T_{n-1} had at the previous step, namely sn1an1s_{n-1}a_{n-1}; that condition is a recurrence for sns_n itself, and unrolling it gives the stated product. With the factor in hand, Sn=snanTnS_n = s_na_nT_n satisfies Sn=Sn1+sncnS_n = S_{n-1} + s_nc_n, which the previous proposition evaluates as a sum. Dividing by snans_na_n at the end is legitimate because both factors are non-zero, which is exactly what the hypotheses on ana_n and bnb_n guarantee.

Proof.

For n2n \geqslant 2, the definition of sns_n gives

snbn=a1an1b2bnbn=a1an1b2bn1=a1an2b2bn1an1=sn1an1,s_n b_n = \frac{a_1 \cdots a_{n-1}}{b_2 \cdots b_n}\,b_n = \frac{a_1 \cdots a_{n-1}}{b_2 \cdots b_{n-1}} = \frac{a_1 \cdots a_{n-2}}{b_2\cdots b_{n-1}}\,a_{n-1} = s_{n-1}a_{n-1},

with the case n=2n = 2 reading s2b2=a1=s1a1s_2b_2 = a_1 = s_1a_1.

Multiply the recurrence by sns_n and set Sn=snanTnS_n = s_na_nT_n. For n2n \geqslant 2,

Sn=snanTn=snbnTn1+sncn=sn1an1Tn1+sncn=Sn1+sncn,S_n = s_na_nT_n = s_nb_nT_{n-1} + s_nc_n = s_{n-1}a_{n-1}T_{n-1} + s_nc_n = S_{n-1} + s_nc_n,

and at n=1n = 1 the recurrence gives S1=s1a1T1=s1(b1T0+c1)=s1b1T0+s1c1S_1 = s_1a_1T_1 = s_1(b_1T_0 + c_1) = s_1b_1T_0 + s_1c_1. So SS satisfies a sum-recurrence started at s1b1T0s_1b_1T_0, and unrolling it gives

Sn=s1b1T0+k=1nskck.S_n = s_1b_1T_0 + \sum_{k=1}^{n}s_kc_k .

Since sn0s_n \neq 0 and an0a_n \neq 0, dividing Sn=snanTnS_n = s_na_nT_n by snans_na_n gives the stated formula.

Example 2.40 (The Tower of Hanoi again).

The recurrence Tn=2Tn1+1T_n = 2T_{n-1} + 1 has an=1a_n = 1, bn=2b_n = 2 and cn=1c_n = 1, so a summation factor is sn=2ns_n = 2^{-n}, which satisfies snbn=2(n1)=sn1an1s_nb_n = 2^{-(n-1)} = s_{n-1}a_{n-1}. Multiplying through,

Tn2n=Tn12n1+12n,\frac{T_n}{2^n} = \frac{T_{n-1}}{2^{\,n-1}} + \frac{1}{2^n},

so Sn=Tn/2nS_n = T_n/2^n obeys S0=0S_0 = 0 and Sn=Sn1+2nS_n = S_{n-1} + 2^{-n}. That is a geometric sum,

Sn=k=1n12k=112n,S_n = \sum_{k=1}^{n}\frac{1}{2^k} = 1 - \frac{1}{2^n},

and multiplying back by 2n2^n gives Tn=2n1T_n = 2^n - 1.

Remark (Where the factor comes from).

The condition snbn=sn1an1s_nb_n = s_{n-1}a_{n-1} is itself a recurrence, sn=sn1an1/bns_n = s_{n-1}a_{n-1}/b_n, and unrolling it from s1=1s_1 = 1 produces the product in the theorem. Any non-zero constant multiple of that product serves equally well, since multiplying every sns_n by the same constant leaves the condition and the final formula unchanged; in the Hanoi example the product gives 2(n1)2^{-(n-1)} and we used 2n2^{-n}. The method needs every ana_n and every bnb_n to be non-zero, and fails otherwise.

Definition 2.41 (Harmonic numbers).

For nN0n \in \mathbb{N}_0 the nnth harmonic number is

Hn=k=1n1k=1+12+13++1n,H_n = \sum_{k=1}^{n}\frac{1}{k} = 1 + \frac{1}{2} + \frac{1}{3} + \cdots + \frac{1}{n},

so that H0=0H_0 = 0. The name comes from music: the kkth harmonic of a vibrating string is the tone produced by a string 1/k1/k times as long.

Harmonic numbers have no closed form in the sense of this chapter, and they are what a summation factor produces as soon as the coefficients of a recurrence vary with nn.

Example 2.42 (A recurrence with variable coefficients).

The Hanoi recurrence had constant ana_n and bnb_n, so the factor was a constant power. Consider instead

T0=0,nTn=(n+1)Tn1+2n(n1),T_0 = 0, \qquad n\,T_n = (n+1)\,T_{n-1} + 2n \qquad (n \geqslant 1),

with an=na_n = n, bn=n+1b_n = n+1 and cn=2nc_n = 2n. The summation factor is

sn=a1a2an1b2b3bn=(n1)!(n+1)!/2=2n(n+1),s_n = \frac{a_1 a_2 \cdots a_{n-1}}{b_2 b_3 \cdots b_n} = \frac{(n-1)!}{(n+1)!/2} = \frac{2}{n(n+1)} ,

which agrees with s1=1s_1 = 1. Then snanTn=2Tn/(n+1)s_n a_n T_n = 2T_n/(n+1) and skck=4/(k+1)s_k c_k = 4/(k+1), while s1b1T0=0s_1 b_1 T_0 = 0, so the theorem gives

2Tnn+1=k=1n4k+1,that isTn=2(n+1)k=1n1k+1.\frac{2T_n}{n+1} = \sum_{k=1}^{n}\frac{4}{k+1}, \qquad\text{that is}\qquad T_n = 2(n+1)\sum_{k=1}^{n}\frac{1}{k+1} .

The remaining sum is a harmonic number in disguise. Shifting the index by one,

k=1n1k+1=2kn+11k=1kn1k1+1n+1=Hnnn+1,\sum_{k=1}^{n}\frac{1}{k+1} = \sum_{2 \leqslant k \leqslant n+1}\frac{1}{k} = \sum_{1 \leqslant k \leqslant n}\frac{1}{k} - 1 + \frac{1}{n+1} = H_n - \frac{n}{n+1},

where the middle step dropped the term at k=1k = 1 and added the one at k=n+1k = n+1. Therefore

Tn=2(n+1)(Hnnn+1)=2(n+1)Hn2n,T_n = 2(n+1)\left(H_n - \frac{n}{n+1}\right) = 2(n+1)H_n - 2n ,

and checking at n=1n = 1 gives T1=4H12=2T_1 = 4H_1 - 2 = 2, which the recurrence confirms.

Problem 2.19.

Use a summation factor to solve T0=1T_0 = 1 and nTn=(n+1)Tn1+n(n+1)nT_n = (n+1)T_{n-1} + n(n+1) for n1n \geqslant 1.

Problem 2.20.

Prove that H2nHn12H_{2n} - H_n \geqslant \tfrac{1}{2} for every nNn \in \mathbb{N}, and deduce that HnH_n can be made as large as we please by taking nn large enough.

Exercises on Recurrences

Exercise 2.1.

Compute TnT_n for the Tower of Hanoi for n=1,,8n = 1, \ldots, 8 from the recurrence, and check each against 2n12^n - 1.

Exercise 2.2.

Suppose a fourth peg is added to the Tower of Hanoi. Give a strategy for nn discs using the extra peg, count its moves, and compare the count with 2n12^n - 1 for n=4,8,16n = 4, 8, 16.

Exercise 2.3.

Solve each recurrence by unrolling, then confirm the answer by induction.

  1. f(0)=2f(0) = 2 and f(n)=3f(n1)f(n) = 3f(n-1) for n1n \geqslant 1;
  2. f(0)=0f(0) = 0 and f(n)=f(n1)+2n1f(n) = f(n-1) + 2n - 1 for n1n \geqslant 1;
  3. f(1)=1f(1) = 1 and f(n)=f(n1)+1/nf(n) = f(n-1) + 1/n for n2n \geqslant 2, as far as a sum in closed form allows.

Exercise 2.4.

Solve f(0)=1f(0) = 1, f(n)=3f(n1)+4f(n) = 3f(n-1) + 4 for n1n \geqslant 1 by the substitution Un=f(n)+cU_n = f(n) + c, choosing cc so that the recurrence for UnU_n has no constant term.

Exercise 2.5.

What is the largest number of regions into which nn circles can cut the plane? Find the recurrence and solve it.

Exercise 2.6.

What is the largest number of pieces into which nn planes can cut three-dimensional space? Argue that the answer satisfies Pn=Pn1+Ln1P_n = P_{n-1} + L_{n-1}, where LnL_n is the count for lines in the plane, and solve.

Exercise 2.7.

For each recurrence, write down the characteristic equation, find its roots, and give the solution meeting the stated boundary conditions.

  1. f(0)=0f(0) = 0, f(1)=1f(1) = 1, f(n)=6f(n1)8f(n2)f(n) = 6f(n-1) - 8f(n-2);
  2. f(0)=1f(0) = 1, f(1)=2f(1) = 2, f(n)=2f(n1)f(n2)f(n) = 2f(n-1) - f(n-2);
  3. f(0)=1f(0) = 1, f(1)=0f(1) = 0, f(2)=1f(2) = 1, f(n)=3f(n2)2f(n3)f(n) = 3f(n-2) - 2f(n-3).

Exercise 2.8.

Solve f(0)=0f(0) = 0 and f(n)=2f(n1)+n2f(n) = 2f(n-1) + n^2 for n1n \geqslant 1.

Exercise 2.9.

Let ff satisfy the Fibonacci recurrence with f(0)=f(1)=1f(0) = f(1) = 1. Prove that f(0)+f(1)++f(n)=f(n+2)1f(0) + f(1) + \cdots + f(n) = f(n+2) - 1.

Exercise 2.10.

Compute J(n)J(n) for n=17,,32n = 17, \ldots, 32 and check that the values run through the odd numbers below 3232 and then restart at 11.

Exercise 2.11.

Suppose the circle is counted in the other direction, so that the first person eliminated is the one before the leader rather than after. Work out the survivor for n=1,,8n = 1, \ldots, 8 and find a recurrence.

Exercise 2.12.

Use the repertoire method on f(1)=αf(1) = \alpha, f(2)=2f()+βf(2\ell) = 2f(\ell) + \beta\ell, f(2+1)=2f()+γf(2\ell+1) = 2f(\ell) + \gamma\ell, taking f(n)=1f(n) = 1 and f(n)=nf(n) = n as two of the substitutions.

Exercise 2.13.

Convert 20262026 to base 22, base 33 and base 1616, and check each answer by Horner’s scheme.

Exercise 2.14.

Let b>1b > 1 and zNz \in \mathbb{N}. Show that zz and z+1z+1 have the same number of base-bb digits unless z+1z + 1 is a power of bb, and use this to count how many numbers have exactly nn digits in base bb.

Exercise 2.15.

Show that x+x=2x\lfloor x \rfloor + \lceil x \rceil = 2\lfloor x \rfloor when xZx \in \mathbb{Z} and 2x+12\lfloor x \rfloor + 1 otherwise, and that x+k=x+k\lfloor x + k \rfloor = \lfloor x \rfloor + k for every kZk \in \mathbb{Z}.

Exercises on Sums

Exercise 2.16.

Some of the regions cut out by nn lines in the plane are bounded and the rest are not. What is the largest possible number of bounded regions?

Exercise 2.17.

Let H(n)=J(n+1)J(n)H(n) = J(n+1) - J(n), with JJ the Josephus survivor. The recurrence for JJ gives H(2n)=2H(2n) = 2 and

H(2n+1)=J(2n+2)J(2n+1)=(2J(n+1)1)(2J(n)+1)=2H(n)2H(2n+1) = J(2n+2) - J(2n+1) = \bigl(2J(n+1) - 1\bigr) - \bigl(2J(n) + 1\bigr) = 2H(n) - 2

for every n1n \geqslant 1. It therefore looks possible to prove H(n)=2H(n) = 2 for all nn by induction. Compute H(1)H(1), H(2)H(2) and H(3)H(3), and say exactly what is wrong with the argument.

Exercise 2.18.

Let α,βR\alpha, \beta \in \mathbb{R} and define Q0=αQ_0 = \alpha, Q1=βQ_1 = \beta and

Qn=1+Qn1Qn2(n2),Q_n = \frac{1 + Q_{n-1}}{Q_{n-2}} \qquad (n \geqslant 2),

assuming α\alpha and β\beta are such that no denominator ever vanishes. Compute Q2,,Q6Q_2, \ldots, Q_6 and prove that Qn+5=QnQ_{n+5} = Q_n for every nN0n \in \mathbb{N}_0.

Exercise 2.19.

Evaluate

k[1jkn]\sum_{k} \,[\,1 \leqslant j \leqslant k \leqslant n\,]

as a function of jj and nn, taking care over the values of jj for which the sum is empty.

Exercise 2.20.

Prove the rule for summation by parts: for every nN0n \in \mathbb{N}_0,

0k<n(ak+1ak)bk=anbna0b00k<nak+1(bk+1bk).\sum_{0 \leqslant k < n} (a_{k+1} - a_k)\,b_k = a_n b_n - a_0 b_0 - \sum_{0 \leqslant k < n} a_{k+1}\,(b_{k+1} - b_k) .

Use only the distributive, associative and commutative laws of summation together with a shift of the index.

Exercise 2.21.

Find a closed form for

k=0n(1)kk2.\sum_{k=0}^{n} (-1)^k k^2 .

Exercise 2.22.

Use a summation factor to solve

T0=5,2Tn=nTn1+3n!(n1),T_0 = 5, \qquad 2T_n = n\,T_{n-1} + 3 \cdot n! \quad (n \geqslant 1),

and check your answer at n=1n = 1 and n=2n = 2.

Exercise 2.23.

Evaluate k=0nk2k\sum_{k=0}^{n} k\,2^k by writing the recurrence it satisfies and solving it, and check the answer for n4n \leqslant 4.

Exercise 2.24.

Show that k=1n1k(k+1)=11n+1\sum_{k=1}^{n} \dfrac{1}{k(k+1)} = 1 - \dfrac{1}{n+1}, first by unrolling the corresponding recurrence and then by writing 1k(k+1)=1k1k+1\dfrac{1}{k(k+1)} = \dfrac{1}{k} - \dfrac{1}{k+1} and cancelling.

Exercise 2.25.

Let KK and KK' be finite sets of integers with KK=K \cap K' = \emptyset. Deduce from the law for combining index sets that kKKak=kKak+kKak\sum_{k \in K \cup K'}a_k = \sum_{k \in K}a_k + \sum_{k \in K'}a_k, and give an example showing the hypothesis is needed.

Exercise 2.26.

Write each of the following as a sum with the index running from 00, using Iverson brackets where a condition is needed.

  1. 1k100k divisible by 3k\displaystyle\sum_{\substack{1 \leqslant k \leqslant 100 \\ k \text{ divisible by } 3}} k;
  2. k=5201k4\displaystyle\sum_{k=5}^{20} \frac{1}{k-4};
  3. the sum of aka_k over those kk between 11 and nn that are perfect squares.

Check Yourself

 

Fresh questions on the whole chapter — none of them is worked out above. Do each on paper first; the box only tells you whether you got there.

Answers are checked in your browser, as often as you like. Nothing is sent anywhere and nothing is kept but your own work. A formula may be written with the symbols themselves or with ~ & | -> <-> ^, and \and, \or, \to expand as you type.

Exercise 2.27.

How many moves does the Tower of Hanoi need for five discs?

answer one of these

Exercise 2.28.

What is the largest number of regions four lines can cut the plane into?

answer one of these

Exercise 2.29.

In how many ways can a staircase of five steps be climbed, one or two steps at a time?

answer one of these

Exercise 2.30.

What are the roots of the characteristic equation of f(n)=3f(n1)2f(n2)f(n) = 3f(n-1) - 2f(n-2)?

answer one of these

Exercise 2.31.

A root r0r \neq 0 of multiplicity 22 of the characteristic equation contributes which solutions?

answer one of these

Exercise 2.32.

To find a particular solution of f(n)=2f(n1)+3nf(n) = 2f(n-1) + 3^n, what should be tried first?

answer one of these

Exercise 2.33.

What is J(20)J(20)?

answer one of these

Exercise 2.34.

What is J(64)J(64)?

answer one of these

Exercise 2.35.

For which nn does the Josephus problem leave the last person standing, that is J(n)=nJ(n) = n?

answer one of these

Exercise 2.36.

What is (1011)2(1011)_2 in base ten?

answer one of these

Exercise 2.37.

What is 101mod7101 \bmod 7?

answer one of these

Exercise 2.38.

What is 3.2\lfloor -3.2 \rfloor?

answer one of these

Exercise 2.39.

How many binary digits does 10001000 have?

answer one of these

Exercise 2.40.

Unrolling Ln=Ln1+nL_n = L_{n-1} + n from L0=1L_0 = 1, what is L10L_{10}?

answer one of these

Exercise 2.41.

What is k=15k2\sum_{k=1}^{5} k^2?

answer one of these

Exercise 2.42.

What is the value of k=31ak\sum_{k=3}^{1} a_k?

answer one of these

Exercise 2.43.

What is [3 is even]+[3 is odd][\,3 \text{ is even}\,] + [\,3 \text{ is odd}\,]?

answer one of these

Exercise 2.44.

What is k=0432k\sum_{k=0}^{4} 3 \cdot 2^k?

answer one of these

Exercise 2.45.

What is the harmonic number H4H_4?

answer one of these

Exercise 2.46.

Which summation factor turns Tn=3Tn1+1T_n = 3T_{n-1} + 1 into a sum?

answer one of these