Introduction to Probability with Mathematica Second Edition Kevin J. Hastings instant download
Introduction to Probability with Mathematica Second Edition Kevin J. Hastings instant download
https://ebookgate.com/product/introduction-to-probability-with-
mathematica-second-edition-kevin-j-hastings/
https://ebookgate.com/product/introduction-to-probability-second-
edition-george-g-roussas/
https://ebookgate.com/product/an-introduction-to-programming-
with-mathematica-3rd-ed-edition-paul-r-wellin/
https://ebookgate.com/product/introduction-to-probability-and-
statistics-second-edition-revised-and-expanded-edition-giri/
https://ebookgate.com/product/introduction-to-algebra-second-
edition-peter-j-cameron/
Introduction to Algebra Second Edition Peter J. Cameron
https://ebookgate.com/product/introduction-to-algebra-second-
edition-peter-j-cameron-2/
https://ebookgate.com/product/crc-standard-curves-and-surfaces-
with-mathematica-second-edition-david-h-von-seggern/
https://ebookgate.com/product/introduction-to-probability-2nd-
edition-dimitri-p-bertsekas/
https://ebookgate.com/product/introduction-to-probability-and-
statistics-thirteenth-edition-william-mendenhall/
https://ebookgate.com/product/introduction-to-probability-
models-9th-edition-sheldon-m-ross/
INTRODUCTION TO
Probability with
Mathematica®
Second Edition
TEXTBOOKS in MATHEMATICS
Series Editor: Denny Gulick
PUBLISHED TITLES
INTRODUCTION TO
Probability with
Mathematica®
Second Edition
Kevin J. Hastings
Knox College
Galesburg, Illinois, U.S.A.
Chapman & Hall/CRC
Taylor & Francis Group
6000 Broken Sound Parkway NW, Suite 300
Boca Raton, FL 33487-2742
This book contains information obtained from authentic and highly regarded sources. Reasonable efforts
have been made to publish reliable data and information, but the author and publisher cannot assume
responsibility for the validity of all materials or the consequences of their use. The authors and publishers
have attempted to trace the copyright holders of all material reproduced in this publication and apologize to
copyright holders if permission to publish in this form has not been obtained. If any copyright material has
not been acknowledged please write and let us know so we may rectify in any future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmit-
ted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented,
including photocopying, microfilming, and recording, or in any information storage or retrieval system,
without written permission from the publishers.
For permission to photocopy or use material electronically from this work, please access www.copyright.
com (http://www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood
Drive, Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization that provides licenses and
registration for a variety of users. For organizations that have been granted a photocopy license by the CCC,
a separate system of payment has been arranged.
Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used
only for identification and explanation without intent to infringe.
QA273.19.E4H37 2010
519.20285’536--dc22 2009030737
Kevin J. Hastings
Note on the Electronic Version and the
KnoxProb7Utilities Package
The CD that accompanies this book contains a Mathematica notebook for each text
section. Copyright law forbids you from distributing these notebooks without the express
permission of the publisher, just as with the print version. The print text was made without
color, by publisher specification, but color effects are included into the electronic version.
Otherwise the electronic notebooks are identical to the print version. When a notebook is
first loaded you can select the Evaluate Initialization Cells command under the Evaluation
menu to reproduce the output. The look of the notebooks in the front end will depend on
what style sheet you are using; I have applied the Book/Textbook stylesheet to these files.
Also on the disk are two packages: the KnoxProb7 Utilities package for users of
version 7 of Mathematica, and KnoxProb6`Utilities` for users of version 6. Move the
appropriate folder into the AddOns\ExtraPackages subdirectory of your main Mathematica
directory in order to allow the electronic book to run. The electronic files are written for
version 7, so the Needs commands in the notebooks should be modified to load Knox-
Prob6`Utilities` instead of KnoxProb7`Utilities` for Mathematica 6 users. The main differ-
ences between the two Utilities versions are: (1) the Histogram command that I had written
for the version 6 package is eliminated in the version 7 package because Wolfram Research
included its own suitable Histogram command into the kernel in version 7; and (2) the
ProbabilityHistogram command had to be rewritten for version 7 due to the elimination of
the BarCharts package that it had relied on. Both packages are updates of those in the
KnoxProb`Utilities` package that was available for the first edition of the book, adapting to
the major changes in the structure of Mathematica that happened as it went into version 6.0.
Among the most important changes for our purposes was that many statistical commands
that had previously been contained in external packages were moved into the kernel, so that
these packages no longer needed to be loaded. The electronic book has been subjected to a
lot of testing, and it should operate well.
Table of Contents
Chapter 1 – Discrete Probability
1.1 The Cast of Characters 1
1.2 Properties of Probability 10
1.3 Simulation 23
1.4 Random Sampling 33
Sampling in Sequence without Replacement 34
Sampling in a Batch without Replacement 38
Other Sampling Situations 42
1.5 Conditional Probability 48
Multiplication Rules 51
Bayes' Formula 56
1.6 Independence 62
Chapter 2 – Discrete Distributions
2.1 Discrete Random Variables, Distributions,
and Expectations 73
Mean, Variance, and Other Moments 79
Two Special Distributions 85
2.2 Bernoulli and Binomial Random Variables 94
Multinomial Distribution 102
2.3 Geometric and Negative Binomial Random Variables 107
2.4 Poisson Distribution 115
Poisson Processes 120
2.5 Joint, Marginal, and Conditional Distributions 124
2.6 More on Expectation 136
Covariance and Correlation 140
Conditional Expectation 148
Chapter 3 – Continuous Probability
3.1 From the Finite to the (Very) Infinite 159
3.2 Continuous Random Variables and Distributions 171
Joint, Marginal, and Conditional Distributions 178
3.3 Continuous Expectation 192
Chapter 4 – Continuous Distributions
4.1 The Normal Distribution 207
4.2 Bivariate Normal Distribution 225
Bivariate Normal Density 229
Marginal and Conditional Distributions 235
4.3 New Random Variables from Old 246
C.D.F. Technique and Simulation 247
Moment–Generating Functions 252
4.4 Order Statistics 259
4.5 Gamma Distributions 273
Main Properties 273
The Exponential Distribution 277
4.6 Chi–Square, Student’s t, and F–Distributions 281
Chi–Square Distribution 282
Student's t–Distribution 289
F–Distribution 293
4.7 Transformations of Normal Random Variables 300
Linear Transformations 301
Quadratic Forms in Normal Random Vectors 306
Chapter 5 – Asymptotic Theory
5.1 Strong and Weak Laws of Large Numbers 313
5.2 Central Limit Theorem 320
Chapter 6 – Stochastic Processes and Applications
6.1 Markov Chains 329
Short Run Distributions 331
Long Run Distributions 334
Absorbing Chains 338
6.2 Poisson Processes 344
6.3 Queues 352
Long Run Distribution of System Size 353
Waiting Time Distribution 358
Simulating Queues 359
6.4 Brownian Motion 365
Geometric Brownian Motion 373
6.5 Financial Mathematics 379
Optimal Portfolios 380
Option Pricing 385
Appendices
A. Introduction to Mathematica 395
B. Glossary of Mathematica Commands for Probability 423
C. Short Answers to Selected Exercises 431
References 445
Index 447
CHAPTER 1
DISCRETE PROBABILITY
1
2 Chapter 1 Discrete Probability
yourself in a kind of workshop, with Mathematica and your own insight and love of
experimentation as your most powerful tools. I caution you against depending too much on
the machine, however. Much of the time, traditional pencil, paper, and brainpower are what
you need most to learn. What the computer does, however, is open up new problems, or let
you get new insights into concepts. So we will be judiciously blending new technology with
traditionally successful pedagogy to enable you to learn effectively. Consistent themes will
be the idea of taking a sample randomly from a larger universe of objects in order to get
information about that universe, and the computer simulation of random phenomena to
observe patterns in many replications that speak to the properties of the phenomena.
The cast of characters in probability whose personalities we will explore in depth in
the coming chapters include the following six principal players: (1) Event; (2) Sample
Space; (3) Probability Measure; (4) Random Variable; (5) Distribution; and (6) Expectation.
The rest of this section will be a brief intuitive introduction to these six.
Most of the time we are interested in assessing likelihoods of events, that is, things
that we might observe as we watch a phenomenon happen. The event that a national chain's
bid to acquire a local grocery store is successful, the event that at least 10 patients arrive to
an emergency room between 6:00 and 7:00 AM, the event that a hand of five poker cards
forms a straight, the event that we hold the winning ticket in the lottery, and the event that
two particular candidates among several are selected for jury duty are just a few examples.
They share the characteristic that there is some uncertain experiment, sampling process, or
phenomenon whose result we do not know "now". But there is a theoretical "later" at which
we can observe the phenomenon taking place, and decide whether the event did or didn't
occur.
An outcome (sometimes called a simple event) is an event that cannot be broken
down into some combination of other events. A composite event is just an event that isn't
simple, that is, it has more than one outcome. For instance the event that we are dealt a poker
hand that makes up a straight is composite because it consists of many outcomes which
completely specify the hand, such as 2 through 6 of hearts, 10 through ace of clubs, etc.
This is where the sample space makes its entry: the sample space is the collection of
all possible outcomes of the experiment or phenomenon, that is all possible indecomposable
results that could happen. For the poker hand example, the sample space would consist of
all possible five-card hands. In specifying sample spaces, we must be clear about assump-
tions; for instance we might assume that the order in which the cards were dealt does not
matter, and we cannot receive the same card twice, so that the cards are dealt without
replacement.
Activity 1 How can you characterize the sample space for the grocery store example?
Make up your own random phenomenon, informally describe the sample space, and give
examples of events.
1.1 The Cast of Characters 3
Activity 2 In the emergency room example above, is the event that was described an
outcome or a composite event? If that event is composite, write down an example of an
outcome relating to that phenomenon.
In random phenomena, we need a way of measuring how likely the events are to
occur. This may be done by some theoretical considerations, or by experience with past
experiments of the same kind. A probability measure assigns a likelihood, that is a number
between 0 and 1, to all events. Though we will have to be more subtle later, for now we can
intuitively consider the extremes of 0 and 1 as representing impossibility and complete
certainty, respectively.
Much of the time in probability problems, probability measures are constructed so
that the probability of an event is the "size" of the event as a proportion of the "size" of the
whole sample space. "Size" may mean different things depending on the context, but the two
most frequent usages are cardinality, that is number of elements of a set, and length (or area
in two dimensions). For example, if you roll a fair die once, since there are six possible faces
that could land on top, the sample space is 1, 2, 3, 4, 5, 6. Since three of the faces are odd,
it seems reasonable that the probability that an odd number is rolled is 3/6. Size means
length in the following scenario. Suppose that a real number is to be randomly selected in
the interval 0, 4. This interval is the sample space for the random phenomenon. Then the
probability that the random real number will be in the interval 1, 3 is 2 4 1 2, which is
the length of the interval 1, 3 divided by the length of the whole sample space interval.
The first two chapters will concentrate on discrete probability, in which counting the
number of elements in sets is very important. We will leave much of the detail for later
sections, except to remind you of the intuitively obvious multiplication principle for
counting. If outcomes of a random experiment consist of two stages, then the total number of
outcomes of the experiment is the number of ways the first stage can occur times the number
of ways that the second can occur. This generalizes to multiple stage experiments. For
instance, if a man has 3 suits, 6 shirts, and 4 ties, and he doesn't care about color coordina-
tion and the like, then he has 3 6 4 72 possible outfits.
It is possible to experimentally estimate a probability by repeating the experiment
over and over again. The probability of the event can be estimated by the number of times
that it occurs among the replications divided by the number of replications. Try this
exercise. In the KnoxProb7`Utilities` package that you should have installed is a Mathemat-
ica command called
DrawIntegerSample[a, b, n]
4 Chapter 1 Discrete Probability
which outputs a sequence of n numbers drawn at random, without reusing numbers previ-
ously in the sequence, from the positive integers in the range a, ... , b. (You should be sure
that the package has been loaded into the ExtraPackages subdirectory within the Mathemat-
ica directory you are using on your computer.) First execute the command to load the
package, then try repeating the experiment of drawing samples of two numbers from
1, ... , 5 a large number of times. I have shown one such sample below. Keep track of how
frequently the number 1 appears in your samples. Empirically, what is a good estimate of the
probability that 1 is in the random sample of size two? Talk with a group of your classmates,
and see if you can set up a good theoretical foundation that supports your conclusion. (Try to
specify the sample space of the experiment.) We will study this type of experiment more
carefully later in this chapter. Incidentally, recall that Mathematica uses braces { } to
delineate sequences as well as unordered sets. We hope that the context will make it clear
which is meant; here the integer random sample is assumed to be in sequence, so that, for
example, 1, 3 is different from 3, 1.
Needs"KnoxProb7`Utilities`"
DrawIntegerSample1, 5, 2
1, 3
We are halfway through our introduction of the cast of characters. Often the outc-
omes of a random phenomenon are not just numbers. They may be sequences of numbers as
in our sampling experiment, or even non-numerical data such as the color of an M&M that
we randomly select from a bag. Yet we may be interested in encoding the simple events by
single numbers, or extracting some single numerical characteristic from more complete
information. For example, if we are dealt a five card hand in poker, an outcome is a full
specification of all five cards, whereas we could be interested only in the number of aces in
the hand, which is a numerical valued function of the outcome. Or, the sample space could
consist of subjects in a medical experiment, and we may be interested in the blood sugar
level of a randomly selected subject. Such a function for transforming outcomes to numerical
values is called a random variable, the fourth member of our cast of characters. Since the
random variable depends on the outcome, and we do not know in advance what will happen,
the value of the random variable is itself uncertain until after the experiment has been
observed.
Activity 3 Use DrawIntegerSample again as below to draw samples of size five from a
population of size 50. Suppose we are interested in the random variable which gives the
minimum among the members of the sample. What values of this random variable do
you observe in several replications?
1.1 The Cast of Characters 5
The cell below contains a command I have called SimulateMinima for observing a
number m of values of the minimum random variable from Activity 3. Read the code
carefully to understand how it works. An integer sample is drawn from the set
{1,2,...,popsize}, and then its minimum is taken. The Table command assembles a list of m
of these minima. To get an idea of the pattern of those sample minima, we plot a graph
called a histogram which tells the proportion of times among the m replications of the
experiment that the sample minimum fell into each of a given number of categories. The
Histogram command is in the kernel in Mathematica 7. Its exact syntax is
where the latter two arguments are optional. (See the help documentation, the note in the
preface, and the appendix on Mathematica commands for version 6 of Mathematica and the
KnoxProb6`Utilities` package.) The binspecifications argument can be set to be a number
for a desired number of categories, or it can be set to a list d w for a desired category width.
The third argument can be set to "Count," "Probability," or "ProbabilityDensity," respec-
tively, to force the bar heights to be freqencies, relative frequencies, or relative frequencies
divided by category widths. One output cell is shown in Figure 1 using 100 replications, six
histogram rectangles, and using samples of size 5 from {1, ... , 50}. You should reexecute
several times to see whether your replications give similar histograms. Should they be
identical to this one? Why or why not? (If you want to suppress the list of minima and get
only the histogram, put a semicolon between the SimulateMinima and Histogram
commands.)
35
30
25
20
15
10
5
5 10 15 20 25 30
Figure 1.1 - Sample histogram of minimum of five values from 1, 2, ... , 50
The histogram for the sample minimum that we just saw, together with your experi-
ments, hints at a very deep idea, which is the fifth member of our cast. A random variable
observed many times will give a list of values that follows a characteristic pattern, with some
random variation. The relative frequencies of occurrence (that is the number of occurrences
divided by the number of replications) of each possible value of the random variable, which
are the histogram rectangle heights, will stabilize around some theoretical probability. Much
as a probability measure can be put on a sample space of simple events, a probability
distribution can be put on the collection of possible values of a random variable. To cite a
very simple example, if 1/3 of the applicants for a job are men and 2/3 are women, if one
applicant is selected randomly, and if we define a random variable
1 if applicant is a man
X
0 if applicant is a woman
then the two possible values of X are 1 and 0, and the probability distribution for this X gives
probability 1/3 to value 1 and 2/3 to value 0.
The last member of our cast is expectation or expected value of a random variable.
Its purpose is to give a single number which is an average value that the random variable can
take on. But if these possible values of the random variable are not equally likely, it doesn't
make sense to compute the average as a simple arithmetical average. For example, suppose
the number of 911 emergency calls during an hour is a random variable X whose values and
probability distribution are as in the table below.
1.1 The Cast of Characters 7
value of X 2 4 6 8
probability 1 10 2 10 3 10 4 10
What could we mean by the average number of calls per hour? The simple arithmetical
average of the possible values of X is (2+4+6+8)/4 = 5, but 6 and 8 are more likely than 2
and 4, so they deserve more influence. In fact, the logical thing to do is to define the
expected value of X, denoted by E[X], to be the weighted average of the possible values,
using the probabilities as weights:
1 2 3 4 60
EX 2 4 6 8 6
10 10 10 10 10
We will be looking at all of our characters again in a more careful way later, but I
hope that the seeds of intuitive understanding have been planted. You should reread this
introductory section from time to time as you progress to see how the intuition fits with the
formality.
Exercises 1.1
1. Most state lotteries have a version of a game called Pick 3 in which you win an amount,
say $500, if you correctly choose three digits in order. Suppose that the price of a Pick 3
ticket is $1. There are two possible sample spaces that might be used to model the random
experiment of observing the outcome of the Pick 3 experiment, according to whether the
information of the winning number is recorded, or just the amount you won. Describe these
two sample spaces clearly, give examples of outcomes for both, and describe a reasonable
probability measure for both.
2. A grand jury is being selected, and there are two positions left to fill, with candidates A,
B, C, and D remaining who are eligible to fill them. The prosecutor decides to select a pair
of people by making slips of paper with each possible pair written on a slip, and then
drawing one slip randomly from a hat. List out all outcomes in the sample space of this
random phenomenon, describe a probability measure consistent with the stated assumptions,
and find the probability that A will serve on the grand jury.
3. In an effort to predict performance of entering college students in a beginning mathemat-
ics course on the basis of their mathematics ACT score, the following data were obtained.
The entries in the table give the numbers of students among a group of 179 who had the
indicated ACT score and the indicated grade.
Grade
A B C D F
23 2 5 16 31 3
ACT 24 6 8 12 15 2
25 7 10 15 6 1
26 8 15 13 4 0
8 Chapter 1 Discrete Probability
(a) A student is selected randomly from the whole group. What is the probability that this
student has a 25 ACT and received a B? What is the probability that this student received a
C? What is the probability that this student has an ACT score of 23?
(b) A student is selected randomly from the group of students who scored 24 on the ACT.
What is the probability that this student received an A?
(c) A student is selected randomly from the group of students who received B's. What is the
probability that the student scored 23 on the ACT? Is it the same as your answer to the last
question in part (a)?
4. Find the sample space for the following random experiment. Four people labeled A, B, C,
and D are to be separated randomly into a group of 2 people and two groups of one person
each. Assume that the order in which the groups are listed does not matter, only the contents
of the groups.
5. Consider the experiment of dealing two cards from a standard 52 card deck (as in black-
jack), one after another without replacing the first card. Describe the form of all outcomes,
and give two examples of outcomes. What is the probability of the event "King on 1st card?"
What is the probability of the event "Queen on 2nd card?"
6. In the Pick 3 lottery example of Exercise 1, consider the random variable X that gives the
net amount you win if you buy one ticket (subtracting the ticket price). What is the probabil-
ity distribution of X? What is the expected value of X?
a X
b 0
c
d 1
e
f
Exercise 7
7. An abstract sample space has outcomes a, b, c, d, e, and f as shown on the left in the
figure. Each outcome has probability 1/6. A random variable X maps the sample space to the
set {0,1} as in the diagram. What is the probability distribution of X? What is the expected
value of X?
1.1 The Cast of Characters 9
8. Two fair coins are flipped at random and in succession. Write the sample space explicitly,
and describe a reasonable probability measure on it. If X is the random variable that counts
the number of heads, find the probability distribution of X and compute the expected value
of X.
9. Using the data in Exercise 3, give an empirical estimate of the probability distribution of
the random variable X that gives the ACT score of a randomly selected student. What is the
expected value of X, and what is its real meaning in this context?
10. (Mathematica) Use the DrawIntegerSample command introduced in the section to build
a command that draws a desired number of samples, each of a desired size, from the set
1, 2, ..., popsize. For each sample, the command appends the maximum number in the
sample to a list. This list can be used to create a histogram of the distribution of maxima.
Repeat the experiment of taking 50 random samples of size 4 from 1, 2, ... , 7 several
times. Describe in words the most salient features of the histograms of the maximum. Use
one of your replications to give an empirical estimate of the probability distribution of the
maximum.
11. (Mathematica) The command SimulateMysteryX[m] illustrated below will simulate a
desired number m of values of a mystery random variable X. First load the KnoxProb7`Utili-
ties` package, then run the command several times using specific numerical values for m.
Try to estimate the probability distribution of X and its expected value.
SimulateMysteryX 10
12. (Mathematica) Write a command in Mathematica which can take as input a list of pairs
pi , xi in which a random variable X takes on the value xi with probability pi and return the
expectation of X. Test your command on the random variable whose probability distribution
is in the table below.
value of X 0 1 2 3
probability 1 4 1 2 1 8 1 8
13. Two flights are selected randomly and in sequence from a list of departing flights
covering a single day at an airport. There were 100 flights in the list, among which 80
departed on time, and 20 did not. Write a description of the sample space of the experiment
of selecting the two flights, and use the multiplication principle to count how many elements
the sample space has. Now let X be the number of flights in the sample of two that were
late. Find the probability distribution of X .
10 Chapter 1 Discrete Probability
1
3
5
There are 5 possible outcomes, namely, the scores 1-5. We can think of the experi-
ment of randomly sampling a student score as spinning the arrow on the pie chart of Figure
2, which has been constructed so that the angles of the circular wedges are proportional to
the frequencies in the categories that were listed in the last paragraph.
This example illustrates several important features of the subject of probability.
First, there is an underlying physics that drives the motion and final resting position of the
arrow. But differences in the starting point, the angular momentum imparted to the arrow,
and even slight wind currents and unevenness of the surface of the spinner give rise to a non-
deterministic or random phenomenon. We cannot predict with certainty where the arrow
will land. It could be philosophically argued that if we knew all of these randomizing factors
perfectly, then the laws of physics would perfectly predict the landing point of the arrow, so
that the phenomenon is not really random. Perhaps this is true in most, if not all, phenomena
that we call random. Nevertheless, it is difficult to know these factors, and the ability to
measure likelihoods of events that we model as random is useful to have.
1.2 Properties of Probability 11
Second, this example shows the two main ways of arriving at an assignment of
probabilities. We might make simplifying assumptions which lead to a logical assignment of
probability. Or we might repeat the experiment many times and observe how frequently
events occur. We were fortunate enough here to have the background data from which our
spinner was constructed, which would indicate by simple counting that if the spinner was
truly spun "randomly" we should assign probabilities
74 293 480 254 130
P1 , P2 , P3 , P4 , P5 (1)
1231 1231 1231 1231 1231
to the five outcomes. But step back for a moment and consider what we would have to do
with our spinner if we weren't blessed with the numbers. We would have no recourse but to
perform the experiment repeatedly. If, say, 1000 spins produced 70 1's, then we would
estimate P[1] empirically by 70 1000 .07, and similarly for the other outcomes.
Third, we can attempt to generalize conclusions. This data set itself can be thought
of as a sort of repeated spinning experiment, in which each student represents a selection
from a larger universe of students who could take the test. The probabilities in formula (1),
which would be exact probabilities for the experiment of selecting one student from this
particular batch, become estimates of probabilities for a different experiment; that of
selecting 1231 students from the universe of all students, past and present, who could take
the test. Whether our particular data set is a "random" sample representing that universe
without bias is a very serious statistical question, best left for a statistics course with a good
unit on samples and surveys.
Using the probabilities in (1), how should probability be assigned to composite
events like "1 or 3?" The logical thing to do is to pool together the probabilities of all
outcomes that are contained in the composite event. Then we would have
74 480 554
P1 or 3 P1 P3 (2)
1231 1231 1231
So the probability of an event is the total of all probabilities of the outcomes that make up
the event.
Two implications follow easily from the last observation: the empty event which
contains no outcomes has probability zero. Also, the event that the spinner lands somewhere
is certain, that is, it has probability 1 (100%). Another way to look at it is that the sample
space, denoted by say, is the composite event consisting of all outcomes. In this case we
have:
P P1 or 2 or 3 or 4 or 5
P1 P2 P5
74 293 130 (3)
1231 1231 1231
1
12 Chapter 1 Discrete Probability
In summary, so far we have learned that outcomes can be given probabilities between
0 and 1 using theoretical assumptions or empirical methods, and probabilities for composite
events are the totals of the outcome probabilities for outcomes in the event. Also P 0
and P 1. Try the following activity, which suggests another property. You will learn
more about that property shortly.
Activity 1 For the spinner experiment we looked at P[1 or 3]. Consider now the two
events "at least 3" and "between 1 and 3 inclusive." What is the probability of the event
"at least 3" or "between 1 and 3 inclusive"? How does this probability relate to the
individual event probabilities? Can you deduce a general principle regarding the
probability of one event or another occurring?
Sometimes we are interested in the set theoretic complement of an event, i.e., the
event that the original event does not occur. Does the probability of the complementary
event relate to the probability of the event? For the spinner, look at the events "at least 3"
and "less than 3," which are complements. We have, using formula (1):
480 254 130 864
Pat least 3 P3 or 4 or 5
1231 1231 1231 1231
(4)
74 293 367
Pless than 3 P1 or 2
1231 1231 1231
Notice that the two probabilities add to one, that is for these two events E and Ec :
PE PEc 1 (5)
This is not a coincidence. Together E and Ec contain all outcomes, and they have no
outcomes in common. The total of their probabilities must therefore equal 1, which is the
probability of the sample space.
Example 2. Let's look at another random phenomenon. Recall from Section 1.1 the
experiment of selecting a sequence of two numbers at random from the set 1, 2, 3, 4, 5
with no repetition of numbers allowed. Such an ordered selection without replacement is
known as a permutation, in this case a permutation of 2 objects from 5. Mathematica can
display all possible permutations as follows. The command
KPermutations[list, k]
in the KnoxProb7`Utilities` package returns a list of all ordered sequences of length k from
the list given in its first argument, assuming that a list member, once selected, cannot be
selected again.
1.2 Properties of Probability 13
Needs"KnoxProb7`Utilities`"
KPermutations1, 2, 3, 4, 5, 2
1, 2, 2, 1, 1, 3, 3, 1, 1, 4, 4, 1,
1, 5, 5, 1, 2, 3, 3, 2, 2, 4, 4, 2, 2, 5,
5, 2, 3, 4, 4, 3, 3, 5, 5, 3, 4, 5, 5, 4
20
As the Length output reports, there are 20 such permutations. These 20 are the outcomes that
form the sample space of the experiment. The randomness of the drawing makes it quite
reasonable to take the theoretical approach to assigning probabilities. Each outcome should
have the same likelihood. Since the total sample space has probability 1, the common
likelihood of the simple events, say x, satisfies
x x x 20 times 1 20 x 1 x 1 20 (6)
In other words, our probability measure on the sample space is defined on outcomes as:
P1, 2 P2, 1 P1, 3 P5, 4 1 20 (7)
and for composite events, we can again total the probabilities of outcomes contained in them.
Activity 2 In the example of selecting two positive integers from the first five, find the
probability that 1 is in the sample. Explain why your result is intuitively reasonable.
For instance,
Peither 1 or 2 is in the sample
P1, 2, 2, 1, 1, 3, 3, 1, 1, 4, 4, 1, 1, 5, 5, 1,
2, 3, 3, 2, 2, 4, 4, 2, 2, 5, 5, 2
14 20
and
P2 is not in sample
P1, 3, 3, 1, 1, 4, 4, 1, 1, 5, 5, 1, 3, 4, 4, 3, 3, 5,
5, 3, 4, 5, 5, 4
12 20
14 Chapter 1 Discrete Probability
By counting outcomes you can check that P[2 is in sample] = 8/20, which is complementary
to P[2 is not in sample] = 12/20 from above. Also notice that
8
P1 in sample P2 in sample
20
however,
14 8 8
P1 in sample or 2 in sample
20 20 20
We see that the probability of the event "either 1 is in the sample or 2 is in the sample" is not
simply the sum of the individual probability that 1 is in the sample plus the probability that 2
is in it. The reason is that in adding 8 20 8 20 we let the outcomes 1, 2 and 2, 1
contribute twice to the sum. This overstates the true probability, but we now realize that it is
easy to correct for the double count by subtracting 2 20 which is the amount of probability
contributed by the doubly counted outcomes. (See Theorem 2 below.)
Activity 3 Use Mathematica to display the ordered samples of size 3 without replace-
ment from 1, 2, 3, 4, 5, 6. What is the probability that 1 is in the sample? What is the
probability that neither 5 nor 6 is in the sample?
Armed with the experience of our examples, let us now develop a mathematical
model for probability, events, and sample spaces that proceeds from a minimal set of axioms
to derive several of the most important basic properties of probability. A few other properties
are given in the exercises.
Definition 1. A sample space of a random experiment is a set whose elements Ω are
called outcomes.
Definition 2 below is provisional we will have to be more careful about what an
event is when we come to continuous probability.
Definition 2. An event A is a subset of the sample space , hence an event is a set of
outcomes. The collection of all events is denoted by .
Suppose for example we consider another sampling experiment in which three letters
are to be selected at random, without replacement and without regard to order from the set of
letters a, b, c, d. The Combinatorica` package in Mathematica (which is loaded automati-
cally when you load KnoxProb7`Utilities`) has the commands
which, respectively, return all subsets of size k taken from the given list of objects, and all
subsets of the given universal set. We can use these to find the sample space of the experi-
ment, and the collection of events :
1.2 Properties of Probability 15
KSubsetsa, b, c, d, 3
Subsets
Notice that the empty set is the first subset of that is displayed; next are the simple
events a, b, c, a, b, d etc.; next are the two element composite events; and so forth.
In all subsequent work we will continue a practice that we have done so far, which is
to blur the distinction between outcomes Ω, which are members of the sample space, and
simple events Ω which are sets consisting of a single outcome. This will enable us to speak
of the "probability of an outcome" when in fact probability is a function on events, as seen in
the next definition.
Definition 3. A probability measure P is a function taking the family of events to the real
numbers such that
(i) P 1;
(ii) For all A , P[A] 0;
(iii) If A1 , A2 , is a sequence of pairwise disjoint events then
P[A1 A2 = PAi
i
Properties (i), (ii), and (iii) are called the axioms of probability. Our mathematical
model so far corresponds with our intuition: a random experiment has a set of possible
outcomes called the sample space, an event is a set of these outcomes, and probability
attaches a real number to each event. Axiom (i) requires the entire sample space to have
probability 1, axiom (ii) says that all probabilities are non-negative numbers, and axiom (iii)
says that when combining disjoint events, the probability of the union is the sum of the
individual event probabilities. For finite sample spaces this axiom permits us to just define
probabilities on outcomes, and then give each event a probability equal to the sum of its
(disjoint) outcome probabilities. We will encounter various ways of constructing probability
measures along the way, which we must verify to satisfy the axioms. Once having done so,
other properties of probability listed in the theorems below are ours for free. They follow
from the axioms alone, and not from any particular construction, which of course is the huge
advantage of basing a mathematical model on the smallest possible collection of axioms.
16 Chapter 1 Discrete Probability
Theorem 1 was anticipated earlier. It is generally used in cases where the comple-
ment of an event of interest is easier to handle than the original event. If we have the
probability of one of the two, then we have the other by subtracting from 1.
The next result is based on the idea that the total probability of a union can be found
by adding the individual probabilities and correcting if necessary by subtracting the probabil-
ity in the double-counted intersection region.
A B
A B
Figure 1.3 - The probability of a union is the total of the event probabilities minus the intersection probability
Proof. (See Figure 3.) Since A can be expressed as the disjoint union A = (A B)
A Bc , and B can be expressed as the disjoint union B A B B Ac we have, by
axiom (iii),
PA PB PA B PA Bc PA B PB Ac
PA Bc PB Ac 2 PA B
Therefore,
1.2 Properties of Probability 17
But it is easy to see from Figure 3 that the events (A Bc ), (B Ac ), and A B are
pairwise disjoint and their union is A B. Thus, by axiom (iii) of probability again,
PA Bc PB Ac PA B PA B (11)
Combining (10) and (11) proves the first assertion. The second assertion follows directly as
a specialization of axiom (iii) to two events. Alternatively, if A and B are disjoint, then
A B and by Exercise 11, P 0.
Activity 4 Try to devise an analogous thoerem to Theorem 2 for a three set union.
(Hint: if you subtract all paired intersection probabilities, are you doing too much?) See
Exercise 14 for a statement of the general result.
You may be curious that the axioms only require events to have non-negative
probability. It should also be clear that events must have probability less than or equal to 1,
because probability 1 represents certainty. In the exercises you are asked to give a rigorous
proof of this fact, stated below as Theorem 3.
Theorem 3. For any event A, P[A] 1.
Another intuitively obvious property is that if an event B has all of the outcomes in it
that another event A has, and perhaps more, then B should have higher probability than A.
This result is given as Theorem 4, and the proof is Exercise 12.
Theorem 4. If A and B are events such that A B, then P[A] P[B].
Theorems 3 and 4 help to reassure us that our theoretical model of probability
corresponds to our intuition, and they will be useful in certain proofs. But Theorems 1 and 2
on complements and unions are more useful in computations. We would like to finish this
section by adding a third very useful computational result, usually called the Law of Total
Probability. Basically it states that we can "divide and conquer," that is break up the
computation of a complicated probability P[A] into a sum of easier probabilities of the form
P[A B]. The imposition of condition B in addition to A presumably simplifies the computa-
tion by limiting or structuring the outcomes in the intersection. (See Figure 4.) All of our
computational results will be used regularly in the rest of the text, and the exercise set for
this section lets you begin to practice with them.
18 Chapter 1 Discrete Probability
B1 B2 ... Bn
A
Proof. We will use induction on the number of events Bi beginning with the base case n =
2. In the base case, it is clear that B2 = Bc1 , and therefore A A B1 A Bc1 and the two
sets in this union are disjoint. By Theorem 2,
PA PA B1 PA Bc1 PA B1 PA B2
Then the Ci 's are also a partition of (see Activity 5 below). By the inductive hypothesis
PA ni1 PA Ci
ni11 PA Bi PA Bn Bn1
ni 11 PA Bi P A Bn A Bn1 (13)
ni11 PA Bi PA Bn PA Bn1
n1
i1 PA Bi
Activity 5 Why are the Ci 's in the proof of the Law of Total Probability a partition of
? Why is the fourth line of (13) true?
1.2 Properties of Probability 19
Exercises 1.2
1. Consider the experiment of rolling one red die and two white dice randomly. Observe the
number of the face that lands up on the red die and the sum of the two face up numbers on
the white dice.
(a) Describe the sample space, giving the format of a typical outcome and two specific
examples of outcomes.
(b) Define a probability measure on this sample space. Argue that it satisfies the three
axioms of probability.
red die
1 2 3 4 5 6
2 3b
3 2b 1b
4 1b
5 1b 2b
6 1b
white sum
7 1b HR
8 1b 1b
9 2b 1b
10 1b
11 1b 1b
12 2 b
Exercise 2
(b) Define a probability measure on this sample space. Argue that it satisfies the three
axioms of probability.
(c) What is the probability that the random guesser gets at least two questions right?
4. (Mathematica) Use Mathematica to display the sample space of all possible random
samples without order and without replacement of three names from the list of names {Al,
Bubba, Celine, Delbert, Erma}. How many events are in the collection of all events ?
Describe a probability measure for this experiment, and find the probability that either
Bubba or Erma is in the sample.
5. Explain why each of the following attempts P1 and P2 is not a good definition of a
probability measure on the space of outcomes = {a, b, c, d, e, f, g}.
P1 P2
a .12 .16
b .05 .20
c .21 .20
d .01 .12
e .04 .08
f .28 .15
g .13 .12
6. (Mathematica) Use Mathematica to display the sample space of all possible random
samples in succession and without replacement of two numbers from the set 1, 2, ..., 10.
Describe a probability measure, and find the probability that 10 is not in the sample.
7. A 1999 Internal Revenue Service study showed that 44.9 million U.S. taxpayers reported
earnings of less than $20,000, 20.4 million earned between $20,000 and $30,000, 16.2
million earned between $30,000 and $40,000, 41.9 million earned between $40,000 and
$100,000, and 10.5 million earned more than $100,000.
(a) Write the outcomes for the experiment of sampling one taxpayer at random, and define
a probability measure. In such a random sample of one taxpayer, what is the probability that
the reported earnings is at least $30,000?
(b) Write the outcomes for the experiment of sampling two taxpayers at random and with
replacement, that is, once a taxpayer has been selected that person goes back into the pool
and could be selected again. Define a probability measure. (Hint: for a succession of two
events which do not depend on one another, it makes sense to compute the probability that
they both occur as the product of their probabilities. You can convince yourself of this by
considering a very simple experiment like the flip of two coins.) Find the probability that at
least one of the two earned more than $100,000.
1.2 Properties of Probability 21
x,y
2 1 1 2
Exercise 8
15. The general result for the probability of a union, which has Theorem 2 and Exercise 14
as special cases, is called the law of inclusion and exclusion. Let A1 , A2 , A3 , ..., An be a
collection of n events. To simplify notation, let Aij stand for a typical intersection of two of
them Ai A j , let Aijk stand for a three-fold intersection Ai Aj Ak , etc. The law states that
22 Chapter 1 Discrete Probability
PA1 A2 A3 ... An
PAi PAij PAijk
i i j i j k
n1
1 PA1 A2 A3 ... An
In other words, one alternately adds and subtracts all k-fold intersection probabilities as k
goes from 1 to n. Use this result in the following classical problem. Four men leave their
hats at a hat check station, then on departing take a hat randomly. Find the probability that
at least one man takes his own hat.
16. Recall Exercise 5 of Section 1.1 (the blackjack deal). Use the Law of Total Probability,
Theorem 5, to find P[queen on 2nd] in a well-justified way.
17. There are two groups of experimental subjects, one with 2 men and 3 women and the
other with 3 men and 2 women. A person is selected at random from the first group and
placed into the second group. Then a person is randomly selected from the second group.
Use the Law of Total Probability to find the probability that the person selected from the
second group is a woman.
In this book we will include as appropriate problems taken from the list of sample
questions for the Society of Actuaries/Casualty Actuarial Society qualifying exam P
(Probability). These problems have been obtained with permission from the societies at the
website www.soa.org/files/pdf/P-09-05ques.pdf.
Sample Problems from Actuarial Exam P
18. The probability that a visit to a primary care physician's (PCP) office results in neither
lab work nor referral to a specialist is 35%. Of those coming to a PCP's office, 30% are
referred to specialists and 40% require lab work. Determine the probability that a visit to a
PCP's office results in both lab work and referral to a specialist.
19. An urn contains 10 balls: 4 red and 6 blue. A second urn contains 16 red balls and an
unknown number of blue balls. A single ball is drawn from each urn. The probability that
both balls are the same color is 0.44. Calculate the number of blue balls in the second urn.
20. An auto insurance company has 10,000 policyholders. Each policyholder is classified as:
(i) young or old; (ii) male or female; and (iii) married or single. Of these policyholders, 3000
are young, 4600 are male, and 7000 are married. The policyholders can also be classified as
1320 young males, 3010 married males, and 1400 young married persons. Finally, 600 of
the policyholders are young married males. How many of the company's policyholders are
young, female, and single?
21. An insurer offers a health plan to the employees of a large company. As part of this plan,
the individual employees may choose exactly two of the supplementary coverages A, B, and
C, or they may choose no supplementary coverage. The proportions of the company's
employees that choose coverages A, B, and C are 1/4, 1/3, and 5/12 respectively. Determine
the probability that a randomly chosen employee will choose no supplementary coverage.
1.3 Simulation 23
1.3 Simulation
To simulate means to reproduce the results of a real phenomenon by artificial means.
We are interested here in phenomena that have a random element. What we really simulate
are the outcomes of a sample space and/or the states of a random variable in accordance with
the probability measure or distribution that we are assuming. Computers give a fast and
convenient way of carrying out these sorts of simulations.
There are several reasons to use simulation in problems. Sometimes we do not yet
have a good understanding of a phenomenon, and observing it repeatedly may give us
intuition about a question related to it. In such cases, closed form analytical results might be
derivable, and the simulation mostly serves the purpose of suggesting what to try to prove.
But many times the system under study is complex enough that analysis is either very
difficult or impossible. (Queueing problems see Section 6.3 are good illustrations of
both situations.) Then simulation is the only means of getting approximate information, and
the tools of probability and statistics also allow us to measure our confidence in our conclu-
sions. Another reason to simulate is somewhat surprising. In some inherently non-probabilis-
tic problems we can use a simulated random target shooting approach to gain information
about physical measurements of size and shape. A simple example of such a problem
solving method (traditionally called Monte Carlo simulation in reference to the European
gaming center) is the example on area of a region in Exercise 8.
I have chosen to give the subject emphasis and early treatment in this book for
another reason. There is more at stake for you intellectually than gaining intuition about
systems by observing simulations. Building an algorithm to solve a problem by simulation
helps to teach you about the subtle concepts of the subject of probability, such as probability
measures and random variables. Thus, here and elsewhere in this book I will be asking you
to carefully study the details of programs I have written, and to write some simulation
programs in Mathematica yourself. You will invest some time and mental effort, but the
payoff will be great.
We have already experienced simulation in the form of selecting ordered samples
without replacement of two numbers from the set 1, 2, 3, 4, 5. In that context we looked
at the empirical histogram of the minimum of the two numbers. We will treat simulations of
samples again in more detail in the next section. For the time being let us see how to use
Mathematica's tools for generating streams of random numbers to solve problems.
Most of the kind of simulations that we will do are adaptations of the simple process
of choosing a random real number in the interval 0, 1. The word "random" here could be
replaced by the more descriptive word "uniform," because the assumption will be that
probability is distributed uniformly through 0, 1, with sets getting large probability only if
their size is large, not because they happen to be in some favored location in 0, 1. More
precisely, we suppose that the sample space of the random experiment is = 0, 1, the
collection of events consists of all subsets of 0, 1 for which it is possible to define their
24 Chapter 1 Discrete Probability
length, and the probability measure P gives probability to a set equal to its length. Then for
instance:
1 3 1 1 2 1 1 7
P 0, 1 1, P , , P 0, , 1 ,
2 4 4 4 3 4 3 12
5
P 0
6
UniformDistribution[{a,b}]
is the syntax for the uniform distribution on the interval [a,b], and
return, respectively, one or a list of n random numbers from the given distribution. Here are
some examples of their use.
4.42891
2.00398
Notice that new random numbers in 2, 5 are returned each time that RandomReal is called.
Incidentally, RandomReal may be used with an empty argument when the distribution being
sampled from is the uniform distribution on 0, 1, which is what we will usually need.
How do Mathematica and other programs obtain such random numbers? There are
several means that are possible, but the most common type of random number generator is
the linear congruential generator which we describe now. The ironic fact is that our
supposedly random stream of numbers is only simulated in a deterministic fashion in such a
1.3 Simulation 25
where multiplier, increment, and modulus are positive integer constants. Then, using the
newly computed seed, return the number
rand seed modulus (2)
Subsequent random numbers are found in the same way, updating seed by formula (1) and
dividing by modulus. Notice that because the initial seed is non-negative and all of the
constants are positive, seed will stay non-negative, which makes rand 0 as well. And since
the mod operation returns a value less than modulus, seed will be less than modulus, hence
rand will be less than 1. So each pseudo-random number that we produce will lie in [0, 1).
Now the larger the value of modulus, the more possible values of seed there can be;
hence, the more real numbers that can be returned when formula (2) is applied. In fact, there
would be exactly modulus number of possible seed values. But modulus, multiplier, and
increment must be carefully chosen to take advantage of this, otherwise, the sequence of
pseudo-random numbers could cycle with a very small period. As a simple example, if the
constants were as follows:
new seed 2 seed 2 mod 8
then possible seed values are 0, 1, 2, 3, 4, 5, 6, and 7, but it is easy to check that for these
seeds the new seeds are, respectively, 2, 4, 6, 0, 2, 4, 6, 0, so that after the first value of seed,
subsequent seeds can only take on one of four values. Even worse, should seed ever equal 6,
then new seeds will continue to be 6 forever, because (2 × 6 + 2) mod 8 is again 6.
Therefore, the choice of the constants is critical to making a stream of numbers that
has the appearance of randomness. There is a lot of number theory involved here which we
cannot hope to cover. The book by Rubinstein (see References) gives an introduction. It is
reported there that the values
multiplier 27 1, increment 1, modulus 235
have been successful, but these are not the only choices. We can build our own function
similar to the RandomReal command in Mathematica to generate a list of uniform[0,1]
numbers using these values as follows.
26 Chapter 1 Discrete Probability
MyRandomArrayinitialseed_, n_ :
Moduleseed, rand, thearray, mult, inc, modul, i,
mult 27 1;
inc 1;
modul 235 ;
thearray ;
seed initialseed;
Doseed Modmult seed inc, modul;
rand N seed modul;
AppendTothearray, rand, i, 1, n;
thearray
The module begins with the list of local variables used in the subsequent lines, and sets the
values above for the multiplier, here called mult, the increment inc, and the modulus modul.
After initializing an empty list of random numbers and setting the initial value of seed
according to the input initialseed, the module enters a loop. In each of the n passes through
the loop, three things are done. The seed is updated by the linear congruence relation (1), the
new random number rand is computed by formula (2), and then rand is appended to the
array of random numbers. Here is a sample run. You should try running the command again
with the same initial seed to see that you get the same sequence of pseudo-random numbers,
then try a different seed.
Activity 2 Revise the random number generating command above using the following
constants, taken from a popular computer science text.
SeedRandom[n]
which sets the initial seed value as the integer n. If you use an empty argument to SeedRan-
dom, it resets the seed using the computer's clock time. In the sequence of commands below,
the seed is set to 79, two random numbers are generated, then the seed is reset to 79, and the
same random number .624058 is returned as was returned the first time. We then reset the
seed "randomly" using the computer clock, and the first random number that is returned is
something other than .624058.
SeedRandom79;
RandomReal
RandomReal
0.624058
0.782677
SeedRandom79;
RandomReal
0.624058
SeedRandom;
RandomReal
0.295358
Activity 3 Perform a similar test with SeedRandom using a seed of 591 and requesting
a RandomReal[UniformDistribution[{0,1}], 5]. Reset the seed by computer clock time
and call for another random list of five numbers to see that different random numbers are
returned.
Example 1 It is time to build a simulation model for an actual system. A random walk on
the line is a random process in which at each time instant 0, 1, 2, … an object occupies a
point with integer coordinates shown as circled numbers in Figure 5.
28 Chapter 1 Discrete Probability
1 p 1 p 1 p 1 p 1 p
0 p
1 p
2 p
3 p
4 p
5
Figure 1.5 - Schematic diagram of a random walk
The position on the line cannot be foretold with certainty, but it satisfies the condition that if
the position is n at one time instant, then it will either be n 1 with probability p or n 1
with probability 1 p at the next time instant, as indicated by the annotated arrows in the
figure. Variations are possible, including allowing the object to wait at its current position
with some probability, enforcing boundary behavior such as absorption or reflection to
confine the random walk to a bounded interval, and increasing the dimension of the set on
which the random walk moves to 2, 3, or higher. Random walks have been used as models
for diffusion of heat, the motion of economic quantities such as stock prices, the behavior of
populations, and the status of competitive games among many other applications, and their
fascinating properties have kept probabilists busy for many decades.
For our purposes suppose we are interested in estimating the probability that a
random walk which starts at a point n 0 reaches a point M n before it reaches 0. This is a
famous problem called the gambler's ruin problem, which really asks how likely it is that a
gambler's wealth that follows a random walk reaches a target level of M before bankruptcy.
We have an initial position n followed by a sequence of random positions X1 , X2 , X3 ,
… . The underlying randomness is such that at each time a simple random experiment
determines whether the move is to the right (probability p) or the left (probability 1 p). So
to simulate the random walk we only need to be able to iteratively simulate the simple
experiment of adding 1 to the current position with probability p and subtracting 1 with
probability 1 p. We will stop when position 0 or position M is reached, and make note of
which of the two was the final position. By running such a simulation many times and
observing the proportion of times that the final state was M, we can estimate the probability
that the final state is M.
To implement the plan in the preceding paragraph, we need a way of randomly
returning +1 with probability p and 1 with probability 1 p. But since we know how to
simulate uniform real random numbers on [0,1], and the probability of an interval is equal to
its length, let's say that if a simulated uniform random number is less than or equal to p then
the result is +1, otherwise 1. Then we have the desired properties of motion, because
Pmove right P 0, p length 0, p p
Pmove left P p, 1 length p, 1 1 p
Here is a Mathematica function that does the job. A uniform random number is
selected and compared to p. If the comparison is true, then +1 is returned, else 1 is
returned. So that we can simulate random walks with different p values, we make p an
argument. One function call with p = .5 is displayed; you should try a few others.
1.3 Simulation 29
StepSizep_ : IfRandomReal p, 1, 1
StepSize.5
1
To simulate the process once, we let the initial position n be given, as well as the
right step probability p and the boundary point M. We repeatedly move by the random
StepSize amount until the random walk reaches 0 or M. The function below returns the
complete list of states that the random walk occupied. Look carefully at the code to see how
it works. The variable statelist records the current list of positions occupied by the random
walk, the variable done becomes true when either the boundary 0 or M is reached, and
variables currstate and nextstate keep track of the current and next position of the random
walk. (The || syntax means logical "or.")
Below is an example run of the command. We include a list plot of the sequence of
positions to help your understanding of the motion of the random walk. You should rerun
this command, changing parameters as desired to get more intuition about the behavior of
the random walk. A more systematic investigation is suggested in Exercise 6. We set a
random seed first for reproducibility, but if you are in the electronic version of the book and
want to see different paths of the random walk, just delete the SeedRandom command.
SeedRandom464 758;
thewalk SimulateRandomWalk0.5, 4, 8
ListPlotthewalk,
PlotStyle PointSize0.015, Black
30 Chapter 1 Discrete Probability
4, 5, 4, 5, 6, 7, 6, 5, 4, 5, 6, 5, 6,
5, 4, 5, 6, 5, 6, 5, 4, 3, 4, 3, 2, 1, 2, 3,
4, 5, 6, 5, 4, 3, 4, 3, 4, 3, 2, 3, 2, 1, 0
7
6
5
4
3
2
1
10 20 30 40
Activity 4 Roughly how would you describe the dependence of the probability that the
random walk reaches M before 0 on the value of p? How does it depend on the value of
n? How could you use SimulateRandomWalk to check your intuition about these
questions?
Continuing the random walk example, to estimate the probability of hitting M before
0 we must repeat the simulation many times, with new streams of random numbers. We
merely take note of the last element of the simulated list of positions, which will be either 0
or M, count the number of times that it is M, and divide by the number of repetitions to
estimate the probability. Here is a command that does this. Any input values we like for p, n,
and M can be used. We also let the number of replications of the simulation be a fourth
argument.
The variable absatM, initialized to zero, keeps track of how many times so far the walk has
been absorbed at M. The algorithm is simple: we repeat exactly numreps times the actions of
simulating the list of positions (called poslist) of the random walk, then pick out the last
Discovering Diverse Content Through
Random Scribd Documents
history, and far, far more vital than any of the phenomena which
recorded history presents.
Recorded history for this island, and for Northern France and for the
Rhine Valley, is a matter of two thousand years; for the Western
Mediterranean of three; but the things of which I speak are to be
reckoned in tens of thousands of years. Their interest does not lie
only or even chiefly in things that disappeared. It is indeed a great
pleasure to rummage in the earth and find the polished stones of
the men who came so many centuries before us, but of whose blood
we certainly are; and it is a great pleasure to find or to guess that
we find under Canterbury the piles of a lake or marsh dwelling,
proving that Canterbury has been there from all time, and that the
apparently defenceless valley city was once chosen as an
impregnable site when the water-meadows of the Stour were
impassable as marsh, or with difficulty passable as a shallow lagoon.
And it is delightful to stand on the earthwork beyond Chilham and to
say to oneself (as one can say with a fair certitude), "Here was the
British camp defending the south-east; here the tenth legion
charged." All these are pleasant, but more pleasant I think to follow
the thing where it actually survives.
Consider the Track-ways, for instance. How rich England is in these!
No other part of Europe will afford the traveller so permanent and so
fascinating a problem. Elsewhere Rome hardened and straightened
every barbaric trail, but in this distant province of Britain she would
only spend just so much energy as made them a foothold for her
soldiery; and all over England you go if you choose foot by foot
along the ancient roads that were made by the men of your blood
before they had heard of brick, or of stone, or of iron, or of written
laws.
I wonder that more men do not set out to follow, let us say, the
Fosse-way. There it runs right across Western England from the
south-west to the north-east, in a line direct yet sinuous, characters
which are the very essence of a savage trail. It is a modern road for
many miles, let us say; and there you are tramping along the
Cotswold on a hard-metalled modern English highway, with
milestones and notices from the county council telling you that the
culverts will not bear a steam-engine, if so be you were travelling in
one. Then suddenly it comes up against a cross-road and apparently
ceases, making what map draughtsmen call a "T"; but right in the
same line you will see a gate, and beyond it a farm lane, and so you
follow. You come to a spinney where a ride is cut through by the
wood-reeve, and it is all in the same line. The Fosse-way turns into a
little path, but you are still on it; it curls over a marshy brook-valley,
keeping on firm land, and as you go you see old stones put there
Heaven knows how many generations ago—or perhaps yesterday,
for the tradition remains and the countryfolk strengthen their wet
lands as they have strengthened them all these thousands of years;
you climb up out of that depression, you get you over a stile, and
there you are again upon a lane. You follow that lane, and once
more it stops dead. This time there is a field before you. No right of
way, no trace of a path, nothing but grass rounded into those
parallel ridges which mark the decay of the corn lands and pasture
taking the place of agriculture. Now your pleasure comes in casting
about for the trail; you look back along the line of the way; you look
forward in the same line till you find some indication, a boundary
between two parishes, perhaps upon your map, or two or three
quarries set together, or some other sign; and very soon you have
picked up the line again.
So you go on mile after mile, and as you tread that line you feel in
the horizons that you see, in the very nature and feel of the soil
beneath your feet, in the skies of England above you, the ancient
purpose and soul of this kingdom. Up this same line went the Clans
marching when they were called Northward to the Host; and up this
went slow, creaking wagons with the lead of the Mendips or the tin
of Cornwall, or the gold of Wales.
And it is still there; it is still used from place to place as a high-road,
it still lives in modern England. There are some of its peers: as for
instance the Ermine Street, far more continuous, and affording
problems more rarely; others like the ridgeway of the Berkshire
Downs, which Rome hardly touched, and of which the last two
thousand years has therefore made hardly anything. You may spend
a delightful day piecing out exactly where it crossed the Thames,
making your guess at it, and wondering as you sit there by Streatley
Vicarage whether those islands did not form a natural weir below
which lay the ford.
The roads are the most obvious things. There are many more; for
instance, thatch. The same laying of the straw in the same manner,
with the same art, has continued, we may be certain, from a time
long before the beginning of history. See how in the Fen Land they
thatch with reeds, and how upon the Chalk Downs with straw from
the lowlands. I remember once being told of a record in a manor
which held of the church, and which lay upon the southern slope of
the Downs, that so much was entered "for straw from the lowlands";
then years afterwards, when I had to thatch a Bethlehem in an
orchard underneath tall elms—a pleasant place to write in with the
noise of bees in the air—the man who came to thatch said to me:
"We must have straw from the lowlands; this upland straw is no
good for thatching." Then immediately when I heard him say this
there was added to me ten thousand years. And I know another
place in England, far distant from this, where a man said to me that
if I wished to cross in a winter mist, as I had determined to do,
Cross Fell, that great summit of the Pennines, I must watch the drift
of the snow, for there was no other guide to one's direction in such
weather. And I remember another man in a boat in the North Sea,
as we came towards the Foreland, talking to me of the two tides,
and telling me how if one caught the tide all the way up to Long
Nose and then went round it, one made two tides in one day. He
spoke with the same pleasure that silly men show when they talk
about an accumulation of money. He felt wealthy and proud from
the knowledge, for by this knowledge he had two tides in one day.
Now knowledge of this sort is older than ten thousand years; and so
is the knowledge of how birds fly, and of how they call, and of how
the weather changes with the moon.
Very many things a man might add to the list that I am making.
Dew-pans are older than our language or religion; and the finding of
water with a stick; and the catching of that difficult animal, the
mole; and the building of flints into mortar, which if one does it the
old way (as you may see at Pevensey) lasts for ever, and if you do it
the new way does not last ten years; and then there is the
knowledge of planting during the crescent part of the month but not
before the new moon shows; and there is the influence of the moon
on cider, and to a less extent upon the brewing of ale; and talking of
ale, the knowledge of how ale should be drawn from the brewing
just when a man can see his face without mist upon the surface of
the hot brew; and there is the knowledge of how to bank rivers,
which is called "throwing the rives" in the South, but in the Fen Land
by some other name; and how to bank them so they do not silt, but
scour themselves. There are these things and a thousand others. All
are immemorial, but I have no space for any now.
ON MILTON
The letters of a people reflect its noblest as architecture reflects its
most intimate mind and as its religion (if it has a separate or tribal
religion) reflects its military capacity or incapacity. The word
"noblest" is vague, and nobility must here be defined to mean that
steadiness in the soul by which it is able to express a fixed character
and individuality of its own. Thus a man contradicts himself from
passion or from a variety of experience or from the very ambiguity
and limitation of words, but he himself resides in all he says, and
when this self is clearly and poisedly expressed it is then that we
find him noble.
The poet Milton, according to this conception, has best expressed
the nobility of the English mind, and in doing a work quite different
from any of his peers has marked a sort of standard from which the
ideal of English letters does not depart.
Two things are remarkable with regard to English literature, first that
it came late into the field of European culture, and secondly that it
has proved extraordinarily diversified. The first point is immaterial to
my subject; the second is material to it; for it might be superficially
imagined that such bewildering complexity and, as it were, lawless
exuberance of method and of matter would never find a pole, nor
ever be symbolised by but one aspect of it. Yet Milton has found that
pole, and Milton's work has afforded that symbol.
In any one moment of English literary history you may contrast two
wholly different masterpieces from the end of the Fourteenth to the
end of the Eighteenth Centuries. After the first third of the
Nineteenth, indeed, first-rate work falls into much more
commonplace groove, and it is perceptible that the best verse and
the best prose written in English are narrowing in their vocabulary,
and, in what is far more important, their way of looking at life. The
newspapers have levelled the writers down as with a trowel; you
have not side by side the coarse and the refined, the amazing and
the steadfast, the grotesque and the terrible; but in all those earlier
centuries you had side by side manner and thought so varied that a
remote posterity will wonder how such a wealth could have arisen
upon so small an area of national soil. Piers Plowman and the
Canterbury Tales are two worlds, and a third world separate from
each is the world of those lovely lyrics which are now so nearly
forgotten, but which the populace, spontaneously engendered and
sang throughout the close of the Middle Ages. The Sixteenth Century
was perhaps less modulated, and flowed, especially towards its end,
in one simpler stream, but in the Seventeenth what a growth of
variety from the Jacobean translation of the Bible to Swift. The very
decade in which Paradise Lost was published corresponded with the
first riot of the Restoration.
If we look closely into all this diversity we can find two common
qualities which mark out all English work in a particular manner from
the work of other nations. To qualities of this kind, which are like
colours rather than like measurable things, it is difficult to give a
title; I will hazard, however, these two words, "Adventure" and
"Mystery." There is no English work of any period, especially is there
no English work of any period later than the middle of the Sixteenth
Century, which has not got in it all those emotions which proceed
from the love of Adventure. How notable it is, for instance, that
Landscape appears and reappears in every diverse form of English
verse. Even in Shakespeare you have it now and then as vivid as a
little snapshot, and it runs unceasingly through every current of the
stream; it glows in Gray's Elegy, and it is the binding element of In
Memoriam. It saves the earlier work of Wordsworth, it permeates
the large effect of Byron, and those two poems, which to-day no one
reads, Thalaba and The Curse of Kehama, are alive with it. It is the
very inspiration of Keats and of Coleridge. Now this hunger for
Landscape and this vivid sense of it are but aspects of Adventure;
for the men who thus feel and speak are the men who, desiring to
travel to unknown places, are in a mood for sudden revelations of
sea and land. So a living poet has written—
or, again,
I confess I can never read that line but I remember a certain river of
twenty years ago, nor does revisiting that stream and seeing it again
with my eyes so powerfully recall what once it was to those who
loved it as does this deathless line. It seems as though the magical
power of the poet escaped the effect of time in a way that the
senses cannot, and a man curious in such matters might find the
existence of such gifts to be a proof of human immortality. The pace
at which Milton rides his verse, the strong constraint within which he
binds it, deeply accentuate this power of rhythm and the mystical
effect it bears. Now you would say a trumpet, now a chorus of
human voices, now a flute, now a single distant song. From the
fortieth to the fifty-fifth line of the third book Paradise Lost has all
the power and nature of a solemn chant; the large complaint in it is
the complaint of an organ, and one may say indeed in this
connection that only one thing is lacking in all the tones Milton
commanded; he disdained intensity of grief as most artists will
disdain intensity of terror. But whereas intensity of terror is no fit
subject for man's pen, and has appealed only to the dirtier of our
little modern fellows, intense grief has been from the very beginning
thought a just subject for verse.
Milton will have none of it. It is the absence of that note which has
made so many hesitate before the glorious achievement of Lycidas,
and in this passage which I quote, where Milton comes nearest to
the cry of sorrow, it is still no more than what I have called it, a
solemn chant.
.... Thus with the year
Seasons return; but not to me returns
Day, or the sweet approach of Ev'n or Morn,
Or sign of vernal bloom, or Summer's Rose,
Or flocks, or herds, or human face divine;
But cloud instead, and ever-during dark
Surrounds me, from the chearful waies of men
Cut off, and, for the Book of knowledge fair,
Presented with a Universal blanc
Of Nature's works, to mee expung'd and ras'd,
And wisdome at one entrance quite shut out.
So much the rather thou, Celestial light,
Shine inward, and the mind through all her powers
Irradiate; there plant eyes, all mist from thence
Purge and disperse, that I may see and tell
Of things invisible to mortal sight.
ebookgate.com