"SICP Exercise" 9 Exercise 1.15

Source: Internet
Author: User



(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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.