/* Bertrands paradox in Picat. From https://towardsdatascience.com/five-paradoxes-with-probabilities-that-will-puzzle-you-2f71201d6ee8 """ 3. Bertrand's Box Paradox If you are familiar with the Monty Hall problem, this paradox is quite similar. In front of us there are three boxes: [image of three boxes] One box contains two silver coins, one box contains two gold coins and one box contains a gold- and a silver coin. We do not know which coins are in which box. Now, we pick a random box and blindly draw a coin from our box. It’s a gold coin! Now, the question is: What’s the probability that the second coin in our box is also a gold coin? My naive (and wrong) answer when encountering the problem for the first time was ½. I thought that because we drew a gold coin, our box is either the one with the two gold coins or the one with the mixed coins. In the first case, we would draw another gold coin and in the second case, we wouldn’t. Therefore, I presumed the probability should be ½. The real probability is ⅔. The reason for that is that the first gold coin we drew could either be the only gold coin in the mixed box, the first gold coin in the solely golden box, or the second gold coin in the solely golden box. And in two of these three possibilities, we will draw another gold coin. """ Here we define the boxes as: - box1: 2 gold coins - box2: 1 gold and 1 silver coin - box3: 2 silver coins Cf my Gamble model gamble_bertrands_paradox.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. /* var : coin1 Probabilities: gold: 1.0000000000000000 mean = [gold = 1.0] var : coin2 Probabilities: gold: 0.6587543112193143 silver: 0.3412456887806857 mean = [gold = 0.658754,silver = 0.341246] var : box Probabilities: b1: 0.6587543112193143 b2: 0.3412456887806857 mean = [b1 = 0.658754,b2 = 0.341246] */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,mean]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => % There are 3 boxes Boxes = [b1,b2,b3], % We pick a box randomly Box = uniform_draw(Boxes), Coins = [gold, silver], % We pick a coin from the selected box Coin1 = cases([ [Box == b1, categorical([1,0],Coins)], [Box == b2, categorical([1/2,1/2],Coins)], [Box == b3, categorical([0,1],Coins)]]), % We observe that it's a gold coin observe(Coin1 == gold), % What is the probabiity the the second coin from the same box % is also a gold coin Coin2 = cases([ [Box == b1, categorical([1,0],Coins)], [Box == b2, categorical([0,1],Coins)], [Box == b3, categorical([0,1],Coins)]]), if observed_ok then add("coin1",Coin1), add("coin2",Coin2), add("box",Box), end.