difference between PermutationGroup.has_element and PermutationGroup.__contains__

43 views
Skip to first unread message

Martin R

unread,
May 9, 2022, 3:35:42 AM5/9/22
to sage-devel
I just found
{{{
    def __contains__(self, item):
        """
        Return whether ``item`` is an element of the group.
...

    def has_element(self, item):
        """
        Returns boolean value of ``item in self`` - however *ignores*
        parentage.
...
        """
        return item in self
}}}

Isn't has_element just an alias of __contains__?

Martin

davida...@gmail.com

unread,
May 9, 2022, 2:17:09 PM5/9/22
to sage-devel
As you noticed, the difference between these two methods is very thin. The special method "__contains__" is necessary because it is called whenever the keyword "in" is used. I think that the code could have been simplified to:

{{{
    def __contains__(self, item):
        """
        Return whether ``item`` is an element of the group.
...

    has_element = __contains__
}}}

Why wasn't it done like this before? I don't know. Is there a better practice? I don't know.

What I know is that if you implement a new structure following the Parent/Element framework (for example:
https://doc.sagemath.org/html/en/thematic_tutorials/coercion_and_categories.html), the __contains__ method should be already available right out of the box.


Martin R

unread,
May 9, 2022, 5:35:10 PM5/9/22
to sage-devel
Exactly this is what I meant with "alias", and why I think that its documentation is misleading, if not wrong.  I just checked, has_element is not used in the sage library at all.  I thus propose to deprecate it.

Kwankyu Lee

unread,
May 10, 2022, 7:10:18 AM5/10/22
to sage-devel
On Tuesday, May 10, 2022 at 6:35:10 AM UTC+9 axio...@yahoo.de wrote:
Exactly this is what I meant with "alias", and why I think that its documentation is misleading, if not wrong.  I just checked, has_element is not used in the sage library at all.  I thus propose to deprecate it.

+1. But first survey use of `has_element` throughout sage library, to balance. 
 

Martin R

unread,
May 10, 2022, 8:30:07 AM5/10/22
to sage-devel
As I said, it is unused.  This is now https://trac.sagemath.org/ticket/33831
Reply all
Reply to author
Forward
0 new messages