fact(0,1). fact(X,Y) :- ground(X), X > 0, Xp is X-1, fact(Xp,Yp), Y is Yp*X.