Summary of the Problem Solving of SiC exercise (2.6), sicp2.6

Source: Internet
Author: User

Summary of the Problem Solving of SiC exercise (2.6), sicp2.6

The section 2.6 of the questions in the column is about the Qiqi count, which is a continuation of the Sections 2.4 and 2.5. Here, the masters want to remind us to think about what "Number" is. How can we achieve "Number" in computer systems? Are you ready to open your mind:


First, let's talk about the following definition:


(define zero (lambda (f) (lambda (x) x)))

Then the operation + 1 is defined:

(define (add-1 n)  (lambda (f) (lambda (x) (f ((n f) x)))))


Then the question requires us to define numbers 1 and 2 based on the above process, and then define basic + operations.


To be honest, when I saw this question for the first time, I was confused when I looked at the above three lines of code for a long time. I don't know what the relationship between such code and numbers is.

One of the keys is that I always want zero to be output as 0, while the (add-1 zero) process will output a number 1.


Who said that only sign 0 represents the number "zero? Cannot an empty pocket be "zero? Who said that only symbol 1 represents the digit "one? Cannot I walk alone on vast land represent "one?


To this extent, you can understand Qiu Qi's count.


The basic idea of Qiqi counting is to call the 0 Function to represent 0, call the 1 function to represent 1, and so on...


Therefore, the zero here is actually a lambda process. This process accepts another process as a parameter, but it is called 0 times. What is called 0 times, it is the parameter that is returned when the parameter is passed.


Correspondingly, the (add-1 n) process also returns a lambda process, which accepts another process as a parameter and calls the process n + 1 times.


In this way, 1 and 2 are easily defined, that is, the lambda process similar to zero is defined, but this is the process of calling 1 and 2 incoming requests respectively. The Code is as follows:

 

(define one  (lambda (f) (lambda (x) (f x))))(define two  (lambda (f) (lambda (x) (f (f x)))))


By considering how to implement the + operation, we know that the "Number" in the Qiu Qi count is actually the number of calls to the incoming process, which is relatively simple, if you want to add n and m in the two odd count, it is actually called (n + m) times for the input process. You can implement the following simple nesting:


(define (plus first second)    (lambda (f)        (lambda (x)             ((first f) ((second f) x)))))



In the end, you may have questions about the significance of such a count?

In fact, what we see here is a more advanced understanding of "Numbers". We can use a simple method to reduce the order. We can define the following process close to boring:

  (define (f x)    (display "*")    )


This process only accepts one parameter, and the process body does not do anything, But prints a * number.


Because Qiu Qi's count actually calculates the number of calls to the process, if we use the above process in Qiu Qi's count, you can intuitively feel the concept of "Number" in the Qiqi count through the printed * number.


For example, the execution (two f) 'A) will print 2 * numbers.

Execute (one f) 'A) to print 1.


For more call examples, refer to the following code:


(define (start-test-2-6)    (display "going to display 1:")(newline)  ((one f) 'a)(newline)  (display "going to display 2:")(newline)  ((two f) 'a) (newline)  (display "going to display 1+2:")(newline)  (((plus one two) f) 'a)  (newline)  (display "going to display 1+2+2")(newline)  (((plus (plus one two) two) f) 'a)  (newline)  (display "end.") (newline))



Eighth grade mathematics book exercise 26 answers to problems and solutions

I will answer 6th: Set the length of the ladder to x meters, then there will be x square = (3 points 1x) square + 4.8 square. The answer is x = 25.92 under the root number, and x is greater than 5, so the ladder is 5 Tall.
 
What is the problem solving process? Multiply it by 36 and divide it by 26

3.6 × (3.6-2.6) limit 2 = 1.8
 

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.