Category: Scheme

  • Sicp Exercise 1.35

    Exercise 1.35. Show that the golden ratio (section 1.2.2) is a fixed point of the transformation x 1 + 1/x, and use this fact to compute by means of the fixed-point procedure. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the…

  • Sicp Exercise 1.34

    Exercise 1.34. Suppose we define the procedure (define (f g) (g 2)) Then we have (f square) 4 (f (lambda (z) (* z (+ z 1)))) 6 What happens if we (perversely) ask the interpreter to evaluate the combination (f f)? Explain. This file contains hidden or bidirectional Unicode text that may be interpreted or…

  • Sicp Exercise 1.33

    Exercise 1.33. You can obtain an even more general version of accumulate (exercise 1.32) by introducing the notion of a filter on the terms to be combined. That is, combine only those terms derived from values in the range that satisfy a specified condition. The resulting filtered-accumulate abstraction takes the same arguments as accumulate, together…

  • Sicp Exercise 1.32

    Exercise 1.32. a. Show that sum and product (exercise 1.31) are both special cases of a still more general notion called accumulate that combines a collection of terms, using some general accumulation function: (accumulate combiner null-value term a next b) Accumulate takes as arguments the same term and range specifications as sum and product, together…

  • Sicp Exercise 1.31

    Exercise 1.31. a. The sum procedure is only the simplest of a vast number of similar abstractions that can be captured as higher-order procedures.51 Write an analogous procedure called product that returns the product of the values of a function at points over a given range. Show how to define factorial in terms of product.…

  • Sicp Exercise 1.30

    Exercise 1.30. The sum procedure above generates a linear recursion. The procedure can be rewritten so that the sum is performed iteratively. Show how to do this by filling in the missing expressions in the following definition: (define (sum term a next b) (define (iter a result) (if (iter ))) (iter )) This file contains…

  • Sicp Exercise 1.29

    Exercise 1.29. Simpson’s Rule is a more accurate method of numerical integration than the method illustrated above. Using Simpson’s Rule, the integral of a function f between a and b is approximated as where h = (b – a)/n, for some even integer n, and yk = f(a + kh). (Increasing n increases the accuracy…

  • Sicp Exercise 1.22

    Exercise 1.22. Most Lisp implementations include a primitive called runtime that returns an integer that specifies the amount of time the system has been running (measured, for example, in microseconds). The following timed-prime-test procedure, when called with an integer n, prints n and checks to see if n is prime. If n is prime, the…

  • Sicp Exercise 1.18

    Exercise 1.18. Using the results of exercises 1.16 and 1.17, devise a procedure that generates an iterative process for multiplying two integers in terms of adding, doubling, and halving and uses a logarithmic number of steps. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below.…

  • Sicp Exercise 1.17

    Exercise 1.17. The exponentiation algorithms in this section are based on performing exponentiation by means of repeated multiplication. In a similar way, one can perform integer multiplication by means of repeated addition. The following multiplication procedure (in which it is assumed that our language can only add, not multiply) is analogous to the expt procedure:…