SICP 1.09-1.10

原创 2016年08月31日 13:43:52

习题1.9

(define (+ a b)
   (if (= a 0)
       b
       (inc (+ (dec a) b))))
(+ 4 5)
(inc (+ 3 5))
(inc (inc (+ 2 5)))
(inc (inc (inc (+ 1 5))))
(inc (inc (inc (inc (+ 0 5)))))
(inc (inc (inc (inc 5))))
(inc (inc (inc 6)))
(inc (inc 7))
(inc 8)
9

替换过程构成了延迟处理链表,所以这是一个递归运算过程。

(define (+ a b)
   (if (= a 0)
       b
       (+ (dec a) (inc b))))     ;尾递归算法
(+ 4 5)
(+ 3 6)
(+ 2 7)
(+ 1 8)
(+ 0 9)
9

替换过程中,每一步的状态只需要2个状态变量来记录,所以这是一个迭代运算过程。


习题1.10

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

>(A 1 10)
(A 0 (A 1 9))
(A 0 (A 0 (A 1 8)))
(A 0 (A 0 (A 0 (A 1 7))))
(A 0 (A 0 (A 0 (A 0 (A 1 6)))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 1 5))))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 1 4)))))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 1 3))))))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 1 2)))))))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 1 1))))))))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 2)))))))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 4))))))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 8)))))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 0 16))))))
(A 0 (A 0 (A 0 (A 0 (A 0 32)))))
(A 0 (A 0 (A 0 (A 0 64))))
(A 0 (A 0 (A 0 128)))
(A 0 (A 0 256))
(A 0 512)
1024

>(A 2 4)
(A 1 (A 2 3))
(A 1 (A 1 (A 2 2)))
(A 1 (A 1 (A 1 (A 2 1))))
(A 1 (A 1 (A 1 2)))
(A 1 (A 1 (A 0 (A 1 1))))
(A 1 (A 1 (A 0 2)))
(A 1 (A 1 4))
(A 1 (A 0 (A 1 3)))
(A 1 (A 0 (A 0 (A 1 2))))
(A 1 (A 0 (A 0 (A 0 (A 1 1)))))
(A 1 (A 0 (A 0 (A 0 2))))
(A 1 (A 0 (A 0 4)))
(A 1 (A 0 8))
(A 1 16)
(A 0 (A 1 15))
......
65536

>(A 3 3)
......
65536

(define (f n) (A 0 n))
f(n) = 2n

(define (g n) (A 1 n))
g(n) = 2 n  

(define (h n) (A 2 n))
h(n) = 2 h(n1)  ; h(1) = 1

Delphi7高级应用开发随书源码

  • 2003年04月30日 00:00
  • 676KB
  • 下载

不是为了生气而种兰花

一位禅师非常喜爱兰花,在平日弘法讲经之余,心费了许多的时间栽种兰花。有一天,他要外出云游一段时间,临行前交待弟子:要好好照顾寺里的兰花。在这段期间,弟子们总是细心照顾兰花,但有一天在浇水时却不小心将兰...
  • yiwuya
  • yiwuya
  • 2008年12月25日 08:48
  • 363

Delphi7高级应用开发随书源码

  • 2003年04月30日 00:00
  • 676KB
  • 下载

[SICP][1.10]Ackermann函数

阿克曼函数

SICP 习题 (1.10)解题总结:阿克曼函数

SICP 习题 1.10 讲的是一个叫“Akermann函数”的东西,去百度查可以查到对应的中文翻译,叫“阿克曼函数”。就像前面的解题总结中提到的,我是一个数学恐惧者,看着稍微复杂一点的什么函数我就怕...

PngBuild BATE1.09(素材生成器)

  • 2013年04月12日 20:59
  • 348B
  • 下载

Nginx1.10 编译安装

安装环境 系统:Centos6.8 软件:Nginx1.10.2 依赖软件:Pcre、Zlib、Openssl 安装前准备安装编译环境 yum -y install wget yum -y ins...

PngBuild BATE1.09(素材生成器)

  • 2013年04月12日 22:17
  • 7.53MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:SICP 1.09-1.10
举报原因:
原因补充:

(最多只允许输入30个字)