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

ripley@stats.ox.ac.uk ripley@stats.ox.ac.uk
Wed, 10 Jan 2001 12:01:57 +0100 (MET)

```On Wed, 10 Jan 2001, Jonathan Rougier wrote:

> 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.

Really?  Which documentation?  I don't think they are the same once
non-finite numbers are involved, and ?solve did not lead me to believe
otherwise.

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

The different is intentional: whoever wrote qr.coef put NAOK=TRUE
in R put not in S.

--
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```