pyDatalog
pyDatalog copied to clipboard
Negation of conjunction does not work
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.
I can confirm. Negations of conjunctions seem to always yield true. Any news concerning this issue?
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.
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
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.