:- module(_, [tak/4], [assertions, regtypes, nativeprops]).

:- entry tak(X,Y,Z,A) : num * num * num * term.
:- pred tak(X,Y,Z,A) : num * num * num * term.
tak(X,Y,Z,A) :-
	tak_(X,Y,Z,A).

:- pred tak_(X,Y,Z,A) : num * num * num * term => num * num * num * num.
tak_(X,Y,Z,A) :-
        X =< Y, !,
        Z = A.
tak_(X,Y,Z,A) :-
        % X > Y,
        X1 is X - 1,
        tak_(X1,Y,Z,A1),
        Y1 is Y - 1,
        tak_(Y1,Z,X,A2),
        Z1 is Z - 1,
        tak_(Z1,X,Y,A3),
        tak_(A1,A2,A3,A).
