/* CS 313 example
* how cut affects search
*/
fact(0, 1) :- !. % once you find base case, don't look for additional solutions
fact(N, R) :-
N1 is N-1,
fact(N1, R1),
R is N * R1.
/* without cuts, b(W) yields 3 solutions: W=3; W=4; W=5. */
a(1).
a(2).
b(Z) :- a(X),
%!, % cut here gives no soln
X mod 2 =:= 0,
%!, % cut here only gives solns 3, 4
a(Y),
%!, % cut here only gives soln 3
Z is X+Y.
b(5).