abs(N,N):-N>=0,!. abs(N,X):-N<0,X is -N. nzd(X,0,X):-!. nzd(X,Y,Z):- X>Y,N is X-Y,nzd(N,Y,Z),!. nzd(X,Y,Z):- X=