From J.C.Rougier@durham.ac.uk  Wed Jan 10 09:39:56 2001
From: J.C.Rougier@durham.ac.uk (Jonathan Rougier)
Date: Wed, 10 Jan 2001 09:39:56 +0000 (GMT)
Subject: [Rd] Inconsistent behaviour in solve (PR#805)
In-Reply-To: <Pine.GSO.4.31.0101091816140.10815-100000@auk.stats>
Message-ID: <Pine.GSO.4.20.0101100932280.503-100000@laplace>

On Tue, 9 Jan 2001, Prof Brian D Ripley wrote:

> On Tue, 9 Jan 2001 J.C.Rougier@durham.ac.uk wrote:
> 
> > I find this a bit puzzling ...
> >
> > > solve(matrix(c(5, 2, 3, 1), 2, 2), c(Inf, 3))
> > [1] NaN Inf
> > > solve(matrix(c(5, 2, 3, 1), 2, 2)) %*% c(Inf, 3)
> >      [,1]
> > [1,] -Inf
> > [2,]  Inf
> >
> > I would expect the answer to be c(-Inf, Inf), so why has the -Inf
> > been replaced by NaN in solve?
> 
> Why would you expect it?  Did you actually check it?
> You have 5x + 3y = Inf,  2x + y = 3
> if y - Inf, x = -Inf and 5x + 3y = NaN, 2x + y = NaN.
> 
> Once you have infinities, the standard laws of arithmetic break.

What was puzzling was that the answers were not the same.  The two results
will have different effects in further calculations as NaN and -Inf are
not treated identically (e.g. max or min).  My understanding, supported by
the documentation, is that the two results should be identical, excepting
numerical accuracy.

In S+ the first version generates an error while the second gives c(-Inf,
Inf) as expected.  I think this is safer.

Cheers, Jonathan.

Jonathan Rougier                       Science Laboratories
Department of Mathematical Sciences    South Road
University of Durham                   Durham DH1 3LE
tel: +44 (0)191 374 2361, fax: +44 (0)191 374 7388
http://www.maths.dur.ac.uk/stats/people/jcr/jcr.html

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] Inconsistent behaviour in solve (PR#805)
Jonathan Rougier