0

Can anybody explain why this is not working.Can someone help me.

fib(0, 0).
fib(1, 1).
fib(N, NF) :-
  N>=0,   fib(N-1, AF),    fib(N-2, BF),    NF is AF + BF.

.

2
Contributors
4
Replies
22
Views
4 Years
Discussion Span
Last Post by Dili1234
0

You can't use arithmetic expressions directly as arguments to predicates in Prolog - you need to asssign them to a variable using is and then use that as the argument:

N >= 0, NM1 is N - 1, NM2 is N - 2, fib(NM1, AF), fib(NM2, BF), NF is AF + BF.
0

Predicate or procedure is what Prolog calls its "functions". So fib/2 is a predicate.

You can't write fib(N-1, AF), you have to write something like NM1 is N-1, fib(NM1, AF).

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.