example of straight-line program
SLPs can be used to shorten computations of algebraic expressions.
For example: The product may be evaluated in fewer than 19 multiplication.
Let and , for .Evidently
However, we do not evaluate as . For instance, to compute wefollow the program. Expand the first the expression from the left first until wereach an term:
Now evaluate the terminal parts and store all the intermediate results:
The total number of multiplications here was 3, rather than 8.
Then can be encoded as an SLP using the binary number for 19.
First, write 19 in binary (base 2):
or rather in the usual binary notation.
Remark. To evaluate this SLP we had to store intermediate values thatwere ultimately not part of the final answer. In this example the final answerwas much larger than the intermediate steps and so we are free to assume thatany memory used in the process was far less than what was required for the finaloutcome. However, it is entirely possible that evaluating an SLP will at timesuse far more memory than required by the final product and may therefore beinfeasible.