#!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. js固定小数位数 .toFixed()

    toFixed(num)法可把 Number 四舍五入为指定小数位数的数字. num为需要固定的位数 var num=2;console.log(num.toFixed(2));//2.00;var ...

  2. 千万不要运行的 Linux 命令

    本文中列出的命令绝对不可以运行,即使你觉得很好奇也不行,除非你是在虚拟机上运行(出现问题你可以还原),因为它们会实实在在的破坏你的系统.所以不在root等高级管理权限下执行命令是很好的习惯. 本文的目 ...

  3. 后门技术和Linux LKM Rootkit详解

    2010-01-15 10:32 chinaitlab chinaitlab 字号:T | T 在这篇文章里, 我们将看到各种不同的后门技术,特别是 Linux的可装载内核模块(LKM). 我们将会发 ...

  4. HDU 2822

    Dogs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  5. SGU 204. Little Jumper

    204. Little Jumper time limit per test: 0.5 sec. memory limit per test: 65536 KB input: standard out ...

  6. git合并分支理解和常用命令的总结

    原文参考:https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 工作区和暂存区 工作区 ...

  7. Java 继承内部类

    大家有没有想过内部类究竟能不能被继承呢? public class Main { public static void main(String[] args){ Outer outer = new O ...

  8. 《java虚拟机》----java内存区域与内存溢出异常

    No1: java虚拟机所管理的内存将会包括以下几个运行时数据区域 1.方法区 2.虚拟机栈 3.本地方法栈 4.堆 5.程序计数器 No2: 程序计数器: 程序计数器(Program Counter ...

  9. Python的环境搭建——万丈高楼平地起

    Python的环境搭建,远程连接,端口映射,虚拟机 写在正文之前 python语言的开发环境还是相对比较简单的,但是也是有很多需要注意的地方,对于初次接触python或者以前很少用到虚拟环境的朋友来说 ...

  10. Codeforces Round #436 (Div. 2) E. Fire(dp 记录路径)

    E. Fire time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...