Basic probability
Define flip(p) that returns True with probability p and False with probability (1-p).
The only built-in you can use is random.random:
>>> import random
>>> random.random() # returns a number in [0,1)
0.4013560344771465
which returns a uniformly distributed number in the interval [0,1). You cannot
specify any parameters to random.random().
Define a recursive function geometric(p) that flips with probability p until it succeeds and returns the number of failed trials before that.
You need to make a toss with equal chance for heads and tails, but you have a coin that you know is biased, but donโt know by how much and in which way. Using only this biased coin, design an experiment that is equivalent to making a fair toss. You can assume that the outcomes of successive tosses of the coin are independent.
๐๏ธYou roll a 6-sided dice once; only if the outcome is even, you roll it for a second time. What is the probability that you roll a 6 on the second roll?
Do not use the multiplication rule or conditional probability. Compute the probability directly over the sample space.
A batch of one hundred items is inspected by testing four randomly selected items. If one of the four is defective, the batch is rejected. What is the probability that the batch is accepted if it contains five defectives?
Source: ItP ๐๏ธYou enter a special kind of chess tournament, in which you play one game with each of three opponents, but you get to choose the order in which you play your opponents, knowing the probability of a win against each. You win the tournament if you win two games in a row, and you want to maximize the probability of winning. Show that it is optimal to play the weakest opponent second, and that the order of playing the other two opponents does not matter.
Source: ItP ๐๏ธBob has a peculiar pair of three-sided dice. When he rolls the dice, the probability of any particular outcome is proportional to the product of the outcome of each die. All outcomes that result in a particular product are equally likely. a. What is the probability of the product being even? b. What is the probability of Bob rolling a 2 and a 3?
Source: PSAAP ๐๏ธHere is the depiction of the sample space of a probabilistic model, where the reals \(x,y,z,t > 0\) indicate the probability mass of the corresponding regions. Note that they are not probabilities themselves, they are only proportional to the probabilities of the corresponding events.
Indicate the following probabilities in terms of \(x,y,z,t\):
- \(P(A\given B) =\)
- \(P(A\given \neg B) =\)
- \(P(A\cap \neg B) =\)
- \(P(B\given A\cap B) =\)
- \(P(A\cup B) =\)
Suppose that we have found that the word โRolexโ occurs in 250 of 2000 messages known to be spam and in 5 of 1000 messages known not to be spam. Estimate the probability that an incoming message containing the word โRolexโ is spam, assuming that it is equally likely that an incoming message is spam or not spam.
Source: Rosen (2019) ๐๏ธTwo players take turns removing a ball from a jar that initially contains \(m\) white and \(n\) black balls. The first player to remove a white ball wins. Develop a recursive formula that allows the convenient computation of the probability that the starting player wins.
Source: ItP ๐๏ธEach of k jars contains m white and n black balls. A ball is randomly chosen from jar 1 and transferred to jar 2, then a ball is randomly chosen from jar 2 and transferred to jar 3, etc. Finally, a ball is randomly chosen from jar k. Show that the probability that the last ball is white is the same as the probability that the first ball is white, i.e., it is m/(m + n).
Source: ItP ๐๏ธWe have two jars, each initially containing an equal number of balls. We perform four successive ball exchanges. In each exchange, we pick simultaneously and at random a ball from each jar and move it to the other jar. What is the probability that at the end of the four exchanges all the balls will be in the jar where they started?
Source: ItP ๐๏ธThe release of two out of three prisoners has been announced, but their identity is kept secret. One of the prisoners considers asking a friendly guard to tell him who is the prisoner other than himself that will be released, but hesitates based on the following rationale: at the prisonerโs present state of knowledge, the probability of being released is 2/3, but after he knows the answer, the probability of being released will become 1/2, since there will be two prisoners (including himself) whose fate is unknown and exactly one of the two will be released. What is wrong with this line of reasoning?
Source: ItP ๐๏ธYou are handed two envelopes, and you know that each contains a positive integer dollar amount and that the two amounts are different. The values of these two amounts are modeled as constants that are unknown. Without knowing what the amounts are, you select at random one of the two envelopes, and after looking at the amount inside, you may switch envelopes if you wish. A friend claims that the following strategy will increase above 1/2 your probability of ending up with the envelope with the larger amount: toss a coin repeatedly, let X be equal to 1/2 plus the number of tosses required to obtain heads for the first time, and switch if the amount in the envelope you selected is less than the value of X. Is your friend correct?
Source: ItP ๐๏ธAlice and Bob have \(2 n + 1\) coins, each coin with probability of heads equal to \(1/2\). Bob tosses \(n+1\) coins, while Alice tosses the remaining \(n\) coins. Assuming independent coin tosses, show that the probability that after all coins have been tossed, Bob will have gotten more heads than Alice is \(1/2\).
Source: ItP ๐๏ธYou are given the following state space with the probabilities of the corresponding events:
If you receive the information that event \(A\) and \(B\) are independent, what can you say, if anything, about the relation between the probability mass terms \(x,y,z,t\)?
๐๏ธ