The cut prediction, ``!'', eliminates choices in a Prolog derivation tree (stops the backchaining along a particular path).
Consider the program
/* program P clause # */ p(a). /* #1 */ p(X) :- q(X), r(X). /* #2 */ p(X) :- u(X). /* #3 */ q(X) :- s(X). /* #4 */ r(a). /* #5 */ r(b). /* #6 */ s(a). /* #7 */ s(b). /* #8 */ s(c). /* #9 */ u(d). /* #10 */
Consider goal
p(X),!.
Result is
X=a ;
no
Cut succeeds when it is the current goal and backtracking up to the cut is pruned.
In this case, the second and third derivations are eliminated, and hence the entire subtrees below these two edges are also cut off.
Try
r(X),s(Y).
r(X),!,s(Y).
r(X), s(Y), !.