SICP 习题解 1.8 1.11


;; Code Writer:    EOF
;; Code Date  :    2014.12.12
;; Code File  :    ex1_8.lisp
;; e-mail     :    [email protected]
	

(defun square (x) (* x x))

(defun cube (x) (* x x x))

(defun improve (x y)
	(/ (+ (/ x (square y)
	      ) 
	      (* 2 y)
	   )
	   3)
)

(defun	good-enough? (x y)
	(< (abs (- (cube y) x) ) 0.001)
)

(defun cube-root-iter  (x y)
	(if (good-enough? x y)	
		y
		(cube-root-iter x (improve x y)
		)
	)	
)

(defun cube-root (x)
	(cube-root-iter x 1.0)
)


SICP 习题解 1.8 1.11_第1张图片





;; Code Writer:    EOF
;; Code Date  :    2014.12.12
;; Code File  :    ex1_11.lisp
;; e-mail     :    [email protected]

(defun f (n)
    (if (< n 3)
     n
     ( + (f (- n 1)) 

         (* (f (- n 2)) 
            2
         )

         (* (f (- n 3))
	    3
	 )
     )
    )
)


SICP 习题解 1.8 1.11_第2张图片












你可能感兴趣的:(lisp)