pyDatalog icon indicating copy to clipboard operation
pyDatalog copied to clipboard

Negation of conjunction does not work

Open cd2bcg16 opened this issue 8 years ago • 4 comments

In 0.17.0 the negation of conjunction does not work. Query

(A==1) & (B==2) & ~((A==1) & (A==1))

should have no solution, however, pyDatalog finds solution [(1,2)].

I have tested negation of an equivalent non-compound term

(A==1) & (B==2) & ~((A==1))

and that indeed results in an empty set.

I have tested this in older releases and I got correct behaviour up to 0.14.6, but not since 0.15.0. I have just upgraded from 0.13 to 0.17 and found this issue.

cd2bcg16 avatar Jul 29 '16 14:07 cd2bcg16

I can confirm. Negations of conjunctions seem to always yield true. Any news concerning this issue?

bernhardwinkel avatar Sep 25 '16 01:09 bernhardwinkel

A workaround is to create a predicate for the clause to be negated :

One(A) <= (A==1) & (A==1)
(A==1) & (B==2) & ~(One(A))

yields the correct empty result.

pcarbonn avatar Sep 25 '16 08:09 pcarbonn

I agree Pierre, the workaround is obvious -- not using negated conjunction. I have patched my pyDatalog and it seems to work. Can you please review and incorporate to the code stream?

--- a/pyDatalog/pyEngine.py
+++ b/pyDatalog/pyEngine.py
@@ -586,8 +586,6 @@ def insert(pred):
     return pred

 def remove(pred):
-    if pred.id in Logic.tl.logic.Pred_registry:
-        del Logic.tl.logic.Pred_registry[pred.id]
     if pred.id in Logic.tl.logic.Db:
         del Logic.tl.logic.Db[pred.id]
     return pred

cd2bcg16 avatar Sep 26 '16 03:09 cd2bcg16

If I applied your patch correctly, it fixes this issue, but the regression tests fail (test.py fails in the reset function, line 6). Predicates cannot be correctly reset anymore.

Could you double-check ?

One approach would be to find out which commit introduced the regression, between 0.14.6, and 0.15.0.

pcarbonn avatar Sep 26 '16 13:09 pcarbonn