Chapter 14. Probability

The theory of probabilities is at bottom nothing butcommonsensereducedtocalculus.

Pierre Simon de Laplace (1749-1827)

Probability theory is used to predict events. The roll of a die, tomorrow’s weather, the chance that the defendant visited the crime scene: all have to do with the likelihoods of particular occurrences.

For our exploration of probability, we’ll begin with a discussion of random numbers, a topic that perplexes many novice Perl programmers who wonder why their random numbers don’t seem very random at all. We use random numbers to simulate and simplify real world situations. You could compute whether a flipped coin will land heads or tails by determining the amount of force applied to the coin, the angular rotation component of that force, the velocity induced by the motion of the arm at the time of release, the location at the time of release, and the elasticity of the floor. Or you can argue that a coin is as likely to come up heads as tails and call each an event with a probability of 0.5.

After we formally introduce events and how to manipulate their probabilities with Perl, we’ll use them for combinatorics: the calculation of permutations and combinations.

The remainder of the chapter is about a plethora of functions called probability distributions. Each distribution models a particular class of phenomena. You’ve probably seen the bell curve (called a normal distribution) that approximates many measurements such as birth weight or ...

Get Mastering Algorithms with Perl now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.