SICP 2.34多项式加法
来源:互联网 发布:周带鱼 知乎 编辑:程序博客网 时间:2024/06/02 02:38
对于一个多项式:
求值,我们可以化简找出其规律,利用Horner 规则化简:
可以明显看出多项式的递归规律:从an开始,(+ (* an x) a(n-1)),下一个也是如此,直到a0。
之前建立的accumulate过程,也有相似的递归性,应该是一类过程,accumulate的原始定义:
(define (accumulate op initial sequence) (if (null? sequence) initial (op (car sequence) (accumulate op initial (cdr sequence)))))
op 是对数据的操作,从简单的加减乘除到复杂的自定义运算。
initial是初始数据,说明它是个什么的累加,比如数或者表
sequence是待处理的数据
那么结合此多项式的计算规律,对于多项式的计算可以抽象成代码:
(define (hover_eval x sequence) (accumulate (lambda (this_coeff higher_terms) (+ (* x this_coeff) higher_terms)) 0 sequence))
手动模拟线性递归过程:
(horner-eval 2 (list 1 3 0 5 0 1))(accumulate (lambda (this-coeff higher-terms) <??>) 0 (list 1 3 0 5 0 1))(+ 1 (* 2 (accumulate (lambda (this-coeff higher-terms) <??>) 0 (list 3 0 5 0 1))))(+ 1 (* 2 (+ 3 (* 2 (accumulate (lambda (this-coeff higher-terms) <??>) 0 (list 0 5 0 1))))))(+ 1 (* 2 (+ 3 (* 2 (+ 0 (* 2 (accumulate (lambda (this-coeff higher-terms) <??>) 0 (list 5 0 1))))))))(+ 1 (* 2 (+ 3 (* 2 (+ 0 (* 2 (+ 5 (* 2 (accumulate (lambda (this-coeff higher-terms) <??>) 0 (list 0 1))))))))))(+ 1 (* 2 (+ 3 (* 2 (+ 0 (* 2 (+ 5 (* 2 (+ 0 (* 2 (accumulate (lambda (this-coeff higher-terms) <??>) 0 (list 1))))))))))))(+ 1 (* 2 (+ 3 (* 2 (+ 0 (* 2 (+ 5 (* 2 (+ 0 (* 2 (+ 1 (* 2 (accumulate (lambda (this-coeff higher-terms) <??>) 0 '())))))))))))))(+ 1 (* 2 (+ 3 (* 2 (+ 0 (* 2 (+ 5 (* 2 (+ 0 (* 2 (+ 1 (* 2 0))))))))))))(+ 1 (* 2 (+ 3 (* 2 (+ 0 (* 2 (+ 5 (* 2 (+ 0 (* 2 (+ 1 0)))))))))))(+ 1 (* 2 (+ 3 (* 2 (+ 0 (* 2 (+ 5 (* 2 (+ 0 (* 2 1))))))))))(+ 1 (* 2 (+ 3 (* 2 (+ 0 (* 2 (+ 5 (* 2 (+ 0 2)))))))))(+ 1 (* 2 (+ 3 (* 2 (+ 0 (* 2 (+ 5 (* 2 2))))))))(+ 1 (* 2 (+ 3 (* 2 (+ 0 (* 2 (+ 5 4)))))))(+ 1 (* 2 (+ 3 (* 2 (+ 0 (* 2 9))))))(+ 1 (* 2 (+ 3 (* 2 18))))(+ 1 (* 2 (+ 3 36)))(+ 1 (* 2 39))(+ 1 78)79
0 0
- SICP 2.34多项式加法
- SICP 练习2.34 多项式求值(horner规则)
- 多项式加法
- 多项式加法
- 多项式加法
- 多项式加法
- 多项式加法
- 多项式加法
- 多项式加法
- 多项式加法
- 多项式加法
- 多项式加法
- 多项式加法
- 多项式加法
- 多项式加法
- 多项式加法
- 多项式加法
- 多项式加法
- Sort (1) -- 常用排序
- 绝对路径与相对路径
- 浅谈 hive 的结构
- 洛谷P1605 迷宫
- 抗战八年应改为抗战十四年
- SICP 2.34多项式加法
- HDU 5616 Jam's balance dp, bitset
- 为QML创建C++插件
- 我的Android开发探索之环境搭建
- 加快git clone
- jQuery操作select(设置某个option为选中状态)
- Python中re的match、search、findall、finditer区别
- 问题四十八:怎么用ray tracing画superhyperboloid(超级双曲面)
- LCD驱动(FrameBuffer)实例开发讲解