 Cache Top-Level Command - Maple Help

Cache Command

create a new cache table Calling Sequence Cache( opts ) Cache( n, opts ) Cache( cache, opts ) Parameters

 n - integer; size of cache table to create cache - cache table; cache table to copy opts - (optional) equations of the form option=value, where option is one of procedure, temporary or permanent Description

 • The Cache command is a top-level command that creates a new cache table.  If n is given, the returned table will be capable of storing at least n distinct temporary entries.  Increasing n may also make accessing permanent elements faster.
 For example:
 > c1 := Cache( 100, permanent=[ a=2, b=3 ], temporary=[ c=4, d=5] );
 ${\mathrm{c1}}{≔}{\mathrm{Cache}}{}\left({128}{,}'{\mathrm{temporary}}'{=}\left[{d}{=}{5}{,}{c}{=}{4}\right]{,}'{\mathrm{permanent}}'{=}\left[{b}{=}{3}{,}{a}{=}{2}\right]\right)$ (1)
 • If cache is given, a cache table with the same size as cache is created.  As well, the entries of cache, both temporary and permanent, are inserted into the new cache table.  Any additional entries specified by optional parameters are also added.
 • There are three optional arguments: procedure, temporary, and permanent.
 procedure = p
 The procedure optional argument accepts a procedure, p as an argument.  The newly created cache table is installed as p's remember table.  If p has option remember or it already has a remember table, an error is raised.
 temporary = list
 The temporary optional argument accepts a list of equations that are used to initialize the temporary entries of the cache table.  The lhs of each equation is used as the key and the rhs is used as the value. As a cache table is only capable of storing a fixed number of temporary entries, there is no guarantee that all the entries in the list will be in the returned table.
 permanent = list
 The permanent optional argument accepts a list of equations that are used to initialize the permanent entries of the cache table.  The lhs of each equation is used as the key and the rhs is used as the value. Examples

The Cache command is always called using the Cache(arguments) calling sequence. You do not need to use with(Cache).

 > $\mathrm{c1}≔\mathrm{Cache}\left(60,\mathrm{permanent}=\left[1=2,2=3\right],\mathrm{temporary}=\left[3=4,4=5\right]\right)$
 ${\mathrm{c1}}{≔}{\mathrm{Cache}}{}\left({64}{,}'{\mathrm{temporary}}'{=}\left[{3}{=}{4}{,}{4}{=}{5}\right]{,}'{\mathrm{permanent}}'{=}\left[{1}{=}{2}{,}{2}{=}{3}\right]\right)$ (2)
 > $\mathrm{c2}≔\mathrm{Cache}\left(\mathrm{c1},\mathrm{permanent}=\left[x=y,y=z\right],\mathrm{temporary}=\left[a=b,b=c\right]\right)$
 ${\mathrm{c2}}{≔}{\mathrm{Cache}}{}\left({64}{,}'{\mathrm{temporary}}'{=}\left[{3}{=}{4}{,}{4}{=}{5}{,}{b}{=}{c}{,}{a}{=}{b}\right]{,}'{\mathrm{permanent}}'{=}\left[{1}{=}{2}{,}{2}{=}{3}{,}{x}{=}{y}{,}{y}{=}{z}\right]\right)$ (3)
 > p := proc(x) return 1; end proc;
 ${p}{≔}{\mathbf{proc}}\left({x}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{return}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{1}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (4)
 > $\mathrm{Cache}\left(\mathrm{c2},\mathrm{procedure}=p\right)$
 ${\mathrm{Cache}}{}\left({64}{,}'{\mathrm{temporary}}'{=}\left[{3}{=}{4}{,}{4}{=}{5}{,}{b}{=}{c}{,}{a}{=}{b}\right]{,}'{\mathrm{permanent}}'{=}\left[{1}{=}{2}{,}{2}{=}{3}{,}{x}{=}{y}{,}{y}{=}{z}\right]\right)$ (5)
 > $p\left(1\right)$
 ${2}$ (6)
 > $p\left(a\right)$
 ${b}$ (7)