Although Justin's solution certainly works, one might consider adding a "real_part()" function to the quaternion class. But it would not do to call the function "real_part" since of course it depends on the ground field (which in the example is QQ and not RR).
I am CC'ing sage-devel since this might be worth a ticket, and also to ask for suggestions as to what the "real part" might be called in general. John On Mar 27, 10:19 pm, Justin Walker <[EMAIL PROTECTED]> wrote: > On Mar 27, 2008, at 12:58 PM, Chris Godsil wrote: > > > > > I want to extract the "real part" of a quaternion, i.e., if > > > L.<i,j,k> = QuaternionAlgebra(QQ,-1,-1); > > > and a is in L, then I want the coefficient of 1 in the expansion of as > > a linear combination of 1, i, j and k. > > > Is there a way to do this? A graceful way? > > One way is: > x.reduced_trace()/2 > since you are working over QQ :-} > > Another is x.vector()[0]. > > Note that, if x is a Sage (or generally, python) object, "x.TAB" will > get you a list of "methods" that might[*] apply to x. Then if 'foo' > is one, "x.foo?" will get you documentation[+] on what 'foo' does. > > HTH > > Justin > > [*] Some methods are shown due to inheritance, and might actually not > apply in a specific situation. > > [+] Documentation: the best documentation is had with "??" we might > not find it in either case, if it's not in a ".py" file. > > -- > Justin C. Walker, Curmudgeon at Large > Director > Institute for the Enhancement of the Director's Income > ----------- > Nobody knows the trouble I've been > ----------- --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@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-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---