Personal understanding Ackermann function

Recently scratch looks "SICP", in which an exercise (1.10) mentioned in the Ackermann function, but the definition seems a bit different.

lang=Scheme

(define (A x y)
    (cond ((= y 0) 0)
          ((= x 0) (* 2 y))
          ((= y 1) 2)
          (else (A (- x 1)
                   (A x (- y 1))))))

(Lisp parentheses really more than)

Is simply a function A (x, y), y = 0 value is 0, y = 1 value is 2, x = 0 when the value of 2 * y, equal to the other case A (x-1, A (x, y-1)).

A (x, y)
x \ and 0 1 2 3 4 n(n>0)
0 0 2 4 6 8 2*n
1 0 2 4 8 16 2^n
2 0 2 4 16 2^16 2 ^ ... ^ 2 (n a 2)
3 0 2 4 2^16 ... 2 ^ 2 ^ (2 ^ 16 2)  

A (3, n) described a bit difficult to write, I described as: starting with n = 2, ... calculated 2 ^ 2 ^ (total A (3, n-1) th 2) as A (3, n) .

It is easy to see, A (x, y) value by A (x, y-1) and A (x-1, n) Effect of the A (x, y-1) is substituted into A (x-1 , n) to obtain the A (x, y).

On the first thought of here, I eat.

Guess you like

Origin blog.csdn.net/Chenyun__/article/details/81199948