friguzzi / cplint

cplint is a suite of programs for reasoning with probabilistic logic programs
Other
67 stars 14 forks source link

Redundant (and costly) use of call/1 #32

Closed pmoura closed 4 years ago

pmoura commented 4 years ago

In the following line, the use of call/1 is redundant but also expensive:

https://github.com/friguzzi/cplint/blob/242814b87dca800eacccf88657e518175592e82e/prolog/viterbi.pl#L116

An example illustrating the cost:

?- time(true).
% 1 inferences, 0.000 CPU in 0.000 seconds (50% CPU, 200000 Lips)
true.

?- time((between(1,1000000,N), \+ float(N), fail; true)).
% 2,999,999 inferences, 0.085 CPU in 0.085 seconds (100% CPU, 35381936 Lips)
true.

?- time((between(1,1000000,N), call(\+ float(N)), fail; true)).
% 2,999,999 inferences, 0.239 CPU in 0.239 seconds (100% CPU, 12562915 Lips)
true.

Same issue in the same file around line 162. The Logtalk linter reports this issues as:

*     Suspicious call: call(\+A) instead of \+A
*       while compiling object viterbi
*       in file /Users/pmoura/Downloads/cplint-master/prolog/viterbi.pl between lines 114-117
*     
*     Suspicious call: call(\+A) instead of \+A
*       while compiling object viterbi
*       in file /Users/pmoura/Downloads/cplint-master/prolog/viterbi.pl between lines 160-163
friguzzi commented 4 years ago

Thanks, fixed in 78780d0d835aa2eb08a0b533b9f0c7c2edbd02ca