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([]))
...
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_eq() . . . pass
running ._test_not_implemented_methods() . . . pass
running ._test_pickling() . . . pass
pass
running ._test_elements_eq() . . . pass
running ._test_eq() . . . 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()
Bases: sage.categories.algebra_functor.AlgebrasCategory
EXAMPLES:
sage: Sets().Algebras(QQ).extra_super_categories()
[Category of modules with basis over Rational Field]
sage: Sets().Algebras(QQ).super_categories()
[Category of modules with basis over Rational Field]
sage: Sets().example().algebra(ZZ).categories()
[Category of set algebras over Integer Ring,
Category of modules with basis over Integer Ring,
...
Category of objects]
Bases: sage.categories.cartesian_product.CartesianProductsCategory
EXAMPLES:
sage: C = Sets().CartesianProducts().example()
sage: C
The cartesian product of (Set of prime numbers (basic implementation), An example of an infinite enumerated set: the non negative integers, An example of a finite enumerated set: {1,2,3})
sage: C.category()
Category of Cartesian products of sets
sage: C.categories()
[Category of Cartesian products of sets, Category of sets,
Category of sets with partial maps,
Category of objects]
sage: TestSuite(C).run()
EXAMPLES:
sage: Sets().CartesianProducts().example()
The cartesian product of (Set of prime numbers (basic implementation), An example of an infinite enumerated set: the non negative integers, An example of a finite enumerated set: {1,2,3})
A cartesian product of sets is a set
EXAMPLES:
sage: Sets().CartesianProducts().extra_super_categories()
[Category of sets]
sage: Sets().CartesianProducts().super_categories()
[Category of sets]
Returns the cartesian product of its arguments, as an element of the cartesian product of the parents of those elements.
EXAMPLES:
sage: C = AlgebrasWithBasis(QQ)
sage: A = C.example()
sage: (a,b,c) = A.algebra_generators()
sage: a.cartesian_product(b, c)
B[(0, word: a)] + B[(1, word: b)] + B[(2, word: c)]
FIXME: is this a policy that we want to enforce on all parents?
Bases: sage.categories.isomorphic_objects.IsomorphicObjectsCategory
A category for isomorphic objects of sets
EXAMPLES:
sage: Sets().IsomorphicObjects()
Category of isomorphic objects of sets
sage: Sets().IsomorphicObjects().all_super_categories()
[Category of isomorphic objects of sets,
Category of subobjects of sets, Category of quotients of sets,
Category of subquotients of sets,
Category of sets,
Category of sets with partial maps,
Category of objects]
EXAMPLES:
sage: from sage.misc.lazy_import import LazyImport
sage: my_integer = LazyImport('sage.rings.all', 'Integer')
sage: my_integer(4)
4
sage: my_integer('101', base=2)
5
sage: my_integer(3/2)
...
TypeError: no conversion of this rational to integer
Returns the algebra of self
EXAMPLES:
sage: A = Sets().example().algebra(QQ); A
Free module generated by Set of prime numbers (basic implementation) over Rational Field
sage: A.category()
Category of set algebras over Rational Field
sage: A = Monoids().example().algebra(QQ); A
Free module generated by An example of a monoid: the free monoid generated by ('a', 'b', 'c', 'd') over Rational Field
sage: A.category()
Category of monoid algebras over Rational Field
sage: A = Monoids().example().algebra(QQ, category = Sets()); A
Free module generated by An example of a monoid: the free monoid generated by ('a', 'b', 'c', 'd') over Rational Field
sage: A.category()
Category of set algebras over Rational Field
Returns a (preferably typical) element of this parent.
This is used both for illustration and testing purposes. If the set self 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 the cartesian product of the parents
EXAMPLES:
sage: C = AlgebrasWithBasis(QQ)
sage: A = C.example(); A.rename("A")
sage: A.cartesian_product(A,A)
A (+) A (+) A
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.
Bases: sage.categories.quotients.QuotientsCategory
A category for subquotients of sets
EXAMPLES:
sage: Sets().Quotients()
Category of quotients of sets
sage: Sets().Quotients().all_super_categories()
[Category of quotients of sets, Category of subquotients of sets, Category of sets,
Category of sets with partial maps, Category of objects]
Bases: sage.categories.subobjects.SubobjectsCategory
A category for subquotients of sets
EXAMPLES:
sage: Sets().Subobjects()
Category of subobjects of sets
sage: Sets().Subobjects().all_super_categories()
[Category of subobjects of sets, Category of subquotients of sets, Category of sets,
Category of sets with partial maps, Category of objects]
Bases: sage.categories.subquotients.SubquotientsCategory
A category for subquotients of sets
EXAMPLES:
sage: Sets().Subquotients()
Category of subquotients of sets
sage: Sets().Subquotients().all_super_categories()
[Category of subquotients of sets, Category of sets,
Category of sets with partial maps,
Category of objects]
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. This is also to 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]