Outside North America

نویسندگان

  • Gerald Jay Sussman
  • Julie Sussman
  • Alan J. Perlis
چکیده

ions and first-class procedures We've seen two ways to express the square-root computation as an instance of a more general method, once as a fixed-point search and once using Newton's method. Since Newton's method was itself expressed as a fixed-point process, we actually saw two ways to compute square roots as fixed points. Each method begins with a function and finds a fixed point of some transformation of the function. We can express this general idea itself as a procedure: (define (fixed-point-of-transform g transform guess) (fixed-point (transform g) guess)) This very general procedure takes as its arguments a procedure g that computes some function, a procedure that transforms g, and an initial guess. The returned result is a fixed point of the transformed function. Using this abstraction, we can recast the first square-root computation from this section (where we look for a fixed point of the average-damped version of y x/y) as an instance of this general method: (define (sqrt x) (fixed-point-of-transform (lambda (y) (/ x y)) average-damp 1.0)) Similarly, we can express the second square-root computation from this section (an instance of Newton's method that finds a fixed point of the Newton transform of y y2 x) as (define (sqrt x) (fixed-point-of-transform (lambda (y) ((square y) x)) newton-transform 1.0)) We began section 1.3 with the observation that compound procedures are a crucial abstraction mechanism, because they permit us to express general methods of computing as explicit elements in our programming language. Now we've seen how higher-order procedures permit us to manipulate these general methods to create further abstractions. As programmers, we should be alert to opportunities to identify the underlying abstractions in our programs and to build upon them and generalize them to create more powerful abstractions. This is not to say that one should always write programs in the most abstract way possible; expert programmers know how to choose the level of abstraction appropriate to their task. But it is important to be able to think in terms of these abstractions, so that we can be ready to apply them in new contexts. The significance of higher-order procedures is that they enable us to represent these abstractions explicitly as elements in our programming language, so that they can be handled just like other computational elements. In general, programming languages impose restrictions on the ways in which computational elements can be manipulated. Elements with the fewest restrictions are said to have first-class status. Some of the ``rights and privileges'' of first-class elements are:64 ● They may be named by variables. ● They may be passed as arguments to procedures. ● They may be returned as the results of procedures. ● They may be included in data structures.65 Lisp, unlike other common programming languages, awards procedures full first-class status. This poses challenges for efficient implementation, but the resulting gain in expressive power is enormous.66 Exercise 1.40. Define a procedure cubic that can be used together with the newtons-method procedure in expressions of the form (newtons-method (cubic a b c) 1) to approximate zeros of the cubic x3 + ax2 + bx + c. Exercise 1.41. Define a procedure double that takes a procedure of one argument as argument and returns a procedure that applies the original procedure twice. For example, if inc is a procedure that adds 1 to its argument, then (double inc) should be a procedure that adds 2. What value is returned by (((double (double double)) inc) 5) Exercise 1.42. Let f and g be two one-argument functions. The composition f after g is defined to be the function x f(g(x)). Define a procedure compose that implements composition. For example, if inc is a procedure that adds 1 to its argument, ((compose square inc) 6) 49 Exercise 1.43. If f is a numerical function and n is a positive integer, then we can form the nth repeated application of f, which is defined to be the function whose value at x is f(f(...(f(x))...)). For example, if f is the function x x + 1, then the nth repeated application of f is the function x x + n. If f is the operation of squaring a number, then the nth repeated application of f is the function that raises its argument to the 2nth power. Write a procedure that takes as inputs a procedure that computes f and a positive integer n and returns the procedure that computes the nth repeated application of f. Your procedure should be able to be used as follows: ((repeated square 2) 5) 625 Hint: You may find it convenient to use compose from exercise 1.42. Exercise 1.44. The idea of smoothing a function is an important concept in signal processing. If f is a function and dx is some small number, then the smoothed version of f is the function whose value at a point x is the average of f(x dx), f(x), and f(x + dx). Write a procedure smooth that takes as input a procedure that computes f and returns a procedure that computes the smoothed f. It is sometimes valuable to repeatedly smooth a function (that is, smooth the smoothed function, and so on) to obtained the n-fold smoothed function. Show how to generate the n-fold smoothed function of any given function using smooth and repeated from exercise 1.43. Exercise 1.45. We saw in section 1.3.3 that attempting to compute square roots by naively finding a fixed point of y x/y does not converge, and that this can be fixed by average damping. The same method works for finding cube roots as fixed points of the average-damped y x/y2. Unfortunately, the process does not work for fourth roots -a single average damp is not enough to make a fixed-point search for y x/y3 converge. On the other hand, if we average damp twice (i.e., use the average damp of the average damp of y x/y3) the fixed-point search does converge. Do some experiments to determine how many average damps are required to compute nth roots as a fixed-point search based upon repeated average damping of y x/yn-1. Use this to implement a simple procedure for computing nth roots using fixedpoint, average-damp, and the repeated procedure of exercise 1.43. Assume that any arithmetic operations you need are available as primitives. Exercise 1.46. Several of the numerical methods described in this chapter are instances of an extremely general computational strategy known as iterative improvement. Iterative improvement says that, to compute something, we start with an initial guess for the answer, test if the guess is good enough, and otherwise improve the guess and continue the process using the improved guess as the new guess. Write a procedure iterative-improve that takes two procedures as arguments: a method for telling whether a guess is good enough and a method for improving a guess. Iterative-improve should return as its value a procedure that takes a guess as argument and keeps improving the guess until it is good enough. Rewrite the sqrt procedure of section 1.1.7 and the fixed-point procedure of section 1.3.3 in terms of iterative-improve. 49 This series, usually written in the equivalent form ( /4) = 1 (1/3) + (1/5) (1/7) + ···, is due to Leibniz. We'll see how to use this as the basis for some fancy numerical tricks in section 3.5.3. 50 Notice that we have used block structure (section 1.1.8) to embed the definitions of pi-next and pi-term within pi-sum, since these procedures are unlikely to be useful for any other purpose. We will see how to get rid of them altogether in section 1.3.2. 51 The intent of exercises 1.31-1.33 is to demonstrate the expressive power that is attained by using an appropriate abstraction to consolidate many seemingly disparate operations. However, though accumulation and filtering are elegant ideas, our hands are somewhat tied in using them at this point since we do not yet have data structures to provide suitable means of combination for these abstractions. We will return to these ideas in section 2.2.3 when we show how to use sequences as interfaces for combining filters and accumulators to build even more powerful abstractions. We will see there how these methods really come into their own as a powerful and elegant approach to designing programs. 52 This formula was discovered by the seventeenth-century English mathematician John Wallis. 53 It would be clearer and less intimidating to people learning Lisp if a name more obvious than lambda, such as make-procedure, were used. But the convention is firmly entrenched. The notation is adopted from the calculus, a mathematical formalism introduced by the mathematical logician Alonzo Church (1941). Church developed the calculus to provide a rigorous foundation for studying the notions of function and function application. The calculus has become a basic tool for mathematical investigations of the semantics of programming languages. 54 Understanding internal definitions well enough to be sure a program means what we intend it to mean requires a more elaborate model of the evaluation process than we have presented in this chapter. The subtleties do not arise with internal definitions of procedures, however. We will return to this issue in section 4.1.6, after we learn more about evaluation. 55 We have used 0.001 as a representative ``small'' number to indicate a tolerance for the acceptable error in a calculation. The appropriate tolerance for a real calculation depends upon the problem to be solved and the limitations of the computer and the algorithm. This is often a very subtle consideration, requiring help from a numerical analyst or some other kind of magician. 56 This can be accomplished using error, which takes as arguments a number of items that are printed as error messages. 57 Try this during a boring lecture: Set your calculator to radians mode and then repeatedly press the cos button until you obtain the fixed point. 58 (pronounced ``maps to'') is the mathematician's way of writing lambda. y x/y means (lambda(y) (/ x y)), that is, the function whose value at y is x/y. 59 Observe that this is a combination whose operator is itself a combination. Exercise 1.4 already demonstrated the ability to form such combinations, but that was only a toy example. Here we begin to see the real need for such combinations -when applying a procedure that is obtained as the value returned by a higher-order procedure. 60 See exercise 1.45 for a further generalization. 61 Elementary calculus books usually describe Newton's method in terms of the sequence of approximations xn+1 = xn g(xn)/Dg(xn). Having language for talking about processes and using the idea of fixed points simplifies the description of the method. 62 Newton's method does not always converge to an answer, but it can be shown that in favorable cases each iteration doubles the number-ofdigits accuracy of the approximation to the solution. In such cases, Newton's method will converge much more rapidly than the half-interval method. 63 For finding square roots, Newton's method converges rapidly to the correct solution from any starting point. 64 The notion of first-class status of programming-language elements is due to the British computer scientist Christopher Strachey (19161975). 65 We'll see examples of this after we introduce data structures in chapter 2. 66 The major implementation cost of first-class procedures is that allowing procedures to be returned as values requires reserving storage for a procedure's free variables even while the procedure is not executing. In the Scheme implementation we will study in section 4.1, these variables are stored in the procedure's environment. [Go to first, previous, next page; contents; index] [Go to first, previous, next page; contents; index]

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Williamsonia Carolinensis Sp. Nov. and Associated Eoginkgoites Foliage from the Upper Triassic Pekin Formation, North Carolina: Implications for Early Evolution in the Williamsoniaceae (bennettitales)

