/* False coin in Picat. Inspired by Peter Winkler in From Celebration of Mind (Gathering For Gardner): "CoM Apr 2021 - Drawing from Urns - Peter Winkler" https://www.youtube.com/watch?v=A0GxvYPTKDk&list=PL5_D5QQxvWKVtX4Vklvhsf5KTYZBLDSwO&index=3 Note: This is not what Peter talked about, but what I - wrongly - remembered. See ppl_false_coin2.pi for this. * We have one fake and one proper coin: 1. head, head 2. head, tail * We take one coin randomly and flip it: it's a head * To identify the fake coin, is it better to flip the same coin or flip the other coin? According to this model, it's better to throw the same coin again, i.e. coinB_switchIsFake: 1/3 vs coinB_sameIsFake: 2/3 Cf my Gamble model gamble_false_coin.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 : coinA Probabilities: 1: 0.6615405188553090 2: 0.3384594811446911 mean = 1.33846 variance = 0.223905 var : sideA Probabilities: head: 1.0000000000000000 mean = [head = 1.0] variance = data is not numeric var : coin B switch Probabilities: 2: 0.6615405188553090 1: 0.3384594811446911 mean = 1.66154 variance = 0.223905 var : side B switch Probabilities: head: 0.6660871890879915 tail: 0.3339128109120086 mean = [head = 0.666087,tail = 0.333913] variance = data is not numeric var : coin B same Probabilities: 1: 0.6615405188553090 2: 0.3384594811446911 mean = 1.33846 variance = 0.223905 var : side B same Probabilities: head: 0.8303022198448783 tail: 0.1696977801551217 mean = [head = 0.830302,tail = 0.169698] variance = data is not numeric var : coin B = switch coin Probabilities: 0: 0.6615405188553090 1: 0.3384594811446911 mean = 0.338459 variance = 0.223905 var : coin B = same coin Probabilities: 1: 0.6615405188553090 0: 0.3384594811446911 mean = 0.661541 variance = 0.223905 */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,mean,variance]), nl, % show_store_lengths, % fail, nl. go => true. flip_coin(C) = cond(C, categorical([1,0],[head,tail]), categorical([1/2,1/2],[head,tail])). model() => % The two coins Coin1 = 1, % fake coin: head,head Coin2 = 2, % proper coin: head,tail Coins = [Coin1,Coin2], % 1. Pick a coin randomly and flip it. It's head. CoinA = uniform_draw(Coins), SideA = flip_coin(CoinA == Coin1), % ??? % We observe that the first flip was a head. observe(SideA == head), % 2a: Take the other coin and flip it. CoinBSwitch = cond(CoinA == Coin1, Coin2, Coin1), SideBSwitch = flip_coin(CoinBSwitch == Coin1), % 2b: Take the same coin and flip it. CoinBSame = CoinA, SideBSame = flip_coin(CoinBSame == Coin1), if observed_ok then add("coinA",CoinA), add("sideA",SideA), add("coin B switch",CoinBSwitch), add("side B switch",SideBSwitch), add("coin B same",CoinBSame), add("side B same",SideBSame), % Probability of fake coin add("coin B = switch coin",cond(CoinBSwitch == Coin1,1,0)), add("coin B = same coin",cond(CoinBSame == Coin1,1,0)), end.