p j, I understand your frustrations, and have shared them in various
contexts, but it is the world you should be mad at, not J.

Like most computer languages, J does not keep track of the precision of
its results.  Even simple arithmetic can lose precision (e.g. subtracting
two numbers that are almost equal or dividing a large number by a small
number).  Trying to keep track of this is highly non-trivial,
computationally expensive, and irrelevant for most purposes.  The approach
generally taken to address this is to use algorithms which will not make
it worse (e.g. the LAPACK algorithms manipulate matrices into a form where
these errors are minimized) or to use iterative algorithms (a close
approximation that is slightly in error is still a close approximation). 
Putting x: in front of things will make this go away for rational
operations, but at a cost in execution time and space.  Symbolic systems
like Maple and Mathematica put off evaluating things numerically unless
they are forced to do so.  Even then, they are subject to loss of
precision in evaluation.

If you want to calculate a square root to a precision you specify, you
need an algorithm, rather than expecting default behavior to work
miracles.  There is a J phrase that will do this using Newton's method:

>From section 8A (still in J504 here)

d85=: 4 : '-:@(+y.&%)^:(>.2^.1>.x.-16)x:%:y.'

uses Newton's method to find x decimal digits of the square root of y.

Best wishes,

John


p j wrote:
> ">>J has finite memory.  Precise representation of an
>> irrational number using a rational representation
>> would require infinite memory.
>
> Although it would be great if there was a switch to
> get "bignumber" extremely high precision that's not
> what I'm requesting here.
>
> I would like a switch that makes J either print the
> right digits or no digits at all.
>
> 61j59 ": x:!.0 %:2
> 1.41421356237309536751922678377013653516769409179687500000000
>    61j59 ": x: %:2
> 1.41421356237313909704121810319897219048636704119254805757362
> from web, real answer
> 1.4142135623 7309504880 1688724209 6980785696
> 7187537694
>
> Even with x:!.0 the 15th digit on is crap.  At least,
> around the 50th digit on gets zero'ed out, so you at
> least have a clue that using expansion that high is
> not accurate.
> Basically I would like a switch that forces J to not
> print anything past the 15th digit if it won't be
> accurate.  If the only benefit is teaching the user
> exactly where the lies begin, its a huge gain, as that
> beats loading the web and comparing digits side by
> side.
>>From a programming perspective it is very difficult to
> debug errors that occur on the 2^64th loop iteration.
>
> --- "Miller, Raul D" <[EMAIL PROTECTED]> wrote:
>
>> p j wrote:
>> > The main problem,
>> >    cf x: %: 2
>> > 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 45 2 1 2 11 1
>> 3 6
>> >    cf x:!.0 %: 2
>> > 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 1 4 2
>> 5 9
>> > 3 3 1 11 57 2
>>
>> Why is this a problem?
>>
>> J has finite memory.  Precise representation of an
>> irrational number using a rational representation
>> would require infinite memory.
>>
>> Which is why we get rational approximations as
>> results from functions which we think of as
>> irrational:
>>
>>    %: 2
>> 1.41421
>>    x: %: 2x
>> 431273813145r304956637823
>>
>> It's also possible to look at the gory internal
>> details of these numbers.
>>
>>    3!:3 %: 2
>> e1000000
>> 08000000
>> 01000000
>> 00000000
>> cd3b7f66
>> 9ea0f63f
>>
>> %: 2 is represented as an ieee floating point
>> number.
>>
>> But, perhaps, the numeric headers are distracting:
>>
>>    hexRepresentation=: (#3!:3 i.0) ,@}. 3!:3@,
>>    hexRepresentation %:2
>> cd3b7f669ea0f63f
>>
>> On the other hand:
>>
>>    hexRepresentation x:%:2x
>>
> 1c0000003c000000e100000004000000030000000100000003000000490c0000d51c0000d8100000e1000000040000000300000001000000030000008f1e00001f160000e90b0000
>>
>> 431273813145r304956637823 is represented using what
>> looks like a pair of numeric vectors of some sort.
>>
>> --
>> Raul
>>
> ----------------------------------------------------------------------
>> For information about J forums see
>> http://www.jsoftware.com/forums.htm
>>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>


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

Reply via email to