On Sat, Mar 7, 2015 at 4:52 AM, John Cremona <
john.c...@gmail.com> wrote:
> On 7 March 2015 at 08:50, Simon King <
simon...@uni-jena.de> wrote:
>> On 2015-03-07, Volker Braun <
vbrau...@gmail.com> wrote:
>>> On Saturday, March 7, 2015 at 3:36:18 AM UTC+1, William wrote:
>>>>
>>>> I tend to agree -- Having rank be removed or raise an error and
>>>> suggest that if they want to compute ranks they must use an exact ring
>>>
>>>
>>> Its still educational, to teach about floating point computation and so on.
>>> We could raise a warning...
>>
>> I agree. I think a warning message menntioning appropriate methods over
>> inexact fields and advising to use exact rings would be ideal.
>
> I think that many users would consider 1.2 to be an exact number. I
> have certainly had to explain to students that if the answer to an
> exact calculation is 6/5 then it is better not to convert to decimal,
> despite what they were taught at school. Of course I understand
> what floating point numbers are, so don't bother telling me! But at
> school, and in mathematics (as opposed to computational mathematics),
> 1.2 and 6/5 are two different ways of writing the exact same number.
In case you want to experience what Sage would feel like with 1.2
becoming exact, do this:
RealNumber0 = RealNumber; RealNumber = lambda x : QQ(RealNumber0(x))
Then
sage: .3
3/10
sage: n = matrix([ [-0.3, 0.2, 0.1],[0.2, -0.4, 0.4], [0.1, 0.2, -0.5] ])
sage: n.rank()
2
sage: n
[-3/10 1/5 1/10]
[ 1/5 -2/5 2/5]
[ 1/10 1/5 -1/2]
etc. So actually *implementing* what you're talking about above is
an easy one-liner.
>
> We cannot really win with this one. From what I wrote above it is
> tempting to convert "simple" decimal literals into some exact ring on
> input, but then someone will input 0.333 and be disappointed that Sage
> did not guess that they meant 1/3.
I suspect that most users of computing software outside of pure math
(e.g., in engineering, applied math, sciences, etc.) expect pretty
much everything to just get rounded to double precision floating like
it does on (1) most calculators, and -- more importantly -- like it
does in (2) Matlab.
Matlab is in fact genuinely much worse than Sage here, in my opinion.
It has a way to represent rational numbers as fractions, and lets you
work with matrices involving them. It's funny because under the hood
it does *everything* using floats, so some answers are completely
wrong (if the numbers were rationals, as they are displayed). Here's
an example; it's a simplified version of something that confused the
hell out of a grad student once a few years ago. Below I compute the
rref of the same matrix over QQ in Octave, Matlab, and Sage, and get
three completely different answers!
In Octave:
octave:1> format rat;
octave:2> a = [-86/17,40/29,-68/43,-20/11;-24/17,-1/38,-2/25,49/17]
a = -86/17 40/29 -68/43 -20/11 -24/17 -1/38 -2/25 49/17
octave:3> rref(a)
ans = 1 0 155/2122 -725/384 0 1 -152/173 -6553/795
In Matlab:
>> format rat;
>> a = [-86/17,40/29,-68/43,-20/11;-24/17,-1/38,-2/25,49/17]
a = -86/17 40/29 -68/43 -20/11 -24/17 -1/38 -2/25 49/17
>> rref(a)
ans = 1 0 13/178 -725/384 0 1 -152/173 -1426/173
sage: F = matrix(2,[-86/17, 40/29, -68/43, -20/11, -24/17, -1/38, -2/25, 49/17])
sage: F.rref()
[ 1 0 306034/4189705 -404710/214357]
[ 0 1 -18405604/20948525 -30037214/3644069]
Caveat: this example is from 2009 -- see
http://linear.ups.edu/sage/linear-tutorial-beezer-sd15.pdf
--
William (
http://wstein.org)