0

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
Anderson Green
  • 30,230
  • 67
  • 195
  • 328
blippy
  • 1,490
  • 1
  • 13
  • 22
  • Probably a better tag would help people find this question. It seems to have no relation to logic-programming, but to Python. – Gábor Bakos Sep 13 '14 at 11:20
  • 2
    I disagree. The Support & Community page at [link](https://sites.google.com/site/pydatalog/support) states: "Please post questions on the use of pyDatalog on StackOverflow (make sure to add the logic-programming tag at the bottom of the form)." – blippy Sep 13 '14 at 11:30
  • Sorry, I was not aware of that. Thanks for the correction. – Gábor Bakos Sep 13 '14 at 12:02

1 Answers1

1

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.

Pierre Carbonnelle
  • 2,305
  • 19
  • 25
  • Excellent. Thank you. I can confirm that the fix is correct. I was then able to extend my program to say scale['mile', 'inch'] = 63360.0, and scale[A,B] = scale[A,C] * scale[C,B]. Thereupon, the program was automatically able to deduce the number of meters in a mile. Very neat. Datalog rocks! – blippy Sep 13 '14 at 22:45
  • Thanks. I'm glad you like it. – Pierre Carbonnelle Sep 14 '14 at 09:47
  • I managed to complete my unit conversion program, and wrote a [blog article](http://mcturra2000.wordpress.com/2014/09/14/logic-programming-example-unit-conversion-using-datalog/) about it. I think it should get people fired up about how logic programming can perform computations more easily than if one had to hand-code solutions. – blippy Sep 14 '14 at 12:23
  • Thanks. I entered an entry on Reddit Python to link to your blog. – Pierre Carbonnelle Sep 15 '14 at 10:30