Prolog Text fac

/**
* Prolog code for the factorial via Peano axioms.
*
* Copyright 2010, XLOG Technologies GmbH, Switzerland
* Jekejeke Prolog 0.8.7 (a fast and small prolog interpreter)
**/

add(n,X,X).
add(s(X),Y,Z) :- add(X,s(Y),Z).

mul(n,_,n).
mul(s(X),Y,Z) :- mul(X,Y,H), add(Y,H,Z).

fac(n,s(n)).
fac(s(X),Y) :- fac(X,H), mul(s(X),H,Y).

Kommentare