/* How many sons? in Picat. From Ruma Falk: "Understanding Probability and Statistics - A Book of Problems" page 56 """ How many sons? Mrs. F is known to be the mother of two. You meet her in town with a boy whom she introduces as her son. What is the probability that Mrs. F has two sons? One possible is that the probability is 1/2: you now have seen one boy, and there the question is whether the other child is a male. Another possibility is that the probability is 1/3: you learned that Mrs. F has 'at least one boy', and hence three equiprobable family structures are possible (BB, BG, GB), of which the target event (BB) is but one. Which is the correct answer? Explain. (Hint: What are your assuptions about the chance mechanism that yielded your observation of Mrs. F hand her son?) """ This problem (with a slighly different wording) was also in Maya Bar-Hillel & Ruma Falk: "Some teasers concerning conditional probabilities" (Cognition 11, 1982, page 109-122). Here we show these two different approaches: - model1: p(two_sons) = 1/2 - model2: p(two_sons) = 1/3 As commented in the hint (and the comments at page 177), the assumptions regarding the "chance mechanism" - i.e. how we know what - matters. Cf my Gamble model gamble_how_many_sons.rkt This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import ppl_distributions, ppl_utils. import util. main => go. /* Model 1 In this model we know that the "first child" is a son. var : child1 Probabilities: son: 1.0000000000000000 mean = [son = 1.0] var : child2 Probabilities: daughter: 0.5025257627803597 son: 0.4974742372196403 mean = [daughter = 0.502526,son = 0.497474] var : child2 == son? Probabilities: false: 0.5025257627803597 true: 0.4974742372196403 mean = [false = 0.502526,true = 0.497474] */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,mean]), nl, % show_store_lengths, % fail, nl. go => true. model() => G = [son,daughter], [Child1,Child2] = uniform_draw_n(G,2), observe(Child1 == son), if observed_ok then add("child1",Child1), add("child2",Child2), add("child2 == son?",check(Child2 == son)), end. /* In this model we only know that one of the children - but not which of them - is a son. var : children Probabilities: [son,daughter]: 0.3370696557245796 [son,son]: 0.3333333333333333 [daughter,son]: 0.3295970109420870 mean = [[son,daughter] = 0.33707,[son,son] = 0.333333,[daughter,son] = 0.329597] var : num sons Probabilities: 1: 0.6666666666666666 2: 0.3333333333333333 mean = 1.33333 var : num sons == 2 Probabilities: false: 0.6666666666666666 true: 0.3333333333333333 mean = [false = 0.666667,true = 0.333333] */ go2 ?=> reset_store, run_model(10_000,$model2,[show_probs_trunc,mean]), nl, % show_store_lengths, % fail, nl. go2 => true. model2() => G = [son,daughter], % The gender of of two children Children = uniform_draw_n(G,2), % How many of the childrens are sons? NumSons = [cond(C==son,1,0) : C in Children].sum, % We know that at least one of the children is a son observe(NumSons >= 1), if observed_ok then add("num sons",NumSons), add("children",Children), add("num sons == 2",check(NumSons == 2)), end.