% Here is another version that does error checking once at the % start, rather than on every recursion. factorial2(N, F) :- integer(N), fact2(N, F). fact2(1, 1). fact2(N, F) :- N > 1, M is N-1, fact2(M, F2), F is N*F2.