/* Break a stick in two in Picat. From Julia Simon "Resample Stats", page 42: """ In a book of puzzles about probability (Mosteller, 1965/1987,#42), this problem appears: "If a stick is broken in two at random, what is the average length of the smaller piece?" ... Yet a rephrasing of the problem reveals its tie to the concept of probability, to wit: What is the probability that the smaller piece will be (say) more than half the length of the larger piece? Or, what is the probability distribution of the sizes of the shorter piece? """ Cf my Gamble model gamble_break_a_stick_in_two.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. /* var : min U Probabilities (truncated): 0.49998813006095: 0.0001000000000000 0.499913797946607: 0.0001000000000000 0.499899011338083: 0.0001000000000000 0.499874599045084: 0.0001000000000000 ......... 0.00018374715009: 0.0001000000000000 0.000179820228452: 0.0001000000000000 0.000074018258636: 0.0001000000000000 0.000052016228462: 0.0001000000000000 mean = 0.25227 HPD intervals: HPD interval (0.84): 0.08265175068874..0.49908960727001 var : p Probabilities: false: 0.6602000000000000 true: 0.3398000000000000 mean = [false = 0.6602,true = 0.3398] 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.84]]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => % Let's assume that the stick is 1 unit long U1 = uniform(0,1), U2 = 1 - U1, MinU = min(U1,U2), MaxU = max(U1,U2), % What is the probability that the smaller piece will be (say) more than % half the length of the larger piece? P = check(MinU > (MaxU / 2)), add("min U",MinU), add("p",P).