#13814: LazyFamily.__eq__ gives false positives.
------------------------------------+---------------------------------------
       Reporter:  cnassau           |         Owner:  sage-combinat
           Type:  defect            |        Status:  new          
       Priority:  major             |     Milestone:  sage-5.6     
      Component:  combinatorics     |    Resolution:               
       Keywords:                    |   Work issues:               
Report Upstream:  N/A               |     Reviewers:               
        Authors:  Christian Nassau  |     Merged in:               
   Dependencies:                    |      Stopgaps:               
------------------------------------+---------------------------------------
Description changed by cnassau:

Old description:

> `LazyFamily.__eq__` occasionally returns false positives, because it only
> compares function names, not values. This can lead to subtle bugs later,
> like this one:
>
> {{{
> #!python
> fun = lambda i:i
> fam1 = LazyFamily((0,1),fun)
> fun = lambda i:i+6
> fam2 = LazyFamily((0,1),fun)
> fam3 = LazyFamily((2,3),fun)
> d1 = DisjointUnionEnumeratedSets((fam1,fam3))
> d2 = DisjointUnionEnumeratedSets((fam2,fam3))
> for u in (fam1,fam2,fam3,d1,d2):
>     print list(u)
> }}}
>
> This gives
>
> {{{
> [0, 1]
> [6, 7]
> [8, 9]
> [0, 1, 8, 9]
> [0, 1, 8, 9]
> }}}
>
> because Sage thinks `fam1 == fam2`. The behaviour can be fixed by setting
>
> {{{
> def noteq(self,other):
>     return False
> LazyFamily.__eq__ = noteq
> }}}
>
> I think `__eq__` should *never* give false positives for classes that
> might be hashed. In this case `LazyFamily.__eq__` should
>
>    * test function equality if the index sets are finite of the same size
>    * return `False` if the both index sets are infinite

New description:

 `LazyFamily.__eq__` occasionally returns false positives, because it only
 compares function names, not values. This can lead to subtle bugs later,
 like this one:

 {{{
 #!python
 fun = lambda i:i
 fam1 = LazyFamily((0,1),fun)
 fun = lambda i:i+6
 fam2 = LazyFamily((0,1),fun)
 fam3 = LazyFamily((2,3),fun)
 d1 = DisjointUnionEnumeratedSets((fam1,fam3))
 d2 = DisjointUnionEnumeratedSets((fam2,fam3))
 for u in (fam1,fam2,fam3,d1,d2):
     print list(u)
 }}}

 This gives

 {{{
 #!python
 [0, 1]
 [6, 7]
 [8, 9]
 [0, 1, 8, 9]
 [0, 1, 8, 9]
 }}}

 because Sage thinks `fam1 == fam2`. The behaviour can be fixed by setting

 {{{
 #!python
 def noteq(self,other):
     return False
 LazyFamily.__eq__ = noteq
 }}}

 I think `__eq__` should _never_ give false positives for classes that
 might be hashed. In this case `LazyFamily.__eq__` should

    * test function equality if the index sets are finite of the same size
    * return `False` if one of the indexing sets is infinite

--

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/13814#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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to