#13677: Improve __repr__ and __str__ methods of WordMorphism
-----------------------------+----------------------------------------------
Reporter: slabbe | Owner: slabbe
Type: enhancement | Status: new
Priority: major | Milestone: sage-5.5
Component: combinatorics | Keywords: wordmorphism
Work issues: | Report Upstream: N/A
Reviewers: | Authors:
Merged in: | Dependencies:
Stopgaps: |
-----------------------------+----------------------------------------------
The `__repr__` method is not fun:
{{{
sage: WordMorphism('a->ab,b->ba')
Morphism from Words over Ordered Alphabet ['a', 'b'] to Words over Ordered
Alphabet ['a', 'b']
sage: WordMorphism({0:[0,1],1:[1,0]})
Morphism from Words over Ordered Alphabet [0, 1] to Words over Ordered
Alphabet [0, 1]
}}}
One always have to use the print statement (which calls `__str__`) ::
{{{
sage: print WordMorphism('a->ab,b->ba')
WordMorphism: a->ab, b->ba
sage: print WordMorphism({0:[0,1],1:[1,0]})
WordMorphism: 0->01, 1->10
}}}
Also, this is ugly:
{{{
sage: sigma = WordMorphism({1:[1,2], 2:[1,3], 3:[1]})
sage: E = E1Star(sigma)
sage: E
E_1^*(WordMorphism: 1->12, 2->13, 3->1)
}}}
The proposed solution is to change the code of `__repr__` so that it
behaves like the actual `__str__` and change the `__str__` to remove the
`WordMorphism: ` part. See examples below :
The new `__repr__` method :
{{{
sage: WordMorphism('a->ab,b->ba')
WordMorphism: a->ab, b->ba
sage: WordMorphism({0:[0,1],1:[1,0]})
WordMorphism: 0->01, 1->10
}}}
The new `__str__` method :
{{{
sage: print WordMorphism('a->ab,b->ba')
a->ab, b->ba
}}}
{{{
sage: sigma = WordMorphism({1:[1,2], 2:[1,3], 3:[1]})
sage: E = E1Star(sigma)
sage: E
E_1^*(1->12, 2->13, 3->1)
}}}
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/13677>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.