Categories¶
AUTHORS:
- David Kohel, William Stein and Nicolas M. Thiery
Every Sage object lies in a category. Categories in Sage are modeled on the mathematical idea of category, and are distinct from Python classes, which are a programming construct.
In most cases, typing x.category()
returns the category to which x
belongs. If C
is a category and x
is any object, C(x)
tries to
make an object in C
from x
. Checking if x
belongs to C
is done
as usually by x in C
.
See Category
and sage.categories.primer
for more details.
EXAMPLES:
We create a couple of categories:
sage: Sets()
Category of sets
sage: GSets(AbelianGroup([2,4,9]))
Category of G-sets for Multiplicative Abelian group isomorphic to C2 x C4 x C9
sage: Semigroups()
Category of semigroups
sage: VectorSpaces(FiniteField(11))
Category of vector spaces over Finite Field of size 11
sage: Ideals(IntegerRing())
Category of ring ideals in Integer Ring
Let’s request the category of some objects:
sage: V = VectorSpace(RationalField(), 3)
sage: V.category()
Category of finite dimensional vector spaces with basis
over (number fields and quotient fields and metric spaces)
sage: G = SymmetricGroup(9)
sage: G.category()
Join of Category of finite enumerated permutation groups and
Category of finite weyl groups and
Category of well generated finite irreducible complex reflection groups
sage: P = PerfectMatchings(3)
sage: P.category()
Category of finite enumerated sets
Let’s check some memberships:
sage: V in VectorSpaces(QQ)
True
sage: V in VectorSpaces(FiniteField(11))
False
sage: G in Monoids()
True
sage: P in Rings()
False
For parametrized categories one can use the following shorthand:
sage: V in VectorSpaces
True
sage: G in VectorSpaces
False
A parent P
is in a category C
if P.category()
is a subcategory of
C
.
Note
Any object of a category should be an instance of
CategoryObject
.
For backward compatibility this is not yet enforced:
sage: class A:
....: def category(self):
....: return Fields()
sage: A() in Rings()
True
By default, the category of an element \(x\) of a parent \(P\) is the category of all objects of \(P\) (this is dubious an may be deprecated):
sage: V = VectorSpace(RationalField(), 3)
sage: v = V.gen(1)
sage: v.category()
Category of elements of Vector space of dimension 3 over Rational Field
-
sage.categories.category.
Category
¶ The base class for modeling mathematical categories, like for example:
Groups()
: the category of groupsEuclideanDomains()
: the category of euclidean ringsVectorSpaces(QQ)
: the category of vector spaces over the field of rationals
See
sage.categories.primer
for an introduction to categories in Sage, their relevance, purpose, and usage. The documentation below will focus on their implementation.Technically, a category is an instance of the class
Category
or some of its subclasses. Some categories, likeVectorSpaces
, are parametrized:VectorSpaces(QQ)
is one of many instances of the classVectorSpaces
. On the other hand,EuclideanDomains()
is the single instance of the classEuclideanDomains
.Recall that an algebraic structure (say, the ring \(\QQ[x]\)) is modelled in Sage by an object which is called a parent. This object belongs to certain categories (here
EuclideanDomains()
andAlgebras()
). The elements of the ring are themselves objects.The class of a category (say
EuclideanDomains
) can define simultaneously:- Operations on the category itself (what is its super categories? its category of morphisms? its dual category?).
- Generic operations on parents in this category, like the ring \(\QQ[x]\).
- Generic operations on elements of such parents (e. g., the Euclidean algorithm for computing gcds).
- Generic operations on morphisms of this category.
This is achieved as follows:
sage: from sage.categories.all import Category sage: class EuclideanDomains(Category): ....: # operations on the category itself ....: def super_categories(self): ....: [Rings()] ....: ....: def dummy(self): # TODO: find some good examples ....: pass ....: ....: class ParentMethods: # holds the generic operations on parents ....: # TODO: find a good example of an operation ....: pass ....: ....: class ElementMethods:# holds the generic operations on elements ....: def gcd(x,y): ....: # Euclid algorithms ....: pass ....: ....: class MorphismMethods: # holds the generic operations on morphisms ....: # TODO: find a good example of an operation ....: pass ....:
Note that the nested class
ParentMethods
is merely a container of operations, and does not inherit from anything. Instead, the hierarchy relation is defined once at the level of the categories, and the actual hierarchy of classes is built in parallel from all theParentMethods
nested classes, and stored in the attributesparent_class
. Then, a parent in a categoryC
receives the appropriate operations from all the super categories by usual class inheritance fromC.parent_class
.Similarly, two other hierarchies of classes, for elements and morphisms respectively, are built from all the
ElementMethods
andMorphismMethods
nested classes.EXAMPLES:
We define a hierarchy of four categories
As()
,Bs()
,Cs()
,Ds()
with a diamond inheritance. Think for example:As()
: the category of setsBs()
: the category of additive groupsCs()
: the category of multiplicative monoidsDs()
: the category of rings
sage: from sage.categories.all import Category sage: from sage.misc.lazy_attribute import lazy_attribute sage: class As (Category): ....: def super_categories(self): ....: return [] ....: ....: class ParentMethods: ....: def fA(self): ....: return "A" ....: f = fA sage: class Bs (Category): ....: def super_categories(self): ....: return [As()] ....: ....: class ParentMethods: ....: def fB(self): ....: return "B" sage: class Cs (Category): ....: def super_categories(self): ....: return [As()] ....: ....: class ParentMethods: ....: def fC(self): ....: return "C" ....: f = fC sage: class Ds (Category): ....: def super_categories(self): ....: return [Bs(),Cs()] ....: ....: class ParentMethods: ....: def fD(self): ....: return "D"
Categories should always have unique representation; by trac ticket trac ticket #12215, this means that it will be kept in cache, but only if there is still some strong reference to it.
We check this before proceeding:
sage: import gc sage: idAs = id(As()) sage: _ = gc.collect() sage: n == id(As()) False sage: a = As() sage: id(As()) == id(As()) True sage: As().parent_class == As().parent_class True
We construct a parent in the category
Ds()
(that, is an instance ofDs().parent_class
), and check that it has access to all the methods provided by all the categories, with the appropriate inheritance order:sage: D = Ds().parent_class() sage: [ D.fA(), D.fB(), D.fC(), D.fD() ] ['A', 'B', 'C', 'D'] sage: D.f() 'C'
sage: C = Cs().parent_class() sage: [ C.fA(), C.fC() ] ['A', 'C'] sage: C.f() 'C'
Here is the parallel hierarchy of classes which has been built automatically, together with the method resolution order (
.mro()
):sage: As().parent_class <class '__main__.As.parent_class'> sage: As().parent_class.__bases__ (<... 'object'>,) sage: As().parent_class.mro() [<class '__main__.As.parent_class'>, <... 'object'>]
sage: Bs().parent_class <class '__main__.Bs.parent_class'> sage: Bs().parent_class.__bases__ (<class '__main__.As.parent_class'>,) sage: Bs().parent_class.mro() [<class '__main__.Bs.parent_class'>, <class '__main__.As.parent_class'>, <... 'object'>]
sage: Cs().parent_class <class '__main__.Cs.parent_class'> sage: Cs().parent_class.__bases__ (<class '__main__.As.parent_class'>,) sage: Cs().parent_class.__mro__ (<class '__main__.Cs.parent_class'>, <class '__main__.As.parent_class'>, <... 'object'>)
sage: Ds().parent_class <class '__main__.Ds.parent_class'> sage: Ds().parent_class.__bases__ (<class '__main__.Cs.parent_class'>, <class '__main__.Bs.parent_class'>) sage: Ds().parent_class.mro() [<class '__main__.Ds.parent_class'>, <class '__main__.Cs.parent_class'>, <class '__main__.Bs.parent_class'>, <class '__main__.As.parent_class'>, <... 'object'>]
Note that that two categories in the same class need not have the same
super_categories
. For example,Algebras(QQ)
hasVectorSpaces(QQ)
as super category, whereasAlgebras(ZZ)
only hasModules(ZZ)
as super category. In particular, the constructed parent class and element class will differ (inheriting, or not, methods specific for vector spaces):sage: Algebras(QQ).parent_class is Algebras(ZZ).parent_class False sage: issubclass(Algebras(QQ).parent_class, VectorSpaces(QQ).parent_class) True
On the other hand, identical hierarchies of classes are, preferably, built only once (e.g. for categories over a base ring):
sage: Algebras(GF(5)).parent_class is Algebras(GF(7)).parent_class True sage: F = FractionField(ZZ['t']) sage: Coalgebras(F).parent_class is Coalgebras(FractionField(F['x'])).parent_class True
We now construct a parent in the usual way:
sage: class myparent(Parent): ....: def __init__(self): ....: Parent.__init__(self, category=Ds()) ....: def g(self): ....: return "myparent" ....: class Element: ....: pass sage: D = myparent() sage: D.__class__ <class '__main__.myparent_with_category'> sage: D.__class__.__bases__ (<class '__main__.myparent'>, <class '__main__.Ds.parent_class'>) sage: D.__class__.mro() [<class '__main__.myparent_with_category'>, <class '__main__.myparent'>, <type 'sage.structure.parent.Parent'>, <type 'sage.structure.category_object.CategoryObject'>, <type 'sage.structure.sage_object.SageObject'>, <class '__main__.Ds.parent_class'>, <class '__main__.Cs.parent_class'>, <class '__main__.Bs.parent_class'>, <class '__main__.As.parent_class'>, <... 'object'>] sage: D.fA() 'A' sage: D.fB() 'B' sage: D.fC() 'C' sage: D.fD() 'D' sage: D.f() 'C' sage: D.g() 'myparent'
sage: D.element_class <class '__main__.myparent_with_category.element_class'> sage: D.element_class.mro() [<class '__main__.myparent_with_category.element_class'>, <class ...__main__....Element...>, <class '__main__.Ds.element_class'>, <class '__main__.Cs.element_class'>, <class '__main__.Bs.element_class'>, <class '__main__.As.element_class'>, <... 'object'>]
-
Category.
_super_categories
()¶ The immediate super categories of this category.
This lazy attribute caches the result of the mandatory method
super_categories()
for speed. It also does some mangling (flattening join categories, sorting, …).Whenever speed matters, developers are advised to use this lazy attribute rather than calling
super_categories()
.Note
This attribute is likely to eventually become a tuple. When this happens, we might as well use
Category._sort()
, if notCategory._sort_uniq()
.EXAMPLES:
sage: Rings()._super_categories [Category of rngs, Category of semirings]
-
Category.
_super_categories_for_classes
()¶ The super categories of this category used for building classes.
This is a close variant of
_super_categories()
used for constructing the list of the bases forparent_class()
,element_class()
, and friends. The purpose is ensure that Python will find a proper Method Resolution Order for those classes. For background, seesage.misc.c3_controlled
.See also
_cmp_key()
.Note
This attribute is calculated as a by-product of computing
_all_super_categories()
.EXAMPLES:
sage: Rings()._super_categories_for_classes [Category of rngs, Category of semirings]
-
Category.
_all_super_categories
()¶ All the super categories of this category, including this category.
Since trac ticket #11943, the order of super categories is determined by Python’s method resolution order C3 algorithm.
See also
all_super_categories()
Note
this attribute is likely to eventually become a tuple.
Note
this sets
_super_categories_for_classes()
as a side effectEXAMPLES:
sage: C = Rings(); C Category of rings sage: C._all_super_categories [Category of rings, Category of rngs, Category of semirings, ... Category of monoids, ... Category of commutative additive groups, ... Category of sets, Category of sets with partial maps, Category of objects]
-
Category.
_all_super_categories_proper
()¶ All the proper super categories of this category.
Since trac ticket #11943, the order of super categories is determined by Python’s method resolution order C3 algorithm.
See also
all_super_categories()
Note
this attribute is likely to eventually become a tuple.
EXAMPLES:
sage: C = Rings(); C Category of rings sage: C._all_super_categories_proper [Category of rngs, Category of semirings, ... Category of monoids, ... Category of commutative additive groups, ... Category of sets, Category of sets with partial maps, Category of objects]
-
Category.
_set_of_super_categories
()¶ The frozen set of all proper super categories of this category.
Note
this is used for speeding up category containment tests.
See also
all_super_categories()
EXAMPLES:
sage: sorted(Groups()._set_of_super_categories, key=str) [Category of inverse unital magmas, Category of magmas, Category of monoids, Category of objects, Category of semigroups, Category of sets, Category of sets with partial maps, Category of unital magmas] sage: sorted(Groups()._set_of_super_categories, key=str) [Category of inverse unital magmas, Category of magmas, Category of monoids, Category of objects, Category of semigroups, Category of sets, Category of sets with partial maps, Category of unital magmas]
-
Category.
_make_named_class
(name, method_provider, cache=False, picklable=True)¶ Construction of the parent/element/… class of
self
.INPUT:
name
– a string; the name of the class as an attribute ofself
. E.g. “parent_class”method_provider
– a string; the name of an attribute ofself
that provides methods for the new class (in addition to those coming from the super categories). E.g. “ParentMethods”cache
– a boolean orignore_reduction
(default:False
) (passed down to dynamic_class; for internal use only)picklable
– a boolean (default:True
)
ASSUMPTION:
It is assumed that this method is only called from a lazy attribute whose name coincides with the given
name
.OUTPUT:
A dynamic class with bases given by the corresponding named classes of
self
’s super_categories, and methods taken from the classgetattr(self,method_provider)
.Note
- In this default implementation, the reduction data of
the named class makes it depend on
self
. Since the result is going to be stored in a lazy attribute ofself
anyway, we may as well disable the caching indynamic_class
(hence the default valuecache=False
). CategoryWithParameters
overrides this method so that the same parent/element/… classes can be shared between closely related categories.- The bases of the named class may also contain the named
classes of some indirect super categories, according to
_super_categories_for_classes()
. This is to guarantee that Python will build consistent method resolution orders. For background, seesage.misc.c3_controlled
.
See also
CategoryWithParameters._make_named_class()
EXAMPLES:
sage: PC = Rings()._make_named_class("parent_class", "ParentMethods"); PC <class 'sage.categories.rings.Rings.parent_class'> sage: type(PC) <class 'sage.structure.dynamic_class.DynamicMetaclass'> sage: PC.__bases__ (<class 'sage.categories.rngs.Rngs.parent_class'>, <class 'sage.categories.semirings.Semirings.parent_class'>)
Note that, by default, the result is not cached:
sage: PC is Rings()._make_named_class("parent_class", "ParentMethods") False
Indeed this method is only meant to construct lazy attributes like
parent_class
which already handle this caching:sage: Rings().parent_class <class 'sage.categories.rings.Rings.parent_class'>
Reduction for pickling also assumes the existence of this lazy attribute:
sage: PC._reduction (<built-in function getattr>, (Category of rings, 'parent_class')) sage: loads(dumps(PC)) is Rings().parent_class True
-
Category.
_repr_
()¶ Return the print representation of this category.
EXAMPLES:
sage: Sets() # indirect doctest Category of sets
-
Category.
_repr_object_names
()¶ Return the name of the objects of this category.
EXAMPLES:
sage: FiniteGroups()._repr_object_names() 'finite groups' sage: AlgebrasWithBasis(QQ)._repr_object_names() 'algebras with basis over Rational Field'
-
Category.
_test_category
(**options)¶ Run generic tests on this category
See also
EXAMPLES:
sage: Sets()._test_category()
Let us now write a couple broken categories:
sage: class MyObjects(Category): ....: pass sage: MyObjects()._test_category() Traceback (most recent call last): ... NotImplementedError: <abstract method super_categories at ...> sage: class MyObjects(Category): ....: def super_categories(self): ....: return tuple() sage: MyObjects()._test_category() Traceback (most recent call last): ... AssertionError: Category of my objects.super_categories() should return a list sage: class MyObjects(Category): ....: def super_categories(self): ....: return [] sage: MyObjects()._test_category() Traceback (most recent call last): ... AssertionError: Category of my objects is not a subcategory of Objects()
-
Category.
_with_axiom
(axiom)¶ Return the subcategory of the objects of
self
satisfying the givenaxiom
.INPUT:
axiom
– a string, the name of an axiom
EXAMPLES:
sage: Sets()._with_axiom("Finite") Category of finite sets sage: type(Magmas().Finite().Commutative()) <class 'sage.categories.category.JoinCategory_with_category'> sage: Magmas().Finite().Commutative().super_categories() [Category of commutative magmas, Category of finite sets] sage: Algebras(QQ).WithBasis().Commutative() is Algebras(QQ).Commutative().WithBasis() True
When
axiom
is not defined forself
,self
is returned:sage: Sets()._with_axiom("Associative") Category of sets
Warning
This may be changed in the future to raising an error.
-
Category.
_with_axiom_as_tuple
(axiom)¶ Return a tuple of categories whose join is
self._with_axiom()
.INPUT:
axiom
– a string, the name of an axiom
This is a lazy version of
_with_axiom()
which is used to avoid recursion loops during join calculations.Note
The order in the result is irrelevant.
EXAMPLES:
sage: Sets()._with_axiom_as_tuple('Finite') (Category of finite sets,) sage: Magmas()._with_axiom_as_tuple('Finite') (Category of magmas, Category of finite sets) sage: Rings().Division()._with_axiom_as_tuple('Finite') (Category of division rings, Category of finite monoids, Category of commutative magmas, Category of finite additive groups) sage: HopfAlgebras(QQ)._with_axiom_as_tuple('FiniteDimensional') (Category of hopf algebras over Rational Field, Category of finite dimensional modules over Rational Field)
-
Category.
_without_axioms
(named=False)¶ Return the category without the axioms that have been added to create it.
INPUT:
named
– a boolean (default:False
)
Todo
Improve this explanation.
If
named
isTrue
, then this stops at the first category that has an explicit name of its own. Seecategory_with_axiom.CategoryWithAxiom._without_axioms()
EXAMPLES:
sage: Sets()._without_axioms() Category of sets sage: Semigroups()._without_axioms() Category of magmas sage: Algebras(QQ).Commutative().WithBasis()._without_axioms() Category of magmatic algebras over Rational Field sage: Algebras(QQ).Commutative().WithBasis()._without_axioms(named=True) Category of algebras over Rational Field
-
static
Category.
_sort
(categories)¶ Return the categories after sorting them decreasingly according to their comparison key.
See also
_cmp_key()
INPUT:
categories
– a list (or iterable) of non-join categories
OUTPUT:
A sorted tuple of categories, possibly with repeats.
Note
The auxiliary function \(_flatten_categories\) used in the test below expects a second argument, which is a type such that instances of that type will be replaced by its super categories. Usually, this type is
JoinCategory
.EXAMPLES:
sage: Category._sort([Sets(), Objects(), Coalgebras(QQ), Monoids(), Sets().Finite()]) (Category of monoids, Category of coalgebras over Rational Field, Category of finite sets, Category of sets, Category of objects) sage: Category._sort([Sets().Finite(), Semigroups().Finite(), Sets().Facade(),Magmas().Commutative()]) (Category of finite semigroups, Category of commutative magmas, Category of finite sets, Category of facade sets) sage: Category._sort(Category._flatten_categories([Sets().Finite(), Algebras(QQ).WithBasis(), Semigroups().Finite(), Sets().Facade(),Algebras(QQ).Commutative(), Algebras(QQ).Graded().WithBasis()], sage.categories.category.JoinCategory)) (Category of algebras with basis over Rational Field, Category of algebras with basis over Rational Field, Category of graded algebras over Rational Field, Category of commutative algebras over Rational Field, Category of finite semigroups, Category of finite sets, Category of facade sets)
-
static
Category.
_sort_uniq
(categories)¶ Return the categories after sorting them and removing redundant categories.
Redundant categories include duplicates and categories which are super categories of other categories in the input.
INPUT:
categories
– a list (or iterable) of categories
OUTPUT: a sorted tuple of mutually incomparable categories
EXAMPLES:
sage: Category._sort_uniq([Rings(), Monoids(), Coalgebras(QQ)]) (Category of rings, Category of coalgebras over Rational Field)
Note that, in the above example,
Monoids()
does not appear in the result because it is a super category ofRings()
.
-
static
Category.
__classcall__
(*args, **options)¶ Input mangling for unique representation.
Let
C = Cs(...)
be a category. Since trac ticket #12895, the class ofC
is a dynamic subclassCs_with_category
ofCs
in order forC
to inherit code from theSubcategoryMethods
nested classes of its super categories.The purpose of this
__classcall__
method is to ensure that reconstructingC
from its class withCs_with_category(...)
actually calls properlyCs(...)
and gives backC
.See also
subcategory_class()
EXAMPLES:
sage: A = Algebras(QQ) sage: A.__class__ <class 'sage.categories.algebras.Algebras_with_category'> sage: A is Algebras(QQ) True sage: A is A.__class__(QQ) True
-
Category.
__init__
(s=None)¶ Initializes this category.
EXAMPLES:
sage: class SemiprimitiveRings(Category): ....: def super_categories(self): ....: return [Rings()] ....: ....: class ParentMethods: ....: def jacobson_radical(self): ....: return self.ideal(0) ....: sage: C = SemiprimitiveRings() sage: C Category of semiprimitive rings sage: C.__class__ <class '__main__.SemiprimitiveRings_with_category'>
Note
Specifying the name of this category by passing a string is deprecated. If the default name (built from the name of the class) is not adequate, please use
_repr_object_names()
to customize it.
-
sage.categories.category.
CategoryWithParameters
¶ A parametrized category whose parent/element classes depend only on its super categories.
Many categories in Sage are parametrized, like
C = Algebras(K)
which takes a base ring as parameter. In many cases, however, the operations provided byC
in the parent class and element class depend only on the super categories ofC
. For example, the vector space operations are provided if and only ifK
is a field, sinceVectorSpaces(K)
is a super category ofC
only in that case. In such cases, and as an optimization (see trac ticket #11935), we want to use the same parent and element class for all fields. This is the purpose of this abstract class.Currently,
JoinCategory
,Category_over_base
andBimodules
inherit from this class.EXAMPLES:
sage: C1 = Algebras(GF(5)) sage: C2 = Algebras(GF(3)) sage: C3 = Algebras(ZZ) sage: from sage.categories.category import CategoryWithParameters sage: isinstance(C1, CategoryWithParameters) True sage: C1.parent_class is C2.parent_class True sage: C1.parent_class is C3.parent_class False
-
Category.
_make_named_class
(name, method_provider, cache=False, picklable=True) Construction of the parent/element/… class of
self
.INPUT:
name
– a string; the name of the class as an attribute ofself
. E.g. “parent_class”method_provider
– a string; the name of an attribute ofself
that provides methods for the new class (in addition to those coming from the super categories). E.g. “ParentMethods”cache
– a boolean orignore_reduction
(default:False
) (passed down to dynamic_class; for internal use only)picklable
– a boolean (default:True
)
ASSUMPTION:
It is assumed that this method is only called from a lazy attribute whose name coincides with the given
name
.OUTPUT:
A dynamic class with bases given by the corresponding named classes of
self
’s super_categories, and methods taken from the classgetattr(self,method_provider)
.Note
- In this default implementation, the reduction data of
the named class makes it depend on
self
. Since the result is going to be stored in a lazy attribute ofself
anyway, we may as well disable the caching indynamic_class
(hence the default valuecache=False
). CategoryWithParameters
overrides this method so that the same parent/element/… classes can be shared between closely related categories.- The bases of the named class may also contain the named
classes of some indirect super categories, according to
_super_categories_for_classes()
. This is to guarantee that Python will build consistent method resolution orders. For background, seesage.misc.c3_controlled
.
See also
CategoryWithParameters._make_named_class()
EXAMPLES:
sage: PC = Rings()._make_named_class("parent_class", "ParentMethods"); PC <class 'sage.categories.rings.Rings.parent_class'> sage: type(PC) <class 'sage.structure.dynamic_class.DynamicMetaclass'> sage: PC.__bases__ (<class 'sage.categories.rngs.Rngs.parent_class'>, <class 'sage.categories.semirings.Semirings.parent_class'>)
Note that, by default, the result is not cached:
sage: PC is Rings()._make_named_class("parent_class", "ParentMethods") False
Indeed this method is only meant to construct lazy attributes like
parent_class
which already handle this caching:sage: Rings().parent_class <class 'sage.categories.rings.Rings.parent_class'>
Reduction for pickling also assumes the existence of this lazy attribute:
sage: PC._reduction (<built-in function getattr>, (Category of rings, 'parent_class')) sage: loads(dumps(PC)) is Rings().parent_class True
-
-
sage.categories.category.
JoinCategory
¶ A class for joins of several categories. Do not use directly; see Category.join instead.
EXAMPLES:
sage: from sage.categories.category import JoinCategory sage: J = JoinCategory((Groups(), CommutativeAdditiveMonoids())); J Join of Category of groups and Category of commutative additive monoids sage: J.super_categories() [Category of groups, Category of commutative additive monoids] sage: J.all_super_categories(proper=True) [Category of groups, ..., Category of magmas, Category of commutative additive monoids, ..., Category of additive magmas, Category of sets, Category of sets with partial maps, Category of objects]
By trac ticket #11935, join categories and categories over base rings inherit from
CategoryWithParameters
. This allows for sharing parent and element classes between similar categories. For example, since group algebras belong to a join category and since the underlying implementation is the same for all finite fields, we have:sage: G = SymmetricGroup(10) sage: A3 = G.algebra(GF(3)) sage: A5 = G.algebra(GF(5)) sage: type(A3.category()) <class 'sage.categories.category.JoinCategory_with_category'> sage: type(A3) is type(A5) True
-
Category.
_repr_object_names
() Return the name of the objects of this category.
EXAMPLES:
sage: FiniteGroups()._repr_object_names() 'finite groups' sage: AlgebrasWithBasis(QQ)._repr_object_names() 'algebras with basis over Rational Field'
-
Category.
_repr_
() Return the print representation of this category.
EXAMPLES:
sage: Sets() # indirect doctest Category of sets
-
Category.
_without_axioms
(named=False) Return the category without the axioms that have been added to create it.
INPUT:
named
– a boolean (default:False
)
Todo
Improve this explanation.
If
named
isTrue
, then this stops at the first category that has an explicit name of its own. Seecategory_with_axiom.CategoryWithAxiom._without_axioms()
EXAMPLES:
sage: Sets()._without_axioms() Category of sets sage: Semigroups()._without_axioms() Category of magmas sage: Algebras(QQ).Commutative().WithBasis()._without_axioms() Category of magmatic algebras over Rational Field sage: Algebras(QQ).Commutative().WithBasis()._without_axioms(named=True) Category of algebras over Rational Field
-
-
sage.categories.category.
category_graph
(categories=None)¶ Return the graph of the categories in Sage.
INPUT:
categories
– a list (or iterable) of categories
If
categories
is specified, then the graph contains the mentioned categories together with all their super categories. Otherwise the graph contains (an instance of) each category insage.categories.all
(e.g.Algebras(QQ)
for algebras).For readability, the names of the category are shortened.
Todo
Further remove the base ring (see also trac ticket #15801).
EXAMPLES:
sage: G = sage.categories.category.category_graph(categories = [Groups()]) sage: G.vertices() ['groups', 'inverse unital magmas', 'magmas', 'monoids', 'objects', 'semigroups', 'sets', 'sets with partial maps', 'unital magmas'] sage: G.plot() Graphics object consisting of 20 graphics primitives sage: sage.categories.category.category_graph().plot() Graphics object consisting of ... graphics primitives
-
sage.categories.category.
category_sample
()¶ Return a sample of categories.
It is constructed by looking for all concrete category classes declared in
sage.categories.all
, callingCategory.an_instance()
on those and taking all their super categories.EXAMPLES:
sage: from sage.categories.category import category_sample sage: sorted(category_sample(), key=str) [Category of G-sets for Symmetric group of order 8! as a permutation group, Category of Hecke modules over Rational Field, Category of Lie algebras over Rational Field, Category of additive magmas, ..., Category of fields, ..., Category of graded hopf algebras with basis over Rational Field, ..., Category of modular abelian varieties over Rational Field, ..., Category of simplicial complexes, ..., Category of vector spaces over Rational Field, ..., Category of weyl groups, ...
-
sage.categories.category.
is_Category
(x)¶ Returns True if x is a category.
EXAMPLES:
sage: sage.categories.category.is_Category(CommutativeAdditiveSemigroups()) True sage: sage.categories.category.is_Category(ZZ) False