释义 |
strength reduction
strength reductionAn optimisation where a function of some systematicallychanging variable is calculated more efficiently by usingprevious values of the function. In a procedural languagethis would apply to an expression involving a loop variableand in a declarative language it would apply to the argumentof a recursive function. E.g.
f x = ... (2**x) ... (f (x+1)) ...
==>
f x = f' x (2**x)wheref ' x z = ... z ... (f' (x+1) 2*z) ...
Here the expensive operation (2**x) has been replaced by thecheaper 2*z in the recursive function f'. This maintains theinvariant that z = 2**x for any call to f'. |