More exact equality isn't enough - as you can see from the example, it calculates a mean of 2.7 when 3 is the right answer. The problem there is roundoff error I expect.

I can think of 3 requirements you might want to put on this function:

1. don't crash on any input

2. ensure that L(x,y) >: x <. y for all x and y

3. ensure that x > y => L(z,x) >: L(z,y) for all x and y

but I don't see how to achieve that, and don't know whether you need to be that accurate.

Henry Rich

On 4/20/2014 5:17 PM, Raul Miller wrote:
On Sun, Apr 20, 2014 at 3:27 PM, Henry Rich <henryhr...@nc.rr.com> wrote:

This has trouble when the numbers are close.

    3 ((]*=) + - % ^.@:%) 3.000000000000001
5.66667
    3 ((]*=!.0) + - % ^.@:%) 3.000000000000001
2.66667


That's a good point.

I didn't need =!.0 for the earlier version (which had the NaN problem when
both args were 0) but the increased robustness of Roger's version looks
like it wants a more exact form of equality.

If I have time, I'll take a look at how stable this is over a wide range of
values (and small epsilons).

Thanks,

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to