aez-notes
Craps
The game of craps, played with two dice, is one of America's fastest and most popular gambling games. Calculating the odds associated with it is an instructive exercise.
The rules are these. Only totals of for the two dice count. The player throws the dice and wins at once if the total for the first throw is 7 or 11, loses at once if it is 2, 3, or 12. Any other throw is called his "point." If the first throw is a point, the player throws the dice repeatedly until he either wins by throwing his point again or loses by throwing 7. What is the player's chance to win?
We start by defining a PDF for a single die.
pdf_dice(x) := pdf_discrete_uniform(x, 6);
Then we convolve this with itself to get the sum of two dice.
pdf_roll(x) := sum(pdf_dice(x - i) * pdf_dice(i), i, 1, 6);
Given pdf_roll
we can compute the probability of winning on the first roll
easily, the difficulty is getting the probability of winning if the first roll
is a point. Here we can break the event down into two independent events: roll a
point initially, and win given that point.
point_vals : [4,5,6,8,9,10]; prob_point_game : apply("+", map(pdf_roll, point_vals)); pdf_point_given_point(x) := pdf_roll(x) / prob_point_game; pdf_win_given_point(x) := pdf_roll(x) / (pdf_roll(x) + pdf_roll(7)); prob_point_game_win : prob_point_game * apply("+", map(lambda([x], pdf_point_given_point(x) * pdf_win_given_point(x)), point_vals) );
Putting this all together and remembering to load distrib
we get the following
program.
load(distrib)$ <<dicePdf>> <<rollPdf>> prob_first_roll_win : pdf_roll(7) + pdf_roll(11); /* about 0.222 */ <<pointWinProb>> /* about 0.271 */ prob_first_roll_win + prob_point_game_win, numer; /* about 0.493 */
This gives the chance of winning at \(0.493\).