I am new to Prolog and I need help with this functor calculates the Fibonacci numbers ... first it adds Y = 0 and Z = 1, then it calls itself Y = Z and Z = Y + Z and every time it increases the value of counter C as long as the counter is X ..... the problem is that the result is always 1, because the prolog never executes the second sentence, even if X is not equal to M, but I donβt know why. ....
X: calculate the Fibonacci value Y: the first number in the Fibonacci series Z: the second number in the Fibonacci series C: the counter with 0 as the value intial T: Y + Z
predicates fib_tail(integer,integer, integer,integer, real) clauses fib_tail(X,Y , Z,M, T):- X=M,T = Y + Z,!. fib_tail(X,Y ,Z, C , T):- T = Y + Z, NY = Z, NZ = Y + Z, NC = C + 1, fib_tail(X, NY, NZ, NC, NT). goal fib_tail(5 ,0 ,1 ,0, T)
source share