pyswip
pyswip copied to clipboard
table not supported?
Tabling was introduced in SWI 8. It doesn't seem possible to make use of it except through consult:
prolog = Prolog()
if 1:
prolog.consult("fib.pl")
else:
prolog.assertz(":- table fib2/2")
prolog.assertz("fib2(0, 1) :- !")
prolog.assertz("fib2(1, 1) :- !")
prolog.assertz("fib(N, F) :- N > 1, N1 is N-1, N2 is N-2, fib(N1, F1), fib(N2, F2), F is F1+F2")
t = time.time()
print(list(prolog.query("fib2(35, F)"))[0]["F"])
print(f"{time.time()-t} seconds") # 3.3s without tabling / 0.00075864s with
The non-consult path takes 3.3 seconds (tabling not activated).
Tabling requires swi-prolog >= 8.x.x. Support pyswip support for 8.x.x is in PR: https://github.com/yuce/pyswip/pull/93