Questions tagged [memoization]

For questions related to user defined caching mechanisms, memoization, in particular.

85
votes
5answers
10k views

What does the construct f[x_] := f[x] = … mean?

This question mentions "x := x = trickery". What does defining a function as f[x_] := f[x] = ... do and what is it good for?
52
votes
4answers
4k views

How can I implement dynamic programming for a function with more than one argument?

Dynamic programming is a technique for avoiding the repeated computation of the same values in a recursive program. Each value computed is immediately stored. If the value is needed again, it is not ...
11
votes
3answers
8k views

Get polynomial interpolation formula

I'm attempting to get a polynomial interpolation formula out of Mathematica but I am absolutely lost. I stared out using ...
34
votes
3answers
2k views

How to clear parts of a memoized function?

I have a function of two variables, e.g.: f[a_, b_] := f[a, b] = something f[a - 1, b - 1] etc With the above code I used the concept of memoization to speed up ...
43
votes
4answers
1k views

Parallelize evaluation of function with memoization

I have a complicated function that I need multiple times, so I want to memoize it and have the first evaluation done in parallel. Unlike in my example below it's not a continuous function, so ...
12
votes
3answers
406 views

Memoization of Rounded inputs

Memoization is a technique for improving performance by having a function remember its previous arguments. For example, f[x_]:=f[x]=mySlowFunction[x] will be ...
14
votes
3answers
599 views

Using Memoization with a Mutable Object

In looking for a solution to this question, I ran across some old binary tree code by Daniel Lichtblau, reproduced below: ...
19
votes
3answers
734 views

How to memoize a function with Options?

Consider the following modified fibonacci function: ...
45
votes
2answers
3k views

Memoization with pure functions?

Is this possible? If I have a simple function, say: f=If[#>0,1,2]& then for each value of # this will re-evaluate f right? Is it possible to define a ...
11
votes
2answers
1k views

Dynamic Programming with delayed evaluation

By using dynamical programming, we can save intermediate steps for recursive relations, as in f[n_]:= f[n] = f[n-1] + f[n-2] However, this only stores ...
9
votes
1answer
223 views

Saving memoization to disk

I like using memoization (i.e. the construct myFunction[x_]:=myFunction[x]=...) when I have a heavy function that I need to re-evaluate on the same arguments. ...
25
votes
4answers
1k views

Throwaway memoization makes built-ins faster?

Yesterday I got into an argument with @UnchartedWorks over in the comment thread here. At first glance, he posted a duplicate of Marius' answer, but with some unnecessary memoization: ...
4
votes
4answers
443 views

How to do memoization together with evaluation of a complicated function

UPDATE 2: much shorter version Given a list of paired indices {i, j}={{1,2}, {3,4}, …}, I need to first evaluate a rather complicated function test[i,j,x] (because ...
5
votes
2answers
236 views

Only perform a symbolic differentiation once

I want to define a function that involves a differentiation step that Mathematica can do easily, which might be of the form ...
0
votes
1answer
71 views

Create recursive sequence of functions with memoization

I am trying to create a sequence of functions and have it properly memoize the results. The recursive operation is simply convolution, so it possible there is a better way to do this (obviously, if I ...
5
votes
0answers
211 views

Dropbox datastore

Dropbox seems to have a feature where it can be used as a database. This would be really cool to use for memoized functions, that can be restored on several computers and sessions. I have a function ...
3
votes
1answer
171 views

Kernel crashed after $RecursionLimit = Infinity

$RecursionLimit = Infinity; T[n_, k_]:= T[n, k] = If[n == 0 || k == 1, 1, T[n, k-1] + If[n<k, 0, T[n-k, k]]]; Table[T[n!, n], {n, 1, 9}] Without ...
6
votes
1answer
114 views

Clever caching of a recursively defined function

I've got a function of the form f[n,s] where n is a natural number and s is a finite ...
5
votes
0answers
297 views

Change of basis of polynomials

Suppose I have a favourite basis for polynomials in $x_1,\dotsc,x_n$, say non-symmetric Macdonald polynomials to be specific. I can easily compute these, and thus the change-of-basis matrix that takes ...
1
vote
2answers
85 views

Unintentional function memoisation via Dynamic

I needed to display edge labels of a graph in a way that allows the edge labels to be moved. ...