8:- use_module(library(mcintyre)). 9
10:- if(current_predicate(use_rendering/1)). 11:- use_rendering(c3). 12:- endif. 13
14:- mc. 15
16:- set_mc(prism_memoization, true). 17
18:- begin_lpad. 19values(throw(_),[heads,tails]).
20:- set_sw(throw(fair),[0.5,0.5]). 21:- set_sw(throw(biased),[0.6,0.4]). 22values(fairness,[fair,biased]).
23:- set_sw(fairness,[0.9,0.1]). 24
25res(Coin,R):- toss(Coin),fairness(Coin,Fairness),msw(throw(Fairness),R).
26fairness(_Coin,Fairness):-msw(fairness,Fairness).
27toss(coin).
28
29:- end_lpad.
?-
prob(res(coin,heads),Prob)
. % what is the probability that coin lands heads? % expected result 0.51 ?-prob(res(coin,tails),Prob)
. % what is the probability that coin lands tails? % expected result 0.49 ?-prob(res(coin,heads),Prob)
,bar(Prob,C)
. % what is the probability that coin lands heads? % expected result 0.51 ?-prob(res(coin,tails),Prob)
,bar(Prob,C)
. % what is the probability that coin lands tails? % expected result 0.49*/