Easiest way to keep my library nice, is to naively call some functions many times with same parameters. Doing so prevents from zoo of (library-)global variables and complicated initialisation functions. I would expect Mathematica to optimise somehow functions calls with same parameters, but it does not appear to do that.
Fallowing example is ran on Mathematica 9:
rands = Array[Random[] &, {2500, 2500}];
Timing[Inverse[rands];]
Timing[Inverse[rands];]
Timing[Inverse[rands];]
Timing[Inverse[rands];]
Output:
{0.687500, Null}
{0.687500, Null}
{0.687500, Null}
{0.687500, Null}
Is there a way to make Mathematica optimise revaluation with same parameters? What kind of nice workaround would you recommend?
EDIT As I learned, the keyword I needed was memoization. I found this post very useful. Thanks!
Memoization– Dr. belisarius May 18 '14 at 15:01