Hi Skip Cave Note that the closed form solution doesn't have to compute the intermediate values.
ts=: (6!:2),7!:2 ts '((0 3+*&5)^:5000)1 0x' NB. brute force solution 0.244886 38848 ts '(,.3*4%~1-~])5^5000x' NB. closed form solution 0.0174891 27712 Here the closed form solution was 14 times faster and used 29 per cent less space. 0.244886 38848%0.0174891 27712 14.0022 1.40185 %0.244886 38848%0.0174891 27712 0.0714173 0.713344 - Bo >________________________________ > Fra: Skip Cave <[email protected]> >Til: [email protected] >Sendt: 22:16 lørdag den 22. december 2012 >Emne: Re: [Jprogramming] arithmetic sequence > >> Is Skip Cave saying that the closed form solution is inferior? >> Bo >> > >No. What I am saying is: > >The brute force solution is the fastest by several orders of magnitude, >but uses lots of space: > > ts '((0 3+*&5)^:(i.5000))1 0x' >0.0714665 2.59842e7 > >The closed form solution is slow AND uses lots of space: > > ts '(,.3*4%~1-~])5^(i.5000x)' >7.70079 4.99247e7 > >The looping solution is slow, but not as slow as the closed form. However >it uses many orders of magnitude less space. > > ts 'acx 5000' >2.51865 107264 > >So if your criteria is time and space usage, then the closed form is the >worst of the lot. There may be other criteria that would result in a >different conclusion. As I have mentioned before, processing time and space >is still much less costly than human programming time, so the large >differences in time and space usage are still miniscule when compared with >the time it took to develop these verbs. > >Skip >---------------------------------------------------------------------- >For information about J forums see http://www.jsoftware.com/forums.htm > > > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
