Download presentation

Presentation is loading. Please wait.

Published byNatasha Beddingfield Modified about 1 year ago

1
Polynomial Evaluation

2
Straightforward Evaluation P(x) = 3x 5 +2x 4 +7x 3 +8x 2 +2x+4P(x) = 3x 5 +2x 4 +7x 3 +8x 2 +2x+4 t1 = (3*x*x*x*x*x)t1 = (3*x*x*x*x*x) t2 = t1 + (2*x*x*x*x)t2 = t1 + (2*x*x*x*x) t3 = t2 + (7*x*x*x)t3 = t2 + (7*x*x*x) t4 = t3 + (8*x*x)t4 = t3 + (8*x*x) P = t4 +(2*x) + 4P = t4 +(2*x) + 4 15 Multiplications, 5 Additions15 Multiplications, 5 Additions

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

4
Horner’s Rule P(x) = 3x 5 +2x 4 +7x 3 +8x 2 +2x+4P(x) = 3x 5 +2x 4 +7x 3 +8x 2 +2x+4 t1 = (3*x) + 2t1 = (3*x) + 2 t2 = (t1*x) + 7t2 = (t1*x) + 7 t3 = (t2*x) + 8t3 = (t2*x) + 8 t4 = (t3*x) + 2t4 = (t3*x) + 2 P = (t4*x) + 4P = (t4*x) + 4 5 Multiplications, 5 Additions5 Multiplications, 5 Additions

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

6
For Power = 15 6 Multiplications by Squaring Algorithm6 Multiplications by Squaring Algorithm An Alternative Procedure:An Alternative Procedure: p = x * xp = x * x p = p * p *xp = p * p *x p = p * p * pp = p * p * p 5 Multiplications by Factorization5 Multiplications by Factorization

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google