Hello.
I have written a set of two predicates to test whether a number is a square number.
patrat_perfect(A):- patr(A, 0).
patr(A, S):- A =:= S * S.
patr(A,S):- A > S * S, T is S+1, patrat(A, T).
patr(A,S):- A < S * S, fail.
The first predicate, patrat_perfect simply execute a call for the second predicate with the value 0 for the second parameter, and the number which should be tested whether or not it is a perfect square for the first parameter.
The patr predicate practically searches that number S from 0 to sqrt(A), which respects the equation S * S = A. In order to do so, the predicate increases the value of S with 1 if A > S * S. If at the next call, A = S * S, then the predicate returns true and if A < S * S, then the predicate returns false through the call of the built-in predicate fail.
The problem is that at every call of the patrat_perfect predicate, I receive the false value. Could you please tell me where do I go wrong?