/* adapted from "Natural Termination" by Dershowitz and Hoot


  av(A,B,C) :- C is the av of natural numbers A and B

*/

av(0,0,0).
av(0,s(0),0).
av(0,s(s(0)),s(0)).

av(s(X),Y,Z) :- av(X,s(Y),Z).
av(X,s(s(s(Y))),s(Z)) :- av(s(X),Y,Z).

%:- av(i,o,i).

/*
    | ?- av(s(0),s(s(0)),Y).

    Y = s(0) ? ;


    | ?- av(A,B,s(0)).

    A = 0,
    B = s(s(0)) ? ;

    A = s(0),
    B = s(0) ? ;

    A = s(s(0)),
    B = 0 ? ;

    and then diverges

*/
