/* Random ratio in Picat. https://brainstellar.com/puzzles/probability/112 """ p and q are two points chosen at random between 0 & 1. What is the probability that the ratio p/q lies between 1 & 2? Answer: 0.25 """ Cf my Gamble model gamble_random_ratio.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 : ratio Probabilities (truncated): 120604.116999928621226: 0.0001000000000000 2964.735349504506758: 0.0001000000000000 1783.696794799288455: 0.0001000000000000 1622.089267188111762: 0.0001000000000000 ......... 0.000609779562723: 0.0001000000000000 0.000542087201848: 0.0001000000000000 0.000344019189895: 0.0001000000000000 0.000330871599078: 0.0001000000000000 mean = 16.6596 HPD intervals: HPD interval (0.94): 0.00033087159908..8.71964436536633 var : prob Probabilities: false: 0.7529000000000000 true: 0.2471000000000000 mean = [false = 0.7529,true = 0.2471] HPD intervals: show_hpd_intervals: data is not numeric */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,mean,show_hpd_intervals, hpd_intervals=[0.94]]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => P = beta_dist(1,1), Q = beta_dist(1,1), Ratio = P / Q, Prob = check( (Ratio >= 1, Ratio <= 2)), add("ratio",Ratio), add("prob",Prob).