├── 1 Counting.pdf ├── 2 Probability.pdf ├── 3 Conditional.pdf ├── README.md ├── assignment_1 ├── Problem_Set_1.pdf ├── problem_set_1_sol.pdf └── problem_set_1_sol.tex └── assignment_2 ├── Problem_Set_2.pdf ├── problem_set_2_sol.aux ├── problem_set_2_sol.log ├── problem_set_2_sol.pdf └── problem_set_2_sol.tex /1 Counting.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndreeaMusat/Stanford-CS109-Probability-for-computer-scientists/1cc1837fa641c63bee8a055bfe3b7eb4fa479439/1 Counting.pdf -------------------------------------------------------------------------------- /2 Probability.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndreeaMusat/Stanford-CS109-Probability-for-computer-scientists/1cc1837fa641c63bee8a055bfe3b7eb4fa479439/2 Probability.pdf -------------------------------------------------------------------------------- /3 Conditional.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndreeaMusat/Stanford-CS109-Probability-for-computer-scientists/1cc1837fa641c63bee8a055bfe3b7eb4fa479439/3 Conditional.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Stanford-CS109-Probability-for-computer-scientists 2 | -------------------------------------------------------------------------------- /assignment_1/Problem_Set_1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndreeaMusat/Stanford-CS109-Probability-for-computer-scientists/1cc1837fa641c63bee8a055bfe3b7eb4fa479439/assignment_1/Problem_Set_1.pdf -------------------------------------------------------------------------------- /assignment_1/problem_set_1_sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndreeaMusat/Stanford-CS109-Probability-for-computer-scientists/1cc1837fa641c63bee8a055bfe3b7eb4fa479439/assignment_1/problem_set_1_sol.pdf -------------------------------------------------------------------------------- /assignment_1/problem_set_1_sol.tex: -------------------------------------------------------------------------------- 1 | \documentclass[10pt,a4paper,oneside,draft]{report} 2 | \usepackage[utf8]{inputenc} 3 | 4 | \title{CS109 assignment 1} 5 | \author{andreea.a.musat@gmail.com} 6 | \date{Januray 2019} 7 | 8 | \usepackage{natbib} 9 | \usepackage{graphicx} 10 | \usepackage{xcolor} 11 | 12 | \newcommand\myworries[1]{\textcolor{red}{#1}} 13 | 14 | \begin{document} 15 | 16 | \maketitle 17 | 18 | \textbf{1.} A substitution cypher is derived from an ordering of the letters in the alphabet. How many ways can the 26 letters be ordered if each letter appears exactly once and:\\ 19 | a. There are no other restrictions? \\ 20 | b. The letters Q and U must be next to each other (but in any order)? \\ 21 | 22 | \textbf{Solution:} \\ 23 | 24 | a. There are 26! ways to permute the 26 letters of the alphabet. \\ 25 | 26 | b. We can assume that U does not exist in the alphabet, as its position always depends on Q in order to get a valid arrangement. Thus, we have 25! ways in which we can arrange all letters except U. Now, we can place U either before or after Q in any of these, so we get a total of $2 * 25!$ ways.\\ 27 | 28 | \textbf{2.} You are counting cards in a card game that uses four standard decks of cards. There are 208 cards total. Each deck has 52 cards (13 values each with 4 suits). Cards are only distinguishable based on their suit and value, not which deck they came from. \\ 29 | a. In how many distinct ways can the cards be ordered? \\ 30 | b. You are dealt two cards. How many distinct pairs of cards can you be dealt? Note: the order of the two cards you are dealt does not matter. \\ 31 | c. You are dealt two cards. Cards with values 10, Jack, Queen, King and Ace are considered “good” cards. How many ways can you get two “good” cards? Order does not matter. \\ 32 | 33 | \textbf{Solution:} \\ 34 | 35 | a. We are trying to order 208 elements, knowing that there are 13 * 4 = 52 unique elements and that each elements appears 4 times, as there ar 4 decks. Thus, there are: $\frac{208!}{4! 4! ... 4!} = \frac{208!}{(4!)^{52}}$ ways of ordering them. \\ 36 | 37 | b. Because we have more than one deck, it is possible to have a pair consisting of the same card. There are $52^2$ possible pairs of cards, but we count the pairs with 2 different elements twice ((1, 2) and (2, 1) for example). If we want to count all pairs twice, we have to add 52 to that number (the number of pairs having the same card), so we get: $\frac{52^2 + 52}{2} = 26 * 53$ total pairs. \\ 38 | 39 | c. There are 5 card values * 4 suits * 4 decks = 80 good cards, so one could get a pair of 2 good cards in ${80 \choose 2}$ ways. 40 | 41 | \textbf{3. }In how many ways can n identical server requests (“identical balls”) be distributed among r servers (“urns”) so that the $i$th server receives at least $m_i$ requests, for each i = 1, 2, ..., r ? 42 | You can assume that $n \geq \sum_{i=1}^{r}m_i$. \\ 43 | 44 | \textbf{Solution}\\ 45 | 46 | We first distribute the minimum number of requests for each server, so that the constraint is satisfied: server i gets $m_i$ requests. Using the notation $m = \sum_{i=1}^{r}m_i$, we are left with $n - m$ requests to distribute on r servers, which can be done in 47 | $n - m + r - 1 \choose r - 1$ ways, as the requests are assumed to be identical. \\ 48 | 49 | \textbf{4.} Determine the number of vectors $(x_1 , x_2 , ..., x_n)$ such that each $x_i$ is a non-negative integer and $\sum_{i=1}^{n}x_i \leq k$ where k is some constant non-negative integer. Note that you can think of n (the size of the vector) as a constant that can be used in your answer. \\ 50 | 51 | \textbf{Solution} \\ 52 | 53 | We can split this problem into k + 1 more specific problems and solve each of them separately: \textit{Given a constant j, determine the number of vectors n-dimensional vectors such that each component is a non-negative integer and the sum of all the components is exactly j.} This problem is equivalent to distributing j balls across n urns (and allowing some of the urns to be empty), which can be done in $j + n - 1 \choose n - 1$ ways for each j. Now, because we are interested in vectors having the sum of their elements less than or equal to k, we get the total number of vectors: $\sum_{i=0}^{k} {j + n - 1 \choose n - 1}$ \\ 54 | 55 | \textbf{5.} Imagine you have a robot (Q) that lives on an n x m grid (it has n rows and m columns). The robot starts in cell (1, 1) (lower left corner) and can take steps either to the right or up (no left or down steps). How many distinct paths can the robot take to the destination in cell (n, m) (upper right corner): \\ 56 | a. If there are no additional constraints? \\ 57 | b. The robot must start by moving to the right? \\ 58 | c. If the robot changes direction exactly 3 times? As an example: moving up two times in a row is not changing directions but switching from moving up to moving right is. Moving [Up, Right, Right, Up] would count as having two direction switches. \\ 59 | 60 | \newpage 61 | \textbf{Solution} \\ 62 | 63 | a. Each path the robot can take can be encoded as a binary string of length n + m consisting of n 0s and m 1s, where 0 means the robot takes a step up and 1 means that the robot takes a step to the right. 64 | There are ${n + m \choose n} = {n + m \choose m}$ ways of choosing one such path. \\ 65 | 66 | b. If the robot starts by moving to the right, then we restrict our binary strings to start with 1. Now we have to count the ways in which we can construct a binary string of length n + m - 1 that consists of n 0s and m-1 1s. There are $ {n + m - 1 \choose n} = {n + m - 1 \choose m - 1} $ such strings. \\ 67 | 68 | c. If the robot changes direction 3 times, its possible paths would have the following form: 00...0 $\vert$ 11...1 $\vert$ 00...0 $\vert$ 11...1 (or starting with a block of ones instead of zeros; we can count these and then multiply the result by 2 to account for the ones starting with 1s), where the first block of zeros should have length between 1 and n - 1 inclusive and the first block of ones should have length between 1 and m - 1 inclusive (and the length of the other 2 blocks is dependent on these, so they can be chosen just in one way). There are 2 * (n - 1) * (m - 1) ways to build a path in which the robot changes direction 3 times. \\ 69 | 70 | \textbf{6.} Given all the start-up activity going on in high-tech, you realize that applying combinatorics to investment strategies might be an interesting idea to pursue. Say you have \textdollar 20 million 71 | that must be invested among 4 possible companies. Each investment must be in integral 72 | units of \textdollar 1 million, and there are minimal investments that need to be made if one is to 73 | invest in these companies. The minimal investments are \textdollar1, \textdollar 2, \textdollar 3, and \textdollar 4 million dollars, 74 | respectively for company 1, 2, 3, and 4. How many different investment strategies are available if: \\ 75 | a. an investment must be made in each company? \\ 76 | b. investments must be made in at least 3 of the 4 companies? \\ 77 | 78 | \textbf{Solution} \\ 79 | 80 | a. We first invest the minimum required amount in each company (it can be done in 1 way, as all million dollars are equal :-) ), then distribute the rest of the money (\textdollar 10 million) between the 4 companies, which can be done in ${10 + 4 - 1 \choose 4 - 1} = {13 \choose 3 } = 286 $ ways. \\ 81 | 82 | b. We will count the ways in which we can invest in exactly 3 companies and then add the result from the previous exercise to this number. Knowing that the minimum sum invested in company i is \textdollar i million dollars, investing in all companies except i requires a minimum investment of 10 - i million dollars (this is to satisfy the constraint; can be done in 1 way), which leaves us \textdollar 10 + i million to invest in 3 companies. This can be done in ${10 + i + 3 - 1 \choose 3 - 1} = {12 + i \choose 2}$ ways. Now, knowing that i can be any of these 4 companies, we get a total number of investing in exactly 3 companies: $\sum_{i = 1}^{4} {12 + i \choose 2}$, so the final result is: 286 + $\sum_{i = 1}^{4} {12 + i \choose 2}$. \\ 83 | 84 | \myworries{TODO: exercises 7-8} \\ 85 | 86 | \textbf{9.} To get good performance when working binary search trees (BST), we must consider the probability of producing completely degenerate BSTs (where each node in the BST has at most one child). \\ 87 | a. If the integers 1 through n are inserted in arbitrary order into a BST (where each possible order is equally likely), what is the probability (as an expression in terms of n) that the resulting BST will have completely degenerate structure? \\ 88 | b. Using your expression from part (a), determine the smallest value of n for which the probability of forming a completely degenerate BST is less than 0.01 (i.e., 1\%).\\ 89 | 90 | \textbf{Solution} \\ 91 | 92 | a. If $(x_1, x_2, \dots x_n)$ is a permutation of the numbers 1 through n, we denote by $D(x_1, x_2, \dots x_n)$ the event that the BST generated by $x_1, x_2, \dots x_n$ in this order is a degenerate BST. We know that a tree is degenerate when each node has at most one child. We know that if an element x is inserted into a BST, all the elements smaller that x will be found on the left subtree of node x, while all the elements greater than x will be found on the right subtree of the BST. Thus, a node will have at most one child only when we know that after inserting it, we are left with numbers that are either smaller or larger than it, but not a mix of them. We can write $P(D(x_1, x_2, \dots x_n))$ as: $ P(D(x_1, x_2, \dots x_n)) = 93 | P((x_1=\max(x_1, x_2, \dots x_n) \lor x_1=\min(x_1, x_2, \dots x_n)) \land D(x_2, x_3, \dots x_n))$. \\ 94 | Because those are independent events, we rewrite it as: 95 | $P(D(x_1, x_2, \dots x_n)) = \\ 96 | (P(x_1=\max(x_1, x_2, \dots x_n)) + P(x_1=\min(x_1, x_2, \dots x_n))) P( D(x_2, x_3, \dots x_n))$. Because the numbers $x_i$, i $\in {1, 2, \dots n}$ are all different, \\ 97 | $P(x_1=\max(x_1, x_2, \dots x_n)) = \frac{1}{n}$ and $P(x_1=\min(x_1, x_2, \dots x_n)) = \frac{1}{n} $, we get that: $P(D(x_1, x_2, \dots x_n)) = \frac{2}{n} P( D(x_2, x_3, \dots x_n))$. \\ 98 | Writing $P( D(x_2, x_3, \dots x_n))$ in terms of $P( D(x_3, x_3, \dots x_n))$ and so on, we obtain: 99 | $P(D(x_1, x_2, \dots x_n)) = \frac{2}{n} \frac{2}{n-1} \frac{2}{n-2} \dots \frac{2}{3} \frac{2}{2} = \frac{2 ^ {n - 1}}{n!}$ \\ 100 | 101 | b. We want to find the smallest value of n such that: 102 | $\frac{2 ^ {n - 1}}{n!} < 0.01$ The left-hand side of the inequality is decreasing. We use an inequality to find an upper bound for our minimum n: 103 | $\frac{2 ^ {n - 1}}{n!} = \frac{2}{3} \frac{2}{4} \dots \frac{2}{n} <= \frac{2}{3} ^ {n-2} < 0.01 $, which is equivalent to $n > 13$. We can now binary search for n and obtain n = 8. \\ 104 | 105 | \textbf{10.} Say a hacker has a list of n distinct password candidates, only one of which will successfully log her into a secure system. \\ 106 | a. If she tries passwords from the list at random, deleting those passwords that do not work, what is the probability that her first successful login will be (exactly) on her k-th try? \\ 107 | b. Now say the hacker tries passwords from the list at random, but does not delete previously tried passwords from the list. She stops after her first successful login attempt. What is the probability that her first successful login will be (exactly) on her k-th try? \\ 108 | 109 | \textbf{Solution} \\ 110 | 111 | a. If the hacker tries the password at random and deletes them after trying them, each try of all the n passwords generates one of the n! possible permutations. There are (n-1)! ways in which she can guess the correct password on the k-th try (that is, all the permutations that have the correct password on the k-th position), so the probability is $\frac{(n-1)!}{n!} = \frac{1}{n}$ \\ 112 | 113 | b. The probability that the first successful login will be exactly on the k-th try is equal to the probability that she tries a wrong password on each of the first k-1 tries multiplied by the probability that she tries the correct one on the k-th try, which is: $(\frac{n-1}{n})^{k-1} \frac{1}{n}$. \\ 114 | 115 | \textbf{11.} Say a university is offering 3 programming classes: one in Java, one in C++, and one in 116 | Python. The classes are open to any of the 100 students at the university. There are:\\ 117 | • a total of 27 students in the Java class\\ 118 | • a total of 26 students in the C++ class\\ 119 | • a total of 18 students in the Python class\\ 120 | • 12 students in both the Java and C++ classes\\ 121 | • 5 students in both the Java and Python classes\\ 122 | • 7 students in both the C++ and Python classes\\ 123 | • 3 students in all three classes (note: these students are also counted as being in each pair of classes in the numbers above).\\ 124 | a. If a student is chosen randomly at the university, what is the probability that he or she is not in any of the 3 programming classes? \\ 125 | b. If a student is chosen randomly at the university, what is the probability that he or she is taking exactly one of the three programming classes? \\ 126 | c. If two students are chosen randomly at the university, what is the probability that at least one of the chosen students is taking at least one programming class? \\ 127 | 128 | \textbf{Solution} \\ 129 | 130 | a. Using the notation |C| = number of students in the C++ class, |J| = number of students in the Java class and |P| = number of students in the Python class, the total number of students enrolled in programming classes is: $|C| + |J| + |P| - |C \cap J| - |C \cap P| - |P \cap J| + |P \cap J \cap C| = 50$, so the probability that a random student is not in any of the 3 programming classes in 0.5. \\ 131 | 132 | b. We denote by $P(\#Cl=1)$ the probability that the number of programming classes taken by a student is exactly one. 133 | $P(\#Cl=1) = P(Cl=C \lor Cl=P \lor Cl=J) = P(Cl=C) + P(Cl=P) + P(Cl=J)$ \\ 134 | The probability that a student is only taking the Java class is $P(Cl=J) = \frac{|J| - |J \cap P| - |J \cap C| + |J \cap C \cap P|}{100} = 0.13$ 135 | Similarily, we compute $P(Cl=P)=0.09$ and $P(Cl=C)=0.1$, so the probability that a student is taking exactly one programming class is 0.32.\\ 136 | 137 | c. The event of choosing a pair of students so that at least one of them is taking at least one programming class is complementary to the event of choosing a pair of students in which none of them takes any programming class. There are 50 students not taking any programming class, so $50 \choose 2$ such pairs out of $100 \choose 2$ total pairs, so the probability is $1 - \frac{ {50\choose 2} }{ {100 \choose 2} } = 0.7525.$ \\ 138 | 139 | \textbf{12.} A binary string containing M 0's and N 1's (in arbitrary order, where all orderings are equally likely) is sent over a network. What is the probability that the first r bits of the received message contain exactly k 1's? \\ 140 | 141 | \textbf{Solution} \\ 142 | 143 | There are $(M+N) \choose N$ possible strings containing M 0's and N 1's. We assume that $r \geq k$, otherwise the probability is 0. There are $r \choose k$ ways to form the first r bits of the string so that it contains k 1's and there are ${M+N-r} \choose {N-k}$ ways to form the rest of (M+N-r) bits so that they contain N-k 1's. Thus, the probability is: \\ 144 | $\frac{ {r \choose k} {{M+N-r} \choose {N-k}} }{ {{M+N} \choose N} }$ \\ 145 | 146 | 147 | \textbf{13.} Suppose that m strings are hashed (randomly) into N buckets, assuming that all $N^m$ arrangements are equally likely. Find the probability that exactly k strings are hashed to the first bucket. \\ 148 | 149 | \textbf{Solution} \\ 150 | There are $m \choose k$ ways to choose the k strings that will be hashed into the first bucket. After that, we are left with m - k strings to be hashed in N - 1 buckets, which can be done in $(N-1)^(m-k)$ ways, so the probability of having exactly k strings hashed to the first bucket is: $\frac{{m \choose k} {(N-1)^{m-k}} }{N^m}$ \\ 151 | 152 | \textbf{14.} A computer generates two random integers in the range 1 to 12, inclusive, where each value in the range 1 to 12 is equally likely to be generated. What is the probability that the second randomly generated integer has a value that is greater than the first? \\ 153 | 154 | \textbf{Solution} \\ 155 | 156 | First, as each number is equally likely to be generated, $p(n) = \frac{1}{12}, \forall n \in \{1, 2, ..., 12\} $. We use the notation $p(I_2 > I_1)$ for the probability that the second generated integer is greater than the first one. We can write this as: \\ 157 | \begin{center} 158 | $p(I_2 > I_1) = \sum_{i_1, i_2 \in \{1, 2, ..., 12\}, i_2 > i_1} p(i_1) p(i_2 \vert i_1) = \frac{1}{12} \sum_{i_1, i_2 \in \{1, 2, ..., 12\}, i_2 > i_1} p(i_2 \vert i_1)$, 159 | \end{center} because the probability of each integer $i_1$ being generated is $\frac{1}{12}$. 160 | Now, the probability to generate a second integer greater than the first one $i_1$ is $\frac{12 - i_1}{12}$, so the final result is:\\ 161 | \begin{center} 162 | $p(I_2 > I_1) = \frac{1}{12} \sum_{i_1, \in \{1, 2, ..., 12\}} \frac{12 - i_1}{12} = \frac{1}{12^2} \sum_{i=1}^{i=11} i = 163 | \frac{11 * 12}{2 * 12^2} = \frac{11}{24}$ 164 | \end{center} 165 | 166 | \end{document} 167 | 168 | -------------------------------------------------------------------------------- /assignment_2/Problem_Set_2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndreeaMusat/Stanford-CS109-Probability-for-computer-scientists/1cc1837fa641c63bee8a055bfe3b7eb4fa479439/assignment_2/Problem_Set_2.pdf -------------------------------------------------------------------------------- /assignment_2/problem_set_2_sol.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | -------------------------------------------------------------------------------- /assignment_2/problem_set_2_sol.log: -------------------------------------------------------------------------------- 1 | This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015/Debian) (preloaded format=pdflatex 2018.11.2) 2 FEB 2019 15:29 2 | entering extended mode 3 | restricted \write18 enabled. 4 | %&-line parsing enabled. 5 | **problem_set_2_sol.tex 6 | (./problem_set_2_sol.tex 7 | LaTeX2e <2016/02/01> 8 | Babel <3.9q> and hyphenation patterns for 5 language(s) loaded. 9 | (/usr/share/texlive/texmf-dist/tex/latex/base/report.cls 10 | Document Class: report 2014/09/29 v1.4h Standard LaTeX document class 11 | (/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo 12 | File: size10.clo 2014/09/29 v1.4h Standard LaTeX file (size option) 13 | ) 14 | \c@part=\count79 15 | \c@chapter=\count80 16 | \c@section=\count81 17 | \c@subsection=\count82 18 | \c@subsubsection=\count83 19 | \c@paragraph=\count84 20 | \c@subparagraph=\count85 21 | \c@figure=\count86 22 | \c@table=\count87 23 | \abovecaptionskip=\skip41 24 | \belowcaptionskip=\skip42 25 | \bibindent=\dimen102 26 | ) 27 | (/usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty 28 | Package: inputenc 2015/03/17 v1.2c Input encoding file 29 | \inpenc@prehook=\toks14 30 | \inpenc@posthook=\toks15 31 | 32 | (/usr/share/texlive/texmf-dist/tex/latex/base/utf8.def 33 | File: utf8.def 2015/12/03 v1.1r UTF-8 support for inputenc 34 | Now handling font encoding OML ... 35 | ... no UTF-8 mapping file for font encoding OML 36 | Now handling font encoding T1 ... 37 | ... processing UTF-8 mapping file for font encoding T1 38 | 39 | (/usr/share/texlive/texmf-dist/tex/latex/base/t1enc.dfu 40 | File: t1enc.dfu 2015/12/03 v1.1r UTF-8 support for inputenc 41 | defining Unicode char U+00A0 (decimal 160) 42 | defining Unicode char U+00A1 (decimal 161) 43 | defining Unicode char U+00A3 (decimal 163) 44 | defining Unicode char U+00AB (decimal 171) 45 | defining Unicode char U+00AD (decimal 173) 46 | defining Unicode char U+00BB (decimal 187) 47 | defining Unicode char U+00BF (decimal 191) 48 | defining Unicode char U+00C0 (decimal 192) 49 | defining Unicode char U+00C1 (decimal 193) 50 | defining Unicode char U+00C2 (decimal 194) 51 | defining Unicode char U+00C3 (decimal 195) 52 | defining Unicode char U+00C4 (decimal 196) 53 | defining Unicode char U+00C5 (decimal 197) 54 | defining Unicode char U+00C6 (decimal 198) 55 | defining Unicode char U+00C7 (decimal 199) 56 | defining Unicode char U+00C8 (decimal 200) 57 | defining Unicode char U+00C9 (decimal 201) 58 | defining Unicode char U+00CA (decimal 202) 59 | defining Unicode char U+00CB (decimal 203) 60 | defining Unicode char U+00CC (decimal 204) 61 | defining Unicode char U+00CD (decimal 205) 62 | defining Unicode char U+00CE (decimal 206) 63 | defining Unicode char U+00CF (decimal 207) 64 | defining Unicode char U+00D0 (decimal 208) 65 | defining Unicode char U+00D1 (decimal 209) 66 | defining Unicode char U+00D2 (decimal 210) 67 | defining Unicode char U+00D3 (decimal 211) 68 | defining Unicode char U+00D4 (decimal 212) 69 | defining Unicode char U+00D5 (decimal 213) 70 | defining Unicode char U+00D6 (decimal 214) 71 | defining Unicode char U+00D8 (decimal 216) 72 | defining Unicode char U+00D9 (decimal 217) 73 | defining Unicode char U+00DA (decimal 218) 74 | defining Unicode char U+00DB (decimal 219) 75 | defining Unicode char U+00DC (decimal 220) 76 | defining Unicode char U+00DD (decimal 221) 77 | defining Unicode char U+00DE (decimal 222) 78 | defining Unicode char U+00DF (decimal 223) 79 | defining Unicode char U+00E0 (decimal 224) 80 | defining Unicode char U+00E1 (decimal 225) 81 | defining Unicode char U+00E2 (decimal 226) 82 | defining Unicode char U+00E3 (decimal 227) 83 | defining Unicode char U+00E4 (decimal 228) 84 | defining Unicode char U+00E5 (decimal 229) 85 | defining Unicode char U+00E6 (decimal 230) 86 | defining Unicode char U+00E7 (decimal 231) 87 | defining Unicode char U+00E8 (decimal 232) 88 | defining Unicode char U+00E9 (decimal 233) 89 | defining Unicode char U+00EA (decimal 234) 90 | defining Unicode char U+00EB (decimal 235) 91 | defining Unicode char U+00EC (decimal 236) 92 | defining Unicode char U+00ED (decimal 237) 93 | defining Unicode char U+00EE (decimal 238) 94 | defining Unicode char U+00EF (decimal 239) 95 | defining Unicode char U+00F0 (decimal 240) 96 | defining Unicode char U+00F1 (decimal 241) 97 | defining Unicode char U+00F2 (decimal 242) 98 | defining Unicode char U+00F3 (decimal 243) 99 | defining Unicode char U+00F4 (decimal 244) 100 | defining Unicode char U+00F5 (decimal 245) 101 | defining Unicode char U+00F6 (decimal 246) 102 | defining Unicode char U+00F8 (decimal 248) 103 | defining Unicode char U+00F9 (decimal 249) 104 | defining Unicode char U+00FA (decimal 250) 105 | defining Unicode char U+00FB (decimal 251) 106 | defining Unicode char U+00FC (decimal 252) 107 | defining Unicode char U+00FD (decimal 253) 108 | defining Unicode char U+00FE (decimal 254) 109 | defining Unicode char U+00FF (decimal 255) 110 | defining Unicode char U+0100 (decimal 256) 111 | defining Unicode char U+0101 (decimal 257) 112 | defining Unicode char U+0102 (decimal 258) 113 | defining Unicode char U+0103 (decimal 259) 114 | defining Unicode char U+0104 (decimal 260) 115 | defining Unicode char U+0105 (decimal 261) 116 | defining Unicode char U+0106 (decimal 262) 117 | defining Unicode char U+0107 (decimal 263) 118 | defining Unicode char U+0108 (decimal 264) 119 | defining Unicode char U+0109 (decimal 265) 120 | defining Unicode char U+010A (decimal 266) 121 | defining Unicode char U+010B (decimal 267) 122 | defining Unicode char U+010C (decimal 268) 123 | defining Unicode char U+010D (decimal 269) 124 | defining Unicode char U+010E (decimal 270) 125 | defining Unicode char U+010F (decimal 271) 126 | defining Unicode char U+0110 (decimal 272) 127 | defining Unicode char U+0111 (decimal 273) 128 | defining Unicode char U+0112 (decimal 274) 129 | defining Unicode char U+0113 (decimal 275) 130 | defining Unicode char U+0114 (decimal 276) 131 | defining Unicode char U+0115 (decimal 277) 132 | defining Unicode char U+0116 (decimal 278) 133 | defining Unicode char U+0117 (decimal 279) 134 | defining Unicode char U+0118 (decimal 280) 135 | defining Unicode char U+0119 (decimal 281) 136 | defining Unicode char U+011A (decimal 282) 137 | defining Unicode char U+011B (decimal 283) 138 | defining Unicode char U+011C (decimal 284) 139 | defining Unicode char U+011D (decimal 285) 140 | defining Unicode char U+011E (decimal 286) 141 | defining Unicode char U+011F (decimal 287) 142 | defining Unicode char U+0120 (decimal 288) 143 | defining Unicode char U+0121 (decimal 289) 144 | defining Unicode char U+0122 (decimal 290) 145 | defining Unicode char U+0123 (decimal 291) 146 | defining Unicode char U+0124 (decimal 292) 147 | defining Unicode char U+0125 (decimal 293) 148 | defining Unicode char U+0128 (decimal 296) 149 | defining Unicode char U+0129 (decimal 297) 150 | defining Unicode char U+012A (decimal 298) 151 | defining Unicode char U+012B (decimal 299) 152 | defining Unicode char U+012C (decimal 300) 153 | defining Unicode char U+012D (decimal 301) 154 | defining Unicode char U+012E (decimal 302) 155 | defining Unicode char U+012F (decimal 303) 156 | defining Unicode char U+0130 (decimal 304) 157 | defining Unicode char U+0131 (decimal 305) 158 | defining Unicode char U+0132 (decimal 306) 159 | defining Unicode char U+0133 (decimal 307) 160 | defining Unicode char U+0134 (decimal 308) 161 | defining Unicode char U+0135 (decimal 309) 162 | defining Unicode char U+0136 (decimal 310) 163 | defining Unicode char U+0137 (decimal 311) 164 | defining Unicode char U+0139 (decimal 313) 165 | defining Unicode char U+013A (decimal 314) 166 | defining Unicode char U+013B (decimal 315) 167 | defining Unicode char U+013C (decimal 316) 168 | defining Unicode char U+013D (decimal 317) 169 | defining Unicode char U+013E (decimal 318) 170 | defining Unicode char U+0141 (decimal 321) 171 | defining Unicode char U+0142 (decimal 322) 172 | defining Unicode char U+0143 (decimal 323) 173 | defining Unicode char U+0144 (decimal 324) 174 | defining Unicode char U+0145 (decimal 325) 175 | defining Unicode char U+0146 (decimal 326) 176 | defining Unicode char U+0147 (decimal 327) 177 | defining Unicode char U+0148 (decimal 328) 178 | defining Unicode char U+014A (decimal 330) 179 | defining Unicode char U+014B (decimal 331) 180 | defining Unicode char U+014C (decimal 332) 181 | defining Unicode char U+014D (decimal 333) 182 | defining Unicode char U+014E (decimal 334) 183 | defining Unicode char U+014F (decimal 335) 184 | defining Unicode char U+0150 (decimal 336) 185 | defining Unicode char U+0151 (decimal 337) 186 | defining Unicode char U+0152 (decimal 338) 187 | defining Unicode char U+0153 (decimal 339) 188 | defining Unicode char U+0154 (decimal 340) 189 | defining Unicode char U+0155 (decimal 341) 190 | defining Unicode char U+0156 (decimal 342) 191 | defining Unicode char U+0157 (decimal 343) 192 | defining Unicode char U+0158 (decimal 344) 193 | defining Unicode char U+0159 (decimal 345) 194 | defining Unicode char U+015A (decimal 346) 195 | defining Unicode char U+015B (decimal 347) 196 | defining Unicode char U+015C (decimal 348) 197 | defining Unicode char U+015D (decimal 349) 198 | defining Unicode char U+015E (decimal 350) 199 | defining Unicode char U+015F (decimal 351) 200 | defining Unicode char U+0160 (decimal 352) 201 | defining Unicode char U+0161 (decimal 353) 202 | defining Unicode char U+0162 (decimal 354) 203 | defining Unicode char U+0163 (decimal 355) 204 | defining Unicode char U+0164 (decimal 356) 205 | defining Unicode char U+0165 (decimal 357) 206 | defining Unicode char U+0168 (decimal 360) 207 | defining Unicode char U+0169 (decimal 361) 208 | defining Unicode char U+016A (decimal 362) 209 | defining Unicode char U+016B (decimal 363) 210 | defining Unicode char U+016C (decimal 364) 211 | defining Unicode char U+016D (decimal 365) 212 | defining Unicode char U+016E (decimal 366) 213 | defining Unicode char U+016F (decimal 367) 214 | defining Unicode char U+0170 (decimal 368) 215 | defining Unicode char U+0171 (decimal 369) 216 | defining Unicode char U+0172 (decimal 370) 217 | defining Unicode char U+0173 (decimal 371) 218 | defining Unicode char U+0174 (decimal 372) 219 | defining Unicode char U+0175 (decimal 373) 220 | defining Unicode char U+0176 (decimal 374) 221 | defining Unicode char U+0177 (decimal 375) 222 | defining Unicode char U+0178 (decimal 376) 223 | defining Unicode char U+0179 (decimal 377) 224 | defining Unicode char U+017A (decimal 378) 225 | defining Unicode char U+017B (decimal 379) 226 | defining Unicode char U+017C (decimal 380) 227 | defining Unicode char U+017D (decimal 381) 228 | defining Unicode char U+017E (decimal 382) 229 | defining Unicode char U+01CD (decimal 461) 230 | defining Unicode char U+01CE (decimal 462) 231 | defining Unicode char U+01CF (decimal 463) 232 | defining Unicode char U+01D0 (decimal 464) 233 | defining Unicode char U+01D1 (decimal 465) 234 | defining Unicode char U+01D2 (decimal 466) 235 | defining Unicode char U+01D3 (decimal 467) 236 | defining Unicode char U+01D4 (decimal 468) 237 | defining Unicode char U+01E2 (decimal 482) 238 | defining Unicode char U+01E3 (decimal 483) 239 | defining Unicode char U+01E6 (decimal 486) 240 | defining Unicode char U+01E7 (decimal 487) 241 | defining Unicode char U+01E8 (decimal 488) 242 | defining Unicode char U+01E9 (decimal 489) 243 | defining Unicode char U+01EA (decimal 490) 244 | defining Unicode char U+01EB (decimal 491) 245 | defining Unicode char U+01F0 (decimal 496) 246 | defining Unicode char U+01F4 (decimal 500) 247 | defining Unicode char U+01F5 (decimal 501) 248 | defining Unicode char U+0218 (decimal 536) 249 | defining Unicode char U+0219 (decimal 537) 250 | defining Unicode char U+021A (decimal 538) 251 | defining Unicode char U+021B (decimal 539) 252 | defining Unicode char U+01E02 (decimal 7682) 253 | defining Unicode char U+01E03 (decimal 7683) 254 | defining Unicode char U+200C (decimal 8204) 255 | defining Unicode char U+2013 (decimal 8211) 256 | defining Unicode char U+2014 (decimal 8212) 257 | defining Unicode char U+2018 (decimal 8216) 258 | defining Unicode char U+2019 (decimal 8217) 259 | defining Unicode char U+201A (decimal 8218) 260 | defining Unicode char U+201C (decimal 8220) 261 | defining Unicode char U+201D (decimal 8221) 262 | defining Unicode char U+201E (decimal 8222) 263 | defining Unicode char U+2030 (decimal 8240) 264 | defining Unicode char U+2031 (decimal 8241) 265 | defining Unicode char U+2039 (decimal 8249) 266 | defining Unicode char U+203A (decimal 8250) 267 | defining Unicode char U+2423 (decimal 9251) 268 | ) 269 | Now handling font encoding OT1 ... 270 | ... processing UTF-8 mapping file for font encoding OT1 271 | 272 | (/usr/share/texlive/texmf-dist/tex/latex/base/ot1enc.dfu 273 | File: ot1enc.dfu 2015/12/03 v1.1r UTF-8 support for inputenc 274 | defining Unicode char U+00A0 (decimal 160) 275 | defining Unicode char U+00A1 (decimal 161) 276 | defining Unicode char U+00A3 (decimal 163) 277 | defining Unicode char U+00AD (decimal 173) 278 | defining Unicode char U+00B8 (decimal 184) 279 | defining Unicode char U+00BF (decimal 191) 280 | defining Unicode char U+00C5 (decimal 197) 281 | defining Unicode char U+00C6 (decimal 198) 282 | defining Unicode char U+00D8 (decimal 216) 283 | defining Unicode char U+00DF (decimal 223) 284 | defining Unicode char U+00E6 (decimal 230) 285 | defining Unicode char U+00EC (decimal 236) 286 | defining Unicode char U+00ED (decimal 237) 287 | defining Unicode char U+00EE (decimal 238) 288 | defining Unicode char U+00EF (decimal 239) 289 | defining Unicode char U+00F8 (decimal 248) 290 | defining Unicode char U+0131 (decimal 305) 291 | defining Unicode char U+0141 (decimal 321) 292 | defining Unicode char U+0142 (decimal 322) 293 | defining Unicode char U+0152 (decimal 338) 294 | defining Unicode char U+0153 (decimal 339) 295 | defining Unicode char U+0174 (decimal 372) 296 | defining Unicode char U+0175 (decimal 373) 297 | defining Unicode char U+0176 (decimal 374) 298 | defining Unicode char U+0177 (decimal 375) 299 | defining Unicode char U+0218 (decimal 536) 300 | defining Unicode char U+0219 (decimal 537) 301 | defining Unicode char U+021A (decimal 538) 302 | defining Unicode char U+021B (decimal 539) 303 | defining Unicode char U+2013 (decimal 8211) 304 | defining Unicode char U+2014 (decimal 8212) 305 | defining Unicode char U+2018 (decimal 8216) 306 | defining Unicode char U+2019 (decimal 8217) 307 | defining Unicode char U+201C (decimal 8220) 308 | defining Unicode char U+201D (decimal 8221) 309 | ) 310 | Now handling font encoding OMS ... 311 | ... processing UTF-8 mapping file for font encoding OMS 312 | 313 | (/usr/share/texlive/texmf-dist/tex/latex/base/omsenc.dfu 314 | File: omsenc.dfu 2015/12/03 v1.1r UTF-8 support for inputenc 315 | defining Unicode char U+00A7 (decimal 167) 316 | defining Unicode char U+00B6 (decimal 182) 317 | defining Unicode char U+00B7 (decimal 183) 318 | defining Unicode char U+2020 (decimal 8224) 319 | defining Unicode char U+2021 (decimal 8225) 320 | defining Unicode char U+2022 (decimal 8226) 321 | ) 322 | Now handling font encoding OMX ... 323 | ... no UTF-8 mapping file for font encoding OMX 324 | Now handling font encoding U ... 325 | ... no UTF-8 mapping file for font encoding U 326 | defining Unicode char U+00A9 (decimal 169) 327 | defining Unicode char U+00AA (decimal 170) 328 | defining Unicode char U+00AE (decimal 174) 329 | defining Unicode char U+00BA (decimal 186) 330 | defining Unicode char U+02C6 (decimal 710) 331 | defining Unicode char U+02DC (decimal 732) 332 | defining Unicode char U+200C (decimal 8204) 333 | defining Unicode char U+2026 (decimal 8230) 334 | defining Unicode char U+2122 (decimal 8482) 335 | defining Unicode char U+2423 (decimal 9251) 336 | )) 337 | (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.sty 338 | Package: amsmath 2016/03/03 v2.15a AMS math features 339 | \@mathmargin=\skip43 340 | 341 | For additional information on amsmath, use the `?' option. 342 | (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty 343 | Package: amstext 2000/06/29 v2.01 AMS text 344 | 345 | (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty 346 | File: amsgen.sty 1999/11/30 v2.0 generic functions 347 | \@emptytoks=\toks16 348 | \ex@=\dimen103 349 | )) 350 | (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty 351 | Package: amsbsy 1999/11/29 v1.2d Bold Symbols 352 | \pmbraise@=\dimen104 353 | ) 354 | (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty 355 | Package: amsopn 1999/12/14 v2.01 operator names 356 | ) 357 | \inf@bad=\count88 358 | LaTeX Info: Redefining \frac on input line 199. 359 | \uproot@=\count89 360 | \leftroot@=\count90 361 | LaTeX Info: Redefining \overline on input line 297. 362 | \classnum@=\count91 363 | \DOTSCASE@=\count92 364 | LaTeX Info: Redefining \ldots on input line 394. 365 | LaTeX Info: Redefining \dots on input line 397. 366 | LaTeX Info: Redefining \cdots on input line 518. 367 | \Mathstrutbox@=\box26 368 | \strutbox@=\box27 369 | \big@size=\dimen105 370 | LaTeX Font Info: Redeclaring font encoding OML on input line 630. 371 | LaTeX Font Info: Redeclaring font encoding OMS on input line 631. 372 | \macc@depth=\count93 373 | \c@MaxMatrixCols=\count94 374 | \dotsspace@=\muskip10 375 | \c@parentequation=\count95 376 | \dspbrk@lvl=\count96 377 | \tag@help=\toks17 378 | \row@=\count97 379 | \column@=\count98 380 | \maxfields@=\count99 381 | \andhelp@=\toks18 382 | \eqnshift@=\dimen106 383 | \alignsep@=\dimen107 384 | \tagshift@=\dimen108 385 | \tagwidth@=\dimen109 386 | \totwidth@=\dimen110 387 | \lineht@=\dimen111 388 | \@envbody=\toks19 389 | \multlinegap=\skip44 390 | \multlinetaggap=\skip45 391 | \mathdisplay@stack=\toks20 392 | LaTeX Info: Redefining \[ on input line 2735. 393 | LaTeX Info: Redefining \] on input line 2736. 394 | ) 395 | (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty 396 | Package: amssymb 2013/01/14 v3.01 AMS font symbols 397 | 398 | (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty 399 | Package: amsfonts 2013/01/14 v3.01 Basic AMSFonts support 400 | \symAMSa=\mathgroup4 401 | \symAMSb=\mathgroup5 402 | LaTeX Font Info: Overwriting math alphabet `\mathfrak' in version `bold' 403 | (Font) U/euf/m/n --> U/euf/b/n on input line 106. 404 | )) 405 | (/usr/share/texlive/texmf-dist/tex/latex/mathtools/mathtools.sty 406 | Package: mathtools 2015/11/12 v1.18 mathematical typesetting tools 407 | 408 | (/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty 409 | Package: keyval 2014/10/28 v1.15 key=value parser (DPC) 410 | \KV@toks@=\toks21 411 | ) 412 | (/usr/share/texlive/texmf-dist/tex/latex/tools/calc.sty 413 | Package: calc 2014/10/28 v4.3 Infix arithmetic (KKT,FJ) 414 | \calc@Acount=\count100 415 | \calc@Bcount=\count101 416 | \calc@Adimen=\dimen112 417 | \calc@Bdimen=\dimen113 418 | \calc@Askip=\skip46 419 | \calc@Bskip=\skip47 420 | LaTeX Info: Redefining \setlength on input line 80. 421 | LaTeX Info: Redefining \addtolength on input line 81. 422 | \calc@Ccount=\count102 423 | \calc@Cskip=\skip48 424 | ) 425 | (/usr/share/texlive/texmf-dist/tex/latex/mathtools/mhsetup.sty 426 | Package: mhsetup 2010/01/21 v1.2a programming setup (MH) 427 | ) 428 | LaTeX Info: Thecontrolsequence`\('isalreadyrobust on input line 129. 429 | LaTeX Info: Thecontrolsequence`\)'isalreadyrobust on input line 129. 430 | LaTeX Info: Thecontrolsequence`\['isalreadyrobust on input line 129. 431 | LaTeX Info: Thecontrolsequence`\]'isalreadyrobust on input line 129. 432 | \g_MT_multlinerow_int=\count103 433 | \l_MT_multwidth_dim=\dimen114 434 | \origjot=\skip49 435 | \l_MT_shortvdotswithinadjustabove_dim=\dimen115 436 | \l_MT_shortvdotswithinadjustbelow_dim=\dimen116 437 | \l_MT_above_intertext_sep=\dimen117 438 | \l_MT_below_intertext_sep=\dimen118 439 | \l_MT_above_shortintertext_sep=\dimen119 440 | \l_MT_below_shortintertext_sep=\dimen120 441 | ) 442 | (/usr/share/texlive/texmf-dist/tex/latex/listings/listings.sty 443 | \lst@mode=\count104 444 | \lst@gtempboxa=\box28 445 | \lst@token=\toks22 446 | \lst@length=\count105 447 | \lst@currlwidth=\dimen121 448 | \lst@column=\count106 449 | \lst@pos=\count107 450 | \lst@lostspace=\dimen122 451 | \lst@width=\dimen123 452 | \lst@newlines=\count108 453 | \lst@lineno=\count109 454 | \lst@maxwidth=\dimen124 455 | 456 | (/usr/share/texlive/texmf-dist/tex/latex/listings/lstmisc.sty 457 | File: lstmisc.sty 2015/06/04 1.6 (Carsten Heinz) 458 | \c@lstnumber=\count110 459 | \lst@skipnumbers=\count111 460 | \lst@framebox=\box29 461 | ) 462 | (/usr/share/texlive/texmf-dist/tex/latex/listings/listings.cfg 463 | File: listings.cfg 2015/06/04 1.6 listings configuration 464 | )) 465 | Package: listings 2015/06/04 1.6 (Carsten Heinz) 466 | 467 | (/usr/share/texlive/texmf-dist/tex/latex/natbib/natbib.sty 468 | Package: natbib 2010/09/13 8.31b (PWD, AO) 469 | \bibhang=\skip50 470 | \bibsep=\skip51 471 | LaTeX Info: Redefining \cite on input line 694. 472 | \c@NAT@ctr=\count112 473 | ) 474 | (/usr/share/texlive/texmf-dist/tex/latex/graphics/graphicx.sty 475 | Package: graphicx 2014/10/28 v1.0g Enhanced LaTeX Graphics (DPC,SPQR) 476 | 477 | (/usr/share/texlive/texmf-dist/tex/latex/graphics/graphics.sty 478 | Package: graphics 2016/01/03 v1.0q Standard LaTeX Graphics (DPC,SPQR) 479 | 480 | (/usr/share/texlive/texmf-dist/tex/latex/graphics/trig.sty 481 | Package: trig 2016/01/03 v1.10 sin cos tan (DPC) 482 | ) 483 | (/usr/share/texlive/texmf-dist/tex/latex/latexconfig/graphics.cfg 484 | File: graphics.cfg 2010/04/23 v1.9 graphics configuration of TeX Live 485 | ) 486 | Package graphics Info: Driver file: pdftex.def on input line 95. 487 | 488 | (/usr/share/texlive/texmf-dist/tex/latex/pdftex-def/pdftex.def 489 | File: pdftex.def 2011/05/27 v0.06d Graphics/color for pdfTeX 490 | 491 | (/usr/share/texlive/texmf-dist/tex/generic/oberdiek/infwarerr.sty 492 | Package: infwarerr 2010/04/08 v1.3 Providing info/warning/error messages (HO) 493 | ) 494 | (/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ltxcmds.sty 495 | Package: ltxcmds 2011/11/09 v1.22 LaTeX kernel commands for general use (HO) 496 | ) 497 | \Gread@gobject=\count113 498 | )) 499 | \Gin@req@height=\dimen125 500 | \Gin@req@width=\dimen126 501 | ) 502 | (/usr/share/texlive/texmf-dist/tex/latex/xcolor/xcolor.sty 503 | Package: xcolor 2007/01/21 v2.11 LaTeX color extensions (UK) 504 | 505 | (/usr/share/texlive/texmf-dist/tex/latex/latexconfig/color.cfg 506 | File: color.cfg 2007/01/18 v1.5 color configuration of teTeX/TeXLive 507 | ) 508 | Package xcolor Info: Driver file: pdftex.def on input line 225. 509 | Package xcolor Info: Model `cmy' substituted by `cmy0' on input line 1337. 510 | Package xcolor Info: Model `hsb' substituted by `rgb' on input line 1341. 511 | Package xcolor Info: Model `RGB' extended on input line 1353. 512 | Package xcolor Info: Model `HTML' substituted by `rgb' on input line 1355. 513 | Package xcolor Info: Model `Hsb' substituted by `hsb' on input line 1356. 514 | Package xcolor Info: Model `tHsb' substituted by `hsb' on input line 1357. 515 | Package xcolor Info: Model `HSB' substituted by `hsb' on input line 1358. 516 | Package xcolor Info: Model `Gray' substituted by `gray' on input line 1359. 517 | Package xcolor Info: Model `wave' substituted by `hsb' on input line 1360. 518 | ) 519 | (./problem_set_2_sol.aux) 520 | \openout1 = `problem_set_2_sol.aux'. 521 | 522 | LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 23. 523 | LaTeX Font Info: ... okay on input line 23. 524 | LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 23. 525 | LaTeX Font Info: ... okay on input line 23. 526 | LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 23. 527 | LaTeX Font Info: ... okay on input line 23. 528 | LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 23. 529 | LaTeX Font Info: ... okay on input line 23. 530 | LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 23. 531 | LaTeX Font Info: ... okay on input line 23. 532 | LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 23. 533 | LaTeX Font Info: ... okay on input line 23. 534 | \c@lstlisting=\count114 535 | 536 | (/usr/share/texlive/texmf-dist/tex/context/base/supp-pdf.mkii 537 | [Loading MPS to PDF converter (version 2006.09.02).] 538 | \scratchcounter=\count115 539 | \scratchdimen=\dimen127 540 | \scratchbox=\box30 541 | \nofMPsegments=\count116 542 | \nofMParguments=\count117 543 | \everyMPshowfont=\toks23 544 | \MPscratchCnt=\count118 545 | \MPscratchDim=\dimen128 546 | \MPnumerator=\count119 547 | \makeMPintoPDFobject=\count120 548 | \everyMPtoPDFconversion=\toks24 549 | ) (/usr/share/texlive/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty 550 | Package: pdftexcmds 2011/11/29 v0.20 Utility functions of pdfTeX for LuaTeX (HO 551 | ) 552 | 553 | (/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ifluatex.sty 554 | Package: ifluatex 2010/03/01 v1.3 Provides the ifluatex switch (HO) 555 | Package ifluatex Info: LuaTeX not detected. 556 | ) 557 | (/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ifpdf.sty 558 | Package: ifpdf 2011/01/30 v2.3 Provides the ifpdf switch (HO) 559 | Package ifpdf Info: pdfTeX in PDF mode is detected. 560 | ) 561 | Package pdftexcmds Info: LuaTeX not detected. 562 | Package pdftexcmds Info: \pdf@primitive is available. 563 | Package pdftexcmds Info: \pdf@ifprimitive is available. 564 | Package pdftexcmds Info: \pdfdraftmode found. 565 | ) 566 | (/usr/share/texlive/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty 567 | Package: epstopdf-base 2010/02/09 v2.5 Base part for package epstopdf 568 | 569 | (/usr/share/texlive/texmf-dist/tex/latex/oberdiek/grfext.sty 570 | Package: grfext 2010/08/19 v1.1 Manage graphics extensions (HO) 571 | 572 | (/usr/share/texlive/texmf-dist/tex/generic/oberdiek/kvdefinekeys.sty 573 | Package: kvdefinekeys 2011/04/07 v1.3 Define keys (HO) 574 | )) 575 | (/usr/share/texlive/texmf-dist/tex/latex/oberdiek/kvoptions.sty 576 | Package: kvoptions 2011/06/30 v3.11 Key value format for package options (HO) 577 | 578 | (/usr/share/texlive/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty 579 | Package: kvsetkeys 2012/04/25 v1.16 Key value parser (HO) 580 | 581 | (/usr/share/texlive/texmf-dist/tex/generic/oberdiek/etexcmds.sty 582 | Package: etexcmds 2011/02/16 v1.5 Avoid name clashes with e-TeX commands (HO) 583 | Package etexcmds Info: Could not find \expanded. 584 | (etexcmds) That can mean that you are not using pdfTeX 1.50 or 585 | (etexcmds) that some package has redefined \expanded. 586 | (etexcmds) In the latter case, load this package earlier. 587 | ))) 588 | Package grfext Info: Graphics extension search list: 589 | (grfext) [.png,.pdf,.jpg,.mps,.jpeg,.jbig2,.jb2,.PNG,.PDF,.JPG,.JPE 590 | G,.JBIG2,.JB2,.eps] 591 | (grfext) \AppendGraphicsExtensions on input line 452. 592 | 593 | (/usr/share/texlive/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg 594 | File: epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Liv 595 | e 596 | )) 597 | LaTeX Font Info: Try loading font information for U+msa on input line 25. 598 | 599 | (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsa.fd 600 | File: umsa.fd 2013/01/14 v3.01 AMS symbols A 601 | ) 602 | LaTeX Font Info: Try loading font information for U+msb on input line 25. 603 | 604 | (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsb.fd 605 | File: umsb.fd 2013/01/14 v3.01 AMS symbols B 606 | ) [1 607 | 608 | {/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] 609 | Underfull \hbox (badness 10000) in paragraph at lines 27--28 610 | 611 | [] 612 | 613 | 614 | Underfull \hbox (badness 10000) in paragraph at lines 29--34 615 | 616 | [] 617 | 618 | 619 | Underfull \hbox (badness 10000) in paragraph at lines 35--36 620 | 621 | [] 622 | 623 | 624 | Underfull \hbox (badness 10000) in paragraph at lines 37--38 625 | 626 | [] 627 | 628 | 629 | Underfull \hbox (badness 10000) in paragraph at lines 39--40 630 | 631 | [] 632 | 633 | 634 | Underfull \hbox (badness 10000) in paragraph at lines 43--44 635 | 636 | [] 637 | 638 | 639 | Underfull \hbox (badness 10000) in paragraph at lines 45--46 640 | 641 | [] 642 | 643 | 644 | Underfull \hbox (badness 10000) in paragraph at lines 47--51 645 | 646 | [] 647 | 648 | 649 | Underfull \hbox (badness 10000) in paragraph at lines 52--53 650 | 651 | [] 652 | 653 | 654 | Package amsmath Warning: Foreign command \atopwithdelims; 655 | (amsmath) \frac or \genfrac should be used instead 656 | (amsmath) on input line 56. 657 | 658 | 659 | Underfull \hbox (badness 10000) in paragraph at lines 56--57 660 | 661 | [] 662 | 663 | 664 | Underfull \hbox (badness 10000) in paragraph at lines 63--67 665 | 666 | [] 667 | 668 | [1] 669 | Underfull \hbox (badness 10000) in paragraph at lines 68--69 670 | 671 | [] 672 | 673 | 674 | Underfull \hbox (badness 10000) in paragraph at lines 70--71 675 | 676 | [] 677 | 678 | 679 | Underfull \hbox (badness 10000) in paragraph at lines 72--73 680 | 681 | [] 682 | 683 | 684 | Underfull \hbox (badness 10000) in paragraph at lines 74--79 685 | 686 | [] 687 | 688 | 689 | Underfull \hbox (badness 10000) in paragraph at lines 81--86 690 | 691 | [] 692 | 693 | 694 | Underfull \hbox (badness 10000) in paragraph at lines 87--88 695 | 696 | [] 697 | 698 | 699 | Underfull \hbox (badness 10000) in paragraph at lines 89--90 700 | 701 | [] 702 | 703 | 704 | Underfull \hbox (badness 10000) in paragraph at lines 98--99 705 | 706 | [] 707 | 708 | 709 | Underfull \hbox (badness 10000) in paragraph at lines 100--101 710 | 711 | [] 712 | 713 | 714 | Underfull \hbox (badness 10000) in paragraph at lines 102--103 715 | 716 | [] 717 | 718 | 719 | Underfull \hbox (badness 10000) in paragraph at lines 104--107 720 | 721 | [] 722 | 723 | [2] 724 | Underfull \hbox (badness 10000) in paragraph at lines 108--109 725 | 726 | [] 727 | 728 | 729 | Underfull \hbox (badness 10000) in paragraph at lines 110--113 730 | 731 | [] 732 | 733 | 734 | Underfull \hbox (badness 10000) in paragraph at lines 114--118 735 | 736 | [] 737 | 738 | 739 | Underfull \hbox (badness 10000) in paragraph at lines 119--120 740 | 741 | [] 742 | 743 | 744 | Underfull \hbox (badness 10000) in paragraph at lines 121--122 745 | 746 | [] 747 | 748 | 749 | Underfull \hbox (badness 10000) in paragraph at lines 123--124 750 | 751 | [] 752 | 753 | 754 | Underfull \hbox (badness 10000) in paragraph at lines 134--135 755 | 756 | [] 757 | 758 | [3] 759 | Underfull \hbox (badness 10000) in paragraph at lines 175--177 760 | 761 | [] 762 | 763 | 764 | Underfull \hbox (badness 10000) in paragraph at lines 178--179 765 | 766 | [] 767 | 768 | [4] 769 | Underfull \hbox (badness 10000) in paragraph at lines 189--190 770 | 771 | [] 772 | 773 | 774 | Underfull \hbox (badness 10000) in paragraph at lines 191--192 775 | 776 | [] 777 | 778 | 779 | Underfull \hbox (badness 10000) in paragraph at lines 194--196 780 | 781 | [] 782 | 783 | 784 | Underfull \hbox (badness 10000) in paragraph at lines 206--208 785 | 786 | [] 787 | 788 | [5] [6] (./problem_set_2_sol.aux) ) 789 | Here is how much of TeX's memory you used: 790 | 5391 strings out of 494910 791 | 71802 string characters out of 6179836 792 | 148891 words of memory out of 5000000 793 | 8607 multiletter control sequences out of 15000+600000 794 | 11378 words of font info for 45 fonts, out of 8000000 for 9000 795 | 36 hyphenation exceptions out of 8191 796 | 38i,13n,35p,729b,223s stack positions out of 5000i,500n,10000p,200000b,80000s 797 | 810 | Output written on problem_set_2_sol.pdf (7 pages, 159738 bytes). 811 | PDF statistics: 812 | 80 PDF objects out of 1000 (max. 8388607) 813 | 57 compressed objects within 1 object stream 814 | 0 named destinations out of 1000 (max. 500000) 815 | 1 words of extra memory for PDF output out of 10000 (max. 10000000) 816 | 817 | -------------------------------------------------------------------------------- /assignment_2/problem_set_2_sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndreeaMusat/Stanford-CS109-Probability-for-computer-scientists/1cc1837fa641c63bee8a055bfe3b7eb4fa479439/assignment_2/problem_set_2_sol.pdf -------------------------------------------------------------------------------- /assignment_2/problem_set_2_sol.tex: -------------------------------------------------------------------------------- 1 | \documentclass[10pt,a4paper,oneside,draft]{report} 2 | \usepackage[utf8]{inputenc} 3 | \usepackage{amsmath,amssymb} 4 | \usepackage{mathtools} 5 | \usepackage{listings} 6 | 7 | \DeclareRobustCommand{\bbone}{\text{\usefont{U}{bbold}{m}{n}1}} 8 | 9 | \DeclareMathOperator{\EX}{\mathbb{E}}% expected value 10 | \DeclarePairedDelimiter\ceil{\lceil}{\rceil} 11 | \DeclarePairedDelimiter\floor{\lfloor}{\rfloor} 12 | 13 | \title{CS109 assignment 2} 14 | \author{andreea.a.musat@gmail.com} 15 | \date{January 2019} 16 | 17 | \usepackage{natbib} 18 | \usepackage{graphicx} 19 | \usepackage{xcolor} 20 | 21 | \newcommand\myworries[1]{\textcolor{red}{#1}} 22 | 23 | \begin{document} 24 | 25 | \maketitle 26 | 27 | \textbf{Warmup} \\ 28 | 29 | \textbf{1.} Say in Silicon Valley, 36\% of engineers program in Java and 24\% of the engineers who 30 | program in Java also program in C++. Furthermore, 33\% of engineers program in C++. \\ 31 | a. What is the probability that a randomly selected engineer programs in Java and C++? \\ 32 | b. What is the conditional probability that a randomly selected engineer programs in Java 33 | given that he/she programs in C++? \\ 34 | 35 | \textbf{Solution} \\ 36 | 37 | a. $P(J, C) = P(J) * P(C|J) = 0.36 * 0.24 = 0.0864$ \\ 38 | 39 | b. $P(J|C) = \frac{ {P(C|J) P(J)} }{P(C)} = \frac{ {0.24 * 0.36} }{0.33} = 0.2618$ \\ 40 | 41 | \textbf{2.} Two cards are randomly chosen without replacement from an ordinary deck of 52 cards. Let E be the event that both cards are Aces. Let F be the event that the first card chosen is the Ace of Spades. Compute $P(E|F)$. 42 | 43 | \textbf{Solution} \\ 44 | 45 | Intuitively, we'd say that if we already know that the first card is Ace of Spades, there are 51 cards left to choose from and 3 of those would make event E happen, so the probability is $\frac{3}{51}$. We can check this result if we apply Bayes' rule: $P(E|F) = \frac{ {P(F|E) P(E)} } {P(F)}$. We know that $P(F) = \frac{1}{52}$, as there is exactly one Ace of Spades in the deck. Also, $P(E) = P(\textnormal{first card is Ace}) P(\textnormal{second card is Ace}) = \frac{4}{52} \frac{3}{51}$. Given that we have a pair of Aces, the probability that first one in the pair is the Ace of Spades is $\frac{1}{4} = P(F|E)$. Replacing the values in Bayes' rule above, we get the same result. \\ 46 | 47 | \textbf{3.} Five servers are located in a computer cluster. After one year, each server independently is still working with probability p, and otherwise fails (with probability 1 – p). \\ 48 | a. What is the probability that at least 1 server is still working after one year? \\ 49 | b. What is the probability that exactly 3 servers are still working after one year? \\ 50 | c. What is the probability that at least 3 servers are still working after one year? \\ 51 | 52 | \textbf{Solution} \\ 53 | 54 | a. $P(\# \textnormal{working clusters} \geq 1) = 1 - P(\# \textnormal{working clusters} = 0) = 1 - (1-p)^5.$ 55 | 56 | b. $P(\# \textnormal{working clusters} = 3) = {5 \choose 3} {p^3} {(1-p)^2} = 10 {p^3} {(1-p)^2} $\\ 57 | 58 | c. \begin{center} 59 | $P(\# \textnormal{working clusters} >= 3) = 60 | P(\# \textnormal{working clusters} = 3) + P(\# \textnormal{working clusters} = 4) + P(\# \textnormal{working clusters} = 5) = {5 \choose 3} {p^3} {(1-p)^2} + {5 \choose 4} {p^4} {(1-p)^1} + {5 \choose 5} {p^5} {(1-p)^0} $ 61 | \end{center} 62 | 63 | \textbf{4.} A website wants to detect if a visitor is a robot. They give the visitor three CAPTCHA tests that are hard for robots, but easy for humans. If the visitor fails in one of the tests, they are flagged as a robot. The probability that a human succeeds at a single test is 0.95, while a robot only succeeds with probability 0.3. Assume all tests are independent. \\ 64 | a. If a robot visits the website, what is the probability they get flagged? \\ 65 | b. If a visitor is human, what is the probability they get flagged? \\ 66 | c. The fraction of visitors on the site that are robots is 1/10. Suppose a visitor gets flagged. What is the probability that visitor is a robot? \\ 67 | 68 | \textbf{Solution} \\ 69 | 70 | a. $P(\textnormal{R is flagged}) = 1 - P(\textnormal{R gets all 3 tests correct}) = 1 - 0.3^3 = 0.973$.\\ 71 | 72 | b. $P(\textnormal{H is flagged}) = 1 - P(\textnormal{H gets all 3 tests correct}) = 1 - 0.95^3 = 0.1426$.\\ 73 | 74 | c. $P(\textnormal{V=R}|\textnormal{V is flagged}) = \frac{ {P(\textnormal{V is flagged} | \textnormal{V=R}) P(\textnormal{V=R})} }{ P(\textnormal{V is flagged}) } 75 | = \\ 76 | \frac{ {P(\textnormal{R is flagged}) P(\textnormal{V=R})} }{ {P(\textnormal{R is flagged})P(\textnormal{V=R}) + P(\textnormal{H is flagged})P(\textnormal{V=H})} } 77 | = \frac{ {0.973 * 0.1} }{ {0.973 * 0.1 + 0.1426 * 0.9} } = 0.4312 78 | $\\ 79 | 80 | 81 | \textbf{5.} Recall the game set-up in the “St. Petersburg’s paradox” discussed in class: there is a fair coin which comes up "heads" with probability p = 0.5. The coin is flipped repeatedly until the first "tails" appears. Let N = number of coin flips before the first "tails" appears (i.e., N = the number of consecutive "heads" that appear). Given that no one really has infinite money to offer as payoff for the game, consider a variant of the game where you win MIN$(2^N , X)$, 82 | where X is the maximum amount that the game provider will pay you after playing. Compute the expected payoff of the game for the following values of X. Show your work.\\ 83 | a. X = \$5. \\ 84 | b. X = \$500. \\ 85 | c. X = \$4096. \\ 86 | 87 | \textbf{Solution} \\ 88 | 89 | In the most general way, we can write: \\ 90 | 91 | 92 | 93 | \begin{gather*} 94 | \EX[\textnormal{payoff}] = \sum_{i=0}^{i=\infty} (\frac{1}{2})^i \frac{1}{2} \min(2^i, X) = \sum_{i=0}^{i=\floor*{\log_2 X}} (\frac{1}{2^{i + 1}}) 2^i + \sum_{i>\floor*{\log_2 X}} \frac{1}{2^{i + 1}} X = \\ 95 | \frac{1}{2} (1 + \floor*{\log_2 X}) + \frac{1}{2^{ \floor*{\log_2 X} + 1 }} X \sum_{i>0} \frac{1}{2 ^ i} = \frac{1}{2} (1 + \floor*{\log_2 X}) + \frac{X}{2^{ \floor*{\log_2 X} }} 96 | \end{gather*} 97 | 98 | a. Using X=\$5 in the equation above, we get: $\EX[\textnormal{payoff}] = \frac{3}{2} + \frac{5}{4} = 2.75.$ \\ 99 | 100 | b. $\EX[\textnormal{payoff} | X=\$500] = \frac{9}{2} + \frac{500}{256} = 6.45.$ \\ 101 | 102 | c. $\EX[\textnormal{payoff} | X=\$4096] = \frac{13}{2} + \frac{4096}{4096} = 7.5.$\\ 103 | 104 | \textbf{6.} A bit string of length n is generated randomly such that each bit is generated independently 105 | with probability p that the bit is a 1 (and 0 otherwise). How large does n need to be (in terms 106 | of p) so that the probability that there is at least one 1 in the string is at least 0.7? \\ 107 | 108 | \textbf{Solution} \\ 109 | 110 | $P(\#_1(string) \geq 1) = 1 - P(\#_1(string)=0) = 1 - (1 - p)^n$. 111 | Thus, $P(\#_1(string) \geq 1) \geq 0.7$ is equivalent to: 112 | $1 - (1 - p)^n \geq 0.7 \iff 0.3 \geq (1 - p)^n \iff \log_{1-p} 0.3 \leq n $ \\ 113 | 114 | \textbf{7.} The probability that a Netflix user likes a movie Mi from the “Tearjerker” genre, given that they like the Tearjerker genre, is $p_i$. The probability that a user likes $M_i$ given that they do not like the Tearjerker genre, is $q_i$. Of all Netflix users, 60\% like the Tearjerker genre. Assume that, conditioned on knowing a user’s preference for the genre (either liking the genre or not liking it), liking movie $M_1$ , $M_2$ and $M_3$ are independent events. Express all your answers in terms of qs and ps. What is the probability: \\ 115 | a. That a user likes all three movies $M_1$ , $M_2$ and $M_3$ given that they like the Tearjerker genre? \\ 116 | b. That they like at least one movie $M_1$ , $M_2$ and $M_3$ given that they like the Tearjerker genre? \\ 117 | c. That they like the Tearjerker genre given that they like $M_1$ , $M_2$ and $M_3$? \\ 118 | 119 | \textbf{Solution} \\ 120 | 121 | TBD \\ 122 | 123 | \textbf{8.} Suppose we want to write an algorithm fairRandom for randomly generating a 0 or a 1 with equal probability (= 0.5). Unfortunately, all we have available to us is a function: \textbf{int unknownRandom()} that randomly generates bits, where on each call a 1 is returned with some unknown probability p that need not be equal to 0.5 (and a 0 is returned with probability 1 – p). Consider the following algorithm for \textbf{fairRandom}: \\ 124 | 125 | \begin{verbatim} 126 | def fairRandom(): 127 | while True: 128 | r1 = unknownRandom() 129 | r2 = unknownRandom() 130 | if (r1 != r2): break 131 | return r2; 132 | \end{verbatim} 133 | 134 | a. Show mathematically that \textbf{fairRandom} does indeed return a 0 or a 1 with equal probability. \\ 135 | 136 | \textbf{Solution} \\ 137 | The event that \textbf{fairRandom} returns 1 happens when the while loop terminates and the last $r_2$ is 1: That is, 138 | \begin{gather*} 139 | P(\textbf{fairRandom() } \text{returns 1}) = P(\text{while loop terminates} \land r_2^{\text{(last)}} = 1). 140 | \end{gather*} 141 | 142 | The while loop terminates if it ends at the first iteration or at the second iteration or so on. We denote by $St(i)$ the event that the while loop terminates at iteration i. We can write: 143 | \begin{gather*} 144 | P(\text{while loop terminates}) = P(\lor_{i=1}^{\infty} St(i)). 145 | \end{gather*} 146 | 147 | Now, the loop terminates at iteration i iff for the first i - 1 iterations we generate the same $r_1$ and $r_2$ and then at the $i^{th}$ iteration we generate different numbers. Let $Eq(i)$ be the event that $r_1$ generated at timestep i is equal to $r_2$ generated at timestep i. Then, 148 | \begin{gather*} 149 | P(St(i)) = P((\land_{k=1}^{i-1} Eq(k)) \land \neg Eq(i)). 150 | \end{gather*} 151 | 152 | Using these, we re-write $P(\textbf{fairRandom()} \text{ returns 1})$: 153 | \begin{gather*} 154 | P(\textbf{fairRandom()} \text{ returns 1}) = P(\text{while loop terminates} \land r_2^{\text{(last)}} = 1) = \\ 155 | P(\text{while loop terminates} | r_2^{\text{(last)}} = 1) P(r_2^{\text{(last)}} = 1) = \\ 156 | P(\lor_{i=1}^{\infty} St(i) | r_2^{\text{(last)}} = 1) P(r_2^{\text{(last)}} = 1) = \\ 157 | P(r_2^{\text{(last)}} = 1) \sum_{i=1}^{\infty} P(St(i) | r_2^{(i)} = 1) = \\ 158 | P(r_2^{\text{(last)}} = 1) \sum_{i=1}^{\infty} P(\big(\land_{k=1}^{i-1} Eq(k)) \land \neg Eq(i) | r_2^{(i)} = 1 \big) = \\ 159 | P(r_2^{\text{(last)}} = 1) \sum_{i=1}^{\infty} P(\neg Eq(i) | r_2^{(i)} = 1) \prod_{k=1}^{i-1} P(Eq(k) | r_2^{(i)} = 1) 160 | \end{gather*} 161 | where we used the fact that the events $St(i)$ are independent for all i (and also the events $Eq(i)$ are independent). We know that $P(r_2 = 1) = p$ and that: 162 | \begin{gather*} 163 | P(Eq(k)) = P(r_1^{(k)} = r_2^{(k)}) = P(r_1^{(k)} = 0 \land r_2^{(k)} = 0) + P(r_1^{(k)} = 1 \land r_2^{(k)} = 1) = \\ 164 | (1-p)^2 + p^2, 165 | \end{gather*} 166 | and obviously: 167 | \begin{gather*} 168 | P(\neg Eq(i) | r_2^{(i)} = 1) = P(r_1^{(i)} = 0) = 1-p 169 | \end{gather*} 170 | We also note that $P(\neg Eq(k)) = 2p(1-p)$. Also, $Eq(k)$ and $r_2^{(i)} = 1$ are independent $\forall k < i$, so replacing these into the above formula we obtain: 171 | \begin{gather*} 172 | P(\textbf{fairRandom()} \text{ returns 1}) = p \sum_{i=1}^{\infty} \Big( (1-p) \prod_{k=1}^{i-1} \big( (1-p)^2 + p^2 \big) \Big) = \\ 173 | p \sum_{i=1}^{\infty} \Big( (1-p) \big( (1-p)^2 + p^2 \big)^{i-1} \Big) = p(1-p) \sum_{i=1}^{\infty} \big( (1-p)^2 + p^2 \big)^{i-1} = \\ 174 | p(1-p) \frac{1}{1 - \big( (1-p)^2 + p^2 \big)} = \frac{p(1-p)}{2p(1-p)} = \frac{1}{2} 175 | \end{gather*} 176 | Similarily, we could also show that $P(\textbf{fairRandom()} \text{ returns 0}) = \frac{1}{2}$ (which is an intuitive result, as the while loop always terminates). \\ 177 | 178 | b. Say we want to simplify the function, so we write the \textbf{simpleRandom} function below. Would the \textbf{simpleRandom} function also generate 0’s and 1’s with equal probability? Explain why or why not. Determine P(\textbf{simpleRandom} \text{ returns 1}) in terms of p. \\ 179 | \begin{verbatim} 180 | int simpleRandom() { 181 | r1 = unknownRandom() 182 | while True: 183 | r2 = unknownRandom() 184 | if (r1 != r2): break 185 | r1 = r2 186 | return r2 187 | \end{verbatim} 188 | 189 | \textbf{Solution} \\ 190 | 191 | The function returns a 1 if the while loop terminates and $r_2$ is 1. Looking at the function, we observe that the loop breaks only when $r_2$ is different from $r_1$ and $r_1$ is only generated once, at the beginning. This means that the loop breaks when we generate the first number different from $r_1$, so we can write: \\ 192 | \begin{gather*} 193 | P(\textbf{simpleRandom() } \text{generates 1}) = P(\text{while loop terminates} \land r_2^{(last)} = 1) 194 | \end{gather*} 195 | Denoting by $St(i)$ the event that the loop terminates at iteration i and by $Eq(i)$ the event that $r_1$ is equal to $r_2$ generated at timestep i ($r_2^{(i)}$), we can continue: \\ 196 | \begin{gather*} 197 | P(\textbf{simpleRandom() } \text{generates 1}) = P\Big( \lor_{i=1}^{\infty} \big( St(i) \land r_2^{(i)} = 1 \big) \Big) = \\ 198 | P\Big( \lor_{i=1}^{\infty} \big( (\land_{k=1}^{i-1} Eq(k)) \land \neg Eq(i) \land r_2^{(i)} = 1 \big) \Big) 199 | \end{gather*} 200 | We use the law of total probability with the partitions $r_1=0$ and $r_1=1$ and we get: 201 | \begin{gather*} 202 | P(\textbf{simpleRandom() } \text{generates 1}) = \\ 203 | P\Big( \lor_{i=1}^{\infty} \big( (\land_{k=1}^{i-1} Eq(k)) \land \neg Eq(i) \land r_2^{(i)} = 1 \big) | r_1=0 \Big) P(r_1=0) + \\ 204 | P\Big( \lor_{i=1}^{\infty} \big( (\land_{k=1}^{i-1} Eq(k)) \land \neg Eq(i) \land r_2^{(i)} = 1 \big) | r_1=1 \Big) P(r_1=1) = \\ 205 | P\Big( \lor_{i=1}^{\infty} \big( (\land_{k=1}^{i-1} Eq(k)) \land \neg Eq(i) \land r_2^{(i)} = 1 \big) | r_1=0 \Big) P(r_1=0), 206 | \end{gather*} 207 | as the second term disappears because $\neg Eq(i) \land r_2^{(i)} = 1$ and $r_1=1$ are contradictory events (from the definition of $Eq(i)$).\\ 208 | 209 | Finally, 210 | \begin{gather*} 211 | P(\textbf{simpleRandom() } \text{generates 1}) = \\ 212 | P\Big( \lor_{i=1}^{\infty} \big( (\land_{k=1}^{i-1} Eq(k)) \land \neg Eq(i) \land r_2^{(i)} = 1 \big) | r_1=0 \Big) P(r_1=0) = \\ 213 | P(r_1=0) \sum_{i=1}^{\infty} P \big( (\land_{k=1}^{i-1} Eq(k) \land \neg Eq(i) \land r_2^{(i)} = 1 \big) | r_1=0) 214 | \end{gather*} 215 | Given that $r_1=0$ and $r_2^{(i)} = 1$, it follows that $\neg Eq(i)$, so this event is redundant and we can remove it: 216 | \begin{gather*} 217 | P(\textbf{simpleRandom() } \text{generates 1}) = \\ 218 | P(r_1=0) \sum_{i=1}^{\infty} P \big( (\land_{k=1}^{i-1} Eq(k) \land r_2^{(i)} = 1 \big) | r_1=0) = \\ 219 | P(r_1=0) \sum_{i=1}^{\infty} \big( P(r_2^{(i)} = 1 | r_1=0) \prod_{k=1}^{i-1} P(Eq(k) | r_1=0) \big) = \\ 220 | (1-p) \sum_{i=1}^{\infty} \big( p \prod_{k=1}^{i-1} P(Eq(k) | r_1=0) \big) = p (1-p) \sum_{i=1}^{\infty} \prod_{k=1}^{i-1} P(r_2^{(k)} = 0) = \\ 221 | p (1-p) \sum_{i=1}^{\infty} (1-p)^{i-1} = p (1-p) \frac{1}{1 - (1-p)} = \frac{p (1-p)}{p} = 1-p 222 | \end{gather*} 223 | The intuitive explanation for this is that whenever we start with $r_1 = 0$, we return $r_2=1$ (as the loop only terminates when we encounter the first different number) and this happens with probability 1-p. 224 | \end{document} 225 | 226 | --------------------------------------------------------------------------------