diff --git a/src/sage/categories/action.pyx b/src/sage/categories/action.pyx index 4637e239dce..b3244f766d4 100644 --- a/src/sage/categories/action.pyx +++ b/src/sage/categories/action.pyx @@ -333,28 +333,30 @@ cdef class InverseAction(Action): EXAMPLES:: - sage: V = QQ^3 # optional - sage.modules - sage: v = V((1, 2, 3)) # optional - sage.modules + sage: V = QQ^3 # needs sage.modules + sage: v = V((1, 2, 3)) # needs sage.modules sage: cm = get_coercion_model() - sage: a = cm.get_action(V, QQ, operator.mul) # optional - sage.modules - sage: a # optional - sage.modules + sage: # needs sage.modules + sage: a = cm.get_action(V, QQ, operator.mul) + sage: a Right scalar multiplication by Rational Field on Vector space of dimension 3 over Rational Field - sage: ~a # optional - sage.modules + sage: ~a Right inverse action by Rational Field on Vector space of dimension 3 over Rational Field - sage: (~a)(v, 1/3) # optional - sage.modules + sage: (~a)(v, 1/3) (3, 6, 9) - sage: b = cm.get_action(QQ, V, operator.mul) # optional - sage.modules - sage: b # optional - sage.modules + sage: # needs sage.modules + sage: b = cm.get_action(QQ, V, operator.mul) + sage: b Left scalar multiplication by Rational Field on Vector space of dimension 3 over Rational Field - sage: ~b # optional - sage.modules + sage: ~b Left inverse action by Rational Field on Vector space of dimension 3 over Rational Field - sage: (~b)(1/3, v) # optional - sage.modules + sage: (~b)(1/3, v) (3, 6, 9) sage: c = cm.get_action(ZZ, list, operator.mul) @@ -398,11 +400,12 @@ cdef class InverseAction(Action): Check that this action can be pickled (:trac:`29031`):: - sage: V = QQ^3 # optional - sage.modules - sage: v = V((1, 2, 3)) # optional - sage.modules - sage: cm = get_coercion_model() # optional - sage.modules - sage: a = cm.get_action(V, QQ, operator.mul) # optional - sage.modules - sage: loads(dumps(~a)) is not None # optional - sage.modules + sage: # needs sage.modules + sage: V = QQ^3 + sage: v = V((1, 2, 3)) + sage: cm = get_coercion_model() + sage: a = cm.get_action(V, QQ, operator.mul) + sage: loads(dumps(~a)) is not None True """ return (type(self), (self._action,)) @@ -432,16 +435,17 @@ cdef class PrecomposedAction(Action): We demonstrate that an example discussed on :trac:`14711` did not become a problem:: - sage: E = ModularSymbols(11).2 # optional - sage.modular - sage: s = E.modular_symbol_rep() # optional - sage.modular - sage: del E,s # optional - sage.modular - sage: import gc # optional - sage.modular - sage: _ = gc.collect() # optional - sage.modular - sage: E = ModularSymbols(11).2 # optional - sage.modular - sage: v = E.manin_symbol_rep() # optional - sage.modular - sage: c,x = v[0] # optional - sage.modular - sage: y = x.modular_symbol_rep() # optional - sage.modular - sage: coercion_model.get_action(QQ, parent(y), op=operator.mul) # optional - sage.modular + sage: # needs sage.modular + sage: E = ModularSymbols(11).2 + sage: s = E.modular_symbol_rep() + sage: del E,s + sage: import gc + sage: _ = gc.collect() + sage: E = ModularSymbols(11).2 + sage: v = E.manin_symbol_rep() + sage: c,x = v[0] + sage: y = x.modular_symbol_rep() + sage: coercion_model.get_action(QQ, parent(y), op=operator.mul) Left scalar multiplication by Rational Field on Abelian Group of all Formal Finite Sums over Rational Field with precomposition on right by Coercion map: @@ -483,12 +487,13 @@ cdef class PrecomposedAction(Action): Check that this action can be pickled (:trac:`29031`):: - sage: E = ModularSymbols(11).2 # optional - sage.modular - sage: v = E.manin_symbol_rep() # optional - sage.modular - sage: c,x = v[0] # optional - sage.modular - sage: y = x.modular_symbol_rep() # optional - sage.modular - sage: act = coercion_model.get_action(QQ, parent(y), op=operator.mul) # optional - sage.modular - sage: loads(dumps(act)) is not None # optional - sage.modular + sage: # needs sage.modular + sage: E = ModularSymbols(11).2 + sage: v = E.manin_symbol_rep() + sage: c,x = v[0] + sage: y = x.modular_symbol_rep() + sage: act = coercion_model.get_action(QQ, parent(y), op=operator.mul) + sage: loads(dumps(act)) is not None True """ return (type(self), (self._action, self.G_precomposition, self.S_precomposition)) diff --git a/src/sage/categories/additive_magmas.py b/src/sage/categories/additive_magmas.py index 3f688577aff..b39441fe84d 100644 --- a/src/sage/categories/additive_magmas.py +++ b/src/sage/categories/additive_magmas.py @@ -283,7 +283,7 @@ def addition_table(self, names='letters', elements=None): elements as lowercase ASCII letters. :: sage: R = IntegerModRing(5) - sage: R.addition_table() # optional - sage.modules + sage: R.addition_table() # needs sage.modules + a b c d e +---------- a| a b c d e @@ -298,7 +298,7 @@ def addition_table(self, names='letters', elements=None): ``digits`` will include leading zeros as padding. :: sage: R = IntegerModRing(11) - sage: P = R.addition_table(names='elements'); P # optional - sage.modules + sage: P = R.addition_table(names='elements'); P # needs sage.modules + 0 1 2 3 4 5 6 7 8 9 10 +--------------------------------- 0| 0 1 2 3 4 5 6 7 8 9 10 @@ -313,7 +313,7 @@ def addition_table(self, names='letters', elements=None): 9| 9 10 0 1 2 3 4 5 6 7 8 10| 10 0 1 2 3 4 5 6 7 8 9 - sage: T = R.addition_table(names='digits'); T # optional - sage.modules + sage: T = R.addition_table(names='digits'); T # needs sage.modules + 00 01 02 03 04 05 06 07 08 09 10 +--------------------------------- 00| 00 01 02 03 04 05 06 07 08 09 10 @@ -333,7 +333,7 @@ def addition_table(self, names='letters', elements=None): sage: S = IntegerModRing(7) sage: elts = [0, 3, 6, 2, 5, 1, 4] - sage: S.addition_table(elements=elts) # optional - sage.modules + sage: S.addition_table(elements=elts) # needs sage.modules + a b c d e f g +-------------- a| a b c d e f g @@ -354,7 +354,7 @@ def addition_table(self, names='letters', elements=None): sage: T = IntegerModRing(12) sage: elts = [0, 3, 6, 9] - sage: T.addition_table(names='elements', elements=elts) # optional - sage.modules + sage: T.addition_table(names='elements', elements=elts) # needs sage.modules + 0 3 6 9 +-------- 0| 0 3 6 9 @@ -367,16 +367,17 @@ def addition_table(self, names='letters', elements=None): :class:`~sage.matrix.operation_table.OperationTable` for more comprehensive documentation. :: + sage: # needs sage.modules sage: R = IntegerModRing(3) - sage: T = R.addition_table() # optional - sage.modules - sage: T.column_keys() # optional - sage.modules + sage: T = R.addition_table() + sage: T.column_keys() (0, 1, 2) - sage: sorted(T.translation().items()) # optional - sage.modules + sage: sorted(T.translation().items()) [('a', 0), ('b', 1), ('c', 2)] - sage: T.change_names(['x', 'y', 'z']) # optional - sage.modules - sage: sorted(T.translation().items()) # optional - sage.modules + sage: T.change_names(['x', 'y', 'z']) + sage: sorted(T.translation().items()) [('x', 0), ('y', 1), ('z', 2)] - sage: T # optional - sage.modules + sage: T + x y z +------ x| x y z @@ -473,16 +474,17 @@ def _add_(self, right): r""" EXAMPLES:: - sage: G5 = GF(5); G8 = GF(4, 'x'); GG = G5.cartesian_product(G8) # optional - sage.rings.finite_rings - sage: e = GG((G5(1), G8.primitive_element())); e # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: G5 = GF(5); G8 = GF(4, 'x'); GG = G5.cartesian_product(G8) + sage: e = GG((G5(1), G8.primitive_element())); e (1, x) - sage: e + e # optional - sage.rings.finite_rings + sage: e + e (2, 0) - sage: e = groups.misc.AdditiveCyclic(8) # optional - sage.rings.finite_rings - sage: x = e.cartesian_product(e)((e(1), e(2))) # optional - sage.rings.finite_rings - sage: x # optional - sage.rings.finite_rings + sage: e = groups.misc.AdditiveCyclic(8) # needs sage.groups + sage: x = e.cartesian_product(e)((e(1), e(2))) + sage: x (1, 2) - sage: 4 * x # optional - sage.rings.finite_rings + sage: 4 * x (4, 0) """ return self.parent()._cartesian_product_of_elements( @@ -521,8 +523,8 @@ def algebra_generators(self): sage: S = CommutativeAdditiveSemigroups().example(); S An example of a commutative semigroup: the free commutative semigroup generated by ('a', 'b', 'c', 'd') - sage: A = S.algebra(QQ) # optional - sage.modules - sage: A.algebra_generators() # optional - sage.modules + sage: A = S.algebra(QQ) # needs sage.modules + sage: A.algebra_generators() # needs sage.modules Family (B[a], B[b], B[c], B[d]) .. TODO:: @@ -547,9 +549,9 @@ def product_on_basis(self, g1, g2): sage: S = CommutativeAdditiveSemigroups().example(); S An example of a commutative semigroup: the free commutative semigroup generated by ('a', 'b', 'c', 'd') - sage: A = S.algebra(QQ) # optional - sage.modules - sage: a, b, c, d = A.algebra_generators() # optional - sage.modules - sage: a * d * b # optional - sage.modules + sage: A = S.algebra(QQ) # needs sage.modules + sage: a, b, c, d = A.algebra_generators() # needs sage.modules + sage: a * d * b # needs sage.modules B[a + b + d] .. TODO:: @@ -724,10 +726,11 @@ def is_empty(self): EXAMPLES:: - sage: A = AdditiveAbelianGroup([3, 3]) # optional - sage.groups - sage: A in AdditiveMagmas() # optional - sage.groups + sage: # needs sage.modules + sage: A = AdditiveAbelianGroup([3, 3]) + sage: A in AdditiveMagmas() True - sage: A.is_empty() # optional - sage.groups + sage: A.is_empty() False sage: B = CommutativeAdditiveMonoids().example() @@ -739,7 +742,7 @@ def is_empty(self): We check that the method ``is_empty`` is inherited from this category in both examples above:: - sage: A.is_empty.__module__ # optional - sage.groups + sage: A.is_empty.__module__ # needs sage.modules 'sage.categories.additive_magmas' sage: B.is_empty.__module__ 'sage.categories.additive_magmas' @@ -807,17 +810,17 @@ def _sub_(left, right): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a', 'b']) # optional - sage.modules - sage: a, b = F.basis() # optional - sage.modules - sage: a - b # optional - sage.modules + sage: F = CombinatorialFreeModule(QQ, ['a', 'b']) # needs sage.modules + sage: a, b = F.basis() # needs sage.modules + sage: a - b # needs sage.modules B['a'] - B['b'] TESTS: Check that :trac:`18275` is fixed:: - sage: C = GF(5).cartesian_product(GF(5)) # optional - sage.rings.finite_rings - sage: C.one() - C.one() # optional - sage.rings.finite_rings + sage: C = GF(5).cartesian_product(GF(5)) + sage: C.one() - C.one() (0, 0) """ return left + (-right) @@ -833,21 +836,22 @@ def __neg__(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a', 'b']) # optional - sage.modules - sage: a, b = F.basis() # optional - sage.modules - sage: -b # optional - sage.modules + sage: F = CombinatorialFreeModule(QQ, ['a', 'b']) # needs sage.modules + sage: a, b = F.basis() # needs sage.modules + sage: -b # needs sage.modules -B['b'] TESTS:: - sage: F = CombinatorialFreeModule(ZZ, ['a', 'b']) # optional - sage.modules - sage: a, b = F.gens() # optional - sage.modules - sage: FF = cartesian_product((F, F)) # optional - sage.modules - sage: x = cartesian_product([a, 2*a-3*b]); x # optional - sage.modules + sage: # needs sage.modules + sage: F = CombinatorialFreeModule(ZZ, ['a', 'b']) + sage: a, b = F.gens() + sage: FF = cartesian_product((F, F)) + sage: x = cartesian_product([a, 2*a-3*b]); x B[(0, 'a')] + 2*B[(1, 'a')] - 3*B[(1, 'b')] - sage: x.parent() is FF # optional - sage.modules + sage: x.parent() is FF True - sage: -x # optional - sage.modules + sage: -x -B[(0, 'a')] - 2*B[(1, 'a')] + 3*B[(1, 'b')] """ return self._neg_() @@ -917,15 +921,15 @@ def _neg_(self): EXAMPLES:: - sage: x = cartesian_product((GF(7)(2), 17)); x # optional - sage.rings.finite_rings + sage: x = cartesian_product((GF(7)(2), 17)); x (2, 17) - sage: -x # optional - sage.rings.finite_rings + sage: -x (5, -17) TESTS:: sage: C = AdditiveMagmas().AdditiveUnital().AdditiveInverse().CartesianProducts() - sage: x.parent() in C # optional - sage.rings.finite_rings + sage: x.parent() in C True """ return self.parent()._cartesian_product_of_elements( @@ -954,7 +958,7 @@ def zero(self): EXAMPLES:: - sage: GF(8, 'x').cartesian_product(GF(5)).zero() # optional - sage.rings.finite_rings + sage: GF(8, 'x').cartesian_product(GF(5)).zero() # needs sage.rings.finite_rings (0, 0) """ return self._cartesian_product_of_elements( @@ -989,15 +993,16 @@ def one_basis(self): EXAMPLES:: + sage: # needs sage.modules sage: S = CommutativeAdditiveMonoids().example(); S An example of a commutative monoid: the free commutative monoid generated by ('a', 'b', 'c', 'd') - sage: A = S.algebra(ZZ) # optional - sage.modules - sage: A.one_basis() # optional - sage.modules + sage: A = S.algebra(ZZ) + sage: A.one_basis() 0 - sage: A.one() # optional - sage.modules + sage: A.one() B[0] - sage: A(3) # optional - sage.modules + sage: A(3) 3*B[0] """ return self.basis().keys().zero() @@ -1016,17 +1021,17 @@ def zero(self): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat + sage: A = Sets().WithRealizations().example(); A # needs sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: A.zero.__module__ # optional - sage.combinat + sage: A.zero.__module__ # needs sage.modules 'sage.categories.additive_magmas' - sage: A.zero() # optional - sage.combinat + sage: A.zero() # needs sage.modules 0 TESTS:: - sage: A.zero() is A.a_realization().zero() # optional - sage.combinat + sage: A.zero() is A.a_realization().zero() # needs sage.modules True - sage: A._test_zero() # optional - sage.combinat + sage: A._test_zero() # needs sage.modules """ return self.a_realization().zero() diff --git a/src/sage/categories/additive_semigroups.py b/src/sage/categories/additive_semigroups.py index 667e27eb1e9..038221fe5be 100644 --- a/src/sage/categories/additive_semigroups.py +++ b/src/sage/categories/additive_semigroups.py @@ -152,8 +152,8 @@ def algebra_generators(self): sage: S = CommutativeAdditiveSemigroups().example(); S An example of a commutative semigroup: the free commutative semigroup generated by ('a', 'b', 'c', 'd') - sage: A = S.algebra(QQ) # optional - sage.modules - sage: A.algebra_generators() # optional - sage.modules + sage: A = S.algebra(QQ) # needs sage.modules + sage: A.algebra_generators() # needs sage.modules Family (B[a], B[b], B[c], B[d]) """ return self.basis().keys().additive_semigroup_generators().map(self.monomial) @@ -172,9 +172,9 @@ def product_on_basis(self, g1, g2): sage: S = CommutativeAdditiveSemigroups().example(); S An example of a commutative semigroup: the free commutative semigroup generated by ('a', 'b', 'c', 'd') - sage: A = S.algebra(QQ) # optional - sage.modules - sage: a, b, c, d = A.algebra_generators() # optional - sage.modules - sage: b * d * c # optional - sage.modules + sage: A = S.algebra(QQ) # needs sage.modules + sage: a, b, c, d = A.algebra_generators() # needs sage.modules + sage: b * d * c # needs sage.modules B[b + c + d] """ return self.monomial(g1 + g2) diff --git a/src/sage/categories/affine_weyl_groups.py b/src/sage/categories/affine_weyl_groups.py index 3df85b07415..4eeea88b6c3 100644 --- a/src/sage/categories/affine_weyl_groups.py +++ b/src/sage/categories/affine_weyl_groups.py @@ -34,9 +34,9 @@ class AffineWeylGroups(Category_singleton): sage: C.example() NotImplemented - sage: W = WeylGroup(["A", 4, 1]); W # optional - sage.combinat sage.groups + sage: W = WeylGroup(["A", 4, 1]); W # needs sage.combinat sage.groups Weyl Group of type ['A', 4, 1] (as a matrix group acting on the root space) - sage: W.category() # optional - sage.combinat sage.groups + sage: W.category() # needs sage.combinat sage.groups Category of irreducible affine weyl groups TESTS:: @@ -81,8 +81,8 @@ def special_node(self): EXAMPLES:: - sage: W = WeylGroup(['A', 3, 1]) # optional - sage.combinat sage.groups - sage: W.special_node() # optional - sage.combinat sage.groups + sage: W = WeylGroup(['A', 3, 1]) # needs sage.combinat sage.groups + sage: W.special_node() # needs sage.combinat sage.groups 0 """ return self.cartan_type().special_node() @@ -95,8 +95,8 @@ def affine_grassmannian_elements_of_given_length(self, k): EXAMPLES:: - sage: W = WeylGroup(['A', 3, 1]) # optional - sage.combinat sage.groups - sage: [x.reduced_word() # optional - sage.combinat sage.groups + sage: W = WeylGroup(['A', 3, 1]) # needs sage.combinat sage.groups + sage: [x.reduced_word() # needs sage.combinat sage.groups ....: for x in W.affine_grassmannian_elements_of_given_length(3)] [[2, 1, 0], [3, 1, 0], [2, 3, 0]] @@ -137,14 +137,15 @@ def is_affine_grassmannian(self): EXAMPLES:: - sage: W = WeylGroup(['A', 3, 1]) # optional - sage.combinat sage.groups - sage: w = W.from_reduced_word([2,1,0]) # optional - sage.combinat sage.groups - sage: w.is_affine_grassmannian() # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = WeylGroup(['A', 3, 1]) + sage: w = W.from_reduced_word([2,1,0]) + sage: w.is_affine_grassmannian() True - sage: w = W.from_reduced_word([2,0]) # optional - sage.combinat sage.groups - sage: w.is_affine_grassmannian() # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([2,0]) + sage: w.is_affine_grassmannian() False - sage: W.one().is_affine_grassmannian() # optional - sage.combinat sage.groups + sage: W.one().is_affine_grassmannian() True """ D = self.descents() @@ -169,17 +170,18 @@ def affine_grassmannian_to_core(self): EXAMPLES:: - sage: W = WeylGroup(['A', 2, 1]) # optional - sage.combinat sage.groups - sage: w = W.from_reduced_word([0,2,1,0]) # optional - sage.combinat sage.groups - sage: la = w.affine_grassmannian_to_core(); la # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = WeylGroup(['A', 2, 1]) + sage: w = W.from_reduced_word([0,2,1,0]) + sage: la = w.affine_grassmannian_to_core(); la [4, 2] - sage: type(la) # optional - sage.combinat sage.groups + sage: type(la) - sage: la.to_grassmannian() == w # optional - sage.combinat sage.groups + sage: la.to_grassmannian() == w True - sage: w = W.from_reduced_word([0,2,1]) # optional - sage.combinat sage.groups - sage: w.affine_grassmannian_to_core() # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([0,2,1]) # needs sage.combinat sage.groups + sage: w.affine_grassmannian_to_core() # needs sage.combinat sage.groups Traceback (most recent call last): ... ValueError: this only works on type 'A' affine Grassmannian elements @@ -214,12 +216,13 @@ def affine_grassmannian_to_partition(self): EXAMPLES:: + sage: # needs sage.combinat sage.groups sage: k = 2 - sage: W = WeylGroup(['A', k, 1]) # optional - sage.combinat sage.groups - sage: w = W.from_reduced_word([0,2,1,0]) # optional - sage.combinat sage.groups - sage: la = w.affine_grassmannian_to_partition(); la # optional - sage.combinat sage.groups + sage: W = WeylGroup(['A', k, 1]) + sage: w = W.from_reduced_word([0,2,1,0]) + sage: la = w.affine_grassmannian_to_partition(); la [2, 2] - sage: la.from_kbounded_to_grassmannian(k) == w # optional - sage.combinat sage.groups + sage: la.from_kbounded_to_grassmannian(k) == w True """ return self.affine_grassmannian_to_core().to_bounded_partition() diff --git a/src/sage/categories/algebra_functor.py b/src/sage/categories/algebra_functor.py index 9142a9b6e38..dd56f26895f 100644 --- a/src/sage/categories/algebra_functor.py +++ b/src/sage/categories/algebra_functor.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.groups +# sage.doctest: needs sage.groups r""" Group algebras and beyond: the Algebra functorial construction diff --git a/src/sage/categories/algebra_ideals.py b/src/sage/categories/algebra_ideals.py index 3bea4f66f91..1d6e3775e7b 100644 --- a/src/sage/categories/algebra_ideals.py +++ b/src/sage/categories/algebra_ideals.py @@ -81,8 +81,8 @@ def super_categories(self): sage: AlgebraIdeals(QQ['x']).super_categories() [Category of algebra modules over Univariate Polynomial Ring in x over Rational Field] - sage: C = AlgebraIdeals(FreeAlgebra(QQ, 2, 'a,b')) # optional - sage.combinat sage.modules - sage: C.super_categories() # optional - sage.combinat sage.modules + sage: C = AlgebraIdeals(FreeAlgebra(QQ, 2, 'a,b')) # needs sage.combinat sage.modules + sage: C.super_categories() # needs sage.combinat sage.modules [] """ diff --git a/src/sage/categories/algebra_modules.py b/src/sage/categories/algebra_modules.py index 086b834f955..7be7de2c471 100644 --- a/src/sage/categories/algebra_modules.py +++ b/src/sage/categories/algebra_modules.py @@ -39,7 +39,7 @@ def __init__(self, A): sage: AlgebraModules(QQ['a']) Category of algebra modules over Univariate Polynomial Ring in a over Rational Field sage: AlgebraModules(QQ['a,b']) # todo: not implemented (QQ['a,b'] should be in Algebras(QQ)) - sage: AlgebraModules(FreeAlgebra(QQ, 2, 'a,b')) # optional - sage.combinat sage.modules + sage: AlgebraModules(FreeAlgebra(QQ, 2, 'a,b')) # needs sage.combinat sage.modules Traceback (most recent call last): ... TypeError: A (=Free Algebra on 2 generators (a, b) over Rational Field) must be a commutative algebra diff --git a/src/sage/categories/algebras.py b/src/sage/categories/algebras.py index 3b808b5d1b7..6ddf749b614 100644 --- a/src/sage/categories/algebras.py +++ b/src/sage/categories/algebras.py @@ -68,9 +68,9 @@ def __contains__(self, x): sage: QQ['x'] in Algebras(QQ) True - sage: QQ^3 in Algebras(QQ) # optional - sage.modules + sage: QQ^3 in Algebras(QQ) # needs sage.modules False - sage: QQ['x'] in Algebras(CDF) + sage: QQ['x'] in Algebras(CDF) # needs sage.rings.complex_double False """ if super().__contains__(x): @@ -154,15 +154,15 @@ def _div_(self, y): EXAMPLES:: - sage: C = AlgebrasWithBasis(QQ).example() # optional - sage.combinat - sage: x = C(2); x # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: C = AlgebrasWithBasis(QQ).example() + sage: x = C(2); x 2*B[word: ] - sage: y = C.algebra_generators().first(); y # optional - sage.combinat + sage: y = C.algebra_generators().first(); y B[word: a] - - sage: y._div_(x) # optional - sage.combinat + sage: y._div_(x) 1/2*B[word: a] - sage: x._div_(y) # optional - sage.combinat + sage: x._div_(y) Traceback (most recent call last): ... ValueError: cannot invert self (= B[word: a]) @@ -182,6 +182,7 @@ def algebra_generators(self): EXAMPLES:: + sage: # needs sage.graphs sage.modules sage: A = FiniteDimensionalAlgebrasWithBasis(QQ).example(); A An example of a finite dimensional algebra with basis: the path algebra of the Kronecker quiver diff --git a/src/sage/categories/algebras_with_basis.py b/src/sage/categories/algebras_with_basis.py index e7762b50f24..62060bb0ecf 100644 --- a/src/sage/categories/algebras_with_basis.py +++ b/src/sage/categories/algebras_with_basis.py @@ -33,37 +33,37 @@ class AlgebrasWithBasis(CategoryWithAxiom_over_base_ring): We construct a typical parent in this category, and do some computations with it:: - sage: A = C.example(); A # optional - sage.combinat + sage: A = C.example(); A # needs sage.combinat sage.modules An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: A.category() # optional - sage.combinat + sage: A.category() # needs sage.combinat sage.modules Category of algebras with basis over Rational Field - sage: A.one_basis() # optional - sage.combinat + sage: A.one_basis() # needs sage.combinat sage.modules word: - sage: A.one() # optional - sage.combinat + sage: A.one() # needs sage.combinat sage.modules B[word: ] - sage: A.base_ring() # optional - sage.combinat + sage: A.base_ring() # needs sage.combinat sage.modules Rational Field - sage: A.basis().keys() # optional - sage.combinat + sage: A.basis().keys() # needs sage.combinat sage.modules Finite words over {'a', 'b', 'c'} - sage: (a,b,c) = A.algebra_generators() # optional - sage.combinat - sage: a^3, b^2 # optional - sage.combinat + sage: (a,b,c) = A.algebra_generators() # needs sage.combinat sage.modules + sage: a^3, b^2 # needs sage.combinat sage.modules (B[word: aaa], B[word: bb]) - sage: a * c * b # optional - sage.combinat + sage: a * c * b # needs sage.combinat sage.modules B[word: acb] - sage: A.product # optional - sage.combinat + sage: A.product # needs sage.combinat sage.modules - sage: A.product(a * b, b) # optional - sage.combinat + sage: A.product(a * b, b) # needs sage.combinat sage.modules B[word: abb] - sage: TestSuite(A).run(verbose=True) # optional - sage.combinat + sage: TestSuite(A).run(verbose=True) # needs sage.combinat sage.modules running ._test_additive_associativity() . . . pass running ._test_an_element() . . . pass running ._test_associativity() . . . pass @@ -93,9 +93,9 @@ class AlgebrasWithBasis(CategoryWithAxiom_over_base_ring): running ._test_prod() . . . pass running ._test_some_elements() . . . pass running ._test_zero() . . . pass - sage: A.__class__ # optional - sage.combinat + sage: A.__class__ # needs sage.combinat sage.modules - sage: A.element_class # optional - sage.combinat + sage: A.element_class # needs sage.combinat sage.modules Please see the source code of `A` (with ``A??``) for how to @@ -112,13 +112,13 @@ def example(self, alphabet=('a','b','c')): EXAMPLES:: - sage: AlgebrasWithBasis(QQ).example() # optional - sage.combinat + sage: AlgebrasWithBasis(QQ).example() # needs sage.combinat sage.modules An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field An other set of generators can be specified as optional argument:: - sage: AlgebrasWithBasis(QQ).example((1,2,3)) # optional - sage.combinat + sage: AlgebrasWithBasis(QQ).example((1,2,3)) # needs sage.combinat sage.modules An example of an algebra with basis: the free algebra on the generators (1, 2, 3) over Rational Field """ @@ -147,12 +147,12 @@ def hochschild_complex(self, M): EXAMPLES:: sage: R. = QQ[] - sage: A = algebras.DifferentialWeyl(R) # optional - sage.combinat - sage: H = A.hochschild_complex(A) # optional - sage.combinat + sage: A = algebras.DifferentialWeyl(R) # needs sage.modules + sage: H = A.hochschild_complex(A) # needs sage.modules - sage: SGA = SymmetricGroupAlgebra(QQ, 3) # optional - sage.combinat - sage: T = SGA.trivial_representation() # optional - sage.combinat - sage: H = SGA.hochschild_complex(T) # optional - sage.combinat + sage: SGA = SymmetricGroupAlgebra(QQ, 3) # needs sage.combinat sage.modules + sage: T = SGA.trivial_representation() # needs sage.combinat sage.modules + sage: H = SGA.hochschild_complex(T) # needs sage.combinat sage.modules """ from sage.homology.hochschild_complex import HochschildComplex return HochschildComplex(self, M) @@ -180,14 +180,15 @@ def __invert__(self): EXAMPLES:: - sage: C = AlgebrasWithBasis(QQ).example() # optional - sage.combinat - sage: x = C(2); x # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: C = AlgebrasWithBasis(QQ).example() + sage: x = C(2); x 2*B[word: ] - sage: ~x # optional - sage.combinat + sage: ~x 1/2*B[word: ] - sage: a = C.algebra_generators().first(); a # optional - sage.combinat + sage: a = C.algebra_generators().first(); a B[word: a] - sage: ~a # optional - sage.combinat + sage: ~a Traceback (most recent call last): ... ValueError: cannot invert self (= B[word: a]) @@ -241,19 +242,19 @@ def one_from_cartesian_product_of_one_basis(self): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example(); A # optional - sage.combinat + sage: A = AlgebrasWithBasis(QQ).example(); A # needs sage.combinat sage.modules An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: A.one_basis() # optional - sage.combinat + sage: A.one_basis() # needs sage.combinat sage.modules word: - sage: B = cartesian_product((A, A, A)) # optional - sage.combinat - sage: B.one_from_cartesian_product_of_one_basis() # optional - sage.combinat + sage: B = cartesian_product((A, A, A)) # needs sage.combinat sage.modules + sage: B.one_from_cartesian_product_of_one_basis() # needs sage.combinat sage.modules B[(0, word: )] + B[(1, word: )] + B[(2, word: )] - sage: B.one() # optional - sage.combinat + sage: B.one() # needs sage.combinat sage.modules B[(0, word: )] + B[(1, word: )] + B[(2, word: )] - sage: cartesian_product([SymmetricGroupAlgebra(QQ, 3), # optional - sage.combinat + sage: cartesian_product([SymmetricGroupAlgebra(QQ, 3), # needs sage.combinat sage.modules ....: SymmetricGroupAlgebra(QQ, 4)]).one() B[(0, [1, 2, 3])] + B[(1, [1, 2, 3, 4])] """ @@ -264,11 +265,11 @@ def one(self): """ TESTS:: - sage: A = AlgebrasWithBasis(QQ).example(); A # optional - sage.combinat + sage: A = AlgebrasWithBasis(QQ).example(); A # needs sage.combinat sage.modules An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: B = cartesian_product((A, A, A)) # optional - sage.combinat - sage: B.one() # optional - sage.combinat + sage: B = cartesian_product((A, A, A)) # needs sage.combinat sage.modules + sage: B.one() # needs sage.combinat sage.modules B[(0, word: )] + B[(1, word: )] + B[(2, word: )] """ if all(hasattr(module, "one_basis") for module in self._sets): @@ -317,15 +318,16 @@ def one_basis(self): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example(); A # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: A = AlgebrasWithBasis(QQ).example(); A An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: A.one_basis() # optional - sage.combinat + sage: A.one_basis() word: - sage: B = tensor((A, A, A)) # optional - sage.combinat - sage: B.one_basis() # optional - sage.combinat + sage: B = tensor((A, A, A)) + sage: B.one_basis() (word: , word: , word: ) - sage: B.one() # optional - sage.combinat + sage: B.one() B[word: ] # B[word: ] # B[word: ] """ # FIXME: this method should be conditionally defined, @@ -343,23 +345,23 @@ def product_on_basis(self, t1, t2): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example(); A # optional - sage.combinat + sage: A = AlgebrasWithBasis(QQ).example(); A # needs sage.combinat sage.modules An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: (a,b,c) = A.algebra_generators() # optional - sage.combinat + sage: (a,b,c) = A.algebra_generators() # needs sage.combinat sage.modules - sage: x = tensor((a, b, c)); x # optional - sage.combinat + sage: x = tensor((a, b, c)); x # needs sage.combinat sage.modules B[word: a] # B[word: b] # B[word: c] - sage: y = tensor((c, b, a)); y # optional - sage.combinat + sage: y = tensor((c, b, a)); y # needs sage.combinat sage.modules B[word: c] # B[word: b] # B[word: a] - sage: x * y # optional - sage.combinat + sage: x * y # needs sage.combinat sage.modules B[word: ac] # B[word: bb] # B[word: ca] - sage: x = tensor(((a + 2*b), c)); x # optional - sage.combinat + sage: x = tensor(((a + 2*b), c)); x # needs sage.combinat sage.modules B[word: a] # B[word: c] + 2*B[word: b] # B[word: c] - sage: y = tensor((c, a)) + 1; y # optional - sage.combinat + sage: y = tensor((c, a)) + 1; y # needs sage.combinat sage.modules B[word: ] # B[word: ] + B[word: c] # B[word: a] - sage: x * y # optional - sage.combinat + sage: x * y # needs sage.combinat sage.modules B[word: a] # B[word: c] + B[word: ac] # B[word: ca] + 2*B[word: b] # B[word: c] + 2*B[word: bc] # B[word: ca] diff --git a/src/sage/categories/bialgebras.py b/src/sage/categories/bialgebras.py index fa6a7a1a507..b927766568b 100644 --- a/src/sage/categories/bialgebras.py +++ b/src/sage/categories/bialgebras.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.combinat +# sage.doctest: needs sage.combinat r""" Bialgebras """ @@ -69,6 +69,7 @@ def is_primitive(self): EXAMPLES:: + sage: # needs sage.modules sage: s = SymmetricFunctions(QQ).schur() sage: s([5]).is_primitive() False @@ -85,10 +86,10 @@ def is_grouplike(self): EXAMPLES:: - sage: s = SymmetricFunctions(QQ).schur() - sage: s([5]).is_grouplike() + sage: s = SymmetricFunctions(QQ).schur() # needs sage.modules + sage: s([5]).is_grouplike() # needs sage.modules False - sage: s([]).is_grouplike() + sage: s([]).is_grouplike() # needs sage.modules True """ return self.coproduct() == self.tensor(self) diff --git a/src/sage/categories/bialgebras_with_basis.py b/src/sage/categories/bialgebras_with_basis.py index 067d0b35b8e..36dd5fccf2a 100644 --- a/src/sage/categories/bialgebras_with_basis.py +++ b/src/sage/categories/bialgebras_with_basis.py @@ -92,24 +92,25 @@ def convolution_product(self, *maps): with the projection ``Proj2`` on the Hopf algebra of non-commutative symmetric functions:: - sage: R = NonCommutativeSymmetricFunctions(QQ).ribbon() # optional - sage.combinat - sage: T = R.convolution_product([Id, Id]) # optional - sage.combinat - sage: [T(R(comp)) for comp in Compositions(3)] # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: R = NonCommutativeSymmetricFunctions(QQ).ribbon() + sage: T = R.convolution_product([Id, Id]) + sage: [T(R(comp)) for comp in Compositions(3)] [4*R[1, 1, 1] + R[1, 2] + R[2, 1], 2*R[1, 1, 1] + 4*R[1, 2] + 2*R[2, 1] + 2*R[3], 2*R[1, 1, 1] + 2*R[1, 2] + 4*R[2, 1] + 2*R[3], R[1, 2] + R[2, 1] + 4*R[3]] - sage: T = R.convolution_product(Proj2, Id) # optional - sage.combinat - sage: [T(R([i])) for i in range(1, 5)] # optional - sage.combinat + sage: T = R.convolution_product(Proj2, Id) + sage: [T(R([i])) for i in range(1, 5)] [0, R[2], R[2, 1] + R[3], R[2, 2] + R[4]] Compute the convolution product of no maps on the Hopf algebra of symmetric functions in non-commuting variables. This is the composition of the counit with the unit:: - sage: m = SymmetricFunctionsNonCommutingVariables(QQ).m() # optional - sage.combinat - sage: T = m.convolution_product() # optional - sage.combinat - sage: [T(m(lam)) # optional - sage.combinat + sage: m = SymmetricFunctionsNonCommutingVariables(QQ).m() # needs sage.combinat sage.modules + sage: T = m.convolution_product() # needs sage.combinat sage.modules + sage: [T(m(lam)) # needs sage.combinat sage.modules ....: for lam in SetPartitions(0).list() + SetPartitions(2).list()] [m{}, 0, 0] @@ -117,8 +118,8 @@ def convolution_product(self, *maps): the identity on the Hopf algebra of symmetric functions in non-commuting variables:: - sage: T = m.convolution_product(Proj2, Id) # optional - sage.combinat - sage: [T(m(lam)) for lam in SetPartitions(3)] # optional - sage.combinat + sage: T = m.convolution_product(Proj2, Id) # needs sage.combinat sage.modules + sage: [T(m(lam)) for lam in SetPartitions(3)] # needs sage.combinat sage.modules [0, m{{1, 2}, {3}} + m{{1, 2, 3}}, m{{1, 2}, {3}} + m{{1, 2, 3}}, @@ -128,15 +129,16 @@ def convolution_product(self, *maps): Compute the convolution product of the antipode with itself and the identity map on group algebra of the symmetric group:: - sage: G = SymmetricGroup(3) # optional - sage.groups sage.combinat - sage: QG = GroupAlgebra(G, QQ) # optional - sage.groups sage.combinat - sage: x = QG.sum_of_terms( # optional - sage.groups sage.combinat + sage: # needs sage.combinat sage.groups + sage: G = SymmetricGroup(3) + sage: QG = GroupAlgebra(G, QQ) + sage: x = QG.sum_of_terms( ....: [(p, p.number_of_peaks() + p.number_of_inversions()) ....: for p in Permutations(3)] ....: ); x 2*[1, 3, 2] + [2, 1, 3] + 3*[2, 3, 1] + 2*[3, 1, 2] + 3*[3, 2, 1] - sage: T = QG.convolution_product(Antipode, Antipode, Id) # optional - sage.groups sage.combinat - sage: T(x) # optional - sage.groups sage.combinat + sage: T = QG.convolution_product(Antipode, Antipode, Id) + sage: T(x) 2*[1, 3, 2] + [2, 1, 3] + 2*[2, 3, 1] + 3*[3, 1, 2] + 3*[3, 2, 1] """ onbasis = lambda x: self.term(x).convolution_product(*maps) @@ -172,32 +174,33 @@ def adams_operator(self, n): EXAMPLES:: - sage: h = SymmetricFunctions(QQ).h() # optional - sage.combinat - sage: h[5].adams_operator(2) # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: h = SymmetricFunctions(QQ).h() + sage: h[5].adams_operator(2) 2*h[3, 2] + 2*h[4, 1] + 2*h[5] - sage: h[5].plethysm(2*h[1]) # optional - sage.combinat + sage: h[5].plethysm(2*h[1]) 2*h[3, 2] + 2*h[4, 1] + 2*h[5] - sage: h([]).adams_operator(0) # optional - sage.combinat + sage: h([]).adams_operator(0) h[] - sage: h([]).adams_operator(1) # optional - sage.combinat + sage: h([]).adams_operator(1) h[] - sage: h[3,2].adams_operator(0) # optional - sage.combinat + sage: h[3,2].adams_operator(0) 0 - sage: h[3,2].adams_operator(1) # optional - sage.combinat + sage: h[3,2].adams_operator(1) h[3, 2] :: - sage: S = NonCommutativeSymmetricFunctions(QQ).S() # optional - sage.combinat - sage: S[4].adams_operator(5) # optional - sage.combinat + sage: S = NonCommutativeSymmetricFunctions(QQ).S() # needs sage.combinat sage.modules + sage: S[4].adams_operator(5) # needs sage.combinat sage.modules 5*S[1, 1, 1, 1] + 10*S[1, 1, 2] + 10*S[1, 2, 1] + 10*S[1, 3] + 10*S[2, 1, 1] + 10*S[2, 2] + 10*S[3, 1] + 5*S[4] :: - sage: m = SymmetricFunctionsNonCommutingVariables(QQ).m() # optional - sage.combinat - sage: m[[1,3],[2]].adams_operator(-2) # optional - sage.combinat + sage: m = SymmetricFunctionsNonCommutingVariables(QQ).m() # needs sage.combinat sage.modules + sage: m[[1,3],[2]].adams_operator(-2) # needs sage.combinat sage.modules 3*m{{1}, {2, 3}} + 3*m{{1, 2}, {3}} + 6*m{{1, 2, 3}} - 2*m{{1, 3}, {2}} """ if n < 0: @@ -259,18 +262,18 @@ def convolution_product(self, *maps): sage: Id = lambda x: x sage: Antipode = lambda x: x.antipode() - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat - sage: s[3].convolution_product(Id, Id) # optional - sage.combinat + sage: s = SymmetricFunctions(QQ).schur() # needs sage.combinat sage.modules + sage: s[3].convolution_product(Id, Id) # needs sage.combinat sage.modules 2*s[2, 1] + 4*s[3] - sage: s[3,2].convolution_product(Id) == s[3,2] # optional - sage.combinat + sage: s[3,2].convolution_product(Id) == s[3,2] # needs sage.combinat sage.modules True The method accepts multiple arguments, or a single argument consisting of a list of maps:: - sage: s[3,2].convolution_product(Id, Id) # optional - sage.combinat + sage: s[3,2].convolution_product(Id, Id) # needs sage.combinat sage.modules 2*s[2, 1, 1, 1] + 6*s[2, 2, 1] + 6*s[3, 1, 1] + 12*s[3, 2] + 6*s[4, 1] + 2*s[5] - sage: s[3,2].convolution_product([Id, Id]) # optional - sage.combinat + sage: s[3,2].convolution_product([Id, Id]) # needs sage.combinat sage.modules 2*s[2, 1, 1, 1] + 6*s[2, 2, 1] + 6*s[3, 1, 1] + 12*s[3, 2] + 6*s[4, 1] + 2*s[5] We test the defining property of the antipode morphism; namely, @@ -278,31 +281,32 @@ def convolution_product(self, *maps): convolution algebra whose identity element is the composition of the counit and unit:: - sage: (s[3,2].convolution_product() # optional - sage.combinat + sage: (s[3,2].convolution_product() # needs sage.combinat sage.modules ....: == s[3,2].convolution_product(Antipode, Id) ....: == s[3,2].convolution_product(Id, Antipode)) True :: - sage: Psi = NonCommutativeSymmetricFunctions(QQ).Psi() # optional - sage.combinat - sage: Psi[2,1].convolution_product(Id, Id, Id) # optional - sage.combinat + sage: Psi = NonCommutativeSymmetricFunctions(QQ).Psi() # needs sage.combinat sage.modules + sage: Psi[2,1].convolution_product(Id, Id, Id) # needs sage.combinat sage.modules 3*Psi[1, 2] + 6*Psi[2, 1] - sage: (Psi[5,1] - Psi[1,5]).convolution_product(Id, Id, Id) # optional - sage.combinat + sage: (Psi[5,1] - Psi[1,5]).convolution_product(Id, Id, Id) # needs sage.combinat sage.modules -3*Psi[1, 5] + 3*Psi[5, 1] :: - sage: G = SymmetricGroup(3) # optional - sage.combinat - sage: QG = GroupAlgebra(G, QQ) # optional - sage.combinat - sage: x = QG.sum_of_terms([(p, p.length()) # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: G = SymmetricGroup(3) + sage: QG = GroupAlgebra(G, QQ) + sage: x = QG.sum_of_terms([(p, p.length()) ....: for p in Permutations(3)]); x [1, 3, 2] + [2, 1, 3] + 2*[2, 3, 1] + 2*[3, 1, 2] + 3*[3, 2, 1] - sage: x.convolution_product(Id, Id) # optional - sage.combinat + sage: x.convolution_product(Id, Id) 5*[1, 2, 3] + 2*[2, 3, 1] + 2*[3, 1, 2] - sage: x.convolution_product(Id, Id, Id) # optional - sage.combinat + sage: x.convolution_product(Id, Id, Id) 4*[1, 2, 3] + [1, 3, 2] + [2, 1, 3] + 3*[3, 2, 1] - sage: x.convolution_product([Id] * 6) # optional - sage.combinat + sage: x.convolution_product([Id] * 6) 9*[1, 2, 3] TESTS:: @@ -312,59 +316,63 @@ def convolution_product(self, *maps): :: - sage: h = SymmetricFunctions(QQ).h() # optional - sage.combinat - sage: h[5].convolution_product([Id, Id]) # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: h = SymmetricFunctions(QQ).h() + sage: h[5].convolution_product([Id, Id]) 2*h[3, 2] + 2*h[4, 1] + 2*h[5] - sage: h.one().convolution_product([Id, Antipode]) # optional - sage.combinat + sage: h.one().convolution_product([Id, Antipode]) h[] - sage: h[3,2].convolution_product([Id, Antipode]) # optional - sage.combinat + sage: h[3,2].convolution_product([Id, Antipode]) 0 - sage: (h.one().convolution_product([Id, Antipode]) # optional - sage.combinat + sage: (h.one().convolution_product([Id, Antipode]) ....: == h.one().convolution_product()) True :: - sage: S = NonCommutativeSymmetricFunctions(QQ).S() # optional - sage.combinat - sage: S[4].convolution_product([Id] * 5) # optional - sage.combinat + sage: S = NonCommutativeSymmetricFunctions(QQ).S() # needs sage.combinat sage.modules + sage: S[4].convolution_product([Id] * 5) # needs sage.combinat sage.modules 5*S[1, 1, 1, 1] + 10*S[1, 1, 2] + 10*S[1, 2, 1] + 10*S[1, 3] + 10*S[2, 1, 1] + 10*S[2, 2] + 10*S[3, 1] + 5*S[4] :: - sage: m = SymmetricFunctionsNonCommutingVariables(QQ).m() # optional - sage.combinat - sage: m[[1,3],[2]].convolution_product([Antipode, Antipode]) # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: m = SymmetricFunctionsNonCommutingVariables(QQ).m() + sage: m[[1,3],[2]].convolution_product([Antipode, Antipode]) 3*m{{1}, {2, 3}} + 3*m{{1, 2}, {3}} + 6*m{{1, 2, 3}} - 2*m{{1, 3}, {2}} - sage: m[[]].convolution_product([]) # optional - sage.combinat + sage: m[[]].convolution_product([]) m{} - sage: m[[1,3],[2]].convolution_product([]) # optional - sage.combinat + sage: m[[1,3],[2]].convolution_product([]) 0 :: - sage: QS = SymmetricGroupAlgebra(QQ, 5) # optional - sage.combinat - sage: x = QS.sum_of_terms(zip(Permutations(5)[3:6], [1,2,3])); x # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: QS = SymmetricGroupAlgebra(QQ, 5) + sage: x = QS.sum_of_terms(zip(Permutations(5)[3:6], [1,2,3])); x [1, 2, 4, 5, 3] + 2*[1, 2, 5, 3, 4] + 3*[1, 2, 5, 4, 3] - sage: x.convolution_product([Antipode, Id]) # optional - sage.combinat + sage: x.convolution_product([Antipode, Id]) 6*[1, 2, 3, 4, 5] - sage: x.convolution_product(Id, Antipode, Antipode, Antipode) # optional - sage.combinat + sage: x.convolution_product(Id, Antipode, Antipode, Antipode) 3*[1, 2, 3, 4, 5] + [1, 2, 4, 5, 3] + 2*[1, 2, 5, 3, 4] :: - sage: G = SymmetricGroup(3) # optional - sage.combinat - sage: QG = GroupAlgebra(G, QQ) # optional - sage.combinat - sage: x = QG.sum_of_terms([(p, p.length()) # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: G = SymmetricGroup(3) + sage: QG = GroupAlgebra(G, QQ) + sage: x = QG.sum_of_terms([(p, p.length()) ....: for p in Permutations(3)]); x [1, 3, 2] + [2, 1, 3] + 2*[2, 3, 1] + 2*[3, 1, 2] + 3*[3, 2, 1] - sage: x.convolution_product(Antipode, Id) # optional - sage.combinat + sage: x.convolution_product(Antipode, Id) 9*[1, 2, 3] - sage: x.convolution_product([Id, Antipode, Antipode, Antipode]) # optional - sage.combinat + sage: x.convolution_product([Id, Antipode, Antipode, Antipode]) 5*[1, 2, 3] + 2*[2, 3, 1] + 2*[3, 1, 2] :: - sage: (s[3,2].counit().parent() # optional - sage.combinat + sage: (s[3,2].counit().parent() # needs sage.combinat sage.modules ....: == s[3,2].convolution_product().parent()) False """ diff --git a/src/sage/categories/bimodules.py b/src/sage/categories/bimodules.py index d85af83880d..3ccc82c7f21 100644 --- a/src/sage/categories/bimodules.py +++ b/src/sage/categories/bimodules.py @@ -103,7 +103,7 @@ def an_instance(cls): EXAMPLES:: - sage: Bimodules.an_instance() + sage: Bimodules.an_instance() # needs sage.rings.real_mpfr Category of bimodules over Rational Field on the left and Real Field with 53 bits of precision on the right """ from sage.rings.rational_field import QQ diff --git a/src/sage/categories/category.py b/src/sage/categories/category.py index 83e88ef748a..242fc1e5683 100644 --- a/src/sage/categories/category.py +++ b/src/sage/categories/category.py @@ -22,49 +22,49 @@ sage: Sets() Category of sets - sage: GSets(AbelianGroup([2, 4, 9])) # optional - sage.groups + sage: GSets(AbelianGroup([2, 4, 9])) # needs sage.groups Category of G-sets for Multiplicative Abelian group isomorphic to C2 x C4 x C9 sage: Semigroups() Category of semigroups - sage: VectorSpaces(FiniteField(11)) # optional - sage.rings.finite_rings + 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) # optional - sage.modules - sage: V.category() # optional - sage.modules + sage: V = VectorSpace(RationalField(), 3) # needs sage.modules + sage: V.category() # needs sage.modules Category of finite dimensional vector spaces with basis over (number fields and quotient fields and metric spaces) - sage: G = SymmetricGroup(9) # optional - sage.groups - sage: G.category() # optional - sage.groups + sage: G = SymmetricGroup(9) # needs sage.groups + sage: G.category() # needs sage.groups 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) # optional - sage.combinat sage.graphs - sage: P.category() # optional - sage.combinat sage.graphs + sage: P = PerfectMatchings(3) # needs sage.combinat + sage: P.category() # needs sage.combinat Category of finite enumerated sets Let's check some memberships:: - sage: V in VectorSpaces(QQ) # optional - sage.modules + sage: V in VectorSpaces(QQ) # needs sage.modules True - sage: V in VectorSpaces(FiniteField(11)) # optional - sage.modules sage.rings.finite_rings + sage: V in VectorSpaces(FiniteField(11)) # needs sage.modules False - sage: G in Monoids() # optional - sage.groups + sage: G in Monoids() # needs sage.groups True - sage: P in Rings() # optional - sage.combinat sage.graphs + sage: P in Rings() # needs sage.combinat False For parametrized categories one can use the following shorthand:: - sage: V in VectorSpaces # optional - sage.modules + sage: V in VectorSpaces # needs sage.modules True - sage: G in VectorSpaces # optional - sage.groups + sage: G in VectorSpaces # needs sage.groups False A parent ``P`` is in a category ``C`` if ``P.category()`` is a subcategory of @@ -86,9 +86,9 @@ By default, the category of an element `x` of a parent `P` is the category of all objects of `P` (this is dubious and may be deprecated):: - sage: V = VectorSpace(RationalField(), 3) # optional - sage.modules - sage: v = V.gen(1) # optional - sage.modules - sage: v.category() # optional - sage.modules + sage: V = VectorSpace(RationalField(), 3) # needs sage.modules + sage: v = V.gen(1) # needs sage.modules + sage: v.category() # needs sage.modules Category of elements of Vector space of dimension 3 over Rational Field """ @@ -327,7 +327,7 @@ class inheritance from ``C.parent_class``. 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 # optional - sage.rings.finite_rings + 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 @@ -566,7 +566,7 @@ def an_instance(cls): sage: Algebras.an_instance() Category of algebras over Rational Field - sage: Bimodules.an_instance() + sage: Bimodules.an_instance() # needs sage.rings.real_mpfr Category of bimodules over Rational Field on the left and Real Field with 53 bits of precision on the right sage: AlgebraIdeals.an_instance() @@ -728,15 +728,15 @@ def __classcontains__(cls, x): This method makes it easy to test if an object is, say, a vector space, without having to specify the base ring:: - sage: F = FreeModule(QQ, 3) # optional - sage.modules - sage: F in VectorSpaces # optional - sage.modules + sage: F = FreeModule(QQ, 3) # needs sage.modules + sage: F in VectorSpaces # needs sage.modules True - sage: F = FreeModule(ZZ, 3) # optional - sage.modules - sage: F in VectorSpaces # optional - sage.modules + sage: F = FreeModule(ZZ, 3) # needs sage.modules + sage: F in VectorSpaces # needs sage.modules False - sage: F in Algebras # optional - sage.modules + sage: F in Algebras # needs sage.modules False TESTS: @@ -802,14 +802,14 @@ def category_graph(self): EXAMPLES:: sage: C = Algebras(QQ) - sage: G = C.category_graph() # optional - sage.graphs - sage: G.is_directed_acyclic() # optional - sage.graphs + sage: G = C.category_graph() # needs sage.graphs + sage: G.is_directed_acyclic() # needs sage.graphs True The girth of a directed acyclic graph is infinite, however, the girth of the underlying undirected graph is 4 in this case:: - sage: Graph(G).girth() # optional - sage.graphs + sage: Graph(G).girth() # needs sage.graphs 4 """ return category_graph([self]) @@ -932,8 +932,8 @@ def _set_of_super_categories(self): TESTS:: - sage: C = HopfAlgebrasWithBasis(GF(7)) # optional - sage.rings.finite_rings - sage: C._set_of_super_categories == set(C._all_super_categories_proper) # optional - sage.rings.finite_rings + sage: C = HopfAlgebrasWithBasis(GF(7)) + sage: C._set_of_super_categories == set(C._all_super_categories_proper) True """ return frozenset(self._all_super_categories_proper) @@ -1673,7 +1673,7 @@ def parent_class(self): the category of algebras over a finite field versus algebras over a non-field:: - sage: Algebras(GF(7)).parent_class is Algebras(GF(5)).parent_class # optional - sage.rings.finite_rings + sage: Algebras(GF(7)).parent_class is Algebras(GF(5)).parent_class True sage: Algebras(QQ).parent_class is Algebras(ZZ).parent_class False @@ -1718,7 +1718,7 @@ def element_class(self): category of algebras over a field versus algebras over a non-field:: - sage: Algebras(GF(5)).element_class is Algebras(GF(3)).element_class # optional - sage.rings.finite_rings + sage: Algebras(GF(5)).element_class is Algebras(GF(3)).element_class True sage: Algebras(QQ).element_class is Algebras(ZZ).element_class False @@ -1792,9 +1792,9 @@ def is_subcategory(self, c): :: - sage: M3 = VectorSpaces(FiniteField(3)) # optional - sage.rings.finite_rings sage.modules - sage: M9 = VectorSpaces(FiniteField(9, 'a')) # optional - sage.rings.finite_rings sage.modules - sage: M3.is_subcategory(M9) # optional - sage.rings.finite_rings sage.modules + sage: M3 = VectorSpaces(FiniteField(3)) + sage: M9 = VectorSpaces(FiniteField(9, 'a')) # needs sage.rings.finite_rings + sage: M3.is_subcategory(M9) # needs sage.rings.finite_rings False Join categories are properly handled:: @@ -1805,16 +1805,16 @@ def is_subcategory(self, c): :: - sage: V3 = VectorSpaces(FiniteField(3)) # optional - sage.rings.finite_rings + sage: V3 = VectorSpaces(FiniteField(3)) sage: POSet = PartiallyOrderedSets() - sage: PoV3 = Category.join((V3, POSet)) # optional - sage.rings.finite_rings - sage: A3 = AlgebrasWithBasis(FiniteField(3)) # optional - sage.rings.finite_rings - sage: PoA3 = Category.join((A3, POSet)) # optional - sage.rings.finite_rings - sage: PoA3.is_subcategory(PoV3) # optional - sage.rings.finite_rings + sage: PoV3 = Category.join((V3, POSet)) + sage: A3 = AlgebrasWithBasis(FiniteField(3)) + sage: PoA3 = Category.join((A3, POSet)) + sage: PoA3.is_subcategory(PoV3) True - sage: PoV3.is_subcategory(PoV3) # optional - sage.rings.finite_rings + sage: PoV3.is_subcategory(PoV3) True - sage: PoV3.is_subcategory(PoA3) # optional - sage.rings.finite_rings + sage: PoV3.is_subcategory(PoA3) False """ if c is self: @@ -2605,7 +2605,7 @@ def category_sample(): EXAMPLES:: sage: from sage.categories.category import category_sample - sage: sorted(category_sample(), key=str) # optional - sage.groups + sage: sorted(category_sample(), key=str) # needs sage.groups [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, @@ -2644,14 +2644,14 @@ def category_graph(categories=None): EXAMPLES:: - sage: G = sage.categories.category.category_graph(categories=[Groups()]) # optional - sage.graphs - sage: G.vertices(sort=True) # optional - sage.graphs + sage: G = sage.categories.category.category_graph(categories=[Groups()]) # needs sage.graphs + sage: G.vertices(sort=True) # needs sage.graphs ['groups', 'inverse unital magmas', 'magmas', 'monoids', 'objects', 'semigroups', 'sets', 'sets with partial maps', 'unital magmas'] - sage: G.plot() # optional - sage.graphs sage.plot + sage: G.plot() # needs sage.graphs sage.plot Graphics object consisting of 20 graphics primitives - sage: sage.categories.category.category_graph().plot() # optional - sage.graphs sage.plot + sage: sage.categories.category.category_graph().plot() # needs sage.graphs sage.plot Graphics object consisting of ... graphics primitives """ from sage import graphs @@ -2699,15 +2699,15 @@ class CategoryWithParameters(Category): EXAMPLES:: - sage: C1 = Algebras(GF(5)) # optional - sage.rings.finite_rings - sage: C2 = Algebras(GF(3)) # optional - sage.rings.finite_rings + 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) # optional - sage.rings.finite_rings + sage: isinstance(C1, CategoryWithParameters) True - sage: C1.parent_class is C2.parent_class # optional - sage.rings.finite_rings + sage: C1.parent_class is C2.parent_class True - sage: C1.parent_class is C3.parent_class # optional - sage.rings.finite_rings + sage: C1.parent_class is C3.parent_class False .. automethod:: Category._make_named_class @@ -2754,7 +2754,7 @@ def _make_named_class(self, name, method_provider, cache=False, **options): sage: Bimodules(ZZ,RR).parent_class is Bimodules(ZZ,RDF).parent_class # indirect doctest True - sage: Bimodules(CC,ZZ).element_class is Bimodules(RR,ZZ).element_class + sage: Bimodules(CC,ZZ).element_class is Bimodules(RR,ZZ).element_class # needs sage.rings.real_mpfr True On the other hand, modules over a field have more methods than @@ -2768,7 +2768,7 @@ def _make_named_class(self, name, method_provider, cache=False, **options): For a more subtle example, one could possibly share the classes for ``GF(3)`` and ``GF(2^3, 'x')``, but this is not currently the case:: - sage: Modules(GF(3)).parent_class is Modules(GF(2^3,'x')).parent_class + sage: Modules(GF(3)).parent_class is Modules(GF(2^3,'x')).parent_class # needs sage.rings.finite_rings False This is because those two fields do not have the exact same category:: @@ -2777,7 +2777,7 @@ def _make_named_class(self, name, method_provider, cache=False, **options): Join of Category of finite enumerated fields and Category of subquotients of monoids and Category of quotients of semigroups - sage: GF(2^3,'x').category() + sage: GF(2^3,'x').category() # needs sage.rings.finite_rings Category of finite enumerated fields Similarly for ``QQ`` and ``RR``:: @@ -2787,15 +2787,17 @@ def _make_named_class(self, name, method_provider, cache=False, **options): and Category of quotient fields and Category of metric spaces sage: RR.category() - Join of Category of fields and Category of infinite sets and Category of complete metric spaces + Join of Category of fields and Category of infinite sets + and Category of complete metric spaces sage: Modules(QQ).parent_class is Modules(RR).parent_class False Some other cases where one could potentially share those classes:: - sage: Modules(GF(3),dispatch=False).parent_class is Modules(ZZ).parent_class + sage: MF = Modules(GF(3), dispatch=False) + sage: MF.parent_class is Modules(ZZ).parent_class False - sage: Modules(GF(3),dispatch=False).element_class is Modules(ZZ).element_class + sage: MF.element_class is Modules(ZZ).element_class False TESTS:: @@ -2926,12 +2928,13 @@ class JoinCategory(CategoryWithParameters): the underlying implementation is the same for all finite fields, we have:: - sage: G = SymmetricGroup(10) # optional - sage.groups sage.rings.finite_rings - sage: A3 = G.algebra(GF(3)) # optional - sage.groups sage.rings.finite_rings - sage: A5 = G.algebra(GF(5)) # optional - sage.groups sage.rings.finite_rings - sage: type(A3.category()) # optional - sage.groups sage.rings.finite_rings + sage: # needs sage.groups sage.rings.finite_rings + sage: G = SymmetricGroup(10) + sage: A3 = G.algebra(GF(3)) + sage: A5 = G.algebra(GF(5)) + sage: type(A3.category()) - sage: type(A3) is type(A5) # optional - sage.groups sage.rings.finite_rings + sage: type(A3) is type(A5) True .. automethod:: Category._repr_object_names diff --git a/src/sage/categories/category_types.py b/src/sage/categories/category_types.py index ef0fb9472bb..a1adcc3c6c9 100644 --- a/src/sage/categories/category_types.py +++ b/src/sage/categories/category_types.py @@ -72,14 +72,15 @@ def _call_(self, x): """ EXAMPLES:: - sage: V = VectorSpace(QQ, 3) # optional - sage.modules - sage: x = V.0 # optional - sage.modules - sage: C = x.category() # optional - sage.modules - sage: C # optional - sage.modules + sage: # needs sage.modules + sage: V = VectorSpace(QQ, 3) + sage: x = V.0 + sage: C = x.category() + sage: C Category of elements of Vector space of dimension 3 over Rational Field - sage: w = C([1, 2, 3]); w # indirect doctest # optional - sage.modules + sage: w = C([1, 2, 3]); w # indirect doctest (1, 2, 3) - sage: w.category() # optional - sage.modules + sage: w.category() Category of elements of Vector space of dimension 3 over Rational Field """ return self.__object(x) @@ -129,9 +130,9 @@ def _latex_(self): r""" EXAMPLES:: - sage: V = VectorSpace(QQ, 3) # optional - sage.modules - sage: x = V.0 # optional - sage.modules - sage: latex(x.category()) # indirect doctest # optional - sage.modules + sage: V = VectorSpace(QQ, 3) # needs sage.modules + sage: x = V.0 # needs sage.modules + sage: latex(x.category()) # indirect doctest # needs sage.modules \mathbf{Elt}_{\Bold{Q}^{3}} """ return "\\mathbf{Elt}_{%s}"%latex(self.__object) @@ -153,11 +154,11 @@ class Category_over_base(CategoryWithParameters): EXAMPLES:: - sage: Algebras(GF(2)).element_class is Algebras(GF(3)).element_class # optional - sage.rings.finite_rings + sage: Algebras(GF(2)).element_class is Algebras(GF(3)).element_class True - sage: C = GF(2).category() # optional - sage.rings.finite_rings - sage: Algebras(GF(2)).parent_class is Algebras(C).parent_class # optional - sage.rings.finite_rings + sage: C = GF(2).category() + sage: Algebras(GF(2)).parent_class is Algebras(C).parent_class True sage: C = ZZ.category() @@ -278,7 +279,7 @@ def _repr_object_names(self): 'algebras over Rational Field' sage: Algebras(Fields())._repr_object_names() 'algebras over fields' - sage: Algebras(GF(2).category())._repr_object_names() # optional - sage.rings.finite_rings + sage: Algebras(GF(2).category())._repr_object_names() 'algebras over (finite enumerated fields and subquotients of monoids and quotients of semigroups)' """ base = self.__base @@ -338,9 +339,9 @@ def __init__(self, base, name=None): EXAMPLES:: - sage: C = Algebras(GF(2)); C # optional - sage.rings.finite_rings + sage: C = Algebras(GF(2)); C Category of algebras over Finite Field of size 2 - sage: TestSuite(C).run() # optional - sage.rings.finite_rings + sage: TestSuite(C).run() """ from sage.categories.rings import Rings if not (base in Rings() or @@ -355,8 +356,8 @@ def base_ring(self): EXAMPLES:: - sage: C = Algebras(GF(2)) # optional - sage.rings.finite_rings - sage: C.base_ring() # optional - sage.rings.finite_rings + sage: C = Algebras(GF(2)) + sage: C.base_ring() Finite Field of size 2 """ return self.base() @@ -399,11 +400,13 @@ def _subcategory_hook_(self, C): sage: VectorSpaces(QQ)._subcategory_hook_(VectorSpaces(QQ) & Rings()) Unknown - sage: Sym = SymmetricFunctions(QQ) # optional - sage.combinat - sage: from sage.combinat.sf.sfa import SymmetricFunctionsBases # optional - sage.combinat - sage: Modules(QQ)._subcategory_hook_(SymmetricFunctionsBases(Sym)) # optional - sage.combinat + + sage: # needs sage.combinat sage.modules + sage: Sym = SymmetricFunctions(QQ) + sage: from sage.combinat.sf.sfa import SymmetricFunctionsBases + sage: Modules(QQ)._subcategory_hook_(SymmetricFunctionsBases(Sym)) Unknown - sage: SymmetricFunctionsBases(Sym).is_subcategory(Modules(QQ)) # optional - sage.combinat + sage: SymmetricFunctionsBases(Sym).is_subcategory(Modules(QQ)) True Case 1: the two bases are categories; then the base of ``C`` @@ -428,18 +431,18 @@ def _subcategory_hook_(self, C): sage: VectorSpaces(QQ)._subcategory_hook_(Algebras(QQ)) True - sage: VectorSpaces(CC)._subcategory_hook_(Algebras(QQ)) # base ring in different categories + sage: VectorSpaces(CC)._subcategory_hook_(Algebras(QQ)) # base ring in different categories # needs sage.rings.real_mpfr False - sage: VectorSpaces(GF(2))._subcategory_hook_(Algebras(GF(3))) # base ring in the same category # optional - sage.rings.finite_rings + sage: VectorSpaces(GF(2))._subcategory_hook_(Algebras(GF(3))) # base ring in the same category False Note; we need both previous tests since the distinction is made respectively using the parent class or the base ring:: - sage: issubclass(Algebras(QQ).parent_class, # optional - sage.modules + sage: issubclass(Algebras(QQ).parent_class, # needs sage.modules ....: VectorSpaces(CC).parent_class) False - sage: issubclass(Algebras(GF(2)).parent_class, # optional - sage.modules sage.rings.finite_rings + sage: issubclass(Algebras(GF(2)).parent_class, ....: VectorSpaces(GF(3)).parent_class) True @@ -447,6 +450,7 @@ def _subcategory_hook_(self, C): method is only valid for :class:`Category_over_base_ring`, not :class:`Category_over_base`:: + sage: # needs sage.groups sage: from sage.categories.category_types import Category_over_base sage: D = Modules(Rings()) sage: class Cs(Category_over_base): diff --git a/src/sage/categories/category_with_axiom.py b/src/sage/categories/category_with_axiom.py index 2128dac2db9..c14d468246e 100644 --- a/src/sage/categories/category_with_axiom.py +++ b/src/sage/categories/category_with_axiom.py @@ -2462,9 +2462,9 @@ def axioms(self): sage: C.axioms() frozenset({'Finite'}) - sage: C = Modules(GF(5)).FiniteDimensional(); C # optional - sage.rings.finite_rings + sage: C = Modules(GF(5)).FiniteDimensional(); C Category of finite dimensional vector spaces over Finite Field of size 5 - sage: sorted(C.axioms()) # optional - sage.rings.finite_rings + sage: sorted(C.axioms()) ['AdditiveAssociative', 'AdditiveCommutative', 'AdditiveInverse', 'AdditiveUnital', 'Finite', 'FiniteDimensional'] @@ -2472,7 +2472,7 @@ def axioms(self): ['AdditiveAssociative', 'AdditiveCommutative', 'AdditiveInverse', 'AdditiveUnital', 'Associative', 'Distributive', 'FiniteDimensional', 'Unital', 'WithBasis'] - sage: sorted(FiniteMonoids().Algebras(GF(3)).axioms()) # optional - sage.rings.finite_rings + sage: sorted(FiniteMonoids().Algebras(GF(3)).axioms()) ['AdditiveAssociative', 'AdditiveCommutative', 'AdditiveInverse', 'AdditiveUnital', 'Associative', 'Distributive', 'Finite', 'FiniteDimensional', 'Unital', 'WithBasis'] diff --git a/src/sage/categories/chain_complexes.py b/src/sage/categories/chain_complexes.py index 8ce3e6145bc..db9c5d03f56 100644 --- a/src/sage/categories/chain_complexes.py +++ b/src/sage/categories/chain_complexes.py @@ -67,27 +67,29 @@ def homology(self, n=None): EXAMPLES:: - sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) # optional - sage.modules - sage: C.homology(0) # optional - sage.modules + sage: # needs sage.modules + sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) + sage: C.homology(0) Z x Z - sage: C.homology(1) # optional - sage.modules + sage: C.homology(1) Z x C3 - sage: C.homology(2) # optional - sage.modules + sage: C.homology(2) 0 :: - sage: A. = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3)) # optional - sage.combinat sage.modules - sage: C = A.cdg_algebra({z: x*y}) # optional - sage.combinat sage.modules - sage: C.homology(0) # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: A. = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3)) + sage: C = A.cdg_algebra({z: x*y}) + sage: C.homology(0) Free module generated by {[1]} over Rational Field - sage: C.homology(1) # optional - sage.combinat sage.modules + sage: C.homology(1) Free module generated by {} over Rational Field - sage: C.homology(2) # optional - sage.combinat sage.modules + sage: C.homology(2) Free module generated by {[x], [y]} over Rational Field - sage: C.homology(3) # optional - sage.combinat sage.modules + sage: C.homology(3) Free module generated by {} over Rational Field - sage: C.homology(4) # optional - sage.combinat sage.modules + sage: C.homology(4) Free module generated by {[x^2], [y^2]} over Rational Field """ @@ -99,16 +101,16 @@ def differential(self, *args, **kwargs): EXAMPLES:: - sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) # optional - sage.modules - sage: C.differential(0) # optional - sage.modules + sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) # needs sage.modules + sage: C.differential(0) # needs sage.modules [3 0 0] [0 0 0] :: - sage: A. = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3)) # optional - sage.combinat sage.modules - sage: C = A.cdg_algebra({z: x*y}) # optional - sage.combinat sage.modules - sage: C.differential() # optional - sage.combinat sage.modules + sage: A. = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3)) # needs sage.combinat sage.modules + sage: C = A.cdg_algebra({z: x*y}) # needs sage.combinat sage.modules + sage: C.differential() # needs sage.combinat sage.modules Differential of Commutative Differential Graded Algebra with generators ('x', 'y', 'z') in degrees (2, 2, 3) over Rational Field Defn: x --> 0 @@ -124,10 +126,11 @@ def lift_from_homology(self, x): EXAMPLES:: - sage: E3 = EuclideanSpace(3) # optional - sage.symbolic - sage: C = E3.de_rham_complex() # optional - sage.symbolic - sage: one = C.homology().one() # optional - sage.symbolic - sage: C.lift_from_homology(one) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: E3 = EuclideanSpace(3) + sage: C = E3.de_rham_complex() + sage: one = C.homology().one() + sage: C.lift_from_homology(one) Mixed differential form one on the Euclidean space E^3 """ @@ -144,10 +147,11 @@ def reduce_to_homology(self, x, n=None): EXAMPLES:: - sage: E3 = EuclideanSpace(3) # optional - sage.symbolic - sage: C = E3.de_rham_complex() # optional - sage.symbolic - sage: one = C.one() # optional - sage.symbolic - sage: C.reduce_to_homology(one) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: E3 = EuclideanSpace(3) + sage: C = E3.de_rham_complex() + sage: one = C.one() + sage: C.reduce_to_homology(one) [one] """ try: @@ -169,35 +173,38 @@ class HomologyFunctor(Functor): EXAMPLES:: - sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) # optional - sage.modules - sage: H = HomologyFunctor(ChainComplexes(ZZ), 1) # optional - sage.modules - sage: H(C) # optional - sage.modules + sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) # needs sage.modules + sage: H = HomologyFunctor(ChainComplexes(ZZ), 1) + sage: H(C) # needs sage.modules Z x C3 :: - sage: A. = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3)) # optional - sage.combinat sage.modules - sage: C = A.cdg_algebra({z: x*y}) # optional - sage.combinat sage.modules - sage: H = HomologyFunctor(ChainComplexes(QQ), 2) # optional - sage.combinat sage.modules - sage: H(C) # optional - sage.combinat sage.modules + sage: A. = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3)) # needs sage.combinat sage.modules + sage: C = A.cdg_algebra({z: x*y}) # needs sage.combinat sage.modules + sage: H = HomologyFunctor(ChainComplexes(QQ), 2) + sage: H(C) # needs sage.combinat sage.modules Free module generated by {[x], [y]} over Rational Field Applying to a chain map:: - sage: S = simplicial_complexes.Sphere(1); S # optional - sage.graphs + sage: # needs sage.graphs sage.modules + sage: S = simplicial_complexes.Sphere(1); S Minimal triangulation of the 1-sphere - sage: C = S.chain_complex() # optional - sage.graphs sage.modules - sage: C.differential() # optional - sage.graphs sage.modules - {0: [], 1: [-1 -1 0] - [ 1 0 -1] - [ 0 1 1], 2: []} - sage: f = {0: zero_matrix(ZZ,3,3), 1: zero_matrix(ZZ,3,3)} # optional - sage.modules - sage: G = Hom(C, C) # optional - sage.graphs sage.modules - sage: x = G(f) # optional - sage.graphs sage.modules - sage: H = HomologyFunctor(ChainComplexes(ZZ), 1) # optional - sage.graphs sage.modules - sage: H(C) # optional - sage.graphs sage.modules + sage: SCC = S.chain_complex() + sage: SCC.differential() + {0: [], + 1: [-1 -1 0] + [ 1 0 -1] + [ 0 1 1], + 2: []} + sage: f = {0: zero_matrix(ZZ,3,3), 1: zero_matrix(ZZ,3,3)} + sage: G = Hom(SCC, SCC) + sage: x = G(f) + sage: H = HomologyFunctor(ChainComplexes(ZZ), 1) + sage: H(SCC) Z - sage: H(x) # optional - sage.graphs sage.modules + sage: H(x) Generic morphism: From: Z To: Z @@ -226,9 +233,9 @@ def _apply_functor(self, x): TESTS:: - sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) # optional - sage.modules - sage: H = HomologyFunctor(ChainComplexes(ZZ), 1) # optional - sage.modules - sage: H._apply_functor(C) # optional - sage.modules + sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) # needs sage.modules + sage: H = HomologyFunctor(ChainComplexes(ZZ), 1) + sage: H._apply_functor(C) # needs sage.modules Z x C3 """ @@ -240,15 +247,16 @@ def _apply_functor_to_morphism(self, f): TESTS:: - sage: E3 = EuclideanSpace(3) # optional - sage.symbolic - sage: C = E3.de_rham_complex() # optional - sage.symbolic - sage: id = Hom(C, C).identity() # optional - sage.symbolic - sage: H = HomologyFunctor(ChainComplexes(SR)) # optional - sage.symbolic - sage: id_star = H(id); id_star # optional - sage.symbolic + sage: # needs sage.symbolic + sage: E3 = EuclideanSpace(3) + sage: C = E3.de_rham_complex() + sage: id = Hom(C, C).identity() + sage: H = HomologyFunctor(ChainComplexes(SR)) + sage: id_star = H(id); id_star Generic endomorphism of De Rham cohomology ring on the Euclidean space E^3 - sage: one = H(C).one() # optional - sage.symbolic - sage: id_star(one) # optional - sage.symbolic + sage: one = H(C).one() + sage: id_star(one) [one] """ from .morphism import SetMorphism diff --git a/src/sage/categories/classical_crystals.py b/src/sage/categories/classical_crystals.py index 744b1cb6e44..fb5d2c7cde8 100644 --- a/src/sage/categories/classical_crystals.py +++ b/src/sage/categories/classical_crystals.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.graphs, sage.combinat +# sage.doctest: needs sage.graphs sage.combinat r""" Classical Crystals """ diff --git a/src/sage/categories/coalgebras.py b/src/sage/categories/coalgebras.py index 870315dc644..abe36aef0bb 100644 --- a/src/sage/categories/coalgebras.py +++ b/src/sage/categories/coalgebras.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.combinat +# sage.doctest: needs sage.combinat r""" Coalgebras """ @@ -67,6 +67,7 @@ def counit(self, x): EXAMPLES:: + sage: # needs sage.modules sage: A = HopfAlgebrasWithBasis(QQ).example(); A An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Rational Field @@ -91,6 +92,7 @@ def coproduct(self, x): EXAMPLES:: + sage: # needs sage.modules sage: A = HopfAlgebrasWithBasis(QQ).example(); A An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Rational Field @@ -109,6 +111,7 @@ def coproduct(self): EXAMPLES:: + sage: # needs sage.modules sage: A = HopfAlgebrasWithBasis(QQ).example(); A An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Rational Field @@ -126,6 +129,7 @@ def counit(self): EXAMPLES:: + sage: # needs sage.modules sage: A = HopfAlgebrasWithBasis(QQ).example(); A An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Rational Field @@ -292,6 +296,7 @@ def coproduct(self, x): EXAMPLES:: + sage: # needs sage.modules sage: N = NonCommutativeSymmetricFunctions(QQ) sage: S = N.complete() sage: N.coproduct.__module__ @@ -307,6 +312,7 @@ def counit(self, x): EXAMPLES:: + sage: # needs sage.modules sage: Sym = SymmetricFunctions(QQ) sage: s = Sym.schur() sage: f = s[2,1] @@ -317,6 +323,7 @@ def counit(self, x): :: + sage: # needs sage.modules sage: N = NonCommutativeSymmetricFunctions(QQ) sage: N.counit.__module__ 'sage.categories.coalgebras' @@ -340,6 +347,7 @@ def coproduct_by_coercion(self, x): EXAMPLES:: + sage: # needs sage.modules sage: Sym = SymmetricFunctions(QQ) sage: m = Sym.monomial() sage: f = m[2,1] @@ -354,6 +362,7 @@ def coproduct_by_coercion(self, x): :: + sage: # needs sage.modules sage: N = NonCommutativeSymmetricFunctions(QQ) sage: R = N.ribbon() sage: R.coproduct_by_coercion.__module__ @@ -375,16 +384,16 @@ def counit_by_coercion(self, x): EXAMPLES:: - sage: sp = SymmetricFunctions(QQ).sp() - sage: sp.an_element() + sage: sp = SymmetricFunctions(QQ).sp() # needs sage.modules + sage: sp.an_element() # needs sage.modules 2*sp[] + 2*sp[1] + 3*sp[2] - sage: sp.counit(sp.an_element()) + sage: sp.counit(sp.an_element()) # needs sage.modules 2 - sage: o = SymmetricFunctions(QQ).o() - sage: o.an_element() + sage: o = SymmetricFunctions(QQ).o() # needs sage.modules + sage: o.an_element() # needs sage.modules 2*o[] + 2*o[1] + 3*o[2] - sage: o.counit(o.an_element()) + sage: o.counit(o.an_element()) # needs sage.modules -1 """ R = self.realization_of().a_realization() diff --git a/src/sage/categories/coalgebras_with_basis.py b/src/sage/categories/coalgebras_with_basis.py index 844f5e5a294..1a3ecfe8302 100644 --- a/src/sage/categories/coalgebras_with_basis.py +++ b/src/sage/categories/coalgebras_with_basis.py @@ -61,12 +61,12 @@ def coproduct_on_basis(self, i): EXAMPLES:: - sage: A = HopfAlgebrasWithBasis(QQ).example(); A # optional - sage.groups sage.modules + sage: A = HopfAlgebrasWithBasis(QQ).example(); A # needs sage.groups sage.modules An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Rational Field - sage: (a, b) = A._group.gens() # optional - sage.groups sage.modules - sage: A.coproduct_on_basis(a) # optional - sage.groups sage.modules + sage: (a, b) = A._group.gens() # needs sage.groups sage.modules + sage: A.coproduct_on_basis(a) # needs sage.groups sage.modules B[(1,2,3)] # B[(1,2,3)] """ @@ -81,14 +81,15 @@ def coproduct(self): EXAMPLES:: - sage: A = HopfAlgebrasWithBasis(QQ).example(); A # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: A = HopfAlgebrasWithBasis(QQ).example(); A An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Rational Field - sage: a, b = A.algebra_generators() # optional - sage.groups sage.modules - sage: a, A.coproduct(a) # optional - sage.groups sage.modules + sage: a, b = A.algebra_generators() + sage: a, A.coproduct(a) (B[(1,2,3)], B[(1,2,3)] # B[(1,2,3)]) - sage: b, A.coproduct(b) # optional - sage.groups sage.modules + sage: b, A.coproduct(b) (B[(1,3)], B[(1,3)] # B[(1,3)]) """ @@ -115,12 +116,12 @@ def counit_on_basis(self, i): EXAMPLES:: - sage: A = HopfAlgebrasWithBasis(QQ).example(); A # optional - sage.groups sage.modules + sage: A = HopfAlgebrasWithBasis(QQ).example(); A # needs sage.groups sage.modules An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Rational Field - sage: (a, b) = A._group.gens() # optional - sage.groups sage.modules - sage: A.counit_on_basis(a) # optional - sage.groups sage.modules + sage: (a, b) = A._group.gens() # needs sage.groups sage.modules + sage: A.counit_on_basis(a) # needs sage.groups sage.modules 1 """ @@ -133,14 +134,15 @@ def counit(self): EXAMPLES:: - sage: A = HopfAlgebrasWithBasis(QQ).example(); A # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: A = HopfAlgebrasWithBasis(QQ).example(); A An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Rational Field - sage: a, b = A.algebra_generators() # optional - sage.groups sage.modules - sage: a, A.counit(a) # optional - sage.groups sage.modules + sage: a, b = A.algebra_generators() + sage: a, A.counit(a) (B[(1,2,3)], 1) - sage: b, A.counit(b) # optional - sage.groups sage.modules + sage: b, A.counit(b) (B[(1,3)], 1) """ @@ -160,29 +162,29 @@ def coproduct_iterated(self, n=1): EXAMPLES:: - sage: Psi = NonCommutativeSymmetricFunctions(QQ).Psi() # optional - sage.combinat - sage: Psi[2,2].coproduct_iterated(0) # optional - sage.combinat + sage: Psi = NonCommutativeSymmetricFunctions(QQ).Psi() # needs sage.combinat sage.modules + sage: Psi[2,2].coproduct_iterated(0) # needs sage.combinat sage.modules Psi[2, 2] - sage: Psi[2,2].coproduct_iterated(2) # optional - sage.combinat + sage: Psi[2,2].coproduct_iterated(2) # needs sage.combinat sage.modules Psi[] # Psi[] # Psi[2, 2] + 2*Psi[] # Psi[2] # Psi[2] + Psi[] # Psi[2, 2] # Psi[] + 2*Psi[2] # Psi[] # Psi[2] + 2*Psi[2] # Psi[2] # Psi[] + Psi[2, 2] # Psi[] # Psi[] TESTS:: - sage: p = SymmetricFunctions(QQ).p() # optional - sage.combinat - sage: p[5,2,2].coproduct_iterated() # optional - sage.combinat + sage: p = SymmetricFunctions(QQ).p() # needs sage.combinat sage.modules + sage: p[5,2,2].coproduct_iterated() # needs sage.combinat sage.modules p[] # p[5, 2, 2] + 2*p[2] # p[5, 2] + p[2, 2] # p[5] + p[5] # p[2, 2] + 2*p[5, 2] # p[2] + p[5, 2, 2] # p[] - sage: p([]).coproduct_iterated(3) # optional - sage.combinat + sage: p([]).coproduct_iterated(3) # needs sage.combinat sage.modules p[] # p[] # p[] # p[] :: - sage: Psi = NonCommutativeSymmetricFunctions(QQ).Psi() # optional - sage.combinat - sage: Psi[2,2].coproduct_iterated(0) # optional - sage.combinat + sage: Psi = NonCommutativeSymmetricFunctions(QQ).Psi() # needs sage.combinat sage.modules + sage: Psi[2,2].coproduct_iterated(0) # needs sage.combinat sage.modules Psi[2, 2] - sage: Psi[2,2].coproduct_iterated(3) # optional - sage.combinat + sage: Psi[2,2].coproduct_iterated(3) # needs sage.combinat sage.modules Psi[] # Psi[] # Psi[] # Psi[2, 2] + 2*Psi[] # Psi[] # Psi[2] # Psi[2] + Psi[] # Psi[] # Psi[2, 2] # Psi[] + 2*Psi[] # Psi[2] # Psi[] # Psi[2] + 2*Psi[] # Psi[2] # Psi[2] # Psi[] + Psi[] # Psi[2, 2] # Psi[] # Psi[] @@ -191,14 +193,14 @@ def coproduct_iterated(self, n=1): :: - sage: m = SymmetricFunctionsNonCommutingVariables(QQ).m() # optional - sage.combinat - sage: m[[1,3],[2]].coproduct_iterated(2) # optional - sage.combinat + sage: m = SymmetricFunctionsNonCommutingVariables(QQ).m() # needs sage.combinat sage.modules + sage: m[[1,3],[2]].coproduct_iterated(2) # needs sage.combinat sage.modules m{} # m{} # m{{1, 3}, {2}} + m{} # m{{1}} # m{{1, 2}} + m{} # m{{1, 2}} # m{{1}} + m{} # m{{1, 3}, {2}} # m{} + m{{1}} # m{} # m{{1, 2}} + m{{1}} # m{{1, 2}} # m{} + m{{1, 2}} # m{} # m{{1}} + m{{1, 2}} # m{{1}} # m{} + m{{1, 3}, {2}} # m{} # m{} - sage: m[[]].coproduct_iterated(3), m[[1,3],[2]].coproduct_iterated(0) # optional - sage.combinat + sage: m[[]].coproduct_iterated(3), m[[1,3],[2]].coproduct_iterated(0) # needs sage.combinat sage.modules (m{} # m{} # m{} # m{}, m{{1, 3}, {2}}) """ if n < 0: diff --git a/src/sage/categories/commutative_additive_groups.py b/src/sage/categories/commutative_additive_groups.py index 9300f4d6db5..ce1dfc5186a 100644 --- a/src/sage/categories/commutative_additive_groups.py +++ b/src/sage/categories/commutative_additive_groups.py @@ -79,11 +79,12 @@ def additive_order(self): sage: G((0,1)).additive_order() +Infinity - sage: K = GF(9) # optional - sage.rings.finite_rings - sage: H = cartesian_product([ # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K = GF(9) + sage: H = cartesian_product([ ....: cartesian_product([Zmod(2), Zmod(9)]), K]) - sage: z = H(((1,2), K.gen())) # optional - sage.rings.finite_rings - sage: z.additive_order() # optional - sage.rings.finite_rings + sage: z = H(((1,2), K.gen())) + sage: z.additive_order() 18 """ from sage.rings.infinity import Infinity diff --git a/src/sage/categories/commutative_algebra_ideals.py b/src/sage/categories/commutative_algebra_ideals.py index e0835848e91..070503ae6c8 100644 --- a/src/sage/categories/commutative_algebra_ideals.py +++ b/src/sage/categories/commutative_algebra_ideals.py @@ -45,7 +45,7 @@ def __init__(self, A): ... TypeError: A (=Ring of integers modulo 4) must be a commutative algebra - sage: CommutativeAlgebraIdeals(Partitions(4)) # optional - sage.combinat sage.modules + sage: CommutativeAlgebraIdeals(Partitions(4)) # needs sage.combinat Traceback (most recent call last): ... TypeError: A (=Partitions of the integer 4) must be a commutative algebra diff --git a/src/sage/categories/commutative_algebras.py b/src/sage/categories/commutative_algebras.py index bdff573db87..986a45db3e3 100644 --- a/src/sage/categories/commutative_algebras.py +++ b/src/sage/categories/commutative_algebras.py @@ -22,8 +22,8 @@ class CommutativeAlgebras(CategoryWithAxiom_over_base_ring): EXAMPLES:: - sage: M = CommutativeAlgebras(GF(19)) # optional - sage.rings.finite_rings - sage: M # optional - sage.rings.finite_rings + sage: M = CommutativeAlgebras(GF(19)) + sage: M Category of commutative algebras over Finite Field of size 19 sage: CommutativeAlgebras(QQ).super_categories() [Category of algebras over Rational Field, Category of commutative rings] @@ -53,7 +53,7 @@ def __contains__(self, A): True sage: QQ['a,b'] in CommutativeAlgebras(QQ) True - sage: FreeAlgebra(QQ, 2, 'a,b') in CommutativeAlgebras(QQ) # optional - sage.combinat + sage: FreeAlgebra(QQ, 2, 'a,b') in CommutativeAlgebras(QQ) # needs sage.combinat sage.modules False TODO: get rid of this method once all commutative algebras in @@ -80,12 +80,13 @@ def extra_super_categories(self): TESTS:: - sage: X = algebras.Shuffle(QQ, 'ab') # optional - sage.combinat - sage: Y = algebras.Shuffle(QQ, 'bc') # optional - sage.combinat - sage: X in Algebras(QQ).Commutative() # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: X = algebras.Shuffle(QQ, 'ab') + sage: Y = algebras.Shuffle(QQ, 'bc') + sage: X in Algebras(QQ).Commutative() True - sage: T = tensor([X, Y]) # optional - sage.combinat - sage: T in CommutativeRings() # optional - sage.combinat + sage: T = tensor([X, Y]) + sage: T in CommutativeRings() True """ return [CommutativeRings()] diff --git a/src/sage/categories/commutative_ring_ideals.py b/src/sage/categories/commutative_ring_ideals.py index 837f1edf944..391c4f2272d 100644 --- a/src/sage/categories/commutative_ring_ideals.py +++ b/src/sage/categories/commutative_ring_ideals.py @@ -35,7 +35,7 @@ def __init__(self, R): TESTS:: - sage: CommutativeRingIdeals(Partitions(4)) # optional - sage.combinat + sage: CommutativeRingIdeals(Partitions(4)) # needs sage.combinat Traceback (most recent call last): ... TypeError: R (=Partitions of the integer 4) must be a commutative ring diff --git a/src/sage/categories/commutative_rings.py b/src/sage/categories/commutative_rings.py index 6219c1070bb..b99fb7d8eb3 100644 --- a/src/sage/categories/commutative_rings.py +++ b/src/sage/categories/commutative_rings.py @@ -35,14 +35,14 @@ class CommutativeRings(CategoryWithAxiom): sage: QQ['x,y,z'] in CommutativeRings() True - sage: GroupAlgebra(DihedralGroup(3), QQ) in CommutativeRings() # optional - sage.groups sage.modules + sage: GroupAlgebra(DihedralGroup(3), QQ) in CommutativeRings() # needs sage.groups sage.modules False - sage: MatrixSpace(QQ, 2, 2) in CommutativeRings() # optional - sage.modules + sage: MatrixSpace(QQ, 2, 2) in CommutativeRings() # needs sage.modules False GroupAlgebra should be fixed:: - sage: GroupAlgebra(CyclicPermutationGroup(3), QQ) in CommutativeRings() # todo: not implemented # optional - sage.groups sage.modules + sage: GroupAlgebra(CyclicPermutationGroup(3), QQ) in CommutativeRings() # not implemented, needs sage.groups sage.modules True """ @@ -110,63 +110,62 @@ def over(self, base=None, gen=None, gens=None, name=None, names=None): We construct an extension of finite fields:: - sage: F = GF(5^2) # optional - sage.rings.finite_rings - sage: k = GF(5^4) # optional - sage.rings.finite_rings - sage: z4 = k.gen() # optional - sage.rings.finite_rings - - sage: K = k.over(F) # optional - sage.rings.finite_rings - sage: K # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: F = GF(5^2) + sage: k = GF(5^4) + sage: z4 = k.gen() + sage: K = k.over(F); K # needs sage.modules Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base If not explicitly given, the default generator of the top ring (here k) is used and the same name is kept:: - sage: K.gen() # optional - sage.rings.finite_rings + sage: K.gen() # needs sage.modules sage.rings.finite_rings z4 - sage: K(z4) # optional - sage.rings.finite_rings + sage: K(z4) # needs sage.modules sage.rings.finite_rings z4 However, it is possible to specify another generator and/or another name. For example:: - sage: Ka = k.over(F, name='a') # optional - sage.rings.finite_rings - sage: Ka # optional - sage.rings.finite_rings + sage: # needs sage.modules sage.rings.finite_rings + sage: Ka = k.over(F, name='a'); Ka Field in a with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base - sage: Ka.gen() # optional - sage.rings.finite_rings + sage: Ka.gen() a - sage: Ka(z4) # optional - sage.rings.finite_rings + sage: Ka(z4) a - sage: Kb = k.over(F, gen=-z4+1, name='b') # optional - sage.rings.finite_rings - sage: Kb # optional - sage.rings.finite_rings + sage: # needs sage.modules sage.rings.finite_rings + sage: Kb = k.over(F, gen=-z4+1, name='b') + sage: Kb Field in b with defining polynomial x^2 + z2*x + 4 over its base - sage: Kb.gen() # optional - sage.rings.finite_rings + sage: Kb.gen() b - sage: Kb(-z4+1) # optional - sage.rings.finite_rings + sage: Kb(-z4+1) b Note that the shortcut ``K.`` is also available:: - sage: KKa. = k.over(F) # optional - sage.rings.finite_rings - sage: KKa is Ka # optional - sage.rings.finite_rings + sage: KKa. = k.over(F) # needs sage.modules sage.rings.finite_rings + sage: KKa is Ka # needs sage.modules sage.rings.finite_rings True Building an extension on top of another extension is allowed:: - sage: L = GF(5^12).over(K) # optional - sage.rings.finite_rings - sage: L # optional - sage.rings.finite_rings + sage: L = GF(5^12).over(K); L # needs sage.modules sage.rings.finite_rings Field in z12 with defining polynomial x^3 + (1 + (4*z2 + 2)*z4)*x^2 + (2 + 2*z4)*x - z4 over its base - sage: L.base_ring() # optional - sage.rings.finite_rings + sage: L.base_ring() # needs sage.modules sage.rings.finite_rings Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base The successive bases of an extension are accessible via the method :meth:`sage.rings.ring_extension.RingExtension_generic.bases`:: - sage: L.bases() # optional - sage.rings.finite_rings + sage: L.bases() # needs sage.modules sage.rings.finite_rings [Field in z12 with defining polynomial x^3 + (1 + (4*z2 + 2)*z4)*x^2 + (2 + 2*z4)*x - z4 over its base, Field in z4 with defining polynomial @@ -176,32 +175,32 @@ def over(self, base=None, gen=None, gens=None, name=None, names=None): When ``base`` is omitted, the canonical base of the ring is used:: sage: S. = QQ[] - sage: E = S.over() # optional - sage.modules - sage: E # optional - sage.modules + sage: E = S.over(); E # needs sage.modules Univariate Polynomial Ring in x over Rational Field over its base - sage: E.base_ring() # optional - sage.modules + sage: E.base_ring() # needs sage.modules Rational Field Here is an example where ``base`` is a defining morphism:: - sage: k. = QQ.extension(x^2 - 2) # optional - sage.rings.number_field - sage: l. = QQ.extension(x^4 - 2) # optional - sage.rings.number_field - sage: f = k.hom([b^2]) # optional - sage.rings.number_field - sage: L = l.over(f) # optional - sage.rings.number_field - sage: L # optional - sage.rings.number_field + sage: # needs sage.modules sage.rings.number_field + sage: k. = QQ.extension(x^2 - 2) + sage: l. = QQ.extension(x^4 - 2) + sage: f = k.hom([b^2]) + sage: L = l.over(f) + sage: L Field in b with defining polynomial x^2 - a over its base - sage: L.base_ring() # optional - sage.rings.number_field + sage: L.base_ring() Number Field in a with defining polynomial x^2 - 2 Similarly, one can create a tower of extensions:: - sage: K = k.over() # optional - sage.rings.number_field - sage: L = l.over(Hom(K, l)(f)) # optional - sage.rings.number_field - sage: L # optional - sage.rings.number_field + sage: # needs sage.modules sage.rings.number_field + sage: K = k.over() + sage: L = l.over(Hom(K, l)(f)); L Field in b with defining polynomial x^2 - a over its base - sage: L.base_ring() # optional - sage.rings.number_field + sage: L.base_ring() Field in a with defining polynomial x^2 - 2 over its base - sage: L.bases() # optional - sage.rings.number_field + sage: L.bases() [Field in b with defining polynomial x^2 - a over its base, Field in a with defining polynomial x^2 - 2 over its base, Rational Field] @@ -227,7 +226,7 @@ class Finite(CategoryWithAxiom): EXAMPLES:: - sage: cartesian_product([Zmod(34), # optional - sage.rings.finite_rings + sage: cartesian_product([Zmod(34), ....: GF(5)]) in Rings().Commutative().Finite() True """ @@ -285,34 +284,36 @@ def cyclotomic_cosets(self, q, cosets=None): cyclic, the set of squares is a particular case of cyclotomic coset:: - sage: K = GF(25, 'z') # optional - sage.rings.finite_rings - sage: a = K.multiplicative_generator() # optional - sage.rings.finite_rings - sage: K.cyclotomic_cosets(a**2, cosets=[1]) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K = GF(25, 'z') + sage: a = K.multiplicative_generator() + sage: K.cyclotomic_cosets(a**2, cosets=[1]) [[1, 2, 3, 4, z + 1, z + 3, 2*z + 1, 2*z + 2, 3*z + 3, 3*z + 4, 4*z + 2, 4*z + 4]] - sage: sorted(b for b in K if not b.is_zero() and b.is_square()) # optional - sage.rings.finite_rings + sage: sorted(b for b in K if not b.is_zero() and b.is_square()) [1, 2, 3, 4, z + 1, z + 3, 2*z + 1, 2*z + 2, 3*z + 3, 3*z + 4, 4*z + 2, 4*z + 4] We compute some examples of minimal polynomials:: - sage: K = GF(27, 'z') # optional - sage.rings.finite_rings - sage: a = K.multiplicative_generator() # optional - sage.rings.finite_rings - sage: R. = PolynomialRing(K, 'X') # optional - sage.rings.finite_rings - sage: a.minimal_polynomial('X') # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K = GF(27, 'z') + sage: a = K.multiplicative_generator() + sage: R. = PolynomialRing(K, 'X') + sage: a.minimal_polynomial('X') X^3 + 2*X + 1 - sage: cyc3 = Zmod(26).cyclotomic_cosets(3, cosets=[1]); cyc3 # optional - sage.rings.finite_rings + + sage: cyc3 = Zmod(26).cyclotomic_cosets(3, cosets=[1]); cyc3 [[1, 3, 9]] - sage: prod(X - a**i for i in cyc3[0]) # optional - sage.rings.finite_rings + sage: prod(X - a**i for i in cyc3[0]) # needs sage.rings.finite_rings X^3 + 2*X + 1 - - sage: (a**7).minimal_polynomial('X') # optional - sage.rings.finite_rings + sage: (a**7).minimal_polynomial('X') # needs sage.rings.finite_rings X^3 + X^2 + 2*X + 1 - sage: cyc7 = Zmod(26).cyclotomic_cosets(3, cosets=[7]); cyc7 # optional - sage.rings.finite_rings + sage: cyc7 = Zmod(26).cyclotomic_cosets(3, cosets=[7]); cyc7 [[7, 11, 21]] - sage: prod(X - a**i for i in cyc7[0]) # optional - sage.rings.finite_rings + sage: prod(X - a**i for i in cyc7[0]) # needs sage.rings.finite_rings X^3 + X^2 + 2*X + 1 Cyclotomic cosets of fields are useful in combinatorial design @@ -321,26 +322,26 @@ def cyclotomic_cosets(self, q, cosets=None): :mod:`~sage.combinat.designs.difference_family`). This is illustrated on the following examples:: - sage: K = GF(5) # optional - sage.rings.finite_rings - sage: a = K.multiplicative_generator() # optional - sage.rings.finite_rings - sage: H = K.cyclotomic_cosets(a**2, cosets=[1, 2]); H # optional - sage.rings.finite_rings + sage: K = GF(5) + sage: a = K.multiplicative_generator() # needs sage.libs.pari + sage: H = K.cyclotomic_cosets(a**2, cosets=[1, 2]); H # needs sage.rings.finite_rings [[1, 4], [2, 3]] - sage: sorted(x - y for D in H for x in D for y in D if x != y) # optional - sage.rings.finite_rings + sage: sorted(x - y for D in H for x in D for y in D if x != y) # needs sage.rings.finite_rings [1, 2, 3, 4] - sage: K = GF(37) # optional - sage.rings.finite_rings - sage: a = K.multiplicative_generator() # optional - sage.rings.finite_rings - sage: H = K.cyclotomic_cosets(a**4, cosets=[1]); H # optional - sage.rings.finite_rings + sage: K = GF(37) + sage: a = K.multiplicative_generator() # needs sage.libs.pari + sage: H = K.cyclotomic_cosets(a**4, cosets=[1]); H # needs sage.rings.finite_rings [[1, 7, 9, 10, 12, 16, 26, 33, 34]] - sage: sorted(x - y for D in H for x in D for y in D if x != y) # optional - sage.rings.finite_rings + sage: sorted(x - y for D in H for x in D for y in D if x != y) # needs sage.rings.finite_rings [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, ..., 33, 34, 34, 35, 35, 36, 36] The method ``cyclotomic_cosets`` works on any finite commutative ring:: - sage: R = cartesian_product([GF(7), Zmod(14)]) # optional - sage.rings.finite_rings - sage: a = R((3,5)) # optional - sage.rings.finite_rings - sage: R.cyclotomic_cosets((3,5), [(1,1)]) # optional - sage.rings.finite_rings + sage: R = cartesian_product([GF(7), Zmod(14)]) + sage: a = R((3,5)) + sage: R.cyclotomic_cosets((3,5), [(1,1)]) [[(1, 1), (2, 11), (3, 5), (4, 9), (5, 3), (6, 13)]] """ q = self(q) @@ -380,7 +381,7 @@ def extra_super_categories(self): sage: CommutativeRings().Commutative().CartesianProducts().extra_super_categories() [Category of commutative rings] - sage: cartesian_product([ZZ, Zmod(34), # optional - sage.rings.finite_rings + sage: cartesian_product([ZZ, Zmod(34), ....: QQ, GF(5)]) in CommutativeRings() True """ diff --git a/src/sage/categories/complete_discrete_valuation.py b/src/sage/categories/complete_discrete_valuation.py index 71c7ec57015..442360465a1 100644 --- a/src/sage/categories/complete_discrete_valuation.py +++ b/src/sage/categories/complete_discrete_valuation.py @@ -22,13 +22,13 @@ class CompleteDiscreteValuationRings(Category_singleton): EXAMPLES:: - sage: Zp(7) in CompleteDiscreteValuationRings() # optional - sage.rings.padics + sage: Zp(7) in CompleteDiscreteValuationRings() # needs sage.rings.padics True sage: QQ in CompleteDiscreteValuationRings() False sage: QQ[['u']] in CompleteDiscreteValuationRings() True - sage: Qp(7) in CompleteDiscreteValuationRings() # optional - sage.rings.padics + sage: Qp(7) in CompleteDiscreteValuationRings() # needs sage.rings.padics False sage: TestSuite(CompleteDiscreteValuationRings()).run() """ @@ -49,10 +49,10 @@ def valuation(self): EXAMPLES:: - sage: R = Zp(7) # optional - sage.rings.padics - sage: x = R(7); x # optional - sage.rings.padics + sage: R = Zp(7) # needs sage.rings.padics + sage: x = R(7); x # needs sage.rings.padics 7 + O(7^21) - sage: x.valuation() # optional - sage.rings.padics + sage: x.valuation() # needs sage.rings.padics 1 """ @@ -63,32 +63,32 @@ def denominator(self): EXAMPLES:: - sage: K = Qp(7) # optional - sage.rings.padics - sage: x = K(1/21) # optional - sage.rings.padics - sage: x.denominator() # optional - sage.rings.padics + sage: # needs sage.rings.padics + sage: K = Qp(7) + sage: x = K(1/21) + sage: x.denominator() 7 + O(7^21) - - sage: x = K(7) # optional - sage.rings.padics - sage: x.denominator() # optional - sage.rings.padics + sage: x = K(7) + sage: x.denominator() 1 + O(7^20) Note that the denominator lives in the ring of integers:: - sage: x.denominator().parent() # optional - sage.rings.padics + sage: x.denominator().parent() # needs sage.rings.padics 7-adic Ring with capped relative precision 20 When the denominator is indistinguishable from 0 and the precision on the input is `O(p^n)`, the return value is `1` if `n` is nonnegative and `p^(-n)` otherwise:: - sage: x = K(0, 5); x # optional - sage.rings.padics + sage: # needs sage.rings.padics + sage: x = K(0, 5); x O(7^5) - sage: x.denominator() # optional - sage.rings.padics + sage: x.denominator() 1 + O(7^20) - - sage: x = K(0, -5); x # optional - sage.rings.padics + sage: x = K(0, -5); x O(7^-5) - sage: x.denominator() # optional - sage.rings.padics + sage: x.denominator() 7^5 + O(7^25) """ return self.parent()(1) @@ -101,26 +101,26 @@ def numerator(self): EXAMPLES:: - sage: K = Qp(7, 5) # optional - sage.rings.padics - sage: x = K(1/21) # optional - sage.rings.padics - sage: x.numerator() # optional - sage.rings.padics + sage: # needs sage.rings.padics + sage: K = Qp(7, 5) + sage: x = K(1/21) + sage: x.numerator() 5 + 4*7 + 4*7^2 + 4*7^3 + 4*7^4 + O(7^5) - - sage: x == x.numerator() / x.denominator() # optional - sage.rings.padics + sage: x == x.numerator() / x.denominator() True Note that the numerator lives in the ring of integers:: - sage: x.numerator().parent() # optional - sage.rings.padics + sage: x.numerator().parent() # needs sage.rings.padics 7-adic Ring with capped relative precision 5 TESTS:: - sage: x = K(0, -5); x # optional - sage.rings.padics + sage: x = K(0, -5); x # needs sage.rings.padics O(7^-5) - sage: x.numerator() # optional - sage.rings.padics + sage: x.numerator() # needs sage.rings.padics O(7^0) - sage: x.denominator() # optional - sage.rings.padics + sage: x.denominator() # needs sage.rings.padics 7^5 + O(7^10) """ return self @@ -146,22 +146,23 @@ def lift_to_precision(self, absprec=None): EXAMPLES:: - sage: R = ZpCA(17) # optional - sage.rings.padics - sage: R(-1, 2).lift_to_precision(10) # optional - sage.rings.padics + sage: # needs sage.rings.padics + sage: R = ZpCA(17) + sage: R(-1, 2).lift_to_precision(10) 16 + 16*17 + O(17^10) - sage: R(1, 15).lift_to_precision(10) # optional - sage.rings.padics + sage: R(1, 15).lift_to_precision(10) 1 + O(17^15) - sage: R(1, 15).lift_to_precision(30) # optional - sage.rings.padics + sage: R(1, 15).lift_to_precision(30) Traceback (most recent call last): ... PrecisionError: precision higher than allowed by the precision cap - sage: (R(-1, 2).lift_to_precision().precision_absolute() # optional - sage.rings.padics + sage: (R(-1, 2).lift_to_precision().precision_absolute() ....: == R.precision_cap()) True - sage: R = Zp(5); c = R(17, 3); c.lift_to_precision(8) # optional - sage.rings.padics + sage: R = Zp(5); c = R(17, 3); c.lift_to_precision(8) # needs sage.rings.padics 2 + 3*5 + O(5^8) - sage: c.lift_to_precision().precision_relative() == R.precision_cap() # optional - sage.rings.padics + sage: c.lift_to_precision().precision_relative() == R.precision_cap() # needs sage.rings.padics True """ @@ -172,13 +173,13 @@ class CompleteDiscreteValuationFields(Category_singleton): EXAMPLES:: - sage: Zp(7) in CompleteDiscreteValuationFields() # optional - sage.rings.padics + sage: Zp(7) in CompleteDiscreteValuationFields() # needs sage.rings.padics False sage: QQ in CompleteDiscreteValuationFields() False sage: LaurentSeriesRing(QQ, 'u') in CompleteDiscreteValuationFields() True - sage: Qp(7) in CompleteDiscreteValuationFields() # optional - sage.rings.padics + sage: Qp(7) in CompleteDiscreteValuationFields() # needs sage.rings.padics True sage: TestSuite(CompleteDiscreteValuationFields()).run() """ @@ -200,10 +201,10 @@ def valuation(self): EXAMPLES:: - sage: K = Qp(7) # optional - sage.rings.padics - sage: x = K(7); x # optional - sage.rings.padics + sage: K = Qp(7) # needs sage.rings.padics + sage: x = K(7); x # needs sage.rings.padics 7 + O(7^21) - sage: x.valuation() # optional - sage.rings.padics + sage: x.valuation() # needs sage.rings.padics 1 """ @@ -214,32 +215,32 @@ def denominator(self): EXAMPLES:: - sage: K = Qp(7) # optional - sage.rings.padics - sage: x = K(1/21) # optional - sage.rings.padics - sage: x.denominator() # optional - sage.rings.padics + sage: # needs sage.rings.padics + sage: K = Qp(7) + sage: x = K(1/21) + sage: x.denominator() 7 + O(7^21) - - sage: x = K(7) # optional - sage.rings.padics - sage: x.denominator() # optional - sage.rings.padics + sage: x = K(7) + sage: x.denominator() 1 + O(7^20) Note that the denominator lives in the ring of integers:: - sage: x.denominator().parent() # optional - sage.rings.padics + sage: x.denominator().parent() # needs sage.rings.padics 7-adic Ring with capped relative precision 20 When the denominator is indistinguishable from 0 and the precision on the input is `O(p^n)`, the return value is `1` if `n` is nonnegative and `p^(-n)` otherwise:: - sage: x = K(0, 5); x # optional - sage.rings.padics + sage: # needs sage.rings.padics + sage: x = K(0, 5); x O(7^5) - sage: x.denominator() # optional - sage.rings.padics + sage: x.denominator() 1 + O(7^20) - - sage: x = K(0, -5); x # optional - sage.rings.padics + sage: x = K(0, -5); x O(7^-5) - sage: x.denominator() # optional - sage.rings.padics + sage: x.denominator() 7^5 + O(7^25) """ val = self.valuation() @@ -257,26 +258,26 @@ def numerator(self): EXAMPLES:: - sage: K = Qp(7, 5) # optional - sage.rings.padics - sage: x = K(1/21) # optional - sage.rings.padics - sage: x.numerator() # optional - sage.rings.padics + sage: # needs sage.rings.padics + sage: K = Qp(7, 5) + sage: x = K(1/21) + sage: x.numerator() 5 + 4*7 + 4*7^2 + 4*7^3 + 4*7^4 + O(7^5) - - sage: x == x.numerator() / x.denominator() # optional - sage.rings.padics + sage: x == x.numerator() / x.denominator() True Note that the numerator lives in the ring of integers:: - sage: x.numerator().parent() # optional - sage.rings.padics + sage: x.numerator().parent() # needs sage.rings.padics 7-adic Ring with capped relative precision 5 TESTS:: - sage: x = K(0, -5); x # optional - sage.rings.padics + sage: x = K(0, -5); x # needs sage.rings.padics O(7^-5) - sage: x.numerator() # optional - sage.rings.padics + sage: x.numerator() # needs sage.rings.padics O(7^0) - sage: x.denominator() # optional - sage.rings.padics + sage: x.denominator() # needs sage.rings.padics 7^5 + O(7^10) """ R = self.parent().integer_ring() diff --git a/src/sage/categories/complex_reflection_groups.py b/src/sage/categories/complex_reflection_groups.py index e55b16eb6a0..fbc04ff329c 100644 --- a/src/sage/categories/complex_reflection_groups.py +++ b/src/sage/categories/complex_reflection_groups.py @@ -64,18 +64,18 @@ class ComplexReflectionGroups(Category_singleton): An example of a reflection group:: - sage: W = ComplexReflectionGroups().example(); W # optional - sage.combinat sage.groups + sage: W = ComplexReflectionGroups().example(); W # needs sage.combinat 5-colored permutations of size 3 ``W`` is in the category of complex reflection groups:: - sage: W in ComplexReflectionGroups() # optional - sage.combinat sage.groups + sage: W in ComplexReflectionGroups() # needs sage.combinat True TESTS:: - sage: TestSuite(W).run() # optional - sage.combinat sage.groups - sage: TestSuite(ComplexReflectionGroups()).run() # optional - sage.combinat sage.groups + sage: TestSuite(W).run() # needs sage.combinat + sage: TestSuite(ComplexReflectionGroups()).run() """ @cached_method @@ -115,7 +115,7 @@ def example(self): EXAMPLES:: sage: from sage.categories.complex_reflection_groups import ComplexReflectionGroups - sage: ComplexReflectionGroups().example() # optional - sage.combinat sage.groups + sage: ComplexReflectionGroups().example() # needs sage.combinat 5-colored permutations of size 3 """ from sage.combinat.colored_permutations import ColoredPermutations @@ -133,9 +133,9 @@ def rank(self): EXAMPLES:: - sage: W = CoxeterGroups().example(); W # optional - sage.groups + sage: W = CoxeterGroups().example(); W The symmetric group on {0, ..., 3} - sage: W.rank() # optional - sage.groups + sage: W.rank() 3 """ diff --git a/src/sage/categories/complex_reflection_or_generalized_coxeter_groups.py b/src/sage/categories/complex_reflection_or_generalized_coxeter_groups.py index 3dff3b983a6..89667bfc237 100644 --- a/src/sage/categories/complex_reflection_or_generalized_coxeter_groups.py +++ b/src/sage/categories/complex_reflection_or_generalized_coxeter_groups.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.groups +# sage.doctest: needs sage.groups r""" Common category for Generalized Coxeter Groups or Complex Reflection Groups """ @@ -419,14 +419,15 @@ def reflection_index_set(self): EXAMPLES:: - sage: W = ReflectionGroup((1,1,4)) # optional - gap3 - sage: W.reflection_index_set() # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup((1,1,4)) + sage: W.reflection_index_set() (1, 2, 3, 4, 5, 6) - sage: W = ReflectionGroup((1,1,4), reflection_index_set=[1,3,'asdf',7,9,11]) # optional - gap3 - sage: W.reflection_index_set() # optional - gap3 + sage: W = ReflectionGroup((1,1,4), reflection_index_set=[1,3,'asdf',7,9,11]) + sage: W.reflection_index_set() (1, 3, 'asdf', 7, 9, 11) - sage: W = ReflectionGroup((1,1,4), reflection_index_set=('a','b','c','d','e','f')) # optional - gap3 - sage: W.reflection_index_set() # optional - gap3 + sage: W = ReflectionGroup((1,1,4), reflection_index_set=('a','b','c','d','e','f')) + sage: W.reflection_index_set() ('a', 'b', 'c', 'd', 'e', 'f') """ @@ -533,14 +534,15 @@ def hyperplane_index_set(self): EXAMPLES:: - sage: W = ReflectionGroup((1,1,4)) # optional - gap3 - sage: W.hyperplane_index_set() # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup((1,1,4)) + sage: W.hyperplane_index_set() (1, 2, 3, 4, 5, 6) - sage: W = ReflectionGroup((1,1,4), hyperplane_index_set=[1,3,'asdf',7,9,11]) # optional - gap3 - sage: W.hyperplane_index_set() # optional - gap3 + sage: W = ReflectionGroup((1,1,4), hyperplane_index_set=[1,3,'asdf',7,9,11]) + sage: W.hyperplane_index_set() (1, 3, 'asdf', 7, 9, 11) - sage: W = ReflectionGroup((1,1,4), hyperplane_index_set=('a','b','c','d','e','f')) # optional - gap3 - sage: W.hyperplane_index_set() # optional - gap3 + sage: W = ReflectionGroup((1,1,4), hyperplane_index_set=('a','b','c','d','e','f')) + sage: W.hyperplane_index_set() ('a', 'b', 'c', 'd', 'e', 'f') """ @@ -1045,12 +1047,13 @@ def apply_reflections(self, word, side='right', word_type='all'): EXAMPLES:: - sage: W = ReflectionGroup((1,1,3)) # optional - gap3 - sage: W.one().apply_reflections([1]) # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup((1,1,3)) + sage: W.one().apply_reflections([1]) (1,4)(2,3)(5,6) - sage: W.one().apply_reflections([2]) # optional - gap3 + sage: W.one().apply_reflections([2]) (1,3)(2,5)(4,6) - sage: W.one().apply_reflections([2,1]) # optional - gap3 + sage: W.one().apply_reflections([2,1]) (1,2,6)(3,4,5) @@ -1079,14 +1082,15 @@ def apply_reflections(self, word, side='right', word_type='all'): s1 - sage: W = ReflectionGroup((1,1,3)) # optional - gap3 - sage: W.one().apply_reflections([1], word_type='distinguished') # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup((1,1,3)) + sage: W.one().apply_reflections([1], word_type='distinguished') (1,4)(2,3)(5,6) - sage: W.one().apply_reflections([2], word_type='distinguished') # optional - gap3 + sage: W.one().apply_reflections([2], word_type='distinguished') (1,3)(2,5)(4,6) - sage: W.one().apply_reflections([3], word_type='distinguished') # optional - gap3 + sage: W.one().apply_reflections([3], word_type='distinguished') (1,5)(2,4)(3,6) - sage: W.one().apply_reflections([2,1], word_type='distinguished') # optional - gap3 + sage: W.one().apply_reflections([2,1], word_type='distinguished') (1,2,6)(3,4,5) sage: W = ReflectionGroup((1,1,3), hyperplane_index_set=['A','B','C']); W # optional - gap3 diff --git a/src/sage/categories/covariant_functorial_construction.py b/src/sage/categories/covariant_functorial_construction.py index 90a1c42b1cc..77d3f76fa1c 100644 --- a/src/sage/categories/covariant_functorial_construction.py +++ b/src/sage/categories/covariant_functorial_construction.py @@ -134,8 +134,8 @@ def category_from_parents(self, parents): EXAMPLES:: - sage: E = CombinatorialFreeModule(QQ, ["a", "b", "c"]) # optional - sage.modules - sage: tensor.category_from_parents((E, E, E)) # optional - sage.modules + sage: E = CombinatorialFreeModule(QQ, ["a", "b", "c"]) # needs sage.modules + sage: tensor.category_from_parents((E, E, E)) # needs sage.modules Category of tensor products of finite dimensional vector spaces with basis over Rational Field """ @@ -214,8 +214,8 @@ def __call__(self, args, **kwargs): EXAMPLES:: - sage: E = CombinatorialFreeModule(QQ, ["a", "b", "c"]); E.rename("E") # optional - sage.modules - sage: tensor((E, E, E)) # optional - sage.modules + sage: E = CombinatorialFreeModule(QQ, ["a", "b", "c"]); E.rename("E") # needs sage.modules + sage: tensor((E, E, E)) # needs sage.modules E # E # E """ args = tuple(args) # a bit brute force; let's see if this becomes a bottleneck later diff --git a/src/sage/categories/coxeter_group_algebras.py b/src/sage/categories/coxeter_group_algebras.py index 623b1078e60..5cececc3fef 100644 --- a/src/sage/categories/coxeter_group_algebras.py +++ b/src/sage/categories/coxeter_group_algebras.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.combinat, sage.groups +# sage.doctest: needs sage.combinat sage.groups r""" Coxeter Group Algebras """ @@ -168,10 +168,10 @@ def demazure_lusztig_eigenvectors(self, q1, q2): sage: q1, q2 = K.gens() sage: KW = W.algebra(K) sage: E = KW.demazure_lusztig_eigenvectors(q1,q2) - sage: E.keys() + sage: E.keys() # needs sage.rings.number_field Weyl Group of type ['B', 2] (as a matrix group acting on the ambient space) sage: w = W.an_element() - sage: E[w] + sage: E[w] # needs sage.rings.number_field (q2/(-q1+q2))*2121 + ((-q2)/(-q1+q2))*121 - 212 + 12 """ W = self.basis().keys() diff --git a/src/sage/categories/coxeter_groups.py b/src/sage/categories/coxeter_groups.py index a131c61427e..0358d51b137 100644 --- a/src/sage/categories/coxeter_groups.py +++ b/src/sage/categories/coxeter_groups.py @@ -53,21 +53,21 @@ class CoxeterGroups(Category_singleton): Here are some further examples:: - sage: FiniteCoxeterGroups().example() # optional - sage.combinat sage.groups + sage: FiniteCoxeterGroups().example() The 5-th dihedral group of order 10 - sage: FiniteWeylGroups().example() # optional - sage.combinat sage.groups + sage: FiniteWeylGroups().example() The symmetric group on {0, ..., 3} - sage: WeylGroup(["B", 3]) # optional - sage.combinat sage.groups + sage: WeylGroup(["B", 3]) # needs sage.combinat sage.groups Weyl Group of type ['B', 3] (as a matrix group acting on the ambient space) - sage: S4 = SymmetricGroup(4); S4 # optional - sage.groups + sage: S4 = SymmetricGroup(4); S4 # needs sage.groups Symmetric group of order 4! as a permutation group - sage: S4 in CoxeterGroups().Finite() # optional - sage.groups + sage: S4 in CoxeterGroups().Finite() # needs sage.groups True Those will eventually be also in this category:: - sage: DihedralGroup(5) # optional - sage.groups + sage: DihedralGroup(5) # needs sage.groups Dihedral group of order 10 as a permutation group .. TODO:: add a demo of usual computations on Coxeter groups. @@ -97,7 +97,7 @@ class CoxeterGroups(Category_singleton): TESTS:: sage: W = CoxeterGroups().example() - sage: TestSuite(W).run() # optional - sage.combinat + sage: TestSuite(W).run() """ def super_categories(self): @@ -136,8 +136,8 @@ def coxeter_matrix(self): EXAMPLES:: - sage: G = WeylGroup(['A', 3]) # optional - sage.combinat sage.groups - sage: G.coxeter_matrix() # optional - sage.combinat sage.groups + sage: G = WeylGroup(['A', 3]) # needs sage.combinat sage.groups + sage: G.coxeter_matrix() # needs sage.combinat sage.groups [1 3 2] [3 1 3] [2 3 1] @@ -150,14 +150,15 @@ def index_set(self): EXAMPLES:: - sage: W = CoxeterGroup([[1,3],[3,1]]) # optional - sage.combinat sage.groups - sage: W.index_set() # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = CoxeterGroup([[1,3],[3,1]]) + sage: W.index_set() (1, 2) - sage: W = CoxeterGroup([[1,3],[3,1]], index_set=['x', 'y']) # optional - sage.combinat sage.groups - sage: W.index_set() # optional - sage.combinat sage.groups + sage: W = CoxeterGroup([[1,3],[3,1]], index_set=['x', 'y']) + sage: W.index_set() ('x', 'y') - sage: W = CoxeterGroup(['H', 3]) # optional - sage.combinat sage.groups - sage: W.index_set() # optional - sage.combinat sage.groups + sage: W = CoxeterGroup(['H', 3]) + sage: W.index_set() (1, 2, 3) """ return self.coxeter_matrix().index_set() @@ -168,18 +169,19 @@ def coxeter_diagram(self): EXAMPLES:: - sage: W = CoxeterGroup(['H', 3], implementation="reflection") # optional - sage.combinat sage.groups - sage: G = W.coxeter_diagram(); G # optional - sage.combinat sage.groups sage.graphs + sage: # needs sage.combinat sage.graphs sage.groups + sage: W = CoxeterGroup(['H', 3], implementation="reflection") + sage: G = W.coxeter_diagram(); G Graph on 3 vertices - sage: G.edges(sort=True) # optional - sage.combinat sage.groups sage.graphs + sage: G.edges(sort=True) [(1, 2, 3), (2, 3, 5)] - sage: CoxeterGroup(G) is W # optional - sage.combinat sage.groups sage.graphs + sage: CoxeterGroup(G) is W True - sage: G = Graph([(0, 1, 3), (1, 2, oo)]) # optional - sage.combinat sage.groups sage.graphs - sage: W = CoxeterGroup(G) # optional - sage.combinat sage.groups sage.graphs - sage: W.coxeter_diagram() == G # optional - sage.combinat sage.groups sage.graphs + sage: G = Graph([(0, 1, 3), (1, 2, oo)]) + sage: W = CoxeterGroup(G) + sage: W.coxeter_diagram() == G True - sage: CoxeterGroup(W.coxeter_diagram()) is W # optional - sage.combinat sage.groups sage.graphs + sage: CoxeterGroup(W.coxeter_diagram()) is W True """ return self.coxeter_matrix().coxeter_graph() @@ -190,8 +192,8 @@ def coxeter_type(self): EXAMPLES:: - sage: W = CoxeterGroup(['H', 3]) # optional - sage.combinat sage.groups - sage: W.coxeter_type() # optional - sage.combinat sage.groups + sage: W = CoxeterGroup(['H', 3]) # needs sage.combinat sage.groups + sage: W.coxeter_type() # needs sage.combinat sage.groups Coxeter type of ['H', 3] """ return self.coxeter_matrix().coxeter_type() @@ -203,12 +205,12 @@ def braid_relations(self): EXAMPLES:: - sage: W = WeylGroup(["A", 2]) # optional - sage.combinat sage.groups - sage: W.braid_relations() # optional - sage.combinat sage.groups + sage: W = WeylGroup(["A", 2]) # needs sage.combinat sage.groups + sage: W.braid_relations() # needs sage.combinat sage.groups [[[1, 2, 1], [2, 1, 2]]] - sage: W = WeylGroup(["B", 3]) # optional - sage.combinat sage.groups - sage: W.braid_relations() # optional - sage.combinat sage.groups + sage: W = WeylGroup(["B", 3]) # needs sage.combinat sage.groups + sage: W.braid_relations() # needs sage.combinat sage.groups [[[1, 2, 1], [2, 1, 2]], [[1, 3], [3, 1]], [[2, 3, 2, 3], [3, 2, 3, 2]]] """ rels = [] @@ -228,12 +230,12 @@ def braid_group_as_finitely_presented_group(self): EXAMPLES:: - sage: W = CoxeterGroup(['A', 2]) # optional - sage.combinat sage.groups - sage: W.braid_group_as_finitely_presented_group() # optional - sage.combinat sage.groups + sage: W = CoxeterGroup(['A', 2]) # needs sage.combinat sage.groups + sage: W.braid_group_as_finitely_presented_group() # needs sage.combinat sage.groups Finitely presented group < S1, S2 | S1*S2*S1*S2^-1*S1^-1*S2^-1 > - sage: W = WeylGroup(['B', 2]) # optional - sage.combinat sage.groups - sage: W.braid_group_as_finitely_presented_group() # optional - sage.combinat sage.groups + sage: W = WeylGroup(['B', 2]) # needs sage.combinat sage.groups + sage: W.braid_group_as_finitely_presented_group() # needs sage.combinat sage.groups Finitely presented group < S1, S2 | (S1*S2)^2*(S1^-1*S2^-1)^2 > sage: W = ReflectionGroup(['B',3], index_set=["AA","BB","5"]) # optional - gap3 @@ -271,7 +273,7 @@ def braid_orbit_iter(self, word): EXAMPLES:: sage: W = CoxeterGroups().example() - sage: sorted(W.braid_orbit_iter([0, 1, 2, 1])) # optional - sage.combinat sage.groups + sage: sorted(W.braid_orbit_iter([0, 1, 2, 1])) # needs sage.combinat sage.graphs [[0, 1, 2, 1], [0, 2, 1, 2], [2, 0, 1, 2]] """ word = list(word) @@ -326,15 +328,16 @@ def braid_orbit(self, word): sage: word = w.reduced_word(); word [0, 1, 2, 1] - sage: sorted(W.braid_orbit(word)) # optional - sage.combinat sage.groups + sage: sorted(W.braid_orbit(word)) # needs sage.combinat sage.graphs [[0, 1, 2, 1], [0, 2, 1, 2], [2, 0, 1, 2]] - sage: sorted(W.braid_orbit([2,1,1,2,1])) # optional - sage.combinat sage.groups + sage: sorted(W.braid_orbit([2,1,1,2,1])) # needs sage.combinat sage.graphs [[1, 2, 1, 1, 2], [2, 1, 1, 2, 1], [2, 1, 2, 1, 2], [2, 2, 1, 2, 2]] - sage: W = ReflectionGroup(['A',3], index_set=["AA","BB","5"]) # optional - gap3 - sage: w = W.long_element() # optional - gap3 - sage: W.braid_orbit(w.reduced_word()) # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',3], index_set=["AA","BB","5"]) + sage: w = W.long_element() + sage: W.braid_orbit(w.reduced_word()) [['BB', '5', 'AA', 'BB', '5', 'AA'], ['5', 'BB', '5', 'AA', 'BB', '5'], ['BB', 'AA', 'BB', '5', 'BB', 'AA'], @@ -382,17 +385,18 @@ def __iter__(self): (2, 1, 2), (2, 1, 2, 1)] - sage: W = WeylGroup(["A", 2, 1]) # optional - sage.combinat sage.groups - sage: g = iter(W) # optional - sage.combinat sage.groups - sage: next(g) # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = WeylGroup(["A", 2, 1]) + sage: g = iter(W) + sage: next(g) [1 0 0] [0 1 0] [0 0 1] - sage: next(g) # optional - sage.combinat sage.groups + sage: next(g) [-1 1 1] [ 0 1 0] [ 0 0 1] - sage: next(g) # optional - sage.combinat sage.groups + sage: next(g) [ 1 0 0] [ 1 -1 1] [ 0 0 1] @@ -405,19 +409,20 @@ def _element_constructor_(self, x, **args): EXAMPLES:: - sage: W1 = WeylGroup("G2", prefix="s") # optional - sage.combinat sage.groups - sage: W2 = CoxeterGroup("G2") # optional - sage.combinat sage.groups - sage: W3 = CoxeterGroup("G2", implementation="permutation") # optional - sage.combinat sage.groups - sage: W1(W2.an_element()) # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W1 = WeylGroup("G2", prefix="s") + sage: W2 = CoxeterGroup("G2") + sage: W3 = CoxeterGroup("G2", implementation="permutation") + sage: W1(W2.an_element()) s1*s2 - sage: W2(W1.an_element()) # optional - sage.combinat sage.groups + sage: W2(W1.an_element()) [ 2 -a] [ a -1] - sage: W1(W3.an_element()) # optional - sage.combinat sage.groups + sage: W1(W3.an_element()) s1*s2 - sage: s1, s2 = W1.simple_reflections() # optional - sage.combinat sage.groups - sage: W = CoxeterGroup("A1") # optional - sage.combinat sage.groups - sage: W(s1 * s2) # optional - sage.combinat sage.groups + sage: s1, s2 = W1.simple_reflections() + sage: W = CoxeterGroup("A1") + sage: W(s1 * s2) Traceback (most recent call last): ... ValueError: inconsistent number of rows: should be 1 but got 3 @@ -455,9 +460,9 @@ def weak_order_ideal(self, predicate, side="right", category=None): We now consider an infinite Coxeter group:: - sage: W = WeylGroup(["A",1,1]) - sage: I = W.weak_order_ideal(predicate = lambda w: w.length() <= 2) - sage: list(iter(I)) + sage: W = WeylGroup(["A",1,1]) # needs sage.groups sage.rings.number_field + sage: I = W.weak_order_ideal(predicate=lambda w: w.length() <= 2) # needs sage.groups sage.rings.number_field + sage: list(iter(I)) # needs sage.groups sage.rings.number_field [ [1 0] [-1 2] [ 1 0] [ 3 -2] [-1 2] [0 1], [ 0 1], [ 2 -1], [ 2 -1], [-2 3] @@ -466,17 +471,17 @@ def weak_order_ideal(self, predicate, side="right", category=None): Even when the result is finite, some features of :class:`FiniteEnumeratedSets` are not available:: - sage: I.cardinality() # todo: not implemented + sage: I.cardinality() # todo: not implemented 5 - sage: list(I) # todo: not implemented + sage: list(I) # todo: not implemented unless this finiteness is explicitly specified:: - sage: I = W.weak_order_ideal(predicate = lambda w: w.length() <= 2, - ....: category = FiniteEnumeratedSets()) - sage: I.cardinality() + sage: I = W.weak_order_ideal(predicate=lambda w: w.length() <= 2, # needs sage.groups sage.rings.number_field + ....: category=FiniteEnumeratedSets()) + sage: I.cardinality() # needs sage.groups sage.rings.number_field 5 - sage: list(I) + sage: list(I) # needs sage.groups sage.rings.number_field [ [1 0] [-1 2] [ 1 0] [ 3 -2] [-1 2] [0 1], [ 0 1], [ 2 -1], [ 2 -1], [-2 3] @@ -499,8 +504,8 @@ def weak_order_ideal(self, predicate, side="right", category=None): We iterate over each level (i.e., breadth-first-search in the search forest), see :trac:`19926`:: - sage: W = CoxeterGroup(['A',2]) - sage: [x.length() for x in W] + sage: W = CoxeterGroup(['A',2]) # needs sage.groups sage.rings.number_field + sage: [x.length() for x in W] # needs sage.groups sage.rings.number_field [0, 1, 1, 2, 2, 3] """ from sage.sets.recursively_enumerated_set import RecursivelyEnumeratedSet_forest @@ -539,17 +544,18 @@ def coxeter_element(self): EXAMPLES:: - sage: CoxeterGroup(['A', 4]).coxeter_element().reduced_word() # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: CoxeterGroup(['A', 4]).coxeter_element().reduced_word() [1, 2, 3, 4] - sage: CoxeterGroup(['B', 4]).coxeter_element().reduced_word() # optional - sage.combinat sage.groups + sage: CoxeterGroup(['B', 4]).coxeter_element().reduced_word() [1, 2, 3, 4] - sage: CoxeterGroup(['D', 4]).coxeter_element().reduced_word() # optional - sage.combinat sage.groups + sage: CoxeterGroup(['D', 4]).coxeter_element().reduced_word() [1, 2, 4, 3] - sage: CoxeterGroup(['F', 4]).coxeter_element().reduced_word() # optional - sage.combinat sage.groups + sage: CoxeterGroup(['F', 4]).coxeter_element().reduced_word() [1, 2, 3, 4] - sage: CoxeterGroup(['E', 8]).coxeter_element().reduced_word() # optional - sage.combinat sage.groups + sage: CoxeterGroup(['E', 8]).coxeter_element().reduced_word() [1, 3, 2, 4, 5, 6, 7, 8] - sage: CoxeterGroup(['H', 3]).coxeter_element().reduced_word() # optional - sage.combinat sage.groups + sage: CoxeterGroup(['H', 3]).coxeter_element().reduced_word() [1, 2, 3] This method is also used for well generated finite complex @@ -573,9 +579,9 @@ def coxeter_element(self): TESTS:: - sage: WeylGroup(['A', 4]).coxeter_element().reduced_word() # optional - sage.combinat sage.groups + sage: WeylGroup(['A', 4]).coxeter_element().reduced_word() # needs sage.combinat sage.groups [1, 2, 3, 4] - sage: SymmetricGroup(3).coxeter_element() # optional - sage.combinat sage.groups + sage: SymmetricGroup(3).coxeter_element() # needs sage.groups (1,3,2) """ return self.prod(self.simple_reflections()) @@ -603,24 +609,24 @@ class is not unique and we only obtain one such class. TESTS:: - sage: W = SymmetricGroup(3) # optional - sage.combinat sage.groups - sage: sorted(W.standard_coxeter_elements()) # optional - sage.combinat sage.groups + sage: W = SymmetricGroup(3) # needs sage.groups + sage: sorted(W.standard_coxeter_elements()) # needs sage.combinat sage.groups [(1,2,3), (1,3,2)] - sage: W = Permutations(3) # optional - sage.combinat sage.groups - sage: sorted(W.standard_coxeter_elements()) # optional - sage.combinat sage.groups + sage: W = Permutations(3) + sage: sorted(W.standard_coxeter_elements()) # needs sage.graphs [[2, 3, 1], [3, 1, 2]] - sage: W = CoxeterGroup(['D', 3]) # optional - sage.combinat sage.groups - sage: sorted(W.standard_coxeter_elements()) # optional - sage.combinat sage.groups + sage: W = CoxeterGroup(['D', 3]) # needs sage.combinat sage.groups + sage: sorted(W.standard_coxeter_elements()) # needs sage.combinat sage.groups [ [-1 1 1] [ 0 -1 1] [ 0 1 -1] [ 1 -1 -1] [-1 0 1] [ 1 -1 0] [ 0 0 -1] [ 1 -1 0] [-1 1 0], [ 0 -1 0], [ 1 0 -1], [ 1 0 -1] ] - sage: W = ColoredPermutations(3,2) # optional - sage.combinat sage.groups - sage: len(W.standard_coxeter_elements()) # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(3,2) # needs sage.combinat + sage: len(W.standard_coxeter_elements()) # needs sage.combinat sage.graphs 2 """ if not self.is_irreducible() or not self.is_well_generated(): @@ -670,7 +676,7 @@ def fully_commutative_elements(self): EXAMPLES:: - sage: CoxeterGroup(['A', 3]).fully_commutative_elements() # optional - sage.combinat sage.groups + sage: CoxeterGroup(['A', 3]).fully_commutative_elements() # needs sage.combinat sage.groups Fully commutative elements of Finite Coxeter group over Integer Ring with Coxeter matrix: [1 3 2] @@ -767,9 +773,10 @@ def kazhdan_lusztig_cells(self, side='left'): representation of elements in the output cells but not the method used for the cell computation:: - sage: W = CoxeterGroup('A2') # optional - sage.combinat sage.groups - sage: KL_cells = W.kazhdan_lusztig_cells(side='right') # optional - sage.combinat sage.groups - sage: set([tuple(sorted(C, key=lambda w: w.reduced_word())) # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = CoxeterGroup('A2') + sage: KL_cells = W.kazhdan_lusztig_cells(side='right') + sage: set([tuple(sorted(C, key=lambda w: w.reduced_word())) ....: for C in KL_cells]) {( [-1 1] [ 0 -1] @@ -787,11 +794,11 @@ def kazhdan_lusztig_cells(self, side='left'): [ 1 0] [-1 1] [ 1 -1], [-1 0] )} - sage: len(KL_cells) # optional - sage.combinat sage.groups + sage: len(KL_cells) 4 - sage: W = CoxeterGroup('A2', implementation='permutation') # optional - sage.combinat sage.groups - sage: len(W.kazhdan_lusztig_cells(side='right')) # optional - sage.combinat sage.groups + sage: W = CoxeterGroup('A2', implementation='permutation') # needs sage.combinat sage.groups + sage: len(W.kazhdan_lusztig_cells(side='right')) # needs sage.combinat sage.groups 4 We compute the left cells in the Coxeter group of type `A_3` @@ -799,9 +806,10 @@ def kazhdan_lusztig_cells(self, side='left'): runs in the background even if the group is not created with the ``'coxeter3'`` implementation:: - sage: W = CoxeterGroup('A3', implementation='coxeter3') # optional - coxeter3 - sage: KL_cells = W.kazhdan_lusztig_cells() # optional - coxeter3 - sage: set([tuple(sorted(C)) for C in KL_cells]) # optional - coxeter3 + sage: # optional - coxeter3, needs sage.combinat sage.groups sage.libs.gap sage.modules sage.rings.number_field + sage: W = CoxeterGroup('A3', implementation='coxeter3') + sage: KL_cells = W.kazhdan_lusztig_cells() + sage: set([tuple(sorted(C)) for C in KL_cells]) {([],), ([1], [2, 1], [3, 2, 1]), ([1, 2], [2], [3, 2]), @@ -812,20 +820,20 @@ def kazhdan_lusztig_cells(self, side='left'): ([1, 2, 3], [2, 3], [3]), ([1, 3], [2, 1, 3]), ([1, 3, 2], [2, 1, 3, 2])} - sage: len(KL_cells) # optional - coxeter3 + sage: len(KL_cells) 10 - - sage: W = CoxeterGroup('A3', implementation='permutation') # optional - coxeter3 - sage: len(W.kazhdan_lusztig_cells()) # optional - coxeter3 + sage: W = CoxeterGroup('A3', implementation='permutation') + sage: len(W.kazhdan_lusztig_cells()) 10 Computing the two sided cells in `B_3`:: - sage: W = CoxeterGroup('B3', implementation='coxeter3') # optional - coxeter3 - sage: b3_cells = W.kazhdan_lusztig_cells('two-sided') # optional - coxeter3 - sage: len(b3_cells) # optional - coxeter3 + sage: # optional - coxeter3, needs sage.combinat sage.groups sage.libs.gap sage.modules sage.rings.number_field + sage: W = CoxeterGroup('B3', implementation='coxeter3') + sage: b3_cells = W.kazhdan_lusztig_cells('two-sided') + sage: len(b3_cells) 6 - sage: set([tuple(sorted(C)) # optional - coxeter3 + sage: set([tuple(sorted(C)) ....: for C in W.kazhdan_lusztig_cells()]) {([],), ([1], [1, 2, 3, 2, 1], [2, 1], [2, 3, 2, 1], [3, 2, 1]), @@ -855,8 +863,8 @@ def kazhdan_lusztig_cells(self, side='left'): TESTS:: - sage: W = CoxeterGroup(['A', 2, 1]) # optional - sage.combinat sage.groups - sage: W.kazhdan_lusztig_cells() # optional - sage.combinat sage.groups + sage: W = CoxeterGroup(['A', 2, 1]) # needs sage.combinat sage.groups + sage: W.kazhdan_lusztig_cells() # needs sage.combinat sage.groups Traceback (most recent call last): ... ValueError: the Coxeter group must be finite to compute Kazhdan--Lusztig cells @@ -939,8 +947,8 @@ def sign_representation(self, base_ring=None, side="twosided"): EXAMPLES:: - sage: W = WeylGroup(["A", 1, 1]) # optional - sage.combinat sage.groups - sage: W.sign_representation() # optional - sage.combinat sage.groups + sage: W = WeylGroup(["A", 1, 1]) # needs sage.combinat sage.groups + sage: W.sign_representation() # needs sage.combinat sage.groups Sign representation of Weyl Group of type ['A', 1, 1] (as a matrix group acting on the root space) over Integer Ring @@ -967,18 +975,18 @@ def demazure_product(self, Q): EXAMPLES:: - sage: W = WeylGroup(['A', 2]) # optional - sage.combinat sage.groups - sage: w = W.demazure_product([2,2,1]) # optional - sage.combinat sage.groups - sage: w.reduced_word() # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = WeylGroup(['A', 2]) + sage: w = W.demazure_product([2,2,1]) + sage: w.reduced_word() [2, 1] - - sage: w = W.demazure_product([2,1,2,1,2]) # optional - sage.combinat sage.groups - sage: w.reduced_word() # optional - sage.combinat sage.groups + sage: w = W.demazure_product([2,1,2,1,2]) + sage: w.reduced_word() [1, 2, 1] - sage: W = WeylGroup(['B', 2]) # optional - sage.combinat sage.groups - sage: w = W.demazure_product([2,1,2,1,2]) # optional - sage.combinat sage.groups - sage: w.reduced_word() # optional - sage.combinat sage.groups + sage: W = WeylGroup(['B', 2]) # needs sage.combinat sage.groups + sage: w = W.demazure_product([2,1,2,1,2]) # needs sage.combinat sage.groups + sage: w.reduced_word() # needs sage.combinat sage.groups [2, 1, 2, 1] """ return self.one().apply_demazure_product(Q) @@ -989,16 +997,16 @@ def bruhat_interval(self, x, y): EXAMPLES:: - sage: W = WeylGroup("A3", prefix="s") # optional - sage.combinat sage.groups - sage: s1, s2, s3 = W.simple_reflections() # optional - sage.combinat sage.groups - sage: W.bruhat_interval(s2, s1*s3*s2*s1*s3) # optional - sage.combinat sage.groups + sage: W = WeylGroup("A3", prefix="s") # needs sage.combinat sage.groups + sage: s1, s2, s3 = W.simple_reflections() # needs sage.combinat sage.groups + sage: W.bruhat_interval(s2, s1*s3*s2*s1*s3) # needs sage.combinat sage.groups [s1*s2*s3*s2*s1, s2*s3*s2*s1, s3*s1*s2*s1, s1*s2*s3*s1, s1*s2*s3*s2, s3*s2*s1, s2*s3*s1, s2*s3*s2, s1*s2*s1, s3*s1*s2, s1*s2*s3, s2*s1, s3*s2, s2*s3, s1*s2, s2] - sage: W = WeylGroup(['A', 2, 1], prefix="s") # optional - sage.combinat sage.groups - sage: s0, s1, s2 = W.simple_reflections() # optional - sage.combinat sage.groups - sage: W.bruhat_interval(1, s0*s1*s2) # optional - sage.combinat sage.groups + sage: W = WeylGroup(['A', 2, 1], prefix="s") # needs sage.combinat sage.groups + sage: s0, s1, s2 = W.simple_reflections() # needs sage.combinat sage.groups + sage: W.bruhat_interval(1, s0*s1*s2) # needs sage.combinat sage.groups [s0*s1*s2, s1*s2, s0*s2, s0*s1, s2, s1, s0, 1] """ if x == 1: @@ -1028,19 +1036,19 @@ def bruhat_interval_poset(self, x, y, facade=False): EXAMPLES:: - sage: W = WeylGroup("A3", prefix="s") # optional - sage.combinat sage.groups - sage: s1, s2, s3 = W.simple_reflections() # optional - sage.combinat sage.groups - sage: W.bruhat_interval_poset(s2, s1*s3*s2*s1*s3) # optional - sage.combinat sage.groups + sage: W = WeylGroup("A3", prefix="s") # needs sage.combinat sage.groups + sage: s1, s2, s3 = W.simple_reflections() # needs sage.combinat sage.groups + sage: W.bruhat_interval_poset(s2, s1*s3*s2*s1*s3) # needs sage.combinat sage.groups Finite poset containing 16 elements - sage: W = WeylGroup(['A', 2, 1], prefix="s") # optional - sage.combinat sage.groups - sage: s0, s1, s2 = W.simple_reflections() # optional - sage.combinat sage.groups - sage: W.bruhat_interval_poset(1, s0*s1*s2) # optional - sage.combinat sage.groups + sage: W = WeylGroup(['A', 2, 1], prefix="s") # needs sage.combinat sage.groups + sage: s0, s1, s2 = W.simple_reflections() # needs sage.combinat sage.groups + sage: W.bruhat_interval_poset(1, s0*s1*s2) # needs sage.combinat sage.groups Finite poset containing 8 elements TESTS:: - sage: W.bruhat_interval_poset(s0*s1*s2, s0*s1*s2) # optional - sage.combinat sage.groups + sage: W.bruhat_interval_poset(s0*s1*s2, s0*s1*s2) # needs sage.combinat sage.groups Finite poset containing 1 elements """ if x == 1: @@ -1095,27 +1103,27 @@ def bruhat_graph(self, x=None, y=None, edge_labels=False): EXAMPLES:: - sage: W = CoxeterGroup(['H', 3]) # optional - sage.combinat sage.groups sage.graphs - sage: G = W.bruhat_graph(); G # optional - sage.combinat sage.groups sage.graphs + sage: W = CoxeterGroup(['H', 3]) # needs sage.combinat sage.graphs sage.groups + sage: G = W.bruhat_graph(); G # needs sage.combinat sage.graphs sage.groups Digraph on 120 vertices - sage: W = CoxeterGroup(['A', 2, 1]) # optional - sage.combinat sage.groups sage.graphs - sage: s1, s2, s3 = W.simple_reflections() # optional - sage.combinat sage.groups sage.graphs - sage: W.bruhat_graph(s1, s1*s3*s2*s3) # optional - sage.combinat sage.groups sage.graphs + sage: # needs sage.combinat sage.graphs sage.groups + sage: W = CoxeterGroup(['A', 2, 1]) + sage: s1, s2, s3 = W.simple_reflections() + sage: W.bruhat_graph(s1, s1*s3*s2*s3) Digraph on 6 vertices - - sage: W.bruhat_graph(s1, s3*s2*s3) # optional - sage.combinat sage.groups sage.graphs + sage: W.bruhat_graph(s1, s3*s2*s3) Digraph on 0 vertices - sage: W = WeylGroup("A3", prefix="s") # optional - sage.combinat sage.groups sage.graphs - sage: s1, s2, s3 = W.simple_reflections() # optional - sage.combinat sage.groups sage.graphs - sage: G = W.bruhat_graph(s1*s3, s1*s2*s3*s2*s1); G # optional - sage.combinat sage.groups sage.graphs + sage: W = WeylGroup("A3", prefix="s") # needs sage.combinat sage.graphs sage.groups + sage: s1, s2, s3 = W.simple_reflections() # needs sage.combinat sage.graphs sage.groups + sage: G = W.bruhat_graph(s1*s3, s1*s2*s3*s2*s1); G # needs sage.combinat sage.graphs sage.groups Digraph on 10 vertices Check that the graph has the correct number of edges (see :trac:`17744`):: - sage: len(G.edges(sort=False)) # optional - sage.combinat sage.groups sage.graphs + sage: len(G.edges(sort=False)) # needs sage.combinat sage.graphs sage.groups 16 """ if x is None or x == 1: @@ -1163,8 +1171,8 @@ def canonical_representation(self): EXAMPLES:: - sage: W = WeylGroup("A3") # optional - sage.combinat sage.groups - sage: W.canonical_representation() # optional - sage.combinat sage.groups + sage: W = WeylGroup("A3") # needs sage.combinat sage.groups + sage: W.canonical_representation() # needs sage.combinat sage.groups Finite Coxeter group over Integer Ring with Coxeter matrix: [1 3 2] [3 1 3] @@ -1180,16 +1188,16 @@ def elements_of_length(self, n): EXAMPLES:: - sage: A = AffinePermutationGroup(['A', 2, 1]) # optional - sage.combinat sage.groups - sage: [len(list(A.elements_of_length(i))) for i in [0..5]] # optional - sage.combinat sage.groups + sage: A = AffinePermutationGroup(['A', 2, 1]) # needs sage.combinat + sage: [len(list(A.elements_of_length(i))) for i in [0..5]] # needs sage.combinat [1, 3, 6, 9, 12, 15] - sage: W = CoxeterGroup(['H', 3]) # optional - sage.combinat sage.groups - sage: [len(list(W.elements_of_length(i))) for i in range(4)] # optional - sage.combinat sage.groups + sage: W = CoxeterGroup(['H', 3]) # needs sage.combinat sage.groups + sage: [len(list(W.elements_of_length(i))) for i in range(4)] # needs sage.combinat sage.groups [1, 3, 5, 7] - sage: W = CoxeterGroup(['A', 2]) # optional - sage.combinat sage.groups - sage: [len(list(W.elements_of_length(i))) for i in range(6)] # optional - sage.combinat sage.groups + sage: W = CoxeterGroup(['A', 2]) # needs sage.combinat sage.groups + sage: [len(list(W.elements_of_length(i))) for i in range(6)] # needs sage.combinat sage.groups [1, 2, 2, 1, 0, 0] """ I = self.weak_order_ideal(ConstantFunction(True), side='right') @@ -1207,18 +1215,20 @@ def random_element_of_length(self, n): EXAMPLES:: - sage: A = AffinePermutationGroup(['A', 7, 1]) # optional - sage.combinat sage.groups - sage: p = A.random_element_of_length(10) # optional - sage.combinat sage.groups - sage: p in A # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: A = AffinePermutationGroup(['A', 7, 1]) + sage: p = A.random_element_of_length(10) + sage: p in A True - sage: p.length() == 10 # optional - sage.combinat sage.groups + sage: p.length() == 10 True - sage: W = CoxeterGroup(['A', 4]) # optional - sage.combinat sage.groups - sage: p = W.random_element_of_length(5) # optional - sage.combinat sage.groups - sage: p in W # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = CoxeterGroup(['A', 4]) + sage: p = W.random_element_of_length(5) + sage: p in W True - sage: p.length() == 5 # optional - sage.combinat sage.groups + sage: p.length() == 5 True """ from sage.misc.prandom import randint @@ -1270,14 +1280,15 @@ def _test_has_descent(self, **options): sage: W = CoxeterGroups().example() sage: W._test_has_descent() - sage: W = Permutations(4) # optional - sage.combinat sage.groups - sage: W._test_has_descent() # optional - sage.combinat sage.groups - sage: sage.combinat.permutation.Permutations.options.mult = "r2l" # optional - sage.combinat sage.groups - sage: W._test_has_descent() # optional - sage.combinat sage.groups - sage: sage.combinat.permutation.Permutations.options._reset() # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = Permutations(4) + sage: W._test_has_descent() + sage: sage.combinat.permutation.Permutations.options.mult = "r2l" + sage: W._test_has_descent() + sage: sage.combinat.permutation.Permutations.options._reset() - sage: W = SignedPermutations(3) # optional - sage.combinat sage.groups - sage: W._test_has_descent() # optional - sage.combinat sage.groups + sage: W = SignedPermutations(3) # needs sage.combinat + sage: W._test_has_descent() """ tester = self._tester(**options) s = self.simple_reflections() @@ -1334,21 +1345,22 @@ def _test_coxeter_relations(self, **options): TESTS:: - sage: A = AffinePermutationGroup(['A', 7, 1]) # optional - sage.combinat sage.groups - sage: A._test_coxeter_relations() # optional - sage.combinat sage.groups + sage: A = AffinePermutationGroup(['A', 7, 1]) # needs sage.combinat + sage: A._test_coxeter_relations() # needs sage.combinat - sage: cm = CartanMatrix([[2,-5,0], [-2,2,-1], [0,-1,2]]) # optional - sage.combinat sage.groups - sage: W = WeylGroup(cm) # optional - sage.combinat sage.groups - sage: W._test_coxeter_relations() # optional - sage.combinat sage.groups + sage: cm = CartanMatrix([[2,-5,0], [-2,2,-1], [0,-1,2]]) # needs sage.graphs + sage: W = WeylGroup(cm) # needs sage.combinat sage.graphs sage.groups + sage: W._test_coxeter_relations() # needs sage.combinat sage.graphs sage.groups - sage: W = Permutations(4) # optional - sage.combinat sage.groups - sage: W._test_coxeter_relations() # optional - sage.combinat sage.groups - sage: sage.combinat.permutation.Permutations.options.mult = "r2l" # optional - sage.combinat sage.groups - sage: W._test_coxeter_relations() # optional - sage.combinat sage.groups - sage: sage.combinat.permutation.Permutations.options._reset() # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = Permutations(4) + sage: W._test_coxeter_relations() + sage: sage.combinat.permutation.Permutations.options.mult = "r2l" + sage: W._test_coxeter_relations() + sage: sage.combinat.permutation.Permutations.options._reset() - sage: W = SignedPermutations(3) # optional - sage.combinat sage.groups - sage: W._test_coxeter_relations() # optional - sage.combinat sage.groups + sage: W = SignedPermutations(3) # needs sage.combinat + sage: W._test_coxeter_relations() # needs sage.combinat """ tester = self._tester(**options) s = self.simple_reflections() @@ -1569,6 +1581,7 @@ def is_fully_commutative(self) -> bool: EXAMPLES:: + sage: # needs sage.combinat sage.groups sage: W = CoxeterGroup(['A', 3]) sage: len([1 for w in W if w.is_fully_commutative()]) 14 @@ -1578,8 +1591,8 @@ def is_fully_commutative(self) -> bool: TESTS:: - sage: W = CoxeterGroup(matrix(2,2,[1,7,7,1]),index_set='ab') - sage: len([1 for w in W if w.is_fully_commutative()]) + sage: W = CoxeterGroup(matrix(2,2,[1,7,7,1]), index_set='ab') # needs sage.combinat sage.groups + sage: len([1 for w in W if w.is_fully_commutative()]) # needs sage.combinat sage.groups 13 """ word = self.reduced_word() @@ -1680,7 +1693,7 @@ def reduced_words_iter(self): sage: W = CoxeterGroups().example() sage: s = W.simple_reflections() sage: w = s[0] * s[2] - sage: sorted(w.reduced_words_iter()) # optional - sage.combinat + sage: sorted(w.reduced_words_iter()) # needs sage.combinat sage.graphs [[0, 2], [2, 0]] """ return self.parent().braid_orbit_iter(self.reduced_word()) @@ -1705,18 +1718,19 @@ def reduced_words(self): sage: W = CoxeterGroups().example() sage: s = W.simple_reflections() sage: w = s[0] * s[2] - sage: sorted(w.reduced_words()) # optional - sage.combinat + sage: sorted(w.reduced_words()) # needs sage.graphs sage.modules [[0, 2], [2, 0]] - sage: W = WeylGroup(['E', 6]) # optional - sage.combinat sage.groups - sage: w = W.from_reduced_word([2,3,4,2]) # optional - sage.combinat sage.groups - sage: sorted(w.reduced_words()) # optional - sage.combinat sage.groups + sage: W = WeylGroup(['E', 6]) # needs sage.combinat sage.groups + sage: w = W.from_reduced_word([2,3,4,2]) # needs sage.combinat sage.groups + sage: sorted(w.reduced_words()) # needs sage.combinat sage.groups [[2, 3, 4, 2], [3, 2, 4, 2], [3, 4, 2, 4]] - sage: W = ReflectionGroup(['A',3], # optional - gap3 + sage: # optional - gap3, needs sage.combinat sage.groups + sage: W = ReflectionGroup(['A',3], ....: index_set=["AA","BB","5"]) - sage: w = W.long_element() # optional - gap3 - sage: w.reduced_words() # optional - gap3 + sage: w = W.long_element() + sage: w.reduced_words() [['BB', '5', 'AA', 'BB', '5', 'AA'], ['5', 'BB', '5', 'AA', 'BB', '5'], ['BB', 'AA', 'BB', '5', 'BB', 'AA'], @@ -1799,32 +1813,34 @@ def reduced_word_graph(self): EXAMPLES:: - sage: W = WeylGroup(['A', 3], prefix='s') # optional - sage.combinat sage.groups - sage: w0 = W.long_element() # optional - sage.combinat sage.groups - sage: G = w0.reduced_word_graph() # optional - sage.combinat sage.groups sage.graphs - sage: G.num_verts() # optional - sage.combinat sage.groups sage.graphs + sage: # needs sage.combinat sage.graphs sage.groups + sage: W = WeylGroup(['A', 3], prefix='s') + sage: w0 = W.long_element() + sage: G = w0.reduced_word_graph() + sage: G.num_verts() 16 - sage: len(w0.reduced_words()) # optional - sage.combinat sage.groups sage.graphs + sage: len(w0.reduced_words()) 16 - sage: G.num_edges() # optional - sage.combinat sage.groups sage.graphs + sage: G.num_edges() 18 - sage: len([e for e in G.edges(sort=False) if e[2] == 2]) # optional - sage.combinat sage.groups sage.graphs + sage: len([e for e in G.edges(sort=False) if e[2] == 2]) 10 - sage: len([e for e in G.edges(sort=False) if e[2] == 3]) # optional - sage.combinat sage.groups sage.graphs + sage: len([e for e in G.edges(sort=False) if e[2] == 3]) 8 TESTS:: - sage: p = Permutation([3,2,4,1]) # optional - sage.combinat - sage: pp = WeylGroup(['A',3]).from_reduced_word(p.reduced_word()) # optional - sage.combinat sage.groups - sage: pp.reduced_word_graph() # optional - sage.combinat sage.groups sage.graphs + sage: p = Permutation([3,2,4,1]) + sage: pp = WeylGroup(['A',3]).from_reduced_word(p.reduced_word()) # needs sage.combinat sage.groups + sage: pp.reduced_word_graph() # needs sage.combinat sage.graphs sage.groups Graph on 3 vertices - sage: w1 = W.one() # optional - sage.combinat sage.groups - sage: G = w1.reduced_word_graph() # optional - sage.combinat sage.groups sage.graphs - sage: G.num_verts() # optional - sage.combinat sage.groups sage.graphs + sage: # needs sage.combinat sage.graphs sage.groups + sage: w1 = W.one() + sage: G = w1.reduced_word_graph() + sage: G.num_verts() 1 - sage: G.num_edges() # optional - sage.combinat sage.groups sage.graphs + sage: G.num_edges() 0 .. SEEALSO:: @@ -1920,14 +1936,14 @@ def reflection_length(self): EXAMPLES:: - sage: W = WeylGroup(['A', 3]) # optional - sage.combinat sage.groups - sage: s = W.simple_reflections() # optional - sage.combinat sage.groups - sage: (s[1]*s[2]*s[3]).reflection_length() # optional - sage.combinat sage.groups + sage: W = WeylGroup(['A', 3]) # needs sage.combinat sage.groups + sage: s = W.simple_reflections() # needs sage.combinat sage.groups + sage: (s[1]*s[2]*s[3]).reflection_length() # needs sage.combinat sage.groups 3 - sage: W = SymmetricGroup(4) # optional - sage.combinat sage.groups - sage: s = W.simple_reflections() # optional - sage.combinat sage.groups - sage: (s[3]*s[2]*s[3]).reflection_length() # optional - sage.combinat sage.groups + sage: W = SymmetricGroup(4) # needs sage.groups + sage: s = W.simple_reflections() # needs sage.groups + sage: (s[3]*s[2]*s[3]).reflection_length() # needs sage.combinat sage.groups 1 """ @@ -1950,14 +1966,14 @@ def absolute_length(self): EXAMPLES:: - sage: W = WeylGroup(["A", 3]) # optional - sage.combinat sage.groups - sage: s = W.simple_reflections() # optional - sage.combinat sage.groups - sage: (s[1]*s[2]*s[3]).absolute_length() # optional - sage.combinat sage.groups + sage: W = WeylGroup(["A", 3]) # needs sage.combinat sage.groups + sage: s = W.simple_reflections() # needs sage.combinat sage.groups + sage: (s[1]*s[2]*s[3]).absolute_length() # needs sage.combinat sage.groups 3 - sage: W = SymmetricGroup(4) # optional - sage.combinat sage.groups - sage: s = W.simple_reflections() # optional - sage.combinat sage.groups - sage: (s[3]*s[2]*s[1]).absolute_length() # optional - sage.combinat sage.groups + sage: W = SymmetricGroup(4) # needs sage.groups + sage: s = W.simple_reflections() # needs sage.groups + sage: (s[3]*s[2]*s[1]).absolute_length() # needs sage.combinat sage.groups 3 """ M = self.canonical_matrix() @@ -1982,45 +1998,48 @@ def absolute_le(self, other): EXAMPLES:: - sage: W = WeylGroup(["A", 3]) # optional - sage.combinat sage.groups - sage: s = W.simple_reflections() # optional - sage.combinat sage.groups - sage: w0 = s[1] # optional - sage.combinat sage.groups - sage: w1 = s[1]*s[2]*s[3] # optional - sage.combinat sage.groups - sage: w0.absolute_le(w1) # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = WeylGroup(["A", 3]) + sage: s = W.simple_reflections() + sage: w0 = s[1] + sage: w1 = s[1]*s[2]*s[3] + sage: w0.absolute_le(w1) True - sage: w1.absolute_le(w0) # optional - sage.combinat sage.groups + sage: w1.absolute_le(w0) False - sage: w1.absolute_le(w1) # optional - sage.combinat sage.groups + sage: w1.absolute_le(w1) True TESTS: Check that this is independent of the implementation of the group, see :trac:`34799`:: - sage: W1 = WeylGroup(['A', 2]) # optional - sage.combinat sage.groups - sage: W2 = Permutations(3) # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W1 = WeylGroup(['A', 2]) + sage: W2 = Permutations(3) sage: P = lambda pi: W2(list(pi.to_permutation())) - sage: d1 = set((P(w1), P(w2)) for w1 in W1 for w2 in W1 # optional - sage.combinat sage.groups + sage: d1 = set((P(w1), P(w2)) for w1 in W1 for w2 in W1 ....: if w1.absolute_le(w2)) - sage: d2 = set((w1, w2) for w1 in W2 for w2 in W2 # optional - sage.combinat sage.groups + sage: d2 = set((w1, w2) for w1 in W2 for w2 in W2 ....: if w1.absolute_le(w2)) - sage: d1 == d2 # optional - sage.combinat sage.groups + sage: d1 == d2 True - sage: sage.combinat.permutation.Permutations.options.mult = "r2l" # optional - sage.combinat sage.groups - sage: d3 = set((w1, w2) # optional - sage.combinat sage.groups + sage: sage.combinat.permutation.Permutations.options.mult = "r2l" + sage: d3 = set((w1, w2) ....: for w1 in W2 for w2 in W2 if w1.absolute_le(w2)) - sage: d1 == d3 # optional - sage.combinat sage.groups + sage: d1 == d3 True - sage: sage.combinat.permutation.Permutations.options._reset() # optional - sage.combinat sage.groups + sage: sage.combinat.permutation.Permutations.options._reset() - sage: W1 = WeylGroup(['B', 2]) # optional - sage.combinat sage.groups - sage: W2 = SignedPermutations(2) # optional - sage.combinat sage.groups - sage: P = lambda pi: W2(list(pi.to_permutation())) # optional - sage.combinat sage.groups - sage: d1 = set((P(w1), P(w2)) # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W1 = WeylGroup(['B', 2]) + sage: W2 = SignedPermutations(2) + sage: P = lambda pi: W2(list(pi.to_permutation())) + sage: d1 = set((P(w1), P(w2)) ....: for w1 in W1 for w2 in W1 if w1.absolute_le(w2)) - sage: d2 = set((w1, w2) # optional - sage.combinat sage.groups + sage: d2 = set((w1, w2) ....: for w1 in W2 for w2 in W2 if w1.absolute_le(w2)) - sage: d1 == d2 # optional - sage.combinat sage.groups + sage: d1 == d2 True """ if self == other: @@ -2039,11 +2058,12 @@ def absolute_covers(self): EXAMPLES:: - sage: W = WeylGroup(["A", 3]) # optional - sage.combinat sage.groups - sage: s = W.simple_reflections() # optional - sage.combinat sage.groups - sage: w0 = s[1] # optional - sage.combinat sage.groups - sage: w1 = s[1]*s[2]*s[3] # optional - sage.combinat sage.groups - sage: w0.absolute_covers() # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = WeylGroup(["A", 3]) + sage: s = W.simple_reflections() + sage: w0 = s[1] + sage: w1 = s[1]*s[2]*s[3] + sage: w0.absolute_covers() [ [0 0 1 0] [0 1 0 0] [0 1 0 0] [0 0 0 1] [0 1 0 0] [1 0 0 0] [1 0 0 0] [0 0 1 0] [1 0 0 0] [0 0 0 1] @@ -2067,9 +2087,9 @@ def canonical_matrix(self): EXAMPLES:: - sage: W = WeylGroup(["A", 3]) # optional - sage.combinat sage.groups - sage: s = W.simple_reflections() # optional - sage.combinat sage.groups - sage: (s[1]*s[2]*s[3]).canonical_matrix() # optional - sage.combinat sage.groups + sage: W = WeylGroup(["A", 3]) # needs sage.combinat sage.groups + sage: s = W.simple_reflections() # needs sage.combinat sage.groups + sage: (s[1]*s[2]*s[3]).canonical_matrix() # needs sage.combinat sage.groups [ 0 0 -1] [ 1 0 -1] [ 0 1 -1] @@ -2150,15 +2170,17 @@ def apply_simple_projection(self, i, side='right', length_increasing=True): (1, 2, 3, 0) sage: w.apply_simple_projection(2, length_increasing=False) (1, 2, 0, 3) - sage: W = WeylGroup(['C', 4], prefix="s") # optional - sage.combinat sage.groups - sage: v = W.from_reduced_word([1,2,3,4,3,1]) # optional - sage.combinat sage.groups - sage: v # optional - sage.combinat sage.groups + + sage: # needs sage.combinat sage.groups + sage: W = WeylGroup(['C', 4], prefix="s") + sage: v = W.from_reduced_word([1,2,3,4,3,1]) + sage: v s1*s2*s3*s4*s3*s1 - sage: v.apply_simple_projection(2) # optional - sage.combinat sage.groups + sage: v.apply_simple_projection(2) s1*s2*s3*s4*s3*s1*s2 - sage: v.apply_simple_projection(2, side='left') # optional - sage.combinat sage.groups + sage: v.apply_simple_projection(2, side='left') s1*s2*s3*s4*s3*s1 - sage: v.apply_simple_projection(1, length_increasing=False) # optional - sage.combinat sage.groups + sage: v.apply_simple_projection(1, length_increasing=False) s1*s2*s3*s4*s3 """ @@ -2186,15 +2208,16 @@ def binary_factorizations(self, predicate=ConstantFunction(True)): We construct the set of all factorizations of the maximal element of the group:: - sage: W = WeylGroup(['A', 3]) # optional - sage.combinat sage.groups - sage: s = W.simple_reflections() # optional - sage.combinat sage.groups - sage: w0 = W.from_reduced_word([1,2,3,1,2,1]) # optional - sage.combinat sage.groups - sage: w0.binary_factorizations().cardinality() # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = WeylGroup(['A', 3]) + sage: s = W.simple_reflections() + sage: w0 = W.from_reduced_word([1,2,3,1,2,1]) + sage: w0.binary_factorizations().cardinality() 24 The same number of factorizations, by bounded length:: - sage: [w0.binary_factorizations( # optional - sage.combinat sage.groups + sage: [w0.binary_factorizations( # needs sage.combinat sage.groups ....: lambda u: u.length() <= l ....: ).cardinality() ....: for l in [-1,0,1,2,3,4,5,6]] @@ -2203,33 +2226,34 @@ def binary_factorizations(self, predicate=ConstantFunction(True)): The number of factorizations of the elements just below the maximal element:: - sage: [(s[i]*w0).binary_factorizations().cardinality() # optional - sage.combinat sage.groups + sage: [(s[i]*w0).binary_factorizations().cardinality() # needs sage.combinat sage.groups ....: for i in [1,2,3]] [12, 12, 12] - sage: w0.binary_factorizations(lambda u: False).cardinality() # optional - sage.combinat sage.groups + sage: w0.binary_factorizations(lambda u: False).cardinality() # needs sage.combinat sage.groups 0 TESTS:: - sage: w0.binary_factorizations().category() # optional - sage.combinat sage.groups + sage: w0.binary_factorizations().category() # needs sage.combinat sage.groups Category of finite enumerated sets Check that this is independent of the implementation of the group, see :trac:`34799`:: - sage: W1 = WeylGroup(['A', 3]) # optional - sage.combinat sage.groups - sage: W2 = Permutations(4) # optional - sage.combinat sage.groups - sage: P = lambda pi: W2(list(pi.to_permutation())) # optional - sage.combinat sage.groups - sage: d1 = {P(pi): set((P(w[0]), P(w[1])) # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W1 = WeylGroup(['A', 3]) + sage: W2 = Permutations(4) + sage: P = lambda pi: W2(list(pi.to_permutation())) + sage: d1 = {P(pi): set((P(w[0]), P(w[1])) ....: for w in pi.binary_factorizations()) ....: for pi in W1} - sage: d2 = {pi: set(pi.binary_factorizations()) for pi in W2} # optional - sage.combinat sage.groups - sage: d1 == d2 # optional - sage.combinat sage.groups + sage: d2 = {pi: set(pi.binary_factorizations()) for pi in W2} + sage: d1 == d2 True - sage: sage.combinat.permutation.Permutations.options.mult = "r2l" # optional - sage.combinat sage.groups - sage: d3 = {pi: set(pi.binary_factorizations()) for pi in W2} # optional - sage.combinat sage.groups - sage: d1 == d3 # optional - sage.combinat sage.groups + sage: sage.combinat.permutation.Permutations.options.mult = "r2l" + sage: d3 = {pi: set(pi.binary_factorizations()) for pi in W2} + sage: d1 == d3 True - sage: sage.combinat.permutation.Permutations.options._reset() # optional - sage.combinat sage.groups + sage: sage.combinat.permutation.Permutations.options._reset() """ from sage.sets.recursively_enumerated_set import RecursivelyEnumeratedSet_forest W = self.parent() @@ -2259,38 +2283,40 @@ def bruhat_lower_covers(self): EXAMPLES:: - sage: W = WeylGroup(["A", 3]) # optional - sage.combinat sage.groups - sage: w = W.from_reduced_word([3,2,3]) # optional - sage.combinat sage.groups - sage: print([v.reduced_word() for v in w.bruhat_lower_covers()]) # optional - sage.combinat sage.groups + sage: W = WeylGroup(["A", 3]) # needs sage.combinat sage.groups + sage: w = W.from_reduced_word([3,2,3]) # needs sage.combinat sage.groups + sage: print([v.reduced_word() for v in w.bruhat_lower_covers()]) # needs sage.combinat sage.groups [[3, 2], [2, 3]] - sage: W = WeylGroup(["A", 3]) # optional - sage.combinat sage.groups - sage: print([v.reduced_word() # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = WeylGroup(["A", 3]) + sage: print([v.reduced_word() ....: for v in W.simple_reflection(1).bruhat_lower_covers()]) [[]] - sage: print([v.reduced_word() # optional - sage.combinat sage.groups + sage: print([v.reduced_word() ....: for v in W.one().bruhat_lower_covers()]) [] - sage: W = WeylGroup(["B", 4, 1]) # optional - sage.combinat sage.groups - sage: w = W.from_reduced_word([0,2]) # optional - sage.combinat sage.groups - sage: print([v.reduced_word() for v in w.bruhat_lower_covers()]) # optional - sage.combinat sage.groups + sage: W = WeylGroup(["B", 4, 1]) + sage: w = W.from_reduced_word([0,2]) + sage: print([v.reduced_word() for v in w.bruhat_lower_covers()]) [[2], [0]] - sage: W = WeylGroup("A3", prefix="s", implementation="permutation") # optional - sage.combinat sage.groups - sage: s1, s2, s3 = W.simple_reflections() # optional - sage.combinat sage.groups - sage: (s1*s2*s3*s1).bruhat_lower_covers() # optional - sage.combinat sage.groups + sage: W = WeylGroup("A3", prefix="s", implementation="permutation") + sage: s1, s2, s3 = W.simple_reflections() + sage: (s1*s2*s3*s1).bruhat_lower_covers() [s2*s1*s3, s1*s2*s1, s1*s2*s3] We now show how to construct the Bruhat poset:: - sage: W = WeylGroup(["A", 3]) # optional - sage.combinat sage.groups - sage: covers = tuple([u, v] # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = WeylGroup(["A", 3]) + sage: covers = tuple([u, v] ....: for v in W for u in v.bruhat_lower_covers()) - sage: P = Poset((W, covers), cover_relations = True) # optional - sage.combinat sage.groups sage.graphs - sage: P.show() # optional - sage.combinat sage.groups sage.graphs + sage: P = Poset((W, covers), cover_relations=True) # needs sage.graphs + sage: P.show() # needs sage.graphs sage.plot Alternatively, one can just use:: - sage: P = W.bruhat_poset() # optional - sage.combinat sage.groups sage.graphs + sage: P = W.bruhat_poset() # needs sage.combinat sage.graphs sage.groups The algorithm is taken from Stembridge's 'coxeter/weyl' package for Maple. """ @@ -2313,21 +2339,22 @@ def bruhat_upper_covers(self): EXAMPLES:: - sage: W = WeylGroup(['A', 3, 1], prefix="s") # optional - sage.combinat sage.groups - sage: w = W.from_reduced_word([1,2,1]) # optional - sage.combinat sage.groups - sage: w.bruhat_upper_covers() # optional - sage.combinat sage.groups + sage: W = WeylGroup(['A', 3, 1], prefix="s") # needs sage.combinat sage.groups + sage: w = W.from_reduced_word([1,2,1]) # needs sage.combinat sage.groups + sage: w.bruhat_upper_covers() # needs sage.combinat sage.groups [s1*s2*s1*s0, s1*s2*s0*s1, s0*s1*s2*s1, s3*s1*s2*s1, s2*s3*s1*s2, s1*s2*s3*s1] - sage: W = WeylGroup(['A', 3]) # optional - sage.combinat sage.groups - sage: w = W.long_element() # optional - sage.combinat sage.groups - sage: w.bruhat_upper_covers() # optional - sage.combinat sage.groups + sage: W = WeylGroup(['A', 3]) # needs sage.combinat sage.groups + sage: w = W.long_element() # needs sage.combinat sage.groups + sage: w.bruhat_upper_covers() # needs sage.combinat sage.groups [] - sage: W = WeylGroup(['A', 3]) # optional - sage.combinat sage.groups - sage: w = W.from_reduced_word([1,2,1]) # optional - sage.combinat sage.groups - sage: S = [v for v in W if w in v.bruhat_lower_covers()] # optional - sage.combinat sage.groups - sage: C = w.bruhat_upper_covers() # optional - sage.combinat sage.groups - sage: set(S) == set(C) # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = WeylGroup(['A', 3]) + sage: w = W.from_reduced_word([1,2,1]) + sage: S = [v for v in W if w in v.bruhat_lower_covers()] + sage: C = w.bruhat_upper_covers() + sage: set(S) == set(C) True """ Covers = set() @@ -2351,17 +2378,17 @@ def bruhat_lower_covers_reflections(self): EXAMPLES:: - sage: W = WeylGroup(['A', 3], prefix="s") # optional - sage.combinat sage.groups - sage: w = W.from_reduced_word([3,1,2,1]) # optional - sage.combinat sage.groups - sage: w.bruhat_lower_covers_reflections() # optional - sage.combinat sage.groups + sage: W = WeylGroup(['A', 3], prefix="s") # needs sage.combinat sage.groups + sage: w = W.from_reduced_word([3,1,2,1]) # needs sage.combinat sage.groups + sage: w.bruhat_lower_covers_reflections() # needs sage.combinat sage.groups [(s1*s2*s1, s1*s2*s3*s2*s1), (s3*s2*s1, s2), (s3*s1*s2, s1)] TESTS: Check bug discovered in :trac:`32669` is fixed:: - sage: W = CoxeterGroup(['A', 3], implementation='permutation') # optional - sage.combinat sage.groups - sage: W.w0.bruhat_lower_covers_reflections() # optional - sage.combinat sage.groups + sage: W = CoxeterGroup(['A', 3], implementation='permutation') # needs sage.combinat sage.groups + sage: W.w0.bruhat_lower_covers_reflections() # needs sage.combinat sage.groups [((1,3,7,9)(2,11,6,10)(4,8,5,12), (2,5)(3,9)(4,6)(8,11)(10,12)), ((1,11)(3,10)(4,9)(5,7)(6,12), (1,4)(2,8)(3,5)(7,10)(9,11)), ((1,9,7,3)(2,10,6,11)(4,12,5,8), (1,7)(2,4)(5,6)(8,10)(11,12))] @@ -2384,11 +2411,12 @@ def lower_cover_reflections(self, side='right'): EXAMPLES:: - sage: W = WeylGroup(['A', 3],prefix="s") # optional - sage.combinat sage.groups - sage: w = W.from_reduced_word([3,1,2,1]) # optional - sage.combinat sage.groups - sage: w.lower_cover_reflections() # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = WeylGroup(['A', 3],prefix="s") + sage: w = W.from_reduced_word([3,1,2,1]) + sage: w.lower_cover_reflections() [s1*s2*s3*s2*s1, s2, s1] - sage: w.lower_cover_reflections(side='left') # optional - sage.combinat sage.groups + sage: w.lower_cover_reflections(side='left') [s2*s3*s2, s3, s1] """ @@ -2407,9 +2435,9 @@ def bruhat_upper_covers_reflections(self): EXAMPLES:: - sage: W = WeylGroup(['A', 4], prefix="s") # optional - sage.combinat sage.groups - sage: w = W.from_reduced_word([3,1,2,1]) # optional - sage.combinat sage.groups - sage: w.bruhat_upper_covers_reflections() # optional - sage.combinat sage.groups + sage: W = WeylGroup(['A', 4], prefix="s") # needs sage.combinat sage.groups + sage: w = W.from_reduced_word([3,1,2,1]) # needs sage.combinat sage.groups + sage: w.bruhat_upper_covers_reflections() # needs sage.combinat sage.groups [(s1*s2*s3*s2*s1, s3), (s2*s3*s1*s2*s1, s2*s3*s2), (s3*s4*s1*s2*s1, s4), (s4*s3*s1*s2*s1, s1*s2*s3*s4*s3*s2*s1)] """ @@ -2431,11 +2459,12 @@ def cover_reflections(self, side='right'): EXAMPLES:: - sage: W = WeylGroup(['A', 4], prefix="s") # optional - sage.combinat sage.groups - sage: w = W.from_reduced_word([3,1,2,1]) # optional - sage.combinat sage.groups - sage: w.cover_reflections() # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = WeylGroup(['A', 4], prefix="s") + sage: w = W.from_reduced_word([3,1,2,1]) + sage: w.cover_reflections() [s3, s2*s3*s2, s4, s1*s2*s3*s4*s3*s2*s1] - sage: w.cover_reflections(side='left') # optional - sage.combinat sage.groups + sage: w.cover_reflections(side='left') [s4, s2, s1*s2*s1, s3*s4*s3] """ @@ -2456,19 +2485,20 @@ def bruhat_le(self, other): EXAMPLES:: - sage: W = WeylGroup(["A", 3]) # optional - sage.combinat sage.groups - sage: u = W.from_reduced_word([1,2,1]) # optional - sage.combinat sage.groups - sage: v = W.from_reduced_word([1,2,3,2,1]) # optional - sage.combinat sage.groups - sage: u.bruhat_le(u) # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = WeylGroup(["A", 3]) + sage: u = W.from_reduced_word([1,2,1]) + sage: v = W.from_reduced_word([1,2,3,2,1]) + sage: u.bruhat_le(u) True - sage: u.bruhat_le(v) # optional - sage.combinat sage.groups + sage: u.bruhat_le(v) True - sage: v.bruhat_le(u) # optional - sage.combinat sage.groups + sage: v.bruhat_le(u) False - sage: v.bruhat_le(v) # optional - sage.combinat sage.groups + sage: v.bruhat_le(v) True - sage: s = W.simple_reflections() # optional - sage.combinat sage.groups - sage: s[1].bruhat_le(W.one()) # optional - sage.combinat sage.groups + sage: s = W.simple_reflections() + sage: s[1].bruhat_le(W.one()) False The implementation uses the equivalent condition that any @@ -2489,20 +2519,21 @@ def bruhat_le(self, other): We now run consistency tests with permutations and :meth:`bruhat_lower_covers`:: - sage: W = WeylGroup(["A", 3]) # optional - sage.combinat sage.groups - sage: P4 = Permutations(4) # optional - sage.combinat sage.groups + sage: W = WeylGroup(["A", 3]) # needs sage.combinat sage.groups + sage: P4 = Permutations(4) sage: def P4toW(w): return W.from_reduced_word(w.reduced_word()) - sage: for u in P4: # optional - sage.combinat sage.groups + sage: for u in P4: # needs sage.combinat sage.groups ....: for v in P4: ....: assert u.bruhat_lequal(v) == P4toW(u).bruhat_le(P4toW(v)) - sage: W = WeylGroup(["B", 3]) # optional - sage.combinat sage.groups - sage: P = W.bruhat_poset() # This is built from bruhat_lower_covers # optional - sage.combinat sage.groups sage.graphs - sage: Q = Poset((W, attrcall("bruhat_le"))) # long time (10s) # optional - sage.combinat sage.groups sage.graphs - sage: all(u.bruhat_le(v) == P.is_lequal(u,v) # long time (7s) # optional - sage.combinat sage.groups sage.graphs + sage: # needs sage.combinat sage.graphs sage.groups + sage: W = WeylGroup(["B", 3]) + sage: P = W.bruhat_poset() # This is built from bruhat_lower_covers + sage: Q = Poset((W, attrcall("bruhat_le"))) # long time (10s) + sage: all(u.bruhat_le(v) == P.is_lequal(u,v) # long time (7s) ....: for u in W for v in W) True - sage: all(P.is_lequal(u,v) == Q.is_lequal(u,v) # long time (9s) # optional - sage.combinat sage.groups sage.graphs + sage: all(P.is_lequal(u,v) == Q.is_lequal(u,v) # long time (9s) ....: for u in W for v in W) True """ @@ -2532,21 +2563,22 @@ def weak_le(self, other, side='right'): EXAMPLES:: - sage: W = WeylGroup(["A", 3]) # optional - sage.combinat sage.groups - sage: u = W.from_reduced_word([1,2]) # optional - sage.combinat sage.groups - sage: v = W.from_reduced_word([1,2,3,2]) # optional - sage.combinat sage.groups - sage: u.weak_le(u) # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = WeylGroup(["A", 3]) + sage: u = W.from_reduced_word([1,2]) + sage: v = W.from_reduced_word([1,2,3,2]) + sage: u.weak_le(u) True - sage: u.weak_le(v) # optional - sage.combinat sage.groups + sage: u.weak_le(v) True - sage: v.weak_le(u) # optional - sage.combinat sage.groups + sage: v.weak_le(u) False - sage: v.weak_le(v) # optional - sage.combinat sage.groups + sage: v.weak_le(v) True Comparison for left weak order is achieved with the option ``side``:: - sage: u.weak_le(v, side='left') # optional - sage.combinat sage.groups + sage: u.weak_le(v, side='left') # needs sage.combinat sage.groups False The implementation uses the equivalent condition that any @@ -2562,10 +2594,10 @@ def weak_le(self, other, side='right'): We now run consistency tests with permutations:: - sage: W = WeylGroup(["A", 3]) # optional - sage.combinat sage.groups - sage: P4 = Permutations(4) # optional - sage.combinat sage.groups - sage: def P4toW(w): return W.from_reduced_word(w.reduced_word()) # optional - sage.combinat sage.groups - sage: for u in P4: # long time (5s on sage.math, 2011) # optional - sage.combinat sage.groups + sage: W = WeylGroup(["A", 3]) # needs sage.combinat sage.groups + sage: P4 = Permutations(4) + sage: def P4toW(w): return W.from_reduced_word(w.reduced_word()) + sage: for u in P4: # long time (5s on sage.math, 2011), needs sage.combinat sage.groups ....: for v in P4: ....: assert u.permutohedron_lequal(v) == P4toW(u).weak_le(P4toW(v)) ....: assert u.permutohedron_lequal(v, side='left') == P4toW(u).weak_le(P4toW(v), side='left') @@ -2598,29 +2630,30 @@ def weak_covers(self, side='right', index_set=None, positive=False): EXAMPLES:: - sage: W = WeylGroup(['A', 3]) # optional - sage.combinat sage.groups - sage: w = W.from_reduced_word([3,2,1]) # optional - sage.combinat sage.groups - sage: [x.reduced_word() for x in w.weak_covers()] # optional - sage.combinat sage.groups + sage: W = WeylGroup(['A', 3]) # needs sage.combinat sage.groups + sage: w = W.from_reduced_word([3,2,1]) # needs sage.combinat sage.groups + sage: [x.reduced_word() for x in w.weak_covers()] # needs sage.combinat sage.groups [[3, 2]] To obtain instead elements that cover self, set ``positive=True``:: - sage: [x.reduced_word() for x in w.weak_covers(positive=True)] # optional - sage.combinat sage.groups + sage: [x.reduced_word() for x in w.weak_covers(positive=True)] # needs sage.combinat sage.groups [[3, 1, 2, 1], [2, 3, 2, 1]] To obtain covers for left weak order, set the option side to 'left':: - sage: [x.reduced_word() for x in w.weak_covers(side='left')] # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: [x.reduced_word() for x in w.weak_covers(side='left')] [[2, 1]] - sage: w = W.from_reduced_word([3,2,3,1]) # optional - sage.combinat sage.groups - sage: [x.reduced_word() for x in w.weak_covers()] # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([3,2,3,1]) + sage: [x.reduced_word() for x in w.weak_covers()] [[2, 3, 2], [3, 2, 1]] - sage: [x.reduced_word() for x in w.weak_covers(side='left')] # optional - sage.combinat sage.groups + sage: [x.reduced_word() for x in w.weak_covers(side='left')] [[3, 2, 1], [2, 3, 1]] Covers w.r.t. a parabolic subgroup are obtained with the option ``index_set``:: - sage: [x.reduced_word() for x in w.weak_covers(index_set=[1,2])] # optional - sage.combinat sage.groups + sage: [x.reduced_word() for x in w.weak_covers(index_set=[1,2])] # needs sage.combinat sage.groups [[2, 3, 2]] """ return [self.apply_simple_reflection(i, side=side) @@ -2704,19 +2737,19 @@ def is_coxeter_sortable(self, c, sorting_word=None): sage: w.is_coxeter_sortable(c) True - sage: W = CoxeterGroup(['A', 3]) # optional - sage.combinat sage.groups - sage: c = W.from_reduced_word([1,2,3]) # optional - sage.combinat sage.groups + sage: W = CoxeterGroup(['A', 3]) # needs sage.combinat sage.groups + sage: c = W.from_reduced_word([1,2,3]) # needs sage.combinat sage.groups Number of `c`-sortable elements in `A_3` (Catalan number):: - sage: len([w for w in W if w.is_coxeter_sortable(c)]) # optional - sage.combinat sage.groups + sage: len([w for w in W if w.is_coxeter_sortable(c)]) 14 TESTS:: - sage: W = SymmetricGroup(3) # optional - sage.combinat sage.groups - sage: c = Permutation((1,2,3)) # optional - sage.combinat sage.groups - sage: sorted(w for w in W if w.is_coxeter_sortable(c)) # optional - sage.combinat sage.groups + sage: W = SymmetricGroup(3) # needs sage.groups + sage: c = Permutation((1,2,3)) + sage: sorted(w for w in W if w.is_coxeter_sortable(c)) # needs sage.combinat sage.groups [(), (2,3), (1,2), (1,3,2), (1,3)] """ if hasattr(c, "reduced_word"): @@ -2767,15 +2800,16 @@ def apply_demazure_product(self, element, side='right', EXAMPLES:: - sage: W = WeylGroup(['C', 4], prefix="s") # optional - sage.combinat sage.groups - sage: v = W.from_reduced_word([1,2,3,4,3,1]) # optional - sage.combinat sage.groups - sage: v.apply_demazure_product([1,3,4,3,3]) # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = WeylGroup(['C', 4], prefix="s") + sage: v = W.from_reduced_word([1,2,3,4,3,1]) + sage: v.apply_demazure_product([1,3,4,3,3]) s4*s1*s2*s3*s4*s3*s1 - sage: v.apply_demazure_product([1,3,4,3], side='left') # optional - sage.combinat sage.groups + sage: v.apply_demazure_product([1,3,4,3], side='left') s3*s4*s1*s2*s3*s4*s2*s3*s1 - sage: v.apply_demazure_product((1,3,4,3), side='left') # optional - sage.combinat sage.groups + sage: v.apply_demazure_product((1,3,4,3), side='left') s3*s4*s1*s2*s3*s4*s2*s3*s1 - sage: v.apply_demazure_product(v) # optional - sage.combinat sage.groups + sage: v.apply_demazure_product(v) s2*s3*s4*s1*s2*s3*s4*s2*s3*s2*s1 """ @@ -2810,14 +2844,15 @@ def min_demazure_product_greater(self, element): EXAMPLES:: - sage: W = WeylGroup(['A', 4], prefix="s") # optional - sage.combinat sage.groups - sage: v = W.from_reduced_word([2,3,4,1,2]) # optional - sage.combinat sage.groups - sage: u = W.from_reduced_word([2,3,2,1]) # optional - sage.combinat sage.groups - sage: v.min_demazure_product_greater(u) # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = WeylGroup(['A', 4], prefix="s") + sage: v = W.from_reduced_word([2,3,4,1,2]) + sage: u = W.from_reduced_word([2,3,2,1]) + sage: v.min_demazure_product_greater(u) s4*s2 - sage: v.min_demazure_product_greater([2,3,2,1]) # optional - sage.combinat sage.groups + sage: v.min_demazure_product_greater([2,3,2,1]) s4*s2 - sage: v.min_demazure_product_greater((2,3,2,1)) # optional - sage.combinat sage.groups + sage: v.min_demazure_product_greater((2,3,2,1)) s4*s2 """ @@ -2857,17 +2892,19 @@ def deodhar_factor_element(self, w, index_set): EXAMPLES:: - sage: W = WeylGroup(['A', 5], prefix="s") # optional - sage.combinat sage.groups - sage: v = W.from_reduced_word([5]) # optional - sage.combinat sage.groups - sage: w = W.from_reduced_word([4,5,2,3,1,2]) # optional - sage.combinat sage.groups - sage: v.deodhar_factor_element(w, [1,3,4]) # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = WeylGroup(['A', 5], prefix="s") + sage: v = W.from_reduced_word([5]) + sage: w = W.from_reduced_word([4,5,2,3,1,2]) + sage: v.deodhar_factor_element(w, [1,3,4]) s3*s1 - sage: W = WeylGroup(['C', 2]) # optional - sage.combinat sage.groups - sage: w = W.from_reduced_word([2,1]) # optional - sage.combinat sage.groups - sage: w.deodhar_factor_element(W.from_reduced_word([2]),[1]) # optional - sage.combinat sage.groups + sage: W = WeylGroup(['C', 2]) + sage: w = W.from_reduced_word([2,1]) + sage: w.deodhar_factor_element(W.from_reduced_word([2]),[1]) Traceback (most recent call last): ... - ValueError: [2, 1] is not of minimum length in its coset for the parabolic subgroup with index set [1] + ValueError: [2, 1] is not of minimum length in its coset + for the parabolic subgroup with index set [1] REFERENCES: @@ -2912,10 +2949,11 @@ def deodhar_lift_up(self, w, index_set): EXAMPLES:: - sage: W = WeylGroup(['A', 3], prefix="s") # optional - sage.combinat sage.groups - sage: v = W.from_reduced_word([1,2,3]) # optional - sage.combinat sage.groups - sage: w = W.from_reduced_word([1,3,2]) # optional - sage.combinat sage.groups - sage: v.deodhar_lift_up(w, [3]) # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = WeylGroup(['A', 3], prefix="s") + sage: v = W.from_reduced_word([1,2,3]) + sage: w = W.from_reduced_word([1,3,2]) + sage: v.deodhar_lift_up(w, [3]) s1*s2*s3*s2 """ vmin = self.coset_representative(index_set) @@ -2946,10 +2984,11 @@ def deodhar_lift_down(self, w, index_set): EXAMPLES:: - sage: W = WeylGroup(['A', 3], prefix="s") # optional - sage.combinat sage.groups - sage: v = W.from_reduced_word([1,2,3,2]) # optional - sage.combinat sage.groups - sage: w = W.from_reduced_word([3,2]) # optional - sage.combinat sage.groups - sage: v.deodhar_lift_down(w, [3]) # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = WeylGroup(['A', 3], prefix="s") + sage: v = W.from_reduced_word([1,2,3,2]) + sage: w = W.from_reduced_word([3,2]) + sage: v.deodhar_lift_down(w, [3]) s2*s3*s2 """ @@ -2969,9 +3008,9 @@ def inversions_as_reflections(self): EXAMPLES:: - sage: W = WeylGroup(['A', 3], prefix="s") # optional - sage.combinat sage.groups - sage: w = W.from_reduced_word([3,1,2,1]) # optional - sage.combinat sage.groups - sage: w.inversions_as_reflections() # optional - sage.combinat sage.groups + sage: W = WeylGroup(['A', 3], prefix="s") # needs sage.combinat sage.groups + sage: w = W.from_reduced_word([3,1,2,1]) # needs sage.combinat sage.groups + sage: w.inversions_as_reflections() # needs sage.combinat sage.groups [s1, s1*s2*s1, s2, s1*s2*s3*s2*s1] """ i = self.first_descent() @@ -2986,9 +3025,9 @@ def left_inversions_as_reflections(self): EXAMPLES:: - sage: W = WeylGroup(['A', 3], prefix="s") # optional - sage.combinat sage.groups - sage: w = W.from_reduced_word([3,1,2,1]) # optional - sage.combinat sage.groups - sage: w.left_inversions_as_reflections() # optional - sage.combinat sage.groups + sage: W = WeylGroup(['A', 3], prefix="s") # needs sage.combinat sage.groups + sage: w = W.from_reduced_word([3,1,2,1]) # needs sage.combinat sage.groups + sage: w.left_inversions_as_reflections() # needs sage.combinat sage.groups [s1, s3, s1*s2*s3*s2*s1, s2*s3*s2] """ return self.inverse().inversions_as_reflections() @@ -3006,24 +3045,24 @@ def lower_covers(self, side='right', index_set=None): EXAMPLES:: - sage: W = WeylGroup(['A', 3]) # optional - sage.combinat sage.groups - sage: w = W.from_reduced_word([3,2,1]) # optional - sage.combinat sage.groups - sage: [x.reduced_word() for x in w.lower_covers()] # optional - sage.combinat sage.groups + sage: W = WeylGroup(['A', 3]) # needs sage.combinat sage.groups + sage: w = W.from_reduced_word([3,2,1]) # needs sage.combinat sage.groups + sage: [x.reduced_word() for x in w.lower_covers()] # needs sage.combinat sage.groups [[3, 2]] To obtain covers for left weak order, set the option side to 'left':: - sage: [x.reduced_word() for x in w.lower_covers(side='left')] # optional - sage.combinat sage.groups + sage: [x.reduced_word() for x in w.lower_covers(side='left')] # needs sage.combinat sage.groups [[2, 1]] - sage: w = W.from_reduced_word([3,2,3,1]) # optional - sage.combinat sage.groups - sage: [x.reduced_word() for x in w.lower_covers()] # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([3,2,3,1]) # needs sage.combinat sage.groups + sage: [x.reduced_word() for x in w.lower_covers()] # needs sage.combinat sage.groups [[2, 3, 2], [3, 2, 1]] Covers w.r.t. a parabolic subgroup are obtained with the option ``index_set``:: - sage: [x.reduced_word() for x in w.lower_covers(index_set=[1,2])] # optional - sage.combinat sage.groups + sage: [x.reduced_word() for x in w.lower_covers(index_set=[1,2])] # needs sage.combinat sage.groups [[2, 3, 2]] - sage: [x.reduced_word() for x in w.lower_covers(side='left')] # optional - sage.combinat sage.groups + sage: [x.reduced_word() for x in w.lower_covers(side='left')] # needs sage.combinat sage.groups [[3, 2, 1], [2, 3, 1]] """ return self.weak_covers(side=side, index_set=index_set, @@ -3042,21 +3081,21 @@ def upper_covers(self, side='right', index_set=None): EXAMPLES:: - sage: W = WeylGroup(['A', 3]) # optional - sage.combinat sage.groups - sage: w = W.from_reduced_word([2,3]) # optional - sage.combinat sage.groups - sage: [x.reduced_word() for x in w.upper_covers()] # optional - sage.combinat sage.groups + sage: W = WeylGroup(['A', 3]) # needs sage.combinat sage.groups + sage: w = W.from_reduced_word([2,3]) # needs sage.combinat sage.groups + sage: [x.reduced_word() for x in w.upper_covers()] # needs sage.combinat sage.groups [[2, 3, 1], [2, 3, 2]] To obtain covers for left weak order, set the option ``side`` to 'left':: - sage: [x.reduced_word() for x in w.upper_covers(side='left')] # optional - sage.combinat sage.groups + sage: [x.reduced_word() for x in w.upper_covers(side='left')] # needs sage.combinat sage.groups [[1, 2, 3], [2, 3, 2]] Covers w.r.t. a parabolic subgroup are obtained with the option ``index_set``:: - sage: [x.reduced_word() for x in w.upper_covers(index_set=[1])] # optional - sage.combinat sage.groups + sage: [x.reduced_word() for x in w.upper_covers(index_set=[1])] # needs sage.combinat sage.groups [[2, 3, 1]] - sage: [x.reduced_word() # optional - sage.combinat sage.groups + sage: [x.reduced_word() # needs sage.combinat sage.groups ....: for x in w.upper_covers(side='left', index_set=[1])] [[1, 2, 3]] """ @@ -3100,9 +3139,9 @@ def kazhdan_lusztig_cell(self, side='left'): choice of implementation affects the representation of elements in the output cell but not the method used for the cell computation:: - sage: W = CoxeterGroup('A3', implementation='permutation') # optional - sage.combinat sage.groups - sage: s1, s2, s3 = W.simple_reflections() # optional - sage.combinat sage.groups - sage: s1.kazhdan_lusztig_cell() # optional - sage.combinat sage.groups + sage: W = CoxeterGroup('A3', implementation='permutation') # needs sage.combinat sage.groups + sage: s1, s2, s3 = W.simple_reflections() # needs sage.combinat sage.groups + sage: s1.kazhdan_lusztig_cell() # needs sage.combinat sage.groups {(1,2,3,12)(4,5,10,11)(6,7,8,9), (1,2,10)(3,6,5)(4,7,8)(9,12,11), (1,7)(2,4)(5,6)(8,10)(11,12)} @@ -3111,30 +3150,33 @@ def kazhdan_lusztig_cell(self, side='left'): the background if available to speed up the computation, even in the different implementations implementations:: - sage: W = WeylGroup('A3', prefix='s') # optional - coxeter3 - sage: s1,s2,s3 = W.simple_reflections() # optional - coxeter3 - sage: s1.kazhdan_lusztig_cell() # optional - coxeter3 + sage: # optional - coxeter3, needs sage.combinat sage.groups sage.modules + sage: W = WeylGroup('A3', prefix='s') + sage: s1,s2,s3 = W.simple_reflections() + sage: s1.kazhdan_lusztig_cell() {s3*s2*s1, s2*s1, s1} - sage: W = CoxeterGroup('A3', implementation='coxeter3') # optional - coxeter3 - sage: s1,s2,s3 = W.simple_reflections() # optional - coxeter3 - sage: s1.kazhdan_lusztig_cell() # optional - coxeter3 + sage: W = CoxeterGroup('A3', implementation='coxeter3') + sage: s1,s2,s3 = W.simple_reflections() + sage: s1.kazhdan_lusztig_cell() {[1], [2, 1], [3, 2, 1]} Next, we compute a right cell and a two-sided cell in `A_3`:: - sage: W = CoxeterGroup('A3', implementation='coxeter3') # optional - coxeter3 - sage: s1,s2,s3 = W.simple_reflections() # optional - coxeter3 - sage: w = s1 * s3 # optional - coxeter3 - sage: w.kazhdan_lusztig_cell(side='right') # optional - coxeter3 + sage: # optional - coxeter3, needs sage.combinat sage.groups sage.modules + sage: W = CoxeterGroup('A3', implementation='coxeter3') + sage: s1,s2,s3 = W.simple_reflections() + sage: w = s1 * s3 + sage: w.kazhdan_lusztig_cell(side='right') {[1, 3], [1, 3, 2]} - sage: w.kazhdan_lusztig_cell(side='two-sided') # optional - coxeter3 + sage: w.kazhdan_lusztig_cell(side='two-sided') {[1, 3], [1, 3, 2], [2, 1, 3], [2, 1, 3, 2]} Some slightly longer computations in `B_4`:: - sage: W = CoxeterGroup('B4', implementation='coxeter3') # optional - coxeter3 - sage: s1,s2,s3,s4 = W.simple_reflections() # optional - coxeter3 - sage: s1.kazhdan_lusztig_cell(side='right') # long time (4 seconds) # optional - coxeter3 + sage: # optional - coxeter3, needs sage.combinat sage.groups sage.modules + sage: W = CoxeterGroup('B4', implementation='coxeter3') + sage: s1,s2,s3,s4 = W.simple_reflections() + sage: s1.kazhdan_lusztig_cell(side='right') # long time (4 seconds) {[1], [1, 2], [1, 2, 3], @@ -3142,7 +3184,7 @@ def kazhdan_lusztig_cell(self, side='left'): [1, 2, 3, 4, 3], [1, 2, 3, 4, 3, 2], [1, 2, 3, 4, 3, 2, 1]} - sage: (s4*s2*s3*s4).kazhdan_lusztig_cell(side='two-sided') # long time (8 seconds) # optional - coxeter3 + sage: (s4*s2*s3*s4).kazhdan_lusztig_cell(side='two-sided') # long time (8 seconds) {[2, 3, 1], [2, 3, 1, 2], [2, 3, 4, 1], diff --git a/src/sage/categories/crystals.py b/src/sage/categories/crystals.py index 3ceb16529d6..7e2a92edeb1 100644 --- a/src/sage/categories/crystals.py +++ b/src/sage/categories/crystals.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.graphs sage.combinat +# sage.doctest: needs sage.graphs sage.combinat r""" Crystals diff --git a/src/sage/categories/discrete_valuation.py b/src/sage/categories/discrete_valuation.py index 42829732859..4bb61a5aa67 100644 --- a/src/sage/categories/discrete_valuation.py +++ b/src/sage/categories/discrete_valuation.py @@ -20,7 +20,7 @@ class DiscreteValuationRings(Category_singleton): EXAMPLES:: - sage: GF(7)[['x']] in DiscreteValuationRings() # optional - sage.rings.finite_rings + sage: GF(7)[['x']] in DiscreteValuationRings() True sage: TestSuite(DiscreteValuationRings()).run() """ @@ -41,7 +41,7 @@ def uniformizer(self): EXAMPLES:: - sage: Zp(5).uniformizer() # optional - sage.rings.padics + sage: Zp(5).uniformizer() # needs sage.rings.padics 5 + O(5^21) sage: K. = QQ[[]] @@ -56,7 +56,7 @@ def residue_field(self): EXAMPLES:: - sage: Zp(5).residue_field() # optional - sage.rings.padics + sage: Zp(5).residue_field() # needs sage.rings.padics Finite Field of size 5 sage: K. = QQ[[]] @@ -70,38 +70,41 @@ def _matrix_charpoly(self, M, var): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings - sage: M = matrix(4, 4, [(t^(i+j)).add_bigoh(10) # optional - sage.rings.finite_rings + sage: # needs sage.modules + sage: R. = PowerSeriesRing(GF(5)) + sage: M = matrix(4, 4, [(t^(i+j)).add_bigoh(10) ....: for i in range(4) for j in range(4)]) - sage: M # optional - sage.rings.finite_rings + sage: M [ 1 + O(t^10) t + O(t^10) t^2 + O(t^10) t^3 + O(t^10)] [ t + O(t^10) t^2 + O(t^10) t^3 + O(t^10) t^4 + O(t^10)] [t^2 + O(t^10) t^3 + O(t^10) t^4 + O(t^10) t^5 + O(t^10)] [t^3 + O(t^10) t^4 + O(t^10) t^5 + O(t^10) t^6 + O(t^10)] - sage: M.charpoly() # indirect doctest # optional - sage.rings.finite_rings + sage: M.charpoly() # indirect doctest x^4 + (4 + 4*t^2 + 4*t^4 + 4*t^6 + O(t^10))*x^3 Note that this function uses a Hessenberg-like algorithm that performs divisions. Hence, truncations may show up even if the input matrix is exact:: - sage: M = matrix(3, 3, [ 1, t, t^2, 1+t, t^2, t^3, t^2, t^3, t^4 ]) # optional - sage.rings.finite_rings - sage: M # optional - sage.rings.finite_rings + sage: # needs sage.modules + sage: M = matrix(3, 3, [ 1, t, t^2, 1+t, t^2, t^3, t^2, t^3, t^4 ]) + sage: M [ 1 t t^2] [1 + t t^2 t^3] [ t^2 t^3 t^4] - sage: M.charpoly() # optional - sage.rings.finite_rings + sage: M.charpoly() x^3 + (4 + 4*t^2 + 4*t^4 + O(t^25))*x^2 + (4*t + O(t^24))*x Another example over the p-adics:: - sage: R = Zp(5, print_mode="digits", prec=5) # optional - sage.rings.padics - sage: M = matrix(R, 3, 3, range(9)) # optional - sage.rings.padics - sage: M # optional - sage.rings.padics + sage: # needs sage.modules sage.rings.padics + sage: R = Zp(5, print_mode="digits", prec=5) + sage: M = matrix(R, 3, 3, range(9)) + sage: M [ 0 ...00001 ...00002] [ ...00003 ...00004 ...000010] [ ...00011 ...00012 ...00013] - sage: M.charpoly() # optional - sage.rings.padics + sage: M.charpoly() ...00001*x^3 + ...44423*x^2 + ...44412*x + ...00000 """ return M._charpoly_hessenberg(var) @@ -114,8 +117,9 @@ def valuation(self): EXAMPLES:: - sage: x = Zp(5)(50) # optional - sage.rings.padics - sage: x.valuation() # optional - sage.rings.padics + sage: # needs sage.rings.padics + sage: x = Zp(5)(50) + sage: x.valuation() 2 """ @@ -125,10 +129,10 @@ def euclidean_degree(self): TESTS:: - sage: R. = GF(5)[[]] # optional - sage.rings.finite_rings - sage: (q^3).euclidean_degree() # optional - sage.rings.finite_rings + sage: R. = GF(5)[[]] + sage: (q^3).euclidean_degree() 3 - sage: R(0).euclidean_degree() # optional - sage.rings.finite_rings + sage: R(0).euclidean_degree() Traceback (most recent call last): ... ValueError: Euclidean degree of the zero element not defined @@ -145,12 +149,12 @@ def quo_rem(self, other): TESTS:: - sage: R. = GF(5)[[]] # optional - sage.rings.finite_rings - sage: (q^2 + q).quo_rem(q) # optional - sage.rings.finite_rings + sage: R. = GF(5)[[]] + sage: (q^2 + q).quo_rem(q) (1 + q, 0) - sage: (q + 1).quo_rem(q^2) # optional - sage.rings.finite_rings + sage: (q + 1).quo_rem(q^2) (0, 1 + q) - sage: q.quo_rem(0) # optional - sage.rings.finite_rings + sage: q.quo_rem(0) Traceback (most recent call last): ... ZeroDivisionError: Euclidean division by the zero element not defined @@ -166,16 +170,18 @@ def quo_rem(self, other): def is_unit(self): """ - Return True if self is invertible. + Return ``True`` if ``self`` is invertible. EXAMPLES:: - sage: x = Zp(5)(50) # optional - sage.rings.padics - sage: x.is_unit() # optional - sage.rings.padics + sage: # needs sage.rings.padics + sage: x = Zp(5)(50) + sage: x.is_unit() False - sage: x = Zp(7)(50) # optional - sage.rings.padics - sage: x.is_unit() # optional - sage.rings.padics + sage: # needs sage.rings.padics + sage: x = Zp(7)(50) + sage: x.is_unit() True """ return self.valuation() == 0 @@ -213,7 +219,7 @@ class DiscreteValuationFields(Category_singleton): EXAMPLES:: - sage: Qp(7) in DiscreteValuationFields() # optional - sage.rings.padics + sage: Qp(7) in DiscreteValuationFields() # needs sage.rings.padics True sage: TestSuite(DiscreteValuationFields()).run() """ @@ -235,7 +241,7 @@ def uniformizer(self): EXAMPLES:: - sage: Qp(5).uniformizer() # optional - sage.rings.padics + sage: Qp(5).uniformizer() # needs sage.rings.padics 5 + O(5^21) """ @@ -247,7 +253,7 @@ def residue_field(self): EXAMPLES:: - sage: Qp(5).residue_field() # optional - sage.rings.padics + sage: Qp(5).residue_field() # needs sage.rings.padics Finite Field of size 5 sage: K. = LaurentSeriesRing(QQ) @@ -261,17 +267,18 @@ def _matrix_hessenbergize(self, H): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings - sage: K = R.fraction_field() # optional - sage.rings.finite_rings - sage: H = matrix(K, 4, 4, [(t^(i+j)).add_bigoh(10) # optional - sage.rings.finite_rings + sage: # needs sage.modules + sage: R. = PowerSeriesRing(GF(5)) + sage: K = R.fraction_field() + sage: H = matrix(K, 4, 4, [(t^(i+j)).add_bigoh(10) ....: for i in range(4) for j in range(4)]) - sage: H # optional - sage.rings.finite_rings + sage: H [ 1 + O(t^10) t + O(t^10) t^2 + O(t^10) t^3 + O(t^10)] [ t + O(t^10) t^2 + O(t^10) t^3 + O(t^10) t^4 + O(t^10)] [t^2 + O(t^10) t^3 + O(t^10) t^4 + O(t^10) t^5 + O(t^10)] [t^3 + O(t^10) t^4 + O(t^10) t^5 + O(t^10) t^6 + O(t^10)] - sage: H.hessenbergize() # optional - sage.rings.finite_rings - sage: H # optional - sage.rings.finite_rings + sage: H.hessenbergize() + sage: H [ 1 + O(t^10) t + t^3 + t^5 + O(t^10) t^2 + O(t^10) t^3 + O(t^10)] [ t + O(t^10) t^2 + t^4 + t^6 + O(t^10) t^3 + O(t^10) t^4 + O(t^10)] [ O(t^10) O(t^10) O(t^10) O(t^10)] @@ -279,14 +286,13 @@ def _matrix_hessenbergize(self, H): Another example over the p-adics:: - sage: K = Qp(5, print_mode="digits", prec=5) # optional - sage.rings.padics - sage: H = matrix(K, 3, 3, range(9)) # optional - sage.rings.padics - sage: H # optional - sage.rings.padics + sage: # needs sage.modules sage.rings.padics + sage: K = Qp(5, print_mode="digits", prec=5) + sage: H = matrix(K, 3, 3, range(9)); H [ 0 ...00001 ...00002] [ ...00003 ...00004 ...000010] [ ...00011 ...00012 ...00013] - sage: H.hessenbergize() # optional - sage.rings.padics - sage: H # optional - sage.rings.padics + sage: H.hessenbergize(); H [ 0 ...00010 ...00002] [ ...00003 ...00024 ...000010] [ ...00000 ...44440 ...44443] @@ -302,7 +308,8 @@ def valuation(self): EXAMPLES:: - sage: x = Qp(5)(50) # optional - sage.rings.padics - sage: x.valuation() # optional - sage.rings.padics + sage: # needs sage.rings.padics + sage: x = Qp(5)(50) + sage: x.valuation() 2 """ diff --git a/src/sage/categories/distributive_magmas_and_additive_magmas.py b/src/sage/categories/distributive_magmas_and_additive_magmas.py index 3518893c907..6d1c7511c11 100644 --- a/src/sage/categories/distributive_magmas_and_additive_magmas.py +++ b/src/sage/categories/distributive_magmas_and_additive_magmas.py @@ -68,7 +68,7 @@ def _test_distributivity(self, **options): However, the elements tested can be customized with the ``elements`` keyword argument:: - sage: CC._test_distributivity(elements=[CC(0),CC(1),CC(3),CC(I)]) + sage: CC._test_distributivity(elements=[CC(0),CC(1),CC(3),CC(I)]) # needs sage.symbolic See the documentation for :class:`TestSuite` for more information. """ diff --git a/src/sage/categories/domains.py b/src/sage/categories/domains.py index 02062390a02..18e2907b8ef 100644 --- a/src/sage/categories/domains.py +++ b/src/sage/categories/domains.py @@ -59,21 +59,22 @@ def _test_zero_divisors(self, **options): not have them in theory. For such inexact rings, these tests are not performed:: - sage: R = ZpFM(5); R # optional - sage.rings.padics + sage: # needs sage.rings.padics + sage: R = ZpFM(5); R 5-adic Ring of fixed modulus 5^20 - sage: R.is_exact() # optional - sage.rings.padics + sage: R.is_exact() False - sage: a = R(5^19) # optional - sage.rings.padics - sage: a.is_zero() # optional - sage.rings.padics + sage: a = R(5^19) + sage: a.is_zero() False - sage: (a * a).is_zero() # optional - sage.rings.padics + sage: (a * a).is_zero() True - sage: R._test_zero_divisors() # optional - sage.rings.padics + sage: R._test_zero_divisors() EXAMPLES:: sage: ZZ._test_zero_divisors() - sage: ZpFM(5)._test_zero_divisors() # optional - sage.rings.padics + sage: ZpFM(5)._test_zero_divisors() # needs sage.rings.padics """ if not self.is_exact(): diff --git a/src/sage/categories/drinfeld_modules.py b/src/sage/categories/drinfeld_modules.py index fe64c6a4a59..380318c37ff 100644 --- a/src/sage/categories/drinfeld_modules.py +++ b/src/sage/categories/drinfeld_modules.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.rings.finite_rings +# sage.doctest: needs sage.rings.finite_rings r""" Drinfeld modules over a base diff --git a/src/sage/categories/enumerated_sets.py b/src/sage/categories/enumerated_sets.py index de57384e2de..98c1a729fba 100644 --- a/src/sage/categories/enumerated_sets.py +++ b/src/sage/categories/enumerated_sets.py @@ -278,33 +278,34 @@ def iterator_range(self, start=None, stop=None, step=None): EXAMPLES:: - sage: P = Partitions() # optional - sage.combinat - sage: list(P.iterator_range(stop=5)) # optional - sage.combinat + sage: # needs sage.combinat + sage: P = Partitions() + sage: list(P.iterator_range(stop=5)) [[], [1], [2], [1, 1], [3]] - sage: list(P.iterator_range(0, 5)) # optional - sage.combinat + sage: list(P.iterator_range(0, 5)) [[], [1], [2], [1, 1], [3]] - sage: list(P.iterator_range(3, 5)) # optional - sage.combinat + sage: list(P.iterator_range(3, 5)) [[1, 1], [3]] - sage: list(P.iterator_range(3, 10)) # optional - sage.combinat + sage: list(P.iterator_range(3, 10)) [[1, 1], [3], [2, 1], [1, 1, 1], [4], [3, 1], [2, 2]] - sage: list(P.iterator_range(3, 10, 2)) # optional - sage.combinat + sage: list(P.iterator_range(3, 10, 2)) [[1, 1], [2, 1], [4], [2, 2]] - sage: it = P.iterator_range(3) # optional - sage.combinat - sage: [next(it) for x in range(10)] # optional - sage.combinat + sage: it = P.iterator_range(3) + sage: [next(it) for x in range(10)] [[1, 1], [3], [2, 1], [1, 1, 1], [4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1], [5]] - sage: it = P.iterator_range(3, step=2) # optional - sage.combinat - sage: [next(it) for x in range(5)] # optional - sage.combinat + sage: it = P.iterator_range(3, step=2) + sage: [next(it) for x in range(5)] [[1, 1], [2, 1], [4], [2, 2], [1, 1, 1, 1]] - sage: next(P.iterator_range(stop=-3)) # optional - sage.combinat + sage: next(P.iterator_range(stop=-3)) Traceback (most recent call last): ... NotImplementedError: cannot list an infinite set - sage: next(P.iterator_range(start=-3)) # optional - sage.combinat + sage: next(P.iterator_range(start=-3)) Traceback (most recent call last): ... NotImplementedError: cannot list an infinite set @@ -357,26 +358,27 @@ def unrank_range(self, start=None, stop=None, step=None): EXAMPLES:: - sage: P = Partitions() # optional - sage.combinat - sage: P.unrank_range(stop=5) # optional - sage.combinat + sage: # needs sage.combinat + sage: P = Partitions() + sage: P.unrank_range(stop=5) [[], [1], [2], [1, 1], [3]] - sage: P.unrank_range(0, 5) # optional - sage.combinat + sage: P.unrank_range(0, 5) [[], [1], [2], [1, 1], [3]] - sage: P.unrank_range(3, 5) # optional - sage.combinat + sage: P.unrank_range(3, 5) [[1, 1], [3]] - sage: P.unrank_range(3, 10) # optional - sage.combinat + sage: P.unrank_range(3, 10) [[1, 1], [3], [2, 1], [1, 1, 1], [4], [3, 1], [2, 2]] - sage: P.unrank_range(3, 10, 2) # optional - sage.combinat + sage: P.unrank_range(3, 10, 2) [[1, 1], [2, 1], [4], [2, 2]] - sage: P.unrank_range(3) # optional - sage.combinat + sage: P.unrank_range(3) Traceback (most recent call last): ... NotImplementedError: cannot list an infinite set - sage: P.unrank_range(stop=-3) # optional - sage.combinat + sage: P.unrank_range(stop=-3) Traceback (most recent call last): ... NotImplementedError: cannot list an infinite set - sage: P.unrank_range(start=-3) # optional - sage.combinat + sage: P.unrank_range(start=-3) Traceback (most recent call last): ... NotImplementedError: cannot list an infinite set @@ -410,24 +412,25 @@ def __getitem__(self, i): EXAMPLES:: - sage: P = Partitions() # optional - sage.combinat - sage: P[:5] # optional - sage.combinat + sage: # needs sage.combinat + sage: P = Partitions() + sage: P[:5] [[], [1], [2], [1, 1], [3]] - sage: P[0:5] # optional - sage.combinat + sage: P[0:5] [[], [1], [2], [1, 1], [3]] - sage: P[3:5] # optional - sage.combinat + sage: P[3:5] [[1, 1], [3]] - sage: P[3:10] # optional - sage.combinat + sage: P[3:10] [[1, 1], [3], [2, 1], [1, 1, 1], [4], [3, 1], [2, 2]] - sage: P[3:10:2] # optional - sage.combinat + sage: P[3:10:2] [[1, 1], [2, 1], [4], [2, 2]] - sage: P[3:] # optional - sage.combinat + sage: P[3:] Traceback (most recent call last): ... NotImplementedError: cannot list an infinite set - sage: P[3] # optional - sage.combinat + sage: P[3] [1, 1] - sage: P[-1] # optional - sage.combinat + sage: P[-1] Traceback (most recent call last): ... NotImplementedError: cannot list an infinite set @@ -468,9 +471,9 @@ def __len__(self): EXAMPLES:: - sage: len(GF(5)) # optional - sage.libs.pari + sage: len(GF(5)) 5 - sage: len(MatrixSpace(GF(2), 3, 3)) # optional - sage.libs.pari sage.modules + sage: len(MatrixSpace(GF(2), 3, 3)) # needs sage.modules 512 """ from sage.rings.infinity import Infinity @@ -495,7 +498,7 @@ def tuple(self): EXAMPLES:: - sage: (GF(3)^2).tuple() # optional - sage.libs.pari + sage: (GF(3)^2).tuple() # needs sage.modules ((0, 0), (1, 0), (2, 0), (0, 1), (1, 1), (2, 1), (0, 2), (1, 2), (2, 2)) sage: R = Integers(11) sage: l = R.tuple(); l @@ -576,7 +579,7 @@ def list(self): EXAMPLES:: - sage: (GF(3)^2).list() # optional - sage.libs.pari + sage: (GF(3)^2).list() # needs sage.modules [(0, 0), (1, 0), (2, 0), (0, 1), (1, 1), (2, 1), (0, 2), (1, 2), (2, 2)] sage: R = Integers(11) sage: R.list() @@ -604,7 +607,7 @@ def _list_from_iterator(self): Trying to list an infinite vector space raises an error instead of running forever (see :trac:`10470`):: - sage: (QQ^2).list() # indirect test # optional - sage.modules + sage: (QQ^2).list() # indirect test # needs sage.modules Traceback (most recent call last): ... AttributeError: 'FreeModule_ambient_field_with_category' object has no attribute 'list' @@ -954,16 +957,16 @@ def map(self, f, name=None, *, is_injective=True): EXAMPLES:: - sage: R = Compositions(4).map(attrcall('partial_sums')); R # optional - sage.combinat + sage: R = Compositions(4).map(attrcall('partial_sums')); R Image of Compositions of 4 by The map *.partial_sums() from Compositions of 4 - sage: R.cardinality() # optional - sage.combinat + sage: R.cardinality() 8 - sage: R.list() # optional - sage.combinat + sage: R.list() [[1, 2, 3, 4], [1, 2, 4], [1, 3, 4], [1, 4], [2, 3, 4], [2, 4], [3, 4], [4]] - sage: [r for r in R] # optional - sage.combinat + sage: [r for r in R] [[1, 2, 3, 4], [1, 2, 4], [1, 3, 4], [1, 4], [2, 3, 4], [2, 4], [3, 4], [4]] - sage: R.category() # optional - sage.combinat + sage: R.category() Category of finite enumerated subobjects of sets .. WARNING:: @@ -971,20 +974,20 @@ def map(self, f, name=None, *, is_injective=True): If the function is not injective, then there may be repeated elements:: - sage: P = Compositions(4) # optional - sage.combinat - sage: P.list() # optional - sage.combinat + sage: P = Compositions(4) + sage: P.list() [[1, 1, 1, 1], [1, 1, 2], [1, 2, 1], [1, 3], [2, 1, 1], [2, 2], [3, 1], [4]] - sage: P.map(attrcall('major_index')).list() # optional - sage.combinat + sage: P.map(attrcall('major_index')).list() [6, 3, 4, 1, 5, 2, 3, 0] Pass ``is_injective=False`` to get a correct result in this case:: - sage: P.map(attrcall('major_index'), is_injective=False).list() # optional - sage.combinat + sage: P.map(attrcall('major_index'), is_injective=False).list() [6, 3, 4, 1, 5, 2, 0] TESTS:: - sage: TestSuite(R).run(skip=['_test_an_element', # optional - sage.combinat + sage: TestSuite(R).run(skip=['_test_an_element', ....: '_test_enumerated_set_contains', ....: '_test_some_elements']) """ diff --git a/src/sage/categories/examples/algebras_with_basis.py b/src/sage/categories/examples/algebras_with_basis.py index ccbc3a3a9c0..04511128301 100644 --- a/src/sage/categories/examples/algebras_with_basis.py +++ b/src/sage/categories/examples/algebras_with_basis.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.combinat +# sage.doctest: needs sage.combinat r""" Examples of algebras with basis """ @@ -26,9 +26,9 @@ def __init__(self, R, alphabet=("a", "b", "c")): """ EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example(); A + sage: A = AlgebrasWithBasis(QQ).example(); A # needs sage.modules An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: TestSuite(A).run() + sage: TestSuite(A).run() # needs sage.modules """ self._alphabet = alphabet @@ -40,7 +40,7 @@ def _repr_(self): """ EXAMPLES:: - sage: AlgebrasWithBasis(QQ).example() # indirect doctest + sage: AlgebrasWithBasis(QQ).example() # indirect doctest # needs sage.modules An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field """ return "An example of an algebra with basis: the free algebra on the generators %s over %s"%(self._alphabet, self.base_ring()) @@ -53,10 +53,10 @@ def one_basis(self): EXAMPLES::r - sage: A = AlgebrasWithBasis(QQ).example() - sage: A.one_basis() + sage: A = AlgebrasWithBasis(QQ).example() # needs sage.modules + sage: A.one_basis() # needs sage.modules word: - sage: A.one() + sage: A.one() # needs sage.modules B[word: ] """ return self.basis().keys()([]) @@ -68,6 +68,7 @@ def product_on_basis(self, w1, w2): EXAMPLES:: + sage: # needs sage.modules sage: A = AlgebrasWithBasis(QQ).example() sage: Words = A.basis().keys() sage: A.product_on_basis(Words("acb"), Words("cba")) @@ -85,9 +86,9 @@ def algebra_generators(self): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example(); A + sage: A = AlgebrasWithBasis(QQ).example(); A # needs sage.modules An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: A.algebra_generators() + sage: A.algebra_generators() # needs sage.modules Family (B[word: a], B[word: b], B[word: c]) """ Words = self.basis().keys() diff --git a/src/sage/categories/examples/crystals.py b/src/sage/categories/examples/crystals.py index c38117b3b70..3378c9282d1 100644 --- a/src/sage/categories/examples/crystals.py +++ b/src/sage/categories/examples/crystals.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.combinat sage.graphs +# sage.doctest: needs sage.combinat sage.graphs r""" Example of a crystal """ diff --git a/src/sage/categories/examples/filtered_modules_with_basis.py b/src/sage/categories/examples/filtered_modules_with_basis.py index 3cf9db3f57c..35edb3314dc 100644 --- a/src/sage/categories/examples/filtered_modules_with_basis.py +++ b/src/sage/categories/examples/filtered_modules_with_basis.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.combinat +# sage.doctest: needs sage.combinat r""" Examples of filtered modules with basis """ @@ -34,7 +34,7 @@ class FilteredPartitionModule(CombinatorialFreeModule): :: - sage: A = ModulesWithBasis(QQ).Filtered().example() + sage: A = ModulesWithBasis(QQ).Filtered().example() # needs sage.modules - If the algebra is called ``A``, then its basis function is stored as ``A.basis``. Thus the function can be used to @@ -44,7 +44,7 @@ class FilteredPartitionModule(CombinatorialFreeModule): :: - sage: [m for m in A.basis(4)] + sage: [m for m in A.basis(4)] # needs sage.modules [P[4], P[3, 1], P[2, 2], P[2, 1, 1], P[1, 1, 1, 1]] - For dealing with basis elements: :meth:`degree_on_basis`, and @@ -58,9 +58,9 @@ class FilteredPartitionModule(CombinatorialFreeModule): :: - sage: A.degree_on_basis(Partition([4,3])) + sage: A.degree_on_basis(Partition([4,3])) # needs sage.modules 7 - sage: A._repr_term(Partition([4,3])) + sage: A._repr_term(Partition([4,3])) # needs sage.modules 'P[4, 3]' - There is a class for elements, which inherits from @@ -74,20 +74,20 @@ class FilteredPartitionModule(CombinatorialFreeModule): :: - sage: p = A.monomial(Partition([3,2,1])); p + sage: p = A.monomial(Partition([3,2,1])); p # needs sage.modules P[3, 2, 1] - sage: p.is_homogeneous() + sage: p.is_homogeneous() # needs sage.modules True - sage: p.degree() + sage: p.degree() # needs sage.modules 6 """ def __init__(self, base_ring): """ EXAMPLES:: - sage: A = ModulesWithBasis(QQ).Filtered().example(); A + sage: A = ModulesWithBasis(QQ).Filtered().example(); A # needs sage.modules An example of a filtered module with basis: the free module on partitions over Rational Field - sage: TestSuite(A).run() + sage: TestSuite(A).run() # needs sage.modules """ CombinatorialFreeModule.__init__(self, base_ring, Partitions(), category=FilteredModulesWithBasis(base_ring)) @@ -111,6 +111,7 @@ def degree_on_basis(self, t): EXAMPLES:: + sage: # needs sage.modules sage: A = ModulesWithBasis(QQ).Filtered().example() sage: A.degree_on_basis(Partition((2,1))) 3 @@ -127,7 +128,7 @@ def _repr_(self): EXAMPLES:: - sage: ModulesWithBasis(QQ).Filtered().example() # indirect doctest + sage: ModulesWithBasis(QQ).Filtered().example() # indirect doctest # needs sage.modules An example of a filtered module with basis: the free module on partitions over Rational Field """ return "An example of a filtered module with basis: the free module on partitions over %s" % self.base_ring() @@ -142,8 +143,8 @@ def _repr_term(self, t): EXAMPLES:: - sage: A = ModulesWithBasis(QQ).Filtered().example() - sage: A._repr_term(Partition((4,2,1))) + sage: A = ModulesWithBasis(QQ).Filtered().example() # needs sage.modules + sage: A._repr_term(Partition((4,2,1))) # needs sage.modules 'P[4, 2, 1]' """ return 'P' + t._repr_() diff --git a/src/sage/categories/examples/finite_coxeter_groups.py b/src/sage/categories/examples/finite_coxeter_groups.py index 57ada2a0c2b..84e4c1f95b4 100644 --- a/src/sage/categories/examples/finite_coxeter_groups.py +++ b/src/sage/categories/examples/finite_coxeter_groups.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.combinat sage.groups +# sage.doctest: needs sage.combinat sage.groups r""" Examples of finite Coxeter groups """ diff --git a/src/sage/categories/examples/finite_dimensional_algebras_with_basis.py b/src/sage/categories/examples/finite_dimensional_algebras_with_basis.py index ac18f69b6ec..0406e23c6e8 100644 --- a/src/sage/categories/examples/finite_dimensional_algebras_with_basis.py +++ b/src/sage/categories/examples/finite_dimensional_algebras_with_basis.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.modules +# sage.doctest: needs sage.modules r""" Example of a finite dimensional algebra with basis """ diff --git a/src/sage/categories/examples/finite_dimensional_lie_algebras_with_basis.py b/src/sage/categories/examples/finite_dimensional_lie_algebras_with_basis.py index db28f48dff7..58e613a6d45 100644 --- a/src/sage/categories/examples/finite_dimensional_lie_algebras_with_basis.py +++ b/src/sage/categories/examples/finite_dimensional_lie_algebras_with_basis.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.modules +# sage.doctest: needs sage.modules r""" Examples of a finite dimensional Lie algebra with basis """ @@ -363,7 +363,7 @@ def lift(self): sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() sage: a, b, c = L.lie_algebra_generators() sage: elt = 2*a + 2*b + 3*c - sage: elt.lift() + sage: elt.lift() # needs sage.combinat 2*b0 + 2*b1 + 3*b2 """ UEA = self.parent().universal_enveloping_algebra() diff --git a/src/sage/categories/examples/finite_semigroups.py b/src/sage/categories/examples/finite_semigroups.py index bf00b415b58..60766b5d9d0 100644 --- a/src/sage/categories/examples/finite_semigroups.py +++ b/src/sage/categories/examples/finite_semigroups.py @@ -70,9 +70,9 @@ class LeftRegularBand(UniqueRepresentation, Parent): Now, let us look at the structure of the semigroup:: sage: S = FiniteSemigroups().example(alphabet = ('a','b','c')) - sage: S.cayley_graph(side="left", simple=True).plot() # optional - sage.graphs + sage: S.cayley_graph(side="left", simple=True).plot() # needs sage.graphs sage.plot Graphics object consisting of 60 graphics primitives - sage: S.j_transversal_of_idempotents() # random (arbitrary choice) # optional - sage.graphs + sage: S.j_transversal_of_idempotents() # random (arbitrary choice) # needs sage.graphs ['acb', 'ac', 'ab', 'bc', 'a', 'c', 'b'] We conclude by running systematic tests on this semigroup:: diff --git a/src/sage/categories/examples/finite_weyl_groups.py b/src/sage/categories/examples/finite_weyl_groups.py index b4d6c05a233..478728c9f0f 100644 --- a/src/sage/categories/examples/finite_weyl_groups.py +++ b/src/sage/categories/examples/finite_weyl_groups.py @@ -59,7 +59,7 @@ class SymmetricGroup(UniqueRepresentation, Parent): 24 sage: S.long_element() (3, 2, 1, 0) - sage: S.cayley_graph(side="left").plot() # optional - sage.graphs sage.plot + sage: S.cayley_graph(side="left").plot() # needs sage.graphs sage.plot Graphics object consisting of 120 graphics primitives Alternatively, one could have implemented @@ -69,7 +69,7 @@ class SymmetricGroup(UniqueRepresentation, Parent): TESTS:: - sage: TestSuite(S).run() # optional - sage.combinat + sage: TestSuite(S).run() """ def __init__(self, n=4): @@ -135,7 +135,7 @@ def cartan_type(self): EXAMPLES:: - sage: FiniteWeylGroups().example().cartan_type() # optional - sage.combinat + sage: FiniteWeylGroups().example().cartan_type() # needs sage.modules ['A', 3] relabelled by {1: 0, 2: 1, 3: 2} """ from sage.combinat.root_system.cartan_type import CartanType diff --git a/src/sage/categories/examples/graded_connected_hopf_algebras_with_basis.py b/src/sage/categories/examples/graded_connected_hopf_algebras_with_basis.py index 2d2a0f71f4b..07afa9c44ec 100644 --- a/src/sage/categories/examples/graded_connected_hopf_algebras_with_basis.py +++ b/src/sage/categories/examples/graded_connected_hopf_algebras_with_basis.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.modules +# sage.doctest: needs sage.modules r""" Examples of graded connected Hopf algebras with basis """ diff --git a/src/sage/categories/examples/graded_modules_with_basis.py b/src/sage/categories/examples/graded_modules_with_basis.py index 86aa957c404..8095beb11c2 100644 --- a/src/sage/categories/examples/graded_modules_with_basis.py +++ b/src/sage/categories/examples/graded_modules_with_basis.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.combinat +# sage.doctest: needs sage.combinat r""" Examples of graded modules with basis """ @@ -35,7 +35,7 @@ class GradedPartitionModule(CombinatorialFreeModule): :: - sage: A = GradedModulesWithBasis(QQ).example() + sage: A = GradedModulesWithBasis(QQ).example() # needs sage.modules - A basis function - this module is graded by the non-negative integers, so there is a function defined in this module, @@ -45,9 +45,9 @@ class GradedPartitionModule(CombinatorialFreeModule): :: - sage: A.basis(2) + sage: A.basis(2) # needs sage.modules Lazy family (Term map from Partitions to An example of a graded module with basis: the free module on partitions over Rational Field(i))_{i in Partitions of the integer 2} - sage: A.basis(6)[Partition([3,2,1])] + sage: A.basis(6)[Partition([3,2,1])] # needs sage.modules P[3, 2, 1] - If the algebra is called ``A``, then its basis function is @@ -58,7 +58,7 @@ class GradedPartitionModule(CombinatorialFreeModule): :: - sage: [m for m in A.basis(4)] + sage: [m for m in A.basis(4)] # needs sage.modules [P[4], P[3, 1], P[2, 2], P[2, 1, 1], P[1, 1, 1, 1]] - For dealing with basis elements: :meth:`degree_on_basis`, and @@ -72,9 +72,9 @@ class GradedPartitionModule(CombinatorialFreeModule): :: - sage: A.degree_on_basis(Partition([4,3])) + sage: A.degree_on_basis(Partition([4,3])) # needs sage.modules 7 - sage: A._repr_term(Partition([4,3])) + sage: A._repr_term(Partition([4,3])) # needs sage.modules 'P[4, 3]' - There is a class for elements, which inherits from @@ -88,20 +88,20 @@ class GradedPartitionModule(CombinatorialFreeModule): :: - sage: p = A.monomial(Partition([3,2,1])); p + sage: p = A.monomial(Partition([3,2,1])); p # needs sage.modules P[3, 2, 1] - sage: p.is_homogeneous() + sage: p.is_homogeneous() # needs sage.modules True - sage: p.degree() + sage: p.degree() # needs sage.modules 6 """ def __init__(self, base_ring): """ EXAMPLES:: - sage: A = GradedModulesWithBasis(QQ).example(); A + sage: A = GradedModulesWithBasis(QQ).example(); A # needs sage.modules An example of a graded module with basis: the free module on partitions over Rational Field - sage: TestSuite(A).run() + sage: TestSuite(A).run() # needs sage.modules """ CombinatorialFreeModule.__init__(self, base_ring, Partitions(), category=GradedModulesWithBasis(base_ring)) @@ -125,6 +125,7 @@ def degree_on_basis(self, t): EXAMPLES:: + sage: # needs sage.modules sage: A = GradedModulesWithBasis(QQ).example() sage: A.degree_on_basis(Partition((2,1))) 3 @@ -141,7 +142,7 @@ def _repr_(self): EXAMPLES:: - sage: GradedModulesWithBasis(QQ).example() # indirect doctest + sage: GradedModulesWithBasis(QQ).example() # indirect doctest # needs sage.modules An example of a graded module with basis: the free module on partitions over Rational Field """ return "An example of a graded module with basis: the free module on partitions over %s" % self.base_ring() @@ -156,8 +157,8 @@ def _repr_term(self, t): EXAMPLES:: - sage: A = GradedModulesWithBasis(QQ).example() - sage: A._repr_term(Partition((4,2,1))) + sage: A = GradedModulesWithBasis(QQ).example() # needs sage.modules + sage: A._repr_term(Partition((4,2,1))) # needs sage.modules 'P[4, 2, 1]' """ return 'P' + t._repr_() diff --git a/src/sage/categories/examples/hopf_algebras_with_basis.py b/src/sage/categories/examples/hopf_algebras_with_basis.py index 265ab46836f..8c9a091b93e 100644 --- a/src/sage/categories/examples/hopf_algebras_with_basis.py +++ b/src/sage/categories/examples/hopf_algebras_with_basis.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.modules +# sage.doctest: needs sage.groups sage.modules r""" Examples of Hopf algebras with basis """ diff --git a/src/sage/categories/examples/lie_algebras.py b/src/sage/categories/examples/lie_algebras.py index 81c7f8457ab..2382f1d0e7b 100644 --- a/src/sage/categories/examples/lie_algebras.py +++ b/src/sage/categories/examples/lie_algebras.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.modules +# sage.doctest: needs sage.modules r""" Examples of a Lie algebra """ @@ -69,11 +69,12 @@ def __classcall_private__(cls, gens): EXAMPLES:: - sage: S3 = SymmetricGroupAlgebra(QQ, 3) # optional - sage.combinat - sage: L1 = LieAlgebras(QQ).example() # optional - sage.combinat - sage: gens = list(S3.algebra_generators()) # optional - sage.combinat - sage: L2 = LieAlgebras(QQ).example(gens) # optional - sage.combinat - sage: L1 is L2 # optional - sage.combinat + sage: # needs sage.combinat + sage: S3 = SymmetricGroupAlgebra(QQ, 3) + sage: L1 = LieAlgebras(QQ).example() + sage: gens = list(S3.algebra_generators()) + sage: L2 = LieAlgebras(QQ).example(gens) + sage: L1 is L2 True """ return super().__classcall__(cls, tuple(gens)) @@ -82,8 +83,8 @@ def __init__(self, gens): """ EXAMPLES:: - sage: L = LieAlgebras(QQ).example() # optional - sage.combinat - sage: TestSuite(L).run() # optional - sage.combinat + sage: L = LieAlgebras(QQ).example() # needs sage.combinat + sage: TestSuite(L).run() # needs sage.combinat """ if not gens: raise ValueError("need at least one generator") @@ -96,7 +97,7 @@ def _repr_(self): """ EXAMPLES:: - sage: LieAlgebras(QQ).example() # optional - sage.combinat sage.groups + sage: LieAlgebras(QQ).example() # needs sage.combinat sage.groups An example of a Lie algebra: the Lie algebra from the associative algebra Symmetric group algebra of order 3 over Rational Field generated by ([2, 1, 3], [2, 3, 1]) @@ -111,10 +112,11 @@ def _element_constructor_(self, value): EXAMPLES:: - sage: S3 = SymmetricGroupAlgebra(ZZ, 3) # optional - sage.combinat sage.groups - sage: gens = S3.algebra_generators() # optional - sage.combinat sage.groups - sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups - sage: L(3*gens[0] + gens[1]) # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: S3 = SymmetricGroupAlgebra(ZZ, 3) + sage: gens = S3.algebra_generators() + sage: L = LieAlgebras(QQ).example() + sage: L(3*gens[0] + gens[1]) 3*[2, 1, 3] + [2, 3, 1] """ return self.element_class(self, self._A(value)) @@ -125,8 +127,8 @@ def zero(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups - sage: L.zero() # optional - sage.combinat sage.groups + sage: L = LieAlgebras(QQ).example() # needs sage.combinat sage.groups + sage: L.zero() # needs sage.combinat sage.groups 0 """ return self.element_class(self, self._A.zero()) @@ -137,8 +139,8 @@ def lie_algebra_generators(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups - sage: L.lie_algebra_generators() # optional - sage.combinat sage.groups + sage: L = LieAlgebras(QQ).example() # needs sage.combinat sage.groups + sage: L.lie_algebra_generators() # needs sage.combinat sage.groups Family ([2, 1, 3], [2, 3, 1]) """ return Family([self.element_class(self, g) for g in self._gens]) @@ -158,17 +160,18 @@ def __eq__(self, rhs): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups - sage: x, y = L.lie_algebra_generators() # optional - sage.combinat sage.groups - sage: x == x # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: L = LieAlgebras(QQ).example() + sage: x, y = L.lie_algebra_generators() + sage: x == x True - sage: x.bracket(y) == -y.bracket(x) # optional - sage.combinat sage.groups + sage: x.bracket(y) == -y.bracket(x) True - sage: x == y # optional - sage.combinat sage.groups + sage: x == y False - sage: x.bracket(x) == L.zero() # optional - sage.combinat sage.groups + sage: x.bracket(x) == L.zero() True - sage: x.bracket(x) == 0 # optional - sage.combinat sage.groups + sage: x.bracket(x) == 0 True """ if not isinstance(rhs, LieAlgebraFromAssociative.Element): @@ -181,15 +184,16 @@ def __ne__(self, rhs): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups - sage: x, y = L.lie_algebra_generators() # optional - sage.combinat sage.groups - sage: x != y # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: L = LieAlgebras(QQ).example() + sage: x, y = L.lie_algebra_generators() + sage: x != y True - sage: x != 0 # optional - sage.combinat sage.groups + sage: x != 0 True - sage: x != x # optional - sage.combinat sage.groups + sage: x != x False - sage: x.bracket(y) != -y.bracket(x) # optional - sage.combinat sage.groups + sage: x.bracket(y) != -y.bracket(x) False """ return not self.__eq__(rhs) @@ -200,10 +204,10 @@ def __bool__(self) -> bool: EXAMPLES:: - sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups - sage: bool(sum(L.lie_algebra_generators())) # optional - sage.combinat sage.groups + sage: L = LieAlgebras(QQ).example() # needs sage.combinat sage.groups + sage: bool(sum(L.lie_algebra_generators())) # needs sage.combinat sage.groups True - sage: bool(L.zero()) # optional - sage.combinat sage.groups + sage: bool(L.zero()) # needs sage.combinat sage.groups False """ return bool(self.value) @@ -214,9 +218,9 @@ def _add_(self, rhs): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups - sage: x, y = L.lie_algebra_generators() # optional - sage.combinat sage.groups - sage: x + y # optional - sage.combinat sage.groups + sage: L = LieAlgebras(QQ).example() # needs sage.combinat sage.groups + sage: x, y = L.lie_algebra_generators() # needs sage.combinat sage.groups + sage: x + y # needs sage.combinat sage.groups [2, 1, 3] + [2, 3, 1] """ return self.__class__(self.parent(), self.value + rhs.value) @@ -227,9 +231,9 @@ def _sub_(self, rhs): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups - sage: x, y = L.lie_algebra_generators() # optional - sage.combinat sage.groups - sage: x - y # optional - sage.combinat sage.groups + sage: L = LieAlgebras(QQ).example() # needs sage.combinat sage.groups + sage: x, y = L.lie_algebra_generators() # needs sage.combinat sage.groups + sage: x - y # needs sage.combinat sage.groups [2, 1, 3] - [2, 3, 1] """ return self.__class__(self.parent(), self.value - rhs.value) @@ -240,9 +244,9 @@ def _acted_upon_(self, scalar, self_on_left=False): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups - sage: x, y = L.lie_algebra_generators() # optional - sage.combinat sage.groups - sage: 3 * x # optional - sage.combinat sage.groups + sage: L = LieAlgebras(QQ).example() # needs sage.combinat sage.groups + sage: x, y = L.lie_algebra_generators() # needs sage.combinat sage.groups + sage: 3 * x # needs sage.combinat sage.groups 3*[2, 1, 3] """ # This was copied, but IDK if it still applies: @@ -266,9 +270,9 @@ def __truediv__(self, x, self_on_left=False): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups - sage: x, y = L.lie_algebra_generators() # optional - sage.combinat sage.groups - sage: y / 4 # optional - sage.combinat sage.groups + sage: L = LieAlgebras(QQ).example() # needs sage.combinat sage.groups + sage: x, y = L.lie_algebra_generators() # needs sage.combinat sage.groups + sage: y / 4 # needs sage.combinat sage.groups 1/4*[2, 3, 1] """ if self_on_left: @@ -281,9 +285,9 @@ def __neg__(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups - sage: x, y = L.lie_algebra_generators() # optional - sage.combinat sage.groups - sage: -x # optional - sage.combinat sage.groups + sage: L = LieAlgebras(QQ).example() # needs sage.combinat sage.groups + sage: x, y = L.lie_algebra_generators() # needs sage.combinat sage.groups + sage: -x # needs sage.combinat sage.groups -[2, 1, 3] """ return self.__class__(self.parent(), -self.value) @@ -314,15 +318,16 @@ def _bracket_(self, rhs): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups - sage: x,y = L.lie_algebra_generators() # optional - sage.combinat sage.groups - sage: elt = 2*x - y # optional - sage.combinat sage.groups - sage: elt.bracket(elt) # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: L = LieAlgebras(QQ).example() + sage: x,y = L.lie_algebra_generators() + sage: elt = 2*x - y + sage: elt.bracket(elt) 0 - sage: elt.bracket(x) # optional - sage.combinat sage.groups + sage: elt.bracket(x) -[1, 3, 2] + [3, 2, 1] - sage: elt2 = x.bracket(y) + x # optional - sage.combinat sage.groups - sage: elt.bracket(elt2) # optional - sage.combinat sage.groups + sage: elt2 = x.bracket(y) + x + sage: elt.bracket(elt2) -2*[2, 1, 3] + 4*[2, 3, 1] - 4*[3, 1, 2] + 2*[3, 2, 1] """ return self.__class__(self.parent(), self.value * rhs.value - rhs.value * self.value) diff --git a/src/sage/categories/examples/lie_algebras_with_basis.py b/src/sage/categories/examples/lie_algebras_with_basis.py index e69711ddf03..a92f51b49db 100644 --- a/src/sage/categories/examples/lie_algebras_with_basis.py +++ b/src/sage/categories/examples/lie_algebras_with_basis.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.modules +# sage.doctest: needs sage.combinat sage.modules r""" Examples of a Lie algebra with basis """ diff --git a/src/sage/categories/examples/sets_cat.py b/src/sage/categories/examples/sets_cat.py index fbd7d8b1fc8..5eecd22be4c 100644 --- a/src/sage/categories/examples/sets_cat.py +++ b/src/sage/categories/examples/sets_cat.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.libs.pari +# sage.doctest: needs sage.libs.pari """ Examples of sets """ diff --git a/src/sage/categories/examples/with_realizations.py b/src/sage/categories/examples/with_realizations.py index 627bd2a07c3..373e0f383e8 100644 --- a/src/sage/categories/examples/with_realizations.py +++ b/src/sage/categories/examples/with_realizations.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.combinat sage.modules +# sage.doctest: needs sage.combinat sage.modules r""" Examples of parents endowed with multiple realizations """ diff --git a/src/sage/categories/fields.py b/src/sage/categories/fields.py index 28a93a314b5..2ed63782ec5 100644 --- a/src/sage/categories/fields.py +++ b/src/sage/categories/fields.py @@ -38,10 +38,10 @@ class Fields(CategoryWithAxiom): sage: K(IntegerRing()) Rational Field - sage: K(PolynomialRing(GF(3), 'x')) # optional - sage.rings.finite_rings + sage: K(PolynomialRing(GF(3), 'x')) Fraction Field of Univariate Polynomial Ring in x over Finite Field of size 3 - sage: K(RealField()) + sage: K(RealField()) # needs sage.rings.real_mpfr Real Field with 53 bits of precision TESTS:: @@ -64,7 +64,7 @@ def __contains__(self, x): """ EXAMPLES:: - sage: GF(4, "a") in Fields() # optional - sage.rings.finite_rings + sage: GF(4, "a") in Fields() # needs sage.rings.finite_rings True sage: QQ in Fields() True @@ -81,15 +81,15 @@ def __contains__(self, x): Caveat: this should eventually be fixed:: - sage: gap.Rationals in Fields() # optional - sage.libs.gap + sage: gap.Rationals in Fields() # needs sage.libs.gap False typically by implementing the method :meth:`category` appropriately for Gap objects:: - sage: GR = gap.Rationals # optional - sage.libs.gap - sage: GR.category = lambda: Fields() # optional - sage.libs.gap - sage: GR in Fields() # optional - sage.libs.gap + sage: GR = gap.Rationals # needs sage.libs.gap + sage: GR.category = lambda: Fields() # needs sage.libs.gap + sage: GR in Fields() # needs sage.libs.gap True The following tests against a memory leak fixed in :trac:`13370`. In order @@ -101,7 +101,7 @@ def __contains__(self, x): sage: _ = gc.collect() sage: permstore = [X for X in gc.get_objects() if isinstance(X, sage.rings.finite_rings.integer_mod_ring.IntegerModRing_generic)] sage: n = len(permstore) - sage: for i in prime_range(100): # optional - sage.libs.pari + sage: for i in prime_range(100): # needs sage.libs.pari ....: R = ZZ.quotient(i) ....: t = R in Fields() @@ -139,17 +139,18 @@ def _contains_helper(cls): TESTS:: + sage: # needs sage.libs.pari sage: P. = QQ[] - sage: Q = P.quotient(x^2 + 2) # optional - sage.libs.pari - sage: Q.category() # optional - sage.libs.pari + sage: Q = P.quotient(x^2 + 2) + sage: Q.category() Category of commutative no zero divisors quotients of algebras over (number fields and quotient fields and metric spaces) sage: F = Fields() - sage: F._contains_helper(Q) # optional - sage.libs.pari + sage: F._contains_helper(Q) False - sage: Q in F # This changes the category! # optional - sage.libs.pari + sage: Q in F # This changes the category! True - sage: F._contains_helper(Q) # optional - sage.libs.pari + sage: F._contains_helper(Q) True """ @@ -167,12 +168,12 @@ def _call_(self, x): sage: Fields().super_categories() [Category of euclidean domains, Category of division rings] - sage: K(IntegerRing()) # indirect doctest + sage: K(IntegerRing()) # indirect doctest Rational Field - sage: K(PolynomialRing(GF(3), 'x')) # indirect doctest # optional - sage.rings.finite_rings + sage: K(PolynomialRing(GF(3), 'x')) # indirect doctest Fraction Field of Univariate Polynomial Ring in x over Finite Field of size 3 - sage: K(RealField()) + sage: K(RealField()) # needs sage.rings.real_mpfr Real Field with 53 bits of precision """ try: @@ -207,11 +208,11 @@ def is_integrally_closed(self): sage: QQ.is_integrally_closed() True - sage: QQbar.is_integrally_closed() # optional - sage.rings.number_field + sage: QQbar.is_integrally_closed() # needs sage.rings.number_field True - sage: Z5 = GF(5); Z5 # optional - sage.rings.finite_rings + sage: Z5 = GF(5); Z5 Finite Field of size 5 - sage: Z5.is_integrally_closed() # optional - sage.rings.finite_rings + sage: Z5.is_integrally_closed() True """ return True @@ -231,14 +232,15 @@ def _gcd_univariate_polynomial(self, a, b): EXAMPLES:: - sage: R. = QQbar[] # optional - sage.rings.number_field - sage: QQbar._gcd_univariate_polynomial(2*x, 2*x^2) # optional - sage.rings.number_field + sage: R. = QQbar[] # needs sage.rings.number_field + sage: QQbar._gcd_univariate_polynomial(2*x, 2*x^2) # needs sage.rings.number_field x TESTS:: - sage: fields = [RR, CC] - sage: fields.append(QQbar) # optional - sage.rings.number_field + sage: fields = [] + sage: fields += [RR, CC] # needs sage.rings.real_mpfr + sage: fields.append(QQbar) # needs sage.rings.number_field sage: for A in fields: ....: g = A._gcd_univariate_polynomial ....: R. = A[] @@ -248,10 +250,11 @@ def _gcd_univariate_polynomial(self, a, b): ....: g(2*x, z) == x and ....: g(z, z) == z) + sage: # needs sage.rings.real_mpfr sage: R. = RR[] - sage: (x^3).gcd(x^5+1) + sage: (x^3).gcd(x^5 + 1) 1.00000000000000 - sage: (x^3).gcd(x^5+x^2) + sage: (x^3).gcd(x^5 + x^2) x^2 sage: f = (x+3)^2 * (x-1) sage: g = (x+3)^5 @@ -261,6 +264,7 @@ def _gcd_univariate_polynomial(self, a, b): The following example illustrates the fact that for inexact base rings, the returned gcd is often 1 due to rounding:: + sage: # needs sage.rings.real_mpfr sage: f = (x+RR.pi())^2 * (x-1) sage: g = (x+RR.pi())^5 sage: f.gcd(g) @@ -268,8 +272,9 @@ def _gcd_univariate_polynomial(self, a, b): Check :trac:`23012`:: + sage: # needs sage.libs.pari sage: R. = QQ[] - sage: Q = R.quotient(x^2-1) # Not a field + sage: Q = R.quotient(x^2 - 1) # Not a field sage: P. = Q[] sage: def always_True(*args, **kwds): return True sage: Q.is_field = always_True @@ -332,8 +337,9 @@ def _xgcd_univariate_polynomial(self, a, b): TESTS:: - sage: fields = [RR, CC] - sage: fields.append(QQbar) # optional - sage.rings.number_field + sage: fields = [] + sage: fields += [RR, CC] # needs sage.rings.real_mpfr + sage: fields.append(QQbar) # needs sage.rings.number_field sage: for A in fields: ....: g = A._xgcd_univariate_polynomial ....: R. = A[] @@ -354,6 +360,7 @@ def _xgcd_univariate_polynomial(self, a, b): We check that the behavior of xgcd with zero elements is compatible with gcd (:trac:`17671`):: + sage: # needs sage.rings.number_field sage: R. = QQbar[] sage: zero = R.zero() sage: zero.xgcd(2*x) @@ -392,9 +399,9 @@ def is_perfect(self): sage: QQ.is_perfect() True - sage: GF(2).is_perfect() # optional - sage.rings.finite_rings + sage: GF(2).is_perfect() True - sage: FunctionField(GF(2), 'x').is_perfect() # optional - sage.rings.finite_rings + sage: FunctionField(GF(2), 'x').is_perfect() False """ @@ -468,11 +475,11 @@ def _squarefree_decomposition_univariate_polynomial(self, f): sage: p = 37 * (x-2/3)^2 sage: p.squarefree_decomposition() (37) * (x - 2/3)^2 - sage: x = polygen(GF(3)) # optional - sage.rings.finite_rings - sage: x.squarefree_decomposition() # optional - sage.rings.finite_rings + sage: x = polygen(GF(3)) + sage: x.squarefree_decomposition() x - sage: f = QQbar['x'](1) # optional - sage.rings.number_field - sage: f.squarefree_decomposition() # optional - sage.rings.number_field + sage: f = QQbar['x'](1) # needs sage.rings.number_field + sage: f.squarefree_decomposition() # needs sage.rings.number_field 1 """ from sage.structure.factorization import Factorization @@ -529,10 +536,11 @@ def vector_space(self, *args, **kwds): EXAMPLES:: - sage: K. = Qq(125) # optional - sage.rings.padics - sage: V, fr, to = K.vector_space() # optional - sage.rings.padics - sage: v = V([1, 2, 3]) # optional - sage.rings.padics - sage: fr(v, 7) # optional - sage.rings.padics + sage: # needs sage.rings.padics + sage: K. = Qq(125) + sage: V, fr, to = K.vector_space() + sage: v = V([1, 2, 3]) + sage: fr(v, 7) (3*a^2 + 2*a + 1) + O(5^7) """ return self.free_module(*args, **kwds) @@ -605,12 +613,12 @@ def gcd(self,other): EXAMPLES:: - sage: K = GF(5) # optional - sage.rings.finite_rings - sage: K(2).gcd(K(1)) # optional - sage.rings.finite_rings + sage: K = GF(5) + sage: K(2).gcd(K(1)) 1 - sage: K(0).gcd(K(0)) # optional - sage.rings.finite_rings + sage: K(0).gcd(K(0)) 0 - sage: all(x.gcd(y) == (0 if x == 0 and y == 0 else 1) # optional - sage.rings.finite_rings + sage: all(x.gcd(y) == (0 if x == 0 and y == 0 else 1) ....: for x in K for y in K) True @@ -663,9 +671,9 @@ def lcm(self, other): EXAMPLES:: - sage: GF(2)(1).lcm(GF(2)(0)) # optional - sage.rings.finite_rings + sage: GF(2)(1).lcm(GF(2)(0)) 0 - sage: GF(2)(1).lcm(GF(2)(1)) # optional - sage.rings.finite_rings + sage: GF(2)(1).lcm(GF(2)(1)) 1 For field of characteristic zero, the lcm of integers is considered @@ -726,14 +734,14 @@ def xgcd(self, other): EXAMPLES:: - sage: K = GF(5) # optional - sage.rings.finite_rings - sage: K(2).xgcd(K(1)) # optional - sage.rings.finite_rings + sage: K = GF(5) + sage: K(2).xgcd(K(1)) (1, 3, 0) - sage: K(0).xgcd(K(4)) # optional - sage.rings.finite_rings + sage: K(0).xgcd(K(4)) (1, 0, 4) - sage: K(1).xgcd(K(1)) # optional - sage.rings.finite_rings + sage: K(1).xgcd(K(1)) (1, 1, 0) - sage: GF(5)(0).xgcd(GF(5)(0)) # optional - sage.rings.finite_rings + sage: GF(5)(0).xgcd(GF(5)(0)) (0, 0, 0) The xgcd of non-zero floating point numbers will be a triple of @@ -777,8 +785,8 @@ def factor(self): EXAMPLES:: - sage: x = GF(7)(5) # optional - sage.rings.finite_rings - sage: x.factor() # optional - sage.rings.finite_rings + sage: x = GF(7)(5) + sage: x.factor() 5 sage: RR(0).factor() Traceback (most recent call last): @@ -797,7 +805,7 @@ def inverse_of_unit(self): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: NumberField(x^7+2, 'a')(2).inverse_of_unit() # optional - sage.rings.number_field + sage: NumberField(x^7 + 2, 'a')(2).inverse_of_unit() # needs sage.rings.number_field 1/2 Trying to invert the zero element typically raises a diff --git a/src/sage/categories/filtered_algebras_with_basis.py b/src/sage/categories/filtered_algebras_with_basis.py index 90c7078e6cc..1abddc81a18 100644 --- a/src/sage/categories/filtered_algebras_with_basis.py +++ b/src/sage/categories/filtered_algebras_with_basis.py @@ -321,6 +321,7 @@ def induced_graded_map(self, other, f): `f` will lead into a graded algebra already, namely into the algebra of symmetric functions:: + sage: # needs sage.combinat sage.modules sage: h = SymmetricFunctions(QQ).h() sage: def map_on_basis(m): # redefining map_on_basis ....: d = m.dict() @@ -351,6 +352,7 @@ def induced_graded_map(self, other, f): is already graded, so its associated graded algebra is implemented as itself:: + sage: # needs sage.combinat sage.modules sage: grh = h.graded_algebra(); grh is h True sage: grf = A.induced_graded_map(h, f); grf @@ -384,6 +386,7 @@ def induced_graded_map(self, other, f): have one as the domain instead. Our new ``f`` will go from ``h`` to ``A``:: + sage: # needs sage.combinat sage.modules sage: def map_on_basis(lam): # redefining map_on_basis ....: return x ** (sum(lam)) + y ** (len(lam)) sage: f = h.module_morphism(on_basis=map_on_basis, @@ -426,6 +429,7 @@ def induced_graded_map(self, other, f): The construct `\operatorname{gr} f` also makes sense when `f` is a filtration-preserving map between graded algebras. :: + sage: # needs sage.combinat sage.modules sage: def map_on_basis(lam): # redefining map_on_basis ....: return h[lam] + h[len(lam)] sage: f = h.module_morphism(on_basis=map_on_basis, @@ -459,6 +463,7 @@ def induced_graded_map(self, other, f): For another example, let us compute `\operatorname{gr} f` for a map `f` between two Clifford algebras:: + sage: # needs sage.modules sage: Q = QuadraticForm(ZZ, 2, [1,2,3]) sage: B = CliffordAlgebra(Q, names=['u','v']); B The Clifford algebra of the Quadratic form in 2 diff --git a/src/sage/categories/filtered_hopf_algebras_with_basis.py b/src/sage/categories/filtered_hopf_algebras_with_basis.py index ca2dc9ac513..0310744d9e1 100644 --- a/src/sage/categories/filtered_hopf_algebras_with_basis.py +++ b/src/sage/categories/filtered_hopf_algebras_with_basis.py @@ -88,14 +88,15 @@ def antipode_on_basis(self, index): TESTS:: - sage: H = GradedHopfAlgebrasWithBasis(QQ).Connected().example() # optional - sage.combinat - sage: H.monomial(0).antipode() # indirect doctest # optional - sage.combinat + sage: # needs sage.modules + sage: H = GradedHopfAlgebrasWithBasis(QQ).Connected().example() + sage: H.monomial(0).antipode() # indirect doctest P0 - sage: H.monomial(1).antipode() # indirect doctest # optional - sage.combinat + sage: H.monomial(1).antipode() # indirect doctest -P1 - sage: H.monomial(2).antipode() # indirect doctest # optional - sage.combinat + sage: H.monomial(2).antipode() # indirect doctest P2 - sage: H.monomial(3).antipode() # indirect doctest # optional - sage.combinat + sage: H.monomial(3).antipode() # indirect doctest -P3 """ if self.monomial(index) == self.one(): @@ -116,15 +117,15 @@ def antipode(self, elem): TESTS:: - sage: H = GradedHopfAlgebrasWithBasis(QQ).Connected().example() # optional - sage.combinat - sage: H.antipode(H.monomial(14)) # optional - sage.combinat + sage: H = GradedHopfAlgebrasWithBasis(QQ).Connected().example() # needs sage.modules + sage: H.antipode(H.monomial(14)) # needs sage.modules P14 - sage: H.monomial(0).antipode() # optional - sage.combinat + sage: H.monomial(0).antipode() # needs sage.modules P0 - sage: H.monomial(2).antipode() # optional - sage.combinat + sage: H.monomial(2).antipode() # needs sage.modules P2 - sage: (2*H.monomial(1) + 3*H.monomial(4)).antipode() # optional - sage.combinat + sage: (2*H.monomial(1) + 3*H.monomial(4)).antipode() # needs sage.modules -2*P1 + 3*P4 """ return self.linear_combination( diff --git a/src/sage/categories/filtered_modules_with_basis.py b/src/sage/categories/filtered_modules_with_basis.py index 7a9b2684f79..15d0f490713 100644 --- a/src/sage/categories/filtered_modules_with_basis.py +++ b/src/sage/categories/filtered_modules_with_basis.py @@ -205,6 +205,7 @@ def homogeneous_component_basis(self, d): to An example of a graded module with basis: the free module on partitions over Integer Ring(i))_{i in Partitions of the integer 4} + sage: # needs sage.modules sage: cat = GradedModulesWithBasis(ZZ) sage: C = CombinatorialFreeModule(ZZ, ['a', 'b'], category=cat) sage: C.degree_on_basis = lambda x: 1 if x == 'a' else 2 @@ -318,12 +319,13 @@ def to_graded_conversion(self): EXAMPLES:: - sage: A = Modules(QQ).WithBasis().Filtered().example() # optional - sage.combinat - sage: p = -2 * A.an_element(); p # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: A = Modules(QQ).WithBasis().Filtered().example() + sage: p = -2 * A.an_element(); p -4*P[] - 4*P[1] - 6*P[2] - sage: q = A.to_graded_conversion()(p); q # optional - sage.combinat + sage: q = A.to_graded_conversion()(p); q -4*Bbar[[]] - 4*Bbar[[1]] - 6*Bbar[[2]] - sage: q.parent() is A.graded_algebra() # optional - sage.combinat + sage: q.parent() is A.graded_algebra() True """ base_one = self.base_ring().one() @@ -346,14 +348,15 @@ def from_graded_conversion(self): EXAMPLES:: - sage: A = Modules(QQ).WithBasis().Filtered().example() # optional - sage.combinat - sage: p = -2 * A.an_element(); p # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: A = Modules(QQ).WithBasis().Filtered().example() + sage: p = -2 * A.an_element(); p -4*P[] - 4*P[1] - 6*P[2] - sage: q = A.to_graded_conversion()(p); q # optional - sage.combinat + sage: q = A.to_graded_conversion()(p); q -4*Bbar[[]] - 4*Bbar[[1]] - 6*Bbar[[2]] - sage: A.from_graded_conversion()(q) == p # optional - sage.combinat + sage: A.from_graded_conversion()(q) == p True - sage: q.parent() is A.graded_algebra() # optional - sage.combinat + sage: q.parent() is A.graded_algebra() True """ base_one = self.base_ring().one() @@ -378,14 +381,15 @@ def projection(self, i): EXAMPLES:: - sage: A = Modules(ZZ).WithBasis().Filtered().example() # optional - sage.combinat - sage: p = -2 * A.an_element(); p # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: A = Modules(ZZ).WithBasis().Filtered().example() + sage: p = -2 * A.an_element(); p -4*P[] - 4*P[1] - 6*P[2] - sage: q = A.projection(2)(p); q # optional - sage.combinat + sage: q = A.projection(2)(p); q -6*Bbar[[2]] - sage: q.parent() is A.graded_algebra() # optional - sage.combinat + sage: q.parent() is A.graded_algebra() True - sage: A.projection(3)(p) # optional - sage.combinat + sage: A.projection(3)(p) 0 """ base_zero = self.base_ring().zero() @@ -439,12 +443,12 @@ def induced_graded_map(self, other, f): We start with the free `\QQ`-module with basis the set of all partitions:: - sage: A = Modules(QQ).WithBasis().Filtered().example(); A # optional - sage.combinat + sage: A = Modules(QQ).WithBasis().Filtered().example(); A # needs sage.combinat sage.modules An example of a filtered module with basis: the free module on partitions over Rational Field - sage: M = A.indices(); M # optional - sage.combinat + sage: M = A.indices(); M # needs sage.combinat sage.modules Partitions - sage: p1, p2, p21, p321 = [A.basis()[Partition(i)] # optional - sage.combinat + sage: p1, p2, p21, p321 = [A.basis()[Partition(i)] # needs sage.combinat sage.modules ....: for i in [[1], [2], [2,1], [3,2,1]]] Let us define a map from ``A`` to itself which acts on the @@ -452,42 +456,44 @@ def induced_graded_map(self, other, f): the conjugates of all partitions `\mu` for which `\lambda / \mu` is a horizontal strip:: - sage: def map_on_basis(lam): # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: def map_on_basis(lam): ....: def mus(k): ....: return lam.remove_horizontal_border_strip(k) ....: return A.sum_of_monomials([Partition(mu).conjugate() ....: for k in range(sum(lam) + 1) ....: for mu in mus(k)]) - sage: f = A.module_morphism(on_basis=map_on_basis, # optional - sage.combinat + sage: f = A.module_morphism(on_basis=map_on_basis, ....: codomain=A) - sage: f(p1) # optional - sage.combinat + sage: f(p1) P[] + P[1] - sage: f(p2) # optional - sage.combinat + sage: f(p2) P[] + P[1] + P[1, 1] - sage: f(p21) # optional - sage.combinat + sage: f(p21) P[1] + P[1, 1] + P[2] + P[2, 1] - sage: f(p21 - p1) # optional - sage.combinat + sage: f(p21 - p1) -P[] + P[1, 1] + P[2] + P[2, 1] - sage: f(p321) # optional - sage.combinat + sage: f(p321) P[2, 1] + P[2, 1, 1] + P[2, 2] + P[2, 2, 1] + P[3, 1] + P[3, 1, 1] + P[3, 2] + P[3, 2, 1] We now compute `\operatorname{gr} f` :: - sage: grA = A.graded_algebra(); grA # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: grA = A.graded_algebra(); grA Graded Module of An example of a filtered module with basis: the free module on partitions over Rational Field - sage: pp1, pp2, pp21, pp321 = [A.to_graded_conversion()(i) # optional - sage.combinat + sage: pp1, pp2, pp21, pp321 = [A.to_graded_conversion()(i) ....: for i in [p1, p2, p21, p321]] - sage: pp2 + 4 * pp21 # optional - sage.combinat + sage: pp2 + 4 * pp21 Bbar[[2]] + 4*Bbar[[2, 1]] - sage: grf = A.induced_graded_map(A, f); grf # optional - sage.combinat + sage: grf = A.induced_graded_map(A, f); grf Generic endomorphism of Graded Module of An example of a filtered module with basis: the free module on partitions over Rational Field - sage: grf(pp1) # optional - sage.combinat + sage: grf(pp1) Bbar[[1]] - sage: grf(pp2 + 4 * pp21) # optional - sage.combinat + sage: grf(pp2 + 4 * pp21) Bbar[[1, 1]] + 4*Bbar[[2, 1]] **Example 2.** @@ -497,48 +503,50 @@ def induced_graded_map(self, other, f): `f` will lead into a graded algebra already, namely into the algebra of symmetric functions:: - sage: h = SymmetricFunctions(QQ).h() # optional - sage.combinat - sage: def map_on_basis(lam): # redefining map_on_basis # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: h = SymmetricFunctions(QQ).h() + sage: def map_on_basis(lam): # redefining map_on_basis ....: def mus(k): ....: return lam.remove_horizontal_border_strip(k) ....: return h.sum_of_monomials([Partition(mu).conjugate() ....: for k in range(sum(lam) + 1) ....: for mu in mus(k)]) - sage: f = A.module_morphism(on_basis=map_on_basis, # optional - sage.combinat + sage: f = A.module_morphism(on_basis=map_on_basis, ....: codomain=h) # redefining f - sage: f(p1) # optional - sage.combinat + sage: f(p1) h[] + h[1] - sage: f(p2) # optional - sage.combinat + sage: f(p2) h[] + h[1] + h[1, 1] - sage: f(A.zero()) # optional - sage.combinat + sage: f(A.zero()) 0 - sage: f(p2 - 3*p1) # optional - sage.combinat + sage: f(p2 - 3*p1) -2*h[] - 2*h[1] + h[1, 1] The algebra ``h`` of symmetric functions in the `h`-basis is already graded, so its associated graded algebra is implemented as itself:: - sage: grh = h.graded_algebra(); grh is h # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: grh = h.graded_algebra(); grh is h True - sage: grf = A.induced_graded_map(h, f); grf # optional - sage.combinat + sage: grf = A.induced_graded_map(h, f); grf Generic morphism: From: Graded Module of An example of a filtered module with basis: the free module on partitions over Rational Field To: Symmetric Functions over Rational Field in the homogeneous basis - sage: grf(pp1) # optional - sage.combinat + sage: grf(pp1) h[1] - sage: grf(pp2) # optional - sage.combinat + sage: grf(pp2) h[1, 1] - sage: grf(pp321) # optional - sage.combinat + sage: grf(pp321) h[3, 2, 1] - sage: grf(pp2 - 3*pp1) # optional - sage.combinat + sage: grf(pp2 - 3*pp1) -3*h[1] + h[1, 1] - sage: grf(pp21) # optional - sage.combinat + sage: grf(pp21) h[2, 1] - sage: grf(grA.zero()) # optional - sage.combinat + sage: grf(grA.zero()) 0 **Example 3.** @@ -547,45 +555,46 @@ def induced_graded_map(self, other, f): have one as the domain instead. Our new ``f`` will go from ``h`` to ``A``:: - sage: def map_on_basis(lam): # redefining map_on_basis # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: def map_on_basis(lam): # redefining map_on_basis ....: def mus(k): ....: return lam.remove_horizontal_border_strip(k) ....: return A.sum_of_monomials([Partition(mu).conjugate() ....: for k in range(sum(lam) + 1) ....: for mu in mus(k)]) - sage: f = h.module_morphism(on_basis=map_on_basis, # optional - sage.combinat + sage: f = h.module_morphism(on_basis=map_on_basis, ....: codomain=A) # redefining f - sage: f(h[1]) # optional - sage.combinat + sage: f(h[1]) P[] + P[1] - sage: f(h[2]) # optional - sage.combinat + sage: f(h[2]) P[] + P[1] + P[1, 1] - sage: f(h[1, 1]) # optional - sage.combinat + sage: f(h[1, 1]) P[1] + P[2] - sage: f(h[2, 2]) # optional - sage.combinat + sage: f(h[2, 2]) P[1, 1] + P[2, 1] + P[2, 2] - sage: f(h[3, 2, 1]) # optional - sage.combinat + sage: f(h[3, 2, 1]) P[2, 1] + P[2, 1, 1] + P[2, 2] + P[2, 2, 1] + P[3, 1] + P[3, 1, 1] + P[3, 2] + P[3, 2, 1] - sage: f(h.one()) # optional - sage.combinat + sage: f(h.one()) P[] - sage: grf = h.induced_graded_map(A, f); grf # optional - sage.combinat + sage: grf = h.induced_graded_map(A, f); grf Generic morphism: From: Symmetric Functions over Rational Field in the homogeneous basis To: Graded Module of An example of a filtered module with basis: the free module on partitions over Rational Field - sage: grf(h[1]) # optional - sage.combinat + sage: grf(h[1]) Bbar[[1]] - sage: grf(h[2]) # optional - sage.combinat + sage: grf(h[2]) Bbar[[1, 1]] - sage: grf(h[1, 1]) # optional - sage.combinat + sage: grf(h[1, 1]) Bbar[[2]] - sage: grf(h[2, 2]) # optional - sage.combinat + sage: grf(h[2, 2]) Bbar[[2, 2]] - sage: grf(h[3, 2, 1]) # optional - sage.combinat + sage: grf(h[3, 2, 1]) Bbar[[3, 2, 1]] - sage: grf(h.one()) # optional - sage.combinat + sage: grf(h.one()) Bbar[[]] **Example 4.** @@ -593,36 +602,37 @@ def induced_graded_map(self, other, f): The construct `\operatorname{gr} f` also makes sense when `f` is a filtration-preserving map between graded modules. :: - sage: def map_on_basis(lam): # redefining map_on_basis # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: def map_on_basis(lam): # redefining map_on_basis ....: def mus(k): ....: return lam.remove_horizontal_border_strip(k) ....: return h.sum_of_monomials([Partition(mu).conjugate() ....: for k in range(sum(lam) + 1) ....: for mu in mus(k)]) - sage: f = h.module_morphism(on_basis=map_on_basis, # optional - sage.combinat + sage: f = h.module_morphism(on_basis=map_on_basis, ....: codomain=h) # redefining f - sage: f(h[1]) # optional - sage.combinat + sage: f(h[1]) h[] + h[1] - sage: f(h[2]) # optional - sage.combinat + sage: f(h[2]) h[] + h[1] + h[1, 1] - sage: f(h[1, 1]) # optional - sage.combinat + sage: f(h[1, 1]) h[1] + h[2] - sage: f(h[2, 1]) # optional - sage.combinat + sage: f(h[2, 1]) h[1] + h[1, 1] + h[2] + h[2, 1] - sage: f(h.one()) # optional - sage.combinat + sage: f(h.one()) h[] - sage: grf = h.induced_graded_map(h, f); grf # optional - sage.combinat + sage: grf = h.induced_graded_map(h, f); grf Generic endomorphism of Symmetric Functions over Rational Field in the homogeneous basis - sage: grf(h[1]) # optional - sage.combinat + sage: grf(h[1]) h[1] - sage: grf(h[2]) # optional - sage.combinat + sage: grf(h[2]) h[1, 1] - sage: grf(h[1, 1]) # optional - sage.combinat + sage: grf(h[1, 1]) h[2] - sage: grf(h[2, 1]) # optional - sage.combinat + sage: grf(h[2, 1]) h[2, 1] - sage: grf(h.one()) # optional - sage.combinat + sage: grf(h.one()) h[] """ grA = self.graded_algebra() @@ -659,26 +669,28 @@ def is_homogeneous(self): EXAMPLES:: - sage: A = ModulesWithBasis(ZZ).Filtered().example() # optional - sage.combinat - sage: x = A(Partition((3,2,1))) # optional - sage.combinat - sage: y = A(Partition((4,4,1))) # optional - sage.combinat - sage: z = A(Partition((2,2,2))) # optional - sage.combinat - sage: (3*x).is_homogeneous() # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: A = ModulesWithBasis(ZZ).Filtered().example() + sage: x = A(Partition((3,2,1))) + sage: y = A(Partition((4,4,1))) + sage: z = A(Partition((2,2,2))) + sage: (3*x).is_homogeneous() True - sage: (x - y).is_homogeneous() # optional - sage.combinat + sage: (x - y).is_homogeneous() False - sage: (x+2*z).is_homogeneous() # optional - sage.combinat + sage: (x+2*z).is_homogeneous() True Here is an example with a graded algebra:: - sage: S = NonCommutativeSymmetricFunctions(QQ).S() # optional - sage.combinat - sage: (x, y) = (S[2], S[3]) # optional - sage.combinat - sage: (3*x).is_homogeneous() # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: S = NonCommutativeSymmetricFunctions(QQ).S() + sage: (x, y) = (S[2], S[3]) + sage: (3*x).is_homogeneous() True - sage: (x^3 - y^2).is_homogeneous() # optional - sage.combinat + sage: (x^3 - y^2).is_homogeneous() True - sage: ((x + y)^2).is_homogeneous() # optional - sage.combinat + sage: ((x + y)^2).is_homogeneous() False Let us now test a filtered algebra (but remember that the @@ -717,10 +729,10 @@ def degree_on_basis(self, m): EXAMPLES:: - sage: A = GradedModulesWithBasis(QQ).example() # optional - sage.combinat sage.modules - sage: A.degree_on_basis(Partition((2,1))) # optional - sage.combinat sage.modules + sage: A = GradedModulesWithBasis(QQ).example() # needs sage.combinat sage.modules + sage: A.degree_on_basis(Partition((2,1))) # needs sage.combinat sage.modules 3 - sage: A.degree_on_basis(Partition((4,2,1,1,1,1))) # optional - sage.combinat sage.modules + sage: A.degree_on_basis(Partition((4,2,1,1,1,1))) # needs sage.combinat sage.modules 10 """ @@ -738,28 +750,30 @@ def homogeneous_degree(self): EXAMPLES:: - sage: A = ModulesWithBasis(ZZ).Filtered().example() # optional - sage.combinat sage.modules - sage: x = A(Partition((3,2,1))) # optional - sage.combinat sage.modules - sage: y = A(Partition((4,4,1))) # optional - sage.combinat sage.modules - sage: z = A(Partition((2,2,2))) # optional - sage.combinat sage.modules - sage: x.degree() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: A = ModulesWithBasis(ZZ).Filtered().example() + sage: x = A(Partition((3,2,1))) + sage: y = A(Partition((4,4,1))) + sage: z = A(Partition((2,2,2))) + sage: x.degree() 6 - sage: (x + 2*z).degree() # optional - sage.combinat sage.modules + sage: (x + 2*z).degree() 6 - sage: (y - x).degree() # optional - sage.combinat sage.modules + sage: (y - x).degree() Traceback (most recent call last): ... ValueError: element is not homogeneous An example in a graded algebra:: - sage: S = NonCommutativeSymmetricFunctions(QQ).S() # optional - sage.combinat sage.modules - sage: (x, y) = (S[2], S[3]) # optional - sage.combinat sage.modules - sage: x.homogeneous_degree() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: S = NonCommutativeSymmetricFunctions(QQ).S() + sage: (x, y) = (S[2], S[3]) + sage: x.homogeneous_degree() 2 - sage: (x^3 + 4*y^2).homogeneous_degree() # optional - sage.combinat sage.modules + sage: (x^3 + 4*y^2).homogeneous_degree() 6 - sage: ((1 + x)^3).homogeneous_degree() # optional - sage.combinat sage.modules + sage: ((1 + x)^3).homogeneous_degree() Traceback (most recent call last): ... ValueError: element is not homogeneous @@ -781,8 +795,8 @@ def homogeneous_degree(self): TESTS:: - sage: S = NonCommutativeSymmetricFunctions(QQ).S() # optional - sage.combinat sage.modules - sage: S.zero().degree() # optional - sage.combinat sage.modules + sage: S = NonCommutativeSymmetricFunctions(QQ).S() # needs sage.combinat sage.modules + sage: S.zero().degree() # needs sage.combinat sage.modules Traceback (most recent call last): ... ValueError: the zero element does not have a well-defined degree @@ -809,32 +823,35 @@ def maximal_degree(self): EXAMPLES:: - sage: A = ModulesWithBasis(ZZ).Filtered().example() # optional - sage.combinat - sage: x = A(Partition((3,2,1))) # optional - sage.combinat - sage: y = A(Partition((4,4,1))) # optional - sage.combinat - sage: z = A(Partition((2,2,2))) # optional - sage.combinat - sage: x.maximal_degree() # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: A = ModulesWithBasis(ZZ).Filtered().example() + sage: x = A(Partition((3,2,1))) + sage: y = A(Partition((4,4,1))) + sage: z = A(Partition((2,2,2))) + sage: x.maximal_degree() 6 - sage: (x + 2*z).maximal_degree() # optional - sage.combinat + sage: (x + 2*z).maximal_degree() 6 - sage: (y - x).maximal_degree() # optional - sage.combinat + sage: (y - x).maximal_degree() 9 - sage: (3*z).maximal_degree() # optional - sage.combinat + sage: (3*z).maximal_degree() 6 Now, we test this on a graded algebra:: - sage: S = NonCommutativeSymmetricFunctions(QQ).S() # optional - sage.combinat - sage: (x, y) = (S[2], S[3]) # optional - sage.combinat - sage: x.maximal_degree() # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: S = NonCommutativeSymmetricFunctions(QQ).S() + sage: (x, y) = (S[2], S[3]) + sage: x.maximal_degree() 2 - sage: (x^3 + 4*y^2).maximal_degree() # optional - sage.combinat + sage: (x^3 + 4*y^2).maximal_degree() 6 - sage: ((1 + x)^3).maximal_degree() # optional - sage.combinat + sage: ((1 + x)^3).maximal_degree() 6 Let us now test a filtered algebra:: + sage: # needs sage.combinat sage.modules sage: A = AlgebrasWithBasis(QQ).Filtered().example() sage: x,y,z = A.algebra_generators() sage: (x*y).maximal_degree() @@ -852,8 +869,8 @@ def maximal_degree(self): TESTS:: - sage: S = NonCommutativeSymmetricFunctions(QQ).S() # optional - sage.combinat - sage: S.zero().degree() # optional - sage.combinat + sage: S = NonCommutativeSymmetricFunctions(QQ).S() # needs sage.combinat sage.modules + sage: S.zero().degree() # needs sage.combinat sage.modules Traceback (most recent call last): ... ValueError: the zero element does not have a well-defined degree @@ -877,6 +894,7 @@ def homogeneous_component(self, n): EXAMPLES:: + sage: # needs sage.combinat sage.modules sage: A = ModulesWithBasis(ZZ).Filtered().example() sage: x = A.an_element(); x 2*P[] + 2*P[1] + 3*P[2] @@ -891,6 +909,7 @@ def homogeneous_component(self, n): sage: x.homogeneous_component(3) 0 + sage: # needs sage.combinat sage.modules sage: A = ModulesWithBasis(ZZ).Graded().example() sage: x = A.an_element(); x 2*P[] + 2*P[1] + 3*P[2] @@ -927,6 +946,7 @@ def homogeneous_component(self, n): Check that this really returns ``A.zero()`` and not a plain ``0``:: + sage: # needs sage.combinat sage.modules sage: A = ModulesWithBasis(ZZ).Filtered().example() sage: x = A.an_element() sage: x.homogeneous_component(3).parent() is A @@ -947,6 +967,7 @@ def truncate(self, n): EXAMPLES:: + sage: # needs sage.combinat sage.modules sage: A = ModulesWithBasis(ZZ).Filtered().example() sage: x = A.an_element(); x 2*P[] + 2*P[1] + 3*P[2] @@ -959,6 +980,7 @@ def truncate(self, n): sage: x.truncate(3) 2*P[] + 2*P[1] + 3*P[2] + sage: # needs sage.combinat sage.modules sage: A = ModulesWithBasis(ZZ).Graded().example() sage: x = A.an_element(); x 2*P[] + 2*P[1] + 3*P[2] @@ -996,6 +1018,7 @@ def truncate(self, n): Check that this really return ``A.zero()`` and not a plain ``0``:: + sage: # needs sage.combinat sage.modules sage: A = ModulesWithBasis(ZZ).Filtered().example() sage: x = A.an_element() sage: x.truncate(0).parent() is A @@ -1014,16 +1037,17 @@ def degree_on_basis(self, m): EXAMPLES:: - sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules - sage: S = E.submodule([x + y, x*y - y*z, y]) # optional - sage.combinat sage.modules - sage: B = S.basis() # optional - sage.combinat sage.modules - sage: [B[0].lift(), B[1].lift(), B[2].lift()] # optional - sage.combinat sage.modules + sage: # needs sage.modules + sage: E. = ExteriorAlgebra(QQ) + sage: S = E.submodule([x + y, x*y - y*z, y]) + sage: B = S.basis() + sage: [B[0].lift(), B[1].lift(), B[2].lift()] [x, y, x*y - y*z] - sage: S.degree_on_basis(0) # optional - sage.combinat sage.modules + sage: S.degree_on_basis(0) 1 - sage: S.degree_on_basis(1) # optional - sage.combinat sage.modules + sage: S.degree_on_basis(1) 1 - sage: S.degree_on_basis(2) # optional - sage.combinat sage.modules + sage: S.degree_on_basis(2) 2 """ return self.basis()[m].lift().degree() @@ -1035,29 +1059,30 @@ def degree(self): EXAMPLES:: - sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules - sage: S = E.submodule([x + y, x*y - y*z, y]) # optional - sage.combinat sage.modules - sage: B = S.basis() # optional - sage.combinat sage.modules - sage: [B[0].lift(), B[1].lift(), B[2].lift()] # optional - sage.combinat sage.modules + sage: # needs sage.modules + sage: E. = ExteriorAlgebra(QQ) + sage: S = E.submodule([x + y, x*y - y*z, y]) + sage: B = S.basis() + sage: [B[0].lift(), B[1].lift(), B[2].lift()] [x, y, x*y - y*z] - sage: B[0].degree() # optional - sage.combinat sage.modules + sage: B[0].degree() 1 - sage: B[1].degree() # optional - sage.combinat sage.modules + sage: B[1].degree() 1 - sage: (B[0] + 3*B[1]).degree() # optional - sage.combinat sage.modules + sage: (B[0] + 3*B[1]).degree() 1 The degree of inhomogeneous elements is not defined (following the behavior of the exterior algebra):: - sage: (B[0] + B[2]).degree() # optional - sage.combinat sage.modules + sage: (B[0] + B[2]).degree() # needs sage.modules Traceback (most recent call last): ... ValueError: element is not homogeneous We can still get the maximal degree:: - sage: (B[0] + B[2]).maximal_degree() # optional - sage.combinat sage.modules + sage: (B[0] + B[2]).maximal_degree() # needs sage.modules 2 """ return self.lift().degree() @@ -1075,14 +1100,15 @@ def maximal_degree(self): EXAMPLES:: - sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules - sage: F = E.submodule([x + 1, x*y - 1]) # optional - sage.combinat sage.modules - sage: B = F.basis() # optional - sage.combinat sage.modules - sage: [B[0].lift(), B[1].lift()] # optional - sage.combinat sage.modules + sage: # needs sage.modules + sage: E. = ExteriorAlgebra(QQ) + sage: F = E.submodule([x + 1, x*y - 1]) + sage: B = F.basis() + sage: [B[0].lift(), B[1].lift()] [-x*y + 1, x*y + x] - sage: B[0].maximal_degree() # optional - sage.combinat sage.modules + sage: B[0].maximal_degree() 2 - sage: B[1].maximal_degree() # optional - sage.combinat sage.modules + sage: B[1].maximal_degree() 2 """ return self.lift().maximal_degree() diff --git a/src/sage/categories/finite_complex_reflection_groups.py b/src/sage/categories/finite_complex_reflection_groups.py index 69762bb353a..889d81de3ad 100644 --- a/src/sage/categories/finite_complex_reflection_groups.py +++ b/src/sage/categories/finite_complex_reflection_groups.py @@ -111,7 +111,7 @@ def WellGenerated(self): sage: CoxeterGroups().Finite().is_subcategory(C) True - sage: SymmetricGroup(3) in C # optional - sage.groups + sage: SymmetricGroup(3) in C # needs sage.groups True .. NOTE:: @@ -126,7 +126,7 @@ def WellGenerated(self): sage: TestSuite(W).run() # optional - gap3 sage: C = ComplexReflectionGroups().Finite().WellGenerated() - sage: TestSuite(C).run() # optional - gap3 + sage: TestSuite(C).run() sage: CoxeterGroups().Finite().WellGenerated.__module__ 'sage.categories.finite_complex_reflection_groups' @@ -149,12 +149,12 @@ def degrees(self): EXAMPLES:: - sage: W = ColoredPermutations(1,4) # optional - sage.combinat sage.groups - sage: W.degrees() # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(1,4) # needs sage.combinat + sage: W.degrees() # needs sage.combinat (2, 3, 4) - sage: W = ColoredPermutations(3,3) # optional - sage.combinat sage.groups - sage: W.degrees() # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(3,3) # needs sage.combinat + sage: W.degrees() # needs sage.combinat (3, 6, 9) sage: W = ReflectionGroup(31) # optional - gap3 @@ -171,12 +171,12 @@ def codegrees(self): EXAMPLES:: - sage: W = ColoredPermutations(1,4) # optional - sage.combinat sage.groups - sage: W.codegrees() # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(1,4) # needs sage.combinat + sage: W.codegrees() # needs sage.combinat (2, 1, 0) - sage: W = ColoredPermutations(3,3) # optional - sage.combinat sage.groups - sage: W.codegrees() # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(3,3) # needs sage.combinat + sage: W.codegrees() # needs sage.combinat (6, 3, 0) sage: W = ReflectionGroup(31) # optional - gap3 @@ -199,27 +199,27 @@ def _test_degrees(self, **options): Reducible real reflection group of rank 4 and type A2 x B2 sage: W._test_degrees() # optional - gap3 - sage: W = SymmetricGroup(5) # optional - sage.groups - sage: W._test_degrees() # optional - sage.groups + sage: W = SymmetricGroup(5) # needs sage.groups + sage: W._test_degrees() # needs sage.groups We now break the implementation of W.degrees and check that this is caught:: - sage: W.degrees = lambda: (1/1,5) # optional - sage.groups - sage: W._test_degrees() # optional - sage.groups + sage: W.degrees = lambda: (1/1,5) # needs sage.groups + sage: W._test_degrees() # needs sage.groups Traceback (most recent call last): ... AssertionError: the degrees should be integers - sage: W.degrees = lambda: (1,2,3) # optional - sage.groups - sage: W._test_degrees() # optional - sage.groups + sage: W.degrees = lambda: (1,2,3) # needs sage.groups + sage: W._test_degrees() # needs sage.groups Traceback (most recent call last): ... AssertionError: the degrees should be larger than 2 We restore W to its normal state:: - sage: del W.degrees # optional - sage.groups - sage: W._test_degrees() # optional - sage.groups + sage: del W.degrees # needs sage.groups + sage: W._test_degrees() # needs sage.groups See the documentation for :class:`TestSuite` for more information. """ @@ -254,27 +254,27 @@ def _test_codegrees(self, **options): Reducible real reflection group of rank 4 and type A2 x B2 sage: W._test_codegrees() # optional - gap3 - sage: W = SymmetricGroup(5) # optional - sage.groups - sage: W._test_codegrees() # optional - sage.groups + sage: W = SymmetricGroup(5) # needs sage.groups + sage: W._test_codegrees() # needs sage.groups We now break the implementation of W.degrees and check that this is caught:: - sage: W.codegrees = lambda: (1/1,5) # optional - sage.groups - sage: W._test_codegrees() # optional - sage.groups + sage: W.codegrees = lambda: (1/1,5) # needs sage.groups + sage: W._test_codegrees() # needs sage.groups Traceback (most recent call last): ... AssertionError: the codegrees should be integers - sage: W.codegrees = lambda: (2,1,-1) # optional - sage.groups - sage: W._test_codegrees() # optional - sage.groups + sage: W.codegrees = lambda: (2,1,-1) # needs sage.groups + sage: W._test_codegrees() # needs sage.groups Traceback (most recent call last): ... AssertionError: the codegrees should be nonnegative We restore W to its normal state:: - sage: del W.codegrees # optional - sage.groups - sage: W._test_codegrees() # optional - sage.groups + sage: del W.codegrees # needs sage.groups + sage: W._test_codegrees() # needs sage.groups See the documentation for :class:`TestSuite` for more information. """ @@ -311,14 +311,15 @@ def number_of_reflection_hyperplanes(self): EXAMPLES:: - sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups - sage: W.number_of_reflection_hyperplanes() # optional - sage.combinat sage.groups + sage: # needs sage.combinat + sage: W = ColoredPermutations(1,3) + sage: W.number_of_reflection_hyperplanes() 3 - sage: W = ColoredPermutations(2,3) # optional - sage.combinat sage.groups - sage: W.number_of_reflection_hyperplanes() # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(2,3) + sage: W.number_of_reflection_hyperplanes() 9 - sage: W = ColoredPermutations(4,3) # optional - sage.combinat sage.groups - sage: W.number_of_reflection_hyperplanes() # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(4,3) + sage: W.number_of_reflection_hyperplanes() 15 sage: W = ReflectionGroup((4,2,3)) # optional - gap3 sage: W.number_of_reflection_hyperplanes() # optional - gap3 @@ -342,21 +343,22 @@ def number_of_reflections(self): EXAMPLES:: - sage: [SymmetricGroup(i).number_of_reflections() # optional - sage.groups + sage: [SymmetricGroup(i).number_of_reflections() # needs sage.groups ....: for i in range(int(8))] [0, 0, 1, 3, 6, 10, 15, 21] - sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups - sage: W.number_of_reflections() # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = ColoredPermutations(1,3) + sage: W.number_of_reflections() 3 - sage: W = ColoredPermutations(2,3) # optional - sage.combinat sage.groups - sage: W.number_of_reflections() # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(2,3) + sage: W.number_of_reflections() 9 - sage: W = ColoredPermutations(4,3) # optional - sage.combinat sage.groups - sage: W.number_of_reflections() # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(4,3) + sage: W.number_of_reflections() 21 - sage: W = ReflectionGroup((4,2,3)) # optional - gap3 # optional - sage.combinat sage.groups - sage: W.number_of_reflections() # optional - gap3 # optional - sage.combinat sage.groups + sage: W = ReflectionGroup((4,2,3)) # optional - gap3 + sage: W.number_of_reflections() # optional - gap3 15 """ from sage.rings.integer_ring import ZZ @@ -377,17 +379,20 @@ def rank(self): EXAMPLES:: - sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups - sage: W.rank() # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = ColoredPermutations(1,3) + sage: W.rank() 2 - sage: W = ColoredPermutations(2,3) # optional - sage.combinat sage.groups - sage: W.rank() # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(2,3) + sage: W.rank() 3 - sage: W = ColoredPermutations(4,3) # optional - sage.combinat sage.groups - sage: W.rank() # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(4,3) + sage: W.rank() 3 - sage: W = ReflectionGroup((4,2,3)) # optional - gap3 # optional - sage.combinat sage.groups - sage: W.rank() # optional - gap3 # optional - sage.combinat sage.groups + + sage: # optional - gap3, needs sage.combinat sage.groups + sage: W = ReflectionGroup((4,2,3)) + sage: W.rank() 3 """ return len(self.degrees()) @@ -401,17 +406,20 @@ def cardinality(self): EXAMPLES:: - sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups - sage: W.cardinality() # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = ColoredPermutations(1,3) + sage: W.cardinality() 6 - sage: W = ColoredPermutations(2,3) # optional - sage.combinat sage.groups - sage: W.cardinality() # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(2,3) + sage: W.cardinality() 48 - sage: W = ColoredPermutations(4,3) # optional - sage.combinat sage.groups - sage: W.cardinality() # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(4,3) + sage: W.cardinality() 384 - sage: W = ReflectionGroup((4,2,3)) # optional - gap3 # optional - sage.combinat sage.groups - sage: W.cardinality() # optional - gap3 # optional - sage.combinat sage.groups + + sage: # optional - gap3, needs sage.combinat sage.groups + sage: W = ReflectionGroup((4,2,3)) + sage: W.cardinality() 192 """ from sage.rings.integer_ring import ZZ @@ -439,20 +447,20 @@ def is_well_generated(self) -> bool: EXAMPLES:: - sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups - sage: W.is_well_generated() # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(1,3) # needs sage.combinat + sage: W.is_well_generated() # needs sage.combinat True - sage: W = ColoredPermutations(4,3) # optional - sage.combinat sage.groups - sage: W.is_well_generated() # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(4,3) # needs sage.combinat + sage: W.is_well_generated() # needs sage.combinat True - sage: W = ReflectionGroup((4,2,3)) # optional - gap3 # optional - sage.combinat sage.groups - sage: W.is_well_generated() # optional - gap3 # optional - sage.combinat sage.groups + sage: # optional - gap3, needs sage.combinat sage.groups + sage: W = ReflectionGroup((4,2,3)) + sage: W.is_well_generated() False - - sage: W = ReflectionGroup((4,4,3)) # optional - gap3 # optional - sage.combinat sage.groups - sage: W.is_well_generated() # optional - gap3 # optional - sage.combinat sage.groups + sage: W = ReflectionGroup((4,4,3)) + sage: W.is_well_generated() True """ return self.number_of_simple_reflections() == self.rank() @@ -474,12 +482,12 @@ def is_real(self): EXAMPLES:: - sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups - sage: W.is_real() # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(1,3) # needs sage.combinat + sage: W.is_real() # needs sage.combinat True - sage: W = ColoredPermutations(4,3) # optional - sage.combinat sage.groups - sage: W.is_real() # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(4,3) # needs sage.combinat + sage: W.is_real() # needs sage.combinat sage.groups False .. TODO:: @@ -544,8 +552,8 @@ def to_matrix(self): [0 1], [ 0 -1], [ 1 1], [ 1 0], [-1 -1], [-1 0] ] - sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups - sage: [t.to_matrix() for t in W] # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(1,3) # needs sage.combinat + sage: [t.to_matrix() for t in W] # needs sage.combinat sage.groups [ [1 0 0] [1 0 0] [0 1 0] [0 0 1] [0 1 0] [0 0 1] [0 1 0] [0 0 1] [1 0 0] [1 0 0] [0 0 1] [0 1 0] @@ -555,8 +563,8 @@ def to_matrix(self): A different representation is given by the colored permutations:: - sage: W = ColoredPermutations(3, 1) # optional - sage.combinat sage.groups - sage: [t.to_matrix() for t in W] # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(3, 1) # needs sage.combinat + sage: [t.to_matrix() for t in W] # needs sage.combinat sage.groups [[1], [zeta3], [-zeta3 - 1]] """ @@ -582,9 +590,9 @@ def character_value(self): EXAMPLES:: - sage: W = ColoredPermutations(1,3); W # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(1,3); W # needs sage.combinat 1-colored permutations of size 3 - sage: [t.character_value() for t in W] # optional - sage.combinat sage.groups + sage: [t.character_value() for t in W] # needs sage.combinat sage.groups [3, 1, 1, 0, 0, 1] Note that this could be a different (faithful) @@ -596,14 +604,14 @@ def character_value(self): sage: [t.character_value() for t in W] # optional - gap3 [2, 0, 0, -1, -1, 0] - sage: W = ColoredPermutations(2,2); W # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(2,2); W # needs sage.combinat 2-colored permutations of size 2 - sage: [t.character_value() for t in W] # optional - sage.combinat sage.groups + sage: [t.character_value() for t in W] # needs sage.combinat sage.groups [2, 0, 0, -2, 0, 0, 0, 0] - sage: W = ColoredPermutations(3,1); W # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(3,1); W # needs sage.combinat 3-colored permutations of size 1 - sage: [t.character_value() for t in W] # optional - sage.combinat sage.groups + sage: [t.character_value() for t in W] # needs sage.combinat sage.groups [1, zeta3, -zeta3 - 1] """ return self.to_matrix().trace() @@ -750,12 +758,12 @@ def absolute_order_ideal(self, gens=None, ....: for w in W.absolute_order_ideal(W.from_reduced_word([2]))) [[], [2]] - sage: W = CoxeterGroup(['A', 3]) # optional - sage.combinat sage.groups - sage: len(list(W.absolute_order_ideal())) # optional - sage.combinat sage.groups + sage: W = CoxeterGroup(['A', 3]) # needs sage.combinat sage.groups + sage: len(list(W.absolute_order_ideal())) # needs sage.combinat sage.groups 14 - sage: W = CoxeterGroup(['A', 2]) # optional - sage.combinat sage.groups - sage: for (w, l) in W.absolute_order_ideal(return_lengths=True): # optional - sage.combinat sage.groups + sage: W = CoxeterGroup(['A', 2]) # needs sage.combinat sage.groups + sage: for (w, l) in W.absolute_order_ideal(return_lengths=True): # needs sage.combinat sage.groups ....: print(w.reduced_word(), l) [1, 2] 2 [1, 2, 1] 1 @@ -822,12 +830,12 @@ def noncrossing_partition_lattice(self, c=None, L=None, EXAMPLES:: - sage: W = SymmetricGroup(4) # optional - sage.combinat sage.groups - sage: W.noncrossing_partition_lattice() # optional - sage.combinat sage.groups + sage: W = SymmetricGroup(4) # needs sage.combinat sage.groups + sage: W.noncrossing_partition_lattice() # needs sage.combinat sage.groups Finite lattice containing 14 elements - sage: W = WeylGroup(['G', 2]) # optional - sage.combinat sage.groups - sage: W.noncrossing_partition_lattice() # optional - sage.combinat sage.groups + sage: W = WeylGroup(['G', 2]) # needs sage.combinat sage.groups + sage: W.noncrossing_partition_lattice() # needs sage.combinat sage.groups Finite lattice containing 8 elements sage: W = ReflectionGroup((1,1,3)) # optional - gap3 @@ -982,14 +990,15 @@ def absolute_poset(self, in_unitary_group=False): TESTS:: - sage: W1 = CoxeterGroup(['A', 2]) # optional - sage.combinat sage.groups - sage: W2 = WeylGroup(['A', 2]) # optional - sage.combinat sage.groups - sage: W3 = SymmetricGroup(3) # optional - sage.combinat sage.groups - sage: W1.absolute_poset() # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W1 = CoxeterGroup(['A', 2]) + sage: W2 = WeylGroup(['A', 2]) + sage: W3 = SymmetricGroup(3) + sage: W1.absolute_poset() Finite poset containing 6 elements - sage: W2.absolute_poset() # optional - sage.combinat sage.groups + sage: W2.absolute_poset() Finite poset containing 6 elements - sage: W3.absolute_poset() # optional - sage.combinat sage.groups + sage: W3.absolute_poset() Finite poset containing 6 elements """ return self.noncrossing_partition_lattice(L=tuple(self), in_unitary_group=in_unitary_group) @@ -1084,7 +1093,7 @@ def example(self): sage: from sage.categories.complex_reflection_groups import ComplexReflectionGroups sage: C = ComplexReflectionGroups().Finite().WellGenerated().Irreducible() - sage: C.example() # optional - sage.combinat sage.groups + sage: C.example() # needs sage.combinat 4-colored permutations of size 3 """ from sage.combinat.colored_permutations import ColoredPermutations @@ -1109,12 +1118,12 @@ def coxeter_number(self): EXAMPLES:: - sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups - sage: W.coxeter_number() # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(1,3) # needs sage.combinat + sage: W.coxeter_number() # needs sage.combinat 3 - sage: W = ColoredPermutations(4,3) # optional - sage.combinat sage.groups - sage: W.coxeter_number() # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(4,3) # needs sage.combinat + sage: W.coxeter_number() # needs sage.combinat 12 sage: W = ReflectionGroup((4,4,3)) # optional - gap3 @@ -1130,20 +1139,20 @@ def number_of_reflections_of_full_support(self): EXAMPLES:: - sage: W = Permutations(4) # optional - sage.combinat sage.groups - sage: W.number_of_reflections_of_full_support() # optional - sage.combinat sage.groups + sage: W = Permutations(4) + sage: W.number_of_reflections_of_full_support() 1 - sage: W = ColoredPermutations(1,4) # optional - sage.combinat sage.groups - sage: W.number_of_reflections_of_full_support() # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(1,4) # needs sage.combinat + sage: W.number_of_reflections_of_full_support() 1 - sage: W = CoxeterGroup("B3") # optional - sage.combinat sage.groups - sage: W.number_of_reflections_of_full_support() # optional - sage.combinat sage.groups + sage: W = CoxeterGroup("B3") # needs sage.combinat sage.groups + sage: W.number_of_reflections_of_full_support() # needs sage.combinat sage.groups 3 - sage: W = ColoredPermutations(3,3) # optional - sage.combinat sage.groups - sage: W.number_of_reflections_of_full_support() # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(3,3) # needs sage.combinat + sage: W.number_of_reflections_of_full_support() # needs sage.combinat 3 """ n = self.rank() @@ -1175,18 +1184,18 @@ def rational_catalan_number(self, p, polynomial=False): EXAMPLES:: - sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups - sage: [W.rational_catalan_number(p) for p in [5,7,8]] # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(1,3) # needs sage.combinat + sage: [W.rational_catalan_number(p) for p in [5,7,8]] # needs sage.combinat [7, 12, 15] - sage: W = ColoredPermutations(2,2) # optional - sage.combinat sage.groups - sage: [W.rational_catalan_number(p) for p in [7,9,11]] # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(2,2) # needs sage.combinat + sage: [W.rational_catalan_number(p) for p in [7,9,11]] # needs sage.combinat [10, 15, 21] TESTS:: - sage: W = ColoredPermutations(1,4) # optional - sage.combinat sage.groups - sage: W.rational_catalan_number(3, polynomial=True) # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(1,4) # needs sage.combinat + sage: W.rational_catalan_number(3, polynomial=True) # needs sage.combinat q^6 + q^4 + q^3 + q^2 + 1 """ from sage.arith.misc import GCD as gcd @@ -1243,37 +1252,38 @@ def fuss_catalan_number(self, m, positive=False, EXAMPLES:: - sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups - sage: [W.fuss_catalan_number(i) for i in [1,2,3]] # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(1,3) # needs sage.combinat + sage: [W.fuss_catalan_number(i) for i in [1,2,3]] # needs sage.combinat [5, 12, 22] - sage: W = ColoredPermutations(1,4) # optional - sage.combinat sage.groups - sage: [W.fuss_catalan_number(i) for i in [1,2,3]] # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(1,4) # needs sage.combinat + sage: [W.fuss_catalan_number(i) for i in [1,2,3]] # needs sage.combinat [14, 55, 140] - sage: W = ColoredPermutations(1,5) # optional - sage.combinat sage.groups - sage: [W.fuss_catalan_number(i) for i in [1,2,3]] # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(1,5) # needs sage.combinat + sage: [W.fuss_catalan_number(i) for i in [1,2,3]] # needs sage.combinat [42, 273, 969] - sage: W = ColoredPermutations(2,2) # optional - sage.combinat sage.groups - sage: [W.fuss_catalan_number(i) for i in [1,2,3]] # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(2,2) # needs sage.combinat + sage: [W.fuss_catalan_number(i) for i in [1,2,3]] # needs sage.combinat [6, 15, 28] - sage: W = ColoredPermutations(2,3) # optional - sage.combinat sage.groups - sage: [W.fuss_catalan_number(i) for i in [1,2,3]] # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(2,3) # needs sage.combinat + sage: [W.fuss_catalan_number(i) for i in [1,2,3]] # needs sage.combinat [20, 84, 220] - sage: W = ColoredPermutations(2,4) # optional - sage.combinat sage.groups - sage: [W.fuss_catalan_number(i) for i in [1,2,3]] # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(2,4) # needs sage.combinat + sage: [W.fuss_catalan_number(i) for i in [1,2,3]] # needs sage.combinat [70, 495, 1820] TESTS:: - sage: W = ColoredPermutations(2,4) # optional - sage.combinat sage.groups - sage: W.fuss_catalan_number(2, positive=True) # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = ColoredPermutations(2,4) + sage: W.fuss_catalan_number(2, positive=True) 330 - sage: W = ColoredPermutations(2,2) # optional - sage.combinat sage.groups - sage: W.fuss_catalan_number(2, polynomial=True) # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(2,2) + sage: W.fuss_catalan_number(2, polynomial=True) q^16 + q^14 + 2*q^12 + 2*q^10 + 3*q^8 + 2*q^6 + 2*q^4 + q^2 + 1 """ @@ -1317,11 +1327,11 @@ def catalan_number(self, positive=False, polynomial=False): EXAMPLES:: - sage: [ColoredPermutations(1,n).catalan_number() # optional - sage.combinat sage.groups + sage: [ColoredPermutations(1,n).catalan_number() # needs sage.combinat ....: for n in [3,4,5]] [5, 14, 42] - sage: [ColoredPermutations(2,n).catalan_number() # optional - sage.combinat sage.groups + sage: [ColoredPermutations(2,n).catalan_number() # needs sage.combinat ....: for n in [3,4,5]] [20, 70, 252] @@ -1331,11 +1341,12 @@ def catalan_number(self, positive=False, polynomial=False): TESTS:: - sage: W = ColoredPermutations(3,6) # optional - sage.combinat sage.groups - sage: W.catalan_number(positive=True) # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: W = ColoredPermutations(3,6) + sage: W.catalan_number(positive=True) 462 - sage: W = ColoredPermutations(2,2) # optional - sage.combinat sage.groups - sage: W.catalan_number(polynomial=True) # optional - sage.combinat sage.groups + sage: W = ColoredPermutations(2,2) + sage: W.catalan_number(polynomial=True) q^8 + q^6 + 2*q^4 + q^2 + 1 """ return self.fuss_catalan_number(1, positive=positive, diff --git a/src/sage/categories/finite_coxeter_groups.py b/src/sage/categories/finite_coxeter_groups.py index a03a7ca5495..b08e857edaf 100644 --- a/src/sage/categories/finite_coxeter_groups.py +++ b/src/sage/categories/finite_coxeter_groups.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.combinat sage.groups +# sage.doctest: needs sage.combinat sage.groups r""" Finite Coxeter Groups """ diff --git a/src/sage/categories/finite_crystals.py b/src/sage/categories/finite_crystals.py index f920da8b877..4d5fdda550d 100644 --- a/src/sage/categories/finite_crystals.py +++ b/src/sage/categories/finite_crystals.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.combinat sage.graphs +# sage.doctest: needs sage.combinat sage.graphs r""" Finite Crystals """ diff --git a/src/sage/categories/finite_dimensional_algebras_with_basis.py b/src/sage/categories/finite_dimensional_algebras_with_basis.py index ce2bf641d7f..bdf727d7efb 100644 --- a/src/sage/categories/finite_dimensional_algebras_with_basis.py +++ b/src/sage/categories/finite_dimensional_algebras_with_basis.py @@ -44,13 +44,14 @@ class FiniteDimensionalAlgebrasWithBasis(CategoryWithAxiom_over_base_ring): sage: C.super_categories() [Category of algebras with basis over Rational Field, Category of finite dimensional magmatic algebras with basis over Rational Field] - sage: C.example() + sage: C.example() # needs sage.modules An example of a finite dimensional algebra with basis: the path algebra of the Kronecker quiver (containing the arrows a:x->y and b:x->y) over Rational Field TESTS:: + sage: # needs sage.graphs sage.modules sage: TestSuite(C).run() sage: C is Algebras(QQ).FiniteDimensional().WithBasis() True @@ -80,6 +81,7 @@ def radical_basis(self): EXAMPLES:: + sage: # needs sage.graphs sage.modules sage: A = Algebras(QQ).FiniteDimensional().WithBasis().example(); A An example of a finite dimensional algebra with basis: the path algebra of the Kronecker quiver @@ -90,29 +92,29 @@ def radical_basis(self): We construct the group algebra of the Klein Four-Group over the rationals:: - sage: A = KleinFourGroup().algebra(QQ) # optional - sage.groups sage.modules + sage: A = KleinFourGroup().algebra(QQ) # needs sage.groups sage.modules This algebra belongs to the category of finite dimensional algebras over the rationals:: - sage: A in Algebras(QQ).FiniteDimensional().WithBasis() # optional - sage.groups sage.modules + sage: A in Algebras(QQ).FiniteDimensional().WithBasis() # needs sage.groups sage.modules True Since the field has characteristic `0`, Maschke's Theorem tells us that the group algebra is semisimple. So its radical is the zero ideal:: - sage: A in Algebras(QQ).Semisimple() # optional - sage.groups sage.modules + sage: A in Algebras(QQ).Semisimple() # needs sage.groups sage.modules True - sage: A.radical_basis() # optional - sage.groups sage.modules + sage: A.radical_basis() # needs sage.groups sage.modules () Let's work instead over a field of characteristic `2`:: - sage: A = KleinFourGroup().algebra(GF(2)) # optional - sage.groups sage.rings.finite_rings sage.modules - sage: A in Algebras(GF(2)).Semisimple() # optional - sage.groups sage.rings.finite_rings sage.modules + sage: A = KleinFourGroup().algebra(GF(2)) # needs sage.groups sage.modules + sage: A in Algebras(GF(2)).Semisimple() # needs sage.groups sage.modules False - sage: A.radical_basis() # optional - sage.groups sage.rings.finite_rings sage.modules + sage: A.radical_basis() # needs sage.groups sage.modules (() + (1,2)(3,4), (3,4) + (1,2)(3,4), (1,2) + (1,2)(3,4)) We now implement the algebra `A = K[x] / (x^p-1)`, where `K` @@ -120,7 +122,8 @@ def radical_basis(self): radical; alas, we currently need to wrap `A` to make it a proper :class:`ModulesWithBasis`:: - sage: class AnAlgebra(CombinatorialFreeModule): # optional - sage.modules + sage: # needs sage.modules + sage: class AnAlgebra(CombinatorialFreeModule): ....: def __init__(self, F): ....: R. = PolynomialRing(F) ....: I = R.ideal(x**F.characteristic()-F.one()) @@ -132,24 +135,24 @@ def radical_basis(self): ....: return self.basis()[self.base_ring().one()] ....: def product_on_basis(self, w1, w2): ....: return self.from_vector(vector(w1*w2)) - sage: AnAlgebra(GF(3)).radical_basis() # optional - sage.rings.finite_rings sage.modules + sage: AnAlgebra(GF(3)).radical_basis() (B[1] + 2*B[xbar^2], B[xbar] + 2*B[xbar^2]) - sage: AnAlgebra(GF(16,'a')).radical_basis() # optional - sage.rings.finite_rings sage.modules + sage: AnAlgebra(GF(16,'a')).radical_basis() # needs sage.rings.finite_rings (B[1] + B[xbar],) - sage: AnAlgebra(GF(49,'a')).radical_basis() # optional - sage.rings.finite_rings sage.modules + sage: AnAlgebra(GF(49,'a')).radical_basis() # needs sage.rings.finite_rings (B[1] + 6*B[xbar^6], B[xbar] + 6*B[xbar^6], B[xbar^2] + 6*B[xbar^6], B[xbar^3] + 6*B[xbar^6], B[xbar^4] + 6*B[xbar^6], B[xbar^5] + 6*B[xbar^6]) TESTS:: - sage: A = KleinFourGroup().algebra(GF(2)) # optional - sage.groups sage.rings.finite_rings sage.modules - sage: A.radical_basis() # optional - sage.groups sage.rings.finite_rings sage.modules + sage: A = KleinFourGroup().algebra(GF(2)) # needs sage.groups sage.modules + sage: A.radical_basis() # needs sage.groups sage.modules (() + (1,2)(3,4), (3,4) + (1,2)(3,4), (1,2) + (1,2)(3,4)) - sage: A = KleinFourGroup().algebra(QQ, category=Monoids()) # optional - sage.groups sage.modules - sage: A.radical_basis.__module__ # optional - sage.groups sage.modules + sage: A = KleinFourGroup().algebra(QQ, category=Monoids()) # needs sage.groups sage.modules + sage: A.radical_basis.__module__ # needs sage.groups sage.modules 'sage.categories.finite_dimensional_algebras_with_basis' - sage: A.radical_basis() # optional - sage.groups sage.modules + sage: A.radical_basis() # needs sage.groups sage.modules () """ F = self.base_ring() @@ -216,6 +219,7 @@ def radical(self): EXAMPLES:: + sage: # needs sage.graphs sage.modules sage: A = Algebras(QQ).FiniteDimensional().WithBasis().example(); A An example of a finite dimensional algebra with basis: the path algebra of the Kronecker quiver @@ -228,12 +232,14 @@ def radical(self): The radical is an ideal of `A`, and thus a finite dimensional non unital associative algebra:: + sage: # needs sage.graphs sage.modules sage: from sage.categories.associative_algebras import AssociativeAlgebras sage: radical in AssociativeAlgebras(QQ).WithBasis().FiniteDimensional() True sage: radical in Algebras(QQ) False + sage: # needs sage.graphs sage.modules sage: radical.dimension() 2 sage: radical.basis() @@ -251,6 +257,7 @@ def radical(self): TESTS:: + sage: # needs sage.graphs sage.modules sage: TestSuite(radical).run() """ category = AssociativeAlgebras(self.base_ring()).WithBasis().FiniteDimensional().Subobjects() @@ -271,6 +278,7 @@ def semisimple_quotient(self): EXAMPLES:: + sage: # needs sage.graphs sage.modules sage: A = Algebras(QQ).FiniteDimensional().WithBasis().example(); A An example of a finite dimensional algebra with basis: the path algebra of the Kronecker quiver @@ -292,10 +300,10 @@ def semisimple_quotient(self): descent algebra of the symmetric group is of dimension the number of partitions of `n`:: - sage: [ DescentAlgebra(QQ,n).B().semisimple_quotient().dimension() # optional - sage.combinat + sage: [ DescentAlgebra(QQ,n).B().semisimple_quotient().dimension() # needs sage.combinat sage.modules ....: for n in range(6) ] [1, 1, 2, 3, 5, 7] - sage: [Partitions(n).cardinality() for n in range(10)] # optional - sage.combinat + sage: [Partitions(n).cardinality() for n in range(10)] # needs sage.combinat [1, 1, 2, 3, 5, 7, 11, 15, 22, 30] .. TODO:: @@ -305,7 +313,7 @@ def semisimple_quotient(self): TESTS:: - sage: TestSuite(S).run() + sage: TestSuite(S).run() # needs sage.graphs sage.modules """ ring = self.base_ring() category = Algebras(ring).WithBasis().FiniteDimensional().Quotients().Semisimple() @@ -326,6 +334,7 @@ def center_basis(self): EXAMPLES:: + sage: # needs sage.graphs sage.modules sage: A = Algebras(QQ).FiniteDimensional().WithBasis().example(); A An example of a finite dimensional algebra with basis: the path algebra of the Kronecker quiver @@ -344,6 +353,7 @@ def center(self): EXAMPLES:: + sage: # needs sage.graphs sage.modules sage: A = Algebras(QQ).FiniteDimensional().WithBasis().example(); A An example of a finite dimensional algebra with basis: the path algebra of the Kronecker quiver @@ -365,8 +375,8 @@ def center(self): The center of a semisimple algebra is semisimple:: - sage: A = DihedralGroup(6).algebra(QQ) # optional - sage.groups sage.modules - sage: A.center() in Algebras(QQ).Semisimple() # optional - sage.groups sage.modules + sage: A = DihedralGroup(6).algebra(QQ) # needs sage.groups sage.modules + sage: A.center() in Algebras(QQ).Semisimple() # needs sage.groups sage.modules True .. TODO:: @@ -376,7 +386,7 @@ def center(self): TESTS:: - sage: TestSuite(center).run() + sage: TestSuite(center).run() # needs sage.graphs sage.modules """ category = Algebras(self.base_ring()).FiniteDimensional().Subobjects().Commutative().WithBasis() if self in Algebras.Semisimple: @@ -397,6 +407,7 @@ def principal_ideal(self, a, side='left'): right principal ideals, our first example deals with a non commutative algebra:: + sage: # needs sage.graphs sage.modules sage: A = Algebras(QQ).FiniteDimensional().WithBasis().example(); A An example of a finite dimensional algebra with basis: the path algebra of the Kronecker quiver @@ -406,27 +417,27 @@ def principal_ideal(self, a, side='left'): In this algebra, multiplication on the right by `x` annihilates all basis elements but `x`:: - sage: x*x, y*x, a*x, b*x + sage: x*x, y*x, a*x, b*x # needs sage.graphs sage.modules (x, 0, 0, 0) so the left ideal generated by `x` is one-dimensional:: - sage: Ax = A.principal_ideal(x, side='left'); Ax + sage: Ax = A.principal_ideal(x, side='left'); Ax # needs sage.graphs sage.modules Free module generated by {0} over Rational Field - sage: [B.lift() for B in Ax.basis()] + sage: [B.lift() for B in Ax.basis()] # needs sage.graphs sage.modules [x] Multiplication on the left by `x` annihilates only `x` and fixes the other basis elements:: - sage: x*x, x*y, x*a, x*b + sage: x*x, x*y, x*a, x*b # needs sage.graphs sage.modules (x, 0, a, b) so the right ideal generated by `x` is 3-dimensional:: - sage: xA = A.principal_ideal(x, side='right'); xA + sage: xA = A.principal_ideal(x, side='right'); xA # needs sage.graphs sage.modules Free module generated by {0, 1, 2} over Rational Field - sage: [B.lift() for B in xA.basis()] + sage: [B.lift() for B in xA.basis()] # needs sage.graphs sage.modules [x, a, b] .. SEEALSO:: @@ -470,20 +481,22 @@ def orthogonal_idempotents_central_mod_radical(self): EXAMPLES:: + sage: # needs sage.graphs sage.modules sage: A = Algebras(QQ).FiniteDimensional().WithBasis().example(); A An example of a finite dimensional algebra with basis: the path algebra of the Kronecker quiver (containing the arrows a:x->y and b:x->y) over Rational Field - sage: A.orthogonal_idempotents_central_mod_radical() # optional - sage.rings.number_field + sage: A.orthogonal_idempotents_central_mod_radical() # needs sage.rings.number_field (x, y) :: + sage: # needs sage.modules sage.rings.number_field sage: Z12 = Monoids().Finite().example(); Z12 An example of a finite multiplicative monoid: the integers modulo 12 sage: A = Z12.algebra(QQ) - sage: idempotents = A.orthogonal_idempotents_central_mod_radical() # optional - sage.rings.number_field - sage: sorted(idempotents, key=str) # optional - sage.rings.number_field + sage: idempotents = A.orthogonal_idempotents_central_mod_radical() + sage: sorted(idempotents, key=str) [-B[0] + 1/2*B[4] + 1/2*B[8], 1/2*B[4] - 1/2*B[8], 1/2*B[9] + 1/2*B[3] - B[0], @@ -493,26 +506,27 @@ def orthogonal_idempotents_central_mod_radical(self): 1/4*B[1] - 1/2*B[9] - 1/2*B[3] + 1/4*B[11] + 1/4*B[5] + 1/4*B[7] + B[0] - 1/2*B[4] - 1/2*B[8], 1/4*B[1] - 1/4*B[5] + 1/4*B[7] - 1/4*B[11] - 1/2*B[4] + 1/2*B[8], B[0]] - sage: sum(idempotents) == 1 # optional - sage.rings.number_field + sage: sum(idempotents) == 1 True - sage: all(e*e == e for e in idempotents) # optional - sage.rings.number_field + sage: all(e*e == e for e in idempotents) True - sage: all(e*f == 0 and f*e == 0 # optional - sage.rings.number_field + sage: all(e*f == 0 and f*e == 0 ....: for e in idempotents for f in idempotents if e != f) True This is best tested with:: - sage: A.is_identity_decomposition_into_orthogonal_idempotents(idempotents) # optional - sage.rings.number_field + sage: A.is_identity_decomposition_into_orthogonal_idempotents(idempotents) # needs sage.graphs sage.modules sage.rings.number_field True We construct orthogonal idempotents for the algebra of the `0`-Hecke monoid:: - sage: from sage.monoids.hecke_monoid import HeckeMonoid # optional - sage.groups - sage: A = HeckeMonoid(SymmetricGroup(4)).algebra(QQ) # optional - sage.groups - sage: idempotents = A.orthogonal_idempotents_central_mod_radical() # optional - sage.groups - sage: A.is_identity_decomposition_into_orthogonal_idempotents(idempotents) # optional - sage.groups + sage: # needs sage.combinat sage.graphs sage.groups sage.modules + sage: from sage.monoids.hecke_monoid import HeckeMonoid + sage: A = HeckeMonoid(SymmetricGroup(4)).algebra(QQ) + sage: idempotents = A.orthogonal_idempotents_central_mod_radical() + sage: A.is_identity_decomposition_into_orthogonal_idempotents(idempotents) True """ one = self.one() @@ -555,6 +569,7 @@ def idempotent_lift(self, x): EXAMPLES:: + sage: # needs sage.graphs sage.modules sage: A = Algebras(QQ).FiniteDimensional().WithBasis().example() sage: S = A.semisimple_quotient() sage: A.idempotent_lift(S.basis()['x']) @@ -647,8 +662,8 @@ def cartan_invariants_matrix(self): in characteristic zero, the Cartan invariants matrix is the identity:: - sage: A3 = SymmetricGroup(3).algebra(QQ) # optional - sage.groups sage.modules - sage: A3.cartan_invariants_matrix() # optional - sage.groups sage.modules + sage: A3 = SymmetricGroup(3).algebra(QQ) # needs sage.groups sage.modules + sage: A3.cartan_invariants_matrix() # needs sage.groups sage.modules [1 0 0] [0 1 0] [0 0 1] @@ -657,7 +672,7 @@ def cartan_invariants_matrix(self): matrix counts the number of paths between two vertices:: sage: A = Algebras(QQ).FiniteDimensional().WithBasis().example() - sage: A.cartan_invariants_matrix() # optional - sage.modules sage.rings.number_field + sage: A.cartan_invariants_matrix() # needs sage.modules sage.rings.number_field [1 2] [0 1] @@ -665,8 +680,8 @@ def cartan_invariants_matrix(self): sage: Z12 = Monoids().Finite().example(); Z12 An example of a finite multiplicative monoid: the integers modulo 12 - sage: A = Z12.algebra(QQ) # optional - sage.modules - sage: A.cartan_invariants_matrix() # optional - sage.modules sage.rings.number_fields + sage: A = Z12.algebra(QQ) # needs sage.modules + sage: A.cartan_invariants_matrix() # needs sage.modules sage.rings.number_field [1 0 0 0 0 0 0 0 0] [0 1 0 0 0 0 0 0 0] [0 0 2 0 0 0 0 0 0] @@ -679,9 +694,10 @@ def cartan_invariants_matrix(self): With the algebra of the `0`-Hecke monoid:: - sage: from sage.monoids.hecke_monoid import HeckeMonoid # optional - sage.groups sage.modules - sage: A = HeckeMonoid(SymmetricGroup(4)).algebra(QQ) # optional - sage.groups sage.modules - sage: A.cartan_invariants_matrix() # optional - sage.groups sage.modules sage.rings.number_field + sage: # needs sage.combinat sage.groups sage.modules + sage: from sage.monoids.hecke_monoid import HeckeMonoid + sage: A = HeckeMonoid(SymmetricGroup(4)).algebra(QQ) + sage: A.cartan_invariants_matrix() # needs sage.rings.number_field [1 0 0 0 0 0 0 0] [0 2 1 0 1 1 0 0] [0 1 1 0 1 0 0 0] @@ -737,14 +753,15 @@ def isotypic_projective_modules(self, side='left'): EXAMPLES:: + sage: # needs sage.graphs sage.modules sage.rings.number_field sage: A = Algebras(QQ).FiniteDimensional().WithBasis().example(); A An example of a finite dimensional algebra with basis: the path algebra of the Kronecker quiver (containing the arrows a:x->y and b:x->y) over Rational Field - sage: Q = A.isotypic_projective_modules(side="left"); Q # optional - sage.rings.number_field + sage: Q = A.isotypic_projective_modules(side="left"); Q [Free module generated by {0} over Rational Field, Free module generated by {0, 1, 2} over Rational Field] - sage: [[x.lift() for x in Qi.basis()] # optional - sage.rings.number_field + sage: [[x.lift() for x in Qi.basis()] ....: for Qi in Q] [[x], [y, a, b]] @@ -752,7 +769,7 @@ def isotypic_projective_modules(self, side='left'): We check that the sum of the dimensions of the isotypic projective modules is the dimension of ``self``:: - sage: sum([Qi.dimension() for Qi in Q]) == A.dimension() # optional - sage.rings.number_field + sage: sum([Qi.dimension() for Qi in Q]) == A.dimension() # needs sage.graphs sage.modules sage.rings.number_field True .. SEEALSO:: @@ -784,19 +801,19 @@ def peirce_summand(self, ei, ej): EXAMPLES:: sage: A = Algebras(QQ).FiniteDimensional().WithBasis().example() - sage: idemp = A.orthogonal_idempotents_central_mod_radical() # optional - sage.rings.number_field - sage: A.peirce_summand(idemp[0], idemp[1]) # optional - sage.rings.number_field + sage: idemp = A.orthogonal_idempotents_central_mod_radical() # needs sage.rings.number_field + sage: A.peirce_summand(idemp[0], idemp[1]) # needs sage.rings.number_field Free module generated by {0, 1} over Rational Field - sage: A.peirce_summand(idemp[1], idemp[0]) # optional - sage.rings.number_field + sage: A.peirce_summand(idemp[1], idemp[0]) # needs sage.rings.number_field Free module generated by {} over Rational Field We recover the `2\times2` block of `\QQ[S_4]` corresponding to the unique simple module of dimension `2` of the symmetric group `S_4`:: - sage: A4 = SymmetricGroup(4).algebra(QQ) # optional - sage.groups - sage: e = A4.central_orthogonal_idempotents()[2] # optional - sage.groups sage.rings.number_field - sage: A4.peirce_summand(e, e) # optional - sage.groups sage.rings.number_field + sage: A4 = SymmetricGroup(4).algebra(QQ) # needs sage.groups + sage: e = A4.central_orthogonal_idempotents()[2] # needs sage.groups sage.rings.number_field + sage: A4.peirce_summand(e, e) # needs sage.groups sage.rings.number_field Free module generated by {0, 1, 2, 3} over Rational Field TESTS: @@ -804,11 +821,12 @@ def peirce_summand(self, ei, ej): We check each idempotent belong to its own Peirce summand (see :trac:`24687`):: - sage: from sage.monoids.hecke_monoid import HeckeMonoid # optional - sage.groups - sage: M = HeckeMonoid(SymmetricGroup(4)) # optional - sage.groups - sage: A = M.algebra(QQ) # optional - sage.groups - sage: Idms = A.orthogonal_idempotents_central_mod_radical() # optional - sage.groups sage.rings.number_field - sage: all(A.peirce_summand(e, e).retract(e) # optional - sage.groups sage.rings.number_field + sage: # needs sage.groups + sage: from sage.monoids.hecke_monoid import HeckeMonoid + sage: M = HeckeMonoid(SymmetricGroup(4)) + sage: A = M.algebra(QQ) + sage: Idms = A.orthogonal_idempotents_central_mod_radical() # needs sage.rings.number_field + sage: all(A.peirce_summand(e, e).retract(e) # needs sage.rings.number_field ....: in A.peirce_summand(e, e) for e in Idms) True """ @@ -861,18 +879,19 @@ def peirce_decomposition(self, idempotents=None, check=True): EXAMPLES:: + sage: # needs sage.graphs sage.groups sage.modules sage.rings.number_field sage: A = Algebras(QQ).FiniteDimensional().WithBasis().example(); A An example of a finite dimensional algebra with basis: the path algebra of the Kronecker quiver (containing the arrows a:x->y and b:x->y) over Rational Field - sage: A.orthogonal_idempotents_central_mod_radical() # optional - sage.groups + sage: A.orthogonal_idempotents_central_mod_radical() (x, y) - sage: decomposition = A.peirce_decomposition(); decomposition # optional - sage.groups sage.modules sage.rings.number_field + sage: decomposition = A.peirce_decomposition(); decomposition [[Free module generated by {0} over Rational Field, Free module generated by {0, 1} over Rational Field], [Free module generated by {} over Rational Field, Free module generated by {0} over Rational Field]] - sage: [ [[x.lift() for x in decomposition[i][j].basis()] # optional - sage.groups sage.modules sage.rings.number_field + sage: [ [[x.lift() for x in decomposition[i][j].basis()] ....: for j in range(2)] ....: for i in range(2)] [[[x], [a, b]], @@ -881,9 +900,10 @@ def peirce_decomposition(self, idempotents=None, check=True): We recover that the group algebra of the symmetric group `S_4` is a block matrix algebra:: - sage: A = SymmetricGroup(4).algebra(QQ) # optional - sage.groups sage.modules - sage: decomposition = A.peirce_decomposition() # long time # optional - sage.groups sage.modules sage.rings.number_field - sage: [[decomposition[i][j].dimension() # long time (4s) # optional - sage.groups sage.modules sage.rings.number_field + sage: # needs sage.groups sage.modules sage.rings.number_field + sage: A = SymmetricGroup(4).algebra(QQ) + sage: decomposition = A.peirce_decomposition() # long time + sage: [[decomposition[i][j].dimension() # long time (4s) ....: for j in range(len(decomposition))] ....: for i in range(len(decomposition))] [[9, 0, 0, 0, 0], @@ -896,7 +916,7 @@ def peirce_decomposition(self, idempotents=None, check=True): dimension of the corresponding simple module of `S_4`. The latter are given by:: - sage: [p.standard_tableaux().cardinality() for p in Partitions(4)] # optional - sage.combinat + sage: [p.standard_tableaux().cardinality() for p in Partitions(4)] # needs sage.combinat [1, 3, 2, 3, 1] """ if idempotents is None: @@ -918,14 +938,13 @@ def is_identity_decomposition_into_orthogonal_idempotents(self, l): EXAMPLES:: + sage: # needs sage.graphs sage.modules sage: A = FiniteDimensionalAlgebrasWithBasis(QQ).example(); A An example of a finite dimensional algebra with basis: the path algebra of the Kronecker quiver (containing the arrows a:x->y and b:x->y) over Rational Field - sage: x,y,a,b = A.algebra_generators(); x,y,a,b (x, y, a, b) - sage: A.is_identity_decomposition_into_orthogonal_idempotents([A.one()]) True sage: A.is_identity_decomposition_into_orthogonal_idempotents([x, y]) @@ -935,20 +954,21 @@ def is_identity_decomposition_into_orthogonal_idempotents(self, l): Here the idempotents do not sum up to `1`:: - sage: A.is_identity_decomposition_into_orthogonal_idempotents([x]) + sage: A.is_identity_decomposition_into_orthogonal_idempotents([x]) # needs sage.graphs sage.modules False Here `1+x` and `-x` are neither idempotent nor orthogonal:: - sage: A.is_identity_decomposition_into_orthogonal_idempotents([1 + x, -x]) + sage: A.is_identity_decomposition_into_orthogonal_idempotents([1 + x, -x]) # needs sage.graphs sage.modules False With the algebra of the `0`-Hecke monoid:: - sage: from sage.monoids.hecke_monoid import HeckeMonoid # optional - sage.groups - sage: A = HeckeMonoid(SymmetricGroup(4)).algebra(QQ) # optional - sage.groups sage.modules - sage: idempotents = A.orthogonal_idempotents_central_mod_radical() # optional - sage.groups sage.modules sage.rings.number_field - sage: A.is_identity_decomposition_into_orthogonal_idempotents(idempotents) # optional - sage.groups sage.modules sage.rings.number_field + sage: # needs sage.combinat sage.groups sage.modules + sage: from sage.monoids.hecke_monoid import HeckeMonoid + sage: A = HeckeMonoid(SymmetricGroup(4)).algebra(QQ) + sage: idempotents = A.orthogonal_idempotents_central_mod_radical() # needs sage.rings.number_field + sage: A.is_identity_decomposition_into_orthogonal_idempotents(idempotents) # needs sage.rings.number_field True Here are some more counterexamples: @@ -956,6 +976,7 @@ def is_identity_decomposition_into_orthogonal_idempotents(self, l): 1. Some orthogonal elements summing to `1` but not being idempotent:: + sage: # needs sage.libs.pari sage.modules sage: class PQAlgebra(CombinatorialFreeModule): ....: def __init__(self, F, p): ....: # Construct the quotient algebra F[x] / p, @@ -973,40 +994,43 @@ def is_identity_decomposition_into_orthogonal_idempotents(self, l): ....: def product_on_basis(self, w1, w2): ....: return self.from_vector(vector(w1*w2)) sage: R. = PolynomialRing(QQ) - sage: A = PQAlgebra(QQ, x**3 - x**2 + x + 1); y = A.x() # optional - sage.libs.pari - sage: a, b = y, 1 - y # optional - sage.libs.pari - sage: A.is_identity_decomposition_into_orthogonal_idempotents((a, b)) # optional - sage.libs.pari + sage: A = PQAlgebra(QQ, x**3 - x**2 + x + 1); y = A.x() + sage: a, b = y, 1 - y + sage: A.is_identity_decomposition_into_orthogonal_idempotents((a, b)) False For comparison:: - sage: A = PQAlgebra(QQ, x**2 - x); y = A.x() # optional - sage.libs.pari - sage: a, b = y, 1-y # optional - sage.libs.pari - sage: A.is_identity_decomposition_into_orthogonal_idempotents((a, b)) # optional - sage.libs.pari + sage: # needs sage.libs.pari sage.modules + sage: A = PQAlgebra(QQ, x**2 - x); y = A.x() + sage: a, b = y, 1-y + sage: A.is_identity_decomposition_into_orthogonal_idempotents((a, b)) True - sage: A.is_identity_decomposition_into_orthogonal_idempotents((a, A.zero(), b)) # optional - sage.libs.pari + sage: A.is_identity_decomposition_into_orthogonal_idempotents((a, A.zero(), b)) True - sage: A = PQAlgebra(QQ, x**3 - x**2 + x - 1); y = A.x() # optional - sage.libs.pari - sage: a = (y**2 + 1) / 2 # optional - sage.libs.pari - sage: b = 1 - a # optional - sage.libs.pari - sage: A.is_identity_decomposition_into_orthogonal_idempotents((a, b)) # optional - sage.libs.pari + sage: A = PQAlgebra(QQ, x**3 - x**2 + x - 1); y = A.x() + sage: a = (y**2 + 1) / 2 + sage: b = 1 - a + sage: A.is_identity_decomposition_into_orthogonal_idempotents((a, b)) True 2. Some idempotents summing to 1 but not orthogonal:: - sage: R. = PolynomialRing(GF(2)) # optional - sage.rings.finite_rings - sage: A = PQAlgebra(GF(2), x) # optional - sage.rings.finite_rings - sage: a = A.one() # optional - sage.rings.finite_rings - sage: A.is_identity_decomposition_into_orthogonal_idempotents((a,)) # optional - sage.rings.finite_rings + sage: # needs sage.libs.pari sage.modules + sage: R. = PolynomialRing(GF(2)) + sage: A = PQAlgebra(GF(2), x) + sage: a = A.one() + sage: A.is_identity_decomposition_into_orthogonal_idempotents((a,)) True - sage: A.is_identity_decomposition_into_orthogonal_idempotents((a, a, a)) # optional - sage.rings.finite_rings + sage: A.is_identity_decomposition_into_orthogonal_idempotents((a, a, a)) False 3. Some orthogonal idempotents not summing to the identity:: - sage: A.is_identity_decomposition_into_orthogonal_idempotents((a,a)) # optional - sage.rings.finite_rings + sage: # needs sage.libs.pari sage.modules + sage: A.is_identity_decomposition_into_orthogonal_idempotents((a,a)) False - sage: A.is_identity_decomposition_into_orthogonal_idempotents(()) # optional - sage.rings.finite_rings + sage: A.is_identity_decomposition_into_orthogonal_idempotents(()) False """ return (self.sum(l) == self.one() @@ -1021,11 +1045,12 @@ def is_commutative(self): EXAMPLES:: - sage: S4 = SymmetricGroupAlgebra(QQ, 4) # optional - sage.groups sage.modules - sage: S4.is_commutative() # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: S4 = SymmetricGroupAlgebra(QQ, 4) + sage: S4.is_commutative() False - sage: S2 = SymmetricGroupAlgebra(QQ, 2) # optional - sage.groups sage.modules - sage: S2.is_commutative() # optional - sage.groups sage.modules + sage: S2 = SymmetricGroupAlgebra(QQ, 2) + sage: S2.is_commutative() True """ B = list(self.basis()) @@ -1049,23 +1074,24 @@ def to_matrix(self, base_ring=None, action=operator.mul, side='left'): EXAMPLES:: - sage: QS3 = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules - sage: a = QS3([2,1,3]) # optional - sage.groups sage.modules - sage: a.to_matrix(side='left') # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: QS3 = SymmetricGroupAlgebra(QQ, 3) + sage: a = QS3([2,1,3]) + sage: a.to_matrix(side='left') [0 0 1 0 0 0] [0 0 0 0 1 0] [1 0 0 0 0 0] [0 0 0 0 0 1] [0 1 0 0 0 0] [0 0 0 1 0 0] - sage: a.to_matrix(side='right') # optional - sage.groups sage.modules + sage: a.to_matrix(side='right') [0 0 1 0 0 0] [0 0 0 1 0 0] [1 0 0 0 0 0] [0 1 0 0 0 0] [0 0 0 0 0 1] [0 0 0 0 1 0] - sage: a.to_matrix(base_ring=RDF, side="left") # optional - sage.groups sage.modules + sage: a.to_matrix(base_ring=RDF, side="left") [0.0 0.0 1.0 0.0 0.0 0.0] [0.0 0.0 0.0 0.0 1.0 0.0] [1.0 0.0 0.0 0.0 0.0 0.0] @@ -1102,47 +1128,50 @@ def __invert__(self): EXAMPLES:: - sage: QS3 = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules - sage: P = Permutation # optional - sage.groups sage.modules - sage: a = 3 * QS3(P([1,2,3])) + QS3(P([1,3,2])) + QS3(P([2,1,3])) # optional - sage.groups sage.modules - sage: b = ~a; b # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: QS3 = SymmetricGroupAlgebra(QQ, 3) + sage: P = Permutation + sage: a = 3 * QS3(P([1,2,3])) + QS3(P([1,3,2])) + QS3(P([2,1,3])) + sage: b = ~a; b 9/20*[1, 2, 3] - 7/40*[1, 3, 2] - 7/40*[2, 1, 3] + 3/40*[2, 3, 1] + 3/40*[3, 1, 2] - 1/20*[3, 2, 1] - sage: a * b # optional - sage.groups sage.modules + sage: a * b [1, 2, 3] - sage: ~b == a # optional - sage.groups sage.modules + sage: ~b == a True - sage: a = 3 * QS3.one() # optional - sage.groups sage.modules - sage: b = ~a # optional - sage.groups sage.modules - sage: b * a == QS3.one() # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: a = 3 * QS3.one() + sage: b = ~a + sage: b * a == QS3.one() True - sage: b == 1/3 * QS3.one() # optional - sage.groups sage.modules + sage: b == 1/3 * QS3.one() True - sage: ~b == a # optional - sage.groups sage.modules + sage: ~b == a True sage: R. = QQ[] - sage: RS3 = SymmetricGroupAlgebra(R, 3) # optional - sage.groups sage.modules - sage: a = RS3(P([1,2,3])) - RS3(P([1,3,2])) + RS3(P([2,1,3])); ~a # optional - sage.groups sage.modules + sage: RS3 = SymmetricGroupAlgebra(R, 3) # needs sage.groups sage.modules + sage: a = RS3(P([1,2,3])) - RS3(P([1,3,2])) + RS3(P([2,1,3])); ~a # needs sage.groups sage.modules -1/2*[1, 3, 2] + 1/2*[2, 1, 3] + 1/2*[2, 3, 1] + 1/2*[3, 1, 2] Some examples on elements that do not have an inverse:: - sage: c = 2 * QS3(P([1,2,3])) + QS3(P([1,3,2])) + QS3(P([2,1,3])) # optional - sage.groups sage.modules - sage: ~c # optional - sage.groups sage.modules + sage: c = 2 * QS3(P([1,2,3])) + QS3(P([1,3,2])) + QS3(P([2,1,3])) # needs sage.groups sage.modules + sage: ~c # needs sage.groups sage.modules Traceback (most recent call last): ... ValueError: cannot invert self (= 2*[1, 2, 3] + [1, 3, 2] + [2, 1, 3]) - sage: ZS3 = SymmetricGroupAlgebra(ZZ, 3) # optional - sage.groups sage.modules - sage: aZ = 3 * ZS3(P([1,2,3])) + ZS3(P([1,3,2])) + ZS3(P([2,1,3])) # optional - sage.groups sage.modules - sage: ~aZ # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: ZS3 = SymmetricGroupAlgebra(ZZ, 3) + sage: aZ = 3 * ZS3(P([1,2,3])) + ZS3(P([1,3,2])) + ZS3(P([2,1,3])) + sage: ~aZ Traceback (most recent call last): ... ValueError: cannot invert self (= 3*[1, 2, 3] + [1, 3, 2] + [2, 1, 3]) - sage: x = 2 * ZS3.one() # optional - sage.groups sage.modules - sage: ~x # optional - sage.groups sage.modules + sage: x = 2 * ZS3.one() + sage: ~x Traceback (most recent call last): ... ValueError: cannot invert self (= 2*[1, 2, 3]) @@ -1151,9 +1180,9 @@ def __invert__(self): An algebra that does not define ``one_basis()``:: - sage: I = DescentAlgebra(QQ, 3).I() # optional - sage.combinat sage.modules - sage: a = 3 * I.one() # optional - sage.combinat sage.modules - sage: ~a == 1/3 * I.one() # optional - sage.combinat sage.modules + sage: I = DescentAlgebra(QQ, 3).I() # needs sage.combinat sage.modules + sage: a = 3 * I.one() # needs sage.combinat sage.modules + sage: ~a == 1/3 * I.one() # needs sage.combinat sage.modules True """ alg = self.parent() @@ -1241,8 +1270,8 @@ def _test_cellular(self, **options): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 3) # optional - sage.combinat sage.modules - sage: S._test_cellular() # optional - sage.combinat sage.modules + sage: S = SymmetricGroupAlgebra(QQ, 3) # needs sage.combinat sage.modules + sage: S._test_cellular() # needs sage.combinat sage.modules """ tester = self._tester(**options) cell_basis = self.cellular_basis() @@ -1275,8 +1304,8 @@ def cell_poset(self): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 4) # optional - sage.groups sage.modules - sage: S.cell_poset() # optional - sage.groups sage.modules + sage: S = SymmetricGroupAlgebra(QQ, 4) # needs sage.groups sage.modules + sage: S.cell_poset() # needs sage.groups sage.modules Finite poset containing 5 elements """ @@ -1290,8 +1319,8 @@ def cell_module_indices(self, mu): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules - sage: S.cell_module_indices([2,1]) # optional - sage.groups sage.modules + sage: S = SymmetricGroupAlgebra(QQ, 3) # needs sage.groups sage.modules + sage: S.cell_module_indices([2,1]) # needs sage.groups sage.modules Standard tableaux of shape [2, 1] """ @@ -1303,8 +1332,8 @@ def _to_cellular_element(self, i): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules - sage: S._to_cellular_element # no implementation currently uses this # optional - sage.groups sage.modules + sage: S = SymmetricGroupAlgebra(QQ, 3) # needs sage.groups sage.modules + sage: S._to_cellular_element # no implementation currently uses this # needs sage.groups sage.modules NotImplemented """ @@ -1316,11 +1345,12 @@ def _from_cellular_index(self, x): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 3) # optional - sage.combinat sage.groups sage.modules - sage: mu = Partition([2,1]) # optional - sage.combinat sage.groups sage.modules - sage: s = StandardTableau([[1,2],[3]]) # optional - sage.combinat sage.groups sage.modules - sage: t = StandardTableau([[1,3],[2]]) # optional - sage.combinat sage.groups sage.modules - sage: S._from_cellular_index((mu, s, t)) # optional - sage.combinat sage.groups sage.modules + sage: # needs sage.combinat sage.groups sage.modules + sage: S = SymmetricGroupAlgebra(QQ, 3) + sage: mu = Partition([2,1]) + sage: s = StandardTableau([[1,2],[3]]) + sage: t = StandardTableau([[1,3],[2]]) + sage: S._from_cellular_index((mu, s, t)) 1/4*[1, 3, 2] - 1/4*[2, 3, 1] + 1/4*[3, 1, 2] - 1/4*[3, 2, 1] """ @@ -1330,8 +1360,8 @@ def cellular_involution(self, x): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules - sage: for b in S.basis(): b, S.cellular_involution(b) # optional - sage.groups sage.modules + sage: S = SymmetricGroupAlgebra(QQ, 3) # needs sage.groups sage.modules + sage: for b in S.basis(): b, S.cellular_involution(b) # needs sage.groups sage.modules ([1, 2, 3], [1, 2, 3]) ([1, 3, 2], 49/48*[1, 3, 2] + 7/48*[2, 3, 1] - 7/48*[3, 1, 2] - 1/48*[3, 2, 1]) @@ -1357,8 +1387,8 @@ def cells(self): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules - sage: dict(S.cells()) # optional - sage.groups sage.modules + sage: S = SymmetricGroupAlgebra(QQ, 3) # needs sage.groups sage.modules + sage: dict(S.cells()) # needs sage.groups sage.modules {[1, 1, 1]: Standard tableaux of shape [1, 1, 1], [2, 1]: Standard tableaux of shape [2, 1], [3]: Standard tableaux of shape [3]} @@ -1372,8 +1402,8 @@ def cellular_basis(self): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules - sage: S.cellular_basis() # optional - sage.groups sage.modules + sage: S = SymmetricGroupAlgebra(QQ, 3) # needs sage.groups sage.modules + sage: S.cellular_basis() # needs sage.groups sage.modules Cellular basis of Symmetric group algebra of order 3 over Rational Field """ @@ -1386,8 +1416,8 @@ def cell_module(self, mu, **kwds): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules - sage: S.cell_module(Partition([2,1])) # optional - sage.combinat sage.groups sage.modules + sage: S = SymmetricGroupAlgebra(QQ, 3) # needs sage.groups sage.modules + sage: S.cell_module(Partition([2,1])) # needs sage.combinat sage.groups sage.modules Cell module indexed by [2, 1] of Cellular basis of Symmetric group algebra of order 3 over Rational Field """ @@ -1405,8 +1435,8 @@ def simple_module_parameterization(self): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 4) # optional - sage.groups sage.modules - sage: S.simple_module_parameterization() # optional - sage.groups sage.modules + sage: S = SymmetricGroupAlgebra(QQ, 4) # needs sage.groups sage.modules + sage: S.simple_module_parameterization() # needs sage.groups sage.modules ([4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]) """ return tuple([mu for mu in self.cell_poset() @@ -1419,12 +1449,13 @@ def cellular_involution(self): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 4) # optional - sage.groups sage.modules - sage: elt = S([3,1,2,4]) # optional - sage.groups sage.modules - sage: ci = elt.cellular_involution(); ci # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: S = SymmetricGroupAlgebra(QQ, 4) + sage: elt = S([3,1,2,4]) + sage: ci = elt.cellular_involution(); ci 7/48*[1, 3, 2, 4] + 49/48*[2, 3, 1, 4] - 1/48*[3, 1, 2, 4] - 7/48*[3, 2, 1, 4] - sage: ci.cellular_involution() # optional - sage.groups sage.modules + sage: ci.cellular_involution() [3, 1, 2, 4] """ return self.parent().cellular_involution(self) @@ -1456,10 +1487,11 @@ def cell_poset(self): EXAMPLES:: - sage: S2 = SymmetricGroupAlgebra(QQ, 2) # optional - sage.groups sage.modules - sage: S3 = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules - sage: T = S2.tensor(S3) # optional - sage.groups sage.modules - sage: T.cell_poset() # optional - sage.combinat sage.graphs sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: S2 = SymmetricGroupAlgebra(QQ, 2) + sage: S3 = SymmetricGroupAlgebra(QQ, 3) + sage: T = S2.tensor(S3) + sage: T.cell_poset() # needs sage.combinat sage.graphs Finite poset containing 6 elements """ ret = self._sets[0].cell_poset() @@ -1476,10 +1508,11 @@ def cell_module_indices(self, mu): EXAMPLES:: - sage: S2 = SymmetricGroupAlgebra(QQ, 2) # optional - sage.groups sage.modules - sage: S3 = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules - sage: T = S2.tensor(S3) # optional - sage.groups sage.modules - sage: T.cell_module_indices(([1,1], [2,1])) # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: S2 = SymmetricGroupAlgebra(QQ, 2) + sage: S3 = SymmetricGroupAlgebra(QQ, 3) + sage: T = S2.tensor(S3) + sage: T.cell_module_indices(([1,1], [2,1])) The Cartesian product of (Standard tableaux of shape [1, 1], Standard tableaux of shape [2, 1]) """ @@ -1495,10 +1528,11 @@ def cellular_involution(self): EXAMPLES:: - sage: S2 = SymmetricGroupAlgebra(QQ, 2) # optional - sage.groups sage.modules - sage: S3 = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules - sage: T = S2.tensor(S3) # optional - sage.groups sage.modules - sage: for b in T.basis(): b, T.cellular_involution(b) # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: S2 = SymmetricGroupAlgebra(QQ, 2) + sage: S3 = SymmetricGroupAlgebra(QQ, 3) + sage: T = S2.tensor(S3) + sage: for b in T.basis(): b, T.cellular_involution(b) ([1, 2] # [1, 2, 3], [1, 2] # [1, 2, 3]) ([1, 2] # [1, 3, 2], 49/48*[1, 2] # [1, 3, 2] + 7/48*[1, 2] # [2, 3, 1] @@ -1548,10 +1582,11 @@ def _to_cellular_element(self, i): EXAMPLES:: - sage: S2 = SymmetricGroupAlgebra(QQ, 2) # optional - sage.groups sage.modules - sage: S3 = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules - sage: T = S2.tensor(S3) # optional - sage.groups sage.modules - sage: all(T(T._to_cellular_element(k)).leading_support() == k # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: S2 = SymmetricGroupAlgebra(QQ, 2) + sage: S3 = SymmetricGroupAlgebra(QQ, 3) + sage: T = S2.tensor(S3) + sage: all(T(T._to_cellular_element(k)).leading_support() == k ....: for k in T.basis().keys()) True """ @@ -1584,11 +1619,12 @@ def _from_cellular_index(self, x): EXAMPLES:: - sage: S2 = SymmetricGroupAlgebra(QQ, 2) # optional - sage.groups sage.modules - sage: S3 = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules - sage: T = S2.tensor(S3) # optional - sage.groups sage.modules - sage: C = T.cellular_basis() # optional - sage.groups sage.modules - sage: all(C(T._from_cellular_index(k)).leading_support() == k # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: S2 = SymmetricGroupAlgebra(QQ, 2) + sage: S3 = SymmetricGroupAlgebra(QQ, 3) + sage: T = S2.tensor(S3) + sage: C = T.cellular_basis() + sage: all(C(T._from_cellular_index(k)).leading_support() == k ....: for k in C.basis().keys()) True """ diff --git a/src/sage/categories/finite_dimensional_graded_lie_algebras_with_basis.py b/src/sage/categories/finite_dimensional_graded_lie_algebras_with_basis.py index e10e30a5846..c5554a2f094 100644 --- a/src/sage/categories/finite_dimensional_graded_lie_algebras_with_basis.py +++ b/src/sage/categories/finite_dimensional_graded_lie_algebras_with_basis.py @@ -53,14 +53,15 @@ def _test_grading(self, **options): EXAMPLES:: + sage: # needs sage.combinat sage.modules sage: C = LieAlgebras(QQ).WithBasis().Graded() sage: C = C.FiniteDimensional().Stratified().Nilpotent() - sage: L = LieAlgebra(QQ, {('x','y'): {'z': 1}}, # optional - sage.combinat sage.modules + sage: L = LieAlgebra(QQ, {('x','y'): {'z': 1}}, ....: nilpotent=True, category=C) - sage: L._test_grading() # optional - sage.combinat sage.modules - sage: L = LieAlgebra(QQ, {('x','y'): {'x': 1}}, # optional - sage.combinat sage.modules + sage: L._test_grading() + sage: L = LieAlgebra(QQ, {('x','y'): {'x': 1}}, ....: nilpotent=True, category=C) - sage: L._test_grading() # optional - sage.combinat sage.modules + sage: L._test_grading() Traceback (most recent call last): ... AssertionError: Lie bracket [x, y] has degree 1, not degree 2 @@ -96,9 +97,9 @@ def homogeneous_component_as_submodule(self, d): sage: C = LieAlgebras(QQ).WithBasis().Graded() sage: C = C.FiniteDimensional().Stratified().Nilpotent() - sage: L = LieAlgebra(QQ, {('x','y'): {'z': 1}}, # optional - sage.combinat sage.modules + sage: L = LieAlgebra(QQ, {('x','y'): {'z': 1}}, # needs sage.combinat sage.modules ....: nilpotent=True, category=C) - sage: L.homogeneous_component_as_submodule(2) # optional - sage.combinat sage.modules + sage: L.homogeneous_component_as_submodule(2) # needs sage.combinat sage.modules Sparse vector space of degree 3 and dimension 1 over Rational Field Basis matrix: [0 0 1] @@ -147,12 +148,12 @@ def _test_generated_by_degree_one(self, **options): sage: C = LieAlgebras(QQ).WithBasis().Graded() sage: C = C.FiniteDimensional().Stratified().Nilpotent() sage: sc = {('x','y'): {'z': 1}} - sage: L. = LieAlgebra(QQ, sc, nilpotent=True, category=C) # optional - sage.combinat sage.modules - sage: L._test_generated_by_degree_one() # optional - sage.combinat sage.modules + sage: L. = LieAlgebra(QQ, sc, nilpotent=True, category=C) # needs sage.combinat sage.modules + sage: L._test_generated_by_degree_one() # needs sage.combinat sage.modules sage: sc = {('x','y'): {'z': 1}, ('a','b'): {'c':1}, ('z','c'): {'m':1}} - sage: L. = LieAlgebra(QQ, sc, nilpotent=True, category=C) # optional - sage.combinat sage.modules - sage: L._test_generated_by_degree_one() # optional - sage.combinat sage.modules + sage: L. = LieAlgebra(QQ, sc, nilpotent=True, category=C) # needs sage.combinat sage.modules + sage: L._test_generated_by_degree_one() # needs sage.combinat sage.modules Traceback (most recent call last): ... AssertionError: [a, b, x, y] does not generate Nilpotent Lie algebra @@ -196,19 +197,20 @@ def degree_on_basis(self, m): EXAMPLES:: + sage: # needs sage.combinat sage.modules sage: C = LieAlgebras(QQ).WithBasis().Graded() sage: C = C.FiniteDimensional().Stratified().Nilpotent() sage: sc = {('X','Y'): {'Z': 1}} - sage: L. = LieAlgebra(QQ, sc, nilpotent=True, category=C) # optional - sage.combinat sage.modules - sage: L.degree_on_basis(X.leading_support()) # optional - sage.combinat sage.modules + sage: L. = LieAlgebra(QQ, sc, nilpotent=True, category=C) + sage: L.degree_on_basis(X.leading_support()) 1 - sage: X.degree() # optional - sage.combinat sage.modules + sage: X.degree() 1 - sage: Y.degree() # optional - sage.combinat sage.modules + sage: Y.degree() 1 - sage: L[X, Y] # optional - sage.combinat sage.modules + sage: L[X, Y] Z - sage: Z.degree() # optional - sage.combinat sage.modules + sage: Z.degree() 2 """ if not hasattr(self, '_basis_degrees'): diff --git a/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py b/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py index 67181caffa9..013b30dc281 100644 --- a/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py +++ b/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py @@ -46,13 +46,13 @@ def example(self, n=3): EXAMPLES:: sage: C = LieAlgebras(QQ).FiniteDimensional().WithBasis() - sage: C.example() # optional - sage.modules + sage: C.example() # needs sage.modules An example of a finite dimensional Lie algebra with basis: the 3-dimensional abelian Lie algebra over Rational Field Other dimensions can be specified as an optional argument:: - sage: C.example(5) # optional - sage.modules + sage: C.example(5) # needs sage.modules An example of a finite dimensional Lie algebra with basis: the 5-dimensional abelian Lie algebra over Rational Field """ @@ -70,29 +70,31 @@ def _construct_UEA(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules sage.combinat - sage: UEA = L._construct_UEA(); UEA # optional - sage.modules sage.combinat + sage: # needs sage.combinat sage.libs.singular sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() + sage: UEA = L._construct_UEA(); UEA Noncommutative Multivariate Polynomial Ring in b0, b1, b2 over Rational Field, nc-relations: {} - sage: UEA.relations(add_commutative=True) # optional - sage.modules sage.combinat + sage: UEA.relations(add_commutative=True) {b1*b0: b0*b1, b2*b0: b0*b2, b2*b1: b1*b2} :: - sage: L. = LieAlgebra(QQ, {('x','y'): {'z':1}, # optional - sage.modules sage.combinat + sage: # needs sage.combinat sage.libs.singular sage.modules + sage: L. = LieAlgebra(QQ, {('x','y'): {'z':1}, ....: ('y','z'): {'x':1}, ....: ('z','x'):{'y':1}}) - sage: UEA = L._construct_UEA(); UEA # optional - sage.modules sage.combinat + sage: UEA = L._construct_UEA(); UEA Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {...} - sage: sorted(UEA.relations().items(), key=str) # optional - sage.modules sage.combinat + sage: sorted(UEA.relations().items(), key=str) [(y*x, x*y - z), (z*x, x*z + y), (z*y, y*z - x)] Singular's ``nc_algebra`` does not work over `\ZZ/6\ZZ`, so we fallback to the PBW basis in this case:: - sage: L = lie_algebras.pwitt(Zmod(6), 6) # optional - sage.modules sage.combinat - sage: L._construct_UEA() # optional - sage.modules sage.combinat + sage: L = lie_algebras.pwitt(Zmod(6), 6) # needs sage.combinat sage.modules + sage: L._construct_UEA() # needs sage.combinat sage.libs.singular sage.modules Universal enveloping algebra of The 6-Witt Lie algebra over Ring of integers modulo 6 in the Poincare-Birkhoff-Witt basis @@ -149,8 +151,8 @@ def _basis_ordering(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules sage.combinat - sage: L._basis_ordering # optional - sage.modules sage.combinat + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.modules + sage: L._basis_ordering # needs sage.modules (0, 1, 2) """ return tuple(self.basis().keys()) @@ -163,10 +165,11 @@ def _basis_key_inverse(self): EXAMPLES:: - sage: G = SymmetricGroup(3) # optional - sage.groups - sage: S = GroupAlgebra(G, QQ) # optional - sage.groups sage.modules - sage: L = LieAlgebra(associative=S) # optional - sage.groups sage.modules - sage: [L._basis_key_inverse[k] for k in L._basis_ordering] # optional - sage.groups sage.modules + sage: # needs sage.combinat sage.groups sage.modules + sage: G = SymmetricGroup(3) + sage: S = GroupAlgebra(G, QQ) + sage: L = LieAlgebra(associative=S) + sage: [L._basis_key_inverse[k] for k in L._basis_ordering] [0, 1, 2, 3, 4, 5] """ return {k: i for i,k in enumerate(self._basis_ordering)} @@ -177,34 +180,35 @@ def _basis_key(self, x): TESTS:: - sage: L = lie_algebras.three_dimensional_by_rank(QQ, 3, # optional - sage.groups sage.modules + sage: L = lie_algebras.three_dimensional_by_rank(QQ, 3, # needs sage.groups sage.modules ....: names=['E','F','H']) - sage: PBW = L.pbw_basis() # optional - sage.groups sage.modules - sage: PBW._basis_key('E') < PBW._basis_key('H') # optional - sage.groups sage.modules + sage: PBW = L.pbw_basis() # needs sage.groups sage.modules + sage: PBW._basis_key('E') < PBW._basis_key('H') # needs sage.groups sage.modules True :: - sage: L = lie_algebras.sl(QQ, 2) # optional - sage.groups sage.modules - sage: def neg_key(x): # optional - sage.groups sage.modules + sage: L = lie_algebras.sl(QQ, 2) # needs sage.groups sage.modules + sage: def neg_key(x): ....: return -L.basis().keys().index(x) - sage: PBW = L.pbw_basis(basis_key=neg_key) # optional - sage.groups sage.modules - sage: prod(PBW.gens()) # indirect doctest # optional - sage.groups sage.modules + sage: PBW = L.pbw_basis(basis_key=neg_key) # needs sage.groups sage.modules + sage: prod(PBW.gens()) # indirect doctest # needs sage.groups sage.modules PBW[-alpha[1]]*PBW[alphacheck[1]]*PBW[alpha[1]] - 4*PBW[-alpha[1]]*PBW[alpha[1]] + PBW[alphacheck[1]]^2 - 2*PBW[alphacheck[1]] Check that :trac:`23266` is fixed:: - sage: sl2 = lie_algebras.sl(QQ, 2, 'matrix') # optional - sage.groups sage.modules - sage: sl2.indices() # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: sl2 = lie_algebras.sl(QQ, 2, 'matrix') + sage: sl2.indices() {'e1', 'f1', 'h1'} - sage: type(sl2.basis().keys()) # optional - sage.groups sage.modules + sage: type(sl2.basis().keys()) - sage: Usl2 = sl2.pbw_basis() # optional - sage.groups sage.modules - sage: Usl2._basis_key(2) # optional - sage.groups sage.modules + sage: Usl2 = sl2.pbw_basis() + sage: Usl2._basis_key(2) 2 - sage: Usl2._basis_key(3) # optional - sage.groups sage.modules + sage: Usl2._basis_key(3) Traceback (most recent call last): ... KeyError: 3 @@ -217,8 +221,8 @@ def _dense_free_module(self, R=None): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules - sage: L._dense_free_module() # optional - sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.modules + sage: L._dense_free_module() # needs sage.modules Vector space of dimension 3 over Rational Field """ if R is None: @@ -240,10 +244,10 @@ def from_vector(self, v, order=None): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules - sage: u = L.from_vector(vector(QQ, (1, 0, 0))); u # optional - sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.modules + sage: u = L.from_vector(vector(QQ, (1, 0, 0))); u # needs sage.modules (1, 0, 0) - sage: parent(u) is L # optional - sage.modules + sage: parent(u) is L # needs sage.modules True """ if order is None: @@ -263,17 +267,17 @@ def killing_matrix(self, x, y): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules - sage: a, b, c = L.lie_algebra_generators() # optional - sage.modules - sage: L.killing_matrix(a, b) # optional - sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.modules + sage: a, b, c = L.lie_algebra_generators() # needs sage.modules + sage: L.killing_matrix(a, b) # needs sage.modules [0 0 0] [0 0 0] [0 0 0] :: - sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules - sage: L.killing_matrix(y, x) # optional - sage.combinat sage.modules + sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) # needs sage.combinat sage.modules + sage: L.killing_matrix(y, x) # needs sage.combinat sage.modules [ 0 -1] [ 0 0] """ @@ -294,9 +298,9 @@ def killing_form(self, x, y): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules - sage: a, b, c = L.lie_algebra_generators() # optional - sage.combinat sage.modules - sage: L.killing_form(a, b) # optional - sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.modules + sage: a, b, c = L.lie_algebra_generators() # needs sage.modules + sage: L.killing_form(a, b) # needs sage.modules 0 """ return self.killing_matrix(x, y).trace() @@ -312,16 +316,16 @@ def killing_form_matrix(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules - sage: L.killing_form_matrix() # optional - sage.modules + sage: # needs sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() + sage: L.killing_form_matrix() [0 0 0] [0 0 0] [0 0 0] - - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example(0) # optional - sage.modules - sage: m = L.killing_form_matrix(); m # optional - sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example(0) + sage: m = L.killing_form_matrix(); m [] - sage: parent(m) # optional - sage.modules + sage: parent(m) Full MatrixSpace of 0 by 0 dense matrices over Rational Field """ from sage.matrix.constructor import matrix @@ -350,18 +354,19 @@ def structure_coefficients(self, include_zeros=False): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules - sage: L.structure_coefficients() # optional - sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.modules + sage: L.structure_coefficients() # needs sage.modules Finite family {} - sage: L.structure_coefficients(True) # optional - sage.modules + sage: L.structure_coefficients(True) # needs sage.modules Finite family {(0, 1): (0, 0, 0), (0, 2): (0, 0, 0), (1, 2): (0, 0, 0)} :: - sage: G = SymmetricGroup(3) # optional - sage.groups - sage: S = GroupAlgebra(G, QQ) # optional - sage.groups sage.modules - sage: L = LieAlgebra(associative=S) # optional - sage.groups sage.modules sage.combinat - sage: L.structure_coefficients() # optional - sage.groups sage.modules sage.combinat + sage: # needs sage.combinat sage.groups sage.modules + sage: G = SymmetricGroup(3) + sage: S = GroupAlgebra(G, QQ) + sage: L = LieAlgebra(associative=S) + sage: L.structure_coefficients() Finite family {((2,3), (1,2)): (1,2,3) - (1,3,2), ((2,3), (1,3)): -(1,2,3) + (1,3,2), ((1,2,3), (2,3)): -(1,2) + (1,3), @@ -404,23 +409,25 @@ def centralizer_basis(self, S): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules - sage: a, b, c = L.lie_algebra_generators() # optional - sage.modules - sage: L.centralizer_basis([a + b, 2*a + c]) # optional - sage.modules + sage: # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() + sage: a, b, c = L.lie_algebra_generators() + sage: L.centralizer_basis([a + b, 2*a + c]) [(1, 0, 0), (0, 1, 0), (0, 0, 1)] - sage: H = lie_algebras.Heisenberg(QQ, 2) # optional - sage.combinat sage.modules - sage: H.centralizer_basis(H) # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: H = lie_algebras.Heisenberg(QQ, 2) + sage: H.centralizer_basis(H) [z] - - sage: D = DescentAlgebra(QQ, 4).D() # optional - sage.combinat sage.modules - sage: L = LieAlgebra(associative=D) # optional - sage.combinat sage.modules - sage: L.centralizer_basis(L) # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.groupssage.modules + sage: D = DescentAlgebra(QQ, 4).D() + sage: L = LieAlgebra(associative=D) + sage: L.centralizer_basis(L) [D{}, D{1} + D{1, 2} + D{2, 3} + D{3}, D{1, 2, 3} + D{1, 3} + D{2}] - sage: D.center_basis() # optional - sage.combinat sage.modules + sage: D.center_basis() (D{}, D{1} + D{1, 2} + D{2, 3} + D{3}, D{1, 2, 3} + D{1, 3} + D{2}) @@ -468,12 +475,13 @@ def centralizer(self, S): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules - sage: a, b, c = L.lie_algebra_generators() # optional - sage.modules - sage: S = L.centralizer([a + b, 2*a + c]); S # optional - sage.modules + sage: # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() + sage: a, b, c = L.lie_algebra_generators() + sage: S = L.centralizer([a + b, 2*a + c]); S An example of a finite dimensional Lie algebra with basis: the 3-dimensional abelian Lie algebra over Rational Field - sage: S.basis_matrix() # optional - sage.modules + sage: S.basis_matrix() [1 0 0] [0 1 0] [0 0 1] @@ -486,11 +494,12 @@ def center(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules - sage: Z = L.center(); Z # optional - sage.modules + sage: # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() + sage: Z = L.center(); Z An example of a finite dimensional Lie algebra with basis: the 3-dimensional abelian Lie algebra over Rational Field - sage: Z.basis_matrix() # optional - sage.modules + sage: Z.basis_matrix() [1 0 0] [0 1 0] [0 0 1] @@ -517,8 +526,9 @@ def derivations_basis(self): We construct the derivations of the Heisenberg Lie algebra:: - sage: H = lie_algebras.Heisenberg(QQ, 1) # optional - sage.combinat sage.modules - sage: H.derivations_basis() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: H = lie_algebras.Heisenberg(QQ, 1) + sage: H.derivations_basis() ( [1 0 0] [0 1 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [1 0 0] [0 1 0] [0 0 0] [0 0 0] @@ -527,8 +537,9 @@ def derivations_basis(self): We construct the derivations of `\mathfrak{sl}_2`:: - sage: sl2 = lie_algebras.sl(QQ, 2) # optional - sage.combinat sage.modules - sage: sl2.derivations_basis() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: sl2 = lie_algebras.sl(QQ, 2) + sage: sl2.derivations_basis() ( [ 1 0 0] [ 0 1 0] [ 0 0 0] [ 0 0 0] [ 0 0 -1/2] [ 1 0 0] @@ -537,9 +548,10 @@ def derivations_basis(self): We verify these are derivations:: - sage: D = [sl2.module_morphism(matrix=M, codomain=sl2) # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: D = [sl2.module_morphism(matrix=M, codomain=sl2) ....: for M in sl2.derivations_basis()] - sage: all(d(a.bracket(b)) == d(a).bracket(b) + a.bracket(d(b)) # optional - sage.combinat sage.modules + sage: all(d(a.bracket(b)) == d(a).bracket(b) + a.bracket(d(b)) ....: for a in sl2.basis() for b in sl2.basis() for d in D) True @@ -581,8 +593,9 @@ def inner_derivations_basis(self): EXAMPLES:: - sage: H = lie_algebras.Heisenberg(QQ, 1) # optional - sage.combinat sage.modules - sage: H.inner_derivations_basis() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: H = lie_algebras.Heisenberg(QQ, 1) + sage: H.inner_derivations_basis() ( [0 0 0] [0 0 0] [0 0 0] [0 0 0] @@ -609,24 +622,26 @@ def subalgebra(self, *gens, **kwds): EXAMPLES:: - sage: H = lie_algebras.Heisenberg(QQ, 2) # optional - sage.combinat sage.modules - sage: p1,p2,q1,q2,z = H.basis() # optional - sage.combinat sage.modules - sage: S = H.subalgebra([p1, q1]) # optional - sage.combinat sage.modules - sage: S.basis().list() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: H = lie_algebras.Heisenberg(QQ, 2) + sage: p1,p2,q1,q2,z = H.basis() + sage: S = H.subalgebra([p1, q1]) + sage: S.basis().list() [p1, q1, z] - sage: S.basis_matrix() # optional - sage.combinat sage.modules + sage: S.basis_matrix() [1 0 0 0 0] [0 0 1 0 0] [0 0 0 0 1] Passing an extra category to a subalgebra:: - sage: L = LieAlgebra(QQ, 3, step=2) # optional - sage.combinat sage.modules - sage: x,y,z = L.homogeneous_component_basis(1) # optional - sage.combinat sage.modules - sage: C = LieAlgebras(QQ).FiniteDimensional().WithBasis() # optional - sage.combinat sage.modules - sage: C = C.Subobjects().Graded().Stratified() # optional - sage.combinat sage.modules - sage: S = L.subalgebra([x, y], category=C) # optional - sage.combinat sage.modules - sage: S.homogeneous_component_basis(2).list() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = LieAlgebra(QQ, 3, step=2) + sage: x,y,z = L.homogeneous_component_basis(1) + sage: C = LieAlgebras(QQ).FiniteDimensional().WithBasis() + sage: C = C.Subobjects().Graded().Stratified() + sage: S = L.subalgebra([x, y], category=C) + sage: S.homogeneous_component_basis(2).list() [X_12] """ from sage.algebras.lie_algebras.subalgebra import LieSubalgebra_finite_dimensional_with_basis @@ -648,21 +663,23 @@ def ideal(self, *gens, **kwds): EXAMPLES:: - sage: H = lie_algebras.Heisenberg(QQ, 2) # optional - sage.combinat sage.modules - sage: p1,p2,q1,q2,z = H.basis() # optional - sage.combinat sage.modules - sage: I = H.ideal([p1-p2, q1-q2]) # optional - sage.combinat sage.modules - sage: I.basis().list() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: H = lie_algebras.Heisenberg(QQ, 2) + sage: p1,p2,q1,q2,z = H.basis() + sage: I = H.ideal([p1 - p2, q1 - q2]) + sage: I.basis().list() [-p1 + p2, -q1 + q2, z] - sage: I.reduce(p1 + p2 + q1 + q2 + z) # optional - sage.combinat sage.modules + sage: I.reduce(p1 + p2 + q1 + q2 + z) 2*p1 + 2*q1 Passing an extra category to an ideal:: - sage: L. = LieAlgebra(QQ, abelian=True) # optional - sage.combinat sage.modules - sage: C = LieAlgebras(QQ).FiniteDimensional().WithBasis() # optional - sage.combinat sage.modules - sage: C = C.Subobjects().Graded().Stratified() # optional - sage.combinat sage.modules - sage: I = L.ideal(x, y, category=C) # optional - sage.combinat sage.modules - sage: I.homogeneous_component_basis(1).list() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L. = LieAlgebra(QQ, abelian=True) + sage: C = LieAlgebras(QQ).FiniteDimensional().WithBasis() + sage: C = C.Subobjects().Graded().Stratified() + sage: I = L.ideal(x, y, category=C) + sage: I.homogeneous_component_basis(1).list() [x, y] """ from sage.algebras.lie_algebras.subalgebra import LieSubalgebra_finite_dimensional_with_basis @@ -679,18 +696,19 @@ def is_ideal(self, A): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules - sage: a, b, c = L.lie_algebra_generators() # optional - sage.combinat sage.modules - sage: I = L.ideal([2*a - c, b + c]) # optional - sage.combinat sage.modules - sage: I.is_ideal(L) # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() + sage: a, b, c = L.lie_algebra_generators() + sage: I = L.ideal([2*a - c, b + c]) + sage: I.is_ideal(L) True - sage: L. = LieAlgebra(QQ, {('x','y'):{'x':1}}) # optional - sage.combinat sage.modules - sage: L.is_ideal(L) # optional - sage.combinat sage.modules + sage: L. = LieAlgebra(QQ, {('x','y'):{'x':1}}) # needs sage.combinat sage.modules + sage: L.is_ideal(L) # needs sage.combinat sage.modules True - sage: F = LieAlgebra(QQ, 'F', representation='polynomial') # optional - sage.combinat sage.modules - sage: L.is_ideal(F) # optional - sage.combinat sage.modules + sage: F = LieAlgebra(QQ, 'F', representation='polynomial') # needs sage.combinat sage.modules + sage: L.is_ideal(F) # needs sage.combinat sage.modules Traceback (most recent call last): ... NotImplementedError: A must be a finite dimensional Lie algebra @@ -731,27 +749,29 @@ def quotient(self, I, names=None, category=None): The Engel Lie algebra as a quotient of the free nilpotent Lie algebra of step 3 with 2 generators:: - sage: L. = LieAlgebra(QQ, 2, step=3) # optional - sage.combinat sage.modules - sage: E = L.quotient(U); E # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L. = LieAlgebra(QQ, 2, step=3) + sage: E = L.quotient(U); E Lie algebra quotient L/I of dimension 4 over Rational Field where L: Free Nilpotent Lie algebra on 5 generators (X, Y, Z, W, U) over Rational Field I: Ideal (U) - sage: E.basis().list() # optional - sage.combinat sage.modules + sage: E.basis().list() [X, Y, Z, W] - sage: E(X).bracket(E(Y)) # optional - sage.combinat sage.modules + sage: E(X).bracket(E(Y)) Z - sage: Y.bracket(Z) # optional - sage.combinat sage.modules + sage: Y.bracket(Z) -U - sage: E(Y).bracket(E(Z)) # optional - sage.combinat sage.modules + sage: E(Y).bracket(E(Z)) 0 - sage: E(U) # optional - sage.combinat sage.modules + sage: E(U) 0 Quotients when the base ring is not a field are not implemented:: - sage: L = lie_algebras.Heisenberg(ZZ, 1) # optional - sage.combinat sage.modules - sage: L.quotient(L.an_element()) # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = lie_algebras.Heisenberg(ZZ, 1) + sage: L.quotient(L.an_element()) Traceback (most recent call last): ... NotImplementedError: quotients over non-fields not implemented @@ -773,43 +793,46 @@ def product_space(self, L, submodule=False): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules - sage: a,b,c = L.lie_algebra_generators() # optional - sage.combinat sage.modules - sage: X = L.subalgebra([a, b+c]) # optional - sage.combinat sage.modules - sage: L.product_space(X) # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() + sage: a,b,c = L.lie_algebra_generators() + sage: X = L.subalgebra([a, b + c]) + sage: L.product_space(X) An example of a finite dimensional Lie algebra with basis: the 0-dimensional abelian Lie algebra over Rational Field with basis matrix: [] - sage: Y = L.subalgebra([a, 2*b-c]) # optional - sage.combinat sage.modules - sage: X.product_space(Y) # optional - sage.combinat sage.modules + sage: Y = L.subalgebra([a, 2*b - c]) + sage: X.product_space(Y) An example of a finite dimensional Lie algebra with basis: the 0-dimensional abelian Lie algebra over Rational Field with basis matrix: [] :: - sage: H = lie_algebras.Heisenberg(ZZ, 4) # optional - sage.combinat sage.modules - sage: Hp = H.product_space(H, submodule=True).basis() # optional - sage.combinat sage.modules - sage: [H.from_vector(v) for v in Hp] # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: H = lie_algebras.Heisenberg(ZZ, 4) + sage: Hp = H.product_space(H, submodule=True).basis() + sage: [H.from_vector(v) for v in Hp] [z] :: - sage: L. = LieAlgebra(QQ, {('x','y'):{'x':1}}) # optional - sage.combinat sage.modules - sage: Lp = L.product_space(L) # todo: not implemented - #17416 # optional - sage.combinat sage.modules - sage: Lp # todo: not implemented - #17416 # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L. = LieAlgebra(QQ, {('x','y'):{'x':1}}) + sage: Lp = L.product_space(L) # not implemented + sage: Lp # not implemented Subalgebra generated of Lie algebra on 2 generators (x, y) over Rational Field with basis: (x,) - sage: Lp.product_space(L) # todo: not implemented - #17416 # optional - sage.combinat sage.modules + sage: Lp.product_space(L) # not implemented Subalgebra generated of Lie algebra on 2 generators (x, y) over Rational Field with basis: (x,) - sage: L.product_space(Lp) # todo: not implemented - #17416 # optional - sage.combinat sage.modules + sage: L.product_space(Lp) # not implemented Subalgebra generated of Lie algebra on 2 generators (x, y) over Rational Field with basis: (x,) - sage: Lp.product_space(Lp) # todo: not implemented - #17416 # optional - sage.combinat sage.modules + sage: Lp.product_space(Lp) # not implemented Subalgebra generated of Lie algebra on 2 generators (x, y) over Rational Field with basis: () @@ -849,8 +872,9 @@ def derived_subalgebra(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules - sage: L.derived_subalgebra() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() + sage: L.derived_subalgebra() An example of a finite dimensional Lie algebra with basis: the 0-dimensional abelian Lie algebra over Rational Field with basis matrix: @@ -858,10 +882,11 @@ def derived_subalgebra(self): If ``self`` is semisimple, then the derived subalgebra is ``self``:: - sage: sl3 = LieAlgebra(QQ, cartan_type=['A', 2]) # optional - sage.combinat sage.modules - sage: sl3.derived_subalgebra() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: sl3 = LieAlgebra(QQ, cartan_type=['A', 2]) + sage: sl3.derived_subalgebra() Lie algebra of ['A', 2] in the Chevalley basis - sage: sl3 is sl3.derived_subalgebra() # optional - sage.combinat sage.modules + sage: sl3 is sl3.derived_subalgebra() True """ @@ -900,8 +925,9 @@ def derived_series(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules - sage: L.derived_series() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() + sage: L.derived_series() (An example of a finite dimensional Lie algebra with basis: the 3-dimensional abelian Lie algebra over Rational Field, An example of a finite dimensional Lie algebra with basis: @@ -910,8 +936,9 @@ def derived_series(self): :: - sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules - sage: L.derived_series() # todo: not implemented - #17416 # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) + sage: L.derived_series() # not implemented (Lie algebra on 2 generators (x, y) over Rational Field, Subalgebra generated of Lie algebra on 2 generators (x, y) over Rational Field @@ -959,8 +986,9 @@ def lower_central_series(self, submodule=False): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules - sage: L.derived_series() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() + sage: L.derived_series() (An example of a finite dimensional Lie algebra with basis: the 3-dimensional abelian Lie algebra over Rational Field, An example of a finite dimensional Lie algebra with basis: @@ -969,16 +997,18 @@ def lower_central_series(self, submodule=False): The lower central series as submodules:: - sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules - sage: L.lower_central_series(submodule=True) # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) + sage: L.lower_central_series(submodule=True) (Sparse vector space of dimension 2 over Rational Field, Vector space of degree 2 and dimension 1 over Rational Field Basis matrix: [1 0]) :: - sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules - sage: L.lower_central_series() # todo: not implemented - #17416 # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) + sage: L.lower_central_series() # not implemented (Lie algebra on 2 generators (x, y) over Rational Field, Subalgebra generated of Lie algebra on 2 generators (x, y) over Rational Field @@ -1001,14 +1031,16 @@ def is_abelian(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules - sage: L.is_abelian() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() + sage: L.is_abelian() True :: - sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules - sage: L.is_abelian() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) + sage: L.is_abelian() False """ return len(self.structure_coefficients()) == 0 @@ -1024,14 +1056,16 @@ def is_solvable(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules - sage: L.is_solvable() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() + sage: L.is_solvable() True :: - sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules - sage: L.is_solvable() # todo: not implemented - #17416 # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) + sage: L.is_solvable() # not implemented False """ return not self.derived_series()[-1].dimension() @@ -1045,8 +1079,9 @@ def is_nilpotent(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules - sage: L.is_nilpotent() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() + sage: L.is_nilpotent() True """ return not self.lower_central_series()[-1].dimension() @@ -1061,8 +1096,9 @@ def is_semisimple(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules - sage: L.is_semisimple() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() + sage: L.is_semisimple() False """ return not self.killing_form_matrix().is_singular() @@ -1107,24 +1143,27 @@ def chevalley_eilenberg_complex(self, M=None, dual=False, sparse=True, ncpus=Non EXAMPLES:: - sage: L = lie_algebras.sl(ZZ, 2) # optional - sage.combinat sage.modules - sage: C = L.chevalley_eilenberg_complex(); C # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = lie_algebras.sl(ZZ, 2) + sage: C = L.chevalley_eilenberg_complex(); C Chain complex with at most 4 nonzero terms over Integer Ring - sage: ascii_art(C) # optional - sage.combinat sage.modules + sage: ascii_art(C) [ 2 0 0] [0] [ 0 -1 0] [0] [0 0 0] [ 0 0 2] [0] 0 <-- C_0 <-------- C_1 <----------- C_2 <---- C_3 <-- 0 - sage: L = LieAlgebra(QQ, cartan_type=['C',2]) # optional - sage.combinat sage.modules - sage: C = L.chevalley_eilenberg_complex() # long time # optional - sage.combinat sage.modules - sage: [C.free_module_rank(i) for i in range(11)] # long time # optional - sage.combinat sage.modules + sage: # long time, needs sage.combinat sage.modules + sage: L = LieAlgebra(QQ, cartan_type=['C',2]) + sage: C = L.chevalley_eilenberg_complex() + sage: [C.free_module_rank(i) for i in range(11)] [1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1] - sage: g = lie_algebras.sl(QQ, 2) # optional - sage.combinat sage.modules - sage: E, F, H = g.basis() # optional - sage.combinat sage.modules - sage: n = g.subalgebra([F, H]) # optional - sage.combinat sage.modules - sage: ascii_art(n.chevalley_eilenberg_complex()) # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: g = lie_algebras.sl(QQ, 2) + sage: E, F, H = g.basis() + sage: n = g.subalgebra([F, H]) + sage: ascii_art(n.chevalley_eilenberg_complex()) [0] [0 0] [2] 0 <-- C_0 <------ C_1 <---- C_2 <-- 0 @@ -1275,15 +1314,17 @@ def homology(self, deg=None, M=None, sparse=True, ncpus=None): EXAMPLES:: - sage: L = lie_algebras.cross_product(QQ) # optional - sage.combinat sage.modules - sage: L.homology() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = lie_algebras.cross_product(QQ) + sage: L.homology() {0: Vector space of dimension 1 over Rational Field, 1: Vector space of dimension 0 over Rational Field, 2: Vector space of dimension 0 over Rational Field, 3: Vector space of dimension 1 over Rational Field} - sage: L = lie_algebras.pwitt(GF(5), 5) # optional - sage.combinat sage.libs.pari sage.modules - sage: L.homology() # optional - sage.combinat sage.libs.pari sage.modules + sage: # needs sage.combinat sage.modules + sage: L = lie_algebras.pwitt(GF(5), 5) + sage: L.homology() {0: Vector space of dimension 1 over Finite Field of size 5, 1: Vector space of dimension 0 over Finite Field of size 5, 2: Vector space of dimension 1 over Finite Field of size 5, @@ -1291,9 +1332,10 @@ def homology(self, deg=None, M=None, sparse=True, ncpus=None): 4: Vector space of dimension 0 over Finite Field of size 5, 5: Vector space of dimension 1 over Finite Field of size 5} - sage: d = {('x', 'y'): {'y': 2}} # optional - sage.combinat sage.modules - sage: L. = LieAlgebra(ZZ, d) # optional - sage.combinat sage.modules - sage: L.homology() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: d = {('x', 'y'): {'y': 2}} + sage: L. = LieAlgebra(ZZ, d) + sage: L.homology() {0: Z, 1: Z x C2, 2: 0} .. SEEALSO:: @@ -1340,8 +1382,9 @@ def cohomology(self, deg=None, M=None, sparse=True, ncpus=None): EXAMPLES:: - sage: L = lie_algebras.so(QQ, 4) # optional - sage.combinat sage.modules - sage: L.cohomology() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = lie_algebras.so(QQ, 4) + sage: L.cohomology() {0: Vector space of dimension 1 over Rational Field, 1: Vector space of dimension 0 over Rational Field, 2: Vector space of dimension 0 over Rational Field, @@ -1350,8 +1393,9 @@ def cohomology(self, deg=None, M=None, sparse=True, ncpus=None): 5: Vector space of dimension 0 over Rational Field, 6: Vector space of dimension 1 over Rational Field} - sage: L = lie_algebras.Heisenberg(QQ, 2) # optional - sage.combinat sage.modules - sage: L.cohomology() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = lie_algebras.Heisenberg(QQ, 2) + sage: L.cohomology() {0: Vector space of dimension 1 over Rational Field, 1: Vector space of dimension 4 over Rational Field, 2: Vector space of dimension 5 over Rational Field, @@ -1359,9 +1403,10 @@ def cohomology(self, deg=None, M=None, sparse=True, ncpus=None): 4: Vector space of dimension 4 over Rational Field, 5: Vector space of dimension 1 over Rational Field} - sage: d = {('x', 'y'): {'y': 2}} # optional - sage.combinat sage.modules - sage: L. = LieAlgebra(ZZ, d) # optional - sage.combinat sage.modules - sage: L.cohomology() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: d = {('x', 'y'): {'y': 2}} + sage: L. = LieAlgebra(ZZ, d) + sage: L.cohomology() {0: Z, 1: Z, 2: C2} .. SEEALSO:: @@ -1382,13 +1427,14 @@ def as_finite_dimensional_algebra(self): EXAMPLES:: - sage: L = lie_algebras.cross_product(QQ) # optional - sage.combinat sage.modules - sage: x, y, z = L.basis() # optional - sage.combinat sage.modules - sage: F = L.as_finite_dimensional_algebra() # optional - sage.combinat sage.modules - sage: X, Y, Z = F.basis() # optional - sage.combinat sage.modules - sage: x.bracket(y) # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = lie_algebras.cross_product(QQ) + sage: x, y, z = L.basis() + sage: F = L.as_finite_dimensional_algebra() + sage: X, Y, Z = F.basis() + sage: x.bracket(y) Z - sage: X * Y # optional - sage.combinat sage.modules + sage: X * Y Z """ from sage.matrix.constructor import matrix @@ -1442,10 +1488,11 @@ def morphism(self, on_generators, codomain=None, base_map=None, check=True): A quotient type Lie algebra morphism :: - sage: L. = LieAlgebra(QQ, {('X','Y'): {'Z': 1}, # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L. = LieAlgebra(QQ, {('X','Y'): {'Z': 1}, ....: ('X','Z'): {'W': 1}}) - sage: K. = LieAlgebra(QQ, abelian=True) # optional - sage.combinat sage.modules - sage: L.morphism({X: A, Y: B}) # optional - sage.combinat sage.modules + sage: K. = LieAlgebra(QQ, abelian=True) + sage: L.morphism({X: A, Y: B}) Lie algebra morphism: From: Lie algebra on 4 generators (X, Y, Z, W) over Rational Field To: Abelian Lie algebra on 2 generators (A, B) over Rational Field @@ -1457,7 +1504,8 @@ def morphism(self, on_generators, codomain=None, base_map=None, check=True): The reverse map `A \mapsto X`, `B \mapsto Y` does not define a Lie algebra morphism, since `[A,B] = 0`, but `[X,Y] \neq 0`:: - sage: K.morphism({A:X, B: Y}) # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: K.morphism({A:X, B: Y}) Traceback (most recent call last): ... ValueError: this does not define a Lie algebra morphism; @@ -1467,16 +1515,17 @@ def morphism(self, on_generators, codomain=None, base_map=None, check=True): on the coefficients, even though it's not a Lie algebra morphism (since it isn't linear):: - sage: R. = ZZ[] # optional - sage.combinat sage.modules - sage: K. = NumberField(x^2 + 1) # optional - sage.combinat sage.modules sage.rings.number_fields - sage: cc = K.hom([-i]) # optional - sage.combinat sage.modules sage.rings.number_fields - sage: L. = LieAlgebra(K, {('X','Y'): {'Z': 1}, # optional - sage.combinat sage.modules sage.rings.number_fields + sage: # needs sage.combinat sage.modules sage.rings.number_fields + sage: R. = ZZ[] + sage: K. = NumberField(x^2 + 1) + sage: cc = K.hom([-i]) + sage: L. = LieAlgebra(K, {('X','Y'): {'Z': 1}, ....: ('X','Z'): {'W': 1}}) - sage: M. = LieAlgebra(K, abelian=True) # optional - sage.combinat sage.modules sage.rings.number_fields - sage: phi = L.morphism({X: A, Y: B}, base_map=cc) # optional - sage.combinat sage.modules sage.rings.number_fields - sage: phi(X) # optional - sage.combinat sage.modules sage.rings.number_fields + sage: M. = LieAlgebra(K, abelian=True) + sage: phi = L.morphism({X: A, Y: B}, base_map=cc) + sage: phi(X) A - sage: phi(i*X) # optional - sage.combinat sage.modules sage.rings.number_fields + sage: phi(i*X) -i*A """ from sage.algebras.lie_algebras.morphism import LieAlgebraMorphism_from_generators @@ -1505,13 +1554,15 @@ def universal_polynomials(self): EXAMPLES:: - sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules - sage: L.universal_polynomials() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) + sage: L.universal_polynomials() Finite family {('x', 'x', 'y'): X01*X10 - X00*X11 + X00, ('y', 'x', 'y'): X10} - sage: L = LieAlgebra(QQ, cartan_type=['A',1]) # optional - sage.combinat sage.modules - sage: list(L.universal_polynomials()) # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = LieAlgebra(QQ, cartan_type=['A',1]) + sage: list(L.universal_polynomials()) [-2*X01*X10 + 2*X00*X11 - 2*X00, -2*X02*X10 + 2*X00*X12 + X01, -2*X02*X11 + 2*X01*X12 - 2*X02, @@ -1522,13 +1573,14 @@ def universal_polynomials(self): -2*X12*X20 + 2*X10*X22 + X21, -2*X12*X21 + 2*X11*X22 - 2*X22] - sage: L = LieAlgebra(QQ, cartan_type=['B', 2]) # optional - sage.combinat sage.modules - sage: al = RootSystem(['B', 2]).root_lattice().simple_roots() # optional - sage.combinat sage.modules - sage: k = list(L.basis().keys())[0] # optional - sage.combinat sage.modules - sage: UP = L.universal_polynomials() # long time # optional - sage.combinat sage.modules - sage: len(UP) # long time # optional - sage.combinat sage.modules + sage: # long time, needs sage.combinat sage.modules + sage: L = LieAlgebra(QQ, cartan_type=['B', 2]) + sage: al = RootSystem(['B', 2]).root_lattice().simple_roots() + sage: k = list(L.basis().keys())[0] + sage: UP = L.universal_polynomials() + sage: len(UP) 450 - sage: UP[al[2], al[1], -al[1]] # long time # optional - sage.combinat sage.modules + sage: UP[al[2], al[1], -al[1]] X0_7*X4_1 - X0_1*X4_7 - 2*X0_7*X5_1 + 2*X0_1*X5_7 + X2_7*X7_1 - X2_1*X7_7 - X3_7*X8_1 + X3_1*X8_7 + X0_4 """ @@ -1582,12 +1634,13 @@ def universal_commutative_algebra(self): EXAMPLES:: - sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules - sage: A = L.universal_commutative_algebra() # optional - sage.combinat sage.modules - sage: a, b, c, d = A.gens() # optional - sage.combinat sage.modules - sage: a, b, c, d # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) + sage: A = L.universal_commutative_algebra() + sage: a, b, c, d = A.gens() + sage: a, b, c, d (X00bar, X01bar, 0, X11bar) - sage: a*d - a # optional - sage.combinat sage.modules + sage: a*d - a 0 """ P = list(self.universal_polynomials()) @@ -1638,6 +1691,7 @@ def casimir_element(self, order=2, UEA=None, force_generic=False): EXAMPLES:: + sage: # needs sage.combinat sage.modules sage: L = LieAlgebra(QQ, cartan_type=['A', 1]) sage: C = L.casimir_element(); C 1/8*b1^2 + 1/2*b0*b2 - 1/4*b1 @@ -1651,18 +1705,21 @@ def casimir_element(self, order=2, UEA=None, force_generic=False): sage: all(g * C == C * g for g in U.algebra_generators()) True + sage: # needs sage.combinat sage.modules sage: L = LieAlgebra(QQ, cartan_type=['B', 2]) sage: U = L.pbw_basis() sage: C = L.casimir_element(UEA=U) sage: all(g * C == C * g for g in U.algebra_generators()) True + sage: # needs sage.combinat sage.modules sage: L = LieAlgebra(QQ, cartan_type=['C', 3]) sage: U = L.pbw_basis() sage: C = L.casimir_element(UEA=U) sage: all(g * C == C * g for g in U.algebra_generators()) True + sage: # needs sage.combinat sage.modules sage: L = LieAlgebra(QQ, cartan_type=['A', 1]) sage: C4 = L.casimir_element(order=4, UEA=L.pbw_basis()); C4 4*PBW[alpha[1]]^2*PBW[-alpha[1]]^2 @@ -1672,12 +1729,14 @@ def casimir_element(self, order=2, UEA=None, force_generic=False): sage: all(g * C4 == C4 * g for g in L.pbw_basis().algebra_generators()) True + sage: # needs sage.combinat sage.modules sage: L = lie_algebras.Heisenberg(QQ, 2) sage: L.casimir_element() 0 TESTS:: + sage: # needs sage.combinat sage.modules sage: L = LieAlgebra(QQ, cartan_type=['A', 1]) sage: L.casimir_element(1) Traceback (most recent call last): @@ -1762,31 +1821,34 @@ def adjoint_matrix(self, sparse=False): # In #11111 (more or less) by using matr EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules - sage: L.an_element().adjoint_matrix() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() + sage: L.an_element().adjoint_matrix() [0 0 0] [0 0 0] [0 0 0] - sage: L.an_element().adjoint_matrix(sparse=True).is_sparse() # optional - sage.combinat sage.modules + sage: L.an_element().adjoint_matrix(sparse=True).is_sparse() True :: - sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules - sage: x.adjoint_matrix() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) + sage: x.adjoint_matrix() [0 1] [0 0] - sage: y.adjoint_matrix() # optional - sage.combinat sage.modules + sage: y.adjoint_matrix() [-1 0] [ 0 0] We verify that this forms a representation:: - sage: sl3 = lie_algebras.sl(QQ, 3) # optional - sage.combinat sage.modules - sage: e1, e2 = sl3.e(1), sl3.e(2) # optional - sage.combinat sage.modules - sage: e12 = e1.bracket(e2) # optional - sage.combinat sage.modules - sage: E1, E2 = e1.adjoint_matrix(), e2.adjoint_matrix() # optional - sage.combinat sage.modules - sage: E1 * E2 - E2 * E1 == e12.adjoint_matrix() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: sl3 = lie_algebras.sl(QQ, 3) + sage: e1, e2 = sl3.e(1), sl3.e(2) + sage: e12 = e1.bracket(e2) + sage: E1, E2 = e1.adjoint_matrix(), e2.adjoint_matrix() + sage: E1 * E2 - E2 * E1 == e12.adjoint_matrix() True """ from sage.matrix.constructor import matrix @@ -1809,16 +1871,17 @@ def to_vector(self, order=None, sparse=False): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules - sage: L.an_element().to_vector() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() + sage: L.an_element().to_vector() (0, 0, 0) - - sage: L.an_element().to_vector(sparse=True) # optional - sage.combinat sage.modules + sage: L.an_element().to_vector(sparse=True) (0, 0, 0) - sage: D = DescentAlgebra(QQ, 4).D() # optional - sage.combinat sage.modules - sage: L = LieAlgebra(associative=D) # optional - sage.combinat sage.modules - sage: L.an_element().to_vector() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.groupssage.modules + sage: D = DescentAlgebra(QQ, 4).D() + sage: L = LieAlgebra(associative=D) + sage: L.an_element().to_vector() (1, 1, 1, 1, 1, 1, 1, 1) TESTS: @@ -1826,13 +1889,14 @@ def to_vector(self, order=None, sparse=False): Check that the error raised agrees with the one from ``monomial_coefficients()`` (see :trac:`25007`):: - sage: L = lie_algebras.sp(QQ, 4, representation='matrix') # optional - sage.combinat sage.modules - sage: x = L.an_element() # optional - sage.combinat sage.modules - sage: x.monomial_coefficients() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = lie_algebras.sp(QQ, 4, representation='matrix') + sage: x = L.an_element() + sage: x.monomial_coefficients() Traceback (most recent call last): ... NotImplementedError: the basis is not defined - sage: x.to_vector() # optional - sage.combinat sage.modules + sage: x.to_vector() Traceback (most recent call last): ... NotImplementedError: the basis is not defined @@ -1866,11 +1930,12 @@ def ambient(self): EXAMPLES:: + sage: # needs sage.combinat sage.modules sage: C = LieAlgebras(QQ).FiniteDimensional().WithBasis() - sage: L = C.example() # optional - sage.combinat sage.modules - sage: a, b, c = L.lie_algebra_generators() # optional - sage.combinat sage.modules - sage: S = L.subalgebra([2*a + b, b + c]) # optional - sage.combinat sage.modules - sage: S.ambient() == L # optional - sage.combinat sage.modules + sage: L = C.example() + sage: a, b, c = L.lie_algebra_generators() + sage: S = L.subalgebra([2*a + b, b + c]) + sage: S.ambient() == L True """ @@ -1881,11 +1946,12 @@ def basis_matrix(self): EXAMPLES:: + sage: # needs sage.combinat sage.modules sage: C = LieAlgebras(QQ).FiniteDimensional().WithBasis() - sage: L = C.example() # optional - sage.combinat sage.modules - sage: a, b, c = L.lie_algebra_generators() # optional - sage.combinat sage.modules - sage: S = L.subalgebra([2*a + b, b + c]) # optional - sage.combinat sage.modules - sage: S.basis_matrix() # optional - sage.combinat sage.modules + sage: L = C.example() + sage: a, b, c = L.lie_algebra_generators() + sage: S = L.subalgebra([2*a + b, b + c]) + sage: S.basis_matrix() [ 1 0 -1/2] [ 0 1 1] """ diff --git a/src/sage/categories/finite_dimensional_modules_with_basis.py b/src/sage/categories/finite_dimensional_modules_with_basis.py index 573aec237a1..1462073c5f2 100644 --- a/src/sage/categories/finite_dimensional_modules_with_basis.py +++ b/src/sage/categories/finite_dimensional_modules_with_basis.py @@ -46,8 +46,8 @@ def gens(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(ZZ, ['a', 'b', 'c']) # optional - sage.modules - sage: F.gens() # optional - sage.modules + sage: F = CombinatorialFreeModule(ZZ, ['a', 'b', 'c']) # needs sage.modules + sage: F.gens() # needs sage.modules (B['a'], B['b'], B['c']) """ return tuple(self.basis()) @@ -91,35 +91,38 @@ def annihilator(self, S, action=operator.mul, side='right', category=None): EXAMPLES:: - sage: F = FiniteDimensionalAlgebrasWithBasis(QQ).example(); F # optional - sage.modules + sage: # needs sage.modules + sage: F = FiniteDimensionalAlgebrasWithBasis(QQ).example(); F An example of a finite dimensional algebra with basis: the path algebra of the Kronecker quiver (containing the arrows a:x->y and b:x->y) over Rational Field - sage: x, y, a, b = F.basis() # optional - sage.modules - sage: A = F.annihilator([a + 3*b + 2*y]); A # optional - sage.modules + sage: x, y, a, b = F.basis() + sage: A = F.annihilator([a + 3*b + 2*y]); A Free module generated by {0} over Rational Field - sage: [b.lift() for b in A.basis()] # optional - sage.modules + sage: [b.lift() for b in A.basis()] [-1/2*a - 3/2*b + x] The category can be used to specify other properties of this subspace, like that this is a subalgebra:: - sage: center = F.annihilator(F.basis(), F.bracket, # optional - sage.modules + sage: # needs sage.modules + sage: center = F.annihilator(F.basis(), F.bracket, ....: category=Algebras(QQ).Subobjects()) - sage: (e,) = center.basis() # optional - sage.modules - sage: e.lift() # optional - sage.modules + sage: (e,) = center.basis() + sage: e.lift() x + y - sage: e * e == e # optional - sage.modules + sage: e * e == e True Taking annihilator is order reversing for inclusion:: - sage: A = F.annihilator([]); A .rename("A") # optional - sage.modules - sage: Ax = F.annihilator([x]); Ax .rename("Ax") # optional - sage.modules - sage: Ay = F.annihilator([y]); Ay .rename("Ay") # optional - sage.modules - sage: Axy = F.annihilator([x,y]); Axy.rename("Axy") # optional - sage.modules - sage: P = Poset(([A, Ax, Ay, Axy], attrcall("is_submodule"))) # optional - sage.combinat sage.graphs sage.modules - sage: sorted(P.cover_relations(), key=str) # optional - sage.combinat sage.graphs sage.modules + sage: # needs sage.modules + sage: A = F.annihilator([]); A .rename("A") + sage: Ax = F.annihilator([x]); Ax .rename("Ax") + sage: Ay = F.annihilator([y]); Ay .rename("Ay") + sage: Axy = F.annihilator([x,y]); Axy.rename("Axy") + sage: P = Poset(([A, Ax, Ay, Axy], attrcall("is_submodule"))) # needs sage.combinat sage.graphs + sage: sorted(P.cover_relations(), key=str) # needs sage.combinat sage.graphs [[Ax, A], [Axy, Ax], [Axy, Ay], [Ay, A]] """ return self.submodule(self.annihilator_basis(S, action, side), @@ -147,6 +150,7 @@ def annihilator_basis(self, S, action=operator.mul, side='right'): By default, the action is the standard `*` operation. So our first example is about an algebra:: + sage: # needs sage.graphs sage.modules sage: F = FiniteDimensionalAlgebrasWithBasis(QQ).example(); F An example of a finite dimensional algebra with basis: the path algebra of the Kronecker quiver @@ -156,39 +160,40 @@ def annihilator_basis(self, S, action=operator.mul, side='right'): In this algebra, multiplication on the right by `x` annihilates all basis elements but `x`:: - sage: x*x, y*x, a*x, b*x + sage: x*x, y*x, a*x, b*x # needs sage.graphs sage.modules (x, 0, 0, 0) So the annihilator is the subspace spanned by `y`, `a`, and `b`:: - sage: F.annihilator_basis([x]) + sage: F.annihilator_basis([x]) # needs sage.graphs sage.modules (y, a, b) The same holds for `a` and `b`:: - sage: x*a, y*a, a*a, b*a + sage: x*a, y*a, a*a, b*a # needs sage.graphs sage.modules (a, 0, 0, 0) - sage: F.annihilator_basis([a]) + sage: F.annihilator_basis([a]) # needs sage.graphs sage.modules (y, a, b) On the other hand, `y` annihilates only `x`:: - sage: F.annihilator_basis([y]) + sage: F.annihilator_basis([y]) # needs sage.graphs sage.modules (x,) Here is a non trivial annihilator:: - sage: F.annihilator_basis([a + 3*b + 2*y]) + sage: F.annihilator_basis([a + 3*b + 2*y]) # needs sage.graphs sage.modules (-1/2*a - 3/2*b + x,) Let's check it:: - sage: (-1/2*a - 3/2*b + x) * (a + 3*b + 2*y) + sage: (-1/2*a - 3/2*b + x) * (a + 3*b + 2*y) # needs sage.graphs sage.modules 0 Doing the same calculations on the left exchanges the roles of `x` and `y`:: + sage: # needs sage.graphs sage.modules sage: F.annihilator_basis([y], side="left") (x, a, b) sage: F.annihilator_basis([a], side="left") @@ -197,28 +202,29 @@ def annihilator_basis(self, S, action=operator.mul, side='right'): (x, a, b) sage: F.annihilator_basis([x], side="left") (y,) - sage: F.annihilator_basis([a+3*b+2*x], side="left") + sage: F.annihilator_basis([a + 3*b + 2*x], side="left") (-1/2*a - 3/2*b + y,) By specifying an inner product, this method can be used to compute the orthogonal of a subspace:: + sage: # needs sage.graphs sage.modules sage: x,y,a,b = F.basis() sage: def scalar(u,v): ....: return vector([sum(u[i]*v[i] for i in F.basis().keys())]) - sage: F.annihilator_basis([x+y, a+b], scalar) + sage: F.annihilator_basis([x + y, a + b], scalar) (x - y, a - b) By specifying the standard Lie bracket as action, one can compute the commutator of a subspace of `F`:: - sage: F.annihilator_basis([a+b], action=F.bracket) + sage: F.annihilator_basis([a + b], action=F.bracket) # needs sage.graphs sage.modules (x + y, a, b) In particular one can compute a basis of the center of the algebra. In our example, it is reduced to the identity:: - sage: F.annihilator_basis(F.algebra_generators(), action=F.bracket) + sage: F.annihilator_basis(F.algebra_generators(), action=F.bracket) # needs sage.graphs sage.modules (x + y,) But see also @@ -252,13 +258,13 @@ def _dense_free_module(self, base_ring=None): EXAMPLES:: - sage: C = CombinatorialFreeModule(QQ['x'], ['a','b','c']); C # optional - sage.modules + sage: C = CombinatorialFreeModule(QQ['x'], ['a','b','c']); C # needs sage.modules Free module generated by {'a', 'b', 'c'} over Univariate Polynomial Ring in x over Rational Field - sage: C._dense_free_module() # optional - sage.modules + sage: C._dense_free_module() # needs sage.modules Ambient free module of rank 3 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field - sage: C._dense_free_module(QQ['x,y']) # optional - sage.modules + sage: C._dense_free_module(QQ['x,y']) # needs sage.modules Ambient free module of rank 3 over the integral domain Multivariate Polynomial Ring in x, y over Rational Field """ @@ -273,11 +279,12 @@ def from_vector(self, vector, order=None, coerce=True): EXAMPLES:: - sage: p_mult = matrix([[0,0,0], [0,0,-1], [0,0,0]]) # optional - sage.modules - sage: q_mult = matrix([[0,0,1], [0,0,0], [0,0,0]]) # optional - sage.modules - sage: A = algebras.FiniteDimensional( # optional - sage.combinat sage.modules + sage: # needs sage.modules + sage: p_mult = matrix([[0,0,0], [0,0,-1], [0,0,0]]) + sage: q_mult = matrix([[0,0,1], [0,0,0], [0,0,0]]) + sage: A = algebras.FiniteDimensional( ....: QQ, [p_mult, q_mult, matrix(QQ, 3, 3)], 'p,q,z') - sage: A.from_vector(vector([1,0,2])) # optional - sage.combinat sage.modules + sage: A.from_vector(vector([1,0,2])) p + 2*z """ if order is None: @@ -313,42 +320,44 @@ def echelon_form(self, elements, row_reduced=False, order=None): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x") # optional - sage.modules - sage: x = X.basis() # optional - sage.modules - sage: V = X.echelon_form([x[0]-x[1], x[0]-x[2], x[1]-x[2]]); V # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x") + sage: x = X.basis() + sage: V = X.echelon_form([x[0]-x[1], x[0]-x[2], x[1]-x[2]]); V [x[0] - x[2], x[1] - x[2]] - sage: matrix(list(map(vector, V))) # optional - sage.modules + sage: matrix(list(map(vector, V))) [ 1 0 -1] [ 0 1 -1] :: - sage: F = CombinatorialFreeModule(ZZ, [1,2,3,4]) # optional - sage.modules - sage: B = F.basis() # optional - sage.modules - sage: elements = [B[1]-17*B[2]+6*B[3], B[1]-17*B[2]+B[4]] # optional - sage.modules - sage: F.echelon_form(elements) # optional - sage.modules + sage: # needs sage.modules + sage: F = CombinatorialFreeModule(ZZ, [1,2,3,4]) + sage: B = F.basis() + sage: elements = [B[1]-17*B[2]+6*B[3], B[1]-17*B[2]+B[4]] + sage: F.echelon_form(elements) [B[1] - 17*B[2] + B[4], 6*B[3] - B[4]] :: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) # optional - sage.modules - sage: a,b,c = F.basis() # optional - sage.modules - sage: F.echelon_form([8*a+b+10*c, -3*a+b-c, a-b-c]) # optional - sage.modules + sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) # needs sage.modules + sage: a,b,c = F.basis() # needs sage.modules + sage: F.echelon_form([8*a+b+10*c, -3*a+b-c, a-b-c]) # needs sage.modules [B['a'] + B['c'], B['b'] + 2*B['c']] :: sage: R. = QQ[] - sage: C = CombinatorialFreeModule(R, range(3), prefix='x') # optional - sage.modules - sage: x = C.basis() # optional - sage.modules - sage: C.echelon_form([x[0] - x[1], 2*x[1] - 2*x[2], x[0] - x[2]]) # optional - sage.modules + sage: C = CombinatorialFreeModule(R, range(3), prefix='x') # needs sage.modules + sage: x = C.basis() # needs sage.modules + sage: C.echelon_form([x[0] - x[1], 2*x[1] - 2*x[2], x[0] - x[2]]) # needs sage.modules sage.rings.function_field [x[0] - x[2], x[1] - x[2]] :: - sage: M = MatrixSpace(QQ, 3, 3) # optional - sage.modules - sage: A = M([[0, 0, 2], [0, 0, 0], [0, 0, 0]]) # optional - sage.modules - sage: M.echelon_form([A, A]) # optional - sage.modules + sage: M = MatrixSpace(QQ, 3, 3) # needs sage.modules + sage: A = M([[0, 0, 2], [0, 0, 0], [0, 0, 0]]) # needs sage.modules + sage: M.echelon_form([A, A]) # needs sage.modules [ [0 0 1] [0 0 0] @@ -359,8 +368,8 @@ def echelon_form(self, elements, row_reduced=False, order=None): We convert the input elements to ``self``:: - sage: E. = ExteriorAlgebra(QQ) # optional - sage.modules sage.combinat - sage: E.echelon_form([1, x + 2]) # optional - sage.modules sage.combinat + sage: E. = ExteriorAlgebra(QQ) # needs sage.modules + sage: E.echelon_form([1, x + 2]) # needs sage.modules [1, x] """ # Make sure elements consists of elements of ``self`` @@ -411,36 +420,39 @@ def invariant_module(self, S, action=operator.mul, action_on_basis=None, We build the invariant module of the permutation representation of the symmetric group:: - sage: G = SymmetricGroup(3); G.rename('S3') # optional - sage.groups sage.modules - sage: M = FreeModule(ZZ, [1,2,3], prefix='M'); M.rename('M') # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: G = SymmetricGroup(3); G.rename('S3') + sage: M = FreeModule(ZZ, [1,2,3], prefix='M'); M.rename('M') sage: action = lambda g, x: M.term(g(x)) - sage: I = M.invariant_module(G, action_on_basis=action); I # optional - sage.groups sage.modules + sage: I = M.invariant_module(G, action_on_basis=action); I (S3)-invariant submodule of M - sage: I.basis() # optional - sage.groups sage.modules + sage: I.basis() Finite family {0: B[0]} - sage: [I.lift(b) for b in I.basis()] # optional - sage.groups sage.modules + sage: [I.lift(b) for b in I.basis()] [M[1] + M[2] + M[3]] - - sage: G.rename(); M.rename() # reset the names # optional - sage.groups sage.modules + sage: G.rename(); M.rename() # reset the names We can construct the invariant module of any module that has an action of ``S``. In this example, we consider the dihedral group `G = D_4` and the subgroup `H < G` of all rotations. We construct the `H`-invariant module of the group algebra `\QQ[G]`:: - sage: G = groups.permutation.Dihedral(4) # optional - sage.groups - sage: H = G.subgroup(G.gen(0)) # optional - sage.groups - sage: H # optional - sage.groups + sage: # needs sage.groups + sage: G = groups.permutation.Dihedral(4) + sage: H = G.subgroup(G.gen(0)) + sage: H Subgroup generated by [(1,2,3,4)] of (Dihedral group of order 8 as a permutation group) - sage: H.cardinality() # optional - sage.groups + sage: H.cardinality() 4 - sage: A = G.algebra(QQ) # optional - sage.groups sage.modules - sage: I = A.invariant_module(H) # optional - sage.groups sage.modules - sage: [I.lift(b) for b in I.basis()] # optional - sage.groups sage.modules + + sage: # needs sage.groups sage.modules + sage: A = G.algebra(QQ) + sage: I = A.invariant_module(H) + sage: [I.lift(b) for b in I.basis()] [() + (1,2,3,4) + (1,3)(2,4) + (1,4,3,2), (2,4) + (1,2)(3,4) + (1,3) + (1,4)(2,3)] - sage: all(h * I.lift(b) == I.lift(b) # optional - sage.groups sage.modules + sage: all(h * I.lift(b) == I.lift(b) ....: for b in I.basis() for h in H) True """ @@ -483,13 +495,14 @@ def twisted_invariant_module(self, G, chi, EXAMPLES:: - sage: M = CombinatorialFreeModule(QQ, [1,2,3]) # optional - sage.groups sage.modules - sage: G = SymmetricGroup(3) # optional - sage.groups + sage: # needs sage.groups sage.modules + sage: M = CombinatorialFreeModule(QQ, [1,2,3]) + sage: G = SymmetricGroup(3) sage: def action(g,x): return(M.term(g(x))) # permute coordinates - sage: T = M.twisted_invariant_module(G, [2,0,-1], # optional - sage.groups sage.modules + sage: T = M.twisted_invariant_module(G, [2,0,-1], ....: action_on_basis=action) sage: import __main__; __main__.action = action - sage: TestSuite(T).run() # optional - sage.groups sage.modules + sage: TestSuite(T).run() """ if action_on_basis is not None: @@ -518,12 +531,13 @@ def dense_coefficient_list(self, order=None): EXAMPLES:: - sage: v = vector([0, -1, -3]) # optional - sage.modules - sage: v.dense_coefficient_list() # optional - sage.modules + sage: # needs sage.modules + sage: v = vector([0, -1, -3]) + sage: v.dense_coefficient_list() [0, -1, -3] - sage: v.dense_coefficient_list([2,1,0]) # optional - sage.modules + sage: v.dense_coefficient_list([2,1,0]) [-3, -1, 0] - sage: sorted(v.coefficients()) # optional - sage.modules + sage: sorted(v.coefficients()) [-3, -1] """ if order is None: @@ -539,11 +553,12 @@ def _vector_(self, order=None): EXAMPLES:: - sage: v = vector([0, -1, -3]) # optional - sage.modules - sage: v._vector_() # optional - sage.modules + sage: # needs sage.modules + sage: v = vector([0, -1, -3]) + sage: v._vector_() (0, -1, -3) - sage: C = CombinatorialFreeModule(QQ['x'], ['a','b','c']) # optional - sage.modules - sage: C.an_element()._vector_() # optional - sage.modules + sage: C = CombinatorialFreeModule(QQ['x'], ['a','b','c']) + sage: C.an_element()._vector_() (2, 2, 3) """ if order is None: @@ -581,31 +596,32 @@ def matrix(self, base_ring=None, side="left"): EXAMPLES:: - sage: X = CombinatorialFreeModule(ZZ, [1,2]); x = X.basis() # optional - sage.modules - sage: Y = CombinatorialFreeModule(ZZ, [3,4]); y = Y.basis() # optional - sage.modules - sage: phi = X.module_morphism(on_basis={1: y[3] + 3*y[4], # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(ZZ, [1,2]); x = X.basis() + sage: Y = CombinatorialFreeModule(ZZ, [3,4]); y = Y.basis() + sage: phi = X.module_morphism(on_basis={1: y[3] + 3*y[4], ....: 2: 2*y[3] + 5*y[4]}.__getitem__, ....: codomain=Y) - sage: phi.matrix() # optional - sage.modules + sage: phi.matrix() [1 2] [3 5] - sage: phi.matrix(side="right") # optional - sage.modules + sage: phi.matrix(side="right") [1 3] [2 5] - sage: phi.matrix().parent() # optional - sage.modules + sage: phi.matrix().parent() # needs sage.modules Full MatrixSpace of 2 by 2 dense matrices over Integer Ring - sage: phi.matrix(QQ).parent() # optional - sage.modules + sage: phi.matrix(QQ).parent() # needs sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field The resulting matrix is immutable:: - sage: phi.matrix().is_mutable() # optional - sage.modules + sage: phi.matrix().is_mutable() # needs sage.modules False The zero morphism has a zero matrix:: - sage: Hom(X, Y).zero().matrix() # optional - sage.modules + sage: Hom(X, Y).zero().matrix() # needs sage.modules [0 0] [0 0] @@ -614,11 +630,11 @@ def matrix(self, base_ring=None, side="left"): Add support for morphisms where the codomain has a different base ring than the domain:: - sage: Y = CombinatorialFreeModule(QQ, [3,4]); y = Y.basis() # optional - sage.modules - sage: phi = X.module_morphism(on_basis={1: y[3] + 3*y[4], # optional - sage.modules + sage: Y = CombinatorialFreeModule(QQ, [3,4]); y = Y.basis() # needs sage.modules + sage: phi = X.module_morphism(on_basis={1: y[3] + 3*y[4], # needs sage.modules ....: 2: 2*y[3] + 5/2*y[4]}.__getitem__, ....: codomain=Y) - sage: phi.matrix().parent() # todo: not implemented # optional - sage.modules + sage: phi.matrix().parent() # not implemented # needs sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field This currently does not work because, in this case, @@ -626,20 +642,21 @@ def matrix(self, base_ring=None, side="left"): additive groups (i.e. the intersection of the categories of modules over `\ZZ` and over `\QQ`):: - sage: phi.parent().homset_category() # optional - sage.modules + sage: phi.parent().homset_category() # needs sage.modules Category of commutative additive semigroups - sage: phi.parent().homset_category() # todo: not implemented # optional - sage.modules + sage: phi.parent().homset_category() # not implemented, needs sage.modules Category of finite dimensional modules with basis over Integer Ring TESTS: Check that :trac:`23216` is fixed:: - sage: X = CombinatorialFreeModule(QQ, []) # optional - sage.modules - sage: Y = CombinatorialFreeModule(QQ, [1,2,3]) # optional - sage.modules - sage: Hom(X, Y).zero().matrix() # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(QQ, []) + sage: Y = CombinatorialFreeModule(QQ, [1,2,3]) + sage: Hom(X, Y).zero().matrix() [] - sage: Hom(X, Y).zero().matrix().parent() # optional - sage.modules + sage: Hom(X, Y).zero().matrix().parent() Full MatrixSpace of 3 by 0 dense matrices over Rational Field """ if base_ring is None: @@ -668,42 +685,43 @@ def __invert__(self): EXAMPLES:: + sage: # needs sage.modules sage: category = FiniteDimensionalModulesWithBasis(ZZ) - sage: X = CombinatorialFreeModule(ZZ, [1,2], category=category); X.rename("X"); x = X.basis() # optional - sage.modules - sage: Y = CombinatorialFreeModule(ZZ, [3,4], category=category); Y.rename("Y"); y = Y.basis() # optional - sage.modules - sage: phi = X.module_morphism(on_basis={1: y[3] + 3*y[4], 2: 2*y[3] + 5*y[4]}.__getitem__, # optional - sage.modules + sage: X = CombinatorialFreeModule(ZZ, [1,2], category=category); X.rename("X"); x = X.basis() + sage: Y = CombinatorialFreeModule(ZZ, [3,4], category=category); Y.rename("Y"); y = Y.basis() + sage: phi = X.module_morphism(on_basis={1: y[3] + 3*y[4], 2: 2*y[3] + 5*y[4]}.__getitem__, ....: codomain=Y, category=category) - sage: psi = ~phi # optional - sage.modules - sage: psi # optional - sage.modules + sage: psi = ~phi + sage: psi Generic morphism: From: Y To: X - sage: psi.parent() # optional - sage.modules + sage: psi.parent() Set of Morphisms from Y to X in Category of finite dimensional modules with basis over Integer Ring - sage: psi(y[3]) # optional - sage.modules + sage: psi(y[3]) -5*B[1] + 3*B[2] - sage: psi(y[4]) # optional - sage.modules + sage: psi(y[4]) 2*B[1] - B[2] - sage: psi.matrix() # optional - sage.modules + sage: psi.matrix() [-5 2] [ 3 -1] - sage: psi(phi(x[1])), psi(phi(x[2])) # optional - sage.modules + sage: psi(phi(x[1])), psi(phi(x[2])) (B[1], B[2]) - sage: phi(psi(y[3])), phi(psi(y[4])) # optional - sage.modules + sage: phi(psi(y[3])), phi(psi(y[4])) (B[3], B[4]) We check that this function complains if the morphism is not invertible:: - sage: phi = X.module_morphism(on_basis={1: y[3] + y[4], 2: y[3] + y[4]}.__getitem__, # optional - sage.modules + sage: phi = X.module_morphism(on_basis={1: y[3] + y[4], 2: y[3] + y[4]}.__getitem__, # needs sage.modules ....: codomain=Y, category=category) - sage: ~phi # optional - sage.modules + sage: ~phi # needs sage.modules Traceback (most recent call last): ... RuntimeError: morphism is not invertible - sage: phi = X.module_morphism(on_basis={1: y[3] + y[4], 2: y[3] + 5*y[4]}.__getitem__, # optional - sage.modules + sage: phi = X.module_morphism(on_basis={1: y[3] + y[4], 2: y[3] + 5*y[4]}.__getitem__, # needs sage.modules ....: codomain=Y, category=category) - sage: ~phi # optional - sage.modules + sage: ~phi # needs sage.modules Traceback (most recent call last): ... RuntimeError: morphism is not invertible @@ -723,9 +741,9 @@ def kernel_basis(self): EXAMPLES:: - sage: SGA = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules - sage: f = SGA.module_morphism(lambda x: SGA(x**2), codomain=SGA) # optional - sage.groups sage.modules - sage: f.kernel_basis() # optional - sage.groups sage.modules + sage: SGA = SymmetricGroupAlgebra(QQ, 3) # needs sage.groups sage.modules + sage: f = SGA.module_morphism(lambda x: SGA(x**2), codomain=SGA) # needs sage.groups sage.modules + sage: f.kernel_basis() # needs sage.groups sage.modules ([1, 2, 3] - [3, 2, 1], [1, 3, 2] - [3, 2, 1], [2, 1, 3] - [3, 2, 1]) """ return tuple(map( self.domain().from_vector, @@ -737,12 +755,13 @@ def kernel(self): EXAMPLES:: - sage: SGA = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules - sage: f = SGA.module_morphism(lambda x: SGA(x**2), codomain=SGA) # optional - sage.groups sage.modules - sage: K = f.kernel() # optional - sage.groups sage.modules - sage: K # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: SGA = SymmetricGroupAlgebra(QQ, 3) + sage: f = SGA.module_morphism(lambda x: SGA(x**2), codomain=SGA) + sage: K = f.kernel() + sage: K Free module generated by {0, 1, 2} over Rational Field - sage: K.ambient() # optional - sage.groups sage.modules + sage: K.ambient() Symmetric group algebra of order 3 over Rational Field """ D = self.domain() @@ -755,9 +774,9 @@ def image_basis(self): EXAMPLES:: - sage: SGA = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules - sage: f = SGA.module_morphism(lambda x: SGA(x**2), codomain=SGA) # optional - sage.groups sage.modules - sage: f.image_basis() # optional - sage.groups sage.modules + sage: SGA = SymmetricGroupAlgebra(QQ, 3) # needs sage.groups sage.modules + sage: f = SGA.module_morphism(lambda x: SGA(x**2), codomain=SGA) # needs sage.groups sage.modules + sage: f.image_basis() # needs sage.groups sage.modules ([1, 2, 3], [2, 3, 1], [3, 1, 2]) """ C = self.codomain() @@ -769,9 +788,9 @@ def image(self): EXAMPLES:: - sage: SGA = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules - sage: f = SGA.module_morphism(lambda x: SGA(x**2), codomain=SGA) # optional - sage.groups sage.modules - sage: f.image() # optional - sage.groups sage.modules + sage: SGA = SymmetricGroupAlgebra(QQ, 3) # needs sage.groups sage.modules + sage: f = SGA.module_morphism(lambda x: SGA(x**2), codomain=SGA) # needs sage.groups sage.modules + sage: f.image() # needs sage.groups sage.modules Free module generated by {0, 1, 2} over Rational Field """ C = self.codomain() diff --git a/src/sage/categories/finite_dimensional_nilpotent_lie_algebras_with_basis.py b/src/sage/categories/finite_dimensional_nilpotent_lie_algebras_with_basis.py index d294ec75fae..78d801a5ef4 100644 --- a/src/sage/categories/finite_dimensional_nilpotent_lie_algebras_with_basis.py +++ b/src/sage/categories/finite_dimensional_nilpotent_lie_algebras_with_basis.py @@ -60,17 +60,18 @@ def _test_nilpotency(self, **options): EXAMPLES:: - sage: L = LieAlgebra(QQ, {('X','Y'): {'Z': 1}}, nilpotent=True) # optional - sage.combinat sage.modules - sage: L._test_nilpotency() # optional - sage.combinat sage.modules - sage: L = LieAlgebra(QQ, {('X','Y'): {'Z': 1}}, # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = LieAlgebra(QQ, {('X','Y'): {'Z': 1}}, nilpotent=True) + sage: L._test_nilpotency() + sage: L = LieAlgebra(QQ, {('X','Y'): {'Z': 1}}, ....: nilpotent=True, step=3) - sage: L._test_nilpotency() # optional - sage.combinat sage.modules + sage: L._test_nilpotency() Traceback (most recent call last): ... AssertionError: claimed nilpotency step 3 does not match the actual nilpotency step 2 - sage: L = LieAlgebra(QQ, {('X','Y'): {'X': 1}}, nilpotent=True) # optional - sage.combinat sage.modules - sage: L._test_nilpotency() # optional - sage.combinat sage.modules + sage: L = LieAlgebra(QQ, {('X','Y'): {'X': 1}}, nilpotent=True) + sage: L._test_nilpotency() Traceback (most recent call last): ... AssertionError: final term of lower central series is non-zero @@ -101,29 +102,30 @@ def lie_group(self, name='G', **kwds): We define the Heisenberg group:: - sage: L = lie_algebras.Heisenberg(QQ, 1) # optional - sage.combinat sage.modules - sage: G = L.lie_group('G'); G # optional - sage.combinat sage.modules sage.symbolic + sage: L = lie_algebras.Heisenberg(QQ, 1) # needs sage.combinat sage.modules + sage: G = L.lie_group('G'); G # needs sage.combinat sage.modules sage.symbolic Lie group G of Heisenberg algebra of rank 1 over Rational Field We test multiplying elements of the group:: - sage: p, q, z = L.basis() # optional - sage.combinat sage.modules sage.symbolic - sage: g = G.exp(p); g # optional - sage.combinat sage.modules sage.symbolic + sage: # needs sage.combinat sage.modules sage.symbolic + sage: p, q, z = L.basis() + sage: g = G.exp(p); g exp(p1) - sage: h = G.exp(q); h # optional - sage.combinat sage.modules sage.symbolic + sage: h = G.exp(q); h exp(q1) - sage: g * h # optional - sage.combinat sage.modules sage.symbolic + sage: g * h exp(p1 + q1 + 1/2*z) We extend an element of the Lie algebra to a left-invariant vector field:: - sage: X = G.left_invariant_extension(2*p + 3*q, name='X'); X # optional - sage.combinat sage.modules sage.symbolic + sage: X = G.left_invariant_extension(2*p + 3*q, name='X'); X # needs sage.combinat sage.modules sage.symbolic Vector field X on the Lie group G of Heisenberg algebra of rank 1 over Rational Field - sage: X.at(G.one()).display() # optional - sage.combinat sage.modules sage.symbolic + sage: X.at(G.one()).display() # needs sage.combinat sage.modules sage.symbolic X = 2 ∂/∂x_0 + 3 ∂/∂x_1 - sage: X.display() # optional - sage.combinat sage.modules sage.symbolic + sage: X.display() # needs sage.combinat sage.modules sage.symbolic X = 2 ∂/∂x_0 + 3 ∂/∂x_1 + (3/2*x_0 - x_1) ∂/∂x_2 .. SEEALSO:: @@ -139,11 +141,12 @@ def step(self): EXAMPLES:: - sage: L = LieAlgebra(QQ, {('X','Y'): {'Z': 1}}, nilpotent=True) # optional - sage.combinat sage.modules - sage: L.step() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = LieAlgebra(QQ, {('X','Y'): {'Z': 1}}, nilpotent=True) + sage: L.step() 2 - sage: sc = {('X','Y'): {'Z': 1}, ('X','Z'): {'W': 1}} # optional - sage.combinat sage.modules - sage: LieAlgebra(QQ, sc, nilpotent=True).step() # optional - sage.combinat sage.modules + sage: sc = {('X','Y'): {'Z': 1}, ('X','Z'): {'W': 1}} + sage: LieAlgebra(QQ, sc, nilpotent=True).step() 3 """ if not hasattr(self, '_step'): @@ -156,8 +159,8 @@ def is_nilpotent(self): EXAMPLES:: - sage: L = LieAlgebra(QQ, {('x','y'): {'z': 1}}, nilpotent=True) # optional - sage.combinat sage.modules - sage: L.is_nilpotent() # optional - sage.combinat sage.modules + sage: L = LieAlgebra(QQ, {('x','y'): {'z': 1}}, nilpotent=True) # needs sage.combinat sage.modules + sage: L.is_nilpotent() # needs sage.combinat sage.modules True """ return True diff --git a/src/sage/categories/finite_dimensional_semisimple_algebras_with_basis.py b/src/sage/categories/finite_dimensional_semisimple_algebras_with_basis.py index 56303fc5eb0..128307db7f2 100644 --- a/src/sage/categories/finite_dimensional_semisimple_algebras_with_basis.py +++ b/src/sage/categories/finite_dimensional_semisimple_algebras_with_basis.py @@ -49,13 +49,13 @@ def radical_basis(self, **keywords): EXAMPLES:: - sage: A = SymmetricGroup(4).algebra(QQ) # optional - sage.groups sage.modules - sage: A.radical_basis() # optional - sage.groups sage.modules + sage: A = SymmetricGroup(4).algebra(QQ) # needs sage.groups sage.modules + sage: A.radical_basis() # needs sage.groups sage.modules () TESTS:: - sage: A.radical_basis.__module__ # optional - sage.groups sage.modules + sage: A.radical_basis.__module__ # needs sage.groups sage.modules 'sage.categories.finite_dimensional_semisimple_algebras_with_basis' """ return () @@ -81,25 +81,27 @@ def central_orthogonal_idempotents(self): acts on `V_i` as multiplication by the `i`-th power of a cube root of unity:: - sage: R = CyclotomicField(3) # optional - sage.rings.number_field - sage: A3 = AlternatingGroup(3).algebra(R) # optional - sage.rings.number_field sage.groups - sage: idempotents = A3.central_orthogonal_idempotents() # optional - sage.rings.number_field sage.groups - sage: idempotents # optional - sage.rings.number_field sage.groups + sage: # needs sage.groups sage.rings.number_field + sage: R = CyclotomicField(3) + sage: A3 = AlternatingGroup(3).algebra(R) + sage: idempotents = A3.central_orthogonal_idempotents() + sage: idempotents (1/3*() + 1/3*(1,2,3) + 1/3*(1,3,2), 1/3*() - (1/3*zeta3+1/3)*(1,2,3) - (-1/3*zeta3)*(1,3,2), 1/3*() - (-1/3*zeta3)*(1,2,3) - (1/3*zeta3+1/3)*(1,3,2)) - sage: A3.is_identity_decomposition_into_orthogonal_idempotents(idempotents) # optional - sage.rings.number_field sage.groups + sage: A3.is_identity_decomposition_into_orthogonal_idempotents(idempotents) True For the semisimple quotient of a quiver algebra, we recover the vertices of the quiver:: - sage: A = FiniteDimensionalAlgebrasWithBasis(QQ).example(); A # optional - sage.combinat + sage: # needs sage.graphs sage.modules + sage: A = FiniteDimensionalAlgebrasWithBasis(QQ).example(); A An example of a finite dimensional algebra with basis: the path algebra of the Kronecker quiver (containing the arrows a:x->y and b:x->y) over Rational Field - sage: Aquo = A.semisimple_quotient() # optional - sage.combinat - sage: Aquo.central_orthogonal_idempotents() # optional - sage.combinat + sage: Aquo = A.semisimple_quotient() + sage: Aquo.central_orthogonal_idempotents() (B['x'], B['y']) """ return tuple([x.lift() @@ -157,8 +159,8 @@ def _orthogonal_decomposition(self, generators=None): center of the algebra of the symmetric group `S_4`:: - sage: Z4 = SymmetricGroup(4).algebra(QQ).center() # optional - sage.groups sage.modules - sage: Z4._orthogonal_decomposition() # optional - sage.groups sage.modules + sage: Z4 = SymmetricGroup(4).algebra(QQ).center() # needs sage.groups sage.modules + sage: Z4._orthogonal_decomposition() # needs sage.groups sage.modules (B[0] + B[1] + B[2] + B[3] + B[4], B[0] + 1/3*B[1] - 1/3*B[2] - 1/3*B[4], B[0] + B[2] - 1/2*B[3], @@ -219,10 +221,11 @@ def central_orthogonal_idempotents(self): EXAMPLES:: - sage: A4 = SymmetricGroup(4).algebra(QQ) # optional - sage.groups sage.modules - sage: Z4 = A4.center() # optional - sage.groups sage.modules - sage: idempotents = Z4.central_orthogonal_idempotents() # optional - sage.groups sage.modules - sage: idempotents # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: A4 = SymmetricGroup(4).algebra(QQ) + sage: Z4 = A4.center() + sage: idempotents = Z4.central_orthogonal_idempotents() + sage: idempotents (1/24*B[0] + 1/24*B[1] + 1/24*B[2] + 1/24*B[3] + 1/24*B[4], 3/8*B[0] + 1/8*B[1] - 1/8*B[2] - 1/8*B[4], 1/6*B[0] + 1/6*B[2] - 1/12*B[3], @@ -233,7 +236,7 @@ def central_orthogonal_idempotents(self): recognize among them the sum and alternating sum of all permutations:: - sage: [e.lift() for e in idempotents] # optional - sage.groups sage.modules + sage: [e.lift() for e in idempotents] # needs sage.groups sage.modules [1/24*() + 1/24*(3,4) + 1/24*(2,3) + 1/24*(2,3,4) + 1/24*(2,4,3) + 1/24*(2,4) + 1/24*(1,2) + 1/24*(1,2)(3,4) + 1/24*(1,2,3) + 1/24*(1,2,3,4) + 1/24*(1,2,4,3) + 1/24*(1,2,4) + 1/24*(1,3,2) @@ -251,7 +254,7 @@ def central_orthogonal_idempotents(self): We check that they indeed form a decomposition of the identity of `Z_4` into orthogonal idempotents:: - sage: Z4.is_identity_decomposition_into_orthogonal_idempotents(idempotents) # optional - sage.groups sage.modules + sage: Z4.is_identity_decomposition_into_orthogonal_idempotents(idempotents) # needs sage.groups sage.modules True """ return tuple([(e.leading_coefficient()/(e*e).leading_coefficient())*e diff --git a/src/sage/categories/finite_enumerated_sets.py b/src/sage/categories/finite_enumerated_sets.py index 4d90a3cd3f9..34d95be9c92 100644 --- a/src/sage/categories/finite_enumerated_sets.py +++ b/src/sage/categories/finite_enumerated_sets.py @@ -59,9 +59,9 @@ def _call_(self, X): EXAMPLES:: - sage: FiniteEnumeratedSets()(GF(3)) # optional - sage.rings.finite_rings + sage: FiniteEnumeratedSets()(GF(3)) Finite Field of size 3 - sage: Partitions(3) # optional - sage.combinat + sage: Partitions(3) # needs sage.combinat Partitions of the integer 3 For now, lists, tuples, sets, Sets are coerced into finite @@ -86,9 +86,9 @@ def __len__(self): EXAMPLES:: - sage: len(GF(5)) # optional - sage.rings.finite_rings + sage: len(GF(5)) 5 - sage: len(MatrixSpace(GF(2), 3, 3)) # optional - sage.rings.finite_rings sage.modules + sage: len(MatrixSpace(GF(2), 3, 3)) # needs sage.modules 512 """ return int(self.cardinality()) @@ -590,17 +590,17 @@ class ParentMethods: inherit various methods from `Sets.CartesianProducts` and not from :class:`EnumeratedSets.Finite`:: - sage: C = cartesian_product([Partitions(10), Permutations(20)]) # optional - sage.combinat - sage: C in EnumeratedSets().Finite() # optional - sage.combinat + sage: C = cartesian_product([Partitions(10), Permutations(20)]) # needs sage.combinat + sage: C in EnumeratedSets().Finite() # needs sage.combinat True - sage: C.random_element.__module__ # optional - sage.combinat + sage: C.random_element.__module__ # needs sage.combinat 'sage.categories.sets_cat' - sage: C.cardinality.__module__ # optional - sage.combinat + sage: C.cardinality.__module__ # needs sage.combinat 'sage.categories.sets_cat' - sage: C.__iter__.__module__ # optional - sage.combinat + sage: C.__iter__.__module__ # needs sage.combinat 'sage.categories.sets_cat' """ random_element = raw_getattr(Sets.CartesianProducts.ParentMethods, "random_element") @@ -613,9 +613,9 @@ def last(self): EXAMPLES:: - sage: C = cartesian_product([Zmod(42), Partitions(10), # optional - sage.combinat + sage: C = cartesian_product([Zmod(42), Partitions(10), # needs sage.combinat ....: IntegerRange(5)]) - sage: C.last() # optional - sage.combinat + sage: C.last() # needs sage.combinat (41, [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 4) """ return self._cartesian_product_of_elements( @@ -636,13 +636,13 @@ def rank(self, x): EXAMPLES:: - sage: C = cartesian_product([GF(2), GF(11), GF(7)]) # optional - sage.rings.finite_rings - sage: C.rank(C((1,2,5))) # optional - sage.rings.finite_rings + sage: C = cartesian_product([GF(2), GF(11), GF(7)]) + sage: C.rank(C((1,2,5))) 96 - sage: C.rank(C((0,0,0))) # optional - sage.rings.finite_rings + sage: C.rank(C((0,0,0))) 0 - sage: for c in C: print(C.rank(c)) # optional - sage.rings.finite_rings + sage: for c in C: print(C.rank(c)) 0 1 2 @@ -655,14 +655,15 @@ def rank(self, x): 152 153 + sage: # needs sage.combinat sage: F1 = FiniteEnumeratedSet('abcdefgh') sage: F2 = IntegerRange(250) - sage: F3 = Partitions(20) # optional - sage.combinat - sage: C = cartesian_product([F1, F2, F3]) # optional - sage.combinat - sage: c = C(('a', 86, [7,5,4,4])) # optional - sage.combinat - sage: C.rank(c) # optional - sage.combinat + sage: F3 = Partitions(20) + sage: C = cartesian_product([F1, F2, F3]) + sage: c = C(('a', 86, [7,5,4,4])) + sage: C.rank(c) 54213 - sage: C.unrank(54213) # optional - sage.combinat + sage: C.unrank(54213) ('a', 86, [7, 5, 4, 4]) """ from builtins import zip @@ -692,18 +693,18 @@ def unrank(self, i): EXAMPLES:: - sage: C = cartesian_product([GF(3), GF(11), GF(7), GF(5)]) # optional - sage.rings.finite_rings - sage: c = C.unrank(123); c # optional - sage.rings.finite_rings + sage: C = cartesian_product([GF(3), GF(11), GF(7), GF(5)]) + sage: c = C.unrank(123); c (0, 3, 3, 3) - sage: C.rank(c) # optional - sage.rings.finite_rings + sage: C.rank(c) 123 - sage: c = C.unrank(857); c # optional - sage.rings.finite_rings + sage: c = C.unrank(857); c (2, 2, 3, 2) - sage: C.rank(c) # optional - sage.rings.finite_rings + sage: C.rank(c) 857 - sage: C.unrank(2500) # optional - sage.rings.finite_rings + sage: C.unrank(2500) Traceback (most recent call last): ... IndexError: index i (=2) is greater than the cardinality diff --git a/src/sage/categories/finite_fields.py b/src/sage/categories/finite_fields.py index b685a249780..0dc80fb8e59 100644 --- a/src/sage/categories/finite_fields.py +++ b/src/sage/categories/finite_fields.py @@ -34,7 +34,7 @@ class FiniteFields(CategoryWithAxiom): Some examples of membership testing and coercion:: - sage: FiniteField(17) in K # optional - sage.rings.finite_rings + sage: FiniteField(17) in K True sage: RationalField() in K False @@ -67,7 +67,7 @@ def __contains__(self, x): """ EXAMPLES:: - sage: GF(4, "a") in FiniteFields() # optional - sage.rings.finite_rings + sage: GF(4, "a") in FiniteFields() # needs sage.rings.finite_rings True sage: QQ in FiniteFields() False @@ -82,7 +82,7 @@ def _call_(self, x): """ EXAMPLES:: - sage: FiniteFields()(GF(4, "a")) # optional - sage.rings.finite_rings + sage: FiniteFields()(GF(4, "a")) # needs sage.rings.finite_rings Finite Field in a of size 2^2 sage: FiniteFields()(RationalField()) # indirect doctest Traceback (most recent call last): diff --git a/src/sage/categories/finite_groups.py b/src/sage/categories/finite_groups.py index 1d0e7d72357..44447d6db2b 100644 --- a/src/sage/categories/finite_groups.py +++ b/src/sage/categories/finite_groups.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.groups +# sage.doctest: needs sage.groups r""" Finite groups """ diff --git a/src/sage/categories/finite_lattice_posets.py b/src/sage/categories/finite_lattice_posets.py index 1bb0de98fad..96f2385404c 100644 --- a/src/sage/categories/finite_lattice_posets.py +++ b/src/sage/categories/finite_lattice_posets.py @@ -49,8 +49,8 @@ def join_irreducibles(self): EXAMPLES:: - sage: L = LatticePoset({0:[1,2],1:[3],2:[3,4],3:[5],4:[5]}) # optional - sage.combinat sage.graphs - sage: L.join_irreducibles() # optional - sage.combinat sage.graphs + sage: L = LatticePoset({0:[1,2],1:[3],2:[3,4],3:[5],4:[5]}) # needs sage.graphs sage.modules + sage: L.join_irreducibles() # needs sage.graphs sage.modules [1, 2, 4] .. SEEALSO:: @@ -71,8 +71,8 @@ def join_irreducibles_poset(self): EXAMPLES:: - sage: L = LatticePoset({0:[1,2,3],1:[4],2:[4],3:[4]}) # optional - sage.combinat sage.graphs - sage: L.join_irreducibles_poset() # optional - sage.combinat sage.graphs + sage: L = LatticePoset({0:[1,2,3],1:[4],2:[4],3:[4]}) # needs sage.graphs sage.modules + sage: L.join_irreducibles_poset() # needs sage.graphs sage.modules Finite poset containing 3 elements .. SEEALSO:: @@ -92,8 +92,8 @@ def meet_irreducibles(self): EXAMPLES:: - sage: L = LatticePoset({0:[1,2],1:[3],2:[3,4],3:[5],4:[5]}) # optional - sage.combinat sage.graphs - sage: L.meet_irreducibles() # optional - sage.combinat sage.graphs + sage: L = LatticePoset({0:[1,2],1:[3],2:[3,4],3:[5],4:[5]}) # needs sage.graphs sage.modules + sage: L.meet_irreducibles() # needs sage.graphs sage.modules [1, 3, 4] .. SEEALSO:: @@ -114,8 +114,8 @@ def meet_irreducibles_poset(self): EXAMPLES:: - sage: L = LatticePoset({0:[1,2,3],1:[4],2:[4],3:[4]}) # optional - sage.combinat sage.graphs - sage: L.join_irreducibles_poset() # optional - sage.combinat sage.graphs + sage: L = LatticePoset({0:[1,2,3],1:[4],2:[4],3:[4]}) # needs sage.graphs sage.modules + sage: L.join_irreducibles_poset() # needs sage.graphs sage.modules Finite poset containing 3 elements .. SEEALSO:: @@ -143,20 +143,21 @@ def irreducibles_poset(self): EXAMPLES:: - sage: L = LatticePoset({1: [2, 3, 4], 2: [5, 6], 3: [5], # optional - sage.combinat sage.graphs + sage: # needs sage.combinat sage.graphs sage.modules + sage: L = LatticePoset({1: [2, 3, 4], 2: [5, 6], 3: [5], ....: 4: [6], 5: [9, 7], 6: [9, 8], 7: [10], ....: 8: [10], 9: [10], 10: [11]}) - sage: L_ = L.irreducibles_poset() # optional - sage.combinat sage.graphs - sage: sorted(L_) # optional - sage.combinat sage.graphs + sage: L_ = L.irreducibles_poset() + sage: sorted(L_) [2, 3, 4, 7, 8, 9, 10, 11] - sage: L_.completion_by_cuts().is_isomorphic(L) # optional - sage.combinat sage.graphs + sage: L_.completion_by_cuts().is_isomorphic(L) True TESTS:: - sage: LatticePoset().irreducibles_poset() # optional - sage.combinat sage.graphs + sage: LatticePoset().irreducibles_poset() # needs sage.graphs Finite poset containing 0 elements - sage: posets.ChainPoset(1).irreducibles_poset() # optional - sage.combinat sage.graphs + sage: posets.ChainPoset(1).irreducibles_poset() # needs sage.graphs Finite poset containing 1 elements """ if self.cardinality() == 1: @@ -191,36 +192,36 @@ def is_lattice_morphism(self, f, codomain): lattice of divisors of `60`, and check that the map `b \mapsto 5 \prod_{x\in b} x` is a morphism of lattices:: - sage: D = LatticePoset((divisors(60), attrcall("divides"))) # optional - sage.combinat sage.graphs - sage: B = LatticePoset((Subsets([2,2,3]), attrcall("issubset"))) # optional - sage.combinat sage.graphs - sage: def f(b): return D(5*prod(b)) # optional - sage.combinat sage.graphs - sage: B.is_lattice_morphism(f, D) # optional - sage.combinat sage.graphs + sage: D = LatticePoset((divisors(60), attrcall("divides"))) # needs sage.graphs sage.modules + sage: B = LatticePoset((Subsets([2,2,3]), attrcall("issubset"))) # needs sage.graphs sage.modules + sage: def f(b): return D(5*prod(b)) + sage: B.is_lattice_morphism(f, D) # needs sage.graphs sage.modules True We construct the boolean lattice `B_2`:: - sage: B = posets.BooleanLattice(2) # optional - sage.combinat sage.graphs - sage: B.cover_relations() # optional - sage.combinat sage.graphs + sage: B = posets.BooleanLattice(2) # needs sage.graphs + sage: B.cover_relations() # needs sage.graphs [[0, 1], [0, 2], [1, 3], [2, 3]] And the same lattice with new top and bottom elements numbered respectively `-1` and `3`:: - sage: G = DiGraph({-1:[0], 0:[1,2], 1:[3], 2:[3], 3:[4]}) # optional - sage.graphs - sage: L = LatticePoset(G) # optional - sage.combinat sage.graphs - sage: L.cover_relations() # optional - sage.combinat sage.graphs + sage: G = DiGraph({-1:[0], 0:[1,2], 1:[3], 2:[3], 3:[4]}) # needs sage.graphs + sage: L = LatticePoset(G) # needs sage.graphs sage.modules + sage: L.cover_relations() # needs sage.graphs sage.modules [[-1, 0], [0, 1], [0, 2], [1, 3], [2, 3], [3, 4]] - sage: f = {B(0): L(0), B(1): L(1), B(2): L(2), B(3): L(3)}.__getitem__ # optional - sage.combinat sage.graphs - sage: B.is_lattice_morphism(f, L) # optional - sage.combinat sage.graphs + sage: f = {B(0): L(0), B(1): L(1), B(2): L(2), B(3): L(3)}.__getitem__ # needs sage.graphs sage.modules + sage: B.is_lattice_morphism(f, L) # needs sage.graphs sage.modules True - sage: f = {B(0): L(-1),B(1): L(1), B(2): L(2), B(3): L(3)}.__getitem__ # optional - sage.combinat sage.graphs - sage: B.is_lattice_morphism(f, L) # optional - sage.combinat sage.graphs + sage: f = {B(0): L(-1),B(1): L(1), B(2): L(2), B(3): L(3)}.__getitem__ # needs sage.graphs sage.modules + sage: B.is_lattice_morphism(f, L) # needs sage.graphs sage.modules False - sage: f = {B(0): L(0), B(1): L(1), B(2): L(2), B(3): L(4)}.__getitem__ # optional - sage.combinat sage.graphs - sage: B.is_lattice_morphism(f, L) # optional - sage.combinat sage.graphs + sage: f = {B(0): L(0), B(1): L(1), B(2): L(2), B(3): L(4)}.__getitem__ # needs sage.graphs sage.modules + sage: B.is_lattice_morphism(f, L) # needs sage.graphs sage.modules False .. SEEALSO:: diff --git a/src/sage/categories/finite_monoids.py b/src/sage/categories/finite_monoids.py index 9531b671249..b446dc925cb 100644 --- a/src/sage/categories/finite_monoids.py +++ b/src/sage/categories/finite_monoids.py @@ -72,9 +72,9 @@ def nerve(self): The nerve (classifying space) of the cyclic group of order 2 is infinite-dimensional real projective space. :: - sage: Sigma2 = groups.permutation.Cyclic(2) # optional - sage.groups - sage: BSigma2 = Sigma2.nerve() # optional - sage.groups - sage: BSigma2.cohomology(4, base_ring=GF(2)) # optional - sage.groups sage.modules sage.rings.finite_rings + sage: Sigma2 = groups.permutation.Cyclic(2) # needs sage.groups + sage: BSigma2 = Sigma2.nerve() # needs sage.groups + sage: BSigma2.cohomology(4, base_ring=GF(2)) # needs sage.groups sage.modules Vector space of dimension 1 over Finite Field of size 2 The `k`-simplices of the nerve are named after the chains @@ -83,29 +83,30 @@ def nerve(self): element) and ``(1,2)`` in Sage. So the 1-cells and 2-cells in `B\Sigma_2` are:: - sage: BSigma2.n_cells(1) # optional - sage.groups + sage: BSigma2.n_cells(1) # needs sage.groups [(1,2)] - sage: BSigma2.n_cells(2) # optional - sage.groups + sage: BSigma2.n_cells(2) # needs sage.groups [(1,2) * (1,2)] Another construction of the group, with different names for its elements:: - sage: C2 = groups.misc.MultiplicativeAbelian([2]) # optional - sage.groups - sage: BC2 = C2.nerve() # optional - sage.groups - sage: BC2.n_cells(0) # optional - sage.groups + sage: # needs sage.groups + sage: C2 = groups.misc.MultiplicativeAbelian([2]) + sage: BC2 = C2.nerve() + sage: BC2.n_cells(0) [1] - sage: BC2.n_cells(1) # optional - sage.groups + sage: BC2.n_cells(1) [f] - sage: BC2.n_cells(2) # optional - sage.groups + sage: BC2.n_cells(2) [f * f] With mod `p` coefficients, `B \Sigma_p` should have its first nonvanishing homology group in dimension `p`:: - sage: Sigma3 = groups.permutation.Symmetric(3) # optional - sage.groups - sage: BSigma3 = Sigma3.nerve() # optional - sage.groups - sage: BSigma3.homology(range(4), base_ring=GF(3)) # optional - sage.groups sage.rings.finite_rings + sage: Sigma3 = groups.permutation.Symmetric(3) # needs sage.groups + sage: BSigma3 = Sigma3.nerve() # needs sage.groups + sage: BSigma3.homology(range(4), base_ring=GF(3)) # needs sage.groups {0: Vector space of dimension 0 over Finite Field of size 3, 1: Vector space of dimension 0 over Finite Field of size 3, 2: Vector space of dimension 0 over Finite Field of size 3, @@ -115,13 +116,13 @@ def nerve(self): `B\Sigma_2` for relatively large values of `n`, while for `B\Sigma_3`, the complexes get large pretty quickly:: - sage: Sigma2.nerve().n_skeleton(14) # optional - sage.groups + sage: # needs sage.groups + sage: Sigma2.nerve().n_skeleton(14) Simplicial set with 15 non-degenerate simplices - - sage: BSigma3 = Sigma3.nerve() # optional - sage.groups - sage: BSigma3.n_skeleton(3) # optional - sage.groups + sage: BSigma3 = Sigma3.nerve() + sage: BSigma3.n_skeleton(3) Simplicial set with 156 non-degenerate simplices - sage: BSigma3.n_skeleton(4) # optional - sage.groups + sage: BSigma3.n_skeleton(4) Simplicial set with 781 non-degenerate simplices Finally, note that the classifying space of the order `p` @@ -129,29 +130,28 @@ def nerve(self): on `p` letters, and its first homology group appears earlier:: - sage: C3 = groups.misc.MultiplicativeAbelian([3]) # optional - sage.groups - sage: list(C3) # optional - sage.groups + sage: # needs sage.groups + sage: C3 = groups.misc.MultiplicativeAbelian([3]) + sage: list(C3) [1, f, f^2] - sage: BC3 = C3.nerve() # optional - sage.groups - sage: BC3.n_cells(1) # optional - sage.groups + sage: BC3 = C3.nerve() + sage: BC3.n_cells(1) [f, f^2] - sage: BC3.n_cells(2) # optional - sage.groups + sage: BC3.n_cells(2) [f * f, f * f^2, f^2 * f, f^2 * f^2] - sage: len(BSigma3.n_cells(2)) # optional - sage.groups + sage: len(BSigma3.n_cells(2)) 25 - sage: len(BC3.n_cells(3)) # optional - sage.groups + sage: len(BC3.n_cells(3)) 8 - sage: len(BSigma3.n_cells(3)) # optional - sage.groups + sage: len(BSigma3.n_cells(3)) 125 - - sage: BC3.homology(range(4), base_ring=GF(3)) # optional - sage.groups sage.rings.finite_rings + sage: BC3.homology(range(4), base_ring=GF(3)) {0: Vector space of dimension 0 over Finite Field of size 3, 1: Vector space of dimension 1 over Finite Field of size 3, 2: Vector space of dimension 1 over Finite Field of size 3, 3: Vector space of dimension 1 over Finite Field of size 3} - - sage: BC5 = groups.permutation.Cyclic(5).nerve() # optional - sage.groups - sage: BC5.homology(range(4), base_ring=GF(5)) # optional - sage.groups sage.rings.finite_rings + sage: BC5 = groups.permutation.Cyclic(5).nerve() + sage: BC5.homology(range(4), base_ring=GF(5)) {0: Vector space of dimension 0 over Finite Field of size 5, 1: Vector space of dimension 1 over Finite Field of size 5, 2: Vector space of dimension 1 over Finite Field of size 5, @@ -179,20 +179,22 @@ def rhodes_radical_congruence(self, base_ring=None): EXAMPLES:: sage: M = Monoids().Finite().example() - sage: M.rhodes_radical_congruence() # optional - sage.groups sage.modules + sage: M.rhodes_radical_congruence() # needs sage.modules [(0, 6), (2, 8), (4, 10)] - sage: from sage.monoids.hecke_monoid import HeckeMonoid # optional - sage.groups sage.modules - sage: H3 = HeckeMonoid(SymmetricGroup(3)) # optional - sage.groups sage.modules - sage: H3.repr_element_method(style="reduced") # optional - sage.groups sage.modules - sage: H3.rhodes_radical_congruence() # optional - sage.groups sage.modules + + sage: # needs sage.combinat sage.groups sage.modules + sage: from sage.monoids.hecke_monoid import HeckeMonoid + sage: H3 = HeckeMonoid(SymmetricGroup(3)) + sage: H3.repr_element_method(style="reduced") + sage: H3.rhodes_radical_congruence() [([1, 2], [2, 1]), ([1, 2], [1, 2, 1]), ([2, 1], [1, 2, 1])] By Maschke's theorem, every group algebra over `\QQ` is semisimple hence the Rhodes radical of a group must be trivial:: - sage: SymmetricGroup(3).rhodes_radical_congruence() # optional - sage.groups sage.modules + sage: SymmetricGroup(3).rhodes_radical_congruence() # needs sage.groups sage.modules [] - sage: DihedralGroup(10).rhodes_radical_congruence() # optional - sage.groups sage.modules + sage: DihedralGroup(10).rhodes_radical_congruence() # needs sage.groups sage.modules [] REFERENCES: diff --git a/src/sage/categories/finite_permutation_groups.py b/src/sage/categories/finite_permutation_groups.py index e081d2d4f63..f14c66a96c9 100644 --- a/src/sage/categories/finite_permutation_groups.py +++ b/src/sage/categories/finite_permutation_groups.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.groups +# sage.doctest: needs sage.groups r""" Finite Permutation Groups """ @@ -270,8 +270,8 @@ def profile_series(self, variable='z'): Univariate Polynomial Ring in z over Rational Field sage: D8.profile_series(variable='y') y^8 + y^7 + 4*y^6 + 5*y^5 + 8*y^4 + 5*y^3 + 4*y^2 + y + 1 - sage: u = var('u') # optional - sage.symbolic - sage: D8.profile_series(u).parent() # optional - sage.symbolic + sage: u = var('u') # needs sage.symbolic + sage: D8.profile_series(u).parent() # needs sage.symbolic Symbolic Ring """ from sage.rings.integer_ring import ZZ diff --git a/src/sage/categories/finite_posets.py b/src/sage/categories/finite_posets.py index 263033a2c9b..c71ee5eaa7b 100644 --- a/src/sage/categories/finite_posets.py +++ b/src/sage/categories/finite_posets.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.combinat sage.graphs +# sage.doctest: needs sage.combinat sage.graphs r""" Finite posets diff --git a/src/sage/categories/finite_semigroups.py b/src/sage/categories/finite_semigroups.py index e9c31e1ad62..ad384fc2b79 100644 --- a/src/sage/categories/finite_semigroups.py +++ b/src/sage/categories/finite_semigroups.py @@ -87,7 +87,7 @@ def j_classes(self): EXAMPLES:: sage: S = FiniteSemigroups().example(alphabet=('a','b', 'c')) - sage: sorted(map(sorted, S.j_classes())) # optional - sage.graphs + sage: sorted(map(sorted, S.j_classes())) # needs sage.graphs [['a'], ['ab', 'ba'], ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'], ['ac', 'ca'], ['b'], ['bc', 'cb'], ['c']] """ @@ -105,7 +105,7 @@ def j_classes_of_idempotents(self): EXAMPLES:: sage: S = FiniteSemigroups().example(alphabet=('a','b', 'c')) - sage: sorted(map(sorted, S.j_classes_of_idempotents())) # optional - sage.graphs + sage: sorted(map(sorted, S.j_classes_of_idempotents())) # needs sage.graphs [['a'], ['ab', 'ba'], ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'], ['ac', 'ca'], ['b'], ['bc', 'cb'], ['c']] """ @@ -123,7 +123,7 @@ def j_transversal_of_idempotents(self): The chosen elements depend on the order of each `J`-class, and that order is random when using Python 3. :: - sage: sorted(S.j_transversal_of_idempotents()) # random # optional - sage.graphs + sage: sorted(S.j_transversal_of_idempotents()) # random # needs sage.graphs ['a', 'ab', 'abc', 'ac', 'b', 'c', 'cb'] """ def first_idempotent(l): diff --git a/src/sage/categories/finite_weyl_groups.py b/src/sage/categories/finite_weyl_groups.py index 1d1d0250c23..4420827c833 100644 --- a/src/sage/categories/finite_weyl_groups.py +++ b/src/sage/categories/finite_weyl_groups.py @@ -27,7 +27,7 @@ class FiniteWeylGroups(CategoryWithAxiom): TESTS:: sage: W = FiniteWeylGroups().example() - sage: TestSuite(W).run() # optional - sage.combinat + sage: TestSuite(W).run() """ class ParentMethods: diff --git a/src/sage/categories/finitely_generated_lambda_bracket_algebras.py b/src/sage/categories/finitely_generated_lambda_bracket_algebras.py index f8a36053753..c997118a3bc 100644 --- a/src/sage/categories/finitely_generated_lambda_bracket_algebras.py +++ b/src/sage/categories/finitely_generated_lambda_bracket_algebras.py @@ -27,7 +27,7 @@ class FinitelyGeneratedLambdaBracketAlgebras(CategoryWithAxiom_over_base_ring): EXAMPLES:: sage: from sage.categories.lambda_bracket_algebras import LambdaBracketAlgebras - sage: LambdaBracketAlgebras(QQbar).FinitelyGenerated() # optional - sage.rings.number_field + sage: LambdaBracketAlgebras(QQbar).FinitelyGenerated() # needs sage.rings.number_field Category of finitely generated lambda bracket algebras over Algebraic Field """ _base_category_class_and_axiom = (LambdaBracketAlgebras, "FinitelyGeneratedAsLambdaBracketAlgebra") @@ -39,12 +39,12 @@ def ngens(self): EXAMPLES:: - sage: Vir = lie_conformal_algebras.Virasoro(QQ) # optional - sage.combinat sage.modules - sage: Vir.ngens() # optional - sage.combinat sage.modules + sage: Vir = lie_conformal_algebras.Virasoro(QQ) # needs sage.combinat sage.modules + sage: Vir.ngens() # needs sage.combinat sage.modules 2 - sage: V = lie_conformal_algebras.Affine(QQ, 'A2') # optional - sage.combinat sage.modules - sage: V.ngens() # optional - sage.combinat sage.modules + sage: V = lie_conformal_algebras.Affine(QQ, 'A2') # needs sage.combinat sage.modules + sage: V.ngens() # needs sage.combinat sage.modules 9 """ return len(self.gens()) @@ -55,12 +55,13 @@ def gen(self,i): EXAMPLES:: - sage: V = lie_conformal_algebras.Affine(QQ, 'A1') # optional - sage.combinat sage.modules - sage: V.gens() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: V = lie_conformal_algebras.Affine(QQ, 'A1') + sage: V.gens() (B[alpha[1]], B[alphacheck[1]], B[-alpha[1]], B['K']) - sage: V.gen(0) # optional - sage.combinat sage.modules + sage: V.gen(0) B[alpha[1]] - sage: V.1 # optional - sage.combinat sage.modules + sage: V.1 B[alphacheck[1]] """ return self.gens()[i] @@ -74,11 +75,11 @@ def some_elements(self): EXAMPLES:: - sage: V = lie_conformal_algebras.Affine(QQ, 'A1', # optional - sage.combinat sage.modules + sage: V = lie_conformal_algebras.Affine(QQ, 'A1', # needs sage.combinat sage.modules ....: names=('e', 'h', 'f')) - sage: V.some_elements() # optional - sage.combinat sage.modules + sage: V.some_elements() # needs sage.combinat sage.modules [e, h, f, K, ...] - sage: all(v.parent() is V for v in V.some_elements()) # optional - sage.combinat sage.modules + sage: all(v.parent() is V for v in V.some_elements()) # needs sage.combinat sage.modules True """ S = list(self.gens()) @@ -93,7 +94,7 @@ class Graded(GradedModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).FinitelyGenerated().Graded() # optional - sage.rings.number_field + sage: LieConformalAlgebras(QQbar).FinitelyGenerated().Graded() # needs sage.rings.number_field Category of H-graded finitely generated lie conformal algebras over Algebraic Field """ @@ -103,7 +104,7 @@ def _repr_object_names(self): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() # optional - sage.rings.number_field + sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() # needs sage.rings.number_field Category of H-graded finitely generated Lie conformal algebras with basis over Algebraic Field """ return "H-graded {}".format(self.base_category()._repr_object_names()) diff --git a/src/sage/categories/finitely_generated_lie_conformal_algebras.py b/src/sage/categories/finitely_generated_lie_conformal_algebras.py index 96433749aa4..53d5ed4ccf6 100644 --- a/src/sage/categories/finitely_generated_lie_conformal_algebras.py +++ b/src/sage/categories/finitely_generated_lie_conformal_algebras.py @@ -27,7 +27,7 @@ class FinitelyGeneratedLieConformalAlgebras(CategoryWithAxiom_over_base_ring): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).FinitelyGenerated() # optional - sage.rings.number_field + sage: LieConformalAlgebras(QQbar).FinitelyGenerated() # needs sage.rings.number_field Category of finitely generated lie conformal algebras over Algebraic Field """ _base_category_class_and_axiom = (LieConformalAlgebras, "FinitelyGeneratedAsLambdaBracketAlgebra") @@ -43,11 +43,11 @@ def some_elements(self): EXAMPLES:: - sage: V = lie_conformal_algebras.Affine(QQ, 'A1', # optional - sage.combinat sage.modules + sage: V = lie_conformal_algebras.Affine(QQ, 'A1', # needs sage.combinat sage.modules ....: names=('e', 'h', 'f')) - sage: V.some_elements() # optional - sage.combinat sage.modules + sage: V.some_elements() # needs sage.combinat sage.modules [e, h, f, K, ...] - sage: all(v.parent() is V for v in V.some_elements()) # optional - sage.combinat sage.modules + sage: all(v.parent() is V for v in V.some_elements()) # needs sage.combinat sage.modules True """ S = list(self.gens()) @@ -62,7 +62,7 @@ class Super(SuperModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(AA).FinitelyGenerated().Super() # optional - sage.rings.number_field + sage: LieConformalAlgebras(AA).FinitelyGenerated().Super() # needs sage.rings.number_field Category of super finitely generated lie conformal algebras over Algebraic Real Field """ @@ -72,7 +72,7 @@ class Graded(GradedModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).FinitelyGenerated().Super().Graded() # optional - sage.rings.number_field + sage: LieConformalAlgebras(QQbar).FinitelyGenerated().Super().Graded() # needs sage.rings.number_field Category of H-graded super finitely generated lie conformal algebras over Algebraic Field """ @@ -82,8 +82,8 @@ def _repr_object_names(self): EXAMPLES:: - sage: C = LieConformalAlgebras(QQbar).FinitelyGenerated() # optional - sage.rings.number_field - sage: C.Super().Graded() # optional - sage.rings.number_field + sage: C = LieConformalAlgebras(QQbar).FinitelyGenerated() # needs sage.rings.number_field + sage: C.Super().Graded() # needs sage.rings.number_field Category of H-graded super finitely generated lie conformal algebras over Algebraic Field """ @@ -95,7 +95,7 @@ class Graded(GradedModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).FinitelyGenerated().Graded() # optional - sage.rings.number_field + sage: LieConformalAlgebras(QQbar).FinitelyGenerated().Graded() # needs sage.rings.number_field Category of H-graded finitely generated lie conformal algebras over Algebraic Field """ @@ -105,7 +105,7 @@ def _repr_object_names(self): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() # optional - sage.rings.number_field + sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() # needs sage.rings.number_field Category of H-graded finitely generated Lie conformal algebras with basis over Algebraic Field """ diff --git a/src/sage/categories/function_fields.py b/src/sage/categories/function_fields.py index 093d2ff6fac..6c949b6197a 100644 --- a/src/sage/categories/function_fields.py +++ b/src/sage/categories/function_fields.py @@ -56,10 +56,10 @@ def _call_(self, x): sage: C(K) Rational function field in x over Rational Field sage: Ky. = K[] - sage: L = K.extension(y^2 - x) # optional - sage.rings.function_field - sage: C(L) # optional - sage.rings.function_field + sage: L = K.extension(y^2 - x) # needs sage.rings.function_field + sage: C(L) # needs sage.rings.function_field Function field in y defined by y^2 - x - sage: C(L.equation_order()) # optional - sage.rings.function_field + sage: C(L.equation_order()) # needs sage.rings.function_field Function field in y defined by y^2 - x """ try: diff --git a/src/sage/categories/functor.pyx b/src/sage/categories/functor.pyx index 823d3a2132f..c25e99f2164 100644 --- a/src/sage/categories/functor.pyx +++ b/src/sage/categories/functor.pyx @@ -117,7 +117,7 @@ cdef class Functor(SageObject): Functor from Category of rings to Category of fields sage: F(ZZ) Rational Field - sage: F(GF(2)) # optional - sage.rings.finite_rings + sage: F(GF(2)) Finite Field of size 2 Functors are not only about the objects of a category, but also about @@ -175,7 +175,7 @@ cdef class Functor(SageObject): Functor from Category of rings to Category of fields sage: F(ZZ) Rational Field - sage: F(GF(2)) # optional - sage.rings.finite_rings + sage: F(GF(2)) Finite Field of size 2 """ @@ -250,14 +250,15 @@ cdef class Functor(SageObject): TESTS:: + sage: # needs sage.rings.finite_rings sage: from sage.categories.functor import Functor sage: F = Functor(Rings(), Fields()) - sage: k. = GF(25) # optional - sage.rings.finite_rings - sage: f = k.hom([-a - 4]) # optional - sage.rings.finite_rings - sage: R. = k[] # optional - sage.rings.finite_rings - sage: fR = R.hom(f, R) # optional - sage.rings.finite_rings - sage: fF = F(fR) # indirect doctest # optional - sage.rings.finite_rings - sage: fF # optional - sage.rings.finite_rings + sage: k. = GF(25) + sage: f = k.hom([-a - 4]) + sage: R. = k[] + sage: fR = R.hom(f, R) + sage: fF = F(fR) # indirect doctest + sage: fF Ring endomorphism of Fraction Field of Univariate Polynomial Ring in t over Finite Field in a of size 5^2 Defn: Induced from base ring by @@ -266,7 +267,7 @@ cdef class Functor(SageObject): Defn: Induced from base ring by Ring endomorphism of Finite Field in a of size 5^2 Defn: a |--> 4*a + 1 - sage: fF((a^2+a)*t^2/(a*t - a^2)) # optional - sage.rings.finite_rings + sage: fF((a^2+a)*t^2/(a*t - a^2)) ((4*a + 2)*t^2)/(t + a + 4) """ try: @@ -338,13 +339,13 @@ cdef class Functor(SageObject): Functor from Category of rings to Category of fields sage: F(ZZ) Rational Field - sage: F(GF(2)) # optional - sage.rings.finite_rings + sage: F(GF(2)) Finite Field of size 2 Two subclasses:: sage: F1 = ForgetfulFunctor(FiniteFields(), Fields()) - sage: F1(GF(5)) # indirect doctest # optional - sage.rings.finite_rings + sage: F1(GF(5)) # indirect doctest Finite Field of size 5 sage: F1(ZZ) Traceback (most recent call last): @@ -372,10 +373,10 @@ cdef class Functor(SageObject): ....: def _apply_functor(self, R): ....: return MatrixSpace(R, self._m, self._n) sage: F = IllFunctor(2, 2) - sage: F(QQ) # optional - sage.modules + sage: F(QQ) # needs sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field sage: F = IllFunctor(2, 3) - sage: F(QQ) # optional - sage.modules + sage: F(QQ) # needs sage.modules Traceback (most recent call last): ... TypeError: Functor from Category of rings to Category of rings @@ -468,7 +469,7 @@ class ForgetfulFunctor_generic(Functor): The forgetful functor from Category of finite enumerated fields to Category of fields - sage: F(GF(3)) # optional - sage.rings.finite_rings + sage: F(GF(3)) Finite Field of size 3 """ diff --git a/src/sage/categories/g_sets.py b/src/sage/categories/g_sets.py index 0f8004ddbf0..5d12a1f5afb 100644 --- a/src/sage/categories/g_sets.py +++ b/src/sage/categories/g_sets.py @@ -23,8 +23,8 @@ class GSets(Category): EXAMPLES:: - sage: S = SymmetricGroup(3) # optional - sage.groups - sage: GSets(S) # optional - sage.groups + sage: S = SymmetricGroup(3) # needs sage.groups + sage: GSets(S) # needs sage.groups Category of G-sets for Symmetric group of order 3! as a permutation group TODO: should this derive from Category_over_base? @@ -33,8 +33,8 @@ def __init__(self, G): """ TESTS:: - sage: S8 = SymmetricGroup(8) # optional - sage.groups - sage: TestSuite(GSets(S8)).run() # optional - sage.groups + sage: S8 = SymmetricGroup(8) # needs sage.groups + sage: TestSuite(GSets(S8)).run() # needs sage.groups """ Category.__init__(self) self.__G = G @@ -43,7 +43,7 @@ def _repr_object_names(self): """ EXAMPLES:: - sage: GSets(SymmetricGroup(8)) # indirect doctests # optional - sage.groups + sage: GSets(SymmetricGroup(8)) # indirect doctests # needs sage.groups Category of G-sets for Symmetric group of order 8! as a permutation group """ return "G-sets for %s"%self.__G @@ -55,7 +55,7 @@ def super_categories(self): """ EXAMPLES:: - sage: GSets(SymmetricGroup(8)).super_categories() # optional - sage.groups + sage: GSets(SymmetricGroup(8)).super_categories() # needs sage.groups [Category of sets] """ return [Sets()] @@ -67,7 +67,7 @@ def an_instance(cls): EXAMPLES:: - sage: GSets.an_instance() # indirect doctest # optional - sage.groups + sage: GSets.an_instance() # indirect doctest # needs sage.groups Category of G-sets for Symmetric group of order 8! as a permutation group """ from sage.groups.perm_gps.permgroup_named import SymmetricGroup diff --git a/src/sage/categories/graded_algebras.py b/src/sage/categories/graded_algebras.py index efa1a501192..190355b59c5 100644 --- a/src/sage/categories/graded_algebras.py +++ b/src/sage/categories/graded_algebras.py @@ -39,8 +39,8 @@ def graded_algebra(self): EXAMPLES:: - sage: m = SymmetricFunctions(QQ).m() # optional - sage.combinat - sage: m.graded_algebra() is m # optional - sage.combinat + sage: m = SymmetricFunctions(QQ).m() # needs sage.combinat sage.modules + sage: m.graded_algebra() is m # needs sage.combinat sage.modules True """ return self diff --git a/src/sage/categories/graded_algebras_with_basis.py b/src/sage/categories/graded_algebras_with_basis.py index 52d80b78b4e..95fcebbb7a7 100644 --- a/src/sage/categories/graded_algebras_with_basis.py +++ b/src/sage/categories/graded_algebras_with_basis.py @@ -46,8 +46,8 @@ def graded_algebra(self): EXAMPLES:: - sage: m = SymmetricFunctions(QQ).m() # optional - sage.combinat - sage: m.graded_algebra() is m # optional - sage.combinat sage.modules + sage: m = SymmetricFunctions(QQ).m() # needs sage.combinat sage.modules + sage: m.graded_algebra() is m # needs sage.combinat sage.modules True TESTS: @@ -57,21 +57,22 @@ def graded_algebra(self): and :meth:`projection` (which form the interface of the associated graded algebra) work correctly here:: - sage: to_gr = m.to_graded_conversion() # optional - sage.combinat sage.modules - sage: from_gr = m.from_graded_conversion() # optional - sage.combinat sage.modules - sage: m[2] == to_gr(m[2]) == from_gr(m[2]) # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: to_gr = m.to_graded_conversion() + sage: from_gr = m.from_graded_conversion() + sage: m[2] == to_gr(m[2]) == from_gr(m[2]) True - sage: u = 3*m[1] - (1/2)*m[3] # optional - sage.combinat sage.modules - sage: u == to_gr(u) == from_gr(u) # optional - sage.combinat sage.modules + sage: u = 3*m[1] - (1/2)*m[3] + sage: u == to_gr(u) == from_gr(u) True - sage: m.zero() == to_gr(m.zero()) == from_gr(m.zero()) # optional - sage.combinat sage.modules + sage: m.zero() == to_gr(m.zero()) == from_gr(m.zero()) True - sage: p2 = m.projection(2) # optional - sage.combinat sage.modules - sage: p2(m[2] - 4*m[1,1] + 3*m[1] - 2*m[[]]) # optional - sage.combinat sage.modules + sage: p2 = m.projection(2) + sage: p2(m[2] - 4*m[1,1] + 3*m[1] - 2*m[[]]) -4*m[1, 1] + m[2] - sage: p2(4*m[1]) # optional - sage.combinat sage.modules + sage: p2(4*m[1]) 0 - sage: p2(m.zero()) == m.zero() # optional - sage.combinat sage.modules + sage: p2(m.zero()) == m.zero() True """ return self @@ -111,13 +112,14 @@ def free_graded_module(self, generator_degrees, names=None): EXAMPLES:: - sage: Q = QuadraticForm(QQ, 3, [1,2,3,4,5,6]) # optional - sage.modules - sage: Cl = CliffordAlgebra(Q) # optional - sage.combinat sage.modules - sage: M = Cl.free_graded_module((0, 2, 3)) # optional - sage.combinat sage.modules - sage: M.gens() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: Q = QuadraticForm(QQ, 3, [1,2,3,4,5,6]) + sage: Cl = CliffordAlgebra(Q) + sage: M = Cl.free_graded_module((0, 2, 3)) + sage: M.gens() (g[0], g[2], g[3]) - sage: N. = Cl.free_graded_module((1, 2)) # optional - sage.combinat sage.modules - sage: N.generators() # optional - sage.combinat sage.modules + sage: N. = Cl.free_graded_module((1, 2)) + sage: N.generators() (xy, z) """ try: @@ -134,10 +136,11 @@ def formal_series_ring(self): EXAMPLES:: - sage: NCSF = NonCommutativeSymmetricFunctions(QQ) # optional - sage.combinat - sage: S = NCSF.Complete() # optional - sage.combinat - sage: L = S.formal_series_ring() # optional - sage.combinat - sage: L # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: NCSF = NonCommutativeSymmetricFunctions(QQ) + sage: S = NCSF.Complete() + sage: L = S.formal_series_ring() + sage: L Lazy completion of Non-Commutative Symmetric Functions over the Rational Field in the Complete basis """ @@ -185,13 +188,14 @@ def one_basis(self): EXAMPLES:: - sage: A. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules - sage: A.one_basis() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: A. = ExteriorAlgebra(QQ) + sage: A.one_basis() 0 - sage: B = tensor((A, A, A)) # optional - sage.combinat sage.modules - sage: B.one_basis() # optional - sage.combinat sage.modules + sage: B = tensor((A, A, A)) + sage: B.one_basis() (0, 0, 0) - sage: B.one() # optional - sage.combinat sage.modules + sage: B.one() 1 # 1 # 1 """ # FIXME: this method should be conditionally defined, @@ -211,10 +215,11 @@ def product_on_basis(self, t0, t1): Test the sign in the super tensor product:: - sage: A = SteenrodAlgebra(3) # optional - sage.combinat sage.modules - sage: x = A.Q(0) # optional - sage.combinat sage.modules - sage: y = x.coproduct() # optional - sage.combinat sage.modules - sage: y^2 # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: A = SteenrodAlgebra(3) + sage: x = A.Q(0) + sage: y = x.coproduct() + sage: y^2 0 TODO: optimize this implementation! diff --git a/src/sage/categories/graded_hopf_algebras_with_basis.py b/src/sage/categories/graded_hopf_algebras_with_basis.py index 204ab23013e..41beadad8a4 100644 --- a/src/sage/categories/graded_hopf_algebras_with_basis.py +++ b/src/sage/categories/graded_hopf_algebras_with_basis.py @@ -44,7 +44,7 @@ def example(self): TESTS:: - sage: GradedHopfAlgebrasWithBasis(QQ).example() # optional - sage.modules + sage: GradedHopfAlgebrasWithBasis(QQ).example() # needs sage.modules An example of a graded connected Hopf algebra with basis over Rational Field """ from sage.categories.examples.graded_connected_hopf_algebras_with_basis import \ @@ -85,7 +85,7 @@ def example(self): TESTS:: - sage: GradedHopfAlgebrasWithBasis(QQ).Connected().example() # optional - sage.modules + sage: GradedHopfAlgebrasWithBasis(QQ).Connected().example() # needs sage.modules An example of a graded connected Hopf algebra with basis over Rational Field """ from sage.categories.examples.graded_connected_hopf_algebras_with_basis import \ @@ -114,10 +114,10 @@ def counit_on_basis(self, i): EXAMPLES:: - sage: H = GradedHopfAlgebrasWithBasis(QQ).Connected().example() # optional - sage.modules - sage: H.monomial(4).counit() # indirect doctest # optional - sage.modules + sage: H = GradedHopfAlgebrasWithBasis(QQ).Connected().example() # needs sage.modules + sage: H.monomial(4).counit() # indirect doctest # needs sage.modules 0 - sage: H.monomial(0).counit() # indirect doctest # optional - sage.modules + sage: H.monomial(0).counit() # indirect doctest # needs sage.modules 1 """ if i == self.one_basis(): @@ -144,14 +144,15 @@ def antipode_on_basis(self, index): TESTS:: - sage: H = GradedHopfAlgebrasWithBasis(QQ).Connected().example() # optional - sage.modules - sage: H.monomial(0).antipode() # indirect doctest # optional - sage.modules + sage: # needs sage.modules + sage: H = GradedHopfAlgebrasWithBasis(QQ).Connected().example() + sage: H.monomial(0).antipode() # indirect doctest P0 - sage: H.monomial(1).antipode() # indirect doctest # optional - sage.modules + sage: H.monomial(1).antipode() # indirect doctest -P1 - sage: H.monomial(2).antipode() # indirect doctest # optional - sage.modules + sage: H.monomial(2).antipode() # indirect doctest P2 - sage: H.monomial(3).antipode() # indirect doctest # optional - sage.modules + sage: H.monomial(3).antipode() # indirect doctest -P3 """ if self.monomial(index) == self.one(): diff --git a/src/sage/categories/graded_lie_conformal_algebras.py b/src/sage/categories/graded_lie_conformal_algebras.py index 2650492898d..a17c067ae4e 100644 --- a/src/sage/categories/graded_lie_conformal_algebras.py +++ b/src/sage/categories/graded_lie_conformal_algebras.py @@ -31,11 +31,12 @@ def Super(self, base_ring=None): EXAMPLES:: - sage: C = LieConformalAlgebras(QQbar) # optional - sage.rings.number_field - sage: C.Graded().Super() is C.Super().Graded() # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + sage: C = LieConformalAlgebras(QQbar) + sage: C.Graded().Super() is C.Super().Graded() True - sage: Cp = C.WithBasis() # optional - sage.rings.number_field - sage: Cp.Graded().Super() is Cp.Super().Graded() # optional - sage.rings.number_field + sage: Cp = C.WithBasis() + sage: Cp.Graded().Super() is Cp.Super().Graded() True """ return self.base_category().Super(base_ring).Graded() @@ -46,10 +47,10 @@ def _repr_object_names(self): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).Graded() # optional - sage.rings.number_field + sage: LieConformalAlgebras(QQbar).Graded() # needs sage.rings.number_field Category of H-graded Lie conformal algebras over Algebraic Field - sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() # optional - sage.rings.number_field + sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() # needs sage.rings.number_field Category of H-graded finitely generated Lie conformal algebras with basis over Algebraic Field """ return "H-graded {}".format(self.base_category()._repr_object_names()) @@ -60,7 +61,7 @@ class GradedLieConformalAlgebras(GradedLieConformalAlgebrasCategory): EXAMPLES:: - sage: C = LieConformalAlgebras(QQbar).Graded(); C # optional - sage.rings.number_field + sage: C = LieConformalAlgebras(QQbar).Graded(); C # needs sage.rings.number_field Category of H-graded Lie conformal algebras over Algebraic Field sage: CS = LieConformalAlgebras(QQ).Graded().Super(); CS diff --git a/src/sage/categories/graded_modules_with_basis.py b/src/sage/categories/graded_modules_with_basis.py index b1185e20352..c813b05e2ec 100644 --- a/src/sage/categories/graded_modules_with_basis.py +++ b/src/sage/categories/graded_modules_with_basis.py @@ -46,18 +46,18 @@ def degree_negation(self, element): EXAMPLES:: - sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules - sage: E.degree_negation((1 + a) * (1 + b)) # optional - sage.combinat sage.modules + sage: E. = ExteriorAlgebra(QQ) # needs sage.modules + sage: E.degree_negation((1 + a) * (1 + b)) # needs sage.modules a*b - a - b + 1 - sage: E.degree_negation(E.zero()) # optional - sage.combinat sage.modules + sage: E.degree_negation(E.zero()) # needs sage.modules 0 - sage: P = GradedModulesWithBasis(ZZ).example(); P # optional - sage.combinat sage.modules + sage: P = GradedModulesWithBasis(ZZ).example(); P # needs sage.combinat sage.modules An example of a graded module with basis: the free module on partitions over Integer Ring - sage: pbp = lambda x: P.basis()[Partition(list(x))] # optional - sage.combinat sage.modules - sage: p = pbp([3,1]) - 2 * pbp([2]) + 4 * pbp([1]) # optional - sage.combinat sage.modules - sage: P.degree_negation(p) # optional - sage.combinat sage.modules + sage: pbp = lambda x: P.basis()[Partition(list(x))] + sage: p = pbp([3,1]) - 2 * pbp([2]) + 4 * pbp([1]) # needs sage.combinat sage.modules + sage: P.degree_negation(p) # needs sage.combinat sage.modules -4*P[1] - 2*P[2] + P[3, 1] """ base_one = self.base_ring().one() @@ -115,22 +115,23 @@ def submodule(self, gens, check=True, already_echelonized=False, A graded submodule of a graded module generated by homogeneous elements is naturally graded:: - sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules - sage: S = E.submodule([x + y, x*y - y*z]) # optional - sage.combinat sage.modules - sage: S.category() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: E. = ExteriorAlgebra(QQ) + sage: S = E.submodule([x + y, x*y - y*z]) + sage: S.category() Join of Category of graded vector spaces with basis over Rational Field and Category of subobjects of filtered modules with basis over Rational Field and Category of finite dimensional vector spaces with basis over Rational Field - sage: S.basis()[0].degree() # optional - sage.combinat sage.modules + sage: S.basis()[0].degree() 1 - sage: S.basis()[1].degree() # optional - sage.combinat sage.modules + sage: S.basis()[1].degree() 2 We check on the echelonized basis:: - sage: Sp = E.submodule([1, x + y + 5, x*y - y*z + x + y - 2]) # optional - sage.combinat sage.modules - sage: Sp.category() # optional - sage.combinat sage.modules + sage: Sp = E.submodule([1, x + y + 5, x*y - y*z + x + y - 2]) # needs sage.combinat sage.modules + sage: Sp.category() # needs sage.combinat sage.modules Join of Category of graded vector spaces with basis over Rational Field and Category of subobjects of filtered modules with basis over Rational Field and @@ -139,8 +140,8 @@ def submodule(self, gens, check=True, already_echelonized=False, If it is generated by inhomogeneous elements, then it is filtered by default:: - sage: F = E.submodule([x + y*z, x*z + y*x]) # optional - sage.combinat sage.modules - sage: F.category() # optional - sage.combinat sage.modules + sage: F = E.submodule([x + y*z, x*z + y*x]) # needs sage.combinat sage.modules + sage: F.category() # needs sage.combinat sage.modules Join of Category of subobjects of filtered modules with basis over Rational Field and Category of filtered vector spaces with basis over Rational Field and @@ -150,15 +151,16 @@ def submodule(self, gens, check=True, already_echelonized=False, structure to the submodule (we can think of this as applying the forgetful functor):: - sage: SM = E.submodule([x + y, x*y - y*z], # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: SM = E.submodule([x + y, x*y - y*z], ....: category=ModulesWithBasis(QQ)) - sage: SM.category() # optional - sage.combinat sage.modules + sage: SM.category() Join of Category of finite dimensional vector spaces with basis over Rational Field and Category of subobjects of sets - sage: FM = E.submodule([x + 1, x*y - x*y*z], # optional - sage.combinat sage.modules + sage: FM = E.submodule([x + 1, x*y - x*y*z], ....: category=ModulesWithBasis(QQ)) - sage: FM.category() # optional - sage.combinat sage.modules + sage: FM.category() Join of Category of finite dimensional vector spaces with basis over Rational Field and Category of subobjects of sets @@ -167,11 +169,11 @@ def submodule(self, gens, check=True, already_echelonized=False, module, then the echelonized elements must be homogeneous:: sage: Cat = ModulesWithBasis(QQ).Graded().Subobjects() - sage: E.submodule([x + y, x*y - 1], category=Cat) # optional - sage.combinat sage.modules + sage: E.submodule([x + y, x*y - 1], category=Cat) # needs sage.combinat sage.modules Traceback (most recent call last): ... ValueError: all of the generators must be homogeneous - sage: E.submodule([x + y, x*y - x - y], category=Cat) # optional - sage.combinat sage.modules + sage: E.submodule([x + y, x*y - x - y], category=Cat) # needs sage.combinat sage.modules Free module generated by {0, 1} over Rational Field """ # Make sure gens consists of elements of ``self`` @@ -223,10 +225,11 @@ def quotient_module(self, submodule, check=True, already_echelonized=False, cate EXAMPLES:: - sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules - sage: S = E.submodule([x + y, x*y - y*z, y]) # optional - sage.combinat sage.modules - sage: Q = E.quotient_module(S) # optional - sage.combinat sage.modules - sage: Q.category() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: E. = ExteriorAlgebra(QQ) + sage: S = E.submodule([x + y, x*y - y*z, y]) + sage: Q = E.quotient_module(S) + sage: Q.category() Join of Category of quotients of graded modules with basis over Rational Field and Category of graded vector spaces with basis over Rational Field and @@ -267,18 +270,18 @@ def degree_negation(self): EXAMPLES:: - sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules - sage: ((1 + a) * (1 + b)).degree_negation() # optional - sage.combinat sage.modules + sage: E. = ExteriorAlgebra(QQ) # needs sage.modules + sage: ((1 + a) * (1 + b)).degree_negation() # needs sage.modules a*b - a - b + 1 - sage: E.zero().degree_negation() # optional - sage.combinat sage.modules + sage: E.zero().degree_negation() # needs sage.modules 0 - sage: P = GradedModulesWithBasis(ZZ).example(); P # optional - sage.combinat sage.modules + sage: P = GradedModulesWithBasis(ZZ).example(); P # needs sage.combinat sage.modules An example of a graded module with basis: the free module on partitions over Integer Ring - sage: pbp = lambda x: P.basis()[Partition(list(x))] # optional - sage.combinat sage.modules - sage: p = pbp([3,1]) - 2 * pbp([2]) + 4 * pbp([1]) # optional - sage.combinat sage.modules - sage: p.degree_negation() # optional - sage.combinat sage.modules + sage: pbp = lambda x: P.basis()[Partition(list(x))] + sage: p = pbp([3,1]) - 2 * pbp([2]) + 4 * pbp([1]) # needs sage.combinat sage.modules + sage: p.degree_negation() # needs sage.combinat sage.modules -4*P[1] - 2*P[2] + P[3, 1] """ return self.parent().degree_negation(self) @@ -292,13 +295,14 @@ def degree_on_basis(self, m): EXAMPLES:: - sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules - sage: S = E.submodule([x + y, x*y - y*z, y]) # optional - sage.combinat sage.modules - sage: Q = E.quotient_module(S) # optional - sage.combinat sage.modules - sage: B = Q.basis() # optional - sage.combinat sage.modules - sage: [B[i].lift() for i in Q.indices()] # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: E. = ExteriorAlgebra(QQ) + sage: S = E.submodule([x + y, x*y - y*z, y]) + sage: Q = E.quotient_module(S) + sage: B = Q.basis() + sage: [B[i].lift() for i in Q.indices()] [1, z, x*z, y*z, x*y*z] - sage: [Q.degree_on_basis(i) for i in Q.indices()] # optional - sage.combinat sage.modules + sage: [Q.degree_on_basis(i) for i in Q.indices()] [0, 1, 2, 2, 3] """ return self.basis()[m].lift().degree() @@ -310,13 +314,14 @@ def degree(self): EXAMPLES:: - sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules - sage: S = E.submodule([x + y, x*y - y*z, y]) # optional - sage.combinat sage.modules - sage: Q = E.quotient_module(S) # optional - sage.combinat sage.modules - sage: B = Q.basis() # optional - sage.combinat sage.modules - sage: [B[i].lift() for i in Q.indices()] # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: E. = ExteriorAlgebra(QQ) + sage: S = E.submodule([x + y, x*y - y*z, y]) + sage: Q = E.quotient_module(S) + sage: B = Q.basis() + sage: [B[i].lift() for i in Q.indices()] [1, z, x*z, y*z, x*y*z] - sage: [B[i].degree() for i in Q.indices()] # optional - sage.combinat sage.modules + sage: [B[i].degree() for i in Q.indices()] [0, 1, 2, 2, 3] """ return self.lift().degree() diff --git a/src/sage/categories/group_algebras.py b/src/sage/categories/group_algebras.py index 36c7e069f34..1f68c28c3b4 100644 --- a/src/sage/categories/group_algebras.py +++ b/src/sage/categories/group_algebras.py @@ -50,16 +50,16 @@ class GroupAlgebras(AlgebrasCategory): Here is how to create the group algebra of a group `G`:: - sage: G = DihedralGroup(5) # optional - sage.groups - sage: QG = G.algebra(QQ); QG # optional - sage.groups sage.modules + sage: G = DihedralGroup(5) # needs sage.groups + sage: QG = G.algebra(QQ); QG # needs sage.groups sage.modules Algebra of Dihedral group of order 10 as a permutation group over Rational Field and an example of computation:: - sage: g = G.an_element(); g # optional - sage.groups sage.modules + sage: g = G.an_element(); g # needs sage.groups sage.modules (1,4)(2,3) - sage: (QG.term(g) + 1)**3 # optional - sage.groups sage.modules + sage: (QG.term(g) + 1)**3 # needs sage.groups sage.modules 4*() + 4*(1,4)(2,3) .. TODO:: @@ -69,14 +69,15 @@ class GroupAlgebras(AlgebrasCategory): TESTS:: - sage: A = GroupAlgebras(QQ).example(GL(3, GF(11))) # optional - sage.groups sage.modules sage.rings.finite_rings - sage: A.one_basis() # optional - sage.groups sage.modules sage.rings.finite_rings + sage: # needs sage.groups sage.modules + sage: A = GroupAlgebras(QQ).example(GL(3, GF(11))) + sage: A.one_basis() [1 0 0] [0 1 0] [0 0 1] - sage: A = SymmetricGroupAlgebra(QQ, 4) # optional - sage.groups sage.modules sage.combinat - sage: x = Permutation([4,3,2,1]) # optional - sage.groups sage.modules sage.combinat - sage: A.product_on_basis(x, x) # optional - sage.groups sage.modules sage.combinat + sage: A = SymmetricGroupAlgebra(QQ, 4) # needs sage.combinat + sage: x = Permutation([4,3,2,1]) + sage: A.product_on_basis(x, x) # needs sage.combinat [1, 2, 3, 4] sage: C = GroupAlgebras(ZZ) @@ -105,13 +106,13 @@ def example(self, G=None): EXAMPLES:: - sage: GroupAlgebras(QQ['x']).example() # optional - sage.groups sage.modules + sage: GroupAlgebras(QQ['x']).example() # needs sage.groups sage.modules Algebra of Dihedral group of order 8 as a permutation group over Univariate Polynomial Ring in x over Rational Field An other group can be specified as optional argument:: - sage: GroupAlgebras(QQ).example(AlternatingGroup(4)) # optional - sage.groups sage.modules + sage: GroupAlgebras(QQ).example(AlternatingGroup(4)) # needs sage.groups sage.modules Algebra of Alternating group of order 4!/2 as a permutation group over Rational Field """ @@ -127,19 +128,20 @@ def __init_extra__(self): EXAMPLES:: - sage: A = GroupAlgebra(SymmetricGroup(4), QQ) # optional - sage.groups sage.modules - sage: B = GroupAlgebra(SymmetricGroup(3), ZZ) # optional - sage.groups sage.modules - sage: A.has_coerce_map_from(B) # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: A = GroupAlgebra(SymmetricGroup(4), QQ) + sage: B = GroupAlgebra(SymmetricGroup(3), ZZ) + sage: A.has_coerce_map_from(B) True - sage: B.has_coerce_map_from(A) # optional - sage.groups sage.modules + sage: B.has_coerce_map_from(A) False - sage: A.has_coerce_map_from(ZZ) # optional - sage.groups sage.modules + sage: A.has_coerce_map_from(ZZ) True - sage: A.has_coerce_map_from(CC) # optional - sage.groups sage.modules + sage: A.has_coerce_map_from(CC) False - sage: A.has_coerce_map_from(SymmetricGroup(5)) # optional - sage.groups sage.modules + sage: A.has_coerce_map_from(SymmetricGroup(5)) False - sage: A.has_coerce_map_from(SymmetricGroup(2)) # optional - sage.groups sage.modules + sage: A.has_coerce_map_from(SymmetricGroup(2)) True """ if not self.base_ring().has_coerce_map_from(self.group()): @@ -155,8 +157,8 @@ def _latex_(self): EXAMPLES:: - sage: A = GroupAlgebra(KleinFourGroup(), ZZ) # optional - sage.groups sage.modules - sage: latex(A) # indirect doctest # optional - sage.groups sage.modules + sage: A = GroupAlgebra(KleinFourGroup(), ZZ) # needs sage.groups sage.modules + sage: latex(A) # indirect doctest # needs sage.groups sage.modules \Bold{Z}[\langle (3,4), (1,2) \rangle] """ from sage.misc.latex import latex @@ -168,9 +170,9 @@ def group(self): EXAMPLES:: - sage: GroupAlgebras(QQ).example(GL(3, GF(11))).group() # optional - sage.groups sage.modules sage.rings.finite_rings + sage: GroupAlgebras(QQ).example(GL(3, GF(11))).group() # needs sage.groups sage.modules General Linear Group of degree 3 over Finite Field of size 11 - sage: SymmetricGroup(10).algebra(QQ).group() # optional - sage.groups sage.modules + sage: SymmetricGroup(10).algebra(QQ).group() # needs sage.groups sage.modules Symmetric group of order 10! as a permutation group """ return self.basis().keys() @@ -198,7 +200,7 @@ def center_basis(self): EXAMPLES:: - sage: SymmetricGroup(3).algebra(QQ).center_basis() # optional - sage.groups sage.modules + sage: SymmetricGroup(3).algebra(QQ).center_basis() # needs sage.groups sage.modules ((), (2,3) + (1,2) + (1,3), (1,2,3) + (1,3,2)) .. SEEALSO:: @@ -220,16 +222,17 @@ def coproduct_on_basis(self, g): EXAMPLES:: - sage: A = CyclicPermutationGroup(6).algebra(ZZ); A # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: A = CyclicPermutationGroup(6).algebra(ZZ); A Algebra of Cyclic group of order 6 as a permutation group over Integer Ring - sage: g = CyclicPermutationGroup(6).an_element(); g # optional - sage.groups sage.modules + sage: g = CyclicPermutationGroup(6).an_element(); g (1,2,3,4,5,6) - sage: A.coproduct_on_basis(g) # optional - sage.groups sage.modules + sage: A.coproduct_on_basis(g) (1,2,3,4,5,6) # (1,2,3,4,5,6) - sage: a = A.an_element(); a # optional - sage.groups sage.modules + sage: a = A.an_element(); a () + 3*(1,2,3,4,5,6) + 3*(1,3,5)(2,4,6) - sage: a.coproduct() # optional - sage.groups sage.modules + sage: a.coproduct() () # () + 3*(1,2,3,4,5,6) # (1,2,3,4,5,6) + 3*(1,3,5)(2,4,6) # (1,3,5)(2,4,6) """ from sage.categories.tensor import tensor @@ -246,16 +249,17 @@ def antipode_on_basis(self,g): EXAMPLES:: - sage: A = CyclicPermutationGroup(6).algebra(ZZ); A # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: A = CyclicPermutationGroup(6).algebra(ZZ); A Algebra of Cyclic group of order 6 as a permutation group over Integer Ring - sage: g = CyclicPermutationGroup(6).an_element(); g # optional - sage.groups sage.modules + sage: g = CyclicPermutationGroup(6).an_element(); g (1,2,3,4,5,6) - sage: A.antipode_on_basis(g) # optional - sage.groups sage.modules + sage: A.antipode_on_basis(g) (1,6,5,4,3,2) - sage: a = A.an_element(); a # optional - sage.groups sage.modules + sage: a = A.an_element(); a () + 3*(1,2,3,4,5,6) + 3*(1,3,5)(2,4,6) - sage: a.antipode() # optional - sage.groups sage.modules + sage: a.antipode() () + 3*(1,5,3)(2,6,4) + 3*(1,6,5,4,3,2) """ return self.term(~g) @@ -270,12 +274,12 @@ def counit_on_basis(self,g): EXAMPLES:: - sage: A = CyclicPermutationGroup(6).algebra(ZZ); A # optional - sage.groups sage.modules + sage: A = CyclicPermutationGroup(6).algebra(ZZ); A # needs sage.groups sage.modules Algebra of Cyclic group of order 6 as a permutation group over Integer Ring - sage: g = CyclicPermutationGroup(6).an_element(); g # optional - sage.groups sage.modules + sage: g = CyclicPermutationGroup(6).an_element(); g # needs sage.groups sage.modules (1,2,3,4,5,6) - sage: A.counit_on_basis(g) # optional - sage.groups sage.modules + sage: A.counit_on_basis(g) # needs sage.groups sage.modules 1 """ return self.base_ring().one() @@ -290,12 +294,12 @@ def counit(self,x): EXAMPLES:: - sage: A = CyclicPermutationGroup(6).algebra(ZZ); A # optional - sage.groups sage.modules + sage: A = CyclicPermutationGroup(6).algebra(ZZ); A # needs sage.groups sage.modules Algebra of Cyclic group of order 6 as a permutation group over Integer Ring - sage: a = A.an_element(); a # optional - sage.groups sage.modules + sage: a = A.an_element(); a # needs sage.groups sage.modules () + 3*(1,2,3,4,5,6) + 3*(1,3,5)(2,4,6) - sage: a.counit() # optional - sage.groups sage.modules + sage: a.counit() # needs sage.groups sage.modules 7 """ return self.base_ring().sum(x.coefficients()) @@ -312,19 +316,20 @@ def is_integral_domain(self, proof=True): EXAMPLES:: - sage: S2 = SymmetricGroup(2) # optional - sage.groups - sage: GroupAlgebra(S2).is_integral_domain() # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: S2 = SymmetricGroup(2) + sage: GroupAlgebra(S2).is_integral_domain() False - sage: S1 = SymmetricGroup(1) # optional - sage.groups - sage: GroupAlgebra(S1).is_integral_domain() # optional - sage.groups sage.modules + sage: S1 = SymmetricGroup(1) + sage: GroupAlgebra(S1).is_integral_domain() True - sage: GroupAlgebra(S1, IntegerModRing(4)).is_integral_domain() # optional - sage.groups sage.modules + sage: GroupAlgebra(S1, IntegerModRing(4)).is_integral_domain() False - sage: GroupAlgebra(AbelianGroup(1)).is_integral_domain() # optional - sage.groups sage.modules + sage: GroupAlgebra(AbelianGroup(1)).is_integral_domain() True - sage: GroupAlgebra(AbelianGroup(2, [0,2])).is_integral_domain() # optional - sage.groups sage.modules + sage: GroupAlgebra(AbelianGroup(2, [0,2])).is_integral_domain() False - sage: GroupAlgebra(GL(2, ZZ)).is_integral_domain() # not implemented # optional - sage.groups sage.modules + sage: GroupAlgebra(GL(2, ZZ)).is_integral_domain() # not implemented False """ from sage.sets.set import Set @@ -394,22 +399,24 @@ def central_form(self): EXAMPLES:: - sage: QS3 = SymmetricGroup(3).algebra(QQ) # optional - sage.groups sage.modules - sage: A = QS3([2,3,1]) + QS3([3,1,2]) # optional - sage.groups sage.modules - sage: A.central_form() # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: QS3 = SymmetricGroup(3).algebra(QQ) + sage: A = QS3([2,3,1]) + QS3([3,1,2]) + sage: A.central_form() B[(1,2,3)] - sage: QS4 = SymmetricGroup(4).algebra(QQ) # optional - sage.groups sage.modules - sage: B = sum(len(s.cycle_type()) * QS4(s) for s in Permutations(4)) # optional - sage.groups sage.modules - sage: B.central_form() # optional - sage.groups sage.modules + sage: QS4 = SymmetricGroup(4).algebra(QQ) + sage: B = sum(len(s.cycle_type()) * QS4(s) for s in Permutations(4)) + sage: B.central_form() 4*B[()] + 3*B[(1,2)] + 2*B[(1,2)(3,4)] + 2*B[(1,2,3)] + B[(1,2,3,4)] The following test fails due to a bug involving combinatorial free modules and the coercion system (see :trac:`28544`):: - sage: G = PermutationGroup([[(1,2,3),(4,5)], [(3,4)]]) # optional - sage.groups sage.modules - sage: QG = GroupAlgebras(QQ).example(G) # optional - sage.groups sage.modules - sage: s = sum(QG.basis()) # optional - sage.groups sage.modules - sage: s.central_form() # not tested # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: G = PermutationGroup([[(1,2,3),(4,5)], [(3,4)]]) + sage: QG = GroupAlgebras(QQ).example(G) + sage: s = sum(QG.basis()) + sage: s.central_form() # not tested B[()] + B[(4,5)] + B[(3,4,5)] + B[(2,3)(4,5)] + B[(2,3,4,5)] + B[(1,2)(3,4,5)] + B[(1,2,3,4,5)] diff --git a/src/sage/categories/groupoid.py b/src/sage/categories/groupoid.py index 9eee3750655..1f7030ab2f6 100644 --- a/src/sage/categories/groupoid.py +++ b/src/sage/categories/groupoid.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.groups +# sage.doctest: needs sage.groups r""" Groupoid """ diff --git a/src/sage/categories/groups.py b/src/sage/categories/groups.py index 569cfc0d36d..e94869cfe1c 100644 --- a/src/sage/categories/groups.py +++ b/src/sage/categories/groups.py @@ -42,7 +42,7 @@ def example(self): """ EXAMPLES:: - sage: Groups().example() # optional - sage.groups + sage: Groups().example() # needs sage.modules General Linear Group of degree 4 over Rational Field """ from sage.rings.rational_field import QQ @@ -69,13 +69,14 @@ def free(index_set=None, names=None, **kwds): EXAMPLES:: - sage: Groups.free(index_set=ZZ) # optional - sage.groups + sage: # needs sage.groups + sage: Groups.free(index_set=ZZ) Free group indexed by Integer Ring - sage: Groups().free(ZZ) # optional - sage.groups + sage: Groups().free(ZZ) Free group indexed by Integer Ring - sage: Groups().free(5) # optional - sage.groups + sage: Groups().free(5) Free Group on generators {x0, x1, x2, x3, x4} - sage: F. = Groups().free(); F # optional - sage.groups + sage: F. = Groups().free(); F Free Group on generators {x, y, z} """ from sage.rings.integer_ring import ZZ @@ -99,8 +100,8 @@ def group_generators(self): EXAMPLES:: - sage: A = AlternatingGroup(4) # optional - sage.groups - sage: A.group_generators() # optional - sage.groups + sage: A = AlternatingGroup(4) # needs sage.groups + sage: A.group_generators() # needs sage.groups Family ((2,3,4), (1,2,3)) """ from sage.sets.family import Family @@ -120,11 +121,12 @@ def monoid_generators(self): EXAMPLES:: - sage: A = AlternatingGroup(4) # optional - sage.groups - sage: A.monoid_generators() # optional - sage.groups + sage: # needs sage.groups + sage: A = AlternatingGroup(4) + sage: A.monoid_generators() Family ((2,3,4), (1,2,3)) - sage: F. = FreeGroup() # optional - sage.groups - sage: F.monoid_generators() # optional - sage.groups + sage: F. = FreeGroup() + sage: F.monoid_generators() Family (x, y, x^-1, y^-1) """ G = self.group_generators() @@ -142,8 +144,8 @@ def _test_inverse(self, **options): EXAMPLES:: - sage: G = SymmetricGroup(3) # optional - sage.groups - sage: G._test_inverse() # optional - sage.groups + sage: G = SymmetricGroup(3) # needs sage.groups + sage: G._test_inverse() # needs sage.groups """ tester = self._tester(**options) for x in tester.some_elements(): @@ -156,8 +158,8 @@ def semidirect_product(self, N, mapping, check=True): EXAMPLES:: - sage: G = Groups().example() # optional - sage.groups - sage: G.semidirect_product(G, Morphism(G, G)) # optional - sage.groups + sage: G = Groups().example() # needs sage.modules + sage: G.semidirect_product(G, Morphism(G, G)) # needs sage.modules Traceback (most recent call last): ... NotImplementedError: semidirect product of General Linear Group of degree 4 @@ -178,8 +180,8 @@ def holomorph(self): EXAMPLES:: - sage: G = Groups().example() # optional - sage.groups - sage: G.holomorph() # optional - sage.groups + sage: G = Groups().example() # needs sage.modules + sage: G.holomorph() # needs sage.modules Traceback (most recent call last): ... NotImplementedError: holomorph of General Linear Group of degree 4 @@ -246,11 +248,12 @@ def cayley_table(self, names='letters', elements=None): Permutation groups, matrix groups and abelian groups can all compute their multiplication tables. :: - sage: G = DiCyclicGroup(3) # optional - sage.groups - sage: T = G.cayley_table() # optional - sage.groups - sage: T.column_keys() # optional - sage.groups + sage: # needs sage.groups + sage: G = DiCyclicGroup(3) + sage: T = G.cayley_table() + sage: T.column_keys() ((), (5,6,7), ..., (1,4,2,3)(5,7)) - sage: T # optional - sage.groups + sage: T * a b c d e f g h i j k l +------------------------ a| a b c d e f g h i j k l @@ -268,8 +271,8 @@ def cayley_table(self, names='letters', elements=None): :: - sage: M = SL(2, 2) # optional - sage.groups - sage: M.cayley_table() # optional - sage.groups + sage: M = SL(2, 2) # needs sage.modules + sage: M.cayley_table() # needs sage.modules * a b c d e f +------------ a| a b c d e f @@ -282,8 +285,8 @@ def cayley_table(self, names='letters', elements=None): :: - sage: A = AbelianGroup([2, 3]) # optional - sage.groups - sage: A.cayley_table() # optional - sage.groups + sage: A = AbelianGroup([2, 3]) # needs sage.groups + sage: A.cayley_table() # needs sage.groups * a b c d e f +------------ a| a b c d e f @@ -301,8 +304,8 @@ def cayley_table(self, names='letters', elements=None): you can choose to just use the string representations of the elements themselves. :: - sage: C = CyclicPermutationGroup(11) # optional - sage.groups - sage: C.cayley_table(names='digits') # optional - sage.groups + sage: C = CyclicPermutationGroup(11) # needs sage.groups + sage: C.cayley_table(names='digits') # needs sage.groups * 00 01 02 03 04 05 06 07 08 09 10 +--------------------------------- 00| 00 01 02 03 04 05 06 07 08 09 10 @@ -319,9 +322,9 @@ def cayley_table(self, names='letters', elements=None): :: - sage: G = QuaternionGroup() # optional - sage.groups - sage: names = ['1', 'I', '-1', '-I', 'J', '-K', '-J', 'K'] # optional - sage.groups - sage: G.cayley_table(names=names) # optional - sage.groups + sage: G = QuaternionGroup() # needs sage.groups + sage: names = ['1', 'I', '-1', '-I', 'J', '-K', '-J', 'K'] + sage: G.cayley_table(names=names) # needs sage.groups * 1 I -1 -I J -K -J K +------------------------ 1| 1 I -1 -I J -K -J K @@ -335,8 +338,8 @@ def cayley_table(self, names='letters', elements=None): :: - sage: A = AbelianGroup([2, 2]) # optional - sage.groups - sage: A.cayley_table(names='elements') # optional - sage.groups + sage: A = AbelianGroup([2, 2]) # needs sage.groups + sage: A.cayley_table(names='elements') # needs sage.groups * 1 f1 f0 f0*f1 +------------------------ 1| 1 f1 f0 f0*f1 @@ -348,10 +351,11 @@ def cayley_table(self, names='letters', elements=None): routine behaves similarly, but changes an existing table "in-place." :: - sage: G = AlternatingGroup(3) # optional - sage.groups - sage: T = G.cayley_table() # optional - sage.groups - sage: T.change_names('digits') # optional - sage.groups - sage: T # optional - sage.groups + sage: # needs sage.groups + sage: G = AlternatingGroup(3) + sage: T = G.cayley_table() + sage: T.change_names('digits') + sage: T * 0 1 2 +------ 0| 0 1 2 @@ -363,11 +367,11 @@ def cayley_table(self, names='letters', elements=None): Elements will be coerced into the group as part of setting up the table. :: - sage: G = SL(2,ZZ) # optional - sage.groups - sage: G # optional - sage.groups + sage: # needs sage.modules + sage: G = SL(2,ZZ); G Special Linear Group of degree 2 over Integer Ring - sage: identity = matrix(ZZ, [[1,0], [0,1]]) # optional - sage.groups - sage: G.cayley_table(elements=[identity, -identity]) # optional - sage.groups + sage: identity = matrix(ZZ, [[1,0], [0,1]]) + sage: G.cayley_table(elements=[identity, -identity]) * a b +---- a| a b @@ -384,11 +388,11 @@ class provides even greater flexibility, including changing confirms that they form a closed subset in the group. :: - sage: from sage.matrix.operation_table import OperationTable # optional - sage.groups - sage: G = DiCyclicGroup(3) # optional - sage.groups - sage: commutator = lambda x, y: x*y*x^-1*y^-1 # optional - sage.groups - sage: T = OperationTable(G, commutator) # optional - sage.groups - sage: T # optional - sage.groups + sage: # needs sage.groups sage.modules + sage: from sage.matrix.operation_table import OperationTable + sage: G = DiCyclicGroup(3) + sage: commutator = lambda x, y: x*y*x^-1*y^-1 + sage: T = OperationTable(G, commutator); T . a b c d e f g h i j k l +------------------------ a| a a a a a a a a a a a a @@ -403,13 +407,12 @@ class provides even greater flexibility, including changing j| a b c a b c a c b a c b k| a b c a b c b a c b a c l| a b c a b c c b a c b a - - sage: trans = T.translation() # optional - sage.groups - sage: comm = [trans['a'], trans['b'], trans['c']] # optional - sage.groups - sage: comm # optional - sage.groups + sage: trans = T.translation() + sage: comm = [trans['a'], trans['b'], trans['c']] + sage: comm [(), (5,6,7), (5,7,6)] - sage: P = G.cayley_table(elements=comm) # optional - sage.groups - sage: P # optional - sage.groups + sage: P = G.cayley_table(elements=comm) + sage: P * a b c +------ a| a b c @@ -440,9 +443,9 @@ def conjugacy_class(self, g): EXAMPLES:: - sage: A = AbelianGroup([2, 2]) # optional - sage.groups - sage: c = A.conjugacy_class(A.an_element()) # optional - sage.groups - sage: type(c) # optional - sage.groups + sage: A = AbelianGroup([2, 2]) # needs sage.groups + sage: c = A.conjugacy_class(A.an_element()) # needs sage.groups + sage: type(c) # needs sage.groups """ from sage.groups.conjugacy_classes import ConjugacyClass @@ -455,16 +458,16 @@ def conjugacy_class(self): EXAMPLES:: - sage: D = DihedralGroup(5) # optional - sage.groups - sage: g = D((1,3,5,2,4)) # optional - sage.groups - sage: g.conjugacy_class() # optional - sage.groups + sage: D = DihedralGroup(5) # needs sage.groups + sage: g = D((1,3,5,2,4)) # needs sage.groups + sage: g.conjugacy_class() # needs sage.groups Conjugacy class of (1,3,5,2,4) in Dihedral group of order 10 as a permutation group - sage: H = MatrixGroup([matrix(GF(5), 2, [1,2, -1,1]), # optional - sage.groups sage.rings.finite_rings sage.modules + sage: H = MatrixGroup([matrix(GF(5), 2, [1,2, -1,1]), # needs sage.modules ....: matrix(GF(5), 2, [1,1, 0,1])]) - sage: h = H(matrix(GF(5), 2, [1,2, -1,1])) # optional - sage.groups sage.rings.finite_rings sage.modules - sage: h.conjugacy_class() # optional - sage.groups sage.rings.finite_rings sage.modules + sage: h = H(matrix(GF(5), 2, [1,2, -1,1])) # needs sage.modules + sage: h.conjugacy_class() # needs sage.groups sage.modules Conjugacy class of [1 2] [4 1] in Matrix group over Finite Field of size 5 with 2 generators ( @@ -472,15 +475,15 @@ def conjugacy_class(self): [4 1], [0 1] ) - sage: G = SL(2, GF(2)) # optional - sage.groups sage.rings.finite_rings sage.modules - sage: g = G.gens()[0] # optional - sage.groups sage.rings.finite_rings sage.modules - sage: g.conjugacy_class() # optional - sage.groups sage.rings.finite_rings sage.modules + sage: G = SL(2, GF(2)) # needs sage.modules + sage: g = G.gens()[0] # needs sage.modules + sage: g.conjugacy_class() # needs sage.modules Conjugacy class of [1 1] [0 1] in Special Linear Group of degree 2 over Finite Field of size 2 - sage: G = SL(2, QQ) # optional - sage.groups sage.modules - sage: g = G([[1,1], [0,1]]) # optional - sage.groups sage.modules - sage: g.conjugacy_class() # optional - sage.groups sage.modules + sage: G = SL(2, QQ) # needs sage.modules + sage: g = G([[1,1], [0,1]]) # needs sage.modules + sage: g.conjugacy_class() # needs sage.groups sage.modules Conjugacy class of [1 1] [0 1] in Special Linear Group of degree 2 over Rational Field """ @@ -511,13 +514,14 @@ def free(index_set=None, names=None, **kwds): EXAMPLES:: - sage: Groups.Commutative.free(index_set=ZZ) # optional - sage.groups + sage: # needs sage.groups + sage: Groups.Commutative.free(index_set=ZZ) Free abelian group indexed by Integer Ring - sage: Groups().Commutative().free(ZZ) # optional - sage.groups + sage: Groups().Commutative().free(ZZ) Free abelian group indexed by Integer Ring - sage: Groups().Commutative().free(5) # optional - sage.groups + sage: Groups().Commutative().free(5) Multiplicative Abelian group isomorphic to Z x Z x Z x Z x Z - sage: F. = Groups().Commutative().free(); F # optional - sage.groups + sage: F. = Groups().Commutative().free(); F Multiplicative Abelian group isomorphic to Z x Z x Z """ from sage.rings.integer_ring import ZZ @@ -574,11 +578,12 @@ def group_generators(self): EXAMPLES:: - sage: C5 = CyclicPermutationGroup(5) # optional - sage.groups - sage: C4 = CyclicPermutationGroup(4) # optional - sage.groups - sage: S4 = SymmetricGroup(3) # optional - sage.groups - sage: C = cartesian_product([C5, C4, S4]) # optional - sage.groups - sage: C.group_generators() # optional - sage.groups + sage: # needs sage.groups + sage: C5 = CyclicPermutationGroup(5) + sage: C4 = CyclicPermutationGroup(4) + sage: S4 = SymmetricGroup(3) + sage: C = cartesian_product([C5, C4, S4]) + sage: C.group_generators() Family (((1,2,3,4,5), (), ()), ((), (1,2,3,4), ()), ((), (), (1,2)), @@ -586,16 +591,17 @@ def group_generators(self): We check the other portion of :trac:`16718` is fixed:: - sage: len(C.j_classes()) # optional - sage.groups + sage: len(C.j_classes()) # needs sage.groups 1 An example with an infinitely generated group (a better output is needed):: - sage: G = Groups.free([1,2]) # optional - sage.groups - sage: H = Groups.free(ZZ) # optional - sage.groups - sage: C = cartesian_product([G, H]) # optional - sage.groups - sage: C.monoid_generators() # optional - sage.groups + sage: # needs sage.groups + sage: G = Groups.free([1,2]) + sage: H = Groups.free(ZZ) + sage: C = cartesian_product([G, H]) + sage: C.monoid_generators() Lazy family (gen(i))_{i in The Cartesian product of (...)} """ F = self.cartesian_factors() @@ -628,13 +634,13 @@ def order(self): EXAMPLES:: - sage: C = cartesian_product([SymmetricGroup(10), SL(2, GF(3))]) # optional - sage.groups sage.rings.finite_rings - sage: C.order() # optional - sage.groups sage.rings.finite_rings + sage: C = cartesian_product([SymmetricGroup(10), SL(2, GF(3))]) # needs sage.groups sage.rings.finite_rings + sage: C.order() # needs sage.groups sage.rings.finite_rings 87091200 TESTS:: - sage: C.order.__module__ # optional - sage.groups sage.rings.finite_rings + sage: C.order.__module__ # needs sage.groups sage.rings.finite_rings 'sage.categories.groups' .. TODO:: diff --git a/src/sage/categories/hecke_modules.py b/src/sage/categories/hecke_modules.py index ae3d638b06b..4a2799d2dbe 100644 --- a/src/sage/categories/hecke_modules.py +++ b/src/sage/categories/hecke_modules.py @@ -46,7 +46,7 @@ class HeckeModules(Category_module): sage: HeckeModules(IntegerRing()) Category of Hecke modules over Integer Ring - sage: HeckeModules(FiniteField(5)) # optional - sage.rings.finite_rings + sage: HeckeModules(FiniteField(5)) Category of Hecke modules over Finite Field of size 5 The base ring doesn't have to be a principal ideal domain:: @@ -64,7 +64,7 @@ def __init__(self, R): sage: TestSuite(HeckeModules(ZZ)).run() - sage: HeckeModules(Partitions(3)).run() # optional - sage.combinat + sage: HeckeModules(Partitions(3)).run() # needs sage.combinat Traceback (most recent call last): ... TypeError: R (=Partitions of the integer 3) must be a commutative ring @@ -121,15 +121,16 @@ def _Hom_(self, Y, category): EXAMPLES:: - sage: M = ModularForms(Gamma0(7), 4) # optional - sage.modular - sage: H = M._Hom_(M, category=HeckeModules(QQ)); H # optional - sage.modular + sage: # needs sage.modular + sage: M = ModularForms(Gamma0(7), 4) + sage: H = M._Hom_(M, category=HeckeModules(QQ)); H Set of Morphisms from Modular Forms space of dimension 3 for Congruence Subgroup Gamma0(7) of weight 4 over Rational Field to Modular Forms space of dimension 3 for Congruence Subgroup Gamma0(7) of weight 4 over Rational Field in Category of Hecke modules over Rational Field - sage: H.__class__ # optional - sage.modular + sage: H.__class__ - sage: TestSuite(H).run(skip=["_test_elements", "_test_an_element", "_test_elements_eq", # optional - sage.modular + sage: TestSuite(H).run(skip=["_test_elements", "_test_an_element", "_test_elements_eq", ....: "_test_elements_eq_reflexive", "_test_elements_eq_transitive", ....: "_test_elements_eq_symmetric", "_test_elements_neq", "_test_some_elements", ....: "_test_zero", "_test_additive_associativity", @@ -142,7 +143,7 @@ def _Hom_(self, Y, category): TESTS:: - sage: H = M._Hom_(M, category=HeckeModules(GF(5))); H # optional - sage.modular sage.rings.finite_rings + sage: H = M._Hom_(M, category=HeckeModules(GF(5))); H # needs sage.modular sage.rings.finite_rings Traceback (most recent call last): ... TypeError: Category of Hecke modules over Finite Field of size 5 diff --git a/src/sage/categories/highest_weight_crystals.py b/src/sage/categories/highest_weight_crystals.py index 226d310eb35..35cec0173a6 100644 --- a/src/sage/categories/highest_weight_crystals.py +++ b/src/sage/categories/highest_weight_crystals.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.graphs, sage.combinat +# sage.doctest: needs sage.combinat sage.graphs r""" Highest Weight Crystals """ diff --git a/src/sage/categories/homset.py b/src/sage/categories/homset.py index 46c9de2ab04..461dc371af9 100644 --- a/src/sage/categories/homset.py +++ b/src/sage/categories/homset.py @@ -11,26 +11,27 @@ In the following, the :class:`Hom` object is indeed cached:: - sage: K = GF(17) # optional - sage.rings.finite_rings - sage: H = Hom(ZZ, K) # optional - sage.rings.finite_rings - sage: H # optional - sage.rings.finite_rings + sage: K = GF(17) + sage: H = Hom(ZZ, K) + sage: H Set of Homomorphisms from Integer Ring to Finite Field of size 17 - sage: H is Hom(ZZ, K) # optional - sage.rings.finite_rings + sage: H is Hom(ZZ, K) True Nonetheless, garbage collection occurs when the original references are overwritten:: - sage: for p in prime_range(200): # optional - sage.rings.finite_rings + sage: # needs sage.libs.pari + sage: for p in prime_range(200): ....: K = GF(p) ....: H = Hom(ZZ, K) sage: import gc sage: _ = gc.collect() - sage: from sage.rings.finite_rings.finite_field_prime_modn import FiniteField_prime_modn as FF # optional - sage.rings.finite_rings - sage: L = [x for x in gc.get_objects() if isinstance(x, FF)] # optional - sage.rings.finite_rings - sage: len(L) # optional - sage.rings.finite_rings + sage: from sage.rings.finite_rings.finite_field_prime_modn import FiniteField_prime_modn as FF + sage: L = [x for x in gc.get_objects() if isinstance(x, FF)] + sage: len(L) 1 - sage: L # optional - sage.rings.finite_rings + sage: L [Finite Field of size 199] AUTHORS: @@ -104,26 +105,26 @@ def Hom(X, Y, category=None, check=True): EXAMPLES:: - sage: V = VectorSpace(QQ, 3) # optional - sage.modules - sage: Hom(V, V) # optional - sage.modules + sage: V = VectorSpace(QQ, 3) # needs sage.modules + sage: Hom(V, V) # needs sage.modules Set of Morphisms (Linear Transformations) from Vector space of dimension 3 over Rational Field to Vector space of dimension 3 over Rational Field - sage: G = AlternatingGroup(3) # optional - sage.groups - sage: Hom(G, G) # optional - sage.groups + sage: G = AlternatingGroup(3) # needs sage.groups + sage: Hom(G, G) # needs sage.groups Set of Morphisms from Alternating group of order 3!/2 as a permutation group to Alternating group of order 3!/2 as a permutation group in Category of finite enumerated permutation groups - sage: Hom(ZZ, QQ, Sets()) # optional - sage.groups + sage: Hom(ZZ, QQ, Sets()) Set of Morphisms from Integer Ring to Rational Field in Category of sets - sage: Hom(FreeModule(ZZ, 1), FreeModule(QQ, 1)) # optional - sage.modules + sage: Hom(FreeModule(ZZ, 1), FreeModule(QQ, 1)) # needs sage.modules Set of Morphisms from Ambient free module of rank 1 over the principal ideal domain Integer Ring to Vector space of dimension 1 over Rational Field in Category of commutative additive groups - sage: Hom(FreeModule(QQ, 1), FreeModule(ZZ, 1)) # optional - sage.modules + sage: Hom(FreeModule(QQ, 1), FreeModule(ZZ, 1)) # needs sage.modules Set of Morphisms from Vector space of dimension 1 over Rational Field to Ambient free module of rank 1 over the principal ideal domain Integer Ring @@ -132,15 +133,16 @@ def Hom(X, Y, category=None, check=True): Here, we test against a memory leak that has been fixed at :trac:`11521` by using a weak cache:: - sage: for p in prime_range(10^3): # optional - sage.rings.finite_rings + sage: # needs sage.libs.pari + sage: for p in prime_range(10^3): ....: K = GF(p) ....: a = K(0) sage: import gc sage: gc.collect() # random 624 - sage: from sage.rings.finite_rings.finite_field_prime_modn import FiniteField_prime_modn as FF # optional - sage.rings.finite_rings - sage: L = [x for x in gc.get_objects() if isinstance(x, FF)] # optional - sage.rings.finite_rings - sage: len(L), L[0] # optional - sage.rings.finite_rings + sage: from sage.rings.finite_rings.finite_field_prime_modn import FiniteField_prime_modn as FF + sage: L = [x for x in gc.get_objects() if isinstance(x, FF)] + sage: len(L), L[0] (1, Finite Field of size 997) To illustrate the choice of the category, we consider the @@ -148,13 +150,13 @@ def Hom(X, Y, category=None, check=True): sage: X = ZZ; X Integer Ring - sage: Y = SymmetricGroup(3); Y # optional - sage.groups + sage: Y = SymmetricGroup(3); Y # needs sage.groups Symmetric group of order 3! as a permutation group By default, the smallest category containing both ``X`` and ``Y``, is used:: - sage: Hom(X, Y) # optional - sage.groups + sage: Hom(X, Y) # needs sage.groups Set of Morphisms from Integer Ring to Symmetric group of order 3! as a permutation group in Category of enumerated monoids @@ -162,13 +164,13 @@ def Hom(X, Y, category=None, check=True): Otherwise, if ``category`` is specified, then ``category`` is used, after checking that ``X`` and ``Y`` are indeed in ``category``:: - sage: Hom(X, Y, Magmas()) # optional - sage.groups + sage: Hom(X, Y, Magmas()) # needs sage.groups Set of Morphisms from Integer Ring to Symmetric group of order 3! as a permutation group in Category of magmas - sage: Hom(X, Y, Groups()) # optional - sage.groups + sage: Hom(X, Y, Groups()) # needs sage.groups Traceback (most recent call last): ... ValueError: Integer Ring is not in Category of groups @@ -195,10 +197,10 @@ def Hom(X, Y, category=None, check=True): Homset are unique parents:: - sage: k = GF(5) # optional - sage.rings.finite_rings - sage: H1 = Hom(k, k) # optional - sage.rings.finite_rings - sage: H2 = Hom(k, k) # optional - sage.rings.finite_rings - sage: H1 is H2 # optional - sage.rings.finite_rings + sage: k = GF(5) + sage: H1 = Hom(k, k) + sage: H2 = Hom(k, k) + sage: H1 is H2 True Moreover, if no category is provided, then the result is identical @@ -243,16 +245,17 @@ def Hom(X, Y, category=None, check=True): Variation on the theme:: - sage: U1 = FreeModule(ZZ, 2) # optional - sage.modules - sage: U2 = FreeModule(ZZ, 2, inner_product_matrix=matrix([[1,0], [0,-1]])) # optional - sage.modules - sage: U1 == U2, U1 is U2 # optional - sage.modules + sage: # needs sage.modules + sage: U1 = FreeModule(ZZ, 2) + sage: U2 = FreeModule(ZZ, 2, inner_product_matrix=matrix([[1,0], [0,-1]])) + sage: U1 == U2, U1 is U2 (False, False) - sage: V = ZZ^3 # optional - sage.modules - sage: H1 = Hom(U1, V); H2 = Hom(U2, V) # optional - sage.modules - sage: H1 == H2, H1 is H2 # optional - sage.modules + sage: V = ZZ^3 + sage: H1 = Hom(U1, V); H2 = Hom(U2, V) + sage: H1 == H2, H1 is H2 (False, False) - sage: H1 = Hom(V, U1); H2 = Hom(V, U2) # optional - sage.modules - sage: H1 == H2, H1 is H2 # optional - sage.modules + sage: H1 = Hom(V, U1); H2 = Hom(V, U2) + sage: H1 == H2, H1 is H2 (False, False) Since :trac:`11900`, the meet of the categories of the given arguments is @@ -298,17 +301,15 @@ def Hom(X, Y, category=None, check=True): Checks that the domain and codomain are in the specified category. Case of a non parent:: - sage: S = SimplicialComplex([[1,2], [1,4]]); S.rename("S") # optional - sage.graphs - sage: Hom(S, S, SimplicialComplexes()) # optional - sage.graphs + sage: # needs sage.graphs + sage: S = SimplicialComplex([[1,2], [1,4]]); S.rename("S") + sage: Hom(S, S, SimplicialComplexes()) Set of Morphisms from S to S in Category of finite simplicial complexes - - sage: Hom(Set(), S, Sets()) # optional - sage.graphs + sage: Hom(Set(), S, Sets()) Set of Morphisms from {} to S in Category of sets - - sage: Hom(S, Set(), Sets()) # optional - sage.graphs + sage: Hom(S, Set(), Sets()) Set of Morphisms from S to {} in Category of sets - - sage: H = Hom(S, S, ChainComplexes(QQ)) # optional - sage.graphs + sage: H = Hom(S, S, ChainComplexes(QQ)) Traceback (most recent call last): ... ValueError: S is not in Category of chain complexes over Rational Field @@ -317,15 +318,16 @@ def Hom(X, Y, category=None, check=True): and not ``X.category().is_subcategory(category)`` as it used to be before :trac:`16275` (see :trac:`15801` for a real use case):: + sage: # needs sage.graphs sage: class PermissiveCategory(Category): ....: def super_categories(self): return [Objects()] ....: def __contains__(self, X): return True sage: C = PermissiveCategory(); C.rename("Permissive category") - sage: S.category().is_subcategory(C) # optional - sage.graphs + sage: S.category().is_subcategory(C) False - sage: S in C # optional - sage.graphs + sage: S in C True - sage: Hom(S, S, C) # optional - sage.graphs + sage: Hom(S, S, C) Set of Morphisms from S to S in Permissive category With ``check=False``, uninitialized parents, as can appear upon @@ -339,6 +341,7 @@ def Hom(X, Y, category=None, check=True): Case of a non parent:: + sage: # needs sage.graphs sage: cls = type(SimplicialComplex([[1,2], [1,4]])) sage: S = unpickle_newobj(cls, ()) sage: H = Hom(S, S, Sets(), check=False) @@ -349,16 +352,16 @@ def Hom(X, Y, category=None, check=True): uninitialized parent:: sage: P. = QQ['x,y'] - sage: Q = P.quotient([x^2-1, y^2-1]) # optional - sage.libs.singular - sage: q = Q.an_element() # optional - sage.libs.singular - sage: explain_pickle(dumps(Q)) # optional - sage.libs.singular + sage: Q = P.quotient([x^2 - 1, y^2 - 1]) + sage: q = Q.an_element() # needs sage.libs.singular + sage: explain_pickle(dumps(Q)) # needs sage.libs.singular pg_... ... = pg_dynamic_class('QuotientRing_generic_with_category', (pg_QuotientRing_generic, pg_getattr(..., 'parent_class')), None, None, pg_QuotientRing_generic) si... = unpickle_newobj(..., ()) ... si... = pg_unpickle_MPolynomialRing_libsingular(..., ('x', 'y'), ...) si... = ... pg_Hom(si..., si..., ...) ... - sage: Q == loads(dumps(Q)) # optional - sage.libs.singular + sage: Q == loads(dumps(Q)) True Check that the ``_Hom_`` method of the ``category`` input is used:: @@ -504,24 +507,25 @@ def End(X, category=None): EXAMPLES:: - sage: V = VectorSpace(QQ, 3) # optional - sage.modules - sage: End(V) # optional - sage.modules + sage: V = VectorSpace(QQ, 3) # needs sage.modules + sage: End(V) # needs sage.modules Set of Morphisms (Linear Transformations) from Vector space of dimension 3 over Rational Field to Vector space of dimension 3 over Rational Field :: - sage: G = AlternatingGroup(3) # optional - sage.groups - sage: S = End(G); S # optional - sage.groups + sage: # needs sage.groups + sage: G = AlternatingGroup(3) + sage: S = End(G); S Set of Morphisms from Alternating group of order 3!/2 as a permutation group to Alternating group of order 3!/2 as a permutation group in Category of finite enumerated permutation groups sage: from sage.categories.homset import is_Endset - sage: is_Endset(S) # optional - sage.groups + sage: is_Endset(S) True - sage: S.domain() # optional - sage.groups + sage: S.domain() Alternating group of order 3!/2 as a permutation group To avoid creating superfluous categories, a homset in a category @@ -533,13 +537,14 @@ def End(X, category=None): groups currently implement nothing more than unital magmas about their homsets, we have:: - sage: G = GL(3, 3) # optional - sage.groups - sage: G.category() # optional - sage.groups + sage: # needs sage.groups + sage: G = GL(3, 3) + sage: G.category() Category of finite groups - sage: H = Hom(G, G) # optional - sage.groups - sage: H.homset_category() # optional - sage.groups + sage: H = Hom(G, G) + sage: H.homset_category() Category of finite groups - sage: H.category() # optional - sage.groups + sage: H.category() Category of endsets of unital magmas Similarly, a ring morphism just needs to preserve addition, @@ -578,29 +583,29 @@ class Homset(Set_generic): EXAMPLES:: - sage: H = Hom(QQ^2, QQ^3) # optional - sage.modules - sage: loads(H.dumps()) is H # optional - sage.modules + sage: H = Hom(QQ^2, QQ^3) # needs sage.modules + sage: loads(H.dumps()) is H # needs sage.modules True Homsets of unique parents are unique as well:: - sage: H = End(AffineSpace(2, names='x,y')) # optional - sage.modules - sage: loads(dumps(AffineSpace(2, names='x,y'))) is AffineSpace(2, names='x,y') # optional - sage.modules + sage: H = End(AffineSpace(2, names='x,y')) + sage: loads(dumps(AffineSpace(2, names='x,y'))) is AffineSpace(2, names='x,y') True - sage: loads(dumps(H)) is H # optional - sage.modules + sage: loads(dumps(H)) is H True Conversely, homsets of non-unique parents are non-unique:: - sage: P11 = ProductProjectiveSpaces(QQ, [1, 1]) # optional - sage.schemes - sage: H = End(P11) # optional - sage.schemes - sage: loads(dumps(P11)) is ProductProjectiveSpaces(QQ, [1, 1]) # optional - sage.schemes + sage: P11 = ProductProjectiveSpaces(QQ, [1, 1]) + sage: H = End(P11) + sage: loads(dumps(P11)) is ProductProjectiveSpaces(QQ, [1, 1]) False - sage: loads(dumps(P11)) == ProductProjectiveSpaces(QQ, [1, 1]) # optional - sage.schemes + sage: loads(dumps(P11)) == ProductProjectiveSpaces(QQ, [1, 1]) True - sage: loads(dumps(H)) is H # optional - sage.schemes + sage: loads(dumps(H)) is H False - sage: loads(dumps(H)) == H # optional - sage.schemes + sage: loads(dumps(H)) == H True """ def __init__(self, X, Y, category=None, base=None, check=True): @@ -613,7 +618,7 @@ def __init__(self, X, Y, category=None, base=None, check=True): sage: class MyHomset(Homset): ....: def _an_element_(self): ....: return sage.categories.morphism.SetMorphism(self, f) - sage: import __main__; __main__.MyHomset = MyHomset # fakes MyHomset being defined in a Python module + sage: import __main__; __main__.MyHomset = MyHomset # fakes MyHomset being defined in a Python module sage: H = MyHomset(X, Y, category=Monoids(), base = ZZ) sage: H Set of Morphisms from X to Y in Category of monoids @@ -643,12 +648,12 @@ def __init__(self, X, Y, category=None, base=None, check=True): sage: Hom(R, R, category=Sets()).base_ring() sage: Hom(R, R, category=Modules(QQ)).base_ring() Rational Field - sage: Hom(QQ^3, QQ^3, category=Modules(QQ)).base_ring() # optional - sage.modules + sage: Hom(QQ^3, QQ^3, category=Modules(QQ)).base_ring() # needs sage.modules Rational Field For whatever it's worth, the ``base`` arguments takes precedence:: - sage: MyHomset(ZZ^3, ZZ^3, base=QQ).base_ring() # optional - sage.modules + sage: MyHomset(ZZ^3, ZZ^3, base=QQ).base_ring() # needs sage.modules Rational Field """ self._domain = X @@ -701,8 +706,8 @@ def __reduce__(self): EXAMPLES:: - sage: H = Hom(QQ^2, QQ^3) # optional - sage.modules - sage: H.__reduce__() # optional - sage.modules + sage: H = Hom(QQ^2, QQ^3) # needs sage.modules + sage: H.__reduce__() # needs sage.modules (, (Vector space of dimension 2 over Rational Field, Vector space of dimension 3 over Rational Field, @@ -712,18 +717,19 @@ def __reduce__(self): TESTS:: - sage: loads(H.dumps()) is H # optional - sage.modules + sage: loads(H.dumps()) is H # needs sage.modules True Homsets of non-unique parents are non-unique as well:: - sage: G = PermutationGroup([[(1, 2, 3), (4, 5)], [(3, 4)]]) # optional - sage.groups - sage: G is loads(dumps(G)) # optional - sage.groups + sage: # needs sage.groups + sage: G = PermutationGroup([[(1, 2, 3), (4, 5)], [(3, 4)]]) + sage: G is loads(dumps(G)) False - sage: H = Hom(G, G) # optional - sage.groups - sage: H is loads(dumps(H)) # optional - sage.groups + sage: H = Hom(G, G) + sage: H is loads(dumps(H)) False - sage: H == loads(dumps(H)) # optional - sage.groups + sage: H == loads(dumps(H)) True """ return Hom, (self._domain, self._codomain, self.__category, False) @@ -732,7 +738,7 @@ def _repr_(self): """ TESTS:: - sage: Hom(ZZ^2, QQ, category=Sets())._repr_() # optional - sage.modules + sage: Hom(ZZ^2, QQ, category=Sets())._repr_() # needs sage.modules 'Set of Morphisms from Ambient free module of rank 2 over the principal ideal domain Integer Ring to Rational Field in Category of sets' """ return "Set of Morphisms from {} to {} in {}".format(self._domain, @@ -749,10 +755,10 @@ def __hash__(self): sage: hash(Hom(QQ, ZZ)) == hash((QQ, ZZ, QQ)) True - sage: E = EllipticCurve('37a') # optional - sage.symbolic - sage: H = E(0).parent(); H # optional - sage.symbolic + sage: E = EllipticCurve('37a') # needs sage.schemes + sage: H = E(0).parent(); H # needs sage.schemes Abelian group of points on Elliptic Curve defined by y^2 + y = x^3 - x over Rational Field - sage: hash(H) == hash((H.domain(), H.codomain(), H.base())) # optional - sage.symbolic + sage: hash(H) == hash((H.domain(), H.codomain(), H.base())) # needs sage.schemes True """ return hash((self._domain, self._codomain, self.base())) @@ -773,8 +779,8 @@ def homset_category(self): EXAMPLES:: - sage: H = Hom(AlternatingGroup(4), AlternatingGroup(7)) # optional - sage.groups - sage: H.homset_category() # optional - sage.groups + sage: H = Hom(AlternatingGroup(4), AlternatingGroup(7)) # needs sage.groups + sage: H.homset_category() # needs sage.groups Category of finite enumerated permutation groups """ return self.__category @@ -785,9 +791,9 @@ def _element_constructor_(self, x, check=None, **options): EXAMPLES:: - sage: H = Hom(SymmetricGroup(4), SymmetricGroup(7)) # optional - sage.groups - sage: phi = Hom(SymmetricGroup(5), SymmetricGroup(6)).natural_map() # optional - sage.groups - sage: phi # optional - sage.groups + sage: H = Hom(SymmetricGroup(4), SymmetricGroup(7)) # needs sage.groups + sage: phi = Hom(SymmetricGroup(5), SymmetricGroup(6)).natural_map() # needs sage.groups + sage: phi # needs sage.groups Coercion morphism: From: Symmetric group of order 5! as a permutation group To: Symmetric group of order 6! as a permutation group @@ -799,7 +805,7 @@ def _element_constructor_(self, x, check=None, **options): collection, if there is a strong reference to its domain (which is the case here):: - sage: H(phi) # optional - sage.groups + sage: H(phi) # needs sage.groups Composite map: From: Symmetric group of order 4! as a permutation group To: Symmetric group of order 7! as a permutation group @@ -820,7 +826,7 @@ def _element_constructor_(self, x, check=None, **options): Also note that making a copy of the resulting map will automatically make strengthened copies of the composed maps:: - sage: copy(H(phi)) # optional - sage.groups + sage: copy(H(phi)) # needs sage.groups Composite map: From: Symmetric group of order 4! as a permutation group To: Symmetric group of order 7! as a permutation group @@ -906,24 +912,25 @@ def _element_constructor_(self, x, check=None, **options): TESTS:: - sage: G. = FreeGroup() # optional - sage.groups - sage: H = Hom(G, G) # optional - sage.groups - sage: H(H.identity()) # optional - sage.groups + sage: # needs sage.groups + sage: G. = FreeGroup() + sage: H = Hom(G, G) + sage: H(H.identity()) Identity endomorphism of Free Group on generators {x, y, z} - sage: H() # optional - sage.groups + sage: H() Traceback (most recent call last): ... TypeError: unable to convert 0 to an element of Set of Morphisms from Free Group on generators {x, y, z} to Free Group on generators {x, y, z} in Category of infinite groups - sage: H("whatever") # optional - sage.groups + sage: H("whatever") Traceback (most recent call last): ... TypeError: unable to convert 'whatever' to an element of Set of Morphisms from Free Group on generators {x, y, z} to Free Group on generators {x, y, z} in Category of infinite groups - sage: HH = Hom(H, H) # optional - sage.groups - sage: HH(HH.identity(), foo="bar") # optional - sage.groups + sage: HH = Hom(H, H) + sage: HH(HH.identity(), foo="bar") Traceback (most recent call last): ... NotImplementedError: no keywords are implemented for @@ -1003,42 +1010,44 @@ class of ``C`` will be inherited by *all* subcategories of Let's take a homset of finite commutative groups as example; at this point this is the simplest one to create (gosh):: + sage: # needs sage.groups sage: cat = Groups().Finite().Commutative() - sage: C3 = PermutationGroup([(1,2,3)]) # optional - sage.groups - sage: C3._refine_category_(cat) # optional - sage.groups - sage: C2 = PermutationGroup([(1,2)]) # optional - sage.groups - sage: C2._refine_category_(cat) # optional - sage.groups - sage: H = Hom(C3, C2, cat) # optional - sage.groups - sage: H.homset_category() # optional - sage.groups + sage: C3 = PermutationGroup([(1,2,3)]) + sage: C3._refine_category_(cat) + sage: C2 = PermutationGroup([(1,2)]) + sage: C2._refine_category_(cat) + sage: H = Hom(C3, C2, cat) + sage: H.homset_category() Category of finite commutative groups - sage: H.category() # optional - sage.groups + sage: H.category() Category of homsets of unital magmas - sage: cls = H._abstract_element_class; cls # optional - sage.groups + sage: cls = H._abstract_element_class; cls - sage: cls.__bases__ == (H.category().element_class, H.homset_category().morphism_class) # optional - sage.groups + sage: cls.__bases__ == (H.category().element_class, H.homset_category().morphism_class) True A morphism of finite commutative semigroups is also a morphism of semigroups, of magmas, ...; it thus inherits code from all those categories:: - sage: issubclass(cls, Semigroups().Finite().morphism_class) # optional - sage.groups + sage: # needs sage.groups + sage: issubclass(cls, Semigroups().Finite().morphism_class) True - sage: issubclass(cls, Semigroups().morphism_class) # optional - sage.groups + sage: issubclass(cls, Semigroups().morphism_class) True - sage: issubclass(cls, Magmas().Commutative().morphism_class) # optional - sage.groups + sage: issubclass(cls, Magmas().Commutative().morphism_class) True - sage: issubclass(cls, Magmas().morphism_class) # optional - sage.groups + sage: issubclass(cls, Magmas().morphism_class) True - sage: issubclass(cls, Sets().morphism_class) # optional - sage.groups + sage: issubclass(cls, Sets().morphism_class) True Recall that FiniteMonoids() is a full subcategory of ``Monoids()``, but not of ``FiniteSemigroups()``. Thus:: - sage: issubclass(cls, Monoids().Finite().Homsets().element_class) # optional - sage.groups + sage: issubclass(cls, Monoids().Finite().Homsets().element_class) # needs sage.groups True - sage: issubclass(cls, Semigroups().Finite().Homsets().element_class) # optional - sage.groups + sage: issubclass(cls, Semigroups().Finite().Homsets().element_class) # needs sage.groups False """ class_name = "%s._abstract_element_class"%self.__class__.__name__ @@ -1139,8 +1148,8 @@ def natural_map(self): Coercion morphism: From: Univariate Polynomial Ring in t over Integer Ring To: Univariate Polynomial Ring in t over Rational Field - sage: H = Hom(QQ['t'], GF(3)['t']) # optional - sage.rings.finite_rings - sage: H.natural_map() # optional - sage.rings.finite_rings + sage: H = Hom(QQ['t'], GF(3)['t']) + sage: H.natural_map() Traceback (most recent call last): ... TypeError: natural coercion morphism @@ -1186,8 +1195,8 @@ def one(self): EXAMPLES:: - sage: K = GaussianIntegers() # optional - sage.rings.number_field - sage: End(K).one() # optional - sage.rings.number_field + sage: K = GaussianIntegers() # needs sage.rings.number_field + sage: End(K).one() # needs sage.rings.number_field Identity endomorphism of Gaussian Integers in Number Field in I with defining polynomial x^2 + 1 with I = 1*I """ @@ -1230,21 +1239,22 @@ def reversed(self): EXAMPLES:: - sage: H = Hom(ZZ^2, ZZ^3); H # optional - sage.modules + sage: # needs sage.modules + sage: H = Hom(ZZ^2, ZZ^3); H Set of Morphisms from Ambient free module of rank 2 over the principal ideal domain Integer Ring to Ambient free module of rank 3 over the principal ideal domain Integer Ring in Category of finite dimensional modules with basis over (euclidean domains and infinite enumerated sets and metric spaces) - sage: type(H) # optional - sage.modules + sage: type(H) - sage: H.reversed() # optional - sage.modules + sage: H.reversed() Set of Morphisms from Ambient free module of rank 3 over the principal ideal domain Integer Ring to Ambient free module of rank 2 over the principal ideal domain Integer Ring in Category of finite dimensional modules with basis over (euclidean domains and infinite enumerated sets and metric spaces) - sage: type(H.reversed()) # optional - sage.modules + sage: type(H.reversed()) """ return Hom(self.codomain(), self.domain(), diff --git a/src/sage/categories/hopf_algebras.py b/src/sage/categories/hopf_algebras.py index ecff3fd58cc..41e349690fe 100644 --- a/src/sage/categories/hopf_algebras.py +++ b/src/sage/categories/hopf_algebras.py @@ -67,18 +67,19 @@ def antipode(self): EXAMPLES:: - sage: A = HopfAlgebrasWithBasis(QQ).example(); A # optional - sage.groups + sage: # needs sage.groups + sage: A = HopfAlgebrasWithBasis(QQ).example(); A An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Rational Field - sage: [a,b] = A.algebra_generators() # optional - sage.groups - sage: a, a.antipode() # optional - sage.groups + sage: [a,b] = A.algebra_generators() + sage: a, a.antipode() (B[(1,2,3)], B[(1,3,2)]) - sage: b, b.antipode() # optional - sage.groups + sage: b, b.antipode() (B[(1,3)], B[(1,3)]) TESTS:: - sage: all(x.antipode() * x == A.one() for x in A.basis()) # optional - sage.groups + sage: all(x.antipode() * x == A.one() for x in A.basis()) # needs sage.groups True """ return self.parent().antipode(self) @@ -136,9 +137,9 @@ def antipode(self): EXAMPLES:: - sage: A = SteenrodAlgebra(3) # optional - sage.combinat sage.modules - sage: a = A.an_element() # optional - sage.combinat sage.modules - sage: a, a.antipode() # optional - sage.combinat sage.modules + sage: A = SteenrodAlgebra(3) # needs sage.combinat sage.modules + sage: a = A.an_element() # needs sage.combinat sage.modules + sage: a, a.antipode() # needs sage.combinat sage.modules (2 Q_1 Q_3 P(2,1), Q_1 Q_3 P(2,1)) """ return self.parent().antipode(self) @@ -205,11 +206,12 @@ def antipode_by_coercion(self, x): EXAMPLES:: - sage: N = NonCommutativeSymmetricFunctions(QQ) # optional - sage.combinat - sage: R = N.ribbon() # optional - sage.combinat - sage: R.antipode_by_coercion.__module__ # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: N = NonCommutativeSymmetricFunctions(QQ) + sage: R = N.ribbon() + sage: R.antipode_by_coercion.__module__ 'sage.categories.hopf_algebras' - sage: R.antipode_by_coercion(R[1,3,1]) # optional - sage.combinat + sage: R.antipode_by_coercion(R[1,3,1]) -R[2, 1, 2] """ R = self.realization_of().a_realization() diff --git a/src/sage/categories/hopf_algebras_with_basis.py b/src/sage/categories/hopf_algebras_with_basis.py index ea401896ca0..1be964cb6c9 100644 --- a/src/sage/categories/hopf_algebras_with_basis.py +++ b/src/sage/categories/hopf_algebras_with_basis.py @@ -33,44 +33,45 @@ class HopfAlgebrasWithBasis(CategoryWithAxiom_over_base_ring): We now show how to use a simple Hopf algebra, namely the group algebra of the dihedral group (see also AlgebrasWithBasis):: - sage: A = C.example(); A # optional - sage.groups + sage: A = C.example(); A # needs sage.groups An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Rational Field - sage: A.__custom_name = "A" # optional - sage.groups - sage: A.category() # optional - sage.groups + sage: A.__custom_name = "A" # needs sage.groups + sage: A.category() # needs sage.groups Category of finite dimensional hopf algebras with basis over Rational Field - sage: A.one_basis() # optional - sage.groups + sage: A.one_basis() # needs sage.groups () - sage: A.one() # optional - sage.groups + sage: A.one() # needs sage.groups B[()] - sage: A.base_ring() # optional - sage.groups + sage: A.base_ring() # needs sage.groups Rational Field - sage: A.basis().keys() # optional - sage.groups + sage: A.basis().keys() # needs sage.groups Dihedral group of order 6 as a permutation group - sage: [a,b] = A.algebra_generators() # optional - sage.groups - sage: a, b # optional - sage.groups + sage: # needs sage.groups + sage: [a,b] = A.algebra_generators() + sage: a, b (B[(1,2,3)], B[(1,3)]) - sage: a^3, b^2 # optional - sage.groups + sage: a^3, b^2 (B[()], B[()]) - sage: a*b # optional - sage.groups + sage: a*b B[(1,2)] - sage: A.product # todo: not quite ... # optional - sage.groups + sage: A.product # todo: not quite ... # needs sage.groups - sage: A.product(b, b) # optional - sage.groups + sage: A.product(b, b) # needs sage.groups B[()] - sage: A.zero().coproduct() # optional - sage.groups + sage: A.zero().coproduct() # needs sage.groups 0 - sage: A.zero().coproduct().parent() # optional - sage.groups + sage: A.zero().coproduct().parent() # needs sage.groups A # A - sage: a.coproduct() # optional - sage.groups + sage: a.coproduct() # needs sage.groups B[(1,2,3)] # B[(1,2,3)] - sage: TestSuite(A).run(verbose=True) # optional - sage.groups + sage: TestSuite(A).run(verbose=True) # needs sage.groups running ._test_additive_associativity() . . . pass running ._test_an_element() . . . pass running ._test_antipode() . . . pass @@ -101,33 +102,33 @@ class HopfAlgebrasWithBasis(CategoryWithAxiom_over_base_ring): running ._test_prod() . . . pass running ._test_some_elements() . . . pass running ._test_zero() . . . pass - sage: A.__class__ # optional - sage.groups + sage: A.__class__ # needs sage.groups - sage: A.element_class # optional - sage.groups + sage: A.element_class # needs sage.groups Let us look at the code for implementing A:: - sage: A?? # todo: not implemented # optional - sage.groups + sage: A?? # not implemented # needs sage.groups TESTS:: - sage: TestSuite(A).run() # optional - sage.groups - sage: TestSuite(C).run() # optional - sage.groups + sage: TestSuite(A).run() # needs sage.groups + sage: TestSuite(C).run() """ def example(self, G=None): """ Returns an example of algebra with basis:: - sage: HopfAlgebrasWithBasis(QQ['x']).example() # optional - sage.groups + sage: HopfAlgebrasWithBasis(QQ['x']).example() # needs sage.groups An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Univariate Polynomial Ring in x over Rational Field An other group can be specified as optional argument:: - sage: HopfAlgebrasWithBasis(QQ).example(SymmetricGroup(4)) # optional - sage.groups + sage: HopfAlgebrasWithBasis(QQ).example(SymmetricGroup(4)) # needs sage.groups An example of Hopf algebra with basis: the group algebra of the Symmetric group of order 4! as a permutation group over Rational Field """ @@ -179,12 +180,13 @@ def antipode_on_basis(self, x): EXAMPLES:: - sage: A = HopfAlgebrasWithBasis(QQ).example() # optional - sage.groups - sage: W = A.basis().keys(); W # optional - sage.groups + sage: # needs sage.groups + sage: A = HopfAlgebrasWithBasis(QQ).example() + sage: W = A.basis().keys(); W Dihedral group of order 6 as a permutation group - sage: w = W.gen(0); w # optional - sage.groups + sage: w = W.gen(0); w (1,2,3) - sage: A.antipode_on_basis(w) # optional - sage.groups + sage: A.antipode_on_basis(w) B[(1,3,2)] """ @@ -200,19 +202,20 @@ def antipode(self): EXAMPLES:: - sage: A = HopfAlgebrasWithBasis(ZZ).example(); A # optional - sage.groups + sage: # needs sage.groups + sage: A = HopfAlgebrasWithBasis(ZZ).example(); A An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Integer Ring - sage: A = HopfAlgebrasWithBasis(QQ).example() # optional - sage.groups - sage: [a,b] = A.algebra_generators() # optional - sage.groups - sage: a, A.antipode(a) # optional - sage.groups + sage: A = HopfAlgebrasWithBasis(QQ).example() + sage: [a,b] = A.algebra_generators() + sage: a, A.antipode(a) (B[(1,2,3)], B[(1,3,2)]) - sage: b, A.antipode(b) # optional - sage.groups + sage: b, A.antipode(b) (B[(1,3)], B[(1,3)]) TESTS:: - sage: all(A.antipode(x) * x == A.one() for x in A.basis()) # optional - sage.groups + sage: all(A.antipode(x) * x == A.one() for x in A.basis()) # needs sage.groups True """ if self.antipode_on_basis is not NotImplemented: @@ -244,13 +247,13 @@ def _test_antipode(self, **options): TESTS:: - sage: R = NonCommutativeSymmetricFunctions(QQ).ribbon() # optional - sage.combinat - sage: R._test_antipode() # optional - sage.combinat + sage: R = NonCommutativeSymmetricFunctions(QQ).ribbon() # needs sage.combinat sage.modules + sage: R._test_antipode() # needs sage.combinat sage.modules :: - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat - sage: s._test_antipode() # optional - sage.combinat + sage: s = SymmetricFunctions(QQ).schur() # needs sage.combinat sage.modules + sage: s._test_antipode() # needs sage.combinat sage.modules """ tester = self._tester(**options) diff --git a/src/sage/categories/integral_domains.py b/src/sage/categories/integral_domains.py index ca910a16e60..b6e6f59a196 100644 --- a/src/sage/categories/integral_domains.py +++ b/src/sage/categories/integral_domains.py @@ -45,7 +45,7 @@ def __contains__(self, x): """ EXAMPLES:: - sage: GF(4, "a") in IntegralDomains() # optional - sage.rings.finite_rings + sage: GF(4, "a") in IntegralDomains() # needs sage.rings.finite_rings True sage: QQ in IntegralDomains() True @@ -108,10 +108,10 @@ def is_integral_domain(self, proof=True): sage: Parent(QQ, category=IntegralDomains()).is_integral_domain() True - sage: L. = LazyLaurentSeriesRing(QQ) # optional - sage.combinat - sage: L.is_integral_domain() # optional - sage.combinat + sage: L. = LazyLaurentSeriesRing(QQ) # needs sage.combinat + sage: L.is_integral_domain() # needs sage.combinat True - sage: L.is_integral_domain(proof=True) # optional - sage.combinat + sage: L.is_integral_domain(proof=True) # needs sage.combinat True """ return True diff --git a/src/sage/categories/kac_moody_algebras.py b/src/sage/categories/kac_moody_algebras.py index 040387a3325..52f738243b8 100644 --- a/src/sage/categories/kac_moody_algebras.py +++ b/src/sage/categories/kac_moody_algebras.py @@ -43,12 +43,12 @@ def example(self, n=2): EXAMPLES:: sage: from sage.categories.kac_moody_algebras import KacMoodyAlgebras - sage: KacMoodyAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: KacMoodyAlgebras(QQ).example() # needs sage.combinat sage.modules Lie algebra of ['A', 2] in the Chevalley basis We can specify the rank of the example:: - sage: KacMoodyAlgebras(QQ).example(4) # optional - sage.combinat sage.modules + sage: KacMoodyAlgebras(QQ).example(4) # needs sage.combinat sage.modules Lie algebra of ['A', 4] in the Chevalley basis """ from sage.algebras.lie_algebras.classical_lie_algebra import LieAlgebraChevalleyBasis @@ -61,8 +61,8 @@ def cartan_type(self): EXAMPLES:: - sage: L = LieAlgebra(QQ, cartan_type=['A', 2]) # optional - sage.combinat sage.modules - sage: L.cartan_type() # optional - sage.combinat sage.modules + sage: L = LieAlgebra(QQ, cartan_type=['A', 2]) # needs sage.combinat sage.modules + sage: L.cartan_type() # needs sage.combinat sage.modules ['A', 2] """ return self._cartan_type @@ -73,8 +73,8 @@ def weyl_group(self): EXAMPLES:: - sage: L = LieAlgebra(QQ, cartan_type=['A', 2]) # optional - sage.combinat sage.modules - sage: L.weyl_group() # optional - sage.combinat sage.modules + sage: L = LieAlgebra(QQ, cartan_type=['A', 2]) # needs sage.combinat sage.modules + sage: L.weyl_group() # needs sage.combinat sage.modules Weyl Group of type ['A', 2] (as a matrix group acting on the ambient space) """ from sage.combinat.root_system.weyl_group import WeylGroup diff --git a/src/sage/categories/lambda_bracket_algebras.py b/src/sage/categories/lambda_bracket_algebras.py index c8277ae1f26..40cb5ed70c4 100644 --- a/src/sage/categories/lambda_bracket_algebras.py +++ b/src/sage/categories/lambda_bracket_algebras.py @@ -45,7 +45,7 @@ def __classcall_private__(cls, R, check=True): EXAMPLES:: - sage: LieConformalAlgebras(QuaternionAlgebra(2)) # optional - sage.combinat sage.modules + sage: LieConformalAlgebras(QuaternionAlgebra(2)) # needs sage.combinat sage.modules Traceback (most recent call last): ValueError: base must be a commutative ring got Quaternion Algebra (-1, -1) with base ring Rational Field @@ -118,8 +118,8 @@ def ideal(self, *gens, **kwds): EXAMPLES:: - sage: Vir = lie_conformal_algebras.Virasoro(QQ) # optional - sage.combinat sage.modules - sage: Vir.ideal() # optional - sage.combinat sage.modules + sage: Vir = lie_conformal_algebras.Virasoro(QQ) # needs sage.combinat sage.modules + sage: Vir.ideal() # needs sage.combinat sage.modules Traceback (most recent call last): ... NotImplementedError: ideals of Lie Conformal algebras are not implemented yet @@ -138,21 +138,22 @@ def bracket(self, rhs): The brackets of the Virasoro Lie conformal algebra:: - sage: Vir = lie_conformal_algebras.Virasoro(QQ); L = Vir.0 # optional - sage.combinat sage.modules - sage: L.bracket(L) # optional - sage.combinat sage.modules + sage: Vir = lie_conformal_algebras.Virasoro(QQ); L = Vir.0 # needs sage.combinat sage.modules + sage: L.bracket(L) # needs sage.combinat sage.modules {0: TL, 1: 2*L, 3: 1/2*C} - sage: L.bracket(L.T()) # optional - sage.combinat sage.modules + sage: L.bracket(L.T()) # needs sage.combinat sage.modules {0: 2*T^(2)L, 1: 3*TL, 2: 4*L, 4: 2*C} Now with a current algebra:: - sage: V = lie_conformal_algebras.Affine(QQ, 'A1') # optional - sage.combinat sage.modules - sage: V.gens() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: V = lie_conformal_algebras.Affine(QQ, 'A1') + sage: V.gens() (B[alpha[1]], B[alphacheck[1]], B[-alpha[1]], B['K']) - sage: E = V.0; H = V.1; F = V.2 # optional - sage.combinat sage.modules - sage: H.bracket(H) # optional - sage.combinat sage.modules + sage: E = V.0; H = V.1; F = V.2 + sage: H.bracket(H) {1: 2*B['K']} - sage: E.bracket(F) # optional - sage.combinat sage.modules + sage: E.bracket(F) {0: B[alphacheck[1]], 1: B['K']} """ return self._bracket_(rhs) @@ -171,21 +172,22 @@ def _bracket_(self, rhs): The brackets of the Virasoro Lie conformal Algebra:: - sage: Vir = lie_conformal_algebras.Virasoro(QQ); L = Vir.0 # optional - sage.combinat sage.modules - sage: L._bracket_(L) # optional - sage.combinat sage.modules + sage: Vir = lie_conformal_algebras.Virasoro(QQ); L = Vir.0 # needs sage.combinat sage.modules + sage: L._bracket_(L) # needs sage.combinat sage.modules {0: TL, 1: 2*L, 3: 1/2*C} - sage: L._bracket_(L.T()) # optional - sage.combinat sage.modules + sage: L._bracket_(L.T()) # needs sage.combinat sage.modules {0: 2*T^(2)L, 1: 3*TL, 2: 4*L, 4: 2*C} Now with a current algebra:: - sage: V = lie_conformal_algebras.Affine(QQ, 'A1') # optional - sage.combinat sage.modules - sage: V.gens() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: V = lie_conformal_algebras.Affine(QQ, 'A1') + sage: V.gens() (B[alpha[1]], B[alphacheck[1]], B[-alpha[1]], B['K']) - sage: E = V.0; H = V.1; F = V.2 # optional - sage.combinat sage.modules - sage: H._bracket_(H) # optional - sage.combinat sage.modules + sage: E = V.0; H = V.1; F = V.2 + sage: H._bracket_(H) {1: 2*B['K']} - sage: E._bracket_(F) # optional - sage.combinat sage.modules + sage: E._bracket_(F) {0: B[alphacheck[1]], 1: B['K']} """ @@ -196,16 +198,17 @@ def nproduct(self, rhs, n): EXAMPLES:: - sage: Vir = lie_conformal_algebras.Virasoro(QQ); L = Vir.0 # optional - sage.combinat sage.modules - sage: L.nproduct(L, 3) # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: Vir = lie_conformal_algebras.Virasoro(QQ); L = Vir.0 + sage: L.nproduct(L, 3) 1/2*C - sage: L.nproduct(L.T(), 0) # optional - sage.combinat sage.modules + sage: L.nproduct(L.T(), 0) 2*T^(2)L - sage: V = lie_conformal_algebras.Affine(QQ, 'A1') # optional - sage.combinat sage.modules - sage: E = V.0; H = V.1; F = V.2 # optional - sage.combinat sage.modules - sage: E.nproduct(H, 0) == - 2*E # optional - sage.combinat sage.modules + sage: V = lie_conformal_algebras.Affine(QQ, 'A1') + sage: E = V.0; H = V.1; F = V.2 + sage: E.nproduct(H, 0) == - 2*E True - sage: E.nproduct(F, 1) # optional - sage.combinat sage.modules + sage: E.nproduct(F, 1) B['K'] """ return self._nproduct_(rhs,n) @@ -221,16 +224,17 @@ def _nproduct_(self, rhs, n): EXAMPLES:: - sage: Vir = lie_conformal_algebras.Virasoro(QQ); L = Vir.0 # optional - sage.combinat sage.modules - sage: L._nproduct_(L, 3) # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: Vir = lie_conformal_algebras.Virasoro(QQ); L = Vir.0 + sage: L._nproduct_(L, 3) 1/2*C - sage: L._nproduct_(L.T(), 0) # optional - sage.combinat sage.modules + sage: L._nproduct_(L.T(), 0) 2*T^(2)L - sage: V = lie_conformal_algebras.Affine(QQ, 'A1') # optional - sage.combinat sage.modules - sage: E = V.0; H = V.1; F = V.2 # optional - sage.combinat sage.modules - sage: E._nproduct_(H, 0) == - 2*E # optional - sage.combinat sage.modules + sage: V = lie_conformal_algebras.Affine(QQ, 'A1') + sage: E = V.0; H = V.1; F = V.2 + sage: E._nproduct_(H, 0) == - 2*E True - sage: E._nproduct_(F, 1) # optional - sage.combinat sage.modules + sage: E._nproduct_(F, 1) B['K'] """ if n >= 0: @@ -255,14 +259,15 @@ def T(self, n=1): EXAMPLES:: - sage: Vir = lie_conformal_algebras.Virasoro(QQ) # optional - sage.combinat sage.modules - sage: Vir.inject_variables() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: Vir = lie_conformal_algebras.Virasoro(QQ) + sage: Vir.inject_variables() Defining L, C - sage: L.T() # optional - sage.combinat sage.modules + sage: L.T() TL - sage: L.T(3) # optional - sage.combinat sage.modules + sage: L.T(3) 6*T^(3)L - sage: C.T() # optional - sage.combinat sage.modules + sage: C.T() 0 """ diff --git a/src/sage/categories/lambda_bracket_algebras_with_basis.py b/src/sage/categories/lambda_bracket_algebras_with_basis.py index bb0e30908b4..62fe41f3336 100644 --- a/src/sage/categories/lambda_bracket_algebras_with_basis.py +++ b/src/sage/categories/lambda_bracket_algebras_with_basis.py @@ -25,7 +25,7 @@ class LambdaBracketAlgebrasWithBasis(CategoryWithAxiom_over_base_ring): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).WithBasis() # optional - sage.rings.number_field + sage: LieConformalAlgebras(QQbar).WithBasis() # needs sage.rings.number_field Category of Lie conformal algebras with basis over Algebraic Field """ class ElementMethods: @@ -36,14 +36,15 @@ def index(self): EXAMPLES:: - sage: V = lie_conformal_algebras.NeveuSchwarz(QQ) # optional - sage.combinat sage.modules - sage: V.inject_variables() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: V = lie_conformal_algebras.NeveuSchwarz(QQ) + sage: V.inject_variables() Defining L, G, C - sage: G.T(3).index() # optional - sage.combinat sage.modules + sage: G.T(3).index() ('G', 3) - sage: v = V.an_element(); v # optional - sage.combinat sage.modules + sage: v = V.an_element(); v L + G + C - sage: v.index() # optional - sage.combinat sage.modules + sage: v.index() Traceback (most recent call last): ... ValueError: index can only be computed for monomials, got L + G + C @@ -63,14 +64,15 @@ class FinitelyGeneratedAsLambdaBracketAlgebra(CategoryWithAxiom_over_base_ring): EXAMPLES:: - sage: C = LieConformalAlgebras(QQbar) # optional - sage.rings.number_field - sage: C1 = C.WithBasis().FinitelyGenerated(); C1 # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + sage: C = LieConformalAlgebras(QQbar) + sage: C1 = C.WithBasis().FinitelyGenerated(); C1 Category of finitely generated Lie conformal algebras with basis over Algebraic Field - sage: C2 = C.FinitelyGenerated().WithBasis(); C2 # optional - sage.rings.number_field + sage: C2 = C.FinitelyGenerated().WithBasis(); C2 Category of finitely generated Lie conformal algebras with basis over Algebraic Field - sage: C1 is C2 # optional - sage.rings.number_field + sage: C1 is C2 True """ class Graded(GradedModulesCategory): @@ -80,8 +82,8 @@ class Graded(GradedModulesCategory): EXAMPLES:: - sage: C = LieConformalAlgebras(QQbar) # optional - sage.rings.number_field - sage: C.WithBasis().FinitelyGenerated().Graded() # optional - sage.rings.number_field + sage: C = LieConformalAlgebras(QQbar) # needs sage.rings.number_field + sage: C.WithBasis().FinitelyGenerated().Graded() # needs sage.rings.number_field Category of H-graded finitely generated Lie conformal algebras with basis over Algebraic Field """ @@ -94,8 +96,8 @@ def degree_on_basis(self, m): EXAMPLES:: - sage: V = lie_conformal_algebras.Virasoro(QQ) # optional - sage.combinat sage.modules - sage: V.degree_on_basis(('L', 2)) # optional - sage.combinat sage.modules + sage: V = lie_conformal_algebras.Virasoro(QQ) # needs sage.combinat sage.modules + sage: V.degree_on_basis(('L', 2)) # needs sage.combinat sage.modules 4 """ if m[0] in self._central_elements: diff --git a/src/sage/categories/lattice_posets.py b/src/sage/categories/lattice_posets.py index 3872ca9b51f..f14fa364415 100644 --- a/src/sage/categories/lattice_posets.py +++ b/src/sage/categories/lattice_posets.py @@ -66,8 +66,8 @@ def meet(self, x, y): EXAMPLES:: - sage: D = LatticePoset((divisors(30), attrcall("divides"))) # optional - sage.combinat - sage: D.meet( D(6), D(15) ) # optional - sage.combinat + sage: D = LatticePoset((divisors(30), attrcall("divides"))) # needs sage.graphs sage.modules + sage: D.meet( D(6), D(15) ) # needs sage.graphs sage.modules 3 """ @@ -82,7 +82,7 @@ def join(self, x, y): EXAMPLES:: - sage: D = LatticePoset((divisors(60), attrcall("divides"))) # optional - sage.combinat - sage: D.join( D(6), D(10) ) # optional - sage.combinat + sage: D = LatticePoset((divisors(60), attrcall("divides"))) # needs sage.graphs sage.modules + sage: D.join( D(6), D(10) ) # needs sage.graphs sage.modules 30 """ diff --git a/src/sage/categories/lie_algebras.py b/src/sage/categories/lie_algebras.py index 0bd0c3185e7..7244eab161b 100644 --- a/src/sage/categories/lie_algebras.py +++ b/src/sage/categories/lie_algebras.py @@ -70,8 +70,8 @@ class LieAlgebras(Category_over_base_ring): TESTS:: - sage: C = LieAlgebras(QQ) # needs sage.combinat sage.modules - sage: TestSuite(C).run() # needs sage.combinat sage.modules + sage: C = LieAlgebras(QQ) + sage: TestSuite(C).run() sage: TestSuite(C.example()).run() # needs sage.combinat sage.modules .. TODO:: @@ -189,14 +189,14 @@ def extra_super_categories(self): [Category of finite sets] sage: LieAlgebras(ZZ).FiniteDimensional().extra_super_categories() [] - sage: C = LieAlgebras(GF(5)).FiniteDimensional() # needs sage.rings.finite_rings - sage: C.is_subcategory(Sets().Finite()) # needs sage.rings.finite_rings + sage: C = LieAlgebras(GF(5)).FiniteDimensional() + sage: C.is_subcategory(Sets().Finite()) True sage: C = LieAlgebras(ZZ).FiniteDimensional() sage: C.is_subcategory(Sets().Finite()) False - sage: C = LieAlgebras(GF(5)).WithBasis().FiniteDimensional() # needs sage.rings.finite_rings - sage: C.is_subcategory(Sets().Finite()) # needs sage.rings.finite_rings + sage: C = LieAlgebras(GF(5)).WithBasis().FiniteDimensional() + sage: C.is_subcategory(Sets().Finite()) True """ if self.base_ring() in Sets().Finite(): @@ -209,8 +209,8 @@ class Nilpotent(CategoryWithAxiom_over_base_ring): TESTS:: - sage: C = LieAlgebras(QQ).Nilpotent() # needs sage.combinat sage.modules - sage: TestSuite(C).run() # needs sage.combinat sage.modules + sage: C = LieAlgebras(QQ).Nilpotent() + sage: TestSuite(C).run() """ class ParentMethods: @abstract_method @@ -301,7 +301,7 @@ def universal_enveloping_algebra(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.modules sage: L.universal_enveloping_algebra() # needs sage.combinat sage.modules Noncommutative Multivariate Polynomial Ring in b0, b1, b2 over Rational Field, nc-relations: {} @@ -334,7 +334,7 @@ def _construct_UEA(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.modules sage: L._construct_UEA() # needs sage.combinat sage.modules Noncommutative Multivariate Polynomial Ring in b0, b1, b2 over Rational Field, nc-relations: {} @@ -342,7 +342,7 @@ def _construct_UEA(self): :: sage: L = LieAlgebra(QQ, 3, 'x', abelian=True) # needs sage.combinat sage.modules - sage: L.universal_enveloping_algebra() # indirect doctest # needs sage.combinat sage.modules + sage: L.universal_enveloping_algebra() # indirect doctest # needs sage.combinat sage.modules Multivariate Polynomial Ring in x0, x1, x2 over Rational Field """ @@ -398,8 +398,8 @@ def module(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.combinat sage.modules - sage: L.module() # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.modules + sage: L.module() # needs sage.modules Vector space of dimension 3 over Rational Field """ @@ -414,10 +414,10 @@ def from_vector(self, v, order=None, coerce=False): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.combinat sage.modules - sage: u = L.from_vector(vector(QQ, (1, 0, 0))); u # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.modules + sage: u = L.from_vector(vector(QQ, (1, 0, 0))); u # needs sage.modules (1, 0, 0) - sage: parent(u) is L # needs sage.combinat sage.modules + sage: parent(u) is L # needs sage.modules True """ @@ -452,9 +452,9 @@ def subalgebra(self, gens, names=None, index_set=None, category=None): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.combinat sage.modules - sage: a, b, c = L.lie_algebra_generators() # needs sage.combinat sage.modules - sage: L.subalgebra([2*a - c, b + c]) # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.modules + sage: a, b, c = L.lie_algebra_generators() # needs sage.modules + sage: L.subalgebra([2*a - c, b + c]) # needs sage.modules An example of a finite dimensional Lie algebra with basis: the 2-dimensional abelian Lie algebra over Rational Field with basis matrix: @@ -480,9 +480,9 @@ def ideal(self, *gens, **kwds): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.combinat sage.modules - sage: a, b, c = L.lie_algebra_generators() # needs sage.combinat sage.modules - sage: L.ideal([2*a - c, b + c]) # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.modules + sage: a, b, c = L.lie_algebra_generators() # needs sage.modules + sage: L.ideal([2*a - c, b + c]) # needs sage.modules An example of a finite dimensional Lie algebra with basis: the 2-dimensional abelian Lie algebra over Rational Field with basis matrix: @@ -530,9 +530,9 @@ def killing_form(self, x, y): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.combinat sage.modules - sage: a, b, c = L.lie_algebra_generators() # needs sage.combinat sage.modules - sage: L.killing_form(a, b + c) # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.modules + sage: a, b, c = L.lie_algebra_generators() # needs sage.modules + sage: L.killing_form(a, b + c) # needs sage.modules 0 """ @@ -596,8 +596,8 @@ def is_solvable(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.combinat sage.modules - sage: L.is_solvable() # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.modules + sage: L.is_solvable() # needs sage.modules True """ @@ -608,8 +608,8 @@ def is_nilpotent(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.combinat sage.modules - sage: L.is_nilpotent() # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.modules + sage: L.is_nilpotent() # needs sage.modules True """ @@ -866,10 +866,10 @@ def to_vector(self, order=None): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.combinat sage.modules - sage: u = L((1, 0, 0)).to_vector(); u # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.modules + sage: u = L((1, 0, 0)).to_vector(); u # needs sage.modules (1, 0, 0) - sage: parent(u) # needs sage.combinat sage.modules + sage: parent(u) # needs sage.modules Vector space of dimension 3 over Rational Field """ @@ -901,9 +901,9 @@ def killing_form(self, x): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.combinat sage.modules - sage: a, b, c = L.lie_algebra_generators() # needs sage.combinat sage.modules - sage: a.killing_form(b) # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.modules + sage: a, b, c = L.lie_algebra_generators() # needs sage.modules + sage: a.killing_form(b) # needs sage.modules 0 """ return self.parent().killing_form(self, x) @@ -959,7 +959,7 @@ def __init__(self, domain, codomain): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.modules sage: f = L.lift # needs sage.combinat sage.modules We skip the category test since this is currently not an element of @@ -975,8 +975,8 @@ def _call_(self, x): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.combinat sage.modules - sage: a, b, c = L.lie_algebra_generators() # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.modules + sage: a, b, c = L.lie_algebra_generators() # needs sage.modules sage: L.lift(3*a + b - c) # needs sage.combinat sage.modules 3*b0 + b1 - b2 """ diff --git a/src/sage/categories/lie_algebras_with_basis.py b/src/sage/categories/lie_algebras_with_basis.py index 4f6cf394651..6eaebfde844 100644 --- a/src/sage/categories/lie_algebras_with_basis.py +++ b/src/sage/categories/lie_algebras_with_basis.py @@ -34,13 +34,13 @@ def example(self, gens=None): EXAMPLES:: - sage: LieAlgebras(QQ).WithBasis().example() # optional - sage.combinat + sage: LieAlgebras(QQ).WithBasis().example() # needs sage.combinat sage.modules An example of a Lie algebra: the abelian Lie algebra on the generators indexed by Partitions over Rational Field Another set of generators can be specified as an optional argument:: - sage: LieAlgebras(QQ).WithBasis().example(Compositions()) # optional - sage.combinat + sage: LieAlgebras(QQ).WithBasis().example(Compositions()) # needs sage.combinat sage.modules An example of a Lie algebra: the abelian Lie algebra on the generators indexed by Compositions of non-negative integers over Rational Field @@ -64,8 +64,8 @@ def _basis_key(self, x): TESTS:: - sage: L = LieAlgebras(QQ).WithBasis().example() # optional - sage.combinat - sage: L._basis_key(Partition([3,1])) # optional - sage.combinat + sage: L = LieAlgebras(QQ).WithBasis().example() # needs sage.combinat sage.modules + sage: L._basis_key(Partition([3,1])) # needs sage.combinat sage.modules [3, 1] """ return x @@ -79,8 +79,8 @@ def bracket_on_basis(self, x, y): EXAMPLES:: - sage: L = LieAlgebras(QQ).WithBasis().example() # optional - sage.combinat - sage: L.bracket_on_basis(Partition([3,1]), Partition([2,2,1,1])) # optional - sage.combinat + sage: L = LieAlgebras(QQ).WithBasis().example() # needs sage.combinat sage.modules + sage: L.bracket_on_basis(Partition([3,1]), Partition([2,2,1,1])) # needs sage.combinat sage.modules 0 """ @@ -95,8 +95,8 @@ def module(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).WithBasis().example() # optional - sage.combinat - sage: L.module() # optional - sage.combinat + sage: L = LieAlgebras(QQ).WithBasis().example() # needs sage.combinat sage.modules + sage: L.module() # needs sage.combinat sage.modules Free module generated by Partitions over Rational Field """ from sage.combinat.free_module import CombinatorialFreeModule @@ -119,10 +119,10 @@ def from_vector(self, v, order=None, coerce=False): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat - sage: u = L.from_vector(vector(QQ, (1, 0, 0))); u # optional - sage.combinat + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.modules + sage: u = L.from_vector(vector(QQ, (1, 0, 0))); u # needs sage.modules (1, 0, 0) - sage: parent(u) is L # optional - sage.combinat + sage: parent(u) is L # needs sage.modules True """ B = self.basis() @@ -135,14 +135,14 @@ def dimension(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat - sage: L.dimension() # optional - sage.combinat + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.modules + sage: L.dimension() # needs sage.modules 3 :: - sage: L = LieAlgebra(QQ, 'x,y', {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules - sage: L.dimension() # optional - sage.combinat sage.modules + sage: L = LieAlgebra(QQ, 'x,y', {('x','y'): {'x':1}}) # needs sage.combinat sage.modules + sage: L.dimension() # needs sage.combinat sage.modules 2 """ return self.basis().cardinality() @@ -154,8 +154,8 @@ def pbw_basis(self, basis_key=None, **kwds): EXAMPLES:: - sage: L = lie_algebras.sl(QQ, 2) # optional - sage.combinat sage.modules - sage: PBW = L.pbw_basis() # optional - sage.combinat sage.modules + sage: L = lie_algebras.sl(QQ, 2) # needs sage.combinat sage.modules + sage: PBW = L.pbw_basis() # needs sage.combinat sage.modules """ from sage.algebras.lie_algebras.poincare_birkhoff_witt \ import PoincareBirkhoffWittBasis @@ -173,11 +173,12 @@ def _bracket_(self, y): EXAMPLES:: - sage: L = LieAlgebras(QQ).WithBasis().example() # optional - sage.combinat - sage: G = L.lie_algebra_generators() # optional - sage.combinat - sage: x = G[Partition([4,3,3,1])] # optional - sage.combinat - sage: y = G[Partition([6,1])] # optional - sage.combinat - sage: x.bracket(y) # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: L = LieAlgebras(QQ).WithBasis().example() + sage: G = L.lie_algebra_generators() + sage: x = G[Partition([4,3,3,1])] + sage: y = G[Partition([6,1])] + sage: x.bracket(y) 0 """ P = self.parent() @@ -206,8 +207,8 @@ def to_vector(self, order=None): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules - sage: L.an_element().to_vector() # optional - sage.modules + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # needs sage.modules + sage: L.an_element().to_vector() # needs sage.modules (0, 0, 0) .. TODO:: @@ -224,15 +225,16 @@ def lift(self): EXAMPLES:: - sage: S = SymmetricGroup(3).algebra(QQ) # optional - sage.groups - sage: L = LieAlgebra(associative=S) # optional - sage.groups - sage: x = L.gen(3) # optional - sage.groups - sage: y = L.gen(1) # optional - sage.groups - sage: x.lift() # optional - sage.groups + sage: # needs sage.groups + sage: S = SymmetricGroup(3).algebra(QQ) + sage: L = LieAlgebra(associative=S) + sage: x = L.gen(3) + sage: y = L.gen(1) + sage: x.lift() b3 - sage: y.lift() # optional - sage.groups + sage: y.lift() b1 - sage: x * y # optional - sage.groups + sage: x * y b1*b3 + b4 - b5 """ P = self.parent() diff --git a/src/sage/categories/lie_conformal_algebras.py b/src/sage/categories/lie_conformal_algebras.py index 4e59d4758b0..ee48889dd0b 100644 --- a/src/sage/categories/lie_conformal_algebras.py +++ b/src/sage/categories/lie_conformal_algebras.py @@ -152,16 +152,16 @@ class LieConformalAlgebras(Category_over_base_ring): Some subcategories:: - sage: LieConformalAlgebras(QQbar).FinitelyGenerated().WithBasis() # optional - sage.rings.number_field + sage: LieConformalAlgebras(QQbar).FinitelyGenerated().WithBasis() # needs sage.rings.number_field Category of finitely generated Lie conformal algebras with basis over Algebraic Field In addition we support functorial constructions ``Graded`` and ``Super``. These functors commute:: - sage: CGS = LieConformalAlgebras(AA).Graded().Super(); CGS # optional - sage.rings.number_field + sage: CGS = LieConformalAlgebras(AA).Graded().Super(); CGS # needs sage.rings.number_field Category of H-graded super Lie conformal algebras over Algebraic Real Field - sage: CGS is LieConformalAlgebras(AA).Super().Graded() # optional - sage.rings.number_field + sage: CGS is LieConformalAlgebras(AA).Super().Graded() # needs sage.rings.number_field True That is, we only consider gradings on super Lie conformal algebras @@ -169,7 +169,7 @@ class LieConformalAlgebras(Category_over_base_ring): The base ring needs to be a commutative ring:: - sage: LieConformalAlgebras(QuaternionAlgebra(2)) # optional - sage.combinat sage.modules + sage: LieConformalAlgebras(QuaternionAlgebra(2)) # needs sage.combinat sage.modules Traceback (most recent call last): ValueError: base must be a commutative ring got Quaternion Algebra (-1, -1) with base ring Rational Field @@ -221,7 +221,7 @@ def example(self): EXAMPLES:: - sage: LieConformalAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: LieConformalAlgebras(QQ).example() # needs sage.combinat sage.modules The Virasoro Lie conformal algebra over Rational Field """ from sage.algebras.lie_conformal_algebras.virasoro_lie_conformal_algebra\ @@ -254,27 +254,28 @@ def _test_jacobi(self, **options): By default, this method tests only the elements returned by ``self.some_elements()``:: - sage: V = lie_conformal_algebras.Affine(QQ, 'B2') # optional - sage.combinat sage.modules - sage: V._test_jacobi() # long time (6 seconds) # optional - sage.combinat sage.modules + sage: V = lie_conformal_algebras.Affine(QQ, 'B2') # needs sage.combinat sage.modules + sage: V._test_jacobi() # long time (6 seconds) # needs sage.combinat sage.modules It works for super Lie conformal algebras too:: - sage: V = lie_conformal_algebras.NeveuSchwarz(QQ) # optional - sage.combinat sage.modules - sage: V._test_jacobi() # optional - sage.combinat sage.modules + sage: V = lie_conformal_algebras.NeveuSchwarz(QQ) # needs sage.combinat sage.modules + sage: V._test_jacobi() # needs sage.combinat sage.modules We can use specific elements by passing the ``elements`` keyword argument:: - sage: V = lie_conformal_algebras.Affine(QQ, 'A1', names=('e', 'h', 'f')) # optional - sage.combinat sage.modules - sage: V.inject_variables() # optional - sage.combinat sage.modules + sage: V = lie_conformal_algebras.Affine(QQ, 'A1', # needs sage.combinat sage.modules + ....: names=('e', 'h', 'f')) + sage: V.inject_variables() # needs sage.combinat sage.modules Defining e, h, f, K - sage: V._test_jacobi(elements=(e, 2*f+h, 3*h)) # optional - sage.combinat sage.modules + sage: V._test_jacobi(elements=(e, 2*f+h, 3*h)) # needs sage.combinat sage.modules TESTS:: sage: wrongdict = {('a', 'a'): {0: {('b', 0): 1}}, ('b', 'a'): {0: {('a', 0): 1}}} - sage: V = LieConformalAlgebra(QQ, wrongdict, names=('a', 'b'), parity=(1, 0)) # optional - sage.combinat sage.modules - sage: V._test_jacobi() # optional - sage.combinat sage.modules + sage: V = LieConformalAlgebra(QQ, wrongdict, names=('a', 'b'), parity=(1, 0)) # needs sage.combinat sage.modules + sage: V._test_jacobi() # needs sage.combinat sage.modules Traceback (most recent call last): ... AssertionError: {(0, 0): -3*a} != {} @@ -325,10 +326,10 @@ def is_even_odd(self): EXAMPLES:: - sage: R = lie_conformal_algebras.NeveuSchwarz(QQ) # optional - sage.combinat sage.modules - sage: R.inject_variables() # optional - sage.combinat sage.modules + sage: R = lie_conformal_algebras.NeveuSchwarz(QQ) # needs sage.combinat sage.modules + sage: R.inject_variables() # needs sage.combinat sage.modules Defining L, G, C - sage: G.is_even_odd() # optional - sage.combinat sage.modules + sage: G.is_even_odd() # needs sage.combinat sage.modules 1 """ return 0 diff --git a/src/sage/categories/lie_conformal_algebras_with_basis.py b/src/sage/categories/lie_conformal_algebras_with_basis.py index 6f31b6b4cca..bedf8934fc4 100644 --- a/src/sage/categories/lie_conformal_algebras_with_basis.py +++ b/src/sage/categories/lie_conformal_algebras_with_basis.py @@ -27,7 +27,7 @@ class LieConformalAlgebrasWithBasis(CategoryWithAxiom_over_base_ring): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).WithBasis() # optional - sage.rings.number_field + sage: LieConformalAlgebras(QQbar).WithBasis() # needs sage.rings.number_field Category of Lie conformal algebras with basis over Algebraic Field """ class Super(SuperModulesCategory): @@ -36,7 +36,7 @@ class Super(SuperModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(AA).WithBasis().Super() # optional - sage.rings.number_field + sage: LieConformalAlgebras(AA).WithBasis().Super() # needs sage.rings.number_field Category of super Lie conformal algebras with basis over Algebraic Real Field """ @@ -53,9 +53,9 @@ def _even_odd_on_basis(self, m): EXAMPLES:: - sage: V = lie_conformal_algebras.NeveuSchwarz(QQ) # optional - sage.combinat sage.modules - sage: B = V._indices # optional - sage.combinat sage.modules - sage: V._even_odd_on_basis(B(('G', 1))) # optional - sage.combinat sage.modules + sage: V = lie_conformal_algebras.NeveuSchwarz(QQ) # needs sage.combinat sage.modules + sage: B = V._indices # needs sage.combinat sage.modules + sage: V._even_odd_on_basis(B(('G', 1))) # needs sage.combinat sage.modules 1 """ return self._parity[self.monomial((m[0],0))] @@ -66,7 +66,7 @@ class Graded(GradedLieConformalAlgebrasCategory): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).WithBasis().Super().Graded() # optional - sage.rings.number_field + sage: LieConformalAlgebras(QQbar).WithBasis().Super().Graded() # needs sage.rings.number_field Category of H-graded super Lie conformal algebras with basis over Algebraic Field """ @@ -77,7 +77,7 @@ class Graded(GradedLieConformalAlgebrasCategory): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).WithBasis().Graded() # optional - sage.rings.number_field + sage: LieConformalAlgebras(QQbar).WithBasis().Graded() # needs sage.rings.number_field Category of H-graded Lie conformal algebras with basis over Algebraic Field """ @@ -88,11 +88,11 @@ class FinitelyGeneratedAsLambdaBracketAlgebra(CategoryWithAxiom_over_base_ring): EXAMPLES:: - sage: C = LieConformalAlgebras(QQbar) # optional - sage.rings.number_field - sage: CWF = C.WithBasis().FinitelyGenerated(); CWF # optional - sage.rings.number_field + sage: C = LieConformalAlgebras(QQbar) # needs sage.rings.number_field + sage: CWF = C.WithBasis().FinitelyGenerated(); CWF # needs sage.rings.number_field Category of finitely generated Lie conformal algebras with basis over Algebraic Field - sage: CWF is C.FinitelyGenerated().WithBasis() # optional - sage.rings.number_field + sage: CWF is C.FinitelyGenerated().WithBasis() # needs sage.rings.number_field True """ class Super(SuperModulesCategory): @@ -102,7 +102,7 @@ class Super(SuperModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(AA).WithBasis().FinitelyGenerated().Super() # optional - sage.rings.number_field + sage: LieConformalAlgebras(AA).WithBasis().FinitelyGenerated().Super() # needs sage.rings.number_field Category of super finitely generated Lie conformal algebras with basis over Algebraic Real Field """ @@ -113,11 +113,11 @@ class Graded(GradedModulesCategory): EXAMPLES:: - sage: C = LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated() # optional - sage.rings.number_field - sage: C.Graded().Super() # optional - sage.rings.number_field + sage: C = LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated() # needs sage.rings.number_field + sage: C.Graded().Super() # needs sage.rings.number_field Category of H-graded super finitely generated Lie conformal algebras with basis over Algebraic Field - sage: C.Graded().Super() is C.Super().Graded() # optional - sage.rings.number_field + sage: C.Graded().Super() is C.Super().Graded() # needs sage.rings.number_field True """ def _repr_object_names(self): @@ -126,8 +126,8 @@ def _repr_object_names(self): EXAMPLES:: - sage: C = LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated() # optional - sage.rings.number_field - sage: C.Super().Graded() # optional - sage.rings.number_field + sage: C = LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated() # needs sage.rings.number_field + sage: C.Super().Graded() # needs sage.rings.number_field Category of H-graded super finitely generated Lie conformal algebras with basis over Algebraic Field """ return "H-graded {}".format(self.base_category()._repr_object_names()) @@ -139,7 +139,7 @@ class Graded(GradedLieConformalAlgebrasCategory): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() # optional - sage.rings.number_field + sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() # needs sage.rings.number_field Category of H-graded finitely generated Lie conformal algebras with basis over Algebraic Field """ diff --git a/src/sage/categories/loop_crystals.py b/src/sage/categories/loop_crystals.py index 83c403323cd..ad49bd42892 100644 --- a/src/sage/categories/loop_crystals.py +++ b/src/sage/categories/loop_crystals.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.graphs sage.combinat +# sage.doctest: needs sage.graphs sage.combinat r""" Loop Crystals """ diff --git a/src/sage/categories/magmas.py b/src/sage/categories/magmas.py index 178361b2961..603e68ad186 100644 --- a/src/sage/categories/magmas.py +++ b/src/sage/categories/magmas.py @@ -383,11 +383,11 @@ def is_field(self, proof=True): EXAMPLES:: - sage: SymmetricGroup(1).algebra(QQ).is_field() # optional - sage.groups + sage: SymmetricGroup(1).algebra(QQ).is_field() # needs sage.groups True - sage: SymmetricGroup(1).algebra(ZZ).is_field() # optional - sage.groups + sage: SymmetricGroup(1).algebra(ZZ).is_field() # needs sage.groups False - sage: SymmetricGroup(2).algebra(QQ).is_field() # optional - sage.groups + sage: SymmetricGroup(2).algebra(QQ).is_field() # needs sage.groups False """ if not self.base_ring().is_field(proof): @@ -540,8 +540,8 @@ def is_empty(self): EXAMPLES:: - sage: S = SymmetricGroup(2) # optional - sage.groups - sage: S.is_empty() # optional - sage.groups + sage: S = SymmetricGroup(2) # needs sage.groups + sage: S.is_empty() # needs sage.groups False sage: M = Monoids().example() @@ -550,7 +550,7 @@ def is_empty(self): TESTS:: - sage: S.is_empty.__module__ # optional - sage.groups + sage: S.is_empty.__module__ # needs sage.groups 'sage.categories.magmas' sage: M.is_empty.__module__ 'sage.categories.magmas' @@ -638,7 +638,7 @@ def one(self): EXAMPLES:: - sage: cartesian_product([QQ, ZZ, RR]).one() + sage: cartesian_product([QQ, ZZ, RR]).one() # needs sage.rings.real_mpfr (1, 1, 1.00000000000000) """ return self._cartesian_product_of_elements( @@ -665,21 +665,21 @@ def __invert__(self): EXAMPLES:: - sage: C = cartesian_product([QQ, ZZ, RR, GF(5)]) # optional - sage.rings.finite_rings - sage: c = C([2,-1,2,2]); c # optional - sage.rings.finite_rings + sage: C = cartesian_product([QQ, ZZ, RR, GF(5)]) + sage: c = C([2,-1,2,2]); c # needs sage.rings.real_mpfr (2, -1, 2.00000000000000, 2) - sage: ~c # optional - sage.rings.finite_rings + sage: ~c # needs sage.rings.real_mpfr (1/2, -1, 0.500000000000000, 3) This fails as soon as one of the entries is not invertible:: - sage: ~C([0,2,2,2]) # optional - sage.rings.finite_rings + sage: ~C([0,2,2,2]) Traceback (most recent call last): ... ZeroDivisionError: rational division by zero - sage: ~C([2,2,2,2]) # optional - sage.rings.finite_rings + sage: ~C([2,2,2,2]) # needs sage.rings.real_mpfr (1/2, 1/2, 0.500000000000000, 3) """ # variant without coercion: @@ -724,11 +724,12 @@ def one(self): EXAMPLES:: - sage: from sage.combinat.root_system.extended_affine_weyl_group import ExtendedAffineWeylGroup # optional - sage.combinat sage.groups - sage: PvW0 = ExtendedAffineWeylGroup(['A',2,1]).PvW0() # optional - sage.combinat sage.groups - sage: PvW0 in Magmas().Unital().Realizations() # optional - sage.combinat sage.groups + sage: # needs sage.combinat sage.groups + sage: from sage.combinat.root_system.extended_affine_weyl_group import ExtendedAffineWeylGroup + sage: PvW0 = ExtendedAffineWeylGroup(['A',2,1]).PvW0() + sage: PvW0 in Magmas().Unital().Realizations() True - sage: PvW0.one() # optional - sage.combinat sage.groups + sage: PvW0.one() 1 """ return self(self.realization_of().a_realization().one()) @@ -884,8 +885,8 @@ def multiplication_table(self, names='letters', elements=None): The default is to represent elements as lowercase ASCII letters. :: - sage: G = CyclicPermutationGroup(5) # optional - sage.groups - sage: G.multiplication_table() # optional - sage.groups + sage: G = CyclicPermutationGroup(5) # needs sage.groups + sage: G.multiplication_table() # needs sage.groups * a b c d e +---------- a| a b c d e @@ -902,10 +903,10 @@ def multiplication_table(self, names='letters', elements=None): sage: from sage.categories.examples.finite_semigroups import LeftRegularBand sage: L = LeftRegularBand(('a', 'b')) - sage: T = L.multiplication_table(names='digits') # optional - sage.modules - sage: T.column_keys() # optional - sage.modules + sage: T = L.multiplication_table(names='digits') # needs sage.modules + sage: T.column_keys() # needs sage.modules ('a', 'ab', 'b', 'ba') - sage: T # optional - sage.modules + sage: T # needs sage.modules * 0 1 2 3 +-------- 0| 0 1 1 1 @@ -918,7 +919,7 @@ def multiplication_table(self, names='letters', elements=None): sage: L = LeftRegularBand(('a', 'b', 'c')) sage: elts = sorted(L.list()) - sage: L.multiplication_table(elements=elts) # optional - sage.modules + sage: L.multiplication_table(elements=elts) # needs sage.modules * a b c d e f g h i j k l m n o +------------------------------ a| a b c d e b b c c c d d e e e @@ -947,7 +948,7 @@ def multiplication_table(self, names='letters', elements=None): sage: L = LeftRegularBand(('a','b','c')) sage: elts=['a', 'c', 'ac', 'ca'] - sage: L.multiplication_table(names='elements', elements=elts) # optional - sage.modules + sage: L.multiplication_table(names='elements', elements=elts) # needs sage.modules * 'a' 'c' 'ac' 'ca' +-------------------- 'a'| 'a' 'ac' 'ac' 'ac' @@ -960,16 +961,17 @@ def multiplication_table(self, names='letters', elements=None): :class:`~sage.matrix.operation_table.OperationTable` for more comprehensive documentation. :: - sage: G = AlternatingGroup(3) # optional - sage.groups - sage: T = G.multiplication_table() # optional - sage.groups sage.modules - sage: T.column_keys() # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: G = AlternatingGroup(3) + sage: T = G.multiplication_table() + sage: T.column_keys() ((), (1,2,3), (1,3,2)) - sage: T.translation() # optional - sage.groups sage.modules + sage: T.translation() {'a': (), 'b': (1,2,3), 'c': (1,3,2)} - sage: T.change_names(['x', 'y', 'z']) # optional - sage.groups sage.modules - sage: T.translation() # optional - sage.groups sage.modules + sage: T.change_names(['x', 'y', 'z']) + sage: T.translation() {'x': (), 'y': (1,2,3), 'z': (1,3,2)} - sage: T # optional - sage.groups sage.modules + sage: T * x y z +------ x| x y z @@ -1084,12 +1086,13 @@ def product(self, left, right): sage: x * x (1/4, 1, 1) - sage: A = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups - sage: x = cartesian_product([A([1,3,2]), A([2,3,1])]) # optional - sage.groups - sage: y = cartesian_product([A([1,3,2]), A([2,3,1])]) # optional - sage.groups - sage: cartesian_product([A,A]).product(x,y) # optional - sage.groups + sage: # needs sage.groups sage.modules + sage: A = SymmetricGroupAlgebra(QQ, 3) + sage: x = cartesian_product([A([1,3,2]), A([2,3,1])]) + sage: y = cartesian_product([A([1,3,2]), A([2,3,1])]) + sage: cartesian_product([A,A]).product(x,y) B[(0, [1, 2, 3])] + B[(1, [3, 1, 2])] - sage: x*y # optional - sage.groups + sage: x*y B[(0, [1, 2, 3])] + B[(1, [3, 1, 2])] """ prods = ((a * b) for a, b in zip(left.cartesian_factors(), @@ -1138,9 +1141,9 @@ def product(self, x, y): Here is a more elaborate example involving a sub algebra:: - sage: Z = SymmetricGroup(5).algebra(QQ).center() # optional - sage.groups - sage: B = Z.basis() # optional - sage.groups - sage: B[3] * B[2] # optional - sage.groups + sage: Z = SymmetricGroup(5).algebra(QQ).center() # needs sage.groups + sage: B = Z.basis() # needs sage.groups + sage: B[3] * B[2] # needs sage.groups 4*B[2] + 6*B[3] + 5*B[6] """ assert x in self @@ -1162,18 +1165,19 @@ def product_by_coercion(self, left, right): EXAMPLES:: - sage: Out = Sets().WithRealizations().example().Out(); Out # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: Out = Sets().WithRealizations().example().Out(); Out The subset algebra of {1, 2, 3} over Rational Field in the Out basis - sage: Out.product # optional - sage.combinat sage.modules + sage: Out.product - sage: Out.product.__module__ # optional - sage.combinat sage.modules + sage: Out.product.__module__ 'sage.categories.magmas' - sage: x = Out.an_element() # optional - sage.combinat sage.modules - sage: y = Out.an_element() # optional - sage.combinat sage.modules - sage: Out.product(x, y) # optional - sage.combinat sage.modules + sage: x = Out.an_element() + sage: y = Out.an_element() + sage: Out.product(x, y) Out[{}] + 4*Out[{1}] + 9*Out[{2}] + Out[{1, 2}] """ diff --git a/src/sage/categories/magmatic_algebras.py b/src/sage/categories/magmatic_algebras.py index 171f564534e..9d37608569d 100644 --- a/src/sage/categories/magmatic_algebras.py +++ b/src/sage/categories/magmatic_algebras.py @@ -110,10 +110,10 @@ def algebra_generators(self): EXAMPLES:: - sage: F = AlgebrasWithBasis(QQ).example(); F # optional - sage.combinat sage.modules + sage: F = AlgebrasWithBasis(QQ).example(); F # needs sage.combinat sage.modules An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: F.algebra_generators() # optional - sage.combinat sage.modules + sage: F.algebra_generators() # needs sage.combinat sage.modules Family (B[word: a], B[word: b], B[word: c]) """ @@ -136,13 +136,13 @@ def algebra_generators(self): EXAMPLES:: - sage: D4 = DescentAlgebra(QQ, 4).B() # optional - sage.combinat sage.modules - sage: D4.algebra_generators() # optional - sage.combinat sage.modules + sage: D4 = DescentAlgebra(QQ, 4).B() # needs sage.combinat sage.modules + sage: D4.algebra_generators() # needs sage.combinat sage.modules Lazy family (...)_{i in Compositions of 4} sage: R. = ZZ[] - sage: P = PartitionAlgebra(1, x, R) # optional - sage.combinat sage.modules - sage: P.algebra_generators() # optional - sage.combinat sage.modules + sage: P = PartitionAlgebra(1, x, R) # needs sage.combinat sage.modules + sage: P.algebra_generators() # needs sage.combinat sage.modules Lazy family (Term map from Partition diagrams of order 1 to Partition Algebra of rank 1 with parameter x @@ -169,9 +169,9 @@ def product_on_basis(self, i, j): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules - sage: Word = A.basis().keys() # optional - sage.combinat sage.modules - sage: A.product_on_basis(Word("abc"), Word("cba")) # optional - sage.combinat sage.modules + sage: A = AlgebrasWithBasis(QQ).example() # needs sage.combinat sage.modules + sage: Word = A.basis().keys() # needs sage.combinat sage.modules + sage: A.product_on_basis(Word("abc"), Word("cba")) # needs sage.combinat sage.modules B[word: abccba] """ @@ -190,9 +190,9 @@ def product(self): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules - sage: a, b, c = A.algebra_generators() # optional - sage.combinat sage.modules - sage: A.product(a + 2*b, 3*c) # optional - sage.combinat sage.modules + sage: A = AlgebrasWithBasis(QQ).example() # needs sage.combinat sage.modules + sage: a, b, c = A.algebra_generators() # needs sage.combinat sage.modules + sage: A.product(a + 2*b, 3*c) # needs sage.combinat sage.modules 3*B[word: ac] + 6*B[word: bc] """ if self.product_on_basis is not NotImplemented: @@ -212,11 +212,11 @@ def _product_from_product_on_basis_multiply( self, left, right ): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example(); A # optional - sage.combinat sage.modules + sage: A = AlgebrasWithBasis(QQ).example(); A # needs sage.combinat sage.modules An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: a, b, c = A.algebra_generators() # optional - sage.combinat sage.modules - sage: A._product_from_product_on_basis_multiply(a*b + 2*c, a - b) # optional - sage.combinat sage.modules + sage: a, b, c = A.algebra_generators() # needs sage.combinat sage.modules + sage: A._product_from_product_on_basis_multiply(a*b + 2*c, a - b) # needs sage.combinat sage.modules B[word: aba] - B[word: abb] + 2*B[word: ca] - 2*B[word: cb] """ @@ -247,17 +247,18 @@ def derivations_basis(self): We construct the Heisenberg Lie algebra as a multiplicative algebra:: - sage: p_mult = matrix([[0,0,0], [0,0,-1], [0,0,0]]) # optional - sage.combinat sage.modules - sage: q_mult = matrix([[0,0,1], [0,0,0], [0,0,0]]) # optional - sage.combinat sage.modules - sage: A = algebras.FiniteDimensional(QQ, # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: p_mult = matrix([[0,0,0], [0,0,-1], [0,0,0]]) + sage: q_mult = matrix([[0,0,1], [0,0,0], [0,0,0]]) + sage: A = algebras.FiniteDimensional(QQ, ....: [p_mult, q_mult, matrix(QQ, 3, 3)], 'p,q,z') - sage: A.inject_variables() # optional - sage.combinat sage.modules + sage: A.inject_variables() Defining p, q, z - sage: p * q # optional - sage.combinat sage.modules + sage: p * q z - sage: q * p # optional - sage.combinat sage.modules + sage: q * p -z - sage: A.derivations_basis() # optional - sage.combinat sage.modules + sage: A.derivations_basis() ( [1 0 0] [0 1 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [1 0 0] [0 1 0] [0 0 0] [0 0 0] @@ -267,16 +268,17 @@ def derivations_basis(self): We construct another example using the exterior algebra and verify we obtain a derivation:: - sage: A = algebras.Exterior(QQ, 1) # optional - sage.combinat sage.modules - sage: A.derivations_basis() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: A = algebras.Exterior(QQ, 1) + sage: A.derivations_basis() ( [0 0] [0 1] ) - sage: D = A.module_morphism(matrix=A.derivations_basis()[0], # optional - sage.combinat sage.modules + sage: D = A.module_morphism(matrix=A.derivations_basis()[0], ....: codomain=A) - sage: one, e = A.basis() # optional - sage.combinat sage.modules - sage: all(D(a*b) == D(a) * b + a * D(b) # optional - sage.combinat sage.modules + sage: one, e = A.basis() + sage: all(D(a*b) == D(a) * b + a * D(b) ....: for a in A.basis() for b in A.basis()) True diff --git a/src/sage/categories/manifolds.py b/src/sage/categories/manifolds.py index 39ba682764e..f8dc1da4de0 100644 --- a/src/sage/categories/manifolds.py +++ b/src/sage/categories/manifolds.py @@ -25,6 +25,7 @@ class Manifolds(Category_over_base_ring): EXAMPLES:: + sage: # needs sage.rings.real_mpfr sage: from sage.categories.manifolds import Manifolds sage: C = Manifolds(RR); C Category of manifolds over Real Field with 53 bits of precision @@ -33,7 +34,7 @@ class Manifolds(Category_over_base_ring): TESTS:: - sage: TestSuite(C).run(skip="_test_category_over_bases") + sage: TestSuite(C).run(skip="_test_category_over_bases") # needs sage.rings.real_mpfr """ def __init__(self, base, name=None): r""" @@ -100,7 +101,7 @@ def Connected(self): EXAMPLES:: sage: from sage.categories.manifolds import Manifolds - sage: Manifolds(RR).Connected() + sage: Manifolds(RR).Connected() # needs sage.rings.real_mpfr Category of connected manifolds over Real Field with 53 bits of precision @@ -120,7 +121,7 @@ def FiniteDimensional(self): EXAMPLES:: sage: from sage.categories.manifolds import Manifolds - sage: C = Manifolds(RR).Connected().FiniteDimensional(); C + sage: C = Manifolds(RR).Connected().FiniteDimensional(); C # needs sage.rings.real_mpfr Category of finite dimensional connected manifolds over Real Field with 53 bits of precision @@ -141,7 +142,7 @@ def Differentiable(self): EXAMPLES:: sage: from sage.categories.manifolds import Manifolds - sage: Manifolds(RR).Differentiable() + sage: Manifolds(RR).Differentiable() # needs sage.rings.real_mpfr Category of differentiable manifolds over Real Field with 53 bits of precision @@ -161,7 +162,7 @@ def Smooth(self): EXAMPLES:: sage: from sage.categories.manifolds import Manifolds - sage: Manifolds(RR).Smooth() + sage: Manifolds(RR).Smooth() # needs sage.rings.real_mpfr Category of smooth manifolds over Real Field with 53 bits of precision @@ -181,7 +182,7 @@ def Analytic(self): EXAMPLES:: sage: from sage.categories.manifolds import Manifolds - sage: Manifolds(RR).Analytic() + sage: Manifolds(RR).Analytic() # needs sage.rings.real_mpfr Category of analytic manifolds over Real Field with 53 bits of precision @@ -202,7 +203,7 @@ def AlmostComplex(self): EXAMPLES:: sage: from sage.categories.manifolds import Manifolds - sage: Manifolds(RR).AlmostComplex() + sage: Manifolds(RR).AlmostComplex() # needs sage.rings.real_mpfr Category of almost complex manifolds over Real Field with 53 bits of precision @@ -222,14 +223,14 @@ def Complex(self): EXAMPLES:: sage: from sage.categories.manifolds import Manifolds - sage: Manifolds(CC).Complex() + sage: Manifolds(CC).Complex() # needs sage.rings.real_mpfr Category of complex manifolds over Complex Field with 53 bits of precision TESTS:: - sage: TestSuite(Manifolds(CC).Complex()).run() - sage: Manifolds(CC).Complex.__module__ + sage: TestSuite(Manifolds(CC).Complex()).run() # needs sage.rings.real_mpfr + sage: Manifolds(CC).Complex.__module__ # needs sage.rings.real_mpfr 'sage.categories.manifolds' """ return ComplexManifolds(self.base())._with_axioms(self.axioms()) @@ -256,7 +257,7 @@ def extra_super_categories(self): EXAMPLES:: sage: from sage.categories.manifolds import Manifolds - sage: Manifolds(RR).Smooth().super_categories() # indirect doctest + sage: Manifolds(RR).Smooth().super_categories() # indirect doctest # needs sage.rings.real_mpfr [Category of differentiable manifolds over Real Field with 53 bits of precision] """ @@ -277,7 +278,7 @@ def extra_super_categories(self): EXAMPLES:: sage: from sage.categories.manifolds import Manifolds - sage: Manifolds(RR).Analytic().super_categories() # indirect doctest + sage: Manifolds(RR).Analytic().super_categories() # indirect doctest # needs sage.rings.real_mpfr [Category of smooth manifolds over Real Field with 53 bits of precision] """ @@ -301,7 +302,7 @@ def extra_super_categories(self): EXAMPLES:: sage: from sage.categories.manifolds import Manifolds - sage: Manifolds(RR).AlmostComplex().super_categories() # indirect doctest + sage: Manifolds(RR).AlmostComplex().super_categories() # indirect doctest # needs sage.rings.real_mpfr [Category of smooth manifolds over Real Field with 53 bits of precision] """ diff --git a/src/sage/categories/map.pyx b/src/sage/categories/map.pyx index 50853348b53..f4529412831 100644 --- a/src/sage/categories/map.pyx +++ b/src/sage/categories/map.pyx @@ -115,7 +115,7 @@ cdef class Map(Element): Using domain and codomain:: - sage: Map(QQ['x'], SymmetricGroup(6)) # optional - sage.groups + sage: Map(QQ['x'], SymmetricGroup(6)) # needs sage.groups Generic map: From: Univariate Polynomial Ring in x over Rational Field To: Symmetric group of order 6! as a permutation group @@ -196,9 +196,9 @@ cdef class Map(Element): EXAMPLES:: - sage: Q = QuadraticField(-5) # optional - sage.rings.number_field - sage: phi = CDF._internal_convert_map_from(Q) # optional - sage.rings.number_field - sage: print(phi.parent()) # optional - sage.rings.number_field + sage: Q = QuadraticField(-5) # needs sage.rings.number_field + sage: phi = CDF._internal_convert_map_from(Q) # needs sage.rings.number_field + sage: print(phi.parent()) # needs sage.rings.number_field Set of field embeddings from Number Field in a with defining polynomial x^2 + 5 with a = 2.236067977499790?*I @@ -208,9 +208,9 @@ cdef class Map(Element): not prevent `Q` from being garbage collected:: sage: import gc - sage: del Q # optional - sage.rings.number_field + sage: del Q # needs sage.rings.number_field sage: _ = gc.collect() - sage: phi.parent() # optional - sage.rings.number_field + sage: phi.parent() # needs sage.rings.number_field Traceback (most recent call last): ... ValueError: This map is in an invalid state, @@ -219,17 +219,18 @@ cdef class Map(Element): You can still obtain copies of the maps used by the coercion system with strong references:: - sage: Q = QuadraticField(-5) # optional - sage.rings.number_field - sage: phi = CDF.convert_map_from(Q) # optional - sage.rings.number_field - sage: print(phi.parent()) # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + sage: Q = QuadraticField(-5) + sage: phi = CDF.convert_map_from(Q) + sage: print(phi.parent()) Set of field embeddings from Number Field in a with defining polynomial x^2 + 5 with a = 2.236067977499790?*I to Complex Double Field sage: import gc - sage: del Q # optional - sage.rings.number_field + sage: del Q sage: _ = gc.collect() - sage: phi.parent() # optional - sage.rings.number_field + sage: phi.parent() Set of field embeddings from Number Field in a with defining polynomial x^2 + 5 with a = 2.236067977499790?*I @@ -260,31 +261,32 @@ cdef class Map(Element): EXAMPLES:: - sage: Q = QuadraticField(-5) # optional - sage.rings.number_field - sage: phi = CDF._internal_convert_map_from(Q) # optional - sage.rings.number_field + sage: Q = QuadraticField(-5) # needs sage.rings.number_field + sage: phi = CDF._internal_convert_map_from(Q) # needs sage.rings.number_field By :trac:`14711`, maps used in the coercion and conversion system use *weak* references to domain and codomain, in contrast to other maps:: - sage: phi.domain # optional - sage.rings.number_field + sage: phi.domain # needs sage.rings.number_field - sage: phi._make_strong_references() # optional - sage.rings.number_field - sage: print(phi.domain) # optional - sage.rings.number_field + sage: phi._make_strong_references() # needs sage.rings.number_field + sage: print(phi.domain) # needs sage.rings.number_field The constant function (...) -> Number Field in a with defining polynomial x^2 + 5 with a = 2.236067977499790?*I Now, as there is a strong reference, `Q` cannot be garbage collected:: + sage: # needs sage.rings.number_field sage: import gc sage: _ = gc.collect() - sage: C = Q.__class__.__base__ # optional - sage.rings.number_field + sage: C = Q.__class__.__base__ sage: x = None - sage: numberQuadFields = len([x for x in gc.get_objects() # optional - sage.rings.number_field + sage: numberQuadFields = len([x for x in gc.get_objects() ....: if isinstance(x, C)]) - sage: del Q, x # optional - sage.rings.number_field + sage: del Q, x sage: _ = gc.collect() - sage: numberQuadFields == len([x for x in gc.get_objects() # optional - sage.rings.number_field + sage: numberQuadFields == len([x for x in gc.get_objects() ....: if isinstance(x, C)]) True @@ -293,12 +295,13 @@ cdef class Map(Element): invalid. This is why :meth:`_make_weak_references` should only be used if one really knows what one is doing:: - sage: phi._make_weak_references() # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + sage: phi._make_weak_references() sage: _ = gc.collect() - sage: numberQuadFields == len([x for x in gc.get_objects() # optional - sage.rings.number_field + sage: numberQuadFields == len([x for x in gc.get_objects() ....: if isinstance(x, C)]) + 1 True - sage: phi # optional - sage.rings.number_field + sage: phi Defunct map """ if not isinstance(self.domain, ConstantFunction): @@ -326,31 +329,32 @@ cdef class Map(Element): EXAMPLES:: - sage: Q = QuadraticField(-5) # optional - sage.rings.number_field - sage: phi = CDF._internal_convert_map_from(Q) # optional - sage.rings.number_field + sage: Q = QuadraticField(-5) # needs sage.rings.number_field + sage: phi = CDF._internal_convert_map_from(Q) # needs sage.rings.number_field By :trac:`14711`, maps used in the coercion and conversion system use *weak* references to domain and codomain, in contrast to other maps:: - sage: phi.domain # optional - sage.rings.number_field + sage: phi.domain # needs sage.rings.number_field - sage: phi._make_strong_references() # optional - sage.rings.number_field - sage: print(phi.domain) # optional - sage.rings.number_field + sage: phi._make_strong_references() # needs sage.rings.number_field + sage: print(phi.domain) # needs sage.rings.number_field The constant function (...) -> Number Field in a with defining polynomial x^2 + 5 with a = 2.236067977499790?*I Now, as there is a strong reference, `Q` cannot be garbage collected:: + sage: # needs sage.rings.number_field sage: import gc sage: _ = gc.collect() - sage: C = Q.__class__.__base__ # optional - sage.rings.number_field + sage: C = Q.__class__.__base__ sage: x = None - sage: numberQuadFields = len([x for x in gc.get_objects() # optional - sage.rings.number_field + sage: numberQuadFields = len([x for x in gc.get_objects() ....: if isinstance(x, C)]) - sage: del Q, x # optional - sage.rings.number_field + sage: del Q, x sage: _ = gc.collect() - sage: numberQuadFields == len([x for x in gc.get_objects() # optional - sage.rings.number_field + sage: numberQuadFields == len([x for x in gc.get_objects() ....: if isinstance(x, C)]) True @@ -359,18 +363,19 @@ cdef class Map(Element): invalid. This is why :meth:`_make_weak_references` should only be used if one really knows what one is doing:: - sage: phi._make_weak_references() # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + sage: phi._make_weak_references() sage: _ = gc.collect() - sage: numberQuadFields == len([x for x in gc.get_objects() # optional - sage.rings.number_field + sage: numberQuadFields == len([x for x in gc.get_objects() ....: if isinstance(x, C)]) + 1 True - sage: phi # optional - sage.rings.number_field + sage: phi Defunct map - sage: phi._make_strong_references() # optional - sage.rings.number_field + sage: phi._make_strong_references() Traceback (most recent call last): ... RuntimeError: The domain of this map became garbage collected - sage: phi.parent() # optional - sage.rings.number_field + sage: phi.parent() Traceback (most recent call last): ... ValueError: This map is in an invalid state, the domain has been garbage collected @@ -400,6 +405,7 @@ cdef class Map(Element): Since it is a ``cdef``d method, it is tested using a dummy python method. :: + sage: # needs sage.rings.real_mpfr sage: from sage.categories.map import Map sage: f = Map(Hom(QQ, ZZ, Rings())) sage: f._update_slots_test({"_domain": RR, "_codomain": QQ}) # indirect doctest @@ -430,6 +436,7 @@ cdef class Map(Element): TESTS:: + sage: # needs sage.rings.real_mpfr sage: from sage.categories.map import Map sage: f = Map(Hom(QQ, ZZ, Rings())) sage: f._update_slots_test({"_domain": RR, "_codomain": QQ}) @@ -564,16 +571,17 @@ cdef class Map(Element): TESTS:: - sage: Q = QuadraticField(-5) # optional - sage.rings.number_field - sage: phi = CDF._internal_coerce_map_from(Q); phi # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + sage: Q = QuadraticField(-5) + sage: phi = CDF._internal_coerce_map_from(Q); phi (map internal to coercion system -- copy before use) Composite map: From: Number Field in a with defining polynomial x^2 + 5 with a = 2.236067977499790?*I To: Complex Double Field - sage: del Q # optional - sage.rings.number_field + sage: del Q sage: import gc sage: _ = gc.collect() - sage: phi # optional - sage.rings.number_field + sage: phi Defunct map """ D = self.domain() @@ -767,11 +775,11 @@ cdef class Map(Element): ``pushforward`` fails, ``_call_`` is tried after conversion:: sage: g = FOO(QQ, ZZ) - sage: g(SR(3)) # optional - sage.symbolic + sage: g(SR(3)) # needs sage.symbolic pushforward Symbolic Ring _call_ Rational Field 3 - sage: g(SR(3), exponent=2) # optional - sage.symbolic + sage: g(SR(3), exponent=2) # needs sage.symbolic pushforward Symbolic Ring _call_with_args Rational Field 9 @@ -1129,6 +1137,7 @@ cdef class Map(Element): EXAMPLES:: + sage: # needs sage.rings.complex_double sage: mor = CDF.coerce_map_from(RDF) sage: mor.extend_domain(QQ) Composite map: @@ -1185,7 +1194,7 @@ cdef class Map(Element): Native morphism: From: Rational Field To: Real Double Field - sage: mor.extend_codomain(GF(7)) # optional - sage.rings.finite_rings + sage: mor.extend_codomain(GF(7)) Traceback (most recent call last): ... TypeError: No coercion from Rational Field to Finite Field of size 7 @@ -1240,14 +1249,15 @@ cdef class Map(Element): ... TypeError: self must be an endomorphism - sage: K. = NumberField(x^4 - 5*x + 5) # optional - sage.rings.number_field - sage: C5. = CyclotomicField(5) # optional - sage.rings.number_field - sage: tau = K.hom([z - z^2]); tau # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + sage: K. = NumberField(x^4 - 5*x + 5) + sage: C5. = CyclotomicField(5) + sage: tau = K.hom([z - z^2]); tau Ring morphism: From: Number Field in a with defining polynomial x^4 - 5*x + 5 To: Cyclotomic Field of order 5 and degree 4 Defn: a |--> -z^2 + z - sage: tau^-1 # optional - sage.rings.number_field + sage: tau^-1 Ring morphism: From: Cyclotomic Field of order 5 and degree 4 To: Number Field in a with defining polynomial x^4 - 5*x + 5 @@ -1874,26 +1884,27 @@ cdef class FormalCompositeMap(Map): EXAMPLES:: - sage: V1 = QQ^2 # optional - sage.modules - sage: V2 = QQ^3 # optional - sage.modules - sage: phi1 = (QQ^1).hom(Matrix([[1, 1]]), V1) # optional - sage.modules - sage: phi2 = V1.hom(Matrix([[1, 2, 3], [4, 5, 6]]), V2) # optional - sage.modules + sage: # needs sage.modules + sage: V1 = QQ^2 + sage: V2 = QQ^3 + sage: phi1 = (QQ^1).hom(Matrix([[1, 1]]), V1) + sage: phi2 = V1.hom(Matrix([[1, 2, 3], [4, 5, 6]]), V2) If both constituents are injective, the composition is injective:: sage: from sage.categories.map import FormalCompositeMap - sage: c1 = FormalCompositeMap(Hom(QQ^1, V2, phi1.category_for()), # optional - sage.modules + sage: c1 = FormalCompositeMap(Hom(QQ^1, V2, phi1.category_for()), # needs sage.modules ....: phi1, phi2) - sage: c1.is_injective() # optional - sage.modules + sage: c1.is_injective() # needs sage.modules True If it cannot be determined whether the composition is injective, an error is raised:: - sage: psi1 = V2.hom(Matrix([[1, 2], [3, 4], [5, 6]]), V1) # optional - sage.modules - sage: c2 = FormalCompositeMap(Hom(V1, V1, phi2.category_for()), # optional - sage.modules + sage: psi1 = V2.hom(Matrix([[1, 2], [3, 4], [5, 6]]), V1) # needs sage.modules + sage: c2 = FormalCompositeMap(Hom(V1, V1, phi2.category_for()), # needs sage.modules ....: phi2, psi1) - sage: c2.is_injective() # optional - sage.modules + sage: c2.is_injective() # needs sage.modules Traceback (most recent call last): ... NotImplementedError: not enough information to deduce injectivity @@ -1901,18 +1912,18 @@ cdef class FormalCompositeMap(Map): If the first map is surjective and the second map is not injective, then the composition is not injective:: - sage: psi2 = V1.hom([[1], [1]], QQ^1) # optional - sage.modules - sage: c3 = FormalCompositeMap(Hom(V2, QQ^1, phi2.category_for()), # optional - sage.modules + sage: psi2 = V1.hom([[1], [1]], QQ^1) # needs sage.modules + sage: c3 = FormalCompositeMap(Hom(V2, QQ^1, phi2.category_for()), # needs sage.modules ....: psi2, psi1) - sage: c3.is_injective() # optional - sage.modules + sage: c3.is_injective() # needs sage.modules False TESTS: Check that :trac:`23205` has been resolved:: - sage: f = QQ.hom(QQbar) * ZZ.hom(QQ) # optional - sage.rings.number_field - sage: f.is_injective() # optional - sage.rings.number_field + sage: f = QQ.hom(QQbar) * ZZ.hom(QQ) # needs sage.rings.number_field + sage: f.is_injective() # needs sage.rings.number_field True """ @@ -1949,23 +1960,24 @@ cdef class FormalCompositeMap(Map): EXAMPLES:: sage: from sage.categories.map import FormalCompositeMap - sage: V3 = QQ^3 # optional - sage.modules - sage: V2 = QQ^2 # optional - sage.modules - sage: V1 = QQ^1 # optional - sage.modules + sage: V3 = QQ^3 # needs sage.modules + sage: V2 = QQ^2 # needs sage.modules + sage: V1 = QQ^1 # needs sage.modules If both maps are surjective, the composition is surjective:: - sage: phi32 = V3.hom(Matrix([[1, 2], [3, 4], [5, 6]]), V2) # optional - sage.modules - sage: phi21 = V2.hom(Matrix([[1], [1]]), V1) # optional - sage.modules - sage: c_phi = FormalCompositeMap(Hom(V3, V1, phi32.category_for()), # optional - sage.modules + sage: # needs sage.modules + sage: phi32 = V3.hom(Matrix([[1, 2], [3, 4], [5, 6]]), V2) + sage: phi21 = V2.hom(Matrix([[1], [1]]), V1) + sage: c_phi = FormalCompositeMap(Hom(V3, V1, phi32.category_for()), ....: phi32, phi21) - sage: c_phi.is_surjective() # optional - sage.modules + sage: c_phi.is_surjective() True If the second map is not surjective, the composition is not surjective:: - sage: FormalCompositeMap(Hom(V3, V1, phi32.category_for()), # optional - sage.modules + sage: FormalCompositeMap(Hom(V3, V1, phi32.category_for()), # needs sage.modules ....: phi32, ....: V2.hom(Matrix([[0], [0]]), V1)).is_surjective() False @@ -1973,14 +1985,14 @@ cdef class FormalCompositeMap(Map): If the second map is an isomorphism and the first map is not surjective, then the composition is not surjective:: - sage: FormalCompositeMap(Hom(V2, V1, phi32.category_for()), # optional - sage.modules + sage: FormalCompositeMap(Hom(V2, V1, phi32.category_for()), # needs sage.modules ....: V2.hom(Matrix([[0], [0]]), V1), ....: V1.hom(Matrix([[1]]), V1)).is_surjective() False Otherwise, surjectivity of the composition cannot be determined:: - sage: FormalCompositeMap(Hom(V2, V1, phi32.category_for()), # optional - sage.modules + sage: FormalCompositeMap(Hom(V2, V1, phi32.category_for()), # needs sage.modules ....: V2.hom(Matrix([[1, 1], [1, 1]]), V2), ....: V2.hom(Matrix([[1], [1]]), V1)).is_surjective() Traceback (most recent call last): @@ -2022,8 +2034,8 @@ cdef class FormalCompositeMap(Map): EXAMPLES:: sage: f = QQ.coerce_map_from(ZZ) - sage: g = MatrixSpace(QQ, 2, 2).coerce_map_from(QQ) # optional - sage.modules - sage: list((g * f).domains()) # optional - sage.modules + sage: g = MatrixSpace(QQ, 2, 2).coerce_map_from(QQ) # needs sage.modules + sage: list((g * f).domains()) # needs sage.modules [Integer Ring, Rational Field] """ for f in self.__list: @@ -2057,9 +2069,9 @@ cdef class FormalCompositeMap(Map): of :class:`sage.rings.polynomial.polynomial_element.Polynomial` before (see comment there):: - sage: k = GF(47) # optional - sage.rings.finite_rings - sage: R. = PolynomialRing(k) # optional - sage.rings.finite_rings - sage: R.coerce_map_from(ZZ).section() # optional - sage.rings.finite_rings + sage: k = GF(47) + sage: R. = PolynomialRing(k) + sage: R.coerce_map_from(ZZ).section() Composite map: From: Univariate Polynomial Ring in x over Finite Field of size 47 To: Integer Ring @@ -2070,9 +2082,9 @@ cdef class FormalCompositeMap(Map): Lifting map: From: Finite Field of size 47 To: Integer Ring - sage: ZZ(R(45)) # indirect doctest # optional - sage.rings.finite_rings + sage: ZZ(R(45)) # indirect doctest 45 - sage: ZZ(3*x + 45) # indirect doctest # optional - sage.rings.finite_rings + sage: ZZ(3*x + 45) # indirect doctest Traceback (most recent call last): ... TypeError: not a constant polynomial diff --git a/src/sage/categories/metric_spaces.py b/src/sage/categories/metric_spaces.py index 6608ca7d4e5..205e8746363 100644 --- a/src/sage/categories/metric_spaces.py +++ b/src/sage/categories/metric_spaces.py @@ -127,10 +127,11 @@ def _test_metric_function(self, **options): EXAMPLES:: - sage: UHP = HyperbolicPlane().UHP() # optional - sage.symbolic - sage: UHP._test_metric_function() # optional - sage.symbolic - sage: elts = [UHP.random_element() for i in range(5)] # optional - sage.symbolic - sage: UHP._test_metric_function(some_elements=elts) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: UHP = HyperbolicPlane().UHP() + sage: UHP._test_metric_function() + sage: elts = [UHP.random_element() for i in range(5)] + sage: UHP._test_metric_function(some_elements=elts) """ tester = self._tester(**options) S = tester.some_elements() @@ -149,11 +150,12 @@ def metric_function(self): EXAMPLES:: - sage: UHP = HyperbolicPlane().UHP() # optional - sage.symbolic - sage: m = UHP.metric_function() # optional - sage.symbolic - sage: p1 = UHP.get_point(5 + 7*I) # optional - sage.symbolic - sage: p2 = UHP.get_point(1.0 + I) # optional - sage.symbolic - sage: m(p1, p2) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: UHP = HyperbolicPlane().UHP() + sage: m = UHP.metric_function() + sage: p1 = UHP.get_point(5 + 7*I) + sage: p2 = UHP.get_point(1.0 + I) + sage: m(p1, p2) 2.23230104635820 """ return lambda a,b: a.dist(b) @@ -166,27 +168,28 @@ def dist(self, a, b): EXAMPLES:: - sage: UHP = HyperbolicPlane().UHP() # optional - sage.symbolic - sage: p1 = UHP.get_point(5 + 7*I) # optional - sage.symbolic - sage: p2 = UHP.get_point(1.0 + I) # optional - sage.symbolic - sage: UHP.dist(p1, p2) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: UHP = HyperbolicPlane().UHP() + sage: p1 = UHP.get_point(5 + 7*I) + sage: p2 = UHP.get_point(1.0 + I) + sage: UHP.dist(p1, p2) 2.23230104635820 - sage: PD = HyperbolicPlane().PD() # optional - sage.symbolic - sage: PD.dist(PD.get_point(0), PD.get_point(I/2)) # optional - sage.symbolic + sage: PD = HyperbolicPlane().PD() # needs sage.symbolic + sage: PD.dist(PD.get_point(0), PD.get_point(I/2)) # needs sage.symbolic arccosh(5/3) TESTS:: - sage: RR.dist(-1, pi) # optional - sage.symbolic + sage: RR.dist(-1, pi) # needs sage.rings.real_mpfr sage.symbolic 4.14159265358979 sage: RDF.dist(1, -1/2) 1.5 - sage: CC.dist(3, 2) + sage: CC.dist(3, 2) # needs sage.rings.real_mpfr 1.00000000000000 - sage: CC.dist(-1, I) + sage: CC.dist(-1, I) # needs sage.rings.real_mpfr sage.symbolic 1.41421356237310 - sage: CDF.dist(-1, I) + sage: CDF.dist(-1, I) # needs sage.rings.real_mpfr sage.symbolic 1.4142135623730951 """ return (self(a) - self(b)).abs() @@ -198,7 +201,7 @@ def abs(self): EXAMPLES:: - sage: CC(I).abs() + sage: CC(I).abs() # needs sage.rings.real_mpfr sage.symbolic 1.00000000000000 """ P = self.parent() @@ -210,10 +213,11 @@ def dist(self, b): EXAMPLES:: - sage: UHP = HyperbolicPlane().UHP() # optional - sage.symbolic - sage: p1 = UHP.get_point(5 + 7*I) # optional - sage.symbolic - sage: p2 = UHP.get_point(1 + I) # optional - sage.symbolic - sage: p1.dist(p2) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: UHP = HyperbolicPlane().UHP() + sage: p1 = UHP.get_point(5 + 7*I) + sage: p2 = UHP.get_point(1 + I) + sage: p1.dist(p2) arccosh(33/7) """ return self.parent().dist(self, b) @@ -266,11 +270,12 @@ def dist(self, a, b): EXAMPLES:: - sage: H = HyperbolicPlane() # optional - sage.symbolic - sage: PD = H.PD() # optional - sage.symbolic - sage: p1 = PD.get_point(0) # optional - sage.symbolic - sage: p2 = PD.get_point(I/2) # optional - sage.symbolic - sage: H.dist(p1, p2) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: H = HyperbolicPlane() + sage: PD = H.PD() + sage: p1 = PD.get_point(0) + sage: p2 = PD.get_point(I/2) + sage: H.dist(p1, p2) arccosh(5/3) """ R = self.a_realization() diff --git a/src/sage/categories/modules.py b/src/sage/categories/modules.py index 81f6df6f51f..e65bab4faf8 100644 --- a/src/sage/categories/modules.py +++ b/src/sage/categories/modules.py @@ -214,23 +214,25 @@ def base_ring(self): sage: C.base_ring.__module__ 'sage.categories.modules' - sage: C = Modules(Rings()) & Semigroups(); C + sage: C2 = Modules(Rings()) & Semigroups(); C2 Join of Category of semigroups and Category of modules over rings - sage: C.base_ring() + sage: C2.base_ring() Category of rings - sage: C.base_ring.__module__ + sage: C2.base_ring.__module__ 'sage.categories.modules' - sage: C = DescentAlgebra(QQ,3).B().category() # optional - sage.combinat sage.modules - sage: C.base_ring.__module__ # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: C3 = DescentAlgebra(QQ,3).B().category() + sage: C3.base_ring.__module__ 'sage.categories.modules' - sage: C.base_ring() # optional - sage.combinat sage.modules + sage: C3.base_ring() Rational Field - sage: C = QuasiSymmetricFunctions(QQ).F().category() # optional - sage.combinat sage.modules - sage: C.base_ring.__module__ # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: C4 = QuasiSymmetricFunctions(QQ).F().category() + sage: C4.base_ring.__module__ 'sage.categories.modules' - sage: C.base_ring() # optional - sage.combinat sage.modules + sage: C4.base_ring() Rational Field """ for C in self.super_categories(): @@ -365,9 +367,9 @@ def FinitelyPresented(self): sage: Modules(ZZ).FinitelyPresented() Category of finitely presented modules over Integer Ring - sage: A = SteenrodAlgebra(2) # optional - sage.combinat sage.modules - sage: from sage.modules.fp_graded.module import FPModule # optional - sage.combinat sage.modules - sage: FPModule(A, [0, 1], [[Sq(2), Sq(1)]]).category() # optional - sage.combinat sage.modules + sage: A = SteenrodAlgebra(2) # needs sage.combinat sage.modules + sage: from sage.modules.fp_graded.module import FPModule # needs sage.combinat sage.modules + sage: FPModule(A, [0, 1], [[Sq(2), Sq(1)]]).category() # needs sage.combinat sage.modules Category of finitely presented graded modules over mod 2 Steenrod algebra, milnor basis @@ -521,7 +523,7 @@ def extra_super_categories(self): [Category of finite sets] sage: Modules(ZZ).FiniteDimensional().extra_super_categories() [] - sage: Modules(GF(5)).FiniteDimensional().is_subcategory(Sets().Finite()) # optional - sage.rings.finite_rings + sage: Modules(GF(5)).FiniteDimensional().is_subcategory(Sets().Finite()) True sage: Modules(ZZ).FiniteDimensional().is_subcategory(Sets().Finite()) False @@ -571,7 +573,7 @@ def extra_super_categories(self): [Category of finite sets] sage: Modules(ZZ).FiniteDimensional().extra_super_categories() [] - sage: Modules(GF(5)).FiniteDimensional().is_subcategory(Sets().Finite()) # optional - sage.rings.finite_rings + sage: Modules(GF(5)).FiniteDimensional().is_subcategory(Sets().Finite()) True sage: Modules(ZZ).FiniteDimensional().is_subcategory(Sets().Finite()) False @@ -618,9 +620,9 @@ def linear_combination(self, iter_of_elements_coeff, factor_on_left=True): EXAMPLES:: - sage: m = matrix([[0,1], [1,1]]) # optional - sage.modules - sage: J. = JordanAlgebra(m) # optional - sage.combinat sage.modules - sage: J.linear_combination(((a+b, 1), (-2*b + c, -1))) # optional - sage.combinat sage.modules + sage: m = matrix([[0,1], [1,1]]) # needs sage.modules + sage: J. = JordanAlgebra(m) # needs sage.combinat sage.modules + sage: J.linear_combination(((a+b, 1), (-2*b + c, -1))) # needs sage.combinat sage.modules 1 + (3, -1) """ if factor_on_left: @@ -637,8 +639,8 @@ def tensor_square(self): EXAMPLES:: - sage: A = HopfAlgebrasWithBasis(QQ).example() # optional - sage.groups sage.modules - sage: A.tensor_square() # optional - sage.groups sage.modules + sage: A = HopfAlgebrasWithBasis(QQ).example() # needs sage.groups sage.modules + sage: A.tensor_square() # needs sage.groups sage.modules An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Rational Field # An example @@ -667,14 +669,15 @@ def module_morphism(self, *, function, category=None, codomain, **keywords): EXAMPLES:: - sage: V = FiniteRankFreeModule(QQ, 2) # optional - sage.modules - sage: e = V.basis('e'); e # optional - sage.modules + sage: # needs sage.modules + sage: V = FiniteRankFreeModule(QQ, 2) + sage: e = V.basis('e'); e Basis (e_0,e_1) on the 2-dimensional vector space over the Rational Field - sage: neg = V.module_morphism(function=operator.neg, codomain=V); neg # optional - sage.modules + sage: neg = V.module_morphism(function=operator.neg, codomain=V); neg Generic endomorphism of 2-dimensional vector space over the Rational Field - sage: neg(e[0]) # optional - sage.modules + sage: neg(e[0]) Element -e_0 of the 2-dimensional vector space over the Rational Field """ @@ -706,9 +709,9 @@ def quotient(self, submodule, check=True, **kwds): EXAMPLES:: - sage: C = CombinatorialFreeModule(QQ, ['a','b','c']) # optional - sage.modules - sage: TA = TensorAlgebra(C) # optional - sage.modules - sage: TA.quotient # optional - sage.modules + sage: C = CombinatorialFreeModule(QQ, ['a','b','c']) # needs sage.modules + sage: TA = TensorAlgebra(C) # needs sage.combinat sage.modules + sage: TA.quotient # needs sage.combinat sage.modules @@ -757,21 +760,22 @@ def base_ring(self): EXAMPLES:: - sage: E = CombinatorialFreeModule(ZZ, [1,2,3]) # optional - sage.modules - sage: F = CombinatorialFreeModule(ZZ, [2,3,4]) # optional - sage.modules - sage: H = Hom(E, F) # optional - sage.modules - sage: H.base_ring() # optional - sage.modules + sage: # needs sage.modules + sage: E = CombinatorialFreeModule(ZZ, [1,2,3]) + sage: F = CombinatorialFreeModule(ZZ, [2,3,4]) + sage: H = Hom(E, F) + sage: H.base_ring() Integer Ring This ``base_ring`` method is actually overridden by :meth:`sage.structure.category_object.CategoryObject.base_ring`:: - sage: H.base_ring.__module__ # optional - sage.modules + sage: H.base_ring.__module__ # needs sage.modules Here we call it directly:: - sage: method = H.category().parent_class.base_ring # optional - sage.modules - sage: method.__get__(H)() # optional - sage.modules + sage: method = H.category().parent_class.base_ring # needs sage.modules + sage: method.__get__(H)() # needs sage.modules Integer Ring """ return self.domain().base_ring() @@ -781,24 +785,25 @@ def zero(self): """ EXAMPLES:: - sage: E = CombinatorialFreeModule(ZZ, [1,2,3]) # optional - sage.modules - sage: F = CombinatorialFreeModule(ZZ, [2,3,4]) # optional - sage.modules - sage: H = Hom(E, F) # optional - sage.modules - sage: f = H.zero() # optional - sage.modules - sage: f # optional - sage.modules + sage: # needs sage.modules + sage: E = CombinatorialFreeModule(ZZ, [1,2,3]) + sage: F = CombinatorialFreeModule(ZZ, [2,3,4]) + sage: H = Hom(E, F) + sage: f = H.zero() + sage: f Generic morphism: From: Free module generated by {1, 2, 3} over Integer Ring To: Free module generated by {2, 3, 4} over Integer Ring - sage: f(E.monomial(2)) # optional - sage.modules + sage: f(E.monomial(2)) 0 - sage: f(E.monomial(3)) == F.zero() # optional - sage.modules + sage: f(E.monomial(3)) == F.zero() True TESTS: We check that ``H.zero()`` is picklable:: - sage: loads(dumps(f.parent().zero())) # optional - sage.modules + sage: loads(dumps(f.parent().zero())) # needs sage.modules Generic morphism: From: Free module generated by {1, 2, 3} over Integer Ring To: Free module generated by {2, 3, 4} over Integer Ring @@ -822,7 +827,7 @@ def extra_super_categories(self): sage: Modules(ZZ).Endsets().extra_super_categories() [Category of magmatic algebras over Integer Ring] - sage: End(ZZ^3) in Algebras(ZZ) # optional - sage.modules + sage: End(ZZ^3) in Algebras(ZZ) # needs sage.modules True """ from .magmatic_algebras import MagmaticAlgebras @@ -861,46 +866,47 @@ def __init_extra__(self): EXAMPLES:: - sage: E = CombinatorialFreeModule(ZZ, [1,2,3]) # optional - sage.modules - sage: F = CombinatorialFreeModule(ZZ, [2,3,4]) # optional - sage.modules - sage: C = cartesian_product([E, F]); C # optional - sage.modules + sage: # needs sage.modules + sage: E = CombinatorialFreeModule(ZZ, [1,2,3]) + sage: F = CombinatorialFreeModule(ZZ, [2,3,4]) + sage: C = cartesian_product([E, F]); C Free module generated by {1, 2, 3} over Integer Ring (+) Free module generated by {2, 3, 4} over Integer Ring - sage: C.base_ring() # optional - sage.modules + sage: C.base_ring() Integer Ring Check that :trac:`29225` is fixed:: - sage: M = cartesian_product((ZZ^2, ZZ^3)); M # optional - sage.modules + sage: M = cartesian_product((ZZ^2, ZZ^3)); M # needs sage.modules The Cartesian product of (Ambient free module of rank 2 over the principal ideal domain Integer Ring, Ambient free module of rank 3 over the principal ideal domain Integer Ring) - sage: M.category() # optional - sage.modules + sage: M.category() # needs sage.modules Category of Cartesian products of modules with basis over (euclidean domains and infinite enumerated sets and metric spaces) - sage: M.base_ring() # optional - sage.modules + sage: M.base_ring() # needs sage.modules Integer Ring - sage: A = cartesian_product((QQ^2, QQ['x'])); A # optional - sage.modules + sage: A = cartesian_product((QQ^2, QQ['x'])); A # needs sage.modules The Cartesian product of (Vector space of dimension 2 over Rational Field, Univariate Polynomial Ring in x over Rational Field) - sage: A.category() # optional - sage.modules + sage: A.category() # needs sage.modules Category of Cartesian products of vector spaces over (number fields and quotient fields and metric spaces) - sage: A.base_ring() # optional - sage.modules + sage: A.base_ring() # needs sage.modules Rational Field This currently only works if all factors have the same base ring:: - sage: B = cartesian_product((ZZ['x'], QQ^3)); B # optional - sage.modules + sage: B = cartesian_product((ZZ['x'], QQ^3)); B # needs sage.modules The Cartesian product of (Univariate Polynomial Ring in x over Integer Ring, Vector space of dimension 3 over Rational Field) - sage: B.category() # optional - sage.modules + sage: B.category() # needs sage.modules Category of Cartesian products of commutative additive groups - sage: B.base_ring() # optional - sage.modules + sage: B.base_ring() # needs sage.modules """ factors = self._sets if factors: @@ -916,12 +922,12 @@ def _lmul_(self, x): EXAMPLES:: - sage: A = FreeModule(ZZ, 2) # optional - sage.modules - sage: B = cartesian_product([A, A]); B # optional - sage.modules + sage: A = FreeModule(ZZ, 2) # needs sage.modules + sage: B = cartesian_product([A, A]); B # needs sage.modules The Cartesian product of (Ambient free module of rank 2 over the principal ideal domain Integer Ring, Ambient free module of rank 2 over the principal ideal domain Integer Ring) - sage: 5*B(([1, 2], [3, 4])) # optional - sage.modules + sage: 5*B(([1, 2], [3, 4])) # needs sage.modules ((5, 10), (15, 20)) """ return self.parent()._cartesian_product_of_elements( @@ -953,9 +959,9 @@ def construction(self): EXAMPLES:: - sage: A = algebras.Free(QQ, 2) # optional - sage.combinat sage.modules - sage: T = A.tensor(A) # optional - sage.combinat sage.modules - sage: T.construction() # optional - sage.combinat sage.modules + sage: A = algebras.Free(QQ, 2) # needs sage.combinat sage.modules + sage: T = A.tensor(A) # needs sage.combinat sage.modules + sage: T.construction() # needs sage.combinat sage.modules (The tensor functorial construction, (Free Algebra on 2 generators (None0, None1) over Rational Field, Free Algebra on 2 generators (None0, None1) over Rational Field)) @@ -976,20 +982,21 @@ def tensor_factors(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(ZZ, [1,2]) # optional - sage.modules - sage: F.rename("F") # optional - sage.modules - sage: G = CombinatorialFreeModule(ZZ, [3,4]) # optional - sage.modules - sage: G.rename("G") # optional - sage.modules - sage: T = tensor([F, G]); T # optional - sage.modules + sage: # needs sage.modules + sage: F = CombinatorialFreeModule(ZZ, [1,2]) + sage: F.rename("F") + sage: G = CombinatorialFreeModule(ZZ, [3,4]) + sage: G.rename("G") + sage: T = tensor([F, G]); T F # G - sage: T.tensor_factors() # optional - sage.modules + sage: T.tensor_factors() (F, G) TESTS:: - sage: Cat = ModulesWithBasis(ZZ).FiniteDimensional().TensorProducts() # optional - sage.modules - sage: M = CombinatorialFreeModule(ZZ, ((1, 1), (1, 2), (2, 1), (2, 2)), category=Cat) # optional - sage.modules - sage: M.construction() # optional - sage.modules + sage: Cat = ModulesWithBasis(ZZ).FiniteDimensional().TensorProducts() + sage: M = CombinatorialFreeModule(ZZ, ((1, 1), (1, 2), (2, 1), (2, 2)), category=Cat) # needs sage.modules + sage: M.construction() # needs sage.modules doctest:warning... DeprecationWarning: implementations of Modules().TensorProducts() now must define the method tensor_factors See https://github.com/sagemath/sage/issues/34393 for details. diff --git a/src/sage/categories/modules_with_basis.py b/src/sage/categories/modules_with_basis.py index 85a0d50239a..65fd47cb890 100644 --- a/src/sage/categories/modules_with_basis.py +++ b/src/sage/categories/modules_with_basis.py @@ -66,23 +66,23 @@ class ModulesWithBasis(CategoryWithAxiom_over_base_ring): Let `X` and `Y` be two modules with basis. We can build `Hom(X,Y)`:: - sage: X = CombinatorialFreeModule(QQ, [1,2]); X.__custom_name = "X" # optional - sage.modules - sage: Y = CombinatorialFreeModule(QQ, [3,4]); Y.__custom_name = "Y" # optional - sage.modules - sage: H = Hom(X, Y); H # optional - sage.modules + sage: X = CombinatorialFreeModule(QQ, [1,2]); X.__custom_name = "X" # needs sage.modules + sage: Y = CombinatorialFreeModule(QQ, [3,4]); Y.__custom_name = "Y" # needs sage.modules + sage: H = Hom(X, Y); H # needs sage.modules Set of Morphisms from X to Y in Category of finite dimensional vector spaces with basis over Rational Field The simplest morphism is the zero map:: - sage: H.zero() # todo: move this test into module once we have an example # optional - sage.modules + sage: H.zero() # todo: move this test into module once we have an example # needs sage.modules Generic morphism: From: X To: Y which we can apply to elements of `X`:: - sage: x = X.monomial(1) + 3 * X.monomial(2) # optional - sage.modules - sage: H.zero()(x) # optional - sage.modules + sage: x = X.monomial(1) + 3 * X.monomial(2) # needs sage.modules + sage: H.zero()(x) # needs sage.modules 0 EXAMPLES: @@ -90,17 +90,17 @@ class ModulesWithBasis(CategoryWithAxiom_over_base_ring): We now construct a more interesting morphism by extending a function by linearity:: - sage: phi = H(on_basis=lambda i: Y.monomial(i + 2)); phi # optional - sage.modules + sage: phi = H(on_basis=lambda i: Y.monomial(i + 2)); phi # needs sage.modules Generic morphism: From: X To: Y - sage: phi(x) # optional - sage.modules + sage: phi(x) # needs sage.modules B[3] + 3*B[4] We can retrieve the function acting on indices of the basis:: - sage: f = phi.on_basis() # optional - sage.modules - sage: f(1), f(2) # optional - sage.modules + sage: f = phi.on_basis() # needs sage.modules + sage: f(1), f(2) # needs sage.modules (B[3], B[4]) `Hom(X,Y)` has a natural module structure (except for the zero, @@ -109,14 +109,14 @@ class ModulesWithBasis(CategoryWithAxiom_over_base_ring): basis; but see :class:`FiniteDimensionalModulesWithBasis` and :class:`GradedModulesWithBasis`:: - sage: H in ModulesWithBasis(QQ), H in Modules(QQ) # optional - sage.modules + sage: H in ModulesWithBasis(QQ), H in Modules(QQ) # needs sage.modules (False, True) Some more playing around with categories and higher order homsets:: - sage: H.category() # optional - sage.modules + sage: H.category() # needs sage.modules Category of homsets of modules with basis over Rational Field - sage: Hom(H, H).category() # optional - sage.modules + sage: Hom(H, H).category() # needs sage.modules Category of endsets of homsets of modules with basis over Rational Field .. TODO:: ``End(X)`` is an algebra. @@ -129,10 +129,10 @@ class ModulesWithBasis(CategoryWithAxiom_over_base_ring): TESTS:: - sage: f = H.zero().on_basis() # optional - sage.modules - sage: f(1) # optional - sage.modules + sage: f = H.zero().on_basis() # needs sage.modules + sage: f(1) # needs sage.modules 0 - sage: f(2) # optional - sage.modules + sage: f(2) # needs sage.modules 0 sage: TestSuite(ModulesWithBasis(ZZ)).run() @@ -152,20 +152,20 @@ def _call_(self, x): ``x`` is returned unchanged if it is already in this category:: - sage: CZ(CombinatorialFreeModule(ZZ, ('a', 'b', 'c'))) # optional - sage.modules + sage: CZ(CombinatorialFreeModule(ZZ, ('a', 'b', 'c'))) # needs sage.modules Free module generated by {'a', 'b', 'c'} over Integer Ring - sage: CZ(ZZ^3) # optional - sage.modules + sage: CZ(ZZ^3) # needs sage.modules Ambient free module of rank 3 over the principal ideal domain Integer Ring If needed (and possible) the base ring is changed appropriately:: - sage: CQ(ZZ^3) # indirect doctest # optional - sage.modules + sage: CQ(ZZ^3) # indirect doctest # needs sage.modules Vector space of dimension 3 over Rational Field If ``x`` itself is not a module with basis, but there is a canonical one associated to it, the latter is returned:: - sage: CQ(AbelianVariety(Gamma0(37))) # indirect doctest # optional - sage.modular sage.modules + sage: CQ(AbelianVariety(Gamma0(37))) # indirect doctest # needs sage.modular sage.modules Vector space of dimension 4 over Rational Field """ try: @@ -210,14 +210,14 @@ def basis(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) # optional - sage.modules - sage: F.basis() # optional - sage.modules + sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) # needs sage.modules + sage: F.basis() # needs sage.modules Finite family {'a': B['a'], 'b': B['b'], 'c': B['c']} :: - sage: QS3 = SymmetricGroupAlgebra(QQ, 3) # optional - sage.group sage.modules - sage: list(QS3.basis()) # optional - sage.group sage.modules + sage: QS3 = SymmetricGroupAlgebra(QQ, 3) # needs sage.combinat sage.groups sage.modules + sage: list(QS3.basis()) # needs sage.combinat sage.groups sage.modules [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]] """ from sage.sets.family import Family @@ -298,16 +298,16 @@ def module_morphism(self, on_basis=None, matrix=None, function=None, :: - sage: X = CombinatorialFreeModule(QQ, [1,2,3]); X.rename("X") # optional - sage.modules - sage: Y = CombinatorialFreeModule(QQ, [1,2,3,4]); Y.rename("Y") # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(QQ, [1,2,3]); X.rename("X") + sage: Y = CombinatorialFreeModule(QQ, [1,2,3,4]); Y.rename("Y") sage: def f(i): ....: return Y.monomial(i) + 2*Y.monomial(i+1) - sage: phi = X.module_morphism(f, codomain=Y) # optional - sage.modules - sage: x = X.basis(); y = Y.basis() # optional - sage.modules - sage: phi(x[1] + x[3]) # optional - sage.modules + sage: phi = X.module_morphism(f, codomain=Y) + sage: x = X.basis(); y = Y.basis() + sage: phi(x[1] + x[3]) B[1] + 2*B[2] + B[3] + 2*B[4] - - sage: phi # optional - sage.modules + sage: phi Generic morphism: From: X To: Y @@ -318,7 +318,7 @@ def module_morphism(self, on_basis=None, matrix=None, function=None, ``CommutativeAdditiveMonoids()`` that contains both the domain and the codomain:: - sage: phi.category_for() # optional - sage.modules + sage: phi.category_for() # needs sage.modules Category of finite dimensional vector spaces with basis over Rational Field @@ -326,42 +326,44 @@ def module_morphism(self, on_basis=None, matrix=None, function=None, sage: def f(i): ....: return Y.monomial(i) + 2*Y.monomial(i+1) - sage: phi = X.module_morphism(f, codomain=Y, zero=10*y[1]) # optional - sage.modules - sage: phi(x[1] + x[3]) # optional - sage.modules + sage: phi = X.module_morphism(f, codomain=Y, zero=10*y[1]) # needs sage.modules + sage: phi(x[1] + x[3]) # needs sage.modules 11*B[1] + 2*B[2] + B[3] + 2*B[4] In this special case, the default category is ``Sets()``:: - sage: phi.category_for() # optional - sage.modules + sage: phi.category_for() # needs sage.modules Category of sets One can construct morphisms with the base ring as codomain:: - sage: X = CombinatorialFreeModule(ZZ, [1, -1]) # optional - sage.modules - sage: phi = X.module_morphism(on_basis=lambda i: i, codomain=ZZ) # optional - sage.modules - sage: phi(2 * X.monomial(1) + 3 * X.monomial(-1)) # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(ZZ, [1, -1]) + sage: phi = X.module_morphism(on_basis=lambda i: i, codomain=ZZ) + sage: phi(2 * X.monomial(1) + 3 * X.monomial(-1)) -1 - sage: phi.category_for() # optional - sage.modules + sage: phi.category_for() Category of commutative additive semigroups - sage: phi.category_for() # todo: not implemented (ZZ is currently not in Modules(ZZ)) # optional - sage.modules + sage: phi.category_for() # not implemented Category of modules over Integer Ring Or more generally any ring admitting a coercion map from the base ring:: - sage: phi = X.module_morphism(on_basis=lambda i: i, codomain=RR) # optional - sage.modules - sage: phi(2 * X.monomial(1) + 3 * X.monomial(-1)) # optional - sage.modules + sage: # needs sage.modules + sage: phi = X.module_morphism(on_basis=lambda i: i, codomain=RR) + sage: phi(2 * X.monomial(1) + 3 * X.monomial(-1)) -1.00000000000000 - sage: phi.category_for() # optional - sage.modules + sage: phi.category_for() Category of commutative additive semigroups - sage: phi.category_for() # todo: not implemented (RR is currently not in Modules(ZZ)) # optional - sage.modules + sage: phi.category_for() # not implemented Category of modules over Integer Ring - sage: phi = X.module_morphism(on_basis=lambda i: i, codomain=Zmod(4)) # optional - sage.modules - sage: phi(2 * X.monomial(1) + 3 * X.monomial(-1)) # optional - sage.modules + sage: phi = X.module_morphism(on_basis=lambda i: i, codomain=Zmod(4)) # needs sage.modules + sage: phi(2 * X.monomial(1) + 3 * X.monomial(-1)) # needs sage.modules 3 - sage: phi = Y.module_morphism(on_basis=lambda i: i, codomain=Zmod(4)) # optional - sage.modules + sage: phi = Y.module_morphism(on_basis=lambda i: i, codomain=Zmod(4)) # needs sage.modules Traceback (most recent call last): ... ValueError: codomain(=Ring of integers modulo 4) should be a module @@ -371,46 +373,48 @@ def module_morphism(self, on_basis=None, matrix=None, function=None, over different base rings; here we implement the natural map from `X = \RR^2` to `Y = \CC`:: - sage: X = CombinatorialFreeModule(RR, ['x', 'y']) # optional - sage.modules - sage: Y = CombinatorialFreeModule(CC, ['z']) # optional - sage.modules - sage: x = X.monomial('x') # optional - sage.modules - sage: y = X.monomial('y') # optional - sage.modules - sage: z = Y.monomial('z') # optional - sage.modules - sage: def on_basis(a): # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(RR, ['x', 'y']) + sage: Y = CombinatorialFreeModule(CC, ['z']) + sage: x = X.monomial('x') + sage: y = X.monomial('y') + sage: z = Y.monomial('z') + sage: def on_basis(a): ....: if a == 'x': ....: return CC(1) * z ....: elif a == 'y': ....: return CC(I) * z - sage: phi = X.module_morphism(on_basis=on_basis, codomain=Y) # optional - sage.modules - sage: v = 3 * x + 2 * y; v # optional - sage.modules + sage: phi = X.module_morphism(on_basis=on_basis, codomain=Y) + sage: v = 3 * x + 2 * y; v 3.00000000000000*B['x'] + 2.00000000000000*B['y'] - sage: phi(v) # optional - sage.modules + sage: phi(v) # needs sage.symbolic (3.00000000000000+2.00000000000000*I)*B['z'] - sage: phi.category_for() # optional - sage.modules + sage: phi.category_for() Category of commutative additive semigroups - sage: phi.category_for() # todo: not implemented (CC is currently not in Modules(RR)!) # optional - sage.modules + sage: phi.category_for() # not implemented Category of vector spaces over Real Field with 53 bits of precision - sage: Y = CombinatorialFreeModule(CC['q'], ['z']) # optional - sage.modules - sage: z = Y.monomial('z') # optional - sage.modules - sage: phi = X.module_morphism(on_basis=on_basis, codomain=Y) # optional - sage.modules - sage: phi(v) # optional - sage.modules + sage: # needs sage.modules + sage: Y = CombinatorialFreeModule(CC['q'], ['z']) + sage: z = Y.monomial('z') + sage: phi = X.module_morphism(on_basis=on_basis, codomain=Y) + sage: phi(v) # needs sage.symbolic (3.00000000000000+2.00000000000000*I)*B['z'] Of course, there should be a coercion between the respective base rings of the domain and the codomain for this to be meaningful:: - sage: Y = CombinatorialFreeModule(QQ, ['z']) # optional - sage.modules - sage: phi = X.module_morphism(on_basis=on_basis, codomain=Y) # optional - sage.modules + sage: Y = CombinatorialFreeModule(QQ, ['z']) # needs sage.modules + sage: phi = X.module_morphism(on_basis=on_basis, codomain=Y) # needs sage.modules Traceback (most recent call last): ... ValueError: codomain(=Free module generated by {'z'} over Rational Field) should be a module over the base ring of the domain(=Free module generated by {'x', 'y'} over Real Field with 53 bits of precision) - sage: Y = CombinatorialFreeModule(RR['q'], ['z']) # optional - sage.modules - sage: phi = Y.module_morphism(on_basis=on_basis, codomain=X) # optional - sage.modules + sage: Y = CombinatorialFreeModule(RR['q'], ['z']) # needs sage.modules + sage: phi = Y.module_morphism(on_basis=on_basis, codomain=X) # needs sage.modules Traceback (most recent call last): ... ValueError: codomain(=Free module generated by {'x', 'y'} @@ -429,11 +433,12 @@ def module_morphism(self, on_basis=None, matrix=None, function=None, This assumes that the respective bases `x` and `y` of `X` and `Y` have the same index set `I`:: - sage: X = CombinatorialFreeModule(ZZ, [1, 2, 3]); X.rename("X") # optional - sage.modules - sage: from sage.arith.misc import factorial # optional - sage.modules - sage: phi = X.module_morphism(diagonal=factorial, codomain=X) # optional - sage.modules - sage: x = X.basis() # optional - sage.modules - sage: phi(x[1]), phi(x[2]), phi(x[3]) # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(ZZ, [1, 2, 3]); X.rename("X") + sage: from sage.arith.misc import factorial + sage: phi = X.module_morphism(diagonal=factorial, codomain=X) + sage: x = X.basis() + sage: phi(x[1]), phi(x[2]), phi(x[3]) (B[1], 2*B[2], 6*B[3]) See also: :class:`sage.modules.with_basis.morphism.DiagonalModuleMorphism`. @@ -442,15 +447,16 @@ def module_morphism(self, on_basis=None, matrix=None, function=None, morphism whose matrix in the distinguished basis of `X` and `Y` is `m`:: - sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") # optional - sage.modules - sage: x = X.basis() # optional - sage.modules - sage: Y = CombinatorialFreeModule(ZZ, [3,4]); Y.rename("Y") # optional - sage.modules - sage: y = Y.basis() # optional - sage.modules - sage: m = matrix([[0,1,2], [3,5,0]]) # optional - sage.modules - sage: phi = X.module_morphism(matrix=m, codomain=Y) # optional - sage.modules - sage: phi(x[1]) # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") + sage: x = X.basis() + sage: Y = CombinatorialFreeModule(ZZ, [3,4]); Y.rename("Y") + sage: y = Y.basis() + sage: m = matrix([[0,1,2], [3,5,0]]) + sage: phi = X.module_morphism(matrix=m, codomain=Y) + sage: phi(x[1]) 3*B[4] - sage: phi(x[2]) # optional - sage.modules + sage: phi(x[2]) B[3] + 5*B[4] @@ -462,37 +468,39 @@ def module_morphism(self, on_basis=None, matrix=None, function=None, invertible elements on its diagonal. This is used to compute preimages and to invert the morphism:: + sage: # needs sage.modules sage: I = list(range(1, 200)) - sage: X = CombinatorialFreeModule(QQ, I); X.rename("X"); x = X.basis() # optional - sage.modules - sage: Y = CombinatorialFreeModule(QQ, I); Y.rename("Y"); y = Y.basis() # optional - sage.modules - sage: f = Y.sum_of_monomials * divisors # optional - sage.modules - sage: phi = X.module_morphism(f, triangular="upper", codomain=Y) # optional - sage.modules - sage: phi(x[2]) # optional - sage.modules + sage: X = CombinatorialFreeModule(QQ, I); X.rename("X"); x = X.basis() + sage: Y = CombinatorialFreeModule(QQ, I); Y.rename("Y"); y = Y.basis() + sage: f = Y.sum_of_monomials * divisors + sage: phi = X.module_morphism(f, triangular="upper", codomain=Y) + sage: phi(x[2]) B[1] + B[2] - sage: phi(x[6]) # optional - sage.modules + sage: phi(x[6]) B[1] + B[2] + B[3] + B[6] - sage: phi(x[30]) # optional - sage.modules + sage: phi(x[30]) B[1] + B[2] + B[3] + B[5] + B[6] + B[10] + B[15] + B[30] - sage: phi.preimage(y[2]) # optional - sage.modules + sage: phi.preimage(y[2]) -B[1] + B[2] - sage: phi.preimage(y[6]) # optional - sage.modules + sage: phi.preimage(y[6]) B[1] - B[2] - B[3] + B[6] - sage: phi.preimage(y[30]) # optional - sage.modules + sage: phi.preimage(y[30]) -B[1] + B[2] + B[3] + B[5] - B[6] - B[10] - B[15] + B[30] - sage: (phi^-1)(y[30]) # optional - sage.modules + sage: (phi^-1)(y[30]) -B[1] + B[2] + B[3] + B[5] - B[6] - B[10] - B[15] + B[30] Since :trac:`8678`, one can also define a triangular morphism from a function:: - sage: X = CombinatorialFreeModule(QQ, [0,1,2,3,4]); x = X.basis() # optional - sage.modules - sage: from sage.modules.with_basis.morphism import TriangularModuleMorphismFromFunction # optional - sage.modules - sage: def f(x): return x + X.term(0, sum(x.coefficients())) # optional - sage.modules - sage: phi = X.module_morphism(function=f, codomain=X, # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(QQ, [0,1,2,3,4]); x = X.basis() + sage: from sage.modules.with_basis.morphism import TriangularModuleMorphismFromFunction + sage: def f(x): return x + X.term(0, sum(x.coefficients())) + sage: phi = X.module_morphism(function=f, codomain=X, ....: triangular="upper") - sage: phi(x[2] + 3*x[4]) # optional - sage.modules + sage: phi(x[2] + 3*x[4]) 4*B[0] + B[2] + 3*B[4] - sage: phi.preimage(_) # optional - sage.modules + sage: phi.preimage(_) B[2] + 3*B[4] For details and further optional arguments, see @@ -515,8 +523,8 @@ def module_morphism(self, on_basis=None, matrix=None, function=None, TESTS:: - sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") # optional - sage.modules - sage: phi = X.module_morphism(codomain=X) # optional - sage.modules + sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") # needs sage.modules + sage: phi = X.module_morphism(codomain=X) # needs sage.modules Traceback (most recent call last): ... ValueError: module_morphism() takes exactly one option @@ -524,8 +532,8 @@ def module_morphism(self, on_basis=None, matrix=None, function=None, :: - sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") # optional - sage.modules - sage: phi = X.module_morphism(diagonal=factorial, matrix=matrix(), # optional - sage.modules + sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") # needs sage.modules + sage: phi = X.module_morphism(diagonal=factorial, matrix=matrix(), # needs sage.modules ....: codomain=X) Traceback (most recent call last): ... @@ -534,16 +542,16 @@ def module_morphism(self, on_basis=None, matrix=None, function=None, :: - sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") # optional - sage.modules - sage: phi = X.module_morphism(matrix=factorial, codomain=X) # optional - sage.modules + sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") # needs sage.modules + sage: phi = X.module_morphism(matrix=factorial, codomain=X) # needs sage.modules Traceback (most recent call last): ... ValueError: matrix (=...factorial...) should be a matrix :: - sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") # optional - sage.modules - sage: phi = X.module_morphism(diagonal=3, codomain=X) # optional - sage.modules + sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") # needs sage.modules + sage: phi = X.module_morphism(diagonal=3, codomain=X) # needs sage.modules Traceback (most recent call last): ... ValueError: diagonal (=3) should be a function @@ -582,14 +590,13 @@ def _repr_(self): """ EXAMPLES:: - sage: class FooBar(CombinatorialFreeModule): pass # optional - sage.modules - sage: C = FooBar(QQ, (1,2,3)); C # indirect doctest # optional - sage.modules + sage: # needs sage.modules + sage: class FooBar(CombinatorialFreeModule): pass + sage: C = FooBar(QQ, (1,2,3)); C # indirect doctest Free module generated by {1, 2, 3} over Rational Field - - sage: C._name = "foobar"; C # optional - sage.modules + sage: C._name = "foobar"; C foobar over Rational Field - - sage: C.rename("barfoo"); C # optional - sage.modules + sage: C.rename("barfoo"); C barfoo sage: class FooBar(Parent): @@ -619,28 +626,30 @@ def _compute_support_order(self, elements, support_order=None): A finite dimensional module:: - sage: V = CombinatorialFreeModule(QQ, range(10), prefix='x') # optional - sage.modules - sage: B = V.basis() # optional - sage.modules - sage: elts = [B[0] - 2*B[3], B[5] + 2*B[0], # optional - sage.modules + sage: # needs sage.modules + sage: V = CombinatorialFreeModule(QQ, range(10), prefix='x') + sage: B = V.basis() + sage: elts = [B[0] - 2*B[3], B[5] + 2*B[0], ....: B[2], B[3], B[1] + B[2] + B[8]] - sage: V._compute_support_order(elts) # optional - sage.modules + sage: V._compute_support_order(elts) (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) - sage: V._compute_support_order(elts, [1,2,0,4,3,5,9,8,7,6]) # optional - sage.modules + sage: V._compute_support_order(elts, [1,2,0,4,3,5,9,8,7,6]) (1, 2, 0, 4, 3, 5, 9, 8, 7, 6) - sage: V._compute_support_order(elts, lambda x: -x) # optional - sage.modules + sage: V._compute_support_order(elts, lambda x: -x) (8, 5, 3, 2, 1, 0) An infinite dimensional module:: - sage: V = CombinatorialFreeModule(QQ, ZZ, prefix='z') # optional - sage.modules - sage: B = V.basis() # optional - sage.modules - sage: elts = [B[0] - 2*B[3], B[5] + 2*B[0], # optional - sage.modules + sage: # needs sage.modules + sage: V = CombinatorialFreeModule(QQ, ZZ, prefix='z') + sage: B = V.basis() + sage: elts = [B[0] - 2*B[3], B[5] + 2*B[0], ....: B[2], B[3], B[1] + B[2] + B[8]] - sage: V._compute_support_order(elts) # optional - sage.modules + sage: V._compute_support_order(elts) (0, 1, 2, 3, 5, 8) - sage: V._compute_support_order(elts, [1,2,0,4,3,5,9,8,7,6]) # optional - sage.modules + sage: V._compute_support_order(elts, [1,2,0,4,3,5,9,8,7,6]) (1, 2, 0, 4, 3, 5, 9, 8, 7, 6) - sage: V._compute_support_order(elts, lambda x: -x) # optional - sage.modules + sage: V._compute_support_order(elts, lambda x: -x) (8, 5, 3, 2, 1, 0) """ if support_order is None: @@ -685,17 +694,17 @@ def echelon_form(self, elements, row_reduced=False, order=None): EXAMPLES:: sage: R. = QQ[] - sage: C = CombinatorialFreeModule(R, ZZ, prefix='z') # optional - sage.modules - sage: z = C.basis() # optional - sage.modules - sage: C.echelon_form([z[0] - z[1], 2*z[1] - 2*z[2], z[0] - z[2]]) # optional - sage.modules + sage: C = CombinatorialFreeModule(R, ZZ, prefix='z') # needs sage.modules + sage: z = C.basis() # needs sage.modules + sage: C.echelon_form([z[0] - z[1], 2*z[1] - 2*z[2], z[0] - z[2]]) # needs sage.libs.singular sage.modules [z[0] - z[2], z[1] - z[2]] TESTS: We convert the input elements to ``self``:: - sage: s = SymmetricFunctions(QQ).s() # optional - sage.combinat sage.modules - sage: s.echelon_form([1, s[1] + 5]) # optional - sage.combinat sage.modules + sage: s = SymmetricFunctions(QQ).s() # needs sage.combinat sage.modules + sage: s.echelon_form([1, s[1] + 5]) # needs sage.combinat sage.modules [s[], s[1]] """ # Make sure elements consists of elements of ``self`` @@ -764,21 +773,22 @@ def submodule(self, gens, check=True, already_echelonized=False, `x_0, x_1, x_2`. The submodule is spanned by `y_0 = x_0 - x_1` and `y_1 - x_1 - x_2`, and its basis elements are indexed by `0` and `1`:: - sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x") # optional - sage.modules - sage: x = X.basis() # optional - sage.modules - sage: gens = [x[0] - x[1], x[1] - x[2]]; gens # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x") + sage: x = X.basis() + sage: gens = [x[0] - x[1], x[1] - x[2]]; gens [x[0] - x[1], x[1] - x[2]] - sage: Y = X.submodule(gens, already_echelonized=True) # optional - sage.modules - sage: Y.print_options(prefix='y'); Y # optional - sage.modules + sage: Y = X.submodule(gens, already_echelonized=True) + sage: Y.print_options(prefix='y'); Y Free module generated by {0, 1} over Rational Field - sage: y = Y.basis() # optional - sage.modules - sage: y[1] # optional - sage.modules + sage: y = Y.basis() + sage: y[1] y[1] - sage: y[1].lift() # optional - sage.modules + sage: y[1].lift() x[1] - x[2] - sage: Y.retract(x[0] - x[2]) # optional - sage.modules + sage: Y.retract(x[0] - x[2]) y[0] + y[1] - sage: Y.retract(x[0]) # optional - sage.modules + sage: Y.retract(x[0]) Traceback (most recent call last): ... ValueError: x[0] is not in the image @@ -786,23 +796,24 @@ def submodule(self, gens, check=True, already_echelonized=False, By using a family to specify a basis of the submodule, we obtain a submodule whose index set coincides with the index set of the family:: - sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x") # optional - sage.modules - sage: x = X.basis() # optional - sage.modules - sage: gens = Family({1: x[0] - x[1], 3: x[1] - x[2]}); gens # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x") + sage: x = X.basis() + sage: gens = Family({1: x[0] - x[1], 3: x[1] - x[2]}); gens Finite family {1: x[0] - x[1], 3: x[1] - x[2]} - sage: Y = X.submodule(gens, already_echelonized=True) # optional - sage.modules - sage: Y.print_options(prefix='y'); Y # optional - sage.modules + sage: Y = X.submodule(gens, already_echelonized=True) + sage: Y.print_options(prefix='y'); Y Free module generated by {1, 3} over Rational Field - sage: y = Y.basis() # optional - sage.modules - sage: y[1] # optional - sage.modules + sage: y = Y.basis() + sage: y[1] y[1] - sage: y[1].lift() # optional - sage.modules + sage: y[1].lift() x[0] - x[1] - sage: y[3].lift() # optional - sage.modules + sage: y[3].lift() x[1] - x[2] - sage: Y.retract(x[0] - x[2]) # optional - sage.modules + sage: Y.retract(x[0] - x[2]) y[1] + y[3] - sage: Y.retract(x[0]) # optional - sage.modules + sage: Y.retract(x[0]) Traceback (most recent call last): ... ValueError: x[0] is not in the image @@ -810,56 +821,59 @@ def submodule(self, gens, check=True, already_echelonized=False, It is not necessary that the generators of the submodule form a basis (an explicit basis will be computed):: - sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x") # optional - sage.modules - sage: x = X.basis() # optional - sage.modules - sage: gens = [x[0] - x[1], 2*x[1] - 2*x[2], x[0] - x[2]]; gens # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x") + sage: x = X.basis() + sage: gens = [x[0] - x[1], 2*x[1] - 2*x[2], x[0] - x[2]]; gens [x[0] - x[1], 2*x[1] - 2*x[2], x[0] - x[2]] - sage: Y = X.submodule(gens, already_echelonized=False) # optional - sage.modules - sage: Y.print_options(prefix='y') # optional - sage.modules - sage: Y # optional - sage.modules + sage: Y = X.submodule(gens, already_echelonized=False) + sage: Y.print_options(prefix='y') + sage: Y Free module generated by {0, 1} over Rational Field - sage: [b.lift() for b in Y.basis()] # optional - sage.modules + sage: [b.lift() for b in Y.basis()] [x[0] - x[2], x[1] - x[2]] We now implement by hand the center of the algebra of the symmetric group `S_3`:: - sage: S3 = SymmetricGroup(3) # optional - sage.groups sage.modules - sage: S3A = S3.algebra(QQ) # optional - sage.groups sage.modules - sage: basis = S3A.annihilator_basis(S3A.algebra_generators(), # optional - sage.groups sage.modules + sage: # needs sage.combinat sage.groups sage.modules + sage: S3 = SymmetricGroup(3) + sage: S3A = S3.algebra(QQ) + sage: basis = S3A.annihilator_basis(S3A.algebra_generators(), ....: S3A.bracket) - sage: basis # optional - sage.groups sage.modules + sage: basis ((), (1,2,3) + (1,3,2), (2,3) + (1,2) + (1,3)) - sage: center = S3A.submodule(basis, # optional - sage.groups sage.modules + sage: center = S3A.submodule(basis, ....: category=AlgebrasWithBasis(QQ).Subobjects(), ....: already_echelonized=True) - sage: center # optional - sage.groups sage.modules + sage: center Free module generated by {0, 1, 2} over Rational Field - sage: center in Algebras # optional - sage.groups sage.modules + sage: center in Algebras True - sage: center.print_options(prefix='c') # optional - sage.groups sage.modules - sage: c = center.basis() # optional - sage.groups sage.modules - sage: c[1].lift() # optional - sage.groups sage.modules + sage: center.print_options(prefix='c') + sage: c = center.basis() + sage: c[1].lift() (1,2,3) + (1,3,2) - sage: c[0]^2 # optional - sage.groups sage.modules + sage: c[0]^2 c[0] - sage: e = 1/6 * (c[0]+c[1]+c[2]) # optional - sage.groups sage.modules - sage: e.is_idempotent() # optional - sage.groups sage.modules + sage: e = 1/6 * (c[0]+c[1]+c[2]) + sage: e.is_idempotent() True Of course, this center is best constructed using:: - sage: center = S3A.center() # optional - sage.groups sage.modules + sage: center = S3A.center() # needs sage.combinat sage.groups sage.modules We can also automatically construct a basis such that the lift morphism is (lower) unitriangular:: + sage: # needs sage.modules sage: R. = QQ[] - sage: C = CombinatorialFreeModule(R, range(3), prefix='x') # optional - sage.modules - sage: x = C.basis() # optional - sage.modules - sage: gens = [x[0] - x[1], 2*x[1] - 2*x[2], x[0] - x[2]] # optional - sage.modules - sage: Y = C.submodule(gens, unitriangular=True) # optional - sage.modules - sage: Y.lift.matrix() # optional - sage.modules + sage: C = CombinatorialFreeModule(R, range(3), prefix='x') + sage: x = C.basis() + sage: gens = [x[0] - x[1], 2*x[1] - 2*x[2], x[0] - x[2]] + sage: Y = C.submodule(gens, unitriangular=True) + sage: Y.lift.matrix() [ 1 0] [ 0 1] [-1 -1] @@ -867,17 +881,18 @@ def submodule(self, gens, check=True, already_echelonized=False, We now construct a (finite-dimensional) submodule of an infinite dimensional free module:: - sage: C = CombinatorialFreeModule(QQ, ZZ, prefix='z') # optional - sage.modules - sage: z = C.basis() # optional - sage.modules - sage: gens = [z[0] - z[1], 2*z[1] - 2*z[2], z[0] - z[2]] # optional - sage.modules - sage: Y = C.submodule(gens) # optional - sage.modules - sage: [Y.lift(b) for b in Y.basis()] # optional - sage.modules + sage: # needs sage.modules + sage: C = CombinatorialFreeModule(QQ, ZZ, prefix='z') + sage: z = C.basis() + sage: gens = [z[0] - z[1], 2*z[1] - 2*z[2], z[0] - z[2]] + sage: Y = C.submodule(gens) + sage: [Y.lift(b) for b in Y.basis()] [z[0] - z[2], z[1] - z[2]] TESTS:: - sage: TestSuite(Y).run() # optional - sage.modules - sage: TestSuite(center).run() # optional - sage.groups sage.modules + sage: TestSuite(Y).run() # needs sage.modules + sage: TestSuite(center).run() # needs sage.combinat sage.groups sage.modules """ # Make sure gens consists of elements of ``self`` from sage.sets.family import Family, AbstractFamily @@ -920,25 +935,27 @@ def quotient_module(self, submodule, check=True, already_echelonized=False, cate EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x") # optional - sage.modules - sage: x = X.basis() # optional - sage.modules - sage: Y = X.quotient_module([x[0] - x[1], x[1] - x[2]], # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x") + sage: x = X.basis() + sage: Y = X.quotient_module([x[0] - x[1], x[1] - x[2]], ....: already_echelonized=True) - sage: Y.print_options(prefix='y'); Y # optional - sage.modules + sage: Y.print_options(prefix='y'); Y Free module generated by {2} over Rational Field - sage: y = Y.basis() # optional - sage.modules - sage: y[2] # optional - sage.modules + sage: y = Y.basis() + sage: y[2] y[2] - sage: y[2].lift() # optional - sage.modules + sage: y[2].lift() x[2] - sage: Y.retract(x[0] + 2*x[1]) # optional - sage.modules + sage: Y.retract(x[0] + 2*x[1]) 3*y[2] + sage: # needs sage.modules sage: R. = QQ[] - sage: C = CombinatorialFreeModule(R, range(3), prefix='x') # optional - sage.modules - sage: x = C.basis() # optional - sage.modules - sage: gens = [x[0] - x[1], 2*x[1] - 2*x[2], x[0] - x[2]] # optional - sage.modules - sage: Y = C.quotient_module(gens) # optional - sage.modules + sage: C = CombinatorialFreeModule(R, range(3), prefix='x') + sage: x = C.basis() + sage: gens = [x[0] - x[1], 2*x[1] - 2*x[2], x[0] - x[2]] + sage: Y = C.quotient_module(gens) .. SEEALSO:: @@ -960,10 +977,10 @@ def tensor(*parents, **kwargs): EXAMPLES:: sage: C = AlgebrasWithBasis(QQ) - sage: A = C.example(); A.rename("A") # optional - sage.combinat sage.modules - sage: A.tensor(A, A) # optional - sage.combinat sage.modules + sage: A = C.example(); A.rename("A") # needs sage.combinat sage.modules + sage: A.tensor(A, A) # needs sage.combinat sage.modules A # A # A - sage: A.rename(None) # optional - sage.combinat sage.modules + sage: A.rename(None) # needs sage.combinat sage.modules """ constructor = kwargs.pop('constructor', tensor) cat = constructor.category_from_parents(parents) @@ -975,24 +992,26 @@ def cardinality(self): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 4) # optional - sage.groups sage.modules - sage: S.cardinality() # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: S = SymmetricGroupAlgebra(QQ, 4) + sage: S.cardinality() +Infinity - sage: S = SymmetricGroupAlgebra(GF(2), 4) # not tested -- MRO bug trac #15475 # optional - sage.groups sage.rings.finite_rings sage.modules - sage: S.cardinality() # not tested -- MRO bug trac #15475 # optional - sage.groups sage.rings.finite_rings sage.modules + sage: S = SymmetricGroupAlgebra(GF(2), 4) # not tested + sage: S.cardinality() # not tested 16777216 - sage: S.cardinality().factor() # not tested -- MRO bug trac #15475 # optional - sage.groups sage.rings.finite_rings sage.modules + sage: S.cardinality().factor() # not tested 2^24 - sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules - sage: E.cardinality() # optional - sage.combinat sage.modules + sage: # needs sage.modules + sage: E. = ExteriorAlgebra(QQ) + sage: E.cardinality() +Infinity - sage: E. = ExteriorAlgebra(GF(3)) # optional - sage.combinat sage.rings.finite_rings sage.modules - sage: E.cardinality() # optional - sage.combinat sage.rings.finite_rings sage.modules + sage: E. = ExteriorAlgebra(GF(3)) + sage: E.cardinality() 81 - sage: s = SymmetricFunctions(GF(2)).s() # optional - sage.combinat sage.rings.finite_rings sage.modules - sage: s.cardinality() # optional - sage.combinat sage.rings.finite_rings sage.modules + sage: s = SymmetricFunctions(GF(2)).s() # needs sage.combinat sage.modules + sage: s.cardinality() # needs sage.combinat sage.modules +Infinity """ from sage.rings.infinity import Infinity @@ -1009,11 +1028,11 @@ def is_finite(self): EXAMPLES:: - sage: GroupAlgebra(SymmetricGroup(2), IntegerModRing(10)).is_finite() # optional - sage.groups sage.modules + sage: GroupAlgebra(SymmetricGroup(2), IntegerModRing(10)).is_finite() # needs sage.combinat sage.groups sage.modules True - sage: GroupAlgebra(SymmetricGroup(2)).is_finite() # optional - sage.groups sage.modules + sage: GroupAlgebra(SymmetricGroup(2)).is_finite() # needs sage.combinat sage.groups sage.modules False - sage: GroupAlgebra(AbelianGroup(1), IntegerModRing(10)).is_finite() # optional - sage.groups sage.modules + sage: GroupAlgebra(AbelianGroup(1), IntegerModRing(10)).is_finite() # needs sage.groups sage.modules False """ return (self.base_ring().is_finite() and self.group().is_finite()) @@ -1028,13 +1047,13 @@ def monomial(self, i): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) # optional - sage.modules - sage: F.monomial('a') # optional - sage.modules + sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) # needs sage.modules + sage: F.monomial('a') # needs sage.modules B['a'] ``F.monomial`` is in fact (almost) a map:: - sage: F.monomial # optional - sage.modules + sage: F.monomial # needs sage.modules Term map from {'a', 'b', 'c'} to Free module generated by {'a', 'b', 'c'} over Rational Field """ @@ -1045,8 +1064,8 @@ def _sum_of_monomials(self, indices): TESTS:: sage: R. = QQ[] - sage: W = DifferentialWeylAlgebra(R) # optional - sage.combinat sage.modules - sage: W._sum_of_monomials([((1,0), (1,0)), ((0,0), (0,1))]) # optional - sage.combinat sage.modules + sage: W = DifferentialWeylAlgebra(R) # needs sage.modules + sage: W._sum_of_monomials([((1,0), (1,0)), ((0,0), (0,1))]) # needs sage.modules dy + x*dx """ # This is the generic implementation. When implementing a @@ -1067,16 +1086,16 @@ def sum_of_monomials(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) # optional - sage.modules - sage: F.sum_of_monomials(['a', 'b']) # optional - sage.modules + sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) # needs sage.modules + sage: F.sum_of_monomials(['a', 'b']) # needs sage.modules B['a'] + B['b'] - sage: F.sum_of_monomials(['a', 'b', 'a']) # optional - sage.modules + sage: F.sum_of_monomials(['a', 'b', 'a']) # needs sage.modules 2*B['a'] + B['b'] ``F.sum_of_monomials`` is in fact (almost) a map:: - sage: F.sum_of_monomials # optional - sage.modules + sage: F.sum_of_monomials # needs sage.modules A map to Free module generated by {'a', 'b', 'c'} over Rational Field """ # domain = iterables of basis indices of self. @@ -1086,10 +1105,10 @@ def monomial_or_zero_if_none(self, i): """ EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) # optional - sage.modules - sage: F.monomial_or_zero_if_none('a') # optional - sage.modules + sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) # needs sage.modules + sage: F.monomial_or_zero_if_none('a') # needs sage.modules B['a'] - sage: F.monomial_or_zero_if_none(None) # optional - sage.modules + sage: F.monomial_or_zero_if_none(None) # needs sage.modules 0 """ if i is None: @@ -1111,9 +1130,9 @@ def term(self, index, coeff=None): EXAMPLES:: - sage: m = matrix([[0,1], [1,1]]) # optional - sage.modules - sage: J. = JordanAlgebra(m) # optional - sage.combinat sage.modules - sage: J.term(1, -2) # optional - sage.combinat sage.modules + sage: m = matrix([[0,1], [1,1]]) # needs sage.modules + sage: J. = JordanAlgebra(m) # needs sage.combinat sage.modules + sage: J.term(1, -2) # needs sage.combinat sage.modules 0 + (-2, 0) Design: should this do coercion on the coefficient ring? @@ -1137,9 +1156,9 @@ def sum_of_terms(self, terms): EXAMPLES:: - sage: m = matrix([[0,1], [1,1]]) # optional - sage.modules - sage: J. = JordanAlgebra(m) # optional - sage.combinat sage.modules - sage: J.sum_of_terms([(0, 2), (2, -3)]) # optional - sage.combinat sage.modules + sage: m = matrix([[0,1], [1,1]]) # needs sage.modules + sage: J. = JordanAlgebra(m) # needs sage.combinat sage.modules + sage: J.sum_of_terms([(0, 2), (2, -3)]) # needs sage.combinat sage.modules 2 + (0, -3) """ return self.sum(self.term(index, coeff) for (index, coeff) in terms) @@ -1166,21 +1185,22 @@ def _apply_module_morphism(self, x, on_basis, codomain=False): EXAMPLES:: - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules - sage: a = s([3]) + s([2,1]) + s([1,1,1]) # optional - sage.combinat sage.modules - sage: b = 2*a # optional - sage.combinat sage.modules - sage: f = lambda part: Integer(len(part)) # optional - sage.combinat sage.modules - sage: s._apply_module_morphism(a, f) #1+2+3 # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: s = SymmetricFunctions(QQ).schur() + sage: a = s([3]) + s([2,1]) + s([1,1,1]) + sage: b = 2*a + sage: f = lambda part: Integer(len(part)) + sage: s._apply_module_morphism(a, f) #1+2+3 6 - sage: s._apply_module_morphism(b, f) #2*(1+2+3) # optional - sage.combinat sage.modules + sage: s._apply_module_morphism(b, f) #2*(1+2+3) 12 - sage: s._apply_module_morphism(s(0), f) # optional - sage.combinat sage.modules + sage: s._apply_module_morphism(s(0), f) 0 - sage: s._apply_module_morphism(s(1), f) # optional - sage.combinat sage.modules + sage: s._apply_module_morphism(s(1), f) 0 - sage: s._apply_module_morphism(s(1), lambda part: len(part), ZZ) # optional - sage.combinat sage.modules + sage: s._apply_module_morphism(s(1), lambda part: len(part), ZZ) 0 - sage: s._apply_module_morphism(s(1), lambda part: len(part)) # optional - sage.combinat sage.modules + sage: s._apply_module_morphism(s(1), lambda part: len(part)) Traceback (most recent call last): ... ValueError: codomain could not be determined @@ -1222,9 +1242,9 @@ def _apply_module_endomorphism(self, x, on_basis): EXAMPLES:: - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules - sage: f = lambda part: 2 * s(part.conjugate()) # optional - sage.combinat sage.modules - sage: s._apply_module_endomorphism(s([2,1]) + s([1,1,1]), f) # optional - sage.combinat sage.modules + sage: s = SymmetricFunctions(QQ).schur() # needs sage.combinat sage.modules + sage: f = lambda part: 2 * s(part.conjugate()) + sage: s._apply_module_endomorphism(s([2,1]) + s([1,1,1]), f) # needs sage.combinat sage.modules 2*s[2, 1] + 2*s[3] """ mc = x.monomial_coefficients(copy=False) @@ -1237,8 +1257,8 @@ def dimension(self): EXAMPLES:: - sage: A. = algebras.DifferentialWeyl(QQ) # optional - sage.combinat sage.modules - sage: A.dimension() # optional - sage.combinat sage.modules + sage: A. = algebras.DifferentialWeyl(QQ) # needs sage.modules + sage: A.dimension() # needs sage.modules +Infinity """ try: @@ -1258,17 +1278,18 @@ def _from_dict(self, d, coerce=True, remove_zeros=True): EXAMPLES:: - sage: A. = algebras.DifferentialWeyl(QQ) # optional - sage.combinat sage.modules - sage: K = A.basis().keys() # optional - sage.combinat sage.modules - sage: d = {K[0]: 3, K[12]: -4/3} # optional - sage.combinat sage.modules - sage: A._from_dict(d) # optional - sage.combinat sage.modules + sage: # needs sage.modules + sage: A. = algebras.DifferentialWeyl(QQ) + sage: K = A.basis().keys() + sage: d = {K[0]: 3, K[12]: -4/3} + sage: A._from_dict(d) -4/3*dx^2 + 3 sage: R. = QQ[] - sage: d = {K[0]: y, K[12]: -4/3} # optional - sage.combinat sage.modules - sage: A._from_dict(d, coerce=False) # optional - sage.combinat sage.modules + sage: d = {K[0]: y, K[12]: -4/3} # needs sage.modules + sage: A._from_dict(d, coerce=False) # needs sage.modules -4/3*dx^2 + y - sage: A._from_dict(d, coerce=True) # optional - sage.combinat sage.modules + sage: A._from_dict(d, coerce=True) # needs sage.modules Traceback (most recent call last): ... TypeError: not a constant polynomial @@ -1307,21 +1328,21 @@ def random_element(self, n=2): EXAMPLES:: - sage: x = DihedralGroup(6).algebra(QQ).random_element() # optional - sage.groups sage.modules - sage: x.parent() is DihedralGroup(6).algebra(QQ) # optional - sage.groups sage.modules + sage: x = DihedralGroup(6).algebra(QQ).random_element() # needs sage.groups sage.modules + sage: x.parent() is DihedralGroup(6).algebra(QQ) # needs sage.groups sage.modules True Note, this result can depend on the PRNG state in libgap in a way that depends on which packages are loaded, so we must re-seed GAP to ensure a consistent result for this example:: - sage: libgap.set_seed(0) # optional - sage.libs.gap + sage: libgap.set_seed(0) # needs sage.libs.gap 0 - sage: m = SU(2, 13).algebra(QQ).random_element(1) # optional - sage.groups sage.modules - sage: m.parent() is SU(2, 13).algebra(QQ) # optional - sage.groups sage.modules + sage: m = SU(2, 13).algebra(QQ).random_element(1) # needs sage.groups sage.libs.pari sage.modules + sage: m.parent() is SU(2, 13).algebra(QQ) # needs sage.groups sage.libs.pari sage.modules True - sage: p = CombinatorialFreeModule(ZZ, Partitions(4)).random_element() # optional - sage.combinat sage.modules - sage: p.parent() is CombinatorialFreeModule(ZZ, Partitions(4)) # optional - sage.combinat sage.modules + sage: p = CombinatorialFreeModule(ZZ, Partitions(4)).random_element() # needs sage.combinat sage.modules + sage: p.parent() is CombinatorialFreeModule(ZZ, Partitions(4)) # needs sage.combinat sage.modules True TESTS: @@ -1331,7 +1352,7 @@ def random_element(self, n=2): coerce the base ring's zero into the algebra, and that we can find a random element in a trivial module:: - sage: class Foo(CombinatorialFreeModule): # optional - sage.modules + sage: class Foo(CombinatorialFreeModule): # needs sage.modules ....: def _element_constructor_(self,x): ....: if x in self: ....: return x @@ -1339,8 +1360,8 @@ def random_element(self, n=2): ....: raise ValueError sage: from sage.categories.magmatic_algebras import MagmaticAlgebras sage: C = MagmaticAlgebras(QQ).WithBasis().Unital() - sage: F = Foo(QQ, tuple(), category=C) # optional - sage.modules - sage: F.random_element() == F.zero() # optional - sage.modules + sage: F = Foo(QQ, tuple(), category=C) # needs sage.modules + sage: F.random_element() == F.zero() # needs sage.modules True """ @@ -1380,25 +1401,27 @@ def monomial_coefficients(self, copy=True): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) # optional - sage.modules - sage: B = F.basis() # optional - sage.modules - sage: f = B['a'] + 3*B['c'] # optional - sage.modules - sage: d = f.monomial_coefficients() # optional - sage.modules - sage: d['a'] # optional - sage.modules + sage: # needs sage.modules + sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) + sage: B = F.basis() + sage: f = B['a'] + 3*B['c'] + sage: d = f.monomial_coefficients() + sage: d['a'] 1 - sage: d['c'] # optional - sage.modules + sage: d['c'] 3 TESTS: We check that we make a copy of the coefficient dictionary:: - sage: F = CombinatorialFreeModule(ZZ, ['a','b','c']) # optional - sage.modules - sage: B = F.basis() # optional - sage.modules - sage: f = B['a'] + 3*B['c'] # optional - sage.modules - sage: d = f.monomial_coefficients() # optional - sage.modules - sage: d['a'] = 5 # optional - sage.modules - sage: f # optional - sage.modules + sage: # needs sage.modules + sage: F = CombinatorialFreeModule(ZZ, ['a','b','c']) + sage: B = F.basis() + sage: f = B['a'] + 3*B['c'] + sage: d = f.monomial_coefficients() + sage: d['a'] = 5 + sage: f B['a'] + 3*B['c'] """ @@ -1408,10 +1431,10 @@ def __getitem__(self, m): EXAMPLES:: - sage: W. = DifferentialWeylAlgebra(QQ) # optional - sage.combinat sage.modules - sage: x[((0,0,0), (0,0,0))] # optional - sage.combinat sage.modules + sage: W. = DifferentialWeylAlgebra(QQ) # needs sage.modules + sage: x[((0,0,0), (0,0,0))] # needs sage.modules 0 - sage: x[((1,0,0), (0,0,0))] # optional - sage.combinat sage.modules + sage: x[((1,0,0), (0,0,0))] # needs sage.modules 1 """ res = self.monomial_coefficients(copy=False).get(m) @@ -1437,19 +1460,20 @@ def coefficient(self, m): EXAMPLES:: - sage: s = CombinatorialFreeModule(QQ, Partitions()) # optional - sage.combinat sage.modules - sage: z = s([4]) - 2*s([2,1]) + s([1,1,1]) + s([1]) # optional - sage.combinat sage.modules - sage: z.coefficient([4]) # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: s = CombinatorialFreeModule(QQ, Partitions()) + sage: z = s([4]) - 2*s([2,1]) + s([1,1,1]) + s([1]) + sage: z.coefficient([4]) 1 - sage: z.coefficient([2,1]) # optional - sage.combinat sage.modules + sage: z.coefficient([2,1]) -2 - sage: z.coefficient(Partition([2,1])) # optional - sage.combinat sage.modules + sage: z.coefficient(Partition([2,1])) -2 - sage: z.coefficient([1,2]) # optional - sage.combinat sage.modules + sage: z.coefficient([1,2]) Traceback (most recent call last): ... AssertionError: [1, 2] should be an element of Partitions - sage: z.coefficient(Composition([2,1])) # optional - sage.combinat sage.modules + sage: z.coefficient(Composition([2,1])) Traceback (most recent call last): ... AssertionError: [2, 1] should be an element of Partitions @@ -1457,12 +1481,13 @@ def coefficient(self, m): Test that ``coefficient`` also works for those parents that do not have an ``element_class``:: - sage: H = pAdicWeightSpace(3) # optional - sage.modules sage.rings.padics - sage: F = CombinatorialFreeModule(QQ, H) # optional - sage.modules sage.rings.padics - sage: hasattr(H, "element_class") # optional - sage.modules sage.rings.padics + sage: # needs sage.modules sage.rings.padics + sage: H = pAdicWeightSpace(3) + sage: F = CombinatorialFreeModule(QQ, H) + sage: hasattr(H, "element_class") False - sage: h = H.an_element() # optional - sage.modules sage.rings.padics - sage: (2*F.monomial(h)).coefficient(h) # optional - sage.modules sage.rings.padics + sage: h = H.an_element() + sage: (2*F.monomial(h)).coefficient(h) 2 """ # NT: coefficient_fast should be the default, just with appropriate assertions @@ -1480,22 +1505,24 @@ def is_zero(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) # optional - sage.modules - sage: B = F.basis() # optional - sage.modules - sage: f = B['a'] - 3*B['c'] # optional - sage.modules - sage: f.is_zero() # optional - sage.modules + sage: # needs sage.modules + sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) + sage: B = F.basis() + sage: f = B['a'] - 3*B['c'] + sage: f.is_zero() False - sage: F.zero().is_zero() # optional - sage.modules + sage: F.zero().is_zero() True :: - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules - sage: s([2,1]).is_zero() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: s = SymmetricFunctions(QQ).schur() + sage: s([2,1]).is_zero() False - sage: s(0).is_zero() # optional - sage.combinat sage.modules + sage: s(0).is_zero() True - sage: (s([2,1]) - s([2,1])).is_zero() # optional - sage.combinat sage.modules + sage: (s([2,1]) - s([2,1])).is_zero() True """ zero = self.parent().base_ring().zero() @@ -1508,17 +1535,18 @@ def __len__(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) # optional - sage.modules - sage: B = F.basis() # optional - sage.modules - sage: f = B['a'] - 3*B['c'] # optional - sage.modules - sage: len(f) # optional - sage.modules + sage: # needs sage.modules + sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) + sage: B = F.basis() + sage: f = B['a'] - 3*B['c'] + sage: len(f) 2 :: - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules - sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) # optional - sage.combinat sage.modules - sage: len(z) # optional - sage.combinat sage.modules + sage: s = SymmetricFunctions(QQ).schur() # needs sage.combinat sage.modules + sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) # needs sage.combinat sage.modules + sage: len(z) # needs sage.combinat sage.modules 4 """ return len(self.support()) @@ -1530,17 +1558,18 @@ def length(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) # optional - sage.modules - sage: B = F.basis() # optional - sage.modules - sage: f = B['a'] - 3*B['c'] # optional - sage.modules - sage: f.length() # optional - sage.modules + sage: # needs sage.modules + sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) + sage: B = F.basis() + sage: f = B['a'] - 3*B['c'] + sage: f.length() 2 :: - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules - sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) # optional - sage.combinat sage.modules - sage: z.length() # optional - sage.combinat sage.modules + sage: s = SymmetricFunctions(QQ).schur() # needs sage.combinat sage.modules + sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) # needs sage.combinat sage.modules + sage: z.length() # needs sage.combinat sage.modules 4 """ return len(self) @@ -1555,17 +1584,18 @@ def support(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) # optional - sage.modules - sage: B = F.basis() # optional - sage.modules - sage: f = B['a'] - 3*B['c'] # optional - sage.modules - sage: sorted(f.support()) # optional - sage.modules + sage: # needs sage.modules + sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) + sage: B = F.basis() + sage: f = B['a'] - 3*B['c'] + sage: sorted(f.support()) ['a', 'c'] :: - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules - sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) # optional - sage.combinat sage.modules - sage: sorted(z.support()) # optional - sage.combinat sage.modules + sage: s = SymmetricFunctions(QQ).schur() # needs sage.combinat sage.modules + sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) # needs sage.combinat sage.modules + sage: sorted(z.support()) # needs sage.combinat sage.modules [[1], [1, 1, 1], [2, 1], [4]] """ try: @@ -1593,13 +1623,14 @@ def monomials(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) # optional - sage.modules - sage: B = F.basis() # optional - sage.modules - sage: f = B['a'] + 2*B['c'] # optional - sage.modules - sage: f.monomials() # optional - sage.modules + sage: # needs sage.modules + sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) + sage: B = F.basis() + sage: f = B['a'] + 2*B['c'] + sage: f.monomials() [B['a'], B['c']] - sage: (F.zero()).monomials() # optional - sage.modules + sage: (F.zero()).monomials() # needs sage.modules [] """ P = self.parent() @@ -1614,10 +1645,11 @@ def terms(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) # optional - sage.modules - sage: B = F.basis() # optional - sage.modules - sage: f = B['a'] + 2*B['c'] # optional - sage.modules - sage: f.terms() # optional - sage.modules + sage: # needs sage.modules + sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) + sage: B = F.basis() + sage: f = B['a'] + 2*B['c'] + sage: f.terms() [B['a'], 2*B['c']] """ P = self.parent() @@ -1642,20 +1674,21 @@ def coefficients(self, sort=True): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) # optional - sage.modules - sage: B = F.basis() # optional - sage.modules - sage: f = B['a'] - 3*B['c'] # optional - sage.modules - sage: f.coefficients() # optional - sage.modules + sage: # needs sage.modules + sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) + sage: B = F.basis() + sage: f = B['a'] - 3*B['c'] + sage: f.coefficients() [1, -3] - sage: f = B['c'] - 3*B['a'] # optional - sage.modules - sage: f.coefficients() # optional - sage.modules + sage: f = B['c'] - 3*B['a'] + sage: f.coefficients() [-3, 1] :: - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules - sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) # optional - sage.combinat sage.modules - sage: z.coefficients() # optional - sage.combinat sage.modules + sage: s = SymmetricFunctions(QQ).schur() # needs sage.combinat sage.modules + sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) # needs sage.combinat sage.modules + sage: z.coefficients() # needs sage.combinat sage.modules [1, 1, 1, 1] """ zero = self.parent().base_ring().zero() @@ -1674,15 +1707,15 @@ def support_of_term(self): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1,2,3,4]); X.rename("X") # optional - sage.modules - sage: X.monomial(2).support_of_term() # optional - sage.modules + sage: X = CombinatorialFreeModule(QQ, [1,2,3,4]); X.rename("X") # needs sage.modules + sage: X.monomial(2).support_of_term() # needs sage.modules 2 - sage: X.term(3, 2).support_of_term() # optional - sage.modules + sage: X.term(3, 2).support_of_term() # needs sage.modules 3 An exception is raised if ``self`` has more than one term:: - sage: (X.monomial(2) + X.monomial(3)).support_of_term() # optional - sage.modules + sage: (X.monomial(2) + X.monomial(3)).support_of_term() # needs sage.modules Traceback (most recent call last): ... ValueError: B[2] + B[3] is not a single term @@ -1704,18 +1737,19 @@ def leading_support(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]) # optional - sage.modules - sage: X.rename("X"); x = X.basis() # optional - sage.modules - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + 4*X.monomial(3) # optional - sage.modules - sage: x.leading_support() # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]) + sage: X.rename("X"); x = X.basis() + sage: x = 3*X.monomial(1) + 2*X.monomial(2) + 4*X.monomial(3) + sage: x.leading_support() 3 - sage: def key(x): return -x # optional - sage.modules - sage: x.leading_support(key=key) # optional - sage.modules + sage: def key(x): return -x + sage: x.leading_support(key=key) 1 - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # optional - sage.combinat sage.modules - sage: f.leading_support() # optional - sage.combinat sage.modules + sage: s = SymmetricFunctions(QQ).schur() # needs sage.combinat sage.modules + sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # needs sage.combinat sage.modules + sage: f.leading_support() # needs sage.combinat sage.modules [3] """ return max(self.support(), *args, **kwds) @@ -1739,17 +1773,18 @@ def leading_item(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") # optional - sage.modules - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + 4*X.monomial(3) # optional - sage.modules - sage: x.leading_item() # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") + sage: x = 3*X.monomial(1) + 2*X.monomial(2) + 4*X.monomial(3) + sage: x.leading_item() (3, 4) - sage: def key(x): return -x # optional - sage.modules - sage: x.leading_item(key=key) # optional - sage.modules + sage: def key(x): return -x + sage: x.leading_item(key=key) (1, 3) - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # optional - sage.combinat sage.modules - sage: f.leading_item() # optional - sage.combinat sage.modules + sage: s = SymmetricFunctions(QQ).schur() # needs sage.combinat sage.modules + sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # needs sage.combinat sage.modules + sage: f.leading_item() # needs sage.combinat sage.modules ([3], -5) """ k = self.leading_support(*args, **kwds) @@ -1768,17 +1803,18 @@ def leading_monomial(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") # optional - sage.modules - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) # optional - sage.modules - sage: x.leading_monomial() # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") + sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) + sage: x.leading_monomial() B[3] - sage: def key(x): return -x # optional - sage.modules - sage: x.leading_monomial(key=key) # optional - sage.modules + sage: def key(x): return -x + sage: x.leading_monomial(key=key) B[1] - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # optional - sage.combinat sage.modules - sage: f.leading_monomial() # optional - sage.combinat sage.modules + sage: s = SymmetricFunctions(QQ).schur() # needs sage.combinat sage.modules + sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # needs sage.combinat sage.modules + sage: f.leading_monomial() # needs sage.combinat sage.modules s[3] """ return self.parent().monomial(self.leading_support(*args, **kwds)) @@ -1796,17 +1832,18 @@ def leading_coefficient(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") # optional - sage.modules - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) # optional - sage.modules - sage: x.leading_coefficient() # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") + sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) + sage: x.leading_coefficient() 1 - sage: def key(x): return -x # optional - sage.modules - sage: x.leading_coefficient(key=key) # optional - sage.modules + sage: def key(x): return -x + sage: x.leading_coefficient(key=key) 3 - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # optional - sage.combinat sage.modules - sage: f.leading_coefficient() # optional - sage.combinat sage.modules + sage: s = SymmetricFunctions(QQ).schur() # needs sage.combinat sage.modules + sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # needs sage.combinat sage.modules + sage: f.leading_coefficient() # needs sage.combinat sage.modules -5 """ return self.leading_item(*args, **kwds)[1] @@ -1824,17 +1861,18 @@ def leading_term(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") # optional - sage.modules - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) # optional - sage.modules - sage: x.leading_term() # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") + sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) + sage: x.leading_term() B[3] - sage: def key(x): return -x # optional - sage.modules - sage: x.leading_term(key=key) # optional - sage.modules + sage: def key(x): return -x + sage: x.leading_term(key=key) 3*B[1] - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # optional - sage.combinat sage.modules - sage: f.leading_term() # optional - sage.combinat sage.modules + sage: s = SymmetricFunctions(QQ).schur() # needs sage.combinat sage.modules + sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # needs sage.combinat sage.modules + sage: f.leading_term() # needs sage.combinat sage.modules -5*s[3] """ return self.parent().term(*self.leading_item(*args, **kwds)) @@ -1850,18 +1888,18 @@ def trailing_support(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") # optional - sage.modules - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + 4*X.monomial(3) # optional - sage.modules - sage: x.trailing_support() # optional - sage.modules + sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") # needs sage.modules + sage: x = 3*X.monomial(1) + 2*X.monomial(2) + 4*X.monomial(3) # needs sage.modules + sage: x.trailing_support() # needs sage.modules 1 - sage: def key(x): return -x # optional - sage.modules - sage: x.trailing_support(key=key) # optional - sage.modules + sage: def key(x): return -x + sage: x.trailing_support(key=key) # needs sage.modules 3 - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # optional - sage.combinat sage.modules - sage: f.trailing_support() # optional - sage.combinat sage.modules + sage: s = SymmetricFunctions(QQ).schur() # needs sage.combinat sage.modules + sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # needs sage.combinat sage.modules + sage: f.trailing_support() # needs sage.combinat sage.modules [1] """ return min(self.support(), *args, **kwds) @@ -1880,17 +1918,18 @@ def trailing_item(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") # optional - sage.modules - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) # optional - sage.modules - sage: x.trailing_item() # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") + sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) + sage: x.trailing_item() (1, 3) - sage: def key(x): return -x # optional - sage.modules - sage: x.trailing_item(key=key) # optional - sage.modules + sage: def key(x): return -x + sage: x.trailing_item(key=key) (3, 1) - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # optional - sage.combinat sage.modules - sage: f.trailing_item() # optional - sage.combinat sage.modules + sage: s = SymmetricFunctions(QQ).schur() # needs sage.combinat sage.modules + sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # needs sage.combinat sage.modules + sage: f.trailing_item() # needs sage.combinat sage.modules ([1], 2) """ k = self.trailing_support(*args, **kwds) @@ -1909,17 +1948,18 @@ def trailing_monomial(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") # optional - sage.modules - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) # optional - sage.modules - sage: x.trailing_monomial() # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") + sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) + sage: x.trailing_monomial() B[1] - sage: def key(x): return -x # optional - sage.modules - sage: x.trailing_monomial(key=key) # optional - sage.modules + sage: def key(x): return -x + sage: x.trailing_monomial(key=key) B[3] - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # optional - sage.combinat sage.modules - sage: f.trailing_monomial() # optional - sage.combinat sage.modules + sage: s = SymmetricFunctions(QQ).schur() # needs sage.combinat sage.modules + sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # needs sage.combinat sage.modules + sage: f.trailing_monomial() # needs sage.combinat sage.modules s[1] """ return self.parent().monomial(self.trailing_support(*args, **kwds)) @@ -1937,17 +1977,18 @@ def trailing_coefficient(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") # optional - sage.modules - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) # optional - sage.modules - sage: x.trailing_coefficient() # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") + sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) + sage: x.trailing_coefficient() 3 - sage: def key(x): return -x # optional - sage.modules - sage: x.trailing_coefficient(key=key) # optional - sage.modules + sage: def key(x): return -x + sage: x.trailing_coefficient(key=key) 1 - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # optional - sage.combinat sage.modules - sage: f.trailing_coefficient() # optional - sage.combinat sage.modules + sage: s = SymmetricFunctions(QQ).schur() # needs sage.combinat sage.modules + sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # needs sage.combinat sage.modules + sage: f.trailing_coefficient() # needs sage.combinat sage.modules 2 """ return self.trailing_item(*args, **kwds)[1] @@ -1965,17 +2006,18 @@ def trailing_term(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") # optional - sage.modules - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) # optional - sage.modules - sage: x.trailing_term() # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") + sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) + sage: x.trailing_term() 3*B[1] - sage: def key(x): return -x # optional - sage.modules - sage: x.trailing_term(key=key) # optional - sage.modules + sage: def key(x): return -x + sage: x.trailing_term(key=key) B[3] - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # optional - sage.combinat sage.modules - sage: f.trailing_term() # optional - sage.combinat sage.modules + sage: s = SymmetricFunctions(QQ).schur() # needs sage.combinat sage.modules + sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # needs sage.combinat sage.modules + sage: f.trailing_term() # needs sage.combinat sage.modules 2*s[1] """ return self.parent().term(*self.trailing_item(*args, **kwds)) @@ -1994,24 +2036,25 @@ def map_coefficients(self, f): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) # optional - sage.modules - sage: B = F.basis() # optional - sage.modules - sage: f = B['a'] - 3*B['c'] # optional - sage.modules - sage: f.map_coefficients(lambda x: x + 5) # optional - sage.modules + sage: # needs sage.modules + sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) + sage: B = F.basis() + sage: f = B['a'] - 3*B['c'] + sage: f.map_coefficients(lambda x: x + 5) 6*B['a'] + 2*B['c'] Killed coefficients are handled properly:: - sage: f.map_coefficients(lambda x: 0) # optional - sage.modules + sage: f.map_coefficients(lambda x: 0) # needs sage.modules 0 - sage: list(f.map_coefficients(lambda x: 0)) # optional - sage.modules + sage: list(f.map_coefficients(lambda x: 0)) # needs sage.modules [] :: - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules - sage: a = s([2,1]) + 2*s([3,2]) # optional - sage.combinat sage.modules - sage: a.map_coefficients(lambda x: x * 2) # optional - sage.combinat sage.modules + sage: s = SymmetricFunctions(QQ).schur() # needs sage.combinat sage.modules + sage: a = s([2,1]) + 2*s([3,2]) # needs sage.combinat sage.modules + sage: a.map_coefficients(lambda x: x * 2) # needs sage.combinat sage.modules 2*s[2, 1] + 4*s[3, 2] """ return self.parent().sum_of_terms( (m, f(c)) for m,c in self ) @@ -2030,30 +2073,30 @@ def map_support(self, f): EXAMPLES:: - sage: B = CombinatorialFreeModule(ZZ, [-1, 0, 1]) # optional - sage.modules - sage: x = B.an_element(); x # optional - sage.modules + sage: B = CombinatorialFreeModule(ZZ, [-1, 0, 1]) # needs sage.modules + sage: x = B.an_element(); x # needs sage.modules 2*B[-1] + 2*B[0] + 3*B[1] - sage: x.map_support(lambda i: -i) # optional - sage.modules + sage: x.map_support(lambda i: -i) # needs sage.modules 3*B[-1] + 2*B[0] + 2*B[1] ``f`` needs not be injective:: - sage: x.map_support(lambda i: 1) # optional - sage.modules + sage: x.map_support(lambda i: 1) # needs sage.modules 7*B[1] - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules - sage: a = s([2,1]) + 2*s([3,2]) # optional - sage.combinat sage.modules - sage: a.map_support(lambda x: x.conjugate()) # optional - sage.combinat sage.modules + sage: s = SymmetricFunctions(QQ).schur() # needs sage.combinat sage.modules + sage: a = s([2,1]) + 2*s([3,2]) # needs sage.combinat sage.modules + sage: a.map_support(lambda x: x.conjugate()) # needs sage.combinat sage.modules s[2, 1] + 2*s[2, 2, 1] TESTS:: - sage: B.zero() # This actually failed at some point!!! See #8890 # optional - sage.modules + sage: B.zero() # This actually failed at some point!!! See #8890 # needs sage.modules 0 - sage: y = B.zero().map_support(lambda i: i/0); y # optional - sage.modules + sage: y = B.zero().map_support(lambda i: i/0); y # needs sage.modules 0 - sage: y.parent() is B # optional - sage.modules + sage: y.parent() is B # needs sage.modules True """ return self.parent().sum_of_terms( (f(m), c) for m,c in self ) @@ -2072,22 +2115,22 @@ def map_support_skip_none(self, f): EXAMPLES:: - sage: B = CombinatorialFreeModule(ZZ, [-1, 0, 1]) # optional - sage.modules - sage: x = B.an_element(); x # optional - sage.modules + sage: B = CombinatorialFreeModule(ZZ, [-1, 0, 1]) # needs sage.modules + sage: x = B.an_element(); x # needs sage.modules 2*B[-1] + 2*B[0] + 3*B[1] - sage: x.map_support_skip_none(lambda i: -i if i else None) # optional - sage.modules + sage: x.map_support_skip_none(lambda i: -i if i else None) # needs sage.modules 3*B[-1] + 2*B[1] ``f`` needs not be injective:: - sage: x.map_support_skip_none(lambda i: 1 if i else None) # optional - sage.modules + sage: x.map_support_skip_none(lambda i: 1 if i else None) # needs sage.modules 5*B[1] TESTS:: - sage: y = x.map_support_skip_none(lambda i: None); y # optional - sage.modules + sage: y = x.map_support_skip_none(lambda i: None); y # needs sage.modules 0 - sage: y.parent() is B # optional - sage.modules + sage: y.parent() is B # needs sage.modules True """ return self.parent().sum_of_terms( (fm,c) for (fm,c) in ((f(m), c) for m,c in self) if fm is not None) @@ -2107,21 +2150,21 @@ def map_item(self, f): EXAMPLES:: - sage: B = CombinatorialFreeModule(ZZ, [-1, 0, 1]) # optional - sage.modules - sage: x = B.an_element(); x # optional - sage.modules + sage: B = CombinatorialFreeModule(ZZ, [-1, 0, 1]) # needs sage.modules + sage: x = B.an_element(); x # needs sage.modules 2*B[-1] + 2*B[0] + 3*B[1] - sage: x.map_item(lambda i, c: (-i, 2*c)) # optional - sage.modules + sage: x.map_item(lambda i, c: (-i, 2*c)) # needs sage.modules 6*B[-1] + 4*B[0] + 4*B[1] ``f`` needs not be injective:: - sage: x.map_item(lambda i, c: (1, 2*c)) # optional - sage.modules + sage: x.map_item(lambda i, c: (1, 2*c)) # needs sage.modules 14*B[1] - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules - sage: f = lambda m, c: (m.conjugate(), 2 * c) # optional - sage.combinat sage.modules - sage: a = s([2,1]) + s([1,1,1]) # optional - sage.combinat sage.modules - sage: a.map_item(f) # optional - sage.combinat sage.modules + sage: s = SymmetricFunctions(QQ).schur() # needs sage.combinat sage.modules + sage: f = lambda m, c: (m.conjugate(), 2 * c) + sage: a = s([2,1]) + s([1,1,1]) # needs sage.combinat sage.modules + sage: a.map_item(f) # needs sage.combinat sage.modules 2*s[2, 1] + 2*s[3] """ return self.parent().sum_of_terms( f(m,c) for m,c in self ) @@ -2134,9 +2177,9 @@ def tensor(*elements): EXAMPLES:: sage: C = AlgebrasWithBasis(QQ) - sage: A = C.example() # optional - sage.combinat sage.modules - sage: a, b, c = A.algebra_generators() # optional - sage.combinat sage.modules - sage: a.tensor(b, c) # optional - sage.combinat sage.modules + sage: A = C.example() # needs sage.combinat sage.modules + sage: a, b, c = A.algebra_generators() # needs sage.combinat sage.modules + sage: a.tensor(b, c) # needs sage.combinat sage.modules B[word: a] # B[word: b] # B[word: c] FIXME: is this a policy that we want to enforce on all parents? @@ -2166,50 +2209,51 @@ def __call_on_basis__(self, **options): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1,2,3]); X.rename("X") # optional - sage.modules - sage: Y = CombinatorialFreeModule(QQ, [1,2,3,4]); Y.rename("Y") # optional - sage.modules - sage: H = Hom(X, Y) # optional - sage.modules - sage: x = X.basis() # optional - sage.modules - + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(QQ, [1,2,3]); X.rename("X") + sage: Y = CombinatorialFreeModule(QQ, [1,2,3,4]); Y.rename("Y") + sage: H = Hom(X, Y) + sage: x = X.basis() sage: def on_basis(i): ....: return Y.monomial(i) + 2*Y.monomial(i + 1) - sage: phi = H(on_basis=on_basis) # indirect doctest # optional - sage.modules - sage: phi # optional - sage.modules + sage: phi = H(on_basis=on_basis) # indirect doctest + sage: phi Generic morphism: - From: X - To: Y - sage: phi(x[1] + x[3]) # optional - sage.modules + From: X + To: Y + sage: phi(x[1] + x[3]) B[1] + 2*B[2] + B[3] + 2*B[4] Diagonal functions can be constructed using the ``diagonal`` option:: - sage: X = CombinatorialFreeModule(QQ, [1,2,3,4]); X.rename("X") # optional - sage.modules - sage: Y = CombinatorialFreeModule(QQ, [1,2,3,4], # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(QQ, [1,2,3,4]); X.rename("X") + sage: Y = CombinatorialFreeModule(QQ, [1,2,3,4], ....: key="Y"); Y.rename("Y") - sage: H = Hom(X, Y) # optional - sage.modules - sage: x = X.basis() # optional - sage.modules - sage: phi = H(diagonal=lambda x: x^2) # optional - sage.modules - sage: phi(x[1] + x[2] + x[3]) # optional - sage.modules + sage: H = Hom(X, Y) + sage: x = X.basis() + sage: phi = H(diagonal=lambda x: x^2) + sage: phi(x[1] + x[2] + x[3]) B[1] + 4*B[2] + 9*B[3] TESTS: As for usual homsets, the argument can be a Python function:: - sage: phi = H(lambda x: Y.zero()) # optional - sage.modules - sage: phi # optional - sage.modules + sage: phi = H(lambda x: Y.zero()); phi # needs sage.modules Generic morphism: From: X To: Y - sage: phi(x[1] + x[3]) # optional - sage.modules + sage: phi(x[1] + x[3]) # needs sage.modules 0 We check that the homset category is properly set up:: - sage: X = CombinatorialFreeModule(QQ, [1,2,3]); X.rename("X") # optional - sage.modules - sage: Y = CombinatorialFreeModule(QQ, [1,2,3,4]); Y.rename("Y") # optional - sage.modules - sage: H = Hom(X, Y) # optional - sage.modules - sage: H.zero().category_for() # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(QQ, [1,2,3]); X.rename("X") + sage: Y = CombinatorialFreeModule(QQ, [1,2,3,4]); Y.rename("Y") + sage: H = Hom(X, Y) + sage: H.zero().category_for() Category of finite dimensional vector spaces with basis over Rational Field """ return self.domain().module_morphism(codomain=self.codomain(), @@ -2228,20 +2272,19 @@ def on_basis(self): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1,2,3]); X.rename("X") # optional - sage.modules - sage: Y = CombinatorialFreeModule(QQ, [1,2,3,4]); Y.rename("Y") # optional - sage.modules - sage: H = Hom(X, Y) # optional - sage.modules - sage: x = X.basis() # optional - sage.modules - - sage: f = H(lambda x: Y.zero()).on_basis() # optional - sage.modules - sage: f(2) # optional - sage.modules + sage: # needs sage.modules + sage: X = CombinatorialFreeModule(QQ, [1,2,3]); X.rename("X") + sage: Y = CombinatorialFreeModule(QQ, [1,2,3,4]); Y.rename("Y") + sage: H = Hom(X, Y) + sage: x = X.basis() + sage: f = H(lambda x: Y.zero()).on_basis() + sage: f(2) 0 - - sage: f = lambda i: Y.monomial(i) + 2*Y.monomial(i+1) # optional - sage.modules - sage: g = H(on_basis=f).on_basis() # optional - sage.modules - sage: g(2) # optional - sage.modules + sage: f = lambda i: Y.monomial(i) + 2*Y.monomial(i+1) + sage: g = H(on_basis=f).on_basis() + sage: g(2) B[2] + 2*B[3] - sage: g == f # optional - sage.modules + sage: g == f True """ return self._on_basis @@ -2256,9 +2299,9 @@ def _on_basis(self, i): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1,2,3]); X.rename("X") # optional - sage.modules - sage: phi = End(X)(lambda x: 2*x) # optional - sage.modules - sage: phi._on_basis(3) # optional - sage.modules + sage: X = CombinatorialFreeModule(QQ, [1,2,3]); X.rename("X") # needs sage.modules + sage: phi = End(X)(lambda x: 2*x) # needs sage.modules + sage: phi._on_basis(3) # needs sage.modules 2*B[3] """ return self(self.domain().monomial(i)) @@ -2288,20 +2331,21 @@ def _an_element_(self): """ EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example(); A # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.groups sage.modules + sage: A = AlgebrasWithBasis(QQ).example(); A An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: B = HopfAlgebrasWithBasis(QQ).example(); B # optional - sage.combinat sage.modules + sage: B = HopfAlgebrasWithBasis(QQ).example(); B An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Rational Field - sage: A.an_element() # optional - sage.combinat sage.modules + sage: A.an_element() B[word: ] + 2*B[word: a] + 3*B[word: b] + B[word: bab] - sage: B.an_element() # optional - sage.combinat sage.modules + sage: B.an_element() B[()] + B[(1,2)] + 3*B[(1,2,3)] + 2*B[(1,3,2)] - sage: ABA = cartesian_product((A, B, A)) # optional - sage.combinat sage.modules - sage: ABA.an_element() # indirect doctest # optional - sage.combinat sage.modules + sage: ABA = cartesian_product((A, B, A)) + sage: ABA.an_element() # indirect doctest 2*B[(0, word: )] + 2*B[(0, word: a)] + 3*B[(0, word: b)] """ from .cartesian_product import cartesian_product @@ -2364,10 +2408,11 @@ def apply_multilinear_morphism(self, f, codomain=None): We start with simple (admittedly not so interesting) examples, with two modules `A` and `B`:: - sage: A = CombinatorialFreeModule(ZZ, [1,2], prefix="A") # optional - sage.modules - sage: A.rename("A") # optional - sage.modules - sage: B = CombinatorialFreeModule(ZZ, [3,4], prefix="B") # optional - sage.modules - sage: B.rename("B") # optional - sage.modules + sage: # needs sage.modules + sage: A = CombinatorialFreeModule(ZZ, [1,2], prefix="A") + sage: A.rename("A") + sage: B = CombinatorialFreeModule(ZZ, [3,4], prefix="B") + sage: B.rename("B") and `f` the bilinear morphism `(a,b) \mapsto b \otimes a` from `A \times B` to `B \otimes A`:: @@ -2378,13 +2423,14 @@ def apply_multilinear_morphism(self, f, codomain=None): Now, calling applying `f` on `a \otimes b` returns the same as `f(a,b)`:: - sage: a = A.monomial(1) + 2 * A.monomial(2); a # optional - sage.modules + sage: # needs sage.modules + sage: a = A.monomial(1) + 2 * A.monomial(2); a A[1] + 2*A[2] - sage: b = B.monomial(3) - 2 * B.monomial(4); b # optional - sage.modules + sage: b = B.monomial(3) - 2 * B.monomial(4); b B[3] - 2*B[4] - sage: f(a, b) # optional - sage.modules + sage: f(a, b) B[3] # A[1] + 2*B[3] # A[2] - 2*B[4] # A[1] - 4*B[4] # A[2] - sage: tensor([a, b]).apply_multilinear_morphism(f) # optional - sage.modules + sage: tensor([a, b]).apply_multilinear_morphism(f) B[3] # A[1] + 2*B[3] # A[2] - 2*B[4] # A[1] - 4*B[4] # A[2] `f` may be a bilinear morphism to any module over the @@ -2392,9 +2438,9 @@ def apply_multilinear_morphism(self, f, codomain=None): sage: def f(a, b): ....: return sum(a.coefficients(), 0) * sum(b.coefficients(), 0) - sage: f(a, b) # optional - sage.modules + sage: f(a, b) # needs sage.modules -3 - sage: tensor([a, b]).apply_multilinear_morphism(f) # optional - sage.modules + sage: tensor([a, b]).apply_multilinear_morphism(f) # needs sage.modules -3 Mind the `0` in the sums above; otherwise `f` would @@ -2402,12 +2448,12 @@ def apply_multilinear_morphism(self, f, codomain=None): sage: def f(a,b): ....: return sum(a.coefficients()) * sum(b.coefficients()) - sage: type(f(A.zero(), B.zero())) # optional - sage.modules + sage: type(f(A.zero(), B.zero())) # needs sage.modules <... 'int'> Which would be wrong and break this method:: - sage: tensor([a, b]).apply_multilinear_morphism(f) # optional - sage.modules + sage: tensor([a, b]).apply_multilinear_morphism(f) # needs sage.modules Traceback (most recent call last): ... AttributeError: 'int' object has no attribute 'parent' @@ -2415,14 +2461,15 @@ def apply_multilinear_morphism(self, f, codomain=None): Here we consider an example where the codomain is a module with basis with a different base ring:: - sage: C = CombinatorialFreeModule(QQ, [(1,3),(2,4)], prefix="C") # optional - sage.modules - sage: C.rename("C") # optional - sage.modules + sage: # needs sage.modules + sage: C = CombinatorialFreeModule(QQ, [(1,3),(2,4)], prefix="C") + sage: C.rename("C") sage: def f(a, b): ....: return C.sum_of_terms([((1,3), QQ(a[1]*b[3])), ....: ((2,4), QQ(a[2]*b[4]))]) - sage: f(a,b) # optional - sage.modules + sage: f(a,b) C[(1, 3)] - 4*C[(2, 4)] - sage: tensor([a, b]).apply_multilinear_morphism(f) # optional - sage.modules + sage: tensor([a, b]).apply_multilinear_morphism(f) C[(1, 3)] - 4*C[(2, 4)] We conclude with a real life application, where we @@ -2430,14 +2477,15 @@ def apply_multilinear_morphism(self, f, codomain=None): Symmetric functions on the Schur basis satisfies its defining formula:: - sage: Sym = SymmetricFunctions(QQ) # optional - sage.combinat sage.modules - sage: s = Sym.schur() # optional - sage.combinat sage.modules - sage: def f(a, b): return a * b.antipode() # optional - sage.combinat sage.modules - sage: x = 4 * s.an_element(); x # optional - sage.combinat sage.modules + sage: # needs lrcalc_python sage.combinat sage.modules + sage: Sym = SymmetricFunctions(QQ) + sage: s = Sym.schur() + sage: def f(a, b): return a * b.antipode() + sage: x = 4 * s.an_element(); x 8*s[] + 8*s[1] + 12*s[2] - sage: x.coproduct().apply_multilinear_morphism(f) # optional - sage.combinat sage.modules + sage: x.coproduct().apply_multilinear_morphism(f) 8*s[] - sage: x.coproduct().apply_multilinear_morphism(f) == x.counit() # optional - sage.combinat sage.modules + sage: x.coproduct().apply_multilinear_morphism(f) == x.counit() True We recover the constant term of `x`, as desired. diff --git a/src/sage/categories/monoids.py b/src/sage/categories/monoids.py index ecf591c7559..994a34cc233 100644 --- a/src/sage/categories/monoids.py +++ b/src/sage/categories/monoids.py @@ -69,7 +69,7 @@ class Monoids(CategoryWithAxiom): Check for :trac:`31212`:: sage: R = IntegerModRing(15) - sage: R.submonoid([R.one()]).list() # optional - sage.groups + sage: R.submonoid([R.one()]).list() # needs sage.combinat [1] """ _base_category_class_and_axiom = (Semigroups, "Unital") @@ -98,11 +98,11 @@ def free(index_set=None, names=None, **kwds): EXAMPLES:: - sage: Monoids.free(index_set=ZZ) # optional - sage.groups + sage: Monoids.free(index_set=ZZ) # needs sage.combinat Free monoid indexed by Integer Ring - sage: Monoids().free(ZZ) # optional - sage.groups + sage: Monoids().free(ZZ) # needs sage.combinat Free monoid indexed by Integer Ring - sage: F. = Monoids().free(); F # optional - sage.groups + sage: F. = Monoids().free(); F # needs sage.combinat Free monoid indexed by {'x', 'y', 'z'} """ if names is not None: @@ -130,8 +130,8 @@ def semigroup_generators(self): EXAMPLES:: - sage: M = Monoids().free([1,2,3]) # optional - sage.groups - sage: M.semigroup_generators() # optional - sage.groups + sage: M = Monoids().free([1,2,3]) # needs sage.combinat + sage: M.semigroup_generators() # needs sage.combinat Family (1, F[1], F[2], F[3]) """ G = self.monoid_generators() @@ -212,22 +212,22 @@ def submonoid(self, generators, category=None): EXAMPLES:: sage: R = IntegerModRing(15) - sage: M = R.submonoid([R(3), R(5)]); M # optional - sage.groups + sage: M = R.submonoid([R(3), R(5)]); M # needs sage.combinat A submonoid of (Ring of integers modulo 15) with 2 generators - sage: M.list() # optional - sage.groups + sage: M.list() # needs sage.combinat [1, 3, 5, 9, 0, 10, 12, 6] Not the presence of the unit, unlike in:: - sage: S = R.subsemigroup([R(3), R(5)]); S # optional - sage.groups + sage: S = R.subsemigroup([R(3), R(5)]); S # needs sage.combinat A subsemigroup of (Ring of integers modulo 15) with 2 generators - sage: S.list() # optional - sage.groups + sage: S.list() # needs sage.combinat [3, 5, 9, 0, 10, 12, 6] This method is really a shorthand for subsemigroup:: - sage: M2 = R.subsemigroup([R(3), R(5)], one=R.one()) # optional - sage.groups - sage: M2 is M # optional - sage.groups + sage: M2 = R.subsemigroup([R(3), R(5)], one=R.one()) # needs sage.combinat + sage: M2 is M # needs sage.combinat True """ return self.subsemigroup(generators, one=self.one()) @@ -245,11 +245,12 @@ def _div_(left, right): EXAMPLES:: - sage: G = FreeGroup(2) # optional - sage.groups - sage: x0, x1 = G.group_generators() # optional - sage.groups - sage: c1 = cartesian_product([x0, x1]) # optional - sage.groups - sage: c2 = cartesian_product([x1, x0]) # optional - sage.groups - sage: c1._div_(c2) # optional - sage.groups + sage: # needs sage.groups + sage: G = FreeGroup(2) + sage: x0, x1 = G.group_generators() + sage: c1 = cartesian_product([x0, x1]) + sage: c2 = cartesian_product([x1, x0]) + sage: c1._div_(c2) (x0*x1^-1, x1*x0^-1) With this default implementation, division will fail as @@ -267,7 +268,7 @@ def _div_(left, right): TESTS:: - sage: c1._div_.__module__ # optional - sage.groups + sage: c1._div_.__module__ # needs sage.groups 'sage.categories.monoids' """ return left * ~right @@ -336,8 +337,8 @@ def powers(self, n): EXAMPLES:: - sage: A = Matrix([[1, 1], [-1, 0]]) # optional - sage.modules - sage: A.powers(6) # optional - sage.modules + sage: A = Matrix([[1, 1], [-1, 0]]) # needs sage.modules + sage: A.powers(6) # needs sage.modules [ [1 0] [ 1 1] [ 0 1] [-1 0] [-1 -1] [ 0 -1] [0 1], [-1 0], [-1 -1], [ 0 -1], [ 1 0], [ 1 1] @@ -363,8 +364,8 @@ def __invert__(self): EXAMPLES:: - sage: A = Matrix([[1, 0], [1, 1]]) # optional - sage.modules - sage: ~A # optional - sage.modules + sage: A = Matrix([[1, 0], [1, 1]]) # needs sage.modules + sage: ~A # needs sage.modules [ 1 0] [-1 1] """ @@ -379,7 +380,7 @@ def inverse(self): EXAMPLES:: - sage: AA(sqrt(~2)).inverse() # optional - sage.symbolic sage.rings.number_field + sage: AA(sqrt(~2)).inverse() # needs sage.rings.number_field sage.symbolic 1.414213562373095? """ # Nota Bene: Element classes should implement ``__invert__`` only. @@ -412,11 +413,11 @@ def free(index_set=None, names=None, **kwds): EXAMPLES:: - sage: Monoids.Commutative.free(index_set=ZZ) # optional - sage.groups + sage: Monoids.Commutative.free(index_set=ZZ) # needs sage.combinat Free abelian monoid indexed by Integer Ring - sage: Monoids().Commutative().free(ZZ) # optional - sage.groups + sage: Monoids().Commutative().free(ZZ) # needs sage.combinat Free abelian monoid indexed by Integer Ring - sage: F. = Monoids().Commutative().free(); F # optional - sage.groups + sage: F. = Monoids().Commutative().free(); F # needs sage.combinat Free abelian monoid indexed by {'x', 'y', 'z'} """ if names is not None: @@ -447,18 +448,18 @@ def one(self): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules + sage: A = Sets().WithRealizations().example(); A # needs sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: A.one.__module__ # optional - sage.combinat sage.modules + sage: A.one.__module__ # needs sage.modules 'sage.categories.monoids' - sage: A.one() # optional - sage.combinat sage.modules + sage: A.one() # needs sage.modules F[{}] TESTS:: - sage: A.one() is A.a_realization().one() # optional - sage.combinat sage.modules + sage: A.one() is A.a_realization().one() # needs sage.modules True - sage: A._test_one() # optional - sage.combinat sage.modules + sage: A._test_one() # needs sage.modules """ return self.a_realization().one() @@ -510,12 +511,13 @@ def one_basis(self): EXAMPLES:: - sage: A = Monoids().example().algebra(ZZ) # optional - sage.modules - sage: A.one_basis() # optional - sage.modules + sage: # needs sage.modules + sage: A = Monoids().example().algebra(ZZ) + sage: A.one_basis() '' - sage: A.one() # optional - sage.modules + sage: A.one() B[''] - sage: A(3) # optional - sage.modules + sage: A(3) 3*B[''] """ return self.basis().keys().one() @@ -542,7 +544,7 @@ def algebra_generators(self): the free monoid generated by ('a', 'b', 'c', 'd') sage: M.monoid_generators() Finite family {'a': 'a', 'b': 'b', 'c': 'c', 'd': 'd'} - sage: M.algebra(ZZ).algebra_generators() # optional - sage.modules + sage: M.algebra(ZZ).algebra_generators() # needs sage.modules Finite family {'a': B['a'], 'b': B['b'], 'c': B['c'], 'd': B['d']} sage: Z12 = Monoids().Finite().example(); Z12 @@ -555,18 +557,18 @@ def algebra_generators(self): has no attribute 'monoid_generators' sage: Z12.semigroup_generators() Family (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) - sage: Z12.algebra(QQ).algebra_generators() # optional - sage.modules + sage: Z12.algebra(QQ).algebra_generators() # needs sage.modules Family (B[0], B[1], B[2], B[3], B[4], B[5], B[6], B[7], B[8], B[9], B[10], B[11]) - sage: A10 = AlternatingGroup(10) # optional - sage.groups - sage: GroupAlgebras(QQ).example(A10).algebra_generators() # optional - sage.groups sage.modules + sage: A10 = AlternatingGroup(10) # needs sage.groups + sage: GroupAlgebras(QQ).example(A10).algebra_generators() # needs sage.groups sage.modules Family ((8,9,10), (1,2,3,4,5,6,7,8,9)) - sage: A = DihedralGroup(3).algebra(QQ); A # optional - sage.groups sage.modules + sage: A = DihedralGroup(3).algebra(QQ); A # needs sage.groups sage.modules Algebra of Dihedral group of order 6 as a permutation group over Rational Field - sage: A.algebra_generators() # optional - sage.groups sage.modules + sage: A.algebra_generators() # needs sage.groups sage.modules Family ((1,2,3), (1,3)) """ monoid = self.basis().keys() @@ -584,16 +586,16 @@ def is_central(self): EXAMPLES:: - sage: SG4 = SymmetricGroupAlgebra(ZZ,4) # optional - sage.groups sage.modules - sage: SG4(1).is_central() # optional - sage.groups sage.modules + sage: SG4 = SymmetricGroupAlgebra(ZZ,4) # needs sage.groups sage.modules + sage: SG4(1).is_central() # needs sage.groups sage.modules True - sage: SG4(Permutation([1,3,2,4])).is_central() # optional - sage.groups sage.modules + sage: SG4(Permutation([1,3,2,4])).is_central() # needs sage.groups sage.modules False - sage: A = GroupAlgebras(QQ).example(); A # optional - sage.groups sage.modules + sage: A = GroupAlgebras(QQ).example(); A # needs sage.groups sage.modules Algebra of Dihedral group of order 8 as a permutation group over Rational Field - sage: sum(A.basis()).is_central() # optional - sage.groups sage.modules + sage: sum(A.basis()).is_central() # needs sage.groups sage.modules True """ return all(i * self == self * i @@ -631,19 +633,20 @@ def monoid_generators(self): EXAMPLES:: - sage: M = Monoids.free([1, 2, 3]) # optional - sage.groups - sage: N = Monoids.free(['a', 'b']) # optional - sage.groups - sage: C = cartesian_product([M, N]) # optional - sage.groups - sage: C.monoid_generators() # optional - sage.groups + sage: # needs sage.groups + sage: M = Monoids.free([1, 2, 3]) + sage: N = Monoids.free(['a', 'b']) + sage: C = cartesian_product([M, N]) + sage: C.monoid_generators() Family ((F[1], 1), (F[2], 1), (F[3], 1), (1, F['a']), (1, F['b'])) An example with an infinitely generated group (a better output is needed):: - sage: N = Monoids.free(ZZ) # optional - sage.groups - sage: C = cartesian_product([M, N]) # optional - sage.groups - sage: C.monoid_generators() # optional - sage.groups + sage: N = Monoids.free(ZZ) # needs sage.combinat + sage: C = cartesian_product([M, N]) # needs sage.combinat sage.groups + sage: C.monoid_generators() # needs sage.combinat sage.groups Lazy family (gen(i))_{i in The Cartesian product of (...)} """ F = self.cartesian_factors() @@ -680,10 +683,11 @@ def multiplicative_order(self): EXAMPLES:: - sage: G1 = SymmetricGroup(3) # optional - sage.groups sage.modules - sage: G2 = SL(2, 3) # optional - sage.groups sage.modules - sage: G = cartesian_product([G1, G2]) # optional - sage.groups sage.modules - sage: G((G1.gen(0), G2.gen(1))).multiplicative_order() # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: G1 = SymmetricGroup(3) + sage: G2 = SL(2, 3) + sage: G = cartesian_product([G1, G2]) + sage: G((G1.gen(0), G2.gen(1))).multiplicative_order() 12 """ from sage.rings.infinity import Infinity @@ -700,10 +704,11 @@ def __invert__(self): EXAMPLES:: - sage: a1 = Permutation((4,2,1,3)) # optional - sage.groups sage.modules - sage: a2 = SL(2, 3)([2,1,1,1]) # optional - sage.groups sage.modules - sage: h = cartesian_product([a1, a2]) # optional - sage.groups sage.modules - sage: ~h # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: a1 = Permutation((4,2,1,3)) + sage: a2 = SL(2, 3)([2,1,1,1]) + sage: h = cartesian_product([a1, a2]) + sage: ~h ([2, 4, 1, 3], [1 2] [2 2]) """ diff --git a/src/sage/categories/morphism.pyx b/src/sage/categories/morphism.pyx index 514140b2333..571f90a7330 100644 --- a/src/sage/categories/morphism.pyx +++ b/src/sage/categories/morphism.pyx @@ -76,18 +76,18 @@ cdef class Morphism(Map): TESTS:: - sage: K = CyclotomicField(12) # optional - sage.rings.number_field - sage: L = CyclotomicField(132) # optional - sage.rings.number_field - sage: phi = L._internal_coerce_map_from(K); phi # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + sage: K = CyclotomicField(12) + sage: L = CyclotomicField(132) + sage: phi = L._internal_coerce_map_from(K); phi (map internal to coercion system -- copy before use) Generic morphism: From: Cyclotomic Field of order 12 and degree 4 To: Cyclotomic Field of order 132 and degree 40 - - sage: del K # optional - sage.rings.number_field + sage: del K sage: import gc sage: _ = gc.collect() - sage: phi # optional - sage.rings.number_field + sage: phi Defunct morphism """ D = self.domain() @@ -182,10 +182,11 @@ cdef class Morphism(Map): and left modules over (euclidean domains and infinite enumerated sets and metric spaces) - sage: K = CyclotomicField(12) # optional - sage.rings.number_field - sage: L = CyclotomicField(132) # optional - sage.rings.number_field - sage: phi = L._internal_coerce_map_from(K) # optional - sage.rings.number_field - sage: phi.category() # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + sage: K = CyclotomicField(12) + sage: L = CyclotomicField(132) + sage: phi = L._internal_coerce_map_from(K) + sage: phi.category() Category of homsets of number fields """ # Should it be Category of elements of ...? @@ -202,10 +203,11 @@ cdef class Morphism(Map): sage: f.is_endomorphism() True - sage: K = CyclotomicField(12) # optional - sage.rings.number_field - sage: L = CyclotomicField(132) # optional - sage.rings.number_field - sage: phi = L._internal_coerce_map_from(K) # optional - sage.rings.number_field - sage: phi.is_endomorphism() # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + sage: K = CyclotomicField(12) + sage: L = CyclotomicField(132) + sage: phi = L._internal_coerce_map_from(K) + sage: phi.is_endomorphism() False """ return self.parent().is_endomorphism_set() @@ -224,7 +226,7 @@ cdef class Morphism(Map): sage: f = R.hom([t]) sage: f.is_identity() True - sage: g = R.hom([t+1]) + sage: g = R.hom([t + 1]) sage: g.is_identity() False @@ -304,14 +306,15 @@ cdef class Morphism(Map): Let us declare a conversion from the symmetric group to `\ZZ` through the sign map:: - sage: S = SymmetricGroup(4) # optional - sage.groups - sage: phi = Hom(S, ZZ)(lambda x: ZZ(x.sign())) # optional - sage.groups - sage: x = S.an_element(); x # optional - sage.groups + sage: # needs sage.groups + sage: S = SymmetricGroup(4) + sage: phi = Hom(S, ZZ)(lambda x: ZZ(x.sign())) + sage: x = S.an_element(); x (2,3,4) - sage: phi(x) # optional - sage.groups + sage: phi(x) 1 - sage: phi.register_as_conversion() # optional - sage.groups - sage: ZZ(x) # optional - sage.groups + sage: phi.register_as_conversion() + sage: ZZ(x) 1 """ self._codomain.register_conversion(self) @@ -350,11 +353,12 @@ cdef class Morphism(Map): TESTS:: + sage: # needs sage.combinat sage: from sage.categories.morphism import SetMorphism - sage: E = End(Partitions(5)) # optional - sage.combinat - sage: f = E.identity() # optional - sage.combinat - sage: g = SetMorphism(E, lambda x: x) # optional - sage.combinat - sage: f == g # optional - sage.combinat + sage: E = End(Partitions(5)) + sage: f = E.identity() + sage: g = SetMorphism(E, lambda x: x) + sage: f == g Traceback (most recent call last): ... NotImplementedError: unable to compare morphisms of type <... 'sage.categories.morphism.IdentityMorphism'> @@ -362,16 +366,16 @@ cdef class Morphism(Map): We check that :trac:`28617` is fixed:: - sage: FF = GF(2^20) # optional - sage.libs.combinat - sage: f = FF.frobenius_endomorphism() # optional - sage.libs.combinat - sage: f == FF.frobenius_endomorphism() # optional - sage.libs.combinat + sage: FF = GF(2^20) # needs sage.rings.finite_rings + sage: f = FF.frobenius_endomorphism() # needs sage.rings.finite_rings + sage: f == FF.frobenius_endomorphism() # needs sage.rings.finite_rings True and that :trac:`29632` is fixed:: - sage: R. = QuadraticField(-1)[] # optional - sage.rings.number_field - sage: f = R.hom(R.gens(), R) # optional - sage.rings.number_field - sage: f.is_identity() # optional - sage.rings.number_field + sage: R. = QuadraticField(-1)[] # needs sage.rings.number_field + sage: f = R.hom(R.gens(), R) # needs sage.rings.number_field + sage: f.is_identity() # needs sage.rings.number_field True """ if self is other: @@ -507,17 +511,18 @@ cdef class IdentityMorphism(Morphism): EXAMPLES:: - sage: E = End(Partitions(5)) # optional - sage.combinat - sage: E.identity().is_identity() # optional - sage.combinat + sage: E = End(Partitions(5)) # needs sage.combinat + sage: E.identity().is_identity() # needs sage.combinat True Check that :trac:`15478` is fixed:: - sage: K. = GF(4) # optional - sage.rings.finite_rings - sage: phi = End(K)([z^2]) # optional - sage.rings.finite_rings - sage: R. = K[] # optional - sage.rings.finite_rings - sage: psi = End(R)(phi) # optional - sage.rings.finite_rings - sage: psi.is_identity() # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K. = GF(4) + sage: phi = End(K)([z^2]) + sage: R. = K[] + sage: psi = End(R)(phi) + sage: psi.is_identity() False """ return True @@ -683,7 +688,7 @@ cdef class SetMorphism(Morphism): sage: f = sage.categories.morphism.SetMorphism(Hom(ZZ,ZZ, Sets()), operator.__abs__) sage: g = sage.categories.morphism.SetMorphism(Hom(ZZ,ZZ, Sets()), operator.__abs__) - sage: h = sage.categories.morphism.SetMorphism(Hom(ZZ,ZZ, Rings()), operator.__abs__) # todo: replace by the more correct Monoids + sage: h = sage.categories.morphism.SetMorphism(Hom(ZZ,ZZ, Rings()), operator.__abs__) # todo: replace by the more correct Monoids sage: i = sage.categories.morphism.SetMorphism(Hom(ZZ,ZZ, Sets()), operator.__neg__) sage: f._eq_c_impl(g) True @@ -709,7 +714,7 @@ cdef class SetMorphism(Morphism): sage: f = sage.categories.morphism.SetMorphism(Hom(ZZ,ZZ, Sets()), operator.__abs__) sage: g = sage.categories.morphism.SetMorphism(Hom(ZZ,ZZ, Sets()), operator.__abs__) - sage: h = sage.categories.morphism.SetMorphism(Hom(ZZ,ZZ, Rings()), operator.__abs__) # todo: replace by the more correct Monoids + sage: h = sage.categories.morphism.SetMorphism(Hom(ZZ,ZZ, Rings()), operator.__abs__) # todo: replace by the more correct Monoids sage: i = sage.categories.morphism.SetMorphism(Hom(ZZ,ZZ, Sets()), operator.__neg__) sage: f == f, f != f, f < f, f > f, f <= f, f >= f (True, False, False, False, True, True) diff --git a/src/sage/categories/number_fields.py b/src/sage/categories/number_fields.py index f3610cd8b7f..3c070bd65b2 100644 --- a/src/sage/categories/number_fields.py +++ b/src/sage/categories/number_fields.py @@ -42,16 +42,16 @@ class NumberFields(Category_singleton): course also in this category:: sage: x = PolynomialRing(RationalField(), 'x').gen() - sage: K = NumberField(x - 1, 'a'); K # optional - sage.rings.number_field + sage: K = NumberField(x - 1, 'a'); K # needs sage.rings.number_field Number Field in a with defining polynomial x - 1 - sage: K in C # optional - sage.rings.number_field + sage: K in C # needs sage.rings.number_field True Number fields all lie in this category, regardless of the name of the variable:: - sage: K = NumberField(x^2 + 1, 'a') # optional - sage.rings.number_field - sage: K in C # optional - sage.rings.number_field + sage: K = NumberField(x^2 + 1, 'a') # needs sage.rings.number_field + sage: K in C # needs sage.rings.number_field True TESTS:: @@ -75,11 +75,11 @@ def __contains__(self, x): EXAMPLES:: sage: x = polygen(QQ, 'x') - sage: NumberField(x^2 + 1, 'a') in NumberFields() # optional - sage.rings.number_field + sage: NumberField(x^2 + 1, 'a') in NumberFields() # needs sage.rings.number_field True - sage: QuadraticField(-97, 'theta') in NumberFields() # optional - sage.rings.number_field + sage: QuadraticField(-97, 'theta') in NumberFields() # needs sage.rings.number_field True - sage: CyclotomicField(97) in NumberFields() # optional - sage.rings.number_field + sage: CyclotomicField(97) in NumberFields() # needs sage.rings.number_field True Note that the rational numbers QQ are a number field:: @@ -105,10 +105,10 @@ def _call_(self, x): sage: C(QQ) Rational Field - sage: C(NumberField(x^2 + 1, 'a')) # optional - sage.rings.number_field + sage: C(NumberField(x^2 + 1, 'a')) # needs sage.rings.number_field Number Field in a with defining polynomial x^2 + 1 - sage: C(UnitGroup(NumberField(x^2 + 1, 'a'))) # indirect doctest # optional - sage.rings.number_field + sage: C(UnitGroup(NumberField(x^2 + 1, 'a'))) # indirect doctest # needs sage.rings.number_field Number Field in a with defining polynomial x^2 + 1 sage: C(ZZ) @@ -151,35 +151,35 @@ def zeta_function(self, prec=53, EXAMPLES:: - sage: K. = NumberField(ZZ['x'].0^2 + ZZ['x'].0 - 1) # optional - sage.rings.number_field - sage: Z = K.zeta_function(); Z # optional - sage.rings.number_field sage.symbolic + sage: K. = NumberField(ZZ['x'].0^2 + ZZ['x'].0 - 1) # needs sage.rings.number_field + sage: Z = K.zeta_function(); Z # needs sage.rings.number_field sage.symbolic PARI zeta function associated to Number Field in a with defining polynomial x^2 + x - 1 - sage: Z(-1) # optional - sage.rings.number_field sage.symbolic + sage: Z(-1) # needs sage.rings.number_field sage.symbolic 0.0333333333333333 sage: x = polygen(QQ, 'x') - sage: L. = NumberField([x^2 - 5, x^2 + 3, x^2 + 1]) # optional - sage.rings.number_field - sage: Z = L.zeta_function() # optional - sage.rings.number_field sage.symbolic - sage: Z(5) # optional - sage.rings.number_field sage.symbolic + sage: L. = NumberField([x^2 - 5, x^2 + 3, x^2 + 1]) # needs sage.rings.number_field + sage: Z = L.zeta_function() # needs sage.rings.number_field sage.symbolic + sage: Z(5) # needs sage.rings.number_field sage.symbolic 1.00199015670185 Using the algorithm "pari":: - sage: K. = NumberField(ZZ['x'].0^2 + ZZ['x'].0 - 1) # optional - sage.rings.number_field - sage: Z = K.zeta_function(algorithm="pari") # optional - sage.rings.number_field sage.symbolic - sage: Z(-1) # optional - sage.rings.number_field sage.symbolic + sage: K. = NumberField(ZZ['x'].0^2 + ZZ['x'].0 - 1) # needs sage.rings.number_field + sage: Z = K.zeta_function(algorithm="pari") # needs sage.rings.number_field sage.symbolic + sage: Z(-1) # needs sage.rings.number_field sage.symbolic 0.0333333333333333 sage: x = polygen(QQ, 'x') - sage: L. = NumberField([x^2 - 5, x^2 + 3, x^2 + 1]) # optional - sage.rings.number_field - sage: Z = L.zeta_function(algorithm="pari") # optional - sage.rings.number_field sage.symbolic - sage: Z(5) # optional - sage.rings.number_field sage.symbolic + sage: L. = NumberField([x^2 - 5, x^2 + 3, x^2 + 1]) # needs sage.rings.number_field + sage: Z = L.zeta_function(algorithm="pari") # needs sage.rings.number_field sage.symbolic + sage: Z(5) # needs sage.rings.number_field sage.symbolic 1.00199015670185 TESTS:: - sage: QQ.zeta_function() # optional - sage.symbolic + sage: QQ.zeta_function() # needs sage.symbolic PARI zeta function associated to Rational Field """ if algorithm == 'gp': @@ -224,8 +224,8 @@ def _test_absolute_disc(self, **options): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: S = NumberField(x**3 - x - 1, 'a') # optional - sage.rings.number_field - sage: S._test_absolute_disc() # optional - sage.rings.number_field + sage: S = NumberField(x**3 - x - 1, 'a') # needs sage.rings.number_field + sage: S._test_absolute_disc() # needs sage.rings.number_field """ from sage.rings.integer import Integer tester = self._tester(**options) diff --git a/src/sage/categories/polyhedra.py b/src/sage/categories/polyhedra.py index 7bfb89bd2ae..256eb99498d 100644 --- a/src/sage/categories/polyhedra.py +++ b/src/sage/categories/polyhedra.py @@ -26,10 +26,11 @@ class PolyhedralSets(Category_over_base_ring): sage: TestSuite(PolyhedralSets(RDF)).run() - sage: P = Polyhedron() # optional - sage.geometry.polyhedron - sage: P.parent().category().element_class # optional - sage.geometry.polyhedron + sage: # needs sage.geometry.polyhedron + sage: P = Polyhedron() + sage: P.parent().category().element_class - sage: P.parent().category().element_class.mro() # optional - sage.geometry.polyhedron + sage: P.parent().category().element_class.mro() [, , , @@ -45,7 +46,7 @@ class PolyhedralSets(Category_over_base_ring): , , ] - sage: isinstance(P, P.parent().category().element_class) # optional - sage.geometry.polyhedron + sage: isinstance(P, P.parent().category().element_class) True """ @@ -53,7 +54,7 @@ def __init__(self, R): """ TESTS:: - sage: PolyhedralSets(AA) # optional - sage.rings.number_field + sage: PolyhedralSets(AA) # needs sage.rings.number_field Category of polyhedral sets over Algebraic Real Field """ Category_over_base_ring.__init__(self, R) diff --git a/src/sage/categories/poor_man_map.py b/src/sage/categories/poor_man_map.py index 6912c4878cf..de5d2c5d462 100644 --- a/src/sage/categories/poor_man_map.py +++ b/src/sage/categories/poor_man_map.py @@ -209,12 +209,13 @@ def __mul__(self, other): But it is detected here:: sage: g = PoorManMap(factorial, domain=ZZ, codomain=ZZ) - sage: h = PoorManMap(sqrt, domain=RR, codomain=CC) - sage: g*h + sage: h = PoorManMap(sqrt, domain=RR, codomain=CC) # needs sage.rings.real_mpfr + sage: g*h # needs sage.rings.real_mpfr Traceback (most recent call last): ... - ValueError: the codomain Complex Field with 53 bits of precision does not coerce into the domain Integer Ring - sage: h*g + ValueError: the codomain Complex Field with 53 bits of precision + does not coerce into the domain Integer Ring + sage: h*g # needs sage.rings.real_mpfr A map from Integer Ring to Complex Field with 53 bits of precision """ self_domain = self.domain() @@ -266,8 +267,8 @@ def _sympy_(self): EXAMPLES:: sage: from sage.categories.poor_man_map import PoorManMap - sage: h = PoorManMap(sin, domain=RR, codomain=RR) # optional - sage.symbolic - sage: h._sympy_() # optional - sage.symbolic + sage: h = PoorManMap(sin, domain=RR, codomain=RR) + sage: h._sympy_() # needs sympy sage.symbolic sin """ from sympy import Lambda, sympify diff --git a/src/sage/categories/posets.py b/src/sage/categories/posets.py index 47408110da2..5cad3c70f73 100644 --- a/src/sage/categories/posets.py +++ b/src/sage/categories/posets.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.graphs, sage.combinat +# sage.doctest: needs sage.graphs, sage.combinat r""" Posets """ @@ -401,7 +401,7 @@ def order_ideal_toggle(self, I, v): sage: P = Poset({1: [2,3], 2: [4], 3: []}) sage: I = Set({1, 2}) - sage: I in P.order_ideals_lattice() + sage: I in P.order_ideals_lattice() # needs sage.modules True sage: P.order_ideal_toggle(I, 1) {1, 2} @@ -412,7 +412,7 @@ def order_ideal_toggle(self, I, v): sage: P.order_ideal_toggle(I, 4) {1, 2, 4} sage: P4 = Posets(4) - sage: all(all(all(P.order_ideal_toggle(P.order_ideal_toggle(I, i), i) == I + sage: all(all(all(P.order_ideal_toggle(P.order_ideal_toggle(I, i), i) == I # needs sage.modules ....: for i in range(4)) ....: for I in P.order_ideals_lattice(facade=True)) ....: for P in P4) diff --git a/src/sage/categories/primer.py b/src/sage/categories/primer.py index d57c38b77fa..14f8d5fbbe5 100644 --- a/src/sage/categories/primer.py +++ b/src/sage/categories/primer.py @@ -75,15 +75,15 @@ Similar objects should behave similarly:: - sage: Permutations(5).cardinality() # optional - sage.combinat + sage: Permutations(5).cardinality() 120 - sage: GL(2,2).cardinality() # optional - sage.groups + sage: GL(2,2).cardinality() # needs sage.modules 6 - sage: A = random_matrix(ZZ, 6, 3, x=7) # optional - sage.modules - sage: L = LatticePolytope(A.rows()) # optional - sage.geometry.polyhedron sage.modules - sage: L.npoints() # oops! # random # optional - sage.geometry.polyhedron sage.modules + sage: A = random_matrix(ZZ, 6, 3, x=7) # needs sage.modules + sage: L = LatticePolytope(A.rows()) # needs sage.geometry.polyhedron sage.modules + sage: L.npoints() # oops! # random # needs sage.geometry.polyhedron sage.modules 37 - How to ensure robustness? @@ -98,9 +98,10 @@ :: - sage: m = random_matrix(QQ, 4, algorithm='echelonizable', # optional - sage.modules + sage: # needs sage.modules + sage: m = random_matrix(QQ, 4, algorithm='echelonizable', ....: rank=3, upper_bound=60) - sage: m^8 == m*m*m*m*m*m*m*m == ((m^2)^2)^2 # optional - sage.modules + sage: m^8 == m*m*m*m*m*m*m*m == ((m^2)^2)^2 True We want to implement binary powering only once, as *generic* code @@ -126,12 +127,12 @@ and sure enough, binary powering is defined there:: - sage: m._pow_int.__module__ + sage: m._pow_int.__module__ # needs sage.modules 'sage.categories.monoids' That's our bookshelf! And it's used in many places:: - sage: GL(2, ZZ) in Monoids() # optional - sage.modules + sage: GL(2, ZZ) in Monoids() # needs sage.modules True sage: NN in Monoids() True @@ -169,20 +170,20 @@ Each set in Sage knows which bookshelf of generic algorithms it can use, that is to which category it belongs:: - sage: G = GL(2, ZZ) # optional - sage.modules - sage: G.category() # optional - sage.modules + sage: G = GL(2, ZZ) # needs sage.modules + sage: G.category() # needs sage.modules Category of infinite groups In fact a group is a semigroup, and Sage knows about this:: sage: Groups().is_subcategory(Semigroups()) True - sage: G in Semigroups() # optional - sage.modules + sage: G in Semigroups() # needs sage.modules True Altogether, our group gets algorithms from a bunch of bookshelves:: - sage: G.categories() # optional - sage.modules + sage: G.categories() # needs sage.modules [Category of infinite groups, Category of groups, Category of monoids, ..., Category of magmas, @@ -190,19 +191,19 @@ Those can be viewed graphically:: - sage: g = Groups().category_graph() # optional - sage.modules sage.graphs - sage: g.set_latex_options(format="dot2tex") # optional - sage.modules sage.graphs - sage: view(g) # not tested # optional - sage.modules sage.graphs sage.plot + sage: g = Groups().category_graph() # needs sage.graphs + sage: g.set_latex_options(format="dot2tex") # needs sage.graphs sage.modules + sage: view(g) # not tested # needs sage.graphs sage.modules sage.plot In case ``dot2tex`` is not available, you can use instead:: - sage: g.show(vertex_shape=None, figsize=20) # optional - sage.modules sage.graphs sage.plot + sage: g.show(vertex_shape=None, figsize=20) # needs sage.graphs sage.modules sage.plot Here is an overview of all categories in Sage:: - sage: g = sage.categories.category.category_graph() # optional - sage.modules sage.graphs - sage: g.set_latex_options(format="dot2tex") # optional - sage.modules sage.graphs - sage: view(g) # not tested # optional - sage.modules sage.graphs sage.plot + sage: g = sage.categories.category.category_graph() # needs sage.graphs sage.modules + sage: g.set_latex_options(format="dot2tex") # needs sage.graphs sage.modules + sage: view(g) # not tested # needs sage.graphs sage.modules sage.plot Wrap-up: generic algorithms in Sage are organized in a hierarchy of bookshelves modelled upon the usual hierarchy of categories provided @@ -371,9 +372,9 @@ Category of sets with partial maps, Category of objects] - sage: g = EuclideanDomains().category_graph() # optional - sage.graphs - sage: g.set_latex_options(format="dot2tex") # optional - sage.graphs - sage: view(g) # not tested # optional - sage.graphs sage.plot + sage: g = EuclideanDomains().category_graph() # needs sage.graphs + sage: g.set_latex_options(format="dot2tex") # needs sage.graphs sage.plot + sage: view(g) # not tested # needs sage.graphs sage.plot A bit of help from computer science =================================== @@ -407,24 +408,27 @@ class implements: sage: i.factor() 2^2 * 3 - sage: x = var('x') # optional - sage.symbolic - sage: p = 6*x^2 + 12*x + 6 # optional - sage.symbolic - sage: type(p) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: x = var('x') + sage: p = 6*x^2 + 12*x + 6 + sage: type(p) - sage: p.factor() # optional - sage.symbolic + sage: p.factor() 6*(x + 1)^2 + sage: # needs sage.symbolic sage: R. = PolynomialRing(QQ, sparse=True) - sage: pQ = R(p) # optional - sage.symbolic - sage: type(pQ) # optional - sage.symbolic + sage: pQ = R(p) + sage: type(pQ) - sage: pQ.factor() # optional - sage.symbolic + sage: pQ.factor() (6) * (x + 1)^2 - sage: pZ = ZZ['x'](p) # optional - sage.symbolic - sage: type(pZ) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: pZ = ZZ['x'](p) + sage: type(pZ) - sage: pZ.factor() # optional - sage.symbolic + sage: pZ.factor() 2 * 3 * (x + 1)^2 Factoring integers, expressions, or polynomials are distinct tasks, @@ -444,9 +448,9 @@ class implements: sage: i._pow_.__module__ # not tested (Issue #24275) 'sage.categories.semigroups' - sage: pQ._mul_.__module__ # optional - sage.symbolic + sage: pQ._mul_.__module__ # needs sage.symbolic 'sage.rings.polynomial.polynomial_element_generic' - sage: pQ._pow_.__module__ # not tested (Issue #24275) # optional - sage.symbolic + sage: pQ._pow_.__module__ # not tested (Issue #24275) # needs sage.symbolic 'sage.categories.semigroups' We see that integers and polynomials have each their own @@ -467,9 +471,9 @@ class implements: hierarchy of categories (bookshelves). Here is for example a piece of the hierarchy of classes for an element of a group of permutations:: - sage: P = Permutations(4) # optional - sage.combinat - sage: m = P.an_element() # optional - sage.combinat - sage: for cls in m.__class__.mro(): print(cls) # optional - sage.combinat + sage: P = Permutations(4) + sage: m = P.an_element() + sage: for cls in m.__class__.mro(): print(cls) @@ -487,9 +491,9 @@ class implements: The full hierarchy is best viewed graphically:: - sage: g = class_graph(m.__class__) # optional - sage.combinat sage.graphs - sage: g.set_latex_options(format="dot2tex") # optional - sage.combinat sage.graphs - sage: view(g) # not tested # optional - sage.combinat sage.graphs sage.plot + sage: g = class_graph(m.__class__) # needs sage.combinat sage.graphs + sage: g.set_latex_options(format="dot2tex") # needs sage.combinat sage.graphs + sage: view(g) # not tested # needs sage.combinat sage.graphs sage.plot Parallel hierarchy of classes for parents ----------------------------------------- @@ -523,13 +527,13 @@ class implements: modelled by instances of some (hierarchy of) classes. For example, our group `G` is an instance of the following class:: - sage: G = GL(2, ZZ) # optional - sage.modules - sage: type(G) # optional - sage.modules + sage: G = GL(2, ZZ) # needs sage.modules + sage: type(G) # needs sage.libs.gap sage.modules Here is a piece of the hierarchy of classes above it:: - sage: for cls in G.__class__.mro(): print(cls) # optional - sage.modules + sage: for cls in G.__class__.mro(): print(cls) # needs sage.libs.gap sage.modules ... @@ -541,10 +545,11 @@ class implements: categories and parallel to that we had seen for the elements. This is best viewed graphically:: - sage: g = class_graph(m.__class__) # optional - sage.modules sage.graphs - sage: g.relabel(lambda x: x.replace("_",r"\_")) # optional - sage.modules sage.graphs - sage: g.set_latex_options(format="dot2tex") # optional - sage.modules sage.graphs - sage: view(g) # not tested # optional - sage.modules sage.graphs sage.plot + sage: # needs sage.graphs sage.modules + sage: g = class_graph(m.__class__) + sage: g.relabel(lambda x: x.replace("_",r"\_")) + sage: g.set_latex_options(format="dot2tex") + sage: view(g) # not tested # needs sage.plot .. NOTE:: @@ -725,7 +730,7 @@ class SubcategoryMethods: Note that categories themselves are naturally modelled by instances because they can have operations of their own. An important one is:: - sage: Groups().example() # optional - sage.modules + sage: Groups().example() # needs sage.modules General Linear Group of degree 4 over Rational Field which gives an example of object of the category. Besides illustrating @@ -1018,17 +1023,17 @@ class SubcategoryMethods: example, permutation groups are by default in the category of finite permutation groups (no surprise):: - sage: P = PermutationGroup([[(1,2,3)]]); P # optional - sage.combinat + sage: P = PermutationGroup([[(1,2,3)]]); P # needs sage.combinat sage.groups Permutation Group with generators [(1,2,3)] - sage: P.category() # optional - sage.combinat + sage: P.category() # needs sage.combinat Category of finite enumerated permutation groups In this case, the group is commutative, so we can specify this:: - sage: P = PermutationGroup([[(1,2,3)]], # optional - sage.combinat + sage: P = PermutationGroup([[(1,2,3)]], # needs sage.combinat sage.groups ....: category=PermutationGroups().Finite().Commutative()); P Permutation Group with generators [(1,2,3)] - sage: P.category() # optional - sage.combinat + sage: P.category() # needs sage.combinat Category of finite enumerated commutative permutation groups This feature can even be used, typically in experimental code, to add @@ -1043,18 +1048,19 @@ class SubcategoryMethods: ....: class ElementMethods: ....: def bar(self): print("bar") - sage: P = PermutationGroup([[(1,2,3)]], category=Foos()) # optional - sage.combinat - sage: P.foo() # optional - sage.combinat + sage: # needs sage.combinat + sage: P = PermutationGroup([[(1,2,3)]], category=Foos()) # needs sage.groups + sage: P.foo() foo - sage: p = P.an_element() # optional - sage.combinat - sage: p.bar() # optional - sage.combinat + sage: p = P.an_element() + sage: p.bar() bar In the long run, it would be thinkable to use this idiom to implement forgetful functors; for example the above group could be constructed as a plain set with:: - sage: P = PermutationGroup([[(1,2,3)]], category=Sets()) # todo: not implemented # optional - sage.combinat + sage: P = PermutationGroup([[(1,2,3)]], category=Sets()) # not implemented, needs sage.combinat At this stage though, this is still to be explored for robustness and practicality. For now, most parents that accept a category argument @@ -1102,9 +1108,9 @@ class SubcategoryMethods: Let for example `A` and `B` be two parents, and let us construct the Cartesian product `A \times B \times B`:: - sage: A = AlgebrasWithBasis(QQ).example(); A.rename("A") # optional - sage.combinat sage.modules - sage: B = HopfAlgebrasWithBasis(QQ).example(); B.rename("B") # optional - sage.combinat sage.modules - sage: C = cartesian_product([A, B, B]); C # optional - sage.combinat sage.modules + sage: A = AlgebrasWithBasis(QQ).example(); A.rename("A") # needs sage.combinat sage.modules + sage: B = HopfAlgebrasWithBasis(QQ).example(); B.rename("B") # needs sage.combinat sage.modules + sage: C = cartesian_product([A, B, B]); C # needs sage.combinat sage.modules A (+) B (+) B In which category should this new parent be? Since `A` and `B` are @@ -1113,14 +1119,14 @@ class SubcategoryMethods: are monoids, `A \times B \times B` is naturally endowed with a monoid structure for pointwise multiplication:: - sage: C in Monoids() # optional - sage.combinat sage.modules + sage: C in Monoids() # needs sage.combinat sage.modules True the unit being the Cartesian product of the units of the operands:: - sage: C.one() # optional - sage.combinat sage.modules + sage: C.one() # needs sage.combinat sage.modules B[(0, word: )] + B[(1, ())] + B[(2, ())] - sage: cartesian_product([A.one(), B.one(), B.one()]) # optional - sage.combinat sage.modules + sage: cartesian_product([A.one(), B.one(), B.one()]) # needs sage.combinat sage.modules B[(0, word: )] + B[(1, ())] + B[(2, ())] The pointwise product can be implemented generically for all magmas @@ -1128,7 +1134,7 @@ class SubcategoryMethods: constructed as Cartesian products. It's thus implemented in the :class:`Magmas` category:: - sage: C.product.__module__ # optional - sage.combinat sage.modules + sage: C.product.__module__ # needs sage.combinat sage.modules 'sage.categories.magmas' More specifically, keeping on using nested classes to structure the @@ -1160,7 +1166,7 @@ class naming and introspection. Sage currently works around the Let us now look at the categories of ``C``:: - sage: C.categories() # optional - sage.combinat sage.modules + sage: C.categories() # needs sage.combinat sage.modules [Category of finite dimensional Cartesian products of algebras with basis over Rational Field, ... Category of Cartesian products of algebras over Rational Field, ... Category of Cartesian products of semigroups, Category of semigroups, ... @@ -1392,9 +1398,9 @@ class naming and introspection. Sage currently works around the or for more advanced categories:: - sage: g = HopfAlgebras(QQ).WithBasis().Graded().Connected().category_graph() # optional - sage.graphs - sage: g.set_latex_options(format="dot2tex") # optional - sage.graphs - sage: view(g) # not tested # optional - sage.graphs sage.plot + sage: g = HopfAlgebras(QQ).WithBasis().Graded().Connected().category_graph() # needs sage.graphs + sage: g.set_latex_options(format="dot2tex") # needs sage.graphs + sage: view(g) # not tested # needs sage.graphs sage.plot Difference between axioms and regressive covariant functorial constructions ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/sage/categories/principal_ideal_domains.py b/src/sage/categories/principal_ideal_domains.py index fa8b2632cc1..95b10b7b034 100644 --- a/src/sage/categories/principal_ideal_domains.py +++ b/src/sage/categories/principal_ideal_domains.py @@ -70,22 +70,23 @@ def _test_gcd_vs_xgcd(self, **options): sage: ZZ._test_gcd_vs_xgcd() sage: QQ._test_gcd_vs_xgcd() sage: QQ['x']._test_gcd_vs_xgcd() - sage: QQbar['x']._test_gcd_vs_xgcd() # optional - sage.rings.number_field + sage: QQbar['x']._test_gcd_vs_xgcd() # needs sage.rings.number_field sage: RR._test_gcd_vs_xgcd() sage: RR['x']._test_gcd_vs_xgcd() A slightly more involved example of polynomial ring with a non UFD base ring:: - sage: K = QuadraticField(5) # optional - sage.rings.number_field - sage: O = K.maximal_order() # optional - sage.rings.number_field - sage: O in UniqueFactorizationDomains() # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + sage: K = QuadraticField(5) + sage: O = K.maximal_order() + sage: O in UniqueFactorizationDomains() False - sage: R = PolynomialRing(O, 'x') # optional - sage.rings.number_field - sage: F = R.fraction_field() # optional - sage.rings.number_field - sage: F in PrincipalIdealDomains() # optional - sage.rings.number_field + sage: R = PolynomialRing(O, 'x') + sage: F = R.fraction_field() + sage: F in PrincipalIdealDomains() True - sage: F._test_gcd_vs_xgcd() # optional - sage.rings.number_field + sage: F._test_gcd_vs_xgcd() """ tester = self._tester(**options) elts = list(tester.some_elements()) diff --git a/src/sage/categories/pushout.py b/src/sage/categories/pushout.py index 7bb97cd83fd..14de4cc4abe 100644 --- a/src/sage/categories/pushout.py +++ b/src/sage/categories/pushout.py @@ -107,12 +107,12 @@ class ConstructionFunctor(Functor): sage: P. = ZZ[] sage: F = P.construction()[0]; F MPoly[x,y] - sage: A. = GF(5)[] # optional - sage.rings.finite_rings - sage: f = A.hom([a + b, a - b], A) # optional - sage.rings.finite_rings - sage: F(A) # optional - sage.rings.finite_rings + sage: A. = GF(5)[] + sage: f = A.hom([a + b, a - b], A) + sage: F(A) Multivariate Polynomial Ring in x, y over Multivariate Polynomial Ring in a, b over Finite Field of size 5 - sage: F(f) # optional - sage.rings.finite_rings + sage: F(f) Ring endomorphism of Multivariate Polynomial Ring in x, y over Multivariate Polynomial Ring in a, b over Finite Field of size 5 Defn: Induced from base ring by @@ -120,7 +120,7 @@ class ConstructionFunctor(Functor): over Finite Field of size 5 Defn: a |--> a + b b |--> a - b - sage: F(f)(F(A)(x)*a) # optional - sage.rings.finite_rings + sage: F(f)(F(A)(x)*a) (a + b)*x """ @@ -441,7 +441,7 @@ class CompositeConstructionFunctor(ConstructionFunctor): True sage: F == CompositeConstructionFunctor(*F.all) True - sage: F(GF(2)['t']) # optional - sage.rings.finite_rings + sage: F(GF(2)['t']) # needs sage.libs.ntl Univariate Polynomial Ring in y over Fraction Field of Univariate Polynomial Ring in x over Fraction Field of Univariate Polynomial Ring in t @@ -812,32 +812,32 @@ class PolynomialFunctor(ConstructionFunctor): EXAMPLES:: sage: P = ZZ['t'].construction()[0] - sage: P(GF(3)) # optional - sage.rings.finite_rings + sage: P(GF(3)) Univariate Polynomial Ring in t over Finite Field of size 3 - sage: P == loads(dumps(P)) # optional - sage.rings.finite_rings + sage: P == loads(dumps(P)) True - sage: R. = GF(5)[] # optional - sage.rings.finite_rings - sage: f = R.hom([x + 2*y, 3*x - y], R) # optional - sage.rings.finite_rings - sage: P(f)((x+y) * P(R).0) # optional - sage.rings.finite_rings + sage: R. = GF(5)[] + sage: f = R.hom([x + 2*y, 3*x - y], R) + sage: P(f)((x+y) * P(R).0) (-x + y)*t By :trac:`9944`, the construction functor distinguishes sparse and dense polynomial rings. Before, the following example failed:: - sage: R. = PolynomialRing(GF(5), sparse=True) # optional - sage.rings.finite_rings - sage: F, B = R.construction() # optional - sage.rings.finite_rings - sage: F(B) is R # optional - sage.rings.finite_rings + sage: R. = PolynomialRing(GF(5), sparse=True) + sage: F, B = R.construction() + sage: F(B) is R True sage: S. = PolynomialRing(ZZ) - sage: R.has_coerce_map_from(S) # optional - sage.rings.finite_rings + sage: R.has_coerce_map_from(S) False - sage: S.has_coerce_map_from(R) # optional - sage.rings.finite_rings + sage: S.has_coerce_map_from(R) False - sage: S.0 + R.0 # optional - sage.rings.finite_rings + sage: S.0 + R.0 2*x - sage: (S.0 + R.0).parent() # optional - sage.rings.finite_rings + sage: (S.0 + R.0).parent() Univariate Polynomial Ring in x over Finite Field of size 5 - sage: (S.0 + R.0).parent().is_sparse() # optional - sage.rings.finite_rings + sage: (S.0 + R.0).parent().is_sparse() False """ @@ -849,7 +849,7 @@ def __init__(self, var, multi_variate=False, sparse=False, implementation=None): sage: from sage.categories.pushout import PolynomialFunctor sage: P = PolynomialFunctor('x') - sage: P(GF(3)) # optional - sage.rings.finite_rings + sage: P(GF(3)) Univariate Polynomial Ring in x over Finite Field of size 3 There is an optional parameter ``multi_variate``, but @@ -876,7 +876,7 @@ def _apply_functor(self, R): TESTS:: sage: P = ZZ['x'].construction()[0] - sage: P(GF(3)) # indirect doctest # optional - sage.rings.finite_rings + sage: P(GF(3)) # indirect doctest Univariate Polynomial Ring in x over Finite Field of size 3 """ @@ -893,7 +893,7 @@ def _apply_functor_to_morphism(self, f): TESTS:: sage: P = ZZ['x'].construction()[0] - sage: P(ZZ.hom(GF(3))) # indirect doctest # optional - sage.rings.finite_rings + sage: P(ZZ.hom(GF(3))) # indirect doctest Ring morphism: From: Univariate Polynomial Ring in x over Integer Ring To: Univariate Polynomial Ring in x over Finite Field of size 3 @@ -1003,19 +1003,19 @@ class MultiPolynomialFunctor(ConstructionFunctor): sage: P. = ZZ[] sage: F = P.construction()[0]; F MPoly[x,y] - sage: A. = GF(5)[] # optional - sage.rings.finite_rings - sage: F(A) # optional - sage.rings.finite_rings + sage: A. = GF(5)[] + sage: F(A) Multivariate Polynomial Ring in x, y over Multivariate Polynomial Ring in a, b over Finite Field of size 5 - sage: f = A.hom([a+b, a-b], A) # optional - sage.rings.finite_rings - sage: F(f) # optional - sage.rings.finite_rings + sage: f = A.hom([a+b, a-b], A) + sage: F(f) Ring endomorphism of Multivariate Polynomial Ring in x, y over Multivariate Polynomial Ring in a, b over Finite Field of size 5 Defn: Induced from base ring by Ring endomorphism of Multivariate Polynomial Ring in a, b over Finite Field of size 5 Defn: a |--> a + b b |--> a - b - sage: F(f)(F(A)(x)*a) # optional - sage.rings.finite_rings + sage: F(f)(F(A)(x)*a) (a + b)*x """ @@ -1031,7 +1031,7 @@ def __init__(self, vars, term_order): MPoly[x,y] sage: F(ZZ) Multivariate Polynomial Ring in x, y over Integer Ring - sage: F(CC) + sage: F(CC) # needs sage.rings.real_mpfr Multivariate Polynomial Ring in x, y over Complex Field with 53 bits of precision """ Functor.__init__(self, Rings(), Rings()) @@ -1051,7 +1051,7 @@ def _apply_functor(self, R): sage: F(ZZ) # indirect doctest Multivariate Polynomial Ring in x, y, z over Integer Ring - sage: F(RR) # indirect doctest + sage: F(RR) # indirect doctest # needs sage.rings.real_mpfr Multivariate Polynomial Ring in x, y, z over Real Field with 53 bits of precision """ from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing @@ -1170,8 +1170,8 @@ def expand(self): 'Multivariate Polynomial Ring in x, y, z over Integer Ring' and 'Multivariate Polynomial Ring in y, s over Rational Field' sage: R = PolynomialRing(ZZ, 'x', 50) - sage: S = PolynomialRing(GF(5), 'x', 20) # optional - sage.rings.finite_rings - sage: R.gen(0) + S.gen(0) # optional - sage.rings.finite_rings + sage: S = PolynomialRing(GF(5), 'x', 20) + sage: R.gen(0) + S.gen(0) 2*x0 """ if len(self.vars) <= 1: @@ -1574,17 +1574,18 @@ class MatrixFunctor(ConstructionFunctor): EXAMPLES:: - sage: MS = MatrixSpace(ZZ, 2, 3) # optional - sage.modules - sage: F = MS.construction()[0]; F # optional - sage.modules + sage: # needs sage.modules + sage: MS = MatrixSpace(ZZ, 2, 3) + sage: F = MS.construction()[0]; F MatrixFunctor - sage: MS = MatrixSpace(ZZ, 2) # optional - sage.modules - sage: F = MS.construction()[0]; F # optional - sage.modules + sage: MS = MatrixSpace(ZZ, 2) + sage: F = MS.construction()[0]; F MatrixFunctor - sage: P. = QQ[] # optional - sage.modules - sage: R = F(P); R # optional - sage.modules + sage: P. = QQ[] + sage: R = F(P); R Full MatrixSpace of 2 by 2 dense matrices over Multivariate Polynomial Ring in x, y over Rational Field - sage: f = P.hom([x+y, x-y], P); F(f) # optional - sage.modules + sage: f = P.hom([x+y, x-y], P); F(f) Ring endomorphism of Full MatrixSpace of 2 by 2 dense matrices over Multivariate Polynomial Ring in x, y over Rational Field @@ -1593,8 +1594,8 @@ class MatrixFunctor(ConstructionFunctor): of Multivariate Polynomial Ring in x, y over Rational Field Defn: x |--> x + y y |--> x - y - sage: M = R([x, y, x*y, x + y]) # optional - sage.modules - sage: F(f)(M) # optional - sage.modules + sage: M = R([x, y, x*y, x + y]) + sage: F(f)(M) [ x + y x - y] [x^2 - y^2 2*x] @@ -1605,22 +1606,23 @@ def __init__(self, nrows, ncols, is_sparse=False): """ TESTS:: + sage: # needs sage.modules sage: from sage.categories.pushout import MatrixFunctor - sage: F = MatrixFunctor(2, 3) # optional - sage.modules - sage: F == MatrixSpace(ZZ, 2, 3).construction()[0] # optional - sage.modules + sage: F = MatrixFunctor(2, 3) + sage: F == MatrixSpace(ZZ, 2, 3).construction()[0] True - sage: F.codomain() # optional - sage.modules + sage: F.codomain() Category of commutative additive groups - sage: R = MatrixSpace(ZZ, 2, 2).construction()[0] # optional - sage.modules - sage: R.codomain() # optional - sage.modules + sage: R = MatrixSpace(ZZ, 2, 2).construction()[0] + sage: R.codomain() Category of rings - sage: F(ZZ) # optional - sage.modules + sage: F(ZZ) Full MatrixSpace of 2 by 3 dense matrices over Integer Ring - sage: F(ZZ) in F.codomain() # optional - sage.modules + sage: F(ZZ) in F.codomain() True - sage: R(GF(2)) # optional - sage.rings.finite_rings sage.modules + sage: R(GF(2)) Full MatrixSpace of 2 by 2 dense matrices over Finite Field of size 2 - sage: R(GF(2)) in R.codomain() # optional - sage.rings.finite_rings sage.modules + sage: R(GF(2)) in R.codomain() True """ if nrows == ncols: @@ -1640,10 +1642,10 @@ def _apply_functor(self, R): The following is a test against a bug discussed at :trac:`8800`:: - sage: F = MatrixSpace(ZZ, 2, 3).construction()[0] # optional - sage.modules - sage: F(RR) # indirect doctest # optional - sage.modules + sage: F = MatrixSpace(ZZ, 2, 3).construction()[0] # needs sage.modules + sage: F(RR) # indirect doctest # needs sage.modules Full MatrixSpace of 2 by 3 dense matrices over Real Field with 53 bits of precision - sage: F(RR) in F.codomain() # optional - sage.modules + sage: F(RR) in F.codomain() # needs sage.modules True """ @@ -1654,10 +1656,10 @@ def __eq__(self, other): """ TESTS:: - sage: F = MatrixSpace(ZZ, 2, 3).construction()[0] # optional - sage.modules - sage: F == loads(dumps(F)) # optional - sage.modules + sage: F = MatrixSpace(ZZ, 2, 3).construction()[0] # needs sage.modules + sage: F == loads(dumps(F)) # needs sage.modules True - sage: F == MatrixSpace(ZZ, 2, 2).construction()[0] # optional - sage.modules + sage: F == MatrixSpace(ZZ, 2, 2).construction()[0] # needs sage.modules False """ if isinstance(other, MatrixFunctor): @@ -1670,10 +1672,10 @@ def __ne__(self, other): EXAMPLES:: - sage: F = MatrixSpace(ZZ, 2, 3).construction()[0] # optional - sage.modules - sage: F != loads(dumps(F)) # optional - sage.modules + sage: F = MatrixSpace(ZZ, 2, 3).construction()[0] # needs sage.modules + sage: F != loads(dumps(F)) # needs sage.modules False - sage: F != MatrixSpace(ZZ, 2, 2).construction()[0] # optional - sage.modules + sage: F != MatrixSpace(ZZ, 2, 2).construction()[0] # needs sage.modules True """ return not (self == other) @@ -1688,20 +1690,21 @@ def merge(self, other): EXAMPLES:: - sage: F1 = MatrixSpace(ZZ, 2, 2).construction()[0] # optional - sage.modules - sage: F2 = MatrixSpace(ZZ, 2, 3).construction()[0] # optional - sage.modules - sage: F3 = MatrixSpace(ZZ, 2, 2, sparse=True).construction()[0] # optional - sage.modules - sage: F1.merge(F2) # optional - sage.modules - sage: F1.merge(F3) # optional - sage.modules + sage: # needs sage.modules + sage: F1 = MatrixSpace(ZZ, 2, 2).construction()[0] + sage: F2 = MatrixSpace(ZZ, 2, 3).construction()[0] + sage: F3 = MatrixSpace(ZZ, 2, 2, sparse=True).construction()[0] + sage: F1.merge(F2) + sage: F1.merge(F3) MatrixFunctor - sage: F13 = F1.merge(F3) # optional - sage.modules - sage: F13.is_sparse # optional - sage.modules + sage: F13 = F1.merge(F3) + sage: F13.is_sparse False - sage: F1.is_sparse # optional - sage.modules + sage: F1.is_sparse False - sage: F3.is_sparse # optional - sage.modules + sage: F3.is_sparse True - sage: F3.merge(F3).is_sparse # optional - sage.modules + sage: F3.merge(F3).is_sparse True """ @@ -1760,9 +1763,9 @@ def __init__(self, var, multi_variate=False): sage: F1(F2(QQ)) Univariate Laurent Polynomial Ring in t over Univariate Laurent Polynomial Ring in s over Rational Field - sage: F2(F1(QQ)) # optional - sage.modules + sage: F2(F1(QQ)) # needs sage.modules Multivariate Laurent Polynomial Ring in t, s over Rational Field - sage: F3(QQ) # optional - sage.modules + sage: F3(QQ) # needs sage.modules Multivariate Laurent Polynomial Ring in s, t over Rational Field """ @@ -1785,9 +1788,9 @@ def _apply_functor(self, R): sage: F1(F2(QQ)) # indirect doctest Univariate Laurent Polynomial Ring in t over Univariate Laurent Polynomial Ring in s over Rational Field - sage: F2(F1(QQ)) # optional - sage.modules + sage: F2(F1(QQ)) # needs sage.modules Multivariate Laurent Polynomial Ring in t, s over Rational Field - sage: F3(QQ) # optional - sage.modules + sage: F3(QQ) # needs sage.modules Multivariate Laurent Polynomial Ring in s, t over Rational Field """ @@ -1855,9 +1858,9 @@ def merge(self, other): sage: F2 = LaurentPolynomialFunctor('t', multi_variate=True) sage: F1.merge(F2) LaurentPolynomialFunctor - sage: F1.merge(F2)(LaurentPolynomialRing(GF(2), 'a')) # optional - sage.rings.finite_rings + sage: F1.merge(F2)(LaurentPolynomialRing(GF(2), 'a')) # needs sage.modules Multivariate Laurent Polynomial Ring in a, t over Finite Field of size 2 - sage: F1.merge(F1)(LaurentPolynomialRing(GF(2), 'a')) # optional - sage.rings.finite_rings + sage: F1.merge(F1)(LaurentPolynomialRing(GF(2), 'a')) # needs sage.modules Univariate Laurent Polynomial Ring in t over Univariate Laurent Polynomial Ring in a over Finite Field of size 2 @@ -1874,12 +1877,14 @@ class VectorFunctor(ConstructionFunctor): EXAMPLES:: - sage: F = (ZZ^3).construction()[0] # optional - sage.modules - sage: F # optional - sage.modules + sage: # needs sage.modules + sage: F = (ZZ^3).construction()[0] + sage: F VectorFunctor - sage: F(GF(2)['t']) # optional - sage.rings.finite_rings sage.modules + sage: F(GF(2)['t']) # needs sage.libs.ntl Ambient free module of rank 3 - over the principal ideal domain Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X) + over the principal ideal domain Univariate Polynomial Ring in t + over Finite Field of size 2 (using GF2X) """ rank = 10 # ranking of functor, not rank of module. # This coincides with the rank of the matrix construction functor, but this is OK since they cannot both be applied in any order @@ -1898,22 +1903,23 @@ def __init__(self, n=None, is_sparse=False, inner_product_matrix=None, *, TESTS:: + sage: # needs sage.modules sage: from sage.categories.pushout import VectorFunctor - sage: F1 = VectorFunctor(3, inner_product_matrix=Matrix(3, 3, range(9))) # optional - sage.modules - sage: F1.domain() # optional - sage.modules + sage: F1 = VectorFunctor(3, inner_product_matrix=Matrix(3, 3, range(9))) + sage: F1.domain() Category of commutative rings - sage: F1.codomain() # optional - sage.modules + sage: F1.codomain() Category of commutative additive groups - sage: M1 = F1(ZZ) # optional - sage.modules - sage: M1.is_sparse() # optional - sage.modules + sage: M1 = F1(ZZ) + sage: M1.is_sparse() False - sage: v = M1([3, 2, 1]) # optional - sage.modules - sage: v * Matrix(3, 3, range(9)) * v.column() # optional - sage.modules + sage: v = M1([3, 2, 1]) + sage: v * Matrix(3, 3, range(9)) * v.column() (96) - sage: v.inner_product(v) # optional - sage.modules + sage: v.inner_product(v) 96 sage: F2 = VectorFunctor(3, is_sparse=True) - sage: M2 = F2(QQ); M2; M2.is_sparse() # optional - sage.modules + sage: M2 = F2(QQ); M2; M2.is_sparse() Sparse vector space of dimension 3 over Rational Field True @@ -1940,29 +1946,31 @@ def _apply_functor(self, R): TESTS:: + sage: # needs sage.modules sage: from sage.categories.pushout import VectorFunctor, pushout - sage: F1 = VectorFunctor(3, inner_product_matrix=Matrix(3, 3, range(9))) # optional - sage.modules - sage: M1 = F1(ZZ) # indirect doctest # optional - sage.modules - sage: M1.is_sparse() # optional - sage.modules + sage: F1 = VectorFunctor(3, inner_product_matrix=Matrix(3, 3, range(9))) + sage: M1 = F1(ZZ) # indirect doctest + sage: M1.is_sparse() False - sage: v = M1([3, 2, 1]) # optional - sage.modules - sage: v * Matrix(3, 3, range(9)) * v.column() # optional - sage.modules + sage: v = M1([3, 2, 1]) + sage: v * Matrix(3, 3, range(9)) * v.column() (96) - sage: v.inner_product(v) # optional - sage.modules + sage: v.inner_product(v) 96 - sage: F2 = VectorFunctor(3, is_sparse=True) # optional - sage.modules - sage: M2 = F2(QQ); M2; M2.is_sparse() # optional - sage.modules + sage: F2 = VectorFunctor(3, is_sparse=True) + sage: M2 = F2(QQ); M2; M2.is_sparse() Sparse vector space of dimension 3 over Rational Field True - sage: v = M2([3, 2, 1]) # optional - sage.modules - sage: v.inner_product(v) # optional - sage.modules + sage: v = M2([3, 2, 1]) + sage: v.inner_product(v) 14 - sage: M = FreeModule(ZZ, 4, with_basis=None, name='M') # optional - sage.modules - sage: latex(M) # optional - sage.modules + sage: # needs sage.modules + sage: M = FreeModule(ZZ, 4, with_basis=None, name='M') + sage: latex(M) M - sage: M_QQ = pushout(M, QQ) # optional - sage.modules - sage: latex(M_QQ) # optional - sage.modules + sage: M_QQ = pushout(M, QQ) + sage: latex(M_QQ) M \otimes \Bold{Q} """ @@ -1990,10 +1998,10 @@ def _apply_functor_to_morphism(self, f): TESTS:: - sage: F = (ZZ^3).construction()[0] # optional - sage.modules + sage: F = (ZZ^3).construction()[0] # needs sage.modules sage: P. = ZZ[] sage: f = P.hom([x + 2*y, 3*x - y], P) - sage: F(f) # indirect doctest # optional - sage.modules + sage: F(f) # indirect doctest # needs sage.modules Traceback (most recent call last): ... NotImplementedError: Cannot create induced morphisms of free modules yet @@ -2007,14 +2015,15 @@ def __eq__(self, other): TESTS:: + sage: # needs sage.modules sage: from sage.categories.pushout import VectorFunctor - sage: F1 = VectorFunctor(3, inner_product_matrix=Matrix(3, 3, range(9))) # optional - sage.modules - sage: F2 = (ZZ^3).construction()[0] # optional - sage.modules - sage: F1 == F2 # optional - sage.modules + sage: F1 = VectorFunctor(3, inner_product_matrix=Matrix(3, 3, range(9))) + sage: F2 = (ZZ^3).construction()[0] + sage: F1 == F2 False - sage: F1(QQ) == F2(QQ) # optional - sage.modules + sage: F1(QQ) == F2(QQ) False - sage: F1 == loads(dumps(F1)) # optional - sage.modules + sage: F1 == loads(dumps(F1)) True """ if isinstance(other, VectorFunctor): @@ -2032,14 +2041,15 @@ def __ne__(self, other): EXAMPLES:: + sage: # needs sage.modules sage: from sage.categories.pushout import VectorFunctor - sage: F1 = VectorFunctor(3, inner_product_matrix=Matrix(3, 3, range(9))) # optional - sage.modules - sage: F2 = (ZZ^3).construction()[0] # optional - sage.modules - sage: F1 != F2 # optional - sage.modules + sage: F1 = VectorFunctor(3, inner_product_matrix=Matrix(3, 3, range(9))) + sage: F2 = (ZZ^3).construction()[0] + sage: F1 != F2 True - sage: F1(QQ) != F2(QQ) # optional - sage.modules + sage: F1(QQ) != F2(QQ) True - sage: F1 != loads(dumps(F1)) # optional - sage.modules + sage: F1 != loads(dumps(F1)) False """ return not (self == other) @@ -2055,19 +2065,19 @@ def merge(self, other): Two modules without explicitly given inner product allow coercion:: - sage: M1 = QQ^3 # optional - sage.modules + sage: M1 = QQ^3 # needs sage.modules sage: P. = ZZ[] - sage: M2 = FreeModule(P, 3) # optional - sage.modules - sage: M1([1,1/2,1/3]) + M2([t,t^2+t,3]) # indirect doctest # optional - sage.modules + sage: M2 = FreeModule(P, 3) # needs sage.modules + sage: M1([1,1/2,1/3]) + M2([t,t^2+t,3]) # indirect doctest # needs sage.modules (t + 1, t^2 + t + 1/2, 10/3) If only one summand has an explicit inner product, the result will be provided with it:: - sage: M3 = FreeModule(P, 3, inner_product_matrix=Matrix(3, 3, range(9))) # optional - sage.modules - sage: M1([1,1/2,1/3]) + M3([t,t^2+t,3]) # optional - sage.modules + sage: M3 = FreeModule(P, 3, inner_product_matrix=Matrix(3, 3, range(9))) # needs sage.modules + sage: M1([1,1/2,1/3]) + M3([t,t^2+t,3]) # needs sage.modules (t + 1, t^2 + t + 1/2, 10/3) - sage: (M1([1,1/2,1/3]) + M3([t,t^2+t,3])).parent().inner_product_matrix() # optional - sage.modules + sage: (M1([1,1/2,1/3]) + M3([t,t^2+t,3])).parent().inner_product_matrix() # needs sage.modules [0 1 2] [3 4 5] [6 7 8] @@ -2078,12 +2088,13 @@ def merge(self, other): inner product was *explicitly* requested for ``M4``. It is therefore not possible to coerce with a different inner product:: - sage: M4 = FreeModule(QQ, 3, inner_product_matrix=Matrix(3, 3, 1)) # optional - sage.modules - sage: M4 == M1 # optional - sage.modules + sage: # needs sage.modules + sage: M4 = FreeModule(QQ, 3, inner_product_matrix=Matrix(3, 3, 1)) + sage: M4 == M1 True - sage: M4.inner_product_matrix() == M1.inner_product_matrix() # optional - sage.modules + sage: M4.inner_product_matrix() == M1.inner_product_matrix() True - sage: M4([1,1/2,1/3]) + M3([t,t^2+t,3]) # indirect doctest # optional - sage.modules + sage: M4([1,1/2,1/3]) + M3([t,t^2+t,3]) # indirect doctest Traceback (most recent call last): ... TypeError: unsupported operand parent(s) for +: @@ -2101,16 +2112,17 @@ def merge(self, other): Names are removed when they conflict:: + sage: # needs sage.modules sage: from sage.categories.pushout import VectorFunctor, pushout - sage: M_ZZx = FreeModule(ZZ['x'], 4, with_basis=None, name='M_ZZx') # optional - sage.modules - sage: N_ZZx = FreeModule(ZZ['x'], 4, with_basis=None, name='N_ZZx') # optional - sage.modules - sage: pushout(M_ZZx, QQ) # optional - sage.modules + sage: M_ZZx = FreeModule(ZZ['x'], 4, with_basis=None, name='M_ZZx') + sage: N_ZZx = FreeModule(ZZ['x'], 4, with_basis=None, name='N_ZZx') + sage: pushout(M_ZZx, QQ) Rank-4 free module M_ZZx_base_ext over the Univariate Polynomial Ring in x over Rational Field - sage: pushout(M_ZZx, N_ZZx) # optional - sage.modules + sage: pushout(M_ZZx, N_ZZx) Rank-4 free module over the Univariate Polynomial Ring in x over Integer Ring - sage: pushout(pushout(M_ZZx, N_ZZx), QQ) # optional - sage.modules + sage: pushout(pushout(M_ZZx, N_ZZx), QQ) Rank-4 free module over the Univariate Polynomial Ring in x over Rational Field """ @@ -2182,14 +2194,15 @@ class SubspaceFunctor(ConstructionFunctor): EXAMPLES:: - sage: M = ZZ^3 # optional - sage.modules - sage: S = M.submodule([(1,2,3), (4,5,6)]); S # optional - sage.modules + sage: # needs sage.modules + sage: M = ZZ^3 + sage: S = M.submodule([(1,2,3), (4,5,6)]); S Free module of degree 3 and rank 2 over Integer Ring Echelon basis matrix: [1 2 3] [0 3 6] - sage: F = S.construction()[0] # optional - sage.modules - sage: F(GF(2)^3) # optional - sage.rings.finite_rings sage.modules + sage: F = S.construction()[0] + sage: F(GF(2)^3) Vector space of degree 3 and dimension 2 over Finite Field of size 2 User basis matrix: [1 0 1] @@ -2211,9 +2224,9 @@ def __init__(self, basis): TESTS:: sage: from sage.categories.pushout import SubspaceFunctor - sage: M = ZZ^3 # optional - sage.modules - sage: F = SubspaceFunctor([M([1,2,3]), M([4,5,6])]) # optional - sage.modules - sage: F(GF(5)^3) # optional - sage.rings.finite_rings sage.modules + sage: M = ZZ^3 # needs sage.modules + sage: F = SubspaceFunctor([M([1,2,3]), M([4,5,6])]) # needs sage.modules + sage: F(GF(5)^3) # needs sage.modules Vector space of degree 3 and dimension 2 over Finite Field of size 5 User basis matrix: [1 2 3] @@ -2233,14 +2246,15 @@ def _apply_functor(self, ambient): TESTS:: - sage: M = ZZ^3 # optional - sage.modules - sage: S = M.submodule([(1,2,3), (4,5,6)]); S # optional - sage.modules + sage: # needs sage.modules + sage: M = ZZ^3 + sage: S = M.submodule([(1,2,3), (4,5,6)]); S Free module of degree 3 and rank 2 over Integer Ring Echelon basis matrix: [1 2 3] [0 3 6] - sage: F = S.construction()[0] # optional - sage.modules - sage: F(GF(2)^3) # indirect doctest # optional - sage.rings.finite_rings sage.modules + sage: F = S.construction()[0] + sage: F(GF(2)^3) # indirect doctest Vector space of degree 3 and dimension 2 over Finite Field of size 2 User basis matrix: [1 0 1] @@ -2254,10 +2268,11 @@ def _apply_functor_to_morphism(self, f): TESTS:: - sage: F = (ZZ^3).span([(1,2,3), (4,5,6)]).construction()[0] # optional - sage.modules - sage: P. = ZZ[] # optional - sage.modules - sage: f = P.hom([x + 2*y, 3*x - y],P) # optional - sage.modules - sage: F(f) # indirect doctest # optional - sage.modules + sage: # needs sage.modules + sage: F = (ZZ^3).span([(1,2,3), (4,5,6)]).construction()[0] + sage: P. = ZZ[] + sage: f = P.hom([x + 2*y, 3*x - y],P) + sage: F(f) # indirect doctest Traceback (most recent call last): ... NotImplementedError: Cannot create morphisms of free sub-modules yet @@ -2268,32 +2283,34 @@ def __eq__(self, other): """ TESTS:: - sage: F1 = (GF(5)^3).span([(1,2,3),(4,5,6)]).construction()[0] # optional - sage.modules sage.rings.finite_rings - sage: F2 = (ZZ^3).span([(1,2,3),(4,5,6)]).construction()[0] # optional - sage.modules - sage: F3 = (QQ^3).span([(1,2,3),(4,5,6)]).construction()[0] # optional - sage.modules - sage: F4 = (ZZ^3).span([(1,0,-1),(0,1,2)]).construction()[0] # optional - sage.modules - sage: F1 == loads(dumps(F1)) # optional - sage.modules sage.rings.finite_rings + sage: # needs sage.modules + sage: F1 = (GF(5)^3).span([(1,2,3),(4,5,6)]).construction()[0] + sage: F2 = (ZZ^3).span([(1,2,3),(4,5,6)]).construction()[0] + sage: F3 = (QQ^3).span([(1,2,3),(4,5,6)]).construction()[0] + sage: F4 = (ZZ^3).span([(1,0,-1),(0,1,2)]).construction()[0] + sage: F1 == loads(dumps(F1)) True The ``span`` method automatically transforms the given basis into echelon form. The bases look like that:: - sage: F1.basis # optional - sage.modules sage.rings.finite_rings + sage: # needs sage.modules + sage: F1.basis [ (1, 0, 4), (0, 1, 2) ] - sage: F2.basis # optional - sage.modules + sage: F2.basis [ (1, 2, 3), (0, 3, 6) ] - sage: F3.basis # optional - sage.modules + sage: F3.basis [ (1, 0, -1), (0, 1, 2) ] - sage: F4.basis # optional - sage.modules + sage: F4.basis [ (1, 0, -1), (0, 1, 2) @@ -2303,18 +2320,18 @@ def __eq__(self, other): The basis of ``F2`` is modulo 5 different from the other bases. So, we have:: - sage: F1 != F2 != F3 # optional - sage.modules sage.rings.finite_rings + sage: F1 != F2 != F3 # needs sage.modules True The bases of ``F1``, ``F3`` and ``F4`` are the same modulo 5; however, there is no coercion from ``QQ^3`` to ``GF(5)^3``. Therefore, we have:: - sage: F1 == F3 # optional - sage.modules sage.rings.finite_rings + sage: F1 == F3 # needs sage.modules False But there are coercions from ``ZZ^3`` to ``QQ^3`` and ``GF(5)^3``, thus:: - sage: F1 == F4 == F3 # optional - sage.modules sage.rings.finite_rings + sage: F1 == F4 == F3 # needs sage.modules True """ @@ -2340,8 +2357,8 @@ def __ne__(self, other): EXAMPLES:: - sage: F1 = (GF(5)^3).span([(1,2,3),(4,5,6)]).construction()[0] # optional - sage.modules sage.rings.finite_rings - sage: F1 != loads(dumps(F1)) # optional - sage.modules sage.rings.finite_rings + sage: F1 = (GF(5)^3).span([(1,2,3),(4,5,6)]).construction()[0] # needs sage.modules + sage: F1 != loads(dumps(F1)) # needs sage.modules False """ return not (self == other) @@ -2354,16 +2371,17 @@ def merge(self, other): EXAMPLES:: - sage: M = GF(5)^3 # optional - sage.modules sage.rings.finite_rings - sage: S1 = M.submodule([(1,2,3),(4,5,6)]) # optional - sage.modules sage.rings.finite_rings - sage: S2 = M.submodule([(2,2,3)]) # optional - sage.modules sage.rings.finite_rings - sage: F1 = S1.construction()[0] # optional - sage.modules sage.rings.finite_rings - sage: F2 = S2.construction()[0] # optional - sage.modules sage.rings.finite_rings - sage: F1.merge(F2) # optional - sage.modules sage.rings.finite_rings + sage: # needs sage.modules + sage: M = GF(5)^3 + sage: S1 = M.submodule([(1,2,3),(4,5,6)]) + sage: S2 = M.submodule([(2,2,3)]) + sage: F1 = S1.construction()[0] + sage: F2 = S2.construction()[0] + sage: F1.merge(F2) SubspaceFunctor - sage: F1.merge(F2)(GF(5)^3) == S1 + S2 # optional - sage.modules sage.rings.finite_rings + sage: F1.merge(F2)(GF(5)^3) == S1 + S2 True - sage: F1.merge(F2)(GF(5)['t']^3) # optional - sage.modules sage.rings.finite_rings + sage: F1.merge(F2)(GF(5)['t']^3) Free module of degree 3 and rank 3 over Univariate Polynomial Ring in t over Finite Field of size 5 User basis matrix: @@ -2373,12 +2391,13 @@ def merge(self, other): TESTS:: + sage: # needs sage.modules sage: P. = ZZ[] - sage: S1 = (ZZ^3).submodule([(1,2,3), (4,5,6)]) # optional - sage.modules - sage: S2 = (Frac(P)^3).submodule([(t,t^2,t^3+1), (4*t,0,1)]) # optional - sage.modules - sage: v = S1([0,3,6]) + S2([2,0,1/(2*t)]); v # indirect doctest # optional - sage.modules + sage: S1 = (ZZ^3).submodule([(1,2,3), (4,5,6)]) + sage: S2 = (Frac(P)^3).submodule([(t,t^2,t^3+1), (4*t,0,1)]) + sage: v = S1([0,3,6]) + S2([2,0,1/(2*t)]); v # indirect doctest (2, 3, (-12*t - 1)/(-2*t)) - sage: v.parent() # optional - sage.modules + sage: v.parent() Vector space of degree 3 and dimension 3 over Fraction Field of Univariate Polynomial Ring in t over Integer Ring User basis matrix: @@ -2425,7 +2444,7 @@ class FractionField(ConstructionFunctor): Category of integral domains sage: F.codomain() Category of fields - sage: F(GF(5)) is GF(5) # optional - sage.rings.finite_rings + sage: F(GF(5)) is GF(5) True sage: F(ZZ['t']) Fraction Field of Univariate Polynomial Ring in t over Integer Ring @@ -2466,7 +2485,7 @@ def _apply_functor(self, R): TESTS:: sage: F = QQ.construction()[0] - sage: F(GF(5)['t']) # indirect doctest # optional - sage.rings.finite_rings + sage: F(GF(5)['t']) # indirect doctest Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 5 """ @@ -2479,36 +2498,40 @@ class CompletionFunctor(ConstructionFunctor): EXAMPLES:: - sage: R = Zp(5) # optional - sage.rings.padics - sage: R # optional - sage.rings.padics + sage: # needs sage.rings.padics + sage: R = Zp(5) + sage: R 5-adic Ring with capped relative precision 20 - sage: F1 = R.construction()[0] # optional - sage.rings.padics - sage: F1 # optional - sage.rings.padics + sage: F1 = R.construction()[0] + sage: F1 Completion[5, prec=20] - sage: F1(ZZ) is R # optional - sage.rings.padics + sage: F1(ZZ) is R True - sage: F1(QQ) # optional - sage.rings.padics + sage: F1(QQ) 5-adic Field with capped relative precision 20 + sage: F2 = RR.construction()[0] sage: F2 Completion[+Infinity, prec=53] sage: F2(QQ) is RR True + sage: P. = ZZ[] sage: Px = P.completion(x) # currently the only implemented completion of P sage: Px Power Series Ring in x over Integer Ring sage: F3 = Px.construction()[0] - sage: F3(GF(3)['x']) # optional - sage.rings.finite_rings + sage: F3(GF(3)['x']) Power Series Ring in x over Finite Field of size 3 TESTS:: - sage: R1. = Zp(5, prec=20)[] # optional - sage.rings.padics - sage: R2 = Qp(5, prec=40) # optional - sage.rings.padics - sage: R2(1) + a # optional - sage.rings.padics + sage: # needs sage.rings.padics + sage: R1. = Zp(5, prec=20)[] + sage: R2 = Qp(5, prec=40) + sage: R2(1) + a (1 + O(5^20))*a + 1 + O(5^40) - sage: 1/2 + a # optional - sage.rings.padics + sage: 1/2 + a (1 + O(5^20))*a + 3 + 2*5 + 2*5^2 + 2*5^3 + 2*5^4 + 2*5^5 + 2*5^6 + 2*5^7 + 2*5^8 + 2*5^9 + 2*5^10 + 2*5^11 + 2*5^12 + 2*5^13 + 2*5^14 + 2*5^15 + 2*5^16 + 2*5^17 + 2*5^18 + 2*5^19 + O(5^20) """ @@ -2539,21 +2562,21 @@ def __init__(self, p, prec, extras=None): TESTS:: sage: from sage.categories.pushout import CompletionFunctor - sage: F1 = CompletionFunctor(5, 100) # optional - sage.rings.padics - sage: F1(QQ) # optional - sage.rings.padics + sage: F1 = CompletionFunctor(5, 100) + sage: F1(QQ) # needs sage.rings.padics 5-adic Field with capped relative precision 100 - sage: F1(ZZ) # optional - sage.rings.padics + sage: F1(ZZ) # needs sage.rings.padics 5-adic Ring with capped relative precision 100 - sage: F1.type is None # optional - sage.rings.padics + sage: F1.type is None True - sage: sorted(F1.extras.items()) # optional - sage.rings.padics + sage: sorted(F1.extras.items()) [] sage: F2 = RR.construction()[0] sage: F2 Completion[+Infinity, prec=53] - sage: F2.type + sage: F2.type # needs sage.rings.real_mpfr 'MPFR' - sage: F2.extras + sage: F2.extras # needs sage.rings.real_mpfr {'rnd': 0, 'sci_not': False} """ Functor.__init__(self, Rings(), Rings()) @@ -2578,7 +2601,7 @@ def _repr_(self): """ TESTS:: - sage: Zp(7).construction() # indirect doctest # optional - sage.rings.padics + sage: Zp(7).construction() # indirect doctest # needs sage.rings.padics (Completion[7, prec=20], Integer Ring) sage: RR.construction() # indirect doctest @@ -2592,11 +2615,12 @@ def _apply_functor(self, R): TESTS:: - sage: R = Zp(5) # optional - sage.rings.padics - sage: F1 = R.construction()[0] # optional - sage.rings.padics - sage: F1(ZZ) is R # indirect doctest # optional - sage.rings.padics + sage: # needs sage.rings.padics + sage: R = Zp(5) + sage: F1 = R.construction()[0] + sage: F1(ZZ) is R # indirect doctest True - sage: F1(QQ) # optional - sage.rings.padics + sage: F1(QQ) 5-adic Field with capped relative precision 20 """ @@ -2635,19 +2659,20 @@ def __eq__(self, other): TESTS:: - sage: R1 = Zp(5, prec=30) # optional - sage.rings.padics - sage: R2 = Zp(5, prec=40) # optional - sage.rings.padics - sage: F1 = R1.construction()[0] # optional - sage.rings.padics - sage: F2 = R2.construction()[0] # optional - sage.rings.padics - sage: F1 == loads(dumps(F1)) # indirect doctest # optional - sage.rings.padics + sage: # needs sage.rings.padics + sage: R1 = Zp(5, prec=30) + sage: R2 = Zp(5, prec=40) + sage: F1 = R1.construction()[0] + sage: F2 = R2.construction()[0] + sage: F1 == loads(dumps(F1)) # indirect doctest True - sage: F1 == F2 # optional - sage.rings.padics + sage: F1 == F2 True - sage: F1(QQ) == F2(QQ) # optional - sage.rings.padics + sage: F1(QQ) == F2(QQ) False - sage: R3 = Zp(7) # optional - sage.rings.padics - sage: F3 = R3.construction()[0] # optional - sage.rings.padics - sage: F1 == F3 # optional - sage.rings.padics + sage: R3 = Zp(7) + sage: F3 = R3.construction()[0] + sage: F1 == F3 False """ if isinstance(other, CompletionFunctor): @@ -2660,19 +2685,20 @@ def __ne__(self, other): EXAMPLES:: - sage: R1 = Zp(5, prec=30) # optional - sage.rings.padics - sage: R2 = Zp(5, prec=40) # optional - sage.rings.padics - sage: F1 = R1.construction()[0] # optional - sage.rings.padics - sage: F2 = R2.construction()[0] # optional - sage.rings.padics - sage: F1 != loads(dumps(F1)) # indirect doctest # optional - sage.rings.padics + sage: # needs sage.rings.padics + sage: R1 = Zp(5, prec=30) + sage: R2 = Zp(5, prec=40) + sage: F1 = R1.construction()[0] + sage: F2 = R2.construction()[0] + sage: F1 != loads(dumps(F1)) # indirect doctest False - sage: F1 != F2 # optional - sage.rings.padics + sage: F1 != F2 False - sage: F1(QQ) != F2(QQ) # optional - sage.rings.padics + sage: F1(QQ) != F2(QQ) True - sage: R3 = Zp(7) # optional - sage.rings.padics - sage: F3 = R3.construction()[0] # optional - sage.rings.padics - sage: F1 != F3 # optional - sage.rings.padics + sage: R3 = Zp(7) + sage: F3 = R3.construction()[0] + sage: F1 != F3 True """ return not (self == other) @@ -2690,22 +2716,23 @@ def merge(self, other): EXAMPLES:: - sage: R1. = Zp(5, prec=20)[] # optional - sage.rings.padics - sage: R2 = Qp(5, prec=40) # optional - sage.rings.padics - sage: R2(1) + a # indirect doctest # optional - sage.rings.padics + sage: # needs sage.rings.padics + sage: R1. = Zp(5, prec=20)[] + sage: R2 = Qp(5, prec=40) + sage: R2(1) + a # indirect doctest (1 + O(5^20))*a + 1 + O(5^40) - sage: R3 = RealField(30) # optional - sage.rings.padics - sage: R4 = RealField(50) # optional - sage.rings.padics - sage: R3(1) + R4(1) # indirect doctest # optional - sage.rings.padics + sage: R3 = RealField(30) + sage: R4 = RealField(50) + sage: R3(1) + R4(1) # indirect doctest 2.0000000 - sage: (R3(1) + R4(1)).parent() # optional - sage.rings.padics + sage: (R3(1) + R4(1)).parent() Real Field with 30 bits of precision TESTS: We check that :trac:`12353` has been resolved:: - sage: RIF(1) > RR(1) + sage: RIF(1) > RR(1) # needs sage.rings.real_interval_field Traceback (most recent call last): ... TypeError: unsupported operand parent(s) for >: @@ -2713,6 +2740,7 @@ def merge(self, other): We check that various pushouts work:: + sage: # needs sage.rings.real_interval_field sage.rings.real_mpfr sage: R0 = RealIntervalField(30) sage: R1 = RealIntervalField(30, sci_not=True) sage: R2 = RealIntervalField(53) @@ -2733,19 +2761,20 @@ def merge(self, other): :: - sage: P0 = ZpFM(5, 10) # optional - sage.rings.padics - sage: P1 = ZpFM(5, 20) # optional - sage.rings.padics - sage: P2 = ZpCR(5, 10) # optional - sage.rings.padics - sage: P3 = ZpCR(5, 20) # optional - sage.rings.padics - sage: P4 = ZpCA(5, 10) # optional - sage.rings.padics - sage: P5 = ZpCA(5, 20) # optional - sage.rings.padics - sage: P6 = Qp(5, 10) # optional - sage.rings.padics - sage: P7 = Qp(5, 20) # optional - sage.rings.padics - sage: Plist = [P2,P3,P4,P5,P6,P7] # optional - sage.rings.padics + sage: # needs sage.rings.padics + sage: P0 = ZpFM(5, 10) + sage: P1 = ZpFM(5, 20) + sage: P2 = ZpCR(5, 10) + sage: P3 = ZpCR(5, 20) + sage: P4 = ZpCA(5, 10) + sage: P5 = ZpCA(5, 20) + sage: P6 = Qp(5, 10) + sage: P7 = Qp(5, 20) + sage: Plist = [P2,P3,P4,P5,P6,P7] sage: from sage.categories.pushout import pushout - sage: pushouts = [P2,P3,P4,P5,P6,P7,P3,P3,P5,P5,P7,P7,P4,P5,P4,P5,P6,P7, # optional - sage.rings.padics + sage: pushouts = [P2,P3,P4,P5,P6,P7,P3,P3,P5,P5,P7,P7,P4,P5,P4,P5,P6,P7, ....: P5,P5,P5,P5,P7,P7,P6,P7,P6,P7,P6,P7,P7,P7,P7,P7,P7,P7] - sage: all(P is Q # optional - sage.rings.padics + sage: all(P is Q ....: for P, Q in zip(pushouts, [pushout(a, b) for a in Plist for b in Plist])) True """ @@ -2788,9 +2817,9 @@ def commutes(self, other): EXAMPLES:: - sage: F1 = Zp(5).construction()[0] # optional - sage.rings.padics + sage: F1 = Zp(5).construction()[0] # needs sage.rings.padics sage: F2 = QQ.construction()[0] - sage: F1.commutes(F2) # optional - sage.rings.padics + sage: F1.commutes(F2) # needs sage.rings.padics True TESTS: @@ -2817,7 +2846,7 @@ def commutes(self, other): Ambiguous base extension error raised):: sage: from sage.categories.pushout import pushout - sage: pushout(Qp(7), RLF) # optional - sage.rings.padics + sage: pushout(Qp(7), RLF) # needs sage.rings.padics Traceback (most recent call last): ... CoercionException: Don't know how to @@ -2840,19 +2869,19 @@ class QuotientFunctor(ConstructionFunctor): EXAMPLES:: sage: P. = ZZ[] - sage: Q = P.quo([x^2 + y^2] * P) # optional - sage.rings.finite_rings - sage: F = Q.construction()[0] # optional - sage.rings.finite_rings - sage: F(QQ['x','y']) # optional - sage.rings.finite_rings + sage: Q = P.quo([x^2 + y^2] * P) + sage: F = Q.construction()[0] + sage: F(QQ['x','y']) Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) - sage: F(QQ['x','y']) == QQ['x','y'].quo([x^2 + y^2] * QQ['x','y']) # optional - sage.rings.finite_rings + sage: F(QQ['x','y']) == QQ['x','y'].quo([x^2 + y^2] * QQ['x','y']) True - sage: F(QQ['x','y','z']) # optional - sage.rings.finite_rings + sage: F(QQ['x','y','z']) Traceback (most recent call last): ... CoercionException: Cannot apply this quotient functor to Multivariate Polynomial Ring in x, y, z over Rational Field - sage: F(QQ['y','z']) # optional - sage.rings.finite_rings + sage: F(QQ['y','z']) # needs sage.rings.finite_rings Traceback (most recent call last): ... TypeError: Could not find a mapping of the passed element to this ring. @@ -2882,24 +2911,24 @@ def __init__(self, I, names=None, as_field=False, domain=None, sage: from sage.categories.pushout import QuotientFunctor sage: P. = ZZ[] sage: F = QuotientFunctor([5 + t^2] * P) - sage: F(P) # optional - sage.rings.finite_rings + sage: F(P) # needs sage.libs.pari Univariate Quotient Polynomial Ring in tbar over Integer Ring with modulus t^2 + 5 - sage: F(QQ['t']) # optional - sage.rings.finite_rings + sage: F(QQ['t']) # needs sage.libs.pari Univariate Quotient Polynomial Ring in tbar over Rational Field with modulus t^2 + 5 sage: F = QuotientFunctor([5 + t^2] * P, names='s') - sage: F(P) # optional - sage.rings.finite_rings + sage: F(P) # needs sage.libs.pari Univariate Quotient Polynomial Ring in s over Integer Ring with modulus t^2 + 5 - sage: F(QQ['t']) # optional - sage.rings.finite_rings + sage: F(QQ['t']) # needs sage.libs.pari Univariate Quotient Polynomial Ring in s over Rational Field with modulus t^2 + 5 sage: F = QuotientFunctor([5] * ZZ, as_field=True) - sage: F(ZZ) # optional - sage.rings.finite_rings + sage: F(ZZ) Finite Field of size 5 sage: F = QuotientFunctor([5] * ZZ) - sage: F(ZZ) # optional - sage.rings.finite_rings + sage: F(ZZ) Ring of integers modulo 5 """ @@ -2926,10 +2955,10 @@ def _apply_functor(self, R): TESTS:: sage: P. = ZZ[] - sage: Q = P.quo([2 + x^2, 3*x + y^2]) # optional - sage.rings.finite_rings - sage: F = Q.construction()[0]; F # optional - sage.rings.finite_rings + sage: Q = P.quo([2 + x^2, 3*x + y^2]) + sage: F = Q.construction()[0]; F QuotientFunctor - sage: F(QQ['x','y']) # indirect doctest # optional - sage.rings.finite_rings + sage: F(QQ['x','y']) # indirect doctest Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + 2, y^2 + 3*x) @@ -2973,15 +3002,16 @@ def __eq__(self, other): TESTS:: + sage: # needs sage.libs.pari sage: P. = QQ[] - sage: F = P.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] # optional - sage.rings.finite_rings - sage: F == loads(dumps(F)) # optional - sage.rings.finite_rings + sage: F = P.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] + sage: F == loads(dumps(F)) True sage: P2. = QQ[] - sage: F == P2.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] # optional - sage.rings.finite_rings + sage: F == P2.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] False sage: P3. = ZZ[] - sage: F == P3.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] # optional - sage.rings.finite_rings + sage: F == P3.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] True """ if not isinstance(other, QuotientFunctor): @@ -2998,15 +3028,16 @@ def __ne__(self, other): EXAMPLES:: + sage: # needs sage.libs.pari sage: P. = QQ[] - sage: F = P.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] # optional - sage.rings.finite_rings - sage: F != loads(dumps(F)) # optional - sage.rings.finite_rings + sage: F = P.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] + sage: F != loads(dumps(F)) False sage: P2. = QQ[] - sage: F != P2.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] # optional - sage.rings.finite_rings + sage: F != P2.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] True sage: P3. = ZZ[] - sage: F != P3.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] # optional - sage.rings.finite_rings + sage: F != P3.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] False """ return not (self == other) @@ -3024,17 +3055,18 @@ def merge(self, other): EXAMPLES:: + sage: # needs sage.libs.pari sage: P. = QQ[] - sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) # optional - sage.rings.finite_rings - sage: Q2 = P.quo([(x^2+1)^2*(x^5+3)]) # optional - sage.rings.finite_rings + sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) + sage: Q2 = P.quo([(x^2+1)^2*(x^5+3)]) sage: from sage.categories.pushout import pushout - sage: pushout(Q1,Q2) # indirect doctest # optional - sage.rings.finite_rings + sage: pushout(Q1,Q2) # indirect doctest Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^4 + 2*x^2 + 1 The following was fixed in :trac:`8800`:: - sage: pushout(GF(5), Integers(5)) # optional - sage.rings.finite_rings + sage: pushout(GF(5), Integers(5)) # needs sage.libs.pari Finite Field of size 5 """ @@ -3094,9 +3126,9 @@ class AlgebraicExtensionFunctor(ConstructionFunctor): EXAMPLES:: sage: x = polygen(QQ, 'x') - sage: K. = NumberField(x^3 + x^2 + 1) # optional - sage.rings.number_field - sage: F = K.construction()[0] # optional - sage.rings.number_field - sage: F(ZZ['t']) # optional - sage.rings.number_field + sage: K. = NumberField(x^3 + x^2 + 1) # needs sage.rings.number_field + sage: F = K.construction()[0] # needs sage.rings.number_field + sage: F(ZZ['t']) # needs sage.rings.number_field Univariate Quotient Polynomial Ring in a over Univariate Polynomial Ring in t over Integer Ring with modulus a^3 + a^2 + 1 @@ -3105,11 +3137,11 @@ class AlgebraicExtensionFunctor(ConstructionFunctor): extension will be constructed as the quotient of a univariate polynomial ring:: - sage: F(CC) # optional - sage.rings.number_field + sage: F(CC) # needs sage.rings.number_field Univariate Quotient Polynomial Ring in a over Complex Field with 53 bits of precision with modulus a^3 + a^2 + 1.00000000000000 - sage: F(RR) # optional - sage.rings.number_field + sage: F(RR) # needs sage.rings.number_field Univariate Quotient Polynomial Ring in a over Real Field with 53 bits of precision with modulus a^3 + a^2 + 1.00000000000000 @@ -3118,48 +3150,51 @@ class AlgebraicExtensionFunctor(ConstructionFunctor): the integers returns an order (not necessarily maximal) of that field, similar to the behaviour of ``ZZ.extension(...)``:: - sage: F(ZZ) # optional - sage.rings.number_field + sage: F(ZZ) # needs sage.rings.number_field Order in Number Field in a with defining polynomial x^3 + x^2 + 1 This also holds for non-absolute number fields:: + sage: # needs sage.rings.number_field sage: x = polygen(QQ, 'x') - sage: K. = NumberField([x^3 + x^2 + 1, x^2 + x + 1]) # optional - sage.rings.number_field - sage: F = K.construction()[0] # optional - sage.rings.number_field - sage: O = F(ZZ); O # optional - sage.rings.number_field + sage: K. = NumberField([x^3 + x^2 + 1, x^2 + x + 1]) + sage: F = K.construction()[0] + sage: O = F(ZZ); O Relative Order in Number Field in a with defining polynomial x^3 + x^2 + 1 over its base field - sage: O.ambient() is K # optional - sage.rings.number_field + sage: O.ambient() is K True Special cases are made for cyclotomic fields and residue fields:: - sage: C = CyclotomicField(8) # optional - sage.rings.number_field - sage: F, R = C.construction() # optional - sage.rings.number_field - sage: F # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + sage: C = CyclotomicField(8) + sage: F, R = C.construction() + sage: F AlgebraicExtensionFunctor - sage: R # optional - sage.rings.number_field + sage: R Rational Field - sage: F(R) # optional - sage.rings.number_field + sage: F(R) Cyclotomic Field of order 8 and degree 4 - sage: F(ZZ) # optional - sage.rings.number_field + sage: F(ZZ) Maximal Order in Cyclotomic Field of order 8 and degree 4 :: - sage: K. = CyclotomicField(7) # optional - sage.rings.number_field - sage: P = K.factor(17)[0][0] # optional - sage.rings.number_field - sage: k = K.residue_field(P) # optional - sage.rings.number_field - sage: F, R = k.construction() # optional - sage.rings.number_field - sage: F # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + sage: K. = CyclotomicField(7) + sage: P = K.factor(17)[0][0] + sage: k = K.residue_field(P) + sage: F, R = k.construction() + sage: F AlgebraicExtensionFunctor - sage: R # optional - sage.rings.number_field + sage: R Cyclotomic Field of order 7 and degree 6 - sage: F(R) is k # optional - sage.rings.number_field + sage: F(R) is k True - sage: F(ZZ) # optional - sage.rings.number_field + sage: F(ZZ) Residue field of Integers modulo 17 - sage: F(CyclotomicField(49)) # optional - sage.rings.number_field + sage: F(CyclotomicField(49)) Residue field in zbar of Fractional ideal (17) """ @@ -3221,25 +3256,25 @@ def __init__(self, polys, names, embeddings=None, structures=None, sage: from sage.categories.pushout import AlgebraicExtensionFunctor sage: P. = ZZ[] - sage: F1 = AlgebraicExtensionFunctor([x^3 - x^2 + 1], ['a'], [None]) # optional - sage.rings.number_field - sage: F2 = AlgebraicExtensionFunctor([x^3 - x^2 + 1], ['a'], [0]) # optional - sage.rings.number_field - sage: F1 == F2 # optional - sage.rings.number_field + sage: F1 = AlgebraicExtensionFunctor([x^3 - x^2 + 1], ['a'], [None]) + sage: F2 = AlgebraicExtensionFunctor([x^3 - x^2 + 1], ['a'], [0]) + sage: F1 == F2 False - sage: F1(QQ) # optional - sage.rings.number_field + sage: F1(QQ) # needs sage.rings.number_field Number Field in a with defining polynomial x^3 - x^2 + 1 - sage: F1(QQ).coerce_embedding() # optional - sage.rings.number_field - sage: phi = F2(QQ).coerce_embedding().__copy__(); phi # optional - sage.rings.number_field + sage: F1(QQ).coerce_embedding() # needs sage.rings.number_field + sage: phi = F2(QQ).coerce_embedding().__copy__(); phi # needs sage.rings.number_field Generic morphism: From: Number Field in a with defining polynomial x^3 - x^2 + 1 with a = -0.7548776662466928? To: Real Lazy Field Defn: a -> -0.7548776662466928? - sage: F1(QQ) == F2(QQ) # optional - sage.rings.number_field + sage: F1(QQ) == F2(QQ) # needs sage.rings.number_field False - sage: F1(GF(5)) # optional - sage.rings.finite_rings sage.rings.number_field + sage: F1(GF(5)) # needs sage.libs.pari Univariate Quotient Polynomial Ring in a over Finite Field of size 5 with modulus a^3 + 4*a^2 + 1 - sage: F2(GF(5)) # optional - sage.rings.finite_rings sage.rings.number_field + sage: F2(GF(5)) # needs sage.libs.pari Traceback (most recent call last): ... NotImplementedError: ring extension with prescribed embedding is not implemented @@ -3248,38 +3283,40 @@ def __init__(self, polys, names, embeddings=None, structures=None, integers, an order (not necessarily maximal) of that field is returned, similar to the behaviour of ``ZZ.extension``:: - sage: F1(ZZ) # optional - sage.rings.number_field + sage: F1(ZZ) # needs sage.rings.number_field Order in Number Field in a with defining polynomial x^3 - x^2 + 1 The cyclotomic fields form a special case of number fields with prescribed embeddings:: - sage: C = CyclotomicField(8) # optional - sage.rings.number_field - sage: F, R = C.construction() # optional - sage.rings.number_field - sage: F # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + sage: C = CyclotomicField(8) + sage: F, R = C.construction() + sage: F AlgebraicExtensionFunctor - sage: R # optional - sage.rings.number_field + sage: R Rational Field - sage: F(R) # optional - sage.rings.number_field + sage: F(R) Cyclotomic Field of order 8 and degree 4 - sage: F(ZZ) # optional - sage.rings.number_field + sage: F(ZZ) Maximal Order in Cyclotomic Field of order 8 and degree 4 The data stored in this construction includes structural morphisms of number fields (see :trac:`20826`):: + sage: # needs sage.rings.number_field sage: R. = ZZ[] - sage: K. = NumberField(x^2 - 3) # optional - sage.rings.number_field - sage: L0. = K.change_names() # optional - sage.rings.number_field - sage: L0.structure() # optional - sage.rings.number_field + sage: K. = NumberField(x^2 - 3) + sage: L0. = K.change_names() + sage: L0.structure() (Isomorphism given by variable name change map: From: Number Field in b with defining polynomial x^2 - 3 To: Number Field in a with defining polynomial x^2 - 3, Isomorphism given by variable name change map: From: Number Field in a with defining polynomial x^2 - 3 To: Number Field in b with defining polynomial x^2 - 3) - sage: L1 = (b*x).parent().base_ring() # optional - sage.rings.number_field - sage: L1 is L0 # optional - sage.rings.number_field + sage: L1 = (b*x).parent().base_ring() + sage: L1 is L0 True """ Functor.__init__(self, Rings(), Rings()) @@ -3322,25 +3359,27 @@ def _apply_functor(self, R): TESTS:: + sage: # needs sage.rings.number_field sage: x = polygen(QQ, 'x') - sage: K. = NumberField(x^3 + x^2 + 1) # optional - sage.rings.number_field - sage: F = K.construction()[0] # optional - sage.rings.number_field - sage: F(ZZ) # indirect doctest # optional - sage.rings.number_field + sage: K. = NumberField(x^3 + x^2 + 1) + sage: F = K.construction()[0] + sage: F(ZZ) # indirect doctest Order in Number Field in a with defining polynomial x^3 + x^2 + 1 - sage: F(ZZ['t']) # indirect doctest # optional - sage.rings.number_field + sage: F(ZZ['t']) # indirect doctest Univariate Quotient Polynomial Ring in a over Univariate Polynomial Ring in t over Integer Ring with modulus a^3 + a^2 + 1 - sage: F(RR) # indirect doctest # optional - sage.rings.number_field + sage: F(RR) # indirect doctest Univariate Quotient Polynomial Ring in a over Real Field with 53 bits of precision with modulus a^3 + a^2 + 1.00000000000000 Check that :trac:`13538` is fixed:: + sage: # needs sage.rings.padics sage: from sage.categories.pushout import AlgebraicExtensionFunctor - sage: K = Qp(3, 3) # optional - sage.rings.padics - sage: R. = K[] # optional - sage.rings.padics - sage: AEF = AlgebraicExtensionFunctor([a^2 - 3], ['a'], [None]) # optional - sage.rings.padics - sage: AEF(K) # optional - sage.rings.padics + sage: K = Qp(3, 3) + sage: R. = K[] + sage: AEF = AlgebraicExtensionFunctor([a^2 - 3], ['a'], [None]) + sage: AEF(K) 3-adic Eisenstein Extension Field in a defined by a^2 - 3 """ @@ -3370,20 +3409,21 @@ def __eq__(self, other): TESTS:: + sage: # needs sage.rings.number_field sage: x = polygen(QQ, 'x') - sage: K. = NumberField(x^3 + x^2 + 1) # optional - sage.rings.number_field - sage: F = K.construction()[0] # optional - sage.rings.number_field - sage: F == loads(dumps(F)) # optional - sage.rings.number_field + sage: K. = NumberField(x^3 + x^2 + 1) + sage: F = K.construction()[0] + sage: F == loads(dumps(F)) True - sage: K2. = NumberField(x^3 + x^2 + 1, latex_names='a') # optional - sage.rings.number_field - sage: F2 = K2.construction()[0] # optional - sage.rings.number_field - sage: F2 == F # optional - sage.rings.number_field + sage: K2. = NumberField(x^3 + x^2 + 1, latex_names='a') # needs sage.rings.number_field + sage: F2 = K2.construction()[0] # needs sage.rings.number_field + sage: F2 == F # needs sage.rings.number_field True - sage: K3. = NumberField(x^3 + x^2 + 1, latex_names='alpha') # optional - sage.rings.number_field - sage: F3 = K3.construction()[0] # optional - sage.rings.number_field - sage: F3 == F # optional - sage.rings.number_field + sage: K3. = NumberField(x^3 + x^2 + 1, latex_names='alpha') # needs sage.rings.number_field + sage: F3 = K3.construction()[0] # needs sage.rings.number_field + sage: F3 == F # needs sage.rings.number_field False """ if not isinstance(other, AlgebraicExtensionFunctor): @@ -3402,9 +3442,9 @@ def __ne__(self, other): EXAMPLES:: sage: x = polygen(QQ, 'x') - sage: K. = NumberField(x^3 + x^2 + 1) # optional - sage.rings.number_field - sage: F = K.construction()[0] # optional - sage.rings.number_field - sage: F != loads(dumps(F)) # optional - sage.rings.number_field + sage: K. = NumberField(x^3 + x^2 + 1) # needs sage.rings.number_field + sage: F = K.construction()[0] # needs sage.rings.number_field + sage: F != loads(dumps(F)) # needs sage.rings.number_field False """ return not (self == other) @@ -3448,36 +3488,38 @@ def merge(self, other): The following demonstrate coercions for finite fields using Conway or pseudo-Conway polynomials:: - sage: k = GF(3^2, prefix='z'); a = k.gen() # optional - sage.rings.finite_rings - sage: l = GF(3^3, prefix='z'); b = l.gen() # optional - sage.rings.finite_rings - sage: a + b # indirect doctest # optional - sage.rings.finite_rings + sage: k = GF(3^2, prefix='z'); a = k.gen() # needs sage.rings.finite_rings + sage: l = GF(3^3, prefix='z'); b = l.gen() # needs sage.rings.finite_rings + sage: a + b # indirect doctest # needs sage.rings.finite_rings z6^5 + 2*z6^4 + 2*z6^3 + z6^2 + 2*z6 + 1 Note that embeddings are compatible in lattices of such finite fields:: - sage: m = GF(3^5, prefix='z'); c = m.gen() # optional - sage.rings.finite_rings - sage: (a + b) + c == a + (b + c) # indirect doctest # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: m = GF(3^5, prefix='z'); c = m.gen() + sage: (a + b) + c == a + (b + c) # indirect doctest True sage: from sage.categories.pushout import pushout - sage: n = pushout(k, l) # optional - sage.rings.finite_rings - sage: o = pushout(l, m) # optional - sage.rings.finite_rings - sage: q = pushout(n, o) # optional - sage.rings.finite_rings - sage: q(o(b)) == q(n(b)) # indirect doctest # optional - sage.rings.finite_rings + sage: n = pushout(k, l) + sage: o = pushout(l, m) + sage: q = pushout(n, o) + sage: q(o(b)) == q(n(b)) # indirect doctest True Coercion is also available for number fields:: - sage: P. = QQ[] # optional - sage.rings.number_field - sage: L. = NumberField(x^8 - x^4 + 1, embedding=CDF.0) # optional - sage.rings.number_field - sage: M1. = NumberField(x^2 + x + 1, embedding=b^4 - 1) # optional - sage.rings.number_field - sage: M2. = NumberField(x^2 + 1, embedding=-b^6) # optional - sage.rings.number_field - sage: M1.coerce_map_from(M2) # optional - sage.rings.number_field - sage: M2.coerce_map_from(M1) # optional - sage.rings.number_field - sage: c1 + c2; parent(c1 + c2) #indirect doctest # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + sage: P. = QQ[] + sage: L. = NumberField(x^8 - x^4 + 1, embedding=CDF.0) + sage: M1. = NumberField(x^2 + x + 1, embedding=b^4 - 1) + sage: M2. = NumberField(x^2 + 1, embedding=-b^6) + sage: M1.coerce_map_from(M2) + sage: M2.coerce_map_from(M1) + sage: c1 + c2; parent(c1 + c2) #indirect doctest -b^6 + b^4 - 1 Number Field in b with defining polynomial x^8 - x^4 + 1 with b = -0.2588190451025208? + 0.9659258262890683?*I - sage: pushout(M1['x'], M2['x']) # optional - sage.rings.number_field + sage: pushout(M1['x'], M2['x']) # needs sage.rings.finite_rings Univariate Polynomial Ring in x over Number Field in b with defining polynomial x^8 - x^4 + 1 with b = -0.2588190451025208? + 0.9659258262890683?*I @@ -3488,13 +3530,14 @@ def merge(self, other): are embedded into a field that is not a numberfield, no merging occurs:: + sage: # needs sage.rings.complex_double sage.rings.number_field sage: cbrt2 = CDF(2)^(1/3) sage: zeta3 = CDF.zeta(3) - sage: K. = NumberField(x^3 - 2, embedding=cbrt2 * zeta3) # optional - sage.rings.number_field - sage: L. = NumberField(x^6 - 2, embedding=1.1) # optional - sage.rings.number_field - sage: L.coerce_map_from(K) # optional - sage.rings.number_field - sage: K.coerce_map_from(L) # optional - sage.rings.number_field - sage: pushout(K, L) # optional - sage.rings.number_field + sage: K. = NumberField(x^3 - 2, embedding=cbrt2 * zeta3) + sage: L. = NumberField(x^6 - 2, embedding=1.1) + sage: L.coerce_map_from(K) + sage: K.coerce_map_from(L) + sage: pushout(K, L) # needs sage.rings.finite_rings Traceback (most recent call last): ... CoercionException: ('Ambiguous Base Extension', Number Field in a with @@ -3568,11 +3611,12 @@ def __mul__(self, other): TESTS:: + sage: # needs sage.rings.number_field sage: P. = QQ[] - sage: K. = NumberField(x^3 - 5, embedding=0) # optional - sage.rings.number_field - sage: L. = K.extension(x^2 + a) # optional - sage.rings.number_field - sage: F, R = L.construction() # optional - sage.rings.number_field - sage: prod(F.expand())(R) == L #indirect doctest # optional - sage.rings.number_field + sage: K. = NumberField(x^3 - 5, embedding=0) + sage: L. = K.extension(x^2 + a) + sage: F, R = L.construction() + sage: prod(F.expand())(R) == L #indirect doctest True """ @@ -3600,19 +3644,20 @@ def expand(self): EXAMPLES:: + sage: # needs sage.rings.number_field sage: P. = QQ[] - sage: K. = NumberField(x^3 - 5, embedding=0) # optional - sage.rings.number_field - sage: L. = K.extension(x^2 + a) # optional - sage.rings.number_field - sage: F, R = L.construction() # optional - sage.rings.number_field - sage: prod(F.expand())(R) == L # optional - sage.rings.number_field + sage: K. = NumberField(x^3 - 5, embedding=0) + sage: L. = K.extension(x^2 + a) + sage: F, R = L.construction() + sage: prod(F.expand())(R) == L True - sage: K = NumberField([x^2 - 2, x^2 - 3],'a') # optional - sage.rings.number_field - sage: F, R = K.construction() # optional - sage.rings.number_field - sage: F # optional - sage.rings.number_field + sage: K = NumberField([x^2 - 2, x^2 - 3],'a') + sage: F, R = K.construction() + sage: F AlgebraicExtensionFunctor - sage: L = F.expand(); L # optional - sage.rings.number_field + sage: L = F.expand(); L [AlgebraicExtensionFunctor, AlgebraicExtensionFunctor] - sage: L[-1](QQ) # optional - sage.rings.number_field + sage: L[-1](QQ) Number Field in a1 with defining polynomial x^2 - 3 """ n = len(self.polys) @@ -3631,12 +3676,13 @@ class AlgebraicClosureFunctor(ConstructionFunctor): EXAMPLES:: + sage: # needs sage.rings.complex_double sage.rings.number_field sage: F = CDF.construction()[0] - sage: F(QQ) # optional - sage.rings.number_field + sage: F(QQ) Algebraic Field - sage: F(RR) + sage: F(RR) # needs sage.rings.real_mpfr Complex Field with 53 bits of precision - sage: F(F(QQ)) is F(QQ) # optional - sage.rings.number_field + sage: F(F(QQ)) is F(QQ) True """ @@ -3648,9 +3694,9 @@ def __init__(self): sage: from sage.categories.pushout import AlgebraicClosureFunctor sage: F = AlgebraicClosureFunctor() - sage: F(QQ) # optional - sage.rings.number_field + sage: F(QQ) # needs sage.rings.number_field Algebraic Field - sage: F(RR) + sage: F(RR) # needs sage.rings.real_mpfr Complex Field with 53 bits of precision sage: F == loads(dumps(F)) True @@ -3664,8 +3710,8 @@ def _apply_functor(self, R): TESTS:: - sage: F = CDF.construction()[0] - sage: F(QQ) # indirect doctest # optional - sage.rings.number_field + sage: F = CDF.construction()[0] # needs sage.rings.complex_double + sage: F(QQ) # indirect doctest # needs sage.rings.complex_double sage.rings.number_field Algebraic Field """ try: @@ -3685,10 +3731,10 @@ def merge(self, other): TESTS:: sage: x = polygen(QQ, 'x') - sage: K. = NumberField(x^3 + x^2 + 1) # optional - sage.rings.number_field - sage: CDF.construction()[0].merge(K.construction()[0]) is None # optional - sage.rings.number_field + sage: K. = NumberField(x^3 + x^2 + 1) # needs sage.rings.number_field + sage: CDF.construction()[0].merge(K.construction()[0]) is None # needs sage.rings.number_field True - sage: CDF.construction()[0].merge(CDF.construction()[0]) # optional - sage.rings.number_field + sage: CDF.construction()[0].merge(CDF.construction()[0]) # needs sage.rings.complex_double AlgebraicClosureFunctor """ @@ -3711,7 +3757,7 @@ def __init__(self, gens, domain): EXAMPLES:: sage: from sage.categories.pushout import PermutationGroupFunctor - sage: PF = PermutationGroupFunctor([PermutationGroupElement([(1,2)])], # optional - sage.groups + sage: PF = PermutationGroupFunctor([PermutationGroupElement([(1,2)])], # needs sage.groups ....: [1,2]); PF PermutationGroupFunctor[(1,2)] """ @@ -3723,9 +3769,9 @@ def _repr_(self): """ EXAMPLES:: - sage: P1 = PermutationGroup([[(1,2)]]) # optional - sage.groups - sage: PF, P = P1.construction() # optional - sage.groups - sage: PF # optional - sage.groups + sage: P1 = PermutationGroup([[(1,2)]]) # needs sage.groups + sage: PF, P = P1.construction() # needs sage.groups + sage: PF # needs sage.groups PermutationGroupFunctor[(1,2)] """ return "PermutationGroupFunctor%s" % list(self.gens()) @@ -3734,9 +3780,9 @@ def __call__(self, R): """ EXAMPLES:: - sage: P1 = PermutationGroup([[(1,2)]]) # optional - sage.groups - sage: PF, P = P1.construction() # optional - sage.groups - sage: PF(P) # optional - sage.groups + sage: P1 = PermutationGroup([[(1,2)]]) # needs sage.groups + sage: PF, P = P1.construction() # needs sage.groups + sage: PF(P) # needs sage.groups Permutation Group with generators [(1,2)] """ from sage.groups.perm_gps.permgroup import PermutationGroup @@ -3747,9 +3793,9 @@ def gens(self): """ EXAMPLES:: - sage: P1 = PermutationGroup([[(1,2)]]) # optional - sage.groups - sage: PF, P = P1.construction() # optional - sage.groups - sage: PF.gens() # optional - sage.groups + sage: P1 = PermutationGroup([[(1,2)]]) # needs sage.groups + sage: PF, P = P1.construction() # needs sage.groups + sage: PF.gens() # needs sage.groups ((1,2),) """ return self._gens @@ -3760,11 +3806,12 @@ def merge(self, other): EXAMPLES:: - sage: P1 = PermutationGroup([[(1,2)]]) # optional - sage.groups - sage: PF1, P = P1.construction() # optional - sage.groups - sage: P2 = PermutationGroup([[(1,3)]]) # optional - sage.groups - sage: PF2, P = P2.construction() # optional - sage.groups - sage: PF1.merge(PF2) # optional - sage.groups + sage: # needs sage.groups + sage: P1 = PermutationGroup([[(1,2)]]) + sage: PF1, P = P1.construction() + sage: P2 = PermutationGroup([[(1,3)]]) + sage: PF2, P = P2.construction() + sage: PF1.merge(PF2) PermutationGroupFunctor[(1,2), (1,3)] """ if self.__class__ != other.__class__: @@ -3810,13 +3857,14 @@ class EquivariantSubobjectConstructionFunctor(ConstructionFunctor): column (index 1); the order of the extra element 2 in a permutation determines whether it is a symmetry or an antisymmetry:: - sage: GSym01 = PermutationGroup([[(0,1),(2,),(3,)]]); GSym01 # optional - sage.groups + sage: # needs sage.groups sage.modules + sage: GSym01 = PermutationGroup([[(0,1),(2,),(3,)]]); GSym01 Permutation Group with generators [(0,1)] - sage: GASym01 = PermutationGroup([[(0,1),(2,3)]]); GASym01 # optional - sage.groups + sage: GASym01 = PermutationGroup([[(0,1),(2,3)]]); GASym01 Permutation Group with generators [(0,1)(2,3)] sage: from sage.categories.action import Action sage: from sage.structure.element import Matrix - sage: class TensorIndexAction(Action): # optional - sage.modules + sage: class TensorIndexAction(Action): ....: def _act_(self, g, x): ....: if isinstance(x, Matrix): ....: if g(0) == 1: @@ -3827,40 +3875,40 @@ class EquivariantSubobjectConstructionFunctor(ConstructionFunctor): ....: else: ....: return x ....: raise NotImplementedError - sage: M = matrix([[1, 2], [3, 4]]); M # optional - sage.modules + sage: M = matrix([[1, 2], [3, 4]]); M [1 2] [3 4] - sage: GSym01_action = TensorIndexAction(GSym01, M.parent()) # optional - sage.groups sage.modules - sage: GASym01_action = TensorIndexAction(GASym01, M.parent()) # optional - sage.groups sage.modules - sage: GSym01_action.act(GSym01.0, M) # optional - sage.groups sage.modules + sage: GSym01_action = TensorIndexAction(GSym01, M.parent()) + sage: GASym01_action = TensorIndexAction(GASym01, M.parent()) + sage: GSym01_action.act(GSym01.0, M) [1 3] [2 4] - sage: GASym01_action.act(GASym01.0, M) # optional - sage.groups sage.modules + sage: GASym01_action.act(GASym01.0, M) [-1 -3] [-2 -4] - sage: Sym01 = M.parent().invariant_module(GSym01, action=GSym01_action); Sym01 # optional - sage.groups sage.modules + sage: Sym01 = M.parent().invariant_module(GSym01, action=GSym01_action); Sym01 (Permutation Group with generators [(0,1)])-invariant submodule of Full MatrixSpace of 2 by 2 dense matrices over Integer Ring - sage: list(Sym01.basis()) # optional - sage.groups sage.modules + sage: list(Sym01.basis()) [B[0], B[1], B[2]] - sage: list(Sym01.basis().map(Sym01.lift)) # optional - sage.groups sage.modules + sage: list(Sym01.basis().map(Sym01.lift)) [ [1 0] [0 1] [0 0] [0 0], [1 0], [0 1] ] - sage: ASym01 = M.parent().invariant_module(GASym01, action=GASym01_action) # optional - sage.groups sage.modules - sage: ASym01 # optional - sage.groups sage.modules + sage: ASym01 = M.parent().invariant_module(GASym01, action=GASym01_action) + sage: ASym01 (Permutation Group with generators [(0,1)(2,3)])-invariant submodule of Full MatrixSpace of 2 by 2 dense matrices over Integer Ring - sage: list(ASym01.basis()) # optional - sage.groups sage.modules + sage: list(ASym01.basis()) [B[0]] - sage: list(ASym01.basis().map(ASym01.lift)) # optional - sage.groups sage.modules + sage: list(ASym01.basis().map(ASym01.lift)) [ [ 0 1] [-1 0] ] sage: from sage.categories.pushout import pushout - sage: pushout(Sym01, QQ) # optional - sage.groups sage.modules + sage: pushout(Sym01, QQ) (Permutation Group with generators [(0,1)])-invariant submodule of Full MatrixSpace of 2 by 2 dense matrices over Rational Field """ @@ -3869,12 +3917,13 @@ def __init__(self, S, action=operator.mul, side='left', """ EXAMPLES:: - sage: G = SymmetricGroup(3); G.rename('S3') # optional - sage.groups sage.modules - sage: M = FreeModule(ZZ, [1,2,3], prefix='M'); M.rename('M') # optional - sage.groups sage.modules - sage: action = lambda g, x: M.term(g(x)) # optional - sage.groups sage.modules - sage: I = M.invariant_module(G, action_on_basis=action); I # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: G = SymmetricGroup(3); G.rename('S3') + sage: M = FreeModule(ZZ, [1,2,3], prefix='M'); M.rename('M') + sage: action = lambda g, x: M.term(g(x)) + sage: I = M.invariant_module(G, action_on_basis=action); I (S3)-invariant submodule of M - sage: I.construction() # optional - sage.groups sage.modules + sage: I.construction() (EquivariantSubobjectConstructionFunctor, Representation of S3 indexed by {1, 2, 3} over Integer Ring) """ @@ -3893,13 +3942,13 @@ def _apply_functor(self, X): TESTS:: sage: from sage.categories.pushout import EquivariantSubobjectConstructionFunctor - sage: M2 = MatrixSpace(QQ, 2); M2 # optional - sage.groups sage.modules + sage: M2 = MatrixSpace(QQ, 2); M2 # needs sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: F = EquivariantSubobjectConstructionFunctor(M2, # optional - sage.groups sage.modules + sage: F = EquivariantSubobjectConstructionFunctor(M2, # needs sage.modules ....: operator.mul, 'left', ....: operator.mul, 'right'); F EquivariantSubobjectConstructionFunctor - sage: F(M2) # optional - sage.groups sage.modules + sage: F(M2) # needs sage.modules Traceback (most recent call last): ... NotImplementedError: non-trivial other_action= is not implemented @@ -3918,24 +3967,24 @@ class BlackBoxConstructionFunctor(ConstructionFunctor): EXAMPLES:: sage: from sage.categories.pushout import BlackBoxConstructionFunctor - sage: FG = BlackBoxConstructionFunctor(gap) # optional - sage.libs.gap - sage: FS = BlackBoxConstructionFunctor(singular) # optional - sage.libs.singular - sage: FG # optional - sage.libs.gap + sage: FG = BlackBoxConstructionFunctor(gap) + sage: FS = BlackBoxConstructionFunctor(singular) + sage: FG BlackBoxConstructionFunctor - sage: FG(ZZ) # optional - sage.libs.gap + sage: FG(ZZ) # needs sage.libs.gap Integers - sage: FG(ZZ).parent() # optional - sage.libs.gap + sage: FG(ZZ).parent() # needs sage.libs.gap Gap - sage: FS(QQ['t']) # optional - sage.libs.singular + sage: FS(QQ['t']) # needs sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 1 // block 1 : ordering lp // : names t // block 2 : ordering C - sage: FG == FS # optional - sage.libs.gap sage.libs.singular + sage: FG == FS # needs sage.libs.gap sage.libs.singular False - sage: FG == loads(dumps(FG)) # optional - sage.libs.gap + sage: FG == loads(dumps(FG)) # needs sage.libs.gap True """ rank = 100 @@ -3945,11 +3994,11 @@ def __init__(self, box): TESTS:: sage: from sage.categories.pushout import BlackBoxConstructionFunctor - sage: FG = BlackBoxConstructionFunctor(gap) # optional - sage.libs.gap - sage: FM = BlackBoxConstructionFunctor(maxima) # optional - sage.symbolic - sage: FM == FG # optional - sage.libs.gap sage.symbolic + sage: FG = BlackBoxConstructionFunctor(gap) + sage: FM = BlackBoxConstructionFunctor(maxima) # needs sage.symbolic + sage: FM == FG # needs sage.libs.gap sage.symbolic False - sage: FM == loads(dumps(FM)) # optional - sage.symbolic + sage: FM == loads(dumps(FM)) # needs sage.symbolic True """ ConstructionFunctor.__init__(self, Objects(), Objects()) @@ -3966,7 +4015,7 @@ def _apply_functor(self, R): sage: from sage.categories.pushout import BlackBoxConstructionFunctor sage: f = lambda x: x^2 sage: F = BlackBoxConstructionFunctor(f) - sage: F(ZZ) # indirect doctest # optional - sage.modules + sage: F(ZZ) # indirect doctest # needs sage.modules Ambient free module of rank 2 over the principal ideal domain Integer Ring """ @@ -3977,11 +4026,11 @@ def __eq__(self, other): TESTS:: sage: from sage.categories.pushout import BlackBoxConstructionFunctor - sage: FG = BlackBoxConstructionFunctor(gap) # optional - sage.libs.gap - sage: FM = BlackBoxConstructionFunctor(maxima) # optional - sage.symbolic - sage: FM == FG # indirect doctest # optional - sage.libs.gap sage.symbolic + sage: FG = BlackBoxConstructionFunctor(gap) + sage: FM = BlackBoxConstructionFunctor(maxima) # needs sage.symbolic + sage: FM == FG # indirect doctest # needs sage.libs.gap sage.symbolic False - sage: FM == loads(dumps(FM)) # optional - sage.symbolic + sage: FM == loads(dumps(FM)) # needs sage.symbolic True """ if not isinstance(other, BlackBoxConstructionFunctor): @@ -3996,11 +4045,11 @@ def __ne__(self, other): EXAMPLES:: sage: from sage.categories.pushout import BlackBoxConstructionFunctor - sage: FG = BlackBoxConstructionFunctor(gap) # optional - sage.libs.gap - sage: FM = BlackBoxConstructionFunctor(maxima) # optional - sage.symbolic - sage: FM != FG # indirect doctest # optional - sage.libs.gap sage.symbolic + sage: FG = BlackBoxConstructionFunctor(gap) + sage: FM = BlackBoxConstructionFunctor(maxima) # needs sage.symbolic + sage: FM != FG # indirect doctest # needs sage.libs.gap sage.symbolic True - sage: FM != loads(dumps(FM)) # optional - sage.symbolic + sage: FM != loads(dumps(FM)) # needs sage.symbolic False """ return not (self == other) @@ -4059,17 +4108,17 @@ def pushout(R, S): which give us `Frac(Poly_x(Complete_7(Frac(\ZZ))))`:: sage: from sage.categories.pushout import pushout - sage: pushout(Qp(7), Frac(ZZ['x'])) # optional - sage.rings.padics + sage: pushout(Qp(7), Frac(ZZ['x'])) # needs sage.rings.padics Fraction Field of Univariate Polynomial Ring in x over 7-adic Field with capped relative precision 20 Note we get the same thing with :: - sage: pushout(Zp(7), Frac(QQ['x'])) # optional - sage.rings.padics + sage: pushout(Zp(7), Frac(QQ['x'])) # needs sage.rings.padics Fraction Field of Univariate Polynomial Ring in x over 7-adic Field with capped relative precision 20 - sage: pushout(Zp(7)['x'], Frac(QQ['x'])) # optional - sage.rings.padics + sage: pushout(Zp(7)['x'], Frac(QQ['x'])) # needs sage.rings.padics Fraction Field of Univariate Polynomial Ring in x over 7-adic Field with capped relative precision 20 @@ -4087,17 +4136,17 @@ def pushout(R, S): Some other examples:: - sage: pushout(Zp(7)['y'], Frac(QQ['t'])['x,y,z']) # optional - sage.rings.padics + sage: pushout(Zp(7)['y'], Frac(QQ['t'])['x,y,z']) # needs sage.rings.padics Multivariate Polynomial Ring in x, y, z over Fraction Field of Univariate Polynomial Ring in t over 7-adic Field with capped relative precision 20 sage: pushout(ZZ['x,y,z'], Frac(ZZ['x'])['y']) Multivariate Polynomial Ring in y, z over Fraction Field of Univariate Polynomial Ring in x over Integer Ring - sage: pushout(MatrixSpace(RDF, 2, 2), Frac(ZZ['x'])) # optional - sage.modules + sage: pushout(MatrixSpace(RDF, 2, 2), Frac(ZZ['x'])) # needs sage.modules Full MatrixSpace of 2 by 2 dense matrices over Fraction Field of Univariate Polynomial Ring in x over Real Double Field - sage: pushout(ZZ, MatrixSpace(ZZ[['x']], 3, 3)) # optional - sage.modules + sage: pushout(ZZ, MatrixSpace(ZZ[['x']], 3, 3)) # needs sage.modules Full MatrixSpace of 3 by 3 dense matrices over Power Series Ring in x over Integer Ring sage: pushout(QQ['x,y'], ZZ[['x']]) @@ -4110,20 +4159,22 @@ def pushout(R, S): the :class:`SubspaceFunctor` construction) is only applied if it leads to a valid coercion:: - sage: A = ZZ^2 # optional - sage.modules - sage: V = span([[1, 2]], QQ) # optional - sage.modules - sage: P = sage.categories.pushout.pushout(A, V) # optional - sage.modules - sage: P # optional - sage.modules + sage: # needs sage.modules + sage: A = ZZ^2 + sage: V = span([[1, 2]], QQ) + sage: P = sage.categories.pushout.pushout(A, V) + sage: P Vector space of dimension 2 over Rational Field - sage: P.has_coerce_map_from(A) # optional - sage.modules + sage: P.has_coerce_map_from(A) True - sage: V = (QQ^3).span([[1, 2, 3/4]]) # optional - sage.modules - sage: A = ZZ^3 # optional - sage.modules - sage: pushout(A, V) # optional - sage.modules + sage: # needs sage.modules + sage: V = (QQ^3).span([[1, 2, 3/4]]) + sage: A = ZZ^3 + sage: pushout(A, V) Vector space of dimension 3 over Rational Field - sage: B = A.span([[0, 0, 2/3]]) # optional - sage.modules - sage: pushout(B, V) # optional - sage.modules + sage: B = A.span([[0, 0, 2/3]]) + sage: pushout(B, V) Vector space of degree 3 and dimension 2 over Rational Field User basis matrix: [1 2 0] @@ -4153,26 +4204,26 @@ def pushout(R, S): Even Power Univariate Polynomial Ring in x over Rational Field sage: pushout(EvenPolynomialRing(QQ, 'x'), QQ) Even Power Univariate Polynomial Ring in x over Rational Field - sage: pushout(EvenPolynomialRing(QQ, 'x'), RR) + sage: pushout(EvenPolynomialRing(QQ, 'x'), RR) # needs sage.rings.real_mpfr Even Power Univariate Polynomial Ring in x over Real Field with 53 bits of precision sage: pushout(EvenPolynomialRing(QQ, 'x'), ZZ['x']) Univariate Polynomial Ring in x over Rational Field sage: pushout(EvenPolynomialRing(QQ, 'x'), QQ['x']) Univariate Polynomial Ring in x over Rational Field - sage: pushout(EvenPolynomialRing(QQ, 'x'), RR['x']) + sage: pushout(EvenPolynomialRing(QQ, 'x'), RR['x']) # needs sage.rings.real_mpfr Univariate Polynomial Ring in x over Real Field with 53 bits of precision sage: pushout(EvenPolynomialRing(QQ, 'x'), EvenPolynomialRing(QQ, 'x')) Even Power Univariate Polynomial Ring in x over Rational Field - sage: pushout(EvenPolynomialRing(QQ, 'x'), EvenPolynomialRing(RR, 'x')) + sage: pushout(EvenPolynomialRing(QQ, 'x'), EvenPolynomialRing(RR, 'x')) # needs sage.rings.real_mpfr Even Power Univariate Polynomial Ring in x over Real Field with 53 bits of precision - sage: pushout(EvenPolynomialRing(QQ, 'x')^2, RR^2) # optional - sage.modules + sage: pushout(EvenPolynomialRing(QQ, 'x')^2, RR^2) # needs sage.modules sage.rings.real_mpfr Ambient free module of rank 2 over the principal ideal domain Even Power Univariate Polynomial Ring in x over Real Field with 53 bits of precision - sage: pushout(EvenPolynomialRing(QQ, 'x')^2, RR['x']^2) # optional - sage.modules + sage: pushout(EvenPolynomialRing(QQ, 'x')^2, RR['x']^2) # needs sage.modules sage.rings.real_mpfr Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Real Field with 53 bits of precision @@ -4360,7 +4411,7 @@ def pushout(R, S): (Univariate Polynomial Ring in x over Integer Ring, Univariate Polynomial Ring in y over Integer Ring, Univariate Polynomial Ring in z over Integer Ring) - sage: pushout(CartesianProductPoly((QQ['a,b']['x'], QQ['y'])), # optional - sage.symbolic + sage: pushout(CartesianProductPoly((QQ['a,b']['x'], QQ['y'])), # needs sage.symbolic ....: CartesianProductPoly((ZZ['b,c']['x'], SR['z']))) The Cartesian product of (Univariate Polynomial Ring in x over @@ -4573,14 +4624,14 @@ def pushout_lattice(R, S): EXAMPLES:: sage: from sage.categories.pushout import pushout_lattice - sage: A, B = pushout_lattice(Qp(7), Frac(ZZ['x'])) # optional - sage.rings.padics - sage: A.codomain() # optional - sage.rings.padics + sage: A, B = pushout_lattice(Qp(7), Frac(ZZ['x'])) # needs sage.rings.padics + sage: A.codomain() # needs sage.rings.padics Fraction Field of Univariate Polynomial Ring in x over 7-adic Field with capped relative precision 20 - sage: A.codomain() is B.codomain() # optional - sage.rings.padics + sage: A.codomain() is B.codomain() # needs sage.rings.padics True - sage: A, B = pushout_lattice(ZZ, MatrixSpace(ZZ[['x']], 3, 3)) # optional - sage.modules - sage: B # optional - sage.modules + sage: A, B = pushout_lattice(ZZ, MatrixSpace(ZZ[['x']], 3, 3)) # needs sage.modules + sage: B # needs sage.modules Identity endomorphism of Full MatrixSpace of 3 by 3 dense matrices over Power Series Ring in x over Integer Ring @@ -4751,7 +4802,7 @@ def construction_tower(R): EXAMPLES:: sage: from sage.categories.pushout import construction_tower - sage: construction_tower(MatrixSpace(FractionField(QQ['t']), 2)) # optional - sage.modules + sage: construction_tower(MatrixSpace(FractionField(QQ['t']), 2)) # needs sage.modules [(None, Full MatrixSpace of 2 by 2 dense matrices over Fraction Field of Univariate Polynomial Ring in t over Rational Field), (MatrixFunctor, Fraction Field @@ -4833,7 +4884,7 @@ def type_to_parent(P): Integer Ring sage: type_to_parent(float) Real Double Field - sage: type_to_parent(complex) + sage: type_to_parent(complex) # needs sage.rings.complex_double Complex Double Field sage: type_to_parent(list) Traceback (most recent call last): diff --git a/src/sage/categories/quantum_group_representations.py b/src/sage/categories/quantum_group_representations.py index 08219858ca5..fc8a4697941 100644 --- a/src/sage/categories/quantum_group_representations.py +++ b/src/sage/categories/quantum_group_representations.py @@ -51,7 +51,7 @@ def example(self): sage: from sage.categories.quantum_group_representations import QuantumGroupRepresentations sage: Cat = QuantumGroupRepresentations(ZZ['q'].fraction_field()) - sage: Cat.example() # optional - sage.combinat sage.modules + sage: Cat.example() # needs sage.combinat sage.modules V((2, 1, 0)) """ from sage.algebras.quantum_groups.representations import AdjointRepresentation @@ -96,34 +96,35 @@ def e_on_basis(self, i, b): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import ( # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: from sage.algebras.quantum_groups.representations import ( ....: MinusculeRepresentation, AdjointRepresentation) sage: R = ZZ['q'].fraction_field() - sage: CM = crystals.Tableaux(['D',4], shape=[1]) # optional - sage.combinat sage.modules - sage: VM = MinusculeRepresentation(R, CM) # optional - sage.combinat sage.modules - sage: CA = crystals.Tableaux(['D',4], shape=[1,1]) # optional - sage.combinat sage.modules - sage: VA = AdjointRepresentation(R, CA) # optional - sage.combinat sage.modules - sage: v = tensor([VM.an_element(), VA.an_element()]); v # optional - sage.combinat sage.modules + sage: CM = crystals.Tableaux(['D',4], shape=[1]) + sage: VM = MinusculeRepresentation(R, CM) + sage: CA = crystals.Tableaux(['D',4], shape=[1,1]) + sage: VA = AdjointRepresentation(R, CA) + sage: v = tensor([VM.an_element(), VA.an_element()]); v 4*B[[[1]]] # B[[[1], [2]]] + 4*B[[[1]]] # B[[[1], [3]]] + 6*B[[[1]]] # B[[[2], [3]]] + 4*B[[[2]]] # B[[[1], [2]]] + 4*B[[[2]]] # B[[[1], [3]]] + 6*B[[[2]]] # B[[[2], [3]]] + 6*B[[[3]]] # B[[[1], [2]]] + 6*B[[[3]]] # B[[[1], [3]]] + 9*B[[[3]]] # B[[[2], [3]]] - sage: v.e(1) # indirect doctest # optional - sage.combinat sage.modules + sage: v.e(1) # indirect doctest 4*B[[[1]]] # B[[[1], [2]]] + ((4*q+6)/q)*B[[[1]]] # B[[[1], [3]]] + 6*B[[[1]]] # B[[[2], [3]]] + 6*q*B[[[2]]] # B[[[1], [3]]] + 9*B[[[3]]] # B[[[1], [3]]] - sage: v.e(2) # indirect doctest # optional - sage.combinat sage.modules + sage: v.e(2) # indirect doctest 4*B[[[1]]] # B[[[1], [2]]] + ((6*q+4)/q)*B[[[2]]] # B[[[1], [2]]] + 6*B[[[2]]] # B[[[1], [3]]] + 9*B[[[2]]] # B[[[2], [3]]] + 6*q*B[[[3]]] # B[[[1], [2]]] - sage: v.e(3) # indirect doctest # optional - sage.combinat sage.modules + sage: v.e(3) # indirect doctest 0 - sage: v.e(4) # indirect doctest # optional - sage.combinat sage.modules + sage: v.e(4) # indirect doctest 0 """ K_elt = [self._sets[k].K_on_basis(i, elt, -1) for k,elt in enumerate(b)] @@ -146,38 +147,39 @@ def f_on_basis(self, i, b): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import ( # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: from sage.algebras.quantum_groups.representations import ( ....: MinusculeRepresentation, AdjointRepresentation) sage: R = ZZ['q'].fraction_field() - sage: KM = crystals.KirillovReshetikhin(['B',3,1], 3,1) # optional - sage.combinat sage.modules - sage: VM = MinusculeRepresentation(R, KM) # optional - sage.combinat sage.modules - sage: KA = crystals.KirillovReshetikhin(['B',3,1], 2,1) # optional - sage.combinat sage.modules - sage: VA = AdjointRepresentation(R, KA) # optional - sage.combinat sage.modules - sage: v = tensor([VM.an_element(), VA.an_element()]); v # optional - sage.combinat sage.modules + sage: KM = crystals.KirillovReshetikhin(['B',3,1], 3,1) + sage: VM = MinusculeRepresentation(R, KM) + sage: KA = crystals.KirillovReshetikhin(['B',3,1], 2,1) + sage: VA = AdjointRepresentation(R, KA) + sage: v = tensor([VM.an_element(), VA.an_element()]); v 4*B[[+++, []]] # B[[]] + 4*B[[+++, []]] # B[[[1], [2]]] + 6*B[[+++, []]] # B[[[1], [3]]] + 4*B[[++-, []]] # B[[]] + 4*B[[++-, []]] # B[[[1], [2]]] + 6*B[[++-, []]] # B[[[1], [3]]] + 6*B[[+-+, []]] # B[[]] + 6*B[[+-+, []]] # B[[[1], [2]]] + 9*B[[+-+, []]] # B[[[1], [3]]] - sage: v.f(0) # indirect doctest # optional - sage.combinat sage.modules + sage: v.f(0) # indirect doctest ((4*q^4+4)/q^2)*B[[+++, []]] # B[[[1], [2]]] + ((4*q^4+4)/q^2)*B[[++-, []]] # B[[[1], [2]]] + ((6*q^4+6)/q^2)*B[[+-+, []]] # B[[[1], [2]]] - sage: v.f(1) # indirect doctest # optional - sage.combinat sage.modules + sage: v.f(1) # indirect doctest 6*B[[+++, []]] # B[[[2], [3]]] + 6*B[[++-, []]] # B[[[2], [3]]] + 9*B[[+-+, []]] # B[[[2], [3]]] + 6*B[[-++, []]] # B[[]] + 6*B[[-++, []]] # B[[[1], [2]]] + 9*q^2*B[[-++, []]] # B[[[1], [3]]] - sage: v.f(2) # indirect doctest # optional - sage.combinat sage.modules + sage: v.f(2) # indirect doctest 4*B[[+++, []]] # B[[[1], [3]]] + 4*B[[++-, []]] # B[[[1], [3]]] + 4*B[[+-+, []]] # B[[]] + 4*q^2*B[[+-+, []]] # B[[[1], [2]]] + ((6*q^2+6)/q^2)*B[[+-+, []]] # B[[[1], [3]]] - sage: v.f(3) # indirect doctest # optional - sage.combinat sage.modules + sage: v.f(3) # indirect doctest 6*B[[+++, []]] # B[[[1], [0]]] + 4*B[[++-, []]] # B[[]] + 4*B[[++-, []]] # B[[[1], [2]]] @@ -209,22 +211,23 @@ def K_on_basis(self, i, b, power=1): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import ( # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: from sage.algebras.quantum_groups.representations import ( ....: MinusculeRepresentation, AdjointRepresentation) sage: R = ZZ['q'].fraction_field() - sage: CM = crystals.Tableaux(['A',2], shape=[1]) # optional - sage.combinat sage.modules - sage: VM = MinusculeRepresentation(R, CM) # optional - sage.combinat sage.modules - sage: CA = crystals.Tableaux(['A',2], shape=[2,1]) # optional - sage.combinat sage.modules - sage: VA = AdjointRepresentation(R, CA) # optional - sage.combinat sage.modules - sage: v = tensor([sum(VM.basis()), VA.module_generator()]); v # optional - sage.combinat sage.modules + sage: CM = crystals.Tableaux(['A',2], shape=[1]) + sage: VM = MinusculeRepresentation(R, CM) + sage: CA = crystals.Tableaux(['A',2], shape=[2,1]) + sage: VA = AdjointRepresentation(R, CA) + sage: v = tensor([sum(VM.basis()), VA.module_generator()]); v B[[[1]]] # B[[[1, 1], [2]]] + B[[[2]]] # B[[[1, 1], [2]]] + B[[[3]]] # B[[[1, 1], [2]]] - sage: v.K(1) # indirect doctest # optional - sage.combinat sage.modules + sage: v.K(1) # indirect doctest q^2*B[[[1]]] # B[[[1, 1], [2]]] + B[[[2]]] # B[[[1, 1], [2]]] + q*B[[[3]]] # B[[[1, 1], [2]]] - sage: v.K(2, -1) # indirect doctest # optional - sage.combinat sage.modules + sage: v.K(2, -1) # indirect doctest 1/q*B[[[1]]] # B[[[1, 1], [2]]] + 1/q^2*B[[[2]]] # B[[[1, 1], [2]]] + B[[[3]]] # B[[[1, 1], [2]]] @@ -241,24 +244,25 @@ def tensor(*factors): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import ( # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: from sage.algebras.quantum_groups.representations import ( ....: MinusculeRepresentation, AdjointRepresentation) sage: R = ZZ['q'].fraction_field() - sage: CM = crystals.Tableaux(['D',4], shape=[1]) # optional - sage.combinat sage.modules - sage: CA = crystals.Tableaux(['D',4], shape=[1,1]) # optional - sage.combinat sage.modules - sage: V = MinusculeRepresentation(R, CM) # optional - sage.combinat sage.modules - sage: V.tensor(V, V) # optional - sage.combinat sage.modules + sage: CM = crystals.Tableaux(['D',4], shape=[1]) + sage: CA = crystals.Tableaux(['D',4], shape=[1,1]) + sage: V = MinusculeRepresentation(R, CM) + sage: V.tensor(V, V) V((1, 0, 0, 0)) # V((1, 0, 0, 0)) # V((1, 0, 0, 0)) - sage: A = MinusculeRepresentation(R, CA) # optional - sage.combinat sage.modules - sage: V.tensor(A) # optional - sage.combinat sage.modules + sage: A = MinusculeRepresentation(R, CA) + sage: V.tensor(A) V((1, 0, 0, 0)) # V((1, 1, 0, 0)) - sage: B = crystals.Tableaux(['A',2], shape=[1]) # optional - sage.combinat sage.modules - sage: W = MinusculeRepresentation(R, B) # optional - sage.combinat sage.modules - sage: tensor([W,V]) # optional - sage.combinat sage.modules + sage: B = crystals.Tableaux(['A',2], shape=[1]) + sage: W = MinusculeRepresentation(R, B) + sage: tensor([W,V]) Traceback (most recent call last): ... ValueError: all factors must be of the same Cartan type - sage: tensor([V,A,W]) # optional - sage.combinat sage.modules + sage: tensor([V,A,W]) Traceback (most recent call last): ... ValueError: all factors must be of the same Cartan type @@ -279,15 +283,16 @@ def e(self, i): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import AdjointRepresentation # optional - sage.combinat sage.modules - sage: C = crystals.Tableaux(['G',2], shape=[1,1]) # optional - sage.combinat sage.modules - sage: R = ZZ['q'].fraction_field() # optional - sage.combinat sage.modules - sage: V = AdjointRepresentation(R, C) # optional - sage.combinat sage.modules - sage: v = V.an_element(); v # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: from sage.algebras.quantum_groups.representations import AdjointRepresentation + sage: C = crystals.Tableaux(['G',2], shape=[1,1]) + sage: R = ZZ['q'].fraction_field() + sage: V = AdjointRepresentation(R, C) + sage: v = V.an_element(); v 2*B[[[1], [2]]] + 2*B[[[1], [3]]] + 3*B[[[2], [3]]] - sage: v.e(1) # optional - sage.combinat sage.modules + sage: v.e(1) ((3*q^4+3*q^2+3)/q^2)*B[[[1], [3]]] - sage: v.e(2) # optional - sage.combinat sage.modules + sage: v.e(2) 2*B[[[1], [2]]] """ F = self.parent() @@ -305,21 +310,22 @@ def f(self, i): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import AdjointRepresentation # optional - sage.combinat sage.modules - sage: K = crystals.KirillovReshetikhin(['D',4,1], 2,1) # optional - sage.combinat sage.modules - sage: R = ZZ['q'].fraction_field() # optional - sage.combinat sage.modules - sage: V = AdjointRepresentation(R, K) # optional - sage.combinat sage.modules - sage: v = V.an_element(); v # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: from sage.algebras.quantum_groups.representations import AdjointRepresentation + sage: K = crystals.KirillovReshetikhin(['D',4,1], 2,1) + sage: R = ZZ['q'].fraction_field() + sage: V = AdjointRepresentation(R, K) + sage: v = V.an_element(); v 2*B[[]] + 2*B[[[1], [2]]] + 3*B[[[1], [3]]] - sage: v.f(0) # optional - sage.combinat sage.modules + sage: v.f(0) ((2*q^2+2)/q)*B[[[1], [2]]] - sage: v.f(1) # optional - sage.combinat sage.modules + sage: v.f(1) 3*B[[[2], [3]]] - sage: v.f(2) # optional - sage.combinat sage.modules + sage: v.f(2) 2*B[[[1], [3]]] - sage: v.f(3) # optional - sage.combinat sage.modules + sage: v.f(3) 3*B[[[1], [4]]] - sage: v.f(4) # optional - sage.combinat sage.modules + sage: v.f(4) 3*B[[[1], [-4]]] """ F = self.parent() @@ -338,19 +344,20 @@ def K(self, i, power=1): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import AdjointRepresentation # optional - sage.combinat sage.modules - sage: K = crystals.KirillovReshetikhin(['D',4,2], 1,1) # optional - sage.combinat sage.modules - sage: R = ZZ['q'].fraction_field() # optional - sage.combinat sage.modules - sage: V = AdjointRepresentation(R, K) # optional - sage.combinat sage.modules - sage: v = V.an_element(); v # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: from sage.algebras.quantum_groups.representations import AdjointRepresentation + sage: K = crystals.KirillovReshetikhin(['D',4,2], 1,1) + sage: R = ZZ['q'].fraction_field() + sage: V = AdjointRepresentation(R, K) + sage: v = V.an_element(); v 2*B[[]] + 2*B[[[1]]] + 3*B[[[2]]] - sage: v.K(0) # optional - sage.combinat sage.modules + sage: v.K(0) 2*B[[]] + 2/q^2*B[[[1]]] + 3*B[[[2]]] - sage: v.K(1) # optional - sage.combinat sage.modules + sage: v.K(1) 2*B[[]] + 2*q^2*B[[[1]]] + 3/q^2*B[[[2]]] - sage: v.K(1, 2) # optional - sage.combinat sage.modules + sage: v.K(1, 2) 2*B[[]] + 2*q^4*B[[[1]]] + 3/q^4*B[[[2]]] - sage: v.K(1, -1) # optional - sage.combinat sage.modules + sage: v.K(1, -1) 2*B[[]] + 2/q^2*B[[[1]]] + 3*q^2*B[[[2]]] """ F = self.parent() @@ -388,12 +395,13 @@ def cartan_type(self): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import MinusculeRepresentation # optional - sage.combinat sage.modules - sage: C = crystals.Tableaux(['C',2], shape=[1]) # optional - sage.combinat sage.modules - sage: R = ZZ['q'].fraction_field() # optional - sage.combinat sage.modules - sage: V = MinusculeRepresentation(R, C) # optional - sage.combinat sage.modules - sage: T = tensor([V,V]) # optional - sage.combinat sage.modules - sage: T.cartan_type() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: from sage.algebras.quantum_groups.representations import MinusculeRepresentation + sage: C = crystals.Tableaux(['C',2], shape=[1]) + sage: R = ZZ['q'].fraction_field() + sage: V = MinusculeRepresentation(R, C) + sage: T = tensor([V,V]) + sage: T.cartan_type() ['C', 2] """ return self._sets[0].cartan_type() @@ -407,18 +415,19 @@ def _test_representation(self, tester=None, **options): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import ( # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: from sage.algebras.quantum_groups.representations import ( ....: MinusculeRepresentation, AdjointRepresentation) - sage: C = crystals.Tableaux(['G',2], shape=[1,1]) # optional - sage.combinat sage.modules - sage: R = ZZ['q'].fraction_field() # optional - sage.combinat sage.modules - sage: V = AdjointRepresentation(R, C) # optional - sage.combinat sage.modules - sage: V._test_representation() # optional - sage.combinat sage.modules + sage: C = crystals.Tableaux(['G',2], shape=[1,1]) + sage: R = ZZ['q'].fraction_field() + sage: V = AdjointRepresentation(R, C) + sage: V._test_representation() We verify that ``C`` does not define a minuscule representation:: - sage: M = MinusculeRepresentation(R, C) # optional - sage.combinat sage.modules - sage: M._test_representation() # optional - sage.combinat sage.modules + sage: M = MinusculeRepresentation(R, C) # needs sage.combinat sage.modules + sage: M._test_representation() # needs sage.combinat sage.modules Traceback (most recent call last): ... AssertionError: [e,f] = (K-K^-1)/(q_i-q_i^-1) -- i: 1 j: 1 @@ -489,11 +498,12 @@ def cartan_type(self): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import MinusculeRepresentation # optional - sage.combinat sage.modules - sage: C = crystals.Tableaux(['C',4], shape=[1]) # optional - sage.combinat sage.modules - sage: R = ZZ['q'].fraction_field() # optional - sage.combinat sage.modules - sage: V = MinusculeRepresentation(R, C) # optional - sage.combinat sage.modules - sage: V.cartan_type() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: from sage.algebras.quantum_groups.representations import MinusculeRepresentation + sage: C = crystals.Tableaux(['C',4], shape=[1]) + sage: R = ZZ['q'].fraction_field() + sage: V = MinusculeRepresentation(R, C) + sage: V.cartan_type() ['C', 4] """ @@ -504,11 +514,12 @@ def index_set(self): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import MinusculeRepresentation # optional - sage.combinat sage.modules - sage: C = crystals.Tableaux(['C',4], shape=[1]) # optional - sage.combinat sage.modules - sage: R = ZZ['q'].fraction_field() # optional - sage.combinat sage.modules - sage: V = MinusculeRepresentation(R, C) # optional - sage.combinat sage.modules - sage: V.index_set() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: from sage.algebras.quantum_groups.representations import MinusculeRepresentation + sage: C = crystals.Tableaux(['C',4], shape=[1]) + sage: R = ZZ['q'].fraction_field() + sage: V = MinusculeRepresentation(R, C) + sage: V.index_set() (1, 2, 3, 4) """ return self.cartan_type().index_set() @@ -519,11 +530,12 @@ def q(self): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import MinusculeRepresentation # optional - sage.combinat sage.modules - sage: C = crystals.Tableaux(['C',4], shape=[1]) # optional - sage.combinat sage.modules - sage: R = ZZ['q'].fraction_field() # optional - sage.combinat sage.modules - sage: V = MinusculeRepresentation(R, C) # optional - sage.combinat sage.modules - sage: V.q() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: from sage.algebras.quantum_groups.representations import MinusculeRepresentation + sage: C = crystals.Tableaux(['C',4], shape=[1]) + sage: R = ZZ['q'].fraction_field() + sage: V = MinusculeRepresentation(R, C) + sage: V.q() q """ return self._q diff --git a/src/sage/categories/quotient_fields.py b/src/sage/categories/quotient_fields.py index 2a79049bd62..f5d8495489d 100644 --- a/src/sage/categories/quotient_fields.py +++ b/src/sage/categories/quotient_fields.py @@ -72,20 +72,21 @@ def gcd(self, other): EXAMPLES:: + sage: # needs sage.libs.pari sage: R. = QQ['x'] sage: p = (1+x)^3*(1+2*x^2)/(1-x^5) sage: q = (1+x)^2*(1+3*x^2)/(1-x^4) - sage: factor(p) # optional - sage.libs.pari + sage: factor(p) (-2) * (x - 1)^-1 * (x + 1)^3 * (x^2 + 1/2) * (x^4 + x^3 + x^2 + x + 1)^-1 - sage: factor(q) # optional - sage.libs.pari + sage: factor(q) (-3) * (x - 1)^-1 * (x + 1) * (x^2 + 1)^-1 * (x^2 + 1/3) sage: gcd(p, q) (x + 1)/(x^7 + x^5 - x^2 - 1) - sage: factor(gcd(p, q)) # optional - sage.libs.pari + sage: factor(gcd(p, q)) (x - 1)^-1 * (x + 1) * (x^2 + 1)^-1 * (x^4 + x^3 + x^2 + x + 1)^-1 - sage: factor(gcd(p, 1 + x)) # optional - sage.libs.pari + sage: factor(gcd(p, 1 + x)) (x - 1)^-1 * (x + 1) * (x^4 + x^3 + x^2 + x + 1)^-1 - sage: factor(gcd(1 + x, q)) # optional - sage.libs.pari + sage: factor(gcd(1 + x, q)) (x - 1)^-1 * (x + 1) * (x^2 + 1)^-1 TESTS: @@ -93,25 +94,26 @@ def gcd(self, other): The following tests that the fraction field returns a correct gcd even if the base ring does not provide lcm and gcd:: - sage: R = ZZ.extension(x^2 + 1, names='i') # optional - sage.rings.number_field - sage: i = R.1 # optional - sage.rings.number_field - sage: gcd(5, 3 + 4*i) # optional - sage.rings.number_field + sage: # needs sage.libs.pari sage.rings.number_field + sage: R = ZZ.extension(x^2 + 1, names='i') + sage: i = R.1 + sage: gcd(5, 3 + 4*i) -i - 2 - sage: P. = R[] # optional - sage.rings.number_field - sage: gcd(t, i) # optional - sage.rings.number_field + sage: P. = R[] + sage: gcd(t, i) Traceback (most recent call last): ... NotImplementedError: Gaussian Integers in Number Field in i with defining polynomial x^2 + 1 does not provide a gcd implementation for univariate polynomials - sage: q = t/(t + 1); q.parent() # optional - sage.rings.number_field + sage: q = t/(t + 1); q.parent() Fraction Field of Univariate Polynomial Ring in t over Gaussian Integers in Number Field in i with defining polynomial x^2 + 1 - sage: gcd(q, q) # optional - sage.rings.number_field + sage: gcd(q, q) 1 - sage: q.gcd(0) # optional - sage.rings.number_field + sage: q.gcd(0) 1 - sage: (q*0).gcd(0) # optional - sage.rings.number_field + sage: (q*0).gcd(0) 0 """ P = self.parent() @@ -177,18 +179,19 @@ def lcm(self, other): Some more involved examples:: + sage: # needs sage.libs.pari sage: R. = QQ[] sage: p = (1+x)^3*(1+2*x^2)/(1-x^5) sage: q = (1+x)^2*(1+3*x^2)/(1-x^4) - sage: factor(p) # optional - sage.libs.pari + sage: factor(p) (-2) * (x - 1)^-1 * (x + 1)^3 * (x^2 + 1/2) * (x^4 + x^3 + x^2 + x + 1)^-1 - sage: factor(q) # optional - sage.libs.pari + sage: factor(q) (-3) * (x - 1)^-1 * (x + 1) * (x^2 + 1)^-1 * (x^2 + 1/3) - sage: factor(lcm(p, q)) # optional - sage.libs.pari + sage: factor(lcm(p, q)) (x - 1)^-1 * (x + 1)^3 * (x^2 + 1/3) * (x^2 + 1/2) - sage: factor(lcm(p, 1 + x)) # optional - sage.libs.pari + sage: factor(lcm(p, 1 + x)) (x + 1)^3 * (x^2 + 1/2) - sage: factor(lcm(1 + x, q)) # optional - sage.libs.pari + sage: factor(lcm(1 + x, q)) (x + 1) * (x^2 + 1/3) TESTS: @@ -196,23 +199,24 @@ def lcm(self, other): The following tests that the fraction field returns a correct lcm even if the base ring does not provide lcm and gcd:: - sage: R = ZZ.extension(x^2+1, names='i') # optional - sage.rings.number_field - sage: i = R.1 # optional - sage.rings.number_field - sage: P. = R[] # optional - sage.rings.number_field - sage: lcm(t, i) # optional - sage.rings.number_field + sage: # needs sage.libs.pari sage.rings.number_field + sage: R = ZZ.extension(x^2+1, names='i') + sage: i = R.1 + sage: P. = R[] + sage: lcm(t, i) Traceback (most recent call last): ... NotImplementedError: Gaussian Integers in Number Field in i with defining polynomial x^2 + 1 does not provide a gcd implementation for univariate polynomials - sage: q = t/(t + 1); q.parent() # optional - sage.rings.number_field + sage: q = t/(t + 1); q.parent() Fraction Field of Univariate Polynomial Ring in t over Gaussian Integers in Number Field in i with defining polynomial x^2 + 1 - sage: lcm(q, q) # optional - sage.rings.number_field + sage: lcm(q, q) 1 - sage: q.lcm(0) # optional - sage.rings.number_field + sage: q.lcm(0) 0 - sage: (q*0).lcm(0) # optional - sage.rings.number_field + sage: (q*0).lcm(0) 0 Check that it is possible to take lcm of a rational and an integer @@ -272,9 +276,9 @@ def xgcd(self, other): sage: R. = QQ['x'] sage: p = (1+x)^3*(1+2*x^2)/(1-x^5) sage: q = (1+x)^2*(1+3*x^2)/(1-x^4) - sage: factor(p) # optional - sage.libs.pari + sage: factor(p) # needs sage.libs.pari (-2) * (x - 1)^-1 * (x + 1)^3 * (x^2 + 1/2) * (x^4 + x^3 + x^2 + x + 1)^-1 - sage: factor(q) # optional - sage.libs.pari + sage: factor(q) # needs sage.libs.pari (-3) * (x - 1)^-1 * (x + 1) * (x^2 + 1)^-1 * (x^2 + 1/3) sage: g, s, t = xgcd(p, q) sage: g @@ -284,21 +288,22 @@ def xgcd(self, other): An example without a well defined gcd or xgcd on its base ring:: - sage: K = QuadraticField(5) # optional - sage.rings.number_field - sage: O = K.maximal_order() # optional - sage.rings.number_field - sage: R = PolynomialRing(O, 'x') # optional - sage.rings.number_field - sage: F = R.fraction_field() # optional - sage.rings.number_field - sage: x = F.gen(0) # optional - sage.rings.number_field - sage: x.gcd(x+1) # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + sage: K = QuadraticField(5) + sage: O = K.maximal_order() + sage: R = PolynomialRing(O, 'x') + sage: F = R.fraction_field() + sage: x = F.gen(0) + sage: x.gcd(x+1) 1 - sage: x.xgcd(x+1) # optional - sage.rings.number_field + sage: x.xgcd(x+1) (1, 1/x, 0) - sage: zero = F.zero() # optional - sage.rings.number_field - sage: zero.gcd(x) # optional - sage.rings.number_field + sage: zero = F.zero() + sage: zero.gcd(x) 1 - sage: zero.xgcd(x) # optional - sage.rings.number_field + sage: zero.xgcd(x) (1, 0, 1/x) - sage: zero.xgcd(zero) # optional - sage.rings.number_field + sage: zero.xgcd(zero) (0, 0, 0) """ P = self.parent() @@ -346,14 +351,14 @@ def factor(self, *args, **kwds): sage: K. = QQ[] sage: f = (x^3+x)/(x-3) - sage: f.factor() # optional - sage.libs.pari + sage: f.factor() # needs sage.libs.pari (x - 3)^-1 * x * (x^2 + 1) Here is an example to show that :trac:`7868` has been resolved:: - sage: R. = GF(2)[] # optional - sage.rings.finite_rings - sage: f = x*y/(x+y) # optional - sage.rings.finite_rings - sage: f.factor() # optional - sage.rings.finite_rings + sage: R. = GF(2)[] + sage: f = x*y/(x+y) + sage: f.factor() # needs sage.rings.finite_rings (x + y)^-1 * y * x """ return (self.numerator().factor(*args, **kwds) / @@ -361,21 +366,20 @@ def factor(self, *args, **kwds): def partial_fraction_decomposition(self, decompose_powers=True): """ - Decomposes fraction field element into a whole part and a list of + Decompose fraction field element into a whole part and a list of fraction field elements over prime power denominators. The sum will be equal to the original fraction. INPUT: - - decompose_powers -- whether to decompose prime power - denominators as opposed to having a single - term for each irreducible factor of the - denominator (default: True) + - ``decompose_powers`` -- boolean (default: ``True``); + whether to decompose prime power denominators as opposed to having + a single term for each irreducible factor of the denominator OUTPUT: - - Partial fraction decomposition of self over the base ring. + Partial fraction decomposition of ``self`` over the base ring. AUTHORS: @@ -383,53 +387,55 @@ def partial_fraction_decomposition(self, decompose_powers=True): EXAMPLES:: + sage: # needs sage.libs.pari sage: S. = QQ[] sage: q = 1/(t+1) + 2/(t+2) + 3/(t-3); q (6*t^2 + 4*t - 6)/(t^3 - 7*t - 6) - sage: whole, parts = q.partial_fraction_decomposition(); parts # optional - sage.libs.pari + sage: whole, parts = q.partial_fraction_decomposition(); parts [3/(t - 3), 1/(t + 1), 2/(t + 2)] - sage: sum(parts) == q # optional - sage.libs.pari + sage: sum(parts) == q True - sage: q = 1/(t^3+1) + 2/(t^2+2) + 3/(t-3)^5 # optional - sage.libs.pari - sage: whole, parts = q.partial_fraction_decomposition(); parts # optional - sage.libs.pari + sage: q = 1/(t^3+1) + 2/(t^2+2) + 3/(t-3)^5 + sage: whole, parts = q.partial_fraction_decomposition(); parts [1/3/(t + 1), 3/(t^5 - 15*t^4 + 90*t^3 - 270*t^2 + 405*t - 243), (-1/3*t + 2/3)/(t^2 - t + 1), 2/(t^2 + 2)] - sage: sum(parts) == q # optional - sage.libs.pari + sage: sum(parts) == q True - sage: q = 2*t / (t + 3)^2 # optional - sage.libs.pari - sage: q.partial_fraction_decomposition() # optional - sage.libs.pari + sage: q = 2*t / (t + 3)^2 + sage: q.partial_fraction_decomposition() (0, [2/(t + 3), -6/(t^2 + 6*t + 9)]) - sage: for p in q.partial_fraction_decomposition()[1]: # optional - sage.libs.pari + sage: for p in q.partial_fraction_decomposition()[1]: ....: print(p.factor()) (2) * (t + 3)^-1 (-6) * (t + 3)^-2 - sage: q.partial_fraction_decomposition(decompose_powers=False) # optional - sage.libs.pari + sage: q.partial_fraction_decomposition(decompose_powers=False) (0, [2*t/(t^2 + 6*t + 9)]) We can decompose over a given algebraic extension:: - sage: R. = QQ[sqrt(2)][] # optional - sage.rings.number_field sage.symbolic - sage: r = 1/(x^4+1) # optional - sage.rings.number_field sage.symbolic - sage: r.partial_fraction_decomposition() # optional - sage.rings.number_field sage.symbolic + sage: R. = QQ[sqrt(2)][] # needs sage.rings.number_field sage.symbolic + sage: r = 1/(x^4+1) # needs sage.rings.number_field sage.symbolic + sage: r.partial_fraction_decomposition() # needs sage.rings.number_field sage.symbolic (0, [(-1/4*sqrt2*x + 1/2)/(x^2 - sqrt2*x + 1), (1/4*sqrt2*x + 1/2)/(x^2 + sqrt2*x + 1)]) - sage: R. = QQ[I][] # of QQ[sqrt(-1)] # optional - sage.rings.number_field - sage: r = 1/(x^4+1) # optional - sage.rings.number_field - sage: r.partial_fraction_decomposition() # optional - sage.rings.number_field + sage: R. = QQ[I][] # of QQ[sqrt(-1)] # needs sage.rings.number_field sage.symbolic + sage: r = 1/(x^4+1) # needs sage.rings.number_field sage.symbolic + sage: r.partial_fraction_decomposition() # needs sage.rings.number_field sage.symbolic (0, [(-1/2*I)/(x^2 - I), 1/2*I/(x^2 + I)]) We can also ask Sage to find the least extension where the denominator factors in linear terms:: + sage: # needs sage.rings.number_field sage: R. = QQ[] sage: r = 1/(x^4+2) - sage: N = r.denominator().splitting_field('a'); N # optional - sage.rings.number_field + sage: N = r.denominator().splitting_field('a'); N Number Field in a with defining polynomial x^8 - 8*x^6 + 28*x^4 + 16*x^2 + 36 - sage: R1. = N[] # optional - sage.rings.number_field - sage: r1 = 1/(x1^4+2) # optional - sage.rings.number_field - sage: r1.partial_fraction_decomposition() # optional - sage.rings.number_field + sage: R1. = N[] + sage: r1 = 1/(x1^4+2) + sage: r1.partial_fraction_decomposition() (0, [(-1/224*a^6 + 13/448*a^4 - 5/56*a^2 - 25/224)/(x1 - 1/28*a^6 + 13/56*a^4 - 5/7*a^2 - 25/28), (1/224*a^6 - 13/448*a^4 + 5/56*a^2 + 25/224)/(x1 + 1/28*a^6 - 13/56*a^4 + 5/7*a^2 + 25/28), @@ -438,9 +444,9 @@ def partial_fraction_decomposition(self, decompose_powers=True): Or we may work directly over an algebraically closed field:: - sage: R. = QQbar[] # optional - sage.rings.number_field - sage: r = 1/(x^4+1) # optional - sage.rings.number_field - sage: r.partial_fraction_decomposition() # optional - sage.rings.number_field + sage: R. = QQbar[] # needs sage.rings.number_field + sage: r = 1/(x^4+1) # needs sage.rings.number_field + sage: r.partial_fraction_decomposition() # needs sage.rings.number_field (0, [(-0.1767766952966369? - 0.1767766952966369?*I)/(x - 0.7071067811865475? - 0.7071067811865475?*I), (-0.1767766952966369? + 0.1767766952966369?*I)/(x - 0.7071067811865475? + 0.7071067811865475?*I), @@ -449,14 +455,15 @@ def partial_fraction_decomposition(self, decompose_powers=True): We do the best we can over inexact fields:: + sage: # needs sage.rings.number_field sage.rings.real_mpfr sage: R. = RealField(20)[] sage: q = 1/(x^2 + x + 2)^2 + 1/(x-1); q (x^4 + 2.0000*x^3 + 5.0000*x^2 + 5.0000*x + 3.0000)/(x^5 + x^4 + 3.0000*x^3 - x^2 - 4.0000) - sage: whole, parts = q.partial_fraction_decomposition(); parts # optional - sage.rings.number_field + sage: whole, parts = q.partial_fraction_decomposition(); parts [1.0000/(x - 1.0000), 1.0000/(x^4 + 2.0000*x^3 + 5.0000*x^2 + 4.0000*x + 4.0000)] - sage: sum(parts) # optional - sage.rings.number_field + sage: sum(parts) (x^4 + 2.0000*x^3 + 5.0000*x^2 + 5.0000*x + 3.0000)/(x^5 + x^4 + 3.0000*x^3 - x^2 - 4.0000) @@ -466,23 +473,23 @@ def partial_fraction_decomposition(self, decompose_powers=True): sage: R. = ZZ[] sage: q = x^2/(x-1) - sage: q.partial_fraction_decomposition() # optional - sage.libs.pari + sage: q.partial_fraction_decomposition() # needs sage.libs.pari (x + 1, [1/(x - 1)]) sage: q = x^10/(x-1)^5 - sage: whole, parts = q.partial_fraction_decomposition() # optional - sage.libs.pari - sage: whole + sum(parts) == q # optional - sage.libs.pari + sage: whole, parts = q.partial_fraction_decomposition() # needs sage.libs.pari + sage: whole + sum(parts) == q # needs sage.libs.pari True And also over finite fields (see :trac:`6052`, :trac:`9945`):: - sage: R. = GF(2)[] # optional - sage.rings.finite_rings - sage: q = (x+1)/(x^3+x+1) # optional - sage.rings.finite_rings - sage: q.partial_fraction_decomposition() # optional - sage.rings.finite_rings + sage: R. = GF(2)[] + sage: q = (x+1)/(x^3+x+1) + sage: q.partial_fraction_decomposition() # needs sage.libs.pari (0, [(x + 1)/(x^3 + x + 1)]) - sage: R. = GF(11)[] # optional - sage.rings.finite_rings - sage: q = x + 1 + 1/(x+1) + x^2/(x^3 + 2*x + 9) # optional - sage.rings.finite_rings - sage: q.partial_fraction_decomposition() # optional - sage.rings.finite_rings + sage: R. = GF(11)[] + sage: q = x + 1 + 1/(x+1) + x^2/(x^3 + 2*x + 9) + sage: q.partial_fraction_decomposition() # needs sage.libs.pari (x + 1, [1/(x + 1), x^2/(x^3 + 2*x + 9)]) And even the rationals:: @@ -496,7 +503,7 @@ def partial_fraction_decomposition(self, decompose_powers=True): sage: S. = QQ[] sage: r = t / (t^3+1)^5 - sage: r.partial_fraction_decomposition() # optional - sage.libs.pari + sage: r.partial_fraction_decomposition() # needs sage.libs.pari (0, [-35/729/(t + 1), -35/729/(t^2 + 2*t + 1), @@ -508,37 +515,38 @@ def partial_fraction_decomposition(self, decompose_powers=True): (-1/81*t + 5/81)/(t^6 - 3*t^5 + 6*t^4 - 7*t^3 + 6*t^2 - 3*t + 1), (-2/27*t + 1/9)/(t^8 - 4*t^7 + 10*t^6 - 16*t^5 + 19*t^4 - 16*t^3 + 10*t^2 - 4*t + 1), (-2/27*t + 1/27)/(t^10 - 5*t^9 + 15*t^8 - 30*t^7 + 45*t^6 - 51*t^5 + 45*t^4 - 30*t^3 + 15*t^2 - 5*t + 1)]) - sage: sum(r.partial_fraction_decomposition()[1]) == r # optional - sage.libs.pari + sage: sum(r.partial_fraction_decomposition()[1]) == r # needs sage.libs.pari True Some special cases:: sage: R = Frac(QQ['x']); x = R.gen() - sage: x.partial_fraction_decomposition() # optional - sage.libs.pari + sage: x.partial_fraction_decomposition() (x, []) - sage: R(0).partial_fraction_decomposition() # optional - sage.libs.pari + sage: R(0).partial_fraction_decomposition() (0, []) - sage: R(1).partial_fraction_decomposition() # optional - sage.libs.pari + sage: R(1).partial_fraction_decomposition() (1, []) - sage: (1/x).partial_fraction_decomposition() # optional - sage.libs.pari + sage: (1/x).partial_fraction_decomposition() # needs sage.libs.pari (0, [1/x]) - sage: (1/x+1/x^3).partial_fraction_decomposition() # optional - sage.libs.pari + sage: (1/x+1/x^3).partial_fraction_decomposition() # needs sage.libs.pari (0, [1/x, 1/x^3]) This was fixed in :trac:`16240`:: + sage: # needs sage.libs.pari sage: R. = QQ['x'] sage: p = 1/(-x + 1) - sage: whole,parts = p.partial_fraction_decomposition() # optional - sage.libs.pari - sage: p == sum(parts) # optional - sage.libs.pari + sage: whole, parts = p.partial_fraction_decomposition() + sage: p == sum(parts) True sage: p = 3/(-x^4 + 1) - sage: whole,parts = p.partial_fraction_decomposition() # optional - sage.libs.pari - sage: p == sum(parts) # optional - sage.libs.pari + sage: whole, parts = p.partial_fraction_decomposition() + sage: p == sum(parts) True sage: p = (6*x^2 - 9*x + 5)/(-x^3 + 3*x^2 - 3*x + 1) - sage: whole,parts = p.partial_fraction_decomposition() # optional - sage.libs.pari - sage: p == sum(parts) # optional - sage.libs.pari + sage: whole, parts = p.partial_fraction_decomposition() + sage: p == sum(parts) True """ denom = self.denominator() diff --git a/src/sage/categories/realizations.py b/src/sage/categories/realizations.py index 0207b66a4be..595ee38dc9a 100644 --- a/src/sage/categories/realizations.py +++ b/src/sage/categories/realizations.py @@ -71,9 +71,9 @@ def Realizations(self): The category of realizations of a given algebra:: - sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules + sage: A = Sets().WithRealizations().example(); A # needs sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: A.Realizations() # optional - sage.combinat sage.modules + sage: A.Realizations() # needs sage.modules Category of realizations of The subset algebra of {1, 2, 3} over Rational Field @@ -116,7 +116,7 @@ class Category_realization_of_parent(Category_over_base, BindableClass): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules + sage: A = Sets().WithRealizations().example(); A # needs sage.modules The subset algebra of {1, 2, 3} over Rational Field The role of this base class is to implement some technical goodies, like @@ -124,7 +124,7 @@ class Category_realization_of_parent(Category_over_base, BindableClass): implemented as a nested class in ``A`` (see the :mod:`code of the example `):: - sage: C = A.Realizations(); C # optional - sage.combinat sage.modules + sage: C = A.Realizations(); C # needs sage.modules Category of realizations of The subset algebra of {1, 2, 3} over Rational Field @@ -134,17 +134,18 @@ def __init__(self, parent_with_realization): """ TESTS:: + sage: # needs sage.combinat sage.modules sage: from sage.categories.realizations import Category_realization_of_parent - sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules + sage: A = Sets().WithRealizations().example(); A The subset algebra of {1, 2, 3} over Rational Field - sage: C = A.Realizations(); C # optional - sage.combinat sage.modules + sage: C = A.Realizations(); C Category of realizations of The subset algebra of {1, 2, 3} over Rational Field - sage: isinstance(C, Category_realization_of_parent) # optional - sage.combinat sage.modules + sage: isinstance(C, Category_realization_of_parent) True - sage: C.parent_with_realization # optional - sage.combinat sage.modules + sage: C.parent_with_realization The subset algebra of {1, 2, 3} over Rational Field - sage: TestSuite(C).run(skip=["_test_category_over_bases"]) # optional - sage.combinat sage.modules + sage: TestSuite(C).run(skip=["_test_category_over_bases"]) .. TODO:: @@ -167,8 +168,8 @@ def _get_name(self): sage: from sage.categories.realizations import Category_realization_of_parent sage: class MultiplicativeBasesOnPrimitiveElements(Category_realization_of_parent): ....: def super_categories(self): return [Objects()] - sage: Sym = SymmetricFunctions(QQ); Sym.rename("Sym") # optional - sage.combinat - sage: MultiplicativeBasesOnPrimitiveElements(Sym)._get_name() # optional - sage.combinat + sage: Sym = SymmetricFunctions(QQ); Sym.rename("Sym") # needs sage.combinat sage.modules + sage: MultiplicativeBasesOnPrimitiveElements(Sym)._get_name() # needs sage.combinat sage.modules 'multiplicative bases on primitive elements' """ import re @@ -185,10 +186,10 @@ def _repr_object_names(self): sage: from sage.categories.realizations import Category_realization_of_parent sage: class MultiplicativeBasesOnPrimitiveElements(Category_realization_of_parent): ....: def super_categories(self): return [Objects()] - sage: Sym = SymmetricFunctions(QQ); Sym.rename("Sym") # optional - sage.combinat - sage: C = MultiplicativeBasesOnPrimitiveElements(Sym); C # optional - sage.combinat + sage: Sym = SymmetricFunctions(QQ); Sym.rename("Sym") # needs sage.combinat sage.modules + sage: C = MultiplicativeBasesOnPrimitiveElements(Sym); C # needs sage.combinat sage.modules Category of multiplicative bases on primitive elements of Sym - sage: C._repr_object_names() # optional - sage.combinat + sage: C._repr_object_names() # needs sage.combinat sage.modules 'multiplicative bases on primitive elements of Sym' """ return "{} of {}".format(self._get_name(), self.base()) diff --git a/src/sage/categories/regular_crystals.py b/src/sage/categories/regular_crystals.py index afad9e78c22..35da8e325e2 100644 --- a/src/sage/categories/regular_crystals.py +++ b/src/sage/categories/regular_crystals.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.combinat sage.graphs +# sage.doctest: needs sage.combinat sage.graphs r""" Regular Crystals """ diff --git a/src/sage/categories/regular_supercrystals.py b/src/sage/categories/regular_supercrystals.py index 9fd6f5c8a83..044f556a1f7 100644 --- a/src/sage/categories/regular_supercrystals.py +++ b/src/sage/categories/regular_supercrystals.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.combinat sage.graphs +# sage.doctest: needs sage.combinat sage.graphs r""" Regular Supercrystals """ diff --git a/src/sage/categories/rings.py b/src/sage/categories/rings.py index 1449333d973..60ca92f971b 100644 --- a/src/sage/categories/rings.py +++ b/src/sage/categories/rings.py @@ -66,17 +66,18 @@ def is_injective(self) -> bool: EXAMPLES:: + sage: # needs sage.libs.singular sage: R. = QQ[] - sage: R.hom([x, y^2], R).is_injective() # optional - sage.libs.singular + sage: R.hom([x, y^2], R).is_injective() True - sage: R.hom([x, x^2], R).is_injective() # optional - sage.libs.singular + sage: R.hom([x, x^2], R).is_injective() False - sage: S. = R.quotient(x^3*y) # optional - sage.libs.singular - sage: R.hom([v, u], S).is_injective() # optional - sage.libs.singular + sage: S. = R.quotient(x^3*y) + sage: R.hom([v, u], S).is_injective() False - sage: S.hom([-u, v], S).is_injective() # optional - sage.libs.singular + sage: S.hom([-u, v], S).is_injective() True - sage: S.cover().is_injective() # optional - sage.libs.singular + sage: S.cover().is_injective() False If the domain is a field, the homomorphism is injective:: @@ -102,12 +103,12 @@ def is_injective(self) -> bool: characteristic can not be injective:: sage: R. = ZZ[] - sage: f = R.hom([GF(3)(1)]); f # optional - sage.rings.finite_rings + sage: f = R.hom([GF(3)(1)]); f Ring morphism: From: Univariate Polynomial Ring in x over Integer Ring To: Finite Field of size 3 Defn: x |--> 1 - sage: f.is_injective() # optional - sage.rings.finite_rings + sage: f.is_injective() False A morphism whose domain is an order in a number field is injective if @@ -132,8 +133,8 @@ def is_injective(self) -> bool: A coercion to the fraction field is injective:: - sage: R = ZpFM(3) # optional - sage.rings.padics - sage: R.fraction_field().coerce_map_from(R).is_injective() # optional - sage.rings.padics + sage: R = ZpFM(3) # needs sage.rings.padics + sage: R.fraction_field().coerce_map_from(R).is_injective() True """ @@ -218,20 +219,20 @@ def extend_to_fraction_field(self): Ring endomorphism of Univariate Polynomial Ring in x over Rational Field Defn: x |--> x + 1 - sage: g = f.extend_to_fraction_field(); g # optional - sage.libs.singular + sage: g = f.extend_to_fraction_field(); g # needs sage.libs.singular Ring endomorphism of Fraction Field of Univariate Polynomial Ring in x over Rational Field Defn: x |--> x + 1 - sage: g(x) # optional - sage.libs.singular + sage: g(x) # needs sage.libs.singular x + 1 - sage: g(1/x) # optional - sage.libs.singular + sage: g(1/x) # needs sage.libs.singular 1/(x + 1) If this morphism is not injective, it does not extend to the fraction field and an error is raised:: - sage: f = GF(5).coerce_map_from(ZZ) # optional - sage.rings.finite_rings - sage: f.extend_to_fraction_field() # optional - sage.rings.finite_rings + sage: f = GF(5).coerce_map_from(ZZ) + sage: f.extend_to_fraction_field() Traceback (most recent call last): ... ValueError: the morphism is not injective @@ -240,7 +241,7 @@ def extend_to_fraction_field(self): sage: A. = RR[] sage: phi = A.hom([x + 1]) - sage: phi.extend_to_fraction_field() # optional - sage.libs.singular + sage: phi.extend_to_fraction_field() # needs sage.libs.singular Ring endomorphism of Fraction Field of Univariate Polynomial Ring in x over Real Field with 53 bits of precision Defn: x |--> x + 1.00000000000000 @@ -336,10 +337,10 @@ def is_zero(self) -> bool: sage: R. = ZZ[] sage: R.quo(1).is_zero() True - sage: R. = GF(101)[] # optional - sage.rings.finite_rings - sage: R.quo(77).is_zero() # optional - sage.rings.finite_rings + sage: R. = GF(101)[] + sage: R.quo(77).is_zero() True - sage: R.quo(x^2 + 1).is_zero() # optional - sage.rings.finite_rings + sage: R.quo(x^2 + 1).is_zero() # needs sage.libs.pari False """ return self.one() == self.zero() @@ -354,19 +355,20 @@ def bracket(self, x, y): EXAMPLES:: - sage: F = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules - sage: F # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: F = AlgebrasWithBasis(QQ).example() + sage: F An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: a, b, c = F.algebra_generators() # optional - sage.combinat sage.modules - sage: F.bracket(a, b) # optional - sage.combinat sage.modules + sage: a, b, c = F.algebra_generators() + sage: F.bracket(a, b) B[word: ab] - B[word: ba] This measures the default of commutation between `x` and `y`. `F` endowed with the bracket operation is a Lie algebra; in particular, it satisfies Jacobi's identity:: - sage: (F.bracket(F.bracket(a,b), c) + F.bracket(F.bracket(b,c), a) # optional - sage.combinat sage.modules + sage: (F.bracket(F.bracket(a,b), c) + F.bracket(F.bracket(b,c), a) # needs sage.combinat sage.modules ....: + F.bracket(F.bracket(c,a), b)) 0 """ @@ -402,7 +404,7 @@ def _Hom_(self, Y, category): sage: Hom(QQ, QQ, category=Rings()).__class__ - sage: Hom(CyclotomicField(3), QQ, category=Rings()).__class__ # optional - sage.rings.number_field + sage: Hom(CyclotomicField(3), QQ, category=Rings()).__class__ # needs sage.rings.number_field sage: TestSuite(Hom(QQ, QQ, category=Rings())).run() # indirect doctest @@ -445,12 +447,13 @@ def _mul_(self, x, switch_sides=False): from the base class of rings. This is the case, e.g., for matrix algebras:: - sage: MS = MatrixSpace(QQ, 2, 2) # optional - sage.modules - sage: isinstance(MS, Ring) # optional - sage.modules + sage: # needs sage.modules + sage: MS = MatrixSpace(QQ, 2, 2) + sage: isinstance(MS, Ring) False - sage: MS in Rings() # optional - sage.modules + sage: MS in Rings() True - sage: MS * 2 # indirect doctest # optional - sage.modules + sage: MS * 2 # indirect doctest Left Ideal ( [2 0] @@ -461,7 +464,7 @@ def _mul_(self, x, switch_sides=False): In the next example, the ring and the other factor switch sides in the product:: - sage: [MS.2] * MS # optional - sage.modules + sage: [MS.2] * MS # needs sage.modules Right Ideal ( [0 0] @@ -507,12 +510,12 @@ def __pow__(self, n): EXAMPLES:: - sage: QQ^5 # optional - sage.modules + sage: QQ^5 # needs sage.modules Vector space of dimension 5 over Rational Field - sage: Integers(20)^1000 # optional - sage.modules + sage: Integers(20)^1000 # needs sage.modules Ambient free module of rank 1000 over Ring of integers modulo 20 - sage: QQ^(2, 3) # optional - sage.modules + sage: QQ^(2, 3) # needs sage.modules Full MatrixSpace of 2 by 3 dense matrices over Rational Field """ if isinstance(n, tuple): @@ -537,18 +540,19 @@ def ideal_monoid(self): EXAMPLES:: - sage: MS = MatrixSpace(QQ, 2, 2) # optional - sage.modules - sage: isinstance(MS, Ring) # optional - sage.modules + sage: # needs sage.modules + sage: MS = MatrixSpace(QQ, 2, 2) + sage: isinstance(MS, Ring) False - sage: MS in Rings() # optional - sage.modules + sage: MS in Rings() True - sage: MS.ideal_monoid() # optional - sage.modules + sage: MS.ideal_monoid() Monoid of ideals of Full MatrixSpace of 2 by 2 dense matrices over Rational Field Note that the monoid is cached:: - sage: MS.ideal_monoid() is MS.ideal_monoid() # optional - sage.modules + sage: MS.ideal_monoid() is MS.ideal_monoid() # needs sage.modules True """ try: @@ -566,11 +570,11 @@ def characteristic(self): sage: QQ.characteristic() 0 - sage: GF(19).characteristic() # optional - sage.rings.finite_rings + sage: GF(19).characteristic() 19 sage: Integers(8).characteristic() 8 - sage: Zp(5).characteristic() # optional - sage.rings.padics + sage: Zp(5).characteristic() # needs sage.rings.padics 0 """ from sage.rings.infinity import infinity @@ -625,19 +629,20 @@ def ideal(self, *args, **kwds): EXAMPLES:: - sage: MS = MatrixSpace(QQ, 2, 2) # optional - sage.modules - sage: isinstance(MS, Ring) # optional - sage.modules + sage: # needs sage.modules + sage: MS = MatrixSpace(QQ, 2, 2) + sage: isinstance(MS, Ring) False - sage: MS in Rings() # optional - sage.modules + sage: MS in Rings() True - sage: MS.ideal(2) # optional - sage.modules + sage: MS.ideal(2) Twosided Ideal ( [2 0] [0 2] ) of Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: MS.ideal([MS.0, MS.1], side='right') # optional - sage.modules + sage: MS.ideal([MS.0, MS.1], side='right') Right Ideal ( [1 0] @@ -739,8 +744,8 @@ def _ideal_class_(self, n=0): EXAMPLES:: - sage: MS = MatrixSpace(QQ, 2, 2) # optional - sage.modules - sage: MS._ideal_class_() # optional - sage.modules + sage: MS = MatrixSpace(QQ, 2, 2) # needs sage.modules + sage: MS._ideal_class_() # needs sage.modules We do not know of a commutative ring in Sage that does not inherit @@ -788,10 +793,11 @@ def quotient(self, I, names=None, **kwds): So, we need a bit of effort to make the following example work with the category framework:: - sage: F. = FreeAlgebra(QQ) # optional - sage.combinat sage.modules - sage: from sage.rings.noncommutative_ideals import Ideal_nc # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: F. = FreeAlgebra(QQ) + sage: from sage.rings.noncommutative_ideals import Ideal_nc sage: from itertools import product - sage: class PowerIdeal(Ideal_nc): # optional - sage.combinat sage.modules + sage: class PowerIdeal(Ideal_nc): ....: def __init__(self, R, n): ....: self._power = n ....: Ideal_nc.__init__(self, R, [R.prod(m) @@ -800,22 +806,22 @@ def quotient(self, I, names=None, **kwds): ....: R = self.ring() ....: return add([c*R(m) for m, c in x ....: if len(m) < self._power], R(0)) - sage: I = PowerIdeal(F, 3) # optional - sage.combinat sage.modules - sage: Q = Rings().parent_class.quotient(F, I); Q # optional - sage.combinat sage.modules + sage: I = PowerIdeal(F, 3) + sage: Q = Rings().parent_class.quotient(F, I); Q Quotient of Free Algebra on 3 generators (x, y, z) over Rational Field by the ideal (x^3, x^2*y, x^2*z, x*y*x, x*y^2, x*y*z, x*z*x, x*z*y, x*z^2, y*x^2, y*x*y, y*x*z, y^2*x, y^3, y^2*z, y*z*x, y*z*y, y*z^2, z*x^2, z*x*y, z*x*z, z*y*x, z*y^2, z*y*z, z^2*x, z^2*y, z^3) - sage: Q.0 # optional - sage.combinat sage.modules + sage: Q.0 xbar - sage: Q.1 # optional - sage.combinat sage.modules + sage: Q.1 ybar - sage: Q.2 # optional - sage.combinat sage.modules + sage: Q.2 zbar - sage: Q.0*Q.1 # optional - sage.combinat sage.modules + sage: Q.0*Q.1 xbar*ybar - sage: Q.0*Q.1*Q.0 # optional - sage.combinat sage.modules + sage: Q.0*Q.1*Q.0 0 An example with polynomial rings:: @@ -826,14 +832,15 @@ def quotient(self, I, names=None, **kwds): sage: S.gens() (a,) + sage: # needs sage.libs.singular sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quotient((x^2, y)) # optional - sage.libs.singular - sage: S # optional - sage.libs.singular + sage: S. = R.quotient((x^2, y)) + sage: S Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y) - sage: S.gens() # optional - sage.libs.singular + sage: S.gens() (a, 0) - sage: a == b # optional - sage.libs.singular + sage: a == b False """ from sage.rings.quotient_ring import QuotientRing @@ -849,8 +856,8 @@ def quo(self, I, names=None, **kwds): EXAMPLES:: - sage: MS = MatrixSpace(QQ, 2) # optional - sage.modules - sage: I = MS * MS.gens() * MS # optional - sage.modules + sage: MS = MatrixSpace(QQ, 2) # needs sage.modules + sage: I = MS * MS.gens() * MS # needs sage.modules ``MS`` is not an instance of :class:`~sage.rings.ring.Ring`. @@ -858,11 +865,11 @@ def quo(self, I, names=None, **kwds): category of rings. The quotient method is inherited from there:: - sage: isinstance(MS, sage.rings.ring.Ring) # optional - sage.modules + sage: isinstance(MS, sage.rings.ring.Ring) # needs sage.modules False - sage: isinstance(MS, Rings().parent_class) # optional - sage.modules + sage: isinstance(MS, Rings().parent_class) # needs sage.modules True - sage: MS.quo(I, names=['a','b','c','d']) # optional - sage.modules + sage: MS.quo(I, names=['a','b','c','d']) # needs sage.modules Quotient of Full MatrixSpace of 2 by 2 dense matrices over Rational Field by the ideal ( @@ -881,14 +888,15 @@ def quo(self, I, names=None, **kwds): A test with a subclass of :class:`~sage.rings.ring.Ring`:: - sage: R. = PolynomialRing(QQ, 2) # optional - sage.libs.singular - sage: S. = R.quo((x^2, y)) # optional - sage.libs.singular - sage: S # optional - sage.libs.singular + sage: # needs sage.libs.singular + sage: R. = PolynomialRing(QQ, 2) + sage: S. = R.quo((x^2, y)) + sage: S Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y) - sage: S.gens() # optional - sage.libs.singular + sage: S.gens() (a, 0) - sage: a == b # optional - sage.libs.singular + sage: a == b False """ return self.quotient(I, names=names, **kwds) @@ -918,18 +926,18 @@ def quotient_ring(self, I, names=None, **kwds): EXAMPLES:: - sage: MS = MatrixSpace(QQ, 2) # optional - sage.modules - sage: I = MS * MS.gens() * MS # optional - sage.modules + sage: MS = MatrixSpace(QQ, 2) # needs sage.modules + sage: I = MS * MS.gens() * MS # needs sage.modules ``MS`` is not an instance of :class:`~sage.rings.ring.Ring`, but it is an instance of the parent class of the category of rings. The quotient method is inherited from there:: - sage: isinstance(MS, sage.rings.ring.Ring) # optional - sage.modules + sage: isinstance(MS, sage.rings.ring.Ring) # needs sage.modules False - sage: isinstance(MS, Rings().parent_class) # optional - sage.modules + sage: isinstance(MS, Rings().parent_class) # needs sage.modules True - sage: MS.quotient_ring(I, names=['a','b','c','d']) # optional - sage.modules + sage: MS.quotient_ring(I, names=['a','b','c','d']) # needs sage.modules Quotient of Full MatrixSpace of 2 by 2 dense matrices over Rational Field by the ideal ( @@ -954,14 +962,15 @@ def quotient_ring(self, I, names=None, **kwds): sage: S.gens() (a,) - sage: R. = PolynomialRing(QQ,2) # optional - sage.libs.singular - sage: S. = R.quotient_ring((x^2, y)) # optional - sage.libs.singular - sage: S # optional - sage.libs.singular + sage: # needs sage.libs.singular + sage: R. = PolynomialRing(QQ,2) + sage: S. = R.quotient_ring((x^2, y)) + sage: S Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y) - sage: S.gens() # optional - sage.libs.singular + sage: S.gens() (a, 0) - sage: a == b # optional - sage.libs.singular + sage: a == b False """ return self.quotient(I, names=names, **kwds) @@ -974,9 +983,9 @@ def __truediv__(self, I): EXAMPLES:: - sage: MS = MatrixSpace(QQ, 2) # optional - sage.modules - sage: I = MS * MS.gens() * MS # optional - sage.modules - sage: MS/I # optional - sage.modules + sage: MS = MatrixSpace(QQ, 2) # needs sage.modules + sage: I = MS * MS.gens() * MS # needs sage.modules + sage: MS/I # needs sage.modules Traceback (most recent call last): ... TypeError: use self.quotient(I) to construct the quotient ring @@ -1013,25 +1022,25 @@ def __getitem__(self, arg): Univariate Polynomial Ring in x over Integer Ring sage: QQ['x'] Univariate Polynomial Ring in x over Rational Field - sage: GF(17)['abc'] # optional - sage.rings.finite_rings + sage: GF(17)['abc'] Univariate Polynomial Ring in abc over Finite Field of size 17 - sage: GF(17)['a,b,c'] # optional - sage.rings.finite_rings + sage: GF(17)['a,b,c'] Multivariate Polynomial Ring in a, b, c over Finite Field of size 17 - sage: GF(17)['a']['b'] # optional - sage.rings.finite_rings + sage: GF(17)['a']['b'] Univariate Polynomial Ring in b over Univariate Polynomial Ring in a over Finite Field of size 17 We can create Ore polynomial rings:: - sage: k. = GF(5^3) # optional - sage.rings.finite_rings - sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings - sage: k['x', Frob] # optional - sage.rings.finite_rings + sage: k. = GF(5^3) # needs sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # needs sage.rings.finite_rings + sage: k['x', Frob] # needs sage.rings.finite_rings Ore Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5 sage: R. = QQ[] - sage: der = R.derivation() # optional - sage.modules - sage: R['d', der] # optional - sage.modules + sage: der = R.derivation() # needs sage.modules + sage: R['d', der] # needs sage.modules Ore Polynomial Ring in d over Univariate Polynomial Ring in t over Rational Field twisted by d/dt @@ -1061,9 +1070,9 @@ def __getitem__(self, arg): Note that the same syntax can be used to create number fields:: - sage: QQ[I] + sage: QQ[I] # needs sage.rings.number_field sage.symbolic Number Field in I with defining polynomial x^2 + 1 with I = 1*I - sage: QQ[I].coerce_embedding() + sage: QQ[I].coerce_embedding() # needs sage.rings.number_field sage.symbolic Generic morphism: From: Number Field in I with defining polynomial x^2 + 1 with I = 1*I To: Complex Lazy Field @@ -1071,10 +1080,10 @@ def __getitem__(self, arg): :: - sage: QQ[sqrt(2)] # optional - sage.symbolic sage.rings.number_field + sage: QQ[sqrt(2)] # needs sage.rings.number_field sage.symbolic Number Field in sqrt2 with defining polynomial x^2 - 2 with sqrt2 = 1.414213562373095? - sage: QQ[sqrt(2)].coerce_embedding() # optional - sage.symbolic sage.rings.number_field + sage: QQ[sqrt(2)].coerce_embedding() # needs sage.rings.number_field sage.symbolic Generic morphism: From: Number Field in sqrt2 with defining polynomial x^2 - 2 with sqrt2 = 1.414213562373095? @@ -1083,26 +1092,26 @@ def __getitem__(self, arg): :: - sage: QQ[sqrt(2), sqrt(3)] # optional - sage.symbolic sage.rings.number_field + sage: QQ[sqrt(2), sqrt(3)] # needs sage.rings.number_field sage.symbolic Number Field in sqrt2 with defining polynomial x^2 - 2 over its base field and orders in number fields:: - sage: ZZ[I] # optional - sage.symbolic sage.rings.number_field + sage: ZZ[I] # needs sage.rings.number_field sage.symbolic Order in Number Field in I0 with defining polynomial x^2 + 1 with I0 = 1*I - sage: ZZ[sqrt(5)] # optional - sage.symbolic sage.rings.number_field + sage: ZZ[sqrt(5)] # needs sage.rings.number_field sage.symbolic Order in Number Field in sqrt5 with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790? - sage: ZZ[sqrt(2) + sqrt(3)] # optional - sage.symbolic sage.rings.number_field + sage: ZZ[sqrt(2) + sqrt(3)] # needs sage.rings.number_field sage.symbolic Order in Number Field in a with defining polynomial x^4 - 10*x^2 + 1 with a = 3.146264369941973? Embeddings are found for simple extensions (when that makes sense):: - sage: QQi. = QuadraticField(-1, 'i') # optional - sage.symbolic sage.rings.number_field - sage: QQ[i].coerce_embedding() # optional - sage.symbolic sage.rings.number_field + sage: QQi. = QuadraticField(-1, 'i') # needs sage.rings.number_field sage.symbolic + sage: QQ[i].coerce_embedding() # needs sage.rings.number_field sage.symbolic Generic morphism: From: Number Field in i with defining polynomial x^2 + 1 with i = 1*I To: Complex Lazy Field @@ -1138,25 +1147,27 @@ def __getitem__(self, arg): Extension towers are built as follows and use distinct generator names:: - sage: K = QQ[2^(1/3), 2^(1/2), 3^(1/3)] # optional - sage.symbolic sage.rings.number_field - sage: K # optional - sage.symbolic sage.rings.number_field + sage: # needs sage.rings.number_field sage.symbolic + sage: K = QQ[2^(1/3), 2^(1/2), 3^(1/3)] + sage: K Number Field in a with defining polynomial x^3 - 2 over its base field - sage: K.base_field() # optional - sage.symbolic sage.rings.number_field + sage: K.base_field() Number Field in sqrt2 with defining polynomial x^2 - 2 over its base field - sage: K.base_field().base_field() # optional - sage.symbolic sage.rings.number_field + sage: K.base_field().base_field() Number Field in b with defining polynomial x^3 - 3 Embeddings:: - sage: a = 10^100; expr = (2*a + sqrt(2))/(2*a^2-1) # optional - sage.symbolic sage.rings.number_field - sage: QQ[expr].coerce_embedding() is None # optional - sage.symbolic sage.rings.number_field + sage: # needs sage.rings.number_field sage.symbolic + sage: a = 10^100; expr = (2*a + sqrt(2))/(2*a^2-1) + sage: QQ[expr].coerce_embedding() is None False - sage: QQ[sqrt(5)].gen() > 0 # optional - sage.symbolic sage.rings.number_field + sage: QQ[sqrt(5)].gen() > 0 True - sage: expr = sqrt(2) + I*(cos(pi/4, hold=True) - sqrt(2)/2) # optional - sage.symbolic sage.rings.number_field - sage: QQ[expr].coerce_embedding() # optional - sage.symbolic sage.rings.number_field + sage: expr = sqrt(2) + I*(cos(pi/4, hold=True) - sqrt(2)/2) + sage: QQ[expr].coerce_embedding() Generic morphism: From: Number Field in a with defining polynomial x^2 - 2 with a = 1.414213562373095? @@ -1280,18 +1291,19 @@ def free_module(self, base=None, basis=None, map=True): EXAMPLES:: + sage: # needs sage.modules sage: R. = QQ[[]] - sage: V, from_V, to_V = R.free_module(R) # optional - sage.modules - sage: v = to_V(1 + x); v # optional - sage.modules + sage: V, from_V, to_V = R.free_module(R) + sage: v = to_V(1 + x); v (1 + x) - sage: from_V(v) # optional - sage.modules + sage: from_V(v) 1 + x - sage: W, from_W, to_W = R.free_module(R, basis=(1 - x)) # optional - sage.modules - sage: W is V # optional - sage.modules + sage: W, from_W, to_W = R.free_module(R, basis=(1 - x)) + sage: W is V True - sage: w = to_W(1 + x); w # optional - sage.modules + sage: w = to_W(1 + x); w (1 - x^2) - sage: from_W(w) # optional - sage.modules + sage: from_W(w) 1 + x + O(x^20) """ if base is None: @@ -1333,12 +1345,13 @@ def is_unit(self) -> bool: EXAMPLES:: - sage: MS = MatrixSpace(ZZ, 2) # optional - sage.modules - sage: MS.one().is_unit() # optional - sage.modules + sage: # needs sage.modules + sage: MS = MatrixSpace(ZZ, 2) + sage: MS.one().is_unit() True - sage: MS.zero().is_unit() # optional - sage.modules + sage: MS.zero().is_unit() False - sage: MS([1,2,3,4]).is_unit() # optional - sage.modules + sage: MS([1,2,3,4]).is_unit() False """ if self.is_one() or (-self).is_one(): @@ -1358,8 +1371,8 @@ def inverse_of_unit(self): EXAMPLES:: sage: R. = ZZ[] - sage: S = R.quo(x^2 + x + 1) # optional - sage.libs.pari - sage: S(1).inverse_of_unit() # optional - sage.libs.pari + sage: S = R.quo(x^2 + x + 1) # needs sage.libs.pari + sage: S(1).inverse_of_unit() # needs sage.libs.pari 1 This method fails when the element is not a unit:: @@ -1430,10 +1443,11 @@ def _gen_names(elts): EXAMPLES:: + sage: # needs sage.combinat sage: from sage.categories.rings import _gen_names - sage: list(_gen_names([sqrt(5)])) # optional - sage.symbolic + sage: list(_gen_names([sqrt(5)])) # needs sage.symbolic ['sqrt5'] - sage: list(_gen_names([sqrt(-17), 2^(1/3)])) # optional - sage.symbolic + sage: list(_gen_names([sqrt(-17), 2^(1/3)])) # needs sage.symbolic ['a', 'b'] sage: list(_gen_names((1..27)))[-1] 'aa' diff --git a/src/sage/categories/semigroups.py b/src/sage/categories/semigroups.py index 45bf6ed7305..4b85a255568 100644 --- a/src/sage/categories/semigroups.py +++ b/src/sage/categories/semigroups.py @@ -196,37 +196,40 @@ def cayley_graph(self, side="right", simple=False, elements=None, We start with the (right) Cayley graphs of some classical groups:: - sage: D4 = DihedralGroup(4); D4 # optional - sage.groups + sage: # needs sage.graphs sage.groups + sage: D4 = DihedralGroup(4); D4 Dihedral group of order 8 as a permutation group - sage: G = D4.cayley_graph() # optional - sage.groups sage.graphs - sage: show(G, color_by_label=True, edge_labels=True) # optional - sage.groups sage.graphs sage.plot - sage: A5 = AlternatingGroup(5); A5 # optional - sage.groups + sage: G = D4.cayley_graph() + sage: show(G, color_by_label=True, edge_labels=True) # needs sage.plot + sage: A5 = AlternatingGroup(5); A5 Alternating group of order 5!/2 as a permutation group - sage: G = A5.cayley_graph() # optional - sage.groups sage.graphs - sage: G.show3d(color_by_label=True, edge_size=0.01, # optional - sage.groups sage.graphs sage.plot + sage: G = A5.cayley_graph() + sage: G.show3d(color_by_label=True, edge_size=0.01, # needs sage.plot ....: edge_size2=0.02, vertex_size=0.03) - sage: G.show3d(vertex_size=0.03, # long time (less than a minute) # optional - sage.groups sage.graphs sage.plot + sage: G.show3d(vertex_size=0.03, # long time (less than a minute), needs sage.plot ....: edge_size=0.01, edge_size2=0.02, ....: vertex_colors={(1,1,1): G.vertices(sort=True)}, ....: bgcolor=(0,0,0), color_by_label=True, ....: xres=700, yres=700, iterations=200) - sage: G.num_edges() # optional - sage.groups sage.graphs + sage: G.num_edges() 120 - sage: w = WeylGroup(['A', 3]) # optional - sage.combinat sage.groups - sage: d = w.cayley_graph(); d # optional - sage.combinat sage.groups sage.graphs + sage: # needs sage.combinat sage.graphs sage.groups + sage: w = WeylGroup(['A', 3]) + sage: d = w.cayley_graph(); d Digraph on 24 vertices - sage: d.show3d(color_by_label=True, edge_size=0.01, vertex_size=0.03) # optional - sage.combinat sage.groups sage.graphs sage.plot + sage: d.show3d(color_by_label=True, edge_size=0.01, vertex_size=0.03) # needs sage.plot Alternative generators may be specified:: - sage: G = A5.cayley_graph(generators=[A5.gens()[0]]) # optional - sage.groups sage.graphs - sage: G.num_edges() # optional - sage.groups sage.graphs + sage: # needs sage.graphs sage.groups + sage: G = A5.cayley_graph(generators=[A5.gens()[0]]) + sage: G.num_edges() 60 - sage: g = PermutationGroup([(i + 1, j + 1) # optional - sage.groups sage.graphs + sage: g = PermutationGroup([(i + 1, j + 1) ....: for i in range(5) ....: for j in range(5) if j != i]) - sage: g.cayley_graph(generators=[(1,2), (2,3)]) # optional - sage.groups sage.graphs + sage: g.cayley_graph(generators=[(1,2), (2,3)]) Digraph on 120 vertices If ``elements`` is specified, then only the subgraph @@ -234,62 +237,63 @@ def cayley_graph(self, side="right", simple=False, elements=None, display the Cayley graph of the free monoid truncated on the elements of length at most 3:: + sage: # needs sage.combinat sage.graphs sage: M = Monoids().example(); M An example of a monoid: the free monoid generated by ('a', 'b', 'c', 'd') - sage: elements = [M.prod(w) # optional - sage.combinat + sage: elements = [M.prod(w) ....: for w in sum((list(Words(M.semigroup_generators(), k)) ....: for k in range(4)), [])] - sage: G = M.cayley_graph(elements=elements) # optional - sage.combinat sage.graphs - sage: G.num_verts(), G.num_edges() # optional - sage.combinat sage.graphs + sage: G = M.cayley_graph(elements=elements) + sage: G.num_verts(), G.num_edges() (85, 84) - sage: G.show3d(color_by_label=True, edge_size=0.001, vertex_size=0.01) # optional - sage.combinat sage.graphs sage.plot + sage: G.show3d(color_by_label=True, edge_size=0.001, vertex_size=0.01) # needs sage.plot We now illustrate the ``side`` and ``simple`` options on a semigroup:: sage: S = FiniteSemigroups().example(alphabet=('a', 'b')) - sage: g = S.cayley_graph(simple=True) # optional - sage.graphs - sage: g.vertices(sort=True) # optional - sage.graphs + sage: g = S.cayley_graph(simple=True) # needs sage.graphs + sage: g.vertices(sort=True) # needs sage.graphs ['a', 'ab', 'b', 'ba'] - sage: g.edges(sort=True) # optional - sage.graphs + sage: g.edges(sort=True) # needs sage.graphs [('a', 'ab', None), ('b', 'ba', None)] :: - sage: g = S.cayley_graph(side="left", simple=True) # optional - sage.graphs - sage: g.vertices(sort=True) # optional - sage.graphs + sage: g = S.cayley_graph(side="left", simple=True) # needs sage.graphs + sage: g.vertices(sort=True) # needs sage.graphs ['a', 'ab', 'b', 'ba'] - sage: g.edges(sort=True) # optional - sage.graphs + sage: g.edges(sort=True) # needs sage.graphs [('a', 'ba', None), ('ab', 'ba', None), ('b', 'ab', None), ('ba', 'ab', None)] :: - sage: g = S.cayley_graph(side="twosided", simple=True) # optional - sage.graphs - sage: g.vertices(sort=True) # optional - sage.graphs + sage: g = S.cayley_graph(side="twosided", simple=True) # needs sage.graphs + sage: g.vertices(sort=True) # needs sage.graphs ['a', 'ab', 'b', 'ba'] - sage: g.edges(sort=True) # optional - sage.graphs + sage: g.edges(sort=True) # needs sage.graphs [('a', 'ab', None), ('a', 'ba', None), ('ab', 'ba', None), ('b', 'ab', None), ('b', 'ba', None), ('ba', 'ab', None)] :: - sage: g = S.cayley_graph(side="twosided") # optional - sage.graphs - sage: g.vertices(sort=True) # optional - sage.graphs + sage: g = S.cayley_graph(side="twosided") # needs sage.graphs + sage: g.vertices(sort=True) # needs sage.graphs ['a', 'ab', 'b', 'ba'] - sage: g.edges(sort=True) # optional - sage.graphs + sage: g.edges(sort=True) # needs sage.graphs [('a', 'a', (0, 'left')), ('a', 'a', (0, 'right')), ('a', 'ab', (1, 'right')), ('a', 'ba', (1, 'left')), ('ab', 'ab', (0, 'left')), ('ab', 'ab', (0, 'right')), ('ab', 'ab', (1, 'right')), ('ab', 'ba', (1, 'left')), ('b', 'ab', (0, 'left')), ('b', 'b', (1, 'left')), ('b', 'b', (1, 'right')), ('b', 'ba', (0, 'right')), ('ba', 'ab', (0, 'left')), ('ba', 'ba', (0, 'right')), ('ba', 'ba', (1, 'left')), ('ba', 'ba', (1, 'right'))] :: - sage: s1 = SymmetricGroup(1); s = s1.cayley_graph() # optional - sage.groups sage.graphs - sage: s.vertices(sort=False) # optional - sage.groups sage.graphs + sage: s1 = SymmetricGroup(1); s = s1.cayley_graph() # needs sage.graphs sage.groups + sage: s.vertices(sort=False) # needs sage.graphs sage.groups [()] TESTS:: - sage: SymmetricGroup(2).cayley_graph(side="both") # optional - sage.groups sage.graphs + sage: SymmetricGroup(2).cayley_graph(side="both") # needs sage.graphs sage.groups Traceback (most recent call last): ... ValueError: option 'side' must be 'left', 'right' or 'twosided' @@ -386,52 +390,53 @@ def subsemigroup(self, generators, one=None, category=None): EXAMPLES:: sage: R = IntegerModRing(15) - sage: M = R.subsemigroup([R(3), R(5)]); M # optional - sage.groups + sage: M = R.subsemigroup([R(3), R(5)]); M # needs sage.combinat A subsemigroup of (Ring of integers modulo 15) with 2 generators - sage: M.list() # optional - sage.groups + sage: M.list() # needs sage.combinat [3, 5, 9, 0, 10, 12, 6] By default, `M` is just in the category of subsemigroups:: - sage: M in Semigroups().Subobjects() # optional - sage.groups + sage: M in Semigroups().Subobjects() # needs sage.combinat True In the following example, we specify that `M` is a submonoid of the finite monoid `R` (it shares the same unit), and a group by itself:: - sage: M = R.subsemigroup([R(-1)], # optional - sage.groups + sage: M = R.subsemigroup([R(-1)], # needs sage.combinat ....: category=Monoids().Finite().Subobjects() & Groups()); M A submonoid of (Ring of integers modulo 15) with 1 generators - sage: M.list() # optional - sage.groups + sage: M.list() # needs sage.combinat [1, 14] - sage: M.one() # optional - sage.groups + sage: M.one() # needs sage.combinat 1 In the following example, `M` is a group; however, its unit does not coincide with that of `R`, so `M` is only a subsemigroup, and we need to specify its unit explicitly:: - sage: M = R.subsemigroup([R(5)], # optional - sage.groups + sage: M = R.subsemigroup([R(5)], # needs sage.combinat ....: category=Semigroups().Finite().Subobjects() & Groups()); M Traceback (most recent call last): ... ValueError: For a monoid which is just a subsemigroup, the unit should be specified - sage: M = R.subsemigroup([R(5)], one=R(10), # optional - sage.groups + sage: # needs sage.groups + sage: M = R.subsemigroup([R(5)], one=R(10), ....: category=Semigroups().Finite().Subobjects() & Groups()); M A subsemigroup of (Ring of integers modulo 15) with 1 generators - sage: M in Groups() # optional - sage.groups + sage: M in Groups() True - sage: M.list() # optional - sage.groups + sage: M.list() [10, 5] - sage: M.one() # optional - sage.groups + sage: M.one() 10 TESTS:: - sage: TestSuite(M).run() # optional - sage.groups + sage: TestSuite(M).run() # needs sage.combinat Failure in _test_inverse: Traceback (most recent call last): ... @@ -461,8 +466,8 @@ def trivial_representation(self, base_ring=None, side="twosided"): EXAMPLES:: - sage: G = groups.permutation.Dihedral(4) # optional - sage.groups - sage: G.trivial_representation() # optional - sage.groups + sage: G = groups.permutation.Dihedral(4) # needs sage.groups + sage: G.trivial_representation() # needs sage.groups Trivial representation of Dihedral group of order 8 as a permutation group over Integer Ring """ @@ -481,8 +486,8 @@ def regular_representation(self, base_ring=None, side="left"): EXAMPLES:: - sage: G = groups.permutation.Dihedral(4) # optional - sage.groups - sage: G.regular_representation() # optional - sage.groups + sage: G = groups.permutation.Dihedral(4) # needs sage.groups + sage: G.regular_representation() # needs sage.groups Left Regular Representation of Dihedral group of order 8 as a permutation group over Integer Ring """ @@ -892,7 +897,7 @@ def algebra_generators(self): the left regular band generated by ('a', 'b', 'c', 'd') sage: M.semigroup_generators() Family ('a', 'b', 'c', 'd') - sage: M.algebra(ZZ).algebra_generators() # optional - sage.modules + sage: M.algebra(ZZ).algebra_generators() # needs sage.modules Family (B['a'], B['b'], B['c'], B['d']) """ return self.basis().keys().semigroup_generators().map(self.monomial) @@ -907,12 +912,12 @@ def gens(self): EXAMPLES:: - sage: a, b = SL2Z.algebra(ZZ).gens(); a, b # optional - sage.groups sage.modules + sage: a, b = SL2Z.algebra(ZZ).gens(); a, b # needs sage.groups sage.modules ([ 0 -1] [ 1 0], [1 1] [0 1]) - sage: 2*a + b # optional - sage.groups sage.modules + sage: 2*a + b # needs sage.groups sage.modules 2*[ 0 -1] [ 1 0] + @@ -927,9 +932,9 @@ def ngens(self): EXAMPLES:: - sage: SL2Z.algebra(ZZ).ngens() # optional - sage.groups sage.modules + sage: SL2Z.algebra(ZZ).ngens() # needs sage.groups sage.modules 2 - sage: DihedralGroup(4).algebra(RR).ngens() # optional - sage.groups sage.modules + sage: DihedralGroup(4).algebra(RR).ngens() # needs sage.groups sage.modules 2 """ return self.basis().keys().ngens() @@ -940,8 +945,8 @@ def gen(self, i=0): EXAMPLES:: - sage: A = GL(3, GF(7)).algebra(ZZ) # optional - sage.groups sage.libs.pari sage.modules - sage: A.gen(0) # optional - sage.groups sage.libs.pari sage.modules + sage: A = GL(3, GF(7)).algebra(ZZ) # needs sage.modules + sage: A.gen(0) # needs sage.groups sage.libs.pari sage.modules [3 0 0] [0 1 0] [0 0 1] @@ -962,9 +967,9 @@ def product_on_basis(self, g1, g2): sage: S = FiniteSemigroups().example(); S An example of a finite semigroup: the left regular band generated by ('a', 'b', 'c', 'd') - sage: A = S.algebra(QQ) # optional - sage.modules - sage: a, b, c, d = A.algebra_generators() # optional - sage.modules - sage: a * b + b * d * c * d # optional - sage.modules + sage: A = S.algebra(QQ) # needs sage.modules + sage: a, b, c, d = A.algebra_generators() # needs sage.modules + sage: a * b + b * d * c * d # needs sage.modules B['ab'] + B['bdc'] """ return self.monomial(g1 * g2) @@ -979,10 +984,11 @@ def trivial_representation(self, side="twosided"): EXAMPLES:: - sage: G = groups.permutation.Dihedral(4) # optional - sage.groups - sage: A = G.algebra(QQ) # optional - sage.groups sage.modules - sage: V = A.trivial_representation() # optional - sage.groups sage.modules - sage: V == G.trivial_representation(QQ) # optional - sage.groups sage.modules + sage: # needs sage.groups + sage: G = groups.permutation.Dihedral(4) + sage: A = G.algebra(QQ) # needs sage.modules + sage: V = A.trivial_representation() # needs sage.modules + sage: V == G.trivial_representation(QQ) # needs sage.modules True """ S = self.basis().keys() @@ -999,10 +1005,11 @@ def regular_representation(self, side="left"): EXAMPLES:: - sage: G = groups.permutation.Dihedral(4) # optional - sage.groups - sage: A = G.algebra(QQ) # optional - sage.groups sage.modules - sage: V = A.regular_representation() # optional - sage.groups sage.modules - sage: V == G.regular_representation(QQ) # optional - sage.groups sage.modules + sage: # needs sage.groups + sage: G = groups.permutation.Dihedral(4) + sage: A = G.algebra(QQ) # needs sage.modules + sage: V = A.regular_representation() # needs sage.modules + sage: V == G.regular_representation(QQ) # needs sage.modules True """ S = self.basis().keys() diff --git a/src/sage/categories/semisimple_algebras.py b/src/sage/categories/semisimple_algebras.py index 9be6bb8d571..9a310614290 100644 --- a/src/sage/categories/semisimple_algebras.py +++ b/src/sage/categories/semisimple_algebras.py @@ -37,15 +37,15 @@ class SemisimpleAlgebras(Category_over_base_ring): Typically, finite group algebras are semisimple:: - sage: DihedralGroup(5).algebra(QQ) in SemisimpleAlgebras # optional - sage.groups + sage: DihedralGroup(5).algebra(QQ) in SemisimpleAlgebras # needs sage.groups True Unless the characteristic of the field divides the order of the group:: - sage: DihedralGroup(5).algebra(IntegerModRing(5)) in SemisimpleAlgebras # optional - sage.groups + sage: DihedralGroup(5).algebra(IntegerModRing(5)) in SemisimpleAlgebras # needs sage.groups False - sage: DihedralGroup(5).algebra(IntegerModRing(7)) in SemisimpleAlgebras # optional - sage.groups + sage: DihedralGroup(5).algebra(IntegerModRing(7)) in SemisimpleAlgebras # needs sage.groups True .. SEEALSO:: :wikipedia:`Semisimple_algebra` @@ -96,13 +96,13 @@ def radical_basis(self, **keywords): EXAMPLES:: - sage: A = SymmetricGroup(4).algebra(QQ) # optional - sage.groups - sage: A.radical_basis() # optional - sage.groups + sage: A = SymmetricGroup(4).algebra(QQ) # needs sage.groups + sage: A.radical_basis() # needs sage.groups () TESTS:: - sage: A.radical_basis.__module__ # optional - sage.groups + sage: A.radical_basis.__module__ # needs sage.groups 'sage.categories.finite_dimensional_semisimple_algebras_with_basis' """ return () diff --git a/src/sage/categories/sets_cat.py b/src/sage/categories/sets_cat.py index c2d87e43b0c..ea5695de6c2 100644 --- a/src/sage/categories/sets_cat.py +++ b/src/sage/categories/sets_cat.py @@ -147,7 +147,7 @@ class Sets(Category_singleton): We run some generic checks on P:: - sage: TestSuite(P).run(verbose=True) # optional - sage.libs.pari + sage: TestSuite(P).run(verbose=True) # needs sage.libs.pari running ._test_an_element() . . . pass running ._test_cardinality() . . . pass running ._test_category() . . . pass @@ -867,11 +867,11 @@ def Facade(self): 1. as plain integers:: - sage: P = Poset((divisors(12), attrcall("divides")), facade=True) # optional - sage.graphs sage.combinat + sage: P = Poset((divisors(12), attrcall("divides")), facade=True) # needs sage.graphs 2. as integers, modified to be aware that their parent is `P`:: - sage: Q = Poset((divisors(12), attrcall("divides")), facade=False) # optional - sage.graphs sage.combinat + sage: Q = Poset((divisors(12), attrcall("divides")), facade=False) # needs sage.graphs The advantage of option 1. is that one needs not do conversions back and forth between `P` and `\ZZ`. The @@ -885,23 +885,23 @@ def Facade(self): To raise this ambiguity, one needs to explicitly specify the underlying poset as in `2 <_P 3`:: - sage: P = Posets().example("facade") # optional - sage.graphs sage.combinat - sage: P.lt(2,3) # optional - sage.graphs sage.combinat + sage: P = Posets().example("facade") + sage: P.lt(2,3) False On the other hand, with option 2. and once constructed, the elements know unambiguously how to compare themselves:: - sage: Q(2) < Q(3) # optional - sage.graphs sage.combinat + sage: Q(2) < Q(3) # needs sage.graphs False - sage: Q(2) < Q(6) # optional - sage.graphs sage.combinat + sage: Q(2) < Q(6) # needs sage.graphs True Beware that ``P(2)`` is still the integer `2`. Therefore ``P(2) < P(3)`` still compares `2` and `3` as integers!:: - sage: P(2) < P(3) # optional - sage.graphs sage.combinat + sage: P(2) < P(3) True In short `P` being a facade parent is one of the programmatic @@ -970,17 +970,17 @@ def _element_constructor_(self): sage: S(17) # indirect doctest 17 - sage: A = FreeModule(QQ, 3) # optional - sage.modules - sage: A.element_class # optional - sage.modules + sage: A = FreeModule(QQ, 3) # needs sage.modules + sage: A.element_class # needs sage.modules - sage: A._element_constructor_ # optional - sage.modules + sage: A._element_constructor_ # needs sage.modules - sage: B = SymmetricGroup(3).algebra(ZZ) # optional - sage.groups sage.modules - sage: B.element_class # optional - sage.groups sage.modules + sage: B = SymmetricGroup(3).algebra(ZZ) # needs sage.groups sage.modules + sage: B.element_class # needs sage.groups sage.modules <...SymmetricGroupAlgebra_n_with_category.element_class'> - sage: B._element_constructor_ # optional - sage.groups sage.modules + sage: B._element_constructor_ # needs sage.groups sage.modules """ @@ -1070,7 +1070,7 @@ def an_element(self): EXAMPLES:: - sage: CDF.an_element() + sage: CDF.an_element() # needs sage.rings.complex_double 1.0*I sage: ZZ[['t']].an_element() t @@ -1192,12 +1192,12 @@ def _test_elements_eq_reflexive(self, **options): We try a non-reflexive equality:: sage: P = Sets().example("wrapper") - sage: P._test_elements_eq_reflexive() # optional - sage.libs.pari + sage: P._test_elements_eq_reflexive() # needs sage.libs.pari sage: eq = P.element_class.__eq__ sage: P.element_class.__eq__ = (lambda x, y: ....: False if eq(x, P(47)) and eq(y, P(47)) else eq(x, y)) - sage: P._test_elements_eq_reflexive() # optional - sage.libs.pari + sage: P._test_elements_eq_reflexive() # needs sage.libs.pari Traceback (most recent call last): ... AssertionError: 47 != 47 @@ -1228,7 +1228,7 @@ def _test_elements_eq_symmetric(self, **options): We test a non symmetric equality:: sage: P = Sets().example("wrapper") - sage: P._test_elements_eq_symmetric() # optional - sage.libs.pari + sage: P._test_elements_eq_symmetric() # needs sage.libs.pari sage: eq = P.element_class.__eq__ sage: def non_sym_eq(x, y): @@ -1236,7 +1236,7 @@ def _test_elements_eq_symmetric(self, **options): ....: elif eq(x, P(47)) and eq(y, P(53)): return True ....: else: return eq(x, y) sage: P.element_class.__eq__ = non_sym_eq - sage: P._test_elements_eq_symmetric() # optional - sage.libs.pari + sage: P._test_elements_eq_symmetric() # needs sage.libs.pari Traceback (most recent call last): ... AssertionError: non symmetric equality: 47 == 53 but 53 != 47 @@ -1269,9 +1269,9 @@ def _test_elements_eq_transitive(self, **options): We test a non transitive equality:: - sage: R = Zp(3) # optional - sage.rings.padics - sage: test = raw_getattr(Sets().ParentMethods, "_test_elements_eq_transitive") # optional - sage.rings.padics - sage: test(R, elements=[R(3,2), R(3,1), R(0)]) # optional - sage.rings.padics + sage: R = Zp(3) # needs sage.rings.padics + sage: test = raw_getattr(Sets().ParentMethods, "_test_elements_eq_transitive") + sage: test(R, elements=[R(3,2), R(3,1), R(0)]) # needs sage.rings.padics Traceback (most recent call last): ... AssertionError: non transitive equality: @@ -1318,12 +1318,12 @@ def _test_elements_neq(self, **options): We try a broken inequality:: sage: P = Sets().example("wrapper") - sage: P._test_elements_neq() # optional - sage.libs.pari + sage: P._test_elements_neq() # needs sage.libs.pari sage: ne = P.element_class.__ne__ sage: eq = P.element_class.__eq__ sage: P.element_class.__ne__ = lambda x, y: False - sage: P._test_elements_neq() # optional - sage.libs.pari + sage: P._test_elements_neq() # needs sage.libs.pari Traceback (most recent call last): ... AssertionError: __eq__ and __ne__ inconsistency: @@ -1562,21 +1562,21 @@ def cartesian_product(*parents, **kwargs): EXAMPLES:: sage: C = AlgebrasWithBasis(QQ) - sage: A = C.example(); A.rename("A") # optional - sage.combinat sage.modules - sage: A.cartesian_product(A, A) # optional - sage.combinat sage.modules + sage: A = C.example(); A.rename("A") # needs sage.combinat sage.modules + sage: A.cartesian_product(A, A) # needs sage.combinat sage.modules A (+) A (+) A - sage: ZZ.cartesian_product(GF(2), FiniteEnumeratedSet([1,2,3])) # optional - sage.rings.finite_rings + sage: ZZ.cartesian_product(GF(2), FiniteEnumeratedSet([1,2,3])) The Cartesian product of (Integer Ring, Finite Field of size 2, {1, 2, 3}) - sage: C = ZZ.cartesian_product(A); C # optional - sage.combinat sage.modules + sage: C = ZZ.cartesian_product(A); C # needs sage.combinat sage.modules The Cartesian product of (Integer Ring, A) TESTS:: - sage: type(C) # optional - sage.combinat sage.modules + sage: type(C) # needs sage.combinat sage.modules - sage: C.category() # optional - sage.combinat sage.modules + sage: C.category() # needs sage.combinat sage.modules Join of Category of rings and ... and Category of Cartesian products of commutative additive groups @@ -1629,21 +1629,22 @@ def algebra(self, base_ring, category=None, **kwds): If `S` is a :class:`group `, the result is its group algebra `KS`:: - sage: S = DihedralGroup(4); S # optional - sage.groups + sage: # needs sage.groups sage.modules + sage: S = DihedralGroup(4); S Dihedral group of order 8 as a permutation group - sage: A = S.algebra(QQ); A # optional - sage.groups sage.modules + sage: A = S.algebra(QQ); A Algebra of Dihedral group of order 8 as a permutation group over Rational Field - sage: A.category() # optional - sage.groups sage.modules + sage: A.category() Category of finite group algebras over Rational Field - sage: a = A.an_element(); a # optional - sage.groups sage.modules + sage: a = A.an_element(); a () + (1,3) + 2*(1,3)(2,4) + 3*(1,4,3,2) This space is endowed with an algebra structure, obtained by extending by bilinearity the multiplication of `G` to a multiplication on `RG`:: - sage: a * a # optional - sage.groups sage.modules + sage: a * a # needs sage.groups sage.modules 6*() + 4*(2,4) + 3*(1,2)(3,4) + 12*(1,2,3,4) + 2*(1,3) + 13*(1,3)(2,4) + 6*(1,4,3,2) + 3*(1,4)(2,3) @@ -1653,11 +1654,11 @@ def algebra(self, base_ring, category=None, **kwds): sage: S = Monoids().example(); S An example of a monoid: the free monoid generated by ('a', 'b', 'c', 'd') - sage: A = S.algebra(QQ); A # optional - sage.modules + sage: A = S.algebra(QQ); A # needs sage.modules Algebra of An example of a monoid: the free monoid generated by ('a', 'b', 'c', 'd') over Rational Field - sage: A.category() # optional - sage.modules + sage: A.category() # needs sage.modules Category of monoid algebras over Rational Field Similarly, we can construct algebras for additive magmas, @@ -1666,18 +1667,18 @@ def algebra(self, base_ring, category=None, **kwds): One may specify for which category one takes the algebra; here we build the algebra of the additive group `GF_3`:: + sage: # needs sage.modules sage: from sage.categories.additive_groups import AdditiveGroups - sage: S = GF(7) # optional - sage.rings.finite_rings - sage: A = S.algebra(QQ, category=AdditiveGroups()); A # optional - sage.rings.finite_rings sage.modules + sage: S = GF(7) + sage: A = S.algebra(QQ, category=AdditiveGroups()); A Algebra of Finite Field of size 7 over Rational Field - sage: A.category() # optional - sage.rings.finite_rings sage.modules + sage: A.category() Category of finite dimensional additive group algebras over Rational Field - - sage: a = A(S(1)) # optional - sage.rings.finite_rings sage.modules - sage: a # optional - sage.rings.finite_rings sage.modules + sage: a = A(S(1)) + sage: a 1 - sage: 1 + a * a * a # optional - sage.rings.finite_rings sage.modules + sage: 1 + a * a * a 0 + 3 Note that the ``category`` keyword needs to be fed with @@ -1720,31 +1721,32 @@ def _sympy_(self): EXAMPLES:: + sage: # needs sympy sage: F = FiniteEnumeratedSets().example(); F An example of a finite enumerated set: {1,2,3} - sage: sF = F._sympy_(); sF # optional - sympy + sage: sF = F._sympy_(); sF SageSet(An example of a finite enumerated set: {1,2,3}) - sage: sF.is_finite_set # optional - sympy + sage: sF.is_finite_set True - sage: bool(sF) # optional - sympy + sage: bool(sF) True - sage: len(sF) # optional - sympy + sage: len(sF) 3 - sage: list(sF) # optional - sympy + sage: list(sF) [1, 2, 3] - sage: from sympy import FiniteSet # optional - sympy - sage: FiniteSet.fromiter(sF) # random - this output is sympy >= 1.9 # optional - sympy + sage: from sympy import FiniteSet + sage: FiniteSet.fromiter(sF) # random - this output is sympy >= 1.9 FiniteSet(1, 2, 3) - sage: RR._sympy_().is_finite_set # optional - sympy + sage: RR._sympy_().is_finite_set # needs sympy False sage: F = Family([1, 2]) sage: F is Family([1, 2]) False - sage: sF = F._sympy_(); sF # optional - sympy + sage: sF = F._sympy_(); sF # needs sympy SageSet(Family (1, 2)) - sage: sF._sage_() is F # optional - sympy + sage: sF._sage_() is F # needs sympy True """ from sage.interfaces.sympy_wrapper import SageSet @@ -1769,9 +1771,9 @@ def cartesian_product(*elements): EXAMPLES:: sage: C = AlgebrasWithBasis(QQ) - sage: A = C.example() # optional - sage.combinat sage.modules - sage: a, b, c = A.algebra_generators() # optional - sage.combinat sage.modules - sage: a.cartesian_product(b, c) # optional - sage.combinat sage.modules + sage: A = C.example() # needs sage.combinat sage.modules + sage: a, b, c = A.algebra_generators() # needs sage.combinat sage.modules + sage: a.cartesian_product(b, c) # needs sage.combinat sage.modules 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? @@ -1805,22 +1807,22 @@ def __invert__(self): We now try to inverse a couple of morphisms defined by a matrix:: - sage: H = End(QQ^2) # optional - sage.modules - sage: phi = H(matrix([[1,1], [0,1]])); phi # optional - sage.modules + sage: H = End(QQ^2) # needs sage.modules + sage: phi = H(matrix([[1,1], [0,1]])); phi # needs sage.modules Vector space morphism represented by the matrix: [1 1] [0 1] Domain: Vector space of dimension 2 over Rational Field Codomain: Vector space of dimension 2 over Rational Field - sage: ~phi # optional - sage.modules + sage: ~phi # needs sage.modules Vector space morphism represented by the matrix: [ 1 -1] [ 0 1] Domain: Vector space of dimension 2 over Rational Field Codomain: Vector space of dimension 2 over Rational Field - sage: phi = H(matrix([[1,1], [1,1]])) # optional - sage.modules - sage: ~phi # optional - sage.modules + sage: phi = H(matrix([[1,1], [1,1]])) # needs sage.modules + sage: ~phi # needs sage.modules Traceback (most recent call last): ... ZeroDivisionError: matrix morphism not invertible @@ -1837,11 +1839,11 @@ def is_injective(self): EXAMPLES:: - sage: f = ZZ.hom(GF(3)); f # optional - sage.rings.finite_rings + sage: f = ZZ.hom(GF(3)); f Natural morphism: From: Integer Ring To: Finite Field of size 3 - sage: f.is_injective() # optional - sage.rings.finite_rings + sage: f.is_injective() False """ if self.domain().cardinality() <= 1: @@ -1856,11 +1858,12 @@ def image(self, domain_subset=None): EXAMPLES:: - sage: P = Partitions(6) # optional - sage.combinat - sage: H = Hom(P, ZZ) # optional - sage.combinat - sage: f = H(ZZ.sum) # optional - sage.combinat - sage: X = f.image() # optional - sage.combinat - sage: list(X) # optional - sage.combinat + sage: # needs sage.combinat + sage: P = Partitions(6) + sage: H = Hom(P, ZZ) + sage: f = H(ZZ.sum) + sage: X = f.image() # needs sage.libs.flint + sage: list(X) # needs sage.libs.flint [6] """ D = self.domain() @@ -2259,18 +2262,19 @@ def __iter__(self): sage: C.__iter__.__module__ 'sage.categories.sets_cat' - sage: F22 = GF(2).cartesian_product(GF(2)) # optional - sage.rings.finite_rings - sage: list(F22) # optional - sage.rings.finite_rings + sage: F22 = GF(2).cartesian_product(GF(2)) + sage: list(F22) [(0, 0), (0, 1), (1, 0), (1, 1)] - sage: C = cartesian_product([Permutations(10)]*4) # optional - sage.combinat - sage: it = iter(C) # optional - sage.combinat - sage: next(it) # optional - sage.combinat + sage: # needs sage.combinat + sage: C = cartesian_product([Permutations(10)]*4) + sage: it = iter(C) + sage: next(it) ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) - sage: next(it) # optional - sage.combinat + sage: next(it) ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], @@ -2279,8 +2283,8 @@ def __iter__(self): When all factors (except possibly the first factor) are known to be finite, it uses the lexicographic order:: - sage: it = iter(cartesian_product([ZZ, GF(2)])) # optional - sage.rings.finite_rings - sage: [next(it) for _ in range(10)] # optional - sage.rings.finite_rings + sage: it = iter(cartesian_product([ZZ, GF(2)])) + sage: [next(it) for _ in range(10)] [(0, 0), (0, 1), (1, 0), (1, 1), (-1, 0), (-1, 1), @@ -2300,8 +2304,8 @@ def __iter__(self): An example with the first factor finite, the second infinite:: - sage: it = iter(cartesian_product([GF(2), ZZ])) # optional - sage.rings.finite_rings - sage: [next(it) for _ in range(11)] # optional - sage.rings.finite_rings + sage: it = iter(cartesian_product([GF(2), ZZ])) + sage: [next(it) for _ in range(11)] [(0, 0), (1, 0), (0, 1), (1, 1), (0, -1), @@ -2386,8 +2390,8 @@ def is_finite(self): EXAMPLES:: sage: E = FiniteEnumeratedSet([1,2,3]) - sage: C = cartesian_product([E, SymmetricGroup(4)]) # optional - sage.groups - sage: C.is_finite() # optional - sage.groups + sage: C = cartesian_product([E, SymmetricGroup(4)]) # needs sage.groups + sage: C.is_finite() # needs sage.groups True sage: cartesian_product([ZZ,ZZ]).is_finite() @@ -2414,8 +2418,8 @@ def cardinality(self): EXAMPLES:: sage: E = FiniteEnumeratedSet([1,2,3]) - sage: C = cartesian_product([E, SymmetricGroup(4)]) # optional - sage.groups - sage: C.cardinality() # optional - sage.groups + sage: C = cartesian_product([E, SymmetricGroup(4)]) # needs sage.groups + sage: C.cardinality() # needs sage.groups 72 sage: E = FiniteEnumeratedSet([]) @@ -2427,9 +2431,9 @@ def cardinality(self): sage: C.cardinality() +Infinity - sage: cartesian_product([GF(5), Permutations(10)]).cardinality() # optional - sage.rings.finite_rings sage.combinat + sage: cartesian_product([GF(5), Permutations(10)]).cardinality() 18144000 - sage: cartesian_product([GF(71)]*20).cardinality() == 71**20 # optional - sage.rings.finite_rings + sage: cartesian_product([GF(71)]*20).cardinality() == 71**20 True """ f = self.cartesian_factors() @@ -2460,8 +2464,8 @@ def random_element(self, *args): EXAMPLES:: - sage: C = cartesian_product([Permutations(10)]*5) # optional - sage.combinat - sage: C.random_element() # random # optional - sage.combinat + sage: C = cartesian_product([Permutations(10)]*5) + sage: C.random_element() # random ([2, 9, 4, 7, 1, 8, 6, 10, 5, 3], [8, 6, 5, 7, 1, 4, 9, 3, 10, 2], [5, 10, 3, 8, 2, 9, 1, 4, 7, 6], @@ -2570,9 +2574,9 @@ def _sympy_(self): EXAMPLES:: sage: ZZ3 = cartesian_product([ZZ, ZZ, ZZ]) - sage: sZZ3 = ZZ3._sympy_(); sZZ3 # optional - sympy + sage: sZZ3 = ZZ3._sympy_(); sZZ3 # needs sympy ProductSet(Integers, Integers, Integers) - sage: (1, 2, 3) in sZZ3 # optional - sympy + sage: (1, 2, 3) in sZZ3 # needs sympy True """ from sympy import ProductSet @@ -2593,14 +2597,15 @@ def cartesian_projection(self, i): EXAMPLES:: - sage: F = CombinatorialFreeModule(ZZ, [4,5]); F.rename("F") # optional - sage.modules - sage: G = CombinatorialFreeModule(ZZ, [4,6]); G.rename("G") # optional - sage.modules - sage: S = cartesian_product([F, G]) # optional - sage.modules - sage: x = (S.monomial((0,4)) + 2 * S.monomial((0,5)) # optional - sage.modules + sage: # needs sage.modules + sage: F = CombinatorialFreeModule(ZZ, [4,5]); F.rename("F") + sage: G = CombinatorialFreeModule(ZZ, [4,6]); G.rename("G") + sage: S = cartesian_product([F, G]) + sage: x = (S.monomial((0,4)) + 2 * S.monomial((0,5)) ....: + 3 * S.monomial((1,6))) - sage: x.cartesian_projection(0) # optional - sage.modules + sage: x.cartesian_projection(0) B[4] + 2*B[5] - sage: x.cartesian_projection(1) # optional - sage.modules + sage: x.cartesian_projection(1) 3*B[6] """ return self.parent().cartesian_projection(i)(self) @@ -2611,20 +2616,21 @@ def cartesian_factors(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(ZZ, [4,5]); F.rename("F") # optional - sage.modules - sage: G = CombinatorialFreeModule(ZZ, [4,6]); G.rename("G") # optional - sage.modules - sage: H = CombinatorialFreeModule(ZZ, [4,7]); H.rename("H") # optional - sage.modules - sage: S = cartesian_product([F, G, H]) # optional - sage.modules - sage: x = (S.monomial((0,4)) + 2 * S.monomial((0,5)) # optional - sage.modules + sage: # needs sage.modules + sage: F = CombinatorialFreeModule(ZZ, [4,5]); F.rename("F") + sage: G = CombinatorialFreeModule(ZZ, [4,6]); G.rename("G") + sage: H = CombinatorialFreeModule(ZZ, [4,7]); H.rename("H") + sage: S = cartesian_product([F, G, H]) + sage: x = (S.monomial((0,4)) + 2 * S.monomial((0,5)) ....: + 3 * S.monomial((1,6)) + 4 * S.monomial((2,4)) ....: + 5 * S.monomial((2,7))) - sage: x.cartesian_factors() # optional - sage.modules + sage: x.cartesian_factors() (B[4] + 2*B[5], 3*B[6], 4*B[4] + 5*B[7]) - sage: [s.parent() for s in x.cartesian_factors()] # optional - sage.modules + sage: [s.parent() for s in x.cartesian_factors()] [F, G, H] - sage: S.zero().cartesian_factors() # optional - sage.modules + sage: S.zero().cartesian_factors() (0, 0, 0) - sage: [s.parent() for s in S.zero().cartesian_factors()] # optional - sage.modules + sage: [s.parent() for s in S.zero().cartesian_factors()] [F, G, H] """ # TODO: optimize @@ -2644,7 +2650,7 @@ def extra_super_categories(self): sage: Sets().Algebras(QQ).extra_super_categories() [Category of vector spaces with basis over Rational Field] - sage: Sets().example().algebra(ZZ).categories() # optional - sage.groups sage.modules + sage: Sets().example().algebra(ZZ).categories() # needs sage.modules [Category of set algebras over Integer Ring, Category of modules with basis over Integer Ring, ... @@ -2661,20 +2667,20 @@ def construction(self): EXAMPLES:: - sage: A = GroupAlgebra(KleinFourGroup(), QQ) # optional - sage.groups sage.modules - sage: F, arg = A.construction(); F, arg # optional - sage.groups sage.modules + sage: A = GroupAlgebra(KleinFourGroup(), QQ) # needs sage.groups sage.modules + sage: F, arg = A.construction(); F, arg # needs sage.groups sage.modules (GroupAlgebraFunctor, Rational Field) - sage: F(arg) is A # optional - sage.groups sage.modules + sage: F(arg) is A # needs sage.groups sage.modules True This also works for structures such as monoid algebras (see :trac:`27937`):: - sage: A = FreeAbelianMonoid('x,y').algebra(QQ) # optional - sage.groups sage.modules - sage: F, arg = A.construction(); F, arg # optional - sage.groups sage.modules + sage: A = FreeAbelianMonoid('x,y').algebra(QQ) # needs sage.groups sage.modules + sage: F, arg = A.construction(); F, arg # needs sage.groups sage.modules (The algebra functorial construction, Free abelian monoid on 2 generators (x, y)) - sage: F(arg) is A # optional - sage.groups sage.modules + sage: F(arg) is A # needs sage.groups sage.modules True """ from sage.categories.algebra_functor import ( @@ -2692,14 +2698,15 @@ def _repr_(self): EXAMPLES:: - sage: A = Groups().example().algebra(QQ); A # optional - sage.groups sage.modules + sage: # needs sage.groups sage.modules + sage: A = Groups().example().algebra(QQ); A Algebra of General Linear Group of degree 4 over Rational Field over Rational Field - sage: A._name = "foo" # optional - sage.groups sage.modules - sage: A # optional - sage.groups sage.modules + sage: A._name = "foo" + sage: A foo over Rational Field - sage: A = KleinFourGroup().algebra(ZZ) # optional - sage.groups sage.modules - sage: A # optional - sage.groups sage.modules + sage: A = KleinFourGroup().algebra(ZZ) + sage: A Algebra of The Klein 4 group of order 4, as a permutation group over Integer Ring """ @@ -2731,10 +2738,10 @@ def example(self, base_ring=None, set=None): EXAMPLES:: - sage: Sets().WithRealizations().example() # optional - sage.combinat sage.modules + sage: Sets().WithRealizations().example() # needs sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: Sets().WithRealizations().example(ZZ, Set([1,2])) # optional - sage.combinat sage.modules + sage: Sets().WithRealizations().example(ZZ, Set([1,2])) # needs sage.modules The subset algebra of {1, 2} over Integer Ring """ from sage.rings.rational_field import QQ @@ -2760,8 +2767,8 @@ def _test_with_realizations(self, **options): EXAMPLES:: - sage: A = Sets().WithRealizations().example() # optional - sage.combinat sage.modules - sage: A._test_with_realizations() # optional - sage.combinat sage.modules + sage: A = Sets().WithRealizations().example() # needs sage.modules + sage: A._test_with_realizations() # needs sage.modules See the documentation for :class:`TestSuite` for more information. @@ -2791,15 +2798,16 @@ def _register_realization(self, realization): """ EXAMPLES:: - sage: A = Sets().WithRealizations().example(QQ['x']); A # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: A = Sets().WithRealizations().example(QQ['x']); A The subset algebra of {1, 2, 3} over Univariate Polynomial Ring in x over Rational Field - sage: class ANewRealizationOfA(CombinatorialFreeModule): # optional - sage.combinat sage.modules + sage: class ANewRealizationOfA(CombinatorialFreeModule): ....: pass - sage: category = A.Realizations() & Algebras(QQ['x']).WithBasis() # optional - sage.combinat sage.modules - sage: R = ANewRealizationOfA(A.base_ring(), A.F().basis().keys(), # optional - sage.combinat sage.modules + sage: category = A.Realizations() & Algebras(QQ['x']).WithBasis() + sage: R = ANewRealizationOfA(A.base_ring(), A.F().basis().keys(), ....: category=category) - sage: R in A.realizations() # indirect doctest # optional - sage.combinat sage.modules + sage: R in A.realizations() # indirect doctest True Note: the test above uses ``QQ[x]`` to not interfer @@ -2827,16 +2835,17 @@ def inject_shorthands(self, shorthands=None, verbose=True): it is convenient to define shorthands for the various realizations, but cumbersome to do it by hand:: - sage: S = SymmetricFunctions(ZZ); S # optional - sage.combinat + sage: S = SymmetricFunctions(ZZ); S # needs sage.combinat sage.modules Symmetric Functions over Integer Ring - sage: s = S.s(); s # optional - sage.combinat + sage: s = S.s(); s # needs sage.combinat sage.modules Symmetric Functions over Integer Ring in the Schur basis - sage: e = S.e(); e # optional - sage.combinat + sage: e = S.e(); e # needs sage.combinat sage.modules Symmetric Functions over Integer Ring in the elementary basis This method automates the process:: - sage: S.inject_shorthands() # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: S.inject_shorthands() Defining e as shorthand for Symmetric Functions over Integer Ring in the elementary basis Defining f as shorthand for @@ -2849,22 +2858,21 @@ def inject_shorthands(self, shorthands=None, verbose=True): Symmetric Functions over Integer Ring in the powersum basis Defining s as shorthand for Symmetric Functions over Integer Ring in the Schur basis - sage: s[1] + e[2] * p[1,1] + 2*h[3] + m[2,1] # optional - sage.combinat + sage: s[1] + e[2] * p[1,1] + 2*h[3] + m[2,1] s[1] - 2*s[1, 1, 1] + s[1, 1, 1, 1] + s[2, 1] + 2*s[2, 1, 1] + s[2, 2] + 2*s[3] + s[3, 1] - - sage: e # optional - sage.combinat + sage: e Symmetric Functions over Integer Ring in the elementary basis - sage: p # optional - sage.combinat + sage: p Symmetric Functions over Integer Ring in the powersum basis - sage: s # optional - sage.combinat + sage: s Symmetric Functions over Integer Ring in the Schur basis Sometimes, like for symmetric functions, one can request for all shorthands to be defined, including less common ones:: - sage: S.inject_shorthands("all") # optional - sage.combinat + sage: S.inject_shorthands("all") # needs sage.combinat sage.modules Defining e as shorthand for Symmetric Functions over Integer Ring in the elementary basis Defining f as shorthand for @@ -2892,37 +2900,37 @@ def inject_shorthands(self, shorthands=None, verbose=True): The messages can be silenced by setting ``verbose=False``:: - sage: Q = QuasiSymmetricFunctions(ZZ) # optional - sage.combinat - sage: Q.inject_shorthands(verbose=False) # optional - sage.combinat - - sage: F[1,2,1] + 5*M[1,3] + F[2]^2 # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: Q = QuasiSymmetricFunctions(ZZ) + sage: Q.inject_shorthands(verbose=False) + sage: F[1,2,1] + 5*M[1,3] + F[2]^2 5*F[1, 1, 1, 1] - 5*F[1, 1, 2] - 3*F[1, 2, 1] + 6*F[1, 3] + 2*F[2, 2] + F[3, 1] + F[4] - - sage: F # optional - sage.combinat + sage: F Quasisymmetric functions over the Integer Ring in the Fundamental basis - sage: M # optional - sage.combinat + sage: M Quasisymmetric functions over the Integer Ring in the Monomial basis One can also just import a subset of the shorthands:: - sage: SQ = SymmetricFunctions(QQ) # optional - sage.combinat - sage: SQ.inject_shorthands(['p', 's'], verbose=False) # optional - sage.combinat - sage: p # optional - sage.combinat + sage: # needs sage.combinat sage.modules + sage: SQ = SymmetricFunctions(QQ) + sage: SQ.inject_shorthands(['p', 's'], verbose=False) + sage: p Symmetric Functions over Rational Field in the powersum basis - sage: s # optional - sage.combinat + sage: s Symmetric Functions over Rational Field in the Schur basis Note that ``e`` is left unchanged:: - sage: e # optional - sage.combinat + sage: e # needs sage.combinat sage.modules Symmetric Functions over Integer Ring in the elementary basis TESTS:: - sage: e == S.e(), h == S.h(), m == S.m(), p == SQ.p(), s == SQ.s() # optional - sage.combinat + sage: e == S.e(), h == S.h(), m == S.m(), p == SQ.p(), s == SQ.s() # needs sage.combinat sage.modules (True, True, True, True, True) """ from sage.misc.misc import inject_variable @@ -2945,9 +2953,9 @@ def a_realization(self): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules + sage: A = Sets().WithRealizations().example(); A # needs sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: A.a_realization() # optional - sage.combinat sage.modules + sage: A.a_realization() # needs sage.modules The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis """ @@ -2959,9 +2967,9 @@ def realizations(self): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules + sage: A = Sets().WithRealizations().example(); A # needs sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: A.realizations() # optional - sage.combinat sage.modules + sage: A.realizations() # needs sage.modules [The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis, The subset algebra of {1, 2, 3} over Rational Field in the In basis, The subset algebra of {1, 2, 3} over Rational Field in the Out basis] @@ -2981,22 +2989,23 @@ def facade_for(self): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules + sage: A = Sets().WithRealizations().example(); A # needs sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: A.facade_for() # optional - sage.combinat sage.modules + sage: A.facade_for() # needs sage.modules [The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis, The subset algebra of {1, 2, 3} over Rational Field in the In basis, The subset algebra of {1, 2, 3} over Rational Field in the Out basis] - sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: A = Sets().WithRealizations().example(); A The subset algebra of {1, 2, 3} over Rational Field - sage: f = A.F().an_element(); f # optional - sage.combinat sage.modules + sage: f = A.F().an_element(); f F[{}] + 2*F[{1}] + 3*F[{2}] + F[{1, 2}] - sage: i = A.In().an_element(); i # optional - sage.combinat sage.modules + sage: i = A.In().an_element(); i In[{}] + 2*In[{1}] + 3*In[{2}] + In[{1, 2}] - sage: o = A.Out().an_element(); o # optional - sage.combinat sage.modules + sage: o = A.Out().an_element(); o Out[{}] + 2*Out[{1}] + 3*Out[{2}] + Out[{1, 2}] - sage: f in A, i in A, o in A # optional - sage.combinat sage.modules + sage: f in A, i in A, o in A (True, True, True) """ return self.realizations() @@ -3008,9 +3017,9 @@ def super_categories(self): """ EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules + sage: A = Sets().WithRealizations().example(); A # needs sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: A.Realizations().super_categories() # optional - sage.combinat sage.modules + sage: A.Realizations().super_categories() # needs sage.modules [Category of realizations of sets] """ return [Sets().Realizations()] @@ -3021,9 +3030,9 @@ def _an_element_(self): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules + sage: A = Sets().WithRealizations().example(); A # needs sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: A.an_element() # indirect doctest # optional - sage.combinat sage.modules + sage: A.an_element() # indirect doctest # needs sage.modules F[{}] + 2*F[{1}] + 3*F[{2}] + F[{1, 2}] TESTS: @@ -3031,9 +3040,9 @@ def _an_element_(self): Check that we are consistent no matter which basis is created first:: - sage: M = posets.BooleanLattice(4).moebius_algebra(QQ) # optional - sage.combinat sage.graphs sage.modules - sage: I = M.I() # optional - sage.combinat sage.graphs sage.modules - sage: M._an_element_() # optional - sage.combinat sage.graphs sage.modules + sage: M = posets.BooleanLattice(4).moebius_algebra(QQ) # needs sage.combinat sage.graphs sage.modules + sage: I = M.I() # needs sage.combinat sage.graphs sage.modules + sage: M._an_element_() # needs sage.combinat sage.graphs sage.modules 2*E[0] + 2*E[1] + 3*E[2] """ return self.a_realization().an_element() @@ -3046,19 +3055,20 @@ def __contains__(self, x): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: A = Sets().WithRealizations().example(); A The subset algebra of {1, 2, 3} over Rational Field - sage: A.an_element() in A # optional - sage.combinat sage.modules + sage: A.an_element() in A True - sage: A.In().an_element() in A # optional - sage.combinat sage.modules + sage: A.In().an_element() in A True - sage: A.F().an_element() in A # optional - sage.combinat sage.modules + sage: A.F().an_element() in A True - sage: A.Out().an_element() in A # optional - sage.combinat sage.modules + sage: A.Out().an_element() in A True - sage: 1 in A # optional - sage.combinat sage.modules + sage: 1 in A True - sage: QQ['x'].an_element() in A # optional - sage.combinat sage.modules + sage: QQ['x'].an_element() in A False """ return any(x in realization for realization in self.realizations()) @@ -3073,8 +3083,8 @@ def __init_extra__(self): TESTS:: - sage: A = Sets().WithRealizations().example() # optional - sage.combinat sage.modules - sage: A.realizations() # indirect doctest # optional - sage.combinat sage.modules + sage: A = Sets().WithRealizations().example() # needs sage.modules + sage: A.realizations() # indirect doctest # needs sage.modules [The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis, The subset algebra of {1, 2, 3} over Rational Field in the In basis, The subset algebra of {1, 2, 3} over Rational Field in the Out basis] @@ -3088,11 +3098,11 @@ def realization_of(self): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules + sage: A = Sets().WithRealizations().example(); A # needs sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: In = A.In(); In # optional - sage.combinat sage.modules + sage: In = A.In(); In # needs sage.modules The subset algebra of {1, 2, 3} over Rational Field in the In basis - sage: In.realization_of() # optional - sage.combinat sage.modules + sage: In.realization_of() # needs sage.modules The subset algebra of {1, 2, 3} over Rational Field """ for category in self.categories(): @@ -3108,11 +3118,11 @@ def _realization_name(self): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules + sage: A = Sets().WithRealizations().example(); A # needs sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: In = A.In(); In # optional - sage.combinat sage.modules + sage: In = A.In(); In # needs sage.modules The subset algebra of {1, 2, 3} over Rational Field in the In basis - sage: In._realization_name() # optional - sage.combinat sage.modules + sage: In._realization_name() # needs sage.modules 'In' """ # The __base__ gets rid of the with_category @@ -3123,9 +3133,9 @@ def _repr_(self): """ EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules + sage: A = Sets().WithRealizations().example(); A # needs sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: In = A.In(); In # optional - sage.combinat sage.modules + sage: In = A.In(); In # needs sage.modules The subset algebra of {1, 2, 3} over Rational Field in the In basis In the example above, :meth:`repr` was overridden by @@ -3137,9 +3147,9 @@ def _repr_(self): sage: from sage.categories.realizations import Realizations sage: class Blah(Parent): ....: pass - sage: C = Sets.WithRealizations.ParentMethods.Realizations(A) # optional - sage.combinat sage.modules - sage: P = Blah(category=C) # optional - sage.combinat sage.modules - sage: P # indirect doctest # optional - sage.combinat sage.modules + sage: C = Sets.WithRealizations.ParentMethods.Realizations(A) # needs sage.modules + sage: P = Blah(category=C) # needs sage.modules + sage: P # indirect doctest # needs sage.modules The subset algebra of {1, 2, 3} over Rational Field in the realization Blah """ return "{} in the realization {}".format(self.realization_of(), self._realization_name()) diff --git a/src/sage/categories/sets_with_grading.py b/src/sage/categories/sets_with_grading.py index a9cc219e06e..b1e321f67f2 100644 --- a/src/sage/categories/sets_with_grading.py +++ b/src/sage/categories/sets_with_grading.py @@ -161,9 +161,9 @@ def subset(self, *args, **options): EXAMPLES:: - sage: W = WeightedIntegerVectors([3,2,1]); W # optional - sage.combinat + sage: W = WeightedIntegerVectors([3,2,1]); W # needs sage.combinat Integer vectors weighted by [3, 2, 1] - sage: W.subset(4) # optional - sage.combinat + sage: W.subset(4) # needs sage.combinat Integer vectors of 4 weighted by [3, 2, 1] """ @@ -213,7 +213,7 @@ def generating_series(self): sage: N.generating_series() 1/(-z + 1) - sage: Permutations().generating_series() # optional - sage.combinat + sage: Permutations().generating_series() # needs sage.combinat 1 + z + 2*z^2 + 6*z^3 + 24*z^4 + 120*z^5 + 720*z^6 + O(z^7) .. TODO:: diff --git a/src/sage/categories/simplicial_complexes.py b/src/sage/categories/simplicial_complexes.py index 87c266858d8..9750dcab686 100644 --- a/src/sage/categories/simplicial_complexes.py +++ b/src/sage/categories/simplicial_complexes.py @@ -67,8 +67,8 @@ def dimension(self): EXAMPLES:: - sage: S = SimplicialComplex([[1,3,4], [1,2],[2,5],[4,5]]) # optional - sage.graphs - sage: S.dimension() # optional - sage.graphs + sage: S = SimplicialComplex([[1,3,4], [1,2],[2,5],[4,5]]) # needs sage.graphs + sage: S.dimension() # needs sage.graphs 2 """ return max(c.dimension() for c in self.facets()) @@ -81,8 +81,8 @@ def facets(self): EXAMPLES:: - sage: S = SimplicialComplex([[1,3,4], [1,2],[2,5],[4,5]]) # optional - sage.graphs - sage: sorted(S.facets()) # optional - sage.graphs + sage: S = SimplicialComplex([[1,3,4], [1,2],[2,5],[4,5]]) # needs sage.graphs + sage: sorted(S.facets()) # needs sage.graphs [(1, 2), (1, 3, 4), (2, 5), (4, 5)] """ @@ -93,8 +93,8 @@ def faces(self): EXAMPLES:: - sage: S = SimplicialComplex([[1,3,4], [1,2],[2,5],[4,5]]) # optional - sage.graphs - sage: S.faces() # optional - sage.graphs + sage: S = SimplicialComplex([[1,3,4], [1,2],[2,5],[4,5]]) # needs sage.graphs + sage: S.faces() # needs sage.graphs {-1: {()}, 0: {(1,), (2,), (3,), (4,), (5,)}, 1: {(1, 2), (1, 3), (1, 4), (2, 5), (3, 4), (4, 5)}, diff --git a/src/sage/categories/simplicial_sets.py b/src/sage/categories/simplicial_sets.py index 4558f139874..c07871402fd 100644 --- a/src/sage/categories/simplicial_sets.py +++ b/src/sage/categories/simplicial_sets.py @@ -71,10 +71,10 @@ def is_finite(self): EXAMPLES:: - sage: simplicial_sets.Torus().is_finite() # optional - sage.graphs + sage: simplicial_sets.Torus().is_finite() # needs sage.graphs True - sage: C5 = groups.misc.MultiplicativeAbelian([5]) # optional - sage.graphs sage.groups - sage: simplicial_sets.ClassifyingSpace(C5).is_finite() # optional - sage.graphs sage.groups + sage: C5 = groups.misc.MultiplicativeAbelian([5]) # needs sage.graphs sage.groups + sage: simplicial_sets.ClassifyingSpace(C5).is_finite() # needs sage.graphs sage.groups False """ return SimplicialSets.Finite() in self.categories() @@ -86,15 +86,16 @@ def is_pointed(self): EXAMPLES:: - sage: from sage.topology.simplicial_set import AbstractSimplex, SimplicialSet # optional - sage.graphs - sage: v = AbstractSimplex(0) # optional - sage.graphs - sage: w = AbstractSimplex(0) # optional - sage.graphs - sage: e = AbstractSimplex(1) # optional - sage.graphs - sage: X = SimplicialSet({e: (v, w)}) # optional - sage.graphs - sage: Y = SimplicialSet({e: (v, w)}, base_point=w) # optional - sage.graphs - sage: X.is_pointed() # optional - sage.graphs + sage: # needs sage.graphs + sage: from sage.topology.simplicial_set import AbstractSimplex, SimplicialSet + sage: v = AbstractSimplex(0) + sage: w = AbstractSimplex(0) + sage: e = AbstractSimplex(1) + sage: X = SimplicialSet({e: (v, w)}) + sage: Y = SimplicialSet({e: (v, w)}, base_point=w) + sage: X.is_pointed() False - sage: Y.is_pointed() # optional - sage.graphs + sage: Y.is_pointed() True """ return SimplicialSets.Pointed() in self.categories() @@ -110,29 +111,30 @@ def set_base_point(self, point): EXAMPLES:: - sage: from sage.topology.simplicial_set import AbstractSimplex, SimplicialSet # optional - sage.graphs - sage: v = AbstractSimplex(0, name='v_0') # optional - sage.graphs - sage: w = AbstractSimplex(0, name='w_0') # optional - sage.graphs - sage: e = AbstractSimplex(1) # optional - sage.graphs - sage: X = SimplicialSet({e: (v, w)}) # optional - sage.graphs - sage: Y = SimplicialSet({e: (v, w)}, base_point=w) # optional - sage.graphs - sage: Y.base_point() # optional - sage.graphs + sage: # needs sage.graphs + sage: from sage.topology.simplicial_set import AbstractSimplex, SimplicialSet + sage: v = AbstractSimplex(0, name='v_0') + sage: w = AbstractSimplex(0, name='w_0') + sage: e = AbstractSimplex(1) + sage: X = SimplicialSet({e: (v, w)}) + sage: Y = SimplicialSet({e: (v, w)}, base_point=w) + sage: Y.base_point() w_0 - sage: X_star = X.set_base_point(w) # optional - sage.graphs - sage: X_star.base_point() # optional - sage.graphs + sage: X_star = X.set_base_point(w) + sage: X_star.base_point() w_0 - sage: Y_star = Y.set_base_point(v) # optional - sage.graphs - sage: Y_star.base_point() # optional - sage.graphs + sage: Y_star = Y.set_base_point(v) + sage: Y_star.base_point() v_0 TESTS:: - sage: X.set_base_point(e) # optional - sage.graphs + sage: X.set_base_point(e) # needs sage.graphs Traceback (most recent call last): ... ValueError: the "point" is not a zero-simplex - sage: pt = AbstractSimplex(0) # optional - sage.graphs - sage: X.set_base_point(pt) # optional - sage.graphs + sage: pt = AbstractSimplex(0) # needs sage.graphs + sage: X.set_base_point(pt) # needs sage.graphs Traceback (most recent call last): ... ValueError: the point is not a simplex in this simplicial set @@ -154,8 +156,8 @@ def one(self): EXAMPLES:: - sage: T = simplicial_sets.Torus() # optional - sage.graphs - sage: Hom(T, T).identity() # optional - sage.graphs + sage: T = simplicial_sets.Torus() # needs sage.graphs + sage: Hom(T, T).identity() # needs sage.graphs Simplicial set endomorphism of Torus Defn: Identity map """ @@ -197,13 +199,14 @@ def base_point(self): EXAMPLES:: - sage: from sage.topology.simplicial_set import AbstractSimplex, SimplicialSet # optional - sage.graphs - sage: v = AbstractSimplex(0, name='*') # optional - sage.graphs - sage: e = AbstractSimplex(1) # optional - sage.graphs - sage: S1 = SimplicialSet({e: (v, v)}, base_point=v) # optional - sage.graphs - sage: S1.is_pointed() # optional - sage.graphs + sage: # needs sage.graphs + sage: from sage.topology.simplicial_set import AbstractSimplex, SimplicialSet + sage: v = AbstractSimplex(0, name='*') + sage: e = AbstractSimplex(1) + sage: S1 = SimplicialSet({e: (v, v)}, base_point=v) + sage: S1.is_pointed() True - sage: S1.base_point() # optional - sage.graphs + sage: S1.base_point() * """ return self._basepoint @@ -226,26 +229,27 @@ def base_point_map(self, domain=None): EXAMPLES:: - sage: T = simplicial_sets.Torus() # optional - sage.graphs - sage: f = T.base_point_map(); f # optional - sage.graphs + sage: # needs sage.graphs + sage: T = simplicial_sets.Torus() + sage: f = T.base_point_map(); f Simplicial set morphism: From: Point To: Torus Defn: Constant map at (v_0, v_0) - sage: S3 = simplicial_sets.Sphere(3) # optional - sage.graphs - sage: g = S3.base_point_map() # optional - sage.graphs - sage: f.domain() == g.domain() # optional - sage.graphs + sage: S3 = simplicial_sets.Sphere(3) + sage: g = S3.base_point_map() + sage: f.domain() == g.domain() True - sage: RP3 = simplicial_sets.RealProjectiveSpace(3) # optional - sage.graphs sage.groups - sage: temp = simplicial_sets.Simplex(0) # optional - sage.graphs sage.groups - sage: pt = temp.set_base_point(temp.n_cells(0)[0]) # optional - sage.graphs sage.groups - sage: h = RP3.base_point_map(domain=pt) # optional - sage.graphs sage.groups - sage: f.domain() == h.domain() # optional - sage.graphs sage.groups + sage: RP3 = simplicial_sets.RealProjectiveSpace(3) # needs sage.groups + sage: temp = simplicial_sets.Simplex(0) + sage: pt = temp.set_base_point(temp.n_cells(0)[0]) + sage: h = RP3.base_point_map(domain=pt) # needs sage.groups + sage: f.domain() == h.domain() # needs sage.groups False - sage: C5 = groups.misc.MultiplicativeAbelian([5]) # optional - sage.graphs sage.groups - sage: BC5 = simplicial_sets.ClassifyingSpace(C5) # optional - sage.graphs sage.groups - sage: BC5.base_point_map() # optional - sage.graphs sage.groups + sage: C5 = groups.misc.MultiplicativeAbelian([5]) # needs sage.graphs sage.groups + sage: BC5 = simplicial_sets.ClassifyingSpace(C5) # needs sage.graphs sage.groups + sage: BC5.base_point_map() # needs sage.graphs sage.groups Simplicial set morphism: From: Point To: Classifying space of Multiplicative Abelian group isomorphic to C5 @@ -285,49 +289,51 @@ def fundamental_group(self, simplify=True): EXAMPLES:: - sage: S1 = simplicial_sets.Sphere(1) # optional - sage.graphs - sage: eight = S1.wedge(S1) # optional - sage.graphs - sage: eight.fundamental_group() # free group on 2 generators # optional - sage.graphs sage.groups + sage: S1 = simplicial_sets.Sphere(1) # needs sage.graphs + sage: eight = S1.wedge(S1) # needs sage.graphs + sage: eight.fundamental_group() # free group on 2 generators # needs sage.graphs sage.groups Finitely presented group < e0, e1 | > The fundamental group of a disjoint union of course depends on the choice of base point:: - sage: T = simplicial_sets.Torus() # optional - sage.graphs - sage: K = simplicial_sets.KleinBottle() # optional - sage.graphs - sage: X = T.disjoint_union(K) # optional - sage.graphs + sage: T = simplicial_sets.Torus() # needs sage.graphs + sage: K = simplicial_sets.KleinBottle() # needs sage.graphs + sage: X = T.disjoint_union(K) # needs sage.graphs - sage: X_0 = X.set_base_point(X.n_cells(0)[0]) # optional - sage.graphs - sage: X_0.fundamental_group().is_abelian() # optional - sage.graphs sage.groups + sage: # needs sage.graphs + sage: X_0 = X.set_base_point(X.n_cells(0)[0]) + sage: X_0.fundamental_group().is_abelian() # needs sage.groups True - sage: X_1 = X.set_base_point(X.n_cells(0)[1]) # optional - sage.graphs - sage: X_1.fundamental_group().is_abelian() # optional - sage.graphs sage.groups + sage: X_1 = X.set_base_point(X.n_cells(0)[1]) + sage: X_1.fundamental_group().is_abelian() # needs sage.groups False - sage: RP3 = simplicial_sets.RealProjectiveSpace(3) # optional - sage.graphs sage.groups - sage: RP3.fundamental_group() # optional - sage.graphs sage.groups + sage: RP3 = simplicial_sets.RealProjectiveSpace(3) # needs sage.graphs sage.groups + sage: RP3.fundamental_group() # needs sage.graphs sage.groups Finitely presented group < e | e^2 > Compute the fundamental group of some classifying spaces:: - sage: C5 = groups.misc.MultiplicativeAbelian([5]) # optional - sage.graphs sage.groups - sage: BC5 = C5.nerve() # optional - sage.graphs sage.groups - sage: BC5.fundamental_group() # optional - sage.graphs sage.groups + sage: C5 = groups.misc.MultiplicativeAbelian([5]) # needs sage.graphs sage.groups + sage: BC5 = C5.nerve() # needs sage.graphs sage.groups + sage: BC5.fundamental_group() # needs sage.graphs sage.groups Finitely presented group < e0 | e0^5 > - sage: Sigma3 = groups.permutation.Symmetric(3) # optional - sage.graphs sage.groups - sage: BSigma3 = Sigma3.nerve() # optional - sage.graphs sage.groups - sage: pi = BSigma3.fundamental_group(); pi # optional - sage.graphs sage.groups + sage: # needs sage.graphs sage.groups + sage: Sigma3 = groups.permutation.Symmetric(3) + sage: BSigma3 = Sigma3.nerve() + sage: pi = BSigma3.fundamental_group(); pi Finitely presented group < e1, e2 | e2^2, e1^3, (e2*e1)^2 > - sage: pi.order() # optional - sage.graphs sage.groups + sage: pi.order() 6 - sage: pi.is_abelian() # optional - sage.graphs sage.groups + sage: pi.is_abelian() False The sphere has a trivial fundamental group:: - sage: S2 = simplicial_sets.Sphere(2) # optional - sage.graphs - sage: S2.fundamental_group() # optional - sage.graphs sage.groups + sage: S2 = simplicial_sets.Sphere(2) # needs sage.graphs + sage: S2.fundamental_group() # needs sage.graphs sage.groups Finitely presented group < | > """ # Import this here to prevent importing libgap upon startup. @@ -347,10 +353,10 @@ def _universal_cover_dict(self): TESTS:: - sage: RP2 = simplicial_sets.RealProjectiveSpace(2) # optional - sage.groups - sage: RP2._universal_cover_dict() # optional - sage.groups + sage: RP2 = simplicial_sets.RealProjectiveSpace(2) # needs sage.groups + sage: RP2._universal_cover_dict() # needs sage.groups (Finitely presented group < e | e^2 >, {f: e}) - sage: RP2.nondegenerate_simplices() # optional - sage.groups + sage: RP2.nondegenerate_simplices() # needs sage.groups [1, f, f * f] """ from sage.groups.free_group import FreeGroup @@ -393,14 +399,14 @@ def universal_cover_map(self): EXAMPLES:: - sage: RP2 = simplicial_sets.RealProjectiveSpace(2) # optional - sage.groups - sage: phi = RP2.universal_cover_map(); phi # optional - sage.groups + sage: RP2 = simplicial_sets.RealProjectiveSpace(2) # needs sage.groups + sage: phi = RP2.universal_cover_map(); phi # needs sage.groups Simplicial set morphism: From: Simplicial set with 6 non-degenerate simplices To: RP^2 Defn: [(1, 1), (1, e), (f, 1), (f, e), (f * f, 1), (f * f, e)] --> [1, 1, f, f, f * f, f * f] - sage: phi.domain().face_data() # optional - sage.groups + sage: phi.domain().face_data() # needs sage.groups {(1, 1): None, (1, e): None, (f, 1): ((1, e), (1, 1)), @@ -431,11 +437,12 @@ def covering_map(self, character): EXAMPLES:: - sage: S1 = simplicial_sets.Sphere(1) # optional - sage.graphs - sage: W = S1.wedge(S1) # optional - sage.graphs - sage: G = CyclicPermutationGroup(3) # optional - sage.groups - sage: a, b = W.n_cells(1) # optional - sage.graphs - sage: C = W.covering_map({a : G.gen(0), b : G.one()}); C # optional - sage.graphs sage.groups + sage: # needs sage.graphs sage.groups + sage: S1 = simplicial_sets.Sphere(1) + sage: W = S1.wedge(S1) + sage: G = CyclicPermutationGroup(3) + sage: a, b = W.n_cells(1) + sage: C = W.covering_map({a : G.gen(0), b : G.one()}); C Simplicial set morphism: From: Simplicial set with 9 non-degenerate simplices To: Wedge: (S^1 v S^1) @@ -443,9 +450,9 @@ def covering_map(self, character): (sigma_1, ()), (sigma_1, (1,2,3)), (sigma_1, (1,2,3)), (sigma_1, (1,3,2)), (sigma_1, (1,3,2))] --> [*, *, *, sigma_1, sigma_1, sigma_1, sigma_1, sigma_1, sigma_1] - sage: C.domain() # optional - sage.graphs sage.groups + sage: C.domain() Simplicial set with 9 non-degenerate simplices - sage: C.domain().face_data() # optional - sage.graphs sage.groups + sage: C.domain().face_data() {(*, ()): None, (*, (1,2,3)): None, (*, (1,3,2)): None, @@ -518,12 +525,13 @@ def cover(self, character): EXAMPLES:: - sage: S1 = simplicial_sets.Sphere(1) # optional - sage.graphs - sage: W = S1.wedge(S1) # optional - sage.graphs - sage: G = CyclicPermutationGroup(3) # optional - sage.groups - sage: (a, b) = W.n_cells(1) # optional - sage.graphs - sage: C = W.cover({a : G.gen(0), b : G.gen(0)^2}) # optional - sage.graphs sage.groups - sage: C.face_data() # optional - sage.graphs sage.groups + sage: # needs sage.graphs sage.groups + sage: S1 = simplicial_sets.Sphere(1) + sage: W = S1.wedge(S1) + sage: G = CyclicPermutationGroup(3) + sage: (a, b) = W.n_cells(1) + sage: C = W.cover({a : G.gen(0), b : G.gen(0)^2}) + sage: C.face_data() {(*, ()): None, (*, (1,2,3)): None, (*, (1,3,2)): None, @@ -533,9 +541,9 @@ def cover(self, character): (sigma_1, (1,2,3)): ((*, ()), (*, (1,2,3))), (sigma_1, (1,3,2)): ((*, ()), (*, (1,3,2))), (sigma_1, (1,3,2)): ((*, (1,2,3)), (*, (1,3,2)))} - sage: C.homology(1) # optional - sage.graphs sage.groups sage.modules + sage: C.homology(1) # needs sage.modules Z x Z x Z x Z - sage: C.fundamental_group() # optional - sage.graphs sage.groups + sage: C.fundamental_group() Finitely presented group < e0, e1, e2, e3 | > """ return self.covering_map(character).domain() @@ -548,10 +556,11 @@ def universal_cover(self): EXAMPLES:: - sage: RP3 = simplicial_sets.RealProjectiveSpace(3) # optional - sage.groups - sage: C = RP3.universal_cover(); C # optional - sage.groups + sage: # needs sage.groups + sage: RP3 = simplicial_sets.RealProjectiveSpace(3) + sage: C = RP3.universal_cover(); C Simplicial set with 8 non-degenerate simplices - sage: C.face_data() # optional - sage.groups + sage: C.face_data() {(1, 1): None, (1, e): None, (f, 1): ((1, e), (1, 1)), @@ -560,7 +569,7 @@ def universal_cover(self): (f * f, e): ((f, 1), s_0 (1, e), (f, e)), (f * f * f, 1): ((f * f, e), s_0 (f, 1), s_1 (f, 1), (f * f, 1)), (f * f * f, e): ((f * f, 1), s_0 (f, e), s_1 (f, e), (f * f, e))} - sage: C.fundamental_group() # optional - sage.groups + sage: C.fundamental_group() Finitely presented group < | > """ return self.universal_cover_map().domain() @@ -579,26 +588,28 @@ def is_simply_connected(self): EXAMPLES:: - sage: T = simplicial_sets.Torus() # optional - sage.graphs - sage: T.is_simply_connected() # optional - sage.graphs sage.groups + sage: # needs sage.graphs sage.groups + sage: T = simplicial_sets.Torus() + sage: T.is_simply_connected() False - sage: T.suspension().is_simply_connected() # optional - sage.graphs sage.groups + sage: T.suspension().is_simply_connected() True - sage: simplicial_sets.KleinBottle().is_simply_connected() # optional - sage.graphs sage.groups + sage: simplicial_sets.KleinBottle().is_simply_connected() False - sage: S2 = simplicial_sets.Sphere(2) # optional - sage.graphs - sage: S3 = simplicial_sets.Sphere(3) # optional - sage.graphs - sage: (S2.wedge(S3)).is_simply_connected() # optional - sage.graphs sage.groups + sage: # needs sage.graphs + sage: S2 = simplicial_sets.Sphere(2) + sage: S3 = simplicial_sets.Sphere(3) + sage: (S2.wedge(S3)).is_simply_connected() # needs sage.groups True - sage: X = S2.disjoint_union(S3) # optional - sage.graphs - sage: X = X.set_base_point(X.n_cells(0)[0]) # optional - sage.graphs - sage: X.is_simply_connected() # optional - sage.graphs sage.groups + sage: X = S2.disjoint_union(S3) + sage: X = X.set_base_point(X.n_cells(0)[0]) + sage: X.is_simply_connected() False - sage: C3 = groups.misc.MultiplicativeAbelian([3]) # optional - sage.graphs sage.groups - sage: BC3 = simplicial_sets.ClassifyingSpace(C3) # optional - sage.graphs sage.groups - sage: BC3.is_simply_connected() # optional - sage.graphs sage.groups + sage: C3 = groups.misc.MultiplicativeAbelian([3]) # needs sage.graphs sage.groups + sage: BC3 = simplicial_sets.ClassifyingSpace(C3) # needs sage.graphs sage.groups + sage: BC3.is_simply_connected() # needs sage.graphs sage.groups False """ if not self.is_connected(): @@ -642,21 +653,22 @@ def connectivity(self, max_dim=None): EXAMPLES:: - sage: simplicial_sets.Sphere(3).connectivity() # optional - sage.graphs sage.groups + sage: # needs sage.graphs sage.groups + sage: simplicial_sets.Sphere(3).connectivity() 2 - sage: simplicial_sets.Sphere(0).connectivity() # optional - sage.graphs sage.groups + sage: simplicial_sets.Sphere(0).connectivity() -1 - sage: K = simplicial_sets.Simplex(4) # optional - sage.graphs - sage: K = K.set_base_point(K.n_cells(0)[0]) # optional - sage.graphs - sage: K.connectivity() # optional - sage.graphs sage.groups + sage: K = simplicial_sets.Simplex(4) + sage: K = K.set_base_point(K.n_cells(0)[0]) + sage: K.connectivity() +Infinity - sage: X = simplicial_sets.Torus().suspension(2) # optional - sage.graphs - sage: X.connectivity() # optional - sage.graphs sage.groups + sage: X = simplicial_sets.Torus().suspension(2) + sage: X.connectivity() 2 - sage: C2 = groups.misc.MultiplicativeAbelian([2]) # optional - sage.graphs sage.groups - sage: BC2 = simplicial_sets.ClassifyingSpace(C2) # optional - sage.graphs sage.groups - sage: BC2.connectivity() # optional - sage.graphs sage.groups + sage: C2 = groups.misc.MultiplicativeAbelian([2]) # needs sage.graphs sage.groups + sage: BC2 = simplicial_sets.ClassifyingSpace(C2) # needs sage.graphs sage.groups + sage: BC2.connectivity() # needs sage.graphs sage.groups 0 """ if not self.is_connected(): @@ -690,17 +702,18 @@ def unset_base_point(self): EXAMPLES:: - sage: from sage.topology.simplicial_set import AbstractSimplex, SimplicialSet # optional - sage.graphs - sage: v = AbstractSimplex(0, name='v_0') # optional - sage.graphs - sage: w = AbstractSimplex(0, name='w_0') # optional - sage.graphs - sage: e = AbstractSimplex(1) # optional - sage.graphs - sage: Y = SimplicialSet({e: (v, w)}, base_point=w) # optional - sage.graphs - sage: Y.is_pointed() # optional - sage.graphs + sage: # needs sage.graphs + sage: from sage.topology.simplicial_set import AbstractSimplex, SimplicialSet + sage: v = AbstractSimplex(0, name='v_0') + sage: w = AbstractSimplex(0, name='w_0') + sage: e = AbstractSimplex(1) + sage: Y = SimplicialSet({e: (v, w)}, base_point=w) + sage: Y.is_pointed() True - sage: Y.base_point() # optional - sage.graphs + sage: Y.base_point() w_0 - sage: Z = Y.unset_base_point() # optional - sage.graphs - sage: Z.is_pointed() # optional - sage.graphs + sage: Z = Y.unset_base_point() + sage: Z.is_pointed() False """ from sage.topology.simplicial_set import SimplicialSet @@ -719,14 +732,15 @@ def fat_wedge(self, n): EXAMPLES:: - sage: S1 = simplicial_sets.Sphere(1) # optional - sage.graphs - sage: S1.fat_wedge(0) # optional - sage.graphs + sage: # needs sage.graphs + sage: S1 = simplicial_sets.Sphere(1) + sage: S1.fat_wedge(0) Point - sage: S1.fat_wedge(1) # optional - sage.graphs + sage: S1.fat_wedge(1) S^1 - sage: S1.fat_wedge(2).fundamental_group() # optional - sage.graphs sage.groups + sage: S1.fat_wedge(2).fundamental_group() # needs sage.groups Finitely presented group < e0, e1 | > - sage: S1.fat_wedge(4).homology() # optional - sage.graphs sage.modules + sage: S1.fat_wedge(4).homology() # needs sage.modules {0: 0, 1: Z x Z x Z x Z, 2: Z^6, 3: Z x Z x Z x Z} """ from sage.topology.simplicial_set_examples import Point @@ -746,18 +760,19 @@ def smash_product(self, *others): EXAMPLES:: - sage: S1 = simplicial_sets.Sphere(1) # optional - sage.graphs - sage: RP2 = simplicial_sets.RealProjectiveSpace(2) # optional - sage.graphs sage.groups - sage: X = S1.smash_product(RP2) # optional - sage.graphs sage.groups - sage: X.homology(base_ring=GF(2)) # optional - sage.graphs sage.groups sage.modules sage.rings.finite_rings + sage: # needs sage.graphs sage.groups + sage: S1 = simplicial_sets.Sphere(1) + sage: RP2 = simplicial_sets.RealProjectiveSpace(2) + sage: X = S1.smash_product(RP2) + sage: X.homology(base_ring=GF(2)) # needs sage.modules {0: Vector space of dimension 0 over Finite Field of size 2, 1: Vector space of dimension 0 over Finite Field of size 2, 2: Vector space of dimension 1 over Finite Field of size 2, 3: Vector space of dimension 1 over Finite Field of size 2} - sage: T = S1.product(S1) # optional - sage.graphs - sage: X = T.smash_product(S1) # optional - sage.graphs - sage: X.homology(reduced=False) # optional - sage.graphs sage.modules + sage: T = S1.product(S1) # needs sage.graphs sage.groups + sage: X = T.smash_product(S1) # needs sage.graphs sage.groups + sage: X.homology(reduced=False) # needs sage.graphs sage.groups sage.modules {0: Z, 1: 0, 2: Z x Z, 3: Z} """ from sage.topology.simplicial_set_constructions import SmashProductOfSimplicialSets_finite diff --git a/src/sage/categories/super_algebras.py b/src/sage/categories/super_algebras.py index cad158f689a..d63b2cc6da5 100644 --- a/src/sage/categories/super_algebras.py +++ b/src/sage/categories/super_algebras.py @@ -76,22 +76,24 @@ def tensor(*parents, **kwargs): EXAMPLES:: - sage: A. = ExteriorAlgebra(ZZ); A.rename("A") # optional - sage.combinat sage.modules - sage: T = A.tensor(A,A); T # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: A. = ExteriorAlgebra(ZZ); A.rename("A") + sage: T = A.tensor(A,A); T A # A # A - sage: T in Algebras(ZZ).Graded().SignedTensorProducts() # optional - sage.combinat sage.modules + sage: T in Algebras(ZZ).Graded().SignedTensorProducts() True - sage: T in Algebras(ZZ).Graded().TensorProducts() # optional - sage.combinat sage.modules + sage: T in Algebras(ZZ).Graded().TensorProducts() False - sage: A.rename(None) # optional - sage.combinat sage.modules + sage: A.rename(None) This also works when the other elements do not have a signed tensor product (:trac:`31266`):: - sage: a = SteenrodAlgebra(3).an_element() # optional - sage.modules - sage: M = CombinatorialFreeModule(GF(3), ['s', 't', 'u']) # optional - sage.modules sage.rings.finite_rings - sage: s = M.basis()['s'] # optional - sage.modules sage.rings.finite_rings - sage: tensor([a, s]) # optional - sage.modules sage.rings.finite_rings + sage: # needs sage.combinat sage.modules + sage: a = SteenrodAlgebra(3).an_element() + sage: M = CombinatorialFreeModule(GF(3), ['s', 't', 'u']) + sage: s = M.basis()['s'] + sage: tensor([a, s]) # needs sage.rings.finite_rings 2*Q_1 Q_3 P(2,1) # B['s'] """ constructor = kwargs.pop('constructor', tensor_signed) diff --git a/src/sage/categories/super_algebras_with_basis.py b/src/sage/categories/super_algebras_with_basis.py index affa3386377..014fe6e563e 100644 --- a/src/sage/categories/super_algebras_with_basis.py +++ b/src/sage/categories/super_algebras_with_basis.py @@ -52,8 +52,8 @@ def graded_algebra(self): EXAMPLES:: - sage: W. = algebras.DifferentialWeyl(QQ) # optional - sage.combinat sage.modules - sage: W.graded_algebra() # optional - sage.combinat sage.modules + sage: W. = algebras.DifferentialWeyl(QQ) # needs sage.modules + sage: W.graded_algebra() # needs sage.combinat sage.modules Graded Algebra of Differential Weyl algebra of polynomials in x, y over Rational Field """ @@ -76,27 +76,29 @@ def supercommutator(self, x): EXAMPLES:: - sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) # optional - sage.modules - sage: Cl. = CliffordAlgebra(Q) # optional - sage.combinat sage.modules - sage: a = x*y - z # optional - sage.combinat sage.modules - sage: b = x - y + y*z # optional - sage.combinat sage.modules - sage: a.supercommutator(b) # optional - sage.combinat sage.modules + sage: # needs sage.modules + sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) + sage: Cl. = CliffordAlgebra(Q) + sage: a = x*y - z + sage: b = x - y + y*z + sage: a.supercommutator(b) -5*x*y + 8*x*z - 2*y*z - 6*x + 12*y - 5*z - sage: a.supercommutator(Cl.one()) # optional - sage.combinat sage.modules + sage: a.supercommutator(Cl.one()) 0 - sage: Cl.one().supercommutator(a) # optional - sage.combinat sage.modules + sage: Cl.one().supercommutator(a) 0 - sage: Cl.zero().supercommutator(a) # optional - sage.combinat sage.modules + sage: Cl.zero().supercommutator(a) 0 - sage: a.supercommutator(Cl.zero()) # optional - sage.combinat sage.modules + sage: a.supercommutator(Cl.zero()) 0 - sage: Q = QuadraticForm(ZZ, 2, [-1,1,-3]) # optional - sage.modules - sage: Cl. = CliffordAlgebra(Q) # optional - sage.combinat sage.modules - sage: [a.supercommutator(b) for a in Cl.basis() for b in Cl.basis()] # optional - sage.combinat sage.modules + sage: # needs sage.modules + sage: Q = QuadraticForm(ZZ, 2, [-1,1,-3]) + sage: Cl. = CliffordAlgebra(Q) + sage: [a.supercommutator(b) for a in Cl.basis() for b in Cl.basis()] [0, 0, 0, 0, 0, -2, 1, -x - 2*y, 0, 1, -6, 6*x + y, 0, x + 2*y, -6*x - y, 0] - sage: [a*b-b*a for a in Cl.basis() for b in Cl.basis()] # optional - sage.combinat sage.modules + sage: [a*b-b*a for a in Cl.basis() for b in Cl.basis()] [0, 0, 0, 0, 0, 0, 2*x*y - 1, -x - 2*y, 0, -2*x*y + 1, 0, 6*x + y, 0, x + 2*y, -6*x - y, 0] @@ -104,8 +106,8 @@ def supercommutator(self, x): supercommutators work as well. We verify the exterior algebra is supercommutative:: - sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules - sage: all(b1.supercommutator(b2) == 0 # optional - sage.combinat sage.modules + sage: E. = ExteriorAlgebra(QQ) # needs sage.modules + sage: all(b1.supercommutator(b2) == 0 # needs sage.modules ....: for b1 in E.basis() for b2 in E.basis()) True """ diff --git a/src/sage/categories/super_hopf_algebras_with_basis.py b/src/sage/categories/super_hopf_algebras_with_basis.py index e8974390ba5..afaafc2b8f7 100644 --- a/src/sage/categories/super_hopf_algebras_with_basis.py +++ b/src/sage/categories/super_hopf_algebras_with_basis.py @@ -42,15 +42,15 @@ def antipode(self): EXAMPLES:: - sage: A = SteenrodAlgebra(7) # optional - sage.combinat sage.modules - sage: a = A.an_element() # optional - sage.combinat sage.modules - sage: a, A.antipode(a) # optional - sage.combinat sage.modules + sage: A = SteenrodAlgebra(7) # needs sage.combinat sage.modules + sage: a = A.an_element() # needs sage.combinat sage.modules + sage: a, A.antipode(a) # needs sage.combinat sage.modules (6 Q_1 Q_3 P(2,1), Q_1 Q_3 P(2,1)) TESTS:: - sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules - sage: [b.antipode() for b in E.basis()] # optional - sage.combinat sage.modules + sage: E. = ExteriorAlgebra(QQ) # needs sage.modules + sage: [b.antipode() for b in E.basis()] # needs sage.modules [1, -x, -y, x*y] """ if self.antipode_on_basis is not NotImplemented: @@ -88,8 +88,8 @@ def _test_antipode(self, **options): TESTS:: - sage: A = SteenrodAlgebra(7) # optional - sage.combinat sage.modules - sage: A._test_antipode() # long time # optional - sage.combinat sage.modules + sage: A = SteenrodAlgebra(7) # needs sage.combinat sage.modules + sage: A._test_antipode() # long time # needs sage.combinat sage.modules """ tester = self._tester(**options) diff --git a/src/sage/categories/super_lie_conformal_algebras.py b/src/sage/categories/super_lie_conformal_algebras.py index 82a11f5f2cc..9e38c4aa3e1 100644 --- a/src/sage/categories/super_lie_conformal_algebras.py +++ b/src/sage/categories/super_lie_conformal_algebras.py @@ -27,16 +27,16 @@ class SuperLieConformalAlgebras(SuperModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(AA).Super() # optional - sage.rings.number_field + sage: LieConformalAlgebras(AA).Super() # needs sage.rings.number_field Category of super Lie conformal algebras over Algebraic Real Field Notice that we can force to have a *purely even* super Lie conformal algebra:: sage: bosondict = {('a','a'): {1:{('K',0):1}}} - sage: R = LieConformalAlgebra(QQ, bosondict, names=('a',), # optional - sage.combinat sage.modules + sage: R = LieConformalAlgebra(QQ, bosondict, names=('a',), # needs sage.combinat sage.modules ....: central_elements=('K',), super=True) - sage: [g.is_even_odd() for g in R.gens()] # optional - sage.combinat sage.modules + sage: [g.is_even_odd() for g in R.gens()] # needs sage.combinat sage.modules [0, 0] """ def extra_super_categories(self): @@ -57,7 +57,7 @@ def example(self): EXAMPLES:: - sage: LieConformalAlgebras(QQ).Super().example() # optional - sage.combinat sage.modules + sage: LieConformalAlgebras(QQ).Super().example() # needs sage.combinat sage.modules The Neveu-Schwarz super Lie conformal algebra over Rational Field """ from sage.algebras.lie_conformal_algebras.neveu_schwarz_lie_conformal_algebra\ @@ -79,30 +79,30 @@ def _test_jacobi(self, **options): By default, this method tests only the elements returned by ``self.some_elements()``:: - sage: V = lie_conformal_algebras.Affine(QQ, 'B2') # optional - sage.combinat sage.modules - sage: V._test_jacobi() # long time (6 seconds) # optional - sage.combinat sage.modules + sage: V = lie_conformal_algebras.Affine(QQ, 'B2') # needs sage.combinat sage.modules + sage: V._test_jacobi() # long time (6 seconds) # needs sage.combinat sage.modules It works for super Lie conformal algebras too:: - sage: V = lie_conformal_algebras.NeveuSchwarz(QQ) # optional - sage.combinat sage.modules - sage: V._test_jacobi() # optional - sage.combinat sage.modules + sage: V = lie_conformal_algebras.NeveuSchwarz(QQ) # needs sage.combinat sage.modules + sage: V._test_jacobi() # needs sage.combinat sage.modules We can use specific elements by passing the ``elements`` keyword argument:: - sage: V = lie_conformal_algebras.Affine(QQ, 'A1', # optional - sage.combinat sage.modules + sage: V = lie_conformal_algebras.Affine(QQ, 'A1', # needs sage.combinat sage.modules ....: names=('e', 'h', 'f')) - sage: V.inject_variables() # optional - sage.combinat sage.modules + sage: V.inject_variables() # needs sage.combinat sage.modules Defining e, h, f, K - sage: V._test_jacobi(elements=(e, 2*f + h, 3*h)) # optional - sage.combinat sage.modules + sage: V._test_jacobi(elements=(e, 2*f + h, 3*h)) # needs sage.combinat sage.modules TESTS:: sage: wrongdict = {('a', 'a'): {0: {('b', 0): 1}}, ....: ('b', 'a'): {0: {('a', 0): 1}}} - sage: V = LieConformalAlgebra(QQ, wrongdict, # optional - sage.combinat sage.modules + sage: V = LieConformalAlgebra(QQ, wrongdict, # needs sage.combinat sage.modules ....: names=('a', 'b'), parity=(1, 0)) - sage: V._test_jacobi() # optional - sage.combinat sage.modules + sage: V._test_jacobi() # needs sage.combinat sage.modules Traceback (most recent call last): ... AssertionError: {(0, 0): -3*a} != {} - {(0, 0): -3*a} + {} @@ -163,10 +163,10 @@ def is_even_odd(self): EXAMPLES:: - sage: R = lie_conformal_algebras.NeveuSchwarz(QQ) # optional - sage.combinat sage.modules - sage: R.inject_variables() # optional - sage.combinat sage.modules + sage: R = lie_conformal_algebras.NeveuSchwarz(QQ) # needs sage.combinat sage.modules + sage: R.inject_variables() # needs sage.combinat sage.modules Defining L, G, C - sage: G.is_even_odd() # optional - sage.combinat sage.modules + sage: G.is_even_odd() # needs sage.combinat sage.modules 1 """ @@ -176,7 +176,7 @@ class Graded(GradedModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(AA).Super().Graded() # optional - sage.rings.number_field + sage: LieConformalAlgebras(AA).Super().Graded() # needs sage.rings.number_field Category of H-graded super Lie conformal algebras over Algebraic Real Field """ def _repr_object_names(self): @@ -185,7 +185,7 @@ def _repr_object_names(self): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).Graded() # optional - sage.rings.number_field + sage: LieConformalAlgebras(QQbar).Graded() # needs sage.rings.number_field Category of H-graded Lie conformal algebras over Algebraic Field """ return "H-graded {}".format(self.base_category()._repr_object_names()) diff --git a/src/sage/categories/super_modules.py b/src/sage/categories/super_modules.py index 2efd5f6e7e2..0fbd94fbf31 100644 --- a/src/sage/categories/super_modules.py +++ b/src/sage/categories/super_modules.py @@ -182,12 +182,13 @@ def is_even_odd(self): EXAMPLES:: + sage: # needs sage.combinat sage.modules sage: cat = Algebras(QQ).WithBasis().Super() - sage: C = CombinatorialFreeModule(QQ, Partitions(), category=cat) # optional - sage.combinat sage.modules - sage: C.degree_on_basis = sum # optional - sage.combinat sage.modules - sage: C.basis()[2,2,1].is_even_odd() # optional - sage.combinat sage.modules + sage: C = CombinatorialFreeModule(QQ, Partitions(), category=cat) + sage: C.degree_on_basis = sum + sage: C.basis()[2,2,1].is_even_odd() 1 - sage: C.basis()[2,2].is_even_odd() # optional - sage.combinat sage.modules + sage: C.basis()[2,2].is_even_odd() 0 """ return self.degree() % 2 @@ -198,12 +199,13 @@ def is_even(self): EXAMPLES:: + sage: # needs sage.combinat sage.modules sage: cat = Algebras(QQ).WithBasis().Super() - sage: C = CombinatorialFreeModule(QQ, Partitions(), category=cat) # optional - sage.combinat sage.modules - sage: C.degree_on_basis = sum # optional - sage.combinat sage.modules - sage: C.basis()[2,2,1].is_even() # optional - sage.combinat sage.modules + sage: C = CombinatorialFreeModule(QQ, Partitions(), category=cat) + sage: C.degree_on_basis = sum + sage: C.basis()[2,2,1].is_even() False - sage: C.basis()[2,2].is_even() # optional - sage.combinat sage.modules + sage: C.basis()[2,2].is_even() True """ return self.is_even_odd() == 0 @@ -214,12 +216,13 @@ def is_odd(self): EXAMPLES:: + sage: # needs sage.combinat sage.modules sage: cat = Algebras(QQ).WithBasis().Super() - sage: C = CombinatorialFreeModule(QQ, Partitions(), category=cat) # optional - sage.combinat sage.modules - sage: C.degree_on_basis = sum # optional - sage.combinat sage.modules - sage: C.basis()[2,2,1].is_odd() # optional - sage.combinat sage.modules + sage: C = CombinatorialFreeModule(QQ, Partitions(), category=cat) + sage: C.degree_on_basis = sum + sage: C.basis()[2,2,1].is_odd() True - sage: C.basis()[2,2].is_odd() # optional - sage.combinat sage.modules + sage: C.basis()[2,2].is_odd() False """ return self.is_even_odd() == 1 diff --git a/src/sage/categories/super_modules_with_basis.py b/src/sage/categories/super_modules_with_basis.py index dff6b54fbe2..ef4bbc048e8 100644 --- a/src/sage/categories/super_modules_with_basis.py +++ b/src/sage/categories/super_modules_with_basis.py @@ -53,11 +53,12 @@ def _even_odd_on_basis(self, m): EXAMPLES:: - sage: Q = QuadraticForm(QQ, 2, [1,2,3]) # optional - sage.modules - sage: C. = CliffordAlgebra(Q) # optional - sage.combinat sage.modules - sage: C._even_odd_on_basis((0,)) # optional - sage.combinat sage.modules + sage: # needs sage.modules + sage: Q = QuadraticForm(QQ, 2, [1,2,3]) + sage: C. = CliffordAlgebra(Q) + sage: C._even_odd_on_basis((0,)) 1 - sage: C._even_odd_on_basis((0,1)) # optional - sage.combinat sage.modules + sage: C._even_odd_on_basis((0,1)) 0 """ return self.degree_on_basis(m) % 2 @@ -70,27 +71,29 @@ def is_super_homogeneous(self): EXAMPLES:: - sage: Q = QuadraticForm(QQ, 2, [1,2,3]) # optional - sage.modules - sage: C. = CliffordAlgebra(Q) # optional - sage.combinat sage.modules - sage: a = x + y # optional - sage.combinat sage.modules - sage: a.is_super_homogeneous() # optional - sage.combinat sage.modules + sage: # needs sage.modules + sage: Q = QuadraticForm(QQ, 2, [1,2,3]) + sage: C. = CliffordAlgebra(Q) + sage: a = x + y + sage: a.is_super_homogeneous() True - sage: a = x*y + 4 # optional - sage.combinat sage.modules - sage: a.is_super_homogeneous() # optional - sage.combinat sage.modules + sage: a = x*y + 4 + sage: a.is_super_homogeneous() True - sage: a = x*y + x - 3*y + 4 # optional - sage.combinat sage.modules - sage: a.is_super_homogeneous() # optional - sage.combinat sage.modules + sage: a = x*y + x - 3*y + 4 + sage: a.is_super_homogeneous() False The exterior algebra has a `\ZZ` grading, which induces the `\ZZ / 2\ZZ` grading. However the definition of homogeneous elements differs because of the different gradings:: - sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules - sage: a = x*y + 4 # optional - sage.combinat sage.modules - sage: a.is_super_homogeneous() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: E. = ExteriorAlgebra(QQ) + sage: a = x*y + 4 + sage: a.is_super_homogeneous() True - sage: a.is_homogeneous() # optional - sage.combinat sage.modules + sage: a.is_homogeneous() False """ even_odd = self.parent()._even_odd_on_basis @@ -110,22 +113,23 @@ def is_even_odd(self): EXAMPLES:: - sage: Q = QuadraticForm(QQ, 2, [1,2,3]) # optional - sage.modules - sage: C. = CliffordAlgebra(Q) # optional - sage.combinat sage.modules - sage: a = x + y # optional - sage.combinat sage.modules - sage: a.is_even_odd() # optional - sage.combinat sage.modules + sage: # needs sage.modules + sage: Q = QuadraticForm(QQ, 2, [1,2,3]) + sage: C. = CliffordAlgebra(Q) + sage: a = x + y + sage: a.is_even_odd() 1 - sage: a = x*y + 4 # optional - sage.combinat sage.modules - sage: a.is_even_odd() # optional - sage.combinat sage.modules + sage: a = x*y + 4 + sage: a.is_even_odd() 0 - sage: a = x + 4 # optional - sage.combinat sage.modules - sage: a.is_even_odd() # optional - sage.combinat sage.modules + sage: a = x + 4 + sage: a.is_even_odd() Traceback (most recent call last): ... ValueError: element is not homogeneous - sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules - sage: (x*y).is_even_odd() # optional - sage.combinat sage.modules + sage: E. = ExteriorAlgebra(QQ) # needs sage.modules + sage: (x*y).is_even_odd() # needs sage.modules 0 """ if not self.support(): @@ -140,18 +144,19 @@ def even_component(self): EXAMPLES:: - sage: Q = QuadraticForm(QQ, 2, [1,2,3]) # optional - sage.modules - sage: C. = CliffordAlgebra(Q) # optional - sage.combinat sage.modules - sage: a = x*y + x - 3*y + 4 # optional - sage.combinat sage.modules - sage: a.even_component() # optional - sage.combinat sage.modules + sage: # needs sage.modules + sage: Q = QuadraticForm(QQ, 2, [1,2,3]) + sage: C. = CliffordAlgebra(Q) + sage: a = x*y + x - 3*y + 4 + sage: a.even_component() x*y + 4 TESTS: Check that this really return ``A.zero()`` and not a plain ``0``:: - sage: a = x + y # optional - sage.combinat sage.modules - sage: a.even_component().parent() is C # optional - sage.combinat sage.modules + sage: a = x + y # needs sage.modules + sage: a.even_component().parent() is C # needs sage.modules True """ even_odd = self.parent()._even_odd_on_basis @@ -165,18 +170,19 @@ def odd_component(self): EXAMPLES:: - sage: Q = QuadraticForm(QQ, 2, [1,2,3]) # optional - sage.modules - sage: C. = CliffordAlgebra(Q) # optional - sage.combinat sage.modules - sage: a = x*y + x - 3*y + 4 # optional - sage.combinat sage.modules - sage: a.odd_component() # optional - sage.combinat sage.modules + sage: # needs sage.modules + sage: Q = QuadraticForm(QQ, 2, [1,2,3]) + sage: C. = CliffordAlgebra(Q) + sage: a = x*y + x - 3*y + 4 + sage: a.odd_component() x - 3*y TESTS: Check that this really return ``A.zero()`` and not a plain ``0``:: - sage: a = x*y # optional - sage.combinat sage.modules - sage: a.odd_component().parent() is C # optional - sage.combinat sage.modules + sage: a = x*y # needs sage.modules + sage: a.odd_component().parent() is C # needs sage.modules True """ even_odd = self.parent()._even_odd_on_basis diff --git a/src/sage/categories/supercommutative_algebras.py b/src/sage/categories/supercommutative_algebras.py index 9cb2f609a8c..1928c7057dc 100644 --- a/src/sage/categories/supercommutative_algebras.py +++ b/src/sage/categories/supercommutative_algebras.py @@ -73,15 +73,15 @@ def _test_supercommutativity(self, **options): By default, this method tests only the elements returned by ``self.some_elements()``:: - sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules - sage: E._test_supercommutativity() # optional - sage.combinat sage.modules + sage: E. = ExteriorAlgebra(QQ) # needs sage.modules + sage: E._test_supercommutativity() # needs sage.modules However, the elements tested can be customized with the ``elements`` keyword argument, but the elements must be homogeneous:: - sage: E._test_supercommutativity(elements=[x+y, x*y-3*y*z, x*y*z]) # optional - sage.combinat sage.modules - sage: E._test_supercommutativity(elements=[x+x*y]) # optional - sage.combinat sage.modules + sage: E._test_supercommutativity(elements=[x+y, x*y-3*y*z, x*y*z]) # needs sage.modules + sage: E._test_supercommutativity(elements=[x+x*y]) # needs sage.modules Traceback (most recent call last): ... ValueError: element is not homogeneous diff --git a/src/sage/categories/supercrystals.py b/src/sage/categories/supercrystals.py index a68c1d7c591..239aa8c0a86 100644 --- a/src/sage/categories/supercrystals.py +++ b/src/sage/categories/supercrystals.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.graphs sage.combinat +# sage.doctest: needs sage.graphs sage.combinat r""" Supercrystals """ diff --git a/src/sage/categories/triangular_kac_moody_algebras.py b/src/sage/categories/triangular_kac_moody_algebras.py index 434ff22c1c7..e9c3f1ad167 100644 --- a/src/sage/categories/triangular_kac_moody_algebras.py +++ b/src/sage/categories/triangular_kac_moody_algebras.py @@ -60,10 +60,10 @@ def _part_on_basis(self, m): EXAMPLES:: - sage: L = lie_algebras.so(QQ, 5) # optional - sage.combinat sage.modules - sage: L.f() # optional - sage.combinat sage.modules + sage: L = lie_algebras.so(QQ, 5) # needs sage.combinat sage.modules + sage: L.f() # needs sage.combinat sage.modules Finite family {1: E[-alpha[1]], 2: E[-alpha[2]]} - sage: L.f(1) # optional - sage.combinat sage.modules + sage: L.f(1) # needs sage.combinat sage.modules E[-alpha[1]] """ deg = self.degree_on_basis(m) @@ -100,8 +100,8 @@ def _part_generators(self, positive=False): EXAMPLES:: - sage: L = LieAlgebra(QQ, cartan_type=['E', 6]) # optional - sage.combinat sage.modules - sage: list(L._part_generators(False)) # optional - sage.combinat sage.modules + sage: L = LieAlgebra(QQ, cartan_type=['E', 6]) # needs sage.combinat sage.modules + sage: list(L._part_generators(False)) # needs sage.combinat sage.modules [E[-alpha[1]], E[-alpha[2]], E[-alpha[3]], E[-alpha[4]], E[-alpha[5]], E[-alpha[6]]] """ @@ -128,10 +128,10 @@ def e(self, i=None): EXAMPLES:: - sage: L = lie_algebras.so(QQ, 5) # optional - sage.combinat sage.modules - sage: L.e() # optional - sage.combinat sage.modules + sage: L = lie_algebras.so(QQ, 5) # needs sage.combinat sage.modules + sage: L.e() # needs sage.combinat sage.modules Finite family {1: E[alpha[1]], 2: E[alpha[2]]} - sage: L.e(1) # optional - sage.combinat sage.modules + sage: L.e(1) # needs sage.combinat sage.modules E[alpha[1]] """ E = self._part_generators(True) @@ -150,10 +150,10 @@ def f(self, i=None): EXAMPLES:: - sage: L = lie_algebras.so(QQ, 5) # optional - sage.combinat sage.modules - sage: L.f() # optional - sage.combinat sage.modules + sage: L = lie_algebras.so(QQ, 5) # needs sage.combinat sage.modules + sage: L.f() # needs sage.combinat sage.modules Finite family {1: E[-alpha[1]], 2: E[-alpha[2]]} - sage: L.f(1) # optional - sage.combinat sage.modules + sage: L.f(1) # needs sage.combinat sage.modules E[-alpha[1]] """ F = self._part_generators(False) @@ -168,8 +168,8 @@ def _negative_half_index_set(self): EXAMPLES:: - sage: L = lie_algebras.so(QQ, 5) # optional - sage.combinat sage.modules - sage: L._negative_half_index_set() # optional - sage.combinat sage.modules + sage: L = lie_algebras.so(QQ, 5) # needs sage.combinat sage.modules + sage: L._negative_half_index_set() # needs sage.combinat sage.modules [-alpha[2], -alpha[1], -alpha[1] - alpha[2], -alpha[1] - 2*alpha[2]] """ @@ -186,15 +186,16 @@ def _weight_action(self, m, wt): EXAMPLES:: - sage: L = lie_algebras.sp(QQ, 6) # optional - sage.combinat sage.modules - sage: La = L.cartan_type().root_system().weight_space().fundamental_weights() # optional - sage.combinat sage.modules - sage: mu = La[1] - 3/5*La[2] # optional - sage.combinat sage.modules - sage: ac = L.cartan_type().root_system().coroot_lattice().simple_roots() # optional - sage.combinat sage.modules - sage: L._weight_action(ac[1], mu) # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = lie_algebras.sp(QQ, 6) + sage: La = L.cartan_type().root_system().weight_space().fundamental_weights() + sage: mu = La[1] - 3/5*La[2] + sage: ac = L.cartan_type().root_system().coroot_lattice().simple_roots() + sage: L._weight_action(ac[1], mu) 1 - sage: L._weight_action(ac[2], mu) # optional - sage.combinat sage.modules + sage: L._weight_action(ac[2], mu) -3/5 - sage: L._weight_action(ac[3], mu) # optional - sage.combinat sage.modules + sage: L._weight_action(ac[3], mu) 0 """ @@ -210,11 +211,12 @@ def verma_module(self, la, basis_key=None, **kwds): EXAMPLES:: - sage: L = lie_algebras.sl(QQ, 3) # optional - sage.combinat sage.modules - sage: P = L.cartan_type().root_system().weight_lattice() # optional - sage.combinat sage.modules - sage: La = P.fundamental_weights() # optional - sage.combinat sage.modules - sage: M = L.verma_module(La[1] + La[2]) # optional - sage.combinat sage.modules - sage: M # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = lie_algebras.sl(QQ, 3) + sage: P = L.cartan_type().root_system().weight_lattice() + sage: La = P.fundamental_weights() + sage: M = L.verma_module(La[1] + La[2]) + sage: M Verma module with highest weight Lambda[1] + Lambda[2] of Lie algebra of ['A', 2] in the Chevalley basis """ @@ -234,18 +236,19 @@ def part(self): EXAMPLES:: - sage: L = LieAlgebra(QQ, cartan_type="F4") # optional - sage.combinat sage.modules - sage: L.inject_variables() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: L = LieAlgebra(QQ, cartan_type="F4") + sage: L.inject_variables() Defining e1, e2, e3, e4, f1, f2, f3, f4, h1, h2, h3, h4 - sage: e1.part() # optional - sage.combinat sage.modules + sage: e1.part() 1 - sage: f4.part() # optional - sage.combinat sage.modules + sage: f4.part() -1 - sage: (h2 + h3).part() # optional - sage.combinat sage.modules + sage: (h2 + h3).part() 0 - sage: (f1.bracket(f2) + 4*f4).part() # optional - sage.combinat sage.modules + sage: (f1.bracket(f2) + 4*f4).part() -1 - sage: (e1 + f1).part() # optional - sage.combinat sage.modules + sage: (e1 + f1).part() Traceback (most recent call last): ... ValueError: element is not in one part diff --git a/src/sage/categories/unique_factorization_domains.py b/src/sage/categories/unique_factorization_domains.py index f3d6b565316..785b99c8388 100644 --- a/src/sage/categories/unique_factorization_domains.py +++ b/src/sage/categories/unique_factorization_domains.py @@ -65,7 +65,7 @@ def __contains__(self, x): """ EXAMPLES:: - sage: GF(4, "a") in UniqueFactorizationDomains() # optional - sage.rings.finite_rings + sage: GF(4, "a") in UniqueFactorizationDomains() # needs sage.rings.finite_rings True sage: QQ in UniqueFactorizationDomains() True @@ -162,10 +162,11 @@ def _gcd_univariate_polynomial(self, f, g): Check that :trac:`23620` has been resolved:: - sage: R. = ZpFM(2)[] # optional - sage.rings.padics - sage: f = 2*x + 2 # optional - sage.rings.padics - sage: g = 4*x + 2 # optional - sage.rings.padics - sage: f.gcd(g).parent() is R # optional - sage.rings.padics + sage: # needs sage.rings.padics + sage: R. = ZpFM(2)[] + sage: f = 2*x + 2 + sage: g = 4*x + 2 + sage: f.gcd(g).parent() is R True """ diff --git a/src/sage/categories/unital_algebras.py b/src/sage/categories/unital_algebras.py index 388a6e940a7..6e242c1806c 100644 --- a/src/sage/categories/unital_algebras.py +++ b/src/sage/categories/unital_algebras.py @@ -61,10 +61,10 @@ def from_base_ring(self, r): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example(); A # optional - sage.combinat sage.modules + sage: A = AlgebrasWithBasis(QQ).example(); A # needs sage.combinat sage.modules An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: A.from_base_ring(1) # optional - sage.combinat sage.modules + sage: A.from_base_ring(1) # needs sage.combinat sage.modules B[word: ] """ return self.one()._lmul_(r) @@ -76,18 +76,18 @@ def __init_extra__(self): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example(); A # optional - sage.combinat sage.modules + sage: A = AlgebrasWithBasis(QQ).example(); A # needs sage.combinat sage.modules An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field sage: coercion_model = sage.structure.element.get_coercion_model() - sage: coercion_model.discover_coercion(QQ, A) # optional - sage.combinat sage.modules + sage: coercion_model.discover_coercion(QQ, A) # needs sage.combinat sage.modules ((map internal to coercion system -- copy before use) Generic morphism: From: Rational Field To: An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field, None) - sage: A(1) # indirect doctest # optional - sage.combinat sage.modules + sage: A(1) # indirect doctest # needs sage.combinat sage.modules B[word: ] TESTS: @@ -95,15 +95,16 @@ def __init_extra__(self): Ensure that :trac:`28328` is fixed and that non-associative algebras are supported:: - sage: class Foo(CombinatorialFreeModule): # optional - sage.modules + sage: # needs sage.modules + sage: class Foo(CombinatorialFreeModule): ....: def one(self): ....: return self.monomial(0) sage: from sage.categories.magmatic_algebras import MagmaticAlgebras sage: C = MagmaticAlgebras(QQ).WithBasis().Unital() - sage: F = Foo(QQ, (1,), category=C) # optional - sage.modules - sage: F(0) # optional - sage.modules + sage: F = Foo(QQ, (1,), category=C) + sage: F(0) 0 - sage: F(3) # optional - sage.modules + sage: F(3) 3*B[0] sage: class Bar(Parent): @@ -185,8 +186,8 @@ def _coerce_map_from_base_ring(self): Check that :trac:`29312` is fixed:: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.modules - sage: F._coerce_map_from_base_ring() # optional - sage.combinat sage.modules + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # needs sage.combinat sage.modules + sage: F._coerce_map_from_base_ring() # needs sage.combinat sage.modules Generic morphism: From: Rational Field To: Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field @@ -276,12 +277,13 @@ def one_basis(self): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules - sage: A.one_basis() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: A = AlgebrasWithBasis(QQ).example() + sage: A.one_basis() word: - sage: A.one() # optional - sage.combinat sage.modules + sage: A.one() B[word: ] - sage: A.from_base_ring(4) # optional - sage.combinat sage.modules + sage: A.from_base_ring(4) 4*B[word: ] """ @@ -297,33 +299,35 @@ def one_from_one_basis(self): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules - sage: A.one_basis() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: A = AlgebrasWithBasis(QQ).example() + sage: A.one_basis() word: - sage: A.one_from_one_basis() # optional - sage.combinat sage.modules + sage: A.one_from_one_basis() B[word: ] - sage: A.one() # optional - sage.combinat sage.modules + sage: A.one() B[word: ] TESTS: Try to check that :trac:`5843` Heisenbug is fixed:: - sage: A = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules - sage: B = AlgebrasWithBasis(QQ).example(('a', 'c')) # optional - sage.combinat sage.modules - sage: A == B # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: A = AlgebrasWithBasis(QQ).example() + sage: B = AlgebrasWithBasis(QQ).example(('a', 'c')) + sage: A == B False - sage: Aone = A.one_from_one_basis # optional - sage.combinat sage.modules - sage: Bone = B.one_from_one_basis # optional - sage.combinat sage.modules - sage: Aone is Bone # optional - sage.combinat sage.modules + sage: Aone = A.one_from_one_basis + sage: Bone = B.one_from_one_basis + sage: Aone is Bone False Even if called in the wrong order, they should returns their respective one:: - sage: Bone().parent() is B # optional - sage.combinat sage.modules + sage: Bone().parent() is B # needs sage.combinat sage.modules True - sage: Aone().parent() is A # optional - sage.combinat sage.modules + sage: Aone().parent() is A # needs sage.combinat sage.modules True """ return self.monomial(self.one_basis()) #. @@ -335,10 +339,10 @@ def one(self): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules - sage: A.one_basis() # optional - sage.combinat sage.modules + sage: A = AlgebrasWithBasis(QQ).example() # needs sage.combinat sage.modules + sage: A.one_basis() # needs sage.combinat sage.modules word: - sage: A.one() # optional - sage.combinat sage.modules + sage: A.one() # needs sage.combinat sage.modules B[word: ] """ if self.one_basis is NotImplemented: @@ -350,8 +354,8 @@ def from_base_ring(self): """ TESTS:: - sage: A = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules - sage: A.from_base_ring(3) # optional - sage.combinat sage.modules + sage: A = AlgebrasWithBasis(QQ).example() # needs sage.combinat sage.modules + sage: A.from_base_ring(3) # needs sage.combinat sage.modules 3*B[word: ] """ if self.one_basis is NotImplemented: @@ -368,12 +372,13 @@ def from_base_ring_from_one_basis(self, r): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules - sage: A.from_base_ring_from_one_basis(3) # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: A = AlgebrasWithBasis(QQ).example() + sage: A.from_base_ring_from_one_basis(3) 3*B[word: ] - sage: A.from_base_ring(3) # optional - sage.combinat sage.modules + sage: A.from_base_ring(3) 3*B[word: ] - sage: A(3) # optional - sage.combinat sage.modules + sage: A(3) 3*B[word: ] """ return self.term(self.one_basis(), r) diff --git a/src/sage/categories/vector_bundles.py b/src/sage/categories/vector_bundles.py index d5388e381c1..a973dde5f9e 100644 --- a/src/sage/categories/vector_bundles.py +++ b/src/sage/categories/vector_bundles.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.symbolic +# sage.doctest: needs sage.symbolic r""" Vector Bundles """ diff --git a/src/sage/categories/vector_spaces.py b/src/sage/categories/vector_spaces.py index 508b0fc1f61..50cd61fb8f5 100644 --- a/src/sage/categories/vector_spaces.py +++ b/src/sage/categories/vector_spaces.py @@ -82,8 +82,8 @@ def __init__(self, K): TESTS:: - sage: C = QQ^10 # vector space # optional - sage.modules - sage: TestSuite(C).run() # optional - sage.modules + sage: C = QQ^10 # vector space # needs sage.modules + sage: TestSuite(C).run() # needs sage.modules sage: TestSuite(VectorSpaces(QQ)).run() """ Category_module.__init__(self, K) @@ -94,15 +94,15 @@ def _call_(self, x): EXAMPLES:: - sage: VectorSpaces(QQ)(ZZ^3) # optional - sage.modules + sage: VectorSpaces(QQ)(ZZ^3) # needs sage.modules Vector space of dimension 3 over Rational Field TESTS: Check whether :trac:`30174` is fixed:: - sage: Q3 = FiniteRankFreeModule(QQ, 3) # optional - sage.modules - sage: Modules(QQ)(Q3) is Q3 # optional - sage.modules + sage: Q3 = FiniteRankFreeModule(QQ, 3) # needs sage.modules + sage: Modules(QQ)(Q3) is Q3 # needs sage.modules True """ @@ -162,15 +162,15 @@ def dimension(self): EXAMPLES:: - sage: M = FreeModule(FiniteField(19), 100) # optional - sage.modules sage.rings.finite_rings - sage: W = M.submodule([M.gen(50)]) # optional - sage.modules sage.rings.finite_rings - sage: W.dimension() # optional - sage.modules sage.rings.finite_rings + sage: M = FreeModule(FiniteField(19), 100) # needs sage.modules + sage: W = M.submodule([M.gen(50)]) # needs sage.modules + sage: W.dimension() # needs sage.modules 1 - sage: M = FiniteRankFreeModule(QQ, 3) # optional - sage.modules - sage: M.dimension() # optional - sage.modules + sage: M = FiniteRankFreeModule(QQ, 3) # needs sage.modules + sage: M.dimension() # needs sage.modules 3 - sage: M.tensor_module(1, 2).dimension() # optional - sage.modules + sage: M.tensor_module(1, 2).dimension() # needs sage.modules 27 """ @@ -253,7 +253,7 @@ def example(self, base_ring=None): EXAMPLES:: - sage: Modules(QQ).WithBasis().Graded().example() # optional - sage.combinat sage.modules + sage: Modules(QQ).WithBasis().Graded().example() # needs sage.combinat sage.modules An example of a graded module with basis: the free module on partitions over Rational Field """ @@ -274,7 +274,7 @@ def example(self, base_ring=None): EXAMPLES:: - sage: Modules(QQ).WithBasis().Graded().example() # optional - sage.combinat sage.modules + sage: Modules(QQ).WithBasis().Graded().example() # needs sage.combinat sage.modules An example of a graded module with basis: the free module on partitions over Rational Field """ diff --git a/src/sage/categories/weyl_groups.py b/src/sage/categories/weyl_groups.py index 70f8879353e..b5649a884fa 100644 --- a/src/sage/categories/weyl_groups.py +++ b/src/sage/categories/weyl_groups.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.combinat sage.groups +# sage.doctest: needs sage.combinat sage.groups r""" Weyl Groups """ diff --git a/src/sage/categories/with_realizations.py b/src/sage/categories/with_realizations.py index dd463186a2a..003277dcd2a 100644 --- a/src/sage/categories/with_realizations.py +++ b/src/sage/categories/with_realizations.py @@ -69,46 +69,47 @@ def WithRealizations(self): represented. Consider for example an algebra `A` which admits several natural bases:: - sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules + sage: A = Sets().WithRealizations().example(); A # needs sage.modules The subset algebra of {1, 2, 3} over Rational Field For each such basis `B` one implements a parent `P_B` which realizes `A` with its elements represented by expanding them on the basis `B`:: - sage: A.F() # optional - sage.combinat sage.modules + sage: # needs sage.modules + sage: A.F() The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis - sage: A.Out() # optional - sage.combinat sage.modules + sage: A.Out() The subset algebra of {1, 2, 3} over Rational Field in the Out basis - sage: A.In() # optional - sage.combinat sage.modules + sage: A.In() The subset algebra of {1, 2, 3} over Rational Field in the In basis - - sage: A.an_element() # optional - sage.combinat sage.modules + sage: A.an_element() F[{}] + 2*F[{1}] + 3*F[{2}] + F[{1, 2}] If `B` and `B'` are two bases, then the change of basis from `B` to `B'` is implemented by a canonical coercion between `P_B` and `P_{B'}`:: - sage: F = A.F(); In = A.In(); Out = A.Out() # optional - sage.combinat sage.modules - sage: i = In.an_element(); i # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: F = A.F(); In = A.In(); Out = A.Out() + sage: i = In.an_element(); i In[{}] + 2*In[{1}] + 3*In[{2}] + In[{1, 2}] - sage: F(i) # optional - sage.combinat sage.modules + sage: F(i) 7*F[{}] + 3*F[{1}] + 4*F[{2}] + F[{1, 2}] - sage: F.coerce_map_from(Out) # optional - sage.combinat sage.modules + sage: F.coerce_map_from(Out) Generic morphism: From: The subset algebra of {1, 2, 3} over Rational Field in the Out basis To: The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis allowing for mixed arithmetic:: - sage: (1 + Out.from_set(1)) * In.from_set(2,3) # optional - sage.combinat sage.modules + sage: (1 + Out.from_set(1)) * In.from_set(2,3) # needs sage.combinat sage.modules Out[{}] + 2*Out[{1}] + 2*Out[{2}] + 2*Out[{3}] + 2*Out[{1, 2}] + 2*Out[{1, 3}] + 4*Out[{2, 3}] + 4*Out[{1, 2, 3}] In our example, there are three realizations:: - sage: A.realizations() # optional - sage.combinat sage.modules + sage: A.realizations() # needs sage.modules [The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis, The subset algebra of {1, 2, 3} over Rational Field in the In basis, The subset algebra of {1, 2, 3} over Rational Field in the Out basis] @@ -116,7 +117,7 @@ def WithRealizations(self): Instead of manually defining the shorthands ``F``, ``In``, and ``Out``, as above one can just do:: - sage: A.inject_shorthands() # optional - sage.combinat sage.modules + sage: A.inject_shorthands() # needs sage.combinat sage.modules Defining F as shorthand for The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis Defining In as shorthand for @@ -142,25 +143,25 @@ def WithRealizations(self): We now illustrate this second point by defining the polynomial ring with coefficients in `A`:: - sage: P = A['x']; P # optional - sage.combinat sage.modules + sage: P = A['x']; P # needs sage.modules Univariate Polynomial Ring in x over The subset algebra of {1, 2, 3} over Rational Field - sage: x = P.gen() # optional - sage.combinat sage.modules + sage: x = P.gen() # needs sage.modules In the following examples, the coefficients turn out to be all represented in the `F` basis:: - sage: P.one() # optional - sage.combinat sage.modules + sage: P.one() # needs sage.modules F[{}] - sage: (P.an_element() + 1)^2 # optional - sage.combinat sage.modules + sage: (P.an_element() + 1)^2 # needs sage.modules F[{}]*x^2 + 2*F[{}]*x + F[{}] However we can create a polynomial with mixed coefficients, and compute with it:: - sage: p = P([1, In[{1}], Out[{2}] ]); p # optional - sage.combinat sage.modules + sage: p = P([1, In[{1}], Out[{2}] ]); p # needs sage.combinat sage.modules Out[{2}]*x^2 + In[{1}]*x + F[{}] - sage: p^2 # optional - sage.combinat sage.modules + sage: p^2 # needs sage.combinat sage.modules Out[{2}]*x^4 + (-8*In[{}] + 4*In[{1}] + 8*In[{2}] + 4*In[{3}] - 4*In[{1, 2}] - 2*In[{1, 3}] - 4*In[{2, 3}] + 2*In[{1, 2, 3}])*x^3 @@ -175,7 +176,7 @@ def WithRealizations(self): One can easily coerce all coefficient to a given basis with:: - sage: p.map_coefficients(In) # optional - sage.combinat sage.modules + sage: p.map_coefficients(In) # needs sage.combinat sage.modules (-4*In[{}] + 2*In[{1}] + 4*In[{2}] + 2*In[{3}] - 2*In[{1, 2}] - In[{1, 3}] - 2*In[{2, 3}] + In[{1, 2, 3}])*x^2 + In[{1}]*x + In[{}] @@ -183,7 +184,7 @@ def WithRealizations(self): Alas, the natural notation for constructing such polynomials does not yet work:: - sage: In[{1}] * x # optional - sage.combinat sage.modules + sage: In[{1}] * x # needs sage.combinat sage.modules Traceback (most recent call last): ... TypeError: unsupported operand parent(s) for *: @@ -197,18 +198,18 @@ def WithRealizations(self): is a category (whose class inherits from :class:`~sage.categories.realizations.Category_realization_of_parent`):: - sage: A.Realizations() # optional - sage.combinat sage.modules + sage: A.Realizations() # needs sage.modules Category of realizations of The subset algebra of {1, 2, 3} over Rational Field The various parent realizing `A` belong to this category:: - sage: A.F() in A.Realizations() # optional - sage.combinat sage.modules + sage: A.F() in A.Realizations() # needs sage.modules True `A` itself is in the category of algebras with realizations:: - sage: A in Algebras(QQ).WithRealizations() # optional - sage.combinat sage.modules + sage: A in Algebras(QQ).WithRealizations() # needs sage.modules True The (mostly technical) ``WithRealizations`` categories are the @@ -228,12 +229,12 @@ def WithRealizations(self): On our example, this simply means that `A` is automatically in the category of rings with realizations (covariance):: - sage: A in Rings().WithRealizations() # optional - sage.combinat sage.modules + sage: A in Rings().WithRealizations() # needs sage.modules True and in the category of algebras (regressiveness):: - sage: A in Algebras(QQ) # optional - sage.combinat sage.modules + sage: A in Algebras(QQ) # needs sage.modules True .. NOTE::