/* Waiting for a truck in Picat. https://brainstellar.com/puzzles/probability/1005 """ On a given highway, trucks arrive at the station according to a Poisson process with Lambda = 0.1/minute. This means that after a truck is just passed, the time for the next truck to arrive is an exponential random number with average arrival time of 10 minutes. Your car just broke on this highway, and you are waiting for the next truck for hitchhiking, what is your expected waiting time? On average how many minutes ago the last truck left? Solution: Using memoryless property of exponential distribution, the expected waiting time is 10 minutes. This also holds backwards, hence the expected time last truck passed is also 10 minutes. But this does not violate the total inter-arrival time of 10 minutes, because if your car breaks at a random time, you are more likely to be in long interval than a short one. """ Cf my Gamble model gamble_waiting_for_a_truck.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 : t1 Probabilities (truncated): 9: 0.1290000000000000 10: 0.1259000000000000 11: 0.1145000000000000 8: 0.1134000000000000 ......... 1: 0.0004000000000000 23: 0.0002000000000000 25: 0.0001000000000000 24: 0.0001000000000000 mean = 10.0045 var : t2 Probabilities (truncated): 19: 0.0900000000000000 18: 0.0855000000000000 20: 0.0848000000000000 21: 0.0842000000000000 ......... 6: 0.0003000000000000 39: 0.0002000000000000 38: 0.0002000000000000 37: 0.0001000000000000 mean = 20.0379 var : t1,t2 Probabilities (truncated): [9,19]: 0.0193000000000000 [10,18]: 0.0163000000000000 [9,17]: 0.0160000000000000 [9,20]: 0.0156000000000000 ......... [2,8]: 0.0001000000000000 [2,7]: 0.0001000000000000 [1,11]: 0.0001000000000000 [1,10]: 0.0001000000000000 Mean (truncated) mean = [[9,19] = 0.0193,[10,18] = 0.0163,[9,17] = 0.016,[9,20] = 0.0156,[10,20] = 0.0153,[9,18] = 0.0151,[8,17] = 0.0146,[11,22] = 0.0143,[11,21] = 0.014,[10,19] = 0.014,[10,21] = 0.0133,[8,18] = 0.013,[11,20] = 0.0127,[8,19] = 0.0126,[12,21] = 0.0122,[12,22] = 0.0121,[7,16] = 0.0121,[8,16] = 0.0119,[11,23] = 0.0118,[9,21] = 0.0117] var : diff Probabilities (truncated): 10: 0.1295000000000000 9: 0.1208000000000000 8: 0.1149000000000000 11: 0.1146000000000000 ......... 22: 0.0005000000000000 1: 0.0004000000000000 25: 0.0002000000000000 24: 0.0002000000000000 mean = 10.0334 */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,mean]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => Lambda = 1/0.1, T1 = poisson_dist(Lambda), T2 = T1 + poisson_dist(Lambda), Diff = abs(T1-T2), add("t1",T1), add("t2",T2), add("t1,t2",[T1,T2]), add("diff",Diff).