[Jprogramming] Puzzling result

Don Kelly dhky at shaw.ca
Tue Sep 12 00:04:41 UTC 2017


I believe that Raul has hit it on the head.  14^2 will be floating as 
will generally be the case with % so it is possible that errors add or 
subtract to give an erroneous result. Note that

(14^2) (] - [ * [: <. ] % [)5729082486784839x

147


(14^2x) (] - [ * [: <. ] % [)5729082486784839

147

and

(14^2x)|5729082486784839

147


does it more simply


Don

On 2017-09-11 6:50 AM, Erling Hellenäs wrote:
> (14^2x) (] - [ * [: <. ] % [)5729082486784839x
>
> 147
>
> (14^2) (] - [ * [: <. ] % [)5729082486784839
>
> _49
>
> (14^2) (] - [ * _1 + [: <. ] % [)5729082486784839
>
> 147
>
> /Erling
>
>
> Den 2017-09-11 kl. 15:40, skrev Erling Hellenäs:
>> From what I see, floor gives an incorrect result which I correct with 
>> the " _1 + " There is not other problem. No loss of precision. /Erling
>>
>>
>> Den 2017-09-11 kl. 15:27, skrev Raul Miller:
>>> I do not know what you are thinking, and you have not illustrated your
>>> thoughts sufficiently for me to grasp them.
>>>
>>> So, I thought I'd work through this:
>>>
>>>     (14^2) (] - [ * _1 + [: <. ] % [)5729082486784839
>>> 147
>>>     (14^2x) (] - [ * _1 + [: <. ] % [)5729082486784839x
>>> 343
>>>
>>> Clearly, the exact answer is different from the quick answer.
>>>
>>> If we compare
>>>     load'debug/dissect'
>>>     dissect '(14^2) (] - [ * _1 + [: <. ] % [)5729082486784839'
>>>     dissect '(14^2x) (] - [ * _1 + [: <. ] % [)5729082486784839x'
>>>
>>> We can see the initial off-by-one errors, but the big difference shows
>>> up at the end (where we subtract from 5729082486784839)
>>>
>>> The value we are subtracting is:
>>>
>>>     (14^2x) ([ * _1 + [: <. ] % [)5729082486784839x
>>> 5729082486784496
>>>     (14^2) ([ * _1 + [: <. ] % [)5729082486784839
>>> 5.72908e15
>>>
>>> Looking at the bits needed to represent that as an integer:
>>>
>>>     2^.(14^2) ([ * _1 + [: <. ] % [)5729082486784839
>>> 52.3472
>>>
>>> we can see that that's right on the edge of being the number of
>>> representable digits in a 64 bit float.
>>>
>>> But, also, it's the result of multiplying
>>>
>>>     14^2
>>> 196
>>>
>>> by an off-by-one amount. And...
>>>
>>>     343-196
>>> 147
>>>
>>> ...
>>>
>>> Anyways, I'm not sure what you were thinking, but I guess we can take
>>> this as a good example of the idea that errors can actually
>>> accumulate.
>>>
>>> Thanks,
>>>
>>
>> ----------------------------------------------------------------------
>> 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