[This was initially on matrices, but I guess it applies to any variable generically]
Say we have Var1 * Var2 * Var3 * Var4.
One of them sporadically changes, which one of them is random.
Is it possible to minimize multiplications?
If I do
In case Var1 changes: newVar1 * savedVar2Var3Var4
I noticed that then I need to recalculate savedVar2Var3Var4 each time Var2, Var3, Var4 change.
Would that re-calculation of ‘saved combinations’ defy the purpose?
Yes, it is possible.
For scalars there will probably be no benefit. For largish matrix math, you could compute and store: Var1*Var2 and Var3*Var4. Your result is the product of these 2 things. Now when one changes you only need to update 2 products instead of 3. Update only one of the 2 stored products depending who change, and update the result.
There you have it, 2 multiplications instead of 3 with each update. This will only benefit you if the common case really is for only one of them to update, but if that’s true it should help a lot.