text stringlengths 1 7.76k | source stringlengths 17 81 |
|---|---|
454 CHAPTER 11. MARKOV CHAINS If we compute the fundamental matrix N, we obtain N = 1 8 14 9 4 3 9 4 3 2 6 14 6 4 4 2 2 2 4 9 14 9 3 2 3 4 2 4 6 14 2 2 4 6 6 4 2 2 14 6 4 2 4 3 2 3 9 14 9 4 2 2 2 4 4 6 14 6 2 3 4 9 3 4 9 14 . The expected time to absorption for different starting states is given by the vec- tor Nc, where Nc = 6 5 6 5 5 6 5 6 . We see that, starting from compartment 1, it will take on the average six steps to reach food. It is clear from symmetry that we should get the same answer for starting at state 3, 7, or 9. It is also clear that it should take one more step, starting at one of these states, than it would starting at 2, 4, 6, or 8. Some of the results obtained from N are not so obvious. For instance, we note that the expected number of times in the starting state is 14/8 regardless of the state in which we start. 2 Mean Recurrence Time A quantity that is closely related to the mean first passage time is the mean recur- rence time, defined as follows. Assume that we start in state si; consider the length of time before we return to si for the first time. It is clear that we must return, since we either stay at si the first step or go to some other state sj, and from any other state sj, we will eventually reach si because the chain is ergodic. Definition 11.8 If an ergodic Markov chain is started in state si, the expected number of steps to return to si for the first time is the mean recurrence time for si. It is denoted by ri. 2 We need to develop some basic properties of the mean first passage time. Con- sider the mean first passage time from si to sj; assume that i ̸= j. This may be computed as follows: take the expected number of steps required given the outcome of the first step, multiply by the probability that this outcome occurs, and add. If the first step is to sj, the expected number of steps required is 1; if it is to some | prob_Page_462_Chunk5301 |
11.5. MEAN FIRST PASSAGE TIME 455 other state sk, the expected number of steps required is mkj plus 1 for the step already taken. Thus, mij = pij + X k̸=j pik(mkj + 1) , or, since P k pik = 1, mij = 1 + X k̸=j pikmkj . (11.2) Similarly, starting in si, it must take at least one step to return. Considering all possible first steps gives us ri = X k pik(mki + 1) (11.3) = 1 + X k pikmki . (11.4) Mean First Passage Matrix and Mean Recurrence Matrix Let us now define two matrices M and D. The ijth entry mij of M is the mean first passage time to go from si to sj if i ̸= j; the diagonal entries are 0. The matrix M is called the mean first passage matrix. The matrix D is the matrix with all entries 0 except the diagonal entries dii = ri. The matrix D is called the mean recurrence matrix. Let C be an r × r matrix with all entries 1. Using Equation 11.2 for the case i ̸= j and Equation 11.4 for the case i = j, we obtain the matrix equation M = PM + C −D , (11.5) or (I −P)M = C −D . (11.6) Equation 11.6 with mii = 0 implies Equations 11.2 and 11.4. We are now in a position to prove our first basic theorem. Theorem 11.15 For an ergodic Markov chain, the mean recurrence time for state si is ri = 1/wi, where wi is the ith component of the fixed probability vector for the transition matrix. Proof. Multiplying both sides of Equation 11.6 by w and using the fact that w(I −P) = 0 gives wC −wD = 0 . Here wC is a row vector with all entries 1 and wD is a row vector with ith entry wiri. Thus (1, 1, . . . , 1) = (w1r1, w2r2, . . . , wnrn) and ri = 1/wi , as was to be proved. 2 | prob_Page_463_Chunk5302 |
456 CHAPTER 11. MARKOV CHAINS Corollary 11.1 For an ergodic Markov chain, the components of the fixed proba- bility vector w are strictly positive. Proof. We know that the values of ri are finite and so wi = 1/ri cannot be 0. 2 Example 11.25 In Example 11.22 we found the fixed probability vector for the maze example to be w = ( 1 12 1 8 1 12 1 8 1 6 1 8 1 12 1 8 1 12 ) . Hence, the mean recurrence times are given by the reciprocals of these probabilities. That is, r = ( 12 8 12 8 6 8 12 8 12) . 2 Returning to the Land of Oz, we found that the weather in the Land of Oz could be represented by a Markov chain with states rain, nice, and snow. In Section 11.3 we found that the limiting vector was w = (2/5, 1/5, 2/5). From this we see that the mean number of days between rainy days is 5/2, between nice days is 5, and between snowy days is 5/2. Fundamental Matrix We shall now develop a fundamental matrix for ergodic chains that will play a role similar to that of the fundamental matrix N = (I −Q)−1 for absorbing chains. As was the case with absorbing chains, the fundamental matrix can be used to find a number of interesting quantities involving ergodic chains. Using this matrix, we will give a method for calculating the mean first passage times for ergodic chains that is easier to use than the method given above. In addition, we will state (but not prove) the Central Limit Theorem for Markov Chains, the statement of which uses the fundamental matrix. We begin by considering the case that P is the transition matrix of a regular Markov chain. Since there are no absorbing states, we might be tempted to try Z = (I −P)−1 for a fundamental matrix. But I −P does not have an inverse. To see this, recall that a matrix R has an inverse if and only if Rx = 0 implies x = 0. But since Pc = c we have (I −P)c = 0, and so I −P does not have an inverse. We recall that if we have an absorbing Markov chain, and Q is the restriction of the transition matrix to the set of transient states, then the fundamental matrix N could be written as N = I + Q + Q2 + · · · . The reason that this power series converges is that Qn →0, so this series acts like a convergent geometric series. This idea might prompt one to try to find a similar series for regular chains. Since we know that Pn →W, we might consider the series I + (P −W) + (P2 −W) + · · · . (11.7) | prob_Page_464_Chunk5303 |
11.5. MEAN FIRST PASSAGE TIME 457 We now use special properties of P and W to rewrite this series. The special properties are: 1) PW = W, and 2) Wk = W for all positive integers k. These facts are easy to verify, and are left as an exercise (see Exercise 22). Using these facts, we see that (P −W)n = n X i=0 (−1)i n i Pn−iWi = Pn + n X i=1 (−1)i n i Wi = Pn + n X i=1 (−1)i n i W = Pn + n X i=1 (−1)i n i ! W . If we expand the expression (1 −1)n, using the Binomial Theorem, we obtain the expression in parenthesis above, except that we have an extra term (which equals 1). Since (1 −1)n = 0, we see that the above expression equals -1. So we have (P −W)n = Pn −W , for all n ≥1. We can now rewrite the series in 11.7 as I + (P −W) + (P −W)2 + · · · . Since the nth term in this series is equal to Pn −W, the nth term goes to 0 as n goes to infinity. This is sufficient to show that this series converges, and sums to the inverse of the matrix I −P + W. We call this inverse the fundamental matrix associated with the chain, and we denote it by Z. In the case that the chain is ergodic, but not regular, it is not true that Pn →W as n →∞. Nevertheless, the matrix I −P + W still has an inverse, as we will now show. Proposition 11.1 Let P be the transition matrix of an ergodic chain, and let W be the matrix all of whose rows are the fixed probability row vector for P. Then the matrix I −P + W has an inverse. Proof. Let x be a column vector such that (I −P + W)x = 0 . To prove the proposition, it is sufficient to show that x must be the zero vector. Multiplying this equation by w and using the fact that w(I−P) = 0 and wW = w, we have w(I −P + W)x = wx = 0 . | prob_Page_465_Chunk5304 |
458 CHAPTER 11. MARKOV CHAINS Therefore, (I −P)x = 0 . But this means that x = Px is a fixed column vector for P. By Theorem 11.10, this can only happen if x is a constant vector. Since wx = 0, and w has strictly positive entries, we see that x = 0. This completes the proof. 2 As in the regular case, we will call the inverse of the matrix I −P + W the fundamental matrix for the ergodic chain with transition matrix P, and we will use Z to denote this fundamental matrix. Example 11.26 Let P be the transition matrix for the weather in the Land of Oz. Then I −P + W = 1 0 0 0 1 0 0 0 1 − 1/2 1/4 1/4 1/2 0 1/2 1/4 1/4 1/2 + 2/5 1/5 2/5 2/5 1/5 2/5 2/5 1/5 2/5 = 9/10 −1/20 3/20 −1/10 6/5 −1/10 3/20 −1/20 9/10 , so Z = (I −P + W)−1 = 86/75 1/25 −14/75 2/25 21/25 2/25 −14/75 1/25 86/75 . 2 Using the Fundamental Matrix to Calculate the Mean First Passage Matrix We shall show how one can obtain the mean first passage matrix M from the fundamental matrix Z for an ergodic Markov chain. Before stating the theorem which gives the first passage times, we need a few facts about Z. Lemma 11.2 Let Z = (I −P + W)−1, and let c be a column vector of all 1’s. Then Zc = c , wZ = w , and Z(I −P) = I −W . Proof. Since Pc = c and Wc = c, c = (I −P + W)c . If we multiply both sides of this equation on the left by Z, we obtain Zc = c . | prob_Page_466_Chunk5305 |
11.5. MEAN FIRST PASSAGE TIME 459 Similarly, since wP = w and wW = w, w = w(I −P + W) . If we multiply both sides of this equation on the right by Z, we obtain wZ = w . Finally, we have (I −P + W)(I −W) = I −W −P + W + W −W = I −P . Multiplying on the left by Z, we obtain I −W = Z(I −P) . This completes the proof. 2 The following theorem shows how one can obtain the mean first passage times from the fundamental matrix. Theorem 11.16 The mean first passage matrix M for an ergodic chain is deter- mined from the fundamental matrix Z and the fixed row probability vector w by mij = zjj −zij wj . Proof. We showed in Equation 11.6 that (I −P)M = C −D . Thus, Z(I −P)M = ZC −ZD , and from Lemma 11.2, Z(I −P)M = C −ZD . Again using Lemma 11.2, we have M −WM = C −ZD or M = C −ZD + WM . From this equation, we see that mij = 1 −zijrj + (wM)j . (11.8) But mjj = 0, and so 0 = 1 −zjjrj + (wM)j , | prob_Page_467_Chunk5306 |
460 CHAPTER 11. MARKOV CHAINS or (wM)j = zjjrj −1 . (11.9) From Equations 11.8 and 11.9, we have mij = (zjj −zij) · rj . Since rj = 1/wj, mij = zjj −zij wj . 2 Example 11.27 (Example 11.26 continued) In the Land of Oz example, we find that Z = (I −P + W)−1 = 86/75 1/25 −14/75 2/25 21/25 2/25 −14/75 1/25 86/75 . We have also seen that w = (2/5, 1/5, 2/5). So, for example, m12 = z22 −z12 w2 = 21/25 −1/25 1/5 = 4 , by Theorem 11.16. Carrying out the calculations for the other entries of M, we obtain M = 0 4 10/3 8/3 0 8/3 10/3 4 0 . 2 Computation The program ErgodicChain calculates the fundamental matrix, the fixed vector, the mean recurrence matrix D, and the mean first passage matrix M. We have run the program for the Ehrenfest urn model (Example 11.8). We obtain: P = 0 1 2 3 4 0 .0000 1.0000 .0000 .0000 .0000 1 .2500 .0000 .7500 .0000 .0000 2 .0000 .5000 .0000 .5000 .0000 3 .0000 .0000 .7500 .0000 .2500 4 .0000 .0000 .0000 1.0000 .0000 ; w = | prob_Page_468_Chunk5307 |
11.5. MEAN FIRST PASSAGE TIME 461 r = | prob_Page_469_Chunk5308 |
462 CHAPTER 11. MARKOV CHAINS 0 200 400 600 800 1000 40 45 50 55 60 65 0 200 400 600 800 1000 40 45 50 55 60 65 Time forward Time reversed Figure 11.6: Ehrenfest simulation. Consider in particular the central term i = n. We have seen that this term is approximately 1/√πn. Thus we may approximate rn by √πn. This model was used to explain the concept of reversibility in physical systems. Assume that we let our system run until it is in equilibrium. At this point, a movie is made, showing the system’s progress. The movie is then shown to you, and you are asked to tell if the movie was shown in the forward or the reverse direction. It would seem that there should always be a tendency to move toward an equal proportion of balls so that the correct order of time should be the one with the most transitions from i to i −1 if i > n and i to i + 1 if i < n. In Figure 11.6 we show the results of simulating the Ehrenfest urn model for the case of n = 50 and 1000 time units, using the program EhrenfestUrn. The top graph shows these results graphed in the order in which they occurred and the bottom graph shows the same results but with time reversed. There is no apparent difference. | prob_Page_470_Chunk5309 |
11.5. MEAN FIRST PASSAGE TIME 463 We note that if we had not started in equilibrium, the two graphs would typically look quite different. 2 Reversibility If the Ehrenfest model is started in equilibrium, then the process has no apparent time direction. The reason for this is that this process has a property called re- versibility. Define Xn to be the number of balls in the left urn at step n. We can calculate, for a general ergodic chain, the reverse transition probability: P(Xn−1 = j|Xn = i) = P(Xn−1 = j, Xn = i) P(Xn = i) = P(Xn−1 = j)P(Xn = i|Xn−1 = j) P(Xn = i) = P(Xn−1 = j)pji P(Xn = i) . In general, this will depend upon n, since P(Xn = j) and also P(Xn−1 = j) change with n. However, if we start with the vector w or wait until equilibrium is reached, this will not be the case. Then we can define p∗ ij = wjpji wi as a transition matrix for the process watched with time reversed. Let us calculate a typical transition probability for the reverse chain P∗= {p∗ ij} in the Ehrenfest model. For example, p∗ i,i−1 = wi−1pi−1,i wi = | prob_Page_471_Chunk5310 |
464 CHAPTER 11. MARKOV CHAINS the number of times that the chain is in state sj in the first n steps. The jth component wj of the fixed probability row vector w is the proportion of times that the chain is in state sj in the long run. Hence, it is reasonable to conjecture that the expected value of the random variable S(n) j , as n →∞, is asymptotic to nwj, and it is easy to show that this is the case (see Exercise 23). It is also natural to ask whether there is a limiting distribution of the random variables S(n) j . The answer is yes, and in fact, this limiting distribution is the normal distribution. As in the case of independent trials, one must normalize these random variables. Thus, we must subtract from S(n) j its expected value, and then divide by its standard deviation. In both cases, we will use the asymptotic values of these quantities, rather than the values themselves. Thus, in the first case, we will use the value nwj. It is not so clear what we should use in the second case. It turns out that the quantity σ2 j = 2wjzjj −wj −w2 j (11.10) represents the asymptotic variance. Armed with these ideas, we can state the following theorem. Theorem 11.17 (Central Limit Theorem for Markov Chains) For an er- godic chain, for any real numbers r < s, we have P r < S(n) j −nwj q nσ2 j < s ! → 1 √ 2π Z s r e−x2/2 dx , as n →∞, for any choice of starting state, where σ2 j is the quantity defined in Equation 11.10. 2 Historical Remarks Markov chains were introduced by Andre˘i Andreevich Markov (1856–1922) and were named in his honor. He was a talented undergraduate who received a gold medal for his undergraduate thesis at St. Petersburg University. Besides being an active research mathematician and teacher, he was also active in politics and patricipated in the liberal movement in Russia at the beginning of the twentieth century. In 1913, when the government celebrated the 300th anniversary of the House of Romanov family, Markov organized a counter-celebration of the 200th anniversary of Bernoulli’s discovery of the Law of Large Numbers. Markov was led to develop Markov chains as a natural extension of sequences of independent random variables. In his first paper, in 1906, he proved that for a Markov chain with positive transition probabilities and numerical states the average of the outcomes converges to the expected value of the limiting distribution (the fixed vector). In a later paper he proved the central limit theorem for such chains. Writing about Markov, A. P. Youschkevitch remarks: Markov arrived at his chains starting from the internal needs of prob- ability theory, and he never wrote about their applications to physical | prob_Page_472_Chunk5311 |
11.5. MEAN FIRST PASSAGE TIME 465 science. For him the only real examples of the chains were literary texts, where the two states denoted the vowels and consonants.19 In a paper written in 1913,20 Markov chose a sequence of 20,000 letters from Pushkin’s Eugene Onegin to see if this sequence can be approximately considered a simple chain. He obtained the Markov chain with transition matrix vowel consonant vowel .128 .872 consonant .663 .337 . The fixed vector for this chain is (.432, .568), indicating that we should expect about 43.2 percent vowels and 56.8 percent consonants in the novel, which was borne out by the actual count. Claude Shannon considered an interesting extension of this idea in his book The Mathematical Theory of Communication,21 in which he developed the information- theoretic concept of entropy. Shannon considers a series of Markov chain approxi- mations to English prose. He does this first by chains in which the states are letters and then by chains in which the states are words. For example, for the case of words he presents first a simulation where the words are chosen independently but with appropriate frequencies. REPRESENTING AND SPEEDILY IS AN GOOD APT OR COME CAN DIFFERENT NATURAL HERE HE THE A IN CAME THE TO OF TO EXPERT GRAY COME TO FURNISHES THE LINE MES- SAGE HAD BE THESE. He then notes the increased resemblence to ordinary English text when the words are chosen as a Markov chain, in which case he obtains THE HEAD AND IN FRONTAL ATTACK ON AN ENGLISH WRI- TER THAT THE CHARACTER OF THIS POINT IS THEREFORE ANOTHER METHOD FOR THE LETTERS THAT THE TIME OF WHO EVER TOLD THE PROBLEM FOR AN UNEXPECTED. A simulation like the last one is carried out by opening a book and choosing the first word, say it is the. Then the book is read until the word the appears again and the word after this is chosen as the second word, which turned out to be head. The book is then read until the word head appears again and the next word, and, is chosen, and so on. Other early examples of the use of Markov chains occurred in Galton’s study of the problem of survival of family names in 1889 and in the Markov chain introduced 19See Dictionary of Scientific Biography, ed. C. C. Gillespie (New York: Scribner’s Sons, 1970), pp. 124–130. 20A. A. Markov, “An Example of Statistical Analysis of the Text of Eugene Onegin Illustrat- ing the Association of Trials into a Chain,” Bulletin de l’Acadamie Imperiale des Sciences de St. Petersburg, ser. 6, vol. 7 (1913), pp. 153–162. 21C. E. Shannon and W. Weaver, The Mathematical Theory of Communication (Urbana: Univ. of Illinois Press, 1964). | prob_Page_473_Chunk5312 |
466 CHAPTER 11. MARKOV CHAINS by P. and T. Ehrenfest in 1907 for diffusion. Poincar´e in 1912 dicussed card shuffling in terms of an ergodic Markov chain defined on a permutation group. Brownian motion, a continuous time version of random walk, was introducted in 1900–1901 by L. Bachelier in his study of the stock market, and in 1905–1907 in the works of A. Einstein and M. Smoluchowsky in their study of physical processes. One of the first systematic studies of finite Markov chains was carried out by M. Frechet.22 The treatment of Markov chains in terms of the two fundamental matrices that we have used was developed by Kemeny and Snell 23 to avoid the use of eigenvalues that one of these authors found too complex. The fundamental matrix N occurred also in the work of J. L. Doob and others in studying the connection between Markov processes and classical potential theory. The fundamental matrix Z for ergodic chains appeared first in the work of Frechet, who used it to find the limiting variance for the central limit theorem for Markov chains. Exercises 1 Consider the Markov chain with transition matrix P = 1/2 1/2 1/4 3/4 . Find the fundamental matrix Z for this chain. Compute the mean first passage matrix using Z. 2 A study of the strengths of Ivy League football teams shows that if a school has a strong team one year it is equally likely to have a strong team or average team next year; if it has an average team, half the time it is average next year, and if it changes it is just as likely to become strong as weak; if it is weak it has 2/3 probability of remaining so and 1/3 of becoming average. (a) A school has a strong team. On the average, how long will it be before it has another strong team? (b) A school has a weak team; how long (on the average) must the alumni wait for a strong team? 3 Consider Example 11.4 with a = .5 and b = .75. Assume that the President says that he or she will run. Find the expected length of time before the first time the answer is passed on incorrectly. 4 Find the mean recurrence time for each state of Example 11.4 for a = .5 and b = .75. Do the same for general a and b. 5 A die is rolled repeatedly. Show by the results of this section that the mean time between occurrences of a given number is 6. 22M. Frechet, “Th´eorie des ´ev´enements en chaine dans le cas d’un nombre fini d’´etats possible,” in Recherches th´eoriques Modernes sur le calcul des probabilit´es, vol. 2 (Paris, 1938). 23J. G. Kemeny and J. L. Snell, Finite Markov Chains. | prob_Page_474_Chunk5313 |
11.5. MEAN FIRST PASSAGE TIME 467 2 4 3 6 5 1 Figure 11.7: Maze for Exercise 7. 6 For the Land of Oz example (Example 11.1), make rain into an absorbing state and find the fundamental matrix N. Interpret the results obtained from this chain in terms of the original chain. 7 A rat runs through the maze shown in Figure 11.7. At each step it leaves the room it is in by choosing at random one of the doors out of the room. (a) Give the transition matrix P for this Markov chain. (b) Show that it is an ergodic chain but not a regular chain. (c) Find the fixed vector. (d) Find the expected number of steps before reaching Room 5 for the first time, starting in Room 1. 8 Modify the program ErgodicChain so that you can compute the basic quan- tities for the queueing example of Exercise 11.3.20. Interpret the mean recur- rence time for state 0. 9 Consider a random walk on a circle of circumference n. The walker takes one unit step clockwise with probability p and one unit counterclockwise with probability q = 1 −p. Modify the program ErgodicChain to allow you to input n and p and compute the basic quantities for this chain. (a) For which values of n is this chain regular? ergodic? (b) What is the limiting vector w? (c) Find the mean first passage matrix for n = 5 and p = .5. Verify that mij = d(n −d), where d is the clockwise distance from i to j. 10 Two players match pennies and have between them a total of 5 pennies. If at any time one player has all of the pennies, to keep the game going, he gives one back to the other player and the game will continue. Show that this game can be formulated as an ergodic chain. Study this chain using the program ErgodicChain. | prob_Page_475_Chunk5314 |
468 CHAPTER 11. MARKOV CHAINS 11 Calculate the reverse transition matrix for the Land of Oz example (Exam- ple 11.1). Is this chain reversible? 12 Give an example of a three-state ergodic Markov chain that is not reversible. 13 Let P be the transition matrix of an ergodic Markov chain and P∗the reverse transition matrix. Show that they have the same fixed probability vector w. 14 If P is a reversible Markov chain, is it necessarily true that the mean time to go from state i to state j is equal to the mean time to go from state j to state i? Hint: Try the Land of Oz example (Example 11.1). 15 Show that any ergodic Markov chain with a symmetric transition matrix (i.e., pij = pji) is reversible. 16 (Crowell24) Let P be the transition matrix of an ergodic Markov chain. Show that (I + P + · · · + Pn−1)(I −P + W) = I −Pn + nW , and from this show that I + P + · · · + Pn−1 n →W , as n →∞. 17 An ergodic Markov chain is started in equilibrium (i.e., with initial probability vector w). The mean time until the next occurrence of state si is ¯ mi = P k wkmki + wiri. Show that ¯ mi = zii/wi, by using the facts that wZ = w and mki = (zii −zki)/wi. 18 A perpetual craps game goes on at Charley’s. Jones comes into Charley’s on an evening when there have already been 100 plays. He plans to play until the next time that snake eyes (a pair of ones) are rolled. Jones wonders how many times he will play. On the one hand he realizes that the average time between snake eyes is 36 so he should play about 18 times as he is equally likely to have come in on either side of the halfway point between occurrences of snake eyes. On the other hand, the dice have no memory, and so it would seem that he would have to play for 36 more times no matter what the previous outcomes have been. Which, if either, of Jones’s arguments do you believe? Using the result of Exercise 17, calculate the expected to reach snake eyes, in equilibrium, and see if this resolves the apparent paradox. If you are still in doubt, simulate the experiment to decide which argument is correct. Can you give an intuitive argument which explains this result? 19 Show that, for an ergodic Markov chain (see Theorem 11.16), X j mijwj = X j zjj −1 = K . 24Private communication. | prob_Page_476_Chunk5315 |
11.5. MEAN FIRST PASSAGE TIME 469 - 5 B 20 C - 30 A 15 GO Figure 11.8: Simplified Monopoly. The second expression above shows that the number K is independent of i. The number K is called Kemeny’s constant. A prize was offered to the first person to give an intuitively plausible reason for the above sum to be independent of i. (See also Exercise 24.) 20 Consider a game played as follows: You are given a regular Markov chain with transition matrix P, fixed probability vector w, and a payofffunction f which assigns to each state si an amount fi which may be positive or negative. Assume that wf = 0. You watch this Markov chain as it evolves, and every time you are in state si you receive an amount fi. Show that your expected winning after n steps can be represented by a column vector g(n), with g(n) = (I + P + P2 + · · · + Pn)f. Show that as n →∞, g(n) →g with g = Zf. 21 A highly simplified game of “Monopoly” is played on a board with four squares as shown in Figure 11.8. You start at GO. You roll a die and move clockwise around the board a number of squares equal to the number that turns up on the die. You collect or pay an amount indicated on the square on which you land. You then roll the die again and move around the board in the same manner from your last position. Using the result of Exercise 20, estimate the amount you should expect to win in the long run playing this version of Monopoly. 22 Show that if P is the transition matrix of a regular Markov chain, and W is the matrix each of whose rows is the fixed probability vector corresponding to P, then PW = W, and Wk = W for all positive integers k. 23 Assume that an ergodic Markov chain has states s1, s2, . . . , sk. Let S(n) j denote the number of times that the chain is in state sj in the first n steps. Let w denote the fixed probability row vector for this chain. Show that, regardless of the starting state, the expected value of S(n) j , divided by n, tends to wj as n →∞. Hint: If the chain starts in state si, then the expected value of S(n) j is given by the expression n X h=0 p(h) ij . | prob_Page_477_Chunk5316 |
470 CHAPTER 11. MARKOV CHAINS 24 In the course of a walk with Snell along Minnehaha Avenue in Minneapolis in the fall of 1983, Peter Doyle25 suggested the following explanation for the constancy of Kemeny’s constant (see Exercise 19). Choose a target state according to the fixed vector w. Start from state i and wait until the time T that the target state occurs for the first time. Let Ki be the expected value of T. Observe that Ki + wi · 1/wi = X j PijKj + 1 , and hence Ki = X j PijKj . By the maximum principle, Ki is a constant. Should Peter have been given the prize? 25Private communication. | prob_Page_478_Chunk5317 |
Chapter 12 Random Walks 12.1 Random Walks in Euclidean Space In the last several chapters, we have studied sums of random variables with the goal being to describe the distribution and density functions of the sum. In this chapter, we shall look at sums of discrete random variables from a different perspective. We shall be concerned with properties which can be associated with the sequence of partial sums, such as the number of sign changes of this sequence, the number of terms in the sequence which equal 0, and the expected size of the maximum term in the sequence. We begin with the following definition. Definition 12.1 Let {Xk}∞ k=1 be a sequence of independent, identically distributed discrete random variables. For each positive integer n, we let Sn denote the sum X1 +X2 +· · ·+Xn. The sequence {Sn}∞ n=1 is called a random walk. If the common range of the Xk’s is Rm, then we say that {Sn} is a random walk in Rm. 2 We view the sequence of Xk’s as being the outcomes of independent experiments. Since the Xk’s are independent, the probability of any particular (finite) sequence of outcomes can be obtained by multiplying the probabilities that each Xk takes on the specified value in the sequence. Of course, these individual probabilities are given by the common distribution of the Xk’s. We will typically be interested in finding probabilities for events involving the related sequence of Sn’s. Such events can be described in terms of the Xk’s, so their probabilities can be calculated using the above idea. There are several ways to visualize a random walk. One can imagine that a particle is placed at the origin in Rm at time n = 0. The sum Sn represents the position of the particle at the end of n seconds. Thus, in the time interval [n−1, n], the particle moves (or jumps) from position Sn−1 to Sn. The vector representing this motion is just Sn −Sn−1, which equals Xn. This means that in a random walk, the jumps are independent and identically distributed. If m = 1, for example, then one can imagine a particle on the real line that starts at the origin, and at the end of each second, jumps one unit to the right or the left, with probabilities given 471 | prob_Page_479_Chunk5318 |
472 CHAPTER 12. RANDOM WALKS by the distribution of the Xk’s. If m = 2, one can visualize the process as taking place in a city in which the streets form square city blocks. A person starts at one corner (i.e., at an intersection of two streets) and goes in one of the four possible directions according to the distribution of the Xk’s. If m = 3, one might imagine being in a jungle gym, where one is free to move in any one of six directions (left, right, forward, backward, up, and down). Once again, the probabilities of these movements are given by the distribution of the Xk’s. Another model of a random walk (used mostly in the case where the range is R1) is a game, involving two people, which consists of a sequence of independent, identically distributed moves. The sum Sn represents the score of the first person, say, after n moves, with the assumption that the score of the second person is −Sn. For example, two people might be flipping coins, with a match or non-match representing +1 or −1, respectively, for the first player. Or, perhaps one coin is being flipped, with a head or tail representing +1 or −1, respectively, for the first player. Random Walks on the Real Line We shall first consider the simplest non-trivial case of a random walk in R1, namely the case where the common distribution function of the random variables Xn is given by fX(x) = 1/2, if x = ±1, 0, otherwise. This situation corresponds to a fair coin being flipped, with Sn representing the number of heads minus the number of tails which occur in the first n flips. We note that in this situation, all paths of length n have the same probability, namely 2−n. It is sometimes instructive to represent a random walk as a polygonal line, or path, in the plane, where the horizontal axis represents time and the vertical axis represents the value of Sn. Given a sequence {Sn} of partial sums, we first plot the points (n, Sn), and then for each k < n, we connect (k, Sk) and (k + 1, Sk+1) with a straight line segment. The length of a path is just the difference in the time values of the beginning and ending points on the path. The reader is referred to Figure 12.1. This figure, and the process it illustrates, are identical with the example, given in Chapter 1, of two people playing heads or tails. Returns and First Returns We say that an equalization has occurred, or there is a return to the origin at time n, if Sn = 0. We note that this can only occur if n is an even integer. To calculate the probability of an equalization at time 2m, we need only count the number of paths of length 2m which begin and end at the origin. The number of such paths is clearly 2m m . Since each path has probability 2−2m, we have the following theorem. | prob_Page_480_Chunk5319 |
12.1. RANDOM WALKS IN EUCLIDEAN SPACE 473 5 10 15 20 25 30 35 40 -10 -8 -6 -4 -2 2 4 6 8 10 Figure 12.1: A random walk of length 40. Theorem 12.1 The probability of a return to the origin at time 2m is given by u2m = 2m m 2−2m . The probability of a return to the origin at an odd time is 0. 2 A random walk is said to have a first return to the origin at time 2m if m > 0, and S2k ̸= 0 for all k < m. In Figure 12.1, the first return occurs at time 2. We define f2m to be the probability of this event. (We also define f0 = 0.) One can think of the expression f2m22m as the number of paths of length 2m between the points (0, 0) and (2m, 0) that do not touch the horizontal axis except at the endpoints. Using this idea, it is easy to prove the following theorem. Theorem 12.2 For n ≥1, the probabilities {u2k} and {f2k} are related by the equation u2n = f0u2n + f2u2n−2 + · · · + f2nu0 . Proof. There are u2n22n paths of length 2n which have endpoints (0, 0) and (2n, 0). The collection of such paths can be partitioned into n sets, depending upon the time of the first return to the origin. A path in this collection which has a first return to the origin at time 2k consists of an initial segment from (0, 0) to (2k, 0), in which no interior points are on the horizontal axis, and a terminal segment from (2k, 0) to (2n, 0), with no further restrictions on this segment. Thus, the number of paths in the collection which have a first return to the origin at time 2k is given by f2k22ku2n−2k22n−2k = f2ku2n−2k22n . If we sum over k, we obtain the equation u2n22n = f0u2n22n + f2u2n−222n + · · · + f2nu022n . Dividing both sides of this equation by 22n completes the proof. 2 | prob_Page_481_Chunk5320 |
474 CHAPTER 12. RANDOM WALKS The expression in the right-hand side of the above theorem should remind the reader of a sum that appeared in Definition 7.1 of the convolution of two distributions. The convolution of two sequences is defined in a similar manner. The above theorem says that the sequence {u2n} is the convolution of itself and the sequence {f2n}. Thus, if we represent each of these sequences by an ordinary generating function, then we can use the above relationship to determine the value f2n. Theorem 12.3 For m ≥1, the probability of a first return to the origin at time 2m is given by f2m = u2m 2m −1 = | prob_Page_482_Chunk5321 |
12.1. RANDOM WALKS IN EUCLIDEAN SPACE 475 Therefore, we have F(x) = U(x) −1 U(x) = (1 −x)−1/2 −1 (1 −x)−1/2 = 1 −(1 −x)1/2 . Although it is possible to compute the value of f2m using the Binomial Theorem, it is easier to note that F ′(x) = U(x)/2, so that the coefficients f2m can be found by integrating the series for U(x). We obtain, for m ≥1, f2m = u2m−2 2m = | prob_Page_483_Chunk5322 |
476 CHAPTER 12. RANDOM WALKS In terms of the fn probabilities, we see that w2n = n X i=1 f2i . Thus, w∗= ∞ X i=1 f2i . In the proof of Theorem 12.3, the generating function F(x) = ∞ X m=0 f2mxm was introduced. There it was noted that this series converges for x ∈(−1, 1). In fact, it is possible to show that this series also converges for x = ±1 by using Exercise 4, together with the fact that f2m = u2m 2m −1 . (This fact was proved in the proof of Theorem 12.3.) Since we also know that F(x) = 1 −(1 −x)1/2 , we see that w∗= F(1) = 1 . Thus, with probability one, the particle returns to the origin. An alternative proof of the fact that w∗= 1 can be obtained by using the results in Exercise 2. 2 Example 12.2 (Eventual Return in Rm) We now turn our attention to the case that the random walk takes place in more than one dimension. We define f (m) 2n to be the probability that the first return to the origin in Rm occurs at time 2n. The quantity u(m) 2n is defined in a similar manner. Thus, f (1) 2n and u(1) 2n equal f2n and u2n, which were defined earlier. If, in addition, we define u(m) 0 = 1 and f (m) 0 = 0, then one can mimic the proof of Theorem 12.2, and show that for all m ≥1, u(m) 2n = f (m) 0 u(m) 2n + f (m) 2 u(m) 2n−2 + · · · + f (m) 2n u(m) 0 . (12.2) We continue to generalize previous work by defining U (m)(x) = ∞ X n=0 u(m) 2n xn and F (m)(x) = ∞ X n=0 f (m) 2n xn . | prob_Page_484_Chunk5323 |
12.1. RANDOM WALKS IN EUCLIDEAN SPACE 477 Then, by using Equation 12.2, we see that U (m)(x) = 1 + U (m)(x)F (m)(x) , as before. These functions will always converge in the interval (−1, 1), since all of their coefficients are at most one in magnitude. In fact, since w(m) ∗ = ∞ X n=0 f (m) 2n ≤1 for all m, the series for F (m)(x) converges at x = 1 as well, and F (m)(x) is left- continuous at x = 1, i.e., lim x↑1 F (m)(x) = F (m)(1) . Thus, we have w(m) ∗ = lim x↑1 F (m)(x) = lim x↑1 U (m)(x) −1 U (m)(x) , (12.3) so to determine w(m) ∗ , it suffices to determine lim x↑1 U (m)(x) . We let u(m) denote this limit. We claim that u(m) = ∞ X n=0 u(m) 2n . (This claim is reasonable; it says that to find out what happens to the function U (m)(x) at x = 1, just let x = 1 in the power series for U (m)(x).) To prove the claim, we note that the coefficients u(m) 2n are non-negative, so U (m)(x) increases monotonically on the interval [0, 1). Thus, for each K, we have K X n=0 u(m) 2n ≤lim x↑1 U (m)(x) = u(m) ≤ ∞ X n=0 u(m) 2n . By letting K →∞, we see that u(m) = ∞ X 2n u(m) 2n . This establishes the claim. From Equation 12.3, we see that if u(m) < ∞, then the probability of an eventual return is u(m) −1 u(m) , while if u(m) = ∞, then the probability of eventual return is 1. To complete the example, we must estimate the sum ∞ X n=0 u(m) 2n . | prob_Page_485_Chunk5324 |
478 CHAPTER 12. RANDOM WALKS In Exercise 12, the reader is asked to show that u(2) 2n = 1 42n 2n n 2 . Using Stirling’s Formula, it is easy to show that (see Exercise 13) 2n n ∼22n √πn , so u(2) 2n ∼1 πn . From this it follows easily that ∞ X n=0 u(2) 2n diverges, so w(2) ∗ = 1, i.e., in R2, the probability of an eventual return is 1. When m = 3, Exercise 12 shows that u(3) 2n = 1 22n 2n n X j,k 1 3n n! j!k!(n −j −k)! 2 . Let M denote the largest value of 1 3n n! j!k!(n −j −k)! , over all non-negative values of j and k with j + k ≤n. It is easy, using Stirling’s Formula, to show that M ∼c n , for some constant c. Thus, we have u(3) 2n ≤ 1 22n 2n n X j,k M 3n n! j!k!(n −j −k)! . Using Exercise 14, one can show that the right-hand expression is at most c′ n3/2 , where c′ is a constant. Thus, ∞ X n=0 u(3) 2n converges, so w(3) ∗ is strictly less than one. This means that in R3, the probability of an eventual return to the origin is strictly less than one (in fact, it is approximately .34). One may summarize these results by stating that one should not get drunk in more than two dimensions. 2 | prob_Page_486_Chunk5325 |
12.1. RANDOM WALKS IN EUCLIDEAN SPACE 479 Expected Number of Equalizations We now give another example of the use of generating functions to find a general formula for terms in a sequence, where the sequence is related by recursion relations to other sequences. Exercise 9 gives still another example. Example 12.3 (Expected Number of Equalizations) In this example, we will de- rive a formula for the expected number of equalizations in a random walk of length 2m. As in the proof of Theorem 12.3, the method has four main parts. First, a recursion is found which relates the mth term in the unknown sequence to earlier terms in the same sequence and to terms in other (known) sequences. An exam- ple of such a recursion is given in Theorem 12.2. Second, the recursion is used to derive a functional equation involving the generating functions of the unknown sequence and one or more known sequences. Equation 12.1 is an example of such a functional equation. Third, the functional equation is solved for the unknown generating function. Last, using a device such as the Binomial Theorem, integra- tion, or differentiation, a formula for the mth coefficient of the unknown generating function is found. We begin by defining g2m to be the number of equalizations among all of the random walks of length 2m. (For each random walk, we disregard the equalization at time 0.) We define g0 = 0. Since the number of walks of length 2m equals 22m, the expected number of equalizations among all such random walks is g2m/22m. Next, we define the generating function G(x): G(x) = ∞ X k=0 g2kxk . Now we need to find a recursion which relates the sequence {g2k} to one or both of the known sequences {f2k} and {u2k}. We consider m to be a fixed positive integer, and consider the set of all paths of length 2m as the disjoint union E2 ∪E4 ∪· · · ∪E2m ∪H , where E2k is the set of all paths of length 2m with first equalization at time 2k, and H is the set of all paths of length 2m with no equalization. It is easy to show (see Exercise 3) that |E2k| = f2k22m . We claim that the number of equalizations among all paths belonging to the set E2k is equal to |E2k| + 22kf2kg2m−2k . (12.4) Each path in E2k has one equalization at time 2k, so the total number of such equalizations is just |E2k|. This is the first summand in expression Equation 12.4. There are 22kf2k different initial segments of length 2k among the paths in E2k. Each of these initial segments can be augmented to a path of length 2m in 22m−2k ways, by adjoining all possible paths of length 2m−2k. The number of equalizations obtained by adjoining all of these paths to any one initial segment is g2m−2k, by | prob_Page_487_Chunk5326 |
480 CHAPTER 12. RANDOM WALKS definition. This gives the second summand in Equation 12.4. Since k can range from 1 to m, we obtain the recursion g2m = m X k=1 |E2k| + 22kf2kg2m−2k . (12.5) The second summand in the typical term above should remind the reader of a convolution. In fact, if we multiply the generating function G(x) by the generating function F(4x) = ∞ X k=0 22kf2kxk , the coefficient of xm equals m X k=0 22kf2kg2m−2k . Thus, the product G(x)F(4x) is part of the functional equation that we are seeking. The first summand in the typical term in Equation 12.5 gives rise to the sum 22m m X k=1 f2k . From Exercise 2, we see that this sum is just (1−u2m)22m. Thus, we need to create a generating function whose mth coefficient is this term; this generating function is ∞ X m=0 (1 −u2m)22mxm , or ∞ X m=0 22mxm − ∞ X m=0 u2m22mxm . The first sum is just (1 −4x)−1, and the second sum is U(4x). So, the functional equation which we have been seeking is G(x) = F(4x)G(x) + 1 1 −4x −U(4x) . If we solve this recursion for G(x), and simplify, we obtain G(x) = 1 (1 −4x)3/2 − 1 (1 −4x) . (12.6) We now need to find a formula for the coefficient of xm. The first summand in Equation 12.6 is (1/2)U ′(4x), so the coefficient of xm in this function is u2m+222m+1(m + 1) . The second summand in Equation 12.6 is the sum of a geometric series with common ratio 4x, so the coefficient of xm is 22m. Thus, we obtain | prob_Page_488_Chunk5327 |
12.1. RANDOM WALKS IN EUCLIDEAN SPACE 481 g2m = u2m+222m+1(m + 1) −22m = 1 2 2m + 2 m + 1 (m + 1) −22m . We recall that the quotient g2m/22m is the expected number of equalizations among all paths of length 2m. Using Exercise 4, it is easy to show that g2m 22m ∼ r 2 π √ 2m . In particular, this means that the average number of equalizations among all paths of length 4m is not twice the average number of equalizations among all paths of length 2m. In order for the average number of equalizations to double, one must quadruple the lengths of the random walks. 2 It is interesting to note that if we define Mn = max 0≤k≤n Sk , then we have E(Mn) ∼ r 2 π √n . This means that the expected number of equalizations and the expected maximum value for random walks of length n are asymptotically equal as n →∞. (In fact, it can be shown that the two expected values differ by at most 1/2 for all positive integers n. See Exercise 9.) Exercises 1 Using the Binomial Theorem, show that 1 √1 −4x = ∞ X m=0 2m m xm . What is the interval of convergence of this power series? 2 (a) Show that for m ≥1, f2m = u2m−2 −u2m . (b) Using part (a), find a closed-form expression for the sum f2 + f4 + · · · + f2m . (c) Using part (b), show that ∞ X m=1 f2m = 1 . (One can also obtain this statement from the fact that F(x) = 1 −(1 −x)1/2 .) | prob_Page_489_Chunk5328 |
482 CHAPTER 12. RANDOM WALKS (d) Using parts (a) and (b), show that the probability of no equalization in the first 2m outcomes equals the probability of an equalization at time 2m. 3 Using the notation of Example 12.3, show that |E2k| = f2k22m . 4 Using Stirling’s Formula, show that u2m ∼ 1 √πm . 5 A lead change in a random walk occurs at time 2k if S2k−1 and S2k+1 are of opposite sign. (a) Give a rigorous argument which proves that among all walks of length 2m that have an equalization at time 2k, exactly half have a lead change at time 2k. (b) Deduce that the total number of lead changes among all walks of length 2m equals 1 2(g2m −u2m) . (c) Find an asymptotic expression for the average number of lead changes in a random walk of length 2m. 6 (a) Show that the probability that a random walk of length 2m has a last return to the origin at time 2k, where 0 ≤k ≤m, equals | prob_Page_490_Chunk5329 |
12.1. RANDOM WALKS IN EUCLIDEAN SPACE 483 *8 Show that P(S1 ≥0, S2 ≥0, . . . , S2m ≥0) = u2m . Hint: First explain why P(S1 > 0, S2 > 0, . . . , S2m > 0) = 1 2P(S1 ̸= 0, S2 ̸= 0, . . . , S2m ̸= 0) . Then use Exercise 7, together with the observation that if no equalization occurs in the first 2m outcomes, then the path goes through the point (1, 1) and remains on or above the horizontal line x = 1. *9 In Feller,3 one finds the following theorem: Let Mn be the random variable which gives the maximum value of Sk, for 1 ≤k ≤n. Define pn,r = n n+r 2 2−n . If r ≥0, then P(Mn = r) = pn,r , if r ≡n (mod 2), pn,r+1 , if r ̸≡n (mod 2). (a) Using this theorem, show that E(M2m) = 1 22m m X k=1 (4k −1) 2m m + k , and if n = 2m + 1, then E(M2m+1) = 1 22m+1 m X k=0 (4k + 1) 2m + 1 m + k + 1 . (b) For m ≥1, define rm = m X k=1 k 2m m + k and sm = m X k=1 k 2m + 1 m + k + 1 . By using the identity n k = n −1 k −1 + n −1 k , show that sm = 2rm −1 2 22m − 2m m 3W. Feller, Introduction to Probability Theory and its Applications, vol. I, 3rd ed. (New York: John Wiley & Sons, 1968). | prob_Page_491_Chunk5330 |
484 CHAPTER 12. RANDOM WALKS and rm = 2sm−1 + 1 222m−1 , if m ≥2. (c) Define the generating functions R(x) = ∞ X k=1 rkxk and S(x) = ∞ X k=1 skxk . Show that S(x) = 2R(x) −1 2 1 1 −4x + 1 2 √ 1 −4x and R(x) = 2xS(x) + x 1 1 −4x . (d) Show that R(x) = x (1 −4x)3/2 , and S(x) = 1 2 1 (1 −4x)3/2 −1 2 1 1 −4x . (e) Show that rm = m 2m −1 m −1 , and sm = 1 2(m + 1) 2m + 1 m −1 2(22m) . (f) Show that E(M2m) = m 22m−1 2m m + 1 22m+1 2m m −1 2 , and E(M2m+1) = m + 1 22m+1 2m + 2 m + 1 −1 2 . The reader should compare these formulas with the expression for g2m/2(2m) in Example 12.3. | prob_Page_492_Chunk5331 |
12.1. RANDOM WALKS IN EUCLIDEAN SPACE 485 *10 (from K. Levasseur4) A parent and his child play the following game. A deck of 2n cards, n red and n black, is shuffled. The cards are turned up one at a time. Before each card is turned up, the parent and the child guess whether it will be red or black. Whoever makes more correct guesses wins the game. The child is assumed to guess each color with the same probability, so she will have a score of n, on average. The parent keeps track of how many cards of each color have already been turned up. If more black cards, say, than red cards remain in the deck, then the parent will guess black, while if an equal number of each color remain, then the parent guesses each color with probability 1/2. What is the expected number of correct guesses that will be made by the parent? Hint: Each of the | prob_Page_493_Chunk5332 |
486 CHAPTER 12. RANDOM WALKS where the last sum extends over all non-negative j and k with j +k ≤n. Also show that this last expression may be rewritten as 1 22n 2n n X j,k 1 3n n! j!k!(n −j −k)! 2 . *12 Prove that if n ≥0, then n X k=0 n k 2 = 2n n . Hint: Write the sum as n X k=0 n k n n −k and explain why this is a coefficient in the product (1 + x)n(1 + x)n . Use this, together with Exercise 11, to show that u(2) 2n = 1 42n 2n n n X k=0 n k 2 = 1 42n 2n n 2 . *13 Using Stirling’s Formula, prove that 2n n ∼22n √πn . *14 Prove that X j,k 1 3n n! j!k!(n −j −k)! = 1 , where the sum extends over all non-negative j and k such that j + k ≤n. Hint: Count how many ways one can place n labelled balls in 3 labelled urns. *15 Using the result proved for the random walk in R3 in Example 12.2, explain why the probability of an eventual return in Rn is strictly less than one, for all n ≥3. Hint: Consider a random walk in Rn and disregard all but the first three coordinates of the particle’s position. 12.2 Gambler’s Ruin In the last section, the simplest kind of symmetric random walk in R1 was studied. In this section, we remove the assumption that the random walk is symmetric. Instead, we assume that p and q are non-negative real numbers with p + q = 1, and that the common distribution function of the jumps of the random walk is fX(x) = p, if x = 1, q, if x = −1. | prob_Page_494_Chunk5333 |
12.2. GAMBLER’S RUIN 487 One can imagine the random walk as representing a sequence of tosses of a weighted coin, with a head appearing with probability p and a tail appearing with probability q. An alternative formulation of this situation is that of a gambler playing a sequence of games against an adversary (sometimes thought of as another person, sometimes called “the house”) where, in each game, the gambler has probability p of winning. The Gambler’s Ruin Problem The above formulation of this type of random walk leads to a problem known as the Gambler’s Ruin problem. This problem was introduced in Exercise 23, but we will give the description of the problem again. A gambler starts with a “stake” of size s. She plays until her capital reaches the value M or the value 0. In the language of Markov chains, these two values correspond to absorbing states. We are interested in studying the probability of occurrence of each of these two outcomes. One can also assume that the gambler is playing against an “infinitely rich” adversary. In this case, we would say that there is only one absorbing state, namely when the gambler’s stake is 0. Under this assumption, one can ask for the proba- bility that the gambler is eventually ruined. We begin by defining qk to be the probability that the gambler’s stake reaches 0, i.e., she is ruined, before it reaches M, given that the initial stake is k. We note that q0 = 1 and qM = 0. The fundamental relationship among the qk’s is the following: qk = pqk+1 + qqk−1 , where 1 ≤k ≤M −1. This holds because if her stake equals k, and she plays one game, then her stake becomes k + 1 with probability p and k −1 with probability q. In the first case, the probability of eventual ruin is qk+1 and in the second case, it is qk−1. We note that since p + q = 1, we can write the above equation as p(qk+1 −qk) = q(qk −qk−1) , or qk+1 −qk = q p(qk −qk−1) . From this equation, it is easy to see that qk+1 −qk = q p k (q1 −q0) . (12.7) We now use telescoping sums to obtain an equation in which the only unknown is q1: −1 = qM −q0 = M−1 X k=0 (qk+1 −qk) , | prob_Page_495_Chunk5334 |
488 CHAPTER 12. RANDOM WALKS so −1 = M−1 X k=0 q p k (q1 −q0) = (q1 −q0) M−1 X k=0 q p k . If p ̸= q, then the above expression equals (q1 −q0)(q/p)M −1 (q/p) −1 , while if p = q = 1/2, then we obtain the equation −1 = (q1 −q0)M . For the moment we shall assume that p ̸= q. Then we have q1 −q0 = −(q/p) −1 (q/p)M −1 . Now, for any z with 1 ≤z ≤M, we have qz −q0 = z−1 X k=0 (qk+1 −qk) = (q1 −q0) z−1 X k=0 q p k = −(q1 −q0)(q/p)z −1 (q/p) −1 = −(q/p)z −1 (q/p)M −1 . Therefore, qz = 1 −(q/p)z −1 (q/p)M −1 = (q/p)M −(q/p)z (q/p)M −1 . Finally, if p = q = 1/2, it is easy to show that (see Exercise 10) qz = M −z M . We note that both of these formulas hold if z = 0. We define, for 0 ≤z ≤M, the quantity pz to be the probability that the gambler’s stake reaches M without ever having reached 0. Since the game might | prob_Page_496_Chunk5335 |
12.2. GAMBLER’S RUIN 489 continue indefinitely, it is not obvious that pz + qz = 1 for all z. However, one can use the same method as above to show that if p ̸= q, then qz = (q/p)z −1 (q/p)M −1 , and if p = q = 1/2, then qz = z M . Thus, for all z, it is the case that pz + qz = 1, so the game ends with probability 1. Infinitely Rich Adversaries We now turn to the problem of finding the probability of eventual ruin if the gambler is playing against an infinitely rich adversary. This probability can be obtained by letting M go to ∞in the expression for qz calculated above. If q < p, then the expression approaches (q/p)z, and if q > p, the expression approaches 1. In the case p = q = 1/2, we recall that qz = 1 −z/M. Thus, if M →∞, we see that the probability of eventual ruin tends to 1. Historical Remarks In 1711, De Moivre, in his book De Mesura Sortis, gave an ingenious derivation of the probability of ruin. The following description of his argument is taken from David.6 The notation used is as follows: We imagine that there are two players, A and B, and the probabilities that they win a game are p and q, respectively. The players start with a and b counters, respectively. Imagine that each player starts with his counters before him in a pile, and that nominal values are assigned to the counters in the following manner. A’s bottom counter is given the nominal value q/p; the next is given the nominal value (q/p)2, and so on until his top counter which has the nominal value (q/p)a. B’s top counter is valued (q/p)a+1, and so on downwards until his bottom counter which is valued (q/p)a+b. After each game the loser’s top counter is transferred to the top of the winner’s pile, and it is always the top counter which is staked for the next game. Then in terms of the nominal values B’s stake is always q/p times A’s, so that at every game each player’s nominal expectation is nil. This remains true throughout the play; therefore A’s chance of winning all B’s counters, multiplied by his nominal gain if he does so, must equal B’s chance multiplied by B’s nominal gain. Thus, Pa q p a+1 + · · · + q p a+b = Pb q p + · · · + q p a . (12.8) 6F. N. David, Games, Gods and Gambling (London: Griffin, 1962). | prob_Page_497_Chunk5336 |
490 CHAPTER 12. RANDOM WALKS Using this equation, together with the fact that Pa + Pb = 1 , it can easily be shown that Pa = (q/p)a −1 (q/p)a+b −1 , if p ̸= q, and Pa = a a + b , if p = q = 1/2. In terms of modern probability theory, de Moivre is changing the values of the counters to make an unfair game into a fair game, which is called a martingale. With the new values, the expected fortune of player A (that is, the sum of the nominal values of his counters) after each play equals his fortune before the play (and similarly for player B). (For a simpler martingale argument, see Exercise 9.) De Moivre then uses the fact that when the game ends, it is still fair, thus Equation 12.8 must be true. This fact requires proof, and is one of the central theorems in the area of martingale theory. Exercises 1 In the gambler’s ruin problem, assume that the gambler initial stake is 1 dollar, and assume that her probability of success on any one game is p. Let T be the number of games until 0 is reached (the gambler is ruined). Show that the generating function for T is h(z) = 1 − p 1 −4pqz2 2pz , and that h(1) = q/p, if q ≤p, 1, if q ≥p, and h′(1) = 1/(q −p), if q > p, ∞, if q = p. Interpret your results in terms of the time T to reach 0. (See also Exam- ple 10.7.) 2 Show that the Taylor series expansion for √1 −x is √ 1 −x = ∞ X n=0 1/2 n xn , where the binomial coefficient | prob_Page_498_Chunk5337 |
12.2. GAMBLER’S RUIN 491 Using this and the result of Exercise 1, show that the probability that the gambler is ruined on the nth step is pT (n) = ( (−1)k−1 2p | prob_Page_499_Chunk5338 |
492 CHAPTER 12. RANDOM WALKS 7 In the game in Exercise 6, let p = q = 1/2 and M = 10. What is the probability that the gambler’s stake equals M at least 20 times before it returns to 0? 8 Write a computer program which simulates the game in Exercise 6 for the case p = q = 1/2, and M = 10. 9 In de Moivre’s description of the game, we can modify the definition of player A’s fortune in such a way that the game is still a martingale (and the calcula- tions are simpler). We do this by assigning nominal values to the counters in the same way as de Moivre, but each player’s current fortune is defined to be just the value of the counter which is being wagered on the next game. So, if player A has a counters, then his current fortune is (q/p)a (we stipulate this to be true even if a = 0). Show that under this definition, player A’s expected fortune after one play equals his fortune before the play, if p ̸= q. Then, as de Moivre does, write an equation which expresses the fact that player A’s expected final fortune equals his initial fortune. Use this equation to find the probability of ruin of player A. 10 Assume in the gambler’s ruin problem that p = q = 1/2. (a) Using Equation 12.7, together with the facts that q0 = 1 and qM = 0, show that for 0 ≤z ≤M, qz = M −z M . (b) In Equation 12.8, let p →1/2 (and since q = 1 −p, q →1/2 as well). Show that in the limit, qz = M −z M . Hint: Replace q by 1 −p, and use L’Hopital’s rule. 11 In American casinos, the roulette wheels have the integers between 1 and 36, together with 0 and 00. Half of the non-zero numbers are red, the other half are black, and 0 and 00 are green. A common bet in this game is to bet a dollar on red. If a red number comes up, the bettor gets her dollar back, and also gets another dollar. If a black or green number comes up, she loses her dollar. (a) Suppose that someone starts with 40 dollars, and continues to bet on red until either her fortune reaches 50 or 0. Find the probability that her fortune reaches 50 dollars. (b) How much money would she have to start with, in order for her to have a 95% chance of winning 10 dollars before going broke? (c) A casino owner was once heard to remark that “If we took 0 and 00 off of the roulette wheel, we would still make lots of money, because people would continue to come in and play until they lost all of their money.” Do you think that such a casino would stay in business? | prob_Page_500_Chunk5339 |
12.3. ARC SINE LAWS 493 12.3 Arc Sine Laws In Exercise 12.1.6, the distribution of the time of the last equalization in the sym- metric random walk was determined. If we let α2k,2m denote the probability that a random walk of length 2m has its last equalization at time 2k, then we have α2k,2m = u2ku2m−2k . We shall now show how one can approximate the distribution of the α’s with a simple function. We recall that u2k ∼ 1 √ πk . Therefore, as both k and m go to ∞, we have α2k,2m ∼ 1 π p k(m −k) . This last expression can be written as 1 πm p (k/m)(1 −k/m) . Thus, if we define f(x) = 1 π p x(1 −x) , for 0 < x < 1, then we have α2k,2m ≈1 mf k m . The reason for the ≈sign is that we no longer require that k get large. This means that we can replace the discrete α2k,2m distribution by the continuous density f(x) on the interval [0, 1] and obtain a good approximation. In particular, if x is a fixed real number between 0 and 1, then we have X k<xm α2k,2m ≈ Z x 0 f(t) dt . It turns out that f(x) has a nice antiderivative, so we can write X k<xm α2k,2m ≈2 π arcsin √x . One can see from the graph of this last function that it has a minimum at x = 1/2 and is symmetric about that point. As noted in the exercise, this implies that half of the walks of length 2m have no equalizations after time m, a fact which probably would not be guessed. It turns out that the arc sine density comes up in the answers to many other questions concerning random walks on the line. Recall that in Section 12.1, a | prob_Page_501_Chunk5340 |
494 CHAPTER 12. RANDOM WALKS random walk could be viewed as a polygonal line connecting (0, 0) with (m, Sm). Under this interpretation, we define b2k,2m to be the probability that a random walk of length 2m has exactly 2k of its 2m polygonal line segments above the t-axis. The probability b2k,2m is frequently interpreted in terms of a two-player game. (The reader will recall the game Heads or Tails, in Example 1.4.) Player A is said to be in the lead at time n if the random walk is above the t-axis at that time, or if the random walk is on the t-axis at time n but above the t-axis at time n −1. (At time 0, neither player is in the lead.) One can ask what is the most probable number of times that player A is in the lead, in a game of length 2m. Most people will say that the answer to this question is m. However, the following theorem says that m is the least likely number of times that player A is in the lead, and the most likely number of times in the lead is 0 or 2m. Theorem 12.4 If Peter and Paul play a game of Heads or Tails of length 2m, the probability that Peter will be in the lead exactly 2k times is equal to α2k,2m . Proof. To prove the theorem, we need to show that b2k,2m = α2k,2m . (12.9) Exercise 12.1.7 shows that b2m,2m = u2m and b0,2m = u2m, so we only need to prove that Equation 12.9 holds for 1 ≤k ≤m−1. We can obtain a recursion involving the b’s and the f’s (defined in Section 12.1) by counting the number of paths of length 2m that have exactly 2k of their segments above the t-axis, where 1 ≤k ≤m −1. To count this collection of paths, we assume that the first return occurs at time 2j, where 1 ≤j ≤m −1. There are two cases to consider. Either during the first 2j outcomes the path is above the t-axis or below the t-axis. In the first case, it must be true that the path has exactly (2k −2j) line segments above the t-axis, between t = 2j and t = 2m. In the second case, it must be true that the path has exactly 2k line segments above the t-axis, between t = 2j and t = 2m. We now count the number of paths of the various types described above. The number of paths of length 2j all of whose line segments lie above the t-axis and which return to the origin for the first time at time 2j equals (1/2)22jf2j. This also equals the number of paths of length 2j all of whose line segments lie below the t-axis and which return to the origin for the first time at time 2j. The number of paths of length (2m −2j) which have exactly (2k −2j) line segments above the t-axis is b2k−2j,2m−2j. Finally, the number of paths of length (2m −2j) which have exactly 2k line segments above the t-axis is b2k,2m−2j. Therefore, we have b2k,2m = 1 2 k X j=1 f2jb2k−2j,2m−2j + 1 2 m−k X j=1 f2jb2k,2m−2j . We now assume that Equation 12.9 is true for m < n. Then we have | prob_Page_502_Chunk5341 |
12.3. ARC SINE LAWS 495 0 10 20 30 40 0 0.02 0.04 0.06 0.08 0.1 0.12 Figure 12.2: Times in the lead. b2k,2n = 1 2 k X j=1 f2jα2k−2j,2m−2j + 1 2 m−k X j=1 f2jα2k,2m−2j = 1 2 k X j=1 f2ju2k−2ju2m−2k + 1 2 m−k X j=1 f2ju2ku2m−2j−2k = 1 2u2m−2k k X j=1 f2ju2k−2j + 1 2u2k m−k X j=1 f2ju2m−2j−2k = 1 2u2m−2ku2k + 1 2u2ku2m−2k , where the last equality follows from Theorem 12.2. Thus, we have b2k,2n = α2k,2n , which completes the proof. 2 We illustrate the above theorem by simulating 10,000 games of Heads or Tails, with each game consisting of 40 tosses. The distribution of the number of times that Peter is in the lead is given in Figure 12.2, together with the arc sine density. We end this section by stating two other results in which the arc sine density appears. Proofs of these results may be found in Feller.8 Theorem 12.5 Let J be the random variable which, for a given random walk of length 2m, gives the smallest subscript j such that Sj = S2m. (Such a subscript j must be even, by parity considerations.) Let γ2k,2m be the probability that J = 2k. Then we have γ2k,2m = α2k,2m . 2 8W. Feller, op. cit., pp. 93–94. | prob_Page_503_Chunk5342 |
496 CHAPTER 12. RANDOM WALKS The next theorem says that the arc sine density is applicable to a wide range of situations. A continuous distribution function F(x) is said to be symmetric if F(x) = 1 −F(−x). (If X is a continuous random variable with a symmetric distribution function, then for any real x, we have P(X ≤x) = P(X ≥−x).) We imagine that we have a random walk of length n in which each summand has the distribution F(x), where F is continuous and symmetric. The subscript of the first maximum of such a walk is the unique subscript k such that Sk > S0, . . . , Sk > Sk−1, Sk ≥Sk+1, . . . , Sk ≥Sn . We define the random variable Kn to be the subscript of the first maximum. We can now state the following theorem concerning the random variable Kn. Theorem 12.6 Let F be a symmetric continuous distribution function, and let α be a fixed real number strictly between 0 and 1. Then as n →∞, we have P(Kn < nα) →2 π arcsin √α . 2 A version of this theorem that holds for a symmetric random walk can also be found in Feller. Exercises 1 For a random walk of length 2m, define ϵk to equal 1 if Sk > 0, or if Sk−1 = 1 and Sk = 0. Define ϵk to equal -1 in all other cases. Thus, ϵk gives the side of the t-axis that the random walk is on during the time interval [k −1, k]. A “law of large numbers” for the sequence {ϵk} would say that for any δ > 0, we would have P −δ < ϵ1 + ϵ2 + · · · + ϵn n < δ →1 as n →∞. Even though the ϵ’s are not independent, the above assertion certainly appears reasonable. Using Theorem 12.4, show that if −1 ≤x ≤1, then lim n→∞P ϵ1 + ϵ2 + · · · + ϵn n < x = 2 π arcsin r 1 + x 2 . 2 Given a random walk W of length m, with summands {X1, X2, . . . , Xm} , define the reversed random walk to be the walk W ∗with summands {Xm, Xm−1, . . . , X1} . (a) Show that the kth partial sum S∗ k satisfies the equation S∗ k = Sm −Sn−k , where Sk is the kth partial sum for the random walk W. | prob_Page_504_Chunk5343 |
12.3. ARC SINE LAWS 497 (b) Explain the geometric relationship between the graphs of a random walk and its reversal. (It is not in general true that one graph is obtained from the other by reflecting in a vertical line.) (c) Use parts (a) and (b) to prove Theorem 12.5. | prob_Page_505_Chunk5344 |
498 CHAPTER 12. RANDOM WALKS | prob_Page_506_Chunk5345 |
Appendices 499 | prob_Page_507_Chunk5346 |
500 APPENDICES NA (0,d) = area of shaded region 0 d .00 .01 .02 .03 .04 .05 .06 .07 .08 .09 0.0 .0000 .0040 .0080 .0120 .0160 .0199 .0239 .0279 .0319 .0359 0.1 .0398 .0438 .0478 .0517 .0557 .0596 .0636 .0675 .0714 .0753 0.2 .0793 .0832 .0871 .0910 .0948 .0987 .1026 .1064 .1103 .1141 0.3 .1179 .1217 .1255 .1293 .1331 .1368 .1406 .1443 .1480 .1517 0.4 .1554 .1591 .1628 .1664 .1700 .1736 .1772 .1808 .1844 .1879 0.5 .1915 .1950 .1985 .2019 .2054 .2088 .2123 .2157 .2190 .2224 0.6 .2257 .2291 .2324 .2357 .2389 .2422 .2454 .2486 .2517 .2549 0.7 .2580 .2611 .2642 .2673 .2704 .2734 .2764 .2794 .2823 .2852 0.8 .2881 .2910 .2939 .2967 .2995 .3023 .3051 .3078 .3106 .3133 0.9 .3159 .3186 .3212 .3238 .3264 .3289 .3315 .3340 .3365 .3389 1.0 .3413 .3438 .3461 .3485 .3508 .3531 .3554 .3577 .3599 .3621 1.1 .3643 .3665 .3686 .3708 .3729 .3749 .3770 .3790 .3810 .3830 1.2 .3849 .3869 .3888 .3907 .3925 .3944 .3962 .3980 .3997 .4015 1.3 .4032 .4049 .4066 .4082 .4099 .4115 .4131 .4147 .4162 .4177 1.4 .4192 .4207 .4222 .4236 .4251 .4265 .4279 .4292 .4306 .4319 1.5 .4332 .4345 .4357 .4370 .4382 .4394 .4406 .4418 .4429 .4441 1.6 .4452 .4463 .4474 .4484 .4495 .4505 .4515 .4525 .4535 .4545 1.7 .4554 .4564 .4573 .4582 .4591 .4599 .4608 .4616 .4625 .4633 1.8 .4641 .4649 .4656 .4664 .4671 .4678 .4686 .4693 .4699 .4706 1.9 .4713 .4719 .4726 .4732 .4738 .4744 .4750 .4756 .4761 .4767 2.0 .4772 .4778 .4783 .4788 .4793 .4798 .4803 .4808 .4812 .4817 2.1 .4821 .4826 .4830 .4834 .4838 .4842 .4846 .4850 .4854 .4857 2.2 .4861 .4864 .4868 .4871 .4875 .4878 .4881 .4884 .4887 .4890 2.3 .4893 .4896 .4898 .4901 .4904 .4906 .4909 .4911 .4913 .4916 2.4 .4918 .4920 .4922 .4925 .4927 .4929 .4931 .4932 .4934 .4936 2.5 .4938 .4940 .4941 .4943 .4945 .4946 .4948 .4949 .4951 .4952 2.6 .4953 .4955 .4956 .4957 .4959 .4960 .4961 .4962 .4963 .4964 2.7 .4965 .4966 .4967 .4968 .4969 .4970 .4971 .4972 .4973 .4974 2.8 .4974 .4975 .4976 .4977 .4977 .4978 .4979 .4979 .4980 .4981 2.9 .4981 .4982 .4982 .4983 .4984 .4984 .4985 .4985 .4986 .4986 3.0 .4987 .4987 .4987 .4988 .4988 .4989 .4989 .4989 .4990 .4990 3.1 .4990 .4991 .4991 .4991 .4992 .4992 .4992 .4992 .4993 .4993 3.2 .4993 .4993 .4994 .4994 .4994 .4994 .4994 .4995 .4995 .4995 3.3 .4995 .4995 .4995 .4996 .4996 .4996 .4996 .4996 .4996 .4997 3.4 .4997 .4997 .4997 .4997 .4997 .4997 .4997 .4997 .4997 .4998 3.5 .4998 .4998 .4998 .4998 .4998 .4998 .4998 .4998 .4998 .4998 3.6 .4998 .4998 .4999 .4999 .4999 .4999 .4999 .4999 .4999 .4999 3.7 .4999 .4999 .4999 .4999 .4999 .4999 .4999 .4999 .4999 .4999 3.8 .4999 .4999 .4999 .4999 .4999 .4999 .4999 .4999 .4999 .4999 3.9 .5000 .5000 .5000 .5000 .5000 .5000 .5000 .5000 .5000 .5000 Appendix A Normal distribution table | prob_Page_508_Chunk5347 |
APPENDICES 501 Above . . . . . . . . . . . . . . . . . . . . . . . . 1 3 . . 4 5 . . 72.5 . . . . . . . . . . . . . . 1 2 1 2 7 2 4 19 6 72.2 71.5 . . . . . . . . 1 3 4 3 5 10 4 9 2 2 43 11 69.9 70.5 1 . . 1 . . 1 1 3 12 18 14 7 4 3 3 68 22 69.5 69.5 . . . . 1 16 4 17 27 20 33 25 20 11 4 5 183 41 68.9 68.5 1 . . 7 11 16 25 31 34 48 21 18 4 3 . . 219 49 68.2 67.5 . . 3 5 14 15 36 38 28 38 19 11 4 . . . . 211 33 67.6 66.5 . . 3 3 5 2 17 17 14 13 4 . . . . . . . . 78 20 67.2 65.5 1 . . 9 5 7 11 11 7 7 5 2 1 . . . . 66 12 66.7 64.5 1 1 4 4 1 5 5 . . 2 . . . . . . . . . . 23 5 65.8 Below . . 1 . . 2 4 1 2 2 1 1 . . . . . . . . . . 14 1 . . Totals . . 5 7 32 59 48 117 138 120 167 99 64 41 17 14 928 205 . . Medians . . . . . . 66.3 67.8 67.9 67.7 67.9 68.3 68.5 69.0 69.0 70.0 . . . . . . . . . . Heights of the Mid-parents in inches. Below 62.2 63.2 64.2 65.2 66.2 67.2 68.2 69.2 70.2 71.2 72.2 73.2 Above children. Heights of the adult children. Total number of Adult Mid- parents. Medians Number of adult children of various statures born of 205 mid-parents of various statures. (All female heights have been multiplied by 1.08) Note. In calculating the Medians, the entries have been taken as referring to the middle of the squares in which they stand. The reason why the headings run 62.2, 63.2, &c., instead of 62.5, 63.5, &c., is that the observations are unequally distributed between 62 and 63, 63 and 64, &c., there being a strong bias in favour of integral inches. After careful consideration, I concluded that the headings, as adopted, best satisfied the conditions. This inequality was not apparent in the case of the Mid-parents. Source: F. Galton, "Regression towards Mediocrity in Hereditary Stature", Royal Anthropological Institute of Great Britain and Ireland, vol.15 (1885), p.248. Appendix B | prob_Page_509_Chunk5348 |
502 APPENDICES Appendix C Life Table Number of survivors at single years of Age, out of 100,000 Born Alive, by Race and Sex: United States, 1990. 0 100000 100000 100000 43 94707 92840 96626 1 99073 98969 99183 44 94453 92505 96455 2 99008 98894 99128 45 94179 92147 96266 3 98959 98840 99085 46 93882 91764 96057 4 98921 98799 99051 47 93560 91352 95827 5 98890 98765 99023 48 93211 90908 95573 6 98863 98735 99000 49 92832 90429 95294 7 98839 98707 98980 50 92420 89912 94987 8 98817 98680 98962 51 91971 89352 94650 9 98797 98657 98946 52 91483 88745 94281 10 98780 98638 98931 53 90950 88084 93877 11 98765 98623 98917 54 90369 87363 93436 12 98750 98608 98902 55 89735 86576 92955 13 98730 98586 98884 56 89045 85719 92432 14 98699 98547 98862 57 88296 84788 91864 15 98653 98485 98833 58 87482 83777 91246 16 98590 98397 98797 59 86596 82678 90571 17 98512 98285 98753 60 85634 81485 89835 18 98421 98154 98704 61 84590 80194 89033 19 98323 98011 98654 62 83462 78803 88162 20 98223 97863 98604 63 82252 77314 87223 21 98120 97710 98555 64 80961 75729 86216 22 98015 97551 98506 65 79590 74051 85141 23 97907 97388 98456 66 78139 72280 83995 24 97797 97221 98405 67 76603 70414 82772 25 97684 97052 98351 68 74975 68445 81465 26 97569 96881 98294 69 73244 66364 80064 27 97452 96707 98235 70 71404 64164 78562 28 97332 96530 98173 71 69453 61847 76953 29 97207 96348 98107 72 67392 59419 75234 30 97077 96159 98038 73 65221 56885 73400 31 96941 95962 97965 74 62942 54249 71499 32 96800 95785 97887 75 60557 51519 69376 33 96652 95545 97804 76 58069 48704 67178 34 96497 95322 97717 77 55482 45816 64851 35 96334 95089 97624 78 52799 42867 62391 36 96161 94843 97525 79 50026 39872 59796 37 95978 94585 97419 80 47168 36848 57062 38 95787 94316 97306 81 44232 33811 54186 39 95588 94038 97187 82 41227 30782 51167 40 95382 93753 97061 83 38161 27782 48002 41 95168 93460 96926 84 35046 24834 44690 42 94944 93157 96782 85 31892 21962 41230 Age Both sexes Male Female Age Both sexes Male Female All races All races | prob_Page_510_Chunk5349 |
Index π, estimation of, 43–46 n!, 80 absorbing Markov chain, 416 absorbing state, 416 AbsorbingChain (program), 421 absorption probabilities, 420 Ace, Mr., 241 Ali, 178 alleles, 348 AllPermutations (program), 84 ANDERSON, C. L., 157 annuity, 246 life, 247 terminal, 247 arc sine laws, 493 area, estimation of, 42 Areabargraph (program), 46 asymptotically equal, 81 Baba, 178 babies, 14, 250 Banach’s Matchbox, 255 BAR-HILLEL, M., 176 BARNES, B., 175 BARNHART, R., 11 BAYER, D., 120 Bayes (program), 147 Bayes probability, 136 Bayes’ formula, 146 BAYES, T., 149 beard, 153 bell-shaped, 47 Benford distribution, 195 BENKOSKI, S., 40 Bernoulli trials process, 96 BERNOULLI, D., 227 BERNOULLI, J., 113, 149, 310–312 Bertrand’s paradox, 47–50 BERTRAND, J., 49, 181 BertrandsParadox (program), 49 beta density, 168 BIENAYM´E, I., 310, 377 BIGGS, N. L., 85 binary expansion, 69 binomial coefficient, 93 binomial distribution, 99, 184 approximating a, 329 Binomial Theorem, 103 BinomialPlot (program), 99 BinomialProbabilities (program), 98 Birthday (program), 78 birthday problem, 77 blackjack, 247, 253 blood test, 254 Bose-Einstein statistics, 107 Box paradox, 181 BOX, G. E. P., 213 boxcars, 27 BRAMS, S., 179, 182 Branch (program), 381 branching process, 376 customer, 393 BranchingSimulation (program), 386 bridge, 181, 182, 199, 203, 287 BROWN, B. H., 38 BROWN, E., 425 Buffon’s needle, 44–46, 51–53 BUFFON, G. L., 9, 44, 50–51 BuffonsNeedle (program), 45 bus paradox, 164 calendar, 38 cancer, 147 503 | prob_Page_511_Chunk5350 |
504 INDEX canonical form of an absorbing Markov chain, 416 car, 137 CARDANO, G., 30–31, 110, 249 cars on a highway, 66 CASANOVA, G., 11 Cauchy density, 218, 400 cells, 347 Central Limit Theorem, 325 for Bernoulli Trials, 330 for Binomial Distributions, 328 for continuous independent trials process, 357 for discrete independent random variables, 345 for discrete independent trials process, 343 for Markov Chains, 464 proof of, 397 chain letter, 388 characteristic function, 397 Chebyshev Inequality, 305, 316 CHEBYSHEV, P. L., 313 chi-squared density, 216, 296 Chicago World’s Fair, 52 chord, random, 47, 54 chromosomes, 348 CHU, S.-C., 110 CHUNG, K. L., 153 Circle of Gold, 388 Clinton, Bill, 196 clover-leaf interchange, 39 CLTBernoulliGlobal, 332 CLTBernoulliLocal (program), 329 CLTBernoulliPlot (program), 327 CLTGeneral (program), 345 CLTIndTrialsLocal (program), 342 CLTIndTrialsPlot (program), 341 COATES, R. M., 305 CoinTosses (program), 3 Collins, People v., 153, 202 color-blindness, 424 conditional density, 162 conditional distribution, 134 conditional expectation, 239 conditional probability, 133 CONDORCET, Le Marquis de, 12 confidence interval, 334, 360 conjunction fallacy, 38 continuum, 41 convolution, 286, 291 of binomial distributions, 289 of Cauchy densities, 294 of exponential densities, 292, 300 of geometric distributions, 289 of normal densities, 294 of standard normal densities, 299 of uniform densities, 292, 299 CONWAY, J., 432 CRAMER, G., 227 craps, 235, 240, 468 Craps (program), 235 CROSSEN, C., 161 CROWELL, R., 468 cumulative distribution function, 61 joint, 165 customer branching process, 393 cut, 120 Dartmouth, 27 darts, 56, 57, 59, 60, 64, 71, 163, 164 Darts (program), 58 DAVID, F. N., 86, 337, 489 DAVID, F. N., 32 de M´ER´E, CHEVALIER, 4, 31, 37 de MOIVRE, A., 37, 88, 148, 336, 489 de MONTMORT, P. R., 85 degrees of freedom, 217 DeMere1 (program), 4 DeMere2 (program), 4 density function, 56, 59 beta, 168 Cauchy, 218, 400 chi-squared, 216, 296 conditional, 162 exponential, 53, 66, 163, 205 gamma, 207 joint, 165 log normal, 224 Maxwell, 215 | prob_Page_512_Chunk5351 |
INDEX 505 normal, 212 Rayleigh, 215, 295 t-, 360 uniform, 60, 205 derangement, 85 DIACONIS, P., 120, 251 Die (program), 225 DieTest (program), 297 distribution function, 1, 19 properties of, 22 Benford, 195 binomial, 99, 184 geometric, 184 hypergeometric, 193 joint, 142 marginal, 143 negative binomial, 186 Poisson, 187 uniform, 183 DNA, 348 DOEBLIN, W., 449 DOYLE, P. G., 87, 452, 470 Drunkard’s Walk example, 416, 419– 421, 423, 427, 443 Dry Gulch, 280 EDWARDS, A. W. F., 108 Egypt, 30 Ehrenfest model, 410, 433, 441, 460, 461 EHRENFEST, P., 410 EHRENFEST, T, 410 EhrenfestUrn (program), 462 EISENBERG, B., 160 elevator, 89, 116 Emile’s restaurant, 75 ENGLE, A., 445 envelopes, 179, 180 EPSTEIN, R., 287 equalization, 472 equalizations expected number of, 479 ergodic Markov chain, 433 ESP, 250, 251 EUCLID, 85 Euler’s formula, 202 Eulerian number, 127 event, 18 events attraction of, 160 independent, 139, 164 repulsion of, 160 existence of God, 245 expected value, 226, 268 exponential density, 53, 66, 163, 205 extinction, problem of, 378 factorial, 80 fair game, 241 FALK, R., 161, 176 fall, 131 fallacy, 38 FELLER, W., 11, 106, 107, 191, 201, 218, 254, 344 FERMAT, P., 4, 32–35, 112–113, 156 Fermi-Dirac statistics, 107 figurate numbers, 108 financial records suspicious, 196 finite additivity property, 23 FINN, J., 178 First Fundamental Mystery of Proba- bility, 232 first maximum of a random walk, 496 first return to the origin, 473 Fisher’s Exact Test, 193 FISHER, R. A., 252 fixed column vector, 435 fixed points, 82 fixed row vector, 435 FixedPoints (program), 82 FixedVector (program), 437 flying bombs, 191, 201 Fourier transform, 397 FRECHET, M., 466 frequency concept of probability, 70 frustration solitaire, 86 Fundamental Limit Theorem for Reg- ular Markov Chains, 448 fundamental matrix, 419 | prob_Page_513_Chunk5352 |
506 INDEX for a regular Markov chain, 457 for an ergodic Markov chain, 458 GALAMBOS, J., 303 GALILEO, G., 13 Gallup Poll, 14, 335 Galton board, 99, 351 GALTON, F., 282, 345, 350, 376 GaltonBoard (program), 99 Gambler’s Ruin, 426, 486, 487 gambling systems, 241 gamma density, 207 GARDNER, M., 181 gas diffusion Ehrenfest model of, 410, 433, 441, 460, 461 GELLER, S., 176 GeneralSimulation (program), 9 generating function for continuous density, 393 moment, 366, 394 ordinary, 369 genes, 348, 411 genetics, 345 genotypes, 348 geometric distribution, 184 geometric series, 29 GHOSH, B. K., 160 goat, 137 GONSHOR, H., 425 GOSSET, W. S., 360 grade point average, 343 GRAHAM, R., 251 GRANBERG, D., 161 GRAUNT, J., 246 Greece, 30 GRIDGEMAN, N. T., 51, 181 GRINSTEAD, C. M., 87 GUDDER, S., 160 HACKING, I., 30, 148 HAMMING, R. W., 284 HANES data, 345 Hangtown, 280 Hanover Inn, 65 hard drive, Warp 9, 66 Hardy-Weinberg Law, 349 harmonic function, 428 Harvard, 27 hat check problem, 82, 85, 105 heights distribution of, 345 helium, 107 HEYDE, C., 377 HILL, T., 196 Holmes, Sherlock, 91 HorseRace (program), 6 hospital, 14, 250 HOWARD, R. A., 406 HTSimulation (program), 6 HUDDE, J., 148 HUIZINGA, F., 388 HUYGENS, C., 147, 243–245 hypergeometric distribution, 193 hypotheses, 145 hypothesis testing, 101 Inclusion-Exclusion Principle, 104 independence of events, 139, 164 mutual, 141 independence of random variables mutual, 143, 165 independence of random variables, 143, 165 independent trials process, 144, 168 interarrival time, average, 208 interleaving, 120 irreducible Markov chain, 433 Isle Royale, 202 JAYNES, E. T., 49 JOHNSONBOUGH, R., 153 joint cumulative distribution function, 165 joint density function, 165 joint distribution function, 142 joint random variable, 142 KAHNEMAN, D., 38 Kemeny’s constant, 469, 470 KEMENY, J. G., 200, 406, 466 | prob_Page_514_Chunk5353 |
INDEX 507 KENDALL, D. G., 377 KEYFITZ, N., 382 KILGOUR, D. M., 179, 182 KINGSTON, J. G., 157 KONOLD, C., 161 KOZELKA, R. M., 344 Labouchere betting system, 12, 13 LABOUCHERE, H. du P., 12 LAMPERTI, J., 267, 324 LAPLACE, P. S., 51, 53, 350 last return to the origin, 482 Law (program), 310 Law of Averages, 70 Law of Large Numbers, 307, 316 for Ergodic Markov Chains, 439 Strong, 70 LawContinuous (program), 318 lead change, 482 LEONARD, B., 256 LEONTIEF, W. W., 426 LEVASSEUR, K., 485 library problem, 82 life table, 39 light bulb, 66, 72, 172 Linda problem, 38 LINDEBERG, J. W., 344 LIPSON, A., 161 Little’s law for queues, 276 Lockhorn, Mr. and Mrs., 65 log normal density, 224 lottery Powerball, 204 LUCAS, E., 119 LUSINCHI, D., 12 MAISTROV, L., 150, 310 MANN, B., 120 margin of error, 335 marginal distribution function, 143 Markov chain, 405 absorbing, 416 ergodic, 433 irreducible, 433 regular, 433 Markov Chains Central Limit Theorem for, 464 Fundamental Limit Theorem for Regular, 448 MARKOV, A. A., 464 martingale, 241, 242, 428 origin of word, 11 martingale betting system, 11, 14, 248 matrix fundamental, 419 MatrixPowers (program), 407 maximum likelihood estimate, 198, 202 Maximum Likelihood Principle, 91, 117 Maxwell density, 215 maze, 440, 453 McCRACKEN, D., 10 mean, 226 mean first passage matrix, 455 mean first passage time, 453 mean recurrence matrix, 455 mean recurrence time, 454 memoryless property, 68, 164, 206 milk, 252 modular arithmetic, 10 moment generating function, 366, 394 moment problem, 368, 397 moments, 365, 393 Monopoly, 469 MonteCarlo (program), 42 Monty Hall problem, 136, 161 moose, 202 mortality table, 246 mule kicks, 201 MULLER, M. E., 213 multiple-gene hypothesis, 348 mustache, 153 mutually independent events, 141 mutually independent random variables, 143 negative binomial distribution, 186 New York Times, 340 New York Yankees, 118, 253 | prob_Page_515_Chunk5354 |
508 INDEX New-Age Solitaire, 130 NEWCOMB, S., 196 NFoldConvolution (program), 287 NIGRINI, M., 196 normal density, 47, 212 NormalArea (program), 322 nursery rhyme, 84 odds, 27 ordering, random, 127 ordinary generating function, 369 ORE, O., 30, 31 outcome, 18 Oz, Land of, 406, 439 P´OLYA, G., 15, 17, 475 Pascal’s triangle, 94, 103, 108 PASCAL, B., 4, 32–35, 107, 112–113, 156, 242, 245 paternity suit, 222 PEARSON, K., 9, 351 PENNEY, W., 432 People v. Collins, 153, 202 PERLMAN, M. D., 45 permutation, 79 fixed points of, 82 Philadelphia 76ers, 15 photons, 106 Pickwick, Mr., 153 PilsdorffBeer Company, 280 PITTEL, B., 256 point count, 287 Poisson approximation to the binomial distribution, 189 Poisson distribution, 187 variance of, 263 poker, 95 polls, 333 Polya urn model, 152, 174 ponytail, 153 posterior probabilities, 145 Powerball lottery, 204 PowerCurve (program), 102 Presidential election, 335 PRICE, C., 86 prior probabilities, 145 probability Bayes, 136 conditional, 133 frequency concept of, 2 of an event, 19 transition, 406 vector, 407 problem of points, 32, 112, 147, 156 process, random, 128 PROPP, J., 256 PROSSER, R., 200 protons, 106 quadratic equation, roots of, 73 quantum mechanics, 107 QUETELET, A., 350 Queue (program), 208 queues, 186, 208, 275 quincunx, 351 R´ENYI, A., 167 RABELAIS, F., 12 racquetball, 157 radioactive isotope, 66, 71 RAND Corporation, 10 random integer, 39 random number generator, 2 random ordering, 127 random process, 128 random variable, 1, 18 continuous, 58 discrete, 18 functions of a, 210 joint, 142 random variables independence of, 143 mutual independence of, 143 random walk, 471 in n dimensions, 17 RandomNumbers (program), 3 RandomPermutation (program), 82 rank event, 160 raquetball, 13 rat, 440, 453 | prob_Page_516_Chunk5355 |
INDEX 509 Rayleigh density, 215, 295 records, 83, 234 Records (program), 84 regression on the mean, 282 regression to the mean, 345, 352 regular Markov chain, 433 reliability of a system, 154 restricted choice, principle of, 182 return to the origin, 472 first, 473 last, 482 probability of eventual, 475 reversibility, 463 reversion, 352 riffle shuffle, 120 RIORDAN, J., 86 rising sequence, 120 rnd, 42 ROBERTS, F., 426 Rome, 30 ROSS, S., 270, 276 roulette, 13, 237, 432 run, 229 SAGAN, H., 237 sample, 333 sample mean, 265 sample space, 18 continuous, 58 countably infinite, 28 infinite, 28 sample standard deviation, 265 sample variance, 265 SAWYER, S., 412 SCHULTZ, H., 255 SENETA, E., 377, 444 service time, average, 208 SHANNON, C. E., 465 SHOLANDER, M., 39 shuffling, 120 SHULTZ, H., 256 SimulateChain (program), 439 simulating a random variable, 211 snakeeyes, 27 SNELL, J. L., 87, 175, 406, 466 snowfall in Hanover, 83 spike graph, 6 Spikegraph (program), 6 spinner, 41, 55, 59, 162 spread, 266 St. Ives, 84 St. Petersburg Paradox, 227 standard deviation, 257 standard normal random variable, 213 standardized random variable, 264 standardized sum, 326 state absorbing, 416 of a Markov chain, 405 transient, 416 statistics applications of the Central Limit Theorem to, 333 stepping stones, 412 SteppingStone (program), 413 stick of unit length, 73 STIFEL, M., 110 STIGLER, S., 350 Stirling’s formula, 81 STIRLING, J., 88 StirlingApproximations (program), 81 stock prices, 241 StockSystem (program), 241 Strong Law of Large Numbers, 70, 314 suit event, 160 SUTHERLAND, E., 182 t-density, 360 TARTAGLIA, N., 110 tax returns, 196 tea, 252 telephone books, 256 tennis, 157, 424 tetrahedral numbers, 108 THACKERAY, W. M., 14 THOMPSON, G. L., 406 THORP, E., 247, 253 | prob_Page_517_Chunk5356 |
510 INDEX time to absorption, 419 TIPPETT, L. H. C., 10 traits, independence of, 216 transient state, 416 transition matrix, 406 transition probability, 406 tree diagram, 24, 76 infinite binary, 69 Treize, 85 triangle acute, 73 triangular numbers, 108 trout, 198 true-false exam, 267 Tunbridge, 154 TVERSKY, A., 14, 38 Two aces problem, 181 two-armed bandit, 170 TwoArm (program), 171 type 1 error, 101 type 2 error, 101 typesetter, 189 ULAM, S., 11 unbiased estimator, 266 uniform density, 205 uniform density function, 60 uniform distribution, 25, 183 uniform random variables sum of two continuous, 63 unshuffle, 122 USPENSKY, J. B., 299 utility function, 227 VANDERBEI, R., 175 variance, 257, 271 calculation of, 258 variation distance, 128 VariationList (program), 128 volleyball, 158 von BORTKIEWICZ, L., 201 von MISES, R., 87 von NEUMANN, J., 10, 11 vos SAVANT, M., 40, 86, 136, 176, 181 Wall Street Journal, 161 watches, counterfeit, 91 WATSON, H. W., 377 WEAVER, W., 465 Weierstrass Approximation Theorem, 315 WELDON, W. F. R., 9 Wheaties, 118, 253 WHITAKER, C., 136 WHITEHEAD, J. H. C., 181 WICHURA, M. J., 45 WILF, H. S., 91, 474 WOLF, R., 9 WOLFORD, G., 159 Woodstock, 154 Yang, 130 Yin, 130 ZAGIER, D., 485 Zorg, planet of, 90 | prob_Page_518_Chunk5357 |
1.7 Real Stuff: Manufacturing and Benchmarking the AMD Opteron X4 44 1.8 Fallacies and Pitfalls 51 1.9 Concluding Remarks 54 1.10 Historical Perspective and Further Reading 55 1.11 Exercises 56 1.1 Introduction Welcome to this book! We’re delighted to have this opportunity to convey the excitement of the world of computer systems. This is not a dry and dreary field, where progress is glacial and where new ideas atrophy from neglect. No! Comput ers are the product of the incredibly vibrant information technology industry, all aspects of which are responsible for almost 10% of the gross national product of the United States, and whose economy has become dependent in part on the rapid improvements in information technology promised by Moore’s law. This unusual industry embraces innovation at a breathtaking rate. In the last 25 years, there have been a number of new computers whose introduction appeared to revolutionize the computing industry; these revolutions were cut short only because someone else built an even better computer. This race to innovate has led to unprecedented progress since the inception of electronic computing in the late 1940s. Had the transportation industry kept pace with the computer industry, for example, today we could travel from New York to London in about a second for roughly a few cents. Take just a moment to contemplate how such an improvement would change society—living in Tahiti while working in San Francisco, going to Moscow for an evening at the Bolshoi Ballet—and you can appreciate the implications of such a change. | clipped_hennesy_Page_1_Chunk5358 |
4 Chapter 1 Computer Abstractions and Technology Computers have led to a third revolution for civilization, with the information revolution taking its place alongside the agricultural and the industrial revolu tions. The resulting multiplication of humankind’s intellectual strength and reach naturally has affected our everyday lives profoundly and changed the ways in which the search for new knowledge is carried out. There is now a new vein of scientific investigation, with computational scientists joining theoretical and experimental scientists in the exploration of new frontiers in astronomy, biology, chemistry, and physics, among others. The computer revolution continues. Each time the cost of computing improves by another factor of 10, the opportunities for computers multiply. Applications that were economically infeasible suddenly become practical. In the recent past, the following applications were “computer science fiction.” ■ ■Computers in automobiles: Until microprocessors improved dramatically in price and performance in the early 1980s, computer control of cars was ludi crous. Today, computers reduce pollution, improve fuel efficiency via engine controls, and increase safety through the prevention of dangerous skids and through the inflation of air bags to protect occupants in a crash. ■ ■Cell phones: Who would have dreamed that advances in computer systems would lead to mobile phones, allowing person-to-person communication almost anywhere in the world? ■ ■Human genome project: The cost of computer equipment to map and ana lyze human DNA sequences is hundreds of millions of dollars. It’s unlikely that anyone would have considered this project had the computer costs been 10 to 100 times higher, as they would have been 10 to 20 years ago. More over, costs continue to drop; you may be able to acquire your own genome, allowing medical care to be tailored to you. ■ ■World Wide Web: Not in existence at the time of the first edition of this book, the World Wide Web has transformed our society. For many, the WWW has replaced libraries. ■ ■Search engines: As the content of the WWW grew in size and in value, find ing relevant information became increasingly important. Today, many peo ple rely on search engines for such a large part of their lives that it would be a hardship to go without them. Clearly, advances in this technology now affect almost every aspect of our soci ety. Hardware advances have allowed programmers to create wonderfully useful software, which explains why computers are omnipresent. Today’s science fiction suggests tomorrow’s killer applications: already on their way are virtual worlds, practical speech recognition, and personalized health care. | clipped_hennesy_Page_2_Chunk5359 |
1.1 Introduction 5 Classes of Computing Applications and Their Characteristics Although a common set of hardware technologies (see Sections 1.3 and 1.7) is used in computers ranging from smart home appliances to cell phones to the largest supercomputers, these different applications have different design requirements and employ the core hardware technologies in different ways. Broadly speaking, computers are used in three different classes of applications. Desktop computers are possibly the best-known form of computing and are characterized by the personal computer, which readers of this book have likely used extensively. Desktop computers emphasize delivery of good performance to single users at low cost and usually execute third-party software. The evolution of many computing technologies is driven by this class of computing, which is only about 30 years old! Servers are the modern form of what were once mainframes, minicomputers, and supercomputers, and are usually accessed only via a network. Servers are ori ented to carrying large workloads, which may consist of either single complex applications—usually a scientific or engineering application—or handling many small jobs, such as would occur in building a large Web server. These applications are usually based on software from another source (such as a database or simula tion system), but are often modified or customized for a particular function. Serv ers are built from the same basic technology as desktop computers, but provide for greater expandability of both computing and input/output capacity. In general, servers also place a greater emphasis on dependability, since a crash is usually more costly than it would be on a single-user desktop computer. Servers span the widest range in cost and capability. At the low end, a server may be little more than a desktop computer without a screen or keyboard and cost a thousand dollars. These low-end servers are typically used for file storage, small business applications, or simple Web serving (see Section 6.10). At the other extreme are supercomputers, which at the present consist of hundreds to thou sands of processors and usually terabytes of memory and petabytes of storage, and cost millions to hundreds of millions of dollars. Supercomputers are usually used for high-end scientific and engineering calculations, such as weather forecasting, oil exploration, protein structure determination, and other large-scale problems. Although such supercomputers represent the peak of computing capability, they represent a relatively small fraction of the servers and a relatively small fraction of the overall computer market in terms of total revenue. Although not called supercomputers, Internet datacenters used by companies like eBay and Google also contain thousands of processors, terabytes of memory, and petabytes of storage. These are usually considered as large clusters of comput ers (see Chapter 7). Embedded computers are the largest class of computers and span the wid est range of applications and performance. Embedded computers include the desktop computer A computer designed for use by an individual, usually incorporating a graphics display, a key board, and a mouse. server A computer used for running larger programs for multiple users, often simultaneously, and typically accessed only via a network. supercomputer A class of computers with the highest performance and cost; they are configured as servers and typically cost millions of dollars. terabyte Originally 1,099,511,627,776 (240) bytes, although some communications and secondary storage systems have redefined it to mean 1,000,000,000,000 (1012) bytes. petabyte Depending on the situation, either 1000 or 1024 terabytes. datacenter A room or building designed to handle the power, cooling, and networking needs of a large number of servers. embedded computer A computer inside another device used for running one predetermined application or collection of software. | clipped_hennesy_Page_3_Chunk5360 |
6 Chapter 1 Computer Abstractions and Technology microprocessors found in your car, the computers in a cell phone, the computers in a video game or television, and the networks of processors that control a mod ern airplane or cargo ship. Embedded computing systems are designed to run one application or one set of related applications, that are normally integrated with the hardware and delivered as a single system; thus, despite the large number of embedded computers, most users never really see that they are using a computer! Figure 1.1 shows that during the last several years, the growth in cell phones that rely on embedded computers has been much faster than the growth rate of desktop computers. Note that the embedded computers are also found in digital TVs and set-top boxes, automobiles, digital cameras, music players, video games, and a variety of other such consumer devices, which further increases the gap between the number of embedded computers and desktop computers. 0 100 200 300 400 500 600 700 Millions 800 900 1000 1100 1200 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 Cell Phones PCs TVs FIGURE 1.1 The number of cell phones, personal computers, and televisions manufactured per year between 1997 and 2007. (We have television data only from 2004.) More than a billion new cell phones were shipped in 2006. Cell phones sales exceeded PCs by only a factor of 1.4 in 1997, but the ratio grew to 4.5 in 2007. The total number in use in 2004 is estimated to be about 2.0B televisions, 1.8B cell phones, and 0.8B PCs. As the world population was about 6.4B in 2004, there were approximately one PC, 2.2 cell phones, and 2.5 televisions for every eight people on the planet. A 2006 survey of U.S. families found that they owned on average 12 gadgets, including three TVs, 2 PCs, and other devices such as game consoles, MP3 players, and cell phones. | clipped_hennesy_Page_4_Chunk5361 |
1.1 Introduction 7 Embedded applications often have unique application requirements that combine a minimum performance with stringent limitations on cost or power. For example, consider a music player: the processor need only be as fast as necessary to handle its limited function, and beyond that, minimizing cost and power are the most important objectives. Despite their low cost, embedded computers often have lower tolerance for failure, since the results can vary from upsetting (when your new television crashes) to devastating (such as might occur when the computer in a plane or cargo ship crashes). In consumer-oriented embedded applications, such as a digital home appliance, dependability is achieved primarily through simplic ity—the emphasis is on doing one function as perfectly as possible. In large embed ded systems, techniques of redundancy from the server world are often employed (see Section 6.9). Although this book focuses on general-purpose computers, most concepts apply directly, or with slight modifications, to embedded computers. Elaboration: Elaborations are short sections used throughout the text to provide more detail on a particular subject that may be of interest. Disinterested readers may skip over an elaboration, since the subsequent material will never depend on the contents of the elaboration. Many embedded processors are designed using processor cores, a version of a proces- sor written in a hardware description language, such as Verilog or VHDL (see Chapter 4). The core allows a designer to integrate other application-specific hardware with the pro- cessor core for fabrication on a single chip. What You Can Learn in This Book Successful programmers have always been concerned about the performance of their programs, because getting results to the user quickly is critical in creating successful software. In the 1960s and 1970s, a primary constraint on computer performance was the size of the computer’s memory. Thus, programmers often followed a simple credo: minimize memory space to make programs fast. In the last decade, advances in computer design and memory technology have greatly reduced the importance of small memory size in most applications other than those in embedded computing systems. Programmers interested in performance now need to understand the issues that have replaced the simple memory model of the 1960s: the parallel nature of processors and the hierarchical nature of memories. Programmers who seek to build competitive versions of compilers, operating systems, databases, and even applications will therefore need to increase their knowledge of computer organization. We are honored to have the opportunity to explain what’s inside this revolution ary machine, unraveling the software below your program and the hardware under the covers of your computer. By the time you complete this book, we believe you will be able to answer the following questions: | clipped_hennesy_Page_5_Chunk5362 |
8 Chapter 1 Computer Abstractions and Technology ■ ■How are programs written in a high-level language, such as C or Java, trans lated into the language of the hardware, and how does the hardware execute the resulting program? Comprehending these concepts forms the basis of understanding the aspects of both the hardware and software that affect program performance. ■ ■What is the interface between the software and the hardware, and how does software instruct the hardware to perform needed functions? These concepts are vital to understanding how to write many kinds of software. ■ ■What determines the performance of a program, and how can a program mer improve the performance? As we will see, this depends on the original program, the software translation of that program into the computer’s language, and the effectiveness of the hardware in executing the program. ■ ■What techniques can be used by hardware designers to improve performance? This book will introduce the basic concepts of modern computer design. The interested reader will find much more material on this topic in our advanced book, Computer Architecture: A Quantitative Approach. ■ ■What are the reasons for and the consequences of the recent switch from sequential processing to parallel processing? This book gives the motivation, describes the current hardware mechanisms to support parallelism, and surveys the new generation of “multicore” microprocessors (see Chapter 7). Without understanding the answers to these questions, improving the perfor mance of your program on a modern computer, or evaluating what features might make one computer better than another for a particular application, will be a complex process of trial and error, rather than a scientific procedure driven by insight and analysis. This first chapter lays the foundation for the rest of the book. It introduces the basic ideas and definitions, places the major components of software and hardware in perspective, shows how to evaluate performance and power, introduces inte grated circuits (the technology that fuels the computer revolution), and explains the shift to multicores. In this chapter and later ones, you will likely see many new words, or words that you may have heard but are not sure what they mean. Don’t panic! Yes, there is a lot of special terminology used in describing modern computers, but the ter minology actually helps, since it enables us to describe precisely a function or capability. In addition, computer designers (including your authors) love using acronyms, which are easy to understand once you know what the letters stand for! To help you remember and locate terms, we have included a highlighted defini tion of every term in the margins the first time it appears in the text. After a short time of working with the terminology, you will be fluent, and your friends will be impressed as you correctly use acronyms such as BIOS, CPU, DIMM, DRAM, PCIE, SATA, and many others. multicore microprocessor A microprocessor containing multiple processors (“cores”) in a single integrated circuit. acronym A word constructed by taking the initial letters of a string of words. For example: RAM is an acronym for Random Access Memory, and CPU is an acronym for Central Processing Unit. | clipped_hennesy_Page_6_Chunk5363 |
1.1 Introduction 9 To reinforce how the software and hardware systems used to run a program will affect performance, we use a special section, Understanding Program Performance, throughout the book to summarize important insights into program performance. The first one appears below. The performance of a program depends on a combination of the effectiveness of the algorithms used in the program, the software systems used to create and trans late the program into machine instructions, and the effectiveness of the computer in executing those instructions, which may include input/output (I/O) operations. This table summarizes how the hardware and software affect performance. Understanding Program Performance Hardware or software component How this component affects performance Where is this topic covered? Algorithm Determines both the number of source-level statements and the number of I/O operations executed Other books! Programming language, compiler, and architecture Determines the number of computer instructions for each source-level statement Chapters 2 and 3 Processor and memory system Determines how fast instructions can be executed Chapters 4, 5, and 7 I/O system (hardware and operating system) Determines how fast I/O operations may be executed Chapter 6 Check Yourself sections are designed to help readers assess whether they compre hend the major concepts introduced in a chapter and understand the implications of those concepts. Some Check Yourself questions have simple answers; others are for discussion among a group. Answers to the specific questions can be found at the end of the chapter. Check Yourself questions appear only at the end of a section, making it easy to skip them if you are sure you understand the material. 1. Section 1.1 showed that the number of embedded processors sold every year greatly outnumbers the number of desktop processors. Can you confirm or deny this insight based on your own experience? Try to count the number of embedded processors in your home. How does it compare with the number of desktop computers in your home? 2. As mentioned earlier, both the software and hardware affect the performance of a program. Can you think of examples where each of the following is the right place to look for a performance bottleneck? ■ ■The algorithm chosen ■ ■The programming language or compiler ■ ■The operating system ■ ■The processor ■ ■The I/O system and devices Check Yourself | clipped_hennesy_Page_7_Chunk5364 |
10 Chapter 1 Computer Abstractions and Technology 1.2 Below Your Program A typical application, such as a word processor or a large database system, may consist of millions of lines of code and rely on sophisticated software libraries that implement complex functions in support of the application. As we will see, the hardware in a computer can only execute extremely simple low-level instructions. To go from a complex application to the simple instructions involves several layers of software that interpret or translate high-level operations into simple computer instructions. Figure 1.2 shows that these layers of software are organized primarily in a hier archical fashion, with applications being the outermost ring and a variety of systems software sitting between the hardware and applications software. There are many types of systems software, but two types of systems software are central to every computer system today: an operating system and a compiler. An operating system interfaces between a user’s program and the hardware and pro vides a variety of services and supervisory functions. Among the most important functions are ■ ■Handling basic input and output operations ■ ■Allocating storage and memory ■ ■Providing for protected sharing of the computer among multiple applications using it simultaneously. Examples of operating systems in use today are Linux, MacOS, and Windows. In Paris they simply stared when I spoke to them in French; I never did succeed in making those idiots understand their own language. Mark Twain, The Innocents Abroad, 1869 systems software Software that provides services that are commonly useful, including operating systems, compilers, loaders, and assemblers. operating system Supervising program that manages the resources of a computer for the benefit of the programs that run on that computer. FIGURE 1.2 A simplified view of hardware and software as hierarchical layers, shown as concentric circles with hardware in the center and applications software outermost. In complex applications, there are often multiple layers of application software as well. For example, a database system may run on top of the systems software hosting an application, which in turn runs on top of the database. A p p li c a ti o n s s o ft w a r e S y s t e m s s o f t w a r e Hardware | clipped_hennesy_Page_8_Chunk5365 |
Compilers perform another vital function: the translation of a program written in a high-level language, such as C, C++, Java, or Visual Basic into instructions that the hardware can execute. Given the sophistication of modern programming languages and the simplicity of the instructions executed by the hardware, the translation from a high-level language program to hardware instructions is complex. We give a brief overview of the process here and then go into more depth in Chapter 2 and Appendix B. From a High-Level Language to the Language of Hardware To actually speak to electronic hardware, you need to send electrical signals. The easiest signals for computers to understand are on and off, and so the computer alphabet is just two letters. Just as the 26 letters of the English alphabet do not limit how much can be written, the two letters of the computer alphabet do not limit what computers can do. The two symbols for these two letters are the numbers 0 and 1, and we commonly think of the computer language as numbers in base 2, or binary numbers. We refer to each “letter” as a binary digit or bit. Computers are slaves to our commands, which are called instructions. Instructions, which are just collections of bits that the computer understands and obeys, can be thought of as numbers. For example, the bits 1000110010100000 tell one computer to add two numbers. Chapter 2 explains why we use numbers for instructions and data; we don’t want to steal that chapter’s thunder, but using numbers for both instructions and data is a foundation of computing. The first programmers communicated to computers in binary numbers, but this was so tedious that they quickly invented new notations that were closer to the way humans think. At first, these notations were translated to binary by hand, but this process was still tiresome. Using the computer to help program the computer, the pioneers invented programs to translate from symbolic notation to binary. The first of these programs was named an assembler. This program translates a symbolic version of an instruction into the binary version. For example, the programmer would write add A,B and the assembler would translate this notation into 1000110010100000 This instruction tells the computer to add the two numbers A and B. The name coined for this symbolic language, still used today, is assembly language. In con trast, the binary language that the machine understands is the machine language. Although a tremendous improvement, assembly language is still far from the notations a scientist might like to use to simulate fluid flow or that an accountant might use to balance the books. Assembly language requires the programmer compiler A program that translates high-level language statements into assembly language statements. binary digit Also called a bit. One of the two numbers in base 2 (0 or 1) that are the components of information. instruction A command that computer hardware understands and obeys. assembler A program that translates a symbolic version of instructions into the binary version. assembly language A symbolic representation of machine instructions. machine language A binary representation of machine instructions. 1.2 Below Your Program 11 | clipped_hennesy_Page_9_Chunk5366 |
12 Chapter 1 Computer Abstractions and Technology to write one line for every instruction that the computer will follow, forcing the programmer to think like the computer. The recognition that a program could be written to translate a more powerful language into computer instructions was one of the great breakthroughs in the early days of computing. Programmers today owe their productivity—and their sanity—to the creation of high-level programming languages and compilers that translate programs in such languages into instructions. Figure 1.3 shows the rela tionships among these programs and languages. high-level programming language A portable language such as C, C++, Java, or Visual Basic that is composed of words and algebraic notation that can be translated by a compiler into assembly language. FIGURE 1.3 C program compiled into assembly language and then assembled into binary machine language. Although the translation from high-level language to binary machine language is shown in two steps, some compilers cut out the middleman and produce binary machine language directly. These languages and this program are examined in more detail in Chapter 2. swap(int v[], int k) {int temp; temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; } swap: multi $2, $5,4 add $2, $4,$2 lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) jr $31 00000000101000100000000100011000 0000000010000010000100000100001 10001101111000100000000000000000 10001110000100100000000000000100 10101110000100100000000000000000 10101101111000100000000000000100 00000011111000000000000000001000 Assembler Compiler Binary machine language program (for MIPS) Assembly language program (for MIPS) High-level language program (in C) | clipped_hennesy_Page_10_Chunk5367 |
A compiler enables a programmer to write this high-level language expression: A + B The compiler would compile it into this assembly language statement: add A,B As shown above, the assembler would translate this statement into the binary instructions that tell the computer to add the two numbers A and B. High-level programming languages offer several important benefits. First, they allow the programmer to think in a more natural language, using English words and algebraic notation, resulting in programs that look much more like text than like tables of cryptic symbols (see Figure 1.3). Moreover, they allow languages to be designed according to their intended use. Hence, Fortran was designed for scientific computation, Cobol for business data processing, Lisp for symbol manipulation, and so on. There are also domain-specific languages for even narrower groups of users, such as those interested in simulation of fluids, for example. The second advantage of programming languages is improved programmer productivity. One of the few areas of widespread agreement in software develop- ment is that it takes less time to develop programs when they are written in languages that require fewer lines to express an idea. Conciseness is a clear advantage of high-level languages over assembly language. The final advantage is that programming languages allow programs to be inde pendent of the computer on which they were developed, since compilers and assemblers can translate high-level language programs to the binary instructions of any computer. These three advantages are so strong that today little program ming is done in assembly language. 1.3 Under the Covers Now that we have looked below your program to uncover the underlying software, let’s open the covers of your computer to learn about the underlying hardware. The underlying hardware in any computer performs the same basic functions: inputting data, outputting data, processing data, and storing data. How these functions are performed is the primary topic of this book, and subsequent chapters deal with different parts of these four tasks. When we come to an important point in this book, a point so important that we hope you will remember it forever, we emphasize it by identifying it as a Big Picture item. We have about a dozen Big Pictures in this book, the first being 1.3 Under the Covers 13 | clipped_hennesy_Page_11_Chunk5368 |
14 Chapter 1 Computer Abstractions and Technology the five components of a computer that perform the tasks of inputting, outputting, processing, and storing data. The five classic components of a computer are input, output, memory, datapath, and control, with the last two sometimes combined and called the processor. Figure 1.4 shows the standard organization of a computer. This organization is independent of hardware technology: you can place every piece of every computer, past and present, into one of these five cat egories. To help you keep all this in perspective, the five components of a computer are shown on the front page of each of the following chapters, with the portion of interest to that chapter highlighted. The BIG Picture FIGURE 1.4 The organization of a computer, showing the five classic components. The processor gets instructions and data from memory. Input writes data to memory, and output reads data from memory. Control sends the signals that determine the operations of the datapath, memory, input, and output. | clipped_hennesy_Page_12_Chunk5369 |
Figure 1.5 shows a computer with keyboard, wireless mouse, and screen. This photograph reveals two of the key components of computers: input devices, such as the keyboard and mouse, and output devices, such as the screen. As the names suggest, input feeds the computer, and output is the result of computation sent to the user. Some devices, such as networks and disks, provide both input and output to the computer. Chapter 6 describes input/output (I/O) devices in more detail, but let’s take an introductory tour through the computer hardware, starting with the external I/O devices. input device A mechanism through which the computer is fed information, such as the keyboard or mouse. output device A mechanism that conveys the result of a computation to a user or another computer. FIGURE 1.5 A desktop computer. The liquid crystal display (LCD) screen is the primary output device, and the keyboard and mouse are the primary input devices. On the right side is an Ethernet cable that connected the laptop to the network and the Web. The laptop contains the processor, memory, and additional I/O devices. This system is a Macbook Pro 15" laptop connected to an external display. 1.3 Under the Covers 15 | clipped_hennesy_Page_13_Chunk5370 |
16 Chapter 1 Computer Abstractions and Technology Anatomy of a Mouse Although many users now take mice for granted, the idea of a pointing device such as a mouse was first shown by Doug Engelbart using a research prototype in 1967. The Alto, which was the inspiration for all workstations as well as for the Macintosh and Windows OS, included a mouse as its pointing device in 1973. By the 1990s, all desktop computers included this device, and new user interfaces based on graphics displays and mice became the norm. The original mouse was electromechanical and used a large ball that when rolled across a surface would cause an x and y counter to be incremented. The amount of increase in each counter told how far the mouse had been moved. The electromechanical mouse has largely been replaced by the newer all-optical mouse. The optical mouse is actually a miniature optical processor including an LED to provide lighting, a tiny black-and-white camera, and a simple optical pro cessor. The LED illuminates the surface underneath the mouse; the camera takes 1500 sample pictures a second under the illumination. Successive pictures are sent to a simple optical processor that compares the images and determines whether the mouse has moved and how far. The replacement of the electromechanical mouse by the electro-optical mouse is an illustration of a common phenomenon where the decreasing costs and higher reliability of electronics cause an electronic solution to replace the older electromechanical technology. On page 22 we’ll see another example: flash memory. Through the Looking Glass The most fascinating I/O device is probably the graphics display. All laptop and handheld computers, calculators, cellular phones, and almost all desktop comput ers now use liquid crystal displays (LCDs) to get a thin, low-power display. The LCD is not the source of light; instead, it controls the transmission of light. A typical LCD includes rod-shaped molecules in a liquid that form a twisting helix that bends light entering the display, from either a light source behind the display or less often from reflected light. The rods straighten out when a current is applied and no longer bend the light. Since the liquid crystal material is between two screens polarized at 90 degrees, the light cannot pass through unless it is bent. Today, most LCD displays use an active matrix that has a tiny transistor switch at each pixel to precisely control current and make sharper images. A red-green-blue mask associated with each dot on the display determines the intensity of the three color components in the final image; in a color active matrix LCD, there are three transistor switches at each point. The image is composed of a matrix of picture elements, or pixels, which can be represented as a matrix of bits, called a bit map. Depending on the size of the screen and the resolution, the display matrix ranges in size from 640 × 480 to 2560 × 1600 pixels in 2008. A color display might use 8 bits for each of the three colors (red, blue, and green), for 24 bits per pixel, permitting millions of different colors to be displayed. I got the idea for the mouse while attending a talk at a computer conference. The speaker was so boring that I started daydreaming and hit upon the idea. Doug Engelbart Through computer displays I have landed an airplane on the deck of a moving carrier, observed a nuclear particle hit a potential well, flown in a rocket at nearly the speed of light and watched a computer reveal its innermost workings. Ivan Sutherland, the “father” of computer graphics, Scientific American, 1984 liquid crystal display A display technology using a thin layer of liquid polymers that can be used to transmit or block light according to whether a charge is applied. active matrix display A liquid crystal display using a transistor to control the transmission of light at each individual pixel. pixel The smallest individual picture element. Screens are composed of hundreds of thousands to millions of pixels, organized in a matrix. | clipped_hennesy_Page_14_Chunk5371 |
The computer hardware support for graphics consists mainly of a raster refresh buffer, or frame buffer, to store the bit map. The image to be represented onscreen is stored in the frame buffer, and the bit pattern per pixel is read out to the graphics display at the refresh rate. Figure 1.6 shows a frame buffer with a simplified design of just 4 bits per pixel. X0 X1 Y0 Frame buffer Raster scan CRT display 0 011 1 101 Y1 X0 X1 Y0 Y1 FIGURE 1.6 Each coordinate in the frame buffer on the left determines the shade of the corresponding coordinate for the raster scan CRT display on the right. Pixel (X0, Y0) contains the bit pattern 0011, which is a lighter shade on the screen than the bit pattern 1101 in pixel (X1, Y1). The goal of the bit map is to faithfully represent what is on the screen. The challenges in graphics systems arise because the human eye is very good at detecting even subtle changes on the screen. Opening the Box If we open the box containing the computer, we see a fascinating board of thin plastic, covered with dozens of small gray or black rectangles. Figure 1.7 shows the contents of the laptop computer in Figure 1.5. The motherboard is shown in the upper part of the photo. Two disk drives are in front—the hard drive on the left and a DVD drive on the right. The hole in the middle is for the laptop battery. The small rectangles on the motherboard contain the devices that drive our advancing technology, called integrated circuits and nicknamed chips. The board is composed of three pieces: the piece connecting to the I/O devices mentioned earlier, the memory, and the processor. The memory is where the programs are kept when they are running; it also contains the data needed by the running programs. Figure 1.8 shows that memory is found on the two small boards, and each small memory board contains eight integrated circuits. The memory in Figure 1.8 is built from DRAM chips. DRAM motherboard A plastic board containing packages of integrated circuits or chips, including processor, cache, memory, and connectors for I/O devices such as networks and disks. integrated circuit Also called a chip. A device combining dozens to millions of transistors. memory The storage area in which programs are kept when they are running and that contains the data needed by the running programs. 1.3 Under the Covers 17 | clipped_hennesy_Page_15_Chunk5372 |
18 Chapter 1 Computer Abstractions and Technology FIGURE 1.7 Inside the laptop computer of Figure 1.5. The shiny box with the white label on the lower left is a 100 GB SATA hard disk drive, and the shiny metal box on the lower right side is the DVD drive. The hole between them is where the laptop battery would be located. The small hole above the battery hole is for memory DIMMs. Figure 1.8 is a close-up of the DIMMs, which are inserted from the bottom in this laptop. Above the battery hole and DVD drive is a printed circuit board (PC board), called the motherboard, which contains most of the electronics of the computer. The two shiny circles in the upper half of the picture are two fans with covers. The processor is the large raised rectangle just below the left fan. Photo courtesy of OtherWorldComputing.com. Hard drive Processor Fan with cover Spot for memory DIMMs Spot for battery Motherboard Fan with cover DVD drive | clipped_hennesy_Page_16_Chunk5373 |
stands for dynamic random access memory. Several DRAMs are used together to contain the instructions and data of a program. In contrast to sequential access memories, such as magnetic tapes, the RAM portion of the term DRAM means that memory accesses take basically the same amount of time no matter what portion of the memory is read. dynamic random access memory (DRAM) Memory built as an integrated circuit; it provides random access to any location. FIGURE 1.8 Close-up of the bottom of the laptop reveals the memory. The main memory is contained on one or more small boards shown on the left. The hole for the battery is to the right. The DRAM chips are mounted on these boards (called DIMMs, for dual inline memory modules) and then plugged into the connectors. Photo courtesy of OtherWorldComputing.com. dual inline memory module (DIMM) A small board that contains DRAM chips on both sides. (SIMMs have DRAMs on only one side.) The processor is the active part of the board, following the instructions of a pro gram to the letter. It adds numbers, tests numbers, signals I/O devices to activate, and so on. The processor is under the fan and covered by a heat sink on the left side of Figure 1.7. Occasionally, people call the processor the CPU, for the more bureaucratic-sounding central processor unit. Descending even lower into the hardware, Figure 1.9 reveals details of a micro processor. The processor logically comprises two main components: datapath and control, the respective brawn and brain of the processor. The datapath performs the arithmetic operations, and control tells the datapath, memory, and I/O devices what to do according to the wishes of the instructions of the program. Chapter 4 explains the datapath and control for a higher-performance design. central processor unit (CPU) Also called processor. The active part of the computer, which contains the datapath and control and which adds numbers, tests numbers, signals I/O devices to activate, and so on. datapath The component of the processor that performs arithmetic operations control The component of the processor that commands the datapath, memory, and I/O devices according to the instruc tions of the program. 1.3 Under the Covers 19 | clipped_hennesy_Page_17_Chunk5374 |
20 Chapter 1 Computer Abstractions and Technology Descending into the depths of any component of the hardware reveals insights into the computer. Inside the processor is another type of memory—cache mem ory. Cache memory consists of a small, fast memory that acts as a buffer for the DRAM memory. (The nontechnical definition of cache is a safe place for hiding things.) Cache is built using a different memory technology, static random access memory (SRAM). SRAM is faster but less dense, and hence more expensive, than DRAM (see Chapter 5). You may have noticed a common theme in both the software and the hardware descriptions: delving into the depths of hardware or software reveals more infor mation or, conversely, lower-level details are hidden to offer a simpler model at higher levels. The use of such layers, or abstractions, is a principal technique for designing very sophisticated computer systems. One of the most important abstractions is the interface between the hard ware and the lowest-level software. Because of its importance, it is given a special cache memory A small, fast memory that acts as a buffer for a slower, larger memory. static random access memory (SRAM) Also memory built as an integrated circuit, but faster and less dense than DRAM. abstraction A model that renders lower-level details of computer systems temporarily invisible to facilitate design of sophisticated systems. FIGURE 1.9 Inside the AMD Barcelona microprocessor. The left-hand side is a microphotograph of the AMD Barcelona processor chip, and the right-hand side shows the major blocks in the processor. This chip has four processors or “cores”. The microprocessor in the laptop in Figure 1.7 has two cores per chip, called an Intel Core 2 Duo. 2MB Shared L3 Cache Northbridge Core 4 Core 3 Core 2 512kB L2 Cache HT PHY, link 1 128-bit FPU L1 Data Cache L2 Ctl L1 Instr Cache Execution Load/ Store Fetch/ Decode/ Branch Slow I/O Fuses HT PHY, link 4 HT PHY, link 3 HT PHY, link 2 Slow I/O Fuses D D R P H Y | clipped_hennesy_Page_18_Chunk5375 |
name: the instruction set architecture, or simply architecture, of a computer. The instruction set architecture includes anything programmers need to know to make a binary machine language program work correctly, including instructions, I/O devices, and so on. Typically, the operating system will encapsulate the details of doing I/O, allocating memory, and other low-level system functions so that application programmers do not need to worry about such details. The combina tion of the basic instruction set and the operating system interface provided for application programmers is called the application binary interface (ABI). An instruction set architecture allows computer designers to talk about func tions independently from the hardware that performs them. For example, we can talk about the functions of a digital clock (keeping time, displaying the time, setting the alarm) independently from the clock hardware (quartz crystal, LED displays, plastic buttons). Computer designers distinguish architecture from an implementation of an architecture along the same lines: an implementation is hardware that obeys the architecture abstraction. These ideas bring us to another Big Picture. instruction set architecture Also called architecture. An abstract interface between the hardware and the lowest-level software that encompasses all the information necessary to write a machine language program that will run correctly, including instructions, registers, memory access, I/O, .... application binary interface (ABI) The user portion of the instruction set plus the operating system interfaces used by application programmers. Defines a standard for binary portability across computers. implementation Hardware that obeys the architecture abstraction. Both hardware and software consist of hierarchical layers, with each lower layer hiding details from the level above. This principle of abstraction is the way both hardware designers and software designers cope with the complexity of computer systems. One key interface between the levels of abstraction is the instruction set architecture—the interface between the hardware and low-level software. This abstract interface enables many implementations of varying cost and performance to run identical software. A Safe Place for Data Thus far, we have seen how to input data, compute using the data, and display data. If we were to lose power to the computer, however, everything would be lost because the memory inside the computer is volatile—that is, when it loses power, it forgets. In contrast, a DVD doesn’t forget the recorded film when you turn off the power to the DVD player and is thus a nonvolatile memory technology. To distinguish between the volatile memory used to hold data and programs while they are running and this nonvolatile memory used to store data and pro grams between runs, the term main memory or primary memory is used for the volatile memory Stor age, such as DRAM, that retains data only if it is receiving power. nonvolatile memory A form of memory that retains data even in the absence of a power source and that is used to store programs between runs. Magnetic disk is nonvolatile. main memory Also called primary memory. Memory used to hold programs while they are running; typically consists of DRAM in today’s computers. 1.3 Under the Covers 21 The BIG Picture | clipped_hennesy_Page_19_Chunk5376 |
22 Chapter 1 Computer Abstractions and Technology former, and secondary memory for the latter. DRAMs have dominated main memory since 1975, but magnetic disks have dominated secondary memory since 1965. The primary nonvolatile storage used in all server computers and workstations is the magnetic hard disk. Flash memory, a nonvolatile semiconduc tor memory, is used instead of disks in mobile devices such as cell phones and is increasingly replacing disks in music players and even laptops. As Figure 1.10 shows, a magnetic hard disk consists of a collection of platters, which rotate on a spindle at 5400 to 15,000 revolutions per minute. The metal platters are covered with magnetic recording material on both sides, similar to the material found on a cassette or videotape. To read and write information on a hard disk, a movable arm containing a small electromagnetic coil called a read-write head is located just above each surface. The entire drive is permanently sealed to control the environment inside the drive, which, in turn, allows the disk heads to be much closer to the drive surface. secondary memory Nonvolatile memory used to store programs and data between runs; typically consists of mag netic disks in today’s computers. magnetic disk Also called hard disk. A form of nonvolatile secondary memory composed of rotating platters coated with a magnetic recording material. flash memory A nonvolatile semi- conductor memory. It is cheaper and slower than DRAM but more expensive and faster than magnetic disks. FIGURE 1.10 A disk showing 10 disk platters and the read/write heads. | clipped_hennesy_Page_20_Chunk5377 |
Diameters of hard disks vary by more than a factor of 3 today, from 1 inch to 3.5 inches, and have been shrunk over the years to fit into new products; workstation servers, personal computers, laptops, palmtops, and digital cameras have all inspired new disk form factors. Traditionally, the widest disks have the highest performance and the smallest disks have the lowest unit cost. The best cost per gigabyte varies. Although most hard drives appear inside computers, as in Figure 1.7, hard drives can also be attached using external interfaces such as universal serial bus (USB). The use of mechanical components means that access times for magnetic disks are much slower than for DRAMs: disks typically take 5–20 milliseconds, while DRAMs take 50–70 nanoseconds—making DRAMs about 100,000 times faster. Yet disks have much lower costs than DRAM for the same storage capacity, because the production costs for a given amount of disk storage are lower than for the same amount of integrated circuit. In 2008, the cost per gigabyte of disk is 30 to 100 times less expensive than DRAM. Thus, there are three primary differences between magnetic disks and main memory: disks are nonvolatile because they are magnetic; they have a slower access time because they are mechanical devices; and they are cheaper per gigabyte because they have very high storage capacity at a modest cost. Many have tried to invent a technology cheaper than DRAM but faster than disk to fill that gap, but many have failed. Challengers have never had a product to market at the right time. By the time a new product would ship, DRAMs and disks had continued to make rapid advances, costs had dropped accordingly, and the challenging product was immediately obsolete. Flash memory, however, is a serious challenger. This semiconductor memory is nonvolatile like disks and has about the same bandwidth, but latency is 100 to 1000 times faster than disk. Flash is popular in cameras and portable music players because it comes in much smaller capacities, it is more rugged, and it is more power efficient than disks, despite the cost per gigabyte in 2008 being about 6 to 10 times higher than disk. Unlike disks and DRAM, flash memory bits wear out after 100,000 to 1,000,000 writes. Thus, file systems must keep track of the number of writes and have a strategy to avoid wearing out storage, such as by moving popular data. Chapter 6 describes flash in more detail. Although hard drives are not removable, there are several storage technologies in use that include the following: ■ ■Optical disks, including both compact disks (CDs) and digital video disks (DVDs), constitute the most common form of removable storage. The Blu- Ray (BD) optical disk standard is the heir-apparent to DVD. ■ ■Flash-based removable memory cards typically attach to a USB connection and are often used to transfer files. ■ ■Magnetic tape provides only slow serial access and has been used to back up disks, a role now often replaced by duplicate hard drives. gigabyte Traditionally 1,073,741,824 (230) bytes, although some communications and secondary storage systems have redefined it to mean 1,000,000,000 (109) bytes. Similarly, depending on the context, megabyte is either 220 or 106 bytes. 1.3 Under the Covers 23 | clipped_hennesy_Page_21_Chunk5378 |
24 Chapter 1 Computer Abstractions and Technology Optical disk technology works differently than magnetic disk technology. In a CD, data is recorded in a spiral fashion, with individual bits being recorded by burning small pits—approximately 1 micron (10−6 meters) in diameter—into the disk surface. The disk is read by shining a laser at the CD surface and determining by examining the reflected light whether there is a pit or flat (reflective) surface. DVDs use the same approach of bouncing a laser beam off a series of pits and flat surfaces. In addition, there are multiple layers that the laser beam can focus on, and the size of each bit is much smaller, which together increase capacity significantly. Blu-Ray uses shorter wavelength lasers that shrink the size of the bits and thereby increase capacity. Optical disk writers in personal computers use a laser to make the pits in the recording layer on the CD or DVD surface. This writing process is relatively slow, taking from minutes (for a full CD) to tens of minutes (for a full DVD). Thus, for large quantities a different technique called pressing is used, which costs only pennies per optical disk. Rewritable CDs and DVDs use a different recording surface that has a crystal line, reflective material; pits are formed that are not reflective in a manner similar to that for a write-once CD or DVD. To erase the CD or DVD, the surface is heated and cooled slowly, allowing an annealing process to restore the surface recording layer to its crystalline structure. These rewritable disks are the most expensive, with write-once being cheaper; for read-only disks—used to distribute software, music, or movies—both the disk cost and recording cost are much lower. Communicating with Other Computers We’ve explained how we can input, compute, display, and save data, but there is still one missing item found in today’s computers: computer networks. Just as the processor shown in Figure 1.4 is connected to memory and I/O devices, networks interconnect whole computers, allowing computer users to extend the power of computing by including communication. Networks have become so popular that they are the backbone of current computer systems; a new computer without an optional network interface would be ridiculed. Networked computers have several major advantages: ■ ■Communication: Information is exchanged between computers at high speeds. ■ ■Resource sharing: Rather than each computer having its own I/O devices, devices can be shared by computers on the network. ■ ■Nonlocal access: By connecting computers over long distances, users need not be near the computer they are using. Networks vary in length and performance, with the cost of communication increasing according to both the speed of communication and the distance that information travels. Perhaps the most popular type of network is Ethernet. It can be up to a kilometer long and transfer at upto 10 gigabits per second. Its length and | clipped_hennesy_Page_22_Chunk5379 |
speed make Ethernet useful to connect computers on the same floor of a building; hence, it is an example of what is generically called a local area network. Local area networks are interconnected with switches that can also provide routing services and security. Wide area networks cross continents and are the backbone of the Internet, which supports the World Wide Web. They are typically based on optical fibers and are leased from telecommunication companies. Networks have changed the face of computing in the last 25 years, both by becoming much more ubiquitous and by making dramatic increases in perfor- mance. In the 1970s, very few individuals had access to electronic mail, the Internet and Web did not exist, and physically mailing magnetic tapes was the primary way to transfer large amounts of data between two locations. Local area networks were almost nonexistent, and the few existing wide area networks had limited capacity and restricted access. As networking technology improved, it became much cheaper and had a much higher capacity. For example, the first standardized local area network technology, developed about 25 years ago, was a version of Ethernet that had a maximum capacity (also called bandwidth) of 10 million bits per second, typically shared by tens of, if not a hundred, computers. Today, local area network technology offers a capacity of from 100 million bits per second to 10 gigabits per second, usually shared by at most a few computers. Optical communications technology has allowed similar growth in the capacity of wide area networks, from hundreds of kilobits to gigabits and from hundreds of computers connected to a worldwide network to millions of computers connected. This combination of dramatic rise in deployment of networking combined with increases in capacity have made network technology central to the information revolution of the last 25 years. For the last decade another innovation in networking is reshaping the way com puters communicate. Wireless technology is widespread, and laptops now incorpo rate this technology. The ability to make a radio in the same low-cost semiconductor technology (CMOS) used for memory and microprocessors enabled a significant improvement in price, leading to an explosion in deployment. Currently available wireless technologies, called by the IEEE standard name 802.11, allow for transmis sion rates from 1 to nearly 100 million bits per second. Wireless technology is quite a bit different from wire-based networks, since all users in an immediate area share the airwaves. ■ ■Semiconductor DRAM and disk storage differ significantly. Describe the fundamental difference for each of the following: volatility, access time, and cost. Technologies for Building Processors and Memory Processors and memory have improved at an incredible rate, because computer designers have long embraced the latest in electronic technology to try to win the race to design a better computer. Figure 1.11 shows the technologies that have been local area network (LAN) A network designed to carry data within a geographically confined area, typically within a single building. wide area network (WAN) A network extended over hundreds of kilometers that can span a continent. Check Yourself 1.3 Under the Covers 25 | clipped_hennesy_Page_23_Chunk5380 |
26 Chapter 1 Computer Abstractions and Technology used over time, with an estimate of the relative performance per unit cost for each technology. Section 1.7 explores the technology that has fueled the computer industry since 1975 and will continue to do so for the foreseeable future. Since this technology shapes what computers will be able to do and how quickly they will evolve, we believe all computer professionals should be familiar with the basics of integrated circuits. Year Technology used in computers Relative performance/unit cost 1951 Vacuum tube 0,000,001 1965 Transistor 0,000,035 1975 Integrated circuit 0,000,900 1995 Very large-scale integrated circuit 2,400,000 2005 Ultra large-scale integrated circuit 6,200,000,000 FIGURE 1.11 Relative performance per unit cost of technologies used in computers over time. Source: Computer Museum, Boston, with 2005 extrapolated by the authors. See Section 1.10 on the CD. vacuum tube An electronic component, predecessor of the transistor, that consists of a hollow glass tube about 5 to 10 cm long from which as much air has been removed as possible and that uses an electron beam to transfer data. A transistor is simply an on/off switch controlled by electricity. The inte grated circuit (IC) combined dozens to hundreds of transistors into a single chip. To describe the tremendous increase in the number of transistors from hundreds to millions, the adjective very large scale is added to the term, creating the abbreviation VLSI, for very large-scale integrated circuit. This rate of increasing integration has been remarkably stable. Figure 1.12 shows the growth in DRAM capacity since 1977. For 20 years, the industry has consistently quadrupled capacity every 3 years, resulting in an increase in excess of 16,000 times! This increase in transistor count for an integrated circuit is popu larly known as Moore’s law, which states that transistor capacity doubles every 18–24 months. Moore’s law resulted from a prediction of such growth in IC capacity made by Gordon Moore, one of the founders of Intel during the 1960s. Sustaining this rate of progress for almost 40 years has required incredible innovation in manufacturing techniques. In Section 1.7, we discuss how to manu facture integrated circuits. 1.4 Performance Assessing the performance of computers can be quite challenging. The scale and intricacy of modern software systems, together with the wide range of perfor mance improvement techniques employed by hardware designers, have made per formance assessment much more difficult. When trying to choose among different computers, performance is an important attribute. Accurately measuring and comparing different computers is critical to transistor An on/off switch controlled by an electric signal. very large-scale integrated (VLSI) circuit A device con taining hundreds of thousands to millions of transistors. | clipped_hennesy_Page_24_Chunk5381 |
purchasers and therefore to designers. The people selling computers know this as well. Often, salespeople would like you to see their computer in the best possible light, whether or not this light accurately reflects the needs of the purchaser’s application. Hence, understanding how best to measure performance and the limitations of performance measurements is important in selecting a computer. The rest of this section describes different ways in which performance can be determined; then, we describe the metrics for measuring performance from the viewpoint of both a computer user and a designer. We also look at how these metrics are related and present the classical processor performance equation, which we will use throughout the text. Defining Performance When we say one computer has better performance than another, what do we mean? Although this question might seem simple, an analogy with passenger airplanes shows how subtle the question of performance can be. Figure 1.13 shows some typical passenger airplanes, together with their cruising speed, range, and capacity. If we wanted to know which of the planes in this table had the best per formance, we would first need to define performance. For example, considering different measures of performance, we see that the plane with the highest cruising speed is the Concorde, the plane with the longest range is the DC-8, and the plane with the largest capacity is the 747. Let’s suppose we define performance in terms of speed. This still leaves two possi ble definitions. You could define the fastest plane as the one with the highest cruising speed, taking a single passenger from one point to another in the least time. If you FIGURE 1.12 Growth of capacity per DRAM chip over time. The y-axis is measured in Kilobits, where K = 1024 (210). The DRAM industry quadrupled capacity almost every three years, a 60% increase per year, for 20 years. In recent years, the rate has slowed down and is somewhat closer to doubling every two years to three years. 1,000,000 1976 1978 1980 1982 1984 1986 Year of introduction 1988 1990 1992 1994 1996 1998 2000 2002 2004 2006 2008 Kbit capacity 16K 64K 256K 1M 4M 16M 64M 128M256M 512M 1G 100,000 10,000 1000 100 10 1.4 Performance 27 | clipped_hennesy_Page_25_Chunk5382 |
28 Chapter 1 Computer Abstractions and Technology were interested in transporting 450 passengers from one point to another, however, the 747 would clearly be the fastest, as the last column of the figure shows. Similarly, we can define computer performance in several different ways. If you were running a program on two different desktop computers, you’d say that the faster one is the desktop computer that gets the job done first. If you were running a datacenter that had several servers running jobs submitted by many users, you’d say that the faster computer was the one that completed the most jobs during a day. As an individual computer user, you are interested in reducing response time—the time between the start and completion of a task—also referred to as execution time. Datacenter managers are often interested in increasing throughput or bandwidth— the total amount of work done in a given time. Hence, in most cases, we will need different performance metrics as well as different sets of applications to benchmark embedded and desktop computers, which are more focused on response time, versus servers, which are more focused on throughput. Throughput and Response Time Do the following changes to a computer system increase throughput, decrease response time, or both? 1. Replacing the processor in a computer with a faster version 2. Adding additional processors to a system that uses multiple processors for separate tasks—for example, searching the World Wide Web Decreasing response time almost always improves throughput. Hence, in case 1, both response time and throughput are improved. In case 2, no one task gets work done faster, so only throughput increases. If, however, the demand for processing in the second case was almost as large as the throughput, the system might force requests to queue up. In this case, increasing the throughput could also improve response time, since it would reduce the waiting time in the queue. Thus, in many real computer systems, changing either execution time or throughput often affects the other. response time Also called execution time. The total time required for the computer to complete a task, including disk accesses, memory accesses, I/O activities, operating system over head, CPU execution time, and so on. throughput Also called bandwidth. Another measure of performance, it is the number of tasks completed per unit time. EXAMPLE ANSWER Airplane Passenger capacity Cruising range (miles) Cruising speed (m.p.h.) Passenger throughput (passengers × m.p.h.) Boeing 777 375 4630 0610 228,750 Boeing 747 470 4150 0610 286,700 BAC/Sud Concorde 132 4000 1350 178,200 Douglas DC-8-50 146 8720 0544 79,424 FIGURE 1.13 The capacity, range, and speed for a number of commercial airplanes. The last column shows the rate at which the airplane transports passengers, which is the capacity times the cruising speed (ignoring range and takeoff and landing times). | clipped_hennesy_Page_26_Chunk5383 |
In discussing the performance of computers, we will be primarily concerned with response time for the first few chapters. To maximize performance, we want to minimize response time or execution time for some task. Thus, we can relate performance and execution time for a computer X: PerformanceX = 1 ______________ Execution timeX This means that for two computers X and Y, if the performance of X is greater than the performance of Y, we have PerformanceX > PerformanceY 1 Execution timeX > 1 Execution timeY Execution timeY > Execution timeX That is, the execution time on Y is longer than that on X, if X is faster than Y. In discussing a computer design, we often want to relate the performance of two different computers quantitatively. We will use the phrase “X is n times faster than Y”—or equivalently “X is n times as fast as Y”—to mean PerformanceX PerformanceY = n If X is n times faster than Y, then the execution time on Y is n times longer than it is on X: PerformanceX PerformanceY = Execution timeY Execution timeX = n Relative Performance If computer A runs a program in 10 seconds and computer B runs the same program in 15 seconds, how much faster is A than B? We know that A is n times faster than B if PerformanceA ____________ PerformanceB = Execution timeB _____________ Execution timeA = n EXAMPLE ANSWER 1.4 Performance 29 | clipped_hennesy_Page_27_Chunk5384 |
30 Chapter 1 Computer Abstractions and Technology Thus the performance ratio is 15 ___ 10 = 1.5 and A is therefore 1.5 times faster than B. In the above example, we could also say that computer B is 1.5 times slower than computer A, since PerformanceA PerformanceB = 1.5 means that PerformanceA 1.5 = PerformanceB For simplicity, we will normally use the terminology faster than when we try to compare computers quantitatively. Because performance and execution time are reciprocals, increasing performance requires decreasing execution time. To avoid the potential confusion between the terms increasing and decreasing, we usually say “improve performance” or “improve execution time” when we mean “increase performance” and “decrease execution time.” Measuring Performance Time is the measure of computer performance: the computer that performs the same amount of work in the least time is the fastest. Program execution time is measured in seconds per program. However, time can be defined in different ways, depending on what we count. The most straightforward definition of time is called wall clock time, response time, or elapsed time. These terms mean the total time to complete a task, including disk accesses, memory accesses, input/output (I/O) activities, operating system overhead—everything. Computers are often shared, however, and a processor may work on several programs simultaneously. In such cases, the system may try to optimize through put rather than attempt to minimize the elapsed time for one program. Hence, we often want to distinguish between the elapsed time and the time that the processor is working on our behalf. CPU execution time or simply CPU time, which recognizes this distinction, is the time the CPU spends computing for this task and does not include time spent waiting for I/O or running other programs. (Remember, though, that the response time experienced by the user will be the elapsed time of the program, not the CPU time.) CPU time can be further divided into the CPU time spent in the program, called user CPU time, and the CPU time spent in the operating system performing tasks on behalf of the program, called system CPU time. Differentiating between system and user CPU time is difficult to CPU execution time Also called CPU time. The actual time the CPU spends computing for a specific task. user CPU time The CPU time spent in a program itself. system CPU time The CPU time spent in the operating system performing tasks on behalf of the program. | clipped_hennesy_Page_28_Chunk5385 |
do accurately, because it is often hard to assign responsibility for operating system activities to one user program rather than another and because of the functionality differences among operating systems. For consistency, we maintain a distinction between performance based on elapsed time and that based on CPU execution time. We will use the term system performance to refer to elapsed time on an unloaded system and CPU performance to refer to user CPU time. We will focus on CPU performance in this chapter, although our discussions of how to summarize performance can be applied to either elapsed time or CPU time measurements. Different applications are sensitive to different aspects of the performance of a computer system. Many applications, especially those running on servers, depend as much on I/O performance, which, in turn, relies on both hardware and software. Total elapsed time measured by a wall clock is the measurement of interest. In some application environments, the user may care about throughput, response time, or a complex combination of the two (e.g., maximum throughput with a worst-case response time). To improve the performance of a program, one must have a clear definition of what performance metric matters and then proceed to look for performance bottlenecks by measuring program execution and looking for the likely bottlenecks. In the following chapters, we will describe how to search for bottlenecks and improve performance in various parts of the system. Although as computer users we care about time, when we examine the details of a computer it’s convenient to think about performance in other metrics. In par ticular, computer designers may want to think about a computer by using a mea sure that relates to how fast the hardware can perform basic functions. Almost all computers are constructed using a clock that determines when events take place in the hardware. These discrete time intervals are called clock cycles (or ticks, clock ticks, clock periods, clocks, cycles). Designers refer to the length of a clock period both as the time for a complete clock cycle (e.g., 250 picoseconds, or 250 ps) and as the clock rate (e.g., 4 gigahertz, or 4 GHz), which is the inverse of the clock period. In the next subsection, we will formalize the relationship between the clock cycles of the hardware designer and the seconds of the computer user. 1. Suppose we know that an application that uses both a desktop client and a remote server is limited by network performance. For the following changes, state whether only the throughput improves, both response time and throughput improve, or neither improves. a. An extra network channel is added between the client and the server, increasing the total network throughput and reducing the delay to obtain network access (since there are now two channels). Understanding Program Performance clock cycle Also called tick, clock tick, clock period, clock, cycle. The time for one clock period, usually of the processor clock, which runs at a constant rate. clock period The length of each clock cycle. Check Yourself 1.4 Performance 31 | clipped_hennesy_Page_29_Chunk5386 |
32 Chapter 1 Computer Abstractions and Technology b. The networking software is improved, thereby reducing the network communication delay, but not increasing throughput. c. More memory is added to the computer. 2. Computer C’s performance is 4 times faster than the performance of com puter B, which runs a given application in 28 seconds. How long will computer C take to run that application? CPU Performance and Its Factors Users and designers often examine performance using different metrics. If we could relate these different metrics, we could determine the effect of a design change on the performance as experienced by the user. Since we are confining ourselves to CPU performance at this point, the bottom-line performance measure is CPU execution time. A simple formula relates the most basic metrics (clock cycles and clock cycle time) to CPU time: CPU execution time for a program = CPU clock cycles for a program × Clock cycle time Alternatively, because clock rate and clock cycle time are inverses, CPU execution time for a program = CPU clock cycles for a program Clock rate This formula makes it clear that the hardware designer can improve performance by reducing the number of clock cycles required for a program or the length of the clock cycle. As we will see in later chapters, the designer often faces a trade-off between the number of clock cycles needed for a program and the length of each cycle. Many techniques that decrease the number of clock cycles may also increase the clock cycle time. Improving Performance Our favorite program runs in 10 seconds on computer A, which has a 2 GHz clock. We are trying to help a computer designer build a computer, B, which will run this program in 6 seconds. The designer has determined that a substantial increase in the clock rate is possible, but this increase will affect the rest of the CPU design, causing computer B to require 1.2 times as many clock cycles as computer A for this program. What clock rate should we tell the designer to target? EXAMPLE | clipped_hennesy_Page_30_Chunk5387 |
Let’s first find the number of clock cycles required for the program on A: CPU timeA = CPU clock cyclesA _________________ Clock rateA 10 seconds = CPU clock cyclesA 2 × 109 cycles second CPU clock cyclesA = 10 seconds × 2 × 109 cycles _______ second = 20 × 109 cycles CPU time for B can be found using this equation: CPU timeB = 1.2 × CPU clock cyclesA _______________________ Clock rateB 6 seconds = 1.2 × 20 × 109 cycles ___________________ Clock rateB ANSWER 1.4 Performance 33 Clock rateB = 1.2 × 20 × 109 cycles 6 seconds = 0.2 × 20 ×109 cycles second = 4 × 109 cycles second = 4 GHz To run the program in 6 seconds, B must have twice the clock rate of A. Instruction Performance The performance equations above did not include any reference to the number of instructions needed for the program. (We’ll see what the instructions that make up a program look like in the next chapter.) However, since the compiler clearly gener ated instructions to execute, and the computer had to execute the instructions to run the program, the execution time must depend on the number of instructions in a program. One way to think about execution time is that it equals the number of instructions executed multiplied by the average time per instruction. Therefore, the number of clock cycles required for a program can be written as CPU clock cycles = Instructions for a program × Average clock cycles per instruction The term clock cycles per instruction, which is the average number of clock cycles each instruction takes to execute, is often abbreviated as CPI. Since different clock cycles per instruction (CPI) Average number of clock cycles per instruction for a program or program fragment. | clipped_hennesy_Page_31_Chunk5388 |
34 Chapter 1 Computer Abstractions and Technology instructions may take different amounts of time depending on what they do, CPI is an average of all the instructions executed in the program. CPI provides one way of comparing two different implementations of the same instruction set architecture, since the number of instructions executed for a program will, of course, be the same. Using the Performance Equation Suppose we have two implementations of the same instruction set architec ture. Computer A has a clock cycle time of 250 ps and a CPI of 2.0 for some program, and computer B has a clock cycle time of 500 ps and a CPI of 1.2 for the same program. Which computer is faster for this program and by how much? We know that each computer executes the same number of instructions for the program; let’s call this number I. First, find the number of processor clock cycles for each computer: CPU clock cyclesA = I × 2.0 CPU clock cyclesB = I × 1.2 Now we can compute the CPU time for each computer: CPU timeA = CPU clock cyclesA × Clock cycle time = I × 2.0 × 250 ps = 500 × I ps Likewise, for B: CPU timeB = I × 1.2 × 500 ps = 600 × I ps Clearly, computer A is faster. The amount faster is given by the ratio of the execution times: CPU performanceA CPU performanceB = Execution timeB Execution timeA = 600 × I ps 500 × I ps = 1.2 We can conclude that computer A is 1.2 times as fast as computer B for this program. EXAMPLE ANSWER | clipped_hennesy_Page_32_Chunk5389 |
The Classic CPU Performance Equation We can now write this basic performance equation in terms of instruction count (the number of instructions executed by the program), CPI, and clock cycle time: CPU time = Instruction count × CPI × Clock cycle time or, since the clock rate is the inverse of clock cycle time: CPU time = Instruction count × CPI Clock rate These formulas are particularly useful because they separate the three key factors that affect performance. We can use these formulas to compare two different implementations or to evaluate a design alternative if we know its impact on these three parameters. Comparing Code Segments A compiler designer is trying to decide between two code sequences for a par ticular computer. The hardware designers have supplied the following facts: instruction count The number of instructions executed by the program. EXAMPLE CPI for each instruction class A B C CPI 1 2 3 Instruction counts for each instruction class Code sequence A B C 1 2 1 2 2 4 1 1 For a particular high-level language statement, the compiler writer is consid ering two code sequences that require the following instruction counts: Which code sequence executes the most instructions? Which will be faster? What is the CPI for each sequence? 1.4 Performance 35 | clipped_hennesy_Page_33_Chunk5390 |
36 Chapter 1 Computer Abstractions and Technology Sequence 1 executes 2 + 1 + 2 = 5 instructions. Sequence 2 executes 4 + 1 + 1 = 6 instructions. Therefore, sequence 1 executes fewer instructions. We can use the equation for CPU clock cycles based on instruction count and CPI to find the total number of clock cycles for each sequence: CPU clock cycles = ∑ i = 1 n (CPIi × Ci) This yields CPU clock cycles1 = (2 × 1) + (1 × 2) + (2 × 3) = 2 + 2 + 6 = 10 cycles CPU clock cycles2 = (4 × 1) + (1 × 2) + (1 × 3) = 4 + 2 + 3 = 9 cycles So code sequence 2 is faster, even though it executes one extra instruction. Since code sequence 2 takes fewer overall clock cycles but has more instruc tions, it must have a lower CPI. The CPI values can be computed by CPI = CPU clock cycles Instruction count CPI1 = CPU clock cycles1 Instruction count1 = 10 5 = 2.0 CPI2 = CPU clock cycles2 Instruction count2 = 9 6 = 1.5 ANSWER Figure 1.14 shows the basic measurements at different levels in the computer and what is being measured in each case. We can see how these factors are combined to yield execution time measured in seconds per program: Time = Seconds/Program = Instructions Program × Clock cycles Instruction × Seconds Clock cycle Always bear in mind that the only complete and reliable measure of computer performance is time. For example, changing the instruction set to lower the instruction count may lead to an organization with a slower clock cycle time or higher CPI that offsets the improvement in instruction count. Similarly, because CPI depends on type of instructions executed, the code that executes the fewest number of instructions may not be the fastest. The BIG Picture | clipped_hennesy_Page_34_Chunk5391 |
How can we determine the value of these factors in the performance equation? We can measure the CPU execution time by running the program, and the clock cycle time is usually published as part of the documentation for a computer. The instruction count and CPI can be more difficult to obtain. Of course, if we know the clock rate and CPU execution time, we need only one of the instruction count or the CPI to determine the other. We can measure the instruction count by using software tools that profile the execution or by using a simulator of the architecture. Alternatively, we can use hardware counters, which are included in most processors, to record a variety of measurements, including the number of instructions executed, the average CPI, and often, the sources of performance loss. Since the instruction count depends on the architecture, but not on the exact implementation, we can measure the instruction count without knowing all the details of the implementation. The CPI, however, depends on a wide variety of design details in the computer, including both the memory system and the processor structure (as we will see in Chapters 4 and 5), as well as on the mix of instruction types executed in an application. Thus, CPI varies by application, as well as among implementations with the same instruction set. The above example shows the danger of using only one factor (instruction count) to assess performance. When comparing two computers, you must look at all three components, which combine to form execution time. If some of the factors are identical, like the clock rate in the above example, performance can be determined by comparing all the nonidentical factors. Since CPI varies by instruction mix, both instruction count and CPI must be compared, even if clock rates are identical. Several exercises at the end of this chapter ask you to evaluate a series of computer and compiler enhancements that affect clock rate, CPI, and instruction count. In Section 1.8, we’ll examine a common performance measurement that does not incorporate all the terms and can thus be misleading. instruction mix A measure of the dynamic frequency of instructions across one or many programs. Components of performance Units of measure CPU execution time for a program Seconds for the program Instruction count Instructions executed for the program Clock cycles per instruction (CPI) Average number of clock cycles per instruction Clock cycle time Seconds per clock cycle FIGURE 1.14 The basic components of performance and how each is measured. 1.4 Performance 37 | clipped_hennesy_Page_35_Chunk5392 |
38 Chapter 1 Computer Abstractions and Technology The performance of a program depends on the algorithm, the language, the compiler, the architecture, and the actual hardware. The following table summarizes how these components affect the factors in the CPU performance equation. Understanding Program Performance Hardware or software component Affects what? How? Algorithm Instruction count, possibly CPI The algorithm determines the number of source program instructions executed and hence the number of processor instructions executed. The algorithm may also affect the CPI, by favoring slower or faster instructions. For example, if the algorithm uses more floating-point operations, it will tend to have a higher CPI. Programming language Instruction count, CPI The programming language certainly affects the instruction count, since statements in the language are translated to processor instructions, which determine instruction count. The language may also affect the CPI because of its features; for example, a language with heavy support for data abstraction (e.g., Java) will require indirect calls, which will use higher CPI instructions. Compiler Instruction count, CPI The efficiency of the compiler affects both the instruction count and average cycles per instruction, since the compiler determines the translation of the source language instructions into computer instructions. The compiler’s role can be very complex and affect the CPI in complex ways. Instruction set architecture Instruction count, clock rate, CPI The instruction set architecture affects all three aspects of CPU performance, since it affects the instructions needed for a function, the cost in cycles of each instruction, and the overall clock rate of the processor. Elaboration: Although you might expect that the minimum CPI is 1.0, as we’ll see in Chapter 4, some processors fetch and execute multiple instructions per clock cycle. To reflect that approach, some designers invert CPI to talk about IPC, or instructions per clock cycle. If a processor executes on average 2 instructions per clock cycle, then it has an IPC of 2 and hence a CPI of 0.5. A given application written in Java runs 15 seconds on a desktop processor. A new Java compiler is released that requires only 0.6 as many instructions as the old compiler. Unfortunately, it increases the CPI by 1.1. How fast can we expect the application to run using this new compiler? Pick the right answer from the three choices below a. 15 × 0.6 1.1 = 8.2 sec b. 15 × 0.6 × 1.1 = 9.9 sec c. 15 × 1.1 0.6 = 27.5 sec Check Yourself | clipped_hennesy_Page_36_Chunk5393 |
1.5 The Power Wall Figure 1.15 shows the increase in clock rate and power of eight generations of Intel microprocessors over 25 years. Both clock rate and power increased rapidly for decades, and then flattened off recently. The reason they grew together is that they are correlated, and the reason for their recent slowing is that we have run into the practical power limit for cooling commodity microprocessors. FIGURE 1.15 Clock rate and Power for Intel x86 microprocessors over eight generations and 25 years. The Pentium 4 made a dramatic jump in clock rate and power but less so in performance. The Prescott thermal problems led to the abandonment of the Pentium 4 line. The Core 2 line reverts to a simpler pipeline with lower clock rates and multiple processors per chip. 2667 12.5 16 2000 200 66 25 3600 75.3 95 29.1 10.1 4.9 4.1 3.3 103 1 10 100 1000 10000 80286 (1982) 80386 (1985) 80486 (1989) Pentium (1993) Pentium Pro (1997) Pentium 4 Willamette (2001) Pentium 4 Prescott (2004) Core 2 Kentsfield (2007) Clock Rate (MHz) 0 20 40 60 80 100 120 Power (Watts) Clock Rate Power The dominant technology for integrated circuits is called CMOS (complemen tary metal oxide semiconductor). For CMOS, the primary source of power dissi pation is so-called dynamic power—that is, power that is consumed during switching. The dynamic power dissipation depends on the capacitive loading of each transistor, the voltage applied, and the frequency that the transistor is switched: Power = Capacitive load × Voltage2 × Frequency switched 1.5 The Power Wall 39 | clipped_hennesy_Page_37_Chunk5394 |
40 Chapter 1 Computer Abstractions and Technology Frequency switched is a function of the clock rate. The capacitive load per transistor is a function of both the number of transistors connected to an output (called the fanout) and the technology, which determines the capacitance of both wires and transistors. How could clock rates grow by a factor of 1000 while power grew by only a factor of 30? Power can be reduced by lowering the voltage, which occurred with each new generation of technology, and power is a function of the voltage squared. Typically, the voltage was reduced about 15% per generation. In 20 years, voltages have gone from 5V to 1V, which is why the increase in power is only 30 times. Relative Power Suppose we developed a new, simpler processor that has 85% of the capacitive load of the more complex older processor. Further, assume that it has adjust able voltage so that it can reduce voltage 15% compared to processor B, which results in a 15% shrink in frequency. What is the impact on dynamic power? Powernew Powerold = 〈Capacitive load × 0.85〉 × 〈Voltage × 0.85〉2 × 〈Frequency switched × 0.85〉 Capacitive load × Voltage2 × Frequency switched Thus the power ratio is 0.854 = 0.52 Hence, the new processor uses about half the power of the old processor. The problem today is that further lowering of the voltage appears to make the transistors too leaky, like water faucets that cannot be completely shut off. Even today about 40% of the power consumption is due to leakage. If transistors started leaking more, the whole process could become unwieldy. To try to address the power problem, designers have already attached large devices to increase cooling, and they turn off parts of the chip that are not used in a given clock cycle. Although there are many more expensive ways to cool chips and thereby raise their power to, say, 300 watts, these techniques are too expensive for desktop computers. Since computer designers slammed into a power wall, they needed a new way forward. They chose a different way from the way they designed microprocessors for their first 30 years. Elaboration: Although dynamic power is the primary source of power dissipation in CMOS, static power dissipation occurs because of leakage current that flows even when a transistor is off. As mentioned above, leakage is typically responsible for 40% of the power consumption in 2008. Thus, increasing the number of transistors increases power dissipation, even if the transistors are always off. A variety of design techniques and technology innovations are being deployed to control leakage, but it’s hard to lower voltage further. EXAMPLE ANSWER | clipped_hennesy_Page_38_Chunk5395 |
1.6 The Sea Change: The Switch from Uniprocessors to Multiprocessors The power limit has forced a dramatic change in the design of microprocessors. Figure 1.16 shows the improvement in response time of programs for desktop microprocessors over time. Since 2002, the rate has slowed from a factor of 1.5 per year to less than a factor of 1.2 per year. Rather than continuing to decrease the response time of a single program run ning on the single processor, as of 2006 all desktop and server companies are ship ping microprocessors with multiple processors per chip, where the benefit is often more on throughput than on response time. To reduce confusion between the words processor and microprocessor, companies refer to processors as “cores,” and such microprocessors are generically called multicore microprocessors. Hence, a “quadcore” microprocessor is a chip that contains four processors or four cores. Figure 1.17 shows the number of processors (cores), power, and clock rates of recent microprocessors. The official plan of record for many companies is to double the number of cores per microprocessor per semiconductor technology generation, which is about every two years (see Chapter 7). In the past, programmers could rely on innovations in hardware, architecture, and compilers to double performance of their programs every 18 months without having to change a line of code. Today, for programmers to get significant improve ment in response time, they need to rewrite their programs to take advantage of multiple processors. Moreover, to get the historic benefit of running faster on new microprocessors, programmers will have to continue to improve performance of their code as the number of cores doubles. To reinforce how the software and hardware systems work hand in hand, we use a special section, Hardware/Software Interface, throughout the book, with the first one appearing below. These elements summarize important insights at this critical interface. Parallelism has always been critical to performance in computing, but it was often hidden. Chapter 4 will explain pipelining, an elegant technique that runs pro grams faster by overlapping the execution of instructions. This is one example of instruction-level parallelism, where the parallel nature of the hardware is abstracted away so the programmer and compiler can think of the hardware as executing instructions sequentially. Forcing programmers to be aware of the parallel hardware and to explicitly rewrite their programs to be parallel had been the “third rail” of computer architec ture, for companies in the past that depended on such a change in behavior failed (see Section 7.14 on the CD). From this historical perspective, it’s startling that the whole IT industry has bet its future that programmers will finally successfully switch to explicitly parallel programming. “Up to now, most software has been like music written for a solo performer; with the current generation of chips we’re getting a little experience with duets and quartets and other small ensembles; but scoring a work for large orchestra and chorus is a different kind of challenge.” Brian Hayes, Computing in a Parallel Universe, 2007. Hardware/ Software Interface 1.6 The Sea Change: The Switch from Uniprocessors to Multiprocessors 41 | clipped_hennesy_Page_39_Chunk5396 |
42 Chapter 1 Computer Abstractions and Technology Why has it been so hard for programmers to write explicitly parallel programs? The first reason is that parallel programming is by definition performance pro gramming, which increases the difficulty of programming. Not only does the program need to be correct, solve an important problem, and provide a useful interface to the people or other programs that invoke it, the program must also be fast. Otherwise, if you don’t need performance, just write a sequential program. The second reason is that fast for parallel hardware means that the programmer must divide an application so that each processor has roughly the same amount to FIGURE 1.16 Growth in processor performance since the mid-1980s. This chart plots performance relative to the VAX 11/780 as measured by the SPECint benchmarks (see Section 1.8). Prior to the mid-1980s, processor performance growth was largely technology- driven and averaged about 25% per year. The increase in growth to about 52% since then is attributable to more advanced architectural and organizational ideas. By 2002, this growth led to a difference in performance of about a factor of seven. Performance for floating-point- oriented calculations has increased even faster. Since 2002, the limits of power, available instruction-level parallelism, and long memory latency have slowed uniprocessor performance recently, to about 20% per year. Performance (vs.VAX-11/780) 10,000 1000 100 10 1978 0 1980 1982 1984 1986 1988 1990 1992 1994 1996 1998 2000 2002 2004 2006 1779 Intel Pentium III, 1.0 GHz 2584 AMD Athlon, 1.6 GHz Intel Pentium 4, 3.0 GHz 4195 AMD Opteron, 2.2 GHz 5364 5764 Intel Xeon, 3.6 GHz 64-bit Intel Xeon, 3.6 GHz 6505 1267 Alpha 21264A, 0.7 GHz 993 Alpha 21264, 0.6 GHz 649 Alpha 21164, 0.6 GHz 481 Alpha 21164, 0.5 GHz 280 Alpha 21164, 0.3 GHz 183 Alpha 21064A, 0.3 GHz 117 PowerPC 604, 0.1GHz 80 Alpha 21064, 0.2 GHz 51 HP PA-RISC, 0.05 GHz 24 IBM RS6000/540 18 MIPS M2000 13 MIPS M/120 9 Sun-4/260 5 VAX 8700 1.5, VAX-11/785 25%/year 52%/year 20% VAX-11/780 Product AMD Opteron X4 (Barcelona) Intel Nehalem IBM Power 6 Sun Ultra SPARC T2 (Niagara 2) Cores per chip 4 4 02 8 Clock rate 2.5 GHz ~ 2.5 GHz ? 4.7 GHz 1.4 GHz Microprocessor power 120 W ~ 100 W ? ~ 100 W ? 94 W FIGURE 1.17 Number of cores per chip, clock rate, and power for 2008 multicore micro processors. | clipped_hennesy_Page_40_Chunk5397 |
do at the same time, and that the overhead of scheduling and coordination doesn’t fritter away the potential performance benefits of parallelism. As an analogy, suppose the task was to write a newspaper story. Eight reporters working on the same story could potentially write a story eight times faster. To achieve this increased speed, one would need to break up the task so that each reporter had something to do at the same time. Thus, we must schedule the sub tasks. If anything went wrong and just one reporter took longer than the seven others did, then the benefits of having eight writers would be diminished. Thus, we must balance the load evenly to get the desired speedup. Another danger would be if reporters had to spend a lot of time talking to each other to write their sections. You would also fall short if one part of the story, such as the conclusion, couldn’t be written until all of the other parts were completed. Thus, care must be taken to reduce communication and synchronization overhead. For both this analogy and parallel programming, the challenges include scheduling, load balancing, time for synchronization, and overhead for communication between the parties. As you might guess, the challenge is stiffer with more reporters for a newspaper story and more processors for parallel programming. To reflect this sea change in the industry, the next five chapters in this edition of the book each have a section on the implications of the parallel revolution to that chapter: ■ ■Chapter 2, Section 2.11: Parallelism and Instructions: Synchronization. Usually independent parallel tasks need to coordinate at times, such as to say when they have completed their work. This chapter explains the instructions used by multicore processors to synchronize tasks. ■ ■Chapter 3, Section 3.6: Parallelism and Computer Arithmetic: Associativity. Often parallel programmers start from a working sequential program. A natural question to learn if their parallel version works is, “does it get the same answer?” If not, a logical conclusion is that there are bugs in the new version. This logic assumes that computer arithmetic is associative: you get the same sum when adding a million numbers, no matter what the order. This chapter explains that while this logic holds for integers, it doesn’t hold for floating-point numbers. ■ ■Chapter 4, Section 4.10: Parallelism and Advanced Instruction-Level Parallelism. Given the difficulty of explicitly parallel programming, tremendous effort was invested in the 1990s in having the hardware and the compiler uncover implicit parallelism. This chapter describes some of these aggressive techniques, includ ing fetching and executing multiple instructions simultaneously and guessing on the outcomes of decisions, and executing instructions speculatively. 1.6 The Sea Change: The Switch from Uniprocessors to Multiprocessors 43 | clipped_hennesy_Page_41_Chunk5398 |
44 Chapter 1 Computer Abstractions and Technology ■ ■Chapter 5, Section 5.8: Parallelism and Memory Hierarchies: Cache Coherence. One way to lower the cost of communication is to have all processors use the same address space, so that any processor can read or write any data. Given that all processors today use caches to keep a temporary copy of the data in faster memory near the processor, it’s easy to imagine that parallel programming would be even more difficult if the caches associated with each processor had inconsistent values of the shared data. This chapter describes the mechanisms that keep the data in all caches consistent. ■ ■Chapter 6, Section 6.9: Parallelism and I/O: Redundant Arrays of Inexpensive Disks. If you ignore input and output in this parallel revolution, the unintended consequence of parallel programming may be to make your parallel program spend most of its time waiting for I/O. This chapter describes RAID, a technique to accelerate the performance of storage accesses. RAID points out another potential benefit of parallelism: by having many copies of resources, the system can continue to provide service despite a failure of one resource. Hence, RAID can improve both I/O performance and availability. In addition to these sections, there is a full chapter on parallel processing. Chapter 7 goes into more detail on the challenges of parallel programming; presents the two contrasting approaches to communication of shared addressing and explicit message passing; describes a restricted model of parallelism that is easier to program; discusses the difficulty of benchmarking parallel processors; introduces a new simple performance model for multicore microprocessors and finally describes and evaluates four examples of multicore microprocessors using this model. Starting with this edition of the book, Appendix A describes an increasingly popular hardware component that is included with desktop computers, the graph ics processing unit (GPU). Invented to accelerate graphics, GPUs are becoming programming platforms in their own right. As you might expect, given these times, GPUs are highly parallel. Appendix A describes the NVIDIA GPU and highlights parts of its parallel programming environment. 1.7 Real Stuff: Manufacturing and Benchmarking the AMD Opteron X4 Each chapter has a section entitled “Real Stuff” that ties the concepts in the book with a computer you may use every day. These sections cover the technology underlying modern computers. For this first “Real Stuff” section, we look at how integrated circuits are manufactured and how performance and power are mea sured, with the AMD Opteron X4 as the example. I thought [computers] would be a universally applicable idea, like a book is. But I didn’t think it would develop as fast as it did, because I didn’t envision we’d be able to get as many parts on a chip as we finally got. The transistor came along unexpectedly. It all happened much faster than we expected. J. Presper Eckert, coinventor of ENIAC, speaking in 1991 | clipped_hennesy_Page_42_Chunk5399 |
Let’s start at the beginning. The manufacture of a chip begins with silicon, a substance found in sand. Because silicon does not conduct electricity well, it is called a semiconductor. With a special chemical process, it is possible to add materials to silicon that allow tiny areas to transform into one of three devices: ■ ■Excellent conductors of electricity (using either microscopic copper or aluminum wire) ■ ■Excellent insulators from electricity (like plastic sheathing or glass) ■ ■Areas that can conduct or insulate under special conditions (as a switch) Transistors fall in the last category. A VLSI circuit, then, is just billions of combi nations of conductors, insulators, and switches manufactured in a single small package. The manufacturing process for integrated circuits is critical to the cost of the chips and hence important to computer designers. Figure 1.18 shows that process. The process starts with a silicon crystal ingot, which looks like a giant sausage. Today, ingots are 8–12 inches in diameter and about 12–24 inches long. An ingot is finely sliced into wafers no more than 0.1 inch thick. These wafers then go through a series of processing steps, during which patterns of chemicals are placed on silicon A natural element that is a semiconductor. semiconductor A substance that does not conduct electricity well. silicon crystal ingot A rod composed of a silicon crystal that is between 8 and 12 inches in diameter and about 12 to 24 inches long. wafer A slice from a silicon ingot no more than 0.1 inch thick, used to create chips. FIGURE 1.18 The chip manufacturing process. After being sliced from the silicon ingot, blank wafers are put through 20 to 40 steps to create patterned wafers (see Figure 1.19). These patterned wafers are then tested with a wafer tester, and a map of the good parts is made. Then, the wafers are diced into dies (see Figure 1.9). In this figure, one wafer produced 20 dies, of which 17 passed testing. (X means the die is bad.) The yield of good dies in this case was 17/20, or 85%. These good dies are then bonded into packages and tested one more time before shipping the packaged parts to customers. One bad packaged part was found in this final test. Slicer Dicer 20 to 40 processing steps Bond die to package Silicon ingot Wafer tester Part tester Ship to customers Tested dies Tested wafer Blank wafers Packaged dies Patterned wafers Tested packaged dies 1.7 Real Stuff: Manufacturing and Benchmarking the AMD Opteron X4 45 | clipped_hennesy_Page_43_Chunk5400 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.