Fast functions for the category framework¶
AUTHOR:
- Simon King (initial version) 
- class sage.categories.category_cy_helper.AxiomContainer[source]¶
- 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 - >>> from sage.all import * >>> all_axioms = sage.categories.category_with_axiom.all_axioms >>> isinstance(all_axioms, sage.categories.category_with_axiom.AxiomContainer) True - add(axiom)[source]¶
- 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 - >>> from sage.all import * >>> all_axioms = sage.categories.category_with_axiom.all_axioms >>> m = max(all_axioms.values()) >>> all_axioms.add('Awesome') >>> all_axioms['Awesome'] == m + Integer(1) True - To avoid side effects, we remove the added axiom: - sage: del all_axioms['Awesome'] - >>> from sage.all import * >>> del all_axioms['Awesome'] 
 
- sage.categories.category_cy_helper.canonicalize_axioms(all_axioms, axioms)[source]¶
- Canonicalize a set of axioms. - INPUT: - all_axioms– all available axioms
- axioms– set (or iterable) of axioms
 - Note - AxiomContainerprovides 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_axiomsin- 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') - >>> from sage.all import * >>> from sage.categories.category_with_axiom import canonicalize_axioms, all_axioms >>> canonicalize_axioms(all_axioms, ["Commutative", "Connected", "WithBasis", "Finite"]) ('Finite', 'Connected', 'WithBasis', 'Commutative') >>> canonicalize_axioms(all_axioms, ["Commutative", "Connected", "Commutative", "WithBasis", "Finite"]) ('Finite', 'Connected', 'WithBasis', 'Commutative') 
- sage.categories.category_cy_helper.category_sort_key(category)[source]¶
- 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 - >>> from sage.all import * >>> from sage.categories.category_cy_helper import category_sort_key >>> category_sort_key(Rings()) is Rings()._cmp_key True 
- sage.categories.category_cy_helper.get_axiom_index(all_axioms, axiom)[source]¶
- 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 - >>> from sage.all import * >>> all_axioms = sage.categories.category_with_axiom.all_axioms >>> from sage.categories.category_cy_helper import get_axiom_index >>> get_axiom_index(all_axioms, 'AdditiveCommutative') == all_axioms['AdditiveCommutative'] True 
- sage.categories.category_cy_helper.join_as_tuple(categories, axioms, ignore_axioms)[source]¶
- 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- axiomwill not be applied to- cat, should- catoccur 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) - >>> from sage.all import * >>> from sage.categories.category_cy_helper import join_as_tuple >>> T = (Coalgebras(QQ), Sets().Finite(), Algebras(ZZ), SimplicialComplexes()) >>> 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) >>> 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) >>> 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)