1/*
    2Throwing a coin with uncertainty on its fairness, from
    3J. Vennekens, S. Verbaeten, and M. Bruynooghe. Logic programs with annotated
    4disjunctions. In International Conference on Logic Programming,
    5volume 3131 of LNCS, pages 195-209. Springer, 2004.
    6*/
    7:- use_module(library(viterbi)).    8
    9:- if(current_predicate(use_rendering/1)).   10:- use_rendering(c3).   11:- use_rendering(graphviz).   12:- use_rendering(table,[header(['Multivalued variable index','Rule index','Grounding substitution'])]).   13:- endif.   14
   15:- viterbi.   16
   17:- begin_lpad.   18
   19heads(Coin): 1/2; tails(Coin) : 1/2:-toss(Coin),\+biased(Coin).
   20% if we toss a Coin that is not biased then it lands heads with probability 1/2
   21% and tails with probability 1/2
   22heads(Coin): 0.6 ; tails(Coin) : 0.4:-toss(Coin),biased(Coin).
   23% if we toss a Coin that is biased then it lands heads with probability 0.6
   24% % and tails with probability 0.4
   25fair(Coin):0.9 ; biased(Coin):0.1.
   26% a Coin is fair with probability 0.9 and biased with probability 0.1
   27toss(coin).
   28% coin is certainly tossed
   29
   30:- end_lpad.

?- viterbi(heads(coin),Prob,Exp).

*/