#!r6rs

( import ( rnrs base ( 6 ) )

         ( rnrs io simple ( 6 ) ) )





( define ( deriv exp var )

   ( define ( variable? x )

      ( symbol? x ) )

   

   ( define ( =number? exp num )

      ( and ( number? exp )

            ( = exp num ) ) )

   

   ( define ( same-variable? x1 x2 )

      ( and ( variable? x1 )

            ( variable? x2 )

            ( eq? x1 x2 ) ) )

   

   ( define ( make-sum a1 a2 )

      ( cond ( ( =number? a1 0 )

               a2 )

             ( ( =number? a2 0 )

               a1 )

             ( ( and ( number? a1 )

                     ( number? a2 ) )

               ( + a1 a2 ) )

             ( else 

               ( list '+ a1 a2 ) ) ) )

   

   ( define ( make-product m1 m2 )

      ( cond ( ( or ( =number? m1 0 )

                    ( =number? m2 0 ) ) 

               0 )

             ( ( =number? m1 1 ) 

               m2 )

             ( ( =number? m2 1 )

               m1 )

             ( ( and ( number? m1 )

                     ( number? m2 ) ) 

               ( * m1 m2 ) )

             ( else

               ( list '* m1 m2 ) ) ) )

   

   ( define ( sum? x )

      ( and ( pair? x )

            ( eq? ( car x ) '+ ) ) )

   

   ( define ( addend s )

      ( cadr s ) )

   

   ( define ( augend s )

      ( caddr s ) )

   

   ( define ( product? x )

      ( and ( pair? x )

            ( eq? ( car x ) '* ) ) )

   

   ( define ( multiplier p )

      ( cadr p ) )

   

   ( define ( multiplicand p )

      ( caddr p ) )

   

   ( cond ( ( number? exp ) 0 )

          ( ( variable? exp )

            ( if ( same-variable? exp var ) 1

                 0 ) )

          ( ( sum? exp )

            ( make-sum ( deriv ( addend exp ) var )

                       ( deriv ( augend exp ) var ) ) )

          ( ( product? exp )

            ( make-sum ( make-product ( multiplier exp )

                                      ( deriv ( multiplicand exp ) var ) )

                       ( make-product ( deriv ( multiplier exp ) var )

                                      ( multiplicand exp ) ) ) )

          ( else 

            ( error "unknown expression type: DERIV" exp ) ) ) )



The differentiation program with abstract data的更多相关文章

  1. ADT(abstract data types)抽象数据类型

    1.What is it? An abstract data type is a set of objects together with a set of operations. 抽象数据类型是带有 ...

  2. 20182320《Program Design and Data Structures》Learning Summary Week9

    20182320<Program Design and Data Structures>Learning Summary Week9 1.Summary of Textbook's Con ...

  3. Rocket - debug - TLDebugModuleInner - Abstract Data

    https://mp.weixin.qq.com/s/DOLkEi-_qQt6lWOhJ2hxVQ 简单介绍TLDebugModuleInner中抽象数据寄存器的实现. 1. abstractData ...

  4. STM8S——Flash program memory and data EEPROM

    1.简介 STM8S内部的FLASH程序存储器和数据EEPROM是由一组通用寄存器来控制的:所以我们可以通过这些通用寄存器来编程或擦除存储器的内容.设置写保护.或者配置特定的低功耗模式.我们也可以自己 ...

  5. Abstract Data Types in C

    Interface declares operations, not data structure Implementation is hidden from client (encapsulatio ...

  6. Abstract Data Type

  7. 20162314 《Program Design & Data Structures》Learning Summary Of The Fifth Week

    20162314 2017-2018-1 <Program Design & Data Structures>Learning Summary Of The Fifth Week ...

  8. detect data races The cost of race detection varies by program, but for a typical program, memory usage may increase by 5-10x and execution time by 2-20x.

    小结: 1. conflicting access 2.性能危害 优化 The cost of race detection varies by program, but for a typical ...

  9. Core Java Volume I — 3.3. Data Types

    3.3. Data TypesJava is a strongly typed language(强类型语音). This means that every variable must have a ...

随机推荐

  1. LeetCode862. Shortest Subarray with Sum at Least K

    Return the length of the shortest, non-empty, contiguous subarray of A with sum at least K. If there ...

  2. python datetime 时区(timezone) dateutil

    记录下python中的时区问题, 代码如下:  包括datetime.datetime对象使用不同的时区,以及在不同时区间转换. from datetime import datetime from ...

  3. Spring MVC数据绑定(二)

    之前学习了SpringMVC数据绑定的基本知识和简单数据绑定以及POJO类型数据的绑定.接下来总结剩下的一些数据类型的绑定 1. 绑定包装POJO 所谓的包装POJO,就是在一个POJO中包含另一个简 ...

  4. Hadoop(一)Hadoop的简介与源码编译

    一 Hadoop简介 1.1Hadoop产生的背景 1. HADOOP最早起源于Nutch.Nutch的设计目标是构建一个大型的全网搜索引擎,包括网页抓取.索引.查询等功能,但随着抓取网页数量的增加, ...

  5. poj1562 Oil Deposits(DFS)

    题目链接 http://poj.org/problem?id=1562 题意 输入一个m行n列的棋盘,棋盘上每个位置为'*'或者'@',求'@'的连通块有几个(连通为8连通,即上下左右,两条对角线). ...

  6. 【WPF】OnApplyTemplate

    操作模板控件 在做WPF开发的时候,我们通常因为满足不同的需求会开发一些自定义控件来满足需要,我们会自定义模板来定义控件的外观,添加命令和路由事件来给控件添加行为,那如何在模板中查找元素并关联事件处理 ...

  7. ref:【干货分享】PHP漏洞挖掘——进阶篇

    ref:http://blog.nsfocus.net/php-vulnerability-mining/ [干货分享]PHP漏洞挖掘——进阶篇 王陶然     从常见的PHP风险点告诉你如何进行PH ...

  8. 转:win32下的堆管理系统

    转:https://bbs.pediy.com/thread-224136.htm 准备刷漏洞战争中的堆溢出部分,但是对于堆的了解较少,在这里记录一下关于堆的学习记录,有错误请各位大大拍砖 参考: & ...

  9. 第一个ajax小demo

    第一个ajax小demo 文章来源:http://blog.csdn.net/magi1201/article/details/44569657

  10. MySQL常用知识

    1.MySQL常用引擎有哪些? A:MySQL常用的引擎有InnoDB.MyISAM.Memory,默认时InnoDB InnoDB:磁盘表,支持事务,支持行级锁,B+Tree索引 优点:具有良好的A ...