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

版权声明:

相关文章推荐

[SICP][1.10]Ackermann函数

阿克曼函数

picamera 1.10 教程及api中文简译(一)在python2.7/3.2+上安装 picamera

转自:http://blog.csdn.net/talkxin/article/details/50499950 点击打开链接 以前做过一个家庭摄像头,用的是raspivid的命令行...

从头认识Spring-1.10 使用命名空间p来注入属性

这一章节我们来介绍一下使用命名空间p来注入属性。1.domain蛋糕类:(不变)package com.raylee.my_new_spring.my_new_spring.ch01.topic_1_...

django1.10官方文档翻译

django1.10官方文档翻译
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

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