Re: Prolog and Logical definitions of plus/subtract



John Todd writes:

I know that the logical definition of and plus and subtract in
Prolog is:
plus(0,N,N).
plus(s(M),N,s(Z)) :- plus(M,N,Z).

where s(X) is the successor of number X.

However, what would you do if you wanted to represent negative
numbers?

Represent +3 as (3 - 0) and -3 as (0 - 3), with 3 and 0 as before.

Then (a - b) + (c - d) = (a + c) - (b + d), with right + as before.

Normalize by (s(X) - s(Y)) = (X - Y) till at least one of X, Y is 0.
This is optional, since (7 - 4) is also +3, and (4 - 7) is -3.
.