% We can also make arithmetic functions invertible with constraints

:- use_module(library(clpfd)).

fac(0, 1).
fac(N, F) :- N #> 0, N1 #= N-1, F #= N*F1, fac(N1, F1).

% ?- fac(5,F).
% F = 120
% ?- fac(N,720).
% N = 6
% ?- fac(N,723).
% no
% ?- fac(N,F).
% N = 0,
% F = 1 ? ;
% N = 1,
% F = 1 ? ;
% N = 2,
% F = 2 ? ;
% N = 3,
% F = 6 ? ;
% N = 4,
% F = 24 ? ;
% N = 5,
% F = 120 ? ;
% N = 6,
% F = 720 ? ;
% N = 7,
% F = 5040 ? ;
% N = 8,
% F = 40320
