Skip to content

The grounded program is still cyclic after executing "problog ground --break-cycles" #125

@werifu

Description

@werifu

Example 4 in the tutorial:
https://dtai.cs.kuleuven.be/problog/tutorial/various/08_bayesian_dataflow.html

% toss both coins for the first time
0.5::c1(0).
0.5::c2(0).

% keep tossing if none was heads
0.5::c1(T) :- T > 0, TT is T-1, \+ or_c1_c2(TT).
0.5::c2(T) :- T > 0, TT is T-1, \+ or_c1_c2(TT).
or_c1_c2(T) :- c1(T).
or_c1_c2(T) :- c2(T).

% return
return(T,1,1) :- or_c1_c2(T), c1(T), c2(T).
return(T,1,0) :- or_c1_c2(T), c1(T), \+ c2(T).
return(T,0,1) :- or_c1_c2(T), \+ c1(T), c2(T).
return(T,0,0) :- or_c1_c2(T),\+c1(T),\+c2(T).

query(return(T,_,_)) :- between(0,2,T).

In the original example, the last line is query(return(T,_,_)) :- between(0,5,T)., but query(return(T,_,_)) :- between(0,2,T). is a smaller case to reproduce this.
After grounded, the output code is as below:

0.5::c1(1) :- \+aux_0.
0.5::c2(1) :- \+aux_0.
0.5::c1(2) :- \+aux_0.
0.5::c2(2) :- \+aux_0.
0.5::c1(0).
0.5::c2(0).
or_c1_c2(0) :- c1(0).
or_c1_c2(0) :- c2(0).
return(0,1,1) :- or_c1_c2(0), c1(0), c2(0).
aux_1 :- c2(0).
return(0,1,0) :- or_c1_c2(0), c1(0), \+aux_1.
return(0,0,1) :- or_c1_c2(0), \+c1(0), c2(0).
aux_-1 :- c2(0).
return(0,0,0) :- or_c1_c2(0), \+c1(0), \+aux_-1.
aux_0 :- or_c1_c2(0).
aux_0 :- or_c1_c2(0).
or_c1_c2(1) :- c1(1).
or_c1_c2(1) :- c2(1).
return(1,1,1) :- or_c1_c2(1), c1(1), c2(1).
aux_17 :- c2(1).
return(1,1,0) :- or_c1_c2(1), c1(1), \+aux_17.
return(1,0,1) :- or_c1_c2(1), \+c1(1), c2(1).
aux_-17 :- c2(1).
return(1,0,0) :- or_c1_c2(1), \+c1(1), \+aux_-17.
aux_0 :- or_c1_c2(1).
aux_0 :- or_c1_c2(1).
or_c1_c2(2) :- c1(2).
or_c1_c2(2) :- c2(2).
return(2,1,1) :- or_c1_c2(2), c1(2), c2(2).
aux_36 :- c2(2).
return(2,1,0) :- or_c1_c2(2), c1(2), \+aux_36.
return(2,0,1) :- or_c1_c2(2), \+c1(2), c2(2).
aux_-36 :- c2(2).
return(2,0,0) :- or_c1_c2(2), \+c1(2), \+aux_-36.
query(return(0,1,1)).
query(return(0,1,0)).
query(return(0,0,1)).
query(return(0,0,0)).
query(return(1,1,1)).
query(return(1,1,0)).
query(return(1,0,1)).
query(return(1,0,0)).
query(return(2,1,1)).
query(return(2,1,0)).
query(return(2,0,1)).
query(return(2,0,0)).

There are cycles in this grounded file.
e.g.

0.5::c1(1) :- \+aux_0.
...
aux_0 :- or_c1_c2(1).
...
or_c1_c2(1) :- c1(1).
...

c1(1) <- aux_0 <- or_c1_c2(1) <- c1(1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions