Opened 9 years ago

Closed 9 years ago

#13677 closed enhancement (fixed)

Improve __repr__ and __str__ methods of WordMorphism

Reported by: slabbe Owned by: slabbe
Priority: major Milestone: sage-5.5
Component: combinatorics Keywords: wordmorphism
Cc: tjolivet, vdelecroix Merged in: sage-5.5.rc0
Authors: Sébastien Labbé Reviewers: Timo Jolivet
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

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)

Attachments (3)

trac_13677-sl.patch (3.0 KB) - added by slabbe 9 years ago.
trac_13677_docfixes_iet-sl.patch (6.5 KB) - added by slabbe 9 years ago.
trac_13677_docfixes_words-sl.patch (30.0 KB) - added by slabbe 9 years ago.

Download all attachments as: .zip

Change History (12)

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:3 Changed 9 years ago by slabbe

  • Cc tjolivet vdelecroix added

Changed 9 years ago by slabbe

Changed 9 years ago by slabbe

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!

Changed 9 years ago by slabbe

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: Changed 9 years ago by jdemeyer

Please clarify which patches need to be applied.

comment:8 in reply to: ↑ 7 Changed 9 years ago by slabbe

Replying to jdemeyer:

Please clarify which patches need to be applied.

All of them, in any order.

comment:9 Changed 9 years ago by jdemeyer

  • Merged in set to sage-5.5.rc0
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.