(wat-aro)

無職から有職者にランクアップしました

SICP 問題 2.15

(define (par1 r1 r2)
  (div-interval (mul-interval r1 r2)
                (add-interval r1 r2)))

(define (par2 r1 r2)
  (let ((one (make-interval 1 1)))
    (div-interval one
                  (add-interval (div-interval one r1)
                                (div-interval one r2)))))

 
 
par1には不確かな数(r1,r2)が4回出てきている. 
par2には不確かな数が2回. 
そのためpar2のほうが誤差が小さい.
 

gosh> (define r1 (make-center-percent 5 5))
r1
gosh> (define r2 (make-center-percent 20 5))
r2
gosh> (define p1 (par1 r1 r2))
p1
gosh> (define p2 (par2 r1 r2))
P2
gosh> (center p1)
4.040100250626566
gosh> (percent p1)
14.900744416873444
gosh> (center p2)
4.0
gosh> (percent p2)
4.999999999999999