/* Bag of marbles in Picat. From https://x.com/madeofmistak3/status/1818764350724944062 """ I have a question. Exactly 1/5th of the people in a town have Beaver Fever . There are two tests for Beaver Fever, TEST1 and TEST2. When a person goes to a doctor to test for Beaver Fever, with probability 2/3 the doctor conducts TEST1 on him and with probability 1/3 the doctor conducts TEST2 on him. When TEST1 is done on a person, the outcome is as follows: If the person has the disease, the result is positive with probability 3/4. If the person does not have the disease, the result is positive with probability 1/4. When TEST2 is done on a person, the outcome is as follows: If the person has the disease, the result is positive with probability 1. If the person does not have the disease, the result is positive with probability 1/2. A person is picked uniformly at random from the town and is sent to a doctor to test for Beaver Fever. The result comes out positive. What is the probability that the person has the disease? """ The problem is from http://allendowney.blogspot.com/2017/02/a-nice-bayes-theorem-problem-medical.html Enumerate (exact) from my Gamble model gamble_beaver_fever.rkt: (#f : 8/13 (0.6153846153846154)) (#t : 5/13 (0.38461538461538464)) This is a port of my Gamble model gamble_beaver_fever.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. main => go. /* This model: Probabilities: false: 0.6478903239548438 true: 0.3521096760451562 */ go ?=> reset_store, run_model(20_000,$model,[show_probs]), nl. go => true. model() => Sick = flip(1/5), Positive = cond( flip(1/3) == true, cond(Sick, flip(3/4), flip(1/4)), % Test 1 cond(Sick, true, flip(1/2))), % Test 2 observe(Positive), if observed_ok then add("sick",Sick) end.