1%   Evan Tick (from Lisp version by R. P. Gabriel)
2%
3%   (almost) Takeuchi function (recursive arithmetic)
4
5tak(R) :- tak(18, 12, 6, R).
6
7tak(X, Y, Z, A) :-
8    {
9      X =< Y,
10      Z = A
11    }.
12
13tak(X, Y, Z, A) :-
14    {
15      X >= Y+1
16    },
17    tak(X-1, Y,   Z,  A1),
18    tak(Y-1, Z,   X,  A2),
19    tak(Z-1, X,   Y,  A3),
20    tak(A1,  A2,  A3, A ).
21