(define (Cube x) (* x x x))
(define (P x) (-(* 3 x) (* 4 (Cube x)))
(Define (sine angle)
(if (Not (> (ABS angle) 0.1))
Angle
(P (sine (/angle 3.0))))
The code in the topic is written to Edwin , and trace can be used to trace P 's call, which is available in Visual Studio , and I've only recently known trace the.
(TRACE-ENTRYP)
; Unspecifiedreturn value
(sine12.15)
[Entering#[compound-procedure P]
Args:4.9999999999999996e-2]
[Entering#[compound-procedure P]
Args:. 1495]
[Entering#[compound-procedure P]
Args:. 4351345505]
[Entering#[compound-procedure P]
Args:. 9758465331678772]
[Entering#[compound-procedure P]
Args:-.7895631144708228]
; value:-.39980345741334
Thus it appears that p has run altogether 5 times.
Everyone should have seen it. The sine process is a recursive, so its time and space complexity are O (Loga). The number of times thep is run is incremented whenever the parameter a in the title is multiplied by 3 . You can have a happy test with trace .
"SICP Exercise" 9 Exercise 1.15