/* Dice 6 throws in Picat. http://cplint.eu/example/inference/dice.swinb """ A six-sided die is repeatedly thrown until the outcome is six. on(T,F) means that on the Tth throw the face F came out. """ What is the probability that the die lands on face 1 at time 0? This is an alternative version compared to ppl_dice_6_throws.pi using a simple while loop instead of recursion. (There is a Gamble model named ppl_dice_6_throws2.pi but this current model is not a very faithful port of that). 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. /* var : len Probabilities: 1: 0.1705000000000000 2: 0.1358000000000000 3: 0.1123000000000000 4: 0.0953000000000000 5: 0.0783000000000000 6: 0.0684000000000000 7: 0.0587000000000000 8: 0.0467000000000000 9: 0.0373000000000000 10: 0.0320000000000000 11: 0.0306000000000000 12: 0.0224000000000000 13: 0.0200000000000000 14: 0.0164000000000000 15: 0.0123000000000000 17: 0.0101000000000000 16: 0.0091000000000000 18: 0.0071000000000000 19: 0.0054000000000000 20: 0.0053000000000000 21: 0.0041000000000000 23: 0.0034000000000000 22: 0.0028000000000000 24: 0.0026000000000000 26: 0.0024000000000000 25: 0.0019000000000000 27: 0.0016000000000000 28: 0.0009000000000000 34: 0.0008000000000000 30: 0.0008000000000000 29: 0.0007000000000000 31: 0.0006000000000000 32: 0.0005000000000000 35: 0.0004000000000000 40: 0.0003000000000000 38: 0.0003000000000000 50: 0.0002000000000000 46: 0.0002000000000000 43: 0.0002000000000000 37: 0.0002000000000000 36: 0.0002000000000000 33: 0.0002000000000000 69: 0.0001000000000000 56: 0.0001000000000000 55: 0.0001000000000000 45: 0.0001000000000000 44: 0.0001000000000000 42: 0.0001000000000000 39: 0.0001000000000000 mean = 6.0296 var : p = 1 Probabilities: true: 1.0000000000000000 mean = [true = 1.0] var : throw 1 = 1 Probabilities: false: 0.8386000000000000 true: 0.1614000000000000 mean = [false = 0.8386,true = 0.1614] var : throw 2 = 1 Probabilities: false: 0.8622000000000000 true: 0.1378000000000000 mean = [false = 0.8622,true = 0.1378] var : throw 3 = 1 Probabilities: false: 0.8790000000000000 true: 0.1210000000000000 mean = [false = 0.879,true = 0.121] */ go ?=> reset_store, run_model(10_000,$model,[show_probs,mean % , % show_percentiles,show_histogram, % show_hpd_intervals,hpd_intervals=[0.94], % min_accepted_samples=1000,show_accepted_samples=true ]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => Until6 = false, Throws = [], while (Until6 == false) D = dice(), Throws := Throws ++ [D], if D == 6 then Until6 := true end, end, Len = Throws.len, P = check(Throws.last == 6), On_1_1 = check(Throws[1] == 1), % Note: we can not use cond/3 here since Picat % then complain if then length is 1. if Len >= 2 then On_2_1 = check(Throws[2] == 1) else On_2_1 = false end, if Len >= 3 then On_3_1 = check(Throws[3] == 1) else On_3_1 = false end, add("len",Len), add("p = 1",P), add("throw 1 = 1",On_1_1), add("throw 2 = 1",On_2_1), add("throw 3 = 1",On_3_1).