I am trying to understand release 9.1.16 arithmetic.
I didn’t test whether this already happened before
release 9.1.16. I am using this popular test case:
tarai(X, Y, _, R) :- X =< Y, !, R = Y.
tarai(X, Y, Z, R) :- X_1 is X-1, tarai(X_1, Y, Z, R_X),
Y_1 is Y-1, tarai(Y_1, Z, X, R_Y),
Z_1 is Z-1, tarai(Z_1, X, Y, R_Z),
tarai(R_X, R_Y, R_Z, R).
Testing with optimise flag false and true. I get these results:
/* optimise=false */
?- time(tarai(12, 11, 0, X)).
% 54,182,800 inferences, 2.625 CPU in 2.616 seconds (100% CPU, 20641067 Lips)
X = 12.
/* optimise=true */
?- time(tarai(12, 11, 0, X)).
% 27,091,399 inferences, 1.906 CPU in 1.918 seconds (99% CPU, 14211881 Lips)
X = 12.
Interestingly when using vm_list/1
I don’t see a difference. Already
optimise=false
does generate a_add_fc
instruction. But how is the
inference count different between the two? And as a result the LIPS
lower, although optimise=true
is faster and does the same thing?
Edit 27.09.2023
There is also the suspicion that SWI-Prolog LIPS are too low in
general. Maybe the tail recursive call is not counted? For example
this Prolog system reports a different count of inferences, much higher:
$ ./tarai 12 11 0
% 196412655 inferences, 3.34256 CPU seconds (58761215.967661 Lips)
12
Guarded Horn Clauses - tadashi9e, 2023
https://qiita.com/tadashi9e/items/45cef62cda6d38dda0c7
Or the SWI-Prolog approach is the more reasonable one, it might not count
(=<)/2, (!)/0 and (=)/2, which also appears in Tarai? But then how does
optimise=true
influence the counting, when these built-ins are not counted?