Fast functions for the category framework#

AUTHOR:

  • Simon King (initial version)

class sage.categories.category_cy_helper.AxiomContainer#

Bases: dict

A fast container for axioms.

This is derived from dict. A key is the name of an axiom. The corresponding value is the “rank” of this axiom, that is used to order the axioms in canonicalize_axioms().

EXAMPLES:

sage: all_axioms = sage.categories.category_with_axiom.all_axioms
sage: isinstance(all_axioms, sage.categories.category_with_axiom.AxiomContainer)
True
add(axiom)#

Add a new axiom name, of the next rank.

EXAMPLES:

sage: all_axioms = sage.categories.category_with_axiom.all_axioms
sage: m = max(all_axioms.values())
sage: all_axioms.add('Awesome')
sage: all_axioms['Awesome'] == m + 1
True

To avoid side effects, we remove the added axiom:

sage: del all_axioms['Awesome']
sage.categories.category_cy_helper.canonicalize_axioms(all_axioms, axioms)#

Canonicalize a set of axioms.

INPUT:

  • all_axioms – all available axioms

  • axioms – a set (or iterable) of axioms

Note

AxiomContainer provides a fast container for axioms, and the collection of axioms is stored in sage.categories.category_with_axiom. In order to avoid circular imports, we expect that the collection of all axioms is provided as an argument to this auxiliary function.

OUTPUT:

A set of axioms as a tuple sorted according to the order of the tuple all_axioms in sage.categories.category_with_axiom.

EXAMPLES:

sage: from sage.categories.category_with_axiom import canonicalize_axioms, all_axioms
sage: canonicalize_axioms(all_axioms, ["Commutative", "Connected", "WithBasis", "Finite"])
('Finite', 'Connected', 'WithBasis', 'Commutative')
sage: canonicalize_axioms(all_axioms, ["Commutative", "Connected", "Commutative", "WithBasis", "Finite"])
('Finite', 'Connected', 'WithBasis', 'Commutative')
sage.categories.category_cy_helper.category_sort_key(category)#

Return category._cmp_key.

This helper function is used for sorting lists of categories.

It is semantically equivalent to operator.attrgetter() ("_cmp_key"), but currently faster.

EXAMPLES:

sage: from sage.categories.category_cy_helper import category_sort_key
sage: category_sort_key(Rings()) is Rings()._cmp_key
True
sage.categories.category_cy_helper.get_axiom_index(all_axioms, axiom)#

Helper function: Return the rank of an axiom.

INPUT:

  • all_axioms – the axiom collection

  • axiom – string, name of an axiom

EXAMPLES:

sage: all_axioms = sage.categories.category_with_axiom.all_axioms
sage: from sage.categories.category_cy_helper import get_axiom_index
sage: get_axiom_index(all_axioms, 'AdditiveCommutative') == all_axioms['AdditiveCommutative']
True
sage.categories.category_cy_helper.join_as_tuple(categories, axioms, ignore_axioms)#

Helper for join().

INPUT:

  • categories – tuple of categories to be joined,

  • axioms – tuple of strings; the names of some supplementary axioms.

  • ignore_axioms – tuple of pairs (cat, axiom), such that axiom will not be applied to cat, should cat occur in the algorithm.

EXAMPLES:

sage: from sage.categories.category_cy_helper import join_as_tuple
sage: T = (Coalgebras(QQ), Sets().Finite(), Algebras(ZZ), SimplicialComplexes())
sage: join_as_tuple(T,(),())
(Category of algebras over Integer Ring,
 Category of finite monoids,
 Category of finite additive groups,
 Category of coalgebras over Rational Field,
 Category of finite simplicial complexes)
sage: join_as_tuple(T,('WithBasis',),())
(Category of algebras with basis over Integer Ring,
 Category of finite monoids,
 Category of coalgebras with basis over Rational Field,
 Category of finite additive groups,
 Category of finite simplicial complexes)
sage: join_as_tuple(T,(),((Monoids(),'Finite'),))
(Category of algebras over Integer Ring,
 Category of finite additive groups,
 Category of coalgebras over Rational Field,
 Category of finite simplicial complexes)