/* Four dice in Picat. Port of the WebPPL model https://gist.github.com/usptact/cc6b906aaf3470bda65bd45d6fb6c9d9#file-four_dice-wppl """ 4 dice: 4, 6, 8 and 12 sides each dice is perfect """ There are four perfect dice with 4, 6, 8 and 12 sides respectively. Select one of the four dice at random and roll this dice two times. The outcome of the two rolls are the same. Throw the selected dice a third time. What is the probability of third roll same as the first two? Cf my Gamble model gamble_four_dice.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. % import ordset. main => go. /* * Probability that the third roll is the same as the first two var : sel Probabilities: 4: 0.3988936693300553 6: 0.2569145666871543 8: 0.2065150583896742 12: 0.1376767055931162 mean = 6.4413 var : same Probabilities: false: 0.8260602335586970 true: 0.1739397664413030 mean = [false = 0.82606,true = 0.17394] * Observe that the third roll is the same as the first two var : sel Probabilities: 4: 0.5699658703071673 6: 0.2423208191126280 8: 0.1296928327645051 12: 0.0580204778156997 mean = 5.46758 var : same Probabilities: true: 1.0000000000000000 mean = [true = 1.0] */ go ?=> member(Obs, [false,true]), if Obs == true then println("* Observe that the third roll is the same as the first two") else println("* Probability that the third roll is the same as the first two") end, reset_store, run_model(10_000,$model(Obs),[show_probs_trunc,mean]), nl, % show_store_lengths,nl, fail, nl. go => true. dice(Sel) = categorical(ones(Sel,1),1..Sel). model(Obs) => % Pick one of the four dice Sel = categorical([1/4,1/4,1/4,1/4],[4,6,8,12]), % Roll the picked die twice Roll1 = dice(Sel), Roll2 = dice(Sel), % The two rolls must return the same face observe(Roll1 == Roll2), % Roll the last time Roll3 = dice(Sel), % Prob that the third roll is the same as the first two Same = check( (Roll1 == Roll2, Roll2 == Roll3)), if Obs == true then observe(Roll3 == Roll2) end, if observed_ok then add("sel",Sel), add("same",Same), end.