I read in an algorithmic book that Ackerman's function cannot be made tail-recursive (what they say is "it cannot be converted to iteration"). I am very puzzled by this, so I tried to come up with this:
let Ackb mn = let rec rAck cont mn = match (m, n) with | 0, n -> cont (n+1) | m, 0 -> rAck cont (m-1) 1 | m, n -> rAck (fun x -> rAck cont (m-1) x) m (n-1) in rAck (fun x -> x) mn ;;
(this is OCaml / F # code).
My problem is that I'm not sure if this is actually a tail recursive. Could you confirm that this is so? If not, why? And in the end, what does it mean when people say that the Ackerman function is not primitive recursive?
Thanks!
algorithm tail-recursion ocaml
Clement
source share