%================================================= % Arithmetic %================================================= %-------------------------------- %Counting Down with Recursion %-------------------------------- count(0,[]) :- !. %The cut will eliminate the fail call to second clause. count(X,[X | Rest]) :- X > 0, Y is X - 1, count(Y,Rest). %-------------------------------- %Summing Up with Recursion % % - Produce the Sum of the numbers % in the input list. %-------------------------------- sum([],0). sum([H | Rest] ,Sum) :- sum(Rest,RSum), Sum is H + RSum. %-------------------------------- %Computing Factorial with Recursion %-------------------------------- fact(0,1). fact(N,Nfact) :- N > 0, M is N - 1, fact(M,Mfact), Nfact is N * Mfact.