from common import register D = 'probability' def add(n, c, t, s, e, **kw): register(D, n, c, t, s, e, **kw) add('hypergeometric', [['A bag contains {r} red balls and {b} blue balls; {n} balls are sampled uniformly without replacement.', 'Choose {n} balls uniformly without replacement from a bag with {r} red and {b} blue balls.', 'There are {r} red and {b} blue balls in a bag, and a uniformly random sample of size {n} is drawn without replacement.'], ['The target is exactly {k} red balls.', 'Require precisely {k} of the sampled balls to be red.', 'Consider the event of drawing exactly {k} red balls.']], ['What is the probability?', 'Find the exact probability of this event.', 'Determine the event probability as a fraction.'], lambda r: dict(r=r.randint(6, 25), b=r.randint(6, 25), n=r.randint(3, 6), k=r.randint(1, 3)), [('favorable', 'C(r,k)*C(b,n-k)'), ('total', 'C(r+b,n)'), ('answer', 'favorable/total')], level='medium', depth=3) add('conditional_table', [['A class has {a} girls who study French, {b} girls who do not, {c} boys who study French, and {d} boys who do not.', 'The four class counts are: French-studying girls {a}, other girls {b}, French-studying boys {c}, and other boys {d}.', 'There are {a} French-studying girls and {b} non-French-studying girls, together with {c} French-studying boys and {d} non-French-studying boys.'], ['A student is selected uniformly from the students who study French.', 'Condition the uniformly random student choice on studying French.', 'Choose uniformly among the French students.']], ['What is the probability that the student is a girl?', 'Find the conditional probability of choosing a girl.', 'Determine the chance that the selected French student is a girl.'], lambda r: dict(a=r.randint(3, 35), b=r.randint(3, 35), c=r.randint(3, 35), d=r.randint(3, 35)), [('eligible', 'a+c'), ('answer', 'a/eligible')], level='easy') add('bayes_urn', [['Choose bag A with probability {p}/{q}, otherwise bag B; A has {a} red and {b} blue balls, while B has {c} red and {d} blue balls.', 'Bag A contains {a} red and {b} blue balls, and bag B contains {c} red and {d} blue balls; choose A with probability {p}/{q} and B otherwise.', 'A bag is chosen with probabilities {p}/{q} for A and the remainder for B; their red/blue counts are {a}/{b} for A and {c}/{d} for B.'], ['One ball is drawn uniformly from the chosen bag and is observed to be red.', 'A uniform draw from the selected bag produces a red ball.', 'The observed result of one uniform ball draw is red.']], ['What is the probability that bag A was chosen?', 'Find the posterior probability of bag A.', 'Determine the conditional probability that the draw came from A.'], lambda r: dict(p=r.randint(1, 4), q=r.randint(6, 10), a=r.randint(3, 20), b=r.randint(3, 20), c=r.randint(3, 20), d=r.randint(3, 20)), [('joint_A', 'p/q*a/(a+b)'), ('joint_B', '(1-p/q)*c/(c+d)'), ('answer', 'joint_A/(joint_A+joint_B)')], level='hard', depth=4, concepts=3) add('sampling_expectation', [['A population contains {r} marked and {b} unmarked objects; {n} are sampled uniformly without replacement.', 'Take a uniform sample of {n} objects, without replacement, from {r} marked and {b} unmarked objects.', 'There are {r} marked objects and {b} unmarked objects, and {n} distinct objects are sampled uniformly.'], ['Each marked object earns {v} points and each unmarked object earns {w} points.', 'Score {v} for each marked object and {w} for each unmarked object.', 'The per-object scores are {v} when marked and {w} when unmarked.']], ['What is the expected total score?', 'Find the expectation of the sample score.', 'Determine the mean total points.'], lambda r: dict(r=r.randint(5, 25), b=r.randint(5, 25), n=r.randint(3, 8), v=r.randint(4, 15), w=r.randint(1, 3)), [('expected_marked', 'n*r/(r+b)'), ('answer', 'v*expected_marked+w*(n-expected_marked)')], level='medium', depth=3) add('ordered_colors', [['A bag has {r} red and {b} blue balls; draw three balls uniformly in order, without replacement.', 'Three uniform sequential draws without replacement are made from {r} red and {b} blue balls.', 'Starting with {r} red balls and {b} blue balls, take three random balls one after another without replacement.']], ['What is the probability of the exact color order red, blue, red?', 'Find the chance of red followed by blue followed by red.', 'Determine the probability that the first and third are red and the second is blue.'], lambda r: dict(r=r.randint(3, 60), b=r.randint(3, 60)), [('first', 'r/(r+b)'), ('second', 'b/(r+b-1)'), ('answer', 'first*second*(r-1)/(r+b-2)')], level='medium', depth=3) add('random_subset_parity', [['An integer is chosen uniformly from 1 through {n}.', 'Select one of the integers 1, 2, ..., {n}, with equal probabilities.', 'The sample space is the integers from 1 to {n}, all equally likely.'], ['The divisors of interest are {a} and {b}.', 'Use divisibility by {a} and by {b}.', 'Consider the two divisibility conditions, by {a} and by {b}.']], ['What is the probability that exactly one of these divisibility conditions holds?', 'Find the chance of divisibility by one, but not both, of the stated divisors.', 'Determine the probability of satisfying precisely one of these two conditions.'], lambda r: dict(n=r.randint(50, 400), a=r.randint(2, 12), b=r.randint(13, 25)), [('both', 'floor(n/lcm(a,b))'), ('answer', '(floor(n/a)+floor(n/b)-2*both)/n')], level='easy', depth=3)