ML-KULeuven / problog

ProbLog is a Probabilistic Logic Programming Language for logic programs with probabilities.
https://dtai.cs.kuleuven.be/problog/
317 stars 35 forks source link

Ground for negation is not what I expect? #119

Closed werifu closed 1 month ago

werifu commented 1 month ago

I defined a rule named end_node(X) meaning no out degrees in a graph.

0.4::edge(1,2).
0.6::edge(2,3).
0.3::edge(3,1).
0.9::edge(3,4).
0.5::edge(1,3).

node(X) :- edge(X,_).
node(X) :- edge(_,X).

end_node(X) :- node(X), not edge(X, _).
query(end_node(_)).

After I ran problog ground --format pl -o output input_file, I got:

0.4::edge(1,2).
0.6::edge(2,3).
0.3::edge(3,1).
0.9::edge(3,4).
0.5::edge(1,3).
node(1) :- edge(1,2).
node(1) :- edge(1,3).
node(1) :- edge(3,1).
node(2) :- edge(2,3).
node(2) :- edge(1,2).
node(3) :- edge(3,1).
node(3) :- edge(3,4).
node(3) :- edge(2,3).
node(3) :- edge(1,3).
node(4) :- edge(3,4).
None :- edge(1,2).
None :- edge(1,3).
end_node(1) :- node(1), edge(1,2).
end_node(2) :- node(2), \+edge(2,3).
None :- edge(3,1).
None :- edge(3,4).
end_node(3) :- node(3), edge(3,1).
end_node(4) :- node(4).
query(end_node(1)).
query(end_node(2)).
query(end_node(3)).
query(end_node(4)).

I noticed end_node(1) :- node(1), edge(1,2). and end_node(3) :- node(3), edge(3,1). that are not as what I expect while end_node(2) :- node(2), \+edge(2,3) is in my expectation. What does it happen? I think the correct answer should be end_node(1) :- node(1), \+edge(1,2), \+edge(1,3)

Problog version: 2.2.4

rmanhaeve commented 1 month ago

Hi

Thank you for raising this issue. The Prolog output format is somewhat of a heuristic reconstruction of the formula constructed by the grounding process. I do believe that there is a bug in this case, since some of the rules make no sense.

I have included an image of the ground formula below. Does this make more sense to you?

ground

werifu commented 1 month ago

Thanks for your reply! The image exactly depicts what I want! Do you have any ideas about how is it caused and how to fix it?

rmanhaeve commented 1 month ago

I've written a fix and pushed it to the master branch. It is not pushed to pypi yet, but I'll let you know as soon as that has happened.

rmanhaeve commented 1 month ago

It has been pushed to pypi.