Manuscript 2014; elect Premise of research. Few reproductive organs unequivocally attributable to the important but enigmatic Mesozoic seed plant order Bennettitales have been described from the Triassic of all of North America outside of Greenland. Here, the first ovulate reproductive organs (gynoecia) of the group from the Upper Triassic of eastern North America are described and assigned to ...

متن کامل

Cutaneous leishmaniasis in North Dakota.

In the United States, autochthonous cutaneous leishmaniasis caused by infection with Leishmania mexicana has been reported from Texas and Oklahoma. Here, we describe a child with 2 new features: cutaneous infection acquired outside of the south-central United States (in North Dakota) and infection caused by Leishmania donovani species complex.

متن کامل

Nuclear ribosomal DNA evidence for a western North American origin of Hawaiian and South American species of Sanicula (Apiaceae).

Results from phylogenetic analysis of nuclear rDNA internal transcribed spacer (ITS) sequences from a worldwide sample of Sanicula indicate that Hawaiian sanicles (Sanicula sect. Sandwicenses) constitute a monophyletic group that descended from a western North American ancestor in Sanicula sect. Sanicoria, a paraphyletic assemblage of mostly Californian species. A monophyletic group comprising ...

متن کامل

Identifying Barriers and Practical Solutions to Conducting Site-Based Research in North America: Exploring Acute Heart Failure Trials As a Case Study.

Although the prognosis of ambulatory heart failure (HF) has improved dramatically there have been few advances in the management of acute HF (AHF). Despite regional differences in patient characteristics, background therapy, and event rates, AHF clinical trial enrollment has transitioned from North America and Western Europe to Eastern Europe, South America, and Asia-Pacific where regulatory bu...

متن کامل

New adapiform primate of Old World affinities from the Devil's Graveyard Formation of Texas.

Most adapiform primates from North America are members of an endemic radiation of notharctines. North American notharctines flourished during the Early and early Middle Eocene, with only two genera persisting into the late Middle Eocene. Here we describe a new genus of adapiform primate from the Devil's Graveyard Formation of Texas. Mescalerolemur horneri, gen. et sp. nov., is known only from t...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 2002