/* Pirhana puzzle in Picat. (From Tijms 2004) http://cs.ioc.ee/ewscs/2020/katoen/katoen-slides-lecture1.pdf """ One fish is contained within the confines of an opaque fishbowl. The fish is equally likely to be a piranha or a goldfish. A sushi lover throws a piranha into the fish bowl alongside the other fish. Then, immediately, before either fish can devour the other, one of the fish is blindly removed from the fishbowl. The fish that has been removed from the bowl turns out to be a piranha. What is the probability that the fish that was originaly in the bowl by itself was a piranha? The Piranha Puzzle Program f1 := gf (0.5) f1 := pir; f2 := pir; s := f1 (0.5) s := f2; observe(s = pir) E(f1 = pir | P terminates) = 1/2 / 3/4 = 2/3 """ Cf my Gamble model gamble_pirhana_puzzle.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 : f1 Probabilities: piranha: 0.6668898112197081 goldfish: 0.3331101887802919 mean = [piranha = 0.66689,goldfish = 0.33311] var : f1 == piranha Probabilities: true: 0.6668898112197081 false: 0.3331101887802919 mean = [true = 0.66689,false = 0.33311] var : f2 Probabilities: piranha: 1.0000000000000000 mean = [piranha = 1.0] var : s Probabilities: piranha: 1.0000000000000000 mean = [piranha = 1.0] */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,mean]), nl, % show_store_lengths, % fail, nl. go => true. model() => F1 = categorical([1/2,1/2],[goldfish, piranha]), F2 = piranha, S = categorical([1/2,1/2],[F1,F2]), observe(S == piranha), if observed_ok then add("f1",F1), add("f2",F2), add("s",S), add("f1 == piranha",check(F1 == piranha)) end.