Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#7405 closed enhancement (fixed)

Change the print of predefined words to the default behavior

Reported by: slabbe Owned by: slabbe
Priority: major Milestone: sage-4.3
Component: combinatorics Keywords: words
Cc: saliola Merged in: sage-4.3.alpha1
Authors: Sébastien Labbé Reviewers: Florent Hivert
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by slabbe)

This ticket concern 4 relatively small things.

(1) Change the print of predefined words to the default behavior.
(2) Correct a bug of __mul__ of WordMorphism.
(3) Adds the Fibonacci word defined from function.
(4) Adds documentation and doctest to a recently added function called _element_classes in word.py.

See below for more explanations.

(1) The rename function is used a lot for predefined words :

sage: words.FibonacciWord()
Fibonacci word over Ordered Alphabet [0, 1], defined recursively
sage: words.FibonacciWord((0,1),'fixed point')
Fibonacci word over Ordered Alphabet [0, 1], defined as the fixed point of a morphism
sage: words.ThueMorseWord(alphabet = (3,4))
Thue-Morse word over Ordered Alphabet [3, 4]
sage: words.FixedPointOfMorphism('a->ab,b->ba','a')
Fixed point beginning with 'a' of the morphism WordMorphism: a->ab, b->ba
sage: words.ChristoffelWord(4,7)
Lower Christoffel word of slope 4/7 over Ordered Alphabet [0, 1]

But I more and more dislike this behavior made for the user since (1) it repeats the information already given by the user and (2) the first thing that the user do with the word is to look the prefix of the word (well, that's what I always do and that's what is done everywhere in the doctests).

To print a prefix, one needs to crete it (which is not always necessary for the user) :

sage: f = words.FibonacciWord()
sage: f
Fibonacci word over Ordered Alphabet [0, 1], defined recursively
sage: print f
Fibonacci word over Ordered Alphabet [0, 1], defined recursively
sage: f[:100]
word: 0100101001001010010100100101001001010010...
sage: print f[:100]
word: 0100101001001010010100100101001001010010100100101001010010010100100101001010010010100100101001010010

I would simply like the following to work :

sage:  words.FibonacciWord()
word: 0100101001001010010100100101001001010010...

which is the default behavior anyway :

sage: Word(lambda n:n%10)
word: 0123456789012345678901234567890123456789...

(2) The codomain of the product of WordMorphism is not correct :

sage: m = WordMorphism('0->a,1->b')
sage: n = WordMorphism('a->c,b->e',codomain=Words('abcde'))
sage: p = n * m
sage: p.codomain()
Words over Ordered Alphabet ['c', 'e']

(3) See the patch. (4) See the patch.

Attachments (1)

trac_7405_words_change_print_to_default-sl.patch (22.8 KB) - added by slabbe 13 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 Changed 13 years ago by slabbe

  • Description modified (diff)

comment:2 Changed 13 years ago by slabbe

  • Status changed from new to needs_review
  • Summary changed from Change the print of predefined words to the default behavior. to [with patch, needs review] Change the print of predefined words to the default behavior.

comment:3 Changed 13 years ago by hivert

  • Report Upstream set to N/A
  • Reviewers set to Florent Hivert

The patch looks good and all tests pass. I'm ready to give a positive review.

However I'm not a word expert so that I'd like someone who is to confirm that the change of printing is really the wanted behavior. Franco: once you agree with that please put a positive review on that patch. I will shorten a bit more the combinat queue...

Cheers,

Florent

comment:4 follow-up: Changed 13 years ago by slabbe

  • Authors set to Sébastien Labbé

Thanks Florent for the review.

I also would like Franco to agree with the print changes before any inclusion in sage since he wrote some of those rename of objects.

Sébastien

comment:5 in reply to: ↑ 4 Changed 13 years ago by saliola

  • Status changed from needs_review to positive_review

I strongly agree with the changes. I think this way is much better.

comment:6 Changed 13 years ago by saliola

  • Summary changed from [with patch, needs review] Change the print of predefined words to the default behavior. to [with patch, positive review] Change the print of predefined words to the default behavior.

Opps, I forgot to change the summary.

comment:7 Changed 13 years ago by mhansen

  • Merged in set to sage-4.3.alpha1
  • Resolution set to fixed
  • Status changed from positive_review to closed

comment:8 Changed 13 years ago by mvngu

  • Summary changed from [with patch, positive review] Change the print of predefined words to the default behavior. to Change the print of predefined words to the default behavior
Note: See TracTickets for help on using tickets.