ML-KULeuven / problog

ProbLog is a Probabilistic Logic Programming Language for logic programs with probabilities.

Home Page:https://dtai.cs.kuleuven.be/problog/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unexpected query results on a simple KB with recursive rules.

liu-cs opened this issue · comments

Hi, I am trying to use Problog to build an automatic geometry problem solver. I encountered an unexpected query result for the following simple KB:

is_parallel_to(X, Y) :- 
    X \== Y,
    is_parallel_to(Y, X).

is_parallel_to(X, Y) :- 
    X \== Y,
    is_parallel_to(X, Z),
    is_parallel_to(Y, Z).

is_parallel_to(line1, line2).
is_parallel_to(line1, line3).
query(is_parallel_to(line2, _)).

and the result is:

is_parallel_to(line2,line1):    1         
is_parallel_to(line2,line2):    1         
is_parallel_to(line2,line3):    1   

I couldn't understand how the is_parallel_to(line2,line2): 1 gets into the result as we have X \== Y, in the bodies of both rules.
Can anyone please help to take a look and point out where it goes wrong? Thanks!

-Changsong

Hi Changsong

This is related to the whether the variables are grounded when you compare the check.

Since Y is not ground when comparing to X, the comparison == is true, as it is just a check that they are not identical, which they are not. The unifcation only happens afterwards.
Replace the == by = (meaning X and Y are not unifiable).

Try this code in the editor for comparison (link):

a :- 1 \== Y, Y=1.
b :- 1 \= Y, Y=1.
c :- Y=1, 1 \== Y.
d :- Y=1, 1 \= Y.

query(a).
query(b).
query(c).
query(d).

Hope this helps!

Thanks, Robin. The explanation and example are very clear. Our problog based geometry solver now works well :-)