On Fri, Jul 18, 2008 at 2:11 AM, John H Palmieri <[EMAIL PROTECTED]> wrote: > > > > On Jul 17, 4:51 pm, Carl Witty <[EMAIL PROTECTED]> wrote: >> On Jul 17, 3:30 pm, John H Palmieri <[EMAIL PROTECTED]> wrote: >> >> >> >> > I have several different vector space bases for an algebra A, and I >> > have implemented this by having a class MyAlgebra, instances of which >> > have an attribute _basis_name which is a string naming the basis. I >> > have __cmp__ defined so that the basis is ignored: any two instances >> > are canonically isomorphic, and there is good coercion between them. >> >> > Now, the attribute _basis_name just affects the _repr_ and _latex_ >> > methods for elements of the algebra; it has no other effect. My >> > question is this: when I multiply elements from algebras with two >> > different bases, I can't figure out how the parent of the result is >> > determined. Some documentation suggests that the parent should be >> > determined by the left factor, but that is not consistently what's >> > happening. >> >> > I think I would like to force the result to have the same parent as >> > the left-hand factor, but by the time elements get to the _mul_ >> > method, their parents have been changed (via coercion), so I can't >> > find out what that parent is. (Perhaps something is getting cached in >> > the coercion process, so things are getting coerced to the cached >> > algebra, not the left-hand parent?) What should I do? Does it sound >> > like I'm doing something wrong, and if so, what should I investigate? >> >> Currently it's built-in to coercion that if two parents are equal, >> then it doesn't matter which parent it picks. (And the decision is >> baked into various caches, etc., so the decision can depend on the >> previous history of commands in this session.) >> >> I've raised this issue as a problem a few weeks ago >> (seehttp://groups.google.com/group/sage-devel/browse_thread/thread/4520ed...), >> but nothing came of it yet. >> >> Even if this gets fixed, I don't think you can fix it so that coercion >> uses the parent of the left-hand value by changing your code; this >> would require changes inside the base coercion code. > > Okay, thanks. Here's something from Section 2.8 of the Sage > Programming Guide: > > ARITHMETIC __add__, __mul__, ...:: When doing a binary operation, if > the parents are not identical (in the sense of is ), determine if > precisely one _coerce_ map is defined; if so, apply it and do the > arithmetic operation. If both are defined, the parents are canonically > isomorphic, so use the left one. If neither are defined, raise a > TypeError. (Whether or not there is a coerce map between objects > should be cached for efficiency.) > > I guess you're saying that this is wrong (the part that says "so use > the left one").
Argh. It was right when I wrote that documentation and implemented the second version of the coercion model. :-) Whoever implemented the third/fourth version(s) of the coercion model will I hope also update the programming guide with correct statements (hint, hint Robertwb). -- william --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---