I had written a program in Prolog and I want to reproduce the results in python using pyDatalog. Below is a snippet of my program.
To give an overview of my problem, I have the nodes('a','b','c' and 'd') connected by arrows ('w1,'w2','w3', and 'w4').
I want to generate a list of the arrows connecting any two nodes I specify. The methodology I used in this is almost identical to the one I used in Prolog but it never finishes executing when I run it so I wonder if I am invoking infinite recursions. I would greatly appreciate any help and I have included my working Prolog program at the end.
from pyDatalog import pyDatalog
pyDatalog.create_terms('A, B, C, O, X')
pyDatalog.create_terms('con, this_c')
+con('w1','a','c')
+con('w2','c','b')
+con('w3','b','d')
+con('w4','d','a')
this_c(O, A, B) <= con(O, A, B)
this_c(O, A, B) <= con(X, A, C) & this_c(O, C, B)
print(this_c(O, 'a', 'b'))
My code in prolog is as follows.
con('w1',a,c).
con('w2',c,b).
con('w3',b,d).
con('w4',d,a).
up('w1').
up('w3').
down('w2').
down('w4').
check(X,Y):-up(X),atom_concat('+', X, Y).
check(X,Y):-down(X),atom_concat('-', X, Y).
comb(Output,Input,A,B):- con(X,A,B), check(X,Y), append([Y],Input,Output).
comb(Output,Input,A,B):- comb(Out,Input,A,C),con(X,C,B), check(X,Y), append([Y],Out,Output).
If I query comb(O,[],a,b)
the output is O = ['-w2', '+w1']