0

I am new to prolog, and I was trying to write rules for shortest path finding, I tried many times writing rules like path(X, Y) := ... and they never work as intented, until I find these rules

(path[X,Y]==P) <= ((path[X,Z]==P2) & nextTo(Z,Y) 
                        & (X!=Y) & (X._not_in(P2)) & (Y._not_in(P2)) 
                        & (P==P2+[Z])) 
(path[X,Y]==P) <= nextTo(X,Y) & (P==[]) 

and it works like a charm. The tool is pydatalog.

The rules are very similar with what I have been trying (of course there are other mistakes in my code), but I was keep using round bracket path(X, Y) := .... I have never seen terms followed with square brackets like (path[X,Y]==P) <= ... before, is path[X,Y] a relation? a function? or a term? I googled but coundn't find satisfying answers.

false
  • 10,264
  • 13
  • 101
  • 209
  • In SWI Prolog `?- write_canonical(test[X,Y]).` gives `[]([_,_],test)`. It appears to be a compound term, with functor `[]` with arity 2, aka `[]/2` with arguments X and Y. I don't understand why it's parsed that way. Datalog may well be different. – TessellatingHeckler May 26 '22 at 12:19
  • It seems like it is syntax defined by pyDatalog (rather than other prolog), and it is a function in pyDatalog, and in pyDatalog, round parences are used to define a literal... correct me if I am wrong. – QianruZhou Jun 15 '22 at 15:46

0 Answers0