[Jprogramming] arithmetic sequence
Bo Jacoby
bojacoby at yahoo.dk
Tue Dec 25 14:18:43 UTC 2012
That's nice Skip. So we agree that the closed form solution is not completely useless.
I disagree with Boyko's claim: "it holds for *all* lengths where extended numbers are needed, i.e. practically always." Practical computations can be done without using extended numbers, like this.
((0 3+*&5)^:50)1 0 NB. big numbers
8.88178e34 6.66134e34
10^.((0 3+*&5)^:50)1 0 NB. taking the log makes them smaller
34.9485 34.8236
((0 3+*&5)^:500)1 0 NB. bigger numbers give floating point overflow
_ _
10^.((0 3+*&5)^:500)1 0 NB. damage is done before the log is taken
_ _
([:(,.3r4*<:)5&^)50 NB. closed form computation
8.88178e34 6.66134e34
10^.([:(,.3r4*<:)5&^)50 NB. closed form computation of the log
34.9485 34.8236
f=:(10^.5)&*,.(10^.3r4)+((10&^.)&-.&(5&^)&-)+(10^.5)&* NB. log of product is sum of logs
f 50 NB. smarter computation of 10^.([:(,.3r4*<:)5&^)50
34.9485 34.8236
f 500 NB. smarter computation of 10^.([:(,.3r4*<:)5&^)500
349.485 349.36
10 ^ 1 | f 500 NB. factors
3.05494 2.2912
<. f 500 NB. exponents
349 349
So the value of ((0 3+*&5)^:500)1 0 is 3.05494e349 2.2912e349
This is computed without using extended precision.
- Bo
>________________________________
> Fra: Skip Cave <skip at caveconsulting.com>
>Til: programming at jsoftware.com
>Sendt: 21:34 søndag den 23. december 2012
>Emne: Re: [Jprogramming] arithmetic sequence
>
>In my first post I stated:
>"I make the assumption here that he wants the verb to calculate all the
>values up to a specific integer in the formula".
>All of my subsequent comments make the assumption that we are comparing
>functions that calculate multiple values in a single call, creating a n by
>2 array. I make no claims about verbs that produce a single value result.
>On Dec 23, 2012 1:22 PM, "Bo Jacoby" <bojacoby at yahoo.dk> wrote:
>
>> Skips special data does not justify his general conclusion: "The brute
>> force solution is the fastest by several orders of magnitude. The closed
>> form solution is slow AND uses lots of space". Other data give other
>> conclusions.
>>
>>
>> closed
>> [: (,. (3r4 * <:)) 5&^
>>
>> (10) 6!:2'closed 5'
>> 1.82306e_5
>> (10) 6!:2'((0 3+*&5)^:5)1 0x'
>> 8.04365e_5
>>
>> (10) 6!:2'closed 50'
>> 3.68924e_5
>> (10) 6!:2'((0 3+*&5)^:50)1 0x'
>> 0.000332709
>>
>> (10) 6!:2'closed 500'
>> 2.99943e_5
>> (10) 6!:2'((0 3+*&5)^:500)1 0x'
>> 0.00487965
>>
>>
>> It cannot be concluded that 'closed' is generally slower than the brute
>> force computation. In the above cases 'closed' is faster.
>>
>>
>> - Bo
>>
>>
>> >________________________________
>> > Fra: Boyko Bantchev <boykobb at gmail.com>
>> >Til: programming at jsoftware.com
>> >Sendt: 18:21 søndag den 23. december 2012
>> >Emne: Re: [Jprogramming] arithmetic sequence
>> >
>> >On 23 December 2012 18:06, Bo Jacoby <bojacoby at yahoo.dk> wrote:
>> >> Skip's conclusion did not follow from his data in the first place.
>> >
>> >His conclusion is based on his data for producing a 5000-items long
>> >sequence. Not only is it valid but in fact it holds for *all* lengths
>> >where extended numbers are needed, i.e. practically always.
>> >----------------------------------------------------------------------
>> >For information about J forums see http://www.jsoftware.com/forums.htm
>> >
>> >
>> >
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>----------------------------------------------------------------------
>For information about J forums see http://www.jsoftware.com/forums.htm
>
>
>
More information about the Programming
mailing list