On Sun, Apr 18, 2010 at 10:08:28AM +0930, ross kyprianou wrote: > >> Any ideas of why _repr_ might not be working inside the class? > > Was this class that of the category or the parent? > > I made a copy of AlgebrasWithBasis.py (so that's the category isnt it?) > and placed my version of _repr_ is various places within that code but > it didnt override the default _repr_ > > > If you do (with x some of your elements): > > sage: x.__class__.mro() > > you will see that the category classes appear quite late there, and in > > particular after Parent. Hence, it is (currently) not possible to > > override _repr_, or anything else implemented in Parent, by code in > > categories. > > I called mro on an element P, as suggested... > > (P,Q,R)= MtxAlgebrasWithBasis(QQ).example(('P','Q','R')).algebra_generators() > P.__class__.mro() > > Does the output (at the end of this reply) mean: _repr_ cant be > overridden somehere as you stated above?
You currently have to implement _repr_term / _repr_ in the class for the parent (resp. for the elements). You can't do this in the categories. That sure is a misfeature, which we will fix soon. It just turns out that in the use cases we got so far it was sufficient to implement this at the level of parent/elements, not categories. > (It would be a huge shame. I checked with support from both commercial > players (Mma & Mple) and both said > they dont support this but have been asked for it multiple times. I > understand its been asked by our users also. > And now that I need it, Im highly motivated to implement it :-) > As a last resort - just to get some of my work progressing for now - > Im happy to copy and customize enough > existing categories code to make matrices work it but if I can do this > properly it could end up in the sage code base for others to use. > Question is is: it possible to implement this "properly"? With enough stamina, everything is possible with Sage :-) Kidding aside, yes, it sure is possible. Send me your code, and I refactor it to its simplest form, as a basis for further work. The most efficient would be to upload it on the Sage-Combinat queue, but that will take some learning the tool: http://wiki.sagemath.org/combinat/MercurialStepByStep; otherwise e-mail is fine. > All that is needed, to make a basic prototype matrix algebra, is > > Distributivity == P(Q+R) => PQ + QR (already working thanks to > existing categories code) > Non-commutivity PQ does not equal QR (also is working) > Printing i.e. show "P Q + Q R" rather than "B[word: PQ] + B[word: PR]" > (by overloading _repr_ or by some other means?) > Substitution i.e. P^-1 * P results in identity - And - (P * > Q).Transpose() results in Q.Transpose() + P.Transpose() > > So two tasks done - two to go if possible! Keep up the good work! Cheers, Nicolas -- Nicolas M. Thiéry "Isil" <nthi...@users.sf.net> http://Nicolas.Thiery.name/ -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org