MAMMAL: arms(dog, 0). arms(human, 2). legs(human, 2). mammal(horse). mammal(X) :- legs(X,4), arms(X,0). mammal(X) :- legs(X,2), arms(X,2). ANCESTOR: parent(joan, john). parent(joan, jean). parent(jean, jan). ancestor(X,Y) :- parent(X,Z),ancestor(Z,Y). ancestor(X,X). FACTORIAL (no cut): fac(0,1). fac(N,X) :- M is N-1, fac(M,Y), X is N*Y. FACTORIAL (with cut); fac(0,1). fac(N,X) :- M is N-1, fac(M,Y), !, X is N*Y. NATURAL (no cut): natural(0). natural(X) :- X < 0, fail. natural(X) :- Y is X - 1, natural(Y). NATURAL (with cut): natural(0). natural(X) :- X < 0, !, fail. natural(X) :- Y is X - 1, natural(Y). GCD: gcd(X,0,X). gcd(X,Y,Z) :- X>Y, gcd(Y,X,Z), !. gcd(X,Y,Z) :- X =< Y, Y1 is Y mod X, gcd(X, Y1, Z), !. MEMBER: ourmember(X, [X|_]). ourmember(X, [_|Y]) :- ourmember(X, Y). APPEND: ourappend([], L, L). ourappend([X | L1], L2, [X | L3]) :- ourappend(L1, L2, L3). FLATTEN: flatten([],[]). flatten(X,[X]) :- atom(X). flatten([F|L1],L2) :- flatten(F,FF), flatten(L1,L1F), ourappend(FF, L1F, L2).