Negative Number of Inferences with time/1

Hi,
I’ve read this Prolog question on stackoverflow: https://stackoverflow.com/questions/76615817/exponential-runtime-of-is-2-when-linear-would-suffice

By querying the example program with SWISH, time/1 prints a negative number of inferences.

p(1).
p(X+X) :- p(X).

?- time(p(X)).
-2 inferences, 0.000 CPU in 0.000 seconds (87% CPU, -115433 Lips)
X = 1

How does time/1 works and how inferences are counted?

Thanks

The VM counts inferences for calls and redo to normal Prolog predicates and foreign predicates except for those handled by the VM itself. The counts depend a bit on the running mode (debug, normal, optimized). Redo ports that should be counted in the theoretical model but are removed due to last call optimization are not in the counts. time/1 subtracts some inferences to compensate its overhead. The number subtracted seems a bit too high in this case.

The inference count has some value in the sense that low inferences per second suggest either the use of expensive foreign code (built-ins or user provided) or poor indexing.

Don’t trust the exact numbers :slight_smile: