For questions related to user defined caching mechanisms, memoization, in particular.
For questions related to user defined caching mechanisms, memoization, in particular. Questions dealing with the structure x := x = expr should use this tag.
For questions about the internal caches in Mathematica, see caching.
I have a function defined something like this:
f[x_] := Module[...];
I can easily write a memoized version of it like this:
f2[x_] := f2[x] = f[x];
And then replace every instance of f[...] with f2[...] in my code.
However, I have code that uses f…
I am trying to construct a way to make a function for the following recurrence relation.
$$ Q(N,L) = \int_{0}^{L-(N-1)a} Q(N-1, L-a-z) dz $$,
with the initial condition $Q(2,L) = \frac{1}{2} (a-L)^2$ for positive real numbers $a$ and $L$.
Since…
If we want to save some outputs of the function, we often use the memoization pattern as follows,
f[x_]:=f[x]=x
f/@Range[10^5]
If I call this function many times for different arguments, Mathematica has to first find the best pattern defined so far…
I defined a function that takes some time to compute using memoization:
y[a_, b_, c_] := y[a, b, c] = First[$y /. NDSolve[.........]
so that if I call y[a,b,c] a second time it doesn't do the NDSolve computation all over again if it has already…
What is the best way to let mathematica memoize built-in function like e.g.
SphericalHarmonicY[l,m,th,ph]
One possibility would be for sure:
sphericalHarmonicY[l_,m_,th_,ph_]:= sphericalHarmonicY[l,m,th,ph]=SphericalHarmonicY[l, m, th, ph]
But…
I have a function that takes in sequences of values (as a list), and recursively removes the largest element from that sequence as part of its computation. Some of these sequences can be quite large, but I suspect that they often have common…
How can I prevent mathematica from using the previous computation in new one? How do I make the code below to compute same amount of time without memorizing previous computation.
In[25]:= AbsoluteTiming@Sum[i^3 + 4. i^2, {i, 1000000}]
Out[25]=…
I want to create a function $f$ which takes as a parameter a function $h$, and calculates its integral between $a$ and $b$.
But I want to apply memoization to this, by only calculating the integral the first time it is called for a particular…
Suppose I have a function that returns a polynomial in x,
GetPoly[params_,x_]:=GetPoly[params,x]...
but it is quite slow, so I memoize this.
However, doing GetPoly[params,2y] or similar do not utilize the memoized data, it does the same…