/* Ratio between 1 and 2 in Picat. From Pascal Bercker: 1 < Ratio of A to B < 2 …? Reply to BL https://medium.com/@pbercker/1-ratio-of-a-to-b-2-reply-to-bl-bde967735a9f """ A and B are two points chosen at random between 0 & 1. What is the probability that the ratio A/B lies between 1 & 2? """ BL's post: "An Interesting Geometry Puzzle In Disguised - How would you unscramble this probability challenge?": https://medium.com/math-games/an-interesting-geometry-puzzle-in-disguised-6e391617557e This is the same problem as ppl_random_ratio.pi (from BrainStellar), which see. Pascal added this: """ What are the most probable values for A and B if the ratio is indeed in the specified range? What will be the updated probability that A > B, given that the ratio is in that range? """ 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, ppl_common_utils. import util. % import ordset. main => go. /* */ go ?=> reset_store, run_model(30_000,$model,[show_probs_trunc,mean, show_hpd_intervals,hpd_intervals=[0.84,0.9,0.94,0.99,0.99999], show_histogram ]), Store = get_store(), A = Store.get("a"), B = Store.get("b"), [A,B].transpose.show_scatter_plot, nl, show_store_lengths,nl, % fail, nl. go => true. model() => A = uniform(0,1), B = uniform(0,1), Ratio = A/B, observe( (Ratio>= 1, Ratio<=2)), if observed_ok then add("a",A), add("b",B), add("ratio",Ratio), end.