J.C.Rougier@durham.ac.uk
2001-Jan-09 17:25 UTC
[Rd] Inconsistent behaviour in solve (PR#805)
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? Cheers, Jonathan. --please do not edit the information below-- Version: platform = sparc-sun-solaris2.7 arch = sparc os = solaris2.7 system = sparc, solaris2.7 status = major = 1 minor = 1.1 year = 2000 month = August day = 15 language = R Search Path: .GlobalEnv, Autoloads, package:base -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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. -- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._