Re: Re: $RecursionLimit Bug?
- To: mathgroup at smc.vnet.net
- Subject: [mg63962] Re: [mg63939] Re: [mg63932] $RecursionLimit Bug?
- From: Pratik Desai <pdesai1 at umbc.edu>
- Date: Wed, 25 Jan 2006 08:45:47 -0500 (EST)
- References: <200601230911.EAA04880@smc.vnet.net> <200601240630.BAA23611@smc.vnet.net> <76e8f8180601240132g5490a56ey14f1fac802dbb6b4@mail.gmail.com>
- Sender: owner-wri-mathgroup at wolfram.com
bsyehuda at gmail.com wrote:
> Hi Pratik,
> This will consum too much memory.
Yes you are quite right. Here is a quote from the documentation
> There is of course a trade$B!>(Boff involved in remembering values. It is
> faster to find a particular value, but it takes more memory space to
> store all of them. You should usually define functions to remember
> values only if the total number of different values that will be
> produced is comparatively small, or the expense of recomputing them is
> very great.
> One can make a compromise if the systems stack limit is known (can be
> revealed with some experimentation). Store intermediate results only
> in known points that will prevent the stack overflow
> The following can serve as an example
> f[0]=1;
> f[x_]:=If[Mod[x,10000]==0,f[x]=x f[x-1],x f[x-1]]
> $RecursionLimit=Infinity
> so
> Table[f[x],{x,10000,100000,10000}]
> will store the results in the points determined by the Table iterator
> and the definition of the function
Another idea, if one is so pressed, could be to store the data in a
external table and use SQL type queries to get the required data.
Best Regards,
Pratik
>
> This way of a forward calculation let youget results for f[10*^5 and
> above].
>
> The payment is ofcourse with computation time (the condition is
> checked in each steps) but this gives results in a very resonable time.
> regards
> yehuda
>
> On 1/24/06, *Pratik Desai* <pdesai1 at umbc.edu
> <mailto:pdesai1 at umbc.edu>> wrote:
>
> W. Craig Carter wrote:
>
> >Hello,
> >I am using Mathematica 5.2 on MacOS 10.4.4
> >
> >I was trying to construct a cannonical timing example by writing
> >a memoryless factorial function.
> >
> >If I do this (fresh kernel):
> >
> >$RecursionLimit = $IterationLimit = 10^6
> >fact[0] = 1;
> >fact[n_] := n fact[n - 1]
> >Timing[fact[10^6]]
> >?fact
> >This generates no output, and the ?fact input line becomes In[1], as
> >if the kernel died after Timing[fact[10^5]], but no messages are
> >generated.
> >
> >If I bury the recursion limit inside a Block, then I get
> >fact[0] = 1;
> >fact[n_] := n fact[n - 1]
> >Timing[Block[{$RecursionLimit = Infinity}, Return[fact[10^5]]]]
> >-----> $RecursionLimit::reclim : Recursion depth of 256 exceeded
> >?fact (* now is In[1] *)
> >-----? Symbol fact not found.
> >
> >
> >Is this a bug?I couldn't find a list of known bugs on the
> >mathematica site....
> >
> >
> >Thanks, WCC
> >
> >
> >
> >W. Craig Carter
> >Lord Foundation Professor of Materials Science and Engineering
> >MIT, Dept. of Materials Science and Engineering 13-501877
> Massachusetts Ave, Cambridge, MA 02139-4307 USA
> >617-253-6048ccarter at mit.edu <mailto:ccarter at mit.edu>
> http://pruffle.mit.edu/~ccarter
> <http://pruffle.mit.edu/%7Eccarter>
> http://pruffle.mit.edu/~ccarter/FAQS/
> <http://pruffle.mit.edu/%7Eccarter/FAQS/>
> http://pruffle.mit.edu/~ccarter/I_do_not_use_microsoft.html
> <http://pruffle.mit.edu/%7Eccarter/I_do_not_use_microsoft.html>
> >
> >
> >
> There is an example similar to this in the Mathematic Book in
> section 2.5.9
> 2.5.9 Functions That Remember Values They Have Found
> Here is one that I modified a bit with RecursionLimit set to infinity
>
> In[27]:=
> Clear[f,x]
> $RecursionLimit=Infinity
> f[x_]:= f[x]=x*f[x- 1]
> f[0]=f[1]=1
> Timing[f[10^4]]//Short
>
> Out[28]=
> $B!g(B
>
> Out[30]=
> 1
>
> Out[31]//Short=
> {0.23 Second,2846259\[LeftSkeleton]35645\[RightSkeleton]00000000}
>
> Hope this helps
>
> Pratik
>
>
- References:
- $RecursionLimit Bug?
- From: "W. Craig Carter" <ccarter@mit.edu>
- Re: $RecursionLimit Bug?
- From: Pratik Desai <pdesai1@umbc.edu>
- $RecursionLimit Bug?