Datalog: Why does (X==False) & (Y==not(X)) not evaluate?

319 Views Asked by At

I'm using pyDatalog (in Python 2.7). Using an arithmetic function like +, I can refer to an earlier bound variable:

>>> (X==1) & (Y==X+1)
[(1, 2)]

But I cannot use the boolean not operator the same way:

>>> not(False)
True
>>> (X==False) & (Y==not(X))
  File "<stdin>", line 1
    (X==False) & (Y==not(X))
                       ^
SyntaxError: invalid syntax
>>> 
2

There are 2 best solutions below

3
galaxyan On

it is operator precedence in Python

(Y == (not(X))

or

(Y == not X)
2
Pierre Carbonnelle On

You could use a custom resolver :

from pyDatalog import pyDatalog

@pyDatalog.predicate()
def not_2(X,Y):
    if X.is_const():
        yield (X.id, not(X.id))
    elif Y.is_const():
        yield (not(Y.id), Y.id)

@pyDatalog.program()
def _():
    print ((X==False) & (not_(X,Y)))