SCIP 1.10
Exercise 1.10. The following procedure computes a mathematical function called Ackermann's
function.
(define (A x y)
(cond ((= y 0) 0)
((= x 0) (* 2 y))
((= y 1) 2)
(else (A (- x 1)
(A x (- y 1))))))
What are the values of the following expressions?
(A 1 10)
(A 2 4)
(A 3 3)
Consider the following procedures, where A is the procedure defined above:
(define (f n) (A 0 n))
(define (g n) (A 1 n))
(define (h n) (A 2 n))
(define (k n) (* 5 n n))
Give concise mathematical definitions for the functions computed by the procedures f, g, and h for
positive integer values of n. For example, (k n) computes 5n2.
answer:
(defun A(x y)
( cond ( (= y 0) 0)
( (= x 0) (* 2 y))
( (= y 1) 2)
( (T) (A (- x 1)
(A x (- y 1))))))
(defun f(n)
(A 0 n))
(defun g(n)
(A 1 n))
(defun h(n)
(A 2 n))
CL-USER> (f 0)
0
CL-USER> (f 1)
2
CL-USER> (f 2)
4
CL-USER> (f 3)
6
(f n) = 2n;
CL-USER> (g 0)
0
CL-USER> (g 1)
2
CL-USER> (g 2)
4
CL-USER> (g 3)
8
CL-USER> (g 4)
(g n) = 2^n
16
CL-USER> (h 0)
0
CL-USER> (h 1)
2
CL-USER> (h 2)
4
CL-USER> (h 3)
16
CL-USER> (h 4)
6553
(h n) = 2^(2^n)
Edit in Emacs with Slime and Steel Bank Common Lisp.