Roger Hui wrote: > Do you have a good estimate for how many terms > are needed in the exponential series? That is, > given epsilon>0 and real y>0, what is a good > estimate for the smallest n such that > epsilon > (y^n)%!n ? > > Such an n must exist because the limit of the > sequence (y^n)%!n is 0. My current approach is to > use Stirling's approximation for !n . >
Here is a suggestion that does not involve anything as fancy as Stirling's approximation. In each case epsilon <verb> y gives a value for n such that epsilon>(y^n)%!n. The verbs ndirect and nbinary give the minimal n, while ncrude is used to get an easy upper bound. NB. Get a crude estimate ncrude=:4 : 0 m=.>.+:y assert.(2*y)<m+1 n=.>.m+ 2^.(y^m)%x*!m assert.x>(y^n)%!n ) NB. Go through term by term for an exact estimate. ndirect=:4 : 0 n=.0 t=.1 while. t>:x do. n=.>:n t=.(y*t)%n end. assert.x>(y^n)%!n n ) NB. Start with crude estimate, then do binary search. nbinary=:4 : 0 hi=.x ncrude y lo=.0 while. 1<hi-lo do. n=.<.-:hi+lo if. x>(y^n)%!n do. hi=.n else. lo=.n end. end. n=.hi assert.x>(y^n)%!n ) 1e_40 ndirect 7 70 1e_40 ncrude 7 150 1e_40 nbinary 7 70 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
