[Jprogramming] Bug: +./4.57 4.34 4.44
'Bo Jacoby' via Programming
programming at jsoftware.com
Sat May 16 10:31:50 UTC 2020
Thanks everyone!
Devon, your solution
9!:19]1e_11
+./4.57 4.34 4.44
0.01
looks palatable! I didn't know of 9!:19. Where to read more about it?
But
+./18.457 18.434 18.444
1.93197e_11
and
9!:19]1e_10
|domain error
| 9!:19]1e_10
so it doesn't really solve the problem.
I agree that the square root of two is incommensurable to one
1+.%:2
1.05427e_10
Raul, "only if". It does work for
0j16":2.3 3.7 0.67
2.2999999999999998 3.7000000000000002 0.6700000000000000
+./2.2999999999999998 3.7000000000000002 0.6700000000000000
0.01
Hauke, I agree labelling it a "problem".
Bill, " just use +./&.x: ". (+.&.x:) some times works while (+.) other times works. Why not recode (+.) to make it work more often?
0j16":%:7
2.6457513110645907
+./2 3*%:7 NB. (+.) works
2.64575
(+.&.x:)/2 3*%:7 NB. (+.&.x:) fails
1.97617e_19
Mike,
ABOUTJ_jijs_
|value error: ABOUTJ_jijs_
????
Thank you. This is educational for me.
Bo Den lørdag den 16. maj 2020 08.26.40 CEST skrev Raul Miller <rauldmiller at gmail.com>:
GCD is meant for exact numbers.
It works fine with fractions, IF (and only if) the numbers you are
working with exactly represent the numbers you intend to manipulate.
For binary floating point numbers this would be sums of powers of 2
which do not exceed the precision of the representation (for current J
on 64 bit machines: all divisors have to be powers of 2, you have 53
bits of mantissa to work with and a limited range of exponents).
5r2 +. 7r2
1r2
2.5 +. 3.5
0.5
Thanks,
--
Raul
On Fri, May 15, 2020 at 11:17 PM bill lam <bbill.lam at gmail.com> wrote:
>
> Yes I agree GCD meant for whole numbers, so that +. on floating points can
> first convert to rational first and convert back to float afterwards
> +./&.x: 4.57 4.34 4.44
> 0.01
> x: is clever enough to find the shortest form of rational equal to the
> original floating number range
> (3!:3) 4.5700000000000003
>
> e300000000000000
> 0800000000000000
> 0100000000000000
> 0000000000000000
> 48e17a14ae471240
> (3!:3) 4.57
> e300000000000000
> 0800000000000000
> 0100000000000000
> 0000000000000000
> 48e17a14ae471240
> x: 4.5700000000000003
> 457r100
> x: 4.57
> 457r100
>
> That said, I don't see any real benefit for change, if a user want rational
> number behavior, he/she can use the form
> +./&.x:
>
>
>
> On Sat, May 16, 2020 at 7:18 AM Devon McCormick <devonmcc at gmail.com> wrote:
>
> > Since, AFAIK, GCD was originally defined in the context of whole numbers,
> > you probably get what you deserve using it with non-integers.
> >
> > On Fri, May 15, 2020 at 7:04 PM Raul Miller <rauldmiller at gmail.com> wrote:
> >
> > > It is odd, though, that even with comparison tolerance set to zero, +.
> > > is not associative on fractional floating point values:
> > >
> > > 9!:19]0
> > >
> > > 0j16":,.+./4.57 4.34 4.44
> > > 0.0000000000000036
> > > 0j16":,.+./|.4.57 4.34 4.44
> > > 0.0000000000290870
> > >
> > > It is commutative though:
> > > (-:|:)+./@>{;~4.57 4.34 4.44
> > > 1
> > > 0j16":+./@>{;~4.57 4.34 4.44
> > > 4.5700000000000003 0.0100000000000655 0.0099999999999758
> > > 0.0100000000000655 4.3399999999999999 0.0200000000000466
> > > 0.0099999999999758 0.0200000000000466 4.4400000000000004
> > >
> > > I'm not quite sure what's going on here... maybe a built in epsilon
> > > which is independent of comparison tolerance?
> > >
> > > Thanks,
> > >
> > > --
> > > Raul
> > >
> > > On Fri, May 15, 2020 at 6:53 PM Hauke Rehr <hauke.rehr at uni-jena.de>
> > wrote:
> > > >
> > > > In case you are willing to accept labelling it a problem.
> > > >
> > > > As I mentioned by altering the thread’s subject, yes,
> > > > this ain’t a bug. But there may be an opportunity for
> > > > improvement without sacrifice. Or so do I think.
> > > >
> > > >
> > > > Am 16.05.20 um 00:49 schrieb 'Michael Day' via Programming:
> > > > > Not a new "bug" - I've still got J503 for some reason - so:
> > > > >
> > > > > +./4.57 4.34 4.44
> > > > > 5.39568e_12
> > > > >
> > > > > ABOUTJ_jijs_ NB. nearest thing to JVERSION???
> > > > > Copyright 1994-2004 Jsoftware Inc.
> > > > > For information about this and related products:
> > > > >
> > > > > Jsoftware Inc.
> > > > > P.O. Box 330
> > > > > Excelsior, MN 55331
> > > > > tel: 952 470-7345 fax: 952 470-9202
> > > > > www.jsoftware.com
> > > > > info at jsoftware.com
> > > > >
> > > > > As Devon and Henry suggest, it's the usual problem with "exact"
> > > > > representation of reals.
> > > > >
> > > > > Mike
> > > > >
> > > > >
> > > > >
> > > > > On 15/05/2020 15:17, 'Bo Jacoby' via Programming wrote:
> > > > >> +./4.57 4.34 4.44
> > > > >> 5.39568e_12
> > > > >>
> > > > >> NB. this was not the correct answer. A bug?
> > > > >>
> > > > >> +./x:4.57 4.34 4.44
> > > > >>
> > > > >> 1r100
> > > > >>
> > > > >> NB. this was a work-around
> > > > >> Thanks!
> > > > >> Bo.
> > > > >>
> > > > >>
> > > > >>
> > > > >>
> > > > >>
> > ----------------------------------------------------------------------
> > > > >> For information about J forums see
> > > http://www.jsoftware.com/forums.htm
> > > > >
> > > >
> > > > --
> > > > ----------------------
> > > > mail written using NEO
> > > > neo-layout.org
> > > >
> > > > ----------------------------------------------------------------------
> > > > For information about J forums see http://www.jsoftware.com/forums.htm
> > > ----------------------------------------------------------------------
> > > For information about J forums see http://www.jsoftware.com/forums.htm
> > >
> >
> >
> > --
> >
> > Devon McCormick, CFA
> >
> > Quantitative Consultant
> > ----------------------------------------------------------------------
> > 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