Hello, I wrote a search for values from the last Fibonacci index. There was an inverse problem. It seems that the recursive algorithm works, put write () and it is clear that the program exits the recursion when it finds the index, but the problem is that I cannot return the found index.
predicates fib2(integer, integer) fibm(integer, integer, integer) clauses fib2(1,1) :- !. fib2(2,1) :- !. fib2(N,F) :- N1 = N - 1, fib2(N1,F1), N2 = N-2, fib2(N2,F2), F = F1+F2. fibm(1, 1, 1) :- !. fibm(2, 1, 1) :- !. fibm(X, N1, Q) :- R = N1 + 1, fib2(R, T), write(" R = ",R), T < X, fibm(X, R), Q = R. goal fibm(21, 0, Q). The input is the value from the sequence and you need to return the index of this value.
fibm/3orfib/2. - Anton Danilov