/* Five coins in Picat. From https://math.stackexchange.com/questions/3633307/bayes-rule-broken """ Bayes' Rule broken?!?! This question has been driving me CRAZY for 4 days now. The question comes from the textbook 'One Thousand Exercises in Probability', specifically Exercise 3 in section 1.4. The solution does not make sense! The question goes as follows: 'A man possesses five coins, two double-headed, two normal and one double-tailed. The man shuts his eyes, picks a coin at random, and tosses the coin. He opens his eyes, sees a head: what is the probability the lower face is also a head?. The book gives an answer that is 2/3 .... """ what is the probability the lower face is also a head?. Exact probabilities from my Gamble model: Output: (head : 2/3 (0.6666666666666666)) (tail : 1/3 (0.3333333333333333)) This is a port of my Racket/Gamble model gamble_five_coins.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. /* What is the probability the lower face is also a head?. var : coin Probabilities: normal-coin: 0.41033333333333333 (1231 / 3000) double-head: 0.38800000000000001 (97 / 250) double-tail: 0.20166666666666666 (121 / 600) var : flip_coin Probabilities: head: 0.65466816647919013 (582 / 889) tail: 0.34533183352080987 (307 / 889) var : toss Probabilities: head: 0.59266666666666667 (889 / 1500) tail: 0.40733333333333333 (611 / 1500) */ go ?=> reset_store, run_model(3_000,$model,[show_probs_rat]), nl. go => true. model() => Coin = categorical([2/5,2/5,1/5],["double-head","normal-coin","double-tail"]), % Toss the coin (first side) Toss = case(Coin,[["double-head","head"], ["double-tail","tail"], [default,categorical([1/2,1/2],["head","tail"])], [true,"xxx"] % checking ]), % Flip the coin (i.e. turn it around), second side FlipCoin = cases([[Coin=="double-head","head"], [Coin=="double-tail","tail"], [Toss=="tail","head"], [Toss=="head","tail"], [true,"xxx"] % checking ]), add("coin",Coin), add("toss",Toss), observe(Toss == "head"), if observed_ok then add("flip_coin",FlipCoin), end.