Facade Sets

For background, see What is a facade set?.

class sage.categories.facade_sets.FacadeSets(base_category)[source]

Bases: CategoryWithAxiom_singleton

class ParentMethods[source]

Bases: object

facade_for()[source]

Return the parents this set is a facade for.

This default implementation assumes that self has an attribute _facade_for, typically initialized by Parent.__init__(). If the attribute is not present, the method raises a NotImplementedError.

EXAMPLES:

sage: S = Sets().Facade().example(); S
An example of facade set: the monoid of positive integers
sage: S.facade_for()
(Integer Ring,)
>>> from sage.all import *
>>> S = Sets().Facade().example(); S
An example of facade set: the monoid of positive integers
>>> S.facade_for()
(Integer Ring,)

Check that Issue #13801 is corrected:

sage: class A(Parent):
....:     def __init__(self):
....:         Parent.__init__(self, category=Sets(), facade=True)
sage: a = A()
sage: a.facade_for()
Traceback (most recent call last):
...
NotImplementedError: this parent did not specify which parents it is a facade for
>>> from sage.all import *
>>> class A(Parent):
...     def __init__(self):
...         Parent.__init__(self, category=Sets(), facade=True)
>>> a = A()
>>> a.facade_for()
Traceback (most recent call last):
...
NotImplementedError: this parent did not specify which parents it is a facade for
is_parent_of(element)[source]

Return whether self is the parent of element.

INPUT:

  • element – any object

Since self is a facade domain, this actually tests whether the parent of element is any of the parent self is a facade for.

EXAMPLES:

sage: S = Sets().Facade().example(); S
An example of facade set: the monoid of positive integers
sage: S.is_parent_of(1)
True
sage: S.is_parent_of(1/2)
False
>>> from sage.all import *
>>> S = Sets().Facade().example(); S
An example of facade set: the monoid of positive integers
>>> S.is_parent_of(Integer(1))
True
>>> S.is_parent_of(Integer(1)/Integer(2))
False

This method differs from __contains__() in two ways. First, this does not take into account the fact that self may be a strict subset of the parent(s) it is a facade for:

sage: -1 in S, S.is_parent_of(-1)
(False, True)
>>> from sage.all import *
>>> -Integer(1) in S, S.is_parent_of(-Integer(1))
(False, True)

Furthermore, there is no coercion attempted:

sage: int(1) in S, S.is_parent_of(int(1))
(True, False)
>>> from sage.all import *
>>> int(Integer(1)) in S, S.is_parent_of(int(Integer(1)))
(True, False)

Warning

this implementation does not handle facade parents of facade parents. Is this a feature we want generically?

example(choice='subset')[source]

Return an example of facade set, as per Category.example().

INPUT:

  • choice – ‘union’ or ‘subset’ (default: 'subset')

EXAMPLES:

sage: Sets().Facade().example()
An example of facade set: the monoid of positive integers
sage: Sets().Facade().example(choice='union')
An example of a facade set: the integers completed by +-infinity
sage: Sets().Facade().example(choice='subset')
An example of facade set: the monoid of positive integers
>>> from sage.all import *
>>> Sets().Facade().example()
An example of facade set: the monoid of positive integers
>>> Sets().Facade().example(choice='union')
An example of a facade set: the integers completed by +-infinity
>>> Sets().Facade().example(choice='subset')
An example of facade set: the monoid of positive integers