kcrisman wrote: > > > On May 15, 10:55 am, "William Stein" <[EMAIL PROTECTED]> wrote: >> On Thu, May 15, 2008 at 7:48 AM, Jason Grout >> >> >> >> <[EMAIL PROTECTED]> wrote: >> >>> Jason Grout wrote: >>>> Based on some conversations with linear algebra people and classroom >>>> demonstrations in a linear algebra class, people are confused that when >>>> they create a matrix with matrix(3, range(9)), for example, that the >>>> echelon_form is not the rref output that they get from most any other >>>> program they have ever used, and certainly not what is taught in an >>>> undergrad linear algebra class. There is additional confusion if the >>>> entries specified have a fraction in them; then the matrix defaults to >>>> being over QQ, and the echelon_form functino gives the expected naive >>>> rref! The problem, of course, lies in the matrix defaulting to having >>>> base_ring == ZZ (i.e., non-field). >>>> What do people think about making the default ring for matrices QQ? >>>> Additionally, if the ring R is determined from the elements provided, >>>> then the matrix would be over R.fraction_field(). Of course, the >>>> documentation for matrix() would clearly indicate what is happening if >>>> the ring is not specified. >>> More concisely, this proposal could be worded: >>> What do people think of making matrix() return a matrix over a field by >>> default, unless a ring is explicitly specified. The default field would >>> either be the fraction field of the ring containing the specified >>> elements, or would be QQ if no elements are specified. This logic would >>> *only* be applied if a ring is not specified. The documentation of >>> matrix() would also be changed accordingly. >> +1 >> >> I suggested this idea. I would never do this is Sage were "just for me", >> but Sage isn't. Please keep that in mind when reading the above proposal... >> >> -- William > > I was just discussing this very issue with my chair yesterday. He had > created some wrappers to make using the elementary operations a little > easier for linear algebra students (though I think ended up sticking > with Octave for this semester for unrelated reasons), and then noticed > this with scaling rows under his first implementation. > > What happens if you start with something like matrix(3, range(9)), but > then want to turn it into a complex matrix and scale a row by (say) i/ > 2? Under the current scaling code, this happens: > > sage: N.rescale_col(2,i/2) > --------------------------------------------------------------------------- > <type 'exceptions.TypeError'> Traceback (most recent call > last) > <snip> > <type 'exceptions.TypeError'>: unable to convert I/2 to a rational > > I certainly have no problem with matrices starting off as rational > ones - a great idea! But it doesn't directly affect this sort of > issue - one could still start with a matrix over ZZ and then want to > multiply it later on by 1/2 without using change_ring(). > > What I am wondering is whether throwing an exception of TypeError > under the current code should be replaced by a try statement first > attempting N.changering(??) . The problem is I have no idea what to > use for ??, because unfortunately i/2 lives in Symbolic Ring, not in > CC, so I can't just put in ??=parent(i/2). It would sort of be beside > of the point of making Sage easier to use in the linear algebra > classroom if we had to explicitly type CC(i/2) everytime we wanted to > use i/2. > > In any case, what "should" happen in the scaling context when scaling > by something mathematically legitimate, but not in the ring the matrix > is defined over in Sage?
I'm not sure I understand the problem. Here is an example session in Sage 3.0.1. Can you change this to illustrate what you mean? sage: m=matrix(3,3,range(9)) sage: n = m*(i/2) sage: n.parent() Full MatrixSpace of 3 by 3 dense matrices over Symbolic Ring sage: n [ 0 I/2 I] [3*I/2 2*I 5*I/2] [ 3*I 7*I/2 4*I] sage: m2 = m/i sage: m2.parent() Full MatrixSpace of 3 by 3 dense matrices over Symbolic Ring sage: m2 [ 0 -1*I -2*I] [-3*I -4*I -5*I] [-6*I -7*I -8*I] Thanks, Jason --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---