根据该手册,除其他外,time(+Goal)
执行Goal
并打印所使用的逻辑推理的数量。
如何将逻辑推理的数量绑定到变量?
以下代码特定于SWI-Prolog。当前,许多其他Prolog不允许计算推断的数量,主要是由于许多不同的优化会使该数量模糊。
:- meta_predicate(call_inferences(0, -)).
call_inferences(Goal_0, Inferences) :-
statistics(inferences, I0),
Goal_0,
statistics(inferences, I1),
Inferences is I1-I0-1.
用法:
?- call_inferences(true,N).
N = 1.
?- call_inferences(nreverse([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30],L), N).
L = [30, 29, 28, 27, 26, 25, 24, 23, 22|...],
N = 496.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句