1 / 6

Polynomial Evaluation

Polynomial Evaluation. Straightforward Evaluation . P(x) = 3x 5 +2x 4 +7x 3 +8x 2 +2x+4 t1 = (3*x*x*x*x*x) t2 = t1 + (2*x*x*x*x) t3 = t2 + (7*x*x*x) t4 = t3 + (8*x*x) P = t4 +(2*x) + 4 15 Multiplications, 5 Additions. A Little Smarter. P(x) = 3x 5 +2x 4 +7x 3 +8x 2 +2x+4

lucie
Download Presentation

Polynomial Evaluation

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. Polynomial Evaluation

  2. Straightforward Evaluation • P(x) = 3x5+2x4+7x3+8x2+2x+4 • t1 = (3*x*x*x*x*x) • t2 = t1 + (2*x*x*x*x) • t3 = t2 + (7*x*x*x) • t4 = t3 + (8*x*x) • P = t4 +(2*x) + 4 • 15 Multiplications, 5 Additions

  3. A Little Smarter • P(x) = 3x5+2x4+7x3+8x2+2x+4 • t1 := 4; xp := x; • t2 := (2*xp) + t1; xp := xp * x; • t3 := (8*xp) + t2; xp := xp * x; • t4 := (7*xp) + t3; xp := xp * x; • t5 := (2*xp) + t4; xp := xp * x; • P := (3*xp) + t5; • 9 Multiplications, 5 Additions

  4. Horner’s Rule • P(x) = 3x5+2x4+7x3+8x2+2x+4 • t1 = (3*x) + 2 • t2 = (t1*x) + 7 • t3 = (t2*x) + 8 • t4 = (t3*x) + 2 • P = (t4*x) + 4 • 5 Multiplications, 5 Additions

  5. Computing Powers xp := x; pwork := power; Res := 1; While pwork > 0 Do If pwork mod 2 = 1 then Res := Res * xp; End If xp := xp * xp; pwork := pwork / 2; /* integer division */ End While

  6. For Power = 15 • 6 Multiplications by Squaring Algorithm • An Alternative Procedure: • p = x * x • p = p * p *x • p = p * p * p • 5 Multiplications by Factorization

More Related