/* Ackermann Prolog style in Picat. For Picat version 3.0. This is a direct port of my SWI-Prolog model: http://hakank.org/swi_prolog/ackermann.pl This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ main => go. go :- M = 3, between(0,10,N), writeln(n=N), % abolish_all_tables, time(once(a(M,N,R))), writeln([3,N,R]), fail, nl. go. % From % https://groups.google.com/g/comp.lang.prolog/c/AX8plLWooJA % Example expected result: % % ?- depth(ack(3,4), 0, N). % N = 10307. go2 ?=> time(depth($ack(3,4), 0, N)), println(n=N), nl. go2 => true. table a(0,N,A):- !,A is N+1. a(M,0,A):- !,M1 is M-1, a(M1,1,A). a(M,N,A):- M1 is M-1, N1 is N-1, a(M,N1,A1), a(M1,A1,A). % https://groups.google.com/g/comp.lang.prolog/c/AX8plLWooJA % (Jan Burse) edge(ack(X, ack(Y, Z)), ack(X, H)) :- !, edge($ack(Y, Z), H). edge(ack(0, N), X) :- !, X is N+1. edge(ack(M, 0), ack(H, 1)) :- !, H is M-1. edge(ack(M, N), ack(H, ack(M, J))) :- H is M-1, J is N-1. depth(ack(X, Y), N, M) :- !, edge($ack(X, Y), H), J is N+1, depth(H, J, M). depth(_, N, N).