# 练习1.1－练习1.9

1. 练习1.1

2. 练习1.2

(/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5)))))
(* 3 (- 6 2) (- 2 7)))


3.练习1.3

(define (sumofmax2 x y z)
(- (+ x y z)
(cond ((and (< x y) (< x z)) x)
((and (< y x) (< y z)) y)
(else z))))

4.练习1.4

5.练习1.5

Scheme的解释器用的是应用序，所以在求表达式(test 0 (p))时首先会将(p)进行展开，可以看到p的实现时他自己，所以会进入一个无穷的递归，最终导致“死机”或者奔溃。

(if (= 0 0)
0
(p))

6.练习1.6

7.练习1.7

(define (good-enough? guess old-guess)
(and (> (/ guess old-guess) 0.99999999999999)
(< (/ guess old-guess) 1.00000000000001)))

(define (average x y)
(/ (+ x y) 2))

(define (improve guess x)
(average guess (/ x guess)))

(define (sqrt-iter guess old-guess x)
(if (good-enough? guess old-guess)
guess
(sqrt-iter (improve guess x) guess x)))

(define (sqrt x)
(sqrt-iter 1.0 0.1 x))

8.练习1.8

(define (good-enough? guess old-guess)
(and (> (/ guess old-guess) 0.9999)
(< (/ guess old-guess) 1.0001)))

(define (improve guess x)
(/ (+ (/ x (* guess guess)) (* 2 guess)) 3))

(define (cbrt-iter guess old-guess x)
(if (good-enough? guess old-guess)
guess
(cbrt-iter (improve guess x) guess x)))

(define (cbrt x)
(cbrt-iter 1.0 0.1 x))

9.练习1.9

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客