1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2%%
3%% 991202 Slim Abdennadher, LMU
4%%
5%% ported to hProlog by Tom Schrijvers
6
7:- module(fib,[main/0,main/1]).
8
9:- use_module(library(chr)).
10
11:- constraints fib/2.
12
13%% fib(N,M) is true if  M is the Nth Fibonacci number.
14
15%% Top-down Evaluation with Tabulation
16
17fib(N,M1), fib(N,M2) <=> M1 = M2, fib(N,M1).
18
19fib(0,M) ==> M = 1.
20
21fib(1,M) ==> M = 1.
22
23fib(N,M) ==> N > 1 | N1 is N-1, fib(N1,M1), N2 is N-2, fib(N2,M2), M is M1 + M2.
24
25main :-
26	main(22).
27
28main(N):-
29	cputime(X),
30	fib(N,_),
31	cputime( Now),
32	Time is Now-X,
33	write(bench(fib ,N,Time, 0, hprolog)),write('.'), nl.
34
35