zoukankan      html  css  js  c++  java
  • Exercise 1.20 最大公约数算法

    The process that 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 in section 1.1.5. (The normal-order- evaluation rule for if is described in exercise 1.5.) Using the substitution method (for normal order), illustrate the process generated in evaluating (gcd 206 40) and indicate the remainder operations that are actually performed. How many remainder operations are actually performed in the normal- order evaluation of (gcd 206 40)? In the applicative-order evaluation? 

    采用Applicative-order

    gcd(206, 40)

    =gcd(40, 6)

    =gcd(6,4)

    =gcd(4,2)

    =gcd(2,0)

    共4次递归,因此,采用Applicative-order,Remainder函数被调用4次。

    采用Normal-order

    gcd(206, 40)

    =gcd( 40, R(206,40)) //这里判断R(206,40)是否为零,有一次Remainder计算

    =gcd(

              R(206,40),

              R(40, R(206,40))

      )//这里判断R(40, R(206,40))是否为零,有两次Remainder计算

    =gcd(

      R(40, R(206, 40)),

          R(

                R(206,40),

                R(40, R(206, 40))

          )//判断是否为零,有4次Remainder计算

    )

    =gcd(

          R(

                R(206,40),

                R(40, R(206, 40))

          ),//返回结果,有4次计算

         R(

                R(40, R(206, 40)),

                R(

                    R(206,40),

                    R(40, R(206, 40))

                ),

         )//判断是否为零,有7次Remainder计算

    )

    总共有1+2+4+7=14次Remainder调用计算

  • 相关阅读:
    13 款开源的全文检索引擎
    Laravel5.5 Jwt 1.0 beta 配置
    Laravel SQL 查询语句集锦
    laravel在中间件内生成的变量如何传到控制器
    laravel中的自定义函数的加载和第三方扩展库加载
    laravel5.5 dingo/api+jwt-auth
    微信小程序之使用checkbox
    微信小程序之使用wx:for遍历循环
    微信小程序之页面导航栏
    微信小程序之数据缓存
  • 原文地址:https://www.cnblogs.com/linghuaichong/p/4043868.html
Copyright © 2011-2022 走看看