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.

.

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.

Please explain me what is a predicate.I'm loss in prolog

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).

thank you for the help..............

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.