Exercise 1.20 greatest common divisor algorithm

Source: Internet
Author: User
Tags gcd greatest common divisor

The process, a procedure generates is of course dependent on the rules used by the interpreter. As an example, consider the iterative GCD procedure given above. Suppose we were to interpret this procedure using Normal-order evaluation, as discussed on section 1.1.5. (The normal-order-evaluation rule for if was described in Exercise 1.5.) Using the substitution method (for normal order), illustrate the process generated in evaluating (GCD 206) and indicate The remainder operations that is actually performed. How many remainder operations is actually performed in the Normal-order evaluation of (GCD 206 40)? In the Applicative-order evaluation?

Using applicative-order:

GCD (206, 40)

=GCD (40, 6)

=GCD (6,4)

=GCD (4,2)

=GCD (2,0)

A total of 4 recursion, so the use of the Applicative-order,remainder function was called 4 times.

With Normal-order

GCD (206, 40)

=GCD (+, R (206,40))//here to determine whether R (206,40) is zero, one remainder calculation

=GCD (

R (206,40),

R (+, R (206,40))

)//Determine if R (206,40) is zero, with two remainder

=GCD (

R (206, 40),

R

R (206,40),

R (R (206, 40))

)//judgment is zero, there are 4 times remainder calculation

)

=GCD (

R

R (206,40),

R (R (206, 40))

),//return result, 4 calculations

R

R (206, 40),

R

R (206,40),

R (R (206, 40))

),

)//judgment is zero, there are 7 times remainder calculation

)

A total of 1+2+4+7=14 times remainder call calculation

Exercise 1.20 greatest common divisor algorithm

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.