Hello, Sage already has two decorators that provide this functionality.
@func_persist will remember the computed values across Sage sessions since the results are written to a file @CachedFunction just stores the results in memory Note that all of the arguments to the function whose results you want to cache must be hashable. --Mike On Mon, Apr 21, 2008 at 1:40 PM, BFJ <[EMAIL PROTECTED]> wrote: > > Hi, > > I ran across the following post and thought I would pass it along. > > http://avinashv.net/2008/04/python-decorators-syntactic-sugar/ > > For those of us who were weened on Maple, the post describes a very > nice way to get the "options remember" functionality that is built > into Maple in python (and Sage). Maybe there is another (or a better) > way to do this in Sage proper, but I couldn't find one looking through > the documentation. > > For those that don't know what "options remember" does in Maple, it is > a declaration in a proc which tells Maple to build an "input" -> > "output" dictionary for the proc. So if you call a proc you've defined > with an input for the first time, it calculates it as usual. The > second time you call the proc with the same input, it just looks up > the output from the table, bypassing the possibly time consuming > calculation. This is very useful in alot of computational situations, > especially combinatorial functions that are defined recursively (like > the fibonacci example given and profiles in the post above). > > -BFJ > > > > --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---