Questions tagged [memoization]

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

Filter by
Sorted by
Tagged with
2 votes
2 answers
80 views

How can I Save function defintion without its DownValues?

I use functions that memorize their values like this one: ...
Igor Kotelnikov's user avatar
2 votes
0 answers
72 views

Nintegrate memoization [closed]

Is there a way to use memoization for NIntegrate (maybe dependent on the method of integration used) to reduce the number of computations for the same subintervals when computing something like the ...
aku jack's user avatar
1 vote
0 answers
31 views

Getting DownValues from memoized function - ParallelEvaluate only uses one kernel at a time

I have the following code where I calculate primorial(n) using a memoized function. When I run this function in ParallelDo everything is fine - the calculation runs on 8 kernels. But I want to use ...
1729taxi's user avatar
  • 747
3 votes
1 answer
213 views

Memoize a compiled function

Let f be some function, I know that i can memoize a function so that it does not compute again previously calculated values, I can also compile the function to speed up the calculations. But how can I ...
DarkBulle's user avatar
  • 964
4 votes
1 answer
74 views

Efficient primorial memoization?

Thinking on this recent question asking to create an primorial list, led me to think How could we exploit something similar to memoization for primorial? Maybe something that stored only the largest ...
rhermans's user avatar
  • 36.2k
3 votes
1 answer
221 views

Recursive function Catalan triangle

I'm trying to learn how to build a recursive function. However, I'm not sure to understand how to set a "limit". Here is what I'm trying to make. I want a function that gives me the i,j ...
TheInvisibleParticle's user avatar
2 votes
2 answers
66 views

Pattern matching in Association fails in `Set` assignment

I want to define a symbolic-valued function using Set to memoize the result. However, I get different results when using an ...
Phro's user avatar
  • 131
2 votes
0 answers
71 views

Controlling memory consumption by memoized function

To speed up a resource-intensive calculation, I use several functions with storing previously calculated values. For example: ...
Igor Kotelnikov's user avatar
1 vote
1 answer
150 views

Dynamic programming and Module

In the following example of the dynamic programming, why does f[n] is written at the end of the Module? ...
SciJewel's user avatar
  • 331
2 votes
0 answers
50 views

Memorization for Rule + ReplaceRepeated?

Question When build packages of noncummutative algebras I met the choice: Rule + ReplaceRepeated ...
Lacia's user avatar
  • 2,208
7 votes
1 answer
256 views

How to remember evaluation across sessions?

I am performing a very time-consuming symbolic calculation. When I reopen a saved Mathematica notebook, it takes quite a long time to evaluate. Is there an option to tell Mathematica to remember the ...
Yrefef's user avatar
  • 71
0 votes
2 answers
135 views

Memoization and recursions

My question is bolded within the text below. Memoization speeds up a recursion that needs to recall a prior rule other than the last one calculated. For instance, on my machine, the following take 0....
theorist's user avatar
  • 3,603
4 votes
1 answer
194 views

Why is a function of two functions that use memoization still slow?

I have two functions that I both use memoization for. My goal is to plot the ratio of these two functions. Since I already plot the functions by themselves, and I use memoization, it would seem to me ...
Brazilian Cérebro's user avatar
1 vote
0 answers
46 views

RegionPlot3D incorrectly plots regions defined by memoized functions

RegionPlot3D incorrectly plots regions defined by memoized functions. A memoizer: ...
Nickolas's user avatar
  • 121
3 votes
1 answer
136 views

Memoization of functions with optional arguments

Consider the following function that generates a sparse diagonal matrix: ...
Heidar's user avatar
  • 263
1 vote
0 answers
37 views

Creating a library of saved function values [duplicate]

I have a command of the form J[b,c,n] which outputs a list of complex numbers, obtained by using FindRoot. Some outputs take ...
math's user avatar
  • 713
0 votes
1 answer
114 views

Memoization Involving More than one Variable [duplicate]

Good morning. I would like to know if there is a way to implement memoization if there is more than one variable involved in the memoization; or more accurately, for my problem, have the memoization ...
Eleven-Eleven's user avatar
0 votes
0 answers
21 views

How to memoize with patterns? [duplicate]

Here is an artificial example to explain what I am up to. Define ClearAll[f] f[x_, y_] := f[x, y] = If[x == 0, g[y], g[f[x - 1, y]]] Then ...
მამუკა ჯიბლაძე's user avatar
2 votes
0 answers
60 views

Optimising tensor operations under memory constraints

