Hello, it would be nice to get some feedback. This bug has consequences on other functions in the combinatorics on words package: for instance, you get
sage: Word('abaa').is_conjugate_with(Word('aaba')) True sage: Word('aaba').is_conjugate_with(Word('abaa')) False even though conjugacy is an equivalence relation. Again, the problem here is that "-1" mistake in the conjugate_position method. It is just a small change, and this group is the only place I know for proposing it. Thanks Alessandro On 21 Mar, 16:11, Alessandro De Luca <alessandro.del...@utu.fi> wrote: > I have taken a look at the code, and I think I have identified the > bug. I'm not sure this is the most appropriate place to suggest a > modification; if not, I hope someone can forward this to the right > address, or at least tell me where to post it. > > Here are some tests showing the issue: > > sage: w=Word([0,0,1,0,2,1]); w > word: 001021 > > sage: w.conjugate(-1) #a conjugate is just a cyclic shift > word: 100102 > > sage: w.conjugate(5) #cyclic shifts are defined modulo the length > word: 100102 > > #conjugate_position correctly shows here how much you need to shift w > to get its 0th conjugate (itself) > sage: w.conjugate(0).conjugate_position(w) > 0 > > sage: w.conjugate(1).conjugate_position(w) > 1 > > # in general, for primitive words (i.e., non-powers) such as w, the > result of > # w.conjugate(n).conjugate_position(w) > # should always equal n % w.length(): > sage: w.conjugate(-2).conjugate_position(w) > 4 > > sage: w.conjugate(-1).conjugate_position(w) #so here the output > should be 5, but... > > sage: w.conjugate(-1).conjugate_position(w) is None #oops! > True > > sage: v=Word('abacabac'); v #the square of 'abac', a non-primitive > word > word: abacabac > > #the following computation is right; the bug only appears when the > expected answer is length-1 > #so non-primitive words always work fine. > sage: v.conjugate(-1).conjugate_position(v) > 3 > ________ > > Here is the current version of the code: > > def conjugate_position(self, other): > r""" > Returns the position where self is conjugate with other. > Returns None if there is no such position. > > EXAMPLES:: > > sage: Word('12113').conjugate_position(Word('31211')) > 1 > sage: Word('12131').conjugate_position(Word('12113')) is None > True > sage: Word().conjugate_position(Word('123')) is None > True > """ > if self.length() != other.length(): > return None > if self == other: > return 0 > for l in xrange(1, other.length() - 1): > other = other.conjugate(1) > if self == other: > return l > return None > > I believe that in order to fix this bug, it is sufficient to > substitute line -5, i.e., > for l in xrange(1, other.length() - 1): > > with the following > for l in xrange(1, other.length()): > > I hope I have made myself clear. > Thanks again, bye > > Alessandro > > On 21 Mar, 09:35, "Nicolas M. Thiery" <nicolas.thi...@u-psud.fr> > wrote: > > > > > > > > > Hi Alessandro, > > > On Sun, Mar 20, 2011 at 05:48:22PM -0700, Alessandro De Luca wrote: > > > I am writing because the conjugate_position method (for finite words) > > > is not working the way I expected. I believe that the output for > > > > w.conjugate(-1).conjugate_position(w) > > > > should equal w.length()-1 for all words w on at least two letters. > > > However, I seem to get no answer, all the time (just as if the two > > > words were not conjugate). All other positions, apart from -1, seem to > > > work just fine. > > > I'm running the latest Sage version, 4.6.2. > > > I don't know what the right thing should be here. But please include > > examples with the obtained output and the output you'd expect: > > > sage: w = ... > > sage.conjugate(-1).conjugate_position(w) > > ... > > > Whatever is the conclusion of the discussion, those should be added to > > the documentation with an explanation; so this is not wasted time, and > > it makes things concrete. > > > Thanks! > > Nicolas > > -- > > Nicolas M. Thi�ry "Isil" <nthi...@users.sf.net>http://Nicolas.Thiery.name/ -- You received this message because you are subscribed to the Google Groups "sage-combinat-devel" group. To post to this group, send email to sage-combinat-devel@googlegroups.com. To unsubscribe from this group, send email to sage-combinat-devel+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sage-combinat-devel?hl=en.