Another example. The following expressions approximate the square root of 2 using Newton's method:
a. Machine numbers (64-bit floating point): ] m=: -:@(+ 2&%)^:(i.10) ] 1 1 1.5 1.41667 1.41422 1.41421 1.41421 1.41421 1.41421 1.41421 1.41421 0j40 ": ,. m 1.0000000000000000000000000000000000000000 1.5000000000000000000000000000000000000000 1.4166666666666665000000000000000000000000 1.4142156862745097000000000000000000000000 1.4142135623746899000000000000000000000000 1.4142135623730949000000000000000000000000 1.4142135623730949000000000000000000000000 1.4142135623730949000000000000000000000000 1.4142135623730949000000000000000000000000 1.4142135623730949000000000000000000000000 The first expression iterates from 0 to 9 times, and displays the result with a print precision of 6. The second displays the result to 40 decimal places. b. The same thing, using an initial estimate of 1x instead of 1. ] x=: -:@(+ 2&%)^:(i.10) ] 1x 1 3r2 17r12 577r408 665857r470832 886731088897r627013566048 1572584048032918633353217r1111984844349868137938112 ... 0j40 ": ,. x 1.0000000000000000000000000000000000000000 1.5000000000000000000000000000000000000000 1.4166666666666666666666666666666666666667 1.4142156862745098039215686274509803921569 1.4142135623746899106262955788901349101166 1.4142135623730950488016896235025302436150 1.4142135623730950488016887242096980785697 1.4142135623730950488016887242096980785697 1.4142135623730950488016887242096980785697 1.4142135623730950488016887242096980785697 ----- Original Message ----- From: Roger Hui <[email protected]> Date: Sunday, August 9, 2009 14:13 Subject: Re: [Jgeneral] Array Based Languages To: General forum <[email protected]> > This is not correct wrt J. > > For historical and practical (time and space) reasons, > by default numbers are 64-bit IEEE floating point numbers > ("machine numbers"), which gives 16 decimal digits of > precision. > In J, if you want more digits, you can use rational numbers, > and that has infinite precision. All you need to do is > to make your input numbers extended precision, > and the interpreter will try to carry through your > computations in extended precision. For example: > > % 1 + +/~ i.10 NB. Hilbert matrix > > 1 0.5 > 0.333333 0.25 0.2 0.166667 0.142857 0.125 0.111111 0.1 > 0.5 > 0.333333 0.25 0.2 0.166667 0.142857 0.125 0.111111 > 0.1 0.0909091 > 0.333333 > 0.25 0.2 > 0.166667 0.142857 0.125 > 0.111111 0.1 0.0909091 0.0833333 > 0.25 > 0.2 0.166667 0.142857 > 0.125 0.111111 0.1 > 0.0909091 0.0833333 0.0769231 > 0.2 0.166667 > 0.142857 0.125 > 0.111111 0.1 0.0909091 > 0.0833333 0.0769231 0.0714286 > 0.166667 0.142857 0.125 > 0.111111 0.1 0.0909091 > 0.0833333 0.0769231 0.0714286 0.0666667 > 0.142857 0.125 > 0.111111 0.1 0.0909091 > 0.0833333 0.0769231 0.0714286 0.0666667 0.0625 > 0.125 > 0.111111 0.1 0.0909091 > 0.0833333 0.0769231 0.0714286 0.0666667 0.0625 > 0.05882350.111111 0.1 > 0.0909091 0.0833333 0.0769231 0.0714286 > 0.0666667 0.0625 0.0588235 0.0555556 > 0.1 0.0909091 0.0833333 0.0769231 > 0.0714286 0.0666667 0.0625 0.0588235 0.0555556 > 0.0526316 > The above calculation has 16 decimal digits of precision. > The output is 6 decimal digits because that is the default > for the session. (You can change the print precision for > the session.) > > % 1 + +/~ i.10x > 1 1r2 1r3 1r4 1r5 > 1r6 1r7 1r8 1r9 1r10 > 1r2 1r3 1r4 1r5 1r6 > 1r7 1r8 1r9 1r10 1r11 > 1r3 1r4 1r5 1r6 1r7 > 1r8 1r9 1r10 1r11 1r12 > 1r4 1r5 1r6 1r7 1r8 1r9 1r10 > 1r11 1r12 1r13 > 1r5 1r6 1r7 1r8 1r9 1r10 1r11 1r12 > 1r13 1r14 > 1r6 1r7 1r8 1r9 1r10 1r11 1r12 1r13 1r14 1r15 > 1r7 1r8 1r9 1r10 1r11 1r12 1r13 1r14 1r15 1r16 > 1r8 1r9 1r10 1r11 1r12 1r13 1r14 1r15 1r16 1r17 > 1r9 1r10 1r11 1r12 1r13 1r14 1r15 1r16 1r17 1r18 > 1r10 1r11 1r12 1r13 1r14 1r15 1r16 1r17 1r18 1r19 > > The only difference between the two input sentences > is the trailing 10 (machine number) and 10x (extended > precision number). > > m +/ .* %. m=: % 1 + +/~ i.10 > 1.00047 _0.00619721 > 0.0133228 0.00179932 _0.00673962 _0.00755167 _0.00690055 > _0.000172734 0.00353628 0.00956631 > _0.00620086 > 1.0811 _0.174345 _0.0235263 > 0.0882211 0.0988431 > 0.0903749 0.00217986 _0.0462107 _0.125206 > 0.0133312 > _0.174349 1.37482 > 0.0506763 _0.190106 > _0.21133 _0.196193 _0.00288332 > 0.0984164 0.269389 > 0.00179848 _0.0235348 > 0.0506859 1.00591 _0.0213178 > _0.0402455 _0.00748849 _0.0185254 > 0.0227113 0.0343037 > _0.00674288 0.0882262 > _0.190103 _0.0213129 > 1.07596 0.161627 > 0.0106583 0.0861107 _0.0938043 _0.126691 > _0.00756361 0.098839 > _0.211326 _0.0402408 > 0.161622 0.974321 > 0.34696 _0.223546 > 0.06125 _0.178329 > _0.00690331 0.090379 > _0.196192 _0.00748292 0.0106608 > 0.346969 0.71698 > 0.368988 _0.242016 _0.0978327 > _0.000171363 0.00217855 _0.00288343 > _0.0185248 0.0861086 > _0.223544 0.368986 > 0.649903 0.18074 _0.0432134 > 0.003535 _0.0462151 > 0.0984225 0.0227093 _0.0938085 > 0.0612454 _0.24202 > 0.180739 0.931766 0.0920672 > 0.00957343 _0.125208 > 0.269389 0.0342936 _0.126692 > _0.178331 _0.0978323 _0.0432161 > 0.0920641 1.18877 > > x +/ .* %. x=: % 1 + +/~ i.10x > 1 0 0 0 0 0 0 0 0 0 > 0 1 0 0 0 0 0 0 0 0 > 0 0 1 0 0 0 0 0 0 0 > 0 0 0 1 0 0 0 0 0 0 > 0 0 0 0 1 0 0 0 0 0 > 0 0 0 0 0 1 0 0 0 0 > 0 0 0 0 0 0 1 0 0 0 > 0 0 0 0 0 0 0 1 0 0 > 0 0 0 0 0 0 0 0 1 0 > 0 0 0 0 0 0 0 0 0 1 > > The preceding are two expressions of the product of the > Hilbert matrix and its inverse. The first uses machine numbers; > the second uses extended precision numbers. > > > > ----- Original Message ----- > From: DIETER ENSSLEN <[email protected]> > Date: Sunday, August 9, 2009 13:43 > Subject: Re: [Jgeneral] Array Based Languages > To: General forum <[email protected]> > > > so unfortunately for the moment or for a very long time we are > > in this at the level of all ipod touch / i phones: 16 > > significant digits, and one level above windows excel's 15, > and > > quite a few levels below several i pod Apps ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
