ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 15 Jun 2015 15:09:01 -0500Why can 'matrix' not use cached functions?https://ask.sagemath.org/question/27111/why-can-matrix-not-use-cached-functions/Consider
def L(n,k):
if n==k: return 1
if k<0 or k>n: return 0
return L(n-1,k-1)+(n+k-1)*L(n-1,k)
print parent(L)
matrix(ZZ, 8, L)
This works. However, as soon as I decorate the above function L with the very reasonable "@CachedFunction" I receive an ValueError: "Invalid matrix constructor".
Peter LuschnyMon, 15 Jun 2015 15:09:01 -0500https://ask.sagemath.org/question/27111/Is there a kind of memoization in Sage build in?https://ask.sagemath.org/question/8624/is-there-a-kind-of-memoization-in-sage-build-in/Maple knows an option called 'remember' which allows the coding of a function with a recursive definition in a natural manner without a loss of efficiency (exponential time to compute often can be reduced to linear time). Does Sage have a similar option?petropolisThu, 09 Feb 2012 09:21:57 -0600https://ask.sagemath.org/question/8624/Timing cached functionshttps://ask.sagemath.org/question/8289/timing-cached-functions/I have defined a recursive function that call itself several times, often asking for the same result that was previously computed. In this setting, defining the function as cached makes perfect sense.
But when i try to timeit, i always get very low timings (i assume the function is computed once and then the cache is called several times, making the average timing very low). I could define the function as non cached, but in that case i can not measure how much i gain by caching the intermediate calls from the function to itself.
Is there some way to say timeit to empty the cache each time the function is run?mmarcoTue, 23 Aug 2011 07:01:45 -0500https://ask.sagemath.org/question/8289/