Sets

exception sage.categories.sets_cat.EmptySetError

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
class sage.categories.sets_cat.Sets(s=None)

Bases: sage.categories.category_singleton.Category_singleton

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'>
<class 'sage.structure.unique_representation.CachedRepresentation'>
<type 'sage.misc.fast_methods.WithEqualityById'>
<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_reflexive() . . . pass
running ._test_elements_eq_symmetric() . . . pass
running ._test_elements_eq_transitive() . . . pass
running ._test_elements_neq() . . . 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 meaningful ...

TESTS:

sage: TestSuite(Sets()).run()
class Algebras(base_category, base_ring)

Bases: sage.categories.algebra_functor.AlgebrasCategory

EXAMPLES:

sage: C = Semigroups().Algebras(QQ)
sage: C
Category of semigroup algebras over Rational Field
sage: C.base_category()
Category of semigroups
sage: C.super_categories()
[Category of algebras with basis over Rational Field, Category of set algebras over Rational Field]

TESTS:

sage: C._short_name()
'Algebras'
sage: latex(C) # todo: improve that
\mathbf{Algebras}(\mathbf{Semigroups})
extra_super_categories()

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]
class Sets.CartesianProducts(category, *args)

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()
ElementMethods

alias of CartesianProducts.ElementMethods

ParentMethods

alias of CartesianProducts.ParentMethods

example()

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})
extra_super_categories()

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]
class Sets.ElementMethods
cartesian_product(*elements)

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?

Sets.Facades

alias of FacadeSets

class Sets.HomCategory(category, name=None)

Bases: sage.categories.category.HomCategory

Initializes this HomCategory

INPUT:
  • category – the category whose Homsets are the objects of this category.
  • name – An optional name for this category.

EXAMPLES:

We need to skip one test, since the hierarchy of hom categories isn’t consistent yet:

sage: C = sage.categories.category.HomCategory(Rings()); C
Category of hom sets in Category of rings
sage: TestSuite(C).run(skip=['_test_category_graph'])
class Sets.IsomorphicObjects(category, *args)

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]
ParentMethods

alias of IsomorphicObjects.ParentMethods

class Sets.ParentMethods
CartesianProduct

alias of CartesianProduct

algebra(base_ring, category=None)

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
an_element()

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
cartesian_product(*parents)

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
is_parent_of(element)

Returns whether self is the parent of element

INPUT:
  • element – any object

EXAMPLES:

sage: S = ZZ
sage: S.is_parent_of(1)
True
sage: S.is_parent_of(2/1)
False

This method differs from __contains__() because it does not attempt any coercion:

sage: 2/1 in S, S.is_parent_of(2/1)
(True, False)
sage: int(1) in S, S.is_parent_of(int(1))
(True, False)
some_elements()

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]
sage: S = Set([])
sage: S.some_elements()
[]

This method should return an iterable, not an iterator.

class Sets.Quotients(category, *args)

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]
ParentMethods

alias of Quotients.ParentMethods

class Sets.Realizations(category, *args)

Bases: sage.categories.realizations.RealizationsCategory

TESTS:

sage: from sage.categories.covariant_functorial_construction import CovariantConstructionCategory
sage: class FooBars(CovariantConstructionCategory):
...       _functor_category = "FooBars"
sage: Category.FooBars = lambda self: FooBars.category_of(self)
sage: C = FooBars(ModulesWithBasis(ZZ))
sage: C
Category of foo bars of modules with basis over Integer Ring
sage: C.base_category()
Category of modules with basis over Integer Ring
sage: latex(C)
\mathbf{FooBars}(\mathbf{ModulesWithBasis}_{\Bold{Z}})
sage: import __main__; __main__.FooBars = FooBars # Fake FooBars being defined in a python module
sage: TestSuite(C).run()
ParentMethods

alias of Realizations.ParentMethods

class Sets.Subobjects(category, *args)

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]
ParentMethods

alias of Subobjects.ParentMethods

class Sets.Subquotients(category, *args)

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]
ElementMethods

alias of Subquotients.ElementMethods

ParentMethods

alias of Subquotients.ParentMethods

class Sets.WithRealizations(category, *args)

Bases: sage.categories.with_realizations.WithRealizationsCategory

TESTS:

sage: from sage.categories.covariant_functorial_construction import CovariantConstructionCategory
sage: class FooBars(CovariantConstructionCategory):
...       _functor_category = "FooBars"
sage: Category.FooBars = lambda self: FooBars.category_of(self)
sage: C = FooBars(ModulesWithBasis(ZZ))
sage: C
Category of foo bars of modules with basis over Integer Ring
sage: C.base_category()
Category of modules with basis over Integer Ring
sage: latex(C)
\mathbf{FooBars}(\mathbf{ModulesWithBasis}_{\Bold{Z}})
sage: import __main__; __main__.FooBars = FooBars # Fake FooBars being defined in a python module
sage: TestSuite(C).run()
ParentMethods

alias of WithRealizations.ParentMethods

example(base_ring=None, set=None)

Returns an example of set with multiple realizations, as per Category.example().

EXAMPLES:

sage: Sets().WithRealizations().example()
The subset algebra of {1, 2, 3} over Rational Field

sage: Sets().WithRealizations().example(ZZ, Set([1,2]))
The subset algebra of {1, 2} over Integer Ring
extra_super_categories()

A set with multiple realizations is a facade parent

EXAMPLES:

sage: Sets().WithRealizations().extra_super_categories()
[Category of facade sets]
sage: Sets().WithRealizations().super_categories()
[Category of facade sets]
Sets.example(choice=None)

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)
Sets.super_categories()

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]
sage.categories.sets_cat.print_compare(x, y)

Helper method used in Sets.ParentMethods._test_elements_eq_symmetric(), Sets.ParentMethods._test_elements_eq_tranisitive().

INPUT:

  • x – an element
  • y – an element

EXAMPLES:

sage: from sage.categories.sets_cat import print_compare
sage: print_compare(1,2)
1 != 2
sage: print_compare(1,1)
1 == 1

Previous topic

Semirings

Next topic

Sets With a Grading

This Page