Michael Orlitzky wrote: > Jason Grout wrote: >> I think there are several points here: >> >> 1. The moment Sage sees a decimal, it starts using approximate, floating >> point arithmetic. If you don't want that, then don't use decimals; use >> fractions. This is consistent with most mathematical software (though >> other software may have better algorithms that minimize the effect of >> the round-off errors). >> >> 2. Sage currently does not deal very well with round-off error in linear >> algebra. This needs to be fixed. Furthermore, Sage doesn't tell you >> (like matlab *sometimes* does) when round-off error might be a big >> issue. For your matrix, Sage probably should have warned you that >> round-off error might lead to an incorrect response. >> >> I've opened up http://trac.sagemath.org/sage_trac/ticket/7392 and >> http://trac.sagemath.org/sage_trac/ticket/7391 to address specific >> issues that came up in this thread. Implementing numerically stable >> arbitrary precision linear algebra is a much bigger project, so I'm >> holding off on opening up a ticket until someone starts making it happen. > > Thanks. If there's a warning, this is a lot less dangerous. > > >> Don't use decimals; use fractions. Then Sage does everything exactly, >> with no round-off error. > > But how would you go about that? You'd have to convert them all by hand, > which sort of defeats the purpose. It would be nice if we could, say, > map (lambda x: x.exact_rational()) the matrix, but once the decimal > number is stored as floating point, its representation is already > incorrect. For example,
Apparently this tries harder to make a "nice" fraction: sage: QQ(0.3) 3/10 So you could do this like Simon says in his post, or like this: sage: n = matrix(QQ, [ [-0.3, 0.2, 0.1], [0.2, -0.4, 0.4], [0.1, 0.2, -0.5] ]) or sage: n.apply_map(lambda x: QQ(x)) [-3/10 1/5 1/10] [ 1/5 -2/5 2/5] [ 1/10 1/5 -1/2] > > I admit to not searching very hard, but is there even any mention in the > docs that this is going to happen as soon as you introduce a decimal point? That's a good question. If you find a place in the docs that is very natural to talk about floating point numbers and computers (which is a very general subject), that would probably be the place for mentioning this. Feel free to send in a patch, or even just the text that should be added! Thanks, Jason --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---