Đang chuẩn bị liên kết để tải về tài liệu:
How to Design Programs phần 6

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Trong ngắn hạn, chức năng từ các số tự nhiên đến các số đại diện của chuỗi vô hạn. Một loạt toán học là tổng của một chuỗi. Ba chuỗi hữu hạn các khoản tiền 20, 25, và 75, tương ứng. Trong trường hợp của chuỗi vô hạn, nó thường là thú vị để xem xét một phần hữu hạn, nhìn chằm chằm với one.51 | make-even N - N even make-odd N - N odd to compute the i-th even to compute the i-th odd number number define make-even i define make-odd i 2 i 2 i 1 In short functions from natural numbers to numbers are representations of infinite sequences. A mathematical series is the sum of a sequence. The three finite sequences have the sums 20 25 and 75 respectively. In the case of infinite sequences it is often interesting to consider a finite portion staring with the first one.51 For example adding the first 10 even numbers yields 90 and adding the first 10 odd numbers yields 100. Computing a series is clearly a job for a computer. Here are functions that add up the first n odd or even numbers respectively using make-even and make-odd to compute the required numbers series-even N - number to sum up the first series-odd N - number to sum up the first n even numbers define series-even n cond n 0 make-even n else make-even n series-even - n 1 make-odd n ake-odd n s-odd - n n odd numbers define series-odd n cond n 0 els ere a-term sequence a-term The two functions are natural candidates for abstract basic abstraction recipe series N N - number to sum up the first nu define series n cond n 0 erm else a-term n 1 result of following our The first argument specifies where the addition starts. The second argument of series is a function that maps a natural number to the corresponding term in the series. To test series we apply it to make-even and make-odd series-even1 N - number define series-even1 n series n make-even series-odd1 N - number define series-odd1 n series n make-odd For over a century mathematicians have used the Greek symbol Sigma to communicate about series. The two series above would be expressed as i fl ì Í1 53 ike-aid i A true lazy mathematician would also replace make-even and make-odd by their definitions that is 2 i and 2 i 1 but we refrain from doing so to emphasize the analogy to our well-organized functions. -282- TEAM FLY PRESENTS Exercise 23.1.1. Use .