optimization - Algorithm for optimizing computation of an arithmetic expression -


suppose have expression formed integer variables , arithmetic operations: addition, subtraction , multiplication. know each multiplication takes m seconds, , each addition/substraction takes seconds. there algorithm compute expression in efficient way arbitrary assignment variables? (assume can store in memory 1 number).

example:

m=10

a=1

expression: a*a+a*b+b*b.

initially, has 3 multiplications , 2 additions, total time 3*m+2*a=32

however, can build equivalent expression (a+b)*(a+b)-a*b has 2 multiplications , 3 additions, total computation time 2*m+3*a=23.

you want apply sum product algorithm.

see:

http://www.isiweb.ee.ethz.ch/papers/docu/aloe-2001-1.pdf


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -