7

  • Write a Prolog predicate, subtract(X, Y, Z), which is true if Z represents the difference between X and Y, assuming X is greater than or equal to Y. If X is less than Y, then this predicate is undefined.
    ?- subtract(s(s(s(s(0)))), s(s(0)), Z).
    Z = s(s(0))
    

    Answer:

    subtract(X, 0, X).
    subtract(s(X), s(Y), Z) :-
        subtract(X, Y, Z).