plus(s(M), N, s(P))
   :-
   plus(M, N, P).

plus(z, N, N).

mult(z, N, z).

mult(s(M), N, Q)
   :-
   mult(M, N, P),
   plus(P, N, Q).


iszero(z).

anyzero([X | _])
   :-
   iszero(X).

anyzero([_ | L])
   :-
   anyzero(L).


mem(X, [X | _]).

mem(X, [Y | L])
   :-
   X \= Y,
   mem(X, L).


partition([], _, [], []).

partition([X | Xs], P, [X | L], G)
   :-
   X =< P,
   partition(Xs, P, L, G).

partition([X | Xs], P, L, [X | G])
   :-
   X > P,
   partition(Xs, P, L, G).


quicksort([], []).

quicksort([H | T], A)
   :-
   partition(T, H, L, G),
   quicksort(L, LL),
   quicksort(G, GG),
   append(LL, [H | GG], A).


minimum(X, Y, X)
   :-
   X =< Y.

minimum(X, Y, Y)
   :-
   X > Y.



min(X, Y, Z)
   :-
   X =< Y
   ->
   Z = X;
   Z = Y.


mini(X, Y, Z)
   :-
   X =< Y,
   !,
   Z = X.

mini(X, Y, Y).


mem2(X, [X | _])
   :-
   !.

mem2(X, [_ | L])
   :-
   mem2(X, L).



minim(X, Y, Z)
   :-
   x =< Y,
   !,
   Z = X.

minim(X, Y, Y)
   :-
   X > Y.



%% BUG!
minimu(X, Y, X)
   :-
   X =< Y,
   !.

minimu(X, Y, Y).


mem3(X, [X | _]).

mem3(X, [Y | L])
    :-
    \+(X = Y),
    mem3(X, L).
