Bases: exceptions.ValueError
Exception raised when some operation can’t be performed on the empty set.
EXAMPLES:
sage: def first_element(st):
... if not st: raise EmptySetError, "no elements"
... else: return st[0]
sage: first_element(Set((1,2,3)))
1
sage: first_element(Set([]))
Traceback (most recent call last):
...
EmptySetError: no elements
Bases: sage.categories.category.Category
The category of sets
The base category for collections of elements with = (equality)
This is also the category whose objects are all parents.
EXAMPLES:
sage: Sets()
Category of sets
sage: Sets().super_categories()
[Category of sets with partial maps]
sage: Sets().all_super_categories()
[Category of sets, Category of sets with partial maps, Category of objects]
Let us consider an example of set:
sage: P = Sets().example("inherits")
sage: P
Set of prime numbers
See P?? for the code.
P is in the category of sets:
sage: P.category()
Category of sets
and therefore gets its methods from the following classes:
sage: for cl in P.__class__.mro(): print(cl)
<class 'sage.categories.examples.sets_cat.PrimeNumbers_Inherits_with_category'>
<class 'sage.categories.examples.sets_cat.PrimeNumbers_Inherits'>
<class 'sage.categories.examples.sets_cat.PrimeNumbers_Abstract'>
<class 'sage.structure.unique_representation.UniqueRepresentation'>
<type 'sage.structure.parent.Parent'>
<type 'sage.structure.category_object.CategoryObject'>
<type 'sage.structure.sage_object.SageObject'>
<class 'sage.categories.sets_cat.Sets.parent_class'>
<class 'sage.categories.category.SetsWithPartialMaps.parent_class'>
<class 'sage.categories.objects.Objects.parent_class'>
<type 'object'>
We run some generic checks on P:
sage: TestSuite(P).run(verbose=True)
running ._test_an_element() . . . pass
running ._test_category() . . . pass
running ._test_elements() . . .
Running the test suite of self.an_element()
running ._test_category() . . . pass
running ._test_not_implemented_methods() . . . pass
running ._test_pickling() . . . pass
pass
running ._test_not_implemented_methods() . . . pass
running ._test_pickling() . . . pass
running ._test_some_elements() . . . pass
Now, we manipulate some elements of P:
sage: P.an_element()
47
sage: x = P(3)
sage: x.parent()
Set of prime numbers
sage: x in P, 4 in P
(True, False)
sage: x.is_prime()
True
They get their methods from the following classes:
sage: for cl in x.__class__.mro(): print(cl)
<class 'sage.categories.examples.sets_cat.PrimeNumbers_Inherits_with_category.element_class'>
<class 'sage.categories.examples.sets_cat.PrimeNumbers_Inherits.Element'>
<type 'sage.rings.integer.IntegerWrapper'>
<type 'sage.rings.integer.Integer'>
<type 'sage.structure.element.EuclideanDomainElement'>
<type 'sage.structure.element.PrincipalIdealDomainElement'>
<type 'sage.structure.element.DedekindDomainElement'>
<type 'sage.structure.element.IntegralDomainElement'>
<type 'sage.structure.element.CommutativeRingElement'>
<type 'sage.structure.element.RingElement'>
<type 'sage.structure.element.ModuleElement'>
<class 'sage.categories.examples.sets_cat.PrimeNumbers_Abstract.Element'>
<type 'sage.structure.element.Element'>
<type 'sage.structure.sage_object.SageObject'>
<class 'sage.categories.sets_cat.Sets.element_class'>
<class 'sage.categories.category.SetsWithPartialMaps.element_class'>
<class 'sage.categories.objects.Objects.element_class'>
<type 'object'>
FIXME: Objects.element_class is not very meaningfull ...
TESTS:
sage: TestSuite(Sets()).run()
Returns a (preferably typical) element of this parent.
This is used both for illustration and testing purposes. If the
set is empty an_element() should raise the exception
EmptySetError.
This default implementation calls _an_element_() and cache the result. Any parent should implement either an_element() or _an_element_().
EXAMPLES:
sage: CDF.an_element()
1.0*I
sage: ZZ[['t']].an_element()
t
Returns a list (or iterable) of elements of self.
This is typically used for running generic tests (see TestSuite).
This default implementation calls an_element().
EXAMPLES:
sage: S = Sets().example(); S
Set of prime numbers (basic implementation)
sage: S.an_element()
47
sage: S.some_elements()
[47]
This method should return an iterable, not an iterator.
Returns examples of objects of Sets(), as per Category.example().
EXAMPLES:
sage: Sets().example()
Set of prime numbers (basic implementation)
sage: Sets().example("inherits")
Set of prime numbers
sage: Sets().example("facade")
Set of prime numbers (facade implementation)
sage: Sets().example("wrapper")
Set of prime numbers (wrapper implementation)
We include SetsWithPartialMaps between Sets and Objects so that we can define morphisms between sets that are only partially defined (and have the Homset constructor not complain that SetsWithPartialMaps is not a supercategory of Fields, for example.
EXAMPLES:
sage: Sets().super_categories()
[Category of sets with partial maps]