contains([Val|Rest],Val). contains([Other|Rest],Val) :- contains(Rest,Val). add([],Right,Right). add([1|MoreLeft],Right,[1|MoreSum]) :- add(MoreLeft,Right,MoreSum). multiply([],Right,[]). multiply([1],Right,Right). multiply([1|MoreLeft],Right,Product) :- le(MoreLeft,Product) , le(Right,Product) , multiply(MoreLeft,Right,PartialProduct) , add(Right,PartialProduct,Product). le([],X). le([1|X],[1|Y]) :- le(X,Y). fact([],[1]). fact([1|N],F) :- le([1|N],F),fact(N,F2),multiply([1|N],F2,F).