Opened 9 years ago

Closed 9 years ago

# Improve __repr__ and __str__ methods of WordMorphism

Reported by: Owned by: slabbe slabbe major sage-5.5 combinatorics wordmorphism tjolivet, vdelecroix sage-5.5.rc0 Sébastien Labbé Timo Jolivet N/A

### Description

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)
```

### comment:1 Changed 9 years ago by slabbe

• Dependencies set to #13676

### comment:2 Changed 9 years ago by slabbe

• Status changed from new to needs_review

### comment:4 Changed 9 years ago by slabbe

• Dependencies #13676 deleted

I changed #13676 to remove the dependancies (by not including new `_latex_` method next to the `__repr__` and `__str__` methods).

I separated the patch into 3 pieces : the code changed, docfixes in `sage/combinat/words`, docfixes in `sage/combinat/iet`. It will be easier to review like that and also easier to update if future conflicts occur.

Needs review!

### comment:5 Changed 9 years ago by tjolivet

• Authors set to Sébastien Labbé
• Milestone changed from sage-5.5 to sage-5.4
• Reviewers set to Timo Jolivet
• Status changed from needs_review to positive_review

### comment:6 Changed 9 years ago by jdemeyer

• Milestone changed from sage-5.4 to sage-5.5

### comment:7 follow-up: ↓ 8 Changed 9 years ago by jdemeyer

Please clarify which patches need to be applied.