8

  • Write a Prolog predicate value_of(X, Y), which is true if Y is the natural number, in normal notation, corresponding to the s(s(...)) expression X.
    ?- value_of(s(s(s(s(0)))), Y).
    Y = 4
    

    Answer:

    value_of(0, 0).
    value_of(s(X), Y) :-
        value_of(X, Z),
        Y is Z+1.