On an imperative programming language, let us consider the following program:
for i in 0..N { // N is the length of the arrays A, B, C.
A[i] = A[i] + B[i];
}
for i in 0..N {
A[i] = A[i] + C[i];
}
This program just sums three arrays $A + B + C$ component-wisely and store it to $A$.
We can easily transform this program into the following equivalent one:
for i in 0..N {
let tmp = A[i] + B[i];
A[i] = tmp + C[i];
}
I think the latter code is more efficient than the former because we can decrease the number of memory accesses.
Now I have a question.
What is the name of this type of program transform or program optimization? Can we also call this deforestation?
tmp
is needed. $\endgroup$