% We can also make arithmetic functions invertible with constraints

:- use_module(library(clpfd)).

% Factorial function (fac(n) = f) as a predicate fac(n,f):
fac(0, 1).
fac(N, F) :- N #> 0, N1 #= N-1, F #= F1*N, fac(N1, F1).
