博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SICP学习笔记 2.3.2 实例:符号求导
阅读量:4029 次
发布时间:2019-05-24

本文共 2589 字,大约阅读时间需要 8 分钟。

    练习2.56

(define (deriv exp var)  (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))))	((exponentiation? exp)	 (make-product	  (make-product (exponent exp)			            (make-exponentiation (base exp) (- (exponent exp) 1)))	  (deriv (base exp) var)))		(else (error "unknown expression type -- DERIV" exp))))

 

    练习2.57

;; 加法(define (make-sum-list x list)  (if (null? list)      x      (make-sum x		            (make-sum-list (car list) (cdr list)))))(define (make-sum-all x . y)  (make-sum-list x y));; 被加数  (define (augend-list s)  (let ((l (length s)))    (cond ((= l 1) 0)	        ((= l 2) (cadr s))	        ((= l 3) (augend s))	        (else (cons '+ (cddr s))))))	        ;; 乘法(define (make-product-list x list)  (if (null? list)      x      (make-product x		                (make-product-list (car list) (cdr list)))))(define (make-product-all x . y)  (make-product-list x y));; 被乘数 (define (multiplicand-list p)  (let ((l (length p)))    (cond ((= l 1) 1)	        ((= l 2) (cadr p))	        ((= l 3) (multiplicand p))	        (else (cons '* (cddr p)))))) 	        ;; 使用新的加法和乘法构造求导过程(define (deriv exp var)  (cond ((number? exp) 0)	((variable? exp)	 (if (same-variable? exp var) 1 0))	((sum? exp)	 (make-sum-all (deriv (addend exp) var)			           (deriv (augend-list exp) var)))	((product? exp)	 (make-sum-all	  (make-product-all (multiplier exp)			                (deriv (multiplicand-list exp) var))	  (make-product-all (deriv (multiplier exp) var)			                (multiplicand-list exp))))	((exponentiation? exp)	 (make-product-all	  (make-product-all (exponent exp)			                (make-exponentiation (base exp) (- (exponent exp) 1)))	  (deriv (base exp) var)))		(else (error "unknown expression type -- DERIV" exp))))1 ]=> (deriv '(* x y (+ x 3)) 'x)	;Value : (+ (* x y) (* y (+ x 3)))

 

    练习2.58

;; 修改加法的构造函数、选择函数和谓词(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))))	      (else (list a1 '+ a2))))(define (addend s) (car s))(define (augend s) (caddr s))(define (sum? x)  (and (pair? x) (eq? (cadr x) '+));; 使用类似的方法修改乘法的构造函数、选择函数和谓词1 ]=> (deriv '((x * y) * ( x + 3)) 'x);Value : ((x * y) + (y * (x + 3)))1 ]=> (deriv '(x + (3 * (x + (y + 2)))) 'x) ;Value: 4

 

    练习2.59

;; 暂无

转载地址:http://fovbi.baihongyu.com/

你可能感兴趣的文章
剑指offer算法题分析与整理(三)
查看>>
部分笔试算法题整理
查看>>
Ubuntu 13.10使用fcitx输入法
查看>>
pidgin-lwqq 安装
查看>>
mint/ubuntu安装搜狗输入法
查看>>
C++动态申请数组和参数传递问题
查看>>
opencv学习——在MFC中读取和显示图像
查看>>
retext出现Could not parse file contents, check if you have the necessary module installed解决方案
查看>>
pyQt不同窗体间的值传递(一)——对话框关闭时返回值给主窗口
查看>>
linux mint下使用外部SMTP(如网易yeah.net)发邮件
查看>>
北京联通华为光猫HG8346R破解改桥接
查看>>
python使用win32*模块模拟人工操作——城通网盘下载器(一)
查看>>
python append 与浅拷贝
查看>>
Matlab与CUDA C的混合编程配置出现的问题及解决方案
查看>>
2017阿里内推笔试题--算法工程师(运筹优化)
查看>>
python自动化工具之pywinauto(零)
查看>>
python自动化工具之pywinauto(四)——批量转换exe视频
查看>>
python一句话之利用文件对话框获取文件路径
查看>>
PaperDownloader——文献命名6起来
查看>>
PaperDownloader 1.5.1——更加人性化的文献下载命名解决方案
查看>>