#15480: Words.__eq__ returns wrong answers
----------------------------------+----------------------------
       Reporter:  ncohen          |        Owner:
           Type:  defect          |       Status:  needs_review
       Priority:  major           |    Milestone:  sage-5.13
      Component:  combinatorics   |   Resolution:
       Keywords:                  |    Merged in:
        Authors:  Nathann Cohen   |    Reviewers:
Report Upstream:  N/A             |  Work issues:
         Branch:  u/ncohen/15480  |       Commit:
   Dependencies:                  |     Stopgaps:
----------------------------------+----------------------------
Changes (by ncohen):

 * status:  new => needs_review
 * branch:   => u/ncohen/15480


Old description:

> Right now equality between sets of words only compare the alphabets
>
> {{{
> sage: Words(3, 10) == Words(3,900)
> True
> sage: Words(2, finite=False) == Words(2)
> True
> sage: Words(2) == Words(2,30)
> True
> }}}

New description:

 Right now equality between sets of words only compare the alphabets

 {{{
 sage: Words(3, 10) == Words(3,900)
 True
 sage: Words(2, finite=False) == Words(2)
 True
 sage: Words(2) == Words(2,30)
 True
 sage: Words(10,0) == Words(20,0)
 False
 }}}

 I am not proud of this patch's code, but I see NO other way to all these
 wrongs answers without rewriting the class hierarchy. The fact that a
 class of finite words is an instance (i.e. it inherits) from a class of
 infinite words makes it really hard to implement `O_o`

 {{{
 sage: isinstance(Words(4,30), type(Words(3)))
 True
 }}}

 You cannot be sure, when implementing the `__eq__` method of `Words_all`,
 that self really represents an infinite class of words.

 Besides, the old code read :

 {{{
         if isinstance(other, Words_all):
             return self.alphabet() == other.alphabet()
         else:
             return NotImplemented
 }}}

 I haven't been able to guess when `not (type(self) is type(other))` does
 not mean that the two classes should not be reported as equal.
 Though the old code seems to imply that this can happen.

 If this can happen we need to add a doctest somewhere.

 Nathann

--

--
Ticket URL: <http://trac.sagemath.org/ticket/15480#comment:1>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to