# Questions tagged [memoization]

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

63 questions
Filter by
Sorted by
Tagged with
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?
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 ...
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 ...
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 ...
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 ...
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: ...
738 views

### How to memoize a function with Options?

Consider the following modified fibonacci function: ...
271 views

### When to use Once for memoization?

While watching Stephen Wolfram's twitch stream I saw him use Once for memoization, which surprised me since I thought of Once as ...
1k views

### Relative performance of the Julia language

I was just reviewing the Mathematica benchmark code linked from the Julia language home page http://julialang.org/. The stated goal of the benchmarks is to test the performance of specific algorithms, ...
600 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: ...
223 views

### How to write crash-robust code?

When a notebook crashes all the work I was doing is lost - I'd like to ameliorate this situation! Is there a way to decorate a symbol so that it is saved to disk whenever it changes, or after a ...
407 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 ...
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 ...
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 ...
176 views

### How to speed up the evaluation of a function with a large LeafCount but many repeated sub-functions for use in NIntegrate

General Context Apparently, the memory leak in NIntegrate is unavoidable pre-MMA-10.2. I have some (two-dimensional) numerical integration to do on a complicated ...
2k views

### Improve speed for calculating a recursive sequence

I want to calculate following recursive sequence: $\alpha_{0}=0,\\ \cos(\alpha_{i})=\cos(\alpha_{i-1})\cdot\cos(\beta_{i})+\sin(\alpha_{i-1})\cdot\sin(\beta_{i})\cdot\cos(\gamma_{i}).$ In ...
671 views

### Can I memoize retroactively?

I have a function defined something like this: f[x_] := Module[...]; I can easily write a memoized version of it like this: ...
224 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. ...
259 views

### using memoization with conditional statement

I would like some advice about the use of memoization in conjunction with conditional statements. Let me try to explain my problem: I am constructing a function depending on a number of parameters. ...
102 views

### Memoization and packages

I am working in a package on symmetric functions, that sometimes are quite expensive to compute. I use memoization extensively, but what is the correct approach for a package intended for the public ...
313 views

120 views

### Memoization of built in function

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: ...
63 views

### Memoized function with function parameter [duplicate]

I have some code that takes a function and uses the function to do some complicated computation. Thus, I wish to store this so I don't have to repeat this. Below, it is more simple than my real ...
72 views

### Parallelization and memoization? [duplicate]

I have an expensive function on discrete values, f[n_] := f[n] = n^2 (* Expensive calculation *) Since f[n] is an expensive ...
155 views

### Extract memoized results in the form of a rule

Lets say I define a function f with memoization. Is there some way to extract the memoized values? For example, ...
275 views

### tricky memoization

Let's say I have the NDSolve example for documentation involving splitting 2nd order into set of 1st order ODEs: ...
62 views

### Timing of three different strategies for fibonacci numbers

A standard way to speed up the creation of Fibonacci numbers is by memoization Instead of: fib1 = 0; fib1 = 1; fib1[n_] := fib1[n - 1] + fib1[n - 2]; One ...
103 views

### Memoization and finding already calculated DownValue

The problem of plotting an expensive function discussed in this question caught my attention. As an exercies I tried to solve it using memoization as follows ...
132 views

### Memoization only under certain conditions

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, ...
76 views

### a recursive function using memoization

I have looked at a lot of these cases, e.g. Can one identify the design patterns of Mathematica? and the included ones. My trimmed example, here establishing the 'initial conditions' (where the ...
100 views

### Debugging and decision support tools for Dynamic Programming (cached definitions) in Mathematica

I'm using the Quantum Computing library with this example: ...