scryer-prolog icon indicating copy to clipboard operation
scryer-prolog copied to clipboard

time/1 negative inference

Open flexoron opened this issue 1 year ago • 4 comments

v0.9.3-126-g1e0fa567-modified

$ scryer-prolog -f
?- use_module(library(time)).
   true.
?- time(X = 1).
   % CPU time: 0.000s, -22 inference (exception?)  % Meaning?
   X = 1.
?- time(X = 1).
   % CPU time: 0.000s, 1 inference
   X = 1.
?-

flexoron avatar Dec 31 '23 21:12 flexoron

What is most irritating here is that the result is stateful

UWN avatar Jan 01 '24 09:01 UWN

Another irritation:

$ scryer-prolog -f
?- use_module(library(lists)).
   true.
?- use_module(library(time)).
   true.
?- time((length(L,1), append(L,[_|Y],LT),Y="")).
   % CPU time: 0.000s, -13 inference (exception?)  % This time -13
   L = [_A], Y = [], LT = [_A,_B].
?- halt.

$ scryer-prolog -f
?- use_module(library(time)).
   true.
?- use_module(library(lists)).
   true.
?- time((length(L,100), append(L,[_|Y],LY),Y="")).  % "Excess work" and it is gone
   % CPU time: 0.000s, 86 inferences
   L = [_A,_B,_C,_D,_E,_F,_G,_H,_I,_J,_K,_L,_M,_N,_O,_P,_Q,_R,_S,_T|...], Y = [], LY = [_A,_B,_C,_D,_E,_F,_G,_H,_I,_J,_K,_L,_M,_N,_O,_P,_Q,_R,_S,_T|...].

flexoron avatar Jan 01 '24 14:01 flexoron

And another one:

$ scryer-prolog -f
?- use_module(library(lists)).
   true.
?- use_module(library(time)).
   true.

?- time((length(L,15), append(L,[_|Y],LY),Y="")). % Goes positive but
   % CPU time: 0.000s, 1 inference                % unexpected
: 
?- time((length(L,15), append(L,[_|Y],LY),Y="")).
  % CPU time: 0.000s, 24 inferences               % I guess this result is expected
: 
?- time((length(L,15), append(L,[_|Y],LY),Y="")).
  % CPU time: 0.000s, 24 inferences
: 
?-

Finding: The result of calling time/1 a first time is rendered unusable.

flexoron avatar Jan 01 '24 14:01 flexoron

Related: #2180.

triska avatar Jan 01 '24 22:01 triska