1 / 6

Efficient Computations and Horner’s Method

Efficient Computations and Horner’s Method. Evaluating Expressions Mathematics vs Computer Science Mathematics makes no distinction between what a positive integral power means and repeated multiplication. For example, in mathematics we see the following two expressions as identical:

bonita
Télécharger la présentation

Efficient Computations and Horner’s Method

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Efficient ComputationsandHorner’s Method

  2. Evaluating Expressions Mathematics vs Computer Science Mathematics makes no distinction between what a positive integral power means and repeated multiplication. For example, in mathematics we see the following two expressions as identical: x3 and x·x·x There is a big difference when it come to applying this and have a machine do this. One of the methods is actually preferred over the other in a computer because it will increase both speed and accuracy. Accuracy Evaluating x·x·xis more accurate than x3 because the expression x·x·x is evaluated using a hardware device (inside the ALU) that will exactly calculate the value if the numbers stay within the machines precision (i.e. they number is not too big or too small). This is not true in Mathematica, but is true in most compiled languages like JAVA and C. The expression x3 is estimated using software. For most machine computations this is ok (machine words have gotten long).

  3. Speed Speed can be improved first by keeping the processing in the ALU instead of the memory which performs slower. This is why multiplication is preferred over exponentiation. There are ways to code expressions that cut down on the number of computations that even need to be done. ALU RAM Memory Control Unit Disk Memory CPU Computer Horner’s form of a polynomial Any polynomial in the form a0+a1x+a2x2+…+anxn can be written a0+x(a1+x(a2+x(…+anx))…) In this form we will reduce the number of computations that need to be done.

  4. Example: 5+7x+9x2+2x3 (Standard Form) • Horner’s Form:5+(7+(9+2·x)·x)·x • If you count the number of operation that are performed there are: • Standard form: 3 additions and 6 multiplications 7·x,9·x·x,2·x·x·x • Horner’s form: 3 additions and 3 multiplications • From this we see that Horner’s form for evaluating a polynomial is an improvement over the standard way. • Horner’s Algorithm • Here is the algorithm for Horner’s form • get list of coefficients {a0,a1,a2,…,an} • express=0 • For i=n,i0, i-1 • express=ai+ x·express

  5. Improvements in Horner's Algorithm There are several ways to improve Horner's Algorithm when it comes to how much multiplication needs to be done (i.e. how the powers are evaluated). A binary approach can be used to limit the number of computations. Evaluating this expression in this form requires: 13 additions and 13 multiplications Breaking the number 13 into its binary representation we see we can dramatically cut down on the number of computations required. 1 addition and 5 multiplications This gives a total of 6 computations compared to the 26 that were required before. This uses only about 23% of the computations that were previously required.

  6. Find the most efficient way to evaluate the polynomial to the right. Apply the standard Horner Method first. From this we see the only powers of (x-7)that are required are 1, 2 and 4. We rewrite the polynomial using only the powers required from the standard Horner's Form.

More Related