# 1.1 程序设计的基本元素

## Exercise 1.1

10, 12, 8, 3, 6, a, b, 19, #f, 4, 16, 6, 16

## Exercise 1.2

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

## Exercise 1.3

(define (square a) (* a a))
(define (square-sum a b) (+ (square a) (square b)))
(define (square-sum-of-two-larger-numbers a b c)
(cond ((not (or (> a b) (> a c))) (square-sum b c))
((not (or (> b a) (> b c))) (square-sum a c))
(else (square-sum a b))))

## Exercise 1.4

b 为正数，求出 (+ a b) 的值，否则求出 (- a b) 的值。

## Exercise 1.5

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

(test 0 (p))
(if (= 0 0) 0 (p))
(if (= 0 0) 0 (p))
(if (= 0 0) 0 (p))
...

## Exercise 1.7

good-enough? 的定义改为以下，可以改进程序：

(define (good-enough? guess x)
(< (abs (- (square guess) x))
(* guess 0.001)))

## Exercise 1.8

(define (cube x) (* x x x))
(define (good-enuf? guess x)
(< (abs (- (cube guess) x))
(* guess 0.001)))
(define (improve guess x)
(/ (+ (/ x (* guess guess))
(* guess 2))
3))
(define (cbrt-iter guess x)
(if (good-enuf? guess x)
guess
(cbrt-iter (improve guess x)
x)))
(define (cbrt x) (cbrt-iter 1.0 x))