log2a.pl

loading
details
attribute value
description
owner Johannes Waldmann
uploaded 2017-08-17 03:45:07.0
disk size 516 Bytes
downloadable true
type
attribute value
name no_type
processor id 1
description this is the default benchmark type for rejected benchmarks and benchmarks that are not associated with a type.
owning community none
loading contents
%query: log2(i,o).
/* author: Michael Codish
   date:    March 2003

 log2(X,Y) :- Y equals the integer log base 2 of X.

 Namely, the largest integer smaller or equal to the 
 log base 2 of X

*/




log2(X,Y) :- log2(X,0,Y).



log2(0,I,I).
log2(s(0),I,I).
log2(s(s(X)),I,Y) :- half(s(s(X)),X1), log2(X1,s(I),Y).


half(0,0).
half(s(0),0).
half(s(s(X)),s(Y)) :- half(X,Y).


/*

    ?- log2(s(s(s(s(s(s(s(s(0)))))))), Y).
    Y = s(s(s(0)))

    ?- log2(s(s(s(s(s(s(s(s(s(s(0)))))))))), Y).
    Y = s(s(s(0)))

*/
popout

content may be truncated. 'popout' for larger text window.

actions get anonymous link download benchmark