Jesse's Blog » 日志 » SICP-Exercise-1.20
SICP-Exercise-1.20
Jesse 发表于 2008-09-03 15:13:45
Exercise 1.20
With normal-order evalutation,
(gcd 206 40)
40 != 0
(gcd 40 (r 206 40))
[(r 206 40) != 0]
=> 1 time
(gcd (r 206 40)
(r 40
(r 206 40)))
[(r 40 (r 206 40)) != 0 ]
=> 2 times
(gcd (r 40
(r 206 40))
(r (r 206 40)
(r 40
(r 206 40))))
(r (r 206 40) (r 40 (r 206 40))) != 0
=> 4 times
(gcd (r (r 206 40)
(r 40
(r 206 40)))
(r (r 40
(r 206 40))
(r (r 206 40)
(r 40
(r 206 40)))))
(r (r 40 (r 206 40)) (r (r 206 40) (r 40 (r 206 40)))) == 0
=> 7 times
(r (r 206 40) (r 40 (r 206 40)))
=> 4 times
So remainder is called 18 times
With applicative-order evalutation,
(gcd 206 40)
(gcd 40 6) 1
(gcd 6 4) 1
(gcd 4 2) 1
(gcd 2 0) 1
Remainder is called 4 times
With normal-order evalutation,
(gcd 206 40)
40 != 0
(gcd 40 (r 206 40))
[(r 206 40) != 0]
=> 1 time
(gcd (r 206 40)
(r 40
(r 206 40)))
[(r 40 (r 206 40)) != 0 ]
=> 2 times
(gcd (r 40
(r 206 40))
(r (r 206 40)
(r 40
(r 206 40))))
(r (r 206 40) (r 40 (r 206 40))) != 0
=> 4 times
(gcd (r (r 206 40)
(r 40
(r 206 40)))
(r (r 40
(r 206 40))
(r (r 206 40)
(r 40
(r 206 40)))))
(r (r 40 (r 206 40)) (r (r 206 40) (r 40 (r 206 40)))) == 0
=> 7 times
(r (r 206 40) (r 40 (r 206 40)))
=> 4 times
So remainder is called 18 times
With applicative-order evalutation,
(gcd 206 40)
(gcd 40 6) 1
(gcd 6 4) 1
(gcd 4 2) 1
(gcd 2 0) 1
Remainder is called 4 times
收藏:
QQ书签
del.icio.us
订阅:
Google
抓虾
