/* Urn puzzle in Picat. From Berlin Bayesians https://app.slack.com/client/TFPMSKW3F/CFQHMRD6K/thread/CFQHMRD6K-1623812230.000500 """ Three urns, first blindly take one from the first and put in the second, then blindly take one from the second and put in the third and then blindly pick one from the third. How likely is it to pick a black one in the last step? ( Urns 1: white black black 2: white white black 3: white black ) """ Cf my Gamble model gamble_urn_puzzle.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 : b all is black Probabilities: false: 0.5288000000000000 true: 0.4712000000000000 mean = [false = 0.5288,true = 0.4712] var : ball Probabilities: white: 0.5288000000000000 black: 0.4712000000000000 mean = [white = 0.5288,black = 0.4712] var : urn2b Probabilities: [white,white,black,black]: 0.6713000000000000 [white,white,black,white]: 0.3287000000000000 mean = [[white,white,black,black] = 0.6713,[white,white,black,white] = 0.3287] var : urn3b Probabilities: [white,black,white]: 0.5864000000000000 [white,black,black]: 0.4136000000000000 mean = [[white,black,white] = 0.5864,[white,black,black] = 0.4136] */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,mean]), nl, % show_store_lengths, % fail, nl. go => true. model() => Urn1 = [white,black,black], Urn2 = [white,white,black], Urn3 = [white,black], % From Urn 1 to Urn 2 Urn2b = Urn2 ++ [uniform_draw(Urn1)], % From Urn 2 to Urn 3 Urn3b = Urn3 ++ [uniform_draw(Urn2b)], % Pick a random ball from Urn3b Ball = uniform_draw(Urn3b), add("urn2b",Urn2b), add("urn3b",Urn3b), add("ball",Ball), add("b all is black",check(Ball == black)).