# This made things very interesting. # Using WordOptions(identifier='') does most of the work needed
### Example 1 ### sage: (P,Q,R)= MtxAlgebrasWithBasis(QQ).example(('P','Q','R')).algebra_generators() sage: P*(Q+R) B[word: PQ] + B[word: PR] ### Example 2 ### sage: WordOptions(identifier='') sage: P*(Q+R) B[PQ] + B[PR] # To go "all the way" a bit more code seems to be needed # this is based on the _repr_ referred to in previous tip from Nicolas def _repr_(self): v = self._monomial_coefficients.items() try: v = sorted(v) except StandardError: # Sorting the output is a plus, but if we can't, no big deal pass repr_term = self.parent()._repr_term # mons = [ repr_term(m) for (m, _) in v ] mons = [ m.string_rep() for (m, _) in v ] cffs = [ x for (_, x) in v ] x = repr_lincomb(mons, cffs).replace("*1 "," ") if x[len(x)-2:] == "*1": return x[:len(x)-2] else: return x # was tested using ... _repr_((P+Q)*R) 'PR + QR' This is what I was aiming to be printed when I do (P+Q)*R Does this code (in the new _repr_) look ok? Im aiming to do things consistently or to standards. Anything better recommended? I should be returning a string from _repr_ - shouldnt I ? thanks Ross On Mon, Apr 12, 2010 at 6:41 PM, slabbe <sla...@gmail.com> wrote: > Hi, > >> Im guessing the code to make the "B[word: ....]" string >> may have been in a python file that corresponded to one of the >> Categories above but couldnt find it > > The 'word: ' part comes from sage/combinat/words : > > sage: Word(range(10)) > word: 0123456789 > sage: Word(lambda n:n) > word: > 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,... > > Currently, one can change the identifier 'word: ' globaly by doing : > > sage: WordOptions(identifier='somethingelse') > sage: Word(lambda n:n%10, length=20) > somethingelse01234567890123456789 > > Or one can erase it completely by doing : > > sage: WordOptions(identifier='') > sage: Word(range(10)) > 0123456789 > > Hence, we get the following which look better : > > sage: WordOptions(identifier='') > sage: A = AlgebrasWithBasis(QQ).example() > sage: A.an_element() > B[] + 2*B[a] + 3*B[b] > sage: A.one() > B[] > sage: A(1) > B[] > > A cleaner solution would avoid changing the global identifier... but > this needs some thoughts and adapt the code somewhere. > > Cheers, > > Sébastien Labbé > > -- > 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 > > To unsubscribe, reply using "remove me" as the subject. > -- 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