Horner's rule

 

Horner's Rule for Polynomials

A general polynomial of degree $n$ can be written as
/begin{displaymath}
P(x) = a_0 + a_1 x + a_2 x^2 + ... + a_n x^n = /sum_{i=0}^n a_i x^i
/end{displaymath}(1)

If we use the Newton-Raphson method for finding roots of the polynomial we need to evaluate both $P(x)$ and its derivative $P^/prime(x)$ for any $x$.

It is often important to write efficient algorithms to complete a project in a timely manner. So let us try to design the algorithm for evaluating a polynomial so it takes the fewest flops (floating point operations, counting both additions and multiplications). For concreteness, consider the polynomial

/begin{displaymath}
7x^3 + 5x^2 - 4x + 2.
/end{displaymath}

The most direct evaluation computes each monomial $a_i x^i$ one by one. It takes $i$ multiplications for each monomial and $n$ additions, resulting in $n(n+3)/2$ flops for a polynomial of degree $n$. That is, the example polynomial takes three flops for the first term, two for the second, one for the third, and three to add them together, for a total of nine. If we reuse $x^i$ from monomial to monomial we can reduce the effort. In the above example, working backwards, we can save $x^2$ from the second term and get $x^3$ for the first in one multiplication by $x$. This strategy reduces the work to $3n-1$ flops overall or eight flops for the example polynomial. For short polynomials, the difference is trivial, but for high degree polynomials it is huge. A still more economical approach regroups and nests the terms as follows:

/begin{displaymath}
2 - 4x + 5x^2 + 7x^3 = 2 + x[-4 + x(5 + 7x)].
/end{displaymath}

(Check the identity by multiplying it out.) This procedure can be generalized to an arbitrary polynomial. Computation starts with the innermost parentheses using the coefficients of the highest degree monomials and works outward, each time multiplying the previous result by $x$ and adding the coefficient of the monomial of the next lower degree. Now it takes $2n$ flops or six for the above example. This is the efficient Horner's algorithm.
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值