# Dice A six-sided die is repeatedly thrown until the outcome is six. on(T,F) means that on the =T=th throw the face =F= came out. What is the probability that the die lands on face 1 at time 0?
prob(on(0,1),Prob).
What is the probability that the die lands on face 1 at time 1?
prob(on(1,1),Prob).
What is the probability that the die lands on face 1 at time 2?
prob(on(2,1),Prob).
What is the probability that the die lands on face 1 at time 2 given that it landed on face 1 at time 0?
prob(on(2,1),on(0,1),Prob).
What is the probability that the die lands on face 1 at time 2 given that it landed on face 1 at times 0 and 1?
prob(on(2,1),evidence,Prob).
What is the probability that the die lands on face 1 at time 0 represented graphically?
prob(on(0,1),Prob),bar(Prob,C).
What is the probability that the die lands on face 1 at time 1 represented graphically?
prob(on(1,1),Prob),bar(Prob,C).
What is the probability that the die lands on face 1 at time 2 represented graphically?
prob(on(2,1),Prob),bar(Prob,C).
What is the probability that the die lands on face 1 at time 2 given that it landed on face 1 at time 0 represented graphically?
prob(on(2,1),on(0,1),Prob),bar(Prob,C).
What is the probability that the die lands on face 1 at time 2 given that it landed on face 1 at time 1 represented graphically?
prob(on(2,1),on(1,1),Prob),bar(Prob,C).
What is the BDD for query on(1,1)?
bdd_dot_string(on(1,1),BDD,Var).
A solid edge indicates a 1-child, a dashed edge indicates a 0-child and a dotted edge indicates a negated 0-child. Each level of the BDD is associated to a variable of the form XI_J indicated on the left: I indicates the multivalued variable index and J the index of the Boolean variable of I. The table =Var= contains the associations between the rule groundings and the multivalued variables: the first column contains the multivalued variable index, the second column contains the rule index, corresponding to its position in the program, and the last column contains the list of constants grounding the rule, each replacing a variable in the order of appearance in the rule. ## Code ### Preamble:
:- use_module(library(pita)). :- if(current_predicate(use_rendering/1)). :- use_rendering(c3). :- use_rendering(graphviz). :- use_rendering(table,[header(['Multivalued variable index','Rule index','Grounding substitution'])]). :- endif. :- pita. :- begin_lpad.
on(T,F) means that the die landed on face =F= at time =T=. At time 0 the dice lands on one of its faces with equal probability:
on(0,1):1/6;on(0,2):1/6;on(0,3):1/6; on(0,4):1/6;on(0,5):1/6;on(0,6):1/6.
At time =T= the die lands on one of its faces with equal probability if at the previous time point it was thrown and it did not land on face 6:
on(X,1):1/6;on(X,2):1/6;on(X,3):1/6; on(X,4):1/6;on(X,5):1/6;on(X,6):1/6:- X1 is X-1,X1>=0,on(X1,_), \+ on(X1,6).
Evidence formed by more than one atom must be explicitly represented. For example, if on(0,1) and on(1,1) are evidence, we can define a clause with their conjunction in the body and use the head as the evidence in queries:
evidence:- on(0,1), on(1,1).
### Epilogue:
:- end_lpad.
## References J. Vennekens, S. Verbaeten, and M. Bruynooghe. Logic programs with annotated disjunctions. In International Conference on Logic Programming, volume 3131 of LNCS, pages 195-209. Springer, 2004.