{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true,
"tags": [
"remove_cell"
]
},
"outputs": [],
"source": [
"# HIDDEN\n",
"from datascience import *\n",
"from prob140 import *\n",
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"plt.style.use('fivethirtyeight')\n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Examples ##"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's see if we can use the results we've developed to calculate some chances. Some of the steps will be clear without calculation; others will require more work. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Example 1: Both Heads and Tails in $n$ Tosses ###\n",
"A coin is tossed $n$ times so that all $2^n$ possible sequences of heads and tails are equally likely. \n",
"\n",
"**Question.** What is the chance of getting at least one head and at least one tail?\n",
"\n",
"**Answer.** There are many sequences in which each face appears at least once. For example, if $n=4$, such sequences include HTTT, HTHT, TTHT, and so on. \n",
"\n",
"**Method: Complement.** \n",
"When an event can happen in many different ways, it might be a good idea to look at the ways in which it *doesn't* happen, in case there are fewer of those.\n",
"\n",
"For $n=4$, the only sequences in which we *don't* get at least one occurrence of each face are HHHH and TTTT. Indeed, for any $n$, there are only two sequences in which we don't get both faces: all heads, and all tails. These are the two sequences in which all the elements are the same.\n",
"\n",
"Let $A$ be the event that we get at least one head and at least one tail. The question asks for $P(A)$. Because $A^c$ is the event \"all the elements of the sequence are the same\", we have\n",
"$$\n",
"P(A^c) = \\frac{2}{2^n} = \\frac{1}{2^{n-1}}\n",
"$$\n",
"By the complement rule,\n",
"$$\n",
"P(A) = 1 - \\frac{1}{2^{n-1}}\n",
"$$\n",
"Notice that the answer tends to 1 as $n$ gets large. With a large number of tosses, you are almost certain to see both heads and tails.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Example 2: Maximum of 12 Rolls of a Die ###\n",
"A die is rolled 12 times so that all $6^{12}$ sequences of faces are equally likely. Define the *maximum* of the 12 rolls to be the largest of the numbers that appear on the 12 faces. For example, the maximum of the sequence \"354222143351\" is 5.\n",
"\n",
"**Question 1.** What is the chance that the maximum is less than 5?\n",
"\n",
"**Answer 1.** The key is to observe that the event \"the maximum is less than 5\" is the same as the event \"all the 12 faces are less than 5\". For this to occur, each of the 12 faces has to have one of the four values 1 through 4. So\n",
"$$\n",
"P(\\text{maximum is less than 5}) = \\frac{4^{12}}{6^{12}}\n",
"$$\n",
"Yes, we could simplify that further, but we're not going to, for reasons that will soon become clear.\n",
"\n",
"**Question 2.** What is the chance that the maximum is less than 4?\n",
"\n",
"**Answer 2.** Nothing new here, other than replacing 5 by 4 in Question 1. \n",
"$$\n",
"P(\\text{maximum is less than 4}) = \\frac{3^{12}}{6^{12}}\n",
"$$\n",
"\n",
"**Question 3.** What is the chance that the maximum is equal to 4?\n",
"\n",
"**Answer 3.** The task of writing down all the sequences in which the maximum is equal to 4 isn't pleasant. Let's see if we can use what we already know. For the maximum to be equal to 4:\n",
"\n",
"- The maximum has to be less than 5,\n",
"- and it can't be less than 4.\n",
"\n",
"We're thinking of the set $\\{4\\}$ as a difference: $\\{1, 2, 3, 4\\} \\backslash \\{1, 2, 3\\}$.\n",
"\n",
"So by the difference rule,\n",
"\n",
"$$\n",
"\\begin{align*}\n",
"P(\\text{maximum is equal to 4}) &= P(\\text{maximum is less than 5}) - P(\\text{maximum is less than 4}) \\\\\n",
"&= \\frac{4^{12}}{6^{12}} - \\frac{3^{12}}{6^{12}}\n",
"\\end{align*}\n",
"$$\n",
"\n",
"There is nothing special about 12 rolls. You can replace 12 by $n$ throughout, and the argument will go through just as above.\n",
"\n",
"The maximum is an example of an *extremum*, the other being the minimum. \n",
"\n",
"**Problem solving technique:** When you work with extrema, remember the observation we used in this example: saying that the maximum is small is the same as saying that all the elements are small. Analogously, saying the minimum is large is the same as saying that all the elements are large."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Example 3: Second Random Digit Greater than the First ###\n",
"A random number generator produces two digits so that all the 100 pairs of digits are equally likely.\n",
"\n",
"**Question.** What is the chance that the second digit is greater than the first?\n",
"\n",
"**Answer, Method I: Partition.** Make an organized list of all the ways in which the event can happen. A good way to list the pairs in which the second digit is greater than the first is to *partition* the pairs according to the value of the first digit:\n",
"\n",
"- first digit 0, second 1 through 9\n",
"- first digit 1, second 2 through 9\n",
"- first digit 2, second 3 through 9\n",
"- and so on, down to\n",
"- first digit 8, second digit 9\n",
"\n",
"This partition makes it easy to count all the pairs in which the second digit is greater than the first: there are $9+8+7+6+5+4+3+2+1 = (9\\times10)/2 = 45$ of them among the 100 possible pairs. So the answer is 0.45.\n",
"\n",
"**Answer, Method II: Symmetry.** Convince yourself of some symmetry: the chance that the second digit is greater than the first is the same as the chance that the first digit is greater than the second. One way to do this is to partition the second event according to the value of the second digit and notice the correspondence with the partition in Method I.\n",
"\n",
"So if $p = P(\\text{second digit is greater than the first})$, the addition rule says\n",
"\n",
"$$\n",
"\\begin{align*}\n",
"1 &= P(\\text{first digit greater than second}) + P(\\text{the two are equal}) + P(\\text{second digit greater than first}) \\\\ \\\\\n",
"&= p + \\frac{10}{100} + p\n",
"\\end{align*}\n",
"$$\n",
"\n",
"because there are 10 pairs of equal digits: 00, 11, 22, $\\ldots$, 99. Now solve for $p$:\n",
"\n",
"$$\n",
"p = \\frac{1 - 0.1}{2} = 0.45\n",
"$$\n",
"as before.\n",
"\n",
"It is a good idea to learn both methods. Partitions and symmetry will be used throughout this course."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 1
}