I have a loop in which several values of a function are computed, depending on the values for that function that were computed in the previous iteration of the loop. This could be implemented recursively, but it would result in very many downvalues for the function. I want to save the memory that those downvalues would occupy. My plan is to maintain two functions; to overwrite the old one with the new one in each iteration of the loop; to clear the new function, and then to compute the values of the new function depending on the values of the old function.
But unfortunately in spite of my using "Set" instead of "SetDelayed", it seems that as soon as the new function is Cleared, the old function forgets its definition:
Clear[funA, funB] funA = 7 funB = funA funB Clear[funA] funB
gives the output:
7 funA 7 funA
all of which is what I wanted, except that I want the last output to be "7", not "funA".
I have experimented with "SetDelayed" (:=) instead of "Set" (=) and with "Evaluate", but to no avail. What am I doing wrong ?
I have a version of my code that works perfectly, in which instead of having two functions and Clearing the old function, I have a single function, and in each iteration of the loop I "Unset" its values that are no longer required. However, the Unsetting process goes value-by-value in a loop of its own, and takes quite a while.