Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Best practice to save results of a function as a database

I have a function defined inductively that taxes my computer quite a lot. It will help a lot if I can save its results somewhere, preventing it from unnecessary calculations.

To simplify, assume that it's a function $f: \mathbb{N} \to \mathbb{N}$, where $f(0)=1$ and $f(i)$ depends on the value of $f$ at lower $i$'s. Imagine that I want to calculate $f(n)$ where $n \sim 10^{1000}$.

Of course, I can do it by

for i in range(1000):

(f(i)).save("./f_value_"+str(i))

But I feel like this can be improved. Any idea?

Best practice to save results of a function as a database

I have a function defined inductively that taxes my computer quite a lot. It will help a lot if I can save its results somewhere, preventing it from unnecessary calculations.

To simplify, assume that it's a function $f: \mathbb{N} \to \mathbb{N}$, where $f(0)=1$ and $f(i)$ depends on the value of $f$ at lower $i$'s. Imagine that I want to calculate $f(n)$ where $n \sim 10^{1000}$.

Of course, I can do it by

for i in range(1000):

range(1000):

(f(i)).save("./f_value_"+str(i))f(i).save("./f_value_{}".format(i))

But I feel like this can be improved. Any idea?