暮色呼如
这是您以逻辑上纯净的方式找到“二的幂”的方法!使用sicstus-prolog 4.3.5 library(reif)和library(clpz)::-use_module([ library(reif),library(clpz) ])。power_of_two_t(I,T):- L#=分钟(I,1), M#= I / \(I-1), 呼叫((L = 1,M = 0),T)。%使用库(reif)的(=)/ 3和(',')/ 3结合使用元谓词的示例查询1:tfilter/3power_of_two_t/2?- tfilter(power_of_two_t, [0,2,3,-5,-2,1,8,7,4], Ps).Ps = [2,1,8,4]. % succeeds deterministically这是由注释建议的更一般的查询:?- tfilter(power_of_two_t, [X], Ps). Ps = [X], 0#=X/\_A, _A+1#=X, X in 1..sup, _A in 0..sup; Ps = [], dif(_A,0), _A#=X/\_B, _B+1#=X, X in 1..sup, _B in 0..sup; Ps = [], dif(_A,1), _A#=min(X,1), _B#=X/\_C, _C+1#=X, X#>=_A, _A in inf..1.脚注1:整理了上面显示的应答序列以指示呼叫的确定性。脚注2:要重现结果,请使用call_det/2如下定义:call_det(G_0,Det):- call_cleanup(G_0,标志=设置), (nonvar(Flag) -> Det = true ; Det =假 )。