Reputation: 4681
I don't seem to be able to write (pseudo-code): Print X and Y for all X,Y where X==True and Y==True or Y==False
>>> from pyDatalog import pyDatalog
>>> pyDatalog.create_terms('X,Y')
>>> print((X==True)
X
----
True
>>> print((X==True) & (Y==True))
X | Y
-----|-----
True | True
The goal is to write something like:
>>> print((X==True) & ((Y==True) or (Y==False)))
X | Y
-----|-----
True | True
True | False
Instead, this prints out exactly what the previous command returned.
How can I do this?
Upvotes: 1
Views: 425
Reputation: 11
If it means to go through set of Boolean values for both X and Y, and print the result of X && Y, this should work:
from pyDatalog import pyDatalog
allValues = [True, False]
pyDatalog.create_terms('result, X, Y, R, table')
(result[X, Y] == True) <= (X == True) & (Y == True)
(result[X, Y] == False) <= (X == False)
(result[X, Y] == False) <= (Y == False)
table(X, Y, R) <= (X._in(allValues)) & (Y._in(allValues)) & (R == result[X, Y])
print(table(X, Y, R))
This is the output:
X | Y | R
------|-------|------
False | True | False
False | False | False
True | True | True
True | False | False
Upvotes: 1
Reputation:
I'm still somewhat new to pyDatalog, but my understanding is that disjunctions should be split into multiple lines. So your code would be come (the admittedly somewhat unenlightening):
from pyDatalog import pyDatalog
pyDatalog.create_terms('X,Y')
print(((X==True) & ((Y==True))))
print(((X==True) & ((Y==False))))
Upvotes: 1