1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %% 16 June 2003 Bart Demoen, Tom Schrijvers, K.U.Leuven
5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 :- module(fibonacci,[main/0,main/1]).
9 :- use_module(library(chr)).
11 :- constraints fibonacci/2.
13 %% fibonacci(N,M) is true iff M is the Nth Fibonacci number.
15 %% Top-down Evaluation with effective Tabulation
16 %% Contrary to the version in the SICStus manual, this one does "true"
19 fibonacci(N,M1) # ID \ fibonacci(N,M2) <=> var(M2) | M1 = M2 pragma passive(ID).
21 fibonacci(0,M) ==> M = 1.
23 fibonacci(1,M) ==> M = 1.
41 write(bench(fibonacci ,N,Time, 0, hprolog)),write('.'), nl.