Search code examples
logic-programmingpydatalog

Why does creating a relationship in pyDatalog seem to give me the wrong answer?


I'm new to the concepts of Datalog, and I am exploring it through pyDatalog. I am experimenting with a unit measurement converter. So, given facts about how many inches there are in a meter, for example, it should be able to tell me how many meters there are in an inch. Here is my code so far:

from pyDatalog import pyDatalog
from pyDatalog.pyDatalog import create_terms as cterms

pyDatalog.create_terms('scale') # the long way of doing it
cterms('A, B, V')
scale['meter', 'inch'] = 39.3707787
scale[A, B] = 1/ scale[B, A]    
print(scale['inch', 'meter'] == V)

Wny doesn't the program convert inches to meters correctly? It should see that there are 39.37 inches in a meter, and apply the reciprocal rule to convert the other way. So it should print out 0.0234, but it actually prints out

V
----------
39.3707787

Solution

  • It's a bug. Correction is now done in changeset b1a5df9, and will be available in the next release. In the meantime, you may want to apply the changeset on your system.