/* Lottery in Picat. From Mathematica (BernoulliDistribution) """ A lottery sells 10 tickets for $1 per ticket. Each time there is only one winning ticket. A gambler has $5 to spend. Find his probability of winning if he buys 5 tickets in 5 different lotteries: D = ProductDistribution((BernoulliDistribution(1/10), 5)); Probability(1 <= x + y + u + v + w, (x, y, u, v, w) -> D) -> 40951/100000 (0.40951) His probability of winning is greater if he buys 5 tickets in the same lottery: PDF(HypergeometricDistribution(5, 1, 10), 1) -> 1/2 """ Cf my Gamble model gamble_lottery.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 : p different lottieries Probabilities: false: 0.5907000000000000 true: 0.4093000000000000 mean = [false = 0.5907,true = 0.4093] var : p same lottery Probabilities: 0: 0.5092000000000000 1: 0.4908000000000000 mean = 0.4908 var : p same lottery1 Probabilities: 1: 0.5083000000000000 0: 0.4917000000000000 mean = 0.5083 Picat> X = hypergeometric_dist_pdf(5,1,10,1) X = 0.500000000000004 */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,mean % , % show_percentiles, % show_hpd_intervals,hpd_intervals=[0.94], % show_histogram, % min_accepted_samples=1000,show_accepted_samples=true ]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => N = 5, Win = bern_n(1/10,N), PDifferentLotteries = check(1 <= Win.sum), PSameLottery = hypergeometric_dist(5,1,10), % Mathematica compliant parameters PSameLottery1 = hypergeometric1_dist(1,10,1,5), add("p different lottieries",PDifferentLotteries), add("p same lottery",PSameLottery), add("p same lottery1",PSameLottery1).