:- pragma memo(fib/2). :- pred fib(int::in, int::out) is det. fib(N, X) :- ( if N =< 2 then X = 1 else fib(N - 1, A), fib(N - 2, B), X = A + B ).