% Arithmetic with Peano representation of numbers

% is the argument a Peano number?
isPeano(o).
isPeano(s(X)) :- isPeano(X).

% the successor of a Peano number
succ(X, s(X)).

% the predecessor of a Peano number
pred(s(X), X).

% add two Peano numbers X and Y: add(X,Y,Z)
add(o ,   Y, Y).
add(s(X), Y, s(Z)) :- add(X,Y,Z).

% subtracts two numbers: Z=X-Y  <=> X = Y+Z
sub(X,Y,Z) :- add(Y,Z,X).

% multiplies two numbers:
mult(o   , _, o).
mult(s(X), Y, Z) :- mult(X,Y,N), add(N,Y,Z).

% less-or-equal relation on Peano numbers
leq(o   ,_).
leq(s(X),s(Y)) :- leq(X,Y).
