Boyko wrote: "And it is very clear that ‘practically always’ refers to the domain of the problem being discussed in this thread, and not to anything else". To me it is not clear what the exact domain is.
The problem was to solve the recursion S(n+1)=3+5*S(n), S(0)=K. The solution is S(n)=(K*a(n))+b where a(n) and b(n) are the columns in the following array ((0 3+*&5)^:(>:i.5))1 0 5 3 25 18 125 93 625 468 3125 2343 Of course also a single row can be computed, but - according to Boyko - that is outside the domain discussed in the thread. ((0 3+*&5)^:5)1 0 3125 2343 If the argument n is big, then S(n) produces floating point overflow. ((0 3+*&5)^:441)1 0 1.76105e308 1.32079e308 ((0 3+*&5)^:442)1 0 _ _ To avoid floating point overflow there are two escape routes. One is to use extended precision. ((0 3+*&5)^:442)1 0x 8805254571710334568747454416748841703270543785149108920194891973879785719185942900509604065239306230314599685033396025436038226869169080408760960496359417657009626203195081877171178435612943653929526971402208215295516470547634000574399263155998264866422030... The other escape route is to compute via the logarithm of the result, using a closed form formula. f=: (10^.5)&*,.(10^.3r4)+((10&^.)&-.&(5&^)&-)+(10^.5)&* 10^f 441 1.76105e308 1.32079e308 This logaritm does not easily produce floating point overflow. f 5000 3494.85 2442.71 ((10^1&|),.<.) f 5000 7.07981 3494 5.10512 2442 This means that S(5000) is equal to (K*7.07981e3494)+5.10512e2442 The timing is competitive to that of using extended precision. 10(6!:2)'((10^1&|),.<.) f 5000' NB. one row 0.000171528 10(6!:2)'((10^1&|),.<.) f >:i.5000' NB. 5000 rows 0.016414 (6!:2)' ((0 3+*&5)^:5000)1 0x' NB one row, extended precision 0.259012 (6!:2)' ((0 3+*&5)^:(>:i.5000))1 0x' NB. 5000 rows, extended precision 0.388583 My conclusions are 1. Extended precision is not always needed 2. The closed form solution is fast - Bo >________________________________ > Fra: Boyko Bantchev <boyk...@gmail.com> >Til: programm...@jsoftware.com >Sendt: 8:45 torsdag den 27. december 2012 >Emne: Re: [Jprogramming] arithmetic sequence > >On 27 December 2012 00:48, Bo Jacoby <bojac...@yahoo.dk> wrote: >> Boyko wrote: "it holds for *all* lengths where extended numbers are needed, >> i.e. practically always." It is not clear to me whether Boyko claims that >> extended numbers are practically always needed. > >Yes, this is what I claim. >And it is very clear that ‘practically always’ refers to the domain >of the problem being discussed in this thread, and not to anything >else. >---------------------------------------------------------------------- >For information about J forums see http://www.jsoftware.com/forums.htm > > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm