下面是我的第N個斐波納契數算出斷言這是確定:麻煩斐波那契數生成
f(0,0).
f(1,1).
f(N,R):-P is N-1,Q is N-2,f(P,T1),f(Q,T2),R is T1+T2.
,我試圖生成具有以下謂詞斐波那契數:
fgen(0,0).
fgen(1,1).
fgen(A,B):-fgen(X,Y),A is X+1,f(A,T),B is T.
當我查詢與fgen(X,Y).
它顯示:
?- fgen(X,Y).
X = 0
Y = 0 ;
X = 1
Y = 1 ;
X = 1
Y = 1 ;
ERROR: Out of local stack
我用trace命令和下面結果:
?- trace,fgen(X,Y).
Call: (9) fgen(_G281, _G282) ? creep
Exit: (9) fgen(0, 0) ? creep
X = 0
Y = 0 ;
Redo: (9) fgen(_G281, _G282) ? creep
Exit: (9) fgen(1, 1) ? creep
X = 1
Y = 1 ;
Redo: (9) fgen(_G281, _G282) ? creep
Call: (10) fgen(_L178, _L189) ? creep
Exit: (10) fgen(0, 0) ? creep
^ Call: (10) _G281 is 0+1 ? creep
^ Exit: (10) 1 is 0+1 ? creep
Call: (10) f(1, _L179) ? creep
Exit: (10) f(1, 1) ? creep
^ Call: (10) _G282 is 1 ? creep
^ Exit: (10) 1 is 1 ? creep
Exit: (9) fgen(1, 1) ? creep
X = 1
Y = 1 ;
Redo: (10) f(1, _L179) ? creep
^ Call: (11) _L207 is 1-1 ? creep
^ Exit: (11) 0 is 1-1 ? creep
^ Call: (11) _L208 is 1-2 ? creep
^ Exit: (11) -1 is 1-2 ? creep
Call: (11) f(0, _L209) ? creep
Exit: (11) f(0, 0) ? abort
% Execution Aborted
我試圖找到bug,但失敗了。如何解決這個問題?