Let riem is a free variable with riem ∈ Arrays[{4, 4, 4, 4} as assumption. Let: ...
user3257842's user avatar
2 votes
0 answers
133 views

Why does this memoized function cause the kernel to quit? [closed]

The following memoized recursive function causes the kernel to beep and quit. ...
qwr's user avatar
  • 403
3 votes
1 answer
170 views

Recursive solution to the extended Josephus problem [duplicate]

The Josephus Problem is described here, with extension of killing every $k$th problem. In the simple case where every other person is killed, we can also use the binary trick. ...
CasperYC's user avatar
  • 1,550
1 vote
2 answers
174 views

Save part of memoized function

I have a function whose performing a series of expansions of a complicated function, which can take a lot of time. To avoid bottlenecks, I use memoization so I need to evaluate it only once. For ...
Bulkilol's user avatar
  • 289
0 votes
4 answers
146 views

How to "cache" function values to pass to ListPlot?

I have a function which is very expensive to run. I would like to Plot the function for a certain range, but it is time prohibitive to let Plot simply compute the function for a lot of values as it ...
Michael's user avatar
  • 197
0 votes
1 answer
75 views

Memoization (or otherwise) for a recurrent definition of a (double) sequence of functions

Beside I've found answers to similar questions (e.g. this), I can't adapt them to my case. I am interested in the following sequence of functions $p_{m,n}(t)$, where $m$ and $n$ are integer: $$ \...
Dmitri's user avatar
  • 522
2 votes
1 answer
140 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 ...
nate's user avatar
  • 445
8 votes
1 answer
165 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 ...
Per Alexandersson's user avatar
6 votes
1 answer
444 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 ...
მამუკა ჯიბლაძე's user avatar
0 votes
1 answer
241 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 ...
irh's user avatar
  • 123
18 votes
1 answer
352 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 ...
Daniel W's user avatar
  • 3,406
0 votes
2 answers
173 views

memoization based on function expression?

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 ...
user56834's user avatar
  • 545
4 votes
0 answers
162 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: ...
Mr Puh's user avatar
  • 1,017
2 votes
1 answer
113 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] = 0; fib1[1] = 1; fib1[n_] := fib1[n - 1] + fib1[n - 2]; One ...
GambitSquared's user avatar
2 votes
1 answer
123 views

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

I'm using the Quantum Computing library with this example: ...
David B's user avatar
  • 271
0 votes
0 answers
97 views

How to create a listable, memoized function

Suppose I have a known real constant $a$, and I want to calculate $f(n) = \prod_{k=1}^{n}(a-k)$. I know I could memoize this function ...
FalafelPita's user avatar
25 votes
4 answers
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: ...
LLlAMnYP's user avatar
  • 11.4k
2 votes
2 answers
127 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 ...
ercegovac's user avatar
  • 1,007
1 vote
1 answer
93 views

Forward iterations of coupled recursion equations

I need to do forward iterations of a system of 16 coupled recursion equations that track the frequency of genotypes over time in a biological model. I find that the iterations run slowly (it takes ~ ...
biologyUser's user avatar
4 votes
4 answers
739 views

Memoization of a function defined by a recurrence relation [duplicate]

I have a function which is defined by the following recurrence relation $$h_{n}(x)=h_{n-1}(x)+\frac{\mathrm{e}^{-x^2}}{2^n n!}H_{n}(x)H_{n-1}(x)$$ with the initial condition $h_{0}(x)=0$ and where the ...
Yasar's user avatar
  • 41
1 vote
1 answer
183 views

Recurrence Table Differentiation

I would like to generate a table of values by differentiating a function for each entry on the table based off of the previous entry. The purpose is to decrease the number of differentiations as the ...
Adam Kirosingh's user avatar
2 votes
1 answer
155 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, ...
Jordy Dickinson's user avatar
1 vote
1 answer
234 views

Which data tabulation concept is best suited for discrete dynamic programming problems (e.g. for optimum series of account withdrawals)?

A bank account has starting balance, which shall be completely withdrawn in n steps, such that the sum of benefits of withdrawals is maximum. Remaining balance yield interest between steps such that ...
nmrphys's user avatar
  • 35
0 votes
0 answers
73 views

Reuse symbolic polynomial

Suppose I have a function that returns a polynomial in x, GetPoly[params_,x_]:=GetPoly[params,x]... but it is quite slow, so ...
Per Alexandersson's user avatar
5 votes
1 answer
242 views

How can I access memoized values from parallel evaluation? [duplicate]

I want to evaluate a table of functions with ParallelTable. Here is the serial code: ...
Math-fort's user avatar
5 votes
0 answers
554 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 ...
Per Alexandersson's user avatar
7 votes
2 answers
2k views

How does one clear the memory of a recursive function

I want to implement the recursive function v[n_] := v[n] = v[n-1] + f[n-1] + Random[NormalDistribution[0,s]] to get ...
Charles Hagwood's user avatar
4 votes
2 answers
210 views

Assigning function values in a memoized recursive module

I have a complicated recursive module which I have memoized. I realised that certain isomorphs of inputs to this function will give the same output. Therefore I decided to memoize all such input-...
Simon's user avatar
  • 1,415
3 votes
0 answers
65 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 ...
Per Alexandersson's user avatar
1 vote
0 answers
89 views

Prevent Mathematica using previous result [closed]

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. ...
Al Guy's user avatar
  • 1,580
7 votes
0 answers
108 views

Time complexity to choose the right overload from the memoized function

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 ...
Sungmin's user avatar
  • 2,285
10 votes
1 answer
288 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 ...
march's user avatar
  • 22.9k