Re: Prolog and Logical definitions of plus/subtract
- From: Jussi Piitulainen <jpiitula@xxxxxxxxxxxxxxxx>
- Date: 27 Oct 2006 10:05:12 +0300
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.
.
- References:
- Prolog and Logical definitions of plus/subtract
- From: John Todd
- Prolog and Logical definitions of plus/subtract
- Prev by Date: Prolog and Logical definitions of plus/subtract
- Next by Date: Feeling stupid..
- Previous by thread: Prolog and Logical definitions of plus/subtract
- Next by thread: Feeling stupid..
- Index(es):