Back Top Forward

The Decrement Relation

Next we will need the definition of the decrement function. This is simply:
dec(X,Y) :- inc(Y,X).

i.e. if the increment of Y is X, the the decrement of X is Y. Queries about dec are handled by replacaing tthem with queries about inc with the arguments swapped.

A simple query:

?- dec(n5,n4).
 yes

The goal dec(n5,n4) has been replaced by a goal of inc(n4,n5).

?- dec(n12,n11).
 no

The goal of dec(n12,n11) has been replaced by a goal of inc(n11,n12) which fails, as before.

?- dec(X,n5).
 X=n6

The goal dec(X,n5) has been repaced by a inc(n5,X) which succeeds, as before.

?- dec(X,Y).
 X=n1,Y=n0;
 X=n2,Y=n1;
 ...
 X=n10,Y=n9;
 no

When resatisfaction is asked for, the goal inc(Y,X) is tried again, giving the alternative solutions.