The differentiation program with abstract data
#!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的更多相关文章
- ADT(abstract data types)抽象数据类型
		1.What is it? An abstract data type is a set of objects together with a set of operations. 抽象数据类型是带有 ... 
- 20182320《Program Design and Data Structures》Learning Summary Week9
		20182320<Program Design and Data Structures>Learning Summary Week9 1.Summary of Textbook's Con ... 
- Rocket - debug - TLDebugModuleInner - Abstract Data
		https://mp.weixin.qq.com/s/DOLkEi-_qQt6lWOhJ2hxVQ 简单介绍TLDebugModuleInner中抽象数据寄存器的实现. 1. abstractData ... 
- STM8S——Flash program memory and data EEPROM
		1.简介 STM8S内部的FLASH程序存储器和数据EEPROM是由一组通用寄存器来控制的:所以我们可以通过这些通用寄存器来编程或擦除存储器的内容.设置写保护.或者配置特定的低功耗模式.我们也可以自己 ... 
- Abstract Data Types in C
		Interface declares operations, not data structure Implementation is hidden from client (encapsulatio ... 
- Abstract Data Type
- 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 ... 
- 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 ... 
- 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 ... 
随机推荐
- 在Ubuntu上安装Redis  MySQL    MongoDB  memcached Nginx
			1.安装Redis sudo apt-get install redis-server 2.安装MySQL sudo apt-get install mysql-server 3.安装MongoDB ... 
- 转:mysql日志(Windows下开启Mysql慢查询、通用日志)
			一.Windows下开启Mysql慢查询详解 //show variables like '%quer%';查询是否开启了慢查询!! 第一步:修改my.ini(mysql配置文件) 在my.ini中 ... 
- 使用CEPH RGW admin ops API 进行用户user AK/SK管理的秘诀
			需求: 云平台面板上需要支持为不同的用户创建不同的RGW 的AK/SK用户秘钥,以完成对象存储的用户隔离,并可以管理bucket和查看bucket容量信息. 分析:查阅CEPH官网文档 S3 API ... 
- 洛谷P1876开灯 题解
			题目传送门 这道题目是道数学题(下面也写了),所以仔细研究发现:N轮之后,只有是小于N的完全平方数的灯能亮着.所以接下来就好办了: #include<bits/stdc++.h> usin ... 
- php面向对象中public与var的区别
			public和var的作用差不多 因为 var定义的变量如果没有加protected 或 private则默认为public php4 中一般是用 varphp5 中就一般是用 public了 现在基 ... 
- 谷歌翻译python接口
			项目地址: https://github.com/ssut/py-googletrans 安装: sudo pip install googletrans 使用: #!/usr/bin/python ... 
- Saltstack 介绍、安装、配置语法(一)
			Slatstack 介绍 官网:https://saltstack.com/ 官方源:http://repo.saltstack.com/ (介绍各操作系统安装方法) yum install htt ... 
- email 校验
			email 校验: javascript: /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/ java: ^([a- ... 
- 1. MNIST读取数据
			%pylab inline Populating the interactive namespace from numpy and matplotlib 在Yann LeCun教授的网站中(http: ... 
- 关于如何在 Unity 的 UI 菜单中默认创建出的控件 Raycast Target 属性默认为 false
			关于如何在 Unity 的 UI 菜单中默认创建出的控件 Raycast Target 属性默认为 false 我们在 Unity 中通过 UI 菜单创建的各种控件,比如 Text, Image 等, ... 
